{"version":3,"file":"platform.mjs","names":[],"sources":["../../src/common/platform.ts"],"sourcesContent":["/* eslint-disable no-restricted-globals */\n/* eslint-disable node/prefer-global/process */\n\n/**\n * Retrieves the global `localStorage` object.\n * @returns The global `localStorage` object if available, otherwise `undefined`.\n */\nexport function getLocalStorage(): any | undefined {\n  if (typeof localStorage !== 'undefined')\n    return localStorage\n}\n\n/**\n * Retrieves the global `window` object.\n * @returns The global `window` object if available, otherwise `undefined`.\n */\nexport function getWindow(): any | undefined {\n  if (typeof window !== 'undefined')\n    return window\n}\n\n/**\n * Retrieves the navigator object if it is available.\n * @returns The navigator object if available, otherwise undefined.\n */\nexport function getNavigator(): any | undefined {\n  if (typeof navigator !== 'undefined')\n    return navigator\n}\n\n/**\n * Retrieves the global object in the current environment.\n * @returns The global object.\n */\nexport function getGlobal(): any {\n  return getWindow()\n    // @ts-expect-error xxx\n    ?? typeof WorkerGlobalScope !== 'undefined'\n    ? self\n    : typeof global !== 'undefined'\n      ? global\n      // eslint-disable-next-line no-new-func\n      : new Function('return this;')()\n}\n\n/** @deprecated */\nexport function detect(\n  info = {\n    ios: false,\n    macos: false,\n    windows: false,\n    beaker: false,\n    electron: false,\n    wkwebview: false,\n    pwa: false,\n    pwaInstalled: false,\n    browser: false,\n    node: false,\n    worker: false,\n    test: false,\n    jest: false,\n    macosNative: false,\n    iosNative: false,\n    appleNative: false,\n    touch: false,\n  },\n) {\n  const _navigator = getNavigator()\n  const _window = getWindow()\n\n  info.ios = _navigator?.platform?.match(/(iPhone|iPod|iPad)/i) != null\n  info.macos = !!_navigator?.platform?.startsWith('Mac')\n  info.windows = !!_navigator?.platform?.startsWith('Win')\n\n  info.beaker = _window?.beaker != null // https://github.com/beakerbrowser/beaker\n  info.electron = (_navigator?.userAgent?.toLowerCase()?.indexOf(' electron/') || -1) > -1 && !info.beaker\n  info.wkwebview = _window?.webkit?.messageHandlers != null // Apple embedded\n\n  info.pwa = _navigator?.serviceWorker != null\n\n  info.pwaInstalled = _navigator?.standalone || _window?.matchMedia?.('(display-mode: standalone)')?.matches\n\n  info.node = typeof process !== 'undefined' && process?.release?.name === 'node'\n  info.browser = !info.electron && !info.wkwebview && !info.node\n\n  // info.worker = typeof importScripts === 'function'\n  // @ts-expect-error xxx\n  info.worker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope\n  // @ts-expect-error xxx\n\n  info.jest = typeof jest !== 'undefined' || typeof vitest !== 'undefined' // || globalThis.__vitest_browser_runner__ != null || globalThis.__vitest_ui_api__ != null\n  info.test = info.jest\n\n  info.macosNative = info.wkwebview && info.macos\n  info.iosNative = info.wkwebview && info.ios\n  info.appleNative = info.wkwebview\n\n  // https://github.com/viljamis/feature.js/blob/master/feature.js#L203\n  // @ts-expect-error xxx\n  info.touch = (_window && 'ontouchstart' in _window) || (_navigator?.maxTouchPoints || 0) > 1 || (_navigator?.msPointerEnabled && _window?.MSGesture) || (_window?.DocumentTouch && document instanceof DocumentTouch)\n\n  return info\n}\n\nexport function isBrowser() {\n  return typeof window !== 'undefined' && globalThis === window\n}\n\n/**\n * Before closing the tab/window or quitting the node process\n * allow to do something important first\n */\nexport function useExitHandler(handler: () => void) {\n  if (isBrowser())\n    window.addEventListener('beforeunload', handler)\n  else if (typeof process !== 'undefined')\n    process.on('exit', () => handler)\n}\n"],"mappings":";;;;;AAOA,SAAgB,kBAAmC;AACjD,KAAI,OAAO,iBAAiB,YAC1B,QAAO;;;;;;AAOX,SAAgB,YAA6B;AAC3C,KAAI,OAAO,WAAW,YACpB,QAAO;;;;;;AAOX,SAAgB,eAAgC;AAC9C,KAAI,OAAO,cAAc,YACvB,QAAO;;;;;;AAOX,SAAgB,YAAiB;AAC/B,QAAO,WAAW,IAEb,OAAO,sBAAsB,cAC9B,OACA,OAAO,WAAW,cAChB,SAEA,IAAI,SAAS,eAAe,EAAE;;;AAItC,SAAgB,OACd,OAAO;CACL,KAAK;CACL,OAAO;CACP,SAAS;CACT,QAAQ;CACR,UAAU;CACV,WAAW;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