From fefa69f0eef6b6bff93d5b12d9cd415d5a90bd7a Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Mar 2026 09:18:34 +0100 Subject: [PATCH 1/4] fix: handle font-stretch returned by font providers --- src/css/parse.ts | 4 ++++ test/extract.test.ts | 24 ++++++++++++++++++++++++ test/providers/adobe.test.ts | 2 ++ 3 files changed, 30 insertions(+) diff --git a/src/css/parse.ts b/src/css/parse.ts index 011057df..f5e00e21 100644 --- a/src/css/parse.ts +++ b/src/css/parse.ts @@ -7,6 +7,7 @@ const extractableKeyMap: Record = { 'src': 'src', 'font-display': 'display', 'font-weight': 'weight', + 'font-stretch': 'stretch', 'font-style': 'style', 'font-feature-settings': 'featureSettings', 'font-variation-settings': 'variationSettings', @@ -130,6 +131,9 @@ function extractCSSValue(node: Declaration) { if (child.type === 'Number') { values.push(Number(child.value)) } + if (child.type === 'Percentage') { + values.push(`${child.value}%`) + } } if (buffer) { diff --git a/test/extract.test.ts b/test/extract.test.ts index 3060dd20..c6138f2d 100644 --- a/test/extract.test.ts +++ b/test/extract.test.ts @@ -205,6 +205,30 @@ describe('css font-face extraction', () => { `) }) + it('should handle percentages', () => { + const css = ` + @font-face { + font-family: 'Test Font'; + src: url('/test.woff2') format('woff2'); + font-stretch: '110%'; + } + ` + + expect(extractFontFaceData(css)).toMatchInlineSnapshot(` + [ + { + "src": [ + { + "format": "woff2", + "url": "/test.woff2", + }, + ], + "stretch": "110%", + }, + ] + `) + }) + it('should handle multi-value font-style properties', () => { expect(extractFontFaceData(` @font-face { diff --git a/test/providers/adobe.test.ts b/test/providers/adobe.test.ts index 7ee9eb9d..c76ba584 100644 --- a/test/providers/adobe.test.ts +++ b/test/providers/adobe.test.ts @@ -76,6 +76,7 @@ describe('adobe', () => { "url": "https://use.typekit.net/font", }, ], + "stretch": "normal", "style": "italic", "weight": 400, }, @@ -95,6 +96,7 @@ describe('adobe', () => { "url": "https://use.typekit.net/font", }, ], + "stretch": "normal", "style": "normal", "weight": 400, }, From 9694334a2207284919405ab32a31382e58eac28e Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Mar 2026 09:23:04 +0100 Subject: [PATCH 2/4] fix: test --- test/providers/bunny.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/providers/bunny.test.ts b/test/providers/bunny.test.ts index 114a5c64..55a88b60 100644 --- a/test/providers/bunny.test.ts +++ b/test/providers/bunny.test.ts @@ -58,7 +58,7 @@ describe('bunny', () => { const { fonts } = await unifont.resolveFont('Alef', { weights: ['400 1100'], }) - expect(fonts.length).toBe(2) + expect(fonts.length).toBe(4) }) it('filters subsets correctly', async () => { From 37352f1e41df9a48de867b947c6cc6b42f463f18 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Mar 2026 09:24:35 +0100 Subject: [PATCH 3/4] fix: test --- test/providers/bunny.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/providers/bunny.test.ts b/test/providers/bunny.test.ts index 55a88b60..114a5c64 100644 --- a/test/providers/bunny.test.ts +++ b/test/providers/bunny.test.ts @@ -58,7 +58,7 @@ describe('bunny', () => { const { fonts } = await unifont.resolveFont('Alef', { weights: ['400 1100'], }) - expect(fonts.length).toBe(4) + expect(fonts.length).toBe(2) }) it('filters subsets correctly', async () => { From 81bd3d1d1c9375e55dc35374616b68eeade0cda9 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 13 Mar 2026 09:26:43 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/css/parse.ts | 3 ++- test/extract.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/css/parse.ts b/src/css/parse.ts index f5e00e21..2927f586 100644 --- a/src/css/parse.ts +++ b/src/css/parse.ts @@ -132,7 +132,8 @@ function extractCSSValue(node: Declaration) { values.push(Number(child.value)) } if (child.type === 'Percentage') { - values.push(`${child.value}%`) + const percentageValue = `${child.value}%` + buffer = buffer ? `${buffer} ${percentageValue}` : percentageValue } } diff --git a/test/extract.test.ts b/test/extract.test.ts index c6138f2d..3bda30f2 100644 --- a/test/extract.test.ts +++ b/test/extract.test.ts @@ -210,7 +210,7 @@ describe('css font-face extraction', () => { @font-face { font-family: 'Test Font'; src: url('/test.woff2') format('woff2'); - font-stretch: '110%'; + font-stretch: 110%; } `