{"ast":null,"code":"import _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport { Platform } from '@unimodules/core';\nimport invariant from 'invariant';\nvar EventTypes = ['url'];\nvar listeners = [];\nexport default {\n  addEventListener: function addEventListener(type, listener) {\n    invariant(EventTypes.indexOf(type) !== -1, \"Linking.addEventListener(): \" + type + \" is not a valid event\");\n\n    var nativeListener = function nativeListener(nativeEvent) {\n      return listener({\n        url: window.location.href,\n        nativeEvent: nativeEvent\n      });\n    };\n\n    listeners.push({\n      listener: listener,\n      nativeListener: nativeListener\n    });\n    window.addEventListener('message', nativeListener, false);\n  },\n  removeEventListener: function removeEventListener(type, listener) {\n    invariant(EventTypes.indexOf(type) !== -1, \"Linking.removeEventListener(): \" + type + \" is not a valid event.\");\n    var listenerIndex = listeners.findIndex(function (pair) {\n      return pair.listener === listener;\n    });\n    invariant(listenerIndex !== -1, 'Linking.removeEventListener(): cannot remove an unregistered event listener.');\n    var nativeListener = listeners[listenerIndex].nativeListener;\n    window.removeEventListener('message', nativeListener, false);\n    listeners.splice(listenerIndex, 1);\n  },\n  canOpenURL: function canOpenURL(url) {\n    return _regeneratorRuntime.async(function canOpenURL$(_context) {\n      while (1) {\n        switch (_context.prev = _context.next) {\n          case 0:\n            return _context.abrupt(\"return\", true);\n\n          case 1:\n          case \"end\":\n            return _context.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  getInitialURL: function getInitialURL() {\n    return _regeneratorRuntime.async(function getInitialURL$(_context2) {\n      while (1) {\n        switch (_context2.prev = _context2.next) {\n          case 0:\n            if (Platform.isDOMAvailable) {\n              _context2.next = 2;\n              break;\n            }\n\n            return _context2.abrupt(\"return\", '');\n\n          case 2:\n            return _context2.abrupt(\"return\", window.location.href);\n\n          case 3:\n          case \"end\":\n            return _context2.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  openURL: function openURL(url) {\n    return _regeneratorRuntime.async(function openURL$(_context3) {\n      while (1) {\n        switch (_context3.prev = _context3.next) {\n          case 0:\n            if (Platform.isDOMAvailable) {\n              window.location = new URL(url, window.location).toString();\n            }\n\n          case 1:\n          case \"end\":\n            return _context3.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  }\n};","map":{"version":3,"sources":["../src/ExpoLinking.web.ts"],"names":[],"mappings":";AAAA,SAAS,QAAT,QAAyB,kBAAzB;AACA,OAAO,SAAP,MAAsB,WAAtB;AAIA,IAAM,UAAU,GAAG,CAAC,KAAD,CAAnB;AAEA,IAAM,SAAS,GAAmE,EAAlF;AAEA,eAAe;AACb,EAAA,gBADa,4BACI,IADJ,EACiB,QADjB,EACsC;AACjD,IAAA,SAAS,CACP,UAAU,CAAC,OAAX,CAAmB,IAAnB,MAA6B,CAAC,CADvB,mCAEwB,IAFxB,2BAAT;;AAIA,QAAM,cAAc,GAAsB,SAApC,cAAoC,CAAA,WAAW;AAAA,aACnD,QAAQ,CAAC;AAAE,QAAA,GAAG,EAAE,MAAM,CAAC,QAAP,CAAgB,IAAvB;AAA6B,QAAA,WAAW,EAAX;AAA7B,OAAD,CAD2C;AAAA,KAArD;;AAEA,IAAA,SAAS,CAAC,IAAV,CAAe;AAAE,MAAA,QAAQ,EAAR,QAAF;AAAY,MAAA,cAAc,EAAd;AAAZ,KAAf;AACA,IAAA,MAAM,CAAC,gBAAP,CAAwB,SAAxB,EAAmC,cAAnC,EAAmD,KAAnD;AACD,GAVY;AAYb,EAAA,mBAZa,+BAYO,IAZP,EAYoB,QAZpB,EAYyC;AACpD,IAAA,SAAS,CACP,UAAU,CAAC,OAAX,CAAmB,IAAnB,MAA6B,CAAC,CADvB,sCAE2B,IAF3B,4BAAT;AAIA,QAAM,aAAa,GAAG,SAAS,CAAC,SAAV,CAAoB,UAAA,IAAI;AAAA,aAAI,IAAI,CAAC,QAAL,KAAkB,QAAtB;AAAA,KAAxB,CAAtB;AACA,IAAA,SAAS,CACP,aAAa,KAAK,CAAC,CADZ,EAEP,8EAFO,CAAT;AAIA,QAAM,cAAc,GAAG,SAAS,CAAC,aAAD,CAAT,CAAyB,cAAhD;AACA,IAAA,MAAM,CAAC,mBAAP,CAA2B,SAA3B,EAAsC,cAAtC,EAAsD,KAAtD;AACA,IAAA,SAAS,CAAC,MAAV,CAAiB,aAAjB,EAAgC,CAAhC;AACD,GAzBY;AA2BP,EAAA,UA3BO,sBA2BI,GA3BJ;AAAA;AAAA;AAAA;AAAA;AAAA,6CA6BJ,IA7BI;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCP,EAAA,aAhCO;AAAA;AAAA;AAAA;AAAA;AAAA,gBAiCN,QAAQ,CAAC,cAjCH;AAAA;AAAA;AAAA;;AAAA,8CAiC0B,EAjC1B;;AAAA;AAAA,8CAkCJ,MAAM,CAAC,QAAP,CAAgB,IAlCZ;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCP,EAAA,OArCO,mBAqCC,GArCD;AAAA;AAAA;AAAA;AAAA;AAsCX,gBAAI,QAAQ,CAAC,cAAb,EAA6B;AAE3B,cAAA,MAAM,CAAC,QAAP,GAAkB,IAAI,GAAJ,CAAQ,GAAR,EAAa,MAAM,CAAC,QAApB,EAA8B,QAA9B,EAAlB;AACD;;AAzCU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAf","sourcesContent":["import { Platform } from '@unimodules/core';\nimport invariant from 'invariant';\n\nimport { NativeURLListener, URLListener } from './Linking.types';\n\nconst EventTypes = ['url'];\n\nconst listeners: { listener: URLListener; nativeListener: NativeURLListener }[] = [];\n\nexport default {\n  addEventListener(type: 'url', listener: URLListener): void {\n    invariant(\n      EventTypes.indexOf(type) !== -1,\n      `Linking.addEventListener(): ${type} is not a valid event`\n    );\n    const nativeListener: NativeURLListener = nativeEvent =>\n      listener({ url: window.location.href, nativeEvent });\n    listeners.push({ listener, nativeListener });\n    window.addEventListener('message', nativeListener, false);\n  },\n\n  removeEventListener(type: 'url', listener: URLListener): void {\n    invariant(\n      EventTypes.indexOf(type) !== -1,\n      `Linking.removeEventListener(): ${type} is not a valid event.`\n    );\n    const listenerIndex = listeners.findIndex(pair => pair.listener === listener);\n    invariant(\n      listenerIndex !== -1,\n      'Linking.removeEventListener(): cannot remove an unregistered event listener.'\n    );\n    const nativeListener = listeners[listenerIndex].nativeListener;\n    window.removeEventListener('message', nativeListener, false);\n    listeners.splice(listenerIndex, 1);\n  },\n\n  async canOpenURL(url: string): Promise<boolean> {\n    // In reality this should be able to return false for links like `chrome://` on chrome.\n    return true;\n  },\n\n  async getInitialURL(): Promise<string> {\n    if (!Platform.isDOMAvailable) return '';\n    return window.location.href;\n  },\n\n  async openURL(url: string): Promise<void> {\n    if (Platform.isDOMAvailable) {\n      // @ts-ignore\n      window.location = new URL(url, window.location).toString();\n    }\n  },\n};\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}