/*!
 * @hyext/utils 
 * (c) 2020-2023 Alex
 * Released under the MIT License.
 */
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __awaiter(thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
}

function __generator(thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
}

function __spreadArrays() {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
}

var createPromisfyFnWithCatch = function (options) {
    var executePromiseFn = options.executePromiseFn, onResolve = options.onResolve, onReject = options.onReject, onPending = options.onPending;
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        return new Promise(function (resolve, reject) {
            onPending && onPending(args);
            var toResolve = function (res) {
                onResolve && onResolve(res);
                resolve(res);
            };
            var toReject = function (err) {
                var error = onReject && onReject(err);
                if (error instanceof Error) {
                    reject(error);
                }
                else {
                    resolve(false);
                }
            };
            try {
                var result = executePromiseFn.apply(null, args);
                if (typeof result === "object" &&
                    result !== null &&
                    typeof result.then === "function") {
                    result
                        .then(function (res) {
                        toResolve(res);
                    })
                        .catch(function (err) {
                        toReject(err);
                    });
                }
                else {
                    // executePromiseFn 是一个普通函数
                    toResolve(result);
                }
            }
            catch (error) {
                toReject(error);
            }
        });
    };
};
var once = function (fn) {
    var result = void 0;
    var callCount = 0;
    return function onceImpl() {
        var arg = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            arg[_i] = arguments[_i];
        }
        if (callCount !== 0) {
            return result;
        }
        callCount += 1;
        return (result = fn.apply(null, arg));
    };
};
var throttle = function (delay, fn) {
    var timer;
    return function throttleImpl() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        timer && clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(null, args);
        }, delay);
    };
};
var createPolling = function (options) {
    var _a = options.intervalTime, intervalTime = _a === void 0 ? 0 : _a, fn = options.fn, _b = options.immediately, immediately = _b === void 0 ? true : _b, onEnd = options.onEnd;
    return function pollingImpl() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var timer;
        var next = false;
        function clear() {
            timer && clearTimeout(timer);
            onEnd && onEnd();
        }
        function run() {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, fn.apply(null, args)];
                        case 1:
                            next = _a.sent();
                            if (next) {
                                delayRun();
                            }
                            else {
                                clear();
                            }
                            return [2 /*return*/];
                    }
                });
            });
        }
        function delayRun() {
            timer = setTimeout(run, intervalTime);
        }
        if (immediately) {
            run();
        }
        else {
            delayRun();
        }
        return function () {
            clear();
        };
    };
};
/**
 * memory - 返回一个缓存每次调用的结果并输出的函数
 * @param fn 计算纯函数，入参成员必须是 number | string
 * @returns 返回一个缓存入参映射结果的函数
 */
var memory = function (fn) {
    var memoryPool = {};
    return function memoryImpl() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var id = args.join("|") || "___default___";
        return memoryPool[id] || (memoryPool[id] = fn.apply(null, args));
    };
};

var _toString = Object.prototype.toString;
function isUndef(v) {
    return v === undefined || v === null;
}
function isDef(v) {
    return v !== undefined && v !== null;
}
function isTrue(v) {
    return v === true;
}
function isFalse(v) {
    return v === false;
}
var isObject = function (v) {
    return typeof v === 'object'
        && !Array.isArray(v)
        && v !== null;
};
var isFunction = function (v) {
    return typeof v === 'function';
};
var isArray = function (v) {
    return Array.isArray(v);
};
function isPlainObject(obj) {
    return _toString.call(obj) === '[object Object]';
}
function isRegExp(v) {
    return _toString.call(v) === '[object RegExp]';
}
var capitalize = memory(function (str) {
    return str.charAt(0).toUpperCase() + str.slice(1);
});
var camelizeRE = /-(\w)/g;
var camelize = memory(function (str) {
    return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; });
});
var hyphenateRE = /\B([A-Z])/g;
var hyphenate = memory(function (str) {
    return str.replace(hyphenateRE, '-$1').toLowerCase();
});
/**
 * Convert an input value to a number for persistence.
 * If the conversion fails, return original string.
 */
function toNumber(val) {
    var n = parseFloat(val);
    return isNaN(n) ? val : n;
}
/**
 * Convert a value to a string
 */
