@rel-packages/osu-beatmap-preview 0.11.5 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/default_skin_archive.d.ts +1 -1
- package/dist/{chunk-zc79wdxj.js → chunk-029sagwa.js} +2 -2
- package/dist/{chunk-fsbv6vcn.js → chunk-0we37sfj.js} +2 -2
- package/dist/chunk-1d7vwgnw.js +15 -0
- package/dist/chunk-3baewprq.js +1 -0
- package/dist/{chunk-0e4ebmdy.js → chunk-3wjb2nvs.js} +2 -2
- package/dist/{chunk-pn7re3na.js → chunk-598ehnf5.js} +2 -2
- package/dist/{chunk-sngkm5ds.js → chunk-8wvq4dfz.js} +2 -2
- package/dist/{chunk-rp8z1jh7.js → chunk-aeeawe99.js} +2 -2
- package/dist/chunk-amhps2v2.js +1 -0
- package/dist/chunk-bxvb53d0.js +1 -0
- package/dist/{chunk-dvctxyxp.js → chunk-cs4e65d1.js} +1 -1
- package/dist/chunk-d7xgaxzy.js +1 -0
- package/dist/chunk-gsjxh2hw.js +1 -0
- package/dist/chunk-hbfgn274.js +1 -0
- package/dist/{chunk-kkmq6cvb.js → chunk-jyb1nvnr.js} +2 -2
- package/dist/chunk-n2mqbpq5.js +11 -0
- package/dist/chunk-p0te881m.js +1 -0
- package/dist/{chunk-5v6x1wpn.js → chunk-shgm3fs6.js} +2 -2
- package/dist/{chunk-1sw3e1ar.js → chunk-sqnzgty6.js} +5 -5
- package/dist/{chunk-h72ajp0p.js → chunk-tj1dwy5a.js} +1 -1
- package/dist/{chunk-eb5gmq04.js → chunk-tqbn5m4a.js} +2 -2
- package/dist/{chunk-edbhr7zr.js → chunk-vkkhj28s.js} +2 -2
- package/dist/chunk-w1tshfsy.js +2 -0
- package/dist/chunk-xtab1dnq.js +1 -0
- package/dist/{chunk-a7wf9wxx.js → chunk-z898rh1p.js} +3 -3
- package/dist/config/standard.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/parser/osz_loader.d.ts.map +1 -1
- package/dist/player/audio_engine.d.ts +93 -0
- package/dist/player/audio_engine.d.ts.map +1 -0
- package/dist/player/player.d.ts +6 -15
- package/dist/player/player.d.ts.map +1 -1
- package/dist/player/player_hitsound.d.ts +20 -3
- package/dist/player/player_hitsound.d.ts.map +1 -1
- package/dist/renderer/backend/pixi_backend.d.ts +12 -0
- package/dist/renderer/backend/pixi_backend.d.ts.map +1 -1
- package/dist/renderer/backend/render_backend.d.ts +1 -0
- package/dist/renderer/backend/render_backend.d.ts.map +1 -1
- package/dist/renderer/drawable/drawable_slider.d.ts +2 -0
- package/dist/renderer/drawable/drawable_slider.d.ts.map +1 -1
- package/dist/renderer/mania/mania_renderer.d.ts +11 -0
- package/dist/renderer/mania/mania_renderer.d.ts.map +1 -1
- package/dist/renderer/standard/standard_renderer.d.ts +3 -1
- package/dist/renderer/standard/standard_renderer.d.ts.map +1 -1
- package/dist/renderer/standard/timing_state.d.ts +1 -0
- package/dist/renderer/standard/timing_state.d.ts.map +1 -1
- package/dist/utils/lru.d.ts +32 -0
- package/dist/utils/lru.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-21p7cseg.js +0 -1
- package/dist/chunk-525kvqgh.js +0 -1
- package/dist/chunk-5evxnj3k.js +0 -9
- package/dist/chunk-7qazncxz.js +0 -15
- package/dist/chunk-ay0z741j.js +0 -1
- package/dist/chunk-ef1ghrsq.js +0 -1
- package/dist/chunk-f3y92gm3.js +0 -1
- package/dist/chunk-kmf5rpya.js +0 -1
- package/dist/chunk-kt3t4zv0.js +0 -2
- package/dist/chunk-shb5s568.js +0 -1
- package/dist/chunk-tb8nqrjk.js +0 -1
- package/dist/player/audio_controller.d.ts +0 -31
- package/dist/player/audio_controller.d.ts.map +0 -1
- package/dist/player/audio_node_controller.d.ts +0 -8
- package/dist/player/audio_node_controller.d.ts.map +0 -1
- package/dist/player/hitsound_controller.d.ts +0 -21
- package/dist/player/hitsound_controller.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-7qazncxz.js";import"./chunk-5v6x1wpn.js";import"./chunk-zc79wdxj.js";import"./chunk-edbhr7zr.js";import"./chunk-eb5gmq04.js";import{v as zt}from"./chunk-ef1ghrsq.js";import{D as je,z as Mt}from"./chunk-a7wf9wxx.js";import{Y as rt,Z as Pe,_ as qt,aa as ct}from"./chunk-kt3t4zv0.js";import"./chunk-5evxnj3k.js";import"./chunk-kkmq6cvb.js";import"./chunk-fsbv6vcn.js";import"./chunk-rp8z1jh7.js";import"./chunk-pn7re3na.js";import"./chunk-0e4ebmdy.js";import"./chunk-sngkm5ds.js";import{Ja as Q,Ka as X,Qa as Z,Sa as Gt,Ua as Kt,Ya as Xt,cb as Zt,hb as B,ib as mt}from"./chunk-1sw3e1ar.js";import{xb as ot}from"./chunk-dvctxyxp.js";var Ut;((i)=>{i[i.Standard=0]="Standard";i[i.Taiko=1]="Taiko";i[i.Catch=2]="Catch";i[i.Mania=3]="Mania"})(Ut||={});var $t;((i)=>{i[i.Auto=0]="Auto";i[i.Normal=1]="Normal";i[i.Soft=2]="Soft";i[i.Drum=3]="Drum"})($t||={});var P={Circle:1,Slider:2,NewCombo:4,Spinner:8,ComboSkip:112,Hold:128},wt={Normal:1,Whistle:2,Finish:4,Clap:8},Yt=(t)=>(t.type&P.Circle)!==0,et=(t)=>(t.type&P.Slider)!==0,j=(t)=>(t.type&P.Spinner)!==0,Wt=(t)=>(t.type&P.Hold)!==0,Te=(t)=>(t.type&P.NewCombo)!==0;var Re;((c)=>{c.NoOsuFiles="NO_OSU_FILES";c.DifficultyNotFound="DIFFICULTY_NOT_FOUND";c.InvalidBeatmap="INVALID_BEATMAP";c.UnsupportedMode="UNSUPPORTED_MODE";c.AudioNotLoaded="AUDIO_NOT_LOADED";c.AudioDecodeError="AUDIO_DECODE_ERROR";c.NotLoaded="NOT_LOADED";c.Unknown="UNKNOWN"})(Re||={});var De=(t)=>({success:!0,data:t}),U=(t,e)=>({success:!1,code:t,reason:e}),$n=(t)=>{if(t.success)return t.data;throw Error(`[${t.code}] ${t.reason}`)},Yn=(t)=>{return t.success},Wn=(t)=>{return!t.success};var g={None:0,NoFail:1,Easy:2,TouchDevice:4,Hidden:8,HardRock:16,SuddenDeath:32,DoubleTime:64,Relax:128,HalfTime:256,Nightcore:512,Flashlight:1024,Autoplay:2048,SpunOut:4096,Autopilot:8192,Perfect:16384,FadeIn:8388608,Mirror:1073741824},br=g.DoubleTime|g.HalfTime|g.Nightcore,Jn=g.HardRock|g.Easy|br,qn=(t)=>{let e=0,r=t.toLowerCase(),n={nf:g.NoFail,ez:g.Easy,td:g.TouchDevice,hd:g.Hidden,hr:g.HardRock,sd:g.SuddenDeath,dt:g.DoubleTime,rx:g.Relax,ht:g.HalfTime,nc:g.Nightcore,fl:g.Flashlight,at:g.Autoplay,so:g.SpunOut,ap:g.Autopilot,pf:g.Perfect,fi:g.FadeIn,mr:g.Mirror};for(let i=0;i<r.length-1;i+=2){let s=r.slice(i,i+2);if(n[s])e|=n[s]}return e},Gn=(t)=>{let e=[];if(t&g.NoFail)e.push("NF");if(t&g.Easy)e.push("EZ");if(t&g.Hidden)e.push("HD");if(t&g.HardRock)e.push("HR");if(t&g.SuddenDeath)e.push("SD");if(t&g.DoubleTime)e.push("DT");if(t&g.HalfTime)e.push("HT");if(t&g.Nightcore)e.push("NC");if(t&g.Flashlight)e.push("FL");if(t&g.SpunOut)e.push("SO");if(t&g.FadeIn)e.push("FI");if(t&g.Mirror)e.push("MR");let r=e.indexOf("DT"),n=e.indexOf("NC");if(r>=0&&n>=0)e.splice(r,1);return e.join("")},Ae=(t)=>{if(t&(g.DoubleTime|g.Nightcore))return 1.5;if(t&g.HalfTime)return 0.75;return 1},gr=[g.HardRock|g.Easy,g.DoubleTime|g.HalfTime|g.Nightcore,g.Hidden|g.FadeIn],Kn=(t,e)=>{if(t&e)return t&~e;let r=t;for(let n of gr)if(e&n)r&=~n;return r|e},E=(t,e)=>(t&e)!==0,Xn=(t)=>{let e=[{name:"Easy",acronym:"EZ",value:g.Easy},{name:"Hidden",acronym:"HD",value:g.Hidden},{name:"Double Time",acronym:"DT",value:g.DoubleTime},{name:"Half Time",acronym:"HT",value:g.HalfTime},{name:"Nightcore",acronym:"NC",value:g.Nightcore}];switch(t){case"standard":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock}];case"mania":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock},{name:"Fade In",acronym:"FI",value:g.FadeIn}];case"taiko":case"catch":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock}];default:return e}};import{init_wasm as Ee,parse as He}from"@rel-packages/osu-beatmap-parser/browser";import Oe from"jszip";class st{async load_osz(t,e){await Ee();let r=await Oe.loadAsync(t),n=new Map;for(let[i,s]of Object.entries(r.files))if(!s.dir)n.set(i,await s.async("arraybuffer"));return this.load_from_files(n,e)}async load_from_files(t,e){await Ee();let r=[...t.keys()].filter((f)=>f.toLowerCase().endsWith(".osu"));if(r.length===0)throw Error("No .osu files found in beatmap");let n=await Promise.all(r.map(async(f)=>{let b=t.get(f),y=this.to_bytes(b),w=await He(y);return{filename:f,beatmap:w}})),i=this.select_difficulty(r,n,e?.difficulty),s=t.get(i),a=this.to_bytes(s),o=await He(a),c=o.General.AudioFilename||null,h=o.Events.background?.filename||null,_=o.Events.video?.filename||null,l=o.Events.video?.startTime??0,d=new Map;for(let[f,b]of t)if(b instanceof ArrayBuffer)d.set(f,b);else d.set(f,new TextEncoder().encode(b).buffer);let u;if(c)u=this.find_file(d,c);let p;if(h){let f=this.find_file(d,h);if(f)p=new Blob([f])}let m;if(_){let f=this.find_file(d,_);if(f)m=new Blob([f])}return{beatmap:o,available_difficulties:n,files:d,audio:u,background:p,video:m,audio_filename:c??void 0,background_filename:h??void 0,video_filename:_??void 0,video_offset:_?l:void 0}}async list_difficulties(t){let e=await Oe.loadAsync(t),r=[];for(let i of Object.keys(e.files))if(i.toLowerCase().endsWith(".osu"))r.push(i);let n=[];for(let i of r){let a=(await e.files[i].async("string")).match(/Version:\s*(.+)/);n.push(a?a[1].trim():i)}return n}select_difficulty(t,e,r){if(r===void 0)return t[0];if(typeof r==="number"){if(r<0||r>=t.length)throw Error(`Difficulty index ${r} out of range (0-${t.length-1})`);return t[r]}let n=e.find((a)=>a.beatmap.Metadata.Version===r);if(n)return n.filename;let i=r.toLowerCase(),s=e.find((a)=>a.filename.toLowerCase().includes(i)||a.beatmap.Metadata.Version.toLowerCase().includes(i));if(s)return s.filename;throw Error(`Difficulty "${r}" not found`)}find_file(t,e){if(t.has(e))return t.get(e);let r=e.toLowerCase();for(let[n,i]of t)if(n.toLowerCase()===r)return i;return}to_bytes(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);return new TextEncoder().encode(t)}}import{init_wasm as mr,parse as Cn}from"@rel-packages/osu-beatmap-parser/browser";var Qt=512,Jt=384,Ne;((s)=>{s[s.None=0]="None";s[s.Large=32]="Large";s[s.Medium=16]="Medium";s[s.Small=8]="Small";s[s.Tiny=4]="Tiny"})(Ne||={});var K={offset_x:64,offset_y:48,scale:1,show_playfield:!0,playfield_color:"#ffffff",playfield_opacity:0.1,grid_level:0,grid_color:"#ffffff",grid_opacity:0.35,use_high_dpi:!0,enable_stacking:!0};class at{backend;skin;config;mods;skin_elements;beatmap;objects=[];background_image=null;constructor(t,e,r=0,n=K,i=null){this.backend=t,this.skin=e,this.mods=r,this.config={...K,...n},this.skin_elements=i}set_background(t){this.background_image=t}update_config(t){this.config={...this.config,...t}}precompute(t=0){}on_seek(t){}dispose(){this.objects=[]}render_playfield(t,e,r,n){if(!this.config.show_playfield)return;let{backend:i,config:s}=this,a=t??512,o=e??384,c=r??0,h=n??0;i.save(),i.set_alpha(s.playfield_opacity),i.begin_path(),i.move_to(c,h),i.line_to(c+a,h),i.line_to(c+a,h+o),i.line_to(c,h+o),i.line_to(c,h),i.stroke_path(s.playfield_color,2),i.restore()}render_grid(){if(this.config.grid_level===0)return;let{backend:t,config:e}=this,r=e.grid_level;t.save(),t.set_alpha(e.grid_opacity);for(let n=0;n<=512;n+=r)t.begin_path(),t.move_to(n,0),t.line_to(n,384),t.stroke_path(e.grid_color,n%(r*4)===0?1:0.5);for(let n=0;n<=384;n+=r)t.begin_path(),t.move_to(0,n),t.line_to(512,n),t.stroke_path(e.grid_color,n%(r*4)===0?1:0.5);t.restore()}render_background(){if(!this.background_image)return;let{backend:t}=this;t.save(),t.set_alpha(0.3);let{width:e,height:r}=t,{width:n,height:i}=this.background_image;if(n>0&&i>0){let s=Math.max(e/n,r/i),a=n*s,o=i*s,c=(e-a)/2,h=(r-o)/2;t.draw_image(this.background_image,c,h,a,o)}else t.draw_image(this.background_image,0,0,e,r);t.restore()}get_visible_objects(t,e,r){let n=[];for(let i=0;i<this.objects.length;i++){let s=this.objects[i],a=s.time-e,o=s.end_time+r;if(t>=a&&t<=o)n.push(s)}return n}}var Se={extension:{type:Q.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await import("./chunk-ay0z741j.js")}};var Ce={extension:{type:Q.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await import("./chunk-shb5s568.js")}};var kt;function Le(t){if(kt!==void 0)return kt;return kt=(()=>{let e={stencil:!0,failIfMajorPerformanceCaveat:t??Mt.defaultOptions.failIfMajorPerformanceCaveat};try{if(!mt.get().getWebGLRenderingContext())return!1;let n=mt.get().createCanvas().getContext("webgl",e),i=!!n?.getContextAttributes()?.stencil;if(n){let s=n.getExtension("WEBGL_lose_context");if(s)s.loseContext()}return n=null,i}catch(r){return!1}})(),kt}var It;async function Be(t={}){if(It!==void 0)return It;return It=await(async()=>{let e=mt.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(t)).requestDevice(),!0}catch(r){return!1}})(),It}var Fe=["webgl","webgpu","canvas"];async function Ve(t){let e=[];if(t.preference)e.push(t.preference),Fe.forEach((s)=>{if(s!==t.preference)e.push(s)});else e=Fe.slice();let r,n={};for(let s=0;s<e.length;s++){let a=e[s];if(a==="webgpu"&&await Be()){let{WebGPURenderer:o}=await import("./chunk-525kvqgh.js");r=o,n={...t,...t.webgpu};break}else if(a==="webgl"&&Le(t.failIfMajorPerformanceCaveat??Mt.defaultOptions.failIfMajorPerformanceCaveat)){let{WebGLRenderer:o}=await import("./chunk-21p7cseg.js");r=o,n={...t,...t.webgl};break}else if(a==="canvas"){let{CanvasRenderer:o}=await import("./chunk-kmf5rpya.js");r=o,n={...t,...t.canvasOptions};break}}if(delete n.webgpu,delete n.webgl,delete n.canvasOptions,!r)throw Error("No available renderer for the current environment");let i=new r;return await i.init(n),i}class Tt{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){if(globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e)globalThis.addEventListener("resize",this.queueResize),this.resize()},get(){return this._resizeTo}}),this.queueResize=()=>{if(!this._resizeTo)return;this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize())},this._cancelResize=()=>{if(this._resizeId)cancelAnimationFrame(this._resizeId),this._resizeId=null},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,r;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,r=globalThis.innerHeight;else{let{clientWidth:n,clientHeight:i}=this._resizeTo;e=n,r=i}this.renderer.resize(e,r),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Tt.extension=Q.Application;class Rt{static init(t){if(t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){if(this._ticker)this._ticker.remove(this.render,this);if(this._ticker=e,e)e.add(this.render,this,Pe.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?qt.shared:new qt,t.autoStart)this.start()}static destroy(){if(this._ticker){let t=this._ticker;this.ticker=null,t.destroy()}}}Rt.extension=Q.Application;X.add(Tt);X.add(Rt);var Ue=class t{constructor(...e){if(this.stage=new rt,e[0]!==void 0)Kt(Gt,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new rt),this.renderer=await Ve(e),t._plugins.forEach((r)=>{r.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return Kt(Gt,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,r=!1){let n=t._plugins.slice(0);n.reverse(),n.forEach((i)=>{i.destroy.call(this)}),this.stage.destroy(r),this.stage=null,this.renderer.destroy(e),this.renderer=null}};Ue._plugins=[];var Dt=Ue;X.handleByList(Q.Application,Dt._plugins);X.add(je);X.add(Se,Ce);var yr={color:16777215,alpha:1};class At{app=null;root=null;state;stack=[];texture_cache=new Map;gradient_texture_cache=new Map;text_texture_cache=new Map;_width=0;_height=0;_dpr=1;is_initialized=!1;context_lost_listener=null;context_restored_listener=null;get width(){return this._width}get height(){return this._height}async initialize(t,e=!0){this.dispose(),this.ensure_sprite_texture_limit(),this._dpr=e?window.devicePixelRatio||1:1;let r=t.clientWidth||t.width,n=t.clientHeight||t.height,i=new Dt;await i.init({canvas:t,width:r,height:n,backgroundAlpha:0,antialias:!0,autoDensity:!0,resolution:this._dpr,clearBeforeRender:!0}),i.ticker.stop(),this.app=i,Zt.defaultOptions.scaleMode="linear";let s=this.app.canvas;this.context_lost_listener=(a)=>{a.preventDefault()},this.context_restored_listener=()=>{this.ensure_sprite_texture_limit()},s.addEventListener("webglcontextlost",this.context_lost_listener,{passive:!1}),s.addEventListener("webglcontextrestored",this.context_restored_listener),this.root=new rt,this.app.stage.addChild(this.root),this._width=r,this._height=n,this.reset_state(),this.is_initialized=!0}begin_frame(){this.clear()}end_frame(){if(!this.app)return;this.app.renderer.render(this.app.stage)}clear(){if(!this.root)return;let t=this.root.removeChildren();for(let e=0;e<t.length;e++)t[e].destroy({children:!0});this.reset_state()}resize(t,e){if(!this.app)return;this._width=t,this._height=e,this._dpr=window.devicePixelRatio||1,this.app.renderer.resolution=this._dpr,this.app.renderer.resize(t,e)}dispose(){if(this.clear_texture_caches(),this.app){let t=this.app.canvas;if(this.context_lost_listener)t.removeEventListener("webglcontextlost",this.context_lost_listener);if(this.context_restored_listener)t.removeEventListener("webglcontextrestored",this.context_restored_listener);this.app.destroy(!1,{children:!0,texture:!0,textureSource:!0}),this.app=null}this.root=null,this.stack=[],this.is_initialized=!1,this.context_lost_listener=null,this.context_restored_listener=null}draw_circle(t,e,r,n,i,s){let a=this.make_graphics(),o=$(n),c=$(i);if(a.circle(t,e,r),n&&n!=="transparent"&&o.alpha>0)a.fill({color:o.color,alpha:o.alpha*this.state.alpha});if(i&&s&&s>0&&c.alpha>0)a.stroke({width:s,color:c.color,alpha:c.alpha*this.state.alpha})}draw_arc(t,e,r,n,i,s,a,o=!1){let c=this.make_graphics(),h=$(s);c.arc(t,e,r,n,i,o),c.stroke({width:a,color:h.color,alpha:h.alpha*this.state.alpha})}draw_rect(t,e,r,n,i){let s=this.make_graphics(),a=$(i);s.rect(t,e,r,n),s.fill({color:a.color,alpha:a.alpha*this.state.alpha})}draw_rect_gradient(t,e,r,n,i){let s=this.get_or_create_gradient_texture(t,e,r,n,i),a=new ct(s);a.alpha=this.state.alpha,a.blendMode=this.state.blend_mode,a.setFromMatrix(this.compose_matrix(t,e,r/s.width,n/s.height)),this.state.container.addChild(a)}create_linear_gradient(t,e,r,n,i){return{type:"linear_gradient",x0:t,y0:e,x1:r,y1:n,stops:i}}draw_text(t,e,r,n,i,s="left",a="alphabetic"){let o=$(i),c=this.get_or_create_text_texture(t,n,o),h=new ct(c.texture);h.alpha=o.alpha*this.state.alpha,h.blendMode=this.state.blend_mode;let _=0;switch(s){case"center":_=0.5;break;case"right":case"end":_=1;break;default:_=0;break}let l=0;switch(a){case"top":case"hanging":l=0;break;case"middle":l=0.5;break;case"bottom":case"ideographic":l=1;break;default:l=c.ascent/Math.max(1,c.height);break}h.anchor.set(_,l),h.setFromMatrix(this.compose_matrix(e,r,1/c.resolution,1/c.resolution)),this.state.container.addChild(h)}begin_path(){this.state.path=[]}move_to(t,e){this.state.path.push({type:"move",x:t,y:e})}line_to(t,e){this.state.path.push({type:"line",x:t,y:e})}draw_line(t,e,r,n,i,s){let a=this.make_graphics(),o=$(i);a.moveTo(t,e),a.lineTo(r,n),a.stroke({width:s,color:o.color,alpha:o.alpha*this.state.alpha})}bezier_curve_to(t,e,r,n,i,s){let o=this.get_last_path_point();if(!o)return;for(let c=1;c<=24;c++){let h=c/24,_=1-h,l=_*_*_*o.x+3*_*_*h*t+3*_*h*h*r+h*h*h*i,d=_*_*_*o.y+3*_*_*h*e+3*_*h*h*n+h*h*h*s;this.state.path.push({type:"line",x:l,y:d})}}quadratic_curve_to(t,e,r,n){let s=this.get_last_path_point();if(!s)return;for(let a=1;a<=20;a++){let o=a/20,c=1-o,h=c*c*s.x+2*c*o*t+o*o*r,_=c*c*s.y+2*c*o*e+o*o*n;this.state.path.push({type:"line",x:h,y:_})}}arc_to(t,e,r,n,i,s=!1){this.state.path.push({type:"arc",x:t,y:e,radius:r,start:n,end:i,ccw:s})}rect(t,e,r,n){this.state.path.push({type:"rect",x:t,y:e,width:r,height:n})}clip(){if(!this.root||this.state.path.length===0)return;let t=this.make_graphics();this.apply_path(t,this.state.path);let e=new rt;e.mask=t,this.state.container.addChild(t),this.state.container.addChild(e),this.state.container=e,this.state.path=[]}stroke_path(t,e,r="butt",n="miter"){let i=this.make_graphics(),s=$(t);this.apply_path(i,this.state.path),i.stroke({width:e,color:s.color,alpha:s.alpha*this.state.alpha})}fill_path(t){let e=this.make_graphics(),r=$(t);this.apply_path(e,this.state.path),e.fill({color:r.color,alpha:r.alpha*this.state.alpha})}close_path(){this.state.path.push({type:"close"})}save(){this.stack.push({matrix:this.state.matrix.clone(),alpha:this.state.alpha,blend_mode:this.state.blend_mode,container:this.state.container,path:this.state.path.slice()})}restore(){let t=this.stack.pop();if(!t)return;this.state=t}translate(t,e){let r=new Z;r.translate(t,e),this.state.matrix.append(r)}scale(t,e){let r=new Z;r.scale(t,e),this.state.matrix.append(r)}rotate(t){let e=new Z;e.rotate(t),this.state.matrix.append(e)}set_alpha(t){this.state.alpha=t}set_shadow(t,e){}set_composite_operation(t){this.state.blend_mode=Rr(t)}set_blend_mode(t){switch(t){case"lighter":this.state.blend_mode="add";return;case"multiply":this.state.blend_mode="multiply";return;case"screen":this.state.blend_mode="screen";return;default:this.state.blend_mode="normal";return}}draw_image(t,e,r,n,i,s){let a=this.get_texture(t.source);if(!a)return;let o=new ct(a);if(o.alpha=this.state.alpha,o.blendMode=this.state.blend_mode,s){let d=$(s);o.tint=d.color,o.alpha*=d.alpha}let c=n??t.width??a.width,h=i??t.height??a.height,_=c/Math.max(1,a.width),l=h/Math.max(1,a.height);o.setFromMatrix(this.compose_matrix(e,r,_,l)),this.state.container.addChild(o)}draw_image_part(t,e,r,n,i,s,a,o,c){let h=this.get_texture(t.source);if(!h)return;let _=new B({source:h.source,frame:new Xt(e,r,n,i)}),l=new ct(_);l.alpha=this.state.alpha,l.blendMode=this.state.blend_mode,l.setFromMatrix(this.compose_matrix(s,a,o/Math.max(1,n),c/Math.max(1,i))),this.state.container.addChild(l)}render_slider_to_image(t,e,r,n,i,s=1,a=1,o=null){if(!this.app||t.length<2)return null;let c=xr(t);if(c.length<2)return null;let h=wr(c,Math.max(0.02,e*0.001)),_=1/0,l=1/0,d=-1/0,u=-1/0;for(let k=0;k<h.length;k++){let I=h[k];if(I[0]<_)_=I[0];if(I[0]>d)d=I[0];if(I[1]<l)l=I[1];if(I[1]>u)u=I[1]}let p=1,m=e*p+2;_-=m,l-=m,d+=m,u+=m;let f=Math.ceil((d-_)*i),b=Math.ceil((u-l)*i);if(f<=0||b<=0)return null;let y=-_,w=-l,D=$(r),O=$(n),R=e*0.9;return{source:this.render_slider_canvas_fallback(h,y,w,e*p,R,D,O,i,s,a,o,f,b),width:f,height:b,min_x:_,min_y:l}}render_slider_canvas_fallback(t,e,r,n,i,s,a,o,c,h,_,l,d){let u=Math.max(1,l),p=Math.max(1,d),m=document.createElement("canvas");m.width=u,m.height=p;let f=m.getContext("2d");if(!f)return B.WHITE;f.save(),f.imageSmoothingEnabled=!0,f.imageSmoothingQuality="high",f.scale(o,o),f.translate(e,r),f.lineCap="round",f.lineJoin="round";let b=kr(t),y=()=>{if(b){f.stroke(b);return}f.beginPath(),f.moveTo(t[0][0],t[0][1]);for(let S=1;S<t.length;S++)f.lineTo(t[S][0],t[S][1]);f.stroke()},w={color:a.color,alpha:0.5*c},D={color:s.color,alpha:s.alpha*h},O={color:0,alpha:0.25*h},R=Ir(w,0.1),M=Tr(w,0.22),k=0.078125,I=0.1875,C=(S)=>{let L=ee(S);if(L<=k)return Ye({color:0,alpha:0},O,L/Math.max(0.000001,k));if(L<=I)return D;let W=(L-I)/Math.max(0.000001,1-I),tt=Math.pow(ee(W),1.35);return Ye(R,M,tt)},x=Math.max(1,Math.floor(t.length/140)),T=Math.max(52,Math.min(76,Math.floor(72/x)));f.globalAlpha=1,f.globalCompositeOperation="source-over";for(let S=1;S<=T;S++){let L=S/T,W=n*2*L,tt=1-L,it=C(tt);if(f.strokeStyle=$e(it),f.lineWidth=Math.max(0.5,W),y(),S===1)f.globalCompositeOperation="destination-over"}return f.globalCompositeOperation="source-over",f.restore(),B.from(m)}reset_state(){if(!this.root)return;this.state={matrix:new Z,alpha:1,blend_mode:"normal",container:this.root,path:[]},this.stack=[]}make_graphics(){let t=new zt;return t.blendMode=this.state.blend_mode,t.setFromMatrix(this.state.matrix),this.state.container.addChild(t),t}apply_path(t,e){for(let r=0;r<e.length;r++){let n=e[r];switch(n.type){case"move":t.moveTo(n.x,n.y);break;case"line":t.lineTo(n.x,n.y);break;case"arc":t.arc(n.x,n.y,n.radius,n.start,n.end,n.ccw);break;case"rect":t.rect(n.x,n.y,n.width,n.height);break;case"close":t.closePath();break}}}compose_matrix(t,e,r=1,n=1){let i=this.state.matrix.clone(),s=new Z;if(s.translate(t,e),i.append(s),r!==1||n!==1){let a=new Z;a.scale(r,n),i.append(a)}return i}get_last_path_point(){for(let t=this.state.path.length-1;t>=0;t--){let e=this.state.path[t];if(e.type==="move"||e.type==="line")return{x:e.x,y:e.y}}return null}get_texture(t){if(!t)return null;if(t instanceof B)return t;let e=this.texture_cache.get(t);if(e)return e;let r=B.from(t);return this.texture_cache.set(t,r),r}get_or_create_gradient_texture(t,e,r,n,i){let s=JSON.stringify({x:t,y:e,width:r,height:n,gradient:i}),a=this.gradient_texture_cache.get(s);if(a)return a;let o=document.createElement("canvas");o.width=Math.max(1,Math.ceil(r)),o.height=Math.max(1,Math.ceil(n));let c=o.getContext("2d");if(!c)return B.WHITE;let h=c.createLinearGradient(i.x0-t,i.y0-e,i.x1-t,i.y1-e);for(let l=0;l<i.stops.length;l++)h.addColorStop(i.stops[l].offset,i.stops[l].color);c.fillStyle=h,c.fillRect(0,0,o.width,o.height);let _=B.from(o);return this.gradient_texture_cache.set(s,_),_}get_or_create_text_texture(t,e,r){let n=`${t}|${e}|${r.color}`,i=this.text_texture_cache.get(n);if(i)return i;let s=vr(e),a=Math.min(6,Math.max(2,this._dpr*3)),o=document.createElement("canvas"),c=o.getContext("2d");if(!c)return{texture:B.WHITE,width:1,height:1,ascent:1,descent:0,resolution:1};c.font=s.css;let h=c.measureText(t),_=Math.max(1,Math.ceil(h.width||s.size)),l=Math.max(1,Math.ceil(h.actualBoundingBoxAscent||s.size*0.8)),d=Math.max(0,Math.ceil(h.actualBoundingBoxDescent||s.size*0.2)),u=Math.max(1,l+d),p=Math.max(2,Math.ceil(s.size*0.25)),m=_+p*2,f=u+p*2;o.width=Math.ceil(m*a),o.height=Math.ceil(f*a),c.setTransform(1,0,0,1,0,0),c.clearRect(0,0,o.width,o.height),c.scale(a,a),c.font=s.css,c.fillStyle=$e(r),c.textAlign="center",c.textBaseline="middle",c.fillText(t,m/2,f/2);let y={texture:B.from(o),width:m,height:f,ascent:f/2,descent:f/2,resolution:a};return this.text_texture_cache.set(n,y),y}clear_texture_caches(){for(let t of this.texture_cache.values()){if(t===B.WHITE)continue;t.destroy(!0)}this.texture_cache.clear();for(let t of this.gradient_texture_cache.values())t.destroy(!0);this.gradient_texture_cache.clear();for(let t of this.text_texture_cache.values())if(t.texture!==B.WHITE)t.texture.destroy(!0);this.text_texture_cache.clear()}ensure_sprite_texture_limit(){}}var vr=(t)=>{let e=t.trim().split(/\s+/),r=14,n="normal",i=-1;for(let o=0;o<e.length;o++)if(e[o].endsWith("px")){r=Number.parseFloat(e[o].replace("px","")),i=o;break}if(i>0)n=e[i-1];let s=i>=0?e.slice(i+1).join(" "):'"Trebuchet MS", Verdana, Arial, sans-serif';return{css:`${n} ${Number.isFinite(r)?r:14}px ${s||'"Trebuchet MS", Verdana, Arial, sans-serif'}`,size:Number.isFinite(r)?r:14}},$=(t)=>{if(!t||t==="transparent")return{color:16777215,alpha:0};let e=t.trim().toLowerCase();if(e.startsWith("#")){let n=e.slice(1);if(n.length===3){let i=Number.parseInt(n[0]+n[0],16),s=Number.parseInt(n[1]+n[1],16),a=Number.parseInt(n[2]+n[2],16);return{color:i<<16|s<<8|a,alpha:1}}if(n.length===6||n.length===8){let i=Number.parseInt(n.slice(0,6),16);if(n.length===8){let s=Number.parseInt(n.slice(6,8),16)/255;return{color:i,alpha:s}}return{color:i,alpha:1}}}let r=e.match(/^rgba?\(([^)]+)\)$/);if(r){let n=r[1].split(",").map((i)=>i.trim());if(n.length>=3){let i=te(Number.parseFloat(n[0])),s=te(Number.parseFloat(n[1])),a=te(Number.parseFloat(n[2])),o=n.length>=4?ee(Number.parseFloat(n[3])):1;return{color:i<<16|s<<8|a,alpha:o}}}if(e==="white")return{color:16777215,alpha:1};if(e==="black")return{color:0,alpha:1};return yr},$e=(t)=>{let e=t.color>>16&255,r=t.color>>8&255,n=t.color&255;return`rgba(${e},${r},${n},${t.alpha})`},xr=(t)=>{if(t.length<=2)return t;let e=[t[0]],r=0.000000000001;for(let n=1;n<t.length;n++){let i=e[e.length-1],s=t[n],a=s[0]-i[0],o=s[1]-i[1];if(a*a+o*o<=r)continue;e.push(s)}if(e.length<2)return[t[0],t[t.length-1]];return e},wr=(t,e)=>{if(t.length<=2)return t;let r=[t[0]],n=e*e;for(let a=1;a<t.length-1;a++){let o=r[r.length-1],c=t[a],h=t[a+1],_=c[0]-o[0],l=c[1]-o[1],d=_*_+l*l;if(d<n)continue;let u=c[0]-o[0],p=c[1]-o[1],m=h[0]-c[0],f=h[1]-c[1],b=Math.hypot(u,p),y=Math.hypot(m,f);if(b>0&&y>0){if((u*m+p*f)/(b*y)>0.9985&&d<n*4)continue}r.push(c)}let i=t[t.length-1],s=r[r.length-1];if(s[0]!==i[0]||s[1]!==i[1])r.push(i);return r.length>=2?r:[t[0],i]},kr=(t)=>{if(typeof Path2D>"u"||t.length<2)return null;let e=new Path2D;e.moveTo(t[0][0],t[0][1]);for(let r=1;r<t.length;r++)e.lineTo(t[r][0],t[r][1]);return e},Mr=(t,e,r)=>{let n=Math.max(0,Math.min(1,r)),i=t.color>>16&255,s=t.color>>8&255,a=t.color&255,o=e>>16&255,c=e>>8&255,h=e&255,_=Math.round(i+(o-i)*n),l=Math.round(s+(c-s)*n),d=Math.round(a+(h-a)*n);return{color:_<<16|l<<8|d,alpha:t.alpha}},Ye=(t,e,r)=>{let n=Math.max(0,Math.min(1,r)),i=t.color>>16&255,s=t.color>>8&255,a=t.color&255,o=e.color>>16&255,c=e.color>>8&255,h=e.color&255,_=Math.round(i+(o-i)*n),l=Math.round(s+(c-s)*n),d=Math.round(a+(h-a)*n);return{color:_<<16|l<<8|d,alpha:t.alpha+(e.alpha-t.alpha)*n}},Ir=(t,e)=>Mr(t,0,e),Tr=(t,e)=>{let r=Math.max(0,e*0.5),n=t.color>>16&255,i=t.color>>8&255,s=t.color&255,a=Math.min(255,Math.round(n*(1+0.5*r)+255*r)),o=Math.min(255,Math.round(i*(1+0.5*r)+255*r)),c=Math.min(255,Math.round(s*(1+0.5*r)+255*r));return{color:a<<16|o<<8|c,alpha:t.alpha}},ee=(t)=>{if(!Number.isFinite(t))return 1;if(t<0)return 0;if(t>1)return 1;return t},te=(t)=>{if(!Number.isFinite(t))return 0;if(t<0)return 0;if(t>255)return 255;return Math.round(t)},Rr=(t)=>{switch(t){case"lighter":return"add";case"multiply":return"multiply";case"screen":return"screen";default:return"normal"}};var re=(t)=>{return new At};var ne={min:1800,mid:1200,max:450};var Dr=(t,e)=>{if(t>5)return e.mid+(e.max-e.mid)*(t-5)/5;if(t<5)return e.mid+(e.mid-e.min)*(t-5)/5;return e.mid},We=(t,e)=>{if(Math.sign(t-e.mid)===Math.sign(e.max-e.mid))return(t-e.mid)/(e.max-e.mid)*5+5;return(t-e.mid)/(e.mid-e.min)*5+5},Et=(t)=>Dr(t,ne),Qe=(t)=>400*Math.min(1,t/450),Ar=(t)=>{return(1-0.7*((t-5)/5))/2*1.00041},Je=(t)=>Ar(t)*64;var ie={name:"Hard Rock",acronym:"HR",apply_to_difficulty(t){t.cs=Math.min(t.cs*1.3,10),t.ar=Math.min(t.ar*1.4,10),t.od=Math.min(t.od*1.4,10),t.hp=Math.min(t.hp*1.4,10)}};var se={name:"Easy",acronym:"EZ",apply_to_difficulty(t){t.cs*=0.5,t.ar*=0.5,t.od*=0.5,t.hp*=0.5}};var Er={name:"Double Time",acronym:"DT",get_rate_multiplier:()=>1.5},Hr={name:"Nightcore",acronym:"NC",get_rate_multiplier:()=>1.5};var Or={name:"Half Time",acronym:"HT",get_rate_multiplier:()=>0.75};var Nr=0.4,Sr=0.3,Cr={name:"Hidden",acronym:"HD"};var Lr=(t)=>{if(t&(g.DoubleTime|g.Nightcore))return 1.5;if(t&g.HalfTime)return 0.75;return 1},Br=(t,e)=>{if(e&g.Easy)se.apply_to_difficulty(t);if(e&g.HardRock)ie.apply_to_difficulty(t)},Fr=(t,e)=>{if(e===1)return t;let r=Et(t)/e;return We(r,ne)},qe=(t,e,r,n,i)=>{let s={cs:t,ar:e,od:r,hp:n};Br(s,i);let a=Lr(i);return s.ar=Fr(s.ar,a),s};var z=(t,e)=>[t[0]+e[0],t[1]+e[1]],V=(t,e)=>[t[0]-e[0],t[1]-e[1]],Ge=(t,e)=>[t[0]*e,t[1]*e];var Y=(t)=>Math.sqrt(t[0]*t[0]+t[1]*t[1]);var Ht=(t,e)=>Y(V(t,e));var nt=(t,e,r)=>t+(e-t)*r,J=(t,e,r)=>[nt(t[0],e[0],r),nt(t[1],e[1],r)],v=(t,e,r)=>Math.min(r,Math.max(e,t));var ae={1:["#d5bc00"],2:["#ffffff","#ffffff"],3:["#ffffff","#d5bc00","#ffffff"],4:["#ffffff","#dc8dba","#dc8dba","#ffffff"],5:["#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff"],6:["#ffffff","#dc8dba","#ffffff","#ffffff","#dc8dba","#ffffff"],7:["#ffffff","#dc8dba","#ffffff","#d5bc00","#ffffff","#dc8dba","#ffffff"],8:["#d5bc00","#ffffff","#dc8dba","#ffffff","#d5bc00","#ffffff","#dc8dba","#ffffff"],9:["#ffffff","#dc8dba","#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff","#dc8dba","#ffffff"],10:["#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff","#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff"]},oe={legacy_version:2.7,combo_colors:["0,185,0","7, 105, 227","224, 4, 38","227, 171, 2"],circle_border_width:0.12,hit_circle_opacity:1,hit_circle_overlay_above_number:!0,hit_circle_prefix:"default",hit_circle_overlap:-2,enable_approach_circle:!0,approach_circle_width:0.1,approach_circle_opacity:0.5,approach_circle_use_combo_color:!0,enable_hitburst:!0,hitburst_duration:180,hitburst_scale:1.2,hitburst_glow_enabled:!1,hitburst_glow_use_combo_color:!0,hitburst_glow_opacity:0.3,slider_body_opacity:0.9,slider_border_opacity:1,slider_tick_opacity:0.75,slider_tick_size:0.1,slider_render_scale:2,follow_circle_factor:1.5,follow_circle_width:4,follow_circle_opacity:0.5,follow_circle_color:"#d3d3d3ff",follow_circle_use_combo_color:!1,slider_ball_color:"#ffffff",slider_ball_opacity:1,enable_slider_ball:!0,slider_ball_flip:!1,allow_slider_ball_tint:!0,slider_ball_frames:10,animation_framerate:-1,follow_point_width:2,follow_point_shape:"line",follow_point_mode:"full",follow_point_length:12,follow_point_line_gap:0,spinner_size:180,spinner_center_size:10,spinner_background_color:"rgba(100,100,100,1)",mania_lane_width:30,mania_note_height:15,mania_hit_position:364,mania_lane_spacing:1,mania_lane_colors:ae,default_font:'"Trebuchet MS", Verdana, Arial, sans-serif',hit_animation_duration:240,hit_animation_scale:1.2,enable_hit_animations:!0,enable_follow_circle_animations:!0},ce=(t)=>{if(!t)return{...oe};return{...oe,...t,mania_lane_colors:t.mania_lane_colors?{...ae,...t.mania_lane_colors}:ae}},q=(t,e,r=1)=>{let n=t.combo_colors[e%t.combo_colors.length];return Vr(n,r)},ht=(t,e,r)=>{let n=t.mania_lane_colors[e]??t.mania_lane_colors[4];return n[r%n.length]??"#ffffff"},Vr=(t,e)=>{let r=t.trim();if(r.includes(",")&&!r.startsWith("rgb"))return`rgba(${r},${e})`;let n=r.match(/^rgb\(([^)]+)\)$/i);if(n)return`rgba(${n[1]},${e})`;let i=r.match(/^rgba\(([^)]+)\)$/i);if(i){let s=i[1].split(",").map((a)=>a.trim());if(s.length>=3)return`rgba(${s[0]},${s[1]},${s[2]},${e})`}if(r.startsWith("#")){let s=r.slice(1);if(s.length===3){let a=Number.parseInt(s[0]+s[0],16),o=Number.parseInt(s[1]+s[1],16),c=Number.parseInt(s[2]+s[2],16);return`rgba(${a},${o},${c},${e})`}if(s.length===6||s.length===8){let a=Number.parseInt(s.slice(0,2),16),o=Number.parseInt(s.slice(2,4),16),c=Number.parseInt(s.slice(4,6),16);return`rgba(${a},${o},${c},${e})`}}return r};var A={None:(t)=>t,Out:(t)=>1-Math.pow(1-t,2),In:(t)=>t*t,InOut:(t)=>t<0.5?2*t*t:1-Math.pow(-2*t+2,2)/2,OutCubic:(t)=>1-Math.pow(1-t,3),InCubic:(t)=>t*t*t,OutQuad:(t)=>1-Math.pow(1-t,2),InQuad:(t)=>t*t,OutQuint:(t)=>1-Math.pow(1-t,5),InQuint:(t)=>t*t*t*t*t,OutElastic:(t)=>{let e=2*Math.PI/3;return t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-0.75)*e)+1}};class he{transforms=[];add(t,e,r,n,i,s=A.None){return this.transforms.push({property:t,start_value:e,end_value:r,start_time:n,end_time:n+i,easing:s}),this}then(){return this}get_value(t,e,r){let n=r;for(let i of this.transforms){if(i.property!==t)continue;if(e<i.start_time)continue;if(e>=i.end_time)n=i.end_value;else{let s=(e-i.start_time)/(i.end_time-i.start_time),a=i.easing(s);n=i.start_value+(i.end_value-i.start_value)*a}}return n}clear(){this.transforms=[]}}class _t{backend;skin;hit_object;config;alpha=1;scale=1;rotation=0;x=0;y=0;armed_state=0;transforms=new he;life_time_start=0;life_time_end=0;constructor(t,e){this.hit_object=t,this.config=e,this.backend=e.backend,this.skin=e.skin;let r=t.data;this.x=r.pos[0],this.y=r.pos[1],this.apply_defaults()}apply_defaults(){let{hit_object:t,config:e}=this,r=t.time-e.preempt;this.life_time_start=r,this.life_time_end=t.end_time+800}is_alive(t){return t>=this.life_time_start&&t<=this.life_time_end}update(t){this.alpha=this.transforms.get_value("alpha",t,1),this.scale=this.transforms.get_value("scale",t,1),this.rotation=this.transforms.get_value("rotation",t,0),this.update_state(t)}update_state(t){if(this.armed_state===0&&t>=this.hit_object.time)this.armed_state=1,this.on_hit(t)}on_hit(t){}render_body_pass(t){}render_head_pass(t){}dispose(){}get start_time(){return this.hit_object.time}get end_time(){return this.hit_object.end_time}get combo_number(){return this.hit_object.combo_number??0}get combo_count(){return this.hit_object.combo_count??1}get position(){return[this.x,this.y]}}var _e=1.04;class ft{state={circle_alpha:0,circle_scale:1,number_alpha:1};update(t,e,r){let n=e-r.preempt;if(t<n){this.reset_pre_hit_state();return}if(t<e){this.update_pre_hit(t,n,e,r);return}let i=Ot(e,n,e,r);this.update_post_hit(t,e,r,i)}render(t,e,r,n,i,s,a,o,c=!0,h=!0){let{circle_alpha:_,circle_scale:l,number_alpha:d}=this.state;if(_<=0.01)return;if(_>0.01){t.set_alpha(_*e.hit_circle_opacity);let u=o?.circle??a?.hitcircle,p=o?.overlay??a?.hitcircleoverlay,m=e.hit_circle_overlay_above_number,f=!!u;if(u){let b=n*2*l*_e;t.draw_image(u,r[0]-b/2,r[1]-b/2,b,b,i)}else{let b=n*e.circle_border_width*l,y=n*(1-e.circle_border_width/2)*l;t.draw_circle(r[0],r[1],y,i,"rgba(255,255,255,1)",b)}if(h&&!m&&p&&f){t.set_alpha(_*e.hit_circle_opacity);let b=n*2*l*_e;t.draw_image(p,r[0]-b/2,r[1]-b/2,b,b)}if(c&&d>0.01){if(t.set_alpha(d*e.hit_circle_opacity),!Pr(t,r,n,l,s,a)){let y=n*0.7*l,w=e.default_font??'"Trebuchet MS", Verdana, Arial, sans-serif',D=`600 ${y}px ${w}`;t.draw_text(String(s),r[0],r[1],D,"rgba(255,255,255,1)","center","middle")}}if(h&&m&&p&&f){t.set_alpha(_*e.hit_circle_opacity);let b=n*2*l*_e;t.draw_image(p,r[0]-b/2,r[1]-b/2,b,b)}t.set_alpha(1)}t.set_alpha(1)}get circle_alpha(){return this.state.circle_alpha}reset_pre_hit_state(){this.state.circle_alpha=0,this.state.circle_scale=1,this.state.number_alpha=1}update_pre_hit(t,e,r,n){let i=Ot(t,e,r,n);this.state.circle_alpha=i,this.state.circle_scale=1,this.state.number_alpha=i}update_post_hit(t,e,r,n){let i=t-e,{skin:s}=r,a=Math.max(110,s.hit_animation_duration*0.62),o=v(i/a,0,1),c=E(r.mods,g.Hidden)?v(n,0,1):v(Math.max(n,0.25),0,1);this.state.circle_alpha=c*(1-A.OutQuad(o)),this.state.circle_scale=nt(1,Math.max(s.hit_animation_scale,1.34),A.OutCubic(o)),this.state.number_alpha=this.state.circle_alpha*(1-0.55*o)}}var Ot=(t,e,r,n)=>{let s=v((t-e)/n.fade_in,0,1);if(E(n.mods,g.Hidden)){let a=r-n.preempt+n.fade_in,o=n.preempt*0.3;if(t>a){let c=v((t-a)/o,0,1);s*=1-c}}return s},Pr=(t,e,r,n,i,s)=>{let a=s?.combo_digits;if(!a||a.length<10)return!1;let o=String(i),c=128,h=0.8,_=r*2/c*h*n,l=(s?.combo_overlap??-2)*_,d=[],u=[],p=0;for(let f=0;f<o.length;f++){let b=o.charCodeAt(f)-48,y=a[b];if(!y||y.height<=0)return!1;let w=y.width*_,D=y.height*_;if(d.push(w),u.push(D),p+=w,f<o.length-1)p-=l}let m=e[0]-p/2;for(let f=0;f<o.length;f++){let b=o.charCodeAt(f)-48,y=a[b],w=d[f],D=u[f],O=e[1]-D/2;if(t.draw_image(y,m,O,w,D),m+=w,f<o.length-1)m-=l}return!0};var jr=0.8;class de{state={alpha:0,scale:1};update(t,e,r){if(!r.skin.enable_hitburst){this.state.alpha=0,this.state.scale=1;return}if(t<e){this.state.alpha=0,this.state.scale=1;return}let n=e-r.preempt,i=Ot(e,n,e,r),s=E(r.mods,g.Hidden)?v(i,0,1):v(Math.max(i,0.25),0,1),a=t-e,o=Math.max(44,r.skin.hitburst_duration*0.52),c=v(a/o,0,1),h=1-A.OutQuint(c),_=Math.max(24,o*0.3),l=v(a/_,0,1),d=A.OutQuad(l)*h;this.state.alpha=E(r.mods,g.Hidden)?d*s*0.78:d*0.78;let u=Math.max(1,r.skin.hitburst_scale*jr),p=Math.max(24,o*0.2),m=Math.min(1.06,u);if(a<=p){let f=v(a/p,0,1);this.state.scale=nt(0.96,m,A.OutCubic(f))}else{let f=v((a-p)/Math.max(1,o-p),0,1);this.state.scale=nt(m,u,A.OutCubic(f))}}render(t,e,r,n,i){if(!e.enable_hitburst)return;if(this.state.alpha<=0.01)return;if(t.set_alpha(this.state.alpha),t.draw_circle(r[0],r[1],n*this.state.scale,"rgba(255,255,255,1)","transparent",0),e.hitburst_glow_enabled){t.save(),t.set_blend_mode("lighter"),t.set_alpha(this.state.alpha*e.hitburst_glow_opacity);let s=e.hitburst_glow_use_combo_color?i:e.hitburst_glow_color??i;t.draw_circle(r[0],r[1],n*this.state.scale*1.08,s,"transparent",0),t.restore()}}}class Nt extends _t{visual=new ft;hitburst=new de;constructor(t,e){super(t,e)}update(t){super.update(t),this.visual.update(t,this.hit_object.time,this.config),this.hitburst.update(t,this.hit_object.time,this.config)}render(t){let{backend:e,skin:r,config:n}=this,{radius:i}=n,s=this.position,a=q(r,this.combo_number,1);this.visual.render(e,r,s,i,a,this.combo_count,n.skin_elements,void 0,!0,!1),this.hitburst.render(e,r,s,i,a)}}var St=(t)=>{let{start_time:e,span_duration:r,span_count:n,length:i,tick_distance:s,min_distance_from_end:a,get_position_at_progress:o}=t,c=[],h=[];if(i<=0||r<=0||n<=0)return{ticks:c,repeats:h};let l=Math.min(1e5,i),d=Math.min(Math.max(s,0),l),u=Math.max(0,Math.min(a,l));for(let p=0;p<n;p++){let m=e+p*r,f=p%2===1;if(d>0){let b=Ur(p,m,r,f,l,d,u,o);if(f)b.reverse();c.push(...b)}if(p<n-1){let b=(p+1)%2;h.push({pos:o(b),time:m+r,repeat_index:p,path_progress:b})}}return c.sort((p,m)=>p.time-m.time),{ticks:c,repeats:h}},Ur=(t,e,r,n,i,s,a,o)=>{let c=[];for(let h=s;h<=i;h+=s){if(h>=i-a)break;let _=h/i,l=n?1-_:_;c.push({pos:o(_),time:e+l*r,span_index:t,path_progress:_})}return c};var pe=(t,e=0.05)=>{if(t.length<2)return[...t];let r=[];return le(t,r,e),r},le=(t,e,r)=>{if($r(t,r)){if(e.length===0)e.push(t[0]);e.push(t[t.length-1]);return}let n=[],i=[];Wr(t,n,i),le(n,e,r),le(i,e,r)},$r=(t,e)=>{if(t.length<=2)return!0;let r=t[0],n=t[t.length-1];for(let i=1;i<t.length-1;i++)if(Yr(t[i],r,n)>e)return!1;return!0},Yr=(t,e,r)=>{let n=r[0]-e[0],i=r[1]-e[1],s=n*n+i*i;if(s===0){let h=t[0]-e[0],_=t[1]-e[1];return Math.hypot(h,_)}let a=Math.max(0,Math.min(1,((t[0]-e[0])*n+(t[1]-e[1])*i)/s)),o=e[0]+a*n,c=e[1]+a*i;return Math.hypot(t[0]-o,t[1]-c)},Wr=(t,e,r)=>{let n=t.length,i=[t];for(let s=1;s<n;s++){i[s]=[];for(let a=0;a<n-s;a++)i[s][a]=J(i[s-1][a],i[s-1][a+1],0.5)}for(let s=0;s<n;s++)e.push(i[s][0]),r.push(i[n-1-s][s])},ue=(t,e,r)=>{let n=V(e,t),i=Y(n);if(i===0)return[t];let s=[n[0]/i,n[1]/i],a=z(t,Ge(s,r));return[t,a]},Ke=(t,e)=>{if(t.length!==3)return pe(t);let[r,n,i]=t,s=Qr(r,n,i);if(!s)return ue(r,i,e);let a=Y(V(r,s)),o=Math.atan2(r[1]-s[1],r[0]-s[0]),c=Math.atan2(i[1]-s[1],i[0]-s[0]),_=(n[0]-r[0])*(i[1]-r[1])-(n[1]-r[1])*(i[0]-r[0])>0,l=c-o;if(_&&l<0)l+=2*Math.PI;if(!_&&l>0)l-=2*Math.PI;let d=2;if(a*2>0.1){let p=Math.abs(l),m=2*Math.acos(1-0.1/a);if(d=Math.max(2,Math.ceil(p/m)),d>=1000)d=1000}let u=[];for(let p=0;p<=d;p++){let m=p/d,f=o+l*m;u.push([s[0]+a*Math.cos(f),s[1]+a*Math.sin(f)])}return u},Qr=(t,e,r)=>{let n=2*(t[0]*(e[1]-r[1])+e[0]*(r[1]-t[1])+r[0]*(t[1]-e[1]));if(Math.abs(n)<0.001)return null;let i=((t[0]*t[0]+t[1]*t[1])*(e[1]-r[1])+(e[0]*e[0]+e[1]*e[1])*(r[1]-t[1])+(r[0]*r[0]+r[1]*r[1])*(t[1]-e[1]))/n,s=((t[0]*t[0]+t[1]*t[1])*(r[0]-e[0])+(e[0]*e[0]+e[1]*e[1])*(t[0]-r[0])+(r[0]*r[0]+r[1]*r[1])*(e[0]-t[0]))/n;return[i,s]},Xe=(t)=>{if(t.length<2)return[...t];let e=[];for(let r=0;r<t.length-1;r++){let n=t[Math.max(0,r-1)],i=t[r],s=t[r+1],a=t[Math.min(t.length-1,r+2)],o=Y(V(s,i)),c=Math.max(6,Math.ceil(o/4));for(let h=0;h<=c;h++){let _=h/c;e.push(Jr(n,i,s,a,_))}}return e},Jr=(t,e,r,n,i)=>{let s=i*i,a=s*i;return[0.5*(2*e[0]+(-t[0]+r[0])*i+(2*t[0]-5*e[0]+4*r[0]-n[0])*s+(-t[0]+3*e[0]-3*r[0]+n[0])*a),0.5*(2*e[1]+(-t[1]+r[1])*i+(2*t[1]-5*e[1]+4*r[1]-n[1])*s+(-t[1]+3*e[1]-3*r[1]+n[1])*a)]};var Ze=(t)=>{let e;if(t.path_type==="L")e=ue(t.pos,t.control_points[0],t.distance);else{let r=[t.pos,...t.control_points];switch(t.path_type){case"P":e=Ke(r,t.distance);break;case"C":e=Xe(r);break;default:e=qr(r);break}}return Gr(e,t.distance)},ze=(t)=>{if(!t.computed_path||t.computed_path.length===0)return t.pos;return t.repetitions%2===0?t.pos:t.computed_path[t.computed_path.length-1]},qr=(t)=>{let e=[],r=[t[0]];for(let i=1;i<t.length;i++){let[s,a]=[t[i-1],t[i]];if(s[0]===a[0]&&s[1]===a[1]){if(r.length>1)e.push(r);r=[a]}else r.push(a)}if(r.length>1)e.push(r);let n=[];for(let i=0;i<e.length;i++){let s=pe(e[i]);if(s.length===0)continue;if(n.length>0){let a=n[n.length-1],o=s[0];if(a[0]===o[0]&&a[1]===o[1]){for(let c=1;c<s.length;c++)n.push(s[c]);continue}}for(let a=0;a<s.length;a++)n.push(s[a])}return n},Gr=(t,e)=>{if(t.length<2)return t;let r=[t[0]],n=0,i=null,s=!1;for(let a=1;a<t.length;a++){let o=Y(V(t[a],t[a-1])),c=V(t[a],t[a-1]);if(o>0)i=[c[0]/o,c[1]/o];if(o===0)continue;if(n+o>=e){let h=e-n;r.push(J(t[a-1],t[a],h/o)),n=e,s=!0;break}n+=o,r.push(t[a])}if(!s&&n<e&&i){let a=e-n,o=r[r.length-1];r.push([o[0]+i[0]*a,o[1]+i[1]*a])}return r};var me=240,fe=1.3,be=35,Kr=250,Xr=300,bt=150,Zr=bt*4,tr=0.96;class gt extends _t{slider_data;position_path;render_path;path_length;span_duration;body_alpha=0;head_visual=new ft;ball_alpha=0;ball_position;ball_reverse=!1;slider_ball_frame_delay=16.666666666666668;follow_alpha=0;follow_scale=1;ticks=[];repeats=[];tick_distance;min_distance_from_end;cached_texture=null;cached_scale=1;tick_entries=[];tick_entries_by_start=[];nested_objects_built=!1;path_ready=!1;constructor(t,e,r,n,i,s){super(t,e);this.slider_data=t.data;let a=Math.max(1,e.radius*0.03),o=r.length>1?this.resample_path(r,a):[];this.position_path=o,this.render_path=o,this.span_duration=n,this.tick_distance=i,this.min_distance_from_end=s;let c=o.length>1?this.calculate_path_length():0;this.path_length=this.slider_data.distance>0?this.slider_data.distance:c,this.ball_position=this.slider_data.pos,this.slider_ball_frame_delay=this.compute_slider_ball_frame_delay(),this.path_ready=o.length>1,this.life_time_end=t.end_time+me}build_nested_objects(){let{slider_data:t,path_length:e,span_duration:r,hit_object:n}=this,i=Math.max(1,t.repetitions),s=1e5,a=Math.min(1e5,t.distance>0?t.distance:e),o=v(this.tick_distance,0,a);if(a<=0||r<=0){this.ticks=[],this.repeats=[];return}let c=St({start_time:n.time,span_duration:r,span_count:i,length:a,tick_distance:o,min_distance_from_end:this.min_distance_from_end,get_position_at_progress:(h)=>this.get_position_at_progress(h)});this.ticks=c.ticks,this.repeats=c.repeats,this.build_tick_entries()}calculate_path_length(){let t=0;for(let e=1;e<this.position_path.length;e++)t+=Y(V(this.position_path[e],this.position_path[e-1]));return t}resample_path(t,e){if(t.length<2)return t.slice();let r=[t[0]],n=0,i=[];for(let _=1;_<t.length;_++){let l=Y(V(t[_],t[_-1]));i.push(l),n+=l}if(n<=0)return r;let s=e,a=0,o=0;while(s<n&&o<i.length){let _=i[o],l=t[o],d=t[o+1];if(_>0&&a+_>=s){let u=(s-a)/_;r.push(J(l,d,u)),s+=e}else a+=_,o++}let c=t[t.length-1],h=r[r.length-1];if(h[0]!==c[0]||h[1]!==c[1])r.push(c);return r}update(t){if(super.update(t),!this.path_ready&&t>=this.hit_object.time-this.config.preempt-300)this.ensure_path_ready();if(!this.nested_objects_built&&t>=this.hit_object.time-this.config.preempt-250)this.ensure_path_ready(),this.build_nested_objects(),this.nested_objects_built=!0;this.calculate_ball_position(t),this.calculate_opacities(t),this.head_visual.update(t,this.hit_object.time,this.config)}calculate_ball_position(t){let{hit_object:e,span_duration:r}=this,n=300,i=300,s=2.4;if(t<e.time){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}if(t<=e.end_time){if(!this.path_ready){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}let h=t-e.time,_=Math.max(1,this.slider_data.repetitions),l=Math.min(Math.floor(h/r),_-1),d=v((h-l*r)/r,0,1),u=l%2===1?1-d:d;this.ball_reverse=l%2===1,this.ball_position=this.get_position_at_progress(u),this.ball_alpha=1;let p=v(h/300,0,1),m=A.OutQuint(p);this.follow_alpha=m,this.follow_scale=1+1.4*m;return}let a=t-e.end_time,o=v(a/300,0,1),c=A.OutQuint(o);this.ball_alpha=1-c,this.follow_alpha=1-c,this.follow_scale=2.4-1.4*c}get_position_at_progress(t){if(!this.path_ready)return this.slider_data.pos;let e=t*this.path_length;return this.get_position_at_length(e)}get_position_at_length(t){if(!this.path_ready||this.position_path.length===0)return this.slider_data.pos;let e=0;for(let r=1;r<this.position_path.length;r++){let n=Y(V(this.position_path[r],this.position_path[r-1]));if(e+n>=t){let i=(t-e)/n;return J(this.position_path[r-1],this.position_path[r],i)}e+=n}return this.position_path[this.position_path.length-1]}calculate_opacities(t){let{hit_object:e,config:r}=this,n=e.time-r.preempt,i=e.time;if(E(r.mods,g.Hidden)){let s=i-r.preempt+r.fade_in;if(t<n)this.body_alpha=0;else if(t<s)this.body_alpha=v((t-n)/r.fade_in,0,1);else if(t<=e.end_time){let a=Math.max(1,e.end_time-s);this.body_alpha=1-v((t-s)/a,0,1)}else this.body_alpha=0}else if(t<n)this.body_alpha=0;else if(t<i)this.body_alpha=v((t-n)/r.fade_in,0,1);else if(t<=e.end_time)this.body_alpha=1;else this.body_alpha=1-v((t-e.end_time)/me,0,1)}compute_slider_ball_frame_delay(){if(this.skin.animation_framerate>0)return 1000/this.skin.animation_framerate;let t=this.path_length/Math.max(1,this.span_duration),e=16.666666666666668;if(t<=0)return e;return Math.max(0.15/t*e,e)}render(t){if(this.body_alpha<=0&&this.head_visual.circle_alpha<=0&&this.ball_alpha<=0)return;this.render_body(t),this.render_head(),this.render_ball(t)}render_body_pass(t){this.render_body(t)}render_head_pass(t){this.render_head(),this.render_reverse_arrows(t),this.render_ball(t)}render_body(t){if(this.body_alpha<=0.01)return;if(this.ensure_path_ready(),this.render_path.length<2)return;let{backend:e}=this;if(this.prepare_body_cache(),this.cached_texture&&this.cached_texture.min_x!==void 0&&this.cached_texture.min_y!==void 0){let r=this.cached_scale;e.set_alpha(this.body_alpha),e.draw_image(this.cached_texture,this.cached_texture.min_x,this.cached_texture.min_y,this.cached_texture.width/r,this.cached_texture.height/r),e.set_alpha(1)}else this.render_live_body_fallback();this.render_ticks(t)}render_live_body_fallback(){if(this.render_path.length<2)return;let{backend:t,config:e,skin:r}=this,n=r.slider_border_color??"rgba(255,255,255,1)",i=r.slider_track_override??q(r,this.combo_number,1),s=e.radius*2,a=e.radius*1.8;this.build_live_body_path(),t.save(),t.set_alpha(this.body_alpha*r.slider_border_opacity),t.stroke_path(n,s,"round","round"),t.restore(),this.build_live_body_path(),t.save(),t.set_alpha(this.body_alpha*r.slider_body_opacity),t.stroke_path(i,a,"round","round"),t.restore()}build_live_body_path(){let{backend:t}=this;t.begin_path(),t.move_to(this.render_path[0][0],this.render_path[0][1]);for(let e=1;e<this.render_path.length;e++)t.line_to(this.render_path[e][0],this.render_path[e][1])}prepare_body_cache(){if(this.ensure_path_ready(),this.render_path.length<2)return;let{backend:t,skin:e,config:r}=this,{radius:n}=r,i=Math.min(5,(r.scale??1)*(e.slider_render_scale||1));if(!this.cached_texture||this.cached_scale!==i){let s=e.slider_track_override??q(e,this.combo_number,1),a=e.slider_border_color??"rgba(255,255,255,1)",o=i;this.cached_texture=t.render_slider_to_image(this.render_path,n,a,s,o,e.slider_body_opacity,e.slider_border_opacity,null),this.cached_scale=i}}has_body_cache(){return this.cached_texture!=null}get_body_cache_bytes(){if(!this.cached_texture)return 0;return Math.max(0,Math.floor(this.cached_texture.width)*Math.floor(this.cached_texture.height)*4)}release_body_cache(){let t=this.cached_texture?.source;if(t?.destroy)t.destroy(!0);else if(this.cached_texture?.source instanceof HTMLCanvasElement)this.cached_texture.source.width=0,this.cached_texture.source.height=0;this.cached_texture=null}estimate_complexity(){if(!this.path_ready)return 1;if(!this.nested_objects_built)return this.render_path.length;return this.render_path.length+this.ticks.length*8+this.repeats.length*16}dispose(){this.release_body_cache(),this.position_path=[],this.render_path=[],this.ticks=[],this.repeats=[],this.tick_entries=[],this.tick_entries_by_start=[]}ensure_path_ready(){if(this.path_ready)return;let t=Ze(this.slider_data);if(t.length<2){this.position_path=[],this.render_path=[],this.path_length=0,this.path_ready=!1;return}let e=Math.max(1,this.config.radius*0.03),r=this.resample_path(t,e);this.position_path=r,this.render_path=r;let n=this.calculate_path_length();this.path_length=this.slider_data.distance>0?this.slider_data.distance:n,this.path_ready=this.position_path.length>1}render_ticks(t){if(this.tick_entries_by_start.length===0)return;let{backend:e,config:r}=this,{radius:n}=r,i=n*0.12,s=E(r.mods,g.Hidden);for(let a of this.tick_entries_by_start){let o=a.tick,c=t-a.appear_time;if(c<0)continue;if(a.visible_end<t)continue;let h=v(c/bt,0,1);if(s&&a.preempt>0){let p=Math.min(a.preempt-bt,1000);if(p>0){let m=o.time-p;if(t>=m){let f=v((t-m)/p,0,1);h*=1-f}}}else if(t>o.time){let p=v((t-o.time)/bt,0,1);h*=1-p}h*=this.body_alpha;let _=v(c/Zr,0,1),d=0.5+0.5*this.ease_out_elastic_half(_),u=i*d;if(h>0.01){e.set_alpha(h);let p=this.config.skin_elements?.sliderscorepoint;if(p){let m=u*2;e.draw_image(p,o.pos[0]-u,o.pos[1]-u,m,m)}else e.draw_circle(o.pos[0],o.pos[1],u,"rgba(255,255,255,0.8)","transparent",0)}}e.set_alpha(1)}build_tick_entries(){let{hit_object:t,config:e}=this,r=E(e.mods,g.Hidden);this.tick_entries=this.ticks.map((n)=>{let i=t.time+n.span_index*this.span_duration,s=e.preempt,a=n.span_index>0?200:s*0.66,o=(n.time-i)/2+a,c=n.time-o,h=r?n.time:n.time+bt;return{tick:n,appear_time:c,visible_end:h,preempt:o}}),this.tick_entries_by_start=[...this.tick_entries].sort((n,i)=>n.appear_time-i.appear_time)}ease_out_elastic_half(t){if(t<=0)return 0;if(t>=1)return 1;let e=0.3;return Math.pow(2,-10*t)*Math.sin((t-e/4)*(2*Math.PI)/e)+1}render_reverse_arrows(t){if(this.repeats.length===0)return;let{backend:e,config:r,hit_object:n,span_duration:i}=this,{radius:s}=r,a=s*0.9;for(let o of this.repeats){let c=r.preempt;if(o.repeat_index>0)c=i*2;else c+=n.time-(n.time-r.preempt);let h=o.time-c,_=o.repeat_index%2===0;if(t<h||t>o.time+me)continue;let l=this.body_alpha*0.9;if(o.repeat_index===0){let y=v((t-h)/150,0,1);l*=A.OutQuint(y)}else if(t<h)l=0;if(t>o.time){let y=Math.min(300,i);l*=1-v((t-o.time)/y,0,1)}if(l<=0.01)continue;let d=this.get_arrow_target_vector(o.pos,_),u=Math.atan2(d[1]-o.pos[1],d[0]-o.pos[0]),p=1;if(t<o.time){let y=n.time-r.preempt,w=(t-y)%Xr;if(w<be)p=1+(fe-1)*A.Out(w/be);else{let D=(w-be)/Kr;p=fe-(fe-1)*A.Out(v(D,0,1))}}else{let y=Math.min(300,i),w=v((t-o.time)/y,0,1);p=1+0.5*A.Out(w)}let m=a*p;e.save(),e.set_alpha(l),e.translate(o.pos[0],o.pos[1]),e.rotate(u);let f=this.config.skin_elements?.reversearrow_frames,b=f&&f.length>0?f[Math.floor((t-h)/50)%f.length]:this.config.skin_elements?.reversearrow;if(b)e.draw_image(b,-m,-m,m*2,m*2);else e.begin_path(),e.move_to(m*0.8,0),e.line_to(-m*0.4,-m*0.5),e.line_to(-m*0.4,m*0.5),e.close_path(),e.fill_path("rgba(255,255,255,0.9)");e.restore()}}render_head(){if(this.head_visual.circle_alpha<=0.01&&this.body_alpha<=0.01)return;let{backend:t,skin:e,config:r}=this,{radius:n}=r,i=this.slider_data.pos,s=this.hit_object.end_pos,a=q(e,this.combo_number,1);if(this.head_visual.render(t,e,i,n*tr,a,this.combo_count,r.skin_elements,r.skin_elements?.sliderstartcircle?{circle:r.skin_elements.sliderstartcircle,overlay:r.skin_elements.sliderstartcircleoverlay}:{circle:r.skin_elements?.hitcircle,overlay:r.skin_elements?.hitcircleoverlay},!0),this.body_alpha>0.01){let o=r.skin_elements?.sliderendcircle;if(!o)return;t.set_alpha(this.body_alpha*e.hit_circle_opacity);let c=r.skin_elements?.sliderendcircleoverlay,h=n*tr,_=h*2;if(t.draw_image(o,s[0]-h,s[1]-h,_,_,a),c)t.draw_image(c,s[0]-h,s[1]-h,_,_);t.set_alpha(1)}}render_ball(t){if(this.ball_alpha<=0.01&&this.follow_alpha<=0.01)return;let{backend:e,skin:r,config:n}=this,{radius:i}=n,s=this.ball_position,a=q(r,this.combo_number,0.9);if(this.follow_alpha>0.01){let o=i*this.follow_scale;e.set_alpha(this.follow_alpha*r.follow_circle_opacity);let c=this.config.skin_elements?.sliderfollowcircle;if(c)e.draw_image(c,s[0]-o,s[1]-o,o*2,o*2);else e.begin_path(),e.arc_to(s[0],s[1],o,0,Math.PI*2),e.stroke_path(r.follow_circle_color,r.follow_circle_width)}if(r.enable_slider_ball&&this.ball_alpha>0.01){e.set_alpha(this.ball_alpha*r.slider_ball_opacity);let o=this.config.skin_elements?.sliderball_frames,c=this.config.skin_elements?.sliderball;if(o&&o.length>0){let h=Math.max(0,t-this.hit_object.time),_=Math.floor(h/Math.max(1,this.slider_ball_frame_delay))%o.length;c=o[_]}if(c){let h=i*1.85,_=r.allow_slider_ball_tint?a:r.slider_ball_color;this.draw_slider_ball_layers(s,h,c,_,r.slider_ball_flip&&this.ball_reverse)}else{let h=r.allow_slider_ball_tint?a:r.slider_ball_color;e.draw_circle(s[0],s[1],i*0.85,h,"rgba(255,255,255,0.9)",i*0.1)}}e.set_alpha(1)}get_arrow_target_vector(t,e){let r=this.position_path;if(r.length===0)return t;if(e){for(let n=r.length-1;n>=0;n--)if(Math.abs(r[n][0]-t[0])>0.01||Math.abs(r[n][1]-t[1])>0.01)return r[n];return r[0]}for(let n=0;n<r.length;n++)if(Math.abs(r[n][0]-t[0])>0.01||Math.abs(r[n][1]-t[1])>0.01)return r[n];return r[r.length-1]}draw_slider_ball_layers(t,e,r,n,i){let{backend:s}=this,a=this.config.skin_elements?.sliderball_nd,o=this.config.skin_elements?.sliderball_spec,c=e/2;if(i){if(s.save(),s.translate(t[0],t[1]),s.scale(-1,1),a)s.draw_image(a,-c,-c,e,e);if(s.draw_image(r,-c,-c,e,e,n),o)s.set_blend_mode("lighter"),s.draw_image(o,-c,-c,e,e),s.set_blend_mode("normal");s.restore();return}if(a)s.draw_image(a,t[0]-c,t[1]-c,e,e);if(s.draw_image(r,t[0]-c,t[1]-c,e,e,n),o)s.set_blend_mode("lighter"),s.draw_image(o,t[0]-c,t[1]-c,e,e),s.set_blend_mode("normal")}}class ge{skin;mods;preempt;fade_in;radius;skin_elements=null;points=[];lines=[];sprites=[];constructor(t,e,r,n,i,s=null){this.skin=t,this.mods=e,this.preempt=r,this.fade_in=n,this.radius=i,this.skin_elements=s}update_settings(t,e,r,n,i){if(this.mods=t,this.preempt=e,this.fade_in=r,this.radius=n,i!==void 0)this.skin_elements=i}build(t){this.points.length=0,this.lines.length=0,this.sprites.length=0;let e=32,r=Math.max(450,this.preempt*0.9),n=E(this.mods,g.Hidden);for(let i=0;i<t.length-1;i++){let s=t[i],a=t[i+1];if(j(s)||j(a))continue;if(s.combo_number!==a.combo_number)continue;let o=s.end_pos,c=a.data.pos,h=c[0]-o[0],_=c[1]-o[1],l=Math.sqrt(h*h+_*_);if(l<e*1.5)continue;let d=s.end_time,u=a.time-d;if(u<=0)continue;let p=l>0?1/l:0,m=[h*p,_*p],f=d-r,b=a.time-r,y=d+(b-d)*0.5,w=a.time;if(n)y=d+(b-d)*0.3,w=d+(a.time-d)*0.65;this.lines.push({start_pos:o,end_pos:c,dir:m,start_time:d,end_time:a.time,appear_time:f,grow_end_time:b,shrink_start_time:y,shrink_end_time:w});let D=l<80?0:Math.floor((l-48)/32),O=Math.max(1,this.fade_in);for(let R=0;R<D;R++){let M=48+32*R,k=M/l,I=d+k*u,C=I-r;this.sprites.push({start_pos:o,dir:m,distance:l,start_time:d,end_time:a.time,preempt:r,time_fade_in:O,d:M,f:k,fade_in_time:C,fade_out_time:I})}for(let R=e*1.5;R<l-e;R+=e){let M=R/l,k=s.end_time+M*u,I=Math.max(s.end_time,k-r);if(n)k=Math.min(k,d+u*0.65);let C=[o[0]+(M-0.1)*h,o[1]+(M-0.1)*_],x=[o[0]+M*h,o[1]+M*_];this.points.push({start_pos:C,end_pos:x,dir:m,fade_in_time:I,fade_out_time:k})}}}render(t,e,r){let n=this.skin.follow_point_shape,i=this.skin.follow_point_mode??"segments",s=this.skin.follow_point_length||this.radius*0.6,a=v(this.skin.follow_point_line_gap??0,0,0.9),o=this.skin_elements?.followpoint_frames,c=this.skin_elements?.followpoint,h=c?"sprites":i,_=Math.max(this.fade_in*0.15,50),l=c?0.72:0.2;if(h==="sprites"){let d=o&&o.length>0?o:c?[c]:[],u=this.radius/64;for(let p of this.sprites){if(t<p.start_time-p.preempt)continue;if(t>p.fade_out_time+p.time_fade_in)continue;let m=0,f=u,b=p.f;if(t<p.fade_in_time+p.time_fade_in){let C=A.OutQuad(v((t-p.fade_in_time)/p.time_fade_in,0,1));m=C,f=(1.5-0.5*C)*u,b=p.f-0.1*(1-C)}else if(t<p.fade_out_time)m=1,f=1*u,b=p.f;else m=1-A.OutQuad(v((t-p.fade_out_time)/p.time_fade_in,0,1)),f=1*u,b=p.f;if(m<=0.01)continue;let y=Math.max(1,(p.fade_out_time-p.fade_in_time)/Math.max(1,d.length)),w=v(Math.floor((t-p.fade_in_time)/y),0,d.length-1),D=d[w],O=p.start_pos[0]+p.dir[0]*(b*p.distance),R=p.start_pos[1]+p.dir[1]*(b*p.distance),M=Math.max(1,D.width*f),k=Math.max(1,D.height*f),I=Math.atan2(p.dir[1],p.dir[0]);e.set_alpha(m),e.save(),e.translate(O,R),e.rotate(I),e.draw_image(D,-M/2,-k/2,M,k),e.restore()}}else if(h==="full")for(let d of this.lines){if(t<d.appear_time||t>d.shrink_end_time)continue;let u=0,p=d.start_pos[0],m=d.start_pos[1],f=d.end_pos[0],b=d.end_pos[1],y=Math.hypot(f-p,b-m),w=this.get_alpha_gate(t,d.start_time,d.end_time,r);if(w<=0.01)continue;let D=this.radius*1.05,O=Math.min(D,y*0.22);if(p+=d.dir[0]*O,m+=d.dir[1]*O,f-=d.dir[0]*O,b-=d.dir[1]*O,t<d.grow_end_time){let R=Math.max(1,d.grow_end_time-d.appear_time),M=v((t-d.appear_time)/R,0,1),k=A.OutQuint(M);u=k,f=p+(f-p)*k,b=m+(b-m)*k}else if(t<d.shrink_start_time)u=1;else{let R=Math.max(1,d.shrink_end_time-d.shrink_start_time),M=v((t-d.shrink_start_time)/R,0,1),k=A.InQuint(M);u=1,p=p+(f-p)*k,m=m+(b-m)*k}if(u<=0)continue;if(e.set_alpha(u*l*w),n==="line")if(a>0){let R=Math.hypot(f-p,b-m),M=d.dir[0],k=d.dir[1],I=R*a/2,C=(p+f)/2,x=(m+b)/2,T=C-M*I,S=x-k*I,L=C+M*I,W=x+k*I;e.draw_line(p,m,T,S,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round"),e.draw_line(L,W,f,b,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else e.draw_line(p,m,f,b,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round");else{let R=this.radius*0.12,M=(d.start_pos[0]+d.end_pos[0])/2,k=(d.start_pos[1]+d.end_pos[1])/2;e.draw_circle(M,k,R,"rgba(255,255,255,1)","transparent",0)}}else for(let d of this.points){if(t<d.fade_in_time||t>d.fade_out_time+_)continue;let u=0,p=1,m=d.end_pos;if(t<d.fade_in_time+_){let b=v((t-d.fade_in_time)/_,0,1),y=A.OutCubic(b);u=y,p=1.5-0.5*y,m=J(d.start_pos,d.end_pos,y)}else if(t<=d.fade_out_time)u=1,p=1,m=d.end_pos;else{let b=v((t-d.fade_out_time)/_,0,1),y=A.OutCubic(b);u=1-y,p=1,m=J(d.start_pos,d.end_pos,1-y)}if(u<=0)continue;let f=this.get_alpha_gate(t,d.fade_in_time+this.preempt,d.fade_out_time,r);if(f<=0.01)continue;if(e.set_alpha(u*l*f),n==="line"){let y=s*p/2,w=d.dir[0],D=d.dir[1],O=m[0]-w*y,R=m[1]-D*y,M=m[0]+w*y,k=m[1]+D*y;e.draw_line(O,R,M,k,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else{let b=this.radius*0.12*p;e.draw_circle(m[0],m[1],b,"rgba(255,255,255,1)","transparent",0)}}e.set_alpha(1)}get_alpha_gate(t,e,r,n){let i=n(t,e),s=n(t,r);return v(Math.min(i,s)/0.7,0,1)}}var Ct=(t,e,r)=>{if(t<=0)return 0;let n=e.Difficulty.SliderMultiplier;return t*r.base_beat_length/(100*n*r.sv_multiplier)},Lt=(t,e)=>{let r=e.sv_multiplier||1,n=t.Difficulty.SliderMultiplier,i=t.Difficulty.SliderTickRate,s=100*n*r,a=t.version<8?1/r:1,o=s/i*a,c=s/e.base_beat_length;return{tick_distance:o,min_distance_from_end:c*10}};class yt{points;index=0;last_time=Number.NEGATIVE_INFINITY;base_beat_length=600;sv_multiplier=1;constructor(t){if(this.points=t,t.length>0&&t[0].uninherited===1&&t[0].beatLength>0)this.base_beat_length=t[0].beatLength}reset(){this.index=0,this.last_time=Number.NEGATIVE_INFINITY,this.base_beat_length=600,this.sv_multiplier=1}get_state_at(t){if(this.points.length===0)return{base_beat_length:600,sv_multiplier:1};if(t<this.last_time)this.reset();for(let e=this.index;e<this.points.length;e++){let r=this.points[e];if(r.time>t)break;if(r.uninherited===1&&r.beatLength>0)this.base_beat_length=r.beatLength,this.sv_multiplier=1;else if(r.uninherited===0&&r.beatLength<0){let n=-100/r.beatLength;if(n>0)this.sv_multiplier=n}this.index=e+1}return this.last_time=t,this.sv_multiplier=v(this.sv_multiplier,0.1,10),{base_beat_length:this.base_beat_length,sv_multiplier:this.sv_multiplier}}}var H={precompute:{lookback_ms:1500,lookahead_ms:8000,frame_budget_ms:0.35,bootstrap_budget_ms:12,bootstrap_total_ms:120},slider_cache:{max_entries:72,max_bytes:100663296,retention_ms:14000,trim_interval_ms:250},stack:{default_leniency:0.7,distance:3,offset_multiplier:6.4}};var Bt=(t)=>{if(t.length===0)return t;let e=t.map((r,n)=>({point:r,index:n}));e.sort((r,n)=>{if(r.point.time!==n.point.time)return r.point.time-n.point.time;if(r.point.uninherited!==n.point.uninherited)return r.point.uninherited>n.point.uninherited?-1:1;return r.index-n.index});for(let r=0;r<t.length;r++)t[r]=e[r].point;return t};var F=(t)=>{if(typeof t==="number"&&Number.isFinite(t))return t;if(typeof t==="string"){let e=Number(t);if(Number.isFinite(e))return e}return null},zr=(t)=>F(t.time)??F(t.startTime)??F(t.start_time)??0,tn=(t,e)=>{let r=F(t.endTime)??F(t.end_time);if(r===null)return e;return Math.max(e,r)},en=(t)=>F(t.type)??F(t.objectType)??0,rn=(t,e)=>{let r=F(t.x);if(r!==null)return r;let n=F(t.column);if(n!==null&&e>0)return(Math.max(0,Math.min(e-1,Math.round(n)))+0.5)/e*512;return 256},nn=(t)=>F(t.y)??192,Ft=(t)=>{let e=[],r=Math.max(1,Math.round(F(t.Difficulty?.CircleSize)??4));for(let n of t.HitObjects){let i=n,s=zr(i),a=tn(i,s),o=rn(i,r),c=nn(i),h=en(i),_={...n,time:s,x:o,y:c,type:h,endTime:a,end_time:a,end_pos:[o,c],combo_number:0,combo_count:0,stack_height:0,stack_offset:[0,0],data:{pos:[o,c]}};if((h&P.Slider)!==0){let l=i.curvePoints||[],d=[];for(let p=0;p<l.length;p++){let m=l[p];d.push([m.x,m.y])}let u={pos:[o,c],path_type:i.curveType||"L",control_points:d,repetitions:(F(i.slides)??1)|0,distance:F(i.length)??0};_.data=u}else if((h&P.Spinner)!==0)_.data={end_time:a},_.end_time=a,_.end_pos=[256,192];else if((h&P.Hold)!==0)_.data={pos:[o,c],end_time:a},_.end_time=a;e.push(_)}return e};var ye=(t)=>384-t;class Vt extends at{radius=32;preempt=1200;fade_in=600;timing_points=[];timing_resolver=null;drawables=[];slider_drawables=[];slider_cache_lru=[];precompute_focus_time=0;precompute_handle=null;precompute_pause_until=0;last_seek_prefetch_at=0;drawable_config;follow_point_renderer;spinner_objects=[];frame_visible_drawables=[];frame_visible_sliders=[];frame_visible_other=[];slider_cache_limit=H.slider_cache.max_entries;slider_cache_bytes=0;last_cache_trim_at=0;constructor(t,e,r=0,n=K,i=null){super(t,e,r,n,i);this.follow_point_renderer=new ge(e,r,this.preempt,this.fade_in,this.radius,i)}initialize(t){this.release_drawables(),this.beatmap=t,this.objects=Ft(t).sort((n,i)=>n.time-i.time),this.timing_points=Bt([...t.TimingPoints]),this.timing_resolver=new yt(this.timing_points);let e=t.Difficulty.ApproachRate>=0?t.Difficulty.ApproachRate:t.Difficulty.OverallDifficulty,r=qe(t.Difficulty.CircleSize,e,0,0,this.mods);if(this.radius=Je(r.cs),this.preempt=Et(r.ar),this.fade_in=Qe(this.preempt),E(this.mods,g.Hidden))this.fade_in=this.preempt*0.4;this.follow_point_renderer.update_settings(this.mods,this.preempt,this.fade_in,this.radius,this.skin_elements),this.preprocess_objects(),this.follow_point_renderer.build(this.objects),this.create_drawables()}set_mods(t){if(this.mods=t,this.beatmap)this.initialize(this.beatmap)}preprocess_objects(){let t=0,e=1;if(this.timing_resolver)this.timing_resolver.reset();for(let r of this.objects){if(Te(r))t=(t+1)%this.skin.combo_colors.length,e=1;else e++;if(r.combo_number=t,r.combo_count=e,et(r)){let n=r.data;if(E(this.mods,g.HardRock))n.pos=[n.pos[0],ye(n.pos[1])],n.control_points=n.control_points.map((o)=>[o[0],ye(o[1])]);let i=this.timing_resolver?.get_state_at(r.time)??{base_beat_length:600,sv_multiplier:1},s=Ct(n.distance,this.beatmap,i);n.duration=s,r.end_time=r.time+s*n.repetitions;let a=n.control_points.length>0?n.control_points[n.control_points.length-1]:n.pos;r.end_pos=n.computed_path&&n.computed_path.length>0?ze(n):a}else if(j(r))r.end_pos=[256,192];else{let n=r.data;if(E(this.mods,g.HardRock))n.pos=[n.pos[0],ye(n.pos[1])];r.end_pos=n.pos}}this.apply_stacking_if_enabled()}apply_stacking_if_enabled(){if(!this.config.enable_stacking||this.objects.length<2)return;let t=this.resolve_stack_leniency(),e=this.preempt*t,r=this.radius/64,n=-H.stack.offset_multiplier*r;for(let i=0;i<this.objects.length;i++)this.objects[i].stack_height=0,this.objects[i].stack_offset=[0,0];for(let i=this.objects.length-1;i>0;i--){let s=this.objects[i];if(j(s))continue;for(let a=i-1;a>=0;a--){let o=this.objects[a];if(j(o))continue;if(s.time-o.end_time>e)break;let c=this.get_object_start_position(s),h=this.get_object_start_position(o),_=Ht(h,c),l=et(o)?Ht(o.end_pos,c):1/0;if(Yt(s)&&et(o)&&l<H.stack.distance){let d=s.stack_height-o.stack_height+1;for(let u=a+1;u<=i;u++){let p=this.objects[u];if(j(p))continue;let m=this.get_object_start_position(p);if(Ht(o.end_pos,m)<H.stack.distance)p.stack_height-=d}break}if(_<H.stack.distance||l<H.stack.distance)o.stack_height=s.stack_height+1,s=o}}for(let i=0;i<this.objects.length;i++){let s=this.objects[i];if(s.stack_height===0)continue;let a=s.stack_height*n,o=[a,a];if(s.stack_offset=o,s.end_pos=z(s.end_pos,o),et(s)){let c=s.data;c.pos=z(c.pos,o);let h=[];for(let _=0;_<c.control_points.length;_++)h.push(z(c.control_points[_],o));if(c.control_points=h,c.computed_path){let _=[];for(let l=0;l<c.computed_path.length;l++)_.push(z(c.computed_path[l],o));c.computed_path=_}continue}if(!j(s)){let c=s.data;c.pos=z(c.pos,o)}}}resolve_stack_leniency(){let t=this.beatmap,e=t.StackLeniency??t.Difficulty?.StackLeniency??t.General?.StackLeniency??H.stack.default_leniency;if(e<=0)return H.stack.default_leniency;return e}get_object_start_position(t){if(et(t))return t.data.pos;if(j(t))return[256,192];return t.data.pos}create_drawables(){this.release_drawables();let t=this.config.use_high_dpi?window.devicePixelRatio||1:1;if(this.drawable_config={backend:this.backend,skin:this.skin,skin_elements:this.skin_elements,preempt:this.preempt,fade_in:this.fade_in,radius:this.radius,scale:this.config.scale*t,mods:this.mods},this.timing_resolver)this.timing_resolver.reset();this.spinner_objects=[];for(let e of this.objects)if(Yt(e))this.drawables.push(new Nt(e,this.drawable_config));else if(et(e)){let r=e.data,n=r.duration||0,i=this.timing_resolver?.get_state_at(e.time)??{base_beat_length:600,sv_multiplier:1},{tick_distance:s,min_distance_from_end:a}=Lt(this.beatmap,i),o=new gt(e,this.drawable_config,r.computed_path||[],n,s,a);this.drawables.push(o),this.slider_drawables.push(o),r.computed_path=[]}else if(j(e))this.spinner_objects.push(e);this.slider_cache_limit=Math.min(H.slider_cache.max_entries,this.slider_drawables.length),this.slider_cache_bytes=0}render(t){let{backend:e,config:r}=this;this.precompute_focus_time=t,this.render_background(),e.save(),e.translate(r.offset_x,r.offset_y),e.scale(r.scale,r.scale),this.render_playfield(),this.render_grid();let n=this.frame_visible_drawables,i=this.frame_visible_sliders,s=this.frame_visible_other;n.length=0,i.length=0,s.length=0;for(let o=this.drawables.length-1;o>=0;o--){let c=this.drawables[o];if(!c.is_alive(t))continue;if(c.update(t),n.push(c),c instanceof gt)i.push(c);else s.push(c)}this.follow_point_renderer.render(t,e,(o,c)=>this.get_circle_alpha(o,c));for(let o=0;o<this.spinner_objects.length;o++){let c=this.spinner_objects[o],h=c.time-this.preempt;if(t>=h&&t<=c.end_time+200)this.draw_spinner(c,t)}for(let o=0;o<i.length;o++){let c=i[o];c.render_body_pass(t),this.touch_slider_cache(c)}let a=performance.now();if(a-this.last_cache_trim_at>=H.slider_cache.trim_interval_ms)this.last_cache_trim_at=a,this.trim_slider_cache_by_time(t);for(let o=0;o<i.length;o++)i[o].render_head_pass(t);for(let o=0;o<s.length;o++)s[o].render(t);if(!E(this.mods,g.Hidden)&&this.skin.enable_approach_circle){for(let o of n)if(t<=o.start_time)this.draw_approach_circle(o,t)}e.restore()}precompute(t=0){this.precompute_focus_time=t,this.process_precompute_queue(t,H.precompute.bootstrap_budget_ms,!0),this.start_precompute_loop()}on_seek(t){this.precompute_focus_time=t,this.precompute_pause_until=performance.now()+90;let e=performance.now();if(e-this.last_seek_prefetch_at<48)return;this.last_seek_prefetch_at=e,this.process_precompute_queue(t,1,!1)}dispose(){this.stop_precompute_loop(),this.release_drawables(),this.timing_points=[],this.timing_resolver=null,super.dispose()}release_drawables(){this.stop_precompute_loop();for(let t of this.drawables)t.dispose();this.drawables=[],this.slider_drawables=[],this.slider_cache_lru=[],this.slider_cache_bytes=0,this.spinner_objects=[],this.frame_visible_drawables.length=0,this.frame_visible_sliders.length=0,this.frame_visible_other.length=0}start_precompute_loop(){if(this.precompute_handle!==null)return;let t=()=>{if(this.precompute_handle=null,!this.has_uncached_sliders())return;if(performance.now()>=this.precompute_pause_until)this.process_precompute_queue(this.precompute_focus_time,H.precompute.frame_budget_ms,!1);this.precompute_handle=window.requestAnimationFrame(t)};this.precompute_handle=window.requestAnimationFrame(t)}stop_precompute_loop(){if(this.precompute_handle!==null)window.cancelAnimationFrame(this.precompute_handle),this.precompute_handle=null}has_uncached_sliders(){for(let t=0;t<this.slider_drawables.length;t++)if(!this.slider_drawables[t].has_body_cache())return!0;return!1}process_precompute_queue(t,e,r){if(this.slider_drawables.length===0)return;let n=performance.now()+e,i=0,s=r?2:1;while(performance.now()<n&&i<s){let a=this.pick_next_slider_for_precompute(t,r);if(!a)break;a.prepare_body_cache(),this.touch_slider_cache(a),i++}}pick_next_slider_for_precompute(t,e){let r=null,n=-1/0;for(let i=0;i<this.slider_drawables.length;i++){let s=this.slider_drawables[i],a=this.score_slider_for_precompute(s,t,e);if(a<=n)continue;n=a,r=s}return r??this.pick_nearest_uncached_slider(t)}score_slider_for_precompute(t,e,r){if(t.has_body_cache())return-1/0;let n=t.start_time-e,i=t.estimate_complexity();if(n>=-H.precompute.lookback_ms&&n<=H.precompute.lookahead_ms){let a=Math.abs(n)*0.025,o=r?0:i*0.02;return(r?i*0.2:0)-a-o}if(r)return i;return-1/0}pick_nearest_uncached_slider(t){let e=null,r=1/0;for(let n=0;n<this.slider_drawables.length;n++){let i=this.slider_drawables[n];if(i.has_body_cache())continue;let s=Math.abs(i.start_time-t);if(s>=r)continue;r=s,e=i}return e}touch_slider_cache(t){if(!t.has_body_cache())return;let e=this.slider_cache_lru.indexOf(t);if(e>=0){this.slider_cache_lru.splice(e,1),this.slider_cache_lru.push(t);return}this.slider_cache_lru.push(t),this.slider_cache_bytes+=t.get_body_cache_bytes(),this.enforce_slider_cache_limit()}enforce_slider_cache_limit(){while(this.slider_cache_lru.length>this.slider_cache_limit||this.slider_cache_bytes>H.slider_cache.max_bytes){let t=this.slider_cache_lru.shift();if(!t)break;this.slider_cache_bytes-=t.get_body_cache_bytes(),t.release_body_cache()}}trim_slider_cache_by_time(t){if(this.slider_cache_lru.length===0)return;let e=[],r=0;for(let n=0;n<this.slider_cache_lru.length;n++){let i=this.slider_cache_lru[n];if(!i.has_body_cache())continue;if(Math.abs(i.start_time-t)<=H.slider_cache.retention_ms||i.is_alive(t))e.push(i),r+=i.get_body_cache_bytes();else i.release_body_cache()}this.slider_cache_lru=e,this.slider_cache_bytes=r,this.enforce_slider_cache_limit()}draw_approach_circle(t,e){let r=t.position,n=t.start_time-this.preempt,s=4-3*v((e-n)/this.preempt,0,1),a=Math.min(this.fade_in*2,this.preempt),o=v((e-n)/Math.max(1,a),0,1),c=this.skin.approach_circle_opacity*o;if(c<=0.01)return;this.backend.save(),this.backend.set_alpha(c);let h=this.skin_elements?.approachcircle;if(h){let _=this.radius*2*s;this.backend.draw_image(h,r[0]-_/2,r[1]-_/2,_,_)}else{let _=this.skin.approach_circle_use_combo_color?q(this.skin,t.combo_number,1):this.skin.approach_circle_color??"rgba(255,255,255,1)";this.backend.draw_circle(r[0],r[1],this.radius*s,"transparent",_,this.radius*this.skin.approach_circle_width)}this.backend.restore()}get_circle_alpha(t,e){let r=e-this.preempt;if(t<r)return 0;let n=v((t-r)/this.fade_in,0,1);if(E(this.mods,g.Hidden)){let i=e-this.preempt+this.fade_in,s=this.preempt*0.3;if(t>i){let a=v((t-i)/s,0,1);n*=1-a}}return n}draw_spinner(t,e){let r=t.time-this.preempt,n=v((e-r)/this.fade_in,0,1);if(e>t.end_time)n=1-A.OutCubic(v((e-t.end_time)/200,0,1));if(n<=0)return;let i=256,s=192,a=Math.max(1,t.end_time-t.time),o=v((e-t.time)/a,0,1);this.backend.save(),this.backend.set_alpha(n);let c=this.skin.spinner_size*(1-o);if(c>5)this.backend.begin_path(),this.backend.arc_to(i,s,c,0,Math.PI*2),this.backend.stroke_path("rgba(255,255,255,0.6)",4);this.backend.draw_circle(i,s,this.skin.spinner_size,"rgba(0,0,0,0.2)"),this.backend.draw_circle(i,s,12,"white"),this.backend.restore()}}var er=11485,rr=8,dt=50,sn=0.4,an=0.2,on=0.68,cn=0.18,hn=0.04,_n=0.2,dn=0.5,ln=0.18,pn=0.5;class G extends at{static MIN_KEY_COUNT=1;static MAX_KEY_COUNT=18;static DEFAULT_KEY_COUNT=4;key_count=4;scroll_time=er/rr;hd_coverage=0.25;fi_coverage=0.6;gradient_ratio=0.2;press_start_sorted=[];press_end_sorted=[];press_start_index=0;press_end_index=0;active_press_objects=new Set;active_press_lane_counts=[];lane_impacts=[];last_press_time=Number.NEGATIVE_INFINITY;base_timing_points=[];constructor(t,e,r=0,n=K,i=null){super(t,e,r,n,i);this.update_scroll_time()}initialize(t){this.beatmap=t,this.objects=Ft(t).sort((e,r)=>e.time-r.time),this.key_count=this.resolve_key_count(t),this.press_start_sorted=this.objects,this.press_end_sorted=this.objects.slice().sort((e,r)=>e.end_time-r.end_time),this.base_timing_points=this.extract_base_timing_points(t),this.reset_pressed_state()}set_mods(t){this.mods=t,this.update_scroll_time()}update_scroll_time(){this.scroll_time=er/rr}get_lane_metrics(){let t=Math.max(1,Number.isFinite(this.skin.mania_lane_width)?this.skin.mania_lane_width:30),e=Math.max(4,Number.isFinite(this.skin.mania_note_height)?this.skin.mania_note_height:15),r=Math.max(0,Number.isFinite(this.skin.mania_lane_spacing)?this.skin.mania_lane_spacing:1),n=Math.max(8,Math.min(Jt,Number.isFinite(this.skin.mania_hit_position)?this.skin.mania_hit_position:364));return{lane_width:t,note_height:e,spacing:r,hit_pos:n}}time_to_y(t,e){let r=t/this.scroll_time;return e-r*e}get_stage_bottom_height(t,e){let r=this.get_mania_texture("mania-stage-bottom",t);if(!r)return 0;return Math.max(1,Math.round(r.height*(e/Math.max(1,r.width))))}draw_clipped_note_with_gradient(t,e,r,n,i,s,a){let o=Math.max(s,e),h=Math.min(a,e+n)-o;if(h<=0||r<=0)return;let _=this.backend;_.draw_rect(t,o,r,h,i);let l=_.create_linear_gradient(t,o,t,o+h,[{offset:0,color:`rgba(255,255,255,${cn})`},{offset:0.45,color:`rgba(255,255,255,${hn})`},{offset:1,color:`rgba(0,0,0,${_n})`}]);_.draw_rect_gradient(t,o,r,h,l)}get_lane(t){let e=t.data.pos,r=Number.isFinite(e?.[0])?e[0]:t.x,n=Math.floor(r*this.key_count/512);if(!Number.isFinite(n))n=0;if(E(this.mods,g.Mirror))n=this.key_count-1-n;return Math.max(0,Math.min(this.key_count-1,n))}resolve_key_count(t){let e=t?.Difficulty?.CircleSize;if(Number.isFinite(e)){let i=Math.round(e);if(i>=G.MIN_KEY_COUNT)return Math.max(G.MIN_KEY_COUNT,Math.min(G.MAX_KEY_COUNT,i))}let r=new Set;for(let i=0;i<t.HitObjects.length;i++){let s=t.HitObjects[i].x;if(Number.isFinite(s))r.add(Math.round(s))}let n=r.size;if(n>=G.MIN_KEY_COUNT&&n<=G.MAX_KEY_COUNT)return n;return G.DEFAULT_KEY_COUNT}reset_pressed_state(){this.press_start_index=0,this.press_end_index=0,this.active_press_objects.clear(),this.active_press_lane_counts=Array(this.key_count).fill(0),this.lane_impacts=Array(this.key_count).fill(0),this.last_press_time=Number.NEGATIVE_INFINITY}add_pressed_object(t){if(this.active_press_objects.has(t))return;this.active_press_objects.add(t);let e=this.get_lane(t);if(e>=0&&e<this.active_press_lane_counts.length)this.active_press_lane_counts[e]++}remove_pressed_object(t){if(!this.active_press_objects.delete(t))return;let e=this.get_lane(t);if(e>=0&&e<this.active_press_lane_counts.length&&this.active_press_lane_counts[e]>0)this.active_press_lane_counts[e]--}rebuild_pressed_state(t){this.active_press_objects.clear(),this.active_press_lane_counts.fill(0);for(let e=0;e<this.objects.length;e++){let r=this.objects[e];if(t>=r.time-dt&&t<=r.end_time+dt)this.add_pressed_object(r)}this.press_start_index=0;while(this.press_start_index<this.press_start_sorted.length&&this.press_start_sorted[this.press_start_index].time-dt<=t)this.press_start_index++;this.press_end_index=0;while(this.press_end_index<this.press_end_sorted.length&&this.press_end_sorted[this.press_end_index].end_time+dt<t)this.press_end_index++}update_pressed_state(t){if(!Number.isFinite(this.last_press_time)||t<this.last_press_time||t-this.last_press_time>1000){this.rebuild_pressed_state(t),this.last_press_time=t;return}while(this.press_start_index<this.press_start_sorted.length&&this.press_start_sorted[this.press_start_index].time-dt<=t)this.add_pressed_object(this.press_start_sorted[this.press_start_index]),this.press_start_index++;while(this.press_end_index<this.press_end_sorted.length&&this.press_end_sorted[this.press_end_index].end_time+dt<t)this.remove_pressed_object(this.press_end_sorted[this.press_end_index]),this.press_end_index++;this.last_press_time=t}extract_base_timing_points(t){let e=[];for(let r=0;r<t.TimingPoints.length;r++){let n=t.TimingPoints[r],i=Number(n.time),s=Number(n.beatLength),a=Math.max(1,Math.round(Number(n.meter)||4)),o=Number(n.uninherited);if(!Number.isFinite(i)||!Number.isFinite(s)||s<=0)continue;if(Number.isFinite(o)&&o===0)continue;e.push({time:i,beat_length:s,meter:a})}if(e.length===0)e.push({time:0,beat_length:600,meter:4});return e.sort((r,n)=>r.time-n.time),e}get_mania_texture(t,e){let r=t.toLowerCase(),n=this.skin_elements?.mania_animations?.[r];if(n&&n.length>0){let i=this.skin.animation_framerate>0?this.skin.animation_framerate:60,s=Math.floor(Math.max(0,e)/1000*i)%n.length;return n[s]}return this.skin_elements?.mania_textures?.[r]??null}draw_column_sprite(t,e,r,n,i){this.backend.draw_image(t,e,r,Math.max(1,n),Math.max(1,i))}get_column_fallback_index(t){if(this.key_count%2===1&&t===Math.floor(this.key_count/2))return"s";let e=t%this.key_count;return Math.min(e,this.key_count-1-e)%2===0?"1":"2"}draw_stage_background(t,e,r,n,i){let{backend:s,key_count:a}=this,{lane_width:o,spacing:c}=this.get_lane_metrics(),h=Math.max(1,o-2*c),_=this.get_mania_texture("mania-stage-left",t);if(_&&_.height>0){let u=_.width*(i/_.height);s.set_alpha(1),s.draw_image(_,e-u,0,u,i)}let l=this.get_mania_texture("mania-stage-right",t);if(l&&l.height>0){let u=l.width*(i/l.height);s.set_alpha(1),s.draw_image(l,e+r,0,u,i)}let d=this.get_mania_texture("mania-stage-light",t);if(d){for(let u=0;u<a;u++){let p=e+u*o+c;s.set_alpha(sn),this.draw_column_sprite(d,p,0,h,n)}s.set_alpha(1);return}for(let u=0;u<a;u++){let p=e+u*o+c,m=ht(this.skin,a,u);s.set_alpha(an),s.draw_rect(p,0,h,n,m)}s.set_alpha(on);for(let u=1;u<a;u++){let p=e+u*o;s.draw_rect(p-0.75,0,1.5,n,"#ffffff")}s.set_alpha(1)}draw_bar_lines(t,e,r,n){let i=this.backend,s=t+this.scroll_time;for(let a=0;a<this.base_timing_points.length;a++){let o=this.base_timing_points[a],c=a+1<this.base_timing_points.length?this.base_timing_points[a+1].time:Number.POSITIVE_INFINITY,h=Math.max(t,o.time),_=Math.min(s,c);if(_<=h)continue;let l=Math.max(0,Math.ceil((h-o.time)/o.beat_length)),d=Math.floor((_-o.time)/o.beat_length);for(let u=l;u<=d;u++){let p=o.time+u*o.beat_length,m=this.time_to_y(p-t,n);if(m<0||m>n)continue;let f=u%o.meter===0;i.set_alpha(f?0.3:0.16),i.draw_rect(e,m,r,f?1.25:1,"#ffffff")}}i.set_alpha(1)}draw_note(t,e,r,n){let{lane_width:i,note_height:s,spacing:a,hit_pos:o}=n,c=this.get_lane(t),h=this.time_to_y(t.time-e,o);if(h<-s-64||h>o+s+8)return;let _=r+c*i,l=Math.max(1,i-2*a),d=ht(this.skin,this.key_count,c);this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(_+a,h-s,l,s,d,0,o)}draw_hold_note(t,e,r,n){let{lane_width:i,note_height:s,spacing:a,hit_pos:o}=n,c=t.data,h=this.get_lane(t),_=this.time_to_y(t.time-e,o),l=this.time_to_y(c.end_time-e,o);if(l>o+s+8&&_>o+s+8)return;if(l<-64&&_<-64)return;let d=r+h*i,u=Math.max(1,i-2*a),p=ht(this.skin,this.key_count,h),m=l,b=(t.time<=e?o:_)-m;if(b>0)this.backend.set_alpha(0.92),this.draw_clipped_note_with_gradient(d+a,m,u,b,p,0,o);if(t.time>=e)this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(d+a,_-s,u,s,p,0,o);if(c.end_time>=e)this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(d+a,l-s,u,s,p,0,o);this.backend.set_alpha(1)}draw_hit_glow(t,e,r){let{lane_width:n,spacing:i,hit_pos:s}=r,{backend:a,key_count:o}=this;if(this.active_press_objects.size===0)return;let c=this.lane_impacts;if(c.length!==o)this.lane_impacts=Array(o).fill(0);else c.fill(0);let h=this.lane_impacts;for(let l of this.active_press_objects){let d=0;if(Wt(l)){let p=l.data;if(t>=l.time&&t<=p.end_time)d=0.35;else if(t<l.time){let m=l.time-t;if(m<=120)d=(1-m/120)*0.7}else{let m=t-p.end_time;if(m<=120)d=(1-m/120)*0.35}}else{let p=Math.abs(t-l.time);if(p<=120)d=1-p/120}if(d<=0)continue;let u=this.get_lane(l);if(d>h[u])h[u]=d}let _=this.get_mania_texture("mania-stage-light",t);a.set_blend_mode("lighter");for(let l=0;l<o;l++){let d=h[l];if(d<=0)continue;let u=e+l*n+i,p=Math.max(1,n-2*i),m=u+p*0.5;if(_){let b=Math.max(16,s*(0.55+d*0.25));a.set_alpha(dn*d),a.draw_image(_,u,s-b,p,b),a.set_alpha(ln*d),a.draw_image(_,u,s-b*0.7,p,b*0.7)}else{let b=Math.max(16,72*d),y=Math.max(2,p*0.16);a.set_alpha(0.4*d),a.draw_rect(m-y*0.5,s-b,y,b,"#cfe9ff")}let f=Math.max(3,p*0.6);a.set_alpha(pn*d),a.draw_rect(m-f*0.5,s-2,f,4,"#ffffff")}a.set_blend_mode("normal"),a.set_alpha(1)}draw_judgment_line(t,e){let{lane_width:r,hit_pos:n}=e,i=r*this.key_count,s=this.get_mania_texture("mania-stage-hint",0);if(s){let a=Math.max(2,Math.round(s.height*(i/Math.max(1,s.width))));this.backend.set_alpha(1),this.backend.draw_image(s,t,n-a,i,a);return}this.backend.draw_rect(t,n-1,i,2,"#ffffff")}draw_lane_keys(t,e,r){let{lane_width:n,hit_pos:i,spacing:s,note_height:a}=r,o=a+5;this.update_pressed_state(t);for(let h=0;h<this.key_count;h++){let _=(this.active_press_lane_counts[h]??0)>0,l=e+h*n,d=ht(this.skin,this.key_count,h),u=this.get_column_fallback_index(h),p=this.get_mania_texture(`mania-key${u}`,t),m=this.get_mania_texture(`mania-key${u}d`,t),f=Math.max(1,n-2*s);if(_&&m){this.backend.set_alpha(1),this.draw_column_sprite(m,l+s,i,f,o);continue}if(p){this.backend.set_alpha(1),this.draw_column_sprite(p,l+s,i,f,o);continue}if(this.backend.set_alpha(0.38),this.backend.draw_rect(l+s,i,f,o,d),_)this.backend.set_alpha(0.72),this.backend.draw_rect(l+s,i,f,o,"#ff6666")}let c=this.get_mania_texture("mania-stage-bottom",t);if(c){let h=this.key_count*n,_=Math.max(1,Math.round(c.height*(h/Math.max(1,c.width))));this.backend.set_alpha(1),this.backend.draw_image(c,e,i,h,_)}this.backend.set_alpha(1)}draw_playfield_frame(t,e,r){let i=Math.max(1,r-0);this.backend.set_alpha(0.92),this.backend.draw_rect(t,0,e,1.5,"#f0f4ff"),this.backend.draw_rect(t,r-1.5,e,1.5,"#f0f4ff"),this.backend.draw_rect(t,0,1.5,i,"#f0f4ff"),this.backend.draw_rect(t+e-1.5,0,1.5,i,"#f0f4ff"),this.backend.set_alpha(1)}render(t){let{backend:e,config:r}=this,n=this.get_lane_metrics(),i=Math.max(1,this.key_count*n.lane_width),s=Math.floor((Qt-i)/2),a=this.get_stage_bottom_height(t,i),o=n.hit_pos+n.note_height+5+a;this.render_background(),e.save(),e.translate(r.offset_x,r.offset_y),e.scale(r.scale,r.scale),this.draw_stage_background(t,s,i,n.hit_pos,o),this.draw_bar_lines(t,s,i,n.hit_pos),e.set_alpha(0.55),e.draw_rect(s,0,i,n.hit_pos,"#000000"),e.set_alpha(1);for(let _=0;_<this.objects.length;_++){let l=this.objects[_];if(Wt(l))this.draw_hold_note(l,t,s,n);else this.draw_note(l,t,s,n)}this.draw_hit_glow(t,s,n),this.draw_judgment_line(s,n),this.draw_lane_keys(t,s,n),this.draw_playfield_frame(s,i,o);let c=E(this.mods,g.Hidden),h=E(this.mods,g.FadeIn);if(c||h){let _=c?this.hd_coverage:this.fi_coverage,l=n.hit_pos*_,d=n.hit_pos*this.gradient_ratio;if(c){let u=n.hit_pos-l,p=d/l,m=e.create_linear_gradient(s,u,s,n.hit_pos,[{offset:0,color:"rgba(0,0,0,0)"},{offset:p*0.4,color:"rgba(0,0,0,0.3)"},{offset:p*0.7,color:"rgba(0,0,0,0.75)"},{offset:p*0.9,color:"rgba(0,0,0,0.95)"},{offset:p,color:"rgba(0,0,0,1)"},{offset:1,color:"rgba(0,0,0,1)"}]);e.draw_rect_gradient(s,u,i,l,m)}else{let u=(l-d)/l,p=e.create_linear_gradient(s,0,s,l,[{offset:0,color:"rgba(0,0,0,1)"},{offset:u,color:"rgba(0,0,0,1)"},{offset:u+(1-u)*0.1,color:"rgba(0,0,0,0.95)"},{offset:u+(1-u)*0.4,color:"rgba(0,0,0,0.75)"},{offset:u+(1-u)*0.7,color:"rgba(0,0,0,0.3)"},{offset:1,color:"rgba(0,0,0,0)"}]);e.draw_rect_gradient(s,0,i,l,p)}}e.restore()}}class vt{audio_context;gain_node;constructor(t){this.audio_context=t,this.gain_node=this.audio_context.createGain(),this.gain_node.connect(this.audio_context.destination)}set_volume(t){this.gain_node.gain.value=v(t,0,1)}dispose_audio_node(){this.gain_node.disconnect()}}class Pt extends vt{media_element=null;media_source=null;media_url=null;_is_playing=!1;_is_loaded=!1;_duration=0;pause_time=0;speed=1;started_at_context_time=0;started_from_time=0;constructor(t){super(t)}get is_playing(){return this._is_playing}get is_loaded(){return this._is_loaded}get duration(){return this._duration}get speed_multiplier(){return this.speed}get current_time(){if(!this.media_element)return this.pause_time;if(!this._is_playing)return this.pause_time;let t=(this.audio_context.currentTime-this.started_at_context_time)*1000*this.speed,e=this.started_from_time+t,r=Math.max(0,this.media_element.currentTime*1000);if(Math.abs(r-e)>40)e=r,this.started_from_time=r,this.started_at_context_time=this.audio_context.currentTime;if(e>=this._duration)return this._duration;return Math.max(0,e)}async load(t,e=1){this.stop(),this.release_media(),this.speed=Math.max(0.1,e),await this.load_media_element(t),this._is_loaded=!0,this.pause_time=0,this.started_at_context_time=0,this.started_from_time=0}async play(t){if(!this.media_element){console.warn("[AudioController] Cannot play: not loaded");return}let e=t!==void 0?t:this.pause_time,r=Math.max(0,Math.min(e,this._duration));this.media_element.currentTime=r/1000,this.media_element.playbackRate=this.speed,this.pause_time=r,this.started_from_time=r,this.started_at_context_time=this.audio_context.currentTime;try{await this.media_element.play()}catch(n){throw this._is_playing=!1,n}this._is_playing=!0}pause(){if(!this._is_playing)return;if(this.media_element)this.media_element.pause(),this.pause_time=this.current_time;this._is_playing=!1}seek(t){let e=Math.max(0,Math.min(t,this._duration));if(this.pause_time=e,this.media_element)this.media_element.currentTime=e/1000;if(this._is_playing)this.started_from_time=e,this.started_at_context_time=this.audio_context.currentTime}stop(){if(this.media_element)this.media_element.pause(),this.media_element.currentTime=0;this._is_playing=!1,this.pause_time=0,this.started_at_context_time=0,this.started_from_time=0}get_host_time(t){let e=t-this.current_time;return this.audio_context.currentTime+e/1000/this.speed}set_speed(t){let e=this.current_time;if(this.speed=Math.max(0.1,t),this.media_element)this.media_element.playbackRate=this.speed;this.started_from_time=e,this.started_at_context_time=this.audio_context.currentTime,this.pause_time=e}set_volume(t){if(super.set_volume(t),this.media_element)this.media_element.volume=1}dispose(){this.stop(),this.release_media(),this._is_loaded=!1,this._duration=0,this.pause_time=0,this._is_playing=!1,this.started_at_context_time=0,this.started_from_time=0,this.dispose_audio_node()}async load_media_element(t){this.release_media();let e=new Blob([t]),r=URL.createObjectURL(e),n=new Audio;n.preload="metadata",n.src=r,n.playbackRate=this.speed,n.volume=1,await new Promise((i,s)=>{let a=!1,o=()=>{n.onloadedmetadata=null,n.onerror=null};n.onloadedmetadata=()=>{if(a)return;a=!0,o(),i()},n.onerror=()=>{if(a)return;a=!0,o(),s(Error("Failed to load media audio metadata"))}}),n.onended=()=>{if(this.media_element!==n)return;if(this._is_playing)this._is_playing=!1,this.pause_time=this._duration},this.media_element=n,this.media_source=this.audio_context.createMediaElementSource(n),this.media_source.connect(this.gain_node),this.media_url=r,this._duration=Math.max(0,(n.duration||0)*1000)}release_media(){if(this.media_source)this.media_source.disconnect(),this.media_source=null;if(this.media_element)this.media_element.onended=null,this.media_element.onerror=null,this.media_element.onloadedmetadata=null,this.media_element.pause(),this.media_element.src="",this.media_element.load(),this.media_element=null;if(this.media_url)URL.revokeObjectURL(this.media_url),this.media_url=null}}class jt{video=null;object_url=null;_offset=0;get element(){return this.video}get offset(){return this._offset}async load(t,e=0){this.dispose(),this._offset=e,this.video=document.createElement("video"),this.video.muted=!0,this.video.loop=!1,this.video.playsInline=!0,this.object_url=URL.createObjectURL(t),this.video.src=this.object_url,await new Promise((r,n)=>{if(!this.video)return n(Error("No video element"));this.video.onloadeddata=()=>r(),this.video.onerror=()=>n(Error("Failed to load video"))})}sync(t){if(!this.video)return;let e=(t-this._offset)/1000;if(e<0){if(!this.video.paused)this.video.pause();return}if(Math.abs(this.video.currentTime-e)>0.1)this.video.currentTime=e}play(){if(this.video&&this.video.paused)this.video.play().catch(()=>{console.warn("[VideoController] failed to play video")})}pause(){if(this.video&&!this.video.paused)this.video.pause()}seek(t){if(!this.video)return;let e=Math.max(0,(t-this._offset)/1000);this.video.currentTime=e}dispose(){if(this.video)this.video.pause(),this.video.src="",this.video=null;if(this.object_url)URL.revokeObjectURL(this.object_url),this.object_url=null}}class ve extends vt{custom_samples=new Map;constructor(t){super(t)}async load_samples(t){this.custom_samples.clear(),await this.load_into_cache(t,this.custom_samples)}async load_samples_from_files(t){this.custom_samples.clear(),await this.load_files_into_cache(t,this.custom_samples)}clear(){this.custom_samples.clear()}play(t,e,r,n,i=100,s,a=0){let o=this.get_set_name(t),c=this.get_set_name(e);if(s){let h=s.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"");if(this.play_buffer(h,i,a))return}if(this.play_sound(o,"hitnormal",n,i,a),r&wt.Whistle)this.play_sound(c,"hitwhistle",n,i,a);if(r&wt.Finish)this.play_sound(c,"hitfinish",n,i,a);if(r&wt.Clap)this.play_sound(c,"hitclap",n,i,a)}play_sample(t,e,r,n=100,i=0){let s=this.get_set_name(t);this.play_sound(s,e,r,n,i)}play_sound(t,e,r,n,i){let s=!1;if(r>1)s=this.play_buffer(`${t}-${e}${r}`,n,i);if(!s)this.play_buffer(`${t}-${e}`,n,i)}play_buffer(t,e,r){let n=this.custom_samples.get(t);if(!n)return!1;let i=this.audio_context.createBufferSource();i.buffer=n;let s=this.audio_context.createGain();return s.gain.value=e/100,i.connect(s),s.connect(this.gain_node),i.start(r),!0}get_set_name(t){switch(t){case 3:return"drum";case 2:return"soft";default:return"normal"}}get_sample_key_from_url(t){let r=t.split("?")[0].split("#")[0].split("/").pop();if(!r)return null;if(!r.endsWith(".wav")&&!r.endsWith(".mp3")&&!r.endsWith(".ogg"))return null;return r.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"")}async load_into_cache(t,e){if(t.length==0)return;let r=[],n=t.map(async(i)=>{let s=this.get_sample_key_from_url(i);if(!s){r.push(i);return}if(e.has(s))return;await this.load_single_sample(i,s,e,r)});await Promise.all(n),this.report_failures(r.length,e.size)}async load_single_sample(t,e,r,n){try{let i=await fetch(t);if(!i.ok){n.push(t);return}let s=await i.arrayBuffer();if(s.byteLength<128){n.push(t);return}let a=await this.audio_context.decodeAudioData(s.slice(0));r.set(e,a)}catch{n.push(t)}}async load_files_into_cache(t,e){if(t.size==0)return;let r=[],n=[];for(let[i,s]of t)n.push((async()=>{let a=this.get_sample_key_from_url(i);if(!a||e.has(a))return;if(s.byteLength<128){r.push(i);return}try{let o=await this.audio_context.decodeAudioData(s.slice(0));e.set(a,o)}catch{r.push(i)}})());await Promise.all(n),this.report_failures(r.length,e.size)}report_failures(t,e){if(t>0&&e===0)console.warn(`[HitsoundController] Failed to load ${t} hitsounds`)}dispose(){this.custom_samples.clear(),this.dispose_audio_node()}}class xe{files;audio_filename;background_filename;video_filename;video_offset;constructor(t){this.files=t.files,this.audio_filename=t.audio_filename,this.background_filename=t.background_filename,this.video_filename=t.video_filename,this.video_offset=t.video_offset}resolve(){let t=this.audio_filename?this.find_file(this.audio_filename):void 0,e=this.background_filename?this.find_file(this.background_filename):void 0,r=this.video_filename?this.find_file(this.video_filename):void 0;return{audio:t,background:e?new Blob([e]):void 0,video:r?new Blob([r]):void 0,video_offset:this.video_offset}}find_file(t){if(this.files.has(t))return this.files.get(t);let e=t.toLowerCase();for(let[r,n]of this.files)if(r.toLowerCase()===e)return n;return}}var un=100,mn=20;class we{audio;hitsounds;resources=null;timing_points=[];timing_resolver=null;audio_offset=20;next_hit_object_index=0;hitsound_lookahead_ms=un;constructor(t,e){this.audio=t;this.hitsounds=e}set_context(t,e,r,n){this.resources=t,this.timing_points=e,this.timing_resolver=r,this.audio_offset=n,this.next_hit_object_index=0}set_audio_offset(t){this.audio_offset=t}set_hitsound_lookahead(t){this.hitsound_lookahead_ms=Math.max(0,t)}update_hit_index(t){if(!this.resources?.beatmap)return;let e=this.resources.beatmap.HitObjects;if(this.next_hit_object_index>0&&e[this.next_hit_object_index-1].time>t)this.next_hit_object_index=0;while(this.next_hit_object_index<e.length&&e[this.next_hit_object_index].time<t)this.next_hit_object_index++}schedule_hitsounds(t){if(!this.resources?.beatmap||!this.audio.is_playing)return 0;let e=0,r=this.resources.beatmap.HitObjects,n=t+this.hitsound_lookahead_ms;while(this.next_hit_object_index<r.length&&r[this.next_hit_object_index].time<=n){let i=r[this.next_hit_object_index];if(i.time>=t-mn)this.play_hitsound(i),e++;this.next_hit_object_index++}return e}play_hitsound(t){let e=this.get_timing_point(t.time),r=this.resolve_sample_settings(e,t.hitSample);if((t.type&P.Slider)===0){this.play_node_hitsound(t.time,t.hitSound,r,r.custom_filename);return}let n=this.resources?.beatmap;if(!n)return;let i=this.timing_resolver?.get_state_at(t.time)??{base_beat_length:600,sv_multiplier:1},s=t.length??0,a=Ct(s,n,i),o=Math.max(1,t.slides||1);if(a<=0||s<=0){this.play_node_hitsound(t.time,t.hitSound,r,r.custom_filename);return}let c=t.edgeSounds??[],h=t.edgeSets??[];for(let d=0;d<=o;d++){let u=t.time+a*d,p=c.length>0?c[d]??0:d==0?t.hitSound:0,m=h.length>0?h[d]:void 0,f=this.resolve_edge_sets(r,m),b=d==0?r.custom_filename:void 0;this.play_node_hitsound(u,p,{...r,...f},b)}let _=Lt(n,i),l=St({start_time:t.time,span_duration:a,span_count:o,length:s,tick_distance:_.tick_distance,min_distance_from_end:_.min_distance_from_end,get_position_at_progress:()=>[0,0]});for(let d of l.ticks){let u=this.audio.get_host_time(d.time+this.audio_offset);this.hitsounds.play_sample(r.normal_set,"slidertick",r.index,r.volume,u)}}play_node_hitsound(t,e,r,n){let i=this.audio.get_host_time(t+this.audio_offset);this.hitsounds.play(r.normal_set,r.addition_set,e,r.index,r.volume,n,i)}resolve_sample_settings(t,e){let{volume:r,sampleSet:n,sampleSet:i,sampleIndex:s}=t,a=void 0;if(e){if(e.normalSet!==0){if(n=e.normalSet,e.additionSet===0)i=n}if(e.additionSet!==0)i=e.additionSet;if(e.index!==0)s=e.index;if(e.volume!==0)r=e.volume;a=e.filename||void 0}if(n===0)n=1;if(i===0)i=n;return{normal_set:n,addition_set:i,index:s,volume:r,custom_filename:a}}resolve_edge_sets(t,e){let{normal_set:r,addition_set:n}=t;if(e){let{normalSet:i,additionSet:s}=e;if(i!==0)r=i;if(s!==0)n=s;else n=r}if(r===0)r=1;if(n===0)n=r;return{normal_set:r,addition_set:n}}get_timing_point(t){let e=this.timing_points;if(e.length==0)return{time:0,beatLength:600,meter:4,sampleSet:1,sampleIndex:1,volume:100,uninherited:1,effects:0};for(let r=e.length-1;r>=0;r--)if(e[r].time<=t)return e[r];return e[0]}}var fn=[".wav",".mp3",".ogg"],bn=/^(normal|soft|drum)-(hitnormal|hitwhistle|hitfinish|hitclap|slidertick|sliderslide|sliderwhistle)\d*$/i,nr=(t,e,r)=>{let n=new Set;for(let a of t.HitObjects){let o=a.hitSample?.filename?.trim();if(o)n.add(o.toLowerCase())}let i=new Map,s=r?.toLowerCase();for(let[a,o]of e){let c=a.toLowerCase();if(!gn(c))continue;if(s&&c==s)continue;let h=yn(c),_=h.replace(/\.(wav|mp3|ogg)$/,""),l=bn.test(_),d=n.has(h)||n.has(_)||n.has(c);if(l||d)i.set(a,o)}return i},gn=(t)=>{for(let e of fn)if(t.endsWith(e))return!0;return!1},yn=(t)=>{let e=t.split("?")[0].split("#")[0];return e.split("/").pop()??e};var vn=["rgb(255, 192, 0)","rgb(0, 202, 0)","rgb(18, 124, 255)","rgb(242, 24, 57)"],ke=(t)=>{let e=t.trim().toLowerCase();if(e==="1"||e==="true"||e==="yes")return!0;if(e==="0"||e==="false"||e==="no")return!1;return},ir=(t)=>{let e={general:{},fonts:{},colours:{combo_colors:[]}},r="",n=t.split(/\r?\n/);for(let i of n){let s=i.trim();if(s.length===0||s.startsWith("//"))continue;if(s.startsWith("[")&&s.endsWith("]")){r=s.slice(1,-1).toLowerCase();continue}let a=s.indexOf(":");if(a===-1)continue;let o=s.slice(0,a).trim().toLowerCase(),c=s.slice(a+1).trim();switch(r){case"general":wn(e.general,o,c);break;case"colours":kn(e.colours,o,c);break;case"fonts":xn(e.fonts,o,c);break}}if(e.colours.combo_colors.length===0)e.colours.combo_colors=[...vn];return e},xn=(t,e,r)=>{switch(e){case"hitcircleprefix":if(r.length>0)t.hit_circle_prefix=r.trim();break;case"hitcircleoverlap":{let n=Number.parseInt(r,10);if(Number.isFinite(n))t.hit_circle_overlap=n;break}}},wn=(t,e,r)=>{switch(e){case"name":t.name=r;break;case"author":t.author=r;break;case"version":t.version=r;break;case"hitcircleoverlayabovenumber":case"hitcircleoverlayabovenumer":t.hit_circle_overlay_above_number=ke(r);break;case"sliderballflip":t.slider_ball_flip=ke(r);break;case"allowslidertainttint":case"allowsliderballtint":t.allow_slider_ball_tint=ke(r);break;case"sliderballframes":{let n=Number.parseInt(r,10);if(Number.isFinite(n)&&n>0)t.slider_ball_frames=n;break}case"animationframerate":{let n=Number.parseInt(r,10);if(Number.isFinite(n))t.animation_framerate=n;break}}},kn=(t,e,r)=>{let n=Mn(r);if(!n)return;let i=e.match(/^combo(\d+)$/);if(i){let s=parseInt(i[1])-1;while(t.combo_colors.length<=s)t.combo_colors.push("");t.combo_colors[s]=n;return}switch(e){case"sliderborder":t.slider_border=n;break;case"slidertrackoverride":t.slider_track_override=n;break;case"sliderball":t.slider_ball=n;break;case"spinnerbackground":t.spinner_background=n;break}},Mn=(t)=>{let e=t.split(",").map((s)=>parseInt(s.trim()));if(e.length<3||e.some(isNaN))return null;let[r,n,i]=e;if(e.length>=4){let s=e[3]/255;return`rgba(${r}, ${n}, ${i}, ${s.toFixed(2)})`}return`rgb(${r}, ${n}, ${i})`},sr=(t,e)=>{let r={...t};if(e.colours.combo_colors.length>0)r.combo_colors=e.colours.combo_colors.filter((n)=>n.length>0);if(e.colours.slider_border)r.slider_border_color=e.colours.slider_border;if(e.colours.slider_track_override)r.slider_track_override=e.colours.slider_track_override;if(e.colours.slider_ball)r.slider_ball_color=e.colours.slider_ball;if(e.colours.spinner_background)r.spinner_background_color=e.colours.spinner_background;if(e.general.hit_circle_overlay_above_number!==void 0)r.hit_circle_overlay_above_number=e.general.hit_circle_overlay_above_number;if(e.general.slider_ball_flip!==void 0)r.slider_ball_flip=e.general.slider_ball_flip;if(e.general.allow_slider_ball_tint!==void 0)r.allow_slider_ball_tint=e.general.allow_slider_ball_tint;if(e.general.slider_ball_frames!==void 0)r.slider_ball_frames=e.general.slider_ball_frames;if(e.general.animation_framerate!==void 0)r.animation_framerate=e.general.animation_framerate;if(e.fonts.hit_circle_prefix!==void 0)r.hit_circle_prefix=e.fonts.hit_circle_prefix;if(e.fonts.hit_circle_overlap!==void 0)r.hit_circle_overlap=e.fonts.hit_circle_overlap;return r};var ar=[".png",".jpg",".jpeg",".webp"],cr=(t,e)=>{if(t.has(e))return{name:e,data:t.get(e)};let r=e.toLowerCase();for(let[n,i]of t)if(n.toLowerCase()===r)return{name:n,data:i};for(let[n,i]of t){let s=n.split("/").pop();if(s&&s.toLowerCase()===r)return{name:n,data:i}}return null},In=(t,e)=>{for(let r=0;r<e.length;r++){let n=e[r];for(let i=0;i<ar.length;i++){let s=`${n}${ar[i]}`,a=cr(t,s);if(a)return{filename:a.name,data:a.data}}}return null},Tn=async(t)=>{let e=new Blob([t.data]),r=URL.createObjectURL(e);try{let n=new Image;n.src=r,await n.decode();let i=t.filename.toLowerCase().includes("@2x")?2:1;return{image:{source:n,width:n.naturalWidth/i,height:n.naturalHeight/i},url:r}}catch(n){return URL.revokeObjectURL(r),console.warn(`[Skin] Failed to decode ${t.filename}`,n),null}},lt=(t,e)=>{if(t.width<=e&&t.height<=e)return t;let r=t.source,n=Number(r?.width??0),i=Number(r?.height??0);if(n<=0||i<=0||t.width<=0||t.height<=0)return t;let s=n/t.width,a=i/t.height,o=Math.min(t.width,e),c=Math.min(t.height,e),h=Math.max(1,Math.round(o*s)),_=Math.max(1,Math.round(c*a)),l=Math.max(0,Math.floor((n-h)/2)),d=Math.max(0,Math.floor((i-_)/2)),u=document.createElement("canvas");u.width=h,u.height=_;let p=u.getContext("2d");if(!p)return t;return p.drawImage(t.source,l,d,h,_,0,0,h,_),{source:u,width:o,height:c}},pt=(t,e)=>{if(t.width<e||t.height<e)return null;return t},N=async(t,e)=>{let r=In(t,e);if(!r)return null;return Tn(r)},Rn=async(t,e)=>{let r=[],n=Math.max(1,Math.min(120,e));for(let i=0;i<n;i++){let s=await N(t,[`sliderb${i}@2x`,`sliderb${i}`]);if(!s){if(i===0)continue;break}r.push(s)}return r},Dn=async(t,e)=>{let r=[];for(let n=0;n<10;n++){let i=await N(t,[`${e}-${n}@2x`,`${e}-${n}`]);if(!i)return[];r.push(i)}return r},or=async(t,e)=>{for(let r=0;r<e.length;r++){let n=e[r],i=[];for(let s=0;s<64;s++){let a=await N(t,[`${n}${s}@2x`,`${n}${s}`,`${n}-${s}@2x`,`${n}-${s}`]);if(!a)break;i.push(a)}if(i.length>0)return i}return[]},An=async(t,e)=>{let r=[];for(let n=0;n<128;n++){let i=await N(t,[`${e}-${n}@2x`,`${e}-${n}`]);if(!i)break;r.push(i)}return r},En=(t)=>{let e=cr(t,"skin.ini");if(!e)return null;try{return new TextDecoder("utf-8").decode(e.data)}catch(r){return console.warn("[Skin] Failed to parse skin.ini",r),null}},hr=async(t,e)=>{let r=[],n=t,i=En(e);if(i)n=sr(n,ir(i));let s={},a=await N(e,["hitcircle@2x","hitcircle"]);if(a){let x=pt(lt(a.image,512),32);if(x)s.hitcircle=x,r.push(a.url)}let o=await N(e,["hitcircleoverlay@2x","hitcircleoverlay"]);if(o){let x=pt(lt(o.image,512),32);if(x)s.hitcircleoverlay=x,r.push(o.url)}let c=await N(e,["sliderstartcircle@2x","sliderstartcircle"]);if(c){let x=pt(lt(c.image,512),32);if(x)s.sliderstartcircle=x,r.push(c.url)}let h=await N(e,["sliderstartcircleoverlay@2x","sliderstartcircleoverlay"]);if(h){let x=pt(lt(h.image,512),32);if(x)s.sliderstartcircleoverlay=x,r.push(h.url)}let _=await N(e,["sliderendcircle@2x","sliderendcircle"]);if(_){let x=pt(lt(_.image,512),32);if(x)s.sliderendcircle=x,r.push(_.url)}let l=await N(e,["sliderendcircleoverlay@2x","sliderendcircleoverlay"]);if(l){let x=pt(lt(l.image,512),32);if(x)s.sliderendcircleoverlay=x,r.push(l.url)}let d=await N(e,["approachcircle@2x","approachcircle"]);if(d)s.approachcircle=d.image,r.push(d.url);let u=await Rn(e,n.slider_ball_frames);if(u.length>0){let x=[];for(let T=0;T<u.length;T++)x.push(u[T].image),r.push(u[T].url);s.sliderball_frames=x,s.sliderball=x[0]}else{let x=await N(e,["sliderb@2x","sliderb","sliderball@2x","sliderball"]);if(x)s.sliderball=x.image,r.push(x.url)}let p=await N(e,["sliderb-nd@2x","sliderb-nd"]);if(p)s.sliderball_nd=p.image,r.push(p.url);let m=await N(e,["sliderb-spec@2x","sliderb-spec"]);if(m)s.sliderball_spec=m.image,r.push(m.url);let f=await N(e,["sliderfollowcircle@2x","sliderfollowcircle"]);if(f)s.sliderfollowcircle=f.image,r.push(f.url);let b=await N(e,["reversearrow@2x","reversearrow"]);if(b)s.reversearrow=b.image,r.push(b.url);let y=await or(e,["reversearrow"]);if(y.length>0){let x=[];for(let T=0;T<y.length;T++)x.push(y[T].image),r.push(y[T].url);if(s.reversearrow_frames=x,!s.reversearrow)s.reversearrow=x[0]}let w=await N(e,["sliderb0@2x","sliderb0","sliderb@2x","sliderb"]);if(w)s.sliderb=w.image,r.push(w.url);let D=await N(e,["sliderscorepoint@2x","sliderscorepoint","sliderpoint10@2x","sliderpoint10"]);if(D)s.sliderscorepoint=D.image,r.push(D.url);let O=await N(e,["followpoint@2x","followpoint"]);if(O)s.followpoint=O.image,r.push(O.url);let R=await An(e,"followpoint");if(R.length>0){let x=[];for(let T=0;T<R.length;T++)x.push(R[T].image),r.push(R[T].url);if(s.followpoint_frames=x,!s.followpoint)s.followpoint=x[0]}let M=await Dn(e,n.hit_circle_prefix||"default");if(M.length>0){let x=[];for(let T=0;T<M.length;T++)x.push(M[T].image),r.push(M[T].url);s.combo_digits=x,s.combo_overlap=n.hit_circle_overlap}let k=["mania-stage-left","mania-stage-right","mania-stage-bottom","mania-stage-light","mania-stage-hint","mania-key1","mania-key1d","mania-key2","mania-key2d","mania-keys","mania-keysd","mania-note1","mania-note2","mania-notes","mania-note1h","mania-note2h","mania-notesh","mania-note1l","mania-note2l","mania-notesl","mania-note1t","mania-note2t","mania-notest"],I={},C={};for(let x=0;x<k.length;x++){let T=k[x],S=T.toLowerCase(),L=await N(e,[`${T}@2x`,T]);if(L)I[S]=L.image,r.push(L.url);let W=await or(e,[T]);if(W.length>0){let tt=[];for(let it=0;it<W.length;it++)tt.push(W[it].image),r.push(W[it].url);if(C[S]=tt,!I[S])I[S]=tt[0]}}if(Object.keys(I).length>0)s.mania_textures=I;if(Object.keys(C).length>0)s.mania_animations=C;return{config:n,elements:s,dispose:()=>{for(let x=0;x<r.length;x++)URL.revokeObjectURL(r[x])}}};import Hn from"jszip";var Me=null,ut=null,Ie=null,xt=null,On=(t)=>{let e=atob(t),r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r.buffer},Nn=async()=>{if(Me)return Me;if(ut)return ut;return ut=import("./chunk-h72ajp0p.js").then((t)=>{return Me=t.DEFAULT_SKIN_ARCHIVE_BASE64,ut=null,t.DEFAULT_SKIN_ARCHIVE_BASE64}).catch((t)=>{throw ut=null,t}),ut},_r=async()=>{if(Ie)return Ie;if(xt)return xt;return xt=(async()=>{let t=await Nn(),e=On(t),r=await Hn.loadAsync(e),n=new Map,i=Object.entries(r.files);for(let s=0;s<i.length;s++){let[a,o]=i[s];if(o.dir)continue;n.set(a,await o.async("arraybuffer"))}return Ie=n,xt=null,n})(),xt};import Sn from"jszip";var dr=(t)=>{let e=new Map;for(let[r,n]of t){if(n instanceof ArrayBuffer){e.set(r,n);continue}e.set(r,new TextEncoder().encode(n).buffer)}return e},lr=async(t)=>{let e=await Sn.loadAsync(t),r=new Map,n=Object.entries(e.files);for(let i=0;i<n.length;i++){let[s,a]=n[i];if(a.dir)continue;r.set(s,await a.async("arraybuffer"))}return r},pr=(t,e)=>{let r=new Map;if(t)for(let[n,i]of t)r.set(n,i);if(e)for(let[n,i]of e)r.set(n,i);return r},ur=(t,e,r)=>{let n=new Map(t);if(e){for(let[i,s]of e)if(!n.has(i))n.set(i,s)}if(r){for(let[i,s]of r)if(!n.has(i))n.set(i,s)}return n};var Ln=0.42,Bn=30,Fn=100,Vn=100;class fr{backend;backend_ready;backend_initialized=!1;renderer=null;audio_context;audio;hitsounds;video=null;resources=null;animation_frame=null;skin;base_skin;mods;custom_rate=null;renderer_config;start_offset;start_mode;custom_start_time;music_volume;hitsound_volume;audio_offset;beatmap_audio_lead_in=0;background_url=null;loaded_skin_elements=null;loaded_skin_dispose=null;should_load_default_skin=!0;default_skin_files=null;default_skin_loading=null;custom_skin_files=null;listeners=new Map;is_loaded_flag=!1;hitsound_scheduler;timing_points=[];timing_resolver=null;resize_observer=null;key_handler=null;options;enable_fps_counter=!1;fps_frame_count=0;fps_last_update=0;current_fps=0;time_smoothing=0.1;smoothed_delta=0;max_frame_delta=100;resync_threshold_ms=Bn;debug_sync=!1;debug_sync_last_emit_at=0;last_timestamp=0;smooth_time=0;constructor(t){this.options=t,this.backend=re(t.backend_type??"auto"),this.skin=ce(),this.base_skin=this.skin,this.mods=t.mods??0,this.renderer_config={...K,...t.renderer_config},this.calculate_layout(t.canvas.width,t.canvas.height,t.playfield_scale),this.start_mode=t.start_mode??(Number.isFinite(t.start_time)?"custom":"preview"),this.custom_start_time=Number.isFinite(t.start_time)?Math.max(0,t.start_time):null,this.start_offset=0,this.music_volume=t.volume??0.5,this.hitsound_volume=t.hitsound_volume??0.25,this.audio_offset=t.audio_offset??20,this.backend_ready=this.backend.initialize(t.canvas,this.renderer_config.use_high_dpi).then(()=>{this.backend_initialized=!0});let e=window.AudioContext??window.webkitAudioContext;if(!e)throw Error("Web Audio API is not supported in this environment");if(this.audio_context=new e,this.audio=new Pt(this.audio_context),this.hitsounds=new ve(this.audio_context),this.hitsound_scheduler=new we(this.audio,this.hitsounds),this.hitsound_scheduler.set_hitsound_lookahead(t.hitsound_lookahead_ms??Vn),this.audio.set_volume(this.music_volume),this.hitsounds.set_volume(this.hitsound_volume),t.auto_resize)this.setup_auto_resize();this.enable_fps_counter=t.enable_fps_counter??!1,this.fps_last_update=performance.now();let r=t.time_smoothing;if(Number.isFinite(r))this.time_smoothing=Math.max(0,Math.min(1,r));let n=t.max_frame_delta;if(Number.isFinite(n))this.max_frame_delta=Math.max(10,n);let i=t.audio_resync_threshold_ms;if(Number.isFinite(i))this.resync_threshold_ms=Math.max(0,i);this.debug_sync=t.debug_sync??!1}async load_osz(t,e){try{let n=await new st().load_osz(t,{difficulty:e});return this.resources=n,this.setup()}catch(r){let n=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",n),U("INVALID_BEATMAP",n)}}async load_files(t,e){try{let r=new st;return this.resources=await r.load_from_files(t,{difficulty:e}),this.setup()}catch(r){let n=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",n),U("INVALID_BEATMAP",n)}}async load_custom_hitsounds(t){if(t.length==0){console.warn("[BeatmapPlayer] No custom hitsound URLs were provided"),this.hitsounds.clear();return}try{await this.hitsounds.load_samples(t)}catch(e){console.error("[BeatmapPlayer] Failed to load custom hitsounds:",e)}}async load_map_custom_hitsounds(){if(!this.resources?.beatmap)return;let t=ur(this.resources.files,this.custom_skin_files,this.default_skin_files),e=nr(this.resources.beatmap,t,this.resources.audio_filename);if(e.size==0){this.hitsounds.clear();return}try{await this.hitsounds.load_samples_from_files(e)}catch(r){console.error("[BeatmapPlayer] Failed to load map custom hitsounds:",r),this.hitsounds.clear()}}async load_beatmap(t,e,r,n,i){return this.resources={beatmap:t,available_difficulties:[],files:new Map,audio:e,background:r,video:n,video_offset:i},this.setup()}async load_osu_content(t,e){try{await mr();let r=await this.parse_content(t);return this.load_beatmap(r,e)}catch(r){let n=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",n),U("INVALID_BEATMAP",n)}}async load_beatmap_files(t,e,r,n,i){try{await mr();let s=typeof t==="string",a=t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):null,o=await this.parse_content(s?t:a);return this.load_beatmap(o,e,r,n,i)}catch(s){let a=s instanceof Error?s.message:String(s);return this.emit("error","INVALID_BEATMAP",a),U("INVALID_BEATMAP",a)}}async setup(){if(!this.resources)return U("NOT_LOADED","No resources loaded");try{await this.backend_ready}catch(i){let s=i instanceof Error?i.message:String(i);return this.emit("error","UNKNOWN",s),U("UNKNOWN",s)}let{beatmap:t}=this.resources;this.timing_points=Bt([...t.TimingPoints]),this.timing_resolver=new yt(this.timing_points),this.resolve_assets(),await this.load_map_skin();let{audio:e,video:r,video_offset:n}=this.resources;if(e)try{await this.audio.load(e,this.resolve_speed_multiplier()),this.release_loaded_audio_bytes()}catch(i){let s=i instanceof Error?i.message:String(i);return this.emit("error","AUDIO_DECODE_ERROR",s),U("AUDIO_DECODE_ERROR",s)}if(this.beatmap_audio_lead_in=Math.max(0,t.General.AudioLeadIn||0),this.hitsound_scheduler.set_context(this.resources,this.timing_points,this.timing_resolver,this.get_effective_audio_offset()),this.load_map_custom_hitsounds(),r)this.video=new jt,await this.video.load(r,n??0);try{this.renderer=this.create_renderer(t),this.renderer.initialize(t),this.renderer.precompute()}catch(i){let s=i instanceof Error?i.message:String(i);return this.emit("error","UNSUPPORTED_MODE",s),U("UNSUPPORTED_MODE",s)}return this.start_offset=this.resolve_initial_start_offset(),this.hitsound_scheduler.update_hit_index(this.start_offset),this.load_background(),this.is_loaded_flag=!0,this.emit("loaded",t,this.resources),requestAnimationFrame(()=>this.render_frame(this.start_offset)),De(this.resources)}async load_background(){if(this.resources)this.resolve_assets();if(!this.resources?.background||!this.renderer)return;try{let t=new Image;if(this.background_url)URL.revokeObjectURL(this.background_url);this.background_url=URL.createObjectURL(this.resources.background),t.src=this.background_url,await t.decode(),this.renderer.set_background({source:t,width:t.width,height:t.height});let e=this.audio.is_playing?this.current_time:this.start_offset;requestAnimationFrame(()=>this.render_frame(e))}catch(t){console.warn("[BeatmapPlayer] Failed to load background",t)}}resolve_assets(){if(!this.resources)return;let t=new xe(this.resources).resolve();if(!this.resources.audio&&t.audio)this.resources.audio=t.audio;if(!this.resources.background&&t.background)this.resources.background=t.background;if(!this.resources.video&&t.video)this.resources.video=t.video;if(!this.resources.video_offset&&t.video_offset)this.resources.video_offset=t.video_offset}release_loaded_audio_bytes(){if(!this.resources)return;this.resources.audio=void 0;let t=this.resources.audio_filename?.toLowerCase();if(!t)return;for(let e of Array.from(this.resources.files.keys()))if(e.toLowerCase()===t)this.resources.files.delete(e)}create_renderer(t){switch(t.General.Mode){case 0:return new Vt(this.backend,this.skin,this.mods,this.renderer_config,this.loaded_skin_elements);case 3:return new G(this.backend,this.skin,this.mods,this.renderer_config,this.loaded_skin_elements);case 1:case 2:default:throw Error(`Unsupported game mode: ${Ut[t.General.Mode]??t.General.Mode}`)}}get_last_object_time(){if(!this.resources?.beatmap.HitObjects.length)return 0;let t=this.resources.beatmap.HitObjects,e=0;for(let r of t){let n=r.endTime||r.time;if(n>e)e=n}return e}resolve_preview_start_offset(){if(!this.resources?.beatmap)return 0;let t=this.resources.beatmap.General.PreviewTime;if(t>0)return t;return Math.max(0,this.get_last_object_time()*Ln)}resolve_initial_start_offset(){let t=Math.max(0,this.duration),e=this.resources?.beatmap?.General.Mode;if(this.start_mode=="beginning")return 0;if(this.start_mode=="custom"){if(this.custom_start_time!==null)return Math.max(0,Math.min(this.custom_start_time,t));return Math.max(0,Math.min(this.resolve_preview_start_offset(),t))}if(e===3)return 0;return Math.max(0,Math.min(this.resolve_preview_start_offset(),t))}async play(){if(!this.renderer||!this.is_loaded_flag){console.warn("[BeatmapPlayer] Cannot play: not loaded");return}if(this.audio.is_playing)return;if(this.audio_context.state==="suspended")await this.audio_context.resume();try{await this.audio.play(this.to_track_time(this.start_offset))}catch(t){console.warn("[BeatmapPlayer] Failed to start audio",t),this.emit("statechange",!1);return}this.video?.play(),this.start_render_loop(),this.emit("play"),this.emit("statechange",!0)}pause(){if(!this.audio.is_playing)return;this.start_offset=this.to_beatmap_time(this.audio.current_time),this.audio.pause(),this.video?.pause(),this.stop_render_loop(),this.emit("pause"),this.emit("statechange",!1)}set_mods(t){this.mods=t;let e=this.resolve_speed_multiplier();if(this.renderer?.set_mods(t),this.audio.set_speed(e),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}set_rate(t){if(t===null)this.custom_rate=null;else if(Number.isFinite(t))this.custom_rate=Math.max(0.1,t);if(this.audio.set_speed(this.resolve_speed_multiplier()),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}seek(t){this.start_offset=Math.max(0,Math.min(t,this.duration)),this.hitsound_scheduler.update_hit_index(this.start_offset),this.audio.seek(this.to_track_time(this.start_offset)),this.video?.seek(this.start_offset),this.video?.sync(this.start_offset),this.last_timestamp=performance.now(),this.smooth_time=this.start_offset,this.smoothed_delta=0,this.emit("seek",this.start_offset),this.render_frame(this.start_offset),this.renderer?.on_seek(this.start_offset)}async set_difficulty(t){if(!this.resources)return U("NOT_LOADED","No beatmap resources loaded");let e=this.is_playing;this.stop();try{let n=await new st().load_from_files(this.resources.files,{difficulty:t});this.resources=n;let i=await this.setup();if(i.success&&e)this.play();return i}catch(r){let n=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",n),U("INVALID_BEATMAP",n)}}async parse_content(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;return await Cn(e)}stop(){this.pause(),this.start_offset=0,this.audio.seek(this.to_track_time(0)),this.hitsound_scheduler.update_hit_index(0),this.render_frame(0)}dispose(){if(this.stop(),this.backend.dispose(),this.audio.dispose(),this.hitsounds.dispose(),this.video?.dispose(),this.renderer?.dispose(),this.background_url)URL.revokeObjectURL(this.background_url),this.background_url=null;if(this.resize_observer)this.resize_observer.disconnect(),this.resize_observer=null;if(this.key_handler)window.removeEventListener("keydown",this.key_handler),this.key_handler=null;if(this.audio_context&&this.audio_context.state!=="closed")this.audio_context.close().catch(()=>{});this.renderer=null,this.resources=null,this.is_loaded_flag=!1,this.listeners.clear(),this.release_loaded_skin()}get current_time(){return this.to_beatmap_time(this.audio.current_time)}get duration(){if(this.audio.duration>0)return Math.max(0,this.audio.duration-this.beatmap_audio_lead_in);return this.get_last_object_time()}get is_playing(){return this.audio.is_playing}get is_loaded(){return this.is_loaded_flag}get mode(){if(!this.resources)return"standard";switch(this.resources.beatmap.General.Mode){case 1:return"taiko";case 2:return"catch";case 3:return"mania";default:return"standard"}}get beatmap(){return this.resources?.beatmap??null}get available_difficulties(){return this.resources?.available_difficulties??[]}get background(){return this.resources?.background}get config(){return this.renderer_config}resize(t,e,r){if(this.backend.resize(t,e),this.calculate_layout(t,e,r),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}update_config(t){if(this.renderer_config={...this.renderer_config,...t},this.renderer?.update_config(this.renderer_config),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}async load_skin_files(t){if(!t){this.custom_skin_files=null,await this.reload_skin_runtime();return}this.custom_skin_files=dr(t),await this.reload_skin_runtime()}async load_skin_osk(t){await this.load_skin_files(await lr(t))}clear_loaded_skin(){this.custom_skin_files=null,this.reload_skin_runtime()}async load_map_skin(){if(this.release_loaded_skin(),!this.resources)return;try{await this.ensure_default_skin_loaded();let t=this.merge_skin_sources(),e=await hr(this.base_skin,t);this.skin=e.config,this.loaded_skin_elements=e.elements,this.loaded_skin_dispose=e.dispose}catch(t){console.warn("[BeatmapPlayer] Failed to load map skin assets",t),this.skin=this.base_skin,this.loaded_skin_elements=null,this.loaded_skin_dispose=null}}release_loaded_skin(){if(this.loaded_skin_dispose)this.loaded_skin_dispose(),this.loaded_skin_dispose=null;this.loaded_skin_elements=null}async ensure_default_skin_loaded(){if(!this.should_load_default_skin){this.default_skin_files=null;return}await this.load_default_skin_files()}async load_default_skin_files(){if(this.default_skin_files)return;if(this.default_skin_loading){await this.default_skin_loading;return}this.default_skin_loading=(async()=>{try{this.default_skin_files=await _r()}catch(t){console.warn("[BeatmapPlayer] Failed to load embedded default skin",t),this.default_skin_files=null}})(),await this.default_skin_loading,this.default_skin_loading=null}merge_skin_sources(){return pr(this.default_skin_files,this.custom_skin_files)}setup_auto_resize(){this.resize_observer=new ResizeObserver(()=>{let e=this.options.canvas.parentElement;if(e){let r=e.getBoundingClientRect();this.resize(r.width,r.height,this.options.playfield_scale)}}),this.resize_observer.observe(this.options.canvas.parentElement||this.options.canvas)}toggle_pause(){if(!this.is_loaded_flag)return;if(this.is_playing)this.pause();else this.play()}toggle_grid(){if(this.renderer_config.grid_level===0)this.renderer_config.grid_level=32;else this.renderer_config.grid_level=0;this.render_frame(this.current_time)}calculate_layout(t,e,r){let s=0.9;if(Number.isFinite(r))s=r;let a=t*s/512,o=e*s/384,c=Math.min(a,o);if(this.renderer_config.scale=c,this.renderer_config.offset_x=Math.floor((t-512*c)/2),this.renderer_config.offset_y=Math.floor((e-384*c)/2),this.renderer)this.renderer.update_config(this.renderer_config)}set_volume(t){this.music_volume=t,this.audio.set_volume(t)}set_hitsound_volume(t){this.hitsound_volume=t,this.hitsounds.set_volume(t)}set_offset(t){if(this.audio_offset=t,this.hitsound_scheduler.set_audio_offset(this.get_effective_audio_offset()),this.is_loaded_flag)this.seek(this.current_time)}on(t,e){if(!this.listeners.has(t))this.listeners.set(t,new Set);this.listeners.get(t).add(e)}off(t,e){this.listeners.get(t)?.delete(e)}emit(t,...e){let r=this.listeners.get(t);if(r)for(let n of r)n(...e)}start_render_loop(){if(this.animation_frame!==null)return;this.last_timestamp=performance.now(),this.smooth_time=this.current_time,this.smoothed_delta=0;let t=(e)=>{if(!this.audio.is_playing){this.animation_frame=null;return}let r=Math.max(0,e-this.last_timestamp);this.last_timestamp=e;let n=Math.min(r,this.max_frame_delta);if(this.time_smoothing>0){if(this.smoothed_delta===0)this.smoothed_delta=n;else this.smoothed_delta+=(n-this.smoothed_delta)*this.time_smoothing;n=this.smoothed_delta}this.smooth_time+=n*this.audio.speed_multiplier;let i=this.current_time;if(Math.abs(this.smooth_time-i)>this.resync_threshold_ms)this.smooth_time=i;else this.smooth_time+=(i-this.smooth_time)*0.1;let a=this.smooth_time,o=this.hitsound_scheduler.schedule_hitsounds(i);if(this.debug_sync)this.emit_debug_sync(i,a,o);if(this.render_frame(a),this.video?.sync(a),this.emit("timeupdate",a,this.duration),a>=this.duration){this.emit("ended"),this.stop_render_loop(),this.emit("statechange",!1);return}this.animation_frame=requestAnimationFrame(t)};this.animation_frame=requestAnimationFrame(t)}stop_render_loop(){if(this.animation_frame!==null)cancelAnimationFrame(this.animation_frame),this.animation_frame=null}render_frame(t){if(!this.backend_initialized)return;if(this.backend.begin_frame?.(),this.backend.clear(),this.renderer?.render(t),this.enable_fps_counter){this.fps_frame_count++;let e=performance.now(),r=e-this.fps_last_update;if(r>=1000)this.current_fps=Math.round(this.fps_frame_count*1000/r),this.fps_frame_count=0,this.fps_last_update=e;let n=`14px ${this.skin.default_font??"monospace"}`;this.backend.draw_text(`${this.current_fps} FPS`,10,20,n,"rgba(255,255,255,0.8)","left","top")}this.backend.end_frame?.()}emit_debug_sync(t,e,r){let n=performance.now();if(n-this.debug_sync_last_emit_at<Fn)return;this.debug_sync_last_emit_at=n,this.emit("debugsync",{audio_time_raw:this.audio.current_time,beatmap_time:t,render_time:e,drift_ms:e-t,scheduled_hitsounds:r})}set_fps_counter(t){this.enable_fps_counter=t}get_effective_audio_offset(){return this.audio_offset+this.beatmap_audio_lead_in}to_track_time(t){return Math.max(0,t+this.get_effective_audio_offset())}to_beatmap_time(t){return Math.max(0,t-this.get_effective_audio_offset())}resolve_speed_multiplier(){return this.custom_rate??Ae(this.mods)}async reload_skin_runtime(){if(!this.is_loaded_flag||!this.resources?.beatmap)return;let t=this.resources.beatmap,e=this.current_time;await this.load_map_skin(),this.renderer=this.create_renderer(t),this.renderer.initialize(t),requestAnimationFrame(()=>this.render_frame(e))}}var Pn=(t)=>{return new URL(t,import.meta.url).toString()};var jn=(t)=>{return Pn(t)};export{$n as unwrap,Kn as toggle_mod,jn as resolve_runtime_asset_url,De as ok,Gn as mods_to_string,qn as mods_from_string,ce as merge_skin,j as is_spinner,et as is_slider,Yn as is_ok,Te as is_new_combo,Wt as is_hold,Wn as is_err,Yt as is_circle,E as has_mod,Ae as get_speed_multiplier,Lr as get_rate_multiplier,ht as get_mania_lane_color,q as get_combo_color,Xn as get_available_mods,qe as get_adjusted_difficulty,U as err,re as create_backend,Fr as apply_rate_to_ar,Br as apply_mods_to_difficulty,jt as VideoController,Vt as StandardRenderer,br as SpeedChangingMods,$t as SampleSet,At as PixiBackend,Qt as PLAYFIELD_WIDTH,Jt as PLAYFIELD_HEIGHT,st as OszLoader,g as Mods,Hr as ModNightcore,Cr as ModHidden,ie as ModHardRock,Or as ModHalfTime,se as ModEasy,Er as ModDoubleTime,G as ManiaRenderer,wt as HitSoundType,P as HitObjectType,Sr as HD_FADE_OUT_MULTIPLIER,Nr as HD_FADE_IN_MULTIPLIER,Ne as GridLevel,Ut as GameMode,Re as ErrorCode,Jn as DifficultyChangingMods,oe as DEFAULT_SKIN,K as DEFAULT_RENDERER_CONFIG,fr as BeatmapPlayer,at as BaseRenderer,Pt as AudioController};
|
|
1
|
+
import"./chunk-1d7vwgnw.js";import"./chunk-shgm3fs6.js";import"./chunk-029sagwa.js";import"./chunk-vkkhj28s.js";import"./chunk-tqbn5m4a.js";import{w as ee}from"./chunk-3baewprq.js";import{A as It,E as Ye}from"./chunk-z898rh1p.js";import{$ as Jt,Z as tt,_ as $e,ba as te}from"./chunk-w1tshfsy.js";import"./chunk-n2mqbpq5.js";import"./chunk-jyb1nvnr.js";import"./chunk-0we37sfj.js";import"./chunk-aeeawe99.js";import"./chunk-598ehnf5.js";import"./chunk-3wjb2nvs.js";import"./chunk-8wvq4dfz.js";import{Ka as W,La as z,Ra as X,Ta as Kt,Va as Xt,Za as Zt,db as zt,ib as L,jb as bt}from"./chunk-sqnzgty6.js";import{yb as ct}from"./chunk-cs4e65d1.js";var $t;((s)=>{s[s.Standard=0]="Standard";s[s.Taiko=1]="Taiko";s[s.Catch=2]="Catch";s[s.Mania=3]="Mania"})($t||={});var Yt;((s)=>{s[s.Auto=0]="Auto";s[s.Normal=1]="Normal";s[s.Soft=2]="Soft";s[s.Drum=3]="Drum"})(Yt||={});var j={Circle:1,Slider:2,NewCombo:4,Spinner:8,ComboSkip:112,Hold:128},kt={Normal:1,Whistle:2,Finish:4,Clap:8},Qt=(t)=>(t.type&j.Circle)!==0,it=(t)=>(t.type&j.Slider)!==0,U=(t)=>(t.type&j.Spinner)!==0,Wt=(t)=>(t.type&j.Hold)!==0,De=(t)=>(t.type&j.NewCombo)!==0;var Ee;((c)=>{c.NoOsuFiles="NO_OSU_FILES";c.DifficultyNotFound="DIFFICULTY_NOT_FOUND";c.InvalidBeatmap="INVALID_BEATMAP";c.UnsupportedMode="UNSUPPORTED_MODE";c.AudioNotLoaded="AUDIO_NOT_LOADED";c.AudioDecodeError="AUDIO_DECODE_ERROR";c.NotLoaded="NOT_LOADED";c.Unknown="UNKNOWN"})(Ee||={});var He=(t)=>({success:!0,data:t}),F=(t,e)=>({success:!1,code:t,reason:e}),Ki=(t)=>{if(t.success)return t.data;throw Error(`[${t.code}] ${t.reason}`)},Xi=(t)=>{return t.success},Zi=(t)=>{return!t.success};var g={None:0,NoFail:1,Easy:2,TouchDevice:4,Hidden:8,HardRock:16,SuddenDeath:32,DoubleTime:64,Relax:128,HalfTime:256,Nightcore:512,Flashlight:1024,Autoplay:2048,SpunOut:4096,Autopilot:8192,Perfect:16384,FadeIn:8388608,Mirror:1073741824},wr=g.DoubleTime|g.HalfTime|g.Nightcore,ts=g.HardRock|g.Easy|wr,es=(t)=>{let e=0,r=t.toLowerCase(),i={nf:g.NoFail,ez:g.Easy,td:g.TouchDevice,hd:g.Hidden,hr:g.HardRock,sd:g.SuddenDeath,dt:g.DoubleTime,rx:g.Relax,ht:g.HalfTime,nc:g.Nightcore,fl:g.Flashlight,at:g.Autoplay,so:g.SpunOut,ap:g.Autopilot,pf:g.Perfect,fi:g.FadeIn,mr:g.Mirror};for(let s=0;s<r.length-1;s+=2){let n=r.slice(s,s+2);if(i[n])e|=i[n]}return e},rs=(t)=>{let e=[];if(t&g.NoFail)e.push("NF");if(t&g.Easy)e.push("EZ");if(t&g.Hidden)e.push("HD");if(t&g.HardRock)e.push("HR");if(t&g.SuddenDeath)e.push("SD");if(t&g.DoubleTime)e.push("DT");if(t&g.HalfTime)e.push("HT");if(t&g.Nightcore)e.push("NC");if(t&g.Flashlight)e.push("FL");if(t&g.SpunOut)e.push("SO");if(t&g.FadeIn)e.push("FI");if(t&g.Mirror)e.push("MR");let r=e.indexOf("DT"),i=e.indexOf("NC");if(r>=0&&i>=0)e.splice(r,1);return e.join("")},Ne=(t)=>{if(t&(g.DoubleTime|g.Nightcore))return 1.5;if(t&g.HalfTime)return 0.75;return 1},kr=[g.HardRock|g.Easy,g.DoubleTime|g.HalfTime|g.Nightcore,g.Hidden|g.FadeIn],is=(t,e)=>{if(t&e)return t&~e;let r=t;for(let i of kr)if(e&i)r&=~i;return r|e},H=(t,e)=>(t&e)!==0,ss=(t)=>{let e=[{name:"Easy",acronym:"EZ",value:g.Easy},{name:"Hidden",acronym:"HD",value:g.Hidden},{name:"Double Time",acronym:"DT",value:g.DoubleTime},{name:"Half Time",acronym:"HT",value:g.HalfTime},{name:"Nightcore",acronym:"NC",value:g.Nightcore}];switch(t){case"standard":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock}];case"mania":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock},{name:"Fade In",acronym:"FI",value:g.FadeIn}];case"taiko":case"catch":return[...e,{name:"Hard Rock",acronym:"HR",value:g.HardRock}];default:return e}};import{init_wasm as Ce,parse as Se}from"@rel-packages/osu-beatmap-parser/browser";import Oe from"jszip";class at{async load_osz(t,e){await Ce();let r=await Oe.loadAsync(t),i=new Map;for(let[s,n]of Object.entries(r.files))if(!n.dir)i.set(s,await n.async("arraybuffer"));return this.load_from_files(i,e)}async load_from_files(t,e){await Ce();let r=[];for(let f of t.keys())if(f.toLowerCase().endsWith(".osu"))r.push(f);if(r.length===0)throw Error("No .osu files found in beatmap");let i=[];for(let f=0;f<r.length;f++){let b=r[f],v=t.get(b),w=this.to_bytes(v),T=await Se(w);i.push({filename:b,beatmap:T})}let s=this.select_difficulty(r,i,e?.difficulty),n=t.get(s),a=this.to_bytes(n),o=await Se(a),c=o.General.AudioFilename||null,_=o.Events.background?.filename||null,h=o.Events.video?.filename||null,p=o.Events.video?.startTime??0,d=new Map;for(let[f,b]of t)if(b instanceof ArrayBuffer)d.set(f,b);else d.set(f,new TextEncoder().encode(b).buffer);let m;if(c)m=this.find_file(d,c);let l;if(_){let f=this.find_file(d,_);if(f)l=new Blob([f])}let u;if(h){let f=this.find_file(d,h);if(f)u=new Blob([f])}return{beatmap:o,available_difficulties:i,files:d,audio:m,background:l,video:u,audio_filename:c??void 0,background_filename:_??void 0,video_filename:h??void 0,video_offset:h?p:void 0}}async list_difficulties(t){let e=await Oe.loadAsync(t),r=[];for(let s of Object.keys(e.files))if(s.toLowerCase().endsWith(".osu"))r.push(s);let i=[];for(let s of r){let a=(await e.files[s].async("string")).match(/Version:\s*(.+)/);i.push(a?a[1].trim():s)}return i}select_difficulty(t,e,r){if(r===void 0)return t[0];if(typeof r==="number"){if(r<0||r>=t.length)throw Error(`Difficulty index ${r} out of range (0-${t.length-1})`);return t[r]}let i=e.find((a)=>a.beatmap.Metadata.Version===r);if(i)return i.filename;let s=r.toLowerCase(),n=e.find((a)=>a.filename.toLowerCase().includes(s)||a.beatmap.Metadata.Version.toLowerCase().includes(s));if(n)return n.filename;throw Error(`Difficulty "${r}" not found`)}find_file(t,e){if(t.has(e))return t.get(e);let r=e.toLowerCase();for(let[i,s]of t)if(i.toLowerCase()===r)return s;return}to_bytes(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);return new TextEncoder().encode(t)}}import{init_wasm as yr,parse as $i}from"@rel-packages/osu-beatmap-parser/browser";var Gt=512,qt=384,Le;((n)=>{n[n.None=0]="None";n[n.Large=32]="Large";n[n.Medium=16]="Medium";n[n.Small=8]="Small";n[n.Tiny=4]="Tiny"})(Le||={});var K={offset_x:64,offset_y:48,scale:1,show_playfield:!0,playfield_color:"#ffffff",playfield_opacity:0.1,grid_level:0,grid_color:"#ffffff",grid_opacity:0.35,use_high_dpi:!0,enable_stacking:!0};class ot{backend;skin;config;mods;skin_elements;beatmap;objects=[];background_image=null;constructor(t,e,r=0,i=K,s=null){this.backend=t,this.skin=e,this.mods=r,this.config={...K,...i},this.skin_elements=s}set_background(t){this.background_image=t}update_config(t){this.config={...this.config,...t}}precompute(t=0){}on_seek(t){}dispose(){this.objects=[]}render_playfield(t,e,r,i){if(!this.config.show_playfield)return;let{backend:s,config:n}=this,a=t??512,o=e??384,c=r??0,_=i??0;s.save(),s.set_alpha(n.playfield_opacity),s.begin_path(),s.move_to(c,_),s.line_to(c+a,_),s.line_to(c+a,_+o),s.line_to(c,_+o),s.line_to(c,_),s.stroke_path(n.playfield_color,2),s.restore()}render_grid(){if(this.config.grid_level===0)return;let{backend:t,config:e}=this,r=e.grid_level;t.save(),t.set_alpha(e.grid_opacity);for(let i=0;i<=512;i+=r)t.begin_path(),t.move_to(i,0),t.line_to(i,384),t.stroke_path(e.grid_color,i%(r*4)===0?1:0.5);for(let i=0;i<=384;i+=r)t.begin_path(),t.move_to(0,i),t.line_to(512,i),t.stroke_path(e.grid_color,i%(r*4)===0?1:0.5);t.restore()}render_background(){if(!this.background_image)return;let{backend:t}=this;t.save(),t.set_alpha(0.3);let{width:e,height:r}=t,{width:i,height:s}=this.background_image;if(i>0&&s>0){let n=Math.max(e/i,r/s),a=i*n,o=s*n,c=(e-a)/2,_=(r-o)/2;t.draw_image(this.background_image,c,_,a,o)}else t.draw_image(this.background_image,0,0,e,r);t.restore()}get_visible_objects(t,e,r){let i=[];for(let s=0;s<this.objects.length;s++){let n=this.objects[s],a=n.time-e,o=n.end_time+r;if(t>=a&&t<=o)i.push(n)}return i}}var Be={extension:{type:W.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await import("./chunk-d7xgaxzy.js")}};var Pe={extension:{type:W.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await import("./chunk-hbfgn274.js")}};var Mt;function Fe(t){if(Mt!==void 0)return Mt;return Mt=(()=>{let e={stencil:!0,failIfMajorPerformanceCaveat:t??It.defaultOptions.failIfMajorPerformanceCaveat};try{if(!bt.get().getWebGLRenderingContext())return!1;let i=bt.get().createCanvas().getContext("webgl",e),s=!!i?.getContextAttributes()?.stencil;if(i){let n=i.getExtension("WEBGL_lose_context");if(n)n.loseContext()}return i=null,s}catch(r){return!1}})(),Mt}var Tt;async function Ve(t={}){if(Tt!==void 0)return Tt;return Tt=await(async()=>{let e=bt.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(t)).requestDevice(),!0}catch(r){return!1}})(),Tt}var je=["webgl","webgpu","canvas"];async function Ue(t){let e=[];if(t.preference)e.push(t.preference),je.forEach((n)=>{if(n!==t.preference)e.push(n)});else e=je.slice();let r,i={};for(let n=0;n<e.length;n++){let a=e[n];if(a==="webgpu"&&await Ve()){let{WebGPURenderer:o}=await import("./chunk-bxvb53d0.js");r=o,i={...t,...t.webgpu};break}else if(a==="webgl"&&Fe(t.failIfMajorPerformanceCaveat??It.defaultOptions.failIfMajorPerformanceCaveat)){let{WebGLRenderer:o}=await import("./chunk-p0te881m.js");r=o,i={...t,...t.webgl};break}else if(a==="canvas"){let{CanvasRenderer:o}=await import("./chunk-amhps2v2.js");r=o,i={...t,...t.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!r)throw Error("No available renderer for the current environment");let s=new r;return await s.init(i),s}class Rt{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){if(globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e)globalThis.addEventListener("resize",this.queueResize),this.resize()},get(){return this._resizeTo}}),this.queueResize=()=>{if(!this._resizeTo)return;this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize())},this._cancelResize=()=>{if(this._resizeId)cancelAnimationFrame(this._resizeId),this._resizeId=null},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,r;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,r=globalThis.innerHeight;else{let{clientWidth:i,clientHeight:s}=this._resizeTo;e=i,r=s}this.renderer.resize(e,r),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Rt.extension=W.Application;class At{static init(t){if(t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){if(this._ticker)this._ticker.remove(this.render,this);if(this._ticker=e,e)e.add(this.render,this,$e.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?Jt.shared:new Jt,t.autoStart)this.start()}static destroy(){if(this._ticker){let t=this._ticker;this.ticker=null,t.destroy()}}}At.extension=W.Application;z.add(Rt);z.add(At);var Qe=class t{constructor(...e){if(this.stage=new tt,e[0]!==void 0)Xt(Kt,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new tt),this.renderer=await Ue(e),t._plugins.forEach((r)=>{r.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return Xt(Kt,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,r=!1){let i=t._plugins.slice(0);i.reverse(),i.forEach((s)=>{s.destroy.call(this)}),this.stage.destroy(r),this.stage=null,this.renderer.destroy(e),this.renderer=null}};Qe._plugins=[];var Dt=Qe;z.handleByList(W.Application,Dt._plugins);z.add(Ye);z.add(Be,Pe);class _t{items=new Map;max_entries;on_evict;constructor(t,e){this.max_entries=Math.max(1,Math.floor(t)),this.on_evict=e}get size(){return this.items.size}has(t){return this.items.has(t)}get(t){let e=this.items.get(t);if(e===void 0)return;return this.items.delete(t),this.items.set(t,e),e}set(t,e){if(this.items.has(t)){let r=this.items.get(t);this.items.delete(t),this.emit_evict(t,r,"replace")}this.items.set(t,e),this.enforce_capacity()}touch(t){let e=this.items.get(t);if(e===void 0)return!1;return this.items.delete(t),this.items.set(t,e),!0}delete(t){let e=this.items.get(t);if(e===void 0)return!1;return this.items.delete(t),this.emit_evict(t,e,"delete"),!0}clear(){if(this.items.size===0)return;let t=Array.from(this.items.entries());this.items.clear();for(let e=0;e<t.length;e++)this.emit_evict(t[e][0],t[e][1],"clear")}set_capacity(t){this.max_entries=Math.max(1,Math.floor(t)),this.enforce_capacity()}evict_oldest(){let t=this.items.entries().next();if(t.done)return!1;let[e,r]=t.value;return this.items.delete(e),this.emit_evict(e,r,"evict"),!0}entries(){return this.items.entries()}enforce_capacity(){while(this.items.size>this.max_entries)this.evict_oldest()}emit_evict(t,e,r){if(this.on_evict)this.on_evict(t,e,r)}}var Mr={color:16777215,alpha:1},Ir=128,Tr=192;class Et{app=null;root=null;state;stack=[];texture_cache=new Map;gradient_texture_cache=new _t(Ir,(t,e)=>{if(e&&e!==L.WHITE)e.destroy(!0)});text_texture_cache=new _t(Tr,(t,e)=>{if(e&&e.texture&&e.texture!==L.WHITE)e.texture.destroy(!0)});_width=0;_height=0;_dpr=1;is_initialized=!1;context_lost_listener=null;context_restored_listener=null;sprite_pool=[];sprite_pool_index=0;graphics_pool=[];graphics_pool_index=0;container_pool=[];container_pool_index=0;is_disposed=!1;get width(){return this._width}get height(){return this._height}async initialize(t,e=!0){this.dispose(),this.ensure_sprite_texture_limit(),this._dpr=e?window.devicePixelRatio||1:1;let r=t.clientWidth||t.width,i=t.clientHeight||t.height,s=new Dt;await s.init({canvas:t,width:r,height:i,backgroundAlpha:0,antialias:!0,autoDensity:!0,resolution:this._dpr,clearBeforeRender:!0}),s.ticker.stop(),this.app=s,zt.defaultOptions.scaleMode="linear";let n=this.app.canvas;this.context_lost_listener=(a)=>{a.preventDefault()},this.context_restored_listener=()=>{this.ensure_sprite_texture_limit()},n.addEventListener("webglcontextlost",this.context_lost_listener,{passive:!1}),n.addEventListener("webglcontextrestored",this.context_restored_listener),this.root=new tt,this.app.stage.addChild(this.root),this._width=r,this._height=i,this.reset_state(),this.is_initialized=!0}begin_frame(){this.clear()}end_frame(){if(!this.app)return;this.app.renderer.render(this.app.stage)}clear(){if(!this.root)return;this.root.removeChildren(),this.sprite_pool_index=0,this.graphics_pool_index=0,this.container_pool_index=0,this.reset_state()}resize(t,e){if(!this.app)return;this._width=t,this._height=e,this._dpr=window.devicePixelRatio||1,this.app.renderer.resolution=this._dpr,this.app.renderer.resize(t,e)}clear_caches(){if(this.is_disposed)return;this.clear_texture_caches();for(let t=0;t<this.sprite_pool.length;t++)this.safe_destroy(this.sprite_pool[t]);this.sprite_pool.length=0,this.sprite_pool_index=0;for(let t=0;t<this.graphics_pool.length;t++)this.safe_destroy(this.graphics_pool[t],{context:!0});this.graphics_pool.length=0,this.graphics_pool_index=0;for(let t=0;t<this.container_pool.length;t++)this.safe_destroy(this.container_pool[t],{children:!0});this.container_pool.length=0,this.container_pool_index=0,this.stack=[],this.state={matrix:new X,alpha:1,blend_mode:"normal",container:this.root??new tt,path:[]}}dispose(){if(this.is_disposed)return;if(this.is_disposed=!0,this.clear_texture_caches(),this.app){let t=this.app.canvas;if(this.context_lost_listener)t.removeEventListener("webglcontextlost",this.context_lost_listener);if(this.context_restored_listener)t.removeEventListener("webglcontextrestored",this.context_restored_listener);this.app.destroy(!1,{children:!0,texture:!0,textureSource:!0}),this.app=null}this.root=null,this.stack=[],this.is_initialized=!1,this.context_lost_listener=null,this.context_restored_listener=null;for(let t=0;t<this.sprite_pool.length;t++)this.safe_destroy(this.sprite_pool[t]);this.sprite_pool.length=0,this.sprite_pool_index=0;for(let t=0;t<this.graphics_pool.length;t++)this.safe_destroy(this.graphics_pool[t],{context:!0});this.graphics_pool.length=0,this.graphics_pool_index=0;for(let t=0;t<this.container_pool.length;t++)this.safe_destroy(this.container_pool[t],{children:!0});this.container_pool.length=0,this.container_pool_index=0}draw_circle(t,e,r,i,s,n){let a=this.make_graphics(),o=$(i),c=$(s);if(a.circle(t,e,r),i&&i!=="transparent"&&o.alpha>0)a.fill({color:o.color,alpha:o.alpha*this.state.alpha});if(s&&n&&n>0&&c.alpha>0)a.stroke({width:n,color:c.color,alpha:c.alpha*this.state.alpha})}draw_arc(t,e,r,i,s,n,a,o=!1){let c=this.make_graphics(),_=$(n);c.arc(t,e,r,i,s,o),c.stroke({width:a,color:_.color,alpha:_.alpha*this.state.alpha})}draw_rect(t,e,r,i,s){let n=this.make_graphics(),a=$(s);n.rect(t,e,r,i),n.fill({color:a.color,alpha:a.alpha*this.state.alpha})}draw_rect_gradient(t,e,r,i,s){let n=this.get_or_create_gradient_texture(t,e,r,i,s),a=this.get_sprite(n);a.alpha=this.state.alpha,a.blendMode=this.state.blend_mode,a.setFromMatrix(this.compose_matrix(t,e,r/n.width,i/n.height)),this.state.container.addChild(a)}create_linear_gradient(t,e,r,i,s){return{type:"linear_gradient",x0:t,y0:e,x1:r,y1:i,stops:s}}draw_text(t,e,r,i,s,n="left",a="alphabetic"){let o=$(s),c=this.get_or_create_text_texture(t,i,o),_=this.get_sprite(c.texture);_.alpha=o.alpha*this.state.alpha,_.blendMode=this.state.blend_mode;let h=0;switch(n){case"center":h=0.5;break;case"right":case"end":h=1;break;default:h=0;break}let p=0;switch(a){case"top":case"hanging":p=0;break;case"middle":p=0.5;break;case"bottom":case"ideographic":p=1;break;default:p=c.ascent/Math.max(1,c.height);break}_.anchor.set(h,p),_.setFromMatrix(this.compose_matrix(e,r,1/c.resolution,1/c.resolution)),this.state.container.addChild(_)}begin_path(){this.state.path=[]}move_to(t,e){this.state.path.push({type:"move",x:t,y:e})}line_to(t,e){this.state.path.push({type:"line",x:t,y:e})}draw_line(t,e,r,i,s,n){let a=this.make_graphics(),o=$(s);a.moveTo(t,e),a.lineTo(r,i),a.stroke({width:n,color:o.color,alpha:o.alpha*this.state.alpha})}bezier_curve_to(t,e,r,i,s,n){let o=this.get_last_path_point();if(!o)return;for(let c=1;c<=24;c++){let _=c/24,h=1-_,p=h*h*h*o.x+3*h*h*_*t+3*h*_*_*r+_*_*_*s,d=h*h*h*o.y+3*h*h*_*e+3*h*_*_*i+_*_*_*n;this.state.path.push({type:"line",x:p,y:d})}}quadratic_curve_to(t,e,r,i){let n=this.get_last_path_point();if(!n)return;for(let a=1;a<=20;a++){let o=a/20,c=1-o,_=c*c*n.x+2*c*o*t+o*o*r,h=c*c*n.y+2*c*o*e+o*o*i;this.state.path.push({type:"line",x:_,y:h})}}arc_to(t,e,r,i,s,n=!1){this.state.path.push({type:"arc",x:t,y:e,radius:r,start:i,end:s,ccw:n})}rect(t,e,r,i){this.state.path.push({type:"rect",x:t,y:e,width:r,height:i})}clip(){if(!this.root||this.state.path.length===0)return;let t=this.make_graphics();this.apply_path(t,this.state.path);let e=this.get_container();e.mask=t,this.state.container.addChild(t),this.state.container.addChild(e),this.state.container=e,this.state.path=[]}stroke_path(t,e,r="butt",i="miter"){let s=this.make_graphics(),n=$(t);this.apply_path(s,this.state.path),s.stroke({width:e,color:n.color,alpha:n.alpha*this.state.alpha})}fill_path(t){let e=this.make_graphics(),r=$(t);this.apply_path(e,this.state.path),e.fill({color:r.color,alpha:r.alpha*this.state.alpha})}close_path(){this.state.path.push({type:"close"})}save(){this.stack.push({matrix:this.state.matrix.clone(),alpha:this.state.alpha,blend_mode:this.state.blend_mode,container:this.state.container,path:this.state.path.slice()})}restore(){let t=this.stack.pop();if(!t)return;this.state=t}translate(t,e){let r=new X;r.translate(t,e),this.state.matrix.append(r)}scale(t,e){let r=new X;r.scale(t,e),this.state.matrix.append(r)}rotate(t){let e=new X;e.rotate(t),this.state.matrix.append(e)}set_alpha(t){this.state.alpha=t}set_shadow(t,e){}set_composite_operation(t){this.state.blend_mode=Sr(t)}set_blend_mode(t){switch(t){case"lighter":this.state.blend_mode="add";return;case"multiply":this.state.blend_mode="multiply";return;case"screen":this.state.blend_mode="screen";return;default:this.state.blend_mode="normal";return}}draw_image(t,e,r,i,s,n){let a=this.get_texture(t.source);if(!a)return;let o=this.get_sprite(a);if(o.alpha=this.state.alpha,o.blendMode=this.state.blend_mode,n){let d=$(n);o.tint=d.color,o.alpha*=d.alpha}let c=i??t.width??a.width,_=s??t.height??a.height,h=c/Math.max(1,a.width),p=_/Math.max(1,a.height);o.setFromMatrix(this.compose_matrix(e,r,h,p)),this.state.container.addChild(o)}draw_image_part(t,e,r,i,s,n,a,o,c){let _=this.get_texture(t.source);if(!_)return;let h=new L({source:_.source,frame:new Zt(e,r,i,s)}),p=this.get_sprite(h);p.alpha=this.state.alpha,p.blendMode=this.state.blend_mode,p.setFromMatrix(this.compose_matrix(n,a,o/Math.max(1,i),c/Math.max(1,s))),this.state.container.addChild(p)}render_slider_to_image(t,e,r,i,s,n=1,a=1,o=null){if(!this.app||t.length<2)return null;let c=Ar(t);if(c.length<2)return null;let _=Dr(c,Math.max(0.02,e*0.001)),h=1/0,p=1/0,d=-1/0,m=-1/0;for(let k=0;k<_.length;k++){let I=_[k];if(I[0]<h)h=I[0];if(I[0]>d)d=I[0];if(I[1]<p)p=I[1];if(I[1]>m)m=I[1]}let l=1,u=e*l+2;h-=u,p-=u,d+=u,m+=u;let f=Math.ceil((d-h)*s),b=Math.ceil((m-p)*s);if(f<=0||b<=0)return null;let v=-h,w=-p,T=$(r),N=$(i),A=e*0.9;return{source:this.render_slider_canvas_fallback(_,v,w,e*l,A,T,N,s,n,a,o,f,b),width:f,height:b,min_x:h,min_y:p}}render_slider_canvas_fallback(t,e,r,i,s,n,a,o,c,_,h,p,d){let m=Math.max(1,p),l=Math.max(1,d),u=document.createElement("canvas");u.width=m,u.height=l;let f=u.getContext("2d");if(!f)return L.WHITE;f.save(),f.imageSmoothingEnabled=!0,f.imageSmoothingQuality="high",f.scale(o,o),f.translate(e,r),f.lineCap="round",f.lineJoin="round";let b=Er(t),v=()=>{if(b){f.stroke(b);return}f.beginPath(),f.moveTo(t[0][0],t[0][1]);for(let S=1;S<t.length;S++)f.lineTo(t[S][0],t[S][1]);f.stroke()},w={color:a.color,alpha:0.5*c},T={color:n.color,alpha:n.alpha*_},N={color:0,alpha:0.25*_},A=Nr(w,0.1),M=Cr(w,0.22),k=0.078125,I=0.1875,O=(S)=>{let B=ie(S);if(B<=k)return Ge({color:0,alpha:0},N,B/Math.max(0.000001,k));if(B<=I)return T;let Q=(B-I)/Math.max(0.000001,1-I),rt=Math.pow(ie(Q),1.35);return Ge(A,M,rt)},x=Math.max(1,Math.floor(t.length/140)),R=Math.max(52,Math.min(76,Math.floor(72/x)));f.globalAlpha=1,f.globalCompositeOperation="source-over";for(let S=1;S<=R;S++){let B=S/R,Q=i*2*B,rt=1-B,nt=O(rt);if(f.strokeStyle=We(nt),f.lineWidth=Math.max(0.5,Q),v(),S===1)f.globalCompositeOperation="destination-over"}return f.globalCompositeOperation="source-over",f.restore(),L.from(u)}reset_state(){if(!this.root)return;this.state={matrix:new X,alpha:1,blend_mode:"normal",container:this.root,path:[]},this.stack=[]}make_graphics(){let t=this.get_graphics();return t.blendMode=this.state.blend_mode,t.setFromMatrix(this.state.matrix),this.state.container.addChild(t),t}get_sprite(t){let e=this.sprite_pool[this.sprite_pool_index];if(!e)e=new te(t),this.sprite_pool.push(e);else e.texture=t,e.tint=16777215,e.alpha=1;return e.anchor.set(0,0),this.sprite_pool_index+=1,e}get_graphics(){let t=this.graphics_pool[this.graphics_pool_index];if(!t)t=new ee,this.graphics_pool.push(t);else t.clear(),t.alpha=1,t.tint=16777215;return this.graphics_pool_index+=1,t}get_container(){let t=this.container_pool[this.container_pool_index];if(!t)t=new tt,this.container_pool.push(t);else t.removeChildren(),t.mask=null,t.alpha=1;return this.container_pool_index+=1,t}apply_path(t,e){for(let r=0;r<e.length;r++){let i=e[r];switch(i.type){case"move":t.moveTo(i.x,i.y);break;case"line":t.lineTo(i.x,i.y);break;case"arc":t.arc(i.x,i.y,i.radius,i.start,i.end,i.ccw);break;case"rect":t.rect(i.x,i.y,i.width,i.height);break;case"close":t.closePath();break}}}compose_matrix(t,e,r=1,i=1){let s=this.state.matrix.clone(),n=new X;if(n.translate(t,e),s.append(n),r!==1||i!==1){let a=new X;a.scale(r,i),s.append(a)}return s}get_last_path_point(){for(let t=this.state.path.length-1;t>=0;t--){let e=this.state.path[t];if(e.type==="move"||e.type==="line")return{x:e.x,y:e.y}}return null}get_texture(t){if(!t)return null;if(t instanceof L)return t;let e=this.texture_cache.get(t);if(e)return e;let r=L.from(t);return this.texture_cache.set(t,r),r}get_or_create_gradient_texture(t,e,r,i,s){let n=Lr(t,e,r,i,s),a=this.gradient_texture_cache.get(n);if(a)return a;let o=document.createElement("canvas");o.width=Math.max(1,Math.ceil(r)),o.height=Math.max(1,Math.ceil(i));let c=o.getContext("2d");if(!c)return L.WHITE;let _=c.createLinearGradient(s.x0-t,s.y0-e,s.x1-t,s.y1-e);for(let p=0;p<s.stops.length;p++)_.addColorStop(s.stops[p].offset,s.stops[p].color);c.fillStyle=_,c.fillRect(0,0,o.width,o.height);let h=L.from(o);return this.gradient_texture_cache.set(n,h),h}get_or_create_text_texture(t,e,r){let i=`${t}|${e}|${r.color}`,s=this.text_texture_cache.get(i);if(s)return s;let n=Rr(e),a=Math.min(6,Math.max(2,this._dpr*3)),o=document.createElement("canvas"),c=o.getContext("2d");if(!c)return{texture:L.WHITE,width:1,height:1,ascent:1,descent:0,resolution:1};c.font=n.css;let _=c.measureText(t),h=Math.max(1,Math.ceil(_.width||n.size)),p=Math.max(1,Math.ceil(_.actualBoundingBoxAscent||n.size*0.8)),d=Math.max(0,Math.ceil(_.actualBoundingBoxDescent||n.size*0.2)),m=Math.max(1,p+d),l=Math.max(2,Math.ceil(n.size*0.25)),u=h+l*2,f=m+l*2;o.width=Math.ceil(u*a),o.height=Math.ceil(f*a),c.setTransform(1,0,0,1,0,0),c.clearRect(0,0,o.width,o.height),c.scale(a,a),c.font=n.css,c.fillStyle=We(r),c.textAlign="center",c.textBaseline="middle",c.fillText(t,u/2,f/2);let v={texture:L.from(o),width:u,height:f,ascent:f/2,descent:f/2,resolution:a};return this.text_texture_cache.set(i,v),v}clear_texture_caches(){for(let t of this.texture_cache.values()){if(!t||t===L.WHITE)continue;this.safe_destroy(t,!0)}this.texture_cache.clear(),this.gradient_texture_cache.clear(),this.text_texture_cache.clear()}ensure_sprite_texture_limit(){}safe_destroy(t,e){if(!t||typeof t.destroy!=="function")return;try{if(e!==void 0)t.destroy(e);else t.destroy()}catch{}}}var Rr=(t)=>{let e=t.trim().split(/\s+/),r=14,i="normal",s=-1;for(let o=0;o<e.length;o++)if(e[o].endsWith("px")){r=Number.parseFloat(e[o].replace("px","")),s=o;break}if(s>0)i=e[s-1];let n=s>=0?e.slice(s+1).join(" "):'"Trebuchet MS", Verdana, Arial, sans-serif';return{css:`${i} ${Number.isFinite(r)?r:14}px ${n||'"Trebuchet MS", Verdana, Arial, sans-serif'}`,size:Number.isFinite(r)?r:14}},$=(t)=>{if(!t||t==="transparent")return{color:16777215,alpha:0};let e=t.trim().toLowerCase();if(e.startsWith("#")){let i=e.slice(1);if(i.length===3){let s=Number.parseInt(i[0]+i[0],16),n=Number.parseInt(i[1]+i[1],16),a=Number.parseInt(i[2]+i[2],16);return{color:s<<16|n<<8|a,alpha:1}}if(i.length===6||i.length===8){let s=Number.parseInt(i.slice(0,6),16);if(i.length===8){let n=Number.parseInt(i.slice(6,8),16)/255;return{color:s,alpha:n}}return{color:s,alpha:1}}}let r=e.match(/^rgba?\(([^)]+)\)$/);if(r){let i=r[1].split(",").map((s)=>s.trim());if(i.length>=3){let s=re(Number.parseFloat(i[0])),n=re(Number.parseFloat(i[1])),a=re(Number.parseFloat(i[2])),o=i.length>=4?ie(Number.parseFloat(i[3])):1;return{color:s<<16|n<<8|a,alpha:o}}}if(e==="white")return{color:16777215,alpha:1};if(e==="black")return{color:0,alpha:1};return Mr},We=(t)=>{let e=t.color>>16&255,r=t.color>>8&255,i=t.color&255;return`rgba(${e},${r},${i},${t.alpha})`},Ar=(t)=>{if(t.length<=2)return t;let e=[t[0]],r=0.000000000001;for(let i=1;i<t.length;i++){let s=e[e.length-1],n=t[i],a=n[0]-s[0],o=n[1]-s[1];if(a*a+o*o<=r)continue;e.push(n)}if(e.length<2)return[t[0],t[t.length-1]];return e},Dr=(t,e)=>{if(t.length<=2)return t;let r=[t[0]],i=e*e;for(let a=1;a<t.length-1;a++){let o=r[r.length-1],c=t[a],_=t[a+1],h=c[0]-o[0],p=c[1]-o[1],d=h*h+p*p;if(d<i)continue;let m=c[0]-o[0],l=c[1]-o[1],u=_[0]-c[0],f=_[1]-c[1],b=Math.hypot(m,l),v=Math.hypot(u,f);if(b>0&&v>0){if((m*u+l*f)/(b*v)>0.9985&&d<i*4)continue}r.push(c)}let s=t[t.length-1],n=r[r.length-1];if(n[0]!==s[0]||n[1]!==s[1])r.push(s);return r.length>=2?r:[t[0],s]},Er=(t)=>{if(typeof Path2D>"u"||t.length<2)return null;let e=new Path2D;e.moveTo(t[0][0],t[0][1]);for(let r=1;r<t.length;r++)e.lineTo(t[r][0],t[r][1]);return e},Hr=(t,e,r)=>{let i=Math.max(0,Math.min(1,r)),s=t.color>>16&255,n=t.color>>8&255,a=t.color&255,o=e>>16&255,c=e>>8&255,_=e&255,h=Math.round(s+(o-s)*i),p=Math.round(n+(c-n)*i),d=Math.round(a+(_-a)*i);return{color:h<<16|p<<8|d,alpha:t.alpha}},Ge=(t,e,r)=>{let i=Math.max(0,Math.min(1,r)),s=t.color>>16&255,n=t.color>>8&255,a=t.color&255,o=e.color>>16&255,c=e.color>>8&255,_=e.color&255,h=Math.round(s+(o-s)*i),p=Math.round(n+(c-n)*i),d=Math.round(a+(_-a)*i);return{color:h<<16|p<<8|d,alpha:t.alpha+(e.alpha-t.alpha)*i}},Nr=(t,e)=>Hr(t,0,e),Cr=(t,e)=>{let r=Math.max(0,e*0.5),i=t.color>>16&255,s=t.color>>8&255,n=t.color&255,a=Math.min(255,Math.round(i*(1+0.5*r)+255*r)),o=Math.min(255,Math.round(s*(1+0.5*r)+255*r)),c=Math.min(255,Math.round(n*(1+0.5*r)+255*r));return{color:a<<16|o<<8|c,alpha:t.alpha}},ie=(t)=>{if(!Number.isFinite(t))return 1;if(t<0)return 0;if(t>1)return 1;return t},re=(t)=>{if(!Number.isFinite(t))return 0;if(t<0)return 0;if(t>255)return 255;return Math.round(t)},Sr=(t)=>{switch(t){case"lighter":return"add";case"multiply":return"multiply";case"screen":return"screen";default:return"normal"}},Z=(t,e)=>{return t^=e>>>0,t=Math.imul(t,16777619)>>>0,t>>>0},ht=(t)=>{if(!Number.isFinite(t))return 0;return Math.round(t*1000)|0},Or=(t)=>{let e=2166136261;for(let r=0;r<t.length;r++)e^=t.charCodeAt(r),e=Math.imul(e,16777619)>>>0;return e>>>0},Lr=(t,e,r,i,s)=>{let n=2166136261;n=Z(n,ht(r)),n=Z(n,ht(i)),n=Z(n,ht(s.x0-t)),n=Z(n,ht(s.y0-e)),n=Z(n,ht(s.x1-t)),n=Z(n,ht(s.y1-e)),n=Z(n,s.stops.length);for(let a=0;a<s.stops.length;a++){let o=s.stops[a];n=Z(n,Br(o.offset)),n=Z(n,Or(o.color))}return n>>>0},Br=(t)=>{if(!Number.isFinite(t))return 0;return Math.round(t*1e6)|0};var se=(t)=>{return new Et};var ne={min:1800,mid:1200,max:450};var Pr=(t,e)=>{if(t>5)return e.mid+(e.max-e.mid)*(t-5)/5;if(t<5)return e.mid+(e.mid-e.min)*(t-5)/5;return e.mid},qe=(t,e)=>{if(Math.sign(t-e.mid)===Math.sign(e.max-e.mid))return(t-e.mid)/(e.max-e.mid)*5+5;return(t-e.mid)/(e.mid-e.min)*5+5},Ht=(t)=>Pr(t,ne),Je=(t)=>400*Math.min(1,t/450),Fr=(t)=>{return(1-0.7*((t-5)/5))/2*1.00041},Ke=(t)=>Fr(t)*64;var ae={name:"Hard Rock",acronym:"HR",apply_to_difficulty(t){t.cs=Math.min(t.cs*1.3,10),t.ar=Math.min(t.ar*1.4,10),t.od=Math.min(t.od*1.4,10),t.hp=Math.min(t.hp*1.4,10)}};var oe={name:"Easy",acronym:"EZ",apply_to_difficulty(t){t.cs*=0.5,t.ar*=0.5,t.od*=0.5,t.hp*=0.5}};var Vr={name:"Double Time",acronym:"DT",get_rate_multiplier:()=>1.5},jr={name:"Nightcore",acronym:"NC",get_rate_multiplier:()=>1.5};var Ur={name:"Half Time",acronym:"HT",get_rate_multiplier:()=>0.75};var $r=0.4,Yr=0.3,Qr={name:"Hidden",acronym:"HD"};var Wr=(t)=>{if(t&(g.DoubleTime|g.Nightcore))return 1.5;if(t&g.HalfTime)return 0.75;return 1},Gr=(t,e)=>{if(e&g.Easy)oe.apply_to_difficulty(t);if(e&g.HardRock)ae.apply_to_difficulty(t)},qr=(t,e)=>{if(e===1)return t;let r=Ht(t)/e;return qe(r,ne)},Xe=(t,e,r,i,s)=>{let n={cs:t,ar:e,od:r,hp:i};Gr(n,s);let a=Wr(s);return n.ar=qr(n.ar,a),n};var et=(t,e)=>[t[0]+e[0],t[1]+e[1]],V=(t,e)=>[t[0]-e[0],t[1]-e[1]],Ze=(t,e)=>[t[0]*e,t[1]*e];var Y=(t)=>Math.sqrt(t[0]*t[0]+t[1]*t[1]);var Nt=(t,e)=>Y(V(t,e));var st=(t,e,r)=>t+(e-t)*r,G=(t,e,r)=>[st(t[0],e[0],r),st(t[1],e[1],r)],y=(t,e,r)=>Math.min(r,Math.max(e,t));var ce={1:["#d5bc00"],2:["#ffffff","#ffffff"],3:["#ffffff","#d5bc00","#ffffff"],4:["#ffffff","#dc8dba","#dc8dba","#ffffff"],5:["#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff"],6:["#ffffff","#dc8dba","#ffffff","#ffffff","#dc8dba","#ffffff"],7:["#ffffff","#dc8dba","#ffffff","#d5bc00","#ffffff","#dc8dba","#ffffff"],8:["#d5bc00","#ffffff","#dc8dba","#ffffff","#d5bc00","#ffffff","#dc8dba","#ffffff"],9:["#ffffff","#dc8dba","#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff","#dc8dba","#ffffff"],10:["#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff","#ffffff","#dc8dba","#d5bc00","#dc8dba","#ffffff"]},_e={legacy_version:2.7,combo_colors:["0,185,0","7, 105, 227","224, 4, 38","227, 171, 2"],circle_border_width:0.12,hit_circle_opacity:1,hit_circle_overlay_above_number:!0,hit_circle_prefix:"default",hit_circle_overlap:-2,enable_approach_circle:!0,approach_circle_width:0.1,approach_circle_opacity:0.5,approach_circle_use_combo_color:!0,enable_hitburst:!0,hitburst_duration:180,hitburst_scale:1.2,hitburst_glow_enabled:!1,hitburst_glow_use_combo_color:!0,hitburst_glow_opacity:0.3,slider_body_opacity:0.9,slider_border_opacity:1,slider_tick_opacity:0.75,slider_tick_size:0.1,slider_render_scale:2,follow_circle_factor:1.5,follow_circle_width:4,follow_circle_opacity:0.5,follow_circle_color:"#d3d3d3ff",follow_circle_use_combo_color:!1,slider_ball_color:"#ffffff",slider_ball_opacity:1,enable_slider_ball:!0,slider_ball_flip:!1,allow_slider_ball_tint:!0,slider_ball_frames:10,animation_framerate:-1,follow_point_width:2,follow_point_shape:"line",follow_point_mode:"full",follow_point_length:12,follow_point_line_gap:0,spinner_size:180,spinner_center_size:10,spinner_background_color:"rgba(100,100,100,1)",mania_lane_width:30,mania_note_height:15,mania_hit_position:364,mania_lane_spacing:1,mania_lane_colors:ce,default_font:'"Trebuchet MS", Verdana, Arial, sans-serif',hit_animation_duration:240,hit_animation_scale:1.2,enable_hit_animations:!0,enable_follow_circle_animations:!0},he=(t)=>{if(!t)return{..._e};return{..._e,...t,mania_lane_colors:t.mania_lane_colors?{...ce,...t.mania_lane_colors}:ce}},q=(t,e,r=1)=>{let i=t.combo_colors[e%t.combo_colors.length];return Jr(i,r)},dt=(t,e,r)=>{let i=t.mania_lane_colors[e]??t.mania_lane_colors[4];return i[r%i.length]??"#ffffff"},Jr=(t,e)=>{let r=t.trim();if(r.includes(",")&&!r.startsWith("rgb"))return`rgba(${r},${e})`;let i=r.match(/^rgb\(([^)]+)\)$/i);if(i)return`rgba(${i[1]},${e})`;let s=r.match(/^rgba\(([^)]+)\)$/i);if(s){let n=s[1].split(",").map((a)=>a.trim());if(n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${e})`}if(r.startsWith("#")){let n=r.slice(1);if(n.length===3){let a=Number.parseInt(n[0]+n[0],16),o=Number.parseInt(n[1]+n[1],16),c=Number.parseInt(n[2]+n[2],16);return`rgba(${a},${o},${c},${e})`}if(n.length===6||n.length===8){let a=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),c=Number.parseInt(n.slice(4,6),16);return`rgba(${a},${o},${c},${e})`}}return r};var D={None:(t)=>t,Out:(t)=>1-Math.pow(1-t,2),In:(t)=>t*t,InOut:(t)=>t<0.5?2*t*t:1-Math.pow(-2*t+2,2)/2,OutCubic:(t)=>1-Math.pow(1-t,3),InCubic:(t)=>t*t*t,OutQuad:(t)=>1-Math.pow(1-t,2),InQuad:(t)=>t*t,OutQuint:(t)=>1-Math.pow(1-t,5),InQuint:(t)=>t*t*t*t*t,OutElastic:(t)=>{let e=2*Math.PI/3;return t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-0.75)*e)+1}};class de{transforms=[];add(t,e,r,i,s,n=D.None){return this.transforms.push({property:t,start_value:e,end_value:r,start_time:i,end_time:i+s,easing:n}),this}then(){return this}get_value(t,e,r){let i=r;for(let s of this.transforms){if(s.property!==t)continue;if(e<s.start_time)continue;if(e>=s.end_time)i=s.end_value;else{let n=(e-s.start_time)/(s.end_time-s.start_time),a=s.easing(n);i=s.start_value+(s.end_value-s.start_value)*a}}return i}clear(){this.transforms=[]}}class lt{backend;skin;hit_object;config;alpha=1;scale=1;rotation=0;x=0;y=0;armed_state=0;transforms=new de;life_time_start=0;life_time_end=0;constructor(t,e){this.hit_object=t,this.config=e,this.backend=e.backend,this.skin=e.skin;let r=t.data;this.x=r.pos[0],this.y=r.pos[1],this.apply_defaults()}apply_defaults(){let{hit_object:t,config:e}=this,r=t.time-e.preempt;this.life_time_start=r,this.life_time_end=t.end_time+800}is_alive(t){return t>=this.life_time_start&&t<=this.life_time_end}update(t){this.alpha=this.transforms.get_value("alpha",t,1),this.scale=this.transforms.get_value("scale",t,1),this.rotation=this.transforms.get_value("rotation",t,0),this.update_state(t)}update_state(t){if(this.armed_state===0&&t>=this.hit_object.time)this.armed_state=1,this.on_hit(t)}on_hit(t){}render_body_pass(t){}render_head_pass(t){}dispose(){}get start_time(){return this.hit_object.time}get end_time(){return this.hit_object.end_time}get combo_number(){return this.hit_object.combo_number??0}get combo_count(){return this.hit_object.combo_count??1}get position(){return[this.x,this.y]}}var le=1.04;class gt{state={circle_alpha:0,circle_scale:1,number_alpha:1};update(t,e,r){let i=e-r.preempt;if(t<i){this.reset_pre_hit_state();return}if(t<e){this.update_pre_hit(t,i,e,r);return}let s=Ct(e,i,e,r);this.update_post_hit(t,e,r,s)}render(t,e,r,i,s,n,a,o,c=!0,_=!0){let{circle_alpha:h,circle_scale:p,number_alpha:d}=this.state;if(h<=0.01)return;if(h>0.01){t.set_alpha(h*e.hit_circle_opacity);let m=o?.circle??a?.hitcircle,l=o?.overlay??a?.hitcircleoverlay,u=e.hit_circle_overlay_above_number,f=!!m;if(m){let b=i*2*p*le;t.draw_image(m,r[0]-b/2,r[1]-b/2,b,b,s)}else{let b=i*e.circle_border_width*p,v=i*(1-e.circle_border_width/2)*p;t.draw_circle(r[0],r[1],v,s,"rgba(255,255,255,1)",b)}if(_&&!u&&l&&f){t.set_alpha(h*e.hit_circle_opacity);let b=i*2*p*le;t.draw_image(l,r[0]-b/2,r[1]-b/2,b,b)}if(c&&d>0.01){if(t.set_alpha(d*e.hit_circle_opacity),!Kr(t,r,i,p,n,a)){let v=i*0.7*p,w=e.default_font??'"Trebuchet MS", Verdana, Arial, sans-serif',T=`600 ${v}px ${w}`;t.draw_text(String(n),r[0],r[1],T,"rgba(255,255,255,1)","center","middle")}}if(_&&u&&l&&f){t.set_alpha(h*e.hit_circle_opacity);let b=i*2*p*le;t.draw_image(l,r[0]-b/2,r[1]-b/2,b,b)}t.set_alpha(1)}t.set_alpha(1)}get circle_alpha(){return this.state.circle_alpha}reset_pre_hit_state(){this.state.circle_alpha=0,this.state.circle_scale=1,this.state.number_alpha=1}update_pre_hit(t,e,r,i){let s=Ct(t,e,r,i);this.state.circle_alpha=s,this.state.circle_scale=1,this.state.number_alpha=s}update_post_hit(t,e,r,i){let s=t-e,{skin:n}=r,a=Math.max(110,n.hit_animation_duration*0.62),o=y(s/a,0,1),c=H(r.mods,g.Hidden)?y(i,0,1):y(Math.max(i,0.25),0,1);this.state.circle_alpha=c*(1-D.OutQuad(o)),this.state.circle_scale=st(1,Math.max(n.hit_animation_scale,1.34),D.OutCubic(o)),this.state.number_alpha=this.state.circle_alpha*(1-0.55*o)}}var Ct=(t,e,r,i)=>{let n=y((t-e)/i.fade_in,0,1);if(H(i.mods,g.Hidden)){let a=r-i.preempt+i.fade_in,o=i.preempt*0.3;if(t>a){let c=y((t-a)/o,0,1);n*=1-c}}return n},Kr=(t,e,r,i,s,n)=>{let a=n?.combo_digits;if(!a||a.length<10)return!1;let o=String(s),c=128,_=0.8,h=r*2/c*_*i,p=(n?.combo_overlap??-2)*h,d=[],m=[],l=0;for(let f=0;f<o.length;f++){let b=o.charCodeAt(f)-48,v=a[b];if(!v||v.height<=0)return!1;let w=v.width*h,T=v.height*h;if(d.push(w),m.push(T),l+=w,f<o.length-1)l-=p}let u=e[0]-l/2;for(let f=0;f<o.length;f++){let b=o.charCodeAt(f)-48,v=a[b],w=d[f],T=m[f],N=e[1]-T/2;if(t.draw_image(v,u,N,w,T),u+=w,f<o.length-1)u-=p}return!0};var Xr=0.8;class pe{state={alpha:0,scale:1};update(t,e,r){if(!r.skin.enable_hitburst){this.state.alpha=0,this.state.scale=1;return}if(t<e){this.state.alpha=0,this.state.scale=1;return}let i=e-r.preempt,s=Ct(e,i,e,r),n=H(r.mods,g.Hidden)?y(s,0,1):y(Math.max(s,0.25),0,1),a=t-e,o=Math.max(44,r.skin.hitburst_duration*0.52),c=y(a/o,0,1),_=1-D.OutQuint(c),h=Math.max(24,o*0.3),p=y(a/h,0,1),d=D.OutQuad(p)*_;this.state.alpha=H(r.mods,g.Hidden)?d*n*0.78:d*0.78;let m=Math.max(1,r.skin.hitburst_scale*Xr),l=Math.max(24,o*0.2),u=Math.min(1.06,m);if(a<=l){let f=y(a/l,0,1);this.state.scale=st(0.96,u,D.OutCubic(f))}else{let f=y((a-l)/Math.max(1,o-l),0,1);this.state.scale=st(u,m,D.OutCubic(f))}}render(t,e,r,i,s){if(!e.enable_hitburst)return;if(this.state.alpha<=0.01)return;if(t.set_alpha(this.state.alpha),t.draw_circle(r[0],r[1],i*this.state.scale,"rgba(255,255,255,1)","transparent",0),e.hitburst_glow_enabled){t.save(),t.set_blend_mode("lighter"),t.set_alpha(this.state.alpha*e.hitburst_glow_opacity);let n=e.hitburst_glow_use_combo_color?s:e.hitburst_glow_color??s;t.draw_circle(r[0],r[1],i*this.state.scale*1.08,n,"transparent",0),t.restore()}}}class St extends lt{visual=new gt;hitburst=new pe;constructor(t,e){super(t,e)}update(t){super.update(t),this.visual.update(t,this.hit_object.time,this.config),this.hitburst.update(t,this.hit_object.time,this.config)}render(t){let{backend:e,skin:r,config:i}=this,{radius:s}=i,n=this.position,a=q(r,this.combo_number,1);this.visual.render(e,r,n,s,a,this.combo_count,i.skin_elements,void 0,!0,!1),this.hitburst.render(e,r,n,s,a)}}var Ot=(t)=>{let{start_time:e,span_duration:r,span_count:i,length:s,tick_distance:n,min_distance_from_end:a,get_position_at_progress:o}=t,c=[],_=[];if(s<=0||r<=0||i<=0)return{ticks:c,repeats:_};let p=Math.min(1e5,s),d=Math.min(Math.max(n,0),p),m=Math.max(0,Math.min(a,p));for(let l=0;l<i;l++){let u=e+l*r,f=l%2===1;if(d>0){let b=Zr(l,u,r,f,p,d,m,o);if(f)b.reverse();c.push(...b)}if(l<i-1){let b=(l+1)%2;_.push({pos:o(b),time:u+r,repeat_index:l,path_progress:b})}}return c.sort((l,u)=>l.time-u.time),{ticks:c,repeats:_}},Zr=(t,e,r,i,s,n,a,o)=>{let c=[];for(let _=n;_<=s;_+=n){if(_>=s-a)break;let h=_/s,p=i?1-h:h;c.push({pos:o(h),time:e+p*r,span_index:t,path_progress:h})}return c};var me=(t,e=0.05)=>{if(t.length<2)return[...t];let r=[];return ue(t,r,e),r},ue=(t,e,r)=>{if(zr(t,r)){if(e.length===0)e.push(t[0]);e.push(t[t.length-1]);return}let i=[],s=[];ei(t,i,s),ue(i,e,r),ue(s,e,r)},zr=(t,e)=>{if(t.length<=2)return!0;let r=t[0],i=t[t.length-1];for(let s=1;s<t.length-1;s++)if(ti(t[s],r,i)>e)return!1;return!0},ti=(t,e,r)=>{let i=r[0]-e[0],s=r[1]-e[1],n=i*i+s*s;if(n===0){let _=t[0]-e[0],h=t[1]-e[1];return Math.hypot(_,h)}let a=Math.max(0,Math.min(1,((t[0]-e[0])*i+(t[1]-e[1])*s)/n)),o=e[0]+a*i,c=e[1]+a*s;return Math.hypot(t[0]-o,t[1]-c)},ei=(t,e,r)=>{let i=t.length,s=[t];for(let n=1;n<i;n++){s[n]=[];for(let a=0;a<i-n;a++)s[n][a]=G(s[n-1][a],s[n-1][a+1],0.5)}for(let n=0;n<i;n++)e.push(s[n][0]),r.push(s[i-1-n][n])},fe=(t,e,r)=>{let i=V(e,t),s=Y(i);if(s===0)return[t];let n=[i[0]/s,i[1]/s],a=et(t,Ze(n,r));return[t,a]},ze=(t,e)=>{if(t.length!==3)return me(t);let[r,i,s]=t,n=ri(r,i,s);if(!n)return fe(r,s,e);let a=Y(V(r,n)),o=Math.atan2(r[1]-n[1],r[0]-n[0]),c=Math.atan2(s[1]-n[1],s[0]-n[0]),h=(i[0]-r[0])*(s[1]-r[1])-(i[1]-r[1])*(s[0]-r[0])>0,p=c-o;if(h&&p<0)p+=2*Math.PI;if(!h&&p>0)p-=2*Math.PI;let d=2;if(a*2>0.1){let l=Math.abs(p),u=2*Math.acos(1-0.1/a);if(d=Math.max(2,Math.ceil(l/u)),d>=1000)d=1000}let m=[];for(let l=0;l<=d;l++){let u=l/d,f=o+p*u;m.push([n[0]+a*Math.cos(f),n[1]+a*Math.sin(f)])}return m},ri=(t,e,r)=>{let i=2*(t[0]*(e[1]-r[1])+e[0]*(r[1]-t[1])+r[0]*(t[1]-e[1]));if(Math.abs(i)<0.001)return null;let s=((t[0]*t[0]+t[1]*t[1])*(e[1]-r[1])+(e[0]*e[0]+e[1]*e[1])*(r[1]-t[1])+(r[0]*r[0]+r[1]*r[1])*(t[1]-e[1]))/i,n=((t[0]*t[0]+t[1]*t[1])*(r[0]-e[0])+(e[0]*e[0]+e[1]*e[1])*(t[0]-r[0])+(r[0]*r[0]+r[1]*r[1])*(e[0]-t[0]))/i;return[s,n]},tr=(t)=>{if(t.length<2)return[...t];let e=[];for(let r=0;r<t.length-1;r++){let i=t[Math.max(0,r-1)],s=t[r],n=t[r+1],a=t[Math.min(t.length-1,r+2)],o=Y(V(n,s)),c=Math.max(6,Math.ceil(o/4));for(let _=0;_<=c;_++){let h=_/c;e.push(ii(i,s,n,a,h))}}return e},ii=(t,e,r,i,s)=>{let n=s*s,a=n*s;return[0.5*(2*e[0]+(-t[0]+r[0])*s+(2*t[0]-5*e[0]+4*r[0]-i[0])*n+(-t[0]+3*e[0]-3*r[0]+i[0])*a),0.5*(2*e[1]+(-t[1]+r[1])*s+(2*t[1]-5*e[1]+4*r[1]-i[1])*n+(-t[1]+3*e[1]-3*r[1]+i[1])*a)]};var er=(t)=>{let e;if(t.path_type==="L")e=fe(t.pos,t.control_points[0],t.distance);else{let r=[t.pos,...t.control_points];switch(t.path_type){case"P":e=ze(r,t.distance);break;case"C":e=tr(r);break;default:e=si(r);break}}return ni(e,t.distance)},rr=(t)=>{if(!t.computed_path||t.computed_path.length===0)return t.pos;return t.repetitions%2===0?t.pos:t.computed_path[t.computed_path.length-1]},si=(t)=>{let e=[],r=[t[0]];for(let s=1;s<t.length;s++){let[n,a]=[t[s-1],t[s]];if(n[0]===a[0]&&n[1]===a[1]){if(r.length>1)e.push(r);r=[a]}else r.push(a)}if(r.length>1)e.push(r);let i=[];for(let s=0;s<e.length;s++){let n=me(e[s]);if(n.length===0)continue;if(i.length>0){let a=i[i.length-1],o=n[0];if(a[0]===o[0]&&a[1]===o[1]){for(let c=1;c<n.length;c++)i.push(n[c]);continue}}for(let a=0;a<n.length;a++)i.push(n[a])}return i},ni=(t,e)=>{if(t.length<2)return t;let r=[t[0]],i=0,s=null,n=!1;for(let a=1;a<t.length;a++){let o=Y(V(t[a],t[a-1])),c=V(t[a],t[a-1]);if(o>0)s=[c[0]/o,c[1]/o];if(o===0)continue;if(i+o>=e){let _=e-i;r.push(G(t[a-1],t[a],_/o)),i=e,n=!0;break}i+=o,r.push(t[a])}if(!n&&i<e&&s){let a=e-i,o=r[r.length-1];r.push([o[0]+s[0]*a,o[1]+s[1]*a])}return r};var be=240,ge=1.3,ve=35,ai=250,oi=300,vt=150,ci=vt*4,ir=0.96;class yt extends lt{slider_data;pending_path;position_path;render_path;path_length;span_duration;body_alpha=0;head_visual=new gt;ball_alpha=0;ball_position;ball_reverse=!1;slider_ball_frame_delay=16.666666666666668;follow_alpha=0;follow_scale=1;ticks=[];repeats=[];tick_distance;min_distance_from_end;cached_texture=null;cached_scale=1;tick_entries=[];tick_entries_by_start=[];nested_objects_built=!1;path_ready=!1;constructor(t,e,r,i,s,n){super(t,e);this.slider_data=t.data,this.pending_path=r.length>1?r:null,this.position_path=[],this.render_path=[],this.span_duration=i,this.tick_distance=s,this.min_distance_from_end=n,this.path_length=this.slider_data.distance>0?this.slider_data.distance:0,this.ball_position=this.slider_data.pos,this.slider_ball_frame_delay=this.compute_slider_ball_frame_delay(),this.path_ready=!1,this.life_time_end=t.end_time+be}build_nested_objects(){let{slider_data:t,path_length:e,span_duration:r,hit_object:i}=this,s=Math.max(1,t.repetitions),n=1e5,a=Math.min(1e5,t.distance>0?t.distance:e),o=y(this.tick_distance,0,a);if(a<=0||r<=0){this.ticks=[],this.repeats=[];return}let c=Ot({start_time:i.time,span_duration:r,span_count:s,length:a,tick_distance:o,min_distance_from_end:this.min_distance_from_end,get_position_at_progress:(_)=>this.get_position_at_progress(_)});this.ticks=c.ticks,this.repeats=c.repeats,this.build_tick_entries()}calculate_path_length(){let t=0;for(let e=1;e<this.position_path.length;e++)t+=Y(V(this.position_path[e],this.position_path[e-1]));return t}resample_path(t,e){if(t.length<2)return t.slice();let r=[t[0]],i=0,s=[];for(let h=1;h<t.length;h++){let p=Y(V(t[h],t[h-1]));s.push(p),i+=p}if(i<=0)return r;let n=e,a=0,o=0;while(n<i&&o<s.length){let h=s[o],p=t[o],d=t[o+1];if(h>0&&a+h>=n){let m=(n-a)/h;r.push(G(p,d,m)),n+=e}else a+=h,o++}let c=t[t.length-1],_=r[r.length-1];if(_[0]!==c[0]||_[1]!==c[1])r.push(c);return r}update(t){if(super.update(t),!this.path_ready&&t>=this.hit_object.time-this.config.preempt-300)this.ensure_path_ready();if(!this.nested_objects_built&&t>=this.hit_object.time-this.config.preempt-250)this.ensure_path_ready(),this.build_nested_objects(),this.nested_objects_built=!0;this.calculate_ball_position(t),this.calculate_opacities(t),this.head_visual.update(t,this.hit_object.time,this.config)}calculate_ball_position(t){let{hit_object:e,span_duration:r}=this,i=300,s=300,n=2.4;if(t<e.time){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}if(t<=e.end_time){if(!this.path_ready){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}let _=t-e.time,h=Math.max(1,this.slider_data.repetitions),p=Math.min(Math.floor(_/r),h-1),d=y((_-p*r)/r,0,1),m=p%2===1?1-d:d;this.ball_reverse=p%2===1,this.ball_position=this.get_position_at_progress(m),this.ball_alpha=1;let l=y(_/300,0,1),u=D.OutQuint(l);this.follow_alpha=u,this.follow_scale=1+1.4*u;return}let a=t-e.end_time,o=y(a/300,0,1),c=D.OutQuint(o);this.ball_alpha=1-c,this.follow_alpha=1-c,this.follow_scale=2.4-1.4*c}get_position_at_progress(t){if(!this.path_ready)return this.slider_data.pos;let e=t*this.path_length;return this.get_position_at_length(e)}get_position_at_length(t){if(!this.path_ready||this.position_path.length===0)return this.slider_data.pos;let e=0;for(let r=1;r<this.position_path.length;r++){let i=Y(V(this.position_path[r],this.position_path[r-1]));if(e+i>=t){let s=(t-e)/i;return G(this.position_path[r-1],this.position_path[r],s)}e+=i}return this.position_path[this.position_path.length-1]}calculate_opacities(t){let{hit_object:e,config:r}=this,i=e.time-r.preempt,s=e.time;if(H(r.mods,g.Hidden)){let n=s-r.preempt+r.fade_in;if(t<i)this.body_alpha=0;else if(t<n)this.body_alpha=y((t-i)/r.fade_in,0,1);else if(t<=e.end_time){let a=Math.max(1,e.end_time-n);this.body_alpha=1-y((t-n)/a,0,1)}else this.body_alpha=0}else if(t<i)this.body_alpha=0;else if(t<s)this.body_alpha=y((t-i)/r.fade_in,0,1);else if(t<=e.end_time)this.body_alpha=1;else this.body_alpha=1-y((t-e.end_time)/be,0,1)}compute_slider_ball_frame_delay(){if(this.skin.animation_framerate>0)return 1000/this.skin.animation_framerate;let t=this.path_length/Math.max(1,this.span_duration),e=16.666666666666668;if(t<=0)return e;return Math.max(0.15/t*e,e)}render(t){if(this.body_alpha<=0&&this.head_visual.circle_alpha<=0&&this.ball_alpha<=0)return;this.render_body(t),this.render_head(),this.render_ball(t)}render_body_pass(t){this.render_body(t)}render_head_pass(t){this.render_head(),this.render_reverse_arrows(t),this.render_ball(t)}render_body(t){if(this.body_alpha<=0.01)return;if(this.ensure_path_ready(),this.render_path.length<2)return;let{backend:e}=this;if(this.prepare_body_cache(),this.cached_texture&&this.cached_texture.min_x!==void 0&&this.cached_texture.min_y!==void 0){let r=this.cached_scale;e.set_alpha(this.body_alpha),e.draw_image(this.cached_texture,this.cached_texture.min_x,this.cached_texture.min_y,this.cached_texture.width/r,this.cached_texture.height/r),e.set_alpha(1)}else this.render_live_body_fallback();this.render_ticks(t)}render_live_body_fallback(){if(this.render_path.length<2)return;let{backend:t,config:e,skin:r}=this,i=r.slider_border_color??"rgba(255,255,255,1)",s=r.slider_track_override??q(r,this.combo_number,1),n=e.radius*2,a=e.radius*1.8;this.build_live_body_path(),t.save(),t.set_alpha(this.body_alpha*r.slider_border_opacity),t.stroke_path(i,n,"round","round"),t.restore(),this.build_live_body_path(),t.save(),t.set_alpha(this.body_alpha*r.slider_body_opacity),t.stroke_path(s,a,"round","round"),t.restore()}build_live_body_path(){let{backend:t}=this;t.begin_path(),t.move_to(this.render_path[0][0],this.render_path[0][1]);for(let e=1;e<this.render_path.length;e++)t.line_to(this.render_path[e][0],this.render_path[e][1])}prepare_body_cache(){if(this.ensure_path_ready(),this.render_path.length<2)return;let{backend:t,skin:e,config:r}=this,{radius:i}=r,s=Math.min(5,(r.scale??1)*(e.slider_render_scale||1));if(!this.cached_texture||this.cached_scale!==s){let n=e.slider_track_override??q(e,this.combo_number,1),a=e.slider_border_color??"rgba(255,255,255,1)",o=s;this.cached_texture=t.render_slider_to_image(this.render_path,i,a,n,o,e.slider_body_opacity,e.slider_border_opacity,null),this.cached_scale=s}}has_body_cache(){return this.cached_texture!=null}get_body_cache_bytes(){if(!this.cached_texture)return 0;return Math.max(0,Math.floor(this.cached_texture.width)*Math.floor(this.cached_texture.height)*4)}release_body_cache(){let t=this.cached_texture?.source;if(t?.destroy)t.destroy(!0);else if(this.cached_texture?.source instanceof HTMLCanvasElement)this.cached_texture.source.width=0,this.cached_texture.source.height=0;this.cached_texture=null}release_path_cache(){this.position_path=[],this.render_path=[],this.path_ready=!1,this.nested_objects_built=!1,this.ticks=[],this.repeats=[],this.tick_entries=[],this.tick_entries_by_start=[]}estimate_complexity(){if(!this.path_ready)return 1;if(!this.nested_objects_built)return this.render_path.length;return this.render_path.length+this.ticks.length*8+this.repeats.length*16}dispose(){this.release_body_cache(),this.release_path_cache(),this.pending_path=null,this.position_path=[],this.render_path=[],this.ticks=[],this.repeats=[],this.tick_entries=[],this.tick_entries_by_start=[]}ensure_path_ready(){if(this.path_ready)return;let t=this.pending_path??er(this.slider_data);if(this.pending_path=null,t.length<2){this.position_path=[],this.render_path=[],this.path_length=0,this.path_ready=!1;return}let e=Math.max(1,this.config.radius*0.03),r=this.resample_path(t,e);this.position_path=r,this.render_path=r;let i=this.calculate_path_length();this.path_length=this.slider_data.distance>0?this.slider_data.distance:i,this.path_ready=this.position_path.length>1}render_ticks(t){if(this.tick_entries_by_start.length===0)return;let{backend:e,config:r}=this,{radius:i}=r,s=i*0.12,n=H(r.mods,g.Hidden);for(let a of this.tick_entries_by_start){let o=a.tick,c=t-a.appear_time;if(c<0)continue;if(a.visible_end<t)continue;let _=y(c/vt,0,1);if(n&&a.preempt>0){let l=Math.min(a.preempt-vt,1000);if(l>0){let u=o.time-l;if(t>=u){let f=y((t-u)/l,0,1);_*=1-f}}}else if(t>o.time){let l=y((t-o.time)/vt,0,1);_*=1-l}_*=this.body_alpha;let h=y(c/ci,0,1),d=0.5+0.5*this.ease_out_elastic_half(h),m=s*d;if(_>0.01){e.set_alpha(_);let l=this.config.skin_elements?.sliderscorepoint;if(l){let u=m*2;e.draw_image(l,o.pos[0]-m,o.pos[1]-m,u,u)}else e.draw_circle(o.pos[0],o.pos[1],m,"rgba(255,255,255,0.8)","transparent",0)}}e.set_alpha(1)}build_tick_entries(){let{hit_object:t,config:e}=this,r=H(e.mods,g.Hidden);this.tick_entries=this.ticks.map((i)=>{let s=t.time+i.span_index*this.span_duration,n=e.preempt,a=i.span_index>0?200:n*0.66,o=(i.time-s)/2+a,c=i.time-o,_=r?i.time:i.time+vt;return{tick:i,appear_time:c,visible_end:_,preempt:o}}),this.tick_entries_by_start=[...this.tick_entries].sort((i,s)=>i.appear_time-s.appear_time)}ease_out_elastic_half(t){if(t<=0)return 0;if(t>=1)return 1;let e=0.3;return Math.pow(2,-10*t)*Math.sin((t-e/4)*(2*Math.PI)/e)+1}render_reverse_arrows(t){if(this.repeats.length===0)return;let{backend:e,config:r,hit_object:i,span_duration:s}=this,{radius:n}=r,a=n*0.9;for(let o of this.repeats){let c=r.preempt;if(o.repeat_index>0)c=s*2;else c+=i.time-(i.time-r.preempt);let _=o.time-c,h=o.repeat_index%2===0;if(t<_||t>o.time+be)continue;let p=this.body_alpha*0.9;if(o.repeat_index===0){let v=y((t-_)/150,0,1);p*=D.OutQuint(v)}else if(t<_)p=0;if(t>o.time){let v=Math.min(300,s);p*=1-y((t-o.time)/v,0,1)}if(p<=0.01)continue;let d=this.get_arrow_target_vector(o.pos,h),m=Math.atan2(d[1]-o.pos[1],d[0]-o.pos[0]),l=1;if(t<o.time){let v=i.time-r.preempt,w=(t-v)%oi;if(w<ve)l=1+(ge-1)*D.Out(w/ve);else{let T=(w-ve)/ai;l=ge-(ge-1)*D.Out(y(T,0,1))}}else{let v=Math.min(300,s),w=y((t-o.time)/v,0,1);l=1+0.5*D.Out(w)}let u=a*l;e.save(),e.set_alpha(p),e.translate(o.pos[0],o.pos[1]),e.rotate(m);let f=this.config.skin_elements?.reversearrow_frames,b=f&&f.length>0?f[Math.floor((t-_)/50)%f.length]:this.config.skin_elements?.reversearrow;if(b)e.draw_image(b,-u,-u,u*2,u*2);else e.begin_path(),e.move_to(u*0.8,0),e.line_to(-u*0.4,-u*0.5),e.line_to(-u*0.4,u*0.5),e.close_path(),e.fill_path("rgba(255,255,255,0.9)");e.restore()}}render_head(){if(this.head_visual.circle_alpha<=0.01&&this.body_alpha<=0.01)return;let{backend:t,skin:e,config:r}=this,{radius:i}=r,s=this.slider_data.pos,n=this.hit_object.end_pos,a=q(e,this.combo_number,1);if(this.head_visual.render(t,e,s,i*ir,a,this.combo_count,r.skin_elements,r.skin_elements?.sliderstartcircle?{circle:r.skin_elements.sliderstartcircle,overlay:r.skin_elements.sliderstartcircleoverlay}:{circle:r.skin_elements?.hitcircle,overlay:r.skin_elements?.hitcircleoverlay},!0),this.body_alpha>0.01){let o=r.skin_elements?.sliderendcircle;if(!o)return;t.set_alpha(this.body_alpha*e.hit_circle_opacity);let c=r.skin_elements?.sliderendcircleoverlay,_=i*ir,h=_*2;if(t.draw_image(o,n[0]-_,n[1]-_,h,h,a),c)t.draw_image(c,n[0]-_,n[1]-_,h,h);t.set_alpha(1)}}render_ball(t){if(this.ball_alpha<=0.01&&this.follow_alpha<=0.01)return;let{backend:e,skin:r,config:i}=this,{radius:s}=i,n=this.ball_position,a=q(r,this.combo_number,0.9);if(this.follow_alpha>0.01){let o=s*this.follow_scale;e.set_alpha(this.follow_alpha*r.follow_circle_opacity);let c=this.config.skin_elements?.sliderfollowcircle;if(c)e.draw_image(c,n[0]-o,n[1]-o,o*2,o*2);else e.begin_path(),e.arc_to(n[0],n[1],o,0,Math.PI*2),e.stroke_path(r.follow_circle_color,r.follow_circle_width)}if(r.enable_slider_ball&&this.ball_alpha>0.01){e.set_alpha(this.ball_alpha*r.slider_ball_opacity);let o=this.config.skin_elements?.sliderball_frames,c=this.config.skin_elements?.sliderball;if(o&&o.length>0){let _=Math.max(0,t-this.hit_object.time),h=Math.floor(_/Math.max(1,this.slider_ball_frame_delay))%o.length;c=o[h]}if(c){let _=s*1.85,h=r.allow_slider_ball_tint?a:r.slider_ball_color;this.draw_slider_ball_layers(n,_,c,h,r.slider_ball_flip&&this.ball_reverse)}else{let _=r.allow_slider_ball_tint?a:r.slider_ball_color;e.draw_circle(n[0],n[1],s*0.85,_,"rgba(255,255,255,0.9)",s*0.1)}}e.set_alpha(1)}get_arrow_target_vector(t,e){let r=this.position_path;if(r.length===0)return t;if(e){for(let i=r.length-1;i>=0;i--)if(Math.abs(r[i][0]-t[0])>0.01||Math.abs(r[i][1]-t[1])>0.01)return r[i];return r[0]}for(let i=0;i<r.length;i++)if(Math.abs(r[i][0]-t[0])>0.01||Math.abs(r[i][1]-t[1])>0.01)return r[i];return r[r.length-1]}draw_slider_ball_layers(t,e,r,i,s){let{backend:n}=this,a=this.config.skin_elements?.sliderball_nd,o=this.config.skin_elements?.sliderball_spec,c=e/2;if(s){if(n.save(),n.translate(t[0],t[1]),n.scale(-1,1),a)n.draw_image(a,-c,-c,e,e);if(n.draw_image(r,-c,-c,e,e,i),o)n.set_blend_mode("lighter"),n.draw_image(o,-c,-c,e,e),n.set_blend_mode("normal");n.restore();return}if(a)n.draw_image(a,t[0]-c,t[1]-c,e,e);if(n.draw_image(r,t[0]-c,t[1]-c,e,e,i),o)n.set_blend_mode("lighter"),n.draw_image(o,t[0]-c,t[1]-c,e,e),n.set_blend_mode("normal")}}class ye{skin;mods;preempt;fade_in;radius;skin_elements=null;points=[];lines=[];sprites=[];constructor(t,e,r,i,s,n=null){this.skin=t,this.mods=e,this.preempt=r,this.fade_in=i,this.radius=s,this.skin_elements=n}update_settings(t,e,r,i,s){if(this.mods=t,this.preempt=e,this.fade_in=r,this.radius=i,s!==void 0)this.skin_elements=s}build(t){this.points.length=0,this.lines.length=0,this.sprites.length=0;let e=32,r=Math.max(450,this.preempt*0.9),i=H(this.mods,g.Hidden);for(let s=0;s<t.length-1;s++){let n=t[s],a=t[s+1];if(U(n)||U(a))continue;if(n.combo_number!==a.combo_number)continue;let o=n.end_pos,c=a.data.pos,_=c[0]-o[0],h=c[1]-o[1],p=Math.sqrt(_*_+h*h);if(p<e*1.5)continue;let d=n.end_time,m=a.time-d;if(m<=0)continue;let l=p>0?1/p:0,u=[_*l,h*l],f=d-r,b=a.time-r,v=d+(b-d)*0.5,w=a.time;if(i)v=d+(b-d)*0.3,w=d+(a.time-d)*0.65;this.lines.push({start_pos:o,end_pos:c,dir:u,start_time:d,end_time:a.time,appear_time:f,grow_end_time:b,shrink_start_time:v,shrink_end_time:w});let T=p<80?0:Math.floor((p-48)/32),N=Math.max(1,this.fade_in);for(let A=0;A<T;A++){let M=48+32*A,k=M/p,I=d+k*m,O=I-r;this.sprites.push({start_pos:o,dir:u,distance:p,start_time:d,end_time:a.time,preempt:r,time_fade_in:N,d:M,f:k,fade_in_time:O,fade_out_time:I})}for(let A=e*1.5;A<p-e;A+=e){let M=A/p,k=n.end_time+M*m,I=Math.max(n.end_time,k-r);if(i)k=Math.min(k,d+m*0.65);let O=[o[0]+(M-0.1)*_,o[1]+(M-0.1)*h],x=[o[0]+M*_,o[1]+M*h];this.points.push({start_pos:O,end_pos:x,dir:u,fade_in_time:I,fade_out_time:k})}}}render(t,e,r){let i=this.skin.follow_point_shape,s=this.skin.follow_point_mode??"segments",n=this.skin.follow_point_length||this.radius*0.6,a=y(this.skin.follow_point_line_gap??0,0,0.9),o=this.skin_elements?.followpoint_frames,c=this.skin_elements?.followpoint,_=c?"sprites":s,h=Math.max(this.fade_in*0.15,50),p=c?0.72:0.2;if(_==="sprites"){let d=o&&o.length>0?o:c?[c]:[],m=this.radius/64;for(let l of this.sprites){if(t<l.start_time-l.preempt)continue;if(t>l.fade_out_time+l.time_fade_in)continue;let u=0,f=m,b=l.f;if(t<l.fade_in_time+l.time_fade_in){let O=D.OutQuad(y((t-l.fade_in_time)/l.time_fade_in,0,1));u=O,f=(1.5-0.5*O)*m,b=l.f-0.1*(1-O)}else if(t<l.fade_out_time)u=1,f=1*m,b=l.f;else u=1-D.OutQuad(y((t-l.fade_out_time)/l.time_fade_in,0,1)),f=1*m,b=l.f;if(u<=0.01)continue;let v=Math.max(1,(l.fade_out_time-l.fade_in_time)/Math.max(1,d.length)),w=y(Math.floor((t-l.fade_in_time)/v),0,d.length-1),T=d[w],N=l.start_pos[0]+l.dir[0]*(b*l.distance),A=l.start_pos[1]+l.dir[1]*(b*l.distance),M=Math.max(1,T.width*f),k=Math.max(1,T.height*f),I=Math.atan2(l.dir[1],l.dir[0]);e.set_alpha(u),e.save(),e.translate(N,A),e.rotate(I),e.draw_image(T,-M/2,-k/2,M,k),e.restore()}}else if(_==="full")for(let d of this.lines){if(t<d.appear_time||t>d.shrink_end_time)continue;let m=0,l=d.start_pos[0],u=d.start_pos[1],f=d.end_pos[0],b=d.end_pos[1],v=Math.hypot(f-l,b-u),w=this.get_alpha_gate(t,d.start_time,d.end_time,r);if(w<=0.01)continue;let T=this.radius*1.05,N=Math.min(T,v*0.22);if(l+=d.dir[0]*N,u+=d.dir[1]*N,f-=d.dir[0]*N,b-=d.dir[1]*N,t<d.grow_end_time){let A=Math.max(1,d.grow_end_time-d.appear_time),M=y((t-d.appear_time)/A,0,1),k=D.OutQuint(M);m=k,f=l+(f-l)*k,b=u+(b-u)*k}else if(t<d.shrink_start_time)m=1;else{let A=Math.max(1,d.shrink_end_time-d.shrink_start_time),M=y((t-d.shrink_start_time)/A,0,1),k=D.InQuint(M);m=1,l=l+(f-l)*k,u=u+(b-u)*k}if(m<=0)continue;if(e.set_alpha(m*p*w),i==="line")if(a>0){let A=Math.hypot(f-l,b-u),M=d.dir[0],k=d.dir[1],I=A*a/2,O=(l+f)/2,x=(u+b)/2,R=O-M*I,S=x-k*I,B=O+M*I,Q=x+k*I;e.draw_line(l,u,R,S,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round"),e.draw_line(B,Q,f,b,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else e.draw_line(l,u,f,b,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round");else{let A=this.radius*0.12,M=(d.start_pos[0]+d.end_pos[0])/2,k=(d.start_pos[1]+d.end_pos[1])/2;e.draw_circle(M,k,A,"rgba(255,255,255,1)","transparent",0)}}else for(let d of this.points){if(t<d.fade_in_time||t>d.fade_out_time+h)continue;let m=0,l=1,u=d.end_pos;if(t<d.fade_in_time+h){let b=y((t-d.fade_in_time)/h,0,1),v=D.OutCubic(b);m=v,l=1.5-0.5*v,u=G(d.start_pos,d.end_pos,v)}else if(t<=d.fade_out_time)m=1,l=1,u=d.end_pos;else{let b=y((t-d.fade_out_time)/h,0,1),v=D.OutCubic(b);m=1-v,l=1,u=G(d.start_pos,d.end_pos,1-v)}if(m<=0)continue;let f=this.get_alpha_gate(t,d.fade_in_time+this.preempt,d.fade_out_time,r);if(f<=0.01)continue;if(e.set_alpha(m*p*f),i==="line"){let v=n*l/2,w=d.dir[0],T=d.dir[1],N=u[0]-w*v,A=u[1]-T*v,M=u[0]+w*v,k=u[1]+T*v;e.draw_line(N,A,M,k,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else{let b=this.radius*0.12*l;e.draw_circle(u[0],u[1],b,"rgba(255,255,255,1)","transparent",0)}}e.set_alpha(1)}get_alpha_gate(t,e,r,i){let s=i(t,e),n=i(t,r);return y(Math.min(s,n)/0.7,0,1)}}var Lt=(t,e,r)=>{if(t<=0)return 0;let i=e.Difficulty.SliderMultiplier;return t*r.base_beat_length/(100*i*r.sv_multiplier)},Bt=(t,e)=>{let r=e.sv_multiplier||1,i=t.Difficulty.SliderMultiplier,s=t.Difficulty.SliderTickRate,n=100*i*r,a=t.version<8?1/r:1,o=n/s*a,c=n/e.base_beat_length;return{tick_distance:o,min_distance_from_end:c*10}};class xt{points;index=0;last_time=Number.NEGATIVE_INFINITY;base_beat_length=600;sv_multiplier=1;constructor(t){this.points=t,this.apply_initial_base_beat_length()}reset(){this.index=0,this.last_time=Number.NEGATIVE_INFINITY,this.base_beat_length=600,this.sv_multiplier=1,this.apply_initial_base_beat_length()}get_state_at(t){if(this.points.length===0)return{base_beat_length:600,sv_multiplier:1};if(t<this.last_time)this.reset();for(let e=this.index;e<this.points.length;e++){let r=this.points[e];if(r.time>t)break;if(r.uninherited===1&&r.beatLength>0)this.base_beat_length=r.beatLength,this.sv_multiplier=1;else if(r.uninherited===0&&r.beatLength<0){let i=-100/r.beatLength;if(i>0)this.sv_multiplier=i}this.index=e+1}return this.last_time=t,this.sv_multiplier=y(this.sv_multiplier,0.1,10),{base_beat_length:this.base_beat_length,sv_multiplier:this.sv_multiplier}}apply_initial_base_beat_length(){for(let t=0;t<this.points.length;t++){let e=this.points[t];if(e.uninherited===1&&e.beatLength>0){this.base_beat_length=e.beatLength;return}}}}var E={precompute:{lookback_ms:1500,lookahead_ms:8000,frame_budget_ms:0.35,bootstrap_budget_ms:12,bootstrap_total_ms:120},slider_cache:{max_entries:40,max_bytes:50331648,retention_ms:8000,trim_interval_ms:250},stack:{default_leniency:0.7,distance:3,offset_multiplier:6.4}};var Pt=(t)=>{if(t.length===0)return t;let e=t.map((r,i)=>({point:r,index:i}));e.sort((r,i)=>{if(r.point.time!==i.point.time)return r.point.time-i.point.time;if(r.point.uninherited!==i.point.uninherited)return r.point.uninherited>i.point.uninherited?-1:1;return r.index-i.index});for(let r=0;r<t.length;r++)t[r]=e[r].point;return t};var P=(t)=>{if(typeof t==="number"&&Number.isFinite(t))return t;if(typeof t==="string"){let e=Number(t);if(Number.isFinite(e))return e}return null},_i=(t)=>P(t.time)??P(t.startTime)??P(t.start_time)??0,hi=(t,e)=>{let r=P(t.endTime)??P(t.end_time);if(r===null)return e;return Math.max(e,r)},di=(t)=>P(t.type)??P(t.objectType)??0,li=(t,e)=>{let r=P(t.x);if(r!==null)return r;let i=P(t.column);if(i!==null&&e>0)return(Math.max(0,Math.min(e-1,Math.round(i)))+0.5)/e*512;return 256},pi=(t)=>P(t.y)??192,Ft=(t)=>{let e=[],r=Math.max(1,Math.round(P(t.Difficulty?.CircleSize)??4));for(let i of t.HitObjects){let s=i,n=_i(s),a=hi(s,n),o=li(s,r),c=pi(s),_=di(s),h={...i,time:n,x:o,y:c,type:_,endTime:a,end_time:a,end_pos:[o,c],combo_number:0,combo_count:0,stack_height:0,stack_offset:[0,0],data:{pos:[o,c]}};if((_&j.Slider)!==0){let p=s.curvePoints||[],d=[];for(let l=0;l<p.length;l++){let u=p[l];d.push([u.x,u.y])}let m={pos:[o,c],path_type:s.curveType||"L",control_points:d,repetitions:(P(s.slides)??1)|0,distance:P(s.length)??0};h.data=m}else if((_&j.Spinner)!==0)h.data={end_time:a},h.end_time=a,h.end_pos=[256,192];else if((_&j.Hold)!==0)h.data={pos:[o,c],end_time:a},h.end_time=a;e.push(h)}return e};var xe=(t)=>384-t;class Vt extends ot{radius=32;preempt=1200;fade_in=600;timing_points=[];timing_resolver=null;drawables=[];slider_drawables=[];slider_cache=this.create_slider_cache(E.slider_cache.max_entries);precompute_focus_time=0;precompute_handle=null;precompute_pause_until=0;last_seek_prefetch_at=0;drawable_config;follow_point_renderer;spinner_objects=[];frame_visible_drawables=[];frame_visible_sliders=[];frame_visible_other=[];slider_cache_limit=E.slider_cache.max_entries;slider_cache_bytes=0;last_cache_trim_at=0;constructor(t,e,r=0,i=K,s=null){super(t,e,r,i,s);this.follow_point_renderer=new ye(e,r,this.preempt,this.fade_in,this.radius,s)}initialize(t){this.release_drawables(),this.beatmap=t,this.objects=Ft(t).sort((i,s)=>i.time-s.time),this.timing_points=Pt([...t.TimingPoints]),this.timing_resolver=new xt(this.timing_points);let e=t.Difficulty.ApproachRate>=0?t.Difficulty.ApproachRate:t.Difficulty.OverallDifficulty,r=Xe(t.Difficulty.CircleSize,e,0,0,this.mods);if(this.radius=Ke(r.cs),this.preempt=Ht(r.ar),this.fade_in=Je(this.preempt),H(this.mods,g.Hidden))this.fade_in=this.preempt*0.4;this.follow_point_renderer.update_settings(this.mods,this.preempt,this.fade_in,this.radius,this.skin_elements),this.preprocess_objects(),this.follow_point_renderer.build(this.objects),this.create_drawables()}set_mods(t){if(this.mods=t,this.beatmap)this.initialize(this.beatmap)}preprocess_objects(){let t=0,e=1;if(this.timing_resolver)this.timing_resolver.reset();for(let r of this.objects){if(De(r))t=(t+1)%this.skin.combo_colors.length,e=1;else e++;if(r.combo_number=t,r.combo_count=e,it(r)){let i=r.data;if(H(this.mods,g.HardRock))i.pos=[i.pos[0],xe(i.pos[1])],i.control_points=i.control_points.map((o)=>[o[0],xe(o[1])]);let s=this.timing_resolver?.get_state_at(r.time)??{base_beat_length:600,sv_multiplier:1},n=Lt(i.distance,this.beatmap,s);i.duration=n,r.end_time=r.time+n*i.repetitions;let a=i.control_points.length>0?i.control_points[i.control_points.length-1]:i.pos;r.end_pos=i.computed_path&&i.computed_path.length>0?rr(i):a}else if(U(r))r.end_pos=[256,192];else{let i=r.data;if(H(this.mods,g.HardRock))i.pos=[i.pos[0],xe(i.pos[1])];r.end_pos=i.pos}}this.apply_stacking_if_enabled()}apply_stacking_if_enabled(){if(!this.config.enable_stacking||this.objects.length<2)return;let t=this.resolve_stack_leniency(),e=this.preempt*t,r=this.radius/64,i=-E.stack.offset_multiplier*r;for(let s=0;s<this.objects.length;s++)this.objects[s].stack_height=0,this.objects[s].stack_offset=[0,0];for(let s=this.objects.length-1;s>0;s--){let n=this.objects[s];if(U(n))continue;for(let a=s-1;a>=0;a--){let o=this.objects[a];if(U(o))continue;if(n.time-o.end_time>e)break;let c=this.get_object_start_position(n),_=this.get_object_start_position(o),h=Nt(_,c),p=it(o)?Nt(o.end_pos,c):1/0;if(Qt(n)&&it(o)&&p<E.stack.distance){let d=n.stack_height-o.stack_height+1;for(let m=a+1;m<=s;m++){let l=this.objects[m];if(U(l))continue;let u=this.get_object_start_position(l);if(Nt(o.end_pos,u)<E.stack.distance)l.stack_height-=d}break}if(h<E.stack.distance||p<E.stack.distance)o.stack_height=n.stack_height+1,n=o}}for(let s=0;s<this.objects.length;s++){let n=this.objects[s];if(n.stack_height===0)continue;let a=n.stack_height*i,o=[a,a];if(n.stack_offset=o,n.end_pos=et(n.end_pos,o),it(n)){let c=n.data;c.pos=et(c.pos,o);let _=[];for(let h=0;h<c.control_points.length;h++)_.push(et(c.control_points[h],o));if(c.control_points=_,c.computed_path){let h=[];for(let p=0;p<c.computed_path.length;p++)h.push(et(c.computed_path[p],o));c.computed_path=h}continue}if(!U(n)){let c=n.data;c.pos=et(c.pos,o)}}}resolve_stack_leniency(){let t=this.beatmap,e=t.StackLeniency??t.Difficulty?.StackLeniency??t.General?.StackLeniency??E.stack.default_leniency;if(e<=0)return E.stack.default_leniency;return e}get_object_start_position(t){if(it(t))return t.data.pos;if(U(t))return[256,192];return t.data.pos}create_drawables(){this.release_drawables();let t=this.config.use_high_dpi?window.devicePixelRatio||1:1;if(this.drawable_config={backend:this.backend,skin:this.skin,skin_elements:this.skin_elements,preempt:this.preempt,fade_in:this.fade_in,radius:this.radius,scale:this.config.scale*t,mods:this.mods},this.timing_resolver)this.timing_resolver.reset();this.spinner_objects=[];for(let e of this.objects)if(Qt(e))this.drawables.push(new St(e,this.drawable_config));else if(it(e)){let r=e.data,i=r.duration||0,s=this.timing_resolver?.get_state_at(e.time)??{base_beat_length:600,sv_multiplier:1},{tick_distance:n,min_distance_from_end:a}=Bt(this.beatmap,s),o=new yt(e,this.drawable_config,r.computed_path||[],i,n,a);this.drawables.push(o),this.slider_drawables.push(o),r.computed_path=[]}else if(U(e))this.spinner_objects.push(e);this.slider_cache_limit=Math.min(E.slider_cache.max_entries,this.slider_drawables.length),this.slider_cache_bytes=0,this.slider_cache=this.create_slider_cache(this.slider_cache_limit)}render(t){let{backend:e,config:r}=this;this.precompute_focus_time=t,this.render_background(),e.save(),e.translate(r.offset_x,r.offset_y),e.scale(r.scale,r.scale),this.render_playfield(),this.render_grid();let i=this.frame_visible_drawables,s=this.frame_visible_sliders,n=this.frame_visible_other;i.length=0,s.length=0,n.length=0;for(let o=this.drawables.length-1;o>=0;o--){let c=this.drawables[o];if(!c.is_alive(t))continue;if(c.update(t),i.push(c),c instanceof yt)s.push(c);else n.push(c)}this.follow_point_renderer.render(t,e,(o,c)=>this.get_circle_alpha(o,c));for(let o=0;o<this.spinner_objects.length;o++){let c=this.spinner_objects[o],_=c.time-this.preempt;if(t>=_&&t<=c.end_time+200)this.draw_spinner(c,t)}for(let o=0;o<s.length;o++){let c=s[o];c.render_body_pass(t),this.touch_slider_cache(c)}let a=performance.now();if(a-this.last_cache_trim_at>=E.slider_cache.trim_interval_ms)this.last_cache_trim_at=a,this.trim_slider_cache_by_time(t),this.trim_slider_runtime_path_cache(t);for(let o=0;o<s.length;o++)s[o].render_head_pass(t);for(let o=0;o<n.length;o++)n[o].render(t);if(!H(this.mods,g.Hidden)&&this.skin.enable_approach_circle){for(let o of i)if(t<=o.start_time)this.draw_approach_circle(o,t)}e.restore()}precompute(t=0){this.precompute_focus_time=t,this.process_precompute_queue(t,E.precompute.bootstrap_budget_ms,!0),this.start_precompute_loop()}on_seek(t){this.precompute_focus_time=t,this.precompute_pause_until=performance.now()+90;let e=performance.now();if(e-this.last_seek_prefetch_at<48)return;this.last_seek_prefetch_at=e,this.process_precompute_queue(t,1,!1)}dispose(){this.stop_precompute_loop(),this.release_drawables(),this.timing_points=[],this.timing_resolver=null,super.dispose()}release_drawables(){this.stop_precompute_loop();for(let t of this.drawables)t.dispose();this.drawables=[],this.slider_drawables=[],this.slider_cache.clear(),this.slider_cache_bytes=0,this.spinner_objects=[],this.frame_visible_drawables.length=0,this.frame_visible_sliders.length=0,this.frame_visible_other.length=0}start_precompute_loop(){if(this.precompute_handle!==null)return;let t=()=>{if(this.precompute_handle=null,!this.has_uncached_sliders())return;if(performance.now()>=this.precompute_pause_until)this.process_precompute_queue(this.precompute_focus_time,E.precompute.frame_budget_ms,!1);this.precompute_handle=window.requestAnimationFrame(t)};this.precompute_handle=window.requestAnimationFrame(t)}stop_precompute_loop(){if(this.precompute_handle!==null)window.cancelAnimationFrame(this.precompute_handle),this.precompute_handle=null}has_uncached_sliders(){for(let t=0;t<this.slider_drawables.length;t++)if(!this.slider_drawables[t].has_body_cache())return!0;return!1}process_precompute_queue(t,e,r){if(this.slider_drawables.length===0)return;let i=performance.now()+e,s=0,n=r?2:1;while(performance.now()<i&&s<n){let a=this.pick_next_slider_for_precompute(t,r);if(!a)break;a.prepare_body_cache(),this.touch_slider_cache(a),s++}}pick_next_slider_for_precompute(t,e){let r=null,i=-1/0;for(let s=0;s<this.slider_drawables.length;s++){let n=this.slider_drawables[s],a=this.score_slider_for_precompute(n,t,e);if(a<=i)continue;i=a,r=n}return r??this.pick_nearest_uncached_slider(t)}score_slider_for_precompute(t,e,r){if(t.has_body_cache())return-1/0;let i=t.start_time-e,s=t.estimate_complexity();if(i>=-E.precompute.lookback_ms&&i<=E.precompute.lookahead_ms){let a=Math.abs(i)*0.025,o=r?0:s*0.02;return(r?s*0.2:0)-a-o}if(r)return s;return-1/0}pick_nearest_uncached_slider(t){let e=null,r=1/0;for(let i=0;i<this.slider_drawables.length;i++){let s=this.slider_drawables[i];if(s.has_body_cache())continue;let n=Math.abs(s.start_time-t);if(n>=r)continue;r=n,e=s}return e}touch_slider_cache(t){if(!t.has_body_cache())return;if(this.slider_cache.touch(t))return;let e=t.get_body_cache_bytes();this.slider_cache.set(t,e),this.slider_cache_bytes+=e,this.enforce_slider_cache_limit()}enforce_slider_cache_limit(){this.slider_cache.set_capacity(this.slider_cache_limit);while(this.slider_cache_bytes>E.slider_cache.max_bytes)if(!this.slider_cache.evict_oldest())break}trim_slider_cache_by_time(t){if(this.slider_cache.size===0)return;let e=[];for(let[r]of this.slider_cache.entries()){if(!r.has_body_cache()){e.push(r);continue}if(!(Math.abs(r.start_time-t)<=E.slider_cache.retention_ms||r.is_alive(t)))e.push(r)}for(let r=0;r<e.length;r++)this.slider_cache.delete(e[r]);this.enforce_slider_cache_limit()}trim_slider_runtime_path_cache(t){let e=E.slider_cache.retention_ms;for(let r=0;r<this.slider_drawables.length;r++){let i=this.slider_drawables[r];if(Math.abs(i.start_time-t)<=e||i.is_alive(t))continue;i.release_path_cache()}}create_slider_cache(t){return new _t(t,(e,r)=>{this.slider_cache_bytes=Math.max(0,this.slider_cache_bytes-r),e.release_body_cache()})}draw_approach_circle(t,e){let r=t.position,i=t.start_time-this.preempt,n=4-3*y((e-i)/this.preempt,0,1),a=Math.min(this.fade_in*2,this.preempt),o=y((e-i)/Math.max(1,a),0,1),c=this.skin.approach_circle_opacity*o;if(c<=0.01)return;this.backend.save(),this.backend.set_alpha(c);let _=this.skin_elements?.approachcircle;if(_){let h=this.radius*2*n;this.backend.draw_image(_,r[0]-h/2,r[1]-h/2,h,h)}else{let h=this.skin.approach_circle_use_combo_color?q(this.skin,t.combo_number,1):this.skin.approach_circle_color??"rgba(255,255,255,1)";this.backend.draw_circle(r[0],r[1],this.radius*n,"transparent",h,this.radius*this.skin.approach_circle_width)}this.backend.restore()}get_circle_alpha(t,e){let r=e-this.preempt;if(t<r)return 0;let i=y((t-r)/this.fade_in,0,1);if(H(this.mods,g.Hidden)){let s=e-this.preempt+this.fade_in,n=this.preempt*0.3;if(t>s){let a=y((t-s)/n,0,1);i*=1-a}}return i}draw_spinner(t,e){let r=t.time-this.preempt,i=y((e-r)/this.fade_in,0,1);if(e>t.end_time)i=1-D.OutCubic(y((e-t.end_time)/200,0,1));if(i<=0)return;let s=256,n=192,a=Math.max(1,t.end_time-t.time),o=y((e-t.time)/a,0,1);this.backend.save(),this.backend.set_alpha(i);let c=this.skin.spinner_size*(1-o);if(c>5)this.backend.begin_path(),this.backend.arc_to(s,n,c,0,Math.PI*2),this.backend.stroke_path("rgba(255,255,255,0.6)",4);this.backend.draw_circle(s,n,this.skin.spinner_size,"rgba(0,0,0,0.2)"),this.backend.draw_circle(s,n,12,"white"),this.backend.restore()}}var sr=11485,nr=8,pt=50,ui=0.4,mi=0.2,fi=0.68,bi=0.18,gi=0.04,vi=0.2,yi=0.5,xi=0.18,wi=0.5;class J extends ot{static MIN_KEY_COUNT=1;static MAX_KEY_COUNT=18;static DEFAULT_KEY_COUNT=4;key_count=4;scroll_time=sr/nr;hd_coverage=0.25;fi_coverage=0.6;gradient_ratio=0.2;press_start_sorted=[];press_end_sorted=[];press_start_index=0;press_end_index=0;active_press_objects=new Set;active_press_lane_counts=[];lane_impacts=[];last_press_time=Number.NEGATIVE_INFINITY;render_start_sorted=[];render_end_sorted=[];render_start_index=0;render_end_index=0;active_render_objects=new Set;last_render_time=Number.NEGATIVE_INFINITY;base_timing_points=[];constructor(t,e,r=0,i=K,s=null){super(t,e,r,i,s);this.update_scroll_time()}initialize(t){this.beatmap=t,this.objects=Ft(t).sort((e,r)=>e.time-r.time),this.key_count=this.resolve_key_count(t),this.press_start_sorted=this.objects,this.press_end_sorted=this.objects.slice().sort((e,r)=>e.end_time-r.end_time),this.render_start_sorted=this.objects,this.render_end_sorted=this.objects.slice().sort((e,r)=>e.end_time-r.end_time),this.base_timing_points=this.extract_base_timing_points(t),this.reset_pressed_state(),this.reset_render_state()}set_mods(t){this.mods=t,this.update_scroll_time()}update_scroll_time(){this.scroll_time=sr/nr}get_lane_metrics(){let t=Math.max(1,Number.isFinite(this.skin.mania_lane_width)?this.skin.mania_lane_width:30),e=Math.max(4,Number.isFinite(this.skin.mania_note_height)?this.skin.mania_note_height:15),r=Math.max(0,Number.isFinite(this.skin.mania_lane_spacing)?this.skin.mania_lane_spacing:1),i=Math.max(8,Math.min(qt,Number.isFinite(this.skin.mania_hit_position)?this.skin.mania_hit_position:364));return{lane_width:t,note_height:e,spacing:r,hit_pos:i}}time_to_y(t,e){let r=t/this.scroll_time;return e-r*e}get_stage_bottom_height(t,e){let r=this.get_mania_texture("mania-stage-bottom",t);if(!r)return 0;return Math.max(1,Math.round(r.height*(e/Math.max(1,r.width))))}draw_clipped_note_with_gradient(t,e,r,i,s,n,a){let o=Math.max(n,e),_=Math.min(a,e+i)-o;if(_<=0||r<=0)return;let h=this.backend;h.draw_rect(t,o,r,_,s);let p=h.create_linear_gradient(t,o,t,o+_,[{offset:0,color:`rgba(255,255,255,${bi})`},{offset:0.45,color:`rgba(255,255,255,${gi})`},{offset:1,color:`rgba(0,0,0,${vi})`}]);h.draw_rect_gradient(t,o,r,_,p)}get_lane(t){let e=t.data.pos,r=Number.isFinite(e?.[0])?e[0]:t.x,i=Math.floor(r*this.key_count/512);if(!Number.isFinite(i))i=0;if(H(this.mods,g.Mirror))i=this.key_count-1-i;return Math.max(0,Math.min(this.key_count-1,i))}resolve_key_count(t){let e=t?.Difficulty?.CircleSize;if(Number.isFinite(e)){let s=Math.round(e);if(s>=J.MIN_KEY_COUNT)return Math.max(J.MIN_KEY_COUNT,Math.min(J.MAX_KEY_COUNT,s))}let r=new Set;for(let s=0;s<t.HitObjects.length;s++){let n=t.HitObjects[s].x;if(Number.isFinite(n))r.add(Math.round(n))}let i=r.size;if(i>=J.MIN_KEY_COUNT&&i<=J.MAX_KEY_COUNT)return i;return J.DEFAULT_KEY_COUNT}reset_pressed_state(){this.press_start_index=0,this.press_end_index=0,this.active_press_objects.clear(),this.active_press_lane_counts=Array(this.key_count).fill(0),this.lane_impacts=Array(this.key_count).fill(0),this.last_press_time=Number.NEGATIVE_INFINITY}reset_render_state(){this.render_start_index=0,this.render_end_index=0,this.active_render_objects.clear(),this.last_render_time=Number.NEGATIVE_INFINITY}add_pressed_object(t){if(this.active_press_objects.has(t))return;this.active_press_objects.add(t);let e=this.get_lane(t);if(e>=0&&e<this.active_press_lane_counts.length)this.active_press_lane_counts[e]++}remove_pressed_object(t){if(!this.active_press_objects.delete(t))return;let e=this.get_lane(t);if(e>=0&&e<this.active_press_lane_counts.length&&this.active_press_lane_counts[e]>0)this.active_press_lane_counts[e]--}rebuild_pressed_state(t){this.active_press_objects.clear(),this.active_press_lane_counts.fill(0);for(let e=0;e<this.objects.length;e++){let r=this.objects[e];if(t>=r.time-pt&&t<=r.end_time+pt)this.add_pressed_object(r)}this.press_start_index=0;while(this.press_start_index<this.press_start_sorted.length&&this.press_start_sorted[this.press_start_index].time-pt<=t)this.press_start_index++;this.press_end_index=0;while(this.press_end_index<this.press_end_sorted.length&&this.press_end_sorted[this.press_end_index].end_time+pt<t)this.press_end_index++}update_pressed_state(t){if(!Number.isFinite(this.last_press_time)||t<this.last_press_time||t-this.last_press_time>1000){this.rebuild_pressed_state(t),this.last_press_time=t;return}while(this.press_start_index<this.press_start_sorted.length&&this.press_start_sorted[this.press_start_index].time-pt<=t)this.add_pressed_object(this.press_start_sorted[this.press_start_index]),this.press_start_index++;while(this.press_end_index<this.press_end_sorted.length&&this.press_end_sorted[this.press_end_index].end_time+pt<t)this.remove_pressed_object(this.press_end_sorted[this.press_end_index]),this.press_end_index++;this.last_press_time=t}add_active_render_object(t){this.active_render_objects.add(t)}remove_active_render_object(t){this.active_render_objects.delete(t)}rebuild_active_render_state(t,e,r){this.active_render_objects.clear();for(let i=0;i<this.objects.length;i++){let s=this.objects[i];if(s.time>r)break;if(s.end_time>=e)this.add_active_render_object(s)}this.render_start_index=0;while(this.render_start_index<this.render_start_sorted.length&&this.render_start_sorted[this.render_start_index].time<=r)this.render_start_index++;this.render_end_index=0;while(this.render_end_index<this.render_end_sorted.length&&this.render_end_sorted[this.render_end_index].end_time<e)this.render_end_index++}update_active_render_state(t,e,r){if(!Number.isFinite(this.last_render_time)||t<this.last_render_time||t-this.last_render_time>1000){this.rebuild_active_render_state(t,e,r),this.last_render_time=t;return}while(this.render_start_index<this.render_start_sorted.length&&this.render_start_sorted[this.render_start_index].time<=r)this.add_active_render_object(this.render_start_sorted[this.render_start_index]),this.render_start_index++;while(this.render_end_index<this.render_end_sorted.length&&this.render_end_sorted[this.render_end_index].end_time<e)this.remove_active_render_object(this.render_end_sorted[this.render_end_index]),this.render_end_index++;this.last_render_time=t}extract_base_timing_points(t){let e=[];for(let r=0;r<t.TimingPoints.length;r++){let i=t.TimingPoints[r],s=Number(i.time),n=Number(i.beatLength),a=Math.max(1,Math.round(Number(i.meter)||4)),o=Number(i.uninherited);if(!Number.isFinite(s)||!Number.isFinite(n)||n<=0)continue;if(Number.isFinite(o)&&o===0)continue;e.push({time:s,beat_length:n,meter:a})}if(e.length===0)e.push({time:0,beat_length:600,meter:4});return e.sort((r,i)=>r.time-i.time),e}get_mania_texture(t,e){let r=t.toLowerCase(),i=this.skin_elements?.mania_animations?.[r];if(i&&i.length>0){let s=this.skin.animation_framerate>0?this.skin.animation_framerate:60,n=Math.floor(Math.max(0,e)/1000*s)%i.length;return i[n]}return this.skin_elements?.mania_textures?.[r]??null}draw_column_sprite(t,e,r,i,s){this.backend.draw_image(t,e,r,Math.max(1,i),Math.max(1,s))}get_column_fallback_index(t){if(this.key_count%2===1&&t===Math.floor(this.key_count/2))return"s";let e=t%this.key_count;return Math.min(e,this.key_count-1-e)%2===0?"1":"2"}draw_stage_background(t,e,r,i,s){let{backend:n,key_count:a}=this,{lane_width:o,spacing:c}=this.get_lane_metrics(),_=Math.max(1,o-2*c),h=this.get_mania_texture("mania-stage-left",t);if(h&&h.height>0){let m=h.width*(s/h.height);n.set_alpha(1),n.draw_image(h,e-m,0,m,s)}let p=this.get_mania_texture("mania-stage-right",t);if(p&&p.height>0){let m=p.width*(s/p.height);n.set_alpha(1),n.draw_image(p,e+r,0,m,s)}let d=this.get_mania_texture("mania-stage-light",t);if(d){for(let m=0;m<a;m++){let l=e+m*o+c;n.set_alpha(ui),this.draw_column_sprite(d,l,0,_,i)}n.set_alpha(1);return}for(let m=0;m<a;m++){let l=e+m*o+c,u=dt(this.skin,a,m);n.set_alpha(mi),n.draw_rect(l,0,_,i,u)}n.set_alpha(fi);for(let m=1;m<a;m++){let l=e+m*o;n.draw_rect(l-0.75,0,1.5,i,"#ffffff")}n.set_alpha(1)}draw_bar_lines(t,e,r,i){let s=this.backend,n=t+this.scroll_time;for(let a=0;a<this.base_timing_points.length;a++){let o=this.base_timing_points[a],c=a+1<this.base_timing_points.length?this.base_timing_points[a+1].time:Number.POSITIVE_INFINITY,_=Math.max(t,o.time),h=Math.min(n,c);if(h<=_)continue;let p=Math.max(0,Math.ceil((_-o.time)/o.beat_length)),d=Math.floor((h-o.time)/o.beat_length);for(let m=p;m<=d;m++){let l=o.time+m*o.beat_length,u=this.time_to_y(l-t,i);if(u<0||u>i)continue;let f=m%o.meter===0;s.set_alpha(f?0.3:0.16),s.draw_rect(e,u,r,f?1.25:1,"#ffffff")}}s.set_alpha(1)}draw_note(t,e,r,i){let{lane_width:s,note_height:n,spacing:a,hit_pos:o}=i,c=this.get_lane(t),_=this.time_to_y(t.time-e,o);if(_<-n-64||_>o+n+8)return;let h=r+c*s,p=Math.max(1,s-2*a),d=dt(this.skin,this.key_count,c);this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(h+a,_-n,p,n,d,0,o)}draw_hold_note(t,e,r,i){let{lane_width:s,note_height:n,spacing:a,hit_pos:o}=i,c=t.data,_=this.get_lane(t),h=this.time_to_y(t.time-e,o),p=this.time_to_y(c.end_time-e,o);if(p>o+n+8&&h>o+n+8)return;if(p<-64&&h<-64)return;let d=r+_*s,m=Math.max(1,s-2*a),l=dt(this.skin,this.key_count,_),u=p,b=(t.time<=e?o:h)-u;if(b>0)this.backend.set_alpha(0.92),this.draw_clipped_note_with_gradient(d+a,u,m,b,l,0,o);if(t.time>=e)this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(d+a,h-n,m,n,l,0,o);if(c.end_time>=e)this.backend.set_alpha(1),this.draw_clipped_note_with_gradient(d+a,p-n,m,n,l,0,o);this.backend.set_alpha(1)}draw_hit_glow(t,e,r){let{lane_width:i,spacing:s,hit_pos:n}=r,{backend:a,key_count:o}=this;if(this.active_press_objects.size===0)return;let c=this.lane_impacts;if(c.length!==o)this.lane_impacts=Array(o).fill(0);else c.fill(0);let _=this.lane_impacts;for(let p of this.active_press_objects){let d=0;if(Wt(p)){let l=p.data;if(t>=p.time&&t<=l.end_time)d=0.35;else if(t<p.time){let u=p.time-t;if(u<=120)d=(1-u/120)*0.7}else{let u=t-l.end_time;if(u<=120)d=(1-u/120)*0.35}}else{let l=Math.abs(t-p.time);if(l<=120)d=1-l/120}if(d<=0)continue;let m=this.get_lane(p);if(d>_[m])_[m]=d}let h=this.get_mania_texture("mania-stage-light",t);a.set_blend_mode("lighter");for(let p=0;p<o;p++){let d=_[p];if(d<=0)continue;let m=e+p*i+s,l=Math.max(1,i-2*s),u=m+l*0.5;if(h){let b=Math.max(16,n*(0.55+d*0.25));a.set_alpha(yi*d),a.draw_image(h,m,n-b,l,b),a.set_alpha(xi*d),a.draw_image(h,m,n-b*0.7,l,b*0.7)}else{let b=Math.max(16,72*d),v=Math.max(2,l*0.16);a.set_alpha(0.4*d),a.draw_rect(u-v*0.5,n-b,v,b,"#cfe9ff")}let f=Math.max(3,l*0.6);a.set_alpha(wi*d),a.draw_rect(u-f*0.5,n-2,f,4,"#ffffff")}a.set_blend_mode("normal"),a.set_alpha(1)}draw_judgment_line(t,e){let{lane_width:r,hit_pos:i}=e,s=r*this.key_count,n=this.get_mania_texture("mania-stage-hint",0);if(n){let a=Math.max(2,Math.round(n.height*(s/Math.max(1,n.width))));this.backend.set_alpha(1),this.backend.draw_image(n,t,i-a,s,a);return}this.backend.draw_rect(t,i-1,s,2,"#ffffff")}draw_lane_keys(t,e,r){let{lane_width:i,hit_pos:s,spacing:n,note_height:a}=r,o=a+5;this.update_pressed_state(t);for(let _=0;_<this.key_count;_++){let h=(this.active_press_lane_counts[_]??0)>0,p=e+_*i,d=dt(this.skin,this.key_count,_),m=this.get_column_fallback_index(_),l=this.get_mania_texture(`mania-key${m}`,t),u=this.get_mania_texture(`mania-key${m}d`,t),f=Math.max(1,i-2*n);if(h&&u){this.backend.set_alpha(1),this.draw_column_sprite(u,p+n,s,f,o);continue}if(l){this.backend.set_alpha(1),this.draw_column_sprite(l,p+n,s,f,o);continue}if(this.backend.set_alpha(0.38),this.backend.draw_rect(p+n,s,f,o,d),h)this.backend.set_alpha(0.72),this.backend.draw_rect(p+n,s,f,o,"#ff6666")}let c=this.get_mania_texture("mania-stage-bottom",t);if(c){let _=this.key_count*i,h=Math.max(1,Math.round(c.height*(_/Math.max(1,c.width))));this.backend.set_alpha(1),this.backend.draw_image(c,e,s,_,h)}this.backend.set_alpha(1)}draw_playfield_frame(t,e,r){let s=Math.max(1,r-0);this.backend.set_alpha(0.92),this.backend.draw_rect(t,0,e,1.5,"#f0f4ff"),this.backend.draw_rect(t,r-1.5,e,1.5,"#f0f4ff"),this.backend.draw_rect(t,0,1.5,s,"#f0f4ff"),this.backend.draw_rect(t+e-1.5,0,1.5,s,"#f0f4ff"),this.backend.set_alpha(1)}render(t){let{backend:e,config:r}=this,i=this.get_lane_metrics(),s=Math.max(1,this.key_count*i.lane_width),n=Math.floor((Gt-s)/2),a=this.get_stage_bottom_height(t,s),o=i.hit_pos+i.note_height+5+a,c=t-i.note_height*4,_=t+this.scroll_time+i.note_height*4;this.render_background(),e.save(),e.translate(r.offset_x,r.offset_y),e.scale(r.scale,r.scale),this.draw_stage_background(t,n,s,i.hit_pos,o),this.draw_bar_lines(t,n,s,i.hit_pos),e.set_alpha(0.55),e.draw_rect(n,0,s,i.hit_pos,"#000000"),e.set_alpha(1),this.update_active_render_state(t,c,_);for(let d of this.active_render_objects)if(Wt(d))this.draw_hold_note(d,t,n,i);else this.draw_note(d,t,n,i);this.draw_hit_glow(t,n,i),this.draw_judgment_line(n,i),this.draw_lane_keys(t,n,i),this.draw_playfield_frame(n,s,o);let h=H(this.mods,g.Hidden),p=H(this.mods,g.FadeIn);if(h||p){let d=h?this.hd_coverage:this.fi_coverage,m=i.hit_pos*d,l=i.hit_pos*this.gradient_ratio;if(h){let u=i.hit_pos-m,f=l/m,b=e.create_linear_gradient(n,u,n,i.hit_pos,[{offset:0,color:"rgba(0,0,0,0)"},{offset:f*0.4,color:"rgba(0,0,0,0.3)"},{offset:f*0.7,color:"rgba(0,0,0,0.75)"},{offset:f*0.9,color:"rgba(0,0,0,0.95)"},{offset:f,color:"rgba(0,0,0,1)"},{offset:1,color:"rgba(0,0,0,1)"}]);e.draw_rect_gradient(n,u,s,m,b)}else{let u=(m-l)/m,f=e.create_linear_gradient(n,0,n,m,[{offset:0,color:"rgba(0,0,0,1)"},{offset:u,color:"rgba(0,0,0,1)"},{offset:u+(1-u)*0.1,color:"rgba(0,0,0,0.95)"},{offset:u+(1-u)*0.4,color:"rgba(0,0,0,0.75)"},{offset:u+(1-u)*0.7,color:"rgba(0,0,0,0.3)"},{offset:1,color:"rgba(0,0,0,0)"}]);e.draw_rect_gradient(n,0,s,m,f)}}e.restore()}}class jt{video=null;object_url=null;_offset=0;get element(){return this.video}get offset(){return this._offset}async load(t,e=0){this.dispose(),this._offset=e,this.video=document.createElement("video"),this.video.muted=!0,this.video.loop=!1,this.video.playsInline=!0,this.object_url=URL.createObjectURL(t),this.video.src=this.object_url,await new Promise((r,i)=>{if(!this.video)return i(Error("No video element"));this.video.onloadeddata=()=>r(),this.video.onerror=()=>i(Error("Failed to load video"))})}sync(t){if(!this.video)return;let e=(t-this._offset)/1000;if(e<0){if(!this.video.paused)this.video.pause();return}if(Math.abs(this.video.currentTime-e)>0.1)this.video.currentTime=e}play(){if(this.video&&this.video.paused)this.video.play().catch(()=>{console.warn("[VideoController] failed to play video")})}pause(){if(this.video&&!this.video.paused)this.video.pause()}seek(t){if(!this.video)return;let e=Math.max(0,(t-this._offset)/1000);this.video.currentTime=e}dispose(){if(this.video)this.video.pause(),this.video.src="",this.video=null;if(this.object_url)URL.revokeObjectURL(this.object_url),this.object_url=null}}class we{static PRECISE_BUFFER_MAX_BYTES=8388608;audio_context;gain_node;preserve_pitch=!1;use_precise_buffer=!1;decoded_buffer=null;buffer_source=null;media_element=null;media_source=null;media_url=null;_is_playing=!1;_is_loaded=!1;_duration=0;pause_time=0;rate=1;started_at_context_time=0;started_from_time=0;constructor(t){this.audio_context=t,this.gain_node=this.audio_context.createGain(),this.gain_node.connect(this.audio_context.destination)}get is_playing(){return this._is_playing}get is_loaded(){return this._is_loaded}get duration(){return this._duration}get speed_multiplier(){return this.rate}get current_time(){if(this.use_precise_buffer&&this.decoded_buffer){if(!this._is_playing)return this.pause_time;let i=(this.audio_context.currentTime-this.started_at_context_time)*1000*this.rate,s=this.started_from_time+i;if(s>=this._duration)return this._duration;return Math.max(0,s)}if(!this.media_element)return this.pause_time;if(!this._is_playing)return this.pause_time;let t=Math.max(0,this.media_element.currentTime*1000);if(Number.isFinite(t)){if(t>=this._duration)return this._duration;return t}let e=(this.audio_context.currentTime-this.started_at_context_time)*1000*this.rate,r=this.started_from_time+e;if(r>=this._duration)return this._duration;return Math.max(0,r)}async load(t,e=1){if(this.stop(),this.release_media(),this.release_precise_buffer(),this.rate=Math.max(0.1,e),this.use_precise_buffer=!1,await this.load_media_element(t),t.byteLength<=we.PRECISE_BUFFER_MAX_BYTES)try{await this.load_precise_buffer(t)}catch{}this.use_precise_buffer=!this.preserve_pitch&&this.decoded_buffer!==null,this._is_loaded=!0,this.pause_time=0,this.started_at_context_time=0,this.started_from_time=0}async play(t){if(!this.use_precise_buffer&&!this.media_element){console.warn("[AudioEngine] Cannot play: not loaded");return}let e=t!==void 0?t:this.pause_time,r=Math.max(0,Math.min(e,this._duration));if(this.use_precise_buffer&&this.decoded_buffer){this.start_precise_playback(r);return}let i=this.media_element;if(!i){console.warn("[AudioEngine] Cannot play: media element unavailable");return}i.currentTime=r/1000,await this.wait_for_seek_settle(r),i.playbackRate=this.rate,this.pause_time=r,this.started_from_time=r,this.started_at_context_time=this.audio_context.currentTime;try{await i.play()}catch(s){throw this._is_playing=!1,s}this._is_playing=!0}pause(){if(!this._is_playing)return;if(this.use_precise_buffer){this.pause_time=this.current_time,this.stop_precise_playback(!1),this._is_playing=!1;return}if(this.media_element)this.media_element.pause(),this.pause_time=Math.max(0,this.media_element.currentTime*1000);this._is_playing=!1}seek(t){let e=Math.max(0,Math.min(t,this._duration));if(this.pause_time=e,this.use_precise_buffer&&this.decoded_buffer){if(this._is_playing)this.start_precise_playback(e);else this.started_from_time=e,this.started_at_context_time=this.audio_context.currentTime;return}if(this.media_element)this.media_element.currentTime=e/1000,this.wait_for_seek_settle(e);if(this._is_playing)this.started_from_time=e,this.started_at_context_time=this.audio_context.currentTime}stop(){if(this.use_precise_buffer)this.stop_precise_playback(!1);if(this.media_element)this.media_element.pause(),this.media_element.currentTime=0;this._is_playing=!1,this.pause_time=0,this.started_at_context_time=0,this.started_from_time=0}get_host_time(t){let e=t-this.current_time;return this.audio_context.currentTime+e/1000/this.rate}set_rate(t){let e=this.current_time;if(this.rate=Math.max(0.1,t),this.use_precise_buffer&&this._is_playing)this.start_precise_playback(e);if(this.media_element)this.media_element.playbackRate=this.rate,this.media_element.preservesPitch=this.preserve_pitch,this.media_element.webkitPreservesPitch=this.preserve_pitch;this.started_from_time=e,this.started_at_context_time=this.audio_context.currentTime,this.pause_time=e}set_volume(t){if(this.gain_node.gain.value=y(t,0,1),this.media_element)this.media_element.volume=1}async set_pitch_preserve(t){if(this.preserve_pitch===t)return;let e=this._is_playing,r=this.current_time;if(this.preserve_pitch=t,this.media_element)this.media_element.preservesPitch=t,this.media_element.webkitPreservesPitch=t;let i=!t&&this.decoded_buffer!==null;if(i===this.use_precise_buffer)return;if(this.pause(),this.use_precise_buffer=i,e)await this.play(r);else this.seek(r)}dispose(){this.stop(),this.release_media(),this.release_precise_buffer(),this._is_loaded=!1,this._duration=0,this.pause_time=0,this._is_playing=!1,this.started_at_context_time=0,this.started_from_time=0,this.gain_node.disconnect()}start_precise_playback(t){if(!this.decoded_buffer)return;this.stop_precise_playback(!1);let e=this.audio_context.createBufferSource();e.buffer=this.decoded_buffer,e.playbackRate.value=this.rate,e.connect(this.gain_node),e.onended=()=>{if(this.buffer_source!==e)return;if(this.buffer_source=null,this._is_playing)this._is_playing=!1,this.pause_time=this._duration},e.start(0,Math.max(0,t/1000)),this.buffer_source=e,this.pause_time=t,this.started_from_time=t,this.started_at_context_time=this.audio_context.currentTime,this._is_playing=!0}stop_precise_playback(t){let e=this.buffer_source;if(!e){if(t)this.pause_time=0;return}this.buffer_source=null,e.onended=null;try{e.stop()}catch{}if(e.disconnect(),t)this.pause_time=0}async load_precise_buffer(t){let e=t.slice(0),r=await this.audio_context.decodeAudioData(e);this.decoded_buffer=r,this._duration=Math.max(0,r.duration*1000)}async load_media_element(t){this.release_media();let e=new Blob([t]),r=URL.createObjectURL(e),i=new Audio;i.preload="metadata",i.src=r,i.playbackRate=this.rate,i.volume=1,i.preservesPitch=this.preserve_pitch,i.webkitPreservesPitch=this.preserve_pitch,await new Promise((s,n)=>{let a=!1,o=()=>{i.onloadedmetadata=null,i.onerror=null};i.onloadedmetadata=()=>{if(a)return;a=!0,o(),s()},i.onerror=()=>{if(a)return;a=!0,o(),n(Error("Failed to load media audio metadata"))}}),i.onended=()=>{if(this.media_element!==i)return;if(this._is_playing)this._is_playing=!1,this.pause_time=this._duration},this.media_element=i,this.media_source=this.audio_context.createMediaElementSource(i),this.media_source.connect(this.gain_node),this.media_url=r,this._duration=Math.max(0,(i.duration||0)*1000)}async wait_for_seek_settle(t){if(!this.media_element)return;let e=this.media_element,r=90,i=800,s=e.currentTime*1000;if(Math.abs(s-t)<=r)return;await new Promise((n)=>{let a=!1,o=window.setTimeout(()=>{c(),n()},i),c=()=>{if(a)return;a=!0,window.clearTimeout(o),e.removeEventListener("seeked",_),e.removeEventListener("timeupdate",_),e.removeEventListener("error",h)},_=()=>{if(Math.abs(e.currentTime*1000-t)<=r)c(),n()},h=()=>{c(),n()};e.addEventListener("seeked",_),e.addEventListener("timeupdate",_),e.addEventListener("error",h)})}release_media(){if(this.media_source)this.media_source.disconnect(),this.media_source=null;if(this.media_element)this.media_element.onended=null,this.media_element.onerror=null,this.media_element.onloadedmetadata=null,this.media_element.pause(),this.media_element.src="",this.media_element.load(),this.media_element=null;if(this.media_url)URL.revokeObjectURL(this.media_url),this.media_url=null}release_precise_buffer(){this.stop_precise_playback(!1),this.decoded_buffer=null,this.use_precise_buffer=!1}}class ar{audio_context;gain_node;custom_samples=new Map;constructor(t){this.audio_context=t,this.gain_node=this.audio_context.createGain(),this.gain_node.connect(this.audio_context.destination)}set_volume(t){this.gain_node.gain.value=y(t,0,1)}async load_samples(t){this.custom_samples.clear(),await this.load_into_cache(t,this.custom_samples)}async load_samples_from_files(t){this.custom_samples.clear(),await this.load_files_into_cache(t,this.custom_samples)}clear(){this.custom_samples.clear()}play(t,e,r,i,s=100,n,a=0){let o=this.get_set_name(t),c=this.get_set_name(e);if(n){let _=this.get_sample_key_from_name(n);if(_&&this.play_buffer(_,s,a))return}if(this.play_sound(o,"hitnormal",i,s,a),r&kt.Whistle)this.play_sound(c,"hitwhistle",i,s,a);if(r&kt.Finish)this.play_sound(c,"hitfinish",i,s,a);if(r&kt.Clap)this.play_sound(c,"hitclap",i,s,a)}play_sample(t,e,r,i=100,s=0){let n=this.get_set_name(t);this.play_sound(n,e,r,i,s)}play_custom(t,e=100,r=0){let i=t.toLowerCase();return this.play_buffer(i,e,r)}dispose(){this.custom_samples.clear(),this.gain_node.disconnect()}play_sound(t,e,r,i,s){let n=[];if(r>1)n.push(`${t}-${e}${r}`);if(n.push(`${t}-${e}`),t!=="normal"){if(r>1)n.push(`normal-${e}${r}`);n.push(`normal-${e}`)}for(let a of n)if(this.play_buffer(a,i,s))return}play_buffer(t,e,r){let i=this.custom_samples.get(t);if(!i)return!1;let s=this.audio_context.createBufferSource();s.buffer=i;let n=this.audio_context.createGain();return n.gain.value=e/100,s.connect(n),n.connect(this.gain_node),s.onended=()=>{s.disconnect(),n.disconnect()},s.start(r),!0}get_set_name(t){switch(t){case 3:return"drum";case 2:return"soft";default:return"normal"}}get_sample_key_from_name(t){let e=t.split("?")[0].split("#")[0],i=e.split("/").pop()??e;if(!i)return null;return i.toLowerCase().replace(/\.(wav|mp3|ogg)$/i,"")}get_sample_key_from_url(t){let e=this.get_sample_key_from_name(t);if(!e)return null;if(!t.toLowerCase().match(/\.(wav|mp3|ogg)(\?|#|$)/))return null;return e}async load_into_cache(t,e){if(t.length==0)return;let r=[],i=[];for(let s=0;s<t.length;s++){let n=t[s];i.push((async()=>{let a=this.get_sample_key_from_url(n);if(!a){r.push(n);return}if(e.has(a))return;await this.load_single_sample(n,a,e,r)})())}await Promise.all(i),this.report_failures(r.length,e.size)}async load_single_sample(t,e,r,i){try{let s=await fetch(t);if(!s.ok){i.push(t);return}let n=await s.arrayBuffer();if(n.byteLength<128){i.push(t);return}let a=await this.audio_context.decodeAudioData(n.slice(0));r.set(e,a)}catch{i.push(t)}}async load_files_into_cache(t,e){if(t.size==0)return;let r=[],i=[];for(let[s,n]of t)i.push((async()=>{let a=this.get_sample_key_from_name(s);if(!a||e.has(a))return;if(n.byteLength<128){r.push(s);return}try{let o=await this.audio_context.decodeAudioData(n.slice(0));e.set(a,o)}catch{r.push(s)}})());await Promise.all(i),this.report_failures(r.length,e.size)}report_failures(t,e){if(t>0&&e===0)console.warn(`[HitsoundMixer] Failed to load ${t} hitsounds`)}}class Ut{music_player;hitsound_mixer;constructor(t){this.music_player=new we(t),this.hitsound_mixer=new ar(t)}get is_playing(){return this.music_player.is_playing}get is_loaded(){return this.music_player.is_loaded}get duration(){return this.music_player.duration}get current_time(){return this.music_player.current_time}get rate(){return this.music_player.speed_multiplier}get speed_multiplier(){return this.music_player.speed_multiplier}async load(t,e=1){await this.music_player.load(t,e)}async play(t){await this.music_player.play(t)}pause(){this.music_player.pause()}seek(t){this.music_player.seek(t)}stop(){this.music_player.stop()}get_host_time(t){return this.music_player.get_host_time(t)}set_rate(t){this.music_player.set_rate(t)}async set_pitch_preserve(t){await this.music_player.set_pitch_preserve(t)}set_music_volume(t){this.music_player.set_volume(t)}set_hitsound_volume(t){this.hitsound_mixer.set_volume(t)}async load_hitsounds(t){await this.hitsound_mixer.load_samples(t)}async load_hitsounds_from_files(t){await this.hitsound_mixer.load_samples_from_files(t)}clear_hitsounds(){this.hitsound_mixer.clear()}dispose(){this.music_player.dispose(),this.hitsound_mixer.dispose()}}class ke{files;audio_filename;background_filename;video_filename;video_offset;constructor(t){this.files=t.files,this.audio_filename=t.audio_filename,this.background_filename=t.background_filename,this.video_filename=t.video_filename,this.video_offset=t.video_offset}resolve(){let t=this.audio_filename?this.find_file(this.audio_filename):void 0,e=this.background_filename?this.find_file(this.background_filename):void 0,r=this.video_filename?this.find_file(this.video_filename):void 0;return{audio:t,background:e?new Blob([e]):void 0,video:r?new Blob([r]):void 0,video_offset:this.video_offset}}find_file(t){if(this.files.has(t))return this.files.get(t);let e=t.toLowerCase();for(let[r,i]of this.files)if(r.toLowerCase()===e)return i;return}}var ki=100,or=20;class Me{audio;hitsounds;resources=null;timing_points=[];timing_resolver=null;audio_offset=20;next_hit_object_index=0;hitsound_lookahead_ms=ki;last_schedule_time=-1/0;nightcore_enabled=!1;nightcore_points=[];nightcore_index=0;nightcore_next_time=0;nightcore_last_schedule_time=-1/0;constructor(t,e){this.audio=t;this.hitsounds=e}set_context(t,e,r,i){this.resources=t,this.timing_points=e,this.timing_resolver=r,this.audio_offset=i,this.next_hit_object_index=0,this.last_schedule_time=-1/0,this.configure_nightcore_points()}set_audio_offset(t){this.audio_offset=t}set_hitsound_lookahead(t){this.hitsound_lookahead_ms=Math.max(0,t)}set_nightcore_enabled(t){this.nightcore_enabled=t,this.reset_nightcore_state(0)}update_hit_index(t){if(!this.resources?.beatmap)return;let e=this.resources.beatmap.HitObjects;if(this.next_hit_object_index>0&&e[this.next_hit_object_index-1].time>t)this.next_hit_object_index=0;while(this.next_hit_object_index<e.length&&e[this.next_hit_object_index].time<t)this.next_hit_object_index++;this.last_schedule_time=t,this.reset_nightcore_state(t)}schedule_hitsounds(t){if(!this.resources?.beatmap)return 0;let e=0,r=this.resources.beatmap.HitObjects,i=t+this.hitsound_lookahead_ms,s=Math.max(t-or,this.last_schedule_time);while(this.next_hit_object_index<r.length&&r[this.next_hit_object_index].time<=i){let n=r[this.next_hit_object_index];if(n.time>=s)this.play_hitsound(n),e++;this.next_hit_object_index++}if(this.nightcore_enabled)e+=this.schedule_nightcore(t);if(t>this.last_schedule_time)this.last_schedule_time=t;return e}play_hitsound(t){let e=this.get_timing_point(t.time),r=this.resolve_sample_settings(e,t.hitSample);if((t.type&j.Slider)===0){this.play_node_hitsound(t.time,t.hitSound,r,r.custom_filename);return}let i=this.resources?.beatmap;if(!i)return;let s=this.timing_resolver?.get_state_at(t.time)??{base_beat_length:600,sv_multiplier:1},n=t.length??0,a=Lt(n,i,s),o=Math.max(1,t.slides||1);if(a<=0||n<=0){this.play_node_hitsound(t.time,t.hitSound,r,r.custom_filename);return}let c=t.edgeSounds??[],_=t.edgeSets??[];for(let d=0;d<=o;d++){let m=t.time+a*d,l=c.length>0?c[d]??0:d==0?t.hitSound:0,u=_.length>0?_[d]:void 0,f=this.resolve_edge_sets(r,u),b=d==0?r.custom_filename:void 0;this.play_node_hitsound(m,l,{...r,...f},b)}let h=Bt(i,s),p=Ot({start_time:t.time,span_duration:a,span_count:o,length:n,tick_distance:h.tick_distance,min_distance_from_end:h.min_distance_from_end,get_position_at_progress:()=>[0,0]});for(let d of p.ticks){let m=this.audio.get_host_time(d.time+this.audio_offset);this.hitsounds.play_sample(r.normal_set,"slidertick",r.index,r.volume,m)}}play_node_hitsound(t,e,r,i){let s=this.audio.get_host_time(t+this.audio_offset);this.hitsounds.play(r.normal_set,r.addition_set,e,r.index,r.volume,i,s)}resolve_sample_settings(t,e){let{volume:r,sampleSet:i,sampleSet:s,sampleIndex:n}=t,a=void 0;if(e){if(e.normalSet!==0){if(i=e.normalSet,e.additionSet===0)s=i}if(e.additionSet!==0)s=e.additionSet;if(e.index!==0)n=e.index;if(e.volume!==0)r=e.volume;a=e.filename||void 0}if(i===0)i=1;if(s===0)s=i;return{normal_set:i,addition_set:s,index:n,volume:r,custom_filename:a}}resolve_edge_sets(t,e){let{normal_set:r,addition_set:i}=t;if(e){let{normalSet:s,additionSet:n}=e;if(s!==0)r=s;if(n!==0)i=n;else i=r}if(r===0)r=1;if(i===0)i=r;return{normal_set:r,addition_set:i}}get_timing_point(t){let e=this.timing_points;if(e.length==0)return{time:0,beatLength:600,meter:4,sampleSet:1,sampleIndex:1,volume:100,uninherited:1,effects:0};for(let r=e.length-1;r>=0;r--)if(e[r].time<=t)return e[r];return e[0]}configure_nightcore_points(){let t=[];for(let e=0;e<this.timing_points.length;e++){let r=this.timing_points[e];if(r.uninherited===1&&r.beatLength>0)t.push({time:r.time,beat_length:r.beatLength,meter:r.meter||4,volume:r.volume||100})}if(t.length==0)t.push({time:0,beat_length:600,meter:4,volume:100});this.nightcore_points=t,this.nightcore_index=0,this.nightcore_next_time=t[0].time,this.nightcore_last_schedule_time=-1/0}reset_nightcore_state(t){if(!this.nightcore_enabled||this.nightcore_points.length==0)return;let e=0;for(let o=0;o<this.nightcore_points.length;o++)if(this.nightcore_points[o].time<=t)e=o;else break;let r=this.nightcore_points[e],i=Math.max(1,r.beat_length),s=t-r.time,n=s<=0?0:Math.floor(s/i),a=r.time+n*i;if(a<t)a+=i;this.nightcore_index=e,this.nightcore_next_time=a,this.nightcore_last_schedule_time=t}schedule_nightcore(t){if(this.nightcore_points.length==0)return 0;let e=t+this.hitsound_lookahead_ms,r=Math.max(t-or,this.nightcore_last_schedule_time),i=0,s=this.nightcore_index,n=this.nightcore_next_time;while(s<this.nightcore_points.length&&n<=e){let a=this.nightcore_points[s],o=Math.max(1,a.beat_length),c=s+1<this.nightcore_points.length?this.nightcore_points[s+1].time:Number.POSITIVE_INFINITY;if(n>=c){if(s++,s>=this.nightcore_points.length)break;n=Math.max(n,this.nightcore_points[s].time);continue}if(n>=r){let _=Math.round((n-a.time)/o);if(this.play_nightcore_beat(a,_,n))i++}n+=o}if(this.nightcore_index=Math.min(s,this.nightcore_points.length-1),this.nightcore_next_time=n,t>this.nightcore_last_schedule_time)this.nightcore_last_schedule_time=t;return i}play_nightcore_beat(t,e,r){let i=this.audio.get_host_time(r+this.audio_offset),s=t.meter||4,n=s>0?e%s:e%4,a=!1;if(n===0)a=this.hitsounds.play_custom("nightcore-finish",t.volume,i)||a,a=this.hitsounds.play_custom("nightcore-kick",t.volume,i)||a;else if(s===3&&n===1)a=this.hitsounds.play_custom("nightcore-clap",t.volume,i)||a;else if(s!==3&&n===2)a=this.hitsounds.play_custom("nightcore-clap",t.volume,i)||a;else a=this.hitsounds.play_custom("nightcore-hat",Math.max(20,t.volume-20),i)||a;return a}}var Mi=[".wav",".mp3",".ogg"],Ii=/^(normal|soft|drum)-(hitnormal|hitwhistle|hitfinish|hitclap|slidertick|sliderslide|sliderwhistle)\d*$/i,cr=(t,e,r)=>{let i=new Set;for(let a of t.HitObjects){let o=a.hitSample?.filename?.trim();if(o)i.add(o.toLowerCase())}let s=new Map,n=r?.toLowerCase();for(let[a,o]of e){let c=a.toLowerCase();if(!Ti(c))continue;if(n&&c==n)continue;let _=Ri(c),h=_.replace(/\.(wav|mp3|ogg)$/,""),p=Ii.test(h),d=i.has(_)||i.has(h)||i.has(c);if(p||d)s.set(a,o)}return s},Ti=(t)=>{for(let e of Mi)if(t.endsWith(e))return!0;return!1},Ri=(t)=>{let e=t.split("?")[0].split("#")[0];return e.split("/").pop()??e};var Ai=["rgb(255, 192, 0)","rgb(0, 202, 0)","rgb(18, 124, 255)","rgb(242, 24, 57)"],Ie=(t)=>{let e=t.trim().toLowerCase();if(e==="1"||e==="true"||e==="yes")return!0;if(e==="0"||e==="false"||e==="no")return!1;return},_r=(t)=>{let e={general:{},fonts:{},colours:{combo_colors:[]}},r="",i=t.split(/\r?\n/);for(let s of i){let n=s.trim();if(n.length===0||n.startsWith("//"))continue;if(n.startsWith("[")&&n.endsWith("]")){r=n.slice(1,-1).toLowerCase();continue}let a=n.indexOf(":");if(a===-1)continue;let o=n.slice(0,a).trim().toLowerCase(),c=n.slice(a+1).trim();switch(r){case"general":Ei(e.general,o,c);break;case"colours":Hi(e.colours,o,c);break;case"fonts":Di(e.fonts,o,c);break}}if(e.colours.combo_colors.length===0)e.colours.combo_colors=[...Ai];return e},Di=(t,e,r)=>{switch(e){case"hitcircleprefix":if(r.length>0)t.hit_circle_prefix=r.trim();break;case"hitcircleoverlap":{let i=Number.parseInt(r,10);if(Number.isFinite(i))t.hit_circle_overlap=i;break}}},Ei=(t,e,r)=>{switch(e){case"name":t.name=r;break;case"author":t.author=r;break;case"version":t.version=r;break;case"hitcircleoverlayabovenumber":case"hitcircleoverlayabovenumer":t.hit_circle_overlay_above_number=Ie(r);break;case"sliderballflip":t.slider_ball_flip=Ie(r);break;case"allowslidertainttint":case"allowsliderballtint":t.allow_slider_ball_tint=Ie(r);break;case"sliderballframes":{let i=Number.parseInt(r,10);if(Number.isFinite(i)&&i>0)t.slider_ball_frames=i;break}case"animationframerate":{let i=Number.parseInt(r,10);if(Number.isFinite(i))t.animation_framerate=i;break}}},Hi=(t,e,r)=>{let i=Ni(r);if(!i)return;let s=e.match(/^combo(\d+)$/);if(s){let n=parseInt(s[1])-1;while(t.combo_colors.length<=n)t.combo_colors.push("");t.combo_colors[n]=i;return}switch(e){case"sliderborder":t.slider_border=i;break;case"slidertrackoverride":t.slider_track_override=i;break;case"sliderball":t.slider_ball=i;break;case"spinnerbackground":t.spinner_background=i;break}},Ni=(t)=>{let e=t.split(",").map((n)=>parseInt(n.trim()));if(e.length<3||e.some(isNaN))return null;let[r,i,s]=e;if(e.length>=4){let n=e[3]/255;return`rgba(${r}, ${i}, ${s}, ${n.toFixed(2)})`}return`rgb(${r}, ${i}, ${s})`},hr=(t,e)=>{let r={...t};if(e.colours.combo_colors.length>0)r.combo_colors=e.colours.combo_colors.filter((i)=>i.length>0);if(e.colours.slider_border)r.slider_border_color=e.colours.slider_border;if(e.colours.slider_track_override)r.slider_track_override=e.colours.slider_track_override;if(e.colours.slider_ball)r.slider_ball_color=e.colours.slider_ball;if(e.colours.spinner_background)r.spinner_background_color=e.colours.spinner_background;if(e.general.hit_circle_overlay_above_number!==void 0)r.hit_circle_overlay_above_number=e.general.hit_circle_overlay_above_number;if(e.general.slider_ball_flip!==void 0)r.slider_ball_flip=e.general.slider_ball_flip;if(e.general.allow_slider_ball_tint!==void 0)r.allow_slider_ball_tint=e.general.allow_slider_ball_tint;if(e.general.slider_ball_frames!==void 0)r.slider_ball_frames=e.general.slider_ball_frames;if(e.general.animation_framerate!==void 0)r.animation_framerate=e.general.animation_framerate;if(e.fonts.hit_circle_prefix!==void 0)r.hit_circle_prefix=e.fonts.hit_circle_prefix;if(e.fonts.hit_circle_overlap!==void 0)r.hit_circle_overlap=e.fonts.hit_circle_overlap;return r};var dr=[".png",".jpg",".jpeg",".webp"],pr=(t,e)=>{if(t.has(e))return{name:e,data:t.get(e)};let r=e.toLowerCase();for(let[i,s]of t)if(i.toLowerCase()===r)return{name:i,data:s};for(let[i,s]of t){let n=i.split("/").pop();if(n&&n.toLowerCase()===r)return{name:i,data:s}}return null},Ci=(t,e)=>{for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<dr.length;s++){let n=`${i}${dr[s]}`,a=pr(t,n);if(a)return{filename:a.name,data:a.data}}}return null},Si=async(t)=>{let e=new Blob([t.data]),r=URL.createObjectURL(e);try{let i=new Image;i.src=r,await i.decode();let s=t.filename.toLowerCase().includes("@2x")?2:1;return{image:{source:i,width:i.naturalWidth/s,height:i.naturalHeight/s},url:r}}catch(i){return URL.revokeObjectURL(r),console.warn(`[Skin] Failed to decode ${t.filename}`,i),null}},ut=(t,e)=>{if(t.width<=e&&t.height<=e)return t;let r=t.source,i=Number(r?.width??0),s=Number(r?.height??0);if(i<=0||s<=0||t.width<=0||t.height<=0)return t;let n=i/t.width,a=s/t.height,o=Math.min(t.width,e),c=Math.min(t.height,e),_=Math.max(1,Math.round(o*n)),h=Math.max(1,Math.round(c*a)),p=Math.max(0,Math.floor((i-_)/2)),d=Math.max(0,Math.floor((s-h)/2)),m=document.createElement("canvas");m.width=_,m.height=h;let l=m.getContext("2d");if(!l)return t;return l.drawImage(t.source,p,d,_,h,0,0,_,h),{source:m,width:o,height:c}},mt=(t,e)=>{if(t.width<e||t.height<e)return null;return t},C=async(t,e)=>{let r=Ci(t,e);if(!r)return null;return Si(r)},Oi=async(t,e)=>{let r=[],i=Math.max(1,Math.min(120,e));for(let s=0;s<i;s++){let n=await C(t,[`sliderb${s}@2x`,`sliderb${s}`]);if(!n){if(s===0)continue;break}r.push(n)}return r},Li=async(t,e)=>{let r=[];for(let i=0;i<10;i++){let s=await C(t,[`${e}-${i}@2x`,`${e}-${i}`]);if(!s)return[];r.push(s)}return r},lr=async(t,e)=>{for(let r=0;r<e.length;r++){let i=e[r],s=[];for(let n=0;n<64;n++){let a=await C(t,[`${i}${n}@2x`,`${i}${n}`,`${i}-${n}@2x`,`${i}-${n}`]);if(!a)break;s.push(a)}if(s.length>0)return s}return[]},Bi=async(t,e)=>{let r=[];for(let i=0;i<128;i++){let s=await C(t,[`${e}-${i}@2x`,`${e}-${i}`]);if(!s)break;r.push(s)}return r},Pi=(t)=>{let e=pr(t,"skin.ini");if(!e)return null;try{return new TextDecoder("utf-8").decode(e.data)}catch(r){return console.warn("[Skin] Failed to parse skin.ini",r),null}},ur=async(t,e)=>{let r=[],i=t,s=Pi(e);if(s)i=hr(i,_r(s));let n={},a=await C(e,["hitcircle@2x","hitcircle"]);if(a){let x=mt(ut(a.image,512),32);if(x)n.hitcircle=x,r.push(a.url)}let o=await C(e,["hitcircleoverlay@2x","hitcircleoverlay"]);if(o){let x=mt(ut(o.image,512),32);if(x)n.hitcircleoverlay=x,r.push(o.url)}let c=await C(e,["sliderstartcircle@2x","sliderstartcircle"]);if(c){let x=mt(ut(c.image,512),32);if(x)n.sliderstartcircle=x,r.push(c.url)}let _=await C(e,["sliderstartcircleoverlay@2x","sliderstartcircleoverlay"]);if(_){let x=mt(ut(_.image,512),32);if(x)n.sliderstartcircleoverlay=x,r.push(_.url)}let h=await C(e,["sliderendcircle@2x","sliderendcircle"]);if(h){let x=mt(ut(h.image,512),32);if(x)n.sliderendcircle=x,r.push(h.url)}let p=await C(e,["sliderendcircleoverlay@2x","sliderendcircleoverlay"]);if(p){let x=mt(ut(p.image,512),32);if(x)n.sliderendcircleoverlay=x,r.push(p.url)}let d=await C(e,["approachcircle@2x","approachcircle"]);if(d)n.approachcircle=d.image,r.push(d.url);let m=await Oi(e,i.slider_ball_frames);if(m.length>0){let x=[];for(let R=0;R<m.length;R++)x.push(m[R].image),r.push(m[R].url);n.sliderball_frames=x,n.sliderball=x[0]}else{let x=await C(e,["sliderb@2x","sliderb","sliderball@2x","sliderball"]);if(x)n.sliderball=x.image,r.push(x.url)}let l=await C(e,["sliderb-nd@2x","sliderb-nd"]);if(l)n.sliderball_nd=l.image,r.push(l.url);let u=await C(e,["sliderb-spec@2x","sliderb-spec"]);if(u)n.sliderball_spec=u.image,r.push(u.url);let f=await C(e,["sliderfollowcircle@2x","sliderfollowcircle"]);if(f)n.sliderfollowcircle=f.image,r.push(f.url);let b=await C(e,["reversearrow@2x","reversearrow"]);if(b)n.reversearrow=b.image,r.push(b.url);let v=await lr(e,["reversearrow"]);if(v.length>0){let x=[];for(let R=0;R<v.length;R++)x.push(v[R].image),r.push(v[R].url);if(n.reversearrow_frames=x,!n.reversearrow)n.reversearrow=x[0]}let w=await C(e,["sliderb0@2x","sliderb0","sliderb@2x","sliderb"]);if(w)n.sliderb=w.image,r.push(w.url);let T=await C(e,["sliderscorepoint@2x","sliderscorepoint","sliderpoint10@2x","sliderpoint10"]);if(T)n.sliderscorepoint=T.image,r.push(T.url);let N=await C(e,["followpoint@2x","followpoint"]);if(N)n.followpoint=N.image,r.push(N.url);let A=await Bi(e,"followpoint");if(A.length>0){let x=[];for(let R=0;R<A.length;R++)x.push(A[R].image),r.push(A[R].url);if(n.followpoint_frames=x,!n.followpoint)n.followpoint=x[0]}let M=await Li(e,i.hit_circle_prefix||"default");if(M.length>0){let x=[];for(let R=0;R<M.length;R++)x.push(M[R].image),r.push(M[R].url);n.combo_digits=x,n.combo_overlap=i.hit_circle_overlap}let k=["mania-stage-left","mania-stage-right","mania-stage-bottom","mania-stage-light","mania-stage-hint","mania-key1","mania-key1d","mania-key2","mania-key2d","mania-keys","mania-keysd","mania-note1","mania-note2","mania-notes","mania-note1h","mania-note2h","mania-notesh","mania-note1l","mania-note2l","mania-notesl","mania-note1t","mania-note2t","mania-notest"],I={},O={};for(let x=0;x<k.length;x++){let R=k[x],S=R.toLowerCase(),B=await C(e,[`${R}@2x`,R]);if(B)I[S]=B.image,r.push(B.url);let Q=await lr(e,[R]);if(Q.length>0){let rt=[];for(let nt=0;nt<Q.length;nt++)rt.push(Q[nt].image),r.push(Q[nt].url);if(O[S]=rt,!I[S])I[S]=rt[0]}}if(Object.keys(I).length>0)n.mania_textures=I;if(Object.keys(O).length>0)n.mania_animations=O;return{config:i,elements:n,dispose:()=>{for(let x=0;x<r.length;x++)URL.revokeObjectURL(r[x])}}};import Fi from"jszip";var Te=null,ft=null,Re=null,wt=null,Vi=(t)=>{let e=atob(t),r=new Uint8Array(e.length);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return r.buffer},ji=async()=>{if(Te)return Te;if(ft)return ft;return ft=import("./chunk-tj1dwy5a.js").then((t)=>{return Te=t.DEFAULT_SKIN_ARCHIVE_BASE64,ft=null,t.DEFAULT_SKIN_ARCHIVE_BASE64}).catch((t)=>{throw ft=null,t}),ft},mr=async()=>{if(Re)return Re;if(wt)return wt;return wt=(async()=>{let t=await ji(),e=Vi(t),r=await Fi.loadAsync(e),i=new Map,s=Object.entries(r.files);for(let n=0;n<s.length;n++){let[a,o]=s[n];if(o.dir)continue;i.set(a,await o.async("arraybuffer"))}return Re=i,wt=null,i})(),wt};import Ui from"jszip";var fr=(t)=>{let e=new Map;for(let[r,i]of t){if(i instanceof ArrayBuffer){e.set(r,i);continue}e.set(r,new TextEncoder().encode(i).buffer)}return e},br=async(t)=>{let e=await Ui.loadAsync(t),r=new Map,i=Object.entries(e.files);for(let s=0;s<i.length;s++){let[n,a]=i[s];if(a.dir)continue;r.set(n,await a.async("arraybuffer"))}return r},gr=(t,e)=>{let r=new Map;if(t)for(let[i,s]of t)r.set(i,s);if(e)for(let[i,s]of e)r.set(i,s);return r},vr=(t,e,r)=>{let i=new Map(t);if(e){for(let[s,n]of e)if(!i.has(s))i.set(s,n)}if(r){for(let[s,n]of r)if(!i.has(s))i.set(s,n)}return i};var Yi=0.42,Qi=30,Wi=100,Ae=g.DoubleTime|g.HalfTime|g.Nightcore;class xr{backend;backend_ready;backend_initialized=!1;renderer=null;audio_context;audio;video=null;resources=null;animation_frame=null;skin;base_skin;mods;custom_rate=null;renderer_config;start_offset;start_mode;custom_start_time;music_volume;hitsound_volume;audio_offset;background_url=null;loaded_skin_elements=null;loaded_skin_dispose=null;should_load_default_skin=!0;default_skin_files=null;default_skin_loading=null;custom_skin_files=null;listeners=new Map;is_loaded_flag=!1;is_disposed_flag=!1;hitsound_scheduler;timing_points=[];timing_resolver=null;resize_observer=null;key_handler=null;options;enable_fps_counter=!1;fps_frame_count=0;fps_last_update=0;current_fps=0;time_smoothing=0.1;smoothed_delta=0;max_frame_delta=100;resync_threshold_ms=Qi;last_timestamp=0;smooth_time=0;constructor(t){this.options=t,this.backend=se(t.backend_type??"auto"),this.skin=he(),this.base_skin=this.skin,this.mods=t.mods??0,this.renderer_config={...K,...t.renderer_config},this.calculate_layout(t.canvas.width,t.canvas.height,t.playfield_scale),this.start_mode=t.start_mode??(Number.isFinite(t.start_time)?"custom":"preview"),this.custom_start_time=Number.isFinite(t.start_time)?Math.max(0,t.start_time):null,this.start_offset=0,this.music_volume=t.volume??0.5,this.hitsound_volume=t.hitsound_volume??0.25,this.audio_offset=t.audio_offset??20,this.backend_ready=this.backend.initialize(t.canvas,this.renderer_config.use_high_dpi).then(()=>{this.backend_initialized=!0});let e=window.AudioContext??window.webkitAudioContext;if(!e)throw Error("Web Audio API is not supported in this environment");if(this.audio_context=new e,this.audio=new Ut(this.audio_context),this.hitsound_scheduler=new Me(this.audio,this.audio.hitsound_mixer),this.hitsound_scheduler.set_hitsound_lookahead(t.hitsound_lookahead_ms??Wi),this.hitsound_scheduler.set_nightcore_enabled((this.mods&g.Nightcore)!==0),this.audio.set_pitch_preserve((this.mods&g.DoubleTime)!==0&&(this.mods&g.Nightcore)===0),this.audio.set_music_volume(this.music_volume),this.audio.set_hitsound_volume(this.hitsound_volume),t.auto_resize)this.setup_auto_resize();this.enable_fps_counter=t.enable_fps_counter??!1,this.fps_last_update=performance.now();let r=t.time_smoothing;if(Number.isFinite(r))this.time_smoothing=Math.max(0,Math.min(1,r));let i=t.max_frame_delta;if(Number.isFinite(i))this.max_frame_delta=Math.max(10,i);let s=t.audio_resync_threshold_ms;if(Number.isFinite(s))this.resync_threshold_ms=Math.max(0,s)}async load_osz(t,e){try{let i=await new at().load_osz(t,{difficulty:e});return this.resources=i,this.setup()}catch(r){let i=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",i),F("INVALID_BEATMAP",i)}}async load_files(t,e){try{let r=new at;return this.resources=await r.load_from_files(t,{difficulty:e}),this.setup()}catch(r){let i=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",i),F("INVALID_BEATMAP",i)}}async load_custom_hitsounds(t){if(t.length==0){console.warn("[BeatmapPlayer] No custom hitsound URLs were provided"),this.audio.clear_hitsounds();return}try{await this.audio.load_hitsounds(t)}catch(e){console.error("[BeatmapPlayer] Failed to load custom hitsounds:",e)}}async load_map_custom_hitsounds(){if(!this.resources?.beatmap)return;let t=vr(this.resources.files,this.custom_skin_files,this.default_skin_files),e=cr(this.resources.beatmap,t,this.resources.audio_filename);if(e.size==0){this.audio.clear_hitsounds();return}try{if(await this.audio.load_hitsounds_from_files(e),this.is_disposed_flag)return}catch(r){console.error("[BeatmapPlayer] Failed to load map custom hitsounds:",r),this.audio.clear_hitsounds()}}async load_beatmap(t,e,r,i,s){return this.resources={beatmap:t,available_difficulties:[],files:new Map,audio:e,background:r,video:i,video_offset:s},this.setup()}async load_osu_content(t,e){try{await yr();let r=await this.parse_content(t);return this.load_beatmap(r,e)}catch(r){let i=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",i),F("INVALID_BEATMAP",i)}}async load_beatmap_files(t,e,r,i,s){try{await yr();let n=typeof t==="string",a=t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):null,o=await this.parse_content(n?t:a);return this.load_beatmap(o,e,r,i,s)}catch(n){let a=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",a),F("INVALID_BEATMAP",a)}}async setup(){if(!this.resources)return F("NOT_LOADED","No resources loaded");if(this.is_disposed_flag)return F("UNKNOWN","Player was disposed");try{await this.backend_ready}catch(s){let n=s instanceof Error?s.message:String(s);return this.emit("error","UNKNOWN",n),F("UNKNOWN",n)}let{beatmap:t}=this.resources;this.timing_points=Pt([...t.TimingPoints]),this.timing_resolver=new xt(this.timing_points),this.resolve_assets(),await this.load_map_skin();let{audio:e,video:r,video_offset:i}=this.resources;if(e)try{await this.audio.load(e,this.resolve_speed_multiplier()),this.release_loaded_audio_bytes()}catch(s){let n=s instanceof Error?s.message:String(s);return this.emit("error","AUDIO_DECODE_ERROR",n),F("AUDIO_DECODE_ERROR",n)}if(this.hitsound_scheduler.set_context(this.resources,this.timing_points,this.timing_resolver,this.get_effective_audio_offset()),this.load_map_custom_hitsounds(),r)this.video=new jt,await this.video.load(r,i??0);try{this.renderer=this.create_renderer(t),this.renderer.initialize(t),this.renderer.precompute()}catch(s){let n=s instanceof Error?s.message:String(s);return this.emit("error","UNSUPPORTED_MODE",n),F("UNSUPPORTED_MODE",n)}return this.start_offset=this.resolve_initial_start_offset(),this.hitsound_scheduler.update_hit_index(this.start_offset),this.load_background(),this.is_loaded_flag=!0,this.emit("loaded",t,this.resources),requestAnimationFrame(()=>this.render_frame(this.start_offset)),He(this.resources)}async load_background(){if(this.resources)this.resolve_assets();if(!this.resources?.background||!this.renderer)return;try{let t=new Image;if(this.background_url)URL.revokeObjectURL(this.background_url);if(this.background_url=URL.createObjectURL(this.resources.background),t.src=this.background_url,await t.decode(),this.is_disposed_flag||!this.renderer)return;this.renderer.set_background({source:t,width:t.width,height:t.height});let e=this.audio.is_playing?this.current_time:this.start_offset;requestAnimationFrame(()=>this.render_frame(e))}catch(t){console.warn("[BeatmapPlayer] Failed to load background",t)}}resolve_assets(){if(!this.resources)return;let t=new ke(this.resources).resolve();if(!this.resources.audio&&t.audio)this.resources.audio=t.audio;if(!this.resources.background&&t.background)this.resources.background=t.background;if(!this.resources.video&&t.video)this.resources.video=t.video;if(!this.resources.video_offset&&t.video_offset)this.resources.video_offset=t.video_offset}release_loaded_audio_bytes(){if(!this.resources)return;this.resources.audio=void 0;let t=this.resources.audio_filename?.toLowerCase();if(!t)return;for(let e of Array.from(this.resources.files.keys()))if(e.toLowerCase()===t)this.resources.files.delete(e)}create_renderer(t){switch(t.General.Mode){case 0:return new Vt(this.backend,this.skin,this.mods,this.renderer_config,this.loaded_skin_elements);case 3:return new J(this.backend,this.skin,this.mods,this.renderer_config,this.loaded_skin_elements);case 1:case 2:default:throw Error(`Unsupported game mode: ${$t[t.General.Mode]??t.General.Mode}`)}}get_last_object_time(){if(!this.resources?.beatmap.HitObjects.length)return 0;let t=this.resources.beatmap.HitObjects,e=0;for(let r of t){let i=r.endTime||r.time;if(i>e)e=i}return e}resolve_preview_start_offset(){if(!this.resources?.beatmap)return 0;let t=this.resources.beatmap.General.PreviewTime;if(t>0)return t;return Math.max(0,this.get_last_object_time()*Yi)}resolve_initial_start_offset(){let t=Math.max(0,this.duration),e=this.resources?.beatmap?.General.Mode;if(this.start_mode=="beginning")return 0;if(this.start_mode=="custom"){if(this.custom_start_time!==null)return Math.max(0,Math.min(this.custom_start_time,t));return Math.max(0,Math.min(this.resolve_preview_start_offset(),t))}if(e===3)return 0;return Math.max(0,Math.min(this.resolve_preview_start_offset(),t))}async play(){if(!this.renderer||!this.is_loaded_flag){console.warn("[BeatmapPlayer] Cannot play: not loaded");return}if(this.audio.is_playing)return;if(this.audio_context.state==="suspended")await this.audio_context.resume();try{await this.audio.play(this.to_track_time(this.start_offset))}catch(e){console.warn("[BeatmapPlayer] Failed to start audio",e),this.emit("statechange",!1);return}let t=this.current_time;this.start_offset=t,this.hitsound_scheduler.update_hit_index(t),this.video?.seek(t),this.video?.sync(t),this.video?.play(),this.start_render_loop(),this.emit("play"),this.emit("statechange",!0)}pause(){if(!this.audio.is_playing)return;this.start_offset=this.to_beatmap_time(this.audio.current_time),this.audio.pause(),this.video?.pause(),this.stop_render_loop(),this.emit("pause"),this.emit("statechange",!1)}set_mods(t){this.mods=t;let e=this.resolve_speed_multiplier();this.renderer?.set_mods(t),this.audio.set_rate(e),this.hitsound_scheduler.set_nightcore_enabled((t&g.Nightcore)!==0);let r=this.is_playing,i=this.current_time;if(this.audio.set_pitch_preserve((t&g.DoubleTime)!==0&&(t&g.Nightcore)===0).then(()=>{if(r&&this.audio.is_playing)this.restart_playback_time(i)}),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}set_rate(t){if(t===null)this.custom_rate=null;else if(Number.isFinite(t))this.custom_rate=Math.max(0.1,t);if(t!==null&&(this.mods&Ae)!==0){let e=this.is_playing,r=this.current_time;this.mods&=~Ae,this.renderer?.set_mods(this.mods),this.hitsound_scheduler.set_nightcore_enabled(!1),this.audio.set_pitch_preserve(!0).then(()=>{if(e&&this.audio.is_playing)this.restart_playback_time(r)})}if(this.audio.set_rate(this.resolve_speed_multiplier()),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}set_speed_mod(t){let e=this.mods&~Ae;if(t==="dt")e|=g.DoubleTime;else if(t==="nc")e|=g.Nightcore;else if(t==="ht")e|=g.HalfTime;this.custom_rate=null,this.set_mods(e)}seek(t){this.start_offset=Math.max(0,Math.min(t,this.duration)),this.hitsound_scheduler.update_hit_index(this.start_offset),this.audio.seek(this.to_track_time(this.start_offset)),this.video?.seek(this.start_offset),this.video?.sync(this.start_offset),this.last_timestamp=performance.now(),this.smooth_time=this.start_offset,this.smoothed_delta=0,this.emit("seek",this.start_offset),this.render_frame(this.start_offset),this.renderer?.on_seek(this.start_offset)}async set_difficulty(t){if(!this.resources)return F("NOT_LOADED","No beatmap resources loaded");let e=this.is_playing;this.stop();try{let i=await new at().load_from_files(this.resources.files,{difficulty:t});this.resources=i;let s=await this.setup();if(s.success&&e)this.play();return s}catch(r){let i=r instanceof Error?r.message:String(r);return this.emit("error","INVALID_BEATMAP",i),F("INVALID_BEATMAP",i)}}async parse_content(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;return await $i(e)}stop(){this.pause(),this.start_offset=0,this.audio.seek(this.to_track_time(0)),this.hitsound_scheduler.update_hit_index(0),this.render_frame(0)}unload(t){if(this.stop(),this.audio.clear_hitsounds(),this.video?.dispose(),this.video=null,this.renderer?.dispose(),this.renderer=null,this.resources=null,this.is_loaded_flag=!1,this.timing_points=[],this.timing_resolver=null,this.hitsound_scheduler.set_context(null,[],null,this.get_effective_audio_offset()),this.release_loaded_skin(),this.background_url)URL.revokeObjectURL(this.background_url),this.background_url=null;if(t?.clear_backend_cache)this.backend.clear_caches?.()}dispose(){if(this.is_disposed_flag)return;if(this.is_disposed_flag=!0,this.unload(),this.backend.dispose(),this.audio.dispose(),this.resize_observer)this.resize_observer.disconnect(),this.resize_observer=null;if(this.key_handler)window.removeEventListener("keydown",this.key_handler),this.key_handler=null;if(this.audio_context&&this.audio_context.state!=="closed")this.audio_context.close().catch(()=>{});this.renderer=null,this.resources=null,this.is_loaded_flag=!1,this.listeners.clear(),this.release_loaded_skin()}get current_time(){return this.to_beatmap_time(this.audio.current_time)}get duration(){if(this.audio.duration>0)return Math.max(0,this.audio.duration);return this.get_last_object_time()}get is_playing(){return this.audio.is_playing}get is_loaded(){return this.is_loaded_flag}get mode(){if(!this.resources)return"standard";switch(this.resources.beatmap.General.Mode){case 1:return"taiko";case 2:return"catch";case 3:return"mania";default:return"standard"}}get beatmap(){return this.resources?.beatmap??null}get available_difficulties(){return this.resources?.available_difficulties??[]}get background(){return this.resources?.background}get config(){return this.renderer_config}resize(t,e,r){if(this.backend.resize(t,e),this.calculate_layout(t,e,r),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}update_config(t){if(this.renderer_config={...this.renderer_config,...t},this.renderer?.update_config(this.renderer_config),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}async load_skin_files(t){if(!t){this.custom_skin_files=null,await this.reload_skin_runtime();return}this.custom_skin_files=fr(t),await this.reload_skin_runtime()}async load_skin_osk(t){await this.load_skin_files(await br(t))}clear_loaded_skin(){this.custom_skin_files=null,this.reload_skin_runtime()}async load_map_skin(){if(this.release_loaded_skin(),!this.resources)return;try{if(await this.ensure_default_skin_loaded(),this.is_disposed_flag)return;let t=this.merge_skin_sources(),e=await ur(this.base_skin,t);if(this.is_disposed_flag){e.dispose();return}this.skin=e.config,this.loaded_skin_elements=e.elements,this.loaded_skin_dispose=e.dispose}catch(t){console.warn("[BeatmapPlayer] Failed to load map skin assets",t),this.skin=this.base_skin,this.loaded_skin_elements=null,this.loaded_skin_dispose=null}}release_loaded_skin(){if(this.loaded_skin_dispose)this.loaded_skin_dispose(),this.loaded_skin_dispose=null;this.loaded_skin_elements=null}async ensure_default_skin_loaded(){if(!this.should_load_default_skin){this.default_skin_files=null;return}await this.load_default_skin_files()}async load_default_skin_files(){if(this.default_skin_files)return;if(this.default_skin_loading){await this.default_skin_loading;return}this.default_skin_loading=(async()=>{try{this.default_skin_files=await mr()}catch(t){console.warn("[BeatmapPlayer] Failed to load embedded default skin",t),this.default_skin_files=null}})(),await this.default_skin_loading,this.default_skin_loading=null}merge_skin_sources(){return gr(this.default_skin_files,this.custom_skin_files)}setup_auto_resize(){this.resize_observer=new ResizeObserver(()=>{let e=this.options.canvas.parentElement;if(e){let r=e.getBoundingClientRect();this.resize(r.width,r.height,this.options.playfield_scale)}}),this.resize_observer.observe(this.options.canvas.parentElement||this.options.canvas)}toggle_pause(){if(!this.is_loaded_flag)return;if(this.is_playing)this.pause();else this.play()}toggle_grid(){if(this.renderer_config.grid_level===0)this.renderer_config.grid_level=32;else this.renderer_config.grid_level=0;this.render_frame(this.current_time)}calculate_layout(t,e,r){let n=0.9;if(Number.isFinite(r))n=r;let a=t*n/512,o=e*n/384,c=Math.min(a,o);if(this.renderer_config.scale=c,this.renderer_config.offset_x=Math.floor((t-512*c)/2),this.renderer_config.offset_y=Math.floor((e-384*c)/2),this.renderer)this.renderer.update_config(this.renderer_config)}set_volume(t){this.music_volume=t,this.audio.set_music_volume(t)}set_hitsound_volume(t){this.hitsound_volume=t,this.audio.set_hitsound_volume(t)}set_offset(t){if(this.audio_offset=t,this.hitsound_scheduler.set_audio_offset(this.get_effective_audio_offset()),this.is_loaded_flag)this.seek(this.current_time)}on(t,e){if(!this.listeners.has(t))this.listeners.set(t,new Set);this.listeners.get(t).add(e)}off(t,e){this.listeners.get(t)?.delete(e)}emit(t,...e){let r=this.listeners.get(t);if(r)for(let i of r)i(...e)}start_render_loop(){if(this.animation_frame!==null)return;this.last_timestamp=performance.now(),this.smooth_time=this.current_time,this.smoothed_delta=0;let t=(e)=>{if(this.is_disposed_flag){this.animation_frame=null;return}if(!this.audio.is_playing){this.animation_frame=null;return}let r=Math.max(0,e-this.last_timestamp);this.last_timestamp=e;let i=Math.min(r,this.max_frame_delta);if(this.time_smoothing>0){if(this.smoothed_delta===0)this.smoothed_delta=i;else this.smoothed_delta+=(i-this.smoothed_delta)*this.time_smoothing;i=this.smoothed_delta}this.smooth_time+=i*this.audio.speed_multiplier;let s=this.current_time;if(Math.abs(this.smooth_time-s)>this.resync_threshold_ms)this.smooth_time=s;else this.smooth_time+=(s-this.smooth_time)*0.1;let a=this.smooth_time,o=this.hitsound_scheduler.schedule_hitsounds(s);if(this.render_frame(a),this.video?.sync(a),this.emit("timeupdate",a,this.duration),a>=this.duration){this.emit("ended"),this.stop_render_loop(),this.emit("statechange",!1);return}this.animation_frame=requestAnimationFrame(t)};this.animation_frame=requestAnimationFrame(t)}stop_render_loop(){if(this.animation_frame!==null)cancelAnimationFrame(this.animation_frame),this.animation_frame=null}render_frame(t){if(!this.backend_initialized)return;if(this.backend.begin_frame?.(),this.backend.clear(),this.renderer?.render(t),this.enable_fps_counter){this.fps_frame_count++;let e=performance.now(),r=e-this.fps_last_update;if(r>=1000)this.current_fps=Math.round(this.fps_frame_count*1000/r),this.fps_frame_count=0,this.fps_last_update=e;let i=`14px ${this.skin.default_font??"monospace"}`;this.backend.draw_text(`${this.current_fps} FPS`,10,20,i,"rgba(255,255,255,0.8)","left","top")}this.backend.end_frame?.()}restart_playback_time(t){this.audio.seek(this.to_track_time(t)),this.last_timestamp=performance.now(),this.smooth_time=t,this.smoothed_delta=0,this.hitsound_scheduler.update_hit_index(t),this.video?.seek(t),this.video?.sync(t),this.start_render_loop(),this.render_frame(t)}set_fps_counter(t){this.enable_fps_counter=t}get_effective_audio_offset(){return this.audio_offset}to_track_time(t){return Math.max(0,t+this.get_effective_audio_offset())}to_beatmap_time(t){return Math.max(0,t-this.get_effective_audio_offset())}resolve_speed_multiplier(){return this.custom_rate??Ne(this.mods)}async reload_skin_runtime(){if(!this.is_loaded_flag||!this.resources?.beatmap)return;let t=this.resources.beatmap,e=this.current_time;await this.load_map_skin(),this.renderer=this.create_renderer(t),this.renderer.initialize(t),requestAnimationFrame(()=>this.render_frame(e))}}var Gi=(t)=>{return new URL(t,import.meta.url).toString()};var qi=(t)=>{return Gi(t)};export{Ki as unwrap,is as toggle_mod,qi as resolve_runtime_asset_url,He as ok,rs as mods_to_string,es as mods_from_string,he as merge_skin,U as is_spinner,it as is_slider,Xi as is_ok,De as is_new_combo,Wt as is_hold,Zi as is_err,Qt as is_circle,H as has_mod,Ne as get_speed_multiplier,Wr as get_rate_multiplier,dt as get_mania_lane_color,q as get_combo_color,ss as get_available_mods,Xe as get_adjusted_difficulty,F as err,se as create_backend,qr as apply_rate_to_ar,Gr as apply_mods_to_difficulty,jt as VideoController,Vt as StandardRenderer,wr as SpeedChangingMods,Yt as SampleSet,Et as PixiBackend,Gt as PLAYFIELD_WIDTH,qt as PLAYFIELD_HEIGHT,at as OszLoader,g as Mods,jr as ModNightcore,Qr as ModHidden,ae as ModHardRock,Ur as ModHalfTime,oe as ModEasy,Vr as ModDoubleTime,J as ManiaRenderer,kt as HitSoundType,j as HitObjectType,Yr as HD_FADE_OUT_MULTIPLIER,$r as HD_FADE_IN_MULTIPLIER,Le as GridLevel,$t as GameMode,Ee as ErrorCode,ts as DifficultyChangingMods,_e as DEFAULT_SKIN,K as DEFAULT_RENDERER_CONFIG,xr as BeatmapPlayer,ot as BaseRenderer,Ut as AudioEngine};
|