UNPKG

@jswork/gm-sdk

Version:

Sdk for tampermonkey based on jQuery/nx.

1,609 lines (1,457 loc) 92.2 kB
/*! * name: @jswork/gm-sdk * description: Sdk for tampermonkey based on jQuery/nx. * homepage: https://github.com/afeiship/gm-sdk * version: 1.1.7 * date: 2025-05-15 14:20:58 * license: MIT */ (function (factory) { typeof define === 'function' && define.amd ? define(factory) : factory(); })((function () { var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function getAugmentedNamespace(n) { if (n.__esModule) return n; var f = n.default; if (typeof f == "function") { var a = function a () { if (this instanceof a) { var args = [null]; args.push.apply(args, arguments); var Ctor = Function.bind.apply(f, args); return new Ctor(); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function () { return n[k]; } }); }); return a; } var dist$a = {exports: {}}; dist$a.exports; (function (module, exports) { (function() { /** Detect free variable `global` from Node.js. */ var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; /** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root = freeGlobal || freeSelf || Function('return this')(); /** Detect free variable `exports`. */ var freeExports = exports && !exports.nodeType && exports; /** Detect free variable `module`. */ var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; //force inject to global: var nx = (root.nx = root.nx || { BREAKER: {}, NIL: {}, VERSION: '1.2.13', DEBUG: false, GLOBAL: root }); // Some AMD build optimizers, like r.js, check for condition patterns like: if (freeModule) { // Export for Node.js. (freeModule.exports = nx).nx = nx; // Export for CommonJS support. freeExports.nx = nx; } else { // Export to the global object. root.nx = nx; } (function () { var DOT = '.'; var NUMBER = 'number'; var UNDEF = 'undefined'; var ARRAY_PROTO = Array.prototype; var toString = Object.prototype.toString; var hasOwn = Object.prototype.hasOwnProperty; var INDEXES_PATH_RE = /\[(\w+)\]/g; var MULTIPLE_DOT_RE = /[.]+/g; var EDGE_DOT_RE = /^\.|\.$/g; var POS1 = '.$1'; var EMP = ''; var normalize = function (path) { return path .toString() .replace(INDEXES_PATH_RE, POS1) .replace(MULTIPLE_DOT_RE, DOT) .replace(EDGE_DOT_RE, EMP); }; nx.noop = function () {}; nx.typeof = function (inTarget) { var isPrimitive = inTarget == null || typeof inTarget !== 'object'; if (!isPrimitive) return toString.call(inTarget).slice(8, -1).toLowerCase(); if (inTarget === null) return 'null'; if (inTarget === undefined) return 'undefined'; return typeof inTarget; }; nx.stubTrue = function () { return true; }; nx.stubFalse = function () { return false; }; nx.stubValue = function (inValue) { return inValue; }; nx.stubPromise = function (inValue) { if (typeof inValue === 'undefined') return Promise.resolve(); return Promise.resolve(inValue); }; nx.isBoolean = function (inTarget) { return typeof inTarget === 'boolean'; }; nx.isString = function (inTarget) { return typeof inTarget === 'string'; }; nx.isNumber = function (inTarget) { return typeof inTarget === NUMBER && !isNaN(inTarget); }; nx.isNaN = function (inTarget) { return isNaN(inTarget); }; nx.isFunction = function (inTarget) { return typeof inTarget === 'function'; }; nx.isNil = function (inTarget) { return inTarget == null; }; nx.isArray = function (inTarget) { return Array.isArray(inTarget); }; nx.isObject = function (inTarget) { if (Array.isArray(inTarget)) return false; return typeof inTarget === 'object' && inTarget !== null; }; nx.isThenable = function (inTarget) { if (!inTarget) return false; return typeof inTarget === 'object' && typeof inTarget.then === 'function'; }; nx.error = function (inMsg) { throw new Error(inMsg); }; nx.try = function (inFn, inCatch) { var cb = inCatch || nx.noop; try { inFn(); } catch (err) { cb(err); } }; nx.forEach = function (inArray, inCallback, inContext) { var length = inArray.length; var i; var result; for (i = 0; i < length; i++) { result = inCallback.call(inContext, inArray[i], i, inArray); if (result === nx.BREAKER) { break; } } }; nx.forIn = function (inObject, inCallback, inContext) { var key; var result; for (key in inObject) { if (hasOwn.call(inObject, key)) { result = inCallback.call(inContext, key, inObject[key], inObject); if (result === nx.BREAKER) { break; } } } }; nx.each = function (inTarget, inCallback, inContext) { var key, length; var iterator = function (inKey, inValue, inIsArray) { return ( inCallback.call(inContext, inKey, inValue, inTarget, inIsArray) === nx.BREAKER ); }; if (inTarget) { length = inTarget.length; if (typeof length === NUMBER) { for (key = 0; key < length; key++) { if (iterator(key, inTarget[key], true)) { break; } } } else { for (key in inTarget) { if (hasOwn.call(inTarget, key)) { if (iterator(key, inTarget[key], false)) { break; } } } } } }; nx.map = function (inTarget, inCallback, inContext) { console.warn('@deprecated: nx.map is deprecated, use array.reduce instead'); var result = []; nx.each(inTarget, function () { var item = inCallback.apply(inContext, arguments); if (item !== nx.BREAKER) { result.push(item); } else { return nx.BREAKER; } }); return result; }; nx.mix = function (inTarget) { var target = inTarget || {}; var i, length; var args = arguments; for (i = 1, length = args.length; i < length; i++) { nx.forIn(args[i], function (key, val) { target[key] = val; }); } return target; }; nx.slice = function (inTarget, inStart, inEnd) { return ARRAY_PROTO.slice.call(inTarget, inStart, inEnd); }; nx.set = function (inTarget, inPath, inValue) { var indexesPath = normalize(inPath); var paths = indexesPath.split(DOT); var result = inTarget || nx.GLOBAL; var len_ = paths.length - 1; var last = paths[len_]; for (var i = 0; i < len_; i++) { var path = paths[i]; var target = isNaN(+paths[i + 1]) ? {} : []; result = result[path] = result[path] || target; } result[last] = inValue; return inTarget; }; nx.get = function (inTarget, inPath, inValue) { if (!inPath) return inTarget; if (Array.isArray(inPath)) return inPath.map(function (path) { return nx.get(inTarget, path, inValue); }); var idx = normalize(inPath); var paths = idx.split(DOT); var result = inTarget || nx.GLOBAL; paths.forEach(function (path) { result = result && result[path]; }); return typeof inValue !== UNDEF && typeof result === UNDEF ? inValue : result; }; nx.del = function (inTarget, inPath) { var indexesPath = normalize(inPath); var paths = indexesPath.split(DOT); for (var i = 0; i < paths.length; i++) { var path = paths[i]; if (i === paths.length - 1) { if (inTarget == null) return false; if (typeof inTarget === 'object') delete inTarget[path]; return true; } inTarget = inTarget[path]; } return false; }; // @url: https://github.com/scopsy/await-to-js nx.to = function (inPromise) { return inPromise .then(function (data) { return [undefined, data]; }) .catch(function (err) { return [err, undefined]; }); }; })(); (function() { var RootClass = function() {}; var classMeta = { __class_id__: 0, __type__: 'nx.RootClass', __base__: Object, __meta__: {}, __static__: false, __statics__: {}, __properties__: {}, __methods__: {}, __method_init__: nx.noop, __static_init__: nx.noop }; var baseMethods = { base: function() { var caller = this.base.caller; var baseMethod; if (caller && (baseMethod = caller.__base__)) { return baseMethod.apply(this, arguments); } }, parent: function(inName) { var isStatic = typeof this.__id__ === 'undefined'; var args = nx.slice(arguments, 1); var base = isStatic ? this.__base__ : this.__base__.prototype; var type = this['@' + inName].__type__; var accessor = ['get', 'set'][args.length]; switch (type) { case 'method': return base[inName].apply(this, args); case 'property': return base['@' + inName][accessor].apply(this, args); } } }; classMeta.__methods__ = RootClass.prototype = nx.mix( { constructor: RootClass, init: nx.noop, destroy: nx.noop, toString: function() { return '[Class@' + this.__type__ + ']'; } }, baseMethods ); //mix && export: nx.mix(classMeta.__statics__, baseMethods); nx.mix(RootClass, classMeta); nx.mix(RootClass, classMeta.__statics__); nx.RootClass = RootClass; })(); (function() { var MEMBER_PREFIX = '@'; var VALUE = 'value'; var COMMA = ','; nx.defineProperty = function(inTarget, inName, inMeta, inIsStatic) { var key = MEMBER_PREFIX + inName; var getter, setter, descriptor; var value, filed; var typeOfObject = typeof inMeta === 'object'; var meta = inMeta && typeOfObject ? inMeta : { value: inMeta }; if (VALUE in meta) { value = meta.value; filed = '_' + inName; getter = function() { return filed in this ? this[filed] : nx.isFunction(value) ? value.call(this) : value; }; setter = function(inValue) { this[filed] = inValue; }; } else { getter = inMeta.get || (inTarget[key] && inTarget[key].get) || nx.noop; setter = inMeta.set || (inTarget[key] && inTarget[key].set) || nx.noop; } //remain base setter/getter: if (key in inTarget) { getter.__base__ = inTarget[key].get; setter.__base__ = inTarget[key].set; } descriptor = inTarget[key] = { __meta__: inMeta, __name__: inName, __type__: 'property', __static__: !!inIsStatic, get: getter, set: setter, configurable: true }; Object.defineProperty(inTarget, inName, descriptor); return descriptor; }; nx.defineMethod = function(inTarget, inName, inMeta, inIsStatic) { var key = MEMBER_PREFIX + inName; inTarget[inName] = inMeta; return (inTarget[key] = { __meta__: inMeta, __name__: inName, __type__: 'method', __static__: !!inIsStatic }); }; nx.defineBombMethod = function(inTarget, inName, inMeta, inIsStatic) { var keys = inName.split(COMMA); keys.forEach(function(key, index) { nx.defineMethod( inTarget, key, inMeta.call(inTarget, key, index), inIsStatic ); }); }; nx.defineMembers = function(inMember, inTarget, inObject, inIsStatic) { nx.forIn(inObject, function(key, val) { if (key.indexOf(COMMA) > -1) { nx.defineBombMethod(inTarget, key, val, inIsStatic); } else { nx['define' + inMember](inTarget, key, val, inIsStatic); } }); }; })(); (function () { var classId = 1, instanceId = 0; var NX_ANONYMOUS = 'nx.Anonymous'; function LifeCycle(inType, inMeta) { this.type = inType; this.meta = inMeta; this.base = inMeta.extends || nx.RootClass; this.$base = this.base.prototype; this.__class_meta__ = {}; this.__class__ = null; this.__constructor__ = null; } LifeCycle.prototype = { constructor: LifeCycle, initMetaProcessor: function () { var meta = this.meta; var methods = meta.methods || {}; var statics = meta.statics || {}; nx.mix(this.__class_meta__, { __type__: this.type, __meta__: meta, __base__: this.base, __class_id__: classId++, __method_init__: methods.init || this.base.__method_init__, __static_init__: statics.init || this.base.__static_init__, __static__: !meta.methods && !!meta.statics }); }, createClassProcessor: function () { var self = this; this.__class__ = function () { this.__id__ = instanceId++; self.__constructor__.apply(this, arguments); self.registerDebug(this); }; }, inheritProcessor: function () { var classMeta = this.__class_meta__; this.inheritedClass(classMeta); this.defineMethods(classMeta, true); this.defineMethods(classMeta, false); this.defineProperties(classMeta); }, inheritedClass: function (inClassMeta) { var SuperClass = function () {}; var Class = this.__class__; SuperClass.prototype = this.$base; Class.prototype = new SuperClass(); Class.prototype.$base = this.$base; Class.prototype.constructor = Class; }, defineMethods: function (inClassMeta, inIsStatic) { var key = inIsStatic ? 'statics' : 'methods'; var key_ = '__' + key + '__'; var target = inIsStatic ? this.__class__ : this.__class__.prototype; var baseTarget = inIsStatic ? this.base : this.base.prototype; var methods = baseTarget[key_] || {}; nx.forIn(this.meta[key], function (key, value) { if (methods[key] && typeof value === 'function') { value.__base__ = methods[key]; } }); target[key_] = nx.mix(inClassMeta[key_], methods, this.meta[key]); nx.defineMembers('Method', target, target[key_], inIsStatic); }, defineProperties: function (inClassMeta) { var isStatic = inClassMeta.__static__; var target = isStatic ? this.__class__ : this.__class__.prototype; var baseTarget = isStatic ? this.base : this.base.prototype; target.__properties__ = nx.mix( null, baseTarget.__properties__, inClassMeta.__properties__, this.meta.properties ); nx.defineMembers('Property', target, target.__properties__, isStatic); }, methodsConstructorProcessor: function () { var classMeta = this.__class_meta__; this.__constructor__ = function () { classMeta.__method_init__.apply(this, arguments); }; }, staticsConstructorProcessor: function () { var classMeta = this.__class_meta__; classMeta.__static_init__.call(this.__class__); }, registerProcessor: function () { var Class = this.__class__; var type = this.type; var classMeta = this.__class_meta__; nx.mix(Class.prototype, classMeta); nx.mix(Class, classMeta); if (type.indexOf(NX_ANONYMOUS) === -1) { nx.set(nx.GLOBAL, type, Class); } }, registerDebug: function (inInstance) { if (nx.DEBUG) { nx.set(nx, '__instances__.' + (instanceId - 1), inInstance); nx.set(nx, '__instances__.length', instanceId); } } }; nx.declare = function (inType, inMeta) { var type = typeof inType === 'string' ? inType : NX_ANONYMOUS + classId; var meta = inMeta || inType; var lifeCycle = new LifeCycle(type, meta); lifeCycle.initMetaProcessor(); lifeCycle.createClassProcessor(); lifeCycle.inheritProcessor(); lifeCycle.methodsConstructorProcessor(); lifeCycle.staticsConstructorProcessor(); lifeCycle.registerProcessor(); return lifeCycle.__class__; }; })(); }.call(commonjsGlobal)); } (dist$a, dist$a.exports)); var distExports$2 = dist$a.exports; var nx = /*@__PURE__*/getDefaultExportFromCjs(distExports$2); /*! * name: @jswork/next-gm-api * description: APIs for tampermonkey. * homepage: https://js.work * version: 1.0.4 * date: 2023-03-31 09:57:58 * license: MIT */ const APIS = [ 'GM_addStyle', 'GM_deleteValue', 'GM_listValues', 'GM_addValueChangeListener', 'GM_removeValueChangeListener', 'GM_setValue', 'GM_getValue', 'GM_log', 'GM_getResourceText', 'GM_getResourceURL', 'GM_registerMenuCommand', 'GM_unregisterMenuCommand', 'GM_openInTab', 'GM_xmlhttpRequest', 'GM_download', 'GM_getTab', 'GM_saveTab', 'GM_getTabs', 'GM_notification', 'GM_setClipboard', 'GM_info', 'GM_cookie' ]; const NxGmApi = nx.declare('nx.GmApi', { statics: { version: '4.10.0', generate: function (inContext) { var results = {}; APIS.forEach(function (api) { var shortName = api.split('_')[1]; this[shortName] = results[shortName] = inContext[api]; }, this); return results; } } }); if (typeof module !== 'undefined' && module.exports) { module.exports = NxGmApi; } var dist$9 = {exports: {}}; /*! * name: @jswork/next-json * description: Better json parse/stringify for JSON. * homepage: https://js.work * version: 1.0.6 * date: 2023-06-16 21:23:57 * license: MIT */ nx.json = JSON; nx.parse = function (inValue) { try { return JSON.parse(inValue); } catch (_) {} return inValue; }; nx.stringify = function (inValue) { try { return JSON.stringify(inValue); } catch (_) {} return inValue; }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = { json: nx.json, parse: nx.parse, stringify: nx.stringify }; } ({ json: nx.json, parse: nx.parse, stringify: nx.stringify }); /*! * name: @jswork/next-slice2str * description: Slice string to two part. * homepage: https://js.work * version: 1.0.6 * date: 2023-07-30 20:49:27 * license: MIT */ nx.slice2str = function (inString, inTarget, inStep) { const isSeparator = typeof inTarget === 'string'; const idx = isSeparator ? inString.indexOf(inTarget) : inTarget; const defaultStep = isSeparator ? 1 : 0; const step = typeof inStep === 'undefined' ? defaultStep : inStep; if (!inString && inString.length <= idx) return; return [inString.substr(0, idx), inString.substring(idx + step)]; }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.slice2str; } nx.slice2str; /*! * name: @jswork/next-abstract-storage * description: An abstract storage based on next. * homepage: https://js.work * version: 1.0.7 * date: 2023-07-27 18:00:50 * license: MIT */ const EMPTY_STR$3 = ''; const SEPARATOR = '@'; const NxAbstractStorage = nx.declare('nx.AbstractStorage', { methods: { init: function (inOptions) { this.engine = inOptions.engine; this.prefix = inOptions.prefix || EMPTY_STR$3; this.options = inOptions; this.setAccessor(); }, setAccessor: function () { this.accessor = { get: this.options.get || 'getItem', set: this.options.set || 'setItem', remove: this.options.remove || 'removeItem', clear: this.options.clear || 'clear', save: this.options.save || 'save' }; }, serialize: function (inTarget) { return nx.stringify(inTarget); }, deserialize: function (inString) { return nx.parse(inString); }, set: function (inKey, inValue) { // del when nx.NIL if (inValue === nx.NIL) return this.del(inKey); // else set var index = inKey.indexOf('.'); if (index > -1) { var paths = nx.slice2str(inKey, index, 1); var context = this.get(paths[0]) || {}; nx.set(context, paths[1], inValue); this.set(paths[0], context); } else { this.engine[this.accessor.set](this.__key(inKey), this.serialize(inValue)); } this.save(); }, sets: function (inObject) { nx.each( inObject, function (key, value) { this.set(key, value); }, this ); }, get: function (inKey) { var index = inKey.indexOf('.'); if (index > -1) { var paths = nx.slice2str(inKey, index, 1); var context = this.get(paths[0]) || {}; return nx.get(context, paths[1]); } else { var value = this.engine[this.accessor.get](this.__key(inKey)); return this.deserialize(value); } }, gets: function (inKeys) { var result = {}; var keys = this.__keys(inKeys); nx.each( keys, function (_, key) { result[key] = this.get(key); }, this ); return result; }, del: function (inKey) { this.engine[this.accessor.remove](this.__key(inKey)); this.save(); }, dels: function (inKeys) { var keys = this.__keys(inKeys); nx.each( keys, function (_, key) { this.del(key); }, this ); }, clear: function () { this.engine[this.accessor.clear](); this.save(); }, keys: function () { return Object.keys(this.engine); }, save: function () { // @template method }, __key: function (inKey) { var prefix = this.prefix; return prefix ? [prefix, SEPARATOR, inKey].join(EMPTY_STR$3) : inKey; }, __keys: function (inKeys) { var length_, keys; var allNsKeys = []; if (!Array.isArray(inKeys)) { keys = this.keys(); length_ = this.prefix.length + 1; nx.each( keys, function (_, item) { if (this.prefix && item.indexOf(this.prefix + SEPARATOR) === 0) { allNsKeys.push(item.slice(length_)); } }, this ); return allNsKeys.length ? allNsKeys : keys; } return inKeys; } } }); if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = NxAbstractStorage; } var index_esm = /*#__PURE__*/Object.freeze({ __proto__: null, default: NxAbstractStorage }); var require$$1 = /*@__PURE__*/getAugmentedNamespace(index_esm); var dist$8 = {exports: {}}; /*! * name: @jswork/next-gm-store-engine * description: Store engin for tampermonkey GM_storage. * homepage: https://github.com/afeiship/next-gm-store-engine * version: 1.0.6 * date: 2023-07-27 18:00:38 * license: MIT */ var hasRequiredDist; function requireDist () { if (hasRequiredDist) return dist$8.exports; hasRequiredDist = 1; (function (module) { (function() { var global = typeof window !== 'undefined' ? window : this || Function('return this')(); var nx = global.nx || distExports$2; var NxGmStoreEngine = nx.declare('nx.GmStoreEngine', { statics: { setItem: function (inKey, inValue) { return GM_setValue(inKey, inValue); }, getItem: function (inKey) { return GM_getValue(inKey); }, removeItem: function (inKey) { GM_deleteValue(inKey); }, clear: function () { var keys = GM_listValues(); keys.forEach(function (key) { this.removeItem(key); }, this); } } }); if (module.exports) { module.exports = NxGmStoreEngine; } })(); } (dist$8)); return dist$8.exports; } /*! * name: @jswork/next-gm-storage * description: Storage implement for GM tampermonkey. * homepage: https://github.com/afeiship/next-gm-storage * version: 1.0.7 * date: 2023-07-27 18:00:43 * license: MIT */ (function (module) { (function() { var global = typeof window !== 'undefined' ? window : this || Function('return this')(); var nx = global.nx || distExports$2; var NxAbstractStorage = nx.AbstractStorage || require$$1; var NxGmStoreEngine = nx.GmStoreEngine || requireDist(); var NxGmStorage = nx.declare('nx.GmStorage', { extends: NxAbstractStorage, methods: { init: function (inPrefix) { this.base({ engine: NxGmStoreEngine, prefix: inPrefix || '' }); }, serialize: function (inTarget) { return inTarget; }, keys: function () { return GM_listValues(); } } }); if (module.exports) { module.exports = NxGmStorage; } })(); } (dist$9)); var distExports$1 = dist$9.exports; var NxGmStorage = /*@__PURE__*/getDefaultExportFromCjs(distExports$1); var c=/\{([^}]+)\}/g;function o(t){let r=[],n;for(;n=c.exec(t);)r.push(n[1]);return r}function l(t){return Object.keys(t).length===0}function y(t,r){let n={},s={};return !r||l(r)?[null,null]:Array.isArray(r)?[null,r]:(Object.keys(r).forEach(e=>{let u=t.includes(e)?n:s;u[e]=r[e];}),[n,s].map(e=>l(e)?null:e))}var f=(t,r)=>{let n=o(t);return Array.isArray(r)?[null,r]:r instanceof FormData?[null,r]:y(n,r)}; /*! * name: @jswork/next-tmpl * description: A simple template engine based on next. * homepage: https://js.work * version: 1.0.7 * date: 2023-05-24 12:44:44 * license: MIT */ const FORMAT_RE = /(?:{)([\w.]+?)(?:})/gm; const EMPTY_STR$2 = ''; nx.tmpl = function (inString, inArgs) { if (!inArgs) return inString; const result = inString || EMPTY_STR$2; const replaceFn = function (mat, match) { return nx.get(inArgs, match) || mat; }; return result.replace(FORMAT_RE, replaceFn); }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.tmpl; } nx.tmpl; /*! * name: @jswork/next-difference * description: Array difference for next. * homepage: https://js.work * version: 1.0.2 * date: 2023-05-24 11:25:10 * license: MIT */ nx.difference = function (inArray1, inArray2) { return inArray1.filter(function (i) { return inArray2.indexOf(i) === -1; }); }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.difference; } nx.difference; /*! * name: @jswork/http-rest-config * description: A simple rest config for react project. * homepage: https://js.work * version: 2.0.32 * date: 2025-02-19 13:40:49 * license: MIT */ var __assign$1 = (undefined && undefined.__assign) || function () { __assign$1 = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign$1.apply(this, arguments); }; var __rest$1 = (undefined && undefined.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __spreadArray$1 = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var STD_TEMPLATES = { index: ['get', '@'], show: ['get', '@/{id}'], create: ['post', '@'], update: ['put', '@/{id}'], destroy: ['delete', '@/{id}'], }; var normalizeResource = function (inResources, inTemplates) { if (!(inResources === null || inResources === void 0 ? void 0 : inResources.length)) return []; var templates = inTemplates || STD_TEMPLATES; var STD_KEYS = Object.keys(STD_TEMPLATES); return inResources.map(function (res) { var resource = typeof res === 'string' ? { name: res } : res; var name = resource.name, only = resource.only, except = resource.except, others = __rest$1(resource, ["name", "only", "except"]); var items = {}; var hasOnly = !!(only === null || only === void 0 ? void 0 : only.length); var hasExcept = !!(except === null || except === void 0 ? void 0 : except.length); var current = __spreadArray$1([], STD_KEYS, true); current = hasOnly ? only : current; current = hasExcept ? nx.difference(current, except) : current; current.forEach(function (item) { var key = "".concat(name, "_").concat(item); var tmpl = templates[item].slice(0); tmpl[1] = tmpl[1].replace('@', "/".concat(name)); items[key] = tmpl; }); return __assign$1(__assign$1({}, others), { items: items }); }); }; var httpRestConfig = function (httpClient, inConfig, inOptions) { var apiConfig = {}; var items = inConfig.items, resources = inConfig.resources, templates = inConfig.templates; var transformApi = __assign$1({}, inOptions).transformApi; // api resources var resourceItems = normalizeResource(resources, templates); var target = items.concat(resourceItems); target.forEach(function (item) { var request = item.request || inConfig.request; var prefix = item.prefix || inConfig.prefix || ''; var suffix = item.suffix || inConfig.suffix || ''; // const baseURL = item.baseURL || inConfig.baseURL || `${location.protocol}//${location.host}`; var baseURL = item.baseURL || inConfig.baseURL; // api items nx.each(item.items, function (key, _item) { var _method = _item[0], _path = _item[1], _opts = _item[2]; var _a = _opts || {}, tags = _a.tags, opts = __rest$1(_a, ["tags"]); var name = prefix + key + suffix; apiConfig[name] = function (inData, inOptions) { var method = String(_method).toLowerCase(); var subpath = request[0], dataType = request[1]; var _a = f(_path, inData), params = _a[0], data = _a[1]; var apiPath = nx.tmpl(_path, params); var options = nx.mix({ dataType: dataType }, opts, inOptions); var url = baseURL + subpath + apiPath; // for restful options.$key = key; options.$name = name; options.$tags = tags || []; var context = httpClient[method](url, data, options); var transformArgs = { key: key, name: name, prefix: prefix, suffix: suffix, method: method, params: params, url: url, data: data, options: options, httpClient: httpClient, context: context, }; return transformApi ? transformApi(transformArgs) : context; }; }); }); return apiConfig; }; // for commonjs es5 require if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = httpRestConfig; } /*! * name: @jswork/http-schema * description: Http schema based on next-fetch. * homepage: https://js.work * version: 2.2.25 * date: 2025-02-19 13:40:53 * license: MIT */ var __assign = (undefined && undefined.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (undefined && undefined.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var defaults$3 = { adapter: 'Axios', harmony: false }; var FETCH_IMPORT_MSG = 'Please import @jswork/next-fetch first.'; var isFetchAdapterNil = function (inAdapter) { return inAdapter === 'Fetch' && typeof nx[inAdapter] === 'undefined'; }; var httpSchema = function (inConfig, inOptions) { var _a = __assign(__assign({}, defaults$3), inOptions), adapter = _a.adapter, harmony = _a.harmony, transformApi = _a.transformApi, dynamicApi = _a.dynamicApi, options = __rest(_a, ["adapter", "harmony", "transformApi", "dynamicApi"]); if (isFetchAdapterNil(adapter)) nx.error(FETCH_IMPORT_MSG); var httpClient = nx[adapter].getInstance(options); var httpRestOpts = transformApi ? { transformApi: transformApi } : undefined; var context = httpRestConfig(httpClient, inConfig, httpRestOpts); var dynamicFn = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return (_a = dynamicApi === null || dynamicApi === void 0 ? void 0 : dynamicApi.apply(void 0, __spreadArray([context], args, false))) !== null && _a !== void 0 ? _a : Promise.resolve(null); }; var dynamicFnGenerator = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return function () { return dynamicFn.apply(void 0, args); }; }; if (harmony) { nx.$api = context; nx.$dapi = dynamicFn; nx.$dapiFn = dynamicFnGenerator; nx.$http = httpClient; } return context; }; // for commonjs es5 if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = httpSchema; } /*! * name: @jswork/next-stub-singleton * description: Stub code for singleton. * homepage: https://js.work * version: 1.0.7 * date: 2023-05-24 12:43:21 * license: MIT */ nx.stubSingleton = function () { return { instance: null, getInstance: function () { var args = [null].concat(nx.slice(arguments)); var Clazz = Function.prototype.bind.apply(this, args); return new Clazz(); }, getSingleton: function () { var args = [null].concat(nx.slice(arguments)); if (!this.instance) { var Clazz = Function.prototype.bind.apply(this, args); this.instance = new Clazz(); } return this.instance; } }; }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.stubSingleton; } nx.stubSingleton; /*! * name: @jswork/next-parse-request-args * description: Request arguments parser. * homepage: https://js.work * version: 1.0.8 * date: 2023-09-15 14:15:02 * license: MIT */ const DEFAULT_OPTIONS = { method: 'get' }; const MSG_ERROR = 'The arguments.length should between 1 ~ 4.'; const HTTP_METHOD = ['GET', 'POST', 'DELETE', 'PUT', 'CONNECT', 'HEAD', 'OPTIONS', 'TRACE']; const isValidMethod = (arg) => HTTP_METHOD.includes(arg.toUpperCase()); nx.parseRequestArgs = function (inArguments, inIsArray) { const args = nx.slice(inArguments); const length = args.length; let options = null; // input: // 1. (config) // 2. (url) // 3. (url, config) // 4. (method, config) // 5. (method, url) // 6. (method, url, config) // 7. (method, url, undefined, data) --- 这种其实是第6种情况,但 config 实际是 data 得到的 // 8. (method, url, data, config) switch (length) { case 1: options = typeof args[0] === 'string' ? { url: args[0] } : args[0]; break; case 2: const config = typeof args[1] === 'string' ? { url: args[1] } : args[1]; options = isValidMethod(args[0]) ? nx.mix({ method: args[0] }, config) : nx.mix({ url: args[0] }, args[1]); break; case 3: options = nx.mix({ method: args[0], url: args[1] }, args[2]); break; case 4: if (args[2] === undefined) (args[2] = args[3]), delete args[3]; options = nx.mix({ method: args[0], url: args[1], data: args[2] }, args[3]); break; default: options = null; nx.error(MSG_ERROR); } options = nx.mix(null, DEFAULT_OPTIONS, options); const { method, url, data, ...opts } = options; return !inIsArray ? options : [method, url, data, opts]; }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.parseRequestArgs; } nx.parseRequestArgs; /*! * name: @jswork/pipe * description: Pipe is a lightweight JavaScript library for function composition and execution. * homepage: https://js.work * version: 1.0.4 * date: 2023-07-16 08:47:22 * license: MIT */ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (undefined && undefined.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; function pipe() { var functions = []; for (var _i = 0; _i < arguments.length; _i++) { functions[_i] = arguments[_i]; } return function (input) { return functions.reduce(function (output, func) { try { return func(output); } catch (error) { console.error('Function execution skipped:', error); return output; } }, input); }; } function pipeAsync() { var functions = []; for (var _i = 0; _i < arguments.length; _i++) { functions[_i] = arguments[_i]; } return function (input) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, functions.reduce(function (acc, func) { return __awaiter(_this, void 0, void 0, function () { var output, result, error_1; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); return [4 /*yield*/, acc]; case 1: output = _a.sent(); return [4 /*yield*/, Promise.resolve(func(output))]; case 2: result = _a.sent(); return [2 /*return*/, result]; case 3: error_1 = _a.sent(); console.error('Function execution skipped:', error_1); return [2 /*return*/, acc]; case 4: return [2 /*return*/]; } }); }); }, Promise.resolve(input))]; }); }); }; } pipe.async = pipeAsync; pipe.sync = pipe; // for commonjs es5 require if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = pipe; } /*! * name: @jswork/next-filter-map * description: Filter after map for next use reduce. * homepage: https://js.work * version: 1.2.3 * date: 2023-05-24 11:26:16 * license: MIT */ nx.filterMap = function (inTarget, inIterator) { return inTarget.reduce(function (acc, item, index) { const res = inIterator(item, index, inTarget); if (res[0]) acc.push(res[1]); return acc; }, []); }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.filterMap; } nx.filterMap; /*! * name: @jswork/next-interceptor * description: Interceptor for next. * homepage: https://js.work * version: 1.1.3 * date: 2024-09-16 09:14:13 * license: MIT */ const defaults$2 = { async: false, items: [], priority: 1000 }; const NxInterceptor = nx.declare('nx.Interceptor', { methods: { init: function (inOptions) { this.options = nx.mix(null, defaults$2, inOptions); this.activeItems = []; }, processItems: function () { const { items, priority } = this.options; return items .map((item) => { item.priority = item.priority || priority; return item; }) .sort((a, b) => a.priority - b.priority); }, applyItems: function (inWhen) { const entities = this.processItems(); const filterType = typeof inWhen === 'function' ? inWhen : (item) => { if (!inWhen) return item; return item.type === inWhen; }; const filterDisabled = (item) => !item.disabled; this.activeItems = nx.filterMap(entities, (item) => [ filterDisabled(item) && filterType(item), item.fn ]); }, compose: function (inPayload, inWhen) { const composer = this.options.async ? pipe.async : pipe.sync; this.applyItems(inWhen); return composer.apply(null, this.activeItems)(inPayload); } } }); if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = NxInterceptor; } /*! * name: @jswork/next-content-type * description: Get correct content type for next. * homepage: https://js.work * version: 1.0.11 * date: 2024-03-29 15:40:29 * license: MIT */ const TYPES = { urlencoded: 'application/x-www-form-urlencoded', multipart: 'multipart/form-data', json: 'application/json;charset=utf-8', raw: 'text/plain', text: 'text/plain', blob: 'application/octet-stream', arraybuffer: 'application/octet-stream', stream: 'application/octet-stream', document: 'application/xml', auto: null }; nx.contentType = function (inKey) { return TYPES[inKey]; }; if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { module.exports = nx.contentType; } nx.contentType; /** * base64.ts * * Licensed under the BSD 3-Clause License. * http://opensource.org/licenses/BSD-3-Clause * * References: * http://en.wikipedia.org/wiki/Base64 * * @author Dan Kogai (https://github.com/dankogai) */ const version = '3.7.7'; /** * @deprecated use lowercase `version`. */ const VERSION = version; const _hasBuffer = typeof Buffer === 'function'; const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined; const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined; const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; const b64chs = Array.prototype.slice.call(b64ch); const b64tab = ((a) => { let tab = {}; a.forEach((c, i) => tab[c] = i); return tab; })(b64chs); const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; const _fromCC = String.fromCharCode.bind(String); const _U8Afrom = typeof Uint8Array.from === 'function' ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0)); const _mkUriSafe = (src) => src .replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_'); const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ''); /** * polyfill version of `btoa` */ const btoaPolyfill = (bin) => { // console.log('polyfilled'); let u32, c0, c1, c2, asc = ''; const pad = bin.length % 3; for (let i = 0; i < bin.length;) { if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255) throw new TypeError('invalid character found'); u32 = (c0 << 16) | (c1 << 8) | c2; asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63]; } return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc; }; /** * does what `window.btoa` of web browsers do. * @param {String} bin binary string * @returns {string} Base64-encoded string */ const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin) : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64') : btoaPolyfill; const _fromUint8Array = _hasBuffer ? (u8a) => Buffer.from(u8a).toString('base64') : (u8a) => { // cf. https://stackoverflow.com/qu