-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcls.min.js
More file actions
2 lines (2 loc) · 36.8 KB
/
cls.min.js
File metadata and controls
2 lines (2 loc) · 36.8 KB
1
2
"use strict";var cls=function(){function _type(e){var t=["Object","Function","String","Number"];return"undefined"==typeof e?"undefined":null===e?"null":void 0===e?"undefined":Array.isArray(e)?"array":"object"==typeof e||"Object"==typeof e?_isDef(e.constructor)?_isDef(e.constructor.name)&&-1===t.indexOf(e.constructor.name)?e.constructor.name:typeof e:"object":typeof e}function _clone(e,t){var r,s={};return"object"!==_type(e)&&"array"!==_type(e)?e:("array"===_type(e)&&(s=[]),forEach(e,function(e,n){r="array"===_type(e)||"object"===_type(e)?_clone(e):e,s[n]=r,"undefined"!=typeof t&&("object"===_type(t)||"function"===_type(t))&&(t[n]=r)}),s)}function _merge(e,t){for(var r,s=Object.keys(t),n=s.length,a=0,i={},o=_clone(t),c=_clone(e);n>a;a++)r=s[a],"object"===_type(o[r])&&"object"===_type(e[r])?(i=_merge(c[r],o[r]),c[r]=i):c[r]=o[r];return c}function forEach(e,t,r){if("[object Function]"!==toString.call(t))throw new TypeError("iterator must be a function");if(!_isDef(e))throw new Error("Object is undefined.");var s=e.length;if(s===+s)for(var n=0;s>n;n++)t.call(r,e[n],n,e);else for(var a in e)hasOwn.call(e,a)&&t.call(r,e[a],a,e)}function _freeze(e){if("undefined"!=typeof e){var t=Object.getOwnPropertyNames(e);return forEach(t,function(t){var r=e[t];"object"!=typeof r||Object.isFrozen(r)||cls.freeze(r)}),Object.freeze(e)}}function _isDef(e){return"undefined"!=typeof e&&null!==e}function _guid(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function convertParamDefault(e,t){var r,s="";if(r=e[0],r=r.toLowerCase(),_isDef(t)&&"string"===_type(t)&&(s=t.toLowerCase(),"undefined"===s||"null"===s)){switch(s){case"undefined":t=void 0;break;case"null":t=null}return t}switch(r){case"string":("'"===t.substr(0,1)||'"'===t.substr(0,1))&&(t=t.replace(/^[\'\"]{1}([^\'\"]+)[\'\"]{1}$/gi,"$1"));break;case"number":t=Number(t);break;case"object":t=JSON.parse(t);break;case"array":t=JSON.parse(t);break;case"bool":case"boolean":if("true"===t.toLowerCase())t=!0;else{if("false"!==t.toLowerCase())throw new Error("Boolean values must be either true or false.");t=!1}}return t}function generateArgumentTypes(e){var t=/^\s?\@param\s+\{([^\}]+)\}\s([a-z0-9\_\$]+)\s?(?:\=\s?([^\n]+))?\s?$/gim,r=t.exec(e.str),s={};if(e.arguments=[],_isDef(r)){if(r.length<3)throw new Error("Variable declaration is incorrect.");if(!_isDef(r[1])||!_isDef(r[2]))throw new Error("Variable declaration is incorrect.");s={types:r[1].split("|"),name:r[2]},_isDef(r[3])&&(s["default"]=convertParamDefault(r[1].split("|"),r[3])),e.arguments.push(s)}}function checkDeclarations(e,t,r,s){var n=!0;if(e.length>2)return!1;if(-1!==e.indexOf("public")&&-1!==e.indexOf("private")&&(n=!1),-1!==e.indexOf("public")&&-1!==e.indexOf("protected")&&(n=!1),-1!==e.indexOf("private")&&-1!==e.indexOf("protected")&&(n=!1),-1!==e.indexOf("const")&&s&&(n=!1),-1===e.indexOf("final")||s||(n=!1),!n)throw new Error("Property declarations in class ["+t+"] property ["+r+"] are incorrect.");return n}function propertyTypeMismatch(e,t,r,s){throw Array.isArray(r)&&(r=r.join(",")),new Error("Type mismatch in class [ "+e+" ] property [ "+t+" ] should be "+r+", '"+s+"' given.")}function ArgumentTypeMismatch(e,t,r,s,n){throw Array.isArray(s)&&(s=s.join(",")),new Error("Type mismatch in class [ "+e+" ] method [ "+t+" ] argument [ "+r+" ] should be "+s+", '"+n+"' given.")}function checkClassPropertyType(e,t,r){if(_isDef(e.classProperties[t])&&_isDef(e.classProperties[t].types)&&-1===e.classProperties[t].types.indexOf(_type(r))&&"anytype"!==e.classProperties[t].types[0]){var s=e.classInstance.getCurrentClassName(),n=e.classProperties[t].types.join(",");propertyTypeMismatch(s,t,n,_type(r))}return!0}function checkMethodArgTypes(e,t,r){var s,n,a,i="",o=0,c=[];if(!_isDef(e.classProperties[t]))throw new Error("There is no such method like ",t);if(!_isDef(e.classProperties[t].arguments))return Array.prototype.slice(r);if(s=e.classProperties[t].arguments,0===s.length)return Array.prototype.slice.call(r);for(o in s)n=s[o],Object.prototype.hasOwnProperty.call(s,o)&&(_isDef(r[o])?c[o]=r[o]:_isDef(n["default"])?c[o]=n["default"]:n.types.indexOf("undefined")?c[o]=void 0:ArgumentTypeMismatch(e.classInstance.getCurrentClassName(),t,n.name,n.types,"undefined"),i=_type(c[o]),"clsClassInstance"===i?(a=e.classFacade.getClassName(),canBeClass(c[o],n.types,a,n.name)):-1===n.types.indexOf(i)&&"anytype"!==n.types[0]&&ArgumentTypeMismatch(e.classInstance.getCurrentClassName(),t,n.name,n.types,i));return c}function checkReturnValue(e,t,r){var s=getObject(e),n=s.classProperties,a=_type(r),i=s.classFacade,o=i.getClassName();if("clsClassInstance"===a&&(a=r.getClassName()),!_isDef(n[t]))throw new Error("There is no method called '"+t+"' in [ "+o+" ] class.");var c=n[t].returns;if(c.indexOf("anytype")>=0)return"clsClassFacade"===a?s.classInstance:r;if(-1===c.indexOf(a))throw new Error("Type mismatch. Method [ "+t+" ] from [ "+o+" ] class, should return '"+c.join(",")+"', not '"+a+"'.");return"clsClassFacade"===a?s.classInstance:r}function getClassPropertiesOf(e,t,r){var s,n={},a="";for(a in e)s=e[a],_isDef(s.declarations)&&-1!==s.declarations.indexOf(t)&&(_isDef(r)?s.classId===r&&(n[a]=s.value):n.push(a));return n}function checkObjectContentTypes(e,t,r){var s,n,a=Object.keys(e),i=a.length,o=0,c="",l="",u="",f=!0;for(_isDef(r)||(r="");i>o;o++)if(c=a[o],_isDef(t[c]))if(s=e[c],n=t[c],l=_type(s),u=_type(n),"object"===l||"function"===l){if(f=checkObjectContentTypes(s,n,r+"."+c),!f)return!1}else if(l!==u)throw r=r+"."+c,r=r.substr(1),new Error("Type mismatch. Object property [ "+r+" ] should be an "+u+".\n'"+l+"' given.");return!0}function cleanOutCommentBlock(e){var t=String(e[1]).replace(/^[\t\*]+/gim,"").replace(/[\*]+/gim,"").replace(/^[ \t\n]{2,50}/gi,"").replace(/\n/gi,"").replace(/(\@)/gi,"\n$1").replace(/^\s+/gim,"").replace(/\s+$/gim,"").trim();return t}function prepareMethod(e,t,r,s){var n,a={},i=new RegExp(METHOD_REG,"gim"),o=t.obj,c=t.className,l=new RegExp(RETURNS_REG,"gim"),u=[],f=!1;_isDef(r)||(f=!0);var p=i.exec(e);if(!_isDef(p))throw new Error("I see death people.");var d=p[1];if(!f&&!canOverride(s,d,r))throw new Error("Cannot override '"+d+"' method.");if(!_isDef(o[d]))throw new Error("Property '"+d+"' is declared but not defined in [ "+c+" ] class.");if(a[d]={types:["function"]},a[d].classId="static:"+c,_isDef(r)&&(a[d].classId=r),a[d].className=c,a[d].value=o[d],4===p.length)if(_isDef(p[2])){if(u=[p[2]],_isDef(p[3])&&u.push(p[3]),f&&-1===u.indexOf("static"))throw new Error("It should be static property or classId is undefined.");checkDeclarations(u,c,d,!0)&&(a[d].declarations=u)}else _isDef(a[d].declarations)||(a[d].declarations=["public"]);return a[d].str=e,generateArgumentTypes(a[d]),n=l.exec(e),_isDef(n)&&(a[d].returns=n[1].split("|"),forEach(a[d].returns,function(e,t){("type"===e.toLowerCase()||"[type]"===e.toLowerCase())&&(a[d].returns[t]="anytype")})),checkClassProperty(a[d],c,d,f),_isDef(s)&&(s[d]=a[d]),[d,a[d]]}function prepareProperty(e,t,r,s){var n,a,i=t.className,o=t.obj,c={},l=new RegExp(PROPERTY_REG,"gim"),u=!1;if(_isDef(r)||(u=!0),n=l.exec(e),!_isDef(n))throw new Error("I see death people.");if(a=n[2],!u&&!canOverride(s,a,r))throw new Error("Cannot override '"+a+"' property.");if(c[a]={},c[a].str=e,c[a].types=n[1].split("|"),c[a].value=o[a],c[a].classId="static:"+i,_isDef(r)&&(c[a].classId=r),c[a].className=i,_isDef(n[3])){var f=[n[3]];if(_isDef(n[4])&&f.push(n[4]),u&&-1===f.indexOf("static"))throw new Error("It should be static property or classId is undefined.");checkDeclarations(f,i,a,!1)&&(c[a].declarations=f)}else _isDef(c[a].declarations)||(c[a].declarations=["public"]);return checkClassProperty(c[a],i,a,u),_isDef(s)&&(s[a]=c[a]),[a,c[a]]}function parseComments(e,t,r,s,n){(null===r||"undefined"==typeof r)&&(r=METHOD_PROPERTY);for(var a,i,o=e.str,c=e.obj,l=new RegExp(COMMENT_BLOCK,"gim"),u=new RegExp(r,"gim"),f="",p="",d="",_=[],h="",y={};_isDef(_);)if(_=l.exec(o),_isDef(_)&&(h=cleanOutCommentBlock(_),u.lastIndex=0,f=u.exec(h),_isDef(f)&&(p=f[1].trim(),d=f[2].trim(),y[d]={},"method"===p?(a=prepareMethod(h,e,s,n),y[a[0]]=a[1]):"property"===p&&(i=prepareProperty(h,e,s,n),y[i[0]]=i[1]),"undefined"==typeof c[d])))throw new Error("Class "+p+" [ "+d+" ] is declared but not defined in [ "+t+" ] class.");return y}function resolveStatic(e,t){var r={};forEach(e,function(e,s){r[s]=e.value,Object.defineProperty(t,s,{enumerable:!0,get:function(){return"function"==typeof e.value?e.value.bind(r):e.value}})})}function checkClassProperty(e,t,r,s){var n=["public","protected","private","static","const","final"],a="";if(!_isDef(e))throw new Error("Cannot create property from empty object.");if(_isDef(s)||(s=!1),!s&&!_isDef(e.classId))throw new Error("classId is not defined");if(_isDef(e.declarations)){if("array"!==_type(e.declarations))throw new Error("Property declarations must be an array of string at [ "+t+" ] [ "+r+" ]");forEach(e.declarations,function(e){if("string"!==_type(e))throw new Error("Property declaration must be a string at [ "+t+" ] [ "+r+" ]");if(-1===n.indexOf(e))throw new Error("Unrecognized property declaration: '"+e+"' for property [ "+r+" ] in class [ "+t+" ]")})}else e.declarations=["public"];if(_isDef(e.types)||("function"===_type(e.value)?e.types=["function"]:e.types=["anytype"]),_isDef(e.types))if(a=_type(e.value),"clsClassInstance"===a)canBeClass(e.value,e.types,t,r);else if(-1===e.types.indexOf(a)&&-1===e.types.indexOf("anytype"))throw new Error("Property value doesn't match declaration at [ "+t+" ] [ "+r+" ]\nExpected: '"+e.types+"' given: '"+a+"'.");-1===e.types.indexOf("function")||_isDef(e.returns)||(e.returns=["anytype"]),-1===e.types.indexOf("function")||_isDef(e.arguments)||(e.arguments=[]),"function"===_type(e.value)&&"undefined"===_type(e.arguments)&&(e.arguments=[])}function defaultClassType(e,t,r,s,n,a){var i=s[t]?s[t]:{};_isDef(i.classId)||(i.classId=e),_isDef(i.value)||(i.value=r),_isDef(n)&&(i.declarations=n),checkClassProperty(i,a,t),_isDef(s[t])||(s[t]=i)}function classPropertiesFromFunction(e,t,r,s){var n=(t.str,t.obj);return parseComments(t,e,null,r,s),forEach(n,function(t,n){defaultClassType(r,n,t,s,void 0,e),s[n].classId===r?s[n].value=t:canOverride(s,n,r)&&(s[n].value=t)}),s}function canOverride(e,t,r){if("object"===!_type(e))throw new Error("Wrong class properties object.");if(_isDef(e[t])){if(_isType(e[t],"final")||_isType(e[t],"const")||_isType(e[t],"static"))throw new Error("Cannot override '"+t+"'.");return!0}return!0}function _addToClassProperties(e,t,r,s){if("undefined"===_type(r)||"null"===_type(r))throw new Error("Cannot add property from empty object.");"undefined"===_type(r.classId)&&(r.classId=s);var n=getObject(s),a=n.classFacade,i=a.getClassName();canOverride(e,t,r.classId)&&(checkClassProperty(r,i,t),e[t]=r)}function classPropertiesFromObject(e,t,r,s){return forEach(t.source,function(t,n){t.classId=r;var a=!1;_isDef(t.declarations)&&(a=t.declarations.indexOf("static")>=0),checkClassProperty(t,e,n,a),s[n]=t}),s}function generateClassProperties(e,t,r,s){return _isDef(s)||(s=new clsClassProperties),"function"===_type(t.source)?classPropertiesFromFunction(e,t,r,s):"object"===_type(t.source)&&classPropertiesFromObject(e,t,r,s),s}function _typeIs(e,t){var r=e.declarations.indexOf(t);return r>=0}function clsClassInstance(e,t,r,s){this.getClassId=getClassId.bind(this,e),this.getCurrentClassName=getCurrentClassName.bind(this,t),this.getClassName=getClassName.bind(this,e),this.childOf=r?r:[],this.mixedWith=s?s:[]}function ___addPublicProperty(e){var t=this.getClassId(),r=this.getCurrentClassName(),s=this,n=__allClasses[t],a=n.classProperties,i=n.classData;if(!a.propertyExists(e))throw new Error("'"+e+"' doesn't exists");if(-1===a[e].declarations.indexOf("public"))throw new Error("'"+e+"' is not public property and cannot be added to instance.");_isDef(s[e])||Object.defineProperty(s,e,{enumerable:!0,get:function(){return i.get(t,e)},set:function(s){return i.set(t,r,e,s)}})}function clsClassProperties(){}function getClassId(e){return e}function getCurrentClassName(e){return e}function getClassName(e){for(var t=getObject(e),r=t.classFacade,s=r.child;""!==s;)t=getObject(s),r=t.classFacade,s=r.child;return r.getCurrentClassName()}function clsClassFacade(e,t){this.getClassId=getClassId.bind(this,e),this.getCurrentClassName=getCurrentClassName.bind(this,t),this.getClassName=getClassName.bind(this,e),this.mixedWith=[],this.child="",this.parent=""}function ___addProperty(e,t,r,s,n){_isDef(s)||(s=this.getClassId());var a=this.getCurrentClassName(),i=__allClasses[s],o=i.classData,c=this;_isDef(r)||(r=!1),r===!0&&_addToClassProperties(i.classProperties,e,t,s),checkPropertyType(s,a,t.value,e),_isDef(c[e])?t.value!==i.classProperties[e].value&&canOverride(i.classProperties,e,s)&&(c[e]=t.value):Object.defineProperty(c,e,{enumerable:!0,get:function(){return o.get(s,e)},set:function(t){return o.set(s,a,e,t)}})}function addToInstance(e,t){var r=this.getClassId(),s=getObject(r),n=s.classInstance;this.___addProperty(e,t,!0,r),-1!==t.declarations.indexOf("public")&&n.___addPublicProperty(e)}function mixWithObject(e){var t=this;forEach(e,function(e,r){t.addToInstance(r,e)})}function getInternalProperty(e){var t=this.getClassId(),r=this.getClassName(),s=getObject(t),n=s.classProperties;if(_isDef(n[e]))return n[e];throw new Error("Property '"+e+"' doesn't exists in [ "+r+" ] class.")}function getInternalProperties(){var e=this.getClassId(),t=(this.getClassName(),getObject(e)),r=t.classProperties;return r}function clsClassData(e){this.classFacades={},this.classProperties=e}function getName(e){var t=getObject(e);return t.classFacade.getCurrentClassName()}function getClassNameOf(e){var t=getObject(e);return t.classFacade.getCurrentClassName()}function getClassNamesOf(e){var t=[];return forEach(e,function(e){t.push(getClassNameOf(e))}),t}function canBeClass(e,t,r,s){var n=e.getClassName();if(t.indexOf("anytype")>=0)return!0;if(t.indexOf(n)>=0)return!0;var a=e.getClassId(),i=getObject(a),o=i.classFacade,c=o.inherits,l=getClassNamesOf(c);for(var u in t){var f=t[u];if(l.indexOf(f)>=0)return!0}classTypeError(r,s,n,t)}function classTypeError(e,t,r,s){throw new Error("Value of [ "+t+" ] in [ "+e+" ] class does not match declaration.\nExpected: '"+s+"' given: '"+r+"'.")}function checkPropertyType(e,t,r,s){var n=getObject(e),a=n.classProperties[s].types,i=_type(r);return a.indexOf(i)>=0?!0:a.indexOf("anytype")>=0?!0:"clsClassInstance"===i?canBeClass(r,a,t,s):a.indexOf(i)>=0?!0:void classTypeError(t,s,i,a)}function fireConstructor(e,t){Array.isArray(t)||(t=Array.prototype.slice.call(t));var r,s=getFacadeOfInstance(e),n=s.getClassId(),a=getObject(n),i=s.getCurrentClassName();return _isDef(s[i])&&a.classProperties[i].classId===n?r=s[i].apply(s,t):""!==s.parent&&(n=s.parent,a=getObject(n),e=a.classInstance,s=a.classFacade,r=fireConstructor(e,t)),r}function stackTrace(e){var t="";try{var r={};r.debug()}catch(s){t=s.stack}var n=t.split("\n").slice(e);return n.join("\n")}function fnToStrings(e){var t=_type(e);if(t=t.toLowerCase(),"function"===t){var r="cls.function:/*\ncompressed function*/\n";return r+e.toString()}if("object"===t||"array"===t){var s,n=_clone(e);return"object"===t&&(s={}),"array"===t&&(s=[]),forEach(n,function(e,t){s[t]=fnToStrings(e)}),s}return e}function _unescape(e){var t=e.substr(16);return t.substr(t.length-1-16)}function StringsToFn(obj){var type=_type(obj);if(type=type.toLowerCase(),"string"===type&&"cls.function:"===obj.substr(0,13)){var str=obj.substr(13),fn=eval("("+str+")");return fn}if("object"===type||"array"===type){var result;return"object"===type&&(result={}),"array"===type&&(result=[]),forEach(obj,function(e,t){result[t]=StringsToFn(e)}),result}return obj}function compressExtend(){var e={__compressedClass:{}},t=e.__compressedClass;t.name=this.___className,t.type=this.___type;var r=this.___firstClass,s=this.___secondClass;return t.data={firstClass:compress.call(r,!0),secondClass:compress.call(s,!0)},e}function compressClass(){var e={__compressedClass:{}},t=e.__compressedClass;t.name=this.___className,t.type=this.___type;var r=this.___source,s=r.toString();return s=/^function\s[^\{]+\{(?:\s+)?return\s?([^$]+)\s?\}$/gi.exec(s),s=s[1],t.data=s,e}function compress(e){var t;return"class"===this.___type&&(t=compressClass.call(this)),"extend"===this.___type&&(t=compressExtend.call(this)),_isDef(e)||(t=JSON.stringify(t),t=LZString.compressToUint8Array(t),this.compressed=t),t}function stringToFunction(e){return new Function("return "+e)}function buildFromStringObjects(e){var t;if("class"===e.type&&(t=_class(e.name,stringToFunction(e.data),!0)),"extend"===e.type){var r=buildFromStringObjects(e.data.firstClass.__compressedClass),s=buildFromStringObjects(e.data.secondClass.__compressedClass);t=cls.extend(r,s)}return t}function decompress(){var e=this.compressed;if(""===e)throw new Error("Class is not compressed.");var t=LZString.decompressFromUint8Array(e),r=JSON.parse(t),s=buildFromStringObjects(r.__compressedClass);return s}function rget(e,t,r){Object.defineProperty(e,t,{enumerable:!1,get:function(){return r}})}function rwget(e,t,r){var s=r;Object.defineProperty(e,t,{enumerable:!1,get:function(){return s},set:function(e){s=e}})}function getStaticFromObject(e,t){var r={};return forEach(e,function(e,s){_isDef(e.declarations)&&-1!==e.declarations.indexOf("static")&&(r[s]=checkClassProperty(e,t,s,!0))}),r}function tabs(e){for(var t="",r=0;e>r;r++)t+=" ";return t}function arrayToString(e,t){var r="";if(0===e.length)return"";if(r+=e[0].trim(),e.length>1&&(r+="\n"),e.length>=3){for(var s=1;s<e.length-1;s++)r+=tabs(t+1)+e[s].trim()+"\n";r+=tabs(t)+e[e.length-1].trim()}else 2===e.length&&(r+=tabs(t)+e[1].trim());return r}function stringify(e,t){var r="",s=_type(e);if("function"===s){var n=e.toString().split("\n");r+=arrayToString(n,t)}else"object"===s?r+=objectToString(e,t+1):"array"===s?e.length>0?(r+=e.length>1?"\n"+tabs(t)+"[\n":"[ ",forEach(e,function(s,n){e.length>1&&(r+=tabs(t+1)),r+=stringify(s,t+2)}),r+=e.length>1?"\n"+tabs(t)+"]":" ]"):r+="[]":"string"===s?(n=e.replace(/\"{1}/gim,'\\"').replace(/^/gim,'"').replace(/\n{1}/gim,'\\n"+\n').substr(1).split("\n"),r+='"'+arrayToString(n,t-1)+'"'):r+=e.toString();return r}function objectToString(e,t){var r="{\n";if("object"!==_type(e))throw new Error("This is not an object.");return forEach(e,function(e,s){r+=tabs(t+1)+'"'+s+'":'+stringify(e,t+1),"object"!==_type(e)&&(r+=","),r+="\n"}),r+=tabs(t-1)+"}",0!==t&&(r+=","),r}function asString(){var e=this.asObject(),t=objectToString(e,0);return t}function saveAsObject(e){var t=this.___className,r="// Auto generated class\n\n";if(r+="var "+t+"Source = "+this.asString()+";\nvar "+t+" = cls.class("+t+","+t+"Source);\n",!_isDef(module))return!1;if(!_isDef(module.exports))return!1;var s=require("fs");s.writeFileSync(e,r)}function asObject(){var e={};return _isDef(module)&&_isDef(module.exports)?(e.className=this.___className,"class"===this.___type?(e.type="class","function"===_type(this.___source)?(e.source={},parseComments(this.___sourceObject,this.___className,void 0,"asObjectId",e.source),forEach(e.source,function(e,t){delete e.classId})):e.source=this.___source):(e.type="extend",e.firstClass=toObject.call(this.firstClass),e.secondClass=toObject.call(this.secondClass)),e):void 0}function _class(e,t,r){var s="",n="",a="",i={},o={},c=Object.keys(__definedClasses);if(!_isDef(e)&&!_isDef(t))throw new Error("There is no source for class creation.");if(r){if(-1!==c.indexOf(e))return __definedClasses[e]}else if(-1!==c.indexOf(e))throw new Error("Class [ "+e+" ] is already defined.");if(n=_type(e),("function"===n||"classConstructor"===n)&&_isDef(e.isConstructor))return e;if("string"!==n)throw new Error("class name should be a string");if(s=_type(t),"function"===s?(a=t.toString(),i=t(),o={className:e,source:t,str:a,obj:i}):(a="object",i={},forEach(t,function(e,t){i[t]=e.value}),o={className:e,source:_clone(t),str:a,obj:i},t=o),"function"!==s&&"object"!==s)throw new Error("Source for class creation must be inline function or specially prepared object.");var l=function(){var r=arguments,s=cls.create(e,t),n=fireConstructor(s,r);if("undefined"===_type(n))return s;if("clsClassFacade"===_type(n)){var a=n.getClassId(),i=getObject(a);return i.classInstance}return n};if(rget(l,"___type","class"),rget(l,"___source",t),rget(l,"___sourceObject",o),rget(l,"___className",e),rget(l,"___arguments",arguments),rget(l,"isConstructor",!0),rget(l,"extend",constructorExtend.bind(l)),rwget(l,"compressed",""),rget(l,"compress",compress.bind(l)),rget(l,"asObject",asObject.bind(l)),rget(l,"asString",asString.bind(l)),rget(l,"saveAsObject",saveAsObject.bind(l)),"function"===s)var u=parseComments(o,e,STATIC_METHOD_PROPERTY);else var u=getStaticFromObject(t,e);return rget(l,"___static",u),resolveStatic(u,l),__definedClasses[e]=l,"undefined"!=typeof window&&(window[e]=l),"undefined"!=typeof GLOBAL&&(GLOBAL[e]=l),l}function lockProperty(e,t){var r,s=getObject(t.getClassId()),n=s.classProperties;if(!_isDef(n[e]))throw new Error("Internal error: Wrong property name.");r=n[e],-1===r.declarations.indexOf("public")&&Object.defineProperty(t,e,{configureable:!1,enumerable:!1,get:function(){throw new Error("Property '"+e+"' is not public.")}})}function _create(e,t,r,s){var n,a=_guid(),i={},o={},c={},l={},u={},f="";if("string"!==_type(e))throw new Error("className should be a string "+_type(e)+" given.");return _isDef(t.___source)&&(t=t.___source),"function"===_type(t)?(u=t(),f=t.toString(),n={className:e,source:t,str:f,obj:u}):(u=t.obj,n=t),_isDef(r)||(r=new clsClassProperties),generateClassProperties(e,n,a,r),_isDef(s)||(s=new clsClassData(r)),o=new clsClassFacade(a,e),c=getClassPropertiesOf(r,"public",a),o.extend="",o.extendingFacade="",o.parent="",o.parentName="",o.inherits=[],o.child="",l.classId=a,l.classProperties=r,l.classFacade=o,l.classData=s,l.publicProperties=c,setObject(a,l),i=new clsClassInstance(a,e),l.classInstance=i,forEach(r,function(e,t){lockProperty(t,i),e.classId===o.getClassId()&&(_isDef(o[t])||o.___addProperty(t,e,!1))}),s.addClassFacade(a,o),forEach(c,function(e,t){i.___addPublicProperty(t)}),i}function getObject(e){return __allClasses[e]}function setObject(e,t){__allClasses[e]=t}function getClassObjectOfInstance(e){var t=e.getClassId(),r=getObject(t);return r}function getFacadeOfInstance(e){var t=e.getClassId(),r=getObject(t);return r.classFacade}function _instanceInherits(e){for(var t=[],r=getClassObjectOfInstance(e),s=r.classFacade,n=1e3;""!==s.parent&&n>=0;){""!==s.parent&&(r=getObject(s.parent),s=r.classFacade);var a=s.getClassId();t.push(a),n--}return t}function _extend(e,t,r,s){var n=(Array.prototype.slice.call(arguments),{}),a={},i={},o={},c={};_isDef(r)||(r=new clsClassProperties,s=new clsClassData(r)),o="class"===e.___type?_create(e.___className,e,r,s):_extend(e.___firstClass,e.___secondClass,r,s),c=getFacadeOfInstance(o),n="class"===t.___type?_create(t.___className,t,r,s):_extend(t.___firstClass,t.___secondClass,r,s),i=__allClasses[n.getClassId()],a=i.classFacade,a.extend=o.getClassId(),a.parent=o.getClassId(),a.parentName=o.getCurrentClassName(),a.inherits=_instanceInherits(n),a.child="";var l=a.getClassId();c.child=l;var u=n.getClassId();return forEach(r,function(e,t){e.classId!==u&&(a.___addProperty(t,e,!1),_typeIs(e,"public")&&n.___addPublicProperty(t))}),n}function arrayExtend(e){var t=e[0];return forEach(e,function(e,r){r>0&&(t=cls.extend(t,e))}),t}function constructorExtend(e,t){if("string"===_type(e)){var r=cls["class"](e,t);return cls.extend(this,r)}return cls.extend(this,e)}function isNode(){var e="undefined"!=typeof process&&"undefined"!=typeof module;return e?e=e&&_isDef(process.version)&&_isDef(module.exports):!1}function buildFile(e){console.log("Building from file:",e);var t=require("fs"),r=t.readFileSync(e,{encoding:"utf8"});__builded[e]=r}function buildForBrowser(){var e=process.argv,t="build.cls",r=["public/js/*.cls.js","public/js/**/*.cls.js"];if(e.indexOf("-o")>=0&&(t=e[e.indexOf("-o")+1]),e.indexOf("-f")>=0){var s=e[e.indexOf("-f")+1];r=s.split(",")}var n=require("readdir"),a=n.readSync("./",r);forEach(a,function(e){buildFile(e)}),__buildString=JSON.stringify(__builded),__buildData=LZString.compressToUint8Array(__buildString);var i=require("fs"),o=i.openSync(t,"w"),c=new Buffer(__buildData,"base64");i.writeSync(o,c,0,c.length),console.log("Done!")}function parseCommand(){var e=process.argv[2];switch(e){case"build":buildForBrowser()}}var cls=function(e,t,r){return cls.create(e,t,r)};cls.type=_type;var hasOwn=Object.prototype.hasOwnProperty,toString=Object.prototype.toString;cls.guid=_guid,cls["var"]=function(e,t){var r,s={},n="",a="",i=0,o=0,c="";for(_isDef(t)||(t=""),a=Object.keys(e),o=a.length;o>i;i++)n=a[i],r=e[n],c=_type(r),function(e,t,r,s,n,a){var i="",o=!0,c={};"object"===s||"function"===s?(c=cls["var"](n[r],a+"."+r),Object.defineProperty(e,r,{get:function(){return c},set:function(e){var t=_type(e);if(t!==s&&"anytype"!==s)throw a=a+"."+r,a=a.substr(1),new Error("Type mismatch. Object [ "+a+" ] should be an "+s+".\n'"+t+"' given.");o=checkObjectContentTypes(e,n[r],a+"."+r),o&&(n[r]=c)}})):Object.defineProperty(e,r,{get:function(){return n[r]},set:function(e){if(i=_type(e),i!==s&&"anytype"!==s)throw a=a+"."+r,a=a.substr(1),new Error("Type mismatch. Object [ "+a+" ] should be an "+s+",");n[r]=e}})}(s,r,n,c,e,t);return s};var COMMENT_BLOCK="\\/\\*\\*?\\s*([^\\/]+)",METHOD_REG="^\\s?\\@method[ \\t]+([^\\s]+)[ \\t]*(?:([^\\n \\t]+))?(?:[ \\t]+([^\\n]+))?\\s?$",PROPERTY_REG="^\\s?\\@property[ \\t]+\\{([^\\}]+)\\}[ \\t]+([^ \\t\\r\\n]+)[ \\t]*([^\\s\\*\\/]+)?(?:[ \\t]+([^\\n\\/]+))?$",RETURNS_REG="^\\@returns?[ \\t]+\\{([^\\}]+)\\}",STATIC_METHOD_PROPERTY="^\\s?\\@(method|property)[ \\t]+(?:\\{.*\\})?[ \\t]?(.*)(?:static)",METHOD_PROPERTY="^\\s?\\@(method|property)[ \\t]+(?:\\{[a-z0-9_\\$\\|]+\\})?[ \\t]?([a-z0-9_\\$]+)?(?:[ \\t]+([a-z]+))?",_isType=_typeIs;Object.defineProperty(clsClassInstance.prototype,"___addPublicProperty",{enumerable:!1,configureable:!1,get:function(){return ___addPublicProperty}}),clsClassProperties.prototype.propertyExists=function(e){return _isDef(this[e])},Object.defineProperty(clsClassFacade.prototype,"___addProperty",{enumerable:!1,configureable:!1,get:function(){return ___addProperty}}),Object.defineProperty(clsClassFacade.prototype,"addToInstance",{enumerable:!1,configureable:!1,get:function(){return addToInstance}}),Object.defineProperty(clsClassFacade.prototype,"mixWithObject",{enumerable:!1,configureable:!1,get:function(){return mixWithObject}}),Object.defineProperty(clsClassFacade.prototype,"getInternalProperty",{enumerable:!1,configureable:!1,get:function(){return getInternalProperty}}),Object.defineProperty(clsClassFacade.prototype,"getInternalProperties",{enumerable:!1,configureable:!1,get:function(){return getInternalProperties}}),clsClassData.prototype.addClassFacade=function(e,t){this.classFacades[e]=t},clsClassData.prototype.propertyExists=function(e){return _isDef(this.classProperties)&&_isDef(this.classProperties[e])},clsClassData.prototype.mixedWithOrChildOfPropertyOwner=function(e,t){var r=this.classFacades[e],s=this.classProperties[t];return e===r.getClassId()?!0:r.mixedWith.indexOf(s.classId)?!0:r.inherits.indexOf(s.classId)?!0:!1},clsClassData.prototype.get=function(e,t){function r(){var r=arguments;r=checkMethodArgTypes(i,t,r);var s=n.value.apply(a,r);return s=checkReturnValue(e,t,s)}var s=getName(e);if(!this.propertyExists(t))throw new Error("There is no property like "+t+" in "+s);var n=this.classProperties[t];if(_isDef(n)){if(n.classId===e){if("function"===_type(n.value)){var a=this.classFacades[e],i=getObject(e);return r}return n.value}if(_typeIs(n,"public")){getName(n.classId);return this.get(n.classId,t)}if(_isDef(e)&&_typeIs(n,"protected")&&this.mixedWithOrChildOfPropertyOwner(e,t)){getName(n.classId);return this.get(n.classId,t)}throw _isDef(e)&&_typeIs(n,"private")?new Error("Cannot access private properties of other classes."):new Error("Cannot access '"+t+"' from outside a class.")}},clsClassData.prototype.set=function(e,t,r,s){var n=getObject(e),a=n.classProperties[r].classId,i=n.classFacade,o=getObject(a),c=(o.classFacade,n.classProperties[r]);if("function"===_type(c.value)){if(_isType(c,"final"))throw new Error("Method '"+r+"' is declared as final and cannot be changed.")}else if(_isType(c,"const"))throw new Error("Property '"+r+"' is declared as const and cannot be changed.");if(checkPropertyType(e,t,s,r),e===a)n.classProperties[r].value=s;else{if(-1===i.inherits.indexOf(a))throw new Error("Cannot change property '"+r+"' only child classes can redefine properties.");n.classProperties[r].value=s}};var __definedClasses={},__allClasses={};cls.compress=function(e){if(_isDef(e.isConstructor))return e.compress();var t=fnToStrings(e),r=JSON.stringify(t),s=LZString.compressToUint8Array(r);return s},cls.decompress=function(e){if(e=LZString.decompressFromUint8Array(e),null===e)throw new Error("Cannot decompress file.");var t,r=JSON.parse(e);return t=_isDef(r.__compressedClass)?buildFromStringObjects(r.__compressedClass):StringsToFn(r)},cls["class"]=function(e,t){return _class(e,t,!1)},cls.create=function(e,t){return _create(e,t)};var getClassObjectOfFacade=getClassObjectOfInstance,__definedAllClasses={};cls.extend=function(e,t){if("array"===_type(e))return arrayExtend(e);var r=Array.prototype.slice.call(arguments);if(r.length>2)return arrayExtend(r);var s=function(){var r=arguments,s=_extend(e,t),n=fireConstructor(s,r);return"undefined"===_type(n)?s:n};rget(s,"___firstClass",e),rget(s,"___secondClass",t),rget(s,"___arguments",arguments),rget(s,"___type","extend"),rget(s,"___className",t.___className),rget(s,"isConstructor",!0),rget(s,"extend",constructorExtend.bind(s)),rwget(s,"compressed",""),rget(s,"compress",compress.bind(s)),rget(s,"asObject",asObject.bind(s)),rget(s,"asString",asString.bind(s)),rget(s,"saveAsObject",saveAsObject.bind(s));var n=_merge(e.___static,t.___static);return rget(s,"___static",n),resolveStatic(n,s),__definedAllClasses[t.___className]=s,s},cls.empty=function(e){return cls["class"](e,function(){return{}})},cls.getSingleClass=function(e){if(!_isDef(__definedClasses[e]))throw new Error("Cannot find [ "+e+" ] class.");return __definedClasses[e]},cls.getClass=function(e){if(_isDef(__definedAllClasses[e]))return __definedAllClasses[e];if(_isDef(__definedClasses[e]))return __definedClasses[e];throw new Error("Cannot find [ "+e+" ] class.")};var __classPath={},__debundledFiles={},__modules={};cls.loadBundle=function(){ajax.get("build.cls").done(function(e){var t=LZString.decompressFromUint8Array(e),r=JSON.parse(t);cls.deBundle(r)})},cls.deBundle=function deBundle(obj){forEach(obj,function(content,fileName){var exprt=content.replace("module.exports","cls.module.exports");if(cls.module={exports:void 0},eval(exprt),__modules[fileName]=cls.module.exports,_isDef(cls.module.exports)&&_isDef(cls.module.exports.isConstructor)){var className=cls.module.exports.___className;__definedAllClasses[className]=cls.module.exports,"undefined"!=typeof window&&(window[className]=cls.module.exports),"undefined"!=typeof GLOBAL&&(GLOBAL[className]=cls.module.exports)}}),console.log("debundled",__definedAllClasses)},cls.require=function(e){if(isNode())return require(e);var t=classNameFromPath(e);return cls.getClass(t)};var __builded={},__buildString="",__buildData,ajax={request:function(e){"string"==typeof e&&(e={url:e}),e.url=e.url||"",e.method=e.method||"get",e.data=e.data||{};var t=function(e,t){var r,s=[];for(var n in e)s.push(n+"="+encodeURIComponent(e[n]));return r=s.join("&"),""!==r?t?t.indexOf("?")<0?"?"+r:"&"+r:r:""},r={host:{},process:function(e){var r=this;return this.xhr=null,window.ActiveXObject?this.xhr=new ActiveXObject("Microsoft.XMLHTTP"):window.XMLHttpRequest&&(this.xhr=new XMLHttpRequest),this.xhr&&(this.xhr.responseType="arraybuffer",this.xhr.onreadystatechange=function(){if(4===r.xhr.readyState&&200===r.xhr.status){var e=new Uint8Array(r.xhr.response);
r.doneCallback&&r.doneCallback.apply(r.host,[e,r.xhr])}else 4===r.xhr.readyState&&r.failCallback&&r.failCallback.apply(r.host,[r.xhr]);r.alwaysCallback&&r.alwaysCallback.apply(r.host,[r.xhr])}),"get"===e.method?this.xhr.open("GET",e.url+t(e.data,e.url),!0):(this.xhr.open(e.method,e.url,!0),this.setHeaders({"X-Requested-With":"XMLHttpRequest","Content-type":"text/plain; charset=x-user-defined"})),e.headers&&"object"==typeof e.headers&&this.setHeaders(e.headers),setTimeout(function(){"get"===e.method?r.xhr.send():r.xhr.send(t(e.data))},20),this},done:function(e){return this.doneCallback=e,this},fail:function(e){return this.failCallback=e,this},always:function(e){return this.alwaysCallback=e,this},setHeaders:function(e){for(var t in e)this.xhr&&this.xhr.setRequestHeader(t,e[t])}};return r.process(e)},get:function(e,t){return this.request({url:e,data:t,method:"get"})},post:function(e,t){return this.request({url:e,data:t,method:"post"})}},LZString=function(){function e(e,t){if(!n[e]){n[e]={};for(var r=0;r<e.length;r++)n[e][e.charAt(r)]=r}return n[e][t]}var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={},a={compressToBase64:function(e){if(null==e)return"";var t=a._compress(e,6,function(e){return r.charAt(e)});switch(t.length%4){default:case 0:return t;case 1:return t+"===";case 2:return t+"==";case 3:return t+"="}},decompressFromBase64:function(t){return null==t?"":""==t?null:a._decompress(t.length,32,function(s){return e(r,t.charAt(s))})},compressToUTF16:function(e){return null==e?"":a._compress(e,15,function(e){return t(e+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:a._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=a.compress(e),r=new Uint8Array(2*t.length),s=0,n=t.length;n>s;s++){var i=t.charCodeAt(s);r[2*s]=i>>>8,r[2*s+1]=i%256}return r},decompressFromUint8Array:function(e){if(null===e||void 0===e)return a.decompress(e);for(var r=new Array(e.length/2),s=0,n=r.length;n>s;s++)r[s]=256*e[2*s]+e[2*s+1];var i=[];return r.forEach(function(e){i.push(t(e))}),a.decompress(i.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":a._compress(e,6,function(e){return s.charAt(e)})},decompressFromEncodedURIComponent:function(t){return null==t?"":""==t?null:(t=t.replace(/ /g,"+"),a._decompress(t.length,32,function(r){return e(s,t.charAt(r))}))},compress:function(e){return a._compress(e,16,function(e){return t(e)})},_compress:function(e,t,r){if(null==e)return"";var s,n,a,i={},o={},c="",l="",u="",f=2,p=3,d=2,_=[],h=0,y=0;for(a=0;a<e.length;a+=1)if(c=e.charAt(a),Object.prototype.hasOwnProperty.call(i,c)||(i[c]=p++,o[c]=!0),l=u+c,Object.prototype.hasOwnProperty.call(i,l))u=l;else{if(Object.prototype.hasOwnProperty.call(o,u)){if(u.charCodeAt(0)<256){for(s=0;d>s;s++)h<<=1,y==t-1?(y=0,_.push(r(h)),h=0):y++;for(n=u.charCodeAt(0),s=0;8>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1}else{for(n=1,s=0;d>s;s++)h=h<<1|n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n=0;for(n=u.charCodeAt(0),s=0;16>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1}f--,0==f&&(f=Math.pow(2,d),d++),delete o[u]}else for(n=i[u],s=0;d>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1;f--,0==f&&(f=Math.pow(2,d),d++),i[l]=p++,u=String(c)}if(""!==u){if(Object.prototype.hasOwnProperty.call(o,u)){if(u.charCodeAt(0)<256){for(s=0;d>s;s++)h<<=1,y==t-1?(y=0,_.push(r(h)),h=0):y++;for(n=u.charCodeAt(0),s=0;8>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1}else{for(n=1,s=0;d>s;s++)h=h<<1|n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n=0;for(n=u.charCodeAt(0),s=0;16>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1}f--,0==f&&(f=Math.pow(2,d),d++),delete o[u]}else for(n=i[u],s=0;d>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1;f--,0==f&&(f=Math.pow(2,d),d++)}for(n=2,s=0;d>s;s++)h=h<<1|1&n,y==t-1?(y=0,_.push(r(h)),h=0):y++,n>>=1;for(;;){if(h<<=1,y==t-1){_.push(r(h));break}y++}return _.join("")},decompress:function(e){return null==e?"":""==e?null:a._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(e,r,s){var n,a,i,o,c,l,u,f,p=[],d=4,_=4,h=3,y="",g=[],m={val:s(0),position:r,index:1};for(a=0;3>a;a+=1)p[a]=a;for(o=0,l=Math.pow(2,2),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;switch(n=o){case 0:for(o=0,l=Math.pow(2,8),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;f=t(o);break;case 1:for(o=0,l=Math.pow(2,16),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;f=t(o);break;case 2:return""}for(p[3]=f,i=f,g.push(f);;){if(m.index>e)return"";for(o=0,l=Math.pow(2,h),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;switch(f=o){case 0:for(o=0,l=Math.pow(2,8),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;p[_++]=t(o),f=_-1,d--;break;case 1:for(o=0,l=Math.pow(2,16),u=1;u!=l;)c=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=s(m.index++)),o|=(c>0?1:0)*u,u<<=1;p[_++]=t(o),f=_-1,d--;break;case 2:return g.join("")}if(0==d&&(d=Math.pow(2,h),h++),p[f])y=p[f];else{if(f!==_)return null;y=i+i.charAt(0)}g.push(y),p[_++]=i+y.charAt(0),d--,i=y,0==d&&(d=Math.pow(2,h),h++)}}};return a}();return isNode()&&(GLOBAL.cls=cls,process.argv.length>2&&parseCommand()),isNode()&&(module.exports=cls),cls}();