Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/css/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const extractableKeyMap: Record<string, keyof FontFaceData> = {
'src': 'src',
'font-display': 'display',
'font-weight': 'weight',
'font-stretch': 'stretch',
'font-style': 'style',
'font-feature-settings': 'featureSettings',
'font-variation-settings': 'variationSettings',
Expand Down Expand Up @@ -130,6 +131,10 @@ function extractCSSValue(node: Declaration) {
if (child.type === 'Number') {
values.push(Number(child.value))
}
if (child.type === 'Percentage') {
const percentageValue = `${child.value}%`
buffer = buffer ? `${buffer} ${percentageValue}` : percentageValue
}
}

if (buffer) {
Expand Down
24 changes: 24 additions & 0 deletions test/extract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions test/providers/adobe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('adobe', () => {
"url": "https://use.typekit.net/font",
},
],
"stretch": "normal",
"style": "italic",
"weight": 400,
},
Expand All @@ -95,6 +96,7 @@ describe('adobe', () => {
"url": "https://use.typekit.net/font",
},
],
"stretch": "normal",
"style": "normal",
"weight": 400,
},
Expand Down
Loading