UNPKG

@zigbang/honeyfarm-dashboard

Version:

HoneyFarm Node에 등록 되어 있는 안드로이드 단말을 웹페이지에서 실시간으로 확인 및 사용 할수 있도록 구현된 웹

1 lines 10.6 kB
{"ast":null,"code":"\"use strict\";\n\nvar _regeneratorRuntime = require(\"@babel/runtime/regenerator\");\n\nvar _slicedToArray = require(\"@babel/runtime/helpers/slicedToArray\");\n\nvar _asyncToGenerator = require(\"@babel/runtime/helpers/asyncToGenerator\");\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nexports.__esModule = true;\nexports.markAssetError = markAssetError;\nexports.isAssetError = isAssetError;\nexports.getClientBuildManifest = getClientBuildManifest;\nexports[\"default\"] = void 0;\n\nvar _getAssetPathFromRoute = _interopRequireDefault(require(\"../next-server/lib/router/utils/get-asset-path-from-route\"));\n\nvar _requestIdleCallback = _interopRequireDefault(require(\"./request-idle-callback\")); // 3.8s was arbitrarily chosen as it's what https://web.dev/interactive\n// considers as \"Good\" time-to-interactive. We must assume something went\n// wrong beyond this point, and then fall-back to a full page transition to\n// show the user something of value.\n\n\nvar MS_MAX_IDLE_DELAY = 3800;\n\nfunction withFuture(key, map, generator) {\n var entry = map.get(key);\n\n if (entry) {\n if ('future' in entry) {\n return entry.future;\n }\n\n return Promise.resolve(entry);\n }\n\n var resolver;\n var prom = new Promise(function (resolve) {\n resolver = resolve;\n });\n map.set(key, entry = {\n resolve: resolver,\n future: prom\n });\n return generator ? // eslint-disable-next-line no-sequences\n generator().then(function (value) {\n return resolver(value), value;\n }) : prom;\n}\n\nfunction hasPrefetch(link) {\n try {\n link = document.createElement('link');\n return (// detect IE11 since it supports prefetch but isn't detected\n // with relList.support\n !!window.MSInputMethodContext && !!document.documentMode || link.relList.supports('prefetch')\n );\n } catch (_unused) {\n return false;\n }\n}\n\nvar canPrefetch = hasPrefetch();\n\nfunction prefetchViaDom(href, as, link) {\n return new Promise(function (res, rej) {\n if (document.querySelector(\"link[rel=\\\"prefetch\\\"][href^=\\\"\".concat(href, \"\\\"]\"))) {\n return res();\n }\n\n link = document.createElement('link'); // The order of property assignment here is intentional:\n\n if (as) link.as = as;\n link.rel = \"prefetch\";\n link.crossOrigin = process.env.__NEXT_CROSS_ORIGIN;\n link.onload = res;\n link.onerror = rej; // `href` should always be last:\n\n link.href = href;\n document.head.appendChild(link);\n });\n}\n\nvar ASSET_LOAD_ERROR = Symbol('ASSET_LOAD_ERROR'); // TODO: unexport\n\nfunction markAssetError(err) {\n return Object.defineProperty(err, ASSET_LOAD_ERROR, {});\n}\n\nfunction isAssetError(err) {\n return err && ASSET_LOAD_ERROR in err;\n}\n\nfunction appendScript(src, script) {\n return new Promise(function (resolve, reject) {\n script = document.createElement('script'); // The order of property assignment here is intentional.\n // 1. Setup success/failure hooks in case the browser synchronously\n // executes when `src` is set.\n\n script.onload = resolve;\n\n script.onerror = function () {\n return reject(markAssetError(new Error(\"Failed to load script: \".concat(src))));\n }; // 2. Configure the cross-origin attribute before setting `src` in case the\n // browser begins to fetch.\n\n\n script.crossOrigin = process.env.__NEXT_CROSS_ORIGIN; // 3. Finally, set the source and inject into the DOM in case the child\n // must be appended for fetching to start.\n\n script.src = src;\n document.body.appendChild(script);\n });\n}\n\nfunction idleTimeout(ms, err) {\n return new Promise(function (_resolve, reject) {\n return (0, _requestIdleCallback[\"default\"])(function () {\n return setTimeout(function () {\n return reject(err);\n }, ms);\n });\n });\n} // TODO: stop exporting or cache the failure\n// It'd be best to stop exporting this. It's an implementation detail. We're\n// only exporting it for backwards compatibilty with the `page-loader`.\n// Only cache this response as a last resort if we cannot eliminate all other\n// code branches that use the Build Manifest Callback and push them through\n// the Route Loader interface.\n\n\nfunction getClientBuildManifest() {\n if (self.__BUILD_MANIFEST) {\n return Promise.resolve(self.__BUILD_MANIFEST);\n }\n\n var onBuildManifest = new Promise(function (resolve) {\n // Mandatory because this is not concurrent safe:\n var cb = self.__BUILD_MANIFEST_CB;\n\n self.__BUILD_MANIFEST_CB = function () {\n resolve(self.__BUILD_MANIFEST);\n cb && cb();\n };\n });\n return Promise.race([onBuildManifest, idleTimeout(MS_MAX_IDLE_DELAY, markAssetError(new Error('Failed to load client build manifest')))]);\n}\n\nfunction getFilesForRoute(assetPrefix, route) {\n if (false) {\n return Promise.resolve({\n scripts: [assetPrefix + '/_next/static/chunks/pages' + encodeURI((0, _getAssetPathFromRoute[\"default\"])(route, '.js'))],\n // Styles are handled by `style-loader` in development:\n css: []\n });\n }\n\n return getClientBuildManifest().then(function (manifest) {\n if (!(route in manifest)) {\n throw markAssetError(new Error(\"Failed to lookup route: \".concat(route)));\n }\n\n var allFiles = manifest[route].map(function (entry) {\n return assetPrefix + '/_next/' + encodeURI(entry);\n });\n return {\n scripts: allFiles.filter(function (v) {\n return v.endsWith('.js');\n }),\n css: allFiles.filter(function (v) {\n return v.endsWith('.css');\n })\n };\n });\n}\n\nfunction createRouteLoader(assetPrefix) {\n var entrypoints = new Map();\n var loadedScripts = new Map();\n var styleSheets = new Map();\n var routes = new Map();\n\n function maybeExecuteScript(src) {\n var prom = loadedScripts.get(src);\n\n if (prom) {\n return prom;\n } // Skip executing script if it's already in the DOM:\n\n\n if (document.querySelector(\"script[src^=\\\"\".concat(src, \"\\\"]\"))) {\n return Promise.resolve();\n }\n\n loadedScripts.set(src, prom = appendScript(src));\n return prom;\n }\n\n function fetchStyleSheet(href) {\n var prom = styleSheets.get(href);\n\n if (prom) {\n return prom;\n }\n\n styleSheets.set(href, prom = fetch(href).then(function (res) {\n if (!res.ok) {\n throw new Error(\"Failed to load stylesheet: \".concat(href));\n }\n\n return res.text().then(function (text) {\n return {\n href: href,\n content: text\n };\n });\n })[\"catch\"](function (err) {\n throw markAssetError(err);\n }));\n return prom;\n }\n\n return {\n whenEntrypoint: function whenEntrypoint(route) {\n return withFuture(route, entrypoints);\n },\n onEntrypoint: function onEntrypoint(route, execute) {\n Promise.resolve(execute).then(function (fn) {\n return fn();\n }).then(function (exports) {\n return {\n component: exports && exports[\"default\"] || exports,\n exports: exports\n };\n }, function (err) {\n return {\n error: err\n };\n }).then(function (input) {\n var old = entrypoints.get(route);\n entrypoints.set(route, input);\n if (old && 'resolve' in old) old.resolve(input);\n });\n },\n loadRoute: function loadRoute(route) {\n var _this = this;\n\n return withFuture(route, routes, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {\n var _yield$getFilesForRou, scripts, css, _yield$Promise$all, _yield$Promise$all2, styles, entrypoint, res;\n\n return _regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.prev = 0;\n _context.next = 3;\n return getFilesForRoute(assetPrefix, route);\n\n case 3:\n _yield$getFilesForRou = _context.sent;\n scripts = _yield$getFilesForRou.scripts;\n css = _yield$getFilesForRou.css;\n _context.next = 8;\n return Promise.all([entrypoints.has(route) ? [] : Promise.all(scripts.map(maybeExecuteScript)), Promise.all(css.map(fetchStyleSheet))]);\n\n case 8:\n _yield$Promise$all = _context.sent;\n _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);\n styles = _yield$Promise$all2[1];\n _context.next = 13;\n return Promise.race([_this.whenEntrypoint(route), idleTimeout(MS_MAX_IDLE_DELAY, markAssetError(new Error(\"Route did not complete loading: \".concat(route))))]);\n\n case 13:\n entrypoint = _context.sent;\n res = Object.assign({\n styles: styles\n }, entrypoint);\n return _context.abrupt(\"return\", 'error' in entrypoint ? entrypoint : res);\n\n case 18:\n _context.prev = 18;\n _context.t0 = _context[\"catch\"](0);\n return _context.abrupt(\"return\", {\n error: _context.t0\n });\n\n case 21:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, null, [[0, 18]]);\n })));\n },\n prefetch: function prefetch(route) {\n var _this2 = this;\n\n // https://github.com/GoogleChromeLabs/quicklink/blob/453a661fa1fa940e2d2e044452398e38c67a98fb/src/index.mjs#L115-L118\n // License: Apache 2.0\n var cn;\n\n if (cn = navigator.connection) {\n // Don't prefetch if using 2G or if Save-Data is enabled.\n if (cn.saveData || /2g/.test(cn.effectiveType)) return Promise.resolve();\n }\n\n return getFilesForRoute(assetPrefix, route).then(function (output) {\n return Promise.all(canPrefetch ? output.scripts.map(function (script) {\n return prefetchViaDom(script, 'script');\n }) : []);\n }).then(function () {\n (0, _requestIdleCallback[\"default\"])(function () {\n return _this2.loadRoute(route);\n });\n })[\"catch\"]( // swallow prefetch errors\n function () {});\n }\n };\n}\n\nvar _default = createRouteLoader;\nexports[\"default\"] = _default;","map":null,"metadata":{},"sourceType":"script"}