imba
Version:
2 lines (1 loc) • 5.79 kB
JavaScript
var g=Symbol.for("#__init__"),R=Symbol.for("#__initor__");var F=Symbol.for("#meta"),x=Symbol.for("imba");var q={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},h=new Map,T=globalThis[x]||(globalThis[x]={counter:0,classes:h});function y(r,t={}){return h.has(r)||h.set(r,{symbol:Symbol(r.name),parent:Object.getPrototypeOf(r.prototype)?.constructor,for:r,uses:null,inits:null,id:T.counter++,...t}),h.get(r)}function b(r,t){return typeof t=="string"?typeof r===t:t?.[Symbol.hasInstance]?.(r)}function P(r){return r?.toIterable?.()||r}function E(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 j(r,t,e,n={}){let o=r.constructor;!e&&t&&(e=Object.getOwnPropertyDescriptors(t),delete e.constructor,e[g]&&(console.warn(`Cannot define plain fields when extending class ${o.name}`),delete e[g]));let i=y(o);if(i&&i.augments){let c=new Map;for(let s of Object.keys(e)){let l=Object.getOwnPropertyDescriptor(r,s);for(let f of i.augments){let p=c.get(f);p||c.set(f,p={});let m=Object.getOwnPropertyDescriptor(f.prototype,s);m&&!E(l,m)?console.warn("wont extend",s,m,l):p[s]=e[s]}}for(let[s,l]of c)Object.keys(l).length&&j(s.prototype,null,l)}return Object.defineProperties(r,e),r}function C(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 i=n.ref=Symbol(t.name),c=Object[Symbol.hasInstance];t.prototype[i]=!0,Object.defineProperty(t,Symbol.hasInstance,{value:function(s){return this===t?s&&!!s[i]:c.call(this,s)}})}if(r.prototype[n.ref])return r;if(n.uses)for(let i of n.uses)C(r,i);n.augments.add(r),e.uses||(e.uses=[]),e.uses.push(t);let o=Object.getOwnPropertyDescriptors(t.prototype);return delete o.constructor,o[g]&&(e.inits||(e.inits=[]),e.inits.push(t.prototype[g]),delete o[g]),Object.defineProperties(r.prototype,o),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 u(r,t,e,n,o=null){let i=Object.getPrototypeOf(r.prototype),c=n&d.HasMixins,s;if(c&&(h.set(r,h.get(i.constructor)),i=Object.getPrototypeOf(i)),o){let f=n&d.IsObjectExtension?o:o.prototype,p=y(r);if(p.uses){o===f&&console.warn("Cannot extend object with mixins");for(let m of p.uses)C(o,m)}return n&d.HasSuperCalls&&(a.cache[t]=Object.create(Object.getPrototypeOf(f),Object.getOwnPropertyDescriptors(f))),j(f,r.prototype),o}let l=i?.constructor;if(s=y(r,{symbol:t}),Object.defineProperty(r,F,{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[R]=t),s.uses)for(let f of s.uses)f.mixes?.(r);return l?.inherited instanceof Function&&l.inherited(r),r}var L=Symbol(),_=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=P(this),o=n.length;e<o;e++){let i=n[e];t.indexOf(i)==-1&&t.push(i)}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(),o=t;return typeof t=="string"?o=function(i){return i[t]}:b(t,Map)?o=function(i){return t.get(i)}:b(t,Function)||(o=function(i){return i}),e?n.sort(function(i,c){let s=o(i),l=o(c);return s<l?1:s>l?-1:0}):n.sort(function(i,c){let s=o(i),l=o(c);return s>l?1:s<l?-1:0})}delete(t){let e=this.indexOf(t);return e<0?!1:(this.splice(e,1),!0)}},v=_;(()=>{u(_,L,"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 Z=Symbol(),$=class{to(t){var e=this;return Array.from({length:t-this+1},function(n,o){return e+o})}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,o=1){let i=(this-t)/(e-t);return n+i*(o-n)}},H=$;(()=>{u($,Z,"Number",1,Number)})();var K=Symbol(),O=class{filter(t){return new Set(Array.from(this).filter(t))}},z=O;(()=>{u(O,K,"Set",1,Set)})();var N=Symbol(),S=class{setnx(t,e){return this.get(t)??(this.set(t,e)&&e)}},D=S;(()=>{u(S,N,"WeakMap",1,WeakMap)})();var U=Symbol(),M=class{setnx(t,e){return this.get(t)??(this.set(t,e)&&e)}},A=M;(()=>{u(M,U,"Map",1,Map)})();var V=Symbol(),w=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}},I=w;(()=>{u(w,V,"String",1,String)})();