“use strict“; var _interopRequireDefault = require(“@babel/runtime/helpers/interopRequireDefault“);

“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) {
// 如果不是global原生的属性,p不是一个数字类型并且p小于global的长度,返回true
if (!global.hasOwnProperty§ || !isNaN§ && 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) {
// 遍历次数,global属性名数组对应的索引,每遍历一次都会加1
var cnt = 0;
// 上一次的属性名
var lastProp;
var hasIframe = false;
// 遍历global对象
for (var p in global) {
if (shouldSkipProperty(global, p)) continue; // 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断

// 遍历window.frames
for (var i = 0; i < window.frames.length && !hasIframe; i++) {
  var frame = window.frames[i];

  if (frame === global[p]) {
    // 拥有iframe
    hasIframe = true;
    break;
  }
}
// 支遍历两次?cnt = 0、cnt = 1?还是当前条件不成立,会一直遍历,cnt = Object.keys(global).length
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) {
// 如果entry是对象类型,返回"/"
if ((0, _typeof2[“default”])(entry) === ‘object’) {
return ‘/’;
}

try {
var _URL = new URL(entry, location.href),
origin = _URL.origin,
pathname = _URL.pathname;
// 除去文件名x.js得到公共路径
var paths = pathname.split(‘/’); // 移除最后一个元素

paths.pop();
return "".concat(origin).concat(paths.join('/'), "/");

} catch (e) {
console.warn(e);
return ‘’;
}
} // Detect whether browser supports

你可能感兴趣的:(微前端,javascript,前端,java)