"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultGetPublicPath = defaultGetPublicPath; exports.evalCode = evalCode; exports.getGlobalProp = getGlobalProp; exports.getInlineCode = getInlineCode; exports.isModuleScriptSupported = isModuleScriptSupported; exports.noteGlobalProps = noteGlobalProps; exports.readResAsString = readResAsString; exports.requestIdleCallback = void 0; var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); /** * @author Kuitos * @homepage https://github.com/kuitos/ * @since 2019-02-25 * fork from https://github.com/systemjs/systemjs/blob/master/src/extras/global.js */ var isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1; function shouldSkipProperty(global, p) { if (!global.hasOwnProperty(p) || !isNaN(p) && p < global.length) return true; if (isIE11) { // https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围 try { return global[p] && typeof window !== 'undefined' && global[p].parent === window; } catch (err) { return true; } } else { return false; } } // safari unpredictably lists some new globals first or second in object order var firstGlobalProp, secondGlobalProp, lastGlobalProp; function getGlobalProp(global) { var cnt = 0; var lastProp; var hasIframe = false; for (var p in global) { if (shouldSkipProperty(global, p)) continue; // 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断 for (var i = 0; i < window.frames.length && !hasIframe; i++) { var frame = window.frames[i]; if (frame === global[p]) { hasIframe = true; break; } } if (!hasIframe && (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp)) return p; cnt++; lastProp = p; } if (lastProp !== lastGlobalProp) return lastProp; } function noteGlobalProps(global) { // alternatively Object.keys(global).pop() // but this may be faster (pending benchmarks) firstGlobalProp = secondGlobalProp = undefined; for (var p in global) { if (shouldSkipProperty(global, p)) continue; if (!firstGlobalProp) firstGlobalProp = p;else if (!secondGlobalProp) secondGlobalProp = p; lastGlobalProp = p; } return lastGlobalProp; } function getInlineCode(match) { var start = match.indexOf('>') + 1; var end = match.lastIndexOf('<'); return match.substring(start, end); } function defaultGetPublicPath(entry) { if ((0, _typeof2["default"])(entry) === 'object') { return '/'; } try { var _URL = new URL(entry, location.href), origin = _URL.origin, pathname = _URL.pathname; var paths = pathname.split('/'); // 移除最后一个元素 paths.pop(); return "".concat(origin).concat(paths.join('/'), "/"); } catch (e) { console.warn(e); return ''; } } // Detect whether browser supports `