text: "use strict";!function(){if(Kekule.PROP_AUTO_TITLE){var e=ClassEx.getPrototype(ObjectEx).defineProp;ClassEx.getPrototype(ObjectEx).defineProp=function(t,r){if(!r.title&&!r.description){var n=this.getClassName();n.startsWith("Kekule.")&&(n=n.substr(7));var i="TITLE_"+t,o="DES_"+t,a=Kekule.Localization.findValue("OBJDEF_TEXTS."+n+"."+i),s=Kekule.Localization.findValue("OBJDEF_TEXTS."+n+"."+o);r.title=a,r.description=s}return e.apply(this,[t,r])}}Kekule.ExceptionLevel={ERROR:-1,WARNING:-2,NOTE:-3,LOG:-4,getAllLevels:function(){var e=Kekule.ExceptionLevel;return[e.ERROR,e.WARNING,e.NOTE,e.LOG]},levelToString:function(e){var t=Kekule.ExceptionLevel;return e===t.ERROR?"error":e===t.WARNING?"warning":e===t.NOTE?"note":"log"}},Kekule.ErrorLevel=Kekule.ExceptionLevel,Kekule.throwException=function(e,t){if(Kekule.exceptionHandler)return Kekule.exceptionHandler.throwException(e,t);var r=Kekule.ExceptionLevel;if(!t||t===r.ERROR)throw"string"==typeof e&&(e=new Kekule.Exception(e)),e;if("undefined"!=typeof console){"string"!=typeof e&&(e=e.message);var n=t===r.WARNING?console.warn:t===r.NOTE?console.info:console.log;n?n(e):console.log(e)}},Kekule.getExceptionMsg=function(e){return"string"==typeof e?e:"object"==typeof e?e.message:""},Kekule.raise=Kekule.throwException,Kekule.error=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.ERROR)},Kekule.chemError=function(e){return"string"==typeof e&&(e=new Kekule.ChemError(e)),Kekule.error(e)},Kekule.warn=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.WARNING)},Kekule.notify=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.NOTE)},Kekule.log=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.LOG)},Kekule.hasLocalRes=function(){return!!Kekule.LOCAL_RES},Kekule.globalOptions={add:function(e,t){var r=Object.getCascadeFieldValue(e,Kekule.globalOptions);r&&DataType.isObjectValue(r)&&DataType.isObjectValue(t)?Object.extend(r,t):Object.setCascadeFieldValue(e,t,Kekule.globalOptions,!0)}},Kekule.HashEx=Class.create({CLASS_NAME:"Kekule.HashEx",PROP_NAME_PREFIX:"__$key$__",initialize:function(){this._map={}},finalize:function(){this._map=null},keyToPropName:function(e){return this.PROP_NAME_PREFIX+e},has:function(e){return this._map.hasOwnProperty(this.keyToPropName(e))},set:function(e,t){return this._map[this.keyToPropName(e)]=t,this},get:function(e,t){var r=this.keyToPropName(e);return this._map.hasOwnProperty(r)?this._map[r]:t},remove:function(e){var t=this.keyToPropName(e);return this._map.hasOwnProperty(t)&&delete this._map[t],this},clear:function(){this._map={}}}),Kekule.MapEx=Class.create({CLASS_NAME:"Kekule.MapEx",initialize:function(e,t){this.isWeak=!e,Kekule.MapEx._inited||Kekule.MapEx._init();var r=e?Kekule.MapEx._implementationNonWeak:Kekule.MapEx._implementationWeak;r?this._implementation=new r:(this._keys=[],this._values=[]),t&&(this._cache={})},finalize:function(){this._implementation||(this._keys=null,this._values=null,this._cache=null)},set:function(e,t){if(this._implementation)this._implementation.set(e,t);else{var r=this._keys.indexOf(e);r>=0?this._values[r]=t:(this._keys.push(e),this._values.push(t))}return this._cache&&this._cache.key===e&&(this._cache.value=t),this},get:function(e,t){if(this._cache&&this._cache.key===e)return this._cache.value;var r,n=!1;if(this._implementation)this._implementation.has(e)&&(r=this._implementation.get(e),n=!0);else{var i=this._keys.indexOf(e);i>=0&&(r=this._values[i],n=!0)}return n&&this._cache&&(this._cache.key=e,this._cache.value=r),n?r:t},has:function(e){return this._implementation?this._implementation.has(e):this._keys.indexOf(e)>=0},remove:function(e){if(this._cache&&this._cache.key===e&&(this._cache={}),this._implementation)return this._implementation[!this._implementation||"delete"](e);var t=this._keys.indexOf(e);return t>=0&&(this._keys.splice(t,1),this._values.splice(t,1)),this},clear:function(){return this._cache&&(this._cache={}),this._implementation&&!this._debug||(this._keys=[],this._values=[]),this._implementation&&(this.isWeak?Kekule.error(Kekule.$L("ErrorMsg.CANNOT_CLEAR_WEAKMAP")):this._implementation.clear()),this},getKeys:function(){if(this._implementation){if(this.isWeak)return Kekule.error(Kekule.$L("ErrorMsg.CANNOT_GET_KEY_LIST_IN_WEAKMAP")),[];var e,t=this._implementation.keys();if(Array.from)e=Array.from(t);else if(t.next){e=[];for(var r=t.next();!r.done;)e.push(r.value),r=t.next()}else for(var n in e=[],t)e.push(n);return e}return[].concat(this._keys)},getValues:function(){if(this._implementation){if(this.isWeak)return Kekule.error(Kekule.$L("ErrorMsg.CANNOT_GET_VALUE_LIST_IN_WEAKMAP")),[];var e,t=this._implementation.values();if(Array.from)e=Array.from(t);else if(t.next){e=[];for(var r=t.next();!r.done;)e.push(r.value),r=t.next()}else for(var n in e=[],t)e.push(n);return e}return this._values},getLength:function(){return this.getKeys().length}}),Kekule.MapEx._init=function(){Kekule.MapEx._implementationWeak=null,Kekule.MapEx._implementationNonWeak=null,Kekule.$jsRoot.WeakMap&&(Kekule.MapEx._implementationWeak=Kekule.$jsRoot.WeakMap),Kekule.$jsRoot.Map&&Kekule.$jsRoot.Map.prototype.keys&&(Kekule.MapEx._implementationNonWeak=Kekule.$jsRoot.Map),Kekule.MapEx._inited=!0},Kekule.MapEx._inited=!1,Kekule.TwoTupleMapEx=Class.create({CLASS_NAME:"Kekule.TwoTupleMapEx",initialize:function(e,t){this.nonWeak=e,this.map=new Kekule.MapEx(e,t),t&&(this._level1Cache={})},finalize:function(){this._level1Cache=null,this.map.finalize()},getSecondLevelMap:function(e,t){if(e&&this._level1Cache&&e===this._level1Cache.key&&this._level1Cache.value)return this._level1Cache.value;var r=this.map.get(e);return!r&&t&&(r=new Kekule.MapEx(this.nonWeak),this.map.set(e,r)),r},set:function(e,t,r){return this.getSecondLevelMap(e,!0).set(t,r),this},get:function(e,t,r){var n=this.getSecondLevelMap(e,!1);return n?n.get(t,r):r},has:function(e,t){var r=this.getSecondLevelMap(e,!1);return!!r&&r.has(t)},remove:function(e,t){var r=this.getSecondLevelMap(e,!1);if(r)return r.remove(t)},clear:function(){this.map.clear(),this._level1Cache&&(this._level1Cache={})}}),Kekule.CoordMode={UNKNOWN:0,COORD2D:2,COORD3D:3},Kekule.ClassDefineUtils={CommonSizeMethods:{getSizeOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getSize3D(t):this.getSize2D(t)},setSizeOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setSize3D(e):this.setSize2D(e)},getBoxOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getBox3D(t):this.getBox2D(t)}},Size2DMethods:{fetchSize2D:function(){var e=this.getPropStoreFieldValue("size2D");return e||(e={},this.setPropStoreFieldValue("size2D",e)),e},notifySize2DChanged:function(e){this.notifyPropSet("size2D",e)},hasSize2D:function(e){var t=this.getPropStoreFieldValue("size2D"),r=t&&(void 0!==t.x||void 0!==t.y);return!r&&e&&(r=!!this.hasSize3D&&this.hasSize3D()),r},getBox2D:function(e){var t=this.getCoord2D(e)||{x:0,y:0},r=this.getSize2D(e);if(r&&(r.x||r.y)){var n={x:r.x,y:-r.y},i=Kekule.CoordUtils.add(t,n);return{x1:t.x,y1:t.y,x2:i.x,y2:i.y}}return{x1:t.x,y1:t.y,x2:t.x,y2:t.y}},get2DSizeX:function(e){var t=this.getSize2D(e);return t&&t.x||0},set2DSizeX:function(e){var t=this.fetchSize2D();t.x!=e&&(t.x=e,this.notifySize2DChanged(t))},get2DSizeY:function(e){var t=this.getSize2D(e);return t&&t.y||0},set2DSizeY:function(e){var t=this.fetchSize2D();t.y!=e&&(t.y=e,this.notifySize2DChanged(t))}},Size3DMethods:{fetchSize3D:function(){var e=this.getPropStoreFieldValue("size3D");return e||(e={},this.setPropStoreFieldValue("size3D",e)),e},notifySize3DChanged:function(e){this.notifyPropSet("size3D",e)},hasSize3D:function(e){var t=this.getPropStoreFieldValue("size3D"),r=t&&(void 0!==t.x||void 0!==t.y||void 0!==t.z);return!r&&e&&(r=!!this.hasSize2D&&this.hasSize2D()),r},getBox3D:function(e){var t=this.getCoord3D(e),r=this.getSize3D(e);if(t&&r){var n=Kekule.CoordUtils.add(t,r);return{x1:t.x,y1:t.y,z1:t.z,x2:n.x,y2:n.y,z2:n.z}}},get3DSizeX:function(e){var t=this.getSize3D(e);return t&&t.x||0},set3DSizeX:function(e){var t=this.fetchSize3D();t.x!=e&&(t.x=e,this.notifySize3DChanged(t))},get3DSizeY:function(e){var t=this.getSize3D(e);return t&&t.y||0},set3DSizeY:function(e){var t=this.fetchSize3D();t.y!=e&&(t.y=e,this.notifySize3DChanged(t))},get3DSizeZ:function(e){var t=this.getSize3D(e);return t&&t.z||0},set3DSizeZ:function(e){var t=this.fetchSize3D();t.z!=e&&(t.z=e,this.notifySize3DChanged(t))}},addStandardSizeSupport:function(e,t){ClassEx.extend(e,Kekule.ClassDefineUtils.CommonSizeMethods),(!t||t.indexOf("size2D")>=0)&&(ClassEx.defineProp(e,"size2D",{dataType:DataType.HASH,getter:function(e,t){var r=this.getPropStoreFieldValue("size2D");!r&&e&&this.hasSize3D()&&(r=this.getSize3D()),!r&&t&&(r={x:0,y:0},this.setPropStoreFieldValue("size2D",r));var n=r?{x:r.x,y:r.y}:void 0;return n&&(n=Kekule.CoordUtils.absValue(n)),n},setter:function(e){var t=this.fetchSize2D();void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),this.notifySize2DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Size2DMethods)),(!t||t.indexOf("size3D")>=0)&&(ClassEx.defineProp(e,"size3D",{dataType:DataType.HASH,getter:function(e,t){var r=this.getPropStoreFieldValue("size3D");return!r&&e&&this.hasSize2D()&&((r=this.getSize2D()).z=0),!r&&t&&(r={x:0,y:0,z:0},this.setPropStoreFieldValue("size3D",r)),r?{x:r.x,y:r.y,z:r.z}:void 0},setter:function(e){var t=this.fetchSize3D();void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),void 0!==e.z&&(t.z=e.z),this.notifySize3DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Size3DMethods))},CommonCoordMethods:{getCoordParent:function(e){return this.getParent&&this.getParent()||null},getCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getCoord3D(t):this.getCoord2D(t)},setCoordOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setCoord3D(e):this.setCoord2D(e)},getAbsCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getAbsCoord3D(t):this.getAbsCoord2D(t)},setAbsCoordOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setAbsCoord3D(e):this.setAbsCoord2D(e)},hasCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.hasCoord3D(t):this.hasCoord2D(t)},getIndirectCoordStorageOfMode:function(e){var t=this.getIndirectCoordStorage&&this.getIndirectCoordStorage();return t&&t[e]},setIndirectCoordStorageOfMode:function(e,t){var r=this.getIndirectCoordStorage&&this.getIndirectCoordStorage();return r&&(r[e]=t),this},calcIndirectCoordValue:function(e,t){var r=["x","y"];e===Kekule.CoordMode.COORD3D&&r.push("z");var n=this.getIndirectCoordStorage()[e],i=this.getIndirectCoordRefCoords(e,t);Kekule.ArrayUtils.isArray(i)&&(i=i[0]);var o=this.getIndirectCoordRefLengths(e,t);if(n&&i&&o){for(var a={},s=Kekule.ObjUtils.notUnset,l=0,u=r.length;l<u;++l){var h,c=r[l],d=n[c],f=i[c],p=o[c];if(s(d)&&s(f)&&s(p))h=0===p?f:f+p*d,a[c]=h}return a}return null},calcIndirectCoordStorage:function(e,t,r,n){var i=["x","y"];e===Kekule.CoordMode.COORD3D&&i.push("z");var o=this.getIndirectCoordStorageOfMode(e),a=this.getIndirectCoordRefCoords(e,n);Kekule.ArrayUtils.isArray(a)&&(a=a[0]);var s=this.getIndirectCoordRefLengths(e,n);if(o&&a&&s){for(var l={},u=Kekule.ObjUtils.notUnset,h=0,c=i.length;h<c;++h){var d,f=i[h],p=t[f],g=a[f],C=s[f];if(!(u(p)&&u(g)&&u(C)))return null;d=0!==C?(p-g)/C:1,l[f]=d}return l}return null},saveIndirectCoordValue:function(e,t,r,n){if(t){var i=this.calcIndirectCoordStorage(e,t,r,n);if(i)return this.setIndirectCoordStorageOfMode(e,i),i}return null},getIndirectCoordRefLengths:function(e,t){return null},getIndirectCoordRefCoords:function(e,t){return null}},Coord2DMethods:{fetchCoord2D:function(){var e=this.getPropStoreFieldValue("coord2D");return e||(e={},this.setPropStoreFieldValue("coord2D",e)),e},notifyCoord2DChanged:function(e){this.notifyPropSet("coord2D",e)},hasCoord2D:function(e){var t=this.getPropStoreFieldValue("coord2D"),r=t&&(void 0!==t.x||void 0!==t.y);return!r&&e&&(r=!!this.hasCoord3D&&this.hasCoord3D()),r},get2DX:function(e){var t=this.getCoord2D(e);return t&&t.x||0},set2DX:function(e){var t=this.fetchCoord2D();t.x!=e&&(t.x=e,this.notifyCoord2DChanged(t))},get2DY:function(e){var t=this.getCoord2D(e);return t&&t.y||0},set2DY:function(e){var t=this.fetchCoord2D();t.y!=e&&(t.y=e,this.notifyCoord2DChanged(t))}},Coord3DMethods:{fetchCoord3D:function(){var e=this.getPropStoreFieldValue("coord3D");return e||(e={},this.setPropStoreFieldValue("coord3D",e)),e},notifyCoord3DChanged:function(e){this.notifyPropSet("coord3D",e)},hasCoord3D:function(e){var t=this.getPropStoreFieldValue("coord3D"),r=t&&(void 0!==t.x||void 0!==t.y||void 0!==t.z);return!r&&e&&(r=!!this.hasCoord2D&&this.hasCoord2D()),r},get3DX:function(e){var t=this.getCoord3D(e);return t&&t.x||0},set3DX:function(e){var t=this.fetchCoord3D();t.x!=e&&(t.x=e,this.notifyCoord3DChanged(t))},get3DY:function(e){var t=this.getCoord3D(e);return t&&t.y||0},set3DY:function(e){var t=this.fetchCoord3D();t.y!=e&&(t.y=e,this.notifyCoord3DChanged(t))},get3DZ:function(e){var t=this.getCoord3D(e);return t&&t.z||0},set3DZ:function(e){var t=this.fetchCoord3D();t.z!=e&&(t.z=e,this.notifyCoord3DChanged(t))}},addStandardCoordSupport:function(e,t){ClassEx.extend(e,Kekule.ClassDefineUtils.CommonCoordMethods),(!t||t.indexOf("coord2D")>=0)&&(ClassEx.defineProp(e,"coord2D",{dataType:DataType.HASH,getter:function(e,t){if(this.getEnableIndirectCoord()){var r=this.calcIndirectCoordValue(Kekule.CoordMode.COORD2D,e);if(r)return r}var n=this.getPropStoreFieldValue("coord2D");return!n&&e&&this.hasCoord3D()&&(n=this.getCoord3D()),!n&&t&&(n={x:0,y:0},this.setPropStoreFieldValue("coord2D",n)),n?{x:n.x,y:n.y}:void 0},setter:function(e){var t=this.fetchCoord2D();this.getEnableIndirectCoord()&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD2D,e,t),void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),this.notifyCoord2DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Coord2DMethods)),(!t||t.indexOf("coord3D")>=0)&&(ClassEx.defineProp(e,"coord3D",{dataType:DataType.HASH,getter:function(e,t){if(this.getEnableIndirectCoord()){var r=this.calcIndirectCoordValue(Kekule.CoordMode.COORD2D,e);if(r)return r}var n=this.getPropStoreFieldValue("coord3D");return!n&&e&&this.hasCoord2D()&&((n=this.getCoord2D()).z=0),!n&&t&&(n={x:0,y:0,z:0},this.setPropStoreFieldValue("coord3D",n)),n?{x:n.x,y:n.y,z:n.z}:void 0},setter:function(e){var t=this.fetchCoord3D();this.getEnableIndirectCoord()&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD3D,e,t),void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),void 0!==e.z&&(t.z=e.z),this.notifyCoord3DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Coord3DMethods)),(!t||t.indexOf("absCoord2D")>=0)&&ClassEx.defineProp(e,"absCoord2D",{dataType:DataType.HASH,serializable:!1,getter:function(e){var t=this.getCoord2D(e)||{},r=this.getCoordParent(Kekule.CoordMode.COORD2D);return r&&r.getAbsCoord2D?Kekule.CoordUtils.add(t,r.getAbsCoord2D(e)||{}):{x:t.x,y:t.y}},setter:function(e,t){var r=e,n=this.getCoordParent(Kekule.CoordMode.COORD2D);n&&n.getAbsCoord2D&&(r=Kekule.CoordUtils.substract(e,n.getAbsCoord2D(t))),this.setCoord2D(r)}}),(!t||t.indexOf("absCoord3D")>=0)&&ClassEx.defineProp(e,"absCoord3D",{dataType:DataType.HASH,serializable:!1,getter:function(e){var t=this.getCoord3D(e)||{},r=this.getCoordParent(Kekule.CoordMode.COORD3D);return r&&r.getAbsCoord3D?Kekule.CoordUtils.add(t,r.getAbsCoord3D(e)||{}):{x:t.x,y:t.y,z:t.z}},setter:function(e,t){var r=e,n=this.getCoordParent(Kekule.CoordMode.COORD2D);n&&n.getAbsCoord3D&&(r=Kekule.CoordUtils.substract(e,n.getAbsCoord3D(t))),this.setCoord3D(r)}}),(!t||t.indexOf("enableIndirectCoord")>=0)&&ClassEx.defineProp(e,"enableIndirectCoord",{scope:Class.PropertyScope.PUBLIC,dataType:DataType.BOOL,serializable:!0,setter:function(e){if(this.getPropStoreFieldValue("enableIndirectCoord")!=e){if(e){var t=this.getCoord2D(),r=this.getCoord3D();t&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD2D,t,t,!0),r&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD3D,r,r,!0)}this.setPropStoreFieldValue("enableIndirectCoord",e)}}}),(!t||t.indexOf("indirectCoordStorage")>=0)&&ClassEx.defineProp(e,"indirectCoordStorage",{dataType:DataType.HASH,serializable:function(){return!!this.getEnableIndirectCoord()},setter:null,getter:function(){var e=this.getPropStoreFieldValue("indirectCoordStorage");return e||((e={})[Kekule.CoordMode.COORD2D]={},e[Kekule.CoordMode.COORD3D]={},this.setPropStoreFieldValue("indirectCoordStorage",e)),e}})},ExtraObjMapMethods:{getExtraProp:function(e,t){var r=this.getExtraObjMap().get(e);return r?t?r[t]:r:void 0},setExtraProp:function(e,t,r){var n;(n=this.getExtraProp(e))?n[t]=r:((n={})[t]=r,this.getExtraObjMap().set(e,n))},removeExtraProp:function(e,t){if(t){var r=this.getExtraProp(e);r[t]=void 0,delete r[t]}else this.getExtraObjMap().remove(e)}},addExtraObjMapSupport:function(e){ClassEx.defineProp(e,"extraObjMap",{dataType:"Kekule.MapEx",serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("extraObjMap");return e||(e=new Kekule.MapEx(!0,!0),this.setPropStoreFieldValue("extraObjMap",e)),e}}),ClassEx.extend(e,Kekule.ClassDefineUtils.ExtraObjMapMethods)},ExtraTwoTupleObjMapMethods:{getExtraProp2:function(e,t,r){var n=(this.__$__k__extraTwoTupleObjMap__$__||this.getExtraTwoTupleObjMap()).get(e,t);return n?r?n[r]:n:void 0},setExtraProp2:function(e,t,r,n){var i;(i=this.getExtraProp2(e,t))?i[r]=n:((i={})[r]=n,(this.__$__k__extraTwoTupleObjMap__$__||this.getExtraTwoTupleObjMap()).set(e,t,i))},removeExtraProp2:function(e,t,r){if(r){var n=this.getExtraProp2(e,t);n[r]=void 0,delete n[r]}else this.getExtraTwoTupleObjMap().remove(e,t)}},addExtraTwoTupleObjMapSupport:function(e){var t="extraTwoTupleObjMap";ClassEx.defineProp(e,t,{dataType:"Kekule.TwoTupleMapEx",serializable:!1,getter:function(){var e=this.getPropStoreFieldValue(t);return e||(e=new Kekule.TwoTupleMapEx(!0,!0),this.setPropStoreFieldValue(t,e),this.__$__k__extraTwoTupleObjMap__$__=e),e}}),ClassEx.extend(e,Kekule.ClassDefineUtils.ExtraTwoTupleObjMapMethods)}},Kekule.ObjPropSettingManager={_items:new Kekule.MapEx(!0),register:function(e,t){Kekule.ObjPropSettingManager._items.set(e,t)},unregister:function(e){Kekule.ObjPropSettingManager._items.remove(e)},getSetting:function(e){return Kekule.ObjPropSettingManager._items.get(e)}},ClassEx.defineProp(ObjectEx,"predefinedSetting",{dataType:DataType.STRING,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=Kekule.StrUtils.splitTokens(e||"",",");if(t.length){for(var r=0,n=t.length;r<n;++r){for(var i=this.getClass(),o=t[r],a=null,s="";i&&!a;){s=ClassEx.getClassName(i)+"."+o,a=Kekule.ObjPropSettingManager.getSetting(s);i=ClassEx.getSuperClass(i)}a||(a=Kekule.ObjPropSettingManager.getSetting(o)),a&&this.setPropValues(a)}this.setPropStoreFieldValue("predefinedSetting",s)}}}),Kekule.ObjectTreeOperation={MODIFY:0,ADD:1,REMOVE:2},Kekule.ChemObjInteractMode={DEFAULT:0,UNMOVABLE:1,UNSELECTABLE:2,HIDDEN:3},Kekule.ComparisonMethod={DEFAULT:0,PROPERTIES:1,CHEM_STRUCTURE:10},Kekule.ObjComparer={equal:function(e,t,r){return 0===Kekule.ObjComparer.compare(e,t,r)},compare:function(e,t,r){return Kekule.ObjComparer._compareValue(e,t,r)},_compareValue:function(e,t,r){var n=DataType;if(e===t)return 0;if(e<t&&!(e>t))return-1;if(e>t&&!(e<t))return 1;var i=null,o=n.getType(e),a=n.getType(t);if(o!==a){var s=[n.UNKNOWN,n.VARIANT,n.UNDEFINED,n.BOOL,n.NUMBER,n.INT,n.FLOAT,n.STRING,n.ARRAY,n.FUNCTION,n.DATE,n.OBJECT,n.OBJECTEX,n.CLASS],l=s.indexOf(o),u=s.indexOf(a);i=l<0&&u<0?null:l-u}else if(!e&&t)i=-1;else if(e&&!t)i=1;else if(e.doCompare)i=e.doCompare(t,r);else if(t.doCompare)i=-t.doCompare(e,r);else if(o===DataType.ARRAY){if(!(i=e.length-t.length))for(var h=0,c=e.length;h<c&&!(i=Kekule.ObjComparer._compareValue(e[h],t[h],r));++h);}else if(o===DataType.OBJECT){var d,f;i=(d=JSON.toString(e))<(f=JSON.toString(t))?-1:d>f?1:0}else i=null;return null===i&&null===(i=(d=e.toString&&e.toString()||"")<(f=t.toString&&t.toString()||"")?-1:d>f?1:null)&&(i=-1),i}};Kekule.ChemObject=Class.create(ObjectEx,{CLASS_NAME:"Kekule.ChemObject",initialize:function(e){this.tryApplySuper("initialize"),e&&this.setId(e),this.setBubbleEvent(!0),this.__load_owner_objRef_props__=null,this.__load_parent_objRef_props__=null,this.addEventListener("change",function(e){var t=this.getPropStoreFieldValue("srcInfo");if(t&&t.data){for(var r=e.target,n=e.changedPropNames,i=!1,o=0,a=n.length;o<a;++o){var s=n[o];if(s&&"srcInfo"!==s&&r.isPropertySerializable(s)){i=!0;break}if("[children]"===s){i=!0;break}}i&&(t.data=null)}},this)},doFinalize:function(){this.__load_owner_objRef_props__=null,this.__load_parent_objRef_props__=null,this.setPropStoreFieldValue("attachedCoordStickNodes",null),this.removeSelf(),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("id",{dataType:DataType.STRING}),this.defineProp("interactMode",{dataType:DataType.INT,enumSource:Kekule.ChemObjInteractMode}),this.defineProp("info",{dataType:DataType.HASH,getter:function(e){var t=this.getPropStoreFieldValue("info");return!t&&e&&(t={},this.setPropStoreFieldValue("info",t)),t}}),this.defineProp("scalarAttribs",{dataType:DataType.ARRAY,setter:null}),this.defineProp("parent",{dataType:"Kekule.ChemObject",serializable:!1,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getParent();t!==e&&(t&&t._removeChildObj&&(t._removeChildObj(this),this.invokeEvent("removeFromObjTree",{obj:this,parent:t})),this.setPropStoreFieldValue("parent",e),e&&e._appendChildObj&&(e._appendChildObj(this),this.invokeEvent("addToObjTree",{obj:this,parent:e})),this.parentChanged(e,t))}}),this.defineProp("owner",{dataType:"Kekule.ChemSpace",serializable:!1,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getOwner();t!==e&&(t&&(t._removeOwnedObj(this),this.invokeEvent("removeFromSpace",{obj:this,owner:t})),this.setPropStoreFieldValue("owner",e),e&&(e._appendOwnedObj(this),this.invokeEvent("addToSpace",{obj:this,owner:t})),this.ownerChanged(e,t))}}),this.defineProp("srcInfo",{dataType:DataType.OBJECT,serializable:!1,scope:Class.PropertyScope.PUBLISHED,getter:function(){var e=this.getPropStoreFieldValue("srcInfo");return e||(e={},this.setPropStoreFieldValue("srcInfo",e)),e}}),this.defineProp("isEditing",{dataType:DataType.BOOL,serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){var e=this.getOwner();return e&&e.getIsEditing?e.getIsEditing():this.getPropStoreFieldValue("isEditing")}}),this.defineProp("attachedCoordStickNodes",{dataType:DataType.ARRAY,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("attachedCoordStickNodes");return e||(e=[],this.setPropStoreFieldValue("attachedCoordStickNodes",e)),e}})},initPropValues:function(){this.tryApplySuper("initPropValues"),this.setEnableObjectChangeEvent(!0)},getHigherLevelObj:function(){return this.getParent()||this.getOwner()},getAutoIdPrefix:function(){return"o"},_parentObjectLoaded:function(e){this._handleObjRefProps(e,this.__load_parent_objRef_props__)},_ownerObjectLoaded:function(e){this._handleObjRefProps(e,this.__load_owner_objRef_props__)},_handleObjRefProps:function(e,t){var r=t;if(r&&e&&e.getChildAtIndexStack)for(var n=Kekule.ObjUtils.getOwnedFieldNames(r),i=0,o=n.length;i<o;++i){var a=n[i],s=r[a];if(DataType.isArrayValue(s)){var l=[];for(i=0,o=s.length;i<o;++i){if(c=this._doUnwrapObjRefSerializationStr(this,s[i])){var u=e.getChildAtIndexStack(c);l.push(u)}else l.push(void 0)}this.setPropValue(a,l)}else{var h,c;(c=this._doUnwrapObjRefSerializationStr(this,s))&&(h=e.getChildAtIndexStack(c)),h&&this.setPropValue(a,h)}try{delete r[a]}catch(e){}}},doSaveProp:function(e,t,r,n){if(t.serializable&&(e._doGetObjRefSerializationValue&&!!t.objRef)){var i="parent"===t.objRefRoot?e.getParent():e.getOwner();if(i){var o=e.getPropValue(t.name);if(o){if(Kekule.ArrayUtils.isArray(o)){for(var a=[],s=0,l=o.length;s<l;++s){var u=e._doGetObjRefSerializationValue(i,e,o[s]);u?a.push(u):a.push(o[s])}return n.doSaveFieldValue(e,t.name,a,r,n.getValueExplicitType(a)),!0}var h=e._doGetObjRefSerializationValue(i,e,o);if(h)return n.doSaveFieldValue(e,t.name,h,r,n.getValueExplicitType(h)),!0}}}},_doGetObjRefSerializationValue:function(e,t,r){var n=e.indexStackOfChild(r);return n&&n.length?"@"+JSON.stringify(n):null},doLoadProp:function(e,t,r,n){if(t.serializable&&!!t.objRef){var i="parent"===t.objRefRoot,o=i?e.__load_parent_objRef_props__:e.__load_owner_objRef_props__;o||(o={},i?e.__load_parent_objRef_props__=o:e.__load_owner_objRef_props__=o);var a=n.doLoadFieldValue(e,t.name,r);if(a){if("string"==typeof a&&a.startsWith("@"))return o[t.name]=a,!0;if(DataType.isArrayValue(a))return o[t.name]=a,!0}}},_doUnwrapObjRefSerializationStr:function(e,t){try{var r=t.substr(1),n=JSON.parse(r);return DataType.isArrayValue(n)?n:null}catch(e){Kekule.error(e)}},loaded:function(){this.tryApplySuper("loaded"),this.notifyParentLoaded()},notifyParentLoaded:function(){for(var e=0,t=this.getChildCount();e<t;++e){var r=this.getChildAt(e);r&&r._parentObjectLoaded&&r._parentObjectLoaded(this)}},isObjRefProperty:function(e){return!(!e||!e.objRef)},notifyPropSet:function(e,t,r){this.tryApplySuper("notifyPropSet",[e,t,r]);var n=this.getPropInfo(e);if(n&&this.isObjRefProperty(n)){var i=this.getOwner();i&&i.modifyObjRefRelation&&i.modifyObjRefRelation(this,n,this.getPropValue(n.name))}},getObjRefProperties:function(){for(var e=[],t=this.getAllPropList(),r=0,n=t.getLength();r<n;++r){var i=t.getPropInfoAt(r);this.isObjRefProperty(i)&&e.push(i)}return e},_registerObjRefRelations:function(e){if(e&&e.modifyObjRefRelation){var t=this.getObjRefProperties();if(t.length)for(var r=0,n=t.length;r<n;++r){var i=t[r],o=this.getPropValue(i.name);e.modifyObjRefRelation(this,i,o)}}},_unregisterObjRefRelations:function(e){if(e&&e.releaseObjRefRelation){var t=this.getObjRefProperties();if(t.length)for(var r=0,n=t.length;r<n;++r){var i=t[r];e.releaseObjRefRelation(this,i)}}},isSelectable:function(){var e=Kekule.ChemObjInteractMode;return!((this.getInteractMode()||e.DEFAULT)&e.UNSELECTABLE)},isMovable:function(){var e=Kekule.ChemObjInteractMode;return!((this.getInteractMode()||e.DEFAULT)&e.UNMOVABLE)},getNearestSelectableObject:function(){return this.isSelectable()?this:this.getParent()?this.getParent().getNearestSelectableObject():null},getNearestMovableObject:function(){return this.isMovable()?this:this.getParent()?this.getParent().getNearestMovableObject():null},getNearestAncestorOfType:function(e){var t=this.getParent();return t?t instanceof e?t:t.getNearestAncestorOfType?t.getNearestAncestorOfType(e):null:null},removeSelf:function(){this.setParent(null),this.setOwner(null)},notifyScalarAttribsChange:function(){this.notifyPropSet("scalarAttribs",this.getPropStoreFieldValue("scalarAttribs"))},notifyInfoChange:function(){this.notifyPropSet("info",this.getPropStoreFieldValue("info"))},_removeChildObj:function(e){this._notifyOwnerObjTreeOperation(e,this,Kekule.ObjectTreeOperation.REMOVE)},_appendChildObj:function(e){this._notifyOwnerObjTreeOperation(e,this,Kekule.ObjectTreeOperation.ADD)},_notifyOwnerObjTreeOperation:function(e,t,r){var n=this.getOwner();n&&n._notifyObjTreeOperation&&n._notifyObjTreeOperation(e,t,r)},objTreeOfOwnerUpdated:function(e,t,r){},objSpaceOfOwnerUpdated:function(e,t,r){},ownerChanged:function(e,t){for(var r=0,n=this.getScalarAttribCount();r<n;++r)this.getScalarAttribAt(r).setOwner(e);for(r=0,n=this.getChildCount();r<n;++r){var i=this.getChildAt(r);i&&i.setOwner&&i.setOwner(e)}},parentChanged:function(e,t){},getParentList:function(){var e=[],t=this.getParent();return t&&(t.getParentList&&(e=t.getParentList()||[]),e.unshift(t)),e},isChildOf:function(e){for(var t=this.getParent();t&&t!==e;)t=t.getParent?t.getParent():null;return!!t},getNextSibling:function(){var e=this.getParent();return e&&e.getNextSiblingOfChild?e.getNextSiblingOfChild(this):null},isSiblingWith:function(e){var t=this.getParent(),r=e.getParent&&e.getParent();return t&&r&&t===r},getChildHolder:function(){return this},getChildSubgroupNames:function(){return[]},getBelongChildSubGroupName:function(e){return null},_getPrevSubgroupChildrenCount:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=0,i=t.length;n<i;++n){if(t[n]===e)return r;var o=this._getSubGroupChildCountMethod(t[n]);r+=o&&o.apply(this)||0}return r},_getSubgroupChildIndexInfoFromChildIndex:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=0,i=t.length;n<i;++n){var o=this._getSubGroupChildCountMethod(t[n]),a=o&&o.apply(this)||0;if(e<r+a)return{name:t[n],index:e-r};r+=a}return null},_getSubGroupChildCountMethod:function(e){return this["get"+e.upperFirst()+"Count"]},_getSubGroupChildAtMethod:function(e){return this["get"+e.upperFirst()+"At"]},_getSubGroupChildIndexOfMethod:function(e){return this["indexOf"+e.upperFirst()]},_getSubGroupChildRemoveMethod:function(e){return this["remove"+e.upperFirst()]},_getSubGroupChildRemoveAtMethod:function(e){return this["remove"+e.upperFirst()+"At"]},_getSubGroupChildAppendMethod:function(e){return this["append"+e.upperFirst()]},_getSubGroupChildInsertBeforeMethod:function(e){return this["insert"+e.upperFirst()+"Before"]},_getSubGroupChildInsertAtMethod:function(e){return this["insert"+e.upperFirst()+"At"]},_ensureSubGroupChildMethodsExist:function(){for(var e=["_getSubGroupChildCountMethod","_getSubGroupChildAtMethod","_getSubGroupChildIndexOfMethod","_getSubGroupChildRemoveMethod","_getSubGroupChildRemoveAtMethod","_getSubGroupChildInsertBeforeMethod","_getSubGroupChildInsertAtMethod"],t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r)for(var i=0,o=e.length;i<o;++i){this[e[i]].apply(this,[t[r]])||Kekule.warn("Subgroup child method not exisits: "+e[i]+" / "+this.getClassName())}},getChildCount:function(){var e=this.getChildHolder();return e&&e!==this?e.getChildCount():this.doGetChildCount()},doGetChildCount:function(){for(var e=0,t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r){var i=this._getSubGroupChildCountMethod(t[r]);i&&(e+=i.apply(this))}return e},getChildAt:function(e){var t=this.getChildHolder();return t&&t!==this?t.getChildAt(e):this.doGetChildAt(e)},doGetChildAt:function(e){var t=this._getSubgroupChildIndexInfoFromChildIndex(e);if(t){var r=this._getSubGroupChildAtMethod(t.name);return r&&r.apply(this,[t.index])}return null},indexOfChild:function(e){var t=this.getChildHolder();return t&&t!==this?t.indexOfChild(e):this.doIndexOfChild(e)},doIndexOfChild:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r){var i=this._getSubGroupChildIndexOfMethod(t[r]);if(i){var o=i.apply(this,[e]);if(o>=0)return this._getPrevSubgroupChildrenCount(t[r])+o}}return-1},hasChild:function(e){return this.indexOfChild(e)>=0},filterChildren:function(e,t){for(var r=[],n=0,i=this.getChildCount();n<i;++n){var o=this.getChildAt(n);if(o)if(e(o,n))r.push(o);else if(t&&o.filterChildren){var a=o.filterChildren(e,t);a&&a.length&&(r=r.concat(a))}}return r},iterateChildren:function(e,t){for(var r=0,n=this.getChildCount();r<n;++r){var i=this.getChildAt(r);i&&(e(i,r),t&&i.iterateChildren&&i.iterateChildren(e,t))}},removeChildAt:function(e){return this.doRemoveChildAt(e)},doRemoveChildAt:function(e){var t=this._getSubgroupChildIndexInfoFromChildIndex(e);if(t){var r=this._getSubGroupChildRemoveAtMethod(t.name);return r&&r.apply(this,[t.index])}return null},removeChild:function(e){var t=this.getChildHolder();return t&&t!==this?t.removeChild(e):this.doRemoveChild(e)},doRemoveChild:function(e){for(var t,r=this.getChildSubgroupNames(),n=0,i=r.length;n<i;++n){var o=this._getSubGroupChildRemoveMethod(r[n]);if(o&&(t=o.apply(this,[e])))return t}return null},removeChildren:function(e){for(var t=e.length-1;t>=0;--t)this.removeChild(e[t])},insertChildAt:function(e,t){var r=this.getChildHolder();return r&&r!==this?r.insertChildAt(e,t):this.doInsertChildAt(e,t)},doInsertChildAt:function(e,t){if(t>=this.getChildCount())return this.appendChild(e);var r=this._getSubgroupChildIndexInfoFromChildIndex(t);if(r){var n=this._getSubGroupChildInsertAtMethod(r.name);if(n){var i=n.apply(this,[e,r.index]);if(i>=0)return this._getPrevSubgroupChildrenCount(r.name)+i}}return-1},insertBefore:function(e,t){return this.insertChildBefore(e,t)},insertChildBefore:function(e,t){var r=this.getChildHolder();return r&&r!==this?r.insertChildBefore(e,t):this.doInsertChildBefore(e,t)},doInsertChildBefore:function(e,t){var r=this.getBelongChildSubGroupName(e);if(!r)return-1;if(t&&r!==this.getBelongChildSubGroupName(t))return-1;this.getChildSubgroupNames();var n=this._getSubGroupChildInsertBeforeMethod(r);return n?this._getPrevSubgroupChildrenCount(r)+n.apply(this,[e,t]):-1},appendChild:function(e){return this.insertChildBefore(e,null)},appendChildren:function(e){for(var t=0,r=e.length;t<r;++t)this.appendChild(e[t])},cascadeOnChildren:function(e){if(!e)return this;for(var t=0,r=this.getChildCount();t<r;++t){var n=this.getChildAt(t);n.cascadeOnChildren&&n.cascadeOnChildren(e),e(n)}return this},cascade:function(e){return e?(this.cascadeOnChildren(e),e(this),this):this},indexStackOfChild:function(e){var t=e.getParentList&&e.getParentList(),r=-1;if(t&&t.length&&(r=t.indexOf(this)),r<0)return null;for(var n,i=[],o=this,a=r-1;a>=0;--a){var s=t[a];if(!((n=o.indexOfChild(s))>=0))return null;i.push(n),o=s}return(n=o.indexOfChild(e))>=0?(i.push(n),i):null},getChildAtIndexStack:function(e){if(!e)return null;if((e=Kekule.ArrayUtils.toArray(e)).length<=0)return null;for(var t=this.getChildAt(e[0]),r=1,n=e.length;r<n;++r){if(!t||!t.getChildAt)return null;t=t.getChildAt(e[r])}return t},isEmpty:function(){return!1},clearIds:function(){this.setId(void 0);for(var e=0,t=this.getChildCount();e<t;++e){var r=this.getChildAt(e);r.clearIds&&r.clearIds()}},assignTo:function(e,t){var r=this.tryApplySuper("assignTo",[e]);return!t&&e.clearIds&&e.clearIds(),r},assign:function(e,t){return e.assignTo(this,t)},clone:function(e){var t=new(this.getClass());return this.assignTo(t,e),t},getScalarAttribCount:function(){var e=this.getScalarAttribs();return e?e.length:0},getScalarAttribAt:function(e){var t=this.getScalarAttribs();return t?t[e]:null},appendScalarAttrib:function(e){this.getScalarAttribs()||this.setPropStoreFieldValue("scalarAttribs",[]);var t=Kekule.ArrayUtils.pushUniqueEx(this.getScalarAttribs(),e);return t.isPushed&&(e.setParent(this),this.notifyScalarAttribsChange()),t.index},removeScalarAttribAt:function(e){if(this.getScalarAttribs()){var t=Kekule.ArrayUtils.removeAt(this.getScalarAttribs(),e);return t&&(t.setParent(null),this.notifyScalarAttribsChange()),t}return null},removeScalarAttrib:function(e){if(this.getScalarAttribs()){var t=Kekule.ArrayUtils.remove(this.getScalarAttribs(),e);return t&&(t.setParent(null),this.notifyScalarAttribsChange()),t}return null},getInfoKeys:function(){return this.getInfo()?Kekule.ObjUtils.getOwnedFieldNames(this.getInfo()):[]},getInfoValue:function(e){return this.getInfo()?this.getInfo()[e]:null},setInfoValue:function(e,t){this.doGetInfo(!0)[e]=t,this.notifyInfoChange()},getContainerBox:function(e,t){if(this.getAbsCoordOfMode){var r=this.getAbsCoordOfMode(e,t)||{},n=r;if(this.getSizeOfMode){var i=this.getSizeOfMode(e,t)||{};if(e===Kekule.CoordMode.COORD3D)n=Kekule.CoordUtils.add(r,this.getSizeOfMode(e,t)||{});else n={x:r.x+i.x,y:r.y-i.y}}return Kekule.BoxUtils.createBox(r,n)}return null},equal:function(e,t){return 0===this.compare(e,t)},compare:function(e,t){if(e===this)return 0;if(!e)return 1;var r,n=this.doGetActualCompareOptions(t);return 0===(r=n.customMethod?n.customMethod(this,e,n):this.doCompare(e,n))?0:r<0?-1:1},doGetActualCompareOptions:function(e){return e||{}},doCompare:function(e,t){if(e===this)return 0;if(this.getClass()!==(e.getClass&&e.getClass()))return this.getClassName()<(e.getClassName&&e.getClassName()||"")?-1:1;var r=this.doCompareOnProperties(e,t);if(!r&&t.extraComparisonProperties)for(var n=0,i=t.extraComparisonProperties.length;n<i;++n){var o=t.extraComparisonProperties[n];if(this.hasProperty(o)&&e.hasProperty&&e.hasProperty(o)){var a=this.getPropValue(o),s=e.getPropValue(o);if(!(r=this.doCompareOnValue(a,s,t)))break}}return r},doCompareOnProperties:function(e,t){var r;t.properties?r=t.properties:(r=this.doGetComparisonPropNames(t))||(r=this.doGetDefaultComparisonPropNames());for(var n=0,i=0,o=r.length;i<o;++i)if(0!==(n=this.doCompareProperty(e,r[i],t)))return n;return 0},doGetComparisonPropNames:function(e){return null},doGetDefaultComparisonPropNames:function(){for(var e=[],t=this.getPropListOfScopes([Class.PropertyScope.PUBLIC,Class.PropertyScope.PUBLISHED]),r=0,n=t.getLength();r<n;++r){var i=t.getPropInfoAt(r);e.push(i.name)}return e},doCompareProperty:function(e,t,r){var n=e.getPropValue&&e.getPropValue(t),i=this.getPropValue(t);return i===n?0:this.doCompareOnValue(i,n,r)},doCompareOnValue:function(e,t,r){return Kekule.ObjComparer._compareValue(e,t,r)},attachCoordStickNodes:function(e){var t=Kekule.ArrayUtils,r=t.toArray(e),n=this.getAttachedCoordStickNodes();return t.pushUnique(n,r),this},detachCoordStickNodes:function(e){for(var t=Kekule.ArrayUtils,r=t.toArray(e),n=this.getAttachedCoordStickNodes(),i=0,o=r.length;i<o;++i)t.remove(n,r[i]);return this}}),Kekule.Scalar=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.Scalar",initialize:function(e,t,r,n){this.tryApplySuper("initialize",[e]),t&&this.setName(t),void 0!==r&&this.setValue(r),n&&this.setUnit(n)},initProperties:function(){this.defineProp("name",{dataType:DataType.STRING}),this.defineProp("value",{dataType:DataType.PRIMARY}),this.defineProp("errorValue",{dataType:DataType.PRIMARY}),this.defineProp("unit",{dataType:DataType.STRING}),this.defineProp("title",{dataType:DataType.STRING})}}),Kekule.ChemObjList=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemObjList",initialize:function(e,t,r){this.tryApplySuper("initialize",[e]),this.setPropStoreFieldValue("itemBaseClass",t),this.setPropStoreFieldValue("items",[]),this._transparent=!!r},initProperties:function(){this.defineProp("itemBaseClass",{dataType:DataType.CLASS,serializable:!1,scope:Class.PropertyScope.PUBLIC}),this.defineProp("items",{dataType:DataType.ARRAY,scope:Class.PropertyScope.PUBLIC,setter:null,getter:function(e){var t=this.getPropStoreFieldValue("items");return!t&&e&&(t=[],this.setPropStoreFieldValue("items",t)),t}})},loaded:function(){this.ownerChanged(this.getOwner()),this.parentChanged(this.getParent()),this.tryApplySuper("loaded")},parentChanged:function(e,t){this.changeAllItemsParent(),this.tryApplySuper("parentChanged",[e,t])},isEmpty:function(){return this.getItemCount()<=0},isValidItemType:function(e){var t=this.getItemBaseClass();return!t||e instanceof t},checkItemType:function(e){var t=this.isValidItemType(e);return t||Kekule.raise(Kekule.$L("ErrorMsg.LIST_ITEM_CLASS_MISMATCH")),t},notifyItemsChange:function(){this.notifyPropSet("items",this.getPropStoreFieldValue("items"))},getItemOwner:function(){return this.getOwner()},changeAllItemsOwner:function(){var e=this.getItems();if(e)for(var t=this.getItemOwner(),r=0,n=e.length;r<n;++r){var i=e[r];i&&i.setOwner&&i.setOwner(t)}},getItemParent:function(){return this._transparent&&this.getParent()||this},changeAllItemsParent:function(){var e=this.getItems();if(e)for(var t=this.getItemParent(),r=0,n=e.length;r<n;++r){var i=e[r];i&&i.setParent&&i.setParent(t)}},getItemCount:function(){var e=this.getPropStoreFieldValue("items");return e?e.length:0},getItemAt:function(e){var t=this.getPropStoreFieldValue("items");return t?t[e]:null},indexOf:function(e){var t=this.getPropStoreFieldValue("items");return t?t.indexOf(e):-1},indexOfItem:function(e){return this.indexOf(e)},getNextSiblingOfChild:function(e){var t=this.indexOf(e);return t>=0?this.getItemAt(t+1):null},getChildSubgroupNames:function(){return["item"].concat(this.tryApplySuper("getChildSubgroupNames"))},getBelongChildSubGroupName:function(e){return this.isValidItemType(e)?"item":this.tryApplySuper("getBelongChildSubGroupName",[e])},append:function(e){if(this.checkItemType(e),e){var t=Kekule.ArrayUtils.pushUniqueEx(this.doGetItems(!0),e);return t.isPushed&&(this.notifyItemsChange(),e.setOwner&&e.setOwner(this.getItemOwner()),e.setParent&&e.setParent(this.getItemParent())),t.index}return-1},insert:function(e,t){if(this.checkItemType(e),e){var r=Kekule.ArrayUtils.insertUniqueEx(this.doGetItems(!0),e,t);return r.isInserted&&(this.notifyItemsChange(),e.setOwner&&e.setOwner(this.getItemOwner()),e.setParent&&e.setParent(this.getItemParent())),r.index}return-1},insertItemAt:function(e,t){return this.insert(e,t)},insertItemBefore:function(e,t){if(t){var r=this.indexOfItem(t);return r>=0?this.insertItemAt(e,r):this.appendItem(e)}return this.append(e)},removeAt:function(e){if(this.getItems()){var t=Kekule.ArrayUtils.removeAt(this.getItems(),e);return t&&(t.setOwner&&t.setOwner(null),t.setParent&&t.setParent(null),this.notifyItemsChange()),t}},removeItemAt:function(e){return this.removeAt(e)},remove:function(e){if(this.getItems()){var t=Kekule.ArrayUtils.remove(this.getItems(),e);return t&&(t.setOwner&&t.setOwner(null),t.setParent&&t.setParent(null),this.notifyItemsChange()),t}},removeItem:function(e){return this.remove(e)},toArray:function(){return this.getItems()||[]},getContainerBox:function(e,t){for(var r,n=this.toArray(),i=0,o=n.length;i<o;++i){var a=n[i],s=a.getContainerBox?a.getContainerBox(e,t):null;s&&(r=r?Kekule.BoxUtils.getContainerBox(r,s):Kekule.BoxUtils.clone(s))}return r}}),Kekule.ChemSpaceElement=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemSpaceElement",initialize:function(e){this.tryApplySuper("initialize",[e]);var t=new Kekule.ChemObjList(null,Kekule.ChemObject,!0);t.setParent(this),t.addEventListener("change",function(){this.objectChange(["children"])},this),this.setPropStoreFieldValue("children",t)},initProperties:function(){this.defineProp("children",{dataType:"Kekule.ChemObjList",scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getChildren();t&&t.finalize(),e&&(e.setParent(this),e.setOwner(this.getOwner()),e._transparent=!0),this.setPropStoreFieldValue("children",e)}})},loaded:function(){var e=this.getChildren();e&&(e.parentChanged(this),e.ownerChanged(this.getOwner())),this.tryApplySuper("loaded")},ownerChanged:function(e,t){this.getChildren().setOwner(e),this.tryApplySuper("ownerChanged",[e,t])},_removeChildObj:function(e){var t=this.indexOfChild(e);t>=0&&this.removeChildAt(t),this.tryApplySuper("_removeChildObj",[e])},getChildHolder:function(){return this.getChildren()},getNextSiblingOfChild:function(e){return this.getChildren().getNextSiblingOfChild(e)},insertChild:function(e,t){return this.getChildren().insert(e,t)}}),Kekule.ChemSpace=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemSpace",initialize:function(e){this.tryApplySuper("initialize",[e]),this._autoIdMap={},this._enableObjRefRelations=!0,this._autoUpdateObjRefRelations=!0,this.setPropStoreFieldValue("enableAutoId",!0),this.setPropStoreFieldValue("ownedObjs",[]);var t=new Kekule.ChemSpaceElement;this.setPropStoreFieldValue("root",t),this.setPropStoreFieldValue("objRefRelationManager",new Kekule.ObjRefRelationManager(this)),t.setParent(this),t.setOwner(this)},initProperties:function(){this.defineProp("ownedObjs",{dataType:DataType.ARRAY,serializable:!1,setter:null,scope:Class.PropertyScope.PUBLIC}),this.defineProp("root",{dataType:"Kekule.ChemSpaceElement",setter:null}),this.defineProp("enableAutoId",{dataType:DataType.BOOL}),this.defineProp("objScreenLengthRatio",{dataType:DataType.FLOAT,serializable:!1,scope:Class.PropertyScope.PRIVATE}),this.defineProp("screenSize",{dataType:DataType.HASH,getter:function(){var e=this.getPropStoreFieldValue("screenSize")||{};return{x:e.x,y:e.y}},setter:function(e){var t=this.getPropStoreFieldValue("screenSize");t||(t={},this.setPropStoreFieldValue("screenSize",t)),t.x=e.x,t.y=e.y}}),this.defineProp("objRefRelationManager",{dataType:"Kekule.ObjRefRelationManager",serializable:!1,scope:Class.PropertyScope.PRIVATE,setter:null})},loaded:function(){var e=this.getRoot();e&&(e.setParent(this),e.setOwner(this)),this.tryApplySuper("loaded"),this.notifyOwnerLoaded()},notifyOwnedObjsChange:function(){this.notifyPropSet("ownedObjs",this.getPropStoreFieldValue("ownedObjs"))},_notifyOwnedObjsSpaceUpdate:function(e,t,r){for(var n=0,i=this.getOwnedObjCount();n<i;++n){var o=this.getOwnedObjAt(n);o&&o.objSpaceOfOwnerUpdated&&o.objSpaceOfOwnerUpdated(e,t,r)}if(this._enableObjRefRelations&&this._autoUpdateObjRefRelations&&r===Kekule.ObjectTreeOperation.REMOVE){var a=Kekule.ArrayUtils,s=this.findObjRefRelations({dest:e})||[];for(n=0,i=s.length;n<i;++n){var l=s[n];if(l.srcProp.autoUpdate){var u=l.dest,h=a.isArray(u)?a.exclude(u,[e]):null;l.srcObj.setPropValue(l.srcProp.name,h)}}}},notifyOwnerLoaded:function(){for(var e=this.getOwnedObjs()||[],t=0,r=e.length;t<r;++t){var n=e[t];n&&n._ownerObjectLoaded&&n._ownerObjectLoaded(this)}},getChildren:function(){return this.getRoot().getChildren().toArray()},getChildHolder:function(){return this.getRoot()},getNextSiblingOfChild:function(e){return this.getRoot().getNextSiblingOfChild(e)},insertChild:function(e,t){return this.getRoot().insertChild(e,t)},indexStackOfChild:function(e){return this.getRoot().indexStackOfChild(e)},getChildAtIndexStack:function(e){return this.getRoot().getChildAtIndexStack(e)},getObjById:function(e){for(var t=0,r=this.getOwnedObjCount();t<r;++t){var n=this.getOwnedObjAt(t);if(n.getId&&n.getId()===e)return n}return null},getAutoId:function(e,t){r=e&&e.getAutoIdPrefix?e.getAutoIdPrefix():"o";var r=e.getAutoIdPrefix?e.getAutoIdPrefix():"o";n=Kekule.ObjUtils.notUnset(t)?t:1;var n=this._getAutoIdIndex(r,n);return this._autoIdMap[r]=n,r+Number(n).toString()},_getAutoIdIndex:function(e,t){for(var r=t||0,n=e+Number(r).toString();this.getObjById(n);)++r,n=e+Number(r).toString();return r},assignAutoIdToObj:function(e){if(e.setId){var t=this.getAutoId(e);e.setId(t)}},getOwnedObjCount:function(){return this.getOwnedObjs().length},getOwnedObjAt:function(e){return this.getOwnedObjs()[e]},indexOfOwnedObj:function(e){return this.getOwnedObjs().indexOf(e)},_appendOwnedObj:function(e){this.indexOfOwnedObj(e)>=0||(this.getEnableAutoId()&&e.getId&&!e.getId()&&this.assignAutoIdToObj(e),this.getOwnedObjs().push(e),e._registerObjRefRelations&&e._registerObjRefRelations(this),this._notifyOwnedObjsSpaceUpdate(e,this,Kekule.ObjectTreeOperation.ADD),this.notifyOwnedObjsChange())},_removeOwnedObjAt:function(e){var t=this.getOwnedObjAt(e);t&&(this.getOwnedObjs().splice(e,1),t._unregisterObjRefRelations&&t._unregisterObjRefRelations(this),this._notifyOwnedObjsSpaceUpdate(t,this,Kekule.ObjectTreeOperation.REMOVE),this.notifyOwnedObjsChange())},_removeOwnedObj:function(e){var t=this.getOwnedObjs().indexOf(e);t>=0&&this._removeOwnedObjAt(t)},_notifyObjTreeOperation:function(e,t,r){for(var n=0,i=this.getOwnedObjCount();n<i;++n){var o=this.getOwnedObjAt(n);o.objTreeOfOwnerUpdated&&o.objTreeOfOwnerUpdated(e,t,r)}},getObjRefRelations:function(){return this._enableObjRefRelations?this.getObjRefRelationManager().getRelations():null},createObjRefRelation:function(e,t,r){return this._enableObjRefRelations?this.getObjRefRelationManager().createRelation(e,t,r):null},modifyObjRefRelation:function(e,t,r){return this._enableObjRefRelations?this.getObjRefRelationManager().modifyRelation(e,t,r):null},getObjRefRelationIndex:function(e,t){return this._enableObjRefRelations?this.getObjRefRelationManager().getRelationIndex(e,t):-1},getObjRefRelation:function(e,t){return this._enableObjRefRelations?this.getObjRefRelationManager().getRelation(e,t):null},releaseObjRefRelation:function(e,t){return this._enableObjRefRelations?this.getObjRefRelationManager().releaseRelation(e,t):null},findObjRefRelations:function(e,t){return this._enableObjRefRelations?this.getObjRefRelationManager().findRelations(e,t):[]}}),Kekule.ClassDefineUtils.addStandardSizeSupport(Kekule.ChemSpace),Kekule.IntermediateChemSpace=Class.create(Kekule.ChemSpace,{CLASS_NAME:"Kekule.IntermediateChemSpace",initialize:function(e){this.tryApplySuper("initialize",[e]),this.setPropStoreFieldValue("enableAutoId",!1),this._enableObjRefRelations=!1,this._autoUpdateObjRefRelations=!1}}),Kekule.ChemDocument=Class.create(Kekule.ChemSpace,{CLASS_NAME:"Kekule.ChemDocument",initProperties:function(){},getAutoIdPrefix:function(){return"d"}}),Kekule.ObjRefRelationManager=Class.create(ObjectEx,{CLASS_NAME:"Kekule.ObjRefRelationManager",initialize:function(e){this.tryApplySuper("initialize"),this.setOwner(e),this.setPropStoreFieldValue("relations",[])},initProperties:function(){this.defineProp("owner",{dataType:"Kekule.ChemObject",serializable:!1}),this.defineProp("relations",{dataType:DataType.ARRAY,serializable:!1,setter:null})},createRelation:function(e,t,r){var n={srcObj:e,srcProp:t,dest:r};return this.getRelations().push(n),n},modifyRelation:function(e,t,r){var n=!r||Kekule.ArrayUtils.isArray(r)&&!r.length,i=this.getRelation(e,t);return n?(i&&this.removeRelation(i),null):(i?i.dest=r:i=this.createRelation(e,t,r),i)},getRelationIndex:function(e,t){for(var r=this.getRelations(),n=0,i=r.length;n<i;++n){var o=r[n];if(o.srcObj===e&&o.srcProp===t)return n}return-1},getRelation:function(e,t){var r=this.getRelations(),n=this.getRelationIndex(e,t);return n>=0?r[n]:null},releaseRelation:function(e,t){var r=this.getRelations(),n=this.getRelationIndex(e,t);n>=0&&r.splice(n,1)},removeRelation:function(e){var t=this.getRelations(),r=t.indexOf(e);r>=0&&t.splice(r,1)},findRelations:function(e,t){var r,n=t||{},i=[],o=Object.extend({},e),a=!1;o.dest&&(delete o.dest,a=!0,r=Kekule.ArrayUtils.toArray(e.dest));for(var s=this.getRelations(),l=0,u=s.length;l<u;++l){var h=s[l],c=!1;if((c=Kekule.ObjUtils.match(h,o))&&a){var d=Kekule.ArrayUtils.toArray(h.dest);c=n.checkDestChildren?this._hasChildOrSelfOfParents(d,r):Kekule.ArrayUtils.intersect(d,r).length===r.length}c&&i.push(h)}return i},_hasChildOrSelfOfParents:function(e,t){for(var r=0,n=e.length;r<n;++r)for(var i=e[r],o=0,a=t.length;o<a;++o){var s=t[o];if(i===s||i.isChildOf&&i.isChildOf(s))return!0}return!1}})}(),Kekule.ExceptionHandler=Class.create(ObjectEx,{CLASS_NAME:"Kekule.ExceptionHandler",initProperties:function(){this.defineEvent("exceptionThrown")},notifyExceptionThrown:function(e,t){var r={exception:e,level:t};return this.invokeEvent("exceptionThrown",r),r},throwException:function(e,t){var r=Kekule.ExceptionLevel;if(t||(t=r.ERROR),!this.notifyExceptionThrown(e,t||r.ERROR).stop){if(!t||t===r.ERROR){var n=e;throw"string"==typeof e&&(n=new Kekule.Exception(e)),n}if("undefined"!=typeof console){"string"!=typeof e&&(e=e.message);var i=t===r.WARNING?"warn":t===r.NOTE?"info":"log";i?console[i](e):console.log(e)}}},raise:function(e,t){return this.throwException(e,t||Kekule.ExceptionLevel.ERROR)}}),Kekule.ExceptionHandler.getInstance=function(){return this.instance||(this.instance=new Kekule.ExceptionHandler),this.instance},Kekule.exceptionHandler=Kekule.ExceptionHandler.getInstance(),Kekule.Exception=function(e,t){this.message=e,this.name=t},Kekule.Exception.prototype=new Error,Kekule.Exception.prototype.constructor=Kekule.Exception,Object.extend(Kekule.Exception.prototype,{getMessage:function(){return this.message}}),Kekule.Error=function(e,t){this.message=e,this.name=t},Kekule.Error.prototype=Kekule.Exception.prototype,Kekule.Error.prototype.constructor=Kekule.Error,Kekule.ChemError=function(e,t){this.message=e,this.name=t},Kekule.ChemError.prototype=Kekule.Error.prototype,Kekule.ChemError.prototype.constructor=Kekule.ChemError,"undefined"==typeof console&&(console={log:function(){},warn:function(){},info:function(){},error:function(){}}),Kekule.oneOf=function(){for(var e=arguments,t=Kekule.ObjUtils.notUnset,r=0,n=e.length;r<n;++r)if(t(e[r]))return e[r];return null},Kekule.ClassUtils={getShortClassName:function(e){var t=e.indexOf(".");return t>=0?e.substring(t+1):e},getLastClassName:function(e){var t=e.lastIndexOf(".");return t>=0?e.substring(t+1):e},makeSingleton:function(e){return Object.extend(e,{_instance:null,getInstance:function(t,r,n,i,o,a,s,l,u,h){return e._instance||(e._instance=new e(t,r,n,i,o,a,s,l,u,h)),e._instance}})}},Kekule.NumUtils={isInteger:function(e){return"number"==typeof e&&parseInt(e,10)===parseFloat(e)},toDecimals:function(e,t){if(Kekule.NumUtils.isInteger(e))return e.toString();var r=Math.pow(10,t),n=Math.round(e*r);n/=r;var i=parseInt(n),o=(n-i).toString();return o.length>t+2?(o=o.substr(2,t),i.toString()+"."+o):n.toString()},isFloatEqual:function(e,t,r){return Kekule.ObjUtils.isUnset(r)&&(r=1e-100),Math.abs(e-t)<=r},getPrimes:function(e){var t,r,n=[],i=[];for(t=2;t<=e;++t)if(!n[t])for(i.push(t),r=t<<1;r<=e;r+=t)n[r]=!0;return i}},Kekule.ObjUtils={getPrototypeOf:function(e){return Object.getPrototypeOf?Object.getPrototypeOf(e):e.prototype||e.__proto__},getPropertyDescriptor:function(e,t,r){var n=Object.getOwnPropertyDescriptor;if(n){var i=n(e,t);return!i&&r&&(e.prototype||e.__proto__)&&(i=Kekule.ObjUtils.getPropertyDescriptor(e.prototype||e.__proto__,t,r)),i}return null},getOwnedFieldNames:function(e,t){var r=[];for(var n in e)e.hasOwnProperty(n)&&(t||"function"!=typeof e[n])&&r.push(n);return r},replacePropName:function(e,t,r){return void 0!==e[t]&&(e.hasOwnProperty(t)?(e[r]=e[t],delete e[t]):Kekule.raise(Kekule.$L("ErrorMsg.NON_OWN_PROPERTY_CANNOT_BE_REPLACED"))),e},isUnset:function(e){return null==e},notUnset:function(e){return null!=e},equal:function(e,t,r){var n=[];for(var i in e)if(!(r&&r.indexOf(i)>=0)){if(e[i]!==t[i])return!1;n.push(i)}for(var i in t)if(!(r&&r.indexOf(i)>=0)&&n.indexOf(i)<0)return!1;return!0},match:function(e,t){for(var r in t)if(t.hasOwnProperty(r)&&e[r]!==t[r])return!1;return!0},isInstanceOf:function(e,t){if(DataType.isArrayValue(t)){for(var r=0,n=t.length;r<n;++r)if(e instanceof t[r])return!0;return!1}return e instanceof t},getLeafFieldCascadeNames:function(e,t){var r=function(e,t,n,i){for(var o in n)if(n.hasOwnProperty(o)&&(i||"function"!=typeof n[o])){var a=n[o];"object"==typeof a?r(e,t+o+".",a,i):e.push(t+o)}},n=[];return r(n,"",e,t),n}},Kekule.ArrayUtils={isArray:function(e){return!!e&&("object"==typeof e&&void 0!==e.length)},toArray:function(e){return Kekule.ArrayUtils.isArray(e)?e:[e]},clone:function(e){return e.slice(0)},filter:function(e,t,r){if(!t)return Kekule.ArrayUtils.clone(e);if(e.filter)return e.filter(t,r);for(var n=[],i=0,o=e.length;i<o;++i){var a=e[i];t.apply(r,[a,i,e])&&n.push(a)}return n},divide:function(e,t){for(var r=[],n=[],i=0,o=0,a=e.length;o<a;++o)n.push(e[o]),++i>=t&&(r.push(n),n=[],i=0);return n.length&&r.push(n),r},pushUnique:function(e,t){var r=Kekule.ArrayUtils.pushUniqueEx(e,t);return r?r.index:null},pushUniqueEx:function(e,t){if(DataType.isArrayValue(t)){for(var r,n=0,i=t.length;n<i;++n)Kekule.ObjUtils.isUnset(r)?r=Kekule.ArrayUtils.pushUniqueEx(e,t[n]):Kekule.ArrayUtils.pushUniqueEx(e,t[n]);return r}if(!t)return{index:-1,isPushed:!1};var o=e.indexOf(t);return o<0?{index:e.push(t),isPushed:!0}:{index:o,isPushed:!1}},insertUnique:function(e,t,r){return Kekule.ArrayUtils.insertUniqueEx(e,t,r).index},insertUniqueEx:function(e,t,r){if(!t)return{index:-1,isInserted:!1};(Kekule.ObjUtils.isUnset(r)||r<0)&&(r=e.length);var n=e.indexOf(t);return n<0?(e.splice(r,0,t),{index:r,isInserted:!0}):n!=r?(e.splice(n,1),e.splice(r,0,t),{index:r,isInserted:!1}):void 0},removeAt:function(e,t){var r=e[t];return void 0!==r?(e.splice(t,1),r):null},remove:function(e,t,r){var n=e.indexOf(t);return n>=0?(Kekule.ArrayUtils.removeAt(e,n),r&&Kekule.ArrayUtils.remove(e,t,r),t):null},replace:function(e,t,r,n){var i=e.indexOf(t);return i>=0?(e[i]=r,n&&Kekule.ArrayUtils.replace(e,t,r,n),t):null},changeIndex:function(e,t,r){if(t>=0&&t<=e.length){var n=e[t];return e.splice(t,1),e.splice(r,0,n),n}return null},changeItemIndex:function(e,t,r){var n=e.indexOf(t);return Kekule.ArrayUtils.changeIndex(e,n,r)},toUnique:function(e){for(var t=[],r=0,n=e.length;r<n;++r){var i=e[r];t.indexOf(i)<0&&t.push(i)}return t},getUniqueElemCount:function(e){return Kekule.ArrayUtils.toUnique(e).length},reverse:function(e){for(var t=[],r=0,n=e.length;r<n;++r)Kekule.ObjUtils.notUnset(e[r])&&(t[n-r-1]=e[r]);return t},randomize:function(e){if(!e)return null;if(!e.length)return[];for(var t=[],r=e.slice(0);r.length>1;){var n=Math.round(Math.random()*(r.length-1));t.push(r.splice(n,1)[0])}return t.push(r[0]),t},exclude:function(e,t){for(var r=[],n=Kekule.ArrayUtils.toArray(t),i=0,o=e.length;i<o;++i){var a=e[i];n.indexOf(a)<0&&r.push(a)}return r},intersect:function(e,t){for(var r=[],n=0,i=e.length;n<i;++n)t.indexOf(e[n])>=0&&r.push(e[n]);return r},flatten:function(e){for(var t=[],r=0,n=e.length;r<n;++r){var i=e[r];if(Kekule.ArrayUtils.isArray(i)){var o=Kekule.ArrayUtils.flatten(i);t=t.concat(o)}else t.push(i)}return t},compare:function(e,t,r){r||(r=function(e,t){return e>t?1:e<t?-1:0});for(var n=Math.min(e.length,t.length),i=0;i<n;++i){var o=r(e[i],t[i]);if(0!==o)return o}return e.length>n?1:t.length>n?-1:0},compareNestedArray:function(e,t,r){var n=Math.min(e.length,t.length);r||(r=function(e,t){return e-t});for(var i=0;i<n;++i){var o=0,a=e[i],s=t[i],l=DataType.isArrayValue(a),u=DataType.isArrayValue(s);if(0!=(o=l&&u?Kekule.ArrayUtils.compareNestedArray(a,s,r):l?1:u?-1:r(a,s)))return o}return e.length>n?1:t.length>n?-1:0},group:function(e,t){t||(t=function(e,t){return e<t?-1:e>t?1:0});var r=Kekule.ArrayUtils.clone(e);r.sort(t);for(var n,i=[],o=0,a=r.length;o<a;++o){var s=r[o];if(n&&0===t(s,n)){var l=i.length?i[i.length-1]:null;Kekule.ArrayUtils.isArray(l)||(i.pop(),l=[n],i.push(l)),l.push(s)}else i.push(s);n=s}return i},indexStackOfElem:function(e,t){for(var r=0,n=t.length;r<n;++r){var i=t[r];if(i===e)return[r];if(Kekule.ArrayUtils.isArray(i)){var o=Kekule.ArrayUtils.indexStackOfElem(e,i);if(o)return o.unshift(r),o}}return null},getElemByIndexStack:function(e,t){var r=Kekule.ArrayUtils.isArray(t)?Kekule.ArrayUtils.clone(t):[t],n=e[r.shift()];return n?r.length?Kekule.ArrayUtils.isArray(n)?Kekule.ArrayUtils.getElemByIndexStack(n,r):null:n:null},getMedian:function(e){var t=[].concat(e),r=t.length;return 0===r?null:r<=1?t[0]:(t.sort(function(e,t){return e-t}),r%2?t[r+1>>1]:(t[r>>1]+t[(r>>1)-1])/2)},sortHashArray:function(e,t){for(var r=[],n=0,i=t.length;n<i;++n){var o={},a=t[n]||"";a.startsWith("!")?(o.field=a.substr(1),o.desc=!0):(o.field=a,o.desc=!1),r.push(o)}return e.sort(function(e,t){for(var n=0,i=0,o=r.length;i<o;++i){var a=r[i].field,s=e[a]||"",l=t[a]||"";if(n=s>l?1:s<l?-1:0,r[i].desc&&(n=-n),0!==n)break}return n}),e}},Kekule.StrUtils={STR_TRUES:["true","yes","t","y"],STR_FALSES:["false","no","f","n"],trim:function(e){return e.replace(/^\s*|\s*$/g,"")},normalizeSpace:function(e){return e.replace(/^\s*|\s(?=\s)|\s*$/g,"")},convertToStr:function(e){return""+e},convertToType:function(e,t){if("string"!=typeof e)return e;switch(t){case DataType.FLOAT:case DataType.NUMBER:return parseFloat(e);case DataType.INT:return parseInt(e);case DataType.BOOL:return Kekule.StrUtils.strToBool(e);default:return e}},boolToStr:function(e){return e?Kekule.StrUtils.STR_TRUES[0]:Kekule.StrUtils.STR_FALSES[0]},strToBool:function(e){for(var t=e.toLowerCase(),r=0,n=Kekule.StrUtils.STR_FALSES.length;r<n;++r)if(t==Kekule.StrUtils.STR_FALSES[r])return!1;return!!e},removeAroundPair:function(e,t,r){return e.startsWith(t)&&e.endsWith(r)?e.substring(t.length,e.length-t.length-r.length+1):e},unquote:function(e){var t=Kekule.StrUtils.removeAroundPair,r=e;return r=t(r,"'","'"),r=t(r,'"','"')},splitTokens:function(e,t){if(!e)return[];if(DataType.isArrayValue(e))return e;var r=t?new RegExp(t,"g"):/\s+/g;return e.split(r)},hasToken:function(e,t,r){return Kekule.StrUtils.splitTokens(e,r).indexOf(t)>=0},addTokens:function(e,t,r){for(var n=Kekule.StrUtils.splitTokens(e,r),i=Kekule.StrUtils.splitTokens(t,r),o=0,a=i.length;o<a;++o)n.indexOf(i[o])<0&&n.push(i[o]);return n.join(r||" ")},removeTokens:function(e,t,r){for(var n=Kekule.StrUtils.splitTokens(e,r),i=Kekule.StrUtils.splitTokens(t,r),o=0,a=i.length;o<a;++o){var s=n.indexOf(i[o]);s>=0&&n.splice(s,1)}return n.join(r||" ")},toggleTokens:function(e,t,r){for(var n=Kekule.StrUtils.splitTokens(e,r),i=Kekule.StrUtils.splitTokens(t,r),o=[],a=0,s=i.length;a<s;++a){var l=n.indexOf(i[a]);l>=0?n.splice(l,1):o.push(i[a])}return(n=n.concat(o)).join(r||" ")},getLineCount:function(e,t){return t||(t="\n"),e.split(t).length},getMaxLineCharCount:function(e,t){t||(t="\n");for(var r=e.split(t),n=0,i=0,o=r.length;i<o;++i){var a=r[i];n=Math.max(a.length,n)}return n},isNumbericStr:function(e){var t=Number(e);return!isNaN(t)},splitIndexEndingStr:function(e){for(var t=e.length-1,r=e.charAt(t),n="";r&&Kekule.StrUtils.isNumbericStr(r);)--t,n=r+n,r=e.charAt(t);return n?{prefix:e.substring(0,t+1),index:parseInt(n)}:null}},Kekule.RoleMapUtils={KEY_ITEM:"item",KEY_ROLE:"role",NON_EXPLICIT_ROLE:null,createMap:function(e,t){var r={};return t=t||Kekule.RoleMapUtils.NON_EXPLICIT_ROLE,r[Kekule.RoleMapUtils.KEY_ITEM]=e,r[Kekule.RoleMapUtils.KEY_ROLE]=t,r},getItem:function(e){return e[Kekule.RoleMapUtils.KEY_ITEM]},setItem:function(e,t){e[Kekule.RoleMapUtils.KEY_ITEM]=t},getRole:function(e){return e[Kekule.RoleMapUtils.KEY_ROLE]},setRole:function(e,t){e[Kekule.RoleMapUtils.KEY_ROLE]=t}},Kekule.FactoryUtils={MATCH_EXACTLY:0,MATCH_BY_CLASS:1,DEF_ITEM_STORE_FIELD_NAME:"_items",createSimpleFactory:function(e){var t=Kekule.FactoryUtils,r={_items:new Kekule.MapEx(!0),_matchMethod:e||Kekule.FactoryUtils.MATCH_EXACTLY,register:function(e,t){r._items.set(e,t)},unregister:function(e){r._items.remove(e)},getClass:function(e){if(r._matchMethod===t.MATCH_EXACTLY)return r._items.get(e);if(r._matchMethod===t.MATCH_BY_CLASS){var n=r._items.get(e);if(!n){var i=ClassEx.getSuperClass(e);i&&(n=r.getClass(i))}return n}},getInstance:function(e,t,n,i,o,a,s,l,u,h){var c=r.getClass(e);if(c)return new c(t,n,i,o,a,s,l,u,h)}};return r}},Kekule.UrlUtils={PROTOCAL_DELIMITER:"://",EXT_DELIMITER:".",PATH_DELIMITER:"/",SEARCH_DELIMITER:"?",SEARCH_PAIR_DELIMITER:"&",KEY_VALUE_DELIMITER:"=",HASH_DELIMITER:"#",normalizePath:function(e){return e.replace(/\\/g,"/")},extractProtocal:function(e){if(!e)return null;var t=e.indexOf(Kekule.UrlUtils.PROTOCAL_DELIMITER);return t>=0?e.substr(0,t):""},extractFileName:function(e){if(!e)return null;var t=e.lastIndexOf(Kekule.UrlUtils.PATH_DELIMITER);return t>=0?e.substr(t+1):e},extractFileExt:function(e){var t=Kekule.UrlUtils.extractFileName(e);if(t){var r=t.lastIndexOf(Kekule.UrlUtils.EXT_DELIMITER);return r>=0?t.substr(r+1):""}return null},extractFileCoreName:function(e){var t=Kekule.UrlUtils.extractFileName(e);if(t){var r=t.lastIndexOf(Kekule.UrlUtils.EXT_DELIMITER);return r>=0?t.substr(0,r):""}return null},extractSearch:function(e){if(!e)return null;var t=e.lastIndexOf(Kekule.UrlUtils.SEARCH_DELIMITER);return t>=0?e.substr(t):null},analysisSearch:function(e,t){for(var r=Kekule.UrlUtils.extractSearch(e)||"",n=(r=r.substr(1)).split(Kekule.UrlUtils.SEARCH_PAIR_DELIMITER),i=t?{}:[],o=0,a=n.length;o<a;++o){var s=n[o].split(Kekule.UrlUtils.KEY_VALUE_DELIMITER);s[0]&&(t?i[s[0]]=s[1]:i.push({key:s[0],value:s[1]}))}return i},generateSearchString:function(e){for(var t=Kekule.UrlUtils,r=[],n=Kekule.ObjUtils.getOwnedFieldNames(e),i=0,o=n.length;i<o;++i){var a=n[i],s=e[a];if(Kekule.ObjUtils.notUnset(s)){s=encodeURIComponent(""+s);r.push(a+t.KEY_VALUE_DELIMITER+s)}}return r.join(t.SEARCH_PAIR_DELIMITER)},generateUrl:function(e,t,r){var n=Kekule.UrlUtils,i=e;if(t){var o=n.generateSearchString(t);i+=n.SEARCH_DELIMITER+o}return r&&(i+=n.HASH_DELIMITER+r),i}},Kekule.MatrixUtils={create:function(e,t,r){var n=!1,i=!1,o=Kekule.ObjUtils;o.notUnset(r)&&(n=!0,Kekule.ArrayUtils.isArray(r)&&(i=!0));for(var a=0,s=new Array(e),l=0,u=s.length;l<u;++l){var h=new Array(t);if(n)for(var c=0,d=h.length;c<d;++c)i&&o.notUnset(r[a])?(h[c]=r[a],++a):h[c]=r;s[l]=h}return s},createIdentity:function(e){for(var t=Kekule.MatrixUtils.create(e,e,0),r=0;r<e-1;++r)t[r][r]=1;return t},getRowCount:function(e){return e.length},getColCount:function(e){return Kekule.MatrixUtils.getRowCount(e)>0?e[0].length:0},getValue:function(e,t,r){return e[t-1][r-1]||0},setValue:function(e,t,r,n){e[t-1][r-1]=n},transpose:function(e){for(var t=Kekule.MatrixUtils,r=t.getColCount(e),n=t.getRowCount(e),i=t.create(r,n),o=1;o<=r;++o)for(var a=i[o-1],s=1;s<=n;++s)a[s-1]=t.getValue(e,s,o);return i},minus:function(e){for(var t=Kekule.MatrixUtils,r=t.getRowCount(e),n=t.getColCount(e),i=this.create(r,n),o=0;o<r;++o)for(var a=i[o],s=e[o],l=0;l<n;++l)a[l]=-(s[l]||0);return i},add:function(e,t){for(var r=Kekule.MatrixUtils,n=r.getRowCount(e),i=r.getColCount(e),o=this.create(n,i),a=1;a<=n;++a)for(var s=1;s<=i;++s)r.setValue(o,a,s,r.getValue(e,a,s)+r.getValue(t,a,s));return o},substract:function(e,t){var r=Kekule.MatrixUtils;return r.add(e,r.minus(t))},multiply:function(e,t){for(var r=Kekule.MatrixUtils,n=r.getRowCount(e),i=r.getColCount(t),o=r.create(n,i),a=1;a<=n;++a)for(var s=1;s<=i;++s){for(var l=0,u=1;u<=n;++u)l+=r.getValue(e,a,u)*r.getValue(t,u,s);r.setValue(o,a,s,l)}return o}},Kekule.CoordUtils={create:function(e,t,r){var n={x:e,y:t};return(r||0===r)&&(n.z=r),n},clone:function(e){var t={x:e.x,y:e.y};return(e.z||0===e.z)&&(t.z=e.z),t},is3D:function(e){return e.z||0===e.z},isEqual:function(e,t){var r=e.x===t.x&&e.y===t.y,n=Kekule.ObjUtils;return r&&(n.notUnset(e.z)||n.notUnset(t.z))&&(r=e.z===t.z),r},isZero:function(e,t){var r=Kekule.ObjUtils.notUnset(t)?t:0;return Math.abs(e.x||0)<=r&&Math.abs(e.y||0)<=r&&Math.abs(e.z||0)<=r},absValue:function(e){if(e){var t={};return Kekule.ObjUtils.isUnset(e.x)||(t.x=Math.abs(e.x)),Kekule.ObjUtils.isUnset(e.y)||(t.y=Math.abs(e.y)),Kekule.ObjUtils.isUnset(e.z)||(t.z=Math.abs(e.z)),t}},add:function(e,t){var r={};return Kekule.ObjUtils.isUnset(e.x)&&Kekule.ObjUtils.isUnset(t.x)||(r.x=(e.x||0)+(t.x||0)),Kekule.ObjUtils.isUnset(e.y)&&Kekule.ObjUtils.isUnset(t.y)||(r.y=(e.y||0)+(t.y||0)),Kekule.ObjUtils.isUnset(e.z)&&Kekule.ObjUtils.isUnset(t.z)||(r.z=(e.z||0)+(t.z||0)),r},substract:function(e,t){var r={};return Kekule.ObjUtils.isUnset(e.x)&&Kekule.ObjUtils.isUnset(t.x)||(r.x=(e.x||0)-(t.x||0)),Kekule.ObjUtils.isUnset(e.y)&&Kekule.ObjUtils.isUnset(t.y)||(r.y=(e.y||0)-(t.y||0)),Kekule.ObjUtils.isUnset(e.z)&&Kekule.ObjUtils.isUnset(t.z)||(r.z=(e.z||0)-(t.z||0)),r},multiply:function(e,t){var r={};return Kekule.ObjUtils.isUnset(e.x)||(r.x=e.x*t),Kekule.ObjUtils.isUnset(e.y)||(r.y=e.y*t),Kekule.ObjUtils.isUnset(e.z)||(r.z=e.z*t),r},divide:function(e,t){return Kekule.CoordUtils.multiply(e,1/t)},standardize:function(e){var t=Math.sqrt(Math.sqr(e.x||0)+Math.sqr(e.y||0)+Math.sqr(e.z||0));return Kekule.CoordUtils.divide(e,t||1)},toArray:function(e){var t=[];t.push(e.x,e.y),Kekule.CoordUtils.is3D(e)&&t.push(e.z)},isSameTransform2DOptions:function(e,t,r){var n=Kekule.ObjUtils.isUnset,i=Kekule.NumUtils.isFloatEqual;r||(r={});var o=r.translate||.01,a=r.scale||.01,s=r.rotate||.01,l=!1,u=e.center,h=t.center;if(l=!(!u||!h)&&(i(u.x,h.x,o)&&i(u.y,h.y,o)))for(var c=["scale","scaleX","scaleY","rotateAngle","translateX","translateY"],d=0,f=c.length;d<f;++d){var p=c[d],g=e[p],C=t[p];if(!n(g)||!n(C))if(!(l=!n(g)&&!n(C)&&i(g,C,0===p.indexOf("scale")?a:0===p.indexOf("rotate")?s:o)))break}return l},isSameTransform3DOptions:function(e,t,r){var n=Kekule.ObjUtils.isUnset,i=Kekule.NumUtils.isFloatEqual;r||(r={});var o=r.translate||.01,a=r.scale||.01,s=r.rotate||.01,l=!1,u=e.center,h=t.center;if(l=u&&h?i(u.x,h.x,o)&&i(u.y,h.y,o)&&i(u.z,h.z,o):!u&&!h){var c=e.rotateAxisVector,d=t.rotateAxisVector;l=c&&d?i(c.x,d.x,o)&&i(c.y,d.y,o)&&i(c.z,d.z,o):!c&&!d}if(l)for(var f=["scale","scaleX","scaleY","scaleZ","rotateAngle","rotateX","rotateY","rotateZ","translateX","translateY","translateZ"],p=0,g=f.length;p<g;++p){var C=f[p],y=e[C],v=t[C];if(!n(y)||!n(v))if(!(l=!n(y)&&!n(v)&&i(y,v,0===C.indexOf("scale")?a:0===C.indexOf("rotate")?s:o)))break}return l},transform2D:function(e,t){var r=Kekule.CoordUtils.calcTransform2DMatrix(t);return Kekule.CoordUtils.transform2DByMatrix(e,r)},inverseTransform2D:function(e,t){var r=Kekule.CoordUtils.calcInverseTransform2DMatrix(t);return Kekule.CoordUtils.transform2DByMatrix(e,r)},transform2DByMatrix:function(e,t){var r=Kekule.MatrixUtils,n=r.create(3,1,[e.x||0,e.y||0,1]);return{x:(n=r.multiply(t,n))[0][0],y:n[1][0]}},calcTransform2DMatrix:function(e,t){var r=Kekule.MatrixUtils,n=e||{},i=n.center;if(i)var o=r.create(3,3,[1,0,-(i.x||0),0,1,-(i.y||0),0,0,1]),a=r.create(3,3,[1,0,i.x||0,0,1,i.y||0,0,0,1]);if(n.rotateAngle)var s=n.rotateAngle,l=Math.cos(s),u=Math.sin(s),h=r.create(3,3,[l,-u,0,u,l,0,0,0,1]);var c=n.scale,d=n.scaleX,f=n.scaleY,p=c||1;if(c||d||f){var g=r.create(3,3);r.setValue(g,1,1,d||p),r.setValue(g,2,2,f||p),r.setValue(g,3,3,1)}var C=n.translateX,y=n.translateY;if(C||y){var v=r.create(3,3);r.setValue(v,1,1,1),r.setValue(v,2,2,1),r.setValue(v,3,3,1),r.setValue(v,1,3,C||0),r.setValue(v,2,3,y||0)}var x=r.create(3,3,[1,0,0,0,1,0,0,0,1]);return t?(o&&(x=r.multiply(o,x)),v&&(x=r.multiply(v,x)),g&&(x=r.multiply(g,x)),h&&(x=r.multiply(h,x)),a&&(x=r.multiply(a,x))):(o&&(x=r.multiply(o,x)),h&&(x=r.multiply(h,x)),g&&(x=r.multiply(g,x)),v&&(x=r.multiply(v,x)),a&&(x=r.multiply(a,x))),x},calcInverseTransform2DMatrix:function(e){var t=Object.create(e);return e.center&&(t.center={x:e.center.x,y:e.center.y}),t.scale&&(t.scale=1/t.scale),t.scaleX&&(t.scaleX=1/t.scaleX),t.scaleY&&(t.scaleY=1/t.scaleY),t.translateX&&(t.translateX=-t.translateX),t.translateY&&(t.translateY=-t.translateY),t.rotateAngle&&(t.rotateAngle=-t.rotateAngle),Kekule.CoordUtils.calcTransform2DMatrix(t,!0)},transform3D:function(e,t){var r=Kekule.CoordUtils.calcTransform3DMatrix(t);return Kekule.CoordUtils.transform3DByMatrix(e,r)},transform3DByMatrix:function(e,t){var r=Kekule.MatrixUtils,n=r.create(4,1,[e.x||0,e.y||0,e.z||0,1]);return{x:(n=r.multiply(t,n))[0][0],y:n[1][0],z:n[2][0]}},_calcRotateXYZ3DMatrixCore:function(e){var t=Kekule.MatrixUtils,r=t.create(4,4,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),n=[];if(e.rotateAngle&&e.rotateAxisVector){var i=Kekule.CoordUtils.standardize(e.rotateAxisVector);n.push({vector:[i.x,i.y,i.z],angle:-e.rotateAngle})}else{var o=e.rotateX,a=e.rotateY,s=e.rotateZ;o&&n.push({vector:[1,0,0],angle:-o}),a&&n.push({vector:[0,1,0],angle:-a}),s&&n.push({vector:[0,0,1],angle:-s})}for(var l=0,u=n.length;l<u;++l){var h,c=t.create(4,4),d=n[l].angle,f=n[l].vector,p=Math.cos(d),g=Math.sin(d);for(l=1;l<=4;++l)for(var C=1;C<=4;++C){if(l<4&&C<4){for(var y=1;y<=3&&(y===l||y===C);++y);var v=f[l-1]*f[C-1];h=l<C?v*(1-p)-Math.pow(-1,l+C)*f[y-1]*g:l>C?v*(1-p)+Math.pow(-1,l+C)*f[y-1]*g:v+(1-v)*p}else h=l===C?1:0;t.setValue(c,l,C,h)}r=t.multiply(c,r)}return r},calcRotate3DMatrix:function(e){var t=Kekule.MatrixUtils,r=Object.create(e||{});if(r.rotateMatrix)a=r.rotateMatrix;else{var n=r.center;if(n)var i=t.create(4,4,[1,0,0,-(n.x||0),0,1,0,-(n.y||0),0,0,1,-(n.z||0),0,0,0,1]),o=t.create(4,4,[1,0,0,n.x||0,0,1,0,n.y||0,0,0,1,n.z||0,0,0,0,1]);var a=Kekule.CoordUtils._calcRotateXYZ3DMatrixCore(e);i&&(a=t.multiply(i,a)),o&&(a=t.multiply(o,a))}return a},calcTransform3DMatrix:function(e){var t=Kekule.MatrixUtils,r=e||{},n=r.center;if(n)var i=t.create(4,4,[1,0,0,-(n.x||0),0,1,0,-(n.y||0),0,0,1,-(n.z||0),0,0,0,1]),o=t.create(4,4,[1,0,0,n.x||0,0,1,0,n.y||0,0,0,1,n.z||0,0,0,0,1]);var a=Object.copyValues({},r,["rotateX","rotateY","rotateZ","rotateAngle","rotateAxisVector","rotateMatrix"]),s=Kekule.CoordUtils.calcRotate3DMatrix(a),l=r.scale,u=r.scaleX,h=r.scaleY,c=r.scaleZ;if(l||u||h||c){var d=l||1,f=t.create(4,4);t.setValue(f,1,1,u||d),t.setValue(f,2,2,h||d),t.setValue(f,3,3,c||d),t.setValue(f,4,4,1)}var p=r.translateX,g=r.translateY,C=r.translateZ;if(p||g||C){var y=t.create(4,4);t.setValue(y,1,1,1),t.setValue(y,2,2,1),t.setValue(y,3,3,1),t.setValue(y,4,4,1),t.setValue(y,1,4,p||0),t.setValue(y,2,4,g||0),t.setValue(y,3,4,C||0)}var v=t.create(4,4,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);return i&&(v=t.multiply(i,v)),s&&(v=t.multiply(s,v)),f&&(v=t.multiply(f,v)),y&&(v=t.multiply(y,v)),o&&(v=t.multiply(o,v)),v},calcInverseTransform3DMatrix:function(e){var t=Object.create(e);return e.center&&(t.center={x:e.center.x,y:e.center.y,z:e.center.z}),t.scale&&(t.scale=1/t.scale),t.scaleX&&(t.scaleX=1/t.scaleX),t.scaleY&&(t.scaleY=1/t.scaleY),t.scaleZ&&(t.scaleZ=1/t.scaleZ),t.translateX&&(t.translateX=-t.translateX),t.translateY&&(t.translateY=-t.translateY),t.translateZ&&(t.translateZ=-t.translateZ),t.rotateAngle&&(t.rotateAngle=-t.rotateAngle),t.rotateX&&(t.rotateX=-t.rotateX),t.rotateX&&(t.rotateY=-t.rotateY),t.rotateZ&&(t.rotateZ=-t.rotateZ),Kekule.CoordUtils.calcTransform3DMatrix(t,!0)},calcCoordGroup2DTransformParams:function(e,t,r,n){var i=Kekule.CoordUtils,o=i.getDistance(e,t),a=i.substract(t,e),s=Math.atan2(a.y,a.x),l=i.getDistance(r,n),u=i.substract(n,r),h=Math.atan2(u.y,u.x),c=i.substract(r,e);return{translateX:c.x,translateY:c.y,scale:l/o,rotateAngle:h-s,center:e}},getDistance:function(e,t){t||(t={x:0,y:0,z:0});var r=Math.sqr(t.x-e.x)+Math.sqr(t.y-e.y);return Kekule.ObjUtils.notUnset(e.z)&&Kekule.ObjUtils.notUnset(t.z)&&(r+=Math.sqr(t.z-e.z)),Math.sqrt(r)},getCenter:function(e){var t=e.length;if(t<=0)return null;for(var r=Object.extend(e[0]),n=1;n<t;++n)r=Kekule.CoordUtils.add(r,e[n]);return Kekule.CoordUtils.divide(r,t)},insideRect:function(e,t,r){return(e.x-t.x)*(e.x-r.x)<=0&&(e.y-t.y)*(e.y-r.y)<=0},isInsideBox:function(e,t){var r=t,n=Math.sign(e.x-r.x1)*Math.sign(e.x-r.x2)<=0&&Math.sign(e.y-r.y1)*Math.sign(e.y-r.y2)<=0;return Kekule.ObjUtils.notUnset(e.z)&&(n=n&&Math.sign(e.z-r.z1)*Math.sign(e.z-r.z2)<=0),n},getContainerBox:function(e){var t={},r={},n=e.length;if(!(n>0))return null;t=Kekule.CoordUtils.clone(e[0]),r=Kekule.CoordUtils.clone(e[0]);for(var i=1;i<n;++i){var o=e[i];t.x=Math.min(t.x,o.x),t.y=Math.min(t.y,o.y),r.x=Math.max(r.x,o.x),r.y=Math.max(r.y,o.y),Kekule.ObjUtils.notUnset(t.z)&&(t.z=Math.min(t.z,o.z),r.z=Math.max(r.z,o.z))}return Kekule.BoxUtils.createBox(t,r)}},Kekule.GeometryUtils={standardizeAngle:function(e,t,r){t=t||0,Math.PI;return e-Math.floor((e-t)/Math.PI/2)*Math.PI*2},polarToCartesian:function(e,t,r,n){return{x:e+r*Math.cos(n),y:t+r*Math.sin(n)}},getVectorScalarProduct:function(e,t){return(e.x||0)*(t.x||0)+(e.y||0)*(t.y||0)+(e.z||0)*(t.z||0)},getVectorCrossProduct:function(e,t){return{x:(e.y||0)*(t.z||0)-(e.z||0)*(t.y||0),y:(e.z||0)*(t.x||0)-(e.x||0)*(t.z||0),z:(e.x||0)*(t.y||0)-(e.y||0)*(t.x||0)}},getVectorIncludedAngle:function(e,t){var r=Kekule.CoordUtils,n=Kekule.GeometryUtils.getVectorCrossProduct(e,t),i={x:0,y:0,z:0},o=r.getDistance(e,i)*r.getDistance(t,i),a=r.getDistance(n,i)/o;return Math.asin(a)},getVectorIncludedAngle2:function(e,t){return Kekule.GeometryUtils.standardizeAngle(Math.atan2(t.y,t.x)-Math.atan2(e.y,e.x))},getDihedralAngleOfVectors:function(e,t,r){var n=Kekule.CoordUtils,i=Kekule.GeometryUtils,o=i.getVectorCrossProduct(e,t),a=i.getVectorCrossProduct(t,r),s=n.getDistance(t)/1e5;if(n.isZero(o,s)||n.isZero(a,s))return-1;var l=n.standardize(t),u=i.getVectorScalarProduct(i.getVectorCrossProduct(o,a),l),h=i.getVectorScalarProduct(o,a),c=Math.atan2(u,h);return c<0&&(c+=2*Math.PI),c},getDihedralAngleOfPoints:function(e,t,r,n){var i=Kekule.CoordUtils,o=i.substract(t,e),a=i.substract(r,t),s=i.substract(n,r);return Kekule.GeometryUtils.getDihedralAngleOfVectors(o,a,s)},getPerpendicularCrossPointFromCoordToLine:function(e,t,r,n){var i,o={};if(Math.abs(t.x-r.x)<1e-10)o.x=t.x,o.y=e.y;else{var a=(r.y-t.y)/(r.x-t.x);o.x=(a*a*t.x+a*(e.y-t.y)+e.x)/(a*a+1),o.y=a*(o.x-t.x)+t.y}if(n)i=!0;else{var s={x:t.x-r.x,y:t.y-r.y};i=Math.abs(s.y)>Math.abs(s.x)?Math.sign(o.y-t.y)*Math.sign(o.y-r.y)<=0:Math.sign(o.x-t.x)*Math.sign(o.x-r.x)<=0}return i?o:null},getDistanceFromPointToLine:function(e,t,r,n){var i=Kekule.GeometryUtils.getPerpendicularCrossPointFromCoordToLine(e,t,r,n);if(i)return Kekule.CoordUtils.getDistance(e,i);var o=Kekule.CoordUtils.getDistance(e,t),a=Kekule.CoordUtils.getDistance(e,r);return Math.min(o,a)},getCrossPointOfLines:function(e,t,r,n){var i=(e.x-r.x)*(t.y-r.y)-(e.y-r.y)*(t.x-r.x),o=(e.x-n.x)*(t.y-n.y)-(e.y-n.y)*(t.x-n.x);if(i*o>=0)return null;var a=(r.x-e.x)*(n.y-e.y)-(r.y-e.y)*(n.x-e.x);if(a*(a+i-o)>=0)return null;var s=a/(o-i),l=s*(t.x-e.x),u=s*(t.y-e.y);return{x:e.x+l,y:e.y+u}},getCrossPointOfVectors:function(e,t){return Kekule.GeometryUtils.getCrossPointOfLines(e[0],e[1],t[0],t[1])},getCrossPointsOfVectorToCircle:function(e,t,r,n){var i=[],o=Kekule.CoordUtils,a=Kekule.NumUtils.isFloatEqual,s=n,l=[o.substract(e[0],t),o.substract(e[1],t)],u=l[1].y-l[0].y,h=l[0].x-l[1].x,c=l[1].x*l[0].y-l[0].x*l[1].y,d=r,f=[],p=4*u*u*c*c-4*(u*u+h*h)*(c*c-d*d*h*h);if(a(p,0,s))f=[-u*c/(u*u+h*h)];else if(p<0)f=[];else{var g=Math.sqrt(p);f=[(-2*u*c+g)/(2*(u*u+h*h)),(-2*u*c-g)/(2*(u*u+h*h))]}if(f&&f.length){var C=[];if(1===f.length&&a(h,0,s)){var y=Math.sqrt(d*d-f[0]*f[0]);a(y,0,s)?C=[0]:(C[0]=y,C[1]=-y,f[1]=f[0])}else for(var v=0,x=f.length;v<x;++v)C[v]=-(u*f[v]+c)/h;for(v=0,x=f.length;v<x;++v){var m=(f[v]-l[0].x)*(f[v]-l[1].x),O=(C[v]-l[0].y)*(C[v]-l[1].y);(a(u,0,s)&&m<=0||a(h,0,s)&&O<=0||m<=0&&O<=0)&&i.push(o.add({x:f[v],y:C[v]},t))}}return i},getCrossPointsOfCircles:function(e,t,r,n,i){if(Kekule.CoordUtils.getDistance(e,r)>t+n)return[];for(var o=t,a=n,s=e.x,l=r.x,u=e.y,h=r.y,c=(o*o-a*a+(l*l-s*s)+(h*h-u*u))/(2*(h-u)),d=(l-s)/(h-u),f=1+d*d,p=-(2*s+2*(c-u)*d),g=s*s+Math.sqr(c-u)-o*o,C=Math.sqrt(p*p-4*f*g),y=2*f,v=Kekule.NumUtils.isFloatEqual(C,0,i)?[-p]:[(-p+C)/y,(-p-C)/y],x=[],m=[],O=0,k=v.length;O<k;++O)x[O]=c-d*v[O],m.push({x:v[O],y:x[O]});return m},simplifyCurveToLineSegments:function(e,t){return t?e.length<=2?Kekule.ArrayUtils.clone(e):Kekule.GeometryUtils._simplifyCurvePartToLineSegments(e,0,e.length-1,t):e},_simplifyCurvePartToLineSegments:function(e,t,r,n){var i=Kekule.GeometryUtils,o=e[t],a=e[r];if(r-t<=1)return[o,a];for(var s=n,l=null,u=t+1;u<r;++u){var h=Kekule.GeometryUtils.getDistanceFromPointToLine(e[u],o,a);h>s&&(s=h,l=u)}if(null===l)return[o,a];var c=i._simplifyCurvePartToLineSegments(e,t,l,n),d=i._simplifyCurvePartToLineSegments(e,l,r,n);return d.shift(),[].concat(c).concat(d)}},Kekule.IntersectionState={EQUAL:0,CONTAINING:1,CONTAINED:2,OVERLAPPED:3,SEPARATED:4},Kekule.BoxUtils={createBox:function(e,t){var r={},n=e.x||0,i=e.y||0,o=t.x||0,a=t.y||0;return n<=o?(r.x1=n,r.x2=o):(r.x1=o,r.x2=n),i<=a?(r.y1=i,r.y2=a):(r.y1=a,r.y2=i),Kekule.ObjUtils.notUnset(e.z)&&Kekule.ObjUtils.notUnset(t.z)&&(e.z<=t.z?(r.z1=e.z,r.z2=t.z):(r.z1=t.z,r.z2=e.z)),r},clone:function(e){var t={x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2};return Kekule.ObjUtils.notUnset(e.z1)&&Kekule.ObjUtils.notUnset(e.z2)&&(t.z1=e.z1,t.z2=e.z2),t},convertToRect:function(e){var t=Kekule.BoxUtils.normalize(e);return Kekule.RectUtils.createRect(t.x1,t.y1,t.x2-t.x1,t.y2-t.y1)},normalize:function(e){var t={x1:Math.min(e.x1,e.x2),y1:Math.min(e.y1,e.y2),x2:Math.max(e.x1,e.x2),y2:Math.max(e.y1,e.y2)};return Kekule.ObjUtils.notUnset(e.z1)&&Kekule.ObjUtils.notUnset(e.z2)&&(t.z1=Math.min(e.z1,e.z2),t.z2=Math.max(e.z1,e.z2)),t},shiftBox:function(e,t,r,n){var i=t||0,o=r||0,a=n||0,s={x:e.x1+i,y:e.y1+o},l={x:e.x2+i,y:e.y2+o};return Kekule.ObjUtils.notUnset(e.z1)&&Kekule.ObjUtils.notUnset(e.z2)&&(s.z=e.z1+a,l.z=e.z2+a),Kekule.BoxUtils.createBox(s,l)},inflateBox:function(e,t,r,n){Kekule.ObjUtils.isUnset(r)&&(r=t),Kekule.ObjUtils.isUnset(n)&&(n=t);var i={x1:(i=Kekule.BoxUtils.normalize(e)).x1-t,y1:i.y1-r,x2:i.x2+t,y2:i.y2+r};return Kekule.ObjUtils.notUnset(i.z1)&&Kekule.ObjUtils.notUnset(i.z2)&&(i.z1=i.z1-n,i.z2=i.z2+n),i},getContainerBox:function(e,t){if(!e)return Kekule.BoxUtils.clone(t);if(!t)return Kekule.BoxUtils.clone(e);var r=Kekule.BoxUtils.normalize(e),n=Kekule.BoxUtils.normalize(t),i={x1:Math.min(r.x1,n.x1),y1:Math.min(r.y1,n.y1),x2:Math.max(r.x2,n.x2),y2:Math.max(r.y2,n.y2)};return Kekule.ObjUtils.notUnset(r.z1)&&Kekule.ObjUtils.notUnset(r.z2)&&Kekule.ObjUtils.notUnset(n.z1)&&Kekule.ObjUtils.notUnset(n.z2)&&(i.z1=Math.min(r.z1,n.z1),i.z2=Math.max(r.z2,n.z2)),i},getIntersection:function(e,t){var r=Kekule.BoxUtils.normalize(e),n=Kekule.BoxUtils.normalize(t),i={x1:Math.max(r.x1,n.x1),y1:Math.max(r.y1,n.y1),x2:Math.min(r.x2,n.x2),y2:Math.min(r.y2,n.y2)};return i.x1>i.x2||i.y1>i.y2?null:Kekule.ObjUtils.notUnset(r.z1)&&Kekule.ObjUtils.notUnset(r.z2)&&Kekule.ObjUtils.notUnset(n.z1)&&Kekule.ObjUtils.notUnset(n.z2)&&(i.z1=Math.max(r.z1,n.z1),i.z2=Math.min(r.z2,n.z2),i.z1>i.z2)?null:i},hasIntersection:function(e,t){return!!Kekule.BoxUtils.getIntersection(e,t)},isEqual:function(e,t){return Math.min(e.x1,e.x2)===Math.min(t.x1,t.x2)&&Math.max(e.x1,e.x2)===Math.max(t.x1,t.x2)&&Math.min(e.y1,e.y2)===Math.min(t.y1,t.y2)&&Math.max(e.y1,e.y2)===Math.max(t.y1,t.y2)},isInside:function(e,t){var r=e,n=t;return Math.min(r.x1,r.x2)>=Math.min(n.x1,n.x2)&&Math.max(r.x1,r.x2)<=Math.max(n.x1,n.x2)&&Math.min(r.y1,r.y2)>=Math.min(n.y1,n.y2)&&Math.max(r.y1,r.y2)<=Math.max(n.y1,n.y2)},getIntersectionState:function(e,t){var r=Kekule.BoxUtils,n=Kekule.IntersectionState;return r.isEqual(e,t)?n.EQUAL:r.isInside(e,t)?n.CONTAINED:r.isInside(t,e)?n.CONTAINING:r.hasIntersection(e,t)?n.OVERLAPPED:n.SEPARATED},getCenterCoord:function(e){var t={x:((e.x1||0)+(e.x2||0))/2,y:((e.y1||0)+(e.y2||0))/2};return(Kekule.ObjUtils.notUnset(e.z1)||Kekule.ObjUtils.notUnset(e.z2))&&(t.z=(e.z1||0+e.z2||0)/2),t},getMinMaxCoords:function(e){var t=Kekule.BoxUtils.normalize(e),r={min:{x:t.x1,y:t.y1},max:{x:t.x2,y:t.y2}};return Kekule.ObjUtils.notUnset(t.z1)&&(r.min.z=t.z1,r.max.z=t.z2),r},getCornerCoords:function(e){var t=Kekule.BoxUtils.normalize(e);return Kekule.ObjUtils.isUnset(t.z1)?[{x:t.x1,y:t.y1},{x:t.x1,y:t.y2},{x:t.x2,y:t.y1},{x:t.x2,y:t.y2}]:[{x:t.x1,y:t.y1,z:t.z1},{x:t.x1,y:t.y2,z:t.z1},{x:t.x2,y:t.y1,z:t.z1},{x:t.x2,y:t.y2,z:t.z1},{x:t.x1,y:t.y1,z:t.z2},{x:t.x1,y:t.y2,z:t.z2},{x:t.x2,y:t.y1,z:t.z2},{x:t.x2,y:t.y2,z:t.z2}]},transform2D:function(e,t){for(var r=Kekule.BoxUtils.getCornerCoords(e),n=[],i=0,o=r.length;i<o;++i)n.push(Kekule.CoordUtils.transform2D(r[i],t));return Kekule.CoordUtils.getContainerBox(n)},transform3D:function(e,t){for(var r=Kekule.BoxUtils.getCornerCoords(e),n=[],i=0,o=r.length;i<o;++i)n.push(Kekule.CoordUtils.transform3D(r[i],t));return Kekule.CoordUtils.getContainerBox(n)}},Kekule.RectUtils={createRect:function(e,t,r,n){return{left:e,top:t,width:r,height:n}},clone:function(e){return{left:e.left,top:e.top,width:e.width,height:e.height}},isZero:function(e){return 0===e.width&&0===e.height},convertToBox:function(e){var t=Kekule.CoordUtils.create(e.left,e.top),r=Kekule.CoordUtils.create(e.left+e.width,e.top+e.height);return Kekule.BoxUtils.createBox(t,r)},inflateRect:function(e,t,r){return Kekule.ObjUtils.isUnset(r)&&(r=t),Kekule.RectUtils.createRect(e.left,e.top,e.width+t,e.height+r)},shiftRect:function(e,t,r){var n=t||0,i=r||0;return Kekule.RectUtils.createRect(e.left+n,e.top+i,e.width,e.height)},getContainerRect:function(e,t){var r=Kekule.RectUtils.convertToBox(e),n=Kekule.RectUtils.convertToBox(t),i=Kekule.BoxUtils.getContainerBox(r,n);return Kekule.BoxUtils.convertToRect(i)},getIntersection:function(e,t){var r=Kekule.RectUtils.convertToBox(e),n=Kekule.RectUtils.convertToBox(t),i=Kekule.BoxUtils.getIntersection(r,n);return i?Kekule.BoxUtils.convertToRect(i):null},hasIntersection:function(e,t){return!!Kekule.RectUtils.getIntersection(e,t)}},Kekule.ZoomUtils={PREDEFINED_ZOOM_RATIOS:[.1,.3,.5,.66,.8,.9,1,1.1,1.25,1.5,1.75,2,2.5,3,4,5,7,10,15,20],getNearestZoomLevel:function(e,t){var r=t||Kekule.ZoomUtils.PREDEFINED_ZOOM_RATIOS,n=r.length;if(e>r[n-1])return r[n-1];if(e<r[0])return r[0];for(var i=0;i<n-1;++i){var o=r[i],a=r[i+1];if(e>=o&&e<=a)return 1===o||1===a?1:(e-o)/(a-o)<=.5?o:a}},getNextZoomInRatio:function(e,t,r){t||(t=1);var n=r||Kekule.ZoomUtils.PREDEFINED_ZOOM_RATIOS,i=n.length;if(e<n[i-1])for(var o=0;o<i;++o)if(n[o]>e)return n[Math.min(o+t,i)-1];return e},getNextZoomOutRatio:function(e,t,r){t||(t=1);var n=r||Kekule.ZoomUtils.PREDEFINED_ZOOM_RATIOS,i=n.length;if(e>n[0])for(var o=i-1;o>=0;--o)if(n[o]<e)return n[Math.max(o-t+1,0)];return e}},Kekule.DomHelper=Class.create(ObjectEx,{CLASS_NAME:"Kekule.DomHelper",NAMESPACE_DEFINE_PREFIX:"xmlns",NAMESPACE_DELIMITER:":",ERR_EMPTY_DOC:"Document is empty",ERR_ELEMENT_NOTSET:"Element not set",initialize:function(e){this.tryApplySuper("initialize"),this._supportNsMethods=null,e&&this.setDocument(e)},initProperties:function(){this.defineProp("document",{dataType:DataType.OBJECT,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("document");if(!e){var t=this.getPropStoreFieldValue("rootElement");e=t?t.ownerDocument:null}return e},setter:function(e){e!=this.getPropStoreFieldValue("document")&&(this.setPropStoreFieldValue("document",e),this.analysisRootElem())}}),this.defineProp("rootElement",{dataType:DataType.OBJECT,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("rootElement");if(!e){var t=this.getPropStoreFieldValue("document");e=t?t.documentElement:null}return e},setter:function(e){this.setPropStoreFieldValue("rootElement",e),this.analysisRootElem()}}),this.defineProp("namespaces",{dataType:DataType.ARRAY,serializable:!1,getter:function(){return this.getPropStoreFieldValue("namespaces")||this.setPropStoreFieldValue("namespaces",[]),this.getPropStoreFieldValue("namespaces")}}),this.defineProp("defNamespaceURI",{dataType:DataType.STRING,serializable:!1}),this.defineProp("forceAnalysisDoc",{dataType:DataType.BOOL})},analysisRootElem:function(){this.setNamespaces([]),this.setDefNamespaceURI(null);var e=this.getRootElement();if(e){var t=e.ownerDocument;if(this._supportNsMethods=!!t.getElementsByTagNameNS,!this._supportNsMethods||this.getForceAnalysisDoc())for(var r=0,n=e.attributes.length;r<n;++r){var i=e.attributes[r],o=i.name;if(o&&o.indexOf(this.NAMESPACE_DEFINE_PREFIX)>=0){var a=i.value,s=o.indexOf(this.NAMESPACE_DELIMITER),l=s>=0?o.substring(s+1):null;this.getNamespaces().push({namespaceURI:a,prefix:l}),l||this.setDefNamespaceURI(a)}}}},_getEmptyDocErrorMsg:function(){return Kekule.hasLocalRes()?Kekule.$L("ErrorMsg.EMPTY_DOC"):this.ERR_EMPTY_DOC},_getElementNotSetErrorMsg:function(){return Kekule.hasLocalRes()?Kekule.$L("ErrorMsg.ELEMENT_NOTSET"):this.ELEMENT_NOTSET},assertDocAvailable:function(e){return!!e||(Kekule.raise(this._getEmptyDocErrorMsg()),!1)},assertElementAvailable:function(e){return!!e||(Kekule.raise(this._getElementNotSetErrorMsg()),!1)},getNsPrefix:function(e){if(e==this.getDefNamespaceURI())return"";for(var t=this.getNamespaces(),r=0,n=t.length;r<n;++r)if(t[r].namespaceURI==e)return t[r].prefix;return null},getQualifiedName:function(e,t){var r=this.getNsPrefix(e);return null===r?null:r?r+this.NAMESPACE_DELIMITER+t:t},createElementNS:function(e,t){var r=this.getDocument();return this.assertDocAvailable(r)?this._supportNsMethods?r.createElementNS(e,t):r.createElement(t):null},getElementsByTagNameNS:function(e,t,r){var n=this.getPropStoreFieldValue("document")||this.getPropStoreFieldValue("rootElement"),i=this.getDocument();if(!this.assertDocAvailable(i))return null;if(this._supportNsMethods)return e||(e="*"),r?r.getElementsByTagNameNS(e,t):n.getElementsByTagNameNS(e,t);var o=this.getQualifiedName(e,t);return null===o?[]:r?r.getElementsByTagName(o):n.getElementsByTagName(o)},getAttributeNodeNS:function(e,t,r){if(!this.assertElementAvailable(r))return null;if(this._supportNsMethods)return e||(e="*"),r.getAttributeNodeNS(e,t);var n=this.getQualifiedName(e,t);return null===n?null:r.getAttributeNode(n)},getAttributeNS:function(e,t,r){if(!this.assertElementAvailable(r))return null;if(this._supportNsMethods)return e||(e="*"),r.getAttributeNS(e,t);var n=this.getQualifiedName(e,t);return null===n?null:r.getAttribute(n)},setAttributeNS:function(e,t,r,n){if(!this.assertElementAvailable(n))return null;if(this._supportNsMethods)return n.setAttributeNS(e,t,r);var i=this.getQualifiedName(e,t);return null===i?null:n.setAttribute(i,r)}}),Kekule.DomUtils={namespaceMatched:function(e,t,r){return void 0===r&&(r=!0),e.namespaceURI==t||r&&!e.namespaceURI},isElement:function(e){return e&&e.tagName&&e.nodeType},getElementText:function(e){for(var t="",r=0,n=e.childNodes.length;r<n;++r)3==e.childNodes[r].nodeType&&(t+=e.childNodes[r].nodeValue);return t},setElementText:function(e,t){for(var r=0,n=e.childNodes.length;r<n;++r)if(3==e.childNodes[r].nodeType)return e.childNodes[r].nodeValue=t,t;var i=e.ownerDocument.createTextNode(t);return e.appendChild(i),t},getLocalName:function(e){return e.localName||e.baseName||e.nodeName},getChildNodesOfTypes:function(e,t){for(var r=[],n=Kekule.ArrayUtils.toArray(t),i=0,o=e.childNodes.length;i<o;++i){var a=e.childNodes[i];(!t||n.indexOf(a.nodeType)>=0)&&r.push(a)}return r},getFirstChildElem:function(e,t,r,n){for(var i=0,o=e.childNodes.length;i<o;++i){var a=e.childNodes[i];if(a.nodeType===Node.ELEMENT_NODE&&(t&&t.toLowerCase()===a.tagName.toLowerCase()||r&&r.toLowerCase()===Kekule.DomUtils.getLocalName(a).toLowerCase()||!t&&!r)&&(!n||Kekule.DomUtils.namespaceMatched(a,n)))return a}},getDirectChildElems:function(e,t,r,n){for(var i=[],o=0,a=e.childNodes.length;o<a;++o){var s=e.childNodes[o];s.nodeType===Node.ELEMENT_NODE&&(t&&t.toLowerCase()===s.tagName.toLowerCase()||r&&r.toLowerCase()===Kekule.DomUtils.getLocalName(s).toLowerCase()||!t&&!r)&&(n&&!Kekule.DomUtils.namespaceMatched(s,n)||i.push(s))}return i},getDirectChildElemsOfAttribValues:function(e,t,r,n,i){for(var o=Kekule.DomUtils.getDirectChildElems(e,r,n,i),a=[],s=0,l=o.length;s<l;++s){for(var u=!0,h=0,c=t.length;h<c;++h){var d=Kekule.ObjUtils.getOwnedFieldNames(t[h])[0];if(o[s].getAttribute(d)!=t[h][d]){u=!1;break}}u&&a.push(o[s])}return a},getParentNode:function(e,t){var r=t||{},n=e.parentNode;return n||(r.acrossShadowRoot&&e.host?e.host:null)},isDescendantOf:function(e,t,r){var n=r||{};try{if(e&&t){if(e.documentElement)return!1;if(e.ownerDocument===t)return!0;for(var i=Kekule.DomUtils.getParentNode,o=i(e,n);o;){if(o===t)return!0;o=i(o,n)}}return!1}catch(e){return!1}},isOrIsDescendantOf:function(e,t,r){return e===t||Kekule.DomUtils.isDescendantOf(e,t,r)},getNearestAncestorByTagName:function(e,t,r){var n=t.toLowerCase();if(r&&e.tagName&&e.tagName.toLowerCase()===n)return e;for(var i=e.parentNode;i&&i.tagName;){if(i.tagName.toLowerCase()===n)return i;i=i.parentNode}return null},getSameNSAttributeValue:function(e,t,r){return e.getAttribute(t)},setSameNSAttributeValue:function(e,t,r,n){return e.setAttribute(t,r)},fetchAttributeValuesToArray:function(e,t,r){for(var n=[],i=0,o=e.attributes.length;i<o;++i){var a=e.attributes[i];if(!t||Kekule.DomUtils.namespaceMatched(a,t,!0)){var s;if(r)try{s=Kekule.DomUtils.getLocalName(a)}catch(e){s=a.name}else s=a.name;n.push({name:s,value:a.value})}}return n},fetchAttributeValuesToJson:function(e,t,r){for(var n={},i=0,o=e.attributes.length;i<o;++i){var a=e.attributes[i];if(!t||Kekule.DomUtils.namespaceMatched(a,t,!0)){var s;if(r)try{s=Kekule.DomUtils.getLocalName(a)}catch(e){s=a.name}else s=a.name;n[s]=a.value}}return n},hasAttribute:function(e,t){return e.hasAttribute?e.hasAttribute(t):!!e.getAttribute(t)},isDataAttribName:function(e){return e.toString().startsWith("data-")},getDataAttribCoreName:function(e){return Kekule.DomUtils.isDataAttribName(e)?e.substr(5):null},getDataAttrib:function(e,t){return e.dataset?e.dataset[t]:e.getAttribute("data-"+t.toString().hyphenize())},setDataAttrib:function(e,t,r){e.dataset?e.dataset[t]=r:e.setAttribute("data-"+t.toString().hyphenize(),r)},getDataset:function(e){if(e.dataset)return e.dataset;for(var t={},r=e.attributes,n=0,i=r.length;n<i;++n){var o=r[n],a=o.name;0===a.toLowerCase().indexOf("data-")&&(t[a.substring(5).camelize()]=o.value)}return t},clearChildContent:function(e){for(var t=Kekule.ArrayUtils.toArray(e.childNodes),r=t.length-1;r>=0;--r){var n=t[r];n.nodeType!==Node.ATTRIBUTE_NODE&&e.removeChild(n)}return e},replaceTagName:function(e,t){if(e.tagName.toLowerCase()!==t.toLowerCase()){for(var r=e.ownerDocument.createElement(t),n=Kekule.DomUtils.fetchAttributeValuesToArray(e),i=0,o=n.length;i<o;++i)r.setAttribute(n[i].name,n[i].value);var a=Kekule.DomUtils.getDirectChildElems(e);for(i=0,o=a.length;i<o;++i)r.appendChild(a[i]);var s=e.parentNode,l=e.nextSibling;return s.removeChild(e),l?s.insertBefore(r,l):s.appendChild(r),r}return e},setElemAttributes:function(e,t){for(var r=Kekule.ObjUtils.getOwnedFieldNames(t),n=0,i=r.length;n<i;++n){var o=r[n],a=t[o];o&&a&&e.setAttribute(o,a)}return e},isInDomTree:function(e,t,r){var n=r||{};if(!e)return!1;if(t||(t=e.ownerDocument),t){if(!n.acrossShadowRoot&&e.getRootNode)return e.getRootNode()===t;var i=t.documentElement;return Kekule.DomUtils.isDescendantOf(e,i,r)||e===i}return!1},isInShadowRoot:function(e){if("undefined"==typeof ShadowRoot)return!1;try{return(e.getRootNode&&e.getRootNode())instanceof ShadowRoot}catch(e){return!1}}},Kekule.DataSrcAttribUtils={isUrlBasedValue:function(e){return 0===e.toLowerCase().indexOf("url(")},getUrl:function(e){var t=e.trim();if(0===t.toLowerCase().indexOf("url(")){var r=t.lastIndexOf(")");return t=t.substring(4,r)}return null},getElementContent:function(e){if(!e)return null;var t=e.innerHTML;return t=t.ltrim()},getElementMimeType:function(e){return e.getAttribute("type")}},Kekule.ScriptFileUtils={_existedScriptUrls:new Kekule.MapEx,appendScriptFile:function(e,t,r){var n;if(e){if((n=Kekule.ScriptFileUtils._existedScriptUrls.get(e))||(n=[],Kekule.ScriptFileUtils._existedScriptUrls.set(e,n)),n.indexOf(t)>=0)return void(r&&r(null));var i=e.createElement("script");return i.src=t,i.onerror=function(e){r&&r(e)},i.onload=i.onreadystatechange=function(e){if(!i._loaded){var o=i.readyState;void 0!==o&&"loaded"!==o&&"complete"!==o||(i._loaded=!0,i.onload=i.onreadystatechange=null,n.push(t),r&&r(null))}},(e.getElementsByTagName("head")[0]||e.body).appendChild(i),i}var o=Kekule.$jsRoot.__$kekule_scriptfile_utils__;if(o&&o.appendScriptFile)return o.appendScriptFile(e,t,r)},appendScriptFiles:function(e,t,r){var n=[].concat(t),i=function(e,t,r,n){if(t.length<=0)r&&(n.length?r(new Error("Error in loading: "+n.join("; "))):r(null));else{var o=t.shift();Kekule.ScriptFileUtils.appendScriptFile(e,o,function(a){a&&n.push(o+": "+a?a.message||a:""),i(e,t,r,n)})}};i(e,n,r,[])}},Kekule.ExternalResourceType={JS_OBJ:"jsObject",STYLESHEET:"stylesheet",DATA:"data",OTHER:"other"},Kekule.ExternalResourceType.DEFAULT=Kekule.ExternalResourceType.JS_OBJ,Kekule.ExternalResourceManager=Class.create(ObjectEx,{CLASS_NAME:"Kekule.ExternalResourceManager",initialize:function(){this.tryApplySuper("initialize"),this.setPropStoreFieldValue("resources",{})},doFinalize:function(){this.setPropStoreFieldValue("resources",null),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("resources",{dataType:DataType.HASH,serializable:!1,setter:null})},register:function(e,t,r,n){var i=this.getResources();i[e]&&this.unregister(e),i[e]={name:e,resource:t,resourceType:r||Kekule.ExternalResourceType.DEFAULT},this.invokeEvent("resourceRegistered",{name:e,resource:t,resourceType:r}),this.invokeEvent(e+"Registered",{name:e,resource:t,resourceType:r})},unregister:function(e){var t=this.getResources();if(t[e]){var r=t[e];this.invokeEvent("resourceUnregistered",r),this.invokeEvent(e+"Unregistered",r),delete t[e]}},getResourceDetails:function(e){return this.getResources()[e]},getResource:function(e){var t=this.getResourceDetails(e);return t&&t.resource}}),Kekule.ClassUtils.makeSingleton(Kekule.ExternalResourceManager),Kekule.externalResourceManager=Kekule.ExternalResourceManager.getInstance();