@newtonedev/components 0.1.8 → 0.1.10
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/fonts/measureFont.d.ts +2 -1
- package/dist/fonts/measureFont.d.ts.map +1 -1
- package/dist/index.cjs +13 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/primitives/Text/Text.d.ts +1 -1
- package/dist/primitives/Text/Text.d.ts.map +1 -1
- package/dist/primitives/Text/Text.types.d.ts +2 -0
- package/dist/primitives/Text/Text.types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/fonts/measureFont.ts +15 -2
- package/src/primitives/Text/Text.tsx +4 -1
- package/src/primitives/Text/Text.types.ts +3 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React14, { createContext, useState, useMemo, useEffect, useContext, useCallback, useRef } from 'react';
|
|
2
2
|
import { srgbToHex, getColor, DEFAULT_NEUTRAL_SATURATION, DEFAULT_NEUTRAL_HUE, DEFAULT_ACCENT_SATURATION, DEFAULT_ACCENT_HUE, DEFAULT_SUCCESS_SATURATION, DEFAULT_SUCCESS_HUE, DEFAULT_WARNING_SATURATION, DEFAULT_WARNING_HUE, DEFAULT_ERROR_SATURATION, DEFAULT_ERROR_HUE } from 'newtone';
|
|
3
|
-
import { ROLE_DEFAULT_WEIGHTS, BREAKPOINT_ROLE_SCALE, scaleRoleStep,
|
|
3
|
+
import { SEMANTIC_WEIGHT_MAP, ROLE_DEFAULT_WEIGHTS, BREAKPOINT_ROLE_SCALE, scaleRoleStep, resolveResponsiveSize, estimateLineWidths, REFERENCE_LINE_HEIGHT_RATIO, buildFontFeatureSettings, getBreakpointForWidth, fontConfigToFamily, DEFAULT_ROLE_SCALES, DEFAULT_LINE_HEIGHTS, DEFAULT_FONT_SIZES, DEFAULT_FONT_SLOTS, buildGoogleFontsUrl } from '@newtonedev/fonts';
|
|
4
4
|
export { DEFAULT_FONT_SIZES, DEFAULT_LINE_HEIGHTS, DEFAULT_ROLE_SCALES, buildGoogleFontsUrl } from '@newtonedev/fonts';
|
|
5
5
|
import { Text, View, useWindowDimensions, Pressable, TextInput as TextInput$1, ScrollView, PanResponder, Animated, StyleSheet } from 'react-native';
|
|
6
6
|
|
|
@@ -835,10 +835,20 @@ function Icon({
|
|
|
835
835
|
|
|
836
836
|
// src/fonts/measureFont.ts
|
|
837
837
|
var REF_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
|
|
838
|
+
function withTimeout(promise, ms, fallback) {
|
|
839
|
+
return Promise.race([
|
|
840
|
+
promise,
|
|
841
|
+
new Promise((resolve) => setTimeout(() => resolve(fallback), ms))
|
|
842
|
+
]);
|
|
843
|
+
}
|
|
838
844
|
async function measureAvgCharWidth(fontFamily, fontWeight, fallback, fontSize = 16) {
|
|
839
845
|
if (typeof document === "undefined") return 0.55;
|
|
840
846
|
try {
|
|
841
|
-
await
|
|
847
|
+
await withTimeout(
|
|
848
|
+
document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`),
|
|
849
|
+
3e3,
|
|
850
|
+
[]
|
|
851
|
+
);
|
|
842
852
|
const canvas = document.createElement("canvas");
|
|
843
853
|
const ctx = canvas.getContext("2d");
|
|
844
854
|
if (!ctx) return 0.55;
|
|
@@ -988,6 +998,7 @@ function TextBase({
|
|
|
988
998
|
role = "body",
|
|
989
999
|
color = "primary",
|
|
990
1000
|
size: sizeOverride,
|
|
1001
|
+
weight: weightOverride,
|
|
991
1002
|
align,
|
|
992
1003
|
numberOfLines,
|
|
993
1004
|
elevation = 1,
|
|
@@ -1004,7 +1015,7 @@ function TextBase({
|
|
|
1004
1015
|
const { config, reportingEndpoint } = useNewtoneTheme();
|
|
1005
1016
|
const size = sizeOverride ?? "md";
|
|
1006
1017
|
const fontSlot = tokens.typography.fonts[scope];
|
|
1007
|
-
const resolvedFontWeight = config.typography.roleWeights?.[role] ?? ROLE_DEFAULT_WEIGHTS[role];
|
|
1018
|
+
const resolvedFontWeight = weightOverride ? SEMANTIC_WEIGHT_MAP[weightOverride] : config.typography.roleWeights?.[role] ?? ROLE_DEFAULT_WEIGHTS[role];
|
|
1008
1019
|
const breakpoint = useBreakpoint();
|
|
1009
1020
|
const baseStep = config.typography.roles[role][size];
|
|
1010
1021
|
const bpScale = BREAKPOINT_ROLE_SCALE[breakpoint][role];
|