imba
Version:
2 lines (1 loc) • 5.99 kB
JavaScript
var g=Symbol.for("#__init__"),T=Symbol.for("#__initor__");var E=Symbol.for("#meta"),_=Symbol.for("imba");var W={SUPERCALLS:1<<3,CONSTRUCTOR:1<<4},d={IsExtension:1<<0,IsTag:1<<1,HasDescriptors:1<<2,HasSuperCalls:1<<3,HasConstructor:1<<4,HasFields:1<<5,HasMixins:1<<6,HasInitor:1<<7,HasDecorators:1<<8,IsObjectExtension:1<<9},m=new Map,L=globalThis[_]||(globalThis[_]={counter:0,classes:m});function y(r,t={}){var e;return m.has(r)||m.set(r,{symbol:Symbol(r.name),parent:(e=Object.getPrototypeOf(r.prototype))==null?void 0:e.constructor,for:r,uses:null,inits:null,id:L.counter++,...t}),m.get(r)}function $(r,t){var e;return typeof t=="string"?typeof r===t:(e=t==null?void 0:t[Symbol.hasInstance])==null?void 0:e.call(t,r)}function j(r){var t;return((t=r==null?void 0:r.toIterable)==null?void 0:t.call(r))||r}function Z(r,t){if(!r||!t)return!1;if(r.get)return t.get===r.get;if(r.set)return t.set===r.set;if(r.value)return r.value===t.value}function C(r,t,e,n={}){let i=r.constructor;!e&&t&&(e=Object.getOwnPropertyDescriptors(t),delete e.constructor,e[g]&&(console.warn(`Cannot define plain fields when extending class ${i.name}`),delete e[g]));let o=y(i);if(o&&o.augments){let u=new Map;for(let s of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(r,s);for(let p of o.augments){let c=u.get(p);c||u.set(p,c={});let h=Object.getOwnPropertyDescriptor(p.prototype,s);h&&!Z(l,h)?console.warn("wont extend",s,h,l):c[s]=e[s]}}for(let[s,l]of u)Object.keys(l).length&&C(s.prototype,null,l)}return Object.defineProperties(r,e),r}function v(r,t){let e=y(r),n=y(t);if(n.parent&&!(r.prototype instanceof n.parent))throw new Error(`Mixin ${t.name} has superclass not present in target class`);if(!n.augments){n.augments=new Set;let o=n.ref=Symbol(t.name),u=Object[Symbol.hasInstance];t.prototype[o]=!0,Object.defineProperty(t,Symbol.hasInstance,{value:function(s){return this===t?s&&!!s[o]:u.call(this,s)}})}if(r.prototype[n.ref])return r;if(n.uses)for(let o of n.uses)v(r,o);n.augments.add(r),e.uses||(e.uses=[]),e.uses.push(t);let i=Object.getOwnPropertyDescriptors(t.prototype);return delete i.constructor,i[g]&&(e.inits||(e.inits=[]),e.inits.push(t.prototype[g]),delete i[g]),Object.defineProperties(r.prototype,i),(t==null?void 0:t.mixed)instanceof Function&&t.mixed(r),r}var a={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(r,t,...e)=>a.target[t].apply(a.self,e),get:(r,t)=>Reflect.get(a.target,t,a.self),set:(r,t,e,n)=>Reflect.set(a.target,t,e,a.self)})};function f(r,t,e,n,i=null){var p;let o=Object.getPrototypeOf(r.prototype),u=n&d.HasMixins,s;if(u&&(m.set(r,m.get(o.constructor)),o=Object.getPrototypeOf(o)),i){let c=n&d.IsObjectExtension?i:i.prototype,h=y(r);if(h.uses){i===c&&console.warn("Cannot extend object with mixins");for(let F of h.uses)v(i,F)}return n&d.HasSuperCalls&&(a.cache[t]=Object.create(Object.getPrototypeOf(c),Object.getOwnPropertyDescriptors(c))),C(c,r.prototype),i}let l=o==null?void 0:o.constructor;if(s=y(r,{symbol:t}),Object.defineProperty(r,E,{value:s,enumerable:!1,configurable:!0}),e&&r.name!==e&&Object.defineProperty(r,"name",{value:e,configurable:!0}),s.flags=n,n&d.HasConstructor&&(r.prototype[T]=t),s.uses)for(let c of s.uses)(p=c.mixes)==null||p.call(c,r);return(l==null?void 0:l.inherited)instanceof Function&&l.inherited(r),r}var b=Symbol(),x=class{get size(){return this.length}set size(t){this.length=t}get emptyΦ(){return this.size===0}get anyΦ(){return this.size>0}get manyΦ(){return this.size>1}get oneΦ(){return this.size===1}get random(){return this[Math.floor(Math.random()*this.length)]}clear(){return this.length=0,this}async resolve(){return await Promise.all(this)}get unique(){let t=[];for(let e=0,n=j(this),i=n.length;e<i;e++){let o=n[e];t.indexOf(o)==-1&&t.push(o)}return t}add(t){return this.has(t)||this.push(t),t}has(t){return this.includes(t)}sorted(t,e=!1){let n=this.slice(),i=t;return typeof t=="string"?i=function(o){return o[t]}:$(t,Map)?i=function(o){return t.get(o)}:$(t,Function)||(i=function(o){return o}),e?n.sort(function(o,u){let s=i(o),l=i(u);return s<l?1:s>l?-1:0}):n.sort(function(o,u){let s=i(o),l=i(u);return s>l?1:s<l?-1:0})}delete(t){let e=this.indexOf(t);return e<0?!1:(this.splice(e,1),!0)}},H=x;(()=>{f(x,b,"Array",1,Array)})();globalThis.sleep=function(r=0,t){return new Promise(function(e){return setTimeout(function(){return t&&t(),e()},r)})};Math.randΞint=function(r,t){return r=Math.ceil(r),t=Math.floor(t),Math.floor(Math.random()*(t-r+1)+r)};Math.randΞfloat=function(r,t){return Math.random()*(t-r)+r};Math.randΞbool=function(){return Math.random()<.5};var K=Symbol(),O=class{to(t){var e=this;return Array.from({length:t-this+1},function(n,i){return e+i})}floor(){return Math.floor(this)}ceil(){return Math.ceil(this)}times(t){let e=0,n=this;for(;e<n;)t(e++)}round(t=1){if(t!=1){let e=1/t;return Math.round(this*e)/e}return Math.round(this)}clamp(t,e){return typeof e!="number"?Math.max(this,t):Math.min(typeof t!="number"?this:Math.max(this,t),e)}lerp(t,e,n=0,i=1){let o=(this-t)/(e-t);return n+o*(i-n)}},z=O;(()=>{f(O,K,"Number",1,Number)})();var N=Symbol(),S=class{filter(t){return new Set(Array.from(this).filter(t))}},D=S;(()=>{f(S,N,"Set",1,Set)})();var U=Symbol(),M=class{setnx(t,e){var n;return(n=this.get(t))!=null?n:this.set(t,e)&&e}},A=M;(()=>{f(M,U,"WeakMap",1,WeakMap)})();var V=Symbol(),w=class{setnx(t,e){var n;return(n=this.get(t))!=null?n:this.set(t,e)&&e}},I=w;(()=>{f(w,V,"Map",1,Map)})();var q=Symbol(),P=class{get upperΦ(){return/^[A-Z][A-Z_\d]*$/.test(this)}get numΦ(){return this.intΦ||this.floatΦ}get intΦ(){return/^-?(0|[1-9]\d*)$/.test(this)}get floatΦ(){return/^-?\d+\.\d+$/.test(this)}get pascalΦ(){return/^[A-Z]+[a-z]+[A-Za-z]*/.test(this)}get slug(){let t=this.normalize("NFKD");return t=t.replace(/[\u0300-\u036f]/g,""),t=t.trim(),t=t.toLowerCase(),t=t.replace(/[^a-z0-9 -]/g,""),t=t.replace(/\s+/g,"-"),t=t.replace(/-+/g,"-"),t}pluck(t){let e=this.match(t),n=e&&e.length;return n>2?e.slice(1):e?e[n-1]:null}},R=P;(()=>{f(P,q,"String",1,String)})();