function toString(val) {
    return val == null
        ? ''
        : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString)
            ? JSON.stringify(val, null, 2)
            : String(val);
}
var patchNumber = function (v) {
    return String(v).length === 1 ? "0" + v : v;
};
var getTime = function (date) {
    if (date === void 0) { date = new Date(); }
    return patchNumber(date.getHours()) + ":" + patchNumber(date.getMinutes()) + ":" + patchNumber(date.getSeconds());
};
var delay = function (duration) {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve();
        }, duration);
    });
};
var second2Minute = function (seconds) {
    var date = new Date(seconds * 1000);
    var m = date.getMinutes();
    var s = date.getSeconds();
    return patchNumber(m) + ":" + patchNumber(s);
};
function limit(v) {
    var num = Number(v);
    return num === 0 || num > 99 ? '99+' : num;
}

var createLogger = function (options) {
    var onBefore = options.onBefore, onAfter = options.onAfter, prefix = options.prefix, logColor = options.logColor, _a = options.enableLog, enableLog = _a === void 0 ? true : _a;
    var defaultLogColor = {
        info: 'blue',
        warn: 'orange',
        error: 'red',
        log: 'green'
    };
    var mergredLogColor = Object.assign(defaultLogColor, logColor);
    function log() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var color = args[0], msg = args[1], data = args[2];
        var prefix = getPrefix();
        var logInfo = {
            prefix: prefix,
            msg: msg,
            data: data,
            desc: prefix + msg
        };
        onBefore && onBefore(logInfo);
        var shouldLog = typeof enableLog === 'function' ? enableLog(logInfo) : enableLog;
        if (shouldLog)
            console.log("%c " + logInfo.desc, "color: " + color + ";", logInfo.data);
        onAfter && onAfter(logInfo);
    }
    function getPrefix() {
        return typeof prefix === 'function' ? prefix() : (prefix || '');
    }
    return {
        log: function (msg, data) {
            log(mergredLogColor.log, msg, data);
        },
        info: function (msg, data) {
            log(mergredLogColor.info, msg, data);
        },
        warn: function (msg, data) {
            log(mergredLogColor.warn, msg, data);
        },
        error: function (msg, data) {
            log(mergredLogColor.error, msg, data);
        }
    };
};

var getTerminalKey = function (path) {
    var pathArray = path.split('.');
    return pathArray[pathArray.length - 1];
};
var getStack = function (SDK, path) {
    var pathArray = path.split('.');
    var stack = SDK;
    var i = 0;
    var pathName;
    if (!stack)
        return;
    while (i < pathArray.length) {
        pathName = pathArray[i];
        stack = stack[pathName];
        if (!stack)
            return;
        i++;
    }
    return stack;
};
var resolveSDKErrorMsg = function (e) {
    var sdkErrMsg = e.message;
    var msg = '';
    try {
        var errObj = JSON.parse(sdkErrMsg);
        msg = errObj.msg;
    }
    catch (error) {
        msg = sdkErrMsg;
    }
    return msg;
};
var createSDKPolyfill = function (options) {
    var paths = options.paths, SDK = options.SDK, onError = options.onError, onCall = options.onCall, onSuccess = options.onSuccess, onPolyfill = options.onPolyfill;
    var polyfillSDK = {};
    if (!SDK || !paths)
        throw new Error('options.SDK和options.paths都必须存在有效值');
    if (paths.length === 0)
        return polyfillSDK;
    paths.forEach(function (path) {
        var api = getStack(SDK, path);
        if (api !== void 0) {
            var key_1 = getTerminalKey(path);
            polyfillSDK[key_1] = api;
            onPolyfill && onPolyfill(polyfillSDK, key_1, api);
            polyfillSDK[key_1] = createPromisfyFnWithCatch({
                executePromiseFn: polyfillSDK[key_1],
                onPending: function (args) {
                    onCall && onCall(args, key_1, path);
                },
                onResolve: function (res) {
                    onSuccess && onSuccess(res, key_1, path);
                },
                onReject: function (err) {
                    var errMsg = resolveSDKErrorMsg(err);
                    return onError && onError(errMsg, key_1, path);
                }
            });
        }
    });
    return polyfillSDK;
};

