/* TidBits OoJs - version: 13.08.20-alpha README: https://github.com/najamelan/TidBits_Javascript_OoJs */ var TidBits=TidBits||{}; (function(y,q){function t(a,d){this.classID=a;this.type=d;this.table={}}function I(a,d,c,b,e){this.Static=d;this.IFace=e;this.Class=a[c];this.name=c;this.id=b;this.bases=[];this.allBases=[];this.accessibleBases=[];this.inaccessibleBases=[];this.friends=[];this.staticLayout=new t(d.ooID,"staticLayout");this.instanceLayout=new t(d.ooID,"instanceLayout");this.layoutInstance=null;this.flags=0;this.virtuals={};this.namespace=a}function z(a,d,c){this._this=a;this.classID=d;this.iFace=c;this.state={};this.methods= {};this.supers=[];this.flags=0}function u(){return null}function J(a,d,c){function b(){}function e(){}var f=a[d];Object.defineProperty(b,"Public",{value:A});Object.defineProperty(b,"Protected",{value:B});Object.defineProperty(b,"Private",{value:C});Object.defineProperty(b,"Friends",{value:K});Object.defineProperty(b,"getPrivateInstance",{value:L});Object.defineProperty(b,"ooID",{value:v()});Object.defineProperty(f,"ooID",{value:b.ooID});Object.defineProperty(b,"toString",{value:function(){return"function Static(){ /*"+ d+"*/ }"}});Object.defineProperty(f,"toString",{value:function(){return"function "+d+"()"}});l[b.ooID]=new I(a,b,d,b.ooID,e);k[b.ooID]=new z(b,b.ooID,f);n[d]=b.ooID;if(c!==q){Array.isArray(c)||(c=Array(c));for(var h=c.length-1;0<=h;--h){var g={as:"private",namespace:a};"string"===typeof c[h]&&(c[h]={inherit:c[h]});c[h]=r(g,c[h]);if(0>["public","private","protected"].indexOf(c[h].as))throw Error("Invalid class access level in class: "+d+". Trying to inherit "+c[h].inherit+" as "+c[h].as+". Only 'public', 'private' or 'protected' are supported"); }l[b.ooID].bases=c;for(var s,h=c.length-1;0<=h;--h)(s=n[c[h].inherit])&&k[b.ooID].supers.push(s);f.prototype=Object.create(c[0].namespace[c[0].inherit].prototype);M(b.ooID)}Object.defineProperty(f.prototype,"constructor",{configurable:!0,value:f});Object.defineProperty(f.prototype,"Public",{configurable:!0,value:A});Object.defineProperty(f.prototype,"Protected",{configurable:!0,value:B});Object.defineProperty(f.prototype,"Private",{configurable:!0,value:C});Object.defineProperty(f.prototype,"Super", {configurable:!0,value:N});Object.defineProperty(f.prototype,"Virtual",{configurable:!0,value:O});e.prototype=Object.create(f.prototype);return b}function M(a){a=l[a];for(var d=a.accessibleBases,c=a.inaccessibleBases,b=a.allBases,e=[],f=a.bases.length-1;0<=f;--f){var h=a.bases[f].inherit,g=n[h];if(g)for(d.push(h),b.push(h),e.push.apply(d,l[g].accessibleBases),e.push.apply(c,l[g].inaccessibleBases),e.push.apply(b,l[g].allBases),h=l[g].bases.length-1;0<=h;--h){var k=l[g].bases[h],m=d.indexOf(k.inherit); "private"===k.as&&-1!==m&&e.push.apply(c,a.accessibleBases.splice(m,1))}}}function A(){return w.call(this,arguments,g.PUBLIC)}function B(){w.call(this,arguments,g.PROTECTED)}function C(){w.call(this,arguments,g.PRIVATE)}function K(){var a=l[k[this.ooID].classID];this===a.Static&&(a.friends=[].concat(Array.prototype.slice.call(arguments,0,arguments.length)))}function L(a){if(this!==l[k[this.ooID].classID].Static)return null;var d=[];a=a.ooID;for(var c=!1,b=null;a=x(a,this.ooID,!0,c);)d.unshift(k[a]._this), c=!0;if(1===d.length)return d.pop();if(1a.classMeta.accessibleBases.indexOf(e)&&!a.layout.get(b,e))throw new TypeError(e+" is not an accessible base of "+a.classMeta.name);if(a.accessLvl===g.VIRTUAL)throw Error("Can't make base methods virtual ("+d+") in "+a.classMeta.name);}}else throw new TypeError("Parameters to this.Public/Private/Protected have to be either strings or references to functions. Got: "+ d+" in class "+a.classMeta.name);var h,f=e||a.classMeta.name;if(h=a.layout.get(b,f))h=a.accessLvl&g.VIRTUAL?h.flags|g.VIRTUAL:a.accessLvl|h.flags&g.VIRTUAL;else if(c||e)h=a.accessLvl;else throw Error("Couldn't find property: "+b+" in class: "+a.classMeta.name);e&&a.layout.get(b)&&a.layout.get(b).ownerID!==n[f]||(h|=g.ACTIVE);a.layout.set({name:b,reference:c,flags:h,ownerID:n[f],setterID:a.classID});a.accessLvl&g.VIRTUAL&&(a.virtuals[b]=a.virtuals[b]||[],a.virtuals[b].push(a.layout.get(b,a.classID)))} function R(a,d){if(!(this.flags&g.PRIVATE)&&this.flags&g.ACTIVE){for(var c,b=this.flags&~g.VIRTUAL,e=a.classMeta.bases.length-1;0<=e;--e)a.classMeta.bases[e].inherit===d.name&&(c=a.classMeta.bases[e].as);if("private"===c||"protected"===c)c="private"===c?g.PRIVATE:g.PROTECTED,b&=~g.PUBLIC&~g.PROTECTED,b|=c;a.layout.set({name:this.name,ownerID:this.ownerID,setterID:this.setterID,reference:this.reference,flags:b})}}function S(a,d,c){c=x(this.ooID,c);delete k[c]._this[d];Object.defineProperty(k[c]._this, d,{enumerable:!0,configurable:!0,get:function(b,a){return function(){return b.bind(a)}}(a.layout.get(d,a.classID).reference,this)})}function H(a,d){if(this.flags&d.accessLvl&&this.setterID===d.classID)if(this.ownerID!==d.classID){var c=d.layout.get(this.name),b=d.layout.get(this.name,d.classID),e=l[this.ownerID].name;if(this.flags&g.PUBLIC)for(d.instRec.iFace[e]=d.instRec.iFace[e]||{},b=b?[d.instRec.iFace[e]]:[d.instRec.iFace,d.instRec.iFace[e]],c=b.length-1;0<=c;--c)Object.defineProperty(b[c],this.name, Object.getOwnPropertyDescriptor(d.instRec._this[e],this.name));else delete d.instRec.iFace[e][this.name],c&&c.ownerID===this.ownerID&&delete d.instRec.iFace[this.name]}else for(this.flags&g.PUBLIC||delete d.instRec.iFace[this.name],e=this.flags&g.PUBLIC?[a,d.iFace]:[a],b=a.ooID,c=e.length-1;0<=c;--c)if(this.reference){var f=x(b,this.ownerID),f=k[f].methods;f[this.name]=f[this.name]||this.reference.bind(a);Object.defineProperty(e[c],this.name,{enumerable:!0,configurable:!0,get:function(a){return function(){return a}}(f[this.name])})}else Object.defineProperty(e[c], this.name,{enumerable:!0,configurable:!0,get:function(a,b){return function(){return k[b].state[a]}}(this.name,b),set:function(a,b){return function(c){k[b].state[a]=c}}(this.name,b)})}function x(a,d,c,b){if(!b&&(k[a].classID===d||c&&-1!==l[k[a].classID].friends.indexOf(l[d].name)))return a;for(var e=null,f,g=k[a].supers.length-1;f=k[a].supers[g];--g)if(f.classID===d||c&&-1!==l[k[f].classID].friends.indexOf(l[d].name)){e=f;break}else if(null!==(e=x(f,d,c,b)))break;return e}function D(){Object.defineProperty(this, "ooID",{value:v()});var a=new l[this.constructor.ooID].IFace;Object.defineProperty(a,"ooID",{value:this.ooID});k[this.ooID]=new z(this,this.constructor.ooID,a)}function v(){return++v.counter}function r(a,d,c){for(var b in d){var e=!!Object.getOwnPropertyDescriptor(d,b).get;if(d.hasOwnProperty(b)&&(!0!==c||e)){var f=Object.getOwnPropertyDescriptor(d,b);e?Object.defineProperty(a,b,{configurable:!0,enumerable:f.enumerable,get:f.get,set:f.set}):Object.defineProperty(a,b,{configurable:!0,enumerable:f.enumerable, writable:f.writable,value:f.value})}}return a}if(!y.OoJs){y.OoJs=u;var l={},k={},n={},g={PRIVATE:1,PROTECTED:2,PUBLIC:4,VIRTUAL:8,INHERITED_INSTANCE:16,INHERITED_STATIC:32,BASE_ACCESSORS:64,STORED:128,SUPERS:256,ACTIVE:512};t.prototype.get=function(a,d){a="OoJs__"+a;if(this.table[a]===q)return q;if(d===q)for(var c=this.table[a].length-1;0<=c;--c)if(this.table[a][c].flags&g.ACTIVE)return this.table[a][c];"string"===typeof d&&(d=n[d]);for(c=this.table[a].length-1;0<=c;--c)if(this.table[a][c].ownerID=== d)return this.table[a][c];return q};t.prototype.getAll=function(a){return this.table["OoJs__"+a]};t.prototype.setActive=function(a,d){console.assert(this.table[a]!==q);"string"===typeof d&&(d=n[d]);for(var c=this.table[a].length-1;0<=c;--c)this.table[a][c].flags=this.table[a][c].ownerID===d?this.table[a][c].flags|g.ACTIVE:this.table[a][c].flags&~g.ACTIVE};t.prototype.set=function(a){var d="OoJs__"+a.name;console.assert(a.ownerID);console.assert(a.name);this.table[d]===q?this.table[d]=[a]:this.get(d.substring(6), a.ownerID)?r(this.get(d.substring(6),a.ownerID),a):this.table[d].push(a);a.flags&g.ACTIVE&&this.setActive(d,a.ownerID)};t.prototype.each=function(){var a=Array.prototype.splice.call(arguments,0,1).pop(),d=[],c;for(c in this.table)if(this.table.hasOwnProperty(c))for(var b=this.table[c].length-1;0<=b;--b)d.push(a.apply(this.table[c][b],arguments));return d};u.setupClass=J;u.typeOf=P;u.extend=r;v.counter=0}})(TidBits);"undefined"!==typeof module&&(module.exports=TidBits);