UNPKG

@alicd/micro-stark

Version:

cone微应用

1,101 lines (953 loc) 33.5 kB
/** * @alicd/micro-stark v0.2.2 * (c) 2021 kaifeng.xkf */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var require$$0 = require('react'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0); var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; var lib$1 = {}; var getMountNode$1 = {}; var cache$1 = {}; Object.defineProperty(cache$1, "__esModule", { value: true }); cache$1.getCache = cache$1.setCache = void 0; var namespace$1 = 'ICESTARK'; cache$1.setCache = function (key, value) { if (!window[namespace$1]) { window[namespace$1] = {}; } window[namespace$1][key] = value; }; cache$1.getCache = function (key) { var icestark = window[namespace$1]; return icestark && icestark[key] ? icestark[key] : null; }; Object.defineProperty(getMountNode$1, "__esModule", { value: true }); var cache_1$9 = cache$1; function getMountNode(element) { if (cache_1$9.getCache('root')) { return cache_1$9.getCache('root'); } if (element) { // string treated as 'id' if (typeof element === 'string') { return document.querySelector("#" + element); } // function, return value if (typeof element === 'function') { return element(); } return element; } var ICE_CONTAINER = document.querySelector('#ice-container'); if (!ICE_CONTAINER) { throw new Error('Current page does not exist <div id="ice-container"></div> element.'); } return ICE_CONTAINER; } getMountNode$1.default = getMountNode; var renderNotFound = {}; Object.defineProperty(renderNotFound, "__esModule", { value: true }); var cache_1$8 = cache$1; /** * CustomEvent Polyfill for IE */ (function () { if (typeof window.CustomEvent === 'function') { return false; } function CustomEvent(event, params) { params = params || { bubbles: false, cancelable: false, detail: null }; var evt = document.createEvent('CustomEvent'); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; } window.CustomEvent = CustomEvent; })(); /** * Trigger customEvent icestark:not-found */ renderNotFound.default = (function () { if (cache_1$8.getCache('root')) { window.dispatchEvent(new CustomEvent('icestark:not-found')); // Compatible processing return renderNotFound(); return null; } return 'Current sub-application is running independently'; }); var getBasename = {}; Object.defineProperty(getBasename, "__esModule", { value: true }); var cache_1$7 = cache$1; getBasename.default = (function () { return (cache_1$7.getCache('basename') ? cache_1$7.getCache('basename') : '/'); }); var setBasename$1 = {}; Object.defineProperty(setBasename$1, "__esModule", { value: true }); var cache_1$6 = cache$1; function setBasename(base) { return cache_1$6.setCache('basename', base); } setBasename$1.default = setBasename; var registerAppEnter = {}; Object.defineProperty(registerAppEnter, "__esModule", { value: true }); var cache_1$5 = cache$1; registerAppEnter.default = (function (callback) { if (!callback) { return; } if (typeof callback !== 'function') { throw new Error('registerAppEnter must be function.'); } cache_1$5.setCache('appEnter', callback); }); var registerAppLeave = {}; Object.defineProperty(registerAppLeave, "__esModule", { value: true }); var cache_1$4 = cache$1; registerAppLeave.default = (function (callback) { if (!callback) { return; } if (typeof callback !== 'function') { throw new Error('registerAppLeave must be function.'); } cache_1$4.setCache('appLeave', callback); }); var appHistory$1 = {}; var formatUrl$1 = {}; Object.defineProperty(formatUrl$1, "__esModule", { value: true }); /** * format url * @param url * @param hashType */ var formatUrl = function (url, hashType) { return (hashType && url.indexOf('#') === -1) ? "#" + url : url; }; formatUrl$1.default = formatUrl; Object.defineProperty(appHistory$1, "__esModule", { value: true }); var formatUrl_1$1 = formatUrl$1; var appHistory = { push: function (url, hashType) { window.history.pushState({}, null, formatUrl_1$1.default(url, hashType)); }, replace: function (url, hashType) { window.history.replaceState({}, null, formatUrl_1$1.default(url, hashType)); }, }; appHistory$1.default = appHistory; var isInIcestark$1 = {}; Object.defineProperty(isInIcestark$1, "__esModule", { value: true }); var cache_1$3 = cache$1; var isInIcestark = function () { return !!cache_1$3.getCache('root'); }; var _default$1 = isInIcestark$1.default = isInIcestark; var AppLink$1 = {}; var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () { __assign = Object.assign || function(t) { var arguments$1 = arguments; for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments$1[i]; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } } } return t; }; return __assign.apply(this, arguments); }; var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) { t[p] = s[p]; } } if (s != null && typeof Object.getOwnPropertySymbols === "function") { for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) { t[p[i]] = s[p[i]]; } } } return t; }; Object.defineProperty(AppLink$1, "__esModule", { value: true }); /* eslint-disable react/jsx-filename-extension */ var React = require$$0__default['default']; var formatUrl_1 = formatUrl$1; var AppLink = function (props) { var to = props.to, hashType = props.hashType, replace = props.replace, message = props.message, children = props.children, rest = __rest(props, ["to", "hashType", "replace", "message", "children"]); var linkTo = formatUrl_1.default(to, hashType); return (React.createElement("a", __assign({}, rest, { href: linkTo, onClick: function (e) { e.preventDefault(); // eslint-disable-next-line no-alert if (message && window.confirm(message) === false) { return false; } var changeState = window.history[replace ? 'replaceState' : 'pushState']; changeState({}, null, linkTo); } }), children)); }; AppLink$1.default = AppLink; var setLibraryName$1 = {}; Object.defineProperty(setLibraryName$1, "__esModule", { value: true }); var cache_1$2 = cache$1; var setLibraryName = function (library) { if (!library) { console.error('[@ice/stark-app] setLibraryName: params can not be empty!'); return; } cache_1$2.setCache('library', library); }; setLibraryName$1.default = setLibraryName; (function (exports) { Object.defineProperty(exports, "__esModule", { value: true }); var getMountNode_1 = getMountNode$1; Object.defineProperty(exports, "getMountNode", { enumerable: true, get: function () { return getMountNode_1.default; } }); var renderNotFound_1 = renderNotFound; Object.defineProperty(exports, "renderNotFound", { enumerable: true, get: function () { return renderNotFound_1.default; } }); var getBasename_1 = getBasename; Object.defineProperty(exports, "getBasename", { enumerable: true, get: function () { return getBasename_1.default; } }); var setBasename_1 = setBasename$1; Object.defineProperty(exports, "setBasename", { enumerable: true, get: function () { return setBasename_1.default; } }); var registerAppEnter_1 = registerAppEnter; Object.defineProperty(exports, "registerAppEnter", { enumerable: true, get: function () { return registerAppEnter_1.default; } }); var registerAppLeave_1 = registerAppLeave; Object.defineProperty(exports, "registerAppLeave", { enumerable: true, get: function () { return registerAppLeave_1.default; } }); var appHistory_1 = appHistory$1; Object.defineProperty(exports, "appHistory", { enumerable: true, get: function () { return appHistory_1.default; } }); var isInIcestark_1 = isInIcestark$1; Object.defineProperty(exports, "isInIcestark", { enumerable: true, get: function () { return isInIcestark_1.default; } }); var AppLink_1 = AppLink$1; Object.defineProperty(exports, "AppLink", { enumerable: true, get: function () { return AppLink_1.default; } }); var setLibraryName_1 = setLibraryName$1; Object.defineProperty(exports, "setLibraryName", { enumerable: true, get: function () { return setLibraryName_1.default; } }); }(lib$1)); var lib = {}; var store$1 = {}; var utils = {}; Object.defineProperty(utils, "__esModule", { value: true }); utils.warn = utils.isArray = utils.isObject = void 0; function isObject(o) { return Object.prototype.toString.call(o) === '[object Object]'; } utils.isObject = isObject; function isArray$2(a) { return Object.prototype.toString.call(a) === '[object Array]'; } utils.isArray = isArray$2; function warn(message) { return console && console.warn(message); } utils.warn = warn; var cache = {}; Object.defineProperty(cache, "__esModule", { value: true }); cache.getCache = cache.setCache = void 0; var namespace = 'ICESTARK'; cache.setCache = function (key, value) { if (!window[namespace]) { window[namespace] = {}; } window[namespace][key] = value; }; cache.getCache = function (key) { var icestark = window[namespace]; return icestark && icestark[key] ? icestark[key] : null; }; /* eslint no-underscore-dangle: ["error", { "allow": ["foo_", "_bar"], "allowAfterThis": true }] */ /* eslint import/no-mutable-exports: 'off' */ Object.defineProperty(store$1, "__esModule", { value: true }); var utils_1$1 = utils; var cache_1$1 = cache; var storeNameSpace = 'store'; var Store = /** @class */ (function () { function Store() { this.store = {}; this.storeEmitter = {}; } Store.prototype._getValue = function (key) { return this.store[key]; }; Store.prototype._setValue = function (key, value) { this.store[key] = value; this._emit(key); }; Store.prototype._emit = function (key) { var keyEmitter = this.storeEmitter[key]; if (!utils_1$1.isArray(keyEmitter) || (utils_1$1.isArray(keyEmitter) && keyEmitter.length === 0)) { return; } var value = this._getValue(key); keyEmitter.forEach(function (cb) { cb(value); }); }; Store.prototype.get = function (key) { if (key === undefined) { return this.store; } if (typeof key !== 'string' && typeof key !== 'symbol') { utils_1$1.warn("store.get: key should be string / symbol"); return null; } return this._getValue(key); }; Store.prototype.set = function (key, value) { var _this = this; if (typeof key !== 'string' && typeof key !== 'symbol' && !utils_1$1.isObject(key)) { utils_1$1.warn('store.set: key should be string / symbol / object'); return; } if (utils_1$1.isObject(key)) { Object.keys(key).forEach(function (k) { var v = key[k]; _this._setValue(k, v); }); } else { this._setValue(key, value); } }; Store.prototype.on = function (key, callback, force) { if (typeof key !== 'string' && typeof key !== 'symbol') { utils_1$1.warn('store.on: key should be string / symbol'); return; } if (callback === undefined || typeof callback !== 'function') { utils_1$1.warn('store.on: callback is required, should be function'); return; } if (!this.storeEmitter[key]) { this.storeEmitter[key] = []; } this.storeEmitter[key].push(callback); if (force) { callback(this._getValue(key)); } }; Store.prototype.off = function (key, callback) { if (typeof key !== 'string' && typeof key !== 'symbol') { utils_1$1.warn('store.off: key should be string / symbol'); return; } if (!utils_1$1.isArray(this.storeEmitter[key])) { utils_1$1.warn("store.off: " + String(key) + " has no callback"); return; } if (callback === undefined) { this.storeEmitter[key] = undefined; return; } this.storeEmitter[key] = this.storeEmitter[key].filter(function (cb) { return cb !== callback; }); }; Store.prototype.has = function (key) { var keyEmitter = this.storeEmitter[key]; return utils_1$1.isArray(keyEmitter) && keyEmitter.length > 0; }; return Store; }()); var store = cache_1$1.getCache(storeNameSpace); if (!store) { store = new Store(); cache_1$1.setCache(storeNameSpace, store); } var _default = store$1.default = store; var event$1 = {}; /* eslint import/no-mutable-exports: 'off' */ Object.defineProperty(event$1, "__esModule", { value: true }); var utils_1 = utils; var cache_1 = cache; var eventNameSpace = 'event'; var Event = /** @class */ (function () { function Event() { this.eventEmitter = {}; } Event.prototype.emit = function (key) { var arguments$1 = arguments; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments$1[_i]; } var keyEmitter = this.eventEmitter[key]; if (!utils_1.isArray(keyEmitter) || (utils_1.isArray(keyEmitter) && keyEmitter.length === 0)) { utils_1.warn("event.emit: no callback is called for " + String(key)); return; } keyEmitter.forEach(function (cb) { cb.apply(void 0, args); }); }; Event.prototype.on = function (key, callback) { if (typeof key !== 'string' && typeof key !== 'symbol') { utils_1.warn('event.on: key should be string / symbol'); return; } if (callback === undefined || typeof callback !== 'function') { utils_1.warn('event.on: callback is required, should be function'); return; } if (!this.eventEmitter[key]) { this.eventEmitter[key] = []; } this.eventEmitter[key].push(callback); }; Event.prototype.off = function (key, callback) { if (typeof key !== 'string' && typeof key !== 'symbol') { utils_1.warn('event.off: key should be string / symbol'); return; } if (!utils_1.isArray(this.eventEmitter[key])) { utils_1.warn("event.off: " + String(key) + " has no callback"); return; } if (callback === undefined) { this.eventEmitter[key] = undefined; return; } this.eventEmitter[key] = this.eventEmitter[key].filter(function (cb) { return cb !== callback; }); }; Event.prototype.has = function (key) { var keyEmitter = this.eventEmitter[key]; return utils_1.isArray(keyEmitter) && keyEmitter.length > 0; }; return Event; }()); var event = cache_1.getCache(eventNameSpace); if (!event) { event = new Event(); cache_1.setCache(eventNameSpace, event); } event$1.default = event; (function (exports) { Object.defineProperty(exports, "__esModule", { value: true }); var store_1 = store$1; Object.defineProperty(exports, "store", { enumerable: true, get: function () { return store_1.default; } }); var event_1 = event$1; Object.defineProperty(exports, "event", { enumerable: true, get: function () { return event_1.default; } }); }(lib)); var getWalleBasePath = function getWalleBasePath() { if (_default$1()) { var microConfig = _default.get('currentAppConfig'); if (microConfig && microConfig.prefix && microConfig.version) { window.basePath = "".concat(microConfig.prefix + microConfig.version, "/"); } if (microConfig && microConfig.isDebug && microConfig.debugPrefix) { window.basePath = "".concat(microConfig.debugPrefix, "/"); } } return window.basePath || './'; }; // 在进入子应用前对已存在的弹窗进行标识 function attachmentStaticWrapper() { var targetEles = document.querySelectorAll('div[data-tag="gateway-wrapper"]'); if (targetEles !== null && targetEles !== void 0 && targetEles.length) { targetEles.forEach(function (item) { var wrapperType = item.getAttribute('data-cone-micro'); if (wrapperType !== 'dynamic') { item.setAttribute('data-cone-micro', 'static'); } }); } } // 进入子应用后的弹窗进行标识 function attachmentDynamicWrapper() { var targetEles = document.querySelectorAll('div[data-tag="gateway-wrapper"]'); if (targetEles !== null && targetEles !== void 0 && targetEles.length) { targetEles.forEach(function (item) { var wrapperType = item.getAttribute('data-cone-micro'); if (wrapperType !== 'static') { item.setAttribute('data-cone-micro', 'dynamic'); } }); } } // 移除子应用的弹窗 function delRemaindToastEle() { var targetEles = document.querySelectorAll('div[data-tag="gateway-wrapper"]'); if (targetEles && targetEles.length > 0) { targetEles.forEach(function (item) { var wrapperType = item.getAttribute('data-cone-micro'); if (wrapperType !== 'static') { document.body.removeChild(item); } }); } } /** * @name 代理rmoveChild方法 * @desc 微前端模式下切换应用,如果存在弹窗,会导致取消弹窗的方法报错 * @author kaifeng.xkf * @date 2020-10-15 * @export */ var originRemoveChild = HTMLDivElement.prototype.removeChild; function proxyRemoveChild() { HTMLDivElement.prototype.removeChild = function () { var arguments$1 = arguments; try { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments$1[_key]; } originRemoveChild.call.apply(originRemoveChild, [this].concat(args)); } catch (error) { console.log(error); } }; var originBodyremoveChild = document.body.removeChild; document.body.removeChild = function () { var arguments$1 = arguments; try { for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments$1[_key2]; } originBodyremoveChild.call.apply(originBodyremoveChild, [this].concat(args)); } catch (error) { console.log(error); } }; } /** Detect free variable `global` from Node.js. */ var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; var _freeGlobal = freeGlobal$1; var freeGlobal = _freeGlobal; /** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root$1 = freeGlobal || freeSelf || Function('return this')(); var _root = root$1; var root = _root; /** Built-in value references. */ var Symbol$3 = root.Symbol; var _Symbol = Symbol$3; /** * A specialized version of `_.map` for arrays without support for iteratee * shorthands. * * @private * @param {Array} [array] The array to iterate over. * @param {Function} iteratee The function invoked per iteration. * @returns {Array} Returns the new mapped array. */ function arrayMap$1(array, iteratee) { var index = -1, length = array == null ? 0 : array.length, result = Array(length); while (++index < length) { result[index] = iteratee(array[index], index, array); } return result; } var _arrayMap = arrayMap$1; /** * Checks if `value` is classified as an `Array` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); * // => true * * _.isArray(document.body.children); * // => false * * _.isArray('abc'); * // => false * * _.isArray(_.noop); * // => false */ var isArray$1 = Array.isArray; var isArray_1 = isArray$1; var Symbol$2 = _Symbol; /** Used for built-in method references. */ var objectProto$1 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto$1.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$1 = objectProto$1.toString; /** Built-in value references. */ var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag$1(value) { var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1]; try { value[symToStringTag$1] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString$1.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$1] = tag; } else { delete value[symToStringTag$1]; } } return result; } var _getRawTag = getRawTag$1; /** Used for built-in method references. */ var objectProto = Object.prototype; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString = objectProto.toString; /** * Converts `value` to a string using `Object.prototype.toString`. * * @private * @param {*} value The value to convert. * @returns {string} Returns the converted string. */ function objectToString$1(value) { return nativeObjectToString.call(value); } var _objectToString = objectToString$1; var Symbol$1 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString; /** `Object#toString` result references. */ var nullTag = '[object Null]', undefinedTag = '[object Undefined]'; /** Built-in value references. */ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined; /** * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag$1(value) { if (value == null) { return value === undefined ? undefinedTag : nullTag; } return (symToStringTag && symToStringTag in Object(value)) ? getRawTag(value) : objectToString(value); } var _baseGetTag = baseGetTag$1; /** * Checks if `value` is object-like. A value is object-like if it's not `null` * and has a `typeof` result of "object". * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @example * * _.isObjectLike({}); * // => true * * _.isObjectLike([1, 2, 3]); * // => true * * _.isObjectLike(_.noop); * // => false * * _.isObjectLike(null); * // => false */ function isObjectLike$1(value) { return value != null && typeof value == 'object'; } var isObjectLike_1 = isObjectLike$1; var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1; /** `Object#toString` result references. */ var symbolTag = '[object Symbol]'; /** * Checks if `value` is classified as a `Symbol` primitive or object. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); * // => true * * _.isSymbol('abc'); * // => false */ function isSymbol$1(value) { return typeof value == 'symbol' || (isObjectLike(value) && baseGetTag(value) == symbolTag); } var isSymbol_1 = isSymbol$1; var Symbol = _Symbol, arrayMap = _arrayMap, isArray = isArray_1, isSymbol = isSymbol_1; /** Used as references for various `Number` constants. */ var INFINITY = 1 / 0; /** Used to convert symbols to primitives and strings. */ var symbolProto = Symbol ? Symbol.prototype : undefined, symbolToString = symbolProto ? symbolProto.toString : undefined; /** * The base implementation of `_.toString` which doesn't convert nullish * values to empty strings. * * @private * @param {*} value The value to process. * @returns {string} Returns the string. */ function baseToString$1(value) { // Exit early for strings to avoid a performance hit in some environments. if (typeof value == 'string') { return value; } if (isArray(value)) { // Recursively convert values (susceptible to call stack limits). return arrayMap(value, baseToString$1) + ''; } if (isSymbol(value)) { return symbolToString ? symbolToString.call(value) : ''; } var result = (value + ''); return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; } var _baseToString = baseToString$1; var baseToString = _baseToString; /** * Converts `value` to a string. An empty string is returned for `null` * and `undefined` values. The sign of `-0` is preserved. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to convert. * @returns {string} Returns the converted string. * @example * * _.toString(null); * // => '' * * _.toString(-0); * // => '-0' * * _.toString([1, 2, 3]); * // => '1,2,3' */ function toString$1(value) { return value == null ? '' : baseToString(value); } var toString_1 = toString$1; /** * The base implementation of `_.propertyOf` without support for deep paths. * * @private * @param {Object} object The object to query. * @returns {Function} Returns the new accessor function. */ function basePropertyOf$1(object) { return function(key) { return object == null ? undefined : object[key]; }; } var _basePropertyOf = basePropertyOf$1; var basePropertyOf = _basePropertyOf; /** Used to map HTML entities to characters. */ var htmlUnescapes = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#39;': "'" }; /** * Used by `_.unescape` to convert HTML entities to characters. * * @private * @param {string} chr The matched character to unescape. * @returns {string} Returns the unescaped character. */ var unescapeHtmlChar$1 = basePropertyOf(htmlUnescapes); var _unescapeHtmlChar = unescapeHtmlChar$1; var toString = toString_1, unescapeHtmlChar = _unescapeHtmlChar; /** Used to match HTML entities and HTML characters. */ var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, reHasEscapedHtml = RegExp(reEscapedHtml.source); /** * The inverse of `_.escape`; this method converts the HTML entities * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to * their corresponding characters. * * **Note:** No other HTML entities are unescaped. To unescape additional * HTML entities use a third-party library like [_he_](https://mths.be/he). * * @static * @memberOf _ * @since 0.6.0 * @category String * @param {string} [string=''] The string to unescape. * @returns {string} Returns the unescaped string. * @example * * _.unescape('fred, barney, &amp; pebbles'); * // => 'fred, barney, & pebbles' */ function unescape(string) { string = toString(string); return (string && reHasEscapedHtml.test(string)) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string; } var _unescape = unescape; var getQueryParams = function getQueryParams() { var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.href; var results = {}; var queryStrList = url.match(/[^?#]+?([^?#]+=[^?#]+)/g); if (!queryStrList) { return results; } queryStrList.forEach(function (queryStr) { var queryList = queryStr.split('&'); queryList.forEach(function (item) { var temp = item.split('='); results[temp[0]] = temp[1]; }); }); return results; }; var supportContext = { WINDOW: 'window', COOKIES: 'cookies', QUERY: 'query' }; function checkContainContext(exprStr, varnameSign) { return exprStr.startsWith("".concat(varnameSign, ".")) || exprStr.startsWith("".concat(varnameSign, "[")); } function getCookies() { var map = {}; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1); } if (c.indexOf('=')) { var temp = c.split('='); if (temp[0]) { map[temp[0]] = temp[1]; } } } return map; } function createFn(arg, expressStr) { var fnStr = "\n var data = ".concat(expressStr, ";\n return data;\n "); return new Function(arg, fnStr); } var processConfig = (function (rawConfig) { var isDebug = location.href.includes('debug='); // 当前是否处于debug模式 var processedConfig; if (!rawConfig) { throw Error('没有找到配置'); } if (typeof rawConfig === 'string') { try { processedConfig = JSON.parse(rawConfig); } catch (error) { console.error(error); } } else { processedConfig = rawConfig; } var queryMap = getQueryParams(); var debugAppId = queryMap['debug']; var cookiesMap = getCookies(); // 对配置文件进行处理 processedConfig.forEach(function (item) { if (isDebug && item.subapp_id === debugAppId && item.debugPrefix) { item.isDebug = true; item.url = item.url.map(function (it) { return it.replace("{prefix}{version}", item.debugPrefix); }); } else { item.url = item.url.map(function (it) { return it.replace('{prefix}', item.prefix).replace('{version}', item.version); }); } // 可以使用{}模板语法 能够识别window location中的参数 使用方式{window.xxx} {query.xxx},其他方式暂时不识别 item.url = item.url.map(function (it) { var newUrl = deepUnescape(it); var varTplList = newUrl.match(/\{([^\}]+)\}/g); if (!varTplList) { return newUrl; } var varList = varTplList.map(function (varTpl) { return { varTpl: varTpl, varExpr: varTpl.replace('{', '').replace('}', '') }; }); varList.forEach(function (varItem) { if (!varItem.varExpr) { return; } try { if (checkContainContext(varItem.varExpr, supportContext.WINDOW)) { var fn = createFn(void 0, varItem.varExpr); varItem.data = fn(); } else if (checkContainContext(varItem.varExpr, supportContext.QUERY)) { var _fn = createFn(supportContext.QUERY, varItem.varExpr); varItem.data = _fn(queryMap); } else if (checkContainContext(varItem.varExpr, supportContext.COOKIES)) { var _fn2 = createFn(supportContext.COOKIES, varItem.varExpr); varItem.data = _fn2(cookiesMap); } } catch (error) { console.error(error); } if (varItem.data) { newUrl = newUrl.replace(varItem.varTpl, varItem.data); } }); return newUrl; }); }); return rawConfig; }); function deepUnescape(str) { var newStr = _unescape(str); if (newStr.includes(';') && newStr !== str) { newStr = deepUnescape(newStr); } return newStr; } var evalConfig = processConfig; var microStark = /*#__PURE__*/Object.freeze({ __proto__: null, evalConfig: evalConfig, getMountNode: lib$1.getMountNode, renderNotFound: lib$1.renderNotFound, getBasename: lib$1.getBasename, setBasename: lib$1.setBasename, registerAppEnter: lib$1.registerAppEnter, registerAppLeave: lib$1.registerAppLeave, appHistory: lib$1.appHistory, isInIcestark: lib$1.isInIcestark, AppLink: lib$1.AppLink, setLibraryName: lib$1.setLibraryName, event: lib.event, store: lib.store, getWalleBasePath: getWalleBasePath, attachmentStaticWrapper: attachmentStaticWrapper, attachmentDynamicWrapper: attachmentDynamicWrapper, delRemaindToastEle: delRemaindToastEle, proxyRemoveChild: proxyRemoveChild }); exports.AppLink = lib$1.AppLink; exports.appHistory = lib$1.appHistory; exports.attachmentDynamicWrapper = attachmentDynamicWrapper; exports.attachmentStaticWrapper = attachmentStaticWrapper; exports.default = microStark; exports.delRemaindToastEle = delRemaindToastEle; exports.evalConfig = evalConfig; exports.event = lib.event; exports.getBasename = lib$1.getBasename; exports.getMountNode = lib$1.getMountNode; exports.getWalleBasePath = getWalleBasePath; exports.isInIcestark = lib$1.isInIcestark; exports.proxyRemoveChild = proxyRemoveChild; exports.registerAppEnter = lib$1.registerAppEnter; exports.registerAppLeave = lib$1.registerAppLeave; exports.renderNotFound = lib$1.renderNotFound; exports.setBasename = lib$1.setBasename; exports.setLibraryName = lib$1.setLibraryName; exports.store = lib.store;