16959 lines
490 KiB
JavaScript
16959 lines
490 KiB
JavaScript
"use strict";
|
||
const _export_sfc = (sfc, props) => {
|
||
const target = sfc.__vccOpts || sfc;
|
||
for (const [key, val] of props) {
|
||
target[key] = val;
|
||
}
|
||
return target;
|
||
};
|
||
/**
|
||
* @vue/shared v3.4.21
|
||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||
* @license MIT
|
||
**/
|
||
function makeMap(str, expectsLowerCase) {
|
||
const set2 = new Set(str.split(","));
|
||
return expectsLowerCase ? (val) => set2.has(val.toLowerCase()) : (val) => set2.has(val);
|
||
}
|
||
const EMPTY_OBJ = Object.freeze({});
|
||
const EMPTY_ARR = Object.freeze([]);
|
||
const NOOP = () => {
|
||
};
|
||
const NO = () => false;
|
||
const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
|
||
(key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
|
||
const isModelListener = (key) => key.startsWith("onUpdate:");
|
||
const extend = Object.assign;
|
||
const remove = (arr, el) => {
|
||
const i = arr.indexOf(el);
|
||
if (i > -1) {
|
||
arr.splice(i, 1);
|
||
}
|
||
};
|
||
const hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
||
const hasOwn = (val, key) => hasOwnProperty$2.call(val, key);
|
||
const isArray$1 = Array.isArray;
|
||
const isMap$1 = (val) => toTypeString(val) === "[object Map]";
|
||
const isSet = (val) => toTypeString(val) === "[object Set]";
|
||
const isFunction$1 = (val) => typeof val === "function";
|
||
const isString$1 = (val) => typeof val === "string";
|
||
const isSymbol = (val) => typeof val === "symbol";
|
||
const isObject$1 = (val) => val !== null && typeof val === "object";
|
||
const isPromise = (val) => {
|
||
return (isObject$1(val) || isFunction$1(val)) && isFunction$1(val.then) && isFunction$1(val.catch);
|
||
};
|
||
const objectToString = Object.prototype.toString;
|
||
const toTypeString = (value) => objectToString.call(value);
|
||
const toRawType = (value) => {
|
||
return toTypeString(value).slice(8, -1);
|
||
};
|
||
const isPlainObject$1 = (val) => toTypeString(val) === "[object Object]";
|
||
const isIntegerKey = (key) => isString$1(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
||
const isReservedProp = /* @__PURE__ */ makeMap(
|
||
// the leading comma is intentional so empty string "" is also included
|
||
",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
|
||
);
|
||
const isBuiltInDirective = /* @__PURE__ */ makeMap(
|
||
"bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
|
||
);
|
||
const cacheStringFunction = (fn) => {
|
||
const cache = /* @__PURE__ */ Object.create(null);
|
||
return (str) => {
|
||
const hit = cache[str];
|
||
return hit || (cache[str] = fn(str));
|
||
};
|
||
};
|
||
const camelizeRE = /-(\w)/g;
|
||
const camelize = cacheStringFunction((str) => {
|
||
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
||
});
|
||
const hyphenateRE = /\B([A-Z])/g;
|
||
const hyphenate = cacheStringFunction(
|
||
(str) => str.replace(hyphenateRE, "-$1").toLowerCase()
|
||
);
|
||
const capitalize = cacheStringFunction((str) => {
|
||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||
});
|
||
const toHandlerKey = cacheStringFunction((str) => {
|
||
const s2 = str ? `on${capitalize(str)}` : ``;
|
||
return s2;
|
||
});
|
||
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
||
const invokeArrayFns$1 = (fns, arg) => {
|
||
for (let i = 0; i < fns.length; i++) {
|
||
fns[i](arg);
|
||
}
|
||
};
|
||
const def = (obj, key, value) => {
|
||
Object.defineProperty(obj, key, {
|
||
configurable: true,
|
||
enumerable: false,
|
||
value
|
||
});
|
||
};
|
||
const looseToNumber = (val) => {
|
||
const n2 = parseFloat(val);
|
||
return isNaN(n2) ? val : n2;
|
||
};
|
||
let _globalThis;
|
||
const getGlobalThis = () => {
|
||
return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
|
||
};
|
||
function normalizeStyle(value) {
|
||
if (isArray$1(value)) {
|
||
const res = {};
|
||
for (let i = 0; i < value.length; i++) {
|
||
const item = value[i];
|
||
const normalized = isString$1(item) ? parseStringStyle(item) : normalizeStyle(item);
|
||
if (normalized) {
|
||
for (const key in normalized) {
|
||
res[key] = normalized[key];
|
||
}
|
||
}
|
||
}
|
||
return res;
|
||
} else if (isString$1(value) || isObject$1(value)) {
|
||
return value;
|
||
}
|
||
}
|
||
const listDelimiterRE = /;(?![^(]*\))/g;
|
||
const propertyDelimiterRE = /:([^]+)/;
|
||
const styleCommentRE = /\/\*[^]*?\*\//g;
|
||
function parseStringStyle(cssText) {
|
||
const ret = {};
|
||
cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
||
if (item) {
|
||
const tmp = item.split(propertyDelimiterRE);
|
||
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
||
}
|
||
});
|
||
return ret;
|
||
}
|
||
function normalizeClass(value) {
|
||
let res = "";
|
||
if (isString$1(value)) {
|
||
res = value;
|
||
} else if (isArray$1(value)) {
|
||
for (let i = 0; i < value.length; i++) {
|
||
const normalized = normalizeClass(value[i]);
|
||
if (normalized) {
|
||
res += normalized + " ";
|
||
}
|
||
}
|
||
} else if (isObject$1(value)) {
|
||
for (const name2 in value) {
|
||
if (value[name2]) {
|
||
res += name2 + " ";
|
||
}
|
||
}
|
||
}
|
||
return res.trim();
|
||
}
|
||
const toDisplayString = (val) => {
|
||
return isString$1(val) ? val : val == null ? "" : isArray$1(val) || isObject$1(val) && (val.toString === objectToString || !isFunction$1(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
|
||
};
|
||
const replacer = (_key, val) => {
|
||
if (val && val.__v_isRef) {
|
||
return replacer(_key, val.value);
|
||
} else if (isMap$1(val)) {
|
||
return {
|
||
[`Map(${val.size})`]: [...val.entries()].reduce(
|
||
(entries, [key, val2], i) => {
|
||
entries[stringifySymbol(key, i) + " =>"] = val2;
|
||
return entries;
|
||
},
|
||
{}
|
||
)
|
||
};
|
||
} else if (isSet(val)) {
|
||
return {
|
||
[`Set(${val.size})`]: [...val.values()].map((v) => stringifySymbol(v))
|
||
};
|
||
} else if (isSymbol(val)) {
|
||
return stringifySymbol(val);
|
||
} else if (isObject$1(val) && !isArray$1(val) && !isPlainObject$1(val)) {
|
||
return String(val);
|
||
}
|
||
return val;
|
||
};
|
||
const stringifySymbol = (v, i = "") => {
|
||
var _a;
|
||
return isSymbol(v) ? `Symbol(${(_a = v.description) != null ? _a : i})` : v;
|
||
};
|
||
const LINEFEED = "\n";
|
||
const SLOT_DEFAULT_NAME = "d";
|
||
const ON_SHOW = "onShow";
|
||
const ON_HIDE = "onHide";
|
||
const ON_LAUNCH = "onLaunch";
|
||
const ON_ERROR = "onError";
|
||
const ON_THEME_CHANGE = "onThemeChange";
|
||
const ON_PAGE_NOT_FOUND = "onPageNotFound";
|
||
const ON_UNHANDLE_REJECTION = "onUnhandledRejection";
|
||
const ON_EXIT = "onExit";
|
||
const ON_LOAD = "onLoad";
|
||
const ON_READY = "onReady";
|
||
const ON_UNLOAD = "onUnload";
|
||
const ON_INIT = "onInit";
|
||
const ON_SAVE_EXIT_STATE = "onSaveExitState";
|
||
const ON_RESIZE = "onResize";
|
||
const ON_BACK_PRESS = "onBackPress";
|
||
const ON_PAGE_SCROLL = "onPageScroll";
|
||
const ON_TAB_ITEM_TAP = "onTabItemTap";
|
||
const ON_REACH_BOTTOM = "onReachBottom";
|
||
const ON_PULL_DOWN_REFRESH = "onPullDownRefresh";
|
||
const ON_SHARE_TIMELINE = "onShareTimeline";
|
||
const ON_ADD_TO_FAVORITES = "onAddToFavorites";
|
||
const ON_SHARE_APP_MESSAGE = "onShareAppMessage";
|
||
const ON_NAVIGATION_BAR_BUTTON_TAP = "onNavigationBarButtonTap";
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED = "onNavigationBarSearchInputClicked";
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED = "onNavigationBarSearchInputChanged";
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED = "onNavigationBarSearchInputConfirmed";
|
||
const ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED = "onNavigationBarSearchInputFocusChanged";
|
||
const customizeRE = /:/g;
|
||
function customizeEvent(str) {
|
||
return camelize(str.replace(customizeRE, "-"));
|
||
}
|
||
function hasLeadingSlash(str) {
|
||
return str.indexOf("/") === 0;
|
||
}
|
||
function addLeadingSlash(str) {
|
||
return hasLeadingSlash(str) ? str : "/" + str;
|
||
}
|
||
const invokeArrayFns = (fns, arg) => {
|
||
let ret;
|
||
for (let i = 0; i < fns.length; i++) {
|
||
ret = fns[i](arg);
|
||
}
|
||
return ret;
|
||
};
|
||
function once(fn, ctx = null) {
|
||
let res;
|
||
return (...args) => {
|
||
if (fn) {
|
||
res = fn.apply(ctx, args);
|
||
fn = null;
|
||
}
|
||
return res;
|
||
};
|
||
}
|
||
function getValueByDataPath(obj, path) {
|
||
if (!isString$1(path)) {
|
||
return;
|
||
}
|
||
path = path.replace(/\[(\d+)\]/g, ".$1");
|
||
const parts = path.split(".");
|
||
let key = parts[0];
|
||
if (!obj) {
|
||
obj = {};
|
||
}
|
||
if (parts.length === 1) {
|
||
return obj[key];
|
||
}
|
||
return getValueByDataPath(obj[key], parts.slice(1).join("."));
|
||
}
|
||
function sortObject(obj) {
|
||
let sortObj = {};
|
||
if (isPlainObject$1(obj)) {
|
||
Object.keys(obj).sort().forEach((key) => {
|
||
const _key = key;
|
||
sortObj[_key] = obj[_key];
|
||
});
|
||
}
|
||
return !Object.keys(sortObj) ? obj : sortObj;
|
||
}
|
||
const encode = encodeURIComponent;
|
||
function stringifyQuery(obj, encodeStr = encode) {
|
||
const res = obj ? Object.keys(obj).map((key) => {
|
||
let val = obj[key];
|
||
if (typeof val === void 0 || val === null) {
|
||
val = "";
|
||
} else if (isPlainObject$1(val)) {
|
||
val = JSON.stringify(val);
|
||
}
|
||
return encodeStr(key) + "=" + encodeStr(val);
|
||
}).filter((x) => x.length > 0).join("&") : null;
|
||
return res ? `?${res}` : "";
|
||
}
|
||
const PAGE_HOOKS = [
|
||
ON_INIT,
|
||
ON_LOAD,
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_UNLOAD,
|
||
ON_BACK_PRESS,
|
||
ON_PAGE_SCROLL,
|
||
ON_TAB_ITEM_TAP,
|
||
ON_REACH_BOTTOM,
|
||
ON_PULL_DOWN_REFRESH,
|
||
ON_SHARE_TIMELINE,
|
||
ON_SHARE_APP_MESSAGE,
|
||
ON_ADD_TO_FAVORITES,
|
||
ON_SAVE_EXIT_STATE,
|
||
ON_NAVIGATION_BAR_BUTTON_TAP,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
|
||
];
|
||
function isRootHook(name2) {
|
||
return PAGE_HOOKS.indexOf(name2) > -1;
|
||
}
|
||
const UniLifecycleHooks = [
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_LAUNCH,
|
||
ON_ERROR,
|
||
ON_THEME_CHANGE,
|
||
ON_PAGE_NOT_FOUND,
|
||
ON_UNHANDLE_REJECTION,
|
||
ON_EXIT,
|
||
ON_INIT,
|
||
ON_LOAD,
|
||
ON_READY,
|
||
ON_UNLOAD,
|
||
ON_RESIZE,
|
||
ON_BACK_PRESS,
|
||
ON_PAGE_SCROLL,
|
||
ON_TAB_ITEM_TAP,
|
||
ON_REACH_BOTTOM,
|
||
ON_PULL_DOWN_REFRESH,
|
||
ON_SHARE_TIMELINE,
|
||
ON_ADD_TO_FAVORITES,
|
||
ON_SHARE_APP_MESSAGE,
|
||
ON_SAVE_EXIT_STATE,
|
||
ON_NAVIGATION_BAR_BUTTON_TAP,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED,
|
||
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
|
||
];
|
||
const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /* @__PURE__ */ (() => {
|
||
return {
|
||
onPageScroll: 1,
|
||
onShareAppMessage: 1 << 1,
|
||
onShareTimeline: 1 << 2
|
||
};
|
||
})();
|
||
function isUniLifecycleHook(name2, value, checkType = true) {
|
||
if (checkType && !isFunction$1(value)) {
|
||
return false;
|
||
}
|
||
if (UniLifecycleHooks.indexOf(name2) > -1) {
|
||
return true;
|
||
} else if (name2.indexOf("on") === 0) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
let vueApp;
|
||
const createVueAppHooks = [];
|
||
function onCreateVueApp(hook) {
|
||
if (vueApp) {
|
||
return hook(vueApp);
|
||
}
|
||
createVueAppHooks.push(hook);
|
||
}
|
||
function invokeCreateVueAppHook(app) {
|
||
vueApp = app;
|
||
createVueAppHooks.forEach((hook) => hook(app));
|
||
}
|
||
const invokeCreateErrorHandler = once((app, createErrorHandler2) => {
|
||
if (isFunction$1(app._component.onError)) {
|
||
return createErrorHandler2(app);
|
||
}
|
||
});
|
||
const E = function() {
|
||
};
|
||
E.prototype = {
|
||
on: function(name2, callback, ctx) {
|
||
var e2 = this.e || (this.e = {});
|
||
(e2[name2] || (e2[name2] = [])).push({
|
||
fn: callback,
|
||
ctx
|
||
});
|
||
return this;
|
||
},
|
||
once: function(name2, callback, ctx) {
|
||
var self2 = this;
|
||
function listener() {
|
||
self2.off(name2, listener);
|
||
callback.apply(ctx, arguments);
|
||
}
|
||
listener._ = callback;
|
||
return this.on(name2, listener, ctx);
|
||
},
|
||
emit: function(name2) {
|
||
var data = [].slice.call(arguments, 1);
|
||
var evtArr = ((this.e || (this.e = {}))[name2] || []).slice();
|
||
var i = 0;
|
||
var len = evtArr.length;
|
||
for (i; i < len; i++) {
|
||
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
||
}
|
||
return this;
|
||
},
|
||
off: function(name2, callback) {
|
||
var e2 = this.e || (this.e = {});
|
||
var evts = e2[name2];
|
||
var liveEvents = [];
|
||
if (evts && callback) {
|
||
for (var i = evts.length - 1; i >= 0; i--) {
|
||
if (evts[i].fn === callback || evts[i].fn._ === callback) {
|
||
evts.splice(i, 1);
|
||
break;
|
||
}
|
||
}
|
||
liveEvents = evts;
|
||
}
|
||
liveEvents.length ? e2[name2] = liveEvents : delete e2[name2];
|
||
return this;
|
||
}
|
||
};
|
||
var E$1 = E;
|
||
const LOCALE_ZH_HANS = "zh-Hans";
|
||
const LOCALE_ZH_HANT = "zh-Hant";
|
||
const LOCALE_EN = "en";
|
||
const LOCALE_FR = "fr";
|
||
const LOCALE_ES = "es";
|
||
function include(str, parts) {
|
||
return !!parts.find((part) => str.indexOf(part) !== -1);
|
||
}
|
||
function startsWith(str, parts) {
|
||
return parts.find((part) => str.indexOf(part) === 0);
|
||
}
|
||
function normalizeLocale(locale, messages) {
|
||
if (!locale) {
|
||
return;
|
||
}
|
||
locale = locale.trim().replace(/_/g, "-");
|
||
if (messages && messages[locale]) {
|
||
return locale;
|
||
}
|
||
locale = locale.toLowerCase();
|
||
if (locale === "chinese") {
|
||
return LOCALE_ZH_HANS;
|
||
}
|
||
if (locale.indexOf("zh") === 0) {
|
||
if (locale.indexOf("-hans") > -1) {
|
||
return LOCALE_ZH_HANS;
|
||
}
|
||
if (locale.indexOf("-hant") > -1) {
|
||
return LOCALE_ZH_HANT;
|
||
}
|
||
if (include(locale, ["-tw", "-hk", "-mo", "-cht"])) {
|
||
return LOCALE_ZH_HANT;
|
||
}
|
||
return LOCALE_ZH_HANS;
|
||
}
|
||
let locales = [LOCALE_EN, LOCALE_FR, LOCALE_ES];
|
||
if (messages && Object.keys(messages).length > 0) {
|
||
locales = Object.keys(messages);
|
||
}
|
||
const lang = startsWith(locale, locales);
|
||
if (lang) {
|
||
return lang;
|
||
}
|
||
}
|
||
function getBaseSystemInfo() {
|
||
return wx.getSystemInfoSync();
|
||
}
|
||
function validateProtocolFail(name2, msg) {
|
||
console.warn(`${name2}: ${msg}`);
|
||
}
|
||
function validateProtocol(name2, data, protocol, onFail) {
|
||
if (!onFail) {
|
||
onFail = validateProtocolFail;
|
||
}
|
||
for (const key in protocol) {
|
||
const errMsg = validateProp$1(key, data[key], protocol[key], !hasOwn(data, key));
|
||
if (isString$1(errMsg)) {
|
||
onFail(name2, errMsg);
|
||
}
|
||
}
|
||
}
|
||
function validateProtocols(name2, args, protocol, onFail) {
|
||
if (!protocol) {
|
||
return;
|
||
}
|
||
if (!isArray$1(protocol)) {
|
||
return validateProtocol(name2, args[0] || /* @__PURE__ */ Object.create(null), protocol, onFail);
|
||
}
|
||
const len = protocol.length;
|
||
const argsLen = args.length;
|
||
for (let i = 0; i < len; i++) {
|
||
const opts = protocol[i];
|
||
const data = /* @__PURE__ */ Object.create(null);
|
||
if (argsLen > i) {
|
||
data[opts.name] = args[i];
|
||
}
|
||
validateProtocol(name2, data, { [opts.name]: opts }, onFail);
|
||
}
|
||
}
|
||
function validateProp$1(name2, value, prop, isAbsent) {
|
||
if (!isPlainObject$1(prop)) {
|
||
prop = { type: prop };
|
||
}
|
||
const { type, required, validator } = prop;
|
||
if (required && isAbsent) {
|
||
return 'Missing required args: "' + name2 + '"';
|
||
}
|
||
if (value == null && !required) {
|
||
return;
|
||
}
|
||
if (type != null) {
|
||
let isValid = false;
|
||
const types = isArray$1(type) ? type : [type];
|
||
const expectedTypes = [];
|
||
for (let i = 0; i < types.length && !isValid; i++) {
|
||
const { valid, expectedType } = assertType$1(value, types[i]);
|
||
expectedTypes.push(expectedType || "");
|
||
isValid = valid;
|
||
}
|
||
if (!isValid) {
|
||
return getInvalidTypeMessage$1(name2, value, expectedTypes);
|
||
}
|
||
}
|
||
if (validator) {
|
||
return validator(value);
|
||
}
|
||
}
|
||
const isSimpleType$1 = /* @__PURE__ */ makeMap("String,Number,Boolean,Function,Symbol");
|
||
function assertType$1(value, type) {
|
||
let valid;
|
||
const expectedType = getType$1(type);
|
||
if (isSimpleType$1(expectedType)) {
|
||
const t2 = typeof value;
|
||
valid = t2 === expectedType.toLowerCase();
|
||
if (!valid && t2 === "object") {
|
||
valid = value instanceof type;
|
||
}
|
||
} else if (expectedType === "Object") {
|
||
valid = isObject$1(value);
|
||
} else if (expectedType === "Array") {
|
||
valid = isArray$1(value);
|
||
} else {
|
||
{
|
||
valid = value instanceof type;
|
||
}
|
||
}
|
||
return {
|
||
valid,
|
||
expectedType
|
||
};
|
||
}
|
||
function getInvalidTypeMessage$1(name2, value, expectedTypes) {
|
||
let message = `Invalid args: type check failed for args "${name2}". Expected ${expectedTypes.map(capitalize).join(", ")}`;
|
||
const expectedType = expectedTypes[0];
|
||
const receivedType = toRawType(value);
|
||
const expectedValue = styleValue$1(value, expectedType);
|
||
const receivedValue = styleValue$1(value, receivedType);
|
||
if (expectedTypes.length === 1 && isExplicable$1(expectedType) && !isBoolean$2(expectedType, receivedType)) {
|
||
message += ` with value ${expectedValue}`;
|
||
}
|
||
message += `, got ${receivedType} `;
|
||
if (isExplicable$1(receivedType)) {
|
||
message += `with value ${receivedValue}.`;
|
||
}
|
||
return message;
|
||
}
|
||
function getType$1(ctor) {
|
||
const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
|
||
return match ? match[1] : "";
|
||
}
|
||
function styleValue$1(value, type) {
|
||
if (type === "String") {
|
||
return `"${value}"`;
|
||
} else if (type === "Number") {
|
||
return `${Number(value)}`;
|
||
} else {
|
||
return `${value}`;
|
||
}
|
||
}
|
||
function isExplicable$1(type) {
|
||
const explicitTypes = ["string", "number", "boolean"];
|
||
return explicitTypes.some((elem) => type.toLowerCase() === elem);
|
||
}
|
||
function isBoolean$2(...args) {
|
||
return args.some((elem) => elem.toLowerCase() === "boolean");
|
||
}
|
||
function tryCatch(fn) {
|
||
return function() {
|
||
try {
|
||
return fn.apply(fn, arguments);
|
||
} catch (e2) {
|
||
console.error(e2);
|
||
}
|
||
};
|
||
}
|
||
let invokeCallbackId = 1;
|
||
const invokeCallbacks = {};
|
||
function addInvokeCallback(id, name2, callback, keepAlive = false) {
|
||
invokeCallbacks[id] = {
|
||
name: name2,
|
||
keepAlive,
|
||
callback
|
||
};
|
||
return id;
|
||
}
|
||
function invokeCallback(id, res, extras) {
|
||
if (typeof id === "number") {
|
||
const opts = invokeCallbacks[id];
|
||
if (opts) {
|
||
if (!opts.keepAlive) {
|
||
delete invokeCallbacks[id];
|
||
}
|
||
return opts.callback(res, extras);
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
const API_SUCCESS = "success";
|
||
const API_FAIL = "fail";
|
||
const API_COMPLETE = "complete";
|
||
function getApiCallbacks(args) {
|
||
const apiCallbacks = {};
|
||
for (const name2 in args) {
|
||
const fn = args[name2];
|
||
if (isFunction$1(fn)) {
|
||
apiCallbacks[name2] = tryCatch(fn);
|
||
delete args[name2];
|
||
}
|
||
}
|
||
return apiCallbacks;
|
||
}
|
||
function normalizeErrMsg$1(errMsg, name2) {
|
||
if (!errMsg || errMsg.indexOf(":fail") === -1) {
|
||
return name2 + ":ok";
|
||
}
|
||
return name2 + errMsg.substring(errMsg.indexOf(":fail"));
|
||
}
|
||
function createAsyncApiCallback(name2, args = {}, { beforeAll, beforeSuccess } = {}) {
|
||
if (!isPlainObject$1(args)) {
|
||
args = {};
|
||
}
|
||
const { success, fail, complete } = getApiCallbacks(args);
|
||
const hasSuccess = isFunction$1(success);
|
||
const hasFail = isFunction$1(fail);
|
||
const hasComplete = isFunction$1(complete);
|
||
const callbackId = invokeCallbackId++;
|
||
addInvokeCallback(callbackId, name2, (res) => {
|
||
res = res || {};
|
||
res.errMsg = normalizeErrMsg$1(res.errMsg, name2);
|
||
isFunction$1(beforeAll) && beforeAll(res);
|
||
if (res.errMsg === name2 + ":ok") {
|
||
isFunction$1(beforeSuccess) && beforeSuccess(res, args);
|
||
hasSuccess && success(res);
|
||
} else {
|
||
hasFail && fail(res);
|
||
}
|
||
hasComplete && complete(res);
|
||
});
|
||
return callbackId;
|
||
}
|
||
const HOOK_SUCCESS = "success";
|
||
const HOOK_FAIL = "fail";
|
||
const HOOK_COMPLETE = "complete";
|
||
const globalInterceptors = {};
|
||
const scopedInterceptors = {};
|
||
function wrapperHook(hook, params) {
|
||
return function(data) {
|
||
return hook(data, params) || data;
|
||
};
|
||
}
|
||
function queue$2(hooks, data, params) {
|
||
let promise = false;
|
||
for (let i = 0; i < hooks.length; i++) {
|
||
const hook = hooks[i];
|
||
if (promise) {
|
||
promise = Promise.resolve(wrapperHook(hook, params));
|
||
} else {
|
||
const res = hook(data, params);
|
||
if (isPromise(res)) {
|
||
promise = Promise.resolve(res);
|
||
}
|
||
if (res === false) {
|
||
return {
|
||
then() {
|
||
},
|
||
catch() {
|
||
}
|
||
};
|
||
}
|
||
}
|
||
}
|
||
return promise || {
|
||
then(callback) {
|
||
return callback(data);
|
||
},
|
||
catch() {
|
||
}
|
||
};
|
||
}
|
||
function wrapperOptions(interceptors2, options = {}) {
|
||
[HOOK_SUCCESS, HOOK_FAIL, HOOK_COMPLETE].forEach((name2) => {
|
||
const hooks = interceptors2[name2];
|
||
if (!isArray$1(hooks)) {
|
||
return;
|
||
}
|
||
const oldCallback = options[name2];
|
||
options[name2] = function callbackInterceptor(res) {
|
||
queue$2(hooks, res, options).then((res2) => {
|
||
return isFunction$1(oldCallback) && oldCallback(res2) || res2;
|
||
});
|
||
};
|
||
});
|
||
return options;
|
||
}
|
||
function wrapperReturnValue(method, returnValue) {
|
||
const returnValueHooks = [];
|
||
if (isArray$1(globalInterceptors.returnValue)) {
|
||
returnValueHooks.push(...globalInterceptors.returnValue);
|
||
}
|
||
const interceptor = scopedInterceptors[method];
|
||
if (interceptor && isArray$1(interceptor.returnValue)) {
|
||
returnValueHooks.push(...interceptor.returnValue);
|
||
}
|
||
returnValueHooks.forEach((hook) => {
|
||
returnValue = hook(returnValue) || returnValue;
|
||
});
|
||
return returnValue;
|
||
}
|
||
function getApiInterceptorHooks(method) {
|
||
const interceptor = /* @__PURE__ */ Object.create(null);
|
||
Object.keys(globalInterceptors).forEach((hook) => {
|
||
if (hook !== "returnValue") {
|
||
interceptor[hook] = globalInterceptors[hook].slice();
|
||
}
|
||
});
|
||
const scopedInterceptor = scopedInterceptors[method];
|
||
if (scopedInterceptor) {
|
||
Object.keys(scopedInterceptor).forEach((hook) => {
|
||
if (hook !== "returnValue") {
|
||
interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
|
||
}
|
||
});
|
||
}
|
||
return interceptor;
|
||
}
|
||
function invokeApi(method, api, options, params) {
|
||
const interceptor = getApiInterceptorHooks(method);
|
||
if (interceptor && Object.keys(interceptor).length) {
|
||
if (isArray$1(interceptor.invoke)) {
|
||
const res = queue$2(interceptor.invoke, options);
|
||
return res.then((options2) => {
|
||
return api(wrapperOptions(getApiInterceptorHooks(method), options2), ...params);
|
||
});
|
||
} else {
|
||
return api(wrapperOptions(interceptor, options), ...params);
|
||
}
|
||
}
|
||
return api(options, ...params);
|
||
}
|
||
function hasCallback(args) {
|
||
if (isPlainObject$1(args) && [API_SUCCESS, API_FAIL, API_COMPLETE].find((cb) => isFunction$1(args[cb]))) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function handlePromise(promise) {
|
||
return promise;
|
||
}
|
||
function promisify$1(name2, fn) {
|
||
return (args = {}, ...rest) => {
|
||
if (hasCallback(args)) {
|
||
return wrapperReturnValue(name2, invokeApi(name2, fn, args, rest));
|
||
}
|
||
return wrapperReturnValue(name2, handlePromise(new Promise((resolve2, reject) => {
|
||
invokeApi(name2, fn, extend(args, { success: resolve2, fail: reject }), rest);
|
||
})));
|
||
};
|
||
}
|
||
function formatApiArgs(args, options) {
|
||
const params = args[0];
|
||
if (!options || !isPlainObject$1(options.formatArgs) && isPlainObject$1(params)) {
|
||
return;
|
||
}
|
||
const formatArgs = options.formatArgs;
|
||
const keys = Object.keys(formatArgs);
|
||
for (let i = 0; i < keys.length; i++) {
|
||
const name2 = keys[i];
|
||
const formatterOrDefaultValue = formatArgs[name2];
|
||
if (isFunction$1(formatterOrDefaultValue)) {
|
||
const errMsg = formatterOrDefaultValue(args[0][name2], params);
|
||
if (isString$1(errMsg)) {
|
||
return errMsg;
|
||
}
|
||
} else {
|
||
if (!hasOwn(params, name2)) {
|
||
params[name2] = formatterOrDefaultValue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function invokeSuccess(id, name2, res) {
|
||
const result = {
|
||
errMsg: name2 + ":ok"
|
||
};
|
||
return invokeCallback(id, extend(res || {}, result));
|
||
}
|
||
function invokeFail(id, name2, errMsg, errRes = {}) {
|
||
const apiErrMsg = name2 + ":fail" + (errMsg ? " " + errMsg : "");
|
||
delete errRes.errCode;
|
||
let res = extend({ errMsg: apiErrMsg }, errRes);
|
||
return invokeCallback(id, res);
|
||
}
|
||
function beforeInvokeApi(name2, args, protocol, options) {
|
||
{
|
||
validateProtocols(name2, args, protocol);
|
||
}
|
||
if (options && options.beforeInvoke) {
|
||
const errMsg2 = options.beforeInvoke(args);
|
||
if (isString$1(errMsg2)) {
|
||
return errMsg2;
|
||
}
|
||
}
|
||
const errMsg = formatApiArgs(args, options);
|
||
if (errMsg) {
|
||
return errMsg;
|
||
}
|
||
}
|
||
function normalizeErrMsg(errMsg) {
|
||
if (!errMsg || isString$1(errMsg)) {
|
||
return errMsg;
|
||
}
|
||
if (errMsg.stack) {
|
||
console.error(errMsg.message + LINEFEED + errMsg.stack);
|
||
return errMsg.message;
|
||
}
|
||
return errMsg;
|
||
}
|
||
function wrapperTaskApi(name2, fn, protocol, options) {
|
||
return (args) => {
|
||
const id = createAsyncApiCallback(name2, args, options);
|
||
const errMsg = beforeInvokeApi(name2, [args], protocol, options);
|
||
if (errMsg) {
|
||
return invokeFail(id, name2, errMsg);
|
||
}
|
||
return fn(args, {
|
||
resolve: (res) => invokeSuccess(id, name2, res),
|
||
reject: (errMsg2, errRes) => invokeFail(id, name2, normalizeErrMsg(errMsg2), errRes)
|
||
});
|
||
};
|
||
}
|
||
function wrapperSyncApi(name2, fn, protocol, options) {
|
||
return (...args) => {
|
||
const errMsg = beforeInvokeApi(name2, args, protocol, options);
|
||
if (errMsg) {
|
||
throw new Error(errMsg);
|
||
}
|
||
return fn.apply(null, args);
|
||
};
|
||
}
|
||
function wrapperAsyncApi(name2, fn, protocol, options) {
|
||
return wrapperTaskApi(name2, fn, protocol, options);
|
||
}
|
||
function defineSyncApi(name2, fn, protocol, options) {
|
||
return wrapperSyncApi(name2, fn, protocol, options);
|
||
}
|
||
function defineAsyncApi(name2, fn, protocol, options) {
|
||
return promisify$1(name2, wrapperAsyncApi(name2, fn, protocol, options));
|
||
}
|
||
const API_UPX2PX = "upx2px";
|
||
const Upx2pxProtocol = [
|
||
{
|
||
name: "upx",
|
||
type: [Number, String],
|
||
required: true
|
||
}
|
||
];
|
||
const EPS = 1e-4;
|
||
const BASE_DEVICE_WIDTH = 750;
|
||
let isIOS = false;
|
||
let deviceWidth = 0;
|
||
let deviceDPR = 0;
|
||
function checkDeviceWidth() {
|
||
const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
|
||
deviceWidth = windowWidth;
|
||
deviceDPR = pixelRatio;
|
||
isIOS = platform === "ios";
|
||
}
|
||
const upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
|
||
if (deviceWidth === 0) {
|
||
checkDeviceWidth();
|
||
}
|
||
number = Number(number);
|
||
if (number === 0) {
|
||
return 0;
|
||
}
|
||
let width = newDeviceWidth || deviceWidth;
|
||
let result = number / BASE_DEVICE_WIDTH * width;
|
||
if (result < 0) {
|
||
result = -result;
|
||
}
|
||
result = Math.floor(result + EPS);
|
||
if (result === 0) {
|
||
if (deviceDPR === 1 || !isIOS) {
|
||
result = 1;
|
||
} else {
|
||
result = 0.5;
|
||
}
|
||
}
|
||
return number < 0 ? -result : result;
|
||
}, Upx2pxProtocol);
|
||
const API_ADD_INTERCEPTOR = "addInterceptor";
|
||
const API_REMOVE_INTERCEPTOR = "removeInterceptor";
|
||
const AddInterceptorProtocol = [
|
||
{
|
||
name: "method",
|
||
type: [String, Object],
|
||
required: true
|
||
}
|
||
];
|
||
const RemoveInterceptorProtocol = AddInterceptorProtocol;
|
||
function mergeInterceptorHook(interceptors2, interceptor) {
|
||
Object.keys(interceptor).forEach((hook) => {
|
||
if (isFunction$1(interceptor[hook])) {
|
||
interceptors2[hook] = mergeHook(interceptors2[hook], interceptor[hook]);
|
||
}
|
||
});
|
||
}
|
||
function removeInterceptorHook(interceptors2, interceptor) {
|
||
if (!interceptors2 || !interceptor) {
|
||
return;
|
||
}
|
||
Object.keys(interceptor).forEach((name2) => {
|
||
const hooks = interceptors2[name2];
|
||
const hook = interceptor[name2];
|
||
if (isArray$1(hooks) && isFunction$1(hook)) {
|
||
remove(hooks, hook);
|
||
}
|
||
});
|
||
}
|
||
function mergeHook(parentVal, childVal) {
|
||
const res = childVal ? parentVal ? parentVal.concat(childVal) : isArray$1(childVal) ? childVal : [childVal] : parentVal;
|
||
return res ? dedupeHooks(res) : res;
|
||
}
|
||
function dedupeHooks(hooks) {
|
||
const res = [];
|
||
for (let i = 0; i < hooks.length; i++) {
|
||
if (res.indexOf(hooks[i]) === -1) {
|
||
res.push(hooks[i]);
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
|
||
if (isString$1(method) && isPlainObject$1(interceptor)) {
|
||
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
|
||
} else if (isPlainObject$1(method)) {
|
||
mergeInterceptorHook(globalInterceptors, method);
|
||
}
|
||
}, AddInterceptorProtocol);
|
||
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
|
||
if (isString$1(method)) {
|
||
if (isPlainObject$1(interceptor)) {
|
||
removeInterceptorHook(scopedInterceptors[method], interceptor);
|
||
} else {
|
||
delete scopedInterceptors[method];
|
||
}
|
||
} else if (isPlainObject$1(method)) {
|
||
removeInterceptorHook(globalInterceptors, method);
|
||
}
|
||
}, RemoveInterceptorProtocol);
|
||
const interceptors = {};
|
||
const API_ON = "$on";
|
||
const OnProtocol = [
|
||
{
|
||
name: "event",
|
||
type: String,
|
||
required: true
|
||
},
|
||
{
|
||
name: "callback",
|
||
type: Function,
|
||
required: true
|
||
}
|
||
];
|
||
const API_ONCE = "$once";
|
||
const OnceProtocol = OnProtocol;
|
||
const API_OFF = "$off";
|
||
const OffProtocol = [
|
||
{
|
||
name: "event",
|
||
type: [String, Array]
|
||
},
|
||
{
|
||
name: "callback",
|
||
type: Function
|
||
}
|
||
];
|
||
const API_EMIT = "$emit";
|
||
const EmitProtocol = [
|
||
{
|
||
name: "event",
|
||
type: String,
|
||
required: true
|
||
}
|
||
];
|
||
const emitter = new E$1();
|
||
const $on = defineSyncApi(API_ON, (name2, callback) => {
|
||
emitter.on(name2, callback);
|
||
return () => emitter.off(name2, callback);
|
||
}, OnProtocol);
|
||
const $once = defineSyncApi(API_ONCE, (name2, callback) => {
|
||
emitter.once(name2, callback);
|
||
return () => emitter.off(name2, callback);
|
||
}, OnceProtocol);
|
||
const $off = defineSyncApi(API_OFF, (name2, callback) => {
|
||
if (!name2) {
|
||
emitter.e = {};
|
||
return;
|
||
}
|
||
if (!isArray$1(name2))
|
||
name2 = [name2];
|
||
name2.forEach((n2) => emitter.off(n2, callback));
|
||
}, OffProtocol);
|
||
const $emit = defineSyncApi(API_EMIT, (name2, ...args) => {
|
||
emitter.emit(name2, ...args);
|
||
}, EmitProtocol);
|
||
let cid;
|
||
let cidErrMsg;
|
||
let enabled;
|
||
function normalizePushMessage(message) {
|
||
try {
|
||
return JSON.parse(message);
|
||
} catch (e2) {
|
||
}
|
||
return message;
|
||
}
|
||
function invokePushCallback(args) {
|
||
if (args.type === "enabled") {
|
||
enabled = true;
|
||
} else if (args.type === "clientId") {
|
||
cid = args.cid;
|
||
cidErrMsg = args.errMsg;
|
||
invokeGetPushCidCallbacks(cid, args.errMsg);
|
||
} else if (args.type === "pushMsg") {
|
||
const message = {
|
||
type: "receive",
|
||
data: normalizePushMessage(args.message)
|
||
};
|
||
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
|
||
const callback = onPushMessageCallbacks[i];
|
||
callback(message);
|
||
if (message.stopped) {
|
||
break;
|
||
}
|
||
}
|
||
} else if (args.type === "click") {
|
||
onPushMessageCallbacks.forEach((callback) => {
|
||
callback({
|
||
type: "click",
|
||
data: normalizePushMessage(args.message)
|
||
});
|
||
});
|
||
}
|
||
}
|
||
const getPushCidCallbacks = [];
|
||
function invokeGetPushCidCallbacks(cid2, errMsg) {
|
||
getPushCidCallbacks.forEach((callback) => {
|
||
callback(cid2, errMsg);
|
||
});
|
||
getPushCidCallbacks.length = 0;
|
||
}
|
||
const API_GET_PUSH_CLIENT_ID = "getPushClientId";
|
||
const getPushClientId = defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve: resolve2, reject }) => {
|
||
Promise.resolve().then(() => {
|
||
if (typeof enabled === "undefined") {
|
||
enabled = false;
|
||
cid = "";
|
||
cidErrMsg = "uniPush is not enabled";
|
||
}
|
||
getPushCidCallbacks.push((cid2, errMsg) => {
|
||
if (cid2) {
|
||
resolve2({ cid: cid2 });
|
||
} else {
|
||
reject(errMsg);
|
||
}
|
||
});
|
||
if (typeof cid !== "undefined") {
|
||
invokeGetPushCidCallbacks(cid, cidErrMsg);
|
||
}
|
||
});
|
||
});
|
||
const onPushMessageCallbacks = [];
|
||
const onPushMessage = (fn) => {
|
||
if (onPushMessageCallbacks.indexOf(fn) === -1) {
|
||
onPushMessageCallbacks.push(fn);
|
||
}
|
||
};
|
||
const offPushMessage = (fn) => {
|
||
if (!fn) {
|
||
onPushMessageCallbacks.length = 0;
|
||
} else {
|
||
const index2 = onPushMessageCallbacks.indexOf(fn);
|
||
if (index2 > -1) {
|
||
onPushMessageCallbacks.splice(index2, 1);
|
||
}
|
||
}
|
||
};
|
||
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
|
||
const CONTEXT_API_RE = /^create|Manager$/;
|
||
const CONTEXT_API_RE_EXC = ["createBLEConnection"];
|
||
const ASYNC_API = ["createBLEConnection"];
|
||
const CALLBACK_API_RE = /^on|^off/;
|
||
function isContextApi(name2) {
|
||
return CONTEXT_API_RE.test(name2) && CONTEXT_API_RE_EXC.indexOf(name2) === -1;
|
||
}
|
||
function isSyncApi(name2) {
|
||
return SYNC_API_RE.test(name2) && ASYNC_API.indexOf(name2) === -1;
|
||
}
|
||
function isCallbackApi(name2) {
|
||
return CALLBACK_API_RE.test(name2) && name2 !== "onPush";
|
||
}
|
||
function shouldPromise(name2) {
|
||
if (isContextApi(name2) || isSyncApi(name2) || isCallbackApi(name2)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
if (!Promise.prototype.finally) {
|
||
Promise.prototype.finally = function(onfinally) {
|
||
const promise = this.constructor;
|
||
return this.then((value) => promise.resolve(onfinally && onfinally()).then(() => value), (reason) => promise.resolve(onfinally && onfinally()).then(() => {
|
||
throw reason;
|
||
}));
|
||
};
|
||
}
|
||
function promisify(name2, api) {
|
||
if (!shouldPromise(name2)) {
|
||
return api;
|
||
}
|
||
if (!isFunction$1(api)) {
|
||
return api;
|
||
}
|
||
return function promiseApi(options = {}, ...rest) {
|
||
if (isFunction$1(options.success) || isFunction$1(options.fail) || isFunction$1(options.complete)) {
|
||
return wrapperReturnValue(name2, invokeApi(name2, api, options, rest));
|
||
}
|
||
return wrapperReturnValue(name2, handlePromise(new Promise((resolve2, reject) => {
|
||
invokeApi(name2, api, extend({}, options, {
|
||
success: resolve2,
|
||
fail: reject
|
||
}), rest);
|
||
})));
|
||
};
|
||
}
|
||
const CALLBACKS = ["success", "fail", "cancel", "complete"];
|
||
function initWrapper(protocols2) {
|
||
function processCallback(methodName, method, returnValue) {
|
||
return function(res) {
|
||
return method(processReturnValue(methodName, res, returnValue));
|
||
};
|
||
}
|
||
function processArgs(methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
|
||
if (isPlainObject$1(fromArgs)) {
|
||
const toArgs = keepFromArgs === true ? fromArgs : {};
|
||
if (isFunction$1(argsOption)) {
|
||
argsOption = argsOption(fromArgs, toArgs) || {};
|
||
}
|
||
for (const key in fromArgs) {
|
||
if (hasOwn(argsOption, key)) {
|
||
let keyOption = argsOption[key];
|
||
if (isFunction$1(keyOption)) {
|
||
keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
|
||
}
|
||
if (!keyOption) {
|
||
console.warn(`微信小程序 ${methodName} 暂不支持 ${key}`);
|
||
} else if (isString$1(keyOption)) {
|
||
toArgs[keyOption] = fromArgs[key];
|
||
} else if (isPlainObject$1(keyOption)) {
|
||
toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
|
||
}
|
||
} else if (CALLBACKS.indexOf(key) !== -1) {
|
||
const callback = fromArgs[key];
|
||
if (isFunction$1(callback)) {
|
||
toArgs[key] = processCallback(methodName, callback, returnValue);
|
||
}
|
||
} else {
|
||
if (!keepFromArgs && !hasOwn(toArgs, key)) {
|
||
toArgs[key] = fromArgs[key];
|
||
}
|
||
}
|
||
}
|
||
return toArgs;
|
||
} else if (isFunction$1(fromArgs)) {
|
||
fromArgs = processCallback(methodName, fromArgs, returnValue);
|
||
}
|
||
return fromArgs;
|
||
}
|
||
function processReturnValue(methodName, res, returnValue, keepReturnValue = false) {
|
||
if (isFunction$1(protocols2.returnValue)) {
|
||
res = protocols2.returnValue(methodName, res);
|
||
}
|
||
return processArgs(methodName, res, returnValue, {}, keepReturnValue);
|
||
}
|
||
return function wrapper(methodName, method) {
|
||
if (!hasOwn(protocols2, methodName)) {
|
||
return method;
|
||
}
|
||
const protocol = protocols2[methodName];
|
||
if (!protocol) {
|
||
return function() {
|
||
console.error(`微信小程序 暂不支持${methodName}`);
|
||
};
|
||
}
|
||
return function(arg1, arg2) {
|
||
let options = protocol;
|
||
if (isFunction$1(protocol)) {
|
||
options = protocol(arg1);
|
||
}
|
||
arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
|
||
const args = [arg1];
|
||
if (typeof arg2 !== "undefined") {
|
||
args.push(arg2);
|
||
}
|
||
const returnValue = wx[options.name || methodName].apply(wx, args);
|
||
if (isSyncApi(methodName)) {
|
||
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName));
|
||
}
|
||
return returnValue;
|
||
};
|
||
};
|
||
}
|
||
const getLocale = () => {
|
||
const app = isFunction$1(getApp) && getApp({ allowDefault: true });
|
||
if (app && app.$vm) {
|
||
return app.$vm.$locale;
|
||
}
|
||
return normalizeLocale(wx.getSystemInfoSync().language) || LOCALE_EN;
|
||
};
|
||
const setLocale = (locale) => {
|
||
const app = isFunction$1(getApp) && getApp();
|
||
if (!app) {
|
||
return false;
|
||
}
|
||
const oldLocale = app.$vm.$locale;
|
||
if (oldLocale !== locale) {
|
||
app.$vm.$locale = locale;
|
||
onLocaleChangeCallbacks.forEach((fn) => fn({ locale }));
|
||
return true;
|
||
}
|
||
return false;
|
||
};
|
||
const onLocaleChangeCallbacks = [];
|
||
const onLocaleChange = (fn) => {
|
||
if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
|
||
onLocaleChangeCallbacks.push(fn);
|
||
}
|
||
};
|
||
if (typeof global !== "undefined") {
|
||
global.getLocale = getLocale;
|
||
}
|
||
const UUID_KEY = "__DC_STAT_UUID";
|
||
let deviceId;
|
||
function useDeviceId(global2 = wx) {
|
||
return function addDeviceId(_, toRes) {
|
||
deviceId = deviceId || global2.getStorageSync(UUID_KEY);
|
||
if (!deviceId) {
|
||
deviceId = Date.now() + "" + Math.floor(Math.random() * 1e7);
|
||
wx.setStorage({
|
||
key: UUID_KEY,
|
||
data: deviceId
|
||
});
|
||
}
|
||
toRes.deviceId = deviceId;
|
||
};
|
||
}
|
||
function addSafeAreaInsets(fromRes, toRes) {
|
||
if (fromRes.safeArea) {
|
||
const safeArea = fromRes.safeArea;
|
||
toRes.safeAreaInsets = {
|
||
top: safeArea.top,
|
||
left: safeArea.left,
|
||
right: fromRes.windowWidth - safeArea.right,
|
||
bottom: fromRes.screenHeight - safeArea.bottom
|
||
};
|
||
}
|
||
}
|
||
function populateParameters(fromRes, toRes) {
|
||
const { brand = "", model = "", system = "", language = "", theme, version: version2, platform, fontSizeSetting, SDKVersion, pixelRatio, deviceOrientation } = fromRes;
|
||
let osName = "";
|
||
let osVersion = "";
|
||
{
|
||
osName = system.split(" ")[0] || "";
|
||
osVersion = system.split(" ")[1] || "";
|
||
}
|
||
let hostVersion = version2;
|
||
let deviceType = getGetDeviceType(fromRes, model);
|
||
let deviceBrand = getDeviceBrand(brand);
|
||
let _hostName = getHostName(fromRes);
|
||
let _deviceOrientation = deviceOrientation;
|
||
let _devicePixelRatio = pixelRatio;
|
||
let _SDKVersion = SDKVersion;
|
||
const hostLanguage = language.replace(/_/g, "-");
|
||
const parameters = {
|
||
appId: "__UNI__98AF235",
|
||
appName: "FeiYi",
|
||
appVersion: "1.0.0",
|
||
appVersionCode: "100",
|
||
appLanguage: getAppLanguage(hostLanguage),
|
||
uniCompileVersion: "4.15",
|
||
uniRuntimeVersion: "4.15",
|
||
uniPlatform: "mp-weixin",
|
||
deviceBrand,
|
||
deviceModel: model,
|
||
deviceType,
|
||
devicePixelRatio: _devicePixelRatio,
|
||
deviceOrientation: _deviceOrientation,
|
||
osName: osName.toLocaleLowerCase(),
|
||
osVersion,
|
||
hostTheme: theme,
|
||
hostVersion,
|
||
hostLanguage,
|
||
hostName: _hostName,
|
||
hostSDKVersion: _SDKVersion,
|
||
hostFontSizeSetting: fontSizeSetting,
|
||
windowTop: 0,
|
||
windowBottom: 0,
|
||
// TODO
|
||
osLanguage: void 0,
|
||
osTheme: void 0,
|
||
ua: void 0,
|
||
hostPackageName: void 0,
|
||
browserName: void 0,
|
||
browserVersion: void 0
|
||
};
|
||
extend(toRes, parameters);
|
||
}
|
||
function getGetDeviceType(fromRes, model) {
|
||
let deviceType = fromRes.deviceType || "phone";
|
||
{
|
||
const deviceTypeMaps = {
|
||
ipad: "pad",
|
||
windows: "pc",
|
||
mac: "pc"
|
||
};
|
||
const deviceTypeMapsKeys = Object.keys(deviceTypeMaps);
|
||
const _model = model.toLocaleLowerCase();
|
||
for (let index2 = 0; index2 < deviceTypeMapsKeys.length; index2++) {
|
||
const _m = deviceTypeMapsKeys[index2];
|
||
if (_model.indexOf(_m) !== -1) {
|
||
deviceType = deviceTypeMaps[_m];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return deviceType;
|
||
}
|
||
function getDeviceBrand(brand) {
|
||
let deviceBrand = brand;
|
||
if (deviceBrand) {
|
||
deviceBrand = deviceBrand.toLocaleLowerCase();
|
||
}
|
||
return deviceBrand;
|
||
}
|
||
function getAppLanguage(defaultLanguage) {
|
||
return getLocale ? getLocale() : defaultLanguage;
|
||
}
|
||
function getHostName(fromRes) {
|
||
const _platform = "WeChat";
|
||
let _hostName = fromRes.hostName || _platform;
|
||
{
|
||
if (fromRes.environment) {
|
||
_hostName = fromRes.environment;
|
||
} else if (fromRes.host && fromRes.host.env) {
|
||
_hostName = fromRes.host.env;
|
||
}
|
||
}
|
||
return _hostName;
|
||
}
|
||
const getSystemInfo = {
|
||
returnValue: (fromRes, toRes) => {
|
||
addSafeAreaInsets(fromRes, toRes);
|
||
useDeviceId()(fromRes, toRes);
|
||
populateParameters(fromRes, toRes);
|
||
}
|
||
};
|
||
const getSystemInfoSync = getSystemInfo;
|
||
const redirectTo = {};
|
||
const previewImage = {
|
||
args(fromArgs, toArgs) {
|
||
let currentIndex = parseInt(fromArgs.current);
|
||
if (isNaN(currentIndex)) {
|
||
return;
|
||
}
|
||
const urls = fromArgs.urls;
|
||
if (!isArray$1(urls)) {
|
||
return;
|
||
}
|
||
const len = urls.length;
|
||
if (!len) {
|
||
return;
|
||
}
|
||
if (currentIndex < 0) {
|
||
currentIndex = 0;
|
||
} else if (currentIndex >= len) {
|
||
currentIndex = len - 1;
|
||
}
|
||
if (currentIndex > 0) {
|
||
toArgs.current = urls[currentIndex];
|
||
toArgs.urls = urls.filter((item, index2) => index2 < currentIndex ? item !== urls[currentIndex] : true);
|
||
} else {
|
||
toArgs.current = urls[0];
|
||
}
|
||
return {
|
||
indicator: false,
|
||
loop: false
|
||
};
|
||
}
|
||
};
|
||
const showActionSheet = {
|
||
args(fromArgs, toArgs) {
|
||
toArgs.alertText = fromArgs.title;
|
||
}
|
||
};
|
||
const getDeviceInfo = {
|
||
returnValue: (fromRes, toRes) => {
|
||
const { brand, model } = fromRes;
|
||
let deviceType = getGetDeviceType(fromRes, model);
|
||
let deviceBrand = getDeviceBrand(brand);
|
||
useDeviceId()(fromRes, toRes);
|
||
toRes = sortObject(extend(toRes, {
|
||
deviceType,
|
||
deviceBrand,
|
||
deviceModel: model
|
||
}));
|
||
}
|
||
};
|
||
const getAppBaseInfo = {
|
||
returnValue: (fromRes, toRes) => {
|
||
const { version: version2, language, SDKVersion, theme } = fromRes;
|
||
let _hostName = getHostName(fromRes);
|
||
let hostLanguage = language.replace(/_/g, "-");
|
||
toRes = sortObject(extend(toRes, {
|
||
hostVersion: version2,
|
||
hostLanguage,
|
||
hostName: _hostName,
|
||
hostSDKVersion: SDKVersion,
|
||
hostTheme: theme,
|
||
appId: "__UNI__98AF235",
|
||
appName: "FeiYi",
|
||
appVersion: "1.0.0",
|
||
appVersionCode: "100",
|
||
appLanguage: getAppLanguage(hostLanguage)
|
||
}));
|
||
}
|
||
};
|
||
const getWindowInfo = {
|
||
returnValue: (fromRes, toRes) => {
|
||
addSafeAreaInsets(fromRes, toRes);
|
||
toRes = sortObject(extend(toRes, {
|
||
windowTop: 0,
|
||
windowBottom: 0
|
||
}));
|
||
}
|
||
};
|
||
const getAppAuthorizeSetting = {
|
||
returnValue: function(fromRes, toRes) {
|
||
const { locationReducedAccuracy } = fromRes;
|
||
toRes.locationAccuracy = "unsupported";
|
||
if (locationReducedAccuracy === true) {
|
||
toRes.locationAccuracy = "reduced";
|
||
} else if (locationReducedAccuracy === false) {
|
||
toRes.locationAccuracy = "full";
|
||
}
|
||
}
|
||
};
|
||
const baseApis = {
|
||
$on,
|
||
$off,
|
||
$once,
|
||
$emit,
|
||
upx2px,
|
||
interceptors,
|
||
addInterceptor,
|
||
removeInterceptor,
|
||
onCreateVueApp,
|
||
invokeCreateVueAppHook,
|
||
getLocale,
|
||
setLocale,
|
||
onLocaleChange,
|
||
getPushClientId,
|
||
onPushMessage,
|
||
offPushMessage,
|
||
invokePushCallback
|
||
};
|
||
function initUni(api, protocols2, platform = wx) {
|
||
const wrapper = initWrapper(protocols2);
|
||
const UniProxyHandlers = {
|
||
get(target, key) {
|
||
if (hasOwn(target, key)) {
|
||
return target[key];
|
||
}
|
||
if (hasOwn(api, key)) {
|
||
return promisify(key, api[key]);
|
||
}
|
||
if (hasOwn(baseApis, key)) {
|
||
return promisify(key, baseApis[key]);
|
||
}
|
||
return promisify(key, wrapper(key, platform[key]));
|
||
}
|
||
};
|
||
return new Proxy({}, UniProxyHandlers);
|
||
}
|
||
function initGetProvider(providers) {
|
||
return function getProvider2({ service, success, fail, complete }) {
|
||
let res;
|
||
if (providers[service]) {
|
||
res = {
|
||
errMsg: "getProvider:ok",
|
||
service,
|
||
provider: providers[service]
|
||
};
|
||
isFunction$1(success) && success(res);
|
||
} else {
|
||
res = {
|
||
errMsg: "getProvider:fail:服务[" + service + "]不存在"
|
||
};
|
||
isFunction$1(fail) && fail(res);
|
||
}
|
||
isFunction$1(complete) && complete(res);
|
||
};
|
||
}
|
||
const objectKeys = [
|
||
"qy",
|
||
"env",
|
||
"error",
|
||
"version",
|
||
"lanDebug",
|
||
"cloud",
|
||
"serviceMarket",
|
||
"router",
|
||
"worklet",
|
||
"__webpack_require_UNI_MP_PLUGIN__"
|
||
];
|
||
const singlePageDisableKey = ["lanDebug", "router", "worklet"];
|
||
const launchOption = wx.getLaunchOptionsSync ? wx.getLaunchOptionsSync() : null;
|
||
function isWxKey(key) {
|
||
if (launchOption && launchOption.scene === 1154 && singlePageDisableKey.includes(key)) {
|
||
return false;
|
||
}
|
||
return objectKeys.indexOf(key) > -1 || typeof wx[key] === "function";
|
||
}
|
||
function initWx() {
|
||
const newWx = {};
|
||
for (const key in wx) {
|
||
if (isWxKey(key)) {
|
||
newWx[key] = wx[key];
|
||
}
|
||
}
|
||
if (typeof globalThis !== "undefined" && typeof requireMiniProgram === "undefined") {
|
||
globalThis.wx = newWx;
|
||
}
|
||
return newWx;
|
||
}
|
||
const mocks$1 = ["__route__", "__wxExparserNodeId__", "__wxWebviewId__"];
|
||
const getProvider = initGetProvider({
|
||
oauth: ["weixin"],
|
||
share: ["weixin"],
|
||
payment: ["wxpay"],
|
||
push: ["weixin"]
|
||
});
|
||
function initComponentMocks(component) {
|
||
const res = /* @__PURE__ */ Object.create(null);
|
||
mocks$1.forEach((name2) => {
|
||
res[name2] = component[name2];
|
||
});
|
||
return res;
|
||
}
|
||
function createSelectorQuery() {
|
||
const query = wx$2.createSelectorQuery();
|
||
const oldIn = query.in;
|
||
query.in = function newIn(component) {
|
||
return oldIn.call(this, initComponentMocks(component));
|
||
};
|
||
return query;
|
||
}
|
||
const wx$2 = initWx();
|
||
let baseInfo = wx$2.getAppBaseInfo && wx$2.getAppBaseInfo();
|
||
if (!baseInfo) {
|
||
baseInfo = wx$2.getSystemInfoSync();
|
||
}
|
||
const host = baseInfo ? baseInfo.host : null;
|
||
const shareVideoMessage = host && host.env === "SAAASDK" ? wx$2.miniapp.shareVideoMessage : wx$2.shareVideoMessage;
|
||
var shims = /* @__PURE__ */ Object.freeze({
|
||
__proto__: null,
|
||
createSelectorQuery,
|
||
getProvider,
|
||
shareVideoMessage
|
||
});
|
||
const compressImage = {
|
||
args(fromArgs, toArgs) {
|
||
if (fromArgs.compressedHeight && !toArgs.compressHeight) {
|
||
toArgs.compressHeight = fromArgs.compressedHeight;
|
||
}
|
||
if (fromArgs.compressedWidth && !toArgs.compressWidth) {
|
||
toArgs.compressWidth = fromArgs.compressedWidth;
|
||
}
|
||
}
|
||
};
|
||
var protocols = /* @__PURE__ */ Object.freeze({
|
||
__proto__: null,
|
||
compressImage,
|
||
getAppAuthorizeSetting,
|
||
getAppBaseInfo,
|
||
getDeviceInfo,
|
||
getSystemInfo,
|
||
getSystemInfoSync,
|
||
getWindowInfo,
|
||
previewImage,
|
||
redirectTo,
|
||
showActionSheet
|
||
});
|
||
const wx$1 = initWx();
|
||
var index = initUni(shims, protocols, wx$1);
|
||
new Set(
|
||
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
||
);
|
||
function toRaw$1(observed) {
|
||
const raw = observed && observed["__v_raw"];
|
||
return raw ? toRaw$1(raw) : observed;
|
||
}
|
||
function isRef$1(r2) {
|
||
return !!(r2 && r2.__v_isRef === true);
|
||
}
|
||
/**
|
||
* @vue/runtime-core v3.4.21
|
||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||
* @license MIT
|
||
**/
|
||
const stack$1 = [];
|
||
function pushWarningContext$1(vnode) {
|
||
stack$1.push(vnode);
|
||
}
|
||
function popWarningContext$1() {
|
||
stack$1.pop();
|
||
}
|
||
function warn$1$1(msg, ...args) {
|
||
const instance = stack$1.length ? stack$1[stack$1.length - 1].component : null;
|
||
const appWarnHandler = instance && instance.appContext.config.warnHandler;
|
||
const trace = getComponentTrace$1();
|
||
if (appWarnHandler) {
|
||
callWithErrorHandling$1(
|
||
appWarnHandler,
|
||
instance,
|
||
11,
|
||
[
|
||
msg + args.map((a) => {
|
||
var _a, _b;
|
||
return (_b = (_a = a.toString) == null ? void 0 : _a.call(a)) != null ? _b : JSON.stringify(a);
|
||
}).join(""),
|
||
instance && instance.proxy,
|
||
trace.map(
|
||
({ vnode }) => `at <${formatComponentName$1(instance, vnode.type)}>`
|
||
).join("\n"),
|
||
trace
|
||
]
|
||
);
|
||
} else {
|
||
const warnArgs = [`[Vue warn]: ${msg}`, ...args];
|
||
if (trace.length && // avoid spamming console during tests
|
||
true) {
|
||
warnArgs.push(`
|
||
`, ...formatTrace$1(trace));
|
||
}
|
||
console.warn(...warnArgs);
|
||
}
|
||
}
|
||
function getComponentTrace$1() {
|
||
let currentVNode = stack$1[stack$1.length - 1];
|
||
if (!currentVNode) {
|
||
return [];
|
||
}
|
||
const normalizedStack = [];
|
||
while (currentVNode) {
|
||
const last = normalizedStack[0];
|
||
if (last && last.vnode === currentVNode) {
|
||
last.recurseCount++;
|
||
} else {
|
||
normalizedStack.push({
|
||
vnode: currentVNode,
|
||
recurseCount: 0
|
||
});
|
||
}
|
||
const parentInstance = currentVNode.component && currentVNode.component.parent;
|
||
currentVNode = parentInstance && parentInstance.vnode;
|
||
}
|
||
return normalizedStack;
|
||
}
|
||
function formatTrace$1(trace) {
|
||
const logs = [];
|
||
trace.forEach((entry, i) => {
|
||
logs.push(...i === 0 ? [] : [`
|
||
`], ...formatTraceEntry$1(entry));
|
||
});
|
||
return logs;
|
||
}
|
||
function formatTraceEntry$1({ vnode, recurseCount }) {
|
||
const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
|
||
const isRoot = vnode.component ? vnode.component.parent == null : false;
|
||
const open = ` at <${formatComponentName$1(
|
||
vnode.component,
|
||
vnode.type,
|
||
isRoot
|
||
)}`;
|
||
const close = `>` + postfix;
|
||
return vnode.props ? [open, ...formatProps$1(vnode.props), close] : [open + close];
|
||
}
|
||
function formatProps$1(props) {
|
||
const res = [];
|
||
const keys = Object.keys(props);
|
||
keys.slice(0, 3).forEach((key) => {
|
||
res.push(...formatProp$1(key, props[key]));
|
||
});
|
||
if (keys.length > 3) {
|
||
res.push(` ...`);
|
||
}
|
||
return res;
|
||
}
|
||
function formatProp$1(key, value, raw) {
|
||
if (isString$1(value)) {
|
||
value = JSON.stringify(value);
|
||
return raw ? value : [`${key}=${value}`];
|
||
} else if (typeof value === "number" || typeof value === "boolean" || value == null) {
|
||
return raw ? value : [`${key}=${value}`];
|
||
} else if (isRef$1(value)) {
|
||
value = formatProp$1(key, toRaw$1(value.value), true);
|
||
return raw ? value : [`${key}=Ref<`, value, `>`];
|
||
} else if (isFunction$1(value)) {
|
||
return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
|
||
} else {
|
||
value = toRaw$1(value);
|
||
return raw ? value : [`${key}=`, value];
|
||
}
|
||
}
|
||
const ErrorTypeStrings$1 = {
|
||
["sp"]: "serverPrefetch hook",
|
||
["bc"]: "beforeCreate hook",
|
||
["c"]: "created hook",
|
||
["bm"]: "beforeMount hook",
|
||
["m"]: "mounted hook",
|
||
["bu"]: "beforeUpdate hook",
|
||
["u"]: "updated",
|
||
["bum"]: "beforeUnmount hook",
|
||
["um"]: "unmounted hook",
|
||
["a"]: "activated hook",
|
||
["da"]: "deactivated hook",
|
||
["ec"]: "errorCaptured hook",
|
||
["rtc"]: "renderTracked hook",
|
||
["rtg"]: "renderTriggered hook",
|
||
[0]: "setup function",
|
||
[1]: "render function",
|
||
[2]: "watcher getter",
|
||
[3]: "watcher callback",
|
||
[4]: "watcher cleanup function",
|
||
[5]: "native event handler",
|
||
[6]: "component event handler",
|
||
[7]: "vnode hook",
|
||
[8]: "directive hook",
|
||
[9]: "transition hook",
|
||
[10]: "app errorHandler",
|
||
[11]: "app warnHandler",
|
||
[12]: "ref function",
|
||
[13]: "async component loader",
|
||
[14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core ."
|
||
};
|
||
function callWithErrorHandling$1(fn, instance, type, args) {
|
||
try {
|
||
return args ? fn(...args) : fn();
|
||
} catch (err) {
|
||
handleError$1(err, instance, type);
|
||
}
|
||
}
|
||
function handleError$1(err, instance, type, throwInDev = true) {
|
||
const contextVNode = instance ? instance.vnode : null;
|
||
if (instance) {
|
||
let cur = instance.parent;
|
||
const exposedInstance = instance.proxy;
|
||
const errorInfo = ErrorTypeStrings$1[type];
|
||
while (cur) {
|
||
const errorCapturedHooks = cur.ec;
|
||
if (errorCapturedHooks) {
|
||
for (let i = 0; i < errorCapturedHooks.length; i++) {
|
||
if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
cur = cur.parent;
|
||
}
|
||
const appErrorHandler = instance.appContext.config.errorHandler;
|
||
if (appErrorHandler) {
|
||
callWithErrorHandling$1(
|
||
appErrorHandler,
|
||
null,
|
||
10,
|
||
[err, exposedInstance, errorInfo]
|
||
);
|
||
return;
|
||
}
|
||
}
|
||
logError$1(err, type, contextVNode, throwInDev);
|
||
}
|
||
function logError$1(err, type, contextVNode, throwInDev = true) {
|
||
{
|
||
const info = ErrorTypeStrings$1[type];
|
||
if (contextVNode) {
|
||
pushWarningContext$1(contextVNode);
|
||
}
|
||
warn$1$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
|
||
if (contextVNode) {
|
||
popWarningContext$1();
|
||
}
|
||
if (throwInDev) {
|
||
throw err;
|
||
} else {
|
||
console.error(err);
|
||
}
|
||
}
|
||
}
|
||
let isFlushing$1 = false;
|
||
let isFlushPending$1 = false;
|
||
const queue$1 = [];
|
||
let flushIndex$1 = 0;
|
||
const pendingPostFlushCbs$1 = [];
|
||
let activePostFlushCbs$1 = null;
|
||
let postFlushIndex$1 = 0;
|
||
const resolvedPromise$1 = /* @__PURE__ */ Promise.resolve();
|
||
const RECURSION_LIMIT$1 = 100;
|
||
function findInsertionIndex$1(id) {
|
||
let start = flushIndex$1 + 1;
|
||
let end = queue$1.length;
|
||
while (start < end) {
|
||
const middle = start + end >>> 1;
|
||
const middleJob = queue$1[middle];
|
||
const middleJobId = getId$1(middleJob);
|
||
if (middleJobId < id || middleJobId === id && middleJob.pre) {
|
||
start = middle + 1;
|
||
} else {
|
||
end = middle;
|
||
}
|
||
}
|
||
return start;
|
||
}
|
||
function queueJob$1(job) {
|
||
if (!queue$1.length || !queue$1.includes(
|
||
job,
|
||
isFlushing$1 && job.allowRecurse ? flushIndex$1 + 1 : flushIndex$1
|
||
)) {
|
||
if (job.id == null) {
|
||
queue$1.push(job);
|
||
} else {
|
||
queue$1.splice(findInsertionIndex$1(job.id), 0, job);
|
||
}
|
||
queueFlush$1();
|
||
}
|
||
}
|
||
function queueFlush$1() {
|
||
if (!isFlushing$1 && !isFlushPending$1) {
|
||
isFlushPending$1 = true;
|
||
resolvedPromise$1.then(flushJobs$1);
|
||
}
|
||
}
|
||
function queuePostFlushCb$1(cb) {
|
||
if (!isArray$1(cb)) {
|
||
if (!activePostFlushCbs$1 || !activePostFlushCbs$1.includes(
|
||
cb,
|
||
cb.allowRecurse ? postFlushIndex$1 + 1 : postFlushIndex$1
|
||
)) {
|
||
pendingPostFlushCbs$1.push(cb);
|
||
}
|
||
} else {
|
||
pendingPostFlushCbs$1.push(...cb);
|
||
}
|
||
queueFlush$1();
|
||
}
|
||
function flushPostFlushCbs$1(seen) {
|
||
if (pendingPostFlushCbs$1.length) {
|
||
const deduped = [...new Set(pendingPostFlushCbs$1)].sort(
|
||
(a, b) => getId$1(a) - getId$1(b)
|
||
);
|
||
pendingPostFlushCbs$1.length = 0;
|
||
if (activePostFlushCbs$1) {
|
||
activePostFlushCbs$1.push(...deduped);
|
||
return;
|
||
}
|
||
activePostFlushCbs$1 = deduped;
|
||
{
|
||
seen = seen || /* @__PURE__ */ new Map();
|
||
}
|
||
for (postFlushIndex$1 = 0; postFlushIndex$1 < activePostFlushCbs$1.length; postFlushIndex$1++) {
|
||
if (checkRecursiveUpdates$1(seen, activePostFlushCbs$1[postFlushIndex$1])) {
|
||
continue;
|
||
}
|
||
activePostFlushCbs$1[postFlushIndex$1]();
|
||
}
|
||
activePostFlushCbs$1 = null;
|
||
postFlushIndex$1 = 0;
|
||
}
|
||
}
|
||
const getId$1 = (job) => job.id == null ? Infinity : job.id;
|
||
const comparator$1 = (a, b) => {
|
||
const diff2 = getId$1(a) - getId$1(b);
|
||
if (diff2 === 0) {
|
||
if (a.pre && !b.pre)
|
||
return -1;
|
||
if (b.pre && !a.pre)
|
||
return 1;
|
||
}
|
||
return diff2;
|
||
};
|
||
function flushJobs$1(seen) {
|
||
isFlushPending$1 = false;
|
||
isFlushing$1 = true;
|
||
{
|
||
seen = seen || /* @__PURE__ */ new Map();
|
||
}
|
||
queue$1.sort(comparator$1);
|
||
const check = (job) => checkRecursiveUpdates$1(seen, job);
|
||
try {
|
||
for (flushIndex$1 = 0; flushIndex$1 < queue$1.length; flushIndex$1++) {
|
||
const job = queue$1[flushIndex$1];
|
||
if (job && job.active !== false) {
|
||
if (check(job)) {
|
||
continue;
|
||
}
|
||
callWithErrorHandling$1(job, null, 14);
|
||
}
|
||
}
|
||
} finally {
|
||
flushIndex$1 = 0;
|
||
queue$1.length = 0;
|
||
flushPostFlushCbs$1(seen);
|
||
isFlushing$1 = false;
|
||
if (queue$1.length || pendingPostFlushCbs$1.length) {
|
||
flushJobs$1(seen);
|
||
}
|
||
}
|
||
}
|
||
function checkRecursiveUpdates$1(seen, fn) {
|
||
if (!seen.has(fn)) {
|
||
seen.set(fn, 1);
|
||
} else {
|
||
const count = seen.get(fn);
|
||
if (count > RECURSION_LIMIT$1) {
|
||
const instance = fn.ownerInstance;
|
||
const componentName = instance && getComponentName$1(instance.type);
|
||
handleError$1(
|
||
`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.`,
|
||
null,
|
||
10
|
||
);
|
||
return true;
|
||
} else {
|
||
seen.set(fn, count + 1);
|
||
}
|
||
}
|
||
}
|
||
const hmrDirtyComponents = /* @__PURE__ */ new Set();
|
||
{
|
||
getGlobalThis().__VUE_HMR_RUNTIME__ = {
|
||
createRecord: tryWrap(createRecord),
|
||
rerender: tryWrap(rerender),
|
||
reload: tryWrap(reload)
|
||
};
|
||
}
|
||
const map = /* @__PURE__ */ new Map();
|
||
function createRecord(id, initialDef) {
|
||
if (map.has(id)) {
|
||
return false;
|
||
}
|
||
map.set(id, {
|
||
initialDef: normalizeClassComponent(initialDef),
|
||
instances: /* @__PURE__ */ new Set()
|
||
});
|
||
return true;
|
||
}
|
||
function normalizeClassComponent(component) {
|
||
return isClassComponent$1(component) ? component.__vccOpts : component;
|
||
}
|
||
function rerender(id, newRender) {
|
||
const record = map.get(id);
|
||
if (!record) {
|
||
return;
|
||
}
|
||
record.initialDef.render = newRender;
|
||
[...record.instances].forEach((instance) => {
|
||
if (newRender) {
|
||
instance.render = newRender;
|
||
normalizeClassComponent(instance.type).render = newRender;
|
||
}
|
||
instance.renderCache = [];
|
||
instance.effect.dirty = true;
|
||
instance.update();
|
||
});
|
||
}
|
||
function reload(id, newComp) {
|
||
const record = map.get(id);
|
||
if (!record)
|
||
return;
|
||
newComp = normalizeClassComponent(newComp);
|
||
updateComponentDef(record.initialDef, newComp);
|
||
const instances = [...record.instances];
|
||
for (const instance of instances) {
|
||
const oldComp = normalizeClassComponent(instance.type);
|
||
if (!hmrDirtyComponents.has(oldComp)) {
|
||
if (oldComp !== record.initialDef) {
|
||
updateComponentDef(oldComp, newComp);
|
||
}
|
||
hmrDirtyComponents.add(oldComp);
|
||
}
|
||
instance.appContext.propsCache.delete(instance.type);
|
||
instance.appContext.emitsCache.delete(instance.type);
|
||
instance.appContext.optionsCache.delete(instance.type);
|
||
if (instance.ceReload) {
|
||
hmrDirtyComponents.add(oldComp);
|
||
instance.ceReload(newComp.styles);
|
||
hmrDirtyComponents.delete(oldComp);
|
||
} else if (instance.parent) {
|
||
instance.parent.effect.dirty = true;
|
||
queueJob$1(instance.parent.update);
|
||
} else if (instance.appContext.reload) {
|
||
instance.appContext.reload();
|
||
} else if (typeof window !== "undefined") {
|
||
window.location.reload();
|
||
} else {
|
||
console.warn(
|
||
"[HMR] Root or manually mounted instance modified. Full reload required."
|
||
);
|
||
}
|
||
}
|
||
queuePostFlushCb$1(() => {
|
||
for (const instance of instances) {
|
||
hmrDirtyComponents.delete(
|
||
normalizeClassComponent(instance.type)
|
||
);
|
||
}
|
||
});
|
||
}
|
||
function updateComponentDef(oldComp, newComp) {
|
||
extend(oldComp, newComp);
|
||
for (const key in oldComp) {
|
||
if (key !== "__file" && !(key in newComp)) {
|
||
delete oldComp[key];
|
||
}
|
||
}
|
||
}
|
||
function tryWrap(fn) {
|
||
return (id, arg) => {
|
||
try {
|
||
return fn(id, arg);
|
||
} catch (e2) {
|
||
console.error(e2);
|
||
console.warn(
|
||
`[HMR] Something went wrong during Vue component hot-reload. Full reload required.`
|
||
);
|
||
}
|
||
};
|
||
}
|
||
{
|
||
const g = getGlobalThis();
|
||
const registerGlobalSetter = (key, setter) => {
|
||
let setters;
|
||
if (!(setters = g[key]))
|
||
setters = g[key] = [];
|
||
setters.push(setter);
|
||
return (v) => {
|
||
if (setters.length > 1)
|
||
setters.forEach((set2) => set2(v));
|
||
else
|
||
setters[0](v);
|
||
};
|
||
};
|
||
registerGlobalSetter(
|
||
`__VUE_INSTANCE_SETTERS__`,
|
||
(v) => v
|
||
);
|
||
registerGlobalSetter(
|
||
`__VUE_SSR_SETTERS__`,
|
||
(v) => v
|
||
);
|
||
}
|
||
const classifyRE$1 = /(?:^|[-_])(\w)/g;
|
||
const classify$1 = (str) => str.replace(classifyRE$1, (c2) => c2.toUpperCase()).replace(/[-_]/g, "");
|
||
function getComponentName$1(Component2, includeInferred = true) {
|
||
return isFunction$1(Component2) ? Component2.displayName || Component2.name : Component2.name || includeInferred && Component2.__name;
|
||
}
|
||
function formatComponentName$1(instance, Component2, isRoot = false) {
|
||
let name2 = getComponentName$1(Component2);
|
||
if (!name2 && Component2.__file) {
|
||
const match = Component2.__file.match(/([^/\\]+)\.\w+$/);
|
||
if (match) {
|
||
name2 = match[1];
|
||
}
|
||
}
|
||
if (!name2 && instance && instance.parent) {
|
||
const inferFromRegistry = (registry) => {
|
||
for (const key in registry) {
|
||
if (registry[key] === Component2) {
|
||
return key;
|
||
}
|
||
}
|
||
};
|
||
name2 = inferFromRegistry(
|
||
instance.components || instance.parent.type.components
|
||
) || inferFromRegistry(instance.appContext.components);
|
||
}
|
||
return name2 ? classify$1(name2) : isRoot ? `App` : `Anonymous`;
|
||
}
|
||
function isClassComponent$1(value) {
|
||
return isFunction$1(value) && "__vccOpts" in value;
|
||
}
|
||
/**
|
||
* @dcloudio/uni-mp-vue v3.4.21
|
||
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
||
* @license MIT
|
||
**/
|
||
function warn$2(msg, ...args) {
|
||
console.warn(`[Vue warn] ${msg}`, ...args);
|
||
}
|
||
let activeEffectScope;
|
||
class EffectScope {
|
||
constructor(detached = false) {
|
||
this.detached = detached;
|
||
this._active = true;
|
||
this.effects = [];
|
||
this.cleanups = [];
|
||
this.parent = activeEffectScope;
|
||
if (!detached && activeEffectScope) {
|
||
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
||
this
|
||
) - 1;
|
||
}
|
||
}
|
||
get active() {
|
||
return this._active;
|
||
}
|
||
run(fn) {
|
||
if (this._active) {
|
||
const currentEffectScope = activeEffectScope;
|
||
try {
|
||
activeEffectScope = this;
|
||
return fn();
|
||
} finally {
|
||
activeEffectScope = currentEffectScope;
|
||
}
|
||
} else {
|
||
warn$2(`cannot run an inactive effect scope.`);
|
||
}
|
||
}
|
||
/**
|
||
* This should only be called on non-detached scopes
|
||
* @internal
|
||
*/
|
||
on() {
|
||
activeEffectScope = this;
|
||
}
|
||
/**
|
||
* This should only be called on non-detached scopes
|
||
* @internal
|
||
*/
|
||
off() {
|
||
activeEffectScope = this.parent;
|
||
}
|
||
stop(fromParent) {
|
||
if (this._active) {
|
||
let i, l;
|
||
for (i = 0, l = this.effects.length; i < l; i++) {
|
||
this.effects[i].stop();
|
||
}
|
||
for (i = 0, l = this.cleanups.length; i < l; i++) {
|
||
this.cleanups[i]();
|
||
}
|
||
if (this.scopes) {
|
||
for (i = 0, l = this.scopes.length; i < l; i++) {
|
||
this.scopes[i].stop(true);
|
||
}
|
||
}
|
||
if (!this.detached && this.parent && !fromParent) {
|
||
const last = this.parent.scopes.pop();
|
||
if (last && last !== this) {
|
||
this.parent.scopes[this.index] = last;
|
||
last.index = this.index;
|
||
}
|
||
}
|
||
this.parent = void 0;
|
||
this._active = false;
|
||
}
|
||
}
|
||
}
|
||
function effectScope(detached) {
|
||
return new EffectScope(detached);
|
||
}
|
||
function recordEffectScope(effect2, scope = activeEffectScope) {
|
||
if (scope && scope.active) {
|
||
scope.effects.push(effect2);
|
||
}
|
||
}
|
||
function getCurrentScope() {
|
||
return activeEffectScope;
|
||
}
|
||
let activeEffect;
|
||
class ReactiveEffect2 {
|
||
constructor(fn, trigger2, scheduler, scope) {
|
||
this.fn = fn;
|
||
this.trigger = trigger2;
|
||
this.scheduler = scheduler;
|
||
this.active = true;
|
||
this.deps = [];
|
||
this._dirtyLevel = 4;
|
||
this._trackId = 0;
|
||
this._runnings = 0;
|
||
this._shouldSchedule = false;
|
||
this._depsLength = 0;
|
||
recordEffectScope(this, scope);
|
||
}
|
||
get dirty() {
|
||
if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
|
||
this._dirtyLevel = 1;
|
||
pauseTracking();
|
||
for (let i = 0; i < this._depsLength; i++) {
|
||
const dep = this.deps[i];
|
||
if (dep.computed) {
|
||
triggerComputed(dep.computed);
|
||
if (this._dirtyLevel >= 4) {
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (this._dirtyLevel === 1) {
|
||
this._dirtyLevel = 0;
|
||
}
|
||
resetTracking();
|
||
}
|
||
return this._dirtyLevel >= 4;
|
||
}
|
||
set dirty(v) {
|
||
this._dirtyLevel = v ? 4 : 0;
|
||
}
|
||
run() {
|
||
this._dirtyLevel = 0;
|
||
if (!this.active) {
|
||
return this.fn();
|
||
}
|
||
let lastShouldTrack = shouldTrack;
|
||
let lastEffect = activeEffect;
|
||
try {
|
||
shouldTrack = true;
|
||
activeEffect = this;
|
||
this._runnings++;
|
||
preCleanupEffect(this);
|
||
return this.fn();
|
||
} finally {
|
||
postCleanupEffect(this);
|
||
this._runnings--;
|
||
activeEffect = lastEffect;
|
||
shouldTrack = lastShouldTrack;
|
||
}
|
||
}
|
||
stop() {
|
||
var _a;
|
||
if (this.active) {
|
||
preCleanupEffect(this);
|
||
postCleanupEffect(this);
|
||
(_a = this.onStop) == null ? void 0 : _a.call(this);
|
||
this.active = false;
|
||
}
|
||
}
|
||
}
|
||
function triggerComputed(computed2) {
|
||
return computed2.value;
|
||
}
|
||
function preCleanupEffect(effect2) {
|
||
effect2._trackId++;
|
||
effect2._depsLength = 0;
|
||
}
|
||
function postCleanupEffect(effect2) {
|
||
if (effect2.deps.length > effect2._depsLength) {
|
||
for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
|
||
cleanupDepEffect(effect2.deps[i], effect2);
|
||
}
|
||
effect2.deps.length = effect2._depsLength;
|
||
}
|
||
}
|
||
function cleanupDepEffect(dep, effect2) {
|
||
const trackId = dep.get(effect2);
|
||
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
||
dep.delete(effect2);
|
||
if (dep.size === 0) {
|
||
dep.cleanup();
|
||
}
|
||
}
|
||
}
|
||
let shouldTrack = true;
|
||
let pauseScheduleStack = 0;
|
||
const trackStack = [];
|
||
function pauseTracking() {
|
||
trackStack.push(shouldTrack);
|
||
shouldTrack = false;
|
||
}
|
||
function resetTracking() {
|
||
const last = trackStack.pop();
|
||
shouldTrack = last === void 0 ? true : last;
|
||
}
|
||
function pauseScheduling() {
|
||
pauseScheduleStack++;
|
||
}
|
||
function resetScheduling() {
|
||
pauseScheduleStack--;
|
||
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
||
queueEffectSchedulers.shift()();
|
||
}
|
||
}
|
||
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
||
var _a;
|
||
if (dep.get(effect2) !== effect2._trackId) {
|
||
dep.set(effect2, effect2._trackId);
|
||
const oldDep = effect2.deps[effect2._depsLength];
|
||
if (oldDep !== dep) {
|
||
if (oldDep) {
|
||
cleanupDepEffect(oldDep, effect2);
|
||
}
|
||
effect2.deps[effect2._depsLength++] = dep;
|
||
} else {
|
||
effect2._depsLength++;
|
||
}
|
||
{
|
||
(_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
||
}
|
||
}
|
||
}
|
||
const queueEffectSchedulers = [];
|
||
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
||
var _a;
|
||
pauseScheduling();
|
||
for (const effect2 of dep.keys()) {
|
||
let tracking;
|
||
if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
||
effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
|
||
effect2._dirtyLevel = dirtyLevel;
|
||
}
|
||
if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
||
{
|
||
(_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
||
}
|
||
effect2.trigger();
|
||
if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
|
||
effect2._shouldSchedule = false;
|
||
if (effect2.scheduler) {
|
||
queueEffectSchedulers.push(effect2.scheduler);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
resetScheduling();
|
||
}
|
||
const createDep = (cleanup, computed2) => {
|
||
const dep = /* @__PURE__ */ new Map();
|
||
dep.cleanup = cleanup;
|
||
dep.computed = computed2;
|
||
return dep;
|
||
};
|
||
const targetMap = /* @__PURE__ */ new WeakMap();
|
||
const ITERATE_KEY = Symbol("iterate");
|
||
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate");
|
||
function track(target, type, key) {
|
||
if (shouldTrack && activeEffect) {
|
||
let depsMap = targetMap.get(target);
|
||
if (!depsMap) {
|
||
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
||
}
|
||
let dep = depsMap.get(key);
|
||
if (!dep) {
|
||
depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
||
}
|
||
trackEffect(
|
||
activeEffect,
|
||
dep,
|
||
{
|
||
target,
|
||
type,
|
||
key
|
||
}
|
||
);
|
||
}
|
||
}
|
||
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
||
const depsMap = targetMap.get(target);
|
||
if (!depsMap) {
|
||
return;
|
||
}
|
||
let deps = [];
|
||
if (type === "clear") {
|
||
deps = [...depsMap.values()];
|
||
} else if (key === "length" && isArray$1(target)) {
|
||
const newLength = Number(newValue);
|
||
depsMap.forEach((dep, key2) => {
|
||
if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
|
||
deps.push(dep);
|
||
}
|
||
});
|
||
} else {
|
||
if (key !== void 0) {
|
||
deps.push(depsMap.get(key));
|
||
}
|
||
switch (type) {
|
||
case "add":
|
||
if (!isArray$1(target)) {
|
||
deps.push(depsMap.get(ITERATE_KEY));
|
||
if (isMap$1(target)) {
|
||
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
||
}
|
||
} else if (isIntegerKey(key)) {
|
||
deps.push(depsMap.get("length"));
|
||
}
|
||
break;
|
||
case "delete":
|
||
if (!isArray$1(target)) {
|
||
deps.push(depsMap.get(ITERATE_KEY));
|
||
if (isMap$1(target)) {
|
||
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
||
}
|
||
}
|
||
break;
|
||
case "set":
|
||
if (isMap$1(target)) {
|
||
deps.push(depsMap.get(ITERATE_KEY));
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
pauseScheduling();
|
||
for (const dep of deps) {
|
||
if (dep) {
|
||
triggerEffects(
|
||
dep,
|
||
4,
|
||
{
|
||
target,
|
||
type,
|
||
key,
|
||
newValue,
|
||
oldValue,
|
||
oldTarget
|
||
}
|
||
);
|
||
}
|
||
}
|
||
resetScheduling();
|
||
}
|
||
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
||
const builtInSymbols = new Set(
|
||
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
||
);
|
||
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
||
function createArrayInstrumentations() {
|
||
const instrumentations = {};
|
||
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
||
instrumentations[key] = function(...args) {
|
||
const arr = toRaw(this);
|
||
for (let i = 0, l = this.length; i < l; i++) {
|
||
track(arr, "get", i + "");
|
||
}
|
||
const res = arr[key](...args);
|
||
if (res === -1 || res === false) {
|
||
return arr[key](...args.map(toRaw));
|
||
} else {
|
||
return res;
|
||
}
|
||
};
|
||
});
|
||
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
||
instrumentations[key] = function(...args) {
|
||
pauseTracking();
|
||
pauseScheduling();
|
||
const res = toRaw(this)[key].apply(this, args);
|
||
resetScheduling();
|
||
resetTracking();
|
||
return res;
|
||
};
|
||
});
|
||
return instrumentations;
|
||
}
|
||
function hasOwnProperty$1(key) {
|
||
const obj = toRaw(this);
|
||
track(obj, "has", key);
|
||
return obj.hasOwnProperty(key);
|
||
}
|
||
class BaseReactiveHandler2 {
|
||
constructor(_isReadonly = false, _isShallow = false) {
|
||
this._isReadonly = _isReadonly;
|
||
this._isShallow = _isShallow;
|
||
}
|
||
get(target, key, receiver) {
|
||
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
||
if (key === "__v_isReactive") {
|
||
return !isReadonly2;
|
||
} else if (key === "__v_isReadonly") {
|
||
return isReadonly2;
|
||
} else if (key === "__v_isShallow") {
|
||
return isShallow2;
|
||
} else if (key === "__v_raw") {
|
||
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
|
||
// this means the reciever is a user proxy of the reactive proxy
|
||
Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
||
return target;
|
||
}
|
||
return;
|
||
}
|
||
const targetIsArray = isArray$1(target);
|
||
if (!isReadonly2) {
|
||
if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
||
return Reflect.get(arrayInstrumentations, key, receiver);
|
||
}
|
||
if (key === "hasOwnProperty") {
|
||
return hasOwnProperty$1;
|
||
}
|
||
}
|
||
const res = Reflect.get(target, key, receiver);
|
||
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
||
return res;
|
||
}
|
||
if (!isReadonly2) {
|
||
track(target, "get", key);
|
||
}
|
||
if (isShallow2) {
|
||
return res;
|
||
}
|
||
if (isRef(res)) {
|
||
return targetIsArray && isIntegerKey(key) ? res : res.value;
|
||
}
|
||
if (isObject$1(res)) {
|
||
return isReadonly2 ? readonly(res) : reactive(res);
|
||
}
|
||
return res;
|
||
}
|
||
}
|
||
class MutableReactiveHandler2 extends BaseReactiveHandler2 {
|
||
constructor(isShallow2 = false) {
|
||
super(false, isShallow2);
|
||
}
|
||
set(target, key, value, receiver) {
|
||
let oldValue = target[key];
|
||
if (!this._isShallow) {
|
||
const isOldValueReadonly = isReadonly(oldValue);
|
||
if (!isShallow(value) && !isReadonly(value)) {
|
||
oldValue = toRaw(oldValue);
|
||
value = toRaw(value);
|
||
}
|
||
if (!isArray$1(target) && isRef(oldValue) && !isRef(value)) {
|
||
if (isOldValueReadonly) {
|
||
return false;
|
||
} else {
|
||
oldValue.value = value;
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
const hadKey = isArray$1(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
|
||
const result = Reflect.set(target, key, value, receiver);
|
||
if (target === toRaw(receiver)) {
|
||
if (!hadKey) {
|
||
trigger(target, "add", key, value);
|
||
} else if (hasChanged(value, oldValue)) {
|
||
trigger(target, "set", key, value, oldValue);
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
deleteProperty(target, key) {
|
||
const hadKey = hasOwn(target, key);
|
||
const oldValue = target[key];
|
||
const result = Reflect.deleteProperty(target, key);
|
||
if (result && hadKey) {
|
||
trigger(target, "delete", key, void 0, oldValue);
|
||
}
|
||
return result;
|
||
}
|
||
has(target, key) {
|
||
const result = Reflect.has(target, key);
|
||
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
||
track(target, "has", key);
|
||
}
|
||
return result;
|
||
}
|
||
ownKeys(target) {
|
||
track(
|
||
target,
|
||
"iterate",
|
||
isArray$1(target) ? "length" : ITERATE_KEY
|
||
);
|
||
return Reflect.ownKeys(target);
|
||
}
|
||
}
|
||
class ReadonlyReactiveHandler2 extends BaseReactiveHandler2 {
|
||
constructor(isShallow2 = false) {
|
||
super(true, isShallow2);
|
||
}
|
||
set(target, key) {
|
||
{
|
||
warn$2(
|
||
`Set operation on key "${String(key)}" failed: target is readonly.`,
|
||
target
|
||
);
|
||
}
|
||
return true;
|
||
}
|
||
deleteProperty(target, key) {
|
||
{
|
||
warn$2(
|
||
`Delete operation on key "${String(key)}" failed: target is readonly.`,
|
||
target
|
||
);
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler2();
|
||
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler2();
|
||
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler2(
|
||
true
|
||
);
|
||
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler2(true);
|
||
const toShallow = (value) => value;
|
||
const getProto = (v) => Reflect.getPrototypeOf(v);
|
||
function get$1(target, key, isReadonly2 = false, isShallow2 = false) {
|
||
target = target["__v_raw"];
|
||
const rawTarget = toRaw(target);
|
||
const rawKey = toRaw(key);
|
||
if (!isReadonly2) {
|
||
if (hasChanged(key, rawKey)) {
|
||
track(rawTarget, "get", key);
|
||
}
|
||
track(rawTarget, "get", rawKey);
|
||
}
|
||
const { has: has2 } = getProto(rawTarget);
|
||
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
||
if (has2.call(rawTarget, key)) {
|
||
return wrap(target.get(key));
|
||
} else if (has2.call(rawTarget, rawKey)) {
|
||
return wrap(target.get(rawKey));
|
||
} else if (target !== rawTarget) {
|
||
target.get(key);
|
||
}
|
||
}
|
||
function has(key, isReadonly2 = false) {
|
||
const target = this["__v_raw"];
|
||
const rawTarget = toRaw(target);
|
||
const rawKey = toRaw(key);
|
||
if (!isReadonly2) {
|
||
if (hasChanged(key, rawKey)) {
|
||
track(rawTarget, "has", key);
|
||
}
|
||
track(rawTarget, "has", rawKey);
|
||
}
|
||
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
||
}
|
||
function size(target, isReadonly2 = false) {
|
||
target = target["__v_raw"];
|
||
!isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
|
||
return Reflect.get(target, "size", target);
|
||
}
|
||
function add$1(value) {
|
||
value = toRaw(value);
|
||
const target = toRaw(this);
|
||
const proto = getProto(target);
|
||
const hadKey = proto.has.call(target, value);
|
||
if (!hadKey) {
|
||
target.add(value);
|
||
trigger(target, "add", value, value);
|
||
}
|
||
return this;
|
||
}
|
||
function set$1(key, value) {
|
||
value = toRaw(value);
|
||
const target = toRaw(this);
|
||
const { has: has2, get: get2 } = getProto(target);
|
||
let hadKey = has2.call(target, key);
|
||
if (!hadKey) {
|
||
key = toRaw(key);
|
||
hadKey = has2.call(target, key);
|
||
} else {
|
||
checkIdentityKeys(target, has2, key);
|
||
}
|
||
const oldValue = get2.call(target, key);
|
||
target.set(key, value);
|
||
if (!hadKey) {
|
||
trigger(target, "add", key, value);
|
||
} else if (hasChanged(value, oldValue)) {
|
||
trigger(target, "set", key, value, oldValue);
|
||
}
|
||
return this;
|
||
}
|
||
function deleteEntry(key) {
|
||
const target = toRaw(this);
|
||
const { has: has2, get: get2 } = getProto(target);
|
||
let hadKey = has2.call(target, key);
|
||
if (!hadKey) {
|
||
key = toRaw(key);
|
||
hadKey = has2.call(target, key);
|
||
} else {
|
||
checkIdentityKeys(target, has2, key);
|
||
}
|
||
const oldValue = get2 ? get2.call(target, key) : void 0;
|
||
const result = target.delete(key);
|
||
if (hadKey) {
|
||
trigger(target, "delete", key, void 0, oldValue);
|
||
}
|
||
return result;
|
||
}
|
||
function clear() {
|
||
const target = toRaw(this);
|
||
const hadItems = target.size !== 0;
|
||
const oldTarget = isMap$1(target) ? new Map(target) : new Set(target);
|
||
const result = target.clear();
|
||
if (hadItems) {
|
||
trigger(target, "clear", void 0, void 0, oldTarget);
|
||
}
|
||
return result;
|
||
}
|
||
function createForEach(isReadonly2, isShallow2) {
|
||
return function forEach(callback, thisArg) {
|
||
const observed = this;
|
||
const target = observed["__v_raw"];
|
||
const rawTarget = toRaw(target);
|
||
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
||
!isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
|
||
return target.forEach((value, key) => {
|
||
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
||
});
|
||
};
|
||
}
|
||
function createIterableMethod(method, isReadonly2, isShallow2) {
|
||
return function(...args) {
|
||
const target = this["__v_raw"];
|
||
const rawTarget = toRaw(target);
|
||
const targetIsMap = isMap$1(rawTarget);
|
||
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
||
const isKeyOnly = method === "keys" && targetIsMap;
|
||
const innerIterator = target[method](...args);
|
||
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
||
!isReadonly2 && track(
|
||
rawTarget,
|
||
"iterate",
|
||
isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
|
||
);
|
||
return {
|
||
// iterator protocol
|
||
next() {
|
||
const { value, done } = innerIterator.next();
|
||
return done ? { value, done } : {
|
||
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
||
done
|
||
};
|
||
},
|
||
// iterable protocol
|
||
[Symbol.iterator]() {
|
||
return this;
|
||
}
|
||
};
|
||
};
|
||
}
|
||
function createReadonlyMethod(type) {
|
||
return function(...args) {
|
||
{
|
||
const key = args[0] ? `on key "${args[0]}" ` : ``;
|
||
warn$2(
|
||
`${capitalize(type)} operation ${key}failed: target is readonly.`,
|
||
toRaw(this)
|
||
);
|
||
}
|
||
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
||
};
|
||
}
|
||
function createInstrumentations() {
|
||
const mutableInstrumentations2 = {
|
||
get(key) {
|
||
return get$1(this, key);
|
||
},
|
||
get size() {
|
||
return size(this);
|
||
},
|
||
has,
|
||
add: add$1,
|
||
set: set$1,
|
||
delete: deleteEntry,
|
||
clear,
|
||
forEach: createForEach(false, false)
|
||
};
|
||
const shallowInstrumentations2 = {
|
||
get(key) {
|
||
return get$1(this, key, false, true);
|
||
},
|
||
get size() {
|
||
return size(this);
|
||
},
|
||
has,
|
||
add: add$1,
|
||
set: set$1,
|
||
delete: deleteEntry,
|
||
clear,
|
||
forEach: createForEach(false, true)
|
||
};
|
||
const readonlyInstrumentations2 = {
|
||
get(key) {
|
||
return get$1(this, key, true);
|
||
},
|
||
get size() {
|
||
return size(this, true);
|
||
},
|
||
has(key) {
|
||
return has.call(this, key, true);
|
||
},
|
||
add: createReadonlyMethod("add"),
|
||
set: createReadonlyMethod("set"),
|
||
delete: createReadonlyMethod("delete"),
|
||
clear: createReadonlyMethod("clear"),
|
||
forEach: createForEach(true, false)
|
||
};
|
||
const shallowReadonlyInstrumentations2 = {
|
||
get(key) {
|
||
return get$1(this, key, true, true);
|
||
},
|
||
get size() {
|
||
return size(this, true);
|
||
},
|
||
has(key) {
|
||
return has.call(this, key, true);
|
||
},
|
||
add: createReadonlyMethod("add"),
|
||
set: createReadonlyMethod("set"),
|
||
delete: createReadonlyMethod("delete"),
|
||
clear: createReadonlyMethod("clear"),
|
||
forEach: createForEach(true, true)
|
||
};
|
||
const iteratorMethods = [
|
||
"keys",
|
||
"values",
|
||
"entries",
|
||
Symbol.iterator
|
||
];
|
||
iteratorMethods.forEach((method) => {
|
||
mutableInstrumentations2[method] = createIterableMethod(method, false, false);
|
||
readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
|
||
shallowInstrumentations2[method] = createIterableMethod(method, false, true);
|
||
shallowReadonlyInstrumentations2[method] = createIterableMethod(
|
||
method,
|
||
true,
|
||
true
|
||
);
|
||
});
|
||
return [
|
||
mutableInstrumentations2,
|
||
readonlyInstrumentations2,
|
||
shallowInstrumentations2,
|
||
shallowReadonlyInstrumentations2
|
||
];
|
||
}
|
||
const [
|
||
mutableInstrumentations,
|
||
readonlyInstrumentations,
|
||
shallowInstrumentations,
|
||
shallowReadonlyInstrumentations
|
||
] = /* @__PURE__ */ createInstrumentations();
|
||
function createInstrumentationGetter(isReadonly2, shallow) {
|
||
const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
|
||
return (target, key, receiver) => {
|
||
if (key === "__v_isReactive") {
|
||
return !isReadonly2;
|
||
} else if (key === "__v_isReadonly") {
|
||
return isReadonly2;
|
||
} else if (key === "__v_raw") {
|
||
return target;
|
||
}
|
||
return Reflect.get(
|
||
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
||
key,
|
||
receiver
|
||
);
|
||
};
|
||
}
|
||
const mutableCollectionHandlers = {
|
||
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
||
};
|
||
const shallowCollectionHandlers = {
|
||
get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
||
};
|
||
const readonlyCollectionHandlers = {
|
||
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
||
};
|
||
const shallowReadonlyCollectionHandlers = {
|
||
get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
||
};
|
||
function checkIdentityKeys(target, has2, key) {
|
||
const rawKey = toRaw(key);
|
||
if (rawKey !== key && has2.call(target, rawKey)) {
|
||
const type = toRawType(target);
|
||
warn$2(
|
||
`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
|
||
);
|
||
}
|
||
}
|
||
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
||
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
||
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
||
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
||
function targetTypeMap(rawType) {
|
||
switch (rawType) {
|
||
case "Object":
|
||
case "Array":
|
||
return 1;
|
||
case "Map":
|
||
case "Set":
|
||
case "WeakMap":
|
||
case "WeakSet":
|
||
return 2;
|
||
default:
|
||
return 0;
|
||
}
|
||
}
|
||
function getTargetType(value) {
|
||
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
||
}
|
||
function reactive(target) {
|
||
if (isReadonly(target)) {
|
||
return target;
|
||
}
|
||
return createReactiveObject(
|
||
target,
|
||
false,
|
||
mutableHandlers,
|
||
mutableCollectionHandlers,
|
||
reactiveMap
|
||
);
|
||
}
|
||
function shallowReactive(target) {
|
||
return createReactiveObject(
|
||
target,
|
||
false,
|
||
shallowReactiveHandlers,
|
||
shallowCollectionHandlers,
|
||
shallowReactiveMap
|
||
);
|
||
}
|
||
function readonly(target) {
|
||
return createReactiveObject(
|
||
target,
|
||
true,
|
||
readonlyHandlers,
|
||
readonlyCollectionHandlers,
|
||
readonlyMap
|
||
);
|
||
}
|
||
function shallowReadonly(target) {
|
||
return createReactiveObject(
|
||
target,
|
||
true,
|
||
shallowReadonlyHandlers,
|
||
shallowReadonlyCollectionHandlers,
|
||
shallowReadonlyMap
|
||
);
|
||
}
|
||
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
||
if (!isObject$1(target)) {
|
||
{
|
||
warn$2(`value cannot be made reactive: ${String(target)}`);
|
||
}
|
||
return target;
|
||
}
|
||
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
||
return target;
|
||
}
|
||
const existingProxy = proxyMap.get(target);
|
||
if (existingProxy) {
|
||
return existingProxy;
|
||
}
|
||
const targetType = getTargetType(target);
|
||
if (targetType === 0) {
|
||
return target;
|
||
}
|
||
const proxy = new Proxy(
|
||
target,
|
||
targetType === 2 ? collectionHandlers : baseHandlers
|
||
);
|
||
proxyMap.set(target, proxy);
|
||
return proxy;
|
||
}
|
||
function isReactive(value) {
|
||
if (isReadonly(value)) {
|
||
return isReactive(value["__v_raw"]);
|
||
}
|
||
return !!(value && value["__v_isReactive"]);
|
||
}
|
||
function isReadonly(value) {
|
||
return !!(value && value["__v_isReadonly"]);
|
||
}
|
||
function isShallow(value) {
|
||
return !!(value && value["__v_isShallow"]);
|
||
}
|
||
function isProxy(value) {
|
||
return isReactive(value) || isReadonly(value);
|
||
}
|
||
function toRaw(observed) {
|
||
const raw = observed && observed["__v_raw"];
|
||
return raw ? toRaw(raw) : observed;
|
||
}
|
||
function markRaw(value) {
|
||
if (Object.isExtensible(value)) {
|
||
def(value, "__v_skip", true);
|
||
}
|
||
return value;
|
||
}
|
||
const toReactive = (value) => isObject$1(value) ? reactive(value) : value;
|
||
const toReadonly = (value) => isObject$1(value) ? readonly(value) : value;
|
||
const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
|
||
class ComputedRefImpl {
|
||
constructor(getter, _setter, isReadonly2, isSSR) {
|
||
this.getter = getter;
|
||
this._setter = _setter;
|
||
this.dep = void 0;
|
||
this.__v_isRef = true;
|
||
this["__v_isReadonly"] = false;
|
||
this.effect = new ReactiveEffect2(
|
||
() => getter(this._value),
|
||
() => triggerRefValue(
|
||
this,
|
||
this.effect._dirtyLevel === 2 ? 2 : 3
|
||
)
|
||
);
|
||
this.effect.computed = this;
|
||
this.effect.active = this._cacheable = !isSSR;
|
||
this["__v_isReadonly"] = isReadonly2;
|
||
}
|
||
get value() {
|
||
const self2 = toRaw(this);
|
||
if ((!self2._cacheable || self2.effect.dirty) && hasChanged(self2._value, self2._value = self2.effect.run())) {
|
||
triggerRefValue(self2, 4);
|
||
}
|
||
trackRefValue(self2);
|
||
if (self2.effect._dirtyLevel >= 2) {
|
||
if (this._warnRecursive) {
|
||
warn$2(COMPUTED_SIDE_EFFECT_WARN, `
|
||
|
||
getter: `, this.getter);
|
||
}
|
||
triggerRefValue(self2, 2);
|
||
}
|
||
return self2._value;
|
||
}
|
||
set value(newValue) {
|
||
this._setter(newValue);
|
||
}
|
||
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
||
get _dirty() {
|
||
return this.effect.dirty;
|
||
}
|
||
set _dirty(v) {
|
||
this.effect.dirty = v;
|
||
}
|
||
// #endregion
|
||
}
|
||
function computed$1(getterOrOptions, debugOptions, isSSR = false) {
|
||
let getter;
|
||
let setter;
|
||
const onlyGetter = isFunction$1(getterOrOptions);
|
||
if (onlyGetter) {
|
||
getter = getterOrOptions;
|
||
setter = () => {
|
||
warn$2("Write operation failed: computed value is readonly");
|
||
};
|
||
} else {
|
||
getter = getterOrOptions.get;
|
||
setter = getterOrOptions.set;
|
||
}
|
||
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
||
if (debugOptions && !isSSR) {
|
||
cRef.effect.onTrack = debugOptions.onTrack;
|
||
cRef.effect.onTrigger = debugOptions.onTrigger;
|
||
}
|
||
return cRef;
|
||
}
|
||
function trackRefValue(ref2) {
|
||
var _a;
|
||
if (shouldTrack && activeEffect) {
|
||
ref2 = toRaw(ref2);
|
||
trackEffect(
|
||
activeEffect,
|
||
(_a = ref2.dep) != null ? _a : ref2.dep = createDep(
|
||
() => ref2.dep = void 0,
|
||
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
||
),
|
||
{
|
||
target: ref2,
|
||
type: "get",
|
||
key: "value"
|
||
}
|
||
);
|
||
}
|
||
}
|
||
function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
|
||
ref2 = toRaw(ref2);
|
||
const dep = ref2.dep;
|
||
if (dep) {
|
||
triggerEffects(
|
||
dep,
|
||
dirtyLevel,
|
||
{
|
||
target: ref2,
|
||
type: "set",
|
||
key: "value",
|
||
newValue: newVal
|
||
}
|
||
);
|
||
}
|
||
}
|
||
function isRef(r2) {
|
||
return !!(r2 && r2.__v_isRef === true);
|
||
}
|
||
function ref(value) {
|
||
return createRef(value, false);
|
||
}
|
||
function createRef(rawValue, shallow) {
|
||
if (isRef(rawValue)) {
|
||
return rawValue;
|
||
}
|
||
return new RefImpl(rawValue, shallow);
|
||
}
|
||
class RefImpl {
|
||
constructor(value, __v_isShallow) {
|
||
this.__v_isShallow = __v_isShallow;
|
||
this.dep = void 0;
|
||
this.__v_isRef = true;
|
||
this._rawValue = __v_isShallow ? value : toRaw(value);
|
||
this._value = __v_isShallow ? value : toReactive(value);
|
||
}
|
||
get value() {
|
||
trackRefValue(this);
|
||
return this._value;
|
||
}
|
||
set value(newVal) {
|
||
const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
|
||
newVal = useDirectValue ? newVal : toRaw(newVal);
|
||
if (hasChanged(newVal, this._rawValue)) {
|
||
this._rawValue = newVal;
|
||
this._value = useDirectValue ? newVal : toReactive(newVal);
|
||
triggerRefValue(this, 4, newVal);
|
||
}
|
||
}
|
||
}
|
||
function unref(ref2) {
|
||
return isRef(ref2) ? ref2.value : ref2;
|
||
}
|
||
const shallowUnwrapHandlers = {
|
||
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
|
||
set: (target, key, value, receiver) => {
|
||
const oldValue = target[key];
|
||
if (isRef(oldValue) && !isRef(value)) {
|
||
oldValue.value = value;
|
||
return true;
|
||
} else {
|
||
return Reflect.set(target, key, value, receiver);
|
||
}
|
||
}
|
||
};
|
||
function proxyRefs(objectWithRefs) {
|
||
return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
||
}
|
||
const stack = [];
|
||
function pushWarningContext(vnode) {
|
||
stack.push(vnode);
|
||
}
|
||
function popWarningContext() {
|
||
stack.pop();
|
||
}
|
||
function warn$1(msg, ...args) {
|
||
pauseTracking();
|
||
const instance = stack.length ? stack[stack.length - 1].component : null;
|
||
const appWarnHandler = instance && instance.appContext.config.warnHandler;
|
||
const trace = getComponentTrace();
|
||
if (appWarnHandler) {
|
||
callWithErrorHandling(
|
||
appWarnHandler,
|
||
instance,
|
||
11,
|
||
[
|
||
msg + args.map((a) => {
|
||
var _a, _b;
|
||
return (_b = (_a = a.toString) == null ? void 0 : _a.call(a)) != null ? _b : JSON.stringify(a);
|
||
}).join(""),
|
||
instance && instance.proxy,
|
||
trace.map(
|
||
({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`
|
||
).join("\n"),
|
||
trace
|
||
]
|
||
);
|
||
} else {
|
||
const warnArgs = [`[Vue warn]: ${msg}`, ...args];
|
||
if (trace.length && // avoid spamming console during tests
|
||
true) {
|
||
warnArgs.push(`
|
||
`, ...formatTrace(trace));
|
||
}
|
||
console.warn(...warnArgs);
|
||
}
|
||
resetTracking();
|
||
}
|
||
function getComponentTrace() {
|
||
let currentVNode = stack[stack.length - 1];
|
||
if (!currentVNode) {
|
||
return [];
|
||
}
|
||
const normalizedStack = [];
|
||
while (currentVNode) {
|
||
const last = normalizedStack[0];
|
||
if (last && last.vnode === currentVNode) {
|
||
last.recurseCount++;
|
||
} else {
|
||
normalizedStack.push({
|
||
vnode: currentVNode,
|
||
recurseCount: 0
|
||
});
|
||
}
|
||
const parentInstance = currentVNode.component && currentVNode.component.parent;
|
||
currentVNode = parentInstance && parentInstance.vnode;
|
||
}
|
||
return normalizedStack;
|
||
}
|
||
function formatTrace(trace) {
|
||
const logs = [];
|
||
trace.forEach((entry, i) => {
|
||
logs.push(...i === 0 ? [] : [`
|
||
`], ...formatTraceEntry(entry));
|
||
});
|
||
return logs;
|
||
}
|
||
function formatTraceEntry({ vnode, recurseCount }) {
|
||
const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
|
||
const isRoot = vnode.component ? vnode.component.parent == null : false;
|
||
const open = ` at <${formatComponentName(
|
||
vnode.component,
|
||
vnode.type,
|
||
isRoot
|
||
)}`;
|
||
const close = `>` + postfix;
|
||
return vnode.props ? [open, ...formatProps(vnode.props), close] : [open + close];
|
||
}
|
||
function formatProps(props) {
|
||
const res = [];
|
||
const keys = Object.keys(props);
|
||
keys.slice(0, 3).forEach((key) => {
|
||
res.push(...formatProp(key, props[key]));
|
||
});
|
||
if (keys.length > 3) {
|
||
res.push(` ...`);
|
||
}
|
||
return res;
|
||
}
|
||
function formatProp(key, value, raw) {
|
||
if (isString$1(value)) {
|
||
value = JSON.stringify(value);
|
||
return raw ? value : [`${key}=${value}`];
|
||
} else if (typeof value === "number" || typeof value === "boolean" || value == null) {
|
||
return raw ? value : [`${key}=${value}`];
|
||
} else if (isRef(value)) {
|
||
value = formatProp(key, toRaw(value.value), true);
|
||
return raw ? value : [`${key}=Ref<`, value, `>`];
|
||
} else if (isFunction$1(value)) {
|
||
return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
|
||
} else {
|
||
value = toRaw(value);
|
||
return raw ? value : [`${key}=`, value];
|
||
}
|
||
}
|
||
const ErrorTypeStrings = {
|
||
["sp"]: "serverPrefetch hook",
|
||
["bc"]: "beforeCreate hook",
|
||
["c"]: "created hook",
|
||
["bm"]: "beforeMount hook",
|
||
["m"]: "mounted hook",
|
||
["bu"]: "beforeUpdate hook",
|
||
["u"]: "updated",
|
||
["bum"]: "beforeUnmount hook",
|
||
["um"]: "unmounted hook",
|
||
["a"]: "activated hook",
|
||
["da"]: "deactivated hook",
|
||
["ec"]: "errorCaptured hook",
|
||
["rtc"]: "renderTracked hook",
|
||
["rtg"]: "renderTriggered hook",
|
||
[0]: "setup function",
|
||
[1]: "render function",
|
||
[2]: "watcher getter",
|
||
[3]: "watcher callback",
|
||
[4]: "watcher cleanup function",
|
||
[5]: "native event handler",
|
||
[6]: "component event handler",
|
||
[7]: "vnode hook",
|
||
[8]: "directive hook",
|
||
[9]: "transition hook",
|
||
[10]: "app errorHandler",
|
||
[11]: "app warnHandler",
|
||
[12]: "ref function",
|
||
[13]: "async component loader",
|
||
[14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core ."
|
||
};
|
||
function callWithErrorHandling(fn, instance, type, args) {
|
||
try {
|
||
return args ? fn(...args) : fn();
|
||
} catch (err) {
|
||
handleError(err, instance, type);
|
||
}
|
||
}
|
||
function callWithAsyncErrorHandling(fn, instance, type, args) {
|
||
if (isFunction$1(fn)) {
|
||
const res = callWithErrorHandling(fn, instance, type, args);
|
||
if (res && isPromise(res)) {
|
||
res.catch((err) => {
|
||
handleError(err, instance, type);
|
||
});
|
||
}
|
||
return res;
|
||
}
|
||
const values = [];
|
||
for (let i = 0; i < fn.length; i++) {
|
||
values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
|
||
}
|
||
return values;
|
||
}
|
||
function handleError(err, instance, type, throwInDev = true) {
|
||
const contextVNode = instance ? instance.vnode : null;
|
||
if (instance) {
|
||
let cur = instance.parent;
|
||
const exposedInstance = instance.proxy;
|
||
const errorInfo = ErrorTypeStrings[type] || type;
|
||
while (cur) {
|
||
const errorCapturedHooks = cur.ec;
|
||
if (errorCapturedHooks) {
|
||
for (let i = 0; i < errorCapturedHooks.length; i++) {
|
||
if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
cur = cur.parent;
|
||
}
|
||
const appErrorHandler = instance.appContext.config.errorHandler;
|
||
if (appErrorHandler) {
|
||
callWithErrorHandling(
|
||
appErrorHandler,
|
||
null,
|
||
10,
|
||
[err, exposedInstance, errorInfo]
|
||
);
|
||
return;
|
||
}
|
||
}
|
||
logError(err, type, contextVNode, throwInDev);
|
||
}
|
||
function logError(err, type, contextVNode, throwInDev = true) {
|
||
{
|
||
const info = ErrorTypeStrings[type] || type;
|
||
if (contextVNode) {
|
||
pushWarningContext(contextVNode);
|
||
}
|
||
warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
|
||
if (contextVNode) {
|
||
popWarningContext();
|
||
}
|
||
if (throwInDev) {
|
||
console.error(err);
|
||
} else {
|
||
console.error(err);
|
||
}
|
||
}
|
||
}
|
||
let isFlushing = false;
|
||
let isFlushPending = false;
|
||
const queue = [];
|
||
let flushIndex = 0;
|
||
const pendingPostFlushCbs = [];
|
||
let activePostFlushCbs = null;
|
||
let postFlushIndex = 0;
|
||
const resolvedPromise = /* @__PURE__ */ Promise.resolve();
|
||
let currentFlushPromise = null;
|
||
const RECURSION_LIMIT = 100;
|
||
function nextTick$1(fn) {
|
||
const p2 = currentFlushPromise || resolvedPromise;
|
||
return fn ? p2.then(this ? fn.bind(this) : fn) : p2;
|
||
}
|
||
function findInsertionIndex(id) {
|
||
let start = flushIndex + 1;
|
||
let end = queue.length;
|
||
while (start < end) {
|
||
const middle = start + end >>> 1;
|
||
const middleJob = queue[middle];
|
||
const middleJobId = getId(middleJob);
|
||
if (middleJobId < id || middleJobId === id && middleJob.pre) {
|
||
start = middle + 1;
|
||
} else {
|
||
end = middle;
|
||
}
|
||
}
|
||
return start;
|
||
}
|
||
function queueJob(job) {
|
||
if (!queue.length || !queue.includes(
|
||
job,
|
||
isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex
|
||
)) {
|
||
if (job.id == null) {
|
||
queue.push(job);
|
||
} else {
|
||
queue.splice(findInsertionIndex(job.id), 0, job);
|
||
}
|
||
queueFlush();
|
||
}
|
||
}
|
||
function queueFlush() {
|
||
if (!isFlushing && !isFlushPending) {
|
||
isFlushPending = true;
|
||
currentFlushPromise = resolvedPromise.then(flushJobs);
|
||
}
|
||
}
|
||
function hasQueueJob(job) {
|
||
return queue.indexOf(job) > -1;
|
||
}
|
||
function invalidateJob(job) {
|
||
const i = queue.indexOf(job);
|
||
if (i > flushIndex) {
|
||
queue.splice(i, 1);
|
||
}
|
||
}
|
||
function queuePostFlushCb(cb) {
|
||
if (!isArray$1(cb)) {
|
||
if (!activePostFlushCbs || !activePostFlushCbs.includes(
|
||
cb,
|
||
cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex
|
||
)) {
|
||
pendingPostFlushCbs.push(cb);
|
||
}
|
||
} else {
|
||
pendingPostFlushCbs.push(...cb);
|
||
}
|
||
queueFlush();
|
||
}
|
||
function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
|
||
{
|
||
seen = seen || /* @__PURE__ */ new Map();
|
||
}
|
||
for (; i < queue.length; i++) {
|
||
const cb = queue[i];
|
||
if (cb && cb.pre) {
|
||
if (instance && cb.id !== instance.uid) {
|
||
continue;
|
||
}
|
||
if (checkRecursiveUpdates(seen, cb)) {
|
||
continue;
|
||
}
|
||
queue.splice(i, 1);
|
||
i--;
|
||
cb();
|
||
}
|
||
}
|
||
}
|
||
function flushPostFlushCbs(seen) {
|
||
if (pendingPostFlushCbs.length) {
|
||
const deduped = [...new Set(pendingPostFlushCbs)].sort(
|
||
(a, b) => getId(a) - getId(b)
|
||
);
|
||
pendingPostFlushCbs.length = 0;
|
||
if (activePostFlushCbs) {
|
||
activePostFlushCbs.push(...deduped);
|
||
return;
|
||
}
|
||
activePostFlushCbs = deduped;
|
||
{
|
||
seen = seen || /* @__PURE__ */ new Map();
|
||
}
|
||
for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
|
||
if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
|
||
continue;
|
||
}
|
||
activePostFlushCbs[postFlushIndex]();
|
||
}
|
||
activePostFlushCbs = null;
|
||
postFlushIndex = 0;
|
||
}
|
||
}
|
||
const getId = (job) => job.id == null ? Infinity : job.id;
|
||
const comparator = (a, b) => {
|
||
const diff2 = getId(a) - getId(b);
|
||
if (diff2 === 0) {
|
||
if (a.pre && !b.pre)
|
||
return -1;
|
||
if (b.pre && !a.pre)
|
||
return 1;
|
||
}
|
||
return diff2;
|
||
};
|
||
function flushJobs(seen) {
|
||
isFlushPending = false;
|
||
isFlushing = true;
|
||
{
|
||
seen = seen || /* @__PURE__ */ new Map();
|
||
}
|
||
queue.sort(comparator);
|
||
const check = (job) => checkRecursiveUpdates(seen, job);
|
||
try {
|
||
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
||
const job = queue[flushIndex];
|
||
if (job && job.active !== false) {
|
||
if (check(job)) {
|
||
continue;
|
||
}
|
||
callWithErrorHandling(job, null, 14);
|
||
}
|
||
}
|
||
} finally {
|
||
flushIndex = 0;
|
||
queue.length = 0;
|
||
flushPostFlushCbs(seen);
|
||
isFlushing = false;
|
||
currentFlushPromise = null;
|
||
if (queue.length || pendingPostFlushCbs.length) {
|
||
flushJobs(seen);
|
||
}
|
||
}
|
||
}
|
||
function checkRecursiveUpdates(seen, fn) {
|
||
if (!seen.has(fn)) {
|
||
seen.set(fn, 1);
|
||
} else {
|
||
const count = seen.get(fn);
|
||
if (count > RECURSION_LIMIT) {
|
||
const instance = fn.ownerInstance;
|
||
const componentName = instance && getComponentName(instance.type);
|
||
handleError(
|
||
`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.`,
|
||
null,
|
||
10
|
||
);
|
||
return true;
|
||
} else {
|
||
seen.set(fn, count + 1);
|
||
}
|
||
}
|
||
}
|
||
let devtools;
|
||
let buffer = [];
|
||
let devtoolsNotInstalled = false;
|
||
function emit$1(event, ...args) {
|
||
if (devtools) {
|
||
devtools.emit(event, ...args);
|
||
} else if (!devtoolsNotInstalled) {
|
||
buffer.push({ event, args });
|
||
}
|
||
}
|
||
function setDevtoolsHook(hook, target) {
|
||
var _a, _b;
|
||
devtools = hook;
|
||
if (devtools) {
|
||
devtools.enabled = true;
|
||
buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
|
||
buffer = [];
|
||
} else if (
|
||
// handle late devtools injection - only do this if we are in an actual
|
||
// browser environment to avoid the timer handle stalling test runner exit
|
||
// (#4815)
|
||
typeof window !== "undefined" && // some envs mock window but not fully
|
||
window.HTMLElement && // also exclude jsdom
|
||
!((_b = (_a = window.navigator) == null ? void 0 : _a.userAgent) == null ? void 0 : _b.includes("jsdom"))
|
||
) {
|
||
const replay = target.__VUE_DEVTOOLS_HOOK_REPLAY__ = target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [];
|
||
replay.push((newHook) => {
|
||
setDevtoolsHook(newHook, target);
|
||
});
|
||
setTimeout(() => {
|
||
if (!devtools) {
|
||
target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
|
||
devtoolsNotInstalled = true;
|
||
buffer = [];
|
||
}
|
||
}, 3e3);
|
||
} else {
|
||
devtoolsNotInstalled = true;
|
||
buffer = [];
|
||
}
|
||
}
|
||
function devtoolsInitApp(app, version2) {
|
||
emit$1("app:init", app, version2, {
|
||
Fragment,
|
||
Text,
|
||
Comment,
|
||
Static
|
||
});
|
||
}
|
||
const devtoolsComponentAdded = /* @__PURE__ */ createDevtoolsComponentHook(
|
||
"component:added"
|
||
/* COMPONENT_ADDED */
|
||
);
|
||
const devtoolsComponentUpdated = /* @__PURE__ */ createDevtoolsComponentHook(
|
||
"component:updated"
|
||
/* COMPONENT_UPDATED */
|
||
);
|
||
const _devtoolsComponentRemoved = /* @__PURE__ */ createDevtoolsComponentHook(
|
||
"component:removed"
|
||
/* COMPONENT_REMOVED */
|
||
);
|
||
const devtoolsComponentRemoved = (component) => {
|
||
if (devtools && typeof devtools.cleanupBuffer === "function" && // remove the component if it wasn't buffered
|
||
!devtools.cleanupBuffer(component)) {
|
||
_devtoolsComponentRemoved(component);
|
||
}
|
||
};
|
||
/*! #__NO_SIDE_EFFECTS__ */
|
||
// @__NO_SIDE_EFFECTS__
|
||
function createDevtoolsComponentHook(hook) {
|
||
return (component) => {
|
||
emit$1(
|
||
hook,
|
||
component.appContext.app,
|
||
component.uid,
|
||
// fixed by xxxxxx
|
||
// 为 0 是 App,无 parent 是 Page 指向 App
|
||
component.uid === 0 ? void 0 : component.parent ? component.parent.uid : 0,
|
||
component
|
||
);
|
||
};
|
||
}
|
||
const devtoolsPerfStart = /* @__PURE__ */ createDevtoolsPerformanceHook(
|
||
"perf:start"
|
||
/* PERFORMANCE_START */
|
||
);
|
||
const devtoolsPerfEnd = /* @__PURE__ */ createDevtoolsPerformanceHook(
|
||
"perf:end"
|
||
/* PERFORMANCE_END */
|
||
);
|
||
function createDevtoolsPerformanceHook(hook) {
|
||
return (component, type, time) => {
|
||
emit$1(hook, component.appContext.app, component.uid, component, type, time);
|
||
};
|
||
}
|
||
function devtoolsComponentEmit(component, event, params) {
|
||
emit$1(
|
||
"component:emit",
|
||
component.appContext.app,
|
||
component,
|
||
event,
|
||
params
|
||
);
|
||
}
|
||
function emit(instance, event, ...rawArgs) {
|
||
if (instance.isUnmounted)
|
||
return;
|
||
const props = instance.vnode.props || EMPTY_OBJ;
|
||
{
|
||
const {
|
||
emitsOptions,
|
||
propsOptions: [propsOptions]
|
||
} = instance;
|
||
if (emitsOptions) {
|
||
if (!(event in emitsOptions) && true) {
|
||
if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
|
||
warn$1(
|
||
`Component emitted event "${event}" but it is neither declared in the emits option nor as an "${toHandlerKey(event)}" prop.`
|
||
);
|
||
}
|
||
} else {
|
||
const validator = emitsOptions[event];
|
||
if (isFunction$1(validator)) {
|
||
const isValid = validator(...rawArgs);
|
||
if (!isValid) {
|
||
warn$1(
|
||
`Invalid event arguments: event validation failed for event "${event}".`
|
||
);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
let args = rawArgs;
|
||
const isModelListener2 = event.startsWith("update:");
|
||
const modelArg = isModelListener2 && event.slice(7);
|
||
if (modelArg && modelArg in props) {
|
||
const modifiersKey = `${modelArg === "modelValue" ? "model" : modelArg}Modifiers`;
|
||
const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
|
||
if (trim) {
|
||
args = rawArgs.map((a) => isString$1(a) ? a.trim() : a);
|
||
}
|
||
if (number) {
|
||
args = rawArgs.map(looseToNumber);
|
||
}
|
||
}
|
||
{
|
||
devtoolsComponentEmit(instance, event, args);
|
||
}
|
||
{
|
||
const lowerCaseEvent = event.toLowerCase();
|
||
if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
|
||
warn$1(
|
||
`Event "${lowerCaseEvent}" is emitted in component ${formatComponentName(
|
||
instance,
|
||
instance.type
|
||
)} but the handler is registered for "${event}". Note that HTML attributes are case-insensitive and you cannot use v-on to listen to camelCase events when using in-DOM templates. You should probably use "${hyphenate(
|
||
event
|
||
)}" instead of "${event}".`
|
||
);
|
||
}
|
||
}
|
||
let handlerName;
|
||
let handler = props[handlerName = toHandlerKey(event)] || // also try camelCase event handler (#2249)
|
||
props[handlerName = toHandlerKey(camelize(event))];
|
||
if (!handler && isModelListener2) {
|
||
handler = props[handlerName = toHandlerKey(hyphenate(event))];
|
||
}
|
||
if (handler) {
|
||
callWithAsyncErrorHandling(
|
||
handler,
|
||
instance,
|
||
6,
|
||
args
|
||
);
|
||
}
|
||
const onceHandler = props[handlerName + `Once`];
|
||
if (onceHandler) {
|
||
if (!instance.emitted) {
|
||
instance.emitted = {};
|
||
} else if (instance.emitted[handlerName]) {
|
||
return;
|
||
}
|
||
instance.emitted[handlerName] = true;
|
||
callWithAsyncErrorHandling(
|
||
onceHandler,
|
||
instance,
|
||
6,
|
||
args
|
||
);
|
||
}
|
||
}
|
||
function normalizeEmitsOptions(comp, appContext, asMixin = false) {
|
||
const cache = appContext.emitsCache;
|
||
const cached = cache.get(comp);
|
||
if (cached !== void 0) {
|
||
return cached;
|
||
}
|
||
const raw = comp.emits;
|
||
let normalized = {};
|
||
let hasExtends = false;
|
||
if (!isFunction$1(comp)) {
|
||
const extendEmits = (raw2) => {
|
||
const normalizedFromExtend = normalizeEmitsOptions(raw2, appContext, true);
|
||
if (normalizedFromExtend) {
|
||
hasExtends = true;
|
||
extend(normalized, normalizedFromExtend);
|
||
}
|
||
};
|
||
if (!asMixin && appContext.mixins.length) {
|
||
appContext.mixins.forEach(extendEmits);
|
||
}
|
||
if (comp.extends) {
|
||
extendEmits(comp.extends);
|
||
}
|
||
if (comp.mixins) {
|
||
comp.mixins.forEach(extendEmits);
|
||
}
|
||
}
|
||
if (!raw && !hasExtends) {
|
||
if (isObject$1(comp)) {
|
||
cache.set(comp, null);
|
||
}
|
||
return null;
|
||
}
|
||
if (isArray$1(raw)) {
|
||
raw.forEach((key) => normalized[key] = null);
|
||
} else {
|
||
extend(normalized, raw);
|
||
}
|
||
if (isObject$1(comp)) {
|
||
cache.set(comp, normalized);
|
||
}
|
||
return normalized;
|
||
}
|
||
function isEmitListener(options, key) {
|
||
if (!options || !isOn(key)) {
|
||
return false;
|
||
}
|
||
key = key.slice(2).replace(/Once$/, "");
|
||
return hasOwn(options, key[0].toLowerCase() + key.slice(1)) || hasOwn(options, hyphenate(key)) || hasOwn(options, key);
|
||
}
|
||
let currentRenderingInstance = null;
|
||
function setCurrentRenderingInstance(instance) {
|
||
const prev = currentRenderingInstance;
|
||
currentRenderingInstance = instance;
|
||
instance && instance.type.__scopeId || null;
|
||
return prev;
|
||
}
|
||
const COMPONENTS = "components";
|
||
function resolveComponent(name2, maybeSelfReference) {
|
||
return resolveAsset(COMPONENTS, name2, true, maybeSelfReference) || name2;
|
||
}
|
||
function resolveAsset(type, name2, warnMissing = true, maybeSelfReference = false) {
|
||
const instance = currentRenderingInstance || currentInstance;
|
||
if (instance) {
|
||
const Component2 = instance.type;
|
||
if (type === COMPONENTS) {
|
||
const selfName = getComponentName(
|
||
Component2,
|
||
false
|
||
);
|
||
if (selfName && (selfName === name2 || selfName === camelize(name2) || selfName === capitalize(camelize(name2)))) {
|
||
return Component2;
|
||
}
|
||
}
|
||
const res = (
|
||
// local registration
|
||
// check instance[type] first which is resolved for options API
|
||
resolve(instance[type] || Component2[type], name2) || // global registration
|
||
resolve(instance.appContext[type], name2)
|
||
);
|
||
if (!res && maybeSelfReference) {
|
||
return Component2;
|
||
}
|
||
if (warnMissing && !res) {
|
||
const extra = type === COMPONENTS ? `
|
||
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.` : ``;
|
||
warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name2}${extra}`);
|
||
}
|
||
return res;
|
||
} else {
|
||
warn$1(
|
||
`resolve${capitalize(type.slice(0, -1))} can only be used in render() or setup().`
|
||
);
|
||
}
|
||
}
|
||
function resolve(registry, name2) {
|
||
return registry && (registry[name2] || registry[camelize(name2)] || registry[capitalize(camelize(name2))]);
|
||
}
|
||
const INITIAL_WATCHER_VALUE = {};
|
||
function watch(source, cb, options) {
|
||
if (!isFunction$1(cb)) {
|
||
warn$1(
|
||
`\`watch(fn, options?)\` signature has been moved to a separate API. Use \`watchEffect(fn, options?)\` instead. \`watch\` now only supports \`watch(source, cb, options?) signature.`
|
||
);
|
||
}
|
||
return doWatch(source, cb, options);
|
||
}
|
||
function doWatch(source, cb, {
|
||
immediate,
|
||
deep,
|
||
flush,
|
||
once: once2,
|
||
onTrack,
|
||
onTrigger
|
||
} = EMPTY_OBJ) {
|
||
if (cb && once2) {
|
||
const _cb = cb;
|
||
cb = (...args) => {
|
||
_cb(...args);
|
||
unwatch();
|
||
};
|
||
}
|
||
if (deep !== void 0 && typeof deep === "number") {
|
||
warn$1(
|
||
`watch() "deep" option with number value will be used as watch depth in future versions. Please use a boolean instead to avoid potential breakage.`
|
||
);
|
||
}
|
||
if (!cb) {
|
||
if (immediate !== void 0) {
|
||
warn$1(
|
||
`watch() "immediate" option is only respected when using the watch(source, callback, options?) signature.`
|
||
);
|
||
}
|
||
if (deep !== void 0) {
|
||
warn$1(
|
||
`watch() "deep" option is only respected when using the watch(source, callback, options?) signature.`
|
||
);
|
||
}
|
||
if (once2 !== void 0) {
|
||
warn$1(
|
||
`watch() "once" option is only respected when using the watch(source, callback, options?) signature.`
|
||
);
|
||
}
|
||
}
|
||
const warnInvalidSource = (s2) => {
|
||
warn$1(
|
||
`Invalid watch source: `,
|
||
s2,
|
||
`A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
|
||
);
|
||
};
|
||
const instance = currentInstance;
|
||
const reactiveGetter = (source2) => deep === true ? source2 : (
|
||
// for deep: false, only traverse root-level properties
|
||
traverse(source2, deep === false ? 1 : void 0)
|
||
);
|
||
let getter;
|
||
let forceTrigger = false;
|
||
let isMultiSource = false;
|
||
if (isRef(source)) {
|
||
getter = () => source.value;
|
||
forceTrigger = isShallow(source);
|
||
} else if (isReactive(source)) {
|
||
getter = () => reactiveGetter(source);
|
||
forceTrigger = true;
|
||
} else if (isArray$1(source)) {
|
||
isMultiSource = true;
|
||
forceTrigger = source.some((s2) => isReactive(s2) || isShallow(s2));
|
||
getter = () => source.map((s2) => {
|
||
if (isRef(s2)) {
|
||
return s2.value;
|
||
} else if (isReactive(s2)) {
|
||
return reactiveGetter(s2);
|
||
} else if (isFunction$1(s2)) {
|
||
return callWithErrorHandling(s2, instance, 2);
|
||
} else {
|
||
warnInvalidSource(s2);
|
||
}
|
||
});
|
||
} else if (isFunction$1(source)) {
|
||
if (cb) {
|
||
getter = () => callWithErrorHandling(source, instance, 2);
|
||
} else {
|
||
getter = () => {
|
||
if (cleanup) {
|
||
cleanup();
|
||
}
|
||
return callWithAsyncErrorHandling(
|
||
source,
|
||
instance,
|
||
3,
|
||
[onCleanup]
|
||
);
|
||
};
|
||
}
|
||
} else {
|
||
getter = NOOP;
|
||
warnInvalidSource(source);
|
||
}
|
||
if (cb && deep) {
|
||
const baseGetter = getter;
|
||
getter = () => traverse(baseGetter());
|
||
}
|
||
let cleanup;
|
||
let onCleanup = (fn) => {
|
||
cleanup = effect2.onStop = () => {
|
||
callWithErrorHandling(fn, instance, 4);
|
||
cleanup = effect2.onStop = void 0;
|
||
};
|
||
};
|
||
let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
||
const job = () => {
|
||
if (!effect2.active || !effect2.dirty) {
|
||
return;
|
||
}
|
||
if (cb) {
|
||
const newValue = effect2.run();
|
||
if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue)) || false) {
|
||
if (cleanup) {
|
||
cleanup();
|
||
}
|
||
callWithAsyncErrorHandling(cb, instance, 3, [
|
||
newValue,
|
||
// pass undefined as the old value when it's changed for the first time
|
||
oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
|
||
onCleanup
|
||
]);
|
||
oldValue = newValue;
|
||
}
|
||
} else {
|
||
effect2.run();
|
||
}
|
||
};
|
||
job.allowRecurse = !!cb;
|
||
let scheduler;
|
||
if (flush === "sync") {
|
||
scheduler = job;
|
||
} else if (flush === "post") {
|
||
scheduler = () => queuePostRenderEffect$1(job, instance && instance.suspense);
|
||
} else {
|
||
job.pre = true;
|
||
if (instance)
|
||
job.id = instance.uid;
|
||
scheduler = () => queueJob(job);
|
||
}
|
||
const effect2 = new ReactiveEffect2(getter, NOOP, scheduler);
|
||
const scope = getCurrentScope();
|
||
const unwatch = () => {
|
||
effect2.stop();
|
||
if (scope) {
|
||
remove(scope.effects, effect2);
|
||
}
|
||
};
|
||
{
|
||
effect2.onTrack = onTrack;
|
||
effect2.onTrigger = onTrigger;
|
||
}
|
||
if (cb) {
|
||
if (immediate) {
|
||
job();
|
||
} else {
|
||
oldValue = effect2.run();
|
||
}
|
||
} else if (flush === "post") {
|
||
queuePostRenderEffect$1(
|
||
effect2.run.bind(effect2),
|
||
instance && instance.suspense
|
||
);
|
||
} else {
|
||
effect2.run();
|
||
}
|
||
return unwatch;
|
||
}
|
||
function instanceWatch(source, value, options) {
|
||
const publicThis = this.proxy;
|
||
const getter = isString$1(source) ? source.includes(".") ? createPathGetter(publicThis, source) : () => publicThis[source] : source.bind(publicThis, publicThis);
|
||
let cb;
|
||
if (isFunction$1(value)) {
|
||
cb = value;
|
||
} else {
|
||
cb = value.handler;
|
||
options = value;
|
||
}
|
||
const reset = setCurrentInstance(this);
|
||
const res = doWatch(getter, cb.bind(publicThis), options);
|
||
reset();
|
||
return res;
|
||
}
|
||
function createPathGetter(ctx, path) {
|
||
const segments = path.split(".");
|
||
return () => {
|
||
let cur = ctx;
|
||
for (let i = 0; i < segments.length && cur; i++) {
|
||
cur = cur[segments[i]];
|
||
}
|
||
return cur;
|
||
};
|
||
}
|
||
function traverse(value, depth, currentDepth = 0, seen) {
|
||
if (!isObject$1(value) || value["__v_skip"]) {
|
||
return value;
|
||
}
|
||
if (depth && depth > 0) {
|
||
if (currentDepth >= depth) {
|
||
return value;
|
||
}
|
||
currentDepth++;
|
||
}
|
||
seen = seen || /* @__PURE__ */ new Set();
|
||
if (seen.has(value)) {
|
||
return value;
|
||
}
|
||
seen.add(value);
|
||
if (isRef(value)) {
|
||
traverse(value.value, depth, currentDepth, seen);
|
||
} else if (isArray$1(value)) {
|
||
for (let i = 0; i < value.length; i++) {
|
||
traverse(value[i], depth, currentDepth, seen);
|
||
}
|
||
} else if (isSet(value) || isMap$1(value)) {
|
||
value.forEach((v) => {
|
||
traverse(v, depth, currentDepth, seen);
|
||
});
|
||
} else if (isPlainObject$1(value)) {
|
||
for (const key in value) {
|
||
traverse(value[key], depth, currentDepth, seen);
|
||
}
|
||
}
|
||
return value;
|
||
}
|
||
function validateDirectiveName(name2) {
|
||
if (isBuiltInDirective(name2)) {
|
||
warn$1("Do not use built-in directive ids as custom directive id: " + name2);
|
||
}
|
||
}
|
||
function createAppContext() {
|
||
return {
|
||
app: null,
|
||
config: {
|
||
isNativeTag: NO,
|
||
performance: false,
|
||
globalProperties: {},
|
||
optionMergeStrategies: {},
|
||
errorHandler: void 0,
|
||
warnHandler: void 0,
|
||
compilerOptions: {}
|
||
},
|
||
mixins: [],
|
||
components: {},
|
||
directives: {},
|
||
provides: /* @__PURE__ */ Object.create(null),
|
||
optionsCache: /* @__PURE__ */ new WeakMap(),
|
||
propsCache: /* @__PURE__ */ new WeakMap(),
|
||
emitsCache: /* @__PURE__ */ new WeakMap()
|
||
};
|
||
}
|
||
let uid$1 = 0;
|
||
function createAppAPI(render, hydrate) {
|
||
return function createApp2(rootComponent, rootProps = null) {
|
||
if (!isFunction$1(rootComponent)) {
|
||
rootComponent = extend({}, rootComponent);
|
||
}
|
||
if (rootProps != null && !isObject$1(rootProps)) {
|
||
warn$1(`root props passed to app.mount() must be an object.`);
|
||
rootProps = null;
|
||
}
|
||
const context = createAppContext();
|
||
const installedPlugins = /* @__PURE__ */ new WeakSet();
|
||
const app = context.app = {
|
||
_uid: uid$1++,
|
||
_component: rootComponent,
|
||
_props: rootProps,
|
||
_container: null,
|
||
_context: context,
|
||
_instance: null,
|
||
version,
|
||
get config() {
|
||
return context.config;
|
||
},
|
||
set config(v) {
|
||
{
|
||
warn$1(
|
||
`app.config cannot be replaced. Modify individual options instead.`
|
||
);
|
||
}
|
||
},
|
||
use(plugin2, ...options) {
|
||
if (installedPlugins.has(plugin2)) {
|
||
warn$1(`Plugin has already been applied to target app.`);
|
||
} else if (plugin2 && isFunction$1(plugin2.install)) {
|
||
installedPlugins.add(plugin2);
|
||
plugin2.install(app, ...options);
|
||
} else if (isFunction$1(plugin2)) {
|
||
installedPlugins.add(plugin2);
|
||
plugin2(app, ...options);
|
||
} else {
|
||
warn$1(
|
||
`A plugin must either be a function or an object with an "install" function.`
|
||
);
|
||
}
|
||
return app;
|
||
},
|
||
mixin(mixin) {
|
||
{
|
||
if (!context.mixins.includes(mixin)) {
|
||
context.mixins.push(mixin);
|
||
} else {
|
||
warn$1(
|
||
"Mixin has already been applied to target app" + (mixin.name ? `: ${mixin.name}` : "")
|
||
);
|
||
}
|
||
}
|
||
return app;
|
||
},
|
||
component(name2, component) {
|
||
{
|
||
validateComponentName(name2, context.config);
|
||
}
|
||
if (!component) {
|
||
return context.components[name2];
|
||
}
|
||
if (context.components[name2]) {
|
||
warn$1(`Component "${name2}" has already been registered in target app.`);
|
||
}
|
||
context.components[name2] = component;
|
||
return app;
|
||
},
|
||
directive(name2, directive) {
|
||
{
|
||
validateDirectiveName(name2);
|
||
}
|
||
if (!directive) {
|
||
return context.directives[name2];
|
||
}
|
||
if (context.directives[name2]) {
|
||
warn$1(`Directive "${name2}" has already been registered in target app.`);
|
||
}
|
||
context.directives[name2] = directive;
|
||
return app;
|
||
},
|
||
// fixed by xxxxxx
|
||
mount() {
|
||
},
|
||
// fixed by xxxxxx
|
||
unmount() {
|
||
},
|
||
provide(key, value) {
|
||
if (key in context.provides) {
|
||
warn$1(
|
||
`App already provides property with key "${String(key)}". It will be overwritten with the new value.`
|
||
);
|
||
}
|
||
context.provides[key] = value;
|
||
return app;
|
||
},
|
||
runWithContext(fn) {
|
||
const lastApp = currentApp;
|
||
currentApp = app;
|
||
try {
|
||
return fn();
|
||
} finally {
|
||
currentApp = lastApp;
|
||
}
|
||
}
|
||
};
|
||
return app;
|
||
};
|
||
}
|
||
let currentApp = null;
|
||
function provide(key, value) {
|
||
if (!currentInstance) {
|
||
{
|
||
warn$1(`provide() can only be used inside setup().`);
|
||
}
|
||
} else {
|
||
let provides = currentInstance.provides;
|
||
const parentProvides = currentInstance.parent && currentInstance.parent.provides;
|
||
if (parentProvides === provides) {
|
||
provides = currentInstance.provides = Object.create(parentProvides);
|
||
}
|
||
provides[key] = value;
|
||
if (currentInstance.type.mpType === "app") {
|
||
currentInstance.appContext.app.provide(key, value);
|
||
}
|
||
}
|
||
}
|
||
function inject(key, defaultValue, treatDefaultAsFactory = false) {
|
||
const instance = currentInstance || currentRenderingInstance;
|
||
if (instance || currentApp) {
|
||
const provides = instance ? instance.parent == null ? instance.vnode.appContext && instance.vnode.appContext.provides : instance.parent.provides : currentApp._context.provides;
|
||
if (provides && key in provides) {
|
||
return provides[key];
|
||
} else if (arguments.length > 1) {
|
||
return treatDefaultAsFactory && isFunction$1(defaultValue) ? defaultValue.call(instance && instance.proxy) : defaultValue;
|
||
} else {
|
||
warn$1(`injection "${String(key)}" not found.`);
|
||
}
|
||
} else {
|
||
warn$1(`inject() can only be used inside setup() or functional components.`);
|
||
}
|
||
}
|
||
/*! #__NO_SIDE_EFFECTS__ */
|
||
// @__NO_SIDE_EFFECTS__
|
||
function defineComponent(options, extraOptions) {
|
||
return isFunction$1(options) ? (
|
||
// #8326: extend call and options.name access are considered side-effects
|
||
// by Rollup, so we have to wrap it in a pure-annotated IIFE.
|
||
/* @__PURE__ */ (() => extend({ name: options.name }, extraOptions, { setup: options }))()
|
||
) : options;
|
||
}
|
||
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
|
||
function onActivated(hook, target) {
|
||
registerKeepAliveHook(hook, "a", target);
|
||
}
|
||
function onDeactivated(hook, target) {
|
||
registerKeepAliveHook(hook, "da", target);
|
||
}
|
||
function registerKeepAliveHook(hook, type, target = currentInstance) {
|
||
const wrappedHook = hook.__wdc || (hook.__wdc = () => {
|
||
let current = target;
|
||
while (current) {
|
||
if (current.isDeactivated) {
|
||
return;
|
||
}
|
||
current = current.parent;
|
||
}
|
||
return hook();
|
||
});
|
||
injectHook(type, wrappedHook, target);
|
||
if (target) {
|
||
let current = target.parent;
|
||
while (current && current.parent) {
|
||
if (isKeepAlive(current.parent.vnode)) {
|
||
injectToKeepAliveRoot(wrappedHook, type, target, current);
|
||
}
|
||
current = current.parent;
|
||
}
|
||
}
|
||
}
|
||
function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
|
||
const injected = injectHook(
|
||
type,
|
||
hook,
|
||
keepAliveRoot,
|
||
true
|
||
/* prepend */
|
||
);
|
||
onUnmounted(() => {
|
||
remove(keepAliveRoot[type], injected);
|
||
}, target);
|
||
}
|
||
function injectHook(type, hook, target = currentInstance, prepend = false) {
|
||
if (target) {
|
||
if (isRootHook(type)) {
|
||
target = target.root;
|
||
}
|
||
const hooks = target[type] || (target[type] = []);
|
||
const wrappedHook = hook.__weh || (hook.__weh = (...args) => {
|
||
if (target.isUnmounted) {
|
||
return;
|
||
}
|
||
pauseTracking();
|
||
const reset = setCurrentInstance(target);
|
||
const res = callWithAsyncErrorHandling(hook, target, type, args);
|
||
reset();
|
||
resetTracking();
|
||
return res;
|
||
});
|
||
if (prepend) {
|
||
hooks.unshift(wrappedHook);
|
||
} else {
|
||
hooks.push(wrappedHook);
|
||
}
|
||
return wrappedHook;
|
||
} else {
|
||
const apiName = toHandlerKey(
|
||
(ErrorTypeStrings[type] || type.replace(/^on/, "")).replace(/ hook$/, "")
|
||
);
|
||
warn$1(
|
||
`${apiName} is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup().`
|
||
);
|
||
}
|
||
}
|
||
const createHook$1 = (lifecycle) => (hook, target = currentInstance) => (
|
||
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
|
||
(!isInSSRComponentSetup || lifecycle === "sp") && injectHook(lifecycle, (...args) => hook(...args), target)
|
||
);
|
||
const onBeforeMount = createHook$1("bm");
|
||
const onMounted = createHook$1("m");
|
||
const onBeforeUpdate = createHook$1("bu");
|
||
const onUpdated = createHook$1("u");
|
||
const onBeforeUnmount = createHook$1("bum");
|
||
const onUnmounted = createHook$1("um");
|
||
const onServerPrefetch = createHook$1("sp");
|
||
const onRenderTriggered = createHook$1(
|
||
"rtg"
|
||
);
|
||
const onRenderTracked = createHook$1(
|
||
"rtc"
|
||
);
|
||
function onErrorCaptured(hook, target = currentInstance) {
|
||
injectHook("ec", hook, target);
|
||
}
|
||
const getPublicInstance = (i) => {
|
||
if (!i)
|
||
return null;
|
||
if (isStatefulComponent(i))
|
||
return getExposeProxy(i) || i.proxy;
|
||
return getPublicInstance(i.parent);
|
||
};
|
||
const publicPropertiesMap = (
|
||
// Move PURE marker to new line to workaround compiler discarding it
|
||
// due to type annotation
|
||
/* @__PURE__ */ extend(/* @__PURE__ */ Object.create(null), {
|
||
$: (i) => i,
|
||
// fixed by xxxxxx vue-i18n 在 dev 模式,访问了 $el,故模拟一个假的
|
||
// $el: i => i.vnode.el,
|
||
$el: (i) => i.__$el || (i.__$el = {}),
|
||
$data: (i) => i.data,
|
||
$props: (i) => shallowReadonly(i.props),
|
||
$attrs: (i) => shallowReadonly(i.attrs),
|
||
$slots: (i) => shallowReadonly(i.slots),
|
||
$refs: (i) => shallowReadonly(i.refs),
|
||
$parent: (i) => getPublicInstance(i.parent),
|
||
$root: (i) => getPublicInstance(i.root),
|
||
$emit: (i) => i.emit,
|
||
$options: (i) => resolveMergedOptions(i),
|
||
$forceUpdate: (i) => i.f || (i.f = () => {
|
||
i.effect.dirty = true;
|
||
queueJob(i.update);
|
||
}),
|
||
// $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy!)),// fixed by xxxxxx
|
||
$watch: (i) => instanceWatch.bind(i)
|
||
})
|
||
);
|
||
const isReservedPrefix = (key) => key === "_" || key === "$";
|
||
const hasSetupBinding = (state, key) => state !== EMPTY_OBJ && !state.__isScriptSetup && hasOwn(state, key);
|
||
const PublicInstanceProxyHandlers = {
|
||
get({ _: instance }, key) {
|
||
const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
|
||
if (key === "__isVue") {
|
||
return true;
|
||
}
|
||
let normalizedProps;
|
||
if (key[0] !== "$") {
|
||
const n2 = accessCache[key];
|
||
if (n2 !== void 0) {
|
||
switch (n2) {
|
||
case 1:
|
||
return setupState[key];
|
||
case 2:
|
||
return data[key];
|
||
case 4:
|
||
return ctx[key];
|
||
case 3:
|
||
return props[key];
|
||
}
|
||
} else if (hasSetupBinding(setupState, key)) {
|
||
accessCache[key] = 1;
|
||
return setupState[key];
|
||
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||
accessCache[key] = 2;
|
||
return data[key];
|
||
} else if (
|
||
// only cache other properties when instance has declared (thus stable)
|
||
// props
|
||
(normalizedProps = instance.propsOptions[0]) && hasOwn(normalizedProps, key)
|
||
) {
|
||
accessCache[key] = 3;
|
||
return props[key];
|
||
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
|
||
accessCache[key] = 4;
|
||
return ctx[key];
|
||
} else if (shouldCacheAccess) {
|
||
accessCache[key] = 0;
|
||
}
|
||
}
|
||
const publicGetter = publicPropertiesMap[key];
|
||
let cssModule, globalProperties;
|
||
if (publicGetter) {
|
||
if (key === "$attrs") {
|
||
track(instance, "get", key);
|
||
} else if (key === "$slots") {
|
||
track(instance, "get", key);
|
||
}
|
||
return publicGetter(instance);
|
||
} else if (
|
||
// css module (injected by vue-loader)
|
||
(cssModule = type.__cssModules) && (cssModule = cssModule[key])
|
||
) {
|
||
return cssModule;
|
||
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
|
||
accessCache[key] = 4;
|
||
return ctx[key];
|
||
} else if (
|
||
// global properties
|
||
globalProperties = appContext.config.globalProperties, hasOwn(globalProperties, key)
|
||
) {
|
||
{
|
||
return globalProperties[key];
|
||
}
|
||
} else if (currentRenderingInstance && (!isString$1(key) || // #1091 avoid internal isRef/isVNode checks on component instance leading
|
||
// to infinite warning loop
|
||
key.indexOf("__v") !== 0)) {
|
||
if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
|
||
warn$1(
|
||
`Property ${JSON.stringify(
|
||
key
|
||
)} must be accessed via $data because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`
|
||
);
|
||
} else if (instance === currentRenderingInstance) {
|
||
warn$1(
|
||
`Property ${JSON.stringify(key)} was accessed during render but is not defined on instance.`
|
||
);
|
||
}
|
||
}
|
||
},
|
||
set({ _: instance }, key, value) {
|
||
const { data, setupState, ctx } = instance;
|
||
if (hasSetupBinding(setupState, key)) {
|
||
setupState[key] = value;
|
||
return true;
|
||
} else if (setupState.__isScriptSetup && hasOwn(setupState, key)) {
|
||
warn$1(`Cannot mutate <script setup> binding "${key}" from Options API.`);
|
||
return false;
|
||
} else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
|
||
data[key] = value;
|
||
return true;
|
||
} else if (hasOwn(instance.props, key)) {
|
||
warn$1(`Attempting to mutate prop "${key}". Props are readonly.`);
|
||
return false;
|
||
}
|
||
if (key[0] === "$" && key.slice(1) in instance) {
|
||
warn$1(
|
||
`Attempting to mutate public property "${key}". Properties starting with $ are reserved and readonly.`
|
||
);
|
||
return false;
|
||
} else {
|
||
if (key in instance.appContext.config.globalProperties) {
|
||
Object.defineProperty(ctx, key, {
|
||
enumerable: true,
|
||
configurable: true,
|
||
value
|
||
});
|
||
} else {
|
||
ctx[key] = value;
|
||
}
|
||
}
|
||
return true;
|
||
},
|
||
has({
|
||
_: { data, setupState, accessCache, ctx, appContext, propsOptions }
|
||
}, key) {
|
||
let normalizedProps;
|
||
return !!accessCache[key] || data !== EMPTY_OBJ && hasOwn(data, key) || hasSetupBinding(setupState, key) || (normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key) || hasOwn(ctx, key) || hasOwn(publicPropertiesMap, key) || hasOwn(appContext.config.globalProperties, key);
|
||
},
|
||
defineProperty(target, key, descriptor) {
|
||
if (descriptor.get != null) {
|
||
target._.accessCache[key] = 0;
|
||
} else if (hasOwn(descriptor, "value")) {
|
||
this.set(target, key, descriptor.value, null);
|
||
}
|
||
return Reflect.defineProperty(target, key, descriptor);
|
||
}
|
||
};
|
||
{
|
||
PublicInstanceProxyHandlers.ownKeys = (target) => {
|
||
warn$1(
|
||
`Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead.`
|
||
);
|
||
return Reflect.ownKeys(target);
|
||
};
|
||
}
|
||
function createDevRenderContext(instance) {
|
||
const target = {};
|
||
Object.defineProperty(target, `_`, {
|
||
configurable: true,
|
||
enumerable: false,
|
||
get: () => instance
|
||
});
|
||
Object.keys(publicPropertiesMap).forEach((key) => {
|
||
Object.defineProperty(target, key, {
|
||
configurable: true,
|
||
enumerable: false,
|
||
get: () => publicPropertiesMap[key](instance),
|
||
// intercepted by the proxy so no need for implementation,
|
||
// but needed to prevent set errors
|
||
set: NOOP
|
||
});
|
||
});
|
||
return target;
|
||
}
|
||
function exposePropsOnRenderContext(instance) {
|
||
const {
|
||
ctx,
|
||
propsOptions: [propsOptions]
|
||
} = instance;
|
||
if (propsOptions) {
|
||
Object.keys(propsOptions).forEach((key) => {
|
||
Object.defineProperty(ctx, key, {
|
||
enumerable: true,
|
||
configurable: true,
|
||
get: () => instance.props[key],
|
||
set: NOOP
|
||
});
|
||
});
|
||
}
|
||
}
|
||
function exposeSetupStateOnRenderContext(instance) {
|
||
const { ctx, setupState } = instance;
|
||
Object.keys(toRaw(setupState)).forEach((key) => {
|
||
if (!setupState.__isScriptSetup) {
|
||
if (isReservedPrefix(key[0])) {
|
||
warn$1(
|
||
`setup() return property ${JSON.stringify(
|
||
key
|
||
)} should not start with "$" or "_" which are reserved prefixes for Vue internals.`
|
||
);
|
||
return;
|
||
}
|
||
Object.defineProperty(ctx, key, {
|
||
enumerable: true,
|
||
configurable: true,
|
||
get: () => setupState[key],
|
||
set: NOOP
|
||
});
|
||
}
|
||
});
|
||
}
|
||
function normalizePropsOrEmits(props) {
|
||
return isArray$1(props) ? props.reduce(
|
||
(normalized, p2) => (normalized[p2] = null, normalized),
|
||
{}
|
||
) : props;
|
||
}
|
||
function createDuplicateChecker() {
|
||
const cache = /* @__PURE__ */ Object.create(null);
|
||
return (type, key) => {
|
||
if (cache[key]) {
|
||
warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
|
||
} else {
|
||
cache[key] = type;
|
||
}
|
||
};
|
||
}
|
||
let shouldCacheAccess = true;
|
||
function applyOptions$1(instance) {
|
||
const options = resolveMergedOptions(instance);
|
||
const publicThis = instance.proxy;
|
||
const ctx = instance.ctx;
|
||
shouldCacheAccess = false;
|
||
if (options.beforeCreate) {
|
||
callHook$1(options.beforeCreate, instance, "bc");
|
||
}
|
||
const {
|
||
// state
|
||
data: dataOptions,
|
||
computed: computedOptions,
|
||
methods,
|
||
watch: watchOptions,
|
||
provide: provideOptions,
|
||
inject: injectOptions,
|
||
// lifecycle
|
||
created,
|
||
beforeMount,
|
||
mounted,
|
||
beforeUpdate,
|
||
updated,
|
||
activated,
|
||
deactivated,
|
||
beforeDestroy,
|
||
beforeUnmount,
|
||
destroyed,
|
||
unmounted,
|
||
render,
|
||
renderTracked,
|
||
renderTriggered,
|
||
errorCaptured,
|
||
serverPrefetch,
|
||
// public API
|
||
expose,
|
||
inheritAttrs,
|
||
// assets
|
||
components,
|
||
directives,
|
||
filters
|
||
} = options;
|
||
const checkDuplicateProperties = createDuplicateChecker();
|
||
{
|
||
const [propsOptions] = instance.propsOptions;
|
||
if (propsOptions) {
|
||
for (const key in propsOptions) {
|
||
checkDuplicateProperties("Props", key);
|
||
}
|
||
}
|
||
}
|
||
if (injectOptions) {
|
||
resolveInjections(injectOptions, ctx, checkDuplicateProperties);
|
||
}
|
||
if (methods) {
|
||
for (const key in methods) {
|
||
const methodHandler = methods[key];
|
||
if (isFunction$1(methodHandler)) {
|
||
{
|
||
Object.defineProperty(ctx, key, {
|
||
value: methodHandler.bind(publicThis),
|
||
configurable: true,
|
||
enumerable: true,
|
||
writable: true
|
||
});
|
||
}
|
||
{
|
||
checkDuplicateProperties("Methods", key);
|
||
}
|
||
} else {
|
||
warn$1(
|
||
`Method "${key}" has type "${typeof methodHandler}" in the component definition. Did you reference the function correctly?`
|
||
);
|
||
}
|
||
}
|
||
}
|
||
if (dataOptions) {
|
||
if (!isFunction$1(dataOptions)) {
|
||
warn$1(
|
||
`The data option must be a function. Plain object usage is no longer supported.`
|
||
);
|
||
}
|
||
const data = dataOptions.call(publicThis, publicThis);
|
||
if (isPromise(data)) {
|
||
warn$1(
|
||
`data() returned a Promise - note data() cannot be async; If you intend to perform data fetching before component renders, use async setup() + <Suspense>.`
|
||
);
|
||
}
|
||
if (!isObject$1(data)) {
|
||
warn$1(`data() should return an object.`);
|
||
} else {
|
||
instance.data = reactive(data);
|
||
{
|
||
for (const key in data) {
|
||
checkDuplicateProperties("Data", key);
|
||
if (!isReservedPrefix(key[0])) {
|
||
Object.defineProperty(ctx, key, {
|
||
configurable: true,
|
||
enumerable: true,
|
||
get: () => data[key],
|
||
set: NOOP
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
shouldCacheAccess = true;
|
||
if (computedOptions) {
|
||
for (const key in computedOptions) {
|
||
const opt = computedOptions[key];
|
||
const get2 = isFunction$1(opt) ? opt.bind(publicThis, publicThis) : isFunction$1(opt.get) ? opt.get.bind(publicThis, publicThis) : NOOP;
|
||
if (get2 === NOOP) {
|
||
warn$1(`Computed property "${key}" has no getter.`);
|
||
}
|
||
const set2 = !isFunction$1(opt) && isFunction$1(opt.set) ? opt.set.bind(publicThis) : () => {
|
||
warn$1(
|
||
`Write operation failed: computed property "${key}" is readonly.`
|
||
);
|
||
};
|
||
const c2 = computed({
|
||
get: get2,
|
||
set: set2
|
||
});
|
||
Object.defineProperty(ctx, key, {
|
||
enumerable: true,
|
||
configurable: true,
|
||
get: () => c2.value,
|
||
set: (v) => c2.value = v
|
||
});
|
||
{
|
||
checkDuplicateProperties("Computed", key);
|
||
}
|
||
}
|
||
}
|
||
if (watchOptions) {
|
||
for (const key in watchOptions) {
|
||
createWatcher(watchOptions[key], ctx, publicThis, key);
|
||
}
|
||
}
|
||
{
|
||
if (provideOptions) {
|
||
const provides = isFunction$1(provideOptions) ? provideOptions.call(publicThis) : provideOptions;
|
||
Reflect.ownKeys(provides).forEach((key) => {
|
||
provide(key, provides[key]);
|
||
});
|
||
}
|
||
}
|
||
{
|
||
if (created) {
|
||
callHook$1(created, instance, "c");
|
||
}
|
||
}
|
||
function registerLifecycleHook(register, hook) {
|
||
if (isArray$1(hook)) {
|
||
hook.forEach((_hook) => register(_hook.bind(publicThis)));
|
||
} else if (hook) {
|
||
register(hook.bind(publicThis));
|
||
}
|
||
}
|
||
registerLifecycleHook(onBeforeMount, beforeMount);
|
||
registerLifecycleHook(onMounted, mounted);
|
||
registerLifecycleHook(onBeforeUpdate, beforeUpdate);
|
||
registerLifecycleHook(onUpdated, updated);
|
||
registerLifecycleHook(onActivated, activated);
|
||
registerLifecycleHook(onDeactivated, deactivated);
|
||
registerLifecycleHook(onErrorCaptured, errorCaptured);
|
||
registerLifecycleHook(onRenderTracked, renderTracked);
|
||
registerLifecycleHook(onRenderTriggered, renderTriggered);
|
||
registerLifecycleHook(onBeforeUnmount, beforeUnmount);
|
||
registerLifecycleHook(onUnmounted, unmounted);
|
||
registerLifecycleHook(onServerPrefetch, serverPrefetch);
|
||
if (isArray$1(expose)) {
|
||
if (expose.length) {
|
||
const exposed = instance.exposed || (instance.exposed = {});
|
||
expose.forEach((key) => {
|
||
Object.defineProperty(exposed, key, {
|
||
get: () => publicThis[key],
|
||
set: (val) => publicThis[key] = val
|
||
});
|
||
});
|
||
} else if (!instance.exposed) {
|
||
instance.exposed = {};
|
||
}
|
||
}
|
||
if (render && instance.render === NOOP) {
|
||
instance.render = render;
|
||
}
|
||
if (inheritAttrs != null) {
|
||
instance.inheritAttrs = inheritAttrs;
|
||
}
|
||
if (components)
|
||
instance.components = components;
|
||
if (directives)
|
||
instance.directives = directives;
|
||
if (instance.ctx.$onApplyOptions) {
|
||
instance.ctx.$onApplyOptions(options, instance, publicThis);
|
||
}
|
||
}
|
||
function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP) {
|
||
if (isArray$1(injectOptions)) {
|
||
injectOptions = normalizeInject(injectOptions);
|
||
}
|
||
for (const key in injectOptions) {
|
||
const opt = injectOptions[key];
|
||
let injected;
|
||
if (isObject$1(opt)) {
|
||
if ("default" in opt) {
|
||
injected = inject(
|
||
opt.from || key,
|
||
opt.default,
|
||
true
|
||
);
|
||
} else {
|
||
injected = inject(opt.from || key);
|
||
}
|
||
} else {
|
||
injected = inject(opt);
|
||
}
|
||
if (isRef(injected)) {
|
||
Object.defineProperty(ctx, key, {
|
||
enumerable: true,
|
||
configurable: true,
|
||
get: () => injected.value,
|
||
set: (v) => injected.value = v
|
||
});
|
||
} else {
|
||
ctx[key] = injected;
|
||
}
|
||
{
|
||
checkDuplicateProperties("Inject", key);
|
||
}
|
||
}
|
||
}
|
||
function callHook$1(hook, instance, type) {
|
||
callWithAsyncErrorHandling(
|
||
isArray$1(hook) ? hook.map((h2) => h2.bind(instance.proxy)) : hook.bind(instance.proxy),
|
||
instance,
|
||
type
|
||
);
|
||
}
|
||
function createWatcher(raw, ctx, publicThis, key) {
|
||
const getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
|
||
if (isString$1(raw)) {
|
||
const handler = ctx[raw];
|
||
if (isFunction$1(handler)) {
|
||
watch(getter, handler);
|
||
} else {
|
||
warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
|
||
}
|
||
} else if (isFunction$1(raw)) {
|
||
watch(getter, raw.bind(publicThis));
|
||
} else if (isObject$1(raw)) {
|
||
if (isArray$1(raw)) {
|
||
raw.forEach((r2) => createWatcher(r2, ctx, publicThis, key));
|
||
} else {
|
||
const handler = isFunction$1(raw.handler) ? raw.handler.bind(publicThis) : ctx[raw.handler];
|
||
if (isFunction$1(handler)) {
|
||
watch(getter, handler, raw);
|
||
} else {
|
||
warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
|
||
}
|
||
}
|
||
} else {
|
||
warn$1(`Invalid watch option: "${key}"`, raw);
|
||
}
|
||
}
|
||
function resolveMergedOptions(instance) {
|
||
const base = instance.type;
|
||
const { mixins, extends: extendsOptions } = base;
|
||
const {
|
||
mixins: globalMixins,
|
||
optionsCache: cache,
|
||
config: { optionMergeStrategies }
|
||
} = instance.appContext;
|
||
const cached = cache.get(base);
|
||
let resolved;
|
||
if (cached) {
|
||
resolved = cached;
|
||
} else if (!globalMixins.length && !mixins && !extendsOptions) {
|
||
{
|
||
resolved = base;
|
||
}
|
||
} else {
|
||
resolved = {};
|
||
if (globalMixins.length) {
|
||
globalMixins.forEach(
|
||
(m2) => mergeOptions(resolved, m2, optionMergeStrategies, true)
|
||
);
|
||
}
|
||
mergeOptions(resolved, base, optionMergeStrategies);
|
||
}
|
||
if (isObject$1(base)) {
|
||
cache.set(base, resolved);
|
||
}
|
||
return resolved;
|
||
}
|
||
function mergeOptions(to, from, strats, asMixin = false) {
|
||
const { mixins, extends: extendsOptions } = from;
|
||
if (extendsOptions) {
|
||
mergeOptions(to, extendsOptions, strats, true);
|
||
}
|
||
if (mixins) {
|
||
mixins.forEach(
|
||
(m2) => mergeOptions(to, m2, strats, true)
|
||
);
|
||
}
|
||
for (const key in from) {
|
||
if (asMixin && key === "expose") {
|
||
warn$1(
|
||
`"expose" option is ignored when declared in mixins or extends. It should only be declared in the base component itself.`
|
||
);
|
||
} else {
|
||
const strat = internalOptionMergeStrats[key] || strats && strats[key];
|
||
to[key] = strat ? strat(to[key], from[key]) : from[key];
|
||
}
|
||
}
|
||
return to;
|
||
}
|
||
const internalOptionMergeStrats = {
|
||
data: mergeDataFn,
|
||
props: mergeEmitsOrPropsOptions,
|
||
emits: mergeEmitsOrPropsOptions,
|
||
// objects
|
||
methods: mergeObjectOptions,
|
||
computed: mergeObjectOptions,
|
||
// lifecycle
|
||
beforeCreate: mergeAsArray$1,
|
||
created: mergeAsArray$1,
|
||
beforeMount: mergeAsArray$1,
|
||
mounted: mergeAsArray$1,
|
||
beforeUpdate: mergeAsArray$1,
|
||
updated: mergeAsArray$1,
|
||
beforeDestroy: mergeAsArray$1,
|
||
beforeUnmount: mergeAsArray$1,
|
||
destroyed: mergeAsArray$1,
|
||
unmounted: mergeAsArray$1,
|
||
activated: mergeAsArray$1,
|
||
deactivated: mergeAsArray$1,
|
||
errorCaptured: mergeAsArray$1,
|
||
serverPrefetch: mergeAsArray$1,
|
||
// assets
|
||
components: mergeObjectOptions,
|
||
directives: mergeObjectOptions,
|
||
// watch
|
||
watch: mergeWatchOptions,
|
||
// provide / inject
|
||
provide: mergeDataFn,
|
||
inject: mergeInject
|
||
};
|
||
function mergeDataFn(to, from) {
|
||
if (!from) {
|
||
return to;
|
||
}
|
||
if (!to) {
|
||
return from;
|
||
}
|
||
return function mergedDataFn() {
|
||
return extend(
|
||
isFunction$1(to) ? to.call(this, this) : to,
|
||
isFunction$1(from) ? from.call(this, this) : from
|
||
);
|
||
};
|
||
}
|
||
function mergeInject(to, from) {
|
||
return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
|
||
}
|
||
function normalizeInject(raw) {
|
||
if (isArray$1(raw)) {
|
||
const res = {};
|
||
for (let i = 0; i < raw.length; i++) {
|
||
res[raw[i]] = raw[i];
|
||
}
|
||
return res;
|
||
}
|
||
return raw;
|
||
}
|
||
function mergeAsArray$1(to, from) {
|
||
return to ? [...new Set([].concat(to, from))] : from;
|
||
}
|
||
function mergeObjectOptions(to, from) {
|
||
return to ? extend(/* @__PURE__ */ Object.create(null), to, from) : from;
|
||
}
|
||
function mergeEmitsOrPropsOptions(to, from) {
|
||
if (to) {
|
||
if (isArray$1(to) && isArray$1(from)) {
|
||
return [.../* @__PURE__ */ new Set([...to, ...from])];
|
||
}
|
||
return extend(
|
||
/* @__PURE__ */ Object.create(null),
|
||
normalizePropsOrEmits(to),
|
||
normalizePropsOrEmits(from != null ? from : {})
|
||
);
|
||
} else {
|
||
return from;
|
||
}
|
||
}
|
||
function mergeWatchOptions(to, from) {
|
||
if (!to)
|
||
return from;
|
||
if (!from)
|
||
return to;
|
||
const merged = extend(/* @__PURE__ */ Object.create(null), to);
|
||
for (const key in from) {
|
||
merged[key] = mergeAsArray$1(to[key], from[key]);
|
||
}
|
||
return merged;
|
||
}
|
||
function initProps$1(instance, rawProps, isStateful, isSSR = false) {
|
||
const props = {};
|
||
const attrs = {};
|
||
instance.propsDefaults = /* @__PURE__ */ Object.create(null);
|
||
setFullProps(instance, rawProps, props, attrs);
|
||
for (const key in instance.propsOptions[0]) {
|
||
if (!(key in props)) {
|
||
props[key] = void 0;
|
||
}
|
||
}
|
||
{
|
||
validateProps(rawProps || {}, props, instance);
|
||
}
|
||
if (isStateful) {
|
||
instance.props = isSSR ? props : shallowReactive(props);
|
||
} else {
|
||
if (!instance.type.props) {
|
||
instance.props = attrs;
|
||
} else {
|
||
instance.props = props;
|
||
}
|
||
}
|
||
instance.attrs = attrs;
|
||
}
|
||
function isInHmrContext(instance) {
|
||
while (instance) {
|
||
if (instance.type.__hmrId)
|
||
return true;
|
||
instance = instance.parent;
|
||
}
|
||
}
|
||
function updateProps(instance, rawProps, rawPrevProps, optimized) {
|
||
const {
|
||
props,
|
||
attrs,
|
||
vnode: { patchFlag }
|
||
} = instance;
|
||
const rawCurrentProps = toRaw(props);
|
||
const [options] = instance.propsOptions;
|
||
let hasAttrsChanged = false;
|
||
if (
|
||
// always force full diff in dev
|
||
// - #1942 if hmr is enabled with sfc component
|
||
// - vite#872 non-sfc component used by sfc component
|
||
!isInHmrContext(instance) && (optimized || patchFlag > 0) && !(patchFlag & 16)
|
||
) {
|
||
if (patchFlag & 8) {
|
||
const propsToUpdate = instance.vnode.dynamicProps;
|
||
for (let i = 0; i < propsToUpdate.length; i++) {
|
||
let key = propsToUpdate[i];
|
||
if (isEmitListener(instance.emitsOptions, key)) {
|
||
continue;
|
||
}
|
||
const value = rawProps[key];
|
||
if (options) {
|
||
if (hasOwn(attrs, key)) {
|
||
if (value !== attrs[key]) {
|
||
attrs[key] = value;
|
||
hasAttrsChanged = true;
|
||
}
|
||
} else {
|
||
const camelizedKey = camelize(key);
|
||
props[camelizedKey] = resolvePropValue(
|
||
options,
|
||
rawCurrentProps,
|
||
camelizedKey,
|
||
value,
|
||
instance,
|
||
false
|
||
);
|
||
}
|
||
} else {
|
||
if (value !== attrs[key]) {
|
||
attrs[key] = value;
|
||
hasAttrsChanged = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
if (setFullProps(instance, rawProps, props, attrs)) {
|
||
hasAttrsChanged = true;
|
||
}
|
||
let kebabKey;
|
||
for (const key in rawCurrentProps) {
|
||
if (!rawProps || // for camelCase
|
||
!hasOwn(rawProps, key) && // it's possible the original props was passed in as kebab-case
|
||
// and converted to camelCase (#955)
|
||
((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey))) {
|
||
if (options) {
|
||
if (rawPrevProps && // for camelCase
|
||
(rawPrevProps[key] !== void 0 || // for kebab-case
|
||
rawPrevProps[kebabKey] !== void 0)) {
|
||
props[key] = resolvePropValue(
|
||
options,
|
||
rawCurrentProps,
|
||
key,
|
||
void 0,
|
||
instance,
|
||
true
|
||
);
|
||
}
|
||
} else {
|
||
delete props[key];
|
||
}
|
||
}
|
||
}
|
||
if (attrs !== rawCurrentProps) {
|
||
for (const key in attrs) {
|
||
if (!rawProps || !hasOwn(rawProps, key) && true) {
|
||
delete attrs[key];
|
||
hasAttrsChanged = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (hasAttrsChanged) {
|
||
trigger(instance, "set", "$attrs");
|
||
}
|
||
{
|
||
validateProps(rawProps || {}, props, instance);
|
||
}
|
||
}
|
||
function setFullProps(instance, rawProps, props, attrs) {
|
||
const [options, needCastKeys] = instance.propsOptions;
|
||
let hasAttrsChanged = false;
|
||
let rawCastValues;
|
||
if (rawProps) {
|
||
for (let key in rawProps) {
|
||
if (isReservedProp(key)) {
|
||
continue;
|
||
}
|
||
const value = rawProps[key];
|
||
let camelKey;
|
||
if (options && hasOwn(options, camelKey = camelize(key))) {
|
||
if (!needCastKeys || !needCastKeys.includes(camelKey)) {
|
||
props[camelKey] = value;
|
||
} else {
|
||
(rawCastValues || (rawCastValues = {}))[camelKey] = value;
|
||
}
|
||
} else if (!isEmitListener(instance.emitsOptions, key)) {
|
||
if (!(key in attrs) || value !== attrs[key]) {
|
||
attrs[key] = value;
|
||
hasAttrsChanged = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (needCastKeys) {
|
||
const rawCurrentProps = toRaw(props);
|
||
const castValues = rawCastValues || EMPTY_OBJ;
|
||
for (let i = 0; i < needCastKeys.length; i++) {
|
||
const key = needCastKeys[i];
|
||
props[key] = resolvePropValue(
|
||
options,
|
||
rawCurrentProps,
|
||
key,
|
||
castValues[key],
|
||
instance,
|
||
!hasOwn(castValues, key)
|
||
);
|
||
}
|
||
}
|
||
return hasAttrsChanged;
|
||
}
|
||
function resolvePropValue(options, props, key, value, instance, isAbsent) {
|
||
const opt = options[key];
|
||
if (opt != null) {
|
||
const hasDefault = hasOwn(opt, "default");
|
||
if (hasDefault && value === void 0) {
|
||
const defaultValue = opt.default;
|
||
if (opt.type !== Function && !opt.skipFactory && isFunction$1(defaultValue)) {
|
||
const { propsDefaults } = instance;
|
||
if (key in propsDefaults) {
|
||
value = propsDefaults[key];
|
||
} else {
|
||
const reset = setCurrentInstance(instance);
|
||
value = propsDefaults[key] = defaultValue.call(
|
||
null,
|
||
props
|
||
);
|
||
reset();
|
||
}
|
||
} else {
|
||
value = defaultValue;
|
||
}
|
||
}
|
||
if (opt[
|
||
0
|
||
/* shouldCast */
|
||
]) {
|
||
if (isAbsent && !hasDefault) {
|
||
value = false;
|
||
} else if (opt[
|
||
1
|
||
/* shouldCastTrue */
|
||
] && (value === "" || value === hyphenate(key))) {
|
||
value = true;
|
||
}
|
||
}
|
||
}
|
||
return value;
|
||
}
|
||
function normalizePropsOptions(comp, appContext, asMixin = false) {
|
||
const cache = appContext.propsCache;
|
||
const cached = cache.get(comp);
|
||
if (cached) {
|
||
return cached;
|
||
}
|
||
const raw = comp.props;
|
||
const normalized = {};
|
||
const needCastKeys = [];
|
||
let hasExtends = false;
|
||
if (!isFunction$1(comp)) {
|
||
const extendProps = (raw2) => {
|
||
hasExtends = true;
|
||
const [props, keys] = normalizePropsOptions(raw2, appContext, true);
|
||
extend(normalized, props);
|
||
if (keys)
|
||
needCastKeys.push(...keys);
|
||
};
|
||
if (!asMixin && appContext.mixins.length) {
|
||
appContext.mixins.forEach(extendProps);
|
||
}
|
||
if (comp.extends) {
|
||
extendProps(comp.extends);
|
||
}
|
||
if (comp.mixins) {
|
||
comp.mixins.forEach(extendProps);
|
||
}
|
||
}
|
||
if (!raw && !hasExtends) {
|
||
if (isObject$1(comp)) {
|
||
cache.set(comp, EMPTY_ARR);
|
||
}
|
||
return EMPTY_ARR;
|
||
}
|
||
if (isArray$1(raw)) {
|
||
for (let i = 0; i < raw.length; i++) {
|
||
if (!isString$1(raw[i])) {
|
||
warn$1(`props must be strings when using array syntax.`, raw[i]);
|
||
}
|
||
const normalizedKey = camelize(raw[i]);
|
||
if (validatePropName(normalizedKey)) {
|
||
normalized[normalizedKey] = EMPTY_OBJ;
|
||
}
|
||
}
|
||
} else if (raw) {
|
||
if (!isObject$1(raw)) {
|
||
warn$1(`invalid props options`, raw);
|
||
}
|
||
for (const key in raw) {
|
||
const normalizedKey = camelize(key);
|
||
if (validatePropName(normalizedKey)) {
|
||
const opt = raw[key];
|
||
const prop = normalized[normalizedKey] = isArray$1(opt) || isFunction$1(opt) ? { type: opt } : extend({}, opt);
|
||
if (prop) {
|
||
const booleanIndex = getTypeIndex(Boolean, prop.type);
|
||
const stringIndex = getTypeIndex(String, prop.type);
|
||
prop[
|
||
0
|
||
/* shouldCast */
|
||
] = booleanIndex > -1;
|
||
prop[
|
||
1
|
||
/* shouldCastTrue */
|
||
] = stringIndex < 0 || booleanIndex < stringIndex;
|
||
if (booleanIndex > -1 || hasOwn(prop, "default")) {
|
||
needCastKeys.push(normalizedKey);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
const res = [normalized, needCastKeys];
|
||
if (isObject$1(comp)) {
|
||
cache.set(comp, res);
|
||
}
|
||
return res;
|
||
}
|
||
function validatePropName(key) {
|
||
if (key[0] !== "$" && !isReservedProp(key)) {
|
||
return true;
|
||
} else {
|
||
warn$1(`Invalid prop name: "${key}" is a reserved property.`);
|
||
}
|
||
return false;
|
||
}
|
||
function getType(ctor) {
|
||
if (ctor === null) {
|
||
return "null";
|
||
}
|
||
if (typeof ctor === "function") {
|
||
return ctor.name || "";
|
||
} else if (typeof ctor === "object") {
|
||
const name2 = ctor.constructor && ctor.constructor.name;
|
||
return name2 || "";
|
||
}
|
||
return "";
|
||
}
|
||
function isSameType(a, b) {
|
||
return getType(a) === getType(b);
|
||
}
|
||
function getTypeIndex(type, expectedTypes) {
|
||
if (isArray$1(expectedTypes)) {
|
||
return expectedTypes.findIndex((t2) => isSameType(t2, type));
|
||
} else if (isFunction$1(expectedTypes)) {
|
||
return isSameType(expectedTypes, type) ? 0 : -1;
|
||
}
|
||
return -1;
|
||
}
|
||
function validateProps(rawProps, props, instance) {
|
||
const resolvedValues = toRaw(props);
|
||
const options = instance.propsOptions[0];
|
||
for (const key in options) {
|
||
let opt = options[key];
|
||
if (opt == null)
|
||
continue;
|
||
validateProp(
|
||
key,
|
||
resolvedValues[key],
|
||
opt,
|
||
shallowReadonly(resolvedValues),
|
||
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key))
|
||
);
|
||
}
|
||
}
|
||
function validateProp(name2, value, prop, props, isAbsent) {
|
||
const { type, required, validator, skipCheck } = prop;
|
||
if (required && isAbsent) {
|
||
warn$1('Missing required prop: "' + name2 + '"');
|
||
return;
|
||
}
|
||
if (value == null && !required) {
|
||
return;
|
||
}
|
||
if (type != null && type !== true && !skipCheck) {
|
||
let isValid = false;
|
||
const types = isArray$1(type) ? type : [type];
|
||
const expectedTypes = [];
|
||
for (let i = 0; i < types.length && !isValid; i++) {
|
||
const { valid, expectedType } = assertType(value, types[i]);
|
||
expectedTypes.push(expectedType || "");
|
||
isValid = valid;
|
||
}
|
||
if (!isValid) {
|
||
warn$1(getInvalidTypeMessage(name2, value, expectedTypes));
|
||
return;
|
||
}
|
||
}
|
||
if (validator && !validator(value, props)) {
|
||
warn$1('Invalid prop: custom validator check failed for prop "' + name2 + '".');
|
||
}
|
||
}
|
||
const isSimpleType = /* @__PURE__ */ makeMap(
|
||
"String,Number,Boolean,Function,Symbol,BigInt"
|
||
);
|
||
function assertType(value, type) {
|
||
let valid;
|
||
const expectedType = getType(type);
|
||
if (isSimpleType(expectedType)) {
|
||
const t2 = typeof value;
|
||
valid = t2 === expectedType.toLowerCase();
|
||
if (!valid && t2 === "object") {
|
||
valid = value instanceof type;
|
||
}
|
||
} else if (expectedType === "Object") {
|
||
valid = isObject$1(value);
|
||
} else if (expectedType === "Array") {
|
||
valid = isArray$1(value);
|
||
} else if (expectedType === "null") {
|
||
valid = value === null;
|
||
} else {
|
||
valid = value instanceof type;
|
||
}
|
||
return {
|
||
valid,
|
||
expectedType
|
||
};
|
||
}
|
||
function getInvalidTypeMessage(name2, value, expectedTypes) {
|
||
if (expectedTypes.length === 0) {
|
||
return `Prop type [] for prop "${name2}" won't match anything. Did you mean to use type Array instead?`;
|
||
}
|
||
let message = `Invalid prop: type check failed for prop "${name2}". Expected ${expectedTypes.map(capitalize).join(" | ")}`;
|
||
const expectedType = expectedTypes[0];
|
||
const receivedType = toRawType(value);
|
||
const expectedValue = styleValue(value, expectedType);
|
||
const receivedValue = styleValue(value, receivedType);
|
||
if (expectedTypes.length === 1 && isExplicable(expectedType) && !isBoolean$1(expectedType, receivedType)) {
|
||
message += ` with value ${expectedValue}`;
|
||
}
|
||
message += `, got ${receivedType} `;
|
||
if (isExplicable(receivedType)) {
|
||
message += `with value ${receivedValue}.`;
|
||
}
|
||
return message;
|
||
}
|
||
function styleValue(value, type) {
|
||
if (type === "String") {
|
||
return `"${value}"`;
|
||
} else if (type === "Number") {
|
||
return `${Number(value)}`;
|
||
} else {
|
||
return `${value}`;
|
||
}
|
||
}
|
||
function isExplicable(type) {
|
||
const explicitTypes = ["string", "number", "boolean"];
|
||
return explicitTypes.some((elem) => type.toLowerCase() === elem);
|
||
}
|
||
function isBoolean$1(...args) {
|
||
return args.some((elem) => elem.toLowerCase() === "boolean");
|
||
}
|
||
let supported;
|
||
let perf;
|
||
function startMeasure(instance, type) {
|
||
if (instance.appContext.config.performance && isSupported()) {
|
||
perf.mark(`vue-${type}-${instance.uid}`);
|
||
}
|
||
{
|
||
devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
|
||
}
|
||
}
|
||
function endMeasure(instance, type) {
|
||
if (instance.appContext.config.performance && isSupported()) {
|
||
const startTag = `vue-${type}-${instance.uid}`;
|
||
const endTag = startTag + `:end`;
|
||
perf.mark(endTag);
|
||
perf.measure(
|
||
`<${formatComponentName(instance, instance.type)}> ${type}`,
|
||
startTag,
|
||
endTag
|
||
);
|
||
perf.clearMarks(startTag);
|
||
perf.clearMarks(endTag);
|
||
}
|
||
{
|
||
devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
|
||
}
|
||
}
|
||
function isSupported() {
|
||
if (supported !== void 0) {
|
||
return supported;
|
||
}
|
||
if (typeof window !== "undefined" && window.performance) {
|
||
supported = true;
|
||
perf = window.performance;
|
||
} else {
|
||
supported = false;
|
||
}
|
||
return supported;
|
||
}
|
||
const queuePostRenderEffect$1 = queuePostFlushCb;
|
||
const Fragment = Symbol.for("v-fgt");
|
||
const Text = Symbol.for("v-txt");
|
||
const Comment = Symbol.for("v-cmt");
|
||
const Static = Symbol.for("v-stc");
|
||
function isVNode(value) {
|
||
return value ? value.__v_isVNode === true : false;
|
||
}
|
||
const InternalObjectKey = `__vInternal`;
|
||
function guardReactiveProps(props) {
|
||
if (!props)
|
||
return null;
|
||
return isProxy(props) || InternalObjectKey in props ? extend({}, props) : props;
|
||
}
|
||
const emptyAppContext = createAppContext();
|
||
let uid = 0;
|
||
function createComponentInstance(vnode, parent, suspense) {
|
||
const type = vnode.type;
|
||
const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
|
||
const instance = {
|
||
uid: uid++,
|
||
vnode,
|
||
type,
|
||
parent,
|
||
appContext,
|
||
root: null,
|
||
// to be immediately set
|
||
next: null,
|
||
subTree: null,
|
||
// will be set synchronously right after creation
|
||
effect: null,
|
||
update: null,
|
||
// will be set synchronously right after creation
|
||
scope: new EffectScope(
|
||
true
|
||
/* detached */
|
||
),
|
||
render: null,
|
||
proxy: null,
|
||
exposed: null,
|
||
exposeProxy: null,
|
||
withProxy: null,
|
||
provides: parent ? parent.provides : Object.create(appContext.provides),
|
||
accessCache: null,
|
||
renderCache: [],
|
||
// local resolved assets
|
||
components: null,
|
||
directives: null,
|
||
// resolved props and emits options
|
||
propsOptions: normalizePropsOptions(type, appContext),
|
||
emitsOptions: normalizeEmitsOptions(type, appContext),
|
||
// emit
|
||
emit: null,
|
||
// to be set immediately
|
||
emitted: null,
|
||
// props default value
|
||
propsDefaults: EMPTY_OBJ,
|
||
// inheritAttrs
|
||
inheritAttrs: type.inheritAttrs,
|
||
// state
|
||
ctx: EMPTY_OBJ,
|
||
data: EMPTY_OBJ,
|
||
props: EMPTY_OBJ,
|
||
attrs: EMPTY_OBJ,
|
||
slots: EMPTY_OBJ,
|
||
refs: EMPTY_OBJ,
|
||
setupState: EMPTY_OBJ,
|
||
setupContext: null,
|
||
attrsProxy: null,
|
||
slotsProxy: null,
|
||
// suspense related
|
||
suspense,
|
||
suspenseId: suspense ? suspense.pendingId : 0,
|
||
asyncDep: null,
|
||
asyncResolved: false,
|
||
// lifecycle hooks
|
||
// not using enums here because it results in computed properties
|
||
isMounted: false,
|
||
isUnmounted: false,
|
||
isDeactivated: false,
|
||
bc: null,
|
||
c: null,
|
||
bm: null,
|
||
m: null,
|
||
bu: null,
|
||
u: null,
|
||
um: null,
|
||
bum: null,
|
||
da: null,
|
||
a: null,
|
||
rtg: null,
|
||
rtc: null,
|
||
ec: null,
|
||
sp: null
|
||
};
|
||
{
|
||
instance.ctx = createDevRenderContext(instance);
|
||
}
|
||
instance.root = parent ? parent.root : instance;
|
||
instance.emit = emit.bind(null, instance);
|
||
if (vnode.ce) {
|
||
vnode.ce(instance);
|
||
}
|
||
return instance;
|
||
}
|
||
let currentInstance = null;
|
||
const getCurrentInstance = () => currentInstance || currentRenderingInstance;
|
||
let internalSetCurrentInstance;
|
||
let setInSSRSetupState;
|
||
{
|
||
internalSetCurrentInstance = (i) => {
|
||
currentInstance = i;
|
||
};
|
||
setInSSRSetupState = (v) => {
|
||
isInSSRComponentSetup = v;
|
||
};
|
||
}
|
||
const setCurrentInstance = (instance) => {
|
||
const prev = currentInstance;
|
||
internalSetCurrentInstance(instance);
|
||
instance.scope.on();
|
||
return () => {
|
||
instance.scope.off();
|
||
internalSetCurrentInstance(prev);
|
||
};
|
||
};
|
||
const unsetCurrentInstance = () => {
|
||
currentInstance && currentInstance.scope.off();
|
||
internalSetCurrentInstance(null);
|
||
};
|
||
const isBuiltInTag = /* @__PURE__ */ makeMap("slot,component");
|
||
function validateComponentName(name2, { isNativeTag }) {
|
||
if (isBuiltInTag(name2) || isNativeTag(name2)) {
|
||
warn$1(
|
||
"Do not use built-in or reserved HTML elements as component id: " + name2
|
||
);
|
||
}
|
||
}
|
||
function isStatefulComponent(instance) {
|
||
return instance.vnode.shapeFlag & 4;
|
||
}
|
||
let isInSSRComponentSetup = false;
|
||
function setupComponent(instance, isSSR = false) {
|
||
isSSR && setInSSRSetupState(isSSR);
|
||
const {
|
||
props
|
||
/*, children*/
|
||
} = instance.vnode;
|
||
const isStateful = isStatefulComponent(instance);
|
||
initProps$1(instance, props, isStateful, isSSR);
|
||
const setupResult = isStateful ? setupStatefulComponent(instance, isSSR) : void 0;
|
||
isSSR && setInSSRSetupState(false);
|
||
return setupResult;
|
||
}
|
||
function setupStatefulComponent(instance, isSSR) {
|
||
const Component2 = instance.type;
|
||
{
|
||
if (Component2.name) {
|
||
validateComponentName(Component2.name, instance.appContext.config);
|
||
}
|
||
if (Component2.components) {
|
||
const names = Object.keys(Component2.components);
|
||
for (let i = 0; i < names.length; i++) {
|
||
validateComponentName(names[i], instance.appContext.config);
|
||
}
|
||
}
|
||
if (Component2.directives) {
|
||
const names = Object.keys(Component2.directives);
|
||
for (let i = 0; i < names.length; i++) {
|
||
validateDirectiveName(names[i]);
|
||
}
|
||
}
|
||
if (Component2.compilerOptions && isRuntimeOnly()) {
|
||
warn$1(
|
||
`"compilerOptions" is only supported when using a build of Vue that includes the runtime compiler. Since you are using a runtime-only build, the options should be passed via your build tool config instead.`
|
||
);
|
||
}
|
||
}
|
||
instance.accessCache = /* @__PURE__ */ Object.create(null);
|
||
instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
|
||
{
|
||
exposePropsOnRenderContext(instance);
|
||
}
|
||
const { setup } = Component2;
|
||
if (setup) {
|
||
const setupContext = instance.setupContext = setup.length > 1 ? createSetupContext(instance) : null;
|
||
const reset = setCurrentInstance(instance);
|
||
pauseTracking();
|
||
const setupResult = callWithErrorHandling(
|
||
setup,
|
||
instance,
|
||
0,
|
||
[
|
||
shallowReadonly(instance.props),
|
||
setupContext
|
||
]
|
||
);
|
||
resetTracking();
|
||
reset();
|
||
if (isPromise(setupResult)) {
|
||
setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
|
||
{
|
||
warn$1(
|
||
`setup() returned a Promise, but the version of Vue you are using does not support it yet.`
|
||
);
|
||
}
|
||
} else {
|
||
handleSetupResult(instance, setupResult, isSSR);
|
||
}
|
||
} else {
|
||
finishComponentSetup(instance, isSSR);
|
||
}
|
||
}
|
||
function handleSetupResult(instance, setupResult, isSSR) {
|
||
if (isFunction$1(setupResult)) {
|
||
{
|
||
instance.render = setupResult;
|
||
}
|
||
} else if (isObject$1(setupResult)) {
|
||
if (isVNode(setupResult)) {
|
||
warn$1(
|
||
`setup() should not return VNodes directly - return a render function instead.`
|
||
);
|
||
}
|
||
{
|
||
instance.devtoolsRawSetupState = setupResult;
|
||
}
|
||
instance.setupState = proxyRefs(setupResult);
|
||
{
|
||
exposeSetupStateOnRenderContext(instance);
|
||
}
|
||
} else if (setupResult !== void 0) {
|
||
warn$1(
|
||
`setup() should return an object. Received: ${setupResult === null ? "null" : typeof setupResult}`
|
||
);
|
||
}
|
||
finishComponentSetup(instance, isSSR);
|
||
}
|
||
let compile;
|
||
const isRuntimeOnly = () => !compile;
|
||
function finishComponentSetup(instance, isSSR, skipOptions) {
|
||
const Component2 = instance.type;
|
||
if (!instance.render) {
|
||
instance.render = Component2.render || NOOP;
|
||
}
|
||
{
|
||
const reset = setCurrentInstance(instance);
|
||
pauseTracking();
|
||
try {
|
||
applyOptions$1(instance);
|
||
} finally {
|
||
resetTracking();
|
||
reset();
|
||
}
|
||
}
|
||
if (!Component2.render && instance.render === NOOP && !isSSR) {
|
||
if (Component2.template) {
|
||
warn$1(
|
||
`Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
|
||
);
|
||
} else {
|
||
warn$1(`Component is missing template or render function.`);
|
||
}
|
||
}
|
||
}
|
||
function getAttrsProxy(instance) {
|
||
return instance.attrsProxy || (instance.attrsProxy = new Proxy(
|
||
instance.attrs,
|
||
{
|
||
get(target, key) {
|
||
track(instance, "get", "$attrs");
|
||
return target[key];
|
||
},
|
||
set() {
|
||
warn$1(`setupContext.attrs is readonly.`);
|
||
return false;
|
||
},
|
||
deleteProperty() {
|
||
warn$1(`setupContext.attrs is readonly.`);
|
||
return false;
|
||
}
|
||
}
|
||
));
|
||
}
|
||
function getSlotsProxy(instance) {
|
||
return instance.slotsProxy || (instance.slotsProxy = new Proxy(instance.slots, {
|
||
get(target, key) {
|
||
track(instance, "get", "$slots");
|
||
return target[key];
|
||
}
|
||
}));
|
||
}
|
||
function createSetupContext(instance) {
|
||
const expose = (exposed) => {
|
||
{
|
||
if (instance.exposed) {
|
||
warn$1(`expose() should be called only once per setup().`);
|
||
}
|
||
if (exposed != null) {
|
||
let exposedType = typeof exposed;
|
||
if (exposedType === "object") {
|
||
if (isArray$1(exposed)) {
|
||
exposedType = "array";
|
||
} else if (isRef(exposed)) {
|
||
exposedType = "ref";
|
||
}
|
||
}
|
||
if (exposedType !== "object") {
|
||
warn$1(
|
||
`expose() should be passed a plain object, received ${exposedType}.`
|
||
);
|
||
}
|
||
}
|
||
}
|
||
instance.exposed = exposed || {};
|
||
};
|
||
{
|
||
return Object.freeze({
|
||
get attrs() {
|
||
return getAttrsProxy(instance);
|
||
},
|
||
get slots() {
|
||
return getSlotsProxy(instance);
|
||
},
|
||
get emit() {
|
||
return (event, ...args) => instance.emit(event, ...args);
|
||
},
|
||
expose
|
||
});
|
||
}
|
||
}
|
||
function getExposeProxy(instance) {
|
||
if (instance.exposed) {
|
||
return instance.exposeProxy || (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
|
||
get(target, key) {
|
||
if (key in target) {
|
||
return target[key];
|
||
}
|
||
return instance.proxy[key];
|
||
},
|
||
has(target, key) {
|
||
return key in target || key in publicPropertiesMap;
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
const classifyRE = /(?:^|[-_])(\w)/g;
|
||
const classify = (str) => str.replace(classifyRE, (c2) => c2.toUpperCase()).replace(/[-_]/g, "");
|
||
function getComponentName(Component2, includeInferred = true) {
|
||
return isFunction$1(Component2) ? Component2.displayName || Component2.name : Component2.name || includeInferred && Component2.__name;
|
||
}
|
||
function formatComponentName(instance, Component2, isRoot = false) {
|
||
let name2 = getComponentName(Component2);
|
||
if (!name2 && Component2.__file) {
|
||
const match = Component2.__file.match(/([^/\\]+)\.\w+$/);
|
||
if (match) {
|
||
name2 = match[1];
|
||
}
|
||
}
|
||
if (!name2 && instance && instance.parent) {
|
||
const inferFromRegistry = (registry) => {
|
||
for (const key in registry) {
|
||
if (registry[key] === Component2) {
|
||
return key;
|
||
}
|
||
}
|
||
};
|
||
name2 = inferFromRegistry(
|
||
instance.components || instance.parent.type.components
|
||
) || inferFromRegistry(instance.appContext.components);
|
||
}
|
||
return name2 ? classify(name2) : isRoot ? `App` : `Anonymous`;
|
||
}
|
||
const computed = (getterOrOptions, debugOptions) => {
|
||
const c2 = computed$1(getterOrOptions, debugOptions, isInSSRComponentSetup);
|
||
{
|
||
const i = getCurrentInstance();
|
||
if (i && i.appContext.config.warnRecursiveComputed) {
|
||
c2._warnRecursive = true;
|
||
}
|
||
}
|
||
return c2;
|
||
};
|
||
const version = "3.4.21";
|
||
const warn = warn$1;
|
||
function unwrapper(target) {
|
||
return unref(target);
|
||
}
|
||
const ARRAYTYPE = "[object Array]";
|
||
const OBJECTTYPE = "[object Object]";
|
||
function diff(current, pre) {
|
||
const result = {};
|
||
syncKeys(current, pre);
|
||
_diff(current, pre, "", result);
|
||
return result;
|
||
}
|
||
function syncKeys(current, pre) {
|
||
current = unwrapper(current);
|
||
if (current === pre)
|
||
return;
|
||
const rootCurrentType = toTypeString(current);
|
||
const rootPreType = toTypeString(pre);
|
||
if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
|
||
for (let key in pre) {
|
||
const currentValue = current[key];
|
||
if (currentValue === void 0) {
|
||
current[key] = null;
|
||
} else {
|
||
syncKeys(currentValue, pre[key]);
|
||
}
|
||
}
|
||
} else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
|
||
if (current.length >= pre.length) {
|
||
pre.forEach((item, index2) => {
|
||
syncKeys(current[index2], item);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
function _diff(current, pre, path, result) {
|
||
current = unwrapper(current);
|
||
if (current === pre)
|
||
return;
|
||
const rootCurrentType = toTypeString(current);
|
||
const rootPreType = toTypeString(pre);
|
||
if (rootCurrentType == OBJECTTYPE) {
|
||
if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length) {
|
||
setResult(result, path, current);
|
||
} else {
|
||
for (let key in current) {
|
||
const currentValue = unwrapper(current[key]);
|
||
const preValue = pre[key];
|
||
const currentType = toTypeString(currentValue);
|
||
const preType = toTypeString(preValue);
|
||
if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
|
||
if (currentValue != preValue) {
|
||
setResult(
|
||
result,
|
||
(path == "" ? "" : path + ".") + key,
|
||
currentValue
|
||
);
|
||
}
|
||
} else if (currentType == ARRAYTYPE) {
|
||
if (preType != ARRAYTYPE) {
|
||
setResult(
|
||
result,
|
||
(path == "" ? "" : path + ".") + key,
|
||
currentValue
|
||
);
|
||
} else {
|
||
if (currentValue.length < preValue.length) {
|
||
setResult(
|
||
result,
|
||
(path == "" ? "" : path + ".") + key,
|
||
currentValue
|
||
);
|
||
} else {
|
||
currentValue.forEach((item, index2) => {
|
||
_diff(
|
||
item,
|
||
preValue[index2],
|
||
(path == "" ? "" : path + ".") + key + "[" + index2 + "]",
|
||
result
|
||
);
|
||
});
|
||
}
|
||
}
|
||
} else if (currentType == OBJECTTYPE) {
|
||
if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) {
|
||
setResult(
|
||
result,
|
||
(path == "" ? "" : path + ".") + key,
|
||
currentValue
|
||
);
|
||
} else {
|
||
for (let subKey in currentValue) {
|
||
_diff(
|
||
currentValue[subKey],
|
||
preValue[subKey],
|
||
(path == "" ? "" : path + ".") + key + "." + subKey,
|
||
result
|
||
);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} else if (rootCurrentType == ARRAYTYPE) {
|
||
if (rootPreType != ARRAYTYPE) {
|
||
setResult(result, path, current);
|
||
} else {
|
||
if (current.length < pre.length) {
|
||
setResult(result, path, current);
|
||
} else {
|
||
current.forEach((item, index2) => {
|
||
_diff(item, pre[index2], path + "[" + index2 + "]", result);
|
||
});
|
||
}
|
||
}
|
||
} else {
|
||
setResult(result, path, current);
|
||
}
|
||
}
|
||
function setResult(result, k, v) {
|
||
result[k] = v;
|
||
}
|
||
function hasComponentEffect(instance) {
|
||
return queue.includes(instance.update);
|
||
}
|
||
function flushCallbacks(instance) {
|
||
const ctx = instance.ctx;
|
||
const callbacks = ctx.__next_tick_callbacks;
|
||
if (callbacks && callbacks.length) {
|
||
const copies = callbacks.slice(0);
|
||
callbacks.length = 0;
|
||
for (let i = 0; i < copies.length; i++) {
|
||
copies[i]();
|
||
}
|
||
}
|
||
}
|
||
function nextTick(instance, fn) {
|
||
const ctx = instance.ctx;
|
||
if (!ctx.__next_tick_pending && !hasComponentEffect(instance)) {
|
||
return nextTick$1(fn && fn.bind(instance.proxy));
|
||
}
|
||
let _resolve;
|
||
if (!ctx.__next_tick_callbacks) {
|
||
ctx.__next_tick_callbacks = [];
|
||
}
|
||
ctx.__next_tick_callbacks.push(() => {
|
||
if (fn) {
|
||
callWithErrorHandling(
|
||
fn.bind(instance.proxy),
|
||
instance,
|
||
14
|
||
);
|
||
} else if (_resolve) {
|
||
_resolve(instance.proxy);
|
||
}
|
||
});
|
||
return new Promise((resolve2) => {
|
||
_resolve = resolve2;
|
||
});
|
||
}
|
||
function clone$3(src, seen) {
|
||
src = unwrapper(src);
|
||
const type = typeof src;
|
||
if (type === "object" && src !== null) {
|
||
let copy = seen.get(src);
|
||
if (typeof copy !== "undefined") {
|
||
return copy;
|
||
}
|
||
if (isArray$1(src)) {
|
||
const len = src.length;
|
||
copy = new Array(len);
|
||
seen.set(src, copy);
|
||
for (let i = 0; i < len; i++) {
|
||
copy[i] = clone$3(src[i], seen);
|
||
}
|
||
} else {
|
||
copy = {};
|
||
seen.set(src, copy);
|
||
for (const name2 in src) {
|
||
if (hasOwn(src, name2)) {
|
||
copy[name2] = clone$3(src[name2], seen);
|
||
}
|
||
}
|
||
}
|
||
return copy;
|
||
}
|
||
if (type !== "symbol") {
|
||
return src;
|
||
}
|
||
}
|
||
function deepCopy(src) {
|
||
return clone$3(src, typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : /* @__PURE__ */ new Map());
|
||
}
|
||
function getMPInstanceData(instance, keys) {
|
||
const data = instance.data;
|
||
const ret = /* @__PURE__ */ Object.create(null);
|
||
keys.forEach((key) => {
|
||
ret[key] = data[key];
|
||
});
|
||
return ret;
|
||
}
|
||
function patch(instance, data, oldData) {
|
||
if (!data) {
|
||
return;
|
||
}
|
||
data = deepCopy(data);
|
||
const ctx = instance.ctx;
|
||
const mpType = ctx.mpType;
|
||
if (mpType === "page" || mpType === "component") {
|
||
data.r0 = 1;
|
||
const mpInstance = ctx.$scope;
|
||
const keys = Object.keys(data);
|
||
const diffData = diff(data, oldData || getMPInstanceData(mpInstance, keys));
|
||
if (Object.keys(diffData).length) {
|
||
ctx.__next_tick_pending = true;
|
||
mpInstance.setData(diffData, () => {
|
||
ctx.__next_tick_pending = false;
|
||
flushCallbacks(instance);
|
||
});
|
||
flushPreFlushCbs();
|
||
} else {
|
||
flushCallbacks(instance);
|
||
}
|
||
}
|
||
}
|
||
function initAppConfig(appConfig) {
|
||
appConfig.globalProperties.$nextTick = function $nextTick(fn) {
|
||
return nextTick(this.$, fn);
|
||
};
|
||
}
|
||
function onApplyOptions(options, instance, publicThis) {
|
||
instance.appContext.config.globalProperties.$applyOptions(
|
||
options,
|
||
instance,
|
||
publicThis
|
||
);
|
||
const computedOptions = options.computed;
|
||
if (computedOptions) {
|
||
const keys = Object.keys(computedOptions);
|
||
if (keys.length) {
|
||
const ctx = instance.ctx;
|
||
if (!ctx.$computedKeys) {
|
||
ctx.$computedKeys = [];
|
||
}
|
||
ctx.$computedKeys.push(...keys);
|
||
}
|
||
}
|
||
delete instance.ctx.$onApplyOptions;
|
||
}
|
||
function setRef$1(instance, isUnmount = false) {
|
||
const {
|
||
setupState,
|
||
$templateRefs,
|
||
ctx: { $scope, $mpPlatform }
|
||
} = instance;
|
||
if ($mpPlatform === "mp-alipay") {
|
||
return;
|
||
}
|
||
if (!$templateRefs || !$scope) {
|
||
return;
|
||
}
|
||
if (isUnmount) {
|
||
return $templateRefs.forEach(
|
||
(templateRef) => setTemplateRef(templateRef, null, setupState)
|
||
);
|
||
}
|
||
const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao";
|
||
const doSetByRefs = (refs) => {
|
||
const mpComponents = (
|
||
// 字节小程序 selectAllComponents 可能返回 null
|
||
// https://github.com/dcloudio/uni-app/issues/3954
|
||
($scope.selectAllComponents(".r") || []).concat(
|
||
$scope.selectAllComponents(".r-i-f") || []
|
||
)
|
||
);
|
||
return refs.filter((templateRef) => {
|
||
const refValue = findComponentPublicInstance(mpComponents, templateRef.i);
|
||
if (check && refValue === null) {
|
||
return true;
|
||
}
|
||
setTemplateRef(templateRef, refValue, setupState);
|
||
return false;
|
||
});
|
||
};
|
||
const doSet = () => {
|
||
const refs = doSetByRefs($templateRefs);
|
||
if (refs.length && instance.proxy && instance.proxy.$scope) {
|
||
instance.proxy.$scope.setData({ r1: 1 }, () => {
|
||
doSetByRefs(refs);
|
||
});
|
||
}
|
||
};
|
||
if ($scope._$setRef) {
|
||
$scope._$setRef(doSet);
|
||
} else {
|
||
nextTick(instance, doSet);
|
||
}
|
||
}
|
||
function toSkip(value) {
|
||
if (isObject$1(value)) {
|
||
markRaw(value);
|
||
}
|
||
return value;
|
||
}
|
||
function findComponentPublicInstance(mpComponents, id) {
|
||
const mpInstance = mpComponents.find(
|
||
(com) => com && (com.properties || com.props).uI === id
|
||
);
|
||
if (mpInstance) {
|
||
const vm = mpInstance.$vm;
|
||
if (vm) {
|
||
return getExposeProxy(vm.$) || vm;
|
||
}
|
||
return toSkip(mpInstance);
|
||
}
|
||
return null;
|
||
}
|
||
function setTemplateRef({ r: r2, f: f2 }, refValue, setupState) {
|
||
if (isFunction$1(r2)) {
|
||
r2(refValue, {});
|
||
} else {
|
||
const _isString = isString$1(r2);
|
||
const _isRef = isRef(r2);
|
||
if (_isString || _isRef) {
|
||
if (f2) {
|
||
if (!_isRef) {
|
||
return;
|
||
}
|
||
if (!isArray$1(r2.value)) {
|
||
r2.value = [];
|
||
}
|
||
const existing = r2.value;
|
||
if (existing.indexOf(refValue) === -1) {
|
||
existing.push(refValue);
|
||
if (!refValue) {
|
||
return;
|
||
}
|
||
onBeforeUnmount(() => remove(existing, refValue), refValue.$);
|
||
}
|
||
} else if (_isString) {
|
||
if (hasOwn(setupState, r2)) {
|
||
setupState[r2] = refValue;
|
||
}
|
||
} else if (isRef(r2)) {
|
||
r2.value = refValue;
|
||
} else {
|
||
warnRef(r2);
|
||
}
|
||
} else {
|
||
warnRef(r2);
|
||
}
|
||
}
|
||
}
|
||
function warnRef(ref2) {
|
||
warn("Invalid template ref type:", ref2, `(${typeof ref2})`);
|
||
}
|
||
const queuePostRenderEffect = queuePostFlushCb;
|
||
function mountComponent(initialVNode, options) {
|
||
const instance = initialVNode.component = createComponentInstance(initialVNode, options.parentComponent, null);
|
||
{
|
||
instance.ctx.$onApplyOptions = onApplyOptions;
|
||
instance.ctx.$children = [];
|
||
}
|
||
if (options.mpType === "app") {
|
||
instance.render = NOOP;
|
||
}
|
||
if (options.onBeforeSetup) {
|
||
options.onBeforeSetup(instance, options);
|
||
}
|
||
{
|
||
pushWarningContext(initialVNode);
|
||
startMeasure(instance, `mount`);
|
||
}
|
||
{
|
||
startMeasure(instance, `init`);
|
||
}
|
||
setupComponent(instance);
|
||
{
|
||
endMeasure(instance, `init`);
|
||
}
|
||
{
|
||
if (options.parentComponent && instance.proxy) {
|
||
options.parentComponent.ctx.$children.push(getExposeProxy(instance) || instance.proxy);
|
||
}
|
||
}
|
||
setupRenderEffect(instance);
|
||
{
|
||
popWarningContext();
|
||
endMeasure(instance, `mount`);
|
||
}
|
||
return instance.proxy;
|
||
}
|
||
const getFunctionalFallthrough = (attrs) => {
|
||
let res;
|
||
for (const key in attrs) {
|
||
if (key === "class" || key === "style" || isOn(key)) {
|
||
(res || (res = {}))[key] = attrs[key];
|
||
}
|
||
}
|
||
return res;
|
||
};
|
||
function renderComponentRoot(instance) {
|
||
const {
|
||
type: Component2,
|
||
vnode,
|
||
proxy,
|
||
withProxy,
|
||
props,
|
||
propsOptions: [propsOptions],
|
||
slots,
|
||
attrs,
|
||
emit: emit2,
|
||
render,
|
||
renderCache,
|
||
data,
|
||
setupState,
|
||
ctx,
|
||
uid: uid2,
|
||
appContext: {
|
||
app: {
|
||
config: {
|
||
globalProperties: { pruneComponentPropsCache: pruneComponentPropsCache2 }
|
||
}
|
||
}
|
||
},
|
||
inheritAttrs
|
||
} = instance;
|
||
instance.$templateRefs = [];
|
||
instance.$ei = 0;
|
||
pruneComponentPropsCache2(uid2);
|
||
instance.__counter = instance.__counter === 0 ? 1 : 0;
|
||
let result;
|
||
const prev = setCurrentRenderingInstance(instance);
|
||
try {
|
||
if (vnode.shapeFlag & 4) {
|
||
fallthroughAttrs(inheritAttrs, props, propsOptions, attrs);
|
||
const proxyToUse = withProxy || proxy;
|
||
result = render.call(
|
||
proxyToUse,
|
||
proxyToUse,
|
||
renderCache,
|
||
props,
|
||
setupState,
|
||
data,
|
||
ctx
|
||
);
|
||
} else {
|
||
fallthroughAttrs(
|
||
inheritAttrs,
|
||
props,
|
||
propsOptions,
|
||
Component2.props ? attrs : getFunctionalFallthrough(attrs)
|
||
);
|
||
const render2 = Component2;
|
||
result = render2.length > 1 ? render2(props, { attrs, slots, emit: emit2 }) : render2(
|
||
props,
|
||
null
|
||
/* we know it doesn't need it */
|
||
);
|
||
}
|
||
} catch (err) {
|
||
handleError(err, instance, 1);
|
||
result = false;
|
||
}
|
||
setRef$1(instance);
|
||
setCurrentRenderingInstance(prev);
|
||
return result;
|
||
}
|
||
function fallthroughAttrs(inheritAttrs, props, propsOptions, fallthroughAttrs2) {
|
||
if (props && fallthroughAttrs2 && inheritAttrs !== false) {
|
||
const keys = Object.keys(fallthroughAttrs2).filter(
|
||
(key) => key !== "class" && key !== "style"
|
||
);
|
||
if (!keys.length) {
|
||
return;
|
||
}
|
||
if (propsOptions && keys.some(isModelListener)) {
|
||
keys.forEach((key) => {
|
||
if (!isModelListener(key) || !(key.slice(9) in propsOptions)) {
|
||
props[key] = fallthroughAttrs2[key];
|
||
}
|
||
});
|
||
} else {
|
||
keys.forEach((key) => props[key] = fallthroughAttrs2[key]);
|
||
}
|
||
}
|
||
}
|
||
const updateComponentPreRender = (instance) => {
|
||
pauseTracking();
|
||
flushPreFlushCbs();
|
||
resetTracking();
|
||
};
|
||
function componentUpdateScopedSlotsFn() {
|
||
const scopedSlotsData = this.$scopedSlotsData;
|
||
if (!scopedSlotsData || scopedSlotsData.length === 0) {
|
||
return;
|
||
}
|
||
const mpInstance = this.ctx.$scope;
|
||
const oldData = mpInstance.data;
|
||
const diffData = /* @__PURE__ */ Object.create(null);
|
||
scopedSlotsData.forEach(({ path, index: index2, data }) => {
|
||
const oldScopedSlotData = getValueByDataPath(oldData, path);
|
||
const diffPath = isString$1(index2) ? `${path}.${index2}` : `${path}[${index2}]`;
|
||
if (typeof oldScopedSlotData === "undefined" || typeof oldScopedSlotData[index2] === "undefined") {
|
||
diffData[diffPath] = data;
|
||
} else {
|
||
const diffScopedSlotData = diff(
|
||
data,
|
||
oldScopedSlotData[index2]
|
||
);
|
||
Object.keys(diffScopedSlotData).forEach((name2) => {
|
||
diffData[diffPath + "." + name2] = diffScopedSlotData[name2];
|
||
});
|
||
}
|
||
});
|
||
scopedSlotsData.length = 0;
|
||
if (Object.keys(diffData).length) {
|
||
mpInstance.setData(diffData);
|
||
}
|
||
}
|
||
function toggleRecurse({ effect: effect2, update }, allowed) {
|
||
effect2.allowRecurse = update.allowRecurse = allowed;
|
||
}
|
||
function setupRenderEffect(instance) {
|
||
const updateScopedSlots = componentUpdateScopedSlotsFn.bind(
|
||
instance
|
||
);
|
||
instance.$updateScopedSlots = () => nextTick$1(() => queueJob(updateScopedSlots));
|
||
const componentUpdateFn = () => {
|
||
if (!instance.isMounted) {
|
||
onBeforeUnmount(() => {
|
||
setRef$1(instance, true);
|
||
}, instance);
|
||
{
|
||
startMeasure(instance, `patch`);
|
||
}
|
||
patch(instance, renderComponentRoot(instance));
|
||
{
|
||
endMeasure(instance, `patch`);
|
||
}
|
||
{
|
||
devtoolsComponentAdded(instance);
|
||
}
|
||
} else {
|
||
const { next, bu, u } = instance;
|
||
{
|
||
pushWarningContext(next || instance.vnode);
|
||
}
|
||
toggleRecurse(instance, false);
|
||
updateComponentPreRender();
|
||
if (bu) {
|
||
invokeArrayFns$1(bu);
|
||
}
|
||
toggleRecurse(instance, true);
|
||
{
|
||
startMeasure(instance, `patch`);
|
||
}
|
||
patch(instance, renderComponentRoot(instance));
|
||
{
|
||
endMeasure(instance, `patch`);
|
||
}
|
||
if (u) {
|
||
queuePostRenderEffect(u);
|
||
}
|
||
{
|
||
devtoolsComponentUpdated(instance);
|
||
}
|
||
{
|
||
popWarningContext();
|
||
}
|
||
}
|
||
};
|
||
const effect2 = instance.effect = new ReactiveEffect2(
|
||
componentUpdateFn,
|
||
NOOP,
|
||
() => queueJob(update),
|
||
instance.scope
|
||
// track it in component's effect scope
|
||
);
|
||
const update = instance.update = () => {
|
||
if (effect2.dirty) {
|
||
effect2.run();
|
||
}
|
||
};
|
||
update.id = instance.uid;
|
||
toggleRecurse(instance, true);
|
||
{
|
||
effect2.onTrack = instance.rtc ? (e2) => invokeArrayFns$1(instance.rtc, e2) : void 0;
|
||
effect2.onTrigger = instance.rtg ? (e2) => invokeArrayFns$1(instance.rtg, e2) : void 0;
|
||
update.ownerInstance = instance;
|
||
}
|
||
update();
|
||
}
|
||
function unmountComponent(instance) {
|
||
const { bum, scope, update, um } = instance;
|
||
if (bum) {
|
||
invokeArrayFns$1(bum);
|
||
}
|
||
scope.stop();
|
||
if (update) {
|
||
update.active = false;
|
||
}
|
||
if (um) {
|
||
queuePostRenderEffect(um);
|
||
}
|
||
queuePostRenderEffect(() => {
|
||
instance.isUnmounted = true;
|
||
});
|
||
{
|
||
devtoolsComponentRemoved(instance);
|
||
}
|
||
}
|
||
const oldCreateApp = createAppAPI();
|
||
function getTarget() {
|
||
if (typeof window !== "undefined") {
|
||
return window;
|
||
}
|
||
if (typeof globalThis !== "undefined") {
|
||
return globalThis;
|
||
}
|
||
if (typeof global !== "undefined") {
|
||
return global;
|
||
}
|
||
if (typeof my !== "undefined") {
|
||
return my;
|
||
}
|
||
}
|
||
function createVueApp(rootComponent, rootProps = null) {
|
||
const target = getTarget();
|
||
target.__VUE__ = true;
|
||
{
|
||
setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
|
||
}
|
||
const app = oldCreateApp(rootComponent, rootProps);
|
||
const appContext = app._context;
|
||
initAppConfig(appContext.config);
|
||
const createVNode2 = (initialVNode) => {
|
||
initialVNode.appContext = appContext;
|
||
initialVNode.shapeFlag = 6;
|
||
return initialVNode;
|
||
};
|
||
const createComponent2 = function createComponent22(initialVNode, options) {
|
||
return mountComponent(createVNode2(initialVNode), options);
|
||
};
|
||
const destroyComponent = function destroyComponent2(component) {
|
||
return component && unmountComponent(component.$);
|
||
};
|
||
app.mount = function mount() {
|
||
rootComponent.render = NOOP;
|
||
const instance = mountComponent(
|
||
createVNode2({ type: rootComponent }),
|
||
{
|
||
mpType: "app",
|
||
mpInstance: null,
|
||
parentComponent: null,
|
||
slots: [],
|
||
props: null
|
||
}
|
||
);
|
||
app._instance = instance.$;
|
||
{
|
||
devtoolsInitApp(app, version);
|
||
}
|
||
instance.$app = app;
|
||
instance.$createComponent = createComponent2;
|
||
instance.$destroyComponent = destroyComponent;
|
||
appContext.$appInstance = instance;
|
||
return instance;
|
||
};
|
||
app.unmount = function unmount() {
|
||
warn(`Cannot unmount an app.`);
|
||
};
|
||
return app;
|
||
}
|
||
function injectLifecycleHook(name2, hook, publicThis, instance) {
|
||
if (isFunction$1(hook)) {
|
||
injectHook(name2, hook.bind(publicThis), instance);
|
||
}
|
||
}
|
||
function initHooks$1(options, instance, publicThis) {
|
||
const mpType = options.mpType || publicThis.$mpType;
|
||
if (!mpType || mpType === "component") {
|
||
return;
|
||
}
|
||
Object.keys(options).forEach((name2) => {
|
||
if (isUniLifecycleHook(name2, options[name2], false)) {
|
||
const hooks = options[name2];
|
||
if (isArray$1(hooks)) {
|
||
hooks.forEach((hook) => injectLifecycleHook(name2, hook, publicThis, instance));
|
||
} else {
|
||
injectLifecycleHook(name2, hooks, publicThis, instance);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
function applyOptions$2(options, instance, publicThis) {
|
||
initHooks$1(options, instance, publicThis);
|
||
}
|
||
function set(target, key, val) {
|
||
return target[key] = val;
|
||
}
|
||
function $callMethod(method, ...args) {
|
||
const fn = this[method];
|
||
if (fn) {
|
||
return fn(...args);
|
||
}
|
||
console.error(`method ${method} not found`);
|
||
return null;
|
||
}
|
||
function createErrorHandler(app) {
|
||
return function errorHandler(err, instance, _info) {
|
||
if (!instance) {
|
||
throw err;
|
||
}
|
||
const appInstance = app._instance;
|
||
if (!appInstance || !appInstance.proxy) {
|
||
throw err;
|
||
}
|
||
{
|
||
appInstance.proxy.$callHook(ON_ERROR, err);
|
||
}
|
||
};
|
||
}
|
||
function mergeAsArray(to, from) {
|
||
return to ? [...new Set([].concat(to, from))] : from;
|
||
}
|
||
function initOptionMergeStrategies(optionMergeStrategies) {
|
||
UniLifecycleHooks.forEach((name2) => {
|
||
optionMergeStrategies[name2] = mergeAsArray;
|
||
});
|
||
}
|
||
let realAtob;
|
||
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
|
||
if (typeof atob !== "function") {
|
||
realAtob = function(str) {
|
||
str = String(str).replace(/[\t\n\f\r ]+/g, "");
|
||
if (!b64re.test(str)) {
|
||
throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
||
}
|
||
str += "==".slice(2 - (str.length & 3));
|
||
var bitmap;
|
||
var result = "";
|
||
var r1;
|
||
var r2;
|
||
var i = 0;
|
||
for (; i < str.length; ) {
|
||
bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 | (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++)));
|
||
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
|
||
}
|
||
return result;
|
||
};
|
||
} else {
|
||
realAtob = atob;
|
||
}
|
||
function b64DecodeUnicode(str) {
|
||
return decodeURIComponent(realAtob(str).split("").map(function(c2) {
|
||
return "%" + ("00" + c2.charCodeAt(0).toString(16)).slice(-2);
|
||
}).join(""));
|
||
}
|
||
function getCurrentUserInfo() {
|
||
const token = index.getStorageSync("uni_id_token") || "";
|
||
const tokenArr = token.split(".");
|
||
if (!token || tokenArr.length !== 3) {
|
||
return {
|
||
uid: null,
|
||
role: [],
|
||
permission: [],
|
||
tokenExpired: 0
|
||
};
|
||
}
|
||
let userInfo;
|
||
try {
|
||
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]));
|
||
} catch (error) {
|
||
throw new Error("获取当前用户信息出错,详细错误信息为:" + error.message);
|
||
}
|
||
userInfo.tokenExpired = userInfo.exp * 1e3;
|
||
delete userInfo.exp;
|
||
delete userInfo.iat;
|
||
return userInfo;
|
||
}
|
||
function uniIdMixin(globalProperties) {
|
||
globalProperties.uniIDHasRole = function(roleId) {
|
||
const { role } = getCurrentUserInfo();
|
||
return role.indexOf(roleId) > -1;
|
||
};
|
||
globalProperties.uniIDHasPermission = function(permissionId) {
|
||
const { permission } = getCurrentUserInfo();
|
||
return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1;
|
||
};
|
||
globalProperties.uniIDTokenValid = function() {
|
||
const { tokenExpired } = getCurrentUserInfo();
|
||
return tokenExpired > Date.now();
|
||
};
|
||
}
|
||
function initApp(app) {
|
||
const appConfig = app._context.config;
|
||
appConfig.errorHandler = invokeCreateErrorHandler(app, createErrorHandler);
|
||
initOptionMergeStrategies(appConfig.optionMergeStrategies);
|
||
const globalProperties = appConfig.globalProperties;
|
||
{
|
||
uniIdMixin(globalProperties);
|
||
}
|
||
{
|
||
globalProperties.$set = set;
|
||
globalProperties.$applyOptions = applyOptions$2;
|
||
globalProperties.$callMethod = $callMethod;
|
||
}
|
||
{
|
||
index.invokeCreateVueAppHook(app);
|
||
}
|
||
}
|
||
const propsCaches = /* @__PURE__ */ Object.create(null);
|
||
function renderProps(props) {
|
||
const { uid: uid2, __counter } = getCurrentInstance();
|
||
const propsId = (propsCaches[uid2] || (propsCaches[uid2] = [])).push(guardReactiveProps(props)) - 1;
|
||
return uid2 + "," + propsId + "," + __counter;
|
||
}
|
||
function pruneComponentPropsCache(uid2) {
|
||
delete propsCaches[uid2];
|
||
}
|
||
function findComponentPropsData(up) {
|
||
if (!up) {
|
||
return;
|
||
}
|
||
const [uid2, propsId] = up.split(",");
|
||
if (!propsCaches[uid2]) {
|
||
return;
|
||
}
|
||
return propsCaches[uid2][parseInt(propsId)];
|
||
}
|
||
var plugin = {
|
||
install(app) {
|
||
initApp(app);
|
||
app.config.globalProperties.pruneComponentPropsCache = pruneComponentPropsCache;
|
||
const oldMount = app.mount;
|
||
app.mount = function mount(rootContainer) {
|
||
const instance = oldMount.call(app, rootContainer);
|
||
const createApp2 = getCreateApp();
|
||
if (createApp2) {
|
||
createApp2(instance);
|
||
} else {
|
||
if (typeof createMiniProgramApp !== "undefined") {
|
||
createMiniProgramApp(instance);
|
||
}
|
||
}
|
||
return instance;
|
||
};
|
||
}
|
||
};
|
||
function getCreateApp() {
|
||
const method = "createApp";
|
||
if (typeof global !== "undefined" && typeof global[method] !== "undefined") {
|
||
return global[method];
|
||
} else if (typeof my !== "undefined") {
|
||
return my[method];
|
||
}
|
||
}
|
||
function vOn(value, key) {
|
||
const instance = getCurrentInstance();
|
||
const ctx = instance.ctx;
|
||
const extraKey = typeof key !== "undefined" && (ctx.$mpPlatform === "mp-weixin" || ctx.$mpPlatform === "mp-qq" || ctx.$mpPlatform === "mp-xhs") && (isString$1(key) || typeof key === "number") ? "_" + key : "";
|
||
const name2 = "e" + instance.$ei++ + extraKey;
|
||
const mpInstance = ctx.$scope;
|
||
if (!value) {
|
||
delete mpInstance[name2];
|
||
return name2;
|
||
}
|
||
const existingInvoker = mpInstance[name2];
|
||
if (existingInvoker) {
|
||
existingInvoker.value = value;
|
||
} else {
|
||
mpInstance[name2] = createInvoker(value, instance);
|
||
}
|
||
return name2;
|
||
}
|
||
function createInvoker(initialValue, instance) {
|
||
const invoker = (e2) => {
|
||
patchMPEvent(e2);
|
||
let args = [e2];
|
||
if (e2.detail && e2.detail.__args__) {
|
||
args = e2.detail.__args__;
|
||
}
|
||
const eventValue = invoker.value;
|
||
const invoke = () => callWithAsyncErrorHandling(patchStopImmediatePropagation(e2, eventValue), instance, 5, args);
|
||
const eventTarget = e2.target;
|
||
const eventSync = eventTarget ? eventTarget.dataset ? String(eventTarget.dataset.eventsync) === "true" : false : false;
|
||
if (bubbles.includes(e2.type) && !eventSync) {
|
||
setTimeout(invoke);
|
||
} else {
|
||
const res = invoke();
|
||
if (e2.type === "input" && (isArray$1(res) || isPromise(res))) {
|
||
return;
|
||
}
|
||
return res;
|
||
}
|
||
};
|
||
invoker.value = initialValue;
|
||
return invoker;
|
||
}
|
||
const bubbles = [
|
||
// touch事件暂不做延迟,否则在 Android 上会影响性能,比如一些拖拽跟手手势等
|
||
// 'touchstart',
|
||
// 'touchmove',
|
||
// 'touchcancel',
|
||
// 'touchend',
|
||
"tap",
|
||
"longpress",
|
||
"longtap",
|
||
"transitionend",
|
||
"animationstart",
|
||
"animationiteration",
|
||
"animationend",
|
||
"touchforcechange"
|
||
];
|
||
function patchMPEvent(event) {
|
||
if (event.type && event.target) {
|
||
event.preventDefault = NOOP;
|
||
event.stopPropagation = NOOP;
|
||
event.stopImmediatePropagation = NOOP;
|
||
if (!hasOwn(event, "detail")) {
|
||
event.detail = {};
|
||
}
|
||
if (hasOwn(event, "markerId")) {
|
||
event.detail = typeof event.detail === "object" ? event.detail : {};
|
||
event.detail.markerId = event.markerId;
|
||
}
|
||
if (isPlainObject$1(event.detail) && hasOwn(event.detail, "checked") && !hasOwn(event.detail, "value")) {
|
||
event.detail.value = event.detail.checked;
|
||
}
|
||
if (isPlainObject$1(event.detail)) {
|
||
event.target = extend({}, event.target, event.detail);
|
||
}
|
||
}
|
||
}
|
||
function patchStopImmediatePropagation(e2, value) {
|
||
if (isArray$1(value)) {
|
||
const originalStop = e2.stopImmediatePropagation;
|
||
e2.stopImmediatePropagation = () => {
|
||
originalStop && originalStop.call(e2);
|
||
e2._stopped = true;
|
||
};
|
||
return value.map((fn) => (e3) => !e3._stopped && fn(e3));
|
||
} else {
|
||
return value;
|
||
}
|
||
}
|
||
function vFor(source, renderItem) {
|
||
let ret;
|
||
if (isArray$1(source) || isString$1(source)) {
|
||
ret = new Array(source.length);
|
||
for (let i = 0, l = source.length; i < l; i++) {
|
||
ret[i] = renderItem(source[i], i, i);
|
||
}
|
||
} else if (typeof source === "number") {
|
||
if (!Number.isInteger(source)) {
|
||
warn(`The v-for range expect an integer value but got ${source}.`);
|
||
return [];
|
||
}
|
||
ret = new Array(source);
|
||
for (let i = 0; i < source; i++) {
|
||
ret[i] = renderItem(i + 1, i, i);
|
||
}
|
||
} else if (isObject$1(source)) {
|
||
if (source[Symbol.iterator]) {
|
||
ret = Array.from(source, (item, i) => renderItem(item, i, i));
|
||
} else {
|
||
const keys = Object.keys(source);
|
||
ret = new Array(keys.length);
|
||
for (let i = 0, l = keys.length; i < l; i++) {
|
||
const key = keys[i];
|
||
ret[i] = renderItem(source[key], key, i);
|
||
}
|
||
}
|
||
} else {
|
||
ret = [];
|
||
}
|
||
return ret;
|
||
}
|
||
function stringifyStyle(value) {
|
||
if (isString$1(value)) {
|
||
return value;
|
||
}
|
||
return stringify$1(normalizeStyle(value));
|
||
}
|
||
function stringify$1(styles) {
|
||
let ret = "";
|
||
if (!styles || isString$1(styles)) {
|
||
return ret;
|
||
}
|
||
for (const key in styles) {
|
||
ret += `${key.startsWith(`--`) ? key : hyphenate(key)}:${styles[key]};`;
|
||
}
|
||
return ret;
|
||
}
|
||
function setRef(ref2, id, opts = {}) {
|
||
const { $templateRefs } = getCurrentInstance();
|
||
$templateRefs.push({ i: id, r: ref2, k: opts.k, f: opts.f });
|
||
}
|
||
const o = (value, key) => vOn(value, key);
|
||
const f = (source, renderItem) => vFor(source, renderItem);
|
||
const s = (value) => stringifyStyle(value);
|
||
const e = (target, ...sources) => extend(target, ...sources);
|
||
const n = (value) => normalizeClass(value);
|
||
const t = (val) => toDisplayString(val);
|
||
const p = (props) => renderProps(props);
|
||
const sr = (ref2, id, opts) => setRef(ref2, id, opts);
|
||
function createApp$1(rootComponent, rootProps = null) {
|
||
rootComponent && (rootComponent.mpType = "app");
|
||
return createVueApp(rootComponent, rootProps).use(plugin);
|
||
}
|
||
const createSSRApp = createApp$1;
|
||
const MP_METHODS = [
|
||
"createSelectorQuery",
|
||
"createIntersectionObserver",
|
||
"selectAllComponents",
|
||
"selectComponent"
|
||
];
|
||
function createEmitFn(oldEmit, ctx) {
|
||
return function emit2(event, ...args) {
|
||
const scope = ctx.$scope;
|
||
if (scope && event) {
|
||
const detail = { __args__: args };
|
||
{
|
||
scope.triggerEvent(event, detail);
|
||
}
|
||
}
|
||
return oldEmit.apply(this, [event, ...args]);
|
||
};
|
||
}
|
||
function initBaseInstance(instance, options) {
|
||
const ctx = instance.ctx;
|
||
ctx.mpType = options.mpType;
|
||
ctx.$mpType = options.mpType;
|
||
ctx.$mpPlatform = "mp-weixin";
|
||
ctx.$scope = options.mpInstance;
|
||
ctx.$mp = {};
|
||
{
|
||
ctx._self = {};
|
||
}
|
||
instance.slots = {};
|
||
if (isArray$1(options.slots) && options.slots.length) {
|
||
options.slots.forEach((name2) => {
|
||
instance.slots[name2] = true;
|
||
});
|
||
if (instance.slots[SLOT_DEFAULT_NAME]) {
|
||
instance.slots.default = true;
|
||
}
|
||
}
|
||
ctx.getOpenerEventChannel = function() {
|
||
{
|
||
return options.mpInstance.getOpenerEventChannel();
|
||
}
|
||
};
|
||
ctx.$hasHook = hasHook;
|
||
ctx.$callHook = callHook;
|
||
instance.emit = createEmitFn(instance.emit, ctx);
|
||
}
|
||
function initComponentInstance(instance, options) {
|
||
initBaseInstance(instance, options);
|
||
const ctx = instance.ctx;
|
||
MP_METHODS.forEach((method) => {
|
||
ctx[method] = function(...args) {
|
||
const mpInstance = ctx.$scope;
|
||
if (mpInstance && mpInstance[method]) {
|
||
return mpInstance[method].apply(mpInstance, args);
|
||
}
|
||
};
|
||
});
|
||
}
|
||
function initMocks(instance, mpInstance, mocks2) {
|
||
const ctx = instance.ctx;
|
||
mocks2.forEach((mock) => {
|
||
if (hasOwn(mpInstance, mock)) {
|
||
instance[mock] = ctx[mock] = mpInstance[mock];
|
||
}
|
||
});
|
||
}
|
||
function hasHook(name2) {
|
||
const hooks = this.$[name2];
|
||
if (hooks && hooks.length) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function callHook(name2, args) {
|
||
if (name2 === "mounted") {
|
||
callHook.call(this, "bm");
|
||
this.$.isMounted = true;
|
||
name2 = "m";
|
||
}
|
||
const hooks = this.$[name2];
|
||
return hooks && invokeArrayFns(hooks, args);
|
||
}
|
||
const PAGE_INIT_HOOKS = [
|
||
ON_LOAD,
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_UNLOAD,
|
||
ON_RESIZE,
|
||
ON_TAB_ITEM_TAP,
|
||
ON_REACH_BOTTOM,
|
||
ON_PULL_DOWN_REFRESH,
|
||
ON_ADD_TO_FAVORITES
|
||
// 'onReady', // lifetimes.ready
|
||
// 'onPageScroll', // 影响性能,开发者手动注册
|
||
// 'onShareTimeline', // 右上角菜单,开发者手动注册
|
||
// 'onShareAppMessage' // 右上角菜单,开发者手动注册
|
||
];
|
||
function findHooks(vueOptions, hooks = /* @__PURE__ */ new Set()) {
|
||
if (vueOptions) {
|
||
Object.keys(vueOptions).forEach((name2) => {
|
||
if (isUniLifecycleHook(name2, vueOptions[name2])) {
|
||
hooks.add(name2);
|
||
}
|
||
});
|
||
{
|
||
const { extends: extendsOptions, mixins } = vueOptions;
|
||
if (mixins) {
|
||
mixins.forEach((mixin) => findHooks(mixin, hooks));
|
||
}
|
||
if (extendsOptions) {
|
||
findHooks(extendsOptions, hooks);
|
||
}
|
||
}
|
||
}
|
||
return hooks;
|
||
}
|
||
function initHook(mpOptions, hook, excludes) {
|
||
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
|
||
mpOptions[hook] = function(args) {
|
||
return this.$vm && this.$vm.$callHook(hook, args);
|
||
};
|
||
}
|
||
}
|
||
const EXCLUDE_HOOKS = [ON_READY];
|
||
function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
|
||
hooks.forEach((hook) => initHook(mpOptions, hook, excludes));
|
||
}
|
||
function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
|
||
findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes));
|
||
}
|
||
function initRuntimeHooks(mpOptions, runtimeHooks) {
|
||
if (!runtimeHooks) {
|
||
return;
|
||
}
|
||
const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
|
||
hooks.forEach((hook) => {
|
||
if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) {
|
||
initHook(mpOptions, hook, []);
|
||
}
|
||
});
|
||
}
|
||
const findMixinRuntimeHooks = /* @__PURE__ */ once(() => {
|
||
const runtimeHooks = [];
|
||
const app = isFunction$1(getApp) && getApp({ allowDefault: true });
|
||
if (app && app.$vm && app.$vm.$) {
|
||
const mixins = app.$vm.$.appContext.mixins;
|
||
if (isArray$1(mixins)) {
|
||
const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
|
||
mixins.forEach((mixin) => {
|
||
hooks.forEach((hook) => {
|
||
if (hasOwn(mixin, hook) && !runtimeHooks.includes(hook)) {
|
||
runtimeHooks.push(hook);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
}
|
||
return runtimeHooks;
|
||
});
|
||
function initMixinRuntimeHooks(mpOptions) {
|
||
initHooks(mpOptions, findMixinRuntimeHooks());
|
||
}
|
||
const HOOKS = [
|
||
ON_SHOW,
|
||
ON_HIDE,
|
||
ON_ERROR,
|
||
ON_THEME_CHANGE,
|
||
ON_PAGE_NOT_FOUND,
|
||
ON_UNHANDLE_REJECTION
|
||
];
|
||
function parseApp(instance, parseAppOptions) {
|
||
const internalInstance = instance.$;
|
||
const appOptions = {
|
||
globalData: instance.$options && instance.$options.globalData || {},
|
||
$vm: instance,
|
||
// mp-alipay 组件 data 初始化比 onLaunch 早,提前挂载
|
||
onLaunch(options) {
|
||
this.$vm = instance;
|
||
const ctx = internalInstance.ctx;
|
||
if (this.$vm && ctx.$scope) {
|
||
return;
|
||
}
|
||
initBaseInstance(internalInstance, {
|
||
mpType: "app",
|
||
mpInstance: this,
|
||
slots: []
|
||
});
|
||
ctx.globalData = this.globalData;
|
||
instance.$callHook(ON_LAUNCH, options);
|
||
}
|
||
};
|
||
const { onError } = internalInstance;
|
||
if (onError) {
|
||
internalInstance.appContext.config.errorHandler = (err) => {
|
||
instance.$callHook(ON_ERROR, err);
|
||
};
|
||
}
|
||
initLocale(instance);
|
||
const vueOptions = instance.$.type;
|
||
initHooks(appOptions, HOOKS);
|
||
initUnknownHooks(appOptions, vueOptions);
|
||
{
|
||
const methods = vueOptions.methods;
|
||
methods && extend(appOptions, methods);
|
||
}
|
||
if (parseAppOptions) {
|
||
parseAppOptions.parse(appOptions);
|
||
}
|
||
return appOptions;
|
||
}
|
||
function initCreateApp(parseAppOptions) {
|
||
return function createApp2(vm) {
|
||
return App(parseApp(vm, parseAppOptions));
|
||
};
|
||
}
|
||
function initCreateSubpackageApp(parseAppOptions) {
|
||
return function createApp2(vm) {
|
||
const appOptions = parseApp(vm, parseAppOptions);
|
||
const app = isFunction$1(getApp) && getApp({
|
||
allowDefault: true
|
||
});
|
||
if (!app)
|
||
return;
|
||
vm.$.ctx.$scope = app;
|
||
const globalData = app.globalData;
|
||
if (globalData) {
|
||
Object.keys(appOptions.globalData).forEach((name2) => {
|
||
if (!hasOwn(globalData, name2)) {
|
||
globalData[name2] = appOptions.globalData[name2];
|
||
}
|
||
});
|
||
}
|
||
Object.keys(appOptions).forEach((name2) => {
|
||
if (!hasOwn(app, name2)) {
|
||
app[name2] = appOptions[name2];
|
||
}
|
||
});
|
||
initAppLifecycle(appOptions, vm);
|
||
};
|
||
}
|
||
function initAppLifecycle(appOptions, vm) {
|
||
if (isFunction$1(appOptions.onLaunch)) {
|
||
const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync();
|
||
appOptions.onLaunch(args);
|
||
}
|
||
if (isFunction$1(appOptions.onShow) && wx.onAppShow) {
|
||
wx.onAppShow((args) => {
|
||
vm.$callHook("onShow", args);
|
||
});
|
||
}
|
||
if (isFunction$1(appOptions.onHide) && wx.onAppHide) {
|
||
wx.onAppHide((args) => {
|
||
vm.$callHook("onHide", args);
|
||
});
|
||
}
|
||
}
|
||
function initLocale(appVm) {
|
||
const locale = ref(normalizeLocale(wx.getSystemInfoSync().language) || LOCALE_EN);
|
||
Object.defineProperty(appVm, "$locale", {
|
||
get() {
|
||
return locale.value;
|
||
},
|
||
set(v) {
|
||
locale.value = v;
|
||
}
|
||
});
|
||
}
|
||
function initVueIds(vueIds, mpInstance) {
|
||
if (!vueIds) {
|
||
return;
|
||
}
|
||
const ids = vueIds.split(",");
|
||
const len = ids.length;
|
||
if (len === 1) {
|
||
mpInstance._$vueId = ids[0];
|
||
} else if (len === 2) {
|
||
mpInstance._$vueId = ids[0];
|
||
mpInstance._$vuePid = ids[1];
|
||
}
|
||
}
|
||
const EXTRAS = ["externalClasses"];
|
||
function initExtraOptions(miniProgramComponentOptions, vueOptions) {
|
||
EXTRAS.forEach((name2) => {
|
||
if (hasOwn(vueOptions, name2)) {
|
||
miniProgramComponentOptions[name2] = vueOptions[name2];
|
||
}
|
||
});
|
||
}
|
||
const WORKLET_RE = /_(.*)_worklet_factory_/;
|
||
function initWorkletMethods(mpMethods, vueMethods) {
|
||
if (vueMethods) {
|
||
Object.keys(vueMethods).forEach((name2) => {
|
||
const matches = name2.match(WORKLET_RE);
|
||
if (matches) {
|
||
const workletName = matches[1];
|
||
mpMethods[name2] = vueMethods[name2];
|
||
mpMethods[workletName] = vueMethods[workletName];
|
||
}
|
||
});
|
||
}
|
||
}
|
||
function initWxsCallMethods(methods, wxsCallMethods) {
|
||
if (!isArray$1(wxsCallMethods)) {
|
||
return;
|
||
}
|
||
wxsCallMethods.forEach((callMethod) => {
|
||
methods[callMethod] = function(args) {
|
||
return this.$vm[callMethod](args);
|
||
};
|
||
});
|
||
}
|
||
function selectAllComponents(mpInstance, selector, $refs) {
|
||
const components = mpInstance.selectAllComponents(selector);
|
||
components.forEach((component) => {
|
||
const ref2 = component.properties.uR;
|
||
$refs[ref2] = component.$vm || component;
|
||
});
|
||
}
|
||
function initRefs(instance, mpInstance) {
|
||
Object.defineProperty(instance, "refs", {
|
||
get() {
|
||
const $refs = {};
|
||
selectAllComponents(mpInstance, ".r", $refs);
|
||
const forComponents = mpInstance.selectAllComponents(".r-i-f");
|
||
forComponents.forEach((component) => {
|
||
const ref2 = component.properties.uR;
|
||
if (!ref2) {
|
||
return;
|
||
}
|
||
if (!$refs[ref2]) {
|
||
$refs[ref2] = [];
|
||
}
|
||
$refs[ref2].push(component.$vm || component);
|
||
});
|
||
return $refs;
|
||
}
|
||
});
|
||
}
|
||
function findVmByVueId(instance, vuePid) {
|
||
const $children = instance.$children;
|
||
for (let i = $children.length - 1; i >= 0; i--) {
|
||
const childVm = $children[i];
|
||
if (childVm.$scope._$vueId === vuePid) {
|
||
return childVm;
|
||
}
|
||
}
|
||
let parentVm;
|
||
for (let i = $children.length - 1; i >= 0; i--) {
|
||
parentVm = findVmByVueId($children[i], vuePid);
|
||
if (parentVm) {
|
||
return parentVm;
|
||
}
|
||
}
|
||
}
|
||
const builtInProps = [
|
||
// 百度小程序,快手小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
|
||
// event-opts
|
||
"eO",
|
||
// 组件 ref
|
||
"uR",
|
||
// 组件 ref-in-for
|
||
"uRIF",
|
||
// 组件 id
|
||
"uI",
|
||
// 组件类型 m: 小程序组件
|
||
"uT",
|
||
// 组件 props
|
||
"uP",
|
||
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
|
||
"uS"
|
||
];
|
||
function initDefaultProps(options, isBehavior = false) {
|
||
const properties = {};
|
||
if (!isBehavior) {
|
||
builtInProps.forEach((name2) => {
|
||
properties[name2] = {
|
||
type: null,
|
||
value: ""
|
||
};
|
||
});
|
||
properties.uS = {
|
||
type: null,
|
||
value: [],
|
||
observer: function(newVal) {
|
||
const $slots = /* @__PURE__ */ Object.create(null);
|
||
newVal && newVal.forEach((slotName) => {
|
||
$slots[slotName] = true;
|
||
});
|
||
this.setData({
|
||
$slots
|
||
});
|
||
}
|
||
};
|
||
}
|
||
if (options.behaviors) {
|
||
if (options.behaviors.includes("__GLOBAL__://form-field")) {
|
||
if (!options.properties || !options.properties.name) {
|
||
properties.name = {
|
||
type: null,
|
||
value: ""
|
||
};
|
||
}
|
||
if (!options.properties || !options.properties.value) {
|
||
properties.value = {
|
||
type: null,
|
||
value: ""
|
||
};
|
||
}
|
||
}
|
||
}
|
||
return properties;
|
||
}
|
||
function initVirtualHostProps(options) {
|
||
const properties = {};
|
||
{
|
||
if (options && options.virtualHost) {
|
||
properties.virtualHostStyle = {
|
||
type: null,
|
||
value: ""
|
||
};
|
||
properties.virtualHostClass = {
|
||
type: null,
|
||
value: ""
|
||
};
|
||
}
|
||
}
|
||
return properties;
|
||
}
|
||
function initProps(mpComponentOptions) {
|
||
if (!mpComponentOptions.properties) {
|
||
mpComponentOptions.properties = {};
|
||
}
|
||
extend(mpComponentOptions.properties, initDefaultProps(mpComponentOptions), initVirtualHostProps(mpComponentOptions.options));
|
||
}
|
||
const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
|
||
function parsePropType(type, defaultValue) {
|
||
if (isArray$1(type) && type.length === 1) {
|
||
return type[0];
|
||
}
|
||
return type;
|
||
}
|
||
function normalizePropType(type, defaultValue) {
|
||
const res = parsePropType(type);
|
||
return PROP_TYPES.indexOf(res) !== -1 ? res : null;
|
||
}
|
||
function initPageProps({ properties }, rawProps) {
|
||
if (isArray$1(rawProps)) {
|
||
rawProps.forEach((key) => {
|
||
properties[key] = {
|
||
type: String,
|
||
value: ""
|
||
};
|
||
});
|
||
} else if (isPlainObject$1(rawProps)) {
|
||
Object.keys(rawProps).forEach((key) => {
|
||
const opts = rawProps[key];
|
||
if (isPlainObject$1(opts)) {
|
||
let value = opts.default;
|
||
if (isFunction$1(value)) {
|
||
value = value();
|
||
}
|
||
const type = opts.type;
|
||
opts.type = normalizePropType(type);
|
||
properties[key] = {
|
||
type: opts.type,
|
||
value
|
||
};
|
||
} else {
|
||
properties[key] = {
|
||
type: normalizePropType(opts)
|
||
};
|
||
}
|
||
});
|
||
}
|
||
}
|
||
function findPropsData(properties, isPage2) {
|
||
return (isPage2 ? findPagePropsData(properties) : findComponentPropsData(properties.uP)) || {};
|
||
}
|
||
function findPagePropsData(properties) {
|
||
const propsData = {};
|
||
if (isPlainObject$1(properties)) {
|
||
Object.keys(properties).forEach((name2) => {
|
||
if (builtInProps.indexOf(name2) === -1) {
|
||
propsData[name2] = properties[name2];
|
||
}
|
||
});
|
||
}
|
||
return propsData;
|
||
}
|
||
function initFormField(vm) {
|
||
const vueOptions = vm.$options;
|
||
if (isArray$1(vueOptions.behaviors) && vueOptions.behaviors.includes("uni://form-field")) {
|
||
vm.$watch("modelValue", () => {
|
||
vm.$scope && vm.$scope.setData({
|
||
name: vm.name,
|
||
value: vm.modelValue
|
||
});
|
||
}, {
|
||
immediate: true
|
||
});
|
||
}
|
||
}
|
||
function initData(_) {
|
||
return {};
|
||
}
|
||
function initPropsObserver(componentOptions) {
|
||
const observe = function observe2() {
|
||
const up = this.properties.uP;
|
||
if (!up) {
|
||
return;
|
||
}
|
||
if (this.$vm) {
|
||
updateComponentProps(up, this.$vm.$);
|
||
} else if (this.properties.uT === "m") {
|
||
updateMiniProgramComponentProperties(up, this);
|
||
}
|
||
};
|
||
{
|
||
if (!componentOptions.observers) {
|
||
componentOptions.observers = {};
|
||
}
|
||
componentOptions.observers.uP = observe;
|
||
}
|
||
}
|
||
function updateMiniProgramComponentProperties(up, mpInstance) {
|
||
const prevProps = mpInstance.properties;
|
||
const nextProps = findComponentPropsData(up) || {};
|
||
if (hasPropsChanged(prevProps, nextProps, false)) {
|
||
mpInstance.setData(nextProps);
|
||
}
|
||
}
|
||
function updateComponentProps(up, instance) {
|
||
const prevProps = toRaw(instance.props);
|
||
const nextProps = findComponentPropsData(up) || {};
|
||
if (hasPropsChanged(prevProps, nextProps)) {
|
||
updateProps(instance, nextProps, prevProps, false);
|
||
if (hasQueueJob(instance.update)) {
|
||
invalidateJob(instance.update);
|
||
}
|
||
{
|
||
instance.update();
|
||
}
|
||
}
|
||
}
|
||
function hasPropsChanged(prevProps, nextProps, checkLen = true) {
|
||
const nextKeys = Object.keys(nextProps);
|
||
if (checkLen && nextKeys.length !== Object.keys(prevProps).length) {
|
||
return true;
|
||
}
|
||
for (let i = 0; i < nextKeys.length; i++) {
|
||
const key = nextKeys[i];
|
||
if (nextProps[key] !== prevProps[key]) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
function initBehaviors(vueOptions) {
|
||
const vueBehaviors = vueOptions.behaviors;
|
||
let vueProps = vueOptions.props;
|
||
if (!vueProps) {
|
||
vueOptions.props = vueProps = [];
|
||
}
|
||
const behaviors = [];
|
||
if (isArray$1(vueBehaviors)) {
|
||
vueBehaviors.forEach((behavior) => {
|
||
behaviors.push(behavior.replace("uni://", "__GLOBAL__://"));
|
||
if (behavior === "uni://form-field") {
|
||
if (isArray$1(vueProps)) {
|
||
vueProps.push("name");
|
||
vueProps.push("modelValue");
|
||
} else {
|
||
vueProps.name = {
|
||
type: String,
|
||
default: ""
|
||
};
|
||
vueProps.modelValue = {
|
||
type: [String, Number, Boolean, Array, Object, Date],
|
||
default: ""
|
||
};
|
||
}
|
||
}
|
||
});
|
||
}
|
||
return behaviors;
|
||
}
|
||
function applyOptions(componentOptions, vueOptions) {
|
||
componentOptions.data = initData();
|
||
componentOptions.behaviors = initBehaviors(vueOptions);
|
||
}
|
||
function parseComponent(vueOptions, { parse: parse2, mocks: mocks2, isPage: isPage2, initRelation: initRelation2, handleLink: handleLink2, initLifetimes: initLifetimes2 }) {
|
||
vueOptions = vueOptions.default || vueOptions;
|
||
const options = {
|
||
multipleSlots: true,
|
||
// styleIsolation: 'apply-shared',
|
||
addGlobalClass: true,
|
||
pureDataPattern: /^uP$/
|
||
};
|
||
if (isArray$1(vueOptions.mixins)) {
|
||
vueOptions.mixins.forEach((item) => {
|
||
if (isObject$1(item.options)) {
|
||
extend(options, item.options);
|
||
}
|
||
});
|
||
}
|
||
if (vueOptions.options) {
|
||
extend(options, vueOptions.options);
|
||
}
|
||
const mpComponentOptions = {
|
||
options,
|
||
lifetimes: initLifetimes2({ mocks: mocks2, isPage: isPage2, initRelation: initRelation2, vueOptions }),
|
||
pageLifetimes: {
|
||
show() {
|
||
this.$vm && this.$vm.$callHook("onPageShow");
|
||
},
|
||
hide() {
|
||
this.$vm && this.$vm.$callHook("onPageHide");
|
||
},
|
||
resize(size2) {
|
||
this.$vm && this.$vm.$callHook("onPageResize", size2);
|
||
}
|
||
},
|
||
methods: {
|
||
__l: handleLink2
|
||
}
|
||
};
|
||
{
|
||
applyOptions(mpComponentOptions, vueOptions);
|
||
}
|
||
initProps(mpComponentOptions);
|
||
initPropsObserver(mpComponentOptions);
|
||
initExtraOptions(mpComponentOptions, vueOptions);
|
||
initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
|
||
{
|
||
initWorkletMethods(mpComponentOptions.methods, vueOptions.methods);
|
||
}
|
||
if (parse2) {
|
||
parse2(mpComponentOptions, { handleLink: handleLink2 });
|
||
}
|
||
return mpComponentOptions;
|
||
}
|
||
function initCreateComponent(parseOptions2) {
|
||
return function createComponent2(vueComponentOptions) {
|
||
return Component(parseComponent(vueComponentOptions, parseOptions2));
|
||
};
|
||
}
|
||
let $createComponentFn;
|
||
let $destroyComponentFn;
|
||
function getAppVm() {
|
||
return getApp().$vm;
|
||
}
|
||
function $createComponent(initialVNode, options) {
|
||
if (!$createComponentFn) {
|
||
$createComponentFn = getAppVm().$createComponent;
|
||
}
|
||
const proxy = $createComponentFn(initialVNode, options);
|
||
return getExposeProxy(proxy.$) || proxy;
|
||
}
|
||
function $destroyComponent(instance) {
|
||
if (!$destroyComponentFn) {
|
||
$destroyComponentFn = getAppVm().$destroyComponent;
|
||
}
|
||
return $destroyComponentFn(instance);
|
||
}
|
||
function parsePage(vueOptions, parseOptions2) {
|
||
const { parse: parse2, mocks: mocks2, isPage: isPage2, initRelation: initRelation2, handleLink: handleLink2, initLifetimes: initLifetimes2 } = parseOptions2;
|
||
const miniProgramPageOptions = parseComponent(vueOptions, {
|
||
mocks: mocks2,
|
||
isPage: isPage2,
|
||
initRelation: initRelation2,
|
||
handleLink: handleLink2,
|
||
initLifetimes: initLifetimes2
|
||
});
|
||
initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
|
||
const methods = miniProgramPageOptions.methods;
|
||
methods.onLoad = function(query) {
|
||
this.options = query;
|
||
this.$page = {
|
||
fullPath: addLeadingSlash(this.route + stringifyQuery(query))
|
||
};
|
||
return this.$vm && this.$vm.$callHook(ON_LOAD, query);
|
||
};
|
||
initHooks(methods, PAGE_INIT_HOOKS);
|
||
{
|
||
initUnknownHooks(methods, vueOptions);
|
||
}
|
||
initRuntimeHooks(methods, vueOptions.__runtimeHooks);
|
||
initMixinRuntimeHooks(methods);
|
||
parse2 && parse2(miniProgramPageOptions, { handleLink: handleLink2 });
|
||
return miniProgramPageOptions;
|
||
}
|
||
function initCreatePage(parseOptions2) {
|
||
return function createPage2(vuePageOptions) {
|
||
return Component(parsePage(vuePageOptions, parseOptions2));
|
||
};
|
||
}
|
||
function initCreatePluginApp(parseAppOptions) {
|
||
return function createApp2(vm) {
|
||
initAppLifecycle(parseApp(vm, parseAppOptions), vm);
|
||
};
|
||
}
|
||
const MPPage = Page;
|
||
const MPComponent = Component;
|
||
function initTriggerEvent(mpInstance) {
|
||
const oldTriggerEvent = mpInstance.triggerEvent;
|
||
const newTriggerEvent = function(event, ...args) {
|
||
return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
|
||
};
|
||
try {
|
||
mpInstance.triggerEvent = newTriggerEvent;
|
||
} catch (error) {
|
||
mpInstance._triggerEvent = newTriggerEvent;
|
||
}
|
||
}
|
||
function initMiniProgramHook(name2, options, isComponent) {
|
||
const oldHook = options[name2];
|
||
if (!oldHook) {
|
||
options[name2] = function() {
|
||
initTriggerEvent(this);
|
||
};
|
||
} else {
|
||
options[name2] = function(...args) {
|
||
initTriggerEvent(this);
|
||
return oldHook.apply(this, args);
|
||
};
|
||
}
|
||
}
|
||
Page = function(options) {
|
||
initMiniProgramHook(ON_LOAD, options);
|
||
return MPPage(options);
|
||
};
|
||
Component = function(options) {
|
||
initMiniProgramHook("created", options);
|
||
const isVueComponent = options.properties && options.properties.uP;
|
||
if (!isVueComponent) {
|
||
initProps(options);
|
||
initPropsObserver(options);
|
||
}
|
||
return MPComponent(options);
|
||
};
|
||
function initLifetimes({ mocks: mocks2, isPage: isPage2, initRelation: initRelation2, vueOptions }) {
|
||
return {
|
||
attached() {
|
||
let properties = this.properties;
|
||
initVueIds(properties.uI, this);
|
||
const relationOptions = {
|
||
vuePid: this._$vuePid
|
||
};
|
||
initRelation2(this, relationOptions);
|
||
const mpInstance = this;
|
||
const isMiniProgramPage = isPage2(mpInstance);
|
||
let propsData = properties;
|
||
this.$vm = $createComponent({
|
||
type: vueOptions,
|
||
props: findPropsData(propsData, isMiniProgramPage)
|
||
}, {
|
||
mpType: isMiniProgramPage ? "page" : "component",
|
||
mpInstance,
|
||
slots: properties.uS || {},
|
||
// vueSlots
|
||
parentComponent: relationOptions.parent && relationOptions.parent.$,
|
||
onBeforeSetup(instance, options) {
|
||
initRefs(instance, mpInstance);
|
||
initMocks(instance, mpInstance, mocks2);
|
||
initComponentInstance(instance, options);
|
||
}
|
||
});
|
||
if (!isMiniProgramPage) {
|
||
initFormField(this.$vm);
|
||
}
|
||
},
|
||
ready() {
|
||
if (this.$vm) {
|
||
{
|
||
this.$vm.$callHook("mounted");
|
||
this.$vm.$callHook(ON_READY);
|
||
}
|
||
}
|
||
},
|
||
detached() {
|
||
if (this.$vm) {
|
||
pruneComponentPropsCache(this.$vm.$.uid);
|
||
$destroyComponent(this.$vm);
|
||
}
|
||
}
|
||
};
|
||
}
|
||
const mocks = ["__route__", "__wxExparserNodeId__", "__wxWebviewId__"];
|
||
function isPage(mpInstance) {
|
||
return !!mpInstance.route;
|
||
}
|
||
function initRelation(mpInstance, detail) {
|
||
mpInstance.triggerEvent("__l", detail);
|
||
}
|
||
function handleLink(event) {
|
||
const detail = event.detail || event.value;
|
||
const vuePid = detail.vuePid;
|
||
let parentVm;
|
||
if (vuePid) {
|
||
parentVm = findVmByVueId(this.$vm, vuePid);
|
||
}
|
||
if (!parentVm) {
|
||
parentVm = this.$vm;
|
||
}
|
||
detail.parent = parentVm;
|
||
}
|
||
var parseOptions = /* @__PURE__ */ Object.freeze({
|
||
__proto__: null,
|
||
handleLink,
|
||
initLifetimes,
|
||
initRelation,
|
||
isPage,
|
||
mocks
|
||
});
|
||
const createApp = initCreateApp();
|
||
const createPage = initCreatePage(parseOptions);
|
||
const createComponent = initCreateComponent(parseOptions);
|
||
const createPluginApp = initCreatePluginApp();
|
||
const createSubpackageApp = initCreateSubpackageApp();
|
||
{
|
||
wx.createApp = global.createApp = createApp;
|
||
wx.createPage = createPage;
|
||
wx.createComponent = createComponent;
|
||
wx.createPluginApp = global.createPluginApp = createPluginApp;
|
||
wx.createSubpackageApp = global.createSubpackageApp = createSubpackageApp;
|
||
}
|
||
var isVue2 = false;
|
||
/*!
|
||
* pinia v2.1.7
|
||
* (c) 2023 Eduardo San Martin Morote
|
||
* @license MIT
|
||
*/
|
||
const piniaSymbol = Symbol("pinia");
|
||
var MutationType;
|
||
(function(MutationType2) {
|
||
MutationType2["direct"] = "direct";
|
||
MutationType2["patchObject"] = "patch object";
|
||
MutationType2["patchFunction"] = "patch function";
|
||
})(MutationType || (MutationType = {}));
|
||
const IS_CLIENT = typeof window !== "undefined";
|
||
const USE_DEVTOOLS = IS_CLIENT;
|
||
const componentStateTypes = [];
|
||
const getStoreType = (id) => "🍍 " + id;
|
||
function addStoreToDevtools(app, store) {
|
||
if (!componentStateTypes.includes(getStoreType(store.$id))) {
|
||
componentStateTypes.push(getStoreType(store.$id));
|
||
}
|
||
}
|
||
function patchActionForGrouping(store, actionNames, wrapWithProxy) {
|
||
const actions = actionNames.reduce((storeActions, actionName) => {
|
||
storeActions[actionName] = toRaw(store)[actionName];
|
||
return storeActions;
|
||
}, {});
|
||
for (const actionName in actions) {
|
||
store[actionName] = function() {
|
||
const trackedStore = wrapWithProxy ? new Proxy(store, {
|
||
get(...args) {
|
||
return Reflect.get(...args);
|
||
},
|
||
set(...args) {
|
||
return Reflect.set(...args);
|
||
}
|
||
}) : store;
|
||
const retValue = actions[actionName].apply(trackedStore, arguments);
|
||
return retValue;
|
||
};
|
||
}
|
||
}
|
||
function devtoolsPlugin({ app, store, options }) {
|
||
if (store.$id.startsWith("__hot:")) {
|
||
return;
|
||
}
|
||
store._isOptionsAPI = !!options.state;
|
||
patchActionForGrouping(store, Object.keys(options.actions), store._isOptionsAPI);
|
||
const originalHotUpdate = store._hotUpdate;
|
||
toRaw(store)._hotUpdate = function(newStore) {
|
||
originalHotUpdate.apply(this, arguments);
|
||
patchActionForGrouping(store, Object.keys(newStore._hmrPayload.actions), !!store._isOptionsAPI);
|
||
};
|
||
addStoreToDevtools(
|
||
app,
|
||
// FIXME: is there a way to allow the assignment from Store<Id, S, G, A> to StoreGeneric?
|
||
store
|
||
);
|
||
}
|
||
function createPinia() {
|
||
const scope = effectScope(true);
|
||
const state = scope.run(() => ref({}));
|
||
let _p = [];
|
||
let toBeInstalled = [];
|
||
const pinia = markRaw({
|
||
install(app) {
|
||
{
|
||
pinia._a = app;
|
||
app.provide(piniaSymbol, pinia);
|
||
app.config.globalProperties.$pinia = pinia;
|
||
toBeInstalled.forEach((plugin2) => _p.push(plugin2));
|
||
toBeInstalled = [];
|
||
}
|
||
},
|
||
use(plugin2) {
|
||
if (!this._a && !isVue2) {
|
||
toBeInstalled.push(plugin2);
|
||
} else {
|
||
_p.push(plugin2);
|
||
}
|
||
return this;
|
||
},
|
||
_p,
|
||
// it's actually undefined here
|
||
// @ts-expect-error
|
||
_a: null,
|
||
_e: scope,
|
||
_s: /* @__PURE__ */ new Map(),
|
||
state
|
||
});
|
||
if (USE_DEVTOOLS && typeof Proxy !== "undefined") {
|
||
pinia.use(devtoolsPlugin);
|
||
}
|
||
return pinia;
|
||
}
|
||
const createHook = (lifecycle) => (hook, target = getCurrentInstance()) => {
|
||
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
|
||
};
|
||
const onShow = /* @__PURE__ */ createHook(ON_SHOW);
|
||
const onLaunch = /* @__PURE__ */ createHook(ON_LAUNCH);
|
||
const onLoad = /* @__PURE__ */ createHook(ON_LOAD);
|
||
const onPullDownRefresh = /* @__PURE__ */ createHook(ON_PULL_DOWN_REFRESH);
|
||
function _extends() {
|
||
return _extends = Object.assign ? Object.assign.bind() : function(n2) {
|
||
for (var e2 = 1; e2 < arguments.length; e2++) {
|
||
var t2 = arguments[e2];
|
||
for (var r in t2)
|
||
({}).hasOwnProperty.call(t2, r) && (n2[r] = t2[r]);
|
||
}
|
||
return n2;
|
||
}, _extends.apply(null, arguments);
|
||
}
|
||
var DEFAULT_CONFIG = {
|
||
// minimum relative difference between two compared values,
|
||
// used by all comparison functions
|
||
relTol: 1e-12,
|
||
// minimum absolute difference between two compared values,
|
||
// used by all comparison functions
|
||
absTol: 1e-15,
|
||
// type of default matrix output. Choose 'matrix' (default) or 'array'
|
||
matrix: "Matrix",
|
||
// type of default number output. Choose 'number' (default) 'BigNumber', 'bigint', or 'Fraction'
|
||
number: "number",
|
||
// type of fallback used for config { number: 'bigint' } when a value cannot be represented
|
||
// in the configured numeric type. Choose 'number' (default) or 'BigNumber'.
|
||
numberFallback: "number",
|
||
// number of significant digits in BigNumbers
|
||
precision: 64,
|
||
// predictable output type of functions. When true, output type depends only
|
||
// on the input types. When false (default), output type can vary depending
|
||
// on input values. For example `math.sqrt(-4)` returns `complex('2i')` when
|
||
// predictable is false, and returns `NaN` when true.
|
||
predictable: false,
|
||
// random seed for seeded pseudo random number generation
|
||
// null = randomly seed
|
||
randomSeed: null
|
||
};
|
||
function getSafeProperty(object, prop) {
|
||
if (isSafeProperty(object, prop)) {
|
||
return object[prop];
|
||
}
|
||
if (typeof object[prop] === "function" && isSafeMethod(object, prop)) {
|
||
throw new Error('Cannot access method "' + prop + '" as a property');
|
||
}
|
||
throw new Error('No access to property "' + prop + '"');
|
||
}
|
||
function setSafeProperty(object, prop, value) {
|
||
if (isSafeProperty(object, prop)) {
|
||
object[prop] = value;
|
||
return value;
|
||
}
|
||
throw new Error('No access to property "' + prop + '"');
|
||
}
|
||
function isSafeProperty(object, prop) {
|
||
if (!isPlainObject(object) && !Array.isArray(object)) {
|
||
return false;
|
||
}
|
||
if (hasOwnProperty(safeNativeProperties, prop)) {
|
||
return true;
|
||
}
|
||
if (prop in Object.prototype) {
|
||
return false;
|
||
}
|
||
if (prop in Function.prototype) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function isSafeMethod(object, method) {
|
||
if (object === null || object === void 0 || typeof object[method] !== "function") {
|
||
return false;
|
||
}
|
||
if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
|
||
return false;
|
||
}
|
||
if (hasOwnProperty(safeNativeMethods, method)) {
|
||
return true;
|
||
}
|
||
if (method in Object.prototype) {
|
||
return false;
|
||
}
|
||
if (method in Function.prototype) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function isPlainObject(object) {
|
||
return typeof object === "object" && object && object.constructor === Object;
|
||
}
|
||
var safeNativeProperties = {
|
||
length: true,
|
||
name: true
|
||
};
|
||
var safeNativeMethods = {
|
||
toString: true,
|
||
valueOf: true,
|
||
toLocaleString: true
|
||
};
|
||
class ObjectWrappingMap {
|
||
constructor(object) {
|
||
this.wrappedObject = object;
|
||
this[Symbol.iterator] = this.entries;
|
||
}
|
||
keys() {
|
||
return Object.keys(this.wrappedObject).filter((key) => this.has(key)).values();
|
||
}
|
||
get(key) {
|
||
return getSafeProperty(this.wrappedObject, key);
|
||
}
|
||
set(key, value) {
|
||
setSafeProperty(this.wrappedObject, key, value);
|
||
return this;
|
||
}
|
||
has(key) {
|
||
return isSafeProperty(this.wrappedObject, key) && key in this.wrappedObject;
|
||
}
|
||
entries() {
|
||
return mapIterator(this.keys(), (key) => [key, this.get(key)]);
|
||
}
|
||
forEach(callback) {
|
||
for (var key of this.keys()) {
|
||
callback(this.get(key), key, this);
|
||
}
|
||
}
|
||
delete(key) {
|
||
if (isSafeProperty(this.wrappedObject, key)) {
|
||
delete this.wrappedObject[key];
|
||
}
|
||
}
|
||
clear() {
|
||
for (var key of this.keys()) {
|
||
this.delete(key);
|
||
}
|
||
}
|
||
get size() {
|
||
return Object.keys(this.wrappedObject).length;
|
||
}
|
||
}
|
||
function mapIterator(it, callback) {
|
||
return {
|
||
next: () => {
|
||
var n2 = it.next();
|
||
return n2.done ? n2 : {
|
||
value: callback(n2.value),
|
||
done: false
|
||
};
|
||
}
|
||
};
|
||
}
|
||
function isNumber(x) {
|
||
return typeof x === "number";
|
||
}
|
||
function isBigNumber(x) {
|
||
if (!x || typeof x !== "object" || typeof x.constructor !== "function") {
|
||
return false;
|
||
}
|
||
if (x.isBigNumber === true && typeof x.constructor.prototype === "object" && x.constructor.prototype.isBigNumber === true) {
|
||
return true;
|
||
}
|
||
if (typeof x.constructor.isDecimal === "function" && x.constructor.isDecimal(x) === true) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function isBigInt(x) {
|
||
return typeof x === "bigint";
|
||
}
|
||
function isComplex(x) {
|
||
return x && typeof x === "object" && Object.getPrototypeOf(x).isComplex === true || false;
|
||
}
|
||
function isFraction(x) {
|
||
return x && typeof x === "object" && Object.getPrototypeOf(x).isFraction === true || false;
|
||
}
|
||
function isUnit(x) {
|
||
return x && x.constructor.prototype.isUnit === true || false;
|
||
}
|
||
function isString(x) {
|
||
return typeof x === "string";
|
||
}
|
||
var isArray = Array.isArray;
|
||
function isMatrix(x) {
|
||
return x && x.constructor.prototype.isMatrix === true || false;
|
||
}
|
||
function isCollection(x) {
|
||
return Array.isArray(x) || isMatrix(x);
|
||
}
|
||
function isDenseMatrix(x) {
|
||
return x && x.isDenseMatrix && x.constructor.prototype.isMatrix === true || false;
|
||
}
|
||
function isSparseMatrix(x) {
|
||
return x && x.isSparseMatrix && x.constructor.prototype.isMatrix === true || false;
|
||
}
|
||
function isRange(x) {
|
||
return x && x.constructor.prototype.isRange === true || false;
|
||
}
|
||
function isIndex(x) {
|
||
return x && x.constructor.prototype.isIndex === true || false;
|
||
}
|
||
function isBoolean(x) {
|
||
return typeof x === "boolean";
|
||
}
|
||
function isResultSet(x) {
|
||
return x && x.constructor.prototype.isResultSet === true || false;
|
||
}
|
||
function isHelp(x) {
|
||
return x && x.constructor.prototype.isHelp === true || false;
|
||
}
|
||
function isFunction(x) {
|
||
return typeof x === "function";
|
||
}
|
||
function isDate(x) {
|
||
return x instanceof Date;
|
||
}
|
||
function isRegExp(x) {
|
||
return x instanceof RegExp;
|
||
}
|
||
function isObject(x) {
|
||
return !!(x && typeof x === "object" && x.constructor === Object && !isComplex(x) && !isFraction(x));
|
||
}
|
||
function isMap(object) {
|
||
if (!object) {
|
||
return false;
|
||
}
|
||
return object instanceof Map || object instanceof ObjectWrappingMap || typeof object.set === "function" && typeof object.get === "function" && typeof object.keys === "function" && typeof object.has === "function";
|
||
}
|
||
function isNull(x) {
|
||
return x === null;
|
||
}
|
||
function isUndefined(x) {
|
||
return x === void 0;
|
||
}
|
||
function isAccessorNode(x) {
|
||
return x && x.isAccessorNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isArrayNode(x) {
|
||
return x && x.isArrayNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isAssignmentNode(x) {
|
||
return x && x.isAssignmentNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isBlockNode(x) {
|
||
return x && x.isBlockNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isConditionalNode(x) {
|
||
return x && x.isConditionalNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isConstantNode(x) {
|
||
return x && x.isConstantNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isFunctionAssignmentNode(x) {
|
||
return x && x.isFunctionAssignmentNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isFunctionNode(x) {
|
||
return x && x.isFunctionNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isIndexNode(x) {
|
||
return x && x.isIndexNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isNode(x) {
|
||
return x && x.isNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isObjectNode(x) {
|
||
return x && x.isObjectNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isOperatorNode(x) {
|
||
return x && x.isOperatorNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isParenthesisNode(x) {
|
||
return x && x.isParenthesisNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isRangeNode(x) {
|
||
return x && x.isRangeNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isRelationalNode(x) {
|
||
return x && x.isRelationalNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isSymbolNode(x) {
|
||
return x && x.isSymbolNode === true && x.constructor.prototype.isNode === true || false;
|
||
}
|
||
function isChain(x) {
|
||
return x && x.constructor.prototype.isChain === true || false;
|
||
}
|
||
function typeOf(x) {
|
||
var t2 = typeof x;
|
||
if (t2 === "object") {
|
||
if (x === null)
|
||
return "null";
|
||
if (isBigNumber(x))
|
||
return "BigNumber";
|
||
if (x.constructor && x.constructor.name)
|
||
return x.constructor.name;
|
||
return "Object";
|
||
}
|
||
return t2;
|
||
}
|
||
function clone$2(x) {
|
||
var type = typeof x;
|
||
if (type === "number" || type === "bigint" || type === "string" || type === "boolean" || x === null || x === void 0) {
|
||
return x;
|
||
}
|
||
if (typeof x.clone === "function") {
|
||
return x.clone();
|
||
}
|
||
if (Array.isArray(x)) {
|
||
return x.map(function(value) {
|
||
return clone$2(value);
|
||
});
|
||
}
|
||
if (x instanceof Date)
|
||
return new Date(x.valueOf());
|
||
if (isBigNumber(x))
|
||
return x;
|
||
if (isObject(x)) {
|
||
return mapObject(x, clone$2);
|
||
}
|
||
if (type === "function") {
|
||
return x;
|
||
}
|
||
throw new TypeError("Cannot clone: unknown type of value (value: ".concat(x, ")"));
|
||
}
|
||
function mapObject(object, callback) {
|
||
var clone2 = {};
|
||
for (var key in object) {
|
||
if (hasOwnProperty(object, key)) {
|
||
clone2[key] = callback(object[key]);
|
||
}
|
||
}
|
||
return clone2;
|
||
}
|
||
function deepStrictEqual(a, b) {
|
||
var prop, i, len;
|
||
if (Array.isArray(a)) {
|
||
if (!Array.isArray(b)) {
|
||
return false;
|
||
}
|
||
if (a.length !== b.length) {
|
||
return false;
|
||
}
|
||
for (i = 0, len = a.length; i < len; i++) {
|
||
if (!deepStrictEqual(a[i], b[i])) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
} else if (typeof a === "function") {
|
||
return a === b;
|
||
} else if (a instanceof Object) {
|
||
if (Array.isArray(b) || !(b instanceof Object)) {
|
||
return false;
|
||
}
|
||
for (prop in a) {
|
||
if (!(prop in b) || !deepStrictEqual(a[prop], b[prop])) {
|
||
return false;
|
||
}
|
||
}
|
||
for (prop in b) {
|
||
if (!(prop in a)) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
} else {
|
||
return a === b;
|
||
}
|
||
}
|
||
function hasOwnProperty(object, property) {
|
||
return object && Object.hasOwnProperty.call(object, property);
|
||
}
|
||
function pickShallow(object, properties) {
|
||
var copy = {};
|
||
for (var i = 0; i < properties.length; i++) {
|
||
var key = properties[i];
|
||
var value = object[key];
|
||
if (value !== void 0) {
|
||
copy[key] = value;
|
||
}
|
||
}
|
||
return copy;
|
||
}
|
||
var MATRIX_OPTIONS = ["Matrix", "Array"];
|
||
var NUMBER_OPTIONS = ["number", "BigNumber", "Fraction"];
|
||
var config$1 = function config(options) {
|
||
if (options) {
|
||
throw new Error("The global config is readonly. \nPlease create a mathjs instance if you want to change the default configuration. \nExample:\n\n import { create, all } from 'mathjs';\n const mathjs = create(all);\n mathjs.config({ number: 'BigNumber' });\n");
|
||
}
|
||
return Object.freeze(DEFAULT_CONFIG);
|
||
};
|
||
_extends(config$1, DEFAULT_CONFIG, {
|
||
MATRIX_OPTIONS,
|
||
NUMBER_OPTIONS
|
||
});
|
||
function ok() {
|
||
return true;
|
||
}
|
||
function notOk() {
|
||
return false;
|
||
}
|
||
function undef() {
|
||
return void 0;
|
||
}
|
||
const NOT_TYPED_FUNCTION = "Argument is not a typed-function.";
|
||
function create() {
|
||
function isPlainObject2(x) {
|
||
return typeof x === "object" && x !== null && x.constructor === Object;
|
||
}
|
||
const _types = [{
|
||
name: "number",
|
||
test: function(x) {
|
||
return typeof x === "number";
|
||
}
|
||
}, {
|
||
name: "string",
|
||
test: function(x) {
|
||
return typeof x === "string";
|
||
}
|
||
}, {
|
||
name: "boolean",
|
||
test: function(x) {
|
||
return typeof x === "boolean";
|
||
}
|
||
}, {
|
||
name: "Function",
|
||
test: function(x) {
|
||
return typeof x === "function";
|
||
}
|
||
}, {
|
||
name: "Array",
|
||
test: Array.isArray
|
||
}, {
|
||
name: "Date",
|
||
test: function(x) {
|
||
return x instanceof Date;
|
||
}
|
||
}, {
|
||
name: "RegExp",
|
||
test: function(x) {
|
||
return x instanceof RegExp;
|
||
}
|
||
}, {
|
||
name: "Object",
|
||
test: isPlainObject2
|
||
}, {
|
||
name: "null",
|
||
test: function(x) {
|
||
return x === null;
|
||
}
|
||
}, {
|
||
name: "undefined",
|
||
test: function(x) {
|
||
return x === void 0;
|
||
}
|
||
}];
|
||
const anyType = {
|
||
name: "any",
|
||
test: ok,
|
||
isAny: true
|
||
};
|
||
let typeMap;
|
||
let typeList;
|
||
let nConversions = 0;
|
||
let typed2 = {
|
||
createCount: 0
|
||
};
|
||
function findType(typeName) {
|
||
const type = typeMap.get(typeName);
|
||
if (type) {
|
||
return type;
|
||
}
|
||
let message = 'Unknown type "' + typeName + '"';
|
||
const name2 = typeName.toLowerCase();
|
||
let otherName;
|
||
for (otherName of typeList) {
|
||
if (otherName.toLowerCase() === name2) {
|
||
message += '. Did you mean "' + otherName + '" ?';
|
||
break;
|
||
}
|
||
}
|
||
throw new TypeError(message);
|
||
}
|
||
function addTypes(types) {
|
||
let beforeSpec = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "any";
|
||
const beforeIndex = beforeSpec ? findType(beforeSpec).index : typeList.length;
|
||
const newTypes = [];
|
||
for (let i = 0; i < types.length; ++i) {
|
||
if (!types[i] || typeof types[i].name !== "string" || typeof types[i].test !== "function") {
|
||
throw new TypeError("Object with properties {name: string, test: function} expected");
|
||
}
|
||
const typeName = types[i].name;
|
||
if (typeMap.has(typeName)) {
|
||
throw new TypeError('Duplicate type name "' + typeName + '"');
|
||
}
|
||
newTypes.push(typeName);
|
||
typeMap.set(typeName, {
|
||
name: typeName,
|
||
test: types[i].test,
|
||
isAny: types[i].isAny,
|
||
index: beforeIndex + i,
|
||
conversionsTo: []
|
||
// Newly added type can't have any conversions to it
|
||
});
|
||
}
|
||
const affectedTypes = typeList.slice(beforeIndex);
|
||
typeList = typeList.slice(0, beforeIndex).concat(newTypes).concat(affectedTypes);
|
||
for (let i = beforeIndex + newTypes.length; i < typeList.length; ++i) {
|
||
typeMap.get(typeList[i]).index = i;
|
||
}
|
||
}
|
||
function clear2() {
|
||
typeMap = /* @__PURE__ */ new Map();
|
||
typeList = [];
|
||
nConversions = 0;
|
||
addTypes([anyType], false);
|
||
}
|
||
clear2();
|
||
addTypes(_types);
|
||
function clearConversions() {
|
||
let typeName;
|
||
for (typeName of typeList) {
|
||
typeMap.get(typeName).conversionsTo = [];
|
||
}
|
||
nConversions = 0;
|
||
}
|
||
function findTypeNames(value) {
|
||
const matches = typeList.filter((name2) => {
|
||
const type = typeMap.get(name2);
|
||
return !type.isAny && type.test(value);
|
||
});
|
||
if (matches.length) {
|
||
return matches;
|
||
}
|
||
return ["any"];
|
||
}
|
||
function isTypedFunction(entity) {
|
||
return entity && typeof entity === "function" && "_typedFunctionData" in entity;
|
||
}
|
||
function findSignature(fn, signature, options) {
|
||
if (!isTypedFunction(fn)) {
|
||
throw new TypeError(NOT_TYPED_FUNCTION);
|
||
}
|
||
const exact = options && options.exact;
|
||
const stringSignature = Array.isArray(signature) ? signature.join(",") : signature;
|
||
const params = parseSignature(stringSignature);
|
||
const canonicalSignature = stringifyParams(params);
|
||
if (!exact || canonicalSignature in fn.signatures) {
|
||
const match = fn._typedFunctionData.signatureMap.get(canonicalSignature);
|
||
if (match) {
|
||
return match;
|
||
}
|
||
}
|
||
const nParams = params.length;
|
||
let remainingSignatures;
|
||
if (exact) {
|
||
remainingSignatures = [];
|
||
let name2;
|
||
for (name2 in fn.signatures) {
|
||
remainingSignatures.push(fn._typedFunctionData.signatureMap.get(name2));
|
||
}
|
||
} else {
|
||
remainingSignatures = fn._typedFunctionData.signatures;
|
||
}
|
||
for (let i = 0; i < nParams; ++i) {
|
||
const want = params[i];
|
||
const filteredSignatures = [];
|
||
let possibility;
|
||
for (possibility of remainingSignatures) {
|
||
const have = getParamAtIndex(possibility.params, i);
|
||
if (!have || want.restParam && !have.restParam) {
|
||
continue;
|
||
}
|
||
if (!have.hasAny) {
|
||
const haveTypes = paramTypeSet(have);
|
||
if (want.types.some((wtype) => !haveTypes.has(wtype.name))) {
|
||
continue;
|
||
}
|
||
}
|
||
filteredSignatures.push(possibility);
|
||
}
|
||
remainingSignatures = filteredSignatures;
|
||
if (remainingSignatures.length === 0)
|
||
break;
|
||
}
|
||
let candidate;
|
||
for (candidate of remainingSignatures) {
|
||
if (candidate.params.length <= nParams) {
|
||
return candidate;
|
||
}
|
||
}
|
||
throw new TypeError("Signature not found (signature: " + (fn.name || "unnamed") + "(" + stringifyParams(params, ", ") + "))");
|
||
}
|
||
function find(fn, signature, options) {
|
||
return findSignature(fn, signature, options).implementation;
|
||
}
|
||
function convert(value, typeName) {
|
||
const type = findType(typeName);
|
||
if (type.test(value)) {
|
||
return value;
|
||
}
|
||
const conversions = type.conversionsTo;
|
||
if (conversions.length === 0) {
|
||
throw new Error("There are no conversions to " + typeName + " defined.");
|
||
}
|
||
for (let i = 0; i < conversions.length; i++) {
|
||
const fromType = findType(conversions[i].from);
|
||
if (fromType.test(value)) {
|
||
return conversions[i].convert(value);
|
||
}
|
||
}
|
||
throw new Error("Cannot convert " + value + " to " + typeName);
|
||
}
|
||
function stringifyParams(params) {
|
||
let separator = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ",";
|
||
return params.map((p2) => p2.name).join(separator);
|
||
}
|
||
function parseParam(param) {
|
||
const restParam = param.indexOf("...") === 0;
|
||
const types = !restParam ? param : param.length > 3 ? param.slice(3) : "any";
|
||
const typeDefs = types.split("|").map((s2) => findType(s2.trim()));
|
||
let hasAny = false;
|
||
let paramName = restParam ? "..." : "";
|
||
const exactTypes = typeDefs.map(function(type) {
|
||
hasAny = type.isAny || hasAny;
|
||
paramName += type.name + "|";
|
||
return {
|
||
name: type.name,
|
||
typeIndex: type.index,
|
||
test: type.test,
|
||
isAny: type.isAny,
|
||
conversion: null,
|
||
conversionIndex: -1
|
||
};
|
||
});
|
||
return {
|
||
types: exactTypes,
|
||
name: paramName.slice(0, -1),
|
||
// remove trailing '|' from above
|
||
hasAny,
|
||
hasConversion: false,
|
||
restParam
|
||
};
|
||
}
|
||
function expandParam(param) {
|
||
const typeNames = param.types.map((t2) => t2.name);
|
||
const matchingConversions = availableConversions(typeNames);
|
||
let hasAny = param.hasAny;
|
||
let newName = param.name;
|
||
const convertibleTypes = matchingConversions.map(function(conversion) {
|
||
const type = findType(conversion.from);
|
||
hasAny = type.isAny || hasAny;
|
||
newName += "|" + conversion.from;
|
||
return {
|
||
name: conversion.from,
|
||
typeIndex: type.index,
|
||
test: type.test,
|
||
isAny: type.isAny,
|
||
conversion,
|
||
conversionIndex: conversion.index
|
||
};
|
||
});
|
||
return {
|
||
types: param.types.concat(convertibleTypes),
|
||
name: newName,
|
||
hasAny,
|
||
hasConversion: convertibleTypes.length > 0,
|
||
restParam: param.restParam
|
||
};
|
||
}
|
||
function paramTypeSet(param) {
|
||
if (!param.typeSet) {
|
||
param.typeSet = /* @__PURE__ */ new Set();
|
||
param.types.forEach((type) => param.typeSet.add(type.name));
|
||
}
|
||
return param.typeSet;
|
||
}
|
||
function parseSignature(rawSignature) {
|
||
const params = [];
|
||
if (typeof rawSignature !== "string") {
|
||
throw new TypeError("Signatures must be strings");
|
||
}
|
||
const signature = rawSignature.trim();
|
||
if (signature === "") {
|
||
return params;
|
||
}
|
||
const rawParams = signature.split(",");
|
||
for (let i = 0; i < rawParams.length; ++i) {
|
||
const parsedParam = parseParam(rawParams[i].trim());
|
||
if (parsedParam.restParam && i !== rawParams.length - 1) {
|
||
throw new SyntaxError('Unexpected rest parameter "' + rawParams[i] + '": only allowed for the last parameter');
|
||
}
|
||
if (parsedParam.types.length === 0) {
|
||
return null;
|
||
}
|
||
params.push(parsedParam);
|
||
}
|
||
return params;
|
||
}
|
||
function hasRestParam(params) {
|
||
const param = last(params);
|
||
return param ? param.restParam : false;
|
||
}
|
||
function compileTest(param) {
|
||
if (!param || param.types.length === 0) {
|
||
return ok;
|
||
} else if (param.types.length === 1) {
|
||
return findType(param.types[0].name).test;
|
||
} else if (param.types.length === 2) {
|
||
const test0 = findType(param.types[0].name).test;
|
||
const test1 = findType(param.types[1].name).test;
|
||
return function or(x) {
|
||
return test0(x) || test1(x);
|
||
};
|
||
} else {
|
||
const tests = param.types.map(function(type) {
|
||
return findType(type.name).test;
|
||
});
|
||
return function or(x) {
|
||
for (let i = 0; i < tests.length; i++) {
|
||
if (tests[i](x)) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
};
|
||
}
|
||
}
|
||
function compileTests(params) {
|
||
let tests, test0, test1;
|
||
if (hasRestParam(params)) {
|
||
tests = initial(params).map(compileTest);
|
||
const varIndex = tests.length;
|
||
const lastTest = compileTest(last(params));
|
||
const testRestParam = function(args) {
|
||
for (let i = varIndex; i < args.length; i++) {
|
||
if (!lastTest(args[i])) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
};
|
||
return function testArgs(args) {
|
||
for (let i = 0; i < tests.length; i++) {
|
||
if (!tests[i](args[i])) {
|
||
return false;
|
||
}
|
||
}
|
||
return testRestParam(args) && args.length >= varIndex + 1;
|
||
};
|
||
} else {
|
||
if (params.length === 0) {
|
||
return function testArgs(args) {
|
||
return args.length === 0;
|
||
};
|
||
} else if (params.length === 1) {
|
||
test0 = compileTest(params[0]);
|
||
return function testArgs(args) {
|
||
return test0(args[0]) && args.length === 1;
|
||
};
|
||
} else if (params.length === 2) {
|
||
test0 = compileTest(params[0]);
|
||
test1 = compileTest(params[1]);
|
||
return function testArgs(args) {
|
||
return test0(args[0]) && test1(args[1]) && args.length === 2;
|
||
};
|
||
} else {
|
||
tests = params.map(compileTest);
|
||
return function testArgs(args) {
|
||
for (let i = 0; i < tests.length; i++) {
|
||
if (!tests[i](args[i])) {
|
||
return false;
|
||
}
|
||
}
|
||
return args.length === tests.length;
|
||
};
|
||
}
|
||
}
|
||
}
|
||
function getParamAtIndex(params, index2) {
|
||
return index2 < params.length ? params[index2] : hasRestParam(params) ? last(params) : null;
|
||
}
|
||
function getTypeSetAtIndex(params, index2) {
|
||
const param = getParamAtIndex(params, index2);
|
||
if (!param) {
|
||
return /* @__PURE__ */ new Set();
|
||
}
|
||
return paramTypeSet(param);
|
||
}
|
||
function isExactType(type) {
|
||
return type.conversion === null || type.conversion === void 0;
|
||
}
|
||
function mergeExpectedParams(signatures, index2) {
|
||
const typeSet = /* @__PURE__ */ new Set();
|
||
signatures.forEach((signature) => {
|
||
const paramSet = getTypeSetAtIndex(signature.params, index2);
|
||
let name2;
|
||
for (name2 of paramSet) {
|
||
typeSet.add(name2);
|
||
}
|
||
});
|
||
return typeSet.has("any") ? ["any"] : Array.from(typeSet);
|
||
}
|
||
function createError(name2, args, signatures) {
|
||
let err, expected;
|
||
const _name = name2 || "unnamed";
|
||
let matchingSignatures = signatures;
|
||
let index2;
|
||
for (index2 = 0; index2 < args.length; index2++) {
|
||
const nextMatchingDefs = [];
|
||
matchingSignatures.forEach((signature) => {
|
||
const param = getParamAtIndex(signature.params, index2);
|
||
const test = compileTest(param);
|
||
if ((index2 < signature.params.length || hasRestParam(signature.params)) && test(args[index2])) {
|
||
nextMatchingDefs.push(signature);
|
||
}
|
||
});
|
||
if (nextMatchingDefs.length === 0) {
|
||
expected = mergeExpectedParams(matchingSignatures, index2);
|
||
if (expected.length > 0) {
|
||
const actualTypes = findTypeNames(args[index2]);
|
||
err = new TypeError("Unexpected type of argument in function " + _name + " (expected: " + expected.join(" or ") + ", actual: " + actualTypes.join(" | ") + ", index: " + index2 + ")");
|
||
err.data = {
|
||
category: "wrongType",
|
||
fn: _name,
|
||
index: index2,
|
||
actual: actualTypes,
|
||
expected
|
||
};
|
||
return err;
|
||
}
|
||
} else {
|
||
matchingSignatures = nextMatchingDefs;
|
||
}
|
||
}
|
||
const lengths = matchingSignatures.map(function(signature) {
|
||
return hasRestParam(signature.params) ? Infinity : signature.params.length;
|
||
});
|
||
if (args.length < Math.min.apply(null, lengths)) {
|
||
expected = mergeExpectedParams(matchingSignatures, index2);
|
||
err = new TypeError("Too few arguments in function " + _name + " (expected: " + expected.join(" or ") + ", index: " + args.length + ")");
|
||
err.data = {
|
||
category: "tooFewArgs",
|
||
fn: _name,
|
||
index: args.length,
|
||
expected
|
||
};
|
||
return err;
|
||
}
|
||
const maxLength = Math.max.apply(null, lengths);
|
||
if (args.length > maxLength) {
|
||
err = new TypeError("Too many arguments in function " + _name + " (expected: " + maxLength + ", actual: " + args.length + ")");
|
||
err.data = {
|
||
category: "tooManyArgs",
|
||
fn: _name,
|
||
index: args.length,
|
||
expectedLength: maxLength
|
||
};
|
||
return err;
|
||
}
|
||
const argTypes = [];
|
||
for (let i = 0; i < args.length; ++i) {
|
||
argTypes.push(findTypeNames(args[i]).join("|"));
|
||
}
|
||
err = new TypeError('Arguments of type "' + argTypes.join(", ") + '" do not match any of the defined signatures of function ' + _name + ".");
|
||
err.data = {
|
||
category: "mismatch",
|
||
actual: argTypes
|
||
};
|
||
return err;
|
||
}
|
||
function getLowestTypeIndex(param) {
|
||
let min2 = typeList.length + 1;
|
||
for (let i = 0; i < param.types.length; i++) {
|
||
if (isExactType(param.types[i])) {
|
||
min2 = Math.min(min2, param.types[i].typeIndex);
|
||
}
|
||
}
|
||
return min2;
|
||
}
|
||
function getLowestConversionIndex(param) {
|
||
let min2 = nConversions + 1;
|
||
for (let i = 0; i < param.types.length; i++) {
|
||
if (!isExactType(param.types[i])) {
|
||
min2 = Math.min(min2, param.types[i].conversionIndex);
|
||
}
|
||
}
|
||
return min2;
|
||
}
|
||
function compareParams(param1, param2) {
|
||
if (param1.hasAny) {
|
||
if (!param2.hasAny) {
|
||
return 1;
|
||
}
|
||
} else if (param2.hasAny) {
|
||
return -1;
|
||
}
|
||
if (param1.restParam) {
|
||
if (!param2.restParam) {
|
||
return 1;
|
||
}
|
||
} else if (param2.restParam) {
|
||
return -1;
|
||
}
|
||
if (param1.hasConversion) {
|
||
if (!param2.hasConversion) {
|
||
return 1;
|
||
}
|
||
} else if (param2.hasConversion) {
|
||
return -1;
|
||
}
|
||
const typeDiff = getLowestTypeIndex(param1) - getLowestTypeIndex(param2);
|
||
if (typeDiff < 0) {
|
||
return -1;
|
||
}
|
||
if (typeDiff > 0) {
|
||
return 1;
|
||
}
|
||
const convDiff = getLowestConversionIndex(param1) - getLowestConversionIndex(param2);
|
||
if (convDiff < 0) {
|
||
return -1;
|
||
}
|
||
if (convDiff > 0) {
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
function compareSignatures(signature1, signature2) {
|
||
const pars1 = signature1.params;
|
||
const pars2 = signature2.params;
|
||
const last1 = last(pars1);
|
||
const last2 = last(pars2);
|
||
const hasRest1 = hasRestParam(pars1);
|
||
const hasRest2 = hasRestParam(pars2);
|
||
if (hasRest1 && last1.hasAny) {
|
||
if (!hasRest2 || !last2.hasAny) {
|
||
return 1;
|
||
}
|
||
} else if (hasRest2 && last2.hasAny) {
|
||
return -1;
|
||
}
|
||
let any1 = 0;
|
||
let conv1 = 0;
|
||
let par;
|
||
for (par of pars1) {
|
||
if (par.hasAny)
|
||
++any1;
|
||
if (par.hasConversion)
|
||
++conv1;
|
||
}
|
||
let any2 = 0;
|
||
let conv2 = 0;
|
||
for (par of pars2) {
|
||
if (par.hasAny)
|
||
++any2;
|
||
if (par.hasConversion)
|
||
++conv2;
|
||
}
|
||
if (any1 !== any2) {
|
||
return any1 - any2;
|
||
}
|
||
if (hasRest1 && last1.hasConversion) {
|
||
if (!hasRest2 || !last2.hasConversion) {
|
||
return 1;
|
||
}
|
||
} else if (hasRest2 && last2.hasConversion) {
|
||
return -1;
|
||
}
|
||
if (conv1 !== conv2) {
|
||
return conv1 - conv2;
|
||
}
|
||
if (hasRest1) {
|
||
if (!hasRest2) {
|
||
return 1;
|
||
}
|
||
} else if (hasRest2) {
|
||
return -1;
|
||
}
|
||
const lengthCriterion = (pars1.length - pars2.length) * (hasRest1 ? -1 : 1);
|
||
if (lengthCriterion !== 0) {
|
||
return lengthCriterion;
|
||
}
|
||
const comparisons = [];
|
||
let tc = 0;
|
||
for (let i = 0; i < pars1.length; ++i) {
|
||
const thisComparison = compareParams(pars1[i], pars2[i]);
|
||
comparisons.push(thisComparison);
|
||
tc += thisComparison;
|
||
}
|
||
if (tc !== 0) {
|
||
return tc;
|
||
}
|
||
let c;
|
||
for (c of comparisons) {
|
||
if (c !== 0) {
|
||
return c;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
function availableConversions(typeNames) {
|
||
if (typeNames.length === 0) {
|
||
return [];
|
||
}
|
||
const types = typeNames.map(findType);
|
||
if (typeNames.length > 1) {
|
||
types.sort((t1, t2) => t1.index - t2.index);
|
||
}
|
||
let matches = types[0].conversionsTo;
|
||
if (typeNames.length === 1) {
|
||
return matches;
|
||
}
|
||
matches = matches.concat([]);
|
||
const knownTypes = new Set(typeNames);
|
||
for (let i = 1; i < types.length; ++i) {
|
||
let newMatch;
|
||
for (newMatch of types[i].conversionsTo) {
|
||
if (!knownTypes.has(newMatch.from)) {
|
||
matches.push(newMatch);
|
||
knownTypes.add(newMatch.from);
|
||
}
|
||
}
|
||
}
|
||
return matches;
|
||
}
|
||
function compileArgsPreprocessing(params, fn) {
|
||
let fnConvert = fn;
|
||
if (params.some((p2) => p2.hasConversion)) {
|
||
const restParam = hasRestParam(params);
|
||
const compiledConversions = params.map(compileArgConversion);
|
||
fnConvert = function convertArgs() {
|
||
const args = [];
|
||
const last2 = restParam ? arguments.length - 1 : arguments.length;
|
||
for (let i = 0; i < last2; i++) {
|
||
args[i] = compiledConversions[i](arguments[i]);
|
||
}
|
||
if (restParam) {
|
||
args[last2] = arguments[last2].map(compiledConversions[last2]);
|
||
}
|
||
return fn.apply(this, args);
|
||
};
|
||
}
|
||
let fnPreprocess = fnConvert;
|
||
if (hasRestParam(params)) {
|
||
const offset = params.length - 1;
|
||
fnPreprocess = function preprocessRestParams() {
|
||
return fnConvert.apply(this, slice(arguments, 0, offset).concat([slice(arguments, offset)]));
|
||
};
|
||
}
|
||
return fnPreprocess;
|
||
}
|
||
function compileArgConversion(param) {
|
||
let test0, test1, conversion0, conversion1;
|
||
const tests = [];
|
||
const conversions = [];
|
||
param.types.forEach(function(type) {
|
||
if (type.conversion) {
|
||
tests.push(findType(type.conversion.from).test);
|
||
conversions.push(type.conversion.convert);
|
||
}
|
||
});
|
||
switch (conversions.length) {
|
||
case 0:
|
||
return function convertArg(arg) {
|
||
return arg;
|
||
};
|
||
case 1:
|
||
test0 = tests[0];
|
||
conversion0 = conversions[0];
|
||
return function convertArg(arg) {
|
||
if (test0(arg)) {
|
||
return conversion0(arg);
|
||
}
|
||
return arg;
|
||
};
|
||
case 2:
|
||
test0 = tests[0];
|
||
test1 = tests[1];
|
||
conversion0 = conversions[0];
|
||
conversion1 = conversions[1];
|
||
return function convertArg(arg) {
|
||
if (test0(arg)) {
|
||
return conversion0(arg);
|
||
}
|
||
if (test1(arg)) {
|
||
return conversion1(arg);
|
||
}
|
||
return arg;
|
||
};
|
||
default:
|
||
return function convertArg(arg) {
|
||
for (let i = 0; i < conversions.length; i++) {
|
||
if (tests[i](arg)) {
|
||
return conversions[i](arg);
|
||
}
|
||
}
|
||
return arg;
|
||
};
|
||
}
|
||
}
|
||
function splitParams(params) {
|
||
function _splitParams(params2, index2, paramsSoFar) {
|
||
if (index2 < params2.length) {
|
||
const param = params2[index2];
|
||
let resultingParams = [];
|
||
if (param.restParam) {
|
||
const exactTypes = param.types.filter(isExactType);
|
||
if (exactTypes.length < param.types.length) {
|
||
resultingParams.push({
|
||
types: exactTypes,
|
||
name: "..." + exactTypes.map((t2) => t2.name).join("|"),
|
||
hasAny: exactTypes.some((t2) => t2.isAny),
|
||
hasConversion: false,
|
||
restParam: true
|
||
});
|
||
}
|
||
resultingParams.push(param);
|
||
} else {
|
||
resultingParams = param.types.map(function(type) {
|
||
return {
|
||
types: [type],
|
||
name: type.name,
|
||
hasAny: type.isAny,
|
||
hasConversion: type.conversion,
|
||
restParam: false
|
||
};
|
||
});
|
||
}
|
||
return flatMap(resultingParams, function(nextParam) {
|
||
return _splitParams(params2, index2 + 1, paramsSoFar.concat([nextParam]));
|
||
});
|
||
} else {
|
||
return [paramsSoFar];
|
||
}
|
||
}
|
||
return _splitParams(params, 0, []);
|
||
}
|
||
function conflicting(params1, params2) {
|
||
const ii = Math.max(params1.length, params2.length);
|
||
for (let i = 0; i < ii; i++) {
|
||
const typeSet1 = getTypeSetAtIndex(params1, i);
|
||
const typeSet2 = getTypeSetAtIndex(params2, i);
|
||
let overlap = false;
|
||
let name2;
|
||
for (name2 of typeSet2) {
|
||
if (typeSet1.has(name2)) {
|
||
overlap = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!overlap) {
|
||
return false;
|
||
}
|
||
}
|
||
const len1 = params1.length;
|
||
const len2 = params2.length;
|
||
const restParam1 = hasRestParam(params1);
|
||
const restParam2 = hasRestParam(params2);
|
||
return restParam1 ? restParam2 ? len1 === len2 : len2 >= len1 : restParam2 ? len1 >= len2 : len1 === len2;
|
||
}
|
||
function clearResolutions(functionList) {
|
||
return functionList.map((fn) => {
|
||
if (isReferToSelf(fn)) {
|
||
return referToSelf(fn.referToSelf.callback);
|
||
}
|
||
if (isReferTo(fn)) {
|
||
return makeReferTo(fn.referTo.references, fn.referTo.callback);
|
||
}
|
||
return fn;
|
||
});
|
||
}
|
||
function collectResolutions(references, functionList, signatureMap) {
|
||
const resolvedReferences = [];
|
||
let reference;
|
||
for (reference of references) {
|
||
let resolution = signatureMap[reference];
|
||
if (typeof resolution !== "number") {
|
||
throw new TypeError('No definition for referenced signature "' + reference + '"');
|
||
}
|
||
resolution = functionList[resolution];
|
||
if (typeof resolution !== "function") {
|
||
return false;
|
||
}
|
||
resolvedReferences.push(resolution);
|
||
}
|
||
return resolvedReferences;
|
||
}
|
||
function resolveReferences(functionList, signatureMap, self2) {
|
||
const resolvedFunctions = clearResolutions(functionList);
|
||
const isResolved = new Array(resolvedFunctions.length).fill(false);
|
||
let leftUnresolved = true;
|
||
while (leftUnresolved) {
|
||
leftUnresolved = false;
|
||
let nothingResolved = true;
|
||
for (let i = 0; i < resolvedFunctions.length; ++i) {
|
||
if (isResolved[i])
|
||
continue;
|
||
const fn = resolvedFunctions[i];
|
||
if (isReferToSelf(fn)) {
|
||
resolvedFunctions[i] = fn.referToSelf.callback(self2);
|
||
resolvedFunctions[i].referToSelf = fn.referToSelf;
|
||
isResolved[i] = true;
|
||
nothingResolved = false;
|
||
} else if (isReferTo(fn)) {
|
||
const resolvedReferences = collectResolutions(fn.referTo.references, resolvedFunctions, signatureMap);
|
||
if (resolvedReferences) {
|
||
resolvedFunctions[i] = fn.referTo.callback.apply(this, resolvedReferences);
|
||
resolvedFunctions[i].referTo = fn.referTo;
|
||
isResolved[i] = true;
|
||
nothingResolved = false;
|
||
} else {
|
||
leftUnresolved = true;
|
||
}
|
||
}
|
||
}
|
||
if (nothingResolved && leftUnresolved) {
|
||
throw new SyntaxError("Circular reference detected in resolving typed.referTo");
|
||
}
|
||
}
|
||
return resolvedFunctions;
|
||
}
|
||
function validateDeprecatedThis(signaturesMap) {
|
||
const deprecatedThisRegex = /\bthis(\(|\.signatures\b)/;
|
||
Object.keys(signaturesMap).forEach((signature) => {
|
||
const fn = signaturesMap[signature];
|
||
if (deprecatedThisRegex.test(fn.toString())) {
|
||
throw new SyntaxError("Using `this` to self-reference a function is deprecated since typed-function@3. Use typed.referTo and typed.referToSelf instead.");
|
||
}
|
||
});
|
||
}
|
||
function createTypedFunction(name2, rawSignaturesMap) {
|
||
typed2.createCount++;
|
||
if (Object.keys(rawSignaturesMap).length === 0) {
|
||
throw new SyntaxError("No signatures provided");
|
||
}
|
||
if (typed2.warnAgainstDeprecatedThis) {
|
||
validateDeprecatedThis(rawSignaturesMap);
|
||
}
|
||
const parsedParams = [];
|
||
const originalFunctions = [];
|
||
const signaturesMap = {};
|
||
const preliminarySignatures = [];
|
||
let signature;
|
||
for (signature in rawSignaturesMap) {
|
||
if (!Object.prototype.hasOwnProperty.call(rawSignaturesMap, signature)) {
|
||
continue;
|
||
}
|
||
const params = parseSignature(signature);
|
||
if (!params)
|
||
continue;
|
||
parsedParams.forEach(function(pp) {
|
||
if (conflicting(pp, params)) {
|
||
throw new TypeError('Conflicting signatures "' + stringifyParams(pp) + '" and "' + stringifyParams(params) + '".');
|
||
}
|
||
});
|
||
parsedParams.push(params);
|
||
const functionIndex = originalFunctions.length;
|
||
originalFunctions.push(rawSignaturesMap[signature]);
|
||
const conversionParams = params.map(expandParam);
|
||
let sp;
|
||
for (sp of splitParams(conversionParams)) {
|
||
const spName = stringifyParams(sp);
|
||
preliminarySignatures.push({
|
||
params: sp,
|
||
name: spName,
|
||
fn: functionIndex
|
||
});
|
||
if (sp.every((p2) => !p2.hasConversion)) {
|
||
signaturesMap[spName] = functionIndex;
|
||
}
|
||
}
|
||
}
|
||
preliminarySignatures.sort(compareSignatures);
|
||
const resolvedFunctions = resolveReferences(originalFunctions, signaturesMap, theTypedFn);
|
||
let s2;
|
||
for (s2 in signaturesMap) {
|
||
if (Object.prototype.hasOwnProperty.call(signaturesMap, s2)) {
|
||
signaturesMap[s2] = resolvedFunctions[signaturesMap[s2]];
|
||
}
|
||
}
|
||
const signatures = [];
|
||
const internalSignatureMap = /* @__PURE__ */ new Map();
|
||
for (s2 of preliminarySignatures) {
|
||
if (!internalSignatureMap.has(s2.name)) {
|
||
s2.fn = resolvedFunctions[s2.fn];
|
||
signatures.push(s2);
|
||
internalSignatureMap.set(s2.name, s2);
|
||
}
|
||
}
|
||
const ok0 = signatures[0] && signatures[0].params.length <= 2 && !hasRestParam(signatures[0].params);
|
||
const ok1 = signatures[1] && signatures[1].params.length <= 2 && !hasRestParam(signatures[1].params);
|
||
const ok2 = signatures[2] && signatures[2].params.length <= 2 && !hasRestParam(signatures[2].params);
|
||
const ok3 = signatures[3] && signatures[3].params.length <= 2 && !hasRestParam(signatures[3].params);
|
||
const ok4 = signatures[4] && signatures[4].params.length <= 2 && !hasRestParam(signatures[4].params);
|
||
const ok5 = signatures[5] && signatures[5].params.length <= 2 && !hasRestParam(signatures[5].params);
|
||
const allOk = ok0 && ok1 && ok2 && ok3 && ok4 && ok5;
|
||
for (let i = 0; i < signatures.length; ++i) {
|
||
signatures[i].test = compileTests(signatures[i].params);
|
||
}
|
||
const test00 = ok0 ? compileTest(signatures[0].params[0]) : notOk;
|
||
const test10 = ok1 ? compileTest(signatures[1].params[0]) : notOk;
|
||
const test20 = ok2 ? compileTest(signatures[2].params[0]) : notOk;
|
||
const test30 = ok3 ? compileTest(signatures[3].params[0]) : notOk;
|
||
const test40 = ok4 ? compileTest(signatures[4].params[0]) : notOk;
|
||
const test50 = ok5 ? compileTest(signatures[5].params[0]) : notOk;
|
||
const test01 = ok0 ? compileTest(signatures[0].params[1]) : notOk;
|
||
const test11 = ok1 ? compileTest(signatures[1].params[1]) : notOk;
|
||
const test21 = ok2 ? compileTest(signatures[2].params[1]) : notOk;
|
||
const test31 = ok3 ? compileTest(signatures[3].params[1]) : notOk;
|
||
const test41 = ok4 ? compileTest(signatures[4].params[1]) : notOk;
|
||
const test51 = ok5 ? compileTest(signatures[5].params[1]) : notOk;
|
||
for (let i = 0; i < signatures.length; ++i) {
|
||
signatures[i].implementation = compileArgsPreprocessing(signatures[i].params, signatures[i].fn);
|
||
}
|
||
const fn0 = ok0 ? signatures[0].implementation : undef;
|
||
const fn1 = ok1 ? signatures[1].implementation : undef;
|
||
const fn2 = ok2 ? signatures[2].implementation : undef;
|
||
const fn3 = ok3 ? signatures[3].implementation : undef;
|
||
const fn4 = ok4 ? signatures[4].implementation : undef;
|
||
const fn5 = ok5 ? signatures[5].implementation : undef;
|
||
const len0 = ok0 ? signatures[0].params.length : -1;
|
||
const len1 = ok1 ? signatures[1].params.length : -1;
|
||
const len2 = ok2 ? signatures[2].params.length : -1;
|
||
const len3 = ok3 ? signatures[3].params.length : -1;
|
||
const len4 = ok4 ? signatures[4].params.length : -1;
|
||
const len5 = ok5 ? signatures[5].params.length : -1;
|
||
const iStart = allOk ? 6 : 0;
|
||
const iEnd = signatures.length;
|
||
const tests = signatures.map((s3) => s3.test);
|
||
const fns = signatures.map((s3) => s3.implementation);
|
||
const generic = function generic2() {
|
||
for (let i = iStart; i < iEnd; i++) {
|
||
if (tests[i](arguments)) {
|
||
return fns[i].apply(this, arguments);
|
||
}
|
||
}
|
||
return typed2.onMismatch(name2, arguments, signatures);
|
||
};
|
||
function theTypedFn(arg0, arg1) {
|
||
if (arguments.length === len0 && test00(arg0) && test01(arg1)) {
|
||
return fn0.apply(this, arguments);
|
||
}
|
||
if (arguments.length === len1 && test10(arg0) && test11(arg1)) {
|
||
return fn1.apply(this, arguments);
|
||
}
|
||
if (arguments.length === len2 && test20(arg0) && test21(arg1)) {
|
||
return fn2.apply(this, arguments);
|
||
}
|
||
if (arguments.length === len3 && test30(arg0) && test31(arg1)) {
|
||
return fn3.apply(this, arguments);
|
||
}
|
||
if (arguments.length === len4 && test40(arg0) && test41(arg1)) {
|
||
return fn4.apply(this, arguments);
|
||
}
|
||
if (arguments.length === len5 && test50(arg0) && test51(arg1)) {
|
||
return fn5.apply(this, arguments);
|
||
}
|
||
return generic.apply(this, arguments);
|
||
}
|
||
try {
|
||
Object.defineProperty(theTypedFn, "name", {
|
||
value: name2
|
||
});
|
||
} catch (err) {
|
||
}
|
||
theTypedFn.signatures = signaturesMap;
|
||
theTypedFn._typedFunctionData = {
|
||
signatures,
|
||
signatureMap: internalSignatureMap
|
||
};
|
||
return theTypedFn;
|
||
}
|
||
function _onMismatch(name2, args, signatures) {
|
||
throw createError(name2, args, signatures);
|
||
}
|
||
function initial(arr) {
|
||
return slice(arr, 0, arr.length - 1);
|
||
}
|
||
function last(arr) {
|
||
return arr[arr.length - 1];
|
||
}
|
||
function slice(arr, start, end) {
|
||
return Array.prototype.slice.call(arr, start, end);
|
||
}
|
||
function findInArray(arr, test) {
|
||
for (let i = 0; i < arr.length; i++) {
|
||
if (test(arr[i])) {
|
||
return arr[i];
|
||
}
|
||
}
|
||
return void 0;
|
||
}
|
||
function flatMap(arr, callback) {
|
||
return Array.prototype.concat.apply([], arr.map(callback));
|
||
}
|
||
function referTo() {
|
||
const references = initial(arguments).map((s2) => stringifyParams(parseSignature(s2)));
|
||
const callback = last(arguments);
|
||
if (typeof callback !== "function") {
|
||
throw new TypeError("Callback function expected as last argument");
|
||
}
|
||
return makeReferTo(references, callback);
|
||
}
|
||
function makeReferTo(references, callback) {
|
||
return {
|
||
referTo: {
|
||
references,
|
||
callback
|
||
}
|
||
};
|
||
}
|
||
function referToSelf(callback) {
|
||
if (typeof callback !== "function") {
|
||
throw new TypeError("Callback function expected as first argument");
|
||
}
|
||
return {
|
||
referToSelf: {
|
||
callback
|
||
}
|
||
};
|
||
}
|
||
function isReferTo(objectOrFn) {
|
||
return objectOrFn && typeof objectOrFn.referTo === "object" && Array.isArray(objectOrFn.referTo.references) && typeof objectOrFn.referTo.callback === "function";
|
||
}
|
||
function isReferToSelf(objectOrFn) {
|
||
return objectOrFn && typeof objectOrFn.referToSelf === "object" && typeof objectOrFn.referToSelf.callback === "function";
|
||
}
|
||
function checkName(nameSoFar, newName) {
|
||
if (!nameSoFar) {
|
||
return newName;
|
||
}
|
||
if (newName && newName !== nameSoFar) {
|
||
const err = new Error("Function names do not match (expected: " + nameSoFar + ", actual: " + newName + ")");
|
||
err.data = {
|
||
actual: newName,
|
||
expected: nameSoFar
|
||
};
|
||
throw err;
|
||
}
|
||
return nameSoFar;
|
||
}
|
||
function getObjectName(obj) {
|
||
let name2;
|
||
for (const key in obj) {
|
||
if (Object.prototype.hasOwnProperty.call(obj, key) && (isTypedFunction(obj[key]) || typeof obj[key].signature === "string")) {
|
||
name2 = checkName(name2, obj[key].name);
|
||
}
|
||
}
|
||
return name2;
|
||
}
|
||
function mergeSignatures(dest, source) {
|
||
let key;
|
||
for (key in source) {
|
||
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||
if (key in dest) {
|
||
if (source[key] !== dest[key]) {
|
||
const err = new Error('Signature "' + key + '" is defined twice');
|
||
err.data = {
|
||
signature: key,
|
||
sourceFunction: source[key],
|
||
destFunction: dest[key]
|
||
};
|
||
throw err;
|
||
}
|
||
}
|
||
dest[key] = source[key];
|
||
}
|
||
}
|
||
}
|
||
const saveTyped = typed2;
|
||
typed2 = function(maybeName) {
|
||
const named = typeof maybeName === "string";
|
||
const start = named ? 1 : 0;
|
||
let name2 = named ? maybeName : "";
|
||
const allSignatures = {};
|
||
for (let i = start; i < arguments.length; ++i) {
|
||
const item = arguments[i];
|
||
let theseSignatures = {};
|
||
let thisName;
|
||
if (typeof item === "function") {
|
||
thisName = item.name;
|
||
if (typeof item.signature === "string") {
|
||
theseSignatures[item.signature] = item;
|
||
} else if (isTypedFunction(item)) {
|
||
theseSignatures = item.signatures;
|
||
}
|
||
} else if (isPlainObject2(item)) {
|
||
theseSignatures = item;
|
||
if (!named) {
|
||
thisName = getObjectName(item);
|
||
}
|
||
}
|
||
if (Object.keys(theseSignatures).length === 0) {
|
||
const err = new TypeError("Argument to 'typed' at index " + i + " is not a (typed) function, nor an object with signatures as keys and functions as values.");
|
||
err.data = {
|
||
index: i,
|
||
argument: item
|
||
};
|
||
throw err;
|
||
}
|
||
if (!named) {
|
||
name2 = checkName(name2, thisName);
|
||
}
|
||
mergeSignatures(allSignatures, theseSignatures);
|
||
}
|
||
return createTypedFunction(name2 || "", allSignatures);
|
||
};
|
||
typed2.create = create;
|
||
typed2.createCount = saveTyped.createCount;
|
||
typed2.onMismatch = _onMismatch;
|
||
typed2.throwMismatchError = _onMismatch;
|
||
typed2.createError = createError;
|
||
typed2.clear = clear2;
|
||
typed2.clearConversions = clearConversions;
|
||
typed2.addTypes = addTypes;
|
||
typed2._findType = findType;
|
||
typed2.referTo = referTo;
|
||
typed2.referToSelf = referToSelf;
|
||
typed2.convert = convert;
|
||
typed2.findSignature = findSignature;
|
||
typed2.find = find;
|
||
typed2.isTypedFunction = isTypedFunction;
|
||
typed2.warnAgainstDeprecatedThis = true;
|
||
typed2.addType = function(type, beforeObjectTest) {
|
||
let before = "any";
|
||
if (beforeObjectTest !== false && typeMap.has("Object")) {
|
||
before = "Object";
|
||
}
|
||
typed2.addTypes([type], before);
|
||
};
|
||
function _validateConversion(conversion) {
|
||
if (!conversion || typeof conversion.from !== "string" || typeof conversion.to !== "string" || typeof conversion.convert !== "function") {
|
||
throw new TypeError("Object with properties {from: string, to: string, convert: function} expected");
|
||
}
|
||
if (conversion.to === conversion.from) {
|
||
throw new SyntaxError('Illegal to define conversion from "' + conversion.from + '" to itself.');
|
||
}
|
||
}
|
||
typed2.addConversion = function(conversion) {
|
||
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
||
override: false
|
||
};
|
||
_validateConversion(conversion);
|
||
const to = findType(conversion.to);
|
||
const existing = to.conversionsTo.find((other) => other.from === conversion.from);
|
||
if (existing) {
|
||
if (options && options.override) {
|
||
typed2.removeConversion({
|
||
from: existing.from,
|
||
to: conversion.to,
|
||
convert: existing.convert
|
||
});
|
||
} else {
|
||
throw new Error('There is already a conversion from "' + conversion.from + '" to "' + to.name + '"');
|
||
}
|
||
}
|
||
to.conversionsTo.push({
|
||
from: conversion.from,
|
||
convert: conversion.convert,
|
||
index: nConversions++
|
||
});
|
||
};
|
||
typed2.addConversions = function(conversions, options) {
|
||
conversions.forEach((conversion) => typed2.addConversion(conversion, options));
|
||
};
|
||
typed2.removeConversion = function(conversion) {
|
||
_validateConversion(conversion);
|
||
const to = findType(conversion.to);
|
||
const existingConversion = findInArray(to.conversionsTo, (c) => c.from === conversion.from);
|
||
if (!existingConversion) {
|
||
throw new Error("Attempt to remove nonexistent conversion from " + conversion.from + " to " + conversion.to);
|
||
}
|
||
if (existingConversion.convert !== conversion.convert) {
|
||
throw new Error("Conversion to remove does not match existing conversion");
|
||
}
|
||
const index2 = to.conversionsTo.indexOf(existingConversion);
|
||
to.conversionsTo.splice(index2, 1);
|
||
};
|
||
typed2.resolve = function(tf, argList) {
|
||
if (!isTypedFunction(tf)) {
|
||
throw new TypeError(NOT_TYPED_FUNCTION);
|
||
}
|
||
const sigs = tf._typedFunctionData.signatures;
|
||
for (let i = 0; i < sigs.length; ++i) {
|
||
if (sigs[i].test(argList)) {
|
||
return sigs[i];
|
||
}
|
||
}
|
||
return null;
|
||
};
|
||
return typed2;
|
||
}
|
||
const typedFunction = create();
|
||
function factory(name2, dependencies2, create2, meta) {
|
||
function assertAndCreate(scope) {
|
||
var deps = pickShallow(scope, dependencies2.map(stripOptionalNotation));
|
||
assertDependencies(name2, dependencies2, scope);
|
||
return create2(deps);
|
||
}
|
||
assertAndCreate.isFactory = true;
|
||
assertAndCreate.fn = name2;
|
||
assertAndCreate.dependencies = dependencies2.slice().sort();
|
||
if (meta) {
|
||
assertAndCreate.meta = meta;
|
||
}
|
||
return assertAndCreate;
|
||
}
|
||
function assertDependencies(name2, dependencies2, scope) {
|
||
var allDefined = dependencies2.filter((dependency) => !isOptionalDependency(dependency)).every((dependency) => scope[dependency] !== void 0);
|
||
if (!allDefined) {
|
||
var missingDependencies = dependencies2.filter((dependency) => scope[dependency] === void 0);
|
||
throw new Error('Cannot create function "'.concat(name2, '", ') + "some dependencies are missing: ".concat(missingDependencies.map((d) => '"'.concat(d, '"')).join(", "), "."));
|
||
}
|
||
}
|
||
function isOptionalDependency(dependency) {
|
||
return dependency && dependency[0] === "?";
|
||
}
|
||
function stripOptionalNotation(dependency) {
|
||
return dependency && dependency[0] === "?" ? dependency.slice(1) : dependency;
|
||
}
|
||
function isInteger(value) {
|
||
if (typeof value === "boolean") {
|
||
return true;
|
||
}
|
||
return isFinite(value) ? value === Math.round(value) : false;
|
||
}
|
||
function formatNumberToBase(n2, base, size2) {
|
||
var prefixes = {
|
||
2: "0b",
|
||
8: "0o",
|
||
16: "0x"
|
||
};
|
||
var prefix = prefixes[base];
|
||
var suffix = "";
|
||
if (size2) {
|
||
if (size2 < 1) {
|
||
throw new Error("size must be in greater than 0");
|
||
}
|
||
if (!isInteger(size2)) {
|
||
throw new Error("size must be an integer");
|
||
}
|
||
if (n2 > 2 ** (size2 - 1) - 1 || n2 < -(2 ** (size2 - 1))) {
|
||
throw new Error("Value must be in range [-2^".concat(size2 - 1, ", 2^").concat(size2 - 1, "-1]"));
|
||
}
|
||
if (!isInteger(n2)) {
|
||
throw new Error("Value must be an integer");
|
||
}
|
||
if (n2 < 0) {
|
||
n2 = n2 + 2 ** size2;
|
||
}
|
||
suffix = "i".concat(size2);
|
||
}
|
||
var sign2 = "";
|
||
if (n2 < 0) {
|
||
n2 = -n2;
|
||
sign2 = "-";
|
||
}
|
||
return "".concat(sign2).concat(prefix).concat(n2.toString(base)).concat(suffix);
|
||
}
|
||
function format$2(value, options) {
|
||
if (typeof options === "function") {
|
||
return options(value);
|
||
}
|
||
if (value === Infinity) {
|
||
return "Infinity";
|
||
} else if (value === -Infinity) {
|
||
return "-Infinity";
|
||
} else if (isNaN(value)) {
|
||
return "NaN";
|
||
}
|
||
var {
|
||
notation,
|
||
precision,
|
||
wordSize
|
||
} = normalizeFormatOptions(options);
|
||
switch (notation) {
|
||
case "fixed":
|
||
return toFixed$1(value, precision);
|
||
case "exponential":
|
||
return toExponential$1(value, precision);
|
||
case "engineering":
|
||
return toEngineering$1(value, precision);
|
||
case "bin":
|
||
return formatNumberToBase(value, 2, wordSize);
|
||
case "oct":
|
||
return formatNumberToBase(value, 8, wordSize);
|
||
case "hex":
|
||
return formatNumberToBase(value, 16, wordSize);
|
||
case "auto":
|
||
return toPrecision(value, precision, options).replace(/((\.\d*?)(0+))($|e)/, function() {
|
||
var digits2 = arguments[2];
|
||
var e2 = arguments[4];
|
||
return digits2 !== "." ? digits2 + e2 : e2;
|
||
});
|
||
default:
|
||
throw new Error('Unknown notation "' + notation + '". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.');
|
||
}
|
||
}
|
||
function normalizeFormatOptions(options) {
|
||
var notation = "auto";
|
||
var precision;
|
||
var wordSize;
|
||
if (options !== void 0) {
|
||
if (isNumber(options)) {
|
||
precision = options;
|
||
} else if (isBigNumber(options)) {
|
||
precision = options.toNumber();
|
||
} else if (isObject(options)) {
|
||
if (options.precision !== void 0) {
|
||
precision = _toNumberOrThrow(options.precision, () => {
|
||
throw new Error('Option "precision" must be a number or BigNumber');
|
||
});
|
||
}
|
||
if (options.wordSize !== void 0) {
|
||
wordSize = _toNumberOrThrow(options.wordSize, () => {
|
||
throw new Error('Option "wordSize" must be a number or BigNumber');
|
||
});
|
||
}
|
||
if (options.notation) {
|
||
notation = options.notation;
|
||
}
|
||
} else {
|
||
throw new Error("Unsupported type of options, number, BigNumber, or object expected");
|
||
}
|
||
}
|
||
return {
|
||
notation,
|
||
precision,
|
||
wordSize
|
||
};
|
||
}
|
||
function splitNumber(value) {
|
||
var match = String(value).toLowerCase().match(/^(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);
|
||
if (!match) {
|
||
throw new SyntaxError("Invalid number " + value);
|
||
}
|
||
var sign2 = match[1];
|
||
var digits2 = match[2];
|
||
var exponent = parseFloat(match[4] || "0");
|
||
var dot = digits2.indexOf(".");
|
||
exponent += dot !== -1 ? dot - 1 : digits2.length - 1;
|
||
var coefficients = digits2.replace(".", "").replace(/^0*/, function(zeros2) {
|
||
exponent -= zeros2.length;
|
||
return "";
|
||
}).replace(/0*$/, "").split("").map(function(d) {
|
||
return parseInt(d);
|
||
});
|
||
if (coefficients.length === 0) {
|
||
coefficients.push(0);
|
||
exponent++;
|
||
}
|
||
return {
|
||
sign: sign2,
|
||
coefficients,
|
||
exponent
|
||
};
|
||
}
|
||
function toEngineering$1(value, precision) {
|
||
if (isNaN(value) || !isFinite(value)) {
|
||
return String(value);
|
||
}
|
||
var split = splitNumber(value);
|
||
var rounded = roundDigits(split, precision);
|
||
var e2 = rounded.exponent;
|
||
var c = rounded.coefficients;
|
||
var newExp = e2 % 3 === 0 ? e2 : e2 < 0 ? e2 - 3 - e2 % 3 : e2 - e2 % 3;
|
||
if (isNumber(precision)) {
|
||
while (precision > c.length || e2 - newExp + 1 > c.length) {
|
||
c.push(0);
|
||
}
|
||
} else {
|
||
var missingZeros = Math.abs(e2 - newExp) - (c.length - 1);
|
||
for (var i = 0; i < missingZeros; i++) {
|
||
c.push(0);
|
||
}
|
||
}
|
||
var expDiff = Math.abs(e2 - newExp);
|
||
var decimalIdx = 1;
|
||
while (expDiff > 0) {
|
||
decimalIdx++;
|
||
expDiff--;
|
||
}
|
||
var decimals = c.slice(decimalIdx).join("");
|
||
var decimalVal = isNumber(precision) && decimals.length || decimals.match(/[1-9]/) ? "." + decimals : "";
|
||
var str = c.slice(0, decimalIdx).join("") + decimalVal + "e" + (e2 >= 0 ? "+" : "") + newExp.toString();
|
||
return rounded.sign + str;
|
||
}
|
||
function toFixed$1(value, precision) {
|
||
if (isNaN(value) || !isFinite(value)) {
|
||
return String(value);
|
||
}
|
||
var splitValue = splitNumber(value);
|
||
var rounded = typeof precision === "number" ? roundDigits(splitValue, splitValue.exponent + 1 + precision) : splitValue;
|
||
var c = rounded.coefficients;
|
||
var p2 = rounded.exponent + 1;
|
||
var pp = p2 + (precision || 0);
|
||
if (c.length < pp) {
|
||
c = c.concat(zeros$1(pp - c.length));
|
||
}
|
||
if (p2 < 0) {
|
||
c = zeros$1(-p2 + 1).concat(c);
|
||
p2 = 1;
|
||
}
|
||
if (p2 < c.length) {
|
||
c.splice(p2, 0, p2 === 0 ? "0." : ".");
|
||
}
|
||
return rounded.sign + c.join("");
|
||
}
|
||
function toExponential$1(value, precision) {
|
||
if (isNaN(value) || !isFinite(value)) {
|
||
return String(value);
|
||
}
|
||
var split = splitNumber(value);
|
||
var rounded = precision ? roundDigits(split, precision) : split;
|
||
var c = rounded.coefficients;
|
||
var e2 = rounded.exponent;
|
||
if (c.length < precision) {
|
||
c = c.concat(zeros$1(precision - c.length));
|
||
}
|
||
var first = c.shift();
|
||
return rounded.sign + first + (c.length > 0 ? "." + c.join("") : "") + "e" + (e2 >= 0 ? "+" : "") + e2;
|
||
}
|
||
function toPrecision(value, precision, options) {
|
||
if (isNaN(value) || !isFinite(value)) {
|
||
return String(value);
|
||
}
|
||
var lowerExp = _toNumberOrDefault$1(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
||
var upperExp = _toNumberOrDefault$1(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
||
var split = splitNumber(value);
|
||
var rounded = precision ? roundDigits(split, precision) : split;
|
||
if (rounded.exponent < lowerExp || rounded.exponent >= upperExp) {
|
||
return toExponential$1(value, precision);
|
||
} else {
|
||
var c = rounded.coefficients;
|
||
var e2 = rounded.exponent;
|
||
if (c.length < precision) {
|
||
c = c.concat(zeros$1(precision - c.length));
|
||
}
|
||
c = c.concat(zeros$1(e2 - c.length + 1 + (c.length < precision ? precision - c.length : 0)));
|
||
c = zeros$1(-e2).concat(c);
|
||
var dot = e2 > 0 ? e2 : 0;
|
||
if (dot < c.length - 1) {
|
||
c.splice(dot + 1, 0, ".");
|
||
}
|
||
return rounded.sign + c.join("");
|
||
}
|
||
}
|
||
function roundDigits(split, precision) {
|
||
var rounded = {
|
||
sign: split.sign,
|
||
coefficients: split.coefficients,
|
||
exponent: split.exponent
|
||
};
|
||
var c = rounded.coefficients;
|
||
while (precision <= 0) {
|
||
c.unshift(0);
|
||
rounded.exponent++;
|
||
precision++;
|
||
}
|
||
if (c.length > precision) {
|
||
var removed = c.splice(precision, c.length - precision);
|
||
if (removed[0] >= 5) {
|
||
var i = precision - 1;
|
||
c[i]++;
|
||
while (c[i] === 10) {
|
||
c.pop();
|
||
if (i === 0) {
|
||
c.unshift(0);
|
||
rounded.exponent++;
|
||
i++;
|
||
}
|
||
i--;
|
||
c[i]++;
|
||
}
|
||
}
|
||
}
|
||
return rounded;
|
||
}
|
||
function zeros$1(length) {
|
||
var arr = [];
|
||
for (var i = 0; i < length; i++) {
|
||
arr.push(0);
|
||
}
|
||
return arr;
|
||
}
|
||
function digits(value) {
|
||
return value.toExponential().replace(/e.*$/, "").replace(/^0\.?0*|\./, "").length;
|
||
}
|
||
function nearlyEqual$1(a, b) {
|
||
var relTol = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1e-8;
|
||
var absTol = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
||
if (relTol <= 0) {
|
||
throw new Error("Relative tolerance must be greater than 0");
|
||
}
|
||
if (absTol < 0) {
|
||
throw new Error("Absolute tolerance must be at least 0");
|
||
}
|
||
if (isNaN(a) || isNaN(b)) {
|
||
return false;
|
||
}
|
||
if (!isFinite(a) || !isFinite(b)) {
|
||
return a === b;
|
||
}
|
||
if (a === b) {
|
||
return true;
|
||
}
|
||
return Math.abs(a - b) <= Math.max(relTol * Math.max(Math.abs(a), Math.abs(b)), absTol);
|
||
}
|
||
function _toNumberOrThrow(value, onError) {
|
||
if (isNumber(value)) {
|
||
return value;
|
||
} else if (isBigNumber(value)) {
|
||
return value.toNumber();
|
||
} else {
|
||
onError();
|
||
}
|
||
}
|
||
function _toNumberOrDefault$1(value, defaultValue) {
|
||
if (isNumber(value)) {
|
||
return value;
|
||
} else if (isBigNumber(value)) {
|
||
return value.toNumber();
|
||
} else {
|
||
return defaultValue;
|
||
}
|
||
}
|
||
var _createTyped2 = function _createTyped() {
|
||
_createTyped2 = typedFunction.create;
|
||
return typedFunction;
|
||
};
|
||
var dependencies$d = ["?BigNumber", "?Complex", "?DenseMatrix", "?Fraction"];
|
||
var createTyped = /* @__PURE__ */ factory("typed", dependencies$d, function createTyped2(_ref) {
|
||
var {
|
||
BigNumber: BigNumber2,
|
||
Complex: Complex2,
|
||
DenseMatrix: DenseMatrix2,
|
||
Fraction: Fraction2
|
||
} = _ref;
|
||
var typed2 = _createTyped2();
|
||
typed2.clear();
|
||
typed2.addTypes([
|
||
{
|
||
name: "number",
|
||
test: isNumber
|
||
},
|
||
{
|
||
name: "Complex",
|
||
test: isComplex
|
||
},
|
||
{
|
||
name: "BigNumber",
|
||
test: isBigNumber
|
||
},
|
||
{
|
||
name: "bigint",
|
||
test: isBigInt
|
||
},
|
||
{
|
||
name: "Fraction",
|
||
test: isFraction
|
||
},
|
||
{
|
||
name: "Unit",
|
||
test: isUnit
|
||
},
|
||
// The following type matches a valid variable name, i.e., an alphanumeric
|
||
// string starting with an alphabetic character. It is used (at least)
|
||
// in the definition of the derivative() function, as the argument telling
|
||
// what to differentiate over must (currently) be a variable.
|
||
// TODO: deprecate the identifier type (it's not used anymore, see https://github.com/josdejong/mathjs/issues/3253)
|
||
{
|
||
name: "identifier",
|
||
test: (s2) => isString && /^(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDDC0-\uDDF3\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDD4A-\uDD65\uDD6F-\uDD85\uDE80-\uDEA9\uDEB0\uDEB1\uDEC2-\uDEC4\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61\uDF80-\uDF89\uDF8B\uDF8E\uDF90-\uDFB5\uDFB7\uDFD1\uDFD3]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8\uDFC0-\uDFE0]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD80E\uD80F\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46\uDC60-\uDFFF]|\uD810[\uDC00-\uDFFA]|\uD811[\uDC00-\uDE46]|\uD818[\uDD00-\uDD1D]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDD40-\uDD6C\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDCFF-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDDD0-\uDDED\uDDF0\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])(?:[0-9A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDDC0-\uDDF3\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDD4A-\uDD65\uDD6F-\uDD85\uDE80-\uDEA9\uDEB0\uDEB1\uDEC2-\uDEC4\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61\uDF80-\uDF89\uDF8B\uDF8E\uDF90-\uDFB5\uDFB7\uDFD1\uDFD3]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8\uDFC0-\uDFE0]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD80E\uD80F\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46\uDC60-\uDFFF]|\uD810[\uDC00-\uDFFA]|\uD811[\uDC00-\uDE46]|\uD818[\uDD00-\uDD1D]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDD40-\uDD6C\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDCFF-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDDD0-\uDDED\uDDF0\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])*$/.test(s2)
|
||
},
|
||
{
|
||
name: "string",
|
||
test: isString
|
||
},
|
||
{
|
||
name: "Chain",
|
||
test: isChain
|
||
},
|
||
{
|
||
name: "Array",
|
||
test: isArray
|
||
},
|
||
{
|
||
name: "Matrix",
|
||
test: isMatrix
|
||
},
|
||
{
|
||
name: "DenseMatrix",
|
||
test: isDenseMatrix
|
||
},
|
||
{
|
||
name: "SparseMatrix",
|
||
test: isSparseMatrix
|
||
},
|
||
{
|
||
name: "Range",
|
||
test: isRange
|
||
},
|
||
{
|
||
name: "Index",
|
||
test: isIndex
|
||
},
|
||
{
|
||
name: "boolean",
|
||
test: isBoolean
|
||
},
|
||
{
|
||
name: "ResultSet",
|
||
test: isResultSet
|
||
},
|
||
{
|
||
name: "Help",
|
||
test: isHelp
|
||
},
|
||
{
|
||
name: "function",
|
||
test: isFunction
|
||
},
|
||
{
|
||
name: "Date",
|
||
test: isDate
|
||
},
|
||
{
|
||
name: "RegExp",
|
||
test: isRegExp
|
||
},
|
||
{
|
||
name: "null",
|
||
test: isNull
|
||
},
|
||
{
|
||
name: "undefined",
|
||
test: isUndefined
|
||
},
|
||
{
|
||
name: "AccessorNode",
|
||
test: isAccessorNode
|
||
},
|
||
{
|
||
name: "ArrayNode",
|
||
test: isArrayNode
|
||
},
|
||
{
|
||
name: "AssignmentNode",
|
||
test: isAssignmentNode
|
||
},
|
||
{
|
||
name: "BlockNode",
|
||
test: isBlockNode
|
||
},
|
||
{
|
||
name: "ConditionalNode",
|
||
test: isConditionalNode
|
||
},
|
||
{
|
||
name: "ConstantNode",
|
||
test: isConstantNode
|
||
},
|
||
{
|
||
name: "FunctionNode",
|
||
test: isFunctionNode
|
||
},
|
||
{
|
||
name: "FunctionAssignmentNode",
|
||
test: isFunctionAssignmentNode
|
||
},
|
||
{
|
||
name: "IndexNode",
|
||
test: isIndexNode
|
||
},
|
||
{
|
||
name: "Node",
|
||
test: isNode
|
||
},
|
||
{
|
||
name: "ObjectNode",
|
||
test: isObjectNode
|
||
},
|
||
{
|
||
name: "OperatorNode",
|
||
test: isOperatorNode
|
||
},
|
||
{
|
||
name: "ParenthesisNode",
|
||
test: isParenthesisNode
|
||
},
|
||
{
|
||
name: "RangeNode",
|
||
test: isRangeNode
|
||
},
|
||
{
|
||
name: "RelationalNode",
|
||
test: isRelationalNode
|
||
},
|
||
{
|
||
name: "SymbolNode",
|
||
test: isSymbolNode
|
||
},
|
||
{
|
||
name: "Map",
|
||
test: isMap
|
||
},
|
||
{
|
||
name: "Object",
|
||
test: isObject
|
||
}
|
||
// order 'Object' last, it matches on other classes too
|
||
]);
|
||
typed2.addConversions([{
|
||
from: "number",
|
||
to: "BigNumber",
|
||
convert: function convert(x) {
|
||
if (!BigNumber2) {
|
||
throwNoBignumber(x);
|
||
}
|
||
if (digits(x) > 15) {
|
||
throw new TypeError("Cannot implicitly convert a number with >15 significant digits to BigNumber (value: " + x + "). Use function bignumber(x) to convert to BigNumber.");
|
||
}
|
||
return new BigNumber2(x);
|
||
}
|
||
}, {
|
||
from: "number",
|
||
to: "Complex",
|
||
convert: function convert(x) {
|
||
if (!Complex2) {
|
||
throwNoComplex(x);
|
||
}
|
||
return new Complex2(x, 0);
|
||
}
|
||
}, {
|
||
from: "BigNumber",
|
||
to: "Complex",
|
||
convert: function convert(x) {
|
||
if (!Complex2) {
|
||
throwNoComplex(x);
|
||
}
|
||
return new Complex2(x.toNumber(), 0);
|
||
}
|
||
}, {
|
||
from: "bigint",
|
||
to: "number",
|
||
convert: function convert(x) {
|
||
if (x > Number.MAX_SAFE_INTEGER) {
|
||
throw new TypeError("Cannot implicitly convert bigint to number: value exceeds the max safe integer value (value: " + x + ")");
|
||
}
|
||
return Number(x);
|
||
}
|
||
}, {
|
||
from: "bigint",
|
||
to: "BigNumber",
|
||
convert: function convert(x) {
|
||
if (!BigNumber2) {
|
||
throwNoBignumber(x);
|
||
}
|
||
return new BigNumber2(x.toString());
|
||
}
|
||
}, {
|
||
from: "bigint",
|
||
to: "Fraction",
|
||
convert: function convert(x) {
|
||
if (!Fraction2) {
|
||
throwNoFraction(x);
|
||
}
|
||
return new Fraction2(x);
|
||
}
|
||
}, {
|
||
from: "Fraction",
|
||
to: "BigNumber",
|
||
convert: function convert(x) {
|
||
throw new TypeError("Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.");
|
||
}
|
||
}, {
|
||
from: "Fraction",
|
||
to: "Complex",
|
||
convert: function convert(x) {
|
||
if (!Complex2) {
|
||
throwNoComplex(x);
|
||
}
|
||
return new Complex2(x.valueOf(), 0);
|
||
}
|
||
}, {
|
||
from: "number",
|
||
to: "Fraction",
|
||
convert: function convert(x) {
|
||
if (!Fraction2) {
|
||
throwNoFraction(x);
|
||
}
|
||
var f2 = new Fraction2(x);
|
||
if (f2.valueOf() !== x) {
|
||
throw new TypeError("Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: " + x + "). Use function fraction(x) to convert to Fraction.");
|
||
}
|
||
return f2;
|
||
}
|
||
}, {
|
||
// FIXME: add conversion from Fraction to number, for example for `sqrt(fraction(1,3))`
|
||
// from: 'Fraction',
|
||
// to: 'number',
|
||
// convert: function (x) {
|
||
// return x.valueOf()
|
||
// }
|
||
// }, {
|
||
from: "string",
|
||
to: "number",
|
||
convert: function convert(x) {
|
||
var n2 = Number(x);
|
||
if (isNaN(n2)) {
|
||
throw new Error('Cannot convert "' + x + '" to a number');
|
||
}
|
||
return n2;
|
||
}
|
||
}, {
|
||
from: "string",
|
||
to: "BigNumber",
|
||
convert: function convert(x) {
|
||
if (!BigNumber2) {
|
||
throwNoBignumber(x);
|
||
}
|
||
try {
|
||
return new BigNumber2(x);
|
||
} catch (err) {
|
||
throw new Error('Cannot convert "' + x + '" to BigNumber');
|
||
}
|
||
}
|
||
}, {
|
||
from: "string",
|
||
to: "bigint",
|
||
convert: function convert(x) {
|
||
try {
|
||
return BigInt(x);
|
||
} catch (err) {
|
||
throw new Error('Cannot convert "' + x + '" to BigInt');
|
||
}
|
||
}
|
||
}, {
|
||
from: "string",
|
||
to: "Fraction",
|
||
convert: function convert(x) {
|
||
if (!Fraction2) {
|
||
throwNoFraction(x);
|
||
}
|
||
try {
|
||
return new Fraction2(x);
|
||
} catch (err) {
|
||
throw new Error('Cannot convert "' + x + '" to Fraction');
|
||
}
|
||
}
|
||
}, {
|
||
from: "string",
|
||
to: "Complex",
|
||
convert: function convert(x) {
|
||
if (!Complex2) {
|
||
throwNoComplex(x);
|
||
}
|
||
try {
|
||
return new Complex2(x);
|
||
} catch (err) {
|
||
throw new Error('Cannot convert "' + x + '" to Complex');
|
||
}
|
||
}
|
||
}, {
|
||
from: "boolean",
|
||
to: "number",
|
||
convert: function convert(x) {
|
||
return +x;
|
||
}
|
||
}, {
|
||
from: "boolean",
|
||
to: "BigNumber",
|
||
convert: function convert(x) {
|
||
if (!BigNumber2) {
|
||
throwNoBignumber(x);
|
||
}
|
||
return new BigNumber2(+x);
|
||
}
|
||
}, {
|
||
from: "boolean",
|
||
to: "bigint",
|
||
convert: function convert(x) {
|
||
return BigInt(+x);
|
||
}
|
||
}, {
|
||
from: "boolean",
|
||
to: "Fraction",
|
||
convert: function convert(x) {
|
||
if (!Fraction2) {
|
||
throwNoFraction(x);
|
||
}
|
||
return new Fraction2(+x);
|
||
}
|
||
}, {
|
||
from: "boolean",
|
||
to: "string",
|
||
convert: function convert(x) {
|
||
return String(x);
|
||
}
|
||
}, {
|
||
from: "Array",
|
||
to: "Matrix",
|
||
convert: function convert(array) {
|
||
if (!DenseMatrix2) {
|
||
throwNoMatrix();
|
||
}
|
||
return new DenseMatrix2(array);
|
||
}
|
||
}, {
|
||
from: "Matrix",
|
||
to: "Array",
|
||
convert: function convert(matrix2) {
|
||
return matrix2.valueOf();
|
||
}
|
||
}]);
|
||
typed2.onMismatch = (name2, args, signatures) => {
|
||
var usualError = typed2.createError(name2, args, signatures);
|
||
if (["wrongType", "mismatch"].includes(usualError.data.category) && args.length === 1 && isCollection(args[0]) && // check if the function can be unary:
|
||
signatures.some((sig) => !sig.params.includes(","))) {
|
||
var err = new TypeError("Function '".concat(name2, "' doesn't apply to matrices. To call it ") + "elementwise on a matrix 'M', try 'map(M, ".concat(name2, ")'."));
|
||
err.data = usualError.data;
|
||
throw err;
|
||
}
|
||
throw usualError;
|
||
};
|
||
typed2.onMismatch = (name2, args, signatures) => {
|
||
var usualError = typed2.createError(name2, args, signatures);
|
||
if (["wrongType", "mismatch"].includes(usualError.data.category) && args.length === 1 && isCollection(args[0]) && // check if the function can be unary:
|
||
signatures.some((sig) => !sig.params.includes(","))) {
|
||
var err = new TypeError("Function '".concat(name2, "' doesn't apply to matrices. To call it ") + "elementwise on a matrix 'M', try 'map(M, ".concat(name2, ")'."));
|
||
err.data = usualError.data;
|
||
throw err;
|
||
}
|
||
throw usualError;
|
||
};
|
||
return typed2;
|
||
});
|
||
function throwNoBignumber(x) {
|
||
throw new Error("Cannot convert value ".concat(x, " into a BigNumber: no class 'BigNumber' provided"));
|
||
}
|
||
function throwNoComplex(x) {
|
||
throw new Error("Cannot convert value ".concat(x, " into a Complex number: no class 'Complex' provided"));
|
||
}
|
||
function throwNoMatrix() {
|
||
throw new Error("Cannot convert array into a Matrix: no class 'DenseMatrix' provided");
|
||
}
|
||
function throwNoFraction(x) {
|
||
throw new Error("Cannot convert value ".concat(x, " into a Fraction, no class 'Fraction' provided."));
|
||
}
|
||
/*!
|
||
* decimal.js v10.4.3
|
||
* An arbitrary-precision Decimal type for JavaScript.
|
||
* https://github.com/MikeMcl/decimal.js
|
||
* Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
|
||
* MIT Licence
|
||
*/
|
||
var EXP_LIMIT = 9e15, MAX_DIGITS = 1e9, NUMERALS = "0123456789abcdef", LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058", PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789", DEFAULTS = {
|
||
// These values must be integers within the stated ranges (inclusive).
|
||
// Most of these values can be changed at run-time using the `Decimal.config` method.
|
||
// The maximum number of significant digits of the result of a calculation or base conversion.
|
||
// E.g. `Decimal.config({ precision: 20 });`
|
||
precision: 20,
|
||
// 1 to MAX_DIGITS
|
||
// The rounding mode used when rounding to `precision`.
|
||
//
|
||
// ROUND_UP 0 Away from zero.
|
||
// ROUND_DOWN 1 Towards zero.
|
||
// ROUND_CEIL 2 Towards +Infinity.
|
||
// ROUND_FLOOR 3 Towards -Infinity.
|
||
// ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
||
// ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
||
// ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
||
// ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
||
// ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
||
//
|
||
// E.g.
|
||
// `Decimal.rounding = 4;`
|
||
// `Decimal.rounding = Decimal.ROUND_HALF_UP;`
|
||
rounding: 4,
|
||
// 0 to 8
|
||
// The modulo mode used when calculating the modulus: a mod n.
|
||
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
||
// The remainder (r) is calculated as: r = a - n * q.
|
||
//
|
||
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
||
// DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
|
||
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
||
// HALF_EVEN 6 The IEEE 754 remainder function.
|
||
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
|
||
//
|
||
// Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
|
||
// division (9) are commonly used for the modulus operation. The other rounding modes can also
|
||
// be used, but they may not give useful results.
|
||
modulo: 1,
|
||
// 0 to 9
|
||
// The exponent value at and beneath which `toString` returns exponential notation.
|
||
// JavaScript numbers: -7
|
||
toExpNeg: -7,
|
||
// 0 to -EXP_LIMIT
|
||
// The exponent value at and above which `toString` returns exponential notation.
|
||
// JavaScript numbers: 21
|
||
toExpPos: 21,
|
||
// 0 to EXP_LIMIT
|
||
// The minimum exponent value, beneath which underflow to zero occurs.
|
||
// JavaScript numbers: -324 (5e-324)
|
||
minE: -EXP_LIMIT,
|
||
// -1 to -EXP_LIMIT
|
||
// The maximum exponent value, above which overflow to Infinity occurs.
|
||
// JavaScript numbers: 308 (1.7976931348623157e+308)
|
||
maxE: EXP_LIMIT,
|
||
// 1 to EXP_LIMIT
|
||
// Whether to use cryptographically-secure random number generation, if available.
|
||
crypto: false
|
||
// true/false
|
||
}, inexact, quadrant, external = true, decimalError = "[DecimalError] ", invalidArgument = decimalError + "Invalid argument: ", precisionLimitExceeded = decimalError + "Precision limit exceeded", cryptoUnavailable = decimalError + "crypto unavailable", tag = "[object Decimal]", mathfloor = Math.floor, mathpow = Math.pow, isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i, isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i, isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i, isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, BASE = 1e7, LOG_BASE = 7, MAX_SAFE_INTEGER = 9007199254740991, LN10_PRECISION = LN10.length - 1, PI_PRECISION = PI.length - 1, P$2 = { toStringTag: tag };
|
||
P$2.absoluteValue = P$2.abs = function() {
|
||
var x = new this.constructor(this);
|
||
if (x.s < 0)
|
||
x.s = 1;
|
||
return finalise(x);
|
||
};
|
||
P$2.ceil = function() {
|
||
return finalise(new this.constructor(this), this.e + 1, 2);
|
||
};
|
||
P$2.clampedTo = P$2.clamp = function(min2, max2) {
|
||
var k, x = this, Ctor = x.constructor;
|
||
min2 = new Ctor(min2);
|
||
max2 = new Ctor(max2);
|
||
if (!min2.s || !max2.s)
|
||
return new Ctor(NaN);
|
||
if (min2.gt(max2))
|
||
throw Error(invalidArgument + max2);
|
||
k = x.cmp(min2);
|
||
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
|
||
};
|
||
P$2.comparedTo = P$2.cmp = function(y) {
|
||
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
||
if (!xd || !yd) {
|
||
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
||
}
|
||
if (!xd[0] || !yd[0])
|
||
return xd[0] ? xs : yd[0] ? -ys : 0;
|
||
if (xs !== ys)
|
||
return xs;
|
||
if (x.e !== y.e)
|
||
return x.e > y.e ^ xs < 0 ? 1 : -1;
|
||
xdL = xd.length;
|
||
ydL = yd.length;
|
||
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
||
if (xd[i] !== yd[i])
|
||
return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
||
}
|
||
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
||
};
|
||
P$2.cosine = P$2.cos = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (!x.d)
|
||
return new Ctor(NaN);
|
||
if (!x.d[0])
|
||
return new Ctor(1);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
||
Ctor.rounding = 1;
|
||
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
||
};
|
||
P$2.cubeRoot = P$2.cbrt = function() {
|
||
var e2, m, n2, r, rep, s2, sd, t2, t3, t3plusx, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite() || x.isZero())
|
||
return new Ctor(x);
|
||
external = false;
|
||
s2 = x.s * mathpow(x.s * x, 1 / 3);
|
||
if (!s2 || Math.abs(s2) == 1 / 0) {
|
||
n2 = digitsToString(x.d);
|
||
e2 = x.e;
|
||
if (s2 = (e2 - n2.length + 1) % 3)
|
||
n2 += s2 == 1 || s2 == -2 ? "0" : "00";
|
||
s2 = mathpow(n2, 1 / 3);
|
||
e2 = mathfloor((e2 + 1) / 3) - (e2 % 3 == (e2 < 0 ? -1 : 2));
|
||
if (s2 == 1 / 0) {
|
||
n2 = "5e" + e2;
|
||
} else {
|
||
n2 = s2.toExponential();
|
||
n2 = n2.slice(0, n2.indexOf("e") + 1) + e2;
|
||
}
|
||
r = new Ctor(n2);
|
||
r.s = x.s;
|
||
} else {
|
||
r = new Ctor(s2.toString());
|
||
}
|
||
sd = (e2 = Ctor.precision) + 3;
|
||
for (; ; ) {
|
||
t2 = r;
|
||
t3 = t2.times(t2).times(t2);
|
||
t3plusx = t3.plus(x);
|
||
r = divide(t3plusx.plus(x).times(t2), t3plusx.plus(t3), sd + 2, 1);
|
||
if (digitsToString(t2.d).slice(0, sd) === (n2 = digitsToString(r.d)).slice(0, sd)) {
|
||
n2 = n2.slice(sd - 3, sd + 1);
|
||
if (n2 == "9999" || !rep && n2 == "4999") {
|
||
if (!rep) {
|
||
finalise(t2, e2 + 1, 0);
|
||
if (t2.times(t2).times(t2).eq(x)) {
|
||
r = t2;
|
||
break;
|
||
}
|
||
}
|
||
sd += 4;
|
||
rep = 1;
|
||
} else {
|
||
if (!+n2 || !+n2.slice(1) && n2.charAt(0) == "5") {
|
||
finalise(r, e2 + 1, 1);
|
||
m = !r.times(r).times(r).eq(x);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
external = true;
|
||
return finalise(r, e2, Ctor.rounding, m);
|
||
};
|
||
P$2.decimalPlaces = P$2.dp = function() {
|
||
var w, d = this.d, n2 = NaN;
|
||
if (d) {
|
||
w = d.length - 1;
|
||
n2 = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
||
w = d[w];
|
||
if (w)
|
||
for (; w % 10 == 0; w /= 10)
|
||
n2--;
|
||
if (n2 < 0)
|
||
n2 = 0;
|
||
}
|
||
return n2;
|
||
};
|
||
P$2.dividedBy = P$2.div = function(y) {
|
||
return divide(this, new this.constructor(y));
|
||
};
|
||
P$2.dividedToIntegerBy = P$2.divToInt = function(y) {
|
||
var x = this, Ctor = x.constructor;
|
||
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
||
};
|
||
P$2.equals = P$2.eq = function(y) {
|
||
return this.cmp(y) === 0;
|
||
};
|
||
P$2.floor = function() {
|
||
return finalise(new this.constructor(this), this.e + 1, 3);
|
||
};
|
||
P$2.greaterThan = P$2.gt = function(y) {
|
||
return this.cmp(y) > 0;
|
||
};
|
||
P$2.greaterThanOrEqualTo = P$2.gte = function(y) {
|
||
var k = this.cmp(y);
|
||
return k == 1 || k === 0;
|
||
};
|
||
P$2.hyperbolicCosine = P$2.cosh = function() {
|
||
var k, n2, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
||
if (!x.isFinite())
|
||
return new Ctor(x.s ? 1 / 0 : NaN);
|
||
if (x.isZero())
|
||
return one;
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
||
Ctor.rounding = 1;
|
||
len = x.d.length;
|
||
if (len < 32) {
|
||
k = Math.ceil(len / 3);
|
||
n2 = (1 / tinyPow(4, k)).toString();
|
||
} else {
|
||
k = 16;
|
||
n2 = "2.3283064365386962890625e-10";
|
||
}
|
||
x = taylorSeries(Ctor, 1, x.times(n2), new Ctor(1), true);
|
||
var cosh2_x, i = k, d8 = new Ctor(8);
|
||
for (; i--; ) {
|
||
cosh2_x = x.times(x);
|
||
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
||
}
|
||
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
||
};
|
||
P$2.hyperbolicSine = P$2.sinh = function() {
|
||
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite() || x.isZero())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
||
Ctor.rounding = 1;
|
||
len = x.d.length;
|
||
if (len < 3) {
|
||
x = taylorSeries(Ctor, 2, x, x, true);
|
||
} else {
|
||
k = 1.4 * Math.sqrt(len);
|
||
k = k > 16 ? 16 : k | 0;
|
||
x = x.times(1 / tinyPow(5, k));
|
||
x = taylorSeries(Ctor, 2, x, x, true);
|
||
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
||
for (; k--; ) {
|
||
sinh2_x = x.times(x);
|
||
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
||
}
|
||
}
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return finalise(x, pr, rm, true);
|
||
};
|
||
P$2.hyperbolicTangent = P$2.tanh = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite())
|
||
return new Ctor(x.s);
|
||
if (x.isZero())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + 7;
|
||
Ctor.rounding = 1;
|
||
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
||
};
|
||
P$2.inverseCosine = P$2.acos = function() {
|
||
var halfPi, x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
||
if (k !== -1) {
|
||
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
||
}
|
||
if (x.isZero())
|
||
return getPi(Ctor, pr + 4, rm).times(0.5);
|
||
Ctor.precision = pr + 6;
|
||
Ctor.rounding = 1;
|
||
x = x.asin();
|
||
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return halfPi.minus(x);
|
||
};
|
||
P$2.inverseHyperbolicCosine = P$2.acosh = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (x.lte(1))
|
||
return new Ctor(x.eq(1) ? 0 : NaN);
|
||
if (!x.isFinite())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
||
Ctor.rounding = 1;
|
||
external = false;
|
||
x = x.times(x).minus(1).sqrt().plus(x);
|
||
external = true;
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return x.ln();
|
||
};
|
||
P$2.inverseHyperbolicSine = P$2.asinh = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite() || x.isZero())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
||
Ctor.rounding = 1;
|
||
external = false;
|
||
x = x.times(x).plus(1).sqrt().plus(x);
|
||
external = true;
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return x.ln();
|
||
};
|
||
P$2.inverseHyperbolicTangent = P$2.atanh = function() {
|
||
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite())
|
||
return new Ctor(NaN);
|
||
if (x.e >= 0)
|
||
return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
xsd = x.sd();
|
||
if (Math.max(xsd, pr) < 2 * -x.e - 1)
|
||
return finalise(new Ctor(x), pr, rm, true);
|
||
Ctor.precision = wpr = xsd - x.e;
|
||
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
||
Ctor.precision = pr + 4;
|
||
Ctor.rounding = 1;
|
||
x = x.ln();
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return x.times(0.5);
|
||
};
|
||
P$2.inverseSine = P$2.asin = function() {
|
||
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
||
if (x.isZero())
|
||
return new Ctor(x);
|
||
k = x.abs().cmp(1);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
if (k !== -1) {
|
||
if (k === 0) {
|
||
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
||
halfPi.s = x.s;
|
||
return halfPi;
|
||
}
|
||
return new Ctor(NaN);
|
||
}
|
||
Ctor.precision = pr + 6;
|
||
Ctor.rounding = 1;
|
||
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return x.times(2);
|
||
};
|
||
P$2.inverseTangent = P$2.atan = function() {
|
||
var i, j, k, n2, px, t2, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
||
if (!x.isFinite()) {
|
||
if (!x.s)
|
||
return new Ctor(NaN);
|
||
if (pr + 4 <= PI_PRECISION) {
|
||
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
||
r.s = x.s;
|
||
return r;
|
||
}
|
||
} else if (x.isZero()) {
|
||
return new Ctor(x);
|
||
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
||
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
||
r.s = x.s;
|
||
return r;
|
||
}
|
||
Ctor.precision = wpr = pr + 10;
|
||
Ctor.rounding = 1;
|
||
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
||
for (i = k; i; --i)
|
||
x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
||
external = false;
|
||
j = Math.ceil(wpr / LOG_BASE);
|
||
n2 = 1;
|
||
x2 = x.times(x);
|
||
r = new Ctor(x);
|
||
px = x;
|
||
for (; i !== -1; ) {
|
||
px = px.times(x2);
|
||
t2 = r.minus(px.div(n2 += 2));
|
||
px = px.times(x2);
|
||
r = t2.plus(px.div(n2 += 2));
|
||
if (r.d[j] !== void 0)
|
||
for (i = j; r.d[i] === t2.d[i] && i--; )
|
||
;
|
||
}
|
||
if (k)
|
||
r = r.times(2 << k - 1);
|
||
external = true;
|
||
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
||
};
|
||
P$2.isFinite = function() {
|
||
return !!this.d;
|
||
};
|
||
P$2.isInteger = P$2.isInt = function() {
|
||
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
||
};
|
||
P$2.isNaN = function() {
|
||
return !this.s;
|
||
};
|
||
P$2.isNegative = P$2.isNeg = function() {
|
||
return this.s < 0;
|
||
};
|
||
P$2.isPositive = P$2.isPos = function() {
|
||
return this.s > 0;
|
||
};
|
||
P$2.isZero = function() {
|
||
return !!this.d && this.d[0] === 0;
|
||
};
|
||
P$2.lessThan = P$2.lt = function(y) {
|
||
return this.cmp(y) < 0;
|
||
};
|
||
P$2.lessThanOrEqualTo = P$2.lte = function(y) {
|
||
return this.cmp(y) < 1;
|
||
};
|
||
P$2.logarithm = P$2.log = function(base) {
|
||
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
||
if (base == null) {
|
||
base = new Ctor(10);
|
||
isBase10 = true;
|
||
} else {
|
||
base = new Ctor(base);
|
||
d = base.d;
|
||
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
||
return new Ctor(NaN);
|
||
isBase10 = base.eq(10);
|
||
}
|
||
d = arg.d;
|
||
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
||
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
||
}
|
||
if (isBase10) {
|
||
if (d.length > 1) {
|
||
inf = true;
|
||
} else {
|
||
for (k = d[0]; k % 10 === 0; )
|
||
k /= 10;
|
||
inf = k !== 1;
|
||
}
|
||
}
|
||
external = false;
|
||
sd = pr + guard;
|
||
num = naturalLogarithm(arg, sd);
|
||
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
||
r = divide(num, denominator, sd, 1);
|
||
if (checkRoundingDigits(r.d, k = pr, rm)) {
|
||
do {
|
||
sd += 10;
|
||
num = naturalLogarithm(arg, sd);
|
||
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
||
r = divide(num, denominator, sd, 1);
|
||
if (!inf) {
|
||
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
||
r = finalise(r, pr + 1, 0);
|
||
}
|
||
break;
|
||
}
|
||
} while (checkRoundingDigits(r.d, k += 10, rm));
|
||
}
|
||
external = true;
|
||
return finalise(r, pr, rm);
|
||
};
|
||
P$2.minus = P$2.sub = function(y) {
|
||
var d, e2, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
||
y = new Ctor(y);
|
||
if (!x.d || !y.d) {
|
||
if (!x.s || !y.s)
|
||
y = new Ctor(NaN);
|
||
else if (x.d)
|
||
y.s = -y.s;
|
||
else
|
||
y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
||
return y;
|
||
}
|
||
if (x.s != y.s) {
|
||
y.s = -y.s;
|
||
return x.plus(y);
|
||
}
|
||
xd = x.d;
|
||
yd = y.d;
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
if (!xd[0] || !yd[0]) {
|
||
if (yd[0])
|
||
y.s = -y.s;
|
||
else if (xd[0])
|
||
y = new Ctor(x);
|
||
else
|
||
return new Ctor(rm === 3 ? -0 : 0);
|
||
return external ? finalise(y, pr, rm) : y;
|
||
}
|
||
e2 = mathfloor(y.e / LOG_BASE);
|
||
xe = mathfloor(x.e / LOG_BASE);
|
||
xd = xd.slice();
|
||
k = xe - e2;
|
||
if (k) {
|
||
xLTy = k < 0;
|
||
if (xLTy) {
|
||
d = xd;
|
||
k = -k;
|
||
len = yd.length;
|
||
} else {
|
||
d = yd;
|
||
e2 = xe;
|
||
len = xd.length;
|
||
}
|
||
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
||
if (k > i) {
|
||
k = i;
|
||
d.length = 1;
|
||
}
|
||
d.reverse();
|
||
for (i = k; i--; )
|
||
d.push(0);
|
||
d.reverse();
|
||
} else {
|
||
i = xd.length;
|
||
len = yd.length;
|
||
xLTy = i < len;
|
||
if (xLTy)
|
||
len = i;
|
||
for (i = 0; i < len; i++) {
|
||
if (xd[i] != yd[i]) {
|
||
xLTy = xd[i] < yd[i];
|
||
break;
|
||
}
|
||
}
|
||
k = 0;
|
||
}
|
||
if (xLTy) {
|
||
d = xd;
|
||
xd = yd;
|
||
yd = d;
|
||
y.s = -y.s;
|
||
}
|
||
len = xd.length;
|
||
for (i = yd.length - len; i > 0; --i)
|
||
xd[len++] = 0;
|
||
for (i = yd.length; i > k; ) {
|
||
if (xd[--i] < yd[i]) {
|
||
for (j = i; j && xd[--j] === 0; )
|
||
xd[j] = BASE - 1;
|
||
--xd[j];
|
||
xd[i] += BASE;
|
||
}
|
||
xd[i] -= yd[i];
|
||
}
|
||
for (; xd[--len] === 0; )
|
||
xd.pop();
|
||
for (; xd[0] === 0; xd.shift())
|
||
--e2;
|
||
if (!xd[0])
|
||
return new Ctor(rm === 3 ? -0 : 0);
|
||
y.d = xd;
|
||
y.e = getBase10Exponent(xd, e2);
|
||
return external ? finalise(y, pr, rm) : y;
|
||
};
|
||
P$2.modulo = P$2.mod = function(y) {
|
||
var q, x = this, Ctor = x.constructor;
|
||
y = new Ctor(y);
|
||
if (!x.d || !y.s || y.d && !y.d[0])
|
||
return new Ctor(NaN);
|
||
if (!y.d || x.d && !x.d[0]) {
|
||
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
||
}
|
||
external = false;
|
||
if (Ctor.modulo == 9) {
|
||
q = divide(x, y.abs(), 0, 3, 1);
|
||
q.s *= y.s;
|
||
} else {
|
||
q = divide(x, y, 0, Ctor.modulo, 1);
|
||
}
|
||
q = q.times(y);
|
||
external = true;
|
||
return x.minus(q);
|
||
};
|
||
P$2.naturalExponential = P$2.exp = function() {
|
||
return naturalExponential(this);
|
||
};
|
||
P$2.naturalLogarithm = P$2.ln = function() {
|
||
return naturalLogarithm(this);
|
||
};
|
||
P$2.negated = P$2.neg = function() {
|
||
var x = new this.constructor(this);
|
||
x.s = -x.s;
|
||
return finalise(x);
|
||
};
|
||
P$2.plus = P$2.add = function(y) {
|
||
var carry, d, e2, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
||
y = new Ctor(y);
|
||
if (!x.d || !y.d) {
|
||
if (!x.s || !y.s)
|
||
y = new Ctor(NaN);
|
||
else if (!x.d)
|
||
y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
||
return y;
|
||
}
|
||
if (x.s != y.s) {
|
||
y.s = -y.s;
|
||
return x.minus(y);
|
||
}
|
||
xd = x.d;
|
||
yd = y.d;
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
if (!xd[0] || !yd[0]) {
|
||
if (!yd[0])
|
||
y = new Ctor(x);
|
||
return external ? finalise(y, pr, rm) : y;
|
||
}
|
||
k = mathfloor(x.e / LOG_BASE);
|
||
e2 = mathfloor(y.e / LOG_BASE);
|
||
xd = xd.slice();
|
||
i = k - e2;
|
||
if (i) {
|
||
if (i < 0) {
|
||
d = xd;
|
||
i = -i;
|
||
len = yd.length;
|
||
} else {
|
||
d = yd;
|
||
e2 = k;
|
||
len = xd.length;
|
||
}
|
||
k = Math.ceil(pr / LOG_BASE);
|
||
len = k > len ? k + 1 : len + 1;
|
||
if (i > len) {
|
||
i = len;
|
||
d.length = 1;
|
||
}
|
||
d.reverse();
|
||
for (; i--; )
|
||
d.push(0);
|
||
d.reverse();
|
||
}
|
||
len = xd.length;
|
||
i = yd.length;
|
||
if (len - i < 0) {
|
||
i = len;
|
||
d = yd;
|
||
yd = xd;
|
||
xd = d;
|
||
}
|
||
for (carry = 0; i; ) {
|
||
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
||
xd[i] %= BASE;
|
||
}
|
||
if (carry) {
|
||
xd.unshift(carry);
|
||
++e2;
|
||
}
|
||
for (len = xd.length; xd[--len] == 0; )
|
||
xd.pop();
|
||
y.d = xd;
|
||
y.e = getBase10Exponent(xd, e2);
|
||
return external ? finalise(y, pr, rm) : y;
|
||
};
|
||
P$2.precision = P$2.sd = function(z) {
|
||
var k, x = this;
|
||
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0)
|
||
throw Error(invalidArgument + z);
|
||
if (x.d) {
|
||
k = getPrecision(x.d);
|
||
if (z && x.e + 1 > k)
|
||
k = x.e + 1;
|
||
} else {
|
||
k = NaN;
|
||
}
|
||
return k;
|
||
};
|
||
P$2.round = function() {
|
||
var x = this, Ctor = x.constructor;
|
||
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
||
};
|
||
P$2.sine = P$2.sin = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite())
|
||
return new Ctor(NaN);
|
||
if (x.isZero())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
||
Ctor.rounding = 1;
|
||
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
||
};
|
||
P$2.squareRoot = P$2.sqrt = function() {
|
||
var m, n2, sd, r, rep, t2, x = this, d = x.d, e2 = x.e, s2 = x.s, Ctor = x.constructor;
|
||
if (s2 !== 1 || !d || !d[0]) {
|
||
return new Ctor(!s2 || s2 < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
||
}
|
||
external = false;
|
||
s2 = Math.sqrt(+x);
|
||
if (s2 == 0 || s2 == 1 / 0) {
|
||
n2 = digitsToString(d);
|
||
if ((n2.length + e2) % 2 == 0)
|
||
n2 += "0";
|
||
s2 = Math.sqrt(n2);
|
||
e2 = mathfloor((e2 + 1) / 2) - (e2 < 0 || e2 % 2);
|
||
if (s2 == 1 / 0) {
|
||
n2 = "5e" + e2;
|
||
} else {
|
||
n2 = s2.toExponential();
|
||
n2 = n2.slice(0, n2.indexOf("e") + 1) + e2;
|
||
}
|
||
r = new Ctor(n2);
|
||
} else {
|
||
r = new Ctor(s2.toString());
|
||
}
|
||
sd = (e2 = Ctor.precision) + 3;
|
||
for (; ; ) {
|
||
t2 = r;
|
||
r = t2.plus(divide(x, t2, sd + 2, 1)).times(0.5);
|
||
if (digitsToString(t2.d).slice(0, sd) === (n2 = digitsToString(r.d)).slice(0, sd)) {
|
||
n2 = n2.slice(sd - 3, sd + 1);
|
||
if (n2 == "9999" || !rep && n2 == "4999") {
|
||
if (!rep) {
|
||
finalise(t2, e2 + 1, 0);
|
||
if (t2.times(t2).eq(x)) {
|
||
r = t2;
|
||
break;
|
||
}
|
||
}
|
||
sd += 4;
|
||
rep = 1;
|
||
} else {
|
||
if (!+n2 || !+n2.slice(1) && n2.charAt(0) == "5") {
|
||
finalise(r, e2 + 1, 1);
|
||
m = !r.times(r).eq(x);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
external = true;
|
||
return finalise(r, e2, Ctor.rounding, m);
|
||
};
|
||
P$2.tangent = P$2.tan = function() {
|
||
var pr, rm, x = this, Ctor = x.constructor;
|
||
if (!x.isFinite())
|
||
return new Ctor(NaN);
|
||
if (x.isZero())
|
||
return new Ctor(x);
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
Ctor.precision = pr + 10;
|
||
Ctor.rounding = 1;
|
||
x = x.sin();
|
||
x.s = 1;
|
||
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
||
Ctor.precision = pr;
|
||
Ctor.rounding = rm;
|
||
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
||
};
|
||
P$2.times = P$2.mul = function(y) {
|
||
var carry, e2, i, k, r, rL, t2, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
||
y.s *= x.s;
|
||
if (!xd || !xd[0] || !yd || !yd[0]) {
|
||
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
||
}
|
||
e2 = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
||
xdL = xd.length;
|
||
ydL = yd.length;
|
||
if (xdL < ydL) {
|
||
r = xd;
|
||
xd = yd;
|
||
yd = r;
|
||
rL = xdL;
|
||
xdL = ydL;
|
||
ydL = rL;
|
||
}
|
||
r = [];
|
||
rL = xdL + ydL;
|
||
for (i = rL; i--; )
|
||
r.push(0);
|
||
for (i = ydL; --i >= 0; ) {
|
||
carry = 0;
|
||
for (k = xdL + i; k > i; ) {
|
||
t2 = r[k] + yd[i] * xd[k - i - 1] + carry;
|
||
r[k--] = t2 % BASE | 0;
|
||
carry = t2 / BASE | 0;
|
||
}
|
||
r[k] = (r[k] + carry) % BASE | 0;
|
||
}
|
||
for (; !r[--rL]; )
|
||
r.pop();
|
||
if (carry)
|
||
++e2;
|
||
else
|
||
r.shift();
|
||
y.d = r;
|
||
y.e = getBase10Exponent(r, e2);
|
||
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
||
};
|
||
P$2.toBinary = function(sd, rm) {
|
||
return toStringBinary(this, 2, sd, rm);
|
||
};
|
||
P$2.toDecimalPlaces = P$2.toDP = function(dp, rm) {
|
||
var x = this, Ctor = x.constructor;
|
||
x = new Ctor(x);
|
||
if (dp === void 0)
|
||
return x;
|
||
checkInt32(dp, 0, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
return finalise(x, dp + x.e + 1, rm);
|
||
};
|
||
P$2.toExponential = function(dp, rm) {
|
||
var str, x = this, Ctor = x.constructor;
|
||
if (dp === void 0) {
|
||
str = finiteToString(x, true);
|
||
} else {
|
||
checkInt32(dp, 0, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
x = finalise(new Ctor(x), dp + 1, rm);
|
||
str = finiteToString(x, true, dp + 1);
|
||
}
|
||
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
||
};
|
||
P$2.toFixed = function(dp, rm) {
|
||
var str, y, x = this, Ctor = x.constructor;
|
||
if (dp === void 0) {
|
||
str = finiteToString(x);
|
||
} else {
|
||
checkInt32(dp, 0, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
||
str = finiteToString(y, false, dp + y.e + 1);
|
||
}
|
||
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
||
};
|
||
P$2.toFraction = function(maxD) {
|
||
var d, d0, d1, d2, e2, k, n2, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
||
if (!xd)
|
||
return new Ctor(x);
|
||
n1 = d0 = new Ctor(1);
|
||
d1 = n0 = new Ctor(0);
|
||
d = new Ctor(d1);
|
||
e2 = d.e = getPrecision(xd) - x.e - 1;
|
||
k = e2 % LOG_BASE;
|
||
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
||
if (maxD == null) {
|
||
maxD = e2 > 0 ? d : n1;
|
||
} else {
|
||
n2 = new Ctor(maxD);
|
||
if (!n2.isInt() || n2.lt(n1))
|
||
throw Error(invalidArgument + n2);
|
||
maxD = n2.gt(d) ? e2 > 0 ? d : n1 : n2;
|
||
}
|
||
external = false;
|
||
n2 = new Ctor(digitsToString(xd));
|
||
pr = Ctor.precision;
|
||
Ctor.precision = e2 = xd.length * LOG_BASE * 2;
|
||
for (; ; ) {
|
||
q = divide(n2, d, 0, 1, 1);
|
||
d2 = d0.plus(q.times(d1));
|
||
if (d2.cmp(maxD) == 1)
|
||
break;
|
||
d0 = d1;
|
||
d1 = d2;
|
||
d2 = n1;
|
||
n1 = n0.plus(q.times(d2));
|
||
n0 = d2;
|
||
d2 = d;
|
||
d = n2.minus(q.times(d2));
|
||
n2 = d2;
|
||
}
|
||
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
||
n0 = n0.plus(d2.times(n1));
|
||
d0 = d0.plus(d2.times(d1));
|
||
n0.s = n1.s = x.s;
|
||
r = divide(n1, d1, e2, 1).minus(x).abs().cmp(divide(n0, d0, e2, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
||
Ctor.precision = pr;
|
||
external = true;
|
||
return r;
|
||
};
|
||
P$2.toHexadecimal = P$2.toHex = function(sd, rm) {
|
||
return toStringBinary(this, 16, sd, rm);
|
||
};
|
||
P$2.toNearest = function(y, rm) {
|
||
var x = this, Ctor = x.constructor;
|
||
x = new Ctor(x);
|
||
if (y == null) {
|
||
if (!x.d)
|
||
return x;
|
||
y = new Ctor(1);
|
||
rm = Ctor.rounding;
|
||
} else {
|
||
y = new Ctor(y);
|
||
if (rm === void 0) {
|
||
rm = Ctor.rounding;
|
||
} else {
|
||
checkInt32(rm, 0, 8);
|
||
}
|
||
if (!x.d)
|
||
return y.s ? x : y;
|
||
if (!y.d) {
|
||
if (y.s)
|
||
y.s = x.s;
|
||
return y;
|
||
}
|
||
}
|
||
if (y.d[0]) {
|
||
external = false;
|
||
x = divide(x, y, 0, rm, 1).times(y);
|
||
external = true;
|
||
finalise(x);
|
||
} else {
|
||
y.s = x.s;
|
||
x = y;
|
||
}
|
||
return x;
|
||
};
|
||
P$2.toNumber = function() {
|
||
return +this;
|
||
};
|
||
P$2.toOctal = function(sd, rm) {
|
||
return toStringBinary(this, 8, sd, rm);
|
||
};
|
||
P$2.toPower = P$2.pow = function(y) {
|
||
var e2, k, pr, r, rm, s2, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
||
if (!x.d || !y.d || !x.d[0] || !y.d[0])
|
||
return new Ctor(mathpow(+x, yn));
|
||
x = new Ctor(x);
|
||
if (x.eq(1))
|
||
return x;
|
||
pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
if (y.eq(1))
|
||
return finalise(x, pr, rm);
|
||
e2 = mathfloor(y.e / LOG_BASE);
|
||
if (e2 >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
||
r = intPow(Ctor, x, k, pr);
|
||
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
||
}
|
||
s2 = x.s;
|
||
if (s2 < 0) {
|
||
if (e2 < y.d.length - 1)
|
||
return new Ctor(NaN);
|
||
if ((y.d[e2] & 1) == 0)
|
||
s2 = 1;
|
||
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
||
x.s = s2;
|
||
return x;
|
||
}
|
||
}
|
||
k = mathpow(+x, yn);
|
||
e2 = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
||
if (e2 > Ctor.maxE + 1 || e2 < Ctor.minE - 1)
|
||
return new Ctor(e2 > 0 ? s2 / 0 : 0);
|
||
external = false;
|
||
Ctor.rounding = x.s = 1;
|
||
k = Math.min(12, (e2 + "").length);
|
||
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
||
if (r.d) {
|
||
r = finalise(r, pr + 5, 1);
|
||
if (checkRoundingDigits(r.d, pr, rm)) {
|
||
e2 = pr + 10;
|
||
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e2 + k)), e2), e2 + 5, 1);
|
||
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
||
r = finalise(r, pr + 1, 0);
|
||
}
|
||
}
|
||
}
|
||
r.s = s2;
|
||
external = true;
|
||
Ctor.rounding = rm;
|
||
return finalise(r, pr, rm);
|
||
};
|
||
P$2.toPrecision = function(sd, rm) {
|
||
var str, x = this, Ctor = x.constructor;
|
||
if (sd === void 0) {
|
||
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
||
} else {
|
||
checkInt32(sd, 1, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
x = finalise(new Ctor(x), sd, rm);
|
||
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
||
}
|
||
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
||
};
|
||
P$2.toSignificantDigits = P$2.toSD = function(sd, rm) {
|
||
var x = this, Ctor = x.constructor;
|
||
if (sd === void 0) {
|
||
sd = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
} else {
|
||
checkInt32(sd, 1, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
}
|
||
return finalise(new Ctor(x), sd, rm);
|
||
};
|
||
P$2.toString = function() {
|
||
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
||
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
||
};
|
||
P$2.truncated = P$2.trunc = function() {
|
||
return finalise(new this.constructor(this), this.e + 1, 1);
|
||
};
|
||
P$2.valueOf = P$2.toJSON = function() {
|
||
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
||
return x.isNeg() ? "-" + str : str;
|
||
};
|
||
function digitsToString(d) {
|
||
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
||
if (indexOfLastWord > 0) {
|
||
str += w;
|
||
for (i = 1; i < indexOfLastWord; i++) {
|
||
ws = d[i] + "";
|
||
k = LOG_BASE - ws.length;
|
||
if (k)
|
||
str += getZeroString(k);
|
||
str += ws;
|
||
}
|
||
w = d[i];
|
||
ws = w + "";
|
||
k = LOG_BASE - ws.length;
|
||
if (k)
|
||
str += getZeroString(k);
|
||
} else if (w === 0) {
|
||
return "0";
|
||
}
|
||
for (; w % 10 === 0; )
|
||
w /= 10;
|
||
return str + w;
|
||
}
|
||
function checkInt32(i, min2, max2) {
|
||
if (i !== ~~i || i < min2 || i > max2) {
|
||
throw Error(invalidArgument + i);
|
||
}
|
||
}
|
||
function checkRoundingDigits(d, i, rm, repeating) {
|
||
var di, k, r, rd;
|
||
for (k = d[0]; k >= 10; k /= 10)
|
||
--i;
|
||
if (--i < 0) {
|
||
i += LOG_BASE;
|
||
di = 0;
|
||
} else {
|
||
di = Math.ceil((i + 1) / LOG_BASE);
|
||
i %= LOG_BASE;
|
||
}
|
||
k = mathpow(10, LOG_BASE - i);
|
||
rd = d[di] % k | 0;
|
||
if (repeating == null) {
|
||
if (i < 3) {
|
||
if (i == 0)
|
||
rd = rd / 100 | 0;
|
||
else if (i == 1)
|
||
rd = rd / 10 | 0;
|
||
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
||
} else {
|
||
r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
|
||
}
|
||
} else {
|
||
if (i < 4) {
|
||
if (i == 0)
|
||
rd = rd / 1e3 | 0;
|
||
else if (i == 1)
|
||
rd = rd / 100 | 0;
|
||
else if (i == 2)
|
||
rd = rd / 10 | 0;
|
||
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
||
} else {
|
||
r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
|
||
}
|
||
}
|
||
return r;
|
||
}
|
||
function convertBase(str, baseIn, baseOut) {
|
||
var j, arr = [0], arrL, i = 0, strL = str.length;
|
||
for (; i < strL; ) {
|
||
for (arrL = arr.length; arrL--; )
|
||
arr[arrL] *= baseIn;
|
||
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
||
for (j = 0; j < arr.length; j++) {
|
||
if (arr[j] > baseOut - 1) {
|
||
if (arr[j + 1] === void 0)
|
||
arr[j + 1] = 0;
|
||
arr[j + 1] += arr[j] / baseOut | 0;
|
||
arr[j] %= baseOut;
|
||
}
|
||
}
|
||
}
|
||
return arr.reverse();
|
||
}
|
||
function cosine(Ctor, x) {
|
||
var k, len, y;
|
||
if (x.isZero())
|
||
return x;
|
||
len = x.d.length;
|
||
if (len < 32) {
|
||
k = Math.ceil(len / 3);
|
||
y = (1 / tinyPow(4, k)).toString();
|
||
} else {
|
||
k = 16;
|
||
y = "2.3283064365386962890625e-10";
|
||
}
|
||
Ctor.precision += k;
|
||
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
||
for (var i = k; i--; ) {
|
||
var cos2x = x.times(x);
|
||
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
||
}
|
||
Ctor.precision -= k;
|
||
return x;
|
||
}
|
||
var divide = /* @__PURE__ */ function() {
|
||
function multiplyInteger(x, k, base) {
|
||
var temp, carry = 0, i = x.length;
|
||
for (x = x.slice(); i--; ) {
|
||
temp = x[i] * k + carry;
|
||
x[i] = temp % base | 0;
|
||
carry = temp / base | 0;
|
||
}
|
||
if (carry)
|
||
x.unshift(carry);
|
||
return x;
|
||
}
|
||
function compare(a, b, aL, bL) {
|
||
var i, r;
|
||
if (aL != bL) {
|
||
r = aL > bL ? 1 : -1;
|
||
} else {
|
||
for (i = r = 0; i < aL; i++) {
|
||
if (a[i] != b[i]) {
|
||
r = a[i] > b[i] ? 1 : -1;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return r;
|
||
}
|
||
function subtract(a, b, aL, base) {
|
||
var i = 0;
|
||
for (; aL--; ) {
|
||
a[aL] -= i;
|
||
i = a[aL] < b[aL] ? 1 : 0;
|
||
a[aL] = i * base + a[aL] - b[aL];
|
||
}
|
||
for (; !a[0] && a.length > 1; )
|
||
a.shift();
|
||
}
|
||
return function(x, y, pr, rm, dp, base) {
|
||
var cmp, e2, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t2, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
||
if (!xd || !xd[0] || !yd || !yd[0]) {
|
||
return new Ctor(
|
||
// Return NaN if either NaN, or both Infinity or 0.
|
||
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
|
||
// Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
|
||
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
||
)
|
||
);
|
||
}
|
||
if (base) {
|
||
logBase = 1;
|
||
e2 = x.e - y.e;
|
||
} else {
|
||
base = BASE;
|
||
logBase = LOG_BASE;
|
||
e2 = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
||
}
|
||
yL = yd.length;
|
||
xL = xd.length;
|
||
q = new Ctor(sign2);
|
||
qd = q.d = [];
|
||
for (i = 0; yd[i] == (xd[i] || 0); i++)
|
||
;
|
||
if (yd[i] > (xd[i] || 0))
|
||
e2--;
|
||
if (pr == null) {
|
||
sd = pr = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
} else if (dp) {
|
||
sd = pr + (x.e - y.e) + 1;
|
||
} else {
|
||
sd = pr;
|
||
}
|
||
if (sd < 0) {
|
||
qd.push(1);
|
||
more = true;
|
||
} else {
|
||
sd = sd / logBase + 2 | 0;
|
||
i = 0;
|
||
if (yL == 1) {
|
||
k = 0;
|
||
yd = yd[0];
|
||
sd++;
|
||
for (; (i < xL || k) && sd--; i++) {
|
||
t2 = k * base + (xd[i] || 0);
|
||
qd[i] = t2 / yd | 0;
|
||
k = t2 % yd | 0;
|
||
}
|
||
more = k || i < xL;
|
||
} else {
|
||
k = base / (yd[0] + 1) | 0;
|
||
if (k > 1) {
|
||
yd = multiplyInteger(yd, k, base);
|
||
xd = multiplyInteger(xd, k, base);
|
||
yL = yd.length;
|
||
xL = xd.length;
|
||
}
|
||
xi = yL;
|
||
rem = xd.slice(0, yL);
|
||
remL = rem.length;
|
||
for (; remL < yL; )
|
||
rem[remL++] = 0;
|
||
yz = yd.slice();
|
||
yz.unshift(0);
|
||
yd0 = yd[0];
|
||
if (yd[1] >= base / 2)
|
||
++yd0;
|
||
do {
|
||
k = 0;
|
||
cmp = compare(yd, rem, yL, remL);
|
||
if (cmp < 0) {
|
||
rem0 = rem[0];
|
||
if (yL != remL)
|
||
rem0 = rem0 * base + (rem[1] || 0);
|
||
k = rem0 / yd0 | 0;
|
||
if (k > 1) {
|
||
if (k >= base)
|
||
k = base - 1;
|
||
prod = multiplyInteger(yd, k, base);
|
||
prodL = prod.length;
|
||
remL = rem.length;
|
||
cmp = compare(prod, rem, prodL, remL);
|
||
if (cmp == 1) {
|
||
k--;
|
||
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
||
}
|
||
} else {
|
||
if (k == 0)
|
||
cmp = k = 1;
|
||
prod = yd.slice();
|
||
}
|
||
prodL = prod.length;
|
||
if (prodL < remL)
|
||
prod.unshift(0);
|
||
subtract(rem, prod, remL, base);
|
||
if (cmp == -1) {
|
||
remL = rem.length;
|
||
cmp = compare(yd, rem, yL, remL);
|
||
if (cmp < 1) {
|
||
k++;
|
||
subtract(rem, yL < remL ? yz : yd, remL, base);
|
||
}
|
||
}
|
||
remL = rem.length;
|
||
} else if (cmp === 0) {
|
||
k++;
|
||
rem = [0];
|
||
}
|
||
qd[i++] = k;
|
||
if (cmp && rem[0]) {
|
||
rem[remL++] = xd[xi] || 0;
|
||
} else {
|
||
rem = [xd[xi]];
|
||
remL = 1;
|
||
}
|
||
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
||
more = rem[0] !== void 0;
|
||
}
|
||
if (!qd[0])
|
||
qd.shift();
|
||
}
|
||
if (logBase == 1) {
|
||
q.e = e2;
|
||
inexact = more;
|
||
} else {
|
||
for (i = 1, k = qd[0]; k >= 10; k /= 10)
|
||
i++;
|
||
q.e = i + e2 * logBase - 1;
|
||
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
||
}
|
||
return q;
|
||
};
|
||
}();
|
||
function finalise(x, sd, rm, isTruncated) {
|
||
var digits2, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
||
out:
|
||
if (sd != null) {
|
||
xd = x.d;
|
||
if (!xd)
|
||
return x;
|
||
for (digits2 = 1, k = xd[0]; k >= 10; k /= 10)
|
||
digits2++;
|
||
i = sd - digits2;
|
||
if (i < 0) {
|
||
i += LOG_BASE;
|
||
j = sd;
|
||
w = xd[xdi = 0];
|
||
rd = w / mathpow(10, digits2 - j - 1) % 10 | 0;
|
||
} else {
|
||
xdi = Math.ceil((i + 1) / LOG_BASE);
|
||
k = xd.length;
|
||
if (xdi >= k) {
|
||
if (isTruncated) {
|
||
for (; k++ <= xdi; )
|
||
xd.push(0);
|
||
w = rd = 0;
|
||
digits2 = 1;
|
||
i %= LOG_BASE;
|
||
j = i - LOG_BASE + 1;
|
||
} else {
|
||
break out;
|
||
}
|
||
} else {
|
||
w = k = xd[xdi];
|
||
for (digits2 = 1; k >= 10; k /= 10)
|
||
digits2++;
|
||
i %= LOG_BASE;
|
||
j = i - LOG_BASE + digits2;
|
||
rd = j < 0 ? 0 : w / mathpow(10, digits2 - j - 1) % 10 | 0;
|
||
}
|
||
}
|
||
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits2 - j - 1));
|
||
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
||
(i > 0 ? j > 0 ? w / mathpow(10, digits2 - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
||
if (sd < 1 || !xd[0]) {
|
||
xd.length = 0;
|
||
if (roundUp) {
|
||
sd -= x.e + 1;
|
||
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
||
x.e = -sd || 0;
|
||
} else {
|
||
xd[0] = x.e = 0;
|
||
}
|
||
return x;
|
||
}
|
||
if (i == 0) {
|
||
xd.length = xdi;
|
||
k = 1;
|
||
xdi--;
|
||
} else {
|
||
xd.length = xdi + 1;
|
||
k = mathpow(10, LOG_BASE - i);
|
||
xd[xdi] = j > 0 ? (w / mathpow(10, digits2 - j) % mathpow(10, j) | 0) * k : 0;
|
||
}
|
||
if (roundUp) {
|
||
for (; ; ) {
|
||
if (xdi == 0) {
|
||
for (i = 1, j = xd[0]; j >= 10; j /= 10)
|
||
i++;
|
||
j = xd[0] += k;
|
||
for (k = 1; j >= 10; j /= 10)
|
||
k++;
|
||
if (i != k) {
|
||
x.e++;
|
||
if (xd[0] == BASE)
|
||
xd[0] = 1;
|
||
}
|
||
break;
|
||
} else {
|
||
xd[xdi] += k;
|
||
if (xd[xdi] != BASE)
|
||
break;
|
||
xd[xdi--] = 0;
|
||
k = 1;
|
||
}
|
||
}
|
||
}
|
||
for (i = xd.length; xd[--i] === 0; )
|
||
xd.pop();
|
||
}
|
||
if (external) {
|
||
if (x.e > Ctor.maxE) {
|
||
x.d = null;
|
||
x.e = NaN;
|
||
} else if (x.e < Ctor.minE) {
|
||
x.e = 0;
|
||
x.d = [0];
|
||
}
|
||
}
|
||
return x;
|
||
}
|
||
function finiteToString(x, isExp, sd) {
|
||
if (!x.isFinite())
|
||
return nonFiniteToString(x);
|
||
var k, e2 = x.e, str = digitsToString(x.d), len = str.length;
|
||
if (isExp) {
|
||
if (sd && (k = sd - len) > 0) {
|
||
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
||
} else if (len > 1) {
|
||
str = str.charAt(0) + "." + str.slice(1);
|
||
}
|
||
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
||
} else if (e2 < 0) {
|
||
str = "0." + getZeroString(-e2 - 1) + str;
|
||
if (sd && (k = sd - len) > 0)
|
||
str += getZeroString(k);
|
||
} else if (e2 >= len) {
|
||
str += getZeroString(e2 + 1 - len);
|
||
if (sd && (k = sd - e2 - 1) > 0)
|
||
str = str + "." + getZeroString(k);
|
||
} else {
|
||
if ((k = e2 + 1) < len)
|
||
str = str.slice(0, k) + "." + str.slice(k);
|
||
if (sd && (k = sd - len) > 0) {
|
||
if (e2 + 1 === len)
|
||
str += ".";
|
||
str += getZeroString(k);
|
||
}
|
||
}
|
||
return str;
|
||
}
|
||
function getBase10Exponent(digits2, e2) {
|
||
var w = digits2[0];
|
||
for (e2 *= LOG_BASE; w >= 10; w /= 10)
|
||
e2++;
|
||
return e2;
|
||
}
|
||
function getLn10(Ctor, sd, pr) {
|
||
if (sd > LN10_PRECISION) {
|
||
external = true;
|
||
if (pr)
|
||
Ctor.precision = pr;
|
||
throw Error(precisionLimitExceeded);
|
||
}
|
||
return finalise(new Ctor(LN10), sd, 1, true);
|
||
}
|
||
function getPi(Ctor, sd, rm) {
|
||
if (sd > PI_PRECISION)
|
||
throw Error(precisionLimitExceeded);
|
||
return finalise(new Ctor(PI), sd, rm, true);
|
||
}
|
||
function getPrecision(digits2) {
|
||
var w = digits2.length - 1, len = w * LOG_BASE + 1;
|
||
w = digits2[w];
|
||
if (w) {
|
||
for (; w % 10 == 0; w /= 10)
|
||
len--;
|
||
for (w = digits2[0]; w >= 10; w /= 10)
|
||
len++;
|
||
}
|
||
return len;
|
||
}
|
||
function getZeroString(k) {
|
||
var zs = "";
|
||
for (; k--; )
|
||
zs += "0";
|
||
return zs;
|
||
}
|
||
function intPow(Ctor, x, n2, pr) {
|
||
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
||
external = false;
|
||
for (; ; ) {
|
||
if (n2 % 2) {
|
||
r = r.times(x);
|
||
if (truncate(r.d, k))
|
||
isTruncated = true;
|
||
}
|
||
n2 = mathfloor(n2 / 2);
|
||
if (n2 === 0) {
|
||
n2 = r.d.length - 1;
|
||
if (isTruncated && r.d[n2] === 0)
|
||
++r.d[n2];
|
||
break;
|
||
}
|
||
x = x.times(x);
|
||
truncate(x.d, k);
|
||
}
|
||
external = true;
|
||
return r;
|
||
}
|
||
function isOdd(n2) {
|
||
return n2.d[n2.d.length - 1] & 1;
|
||
}
|
||
function maxOrMin(Ctor, args, ltgt) {
|
||
var y, x = new Ctor(args[0]), i = 0;
|
||
for (; ++i < args.length; ) {
|
||
y = new Ctor(args[i]);
|
||
if (!y.s) {
|
||
x = y;
|
||
break;
|
||
} else if (x[ltgt](y)) {
|
||
x = y;
|
||
}
|
||
}
|
||
return x;
|
||
}
|
||
function naturalExponential(x, sd) {
|
||
var denominator, guard, j, pow2, sum2, t2, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
||
if (!x.d || !x.d[0] || x.e > 17) {
|
||
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
||
}
|
||
if (sd == null) {
|
||
external = false;
|
||
wpr = pr;
|
||
} else {
|
||
wpr = sd;
|
||
}
|
||
t2 = new Ctor(0.03125);
|
||
while (x.e > -2) {
|
||
x = x.times(t2);
|
||
k += 5;
|
||
}
|
||
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
||
wpr += guard;
|
||
denominator = pow2 = sum2 = new Ctor(1);
|
||
Ctor.precision = wpr;
|
||
for (; ; ) {
|
||
pow2 = finalise(pow2.times(x), wpr, 1);
|
||
denominator = denominator.times(++i);
|
||
t2 = sum2.plus(divide(pow2, denominator, wpr, 1));
|
||
if (digitsToString(t2.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
||
j = k;
|
||
while (j--)
|
||
sum2 = finalise(sum2.times(sum2), wpr, 1);
|
||
if (sd == null) {
|
||
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
||
Ctor.precision = wpr += 10;
|
||
denominator = pow2 = t2 = new Ctor(1);
|
||
i = 0;
|
||
rep++;
|
||
} else {
|
||
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
||
}
|
||
} else {
|
||
Ctor.precision = pr;
|
||
return sum2;
|
||
}
|
||
}
|
||
sum2 = t2;
|
||
}
|
||
}
|
||
function naturalLogarithm(y, sd) {
|
||
var c, c0, denominator, e2, numerator, rep, sum2, t2, wpr, x1, x2, n2 = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
||
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
||
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
||
}
|
||
if (sd == null) {
|
||
external = false;
|
||
wpr = pr;
|
||
} else {
|
||
wpr = sd;
|
||
}
|
||
Ctor.precision = wpr += guard;
|
||
c = digitsToString(xd);
|
||
c0 = c.charAt(0);
|
||
if (Math.abs(e2 = x.e) < 15e14) {
|
||
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
||
x = x.times(y);
|
||
c = digitsToString(x.d);
|
||
c0 = c.charAt(0);
|
||
n2++;
|
||
}
|
||
e2 = x.e;
|
||
if (c0 > 1) {
|
||
x = new Ctor("0." + c);
|
||
e2++;
|
||
} else {
|
||
x = new Ctor(c0 + "." + c.slice(1));
|
||
}
|
||
} else {
|
||
t2 = getLn10(Ctor, wpr + 2, pr).times(e2 + "");
|
||
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t2);
|
||
Ctor.precision = pr;
|
||
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
||
}
|
||
x1 = x;
|
||
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
||
x2 = finalise(x.times(x), wpr, 1);
|
||
denominator = 3;
|
||
for (; ; ) {
|
||
numerator = finalise(numerator.times(x2), wpr, 1);
|
||
t2 = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
||
if (digitsToString(t2.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
||
sum2 = sum2.times(2);
|
||
if (e2 !== 0)
|
||
sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e2 + ""));
|
||
sum2 = divide(sum2, new Ctor(n2), wpr, 1);
|
||
if (sd == null) {
|
||
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
||
Ctor.precision = wpr += guard;
|
||
t2 = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
||
x2 = finalise(x.times(x), wpr, 1);
|
||
denominator = rep = 1;
|
||
} else {
|
||
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
||
}
|
||
} else {
|
||
Ctor.precision = pr;
|
||
return sum2;
|
||
}
|
||
}
|
||
sum2 = t2;
|
||
denominator += 2;
|
||
}
|
||
}
|
||
function nonFiniteToString(x) {
|
||
return String(x.s * x.s / 0);
|
||
}
|
||
function parseDecimal(x, str) {
|
||
var e2, i, len;
|
||
if ((e2 = str.indexOf(".")) > -1)
|
||
str = str.replace(".", "");
|
||
if ((i = str.search(/e/i)) > 0) {
|
||
if (e2 < 0)
|
||
e2 = i;
|
||
e2 += +str.slice(i + 1);
|
||
str = str.substring(0, i);
|
||
} else if (e2 < 0) {
|
||
e2 = str.length;
|
||
}
|
||
for (i = 0; str.charCodeAt(i) === 48; i++)
|
||
;
|
||
for (len = str.length; str.charCodeAt(len - 1) === 48; --len)
|
||
;
|
||
str = str.slice(i, len);
|
||
if (str) {
|
||
len -= i;
|
||
x.e = e2 = e2 - i - 1;
|
||
x.d = [];
|
||
i = (e2 + 1) % LOG_BASE;
|
||
if (e2 < 0)
|
||
i += LOG_BASE;
|
||
if (i < len) {
|
||
if (i)
|
||
x.d.push(+str.slice(0, i));
|
||
for (len -= LOG_BASE; i < len; )
|
||
x.d.push(+str.slice(i, i += LOG_BASE));
|
||
str = str.slice(i);
|
||
i = LOG_BASE - str.length;
|
||
} else {
|
||
i -= len;
|
||
}
|
||
for (; i--; )
|
||
str += "0";
|
||
x.d.push(+str);
|
||
if (external) {
|
||
if (x.e > x.constructor.maxE) {
|
||
x.d = null;
|
||
x.e = NaN;
|
||
} else if (x.e < x.constructor.minE) {
|
||
x.e = 0;
|
||
x.d = [0];
|
||
}
|
||
}
|
||
} else {
|
||
x.e = 0;
|
||
x.d = [0];
|
||
}
|
||
return x;
|
||
}
|
||
function parseOther(x, str) {
|
||
var base, Ctor, divisor, i, isFloat, len, p2, xd, xe;
|
||
if (str.indexOf("_") > -1) {
|
||
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
||
if (isDecimal.test(str))
|
||
return parseDecimal(x, str);
|
||
} else if (str === "Infinity" || str === "NaN") {
|
||
if (!+str)
|
||
x.s = NaN;
|
||
x.e = NaN;
|
||
x.d = null;
|
||
return x;
|
||
}
|
||
if (isHex.test(str)) {
|
||
base = 16;
|
||
str = str.toLowerCase();
|
||
} else if (isBinary.test(str)) {
|
||
base = 2;
|
||
} else if (isOctal.test(str)) {
|
||
base = 8;
|
||
} else {
|
||
throw Error(invalidArgument + str);
|
||
}
|
||
i = str.search(/p/i);
|
||
if (i > 0) {
|
||
p2 = +str.slice(i + 1);
|
||
str = str.substring(2, i);
|
||
} else {
|
||
str = str.slice(2);
|
||
}
|
||
i = str.indexOf(".");
|
||
isFloat = i >= 0;
|
||
Ctor = x.constructor;
|
||
if (isFloat) {
|
||
str = str.replace(".", "");
|
||
len = str.length;
|
||
i = len - i;
|
||
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
||
}
|
||
xd = convertBase(str, base, BASE);
|
||
xe = xd.length - 1;
|
||
for (i = xe; xd[i] === 0; --i)
|
||
xd.pop();
|
||
if (i < 0)
|
||
return new Ctor(x.s * 0);
|
||
x.e = getBase10Exponent(xd, xe);
|
||
x.d = xd;
|
||
external = false;
|
||
if (isFloat)
|
||
x = divide(x, divisor, len * 4);
|
||
if (p2)
|
||
x = x.times(Math.abs(p2) < 54 ? mathpow(2, p2) : Decimal.pow(2, p2));
|
||
external = true;
|
||
return x;
|
||
}
|
||
function sine(Ctor, x) {
|
||
var k, len = x.d.length;
|
||
if (len < 3) {
|
||
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
||
}
|
||
k = 1.4 * Math.sqrt(len);
|
||
k = k > 16 ? 16 : k | 0;
|
||
x = x.times(1 / tinyPow(5, k));
|
||
x = taylorSeries(Ctor, 2, x, x);
|
||
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
||
for (; k--; ) {
|
||
sin2_x = x.times(x);
|
||
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
||
}
|
||
return x;
|
||
}
|
||
function taylorSeries(Ctor, n2, x, y, isHyperbolic) {
|
||
var j, t2, u, x2, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
||
external = false;
|
||
x2 = x.times(x);
|
||
u = new Ctor(y);
|
||
for (; ; ) {
|
||
t2 = divide(u.times(x2), new Ctor(n2++ * n2++), pr, 1);
|
||
u = isHyperbolic ? y.plus(t2) : y.minus(t2);
|
||
y = divide(t2.times(x2), new Ctor(n2++ * n2++), pr, 1);
|
||
t2 = u.plus(y);
|
||
if (t2.d[k] !== void 0) {
|
||
for (j = k; t2.d[j] === u.d[j] && j--; )
|
||
;
|
||
if (j == -1)
|
||
break;
|
||
}
|
||
j = u;
|
||
u = y;
|
||
y = t2;
|
||
t2 = j;
|
||
}
|
||
external = true;
|
||
t2.d.length = k + 1;
|
||
return t2;
|
||
}
|
||
function tinyPow(b, e2) {
|
||
var n2 = b;
|
||
while (--e2)
|
||
n2 *= b;
|
||
return n2;
|
||
}
|
||
function toLessThanHalfPi(Ctor, x) {
|
||
var t2, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
||
x = x.abs();
|
||
if (x.lte(halfPi)) {
|
||
quadrant = isNeg ? 4 : 1;
|
||
return x;
|
||
}
|
||
t2 = x.divToInt(pi);
|
||
if (t2.isZero()) {
|
||
quadrant = isNeg ? 3 : 2;
|
||
} else {
|
||
x = x.minus(t2.times(pi));
|
||
if (x.lte(halfPi)) {
|
||
quadrant = isOdd(t2) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
||
return x;
|
||
}
|
||
quadrant = isOdd(t2) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
||
}
|
||
return x.minus(pi).abs();
|
||
}
|
||
function toStringBinary(x, baseOut, sd, rm) {
|
||
var base, e2, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
|
||
if (isExp) {
|
||
checkInt32(sd, 1, MAX_DIGITS);
|
||
if (rm === void 0)
|
||
rm = Ctor.rounding;
|
||
else
|
||
checkInt32(rm, 0, 8);
|
||
} else {
|
||
sd = Ctor.precision;
|
||
rm = Ctor.rounding;
|
||
}
|
||
if (!x.isFinite()) {
|
||
str = nonFiniteToString(x);
|
||
} else {
|
||
str = finiteToString(x);
|
||
i = str.indexOf(".");
|
||
if (isExp) {
|
||
base = 2;
|
||
if (baseOut == 16) {
|
||
sd = sd * 4 - 3;
|
||
} else if (baseOut == 8) {
|
||
sd = sd * 3 - 2;
|
||
}
|
||
} else {
|
||
base = baseOut;
|
||
}
|
||
if (i >= 0) {
|
||
str = str.replace(".", "");
|
||
y = new Ctor(1);
|
||
y.e = str.length - i;
|
||
y.d = convertBase(finiteToString(y), 10, base);
|
||
y.e = y.d.length;
|
||
}
|
||
xd = convertBase(str, 10, base);
|
||
e2 = len = xd.length;
|
||
for (; xd[--len] == 0; )
|
||
xd.pop();
|
||
if (!xd[0]) {
|
||
str = isExp ? "0p+0" : "0";
|
||
} else {
|
||
if (i < 0) {
|
||
e2--;
|
||
} else {
|
||
x = new Ctor(x);
|
||
x.d = xd;
|
||
x.e = e2;
|
||
x = divide(x, y, sd, rm, 0, base);
|
||
xd = x.d;
|
||
e2 = x.e;
|
||
roundUp = inexact;
|
||
}
|
||
i = xd[sd];
|
||
k = base / 2;
|
||
roundUp = roundUp || xd[sd + 1] !== void 0;
|
||
roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
|
||
xd.length = sd;
|
||
if (roundUp) {
|
||
for (; ++xd[--sd] > base - 1; ) {
|
||
xd[sd] = 0;
|
||
if (!sd) {
|
||
++e2;
|
||
xd.unshift(1);
|
||
}
|
||
}
|
||
}
|
||
for (len = xd.length; !xd[len - 1]; --len)
|
||
;
|
||
for (i = 0, str = ""; i < len; i++)
|
||
str += NUMERALS.charAt(xd[i]);
|
||
if (isExp) {
|
||
if (len > 1) {
|
||
if (baseOut == 16 || baseOut == 8) {
|
||
i = baseOut == 16 ? 4 : 3;
|
||
for (--len; len % i; len++)
|
||
str += "0";
|
||
xd = convertBase(str, base, baseOut);
|
||
for (len = xd.length; !xd[len - 1]; --len)
|
||
;
|
||
for (i = 1, str = "1."; i < len; i++)
|
||
str += NUMERALS.charAt(xd[i]);
|
||
} else {
|
||
str = str.charAt(0) + "." + str.slice(1);
|
||
}
|
||
}
|
||
str = str + (e2 < 0 ? "p" : "p+") + e2;
|
||
} else if (e2 < 0) {
|
||
for (; ++e2; )
|
||
str = "0" + str;
|
||
str = "0." + str;
|
||
} else {
|
||
if (++e2 > len)
|
||
for (e2 -= len; e2--; )
|
||
str += "0";
|
||
else if (e2 < len)
|
||
str = str.slice(0, e2) + "." + str.slice(e2);
|
||
}
|
||
}
|
||
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
||
}
|
||
return x.s < 0 ? "-" + str : str;
|
||
}
|
||
function truncate(arr, len) {
|
||
if (arr.length > len) {
|
||
arr.length = len;
|
||
return true;
|
||
}
|
||
}
|
||
function abs(x) {
|
||
return new this(x).abs();
|
||
}
|
||
function acos(x) {
|
||
return new this(x).acos();
|
||
}
|
||
function acosh(x) {
|
||
return new this(x).acosh();
|
||
}
|
||
function add(x, y) {
|
||
return new this(x).plus(y);
|
||
}
|
||
function asin(x) {
|
||
return new this(x).asin();
|
||
}
|
||
function asinh(x) {
|
||
return new this(x).asinh();
|
||
}
|
||
function atan(x) {
|
||
return new this(x).atan();
|
||
}
|
||
function atanh(x) {
|
||
return new this(x).atanh();
|
||
}
|
||
function atan2(y, x) {
|
||
y = new this(y);
|
||
x = new this(x);
|
||
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
||
if (!y.s || !x.s) {
|
||
r = new this(NaN);
|
||
} else if (!y.d && !x.d) {
|
||
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
||
r.s = y.s;
|
||
} else if (!x.d || y.isZero()) {
|
||
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
||
r.s = y.s;
|
||
} else if (!y.d || x.isZero()) {
|
||
r = getPi(this, wpr, 1).times(0.5);
|
||
r.s = y.s;
|
||
} else if (x.s < 0) {
|
||
this.precision = wpr;
|
||
this.rounding = 1;
|
||
r = this.atan(divide(y, x, wpr, 1));
|
||
x = getPi(this, wpr, 1);
|
||
this.precision = pr;
|
||
this.rounding = rm;
|
||
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
||
} else {
|
||
r = this.atan(divide(y, x, wpr, 1));
|
||
}
|
||
return r;
|
||
}
|
||
function cbrt(x) {
|
||
return new this(x).cbrt();
|
||
}
|
||
function ceil(x) {
|
||
return finalise(x = new this(x), x.e + 1, 2);
|
||
}
|
||
function clamp(x, min2, max2) {
|
||
return new this(x).clamp(min2, max2);
|
||
}
|
||
function config2(obj) {
|
||
if (!obj || typeof obj !== "object")
|
||
throw Error(decimalError + "Object expected");
|
||
var i, p2, v, useDefaults = obj.defaults === true, ps = [
|
||
"precision",
|
||
1,
|
||
MAX_DIGITS,
|
||
"rounding",
|
||
0,
|
||
8,
|
||
"toExpNeg",
|
||
-EXP_LIMIT,
|
||
0,
|
||
"toExpPos",
|
||
0,
|
||
EXP_LIMIT,
|
||
"maxE",
|
||
0,
|
||
EXP_LIMIT,
|
||
"minE",
|
||
-EXP_LIMIT,
|
||
0,
|
||
"modulo",
|
||
0,
|
||
9
|
||
];
|
||
for (i = 0; i < ps.length; i += 3) {
|
||
if (p2 = ps[i], useDefaults)
|
||
this[p2] = DEFAULTS[p2];
|
||
if ((v = obj[p2]) !== void 0) {
|
||
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
||
this[p2] = v;
|
||
else
|
||
throw Error(invalidArgument + p2 + ": " + v);
|
||
}
|
||
}
|
||
if (p2 = "crypto", useDefaults)
|
||
this[p2] = DEFAULTS[p2];
|
||
if ((v = obj[p2]) !== void 0) {
|
||
if (v === true || v === false || v === 0 || v === 1) {
|
||
if (v) {
|
||
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
||
this[p2] = true;
|
||
} else {
|
||
throw Error(cryptoUnavailable);
|
||
}
|
||
} else {
|
||
this[p2] = false;
|
||
}
|
||
} else {
|
||
throw Error(invalidArgument + p2 + ": " + v);
|
||
}
|
||
}
|
||
return this;
|
||
}
|
||
function cos(x) {
|
||
return new this(x).cos();
|
||
}
|
||
function cosh$1(x) {
|
||
return new this(x).cosh();
|
||
}
|
||
function clone$1(obj) {
|
||
var i, p2, ps;
|
||
function Decimal2(v) {
|
||
var e2, i2, t2, x = this;
|
||
if (!(x instanceof Decimal2))
|
||
return new Decimal2(v);
|
||
x.constructor = Decimal2;
|
||
if (isDecimalInstance(v)) {
|
||
x.s = v.s;
|
||
if (external) {
|
||
if (!v.d || v.e > Decimal2.maxE) {
|
||
x.e = NaN;
|
||
x.d = null;
|
||
} else if (v.e < Decimal2.minE) {
|
||
x.e = 0;
|
||
x.d = [0];
|
||
} else {
|
||
x.e = v.e;
|
||
x.d = v.d.slice();
|
||
}
|
||
} else {
|
||
x.e = v.e;
|
||
x.d = v.d ? v.d.slice() : v.d;
|
||
}
|
||
return;
|
||
}
|
||
t2 = typeof v;
|
||
if (t2 === "number") {
|
||
if (v === 0) {
|
||
x.s = 1 / v < 0 ? -1 : 1;
|
||
x.e = 0;
|
||
x.d = [0];
|
||
return;
|
||
}
|
||
if (v < 0) {
|
||
v = -v;
|
||
x.s = -1;
|
||
} else {
|
||
x.s = 1;
|
||
}
|
||
if (v === ~~v && v < 1e7) {
|
||
for (e2 = 0, i2 = v; i2 >= 10; i2 /= 10)
|
||
e2++;
|
||
if (external) {
|
||
if (e2 > Decimal2.maxE) {
|
||
x.e = NaN;
|
||
x.d = null;
|
||
} else if (e2 < Decimal2.minE) {
|
||
x.e = 0;
|
||
x.d = [0];
|
||
} else {
|
||
x.e = e2;
|
||
x.d = [v];
|
||
}
|
||
} else {
|
||
x.e = e2;
|
||
x.d = [v];
|
||
}
|
||
return;
|
||
} else if (v * 0 !== 0) {
|
||
if (!v)
|
||
x.s = NaN;
|
||
x.e = NaN;
|
||
x.d = null;
|
||
return;
|
||
}
|
||
return parseDecimal(x, v.toString());
|
||
} else if (t2 !== "string") {
|
||
throw Error(invalidArgument + v);
|
||
}
|
||
if ((i2 = v.charCodeAt(0)) === 45) {
|
||
v = v.slice(1);
|
||
x.s = -1;
|
||
} else {
|
||
if (i2 === 43)
|
||
v = v.slice(1);
|
||
x.s = 1;
|
||
}
|
||
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
||
}
|
||
Decimal2.prototype = P$2;
|
||
Decimal2.ROUND_UP = 0;
|
||
Decimal2.ROUND_DOWN = 1;
|
||
Decimal2.ROUND_CEIL = 2;
|
||
Decimal2.ROUND_FLOOR = 3;
|
||
Decimal2.ROUND_HALF_UP = 4;
|
||
Decimal2.ROUND_HALF_DOWN = 5;
|
||
Decimal2.ROUND_HALF_EVEN = 6;
|
||
Decimal2.ROUND_HALF_CEIL = 7;
|
||
Decimal2.ROUND_HALF_FLOOR = 8;
|
||
Decimal2.EUCLID = 9;
|
||
Decimal2.config = Decimal2.set = config2;
|
||
Decimal2.clone = clone$1;
|
||
Decimal2.isDecimal = isDecimalInstance;
|
||
Decimal2.abs = abs;
|
||
Decimal2.acos = acos;
|
||
Decimal2.acosh = acosh;
|
||
Decimal2.add = add;
|
||
Decimal2.asin = asin;
|
||
Decimal2.asinh = asinh;
|
||
Decimal2.atan = atan;
|
||
Decimal2.atanh = atanh;
|
||
Decimal2.atan2 = atan2;
|
||
Decimal2.cbrt = cbrt;
|
||
Decimal2.ceil = ceil;
|
||
Decimal2.clamp = clamp;
|
||
Decimal2.cos = cos;
|
||
Decimal2.cosh = cosh$1;
|
||
Decimal2.div = div;
|
||
Decimal2.exp = exp;
|
||
Decimal2.floor = floor;
|
||
Decimal2.hypot = hypot$1;
|
||
Decimal2.ln = ln;
|
||
Decimal2.log = log;
|
||
Decimal2.log10 = log10;
|
||
Decimal2.log2 = log2;
|
||
Decimal2.max = max;
|
||
Decimal2.min = min;
|
||
Decimal2.mod = mod;
|
||
Decimal2.mul = mul;
|
||
Decimal2.pow = pow;
|
||
Decimal2.random = random;
|
||
Decimal2.round = round$1;
|
||
Decimal2.sign = sign;
|
||
Decimal2.sin = sin;
|
||
Decimal2.sinh = sinh$1;
|
||
Decimal2.sqrt = sqrt;
|
||
Decimal2.sub = sub;
|
||
Decimal2.sum = sum;
|
||
Decimal2.tan = tan;
|
||
Decimal2.tanh = tanh;
|
||
Decimal2.trunc = trunc$1;
|
||
if (obj === void 0)
|
||
obj = {};
|
||
if (obj) {
|
||
if (obj.defaults !== true) {
|
||
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
||
for (i = 0; i < ps.length; )
|
||
if (!obj.hasOwnProperty(p2 = ps[i++]))
|
||
obj[p2] = this[p2];
|
||
}
|
||
}
|
||
Decimal2.config(obj);
|
||
return Decimal2;
|
||
}
|
||
function div(x, y) {
|
||
return new this(x).div(y);
|
||
}
|
||
function exp(x) {
|
||
return new this(x).exp();
|
||
}
|
||
function floor(x) {
|
||
return finalise(x = new this(x), x.e + 1, 3);
|
||
}
|
||
function hypot$1() {
|
||
var i, n2, t2 = new this(0);
|
||
external = false;
|
||
for (i = 0; i < arguments.length; ) {
|
||
n2 = new this(arguments[i++]);
|
||
if (!n2.d) {
|
||
if (n2.s) {
|
||
external = true;
|
||
return new this(1 / 0);
|
||
}
|
||
t2 = n2;
|
||
} else if (t2.d) {
|
||
t2 = t2.plus(n2.times(n2));
|
||
}
|
||
}
|
||
external = true;
|
||
return t2.sqrt();
|
||
}
|
||
function isDecimalInstance(obj) {
|
||
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
||
}
|
||
function ln(x) {
|
||
return new this(x).ln();
|
||
}
|
||
function log(x, y) {
|
||
return new this(x).log(y);
|
||
}
|
||
function log2(x) {
|
||
return new this(x).log(2);
|
||
}
|
||
function log10(x) {
|
||
return new this(x).log(10);
|
||
}
|
||
function max() {
|
||
return maxOrMin(this, arguments, "lt");
|
||
}
|
||
function min() {
|
||
return maxOrMin(this, arguments, "gt");
|
||
}
|
||
function mod(x, y) {
|
||
return new this(x).mod(y);
|
||
}
|
||
function mul(x, y) {
|
||
return new this(x).mul(y);
|
||
}
|
||
function pow(x, y) {
|
||
return new this(x).pow(y);
|
||
}
|
||
function random(sd) {
|
||
var d, e2, k, n2, i = 0, r = new this(1), rd = [];
|
||
if (sd === void 0)
|
||
sd = this.precision;
|
||
else
|
||
checkInt32(sd, 1, MAX_DIGITS);
|
||
k = Math.ceil(sd / LOG_BASE);
|
||
if (!this.crypto) {
|
||
for (; i < k; )
|
||
rd[i++] = Math.random() * 1e7 | 0;
|
||
} else if (crypto.getRandomValues) {
|
||
d = crypto.getRandomValues(new Uint32Array(k));
|
||
for (; i < k; ) {
|
||
n2 = d[i];
|
||
if (n2 >= 429e7) {
|
||
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
||
} else {
|
||
rd[i++] = n2 % 1e7;
|
||
}
|
||
}
|
||
} else if (crypto.randomBytes) {
|
||
d = crypto.randomBytes(k *= 4);
|
||
for (; i < k; ) {
|
||
n2 = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
||
if (n2 >= 214e7) {
|
||
crypto.randomBytes(4).copy(d, i);
|
||
} else {
|
||
rd.push(n2 % 1e7);
|
||
i += 4;
|
||
}
|
||
}
|
||
i = k / 4;
|
||
} else {
|
||
throw Error(cryptoUnavailable);
|
||
}
|
||
k = rd[--i];
|
||
sd %= LOG_BASE;
|
||
if (k && sd) {
|
||
n2 = mathpow(10, LOG_BASE - sd);
|
||
rd[i] = (k / n2 | 0) * n2;
|
||
}
|
||
for (; rd[i] === 0; i--)
|
||
rd.pop();
|
||
if (i < 0) {
|
||
e2 = 0;
|
||
rd = [0];
|
||
} else {
|
||
e2 = -1;
|
||
for (; rd[0] === 0; e2 -= LOG_BASE)
|
||
rd.shift();
|
||
for (k = 1, n2 = rd[0]; n2 >= 10; n2 /= 10)
|
||
k++;
|
||
if (k < LOG_BASE)
|
||
e2 -= LOG_BASE - k;
|
||
}
|
||
r.e = e2;
|
||
r.d = rd;
|
||
return r;
|
||
}
|
||
function round$1(x) {
|
||
return finalise(x = new this(x), x.e + 1, this.rounding);
|
||
}
|
||
function sign(x) {
|
||
x = new this(x);
|
||
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
||
}
|
||
function sin(x) {
|
||
return new this(x).sin();
|
||
}
|
||
function sinh$1(x) {
|
||
return new this(x).sinh();
|
||
}
|
||
function sqrt(x) {
|
||
return new this(x).sqrt();
|
||
}
|
||
function sub(x, y) {
|
||
return new this(x).sub(y);
|
||
}
|
||
function sum() {
|
||
var i = 0, args = arguments, x = new this(args[i]);
|
||
external = false;
|
||
for (; x.s && ++i < args.length; )
|
||
x = x.plus(args[i]);
|
||
external = true;
|
||
return finalise(x, this.precision, this.rounding);
|
||
}
|
||
function tan(x) {
|
||
return new this(x).tan();
|
||
}
|
||
function tanh(x) {
|
||
return new this(x).tanh();
|
||
}
|
||
function trunc$1(x) {
|
||
return finalise(x = new this(x), x.e + 1, 1);
|
||
}
|
||
P$2[Symbol.for("nodejs.util.inspect.custom")] = P$2.toString;
|
||
P$2[Symbol.toStringTag] = "Decimal";
|
||
var Decimal = P$2.constructor = clone$1(DEFAULTS);
|
||
LN10 = new Decimal(LN10);
|
||
PI = new Decimal(PI);
|
||
var name$c = "BigNumber";
|
||
var dependencies$c = ["?on", "config"];
|
||
var createBigNumberClass = /* @__PURE__ */ factory(name$c, dependencies$c, (_ref) => {
|
||
var {
|
||
on,
|
||
config: config3
|
||
} = _ref;
|
||
var BigNumber2 = Decimal.clone({
|
||
precision: config3.precision,
|
||
modulo: Decimal.EUCLID
|
||
});
|
||
BigNumber2.prototype = Object.create(BigNumber2.prototype);
|
||
BigNumber2.prototype.type = "BigNumber";
|
||
BigNumber2.prototype.isBigNumber = true;
|
||
BigNumber2.prototype.toJSON = function() {
|
||
return {
|
||
mathjs: "BigNumber",
|
||
value: this.toString()
|
||
};
|
||
};
|
||
BigNumber2.fromJSON = function(json) {
|
||
return new BigNumber2(json.value);
|
||
};
|
||
if (on) {
|
||
on("config", function(curr, prev) {
|
||
if (curr.precision !== prev.precision) {
|
||
BigNumber2.config({
|
||
precision: curr.precision
|
||
});
|
||
}
|
||
});
|
||
}
|
||
return BigNumber2;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
const cosh = Math.cosh || function(x) {
|
||
return Math.abs(x) < 1e-9 ? 1 - x : (Math.exp(x) + Math.exp(-x)) * 0.5;
|
||
};
|
||
const sinh = Math.sinh || function(x) {
|
||
return Math.abs(x) < 1e-9 ? x : (Math.exp(x) - Math.exp(-x)) * 0.5;
|
||
};
|
||
const cosm1 = function(x) {
|
||
const b = Math.PI / 4;
|
||
if (-b > x || x > b) {
|
||
return Math.cos(x) - 1;
|
||
}
|
||
const xx = x * x;
|
||
return xx * (xx * (xx * (xx * (xx * (xx * (xx * (xx / 20922789888e3 - 1 / 87178291200) + 1 / 479001600) - 1 / 3628800) + 1 / 40320) - 1 / 720) + 1 / 24) - 1 / 2);
|
||
};
|
||
const hypot = function(x, y) {
|
||
x = Math.abs(x);
|
||
y = Math.abs(y);
|
||
if (x < y)
|
||
[x, y] = [y, x];
|
||
if (x < 1e8)
|
||
return Math.sqrt(x * x + y * y);
|
||
y /= x;
|
||
return x * Math.sqrt(1 + y * y);
|
||
};
|
||
const parser_exit = function() {
|
||
throw SyntaxError("Invalid Param");
|
||
};
|
||
function logHypot(a, b) {
|
||
const _a = Math.abs(a);
|
||
const _b = Math.abs(b);
|
||
if (a === 0) {
|
||
return Math.log(_b);
|
||
}
|
||
if (b === 0) {
|
||
return Math.log(_a);
|
||
}
|
||
if (_a < 3e3 && _b < 3e3) {
|
||
return Math.log(a * a + b * b) * 0.5;
|
||
}
|
||
a = a * 0.5;
|
||
b = b * 0.5;
|
||
return 0.5 * Math.log(a * a + b * b) + Math.LN2;
|
||
}
|
||
const P$1 = { "re": 0, "im": 0 };
|
||
const parse$1 = function(a, b) {
|
||
const z = P$1;
|
||
if (a === void 0 || a === null) {
|
||
z["re"] = z["im"] = 0;
|
||
} else if (b !== void 0) {
|
||
z["re"] = a;
|
||
z["im"] = b;
|
||
} else
|
||
switch (typeof a) {
|
||
case "object":
|
||
if ("im" in a && "re" in a) {
|
||
z["re"] = a["re"];
|
||
z["im"] = a["im"];
|
||
} else if ("abs" in a && "arg" in a) {
|
||
if (!isFinite(a["abs"]) && isFinite(a["arg"])) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
z["re"] = a["abs"] * Math.cos(a["arg"]);
|
||
z["im"] = a["abs"] * Math.sin(a["arg"]);
|
||
} else if ("r" in a && "phi" in a) {
|
||
if (!isFinite(a["r"]) && isFinite(a["phi"])) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
z["re"] = a["r"] * Math.cos(a["phi"]);
|
||
z["im"] = a["r"] * Math.sin(a["phi"]);
|
||
} else if (a.length === 2) {
|
||
z["re"] = a[0];
|
||
z["im"] = a[1];
|
||
} else {
|
||
parser_exit();
|
||
}
|
||
break;
|
||
case "string":
|
||
z["im"] = /* void */
|
||
z["re"] = 0;
|
||
const tokens = a.replace(/_/g, "").match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
|
||
let plus = 1;
|
||
let minus = 0;
|
||
if (tokens === null) {
|
||
parser_exit();
|
||
}
|
||
for (let i = 0; i < tokens.length; i++) {
|
||
const c = tokens[i];
|
||
if (c === " " || c === " " || c === "\n")
|
||
;
|
||
else if (c === "+") {
|
||
plus++;
|
||
} else if (c === "-") {
|
||
minus++;
|
||
} else if (c === "i" || c === "I") {
|
||
if (plus + minus === 0) {
|
||
parser_exit();
|
||
}
|
||
if (tokens[i + 1] !== " " && !isNaN(tokens[i + 1])) {
|
||
z["im"] += parseFloat((minus % 2 ? "-" : "") + tokens[i + 1]);
|
||
i++;
|
||
} else {
|
||
z["im"] += parseFloat((minus % 2 ? "-" : "") + "1");
|
||
}
|
||
plus = minus = 0;
|
||
} else {
|
||
if (plus + minus === 0 || isNaN(c)) {
|
||
parser_exit();
|
||
}
|
||
if (tokens[i + 1] === "i" || tokens[i + 1] === "I") {
|
||
z["im"] += parseFloat((minus % 2 ? "-" : "") + c);
|
||
i++;
|
||
} else {
|
||
z["re"] += parseFloat((minus % 2 ? "-" : "") + c);
|
||
}
|
||
plus = minus = 0;
|
||
}
|
||
}
|
||
if (plus + minus > 0) {
|
||
parser_exit();
|
||
}
|
||
break;
|
||
case "number":
|
||
z["im"] = 0;
|
||
z["re"] = a;
|
||
break;
|
||
default:
|
||
parser_exit();
|
||
}
|
||
if (isNaN(z["re"]) || isNaN(z["im"]))
|
||
;
|
||
return z;
|
||
};
|
||
function Complex$1(a, b) {
|
||
if (!(this instanceof Complex$1)) {
|
||
return new Complex$1(a, b);
|
||
}
|
||
const z = parse$1(a, b);
|
||
this["re"] = z["re"];
|
||
this["im"] = z["im"];
|
||
}
|
||
Complex$1.prototype = {
|
||
"re": 0,
|
||
"im": 0,
|
||
/**
|
||
* Calculates the sign of a complex number, which is a normalized complex
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sign": function() {
|
||
const abs2 = hypot(this["re"], this["im"]);
|
||
return new Complex$1(
|
||
this["re"] / abs2,
|
||
this["im"] / abs2
|
||
);
|
||
},
|
||
/**
|
||
* Adds two complex numbers
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"add": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
const tInfin = this["isInfinite"]();
|
||
const zInfin = !(isFinite(z["re"]) && isFinite(z["im"]));
|
||
if (tInfin || zInfin) {
|
||
if (tInfin && zInfin) {
|
||
return Complex$1["NAN"];
|
||
}
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
return new Complex$1(
|
||
this["re"] + z["re"],
|
||
this["im"] + z["im"]
|
||
);
|
||
},
|
||
/**
|
||
* Subtracts two complex numbers
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sub": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
const tInfin = this["isInfinite"]();
|
||
const zInfin = !(isFinite(z["re"]) && isFinite(z["im"]));
|
||
if (tInfin || zInfin) {
|
||
if (tInfin && zInfin) {
|
||
return Complex$1["NAN"];
|
||
}
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
return new Complex$1(
|
||
this["re"] - z["re"],
|
||
this["im"] - z["im"]
|
||
);
|
||
},
|
||
/**
|
||
* Multiplies two complex numbers
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"mul": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
const tInfin = this["isInfinite"]();
|
||
const zInfin = !(isFinite(z["re"]) && isFinite(z["im"]));
|
||
const tIsZero = this["re"] === 0 && this["im"] === 0;
|
||
const zIsZero = z["re"] === 0 && z["im"] === 0;
|
||
if (tInfin && zIsZero || zInfin && tIsZero) {
|
||
return Complex$1["NAN"];
|
||
}
|
||
if (tInfin || zInfin) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
if (z["im"] === 0 && this["im"] === 0) {
|
||
return new Complex$1(this["re"] * z["re"], 0);
|
||
}
|
||
return new Complex$1(
|
||
this["re"] * z["re"] - this["im"] * z["im"],
|
||
this["re"] * z["im"] + this["im"] * z["re"]
|
||
);
|
||
},
|
||
/**
|
||
* Divides two complex numbers
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"div": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
const tInfin = this["isInfinite"]();
|
||
const zInfin = !(isFinite(z["re"]) && isFinite(z["im"]));
|
||
const tIsZero = this["re"] === 0 && this["im"] === 0;
|
||
const zIsZero = z["re"] === 0 && z["im"] === 0;
|
||
if (tIsZero && zIsZero || tInfin && zInfin) {
|
||
return Complex$1["NAN"];
|
||
}
|
||
if (zIsZero || tInfin) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
if (tIsZero || zInfin) {
|
||
return Complex$1["ZERO"];
|
||
}
|
||
if (0 === z["im"]) {
|
||
return new Complex$1(this["re"] / z["re"], this["im"] / z["re"]);
|
||
}
|
||
if (Math.abs(z["re"]) < Math.abs(z["im"])) {
|
||
const x = z["re"] / z["im"];
|
||
const t2 = z["re"] * x + z["im"];
|
||
return new Complex$1(
|
||
(this["re"] * x + this["im"]) / t2,
|
||
(this["im"] * x - this["re"]) / t2
|
||
);
|
||
} else {
|
||
const x = z["im"] / z["re"];
|
||
const t2 = z["im"] * x + z["re"];
|
||
return new Complex$1(
|
||
(this["re"] + this["im"] * x) / t2,
|
||
(this["im"] - this["re"] * x) / t2
|
||
);
|
||
}
|
||
},
|
||
/**
|
||
* Calculate the power of two complex numbers
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"pow": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
const tIsZero = this["re"] === 0 && this["im"] === 0;
|
||
const zIsZero = z["re"] === 0 && z["im"] === 0;
|
||
if (zIsZero) {
|
||
return Complex$1["ONE"];
|
||
}
|
||
if (z["im"] === 0) {
|
||
if (this["im"] === 0 && this["re"] > 0) {
|
||
return new Complex$1(Math.pow(this["re"], z["re"]), 0);
|
||
} else if (this["re"] === 0) {
|
||
switch ((z["re"] % 4 + 4) % 4) {
|
||
case 0:
|
||
return new Complex$1(Math.pow(this["im"], z["re"]), 0);
|
||
case 1:
|
||
return new Complex$1(0, Math.pow(this["im"], z["re"]));
|
||
case 2:
|
||
return new Complex$1(-Math.pow(this["im"], z["re"]), 0);
|
||
case 3:
|
||
return new Complex$1(0, -Math.pow(this["im"], z["re"]));
|
||
}
|
||
}
|
||
}
|
||
if (tIsZero && z["re"] > 0) {
|
||
return Complex$1["ZERO"];
|
||
}
|
||
const arg = Math.atan2(this["im"], this["re"]);
|
||
const loh = logHypot(this["re"], this["im"]);
|
||
let re = Math.exp(z["re"] * loh - z["im"] * arg);
|
||
let im = z["im"] * loh + z["re"] * arg;
|
||
return new Complex$1(
|
||
re * Math.cos(im),
|
||
re * Math.sin(im)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex square root
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sqrt": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (b === 0) {
|
||
if (a >= 0) {
|
||
return new Complex$1(Math.sqrt(a), 0);
|
||
} else {
|
||
return new Complex$1(0, Math.sqrt(-a));
|
||
}
|
||
}
|
||
const r = hypot(a, b);
|
||
let re = Math.sqrt(0.5 * (r + Math.abs(a)));
|
||
let im = Math.abs(b) / (2 * re);
|
||
if (a >= 0) {
|
||
return new Complex$1(re, b < 0 ? -im : im);
|
||
} else {
|
||
return new Complex$1(im, b < 0 ? -re : re);
|
||
}
|
||
},
|
||
/**
|
||
* Calculate the complex exponent
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"exp": function() {
|
||
const er = Math.exp(this["re"]);
|
||
if (this["im"] === 0) {
|
||
return new Complex$1(er, 0);
|
||
}
|
||
return new Complex$1(
|
||
er * Math.cos(this["im"]),
|
||
er * Math.sin(this["im"])
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex exponent and subtracts one.
|
||
*
|
||
* This may be more accurate than `Complex(x).exp().sub(1)` if
|
||
* `x` is small.
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"expm1": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
return new Complex$1(
|
||
Math.expm1(a) * Math.cos(b) + cosm1(b),
|
||
Math.exp(a) * Math.sin(b)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the natural log
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"log": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (b === 0 && a > 0) {
|
||
return new Complex$1(Math.log(a), 0);
|
||
}
|
||
return new Complex$1(
|
||
logHypot(a, b),
|
||
Math.atan2(b, a)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the magnitude of the complex number
|
||
*
|
||
* @returns {number}
|
||
*/
|
||
"abs": function() {
|
||
return hypot(this["re"], this["im"]);
|
||
},
|
||
/**
|
||
* Calculate the angle of the complex number
|
||
*
|
||
* @returns {number}
|
||
*/
|
||
"arg": function() {
|
||
return Math.atan2(this["im"], this["re"]);
|
||
},
|
||
/**
|
||
* Calculate the sine of the complex number
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sin": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
return new Complex$1(
|
||
Math.sin(a) * cosh(b),
|
||
Math.cos(a) * sinh(b)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the cosine
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"cos": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
return new Complex$1(
|
||
Math.cos(a) * cosh(b),
|
||
-Math.sin(a) * sinh(b)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the tangent
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"tan": function() {
|
||
const a = 2 * this["re"];
|
||
const b = 2 * this["im"];
|
||
const d = Math.cos(a) + cosh(b);
|
||
return new Complex$1(
|
||
Math.sin(a) / d,
|
||
sinh(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the cotangent
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"cot": function() {
|
||
const a = 2 * this["re"];
|
||
const b = 2 * this["im"];
|
||
const d = Math.cos(a) - cosh(b);
|
||
return new Complex$1(
|
||
-Math.sin(a) / d,
|
||
sinh(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the secant
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sec": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const d = 0.5 * cosh(2 * b) + 0.5 * Math.cos(2 * a);
|
||
return new Complex$1(
|
||
Math.cos(a) * cosh(b) / d,
|
||
Math.sin(a) * sinh(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the cosecans
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"csc": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const d = 0.5 * cosh(2 * b) - 0.5 * Math.cos(2 * a);
|
||
return new Complex$1(
|
||
Math.sin(a) * cosh(b) / d,
|
||
-Math.cos(a) * sinh(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex arcus sinus
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"asin": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const t1 = new Complex$1(
|
||
b * b - a * a + 1,
|
||
-2 * a * b
|
||
)["sqrt"]();
|
||
const t2 = new Complex$1(
|
||
t1["re"] - b,
|
||
t1["im"] + a
|
||
)["log"]();
|
||
return new Complex$1(t2["im"], -t2["re"]);
|
||
},
|
||
/**
|
||
* Calculate the complex arcus cosinus
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acos": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const t1 = new Complex$1(
|
||
b * b - a * a + 1,
|
||
-2 * a * b
|
||
)["sqrt"]();
|
||
const t2 = new Complex$1(
|
||
t1["re"] - b,
|
||
t1["im"] + a
|
||
)["log"]();
|
||
return new Complex$1(Math.PI / 2 - t2["im"], t2["re"]);
|
||
},
|
||
/**
|
||
* Calculate the complex arcus tangent
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"atan": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (a === 0) {
|
||
if (b === 1) {
|
||
return new Complex$1(0, Infinity);
|
||
}
|
||
if (b === -1) {
|
||
return new Complex$1(0, -Infinity);
|
||
}
|
||
}
|
||
const d = a * a + (1 - b) * (1 - b);
|
||
const t1 = new Complex$1(
|
||
(1 - b * b - a * a) / d,
|
||
-2 * a / d
|
||
).log();
|
||
return new Complex$1(-0.5 * t1["im"], 0.5 * t1["re"]);
|
||
},
|
||
/**
|
||
* Calculate the complex arcus cotangent
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acot": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (b === 0) {
|
||
return new Complex$1(Math.atan2(1, a), 0);
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).atan() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).atan();
|
||
},
|
||
/**
|
||
* Calculate the complex arcus secant
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"asec": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (a === 0 && b === 0) {
|
||
return new Complex$1(0, Infinity);
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).acos() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).acos();
|
||
},
|
||
/**
|
||
* Calculate the complex arcus cosecans
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acsc": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (a === 0 && b === 0) {
|
||
return new Complex$1(Math.PI / 2, Infinity);
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).asin() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).asin();
|
||
},
|
||
/**
|
||
* Calculate the complex sinh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sinh": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
return new Complex$1(
|
||
sinh(a) * Math.cos(b),
|
||
cosh(a) * Math.sin(b)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex cosh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"cosh": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
return new Complex$1(
|
||
cosh(a) * Math.cos(b),
|
||
sinh(a) * Math.sin(b)
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex tanh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"tanh": function() {
|
||
const a = 2 * this["re"];
|
||
const b = 2 * this["im"];
|
||
const d = cosh(a) + Math.cos(b);
|
||
return new Complex$1(
|
||
sinh(a) / d,
|
||
Math.sin(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex coth
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"coth": function() {
|
||
const a = 2 * this["re"];
|
||
const b = 2 * this["im"];
|
||
const d = cosh(a) - Math.cos(b);
|
||
return new Complex$1(
|
||
sinh(a) / d,
|
||
-Math.sin(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex coth
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"csch": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const d = Math.cos(2 * b) - cosh(2 * a);
|
||
return new Complex$1(
|
||
-2 * sinh(a) * Math.cos(b) / d,
|
||
2 * cosh(a) * Math.sin(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex sech
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"sech": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const d = Math.cos(2 * b) + cosh(2 * a);
|
||
return new Complex$1(
|
||
2 * cosh(a) * Math.cos(b) / d,
|
||
-2 * sinh(a) * Math.sin(b) / d
|
||
);
|
||
},
|
||
/**
|
||
* Calculate the complex asinh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"asinh": function() {
|
||
let tmp = this["im"];
|
||
this["im"] = -this["re"];
|
||
this["re"] = tmp;
|
||
const res = this["asin"]();
|
||
this["re"] = -this["im"];
|
||
this["im"] = tmp;
|
||
tmp = res["re"];
|
||
res["re"] = -res["im"];
|
||
res["im"] = tmp;
|
||
return res;
|
||
},
|
||
/**
|
||
* Calculate the complex acosh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acosh": function() {
|
||
const res = this["acos"]();
|
||
if (res["im"] <= 0) {
|
||
const tmp = res["re"];
|
||
res["re"] = -res["im"];
|
||
res["im"] = tmp;
|
||
} else {
|
||
const tmp = res["im"];
|
||
res["im"] = -res["re"];
|
||
res["re"] = tmp;
|
||
}
|
||
return res;
|
||
},
|
||
/**
|
||
* Calculate the complex atanh
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"atanh": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const noIM = a > 1 && b === 0;
|
||
const oneMinus = 1 - a;
|
||
const onePlus = 1 + a;
|
||
const d = oneMinus * oneMinus + b * b;
|
||
const x = d !== 0 ? new Complex$1(
|
||
(onePlus * oneMinus - b * b) / d,
|
||
(b * oneMinus + onePlus * b) / d
|
||
) : new Complex$1(
|
||
a !== -1 ? a / 0 : 0,
|
||
b !== 0 ? b / 0 : 0
|
||
);
|
||
const temp = x["re"];
|
||
x["re"] = logHypot(x["re"], x["im"]) / 2;
|
||
x["im"] = Math.atan2(x["im"], temp) / 2;
|
||
if (noIM) {
|
||
x["im"] = -x["im"];
|
||
}
|
||
return x;
|
||
},
|
||
/**
|
||
* Calculate the complex acoth
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acoth": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (a === 0 && b === 0) {
|
||
return new Complex$1(0, Math.PI / 2);
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).atanh() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).atanh();
|
||
},
|
||
/**
|
||
* Calculate the complex acsch
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"acsch": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (b === 0) {
|
||
return new Complex$1(
|
||
a !== 0 ? Math.log(a + Math.sqrt(a * a + 1)) : Infinity,
|
||
0
|
||
);
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).asinh() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).asinh();
|
||
},
|
||
/**
|
||
* Calculate the complex asech
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"asech": function() {
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
if (this["isZero"]()) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
const d = a * a + b * b;
|
||
return d !== 0 ? new Complex$1(
|
||
a / d,
|
||
-b / d
|
||
).acosh() : new Complex$1(
|
||
a !== 0 ? a / 0 : 0,
|
||
b !== 0 ? -b / 0 : 0
|
||
).acosh();
|
||
},
|
||
/**
|
||
* Calculate the complex inverse 1/z
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"inverse": function() {
|
||
if (this["isZero"]()) {
|
||
return Complex$1["INFINITY"];
|
||
}
|
||
if (this["isInfinite"]()) {
|
||
return Complex$1["ZERO"];
|
||
}
|
||
const a = this["re"];
|
||
const b = this["im"];
|
||
const d = a * a + b * b;
|
||
return new Complex$1(a / d, -b / d);
|
||
},
|
||
/**
|
||
* Returns the complex conjugate
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"conjugate": function() {
|
||
return new Complex$1(this["re"], -this["im"]);
|
||
},
|
||
/**
|
||
* Gets the negated complex number
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"neg": function() {
|
||
return new Complex$1(-this["re"], -this["im"]);
|
||
},
|
||
/**
|
||
* Ceils the actual complex number
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"ceil": function(places) {
|
||
places = Math.pow(10, places || 0);
|
||
return new Complex$1(
|
||
Math.ceil(this["re"] * places) / places,
|
||
Math.ceil(this["im"] * places) / places
|
||
);
|
||
},
|
||
/**
|
||
* Floors the actual complex number
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"floor": function(places) {
|
||
places = Math.pow(10, places || 0);
|
||
return new Complex$1(
|
||
Math.floor(this["re"] * places) / places,
|
||
Math.floor(this["im"] * places) / places
|
||
);
|
||
},
|
||
/**
|
||
* Ceils the actual complex number
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"round": function(places) {
|
||
places = Math.pow(10, places || 0);
|
||
return new Complex$1(
|
||
Math.round(this["re"] * places) / places,
|
||
Math.round(this["im"] * places) / places
|
||
);
|
||
},
|
||
/**
|
||
* Compares two complex numbers
|
||
*
|
||
* **Note:** new Complex(Infinity).equals(Infinity) === false
|
||
*
|
||
* @returns {boolean}
|
||
*/
|
||
"equals": function(a, b) {
|
||
const z = parse$1(a, b);
|
||
return Math.abs(z["re"] - this["re"]) <= Complex$1["EPSILON"] && Math.abs(z["im"] - this["im"]) <= Complex$1["EPSILON"];
|
||
},
|
||
/**
|
||
* Clones the actual object
|
||
*
|
||
* @returns {Complex}
|
||
*/
|
||
"clone": function() {
|
||
return new Complex$1(this["re"], this["im"]);
|
||
},
|
||
/**
|
||
* Gets a string of the actual complex number
|
||
*
|
||
* @returns {string}
|
||
*/
|
||
"toString": function() {
|
||
let a = this["re"];
|
||
let b = this["im"];
|
||
let ret = "";
|
||
if (this["isNaN"]()) {
|
||
return "NaN";
|
||
}
|
||
if (this["isInfinite"]()) {
|
||
return "Infinity";
|
||
}
|
||
if (Math.abs(a) < Complex$1["EPSILON"]) {
|
||
a = 0;
|
||
}
|
||
if (Math.abs(b) < Complex$1["EPSILON"]) {
|
||
b = 0;
|
||
}
|
||
if (b === 0) {
|
||
return ret + a;
|
||
}
|
||
if (a !== 0) {
|
||
ret += a;
|
||
ret += " ";
|
||
if (b < 0) {
|
||
b = -b;
|
||
ret += "-";
|
||
} else {
|
||
ret += "+";
|
||
}
|
||
ret += " ";
|
||
} else if (b < 0) {
|
||
b = -b;
|
||
ret += "-";
|
||
}
|
||
if (1 !== b) {
|
||
ret += b;
|
||
}
|
||
return ret + "i";
|
||
},
|
||
/**
|
||
* Returns the actual number as a vector
|
||
*
|
||
* @returns {Array}
|
||
*/
|
||
"toVector": function() {
|
||
return [this["re"], this["im"]];
|
||
},
|
||
/**
|
||
* Returns the actual real value of the current object
|
||
*
|
||
* @returns {number|null}
|
||
*/
|
||
"valueOf": function() {
|
||
if (this["im"] === 0) {
|
||
return this["re"];
|
||
}
|
||
return null;
|
||
},
|
||
/**
|
||
* Determines whether a complex number is not on the Riemann sphere.
|
||
*
|
||
* @returns {boolean}
|
||
*/
|
||
"isNaN": function() {
|
||
return isNaN(this["re"]) || isNaN(this["im"]);
|
||
},
|
||
/**
|
||
* Determines whether or not a complex number is at the zero pole of the
|
||
* Riemann sphere.
|
||
*
|
||
* @returns {boolean}
|
||
*/
|
||
"isZero": function() {
|
||
return this["im"] === 0 && this["re"] === 0;
|
||
},
|
||
/**
|
||
* Determines whether a complex number is not at the infinity pole of the
|
||
* Riemann sphere.
|
||
*
|
||
* @returns {boolean}
|
||
*/
|
||
"isFinite": function() {
|
||
return isFinite(this["re"]) && isFinite(this["im"]);
|
||
},
|
||
/**
|
||
* Determines whether or not a complex number is at the infinity pole of the
|
||
* Riemann sphere.
|
||
*
|
||
* @returns {boolean}
|
||
*/
|
||
"isInfinite": function() {
|
||
return !this["isFinite"]();
|
||
}
|
||
};
|
||
Complex$1["ZERO"] = new Complex$1(0, 0);
|
||
Complex$1["ONE"] = new Complex$1(1, 0);
|
||
Complex$1["I"] = new Complex$1(0, 1);
|
||
Complex$1["PI"] = new Complex$1(Math.PI, 0);
|
||
Complex$1["E"] = new Complex$1(Math.E, 0);
|
||
Complex$1["INFINITY"] = new Complex$1(Infinity, Infinity);
|
||
Complex$1["NAN"] = new Complex$1(NaN, NaN);
|
||
Complex$1["EPSILON"] = 1e-15;
|
||
var name$b = "Complex";
|
||
var dependencies$b = [];
|
||
var createComplexClass = /* @__PURE__ */ factory(name$b, dependencies$b, () => {
|
||
Object.defineProperty(Complex$1, "name", {
|
||
value: "Complex"
|
||
});
|
||
Complex$1.prototype.constructor = Complex$1;
|
||
Complex$1.prototype.type = "Complex";
|
||
Complex$1.prototype.isComplex = true;
|
||
Complex$1.prototype.toJSON = function() {
|
||
return {
|
||
mathjs: "Complex",
|
||
re: this.re,
|
||
im: this.im
|
||
};
|
||
};
|
||
Complex$1.prototype.toPolar = function() {
|
||
return {
|
||
r: this.abs(),
|
||
phi: this.arg()
|
||
};
|
||
};
|
||
Complex$1.prototype.format = function(options) {
|
||
var str = "";
|
||
var im = this.im;
|
||
var re = this.re;
|
||
var strRe = format$2(this.re, options);
|
||
var strIm = format$2(this.im, options);
|
||
var precision = isNumber(options) ? options : options ? options.precision : null;
|
||
if (precision !== null) {
|
||
var epsilon = Math.pow(10, -precision);
|
||
if (Math.abs(re / im) < epsilon) {
|
||
re = 0;
|
||
}
|
||
if (Math.abs(im / re) < epsilon) {
|
||
im = 0;
|
||
}
|
||
}
|
||
if (im === 0) {
|
||
str = strRe;
|
||
} else if (re === 0) {
|
||
if (im === 1) {
|
||
str = "i";
|
||
} else if (im === -1) {
|
||
str = "-i";
|
||
} else {
|
||
str = strIm + "i";
|
||
}
|
||
} else {
|
||
if (im < 0) {
|
||
if (im === -1) {
|
||
str = strRe + " - i";
|
||
} else {
|
||
str = strRe + " - " + strIm.substring(1) + "i";
|
||
}
|
||
} else {
|
||
if (im === 1) {
|
||
str = strRe + " + i";
|
||
} else {
|
||
str = strRe + " + " + strIm + "i";
|
||
}
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
Complex$1.fromPolar = function(args) {
|
||
switch (arguments.length) {
|
||
case 1: {
|
||
var arg = arguments[0];
|
||
if (typeof arg === "object") {
|
||
return Complex$1(arg);
|
||
} else {
|
||
throw new TypeError("Input has to be an object with r and phi keys.");
|
||
}
|
||
}
|
||
case 2: {
|
||
var r = arguments[0];
|
||
var phi = arguments[1];
|
||
if (isNumber(r)) {
|
||
if (isUnit(phi) && phi.hasBase("ANGLE")) {
|
||
phi = phi.toNumber("rad");
|
||
}
|
||
if (isNumber(phi)) {
|
||
return new Complex$1({
|
||
r,
|
||
phi
|
||
});
|
||
}
|
||
throw new TypeError("Phi is not a number nor an angle unit.");
|
||
} else {
|
||
throw new TypeError("Radius r is not a number.");
|
||
}
|
||
}
|
||
default:
|
||
throw new SyntaxError("Wrong number of arguments in function fromPolar");
|
||
}
|
||
};
|
||
Complex$1.prototype.valueOf = Complex$1.prototype.toString;
|
||
Complex$1.fromJSON = function(json) {
|
||
return new Complex$1(json);
|
||
};
|
||
Complex$1.compare = function(a, b) {
|
||
if (a.re > b.re) {
|
||
return 1;
|
||
}
|
||
if (a.re < b.re) {
|
||
return -1;
|
||
}
|
||
if (a.im > b.im) {
|
||
return 1;
|
||
}
|
||
if (a.im < b.im) {
|
||
return -1;
|
||
}
|
||
return 0;
|
||
};
|
||
return Complex$1;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
if (typeof BigInt === "undefined")
|
||
BigInt = function(n2) {
|
||
if (isNaN(n2))
|
||
throw new Error("");
|
||
return n2;
|
||
};
|
||
const C_ZERO = BigInt(0);
|
||
const C_ONE = BigInt(1);
|
||
const C_TWO = BigInt(2);
|
||
const C_FIVE = BigInt(5);
|
||
const C_TEN = BigInt(10);
|
||
const MAX_CYCLE_LEN = 2e3;
|
||
const P = {
|
||
"s": C_ONE,
|
||
"n": C_ZERO,
|
||
"d": C_ONE
|
||
};
|
||
function assign(n2, s2) {
|
||
try {
|
||
n2 = BigInt(n2);
|
||
} catch (e2) {
|
||
throw InvalidParameter();
|
||
}
|
||
return n2 * s2;
|
||
}
|
||
function trunc(x) {
|
||
return typeof x === "bigint" ? x : Math.floor(x);
|
||
}
|
||
function newFraction(n2, d) {
|
||
if (d === C_ZERO) {
|
||
throw DivisionByZero();
|
||
}
|
||
const f2 = Object.create(Fraction$1.prototype);
|
||
f2["s"] = n2 < C_ZERO ? -C_ONE : C_ONE;
|
||
n2 = n2 < C_ZERO ? -n2 : n2;
|
||
const a = gcd(n2, d);
|
||
f2["n"] = n2 / a;
|
||
f2["d"] = d / a;
|
||
return f2;
|
||
}
|
||
function factorize(num) {
|
||
const factors = {};
|
||
let n2 = num;
|
||
let i = C_TWO;
|
||
let s2 = C_FIVE - C_ONE;
|
||
while (s2 <= n2) {
|
||
while (n2 % i === C_ZERO) {
|
||
n2 /= i;
|
||
factors[i] = (factors[i] || C_ZERO) + C_ONE;
|
||
}
|
||
s2 += C_ONE + C_TWO * i++;
|
||
}
|
||
if (n2 !== num) {
|
||
if (n2 > 1)
|
||
factors[n2] = (factors[n2] || C_ZERO) + C_ONE;
|
||
} else {
|
||
factors[num] = (factors[num] || C_ZERO) + C_ONE;
|
||
}
|
||
return factors;
|
||
}
|
||
const parse = function(p1, p2) {
|
||
let n2 = C_ZERO, d = C_ONE, s2 = C_ONE;
|
||
if (p1 === void 0 || p1 === null)
|
||
;
|
||
else if (p2 !== void 0) {
|
||
if (typeof p1 === "bigint") {
|
||
n2 = p1;
|
||
} else if (isNaN(p1)) {
|
||
throw InvalidParameter();
|
||
} else if (p1 % 1 !== 0) {
|
||
throw NonIntegerParameter();
|
||
} else {
|
||
n2 = BigInt(p1);
|
||
}
|
||
if (typeof p2 === "bigint") {
|
||
d = p2;
|
||
} else if (isNaN(p2)) {
|
||
throw InvalidParameter();
|
||
} else if (p2 % 1 !== 0) {
|
||
throw NonIntegerParameter();
|
||
} else {
|
||
d = BigInt(p2);
|
||
}
|
||
s2 = n2 * d;
|
||
} else if (typeof p1 === "object") {
|
||
if ("d" in p1 && "n" in p1) {
|
||
n2 = BigInt(p1["n"]);
|
||
d = BigInt(p1["d"]);
|
||
if ("s" in p1)
|
||
n2 *= BigInt(p1["s"]);
|
||
} else if (0 in p1) {
|
||
n2 = BigInt(p1[0]);
|
||
if (1 in p1)
|
||
d = BigInt(p1[1]);
|
||
} else if (typeof p1 === "bigint") {
|
||
n2 = p1;
|
||
} else {
|
||
throw InvalidParameter();
|
||
}
|
||
s2 = n2 * d;
|
||
} else if (typeof p1 === "number") {
|
||
if (isNaN(p1)) {
|
||
throw InvalidParameter();
|
||
}
|
||
if (p1 < 0) {
|
||
s2 = -C_ONE;
|
||
p1 = -p1;
|
||
}
|
||
if (p1 % 1 === 0) {
|
||
n2 = BigInt(p1);
|
||
} else if (p1 > 0) {
|
||
let z = 1;
|
||
let A = 0, B = 1;
|
||
let C = 1, D = 1;
|
||
let N = 1e7;
|
||
if (p1 >= 1) {
|
||
z = 10 ** Math.floor(1 + Math.log10(p1));
|
||
p1 /= z;
|
||
}
|
||
while (B <= N && D <= N) {
|
||
let M = (A + C) / (B + D);
|
||
if (p1 === M) {
|
||
if (B + D <= N) {
|
||
n2 = A + C;
|
||
d = B + D;
|
||
} else if (D > B) {
|
||
n2 = C;
|
||
d = D;
|
||
} else {
|
||
n2 = A;
|
||
d = B;
|
||
}
|
||
break;
|
||
} else {
|
||
if (p1 > M) {
|
||
A += C;
|
||
B += D;
|
||
} else {
|
||
C += A;
|
||
D += B;
|
||
}
|
||
if (B > N) {
|
||
n2 = C;
|
||
d = D;
|
||
} else {
|
||
n2 = A;
|
||
d = B;
|
||
}
|
||
}
|
||
}
|
||
n2 = BigInt(n2) * BigInt(z);
|
||
d = BigInt(d);
|
||
}
|
||
} else if (typeof p1 === "string") {
|
||
let ndx = 0;
|
||
let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;
|
||
let match = p1.replace(/_/g, "").match(/\d+|./g);
|
||
if (match === null)
|
||
throw InvalidParameter();
|
||
if (match[ndx] === "-") {
|
||
s2 = -C_ONE;
|
||
ndx++;
|
||
} else if (match[ndx] === "+") {
|
||
ndx++;
|
||
}
|
||
if (match.length === ndx + 1) {
|
||
w = assign(match[ndx++], s2);
|
||
} else if (match[ndx + 1] === "." || match[ndx] === ".") {
|
||
if (match[ndx] !== ".") {
|
||
v = assign(match[ndx++], s2);
|
||
}
|
||
ndx++;
|
||
if (ndx + 1 === match.length || match[ndx + 1] === "(" && match[ndx + 3] === ")" || match[ndx + 1] === "'" && match[ndx + 3] === "'") {
|
||
w = assign(match[ndx], s2);
|
||
y = C_TEN ** BigInt(match[ndx].length);
|
||
ndx++;
|
||
}
|
||
if (match[ndx] === "(" && match[ndx + 2] === ")" || match[ndx] === "'" && match[ndx + 2] === "'") {
|
||
x = assign(match[ndx + 1], s2);
|
||
z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;
|
||
ndx += 3;
|
||
}
|
||
} else if (match[ndx + 1] === "/" || match[ndx + 1] === ":") {
|
||
w = assign(match[ndx], s2);
|
||
y = assign(match[ndx + 2], C_ONE);
|
||
ndx += 3;
|
||
} else if (match[ndx + 3] === "/" && match[ndx + 1] === " ") {
|
||
v = assign(match[ndx], s2);
|
||
w = assign(match[ndx + 2], s2);
|
||
y = assign(match[ndx + 4], C_ONE);
|
||
ndx += 5;
|
||
}
|
||
if (match.length <= ndx) {
|
||
d = y * z;
|
||
s2 = /* void */
|
||
n2 = x + d * v + z * w;
|
||
} else {
|
||
throw InvalidParameter();
|
||
}
|
||
} else if (typeof p1 === "bigint") {
|
||
n2 = p1;
|
||
s2 = p1;
|
||
d = C_ONE;
|
||
} else {
|
||
throw InvalidParameter();
|
||
}
|
||
if (d === C_ZERO) {
|
||
throw DivisionByZero();
|
||
}
|
||
P["s"] = s2 < C_ZERO ? -C_ONE : C_ONE;
|
||
P["n"] = n2 < C_ZERO ? -n2 : n2;
|
||
P["d"] = d < C_ZERO ? -d : d;
|
||
};
|
||
function modpow(b, e2, m) {
|
||
let r = C_ONE;
|
||
for (; e2 > C_ZERO; b = b * b % m, e2 >>= C_ONE) {
|
||
if (e2 & C_ONE) {
|
||
r = r * b % m;
|
||
}
|
||
}
|
||
return r;
|
||
}
|
||
function cycleLen(n2, d) {
|
||
for (; d % C_TWO === C_ZERO; d /= C_TWO) {
|
||
}
|
||
for (; d % C_FIVE === C_ZERO; d /= C_FIVE) {
|
||
}
|
||
if (d === C_ONE)
|
||
return C_ZERO;
|
||
let rem = C_TEN % d;
|
||
let t2 = 1;
|
||
for (; rem !== C_ONE; t2++) {
|
||
rem = rem * C_TEN % d;
|
||
if (t2 > MAX_CYCLE_LEN)
|
||
return C_ZERO;
|
||
}
|
||
return BigInt(t2);
|
||
}
|
||
function cycleStart(n2, d, len) {
|
||
let rem1 = C_ONE;
|
||
let rem2 = modpow(C_TEN, len, d);
|
||
for (let t2 = 0; t2 < 300; t2++) {
|
||
if (rem1 === rem2)
|
||
return BigInt(t2);
|
||
rem1 = rem1 * C_TEN % d;
|
||
rem2 = rem2 * C_TEN % d;
|
||
}
|
||
return 0;
|
||
}
|
||
function gcd(a, b) {
|
||
if (!a)
|
||
return b;
|
||
if (!b)
|
||
return a;
|
||
while (1) {
|
||
a %= b;
|
||
if (!a)
|
||
return b;
|
||
b %= a;
|
||
if (!b)
|
||
return a;
|
||
}
|
||
}
|
||
function Fraction$1(a, b) {
|
||
parse(a, b);
|
||
if (this instanceof Fraction$1) {
|
||
a = gcd(P["d"], P["n"]);
|
||
this["s"] = P["s"];
|
||
this["n"] = P["n"] / a;
|
||
this["d"] = P["d"] / a;
|
||
} else {
|
||
return newFraction(P["s"] * P["n"], P["d"]);
|
||
}
|
||
}
|
||
var DivisionByZero = function() {
|
||
return new Error("Division by Zero");
|
||
};
|
||
var InvalidParameter = function() {
|
||
return new Error("Invalid argument");
|
||
};
|
||
var NonIntegerParameter = function() {
|
||
return new Error("Parameters must be integer");
|
||
};
|
||
Fraction$1.prototype = {
|
||
"s": C_ONE,
|
||
"n": C_ZERO,
|
||
"d": C_ONE,
|
||
/**
|
||
* Calculates the absolute value
|
||
*
|
||
* Ex: new Fraction(-4).abs() => 4
|
||
**/
|
||
"abs": function() {
|
||
return newFraction(this["n"], this["d"]);
|
||
},
|
||
/**
|
||
* Inverts the sign of the current fraction
|
||
*
|
||
* Ex: new Fraction(-4).neg() => 4
|
||
**/
|
||
"neg": function() {
|
||
return newFraction(-this["s"] * this["n"], this["d"]);
|
||
},
|
||
/**
|
||
* Adds two rational numbers
|
||
*
|
||
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
|
||
**/
|
||
"add": function(a, b) {
|
||
parse(a, b);
|
||
return newFraction(
|
||
this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
|
||
this["d"] * P["d"]
|
||
);
|
||
},
|
||
/**
|
||
* Subtracts two rational numbers
|
||
*
|
||
* Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
|
||
**/
|
||
"sub": function(a, b) {
|
||
parse(a, b);
|
||
return newFraction(
|
||
this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
|
||
this["d"] * P["d"]
|
||
);
|
||
},
|
||
/**
|
||
* Multiplies two rational numbers
|
||
*
|
||
* Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
|
||
**/
|
||
"mul": function(a, b) {
|
||
parse(a, b);
|
||
return newFraction(
|
||
this["s"] * P["s"] * this["n"] * P["n"],
|
||
this["d"] * P["d"]
|
||
);
|
||
},
|
||
/**
|
||
* Divides two rational numbers
|
||
*
|
||
* Ex: new Fraction("-17.(345)").inverse().div(3)
|
||
**/
|
||
"div": function(a, b) {
|
||
parse(a, b);
|
||
return newFraction(
|
||
this["s"] * P["s"] * this["n"] * P["d"],
|
||
this["d"] * P["n"]
|
||
);
|
||
},
|
||
/**
|
||
* Clones the actual object
|
||
*
|
||
* Ex: new Fraction("-17.(345)").clone()
|
||
**/
|
||
"clone": function() {
|
||
return newFraction(this["s"] * this["n"], this["d"]);
|
||
},
|
||
/**
|
||
* Calculates the modulo of two rational numbers - a more precise fmod
|
||
*
|
||
* Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
|
||
* Ex: new Fraction(20, 10).mod().equals(0) ? "is Integer"
|
||
**/
|
||
"mod": function(a, b) {
|
||
if (a === void 0) {
|
||
return newFraction(this["s"] * this["n"] % this["d"], C_ONE);
|
||
}
|
||
parse(a, b);
|
||
if (C_ZERO === P["n"] * this["d"]) {
|
||
throw DivisionByZero();
|
||
}
|
||
return newFraction(
|
||
this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
|
||
P["d"] * this["d"]
|
||
);
|
||
},
|
||
/**
|
||
* Calculates the fractional gcd of two rational numbers
|
||
*
|
||
* Ex: new Fraction(5,8).gcd(3,7) => 1/56
|
||
*/
|
||
"gcd": function(a, b) {
|
||
parse(a, b);
|
||
return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
|
||
},
|
||
/**
|
||
* Calculates the fractional lcm of two rational numbers
|
||
*
|
||
* Ex: new Fraction(5,8).lcm(3,7) => 15
|
||
*/
|
||
"lcm": function(a, b) {
|
||
parse(a, b);
|
||
if (P["n"] === C_ZERO && this["n"] === C_ZERO) {
|
||
return newFraction(C_ZERO, C_ONE);
|
||
}
|
||
return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
|
||
},
|
||
/**
|
||
* Gets the inverse of the fraction, means numerator and denominator are exchanged
|
||
*
|
||
* Ex: new Fraction([-3, 4]).inverse() => -4 / 3
|
||
**/
|
||
"inverse": function() {
|
||
return newFraction(this["s"] * this["d"], this["n"]);
|
||
},
|
||
/**
|
||
* Calculates the fraction to some integer exponent
|
||
*
|
||
* Ex: new Fraction(-1,2).pow(-3) => -8
|
||
*/
|
||
"pow": function(a, b) {
|
||
parse(a, b);
|
||
if (P["d"] === C_ONE) {
|
||
if (P["s"] < C_ZERO) {
|
||
return newFraction((this["s"] * this["d"]) ** P["n"], this["n"] ** P["n"]);
|
||
} else {
|
||
return newFraction((this["s"] * this["n"]) ** P["n"], this["d"] ** P["n"]);
|
||
}
|
||
}
|
||
if (this["s"] < C_ZERO)
|
||
return null;
|
||
let N = factorize(this["n"]);
|
||
let D = factorize(this["d"]);
|
||
let n2 = C_ONE;
|
||
let d = C_ONE;
|
||
for (let k in N) {
|
||
if (k === "1")
|
||
continue;
|
||
if (k === "0") {
|
||
n2 = C_ZERO;
|
||
break;
|
||
}
|
||
N[k] *= P["n"];
|
||
if (N[k] % P["d"] === C_ZERO) {
|
||
N[k] /= P["d"];
|
||
} else
|
||
return null;
|
||
n2 *= BigInt(k) ** N[k];
|
||
}
|
||
for (let k in D) {
|
||
if (k === "1")
|
||
continue;
|
||
D[k] *= P["n"];
|
||
if (D[k] % P["d"] === C_ZERO) {
|
||
D[k] /= P["d"];
|
||
} else
|
||
return null;
|
||
d *= BigInt(k) ** D[k];
|
||
}
|
||
if (P["s"] < C_ZERO) {
|
||
return newFraction(d, n2);
|
||
}
|
||
return newFraction(n2, d);
|
||
},
|
||
/**
|
||
* Calculates the logarithm of a fraction to a given rational base
|
||
*
|
||
* Ex: new Fraction(27, 8).log(9, 4) => 3/2
|
||
*/
|
||
"log": function(a, b) {
|
||
parse(a, b);
|
||
if (this["s"] <= C_ZERO || P["s"] <= C_ZERO)
|
||
return null;
|
||
const allPrimes = {};
|
||
const baseFactors = factorize(P["n"]);
|
||
const T1 = factorize(P["d"]);
|
||
const numberFactors = factorize(this["n"]);
|
||
const T2 = factorize(this["d"]);
|
||
for (const prime in T1) {
|
||
baseFactors[prime] = (baseFactors[prime] || C_ZERO) - T1[prime];
|
||
}
|
||
for (const prime in T2) {
|
||
numberFactors[prime] = (numberFactors[prime] || C_ZERO) - T2[prime];
|
||
}
|
||
for (const prime in baseFactors) {
|
||
if (prime === "1")
|
||
continue;
|
||
allPrimes[prime] = true;
|
||
}
|
||
for (const prime in numberFactors) {
|
||
if (prime === "1")
|
||
continue;
|
||
allPrimes[prime] = true;
|
||
}
|
||
let retN = null;
|
||
let retD = null;
|
||
for (const prime in allPrimes) {
|
||
const baseExponent = baseFactors[prime] || C_ZERO;
|
||
const numberExponent = numberFactors[prime] || C_ZERO;
|
||
if (baseExponent === C_ZERO) {
|
||
if (numberExponent !== C_ZERO) {
|
||
return null;
|
||
}
|
||
continue;
|
||
}
|
||
let curN = numberExponent;
|
||
let curD = baseExponent;
|
||
const gcdValue = gcd(curN, curD);
|
||
curN /= gcdValue;
|
||
curD /= gcdValue;
|
||
if (retN === null && retD === null) {
|
||
retN = curN;
|
||
retD = curD;
|
||
} else if (curN * retD !== retN * curD) {
|
||
return null;
|
||
}
|
||
}
|
||
return retN !== null && retD !== null ? newFraction(retN, retD) : null;
|
||
},
|
||
/**
|
||
* Check if two rational numbers are the same
|
||
*
|
||
* Ex: new Fraction(19.6).equals([98, 5]);
|
||
**/
|
||
"equals": function(a, b) {
|
||
parse(a, b);
|
||
return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"];
|
||
},
|
||
/**
|
||
* Check if this rational number is less than another
|
||
*
|
||
* Ex: new Fraction(19.6).lt([98, 5]);
|
||
**/
|
||
"lt": function(a, b) {
|
||
parse(a, b);
|
||
return this["s"] * this["n"] * P["d"] < P["s"] * P["n"] * this["d"];
|
||
},
|
||
/**
|
||
* Check if this rational number is less than or equal another
|
||
*
|
||
* Ex: new Fraction(19.6).lt([98, 5]);
|
||
**/
|
||
"lte": function(a, b) {
|
||
parse(a, b);
|
||
return this["s"] * this["n"] * P["d"] <= P["s"] * P["n"] * this["d"];
|
||
},
|
||
/**
|
||
* Check if this rational number is greater than another
|
||
*
|
||
* Ex: new Fraction(19.6).lt([98, 5]);
|
||
**/
|
||
"gt": function(a, b) {
|
||
parse(a, b);
|
||
return this["s"] * this["n"] * P["d"] > P["s"] * P["n"] * this["d"];
|
||
},
|
||
/**
|
||
* Check if this rational number is greater than or equal another
|
||
*
|
||
* Ex: new Fraction(19.6).lt([98, 5]);
|
||
**/
|
||
"gte": function(a, b) {
|
||
parse(a, b);
|
||
return this["s"] * this["n"] * P["d"] >= P["s"] * P["n"] * this["d"];
|
||
},
|
||
/**
|
||
* Compare two rational numbers
|
||
* < 0 iff this < that
|
||
* > 0 iff this > that
|
||
* = 0 iff this = that
|
||
*
|
||
* Ex: new Fraction(19.6).compare([98, 5]);
|
||
**/
|
||
"compare": function(a, b) {
|
||
parse(a, b);
|
||
let t2 = this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"];
|
||
return (C_ZERO < t2) - (t2 < C_ZERO);
|
||
},
|
||
/**
|
||
* Calculates the ceil of a rational number
|
||
*
|
||
* Ex: new Fraction('4.(3)').ceil() => (5 / 1)
|
||
**/
|
||
"ceil": function(places) {
|
||
places = C_TEN ** BigInt(places || 0);
|
||
return newFraction(
|
||
trunc(this["s"] * places * this["n"] / this["d"]) + (places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
|
||
places
|
||
);
|
||
},
|
||
/**
|
||
* Calculates the floor of a rational number
|
||
*
|
||
* Ex: new Fraction('4.(3)').floor() => (4 / 1)
|
||
**/
|
||
"floor": function(places) {
|
||
places = C_TEN ** BigInt(places || 0);
|
||
return newFraction(
|
||
trunc(this["s"] * places * this["n"] / this["d"]) - (places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
|
||
places
|
||
);
|
||
},
|
||
/**
|
||
* Rounds a rational numbers
|
||
*
|
||
* Ex: new Fraction('4.(3)').round() => (4 / 1)
|
||
**/
|
||
"round": function(places) {
|
||
places = C_TEN ** BigInt(places || 0);
|
||
return newFraction(
|
||
trunc(this["s"] * places * this["n"] / this["d"]) + this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
|
||
places
|
||
);
|
||
},
|
||
/**
|
||
* Rounds a rational number to a multiple of another rational number
|
||
*
|
||
* Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
|
||
**/
|
||
"roundTo": function(a, b) {
|
||
parse(a, b);
|
||
const n2 = this["n"] * P["d"];
|
||
const d = this["d"] * P["n"];
|
||
const r = n2 % d;
|
||
let k = trunc(n2 / d);
|
||
if (r + r >= d) {
|
||
k++;
|
||
}
|
||
return newFraction(this["s"] * k * P["n"], P["d"]);
|
||
},
|
||
/**
|
||
* Check if two rational numbers are divisible
|
||
*
|
||
* Ex: new Fraction(19.6).divisible(1.5);
|
||
*/
|
||
"divisible": function(a, b) {
|
||
parse(a, b);
|
||
return !(!(P["n"] * this["d"]) || this["n"] * P["d"] % (P["n"] * this["d"]));
|
||
},
|
||
/**
|
||
* Returns a decimal representation of the fraction
|
||
*
|
||
* Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
|
||
**/
|
||
"valueOf": function() {
|
||
return Number(this["s"] * this["n"]) / Number(this["d"]);
|
||
},
|
||
/**
|
||
* Creates a string representation of a fraction with all digits
|
||
*
|
||
* Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
|
||
**/
|
||
"toString": function(dec) {
|
||
let N = this["n"];
|
||
let D = this["d"];
|
||
dec = dec || 15;
|
||
let cycLen = cycleLen(N, D);
|
||
let cycOff = cycleStart(N, D, cycLen);
|
||
let str = this["s"] < C_ZERO ? "-" : "";
|
||
str += trunc(N / D);
|
||
N %= D;
|
||
N *= C_TEN;
|
||
if (N)
|
||
str += ".";
|
||
if (cycLen) {
|
||
for (let i = cycOff; i--; ) {
|
||
str += trunc(N / D);
|
||
N %= D;
|
||
N *= C_TEN;
|
||
}
|
||
str += "(";
|
||
for (let i = cycLen; i--; ) {
|
||
str += trunc(N / D);
|
||
N %= D;
|
||
N *= C_TEN;
|
||
}
|
||
str += ")";
|
||
} else {
|
||
for (let i = dec; N && i--; ) {
|
||
str += trunc(N / D);
|
||
N %= D;
|
||
N *= C_TEN;
|
||
}
|
||
}
|
||
return str;
|
||
},
|
||
/**
|
||
* Returns a string-fraction representation of a Fraction object
|
||
*
|
||
* Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
|
||
**/
|
||
"toFraction": function(showMixed) {
|
||
let n2 = this["n"];
|
||
let d = this["d"];
|
||
let str = this["s"] < C_ZERO ? "-" : "";
|
||
if (d === C_ONE) {
|
||
str += n2;
|
||
} else {
|
||
let whole = trunc(n2 / d);
|
||
if (showMixed && whole > C_ZERO) {
|
||
str += whole;
|
||
str += " ";
|
||
n2 %= d;
|
||
}
|
||
str += n2;
|
||
str += "/";
|
||
str += d;
|
||
}
|
||
return str;
|
||
},
|
||
/**
|
||
* Returns a latex representation of a Fraction object
|
||
*
|
||
* Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
|
||
**/
|
||
"toLatex": function(showMixed) {
|
||
let n2 = this["n"];
|
||
let d = this["d"];
|
||
let str = this["s"] < C_ZERO ? "-" : "";
|
||
if (d === C_ONE) {
|
||
str += n2;
|
||
} else {
|
||
let whole = trunc(n2 / d);
|
||
if (showMixed && whole > C_ZERO) {
|
||
str += whole;
|
||
n2 %= d;
|
||
}
|
||
str += "\\frac{";
|
||
str += n2;
|
||
str += "}{";
|
||
str += d;
|
||
str += "}";
|
||
}
|
||
return str;
|
||
},
|
||
/**
|
||
* Returns an array of continued fraction elements
|
||
*
|
||
* Ex: new Fraction("7/8").toContinued() => [0,1,7]
|
||
*/
|
||
"toContinued": function() {
|
||
let a = this["n"];
|
||
let b = this["d"];
|
||
let res = [];
|
||
do {
|
||
res.push(trunc(a / b));
|
||
let t2 = a % b;
|
||
a = b;
|
||
b = t2;
|
||
} while (a !== C_ONE);
|
||
return res;
|
||
},
|
||
"simplify": function(eps) {
|
||
const ieps = BigInt(1 / (eps || 1e-3) | 0);
|
||
const thisABS = this["abs"]();
|
||
const cont = thisABS["toContinued"]();
|
||
for (let i = 1; i < cont.length; i++) {
|
||
let s2 = newFraction(cont[i - 1], C_ONE);
|
||
for (let k = i - 2; k >= 0; k--) {
|
||
s2 = s2["inverse"]()["add"](cont[k]);
|
||
}
|
||
let t2 = s2["sub"](thisABS);
|
||
if (t2["n"] * ieps < t2["d"]) {
|
||
return s2["mul"](this["s"]);
|
||
}
|
||
}
|
||
return this;
|
||
}
|
||
};
|
||
var name$a = "Fraction";
|
||
var dependencies$a = [];
|
||
var createFractionClass = /* @__PURE__ */ factory(name$a, dependencies$a, () => {
|
||
Object.defineProperty(Fraction$1, "name", {
|
||
value: "Fraction"
|
||
});
|
||
Fraction$1.prototype.constructor = Fraction$1;
|
||
Fraction$1.prototype.type = "Fraction";
|
||
Fraction$1.prototype.isFraction = true;
|
||
Fraction$1.prototype.toJSON = function() {
|
||
return {
|
||
mathjs: "Fraction",
|
||
n: String(this.s * this.n),
|
||
d: String(this.d)
|
||
};
|
||
};
|
||
Fraction$1.fromJSON = function(json) {
|
||
return new Fraction$1(json);
|
||
};
|
||
return Fraction$1;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
var name$9 = "Matrix";
|
||
var dependencies$9 = [];
|
||
var createMatrixClass = /* @__PURE__ */ factory(name$9, dependencies$9, () => {
|
||
function Matrix2() {
|
||
if (!(this instanceof Matrix2)) {
|
||
throw new SyntaxError("Constructor must be called with the new operator");
|
||
}
|
||
}
|
||
Matrix2.prototype.type = "Matrix";
|
||
Matrix2.prototype.isMatrix = true;
|
||
Matrix2.prototype.storage = function() {
|
||
throw new Error("Cannot invoke storage on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.datatype = function() {
|
||
throw new Error("Cannot invoke datatype on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.create = function(data, datatype) {
|
||
throw new Error("Cannot invoke create on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.subset = function(index2, replacement, defaultValue) {
|
||
throw new Error("Cannot invoke subset on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.get = function(index2) {
|
||
throw new Error("Cannot invoke get on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.set = function(index2, value, defaultValue) {
|
||
throw new Error("Cannot invoke set on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.resize = function(size2, defaultValue) {
|
||
throw new Error("Cannot invoke resize on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.reshape = function(size2, defaultValue) {
|
||
throw new Error("Cannot invoke reshape on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.clone = function() {
|
||
throw new Error("Cannot invoke clone on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.size = function() {
|
||
throw new Error("Cannot invoke size on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.map = function(callback, skipZeros) {
|
||
throw new Error("Cannot invoke map on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.forEach = function(callback) {
|
||
throw new Error("Cannot invoke forEach on a Matrix interface");
|
||
};
|
||
Matrix2.prototype[Symbol.iterator] = function() {
|
||
throw new Error("Cannot iterate a Matrix interface");
|
||
};
|
||
Matrix2.prototype.toArray = function() {
|
||
throw new Error("Cannot invoke toArray on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.valueOf = function() {
|
||
throw new Error("Cannot invoke valueOf on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.format = function(options) {
|
||
throw new Error("Cannot invoke format on a Matrix interface");
|
||
};
|
||
Matrix2.prototype.toString = function() {
|
||
throw new Error("Cannot invoke toString on a Matrix interface");
|
||
};
|
||
return Matrix2;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
function formatBigNumberToBase(n2, base, size2) {
|
||
var BigNumberCtor = n2.constructor;
|
||
var big2 = new BigNumberCtor(2);
|
||
var suffix = "";
|
||
if (size2) {
|
||
if (size2 < 1) {
|
||
throw new Error("size must be in greater than 0");
|
||
}
|
||
if (!isInteger(size2)) {
|
||
throw new Error("size must be an integer");
|
||
}
|
||
if (n2.greaterThan(big2.pow(size2 - 1).sub(1)) || n2.lessThan(big2.pow(size2 - 1).mul(-1))) {
|
||
throw new Error("Value must be in range [-2^".concat(size2 - 1, ", 2^").concat(size2 - 1, "-1]"));
|
||
}
|
||
if (!n2.isInteger()) {
|
||
throw new Error("Value must be an integer");
|
||
}
|
||
if (n2.lessThan(0)) {
|
||
n2 = n2.add(big2.pow(size2));
|
||
}
|
||
suffix = "i".concat(size2);
|
||
}
|
||
switch (base) {
|
||
case 2:
|
||
return "".concat(n2.toBinary()).concat(suffix);
|
||
case 8:
|
||
return "".concat(n2.toOctal()).concat(suffix);
|
||
case 16:
|
||
return "".concat(n2.toHexadecimal()).concat(suffix);
|
||
default:
|
||
throw new Error("Base ".concat(base, " not supported "));
|
||
}
|
||
}
|
||
function format$1(value, options) {
|
||
if (typeof options === "function") {
|
||
return options(value);
|
||
}
|
||
if (!value.isFinite()) {
|
||
return value.isNaN() ? "NaN" : value.gt(0) ? "Infinity" : "-Infinity";
|
||
}
|
||
var {
|
||
notation,
|
||
precision,
|
||
wordSize
|
||
} = normalizeFormatOptions(options);
|
||
switch (notation) {
|
||
case "fixed":
|
||
return toFixed(value, precision);
|
||
case "exponential":
|
||
return toExponential(value, precision);
|
||
case "engineering":
|
||
return toEngineering(value, precision);
|
||
case "bin":
|
||
return formatBigNumberToBase(value, 2, wordSize);
|
||
case "oct":
|
||
return formatBigNumberToBase(value, 8, wordSize);
|
||
case "hex":
|
||
return formatBigNumberToBase(value, 16, wordSize);
|
||
case "auto": {
|
||
var lowerExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
||
var upperExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
||
if (value.isZero())
|
||
return "0";
|
||
var str;
|
||
var rounded = value.toSignificantDigits(precision);
|
||
var exp2 = rounded.e;
|
||
if (exp2 >= lowerExp && exp2 < upperExp) {
|
||
str = rounded.toFixed();
|
||
} else {
|
||
str = toExponential(value, precision);
|
||
}
|
||
return str.replace(/((\.\d*?)(0+))($|e)/, function() {
|
||
var digits2 = arguments[2];
|
||
var e2 = arguments[4];
|
||
return digits2 !== "." ? digits2 + e2 : e2;
|
||
});
|
||
}
|
||
default:
|
||
throw new Error('Unknown notation "' + notation + '". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.');
|
||
}
|
||
}
|
||
function toEngineering(value, precision) {
|
||
var e2 = value.e;
|
||
var newExp = e2 % 3 === 0 ? e2 : e2 < 0 ? e2 - 3 - e2 % 3 : e2 - e2 % 3;
|
||
var valueWithoutExp = value.mul(Math.pow(10, -newExp));
|
||
var valueStr = valueWithoutExp.toPrecision(precision);
|
||
if (valueStr.includes("e")) {
|
||
var BigNumber2 = value.constructor;
|
||
valueStr = new BigNumber2(valueStr).toFixed();
|
||
}
|
||
return valueStr + "e" + (e2 >= 0 ? "+" : "") + newExp.toString();
|
||
}
|
||
function toExponential(value, precision) {
|
||
if (precision !== void 0) {
|
||
return value.toExponential(precision - 1);
|
||
} else {
|
||
return value.toExponential();
|
||
}
|
||
}
|
||
function toFixed(value, precision) {
|
||
return value.toFixed(precision);
|
||
}
|
||
function _toNumberOrDefault(value, defaultValue) {
|
||
if (isNumber(value)) {
|
||
return value;
|
||
} else if (isBigNumber(value)) {
|
||
return value.toNumber();
|
||
} else {
|
||
return defaultValue;
|
||
}
|
||
}
|
||
function format(value, options) {
|
||
var result = _format(value, options);
|
||
if (options && typeof options === "object" && "truncate" in options && result.length > options.truncate) {
|
||
return result.substring(0, options.truncate - 3) + "...";
|
||
}
|
||
return result;
|
||
}
|
||
function _format(value, options) {
|
||
if (typeof value === "number") {
|
||
return format$2(value, options);
|
||
}
|
||
if (isBigNumber(value)) {
|
||
return format$1(value, options);
|
||
}
|
||
if (looksLikeFraction(value)) {
|
||
if (!options || options.fraction !== "decimal") {
|
||
return "".concat(value.s * value.n, "/").concat(value.d);
|
||
} else {
|
||
return value.toString();
|
||
}
|
||
}
|
||
if (Array.isArray(value)) {
|
||
return formatArray(value, options);
|
||
}
|
||
if (isString(value)) {
|
||
return stringify(value);
|
||
}
|
||
if (typeof value === "function") {
|
||
return value.syntax ? String(value.syntax) : "function";
|
||
}
|
||
if (value && typeof value === "object") {
|
||
if (typeof value.format === "function") {
|
||
return value.format(options);
|
||
} else if (value && value.toString(options) !== {}.toString()) {
|
||
return value.toString(options);
|
||
} else {
|
||
var entries = Object.keys(value).map((key) => {
|
||
return stringify(key) + ": " + format(value[key], options);
|
||
});
|
||
return "{" + entries.join(", ") + "}";
|
||
}
|
||
}
|
||
return String(value);
|
||
}
|
||
function stringify(value) {
|
||
var text = String(value);
|
||
var escaped = "";
|
||
var i = 0;
|
||
while (i < text.length) {
|
||
var c = text.charAt(i);
|
||
escaped += c in controlCharacters ? controlCharacters[c] : c;
|
||
i++;
|
||
}
|
||
return '"' + escaped + '"';
|
||
}
|
||
var controlCharacters = {
|
||
'"': '\\"',
|
||
"\\": "\\\\",
|
||
"\b": "\\b",
|
||
"\f": "\\f",
|
||
"\n": "\\n",
|
||
"\r": "\\r",
|
||
" ": "\\t"
|
||
};
|
||
function formatArray(array, options) {
|
||
if (Array.isArray(array)) {
|
||
var str = "[";
|
||
var len = array.length;
|
||
for (var i = 0; i < len; i++) {
|
||
if (i !== 0) {
|
||
str += ", ";
|
||
}
|
||
str += formatArray(array[i], options);
|
||
}
|
||
str += "]";
|
||
return str;
|
||
} else {
|
||
return format(array, options);
|
||
}
|
||
}
|
||
function looksLikeFraction(value) {
|
||
return value && typeof value === "object" && typeof value.s === "bigint" && typeof value.n === "bigint" && typeof value.d === "bigint" || false;
|
||
}
|
||
function DimensionError(actual, expected, relation) {
|
||
if (!(this instanceof DimensionError)) {
|
||
throw new SyntaxError("Constructor must be called with the new operator");
|
||
}
|
||
this.actual = actual;
|
||
this.expected = expected;
|
||
this.relation = relation;
|
||
this.message = "Dimension mismatch (" + (Array.isArray(actual) ? "[" + actual.join(", ") + "]" : actual) + " " + (this.relation || "!=") + " " + (Array.isArray(expected) ? "[" + expected.join(", ") + "]" : expected) + ")";
|
||
this.stack = new Error().stack;
|
||
}
|
||
DimensionError.prototype = new RangeError();
|
||
DimensionError.prototype.constructor = RangeError;
|
||
DimensionError.prototype.name = "DimensionError";
|
||
DimensionError.prototype.isDimensionError = true;
|
||
function IndexError(index2, min2, max2) {
|
||
if (!(this instanceof IndexError)) {
|
||
throw new SyntaxError("Constructor must be called with the new operator");
|
||
}
|
||
this.index = index2;
|
||
if (arguments.length < 3) {
|
||
this.min = 0;
|
||
this.max = min2;
|
||
} else {
|
||
this.min = min2;
|
||
this.max = max2;
|
||
}
|
||
if (this.min !== void 0 && this.index < this.min) {
|
||
this.message = "Index out of range (" + this.index + " < " + this.min + ")";
|
||
} else if (this.max !== void 0 && this.index >= this.max) {
|
||
this.message = "Index out of range (" + this.index + " > " + (this.max - 1) + ")";
|
||
} else {
|
||
this.message = "Index out of range (" + this.index + ")";
|
||
}
|
||
this.stack = new Error().stack;
|
||
}
|
||
IndexError.prototype = new RangeError();
|
||
IndexError.prototype.constructor = RangeError;
|
||
IndexError.prototype.name = "IndexError";
|
||
IndexError.prototype.isIndexError = true;
|
||
function arraySize(x) {
|
||
var s2 = [];
|
||
while (Array.isArray(x)) {
|
||
s2.push(x.length);
|
||
x = x[0];
|
||
}
|
||
return s2;
|
||
}
|
||
function _validate(array, size2, dim) {
|
||
var i;
|
||
var len = array.length;
|
||
if (len !== size2[dim]) {
|
||
throw new DimensionError(len, size2[dim]);
|
||
}
|
||
if (dim < size2.length - 1) {
|
||
var dimNext = dim + 1;
|
||
for (i = 0; i < len; i++) {
|
||
var child = array[i];
|
||
if (!Array.isArray(child)) {
|
||
throw new DimensionError(size2.length - 1, size2.length, "<");
|
||
}
|
||
_validate(array[i], size2, dimNext);
|
||
}
|
||
} else {
|
||
for (i = 0; i < len; i++) {
|
||
if (Array.isArray(array[i])) {
|
||
throw new DimensionError(size2.length + 1, size2.length, ">");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function validate(array, size2) {
|
||
var isScalar = size2.length === 0;
|
||
if (isScalar) {
|
||
if (Array.isArray(array)) {
|
||
throw new DimensionError(array.length, 0);
|
||
}
|
||
} else {
|
||
_validate(array, size2, 0);
|
||
}
|
||
}
|
||
function validateIndex(index2, length) {
|
||
if (index2 !== void 0) {
|
||
if (!isNumber(index2) || !isInteger(index2)) {
|
||
throw new TypeError("Index must be an integer (value: " + index2 + ")");
|
||
}
|
||
if (index2 < 0 || typeof length === "number" && index2 >= length) {
|
||
throw new IndexError(index2, length);
|
||
}
|
||
}
|
||
}
|
||
function resize(array, size2, defaultValue) {
|
||
if (!Array.isArray(size2)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (size2.length === 0) {
|
||
throw new Error("Resizing to scalar is not supported");
|
||
}
|
||
size2.forEach(function(value) {
|
||
if (!isNumber(value) || !isInteger(value) || value < 0) {
|
||
throw new TypeError("Invalid size, must contain positive integers (size: " + format(size2) + ")");
|
||
}
|
||
});
|
||
if (isNumber(array) || isBigNumber(array)) {
|
||
array = [array];
|
||
}
|
||
var _defaultValue = defaultValue !== void 0 ? defaultValue : 0;
|
||
_resize(array, size2, 0, _defaultValue);
|
||
return array;
|
||
}
|
||
function _resize(array, size2, dim, defaultValue) {
|
||
var i;
|
||
var elem;
|
||
var oldLen = array.length;
|
||
var newLen = size2[dim];
|
||
var minLen = Math.min(oldLen, newLen);
|
||
array.length = newLen;
|
||
if (dim < size2.length - 1) {
|
||
var dimNext = dim + 1;
|
||
for (i = 0; i < minLen; i++) {
|
||
elem = array[i];
|
||
if (!Array.isArray(elem)) {
|
||
elem = [elem];
|
||
array[i] = elem;
|
||
}
|
||
_resize(elem, size2, dimNext, defaultValue);
|
||
}
|
||
for (i = minLen; i < newLen; i++) {
|
||
elem = [];
|
||
array[i] = elem;
|
||
_resize(elem, size2, dimNext, defaultValue);
|
||
}
|
||
} else {
|
||
for (i = 0; i < minLen; i++) {
|
||
while (Array.isArray(array[i])) {
|
||
array[i] = array[i][0];
|
||
}
|
||
}
|
||
for (i = minLen; i < newLen; i++) {
|
||
array[i] = defaultValue;
|
||
}
|
||
}
|
||
}
|
||
function reshape(array, sizes) {
|
||
var flatArray = flatten(array);
|
||
var currentLength = flatArray.length;
|
||
if (!Array.isArray(array) || !Array.isArray(sizes)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (sizes.length === 0) {
|
||
throw new DimensionError(0, currentLength, "!=");
|
||
}
|
||
sizes = processSizesWildcard(sizes, currentLength);
|
||
var newLength = product(sizes);
|
||
if (currentLength !== newLength) {
|
||
throw new DimensionError(newLength, currentLength, "!=");
|
||
}
|
||
try {
|
||
return _reshape(flatArray, sizes);
|
||
} catch (e2) {
|
||
if (e2 instanceof DimensionError) {
|
||
throw new DimensionError(newLength, currentLength, "!=");
|
||
}
|
||
throw e2;
|
||
}
|
||
}
|
||
function processSizesWildcard(sizes, currentLength) {
|
||
var newLength = product(sizes);
|
||
var processedSizes = sizes.slice();
|
||
var WILDCARD = -1;
|
||
var wildCardIndex = sizes.indexOf(WILDCARD);
|
||
var isMoreThanOneWildcard = sizes.indexOf(WILDCARD, wildCardIndex + 1) >= 0;
|
||
if (isMoreThanOneWildcard) {
|
||
throw new Error("More than one wildcard in sizes");
|
||
}
|
||
var hasWildcard = wildCardIndex >= 0;
|
||
var canReplaceWildcard = currentLength % newLength === 0;
|
||
if (hasWildcard) {
|
||
if (canReplaceWildcard) {
|
||
processedSizes[wildCardIndex] = -currentLength / newLength;
|
||
} else {
|
||
throw new Error("Could not replace wildcard, since " + currentLength + " is no multiple of " + -newLength);
|
||
}
|
||
}
|
||
return processedSizes;
|
||
}
|
||
function product(array) {
|
||
return array.reduce((prev, curr) => prev * curr, 1);
|
||
}
|
||
function _reshape(array, sizes) {
|
||
var tmpArray = array;
|
||
var tmpArray2;
|
||
for (var sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) {
|
||
var size2 = sizes[sizeIndex];
|
||
tmpArray2 = [];
|
||
var length = tmpArray.length / size2;
|
||
for (var i = 0; i < length; i++) {
|
||
tmpArray2.push(tmpArray.slice(i * size2, (i + 1) * size2));
|
||
}
|
||
tmpArray = tmpArray2;
|
||
}
|
||
return tmpArray;
|
||
}
|
||
function unsqueeze(array, dims, outer, size2) {
|
||
var s2 = size2 || arraySize(array);
|
||
if (outer) {
|
||
for (var i = 0; i < outer; i++) {
|
||
array = [array];
|
||
s2.unshift(1);
|
||
}
|
||
}
|
||
array = _unsqueeze(array, dims, 0);
|
||
while (s2.length < dims) {
|
||
s2.push(1);
|
||
}
|
||
return array;
|
||
}
|
||
function _unsqueeze(array, dims, dim) {
|
||
var i, ii;
|
||
if (Array.isArray(array)) {
|
||
var next = dim + 1;
|
||
for (i = 0, ii = array.length; i < ii; i++) {
|
||
array[i] = _unsqueeze(array[i], dims, next);
|
||
}
|
||
} else {
|
||
for (var d = dim; d < dims; d++) {
|
||
array = [array];
|
||
}
|
||
}
|
||
return array;
|
||
}
|
||
function flatten(array) {
|
||
if (!Array.isArray(array)) {
|
||
return array;
|
||
}
|
||
var flat = [];
|
||
array.forEach(function callback(value) {
|
||
if (Array.isArray(value)) {
|
||
value.forEach(callback);
|
||
} else {
|
||
flat.push(value);
|
||
}
|
||
});
|
||
return flat;
|
||
}
|
||
function getArrayDataType(array, typeOf2) {
|
||
var type;
|
||
var length = 0;
|
||
for (var i = 0; i < array.length; i++) {
|
||
var item = array[i];
|
||
var _isArray = Array.isArray(item);
|
||
if (i === 0 && _isArray) {
|
||
length = item.length;
|
||
}
|
||
if (_isArray && item.length !== length) {
|
||
return void 0;
|
||
}
|
||
var itemType = _isArray ? getArrayDataType(item, typeOf2) : typeOf2(item);
|
||
if (type === void 0) {
|
||
type = itemType;
|
||
} else if (type !== itemType) {
|
||
return "mixed";
|
||
} else
|
||
;
|
||
}
|
||
return type;
|
||
}
|
||
function concatRecursive(a, b, concatDim, dim) {
|
||
if (dim < concatDim) {
|
||
if (a.length !== b.length) {
|
||
throw new DimensionError(a.length, b.length);
|
||
}
|
||
var c = [];
|
||
for (var i = 0; i < a.length; i++) {
|
||
c[i] = concatRecursive(a[i], b[i], concatDim, dim + 1);
|
||
}
|
||
return c;
|
||
} else {
|
||
return a.concat(b);
|
||
}
|
||
}
|
||
function concat() {
|
||
var arrays = Array.prototype.slice.call(arguments, 0, -1);
|
||
var concatDim = Array.prototype.slice.call(arguments, -1);
|
||
if (arrays.length === 1) {
|
||
return arrays[0];
|
||
}
|
||
if (arrays.length > 1) {
|
||
return arrays.slice(1).reduce(function(A, B) {
|
||
return concatRecursive(A, B, concatDim, 0);
|
||
}, arrays[0]);
|
||
} else {
|
||
throw new Error("Wrong number of arguments in function concat");
|
||
}
|
||
}
|
||
function broadcastSizes() {
|
||
for (var _len = arguments.length, sizes = new Array(_len), _key = 0; _key < _len; _key++) {
|
||
sizes[_key] = arguments[_key];
|
||
}
|
||
var dimensions = sizes.map((s2) => s2.length);
|
||
var N = Math.max(...dimensions);
|
||
var sizeMax = new Array(N).fill(null);
|
||
for (var i = 0; i < sizes.length; i++) {
|
||
var size2 = sizes[i];
|
||
var dim = dimensions[i];
|
||
for (var j = 0; j < dim; j++) {
|
||
var n2 = N - dim + j;
|
||
if (size2[j] > sizeMax[n2]) {
|
||
sizeMax[n2] = size2[j];
|
||
}
|
||
}
|
||
}
|
||
for (var _i = 0; _i < sizes.length; _i++) {
|
||
checkBroadcastingRules(sizes[_i], sizeMax);
|
||
}
|
||
return sizeMax;
|
||
}
|
||
function checkBroadcastingRules(size2, toSize) {
|
||
var N = toSize.length;
|
||
var dim = size2.length;
|
||
for (var j = 0; j < dim; j++) {
|
||
var n2 = N - dim + j;
|
||
if (size2[j] < toSize[n2] && size2[j] > 1 || size2[j] > toSize[n2]) {
|
||
throw new Error("shape missmatch: missmatch is found in arg with shape (".concat(size2, ") not possible to broadcast dimension ").concat(dim, " with size ").concat(size2[j], " to size ").concat(toSize[n2]));
|
||
}
|
||
}
|
||
}
|
||
function broadcastTo(array, toSize) {
|
||
var Asize = arraySize(array);
|
||
if (deepStrictEqual(Asize, toSize)) {
|
||
return array;
|
||
}
|
||
checkBroadcastingRules(Asize, toSize);
|
||
var broadcastedSize = broadcastSizes(Asize, toSize);
|
||
var N = broadcastedSize.length;
|
||
var paddedSize = [...Array(N - Asize.length).fill(1), ...Asize];
|
||
var A = clone(array);
|
||
if (Asize.length < N) {
|
||
A = reshape(A, paddedSize);
|
||
Asize = arraySize(A);
|
||
}
|
||
for (var dim = 0; dim < N; dim++) {
|
||
if (Asize[dim] < broadcastedSize[dim]) {
|
||
A = stretch(A, broadcastedSize[dim], dim);
|
||
Asize = arraySize(A);
|
||
}
|
||
}
|
||
return A;
|
||
}
|
||
function stretch(arrayToStretch, sizeToStretch, dimToStretch) {
|
||
return concat(...Array(sizeToStretch).fill(arrayToStretch), dimToStretch);
|
||
}
|
||
function get(array, index2) {
|
||
if (!Array.isArray(array)) {
|
||
throw new Error("Array expected");
|
||
}
|
||
var size2 = arraySize(array);
|
||
if (index2.length !== size2.length) {
|
||
throw new DimensionError(index2.length, size2.length);
|
||
}
|
||
for (var x = 0; x < index2.length; x++) {
|
||
validateIndex(index2[x], size2[x]);
|
||
}
|
||
return index2.reduce((acc, curr) => acc[curr], array);
|
||
}
|
||
function clone(array) {
|
||
return _extends([], array);
|
||
}
|
||
function optimizeCallback(callback, array, name2) {
|
||
if (typedFunction.isTypedFunction(callback)) {
|
||
var firstIndex = (array.isMatrix ? array.size() : arraySize(array)).map(() => 0);
|
||
var firstValue = array.isMatrix ? array.get(firstIndex) : get(array, firstIndex);
|
||
var hasSingleSignature = Object.keys(callback.signatures).length === 1;
|
||
var numberOfArguments = _findNumberOfArguments(callback, firstValue, firstIndex, array);
|
||
var fastCallback = hasSingleSignature ? Object.values(callback.signatures)[0] : callback;
|
||
if (numberOfArguments >= 1 && numberOfArguments <= 3) {
|
||
return function() {
|
||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||
args[_key] = arguments[_key];
|
||
}
|
||
return _tryFunctionWithArgs(fastCallback, args.slice(0, numberOfArguments), name2, callback.name);
|
||
};
|
||
}
|
||
return function() {
|
||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
||
args[_key2] = arguments[_key2];
|
||
}
|
||
return _tryFunctionWithArgs(fastCallback, args, name2, callback.name);
|
||
};
|
||
}
|
||
return callback;
|
||
}
|
||
function _findNumberOfArguments(callback, value, index2, array) {
|
||
var testArgs = [value, index2, array];
|
||
for (var i = 3; i > 0; i--) {
|
||
var args = testArgs.slice(0, i);
|
||
if (typedFunction.resolve(callback, args) !== null) {
|
||
return i;
|
||
}
|
||
}
|
||
}
|
||
function _tryFunctionWithArgs(func, args, mappingFnName, callbackName) {
|
||
try {
|
||
return func(...args);
|
||
} catch (err) {
|
||
_createCallbackError(err, args, mappingFnName, callbackName);
|
||
}
|
||
}
|
||
function _createCallbackError(err, args, mappingFnName, callbackName) {
|
||
var _err$data;
|
||
if (err instanceof TypeError && ((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.category) === "wrongType") {
|
||
var argsDesc = [];
|
||
argsDesc.push("value: ".concat(typeOf(args[0])));
|
||
if (args.length >= 2) {
|
||
argsDesc.push("index: ".concat(typeOf(args[1])));
|
||
}
|
||
if (args.length >= 3) {
|
||
argsDesc.push("array: ".concat(typeOf(args[2])));
|
||
}
|
||
throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "".concat(callbackName, "(").concat(argsDesc.join(", "), ") at index ").concat(JSON.stringify(args[1])));
|
||
} else {
|
||
throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "to function ".concat(callbackName, ": ").concat(err.message));
|
||
}
|
||
}
|
||
var name$8 = "DenseMatrix";
|
||
var dependencies$8 = ["Matrix"];
|
||
var createDenseMatrixClass = /* @__PURE__ */ factory(name$8, dependencies$8, (_ref) => {
|
||
var {
|
||
Matrix: Matrix2
|
||
} = _ref;
|
||
function DenseMatrix2(data, datatype) {
|
||
if (!(this instanceof DenseMatrix2)) {
|
||
throw new SyntaxError("Constructor must be called with the new operator");
|
||
}
|
||
if (datatype && !isString(datatype)) {
|
||
throw new Error("Invalid datatype: " + datatype);
|
||
}
|
||
if (isMatrix(data)) {
|
||
if (data.type === "DenseMatrix") {
|
||
this._data = clone$2(data._data);
|
||
this._size = clone$2(data._size);
|
||
this._datatype = datatype || data._datatype;
|
||
} else {
|
||
this._data = data.toArray();
|
||
this._size = data.size();
|
||
this._datatype = datatype || data._datatype;
|
||
}
|
||
} else if (data && isArray(data.data) && isArray(data.size)) {
|
||
this._data = data.data;
|
||
this._size = data.size;
|
||
validate(this._data, this._size);
|
||
this._datatype = datatype || data.datatype;
|
||
} else if (isArray(data)) {
|
||
this._data = preprocess(data);
|
||
this._size = arraySize(this._data);
|
||
validate(this._data, this._size);
|
||
this._datatype = datatype;
|
||
} else if (data) {
|
||
throw new TypeError("Unsupported type of data (" + typeOf(data) + ")");
|
||
} else {
|
||
this._data = [];
|
||
this._size = [0];
|
||
this._datatype = datatype;
|
||
}
|
||
}
|
||
DenseMatrix2.prototype = new Matrix2();
|
||
DenseMatrix2.prototype.createDenseMatrix = function(data, datatype) {
|
||
return new DenseMatrix2(data, datatype);
|
||
};
|
||
Object.defineProperty(DenseMatrix2, "name", {
|
||
value: "DenseMatrix"
|
||
});
|
||
DenseMatrix2.prototype.constructor = DenseMatrix2;
|
||
DenseMatrix2.prototype.type = "DenseMatrix";
|
||
DenseMatrix2.prototype.isDenseMatrix = true;
|
||
DenseMatrix2.prototype.getDataType = function() {
|
||
return getArrayDataType(this._data, typeOf);
|
||
};
|
||
DenseMatrix2.prototype.storage = function() {
|
||
return "dense";
|
||
};
|
||
DenseMatrix2.prototype.datatype = function() {
|
||
return this._datatype;
|
||
};
|
||
DenseMatrix2.prototype.create = function(data, datatype) {
|
||
return new DenseMatrix2(data, datatype);
|
||
};
|
||
DenseMatrix2.prototype.subset = function(index2, replacement, defaultValue) {
|
||
switch (arguments.length) {
|
||
case 1:
|
||
return _get(this, index2);
|
||
case 2:
|
||
case 3:
|
||
return _set(this, index2, replacement, defaultValue);
|
||
default:
|
||
throw new SyntaxError("Wrong number of arguments");
|
||
}
|
||
};
|
||
DenseMatrix2.prototype.get = function(index2) {
|
||
return get(this._data, index2);
|
||
};
|
||
DenseMatrix2.prototype.set = function(index2, value, defaultValue) {
|
||
if (!isArray(index2)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (index2.length < this._size.length) {
|
||
throw new DimensionError(index2.length, this._size.length, "<");
|
||
}
|
||
var i, ii, indexI;
|
||
var size2 = index2.map(function(i2) {
|
||
return i2 + 1;
|
||
});
|
||
_fit(this, size2, defaultValue);
|
||
var data = this._data;
|
||
for (i = 0, ii = index2.length - 1; i < ii; i++) {
|
||
indexI = index2[i];
|
||
validateIndex(indexI, data.length);
|
||
data = data[indexI];
|
||
}
|
||
indexI = index2[index2.length - 1];
|
||
validateIndex(indexI, data.length);
|
||
data[indexI] = value;
|
||
return this;
|
||
};
|
||
function _get(matrix2, index2) {
|
||
if (!isIndex(index2)) {
|
||
throw new TypeError("Invalid index");
|
||
}
|
||
var isScalar = index2.isScalar();
|
||
if (isScalar) {
|
||
return matrix2.get(index2.min());
|
||
} else {
|
||
var size2 = index2.size();
|
||
if (size2.length !== matrix2._size.length) {
|
||
throw new DimensionError(size2.length, matrix2._size.length);
|
||
}
|
||
var min2 = index2.min();
|
||
var max2 = index2.max();
|
||
for (var i = 0, ii = matrix2._size.length; i < ii; i++) {
|
||
validateIndex(min2[i], matrix2._size[i]);
|
||
validateIndex(max2[i], matrix2._size[i]);
|
||
}
|
||
return new DenseMatrix2(_getSubmatrix(matrix2._data, index2, size2.length, 0), matrix2._datatype);
|
||
}
|
||
}
|
||
function _getSubmatrix(data, index2, dims, dim) {
|
||
var last = dim === dims - 1;
|
||
var range = index2.dimension(dim);
|
||
if (last) {
|
||
return range.map(function(i) {
|
||
validateIndex(i, data.length);
|
||
return data[i];
|
||
}).valueOf();
|
||
} else {
|
||
return range.map(function(i) {
|
||
validateIndex(i, data.length);
|
||
var child = data[i];
|
||
return _getSubmatrix(child, index2, dims, dim + 1);
|
||
}).valueOf();
|
||
}
|
||
}
|
||
function _set(matrix2, index2, submatrix, defaultValue) {
|
||
if (!index2 || index2.isIndex !== true) {
|
||
throw new TypeError("Invalid index");
|
||
}
|
||
var iSize = index2.size();
|
||
var isScalar = index2.isScalar();
|
||
var sSize;
|
||
if (isMatrix(submatrix)) {
|
||
sSize = submatrix.size();
|
||
submatrix = submatrix.valueOf();
|
||
} else {
|
||
sSize = arraySize(submatrix);
|
||
}
|
||
if (isScalar) {
|
||
if (sSize.length !== 0) {
|
||
throw new TypeError("Scalar expected");
|
||
}
|
||
matrix2.set(index2.min(), submatrix, defaultValue);
|
||
} else {
|
||
if (!deepStrictEqual(sSize, iSize)) {
|
||
try {
|
||
if (sSize.length === 0) {
|
||
submatrix = broadcastTo([submatrix], iSize);
|
||
} else {
|
||
submatrix = broadcastTo(submatrix, iSize);
|
||
}
|
||
sSize = arraySize(submatrix);
|
||
} catch (_unused) {
|
||
}
|
||
}
|
||
if (iSize.length < matrix2._size.length) {
|
||
throw new DimensionError(iSize.length, matrix2._size.length, "<");
|
||
}
|
||
if (sSize.length < iSize.length) {
|
||
var i = 0;
|
||
var outer = 0;
|
||
while (iSize[i] === 1 && sSize[i] === 1) {
|
||
i++;
|
||
}
|
||
while (iSize[i] === 1) {
|
||
outer++;
|
||
i++;
|
||
}
|
||
submatrix = unsqueeze(submatrix, iSize.length, outer, sSize);
|
||
}
|
||
if (!deepStrictEqual(iSize, sSize)) {
|
||
throw new DimensionError(iSize, sSize, ">");
|
||
}
|
||
var size2 = index2.max().map(function(i2) {
|
||
return i2 + 1;
|
||
});
|
||
_fit(matrix2, size2, defaultValue);
|
||
var dims = iSize.length;
|
||
var dim = 0;
|
||
_setSubmatrix(matrix2._data, index2, submatrix, dims, dim);
|
||
}
|
||
return matrix2;
|
||
}
|
||
function _setSubmatrix(data, index2, submatrix, dims, dim) {
|
||
var last = dim === dims - 1;
|
||
var range = index2.dimension(dim);
|
||
if (last) {
|
||
range.forEach(function(dataIndex, subIndex) {
|
||
validateIndex(dataIndex);
|
||
data[dataIndex] = submatrix[subIndex[0]];
|
||
});
|
||
} else {
|
||
range.forEach(function(dataIndex, subIndex) {
|
||
validateIndex(dataIndex);
|
||
_setSubmatrix(data[dataIndex], index2, submatrix[subIndex[0]], dims, dim + 1);
|
||
});
|
||
}
|
||
}
|
||
DenseMatrix2.prototype.resize = function(size2, defaultValue, copy) {
|
||
if (!isCollection(size2)) {
|
||
throw new TypeError("Array or Matrix expected");
|
||
}
|
||
var sizeArray = size2.valueOf().map((value) => {
|
||
return Array.isArray(value) && value.length === 1 ? value[0] : value;
|
||
});
|
||
var m = copy ? this.clone() : this;
|
||
return _resize2(m, sizeArray, defaultValue);
|
||
};
|
||
function _resize2(matrix2, size2, defaultValue) {
|
||
if (size2.length === 0) {
|
||
var v = matrix2._data;
|
||
while (isArray(v)) {
|
||
v = v[0];
|
||
}
|
||
return v;
|
||
}
|
||
matrix2._size = size2.slice(0);
|
||
matrix2._data = resize(matrix2._data, matrix2._size, defaultValue);
|
||
return matrix2;
|
||
}
|
||
DenseMatrix2.prototype.reshape = function(size2, copy) {
|
||
var m = copy ? this.clone() : this;
|
||
m._data = reshape(m._data, size2);
|
||
var currentLength = m._size.reduce((length, size3) => length * size3);
|
||
m._size = processSizesWildcard(size2, currentLength);
|
||
return m;
|
||
};
|
||
function _fit(matrix2, size2, defaultValue) {
|
||
var newSize = matrix2._size.slice(0);
|
||
var changed = false;
|
||
while (newSize.length < size2.length) {
|
||
newSize.push(0);
|
||
changed = true;
|
||
}
|
||
for (var i = 0, ii = size2.length; i < ii; i++) {
|
||
if (size2[i] > newSize[i]) {
|
||
newSize[i] = size2[i];
|
||
changed = true;
|
||
}
|
||
}
|
||
if (changed) {
|
||
_resize2(matrix2, newSize, defaultValue);
|
||
}
|
||
}
|
||
DenseMatrix2.prototype.clone = function() {
|
||
var m = new DenseMatrix2({
|
||
data: clone$2(this._data),
|
||
size: clone$2(this._size),
|
||
datatype: this._datatype
|
||
});
|
||
return m;
|
||
};
|
||
DenseMatrix2.prototype.size = function() {
|
||
return this._size.slice(0);
|
||
};
|
||
DenseMatrix2.prototype._forEach = function(callback) {
|
||
var me = this;
|
||
var s2 = me.size();
|
||
if (s2.length === 1) {
|
||
for (var i = 0; i < s2[0]; i++) {
|
||
callback(me._data, i, [i]);
|
||
}
|
||
return;
|
||
}
|
||
var index2 = Array(s2.length).fill(0);
|
||
var data = Array(s2.length - 1);
|
||
var last = data.length - 1;
|
||
data[0] = me._data[0];
|
||
for (var _i = 0; _i < last; _i++) {
|
||
data[_i + 1] = data[_i][0];
|
||
}
|
||
index2[last] = -1;
|
||
while (true) {
|
||
var _i2 = void 0;
|
||
for (_i2 = last; _i2 >= 0; _i2--) {
|
||
index2[_i2]++;
|
||
if (index2[_i2] === s2[_i2]) {
|
||
index2[_i2] = 0;
|
||
continue;
|
||
}
|
||
data[_i2] = _i2 === 0 ? me._data[index2[_i2]] : data[_i2 - 1][index2[_i2]];
|
||
for (var j = _i2; j < last; j++) {
|
||
data[j + 1] = data[j][0];
|
||
}
|
||
for (var _j = 0; _j < s2[data.length]; _j++) {
|
||
index2[data.length] = _j;
|
||
callback(data[last], _j, index2.slice(0));
|
||
}
|
||
break;
|
||
}
|
||
if (_i2 === -1) {
|
||
break;
|
||
}
|
||
}
|
||
};
|
||
DenseMatrix2.prototype.map = function(callback) {
|
||
var me = this;
|
||
var result = new DenseMatrix2(me);
|
||
var fastCallback = optimizeCallback(callback, me._data, "map");
|
||
result._forEach(function(arr, i, index2) {
|
||
arr[i] = fastCallback(arr[i], index2, me);
|
||
});
|
||
return result;
|
||
};
|
||
DenseMatrix2.prototype.forEach = function(callback) {
|
||
var me = this;
|
||
var fastCallback = optimizeCallback(callback, me._data, "map");
|
||
me._forEach(function(arr, i, index2) {
|
||
fastCallback(arr[i], index2, me);
|
||
});
|
||
};
|
||
DenseMatrix2.prototype[Symbol.iterator] = function* () {
|
||
var _recurse = function* recurse(value, index2) {
|
||
if (isArray(value)) {
|
||
for (var i = 0; i < value.length; i++) {
|
||
yield* _recurse(value[i], index2.concat(i));
|
||
}
|
||
} else {
|
||
yield {
|
||
value,
|
||
index: index2
|
||
};
|
||
}
|
||
};
|
||
yield* _recurse(this._data, []);
|
||
};
|
||
DenseMatrix2.prototype.rows = function() {
|
||
var result = [];
|
||
var s2 = this.size();
|
||
if (s2.length !== 2) {
|
||
throw new TypeError("Rows can only be returned for a 2D matrix.");
|
||
}
|
||
var data = this._data;
|
||
for (var row of data) {
|
||
result.push(new DenseMatrix2([row], this._datatype));
|
||
}
|
||
return result;
|
||
};
|
||
DenseMatrix2.prototype.columns = function() {
|
||
var _this = this;
|
||
var result = [];
|
||
var s2 = this.size();
|
||
if (s2.length !== 2) {
|
||
throw new TypeError("Rows can only be returned for a 2D matrix.");
|
||
}
|
||
var data = this._data;
|
||
var _loop = function _loop2(i2) {
|
||
var col = data.map((row) => [row[i2]]);
|
||
result.push(new DenseMatrix2(col, _this._datatype));
|
||
};
|
||
for (var i = 0; i < s2[1]; i++) {
|
||
_loop(i);
|
||
}
|
||
return result;
|
||
};
|
||
DenseMatrix2.prototype.toArray = function() {
|
||
return clone$2(this._data);
|
||
};
|
||
DenseMatrix2.prototype.valueOf = function() {
|
||
return this._data;
|
||
};
|
||
DenseMatrix2.prototype.format = function(options) {
|
||
return format(this._data, options);
|
||
};
|
||
DenseMatrix2.prototype.toString = function() {
|
||
return format(this._data);
|
||
};
|
||
DenseMatrix2.prototype.toJSON = function() {
|
||
return {
|
||
mathjs: "DenseMatrix",
|
||
data: this._data,
|
||
size: this._size,
|
||
datatype: this._datatype
|
||
};
|
||
};
|
||
DenseMatrix2.prototype.diagonal = function(k) {
|
||
if (k) {
|
||
if (isBigNumber(k)) {
|
||
k = k.toNumber();
|
||
}
|
||
if (!isNumber(k) || !isInteger(k)) {
|
||
throw new TypeError("The parameter k must be an integer number");
|
||
}
|
||
} else {
|
||
k = 0;
|
||
}
|
||
var kSuper = k > 0 ? k : 0;
|
||
var kSub = k < 0 ? -k : 0;
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var n2 = Math.min(rows - kSub, columns - kSuper);
|
||
var data = [];
|
||
for (var i = 0; i < n2; i++) {
|
||
data[i] = this._data[i + kSub][i + kSuper];
|
||
}
|
||
return new DenseMatrix2({
|
||
data,
|
||
size: [n2],
|
||
datatype: this._datatype
|
||
});
|
||
};
|
||
DenseMatrix2.diagonal = function(size2, value, k, defaultValue) {
|
||
if (!isArray(size2)) {
|
||
throw new TypeError("Array expected, size parameter");
|
||
}
|
||
if (size2.length !== 2) {
|
||
throw new Error("Only two dimensions matrix are supported");
|
||
}
|
||
size2 = size2.map(function(s2) {
|
||
if (isBigNumber(s2)) {
|
||
s2 = s2.toNumber();
|
||
}
|
||
if (!isNumber(s2) || !isInteger(s2) || s2 < 1) {
|
||
throw new Error("Size values must be positive integers");
|
||
}
|
||
return s2;
|
||
});
|
||
if (k) {
|
||
if (isBigNumber(k)) {
|
||
k = k.toNumber();
|
||
}
|
||
if (!isNumber(k) || !isInteger(k)) {
|
||
throw new TypeError("The parameter k must be an integer number");
|
||
}
|
||
} else {
|
||
k = 0;
|
||
}
|
||
var kSuper = k > 0 ? k : 0;
|
||
var kSub = k < 0 ? -k : 0;
|
||
var rows = size2[0];
|
||
var columns = size2[1];
|
||
var n2 = Math.min(rows - kSub, columns - kSuper);
|
||
var _value;
|
||
if (isArray(value)) {
|
||
if (value.length !== n2) {
|
||
throw new Error("Invalid value array length");
|
||
}
|
||
_value = function _value2(i) {
|
||
return value[i];
|
||
};
|
||
} else if (isMatrix(value)) {
|
||
var ms = value.size();
|
||
if (ms.length !== 1 || ms[0] !== n2) {
|
||
throw new Error("Invalid matrix length");
|
||
}
|
||
_value = function _value2(i) {
|
||
return value.get([i]);
|
||
};
|
||
} else {
|
||
_value = function _value2() {
|
||
return value;
|
||
};
|
||
}
|
||
if (!defaultValue) {
|
||
defaultValue = isBigNumber(_value(0)) ? _value(0).mul(0) : 0;
|
||
}
|
||
var data = [];
|
||
if (size2.length > 0) {
|
||
data = resize(data, size2, defaultValue);
|
||
for (var d = 0; d < n2; d++) {
|
||
data[d + kSub][d + kSuper] = _value(d);
|
||
}
|
||
}
|
||
return new DenseMatrix2({
|
||
data,
|
||
size: [rows, columns]
|
||
});
|
||
};
|
||
DenseMatrix2.fromJSON = function(json) {
|
||
return new DenseMatrix2(json);
|
||
};
|
||
DenseMatrix2.prototype.swapRows = function(i, j) {
|
||
if (!isNumber(i) || !isInteger(i) || !isNumber(j) || !isInteger(j)) {
|
||
throw new Error("Row index must be positive integers");
|
||
}
|
||
if (this._size.length !== 2) {
|
||
throw new Error("Only two dimensional matrix is supported");
|
||
}
|
||
validateIndex(i, this._size[0]);
|
||
validateIndex(j, this._size[0]);
|
||
DenseMatrix2._swapRows(i, j, this._data);
|
||
return this;
|
||
};
|
||
DenseMatrix2._swapRows = function(i, j, data) {
|
||
var vi = data[i];
|
||
data[i] = data[j];
|
||
data[j] = vi;
|
||
};
|
||
function preprocess(data) {
|
||
if (isMatrix(data)) {
|
||
return preprocess(data.valueOf());
|
||
}
|
||
if (isArray(data)) {
|
||
return data.map(preprocess);
|
||
}
|
||
return data;
|
||
}
|
||
return DenseMatrix2;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
function deepMap(array, callback, skipZeros) {
|
||
if (array && typeof array.map === "function") {
|
||
return array.map(function(x) {
|
||
return deepMap(x, callback);
|
||
});
|
||
} else {
|
||
return callback(array);
|
||
}
|
||
}
|
||
function roundNumber(value) {
|
||
var decimals = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
||
if (!isInteger(decimals) || decimals < 0 || decimals > 15) {
|
||
throw new Error("Number of decimals in function round must be an integer from 0 to 15 inclusive");
|
||
}
|
||
return parseFloat(toFixed$1(value, decimals));
|
||
}
|
||
function nearlyEqual(a, b) {
|
||
var relTol = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1e-9;
|
||
var absTol = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
||
if (relTol <= 0) {
|
||
throw new Error("Relative tolerance must be greater than 0");
|
||
}
|
||
if (absTol < 0) {
|
||
throw new Error("Absolute tolerance must be at least 0");
|
||
}
|
||
if (a.isNaN() || b.isNaN()) {
|
||
return false;
|
||
}
|
||
if (!a.isFinite() || !b.isFinite()) {
|
||
return a.eq(b);
|
||
}
|
||
if (a.eq(b)) {
|
||
return true;
|
||
}
|
||
return a.minus(b).abs().lte(a.constructor.max(a.constructor.max(a.abs(), b.abs()).mul(relTol), absTol));
|
||
}
|
||
function complexEquals(x, y, relTol, absTol) {
|
||
return nearlyEqual$1(x.re, y.re, relTol, absTol) && nearlyEqual$1(x.im, y.im, relTol, absTol);
|
||
}
|
||
var createCompareUnits = /* @__PURE__ */ factory("compareUnits", ["typed"], (_ref) => {
|
||
var {
|
||
typed: typed2
|
||
} = _ref;
|
||
return {
|
||
"Unit, Unit": typed2.referToSelf((self2) => (x, y) => {
|
||
if (!x.equalBase(y)) {
|
||
throw new Error("Cannot compare units with different base");
|
||
}
|
||
return typed2.find(self2, [x.valueType(), y.valueType()])(x.value, y.value);
|
||
})
|
||
};
|
||
});
|
||
var name$7 = "equalScalar";
|
||
var dependencies$7 = ["typed", "config"];
|
||
var createEqualScalar = /* @__PURE__ */ factory(name$7, dependencies$7, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
config: config3
|
||
} = _ref;
|
||
var compareUnits = createCompareUnits({
|
||
typed: typed2
|
||
});
|
||
return typed2(name$7, {
|
||
"boolean, boolean": function boolean_boolean(x, y) {
|
||
return x === y;
|
||
},
|
||
"number, number": function number_number(x, y) {
|
||
return nearlyEqual$1(x, y, config3.relTol, config3.absTol);
|
||
},
|
||
"BigNumber, BigNumber": function BigNumber_BigNumber(x, y) {
|
||
return x.eq(y) || nearlyEqual(x, y, config3.relTol, config3.absTol);
|
||
},
|
||
"bigint, bigint": function bigint_bigint(x, y) {
|
||
return x === y;
|
||
},
|
||
"Fraction, Fraction": function Fraction_Fraction(x, y) {
|
||
return x.equals(y);
|
||
},
|
||
"Complex, Complex": function Complex_Complex(x, y) {
|
||
return complexEquals(x, y, config3.relTol, config3.absTol);
|
||
}
|
||
}, compareUnits);
|
||
});
|
||
factory(name$7, ["typed", "config"], (_ref2) => {
|
||
var {
|
||
typed: typed2,
|
||
config: config3
|
||
} = _ref2;
|
||
return typed2(name$7, {
|
||
"number, number": function number_number(x, y) {
|
||
return nearlyEqual$1(x, y, config3.relTol, config3.absTol);
|
||
}
|
||
});
|
||
});
|
||
var name$6 = "SparseMatrix";
|
||
var dependencies$6 = ["typed", "equalScalar", "Matrix"];
|
||
var createSparseMatrixClass = /* @__PURE__ */ factory(name$6, dependencies$6, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
equalScalar: equalScalar2,
|
||
Matrix: Matrix2
|
||
} = _ref;
|
||
function SparseMatrix2(data, datatype) {
|
||
if (!(this instanceof SparseMatrix2)) {
|
||
throw new SyntaxError("Constructor must be called with the new operator");
|
||
}
|
||
if (datatype && !isString(datatype)) {
|
||
throw new Error("Invalid datatype: " + datatype);
|
||
}
|
||
if (isMatrix(data)) {
|
||
_createFromMatrix(this, data, datatype);
|
||
} else if (data && isArray(data.index) && isArray(data.ptr) && isArray(data.size)) {
|
||
this._values = data.values;
|
||
this._index = data.index;
|
||
this._ptr = data.ptr;
|
||
this._size = data.size;
|
||
this._datatype = datatype || data.datatype;
|
||
} else if (isArray(data)) {
|
||
_createFromArray(this, data, datatype);
|
||
} else if (data) {
|
||
throw new TypeError("Unsupported type of data (" + typeOf(data) + ")");
|
||
} else {
|
||
this._values = [];
|
||
this._index = [];
|
||
this._ptr = [0];
|
||
this._size = [0, 0];
|
||
this._datatype = datatype;
|
||
}
|
||
}
|
||
function _createFromMatrix(matrix2, source, datatype) {
|
||
if (source.type === "SparseMatrix") {
|
||
matrix2._values = source._values ? clone$2(source._values) : void 0;
|
||
matrix2._index = clone$2(source._index);
|
||
matrix2._ptr = clone$2(source._ptr);
|
||
matrix2._size = clone$2(source._size);
|
||
matrix2._datatype = datatype || source._datatype;
|
||
} else {
|
||
_createFromArray(matrix2, source.valueOf(), datatype || source._datatype);
|
||
}
|
||
}
|
||
function _createFromArray(matrix2, data, datatype) {
|
||
matrix2._values = [];
|
||
matrix2._index = [];
|
||
matrix2._ptr = [];
|
||
matrix2._datatype = datatype;
|
||
var rows = data.length;
|
||
var columns = 0;
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
if (isString(datatype)) {
|
||
eq = typed2.find(equalScalar2, [datatype, datatype]) || equalScalar2;
|
||
zero = typed2.convert(0, datatype);
|
||
}
|
||
if (rows > 0) {
|
||
var j = 0;
|
||
do {
|
||
matrix2._ptr.push(matrix2._index.length);
|
||
for (var i = 0; i < rows; i++) {
|
||
var row = data[i];
|
||
if (isArray(row)) {
|
||
if (j === 0 && columns < row.length) {
|
||
columns = row.length;
|
||
}
|
||
if (j < row.length) {
|
||
var v = row[j];
|
||
if (!eq(v, zero)) {
|
||
matrix2._values.push(v);
|
||
matrix2._index.push(i);
|
||
}
|
||
}
|
||
} else {
|
||
if (j === 0 && columns < 1) {
|
||
columns = 1;
|
||
}
|
||
if (!eq(row, zero)) {
|
||
matrix2._values.push(row);
|
||
matrix2._index.push(i);
|
||
}
|
||
}
|
||
}
|
||
j++;
|
||
} while (j < columns);
|
||
}
|
||
matrix2._ptr.push(matrix2._index.length);
|
||
matrix2._size = [rows, columns];
|
||
}
|
||
SparseMatrix2.prototype = new Matrix2();
|
||
SparseMatrix2.prototype.createSparseMatrix = function(data, datatype) {
|
||
return new SparseMatrix2(data, datatype);
|
||
};
|
||
Object.defineProperty(SparseMatrix2, "name", {
|
||
value: "SparseMatrix"
|
||
});
|
||
SparseMatrix2.prototype.constructor = SparseMatrix2;
|
||
SparseMatrix2.prototype.type = "SparseMatrix";
|
||
SparseMatrix2.prototype.isSparseMatrix = true;
|
||
SparseMatrix2.prototype.getDataType = function() {
|
||
return getArrayDataType(this._values, typeOf);
|
||
};
|
||
SparseMatrix2.prototype.storage = function() {
|
||
return "sparse";
|
||
};
|
||
SparseMatrix2.prototype.datatype = function() {
|
||
return this._datatype;
|
||
};
|
||
SparseMatrix2.prototype.create = function(data, datatype) {
|
||
return new SparseMatrix2(data, datatype);
|
||
};
|
||
SparseMatrix2.prototype.density = function() {
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
return rows !== 0 && columns !== 0 ? this._index.length / (rows * columns) : 0;
|
||
};
|
||
SparseMatrix2.prototype.subset = function(index2, replacement, defaultValue) {
|
||
if (!this._values) {
|
||
throw new Error("Cannot invoke subset on a Pattern only matrix");
|
||
}
|
||
switch (arguments.length) {
|
||
case 1:
|
||
return _getsubset(this, index2);
|
||
case 2:
|
||
case 3:
|
||
return _setsubset(this, index2, replacement, defaultValue);
|
||
default:
|
||
throw new SyntaxError("Wrong number of arguments");
|
||
}
|
||
};
|
||
function _getsubset(matrix2, idx) {
|
||
if (!isIndex(idx)) {
|
||
throw new TypeError("Invalid index");
|
||
}
|
||
var isScalar = idx.isScalar();
|
||
if (isScalar) {
|
||
return matrix2.get(idx.min());
|
||
}
|
||
var size2 = idx.size();
|
||
if (size2.length !== matrix2._size.length) {
|
||
throw new DimensionError(size2.length, matrix2._size.length);
|
||
}
|
||
var i, ii, k, kk;
|
||
var min2 = idx.min();
|
||
var max2 = idx.max();
|
||
for (i = 0, ii = matrix2._size.length; i < ii; i++) {
|
||
validateIndex(min2[i], matrix2._size[i]);
|
||
validateIndex(max2[i], matrix2._size[i]);
|
||
}
|
||
var mvalues = matrix2._values;
|
||
var mindex = matrix2._index;
|
||
var mptr = matrix2._ptr;
|
||
var rows = idx.dimension(0);
|
||
var columns = idx.dimension(1);
|
||
var w = [];
|
||
var pv = [];
|
||
rows.forEach(function(i2, r) {
|
||
pv[i2] = r[0];
|
||
w[i2] = true;
|
||
});
|
||
var values = mvalues ? [] : void 0;
|
||
var index2 = [];
|
||
var ptr = [];
|
||
columns.forEach(function(j) {
|
||
ptr.push(index2.length);
|
||
for (k = mptr[j], kk = mptr[j + 1]; k < kk; k++) {
|
||
i = mindex[k];
|
||
if (w[i] === true) {
|
||
index2.push(pv[i]);
|
||
if (values) {
|
||
values.push(mvalues[k]);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
ptr.push(index2.length);
|
||
return new SparseMatrix2({
|
||
values,
|
||
index: index2,
|
||
ptr,
|
||
size: size2,
|
||
datatype: matrix2._datatype
|
||
});
|
||
}
|
||
function _setsubset(matrix2, index2, submatrix, defaultValue) {
|
||
if (!index2 || index2.isIndex !== true) {
|
||
throw new TypeError("Invalid index");
|
||
}
|
||
var iSize = index2.size();
|
||
var isScalar = index2.isScalar();
|
||
var sSize;
|
||
if (isMatrix(submatrix)) {
|
||
sSize = submatrix.size();
|
||
submatrix = submatrix.toArray();
|
||
} else {
|
||
sSize = arraySize(submatrix);
|
||
}
|
||
if (isScalar) {
|
||
if (sSize.length !== 0) {
|
||
throw new TypeError("Scalar expected");
|
||
}
|
||
matrix2.set(index2.min(), submatrix, defaultValue);
|
||
} else {
|
||
if (iSize.length !== 1 && iSize.length !== 2) {
|
||
throw new DimensionError(iSize.length, matrix2._size.length, "<");
|
||
}
|
||
if (sSize.length < iSize.length) {
|
||
var i = 0;
|
||
var outer = 0;
|
||
while (iSize[i] === 1 && sSize[i] === 1) {
|
||
i++;
|
||
}
|
||
while (iSize[i] === 1) {
|
||
outer++;
|
||
i++;
|
||
}
|
||
submatrix = unsqueeze(submatrix, iSize.length, outer, sSize);
|
||
}
|
||
if (!deepStrictEqual(iSize, sSize)) {
|
||
throw new DimensionError(iSize, sSize, ">");
|
||
}
|
||
if (iSize.length === 1) {
|
||
var range = index2.dimension(0);
|
||
range.forEach(function(dataIndex, subIndex) {
|
||
validateIndex(dataIndex);
|
||
matrix2.set([dataIndex, 0], submatrix[subIndex[0]], defaultValue);
|
||
});
|
||
} else {
|
||
var firstDimensionRange = index2.dimension(0);
|
||
var secondDimensionRange = index2.dimension(1);
|
||
firstDimensionRange.forEach(function(firstDataIndex, firstSubIndex) {
|
||
validateIndex(firstDataIndex);
|
||
secondDimensionRange.forEach(function(secondDataIndex, secondSubIndex) {
|
||
validateIndex(secondDataIndex);
|
||
matrix2.set([firstDataIndex, secondDataIndex], submatrix[firstSubIndex[0]][secondSubIndex[0]], defaultValue);
|
||
});
|
||
});
|
||
}
|
||
}
|
||
return matrix2;
|
||
}
|
||
SparseMatrix2.prototype.get = function(index2) {
|
||
if (!isArray(index2)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (index2.length !== this._size.length) {
|
||
throw new DimensionError(index2.length, this._size.length);
|
||
}
|
||
if (!this._values) {
|
||
throw new Error("Cannot invoke get on a Pattern only matrix");
|
||
}
|
||
var i = index2[0];
|
||
var j = index2[1];
|
||
validateIndex(i, this._size[0]);
|
||
validateIndex(j, this._size[1]);
|
||
var k = _getValueIndex(i, this._ptr[j], this._ptr[j + 1], this._index);
|
||
if (k < this._ptr[j + 1] && this._index[k] === i) {
|
||
return this._values[k];
|
||
}
|
||
return 0;
|
||
};
|
||
SparseMatrix2.prototype.set = function(index2, v, defaultValue) {
|
||
if (!isArray(index2)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (index2.length !== this._size.length) {
|
||
throw new DimensionError(index2.length, this._size.length);
|
||
}
|
||
if (!this._values) {
|
||
throw new Error("Cannot invoke set on a Pattern only matrix");
|
||
}
|
||
var i = index2[0];
|
||
var j = index2[1];
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
if (isString(this._datatype)) {
|
||
eq = typed2.find(equalScalar2, [this._datatype, this._datatype]) || equalScalar2;
|
||
zero = typed2.convert(0, this._datatype);
|
||
}
|
||
if (i > rows - 1 || j > columns - 1) {
|
||
_resize2(this, Math.max(i + 1, rows), Math.max(j + 1, columns), defaultValue);
|
||
rows = this._size[0];
|
||
columns = this._size[1];
|
||
}
|
||
validateIndex(i, rows);
|
||
validateIndex(j, columns);
|
||
var k = _getValueIndex(i, this._ptr[j], this._ptr[j + 1], this._index);
|
||
if (k < this._ptr[j + 1] && this._index[k] === i) {
|
||
if (!eq(v, zero)) {
|
||
this._values[k] = v;
|
||
} else {
|
||
_remove(k, j, this._values, this._index, this._ptr);
|
||
}
|
||
} else {
|
||
if (!eq(v, zero)) {
|
||
_insert(k, i, j, v, this._values, this._index, this._ptr);
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
function _getValueIndex(i, top, bottom, index2) {
|
||
if (bottom - top === 0) {
|
||
return bottom;
|
||
}
|
||
for (var r = top; r < bottom; r++) {
|
||
if (index2[r] === i) {
|
||
return r;
|
||
}
|
||
}
|
||
return top;
|
||
}
|
||
function _remove(k, j, values, index2, ptr) {
|
||
values.splice(k, 1);
|
||
index2.splice(k, 1);
|
||
for (var x = j + 1; x < ptr.length; x++) {
|
||
ptr[x]--;
|
||
}
|
||
}
|
||
function _insert(k, i, j, v, values, index2, ptr) {
|
||
values.splice(k, 0, v);
|
||
index2.splice(k, 0, i);
|
||
for (var x = j + 1; x < ptr.length; x++) {
|
||
ptr[x]++;
|
||
}
|
||
}
|
||
SparseMatrix2.prototype.resize = function(size2, defaultValue, copy) {
|
||
if (!isCollection(size2)) {
|
||
throw new TypeError("Array or Matrix expected");
|
||
}
|
||
var sizeArray = size2.valueOf().map((value) => {
|
||
return Array.isArray(value) && value.length === 1 ? value[0] : value;
|
||
});
|
||
if (sizeArray.length !== 2) {
|
||
throw new Error("Only two dimensions matrix are supported");
|
||
}
|
||
sizeArray.forEach(function(value) {
|
||
if (!isNumber(value) || !isInteger(value) || value < 0) {
|
||
throw new TypeError("Invalid size, must contain positive integers (size: " + format(sizeArray) + ")");
|
||
}
|
||
});
|
||
var m = copy ? this.clone() : this;
|
||
return _resize2(m, sizeArray[0], sizeArray[1], defaultValue);
|
||
};
|
||
function _resize2(matrix2, rows, columns, defaultValue) {
|
||
var value = defaultValue || 0;
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
if (isString(matrix2._datatype)) {
|
||
eq = typed2.find(equalScalar2, [matrix2._datatype, matrix2._datatype]) || equalScalar2;
|
||
zero = typed2.convert(0, matrix2._datatype);
|
||
value = typed2.convert(value, matrix2._datatype);
|
||
}
|
||
var ins = !eq(value, zero);
|
||
var r = matrix2._size[0];
|
||
var c = matrix2._size[1];
|
||
var i, j, k;
|
||
if (columns > c) {
|
||
for (j = c; j < columns; j++) {
|
||
matrix2._ptr[j] = matrix2._values.length;
|
||
if (ins) {
|
||
for (i = 0; i < r; i++) {
|
||
matrix2._values.push(value);
|
||
matrix2._index.push(i);
|
||
}
|
||
}
|
||
}
|
||
matrix2._ptr[columns] = matrix2._values.length;
|
||
} else if (columns < c) {
|
||
matrix2._ptr.splice(columns + 1, c - columns);
|
||
matrix2._values.splice(matrix2._ptr[columns], matrix2._values.length);
|
||
matrix2._index.splice(matrix2._ptr[columns], matrix2._index.length);
|
||
}
|
||
c = columns;
|
||
if (rows > r) {
|
||
if (ins) {
|
||
var n2 = 0;
|
||
for (j = 0; j < c; j++) {
|
||
matrix2._ptr[j] = matrix2._ptr[j] + n2;
|
||
k = matrix2._ptr[j + 1] + n2;
|
||
var p2 = 0;
|
||
for (i = r; i < rows; i++, p2++) {
|
||
matrix2._values.splice(k + p2, 0, value);
|
||
matrix2._index.splice(k + p2, 0, i);
|
||
n2++;
|
||
}
|
||
}
|
||
matrix2._ptr[c] = matrix2._values.length;
|
||
}
|
||
} else if (rows < r) {
|
||
var d = 0;
|
||
for (j = 0; j < c; j++) {
|
||
matrix2._ptr[j] = matrix2._ptr[j] - d;
|
||
var k0 = matrix2._ptr[j];
|
||
var k1 = matrix2._ptr[j + 1] - d;
|
||
for (k = k0; k < k1; k++) {
|
||
i = matrix2._index[k];
|
||
if (i > rows - 1) {
|
||
matrix2._values.splice(k, 1);
|
||
matrix2._index.splice(k, 1);
|
||
d++;
|
||
}
|
||
}
|
||
}
|
||
matrix2._ptr[j] = matrix2._values.length;
|
||
}
|
||
matrix2._size[0] = rows;
|
||
matrix2._size[1] = columns;
|
||
return matrix2;
|
||
}
|
||
SparseMatrix2.prototype.reshape = function(sizes, copy) {
|
||
if (!isArray(sizes)) {
|
||
throw new TypeError("Array expected");
|
||
}
|
||
if (sizes.length !== 2) {
|
||
throw new Error("Sparse matrices can only be reshaped in two dimensions");
|
||
}
|
||
sizes.forEach(function(value) {
|
||
if (!isNumber(value) || !isInteger(value) || value <= -2 || value === 0) {
|
||
throw new TypeError("Invalid size, must contain positive integers or -1 (size: " + format(sizes) + ")");
|
||
}
|
||
});
|
||
var currentLength = this._size[0] * this._size[1];
|
||
sizes = processSizesWildcard(sizes, currentLength);
|
||
var newLength = sizes[0] * sizes[1];
|
||
if (currentLength !== newLength) {
|
||
throw new Error("Reshaping sparse matrix will result in the wrong number of elements");
|
||
}
|
||
var m = copy ? this.clone() : this;
|
||
if (this._size[0] === sizes[0] && this._size[1] === sizes[1]) {
|
||
return m;
|
||
}
|
||
var colIndex = [];
|
||
for (var i = 0; i < m._ptr.length; i++) {
|
||
for (var j = 0; j < m._ptr[i + 1] - m._ptr[i]; j++) {
|
||
colIndex.push(i);
|
||
}
|
||
}
|
||
var values = m._values.slice();
|
||
var rowIndex = m._index.slice();
|
||
for (var _i = 0; _i < m._index.length; _i++) {
|
||
var r1 = rowIndex[_i];
|
||
var c1 = colIndex[_i];
|
||
var flat = r1 * m._size[1] + c1;
|
||
colIndex[_i] = flat % sizes[1];
|
||
rowIndex[_i] = Math.floor(flat / sizes[1]);
|
||
}
|
||
m._values.length = 0;
|
||
m._index.length = 0;
|
||
m._ptr.length = sizes[1] + 1;
|
||
m._size = sizes.slice();
|
||
for (var _i2 = 0; _i2 < m._ptr.length; _i2++) {
|
||
m._ptr[_i2] = 0;
|
||
}
|
||
for (var h = 0; h < values.length; h++) {
|
||
var _i3 = rowIndex[h];
|
||
var _j = colIndex[h];
|
||
var v = values[h];
|
||
var k = _getValueIndex(_i3, m._ptr[_j], m._ptr[_j + 1], m._index);
|
||
_insert(k, _i3, _j, v, m._values, m._index, m._ptr);
|
||
}
|
||
return m;
|
||
};
|
||
SparseMatrix2.prototype.clone = function() {
|
||
var m = new SparseMatrix2({
|
||
values: this._values ? clone$2(this._values) : void 0,
|
||
index: clone$2(this._index),
|
||
ptr: clone$2(this._ptr),
|
||
size: clone$2(this._size),
|
||
datatype: this._datatype
|
||
});
|
||
return m;
|
||
};
|
||
SparseMatrix2.prototype.size = function() {
|
||
return this._size.slice(0);
|
||
};
|
||
SparseMatrix2.prototype.map = function(callback, skipZeros) {
|
||
if (!this._values) {
|
||
throw new Error("Cannot invoke map on a Pattern only matrix");
|
||
}
|
||
var me = this;
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var fastCallback = optimizeCallback(callback, me, "map");
|
||
var invoke = function invoke2(v, i, j) {
|
||
return fastCallback(v, [i, j], me);
|
||
};
|
||
return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
|
||
};
|
||
function _map(matrix2, minRow, maxRow, minColumn, maxColumn, callback, skipZeros) {
|
||
var values = [];
|
||
var index2 = [];
|
||
var ptr = [];
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
if (isString(matrix2._datatype)) {
|
||
eq = typed2.find(equalScalar2, [matrix2._datatype, matrix2._datatype]) || equalScalar2;
|
||
zero = typed2.convert(0, matrix2._datatype);
|
||
}
|
||
var invoke = function invoke2(v, x, y) {
|
||
var value2 = callback(v, x, y);
|
||
if (!eq(value2, zero)) {
|
||
values.push(value2);
|
||
index2.push(x);
|
||
}
|
||
};
|
||
for (var j = minColumn; j <= maxColumn; j++) {
|
||
ptr.push(values.length);
|
||
var k0 = matrix2._ptr[j];
|
||
var k1 = matrix2._ptr[j + 1];
|
||
if (skipZeros) {
|
||
for (var k = k0; k < k1; k++) {
|
||
var i = matrix2._index[k];
|
||
if (i >= minRow && i <= maxRow) {
|
||
invoke(matrix2._values[k], i - minRow, j - minColumn);
|
||
}
|
||
}
|
||
} else {
|
||
var _values = {};
|
||
for (var _k = k0; _k < k1; _k++) {
|
||
var _i4 = matrix2._index[_k];
|
||
_values[_i4] = matrix2._values[_k];
|
||
}
|
||
for (var _i5 = minRow; _i5 <= maxRow; _i5++) {
|
||
var value = _i5 in _values ? _values[_i5] : 0;
|
||
invoke(value, _i5 - minRow, j - minColumn);
|
||
}
|
||
}
|
||
}
|
||
ptr.push(values.length);
|
||
return new SparseMatrix2({
|
||
values,
|
||
index: index2,
|
||
ptr,
|
||
size: [maxRow - minRow + 1, maxColumn - minColumn + 1]
|
||
});
|
||
}
|
||
SparseMatrix2.prototype.forEach = function(callback, skipZeros) {
|
||
if (!this._values) {
|
||
throw new Error("Cannot invoke forEach on a Pattern only matrix");
|
||
}
|
||
var me = this;
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var fastCallback = optimizeCallback(callback, me, "forEach");
|
||
for (var j = 0; j < columns; j++) {
|
||
var k0 = this._ptr[j];
|
||
var k1 = this._ptr[j + 1];
|
||
if (skipZeros) {
|
||
for (var k = k0; k < k1; k++) {
|
||
var i = this._index[k];
|
||
fastCallback(this._values[k], [i, j], me);
|
||
}
|
||
} else {
|
||
var values = {};
|
||
for (var _k2 = k0; _k2 < k1; _k2++) {
|
||
var _i6 = this._index[_k2];
|
||
values[_i6] = this._values[_k2];
|
||
}
|
||
for (var _i7 = 0; _i7 < rows; _i7++) {
|
||
var value = _i7 in values ? values[_i7] : 0;
|
||
fastCallback(value, [_i7, j], me);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
SparseMatrix2.prototype[Symbol.iterator] = function* () {
|
||
if (!this._values) {
|
||
throw new Error("Cannot iterate a Pattern only matrix");
|
||
}
|
||
var columns = this._size[1];
|
||
for (var j = 0; j < columns; j++) {
|
||
var k0 = this._ptr[j];
|
||
var k1 = this._ptr[j + 1];
|
||
for (var k = k0; k < k1; k++) {
|
||
var i = this._index[k];
|
||
yield {
|
||
value: this._values[k],
|
||
index: [i, j]
|
||
};
|
||
}
|
||
}
|
||
};
|
||
SparseMatrix2.prototype.toArray = function() {
|
||
return _toArray(this._values, this._index, this._ptr, this._size, true);
|
||
};
|
||
SparseMatrix2.prototype.valueOf = function() {
|
||
return _toArray(this._values, this._index, this._ptr, this._size, false);
|
||
};
|
||
function _toArray(values, index2, ptr, size2, copy) {
|
||
var rows = size2[0];
|
||
var columns = size2[1];
|
||
var a = [];
|
||
var i, j;
|
||
for (i = 0; i < rows; i++) {
|
||
a[i] = [];
|
||
for (j = 0; j < columns; j++) {
|
||
a[i][j] = 0;
|
||
}
|
||
}
|
||
for (j = 0; j < columns; j++) {
|
||
var k0 = ptr[j];
|
||
var k1 = ptr[j + 1];
|
||
for (var k = k0; k < k1; k++) {
|
||
i = index2[k];
|
||
a[i][j] = values ? copy ? clone$2(values[k]) : values[k] : 1;
|
||
}
|
||
}
|
||
return a;
|
||
}
|
||
SparseMatrix2.prototype.format = function(options) {
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var density = this.density();
|
||
var str = "Sparse Matrix [" + format(rows, options) + " x " + format(columns, options) + "] density: " + format(density, options) + "\n";
|
||
for (var j = 0; j < columns; j++) {
|
||
var k0 = this._ptr[j];
|
||
var k1 = this._ptr[j + 1];
|
||
for (var k = k0; k < k1; k++) {
|
||
var i = this._index[k];
|
||
str += "\n (" + format(i, options) + ", " + format(j, options) + ") ==> " + (this._values ? format(this._values[k], options) : "X");
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
SparseMatrix2.prototype.toString = function() {
|
||
return format(this.toArray());
|
||
};
|
||
SparseMatrix2.prototype.toJSON = function() {
|
||
return {
|
||
mathjs: "SparseMatrix",
|
||
values: this._values,
|
||
index: this._index,
|
||
ptr: this._ptr,
|
||
size: this._size,
|
||
datatype: this._datatype
|
||
};
|
||
};
|
||
SparseMatrix2.prototype.diagonal = function(k) {
|
||
if (k) {
|
||
if (isBigNumber(k)) {
|
||
k = k.toNumber();
|
||
}
|
||
if (!isNumber(k) || !isInteger(k)) {
|
||
throw new TypeError("The parameter k must be an integer number");
|
||
}
|
||
} else {
|
||
k = 0;
|
||
}
|
||
var kSuper = k > 0 ? k : 0;
|
||
var kSub = k < 0 ? -k : 0;
|
||
var rows = this._size[0];
|
||
var columns = this._size[1];
|
||
var n2 = Math.min(rows - kSub, columns - kSuper);
|
||
var values = [];
|
||
var index2 = [];
|
||
var ptr = [];
|
||
ptr[0] = 0;
|
||
for (var j = kSuper; j < columns && values.length < n2; j++) {
|
||
var k0 = this._ptr[j];
|
||
var k1 = this._ptr[j + 1];
|
||
for (var x = k0; x < k1; x++) {
|
||
var i = this._index[x];
|
||
if (i === j - kSuper + kSub) {
|
||
values.push(this._values[x]);
|
||
index2[values.length - 1] = i - kSub;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
ptr.push(values.length);
|
||
return new SparseMatrix2({
|
||
values,
|
||
index: index2,
|
||
ptr,
|
||
size: [n2, 1]
|
||
});
|
||
};
|
||
SparseMatrix2.fromJSON = function(json) {
|
||
return new SparseMatrix2(json);
|
||
};
|
||
SparseMatrix2.diagonal = function(size2, value, k, defaultValue, datatype) {
|
||
if (!isArray(size2)) {
|
||
throw new TypeError("Array expected, size parameter");
|
||
}
|
||
if (size2.length !== 2) {
|
||
throw new Error("Only two dimensions matrix are supported");
|
||
}
|
||
size2 = size2.map(function(s2) {
|
||
if (isBigNumber(s2)) {
|
||
s2 = s2.toNumber();
|
||
}
|
||
if (!isNumber(s2) || !isInteger(s2) || s2 < 1) {
|
||
throw new Error("Size values must be positive integers");
|
||
}
|
||
return s2;
|
||
});
|
||
if (k) {
|
||
if (isBigNumber(k)) {
|
||
k = k.toNumber();
|
||
}
|
||
if (!isNumber(k) || !isInteger(k)) {
|
||
throw new TypeError("The parameter k must be an integer number");
|
||
}
|
||
} else {
|
||
k = 0;
|
||
}
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
if (isString(datatype)) {
|
||
eq = typed2.find(equalScalar2, [datatype, datatype]) || equalScalar2;
|
||
zero = typed2.convert(0, datatype);
|
||
}
|
||
var kSuper = k > 0 ? k : 0;
|
||
var kSub = k < 0 ? -k : 0;
|
||
var rows = size2[0];
|
||
var columns = size2[1];
|
||
var n2 = Math.min(rows - kSub, columns - kSuper);
|
||
var _value;
|
||
if (isArray(value)) {
|
||
if (value.length !== n2) {
|
||
throw new Error("Invalid value array length");
|
||
}
|
||
_value = function _value2(i2) {
|
||
return value[i2];
|
||
};
|
||
} else if (isMatrix(value)) {
|
||
var ms = value.size();
|
||
if (ms.length !== 1 || ms[0] !== n2) {
|
||
throw new Error("Invalid matrix length");
|
||
}
|
||
_value = function _value2(i2) {
|
||
return value.get([i2]);
|
||
};
|
||
} else {
|
||
_value = function _value2() {
|
||
return value;
|
||
};
|
||
}
|
||
var values = [];
|
||
var index2 = [];
|
||
var ptr = [];
|
||
for (var j = 0; j < columns; j++) {
|
||
ptr.push(values.length);
|
||
var i = j - kSuper;
|
||
if (i >= 0 && i < n2) {
|
||
var v = _value(i);
|
||
if (!eq(v, zero)) {
|
||
index2.push(i + kSub);
|
||
values.push(v);
|
||
}
|
||
}
|
||
}
|
||
ptr.push(values.length);
|
||
return new SparseMatrix2({
|
||
values,
|
||
index: index2,
|
||
ptr,
|
||
size: [rows, columns]
|
||
});
|
||
};
|
||
SparseMatrix2.prototype.swapRows = function(i, j) {
|
||
if (!isNumber(i) || !isInteger(i) || !isNumber(j) || !isInteger(j)) {
|
||
throw new Error("Row index must be positive integers");
|
||
}
|
||
if (this._size.length !== 2) {
|
||
throw new Error("Only two dimensional matrix is supported");
|
||
}
|
||
validateIndex(i, this._size[0]);
|
||
validateIndex(j, this._size[0]);
|
||
SparseMatrix2._swapRows(i, j, this._size[1], this._values, this._index, this._ptr);
|
||
return this;
|
||
};
|
||
SparseMatrix2._forEachRow = function(j, values, index2, ptr, callback) {
|
||
var k0 = ptr[j];
|
||
var k1 = ptr[j + 1];
|
||
for (var k = k0; k < k1; k++) {
|
||
callback(index2[k], values[k]);
|
||
}
|
||
};
|
||
SparseMatrix2._swapRows = function(x, y, columns, values, index2, ptr) {
|
||
for (var j = 0; j < columns; j++) {
|
||
var k0 = ptr[j];
|
||
var k1 = ptr[j + 1];
|
||
var kx = _getValueIndex(x, k0, k1, index2);
|
||
var ky = _getValueIndex(y, k0, k1, index2);
|
||
if (kx < k1 && ky < k1 && index2[kx] === x && index2[ky] === y) {
|
||
if (values) {
|
||
var v = values[kx];
|
||
values[kx] = values[ky];
|
||
values[ky] = v;
|
||
}
|
||
continue;
|
||
}
|
||
if (kx < k1 && index2[kx] === x && (ky >= k1 || index2[ky] !== y)) {
|
||
var vx = values ? values[kx] : void 0;
|
||
index2.splice(ky, 0, y);
|
||
if (values) {
|
||
values.splice(ky, 0, vx);
|
||
}
|
||
index2.splice(ky <= kx ? kx + 1 : kx, 1);
|
||
if (values) {
|
||
values.splice(ky <= kx ? kx + 1 : kx, 1);
|
||
}
|
||
continue;
|
||
}
|
||
if (ky < k1 && index2[ky] === y && (kx >= k1 || index2[kx] !== x)) {
|
||
var vy = values ? values[ky] : void 0;
|
||
index2.splice(kx, 0, x);
|
||
if (values) {
|
||
values.splice(kx, 0, vy);
|
||
}
|
||
index2.splice(kx <= ky ? ky + 1 : ky, 1);
|
||
if (values) {
|
||
values.splice(kx <= ky ? ky + 1 : ky, 1);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
return SparseMatrix2;
|
||
}, {
|
||
isClass: true
|
||
});
|
||
var name$5 = "matrix";
|
||
var dependencies$5 = ["typed", "Matrix", "DenseMatrix", "SparseMatrix"];
|
||
var createMatrix = /* @__PURE__ */ factory(name$5, dependencies$5, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
Matrix: Matrix2,
|
||
DenseMatrix: DenseMatrix2,
|
||
SparseMatrix: SparseMatrix2
|
||
} = _ref;
|
||
return typed2(name$5, {
|
||
"": function _() {
|
||
return _create([]);
|
||
},
|
||
string: function string(format2) {
|
||
return _create([], format2);
|
||
},
|
||
"string, string": function string_string(format2, datatype) {
|
||
return _create([], format2, datatype);
|
||
},
|
||
Array: function Array2(data) {
|
||
return _create(data);
|
||
},
|
||
Matrix: function Matrix3(data) {
|
||
return _create(data, data.storage());
|
||
},
|
||
"Array | Matrix, string": _create,
|
||
"Array | Matrix, string, string": _create
|
||
});
|
||
function _create(data, format2, datatype) {
|
||
if (format2 === "dense" || format2 === "default" || format2 === void 0) {
|
||
return new DenseMatrix2(data, datatype);
|
||
}
|
||
if (format2 === "sparse") {
|
||
return new SparseMatrix2(data, datatype);
|
||
}
|
||
throw new TypeError("Unknown matrix type " + JSON.stringify(format2) + ".");
|
||
}
|
||
});
|
||
var name$4 = "matAlgo11xS0s";
|
||
var dependencies$4 = ["typed", "equalScalar"];
|
||
var createMatAlgo11xS0s = /* @__PURE__ */ factory(name$4, dependencies$4, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
equalScalar: equalScalar2
|
||
} = _ref;
|
||
return function matAlgo11xS0s(s2, b, callback, inverse) {
|
||
var avalues = s2._values;
|
||
var aindex = s2._index;
|
||
var aptr = s2._ptr;
|
||
var asize = s2._size;
|
||
var adt = s2._datatype;
|
||
if (!avalues) {
|
||
throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");
|
||
}
|
||
var rows = asize[0];
|
||
var columns = asize[1];
|
||
var dt;
|
||
var eq = equalScalar2;
|
||
var zero = 0;
|
||
var cf = callback;
|
||
if (typeof adt === "string") {
|
||
dt = adt;
|
||
eq = typed2.find(equalScalar2, [dt, dt]);
|
||
zero = typed2.convert(0, dt);
|
||
b = typed2.convert(b, dt);
|
||
cf = typed2.find(callback, [dt, dt]);
|
||
}
|
||
var cvalues = [];
|
||
var cindex = [];
|
||
var cptr = [];
|
||
for (var j = 0; j < columns; j++) {
|
||
cptr[j] = cindex.length;
|
||
for (var k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
||
var i = aindex[k];
|
||
var v = inverse ? cf(b, avalues[k]) : cf(avalues[k], b);
|
||
if (!eq(v, zero)) {
|
||
cindex.push(i);
|
||
cvalues.push(v);
|
||
}
|
||
}
|
||
}
|
||
cptr[columns] = cindex.length;
|
||
return s2.createSparseMatrix({
|
||
values: cvalues,
|
||
index: cindex,
|
||
ptr: cptr,
|
||
size: [rows, columns],
|
||
datatype: dt
|
||
});
|
||
};
|
||
});
|
||
var name$3 = "matAlgo12xSfs";
|
||
var dependencies$3 = ["typed", "DenseMatrix"];
|
||
var createMatAlgo12xSfs = /* @__PURE__ */ factory(name$3, dependencies$3, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
DenseMatrix: DenseMatrix2
|
||
} = _ref;
|
||
return function matAlgo12xSfs(s2, b, callback, inverse) {
|
||
var avalues = s2._values;
|
||
var aindex = s2._index;
|
||
var aptr = s2._ptr;
|
||
var asize = s2._size;
|
||
var adt = s2._datatype;
|
||
if (!avalues) {
|
||
throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");
|
||
}
|
||
var rows = asize[0];
|
||
var columns = asize[1];
|
||
var dt;
|
||
var cf = callback;
|
||
if (typeof adt === "string") {
|
||
dt = adt;
|
||
b = typed2.convert(b, dt);
|
||
cf = typed2.find(callback, [dt, dt]);
|
||
}
|
||
var cdata = [];
|
||
var x = [];
|
||
var w = [];
|
||
for (var j = 0; j < columns; j++) {
|
||
var mark = j + 1;
|
||
for (var k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
||
var r = aindex[k];
|
||
x[r] = avalues[k];
|
||
w[r] = mark;
|
||
}
|
||
for (var i = 0; i < rows; i++) {
|
||
if (j === 0) {
|
||
cdata[i] = [];
|
||
}
|
||
if (w[i] === mark) {
|
||
cdata[i][j] = inverse ? cf(b, x[i]) : cf(x[i], b);
|
||
} else {
|
||
cdata[i][j] = inverse ? cf(b, 0) : cf(0, b);
|
||
}
|
||
}
|
||
}
|
||
return new DenseMatrix2({
|
||
data: cdata,
|
||
size: [rows, columns],
|
||
datatype: dt
|
||
});
|
||
};
|
||
});
|
||
var name$2 = "matAlgo14xDs";
|
||
var dependencies$2 = ["typed"];
|
||
var createMatAlgo14xDs = /* @__PURE__ */ factory(name$2, dependencies$2, (_ref) => {
|
||
var {
|
||
typed: typed2
|
||
} = _ref;
|
||
return function matAlgo14xDs(a, b, callback, inverse) {
|
||
var adata = a._data;
|
||
var asize = a._size;
|
||
var adt = a._datatype;
|
||
var dt;
|
||
var cf = callback;
|
||
if (typeof adt === "string") {
|
||
dt = adt;
|
||
b = typed2.convert(b, dt);
|
||
cf = typed2.find(callback, [dt, dt]);
|
||
}
|
||
var cdata = asize.length > 0 ? _iterate(cf, 0, asize, asize[0], adata, b, inverse) : [];
|
||
return a.createDenseMatrix({
|
||
data: cdata,
|
||
size: clone$2(asize),
|
||
datatype: dt
|
||
});
|
||
};
|
||
function _iterate(f2, level, s2, n2, av, bv, inverse) {
|
||
var cv = [];
|
||
if (level === s2.length - 1) {
|
||
for (var i = 0; i < n2; i++) {
|
||
cv[i] = inverse ? f2(bv, av[i]) : f2(av[i], bv);
|
||
}
|
||
} else {
|
||
for (var j = 0; j < n2; j++) {
|
||
cv[j] = _iterate(f2, level + 1, s2, s2[level + 1], av[j], bv, inverse);
|
||
}
|
||
}
|
||
return cv;
|
||
}
|
||
});
|
||
var name$1 = "zeros";
|
||
var dependencies$1 = ["typed", "config", "matrix", "BigNumber"];
|
||
var createZeros = /* @__PURE__ */ factory(name$1, dependencies$1, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
config: config3,
|
||
matrix: matrix2,
|
||
BigNumber: BigNumber2
|
||
} = _ref;
|
||
return typed2(name$1, {
|
||
"": function _() {
|
||
return config3.matrix === "Array" ? _zeros([]) : _zeros([], "default");
|
||
},
|
||
// math.zeros(m, n, p, ..., format)
|
||
// TODO: more accurate signature '...number | BigNumber, string' as soon as typed-function supports this
|
||
"...number | BigNumber | string": function number__BigNumber__string(size2) {
|
||
var last = size2[size2.length - 1];
|
||
if (typeof last === "string") {
|
||
var format2 = size2.pop();
|
||
return _zeros(size2, format2);
|
||
} else if (config3.matrix === "Array") {
|
||
return _zeros(size2);
|
||
} else {
|
||
return _zeros(size2, "default");
|
||
}
|
||
},
|
||
Array: _zeros,
|
||
Matrix: function Matrix2(size2) {
|
||
var format2 = size2.storage();
|
||
return _zeros(size2.valueOf(), format2);
|
||
},
|
||
"Array | Matrix, string": function Array__Matrix_string(size2, format2) {
|
||
return _zeros(size2.valueOf(), format2);
|
||
}
|
||
});
|
||
function _zeros(size2, format2) {
|
||
var hasBigNumbers = _normalize(size2);
|
||
var defaultValue = hasBigNumbers ? new BigNumber2(0) : 0;
|
||
_validate2(size2);
|
||
if (format2) {
|
||
var m = matrix2(format2);
|
||
if (size2.length > 0) {
|
||
return m.resize(size2, defaultValue);
|
||
}
|
||
return m;
|
||
} else {
|
||
var arr = [];
|
||
if (size2.length > 0) {
|
||
return resize(arr, size2, defaultValue);
|
||
}
|
||
return arr;
|
||
}
|
||
}
|
||
function _normalize(size2) {
|
||
var hasBigNumbers = false;
|
||
size2.forEach(function(value, index2, arr) {
|
||
if (isBigNumber(value)) {
|
||
hasBigNumbers = true;
|
||
arr[index2] = value.toNumber();
|
||
}
|
||
});
|
||
return hasBigNumbers;
|
||
}
|
||
function _validate2(size2) {
|
||
size2.forEach(function(value) {
|
||
if (typeof value !== "number" || !isInteger(value) || value < 0) {
|
||
throw new Error("Parameters in function zeros must be positive integers");
|
||
}
|
||
});
|
||
}
|
||
});
|
||
var NO_INT = "Number of decimals in function round must be an integer";
|
||
var name = "round";
|
||
var dependencies = ["typed", "config", "matrix", "equalScalar", "zeros", "BigNumber", "DenseMatrix"];
|
||
var createRound = /* @__PURE__ */ factory(name, dependencies, (_ref) => {
|
||
var {
|
||
typed: typed2,
|
||
config: config3,
|
||
matrix: matrix2,
|
||
equalScalar: equalScalar2,
|
||
zeros: zeros2,
|
||
BigNumber: _BigNumber,
|
||
DenseMatrix: DenseMatrix2
|
||
} = _ref;
|
||
var matAlgo11xS0s = createMatAlgo11xS0s({
|
||
typed: typed2,
|
||
equalScalar: equalScalar2
|
||
});
|
||
var matAlgo12xSfs = createMatAlgo12xSfs({
|
||
typed: typed2,
|
||
DenseMatrix: DenseMatrix2
|
||
});
|
||
var matAlgo14xDs = createMatAlgo14xDs({
|
||
typed: typed2
|
||
});
|
||
function toExponent(epsilon) {
|
||
return Math.abs(splitNumber(epsilon).exponent);
|
||
}
|
||
return typed2(name, {
|
||
number: function number(x) {
|
||
var xEpsilon = roundNumber(x, toExponent(config3.relTol));
|
||
var xSelected = nearlyEqual$1(x, xEpsilon, config3.relTol, config3.absTol) ? xEpsilon : x;
|
||
return roundNumber(xSelected);
|
||
},
|
||
"number, number": function number_number(x, n2) {
|
||
var epsilonExponent = toExponent(config3.relTol);
|
||
if (n2 >= epsilonExponent) {
|
||
return roundNumber(x, n2);
|
||
}
|
||
var xEpsilon = roundNumber(x, epsilonExponent);
|
||
var xSelected = nearlyEqual$1(x, xEpsilon, config3.relTol, config3.absTol) ? xEpsilon : x;
|
||
return roundNumber(xSelected, n2);
|
||
},
|
||
"number, BigNumber": function number_BigNumber(x, n2) {
|
||
if (!n2.isInteger()) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
return new _BigNumber(x).toDecimalPlaces(n2.toNumber());
|
||
},
|
||
Complex: function Complex2(x) {
|
||
return x.round();
|
||
},
|
||
"Complex, number": function Complex_number(x, n2) {
|
||
if (n2 % 1) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
return x.round(n2);
|
||
},
|
||
"Complex, BigNumber": function Complex_BigNumber(x, n2) {
|
||
if (!n2.isInteger()) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
var _n = n2.toNumber();
|
||
return x.round(_n);
|
||
},
|
||
BigNumber: function BigNumber2(x) {
|
||
var xEpsilon = new _BigNumber(x).toDecimalPlaces(toExponent(config3.relTol));
|
||
var xSelected = nearlyEqual(x, xEpsilon, config3.relTol, config3.absTol) ? xEpsilon : x;
|
||
return xSelected.toDecimalPlaces(0);
|
||
},
|
||
"BigNumber, BigNumber": function BigNumber_BigNumber(x, n2) {
|
||
if (!n2.isInteger()) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
var epsilonExponent = toExponent(config3.relTol);
|
||
if (n2 >= epsilonExponent) {
|
||
return x.toDecimalPlaces(n2.toNumber());
|
||
}
|
||
var xEpsilon = x.toDecimalPlaces(epsilonExponent);
|
||
var xSelected = nearlyEqual(x, xEpsilon, config3.relTol, config3.absTol) ? xEpsilon : x;
|
||
return xSelected.toDecimalPlaces(n2.toNumber());
|
||
},
|
||
Fraction: function Fraction2(x) {
|
||
return x.round();
|
||
},
|
||
"Fraction, number": function Fraction_number(x, n2) {
|
||
if (n2 % 1) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
return x.round(n2);
|
||
},
|
||
"Fraction, BigNumber": function Fraction_BigNumber(x, n2) {
|
||
if (!n2.isInteger()) {
|
||
throw new TypeError(NO_INT);
|
||
}
|
||
return x.round(n2.toNumber());
|
||
},
|
||
"Unit, number, Unit": typed2.referToSelf((self2) => function(x, n2, unit) {
|
||
var valueless = x.toNumeric(unit);
|
||
return unit.multiply(self2(valueless, n2));
|
||
}),
|
||
"Unit, BigNumber, Unit": typed2.referToSelf((self2) => (x, n2, unit) => self2(x, n2.toNumber(), unit)),
|
||
"Array | Matrix, number | BigNumber, Unit": typed2.referToSelf((self2) => (x, n2, unit) => {
|
||
return deepMap(x, (value) => self2(value, n2, unit));
|
||
}),
|
||
"Array | Matrix | Unit, Unit": typed2.referToSelf((self2) => (x, unit) => self2(x, 0, unit)),
|
||
"Array | Matrix": typed2.referToSelf((self2) => (x) => {
|
||
return deepMap(x, self2);
|
||
}),
|
||
"SparseMatrix, number | BigNumber": typed2.referToSelf((self2) => (x, n2) => {
|
||
return matAlgo11xS0s(x, n2, self2, false);
|
||
}),
|
||
"DenseMatrix, number | BigNumber": typed2.referToSelf((self2) => (x, n2) => {
|
||
return matAlgo14xDs(x, n2, self2, false);
|
||
}),
|
||
"Array, number | BigNumber": typed2.referToSelf((self2) => (x, n2) => {
|
||
return matAlgo14xDs(matrix2(x), n2, self2, false).valueOf();
|
||
}),
|
||
"number | Complex | BigNumber | Fraction, SparseMatrix": typed2.referToSelf((self2) => (x, n2) => {
|
||
if (equalScalar2(x, 0)) {
|
||
return zeros2(n2.size(), n2.storage());
|
||
}
|
||
return matAlgo12xSfs(n2, x, self2, true);
|
||
}),
|
||
"number | Complex | BigNumber | Fraction, DenseMatrix": typed2.referToSelf((self2) => (x, n2) => {
|
||
if (equalScalar2(x, 0)) {
|
||
return zeros2(n2.size(), n2.storage());
|
||
}
|
||
return matAlgo14xDs(n2, x, self2, true);
|
||
}),
|
||
"number | Complex | BigNumber | Fraction, Array": typed2.referToSelf((self2) => (x, n2) => {
|
||
return matAlgo14xDs(matrix2(n2), x, self2, true).valueOf();
|
||
})
|
||
});
|
||
});
|
||
var BigNumber = /* @__PURE__ */ createBigNumberClass({
|
||
config: config$1
|
||
});
|
||
var Complex = /* @__PURE__ */ createComplexClass({});
|
||
var Fraction = /* @__PURE__ */ createFractionClass({});
|
||
var Matrix = /* @__PURE__ */ createMatrixClass({});
|
||
var DenseMatrix = /* @__PURE__ */ createDenseMatrixClass({
|
||
Matrix
|
||
});
|
||
var typed = /* @__PURE__ */ createTyped({
|
||
BigNumber,
|
||
Complex,
|
||
DenseMatrix,
|
||
Fraction
|
||
});
|
||
var equalScalar = /* @__PURE__ */ createEqualScalar({
|
||
config: config$1,
|
||
typed
|
||
});
|
||
var SparseMatrix = /* @__PURE__ */ createSparseMatrixClass({
|
||
Matrix,
|
||
equalScalar,
|
||
typed
|
||
});
|
||
var matrix = /* @__PURE__ */ createMatrix({
|
||
DenseMatrix,
|
||
Matrix,
|
||
SparseMatrix,
|
||
typed
|
||
});
|
||
var zeros = /* @__PURE__ */ createZeros({
|
||
BigNumber,
|
||
config: config$1,
|
||
matrix,
|
||
typed
|
||
});
|
||
var round = /* @__PURE__ */ createRound({
|
||
BigNumber,
|
||
DenseMatrix,
|
||
config: config$1,
|
||
equalScalar,
|
||
matrix,
|
||
typed,
|
||
zeros
|
||
});
|
||
function mitt(n2) {
|
||
return { all: n2 = n2 || /* @__PURE__ */ new Map(), on: function(t2, e2) {
|
||
var i = n2.get(t2);
|
||
i ? i.push(e2) : n2.set(t2, [e2]);
|
||
}, off: function(t2, e2) {
|
||
var i = n2.get(t2);
|
||
i && (e2 ? i.splice(i.indexOf(e2) >>> 0, 1) : n2.set(t2, []));
|
||
}, emit: function(t2, e2) {
|
||
var i = n2.get(t2);
|
||
i && i.slice().map(function(n3) {
|
||
n3(e2);
|
||
}), (i = n2.get("*")) && i.slice().map(function(n3) {
|
||
n3(t2, e2);
|
||
});
|
||
} };
|
||
}
|
||
exports._export_sfc = _export_sfc;
|
||
exports.createPinia = createPinia;
|
||
exports.createSSRApp = createSSRApp;
|
||
exports.defineComponent = defineComponent;
|
||
exports.e = e;
|
||
exports.f = f;
|
||
exports.index = index;
|
||
exports.mitt = mitt;
|
||
exports.n = n;
|
||
exports.o = o;
|
||
exports.onLaunch = onLaunch;
|
||
exports.onLoad = onLoad;
|
||
exports.onMounted = onMounted;
|
||
exports.onPullDownRefresh = onPullDownRefresh;
|
||
exports.onShow = onShow;
|
||
exports.p = p;
|
||
exports.ref = ref;
|
||
exports.resolveComponent = resolveComponent;
|
||
exports.round = round;
|
||
exports.s = s;
|
||
exports.sr = sr;
|
||
exports.t = t;
|
||
exports.toRaw = toRaw;
|
||
exports.unref = unref;
|
||
exports.watch = watch;
|
||
exports.wx$1 = wx$1;
|