@yahoo/uds-mobile 2.24.0-beta.7 → 2.24.0-beta.9
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 +3 -1
- package/dist/components/Avatar/AvatarIcon.cjs +1 -1
- package/dist/components/Avatar/AvatarIcon.js +1 -1
- package/dist/components/Avatar/AvatarIcon.js.map +1 -1
- package/dist/components/Avatar/AvatarImage.cjs +1 -1
- package/dist/components/Avatar/AvatarImage.js +1 -1
- package/dist/components/Avatar/AvatarImage.js.map +1 -1
- package/dist/components/Avatar/AvatarText.cjs +1 -1
- package/dist/components/Avatar/AvatarText.js +1 -1
- package/dist/components/Avatar/AvatarText.js.map +1 -1
- package/dist/components/Avatar/useAvatarFontScale.cjs +2 -2
- package/dist/components/Avatar/useAvatarFontScale.d.cts +1 -1
- package/dist/components/Avatar/useAvatarFontScale.d.ts +1 -1
- package/dist/components/Avatar/useAvatarFontScale.js +3 -3
- package/dist/components/Avatar/useAvatarFontScale.js.map +1 -1
- package/dist/components/Button/buttonTheme.cjs +6 -1
- package/dist/components/Button/buttonTheme.d.cts +3 -1
- package/dist/components/Button/buttonTheme.d.cts.map +1 -1
- package/dist/components/Button/buttonTheme.d.ts +3 -1
- package/dist/components/Button/buttonTheme.d.ts.map +1 -1
- package/dist/components/Button/buttonTheme.js +6 -2
- package/dist/components/Button/buttonTheme.js.map +1 -1
- package/dist/components/Button.cjs +5 -4
- package/dist/components/Button.js +6 -5
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Checkbox.cjs +13 -7
- package/dist/components/Checkbox.d.cts.map +1 -1
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/Checkbox.js +14 -8
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/Chip/ChipBase.cjs +2 -2
- package/dist/components/Chip/ChipBase.js +3 -3
- package/dist/components/Chip/ChipBase.js.map +1 -1
- package/dist/components/Icon.cjs +8 -7
- package/dist/components/Icon.d.cts +2 -0
- package/dist/components/Icon.d.cts.map +1 -1
- package/dist/components/Icon.d.ts +2 -0
- package/dist/components/Icon.d.ts.map +1 -1
- package/dist/components/Icon.js +9 -8
- package/dist/components/Icon.js.map +1 -1
- package/dist/components/IconButton.cjs +17 -6
- package/dist/components/IconButton.d.cts +6 -0
- package/dist/components/IconButton.d.cts.map +1 -1
- package/dist/components/IconButton.d.ts +6 -0
- package/dist/components/IconButton.d.ts.map +1 -1
- package/dist/components/IconButton.js +18 -7
- package/dist/components/IconButton.js.map +1 -1
- package/dist/components/Input.cjs +4 -2
- package/dist/components/Input.js +5 -3
- package/dist/components/Input.js.map +1 -1
- package/dist/components/InputHelpText.cjs +2 -1
- package/dist/components/InputHelpText.js +2 -1
- package/dist/components/InputHelpText.js.map +1 -1
- package/dist/components/Link.cjs +5 -1
- package/dist/components/Link.d.cts.map +1 -1
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +5 -1
- package/dist/components/Link.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +1 -1
- package/dist/components/Pagination/Pagination.js +1 -1
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.cjs +1 -1
- package/dist/components/Pagination/PaginationEllipsis.js +2 -2
- package/dist/components/Pagination/PaginationEllipsis.js.map +1 -1
- package/dist/components/Pagination/paginationContext.d.cts +2 -2
- package/dist/components/Pagination/paginationContext.d.ts +2 -2
- package/dist/components/Pagination/paginationContext.js.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.cjs +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.js +2 -2
- package/dist/components/Pagination/usePaginationControlStyles.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +2 -2
- package/dist/components/Radio/Radio.js +3 -3
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Select/Select.cjs +3 -1
- package/dist/components/Select/Select.js +3 -1
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectItem.cjs +1 -2
- package/dist/components/Select/SelectItem.js +2 -3
- package/dist/components/Select/SelectItem.js.map +1 -1
- package/dist/components/Select/SelectTrigger.cjs +1 -2
- package/dist/components/Select/SelectTrigger.js +2 -3
- package/dist/components/Select/SelectTrigger.js.map +1 -1
- package/dist/components/Select/types.d.cts +1 -1
- package/dist/components/Select/types.d.ts +1 -1
- package/dist/components/Switch.cjs +20 -5
- package/dist/components/Switch.d.cts.map +1 -1
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +21 -6
- package/dist/components/Switch.js.map +1 -1
- package/dist/components/Tabs/Tab.cjs +2 -2
- package/dist/components/Tabs/Tab.js +3 -3
- package/dist/components/Tabs/Tab.js.map +1 -1
- package/dist/components/Text.cjs +2 -1
- package/dist/components/Text.d.cts.map +1 -1
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js +2 -1
- package/dist/components/Text.js.map +1 -1
- package/dist/fontScaling/FontScalingContext.cjs +20 -3
- package/dist/fontScaling/FontScalingContext.d.cts +11 -3
- package/dist/fontScaling/FontScalingContext.d.cts.map +1 -1
- package/dist/fontScaling/FontScalingContext.d.ts +11 -3
- package/dist/fontScaling/FontScalingContext.d.ts.map +1 -1
- package/dist/fontScaling/FontScalingContext.js +20 -5
- package/dist/fontScaling/FontScalingContext.js.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.cjs +85 -9
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts +2 -2
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts +2 -2
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.js +85 -9
- package/dist/fontScaling/androidNonlinearFontScaling.js.map +1 -1
- package/dist/fontScaling/types.d.cts +8 -7
- package/dist/fontScaling/types.d.cts.map +1 -1
- package/dist/fontScaling/types.d.ts +8 -7
- package/dist/fontScaling/types.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.cjs +21 -4
- package/dist/fontScaling/useFontScale.d.cts +6 -17
- package/dist/fontScaling/useFontScale.d.cts.map +1 -1
- package/dist/fontScaling/useFontScale.d.ts +6 -17
- package/dist/fontScaling/useFontScale.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.js +21 -5
- package/dist/fontScaling/useFontScale.js.map +1 -1
- package/dist/mobile/generated/fontMetrics.cjs +530 -530
- package/dist/mobile/generated/fontMetrics.js +530 -530
- package/dist/mobile/generated/fontMetrics.js.map +1 -1
- package/fonts/index.cjs +214 -214
- package/fonts/index.mjs +214 -214
- package/generated/fontMetrics.ts +530 -530
- package/package.json +1 -1
|
@@ -6,10 +6,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
6
6
|
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
7
7
|
* size that native Text renders.
|
|
8
8
|
*
|
|
9
|
-
* These lookup tables mirror Android's `FontScaleConverterFactory`.
|
|
9
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Android 14
|
|
10
|
+
* shipped fewer preference curves than Android 15+, so callers must provide the
|
|
11
|
+
* platform version to select the same table native Text uses. Values between
|
|
10
12
|
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
11
13
|
*
|
|
12
14
|
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
15
|
+
* @see https://android.googlesource.com/platform/prebuilts/fullsdk/sources/+/refs/heads/androidx-compose-integration-release/android-34/android/content/res/FontScaleConverterFactory.java
|
|
13
16
|
*/
|
|
14
17
|
const COMMON_SP_SIZES = [
|
|
15
18
|
8,
|
|
@@ -22,7 +25,79 @@ const COMMON_SP_SIZES = [
|
|
|
22
25
|
30,
|
|
23
26
|
100
|
|
24
27
|
];
|
|
25
|
-
const
|
|
28
|
+
const ANDROID_14_FONT_SCALE_CURVES = [
|
|
29
|
+
{
|
|
30
|
+
scale: 1.15,
|
|
31
|
+
dp: [
|
|
32
|
+
9.2,
|
|
33
|
+
11.5,
|
|
34
|
+
13.8,
|
|
35
|
+
16.4,
|
|
36
|
+
19.8,
|
|
37
|
+
21.8,
|
|
38
|
+
25.2,
|
|
39
|
+
30,
|
|
40
|
+
100
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
scale: 1.3,
|
|
45
|
+
dp: [
|
|
46
|
+
10.4,
|
|
47
|
+
13,
|
|
48
|
+
15.6,
|
|
49
|
+
18.8,
|
|
50
|
+
21.6,
|
|
51
|
+
23.6,
|
|
52
|
+
26.4,
|
|
53
|
+
30,
|
|
54
|
+
100
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
scale: 1.5,
|
|
59
|
+
dp: [
|
|
60
|
+
12,
|
|
61
|
+
15,
|
|
62
|
+
18,
|
|
63
|
+
22,
|
|
64
|
+
24,
|
|
65
|
+
26,
|
|
66
|
+
28,
|
|
67
|
+
30,
|
|
68
|
+
100
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
scale: 1.8,
|
|
73
|
+
dp: [
|
|
74
|
+
14.4,
|
|
75
|
+
18,
|
|
76
|
+
21.6,
|
|
77
|
+
24.4,
|
|
78
|
+
27.6,
|
|
79
|
+
30.8,
|
|
80
|
+
32.8,
|
|
81
|
+
34.8,
|
|
82
|
+
100
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
scale: 2,
|
|
87
|
+
dp: [
|
|
88
|
+
16,
|
|
89
|
+
20,
|
|
90
|
+
24,
|
|
91
|
+
26,
|
|
92
|
+
30,
|
|
93
|
+
34,
|
|
94
|
+
36,
|
|
95
|
+
38,
|
|
96
|
+
100
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
const ANDROID_15_FONT_SCALE_CURVES = [
|
|
26
101
|
{
|
|
27
102
|
scale: 1.05,
|
|
28
103
|
dp: [
|
|
@@ -154,16 +229,17 @@ function interpolateSize(fontSize, dpValues) {
|
|
|
154
229
|
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
155
230
|
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
156
231
|
}
|
|
157
|
-
/** Converts an SP value to
|
|
158
|
-
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
159
|
-
const
|
|
160
|
-
const
|
|
232
|
+
/** Converts an SP value to the nonlinear DP size used by this Android API level. */
|
|
233
|
+
function convertAndroidSpToDp(fontSize, fontScale, platformVersion = 35) {
|
|
234
|
+
const curves = platformVersion === 34 ? ANDROID_14_FONT_SCALE_CURVES : ANDROID_15_FONT_SCALE_CURVES;
|
|
235
|
+
const firstCurve = curves[0];
|
|
236
|
+
const lastCurve = curves[curves.length - 1];
|
|
161
237
|
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
162
|
-
for (let index = 0; index <
|
|
163
|
-
const curve =
|
|
238
|
+
for (let index = 0; index < curves.length; index += 1) {
|
|
239
|
+
const curve = curves[index];
|
|
164
240
|
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
165
241
|
if (fontScale < curve.scale) {
|
|
166
|
-
const previousCurve =
|
|
242
|
+
const previousCurve = curves[index - 1];
|
|
167
243
|
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
168
244
|
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
169
245
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
-
/** Converts an SP value to
|
|
4
|
-
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
3
|
+
/** Converts an SP value to the nonlinear DP size used by this Android API level. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number, platformVersion?: number): number;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { convertAndroidSpToDp };
|
|
7
7
|
//# sourceMappingURL=androidNonlinearFontScaling.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"androidNonlinearFontScaling.d.cts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.cts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBA8DS,oBAAA,CACP,QAAA,UACA,SAAA,UACA,eAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
-
/** Converts an SP value to
|
|
4
|
-
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
3
|
+
/** Converts an SP value to the nonlinear DP size used by this Android API level. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number, platformVersion?: number): number;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { convertAndroidSpToDp };
|
|
7
7
|
//# sourceMappingURL=androidNonlinearFontScaling.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"androidNonlinearFontScaling.d.ts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.ts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBA8DS,oBAAA,CACP,QAAA,UACA,SAAA,UACA,eAAA"}
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
6
6
|
* size that native Text renders.
|
|
7
7
|
*
|
|
8
|
-
* These lookup tables mirror Android's `FontScaleConverterFactory`.
|
|
8
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Android 14
|
|
9
|
+
* shipped fewer preference curves than Android 15+, so callers must provide the
|
|
10
|
+
* platform version to select the same table native Text uses. Values between
|
|
9
11
|
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
10
12
|
*
|
|
11
13
|
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
14
|
+
* @see https://android.googlesource.com/platform/prebuilts/fullsdk/sources/+/refs/heads/androidx-compose-integration-release/android-34/android/content/res/FontScaleConverterFactory.java
|
|
12
15
|
*/
|
|
13
16
|
const COMMON_SP_SIZES = [
|
|
14
17
|
8,
|
|
@@ -21,7 +24,79 @@ const COMMON_SP_SIZES = [
|
|
|
21
24
|
30,
|
|
22
25
|
100
|
|
23
26
|
];
|
|
24
|
-
const
|
|
27
|
+
const ANDROID_14_FONT_SCALE_CURVES = [
|
|
28
|
+
{
|
|
29
|
+
scale: 1.15,
|
|
30
|
+
dp: [
|
|
31
|
+
9.2,
|
|
32
|
+
11.5,
|
|
33
|
+
13.8,
|
|
34
|
+
16.4,
|
|
35
|
+
19.8,
|
|
36
|
+
21.8,
|
|
37
|
+
25.2,
|
|
38
|
+
30,
|
|
39
|
+
100
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
scale: 1.3,
|
|
44
|
+
dp: [
|
|
45
|
+
10.4,
|
|
46
|
+
13,
|
|
47
|
+
15.6,
|
|
48
|
+
18.8,
|
|
49
|
+
21.6,
|
|
50
|
+
23.6,
|
|
51
|
+
26.4,
|
|
52
|
+
30,
|
|
53
|
+
100
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
scale: 1.5,
|
|
58
|
+
dp: [
|
|
59
|
+
12,
|
|
60
|
+
15,
|
|
61
|
+
18,
|
|
62
|
+
22,
|
|
63
|
+
24,
|
|
64
|
+
26,
|
|
65
|
+
28,
|
|
66
|
+
30,
|
|
67
|
+
100
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
scale: 1.8,
|
|
72
|
+
dp: [
|
|
73
|
+
14.4,
|
|
74
|
+
18,
|
|
75
|
+
21.6,
|
|
76
|
+
24.4,
|
|
77
|
+
27.6,
|
|
78
|
+
30.8,
|
|
79
|
+
32.8,
|
|
80
|
+
34.8,
|
|
81
|
+
100
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
scale: 2,
|
|
86
|
+
dp: [
|
|
87
|
+
16,
|
|
88
|
+
20,
|
|
89
|
+
24,
|
|
90
|
+
26,
|
|
91
|
+
30,
|
|
92
|
+
34,
|
|
93
|
+
36,
|
|
94
|
+
38,
|
|
95
|
+
100
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
const ANDROID_15_FONT_SCALE_CURVES = [
|
|
25
100
|
{
|
|
26
101
|
scale: 1.05,
|
|
27
102
|
dp: [
|
|
@@ -153,16 +228,17 @@ function interpolateSize(fontSize, dpValues) {
|
|
|
153
228
|
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
154
229
|
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
155
230
|
}
|
|
156
|
-
/** Converts an SP value to
|
|
157
|
-
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
158
|
-
const
|
|
159
|
-
const
|
|
231
|
+
/** Converts an SP value to the nonlinear DP size used by this Android API level. */
|
|
232
|
+
function convertAndroidSpToDp(fontSize, fontScale, platformVersion = 35) {
|
|
233
|
+
const curves = platformVersion === 34 ? ANDROID_14_FONT_SCALE_CURVES : ANDROID_15_FONT_SCALE_CURVES;
|
|
234
|
+
const firstCurve = curves[0];
|
|
235
|
+
const lastCurve = curves[curves.length - 1];
|
|
160
236
|
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
161
|
-
for (let index = 0; index <
|
|
162
|
-
const curve =
|
|
237
|
+
for (let index = 0; index < curves.length; index += 1) {
|
|
238
|
+
const curve = curves[index];
|
|
163
239
|
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
164
240
|
if (fontScale < curve.scale) {
|
|
165
|
-
const previousCurve =
|
|
241
|
+
const previousCurve = curves[index - 1];
|
|
166
242
|
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
167
243
|
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
168
244
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"androidNonlinearFontScaling.js","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"sourcesContent":["/**\n * Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`\n * is only the user's preference; multiplying by it directly does not reproduce the\n * size that native Text renders.\n *\n * These lookup tables mirror Android's `FontScaleConverterFactory`. Values between\n * table entries are linearly interpolated, as they are in the platform implementation.\n *\n * @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java\n */\nconst COMMON_SP_SIZES = [8, 10, 12, 14, 18, 20, 24, 30, 100] as const;\n\nconst
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.js","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"sourcesContent":["/**\n * Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`\n * is only the user's preference; multiplying by it directly does not reproduce the\n * size that native Text renders.\n *\n * These lookup tables mirror Android's `FontScaleConverterFactory`. Android 14\n * shipped fewer preference curves than Android 15+, so callers must provide the\n * platform version to select the same table native Text uses. Values between\n * table entries are linearly interpolated, as they are in the platform implementation.\n *\n * @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java\n * @see https://android.googlesource.com/platform/prebuilts/fullsdk/sources/+/refs/heads/androidx-compose-integration-release/android-34/android/content/res/FontScaleConverterFactory.java\n */\nconst COMMON_SP_SIZES = [8, 10, 12, 14, 18, 20, 24, 30, 100] as const;\n\nconst ANDROID_14_FONT_SCALE_CURVES = [\n { scale: 1.15, dp: [9.2, 11.5, 13.8, 16.4, 19.8, 21.8, 25.2, 30, 100] },\n { scale: 1.3, dp: [10.4, 13, 15.6, 18.8, 21.6, 23.6, 26.4, 30, 100] },\n { scale: 1.5, dp: [12, 15, 18, 22, 24, 26, 28, 30, 100] },\n { scale: 1.8, dp: [14.4, 18, 21.6, 24.4, 27.6, 30.8, 32.8, 34.8, 100] },\n { scale: 2, dp: [16, 20, 24, 26, 30, 34, 36, 38, 100] },\n] as const;\n\nconst ANDROID_15_FONT_SCALE_CURVES = [\n { scale: 1.05, dp: [8.4, 10.5, 12.6, 14.8, 18.6, 20.6, 24.4, 30, 100] },\n { scale: 1.1, dp: [8.8, 11, 13.2, 15.6, 19.2, 21.2, 24.8, 30, 100] },\n { scale: 1.15, dp: [9.2, 11.5, 13.8, 16.4, 19.8, 21.8, 25.2, 30, 100] },\n { scale: 1.2, dp: [9.6, 12, 14.4, 17.2, 20.4, 22.4, 25.6, 30, 100] },\n { scale: 1.3, dp: [10.4, 13, 15.6, 18.8, 21.6, 23.6, 26.4, 30, 100] },\n { scale: 1.5, dp: [12, 15, 18, 22, 24, 26, 28, 30, 100] },\n { scale: 1.8, dp: [14.4, 18, 21.6, 24.4, 27.6, 30.8, 32.8, 34.8, 100] },\n { scale: 2, dp: [16, 20, 24, 26, 30, 34, 36, 38, 100] },\n] as const;\n\nfunction lerp(start: number, end: number, amount: number): number {\n return start + (end - start) * amount;\n}\n\nfunction interpolateSize(fontSize: number, dpValues: readonly number[]): number {\n if (fontSize <= 0) {\n return fontSize;\n }\n\n for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {\n const currentSp = COMMON_SP_SIZES[index];\n if (fontSize === currentSp) {\n return dpValues[index] as number;\n }\n if (fontSize < currentSp) {\n const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];\n const previousDp = index === 0 ? 0 : (dpValues[index - 1] as number);\n const amount = (fontSize - previousSp) / (currentSp - previousSp);\n return lerp(previousDp, dpValues[index] as number, amount);\n }\n }\n\n // Android extrapolates beyond the table with the last entry's ratio.\n const lastIndex = COMMON_SP_SIZES.length - 1;\n return fontSize * ((dpValues[lastIndex] as number) / COMMON_SP_SIZES[lastIndex]);\n}\n\n/** Converts an SP value to the nonlinear DP size used by this Android API level. */\nfunction convertAndroidSpToDp(\n fontSize: number,\n fontScale: number,\n platformVersion: number = 35,\n): number {\n const curves =\n platformVersion === 34 ? ANDROID_14_FONT_SCALE_CURVES : ANDROID_15_FONT_SCALE_CURVES;\n const firstCurve = curves[0];\n const lastCurve = curves[curves.length - 1];\n\n // Outside Android's curve range, the platform falls back to a linear table.\n if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) {\n return fontSize * fontScale;\n }\n\n for (let index = 0; index < curves.length; index += 1) {\n const curve = curves[index];\n if (fontScale === curve.scale) {\n return interpolateSize(fontSize, curve.dp);\n }\n if (fontScale < curve.scale) {\n const previousCurve = curves[index - 1];\n const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);\n return lerp(\n interpolateSize(fontSize, previousCurve.dp),\n interpolateSize(fontSize, curve.dp),\n amount,\n );\n }\n }\n\n return fontSize * fontScale;\n}\n\nexport { convertAndroidSpToDp };\n"],"mappings":"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"}
|
|
@@ -21,9 +21,10 @@ type FontScalingCapValue = number | null;
|
|
|
21
21
|
*/
|
|
22
22
|
interface FontScalingConfig {
|
|
23
23
|
/**
|
|
24
|
-
* Master switch for UDS-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Master switch for UDS-added font-scaling behavior. When `false`, native
|
|
25
|
+
* text keeps its pre-feature scaling behavior while UDS caps, Dynamic Type
|
|
26
|
+
* ramps, multicolor-icon scaling, and scale-aware geometry are disabled.
|
|
27
|
+
* Explicit component and native text props still apply.
|
|
27
28
|
* @default true
|
|
28
29
|
*/
|
|
29
30
|
enabled?: boolean;
|
|
@@ -35,10 +36,10 @@ interface FontScalingConfig {
|
|
|
35
36
|
*/
|
|
36
37
|
default?: FontScalingCapValue;
|
|
37
38
|
/**
|
|
38
|
-
* Cap for control-internal text, icons, and geometry in Button,
|
|
39
|
-
* Radio, Switch, Chip, Tabs, Input, Select, Avatar, and Pagination,
|
|
40
|
-
* standalone `Icon` glyphs and multicolor SVGs. Link resolves through
|
|
41
|
-
* typography variant instead of the control cap.
|
|
39
|
+
* Cap for control-internal text, icons, and geometry in Button, IconButton,
|
|
40
|
+
* Checkbox, Radio, Switch, Chip, Tabs, Input, Select, Avatar, and Pagination,
|
|
41
|
+
* plus standalone `Icon` glyphs and multicolor SVGs. Link resolves through
|
|
42
|
+
* its typography variant instead of the control cap.
|
|
42
43
|
* @default 2
|
|
43
44
|
*/
|
|
44
45
|
control?: FontScalingCapValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/fontScaling/types.ts"],"mappings":";;;;;;AAAsD;;;;KAQjD,mBAAA;AAAmB;;;;;;;;;;AAAA,UAYd,iBAAA;
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/fontScaling/types.ts"],"mappings":";;;;;;AAAsD;;;;KAQjD,mBAAA;AAAmB;;;;;;;;;;AAAA,UAYd,iBAAA;EAQR;;;;;;;EAAA,OAAA;EAoB0B;;;;;;EAb1B,OAAA,GAAU,mBAAA;;;;;;;;EAQV,OAAA,GAAU,mBAAA;;;;;EAKV,QAAA,GAAW,OAAA,CAAQ,MAAA,CAAO,WAAA,EAAa,mBAAA;AAAA"}
|
|
@@ -21,9 +21,10 @@ type FontScalingCapValue = number | null;
|
|
|
21
21
|
*/
|
|
22
22
|
interface FontScalingConfig {
|
|
23
23
|
/**
|
|
24
|
-
* Master switch for UDS-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Master switch for UDS-added font-scaling behavior. When `false`, native
|
|
25
|
+
* text keeps its pre-feature scaling behavior while UDS caps, Dynamic Type
|
|
26
|
+
* ramps, multicolor-icon scaling, and scale-aware geometry are disabled.
|
|
27
|
+
* Explicit component and native text props still apply.
|
|
27
28
|
* @default true
|
|
28
29
|
*/
|
|
29
30
|
enabled?: boolean;
|
|
@@ -35,10 +36,10 @@ interface FontScalingConfig {
|
|
|
35
36
|
*/
|
|
36
37
|
default?: FontScalingCapValue;
|
|
37
38
|
/**
|
|
38
|
-
* Cap for control-internal text, icons, and geometry in Button,
|
|
39
|
-
* Radio, Switch, Chip, Tabs, Input, Select, Avatar, and Pagination,
|
|
40
|
-
* standalone `Icon` glyphs and multicolor SVGs. Link resolves through
|
|
41
|
-
* typography variant instead of the control cap.
|
|
39
|
+
* Cap for control-internal text, icons, and geometry in Button, IconButton,
|
|
40
|
+
* Checkbox, Radio, Switch, Chip, Tabs, Input, Select, Avatar, and Pagination,
|
|
41
|
+
* plus standalone `Icon` glyphs and multicolor SVGs. Link resolves through
|
|
42
|
+
* its typography variant instead of the control cap.
|
|
42
43
|
* @default 2
|
|
43
44
|
*/
|
|
44
45
|
control?: FontScalingCapValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/fontScaling/types.ts"],"mappings":";;;;;;AAAsD;;;;KAQjD,mBAAA;AAAmB;;;;;;;;;;AAAA,UAYd,iBAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/fontScaling/types.ts"],"mappings":";;;;;;AAAsD;;;;KAQjD,mBAAA;AAAmB;;;;;;;;;;AAAA,UAYd,iBAAA;EAQR;;;;;;;EAAA,OAAA;EAoB0B;;;;;;EAb1B,OAAA,GAAU,mBAAA;;;;;;;;EAQV,OAAA,GAAU,mBAAA;;;;;EAKV,QAAA,GAAW,OAAA,CAAQ,MAAA,CAAO,WAAA,EAAa,mBAAA;AAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
4
|
+
const require_fontScaling_FontScalingContext = require("./FontScalingContext.cjs");
|
|
4
5
|
const require_fontScaling_androidNonlinearFontScaling = require("./androidNonlinearFontScaling.cjs");
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let react_native = require("react-native");
|
|
@@ -25,17 +26,33 @@ function getFontScale() {
|
|
|
25
26
|
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
26
27
|
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
27
28
|
* scalar behavior for custom callers that do not know their base size.
|
|
29
|
+
* On iOS this follows the global text-size curve; accompanying text should
|
|
30
|
+
* omit `dynamicTypeRamp` so its native size uses the same multiplier.
|
|
28
31
|
*
|
|
29
32
|
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
30
33
|
* components re-render solely when the user changes the OS text size.
|
|
34
|
+
* Returns 1 when the nearest font-scaling provider has `enabled: false`.
|
|
31
35
|
*/
|
|
32
|
-
function
|
|
36
|
+
function useFontScaleValue(cap, fontSize, honorResolvedComponentOverride = false) {
|
|
37
|
+
const enabled = require_fontScaling_FontScalingContext.useFontScalingEnabled();
|
|
33
38
|
const fontScale = (0, react.useSyncExternalStore)(subscribe, getFontScale, getFontScale);
|
|
39
|
+
if (!enabled && !honorResolvedComponentOverride) return 1;
|
|
34
40
|
const effectiveCap = typeof cap === "number" && cap >= 1 ? cap : Number.POSITIVE_INFINITY;
|
|
35
|
-
const cappedFontScale = Math.min(fontScale, effectiveCap);
|
|
36
41
|
const platformVersion = Number(react_native.Platform.Version);
|
|
37
|
-
const nativeScale = react_native.Platform.OS === "android" && platformVersion >= 34 && typeof fontSize === "number" && fontSize > 0 ? require_fontScaling_androidNonlinearFontScaling.convertAndroidSpToDp(fontSize,
|
|
38
|
-
return Math.max(1, nativeScale);
|
|
42
|
+
const nativeScale = react_native.Platform.OS === "android" && platformVersion >= 34 && typeof fontSize === "number" && fontSize > 0 ? require_fontScaling_androidNonlinearFontScaling.convertAndroidSpToDp(fontSize, fontScale, platformVersion) / fontSize : fontScale;
|
|
43
|
+
return Math.max(1, Math.min(nativeScale, effectiveCap));
|
|
44
|
+
}
|
|
45
|
+
function useFontScale(cap, fontSize) {
|
|
46
|
+
return useFontScaleValue(cap, fontSize);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Internal component path. A resolved cap is defined under rollback mode only
|
|
50
|
+
* when it came from an explicit component prop, which the public contract says
|
|
51
|
+
* must continue to apply.
|
|
52
|
+
*/
|
|
53
|
+
function useComponentFontScale(cap, fontSize) {
|
|
54
|
+
return useFontScaleValue(cap, fontSize, cap !== void 0);
|
|
39
55
|
}
|
|
40
56
|
//#endregion
|
|
57
|
+
exports.useComponentFontScale = useComponentFontScale;
|
|
41
58
|
exports.useFontScale = useFontScale;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fontScaling/useFontScale.d.ts
|
|
3
|
+
declare function useFontScale(cap?: number | null, fontSize?: number): number;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1
|
|
9
|
-
* caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result
|
|
10
|
-
* is never below 1 so containers never shrink under their token metrics
|
|
11
|
-
* (font scales < 1 shrink text only, as today).
|
|
12
|
-
*
|
|
13
|
-
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
14
|
-
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
15
|
-
* scalar behavior for custom callers that do not know their base size.
|
|
16
|
-
*
|
|
17
|
-
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
18
|
-
* components re-render solely when the user changes the OS text size.
|
|
5
|
+
* Internal component path. A resolved cap is defined under rollback mode only
|
|
6
|
+
* when it came from an explicit component prop, which the public contract says
|
|
7
|
+
* must continue to apply.
|
|
19
8
|
*/
|
|
20
|
-
declare function
|
|
9
|
+
declare function useComponentFontScale(cap?: number | null, fontSize?: number): number;
|
|
21
10
|
//#endregion
|
|
22
|
-
export { useFontScale };
|
|
11
|
+
export { useComponentFontScale, useFontScale };
|
|
23
12
|
//# sourceMappingURL=useFontScale.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFontScale.d.cts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFontScale.d.cts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":";;iBA+DS,YAAA,CAAa,GAAA,kBAAqB,QAAA;;;;;;iBASlC,qBAAA,CAAsB,GAAA,kBAAqB,QAAA"}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/fontScaling/useFontScale.d.ts
|
|
3
|
+
declare function useFontScale(cap?: number | null, fontSize?: number): number;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1
|
|
9
|
-
* caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result
|
|
10
|
-
* is never below 1 so containers never shrink under their token metrics
|
|
11
|
-
* (font scales < 1 shrink text only, as today).
|
|
12
|
-
*
|
|
13
|
-
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
14
|
-
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
15
|
-
* scalar behavior for custom callers that do not know their base size.
|
|
16
|
-
*
|
|
17
|
-
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
18
|
-
* components re-render solely when the user changes the OS text size.
|
|
5
|
+
* Internal component path. A resolved cap is defined under rollback mode only
|
|
6
|
+
* when it came from an explicit component prop, which the public contract says
|
|
7
|
+
* must continue to apply.
|
|
19
8
|
*/
|
|
20
|
-
declare function
|
|
9
|
+
declare function useComponentFontScale(cap?: number | null, fontSize?: number): number;
|
|
21
10
|
//#endregion
|
|
22
|
-
export { useFontScale };
|
|
11
|
+
export { useComponentFontScale, useFontScale };
|
|
23
12
|
//# sourceMappingURL=useFontScale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFontScale.d.ts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFontScale.d.ts","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"mappings":";;iBA+DS,YAAA,CAAa,GAAA,kBAAqB,QAAA;;;;;;iBASlC,qBAAA,CAAsB,GAAA,kBAAqB,QAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
import { useFontScalingEnabled } from "./FontScalingContext.js";
|
|
2
3
|
import { convertAndroidSpToDp } from "./androidNonlinearFontScaling.js";
|
|
3
4
|
import { useSyncExternalStore } from "react";
|
|
4
5
|
import { Dimensions, Platform } from "react-native";
|
|
@@ -23,19 +24,34 @@ function getFontScale() {
|
|
|
23
24
|
* Pass the SP size that the geometry accompanies on Android so this mirrors
|
|
24
25
|
* Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy
|
|
25
26
|
* scalar behavior for custom callers that do not know their base size.
|
|
27
|
+
* On iOS this follows the global text-size curve; accompanying text should
|
|
28
|
+
* omit `dynamicTypeRamp` so its native size uses the same multiplier.
|
|
26
29
|
*
|
|
27
30
|
* Subscribes to font-scale changes only — rotation does not re-render, and
|
|
28
31
|
* components re-render solely when the user changes the OS text size.
|
|
32
|
+
* Returns 1 when the nearest font-scaling provider has `enabled: false`.
|
|
29
33
|
*/
|
|
30
|
-
function
|
|
34
|
+
function useFontScaleValue(cap, fontSize, honorResolvedComponentOverride = false) {
|
|
35
|
+
const enabled = useFontScalingEnabled();
|
|
31
36
|
const fontScale = useSyncExternalStore(subscribe, getFontScale, getFontScale);
|
|
37
|
+
if (!enabled && !honorResolvedComponentOverride) return 1;
|
|
32
38
|
const effectiveCap = typeof cap === "number" && cap >= 1 ? cap : Number.POSITIVE_INFINITY;
|
|
33
|
-
const cappedFontScale = Math.min(fontScale, effectiveCap);
|
|
34
39
|
const platformVersion = Number(Platform.Version);
|
|
35
|
-
const nativeScale = Platform.OS === "android" && platformVersion >= 34 && typeof fontSize === "number" && fontSize > 0 ? convertAndroidSpToDp(fontSize,
|
|
36
|
-
return Math.max(1, nativeScale);
|
|
40
|
+
const nativeScale = Platform.OS === "android" && platformVersion >= 34 && typeof fontSize === "number" && fontSize > 0 ? convertAndroidSpToDp(fontSize, fontScale, platformVersion) / fontSize : fontScale;
|
|
41
|
+
return Math.max(1, Math.min(nativeScale, effectiveCap));
|
|
42
|
+
}
|
|
43
|
+
function useFontScale(cap, fontSize) {
|
|
44
|
+
return useFontScaleValue(cap, fontSize);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Internal component path. A resolved cap is defined under rollback mode only
|
|
48
|
+
* when it came from an explicit component prop, which the public contract says
|
|
49
|
+
* must continue to apply.
|
|
50
|
+
*/
|
|
51
|
+
function useComponentFontScale(cap, fontSize) {
|
|
52
|
+
return useFontScaleValue(cap, fontSize, cap !== void 0);
|
|
37
53
|
}
|
|
38
54
|
//#endregion
|
|
39
|
-
export { useFontScale };
|
|
55
|
+
export { useComponentFontScale, useFontScale };
|
|
40
56
|
|
|
41
57
|
//# sourceMappingURL=useFontScale.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFontScale.js","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { Dimensions, Platform } from 'react-native';\n\nimport { convertAndroidSpToDp } from './androidNonlinearFontScaling';\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const subscription = Dimensions.addEventListener('change', onStoreChange);\n return () => subscription.remove();\n}\n\n// Unistyles' rt.fontScale is stale when the OS text size changes while the\n// app is running; Dimensions reflects the live value on both platforms.\nfunction getFontScale(): number {\n return Dimensions.get('window').fontScale;\n}\n\n/**\n * The effective scale for `fontSize`, clamped to `[1, cap]`, for sizing\n * containers around scaled text (e.g. a checkbox box growing with its\n * checkmark).\n *\n * `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1\n * caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result\n * is never below 1 so containers never shrink under their token metrics\n * (font scales < 1 shrink text only, as today).\n *\n * Pass the SP size that the geometry accompanies on Android so this mirrors\n * Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy\n * scalar behavior for custom callers that do not know their base size.\n *\n * Subscribes to font-scale changes only — rotation does not re-render, and\n * components re-render solely when the user changes the OS text size.\n */\nfunction
|
|
1
|
+
{"version":3,"file":"useFontScale.js","names":[],"sources":["../../src/fontScaling/useFontScale.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { Dimensions, Platform } from 'react-native';\n\nimport { convertAndroidSpToDp } from './androidNonlinearFontScaling';\nimport { useFontScalingEnabled } from './FontScalingContext';\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const subscription = Dimensions.addEventListener('change', onStoreChange);\n return () => subscription.remove();\n}\n\n// Unistyles' rt.fontScale is stale when the OS text size changes while the\n// app is running; Dimensions reflects the live value on both platforms.\nfunction getFontScale(): number {\n return Dimensions.get('window').fontScale;\n}\n\n/**\n * The effective scale for `fontSize`, clamped to `[1, cap]`, for sizing\n * containers around scaled text (e.g. a checkbox box growing with its\n * checkmark).\n *\n * `cap` uses the same semantics as `maxFontSizeMultiplier`: a number >= 1\n * caps the scale; `null`, `0`, or `undefined` leave it uncapped. The result\n * is never below 1 so containers never shrink under their token metrics\n * (font scales < 1 shrink text only, as today).\n *\n * Pass the SP size that the geometry accompanies on Android so this mirrors\n * Android 14+'s nonlinear scaling. Omitting `fontSize` preserves the legacy\n * scalar behavior for custom callers that do not know their base size.\n * On iOS this follows the global text-size curve; accompanying text should\n * omit `dynamicTypeRamp` so its native size uses the same multiplier.\n *\n * Subscribes to font-scale changes only — rotation does not re-render, and\n * components re-render solely when the user changes the OS text size.\n * Returns 1 when the nearest font-scaling provider has `enabled: false`.\n */\nfunction useFontScaleValue(\n cap?: number | null,\n fontSize?: number,\n honorResolvedComponentOverride = false,\n): number {\n const enabled = useFontScalingEnabled();\n const fontScale = useSyncExternalStore(subscribe, getFontScale, getFontScale);\n if (!enabled && !honorResolvedComponentOverride) {\n return 1;\n }\n\n const effectiveCap = typeof cap === 'number' && cap >= 1 ? cap : Number.POSITIVE_INFINITY;\n const platformVersion = Number(Platform.Version);\n const nativeScale =\n Platform.OS === 'android' &&\n platformVersion >= 34 &&\n typeof fontSize === 'number' &&\n fontSize > 0\n ? convertAndroidSpToDp(fontSize, fontScale, platformVersion) / fontSize\n : fontScale;\n\n // React Native applies maxFontSizeMultiplier after the platform conversion.\n // This matters on Android 14+, where the converted size is nonlinear.\n return Math.max(1, Math.min(nativeScale, effectiveCap));\n}\n\nfunction useFontScale(cap?: number | null, fontSize?: number): number {\n return useFontScaleValue(cap, fontSize);\n}\n\n/**\n * Internal component path. A resolved cap is defined under rollback mode only\n * when it came from an explicit component prop, which the public contract says\n * must continue to apply.\n */\nfunction useComponentFontScale(cap?: number | null, fontSize?: number): number {\n return useFontScaleValue(cap, fontSize, cap !== undefined);\n}\n\nexport { useComponentFontScale, useFontScale };\n"],"mappings":";;;;;;AAMA,SAAS,UAAU,eAAuC;CACxD,MAAM,eAAe,WAAW,iBAAiB,UAAU,cAAc;CACzE,aAAa,aAAa,QAAQ;;AAKpC,SAAS,eAAuB;CAC9B,OAAO,WAAW,IAAI,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuBlC,SAAS,kBACP,KACA,UACA,iCAAiC,OACzB;CACR,MAAM,UAAU,uBAAuB;CACvC,MAAM,YAAY,qBAAqB,WAAW,cAAc,aAAa;CAC7E,IAAI,CAAC,WAAW,CAAC,gCACf,OAAO;CAGT,MAAM,eAAe,OAAO,QAAQ,YAAY,OAAO,IAAI,MAAM,OAAO;CACxE,MAAM,kBAAkB,OAAO,SAAS,QAAQ;CAChD,MAAM,cACJ,SAAS,OAAO,aAChB,mBAAmB,MACnB,OAAO,aAAa,YACpB,WAAW,IACP,qBAAqB,UAAU,WAAW,gBAAgB,GAAG,WAC7D;CAIN,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,aAAa,aAAa,CAAC;;AAGzD,SAAS,aAAa,KAAqB,UAA2B;CACpE,OAAO,kBAAkB,KAAK,SAAS;;;;;;;AAQzC,SAAS,sBAAsB,KAAqB,UAA2B;CAC7E,OAAO,kBAAkB,KAAK,UAAU,QAAQ,KAAA,EAAU"}
|