@cosmoledo/gleam 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/dist/gleam.d.ts +526 -62
- package/dist/gleam.esm.js +358 -81
- package/dist/gleam.esm.js.map +3 -3
- package/dist/gleam.js +358 -81
- package/dist/gleam.js.map +3 -3
- package/dist/gleam.min.js +7 -7
- package/dist/gleam.min.js.map +4 -4
- package/package.json +13 -11
package/dist/gleam.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var Gleam=(()=>{var lt=Object.defineProperty;var Zt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var Ut=(n,t,e)=>t in n?lt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Jt=(n,t)=>{for(var e in t)lt(n,e,{get:t[e],enumerable:!0})},Xt=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Wt(t))!qt.call(n,r)&&r!==e&<(n,r,{get:()=>t[r],enumerable:!(i=Zt(t,r))||i.enumerable});return n};var jt=n=>Xt(lt({},"__esModule",{value:!0}),n);var l=(n,t,e)=>Ut(n,typeof t!="symbol"?t+"":t,e);var je={};Jt(je,{Animator:()=>et,AudioBase:()=>L,CANVAS_TYPES:()=>Bt,CONTROLLER_KEYS:()=>We,CanvasManager:()=>G,Color:()=>z,Controller:()=>st,ControllerCursor:()=>$,EASINGS:()=>ct,EventSystem:()=>y,Game:()=>rt,Gameloop:()=>_,KEYBOARD_KEYS:()=>$t,Keyboard:()=>O,Music:()=>J,POINTER_KEYS:()=>Ye,Particle:()=>nt,Pointer:()=>B,Polygon:()=>at,Projectile:()=>it,Rect:()=>k,SHAKE_TYPES:()=>Lt,Screenshake:()=>ot,Settings:()=>d,Sound:()=>X,Vec2:()=>m,applyFilterOnCanvas:()=>Ot,approxEqual:()=>E,changeColor:()=>Ge,chunk:()=>ie,clamp:()=>C,cloneGrid:()=>Ae,colorShifter:()=>we,compact:()=>Je,convert1DTo2D:()=>Ie,convert2DTo1D:()=>Tt,createNewCanvas:()=>M,debounce:()=>dt,deepClone:()=>Ue,defineMethod:()=>f,delay:()=>Qt,doWhilePressed:()=>Le,easeIn:()=>At,easeInOut:()=>It,easeOut:()=>Pt,generateGrid:()=>Pe,getCanvasConstruct:()=>St,getElement:()=>tt,getFactorial:()=>pe,getUsedColors:()=>Oe,hex2rgb:()=>ht,hue2rgb:()=>Q,initCSSVariables:()=>Se,isNumeric:()=>se,isTouchPrimary:()=>te,linear:()=>Ht,loadBunch:()=>De,loadCanvas:()=>Gt,loadImage:()=>q,loadImageFromJson:()=>ke,loadJson:()=>_t,loadJsonCommented:()=>He,loadText:()=>Rt,map:()=>bt,mapUnclamped:()=>Vt,prepareLanguage:()=>ze,rafLoop:()=>D,random2Pi:()=>vt,randomBetweenFloat:()=>j,randomBetweenInt:()=>P,randomBoolean:()=>Dt,randomHex:()=>fe,randomItem:()=>yt,randomRgb:()=>be,randomSign:()=>ae,remove:()=>N,replaceCharAt:()=>Xe,rgb2Int:()=>H,rgb2hex:()=>de,rotateHue:()=>Ke,roundTo:()=>me,safeLoad:()=>W,setDisplay:()=>Te,setVisibility:()=>Re,shuffle:()=>re,splitSpriteSheet:()=>_e,styleElement:()=>Me,threshold:()=>gt,throttle:()=>S,throttleByKey:()=>F,toDegrees:()=>ue,toDotted:()=>ne,toHHMMSS:()=>ce,toRadians:()=>he,urlBasename:()=>ft,validateUrl:()=>Z,waitForEvent:()=>Ve,wrapDegrees:()=>Et,wrapRadians:()=>wt,wrapValue:()=>I});function dt(n,t){let e;return(...i)=>{clearTimeout(e),e=setTimeout(()=>n(...i),t)}}function Qt(n){return new Promise(t=>setTimeout(t,n))}function te(){return matchMedia("(pointer: coarse)").matches}function D(n){let t=0,e=!0,i=0,r=o=>{let s=t===0?0:(o-t)/1e3;t=o,n(s),e&&(i=requestAnimationFrame(r))};return i=requestAnimationFrame(r),()=>{e=!1,cancelAnimationFrame(i)}}function S(n,t=1e3){let e=-1/0,i=0;return()=>{i++;let r=performance.now();if(r-e>t){e=r;let o=i;i=0,n(o)}}}function F(n,t=1e3){let e=new Map;return(i,...r)=>{let o=e.get(i);if(!o){let s,a=S(c=>n(c,...s),t);o=(...c)=>{s=c,a()},e.set(i,o)}o(...r)}}function ft(n){let e=new URL(n,"http://_/").pathname.split("/").pop(),i=e.lastIndexOf("."),r=i>0?e.slice(0,i):e;if(!r)return null;try{return decodeURIComponent(r)}catch{return null}}var K=class K{static addEventListener(t,e,i={}){if(i.signal?.aborted)return function(){};let r=++this.nextId;function o(){let c=K.eventListener[t];c?.delete(r)&&(c.size===0&&delete K.eventListener[t],s.options.signal&&s.options.signal.removeEventListener("abort",o))}let s={callback:e,dispose:o,options:{once:i.once??!1,signal:i.signal}},a=this.eventListener[t];return a||(a=new Map,this.eventListener[t]=a),a.set(r,s),i.signal&&i.signal.addEventListener("abort",o,{once:!0}),o}static dispatchEvent(t,...e){let i=this.eventListener[t];if(!i)return;let r=this.nextId;i.forEach((o,s)=>{if(!(s>r)){o.options.once&&o.dispose();try{o.callback(...e)}catch(a){let c=a instanceof Error?a.message:String(a);this.logListenerError(`${t}:${c}`,t,a)}}})}};l(K,"eventListener",{}),l(K,"logListenerError",F((t,e,i)=>{let r=t>1?` (x${t} since last log)`:"";console.error(`EventSystem listener for "${e}" threw${r}:`,i)})),l(K,"nextId",0);var y=K;var ee={1:"ABORTED",2:"NETWORK",3:"DECODE",4:"SRC_NOT_SUPPORTED"},L=class{constructor(t=!0){l(this,"songs",new Map);l(this,"_enabled");l(this,"registered",!1);this._enabled=t,y.addEventListener("gameloopStopped",()=>this.stop())}get enabled(){return this._enabled}set enabled(t){this._enabled=t,t||this.stop()}register(t=1,...e){if(this.throwOnBadVolume(t,"defaultVolume"),this.registered)throw new Error("register() can only be called once per instance");this.registered=!0,e.forEach(i=>{typeof i=="string"?i={name:ft(i)??i,path:i}:i.volume!==void 0&&this.throwOnBadVolume(i.volume,`Volume of "${i.name}"`);let r=new window.Audio;r.addEventListener("error",()=>{let o=r.error,s=o?`${ee[o.code]??o.code}${o.message?`: ${o.message}`:""}`:"unknown";console.error(`Failed to load audio "${i.name}" from "${r.src}": ${s}`)}),r.preload="auto",r.src=i.path,r.id=i.name,r.volume=i.volume??t,r.defaultVolume=r.volume,this.songs.set(i.name,r)})}stop(){}throwOnBadVolume(t,e){if(!Number.isFinite(t))throw new Error(e+" is invalid, it has to be in range of 0 to 1");if(t<0)throw new Error(e+" has to be above 0. What's a negative volume anyway?");if(t>1)throw new Error(e+" has to be lower or equal to 1! If you need a louder volume, you need to update the audio file itself.")}};function E(n,t,e=1e-9){return Math.abs(n-t)<=e}function C(n,t,e){return Math.min(e,Math.max(t,n))}function Vt(n,t,e,i,r){return t===e?i:i+(r-i)*(n-t)/(e-t)}function bt(n,t,e,i,r){return C(Vt(n,t,e,i,r),Math.min(i,r),Math.max(i,r))}function gt(n,t){return Math.abs(n)<t?0:n}function ne(n){return Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g,".")}function I(n,t,e){if(E(t,e))throw new RangeError(`wrapValue: min and max must differ (got ${t})`);t>e&&([t,e]=[e,t]);let i=e-t;return((n-t)%i+i)%i+t}function At(n){return n*n}function It(n){return n<.5?2*n*n:1-2*(1-n)*(1-n)}function Pt(n){return n*(2-n)}function Ht(n){return n}var ct={"ease-in":At,"ease-in-out":It,"ease-out":Pt,linear:Ht};function ie(n,t){if(!Number.isFinite(t)||t<1)throw new RangeError(`chunk: maxLength must be a finite number >= 1 (got ${t})`);let e=[],i=[];return n.forEach((r,o)=>{i.push(r),(i.length===t||o===n.length-1)&&(e.push(i),i=[])}),e}function yt(n){if(n.length===0)throw new Error("randomItem called on empty array");return n[Math.random()*n.length|0]}function N(n,t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}function re(n){let t=n.slice();for(let e=t.length-1;e>0;e--){let i=Math.floor(Math.random()*(e+1));[t[e],t[i]]=[t[i],t[e]]}return t}var J=class extends L{constructor(){super(...arguments);l(this,"last",null);l(this,"current",null);l(this,"next",null);l(this,"fadeCancel",null)}get isPlaying(){return!!this.fadeCancel||this.current instanceof window.Audio&&!this.current.paused}get enabled(){return super.enabled}set enabled(e){super.enabled=e,e&&!this.isPlaying&&this.fade()}fade(e=null,i=1e3,r={cur:"ease-in",next:"ease-out"}){if(i<=0)throw new Error(`fadeTime must be > 0, got ${i}`);if(this.songs.size===0)throw new Error("No music registered!");if(e&&!this.songs.has(e))throw new Error(`Music "${e}" not registered!`);if(!this.enabled)return;if(this.fadeCancel&&(console.warn("Stopping current music fading."),this.fadeCancel(),this.fadeCancel=null,this.current?.stop(),this.current=this.next,this.next=null),this.songs.size===1){console.info("Only one music registered, playing that looped."),this.current=this.songs.values().next().value,this.current.loop=!0,this.current.play();return}e?this.next=this.songs.get(e):(this.next=this.getRandom(),this.next||(console.warn("Not enough songs to pick a fresh one, replaying the previous one."),this.next=this.last)),this.next.onended=()=>{this.fade()},this.next.volume=0,this.next.play(),console.log(`Start fading to music: "${this.next.id}"`),this.current&&(this.current.onended=()=>{});let o=ct[r.cur],s=ct[r.next],a=i/1e3,c=0,u=this.current?.volume??0;this.fadeCancel=D(h=>{c+=h/a,this.current&&(this.current.volume=u*(1-C(o(c),0,1))),this.next.volume=this.next.defaultVolume*C(s(c),0,1),c>=1&&(this.fadeCancel?.(),this.fadeCancel=null,this.current&&(this.current.stop(),this.current.volume=this.current.defaultVolume),this.next.volume=this.next.defaultVolume,this.last=this.current,this.current=this.next,this.next=null)})}stop(){super.stop(),this.fadeCancel?.(),this.fadeCancel=null,this.current?.stop(),this.next?.stop(),this.last=this.current,this.current=this.next,this.next=null}getRandom(){let e=Array.from(this.songs.values());return this.last&&N(e,this.last),this.current&&N(e,this.current),e.length===0?null:yt(e)}};var X=class extends L{constructor(){super(...arguments);l(this,"currentSounds",[])}play(e){if(this.songs.size===0)throw new Error("No sounds registered!");if(!this.songs.has(e))throw new Error(`Sound "${e}" not registered!`);if(!this.enabled)return Promise.resolve();let i=this.songs.get(e).clone();this.currentSounds.push(i);let r=()=>N(this.currentSounds,i);return i.onended=r,i.onerror=()=>{r(),console.error(`Playback failed for Sound "${e}", reason: ${i.error?.message??"unknown"}`)},i.play().catch(o=>{throw r(),o})}stop(){super.stop(),this.currentSounds.forEach(e=>e.stop()),this.currentSounds.length=0}};var oe=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function se(n){return typeof n=="number"?Number.isFinite(n):typeof n=="string"?oe.test(n.trim()):!1}function vt(){return Math.random()*Math.PI*2}function j(n,t){return n>t&&([n,t]=[t,n]),n+Math.random()*(t-n)}function P(n,t){return n>t&&([n,t]=[t,n]),Math.floor(n+Math.random()*(t-n+1))}function Dt(){return Math.random()>=.5}function ae(){return Dt()?1:-1}var le=S(n=>{console.warn(`toHHMMSS() received invalid input (NaN, Infinity, or negative) x${n} since last warning; returning "00:00".`)});function ce(n){if(!Number.isFinite(n)||n<0)return le(),"00:00";n=Math.floor(n);let t=Math.floor(n/3600),e=Math.floor((n-t*3600)/60),i=n-t*3600-e*60,r=t<10?"0"+t:""+t,o=e<10?"0"+e:""+e,s=i<10?"0"+i:""+i;return t===0?`${o}:${s}`:`${r}:${o}:${s}`}function ue(n){return n*180/Math.PI}function he(n){return n*Math.PI/180}function wt(n){return I(n,-Math.PI,Math.PI)}function Et(n){return I(n,-180,180)}function me(n,t){let e=Math.pow(10,t);return Math.round(n*e)/e}var ut={0:1},xt=0,kt=1/0;function pe(n){let t=Math.floor(n);if(t<0||!Number.isFinite(t))throw new Error("getFactorial requires non-negative integer");if(t>=kt)return 1/0;if(ut[t]!==void 0)return ut[t];let e=ut[xt];for(let i=xt+1;i<=t;i++){if(e*=i,!Number.isFinite(e))return kt=i,1/0;ut[i]=e,xt=i}return e}function de(n,t,e){return"#"+(16777216+H(n,t,e)).toString(16).slice(1)}function H(n,t,e,i){if(i===void 0)return n<<16|t<<8|e;let r=Math.round(i*255);return(n<<24|t<<16|e<<8|r)>>>0}function ht(n){return n.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(t,e,i,r)=>"#"+e+e+i+i+r+r).substring(1).match(/.{2}/g).map(t=>parseInt(t,16))}function Q(n,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?n+(t-n)*6*e:e<1/2?t:e<2/3?n+(t-n)*(2/3-e)*6:n}function fe(){return"#"+Math.random().toString(16).slice(2,6)}function be(n=0,t=255){return[P(n,t),P(n,t),P(n,t)]}var z=class n{constructor(t,e,i,r){l(this,"_r");l(this,"_g");l(this,"_b");l(this,"_alpha",1);this.set(t,e,i,r)}static fromHex(t){let e=t.replace("#","").toUpperCase();if(!/^[0-9A-F]+$/.test(e))throw new Error(`Invalid hex color: ${t}`);if((e.length===3||e.length===4)&&(e=e.split("").map(s=>s+s).join("")),e.length!==6&&e.length!==8)throw new Error(`Invalid hex color: ${t}`);let i=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),o=parseInt(e.slice(4,6),16);if(e.length===8){let s=parseInt(e.slice(6,8),16);return new n(i,r,o,s/255)}return new n(i,r,o)}static fromHSL(t,e,i,r=1){let o=I(t,0,360)/360,s=e/100,a=i/100,c,u,h;if(s===0)c=u=h=a;else{let g=a<.5?a*(1+s):a+s-a*s,v=2*a-g;c=Q(v,g,o+1/3),u=Q(v,g,o),h=Q(v,g,o-1/3)}return new n(c*255,u*255,h*255,r)}get r(){return this._r}get g(){return this._g}get b(){return this._b}get alpha(){return this._alpha}set(t,e,i,r){if(this._r=C(t,0,255),this._g=C(e,0,255),this._b=C(i,0,255),r!==void 0){let o=C(r,0,1);this._alpha=E(o,0)?0:E(o,1)?1:o}return this}applyMatrix(t,e,i,r,o,s,a,c,u){return this.set(this.r*t+this.g*e+this.b*i,this.r*r+this.g*o+this.b*s,this.r*a+this.g*c+this.b*u)}brightness(t){return this.set(this.r*t,this.g*t,this.b*t)}contrast(t){return this.set(127.5+(this.r-127.5)*t,127.5+(this.g-127.5)*t,127.5+(this.b-127.5)*t)}grayscale(t=1){let e=.2126+.7874*(1-t),i=.7152-.7152*(1-t),r=.0722-.0722*(1-t),o=.2126-.2126*(1-t),s=.7152+.2848*(1-t),a=.0722-.0722*(1-t),c=.2126-.2126*(1-t),u=.7152-.7152*(1-t),h=.0722+.9278*(1-t);return this.applyMatrix(e,i,r,o,s,a,c,u,h)}hueRotate(t){let e=Math.cos(t),i=Math.sin(t),r=.213+e*.787-i*.213,o=.715-e*.715-i*.715,s=.072-e*.072+i*.928,a=.213-e*.213+i*.143,c=.715+e*.285+i*.14,u=.072-e*.072-i*.283,h=.213-e*.213-i*.787,g=.715-e*.715+i*.715,v=.072+e*.928+i*.072;return this.applyMatrix(r,o,s,a,c,u,h,g,v)}invert(t=1){return this.set(this.r*(1-t)+(255-this.r)*t,this.g*(1-t)+(255-this.g)*t,this.b*(1-t)+(255-this.b)*t)}mix(t,e){let i=1-e;return this.set(this.r*i+t.r*e,this.g*i+t.g*e,this.b*i+t.b*e,this.alpha*i+t.alpha*e)}round(){return this.set(Math.round(this.r),Math.round(this.g),Math.round(this.b))}saturate(t=1){let e=.213+.787*t,i=.715-.715*t,r=.072-.072*t,o=.213-.213*t,s=.715+.285*t,a=.072-.072*t,c=.213-.213*t,u=.715-.715*t,h=.072+.928*t;return this.applyMatrix(e,i,r,o,s,a,c,u,h)}sepia(t=1){let e=.393+.607*(1-t),i=.769-.769*(1-t),r=.189-.189*(1-t),o=.349-.349*(1-t),s=.686+.314*(1-t),a=.168-.168*(1-t),c=.272-.272*(1-t),u=.534-.534*(1-t),h=.131+.869*(1-t);return this.applyMatrix(e,i,r,o,s,a,c,u,h)}shade(t){let e=t<0?0:255,i=Math.abs(t);return this.set(this.r+(e-this.r)*i,this.g+(e-this.g)*i,this.b+(e-this.b)*i)}toHex(){let t=Math.round(this.r).toString(16).padStart(2,"0"),e=Math.round(this.g).toString(16).padStart(2,"0"),i=Math.round(this.b).toString(16).padStart(2,"0"),r=`#${t}${e}${i}`;if(this.alpha===1)return r;let o=Math.round(this.alpha*255);return`${r}${o.toString(16).padStart(2,"0")}`}toHSL(){let{h:t,s:e,l:i}=this.toHSLObject(),r=Math.round(t),o=Math.round(e),s=Math.round(i);return this.alpha===1?`hsl(${r}, ${o}%, ${s}%)`:`hsla(${r}, ${o}%, ${s}%, ${this.alpha.toFixed(2)})`}toHSLObject(){let t=this.r/255,e=this.g/255,i=this.b/255,r=Math.max(t,e,i),o=Math.min(t,e,i),s=(r+o)/2,a=0,c=0;if(r!==o){let u=r-o;switch(c=s>.5?u/(2-r-o):u/(r+o),r){case t:a=(e-i)/u+(e<i?6:0);break;case e:a=(i-t)/u+2;break;case i:a=(t-e)/u+4;break}a/=6}return{h:a*360,s:c*100,l:s*100,a:this.alpha}}toRGB(){let t=Math.round(this.r),e=Math.round(this.g),i=Math.round(this.b);return this.alpha===1?`rgb(${t}, ${e}, ${i})`:`rgba(${t}, ${e}, ${i}, ${this.alpha.toFixed(2)})`}clone(){return new n(this.r,this.g,this.b,this.alpha)}equals(t,e=!0){return E(this.r,t.r)&&E(this.g,t.g)&&E(this.b,t.b)&&(!e||E(this.alpha,t.alpha))}};var ge=2,ye=3,xe=4,ve=5;function we(n){let t=new z(n[0],n[1],n[2]);return new Ct(t).solve().filter.replace("filter: ","").replace(";","")}var Ct=class{constructor(t){l(this,"reusedColor");l(this,"target");l(this,"targetHSL");this.target=t,this.targetHSL=t.toHSLObject(),this.reusedColor=new z(0,0,0)}css(t){let[e,i,r,o,s,a]=t;return`filter: invert(${Math.round(e)}%) sepia(${Math.round(i)}%) saturate(${Math.round(r)}%) hue-rotate(${Math.round(o*3.6)}deg) brightness(${Math.round(s)}%) contrast(${Math.round(a)}%);`}loss(t){let[e,i,r,o,s,a]=t,c=this.reusedColor;c.set(0,0,0),c.invert(e/100),c.sepia(i/100),c.saturate(r/100),c.hueRotate(o/100*Math.PI*2),c.brightness(s/100),c.contrast(a/100);let u=c.toHSLObject();return Math.abs(c.r-this.target.r)+Math.abs(c.g-this.target.g)+Math.abs(c.b-this.target.b)+Math.abs(Et(u.h-this.targetHSL.h))/1.8+Math.abs(u.s-this.targetHSL.s)+Math.abs(u.l-this.targetHSL.l)}solve(){let t=this.solveNarrow(this.solveWide());return{values:t.values,loss:t.loss,filter:this.css(t.values)}}solveNarrow(t){let e=t.loss,i=2,r=e+1,o=[.25*r,.25*r,r,.25*r,.2*r,.2*r];return this.spsa(e,o,i,t.values,500)}solveWide(){let i=[60,180,18e3,600,1.2,1.2],r={loss:1/0,values:[50,20,3750,50,100,100]};for(let o=0;r.loss>25&&o<3;o++){let s=[50,20,3750,50,100,100],a=this.spsa(5,i,15,s,1e3);a.loss<r.loss&&(r=a)}return r}spsa(t,e,i,r,o){r=r.slice();let s=1,a=.16666666666666666,c=r.slice(),u=1/0,h=[0,0,0,0,0,0],g=[0,0,0,0,0,0],v=[0,0,0,0,0,0];for(let x=0;x<o;x++){let p=i/Math.pow(x+1,a);for(let w=0;w<6;w++)h[w]=Math.random()>.5?1:-1,g[w]=r[w]+p*h[w],v[w]=r[w]-p*h[w];let b=this.loss(g)-this.loss(v);for(let w=0;w<6;w++){let mt=b/(2*p)*h[w],pt=e[w]/Math.pow(t+x+1,s);r[w]=R(r[w]-pt*mt,w)}let A=this.loss(r);A<u&&(c=r.slice(),u=A)}return{values:c,loss:u};function R(x,p){let b=100;return p===ge?b=7500:(p===xe||p===ve)&&(b=200),p===ye?x=I(x,0,b):x<0?x=0:x>b&&(x=b),x}}};var k=class n{constructor(t=0,e=0,i=0,r=0){l(this,"_h",0);l(this,"_w",0);l(this,"_x",0);l(this,"_y",0);l(this,"_sides");l(this,"sideIsDirty",!0);this.set(t,e,i,r)}static fromBoundingClientRect(t){return t instanceof HTMLElement&&(t=t.getBoundingClientRect()),new n(t.left,t.top,t.width,t.height)}static fromPolygon(t){if(t.points.length===0)throw new Error("Supplied polygon has no points!");let e=1/0,i=1/0,r=-1/0,o=-1/0;return t.points.forEach(s=>{s.x<e&&(e=s.x),s.x>r&&(r=s.x),s.y<i&&(i=s.y),s.y>o&&(o=s.y)}),new n(e,i,r-e,o-i)}get h(){return this._h}set h(t){this._h=t,this.sideIsDirty=!0}get w(){return this._w}set w(t){this._w=t,this.sideIsDirty=!0}get x(){return this._x}set x(t){this._x=t,this.sideIsDirty=!0}get y(){return this._y}set y(t){this._y=t,this.sideIsDirty=!0}get sides(){return this.sideIsDirty&&(this._sides={bottom:this.y+this.h,centerPos:new m(this.x+this.w*.5,this.y+this.h*.5),halfSize:new m(this.w*.5,this.h*.5),right:this.x+this.w},this.sideIsDirty=!1),this._sides}inflate(t){return this.x-=t,this.y-=t,this.w+=2*t,this.h+=2*t,this.sideIsDirty=!0,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.sideIsDirty=!0,this}set(t=0,e=0,i,r){return typeof t=="number"?(this.x=t,this.y=e):("w"in t&&(this.w=t.w,this.h=t.h),this.x=t.x,this.y=t.y),i!==void 0&&(this.w=i),r!==void 0&&(this.h=r),this.sideIsDirty=!0,this}collide(t){return this.x<=t.x+t.w&&this.x+this.w>=t.x&&this.y<=t.y+t.h&&this.y+this.h>=t.y}collideFull(t){return t.x+t.w<=this.x+this.w&&t.x>=this.x&&t.y>=this.y&&t.y+t.h<=this.y+this.h}collidePoint(t){return this.x<=t.x&&t.x<=this.x+this.w&&this.y<=t.y&&t.y<=this.y+this.h}collideSide(t){let e=this.x+this.w*.5-(t.x+t.w*.5),i=this.y+this.h*.5-(t.y+t.h*.5),r=(this.w+t.w)*.5,o=(this.h+t.h)*.5,s=r*i,a=o*e,c="none";return Math.abs(e)<=r&&Math.abs(i)<=o&&(s>a?c=s>-a?"bottom":"left":c=s>-a?"right":"top"),c}pos(){return new m(this.x,this.y)}size(){return new m(this.w,this.h)}toString(){return`Rect [x: ${this.x}, y: ${this.y}, w: ${this.w}, h: ${this.h}]`}clone(){return new n(this.x,this.y,this.w,this.h)}equals(t,e=!0){let i=E(this.x,t.x)&&E(this.y,t.y);return i&&e&&(i=E(this.w,t.w)&&E(this.h,t.h)),i}};var T={Add:1,Sub:2,Mult:3,Div:4,Rem:5,Equal:6,Mod:7},Ee=S(n=>console.warn(`Vec2.normalize() called on zero vector x${n} since last warning; returning zero.`)),Ce=S(n=>console.warn(`Vec2 operation produced non-finite value x${n} since last warning; check for zero divisor.`)),m=class n{constructor(t=0,e){l(this,"x",0);l(this,"y",0);this.calculate(T.Equal,t,e)}static fromAngle(t,e=1,i=e){return new n(Math.cos(t)*e,Math.sin(t)*i)}set(t,e){return this.calculate(T.Equal,t,e)}abs(){return this.map(Math.abs)}add(t,e){return this.calculate(T.Add,t,e)}ceil(){return this.map(Math.ceil)}clamp(t,e=t){return this.x=C(this.x,t[0],t[1]),this.y=C(this.y,e[0],e[1]),this}div(t,e){return this.calculate(T.Div,t,e)}floor(){return this.map(Math.floor)}map(t){return this.x=t(this.x,0),this.y=t(this.y,1),this}mod(t,e){return this.calculate(T.Mod,t,e)}mult(t,e){return this.calculate(T.Mult,t,e)}negate(){return this.mult(-1)}normalize(){let t=this.length();return E(t,0)?(Ee(),this):this.map(e=>e/t)}normalizeManhattan(){let t=this.lengthManhattan();return E(t,0)?this:this.map(e=>e/t)}rem(t,e){return this.calculate(T.Rem,t,e)}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}sub(t,e){return this.calculate(T.Sub,t,e)}angle(t){return t?Math.atan2(t.y-this.y,t.x-this.x):Math.atan2(this.y,this.x)}distance(t){return Math.sqrt(Math.pow(t.x-this.x,2)+Math.pow(t.y-this.y,2))}distanceManhattan(t){return Math.abs(t.x-this.x)+Math.abs(t.y-this.y)}dotProduct(t){return this.x*t.x+this.y*t.y}isValid(){return Number.isFinite(this.x)&&Number.isFinite(this.y)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthManhattan(){return Math.abs(this.x)+Math.abs(this.y)}max(){return Math.max(this.x,this.y)}min(){return Math.min(this.x,this.y)}toArray(){return[this.x,this.y]}toRectAddPos(t,e){return this.concat(!0,t,e)}toRectAddSize(t,e){return this.concat(!1,t,e)}toString(){return`Vec2 [x: ${this.x}, y: ${this.y}]`}clone(){return new n(this.x,this.y)}equals(t,e){let[i,r]=this.getValues(t,e);return E(this.x,i)&&E(this.y,r)}calculate(t,e,i){let[r,o]=this.getValues(e,i);switch(t){case T.Add:this.x+=r,this.y+=o;break;case T.Sub:this.x-=r,this.y-=o;break;case T.Mult:this.x*=r,this.y*=o;break;case T.Div:this.x/=r,this.y/=o;break;case T.Rem:this.x%=r,this.y%=o;break;case T.Equal:this.x=r,this.y=o;break;case T.Mod:this.x=(this.x%r+r)%r,this.y=(this.y%o+o)%o;break;default:break}return this.isValid()||Ce(),this}concat(t,e,i){let[r,o]=this.getValues(e,i);return t?new k(r,o,this.x,this.y):new k(this.x,this.y,r,o)}getValues(t,e){let i=0,r=0;if(typeof t=="number")i=t,e===void 0?r=t:r=e;else if(e===void 0)i=t.x,r=t.y;else throw new Error("When x is a Vector2, y must be omitted!");return[i,r]}};var Mt="gleam",d=class{static get localStorage(){return this._localStorage}static init(t,e){if(this.initialized)throw new Error("Settings.init called twice");if(Object.assign(this,t),!(Number.isFinite(this.fps)&&this.fps>0))throw new Error(`Settings.fps must be > 0, got ${this.fps}`);this.debug&&(window.game=e),this.warnBeforeClose&&window.addEventListener("beforeunload",r=>(this.triedToClose?.(),r.preventDefault(),r.returnValue=!0,"Are you sure?"),!1),this._localStorage.language=navigator.language.split("-")[0]||"en";let i=localStorage.getItem(Mt);if(i)try{let r=JSON.parse(i);Object.assign(this._localStorage,r)}catch{console.error("Couldn't parse local storage! Will be cleaned now.",i),localStorage.removeItem(Mt)}this.initialized=!0}static setLocalStorage(t,e){this._localStorage[t]=e,localStorage.setItem(Mt,JSON.stringify(this._localStorage))}};l(d,"antialias",!1),l(d,"autoloop",!0),l(d,"backgroundColor","#444"),l(d,"debug",!1),l(d,"doNotClear",!1),l(d,"enableResize",!0),l(d,"font","Arial"),l(d,"fps",1/60),l(d,"triedToClose"),l(d,"useClearRect",!0),l(d,"warnBeforeClose",!1),l(d,"initialized",!1),l(d,"_localStorage",{language:""});function tt(n,t=document){let e=t.querySelector(n);if(!e)throw new Error(`Element not found: ${n}`);return e}function Me(n,t){Object.assign(n.style,t)}function Te(n,t){n.style.display=t?"":"none"}function Re(n,t){n.style.visibility=t?"":"hidden"}function Se(){let n=tt(":root");return{root:n,get(t){return getComputedStyle(n).getPropertyValue("--"+t)},set(t,e){n.style.setProperty("--"+t,e)}}}function Le(n,t,e=200){let i=tt(n),r,o=null;function s(u){o===null&&(o=u.pointerId,i.setPointerCapture(o),clearInterval(r),t(),r=setInterval(()=>t(),e))}function a(u){u.pointerId===o&&(clearInterval(r),i.releasePointerCapture(u.pointerId),o=null)}i.addEventListener("pointerdown",s),i.addEventListener("pointerup",a),i.addEventListener("pointercancel",a);function c(){i.removeEventListener("pointerdown",s),i.removeEventListener("pointerup",a),i.removeEventListener("pointercancel",a),clearInterval(r),o!==null&&(i.releasePointerCapture(o),o=null)}return c}async function Ve(n,t,e){if(e?.aborted)throw e.reason;return new Promise((i,r)=>{n.addEventListener(t,()=>i(),{once:!0,signal:e}),e?.addEventListener("abort",()=>r(e.reason),{once:!0})})}function Ae(n){return n.map(t=>t.slice())}function Ie(n,t){return{x:n%t,y:n/t|0}}function Tt(n,t,e){return n+e*t}function Pe(n,t,e){let i=typeof e=="function";return Array.from({length:n},(r,o)=>Array.from({length:t},(s,a)=>i?e(a,o):e))}function f(n,t,e){Object.defineProperty(n,t,{value:e,configurable:!0,writable:!0})}var Kt=1e4;function Z(n){let t=n.trim().match(/^([a-z][a-z0-9+.-]*):/i);if(!t)return;let e=t[1].toLowerCase();if(!["blob","data","http","https"].includes(e))throw new Error(`Invalid URL protocol: ${n}`)}function W(n,t,e){let i,r=new Promise((o,s)=>{i=setTimeout(()=>{s(new Error(`Timeout (${Kt}ms) when loading ${e}: ${t}`))},Kt)});return Promise.race([n,r]).catch(o=>{clearTimeout(i);let s=o?.message||String(o);throw console.error(`${e} failed on ${t}
|
|
2
|
-
${s}`),o}).finally(()=>clearTimeout(
|
|
3
|
-
Status: ${t.status} ${t.statusText}`);return t.text()})(),n,"text")}async function
|
|
4
|
-
`).filter(
|
|
5
|
-
`);return JSON.parse(e)}),n,"JSON (commented)")}async function
|
|
6
|
-
Source: ${s}`)}let
|
|
7
|
-
Source: ${n}${t}.json`);return i.sprites.forEach((s,a)=>{if(s.x===void 0||s.y===void 0||!s.w||!s.h||!s.name)throw new Error(`Invalid sprite data at index ${a}: ${JSON.stringify(s,null,2)}`);let c=r.subImage(s.x,s.y,s.w,s.h);for(let u in s)c.dataset[u]=String(s[u]);o[s.name]=c}),o}async function De(n){let t={},e=Object.keys(n);return Promise.all(e.map(i=>n[i])).then(i=>(e.forEach((r,o)=>{t[r]=i[o]}),t))}f(HTMLCanvasElement.prototype,"hasAnyColor",function(){return this.getContext("2d").getImageData(0,0,this.width,this.height).data.some(t=>t!==0)});f(HTMLCanvasElement.prototype,"getPixelAt",function(n,t,e="integer"){let i=0,r=0,o=0,s=0;if(n>=0&&n<this.width&&t>=0&&t<this.height){let a=this.getContext("2d").getImageData(n,t,1,1).data;i=a[0],r=a[1],o=a[2],s=a[3]}switch(e){case"array":return[i,r,o,s];case"json":return{r:i,g:r,b:o,a:s};case"string":return`rgba(${i}, ${r}, ${o}, ${s})`;default:return H(i,r,o,s/255)}});f(HTMLCanvasElement.prototype,"replaceColors",function(n){let t=new Map;for(let o in n){let[s,a,c]=ht(o),[u,h,g]=ht(n[o]);t.set(H(s,a,c),[u,h,g])}let e=this.getContext("2d"),i=e.getImageData(0,0,this.width,this.height),{data:r}=i;for(let o=0;o<r.length;o+=4){if(r[o+3]===0)continue;let s=t.get(H(r[o],r[o+1],r[o+2]));s!==void 0&&(r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2])}return e.putImageData(i,0,0),this});f(HTMLCanvasElement.prototype,"rotateBy",function(n){let t=Math.ceil(Math.sqrt(this.width*this.width+this.height*this.height)),e=M(t,t);return e.context.translate(t*.5,t*.5),e.context.rotate(n),e.context.drawImage(this,-this.width*.5,-this.height*.5),e.context.translate(-t*.5,-t*.5),e.canvas});f(HTMLCanvasElement.prototype,"rotateByAligned",function(n){let t=M(this.width,this.height);return t.context.translate(this.width*.5,this.height*.5),t.context.rotate(n),t.context.translate(-this.width*.5,-this.height*.5),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"autoCrop",function(){let n={x:this.width,y:this.height,update(s,a){this.x=Math.min(this.x,s),this.y=Math.min(this.y,a)}},t={x:0,y:0,update(s,a){this.x=Math.max(this.x,s),this.y=Math.max(this.y,a)}},i=this.getContext("2d").getImageData(0,0,this.width,this.height);for(let s=0;s<this.height;s++)for(let a=0;a<this.width;a++)i.data[Tt(a*4,s*4,this.width)+3]!==0&&(n.update(a,s),t.update(a,s));if(n.x>t.x)return this.clone();let r=t.x-n.x+1,o=t.y-n.y+1;return this.subImage(n.x,n.y,r,o)});f(HTMLCanvasElement.prototype,"scaleBy",function(n=1,t=n){if(n<=0||t<=0)throw new Error(`scaleBy requires positive scale factors, got: ${n} x ${t}`);let e=M(this.width*n,this.height*t);return e.context.scale(n,t),e.context.drawImage(this,0,0),e.canvas});f(HTMLCanvasElement.prototype,"resize",function(n,t=!0){return t?this.scaleBy(n/this.width):this.scaleBy(n/this.height)});f(HTMLCanvasElement.prototype,"flipX",function(n=0){let t=M(this.width,this.height);return t.context.translate(this.width+n,0),t.context.scale(-1,1),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"flipY",function(n=0){let t=M(this.width,this.height);return t.context.translate(0,this.height+n),t.context.scale(1,-1),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"subImage",function(n,t,e,i){e===void 0&&(e=this.width),i===void 0&&(i=this.height);let r=M(e,i);return r.context.drawImage(this,n,t,e,i,0,0,e,i),r.canvas});f(HTMLCanvasElement.prototype,"clone",function(){let n=M(this.width,this.height);n.canvas.id=this.id,n.context.drawImage(this,0,0);for(let t in this.dataset)n.canvas.dataset[t]=this.dataset[t];return n.canvas});f(HTMLCanvasElement.prototype,"toImage",function(){return q(this.toDataURL())});function M(n,t,e=d.antialias){let i=document.createElement("canvas");i.width=n,i.height=t;let r=i.getContext("2d");return r.imageSmoothingEnabled=e,{canvas:i,context:r}}function St(n){let t=tt(n),e=t.getContext("2d");return{canvas:t,context:e}}function Ot(n,t,e=n.width,i=n.height){let r=M(e,i);return r.context.filter=t,r.context.drawImage(n,0,0),r.context.filter="none",r.canvas}function Ke(n,t,e,i){return Ot(n,"hue-rotate("+t+"deg)",e,i)}function Ge(n,t,e){n.save(),n.clearRect(0,0,t.width,t.height),n.globalCompositeOperation="source-over",n.drawImage(t,0,0,t.width,t.height),n.globalCompositeOperation="color",n.fillStyle=e,n.fillRect(0,0,t.width,t.height),n.globalCompositeOperation="destination-in",n.drawImage(t,0,0,t.width,t.height),n.restore()}function _e(n,t,e){if(n.width%t!==0||n.height%e!==0)throw new Error(`SpriteSheet doesn't divide evenly: ${n.width}x${n.height} / ${t}x${e}`);let i=n.width/t,r=n.height/e,o=[];return Array.from({length:e}).forEach((s,a)=>{Array.from({length:t}).forEach((c,u)=>{o.push(n.subImage(u*i,a*r,i,r))})}),o}function Oe(n,t=1,e=0,i=0){let r=n.getContext("2d").getImageData(0,0,n.width,n.height).data,o=new Map;for(let a=0;a<r.length;a+=4){let c=H(r[a],r[a+1],r[a+2]);o.set(c,(o.get(c)??0)+1)}(t<1||e>0||i>0)&&o.forEach((a,c)=>{let u=a*t|0;u===0||e>0&&u<e||i>0&&u>i?o.delete(c):o.set(c,u)});let s=new Map;return o.forEach((a,c)=>{s.set("#"+(16777216+c).toString(16).slice(1),a)}),s}var V=class V{constructor(t,e){l(this,"active",!0);l(this,"image");l(this,"imageId",0);l(this,"lookLeft",!1);l(this,"onEnd");l(this,"size",new m);l(this,"animations",[]);l(this,"currentAnimation",0);l(this,"entity");l(this,"lastPlayed");l(this,"namespace");l(this,"onFrame");l(this,"playVersion",0);l(this,"timer",0);this.entity=t,this.namespace=e}static clearSpriteCache(t){if(t===void 0){V.spriteCache.clear();return}let e=`${t}.`;V.spriteCache.forEach((i,r)=>{r.startsWith(e)&&V.spriteCache.delete(r)})}get current(){return this.animations[this.currentAnimation]}draw(t,e=new m){t.drawImage(this.image,this.entity.pos.x+e.x-this.size.x,this.entity.pos.y+e.y)}update(t){if(this.active&&(this.timer+=t,!(this.timer<=this.current.timing))){if(this.timer-=this.current.timing,this.imageId++,this.imageId>=this.current.sprites.length){let e=this.onEnd;this.onEnd=void 0,this.onFrame=void 0,this.imageId=0;let i=this.playVersion;if(e?.(),this.playVersion!==i)return;if(this.lastPlayed){this.play(this.lastPlayed),this.lastPlayed=void 0;return}if(this.current.sprites.length===1){this.active=!1;return}}if(this.onFrame?.[this.imageId]){let e=this.onFrame[this.imageId];delete this.onFrame[this.imageId];let i=this.playVersion;if(e(),this.playVersion!==i)return}this.active&&this.setImage()}}add(t,e,i,r=!1){r&&this.animations.some(o=>o.default)&&console.error("Only one default animation allowed!"),this.animations.some(o=>o.name===t)&&console.error("Duplicate animation name!"),this.animations.push({default:r,name:t,sprites:e,timing:i}),r&&this.play(t)}addAnimation(t,e=!1){this.add(t.name,t.sprites,t.timing,t.default||e)}drawRotated(t,e,i=new m){let r=this.entity.pos.x+i.x,o=this.entity.pos.y+i.y,s=this.image.width*.75,a=this.image.height*.5;t.setTransform(1,0,0,1,r+s-this.size.x,o+a),t.rotate(e),t.drawImage(this.image,-s,-a),t.setTransform(1,0,0,1,0,0)}play(t,e,i){let r=this.animations.findIndex(a=>a.name===t);if(r<0)throw new Error(`Animator.play: animation "${t}" not found`);this.playVersion++;let o=this.playVersion;this.imageId=0,this.timer=0,this.currentAnimation=r,this.setImage();let s=this.onEnd;this.onEnd=e,this.onFrame=i,s?.(),this.playVersion===o&&(this.active=!0)}playIfNot(t,e,i){return this.isPlaying(t)?!1:(this.play(t,e,i),!0)}playNextOnce(t){this.lastPlayed=t}playOnce(t,e,i){this.lastPlayed=this.current?.name,this.play(t,e,i)}randomTimer(){this.timer=j(0,this.current.timing)}removeAllAnimations(){this.animations.length=0,this.active=!0,this.onEnd=void 0,this.onFrame=void 0,V.clearSpriteCache(this.namespace)}reset(){let t=this.animations.find(e=>e.default);t?(this.play(t.name),this.active=!0):this.active=!1}isPlaying(t){return this.current&&this.current.name===t}setImage(){let t=this.current,e=t.sprites[this.imageId];this.size.set(e.width,e.height),this.entity.flipX===void 0&&(this.entity.flipX=this.size.x);let i=`${this.namespace}.${t.name}`,r=V.spriteCache.get(i);r||(r={unflipped:[],flipped:[]},V.spriteCache.set(i,r));let o=this.lookLeft?r.flipped:r.unflipped;if(!o[this.imageId]){let s=M(this.size.x*2,this.size.y);s.context.translate(this.size.x+(this.lookLeft?this.entity.flipX:0),0),this.lookLeft&&s.context.scale(-1,1),s.context.drawImage(e,0,0),o[this.imageId]=s.canvas}this.image=o[this.imageId]}};l(V,"spriteCache",new Map);var et=V;var nt=class{constructor(t,e,i=2){l(this,"color");l(this,"lifetime",0);l(this,"maxLifeTime");l(this,"pos");l(this,"size");l(this,"vel");l(this,"_rect");this.pos=t.clone(),this.color=e,this.size=i,this._rect=t.toRectAddSize(i),this.vel=m.fromAngle(vt(),P(50,150),P(50,150)),this.maxLifeTime=.5+Math.random()}get alive(){return this.lifetime<this.maxLifeTime}get rect(){return this._rect}draw(t,e=new m){t.fillStyle=this.color,t.drawCircle({x:this.pos.x+e.x,y:this.pos.y+e.y},this.size,"fill")}update(t){this.lifetime+=t,this.pos.x+=this.vel.x*t,this.pos.y+=this.vel.y*t,this._rect.set(this.pos.x,this.pos.y)}resetLifetime(){this.lifetime-=this.maxLifeTime}};var it=class{constructor(t,e,i=new m){l(this,"maxLifetime",1/0);l(this,"payload");l(this,"speed",1200);l(this,"image");l(this,"lifetime",0);l(this,"pos");l(this,"rotation",0);l(this,"vel");l(this,"_rect");l(this,"originalImage");this.pos=t.clone(),this.originalImage=e,this.vel=i.clone(),this._rect=t.toRectAddSize(e.width,e.height),this.rebuildRotation()}get alive(){return this.lifetime<this.maxLifetime}get rect(){return this._rect}draw(t,e=new m){t.drawImage(this.image,this.pos.x+e.x,this.pos.y+e.y)}update(t){this.lifetime+=t,this.pos.x+=this.vel.x*this.speed*t,this.pos.y+=this.vel.y*this.speed*t,this._rect.set(this.pos.x,this.pos.y)}rebuildRotation(){this.rotation=Math.atan2(this.vel.y,this.vel.x),this.image=this.originalImage.rotateBy(this.rotation),this._rect.w=this.image.width,this._rect.h=this.image.height}remove(){this.lifetime=this.maxLifetime*2}};var Bt={ANY:Symbol("any"),DEFAULT:Symbol("default"),BACKGROUND:Symbol("background"),MAIN:Symbol("main")},G=class{constructor(){l(this,"canvasBoundingClientRect");l(this,"canvasHolder",{});l(this,"ratio",1);l(this,"resizedSize",new m);l(this,"mainHolder")}get canvas(){return this.mainHolder.canvas}get canvasContext(){return this.mainHolder.context}get height(){return this.canvas.height}set height(t){this.canvas.height=t}get size(){return new m(this.width,this.height)}get width(){return this.canvas.width}set width(t){this.canvas.width=t}finishSetup(){if(this.mainHolder)throw new Error("Already set up.");let t=Object.values(this.canvasHolder).filter(e=>e.type===Bt.MAIN);if(t.length===0)throw new Error("No main canvas defined!");if(t.length>1)throw new Error("Multiple main canvas defined!");if(this.mainHolder=t[0],this.width===0||this.height===0)throw new Error("Main canvas has zero width or height.");this.canvasBoundingClientRect=this.canvas.getBoundingClientRect(),d.enableResize&&y.addEventListener("resized",()=>this.resize())}resize(){let t=window.innerHeight/window.innerWidth;Object.values(this.canvasHolder).forEach(e=>{if(!e.resize)return;let i=e.canvas.height/e.canvas.width,r,o;t<i?(o=window.innerHeight,r=o/i):(r=window.innerWidth,o=r*i),e.canvas===this.canvas&&(this.resizedSize=new m(r,o),this.ratio=r/this.width),e.canvas.style.width=r+"px",e.canvas.style.height=o+"px"}),this.canvasBoundingClientRect=this.canvas.getBoundingClientRect()}setFontSize(t,e=d.font){this.canvasContext.font=`${t}px "${e}"`}setupCanvas(t,e,i=!0){if(!document.querySelector(e))throw new Error("Canvas '"+e+"' does not exist!");if(this.canvasHolder[e])throw new Error(`Canvas "${e}" was already registered!`);let r=Object.assign({},St(e),{id:e,resize:i,type:t});return r.context.fillStyle="white",r.context.strokeStyle="white",r.context.font="12px Arial",this.canvasHolder[e]=r,r}};var Be=.25,$e=5,_=class{constructor(t){l(this,"levelTime",0);l(this,"_isLooping",!1);l(this,"accumulator",0);l(this,"game");l(this,"stop",!1);this.game=t}get isLooping(){return this._isLooping}startLoop(){if(this._isLooping&&this.stop)throw new Error('Gameloop teardown is pending; wait for the "gameloopStopped" event before restarting.');this.stop=!1,this.looper()}stopLoop(){this.stop=!0}draw(t){d.doNotClear||(d.useClearRect?t.clearRect(0,0,this.game.canman.canvas.width,this.game.canman.canvas.height):(t.fillStyle=d.backgroundColor,t.fillRect(0,0,this.game.canman.canvas.width,this.game.canman.canvas.height))),this.game.draw(t)}looper(){if(this._isLooping)return;this._isLooping=!0;let t=this.game.canman.canvasContext,e=D(i=>{if(this.stop){this._isLooping=!1,y.dispatchEvent("gameloopStopped"),console.log("Simulation stopped."),e();return}i>Be?this.accumulator=0:this.accumulator+=i;let r=$e;for(;r-- >0&&this.accumulator>=d.fps;)this.game.update(d.fps),this.accumulator-=d.fps,this.levelTime+=d.fps*1e3;this.draw(t)});console.log("Simulation started.")}};var $t={KEY_0:"Digit0",KEY_1:"Digit1",KEY_2:"Digit2",KEY_3:"Digit3",KEY_4:"Digit4",KEY_5:"Digit5",KEY_6:"Digit6",KEY_7:"Digit7",KEY_8:"Digit8",KEY_9:"Digit9",KEY_A:"KeyA",KEY_B:"KeyB",KEY_C:"KeyC",KEY_D:"KeyD",KEY_DOWN:"ArrowDown",KEY_E:"KeyE",KEY_ENTER:"Enter",KEY_ESCAPE:"Escape",KEY_F:"KeyF",KEY_G:"KeyG",KEY_H:"KeyH",KEY_I:"KeyI",KEY_J:"KeyJ",KEY_K:"KeyK",KEY_L:"KeyL",KEY_LEFT:"ArrowLeft",KEY_M:"KeyM",KEY_N:"KeyN",KEY_O:"KeyO",KEY_P:"KeyP",KEY_Q:"KeyQ",KEY_R:"KeyR",KEY_RIGHT:"ArrowRight",KEY_S:"KeyS",KEY_SPACE:"Space",KEY_T:"KeyT",KEY_TAB:"Tab",KEY_U:"KeyU",KEY_UP:"ArrowUp",KEY_V:"KeyV",KEY_W:"KeyW",KEY_X:"KeyX",KEY_Y:"KeyY",KEY_Z:"KeyZ"},O=class{constructor(t){l(this,"keys",{});let e=i=>{let r=i.code,o=i.type==="keydown";this.keys[r]=o,d.debug&&r===$t.KEY_ESCAPE&&o&&t.gameloop.stopLoop(),y.dispatchEvent("inputKeyboard",this.keys,r,o)};window.addEventListener("keydown",e,!1),window.addEventListener("keyup",e,!1),window.addEventListener("blur",()=>this.reset(),!1),y.addEventListener("gameloopStopped",()=>this.reset())}reset(){for(let t in this.keys)this.keys[t]=!1}stopPress(t){this.keys[t]=!1}isPressed(t){return!!this.keys[t]}};var Ye={LEFT:0,MIDDLE:1,RIGHT:2,PREV:3,FORWARD:4},B=class{constructor(t){l(this,"hasMoved",!1);l(this,"lastEvent",null);l(this,"posReal",new m);l(this,"posRealLast",new m);l(this,"posScaled",new m);l(this,"posScaledLast",new m);l(this,"pressed",[]);l(this,"game");this.game=t;let e=r=>{r.target===this.game.canman.canvas&&r.preventDefault(),this.lastEvent=r,this.hasMoved=!0,this.update(r),y.dispatchEvent("inputPointer",this)},i=r=>{r.target===this.game.canman.canvas&&r.preventDefault(),this.lastEvent=r,this.pressed[r.button]=r.type==="pointerdown",y.dispatchEvent("inputPointer",this)};window.addEventListener("pointermove",e,!1),window.addEventListener("pointerdown",i,!1),window.addEventListener("pointerup",i,!1),window.addEventListener("blur",()=>this.reset(),!1),document.addEventListener("contextmenu",r=>{r.preventDefault()},!1)}reset(){this.pressed.length=0}update(t){this.posRealLast.set(this.posReal.x,this.posReal.y),this.posReal.set(t.clientX,t.clientY),this.posScaledLast.set(this.posScaled.x,this.posScaled.y),this.posScaled.set(C((t.clientX-this.game.canman.canvasBoundingClientRect.left)/this.game.canman.canvasBoundingClientRect.width*this.game.canman.width|0,0,this.game.canman.width),C((t.clientY-this.game.canman.canvasBoundingClientRect.top)/this.game.canman.canvasBoundingClientRect.height*this.game.canman.height|0,0,this.game.canman.height))}};f(window,"t",function(){throw new Error("Call 'prepareLanguage' first!")});var Fe=F((n,t)=>{let e=n>1?` (x${n} since last log)`:"";console.warn(`"${t}" has no translation${e}`)}),Ne=F((n,t,e)=>{let i=n>1?` (x${n} since last log)`:"";console.warn(`Language "${t}" not found, falling back to "${e}"${i}`)});function ze(n,t="en"){if(!n[t])throw new Error(`Default language is defined as "${t}" but isn't supplied!`);let e=new Set;for(let r in n)for(let o in n[r])e.add(o);let i=[...e].sort();for(let r in n)i.forEach(o=>{n[r][o]===void 0&&console.error(`"${r}" misses "${o}"`)});f(window,"t",function(r){let o=d.localStorage.language,s=n[o];return s||(Ne(o,o,t),s=n[t]),s[r]===void 0?(Fe(r,r),r):s[r]})}f(HTMLAudioElement.prototype,"clone",function(){let n=this.cloneNode(!0);return n.volume=this.volume,n});f(HTMLAudioElement.prototype,"stop",function(){this.pause(),this.currentTime=0,this.defaultVolume!==void 0&&(this.volume=this.defaultVolume)});f(CanvasRenderingContext2D.prototype,"fillBar",function(n,t,e="white",i="black"){this.fillStyle=e,this.fillRect(n.x,n.y,n.w,n.h),this.fillStyle=i,this.fillRect(n.x,n.y,n.w*t,n.h)});f(CanvasRenderingContext2D.prototype,"fillFramedBar",function(n,t=.8,e=4,i=["white","black","red"]){this.fillStyle=i[0],this.fillRect(n.x,n.y,n.w,n.h),this.fillStyle=i[1],this.fillRect(n.x+e,n.y+e,n.w-e*2,n.h-e*2),t>0&&(this.fillStyle=i[2],this.fillRect(n.x+e,n.y+e,t*(n.w-e*2),n.h-e*2))});f(CanvasRenderingContext2D.prototype,"drawCircle",function(n,t,e,i=1){this.beginPath(),this.arc(n.x,n.y,t,0,i*2*Math.PI),this[e]()});f(CanvasRenderingContext2D.prototype,"drawRect",function(...n){let t,e,i,r,o;typeof n[0]=="number"?[t,e,i,r,o]=n:[{x:t,y:e,w:i,h:r},o]=n,this.beginPath(),this.rect(t,e,i,r),this[o]()});f(CanvasRenderingContext2D.prototype,"drawRoundRect",function(...n){let t,e,i,r,o,s;typeof n[0]=="number"?[t,e,i,r,o,s]=n:[{x:t,y:e,w:i,h:r},o,s]=n;let{padding:a=0,radius:c=16}=s??{};t+=a,e+=a,i-=a*2,r-=a*2,this.beginPath(),this.roundRect(t,e,i,r,c),this[o]()});f(CanvasRenderingContext2D.prototype,"strokeDottedRect",function(n){this.setLineDash([15,15]),this.lineWidth=5,this.beginPath(),this.moveTo(n.x,n.y),this.lineTo(n.x+n.w,n.y),this.lineTo(n.x+n.w,n.y+n.h),this.lineTo(n.x,n.y+n.h),this.lineTo(n.x,n.y),this.stroke()});f(CanvasRenderingContext2D.prototype,"strokeLine",function(n,t,e,i){this.beginPath(),this.moveTo(n,t),this.lineTo(e,i),this.stroke(),this.closePath()});f(CanvasRenderingContext2D.prototype,"drawPolygon",function(n,t,e){let i=Math.min(t.w,t.h)*.5,r=t.x+t.w*.5,o=t.y+t.h*.5;this.beginPath(),this.moveTo(r+i,o);for(let s=1;s<=n;s++)this.lineTo(Math.round(r+i*Math.cos(s*2*Math.PI/n)),Math.round(o+i*Math.sin(s*2*Math.PI/n)));this.closePath(),this[e]()});f(CanvasRenderingContext2D.prototype,"drawTriangle",function(n,t){this.beginPath(),this.moveTo(n.x,n.y),this.lineTo(n.x+n.w,n.y),this.lineTo(n.x+n.w*.5,n.y+n.h),this[t]()});f(CanvasRenderingContext2D.prototype,"writeText",function(n,t,e,i=.5){this.fillText(n,t-this.measureText(n).width*i,e)});f(CanvasRenderingContext2D.prototype,"writeMultilineText",function(n,t,e,i,r=50,o=50){let s=n.split(" "),a=0;for(;s.length>0&&a<o;){let c=s.length;for(let u=1;u<=s.length;u++)if(this.measureText(s.slice(0,u).join(" ")).width>i){c=Math.max(1,u-1);break}this.writeText(s.slice(0,c).join(" "),t,e,0),s.splice(0,c),e+=r,a++}return a>=o&&console.error("maxAttempts reached",a),a<o});f(CanvasRenderingContext2D.prototype,"drawImageRotated",function(n,t,e,i){this.save(),this.translate(t+n.width*.5,e+n.height*.5),this.rotate(i),this.drawImage(n,-n.width*.5,-n.height*.5),this.restore()});f(CanvasRenderingContext2D.prototype,"generateColor",function(n,t){let e=M(n,n);e.context.strokeStyle=t,e.context.lineWidth=6,e.context.drawRoundRect(0,0,n,n,"stroke",{padding:e.context.lineWidth,radius:15});let i=e.context.getImageData(0,0,n,n).data,r=[];for(let a=0;a<i.length;a+=4)i[a+3]&&r.push([a/4%n,a/4/n|0]);let o=[];r.forEach(a=>{a[0]>n*.5&&o.push(a)});for(let a=r.length-1;a>=0;a--)r[a][0]<=n*.5&&o.push(r[a]);let s=(a,c,u=0,h=0)=>{this.drawImage(e.canvas,a.x+u,a.y+h),this.fillStyle="white";for(let g=0;g<Math.min(c*o.length,o.length);g++)this.fillRect(a.x+o[g][0]+u,a.y+o[g][1]+h,1,1)};return{colors:o,image:e.canvas,drawPartialRoundRect:s}});f(HTMLImageElement.prototype,"subImage",HTMLCanvasElement.prototype.subImage);var rt=class{constructor(t={}){l(this,"canman",new G);l(this,"gameloop");l(this,"keyboard");l(this,"pointer");l(this,"initialized",!1);d.init(t,this),history.scrollRestoration="manual",this.gameloop=new _(this),this.keyboard=new O(this),this.pointer=new B(this)}draw(t){throw new Error("Override draw function!")}update(t){throw new Error("Override update function!")}async init(){throw new Error("Override init() and start the game via preInit() \u2014 do not call init() directly.")}async preInit(t=!0){if(this.initialized)throw new Error("preInit() may only be called once per Game instance.");this.initialized=!0,this.canman.finishSetup(),window.addEventListener("resize",dt(()=>y.dispatchEvent("resized"),250),!1),this.gameloop.levelTime=0,t&&await this.init(),y.dispatchEvent("resized"),d.autoloop&&this.gameloop.startLoop()}};var Lt={NORMAL:{step:3,update(n,t){let e=`rotate(${j(-2,2)*t}deg)`;n("transform",e),n("webkitTransform",e),n("filter",`blur(${t*5}px)`)}},FAST:{step:15,update(n,t){n("filter",`blur(${t*3}px)`)}}},ot=class{constructor(t){l(this,"isShaking",!1);l(this,"shakeType",Lt.NORMAL);l(this,"style");this.style=t.style}shake(t=Lt.NORMAL){if(this.isShaking)return null;this.isShaking=!0,this.shakeType=t;let e=1,i=new Map,r=(c,u)=>{i.has(c)||i.set(c,this.style[c]),this.style[c]=u},o=D(c=>{this.shakeType.update(r,e),e-=this.shakeType.step*c,e<=0&&a()}),s=!0,a=()=>{s&&(s=!1,o(),i.forEach((c,u)=>{this.style[u]=c}),this.isShaking=!1)};return a}};var Ze=600,U;(async()=>U=await q("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAilBMVEUAAAAaGhoZGRkZGRkbGxsZGRkaGhoWFhYgICAZGRkZGRkZGRkZGRkZGRkZGRkYGBgZGRkZGRkbGxsaGhoZGRkZGRkZGRkZGRkZGRkaGhoZGRkZGRkaGhoZGRkZGRkZGRkYGBgZGRkZGRkbGxsZGRkYGBgZGRkYGBgaGhoYGBgYGBgYGBgZGRkaGhqj+rsBAAAALXRSTlMA9fvsBINBCwfhZTnS2sByMcUZE8oe1TUqubeppJOLhlDyeiPOrp57X19dSkdeSFeiAAAELElEQVR42sSY2XaqQBBFD20jozKJI3E2Tun//72bKgmXZBmjLbT7KQ9J2HSdrqoFtMiCw2I2SUKvI0THC5PJbHEIMhjBOc/7HXWVTn9+dtAmbtdOhLqJSOyui3YYvXXUXXTeRmicfN9TNaxtYUf+shtbVtxd+pFdbC1Vo7fPm335Xe3Z0/VyI1FiWSiRm+V6WrPYNXcMwbSq8KCqcCXwMyWDKiXTAE3Q7auSMEpB/C7ApFGoSvpdPEs6q5IVA/hbgImrvM5SPIOMVorxfBe4U4BxfU8xq0hCmyAsM+1L4BEBlvd7ZeV0oyBtoQjvJIEHBRh58hQhbKlV/Uv4xNwBNAQYZy4uYdRIwsclRkkMaAowcXKJ8AceQy4UYfmApkCFbyli8VAZ3EIRwzGeF8B4qIjCxd04E0W8O2hCAM67IiYO7iQb8PEfgQYEmCOXYZDhLvIexyZAcwIIONK9/K735+d7YzQpgLHHBtkdBRtw/HI0K4B8yFVw/sz/pKxWswJVsiYubiILfv8MzQsg4zMoJG6x4PrnaEMAOedgcbP/cv7HaEcAY74LN7pySr9gBWhLAIFFL5j+GgCef0e0J4Ajz8bfYmBz/0WbAuCubOMqgaAL4LQr4NBVEMHVAoQUgDHaFcCYYhBeK0KkPvHRtgB8ek505QbQ/pugfQEktCun+MmMahObEIgpazP8oKs+mcOEAOb0rC6+Qy3Ac8wIOB41A3wjIKkTzAjgRE8LUGdK24I0JSBp55mixuhyBY0IVFdxhP/sKAHSnICkFOxQkeseAAtoH0GOL/Y0JF2TAi4N/j2+oEy8waQA3ij13yIYmxWIOYY1mxBmBRDSqdfqEZkWiDh31RgQqWmBVNBAqDaxAUwLYFDtZgn9ZF7A/to/HD4L8wJceQfAmVZB17yAS8vhuVwPpjAvwBN4Xq4i61cIrMu1hLrA8hUCS+oEQKY+2bxCYENPzhBQBuUrBKTFi9lBKbXFKwSwVUod+JNE8RqBgj9XzKgPGheoeuEMEx6FuoyEGAFPDMQJTwIfeuR9/t6QQw+fp0Go3wbcoWKGrn4jCOHpj6K1WtmWZa/UWn8ceejo74OhiCmEsQj198IOBDUiPZSwLPpjof0PlBL/mrd3GwiBIAiiAgRYCOcMfOzNP70TpNBCr4kAaX8zPVX+B6IluJ4luKIlSDbhOpZzms5lrMEmTI7hfoz3O/bgGEYX0f17s/07uYjCq3ib5y27iv1jxJ9jXpDwkowXpbws940Jb814c8rbcx5Q+IiGh1Q8puNBpY9qeVjt43o+sOAjGz+04mM7P7jko1s/vObjew8wcITDQywc4/Egk0e5OMzmcT4PNHqkk0OtHuv1YLNHuz3c7vF+Lzh4xcNLLgWajxedvOpVILt53a9AeCxQPguk1wLtt0B8blC/C+T3L/T/P3gDDpik2UVvAAAAAElFTkSuQmCC"))();var $=class{constructor(t,e,i){l(this,"axisId");l(this,"controller");l(this,"game");l(this,"pos");this.controller=t,this.game=e,this.axisId=i,this.pos=e.canman.size.mult(.5)}get centerPos(){return this.pos.clone().add(U.width*.5,U.height*.5)}draw(t){t.drawImage(U,this.pos.x,this.pos.y)}update(t){let e=this.controller.stick(this.axisId).mult(Ze*t);e.length()!==0&&(this.pos.x=C(this.pos.x+e.x,0,this.game.canman.width-U.width),this.pos.y=C(this.pos.y+e.y,0,this.game.canman.height-U.height))}};var We={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,SELECT:8,START:9,LEFT_STICK:10,RIGHT_STICK:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,GUIDE:16},Yt=.3,st=class{constructor(t){l(this,"buttons",[]);l(this,"cursors",[]);l(this,"axes",[]);l(this,"index",-1);l(this,"lastTime",0);if(!("getGamepads"in navigator)){console.error("Controller not supported!");return}for(let e=0;e<2;e++)this.cursors.push(new $(this,t,e));window.addEventListener("gamepadconnected",e=>{this.index=e.gamepad.index,console.log("Gamepad connected:",e.gamepad.id),y.dispatchEvent("inputControllerConnected",e.gamepad),this.vibrate()}),window.addEventListener("gamepaddisconnected",e=>{this.index===e.gamepad.index?(this.index=-1,console.log("Our Gamepad was disconnected:",e.gamepad.index),y.dispatchEvent("inputControllerDisconnected")):console.log("Different Gamepad was disconnected:",e.gamepad.index)}),window.addEventListener("blur",()=>this.reset(),!1)}draw(t){this.index<0||this.cursors.forEach(e=>e.draw(t))}update(t){this.cursors.forEach(r=>r.update(t));let e=this.getGamepad();if(!e||this.lastTime===e.timestamp)return;this.lastTime=e.timestamp,this.buttons=e.buttons.map(r=>r.pressed),this.axes.length=0;let i=e.axes;for(let r=0;r+1<i.length;r+=2)this.axes.push(new m(i[r],i[r+1]))}reset(){this.buttons.length=0,this.axes.length=0}vibrate(){let t=this.getGamepad();if(!t)return!1;let e=t.vibrationActuator;return e&&e.playEffect("dual-rumble",{duration:400,weakMagnitude:1,startDelay:0,strongMagnitude:1}),!!e}stick(t){return this.index<0||t>=this.axes.length?new m:this.axes[t].clone().map(e=>gt(e,Yt)).map(e=>Math.sign(e)*bt(Math.abs(e),Yt,1,0,1))}getGamepad(){return this.index<0?null:navigator.getGamepads()[this.index]??null}};var qe=S(n=>{console.warn(`Polygon.collide: found a zero-edge polygon \u2014 no collision possible. (called x${n} since last trace)`)});function Ft(n,t,e,i){return Math.atan2(i-t,e-n)}function Nt(n,t,e,i){return n<e?e-t:n-i}function zt(n,t,e){let i=n.dotProduct(t.points[0]);e.x=i,e.y=i;for(let r=1;r<t.points.length;r++)i=t.points[r].dotProduct(n),i<e.x?e.x=i:i>e.y&&(e.y=i)}var at=class n{constructor(...t){l(this,"_center",new m);l(this,"_points",[]);l(this,"edges",[]);this.addPoints(...t)}static fromCanvas(t,e,i){e=Math.max(2,e);let r=t.width,o=t.height,s=t.getContext("2d").getImageData(0,0,r,o).data,a=[0],c=[0],u=[1],h=0,g=-1,v=0,R=0;for(let p=0;p<r;p+=e)for(let b=0;b<o;b+=1)if(s[(b*r+p)*4+3]!==0){a[h]=p,c[h]=b,u[h]=1,h++,g<0&&(g=b),v=p,R=b;break}for(let p=0;p<o;p+=e)for(let b=r-1;b>=0;b-=1)if(s[(p*r+b)*4+3]!==0&&p>R){a[h]=b,c[h]=p,u[h]=1,h++,v=b,R=p;break}for(let p=r-1;p>=0;p-=e)for(let b=o-1;b>=0;b-=1)if(s[(b*r+p)*4+3]!==0&&p<v){a[h]=p,c[h]=b,u[h]=1,h++,v=p,R=b;break}for(let p=o-1;p>=0;p-=e)for(let b=0;b<r;b+=1)if(s[(p*r+b)*4+3]!==0&&p<R&&p>g){a[h]=b,c[h]=p,u[h]=1,h++,v=b,R=p;break}if(h<3)throw new Error(`Polygon.fromCanvas: scan produced "${h}" vertices (need >=3). Canvas may be empty or detail (${e}) too large.`);for(let p=0;p<h;p++){let b=p,A=(p+1)%h,w=(p+2)%h,mt=Ft(a[b],c[b],a[A],c[A]),pt=Ft(a[A],c[A],a[w],c[w]);Math.abs(wt(mt-pt))<=i&&(u[A]=0)}let x=[];for(let p=0;p<h;p++)u[p]===1&&x.push(new m(a[p],c[p]));return new n(...x)}static fromEdges(t,e){let i=e instanceof m?e:new m(e,e),r=Math.min(i.x,i.y)*.5,o=i.x*.5,s=i.y*.5,a=[];for(let c=1;c<=t;c++)a.push(new m(Math.round(o+r*Math.cos(c*2*Math.PI/t)),Math.round(s+r*Math.sin(c*2*Math.PI/t))));return new n(...a)}static fromRect(t){return new n(new m(t.x,t.y),new m(t.x+t.w,t.y),new m(t.x+t.w,t.y+t.h),new m(t.x,t.y+t.h))}get center(){return this._center}get points(){return this._points}draw(t,e=new m){if(this._points.length!==0){t.beginPath(),t.moveTo(e.x+this._points[0].x|0,e.y+this._points[0].y|0);for(let i=1;i<this._points.length;i++)t.lineTo(e.x+this._points[i].x|0,e.y+this._points[i].y|0);t.closePath(),t.stroke()}}addPoint(t,e){return this._points.push(new m(t,e)),this.update(),this}addPoints(...t){return t.forEach(e=>this._points.push(e.clone())),this.update(),this}offset(t=0,e=0){return this._points.forEach(i=>i.add(t,e)),this.update(),this}rotate(t,e=this.center){if(!t)return this;let i=Math.cos(t),r=Math.sin(t);return this._points.forEach(o=>{let s=o.x-e.x,a=o.y-e.y;o.set(s*i-a*r+e.x,s*r+a*i+e.y)}),this.update(),this}collide(t,e=new m){let i={intersect:!0,minimumTranslationVector:new m,willIntersect:!0},r=this.edges.length,o=t.edges.length;if(r===0||o===0)return qe(),{intersect:!1,minimumTranslationVector:new m,willIntersect:!1};let s=1/0,a=new m,c;for(let u=0;u<r+o;u++){u<r?c=this.edges[u]:c=t.edges[u-r];let h=new m(-c.y,c.x);h.normalize();let g=new m,v=new m;zt(h,this,g),zt(h,t,v),Nt(g.x,g.y,v.x,v.y)>0&&(i.intersect=!1);let R=h.dotProduct(e);R<0?g.x+=R:g.y+=R;let x=Nt(g.x,g.y,v.x,v.y);if(x>0&&(i.willIntersect=!1),!i.intersect&&!i.willIntersect)break;x=Math.abs(x),x<s&&(s=x,a=h.clone(),this.center.clone().sub(t.center).dotProduct(a)<0&&a.negate())}return i.willIntersect&&(i.minimumTranslationVector=a.mult(s)),i}clone(){return new n(...this._points)}update(){if(this._points.length===0)return;let t,e;this.edges.length=0;for(let o=0;o<this._points.length;o++)t=this._points[o],o+1>=this._points.length?e=this._points[0]:e=this._points[o+1],this.edges.push(e.clone().sub(t));let i=0,r=0;this.points.forEach(o=>{i+=o.x,r+=o.y}),this.center.set(i/this._points.length,r/this._points.length)}};function Ue(n){return Y(n,new WeakMap)}function Y(n,t){if(Object(n)!==n||n instanceof Function)return n;let e=n;if(t.has(e))return t.get(e);if(n instanceof Date){let r=new Date(n.getTime());return t.set(e,r),r}if(n instanceof RegExp){let r=new RegExp(n.source,n.flags);return r.lastIndex=n.lastIndex,t.set(e,r),r}if(n instanceof Map){let r=new Map;return t.set(e,r),n.forEach((o,s)=>{r.set(Y(s,t),Y(o,t))}),r}if(n instanceof Set){let r=new Set;return t.set(e,r),n.forEach(o=>{r.add(Y(o,t))}),r}if(Array.isArray(n)){let r=[];return t.set(e,r),n.forEach((o,s)=>{r[s]=Y(o,t)}),r}if(n instanceof ArrayBuffer){let r=n.slice(0);return t.set(e,r),r}if(n instanceof DataView){let r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=new DataView(r);return t.set(e,o),o}if(ArrayBuffer.isView(n)){let r=n.slice();return t.set(e,r),r}let i=Object.create(Object.getPrototypeOf(e));return t.set(e,i),Reflect.ownKeys(e).forEach(r=>{let o=Object.getOwnPropertyDescriptor(e,r);if("value"in o){o.value=Y(o.value,t),Object.defineProperty(i,r,o);return}let s=Y(e[r],t);Object.defineProperty(i,r,{value:s,writable:!0,enumerable:o.enumerable,configurable:o.configurable})}),i}function Je(n){return n.trim().replace(/\s+/g," ")}function Xe(n,t,e){let i=Array.from(n);if(t<0||t>=i.length)throw new Error(`replaceCharAt index out of range: ${t} (length ${i.length})`);let r=Array.from(e);if(r.length!==1)throw new Error(`replaceCharAt requires a single character, got length ${r.length}`);return i[t]=e,i.join("")}return jt(je);})();
|
|
1
|
+
"use strict";var Gleam=(()=>{var st=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var Jt=(n,t,e)=>t in n?st(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Ut=(n,t)=>{for(var e in t)st(n,e,{get:t[e],enumerable:!0})},Xt=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Wt(t))!qt.call(n,i)&&i!==e&&st(n,i,{get:()=>t[i],enumerable:!(r=zt(t,i))||r.enumerable});return n};var jt=n=>Xt(st({},"__esModule",{value:!0}),n);var l=(n,t,e)=>Jt(n,typeof t!="symbol"?t+"":t,e);var Xe={};Ut(Xe,{Animator:()=>Z,AudioBase:()=>L,CANVAS_TYPES:()=>kt,CONTROLLER_KEYS:()=>ze,CanvasManager:()=>$,Color:()=>Y,Controller:()=>it,ControllerCursor:()=>Q,EASINGS:()=>at,EventSystem:()=>y,Game:()=>nt,Gameloop:()=>k,KEYBOARD_KEYS:()=>Ft,Keyboard:()=>O,MAX_DT_SECONDS:()=>Ot,MAX_STEPS_PER_FRAME:()=>Bt,Music:()=>q,POINTER_KEYS:()=>Fe,Particle:()=>tt,Pointer:()=>B,Polygon:()=>ot,Projectile:()=>et,Rect:()=>D,SHAKE_TYPES:()=>Tt,Screenshake:()=>rt,Settings:()=>d,Sound:()=>J,Vec2:()=>m,applyFilterOnCanvas:()=>$t,approxEqual:()=>E,changeColor:()=>ke,chunk:()=>ie,clamp:()=>C,cloneGrid:()=>Pe,colorShifter:()=>Ee,compact:()=>Je,convert1DTo2D:()=>He,convert2DTo1D:()=>Et,createNewCanvas:()=>M,debounce:()=>pt,deepClone:()=>qe,defineMethod:()=>f,delay:()=>Zt,doWhilePressed:()=>Ve,easeIn:()=>Lt,easeInOut:()=>Vt,easeOut:()=>It,generateGrid:()=>Ae,getCanvasConstruct:()=>Mt,getElement:()=>j,getFactorial:()=>de,getUsedColors:()=>Be,hex2rgb:()=>ct,hue2rgb:()=>X,initCSSVariables:()=>Le,isNumeric:()=>ae,isTouchPrimary:()=>Qt,linear:()=>Pt,loadBunch:()=>Ke,loadCanvas:()=>_t,loadImage:()=>ut,loadImageFromJson:()=>_e,loadJson:()=>Kt,loadJsonCommented:()=>De,loadText:()=>Ct,map:()=>ee,mapUnclamped:()=>St,prepareLanguage:()=>Ye,rafLoop:()=>_,random2Pi:()=>gt,randomBetweenFloat:()=>U,randomBetweenInt:()=>H,randomBoolean:()=>At,randomHex:()=>be,randomItem:()=>ft,randomRgb:()=>ge,randomSign:()=>le,remove:()=>G,replaceCharAt:()=>Ue,rgb2Int:()=>A,rgb2hex:()=>fe,rotateHue:()=>$e,roundTo:()=>pe,safeLoad:()=>W,setDisplay:()=>Re,setVisibility:()=>Se,shuffle:()=>oe,splitSpriteSheet:()=>Oe,styleElement:()=>Te,threshold:()=>ne,throttle:()=>S,throttleByKey:()=>N,toDegrees:()=>he,toDotted:()=>re,toHHMMSS:()=>ue,toRadians:()=>me,urlBasename:()=>dt,validateUrl:()=>z,waitForEvent:()=>Ie,wrapDegrees:()=>xt,wrapRadians:()=>yt,wrapValue:()=>P});function pt(n,t){let e;return(...r)=>{clearTimeout(e),e=setTimeout(()=>n(...r),t)}}function Zt(n){return new Promise(t=>setTimeout(t,n))}function Qt(){return matchMedia("(pointer: coarse)").matches}function _(n){let t=0,e=!0,r=0,i=o=>{let s=t===0?0:(o-t)/1e3;t=o,n(s),e&&(r=requestAnimationFrame(i))};return r=requestAnimationFrame(i),()=>{e=!1,cancelAnimationFrame(r)}}function S(n,t=1e3){let e=-1/0,r=0;return()=>{r++;let i=performance.now();if(i-e>t){e=i;let o=r;r=0,n(o)}}}function N(n,t=1e3){let e=new Map;return(r,...i)=>{let o=e.get(r);if(!o){let s,a=S(c=>n(c,...s),t);o=(...c)=>{s=c,a()},e.set(r,o)}o(...i)}}function dt(n){let e=new URL(n,"http://_/").pathname.split("/").pop(),r=e.lastIndexOf("."),i=r>0?e.slice(0,r):e;if(!i)return null;try{return decodeURIComponent(i)}catch{return null}}var K=class K{static addEventListener(t,e,r={}){if(r.signal?.aborted)return function(){};let i=++this.nextId;function o(){let c=K.eventListener[t];c?.delete(i)&&(c.size===0&&delete K.eventListener[t],s.options.signal&&s.options.signal.removeEventListener("abort",o))}let s={callback:e,dispose:o,options:{once:r.once??!1,signal:r.signal}},a=this.eventListener[t];return a||(a=new Map,this.eventListener[t]=a),a.set(i,s),r.signal&&r.signal.addEventListener("abort",o,{once:!0}),o}static dispatchEvent(t,...e){let r=this.eventListener[t];if(!r)return;let i=this.nextId;r.forEach((o,s)=>{if(!(s>i)){o.options.once&&o.dispose();try{o.callback(...e)}catch(a){let c=a instanceof Error?a.message:String(a);this.logListenerError(`${t}:${c}`,t,a)}}})}};l(K,"eventListener",{}),l(K,"logListenerError",N((t,e,r)=>{let i=t>1?` (x${t} since last log)`:"";console.error(`EventSystem listener for "${e}" threw${i}:`,r)})),l(K,"nextId",0);var y=K;var te={1:"ABORTED",2:"NETWORK",3:"DECODE",4:"SRC_NOT_SUPPORTED"},L=class{constructor(t=!0){l(this,"songs",new Map);l(this,"_enabled");l(this,"registered",!1);this._enabled=t,y.addEventListener("gameloopStopped",()=>this.stop())}get enabled(){return this._enabled}set enabled(t){this._enabled=t,t||this.stop()}register(t=1,...e){if(this.throwOnBadVolume(t,"defaultVolume"),this.registered)throw new Error("register() can only be called once per instance");this.registered=!0,e.forEach(r=>{typeof r=="string"?r={name:dt(r)??r,path:r}:r.volume!==void 0&&this.throwOnBadVolume(r.volume,`Volume of "${r.name}"`);let i=new window.Audio;i.addEventListener("error",()=>{let o=i.error,s=o?`${te[o.code]??o.code}${o.message?`: ${o.message}`:""}`:"unknown";console.error(`Failed to load audio "${r.name}" from "${i.src}": ${s}`)}),i.preload="auto",i.src=r.path,i.id=r.name,i.volume=r.volume??t,i.defaultVolume=i.volume,this.songs.set(r.name,i)})}stop(){}throwOnBadVolume(t,e){if(!Number.isFinite(t))throw new Error(e+" is invalid, it has to be in range of 0 to 1");if(t<0)throw new Error(e+" has to be above 0. What's a negative volume anyway?");if(t>1)throw new Error(e+" has to be lower or equal to 1! If you need a louder volume, you need to update the audio file itself.")}};function E(n,t,e=1e-9){return Math.abs(n-t)<=e}function C(n,t,e){return Math.min(e,Math.max(t,n))}function St(n,t,e,r,i){return t===e?r:r+(i-r)*(n-t)/(e-t)}function ee(n,t,e,r,i){return C(St(n,t,e,r,i),Math.min(r,i),Math.max(r,i))}function ne(n,t){return Math.abs(n)<t?0:n}function re(n){return Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g,".")}function P(n,t,e){if(E(t,e))throw new RangeError(`wrapValue: min and max must differ (got ${t})`);t>e&&([t,e]=[e,t]);let r=e-t;return((n-t)%r+r)%r+t}function Lt(n){return n*n}function Vt(n){return n<.5?2*n*n:1-2*(1-n)*(1-n)}function It(n){return n*(2-n)}function Pt(n){return n}var at={"ease-in":Lt,"ease-in-out":Vt,"ease-out":It,linear:Pt};function ie(n,t){if(!Number.isFinite(t)||t<1)throw new RangeError(`chunk: maxLength must be a finite number >= 1 (got ${t})`);let e=[],r=[];return n.forEach((i,o)=>{r.push(i),(r.length===t||o===n.length-1)&&(e.push(r),r=[])}),e}function ft(n){if(n.length===0)throw new Error("randomItem called on empty array");return n[Math.random()*n.length|0]}function G(n,t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}function oe(n){let t=n.slice();for(let e=t.length-1;e>0;e--){let r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}var q=class extends L{constructor(){super(...arguments);l(this,"last",null);l(this,"current",null);l(this,"next",null);l(this,"fadeCancel",null)}get isPlaying(){return!!this.fadeCancel||this.current instanceof window.Audio&&!this.current.paused}get enabled(){return super.enabled}set enabled(e){super.enabled=e,e&&!this.isPlaying&&this.fade()}fade(e=null,r=1e3,i={cur:"ease-in",next:"ease-out"}){if(r<=0)throw new Error(`fadeTime must be > 0, got ${r}`);if(this.songs.size===0)throw new Error("No music registered!");if(e&&!this.songs.has(e))throw new Error(`Music "${e}" not registered!`);if(!this.enabled)return;if(this.fadeCancel&&(console.warn("Stopping current music fading."),this.fadeCancel(),this.fadeCancel=null,this.current?.stop(),this.current=this.next,this.next=null),this.songs.size===1){console.info("Only one music registered, playing that looped."),this.current=this.songs.values().next().value,this.current.loop=!0,this.current.play();return}e?this.next=this.songs.get(e):(this.next=this.getRandom(),this.next||(console.warn("Not enough songs to pick a fresh one, replaying the previous one."),this.next=this.last)),this.next.onended=()=>{this.fade()},this.next.volume=0,this.next.play(),console.log(`Start fading to music: "${this.next.id}"`),this.current&&(this.current.onended=()=>{});let o=at[i.cur],s=at[i.next],a=r/1e3,c=0,u=this.current?.volume??0;this.fadeCancel=_(h=>{c+=h/a,this.current&&(this.current.volume=u*(1-C(o(c),0,1))),this.next.volume=this.next.defaultVolume*C(s(c),0,1),c>=1&&(this.fadeCancel?.(),this.fadeCancel=null,this.current&&(this.current.stop(),this.current.volume=this.current.defaultVolume),this.next.volume=this.next.defaultVolume,this.last=this.current,this.current=this.next,this.next=null)})}stop(){super.stop(),this.fadeCancel?.(),this.fadeCancel=null,this.current?.stop(),this.next?.stop(),this.last=this.current,this.current=this.next,this.next=null}getRandom(){let e=Array.from(this.songs.values());return this.last&&G(e,this.last),this.current&&G(e,this.current),e.length===0?null:ft(e)}};var J=class extends L{constructor(){super(...arguments);l(this,"currentSounds",[])}play(e){if(this.songs.size===0)throw new Error("No sounds registered!");if(!this.songs.has(e))throw new Error(`Sound "${e}" not registered!`);if(!this.enabled)return Promise.resolve();let r=this.songs.get(e).clone();this.currentSounds.push(r);let i=()=>G(this.currentSounds,r);return r.onended=i,r.onerror=()=>{i(),console.error(`Playback failed for Sound "${e}", reason: ${r.error?.message??"unknown"}`)},r.play().catch(o=>{throw i(),o})}stop(){super.stop(),this.currentSounds.forEach(e=>e.stop()),this.currentSounds.length=0}};var se=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;function ae(n){return typeof n=="number"?Number.isFinite(n):typeof n=="string"?se.test(n.trim()):!1}function gt(){return Math.random()*Math.PI*2}function U(n,t){return n>t&&([n,t]=[t,n]),n+Math.random()*(t-n)}function H(n,t){return n>t&&([n,t]=[t,n]),Math.floor(n+Math.random()*(t-n+1))}function At(){return Math.random()>=.5}function le(){return At()?1:-1}var ce=S(n=>{console.warn(`toHHMMSS() received invalid input (NaN, Infinity, or negative) x${n} since last warning; returning "00:00".`)});function ue(n){if(!Number.isFinite(n)||n<0)return ce(),"00:00";n=Math.floor(n);let t=Math.floor(n/3600),e=Math.floor((n-t*3600)/60),r=n-t*3600-e*60,i=t<10?"0"+t:""+t,o=e<10?"0"+e:""+e,s=r<10?"0"+r:""+r;return t===0?`${o}:${s}`:`${i}:${o}:${s}`}function he(n){return n*180/Math.PI}function me(n){return n*Math.PI/180}function yt(n){return P(n,-Math.PI,Math.PI)}function xt(n){return P(n,-180,180)}function pe(n,t){let e=Math.pow(10,t);return Math.round(n*e)/e}var lt={0:1},bt=0,Ht=1/0;function de(n){let t=Math.floor(n);if(t<0||!Number.isFinite(t))throw new Error("getFactorial requires non-negative integer");if(t>=Ht)return 1/0;if(lt[t]!==void 0)return lt[t];let e=lt[bt];for(let r=bt+1;r<=t;r++){if(e*=r,!Number.isFinite(e))return Ht=r,1/0;lt[r]=e,bt=r}return e}function fe(n,t,e){return"#"+(16777216+A(n,t,e)).toString(16).slice(1)}function A(n,t,e,r){if(r===void 0)return n<<16|t<<8|e;let i=Math.round(r*255);return(n<<24|t<<16|e<<8|i)>>>0}function ct(n){return n.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(t,e,r,i)=>"#"+e+e+r+r+i+i).substring(1).match(/.{2}/g).map(t=>parseInt(t,16))}function X(n,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?n+(t-n)*6*e:e<1/2?t:e<2/3?n+(t-n)*(2/3-e)*6:n}function be(){return"#"+Math.random().toString(16).slice(2,6)}function ge(n=0,t=255){return[H(n,t),H(n,t),H(n,t)]}var Y=class n{constructor(t,e,r,i){l(this,"_r");l(this,"_g");l(this,"_b");l(this,"_alpha",1);this.set(t,e,r,i)}static fromHex(t){let e=t.replace("#","").toUpperCase();if(!/^[0-9A-F]+$/.test(e))throw new Error(`Invalid hex color: ${t}`);if((e.length===3||e.length===4)&&(e=e.split("").map(s=>s+s).join("")),e.length!==6&&e.length!==8)throw new Error(`Invalid hex color: ${t}`);let r=parseInt(e.slice(0,2),16),i=parseInt(e.slice(2,4),16),o=parseInt(e.slice(4,6),16);if(e.length===8){let s=parseInt(e.slice(6,8),16);return new n(r,i,o,s/255)}return new n(r,i,o)}static fromHSL(t,e,r,i=1){let o=P(t,0,360)/360,s=e/100,a=r/100,c,u,h;if(s===0)c=u=h=a;else{let g=a<.5?a*(1+s):a+s-a*s,v=2*a-g;c=X(v,g,o+1/3),u=X(v,g,o),h=X(v,g,o-1/3)}return new n(c*255,u*255,h*255,i)}get r(){return this._r}get g(){return this._g}get b(){return this._b}get alpha(){return this._alpha}set(t,e,r,i){if(this._r=C(t,0,255),this._g=C(e,0,255),this._b=C(r,0,255),i!==void 0){let o=C(i,0,1);this._alpha=E(o,0)?0:E(o,1)?1:o}return this}applyMatrix(t,e,r,i,o,s,a,c,u){return this.set(this.r*t+this.g*e+this.b*r,this.r*i+this.g*o+this.b*s,this.r*a+this.g*c+this.b*u)}brightness(t){return this.set(this.r*t,this.g*t,this.b*t)}contrast(t){return this.set(127.5+(this.r-127.5)*t,127.5+(this.g-127.5)*t,127.5+(this.b-127.5)*t)}grayscale(t=1){let e=.2126+.7874*(1-t),r=.7152-.7152*(1-t),i=.0722-.0722*(1-t),o=.2126-.2126*(1-t),s=.7152+.2848*(1-t),a=.0722-.0722*(1-t),c=.2126-.2126*(1-t),u=.7152-.7152*(1-t),h=.0722+.9278*(1-t);return this.applyMatrix(e,r,i,o,s,a,c,u,h)}hueRotate(t){let e=Math.cos(t),r=Math.sin(t),i=.213+e*.787-r*.213,o=.715-e*.715-r*.715,s=.072-e*.072+r*.928,a=.213-e*.213+r*.143,c=.715+e*.285+r*.14,u=.072-e*.072-r*.283,h=.213-e*.213-r*.787,g=.715-e*.715+r*.715,v=.072+e*.928+r*.072;return this.applyMatrix(i,o,s,a,c,u,h,g,v)}invert(t=1){return this.set(this.r*(1-t)+(255-this.r)*t,this.g*(1-t)+(255-this.g)*t,this.b*(1-t)+(255-this.b)*t)}mix(t,e){let r=1-e;return this.set(this.r*r+t.r*e,this.g*r+t.g*e,this.b*r+t.b*e,this.alpha*r+t.alpha*e)}round(){return this.set(Math.round(this.r),Math.round(this.g),Math.round(this.b))}saturate(t=1){let e=.213+.787*t,r=.715-.715*t,i=.072-.072*t,o=.213-.213*t,s=.715+.285*t,a=.072-.072*t,c=.213-.213*t,u=.715-.715*t,h=.072+.928*t;return this.applyMatrix(e,r,i,o,s,a,c,u,h)}sepia(t=1){let e=.393+.607*(1-t),r=.769-.769*(1-t),i=.189-.189*(1-t),o=.349-.349*(1-t),s=.686+.314*(1-t),a=.168-.168*(1-t),c=.272-.272*(1-t),u=.534-.534*(1-t),h=.131+.869*(1-t);return this.applyMatrix(e,r,i,o,s,a,c,u,h)}shade(t){let e=t<0?0:255,r=Math.abs(t);return this.set(this.r+(e-this.r)*r,this.g+(e-this.g)*r,this.b+(e-this.b)*r)}toHex(){let t=Math.round(this.r).toString(16).padStart(2,"0"),e=Math.round(this.g).toString(16).padStart(2,"0"),r=Math.round(this.b).toString(16).padStart(2,"0"),i=`#${t}${e}${r}`;if(this.alpha===1)return i;let o=Math.round(this.alpha*255);return`${i}${o.toString(16).padStart(2,"0")}`}toHSL(){let{h:t,s:e,l:r}=this.toHSLObject(),i=Math.round(t),o=Math.round(e),s=Math.round(r);return this.alpha===1?`hsl(${i}, ${o}%, ${s}%)`:`hsla(${i}, ${o}%, ${s}%, ${this.alpha.toFixed(2)})`}toHSLObject(){let t=this.r/255,e=this.g/255,r=this.b/255,i=Math.max(t,e,r),o=Math.min(t,e,r),s=(i+o)/2,a=0,c=0;if(i!==o){let u=i-o;switch(c=s>.5?u/(2-i-o):u/(i+o),i){case t:a=(e-r)/u+(e<r?6:0);break;case e:a=(r-t)/u+2;break;case r:a=(t-e)/u+4;break}a/=6}return{h:a*360,s:c*100,l:s*100,a:this.alpha}}toRGB(){let t=Math.round(this.r),e=Math.round(this.g),r=Math.round(this.b);return this.alpha===1?`rgb(${t}, ${e}, ${r})`:`rgba(${t}, ${e}, ${r}, ${this.alpha.toFixed(2)})`}clone(){return new n(this.r,this.g,this.b,this.alpha)}equals(t,e=!0){return E(this.r,t.r)&&E(this.g,t.g)&&E(this.b,t.b)&&(!e||E(this.alpha,t.alpha))}};var ye=2,xe=3,ve=4,we=5;function Ee(n){let t=new Y(n[0],n[1],n[2]);return new vt(t).solve().filter.replace("filter: ","").replace(";","")}var vt=class{constructor(t){l(this,"reusedColor");l(this,"target");l(this,"targetHSL");this.target=t,this.targetHSL=t.toHSLObject(),this.reusedColor=new Y(0,0,0)}css(t){let[e,r,i,o,s,a]=t;return`filter: invert(${Math.round(e)}%) sepia(${Math.round(r)}%) saturate(${Math.round(i)}%) hue-rotate(${Math.round(o*3.6)}deg) brightness(${Math.round(s)}%) contrast(${Math.round(a)}%);`}loss(t){let[e,r,i,o,s,a]=t,c=this.reusedColor;c.set(0,0,0),c.invert(e/100),c.sepia(r/100),c.saturate(i/100),c.hueRotate(o/100*Math.PI*2),c.brightness(s/100),c.contrast(a/100);let u=c.toHSLObject();return Math.abs(c.r-this.target.r)+Math.abs(c.g-this.target.g)+Math.abs(c.b-this.target.b)+Math.abs(xt(u.h-this.targetHSL.h))/1.8+Math.abs(u.s-this.targetHSL.s)+Math.abs(u.l-this.targetHSL.l)}solve(){let t=this.solveNarrow(this.solveWide());return{values:t.values,loss:t.loss,filter:this.css(t.values)}}solveNarrow(t){let e=t.loss,r=2,i=e+1,o=[.25*i,.25*i,i,.25*i,.2*i,.2*i];return this.spsa(e,o,r,t.values,500)}solveWide(){let r=[60,180,18e3,600,1.2,1.2],i={loss:1/0,values:[50,20,3750,50,100,100]};for(let o=0;i.loss>25&&o<3;o++){let s=[50,20,3750,50,100,100],a=this.spsa(5,r,15,s,1e3);a.loss<i.loss&&(i=a)}return i}spsa(t,e,r,i,o){i=i.slice();let s=1,a=.16666666666666666,c=i.slice(),u=1/0,h=[0,0,0,0,0,0],g=[0,0,0,0,0,0],v=[0,0,0,0,0,0];for(let x=0;x<o;x++){let p=r/Math.pow(x+1,a);for(let w=0;w<6;w++)h[w]=Math.random()>.5?1:-1,g[w]=i[w]+p*h[w],v[w]=i[w]-p*h[w];let b=this.loss(g)-this.loss(v);for(let w=0;w<6;w++){let ht=b/(2*p)*h[w],mt=e[w]/Math.pow(t+x+1,s);i[w]=R(i[w]-mt*ht,w)}let I=this.loss(i);I<u&&(c=i.slice(),u=I)}return{values:c,loss:u};function R(x,p){let b=100;return p===ye?b=7500:(p===ve||p===we)&&(b=200),p===xe?x=P(x,0,b):x<0?x=0:x>b&&(x=b),x}}};var D=class n{constructor(t=0,e=0,r=0,i=0){l(this,"_h",0);l(this,"_w",0);l(this,"_x",0);l(this,"_y",0);l(this,"_sides");l(this,"sideIsDirty",!0);this.set(t,e,r,i)}static fromBoundingClientRect(t){return t instanceof HTMLElement&&(t=t.getBoundingClientRect()),new n(t.left,t.top,t.width,t.height)}static fromPolygon(t){if(t.points.length===0)throw new Error("Supplied polygon has no points!");let e=1/0,r=1/0,i=-1/0,o=-1/0;return t.points.forEach(s=>{s.x<e&&(e=s.x),s.x>i&&(i=s.x),s.y<r&&(r=s.y),s.y>o&&(o=s.y)}),new n(e,r,i-e,o-r)}get h(){return this._h}set h(t){this._h=t,this.sideIsDirty=!0}get w(){return this._w}set w(t){this._w=t,this.sideIsDirty=!0}get x(){return this._x}set x(t){this._x=t,this.sideIsDirty=!0}get y(){return this._y}set y(t){this._y=t,this.sideIsDirty=!0}get sides(){return this.sideIsDirty&&(this._sides={bottom:this.y+this.h,centerPos:new m(this.x+this.w*.5,this.y+this.h*.5),halfSize:new m(this.w*.5,this.h*.5),right:this.x+this.w},this.sideIsDirty=!1),this._sides}inflate(t){return this.x-=t,this.y-=t,this.w+=2*t,this.h+=2*t,this.sideIsDirty=!0,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.sideIsDirty=!0,this}set(t=0,e=0,r,i){return typeof t=="number"?(this.x=t,this.y=e):("w"in t&&(this.w=t.w,this.h=t.h),this.x=t.x,this.y=t.y),r!==void 0&&(this.w=r),i!==void 0&&(this.h=i),this.sideIsDirty=!0,this}collide(t){return this.x<=t.x+t.w&&this.x+this.w>=t.x&&this.y<=t.y+t.h&&this.y+this.h>=t.y}collideFull(t){return t.x+t.w<=this.x+this.w&&t.x>=this.x&&t.y>=this.y&&t.y+t.h<=this.y+this.h}collidePoint(t){return this.x<=t.x&&t.x<=this.x+this.w&&this.y<=t.y&&t.y<=this.y+this.h}collideSide(t){let e=this.x+this.w*.5-(t.x+t.w*.5),r=this.y+this.h*.5-(t.y+t.h*.5),i=(this.w+t.w)*.5,o=(this.h+t.h)*.5,s=i*r,a=o*e,c="none";return Math.abs(e)<=i&&Math.abs(r)<=o&&(s>a?c=s>-a?"bottom":"left":c=s>-a?"right":"top"),c}pos(){return new m(this.x,this.y)}size(){return new m(this.w,this.h)}toString(){return`Rect [x: ${this.x}, y: ${this.y}, w: ${this.w}, h: ${this.h}]`}clone(){return new n(this.x,this.y,this.w,this.h)}equals(t,e=!0){let r=E(this.x,t.x)&&E(this.y,t.y);return r&&e&&(r=E(this.w,t.w)&&E(this.h,t.h)),r}};var T={Add:1,Sub:2,Mult:3,Div:4,Rem:5,Equal:6,Mod:7},Ce=S(n=>console.warn(`Vec2.normalize() called on zero vector x${n} since last warning; returning zero.`)),Me=S(n=>console.warn(`Vec2 operation produced non-finite value x${n} since last warning; check for zero divisor.`)),m=class n{constructor(t=0,e){l(this,"x",0);l(this,"y",0);this.calculate(T.Equal,t,e)}static fromAngle(t,e=1,r=e){return new n(Math.cos(t)*e,Math.sin(t)*r)}set(t,e){return this.calculate(T.Equal,t,e)}abs(){return this.map(Math.abs)}add(t,e){return this.calculate(T.Add,t,e)}ceil(){return this.map(Math.ceil)}clamp(t,e=t){return this.x=C(this.x,t[0],t[1]),this.y=C(this.y,e[0],e[1]),this}div(t,e){return this.calculate(T.Div,t,e)}floor(){return this.map(Math.floor)}map(t){return this.x=t(this.x,0),this.y=t(this.y,1),this}mod(t,e){return this.calculate(T.Mod,t,e)}mult(t,e){return this.calculate(T.Mult,t,e)}negate(){return this.mult(-1)}normalize(){let t=this.length();return E(t,0)?(Ce(),this):this.map(e=>e/t)}normalizeManhattan(){let t=this.lengthManhattan();return E(t,0)?this:this.map(e=>e/t)}rem(t,e){return this.calculate(T.Rem,t,e)}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}sub(t,e){return this.calculate(T.Sub,t,e)}angle(t){return t?Math.atan2(t.y-this.y,t.x-this.x):Math.atan2(this.y,this.x)}distance(t){return Math.sqrt(Math.pow(t.x-this.x,2)+Math.pow(t.y-this.y,2))}distanceManhattan(t){return Math.abs(t.x-this.x)+Math.abs(t.y-this.y)}dotProduct(t){return this.x*t.x+this.y*t.y}isValid(){return Number.isFinite(this.x)&&Number.isFinite(this.y)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}lengthManhattan(){return Math.abs(this.x)+Math.abs(this.y)}max(){return Math.max(this.x,this.y)}min(){return Math.min(this.x,this.y)}toArray(){return[this.x,this.y]}toRectAddPos(t,e){return this.concat(!0,t,e)}toRectAddSize(t,e){return this.concat(!1,t,e)}toString(){return`Vec2 [x: ${this.x}, y: ${this.y}]`}clone(){return new n(this.x,this.y)}equals(t,e){let[r,i]=this.getValues(t,e);return E(this.x,r)&&E(this.y,i)}calculate(t,e,r){let[i,o]=this.getValues(e,r);switch(t){case T.Add:this.x+=i,this.y+=o;break;case T.Sub:this.x-=i,this.y-=o;break;case T.Mult:this.x*=i,this.y*=o;break;case T.Div:this.x/=i,this.y/=o;break;case T.Rem:this.x%=i,this.y%=o;break;case T.Equal:this.x=i,this.y=o;break;case T.Mod:this.x=(this.x%i+i)%i,this.y=(this.y%o+o)%o;break;default:break}return this.isValid()||Me(),this}concat(t,e,r){let[i,o]=this.getValues(e,r);return t?new D(i,o,this.x,this.y):new D(this.x,this.y,i,o)}getValues(t,e){let r=0,i=0;if(typeof t=="number")r=t,e===void 0?i=t:i=e;else if(e===void 0)r=t.x,i=t.y;else throw new Error("When x is a Vector2, y must be omitted!");return[r,i]}};var wt="gleam",d=class{static get localStorage(){return this._localStorage}static init(t,e){if(this.initialized)throw new Error("Settings.init called twice");if(Object.assign(this,t),!(Number.isFinite(this.fps)&&this.fps>0))throw new Error(`Settings.fps must be > 0, got ${this.fps}`);this.debug&&(window.game=e),this.warnBeforeClose&&window.addEventListener("beforeunload",i=>(this.triedToClose?.(),i.preventDefault(),i.returnValue=!0,"Are you sure?"),!1),this._localStorage.language=navigator.language.split("-")[0]||"en";let r=localStorage.getItem(wt);if(r)try{let i=JSON.parse(r);Object.assign(this._localStorage,i)}catch{console.error("Couldn't parse local storage! Will be cleaned now.",r),localStorage.removeItem(wt)}this.initialized=!0}static setLocalStorage(t,e){this._localStorage[t]=e,localStorage.setItem(wt,JSON.stringify(this._localStorage))}};l(d,"antialias",!1),l(d,"autoloop",!0),l(d,"backgroundColor","#444"),l(d,"debug",!1),l(d,"doNotClear",!1),l(d,"enableResize",!0),l(d,"font","Arial"),l(d,"fps",1/60),l(d,"triedToClose"),l(d,"useClearRect",!0),l(d,"warnBeforeClose",!1),l(d,"initialized",!1),l(d,"_localStorage",{language:""});function j(n,t=document){let e=t.querySelector(n);if(!e)throw new Error(`Element not found: ${n}`);return e}function Te(n,t){Object.assign(n.style,t)}function Re(n,t){n.style.display=t?"":"none"}function Se(n,t){n.style.visibility=t?"":"hidden"}function Le(){let n=j(":root");return{root:n,get(t){return getComputedStyle(n).getPropertyValue("--"+t)},set(t,e){n.style.setProperty("--"+t,e)}}}function Ve(n,t,e=200){let r=j(n),i,o=null;function s(u){o===null&&(o=u.pointerId,r.setPointerCapture(o),clearInterval(i),t(),i=setInterval(()=>t(),e))}function a(u){u.pointerId===o&&(clearInterval(i),r.releasePointerCapture(u.pointerId),o=null)}r.addEventListener("pointerdown",s),r.addEventListener("pointerup",a),r.addEventListener("pointercancel",a);function c(){r.removeEventListener("pointerdown",s),r.removeEventListener("pointerup",a),r.removeEventListener("pointercancel",a),clearInterval(i),o!==null&&(r.releasePointerCapture(o),o=null)}return c}async function Ie(n,t,e){if(e?.aborted)throw e.reason;return new Promise((r,i)=>{n.addEventListener(t,()=>r(),{once:!0,signal:e}),e?.addEventListener("abort",()=>i(e.reason),{once:!0})})}function Pe(n){return n.map(t=>t.slice())}function He(n,t){return{x:n%t,y:n/t|0}}function Et(n,t,e){return n+e*t}function Ae(n,t,e){let r=typeof e=="function";return Array.from({length:n},(i,o)=>Array.from({length:t},(s,a)=>r?e(a,o):e))}function f(n,t,e){Object.defineProperty(n,t,{value:e,configurable:!0,writable:!0})}var Dt=1e4;function z(n){let t=n.trim().match(/^([a-z][a-z0-9+.-]*):/i);if(!t)return;let e=t[1].toLowerCase();if(!["blob","data","http","https"].includes(e))throw new Error(`Invalid URL protocol: ${n}`)}function W(n,t,e){let r,i=new Promise((o,s)=>{r=setTimeout(()=>{s(new Error(`Timeout (${Dt}ms) when loading ${e}: ${t}`))},Dt)});return Promise.race([n,i]).catch(o=>{clearTimeout(r);let s=o?.message||String(o);throw console.error(`${e} failed on ${t}
|
|
2
|
+
${s}`),o}).finally(()=>clearTimeout(r))}async function ut(n){return z(n),W(new Promise((t,e)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>e(new Error(`Image failed to load: ${n}`)),r.crossOrigin="anonymous",r.src=n}),n,"image")}async function _t(n){return z(n),W((async()=>{let t=await ut(n),e=M(t.width,t.height);return e.canvas.id=n,e.context.drawImage(t,0,0),e.canvas})(),n,"canvas")}async function Ct(n){return z(n),W((async()=>{let t=await fetch(n);if(!t.ok)throw new Error(`HTTP ${t.status}: Failed to load text from ${n}
|
|
3
|
+
Status: ${t.status} ${t.statusText}`);return t.text()})(),n,"text")}async function Kt(n){return z(n),W(Ct(n).then(t=>JSON.parse(t)),n,"JSON")}async function De(n){return z(n),W(Ct(n).then(t=>{let e=t.split(`
|
|
4
|
+
`).filter(r=>{let i=r.trim();return!(!i||i.startsWith("//"))}).join(`
|
|
5
|
+
`);return JSON.parse(e)}),n,"JSON (commented)")}async function _e(n,t,e=!1){n.endsWith("/")||(n+="/");let r;if(e)try{r=JSON.parse(t)}catch(s){throw new Error(`Failed to parse inline JSON: ${s.message}`)}else{let s=n+t+".json";r=await Kt(s)}if(!r||!r.options?.file){let s=e?"inline JSON":`${n}${t}.json`;throw new Error(`JSON missing 'options.file' property
|
|
6
|
+
Source: ${s}`)}let i=await _t(n+r.options.file),o={};if(!r.sprites||!Array.isArray(r.sprites))throw new Error(`JSON missing 'sprites' array
|
|
7
|
+
Source: ${n}${t}.json`);return r.sprites.forEach((s,a)=>{if(s.x===void 0||s.y===void 0||!s.w||!s.h||!s.name)throw new Error(`Invalid sprite data at index ${a}: ${JSON.stringify(s,null,2)}`);let c=i.subImage(s.x,s.y,s.w,s.h);for(let u in s)c.dataset[u]=String(s[u]);o[s.name]=c}),o}async function Ke(n){let t={},e=Object.keys(n);return Promise.all(e.map(r=>n[r])).then(r=>(e.forEach((i,o)=>{t[i]=r[o]}),t))}f(HTMLCanvasElement.prototype,"hasAnyColor",function(){return this.getContext("2d").getImageData(0,0,this.width,this.height).data.some(t=>t!==0)});f(HTMLCanvasElement.prototype,"getPixelAt",function(n,t,e="integer"){let r=0,i=0,o=0,s=0;if(n>=0&&n<this.width&&t>=0&&t<this.height){let a=this.getContext("2d").getImageData(n,t,1,1).data;r=a[0],i=a[1],o=a[2],s=a[3]}switch(e){case"array":return[r,i,o,s];case"json":return{r,g:i,b:o,a:s};case"string":return`rgba(${r}, ${i}, ${o}, ${s})`;default:return A(r,i,o,s/255)}});f(HTMLCanvasElement.prototype,"replaceColors",function(n){let t=new Map;for(let o in n){let[s,a,c]=ct(o),[u,h,g]=ct(n[o]);t.set(A(s,a,c),[u,h,g])}let e=this.getContext("2d"),r=e.getImageData(0,0,this.width,this.height),{data:i}=r;for(let o=0;o<i.length;o+=4){if(i[o+3]===0)continue;let s=t.get(A(i[o],i[o+1],i[o+2]));s!==void 0&&(i[o]=s[0],i[o+1]=s[1],i[o+2]=s[2])}return e.putImageData(r,0,0),this});f(HTMLCanvasElement.prototype,"rotateBy",function(n){let t=Math.ceil(Math.sqrt(this.width*this.width+this.height*this.height)),e=M(t,t);return e.context.translate(t*.5,t*.5),e.context.rotate(n),e.context.drawImage(this,-this.width*.5,-this.height*.5),e.context.translate(-t*.5,-t*.5),e.canvas});f(HTMLCanvasElement.prototype,"rotateByAligned",function(n){let t=M(this.width,this.height);return t.context.translate(this.width*.5,this.height*.5),t.context.rotate(n),t.context.translate(-this.width*.5,-this.height*.5),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"autoCrop",function(){let n={x:this.width,y:this.height,update(s,a){this.x=Math.min(this.x,s),this.y=Math.min(this.y,a)}},t={x:0,y:0,update(s,a){this.x=Math.max(this.x,s),this.y=Math.max(this.y,a)}},r=this.getContext("2d").getImageData(0,0,this.width,this.height);for(let s=0;s<this.height;s++)for(let a=0;a<this.width;a++)r.data[Et(a*4,s*4,this.width)+3]!==0&&(n.update(a,s),t.update(a,s));if(n.x>t.x)return this.clone();let i=t.x-n.x+1,o=t.y-n.y+1;return this.subImage(n.x,n.y,i,o)});f(HTMLCanvasElement.prototype,"scaleBy",function(n=1,t=n){if(n<=0||t<=0)throw new Error(`scaleBy requires positive scale factors, got: ${n} x ${t}`);let e=M(this.width*n,this.height*t);return e.context.scale(n,t),e.context.drawImage(this,0,0),e.canvas});f(HTMLCanvasElement.prototype,"resize",function(n,t=!0){return t?this.scaleBy(n/this.width):this.scaleBy(n/this.height)});f(HTMLCanvasElement.prototype,"flipX",function(n=0){let t=M(this.width,this.height);return t.context.translate(this.width+n,0),t.context.scale(-1,1),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"flipY",function(n=0){let t=M(this.width,this.height);return t.context.translate(0,this.height+n),t.context.scale(1,-1),t.context.drawImage(this,0,0),t.canvas});f(HTMLCanvasElement.prototype,"subImage",function(n,t,e,r){e===void 0&&(e=this.width),r===void 0&&(r=this.height);let i=M(e,r);return i.context.drawImage(this,n,t,e,r,0,0,e,r),i.canvas});f(HTMLCanvasElement.prototype,"clone",function(){let n=M(this.width,this.height);n.canvas.id=this.id,n.context.drawImage(this,0,0);for(let t in this.dataset)n.canvas.dataset[t]=this.dataset[t];return n.canvas});f(HTMLCanvasElement.prototype,"toImage",function(){return ut(this.toDataURL())});function M(n,t,e=d.antialias){let r=document.createElement("canvas");r.width=n,r.height=t;let i=r.getContext("2d");return i.imageSmoothingEnabled=e,{canvas:r,context:i}}function Mt(n){let t=j(n),e=t.getContext("2d");return{canvas:t,context:e}}function $t(n,t,e=n.width,r=n.height){let i=M(e,r);return i.context.filter=t,i.context.drawImage(n,0,0),i.context.filter="none",i.canvas}function $e(n,t,e,r){return $t(n,"hue-rotate("+t+"deg)",e,r)}function ke(n,t,e){n.save(),n.clearRect(0,0,t.width,t.height),n.globalCompositeOperation="source-over",n.drawImage(t,0,0,t.width,t.height),n.globalCompositeOperation="color",n.fillStyle=e,n.fillRect(0,0,t.width,t.height),n.globalCompositeOperation="destination-in",n.drawImage(t,0,0,t.width,t.height),n.restore()}function Oe(n,t,e){if(n.width%t!==0||n.height%e!==0)throw new Error(`SpriteSheet doesn't divide evenly: ${n.width}x${n.height} / ${t}x${e}`);let r=n.width/t,i=n.height/e,o=[];return Array.from({length:e}).forEach((s,a)=>{Array.from({length:t}).forEach((c,u)=>{o.push(n.subImage(u*r,a*i,r,i))})}),o}function Be(n,t=1,e=0,r=0){let i=n.getContext("2d").getImageData(0,0,n.width,n.height).data,o=new Map;for(let a=0;a<i.length;a+=4){let c=A(i[a],i[a+1],i[a+2]);o.set(c,(o.get(c)??0)+1)}(t<1||e>0||r>0)&&o.forEach((a,c)=>{let u=a*t|0;u===0||e>0&&u<e||r>0&&u>r?o.delete(c):o.set(c,u)});let s=new Map;return o.forEach((a,c)=>{s.set("#"+(16777216+c).toString(16).slice(1),a)}),s}var V=class V{constructor(t,e){l(this,"active",!0);l(this,"image");l(this,"imageId",0);l(this,"lookLeft",!1);l(this,"onEnd");l(this,"size",new m);l(this,"animations",[]);l(this,"currentAnimation",0);l(this,"entity");l(this,"lastPlayed");l(this,"namespace");l(this,"onFrame");l(this,"playVersion",0);l(this,"timer",0);this.entity=t,this.namespace=e}static clearSpriteCache(t){if(t===void 0){V.spriteCache.clear();return}let e=`${t}.`;V.spriteCache.forEach((r,i)=>{i.startsWith(e)&&V.spriteCache.delete(i)})}get current(){return this.animations[this.currentAnimation]}draw(t,e=new m){t.drawImage(this.image,this.entity.pos.x+e.x-this.size.x,this.entity.pos.y+e.y)}update(t){if(this.active&&(this.timer+=t,!(this.timer<=this.current.timing))){if(this.timer-=this.current.timing,this.imageId++,this.imageId>=this.current.sprites.length){let e=this.onEnd;this.onEnd=void 0,this.onFrame=void 0,this.imageId=0;let r=this.playVersion;if(e?.(),this.playVersion!==r)return;if(this.lastPlayed){this.play(this.lastPlayed),this.lastPlayed=void 0;return}if(this.current.sprites.length===1){this.active=!1;return}}if(this.onFrame?.[this.imageId]){let e=this.onFrame[this.imageId];delete this.onFrame[this.imageId];let r=this.playVersion;if(e(),this.playVersion!==r)return}this.active&&this.setImage()}}add(t,e,r,i=!1){i&&this.animations.some(o=>o.default)&&console.error("Only one default animation allowed!"),this.animations.some(o=>o.name===t)&&console.error("Duplicate animation name!"),this.animations.push({default:i,name:t,sprites:e,timing:r}),i&&this.play(t)}addAnimation(t,e=!1){this.add(t.name,t.sprites,t.timing,t.default||e)}drawRotated(t,e,r=new m){let i=this.entity.pos.x+r.x,o=this.entity.pos.y+r.y,s=this.image.width*.75,a=this.image.height*.5;t.setTransform(1,0,0,1,i+s-this.size.x,o+a),t.rotate(e),t.drawImage(this.image,-s,-a),t.setTransform(1,0,0,1,0,0)}play(t,e,r){let i=this.animations.findIndex(a=>a.name===t);if(i<0)throw new Error(`Animator.play: animation "${t}" not found`);this.playVersion++;let o=this.playVersion;this.imageId=0,this.timer=0,this.currentAnimation=i,this.setImage();let s=this.onEnd;this.onEnd=e,this.onFrame=r,s?.(),this.playVersion===o&&(this.active=!0)}playIfNot(t,e,r){return this.isPlaying(t)?!1:(this.play(t,e,r),!0)}playNextOnce(t){this.lastPlayed=t}playOnce(t,e,r){this.lastPlayed=this.current?.name,this.play(t,e,r)}randomTimer(){this.timer=U(0,this.current.timing)}removeAllAnimations(){this.animations.length=0,this.active=!0,this.onEnd=void 0,this.onFrame=void 0,V.clearSpriteCache(this.namespace)}reset(){let t=this.animations.find(e=>e.default);t?(this.play(t.name),this.active=!0):this.active=!1}isPlaying(t){return this.current&&this.current.name===t}setImage(){let t=this.current,e=t.sprites[this.imageId];this.size.set(e.width,e.height),this.entity.flipX===void 0&&(this.entity.flipX=this.size.x);let r=`${this.namespace}.${t.name}`,i=V.spriteCache.get(r);i||(i={unflipped:[],flipped:[]},V.spriteCache.set(r,i));let o=this.lookLeft?i.flipped:i.unflipped;if(!o[this.imageId]){let s=M(this.size.x*2,this.size.y);s.context.translate(this.size.x+(this.lookLeft?this.entity.flipX:0),0),this.lookLeft&&s.context.scale(-1,1),s.context.drawImage(e,0,0),o[this.imageId]=s.canvas}this.image=o[this.imageId]}};l(V,"spriteCache",new Map);var Z=V;var Q=class{constructor(t,e,r,i=80){l(this,"controller");l(this,"crosshair");l(this,"range");l(this,"sticks",[]);this.controller=t,this.crosshair=e,this.range=i,r.forEach(o=>this.sticks.push({pos:o.clone(),offset:new m}))}draw(t){this.sticks.forEach(e=>{t.drawImage(this.crosshair,e.pos.x+e.offset.x,e.pos.y+e.offset.y)})}update(t){let e=1-Math.pow(.5,t/.05);this.controller.poll().forEach((r,i)=>{let o=this.sticks[i].offset;o.x+=(r.x*this.range-o.x)*e,o.y+=(r.y*this.range-o.y)*e})}};var tt=class{constructor(t,e,r=2){l(this,"color");l(this,"lifetime",0);l(this,"maxLifeTime");l(this,"pos");l(this,"size");l(this,"vel");l(this,"_rect");this.pos=t.clone(),this.color=e,this.size=r,this._rect=t.toRectAddSize(r),this.vel=m.fromAngle(gt(),H(50,150),H(50,150)),this.maxLifeTime=.5+Math.random()}get alive(){return this.lifetime<this.maxLifeTime}get rect(){return this._rect}draw(t,e=new m){t.fillStyle=this.color,t.drawCircle({x:this.pos.x+e.x,y:this.pos.y+e.y},this.size,"fill")}update(t){this.lifetime+=t,this.pos.x+=this.vel.x*t,this.pos.y+=this.vel.y*t,this._rect.set(this.pos.x,this.pos.y)}resetLifetime(){this.lifetime-=this.maxLifeTime}};var et=class{constructor(t,e,r=new m){l(this,"maxLifetime",1/0);l(this,"payload");l(this,"speed",1200);l(this,"image");l(this,"lifetime",0);l(this,"pos");l(this,"rotation",0);l(this,"vel");l(this,"_rect");l(this,"originalImage");this.pos=t.clone(),this.originalImage=e,this.vel=r.clone(),this._rect=t.toRectAddSize(e.width,e.height),this.rebuildRotation()}get alive(){return this.lifetime<this.maxLifetime}get rect(){return this._rect}draw(t,e=new m){t.drawImage(this.image,this.pos.x+e.x,this.pos.y+e.y)}update(t){this.lifetime+=t,this.pos.x+=this.vel.x*this.speed*t,this.pos.y+=this.vel.y*this.speed*t,this._rect.set(this.pos.x,this.pos.y)}rebuildRotation(){this.rotation=Math.atan2(this.vel.y,this.vel.x),this.image=this.originalImage.rotateBy(this.rotation),this._rect.w=this.image.width,this._rect.h=this.image.height}remove(){this.lifetime=this.maxLifetime*2}};var kt={ANY:Symbol("any"),DEFAULT:Symbol("default"),BACKGROUND:Symbol("background"),MAIN:Symbol("main")},$=class{constructor(){l(this,"canvasBoundingClientRect");l(this,"canvasHolder",{});l(this,"ratio",1);l(this,"resizedSize",new m);l(this,"mainHolder")}get canvas(){return this.mainHolder.canvas}get canvasContext(){return this.mainHolder.context}get height(){return this.canvas.height}set height(t){this.canvas.height=t}get size(){return new m(this.width,this.height)}get width(){return this.canvas.width}set width(t){this.canvas.width=t}finishSetup(){if(this.mainHolder)throw new Error("Already set up.");let t=Object.values(this.canvasHolder).filter(e=>e.type===kt.MAIN);if(t.length===0)throw new Error("No main canvas defined!");if(t.length>1)throw new Error("Multiple main canvas defined!");if(this.mainHolder=t[0],this.width===0||this.height===0)throw new Error("Main canvas has zero width or height.");this.canvasBoundingClientRect=this.canvas.getBoundingClientRect(),d.enableResize&&y.addEventListener("resized",()=>this.resize())}resize(){let t=window.innerHeight/window.innerWidth;Object.values(this.canvasHolder).forEach(e=>{if(!e.resize)return;let r=e.canvas.height/e.canvas.width,i,o;t<r?(o=window.innerHeight,i=o/r):(i=window.innerWidth,o=i*r),e.canvas===this.canvas&&(this.resizedSize=new m(i,o),this.ratio=i/this.width),e.canvas.style.width=i+"px",e.canvas.style.height=o+"px"}),this.canvasBoundingClientRect=this.canvas.getBoundingClientRect()}setFontSize(t,e=d.font){this.canvasContext.font=`${t}px "${e}"`}setupCanvas(t,e,r=d.enableResize){if(!document.querySelector(e))throw new Error("Canvas '"+e+"' does not exist!");if(this.canvasHolder[e])throw new Error(`Canvas "${e}" was already registered!`);let i=Object.assign({},Mt(e),{id:e,resize:r,type:t});return i.context.fillStyle="white",i.context.strokeStyle="white",i.context.font="12px Arial",this.canvasHolder[e]=i,i}};var Ot=.25,Bt=5,k=class{constructor(t){l(this,"levelTime",0);l(this,"_isLooping",!1);l(this,"accumulator",0);l(this,"game");l(this,"stop",!1);this.game=t}get isLooping(){return this._isLooping}startLoop(){if(this._isLooping&&this.stop)throw new Error('Gameloop teardown is pending; wait for the "gameloopStopped" event before restarting.');this.stop=!1,this.looper()}stopLoop(){this.stop=!0}draw(t){d.doNotClear||(d.useClearRect?t.clearRect(0,0,this.game.canman.canvas.width,this.game.canman.canvas.height):(t.fillStyle=d.backgroundColor,t.fillRect(0,0,this.game.canman.canvas.width,this.game.canman.canvas.height))),this.game.draw(t)}looper(){if(this._isLooping)return;this._isLooping=!0;let t=this.game.canman.canvasContext,e=_(r=>{if(this.stop){this._isLooping=!1,y.dispatchEvent("gameloopStopped"),console.log("Simulation stopped."),e();return}r>Ot?this.accumulator=0:this.accumulator+=r;let i=Bt;for(;i-- >0&&this.accumulator>=d.fps;)this.game.update(d.fps),this.accumulator-=d.fps,this.levelTime+=d.fps*1e3;this.draw(t)});console.log("Simulation started.")}};var Ft={KEY_0:"Digit0",KEY_1:"Digit1",KEY_2:"Digit2",KEY_3:"Digit3",KEY_4:"Digit4",KEY_5:"Digit5",KEY_6:"Digit6",KEY_7:"Digit7",KEY_8:"Digit8",KEY_9:"Digit9",KEY_A:"KeyA",KEY_B:"KeyB",KEY_C:"KeyC",KEY_D:"KeyD",KEY_DOWN:"ArrowDown",KEY_E:"KeyE",KEY_ENTER:"Enter",KEY_ESCAPE:"Escape",KEY_F:"KeyF",KEY_G:"KeyG",KEY_H:"KeyH",KEY_I:"KeyI",KEY_J:"KeyJ",KEY_K:"KeyK",KEY_L:"KeyL",KEY_LEFT:"ArrowLeft",KEY_M:"KeyM",KEY_N:"KeyN",KEY_O:"KeyO",KEY_P:"KeyP",KEY_Q:"KeyQ",KEY_R:"KeyR",KEY_RIGHT:"ArrowRight",KEY_S:"KeyS",KEY_SPACE:"Space",KEY_T:"KeyT",KEY_TAB:"Tab",KEY_U:"KeyU",KEY_UP:"ArrowUp",KEY_V:"KeyV",KEY_W:"KeyW",KEY_X:"KeyX",KEY_Y:"KeyY",KEY_Z:"KeyZ"},O=class{constructor(t){l(this,"keys",{});let e=r=>{let i=r.code,o=r.type==="keydown";this.keys[i]=o,d.debug&&i===Ft.KEY_ESCAPE&&o&&t.gameloop.stopLoop(),y.dispatchEvent("inputKeyboard",this.keys,i,o)};window.addEventListener("keydown",e,!1),window.addEventListener("keyup",e,!1),window.addEventListener("blur",()=>this.reset(),!1),y.addEventListener("gameloopStopped",()=>this.reset())}reset(){for(let t in this.keys)this.keys[t]=!1}stopPress(t){this.keys[t]=!1}isPressed(t){return!!this.keys[t]}};var Fe={LEFT:0,MIDDLE:1,RIGHT:2,PREV:3,FORWARD:4},B=class{constructor(t){l(this,"hasMoved",!1);l(this,"lastEvent",null);l(this,"posReal",new m);l(this,"posRealLast",new m);l(this,"posScaled",new m);l(this,"posScaledLast",new m);l(this,"pressed",[]);l(this,"game");this.game=t;let e=i=>{i.target===this.game.canman.canvas&&i.preventDefault(),this.lastEvent=i,this.hasMoved=!0,this.update(i),y.dispatchEvent("inputPointer",this)},r=i=>{i.target===this.game.canman.canvas&&i.preventDefault(),this.lastEvent=i,this.pressed[i.button]=i.type==="pointerdown",y.dispatchEvent("inputPointer",this)};window.addEventListener("pointermove",e,!1),window.addEventListener("pointerdown",r,!1),window.addEventListener("pointerup",r,!1),window.addEventListener("blur",()=>this.reset(),!1),document.addEventListener("contextmenu",i=>{i.preventDefault()},!1)}reset(){this.pressed.length=0}update(t){this.posRealLast.set(this.posReal.x,this.posReal.y),this.posReal.set(t.clientX,t.clientY),this.posScaledLast.set(this.posScaled.x,this.posScaled.y),this.posScaled.set(C((t.clientX-this.game.canman.canvasBoundingClientRect.left)/this.game.canman.canvasBoundingClientRect.width*this.game.canman.width|0,0,this.game.canman.width),C((t.clientY-this.game.canman.canvasBoundingClientRect.top)/this.game.canman.canvasBoundingClientRect.height*this.game.canman.height|0,0,this.game.canman.height))}};f(window,"t",function(){throw new Error("Call 'prepareLanguage' first!")});var Ne=N((n,t)=>{let e=n>1?` (x${n} since last log)`:"";console.warn(`"${t}" has no translation${e}`)}),Ge=N((n,t,e)=>{let r=n>1?` (x${n} since last log)`:"";console.warn(`Language "${t}" not found, falling back to "${e}"${r}`)});function Ye(n,t="en"){if(!n[t])throw new Error(`Default language is defined as "${t}" but isn't supplied!`);let e=new Set;for(let i in n)for(let o in n[i])e.add(o);let r=[...e].sort();for(let i in n)r.forEach(o=>{n[i][o]===void 0&&console.error(`"${i}" misses "${o}"`)});f(window,"t",function(i){let o=d.localStorage.language,s=n[o];return s||(Ge(o,o,t),s=n[t]),s[i]===void 0?(Ne(i,i),i):s[i]})}f(HTMLAudioElement.prototype,"clone",function(){let n=this.cloneNode(!0);return n.volume=this.volume,n});f(HTMLAudioElement.prototype,"stop",function(){this.pause(),this.currentTime=0,this.defaultVolume!==void 0&&(this.volume=this.defaultVolume)});f(CanvasRenderingContext2D.prototype,"fillBar",function(n,t,e="white",r="black"){this.fillStyle=e,this.fillRect(n.x,n.y,n.w,n.h),this.fillStyle=r,this.fillRect(n.x,n.y,n.w*t,n.h)});f(CanvasRenderingContext2D.prototype,"fillFramedBar",function(n,t=.8,e=4,r=["white","black","red"]){this.fillStyle=r[0],this.fillRect(n.x,n.y,n.w,n.h),this.fillStyle=r[1],this.fillRect(n.x+e,n.y+e,n.w-e*2,n.h-e*2),t>0&&(this.fillStyle=r[2],this.fillRect(n.x+e,n.y+e,t*(n.w-e*2),n.h-e*2))});f(CanvasRenderingContext2D.prototype,"drawCircle",function(n,t,e,r=1){this.beginPath(),this.arc(n.x,n.y,t,0,r*2*Math.PI),this[e]()});f(CanvasRenderingContext2D.prototype,"drawRect",function(...n){let t,e,r,i,o;typeof n[0]=="number"?[t,e,r,i,o]=n:[{x:t,y:e,w:r,h:i},o]=n,this.beginPath(),this.rect(t,e,r,i),this[o]()});f(CanvasRenderingContext2D.prototype,"drawRoundRect",function(...n){let t,e,r,i,o,s;typeof n[0]=="number"?[t,e,r,i,o,s]=n:[{x:t,y:e,w:r,h:i},o,s]=n;let{padding:a=0,radius:c=16}=s??{};t+=a,e+=a,r-=a*2,i-=a*2,this.beginPath(),this.roundRect(t,e,r,i,c),this[o]()});f(CanvasRenderingContext2D.prototype,"strokeDottedRect",function(n){this.setLineDash([15,15]),this.lineWidth=5,this.beginPath(),this.moveTo(n.x,n.y),this.lineTo(n.x+n.w,n.y),this.lineTo(n.x+n.w,n.y+n.h),this.lineTo(n.x,n.y+n.h),this.lineTo(n.x,n.y),this.stroke()});f(CanvasRenderingContext2D.prototype,"strokeLine",function(n,t,e,r){this.beginPath(),this.moveTo(n,t),this.lineTo(e,r),this.stroke(),this.closePath()});f(CanvasRenderingContext2D.prototype,"drawPolygon",function(n,t,e){let r=Math.min(t.w,t.h)*.5,i=t.x+t.w*.5,o=t.y+t.h*.5;this.beginPath(),this.moveTo(i+r,o);for(let s=1;s<=n;s++)this.lineTo(Math.round(i+r*Math.cos(s*2*Math.PI/n)),Math.round(o+r*Math.sin(s*2*Math.PI/n)));this.closePath(),this[e]()});f(CanvasRenderingContext2D.prototype,"drawTriangle",function(n,t){this.beginPath(),this.moveTo(n.x,n.y),this.lineTo(n.x+n.w,n.y),this.lineTo(n.x+n.w*.5,n.y+n.h),this[t]()});f(CanvasRenderingContext2D.prototype,"writeText",function(n,t,e,r=.5){this.fillText(n,t-this.measureText(n).width*r,e)});f(CanvasRenderingContext2D.prototype,"writeMultilineText",function(n,t,e,r,i=50,o=50){let s=n.split(" "),a=0;for(;s.length>0&&a<o;){let c=s.length;for(let u=1;u<=s.length;u++)if(this.measureText(s.slice(0,u).join(" ")).width>r){c=Math.max(1,u-1);break}this.writeText(s.slice(0,c).join(" "),t,e,0),s.splice(0,c),e+=i,a++}return a>=o&&console.error("maxAttempts reached",a),a<o});f(CanvasRenderingContext2D.prototype,"drawImageRotated",function(n,t,e,r){this.save(),this.translate(t+n.width*.5,e+n.height*.5),this.rotate(r),this.drawImage(n,-n.width*.5,-n.height*.5),this.restore()});f(CanvasRenderingContext2D.prototype,"generateColor",function(n,t){let e=M(n,n);e.context.strokeStyle=t,e.context.lineWidth=6,e.context.drawRoundRect(0,0,n,n,"stroke",{padding:e.context.lineWidth,radius:15});let r=e.context.getImageData(0,0,n,n).data,i=[];for(let a=0;a<r.length;a+=4)r[a+3]&&i.push([a/4%n,a/4/n|0]);let o=[];i.forEach(a=>{a[0]>n*.5&&o.push(a)});for(let a=i.length-1;a>=0;a--)i[a][0]<=n*.5&&o.push(i[a]);let s=(a,c,u=0,h=0)=>{this.drawImage(e.canvas,a.x+u,a.y+h),this.fillStyle="white";for(let g=0;g<Math.min(c*o.length,o.length);g++)this.fillRect(a.x+o[g][0]+u,a.y+o[g][1]+h,1,1)};return{colors:o,image:e.canvas,drawPartialRoundRect:s}});f(HTMLImageElement.prototype,"subImage",HTMLCanvasElement.prototype.subImage);var nt=class{constructor(t={}){l(this,"canman",new $);l(this,"gameloop");l(this,"keyboard");l(this,"pointer");l(this,"initialized",!1);d.init(t,this),history.scrollRestoration="manual",this.gameloop=new k(this),this.keyboard=new O(this),this.pointer=new B(this)}draw(t){throw new Error("Override draw function!")}update(t){throw new Error("Override update function!")}async init(){throw new Error("Override init() and start the game via preInit() \u2014 do not call init() directly.")}async preInit(t=!0){if(this.initialized)throw new Error("preInit() may only be called once per Game instance.");this.initialized=!0,this.canman.finishSetup(),window.addEventListener("resize",pt(()=>y.dispatchEvent("resized"),250),!1),this.gameloop.levelTime=0,t&&await this.init(),y.dispatchEvent("resized"),d.autoloop&&this.gameloop.startLoop()}};var Tt={NORMAL:{step:3,update(n,t){let e=`rotate(${U(-2,2)*t}deg)`;n("transform",e),n("webkitTransform",e),n("filter",`blur(${t*5}px)`)}},FAST:{step:15,update(n,t){n("filter",`blur(${t*3}px)`)}}},rt=class{constructor(t){l(this,"isShaking",!1);l(this,"shakeType",Tt.NORMAL);l(this,"style");this.style=t.style}shake(t=Tt.NORMAL){if(this.isShaking)return null;this.isShaking=!0,this.shakeType=t;let e=1,r=new Map,i=(c,u)=>{r.has(c)||r.set(c,this.style[c]),this.style[c]=u},o=_(c=>{this.shakeType.update(i,e),e-=this.shakeType.step*c,e<=0&&a()}),s=!0,a=()=>{s&&(s=!1,o(),r.forEach((c,u)=>{this.style[u]=c}),this.isShaking=!1)};return a}};var ze={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,SELECT:8,START:9,LEFT_STICK:10,RIGHT_STICK:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,GUIDE:16},Rt=.25,it=class{constructor(){l(this,"buttons",[]);l(this,"axes",[]);l(this,"index",-1);l(this,"lastTime",0);if(!("getGamepads"in navigator)){console.error("Controller not supported!");return}window.addEventListener("gamepadconnected",t=>{this.index=t.gamepad.index;for(let e=0;e<t.gamepad.axes.length/2;e++)this.axes.push(new m);console.log("Gamepad connected:",t.gamepad.id),y.dispatchEvent("inputControllerConnected",t.gamepad),this.vibrate()}),window.addEventListener("gamepaddisconnected",t=>{this.index===t.gamepad.index?(this.index=-1,console.log("Our Gamepad was disconnected:",t.gamepad.index),this.reset(),y.dispatchEvent("inputControllerDisconnected")):console.log("Different Gamepad was disconnected:",t.gamepad.index)}),window.addEventListener("blur",()=>this.reset(),!1)}poll(){let t=this.getGamepad();if(!t||this.lastTime===t.timestamp)return this.axes;this.lastTime=t.timestamp,this.buttons=t.buttons.map(e=>e.pressed);for(let e=0;e<this.axes.length;e++){this.axes[e].set(t.axes[e*2],t.axes[e*2+1]);let r=this.axes[e].length();r<Rt?this.axes[e].set(0,0):this.axes[e].mult((Math.min(1,r)-Rt)/(1-Rt)/r)}return this.axes}reset(){this.buttons.length=0,this.axes.length=0}vibrate(){let t=this.getGamepad();if(!t)return!1;let e=t.vibrationActuator;return e&&e.playEffect("dual-rumble",{duration:400,weakMagnitude:1,startDelay:0,strongMagnitude:1}),!!e}getGamepad(){return this.index<0?null:navigator.getGamepads()[this.index]??null}};var We=S(n=>{console.warn(`Polygon.collide: found a zero-edge polygon \u2014 no collision possible. (called x${n} since last trace)`)});function Nt(n,t,e,r){return Math.atan2(r-t,e-n)}function Gt(n,t,e,r){return n<e?e-t:n-r}function Yt(n,t,e){let r=n.dotProduct(t.points[0]);e.x=r,e.y=r;for(let i=1;i<t.points.length;i++)r=t.points[i].dotProduct(n),r<e.x?e.x=r:r>e.y&&(e.y=r)}var ot=class n{constructor(...t){l(this,"_center",new m);l(this,"_points",[]);l(this,"edges",[]);this.addPoints(...t)}static fromCanvas(t,e,r){e=Math.max(2,e);let i=t.width,o=t.height,s=t.getContext("2d").getImageData(0,0,i,o).data,a=[0],c=[0],u=[1],h=0,g=-1,v=0,R=0;for(let p=0;p<i;p+=e)for(let b=0;b<o;b+=1)if(s[(b*i+p)*4+3]!==0){a[h]=p,c[h]=b,u[h]=1,h++,g<0&&(g=b),v=p,R=b;break}for(let p=0;p<o;p+=e)for(let b=i-1;b>=0;b-=1)if(s[(p*i+b)*4+3]!==0&&p>R){a[h]=b,c[h]=p,u[h]=1,h++,v=b,R=p;break}for(let p=i-1;p>=0;p-=e)for(let b=o-1;b>=0;b-=1)if(s[(b*i+p)*4+3]!==0&&p<v){a[h]=p,c[h]=b,u[h]=1,h++,v=p,R=b;break}for(let p=o-1;p>=0;p-=e)for(let b=0;b<i;b+=1)if(s[(p*i+b)*4+3]!==0&&p<R&&p>g){a[h]=b,c[h]=p,u[h]=1,h++,v=b,R=p;break}if(h<3)throw new Error(`Polygon.fromCanvas: scan produced "${h}" vertices (need >=3). Canvas may be empty or detail (${e}) too large.`);for(let p=0;p<h;p++){let b=p,I=(p+1)%h,w=(p+2)%h,ht=Nt(a[b],c[b],a[I],c[I]),mt=Nt(a[I],c[I],a[w],c[w]);Math.abs(yt(ht-mt))<=r&&(u[I]=0)}let x=[];for(let p=0;p<h;p++)u[p]===1&&x.push(new m(a[p],c[p]));return new n(...x)}static fromEdges(t,e){let r=e instanceof m?e:new m(e,e),i=Math.min(r.x,r.y)*.5,o=r.x*.5,s=r.y*.5,a=[];for(let c=1;c<=t;c++)a.push(new m(Math.round(o+i*Math.cos(c*2*Math.PI/t)),Math.round(s+i*Math.sin(c*2*Math.PI/t))));return new n(...a)}static fromRect(t){return new n(new m(t.x,t.y),new m(t.x+t.w,t.y),new m(t.x+t.w,t.y+t.h),new m(t.x,t.y+t.h))}get center(){return this._center}get points(){return this._points}draw(t,e=new m){if(this._points.length!==0){t.beginPath(),t.moveTo(e.x+this._points[0].x|0,e.y+this._points[0].y|0);for(let r=1;r<this._points.length;r++)t.lineTo(e.x+this._points[r].x|0,e.y+this._points[r].y|0);t.closePath(),t.stroke()}}addPoint(t,e){return this._points.push(new m(t,e)),this.update(),this}addPoints(...t){return t.forEach(e=>this._points.push(e.clone())),this.update(),this}offset(t=0,e=0){return this._points.forEach(r=>r.add(t,e)),this.update(),this}rotate(t,e=this.center){if(!t)return this;let r=Math.cos(t),i=Math.sin(t);return this._points.forEach(o=>{let s=o.x-e.x,a=o.y-e.y;o.set(s*r-a*i+e.x,s*i+a*r+e.y)}),this.update(),this}collide(t,e=new m){let r={intersect:!0,minimumTranslationVector:new m,willIntersect:!0},i=this.edges.length,o=t.edges.length;if(i===0||o===0)return We(),{intersect:!1,minimumTranslationVector:new m,willIntersect:!1};let s=1/0,a=new m,c;for(let u=0;u<i+o;u++){u<i?c=this.edges[u]:c=t.edges[u-i];let h=new m(-c.y,c.x);h.normalize();let g=new m,v=new m;Yt(h,this,g),Yt(h,t,v),Gt(g.x,g.y,v.x,v.y)>0&&(r.intersect=!1);let R=h.dotProduct(e);R<0?g.x+=R:g.y+=R;let x=Gt(g.x,g.y,v.x,v.y);if(x>0&&(r.willIntersect=!1),!r.intersect&&!r.willIntersect)break;x=Math.abs(x),x<s&&(s=x,a=h.clone(),this.center.clone().sub(t.center).dotProduct(a)<0&&a.negate())}return r.willIntersect&&(r.minimumTranslationVector=a.mult(s)),r}clone(){return new n(...this._points)}update(){if(this._points.length===0)return;let t,e;this.edges.length=0;for(let o=0;o<this._points.length;o++)t=this._points[o],o+1>=this._points.length?e=this._points[0]:e=this._points[o+1],this.edges.push(e.clone().sub(t));let r=0,i=0;this.points.forEach(o=>{r+=o.x,i+=o.y}),this.center.set(r/this._points.length,i/this._points.length)}};function qe(n){return F(n,new WeakMap)}function F(n,t){if(Object(n)!==n||n instanceof Function)return n;let e=n;if(t.has(e))return t.get(e);if(n instanceof Date){let i=new Date(n.getTime());return t.set(e,i),i}if(n instanceof RegExp){let i=new RegExp(n.source,n.flags);return i.lastIndex=n.lastIndex,t.set(e,i),i}if(n instanceof Map){let i=new Map;return t.set(e,i),n.forEach((o,s)=>{i.set(F(s,t),F(o,t))}),i}if(n instanceof Set){let i=new Set;return t.set(e,i),n.forEach(o=>{i.add(F(o,t))}),i}if(Array.isArray(n)){let i=[];return t.set(e,i),n.forEach((o,s)=>{i[s]=F(o,t)}),i}if(n instanceof ArrayBuffer){let i=n.slice(0);return t.set(e,i),i}if(n instanceof DataView){let i=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=new DataView(i);return t.set(e,o),o}if(ArrayBuffer.isView(n)){let i=n.slice();return t.set(e,i),i}let r=Object.create(Object.getPrototypeOf(e));return t.set(e,r),Reflect.ownKeys(e).forEach(i=>{let o=Object.getOwnPropertyDescriptor(e,i);if("value"in o){o.value=F(o.value,t),Object.defineProperty(r,i,o);return}let s=F(e[i],t);Object.defineProperty(r,i,{value:s,writable:!0,enumerable:o.enumerable,configurable:o.configurable})}),r}function Je(n){return n.trim().replace(/\s+/g," ")}function Ue(n,t,e){let r=Array.from(n);if(t<0||t>=r.length)throw new Error(`replaceCharAt index out of range: ${t} (length ${r.length})`);let i=Array.from(e);if(i.length!==1)throw new Error(`replaceCharAt requires a single character, got length ${i.length}`);return r[t]=e,r.join("")}return jt(Xe);})();
|
|
8
8
|
//# sourceMappingURL=gleam.min.js.map
|