@yahoo/uds-mobile 2.24.0-beta.4 → 2.24.0-beta.6
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/components/Avatar/AvatarIcon.cjs +8 -2
- package/dist/components/Avatar/AvatarIcon.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarIcon.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarIcon.js +9 -3
- package/dist/components/Avatar/AvatarIcon.js.map +1 -1
- package/dist/components/Avatar/AvatarImage.cjs +9 -2
- package/dist/components/Avatar/AvatarImage.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarImage.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarImage.js +10 -3
- package/dist/components/Avatar/AvatarImage.js.map +1 -1
- package/dist/components/Avatar/AvatarText.cjs +8 -2
- package/dist/components/Avatar/AvatarText.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarText.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarText.js +9 -3
- package/dist/components/Avatar/AvatarText.js.map +1 -1
- package/dist/components/Avatar/types.d.cts +7 -3
- package/dist/components/Avatar/types.d.cts.map +1 -1
- package/dist/components/Avatar/types.d.ts +7 -3
- package/dist/components/Avatar/types.d.ts.map +1 -1
- package/dist/components/Avatar/useAvatarFontScale.cjs +16 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.js +16 -0
- package/dist/components/Avatar/useAvatarFontScale.js.map +1 -0
- package/dist/components/Avatar/utils.cjs +9 -6
- package/dist/components/Avatar/utils.d.cts +2 -2
- package/dist/components/Avatar/utils.d.cts.map +1 -1
- package/dist/components/Avatar/utils.d.ts +2 -2
- package/dist/components/Avatar/utils.d.ts.map +1 -1
- package/dist/components/Avatar/utils.js +9 -6
- package/dist/components/Avatar/utils.js.map +1 -1
- package/dist/components/Button/buttonTheme.cjs +10 -6
- package/dist/components/Button/buttonTheme.d.cts +10 -5
- package/dist/components/Button/buttonTheme.d.cts.map +1 -1
- package/dist/components/Button/buttonTheme.d.ts +10 -5
- package/dist/components/Button/buttonTheme.d.ts.map +1 -1
- package/dist/components/Button/buttonTheme.js +10 -6
- package/dist/components/Button/buttonTheme.js.map +1 -1
- package/dist/components/Button.cjs +22 -9
- package/dist/components/Button.d.cts.map +1 -1
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +22 -9
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Checkbox.cjs +7 -3
- package/dist/components/Checkbox.js +7 -3
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/Chip/ChipBase.cjs +22 -19
- package/dist/components/Chip/ChipBase.js +22 -19
- package/dist/components/Chip/ChipBase.js.map +1 -1
- package/dist/components/Icon.cjs +5 -4
- package/dist/components/Icon.d.cts.map +1 -1
- package/dist/components/Icon.d.ts.map +1 -1
- package/dist/components/Icon.js +5 -4
- package/dist/components/Icon.js.map +1 -1
- package/dist/components/Input.cjs +54 -18
- package/dist/components/Input.d.cts +5 -0
- package/dist/components/Input.d.cts.map +1 -1
- package/dist/components/Input.d.ts +5 -0
- package/dist/components/Input.d.ts.map +1 -1
- package/dist/components/Input.js +54 -18
- package/dist/components/Input.js.map +1 -1
- package/dist/components/InputHelpText.cjs +6 -1
- package/dist/components/InputHelpText.d.cts +2 -0
- package/dist/components/InputHelpText.d.cts.map +1 -1
- package/dist/components/InputHelpText.d.ts +2 -0
- package/dist/components/InputHelpText.d.ts.map +1 -1
- package/dist/components/InputHelpText.js +6 -1
- package/dist/components/InputHelpText.js.map +1 -1
- package/dist/components/Link.cjs +10 -1
- package/dist/components/Link.d.cts +6 -0
- package/dist/components/Link.d.cts.map +1 -1
- package/dist/components/Link.d.ts +6 -0
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +10 -1
- package/dist/components/Link.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +18 -10
- package/dist/components/Pagination/Pagination.d.cts +2 -0
- package/dist/components/Pagination/Pagination.d.cts.map +1 -1
- package/dist/components/Pagination/Pagination.d.ts +2 -0
- package/dist/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/components/Pagination/Pagination.js +18 -10
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.cjs +8 -2
- package/dist/components/Pagination/PaginationEllipsis.d.cts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.d.ts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.js +9 -3
- package/dist/components/Pagination/PaginationEllipsis.js.map +1 -1
- package/dist/components/Pagination/PaginationItem.cjs +2 -1
- package/dist/components/Pagination/PaginationItem.js +2 -1
- package/dist/components/Pagination/PaginationItem.js.map +1 -1
- package/dist/components/Pagination/PaginationLink.cjs +2 -1
- package/dist/components/Pagination/PaginationLink.js +2 -1
- package/dist/components/Pagination/PaginationLink.js.map +1 -1
- package/dist/components/Pagination/PaginationNext.cjs +3 -1
- package/dist/components/Pagination/PaginationNext.js +3 -1
- package/dist/components/Pagination/PaginationNext.js.map +1 -1
- package/dist/components/Pagination/PaginationPrev.cjs +3 -1
- package/dist/components/Pagination/PaginationPrev.js +3 -1
- package/dist/components/Pagination/PaginationPrev.js.map +1 -1
- package/dist/components/Pagination/paginationContext.d.cts +2 -0
- package/dist/components/Pagination/paginationContext.d.cts.map +1 -1
- package/dist/components/Pagination/paginationContext.d.ts +2 -0
- package/dist/components/Pagination/paginationContext.d.ts.map +1 -1
- package/dist/components/Pagination/paginationContext.js.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.cjs +8 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.cts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.ts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.js +9 -2
- package/dist/components/Pagination/usePaginationControlStyles.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +2 -1
- package/dist/components/Radio/Radio.js +2 -1
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Select/Select.cjs +11 -2
- package/dist/components/Select/Select.d.cts +2 -0
- package/dist/components/Select/Select.d.cts.map +1 -1
- package/dist/components/Select/Select.d.ts +2 -0
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/Select.js +11 -2
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectItem.cjs +26 -15
- package/dist/components/Select/SelectItem.d.cts.map +1 -1
- package/dist/components/Select/SelectItem.d.ts.map +1 -1
- package/dist/components/Select/SelectItem.js +26 -15
- package/dist/components/Select/SelectItem.js.map +1 -1
- package/dist/components/Select/SelectTrigger.cjs +28 -13
- package/dist/components/Select/SelectTrigger.d.cts.map +1 -1
- package/dist/components/Select/SelectTrigger.d.ts.map +1 -1
- package/dist/components/Select/SelectTrigger.js +28 -13
- package/dist/components/Select/SelectTrigger.js.map +1 -1
- package/dist/components/Select/types.d.cts +2 -0
- package/dist/components/Select/types.d.cts.map +1 -1
- package/dist/components/Select/types.d.ts +2 -0
- package/dist/components/Select/types.d.ts.map +1 -1
- package/dist/components/Switch.cjs +5 -3
- package/dist/components/Switch.d.cts.map +1 -1
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +5 -3
- package/dist/components/Switch.js.map +1 -1
- package/dist/components/Tabs/Tab.cjs +6 -2
- package/dist/components/Tabs/Tab.d.cts.map +1 -1
- package/dist/components/Tabs/Tab.d.ts.map +1 -1
- package/dist/components/Tabs/Tab.js +6 -2
- package/dist/components/Tabs/Tab.js.map +1 -1
- package/dist/components/Text.cjs +4 -0
- package/dist/components/Text.d.cts.map +1 -1
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js +4 -0
- package/dist/components/Text.js.map +1 -1
- package/dist/components/UDSProvider.cjs +1 -1
- package/dist/components/UDSProvider.js +1 -1
- package/dist/fontScaling/FontScalingContext.cjs +14 -0
- package/dist/fontScaling/FontScalingContext.d.cts +7 -1
- package/dist/fontScaling/FontScalingContext.d.cts.map +1 -1
- package/dist/fontScaling/FontScalingContext.d.ts +7 -1
- package/dist/fontScaling/FontScalingContext.d.ts.map +1 -1
- package/dist/fontScaling/FontScalingContext.js +15 -2
- package/dist/fontScaling/FontScalingContext.js.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.cjs +174 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js +175 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js.map +1 -0
- package/dist/fontScaling/constants.cjs +33 -0
- package/dist/fontScaling/constants.d.cts +11 -1
- package/dist/fontScaling/constants.d.cts.map +1 -1
- package/dist/fontScaling/constants.d.ts +11 -1
- package/dist/fontScaling/constants.d.ts.map +1 -1
- package/dist/fontScaling/constants.js +33 -1
- package/dist/fontScaling/constants.js.map +1 -1
- package/dist/fontScaling/index.cjs +2 -1
- package/dist/fontScaling/index.d.cts +2 -2
- package/dist/fontScaling/index.d.ts +2 -2
- package/dist/fontScaling/index.js +3 -3
- package/dist/fontScaling/useFontScale.cjs +13 -4
- package/dist/fontScaling/useFontScale.d.cts +8 -3
- package/dist/fontScaling/useFontScale.d.cts.map +1 -1
- package/dist/fontScaling/useFontScale.d.ts +8 -3
- package/dist/fontScaling/useFontScale.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.js +14 -5
- package/dist/fontScaling/useFontScale.js.map +1 -1
- package/dist/jest/mocks/styles.cjs +13 -1
- package/dist/jest/mocks/styles.d.cts.map +1 -1
- package/dist/jest/mocks/styles.d.ts.map +1 -1
- package/dist/jest/mocks/styles.js +13 -1
- package/dist/jest/mocks/styles.js.map +1 -1
- package/dist/portal.cjs +8 -2
- package/dist/portal.d.cts.map +1 -1
- package/dist/portal.d.ts.map +1 -1
- package/dist/portal.js +8 -2
- package/dist/portal.js.map +1 -1
- package/package.json +1 -1
package/dist/components/Text.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
import { DEFAULT_DYNAMIC_TYPE_RAMPS } from "../fontScaling/constants.js";
|
|
2
3
|
import { useMaxFontSizeMultiplier } from "../fontScaling/useMaxFontSizeMultiplier.js";
|
|
3
4
|
import { memo, useMemo } from "react";
|
|
4
5
|
import { Text as Text$1 } from "react-native";
|
|
@@ -53,6 +54,8 @@ const Text = memo(function Text({ color = "primary", variant = "body1", fontFami
|
|
|
53
54
|
const resolvedFontSize = fontSize ?? resolvedVariant;
|
|
54
55
|
const resolvedLineHeight = lineHeight === "none" ? void 0 : lineHeight ?? (hasCJKContent(children) ? void 0 : resolvedVariant);
|
|
55
56
|
const resolvedLetterSpacing = letterSpacing ?? resolvedVariant;
|
|
57
|
+
const baseVariant = resolvedVariant?.split("/")[0];
|
|
58
|
+
const defaultDynamicTypeRamp = baseVariant ? DEFAULT_DYNAMIC_TYPE_RAMPS[baseVariant] : void 0;
|
|
56
59
|
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier(resolvedVariant, maxFontSizeMultiplier);
|
|
57
60
|
styles.useVariants({
|
|
58
61
|
color: resolvedColor,
|
|
@@ -125,6 +128,7 @@ const Text = memo(function Text({ color = "primary", variant = "body1", fontFami
|
|
|
125
128
|
styles.foundation
|
|
126
129
|
]),
|
|
127
130
|
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
131
|
+
dynamicTypeRamp: defaultDynamicTypeRamp,
|
|
128
132
|
...props,
|
|
129
133
|
children
|
|
130
134
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.js","names":["RNText"],"sources":["../../src/components/Text.tsx"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport { memo, useMemo } from 'react';\nimport type { StyleProp, TextProps as RNTextProps, TextStyle } from 'react-native';\nimport { Text as RNText } from 'react-native';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { styles } from '../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\n\n// TextVariant is a subset of fontFamily that represents typography variants\ntype TextVariant = Exclude<\n NonNullable<StyleProps['fontFamily']>,\n 'sans' | 'sans-alt' | 'serif' | 'serif-alt' | 'mono' | 'icons'\n>;\ntype TextVariantProp = TextVariant | 'inherit';\n\n// React Native text decoration line values\n// See: https://reactnative.dev/docs/text-style-props#textdecorationline\ntype TextDecorationLine = 'none' | 'underline' | 'line-through' | 'underline line-through';\n\n// Chinese/Japanese/Korean scripts: Hangul Jamo, CJK radicals + punctuation,\n// Kana, Han ideographs, Hangul syllables, compatibility ideographs, and\n// full/half-width forms.\nconst CJK_RE =\n /[\\u1100-\\u11FF\\u2E80-\\u303F\\u3040-\\u30FF\\u31C0-\\u9FFF\\uAC00-\\uD7AF\\uF900-\\uFAFF\\uFF00-\\uFFEF]/;\n\n/**\n * Detects CJK characters in string children (including strings inside a\n * children array, e.g. from `{city}` interpolation). Nested elements are not\n * inspected - a nested <Text> runs its own detection.\n */\nfunction hasCJKContent(children: ReactNode): boolean {\n if (typeof children === 'string') {\n return CJK_RE.test(children);\n }\n if (Array.isArray(children)) {\n return children.some((child) => typeof child === 'string' && CJK_RE.test(child));\n }\n return false;\n}\n\ninterface TextProps extends RNTextProps {\n /** Ref to the underlying Text element */\n ref?: Ref<RNText>;\n /** Text color from the theme palette */\n color?: StyleProps['color'] | 'inherit';\n /** Typography variant - sets fontSize, lineHeight, letterSpacing, and fontFamily together */\n variant?: TextVariantProp;\n /**\n * Caps how far this text grows with the OS text-size setting. Every text\n * variant is capped at 2x or below by default, with the largest display and\n * title variants tapering further (see DEFAULT_MAX_FONT_SIZE_MULTIPLIERS).\n * Set null to remove the cap (maps to React Native's 0, which also overrides\n * an inherited cap); inherit-variant text inherits its parent's cap.\n * Override app-wide via UDSFontScalingProvider.\n */\n maxFontSizeMultiplier?: number | null;\n /** Override the fontFamily independently */\n fontFamily?: StyleProps['fontFamily'];\n /** Override the fontSize independently */\n fontSize?: StyleProps['fontSize'];\n /** Set font weight (not derived from variant) */\n fontWeight?: StyleProps['fontWeight'];\n /** Override the lineHeight independently. Use 'none' to remove the variant lineHeight and let the font's natural line height apply */\n lineHeight?: StyleProps['lineHeight'] | 'none';\n /** Override the letterSpacing independently */\n letterSpacing?: StyleProps['letterSpacing'];\n /** Text alignment (left, center, right) */\n textAlign?: StyleProps['textAlign'];\n /** Set text transform (not derived from variant) */\n textTransform?: StyleProps['textTransform'];\n /** Text decoration (underline, line-through, etc.) */\n textDecorationLine?: TextDecorationLine;\n // Background\n backgroundColor?: StyleProps['backgroundColor'];\n // Border\n borderRadius?: StyleProps['borderRadius'];\n borderTopStartRadius?: StyleProps['borderTopStartRadius'];\n borderTopEndRadius?: StyleProps['borderTopEndRadius'];\n borderBottomStartRadius?: StyleProps['borderBottomStartRadius'];\n borderBottomEndRadius?: StyleProps['borderBottomEndRadius'];\n borderColor?: StyleProps['borderColor'];\n borderStartColor?: StyleProps['borderStartColor'];\n borderEndColor?: StyleProps['borderEndColor'];\n borderTopColor?: StyleProps['borderTopColor'];\n borderBottomColor?: StyleProps['borderBottomColor'];\n borderWidth?: StyleProps['borderWidth'];\n borderVerticalWidth?: StyleProps['borderVerticalWidth'];\n borderHorizontalWidth?: StyleProps['borderHorizontalWidth'];\n borderStartWidth?: StyleProps['borderStartWidth'];\n borderEndWidth?: StyleProps['borderEndWidth'];\n borderTopWidth?: StyleProps['borderTopWidth'];\n borderBottomWidth?: StyleProps['borderBottomWidth'];\n // Spacing\n spacing?: StyleProps['spacing'];\n spacingHorizontal?: StyleProps['spacingHorizontal'];\n spacingVertical?: StyleProps['spacingVertical'];\n spacingBottom?: StyleProps['spacingBottom'];\n spacingEnd?: StyleProps['spacingEnd'];\n spacingStart?: StyleProps['spacingStart'];\n spacingTop?: StyleProps['spacingTop'];\n // Offset\n offset?: StyleProps['offset'];\n offsetVertical?: StyleProps['offsetVertical'];\n offsetHorizontal?: StyleProps['offsetHorizontal'];\n offsetBottom?: StyleProps['offsetBottom'];\n offsetEnd?: StyleProps['offsetEnd'];\n offsetStart?: StyleProps['offsetStart'];\n offsetTop?: StyleProps['offsetTop'];\n // Flex\n flexShrink?: StyleProps['flexShrink'];\n // Vertical Alignment\n verticalAlign?: TextStyle['textAlignVertical'];\n // Size\n height?: number | `${number}%`;\n width?: number | `${number}%`;\n minHeight?: number | `${number}%`;\n maxHeight?: number | `${number}%`;\n minWidth?: number | `${number}%`;\n maxWidth?: number | `${number}%`;\n // Dangerously set props\n dangerouslySetColor?: string;\n}\n\n/**\n * **📝 A text component with UDS styling**\n *\n * @description\n * A styled text component that supports UDS typography variants and colors.\n *\n * @category Display\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Text } from '@yahoo/uds-mobile/Text';\n *\n * <Text variant=\"body1\" color=\"primary\">Hello, World!</Text>\n * <Text variant=\"display1\" fontWeight=\"bold\">Heading</Text>\n * <Text variant=\"label1\" color=\"secondary\">Caption text</Text>\n * ```\n *\n * @usage\n * - Use variant prop to set typography (display1, body1, label1, etc.)\n * - Use color prop to set text color from the palette\n * - Use fontWeight to override the variant's default weight\n *\n * @accessibility\n * - Text is readable by screen readers by default\n * - Use appropriate variant sizes for readability\n * - Ensure sufficient color contrast with background\n *\n * @see {@link Link} for interactive text links\n */\nconst Text = memo(function Text({\n // Text-specific\n color = 'primary',\n variant = 'body1',\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n maxFontSizeMultiplier,\n textAlign,\n textTransform,\n textDecorationLine,\n style,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Spacing\n spacing,\n spacingHorizontal,\n spacingVertical,\n spacingBottom,\n spacingEnd,\n spacingStart,\n spacingTop,\n // Offset\n offset,\n offsetVertical,\n offsetHorizontal,\n offsetBottom,\n offsetEnd,\n offsetStart,\n offsetTop,\n // Flex\n flexShrink,\n // Vertical Alignment\n verticalAlign,\n // Size\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n // Dangerously set props\n dangerouslySetColor,\n ref,\n children,\n // Rest\n ...props\n}: TextProps) {\n const resolvedColor = color === 'inherit' ? undefined : color;\n const resolvedVariant = variant === 'inherit' ? undefined : variant;\n const resolvedFontFamily = fontFamily ?? resolvedVariant;\n const resolvedFontSize = fontSize ?? resolvedVariant;\n // React Native clips glyphs when lineHeight is smaller than the font's\n // natural line box. CJK fallback fonts are ~1.4x taller than Latin ones, so\n // Latin-tuned variant lineHeights clip CJK text - drop the variant lineHeight\n // for CJK content so the line grows to fit.\n const resolvedLineHeight =\n lineHeight === 'none'\n ? undefined\n : (lineHeight ?? (hasCJKContent(children) ? undefined : resolvedVariant));\n const resolvedLetterSpacing = letterSpacing ?? resolvedVariant;\n // Explicit prop wins, including explicit null (?? would swallow it).\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier(\n resolvedVariant,\n maxFontSizeMultiplier,\n );\n\n styles.useVariants({\n // Text styles\n color: resolvedColor,\n fontFamily: resolvedFontFamily,\n fontSize: resolvedFontSize,\n fontWeight,\n lineHeight: resolvedLineHeight,\n letterSpacing: resolvedLetterSpacing,\n textAlign,\n textTransform,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Spacing\n spacing,\n spacingHorizontal,\n spacingVertical,\n spacingBottom,\n spacingEnd,\n spacingStart,\n spacingTop,\n // Offset\n offset,\n offsetVertical,\n offsetHorizontal,\n offsetBottom,\n offsetEnd,\n offsetStart,\n offsetTop,\n // Flex\n flexShrink,\n });\n\n // styles.foundation must be in deps - it returns a new reference when variants change.\n const computedStyle: StyleProp<TextStyle> = useMemo(\n () => [\n textDecorationLine ? { textDecorationLine } : undefined,\n dangerouslySetColor ? { color: dangerouslySetColor } : undefined,\n verticalAlign ? { textAlignVertical: verticalAlign } : undefined,\n height ? { height } : undefined,\n minHeight ? { minHeight } : undefined,\n maxHeight ? { maxHeight } : undefined,\n width ? { width } : undefined,\n minWidth ? { minWidth } : undefined,\n maxWidth ? { maxWidth } : undefined,\n styles.foundation,\n style,\n ],\n [\n textDecorationLine,\n dangerouslySetColor,\n verticalAlign,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n style,\n styles.foundation,\n ],\n );\n\n return (\n <RNText\n ref={ref}\n style={computedStyle}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n {...props}\n >\n {children}\n </RNText>\n );\n});\n\nText.displayName = 'Text';\n\nexport { Text, type TextProps, type TextVariant };\n"],"mappings":";;;;;;;AAuBA,MAAM,SACJ;;;;;;AAOF,SAAS,cAAc,UAA8B;CACnD,IAAI,OAAO,aAAa,UACtB,OAAO,OAAO,KAAK,SAAS;CAE9B,IAAI,MAAM,QAAQ,SAAS,EACzB,OAAO,SAAS,MAAM,UAAU,OAAO,UAAU,YAAY,OAAO,KAAK,MAAM,CAAC;CAElF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHT,MAAM,OAAO,KAAK,SAAS,KAAK,EAE9B,QAAQ,WACR,UAAU,SACV,YACA,UACA,YACA,YACA,eACA,uBACA,WACA,eACA,oBACA,OAEA,iBAEA,cACA,sBACA,oBACA,yBACA,uBACA,aACA,kBACA,gBACA,gBACA,mBACA,aACA,qBACA,uBACA,kBACA,gBACA,gBACA,mBAEA,SACA,mBACA,iBACA,eACA,YACA,cACA,YAEA,QACA,gBACA,kBACA,cACA,WACA,aACA,WAEA,YAEA,eAEA,QACA,WACA,WACA,OACA,UACA,UAEA,qBACA,KACA,UAEA,GAAG,SACS;CACZ,MAAM,gBAAgB,UAAU,YAAY,KAAA,IAAY;CACxD,MAAM,kBAAkB,YAAY,YAAY,KAAA,IAAY;CAC5D,MAAM,qBAAqB,cAAc;CACzC,MAAM,mBAAmB,YAAY;CAKrC,MAAM,qBACJ,eAAe,SACX,KAAA,IACC,eAAe,cAAc,SAAS,GAAG,KAAA,IAAY;CAC5D,MAAM,wBAAwB,iBAAiB;CAE/C,MAAM,gCAAgC,yBACpC,iBACA,sBACD;CAED,OAAO,YAAY;EAEjB,OAAO;EACP,YAAY;EACZ,UAAU;EACV;EACA,YAAY;EACZ,eAAe;EACf;EACA;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACD,CAAC;CAgCF,OACE,oBAACA,QAAD;EACO;EACL,OAhCwC,cACpC;GACJ,qBAAqB,EAAE,oBAAoB,GAAG,KAAA;GAC9C,sBAAsB,EAAE,OAAO,qBAAqB,GAAG,KAAA;GACvD,gBAAgB,EAAE,mBAAmB,eAAe,GAAG,KAAA;GACvD,SAAS,EAAE,QAAQ,GAAG,KAAA;GACtB,YAAY,EAAE,WAAW,GAAG,KAAA;GAC5B,YAAY,EAAE,WAAW,GAAG,KAAA;GAC5B,QAAQ,EAAE,OAAO,GAAG,KAAA;GACpB,WAAW,EAAE,UAAU,GAAG,KAAA;GAC1B,WAAW,EAAE,UAAU,GAAG,KAAA;GAC1B,OAAO;GACP;GACD,EACD;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;GACR,CAMqB;EACpB,uBAAuB;EACvB,GAAI;EAEH;EACM,CAAA;EAEX;AAEF,KAAK,cAAc"}
|
|
1
|
+
{"version":3,"file":"Text.js","names":["RNText"],"sources":["../../src/components/Text.tsx"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport { memo, useMemo } from 'react';\nimport type { StyleProp, TextProps as RNTextProps, TextStyle } from 'react-native';\nimport { Text as RNText } from 'react-native';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { styles } from '../../generated/styles';\nimport { DEFAULT_DYNAMIC_TYPE_RAMPS } from '../fontScaling/constants';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\n\n// TextVariant is a subset of fontFamily that represents typography variants\ntype TextVariant = Exclude<\n NonNullable<StyleProps['fontFamily']>,\n 'sans' | 'sans-alt' | 'serif' | 'serif-alt' | 'mono' | 'icons'\n>;\ntype TextVariantProp = TextVariant | 'inherit';\n\n// React Native text decoration line values\n// See: https://reactnative.dev/docs/text-style-props#textdecorationline\ntype TextDecorationLine = 'none' | 'underline' | 'line-through' | 'underline line-through';\n\n// Chinese/Japanese/Korean scripts: Hangul Jamo, CJK radicals + punctuation,\n// Kana, Han ideographs, Hangul syllables, compatibility ideographs, and\n// full/half-width forms.\nconst CJK_RE =\n /[\\u1100-\\u11FF\\u2E80-\\u303F\\u3040-\\u30FF\\u31C0-\\u9FFF\\uAC00-\\uD7AF\\uF900-\\uFAFF\\uFF00-\\uFFEF]/;\n\n/**\n * Detects CJK characters in string children (including strings inside a\n * children array, e.g. from `{city}` interpolation). Nested elements are not\n * inspected - a nested <Text> runs its own detection.\n */\nfunction hasCJKContent(children: ReactNode): boolean {\n if (typeof children === 'string') {\n return CJK_RE.test(children);\n }\n if (Array.isArray(children)) {\n return children.some((child) => typeof child === 'string' && CJK_RE.test(child));\n }\n return false;\n}\n\ninterface TextProps extends RNTextProps {\n /** Ref to the underlying Text element */\n ref?: Ref<RNText>;\n /** Text color from the theme palette */\n color?: StyleProps['color'] | 'inherit';\n /** Typography variant - sets fontSize, lineHeight, letterSpacing, and fontFamily together */\n variant?: TextVariantProp;\n /**\n * Caps how far this text grows with the OS text-size setting. Every text\n * variant is capped at 2x or below by default, with the largest display and\n * title variants tapering further (see DEFAULT_MAX_FONT_SIZE_MULTIPLIERS).\n * Set null to remove the cap (maps to React Native's 0, which also overrides\n * an inherited cap); inherit-variant text inherits its parent's cap.\n * Override app-wide via UDSFontScalingProvider.\n */\n maxFontSizeMultiplier?: number | null;\n /** Override the fontFamily independently */\n fontFamily?: StyleProps['fontFamily'];\n /** Override the fontSize independently */\n fontSize?: StyleProps['fontSize'];\n /** Set font weight (not derived from variant) */\n fontWeight?: StyleProps['fontWeight'];\n /** Override the lineHeight independently. Use 'none' to remove the variant lineHeight and let the font's natural line height apply */\n lineHeight?: StyleProps['lineHeight'] | 'none';\n /** Override the letterSpacing independently */\n letterSpacing?: StyleProps['letterSpacing'];\n /** Text alignment (left, center, right) */\n textAlign?: StyleProps['textAlign'];\n /** Set text transform (not derived from variant) */\n textTransform?: StyleProps['textTransform'];\n /** Text decoration (underline, line-through, etc.) */\n textDecorationLine?: TextDecorationLine;\n // Background\n backgroundColor?: StyleProps['backgroundColor'];\n // Border\n borderRadius?: StyleProps['borderRadius'];\n borderTopStartRadius?: StyleProps['borderTopStartRadius'];\n borderTopEndRadius?: StyleProps['borderTopEndRadius'];\n borderBottomStartRadius?: StyleProps['borderBottomStartRadius'];\n borderBottomEndRadius?: StyleProps['borderBottomEndRadius'];\n borderColor?: StyleProps['borderColor'];\n borderStartColor?: StyleProps['borderStartColor'];\n borderEndColor?: StyleProps['borderEndColor'];\n borderTopColor?: StyleProps['borderTopColor'];\n borderBottomColor?: StyleProps['borderBottomColor'];\n borderWidth?: StyleProps['borderWidth'];\n borderVerticalWidth?: StyleProps['borderVerticalWidth'];\n borderHorizontalWidth?: StyleProps['borderHorizontalWidth'];\n borderStartWidth?: StyleProps['borderStartWidth'];\n borderEndWidth?: StyleProps['borderEndWidth'];\n borderTopWidth?: StyleProps['borderTopWidth'];\n borderBottomWidth?: StyleProps['borderBottomWidth'];\n // Spacing\n spacing?: StyleProps['spacing'];\n spacingHorizontal?: StyleProps['spacingHorizontal'];\n spacingVertical?: StyleProps['spacingVertical'];\n spacingBottom?: StyleProps['spacingBottom'];\n spacingEnd?: StyleProps['spacingEnd'];\n spacingStart?: StyleProps['spacingStart'];\n spacingTop?: StyleProps['spacingTop'];\n // Offset\n offset?: StyleProps['offset'];\n offsetVertical?: StyleProps['offsetVertical'];\n offsetHorizontal?: StyleProps['offsetHorizontal'];\n offsetBottom?: StyleProps['offsetBottom'];\n offsetEnd?: StyleProps['offsetEnd'];\n offsetStart?: StyleProps['offsetStart'];\n offsetTop?: StyleProps['offsetTop'];\n // Flex\n flexShrink?: StyleProps['flexShrink'];\n // Vertical Alignment\n verticalAlign?: TextStyle['textAlignVertical'];\n // Size\n height?: number | `${number}%`;\n width?: number | `${number}%`;\n minHeight?: number | `${number}%`;\n maxHeight?: number | `${number}%`;\n minWidth?: number | `${number}%`;\n maxWidth?: number | `${number}%`;\n // Dangerously set props\n dangerouslySetColor?: string;\n}\n\n/**\n * **📝 A text component with UDS styling**\n *\n * @description\n * A styled text component that supports UDS typography variants and colors.\n *\n * @category Display\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Text } from '@yahoo/uds-mobile/Text';\n *\n * <Text variant=\"body1\" color=\"primary\">Hello, World!</Text>\n * <Text variant=\"display1\" fontWeight=\"bold\">Heading</Text>\n * <Text variant=\"label1\" color=\"secondary\">Caption text</Text>\n * ```\n *\n * @usage\n * - Use variant prop to set typography (display1, body1, label1, etc.)\n * - Use color prop to set text color from the palette\n * - Use fontWeight to override the variant's default weight\n *\n * @accessibility\n * - Text is readable by screen readers by default\n * - Use appropriate variant sizes for readability\n * - Ensure sufficient color contrast with background\n *\n * @see {@link Link} for interactive text links\n */\nconst Text = memo(function Text({\n // Text-specific\n color = 'primary',\n variant = 'body1',\n fontFamily,\n fontSize,\n fontWeight,\n lineHeight,\n letterSpacing,\n maxFontSizeMultiplier,\n textAlign,\n textTransform,\n textDecorationLine,\n style,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Spacing\n spacing,\n spacingHorizontal,\n spacingVertical,\n spacingBottom,\n spacingEnd,\n spacingStart,\n spacingTop,\n // Offset\n offset,\n offsetVertical,\n offsetHorizontal,\n offsetBottom,\n offsetEnd,\n offsetStart,\n offsetTop,\n // Flex\n flexShrink,\n // Vertical Alignment\n verticalAlign,\n // Size\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n // Dangerously set props\n dangerouslySetColor,\n ref,\n children,\n // Rest\n ...props\n}: TextProps) {\n const resolvedColor = color === 'inherit' ? undefined : color;\n const resolvedVariant = variant === 'inherit' ? undefined : variant;\n const resolvedFontFamily = fontFamily ?? resolvedVariant;\n const resolvedFontSize = fontSize ?? resolvedVariant;\n // React Native clips glyphs when lineHeight is smaller than the font's\n // natural line box. CJK fallback fonts are ~1.4x taller than Latin ones, so\n // Latin-tuned variant lineHeights clip CJK text - drop the variant lineHeight\n // for CJK content so the line grows to fit.\n const resolvedLineHeight =\n lineHeight === 'none'\n ? undefined\n : (lineHeight ?? (hasCJKContent(children) ? undefined : resolvedVariant));\n const resolvedLetterSpacing = letterSpacing ?? resolvedVariant;\n const baseVariant = resolvedVariant?.split('/')[0] as TextVariant | undefined;\n const defaultDynamicTypeRamp = baseVariant ? DEFAULT_DYNAMIC_TYPE_RAMPS[baseVariant] : undefined;\n // Explicit prop wins, including explicit null (?? would swallow it).\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier(\n resolvedVariant,\n maxFontSizeMultiplier,\n );\n\n styles.useVariants({\n // Text styles\n color: resolvedColor,\n fontFamily: resolvedFontFamily,\n fontSize: resolvedFontSize,\n fontWeight,\n lineHeight: resolvedLineHeight,\n letterSpacing: resolvedLetterSpacing,\n textAlign,\n textTransform,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Spacing\n spacing,\n spacingHorizontal,\n spacingVertical,\n spacingBottom,\n spacingEnd,\n spacingStart,\n spacingTop,\n // Offset\n offset,\n offsetVertical,\n offsetHorizontal,\n offsetBottom,\n offsetEnd,\n offsetStart,\n offsetTop,\n // Flex\n flexShrink,\n });\n\n // styles.foundation must be in deps - it returns a new reference when variants change.\n const computedStyle: StyleProp<TextStyle> = useMemo(\n () => [\n textDecorationLine ? { textDecorationLine } : undefined,\n dangerouslySetColor ? { color: dangerouslySetColor } : undefined,\n verticalAlign ? { textAlignVertical: verticalAlign } : undefined,\n height ? { height } : undefined,\n minHeight ? { minHeight } : undefined,\n maxHeight ? { maxHeight } : undefined,\n width ? { width } : undefined,\n minWidth ? { minWidth } : undefined,\n maxWidth ? { maxWidth } : undefined,\n styles.foundation,\n style,\n ],\n [\n textDecorationLine,\n dangerouslySetColor,\n verticalAlign,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n style,\n styles.foundation,\n ],\n );\n\n return (\n <RNText\n ref={ref}\n style={computedStyle}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n dynamicTypeRamp={defaultDynamicTypeRamp}\n {...props}\n >\n {children}\n </RNText>\n );\n});\n\nText.displayName = 'Text';\n\nexport { Text, type TextProps, type TextVariant };\n"],"mappings":";;;;;;;;AAwBA,MAAM,SACJ;;;;;;AAOF,SAAS,cAAc,UAA8B;CACnD,IAAI,OAAO,aAAa,UACtB,OAAO,OAAO,KAAK,SAAS;CAE9B,IAAI,MAAM,QAAQ,SAAS,EACzB,OAAO,SAAS,MAAM,UAAU,OAAO,UAAU,YAAY,OAAO,KAAK,MAAM,CAAC;CAElF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHT,MAAM,OAAO,KAAK,SAAS,KAAK,EAE9B,QAAQ,WACR,UAAU,SACV,YACA,UACA,YACA,YACA,eACA,uBACA,WACA,eACA,oBACA,OAEA,iBAEA,cACA,sBACA,oBACA,yBACA,uBACA,aACA,kBACA,gBACA,gBACA,mBACA,aACA,qBACA,uBACA,kBACA,gBACA,gBACA,mBAEA,SACA,mBACA,iBACA,eACA,YACA,cACA,YAEA,QACA,gBACA,kBACA,cACA,WACA,aACA,WAEA,YAEA,eAEA,QACA,WACA,WACA,OACA,UACA,UAEA,qBACA,KACA,UAEA,GAAG,SACS;CACZ,MAAM,gBAAgB,UAAU,YAAY,KAAA,IAAY;CACxD,MAAM,kBAAkB,YAAY,YAAY,KAAA,IAAY;CAC5D,MAAM,qBAAqB,cAAc;CACzC,MAAM,mBAAmB,YAAY;CAKrC,MAAM,qBACJ,eAAe,SACX,KAAA,IACC,eAAe,cAAc,SAAS,GAAG,KAAA,IAAY;CAC5D,MAAM,wBAAwB,iBAAiB;CAC/C,MAAM,cAAc,iBAAiB,MAAM,IAAI,CAAC;CAChD,MAAM,yBAAyB,cAAc,2BAA2B,eAAe,KAAA;CAEvF,MAAM,gCAAgC,yBACpC,iBACA,sBACD;CAED,OAAO,YAAY;EAEjB,OAAO;EACP,YAAY;EACZ,UAAU;EACV;EACA,YAAY;EACZ,eAAe;EACf;EACA;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACD,CAAC;CAgCF,OACE,oBAACA,QAAD;EACO;EACL,OAhCwC,cACpC;GACJ,qBAAqB,EAAE,oBAAoB,GAAG,KAAA;GAC9C,sBAAsB,EAAE,OAAO,qBAAqB,GAAG,KAAA;GACvD,gBAAgB,EAAE,mBAAmB,eAAe,GAAG,KAAA;GACvD,SAAS,EAAE,QAAQ,GAAG,KAAA;GACtB,YAAY,EAAE,WAAW,GAAG,KAAA;GAC5B,YAAY,EAAE,WAAW,GAAG,KAAA;GAC5B,QAAQ,EAAE,OAAO,GAAG,KAAA;GACpB,WAAW,EAAE,UAAU,GAAG,KAAA;GAC1B,WAAW,EAAE,UAAU,GAAG,KAAA;GAC1B,OAAO;GACP;GACD,EACD;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;GACR,CAMqB;EACpB,uBAAuB;EACvB,iBAAiB;EACjB,GAAI;EAEH;EACM,CAAA;EAEX;AAEF,KAAK,cAAc"}
|
|
@@ -1,8 +1,8 @@
|
|
|
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_portal = require("../portal.cjs");
|
|
5
4
|
const require_fontScaling_FontScalingContext = require("../fontScaling/FontScalingContext.cjs");
|
|
5
|
+
const require_portal = require("../portal.cjs");
|
|
6
6
|
let react = require("react");
|
|
7
7
|
let react_native = require("react-native");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
-
import { PortalProvider } from "../portal.js";
|
|
3
2
|
import { UDSFontScalingProvider } from "../fontScaling/FontScalingContext.js";
|
|
3
|
+
import { PortalProvider } from "../portal.js";
|
|
4
4
|
import { memo } from "react";
|
|
5
5
|
import { StyleSheet } from "react-native";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -31,6 +31,20 @@ const UDSFontScalingProvider = (0, react.memo)(function UDSFontScalingProvider({
|
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
UDSFontScalingProvider.displayName = "UDSFontScalingProvider";
|
|
34
|
+
/** Keeps custom UDS content inside a control on the control's resolved cap. */
|
|
35
|
+
const ResolvedControlFontScalingProvider = (0, react.memo)(function ResolvedControlFontScalingProvider({ maxFontSizeMultiplier, children }) {
|
|
36
|
+
const cap = maxFontSizeMultiplier === 0 ? null : maxFontSizeMultiplier;
|
|
37
|
+
const config = (0, react.useMemo)(() => ({
|
|
38
|
+
default: cap,
|
|
39
|
+
control: cap
|
|
40
|
+
}), [cap]);
|
|
41
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontScalingContext.Provider, {
|
|
42
|
+
value: config,
|
|
43
|
+
children
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
ResolvedControlFontScalingProvider.displayName = "ResolvedControlFontScalingProvider";
|
|
34
47
|
//#endregion
|
|
35
48
|
exports.FontScalingContext = FontScalingContext;
|
|
49
|
+
exports.ResolvedControlFontScalingProvider = ResolvedControlFontScalingProvider;
|
|
36
50
|
exports.UDSFontScalingProvider = UDSFontScalingProvider;
|
|
@@ -34,6 +34,12 @@ interface UDSFontScalingProviderProps {
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
declare const UDSFontScalingProvider: _$react.NamedExoticComponent<UDSFontScalingProviderProps>;
|
|
37
|
+
interface ResolvedControlFontScalingProviderProps {
|
|
38
|
+
maxFontSizeMultiplier: number;
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/** Keeps custom UDS content inside a control on the control's resolved cap. */
|
|
42
|
+
declare const ResolvedControlFontScalingProvider: _$react.NamedExoticComponent<ResolvedControlFontScalingProviderProps>;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { FontScalingContext, UDSFontScalingProvider, type UDSFontScalingProviderProps };
|
|
44
|
+
export { FontScalingContext, ResolvedControlFontScalingProvider, UDSFontScalingProvider, type UDSFontScalingProviderProps };
|
|
39
45
|
//# sourceMappingURL=FontScalingContext.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontScalingContext.d.cts","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"mappings":";;;;;;cAMM,kBAAA,EAAkB,OAAA,CAAA,OAAA,CAAA,iBAAA;AAAA,UAEd,2BAAA;;AALuC;;;;EAW/C,MAAA,EAAQ,iBAAA;EACR,QAAA,EAAU,SAAA;AAAA;;;;;;;;;AAAS
|
|
1
|
+
{"version":3,"file":"FontScalingContext.d.cts","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"mappings":";;;;;;cAMM,kBAAA,EAAkB,OAAA,CAAA,OAAA,CAAA,iBAAA;AAAA,UAEd,2BAAA;;AALuC;;;;EAW/C,MAAA,EAAQ,iBAAA;EACR,QAAA,EAAU,SAAA;AAAA;;;;;;;;;AAAS;;;;;AAsBO;;;;;;cAAtB,sBAAA,EAAsB,OAAA,CAAA,oBAAA,CAAA,2BAAA;AAAA,UASlB,uCAAA;EACR,qBAAA;EACA,QAAA,EAAU,SAAA;AAAA;;cAIN,kCAAA,EAAkC,OAAA,CAAA,oBAAA,CAAA,uCAAA"}
|
|
@@ -34,6 +34,12 @@ interface UDSFontScalingProviderProps {
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
declare const UDSFontScalingProvider: _$react.NamedExoticComponent<UDSFontScalingProviderProps>;
|
|
37
|
+
interface ResolvedControlFontScalingProviderProps {
|
|
38
|
+
maxFontSizeMultiplier: number;
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/** Keeps custom UDS content inside a control on the control's resolved cap. */
|
|
42
|
+
declare const ResolvedControlFontScalingProvider: _$react.NamedExoticComponent<ResolvedControlFontScalingProviderProps>;
|
|
37
43
|
//#endregion
|
|
38
|
-
export { FontScalingContext, UDSFontScalingProvider, type UDSFontScalingProviderProps };
|
|
44
|
+
export { FontScalingContext, ResolvedControlFontScalingProvider, UDSFontScalingProvider, type UDSFontScalingProviderProps };
|
|
39
45
|
//# sourceMappingURL=FontScalingContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontScalingContext.d.ts","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"mappings":";;;;;;cAMM,kBAAA,EAAkB,OAAA,CAAA,OAAA,CAAA,iBAAA;AAAA,UAEd,2BAAA;;AALuC;;;;EAW/C,MAAA,EAAQ,iBAAA;EACR,QAAA,EAAU,SAAA;AAAA;;;;;;;;;AAAS
|
|
1
|
+
{"version":3,"file":"FontScalingContext.d.ts","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"mappings":";;;;;;cAMM,kBAAA,EAAkB,OAAA,CAAA,OAAA,CAAA,iBAAA;AAAA,UAEd,2BAAA;;AALuC;;;;EAW/C,MAAA,EAAQ,iBAAA;EACR,QAAA,EAAU,SAAA;AAAA;;;;;;;;;AAAS;;;;;AAsBO;;;;;;cAAtB,sBAAA,EAAsB,OAAA,CAAA,oBAAA,CAAA,2BAAA;AAAA,UASlB,uCAAA;EACR,qBAAA;EACA,QAAA,EAAU,SAAA;AAAA;;cAIN,kCAAA,EAAkC,OAAA,CAAA,oBAAA,CAAA,uCAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
-
import { createContext, memo } from "react";
|
|
2
|
+
import { createContext, memo, useMemo } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/fontScaling/FontScalingContext.tsx
|
|
5
5
|
const FontScalingContext = createContext(void 0);
|
|
@@ -29,7 +29,20 @@ const UDSFontScalingProvider = memo(function UDSFontScalingProvider({ config, ch
|
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
UDSFontScalingProvider.displayName = "UDSFontScalingProvider";
|
|
32
|
+
/** Keeps custom UDS content inside a control on the control's resolved cap. */
|
|
33
|
+
const ResolvedControlFontScalingProvider = memo(function ResolvedControlFontScalingProvider({ maxFontSizeMultiplier, children }) {
|
|
34
|
+
const cap = maxFontSizeMultiplier === 0 ? null : maxFontSizeMultiplier;
|
|
35
|
+
const config = useMemo(() => ({
|
|
36
|
+
default: cap,
|
|
37
|
+
control: cap
|
|
38
|
+
}), [cap]);
|
|
39
|
+
return /* @__PURE__ */ jsx(FontScalingContext.Provider, {
|
|
40
|
+
value: config,
|
|
41
|
+
children
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
ResolvedControlFontScalingProvider.displayName = "ResolvedControlFontScalingProvider";
|
|
32
45
|
//#endregion
|
|
33
|
-
export { FontScalingContext, UDSFontScalingProvider };
|
|
46
|
+
export { FontScalingContext, ResolvedControlFontScalingProvider, UDSFontScalingProvider };
|
|
34
47
|
|
|
35
48
|
//# sourceMappingURL=FontScalingContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontScalingContext.js","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { createContext, memo } from 'react';\n\nimport type { FontScalingConfig } from './types';\n\n// undefined = no provider mounted; built-in defaults apply.\nconst FontScalingContext = createContext<FontScalingConfig | undefined>(undefined);\n\ninterface UDSFontScalingProviderProps {\n /**\n * Font-scaling caps for the subtree. Should be identity-stable (a module\n * constant or memoized) — every UDS text element reads it from context.\n * The nearest provider wins wholesale; configs are not merged.\n */\n config: FontScalingConfig;\n children: ReactNode;\n}\n\n/**\n * **🔠 Overrides UDS font-scaling caps for a subtree**\n *\n * @description\n * Configures how UDS text and controls respond to the OS text-size setting.\n * Without a provider, built-in defaults apply (every text style is capped at\n * 2x or below, with the largest display/title tiers tapered further, and\n * control internals capped at 2x). Most apps set this once at the root via the\n * `fontScaling` prop on `UDSGestureProvider`.\n *\n * @example\n * ```tsx\n * const FONT_SCALING = { default: 2, variants: { display1: 1.75 } };\n *\n * <UDSFontScalingProvider config={FONT_SCALING}>\n * <App />\n * </UDSFontScalingProvider>\n * ```\n */\nconst UDSFontScalingProvider = memo(function UDSFontScalingProvider({\n config,\n children,\n}: UDSFontScalingProviderProps) {\n return <FontScalingContext.Provider value={config}>{children}</FontScalingContext.Provider>;\n});\n\nUDSFontScalingProvider.displayName = 'UDSFontScalingProvider';\n\
|
|
1
|
+
{"version":3,"file":"FontScalingContext.js","names":[],"sources":["../../src/fontScaling/FontScalingContext.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { createContext, memo, useMemo } from 'react';\n\nimport type { FontScalingConfig } from './types';\n\n// undefined = no provider mounted; built-in defaults apply.\nconst FontScalingContext = createContext<FontScalingConfig | undefined>(undefined);\n\ninterface UDSFontScalingProviderProps {\n /**\n * Font-scaling caps for the subtree. Should be identity-stable (a module\n * constant or memoized) — every UDS text element reads it from context.\n * The nearest provider wins wholesale; configs are not merged.\n */\n config: FontScalingConfig;\n children: ReactNode;\n}\n\n/**\n * **🔠 Overrides UDS font-scaling caps for a subtree**\n *\n * @description\n * Configures how UDS text and controls respond to the OS text-size setting.\n * Without a provider, built-in defaults apply (every text style is capped at\n * 2x or below, with the largest display/title tiers tapered further, and\n * control internals capped at 2x). Most apps set this once at the root via the\n * `fontScaling` prop on `UDSGestureProvider`.\n *\n * @example\n * ```tsx\n * const FONT_SCALING = { default: 2, variants: { display1: 1.75 } };\n *\n * <UDSFontScalingProvider config={FONT_SCALING}>\n * <App />\n * </UDSFontScalingProvider>\n * ```\n */\nconst UDSFontScalingProvider = memo(function UDSFontScalingProvider({\n config,\n children,\n}: UDSFontScalingProviderProps) {\n return <FontScalingContext.Provider value={config}>{children}</FontScalingContext.Provider>;\n});\n\nUDSFontScalingProvider.displayName = 'UDSFontScalingProvider';\n\ninterface ResolvedControlFontScalingProviderProps {\n maxFontSizeMultiplier: number;\n children: ReactNode;\n}\n\n/** Keeps custom UDS content inside a control on the control's resolved cap. */\nconst ResolvedControlFontScalingProvider = memo(function ResolvedControlFontScalingProvider({\n maxFontSizeMultiplier,\n children,\n}: ResolvedControlFontScalingProviderProps) {\n const cap = maxFontSizeMultiplier === 0 ? null : maxFontSizeMultiplier;\n const config = useMemo<FontScalingConfig>(() => ({ default: cap, control: cap }), [cap]);\n\n return <FontScalingContext.Provider value={config}>{children}</FontScalingContext.Provider>;\n});\n\nResolvedControlFontScalingProvider.displayName = 'ResolvedControlFontScalingProvider';\n\nexport {\n FontScalingContext,\n ResolvedControlFontScalingProvider,\n UDSFontScalingProvider,\n type UDSFontScalingProviderProps,\n};\n"],"mappings":";;;;AAMA,MAAM,qBAAqB,cAA6C,KAAA,EAAU;;;;;;;;;;;;;;;;;;;;AA+BlF,MAAM,yBAAyB,KAAK,SAAS,uBAAuB,EAClE,QACA,YAC8B;CAC9B,OAAO,oBAAC,mBAAmB,UAApB;EAA6B,OAAO;EAAS;EAAuC,CAAA;EAC3F;AAEF,uBAAuB,cAAc;;AAQrC,MAAM,qCAAqC,KAAK,SAAS,mCAAmC,EAC1F,uBACA,YAC0C;CAC1C,MAAM,MAAM,0BAA0B,IAAI,OAAO;CACjD,MAAM,SAAS,eAAkC;EAAE,SAAS;EAAK,SAAS;EAAK,GAAG,CAAC,IAAI,CAAC;CAExF,OAAO,oBAAC,mBAAmB,UAApB;EAA6B,OAAO;EAAS;EAAuC,CAAA;EAC3F;AAEF,mCAAmC,cAAc"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/fontScaling/androidNonlinearFontScaling.ts
|
|
4
|
+
/**
|
|
5
|
+
* Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`
|
|
6
|
+
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
7
|
+
* size that native Text renders.
|
|
8
|
+
*
|
|
9
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Values between
|
|
10
|
+
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
11
|
+
*
|
|
12
|
+
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
13
|
+
*/
|
|
14
|
+
const COMMON_SP_SIZES = [
|
|
15
|
+
8,
|
|
16
|
+
10,
|
|
17
|
+
12,
|
|
18
|
+
14,
|
|
19
|
+
18,
|
|
20
|
+
20,
|
|
21
|
+
24,
|
|
22
|
+
30,
|
|
23
|
+
100
|
|
24
|
+
];
|
|
25
|
+
const ANDROID_FONT_SCALE_CURVES = [
|
|
26
|
+
{
|
|
27
|
+
scale: 1.05,
|
|
28
|
+
dp: [
|
|
29
|
+
8.4,
|
|
30
|
+
10.5,
|
|
31
|
+
12.6,
|
|
32
|
+
14.8,
|
|
33
|
+
18.6,
|
|
34
|
+
20.6,
|
|
35
|
+
24.4,
|
|
36
|
+
30,
|
|
37
|
+
100
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
scale: 1.1,
|
|
42
|
+
dp: [
|
|
43
|
+
8.8,
|
|
44
|
+
11,
|
|
45
|
+
13.2,
|
|
46
|
+
15.6,
|
|
47
|
+
19.2,
|
|
48
|
+
21.2,
|
|
49
|
+
24.8,
|
|
50
|
+
30,
|
|
51
|
+
100
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
scale: 1.15,
|
|
56
|
+
dp: [
|
|
57
|
+
9.2,
|
|
58
|
+
11.5,
|
|
59
|
+
13.8,
|
|
60
|
+
16.4,
|
|
61
|
+
19.8,
|
|
62
|
+
21.8,
|
|
63
|
+
25.2,
|
|
64
|
+
30,
|
|
65
|
+
100
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
scale: 1.2,
|
|
70
|
+
dp: [
|
|
71
|
+
9.6,
|
|
72
|
+
12,
|
|
73
|
+
14.4,
|
|
74
|
+
17.2,
|
|
75
|
+
20.4,
|
|
76
|
+
22.4,
|
|
77
|
+
25.6,
|
|
78
|
+
30,
|
|
79
|
+
100
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
scale: 1.3,
|
|
84
|
+
dp: [
|
|
85
|
+
10.4,
|
|
86
|
+
13,
|
|
87
|
+
15.6,
|
|
88
|
+
18.8,
|
|
89
|
+
21.6,
|
|
90
|
+
23.6,
|
|
91
|
+
26.4,
|
|
92
|
+
30,
|
|
93
|
+
100
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
scale: 1.5,
|
|
98
|
+
dp: [
|
|
99
|
+
12,
|
|
100
|
+
15,
|
|
101
|
+
18,
|
|
102
|
+
22,
|
|
103
|
+
24,
|
|
104
|
+
26,
|
|
105
|
+
28,
|
|
106
|
+
30,
|
|
107
|
+
100
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
scale: 1.8,
|
|
112
|
+
dp: [
|
|
113
|
+
14.4,
|
|
114
|
+
18,
|
|
115
|
+
21.6,
|
|
116
|
+
24.4,
|
|
117
|
+
27.6,
|
|
118
|
+
30.8,
|
|
119
|
+
32.8,
|
|
120
|
+
34.8,
|
|
121
|
+
100
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
scale: 2,
|
|
126
|
+
dp: [
|
|
127
|
+
16,
|
|
128
|
+
20,
|
|
129
|
+
24,
|
|
130
|
+
26,
|
|
131
|
+
30,
|
|
132
|
+
34,
|
|
133
|
+
36,
|
|
134
|
+
38,
|
|
135
|
+
100
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
function lerp(start, end, amount) {
|
|
140
|
+
return start + (end - start) * amount;
|
|
141
|
+
}
|
|
142
|
+
function interpolateSize(fontSize, dpValues) {
|
|
143
|
+
if (fontSize <= 0) return fontSize;
|
|
144
|
+
for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {
|
|
145
|
+
const currentSp = COMMON_SP_SIZES[index];
|
|
146
|
+
if (fontSize === currentSp) return dpValues[index];
|
|
147
|
+
if (fontSize < currentSp) {
|
|
148
|
+
const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];
|
|
149
|
+
const previousDp = index === 0 ? 0 : dpValues[index - 1];
|
|
150
|
+
const amount = (fontSize - previousSp) / (currentSp - previousSp);
|
|
151
|
+
return lerp(previousDp, dpValues[index], amount);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
155
|
+
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
156
|
+
}
|
|
157
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
158
|
+
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
159
|
+
const firstCurve = ANDROID_FONT_SCALE_CURVES[0];
|
|
160
|
+
const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_CURVES.length - 1];
|
|
161
|
+
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
162
|
+
for (let index = 0; index < ANDROID_FONT_SCALE_CURVES.length; index += 1) {
|
|
163
|
+
const curve = ANDROID_FONT_SCALE_CURVES[index];
|
|
164
|
+
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
165
|
+
if (fontScale < curve.scale) {
|
|
166
|
+
const previousCurve = ANDROID_FONT_SCALE_CURVES[index - 1];
|
|
167
|
+
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
168
|
+
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return fontSize * fontScale;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
exports.convertAndroidSpToDp = convertAndroidSpToDp;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { convertAndroidSpToDp };
|
|
7
|
+
//# sourceMappingURL=androidNonlinearFontScaling.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.cts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBAmDS,oBAAA,CAAqB,QAAA,UAAkB,SAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.d.ts
|
|
3
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
4
|
+
declare function convertAndroidSpToDp(fontSize: number, fontScale: number): number;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { convertAndroidSpToDp };
|
|
7
|
+
//# sourceMappingURL=androidNonlinearFontScaling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidNonlinearFontScaling.d.ts","names":[],"sources":["../../src/fontScaling/androidNonlinearFontScaling.ts"],"mappings":";;;iBAmDS,oBAAA,CAAqB,QAAA,UAAkB,SAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
//#region src/fontScaling/androidNonlinearFontScaling.ts
|
|
3
|
+
/**
|
|
4
|
+
* Android 14+ converts SP through a size-dependent curve. `Configuration.fontScale`
|
|
5
|
+
* is only the user's preference; multiplying by it directly does not reproduce the
|
|
6
|
+
* size that native Text renders.
|
|
7
|
+
*
|
|
8
|
+
* These lookup tables mirror Android's `FontScaleConverterFactory`. Values between
|
|
9
|
+
* table entries are linearly interpolated, as they are in the platform implementation.
|
|
10
|
+
*
|
|
11
|
+
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/content/res/FontScaleConverterFactory.java
|
|
12
|
+
*/
|
|
13
|
+
const COMMON_SP_SIZES = [
|
|
14
|
+
8,
|
|
15
|
+
10,
|
|
16
|
+
12,
|
|
17
|
+
14,
|
|
18
|
+
18,
|
|
19
|
+
20,
|
|
20
|
+
24,
|
|
21
|
+
30,
|
|
22
|
+
100
|
|
23
|
+
];
|
|
24
|
+
const ANDROID_FONT_SCALE_CURVES = [
|
|
25
|
+
{
|
|
26
|
+
scale: 1.05,
|
|
27
|
+
dp: [
|
|
28
|
+
8.4,
|
|
29
|
+
10.5,
|
|
30
|
+
12.6,
|
|
31
|
+
14.8,
|
|
32
|
+
18.6,
|
|
33
|
+
20.6,
|
|
34
|
+
24.4,
|
|
35
|
+
30,
|
|
36
|
+
100
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
scale: 1.1,
|
|
41
|
+
dp: [
|
|
42
|
+
8.8,
|
|
43
|
+
11,
|
|
44
|
+
13.2,
|
|
45
|
+
15.6,
|
|
46
|
+
19.2,
|
|
47
|
+
21.2,
|
|
48
|
+
24.8,
|
|
49
|
+
30,
|
|
50
|
+
100
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
scale: 1.15,
|
|
55
|
+
dp: [
|
|
56
|
+
9.2,
|
|
57
|
+
11.5,
|
|
58
|
+
13.8,
|
|
59
|
+
16.4,
|
|
60
|
+
19.8,
|
|
61
|
+
21.8,
|
|
62
|
+
25.2,
|
|
63
|
+
30,
|
|
64
|
+
100
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
scale: 1.2,
|
|
69
|
+
dp: [
|
|
70
|
+
9.6,
|
|
71
|
+
12,
|
|
72
|
+
14.4,
|
|
73
|
+
17.2,
|
|
74
|
+
20.4,
|
|
75
|
+
22.4,
|
|
76
|
+
25.6,
|
|
77
|
+
30,
|
|
78
|
+
100
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
scale: 1.3,
|
|
83
|
+
dp: [
|
|
84
|
+
10.4,
|
|
85
|
+
13,
|
|
86
|
+
15.6,
|
|
87
|
+
18.8,
|
|
88
|
+
21.6,
|
|
89
|
+
23.6,
|
|
90
|
+
26.4,
|
|
91
|
+
30,
|
|
92
|
+
100
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
scale: 1.5,
|
|
97
|
+
dp: [
|
|
98
|
+
12,
|
|
99
|
+
15,
|
|
100
|
+
18,
|
|
101
|
+
22,
|
|
102
|
+
24,
|
|
103
|
+
26,
|
|
104
|
+
28,
|
|
105
|
+
30,
|
|
106
|
+
100
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
scale: 1.8,
|
|
111
|
+
dp: [
|
|
112
|
+
14.4,
|
|
113
|
+
18,
|
|
114
|
+
21.6,
|
|
115
|
+
24.4,
|
|
116
|
+
27.6,
|
|
117
|
+
30.8,
|
|
118
|
+
32.8,
|
|
119
|
+
34.8,
|
|
120
|
+
100
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
scale: 2,
|
|
125
|
+
dp: [
|
|
126
|
+
16,
|
|
127
|
+
20,
|
|
128
|
+
24,
|
|
129
|
+
26,
|
|
130
|
+
30,
|
|
131
|
+
34,
|
|
132
|
+
36,
|
|
133
|
+
38,
|
|
134
|
+
100
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
function lerp(start, end, amount) {
|
|
139
|
+
return start + (end - start) * amount;
|
|
140
|
+
}
|
|
141
|
+
function interpolateSize(fontSize, dpValues) {
|
|
142
|
+
if (fontSize <= 0) return fontSize;
|
|
143
|
+
for (let index = 0; index < COMMON_SP_SIZES.length; index += 1) {
|
|
144
|
+
const currentSp = COMMON_SP_SIZES[index];
|
|
145
|
+
if (fontSize === currentSp) return dpValues[index];
|
|
146
|
+
if (fontSize < currentSp) {
|
|
147
|
+
const previousSp = index === 0 ? 0 : COMMON_SP_SIZES[index - 1];
|
|
148
|
+
const previousDp = index === 0 ? 0 : dpValues[index - 1];
|
|
149
|
+
const amount = (fontSize - previousSp) / (currentSp - previousSp);
|
|
150
|
+
return lerp(previousDp, dpValues[index], amount);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const lastIndex = COMMON_SP_SIZES.length - 1;
|
|
154
|
+
return fontSize * (dpValues[lastIndex] / COMMON_SP_SIZES[lastIndex]);
|
|
155
|
+
}
|
|
156
|
+
/** Converts an SP value to its Android 14+ nonlinear DP size. */
|
|
157
|
+
function convertAndroidSpToDp(fontSize, fontScale) {
|
|
158
|
+
const firstCurve = ANDROID_FONT_SCALE_CURVES[0];
|
|
159
|
+
const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_CURVES.length - 1];
|
|
160
|
+
if (fontScale < firstCurve.scale || fontScale > lastCurve.scale) return fontSize * fontScale;
|
|
161
|
+
for (let index = 0; index < ANDROID_FONT_SCALE_CURVES.length; index += 1) {
|
|
162
|
+
const curve = ANDROID_FONT_SCALE_CURVES[index];
|
|
163
|
+
if (fontScale === curve.scale) return interpolateSize(fontSize, curve.dp);
|
|
164
|
+
if (fontScale < curve.scale) {
|
|
165
|
+
const previousCurve = ANDROID_FONT_SCALE_CURVES[index - 1];
|
|
166
|
+
const amount = (fontScale - previousCurve.scale) / (curve.scale - previousCurve.scale);
|
|
167
|
+
return lerp(interpolateSize(fontSize, previousCurve.dp), interpolateSize(fontSize, curve.dp), amount);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return fontSize * fontScale;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { convertAndroidSpToDp };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=androidNonlinearFontScaling.js.map
|
|
@@ -0,0 +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 ANDROID_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 its Android 14+ nonlinear DP size. */\nfunction convertAndroidSpToDp(fontSize: number, fontScale: number): number {\n const firstCurve = ANDROID_FONT_SCALE_CURVES[0];\n const lastCurve = ANDROID_FONT_SCALE_CURVES[ANDROID_FONT_SCALE_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 < ANDROID_FONT_SCALE_CURVES.length; index += 1) {\n const curve = ANDROID_FONT_SCALE_CURVES[index];\n if (fontScale === curve.scale) {\n return interpolateSize(fontSize, curve.dp);\n }\n if (fontScale < curve.scale) {\n const previousCurve = ANDROID_FONT_SCALE_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":";;;;;;;;;;;;AAUA,MAAM,kBAAkB;CAAC;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;AAE5D,MAAM,4BAA4B;CAChC;EAAE,OAAO;EAAM,IAAI;GAAC;GAAK;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACvE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAK;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACpE;EAAE,OAAO;EAAM,IAAI;GAAC;GAAK;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACvE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAK;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACpE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAM;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;GAAI;EAAE;CACrE;EAAE,OAAO;EAAK,IAAI;GAAC;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;EAAE;CACzD;EAAE,OAAO;EAAK,IAAI;GAAC;GAAM;GAAI;GAAM;GAAM;GAAM;GAAM;GAAM;GAAM;GAAI;EAAE;CACvE;EAAE,OAAO;EAAG,IAAI;GAAC;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI;EAAE;CACxD;AAED,SAAS,KAAK,OAAe,KAAa,QAAwB;CAChE,OAAO,SAAS,MAAM,SAAS;;AAGjC,SAAS,gBAAgB,UAAkB,UAAqC;CAC9E,IAAI,YAAY,GACd,OAAO;CAGT,KAAK,IAAI,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ,SAAS,GAAG;EAC9D,MAAM,YAAY,gBAAgB;EAClC,IAAI,aAAa,WACf,OAAO,SAAS;EAElB,IAAI,WAAW,WAAW;GACxB,MAAM,aAAa,UAAU,IAAI,IAAI,gBAAgB,QAAQ;GAC7D,MAAM,aAAa,UAAU,IAAI,IAAK,SAAS,QAAQ;GACvD,MAAM,UAAU,WAAW,eAAe,YAAY;GACtD,OAAO,KAAK,YAAY,SAAS,QAAkB,OAAO;;;CAK9D,MAAM,YAAY,gBAAgB,SAAS;CAC3C,OAAO,YAAa,SAAS,aAAwB,gBAAgB;;;AAIvE,SAAS,qBAAqB,UAAkB,WAA2B;CACzE,MAAM,aAAa,0BAA0B;CAC7C,MAAM,YAAY,0BAA0B,0BAA0B,SAAS;CAG/E,IAAI,YAAY,WAAW,SAAS,YAAY,UAAU,OACxD,OAAO,WAAW;CAGpB,KAAK,IAAI,QAAQ,GAAG,QAAQ,0BAA0B,QAAQ,SAAS,GAAG;EACxE,MAAM,QAAQ,0BAA0B;EACxC,IAAI,cAAc,MAAM,OACtB,OAAO,gBAAgB,UAAU,MAAM,GAAG;EAE5C,IAAI,YAAY,MAAM,OAAO;GAC3B,MAAM,gBAAgB,0BAA0B,QAAQ;GACxD,MAAM,UAAU,YAAY,cAAc,UAAU,MAAM,QAAQ,cAAc;GAChF,OAAO,KACL,gBAAgB,UAAU,cAAc,GAAG,EAC3C,gBAAgB,UAAU,MAAM,GAAG,EACnC,OACD;;;CAIL,OAAO,WAAW"}
|
|
@@ -65,8 +65,41 @@ const DEFAULT_MAX_FONT_SIZE_MULTIPLIERS = Object.freeze(Object.fromEntries(Objec
|
|
|
65
65
|
* supported ceiling rather than a looser per-variant cap.
|
|
66
66
|
*/
|
|
67
67
|
const DEFAULT_CONTROL_MAX_FONT_SIZE_MULTIPLIER = 2;
|
|
68
|
+
/**
|
|
69
|
+
* iOS Dynamic Type curve used by each UDS typography tier. React Native uses
|
|
70
|
+
* the selected system text style's curve while preserving the configured UDS
|
|
71
|
+
* font size. Android ignores `dynamicTypeRamp` and continues to use its native
|
|
72
|
+
* nonlinear font scaling.
|
|
73
|
+
*
|
|
74
|
+
* Keys are base variants; `/emphasized` twins resolve to their base.
|
|
75
|
+
*/
|
|
76
|
+
const DEFAULT_DYNAMIC_TYPE_RAMPS = {
|
|
77
|
+
display1: "largeTitle",
|
|
78
|
+
display2: "largeTitle",
|
|
79
|
+
display3: "largeTitle",
|
|
80
|
+
title1: "title1",
|
|
81
|
+
title2: "title2",
|
|
82
|
+
title3: "title3",
|
|
83
|
+
title4: "title3",
|
|
84
|
+
headline1: "headline",
|
|
85
|
+
body1: "body",
|
|
86
|
+
label1: "callout",
|
|
87
|
+
label2: "subheadline",
|
|
88
|
+
label3: "footnote",
|
|
89
|
+
label4: "caption1",
|
|
90
|
+
caption1: "caption1",
|
|
91
|
+
caption2: "caption2",
|
|
92
|
+
legal1: "caption2",
|
|
93
|
+
ui1: "title3",
|
|
94
|
+
ui2: "title3",
|
|
95
|
+
ui3: "callout",
|
|
96
|
+
ui4: "subheadline",
|
|
97
|
+
ui5: "footnote",
|
|
98
|
+
ui6: "caption2"
|
|
99
|
+
};
|
|
68
100
|
//#endregion
|
|
69
101
|
exports.DEFAULT_CONTROL_MAX_FONT_SIZE_MULTIPLIER = DEFAULT_CONTROL_MAX_FONT_SIZE_MULTIPLIER;
|
|
102
|
+
exports.DEFAULT_DYNAMIC_TYPE_RAMPS = DEFAULT_DYNAMIC_TYPE_RAMPS;
|
|
70
103
|
exports.DEFAULT_MAX_FONT_SIZE_MULTIPLIERS = DEFAULT_MAX_FONT_SIZE_MULTIPLIERS;
|
|
71
104
|
exports.MAX_SUPPORTED_FONT_SCALE = MAX_SUPPORTED_FONT_SCALE;
|
|
72
105
|
exports.TYPE_SCALE_CURVE = TYPE_SCALE_CURVE;
|