diff --git a/assets/index-56oO-tjT.js b/assets/index-BjrKYEaS.js similarity index 99% rename from assets/index-56oO-tjT.js rename to assets/index-BjrKYEaS.js index f111d35..09dcb2e 100644 --- a/assets/index-56oO-tjT.js +++ b/assets/index-BjrKYEaS.js @@ -115,7 +115,7 @@ ${t.join(` `),e),e.log.trace('handle: responded with "%s" for "%s"',s,s),{stream:r.unwrap(),protocol:s};if(s==="ls"){const i=new at(...t.map(o=>aa.single(j(`${o} `))),j(` `));e.log.trace('handle: respond with "%s" for %s',t,s),await oi(r,i,e),e.log.trace('handle: responded with "%s" for %s',t,s);continue}e.log('handle: respond with "na" for "%s"',s),await oi(r,j(`na -`),e),e.log('handle: responded with "na" for "%s"',s)}}const yT=500;var Sd,Ad;Ad=Symbol.toStringTag,Sd=Mb;class bT{constructor(t){y(this,"id");y(this,"remoteAddr");y(this,"remotePeer");y(this,"direction");y(this,"timeline");y(this,"multiplexer");y(this,"encryption");y(this,"status");y(this,"transient");y(this,"log");y(this,"tags");y(this,"_newStream");y(this,"_close");y(this,"_abort");y(this,"_getStreams");y(this,Ad,"Connection");y(this,Sd,!0);const{remoteAddr:e,remotePeer:r,newStream:s,close:i,abort:o,getStreams:l}=t;this.id=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`,this.remoteAddr=e,this.remotePeer=r,this.direction=t.direction,this.status="open",this.timeline=t.timeline,this.multiplexer=t.multiplexer,this.encryption=t.encryption,this.transient=t.transient??!1,this.log=t.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`),this.remoteAddr.getPeerId()==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),this._newStream=s,this._close=i,this._abort=o,this._getStreams=l,this.tags=[]}get streams(){return this._getStreams()}async newStream(t,e){if(this.status==="closing")throw new C("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new C("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(t)||(t=[t]),this.transient&&e?.runOnTransientConnection!==!0)throw new C("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");const r=await this._newStream(t,e);return r.direction="outbound",r}async close(t={}){if(!(this.status==="closed"||this.status==="closing")){if(this.log("closing connection to %a",this.remoteAddr),this.status="closing",t.signal==null){const e=AbortSignal.timeout(yT);Qe(1/0,e),t={...t,signal:e}}try{this.log.trace("closing all streams"),await Promise.all(this.streams.map(async e=>e.close(t))),this.log.trace("closing underlying transport"),await this._close(t),this.log.trace("updating timeline with close time"),this.status="closed",this.timeline.close=Date.now()}catch(e){this.log.error("error encountered during graceful close of connection to %a",this.remoteAddr,e),this.abort(e)}}}abort(t){this.log.error("aborting connection to %a due to error",this.remoteAddr,t),this.status="closing",this.streams.forEach(e=>{e.abort(t)}),this.log.error("all streams aborted",this.streams.length),this._abort(t),this.timeline.close=Date.now(),this.status="closed"}}function _T(n){return new bT(n)}const wT=3e4;function vT(n,t){try{const{options:e}=t.getHandler(n);return e.maxInboundStreams}catch(e){if(e.code!==Z.ERR_NO_HANDLER_FOR_PROTOCOL)throw e}return $y}function ET(n,t,e={}){try{const{options:r}=t.getHandler(n);if(r.maxOutboundStreams!=null)return r.maxOutboundStreams}catch(r){if(r.code!==Z.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return e.maxOutboundStreams??Hy}function Ef(n,t,e){let r=0;return e.streams.forEach(s=>{s.direction===t&&s.protocol===n&&r++}),r}var Id;Id=Symbol.toStringTag;class ST{constructor(t,e){y(this,"components");y(this,"connectionEncryption");y(this,"muxers");y(this,"inboundUpgradeTimeout");y(this,"events");y(this,Id,"@libp2p/upgrader");this.components=t,this.connectionEncryption=new Map,e.connectionEncryption.forEach(r=>{this.connectionEncryption.set(r.protocol,r)}),this.muxers=new Map,e.muxers.forEach(r=>{this.muxers.set(r.protocol,r)}),this.inboundUpgradeTimeout=e.inboundUpgradeTimeout??YR,this.events=t.events}async shouldBlockConnection(t,e,r){const s=this.components.connectionGater[r];if(s!==void 0&&await s(t,e))throw new C(`The multiaddr connection is blocked by gater.${r}`,Z.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(t,e){if(!await this.components.connectionManager.acceptIncomingConnection(t))throw new C("connection denied",Z.ERR_CONNECTION_DENIED);let s,i,o,l,c;const u=AbortSignal.timeout(this.inboundUpgradeTimeout),f=()=>{t.abort(new C("inbound upgrade timeout",fp))};u.addEventListener("abort",f,{once:!0}),Qe(1/0,u);try{if(await this.components.connectionGater.denyInboundConnection?.(t)===!0)throw new C("The multiaddr connection is blocked by gater.acceptConnection",Z.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(t),t.log("starting the inbound connection upgrade");let a=t;if(e?.skipProtection!==!0){const h=this.components.connectionProtector;h!=null&&(t.log("protecting the inbound connection"),a=await h.protect(t))}try{if(s=a,e?.skipEncryption!==!0){e?.onProgress?.(new rt("upgrader:encrypt-inbound-connection")),{conn:s,remotePeer:i,protocol:c}=await this._encryptInbound(a);const h={...a,...s};await this.shouldBlockConnection(i,h,"denyInboundEncryptedConnection")}else{const h=t.remoteAddr.getPeerId();if(h==null)throw new C("inbound connection that skipped encryption must have a peer id",Z.ERR_INVALID_MULTIADDR);const d=Ue(h);c="native",i=d}if(o=s,e?.muxerFactory!=null)l=e.muxerFactory;else if(this.muxers.size>0){e?.onProgress?.(new rt("upgrader:multiplex-inbound-connection"));const h=await this._multiplexInbound({...a,...s},this.muxers);l=h.muxerFactory,o=h.stream}}catch(h){throw t.log.error("failed to upgrade inbound connection",h),h}return await this.shouldBlockConnection(i,t,"denyInboundUpgradedConnection"),t.log("successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:t,upgradedConn:o,muxerFactory:l,remotePeer:i,transient:e?.transient})}finally{u.removeEventListener("abort",f),this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(t,e){const r=t.remoteAddr.getPeerId();let s;r!=null&&(s=Ue(r),await this.shouldBlockConnection(s,t,"denyOutboundConnection"));let i,o,l,c,u;this.components.metrics?.trackMultiaddrConnection(t),t.log("starting the outbound connection upgrade");let f=t;if(e?.skipProtection!==!0){const a=this.components.connectionProtector;a!=null&&(f=await a.protect(t))}try{if(i=f,e?.skipEncryption!==!0){({conn:i,remotePeer:o,protocol:c}=await this._encryptOutbound(f,s));const a={...f,...i};await this.shouldBlockConnection(o,a,"denyOutboundEncryptedConnection")}else{if(s==null)throw new C("Encryption was skipped but no peer id was passed",Z.ERR_INVALID_PEER);c="native",o=s}if(l=i,e?.muxerFactory!=null)u=e.muxerFactory;else if(this.muxers.size>0){const a=await this._multiplexOutbound({...f,...i},this.muxers);u=a.muxerFactory,l=a.stream}}catch(a){throw t.log.error("failed to upgrade outbound connection",a),await t.close(a),a}return await this.shouldBlockConnection(o,t,"denyOutboundUpgradedConnection"),t.log("successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:t,upgradedConn:l,muxerFactory:u,remotePeer:o,transient:e?.transient})}_createConnection(t){const{cryptoProtocol:e,direction:r,maConn:s,upgradedConn:i,remotePeer:o,muxerFactory:l,transient:c}=t;let u,f,a;l!=null&&(u=l.createStreamMuxer({direction:r,onIncomingStream:m=>{a!=null&&Promise.resolve().then(async()=>{const p=this.components.registrar.getProtocols(),{stream:g,protocol:b}=await Ja(m,p,{log:m.log,yieldBytes:!1});if(a==null)return;a.log("incoming stream opened on %s",b);const w=vT(b,this.components.registrar);if(Ef(b,"inbound",a)===w){const A=new C(`Too many inbound protocol streams for protocol "${b}" - limit ${w}`,Z.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw m.abort(A),A}m.source=g.source,m.sink=g.sink,m.protocol=b,g.closeWrite!=null&&(m.closeWrite=g.closeWrite),g.closeRead!=null&&(m.closeRead=g.closeRead),g.close!=null&&(m.close=g.close),await this.components.peerStore.merge(o,{protocols:[b]}),this.components.metrics?.trackProtocolStream(m,a),this._onStream({connection:a,stream:m,protocol:b})}).catch(async p=>{a.log.error("error handling incoming stream id %s",m.id,p.message,p.code,p.stack),m.timeline.close==null&&await m.close()})}}),f=async(m,p={})=>{if(u==null)throw new C("Stream is not multiplexed",Z.ERR_MUXER_UNAVAILABLE);a.log("starting new stream for protocols %s",m);const g=await u.newStream();a.log.trace("started new stream %s for protocols %s",g.id,m);try{if(p.signal==null){g.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",m);const S=AbortSignal.timeout(wT);Qe(1/0,S),p={...p,signal:S}}g.log.trace("selecting protocol from protocols %s",m);const{stream:b,protocol:w}=await ja(g,m,{...p,log:g.log,yieldBytes:!0});g.log("selected protocol %s",w);const _=ET(w,this.components.registrar,p),A=Ef(w,"outbound",a);if(A>=_){const S=new C(`Too many outbound protocol streams for protocol "${w}" - ${A}/${_}`,Z.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw g.abort(S),S}return await this.components.peerStore.merge(o,{protocols:[w]}),g.source=b.source,g.sink=b.sink,g.protocol=w,b.closeWrite!=null&&(g.closeWrite=b.closeWrite),b.closeRead!=null&&(g.closeRead=b.closeRead),b.close!=null&&(g.close=b.close),this.components.metrics?.trackProtocolStream(g,a),g}catch(b){throw a.log.error("could not create new stream for protocols %s",m,b),g.timeline.close==null&&g.abort(b),b.code!=null?b:new C(String(b),Z.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(i.source),i.sink(u.source)]).catch(m=>{a.log.error("error piping data through muxer",m)}));const h=s.timeline;s.timeline=new Proxy(h,{set:(...m)=>(a!=null&&m[1]==="close"&&m[2]!=null&&h.close==null&&(async()=>{try{a.status==="open"&&await a.close()}catch(p){a.log.error("error closing connection after timeline close",p)}finally{this.events.safeDispatchEvent("connection:close",{detail:a})}})().catch(p=>{a.log.error("error thrown while dispatching connection:close event",p)}),Reflect.set(...m))}),s.timeline.upgraded=Date.now();const d=()=>{throw new C("connection is not multiplexed",Z.ERR_CONNECTION_NOT_MULTIPLEXED)};return a=_T({remoteAddr:s.remoteAddr,remotePeer:o,status:"open",direction:r,timeline:s.timeline,multiplexer:u?.protocol,encryption:e,transient:c,logger:this.components.logger,newStream:f??d,getStreams:()=>u!=null?u.streams:[],close:async m=>{u!=null&&(a.log.trace("close muxer"),await u.close(m)),a.log.trace("close maconn"),await s.close(m),a.log.trace("closed maconn")},abort:m=>{s.abort(m),u?.abort(m)}}),this.events.safeDispatchEvent("connection:open",{detail:a}),a}_onStream(t){const{connection:e,stream:r,protocol:s}=t,{handler:i,options:o}=this.components.registrar.getHandler(s);if(e.transient&&o.runOnTransientConnection!==!0)throw new C("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");i({connection:e,stream:r})}async _encryptInbound(t){const e=Array.from(this.connectionEncryption.keys());t.log("handling inbound crypto protocol selection",e);try{const{stream:r,protocol:s}=await Ja(t,e,{log:t.log}),i=this.connectionEncryption.get(s);if(i==null)throw new Error(`no crypto module found for ${s}`);return t.log("encrypting inbound connection using",s),{...await i.secureInbound(this.components.peerId,r),protocol:s}}catch(r){throw t.log.error("encrypting inbound connection failed",r),new C(r.message,Z.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(t,e){const r=Array.from(this.connectionEncryption.keys());t.log("selecting outbound crypto protocol",r);try{t.log.trace("selecting encrypter from %s",r);const{stream:s,protocol:i}=await ja(t,r,{log:t.log,yieldBytes:!0}),o=this.connectionEncryption.get(i);if(o==null)throw new Error(`no crypto module found for ${i}`);return t.log("encrypting outbound connection to %p using %s",e,o),{...await o.secureOutbound(this.components.peerId,s,e),protocol:i}}catch(s){throw t.log.error("encrypting outbound connection to %p failed",e,s),new C(s.message,Z.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(t,e){const r=Array.from(e.keys());t.log("outbound selecting muxer %s",r);try{t.log.trace("selecting stream muxer from %s",r);const{stream:s,protocol:i}=await ja(t,r,{log:t.log,yieldBytes:!0});t.log("selected %s as muxer protocol",i);const o=e.get(i);return{stream:s,muxerFactory:o}}catch(s){throw t.log.error("error multiplexing outbound connection",s),new C(String(s),Z.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(t,e){const r=Array.from(e.keys());t.log("inbound handling muxers %s",r);try{const{stream:s,protocol:i}=await Ja(t,r,{log:t.log}),o=e.get(i);return{stream:s,muxerFactory:o}}catch(s){throw t.log.error("error multiplexing inbound connection",s),new C(String(s),Z.ERR_MUXER_UNAVAILABLE)}}}const AT="1.8.1",IT="libp2p";var Di,Yl;class RT extends Nn{constructor(e){super();Ce(this,Di);y(this,"peerId");y(this,"peerStore");y(this,"contentRouting");y(this,"peerRouting");y(this,"metrics");y(this,"services");y(this,"logger");y(this,"status");y(this,"components");y(this,"log");this.status="stopped";const r=new Nn,s=r.dispatchEvent.bind(r);r.dispatchEvent=c=>{const u=s(c),f=this.dispatchEvent(new xr(c.type,{detail:c.detail}));return u||f},Qe(1/0,r),this.peerId=e.peerId,this.logger=e.logger??ay(),this.log=this.logger.forComponent("libp2p"),this.services={};const i=this.components=gR({peerId:e.peerId,privateKey:e.privateKey,nodeInfo:e.nodeInfo??{name:IT,version:AT},logger:this.logger,events:r,datastore:e.datastore??new lR,connectionGater:AR(e.connectionGater),dns:e.dns});this.peerStore=this.configureComponent("peerStore",new tR(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),i.events.addEventListener("peer:update",c=>{if(c.detail.previous==null){const u={id:c.detail.peer.id,multiaddrs:c.detail.peer.addresses.map(f=>f.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:u})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new ST(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((c,u)=>this.configureComponent(`connection-encryption-${u}`,c(this.components))),muxers:(e.streamMuxers??[]).map((c,u)=>this.configureComponent(`stream-muxers-${u}`,c(this.components))),inboundUpgradeTimeout:e.connectionManager?.inboundUpgradeTimeout}),this.configureComponent("transportManager",new fT(this.components,e.transportManager)),this.configureComponent("connectionManager",new iT(this.components,e.connectionManager)),this.configureComponent("registrar",new cT(this.components)),this.configureComponent("addressManager",new hR(this.components,e.addresses));const o=(e.peerRouters??[]).map((c,u)=>this.configureComponent(`peer-router-${u}`,c(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new aT(this.components,{routers:o}));const l=(e.contentRouters??[]).map((c,u)=>this.configureComponent(`content-router-${u}`,c(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new oT(this.components,{routers:l})),this.configureComponent("randomWalk",new lT(this.components)),(e.peerDiscovery??[]).forEach((c,u)=>{this.configureComponent(`peer-discovery-${u}`,c(this.components)).addEventListener("peer",a=>{ye(this,Di,Yl).call(this,a)})}),e.transports?.forEach((c,u)=>{this.components.transportManager.add(this.configureComponent(`transport-${u}`,c(this.components)))}),e.services!=null)for(const c of Object.keys(e.services)){const u=e.services[c],f=u(this.components);if(f==null){this.log.error("service factory %s returned null or undefined instance",c);continue}this.services[c]=f,this.configureComponent(c,f),f[qu]!=null&&(this.log("registering service %s for content routing",c),l.push(f[qu])),f[Wu]!=null&&(this.log("registering service %s for peer routing",c),o.push(f[Wu])),f[bo]!=null&&(this.log("registering service %s for peer discovery",c),f[bo].addEventListener?.("peer",a=>{ye(this,Di,Yl).call(this,a)}))}mR(i)}configureComponent(e,r){return r==null&&this.log.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started")}catch(e){throw this.log.error("An error occurred starting libp2p",e),this.status="started",await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){const e=new Ur;for(const r of this.components.connectionManager.getConnections())e.add(r.remotePeer);return Array.from(e)}async dial(e,r={}){return this.components.connectionManager.openConnection(e,{priority:75,...r})}async dialProtocol(e,r,s={}){if(r==null)throw new C("no protocols were provided to open a stream",Z.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new C("no protocols were provided to open a stream",Z.ERR_INVALID_PROTOCOLS_FOR_STREAM);return(await this.dial(e,s)).newStream(r,s)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,r={}){da(e)&&(e=Ue(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(this.log("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;try{const o=await this.peerStore.get(e);if(o.id.publicKey!=null)return o.id.publicKey}catch(o){if(o.code!==Z.ERR_NOT_FOUND)throw o}const s=Jt([j("/pk/"),e.multihash.digest]),i=await this.contentRouting.get(s,r);return Si(i),await this.peerStore.patch(e,{publicKey:i}),i}async handle(e,r,s){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async i=>{await this.components.registrar.handle(i,r,s)}))}async unhandle(e){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async r=>{await this.components.registrar.unhandle(r)}))}async register(e,r){return this.components.registrar.register(e,r)}unregister(e){this.components.registrar.unregister(e)}async isDialable(e,r={}){return this.components.connectionManager.isDialable(e,r)}}Di=new WeakSet,Yl=function(e){const{detail:r}=e;if(r.id.toString()===this.peerId.toString()){this.log.error(new Error(Z.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs}).catch(s=>{this.log.error(s)})};async function TT(n={}){const t=n.peerId??(n.peerId=await ty());if(t.privateKey==null)throw new C("peer id was missing private key","ERR_MISSING_PRIVATE_KEY");return n.privateKey??(n.privateKey=await fa(t.privateKey)),new RT(await WR(n))}async function kT(n={}){const t=await TT(n);return n.start!==!1&&await t.start(),t}function CT({data:n=[],maxSize:t=1/0,compare:e=(s,i)=>si?1:0,extractKey:r=s=>s}={}){this.data=n;const s=new Map(n.map((l,c)=>[r(l),c]));this.indexes=s;const i=l=>{const c=n[l];for(;l>0;){const u=l-1>>1,f=n[u];if(e(c,f)>=0)break;s.set(r(f),l),n[l]=f,l=u}s.set(r(c),l),n[l]=c},o=l=>{const c=n.length>>1,u=n[l];for(;l=0)break;s.set(r(a),l),n[l]=a,l=f}s.set(r(u),l),n[l]=u};if(n.length>0)for(let l=(n.length>>1)-1;l>=0;l--)o(l);this.push=l=>{let c=s.get(r(l));if(c===void 0)return n.push(l),i(n.length-1),n.length<=t?void 0:this.pop();e(n[c],l)>=0||(n[c]=l,o(c))},this.pop=()=>{if(n.length===0)return;const l=n[0],c=n.pop();return n.length>0&&(s.set(r(c),0),n[0]=c,o(0)),s.delete(r(l)),l},this.peek=()=>n[0]}async function zy(n={}){const{type:t,moves:e,playerName:r,timestamp:s,value:i}=n;if(!t||!e||!r||!s||!i)throw new Error(["RECORD VALIDATION: BAD GAME DATA!",n]);return new Promise((o,l)=>{const c=setTimeout(()=>l(["RECORD VALIDATION: TIMEOUT!",n]),3333),u=Yd({cards:tt(Te.cards),energy:tt(Te.energy),log:tt(Te.log),matchedIndexes:tt(Te.matchedIndexes),moves:ri(e),options:ri({playerName:r,cluster:!1,rapid:!0}),phase:tt(Te.phase),plusIndex:tt(Te.plusIndex),records:tt({...Te.records}),score:tt(Te.score),seed:ri(nc(n)),timestamp:ri(s)});u.records.subscribe(f=>{const{movesInitial:a,phase:h}=u;if(a!==null&&Ie(h)!==X.gameOver)return;clearTimeout(c);const d=f[t][B.value];n={type:t,moves:e,playerName:r,timestamp:s,value:i},d>=i?(n.value=d,o(n)):l(["RECORD VALIDATION: WRONG VALUE!",n,d])})})}const Vs={root:"/digifall/root/1.0",preview:"/digifall/preview/1.0"},ou="12D3KooWRjPoVe5DnnMJzy8PYUwmgrkvgaXSpuR3MuNmbgoSRvio",xT="/dns4/relay.digifall.app/tcp/443/wss/p2p/"+ou;let In;const DT=hb(B.digifall,B.leaderboard),Aa=Qr.reduce((n,t)=>(n[t]=DT(t,Te[B.leaderboard][t]),n),{});function au(n,t){return n.value>t.value?1:n.value(n[t]=new CT({maxSize:Fd,compare:au,extractKey:PT}),n),{}),Vr=Qr.reduce((n,t)=>(n[t]=0,n),{});function lu(n){return JSON.parse(ue(n.subarray()))}function Ia(n){return j(JSON.stringify(n))}async function Gy(n){for await(const t of n){const e=lu(t),{type:r,playerName:s,value:i}=e,{data:o,indexes:l}=Zt[r],c=l.get(s);c in o&&o[c].value>=i||zy(e).then(u=>{Zt[r].push(u),Aa[r].set(Zt[r].data),console.warn("P2P LEADERBOARD UPDATED!",r,s,i)}).catch(u=>ln&&console.error(...u))}}async function NT(n,t){ln&&console.log(Vs.preview);const e=t.flatMap(r=>Zt[r].data.map(({playerName:s,value:i})=>Ia({type:r,playerName:s,value:i})));return n.newStream(Vs.preview,{runOnTransientConnection:!0}).then(r=>Jn(e,r,Gy)).catch(r=>ln&&console.error(r))}async function MT({connection:n,stream:t}){ln&&console.log("handleRoot"),Jn(t.source,async function*(e){const r=new Set;for await(const s of e){const[i,o]=lu(s);if(o===0){for(const l of Zt[i].data)yield Ia(l);continue}i in Vr&&o!==Vr[i]&&r.add(i)}r.size===0||n.status!=="open"||NT(n,Array.from(r))},t.sink).catch(e=>ln&&console.error(e))}async function OT({stream:n}){ln&&console.log("handlePreview"),Jn(n.source,async function*(t){const e=new Set,r=Qr.reduce((i,o)=>(i[o]=new Set,i),{});for await(const i of t){const{type:o,playerName:l,value:c}=lu(i);o in Vr&&e.add(o);const u=Zt[o].indexes.get(l);u!==void 0&&(Zt[o].data[u].value>c||r[o].add(l))}const s=Array.from(e).flatMap(i=>Zt[i].data.filter(o=>!r[i].has(o.playerName)).map(Ia));for(const i of s)yield i},n.sink).catch(t=>ln&&console.error(t))}function LT({detail:n}){ln&&console.log("peer:discovery",n.id.toString())}async function Ky(n){ln&&console.log(Vs.root);const t=Object.entries(Vr).map(Ia);n.newStream(Vs.root,{runOnTransientConnection:!0}).then(e=>Jn(t,e,Gy)).catch(e=>{ln&&console.error(e),e.code==="ERR_UNSUPPORTED_PROTOCOL"&&In.components.connectionGater.denyDialPeer(n.remotePeer),n.close()})}async function BT({detail:n}){const t=n.remotePeer.toString();ln&&console.log("connection:open",t),t!==ou&&n.status==="open"&&Ky(n)}async function qy(){In.getConnections().filter(({direction:n,remotePeer:t,status:e})=>e==="open"&&n==="outbound"&&t.toString()!==ou).forEach(Ky)}(async function(){const t=await ty(),e=await tI(Ie(Ni(B.peerId,{id:t.toString(),privKey:ue(t.privateKey,"base64pad"),pubKey:ue(t.publicKey,"base64pad")})));In=await kT({peerId:e,transports:[xI(),QA({discoverRelays:1})],connectionEncryption:[iI()],streamMuxers:[J2({maxInboundStreams:2,maxOutboundStreams:3})],peerDiscovery:[tA({list:[xT]}),uI({interval:1e4,topics:["digifall._peer-discovery"],listenOnly:!1})],services:{identify:R2({protocolPrefix:"digifall"}),pubsub:US({emitSelf:!0})},connectionManager:{minConnections:2,maxConnections:5,maxIncomingPendingConnections:3,inboundConnectionThreshold:3,autoDialDiscoveredPeersDebounce:Math.trunc(Math.random()*1e4)}}),In.handle(Vs.root,MT,{runOnTransientConnection:!0}),In.handle(Vs.preview,OT,{runOnTransientConnection:!0}),In.addEventListener("peer:discovery",LT),In.addEventListener("connection:open",BT),setInterval(qy,3e4),ln&&(window.libp2p=In)})();Qr.forEach(n=>{const t=Aa[n];t.subscribe(async e=>{if(!(!e||e.length===0)){if(Zt[n].data.length>0){const r=Vr[n];return Vr[n]=sl(e.slice().sort(au).map(s=>sl([nc(s),s.value]))),r===Vr[n]?void 0:qy()}Promise.allSettled(e.map(r=>zy(r).then(s=>Zt[n].push(s)))).then(()=>t.set(Zt[n].data))}})});vs.subscribe(n=>{const t=Ie(er);t!==X.idle&&t!==X.gameOver||Qr.forEach(e=>{const r=n[e];r[B.value]!==0&&(r[B.type]=e,Zt[e].push(r),Aa[e].set(Zt[e].data))})});Ct.subscribe(({leaderboard:n})=>{setTimeout(()=>n?In.start():In.stop(),3e3)});function Sf(n,t,e){const r=n.slice();r[20]=t[e].playerName,r[21]=t[e].value,r[28]=e;const s=r[20]===r[4][B.playerName];r[22]=s;const i=r[0]*ar+r[28]+1;r[23]=i;const o=(r[23].toString().length===1?8:14)+"rem";r[24]=o;const l=r[28]%10;r[25]=l;const c=("PLACE: "+r[23]+` +`),e),e.log('handle: responded with "na" for "%s"',s)}}const yT=500;var Sd,Ad;Ad=Symbol.toStringTag,Sd=Mb;class bT{constructor(t){y(this,"id");y(this,"remoteAddr");y(this,"remotePeer");y(this,"direction");y(this,"timeline");y(this,"multiplexer");y(this,"encryption");y(this,"status");y(this,"transient");y(this,"log");y(this,"tags");y(this,"_newStream");y(this,"_close");y(this,"_abort");y(this,"_getStreams");y(this,Ad,"Connection");y(this,Sd,!0);const{remoteAddr:e,remotePeer:r,newStream:s,close:i,abort:o,getStreams:l}=t;this.id=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`,this.remoteAddr=e,this.remotePeer=r,this.direction=t.direction,this.status="open",this.timeline=t.timeline,this.multiplexer=t.multiplexer,this.encryption=t.encryption,this.transient=t.transient??!1,this.log=t.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`),this.remoteAddr.getPeerId()==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),this._newStream=s,this._close=i,this._abort=o,this._getStreams=l,this.tags=[]}get streams(){return this._getStreams()}async newStream(t,e){if(this.status==="closing")throw new C("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new C("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(t)||(t=[t]),this.transient&&e?.runOnTransientConnection!==!0)throw new C("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");const r=await this._newStream(t,e);return r.direction="outbound",r}async close(t={}){if(!(this.status==="closed"||this.status==="closing")){if(this.log("closing connection to %a",this.remoteAddr),this.status="closing",t.signal==null){const e=AbortSignal.timeout(yT);Qe(1/0,e),t={...t,signal:e}}try{this.log.trace("closing all streams"),await Promise.all(this.streams.map(async e=>e.close(t))),this.log.trace("closing underlying transport"),await this._close(t),this.log.trace("updating timeline with close time"),this.status="closed",this.timeline.close=Date.now()}catch(e){this.log.error("error encountered during graceful close of connection to %a",this.remoteAddr,e),this.abort(e)}}}abort(t){this.log.error("aborting connection to %a due to error",this.remoteAddr,t),this.status="closing",this.streams.forEach(e=>{e.abort(t)}),this.log.error("all streams aborted",this.streams.length),this._abort(t),this.timeline.close=Date.now(),this.status="closed"}}function _T(n){return new bT(n)}const wT=3e4;function vT(n,t){try{const{options:e}=t.getHandler(n);return e.maxInboundStreams}catch(e){if(e.code!==Z.ERR_NO_HANDLER_FOR_PROTOCOL)throw e}return $y}function ET(n,t,e={}){try{const{options:r}=t.getHandler(n);if(r.maxOutboundStreams!=null)return r.maxOutboundStreams}catch(r){if(r.code!==Z.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return e.maxOutboundStreams??Hy}function Ef(n,t,e){let r=0;return e.streams.forEach(s=>{s.direction===t&&s.protocol===n&&r++}),r}var Id;Id=Symbol.toStringTag;class ST{constructor(t,e){y(this,"components");y(this,"connectionEncryption");y(this,"muxers");y(this,"inboundUpgradeTimeout");y(this,"events");y(this,Id,"@libp2p/upgrader");this.components=t,this.connectionEncryption=new Map,e.connectionEncryption.forEach(r=>{this.connectionEncryption.set(r.protocol,r)}),this.muxers=new Map,e.muxers.forEach(r=>{this.muxers.set(r.protocol,r)}),this.inboundUpgradeTimeout=e.inboundUpgradeTimeout??YR,this.events=t.events}async shouldBlockConnection(t,e,r){const s=this.components.connectionGater[r];if(s!==void 0&&await s(t,e))throw new C(`The multiaddr connection is blocked by gater.${r}`,Z.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(t,e){if(!await this.components.connectionManager.acceptIncomingConnection(t))throw new C("connection denied",Z.ERR_CONNECTION_DENIED);let s,i,o,l,c;const u=AbortSignal.timeout(this.inboundUpgradeTimeout),f=()=>{t.abort(new C("inbound upgrade timeout",fp))};u.addEventListener("abort",f,{once:!0}),Qe(1/0,u);try{if(await this.components.connectionGater.denyInboundConnection?.(t)===!0)throw new C("The multiaddr connection is blocked by gater.acceptConnection",Z.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(t),t.log("starting the inbound connection upgrade");let a=t;if(e?.skipProtection!==!0){const h=this.components.connectionProtector;h!=null&&(t.log("protecting the inbound connection"),a=await h.protect(t))}try{if(s=a,e?.skipEncryption!==!0){e?.onProgress?.(new rt("upgrader:encrypt-inbound-connection")),{conn:s,remotePeer:i,protocol:c}=await this._encryptInbound(a);const h={...a,...s};await this.shouldBlockConnection(i,h,"denyInboundEncryptedConnection")}else{const h=t.remoteAddr.getPeerId();if(h==null)throw new C("inbound connection that skipped encryption must have a peer id",Z.ERR_INVALID_MULTIADDR);const d=Ue(h);c="native",i=d}if(o=s,e?.muxerFactory!=null)l=e.muxerFactory;else if(this.muxers.size>0){e?.onProgress?.(new rt("upgrader:multiplex-inbound-connection"));const h=await this._multiplexInbound({...a,...s},this.muxers);l=h.muxerFactory,o=h.stream}}catch(h){throw t.log.error("failed to upgrade inbound connection",h),h}return await this.shouldBlockConnection(i,t,"denyInboundUpgradedConnection"),t.log("successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:t,upgradedConn:o,muxerFactory:l,remotePeer:i,transient:e?.transient})}finally{u.removeEventListener("abort",f),this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(t,e){const r=t.remoteAddr.getPeerId();let s;r!=null&&(s=Ue(r),await this.shouldBlockConnection(s,t,"denyOutboundConnection"));let i,o,l,c,u;this.components.metrics?.trackMultiaddrConnection(t),t.log("starting the outbound connection upgrade");let f=t;if(e?.skipProtection!==!0){const a=this.components.connectionProtector;a!=null&&(f=await a.protect(t))}try{if(i=f,e?.skipEncryption!==!0){({conn:i,remotePeer:o,protocol:c}=await this._encryptOutbound(f,s));const a={...f,...i};await this.shouldBlockConnection(o,a,"denyOutboundEncryptedConnection")}else{if(s==null)throw new C("Encryption was skipped but no peer id was passed",Z.ERR_INVALID_PEER);c="native",o=s}if(l=i,e?.muxerFactory!=null)u=e.muxerFactory;else if(this.muxers.size>0){const a=await this._multiplexOutbound({...f,...i},this.muxers);u=a.muxerFactory,l=a.stream}}catch(a){throw t.log.error("failed to upgrade outbound connection",a),await t.close(a),a}return await this.shouldBlockConnection(o,t,"denyOutboundUpgradedConnection"),t.log("successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:t,upgradedConn:l,muxerFactory:u,remotePeer:o,transient:e?.transient})}_createConnection(t){const{cryptoProtocol:e,direction:r,maConn:s,upgradedConn:i,remotePeer:o,muxerFactory:l,transient:c}=t;let u,f,a;l!=null&&(u=l.createStreamMuxer({direction:r,onIncomingStream:m=>{a!=null&&Promise.resolve().then(async()=>{const p=this.components.registrar.getProtocols(),{stream:g,protocol:b}=await Ja(m,p,{log:m.log,yieldBytes:!1});if(a==null)return;a.log("incoming stream opened on %s",b);const w=vT(b,this.components.registrar);if(Ef(b,"inbound",a)===w){const A=new C(`Too many inbound protocol streams for protocol "${b}" - limit ${w}`,Z.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw m.abort(A),A}m.source=g.source,m.sink=g.sink,m.protocol=b,g.closeWrite!=null&&(m.closeWrite=g.closeWrite),g.closeRead!=null&&(m.closeRead=g.closeRead),g.close!=null&&(m.close=g.close),await this.components.peerStore.merge(o,{protocols:[b]}),this.components.metrics?.trackProtocolStream(m,a),this._onStream({connection:a,stream:m,protocol:b})}).catch(async p=>{a.log.error("error handling incoming stream id %s",m.id,p.message,p.code,p.stack),m.timeline.close==null&&await m.close()})}}),f=async(m,p={})=>{if(u==null)throw new C("Stream is not multiplexed",Z.ERR_MUXER_UNAVAILABLE);a.log("starting new stream for protocols %s",m);const g=await u.newStream();a.log.trace("started new stream %s for protocols %s",g.id,m);try{if(p.signal==null){g.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",m);const S=AbortSignal.timeout(wT);Qe(1/0,S),p={...p,signal:S}}g.log.trace("selecting protocol from protocols %s",m);const{stream:b,protocol:w}=await ja(g,m,{...p,log:g.log,yieldBytes:!0});g.log("selected protocol %s",w);const _=ET(w,this.components.registrar,p),A=Ef(w,"outbound",a);if(A>=_){const S=new C(`Too many outbound protocol streams for protocol "${w}" - ${A}/${_}`,Z.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw g.abort(S),S}return await this.components.peerStore.merge(o,{protocols:[w]}),g.source=b.source,g.sink=b.sink,g.protocol=w,b.closeWrite!=null&&(g.closeWrite=b.closeWrite),b.closeRead!=null&&(g.closeRead=b.closeRead),b.close!=null&&(g.close=b.close),this.components.metrics?.trackProtocolStream(g,a),g}catch(b){throw a.log.error("could not create new stream for protocols %s",m,b),g.timeline.close==null&&g.abort(b),b.code!=null?b:new C(String(b),Z.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(i.source),i.sink(u.source)]).catch(m=>{a.log.error("error piping data through muxer",m)}));const h=s.timeline;s.timeline=new Proxy(h,{set:(...m)=>(a!=null&&m[1]==="close"&&m[2]!=null&&h.close==null&&(async()=>{try{a.status==="open"&&await a.close()}catch(p){a.log.error("error closing connection after timeline close",p)}finally{this.events.safeDispatchEvent("connection:close",{detail:a})}})().catch(p=>{a.log.error("error thrown while dispatching connection:close event",p)}),Reflect.set(...m))}),s.timeline.upgraded=Date.now();const d=()=>{throw new C("connection is not multiplexed",Z.ERR_CONNECTION_NOT_MULTIPLEXED)};return a=_T({remoteAddr:s.remoteAddr,remotePeer:o,status:"open",direction:r,timeline:s.timeline,multiplexer:u?.protocol,encryption:e,transient:c,logger:this.components.logger,newStream:f??d,getStreams:()=>u!=null?u.streams:[],close:async m=>{u!=null&&(a.log.trace("close muxer"),await u.close(m)),a.log.trace("close maconn"),await s.close(m),a.log.trace("closed maconn")},abort:m=>{s.abort(m),u?.abort(m)}}),this.events.safeDispatchEvent("connection:open",{detail:a}),a}_onStream(t){const{connection:e,stream:r,protocol:s}=t,{handler:i,options:o}=this.components.registrar.getHandler(s);if(e.transient&&o.runOnTransientConnection!==!0)throw new C("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");i({connection:e,stream:r})}async _encryptInbound(t){const e=Array.from(this.connectionEncryption.keys());t.log("handling inbound crypto protocol selection",e);try{const{stream:r,protocol:s}=await Ja(t,e,{log:t.log}),i=this.connectionEncryption.get(s);if(i==null)throw new Error(`no crypto module found for ${s}`);return t.log("encrypting inbound connection using",s),{...await i.secureInbound(this.components.peerId,r),protocol:s}}catch(r){throw t.log.error("encrypting inbound connection failed",r),new C(r.message,Z.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(t,e){const r=Array.from(this.connectionEncryption.keys());t.log("selecting outbound crypto protocol",r);try{t.log.trace("selecting encrypter from %s",r);const{stream:s,protocol:i}=await ja(t,r,{log:t.log,yieldBytes:!0}),o=this.connectionEncryption.get(i);if(o==null)throw new Error(`no crypto module found for ${i}`);return t.log("encrypting outbound connection to %p using %s",e,o),{...await o.secureOutbound(this.components.peerId,s,e),protocol:i}}catch(s){throw t.log.error("encrypting outbound connection to %p failed",e,s),new C(s.message,Z.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(t,e){const r=Array.from(e.keys());t.log("outbound selecting muxer %s",r);try{t.log.trace("selecting stream muxer from %s",r);const{stream:s,protocol:i}=await ja(t,r,{log:t.log,yieldBytes:!0});t.log("selected %s as muxer protocol",i);const o=e.get(i);return{stream:s,muxerFactory:o}}catch(s){throw t.log.error("error multiplexing outbound connection",s),new C(String(s),Z.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(t,e){const r=Array.from(e.keys());t.log("inbound handling muxers %s",r);try{const{stream:s,protocol:i}=await Ja(t,r,{log:t.log}),o=e.get(i);return{stream:s,muxerFactory:o}}catch(s){throw t.log.error("error multiplexing inbound connection",s),new C(String(s),Z.ERR_MUXER_UNAVAILABLE)}}}const AT="1.8.1",IT="libp2p";var Di,Yl;class RT extends Nn{constructor(e){super();Ce(this,Di);y(this,"peerId");y(this,"peerStore");y(this,"contentRouting");y(this,"peerRouting");y(this,"metrics");y(this,"services");y(this,"logger");y(this,"status");y(this,"components");y(this,"log");this.status="stopped";const r=new Nn,s=r.dispatchEvent.bind(r);r.dispatchEvent=c=>{const u=s(c),f=this.dispatchEvent(new xr(c.type,{detail:c.detail}));return u||f},Qe(1/0,r),this.peerId=e.peerId,this.logger=e.logger??ay(),this.log=this.logger.forComponent("libp2p"),this.services={};const i=this.components=gR({peerId:e.peerId,privateKey:e.privateKey,nodeInfo:e.nodeInfo??{name:IT,version:AT},logger:this.logger,events:r,datastore:e.datastore??new lR,connectionGater:AR(e.connectionGater),dns:e.dns});this.peerStore=this.configureComponent("peerStore",new tR(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),i.events.addEventListener("peer:update",c=>{if(c.detail.previous==null){const u={id:c.detail.peer.id,multiaddrs:c.detail.peer.addresses.map(f=>f.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:u})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new ST(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((c,u)=>this.configureComponent(`connection-encryption-${u}`,c(this.components))),muxers:(e.streamMuxers??[]).map((c,u)=>this.configureComponent(`stream-muxers-${u}`,c(this.components))),inboundUpgradeTimeout:e.connectionManager?.inboundUpgradeTimeout}),this.configureComponent("transportManager",new fT(this.components,e.transportManager)),this.configureComponent("connectionManager",new iT(this.components,e.connectionManager)),this.configureComponent("registrar",new cT(this.components)),this.configureComponent("addressManager",new hR(this.components,e.addresses));const o=(e.peerRouters??[]).map((c,u)=>this.configureComponent(`peer-router-${u}`,c(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new aT(this.components,{routers:o}));const l=(e.contentRouters??[]).map((c,u)=>this.configureComponent(`content-router-${u}`,c(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new oT(this.components,{routers:l})),this.configureComponent("randomWalk",new lT(this.components)),(e.peerDiscovery??[]).forEach((c,u)=>{this.configureComponent(`peer-discovery-${u}`,c(this.components)).addEventListener("peer",a=>{ye(this,Di,Yl).call(this,a)})}),e.transports?.forEach((c,u)=>{this.components.transportManager.add(this.configureComponent(`transport-${u}`,c(this.components)))}),e.services!=null)for(const c of Object.keys(e.services)){const u=e.services[c],f=u(this.components);if(f==null){this.log.error("service factory %s returned null or undefined instance",c);continue}this.services[c]=f,this.configureComponent(c,f),f[qu]!=null&&(this.log("registering service %s for content routing",c),l.push(f[qu])),f[Wu]!=null&&(this.log("registering service %s for peer routing",c),o.push(f[Wu])),f[bo]!=null&&(this.log("registering service %s for peer discovery",c),f[bo].addEventListener?.("peer",a=>{ye(this,Di,Yl).call(this,a)}))}mR(i)}configureComponent(e,r){return r==null&&this.log.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started")}catch(e){throw this.log.error("An error occurred starting libp2p",e),this.status="started",await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){const e=new Ur;for(const r of this.components.connectionManager.getConnections())e.add(r.remotePeer);return Array.from(e)}async dial(e,r={}){return this.components.connectionManager.openConnection(e,{priority:75,...r})}async dialProtocol(e,r,s={}){if(r==null)throw new C("no protocols were provided to open a stream",Z.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new C("no protocols were provided to open a stream",Z.ERR_INVALID_PROTOCOLS_FOR_STREAM);return(await this.dial(e,s)).newStream(r,s)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,r={}){da(e)&&(e=Ue(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(this.log("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;try{const o=await this.peerStore.get(e);if(o.id.publicKey!=null)return o.id.publicKey}catch(o){if(o.code!==Z.ERR_NOT_FOUND)throw o}const s=Jt([j("/pk/"),e.multihash.digest]),i=await this.contentRouting.get(s,r);return Si(i),await this.peerStore.patch(e,{publicKey:i}),i}async handle(e,r,s){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async i=>{await this.components.registrar.handle(i,r,s)}))}async unhandle(e){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async r=>{await this.components.registrar.unhandle(r)}))}async register(e,r){return this.components.registrar.register(e,r)}unregister(e){this.components.registrar.unregister(e)}async isDialable(e,r={}){return this.components.connectionManager.isDialable(e,r)}}Di=new WeakSet,Yl=function(e){const{detail:r}=e;if(r.id.toString()===this.peerId.toString()){this.log.error(new Error(Z.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs}).catch(s=>{this.log.error(s)})};async function TT(n={}){const t=n.peerId??(n.peerId=await ty());if(t.privateKey==null)throw new C("peer id was missing private key","ERR_MISSING_PRIVATE_KEY");return n.privateKey??(n.privateKey=await fa(t.privateKey)),new RT(await WR(n))}async function kT(n={}){const t=await TT(n);return n.start!==!1&&await t.start(),t}function CT({data:n=[],maxSize:t=1/0,compare:e=(s,i)=>si?1:0,extractKey:r=s=>s}={}){this.data=n;const s=new Map(n.map((l,c)=>[r(l),c]));this.indexes=s;const i=l=>{const c=n[l];for(;l>0;){const u=l-1>>1,f=n[u];if(e(c,f)>=0)break;s.set(r(f),l),n[l]=f,l=u}s.set(r(c),l),n[l]=c},o=l=>{const c=n.length>>1,u=n[l];for(;l=0)break;s.set(r(a),l),n[l]=a,l=f}s.set(r(u),l),n[l]=u};if(n.length>0)for(let l=(n.length>>1)-1;l>=0;l--)o(l);this.push=l=>{let c=s.get(r(l));if(c===void 0)return n.push(l),i(n.length-1),n.length<=t?void 0:this.pop();e(n[c],l)>=0||(n[c]=l,o(c))},this.pop=()=>{if(n.length===0)return;const l=n[0],c=n.pop();return n.length>0&&(s.set(r(c),0),n[0]=c,o(0)),s.delete(r(l)),l},this.peek=()=>n[0]}async function zy(n={}){const{type:t,moves:e,playerName:r,timestamp:s,value:i}=n;if(!t||!e||!r||!s||!i)throw new Error(["RECORD VALIDATION: BAD GAME DATA!",n]);return new Promise((o,l)=>{const c=setTimeout(()=>l(["RECORD VALIDATION: TIMEOUT!",n]),3e3),u=Yd({cards:tt(Te.cards),energy:tt(Te.energy),log:tt(Te.log),matchedIndexes:tt(Te.matchedIndexes),moves:ri(e),options:ri({playerName:r,cluster:!1,rapid:!0}),phase:tt(Te.phase),plusIndex:tt(Te.plusIndex),records:tt({...Te.records}),score:tt(Te.score),seed:ri(nc(n)),timestamp:ri(s)});u.records.subscribe(f=>{const{movesInitial:a,phase:h}=u;if(a!==null&&Ie(h)!==X.gameOver)return;clearTimeout(c);const d=f[t][B.value];n={type:t,moves:e,playerName:r,timestamp:s,value:i},d>=i?(n.value=d,o(n)):l(["RECORD VALIDATION: WRONG VALUE!",n,d])})})}const Vs={root:"/digifall/root/1.0",preview:"/digifall/preview/1.0"},ou="12D3KooWRjPoVe5DnnMJzy8PYUwmgrkvgaXSpuR3MuNmbgoSRvio",xT="/dns4/relay.digifall.app/tcp/443/wss/p2p/"+ou;let In;const DT=hb(B.digifall,B.leaderboard),Aa=Qr.reduce((n,t)=>(n[t]=DT(t,Te[B.leaderboard][t]),n),{});function au(n,t){return n.value>t.value?1:n.value(n[t]=new CT({maxSize:Fd,compare:au,extractKey:PT}),n),{}),Vr=Qr.reduce((n,t)=>(n[t]=0,n),{});function lu(n){return JSON.parse(ue(n.subarray()))}function Ia(n){return j(JSON.stringify(n))}async function Gy(n){for await(const t of n){const e=lu(t),{type:r,playerName:s,value:i}=e,{data:o,indexes:l}=Zt[r],c=l.get(s);c in o&&o[c].value>=i||zy(e).then(u=>{Zt[r].push(u),Aa[r].set(Zt[r].data),console.warn("P2P LEADERBOARD UPDATED!",r,s,i)}).catch(u=>ln&&console.error(...u))}}async function NT(n,t){ln&&console.log(Vs.preview);const e=t.flatMap(r=>Zt[r].data.map(({playerName:s,value:i})=>Ia({type:r,playerName:s,value:i})));return n.newStream(Vs.preview,{runOnTransientConnection:!0}).then(r=>Jn(e,r,Gy)).catch(r=>ln&&console.error(r))}async function MT({connection:n,stream:t}){ln&&console.log("handleRoot"),Jn(t.source,async function*(e){const r=new Set;for await(const s of e){const[i,o]=lu(s);if(o===0){for(const l of Zt[i].data)yield Ia(l);continue}i in Vr&&o!==Vr[i]&&r.add(i)}r.size===0||n.status!=="open"||NT(n,Array.from(r))},t.sink).catch(e=>ln&&console.error(e))}async function OT({stream:n}){ln&&console.log("handlePreview"),Jn(n.source,async function*(t){const e=new Set,r=Qr.reduce((i,o)=>(i[o]=new Set,i),{});for await(const i of t){const{type:o,playerName:l,value:c}=lu(i);o in Vr&&e.add(o);const u=Zt[o].indexes.get(l);u!==void 0&&(Zt[o].data[u].value>c||r[o].add(l))}const s=Array.from(e).flatMap(i=>Zt[i].data.filter(o=>!r[i].has(o.playerName)).map(Ia));for(const i of s)yield i},n.sink).catch(t=>ln&&console.error(t))}function LT({detail:n}){ln&&console.log("peer:discovery",n.id.toString())}async function Ky(n){ln&&console.log(Vs.root);const t=Object.entries(Vr).map(Ia);n.newStream(Vs.root,{runOnTransientConnection:!0}).then(e=>Jn(t,e,Gy)).catch(e=>{ln&&console.error(e),e.code==="ERR_UNSUPPORTED_PROTOCOL"&&In.components.connectionGater.denyDialPeer(n.remotePeer),n.close()})}async function BT({detail:n}){const t=n.remotePeer.toString();ln&&console.log("connection:open",t),t!==ou&&n.status==="open"&&Ky(n)}async function qy(){In.getConnections().filter(({direction:n,remotePeer:t,status:e})=>e==="open"&&n==="outbound"&&t.toString()!==ou).forEach(Ky)}(async function(){const t=await ty(),e=await tI(Ie(Ni(B.peerId,{id:t.toString(),privKey:ue(t.privateKey,"base64pad"),pubKey:ue(t.publicKey,"base64pad")})));In=await kT({peerId:e,transports:[xI(),QA({discoverRelays:1})],connectionEncryption:[iI()],streamMuxers:[J2({maxInboundStreams:2,maxOutboundStreams:3})],peerDiscovery:[tA({list:[xT]}),uI({interval:1e4,topics:["digifall._peer-discovery"],listenOnly:!1})],services:{identify:R2({protocolPrefix:"digifall"}),pubsub:US({emitSelf:!0})},connectionManager:{minConnections:2,maxConnections:5,maxIncomingPendingConnections:3,inboundConnectionThreshold:3,autoDialDiscoveredPeersDebounce:Math.trunc(Math.random()*1e4)}}),In.handle(Vs.root,MT,{runOnTransientConnection:!0}),In.handle(Vs.preview,OT,{runOnTransientConnection:!0}),In.addEventListener("peer:discovery",LT),In.addEventListener("connection:open",BT),setInterval(qy,3e4),ln&&(window.libp2p=In)})();Qr.forEach(n=>{const t=Aa[n];t.subscribe(async e=>{if(!(!e||e.length===0)){if(Zt[n].data.length>0){const r=Vr[n];return Vr[n]=sl(e.slice().sort(au).map(s=>sl([nc(s),s.value]))),r===Vr[n]?void 0:qy()}Promise.allSettled(e.map(r=>zy(r).then(s=>Zt[n].push(s)))).then(()=>t.set(Zt[n].data))}})});vs.subscribe(n=>{const t=Ie(er);t!==X.idle&&t!==X.gameOver||Qr.forEach(e=>{const r=n[e];r[B.value]!==0&&(r[B.type]=e,Zt[e].push(r),Aa[e].set(Zt[e].data))})});Ct.subscribe(({leaderboard:n})=>{setTimeout(()=>n?In.start():In.stop(),3e3)});function Sf(n,t,e){const r=n.slice();r[20]=t[e].playerName,r[21]=t[e].value,r[28]=e;const s=r[20]===r[4][B.playerName];r[22]=s;const i=r[0]*ar+r[28]+1;r[23]=i;const o=(r[23].toString().length===1?8:14)+"rem";r[24]=o;const l=r[28]%10;r[25]=l;const c=("PLACE: "+r[23]+` PLAYER NAME: "`+r[20]+`" SCORE: `+r[21]).toUpperCase();return r[26]=c,r}function Af(n,t,e){const r=n.slice();r[29]=t[e],r[28]=e;const s=r[28]+1;return r[21]=s,r}function If(n){let t,e=n[6][n[1]]+"",r,s;return{c(){t=x("span"),r=Oe(e)},m(i,o){V(i,t,o),T(t,r)},p(i,o){o&2&&e!==(e=i[6][i[1]]+"")&&Je(r,e)},i(i){i&&(s||Re(()=>{s=qe(t,Zn,{duration:200}),s.start()}))},o:he,d(i){i&&F(t)}}}function Rf(n){let t,e=`var(--color-${n[21]})`;return{c(){t=x("li"),t.textContent=`${n[21]} `,k(t,"class","page"),k(t,"data-index",n[28]),te(t,"active",n[28]===n[0]),Be(t,"--color",e)},m(r,s){V(r,t,s)},p(r,s){s&1&&te(t,"active",r[28]===r[0])},d(r){r&&F(t)}}}function Tf(n){let t,e,r=n[20]+"",s,i,o,l,c,u=n[21]+"",f,a,h;return{c(){t=x("dt"),e=x("div"),s=Oe(r),o=K(),c=x("dd"),f=Oe(u),a=K(),k(e,"class","player-name"),k(e,"title",i=n[26]),Be(e,"--delay",n[25]),k(t,"data-nth",l=n[23]),te(t,"self",n[22]),Be(t,"margin-left",n[24]),k(c,"title",h=n[26]),te(c,"self",n[22]),Be(c,"margin-left",n[24])},m(d,m){V(d,t,m),T(t,e),T(e,s),T(t,o),V(d,c,m),T(c,f),T(c,a)},p(d,m){m&4&&r!==(r=d[20]+"")&&Je(s,r),m&5&&i!==(i=d[26])&&k(e,"title",i),m&1&&l!==(l=d[23])&&k(t,"data-nth",l),m&20&&te(t,"self",d[22]),m&1&&Be(t,"margin-left",d[24]),m&4&&u!==(u=d[21]+"")&&Je(f,u),m&5&&h!==(h=d[26])&&k(c,"title",h),m&20&&te(c,"self",d[22]),m&1&&Be(c,"margin-left",d[24])},d(d){d&&(F(t),F(c))}}}function kf(n){let t,e,r,s,i=jt(n[2]),o=[];for(let l=0;l{s&&(r&&r.end(1),e=qe(t,an,{x:n[9](1)}),e.start())}),s=!0)},o(l){e&&e.invalidate(),l&&(r=jo(t,an,{x:n[9](-1)})),s=!1},d(l){l&&F(t),Pi(o,l),l&&r&&r.end()}}}function FT(n){let t,e,r,s,i,o,l=n[6][n[1]],c,u,f,a,h,d,m=n[0],p,g,b,w,_,A,S,E,v=If(n),R=jt(Array.from({length:n[5]})),I=[];for(let P=0;P{c=qe(r,an,{y:-48}),c.start()})),H(D),P&&(_||Re(()=>{_=qe(w,an,{y:48}),_.start()})),P&&(A||Re(()=>{A=qe(t,Zn,{}),A.start()}))},o(P){re(v),re(D)},d(P){P&&F(t),v.d(P),Pi(I,P),D.d(P),S=!1,mt(E)}}}const ar=9;function UT(n,t,e){let r,s,i,o,l,c,u=he,f=()=>(u(),u=Zo(r,I=>e(16,c=I)),r),a,h;oe(n,Ge,I=>e(18,a=I)),oe(n,Ct,I=>e(4,h=I)),n.$$.on_destroy.push(()=>u());let d=0;const m=Math.ceil(Fd/ar);let p=B.highScore,g=d;const b={[B.highCombo]:"combos",[B.highScore]:"scores"};function w(){return g=d,e(0,d=d<1?ar-1:d-1)}function _(){return g=d,e(0,d=dP===h[B.playerName]);D!==-1&&(g=d,e(0,d=Math.trunc(D/ar)))}function S(I){e(1,p=p===B.highScore?B.highCombo:B.highScore)}function E(I){const D=I.composedPath().find(({dataset:P})=>P&&P.index);D!==void 0&&(g=d,e(0,d=Number(D.dataset.index)))}function v(I=1){if(d===g)return 0;const D=256;return I*(d>g?D:-D)}function R(){ut(Ge,a=pe.menu,a)}return n.$$.update=()=>{n.$$.dirty&2&&f(e(3,r=Aa[p])),n.$$.dirty&65536&&e(15,s=c.slice().sort((I,D)=>au(D,I))),n.$$.dirty&32768&&A(s),n.$$.dirty&1&&e(14,i=d*ar),n.$$.dirty&16384&&e(13,o=i+ar),n.$$.dirty&57344&&e(2,l=s.slice(i,o)),n.$$.dirty&4&&l.push(...Array.from({length:ar-l.length}).fill({playerName:"",value:0}))},[d,p,l,r,h,m,b,S,E,v,R,w,_,o,i,s,c]}class VT extends Pt{constructor(t){super(),Dt(this,t,UT,FT,ct,{prevPage:11,nextPage:12})}get prevPage(){return this.$$.ctx[11]}get nextPage(){return this.$$.ctx[12]}}function Cf(n){let t,e,r,s,i,o,l,c,u,f,a,h=n[1]&&xf(n);const d=n[6].default,m=o0(d,n,n[5],null);return{c(){t=x("div"),e=x("div"),h&&h.c(),r=K(),s=x("div"),i=K(),o=x("div"),m&&m.c(),c=K(),u=x("div"),k(e,"class","section-1"),k(s,"class","section-2"),k(o,"class","section-3"),k(u,"class","section-4"),k(t,"class","dialog content")},m(p,g){V(p,t,g),T(t,e),h&&h.m(e,null),T(t,r),T(t,s),T(t,i),T(t,o),m&&m.m(o,null),T(t,c),T(t,u),a=!0},p(p,g){p[1]?h?(h.p(p,g),g&2&&H(h,1)):(h=xf(p),h.c(),H(h,1),h.m(e,null)):h&&(h.d(1),h=null),m&&m.p&&(!a||g&32)&&l0(m,d,p,p[5],a?a0(d,p[5],g,null):c0(p[5]),null)},i(p){a||(H(h),H(m,p),p&&(l||Re(()=>{l=qe(o,an,{y:24}),l.start()})),p&&(f||Re(()=>{f=qe(t,Zn,{}),f.start()})),a=!0)},o(p){re(m,p),a=!1},d(p){p&&F(t),h&&h.d(),m&&m.d(p)}}}function xf(n){let t,e,r;return{c(){t=x("span"),e=Oe(n[1]),k(t,"class","title")},m(s,i){V(s,t,i),T(t,e)},p(s,i){i&2&&Je(e,s[1])},i(s){s&&(r||Re(()=>{r=qe(t,an,{y:-48}),r.start()}))},o:he,d(s){s&&F(t)}}}function $T(n){let t,e,r=n[0]&&Cf(n);return{c(){r&&r.c(),t=Hs()},m(s,i){r&&r.m(s,i),V(s,t,i),e=!0},p(s,[i]){s[0]?r?(r.p(s,i),i&1&&H(r,1)):(r=Cf(s),r.c(),H(r,1),r.m(t.parentNode,t)):r&&($t(),re(r,1,1,()=>{r=null}),Ht())},i(s){e||(H(r),e=!0)},o(s){re(r),e=!1},d(s){s&&F(t),r&&r.d(s)}}}function HT(n,t,e){let{$$slots:r={},$$scope:s}=t;const i=w0();let{title:o=""}=t,{opened:l=!1}=t;function c(){return l}function u(){e(0,l=!1),i("close")}function f(){e(0,l=!0),i("show")}return n.$$set=a=>{"title"in a&&e(1,o=a.title),"opened"in a&&e(0,l=a.opened),"$$scope"in a&&e(5,s=a.$$scope)},[l,o,c,u,f,s,r]}class cu extends Pt{constructor(t){super(),Dt(this,t,HT,$T,ct,{title:1,opened:0,isOpened:2,close:3,show:4})}get isOpened(){return this.$$.ctx[2]}get close(){return this.$$.ctx[3]}get show(){return this.$$.ctx[4]}}const zT="0.9.2";function Df(n){let t,e,r,s,i,o,l,c,u,f,a,h,d,m,p,g,b,w,_,A,S,E,v=n[2].rapid&&Pf();function R(U,W){return U[3]===X.gameOver?KT:GT}let I=R(n),D=I(n),P=n[2][B.leaderboard]&&Nf(n);return{c(){t=x("div"),e=x("div"),r=x("h1"),s=Oe(`digifall `),v&&v.c(),i=K(),o=x("span"),o.textContent=`${zT}`,l=K(),c=x("div"),u=K(),f=x("div"),a=x("div"),D.c(),h=K(),P&&P.c(),d=K(),m=x("button"),m.textContent="options",p=K(),g=x("div"),w=K(),_=x("a"),_.innerHTML='',k(o,"class","version"),k(e,"class","section-1"),k(c,"class","section-2"),k(a,"class","col"),k(f,"class","section-3"),k(g,"class","section-4"),k(t,"class","menu content"),k(_,"href","https://github.com/shlavik/digifall"),k(_,"class","github-corner"),k(_,"aria-label","View source on GitHub")},m(U,W){V(U,t,W),T(t,e),T(e,r),T(r,s),v&&v.m(r,null),T(r,i),T(r,o),T(t,l),T(t,c),T(t,u),T(t,f),T(f,a),D.m(a,null),T(a,h),P&&P.m(a,null),T(a,d),T(a,m),T(t,p),T(t,g),V(U,w,W),V(U,_,W),S||(E=we(m,"click",n[7]),S=!0)},p(U,W){U[2].rapid?v||(v=Pf(),v.c(),v.m(r,i)):v&&(v.d(1),v=null),I===(I=R(U))&&D?D.p(U,W):(D.d(1),D=I(U),D&&(D.c(),D.m(a,h))),U[2][B.leaderboard]?P?P.p(U,W):(P=Nf(U),P.c(),P.m(a,d)):P&&(P.d(1),P=null)},i(U){b||Re(()=>{b=qe(t,Zn,{}),b.start()}),U&&(A||Re(()=>{A=qe(_,Zn,{}),A.start()}))},o:he,d(U){U&&(F(t),F(w),F(_)),v&&v.d(),D.d(),P&&P.d(),S=!1,E()}}}function Pf(n){let t;return{c(){t=x("span"),t.textContent="rapid",k(t,"class","rapid")},m(e,r){V(e,t,r)},d(e){e&&F(t)}}}function GT(n){let t,e,r,s,i;return{c(){t=x("button"),t.textContent="resume",e=K(),r=x("button"),r.textContent="new game"},m(o,l){V(o,t,l),V(o,e,l),V(o,r,l),s||(i=[we(t,"click",n[4]),we(r,"click",function(){On(n[0].show)&&n[0].show.apply(this,arguments)})],s=!0)},p(o,l){n=o},d(o){o&&(F(t),F(e),F(r)),s=!1,mt(i)}}}function KT(n){let t,e,r;return{c(){t=x("button"),t.textContent="new game"},m(s,i){V(s,t,i),e||(r=we(t,"click",n[5]),e=!0)},p:he,d(s){s&&F(t),e=!1,r()}}}function Nf(n){let t,e,r;return{c(){t=x("button"),t.textContent="p2p leaderboard"},m(s,i){V(s,t,i),e||(r=we(t,"click",n[6]),e=!0)},p:he,d(s){s&&F(t),e=!1,r()}}}function qT(n){let t,e,r,s,i,o,l,c,u;return{c(){t=x("div"),e=x("p"),e.textContent="start a new game?",r=K(),s=x("div"),i=x("button"),i.textContent="yes",o=K(),l=x("button"),l.textContent="no",k(s,"class","row"),k(t,"class","col")},m(f,a){V(f,t,a),T(t,e),T(t,r),T(t,s),T(s,i),T(s,o),T(s,l),c||(u=[we(i,"click",n[5]),we(l,"click",function(){On(n[0].close)&&n[0].close.apply(this,arguments)})],c=!0)},p(f,a){n=f},d(f){f&&F(t),c=!1,mt(u)}}}function WT(n){let t,e,r,s,i=!n[1]&&Df(n);function o(c){n[11](c)}let l={$$slots:{default:[qT]},$$scope:{ctx:n}};return n[1]!==void 0&&(l.opened=n[1]),e=new cu({props:l}),n[10](e),Me.push(()=>Gs(e,"opened",o)),{c(){i&&i.c(),t=K(),st(e.$$.fragment)},m(c,u){i&&i.m(c,u),V(c,t,u),Xe(e,c,u),s=!0},p(c,[u]){c[1]?i&&(i.d(1),i=null):i?(i.p(c,u),u&2&&H(i,1)):(i=Df(c),i.c(),H(i,1),i.m(t.parentNode,t));const f={};u&8193&&(f.$$scope={dirty:u,ctx:c}),!r&&u&2&&(r=!0,f.opened=c[1],zs(()=>r=!1)),e.$set(f)},i(c){s||(H(i),H(e.$$.fragment,c),s=!0)},o(c){re(e.$$.fragment,c),s=!1},d(c){c&&F(t),i&&i.d(c),n[10](null),Ze(e,c)}}}function YT(n,t,e){let r,s,i;oe(n,Ge,g=>e(12,r=g)),oe(n,Ct,g=>e(2,s=g)),oe(n,er,g=>e(3,i=g));let o=null,l=!1;_0(()=>{s.playerName===""&&ut(Ge,r=pe.wellcome,r)});function c(){return o.isOpened()}function u(){o.close()}function f(){ut(Ge,r=null,r)}function a(){o.close(),sc()}function h(){ut(Ge,r=pe.leaderboard,r)}function d(){ut(Ge,r=pe.options,r)}function m(g){Me[g?"unshift":"push"](()=>{o=g,e(0,o)})}function p(g){l=g,e(1,l)}return[o,l,s,i,f,a,h,d,c,u,m,p]}class QT extends Pt{constructor(t){super(),Dt(this,t,YT,WT,ct,{isNewGameDialog:8,closeNewGameDialog:9})}get isNewGameDialog(){return this.$$.ctx[8]}get closeNewGameDialog(){return this.$$.ctx[9]}}function XT(n){let t,e,r,s,i;return{c(){t=x("span"),t.textContent="a-z 0-9 @&$!?-+=.:/_",e=K(),r=x("input"),k(t,"class","symbols"),Be(t,"visibility",n[2]),k(r,"class","player-name"),k(r,"type","text"),k(r,"inputmode","url"),k(r,"placeholder","player name"),k(r,"spellcheck","false"),k(r,"maxlength","42"),k(r,"title",n[3])},m(o,l){V(o,t,l),V(o,e,l),V(o,r,l),n[5](r),wu(r,n[0]),s||(i=we(r,"input",n[6]),s=!0)},p(o,[l]){l&4&&Be(t,"visibility",o[2]),l&8&&k(r,"title",o[3]),l&1&&r.value!==o[0]&&wu(r,o[0])},i:he,o:he,d(o){o&&(F(t),F(e),F(r)),n[5](null),s=!1,i()}}}function ZT(n,t,e){let r,s;oe(n,Ct,a=>e(7,s=a));let{playerName:i=s.playerName}=t,o=null,l="hidden";function c(a=400){e(2,l="hidden"),o&&(o.classList.toggle("blink"),setTimeout(()=>o.classList.toggle("blink"),a))}function u(a){Me[a?"unshift":"push"](()=>{o=a,e(1,o)})}function f(){i=this.value,e(0,i),e(1,o)}return n.$$set=a=>{"playerName"in a&&e(0,i=a.playerName)},n.$$.update=()=>{if(n.$$.dirty&3){let a=i;e(0,i=i.toLowerCase().replace(/[^a-z0-9\@\&\$\!\?\-\+\=\.\:\/\_]/g,"")),e(2,l=a!==i?"visible":"hidden"),i===""&&o&&o.focus()}n.$$.dirty&1&&e(3,r="player name: "+i.toUpperCase())},[i,o,l,r,c,u,f]}class Wy extends Pt{constructor(t){super(),Dt(this,t,ZT,XT,ct,{playerName:0,blink:4})}get blink(){return this.$$.ctx[4]}}function Mf(n){let t,e,r,s,i,o,l,c,u,f,a,h,d,m,p,g,b,w,_,A,S,E,v,R,I,D,P,U,W,fe,N,$,ne,L;function M(z){n[10](z)}let G={};return n[3]!==void 0&&(G.playerName=n[3]),f=new Wy({props:G}),n[9](f),Me.push(()=>Gs(f,"playerName",M)),{c(){t=x("form"),e=x("div"),r=x("span"),r.textContent="options",i=K(),o=x("div"),l=K(),c=x("div"),u=x("div"),st(f.$$.fragment),h=K(),d=x("input"),m=K(),p=x("label"),p.textContent="p2p leaderboard",g=K(),b=x("input"),w=K(),_=x("label"),_.textContent="rapid mode",A=K(),S=x("input"),v=K(),R=x("label"),R.textContent="sound effects",D=K(),P=x("div"),U=x("div"),W=x("button"),W.textContent="return",k(e,"class","section-1"),k(o,"class","section-2"),k(d,"type","checkbox"),k(d,"id","leaderboard"),k(p,"for","leaderboard"),k(p,"title","for those who like to share records"),k(p,"tabindex","0"),k(p,"role","button"),k(b,"type","checkbox"),k(b,"id","rapid"),k(_,"for","rapid"),k(_,"title","pro mode w/o boring animations"),k(_,"tabindex","0"),k(_,"role","button"),k(S,"type","checkbox"),k(S,"id","sound"),S.checked=E=n[4].sound,k(R,"for","sound"),k(R,"title","auditory pleasure"),k(R,"tabindex","0"),k(R,"role","button"),k(u,"class","col"),k(c,"class","section-3"),k(W,"type","submit"),k(W,"title","return to main menu"),k(U,"class","col"),k(P,"class","section-4"),k(t,"class","options content")},m(z,ee){V(z,t,ee),T(t,e),T(e,r),T(t,i),T(t,o),T(t,l),T(t,c),T(c,u),Xe(f,u,null),T(u,h),T(u,d),d.checked=n[4].leaderboard,T(u,m),T(u,p),T(u,g),T(u,b),b.checked=n[4].rapid,T(u,w),T(u,_),T(u,A),T(u,S),T(u,v),T(u,R),T(t,D),T(t,P),T(P,U),T(U,W),$=!0,ne||(L=[we(d,"change",n[11]),we(b,"change",n[12]),we(S,"click",n[13]),we(t,"submit",jl(n[7]))],ne=!0)},p(z,ee){const ie={};!a&&ee&8&&(a=!0,ie.playerName=z[3],zs(()=>a=!1)),f.$set(ie),ee&16&&(d.checked=z[4].leaderboard),ee&16&&(b.checked=z[4].rapid),(!$||ee&16&&E!==(E=z[4].sound))&&(S.checked=E)},i(z){$||(s||Re(()=>{s=qe(r,an,{y:-48}),s.start()}),H(f.$$.fragment,z),I||Re(()=>{I=qe(c,an,{y:24}),I.start()}),fe||Re(()=>{fe=qe(W,an,{y:48}),fe.start()}),N||Re(()=>{N=qe(t,Zn,{}),N.start()}),$=!0)},o(z){re(f.$$.fragment,z),$=!1},d(z){z&&F(t),n[9](null),Ze(f),ne=!1,mt(L)}}}function jT(n){let t,e,r,s,i,o,l,c,u,f,a;return{c(){t=x("div"),e=x("p"),e.textContent="new name detected!",r=K(),s=x("p"),s.textContent="progress will be lost!",i=K(),o=x("div"),l=x("button"),l.textContent="accept",c=K(),u=x("button"),u.textContent="reject",k(o,"class","row"),k(t,"class","col exclam-fix")},m(h,d){V(h,t,d),T(t,e),T(t,r),T(t,s),T(t,i),T(t,o),T(o,l),T(o,c),T(o,u),f||(a=[we(l,"click",n[5]),we(u,"click",n[6])],f=!0)},p:he,d(h){h&&F(t),f=!1,mt(a)}}}function JT(n){let t,e,r,s,i=!n[1]&&Mf(n);function o(c){n[15](c)}let l={title:n[3],$$slots:{default:[jT]},$$scope:{ctx:n}};return n[1]!==void 0&&(l.opened=n[1]),e=new cu({props:l}),n[14](e),Me.push(()=>Gs(e,"opened",o)),{c(){i&&i.c(),t=K(),st(e.$$.fragment)},m(c,u){i&&i.m(c,u),V(c,t,u),Xe(e,c,u),s=!0},p(c,[u]){c[1]?i&&($t(),re(i,1,1,()=>{i=null}),Ht()):i?(i.p(c,u),u&2&&H(i,1)):(i=Mf(c),i.c(),H(i,1),i.m(t.parentNode,t));const f={};u&8&&(f.title=c[3]),u&262144&&(f.$$scope={dirty:u,ctx:c}),!r&&u&2&&(r=!0,f.opened=c[1],zs(()=>r=!1)),e.$set(f)},i(c){s||(H(i),H(e.$$.fragment,c),s=!0)},o(c){re(i),re(e.$$.fragment,c),s=!1},d(c){c&&F(t),i&&i.d(c),n[14](null),Ze(e,c)}}}function ek(n,t,e){let r,s,i;oe(n,Ge,S=>e(16,r=S)),oe(n,Ct,S=>e(4,s=S)),oe(n,vs,S=>e(17,i=S));let o=null,l=!1,c=null,u=s.playerName;function f(){return l}function a(){o.close(),ut(vs,i=Te.records,i),sc(u)}function h(){o.close(),e(3,u=s.playerName)}function d(){if(u==="")return c.blink();if(u===s.playerName)return ut(Ge,r=pe.menu,r);o.show()}function m(S){Me[S?"unshift":"push"](()=>{c=S,e(2,c)})}function p(S){u=S,e(3,u)}function g(){s.leaderboard=this.checked,Ct.set(s)}function b(){s.rapid=this.checked,Ct.set(s)}const w=()=>ut(Ct,s.sound=!s.sound,s);function _(S){Me[S?"unshift":"push"](()=>{o=S,e(0,o)})}function A(S){l=S,e(1,l)}return[o,l,c,u,s,a,h,d,f,m,p,g,b,w,_,A]}class tk extends Pt{constructor(t){super(),Dt(this,t,ek,JT,ct,{isDialogOpened:8})}get isDialogOpened(){return this.$$.ctx[8]}}function Of(n){let t,e,r,s,i,o,l,c,u,f,a,h,d,m,p,g,b;function w(A){n[7](A)}let _={};return n[3]!==void 0&&(_.playerName=n[3]),c=new Wy({props:_}),n[6](c),Me.push(()=>Gs(c,"playerName",w)),{c(){t=x("form"),e=x("div"),e.innerHTML="

digifall

",r=K(),s=x("div"),i=K(),o=x("div"),l=x("div"),st(c.$$.fragment),f=K(),a=x("button"),a.textContent="start",h=K(),d=x("div"),k(e,"class","section-1"),k(s,"class","section-2"),k(a,"type","submit"),k(l,"class","col"),k(o,"class","section-3"),k(d,"class","section-4"),k(t,"class","wellcome content")},m(A,S){V(A,t,S),T(t,e),T(t,r),T(t,s),T(t,i),T(t,o),T(o,l),Xe(c,l,null),T(l,f),T(l,a),T(t,h),T(t,d),p=!0,g||(b=[we(t,"input",n[4]),we(t,"submit",jl(n[5]))],g=!0)},p(A,S){const E={};!u&&S&8&&(u=!0,E.playerName=A[3],zs(()=>u=!1)),c.$set(E)},i(A){p||(H(c.$$.fragment,A),m||Re(()=>{m=qe(t,Zn,{}),m.start()}),p=!0)},o(A){re(c.$$.fragment,A),p=!1},d(A){A&&F(t),n[6](null),Ze(c),g=!1,mt(b)}}}function nk(n){let t,e,r,s,i,o,l,c;return{c(){t=x("div"),e=x("p"),e.textContent="this game doesn't contain tutorial mode!",r=K(),s=x("p"),s.textContent="the rules may not be obvious at first, but they're pretty simple!",i=K(),o=x("button"),o.textContent="continue",k(t,"class","col")},m(u,f){V(u,t,f),T(t,e),T(t,r),T(t,s),T(t,i),T(t,o),l||(c=we(o,"click",function(){On(n[0].close)&&n[0].close.apply(this,arguments)}),l=!0)},p(u,f){n=u},d(u){u&&F(t),l=!1,c()}}}function rk(n){let t,e,r,s,i=!n[1]&&Of(n);function o(c){n[9](c)}let l={title:"heads up!",$$slots:{default:[nk]},$$scope:{ctx:n}};return n[1]!==void 0&&(l.opened=n[1]),e=new cu({props:l}),n[8](e),Me.push(()=>Gs(e,"opened",o)),{c(){i&&i.c(),t=K(),st(e.$$.fragment)},m(c,u){i&&i.m(c,u),V(c,t,u),Xe(e,c,u),s=!0},p(c,[u]){c[1]?i&&($t(),re(i,1,1,()=>{i=null}),Ht()):i?(i.p(c,u),u&2&&H(i,1)):(i=Of(c),i.c(),H(i,1),i.m(t.parentNode,t));const f={};u&8193&&(f.$$scope={dirty:u,ctx:c}),!r&&u&2&&(r=!0,f.opened=c[1],zs(()=>r=!1)),e.$set(f)},i(c){s||(H(i),H(e.$$.fragment,c),s=!0)},o(c){re(i),re(e.$$.fragment,c),s=!1},d(c){c&&F(t),i&&i.d(c),n[8](null),Ze(e,c)}}}function sk(n,t,e){let r,s,i;oe(n,Ge,g=>e(10,r=g)),oe(n,Ct,g=>e(11,s=g)),oe(n,yo,g=>e(12,i=g));let o=null,l=!0,c=null,u=s.playerName;function f(){ut(yo,i=Date.now(),i),ut(Ct,s.playerName=u,s)}function a(){if(u==="")return c.blink();ut(Ge,r=null,r)}function h(g){Me[g?"unshift":"push"](()=>{c=g,e(2,c)})}function d(g){u=g,e(3,u)}function m(g){Me[g?"unshift":"push"](()=>{o=g,e(0,o)})}function p(g){l=g,e(1,l)}return[o,l,c,u,f,a,h,d,m,p]}class ik extends Pt{constructor(t){super(),Dt(this,t,sk,rk,ct,{})}}function Lf(n){let t,e,r,s,i;const o=[uk,ck,lk,ak,ok],l=[];function c(u,f){return u[4]===pe.gameOver?0:u[4]===pe.leaderboard?1:u[4]===pe.menu?2:u[4]===pe.options?3:u[4]===pe.wellcome?4:-1}return~(e=c(n))&&(r=l[e]=o[e](n)),{c(){t=x("div"),r&&r.c(),k(t,"class","overlay")},m(u,f){V(u,t,f),~e&&l[e].m(t,null),i=!0},p(u,f){let a=e;e=c(u),e===a?~e&&l[e].p(u,f):(r&&($t(),re(l[a],1,1,()=>{l[a]=null}),Ht()),~e?(r=l[e],r?r.p(u,f):(r=l[e]=o[e](u),r.c()),H(r,1),r.m(t,null)):r=null)},i(u){i||(H(r),u&&Re(()=>{i&&(s||(s=vu(t,pi,{duration:200},!0)),s.run(1))}),i=!0)},o(u){re(r),u&&(s||(s=vu(t,pi,{duration:200},!1)),s.run(0)),i=!1},d(u){u&&F(t),~e&&l[e].d(),u&&s&&s.end()}}}function ok(n){let t,e;return t=new ik({}),{c(){st(t.$$.fragment)},m(r,s){Xe(t,r,s),e=!0},p:he,i(r){e||(H(t.$$.fragment,r),e=!0)},o(r){re(t.$$.fragment,r),e=!1},d(r){Ze(t,r)}}}function ak(n){let t,e,r={};return t=new tk({props:r}),n[15](t),{c(){st(t.$$.fragment)},m(s,i){Xe(t,s,i),e=!0},p(s,i){const o={};t.$set(o)},i(s){e||(H(t.$$.fragment,s),e=!0)},o(s){re(t.$$.fragment,s),e=!1},d(s){n[15](null),Ze(t,s)}}}function lk(n){let t,e,r={};return t=new QT({props:r}),n[14](t),{c(){st(t.$$.fragment)},m(s,i){Xe(t,s,i),e=!0},p(s,i){const o={};t.$set(o)},i(s){e||(H(t.$$.fragment,s),e=!0)},o(s){re(t.$$.fragment,s),e=!1},d(s){n[14](null),Ze(t,s)}}}function ck(n){let t,e,r={};return t=new VT({props:r}),n[13](t),{c(){st(t.$$.fragment)},m(s,i){Xe(t,s,i),e=!0},p(s,i){const o={};t.$set(o)},i(s){e||(H(t.$$.fragment,s),e=!0)},o(s){re(t.$$.fragment,s),e=!1},d(s){n[13](null),Ze(t,s)}}}function uk(n){let t,e,r;function s(o){n[12](o)}let i={};return n[3]!==void 0&&(i.scoreComponent=n[3]),t=new Nb({props:i}),Me.push(()=>Gs(t,"scoreComponent",s)),{c(){st(t.$$.fragment)},m(o,l){Xe(t,o,l),r=!0},p(o,l){const c={};!e&&l&8&&(e=!0,c.scoreComponent=o[3],zs(()=>e=!1)),t.$set(c)},i(o){r||(H(t.$$.fragment,o),r=!0)},o(o){re(t.$$.fragment,o),r=!1},d(o){Ze(t,o)}}}function hk(n){let t,e,r=n[4]&&Lf(n);return{c(){r&&r.c(),t=Hs()},m(s,i){r&&r.m(s,i),V(s,t,i),e=!0},p(s,[i]){s[4]?r?(r.p(s,i),i&16&&H(r,1)):(r=Lf(s),r.c(),H(r,1),r.m(t.parentNode,t)):r&&($t(),re(r,1,1,()=>{r=null}),Ht())},i(s){e||(H(r),e=!0)},o(s){re(r),e=!1},d(s){s&&F(t),r&&r.d(s)}}}function fk({node:n,selectors:t,shift:e=0}={}){if(!t||t.length<1)return;const r=t.map(l=>".overlay "+l).join(", "),s=Array.from(document.querySelectorAll(r));if(!n)return s.at(e<0?e:0);if(e===0)return n;const i=s.indexOf(n);if(i===-1)return s.at(e<0?e:0);let o=i+e;return o<0&&(o=s.length+o),o>s.length-1&&(o=o-s.length),s[o]}function dk(n,t,e){let r,s;oe(n,Ge,v=>e(4,r=v)),oe(n,er,v=>e(17,s=v));let i=null,o=null,l=null,c=null,u=null;async function f(){if(await v0(),o&&o.isNewGameDialog())return o.closeNewGameDialog();ut(Ge,r=r===null?pe.menu:r===pe.menu?null:r===pe.leaderboard||r===pe.options?pe.menu:null,r)}function a(){w(-1)}function h(){w(1)}function d(){if(r===pe.leaderboard)return u?u.classList.contains("type")?u.click():u.classList.contains("pages")?i.prevPage():null:void 0;(r!==pe.options||l.isDialogOpened())&&w(-1)}function m(){if(r===pe.leaderboard)return u?u.classList.contains("type")?u.click():u.classList.contains("pages")?i.nextPage():null:void 0;(r!==pe.options||l.isDialogOpened())&&w(-1)}function p(){u&&(c&&c.isFocused()?c.nextType():u.classList.contains("focus")&&u.click())}function g(){if(u&&u.blur(),r===pe.options||r===pe.leaderboard||r===pe.gameOver)return ut(Ge,r=pe.menu,r);if(r===pe.menu&&s!==X.gameOver)return ut(Ge,r=null,r)}function b(v){if(v){if(c&&c.isFocused()&&c.blur(),u&&(u.classList.remove("focus"),u.blur()),v.classList.contains("score"))return c&&c.focus();u=v,u.classList.add("focus"),u.focus()}}function w(v){const R=["button:not(.digifall)","[role='button']","input:not([type='checkbox'])"],I=R.map(U=>".overlay "+U+".focus").join(", "),D=document.querySelector(I),P=fk({node:D,selectors:R,shift:v});b(P)}function _(v){c=v,e(3,c)}function A(v){Me[v?"unshift":"push"](()=>{i=v,e(0,i)})}function S(v){Me[v?"unshift":"push"](()=>{o=v,e(1,o)})}function E(v){Me[v?"unshift":"push"](()=>{l=v,e(2,l)})}return[i,o,l,c,r,f,a,h,d,m,p,g,_,A,S,E]}class pk extends Pt{constructor(t){super(),Dt(this,t,dk,hk,ct,{switchOverlay:5,moveUp:6,moveDown:7,moveLeft:8,moveRight:9,perfomAction:10,blur:11})}get switchOverlay(){return this.$$.ctx[5]}get moveUp(){return this.$$.ctx[6]}get moveDown(){return this.$$.ctx[7]}get moveLeft(){return this.$$.ctx[8]}get moveRight(){return this.$$.ctx[9]}get perfomAction(){return this.$$.ctx[10]}get blur(){return this.$$.ctx[11]}}function gk(n){let t,e,r,s,i,o,l,c={};e=new kb({props:c}),n[6](e);let u={};return s=new pk({props:u}),n[7](s),{c(){t=x("div"),st(e.$$.fragment),r=K(),st(s.$$.fragment),k(t,"class","app")},m(f,a){V(f,t,a),Xe(e,t,null),T(t,r),Xe(s,t,null),i=!0,o||(l=we(window,"keydown",n[2]),o=!0)},p(f,[a]){const h={};e.$set(h);const d={};s.$set(d)},i(f){i||(H(e.$$.fragment,f),H(s.$$.fragment,f),i=!0)},o(f){re(e.$$.fragment,f),re(s.$$.fragment,f),i=!1},d(f){f&&F(t),n[6](null),Ze(e),n[7](null),Ze(s),o=!1,l()}}}function el(){const{style:n,offsetHeight:t,offsetWidth:e}=document.documentElement,i=t/e<1.5?t/192:e/128,o=i%.25;n.setProperty("font-size",i-o+"px")}function mk(n){document.documentElement.classList[n?"add":"remove"]("random-color")}function yk(n,t,e){let r,s,i,o;oe(n,Ge,h=>e(3,r=h)),oe(n,Oi,h=>e(8,s=h)),oe(n,er,h=>e(4,i=h)),oe(n,ta,h=>e(5,o=h));let l=null,c=null;Eu>0&&setTimeout(()=>location=location,Eu*1e3),onstorage=function(){document.hasFocus()||(document.location=document.location)},el(),onresize=el,document.addEventListener("visibilitychange",el);function u(h){const d=r===null?l:c;switch(h.code){case"Escape":return h.preventDefault(),d.blur();case"Tab":return h.preventDefault(),!s||r===pe.wellcome||r===pe.gameOver?void 0:c.switchOverlay();case"ArrowUp":return d.moveUp();case"ArrowDown":return d.moveDown();case"ArrowLeft":return d.moveLeft();case"ArrowRight":return d.moveRight();case"Enter":case"Space":case"KeyF":case"KeyJ":return d.perfomAction()}}function f(h){Me[h?"unshift":"push"](()=>{l=h,e(0,l)})}function a(h){Me[h?"unshift":"push"](()=>{c=h,e(1,c)})}return n.$$.update=()=>{n.$$.dirty&16&&i===X.gameOver&&ut(Ge,r=pe.gameOver,r),n.$$.dirty&56&&mk(o.value>100||i===X.extra||i===X.combo||r===pe.leaderboard||r===pe.gameOver)},[l,c,u,r,i,o,f,a]}class bk extends Pt{constructor(t){super(),Dt(this,t,yk,gk,ct,{})}}Yd($r,ub);new bk({target:document.body}); diff --git a/index.html b/index.html index 8093801..18aaa52 100644 --- a/index.html +++ b/index.html @@ -46,7 +46,7 @@ gtag("js", new Date()); gtag("config", "G-KK6TCRZ4TJ"); - +