-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f567f82
commit dbef7ed
Showing
6 changed files
with
181 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
const uniquer = require('../../utils/uniquer') | ||
|
||
module.exports = atRules => { | ||
const all = atRules | ||
.filter(rule => rule.type === 'font-face') | ||
.map(rule => rule.params) | ||
.map(rule => rule.descriptors) | ||
|
||
// Tricky bit: uniqueness will be based on the `src` of the @font-face | ||
const uniqueWithCount = uniquer( | ||
all.map(ff => ff.src) | ||
).uniqueWithCount.map(item => { | ||
// Once we have a list of unique @font-faces, | ||
// we'll map it back to the original values again | ||
return { | ||
count: item.count, | ||
value: all.find(ff => ff.src === item.value) | ||
} | ||
}) | ||
|
||
return { | ||
total: all.length | ||
total: all.length, | ||
unique: uniqueWithCount.map(item => item.value), | ||
totalUnique: uniqueWithCount.length, | ||
uniqueWithCount | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,53 @@ | ||
.rule { | ||
.regular-rule { | ||
color: red | ||
} | ||
|
||
/** | ||
* All bells and whistles | ||
*/ | ||
|
||
@font-face { | ||
/* empty */ | ||
font-display: swap; | ||
font-family: monospace; | ||
font-stretch: condensed; | ||
font-style: italic; | ||
font-weight: bold; | ||
font-variant: no-common-ligatures proportional-nums; | ||
font-feature-settings: "liga" 0; | ||
font-variation-settings: "xhgt" 0.7; | ||
src: local('Input Mono'); | ||
unicode-range: U+0025-00FF; | ||
} | ||
|
||
/** | ||
* Intentional duplicate to test uniqueness | ||
*/ | ||
@font-face { | ||
font-family: monospace; | ||
font-variant: normal; | ||
font-weight: normal; | ||
src: url('https://example.com'); | ||
font-family: 'Example Duplicate'; | ||
} | ||
|
||
@font-face { | ||
src: url('https://example.com'); | ||
font-family: 'Example Duplicate'; | ||
} | ||
|
||
/** | ||
* These examples are taken from https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#Descriptors | ||
*/ | ||
|
||
@font-face { | ||
font-family: MyHelvetica; | ||
src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"), url(MgOpenModernaBold.ttf); | ||
font-weight: bold; | ||
} | ||
|
||
@font-face { | ||
font-family: "Bitstream Vera Serif Bold"; | ||
src: url("https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf"); | ||
} | ||
|
||
@font-face { | ||
font-family: "Open Sans"; | ||
src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"), url("/fonts/OpenSans-Regular-webfont.woff") format("woff"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,81 @@ | ||
{ | ||
"total": 2 | ||
"total": 6, | ||
"totalUnique": 5, | ||
"unique": [ | ||
{ | ||
"font-display": "swap", | ||
"font-family": "monospace", | ||
"font-stretch": "condensed", | ||
"font-style": "italic", | ||
"font-weight": "bold", | ||
"font-variant": "no-common-ligatures proportional-nums", | ||
"font-feature-settings": "\"liga\" 0", | ||
"font-variation-settings": "\"xhgt\" 0.7", | ||
"src": "local('Input Mono')", | ||
"unicode-range": "U+0025-00FF" | ||
}, | ||
{ | ||
"font-family": "MyHelvetica", | ||
"src": "local(\"Helvetica Neue Bold\"), local(\"HelveticaNeue-Bold\"), url(MgOpenModernaBold.ttf)", | ||
"font-weight": "bold" | ||
}, | ||
{ | ||
"src": "url('https://example.com')", | ||
"font-family": "'Example Duplicate'" | ||
}, | ||
{ | ||
"font-family": "\"Open Sans\"", | ||
"src": "url(\"/fonts/OpenSans-Regular-webfont.woff2\") format(\"woff2\"), url(\"/fonts/OpenSans-Regular-webfont.woff\") format(\"woff\")" | ||
}, | ||
{ | ||
"font-family": "\"Bitstream Vera Serif Bold\"", | ||
"src": "url(\"https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf\")" | ||
} | ||
], | ||
"uniqueWithCount": [ | ||
{ | ||
"count": 1, | ||
"value": { | ||
"font-display": "swap", | ||
"font-family": "monospace", | ||
"font-stretch": "condensed", | ||
"font-style": "italic", | ||
"font-weight": "bold", | ||
"font-variant": "no-common-ligatures proportional-nums", | ||
"font-feature-settings": "\"liga\" 0", | ||
"font-variation-settings": "\"xhgt\" 0.7", | ||
"src": "local('Input Mono')", | ||
"unicode-range": "U+0025-00FF" | ||
} | ||
}, | ||
{ | ||
"count": 1, | ||
"value": { | ||
"font-family": "MyHelvetica", | ||
"src": "local(\"Helvetica Neue Bold\"), local(\"HelveticaNeue-Bold\"), url(MgOpenModernaBold.ttf)", | ||
"font-weight": "bold" | ||
} | ||
}, | ||
{ | ||
"count": 2, | ||
"value": { | ||
"src": "url('https://example.com')", | ||
"font-family": "'Example Duplicate'" | ||
} | ||
}, | ||
{ | ||
"count": 1, | ||
"value": { | ||
"font-family": "\"Open Sans\"", | ||
"src": "url(\"/fonts/OpenSans-Regular-webfont.woff2\") format(\"woff2\"), url(\"/fonts/OpenSans-Regular-webfont.woff\") format(\"woff\")" | ||
} | ||
}, | ||
{ | ||
"count": 1, | ||
"value": { | ||
"font-family": "\"Bitstream Vera Serif Bold\"", | ||
"src": "url(\"https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf\")" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters