fontdue-js 2.20.0 → 2.20.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.20.1
2
+
3
+ - Fixed `useAutofit` measuring multi-line text as a single line, causing the font size to be too small when type tester content contains line breaks
4
+
1
5
  ## 2.20.0
2
6
 
3
7
  - **Font loading now uses the FontFace API instead of CSS `@font-face`**. Fonts loaded by fontdue-js components (TypeTester, StoreModal, CharacterViewer, etc.) are no longer loaded via CSS stylesheet injection. Instead, font files are fetched as binary data and loaded via the browser's `FontFace` API. **Note:** components like TypeTesters and CharacterViewer previously loaded the entire family's CSS, which made all styles available page-wide as a side effect. They now only load the specific style they're rendering. If you render font styles outside of fontdue-js components (e.g., in a specimen section), you'll need to load those fonts yourself — either with the new `useFont` hook and `webfontSources`, or with your own `@font-face` rules.
@@ -87,10 +87,11 @@ const useAutofit = _ref => {
87
87
  const availableWidth = containerWidth - padding;
88
88
  if (availableWidth <= 0 || !text) return;
89
89
 
90
- // Use DOM measurement when variable font settings are active
91
- // (canvas doesn't support fontVariationSettings in most browsers).
92
- // Otherwise use canvas for better performance (no layout reflow).
93
- const refWidth = fontVariationSettings ? measureWithDOM(text, fontFamily, fontWeight, fontStyle, letterSpacing, fontVariationSettings) : measureWithCanvas(text, fontFamily, fontWeight, fontStyle, letterSpacing);
90
+ // Split by newlines and measure the widest line, since the rendered
91
+ // text preserves line breaks (Draft.js uses white-space: pre-wrap).
92
+ const lines = text.split('\n');
93
+ const measure = fontVariationSettings ? line => measureWithDOM(line, fontFamily, fontWeight, fontStyle, letterSpacing, fontVariationSettings) : line => measureWithCanvas(line, fontFamily, fontWeight, fontStyle, letterSpacing);
94
+ const refWidth = Math.max(...lines.map(measure));
94
95
  if (refWidth <= 0) return;
95
96
 
96
97
  // Text width scales linearly with font size.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fontdue-js",
3
- "version": "2.20.0",
3
+ "version": "2.20.1",
4
4
  "scripts": {
5
5
  "build": "npm run relay && run-p build-js build-css build-ts",
6
6
  "build-js": "babel src --out-dir dist --extensions .ts,.tsx,.js,.jsx",