1.1.0 • Published 9 months ago

local-font v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

local-font

wrapper of experimental queryLocalFonts API

caniuse

utils

import {
  checkLocalFontPermission,
  fontWeightLabels,
  isMonospace,
  isSupportQueryLocalFonts,
  parseFontStyleToWeight,
  queryFontList,
  queryTargetFontBlob
} from 'local-font'

if (isSupportQueryLocalFonts() && (await checkLocalFontPermission()).state === 'granted') {
  const data = await queryFontList() // ==> FontData[]
  await queryTargetFontBlob('ComicSansMS') // ==> Blob | null

  const ctx = document.createElement('canvas').getContext('2d')!
  isMonospace(data[0].family) // `true` or `false`
  fontWeightLabels[parseFontStyleToWeight(data[0].style)] // Regular
}

typescript support

in tsconfig.json:

{
  "compilerOptions": {
    "types": [
      "local-font/types"
    ]
  }
}
1.1.0

9 months ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago