@ptkdev/svelte-game-boilerplate
Version:
Make javascript game with this friendly kaboom boilerplate made with typescript, svelte and love
322 lines (307 loc) • 252 kB
JavaScript
(function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
var app = (function () {
'use strict';
function noop() { }
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function detach(node) {
node.parentNode.removeChild(node);
}
function children(element) {
return Array.from(element.childNodes);
}
function custom_event(type, detail, bubbles = false) {
const e = document.createEvent('CustomEvent');
e.initCustomEvent(type, bubbles, false, detail);
return e;
}
let current_component;
function set_current_component(component) {
current_component = component;
}
const dirty_components = [];
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
let flushing = false;
const seen_callbacks = new Set();
function flush() {
if (flushing)
return;
flushing = true;
do {
// first, call beforeUpdate functions
// and update components
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
update(component.$$);
}
set_current_component(null);
dirty_components.length = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
flushing = false;
seen_callbacks.clear();
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
const outroing = new Set();
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function mount_component(component, target, anchor, customElement) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = on_mount.map(run).filter(is_function);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles && append_styles($$.root);
let ready = false;
$$.ctx = instance
? instance(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
})
: [];
$$.update();
ready = true;
run_all($$.before_update);
// `false` as a special case of no DOM component
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor, options.customElement);
flush();
}
set_current_component(parent_component);
}
/**
* Base class for Svelte components. Used when dev=false.
*/
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}
function dispatch_dev(type, detail) {
document.dispatchEvent(custom_event(type, Object.assign({ version: '3.44.1' }, detail), true));
}
function validate_slots(name, slot, keys) {
for (const slot_key of Object.keys(slot)) {
if (!~keys.indexOf(slot_key)) {
console.warn(`<${name}> received an unexpected slot "${slot_key}".`);
}
}
}
/**
* Base class for Svelte components with some minor dev-enhancements. Used when dev=true.
*/
class SvelteComponentDev extends SvelteComponent {
constructor(options) {
if (!options || (!options.target && !options.$$inline)) {
throw new Error("'target' is a required option");
}
super();
}
$destroy() {
super.$destroy();
this.$destroy = () => {
console.warn('Component was already destroyed'); // eslint-disable-line no-console
};
}
$capture_state() { }
$inject_state() { }
}
var jt=Object.defineProperty,cn=Object.defineProperties;var ln=Object.getOwnPropertyDescriptors;var Qt=Object.getOwnPropertySymbols;var dn=Object.prototype.hasOwnProperty,hn=Object.prototype.propertyIsEnumerable;var Bt=(e,t,r)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ne=(e,t)=>{for(var r in t||(t={}))dn.call(t,r)&&Bt(e,r,t[r]);if(Qt)for(var r of Qt(t))hn.call(t,r)&&Bt(e,r,t[r]);return e},se=(e,t)=>cn(e,ln(t));var i=(e,t)=>jt(e,"name",{value:t,configurable:!0});var Kt=(e,t,r)=>(Bt(e,typeof t!="symbol"?t+"":t,r),r);var er=(e,t,r)=>new Promise((a,b)=>{var P=V=>{try{D(r.next(V));}catch(A){b(A);}},v=V=>{try{D(r.throw(V));}catch(A){b(A);}},D=V=>V.done?a(V.value):Promise.resolve(V.value).then(P,v);D((r=r.apply(e,t)).next());});var tr=(()=>{for(var e=new Uint8Array(128),t=0;t<64;t++)e[t<26?t+65:t<52?t+71:t<62?t-4:t*4-205]=t;return r=>{for(var a=r.length,b=new Uint8Array((a-(r[a-1]=="=")-(r[a-2]=="="))*3/4|0),P=0,v=0;P<a;){var D=e[r.charCodeAt(P++)],V=e[r.charCodeAt(P++)],A=e[r.charCodeAt(P++)],L=e[r.charCodeAt(P++)];b[v++]=D<<2|V>>4,b[v++]=V<<4|A>>2,b[v++]=A<<6|L;}return b}})();function Ce(e){return e*Math.PI/180}i(Ce,"deg2rad");function Tt(e){return e*180/Math.PI}i(Tt,"rad2deg");function pe(e,t,r){return t>r?pe(e,r,t):Math.min(Math.max(e,t),r)}i(pe,"clamp");function Ne(e,t,r){return e+(t-e)*r}i(Ne,"lerp");function Oe(e,t,r,a,b){return a+(e-t)/(r-t)*(b-a)}i(Oe,"map");function rr(e,t,r,a,b){return pe(Oe(e,t,r,a,b),a,b)}i(rr,"mapc");function c(...e){if(e.length===0)return c(0,0);if(e.length===1){if(typeof e[0]=="number")return c(e[0],e[0]);if(We(e[0]))return c(e[0].x,e[0].y);if(Array.isArray(e[0])&&e[0].length===2)return c.apply(null,e[0])}return {x:e[0],y:e[1],clone(){return c(this.x,this.y)},add(...t){let r=c(...t);return c(this.x+r.x,this.y+r.y)},sub(...t){let r=c(...t);return c(this.x-r.x,this.y-r.y)},scale(...t){let r=c(...t);return c(this.x*r.x,this.y*r.y)},dist(...t){let r=c(...t);return Math.sqrt((this.x-r.x)*(this.x-r.x)+(this.y-r.y)*(this.y-r.y))},len(){return this.dist(c(0,0))},unit(){return this.scale(1/this.len())},normal(){return c(this.y,-this.x)},dot(t){return this.x*t.x+this.y*t.y},angle(...t){let r=c(...t);return Tt(Math.atan2(this.y-r.y,this.x-r.x))},lerp(t,r){return c(Ne(this.x,t.x,r),Ne(this.y,t.y,r))},toFixed(t){return c(this.x.toFixed(t),this.y.toFixed(t))},eq(t){return this.x===t.x&&this.y===t.y},str(){return `(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}}}i(c,"vec2");function ot(e){let t=Ce(e);return c(Math.cos(t),Math.sin(t))}i(ot,"dir");function Pe(e,t,r){return {x:e,y:t,z:r,xy(){return c(this.x,this.y)}}}i(Pe,"vec3");function We(e){return e!==void 0&&e.x!==void 0&&e.y!==void 0}i(We,"isVec2");function nr(e){return e!==void 0&&e.x!==void 0&&e.y!==void 0&&e.z!==void 0}i(nr,"isVec3");function qe(e){return e!==void 0&&e.r!==void 0&&e.g!==void 0&&e.b!==void 0}i(qe,"isColor");function sr(e){if(e!==void 0&&Array.isArray(e.m)&&e.m.length===16)return e}i(sr,"isMat4");function I(...e){if(e.length===0)return I(255,255,255);if(e.length===1){if(qe(e[0]))return I(e[0].r,e[0].g,e[0].b);if(Array.isArray(e[0])&&e[0].length===3)return I.apply(null,e[0])}return {r:pe(~~e[0],0,255),g:pe(~~e[1],0,255),b:pe(~~e[2],0,255),clone(){return I(this.r,this.g,this.b)},lighten(t){return I(this.r+t,this.g+t,this.b+t)},darken(t){return this.lighten(-t)},invert(){return I(255-this.r,255-this.g,255-this.b)},mult(t){return I(this.r*t.r/255,this.g*t.g/255,this.b*t.b/255)},eq(t){return this.r===t.r&&this.g===t.g&&this.b===t.g},str(){return `(${this.r}, ${this.g}, ${this.b})`}}}i(I,"rgb");function ir(e,t,r){if(t==0)return I(255*r,255*r,255*r);let a=i((A,L,N)=>(N<0&&(N+=1),N>1&&(N-=1),N<1/6?A+(L-A)*6*N:N<1/2?L:N<2/3?A+(L-A)*(2/3-N)*6:A),"hue2rgb"),b=r<.5?r*(1+t):r+t-r*t,P=2*r-b,v=a(P,b,e+1/3),D=a(P,b,e),V=a(P,b,e-1/3);return I(Math.round(v*255),Math.round(D*255),Math.round(V*255))}i(ir,"hsl2rgb");function de(e,t,r,a){return {x:e!=null?e:0,y:t!=null?t:0,w:r!=null?r:1,h:a!=null?a:1,scale(b){return de(this.x+this.w*b.x,this.y+this.h*b.y,this.w*b.w,this.h*b.h)},clone(){return de(this.x,this.y,this.w,this.h)},eq(b){return this.x===b.x&&this.y===b.y&&this.w===b.w&&this.h===b.h}}}i(de,"quad");function le(e){return {m:e?[...e]:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],clone(){return le(this.m)},mult(t){let r=[];for(let a=0;a<4;a++)for(let b=0;b<4;b++)r[a*4+b]=this.m[0*4+b]*t.m[a*4+0]+this.m[1*4+b]*t.m[a*4+1]+this.m[2*4+b]*t.m[a*4+2]+this.m[3*4+b]*t.m[a*4+3];return le(r)},multVec4(t){return {x:t.x*this.m[0]+t.y*this.m[4]+t.z*this.m[8]+t.w*this.m[12],y:t.x*this.m[1]+t.y*this.m[5]+t.z*this.m[9]+t.w*this.m[13],z:t.x*this.m[2]+t.y*this.m[6]+t.z*this.m[10]+t.w*this.m[14],w:t.x*this.m[3]+t.y*this.m[7]+t.z*this.m[11]+t.w*this.m[15]}},multVec3(t){let r=this.multVec4({x:t.x,y:t.y,z:t.z,w:1});return Pe(r.x,r.y,r.z)},multVec2(t){return c(t.x*this.m[0]+t.y*this.m[4]+0*this.m[8]+1*this.m[12],t.x*this.m[1]+t.y*this.m[5]+0*this.m[9]+1*this.m[13])},translate(t){return this.mult(le([1,0,0,0,0,1,0,0,0,0,1,0,t.x,t.y,0,1]))},scale(t){return this.mult(le([t.x,0,0,0,0,t.y,0,0,0,0,1,0,0,0,0,1]))},rotateX(t){return t=Ce(-t),this.mult(le([1,0,0,0,0,Math.cos(t),-Math.sin(t),0,0,Math.sin(t),Math.cos(t),0,0,0,0,1]))},rotateY(t){return t=Ce(-t),this.mult(le([Math.cos(t),0,Math.sin(t),0,0,1,0,0,-Math.sin(t),0,Math.cos(t),0,0,0,0,1]))},rotateZ(t){return t=Ce(-t),this.mult(le([Math.cos(t),-Math.sin(t),0,0,Math.sin(t),Math.cos(t),0,0,0,0,1,0,0,0,0,1]))},invert(){let t=[],r=this.m[10]*this.m[15]-this.m[14]*this.m[11],a=this.m[9]*this.m[15]-this.m[13]*this.m[11],b=this.m[9]*this.m[14]-this.m[13]*this.m[10],P=this.m[8]*this.m[15]-this.m[12]*this.m[11],v=this.m[8]*this.m[14]-this.m[12]*this.m[10],D=this.m[8]*this.m[13]-this.m[12]*this.m[9],V=this.m[6]*this.m[15]-this.m[14]*this.m[7],A=this.m[5]*this.m[15]-this.m[13]*this.m[7],L=this.m[5]*this.m[14]-this.m[13]*this.m[6],N=this.m[4]*this.m[15]-this.m[12]*this.m[7],Y=this.m[4]*this.m[14]-this.m[12]*this.m[6],ie=this.m[5]*this.m[15]-this.m[13]*this.m[7],j=this.m[4]*this.m[13]-this.m[12]*this.m[5],oe=this.m[6]*this.m[11]-this.m[10]*this.m[7],J=this.m[5]*this.m[11]-this.m[9]*this.m[7],ue=this.m[5]*this.m[10]-this.m[9]*this.m[6],y=this.m[4]*this.m[11]-this.m[8]*this.m[7],ye=this.m[4]*this.m[10]-this.m[8]*this.m[6],S=this.m[4]*this.m[9]-this.m[8]*this.m[5];t[0]=this.m[5]*r-this.m[6]*a+this.m[7]*b,t[4]=-(this.m[4]*r-this.m[6]*P+this.m[7]*v),t[8]=this.m[4]*a-this.m[5]*P+this.m[7]*D,t[12]=-(this.m[4]*b-this.m[5]*v+this.m[6]*D),t[1]=-(this.m[1]*r-this.m[2]*a+this.m[3]*b),t[5]=this.m[0]*r-this.m[2]*P+this.m[3]*v,t[9]=-(this.m[0]*a-this.m[1]*P+this.m[3]*D),t[13]=this.m[0]*b-this.m[1]*v+this.m[2]*D,t[2]=this.m[1]*V-this.m[2]*A+this.m[3]*L,t[6]=-(this.m[0]*V-this.m[2]*N+this.m[3]*Y),t[10]=this.m[0]*ie-this.m[1]*N+this.m[3]*j,t[14]=-(this.m[0]*L-this.m[1]*Y+this.m[2]*j),t[3]=-(this.m[1]*oe-this.m[2]*J+this.m[3]*ue),t[7]=this.m[0]*oe-this.m[2]*y+this.m[3]*ye,t[11]=-(this.m[0]*J-this.m[1]*y+this.m[3]*S),t[15]=this.m[0]*ue-this.m[1]*ye+this.m[2]*S;let T=this.m[0]*t[0]+this.m[1]*t[4]+this.m[2]*t[8]+this.m[3]*t[12];for(let _=0;_<4;_++)for(let z=0;z<4;z++)t[_*4+z]*=1/T;return le(t)}}}i(le,"mat4");function Pt(e,t,r,a=Math.sin){return e+(a(r)+1)/2*(t-e)}i(Pt,"wave");var fn=1103515245,mn=12345,or=2147483648,St=Dt(Date.now());function Dt(e){return {seed:e,gen(...t){if(t.length===0)return this.seed=(fn*this.seed+mn)%or,this.seed/or;if(t.length===1){if(typeof t[0]=="number")return this.gen(0,t[0]);if(We(t[0]))return this.gen(c(0,0),t[0]);if(qe(t[0]))return this.gen(I(0,0,0),t[0])}else if(t.length===2){if(typeof t[0]=="number"&&typeof t[1]=="number")return this.gen()*(t[1]-t[0])+t[0];if(We(t[0])&&We(t[1]))return c(this.gen(t[0].x,t[1].x),this.gen(t[0].y,t[1].y));if(qe(t[0])&&qe(t[1]))return I(this.gen(t[0].r,t[1].r),this.gen(t[0].g,t[1].g),this.gen(t[0].b,t[1].b))}}}}i(Dt,"rng");function ar(e){return e!=null&&(St.seed=e),St.seed}i(ar,"randSeed");function je(...e){return St.gen(...e)}i(je,"rand");function Rt(...e){return Math.floor(je(...e))}i(Rt,"randi");function ur(e){return je()<=e}i(ur,"chance");function cr(e){return e[Rt(e.length)]}i(cr,"choose");function lr(e,t){return e.p2.x>=t.p1.x&&e.p1.x<=t.p2.x&&e.p2.y>=t.p1.y&&e.p1.y<=t.p2.y}i(lr,"testRectRect2");function At(e,t){return e.p2.x>t.p1.x&&e.p1.x<t.p2.x&&e.p2.y>t.p1.y&&e.p1.y<t.p2.y}i(At,"testRectRect");function Mt(e,t){if(e.p1.x===e.p2.x&&e.p1.y===e.p2.y||t.p1.x===t.p2.x&&t.p1.y===t.p2.y)return null;let r=(t.p2.y-t.p1.y)*(e.p2.x-e.p1.x)-(t.p2.x-t.p1.x)*(e.p2.y-e.p1.y);if(r===0)return null;let a=((t.p2.x-t.p1.x)*(e.p1.y-t.p1.y)-(t.p2.y-t.p1.y)*(e.p1.x-t.p1.x))/r,b=((e.p2.x-e.p1.x)*(e.p1.y-t.p1.y)-(e.p2.y-e.p1.y)*(e.p1.x-t.p1.x))/r;return a<0||a>1||b<0||b>1?null:a}i(Mt,"testLineLineT");function Se(e,t){let r=Mt(e,t);return r?c(e.p1.x+r*(e.p2.x-e.p1.x),e.p1.y+r*(e.p2.y-e.p1.y)):null}i(Se,"testLineLine");function at(e,t){return Be(e,t.p1)||Be(e,t.p2)?!0:!!Se(t,mt(e.p1,c(e.p2.x,e.p1.y)))||!!Se(t,mt(c(e.p2.x,e.p1.y),e.p2))||!!Se(t,mt(e.p2,c(e.p1.x,e.p2.y)))||!!Se(t,mt(c(e.p1.x,e.p2.y),e.p1))}i(at,"testRectLine");function Be(e,t){return t.x>e.p1.x&&t.x<e.p2.x&&t.y>e.p1.y&&t.y<e.p2.y}i(Be,"testRectPoint");function dr(e,t){return !1}i(dr,"testRectCircle");function ut(e,t){return lt(t,[e.p1,c(e.p2.x,e.p1.y),e.p2,c(e.p1.x,e.p2.y)])}i(ut,"testRectPolygon");function hr(e,t){return !1}i(hr,"testLinePoint");function fr(e,t){return !1}i(fr,"testLineCircle");function Qe(e,t){if($e(t,e.p1)||$e(t,e.p2))return !0;for(let r=0;r<t.length;r++){let a=t[r],b=t[(r+1)%t.length];if(Se(e,{p1:a,p2:b}))return !0}return !1}i(Qe,"testLinePolygon");function ct(e,t){return e.center.dist(t)<e.radius}i(ct,"testCirclePoint");function Vt(e,t){return e.center.dist(t.center)<e.radius+t.radius}i(Vt,"testCircleCircle");function mr(e,t){return !1}i(mr,"testCirclePolygon");function lt(e,t){for(let r=0;r<e.length;r++){let a={p1:e[r],p2:e[(r+1)%e.length]};if(Qe(a,t))return !0}return !1}i(lt,"testPolygonPolygon");function $e(e,t){let r=!1;for(let a=0;a<e.length;a++){let b=e[a],P=e[(a+1)%e.length];(b.y>t.y&&P.y<t.y||b.y<t.y&&P.y>t.y)&&t.x<(P.x-b.x)*(t.y-b.y)/(P.y-b.y)+b.x&&(r=!r);}return r}i($e,"testPolygonPoint");function pn(e,t){return e.eq(t)}i(pn,"testPointPoint");function dt$1(e,t){switch(e.shape){case"rect":return At(t,e);case"line":return at(t,e);case"circle":return dr();case"polygon":return ut(t,e.pts);case"point":return Be(t,e.pt)}throw new Error(`Unknown area shape: ${e.shape}`)}i(dt$1,"testAreaRect");function kt(e,t){switch(e.shape){case"rect":return at(e,t);case"line":return Boolean(Se(e,t));case"circle":return fr();case"polygon":return Qe(t,e.pts);case"point":return hr(t,e.pt)}throw new Error(`Unknown area shape: ${e.shape}`)}i(kt,"testAreaLine");function It(e,t){switch(e.shape){case"rect":return dr();case"line":return fr();case"circle":return Vt(e,t);case"polygon":return mr(t,e.pts);case"point":return ct(t,e.pt)}throw new Error(`Unknown area shape: ${e.shape}`)}i(It,"testAreaCircle");function Lt(e,t){switch(e.shape){case"rect":return ut(e,t);case"line":return Qe(e,t);case"circle":return mr();case"polygon":return lt(t,e.pts);case"point":return $e(t,e.pt)}throw new Error(`Unknown area shape: ${e.shape}`)}i(Lt,"testAreaPolygon");function ht(e,t){switch(e.shape){case"rect":return Be(e,t);case"line":return hr();case"circle":return ct(e,t);case"polygon":return $e(e.pts,t);case"point":return pn(e.pt,t)}throw new Error(`Unknown area shape: ${e.shape}`)}i(ht,"testAreaPoint");function Ft(e,t){switch(t.shape){case"rect":return dt$1(e,t);case"line":return kt(e,t);case"circle":return It(e,t);case"polygon":return Lt(e,t.pts);case"point":return ht(e,t.pt)}throw new Error(`Unknown area shape: ${t.shape}`)}i(Ft,"testAreaArea");function ft(e,t){return {p1:c(e.p1.x-t.p2.x,e.p1.y-t.p2.y),p2:c(e.p2.x-t.p1.x,e.p2.y-t.p1.y)}}i(ft,"minkDiff");function mt(e,t){return {p1:e.clone(),p2:t.clone()}}i(mt,"makeLine");var he=class extends Map{constructor(...t){super(...t);Kt(this,"_lastID");this._lastID=0;}push(t){let r=this._lastID;return this.set(r,t),this._lastID++,r}pushd(t){let r=this.push(t);return ()=>this.delete(r)}};i(he,"IDList");function Ot(e,t){let r=typeof e,a=typeof t;if(r!==a)return !1;if(r==="object"&&a==="object"){let b=Object.keys(e),P=Object.keys(t);if(b.length!==P.length)return !1;for(let v of b){let D=e[v],V=t[v];if(!(typeof D=="function"&&typeof V=="function")&&!Ot(D,V))return !1}return !0}return e===t}i(Ot,"deepEq");function _t(e,t){let r=document.createElement("a");document.body.appendChild(r),r.setAttribute("style","display: none"),r.href=e,r.download=t,r.click(),document.body.removeChild(r);}i(_t,"downloadURL");function pr(e,t){let r=URL.createObjectURL(e);_t(r,t),URL.revokeObjectURL(r);}i(pr,"downloadBlob");var pt="topleft",Ke=9,yt=65536,yr=64,yn=`
attribute vec3 a_pos;
attribute vec2 a_uv;
attribute vec4 a_color;
varying vec3 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
vec4 def_vert() {
return vec4(a_pos, 1.0);
}
{{user}}
void main() {
vec4 pos = vert(a_pos, a_uv, a_color);
v_pos = a_pos;
v_uv = a_uv;
v_color = a_color;
gl_Position = pos;
}
`,bn=`
precision mediump float;
varying vec3 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
uniform sampler2D u_tex;
vec4 def_frag() {
return v_color * texture2D(u_tex, v_uv);
}
{{user}}
void main() {
gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
if (gl_FragColor.a == 0.0) {
discard;
}
}
`,Xt=`
vec4 vert(vec3 pos, vec2 uv, vec4 color) {
return def_vert();
}
`,Wt=`
vec4 frag(vec3 pos, vec2 uv, vec4 color, sampler2D tex) {
return def_frag();
}
`;function Ge(e){switch(e){case"topleft":return c(-1,-1);case"top":return c(0,-1);case"topright":return c(1,-1);case"left":return c(-1,0);case"center":return c(0,0);case"right":return c(1,0);case"botleft":return c(-1,1);case"bot":return c(0,1);case"botright":return c(1,1);default:return e}}i(Ge,"originPt");function br(e,t){let r=(()=>{var C;let o=P(Xt,Wt),f=b(new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),U=(C=t.background)!=null?C:I(0,0,0);e.clearColor(U.r/255,U.g/255,U.b/255,1),e.enable(e.BLEND),e.enable(e.SCISSOR_TEST),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);let R=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,R),e.bufferData(e.ARRAY_BUFFER,yt*4,e.DYNAMIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null);let x=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,x),e.bufferData(e.ELEMENT_ARRAY_BUFFER,yt*2,e.DYNAMIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null);let E=b(new ImageData(new Uint8ClampedArray([128,128,128,255,190,190,190,255,190,190,190,255,128,128,128,255]),2,2),{wrap:"repeat",filter:"nearest"});return {drawCalls:0,lastDrawCalls:0,defShader:o,curShader:o,defTex:f,curTex:f,curUniform:{},vbuf:R,ibuf:x,vqueue:[],iqueue:[],transform:le(),transformStack:[],background:U,bgTex:E,width:t.width,height:t.height}})();function a(o){return Math.log(o)/Math.log(2)%1==0}i(a,"powerOfTwo");function b(o,f={}){let U=e.createTexture();e.bindTexture(e.TEXTURE_2D,U),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o);let R=(()=>{var E;switch((E=f.filter)!=null?E:t.texFilter){case"linear":return e.LINEAR;case"nearest":return e.NEAREST;default:return e.NEAREST}})(),x=(()=>{switch(f.wrap){case"repeat":return e.REPEAT;case"clampToEdge":return e.CLAMP_TO_EDGE;default:return e.CLAMP_TO_EDGE}})();return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,R),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,R),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,x),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,x),e.bindTexture(e.TEXTURE_2D,null),{width:o.width,height:o.height,bind(){e.bindTexture(e.TEXTURE_2D,U);},unbind(){e.bindTexture(e.TEXTURE_2D,null);}}}i(b,"makeTex");function P(o=Xt,f=Wt){let U,R=yn.replace("{{user}}",o!=null?o:Xt),x=bn.replace("{{user}}",f!=null?f:Wt),E=e.createShader(e.VERTEX_SHADER),C=e.createShader(e.FRAGMENT_SHADER);if(e.shaderSource(E,R),e.shaderSource(C,x),e.compileShader(E),e.compileShader(C),U=e.getShaderInfoLog(E))throw new Error(U);if(U=e.getShaderInfoLog(C))throw new Error(U);let O=e.createProgram();if(e.attachShader(O,E),e.attachShader(O,C),e.bindAttribLocation(O,0,"a_pos"),e.bindAttribLocation(O,1,"a_uv"),e.bindAttribLocation(O,2,"a_color"),e.linkProgram(O),(U=e.getProgramInfoLog(O))&&U!==`
`)throw new Error(U);return {bind(){e.useProgram(O);},unbind(){e.useProgram(null);},bindAttribs(){e.vertexAttribPointer(0,3,e.FLOAT,!1,Ke*4,0),e.enableVertexAttribArray(0),e.vertexAttribPointer(1,2,e.FLOAT,!1,Ke*4,12),e.enableVertexAttribArray(1),e.vertexAttribPointer(2,4,e.FLOAT,!1,Ke*4,20),e.enableVertexAttribArray(2);},send(H){this.bind();for(let re in H){let Z=H[re],ee=e.getUniformLocation(O,re);typeof Z=="number"?e.uniform1f(ee,Z):sr(Z)?e.uniformMatrix4fv(ee,!1,new Float32Array(Z.m)):qe(Z)?e.uniform4f(ee,Z.r,Z.g,Z.b,Z.a):nr(Z)?e.uniform3f(ee,Z.x,Z.y,Z.z):We(Z)&&e.uniform2f(ee,Z.x,Z.y);}this.unbind();}}}i(P,"makeShader");function v(o,f,U,R){let x=o.width/f,E=o.height/U,C=1/x,O=1/E,H={},re=R.split("").entries();for(let[Z,ee]of re)H[ee]=c(Z%x*C,Math.floor(Z/x)*O);return {tex:o,map:H,qw:C,qh:O}}i(v,"makeFont");function D(o,f,U=r.defTex,R=r.defShader,x={}){U=U!=null?U:r.defTex,R=R!=null?R:r.defShader,(U!==r.curTex||R!==r.curShader||!Ot(r.curUniform,x)||r.vqueue.length+o.length*Ke>yt||r.iqueue.length+f.length>yt)&&V(),r.curTex=U,r.curShader=R,r.curUniform=x,f.forEach(E=>{r.iqueue.push(E+r.vqueue.length/Ke);}),o.forEach(E=>{let C=Y(r.transform.multVec2(E.pos.xy()));r.vqueue.push(C.x,C.y,E.pos.z,E.uv.x,E.uv.y,E.color.r/255,E.color.g/255,E.color.b/255,E.opacity);});}i(D,"drawRaw");function V(){!r.curTex||!r.curShader||r.vqueue.length===0||r.iqueue.length===0||(r.curShader.send(r.curUniform),e.bindBuffer(e.ARRAY_BUFFER,r.vbuf),e.bufferSubData(e.ARRAY_BUFFER,0,new Float32Array(r.vqueue)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r.ibuf),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,new Uint16Array(r.iqueue)),r.curShader.bind(),r.curShader.bindAttribs(),r.curTex.bind(),e.drawElements(e.TRIANGLES,r.iqueue.length,e.UNSIGNED_SHORT,0),r.curTex.unbind(),r.curShader.unbind(),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),r.iqueue=[],r.vqueue=[],r.drawCalls++);}i(V,"flush");function A(){e.clear(e.COLOR_BUFFER_BIT),t.background||T({width:Ee(),height:ce(),quad:de(0,0,Ee()*xe()/yr,ce()*xe()/yr),tex:r.bgTex}),r.drawCalls=0,r.transformStack=[],r.transform=le();}i(A,"frameStart");function L(){V(),r.lastDrawCalls=r.drawCalls;}i(L,"frameEnd");function N(){return r.lastDrawCalls}i(N,"drawCalls");function Y(o){return c(o.x/Ee()*2-1,-o.y/ce()*2+1)}i(Y,"toNDC");function ie(o){r.transform=o.clone();}i(ie,"applyMatrix");function j(...o){if(o[0]===void 0)return;let f=c(...o);f.x===0&&f.y===0||(r.transform=r.transform.translate(f));}i(j,"pushTranslate");function oe(...o){if(o[0]===void 0)return;let f=c(...o);f.x===1&&f.y===1||(r.transform=r.transform.scale(f));}i(oe,"pushScale");function J(o){!o||(r.transform=r.transform.rotateX(o));}i(J,"pushRotateX");function ue(o){!o||(r.transform=r.transform.rotateY(o));}i(ue,"pushRotateY");function y(o){!o||(r.transform=r.transform.rotateZ(o));}i(y,"pushRotateZ");function ye(){r.transformStack.push(r.transform.clone());}i(ye,"pushTransform");function S(){r.transformStack.length>0&&(r.transform=r.transformStack.pop());}i(S,"popTransform");function T(o){var H;if(o.width===void 0||o.height===void 0)throw new Error('drawUVQuad() requires property "width" and "height".');if(o.width<=0||o.height<=0)return;let f=o.width,U=o.height,x=Ge(o.origin||pt).scale(c(f,U).scale(-.5)),E=o.quad||de(0,0,1,1),C=o.color||I(255,255,255),O=(H=o.opacity)!=null?H:1;ye(),j(o.pos),y(o.angle),oe(o.scale),j(x),D([{pos:Pe(-f/2,U/2,0),uv:c(o.flipX?E.x+E.w:E.x,o.flipY?E.y:E.y+E.h),color:C,opacity:O},{pos:Pe(-f/2,-U/2,0),uv:c(o.flipX?E.x+E.w:E.x,o.flipY?E.y+E.h:E.y),color:C,opacity:O},{pos:Pe(f/2,-U/2,0),uv:c(o.flipX?E.x:E.x+E.w,o.flipY?E.y+E.h:E.y),color:C,opacity:O},{pos:Pe(f/2,U/2,0),uv:c(o.flipX?E.x:E.x+E.w,o.flipY?E.y:E.y+E.h),color:C,opacity:O}],[0,1,3,1,2,3],o.tex,o.shader,o.uniform),S();}i(T,"drawUVQuad");function _(o){var E;if(!o.tex)throw new Error('drawTexture() requires property "tex".');let f=(E=o.quad)!=null?E:de(0,0,1,1),U=o.tex.width*f.w,R=o.tex.height*f.h,x=c(1);if(o.tiled){let C=Math.ceil((o.width||U)/U),O=Math.ceil((o.height||R)/R),re=Ge(o.origin||pt).add(c(1,1)).scale(.5).scale(C*U,O*R);for(let Z=0;Z<C;Z++)for(let ee=0;ee<O;ee++)T(se(ne({},o),{pos:(o.pos||c(0)).add(c(U*Z,R*ee)).sub(re),scale:x.scale(o.scale||c(1)),tex:o.tex,quad:f,width:U,height:R,origin:"topleft"}));}else o.width&&o.height?(x.x=o.width/U,x.y=o.height/R):o.width?(x.x=o.width/U,x.y=x.x):o.height&&(x.y=o.height/R,x.x=x.y),T(se(ne({},o),{scale:x.scale(o.scale||c(1)),tex:o.tex,quad:f,width:U,height:R}));}i(_,"drawTexture");function z(o,f,U,R,x,E=1){R=Ce(R%360),x=Ce(x%360),x<=R&&(x+=Math.PI*2);let C=Math.ceil(Math.max(Math.sqrt(f+U)*3*(E||1),16)),O=(x-R)/C,H=[];for(let re=R;re<x;re+=O)H.push(o.add(f*Math.cos(re),U*Math.sin(re)));return H.push(o.add(f*Math.cos(x),U*Math.sin(x))),H}i(z,"getArcPts");function X(o){if(o.width===void 0||o.height===void 0)throw new Error('drawRect() requires property "width" and "height".');if(o.width<=0||o.height<=0)return;let f=o.width,U=o.height,x=Ge(o.origin||pt).add(1,1).scale(c(f,U).scale(-.5)),E=[c(0,0),c(f,0),c(f,U),c(0,U)];if(o.radius){let C=Math.min(Math.min(f,U)/2,o.radius);E=[c(C,0),c(f-C,0),...z(c(f-C,C),C,C,270,360),c(f,C),c(f,U-C),...z(c(f-C,U-C),C,C,0,90),c(f-C,U),c(C,U),...z(c(C,U-C),C,C,90,180),c(0,U-C),c(0,C),...z(c(C,C),C,C,180,270)];}ae(se(ne({},o),{offset:x,pts:E}));}i(X,"drawRect");function W(o){let{p1:f,p2:U}=o;if(!f||!U)throw new Error('drawLine() requires properties "p1" and "p2".');let R=o.width||1,x=U.sub(f).unit().normal().scale(R*.5),E=[f.sub(x),f.add(x),U.add(x),U.sub(x)].map(C=>{var O,H;return {pos:Pe(C.x,C.y,0),uv:c(0),color:(O=o.color)!=null?O:I(),opacity:(H=o.opacity)!=null?H:1}});D(E,[0,1,3,1,2,3],r.defTex,o.shader,o.uniform);}i(W,"drawLine");function k(o){let f=o.pts;if(!f)throw new Error('drawLines() requires property "pts".');if(!(f.length<2))if(o.radius&&f.length>=3){let U=f[0].dist(f[1]);for(let x=1;x<f.length-1;x++)U=Math.min(f[x].dist(f[x+1]),U);Math.min(o.radius,U/2);W(se(ne({},o),{p1:f[0],p2:f[1]}));for(let x=1;x<f.length-2;x++){let E=f[x],C=f[x+1];W(se(ne({},o),{p1:E,p2:C}));}W(se(ne({},o),{p1:f[f.length-2],p2:f[f.length-1]}));}else for(let U=0;U<f.length-1;U++)W(se(ne({},o),{p1:f[U],p2:f[U+1]}));}i(k,"drawLines");function q(o){if(!o.p1||!o.p2||!o.p3)throw new Error('drawPolygon() requires properties "p1", "p2" and "p3".');return ae(se(ne({},o),{pts:[o.p1,o.p2,o.p3]}))}i(q,"drawTriangle");function $(o){if(!o.radius)throw new Error('drawCircle() requires property "radius".');o.radius!==0&&F(se(ne({},o),{radiusX:o.radius,radiusY:o.radius,angle:0}));}i($,"drawCircle");function F(o){var f,U;if(o.radiusX===void 0||o.radiusY===void 0)throw new Error('drawEllipse() requires properties "radiusX" and "radiusY".');o.radiusX===0||o.radiusY===0||ae(se(ne({},o),{pts:z(c(0),o.radiusX,o.radiusY,(f=o.start)!=null?f:0,(U=o.end)!=null?U:360,o.resolution),radius:0}));}i(F,"drawEllipse");function ae(o){var U,R;if(!o.pts)throw new Error('drawPolygon() requires property "pts".');let f=o.pts.length;if(!(f<3)){if(ye(),j(o.pos),oe(o.scale),y(o.angle),j(o.offset),o.fill!==!1){let x=(U=o.color)!=null?U:I(),E=o.pts.map(O=>{var H;return {pos:Pe(O.x,O.y,0),uv:c(0,0),color:x,opacity:(H=o.opacity)!=null?H:1}}),C=[...Array(f-2).keys()].map(O=>[0,O+1,O+2]).flat();D(E,(R=o.indices)!=null?R:C,r.defTex,o.shader,o.uniform);}o.outline&&k({pts:[...o.pts,o.pts[0]],radius:o.radius,width:o.outline.width,color:o.outline.color}),S();}}i(ae,"drawPolygon");function w(o){if(o.text===void 0)throw new Error('fmtText() requires property "text".');let f=o.font,U=(o.text+"").split(""),R=f.qw*f.tex.width,x=f.qh*f.tex.height,E=o.size||x,C=c(E/x).scale(c(o.scale||1)),O=C.x*R,H=C.y*x,re=0,Z=H,ee=0,Ae=[],fe=[],be=null,me=0;for(;me<U.length;){let ge=U[me];ge===`
`?(Z+=H,re=0,be=null,Ae.push(fe),fe=[]):(o.width?re+O>o.width:!1)&&(Z+=H,re=0,be!=null&&(me-=fe.length-be,ge=U[me],fe=fe.slice(0,be)),be=null,Ae.push(fe),fe=[]),ge!==`
`&&(fe.push(ge),re+=O,ge===" "&&(be=fe.length)),ee=Math.max(ee,re),me++;}Ae.push(fe),o.width&&(ee=o.width);let Ye=[],Me=c(o.pos||0),Ve=Ge(o.origin||pt).scale(.5),et=-Ve.x*O-(Ve.x+.5)*(ee-O),Ut=-Ve.y*H-(Ve.y+.5)*(Z-H),ze=0;return Ae.forEach((ge,tt)=>{let gt=(ee-ge.length*O)*(Ve.x+.5);ge.forEach((Ze,Te)=>{var rt,nt;let Je=f.map[Ze],wt=Te*O,xt=tt*H;if(ze+=1,Je){let we={tex:f.tex,quad:de(Je.x,Je.y,f.qw,f.qh),ch:Ze,pos:c(Me.x+wt+et+gt,Me.y+xt+Ut),opacity:o.opacity,color:(rt=o.color)!=null?rt:I(255,255,255),origin:o.origin,scale:C,angle:0};if(o.transform){let Ue=(nt=o.transform(ze,Ze))!=null?nt:{};Ue.pos&&(we.pos=we.pos.add(Ue.pos)),Ue.scale&&(we.scale=we.scale.scale(c(Ue.scale))),Ue.angle&&(we.angle+=Ue.angle),Ue.color&&(we.color=we.color.mult(Ue.color)),Ue.opacity&&(we.opacity*=Ue.opacity);}Ye.push(we);}});}),{width:ee,height:Z,chars:Ye}}i(w,"fmtText");function G(o){De(w(o));}i(G,"drawText");function De(o){for(let f of o.chars)T({tex:f.tex,width:f.tex.width*f.quad.w,height:f.tex.height*f.quad.h,pos:f.pos,scale:f.scale,angle:f.angle,color:f.color,opacity:f.opacity,quad:f.quad,origin:"center"});}i(De,"drawFmtText");function Re(){if(t.width&&t.height&&t.stretch)if(t.letterbox){let o=e.drawingBufferWidth/e.drawingBufferHeight,f=t.width/t.height;if(o>f){r.width=t.height*o,r.height=t.height;let U=e.drawingBufferHeight*f,R=e.drawingBufferHeight,x=(e.drawingBufferWidth-U)/2;e.scissor(x,0,U,R),e.viewport(x,0,e.drawingBufferWidth,e.drawingBufferHeight);}else {r.width=t.width,r.height=t.width/o;let U=e.drawingBufferWidth,R=e.drawingBufferWidth/f,x=(e.drawingBufferHeight-R)/2;e.scissor(0,e.drawingBufferHeight-R-x,U,R),e.viewport(0,-x,e.drawingBufferWidth,e.drawingBufferHeight);}}else r.width=t.width,r.height=t.height,e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight);else r.width=e.drawingBufferWidth/xe(),r.height=e.drawingBufferHeight/xe(),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight);}i(Re,"updateSize");function Ee(){return r.width}i(Ee,"width");function ce(){return r.height}i(ce,"height");function xe(){var o;return (o=t.scale)!=null?o:1}i(xe,"scale");function bt(){return r.background.clone()}return i(bt,"background"),Re(),A(),L(),{width:Ee,height:ce,scale:xe,makeTex:b,makeShader:P,makeFont:v,drawTexture:_,drawText:G,drawFmtText:De,drawRect:X,drawLine:W,drawLines:k,drawTriangle:q,drawCircle:$,drawEllipse:F,drawPolygon:ae,drawUVQuad:T,fmtText:w,frameStart:A,frameEnd:L,pushTranslate:j,pushScale:oe,pushRotateX:J,pushRotateY:ue,pushRotateZ:y,pushTransform:ye,popTransform:S,applyMatrix:ie,drawCalls:N,background:bt}}i(br,"gfxInit");function Ur(e){return e==="pressed"||e==="rpressed"?"down":e==="released"?"up":e}i(Ur,"processBtnState");function Un(e){e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen();}i(Un,"enterFullscreen");function gn(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen();}i(gn,"exitFullscreen");function wn(){return document.fullscreenElement||document.webkitFullscreenElement}i(wn,"getFullscreenElement");function gr(e={}){var $,F,ae;let t=($=e.root)!=null?$:document.body;t===document.body&&(document.body.style.width="100%",document.body.style.height="100%",document.body.style.margin="0px",document.documentElement.style.width="100%",document.documentElement.style.height="100%");let r={canvas:(F=e.canvas)!=null?F:(()=>{let w=document.createElement("canvas");return t.appendChild(w),w})(),keyStates:{},charInputted:[],isMouseMoved:!1,isKeyPressed:!1,isKeyPressedRepeat:!1,mouseStates:{},mousePos:c(0,0),mouseDeltaPos:c(0,0),time:0,realTime:0,skipTime:!1,dt:0,scale:(ae=e.scale)!=null?ae:1,isTouch:!1,loopID:null,stopped:!1,fps:0,fpsBuf:[],fpsTimer:0},a={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"},b=["space","left","right","up","down","tab","f1","f2","f3","f4","f5","f6","f7","f8","f9","f10","f11","s"];e.width&&e.height&&!e.stretch?(r.canvas.width=e.width*r.scale,r.canvas.height=e.height*r.scale):(r.canvas.width=r.canvas.parentElement.offsetWidth,r.canvas.height=r.canvas.parentElement.offsetHeight);let P=["outline: none","cursor: default"];e.crisp&&(P.push("image-rendering: pixelated"),P.push("image-rendering: crisp-edges")),r.canvas.style=P.join(";"),r.canvas.setAttribute("tabindex","0");let v=r.canvas.getContext("webgl",{antialias:!0,depth:!0,stencil:!0,alpha:!0,preserveDrawingBuffer:!0});r.isTouch="ontouchstart"in window||navigator.maxTouchPoints>0,r.canvas.addEventListener("mousemove",w=>{W()?r.mousePos=c(w.offsetX,w.offsetY).scale(1/r.scale):r.mousePos=c(w.offsetX,w.offsetY).scale(1/r.scale),r.mouseDeltaPos=c(w.movementX,w.movementY).scale(1/r.scale),r.isMouseMoved=!0;});let D=["left","middle","right","back","forward"];r.canvas.addEventListener("mousedown",w=>{let G=D[w.button];G&&(r.mouseStates[G]="pressed");}),r.canvas.addEventListener("mouseup",w=>{let G=D[w.button];G&&(r.mouseStates[G]="released");}),r.canvas.addEventListener("keydown",w=>{let G=a[w.key]||w.key.toLowerCase();b.includes(G)&&w.preventDefault(),G.length===1&&r.charInputted.push(w.key),G==="space"&&r.charInputted.push(" "),w.repeat?(r.isKeyPressedRepeat=!0,r.keyStates[G]="rpressed"):(r.isKeyPressed=!0,r.keyStates[G]="pressed");}),r.canvas.addEventListener("keyup",w=>{let G=a[w.key]||w.key.toLowerCase();r.keyStates[G]="released";}),r.canvas.addEventListener("touchstart",w=>{if(!e.touchToMouse)return;w.preventDefault();let G=w.touches[0];r.mousePos=c(G.clientX,G.clientY).scale(1/r.scale),r.mouseStates.left="pressed";}),r.canvas.addEventListener("touchmove",w=>{if(!e.touchToMouse)return;w.preventDefault();let G=w.touches[0];r.mousePos=c(G.clientX,G.clientY).scale(1/r.scale),r.isMouseMoved=!0;}),r.canvas.addEventListener("touchend",w=>{!e.touchToMouse||(r.mouseStates.left="released");}),r.canvas.addEventListener("touchcancel",w=>{!e.touchToMouse||(r.mouseStates.left="released");}),r.canvas.addEventListener("contextmenu",function(w){w.preventDefault();}),document.addEventListener("visibilitychange",()=>{var w,G;switch(document.visibilityState){case"visible":r.skipTime=!0,(w=e.audioCtx)==null||w.resume();break;case"hidden":(G=e.audioCtx)==null||G.suspend();break}});function V(){return r.mousePos.clone()}i(V,"mousePos");function A(){return r.mouseDeltaPos.clone()}i(A,"mouseDeltaPos");function L(w="left"){return r.mouseStates[w]==="pressed"}i(L,"isMousePressed");function N(w="left"){return r.mouseStates[w]==="pressed"||r.mouseStates[w]==="down"}i(N,"isMouseDown");function Y(w="left"){return r.mouseStates[w]==="released"}i(Y,"isMouseReleased");function ie(){return r.isMouseMoved}i(ie,"isMouseMoved");function j(w){return w===void 0?r.isKeyPressed:r.keyStates[w]==="pressed"}i(j,"isKeyPressed");function oe(w){return w===void 0?r.isKeyPressedRepeat:r.keyStates[w]==="pressed"||r.keyStates[w]==="rpressed"}i(oe,"isKeyPressedRepeat");function J(w){return r.keyStates[w]==="pressed"||r.keyStates[w]==="rpressed"||r.keyStates[w]==="down"}i(J,"isKeyDown");function ue(w){return r.keyStates[w]==="released"}i(ue,"isKeyReleased");function y(){return [...r.charInputted]}i(y,"charInputted");function ye(){return r.dt}i(ye,"dt");function S(){return r.time}i(S,"time");function T(){return r.fps}i(T,"fps");function _(){return r.canvas.toDataURL()}i(_,"screenshot");function z(w){return w&&(r.canvas.style.cursor=w),r.canvas.style.cursor}i(z,"cursor");function X(w=!0){w?Un(r.canvas):gn();}i(X,"fullscreen");function W(){return Boolean(wn())}i(W,"isFullscreen");function k(w){let G=i(De=>{if(document.visibilityState!=="visible"){r.loopID=requestAnimationFrame(G);return}let Re=De/1e3,Ee=Re-r.realTime;r.realTime=Re,r.skipTime||(r.dt=Ee,r.time+=r.dt,r.fpsBuf.push(1/r.dt),r.fpsTimer+=r.dt,r.fpsTimer>=1&&(r.fpsTimer=0,r.fps=Math.round(r.fpsBuf.reduce((ce,xe)=>ce+xe)/r.fpsBuf.length),r.fpsBuf=[])),r.skipTime=!1,w();for(let ce in r.keyStates)r.keyStates[ce]=Ur(r.keyStates[ce]);for(let ce in r.mouseStates)r.mouseStates[ce]=Ur(r.mouseStates[ce]);r.charInputted=[],r.isMouseMoved=!1,r.isKeyPressed=!1,r.isKeyPressedRepeat=!1,r.loopID=requestAnimationFrame(G);},"frame");r.stopped=!1,r.loopID=requestAnimationFrame(G);}i(k,"run");function q(){cancelAnimationFrame(r.loopID),r.stopped=!0;}return i(q,"quit"),{gl:v,mousePos:V,mouseDeltaPos:A,isKeyDown:J,isKeyPressed:j,isKeyPressedRepeat:oe,isKeyReleased:ue,isMouseDown:N,isMousePressed:L,isMouseReleased:Y,isMouseMoved:ie,charInputted:y,cursor:z,dt:ye,time:S,fps:T,screenshot:_,run:k,quit:q,isFocused:()=>document.activeElement===r.canvas,focus:()=>r.canvas.focus(),canvas:r.canvas,isTouch:r.isTouch,scale:r.scale,fullscreen:X,isFullscreen:W}}i(gr,"appInit");var wr=tr("SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4Ljc2LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAASAAAeMwAUFBQUFCIiIiIiIjAwMDAwPj4+Pj4+TExMTExZWVlZWVlnZ2dnZ3V1dXV1dYODg4ODkZGRkZGRn5+fn5+frKysrKy6urq6urrIyMjIyNbW1tbW1uTk5OTk8vLy8vLy//////8AAAAATGF2YzU4LjEzAAAAAAAAAAAAAAAAJAQKAAAAAAAAHjOZTf9/AAAAAAAAAAAAAAAAAAAAAP/7kGQAAANUMEoFPeACNQV40KEYABEY41g5vAAA9RjpZxRwAImU+W8eshaFpAQgALAAYALATx/nYDYCMJ0HITQYYA7AH4c7MoGsnCMU5pnW+OQnBcDrQ9Xx7w37/D+PimYavV8elKUpT5fqx5VjV6vZ38eJR48eRKa9KUp7v396UgPHkQwMAAAAAA//8MAOp39CECAAhlIEEIIECBAgTT1oj///tEQYT0wgEIYxgDC09aIiE7u7u7uIiIz+LtoIQGE/+XAGYLjpTAIOGYYy0ZACgDgSNFxC7YYiINocwERj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