{"ast":null,"code":"import _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\n\nfunction _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === \"undefined\" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } it = o[Symbol.iterator](); return it.next.bind(it); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nimport { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\nimport { FontDisplay } from \"./Font.types\";\n\nfunction getFontFaceStyleSheet() {\n  if (!Platform.isDOMAvailable) {\n    return null;\n  }\n\n  var styleSheet = getStyleElement();\n  return styleSheet.sheet ? styleSheet.sheet : null;\n}\n\nfunction getFontFaceRules() {\n  var sheet = getFontFaceStyleSheet();\n\n  if (sheet) {\n    var rules = _toConsumableArray(sheet.cssRules);\n\n    var items = [];\n\n    for (var i = 0; i < rules.length; i++) {\n      var rule = rules[i];\n\n      if (rule instanceof CSSFontFaceRule) {\n        items.push({\n          rule: rule,\n          index: i\n        });\n      }\n    }\n\n    return items;\n  }\n\n  return [];\n}\n\nfunction getFontFaceRulesMatchingResource(fontFamilyName, options) {\n  var rules = getFontFaceRules();\n  return rules.filter(function (_ref) {\n    var rule = _ref.rule;\n    return rule.style.fontFamily === fontFamilyName && (options && options.display ? options.display === rule.style.fontDisplay : true);\n  });\n}\n\nexport default {\n  get name() {\n    return 'ExpoFontLoader';\n  },\n\n  unloadAllAsync: function unloadAllAsync() {\n    var element;\n    return _regeneratorRuntime.async(function unloadAllAsync$(_context) {\n      while (1) {\n        switch (_context.prev = _context.next) {\n          case 0:\n            if (Platform.isDOMAvailable) {\n              _context.next = 2;\n              break;\n            }\n\n            return _context.abrupt(\"return\");\n\n          case 2:\n            element = document.getElementById(ID);\n\n            if (element && element instanceof HTMLStyleElement) {\n              document.removeChild(element);\n            }\n\n          case 4:\n          case \"end\":\n            return _context.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  unloadAsync: function unloadAsync(fontFamilyName, options) {\n    var sheet, items, _iterator, _step, item;\n\n    return _regeneratorRuntime.async(function unloadAsync$(_context2) {\n      while (1) {\n        switch (_context2.prev = _context2.next) {\n          case 0:\n            sheet = getFontFaceStyleSheet();\n\n            if (sheet) {\n              _context2.next = 3;\n              break;\n            }\n\n            return _context2.abrupt(\"return\");\n\n          case 3:\n            items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n\n            for (_iterator = _createForOfIteratorHelperLoose(items); !(_step = _iterator()).done;) {\n              item = _step.value;\n              sheet.deleteRule(item.index);\n            }\n\n          case 5:\n          case \"end\":\n            return _context2.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  loadAsync: function loadAsync(fontFamilyName, resource) {\n    var canInjectStyle, style;\n    return _regeneratorRuntime.async(function loadAsync$(_context3) {\n      while (1) {\n        switch (_context3.prev = _context3.next) {\n          case 0:\n            if (Platform.isDOMAvailable) {\n              _context3.next = 2;\n              break;\n            }\n\n            return _context3.abrupt(\"return\");\n\n          case 2:\n            canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n\n            if (canInjectStyle) {\n              _context3.next = 5;\n              break;\n            }\n\n            throw new CodedError('ERR_WEB_ENVIRONMENT', \"The browser's `document.head` element doesn't support injecting fonts.\");\n\n          case 5:\n            style = _createWebStyle(fontFamilyName, resource);\n            document.head.appendChild(style);\n\n            if (isFontLoadingListenerSupported()) {\n              _context3.next = 9;\n              break;\n            }\n\n            return _context3.abrupt(\"return\");\n\n          case 9:\n            return _context3.abrupt(\"return\", new FontObserver(fontFamilyName, {\n              display: resource.display\n            }).load());\n\n          case 10:\n          case \"end\":\n            return _context3.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  }\n};\nvar ID = 'expo-generated-fonts';\n\nfunction getStyleElement() {\n  var element = document.getElementById(ID);\n\n  if (element && element instanceof HTMLStyleElement) {\n    return element;\n  }\n\n  var styleElement = document.createElement('style');\n  styleElement.id = ID;\n  styleElement.type = 'text/css';\n  return styleElement;\n}\n\nfunction _createWebStyle(fontFamily, resource) {\n  var fontStyle = \"@font-face {\\n    font-family: \" + fontFamily + \";\\n    src: url(\" + resource.uri + \");\\n    font-display: \" + (resource.display || FontDisplay.AUTO) + \";\\n  }\";\n  var styleElement = getStyleElement();\n\n  if (styleElement.styleSheet) {\n    var styleElementIE = styleElement;\n    styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText ? styleElementIE.styleSheet.cssText + fontStyle : fontStyle;\n  } else {\n    var textNode = document.createTextNode(fontStyle);\n    styleElement.appendChild(textNode);\n  }\n\n  return styleElement;\n}\n\nfunction isFontLoadingListenerSupported() {\n  var userAgent = window.navigator.userAgent;\n  var isIOS = !!userAgent.match(/iPad|iPhone/i);\n  var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n  var isEdge = userAgent.includes('Edge');\n  var isIE = userAgent.includes('Trident');\n  var isFirefox = userAgent.includes('Firefox');\n  return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}","map":{"version":3,"sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":";;;;;;;;;AAA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AC,SAA7B,CAAQ,SAAR;AAEA,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,KAAV,CAAgB,cAAhB,CAAhB;AACA,MAAM,QAAQ,GAAG,iCAAiC,IAAjC,CAAsC,SAAS,CAAC,SAAhD,CAAjB;AAEA,MAAM,MAAM,GAAG,SAAS,CAAC,QAAV,CAAmB,MAAnB,CAAf;AAEA,MAAM,IAAI,GAAG,SAAS,CAAC,QAAV,CAAmB,SAAnB,CAAb;AAEA,MAAM,SAAS,GAAG,SAAS,CAAC,QAAV,CAAmB,SAAnB,CAAlB;AACA,SAAO,CAAC,QAAD,IAAa,CAAC,KAAd,IAAuB,CAAC,MAAxB,IAAkC,CAAC,IAAnC,IAA2C,CAAC,SAAnD;AACD","sourcesContent":["import { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\n\nimport { UnloadFontOptions } from './Font';\nimport { FontDisplay, FontResource } from './Font.types';\n\nfunction getFontFaceStyleSheet(): CSSStyleSheet | null {\n  if (!Platform.isDOMAvailable) {\n    return null;\n  }\n  const styleSheet = getStyleElement();\n  return styleSheet.sheet ? (styleSheet.sheet as CSSStyleSheet) : null;\n}\n\ntype RuleItem = { rule: CSSFontFaceRule; index: number };\n\nfunction getFontFaceRules(): RuleItem[] {\n  const sheet = getFontFaceStyleSheet();\n  if (sheet) {\n    // @ts-ignore: rule iterator\n    const rules = [...sheet.cssRules];\n\n    const items: RuleItem[] = [];\n\n    for (let i = 0; i < rules.length; i++) {\n      const rule = rules[i];\n      if (rule instanceof CSSFontFaceRule) {\n        items.push({ rule, index: i });\n      }\n    }\n    return items;\n  }\n  return [];\n}\n\nfunction getFontFaceRulesMatchingResource(\n  fontFamilyName: string,\n  options?: UnloadFontOptions\n): RuleItem[] {\n  const rules = getFontFaceRules();\n  return rules.filter(({ rule }) => {\n    return (\n      rule.style.fontFamily === fontFamilyName &&\n      (options && options.display ? options.display === (rule.style as any).fontDisplay : true)\n    );\n  });\n}\n\nexport default {\n  get name(): string {\n    return 'ExpoFontLoader';\n  },\n\n  async unloadAllAsync(): Promise<void> {\n    if (!Platform.isDOMAvailable) return;\n\n    const element = document.getElementById(ID);\n    if (element && element instanceof HTMLStyleElement) {\n      document.removeChild(element);\n    }\n  },\n\n  async unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void> {\n    const sheet = getFontFaceStyleSheet();\n    if (!sheet) return;\n    const items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n    for (const item of items) {\n      sheet.deleteRule(item.index);\n    }\n  },\n\n  async loadAsync(fontFamilyName: string, resource: FontResource): Promise<void> {\n    if (!Platform.isDOMAvailable) {\n      return;\n    }\n\n    const canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n    if (!canInjectStyle) {\n      throw new CodedError(\n        'ERR_WEB_ENVIRONMENT',\n        `The browser's \\`document.head\\` element doesn't support injecting fonts.`\n      );\n    }\n\n    const style = _createWebStyle(fontFamilyName, resource);\n    document.head!.appendChild(style);\n\n    if (!isFontLoadingListenerSupported()) {\n      return;\n    }\n\n    return new FontObserver(fontFamilyName, { display: resource.display }).load();\n  },\n};\n\nconst ID = 'expo-generated-fonts';\n\nfunction getStyleElement(): HTMLStyleElement {\n  const element = document.getElementById(ID);\n  if (element && element instanceof HTMLStyleElement) {\n    return element;\n  }\n  const styleElement = document.createElement('style');\n  styleElement.id = ID;\n  styleElement.type = 'text/css';\n  return styleElement;\n}\n\nfunction _createWebStyle(fontFamily: string, resource: FontResource): HTMLStyleElement {\n  const fontStyle = `@font-face {\n    font-family: ${fontFamily};\n    src: url(${resource.uri});\n    font-display: ${resource.display || FontDisplay.AUTO};\n  }`;\n\n  const styleElement = getStyleElement();\n  // @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and\n  // possibly can be removed if it's unnecessary on IE 11.\n  if (styleElement.styleSheet) {\n    const styleElementIE = styleElement as any;\n    styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText\n      ? styleElementIE.styleSheet.cssText + fontStyle\n      : fontStyle;\n  } else {\n    const textNode = document.createTextNode(fontStyle);\n    styleElement.appendChild(textNode);\n  }\n  return styleElement;\n}\n\nfunction isFontLoadingListenerSupported(): boolean {\n  const { userAgent } = window.navigator;\n  // WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95\n  const isIOS = !!userAgent.match(/iPad|iPhone/i);\n  const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n  // Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795\n  const isEdge = userAgent.includes('Edge');\n  // Internet Explorer\n  const isIE = userAgent.includes('Trident');\n  // Firefox\n  const isFirefox = userAgent.includes('Firefox');\n  return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}