{"version":3,"sources":["../src/AdobeFonts.tsx"],"sourcesContent":["import React, { ReactNode, useEffect } from 'react'\n\nexport type AdobeFontsProps = {\n  kitId: string\n  /** This callback is triggered when all fonts have been requested. */\n  onLoading?: () => void\n  /** This callback is triggered when the fonts have rendered. */\n  onActive?: () => void\n  /** This callback is triggered when the browser does not support linked fonts *or* if none of the fonts could be loaded. */\n  onInactive?: () => void\n  /** This callback is triggered once for each font that's loaded. The callback is called with the family name as the first argument and font variation description as the second argument. */\n  onFontLoading?: (fontFamily: string, fontVariation: string) => void\n  /** This callback is triggered once for each font that renders. The callback is called with the family name as the first argument and font variation description as the second argument. */\n  onFontActive?: (fontFamily: string, fontVariation: string) => void\n  /** This callback is triggered if the font can't be loaded. The callback is called with the family name as the first argument and font variation description as the second argument. */\n  onFontInactive?: (fontFamily: string, fontVariation: string) => void\n}\n\nexport const useAdobeFonts = ({\n  kitId,\n  onLoading,\n  onActive,\n  onInactive,\n  onFontLoading,\n  onFontActive,\n  onFontInactive,\n}: AdobeFontsProps) => {\n  useEffect(() => {\n    const config = {\n      kitId,\n      scriptTimeout: 3000,\n      async: true,\n      loading: onLoading,\n      active: onActive,\n      inactive: onInactive,\n      fontloading: onFontLoading,\n      fontactive: onFontActive,\n      fontinactive: onFontInactive,\n    }\n\n    const d = window.document\n    const h = d.documentElement\n    const s = d.getElementsByTagName('script')[0]\n    const t = setTimeout(function () {\n      h.className = h.className.replace(/\\bwf-loading\\b/g, '') + ' wf-inactive'\n    }, config.scriptTimeout)\n    const tk = d.createElement('script')\n\n    let a\n    let f = false\n\n    h.className += ' wf-loading'\n\n    tk.src = 'https://use.typekit.net/' + config.kitId + '.js'\n    tk.async = true\n\n    tk.onload = (tk as any).onreadystatechange = function () {\n      a = this.readyState\n\n      if (f || (a && a != 'complete' && a != 'loaded')) return\n\n      f = true\n\n      clearTimeout(t)\n\n      try {\n        ;(window as any).Typekit.load(config)\n      } catch (e) {}\n    }\n\n    if (s.parentNode == undefined) return\n\n    s.parentNode.insertBefore(tk, s)\n  }, [])\n}\n\nexport const AdobeFonts = (props: AdobeFontsProps & { children?: ReactNode }) => {\n  useAdobeFonts({\n    kitId: props.kitId,\n    onLoading: props.onLoading,\n    onActive: props.onActive,\n    onInactive: props.onInactive,\n    onFontLoading: props.onFontLoading,\n    onFontActive: props.onFontActive,\n    onFontInactive: props.onFontInactive,\n  })\n\n  return <>{props.children}</>\n}\n"],"mappings":"AAAA,qCAkBO,GAAM,GAAgB,CAAC,CAC5B,QACA,YACA,WACA,aACA,gBACA,eACA,oBACqB,CACrB,EAAU,IAAM,CACd,GAAM,GAAS,CACb,QACA,cAAe,IACf,MAAO,GACP,QAAS,EACT,OAAQ,EACR,SAAU,EACV,YAAa,EACb,WAAY,EACZ,aAAc,CAChB,EAEM,EAAI,OAAO,SACX,EAAI,EAAE,gBACN,EAAI,EAAE,qBAAqB,QAAQ,EAAE,GACrC,EAAI,WAAW,UAAY,CAC/B,EAAE,UAAY,EAAE,UAAU,QAAQ,kBAAmB,EAAE,EAAI,cAC7D,EAAG,EAAO,aAAa,EACjB,EAAK,EAAE,cAAc,QAAQ,EAE/B,EACA,EAAI,GAqBR,AAnBA,EAAE,WAAa,cAEf,EAAG,IAAM,2BAA6B,EAAO,MAAQ,MACrD,EAAG,MAAQ,GAEX,EAAG,OAAU,EAAW,mBAAqB,UAAY,CAGvD,GAFA,EAAI,KAAK,WAEL,KAAM,GAAK,GAAK,YAAc,GAAK,UAEvC,GAAI,GAEJ,aAAa,CAAC,EAEd,GAAI,CACD,AAAC,OAAe,QAAQ,KAAK,CAAM,CACtC,MAAE,CAAW,EACf,EAEI,EAAE,YAAc,MAEpB,EAAE,WAAW,aAAa,EAAI,CAAC,CACjC,EAAG,CAAC,CAAC,CACP,EAEa,EAAa,AAAC,GACzB,GAAc,CACZ,MAAO,EAAM,MACb,UAAW,EAAM,UACjB,SAAU,EAAM,SAChB,WAAY,EAAM,WAClB,cAAe,EAAM,cACrB,aAAc,EAAM,aACpB,eAAgB,EAAM,cACxB,CAAC,EAEM,gCAAG,EAAM,QAAS","names":[]}