Guest User

Untitled

a guest
Dec 16th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /*
  2. * A small utility to fix the letter kerning on macOS Chrome and Firefox when using the system font
  3. * (San Francisco). It is now fixed in the text rendering engine in FF 58 and Chrome 64.
  4. */
  5. ;(() => {
  6. const ua = navigator.userAgent
  7.  
  8. // macOS 10.11 (El Capitan) came with San Francisco. Previous versions used Helvetica
  9. const isRelevantMacOS =
  10. /Mac/.test(navigator.platform) &&
  11. (ua.match(/OS X 10[._](\d{1,2})/) || [])[1] >= 11
  12.  
  13. // Chrome v64 and FF v58 fix the issue
  14. const isAffectedBrowser =
  15. (ua.match(/Chrome\/(\d+)\./) || [])[1] < 64 ||
  16. (ua.match(/Firefox\/(\d+)\./) || [])[1] < 58
  17.  
  18. if (isRelevantMacOS && isAffectedBrowser) {
  19. document.documentElement.style.letterSpacing = '-0.3px'
  20. for (const el of document.all) {
  21. const fontSize = parseFloat(getComputedStyle(el).fontSize)
  22. if (fontSize >= 20) el.style.letterSpacing = '0.3px'
  23. }
  24. }
  25. })()
Add Comment
Please, Sign In to add comment