var promiseTimeout = function (ms, promise) {
    var id;
    // Create a promise that rejects in <ms> milliseconds
    var timeout = new Promise(function (resolve, reject) {
        id = setTimeout(function () {
            reject(new Error('Timed out in ' + ms + 'ms.'));
        }, ms);
    });
    // Returns a race between our timeout and the passed in promise
    return new Promise(function (resolve, reject) {
        Promise.race([
            promise,
            timeout
        ]).then(function (res) {
            clearTimeout(id);
            resolve(res);
        }).catch(reject);
    });
};
var promiseRetry = function (maxExeCount, interval, cb) {
    var timer;
    var count = 0;
    function clearTimer() { timer && clearTimeout(timer); }
    return new Promise(function (resolve, reject) {
        function run() {
            return __awaiter(this, void 0, void 0, function () {
                var res, error_1;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            ++count;
                            if (!(count > maxExeCount)) return [3 /*break*/, 1];
                            clearTimer();
                            reject(new Error('The current call count more than maxExeCount'));
                            return [3 /*break*/, 5];
                        case 1:
                            res = void 0;
                            _a.label = 2;
                        case 2:
                            _a.trys.push([2, 4, , 5]);
                            return [4 /*yield*/, cb(count)];
                        case 3:
                            res = _a.sent();
                            if (res.isDone) {
                                clearTimer();
                                resolve(res.payload);
                            }
                            else {
                                next();
                            }
                            return [3 /*break*/, 5];
                        case 4:
                            error_1 = _a.sent();
                            clearTimer();
                            reject(error_1);
                            return [3 /*break*/, 5];
                        case 5: return [2 /*return*/];
                    }
                });
            });
        }
        function next() {
            var _this = this;
            timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, run()];
                        case 1:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            }); }, interval);
        }
        run();
    });
};

var LOGGER_LABEL = '[setModeWithQueue]';
var logger = function (msg) { return console.log(LOGGER_LABEL + " " + msg); };
var Emitter = /** @class */ (function () {
    function Emitter(logger) {
        this.listenerMap = new Map();
        this.logger = logger.bind(this);
    }
    Emitter.prototype.log = function (message) {
        this.logger("==> [Emitter] " + message);
    };
    Emitter.prototype.on = function (event, callback) {
        var _this = this;
        var _a;
        var listeners = (_a = this.listenerMap.get(event)) !== null && _a !== void 0 ? _a : [];
        this.listenerMap.set(event, __spreadArrays(listeners, [callback]));
        return function () { return _this.off(event, callback); };
    };
    Emitter.prototype.off = function (event, callback) {
        var _a;
        var listeners = (_a = this.listenerMap.get(event)) !== null && _a !== void 0 ? _a : [];
        this.listenerMap.set(event, listeners.filter(function (listener) { return listener !== callback; }));
    };
    /**
      * 因为 setMode 会在 onShow 之前执行，所以需要缓存 onShow 事件
      * 否则当 onShow 开始监听时, 事件可能已经触发过了, 导致无法监听到事件
      */
    Emitter.prototype.emit = function (event) {
        var _a;
        var payload = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            payload[_i - 1] = arguments[_i];
        }
        var listeners = (_a = this.listenerMap.get(event)) !== null && _a !== void 0 ? _a : [];
        this.log("emit " + event + ": " + JSON.stringify(payload));
        listeners.forEach(function (fn) { return fn.apply(void 0, payload); });
    };
    Emitter.prototype.cleanup = function () {
        this.log("cleanup all listeners");
        this.listenerMap = new Map();
    };
    return Emitter;
}());
var delay$1 = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
/**
  * 一个高阶函数, 调用后返回 setModeWithQueue 函数
  * 这个高阶函数每次调用都会取消监听 noticeShow/noticeHide 事件, 再重新进行监听
  */
var getSetModeWithQueueFn = function () {
    var resetDelay = 1000;
    logger = function (msg) {
        var _a, _b, _c;
        (_c = (_b = (_a = global === null || global === void 0 ? void 0 : global.hyExt) === null || _a === void 0 ? void 0 : _a.logger) === null || _b === void 0 ? void 0 : _b.info) === null || _c === void 0 ? void 0 : _c.call(_b, LOGGER_LABEL + " " + msg);
        console.log(LOGGER_LABEL + " " + msg);
    };
    var emitter = new Emitter(logger);
    var SHOW_EVENT = 'onNoticeShow';
    var TIMEOUT_EVENT = 'onNoticeHide';
    var listenToShowError = null;
    var listenToTimeoutError = null;
    var listenToShow = function () { return __awaiter(void 0, void 0, void 0, function () {
        var _a, _b, _c, _d;
        return __generator(this, function (_e) {
            switch (_e.label) {
                case 0: return [4 /*yield*/, ((_b = (_a = global.hyExt.popup) === null || _a === void 0 ? void 0 : _a.offNoticeShow) === null || _b === void 0 ? void 0 : _b.call(_a))];
                case 1:
                    _e.sent();
                    return [4 /*yield*/, ((_d = (_c = global.hyExt.popup) === null || _c === void 0 ? void 0 : _c.onNoticeShow) === null || _d === void 0 ? void 0 : _d.call(_c, {
                            callback: function (info) {
                                logger("onNoticeShow \u89E6\u53D1, info: " + JSON.stringify(info || '{}'));
                                return emitter.emit(SHOW_EVENT, info);
                            }
                        }))];
                case 2:
                    _e.sent();
                    if (!global.hyExt.popup.offNoticeShow || !global.hyExt.popup.onNoticeShow)
                        throw new Error('no onNoticeShow/offNoticeShow function');
                    return [2 /*return*/];
            }
        });
    }); };
    var listenToTimeout = function () { return __awaiter(void 0, void 0, void 0, function () {
        var _a, _b, _c, _d;
        return __generator(this, function (_e) {
            switch (_e.label) {
                case 0: return [4 /*yield*/, ((_b = (_a = global.hyExt.popup).offNoticeHide) === null || _b === void 0 ? void 0 : _b.call(_a))];
                case 1:
                    _e.sent();
                    return [4 /*yield*/, ((_d = (_c = global.hyExt.popup).onNoticeHide) === null || _d === void 0 ? void 0 : _d.call(_c, {
                            callback: function (info) {
                                logger("onNoticeHide \u89E6\u53D1, info: " + JSON.stringify(info || '{}'));
                                return emitter.emit(TIMEOUT_EVENT, info);
                            }
                        }))];
                case 2:
                    _e.sent();
                    if (!global.hyExt.popup.offNoticeHide || !global.hyExt.popup.onNoticeHide)
                        throw new Error('no onNoticeHide/offNoticeHide function');
                    return [2 /*return*/];
            }
        });
    }); };
    var resetMode = function () {
        logger('重置Mode为NORMAL');
        return global.hyExt.popup.setMode({ mode: 'NORMAL' })
            .then(function () { return delay$1(resetDelay); })
            .catch(function () { });
    };
    var init = function () { return Promise.all([
        listenToTimeout()
            .then(function () { listenToTimeoutError = null; })
            .catch(function (err) {
            logger("\u76D1\u542C/\u53D6\u6D88\u76D1\u542C\u5931\u8D25: " + (err === null || err === void 0 ? void 0 : err.message));
            listenToTimeoutError = err;
        }),
        listenToShow()
            .then(function () { listenToShowError = null; })
            .catch(function (err) {
            logger("\u76D1\u542C/\u53D6\u6D88\u76D1\u542C\u5931\u8D25: " + (err === null || err === void 0 ? void 0 : err.message));
            listenToShowError = err;
        }),
    ]); };
    var initPromise = init();
    /**
      * setModeWithQueue 函数是对setMode的封装, 用于支持 notice 队列
      * setModeWithQueue resolve 表示setMode成功, 但是由于终端的排队机制, 当mode为NOTICE时, 并不表示notice已经展示
      * 因此对比setMode, 添加两个额外的参数:
      *  - onShow: 如果当前mode是NOTICE, 那么当收到终端的展示事件时, 会调用这个函数. 如果当前mode不是NOTICE, 则在 setMode resolve 后调用这个函数
      *  - onNoticeHide: 当notice超时被终端隐藏, 或者调用了setMode 切换到非NOTICE模式时 , 会调用这个函数.
      * */
    var setModeWithQueue = function (params) { return __awaiter(void 0, void 0, void 0, function () {
        var mode, onShow, onNoticeHide, data;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    mode = params.mode, onShow = params.onShow, onNoticeHide = params.onNoticeHide;
                    return [4 /*yield*/, initPromise
                        /* 在调用 setMode 之前, 先重置为 NORMAL 模式 */
                    ];
                case 1:
                    _a.sent();
                    if (!(mode !== 'NORMAL')) return [3 /*break*/, 3];
                    return [4 /*yield*/, resetMode()];
                case 2:
                    _a.sent();
                    _a.label = 3;
                case 3:
                    logger("setMode({ mode: " + mode + "})");
                    return [4 /*yield*/, global.hyExt.popup.setMode({ mode: mode })
                        /* 排队机制只支持 mode === 'NOTICE' */
                        /* 没有 noticeKey 表明不支持 notice 队列. 这个时候不需要理会到底有没有监听成功 */
                    ];
                case 4:
                    data = _a.sent();
                    /* 排队机制只支持 mode === 'NOTICE' */
                    /* 没有 noticeKey 表明不支持 notice 队列. 这个时候不需要理会到底有没有监听成功 */
                    if (mode !== 'NOTICE' || !(data === null || data === void 0 ? void 0 : data.noticeKey)) {
                        logger("\u4E0D\u652F\u6301notice\u961F\u5217, \u76F4\u63A5\u89E6\u53D1onShow\u56DE\u8C03");
                        onShow === null || onShow === void 0 ? void 0 : onShow(data);
                        return [2 /*return*/, data];
                    }
                    /* 虽然是NOTICE, 但是调用者并不关心什么时候展示/隐藏 */
                    if (!onShow && !onNoticeHide) {
                        logger("\u652F\u6301notice\u961F\u5217, \u4E1A\u52A1\u4E0D\u5173\u5FC3onShow/onHide");
                        return [2 /*return*/, data];
                    }
                    /* 关心 onShow 但是监听失败, 则抛出异常. 但是这个时候其实已经调用了 setMode 了*/
                    if (mode === 'NOTICE' && listenToShowError && onShow) {
                        logger("\u652F\u6301notice\u961F\u5217, \u4E1A\u52A1\u5173\u5FC3onShow, \u4F46\u662F\u5E95\u5C42\u76D1\u542C\u5931\u8D25");
                        throw listenToShowError;
                    }
                    /* 关心 onTimeout 但是监听失败, 则抛出异常. 但是这个时候其实已经调用了 setMode 了*/
                    if (mode === 'NOTICE' && listenToTimeoutError && onNoticeHide) {
                        logger("\u652F\u6301notice\u961F\u5217, \u4E1A\u52A1\u5173\u5FC3onHide, \u4F46\u662F\u5E95\u5C42\u76D1\u542C\u5931\u8D25");
                        throw listenToTimeoutError;
                    }
                    if (mode === 'NOTICE' && onShow) {
                        emitter.on(SHOW_EVENT, function (info) { return ((info.noticeKey === data.noticeKey) && onShow(data)); });
                    }
                    if (mode === 'NOTICE' && onNoticeHide) {
                        emitter.on(TIMEOUT_EVENT, function (info) { return ((info.noticeKey === data.noticeKey) && onNoticeHide(data)); });
                    }
                    return [2 /*return*/];
            }
        });
    }); };
    return setModeWithQueue;
};

// @ts-ignore
var customContainerWidth = global && global.__customContainerWidth;
var inWebView = typeof customContainerWidth !== "undefined";
function isWebViewEnv() {
    return inWebView;
}
function tryThrowNotWebViewEnvError() {
    if (!inWebView) {
        throw new Error('请在webview环境下使用');
    }
}
function isIOSOnWeb() {
    tryThrowNotWebViewEnvError();
    var userAgent = navigator.userAgent.toLowerCase();
    return /iphone|ipad|ipod/.test(userAgent);
}
function isAndroidOnWeb() {
    tryThrowNotWebViewEnvError();
    var userAgent = navigator.userAgent.toLowerCase();
    return userAgent.indexOf("android") > -1;
}
function scalePxOnWebView(px, base) {
    if (base === void 0) { base = 750; }
    tryThrowNotWebViewEnvError();
    return Math.ceil((px * customContainerWidth) / base);
}
function isWebviewProxyEnv() {
    // @ts-expect-error
    return global.__ext_env && global.__ext_env === 'webview-proxy';
}

export { Emitter, camelize, capitalize, createLogger, createPolling, createPromisfyFnWithCatch, createSDKPolyfill, delay, getSetModeWithQueueFn, getTime, hyphenate, isAndroidOnWeb, isArray, isDef, isFalse, isFunction, isIOSOnWeb, isObject, isPlainObject, isRegExp, isTrue, isUndef, isWebViewEnv, isWebviewProxyEnv, limit, memory, once, patchNumber, promiseRetry, promiseTimeout, scalePxOnWebView, second2Minute, throttle, toNumber, toString };
