UNPKG

cejs

Version:

A JavaScript module framework that is simple to use.

925 lines 560 kB
�� /* ,g�jHh�p��Rub �ˊ�RKb�R�}/�� This file is auto created from _structure/structure.js, base.js, module.js, dependency_chain.js, initialization.js by auto-generate tool: build.nodejs(.js) @ 2024. */ 'use strict'; if (typeof CeL !== 'function') { /** * <code> TODO \ module_name 9eb arguments http://threecups.org/?p=129 http://cdnjs.com/ listen language change event play board use <a href="http://prototyp.ical.ly/index.php/2007/03/01/javascript-design-patterns-1-the-singleton/" accessdate="2010/4/25 0:23" title="prototyp.ical.ly &amp;raquo; Javascript Design Patterns - 1. The Singleton">Singleton pattern</a>, Module !j_b�U�O!j_�<a href="http://zh.wikipedia.org/wiki/%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F" accessdate="2010/4/25 0:25" title="US�O!j_">Singleton</a> �<a href="http://www.comsharp.com/GetKnowledge/zh-CN/TeamBlogTimothyPage_K950.aspx" accessdate="2010/4/25 0:24" title="���N�v��h`Zf�v JavaScript �b�] - �W�N COMSHARP CMS">�p Douglas Crockford @b�c]</a> �&N��'Yϑ�a(u(W Yahoo User Interface Library YUI0 http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices http://ioio.name/core-javascript-pitfalls.html CommonJS http://www.heliximitate.cn/studyblog/archives/tag/commonjs </code> */ /** * <code> // TODO // 2011/7/31 21:18:01 //module //typeof CeL_id === 'string' && typeof this[CeL_id] === 'function' && typeof CeL === 'function' && CeL.run({ name:[module_name], require:[function_name,module_name], code:function(CeL){ var private_value=1; function module_function_1(arg) { ; } module_function_1.required=''; function module_class_1(arg) { ; } function get_value(){ return private_value; } module_class_1.prototype.print=function(){}; module_class_1.print=function(){}; return {module_function_1,module_class_1}; } }); </code> */ // void( // typeof CeL !== 'function' && ( /** * We can redefine native values only for undefined.<br /> * http://weblogs.asp.net/bleroy/archive/2006/08/02/Define-undefined.aspx<br /> * <br /> * Will speed up references to undefined, and allows redefining its name. (from * jQuery)<br /> * <br /> * (u(W�k�b/f return undefined<br /> * (W ��v browser -N �undefined �S�� NX[(W0 */ function (globalThis) { if (false) if (typeof globalThis !== 'object' && typeof globalThis !== 'function') throw new Error('No globalThis object specified!'); var // https://developers.google.com/closure/compiler/docs/js-for-compiler /** @const */ library_name = 'CeL', /** * library version. * * @type {String} * @ignore */ library_version = '4.5.10', /** * default debug level * * @type {!p :Natural+0} * @ignore */ debug = 0, // �Su console0 // typeof console !== 'undefined' && console has_console = typeof console === 'object' // && (typeof console.log === 'function' // in IE 8, typeof console.log === 'object'. || typeof console.log === 'object') && typeof console.error === typeof console.log && typeof console.trace === typeof console.log, old_namespace, // default not_native_keyword. // @inner // const KEY_not_native = typeof Symbol === 'function' ? Symbol('not_native') : 'not_native', // _base_function_to_extend, function_name_pattern; // members of library ----------------------------------------------- // define 'undefined' try { // undefined === void 0 if (undefined !== undefined) { throw new Error('Invalid undefined'); } // eval('if(undefined!==undefined){throw new Error('Invalid // undefined');}'); } catch (e) { // Firefox/49.0 WebExtensions �S�� throw: // Error: call to eval() blocked by CSP // @see // https://developer.mozilla.org/en-US/docs/Archive/Firefox_OS/Firefox_OS_apps/Building_apps_for_Firefox_OS/CSP // or: undefined=void 0 if (e === 1) eval('undefined=this.undefined;'); } try { old_namespace = globalThis[library_name]; } catch (e) { // throw { message: '' }; throw new Error(library_name + ': Cannot get the global scope object!'); } if (false) { _Global.JustANumber = 2; var _GlobalPrototype = _Global.constructor.prototype; _GlobalPrototype.JustANumber = 2; } // ��]�}�[�N� ��N�0�V�p�] g \ conflict �v \V{ ��Vdk�N�0 if (false) if (globalThis[library_name] !== undefined) return; /** * Will speed up references to DOM: window, and allows redefining its name. * (from jQuery) * * @ignore */ // window = this; /** * ,g JavaScript framework �vFh�g�W,g�[JT0<br /> * base name-space declaration of JavaScript library framework * * @name CeL * @class Colorless echo JavaScript kit/library: library base name-space */ function _() { /** * function CeL: library root<br /> * declaration for debug */ // this.globalThis = arguments[0] || arguments.callee.ce_doc; // return new (this.init.apply(globalThis, arguments)); }; // if (typeof _.prototype !== 'object') _// JSDT:_module_ . /** * framework main prototype definition for JSDT: g prototype Mbg\KNvu\O Class */ prototype = { }; // _.library_version = _.version = library_version; _.build_date = new Date("2024-12-02T09:48:37.418Z"); // name-space xkl\-��[ _// JSDT:_module_ . get_old_namespace = function () { return old_namespace; }; _// JSDT:_module_ . recover_namespace = function () { if (old_namespace === undefined) delete globalThis[library_name]; else globalThis[library_name] = old_namespace; return _; }; _// JSDT:_module_ . /** * JavaScript library framework main class name. * * @see <a * href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMA-262</a>: * Object.Class: A string value indicating the kind of this object. * @constant */ Class = library_name; var is_WWW = typeof window === 'object' && (globalThis === window // 2021/11/16 e.g., under https://web.archive.org/ // `window is {Proxy} of `globalThis` || window.window === window && _ === window[library_name]) // 1u�h�N�Vۂ�v���Y0 && typeof navigator === 'object' // Internet Explorer 6.0 (6.00.2900.2180), // Internet Explorer 7.0 (7.00.5730.13) -N � // navigator === window.navigator Nb�z� && navigator == window.navigator && typeof location === 'object' && location === window.location // object || function && typeof setTimeout !== 'undefined' && setTimeout === window.setTimeout && typeof document === 'object' && document === window.document // NiQ P(W IE5.5 -N��/f Object // && _.is_type(window, 'globalThis') // && _.is_type(document, 'HTMLDocument') // && navigator.userAgent , is_W3CDOM = is_WWW // W3CDOM, type: Object @ IE5.5 && document.createElement // &&!!document.createElement // type: Object @ IE5.5 && document.getElementsByTagName; _// JSDT:_module_ . /** * Are we in a web environment? * * @param {Boolean} * W3CDOM Test if we are in a World Wide Web Consortium (W3C) * Document Object Model (DOM) environment. * * @return We're in a WWW environment. * * @since 2009/12/29 19:18:53 * @see use lazy evaluation / lazy loading * @_memberOf _module_ */ is_WWW = function (W3CDOM) { return W3CDOM ? is_W3CDOM : is_WWW; }; _// JSDT:_module_ . /** * ,g library \(uKN evaluate()0 * * �(W function -N eval �Nrs�_ local variable �(W � browser -N��R var0<br /> * e.g., 'var local_variable=' + ..<br /> * N�R var (W � browser -Ng��b global ��xe0 * * @param {String}code * script code to evaluate * * @returns value that evaluate process returned * @see window.eval === window.parent.eval * http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript * http://perfectionkills.com/global-eval-what-are-the-options/ */ eval_code = globalThis.execScript ? function (code) { // �zl CeL.run() (W�S�N�v�c�S�_ code �v�`�l N ��e �Hr JScript �S��g�N eval() �O include � // �\ �b var �v<P Ng��-��[0R global scope0 // use window.execScript(code, "JavaScript") in JScript: // window.execScript() \�v�cO(uhQ@\ N N�e�t�X � // �Vdk �execScript(Str)-N�vW[&{2NStr�S�Nq_��hQ@\��ϑ0  _NS�br�fhQ@\��ϑ0�Qxe�N�S \a��i �hV0 // window.execScript doesn t return a value. return globalThis.execScript(code, "JavaScript"); } : function eval_code(code) { /** * JSC eval() takes an optional second argument which can be 'unsafe'.<br /> * Mozilla/SpiderMonkey eval() takes an optional second argument which * is the scope object for new symbols. */ if (false) { _.debug(globalThis.eval, 2); _.debug(globalThis.eval && globalThis.eval !== arguments.callee); } // NO globalThis.eval.call(global, code) : // http://perfectionkills.com/global-eval-what-are-the-options/ // TODO: <ONN N=~/f g(u0�� era.htm0 return globalThis.eval && globalThis.eval !== eval_code ? globalThis.eval(code) // QuickJS 2020-04-12 �_��b,g�k;��hQ�*Rd� �&TGR N��ck8^�WL�0�a�p bug0 // �.zh�:y�l Eclipse Kepler (4.3.2) SR2 KN JsDoc \!q�lU�t0 : (0, eval)(code); }; try { _// JSDT:_module_ . /** * evaluate @ Global scope.<br /> * * By the ECMA-262, new Function() will 'Pass in the Global Environment * as the Scope parameter.'<br /> * * copy from jQuery core.js * * @param {String}code * script code to evaluate * * @returns value that evaluate process returned * @see <a * href="http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context" * accessdate="2011/8/6 8:56">Eval JavaScript in a global context | * Java.net</a> use execScript on Internet Explorer */ global_eval = new Function('code', 'return ' + ( typeof execScript === 'function' ? 'execScript(' : is_WWW ? 'window.eval(' : 'eval.call(null,' ) + 'code)'); } catch (e) { // Firefox/49.0 WebExtensions �S�� throw: // Error: call to Function() blocked by CSP _.global_eval = function(code) { _.error('global_eval: Cannot eval()!'); }; } // 2019/6/3 18:16:44 CeL.null_Object() �! Object.create(null) if (typeof Object.create !== 'function') { // https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/create // HQ�fBff}N P �(u�e `Object.create(null)`0 (Object.create = function create(proto, propertiesObject) { if (proto !== null && typeof proto !== "object" && typeof proto !== "function") { throw TypeError("Object prototype may only be an Object or null: " + proto); } // new Object(); var new_Object = {}; if (Object.setPrototypeOf && !Object.setPrototypeOf[KEY_not_native]) { Object.setPrototypeOf(new_Object, proto); } else { new_Object.__proto__ = proto; } if(typeof propertiesObject === "object") { Object.defineProperties(new_Object, propertiesObject); } return new_Object; })[KEY_not_native] = true; } /** * setup options. MRnU�t options �ck��S read-only �Sxe0 * * @example<code> // // MR\\Omi/MRnU�t0 // if (!library_namespace.is_Object(options)) // options = Object.create(null); // �! // options = library_namespace.setup_options(options); // options = library_namespace.setup_options(options, true); * </code> * * @param {Object}[options] * D��R�Sxe/-��[x��d'`/yr�k�R���x��0 * @param {Boolean}[new_one] * ͑�e ��Q�S���f9e�vx��0vug�f9e0RoptionsBf ��Q-��[dk�0 * * @returns {Object}x��0 * * @since 2016/3/13 13:58:9 */ function _setup_options(options, new_one) { if (options && (!new_one || Array.isArray(options))) { return options; } // create a new one. copy options. // or use Object.clone(options) options = Object.assign(Object.create(null), options); // ;��Q�poR,g0 options.new_NO = (options.new_NO | 0) + 1; return options; } /** * setup options. MRnU�t options �ck��S&N�c�O�S��a9e���v TgQ�[�Sxe ��N�MQ�O9eb��˄D��R�Sxe0<br /> * �P(u(W<b> Ng9e��</b> options �v�`�l0 * * @example<code> // // MR\\Omi/MRnU�t0 // if (!library_namespace.is_Object(options)) // options = Object.create(null); // �! // options = library_namespace.setup_options(options); * </code> * * @param {Object}[options] * D��R�Sxe/-��[x��d'`/yr�k�R���x��0 * * @returns {Object}x��0 * * @since 2016/3/13 13:58:9 */ function setup_options(options) { if (typeof options === 'string') { // e.g., 'bot' �! {bot:true} // e.g., 'bot|minor' �! {bot:true,minor:true} var _options = Object.create(null), i = 0; for (options = options.split('|'); i < options.length; i++) { if (options[i]) { _options[options[i]] = true; } } return _options; } // e.g., number: Invalid option? return (typeof options === 'object' /* || typeof options === 'function' */) // typeof null === 'object' && options || Object.assign(Object.create(null), options); } /** * setup options. MRnU�t / clone options ��MQ�O9eb��˄D��R�Sxe0<br /> * ͑�e ��Q�S���f9e�vx��0vug�f9e0R options Bf ��QO(udk�Qxe0 * * @example<code> // MR\\Omi/MRnU�t0 // ͑�e �N P options �N�MQal�g0 if (!library_namespace.is_Object(options)) options = Object.create(null); // �! options = library_namespace.new_options(options); // O(u�e���l0 options = { ...options }; </code> * * @param {Object}[options] * D��R�Sxe/-��[x��d'`/yr�k�R���x��0 * * @returns {Object}x��0 * * @since 2016/03/14 16:34:09 */ function new_options(options) { // create a new one. copy options. // or use Object.clone(options) var length = arguments.length; if (_.is_Object(options)) { if ((new_options.new_key in options) && length === 1) { // converted return options; } options = Object.assign(Object.create(null), options); } else { options = Object.create(null); } if (length > 1) { for(var i = 1; i < length; i++) // if (_.is_Object(arguments[i])) if (arguments[i]) Object.assign(options, arguments[i]); } Object.defineProperty(options, new_options.new_key, { // let [new_options.new_key] deletable configurable : true, // NAQ1� enumerable �N�MQdkl\'`��O(u0 // enumerable : false value : true }); return options; } new_options.new_key = 'is new options'; // Ng�f�R options �v(udk0 _.setup_options = setup_options; // g�f�R options �v(udk0 _.new_options = new_options; var modify_function_hash = Object.create(null); _// JSDT:_module_ . /** * simple evaluates to get the value of specified variable identifier name. * * NO(u eval() �v�e�l �Nd\Nd\ call name-space0 * * BUG: !q֊/f N/f�v T name_space ��S�� variable_name �v T �sSg�WL� modify_function0<br /> * �N��aԚzz���c�SBf��He�s �g�X�R��aԚzz��KNO(u0 * * (WiQ PP[d\(a.b.c) N ��#j\OHe�s��]@Chrome/5.0.375.29:<br /> * function(v){try{return(new Function('return('+v+')'))();}catch(e){}} * * TODO:<br /> * NX[(WBf throw. * * @param {String}variable_name * variable identifier name. e.g., /[a-z\d$_]+(.[a-z\d_]+)+/i * @param {Function}[modify_function] * ;��Q: vu�N .set_value() 9e��Bf ���O�WL�dk�Qxe:<br /> * modify_function(value, variable_name). * @param {Object|Function}[name_space] * initialize name-space. default: globalThis. * @param [value] * -��[ variable �p value. * * @returns value of specified variable identifier name * * @since 2010/1/1 18:11:40 * @note 'namespace' /f JScript.NET �v�OYuW[0 * * @see https://github.com/tc39/proposal-optional-chaining */ value_of = function (variable_name, modify_function, name_space, value) { var variable_name_array; if (Array.isArray(variable_name) && variable_name.length > 0) { variable_name_array = variable_name; variable_name = variable_name.join('.'); // (W Object("") �v�`�l N �typeof this==='object'0dkBf N�S(u typeof0 } else if (typeof variable_name === 'string' && variable_name) variable_name_array = variable_name.split('.'); else // return variable_name: �2� value_of(null/undefined/NaN) return variable_name; // _.debug('get value of [' + variable_name + ']'); if (_.is_Function(modify_function)) { if (variable_name in modify_function_hash) modify_function_hash[variable_name].push(modify_function); else modify_function_hash[variable_name] = [modify_function]; } var i = 0, // TODO: // �SU�t�Y: // obj1 . obj2 [ ' obj3.4 * \[ ' ] [''] . obj5 [ " obj6 \" \' \] . " ] // or detect obj1 .. obj2 l = variable_name_array.length, v = name_space || // `CeL.env.global`, NOT `CeL.env.globalThis` globalThis, // do set value do_set = arguments.length > 3; if (false) _.debug('globalThis.' + _.Class + ' = ' + _.env.global[_.Class]); if (do_set) l--; function cannot_travel_down() { variable_name_array[i] = '<em>' + variable_name_array[i] + '</em><span class="debug_weaken">'; if (false) alert(_.log.buffer.length + ',' + _.log.max_length + '\n' + _.debug); _.debug('Cannot ' + (do_set ? 'set' : 'get') + ' variable [<span title="' + variable_name + '">' + variable_name_array.join('.') + '</span></span>]!', 2, 'value_of'); // throw return undefined; } try { while (i < l) { var variable_name = variable_name_array[i++]; if (false) { _.debug('to [' + variable_name + ']: ' //+ v[variable_name] ); } if (!(variable_name in v)) return cannot_travel_down(); if (platform.nodejs && typeof v === 'function' // TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them && variable_name in { 'caller' : true, 'callee' : true, 'arguments' : true }) { return cannot_travel_down(); } v = v[variable_name]; } if (do_set) { v[variable_name_array[i]] = value; do_set = modify_function_hash[variable_name]; if (do_set) for (i in do_set) try { do_set[i](value, variable_name); } catch (e) { // TODO: handle exception } } } catch (e) { return cannot_travel_down(); } return v; }; _// JSDT:_module_ . /** * simple evaluates to set value of specified variable identifier name.<br /> * NO(u eval(). * * @param {String}variable_name * variable identifier name. e.g., /[a-z\d$_]+(.[a-z\d_]+)+/i * @param [value] * -��[ variable �p value. * @param {Object|Function}[name_space] * initialize name-space. default: globalThis. * * @returns name-space of specified variable identifier name.<br /> * e.g., return a.b.c when call .set_value('a.b.c.d'). * @since 2011/8/27 15:43:03 */ set_value = function (variable_name, value, name_space) { return _.value_of(variable_name, null, name_space, value); }; // ------------------------------------------------------------------------ _// JSDT:_module_ . /** * is index (u, only digits. texe >= 0.<br /> * cf. Number.isInteger() * * @param value * value to test * @returns if value only digits. */ is_digits = function (value) { // ��2� TypeError: Cannot convert object to primitive value0 return typeof value !== 'object' // value == value | 0 // value == (value >>> 0) && /^\d+$/.test(value); }; if (false) if (!globalThis.is_digits) globalThis.is_digits = _.is_digits; /** * ,nf�T type: * * undefined:<br /> * ��xe<PX[(WN��xe 'undefined' X[(WBf: variable === undefined<br /> * &TGR: typeof(variable) === 'undefined' * * TODO:<br /> * void(1) === void(0) === undefined * * number, boolean, string:<br /> * typeof(variable) === '~'<br /> * * TODO:<br /> * NaN<br /> * int/float * * object:<br /> * null * * N T frame -N�v Array �d g N T�v constructor */ /** * A cache to the function we use to get the type of specified value.<br /> * Get the [[Class]] property of this object.<br /> * NO(u Object.toString() /f`�� overridden * * @type {Function} * @inner */ var get_object_type = Function.prototype.bind ? Function.prototype.call.bind(Object.prototype.toString) : function (o) { return Object.prototype.toString.call(o); }; _.get_object_type = get_object_type; _// JSDT:_module_ . /** * $R�e�pUO.z type0;N��(u(W Error, DOMException I{ native methods / native objects / * built-in objects KN$R%R0 * * @param value * variable or class instance to test * @param {String}[want_type] * type to compare: number, string, boolean, undefined, object, * function * @param {Boolean}[get_Class] * get the class name of a class(function) instance. * * @returns {Boolean} The type is matched. * @returns {String} The type of value * @returns {undefined} error occurred * * @example<code> CeL.is_type(value_to_test, 'Array'); </code> * * @since 2009/12/14 19:50:14 * @see <a * href="http://lifesinger.org/blog/2009/02/javascript-type-check-2/" * accessdate="2009/12/6 19:10">JavaScript{|�W�hKm\�~� N � - �\g�YLk</a><br /> * <a * href="http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/" * accessdate="2009/12/6 19:10">Perfection kills &raquo; `instanceof` * considered harmful (or how to write a robust `isArray`)</a> */ is_type = function is_type(value, want_type, get_Class) { var type; if (want_type && (type = typeof want_type) !== 'string') want_type = type; type = value === null ? String(value) : typeof value; if (get_Class) try { if (type === 'function' && value.Class) // get the class name of a class // � value �p function Bf �,nf�vQ,g��KN Class0 type = value.Class; else if (type === 'function' || type === 'object') if (('constructor' in value) && (get_Class = value.constructor).Class) // get the class name of a class instance // � value �p function N!q Class �b�p object Bf �,nf�vQ // constructor KN Class0 type = get_Class.Class; else if (get_Class = _.get_function_name(get_Class)) // get Class by function name type = get_Class; } catch (e) { _.error(_.Class + '.is_type: Fault to get ths class name of value!'); } if (type !== 'object') // type maybe 'unknown' or 'date'! return want_type ? type === want_type.toLowerCase() : type; try { get_Class = get_object_type(value); } catch (e) { _.error(_.Class + '.is_type: Fault to get object type of value!'); get_Class = ''; } if (want_type) return get_Class === (want_type.charAt(0) === '[' ? want_type : '[object ' + want_type + ']'); want_type = get_Class.match(/^\[object ([^\]]+)\]$/); if (want_type) return want_type[1]; return type; }; _// JSDT:_module_ . /** * get a type test function * * @example<code> * // 'YϑW�I�Bf ��c���SY(W,g�� scope -N ��Qwc�_� * _.OtS = Object.prototype.toString; * var is_Person = CeL.type_tester('Person', 'OtS'); * // test * if(is_Person(value)) * // it's really a Person object * ; * </code> * * @param {String}want_type * object type to compare * @param {String}[toString_reference] * a reference name to Object.prototype.toString * * @returns {Function} type test function * @since 2009/12/20 08:38:26 */ type_tester = function type_tester(want_type, toString_reference) { var t = '[object ' + want_type + ']'; if (false) return new Function('v', 'return "' + t + '"===' + (toString_reference || // (W Google Chrome -N � // 'Object.prototype.toString' �S�N�vQ reference T��^ � // FOvQ�N�v reference g�_�N0 'Object.prototype.toString' ) + '.call(v);'); return typeof toString_reference === 'string' && toString_reference ? new Function('v', 'return "' + t + '"===' + toString_reference + '.call(v);') // slow@Chrome : function (v) { return t === get_object_type(v); }; // faster@Chrome // : new Function('v', 'return "' + t + // '"===Object.prototype.toString.call(v);'); }; _// JSDT:_module_ . /** * Test if the value is a native Function. * * @param v * value to test * @returns {Boolean} the value is a native Function. * @since 2009/12/20 08:38:26 */ is_Function = // _.type_tester('Function'); function is_Function(v) { // typeof �k Object.prototype.toString �_ � // NN��_�la g�N native object �S�� type /f 'function' �FO NwQ g function yr'`0 return get_object_type(v) === '[object Function]'; // ��la �(W firefox 3 -N � // typeof [object HTMLObje