@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.
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Measure the average character width ratio for a font using the Canvas API.
3
3
  *
4
- * Waits for the font to load via `document.fonts.load()` before measuring.
4
+ * Waits for the font to load via `document.fonts.load()` before measuring,
5
+ * with a 3-second timeout to prevent hangs when fonts fail to load silently.
5
6
  * Falls back to 0.55 if the browser context is unavailable, the font fails
6
7
  * to load, or canvas is not supported.
7
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"measureFont.d.ts","sourceRoot":"","sources":["../../src/fonts/measureFont.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAAK,GACZ,OAAO,CAAC,MAAM,CAAC,CAajB"}
1
+ {"version":3,"file":"measureFont.d.ts","sourceRoot":"","sources":["../../src/fonts/measureFont.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAAK,GACZ,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
package/dist/index.cjs CHANGED
@@ -840,10 +840,20 @@ function Icon({
840
840
 
841
841
  // src/fonts/measureFont.ts
842
842
  var REF_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
843
+ function withTimeout(promise, ms, fallback) {
844
+ return Promise.race([
845
+ promise,
846
+ new Promise((resolve) => setTimeout(() => resolve(fallback), ms))
847
+ ]);
848
+ }
843
849
  async function measureAvgCharWidth(fontFamily, fontWeight, fallback, fontSize = 16) {
844
850
  if (typeof document === "undefined") return 0.55;
845
851
  try {
846
- await document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`);
852
+ await withTimeout(
853
+ document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`),
854
+ 3e3,
855
+ []
856
+ );
847
857
  const canvas = document.createElement("canvas");
848
858
  const ctx = canvas.getContext("2d");
849
859
  if (!ctx) return 0.55;
@@ -993,6 +1003,7 @@ function TextBase({
993
1003
  role = "body",
994
1004
  color = "primary",
995
1005
  size: sizeOverride,
1006
+ weight: weightOverride,
996
1007
  align,
997
1008
  numberOfLines,
998
1009
  elevation = 1,
@@ -1009,7 +1020,7 @@ function TextBase({
1009
1020
  const { config, reportingEndpoint } = useNewtoneTheme();
1010
1021
  const size = sizeOverride ?? "md";
1011
1022
  const fontSlot = tokens.typography.fonts[scope];
1012
- const resolvedFontWeight = config.typography.roleWeights?.[role] ?? fonts.ROLE_DEFAULT_WEIGHTS[role];
1023
+ const resolvedFontWeight = weightOverride ? fonts.SEMANTIC_WEIGHT_MAP[weightOverride] : config.typography.roleWeights?.[role] ?? fonts.ROLE_DEFAULT_WEIGHTS[role];
1013
1024
  const breakpoint = useBreakpoint();
1014
1025
  const baseStep = config.typography.roles[role][size];
1015
1026
  const bpScale = fonts.BREAKPOINT_ROLE_SCALE[breakpoint][role];