@rel-packages/osu-beatmap-preview 0.8.6 → 0.9.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/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var Ir;((e)=>{e[e.Standard=0]="Standard";e[e.Taiko=1]="Taiko";e[e.Catch=2]="Catch";e[e.Mania=3]="Mania"})(Ir||={});var Hr;((e)=>{e[e.Auto=0]="Auto";e[e.Normal=1]="Normal";e[e.Soft=2]="Soft";e[e.Drum=3]="Drum"})(Hr||={});var N={Circle:1,Slider:2,NewCombo:4,Spinner:8,ComboSkip:112,Hold:128},j={Normal:1,Whistle:2,Finish:4,Clap:8},Ur=(r)=>(r.type&N.Circle)!==0,pr=(r)=>(r.type&N.Slider)!==0,Z=(r)=>(r.type&N.Spinner)!==0,qr=(r)=>(r.type&N.Hold)!==0,Zr=(r)=>(r.type&N.NewCombo)!==0;var Xr;((h)=>{h.NoOsuFiles="NO_OSU_FILES";h.DifficultyNotFound="DIFFICULTY_NOT_FOUND";h.InvalidBeatmap="INVALID_BEATMAP";h.UnsupportedMode="UNSUPPORTED_MODE";h.AudioNotLoaded="AUDIO_NOT_LOADED";h.AudioDecodeError="AUDIO_DECODE_ERROR";h.NotLoaded="NOT_LOADED";h.Unknown="UNKNOWN"})(Xr||={});var Er=(r)=>({success:!0,data:r}),L=(r,u)=>({success:!1,code:r,reason:u}),cu=(r)=>{if(r.success)return r.data;throw Error(`[${r.code}] ${r.reason}`)},Gu=(r)=>{return r.success},wu=(r)=>{return!r.success};var p={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},fu=p.DoubleTime|p.HalfTime|p.Nightcore,iu=p.HardRock|p.Easy|fu,gu=(r)=>{let u=0,n=r.toLowerCase(),s={nf:p.NoFail,ez:p.Easy,td:p.TouchDevice,hd:p.Hidden,hr:p.HardRock,sd:p.SuddenDeath,dt:p.DoubleTime,rx:p.Relax,ht:p.HalfTime,nc:p.Nightcore,fl:p.Flashlight,at:p.Autoplay,so:p.SpunOut,ap:p.Autopilot,pf:p.Perfect,fi:p.FadeIn,mr:p.Mirror};for(let e=0;e<n.length-1;e+=2){let t=n.slice(e,e+2);if(s[t])u|=s[t]}return u},du=(r)=>{let u=[];if(r&p.NoFail)u.push("NF");if(r&p.Easy)u.push("EZ");if(r&p.Hidden)u.push("HD");if(r&p.HardRock)u.push("HR");if(r&p.SuddenDeath)u.push("SD");if(r&p.DoubleTime)u.push("DT");if(r&p.HalfTime)u.push("HT");if(r&p.Nightcore)u.push("NC");if(r&p.Flashlight)u.push("FL");if(r&p.SpunOut)u.push("SO");if(r&p.FadeIn)u.push("FI");if(r&p.Mirror)u.push("MR");let n=u.indexOf("DT"),s=u.indexOf("NC");if(n>=0&&s>=0)u.splice(n,1);return u.join("")},z=(r)=>{if(r&(p.DoubleTime|p.Nightcore))return 1.5;if(r&p.HalfTime)return 0.75;return 1},hu=[p.HardRock|p.Easy,p.DoubleTime|p.HalfTime|p.Nightcore,p.Hidden|p.FadeIn],ju=(r,u)=>{if(r&u)return r&~u;let n=r;for(let s of hu)if(u&s)n&=~s;return n|u},m=(r,u)=>(r&u)!==0,bu=(r)=>{let u=[{name:"Easy",acronym:"EZ",value:p.Easy},{name:"Hidden",acronym:"HD",value:p.Hidden},{name:"Double Time",acronym:"DT",value:p.DoubleTime},{name:"Half Time",acronym:"HT",value:p.HalfTime},{name:"Nightcore",acronym:"NC",value:p.Nightcore}];switch(r){case"standard":return[...u,{name:"Hard Rock",acronym:"HR",value:p.HardRock}];case"mania":return[...u,{name:"Hard Rock",acronym:"HR",value:p.HardRock},{name:"Fade In",acronym:"FI",value:p.FadeIn}];case"taiko":case"catch":return[...u,{name:"Hard Rock",acronym:"HR",value:p.HardRock}];default:return u}};import Wr from"jszip";import{init_wasm as Yr,parse as Kr}from"@rel-packages/osu-beatmap-parser/browser";class X{async load_osz(r,u){await Yr();let n=await Wr.loadAsync(r),s=new Map;for(let[e,t]of Object.entries(n.files))if(!t.dir)s.set(e,await t.async("arraybuffer"));return this.load_from_files(s,u)}async load_from_files(r,u){await Yr();let n=[...r.keys()].filter((B)=>B.toLowerCase().endsWith(".osu"));if(n.length===0)throw Error("No .osu files found in beatmap");let s=await Promise.all(n.map(async(B)=>{let P=r.get(B),y=this.to_bytes(P),O=await Kr(y);return{filename:B,beatmap:O}})),e=this.select_difficulty(n,s,u?.difficulty),t=r.get(e),o=this.to_bytes(t),f=await Kr(o),h=f.General.AudioFilename||null,T=f.Events.background?.filename||null,M=f.Events.video?.filename||null,I=f.Events.video?.startTime??0,H=new Map;for(let[B,P]of r)if(P instanceof ArrayBuffer)H.set(B,P);else H.set(B,new TextEncoder().encode(P).buffer);let V;if(h)V=this.find_file(H,h);let R;if(T){let B=this.find_file(H,T);if(B)R=new Blob([B])}let D;if(M){let B=this.find_file(H,M);if(B)D=new Blob([B])}return{beatmap:f,available_difficulties:s,files:H,audio:V,background:R,video:D,audio_filename:h??void 0,background_filename:T??void 0,video_filename:M??void 0,video_offset:M?I:void 0}}async list_difficulties(r){let u=await Wr.loadAsync(r),n=[];for(let e of Object.keys(u.files))if(e.toLowerCase().endsWith(".osu"))n.push(e);let s=[];for(let e of n){let o=(await u.files[e].async("string")).match(/Version:\s*(.+)/);s.push(o?o[1].trim():e)}return s}select_difficulty(r,u,n){if(n===void 0)return r[0];if(typeof n==="number"){if(n<0||n>=r.length)throw Error(`Difficulty index ${n} out of range (0-${r.length-1})`);return r[n]}let s=u.find((o)=>o.beatmap.Metadata.Version===n);if(s)return s.filename;let e=n.toLowerCase(),t=u.find((o)=>o.filename.toLowerCase().includes(e)||o.beatmap.Metadata.Version.toLowerCase().includes(e));if(t)return t.filename;throw Error(`Difficulty "${n}" not found`)}find_file(r,u){if(r.has(u))return r.get(u);let n=u.toLowerCase();for(let[s,e]of r)if(s.toLowerCase()===n)return e;return}to_bytes(r){if(r instanceof ArrayBuffer)return new Uint8Array(r);return new TextEncoder().encode(r)}}import{init_wasm as uu,parse as Xu}from"@rel-packages/osu-beatmap-parser/browser";var Mr=512,Dr=384,zr;((t)=>{t[t.None=0]="None";t[t.Large=32]="Large";t[t.Medium=16]="Medium";t[t.Small=8]="Small";t[t.Tiny=4]="Tiny"})(zr||={});var v={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};class E{backend;skin;config;mods;beatmap;objects=[];background_image=null;constructor(r,u,n=0,s=v){this.backend=r,this.skin=u,this.mods=n,this.config={...v,...s}}set_background(r){this.background_image=r}update_config(r){this.config={...this.config,...r}}precompute(){}dispose(){this.objects=[]}render_playfield(r,u,n,s){if(!this.config.show_playfield)return;let{backend:e,config:t}=this,o=r??512,f=u??384,h=n??0,T=s??0;e.save(),e.set_alpha(t.playfield_opacity),e.begin_path(),e.move_to(h,T),e.line_to(h+o,T),e.line_to(h+o,T+f),e.line_to(h,T+f),e.line_to(h,T),e.stroke_path(t.playfield_color,2),e.restore()}render_grid(){if(this.config.grid_level===0)return;let{backend:r,config:u}=this,n=u.grid_level;r.save(),r.set_alpha(u.grid_opacity);for(let s=0;s<=512;s+=n)r.begin_path(),r.move_to(s,0),r.line_to(s,384),r.stroke_path(u.grid_color,s%(n*4)===0?1:0.5);for(let s=0;s<=384;s+=n)r.begin_path(),r.move_to(0,s),r.line_to(512,s),r.stroke_path(u.grid_color,s%(n*4)===0?1:0.5);r.restore()}render_background(){if(!this.background_image)return;let{backend:r}=this;r.save(),r.set_alpha(0.3);let{width:u,height:n}=r,{width:s,height:e}=this.background_image;if(s>0&&e>0){let t=Math.max(u/s,n/e),o=s*t,f=e*t,h=(u-o)/2,T=(n-f)/2;r.draw_image(this.background_image,h,T,o,f)}else r.draw_image(this.background_image,0,0,u,n);r.restore()}get_visible_objects(r,u,n){let s=[];for(let e of this.objects){let t=e.time-u,o=e.end_time+n;if(r>=t&&r<=o)s.push(e)}return s}}class b{ctx;_width=0;_height=0;_dpr=1;is_initialized=!1;get width(){return this._width}get height(){return this._height}initialize(r,u=!0){this._dpr=u?window.devicePixelRatio||1:1;let n=r.clientWidth||r.width,s=r.clientHeight||r.height;this.apply_canvas_size(r,n,s);let e=r.getContext("2d",{alpha:!0,desynchronized:!0});if(!e)throw Error("Failed to get 2D context");this.ctx=e,this._width=n,this._height=s,this.configure_context(),this.is_initialized=!0}clear(){if(!this.is_initialized)return;this.ctx.save(),this.ctx.setTransform(this._dpr,0,0,this._dpr,0,0),this.ctx.clearRect(0,0,this._width,this._height),this.ctx.restore()}dispose(){}begin_frame(){}end_frame(){}resize(r,u){if(!this.is_initialized)return;this._width=r,this._height=u,this._dpr=window.devicePixelRatio||1;let n=this.ctx.canvas;this.apply_canvas_size(n,r,u),this.reset_transform(),this.configure_context()}draw_circle(r,u,n,s,e,t){let o=this.ctx;if(o.beginPath(),o.arc(r,u,n,0,Math.PI*2),s&&s!=="transparent")o.fillStyle=s,o.fill();if(e&&t&&t>0)o.strokeStyle=e,o.lineWidth=t,o.stroke()}draw_arc(r,u,n,s,e,t,o,f=!1){let h=this.ctx;h.beginPath(),h.arc(r,u,n,s,e,f),h.strokeStyle=t,h.lineWidth=o,h.stroke()}draw_rect(r,u,n,s,e){this.ctx.fillStyle=e,this.ctx.fillRect(r,u,n,s)}draw_rect_gradient(r,u,n,s,e){this.ctx.fillStyle=e,this.ctx.fillRect(r,u,n,s)}create_linear_gradient(r,u,n,s,e){let t=this.ctx.createLinearGradient(r,u,n,s);for(let o of e)t.addColorStop(o.offset,o.color);return t}draw_text(r,u,n,s,e,t="left",o="alphabetic"){let f=this.ctx;f.font=s,f.fillStyle=e,f.textAlign=t,f.textBaseline=o,f.fillText(r,u,n)}measure_text(r,u){let n=this.ctx,s=n.font;n.font=u;let e=n.measureText(r);return n.font=s,e}begin_path(){this.ctx.beginPath()}move_to(r,u){this.ctx.moveTo(r,u)}line_to(r,u){this.ctx.lineTo(r,u)}draw_line(r,u,n,s,e,t,o="butt",f="miter"){this.ctx.beginPath(),this.ctx.moveTo(r,u),this.ctx.lineTo(n,s),this.ctx.strokeStyle=e,this.ctx.lineWidth=t,this.ctx.lineCap=o,this.ctx.lineJoin=f,this.ctx.stroke()}bezier_curve_to(r,u,n,s,e,t){this.ctx.bezierCurveTo(r,u,n,s,e,t)}quadratic_curve_to(r,u,n,s){this.ctx.quadraticCurveTo(r,u,n,s)}arc_to(r,u,n,s,e,t){this.ctx.arc(r,u,n,s,e,t)}rect(r,u,n,s){this.ctx.rect(r,u,n,s)}clip(){this.ctx.clip()}stroke_path(r,u,n="butt",s="miter"){let e=this.ctx;e.strokeStyle=r,e.lineWidth=u,e.lineCap=n,e.lineJoin=s,e.stroke()}fill_path(r){this.ctx.fillStyle=r,this.ctx.fill()}close_path(){this.ctx.closePath()}save(){this.ctx.save()}restore(){this.ctx.restore()}translate(r,u){this.ctx.translate(r,u)}scale(r,u){this.ctx.scale(r,u)}rotate(r){this.ctx.rotate(r)}set_alpha(r){this.ctx.globalAlpha=r}set_shadow(r,u){this.ctx.shadowColor=r,this.ctx.shadowBlur=u}set_composite_operation(r){this.ctx.globalCompositeOperation=r}set_blend_mode(r){let u={normal:"source-over",lighter:"lighter",multiply:"multiply",screen:"screen"};this.ctx.globalCompositeOperation=u[r]??"source-over"}draw_image(r,u,n,s,e){if(s!==void 0&&e!==void 0)this.ctx.drawImage(r.source,u,n,s,e);else this.ctx.drawImage(r.source,u,n)}draw_image_part(r,u,n,s,e,t,o,f,h){this.ctx.drawImage(r.source,u,n,s,e,t,o,f,h)}render_slider_to_image(r,u,n,s,e,t=1,o=1){let f=1/0,h=1/0,T=-1/0,M=-1/0;for(let y of r){if(y[0]<f)f=y[0];if(y[0]>T)T=y[0];if(y[1]<h)h=y[1];if(y[1]>M)M=y[1]}let I=u+2;f-=I,h-=I,T+=I,M+=I;let H=Math.ceil((T-f)*e),V=Math.ceil((M-h)*e);if(H<=0||V<=0)return null;let R=document.createElement("canvas");R.width=H,R.height=V;let D=R.getContext("2d");if(!D)return null;D.save(),D.scale(e,e),D.translate(-f,-h);let B=()=>{if(D.beginPath(),r.length>0){D.moveTo(r[0][0],r[0][1]);for(let y=1;y<r.length;y++)D.lineTo(r[y][0],r[y][1])}};D.lineCap="round",D.lineJoin="round",D.globalAlpha=o,D.strokeStyle=n,D.lineWidth=u*2,B(),D.stroke();let P=u*0.872;if(t<1)D.globalCompositeOperation="destination-out",D.globalAlpha=1,D.lineWidth=P*2,B(),D.stroke(),D.globalCompositeOperation="source-over";return D.globalAlpha=t,D.strokeStyle=s,D.lineWidth=P*2,B(),D.stroke(),D.restore(),{source:R,width:H,height:V,min_x:f,min_y:h}}apply_canvas_size(r,u,n){r.width=u*this._dpr,r.height=n*this._dpr,r.style.width=`${u}px`,r.style.height=`${n}px`}configure_context(){this.ctx.scale(this._dpr,this._dpr),this.ctx.imageSmoothingEnabled=!0,this.ctx.imageSmoothingQuality="high"}reset_transform(){if(this.ctx.resetTransform)this.ctx.resetTransform();else this.ctx.setTransform(1,0,0,1,0,0)}}var Vr={min:1800,mid:1200,max:450};var Tu=(r,u)=>{if(r>5)return u.mid+(u.max-u.mid)*(r-5)/5;if(r<5)return u.mid+(u.mid-u.min)*(r-5)/5;return u.mid},cr=(r,u)=>{if(Math.sign(r-u.mid)===Math.sign(u.max-u.mid))return(r-u.mid)/(u.max-u.mid)*5+5;return(r-u.mid)/(u.mid-u.min)*5+5},k=(r)=>Tu(r,Vr),Gr=(r)=>400*Math.min(1,r/450),Iu=(r)=>{return(1-0.7*((r-5)/5))/2},wr=(r)=>Iu(r)*64;var Rr={name:"Hard Rock",acronym:"HR",apply_to_difficulty(r){r.cs=Math.min(r.cs*1.3,10),r.ar=Math.min(r.ar*1.4,10),r.od=Math.min(r.od*1.4,10),r.hp=Math.min(r.hp*1.4,10)}};var Br={name:"Easy",acronym:"EZ",apply_to_difficulty(r){r.cs*=0.5,r.ar*=0.5,r.od*=0.5,r.hp*=0.5}};var Hu={name:"Double Time",acronym:"DT",get_rate_multiplier:()=>1.5},pu={name:"Nightcore",acronym:"NC",get_rate_multiplier:()=>1.5};var Mu={name:"Half Time",acronym:"HT",get_rate_multiplier:()=>0.75};var Du=0.4,Vu=0.3,Ru={name:"Hidden",acronym:"HD"};var Pr=(r)=>{if(r&(p.DoubleTime|p.Nightcore))return 1.5;if(r&p.HalfTime)return 0.75;return 1},Bu=(r,u)=>{if(u&p.Easy)Br.apply_to_difficulty(r);if(u&p.HardRock)Rr.apply_to_difficulty(r)},Pu=(r,u)=>{if(u===1)return r;let n=k(r)/u;return cr(n,Vr)},xr=(r,u,n,s,e)=>{let t={cs:r,ar:u,od:n,hp:s};Bu(t,e);let o=Pr(e);return t.ar=Pu(t.ar,o),t};var ir=(r,u)=>[r[0]+u[0],r[1]+u[1]],$=(r,u)=>[r[0]-u[0],r[1]-u[1]],gr=(r,u)=>[r[0]*u,r[1]*u];var l=(r)=>Math.sqrt(r[0]*r[0]+r[1]*r[1]);var W=(r,u,n)=>r+(u-r)*n,Q=(r,u,n)=>[W(r[0],u[0],n),W(r[1],u[1],n)],F=(r,u,n)=>Math.min(n,Math.max(u,r));var Fr={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"]},yr={combo_colors:["0,185,0","7, 105, 227","224, 4, 38","227, 171, 2"],circle_border_width:0.12,hit_circle_opacity:0.95,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,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,mania_lane_width:30,mania_note_height:15,mania_hit_position:364,mania_lane_spacing:1,mania_lane_colors:Fr,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},a=(r)=>{if(!r)return{...yr};return{...yr,...r,mania_lane_colors:r.mania_lane_colors?{...Fr,...r.mania_lane_colors}:Fr}},J=(r,u,n=1)=>{return`rgba(${r.combo_colors[u%r.combo_colors.length]},${n})`},c=(r,u,n)=>{let s=r.mania_lane_colors[u]??r.mania_lane_colors[4];return s[n%s.length]??"#ffffff"};var C={None:(r)=>r,Out:(r)=>1-Math.pow(1-r,2),In:(r)=>r*r,InOut:(r)=>r<0.5?2*r*r:1-Math.pow(-2*r+2,2)/2,OutCubic:(r)=>1-Math.pow(1-r,3),InCubic:(r)=>r*r*r,OutQuad:(r)=>1-Math.pow(1-r,2),InQuad:(r)=>r*r,OutQuint:(r)=>1-Math.pow(1-r,5),InQuint:(r)=>r*r*r*r*r,OutElastic:(r)=>{let u=2*Math.PI/3;return r===0?0:r===1?1:Math.pow(2,-10*r)*Math.sin((r*10-0.75)*u)+1}};class mr{transforms=[];add(r,u,n,s,e,t=C.None){return this.transforms.push({property:r,start_value:u,end_value:n,start_time:s,end_time:s+e,easing:t}),this}then(){return this}get_value(r,u,n){let s=n;for(let e of this.transforms){if(e.property!==r)continue;if(u<e.start_time)continue;if(u>=e.end_time)s=e.end_value;else{let t=(u-e.start_time)/(e.end_time-e.start_time),o=e.easing(t);s=e.start_value+(e.end_value-e.start_value)*o}}return s}clear(){this.transforms=[]}}class Y{backend;skin;hit_object;config;alpha=1;scale=1;rotation=0;x=0;y=0;armed_state=0;transforms=new mr;life_time_start=0;life_time_end=0;constructor(r,u){this.hit_object=r,this.config=u,this.backend=u.backend,this.skin=u.skin;let n=r.data;this.x=n.pos[0],this.y=n.pos[1],this.apply_defaults()}apply_defaults(){let{hit_object:r,config:u}=this,n=r.time-u.preempt;this.life_time_start=n,this.life_time_end=r.end_time+800}is_alive(r){return r>=this.life_time_start&&r<=this.life_time_end}update(r){this.alpha=this.transforms.get_value("alpha",r,1),this.scale=this.transforms.get_value("scale",r,1),this.rotation=this.transforms.get_value("rotation",r,0),this.update_state(r)}update_state(r){if(this.armed_state===0&&r>=this.hit_object.time)this.armed_state=1,this.on_hit(r)}on_hit(r){}render_body_pass(r){}render_head_pass(r){}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]}}class G{state={circle_alpha:0,circle_scale:1,number_alpha:1};update(r,u,n){let s=u-n.preempt;if(r<s){this.reset_pre_hit_state();return}if(r<u){this.update_pre_hit(r,s,u,n);return}let e=_(u,s,u,n);this.update_post_hit(r,u,n,e)}render(r,u,n,s,e,t){let{circle_alpha:o,circle_scale:f,number_alpha:h}=this.state;if(o<=0.01)return;let T=s*f;if(o>0.01){let M=s*u.circle_border_width,I=s*(1-u.circle_border_width/2)*f;if(r.set_alpha(o*u.hit_circle_opacity),r.draw_circle(n[0],n[1],I,e,"rgba(255,255,255,1)",M),h>0.01){let H=s*0.7*f;r.set_alpha(h*u.hit_circle_opacity);let V=u.default_font??'"Trebuchet MS", Verdana, Arial, sans-serif',R=`600 ${H}px ${V}`;r.draw_text(String(t),n[0],n[1],R,"rgba(255,255,255,1)","center","middle")}r.set_alpha(1)}r.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(r,u,n,s){let e=_(r,u,n,s);this.state.circle_alpha=e,this.state.circle_scale=1,this.state.number_alpha=e}update_post_hit(r,u,n,s){let e=r-u,{skin:t}=n,o=Math.max(90,t.hit_animation_duration*0.75),f=F(e/o,0,1),h=m(n.mods,p.Hidden)?F(s,0,1):F(Math.max(s,0.25),0,1);this.state.circle_alpha=h*(1-C.OutQuad(f));let T=Math.max(90,o*0.85),M=F(e/T,0,1);this.state.circle_scale=W(1,t.hit_animation_scale,C.OutCubic(M)),this.state.number_alpha=this.state.circle_alpha}}var _=(r,u,n,s)=>{let t=F((r-u)/s.fade_in,0,1);if(m(s.mods,p.Hidden)){let o=n-s.preempt+s.fade_in,f=s.preempt*0.3;if(r>o){let h=F((r-o)/f,0,1);t*=1-h}}return t};class Cr{state={alpha:0,scale:1};update(r,u,n){if(!n.skin.enable_hitburst){this.state.alpha=0,this.state.scale=1;return}if(r<u){this.state.alpha=0,this.state.scale=1;return}let s=u-n.preempt,e=_(u,s,u,n),t=m(n.mods,p.Hidden)?F(e,0,1):F(Math.max(e,0.25),0,1),o=r-u,f=Math.max(70,n.skin.hitburst_duration),h=F(o/f,0,1),T=1-C.OutQuint(h);this.state.alpha=m(n.mods,p.Hidden)?T*t:T,this.state.scale=W(1,n.skin.hitburst_scale,C.OutCubic(h))}render(r,u,n,s,e){if(!u.enable_hitburst)return;if(this.state.alpha<=0.01)return;if(r.set_alpha(this.state.alpha),r.draw_circle(n[0],n[1],s*this.state.scale,"rgba(255,255,255,1)","transparent",0),u.hitburst_glow_enabled){r.save(),r.set_blend_mode("lighter"),r.set_alpha(this.state.alpha*u.hitburst_glow_opacity);let t=u.hitburst_glow_use_combo_color?e:u.hitburst_glow_color??e;r.draw_circle(n[0],n[1],s*this.state.scale*1.08,t,"transparent",0),r.restore()}}}class rr extends Y{visual=new G;hitburst=new Cr;constructor(r,u){super(r,u)}update(r){super.update(r),this.visual.update(r,this.hit_object.time,this.config),this.hitburst.update(r,this.hit_object.time,this.config)}render(r){let{backend:u,skin:n,config:s}=this,{radius:e}=s,t=this.position,o=J(n,this.combo_number,1);this.visual.render(u,n,t,e,o,this.combo_count),this.hitburst.render(u,n,t,e,o)}}var ur=(r)=>{let{start_time:u,span_duration:n,span_count:s,length:e,tick_distance:t,min_distance_from_end:o,get_position_at_progress:f}=r,h=[],T=[];if(e<=0||n<=0||s<=0)return{ticks:h,repeats:T};let I=Math.min(1e5,e),H=Math.min(Math.max(t,0),I),V=Math.max(0,Math.min(o,I));for(let R=0;R<s;R++){let D=u+R*n,B=R%2===1;if(H>0){let P=Fu(R,D,n,B,I,H,V,f);if(B)P.reverse();h.push(...P)}if(R<s-1){let P=(R+1)%2;T.push({pos:f(P),time:D+n,repeat_index:R,path_progress:P})}}return h.sort((R,D)=>R.time-D.time),{ticks:h,repeats:T}},Fu=(r,u,n,s,e,t,o,f)=>{let h=[];for(let T=t;T<=e;T+=t){if(T>=e-o)break;let M=T/e,I=s?1-M:M;h.push({pos:f(M),time:u+I*n,span_index:r,path_progress:M})}return h};var Or=240,Sr=1.3,Ar=35,yu=250,mu=300,w=150,Cu=w*4;class K extends Y{slider_data;position_path;render_path;path_length;span_duration;body_alpha=0;head_visual=new G;ball_alpha=0;ball_position;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=[];constructor(r,u,n,s,e,t){super(r,u);this.slider_data=r.data;let o=Math.max(1,u.radius*0.05);this.position_path=n,this.render_path=this.resample_path(n,o),this.span_duration=s,this.tick_distance=e,this.min_distance_from_end=t;let f=this.calculate_path_length();this.path_length=this.slider_data.distance>0?this.slider_data.distance:f,this.ball_position=this.slider_data.pos,this.build_nested_objects(),this.life_time_end=r.end_time+Or}build_nested_objects(){let{slider_data:r,path_length:u,span_duration:n,hit_object:s}=this,e=Math.max(1,r.repetitions),t=1e5,o=Math.min(1e5,r.distance>0?r.distance:u),f=F(this.tick_distance,0,o);if(o<=0||n<=0){this.ticks=[],this.repeats=[];return}let h=ur({start_time:s.time,span_duration:n,span_count:e,length:o,tick_distance:f,min_distance_from_end:this.min_distance_from_end,get_position_at_progress:(T)=>this.get_position_at_progress(T)});this.ticks=h.ticks,this.repeats=h.repeats,this.build_tick_entries()}calculate_path_length(){let r=0;for(let u=1;u<this.position_path.length;u++)r+=l($(this.position_path[u],this.position_path[u-1]));return r}resample_path(r,u){if(r.length<2)return r.slice();let n=[r[0]],s=0,e=[];for(let M=1;M<r.length;M++){let I=l($(r[M],r[M-1]));e.push(I),s+=I}if(s<=0)return n;let t=u,o=0,f=0;while(t<s&&f<e.length){let M=e[f],I=r[f],H=r[f+1];if(M>0&&o+M>=t){let V=(t-o)/M;n.push(Q(I,H,V)),t+=u}else o+=M,f++}let h=r[r.length-1],T=n[n.length-1];if(T[0]!==h[0]||T[1]!==h[1])n.push(h);return n}update(r){super.update(r),this.calculate_ball_position(r),this.calculate_opacities(r),this.head_visual.update(r,this.hit_object.time,this.config)}calculate_ball_position(r){let{hit_object:u,span_duration:n}=this,s=300,e=300,t=2.4;if(r<u.time){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}if(r<=u.end_time){let T=r-u.time,M=Math.max(1,this.slider_data.repetitions),I=Math.min(Math.floor(T/n),M-1),H=F((T-I*n)/n,0,1),V=I%2===1?1-H:H;this.ball_position=this.get_position_at_progress(V),this.ball_alpha=1;let R=F(T/300,0,1),D=C.OutQuint(R);this.follow_alpha=D,this.follow_scale=1+1.4*D;return}let o=r-u.end_time,f=F(o/300,0,1),h=C.OutQuint(f);this.ball_alpha=1-h,this.follow_alpha=1-h,this.follow_scale=2.4-1.4*h}get_position_at_progress(r){let u=r*this.path_length;return this.get_position_at_length(u)}get_position_at_length(r){let u=0;for(let n=1;n<this.position_path.length;n++){let s=l($(this.position_path[n],this.position_path[n-1]));if(u+s>=r){let e=(r-u)/s;return Q(this.position_path[n-1],this.position_path[n],e)}u+=s}return this.position_path[this.position_path.length-1]}calculate_opacities(r){let{hit_object:u,config:n}=this,s=u.time-n.preempt,e=u.time;if(m(n.mods,p.Hidden)){let t=e-n.preempt+n.fade_in;if(r<s)this.body_alpha=0;else if(r<t)this.body_alpha=F((r-s)/n.fade_in,0,1);else if(r<=u.end_time){let o=Math.max(1,u.end_time-t);this.body_alpha=1-F((r-t)/o,0,1)}else this.body_alpha=0}else if(r<s)this.body_alpha=0;else if(r<e)this.body_alpha=F((r-s)/n.fade_in,0,1);else if(r<=u.end_time)this.body_alpha=1;else this.body_alpha=1-F((r-u.end_time)/Or,0,1)}render(r){if(this.body_alpha<=0&&this.head_visual.circle_alpha<=0&&this.ball_alpha<=0)return;this.render_body(r),this.render_head(),this.render_ball(r)}render_body_pass(r){this.render_body(r)}render_head_pass(r){this.render_head(),this.render_reverse_arrows(r),this.render_ball(r)}render_body(r){if(this.body_alpha<=0.01||this.render_path.length<2)return;let{backend:u}=this;if(this.prepare_body_cache(),this.cached_texture&&this.cached_texture.min_x!==void 0&&this.cached_texture.min_y!==void 0){let n=this.cached_scale;u.set_alpha(this.body_alpha),u.draw_image(this.cached_texture,this.cached_texture.min_x,this.cached_texture.min_y,this.cached_texture.width/n,this.cached_texture.height/n),u.set_alpha(1)}this.render_ticks(r)}prepare_body_cache(){if(this.render_path.length<2)return;let{backend:r,skin:u,config:n}=this,{radius:s}=n,e=(n.scale??1)*(u.slider_render_scale||1);if(!this.cached_texture||this.cached_scale!==e){let t=J(u,this.combo_number,1),o=u.slider_border_color??"rgba(255,255,255,1)",f=e;this.cached_texture=r.render_slider_to_image(this.render_path,s,o,t,f,u.slider_body_opacity,u.slider_border_opacity),this.cached_scale=e}}dispose(){if(this.cached_texture?.source instanceof HTMLCanvasElement)this.cached_texture.source.width=0,this.cached_texture.source.height=0;this.cached_texture=null,this.position_path=[],this.render_path=[],this.ticks=[],this.repeats=[],this.tick_entries=[],this.tick_entries_by_start=[]}render_ticks(r){if(this.tick_entries_by_start.length===0)return;let{backend:u,config:n,hit_object:s}=this,{radius:e}=n,t=e*0.12,o=s.time-n.preempt,f=m(n.mods,p.Hidden);for(let h of this.tick_entries_by_start){let T=h.tick,M=r-h.appear_time;if(M<0)continue;if(h.visible_end<r)continue;let I=F(M/w,0,1);if(f&&h.preempt>0){let B=Math.min(h.preempt-w,1000);if(B>0){let P=T.time-B;if(r>=P){let y=F((r-P)/B,0,1);I*=1-y}}}else if(r>T.time){let B=F((r-T.time)/w,0,1);I*=1-B}I*=this.body_alpha;let H=F(M/Cu,0,1),R=0.5+0.5*this.ease_out_elastic_half(H),D=t*R;if(I>0.01)u.set_alpha(I),u.draw_circle(T.pos[0],T.pos[1],D,"rgba(255,255,255,0.8)","transparent",0)}u.set_alpha(1)}build_tick_entries(){let{hit_object:r,config:u}=this,n=r.time-u.preempt,s=m(u.mods,p.Hidden);this.tick_entries=this.ticks.map((e)=>{let t=r.time+e.span_index*this.span_duration,o=u.preempt,f=e.span_index>0?200:o*0.66,h=(e.time-t)/2+f,T=e.time-h,M=s?e.time:e.time+w;return{tick:e,appear_time:T,visible_end:M,preempt:h}}),this.tick_entries_by_start=[...this.tick_entries].sort((e,t)=>e.appear_time-t.appear_time)}ease_out_elastic_half(r){if(r<=0)return 0;if(r>=1)return 1;let u=0.3;return Math.pow(2,-10*r)*Math.sin((r-u/4)*(2*Math.PI)/u)+1}render_reverse_arrows(r){if(this.repeats.length===0)return;let{backend:u,config:n,hit_object:s,span_duration:e}=this,{radius:t}=n,o=t*0.6;for(let f of this.repeats){let h=n.preempt;if(f.repeat_index>0)h=e*2;else h+=s.time-(s.time-n.preempt);let T=f.time-h,M=f.repeat_index%2===0;if(r<T||r>f.time+Or)continue;let I=this.body_alpha*0.9;if(f.repeat_index===0){let P=F((r-T)/150,0,1);I*=C.OutQuint(P)}else if(r<T)I=0;if(r>f.time){let P=Math.min(300,e);I*=1-F((r-f.time)/P,0,1)}if(I<=0.01)continue;let H=this.position_path,V;if(M){let P=H.length-1;V=H[0];for(let y=P;y>=0;y--)if(Math.abs(H[y][0]-f.pos[0])>0.01||Math.abs(H[y][1]-f.pos[1])>0.01){V=H[y];break}}else{V=H[H.length-1];for(let P=0;P<H.length;P++)if(Math.abs(H[P][0]-f.pos[0])>0.01||Math.abs(H[P][1]-f.pos[1])>0.01){V=H[P];break}}let R=Math.atan2(V[1]-f.pos[1],V[0]-f.pos[0]),D=1;if(r<f.time){let P=s.time-n.preempt,y=(r-P)%mu;if(y<Ar)D=1+(Sr-1)*C.Out(y/Ar);else{let O=(y-Ar)/yu;D=Sr-(Sr-1)*C.Out(F(O,0,1))}}else{let P=Math.min(300,e),y=F((r-f.time)/P,0,1);D=1+0.5*C.Out(y)}let B=o*D;u.save(),u.set_alpha(I),u.translate(f.pos[0],f.pos[1]),u.rotate(R),u.begin_path(),u.move_to(B*0.8,0),u.line_to(-B*0.4,-B*0.5),u.line_to(-B*0.4,B*0.5),u.close_path(),u.fill_path("rgba(255,255,255,0.9)"),u.restore()}}render_head(){if(this.head_visual.circle_alpha<=0.01)return;let{backend:r,skin:u,config:n}=this,{radius:s}=n,e=this.slider_data.pos,t=J(u,this.combo_number,1);this.head_visual.render(r,u,e,s,t,this.combo_count)}render_ball(r){if(this.ball_alpha<=0.01&&this.follow_alpha<=0.01)return;let{backend:u,skin:n,config:s}=this,{radius:e}=s,t=this.ball_position,o=J(n,this.combo_number,0.9);if(this.follow_alpha>0.01){let f=e*this.follow_scale;u.set_alpha(this.follow_alpha*n.follow_circle_opacity),u.begin_path(),u.arc_to(t[0],t[1],f,0,Math.PI*2),u.stroke_path(n.follow_circle_color,n.follow_circle_width)}if(n.enable_slider_ball&&this.ball_alpha>0.01)u.set_alpha(this.ball_alpha*n.slider_ball_opacity),u.draw_circle(t[0],t[1],e*0.85,o,"rgba(255,255,255,0.9)",e*0.1);u.set_alpha(1)}}class $r{skin;mods;preempt;fade_in;radius;points=[];lines=[];constructor(r,u,n,s,e){this.skin=r,this.mods=u,this.preempt=n,this.fade_in=s,this.radius=e}update_settings(r,u,n,s){this.mods=r,this.preempt=u,this.fade_in=n,this.radius=s}build(r){this.points=[],this.lines=[];let u=32,n=Math.max(450,this.preempt*0.9);for(let s=0;s<r.length-1;s++){let e=r[s],t=r[s+1];if(Z(e)||Z(t))continue;if(e.combo_number!==t.combo_number)continue;let o=e.end_pos,f=t.data.pos,h=f[0]-o[0],T=f[1]-o[1],M=Math.sqrt(h*h+T*T);if(M<u*1.5)continue;let I=e.end_time,H=t.time-I;if(H<=0)continue;let V=M>0?1/M:0,R=[h*V,T*V],D=I-n,B=t.time-n,P=I+(B-I)*0.5,y=t.time;if(m(this.mods,p.Hidden))P=I+(B-I)*0.3,y=I+(t.time-I)*0.65;this.lines.push({start_pos:o,end_pos:f,dir:R,start_time:I,end_time:t.time,appear_time:D,grow_end_time:B,shrink_start_time:P,shrink_end_time:y});for(let O=u*1.5;O<M-u;O+=u){let A=O/M,S=e.end_time+A*H,q=Math.max(e.end_time,S-n);if(m(this.mods,p.Hidden))S=Math.min(S,I+H*0.65);let g=[o[0]+(A-0.1)*h,o[1]+(A-0.1)*T],d=[o[0]+A*h,o[1]+A*T];this.points.push({start_pos:g,end_pos:d,dir:R,fade_in_time:q,fade_out_time:S})}}}render(r,u,n){let s=this.skin.follow_point_shape,e=this.skin.follow_point_mode??"segments",t=this.skin.follow_point_length||this.radius*0.6,o=F(this.skin.follow_point_line_gap??0,0,0.9),f=Math.max(this.fade_in*0.15,50),h=0.2;if(e==="full")for(let T of this.lines){if(r<T.appear_time||r>T.shrink_end_time)continue;let M=0,I=T.start_pos[0],H=T.start_pos[1],V=T.end_pos[0],R=T.end_pos[1],D=Math.hypot(V-I,R-H),B=this.get_alpha_gate(r,T.start_time,T.end_time,n);if(B<=0.01)continue;let P=this.radius*1.05,y=Math.min(P,D*0.22);if(I+=T.dir[0]*y,H+=T.dir[1]*y,V-=T.dir[0]*y,R-=T.dir[1]*y,r<T.grow_end_time){let O=Math.max(1,T.grow_end_time-T.appear_time),A=F((r-T.appear_time)/O,0,1),S=C.OutQuint(A);M=S,V=I+(V-I)*S,R=H+(R-H)*S}else if(r<T.shrink_start_time)M=1;else{let O=Math.max(1,T.shrink_end_time-T.shrink_start_time),A=F((r-T.shrink_start_time)/O,0,1),S=C.InQuint(A);M=1,I=I+(V-I)*S,H=H+(R-H)*S}if(M<=0)continue;if(u.set_alpha(M*0.2*B),s==="line")if(o>0){let O=Math.hypot(V-I,R-H),A=T.dir[0],S=T.dir[1],q=O*o/2,g=(I+V)/2,d=(H+R)/2,su=g-A*q,eu=d-S*q,tu=g+A*q,ou=d+S*q;u.draw_line(I,H,su,eu,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round"),u.draw_line(tu,ou,V,R,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else u.draw_line(I,H,V,R,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round");else{let O=this.radius*0.12,A=(T.start_pos[0]+T.end_pos[0])/2,S=(T.start_pos[1]+T.end_pos[1])/2;u.draw_circle(A,S,O,"rgba(255,255,255,1)","transparent",0)}}else for(let T of this.points){if(r<T.fade_in_time||r>T.fade_out_time+f)continue;let M=0,I=1,H=T.end_pos;if(r<T.fade_in_time+f){let R=F((r-T.fade_in_time)/f,0,1),D=C.OutCubic(R);M=D,I=1.5-0.5*D,H=Q(T.start_pos,T.end_pos,D)}else if(r<=T.fade_out_time)M=1,I=1,H=T.end_pos;else{let R=F((r-T.fade_out_time)/f,0,1),D=C.OutCubic(R);M=1-D,I=1,H=Q(T.start_pos,T.end_pos,1-D)}if(M<=0)continue;let V=this.get_alpha_gate(r,T.fade_in_time+this.preempt,T.fade_out_time,n);if(V<=0.01)continue;if(u.set_alpha(M*0.2*V),s==="line"){let D=t*I/2,B=T.dir[0],P=T.dir[1],y=H[0]-B*D,O=H[1]-P*D,A=H[0]+B*D,S=H[1]+P*D;u.draw_line(y,O,A,S,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else{let R=this.radius*0.12*I;u.draw_circle(H[0],H[1],R,"rgba(255,255,255,1)","transparent",0)}}u.set_alpha(1)}get_alpha_gate(r,u,n,s){let e=s(r,u),t=s(r,n);return F(Math.min(e,t)/0.7,0,1)}}var Nr=(r,u=0.08)=>{if(r.length<2)return[...r];let n=[];return lr(r,n,u),n},lr=(r,u,n)=>{if(Ou(r,n)){if(u.length===0)u.push(r[0]);u.push(r[r.length-1]);return}let s=[],e=[];Au(r,s,e),lr(s,u,n),lr(e,u,n)},Ou=(r,u)=>{if(r.length<=2)return!0;let n=r[0],s=r[r.length-1];for(let e=1;e<r.length-1;e++)if(Su(r[e],n,s)>u)return!1;return!0},Su=(r,u,n)=>{let s=$(n,u),e=s[0]*s[0]+s[1]*s[1];if(e===0)return l($(r,u));let t=Math.max(0,Math.min(1,((r[0]-u[0])*s[0]+(r[1]-u[1])*s[1])/e)),o=[u[0]+t*s[0],u[1]+t*s[1]];return l($(r,o))},Au=(r,u,n)=>{let s=r.length,e=[r];for(let t=1;t<s;t++){e[t]=[];for(let o=0;o<s-t;o++)e[t][o]=Q(e[t-1][o],e[t-1][o+1],0.5)}for(let t=0;t<s;t++)u.push(e[t][0]),n.push(e[s-1-t][t])},Lr=(r,u,n)=>{let s=$(u,r),e=l(s);if(e===0)return[r];let t=[s[0]/e,s[1]/e],o=ir(r,gr(t,n));return[r,o]},dr=(r,u)=>{if(r.length!==3)return Nr(r);let[n,s,e]=r,t=$u(n,s,e);if(!t)return Lr(n,e,u);let o=l($(n,t)),f=Math.atan2(n[1]-t[1],n[0]-t[0]),h=Math.atan2(e[1]-t[1],e[0]-t[0]),M=(s[0]-n[0])*(e[1]-n[1])-(s[1]-n[1])*(e[0]-n[0])>0,I=h-f;if(M&&I<0)I+=2*Math.PI;if(!M&&I>0)I-=2*Math.PI;let H=Math.abs(I)*o,V=2;if(o*2>0.1){let D=Math.abs(I),B=2*Math.acos(1-0.1/o);if(V=Math.max(2,Math.ceil(D/B)),V>=1000)V=1000}let R=[];for(let D=0;D<=V;D++){let B=D/V,P=f+I*B;R.push([t[0]+o*Math.cos(P),t[1]+o*Math.sin(P)])}return R},$u=(r,u,n)=>{let s=2*(r[0]*(u[1]-n[1])+u[0]*(n[1]-r[1])+n[0]*(r[1]-u[1]));if(Math.abs(s)<0.001)return null;let e=((r[0]*r[0]+r[1]*r[1])*(u[1]-n[1])+(u[0]*u[0]+u[1]*u[1])*(n[1]-r[1])+(n[0]*n[0]+n[1]*n[1])*(r[1]-u[1]))/s,t=((r[0]*r[0]+r[1]*r[1])*(n[0]-u[0])+(u[0]*u[0]+u[1]*u[1])*(r[0]-n[0])+(n[0]*n[0]+n[1]*n[1])*(u[0]-r[0]))/s;return[e,t]},jr=(r)=>{if(r.length<2)return[...r];let u=[];for(let n=0;n<r.length-1;n++){let s=r[Math.max(0,n-1)],e=r[n],t=r[n+1],o=r[Math.min(r.length-1,n+2)],f=l($(t,e)),h=Math.max(8,Math.ceil(f/3));for(let T=0;T<=h;T++){let M=T/h;u.push(lu(s,e,t,o,M))}}return u},lu=(r,u,n,s,e)=>{let t=e*e,o=t*e;return[0.5*(2*u[0]+(-r[0]+n[0])*e+(2*r[0]-5*u[0]+4*n[0]-s[0])*t+(-r[0]+3*u[0]-3*n[0]+s[0])*o),0.5*(2*u[1]+(-r[1]+n[1])*e+(2*r[1]-5*u[1]+4*n[1]-s[1])*t+(-r[1]+3*u[1]-3*n[1]+s[1])*o)]};var br=(r)=>{let u;if(r.path_type==="L")u=Lr(r.pos,r.control_points[0],r.distance);else{let n=[r.pos,...r.control_points];switch(r.path_type){case"P":u=dr(n,r.distance);break;case"C":u=jr(n);break;default:u=Nu(n);break}}return Lu(u,r.distance)},kr=(r)=>{if(!r.computed_path||r.computed_path.length===0)return r.pos;return r.repetitions%2===0?r.pos:r.computed_path[r.computed_path.length-1]},Nu=(r)=>{let u=[],n=[r[0]];for(let e=1;e<r.length;e++){let[t,o]=[r[e-1],r[e]];if(t[0]===o[0]&&t[1]===o[1]){if(n.length>1)u.push(n);n=[o]}else n.push(o)}if(n.length>1)u.push(n);let s=[];for(let e of u)s.push(...Nr(e));return s},Lu=(r,u)=>{if(r.length<2)return r;let n=[r[0]],s=0,e=null,t=!1;for(let o=1;o<r.length;o++){let f=l($(r[o],r[o-1])),h=$(r[o],r[o-1]);if(f>0)e=[h[0]/f,h[1]/f];if(f===0)continue;if(s+f>=u){let T=u-s;n.push(Q(r[o-1],r[o],T/f)),s=u,t=!0;break}s+=f,n.push(r[o])}if(!t&&s<u&&e){let o=u-s,f=n[n.length-1];n.push([f[0]+e[0]*o,f[1]+e[1]*o])}return n};var nr=(r,u,n)=>{if(r<=0)return 0;let s=u.Difficulty.SliderMultiplier;return r*n.base_beat_length/(100*s*n.sv_multiplier)},sr=(r,u)=>{let n=u.sv_multiplier||1,s=r.Difficulty.SliderMultiplier,e=r.Difficulty.SliderTickRate,t=100*s*n,o=r.version<8?1/n:1,f=t/e*o,h=t/u.base_beat_length;return{tick_distance:f,min_distance_from_end:h*10}};class x{points;index=0;last_time=Number.NEGATIVE_INFINITY;base_beat_length=600;sv_multiplier=1;constructor(r){if(this.points=r,r.length>0&&r[0].uninherited===1&&r[0].beatLength>0)this.base_beat_length=r[0].beatLength}reset(){this.index=0,this.last_time=Number.NEGATIVE_INFINITY,this.base_beat_length=600,this.sv_multiplier=1}get_state_at(r){if(this.points.length===0)return{base_beat_length:600,sv_multiplier:1};if(r<this.last_time)this.reset();for(let u=this.index;u<this.points.length;u++){let n=this.points[u];if(n.time>r)break;if(n.uninherited===1&&n.beatLength>0)this.base_beat_length=n.beatLength,this.sv_multiplier=1;else if(n.uninherited===0&&n.beatLength<0){let s=-100/n.beatLength;if(s>0)this.sv_multiplier=s}this.index=u}return this.last_time=r,this.sv_multiplier=F(this.sv_multiplier,0.1,10),{base_beat_length:this.base_beat_length,sv_multiplier:this.sv_multiplier}}}var er=(r)=>{if(r.length===0)return r;return r.sort((u,n)=>{if(u.time!==n.time)return u.time-n.time;if(u.uninherited===n.uninherited)return 0;return u.uninherited>n.uninherited?-1:1})};var tr=(r)=>{let u=[];for(let n of r.HitObjects){let s={...n,end_time:n.endTime||n.time,end_pos:[n.x,n.y],combo_number:0,combo_count:0,data:{pos:[n.x,n.y]}};if(n.type&N.Slider){let e={pos:[n.x,n.y],path_type:n.curveType||"L",control_points:(n.curvePoints||[]).map((t)=>[t.x,t.y]),repetitions:n.slides||1,distance:n.length||0};s.data=e}else if(n.type&N.Spinner){let e=n.endTime||n.time;s.data={end_time:e},s.end_time=e,s.end_pos=[256,192]}else if(n.type&N.Hold){let e=n.endTime||n.time;s.data={pos:[n.x,n.y],end_time:e},s.end_time=e}u.push(s)}return u};var Qr=(r)=>384-r;class or extends E{radius=32;preempt=1200;fade_in=600;timing_points=[];timing_resolver=null;drawables=[];drawable_config;follow_point_renderer;constructor(r,u,n=0,s=v){super(r,u,n,s);this.follow_point_renderer=new $r(u,n,this.preempt,this.fade_in,this.radius)}initialize(r){this.release_drawables(),this.beatmap=r,this.objects=tr(r).sort((s,e)=>s.time-e.time),this.timing_points=er([...r.TimingPoints]),this.timing_resolver=new x(this.timing_points);let u=r.Difficulty.ApproachRate>=0?r.Difficulty.ApproachRate:r.Difficulty.OverallDifficulty,n=xr(r.Difficulty.CircleSize,u,0,0,this.mods);if(this.radius=wr(n.cs),this.preempt=k(n.ar),this.fade_in=Gr(this.preempt),m(this.mods,p.Hidden))this.fade_in=this.preempt*0.4;this.follow_point_renderer.update_settings(this.mods,this.preempt,this.fade_in,this.radius),this.preprocess_objects(),this.follow_point_renderer.build(this.objects),this.create_drawables()}set_mods(r){if(this.mods=r,this.beatmap)this.initialize(this.beatmap)}preprocess_objects(){let r=0,u=1;if(this.timing_resolver)this.timing_resolver.reset();for(let n of this.objects){if(Zr(n))r=(r+1)%this.skin.combo_colors.length,u=1;else u++;if(n.combo_number=r,n.combo_count=u,pr(n)){let s=n.data;if(m(this.mods,p.HardRock))s.pos=[s.pos[0],Qr(s.pos[1])],s.control_points=s.control_points.map((o)=>[o[0],Qr(o[1])]);s.computed_path=br(s);let e=this.timing_resolver?.get_state_at(n.time)??{base_beat_length:600,sv_multiplier:1},t=nr(s.distance,this.beatmap,e);s.duration=t,n.end_time=n.time+t*s.repetitions,n.end_pos=kr(s)}else if(Z(n))n.end_pos=[256,192];else{let s=n.data;if(m(this.mods,p.HardRock))s.pos=[s.pos[0],Qr(s.pos[1])];n.end_pos=s.pos}}}create_drawables(){this.release_drawables();let r=this.config.use_high_dpi?window.devicePixelRatio||1:1;if(this.drawable_config={backend:this.backend,skin:this.skin,preempt:this.preempt,fade_in:this.fade_in,radius:this.radius,scale:this.config.scale*r,mods:this.mods},this.timing_resolver)this.timing_resolver.reset();for(let u of this.objects)if(Ur(u))this.drawables.push(new rr(u,this.drawable_config));else if(pr(u)){let n=u.data,s=n.computed_path||[],e=n.duration||0,t=this.timing_resolver?.get_state_at(u.time)??{base_beat_length:600,sv_multiplier:1},{tick_distance:o,min_distance_from_end:f}=sr(this.beatmap,t);this.drawables.push(new K(u,this.drawable_config,s,e,o,f))}}render(r){let{backend:u,config:n}=this;this.render_background(),u.save(),u.translate(n.offset_x,n.offset_y),u.scale(n.scale,n.scale),this.render_playfield(),this.render_grid();let s=[];for(let e=this.drawables.length-1;e>=0;e--){let t=this.drawables[e];if(t.is_alive(r))s.push(t)}this.follow_point_renderer.render(r,u,(e,t)=>this.get_circle_alpha(e,t));for(let e of this.objects)if(Z(e)){let t=e.time-this.preempt;if(r>=t&&r<=e.end_time+200)this.draw_spinner(e,r)}for(let e of s)e.update(r);for(let e of s)if(e instanceof K)e.render_body_pass(r);for(let e of s)if(e instanceof K)e.render_head_pass(r);else e.render(r);if(!m(this.mods,p.Hidden)&&this.skin.enable_approach_circle){for(let e of s)if(r<=e.start_time)this.draw_approach_circle(e,r)}u.restore()}precompute(){}dispose(){this.release_drawables(),this.timing_points=[],this.timing_resolver=null,super.dispose()}release_drawables(){for(let r of this.drawables)r.dispose();this.drawables=[]}draw_approach_circle(r,u){let n=r.position,s=r.start_time-this.preempt,e=Math.min(this.fade_in*2,this.preempt),o=F((u-s)/e,0,1)*this.skin.approach_circle_opacity,h=4-3*F((u-s)/this.preempt,0,1),T=J(this.skin,r.combo_number,1);this.backend.save(),this.backend.set_alpha(o),this.backend.draw_circle(n[0],n[1],this.radius*h,"transparent",T,this.radius*this.skin.approach_circle_width),this.backend.restore()}get_circle_alpha(r,u){let n=u-this.preempt;if(r<n)return 0;let s=F((r-n)/this.fade_in,0,1);if(m(this.mods,p.Hidden)){let e=u-this.preempt+this.fade_in,t=this.preempt*0.3;if(r>e){let o=F((r-e)/t,0,1);s*=1-o}}return s}draw_spinner(r,u){let n=r.time-this.preempt,s=F((u-n)/this.fade_in,0,1);if(u>r.end_time)s=1-C.OutCubic(F((u-r.end_time)/200,0,1));if(s<=0)return;let e=256,t=192,o=r.end_time-r.time,f=F((u-r.time)/o,0,1);this.backend.set_alpha(s);let h=this.skin.spinner_size*(1-f);if(h>5)this.backend.begin_path(),this.backend.arc_to(e,t,h,0,Math.PI*2),this.backend.stroke_path("rgba(255,255,255,0.6)",4);this.backend.draw_circle(e,t,this.skin.spinner_size,"rgba(0,0,0,0.2)"),this.backend.draw_circle(e,t,12,"white")}}var ar=11485,_r=20;class fr extends E{key_count=4;scroll_time=ar/_r;hd_coverage=0.25;fi_coverage=0.6;gradient_ratio=0.2;constructor(r,u,n=0,s=v){super(r,u,n,s);this.update_scroll_time()}initialize(r){this.beatmap=r,this.objects=tr(r),this.key_count=Math.floor(r.Difficulty.CircleSize)}set_mods(r){this.mods=r,this.update_scroll_time()}update_scroll_time(){let r=Pr(this.mods);this.scroll_time=ar/(_r*r)}time_to_y(r){let u=this.skin.mania_hit_position,n=r/this.scroll_time;return u-n*u}render(r){let{backend:u,config:n,skin:s,key_count:e}=this;this.render_background();let t=e*s.mania_lane_width,o=Math.floor((Mr-t)/2),f=s.mania_hit_position;u.save(),u.translate(n.offset_x,n.offset_y),u.scale(n.scale,n.scale),this.render_playfield(t,Dr,o),this.draw_lane_keys(r,o),this.draw_judgment_line(o),u.save(),u.begin_path(),u.rect(o,0,t,f),u.clip(),u.set_alpha(0.7),u.draw_rect(o,0,t,f,"#000000"),u.set_alpha(1);for(let h of this.objects){if(h.end_time<r)continue;if(qr(h))this.draw_hold_note(h,r,o);else this.draw_note(h,r,o)}if(m(this.mods,p.Hidden)||m(this.mods,p.FadeIn)){let h=m(this.mods,p.Hidden)?this.hd_coverage:this.fi_coverage,T=f*h,M=f*this.gradient_ratio;if(m(this.mods,p.Hidden)){let I=f-T,H=M/T,V=u.create_linear_gradient(o,I,o,f,[{offset:0,color:"rgba(0,0,0,0)"},{offset:H*0.4,color:"rgba(0,0,0,0.3)"},{offset:H*0.7,color:"rgba(0,0,0,0.75)"},{offset:H*0.9,color:"rgba(0,0,0,0.95)"},{offset:H,color:"rgba(0,0,0,1)"},{offset:1,color:"rgba(0,0,0,1)"}]);u.draw_rect_gradient(o,I,t,T,V)}else{let I=(T-M)/T,H=u.create_linear_gradient(o,0,o,T,[{offset:0,color:"rgba(0,0,0,1)"},{offset:I,color:"rgba(0,0,0,1)"},{offset:I+(1-I)*0.1,color:"rgba(0,0,0,0.95)"},{offset:I+(1-I)*0.4,color:"rgba(0,0,0,0.75)"},{offset:I+(1-I)*0.7,color:"rgba(0,0,0,0.3)"},{offset:1,color:"rgba(0,0,0,0)"}]);u.draw_rect_gradient(o,0,t,T,H)}}u.restore(),u.restore()}get_lane(r){let u=r.data.pos,n=Math.floor(u[0]*this.key_count/512);if(m(this.mods,p.Mirror))n=this.key_count-1-n;return n}draw_note(r,u,n){let{backend:s,skin:e,key_count:t}=this,o=this.get_lane(r),f=e.mania_lane_width,h=e.mania_note_height,T=e.mania_lane_spacing,M=r.time-u,I=this.time_to_y(M);if(I<-h-64)return;let H=n+o*f,V=c(e,t,o);s.set_alpha(1),s.draw_rect(H+T,I-h,f-2*T,h,V)}draw_hold_note(r,u,n){let{backend:s,skin:e,key_count:t}=this,o=r.data,f=this.get_lane(r),h=e.mania_lane_width,T=e.mania_note_height,M=e.mania_lane_spacing,I=r.time-u,H=o.end_time-u,V=this.time_to_y(I),R=this.time_to_y(H),D=n+f*h,B=c(e,t,f);if(R<-64&&V<-64)return;let P=R,O=(I<0?e.mania_hit_position:V)-P;if(O>0)s.set_alpha(0.9),s.draw_rect(D+M,P,h-2*M,O,B);if(I>=0)s.set_alpha(1),s.draw_rect(D+M,V-T,h-2*M,T,B);s.set_alpha(1)}draw_judgment_line(r){let{backend:u,skin:n,key_count:s}=this,e=n.mania_lane_width,t=n.mania_hit_position;u.draw_rect(r,t-1,e*s,2,"#ffffff")}draw_lane_keys(r,u){let{backend:n,skin:s,key_count:e}=this,{mania_lane_width:t,mania_hit_position:o,mania_lane_spacing:f,mania_note_height:h}=s,T=h+5,M=new Set,I=50;for(let H of this.objects)if(r>=H.time-50&&r<=H.end_time+50)M.add(this.get_lane(H));for(let H=0;H<e;H++){let V=M.has(H),R=u+H*t,D=c(s,e,H);if(n.set_alpha(0.3),n.draw_rect(R+f,o,t-2*f,T,D),V)n.set_alpha(1),n.draw_rect(R+f,o,t-2*f,T,"#ff6666")}n.set_alpha(1)}}class i{audio_context;gain_node;constructor(r){this.audio_context=r,this.gain_node=this.audio_context.createGain(),this.gain_node.connect(this.audio_context.destination)}set_volume(r){this.gain_node.gain.value=F(r,0,1)}dispose_audio_node(){this.gain_node.disconnect()}}class hr extends i{audio_element=null;media_source_node=null;object_url=null;pause_time=0;speed=1;_is_playing=!1;_duration=0;_is_loaded=!1;constructor(r){super(r)}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.audio_element)return this.pause_time;if(!this._is_playing)return this.pause_time;return this.audio_element.currentTime*1000}async load(r,u=0){this.stop(),this.release_media();try{this.speed=z(u);let n=new Blob([r]),s=URL.createObjectURL(n),e=new Audio(s);e.preload="metadata",e.playbackRate=this.speed,e.preservesPitch=!1,this.audio_element=e,this.object_url=s,this.media_source_node=this.audio_context.createMediaElementSource(e),this.media_source_node.connect(this.gain_node),await new Promise((t,o)=>{let f=()=>{e.removeEventListener("loadedmetadata",f),e.removeEventListener("error",h),t()},h=()=>{e.removeEventListener("loadedmetadata",f),e.removeEventListener("error",h),o(Error("Failed to load audio metadata"))};e.addEventListener("loadedmetadata",f,{once:!0}),e.addEventListener("error",h,{once:!0})}),this._duration=Math.max(0,(this.audio_element.duration||0)*1000),this._is_loaded=!0,this.pause_time=0,this.audio_element.onended=()=>{this._is_playing=!1,this.pause_time=this._duration}}catch(n){throw console.error("Failed to load audio data",n),this.release_media(),n}}async play(r){if(!this.audio_element){console.warn("[AudioController] Cannot play: not loaded");return}let u=r!==void 0?r/1000:this.pause_time/1000,n=this.audio_element.duration||this._duration/1000,s=Math.max(0,Math.min(u,n));if(s>=n){this.pause_time=n*1000;return}this.audio_element.currentTime=s,this.audio_element.playbackRate=this.speed;try{await this.audio_element.play(),this._is_playing=!0}catch(e){throw this._is_playing=!1,e}}pause(){if(!this.audio_element||!this._is_playing)return;this.pause_time=this.current_time,this.audio_element.pause(),this._is_playing=!1}seek(r){let u=Math.max(0,Math.min(r,this._duration));if(this.pause_time=u,!this.audio_element)return;this.audio_element.currentTime=u/1000}stop(){if(this.pause(),this.pause_time=0,this.audio_element)this.audio_element.currentTime=0}get_host_time(r){let u=r-this.current_time;return this.audio_context.currentTime+u/1000/this.speed}set_speed(r){if(this.speed=r,this.audio_element)this.audio_element.playbackRate=r}dispose(){this.stop(),this.release_media(),this._is_loaded=!1,this._duration=0,this.pause_time=0,this._is_playing=!1,this.dispose_audio_node()}release_media(){if(this.audio_element)this.audio_element.pause(),this.audio_element.onended=null,this.audio_element.src="",this.audio_element.load(),this.audio_element=null;if(this.media_source_node)this.media_source_node.disconnect(),this.media_source_node=null;if(this.object_url)URL.revokeObjectURL(this.object_url),this.object_url=null}}class Tr{video=null;object_url=null;_offset=0;get element(){return this.video}get offset(){return this._offset}async load(r,u=0){this.dispose(),this._offset=u,this.video=document.createElement("video"),this.video.muted=!0,this.video.loop=!1,this.video.playsInline=!0,this.object_url=URL.createObjectURL(r),this.video.src=this.object_url,await new Promise((n,s)=>{if(!this.video)return s(Error("No video element"));this.video.onloadeddata=()=>n(),this.video.onerror=()=>s(Error("Failed to load video"))})}sync(r){if(!this.video)return;let u=(r-this._offset)/1000;if(u<0){if(!this.video.paused)this.video.pause();return}if(Math.abs(this.video.currentTime-u)>0.1)this.video.currentTime=u}play(){if(this.video&&this.video.paused)this.video.play().catch(()=>{console.log("failed to play video")})}pause(){if(this.video&&!this.video.paused)this.video.pause()}seek(r){if(!this.video)return;let u=Math.max(0,(r-this._offset)/1000);this.video.currentTime=u}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 U extends i{static default_samples=new Map;static default_loads=new Map;custom_samples=new Map;constructor(r){super(r)}async load_samples(r){this.custom_samples.clear(),await this.load_into_cache(r,this.custom_samples,!1)}async load_samples_from_files(r){this.custom_samples.clear(),await this.load_files_into_cache(r,this.custom_samples)}async load_default_samples(r){await this.load_into_cache(r,U.default_samples,!0)}clear(){this.custom_samples.clear()}play(r,u,n,s,e=100,t,o=0){let f=this.get_set_name(r),h=this.get_set_name(u);if(t){let T=t.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"");if(this.play_buffer(T,e,o))return}if(this.play_sound(f,"hitnormal",s,e,o),n&j.Whistle)this.play_sound(h,"hitwhistle",s,e,o);if(n&j.Finish)this.play_sound(h,"hitfinish",s,e,o);if(n&j.Clap)this.play_sound(h,"hitclap",s,e,o)}play_sample(r,u,n,s=100,e=0){let t=this.get_set_name(r);this.play_sound(t,u,n,s,e)}play_sound(r,u,n,s,e){let t=!1;if(n>1)t=this.play_buffer(`${r}-${u}${n}`,s,e);if(!t)this.play_buffer(`${r}-${u}`,s,e)}play_buffer(r,u,n){let s=this.custom_samples.get(r)??U.default_samples.get(r);if(!s)return!1;let e=this.audio_context.createBufferSource();e.buffer=s;let t=this.audio_context.createGain();return t.gain.value=u/100,e.connect(t),t.connect(this.gain_node),e.start(n),!0}get_set_name(r){switch(r){case 3:return"drum";case 2:return"soft";default:return"normal"}}get_sample_key_from_url(r){let n=r.split("?")[0].split("#")[0].split("/").pop();if(!n)return null;if(!n.endsWith(".wav")&&!n.endsWith(".mp3")&&!n.endsWith(".ogg"))return null;return n.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"")}async load_into_cache(r,u,n){if(r.length==0)return;let s=[],e=r.map(async(t)=>{let o=this.get_sample_key_from_url(t);if(!o){s.push(t);return}if(u.has(o))return;if(!n){await this.load_single_sample(t,o,u,s);return}let f=U.default_loads.get(o);if(f){await f;return}let h=this.load_single_sample(t,o,u,s).finally(()=>{U.default_loads.delete(o)});U.default_loads.set(o,h),await h});if(await Promise.all(e),s.length>0)console.warn(`[HitsoundController] Failed to load ${s.length} hitsounds`)}async load_single_sample(r,u,n,s){try{let e=await fetch(r);if(!e.ok){s.push(r);return}let t=await e.arrayBuffer();if(t.byteLength<128){s.push(r);return}let o=await this.audio_context.decodeAudioData(t.slice(0));n.set(u,o)}catch{s.push(r)}}async load_files_into_cache(r,u){if(r.size==0)return;let n=[],s=[...r.entries()].map(async([e,t])=>{let o=this.get_sample_key_from_url(e);if(!o)return;if(u.has(o))return;if(t.byteLength<128){n.push(e);return}try{let f=await this.audio_context.decodeAudioData(t.slice(0));u.set(o,f)}catch{n.push(e)}});if(await Promise.all(s),n.length>0)console.warn(`[HitsoundController] Failed to load ${n.length} hitsounds`)}dispose(){this.custom_samples.clear(),this.dispose_audio_node()}}class vr{files;audio_filename;background_filename;video_filename;video_offset;constructor(r){this.files=r.files,this.audio_filename=r.audio_filename,this.background_filename=r.background_filename,this.video_filename=r.video_filename,this.video_offset=r.video_offset}resolve(){let r=this.audio_filename?this.find_file(this.audio_filename):void 0,u=this.background_filename?this.find_file(this.background_filename):void 0,n=this.video_filename?this.find_file(this.video_filename):void 0;return{audio:r,background:u?new Blob([u]):void 0,video:n?new Blob([n]):void 0,video_offset:this.video_offset}}find_file(r){if(this.files.has(r))return this.files.get(r);let u=r.toLowerCase();for(let[n,s]of this.files)if(n.toLowerCase()===u)return s;return}}var Qu=100,vu=20;class Jr{audio;hitsounds;resources=null;timing_points=[];timing_resolver=null;audio_offset=20;next_hit_object_index=0;constructor(r,u){this.audio=r;this.hitsounds=u}set_context(r,u,n,s){this.resources=r,this.timing_points=u,this.timing_resolver=n,this.audio_offset=s,this.next_hit_object_index=0}set_audio_offset(r){this.audio_offset=r}update_hit_index(r){if(!this.resources?.beatmap)return;let u=this.resources.beatmap.HitObjects;if(this.next_hit_object_index>0&&u[this.next_hit_object_index-1].time>r)this.next_hit_object_index=0;while(this.next_hit_object_index<u.length&&u[this.next_hit_object_index].time<r)this.next_hit_object_index++}schedule_hitsounds(r){if(!this.resources?.beatmap||!this.audio.is_playing)return;let u=this.resources.beatmap.HitObjects,n=r+Qu;while(this.next_hit_object_index<u.length&&u[this.next_hit_object_index].time<=n){let s=u[this.next_hit_object_index];if(s.time>=r-vu)this.play_hitsound(s);this.next_hit_object_index++}}play_hitsound(r){let u=this.get_timing_point(r.time),n=this.resolve_sample_settings(u,r.hitSample);if((r.type&N.Slider)===0){this.play_node_hitsound(r.time,r.hitSound,n,n.custom_filename);return}let s=this.resources?.beatmap;if(!s)return;let e=this.timing_resolver?.get_state_at(r.time)??{base_beat_length:600,sv_multiplier:1},t=r.length??0,o=nr(t,s,e),f=Math.max(1,r.slides||1);if(o<=0||t<=0){this.play_node_hitsound(r.time,r.hitSound,n,n.custom_filename);return}let h=r.edgeSounds??[],T=r.edgeSets??[];for(let H=0;H<=f;H++){let V=r.time+o*H,R=h.length>0?h[H]??0:H==0?r.hitSound:0,D=T.length>0?T[H]:void 0,B=this.resolve_edge_sets(n,D),P=H==0?n.custom_filename:void 0;this.play_node_hitsound(V,R,{...n,...B},P)}let M=sr(s,e),I=ur({start_time:r.time,span_duration:o,span_count:f,length:t,tick_distance:M.tick_distance,min_distance_from_end:M.min_distance_from_end,get_position_at_progress:()=>[0,0]});for(let H of I.ticks){let V=this.audio.get_host_time(H.time+this.audio_offset);this.hitsounds.play_sample(n.normal_set,"slidertick",n.index,n.volume,V)}}play_node_hitsound(r,u,n,s){let e=this.audio.get_host_time(r+this.audio_offset);this.hitsounds.play(n.normal_set,n.addition_set,u,n.index,n.volume,s,e)}resolve_sample_settings(r,u){let{volume:n,sampleSet:s,sampleSet:e,sampleIndex:t}=r,o=void 0;if(u){if(u.normalSet!==0){if(s=u.normalSet,u.additionSet===0)e=s}if(u.additionSet!==0)e=u.additionSet;if(u.index!==0)t=u.index;if(u.volume!==0)n=u.volume;o=u.filename||void 0}if(s===0)s=1;if(e===0)e=s;return{normal_set:s,addition_set:e,index:t,volume:n,custom_filename:o}}resolve_edge_sets(r,u){let{normal_set:n,addition_set:s}=r;if(u){let{normalSet:e,additionSet:t}=u;if(e!==0)n=e;if(t!==0)s=t;else s=n}if(n===0)n=1;if(s===0)s=n;return{normal_set:n,addition_set:s}}get_timing_point(r){let u=this.timing_points;if(u.length==0)return{time:0,beatLength:600,meter:4,sampleSet:1,sampleIndex:1,volume:100,uninherited:1,effects:0};for(let n=u.length-1;n>=0;n--)if(u[n].time<=r)return u[n];return u[0]}}var Ju=[".wav",".mp3",".ogg"],Uu=/^(normal|soft|drum)-(hitnormal|hitwhistle|hitfinish|hitclap|slidertick|sliderslide|sliderwhistle)\d*$/i,ru=(r,u,n)=>{let s=new Set;for(let o of r.HitObjects){let f=o.hitSample?.filename?.trim();if(f)s.add(f.toLowerCase())}let e=new Map,t=n?.toLowerCase();for(let[o,f]of u){let h=o.toLowerCase();if(!qu(h))continue;if(t&&h==t)continue;let T=Zu(h),M=T.replace(/\.(wav|mp3|ogg)$/,""),I=Uu.test(M),H=s.has(T)||s.has(M)||s.has(h);if(I||H)e.set(o,f)}return e},qu=(r)=>{for(let u of Ju)if(r.endsWith(u))return!0;return!1},Zu=(r)=>{let u=r.split("?")[0].split("#")[0];return u.split("/").pop()??u};var Eu=0.42,Wu=30;class nu{backend;renderer=null;audio_context;audio;hitsounds;video=null;resources=null;animation_frame=null;skin;mods;renderer_config;start_offset;start_mode;custom_start_time;music_volume;hitsound_volume;audio_offset;background_url=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;last_timestamp=0;smooth_time=0;constructor(r){this.options=r,this.backend=r.backend??new b,this.skin=a(r.skin),this.mods=r.mods??0,this.renderer_config={...v,...r.renderer_config},this.calculate_layout(r.canvas.width,r.canvas.height,r.playfield_scale),this.start_mode=r.start_mode??(Number.isFinite(r.start_time)?"custom":"preview"),this.custom_start_time=Number.isFinite(r.start_time)?Math.max(0,r.start_time):null,this.start_offset=0,this.music_volume=r.volume??0.5,this.hitsound_volume=r.hitsound_volume??0.25,this.audio_offset=r.audio_offset??20,this.backend.initialize(r.canvas,this.renderer_config.use_high_dpi);let u=window.AudioContext||window.webkitAudioContext;if(this.audio_context=new u,this.audio=new hr(this.audio_context),this.hitsounds=new U(this.audio_context),this.hitsound_scheduler=new Jr(this.audio,this.hitsounds),this.audio.set_volume(this.music_volume),this.hitsounds.set_volume(this.hitsound_volume),r.auto_resize)this.setup_auto_resize();this.enable_fps_counter=r.enable_fps_counter??!1,this.fps_last_update=performance.now();let n=r.time_smoothing;if(Number.isFinite(n))this.time_smoothing=Math.max(0,Math.min(1,n));let s=r.max_frame_delta;if(Number.isFinite(s))this.max_frame_delta=Math.max(10,s)}async load_osz(r,u){try{let s=await new X().load_osz(r,{difficulty:u});return this.resources=s,this.setup()}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_files(r,u){try{let n=new X;return this.resources=await n.load_from_files(r,{difficulty:u}),this.setup()}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_default_hitsounds(r){if(r.length==0){console.warn("[BeatmapPlayer] No default hitsound URLs were provided");return}try{await this.hitsounds.load_default_samples(r)}catch(u){console.error("[BeatmapPlayer] Failed to load default hitsounds:",u)}}async load_custom_hitsounds(r){if(r.length==0){console.warn("[BeatmapPlayer] No custom hitsound URLs were provided"),this.hitsounds.clear();return}try{await this.hitsounds.load_samples(r)}catch(u){console.error("[BeatmapPlayer] Failed to load custom hitsounds:",u)}}async load_map_custom_hitsounds(){if(!this.resources?.beatmap)return;let r=ru(this.resources.beatmap,this.resources.files,this.resources.audio_filename);if(r.size==0){this.hitsounds.clear();return}try{await this.hitsounds.load_samples_from_files(r)}catch(u){console.error("[BeatmapPlayer] Failed to load map custom hitsounds:",u),this.hitsounds.clear()}}async load_beatmap(r,u,n,s,e){return this.resources={beatmap:r,available_difficulties:[],files:new Map,audio:u,background:n,video:s,video_offset:e},this.setup()}async load_osu_content(r,u){try{await uu();let n=await this.parse_content(r);return this.load_beatmap(n,u)}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_beatmap_files(r,u,n,s,e){try{await uu();let t=typeof r==="string",o=r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):null,f=await this.parse_content(t?r:o);return this.load_beatmap(f,u,n,s,e)}catch(t){let o=t instanceof Error?t.message:String(t);return this.emit("error","INVALID_BEATMAP",o),L("INVALID_BEATMAP",o)}}async setup(){if(!this.resources)return L("NOT_LOADED","No resources loaded");let{beatmap:r}=this.resources;this.timing_points=er([...r.TimingPoints]),this.timing_resolver=new x(this.timing_points);let u=z(this.mods);this.resolve_assets();let{audio:n,video:s,video_offset:e}=this.resources;if(n)try{await this.audio.load(n,this.mods)}catch(t){let o=t instanceof Error?t.message:String(t);return this.emit("error","AUDIO_DECODE_ERROR",o),L("AUDIO_DECODE_ERROR",o)}if(this.hitsound_scheduler.set_context(this.resources,this.timing_points,this.timing_resolver,this.audio_offset),this.load_map_custom_hitsounds(),s)this.video=new Tr,await this.video.load(s,e??0);try{this.renderer=this.create_renderer(r),this.renderer.initialize(r),this.renderer.precompute()}catch(t){let o=t instanceof Error?t.message:String(t);return this.emit("error","UNSUPPORTED_MODE",o),L("UNSUPPORTED_MODE",o)}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",r,this.resources),requestAnimationFrame(()=>this.render_frame(this.start_offset)),Er(this.resources)}async load_background(){if(this.resources)this.resolve_assets();if(!this.resources?.background||!this.renderer)return;try{let r=new Image;if(this.background_url)URL.revokeObjectURL(this.background_url);this.background_url=URL.createObjectURL(this.resources.background),r.src=this.background_url,await r.decode(),this.renderer.set_background({source:r,width:r.width,height:r.height});let u=this.audio.is_playing?this.current_time:this.start_offset;requestAnimationFrame(()=>this.render_frame(u))}catch(r){console.warn("[BeatmapPlayer] Failed to load background",r)}}resolve_assets(){if(!this.resources)return;let r=new vr(this.resources).resolve();if(!this.resources.audio&&r.audio)this.resources.audio=r.audio;if(!this.resources.background&&r.background)this.resources.background=r.background;if(!this.resources.video&&r.video)this.resources.video=r.video;if(!this.resources.video_offset&&r.video_offset)this.resources.video_offset=r.video_offset}create_renderer(r){switch(r.General.Mode){case 0:return new or(this.backend,this.skin,this.mods,this.renderer_config);case 3:return new fr(this.backend,this.skin,this.mods,this.renderer_config);case 1:case 2:default:throw Error(`Unsupported game mode: ${Ir[r.General.Mode]??r.General.Mode}`)}}get_last_object_time(){if(!this.resources?.beatmap.HitObjects.length)return 0;let r=this.resources.beatmap.HitObjects,u=0;for(let n of r){let s=n.endTime||n.time;if(s>u)u=s}return u}resolve_preview_start_offset(){if(!this.resources?.beatmap)return 0;let r=this.resources.beatmap.General.PreviewTime;if(r>0)return r;return Math.max(0,this.get_last_object_time()*Eu)}resolve_initial_start_offset(){let r=Math.max(0,this.duration);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,r));return Math.max(0,Math.min(this.resolve_preview_start_offset(),r))}return Math.max(0,Math.min(this.resolve_preview_start_offset(),r))}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();this.audio.play(Math.max(0,this.start_offset+this.audio_offset)),this.video?.play(),this.start_render_loop(),this.emit("play"),this.emit("statechange",!0)}pause(){if(!this.audio.is_playing)return;this.start_offset=Math.max(0,this.audio.current_time-this.audio_offset),this.audio.pause(),this.video?.pause(),this.stop_render_loop(),this.emit("pause"),this.emit("statechange",!1)}set_mods(r){this.mods=r;let u=z(r);if(this.renderer?.set_mods(r),this.audio.set_speed(u),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}seek(r){this.start_offset=Math.max(0,Math.min(r,this.duration)),this.hitsound_scheduler.update_hit_index(this.start_offset),this.audio.seek(Math.max(0,this.start_offset+this.audio_offset)),this.video?.seek(this.start_offset),this.emit("seek",this.start_offset),this.render_frame(this.start_offset)}async set_difficulty(r){if(!this.resources)return L("NOT_LOADED","No beatmap resources loaded");let u=this.is_playing;this.stop();try{let s=await new X().load_from_files(this.resources.files,{difficulty:r});this.resources=s;let e=await this.setup();if(e.success&&u)this.play();return e}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async parse_content(r){let u=typeof r=="string"?new TextEncoder().encode(r):r;return await Xu(u)}stop(){this.pause(),this.start_offset=0,this.audio.seek(Math.max(0,this.audio_offset)),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()}get current_time(){return Math.max(0,this.audio.current_time-this.audio_offset)}get duration(){return this.audio.duration||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(r,u,n){if(this.backend.resize(r,u),this.calculate_layout(r,u,n),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}update_config(r){if(this.renderer_config={...this.renderer_config,...r},this.renderer?.update_config(this.renderer_config),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}set_skin(r){if(this.skin=a(r),this.is_loaded_flag&&this.resources?.beatmap)this.renderer=this.create_renderer(this.resources.beatmap),this.renderer.initialize(this.resources.beatmap),requestAnimationFrame(()=>this.render_frame(this.current_time))}setup_auto_resize(){this.resize_observer=new ResizeObserver(()=>{let u=this.options.canvas.parentElement;if(u){let n=u.getBoundingClientRect();this.resize(n.width,n.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(r,u,n){let t=0.9;if(Number.isFinite(n))t=n;let o=r*t/512,f=u*t/384,h=Math.min(o,f);if(this.renderer_config.scale=h,this.renderer_config.offset_x=Math.floor((r-512*h)/2),this.renderer_config.offset_y=Math.floor((u-384*h)/2),this.renderer)this.renderer.update_config(this.renderer_config)}set_volume(r){this.music_volume=r,this.audio.set_volume(r)}set_hitsound_volume(r){this.hitsound_volume=r,this.hitsounds.set_volume(r)}set_offset(r){if(this.audio_offset=r,this.hitsound_scheduler.set_audio_offset(r),this.is_loaded_flag)this.seek(this.current_time)}on(r,u){if(!this.listeners.has(r))this.listeners.set(r,new Set);this.listeners.get(r).add(u)}off(r,u){this.listeners.get(r)?.delete(u)}emit(r,...u){let n=this.listeners.get(r);if(n)for(let s of n)s(...u)}start_render_loop(){if(this.animation_frame!==null)return;this.last_timestamp=performance.now(),this.smooth_time=this.audio.current_time-this.audio_offset,this.smoothed_delta=0;let r=(u)=>{if(!this.audio.is_playing){this.animation_frame=null;return}let n=Math.max(0,u-this.last_timestamp);this.last_timestamp=u;let s=Math.min(n,this.max_frame_delta);if(this.time_smoothing>0){if(this.smoothed_delta===0)this.smoothed_delta=s;else this.smoothed_delta+=(s-this.smoothed_delta)*this.time_smoothing;s=this.smoothed_delta}this.smooth_time+=s*this.audio.speed_multiplier;let e=this.audio.current_time-this.audio_offset;if(Math.abs(this.smooth_time-e)>Wu)this.smooth_time=e;else this.smooth_time+=(e-this.smooth_time)*0.1;let o=this.smooth_time;if(this.hitsound_scheduler.schedule_hitsounds(e),this.render_frame(o),this.video?.sync(o),this.emit("timeupdate",o,this.duration),o>=this.duration){this.emit("ended"),this.stop_render_loop(),this.emit("statechange",!1);return}this.animation_frame=requestAnimationFrame(r)};this.animation_frame=requestAnimationFrame(r)}stop_render_loop(){if(this.animation_frame!==null)cancelAnimationFrame(this.animation_frame),this.animation_frame=null}render_frame(r){if(this.backend.begin_frame?.(),this.backend.clear(),this.renderer?.render(r),this.enable_fps_counter){this.fps_frame_count++;let u=performance.now(),n=u-this.fps_last_update;if(n>=1000)this.current_fps=Math.round(this.fps_frame_count*1000/n),this.fps_frame_count=0,this.fps_last_update=u;let s=`14px ${this.skin.default_font??"monospace"}`;this.backend.draw_text(`${this.current_fps} FPS`,10,20,s,"rgba(255,255,255,0.8)","left","top")}this.backend.end_frame?.()}set_fps_counter(r){this.enable_fps_counter=r}}var Yu=(r)=>{try{return new FontFace(r.family,r.url,{weight:r.weight,style:"normal"})}catch(u){return console.error(u),null}},Ku=async(r)=>{let u=Yu(r);if(!u)return!1;try{await u.load(),document.fonts.add(u)}catch(n){return console.error(n),!1}return!0};export{cu as unwrap,ju as toggle_mod,Er as ok,du as mods_to_string,gu as mods_from_string,a as merge_skin,Ku as load_font,Z as is_spinner,pr as is_slider,Gu as is_ok,Zr as is_new_combo,qr as is_hold,wu as is_err,Ur as is_circle,m as has_mod,z as get_speed_multiplier,Pr as get_rate_multiplier,c as get_mania_lane_color,J as get_combo_color,bu as get_available_mods,xr as get_adjusted_difficulty,L as err,Pu as apply_rate_to_ar,Bu as apply_mods_to_difficulty,Tr as VideoController,or as StandardRenderer,fu as SpeedChangingMods,Hr as SampleSet,Mr as PLAYFIELD_WIDTH,Dr as PLAYFIELD_HEIGHT,X as OszLoader,p as Mods,pu as ModNightcore,Ru as ModHidden,Rr as ModHardRock,Mu as ModHalfTime,Br as ModEasy,Hu as ModDoubleTime,fr as ManiaRenderer,j as HitSoundType,N as HitObjectType,Vu as HD_FADE_OUT_MULTIPLIER,Du as HD_FADE_IN_MULTIPLIER,zr as GridLevel,Ir as GameMode,Xr as ErrorCode,iu as DifficultyChangingMods,yr as DEFAULT_SKIN,v as DEFAULT_RENDERER_CONFIG,b as CanvasBackend,nu as BeatmapPlayer,E as BaseRenderer,hr as AudioController};
1
+ var Tr;((t)=>{t[t.Standard=0]="Standard";t[t.Taiko=1]="Taiko";t[t.Catch=2]="Catch";t[t.Mania=3]="Mania"})(Tr||={});var Hr;((t)=>{t[t.Auto=0]="Auto";t[t.Normal=1]="Normal";t[t.Soft=2]="Soft";t[t.Drum=3]="Drum"})(Hr||={});var J={Circle:1,Slider:2,NewCombo:4,Spinner:8,ComboSkip:112,Hold:128},i={Normal:1,Whistle:2,Finish:4,Clap:8},Xr=(r)=>(r.type&J.Circle)!==0,Vr=(r)=>(r.type&J.Slider)!==0,U=(r)=>(r.type&J.Spinner)!==0,mr=(r)=>(r.type&J.Hold)!==0,Ur=(r)=>(r.type&J.NewCombo)!==0;var Wr;((f)=>{f.NoOsuFiles="NO_OSU_FILES";f.DifficultyNotFound="DIFFICULTY_NOT_FOUND";f.InvalidBeatmap="INVALID_BEATMAP";f.UnsupportedMode="UNSUPPORTED_MODE";f.AudioNotLoaded="AUDIO_NOT_LOADED";f.AudioDecodeError="AUDIO_DECODE_ERROR";f.NotLoaded="NOT_LOADED";f.Unknown="UNKNOWN"})(Wr||={});var Yr=(r)=>({success:!0,data:r}),L=(r,u)=>({success:!1,code:r,reason:u}),ju=(r)=>{if(r.success)return r.data;throw Error(`[${r.code}] ${r.reason}`)},bu=(r)=>{return r.success},iu=(r)=>{return!r.success};var V={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},fu=V.DoubleTime|V.HalfTime|V.Nightcore,du=V.HardRock|V.Easy|fu,au=(r)=>{let u=0,n=r.toLowerCase(),s={nf:V.NoFail,ez:V.Easy,td:V.TouchDevice,hd:V.Hidden,hr:V.HardRock,sd:V.SuddenDeath,dt:V.DoubleTime,rx:V.Relax,ht:V.HalfTime,nc:V.Nightcore,fl:V.Flashlight,at:V.Autoplay,so:V.SpunOut,ap:V.Autopilot,pf:V.Perfect,fi:V.FadeIn,mr:V.Mirror};for(let t=0;t<n.length-1;t+=2){let e=n.slice(t,t+2);if(s[e])u|=s[e]}return u},_u=(r)=>{let u=[];if(r&V.NoFail)u.push("NF");if(r&V.Easy)u.push("EZ");if(r&V.Hidden)u.push("HD");if(r&V.HardRock)u.push("HR");if(r&V.SuddenDeath)u.push("SD");if(r&V.DoubleTime)u.push("DT");if(r&V.HalfTime)u.push("HT");if(r&V.Nightcore)u.push("NC");if(r&V.Flashlight)u.push("FL");if(r&V.SpunOut)u.push("SO");if(r&V.FadeIn)u.push("FI");if(r&V.Mirror)u.push("MR");let n=u.indexOf("DT"),s=u.indexOf("NC");if(n>=0&&s>=0)u.splice(n,1);return u.join("")},E=(r)=>{if(r&(V.DoubleTime|V.Nightcore))return 1.5;if(r&V.HalfTime)return 0.75;return 1},Iu=[V.HardRock|V.Easy,V.DoubleTime|V.HalfTime|V.Nightcore,V.Hidden|V.FadeIn],rn=(r,u)=>{if(r&u)return r&~u;let n=r;for(let s of Iu)if(u&s)n&=~s;return n|u},$=(r,u)=>(r&u)!==0,un=(r)=>{let u=[{name:"Easy",acronym:"EZ",value:V.Easy},{name:"Hidden",acronym:"HD",value:V.Hidden},{name:"Double Time",acronym:"DT",value:V.DoubleTime},{name:"Half Time",acronym:"HT",value:V.HalfTime},{name:"Nightcore",acronym:"NC",value:V.Nightcore}];switch(r){case"standard":return[...u,{name:"Hard Rock",acronym:"HR",value:V.HardRock}];case"mania":return[...u,{name:"Hard Rock",acronym:"HR",value:V.HardRock},{name:"Fade In",acronym:"FI",value:V.FadeIn}];case"taiko":case"catch":return[...u,{name:"Hard Rock",acronym:"HR",value:V.HardRock}];default:return u}};import zr from"jszip";import{init_wasm as Kr,parse as lr}from"@rel-packages/osu-beatmap-parser/browser";class W{async load_osz(r,u){await Kr();let n=await zr.loadAsync(r),s=new Map;for(let[t,e]of Object.entries(n.files))if(!e.dir)s.set(t,await e.async("arraybuffer"));return this.load_from_files(s,u)}async load_from_files(r,u){await Kr();let n=[...r.keys()].filter((R)=>R.toLowerCase().endsWith(".osu"));if(n.length===0)throw Error("No .osu files found in beatmap");let s=await Promise.all(n.map(async(R)=>{let P=r.get(R),F=this.to_bytes(P),S=await lr(F);return{filename:R,beatmap:S}})),t=this.select_difficulty(n,s,u?.difficulty),e=r.get(t),o=this.to_bytes(e),h=await lr(o),f=h.General.AudioFilename||null,I=h.Events.background?.filename||null,D=h.Events.video?.filename||null,T=h.Events.video?.startTime??0,H=new Map;for(let[R,P]of r)if(P instanceof ArrayBuffer)H.set(R,P);else H.set(R,new TextEncoder().encode(P).buffer);let M;if(f)M=this.find_file(H,f);let B;if(I){let R=this.find_file(H,I);if(R)B=new Blob([R])}let p;if(D){let R=this.find_file(H,D);if(R)p=new Blob([R])}return{beatmap:h,available_difficulties:s,files:H,audio:M,background:B,video:p,audio_filename:f??void 0,background_filename:I??void 0,video_filename:D??void 0,video_offset:D?T:void 0}}async list_difficulties(r){let u=await zr.loadAsync(r),n=[];for(let t of Object.keys(u.files))if(t.toLowerCase().endsWith(".osu"))n.push(t);let s=[];for(let t of n){let o=(await u.files[t].async("string")).match(/Version:\s*(.+)/);s.push(o?o[1].trim():t)}return s}select_difficulty(r,u,n){if(n===void 0)return r[0];if(typeof n==="number"){if(n<0||n>=r.length)throw Error(`Difficulty index ${n} out of range (0-${r.length-1})`);return r[n]}let s=u.find((o)=>o.beatmap.Metadata.Version===n);if(s)return s.filename;let t=n.toLowerCase(),e=u.find((o)=>o.filename.toLowerCase().includes(t)||o.beatmap.Metadata.Version.toLowerCase().includes(t));if(e)return e.filename;throw Error(`Difficulty "${n}" not found`)}find_file(r,u){if(r.has(u))return r.get(u);let n=u.toLowerCase();for(let[s,t]of r)if(s.toLowerCase()===n)return t;return}to_bytes(r){if(r instanceof ArrayBuffer)return new Uint8Array(r);return new TextEncoder().encode(r)}}import{init_wasm as nu,parse as Eu}from"@rel-packages/osu-beatmap-parser/browser";var Dr=512,pr=384,Er;((e)=>{e[e.None=0]="None";e[e.Large=32]="Large";e[e.Medium=16]="Medium";e[e.Small=8]="Small";e[e.Tiny=4]="Tiny"})(Er||={});var q={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};class Y{backend;skin;config;mods;beatmap;objects=[];background_image=null;constructor(r,u,n=0,s=q){this.backend=r,this.skin=u,this.mods=n,this.config={...q,...s}}set_background(r){this.background_image=r}update_config(r){this.config={...this.config,...r}}precompute(r=0){}on_seek(r){}dispose(){this.objects=[]}render_playfield(r,u,n,s){if(!this.config.show_playfield)return;let{backend:t,config:e}=this,o=r??512,h=u??384,f=n??0,I=s??0;t.save(),t.set_alpha(e.playfield_opacity),t.begin_path(),t.move_to(f,I),t.line_to(f+o,I),t.line_to(f+o,I+h),t.line_to(f,I+h),t.line_to(f,I),t.stroke_path(e.playfield_color,2),t.restore()}render_grid(){if(this.config.grid_level===0)return;let{backend:r,config:u}=this,n=u.grid_level;r.save(),r.set_alpha(u.grid_opacity);for(let s=0;s<=512;s+=n)r.begin_path(),r.move_to(s,0),r.line_to(s,384),r.stroke_path(u.grid_color,s%(n*4)===0?1:0.5);for(let s=0;s<=384;s+=n)r.begin_path(),r.move_to(0,s),r.line_to(512,s),r.stroke_path(u.grid_color,s%(n*4)===0?1:0.5);r.restore()}render_background(){if(!this.background_image)return;let{backend:r}=this;r.save(),r.set_alpha(0.3);let{width:u,height:n}=r,{width:s,height:t}=this.background_image;if(s>0&&t>0){let e=Math.max(u/s,n/t),o=s*e,h=t*e,f=(u-o)/2,I=(n-h)/2;r.draw_image(this.background_image,f,I,o,h)}else r.draw_image(this.background_image,0,0,u,n);r.restore()}get_visible_objects(r,u,n){let s=[];for(let t of this.objects){let e=t.time-u,o=t.end_time+n;if(r>=e&&r<=o)s.push(t)}return s}}class k{ctx;_width=0;_height=0;_dpr=1;is_initialized=!1;get width(){return this._width}get height(){return this._height}initialize(r,u=!0){this._dpr=u?window.devicePixelRatio||1:1;let n=r.clientWidth||r.width,s=r.clientHeight||r.height;this.apply_canvas_size(r,n,s);let t=r.getContext("2d",{alpha:!0,desynchronized:!0});if(!t)throw Error("Failed to get 2D context");this.ctx=t,this._width=n,this._height=s,this.configure_context(),this.is_initialized=!0}clear(){if(!this.is_initialized)return;this.ctx.save(),this.ctx.setTransform(this._dpr,0,0,this._dpr,0,0),this.ctx.clearRect(0,0,this._width,this._height),this.ctx.restore()}dispose(){}begin_frame(){}end_frame(){}resize(r,u){if(!this.is_initialized)return;this._width=r,this._height=u,this._dpr=window.devicePixelRatio||1;let n=this.ctx.canvas;this.apply_canvas_size(n,r,u),this.reset_transform(),this.configure_context()}draw_circle(r,u,n,s,t,e){let o=this.ctx;if(o.beginPath(),o.arc(r,u,n,0,Math.PI*2),s&&s!=="transparent")o.fillStyle=s,o.fill();if(t&&e&&e>0)o.strokeStyle=t,o.lineWidth=e,o.stroke()}draw_arc(r,u,n,s,t,e,o,h=!1){let f=this.ctx;f.beginPath(),f.arc(r,u,n,s,t,h),f.strokeStyle=e,f.lineWidth=o,f.stroke()}draw_rect(r,u,n,s,t){this.ctx.fillStyle=t,this.ctx.fillRect(r,u,n,s)}draw_rect_gradient(r,u,n,s,t){this.ctx.fillStyle=t,this.ctx.fillRect(r,u,n,s)}create_linear_gradient(r,u,n,s,t){let e=this.ctx.createLinearGradient(r,u,n,s);for(let o of t)e.addColorStop(o.offset,o.color);return e}draw_text(r,u,n,s,t,e="left",o="alphabetic"){let h=this.ctx;h.font=s,h.fillStyle=t,h.textAlign=e,h.textBaseline=o,h.fillText(r,u,n)}measure_text(r,u){let n=this.ctx,s=n.font;n.font=u;let t=n.measureText(r);return n.font=s,t}begin_path(){this.ctx.beginPath()}move_to(r,u){this.ctx.moveTo(r,u)}line_to(r,u){this.ctx.lineTo(r,u)}draw_line(r,u,n,s,t,e,o="butt",h="miter"){this.ctx.beginPath(),this.ctx.moveTo(r,u),this.ctx.lineTo(n,s),this.ctx.strokeStyle=t,this.ctx.lineWidth=e,this.ctx.lineCap=o,this.ctx.lineJoin=h,this.ctx.stroke()}bezier_curve_to(r,u,n,s,t,e){this.ctx.bezierCurveTo(r,u,n,s,t,e)}quadratic_curve_to(r,u,n,s){this.ctx.quadraticCurveTo(r,u,n,s)}arc_to(r,u,n,s,t,e){this.ctx.arc(r,u,n,s,t,e)}rect(r,u,n,s){this.ctx.rect(r,u,n,s)}clip(){this.ctx.clip()}stroke_path(r,u,n="butt",s="miter"){let t=this.ctx;t.strokeStyle=r,t.lineWidth=u,t.lineCap=n,t.lineJoin=s,t.stroke()}fill_path(r){this.ctx.fillStyle=r,this.ctx.fill()}close_path(){this.ctx.closePath()}save(){this.ctx.save()}restore(){this.ctx.restore()}translate(r,u){this.ctx.translate(r,u)}scale(r,u){this.ctx.scale(r,u)}rotate(r){this.ctx.rotate(r)}set_alpha(r){this.ctx.globalAlpha=r}set_shadow(r,u){this.ctx.shadowColor=r,this.ctx.shadowBlur=u}set_composite_operation(r){this.ctx.globalCompositeOperation=r}set_blend_mode(r){let u={normal:"source-over",lighter:"lighter",multiply:"multiply",screen:"screen"};this.ctx.globalCompositeOperation=u[r]??"source-over"}draw_image(r,u,n,s,t){if(s!==void 0&&t!==void 0)this.ctx.drawImage(r.source,u,n,s,t);else this.ctx.drawImage(r.source,u,n)}draw_image_part(r,u,n,s,t,e,o,h,f){this.ctx.drawImage(r.source,u,n,s,t,e,o,h,f)}render_slider_to_image(r,u,n,s,t,e=1,o=1){let h=1/0,f=1/0,I=-1/0,D=-1/0;for(let F of r){if(F[0]<h)h=F[0];if(F[0]>I)I=F[0];if(F[1]<f)f=F[1];if(F[1]>D)D=F[1]}let T=u+2;h-=T,f-=T,I+=T,D+=T;let H=Math.ceil((I-h)*t),M=Math.ceil((D-f)*t);if(H<=0||M<=0)return null;let B=document.createElement("canvas");B.width=H,B.height=M;let p=B.getContext("2d");if(!p)return null;p.save(),p.scale(t,t),p.translate(-h,-f);let R=()=>{if(p.beginPath(),r.length>0){p.moveTo(r[0][0],r[0][1]);for(let F=1;F<r.length;F++)p.lineTo(r[F][0],r[F][1])}};p.lineCap="round",p.lineJoin="round",p.globalAlpha=o,p.strokeStyle=n,p.lineWidth=u*2,R(),p.stroke();let P=u*0.872;if(e<1)p.globalCompositeOperation="destination-out",p.globalAlpha=1,p.lineWidth=P*2,R(),p.stroke(),p.globalCompositeOperation="source-over";return p.globalAlpha=e,p.strokeStyle=s,p.lineWidth=P*2,R(),p.stroke(),p.restore(),{source:B,width:H,height:M,min_x:h,min_y:f}}apply_canvas_size(r,u,n){r.width=u*this._dpr,r.height=n*this._dpr,r.style.width=`${u}px`,r.style.height=`${n}px`}configure_context(){this.ctx.scale(this._dpr,this._dpr),this.ctx.imageSmoothingEnabled=!0,this.ctx.imageSmoothingQuality="high"}reset_transform(){if(this.ctx.resetTransform)this.ctx.resetTransform();else this.ctx.setTransform(1,0,0,1,0,0)}}var Mr={min:1800,mid:1200,max:450};var Tu=(r,u)=>{if(r>5)return u.mid+(u.max-u.mid)*(r-5)/5;if(r<5)return u.mid+(u.mid-u.min)*(r-5)/5;return u.mid},Gr=(r,u)=>{if(Math.sign(r-u.mid)===Math.sign(u.max-u.mid))return(r-u.mid)/(u.max-u.mid)*5+5;return(r-u.mid)/(u.mid-u.min)*5+5},d=(r)=>Tu(r,Mr),wr=(r)=>400*Math.min(1,r/450),Hu=(r)=>{return(1-0.7*((r-5)/5))/2},xr=(r)=>Hu(r)*64;var Br={name:"Hard Rock",acronym:"HR",apply_to_difficulty(r){r.cs=Math.min(r.cs*1.3,10),r.ar=Math.min(r.ar*1.4,10),r.od=Math.min(r.od*1.4,10),r.hp=Math.min(r.hp*1.4,10)}};var Rr={name:"Easy",acronym:"EZ",apply_to_difficulty(r){r.cs*=0.5,r.ar*=0.5,r.od*=0.5,r.hp*=0.5}};var Vu={name:"Double Time",acronym:"DT",get_rate_multiplier:()=>1.5},Du={name:"Nightcore",acronym:"NC",get_rate_multiplier:()=>1.5};var pu={name:"Half Time",acronym:"HT",get_rate_multiplier:()=>0.75};var Mu=0.4,Bu=0.3,Ru={name:"Hidden",acronym:"HD"};var Pr=(r)=>{if(r&(V.DoubleTime|V.Nightcore))return 1.5;if(r&V.HalfTime)return 0.75;return 1},Pu=(r,u)=>{if(u&V.Easy)Rr.apply_to_difficulty(r);if(u&V.HardRock)Br.apply_to_difficulty(r)},yu=(r,u)=>{if(u===1)return r;let n=d(r)/u;return Gr(n,Mr)},cr=(r,u,n,s,t)=>{let e={cs:r,ar:u,od:n,hp:s};Pu(e,t);let o=Pr(t);return e.ar=yu(e.ar,o),e};var gr=(r,u)=>[r[0]+u[0],r[1]+u[1]],O=(r,u)=>[r[0]-u[0],r[1]-u[1]],jr=(r,u)=>[r[0]*u,r[1]*u];var Q=(r)=>Math.sqrt(r[0]*r[0]+r[1]*r[1]);var z=(r,u,n)=>r+(u-r)*n,v=(r,u,n)=>[z(r[0],u[0],n),z(r[1],u[1],n)],y=(r,u,n)=>Math.min(n,Math.max(u,r));var yr={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"]},Fr={combo_colors:["0,185,0","7, 105, 227","224, 4, 38","227, 171, 2"],circle_border_width:0.12,hit_circle_opacity:0.95,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,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,mania_lane_width:30,mania_note_height:15,mania_hit_position:364,mania_lane_spacing:1,mania_lane_colors:yr,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},a=(r)=>{if(!r)return{...Fr};return{...Fr,...r,mania_lane_colors:r.mania_lane_colors?{...yr,...r.mania_lane_colors}:yr}},Z=(r,u,n=1)=>{return`rgba(${r.combo_colors[u%r.combo_colors.length]},${n})`},G=(r,u,n)=>{let s=r.mania_lane_colors[u]??r.mania_lane_colors[4];return s[n%s.length]??"#ffffff"};var C={None:(r)=>r,Out:(r)=>1-Math.pow(1-r,2),In:(r)=>r*r,InOut:(r)=>r<0.5?2*r*r:1-Math.pow(-2*r+2,2)/2,OutCubic:(r)=>1-Math.pow(1-r,3),InCubic:(r)=>r*r*r,OutQuad:(r)=>1-Math.pow(1-r,2),InQuad:(r)=>r*r,OutQuint:(r)=>1-Math.pow(1-r,5),InQuint:(r)=>r*r*r*r*r,OutElastic:(r)=>{let u=2*Math.PI/3;return r===0?0:r===1?1:Math.pow(2,-10*r)*Math.sin((r*10-0.75)*u)+1}};class $r{transforms=[];add(r,u,n,s,t,e=C.None){return this.transforms.push({property:r,start_value:u,end_value:n,start_time:s,end_time:s+t,easing:e}),this}then(){return this}get_value(r,u,n){let s=n;for(let t of this.transforms){if(t.property!==r)continue;if(u<t.start_time)continue;if(u>=t.end_time)s=t.end_value;else{let e=(u-t.start_time)/(t.end_time-t.start_time),o=t.easing(e);s=t.start_value+(t.end_value-t.start_value)*o}}return s}clear(){this.transforms=[]}}class K{backend;skin;hit_object;config;alpha=1;scale=1;rotation=0;x=0;y=0;armed_state=0;transforms=new $r;life_time_start=0;life_time_end=0;constructor(r,u){this.hit_object=r,this.config=u,this.backend=u.backend,this.skin=u.skin;let n=r.data;this.x=n.pos[0],this.y=n.pos[1],this.apply_defaults()}apply_defaults(){let{hit_object:r,config:u}=this,n=r.time-u.preempt;this.life_time_start=n,this.life_time_end=r.end_time+800}is_alive(r){return r>=this.life_time_start&&r<=this.life_time_end}update(r){this.alpha=this.transforms.get_value("alpha",r,1),this.scale=this.transforms.get_value("scale",r,1),this.rotation=this.transforms.get_value("rotation",r,0),this.update_state(r)}update_state(r){if(this.armed_state===0&&r>=this.hit_object.time)this.armed_state=1,this.on_hit(r)}on_hit(r){}render_body_pass(r){}render_head_pass(r){}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]}}class w{state={circle_alpha:0,circle_scale:1,number_alpha:1};update(r,u,n){let s=u-n.preempt;if(r<s){this.reset_pre_hit_state();return}if(r<u){this.update_pre_hit(r,s,u,n);return}let t=_(u,s,u,n);this.update_post_hit(r,u,n,t)}render(r,u,n,s,t,e){let{circle_alpha:o,circle_scale:h,number_alpha:f}=this.state;if(o<=0.01)return;let I=s*h;if(o>0.01){let D=s*u.circle_border_width,T=s*(1-u.circle_border_width/2)*h;if(r.set_alpha(o*u.hit_circle_opacity),r.draw_circle(n[0],n[1],T,t,"rgba(255,255,255,1)",D),f>0.01){let H=s*0.7*h;r.set_alpha(f*u.hit_circle_opacity);let M=u.default_font??'"Trebuchet MS", Verdana, Arial, sans-serif',B=`600 ${H}px ${M}`;r.draw_text(String(e),n[0],n[1],B,"rgba(255,255,255,1)","center","middle")}r.set_alpha(1)}r.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(r,u,n,s){let t=_(r,u,n,s);this.state.circle_alpha=t,this.state.circle_scale=1,this.state.number_alpha=t}update_post_hit(r,u,n,s){let t=r-u,{skin:e}=n,o=Math.max(90,e.hit_animation_duration*0.75),h=y(t/o,0,1),f=$(n.mods,V.Hidden)?y(s,0,1):y(Math.max(s,0.25),0,1);this.state.circle_alpha=f*(1-C.OutQuad(h));let I=Math.max(90,o*0.85),D=y(t/I,0,1);this.state.circle_scale=z(1,e.hit_animation_scale,C.OutCubic(D)),this.state.number_alpha=this.state.circle_alpha}}var _=(r,u,n,s)=>{let e=y((r-u)/s.fade_in,0,1);if($(s.mods,V.Hidden)){let o=n-s.preempt+s.fade_in,h=s.preempt*0.3;if(r>o){let f=y((r-o)/h,0,1);e*=1-f}}return e};class Cr{state={alpha:0,scale:1};update(r,u,n){if(!n.skin.enable_hitburst){this.state.alpha=0,this.state.scale=1;return}if(r<u){this.state.alpha=0,this.state.scale=1;return}let s=u-n.preempt,t=_(u,s,u,n),e=$(n.mods,V.Hidden)?y(t,0,1):y(Math.max(t,0.25),0,1),o=r-u,h=Math.max(70,n.skin.hitburst_duration),f=y(o/h,0,1),I=1-C.OutQuint(f);this.state.alpha=$(n.mods,V.Hidden)?I*e:I,this.state.scale=z(1,n.skin.hitburst_scale,C.OutCubic(f))}render(r,u,n,s,t){if(!u.enable_hitburst)return;if(this.state.alpha<=0.01)return;if(r.set_alpha(this.state.alpha),r.draw_circle(n[0],n[1],s*this.state.scale,"rgba(255,255,255,1)","transparent",0),u.hitburst_glow_enabled){r.save(),r.set_blend_mode("lighter"),r.set_alpha(this.state.alpha*u.hitburst_glow_opacity);let e=u.hitburst_glow_use_combo_color?t:u.hitburst_glow_color??t;r.draw_circle(n[0],n[1],s*this.state.scale*1.08,e,"transparent",0),r.restore()}}}class rr extends K{visual=new w;hitburst=new Cr;constructor(r,u){super(r,u)}update(r){super.update(r),this.visual.update(r,this.hit_object.time,this.config),this.hitburst.update(r,this.hit_object.time,this.config)}render(r){let{backend:u,skin:n,config:s}=this,{radius:t}=s,e=this.position,o=Z(n,this.combo_number,1);this.visual.render(u,n,e,t,o,this.combo_count),this.hitburst.render(u,n,e,t,o)}}var ur=(r)=>{let{start_time:u,span_duration:n,span_count:s,length:t,tick_distance:e,min_distance_from_end:o,get_position_at_progress:h}=r,f=[],I=[];if(t<=0||n<=0||s<=0)return{ticks:f,repeats:I};let T=Math.min(1e5,t),H=Math.min(Math.max(e,0),T),M=Math.max(0,Math.min(o,T));for(let B=0;B<s;B++){let p=u+B*n,R=B%2===1;if(H>0){let P=Fu(B,p,n,R,T,H,M,h);if(R)P.reverse();f.push(...P)}if(B<s-1){let P=(B+1)%2;I.push({pos:h(P),time:p+n,repeat_index:B,path_progress:P})}}return f.sort((B,p)=>B.time-p.time),{ticks:f,repeats:I}},Fu=(r,u,n,s,t,e,o,h)=>{let f=[];for(let I=e;I<=t;I+=e){if(I>=t-o)break;let D=I/t,T=s?1-D:D;f.push({pos:h(D),time:u+T*n,span_index:r,path_progress:D})}return f};var Sr=240,Nr=1.3,Ar=35,$u=250,Cu=300,x=150,Su=x*4;class l extends K{slider_data;position_path;render_path;path_length;span_duration;body_alpha=0;head_visual=new w;ball_alpha=0;ball_position;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=[];constructor(r,u,n,s,t,e){super(r,u);this.slider_data=r.data;let o=Math.max(1,u.radius*0.05);this.position_path=n,this.render_path=this.resample_path(n,o),this.span_duration=s,this.tick_distance=t,this.min_distance_from_end=e;let h=this.calculate_path_length();this.path_length=this.slider_data.distance>0?this.slider_data.distance:h,this.ball_position=this.slider_data.pos,this.build_nested_objects(),this.life_time_end=r.end_time+Sr}build_nested_objects(){let{slider_data:r,path_length:u,span_duration:n,hit_object:s}=this,t=Math.max(1,r.repetitions),e=1e5,o=Math.min(1e5,r.distance>0?r.distance:u),h=y(this.tick_distance,0,o);if(o<=0||n<=0){this.ticks=[],this.repeats=[];return}let f=ur({start_time:s.time,span_duration:n,span_count:t,length:o,tick_distance:h,min_distance_from_end:this.min_distance_from_end,get_position_at_progress:(I)=>this.get_position_at_progress(I)});this.ticks=f.ticks,this.repeats=f.repeats,this.build_tick_entries()}calculate_path_length(){let r=0;for(let u=1;u<this.position_path.length;u++)r+=Q(O(this.position_path[u],this.position_path[u-1]));return r}resample_path(r,u){if(r.length<2)return r.slice();let n=[r[0]],s=0,t=[];for(let D=1;D<r.length;D++){let T=Q(O(r[D],r[D-1]));t.push(T),s+=T}if(s<=0)return n;let e=u,o=0,h=0;while(e<s&&h<t.length){let D=t[h],T=r[h],H=r[h+1];if(D>0&&o+D>=e){let M=(e-o)/D;n.push(v(T,H,M)),e+=u}else o+=D,h++}let f=r[r.length-1],I=n[n.length-1];if(I[0]!==f[0]||I[1]!==f[1])n.push(f);return n}update(r){super.update(r),this.calculate_ball_position(r),this.calculate_opacities(r),this.head_visual.update(r,this.hit_object.time,this.config)}calculate_ball_position(r){let{hit_object:u,span_duration:n}=this,s=300,t=300,e=2.4;if(r<u.time){this.ball_alpha=0,this.follow_alpha=0,this.follow_scale=1;return}if(r<=u.end_time){let I=r-u.time,D=Math.max(1,this.slider_data.repetitions),T=Math.min(Math.floor(I/n),D-1),H=y((I-T*n)/n,0,1),M=T%2===1?1-H:H;this.ball_position=this.get_position_at_progress(M),this.ball_alpha=1;let B=y(I/300,0,1),p=C.OutQuint(B);this.follow_alpha=p,this.follow_scale=1+1.4*p;return}let o=r-u.end_time,h=y(o/300,0,1),f=C.OutQuint(h);this.ball_alpha=1-f,this.follow_alpha=1-f,this.follow_scale=2.4-1.4*f}get_position_at_progress(r){let u=r*this.path_length;return this.get_position_at_length(u)}get_position_at_length(r){let u=0;for(let n=1;n<this.position_path.length;n++){let s=Q(O(this.position_path[n],this.position_path[n-1]));if(u+s>=r){let t=(r-u)/s;return v(this.position_path[n-1],this.position_path[n],t)}u+=s}return this.position_path[this.position_path.length-1]}calculate_opacities(r){let{hit_object:u,config:n}=this,s=u.time-n.preempt,t=u.time;if($(n.mods,V.Hidden)){let e=t-n.preempt+n.fade_in;if(r<s)this.body_alpha=0;else if(r<e)this.body_alpha=y((r-s)/n.fade_in,0,1);else if(r<=u.end_time){let o=Math.max(1,u.end_time-e);this.body_alpha=1-y((r-e)/o,0,1)}else this.body_alpha=0}else if(r<s)this.body_alpha=0;else if(r<t)this.body_alpha=y((r-s)/n.fade_in,0,1);else if(r<=u.end_time)this.body_alpha=1;else this.body_alpha=1-y((r-u.end_time)/Sr,0,1)}render(r){if(this.body_alpha<=0&&this.head_visual.circle_alpha<=0&&this.ball_alpha<=0)return;this.render_body(r),this.render_head(),this.render_ball(r)}render_body_pass(r){this.render_body(r)}render_head_pass(r){this.render_head(),this.render_reverse_arrows(r),this.render_ball(r)}render_body(r){if(this.body_alpha<=0.01||this.render_path.length<2)return;let{backend:u}=this;if(this.prepare_body_cache(),this.cached_texture&&this.cached_texture.min_x!==void 0&&this.cached_texture.min_y!==void 0){let n=this.cached_scale;u.set_alpha(this.body_alpha),u.draw_image(this.cached_texture,this.cached_texture.min_x,this.cached_texture.min_y,this.cached_texture.width/n,this.cached_texture.height/n),u.set_alpha(1)}this.render_ticks(r)}prepare_body_cache(){if(this.render_path.length<2)return;let{backend:r,skin:u,config:n}=this,{radius:s}=n,t=(n.scale??1)*(u.slider_render_scale||1);if(!this.cached_texture||this.cached_scale!==t){let e=Z(u,this.combo_number,1),o=u.slider_border_color??"rgba(255,255,255,1)",h=t;this.cached_texture=r.render_slider_to_image(this.render_path,s,o,e,h,u.slider_body_opacity,u.slider_border_opacity),this.cached_scale=t}}has_body_cache(){return this.cached_texture!=null}release_body_cache(){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(){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=[]}render_ticks(r){if(this.tick_entries_by_start.length===0)return;let{backend:u,config:n,hit_object:s}=this,{radius:t}=n,e=t*0.12,o=s.time-n.preempt,h=$(n.mods,V.Hidden);for(let f of this.tick_entries_by_start){let I=f.tick,D=r-f.appear_time;if(D<0)continue;if(f.visible_end<r)continue;let T=y(D/x,0,1);if(h&&f.preempt>0){let R=Math.min(f.preempt-x,1000);if(R>0){let P=I.time-R;if(r>=P){let F=y((r-P)/R,0,1);T*=1-F}}}else if(r>I.time){let R=y((r-I.time)/x,0,1);T*=1-R}T*=this.body_alpha;let H=y(D/Su,0,1),B=0.5+0.5*this.ease_out_elastic_half(H),p=e*B;if(T>0.01)u.set_alpha(T),u.draw_circle(I.pos[0],I.pos[1],p,"rgba(255,255,255,0.8)","transparent",0)}u.set_alpha(1)}build_tick_entries(){let{hit_object:r,config:u}=this,n=r.time-u.preempt,s=$(u.mods,V.Hidden);this.tick_entries=this.ticks.map((t)=>{let e=r.time+t.span_index*this.span_duration,o=u.preempt,h=t.span_index>0?200:o*0.66,f=(t.time-e)/2+h,I=t.time-f,D=s?t.time:t.time+x;return{tick:t,appear_time:I,visible_end:D,preempt:f}}),this.tick_entries_by_start=[...this.tick_entries].sort((t,e)=>t.appear_time-e.appear_time)}ease_out_elastic_half(r){if(r<=0)return 0;if(r>=1)return 1;let u=0.3;return Math.pow(2,-10*r)*Math.sin((r-u/4)*(2*Math.PI)/u)+1}render_reverse_arrows(r){if(this.repeats.length===0)return;let{backend:u,config:n,hit_object:s,span_duration:t}=this,{radius:e}=n,o=e*0.6;for(let h of this.repeats){let f=n.preempt;if(h.repeat_index>0)f=t*2;else f+=s.time-(s.time-n.preempt);let I=h.time-f,D=h.repeat_index%2===0;if(r<I||r>h.time+Sr)continue;let T=this.body_alpha*0.9;if(h.repeat_index===0){let P=y((r-I)/150,0,1);T*=C.OutQuint(P)}else if(r<I)T=0;if(r>h.time){let P=Math.min(300,t);T*=1-y((r-h.time)/P,0,1)}if(T<=0.01)continue;let H=this.position_path,M;if(D){let P=H.length-1;M=H[0];for(let F=P;F>=0;F--)if(Math.abs(H[F][0]-h.pos[0])>0.01||Math.abs(H[F][1]-h.pos[1])>0.01){M=H[F];break}}else{M=H[H.length-1];for(let P=0;P<H.length;P++)if(Math.abs(H[P][0]-h.pos[0])>0.01||Math.abs(H[P][1]-h.pos[1])>0.01){M=H[P];break}}let B=Math.atan2(M[1]-h.pos[1],M[0]-h.pos[0]),p=1;if(r<h.time){let P=s.time-n.preempt,F=(r-P)%Cu;if(F<Ar)p=1+(Nr-1)*C.Out(F/Ar);else{let S=(F-Ar)/$u;p=Nr-(Nr-1)*C.Out(y(S,0,1))}}else{let P=Math.min(300,t),F=y((r-h.time)/P,0,1);p=1+0.5*C.Out(F)}let R=o*p;u.save(),u.set_alpha(T),u.translate(h.pos[0],h.pos[1]),u.rotate(B),u.begin_path(),u.move_to(R*0.8,0),u.line_to(-R*0.4,-R*0.5),u.line_to(-R*0.4,R*0.5),u.close_path(),u.fill_path("rgba(255,255,255,0.9)"),u.restore()}}render_head(){if(this.head_visual.circle_alpha<=0.01)return;let{backend:r,skin:u,config:n}=this,{radius:s}=n,t=this.slider_data.pos,e=Z(u,this.combo_number,1);this.head_visual.render(r,u,t,s,e,this.combo_count)}render_ball(r){if(this.ball_alpha<=0.01&&this.follow_alpha<=0.01)return;let{backend:u,skin:n,config:s}=this,{radius:t}=s,e=this.ball_position,o=Z(n,this.combo_number,0.9);if(this.follow_alpha>0.01){let h=t*this.follow_scale;u.set_alpha(this.follow_alpha*n.follow_circle_opacity),u.begin_path(),u.arc_to(e[0],e[1],h,0,Math.PI*2),u.stroke_path(n.follow_circle_color,n.follow_circle_width)}if(n.enable_slider_ball&&this.ball_alpha>0.01)u.set_alpha(this.ball_alpha*n.slider_ball_opacity),u.draw_circle(e[0],e[1],t*0.85,o,"rgba(255,255,255,0.9)",t*0.1);u.set_alpha(1)}}class Or{skin;mods;preempt;fade_in;radius;points=[];lines=[];constructor(r,u,n,s,t){this.skin=r,this.mods=u,this.preempt=n,this.fade_in=s,this.radius=t}update_settings(r,u,n,s){this.mods=r,this.preempt=u,this.fade_in=n,this.radius=s}build(r){this.points=[],this.lines=[];let u=32,n=Math.max(450,this.preempt*0.9);for(let s=0;s<r.length-1;s++){let t=r[s],e=r[s+1];if(U(t)||U(e))continue;if(t.combo_number!==e.combo_number)continue;let o=t.end_pos,h=e.data.pos,f=h[0]-o[0],I=h[1]-o[1],D=Math.sqrt(f*f+I*I);if(D<u*1.5)continue;let T=t.end_time,H=e.time-T;if(H<=0)continue;let M=D>0?1/D:0,B=[f*M,I*M],p=T-n,R=e.time-n,P=T+(R-T)*0.5,F=e.time;if($(this.mods,V.Hidden))P=T+(R-T)*0.3,F=T+(e.time-T)*0.65;this.lines.push({start_pos:o,end_pos:h,dir:B,start_time:T,end_time:e.time,appear_time:p,grow_end_time:R,shrink_start_time:P,shrink_end_time:F});for(let S=u*1.5;S<D-u;S+=u){let A=S/D,N=t.end_time+A*H,m=Math.max(t.end_time,N-n);if($(this.mods,V.Hidden))N=Math.min(N,T+H*0.65);let j=[o[0]+(A-0.1)*f,o[1]+(A-0.1)*I],b=[o[0]+A*f,o[1]+A*I];this.points.push({start_pos:j,end_pos:b,dir:B,fade_in_time:m,fade_out_time:N})}}}render(r,u,n){let s=this.skin.follow_point_shape,t=this.skin.follow_point_mode??"segments",e=this.skin.follow_point_length||this.radius*0.6,o=y(this.skin.follow_point_line_gap??0,0,0.9),h=Math.max(this.fade_in*0.15,50),f=0.2;if(t==="full")for(let I of this.lines){if(r<I.appear_time||r>I.shrink_end_time)continue;let D=0,T=I.start_pos[0],H=I.start_pos[1],M=I.end_pos[0],B=I.end_pos[1],p=Math.hypot(M-T,B-H),R=this.get_alpha_gate(r,I.start_time,I.end_time,n);if(R<=0.01)continue;let P=this.radius*1.05,F=Math.min(P,p*0.22);if(T+=I.dir[0]*F,H+=I.dir[1]*F,M-=I.dir[0]*F,B-=I.dir[1]*F,r<I.grow_end_time){let S=Math.max(1,I.grow_end_time-I.appear_time),A=y((r-I.appear_time)/S,0,1),N=C.OutQuint(A);D=N,M=T+(M-T)*N,B=H+(B-H)*N}else if(r<I.shrink_start_time)D=1;else{let S=Math.max(1,I.shrink_end_time-I.shrink_start_time),A=y((r-I.shrink_start_time)/S,0,1),N=C.InQuint(A);D=1,T=T+(M-T)*N,H=H+(B-H)*N}if(D<=0)continue;if(u.set_alpha(D*0.2*R),s==="line")if(o>0){let S=Math.hypot(M-T,B-H),A=I.dir[0],N=I.dir[1],m=S*o/2,j=(T+M)/2,b=(H+B)/2,tu=j-A*m,eu=b-N*m,ou=j+A*m,hu=b+N*m;u.draw_line(T,H,tu,eu,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round"),u.draw_line(ou,hu,M,B,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else u.draw_line(T,H,M,B,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round");else{let S=this.radius*0.12,A=(I.start_pos[0]+I.end_pos[0])/2,N=(I.start_pos[1]+I.end_pos[1])/2;u.draw_circle(A,N,S,"rgba(255,255,255,1)","transparent",0)}}else for(let I of this.points){if(r<I.fade_in_time||r>I.fade_out_time+h)continue;let D=0,T=1,H=I.end_pos;if(r<I.fade_in_time+h){let B=y((r-I.fade_in_time)/h,0,1),p=C.OutCubic(B);D=p,T=1.5-0.5*p,H=v(I.start_pos,I.end_pos,p)}else if(r<=I.fade_out_time)D=1,T=1,H=I.end_pos;else{let B=y((r-I.fade_out_time)/h,0,1),p=C.OutCubic(B);D=1-p,T=1,H=v(I.start_pos,I.end_pos,1-p)}if(D<=0)continue;let M=this.get_alpha_gate(r,I.fade_in_time+this.preempt,I.fade_out_time,n);if(M<=0.01)continue;if(u.set_alpha(D*0.2*M),s==="line"){let p=e*T/2,R=I.dir[0],P=I.dir[1],F=H[0]-R*p,S=H[1]-P*p,A=H[0]+R*p,N=H[1]+P*p;u.draw_line(F,S,A,N,"rgba(255,255,255,1)",this.skin.follow_point_width,"round","round")}else{let B=this.radius*0.12*T;u.draw_circle(H[0],H[1],B,"rgba(255,255,255,1)","transparent",0)}}u.set_alpha(1)}get_alpha_gate(r,u,n,s){let t=s(r,u),e=s(r,n);return y(Math.min(t,e)/0.7,0,1)}}var Jr=(r,u=0.08)=>{if(r.length<2)return[...r];let n=[];return Qr(r,n,u),n},Qr=(r,u,n)=>{if(Nu(r,n)){if(u.length===0)u.push(r[0]);u.push(r[r.length-1]);return}let s=[],t=[];Ou(r,s,t),Qr(s,u,n),Qr(t,u,n)},Nu=(r,u)=>{if(r.length<=2)return!0;let n=r[0],s=r[r.length-1];for(let t=1;t<r.length-1;t++)if(Au(r[t],n,s)>u)return!1;return!0},Au=(r,u,n)=>{let s=O(n,u),t=s[0]*s[0]+s[1]*s[1];if(t===0)return Q(O(r,u));let e=Math.max(0,Math.min(1,((r[0]-u[0])*s[0]+(r[1]-u[1])*s[1])/t)),o=[u[0]+e*s[0],u[1]+e*s[1]];return Q(O(r,o))},Ou=(r,u,n)=>{let s=r.length,t=[r];for(let e=1;e<s;e++){t[e]=[];for(let o=0;o<s-e;o++)t[e][o]=v(t[e-1][o],t[e-1][o+1],0.5)}for(let e=0;e<s;e++)u.push(t[e][0]),n.push(t[s-1-e][e])},Lr=(r,u,n)=>{let s=O(u,r),t=Q(s);if(t===0)return[r];let e=[s[0]/t,s[1]/t],o=gr(r,jr(e,n));return[r,o]},br=(r,u)=>{if(r.length!==3)return Jr(r);let[n,s,t]=r,e=Qu(n,s,t);if(!e)return Lr(n,t,u);let o=Q(O(n,e)),h=Math.atan2(n[1]-e[1],n[0]-e[0]),f=Math.atan2(t[1]-e[1],t[0]-e[0]),D=(s[0]-n[0])*(t[1]-n[1])-(s[1]-n[1])*(t[0]-n[0])>0,T=f-h;if(D&&T<0)T+=2*Math.PI;if(!D&&T>0)T-=2*Math.PI;let H=Math.abs(T)*o,M=2;if(o*2>0.1){let p=Math.abs(T),R=2*Math.acos(1-0.1/o);if(M=Math.max(2,Math.ceil(p/R)),M>=1000)M=1000}let B=[];for(let p=0;p<=M;p++){let R=p/M,P=h+T*R;B.push([e[0]+o*Math.cos(P),e[1]+o*Math.sin(P)])}return B},Qu=(r,u,n)=>{let s=2*(r[0]*(u[1]-n[1])+u[0]*(n[1]-r[1])+n[0]*(r[1]-u[1]));if(Math.abs(s)<0.001)return null;let t=((r[0]*r[0]+r[1]*r[1])*(u[1]-n[1])+(u[0]*u[0]+u[1]*u[1])*(n[1]-r[1])+(n[0]*n[0]+n[1]*n[1])*(r[1]-u[1]))/s,e=((r[0]*r[0]+r[1]*r[1])*(n[0]-u[0])+(u[0]*u[0]+u[1]*u[1])*(r[0]-n[0])+(n[0]*n[0]+n[1]*n[1])*(u[0]-r[0]))/s;return[t,e]},ir=(r)=>{if(r.length<2)return[...r];let u=[];for(let n=0;n<r.length-1;n++){let s=r[Math.max(0,n-1)],t=r[n],e=r[n+1],o=r[Math.min(r.length-1,n+2)],h=Q(O(e,t)),f=Math.max(8,Math.ceil(h/3));for(let I=0;I<=f;I++){let D=I/f;u.push(Ju(s,t,e,o,D))}}return u},Ju=(r,u,n,s,t)=>{let e=t*t,o=e*t;return[0.5*(2*u[0]+(-r[0]+n[0])*t+(2*r[0]-5*u[0]+4*n[0]-s[0])*e+(-r[0]+3*u[0]-3*n[0]+s[0])*o),0.5*(2*u[1]+(-r[1]+n[1])*t+(2*r[1]-5*u[1]+4*n[1]-s[1])*e+(-r[1]+3*u[1]-3*n[1]+s[1])*o)]};var kr=(r)=>{let u;if(r.path_type==="L")u=Lr(r.pos,r.control_points[0],r.distance);else{let n=[r.pos,...r.control_points];switch(r.path_type){case"P":u=br(n,r.distance);break;case"C":u=ir(n);break;default:u=Lu(n);break}}return vu(u,r.distance)},dr=(r)=>{if(!r.computed_path||r.computed_path.length===0)return r.pos;return r.repetitions%2===0?r.pos:r.computed_path[r.computed_path.length-1]},Lu=(r)=>{let u=[],n=[r[0]];for(let t=1;t<r.length;t++){let[e,o]=[r[t-1],r[t]];if(e[0]===o[0]&&e[1]===o[1]){if(n.length>1)u.push(n);n=[o]}else n.push(o)}if(n.length>1)u.push(n);let s=[];for(let t of u)s.push(...Jr(t));return s},vu=(r,u)=>{if(r.length<2)return r;let n=[r[0]],s=0,t=null,e=!1;for(let o=1;o<r.length;o++){let h=Q(O(r[o],r[o-1])),f=O(r[o],r[o-1]);if(h>0)t=[f[0]/h,f[1]/h];if(h===0)continue;if(s+h>=u){let I=u-s;n.push(v(r[o-1],r[o],I/h)),s=u,e=!0;break}s+=h,n.push(r[o])}if(!e&&s<u&&t){let o=u-s,h=n[n.length-1];n.push([h[0]+t[0]*o,h[1]+t[1]*o])}return n};var nr=(r,u,n)=>{if(r<=0)return 0;let s=u.Difficulty.SliderMultiplier;return r*n.base_beat_length/(100*s*n.sv_multiplier)},sr=(r,u)=>{let n=u.sv_multiplier||1,s=r.Difficulty.SliderMultiplier,t=r.Difficulty.SliderTickRate,e=100*s*n,o=r.version<8?1/n:1,h=e/t*o,f=e/u.base_beat_length;return{tick_distance:h,min_distance_from_end:f*10}};class c{points;index=0;last_time=Number.NEGATIVE_INFINITY;base_beat_length=600;sv_multiplier=1;constructor(r){if(this.points=r,r.length>0&&r[0].uninherited===1&&r[0].beatLength>0)this.base_beat_length=r[0].beatLength}reset(){this.index=0,this.last_time=Number.NEGATIVE_INFINITY,this.base_beat_length=600,this.sv_multiplier=1}get_state_at(r){if(this.points.length===0)return{base_beat_length:600,sv_multiplier:1};if(r<this.last_time)this.reset();for(let u=this.index;u<this.points.length;u++){let n=this.points[u];if(n.time>r)break;if(n.uninherited===1&&n.beatLength>0)this.base_beat_length=n.beatLength,this.sv_multiplier=1;else if(n.uninherited===0&&n.beatLength<0){let s=-100/n.beatLength;if(s>0)this.sv_multiplier=s}this.index=u}return this.last_time=r,this.sv_multiplier=y(this.sv_multiplier,0.1,10),{base_beat_length:this.base_beat_length,sv_multiplier:this.sv_multiplier}}}var tr=(r)=>{if(r.length===0)return r;return r.sort((u,n)=>{if(u.time!==n.time)return u.time-n.time;if(u.uninherited===n.uninherited)return 0;return u.uninherited>n.uninherited?-1:1})};var er=(r)=>{let u=[];for(let n of r.HitObjects){let s={...n,end_time:n.endTime||n.time,end_pos:[n.x,n.y],combo_number:0,combo_count:0,data:{pos:[n.x,n.y]}};if(n.type&J.Slider){let t={pos:[n.x,n.y],path_type:n.curveType||"L",control_points:(n.curvePoints||[]).map((e)=>[e.x,e.y]),repetitions:n.slides||1,distance:n.length||0};s.data=t}else if(n.type&J.Spinner){let t=n.endTime||n.time;s.data={end_time:t},s.end_time=t,s.end_pos=[256,192]}else if(n.type&J.Hold){let t=n.endTime||n.time;s.data={pos:[n.x,n.y],end_time:t},s.end_time=t}u.push(s)}return u};var vr=(r)=>384-r,qu=1500,Zu=20000,ar=1.5,Xu=8,mu=120;class or extends Y{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;constructor(r,u,n=0,s=q){super(r,u,n,s);this.follow_point_renderer=new Or(u,n,this.preempt,this.fade_in,this.radius)}initialize(r){this.release_drawables(),this.beatmap=r,this.objects=er(r).sort((s,t)=>s.time-t.time),this.timing_points=tr([...r.TimingPoints]),this.timing_resolver=new c(this.timing_points);let u=r.Difficulty.ApproachRate>=0?r.Difficulty.ApproachRate:r.Difficulty.OverallDifficulty,n=cr(r.Difficulty.CircleSize,u,0,0,this.mods);if(this.radius=xr(n.cs),this.preempt=d(n.ar),this.fade_in=wr(this.preempt),$(this.mods,V.Hidden))this.fade_in=this.preempt*0.4;this.follow_point_renderer.update_settings(this.mods,this.preempt,this.fade_in,this.radius),this.preprocess_objects(),this.follow_point_renderer.build(this.objects),this.create_drawables()}set_mods(r){if(this.mods=r,this.beatmap)this.initialize(this.beatmap)}preprocess_objects(){let r=0,u=1;if(this.timing_resolver)this.timing_resolver.reset();for(let n of this.objects){if(Ur(n))r=(r+1)%this.skin.combo_colors.length,u=1;else u++;if(n.combo_number=r,n.combo_count=u,Vr(n)){let s=n.data;if($(this.mods,V.HardRock))s.pos=[s.pos[0],vr(s.pos[1])],s.control_points=s.control_points.map((o)=>[o[0],vr(o[1])]);s.computed_path=kr(s);let t=this.timing_resolver?.get_state_at(n.time)??{base_beat_length:600,sv_multiplier:1},e=nr(s.distance,this.beatmap,t);s.duration=e,n.end_time=n.time+e*s.repetitions,n.end_pos=dr(s)}else if(U(n))n.end_pos=[256,192];else{let s=n.data;if($(this.mods,V.HardRock))s.pos=[s.pos[0],vr(s.pos[1])];n.end_pos=s.pos}}}create_drawables(){this.release_drawables();let r=this.config.use_high_dpi?window.devicePixelRatio||1:1;if(this.drawable_config={backend:this.backend,skin:this.skin,preempt:this.preempt,fade_in:this.fade_in,radius:this.radius,scale:this.config.scale*r,mods:this.mods},this.timing_resolver)this.timing_resolver.reset();for(let u of this.objects)if(Xr(u))this.drawables.push(new rr(u,this.drawable_config));else if(Vr(u)){let n=u.data,s=n.computed_path||[],t=n.duration||0,e=this.timing_resolver?.get_state_at(u.time)??{base_beat_length:600,sv_multiplier:1},{tick_distance:o,min_distance_from_end:h}=sr(this.beatmap,e),f=new l(u,this.drawable_config,s,t,o,h);this.drawables.push(f),this.slider_drawables.push(f)}}render(r){let{backend:u,config:n}=this;if(this.precompute_focus_time=r,performance.now()>=this.precompute_pause_until)this.process_precompute_queue(r,ar,!1);this.render_background(),u.save(),u.translate(n.offset_x,n.offset_y),u.scale(n.scale,n.scale),this.render_playfield(),this.render_grid();let s=[];for(let t=this.drawables.length-1;t>=0;t--){let e=this.drawables[t];if(e.is_alive(r))s.push(e)}this.follow_point_renderer.render(r,u,(t,e)=>this.get_circle_alpha(t,e));for(let t of this.objects)if(U(t)){let e=t.time-this.preempt;if(r>=e&&r<=t.end_time+200)this.draw_spinner(t,r)}for(let t of s)t.update(r);for(let t of s)if(t instanceof l){if(!t.has_body_cache())t.prepare_body_cache();this.touch_slider_cache(t),t.render_body_pass(r)}for(let t of s)if(t instanceof l)t.render_head_pass(r);else t.render(r);if(!$(this.mods,V.Hidden)&&this.skin.enable_approach_circle){for(let t of s)if(r<=t.start_time)this.draw_approach_circle(t,r)}u.restore()}precompute(r=0){this.precompute_focus_time=r,this.process_precompute_queue(r,Xu,!0),this.start_precompute_loop()}on_seek(r){this.precompute_focus_time=r,this.precompute_pause_until=performance.now()+90;let u=performance.now();if(u-this.last_seek_prefetch_at<48)return;this.last_seek_prefetch_at=u,this.process_precompute_queue(r,2.5,!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 r of this.drawables)r.dispose();this.drawables=[],this.slider_drawables=[],this.slider_cache_lru=[]}start_precompute_loop(){if(this.precompute_handle!==null)return;let r=()=>{if(this.precompute_handle=null,!this.has_uncached_sliders())return;this.process_precompute_queue(this.precompute_focus_time,ar,!1),this.precompute_handle=window.requestAnimationFrame(r)};this.precompute_handle=window.requestAnimationFrame(r)}stop_precompute_loop(){if(this.precompute_handle!==null)window.cancelAnimationFrame(this.precompute_handle),this.precompute_handle=null}has_uncached_sliders(){for(let r of this.slider_drawables)if(!r.has_body_cache())return!0;return!1}process_precompute_queue(r,u,n){if(this.slider_drawables.length==0)return;let s=performance.now()+u;while(performance.now()<s){let t=this.pick_next_slider_for_precompute(r,n);if(!t)break;t.prepare_body_cache(),this.touch_slider_cache(t),this.enforce_slider_cache_limit()}}pick_next_slider_for_precompute(r,u){let n=null,s=-1/0;for(let t of this.slider_drawables){if(t.has_body_cache())continue;let e=t.start_time-r,o=e>=-qu&&e<=Zu,h=t.estimate_complexity();if(o){let f=Math.abs(e)*0.02,I=h-f;if(I>s)s=I,n=t}else if(n==null&&u){if(h>s)s=h,n=t}}return n}touch_slider_cache(r){if(!r.has_body_cache())return;let u=this.slider_cache_lru.indexOf(r);if(u>=0)this.slider_cache_lru.splice(u,1);this.slider_cache_lru.push(r)}enforce_slider_cache_limit(){while(this.slider_cache_lru.length>mu){let r=this.slider_cache_lru.shift();if(!r)break;r.release_body_cache()}}draw_approach_circle(r,u){let n=r.position,s=r.start_time-this.preempt,t=Math.min(this.fade_in*2,this.preempt),o=y((u-s)/t,0,1)*this.skin.approach_circle_opacity,f=4-3*y((u-s)/this.preempt,0,1),I=Z(this.skin,r.combo_number,1);this.backend.save(),this.backend.set_alpha(o),this.backend.draw_circle(n[0],n[1],this.radius*f,"transparent",I,this.radius*this.skin.approach_circle_width),this.backend.restore()}get_circle_alpha(r,u){let n=u-this.preempt;if(r<n)return 0;let s=y((r-n)/this.fade_in,0,1);if($(this.mods,V.Hidden)){let t=u-this.preempt+this.fade_in,e=this.preempt*0.3;if(r>t){let o=y((r-t)/e,0,1);s*=1-o}}return s}draw_spinner(r,u){let n=r.time-this.preempt,s=y((u-n)/this.fade_in,0,1);if(u>r.end_time)s=1-C.OutCubic(y((u-r.end_time)/200,0,1));if(s<=0)return;let t=256,e=192,o=r.end_time-r.time,h=y((u-r.time)/o,0,1);this.backend.set_alpha(s);let f=this.skin.spinner_size*(1-h);if(f>5)this.backend.begin_path(),this.backend.arc_to(t,e,f,0,Math.PI*2),this.backend.stroke_path("rgba(255,255,255,0.6)",4);this.backend.draw_circle(t,e,this.skin.spinner_size,"rgba(0,0,0,0.2)"),this.backend.draw_circle(t,e,12,"white")}}var _r=11485,ru=20;class hr extends Y{key_count=4;scroll_time=_r/ru;hd_coverage=0.25;fi_coverage=0.6;gradient_ratio=0.2;constructor(r,u,n=0,s=q){super(r,u,n,s);this.update_scroll_time()}initialize(r){this.beatmap=r,this.objects=er(r),this.key_count=Math.floor(r.Difficulty.CircleSize)}set_mods(r){this.mods=r,this.update_scroll_time()}update_scroll_time(){let r=Pr(this.mods);this.scroll_time=_r/(ru*r)}time_to_y(r){let u=this.skin.mania_hit_position,n=r/this.scroll_time;return u-n*u}render(r){let{backend:u,config:n,skin:s,key_count:t}=this;this.render_background();let e=t*s.mania_lane_width,o=Math.floor((Dr-e)/2),h=s.mania_hit_position;u.save(),u.translate(n.offset_x,n.offset_y),u.scale(n.scale,n.scale),this.render_playfield(e,pr,o),this.draw_lane_keys(r,o),this.draw_judgment_line(o),u.save(),u.begin_path(),u.rect(o,0,e,h),u.clip(),u.set_alpha(0.7),u.draw_rect(o,0,e,h,"#000000"),u.set_alpha(1);for(let f of this.objects){if(f.end_time<r)continue;if(mr(f))this.draw_hold_note(f,r,o);else this.draw_note(f,r,o)}if($(this.mods,V.Hidden)||$(this.mods,V.FadeIn)){let f=$(this.mods,V.Hidden)?this.hd_coverage:this.fi_coverage,I=h*f,D=h*this.gradient_ratio;if($(this.mods,V.Hidden)){let T=h-I,H=D/I,M=u.create_linear_gradient(o,T,o,h,[{offset:0,color:"rgba(0,0,0,0)"},{offset:H*0.4,color:"rgba(0,0,0,0.3)"},{offset:H*0.7,color:"rgba(0,0,0,0.75)"},{offset:H*0.9,color:"rgba(0,0,0,0.95)"},{offset:H,color:"rgba(0,0,0,1)"},{offset:1,color:"rgba(0,0,0,1)"}]);u.draw_rect_gradient(o,T,e,I,M)}else{let T=(I-D)/I,H=u.create_linear_gradient(o,0,o,I,[{offset:0,color:"rgba(0,0,0,1)"},{offset:T,color:"rgba(0,0,0,1)"},{offset:T+(1-T)*0.1,color:"rgba(0,0,0,0.95)"},{offset:T+(1-T)*0.4,color:"rgba(0,0,0,0.75)"},{offset:T+(1-T)*0.7,color:"rgba(0,0,0,0.3)"},{offset:1,color:"rgba(0,0,0,0)"}]);u.draw_rect_gradient(o,0,e,I,H)}}u.restore(),u.restore()}get_lane(r){let u=r.data.pos,n=Math.floor(u[0]*this.key_count/512);if($(this.mods,V.Mirror))n=this.key_count-1-n;return n}draw_note(r,u,n){let{backend:s,skin:t,key_count:e}=this,o=this.get_lane(r),h=t.mania_lane_width,f=t.mania_note_height,I=t.mania_lane_spacing,D=r.time-u,T=this.time_to_y(D);if(T<-f-64)return;let H=n+o*h,M=G(t,e,o);s.set_alpha(1),s.draw_rect(H+I,T-f,h-2*I,f,M)}draw_hold_note(r,u,n){let{backend:s,skin:t,key_count:e}=this,o=r.data,h=this.get_lane(r),f=t.mania_lane_width,I=t.mania_note_height,D=t.mania_lane_spacing,T=r.time-u,H=o.end_time-u,M=this.time_to_y(T),B=this.time_to_y(H),p=n+h*f,R=G(t,e,h);if(B<-64&&M<-64)return;let P=B,S=(T<0?t.mania_hit_position:M)-P;if(S>0)s.set_alpha(0.9),s.draw_rect(p+D,P,f-2*D,S,R);if(T>=0)s.set_alpha(1),s.draw_rect(p+D,M-I,f-2*D,I,R);s.set_alpha(1)}draw_judgment_line(r){let{backend:u,skin:n,key_count:s}=this,t=n.mania_lane_width,e=n.mania_hit_position;u.draw_rect(r,e-1,t*s,2,"#ffffff")}draw_lane_keys(r,u){let{backend:n,skin:s,key_count:t}=this,{mania_lane_width:e,mania_hit_position:o,mania_lane_spacing:h,mania_note_height:f}=s,I=f+5,D=new Set,T=50;for(let H of this.objects)if(r>=H.time-50&&r<=H.end_time+50)D.add(this.get_lane(H));for(let H=0;H<t;H++){let M=D.has(H),B=u+H*e,p=G(s,t,H);if(n.set_alpha(0.3),n.draw_rect(B+h,o,e-2*h,I,p),M)n.set_alpha(1),n.draw_rect(B+h,o,e-2*h,I,"#ff6666")}n.set_alpha(1)}}class g{audio_context;gain_node;constructor(r){this.audio_context=r,this.gain_node=this.audio_context.createGain(),this.gain_node.connect(this.audio_context.destination)}set_volume(r){this.gain_node.gain.value=y(r,0,1)}dispose_audio_node(){this.gain_node.disconnect()}}class fr extends g{audio_element=null;media_source_node=null;object_url=null;pause_time=0;speed=1;_is_playing=!1;_duration=0;_is_loaded=!1;constructor(r){super(r)}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.audio_element)return this.pause_time;if(!this._is_playing)return this.pause_time;return this.audio_element.currentTime*1000}async load(r,u=0){this.stop(),this.release_media();try{this.speed=E(u);let n=new Blob([r]),s=URL.createObjectURL(n),t=new Audio(s);t.preload="metadata",t.playbackRate=this.speed,t.preservesPitch=!1,this.audio_element=t,this.object_url=s,this.media_source_node=this.audio_context.createMediaElementSource(t),this.media_source_node.connect(this.gain_node),await new Promise((e,o)=>{let h=()=>{t.removeEventListener("loadedmetadata",h),t.removeEventListener("error",f),e()},f=()=>{t.removeEventListener("loadedmetadata",h),t.removeEventListener("error",f),o(Error("Failed to load audio metadata"))};t.addEventListener("loadedmetadata",h,{once:!0}),t.addEventListener("error",f,{once:!0})}),this._duration=Math.max(0,(this.audio_element.duration||0)*1000),this._is_loaded=!0,this.pause_time=0,this.audio_element.onended=()=>{this._is_playing=!1,this.pause_time=this._duration}}catch(n){throw console.error("Failed to load audio data",n),this.release_media(),n}}async play(r){if(!this.audio_element){console.warn("[AudioController] Cannot play: not loaded");return}let u=r!==void 0?r/1000:this.pause_time/1000,n=this.audio_element.duration||this._duration/1000,s=Math.max(0,Math.min(u,n));if(s>=n){this.pause_time=n*1000;return}this.audio_element.currentTime=s,this.audio_element.playbackRate=this.speed;try{await this.audio_element.play(),this._is_playing=!0}catch(t){throw this._is_playing=!1,t}}pause(){if(!this.audio_element||!this._is_playing)return;this.pause_time=this.current_time,this.audio_element.pause(),this._is_playing=!1}seek(r){let u=Math.max(0,Math.min(r,this._duration));if(this.pause_time=u,!this.audio_element)return;this.audio_element.currentTime=u/1000}stop(){if(this.pause(),this.pause_time=0,this.audio_element)this.audio_element.currentTime=0}get_host_time(r){let u=r-this.current_time;return this.audio_context.currentTime+u/1000/this.speed}set_speed(r){if(this.speed=r,this.audio_element)this.audio_element.playbackRate=r}dispose(){this.stop(),this.release_media(),this._is_loaded=!1,this._duration=0,this.pause_time=0,this._is_playing=!1,this.dispose_audio_node()}release_media(){if(this.audio_element)this.audio_element.pause(),this.audio_element.onended=null,this.audio_element.src="",this.audio_element.load(),this.audio_element=null;if(this.media_source_node)this.media_source_node.disconnect(),this.media_source_node=null;if(this.object_url)URL.revokeObjectURL(this.object_url),this.object_url=null}}class Ir{video=null;object_url=null;_offset=0;get element(){return this.video}get offset(){return this._offset}async load(r,u=0){this.dispose(),this._offset=u,this.video=document.createElement("video"),this.video.muted=!0,this.video.loop=!1,this.video.playsInline=!0,this.object_url=URL.createObjectURL(r),this.video.src=this.object_url,await new Promise((n,s)=>{if(!this.video)return s(Error("No video element"));this.video.onloadeddata=()=>n(),this.video.onerror=()=>s(Error("Failed to load video"))})}sync(r){if(!this.video)return;let u=(r-this._offset)/1000;if(u<0){if(!this.video.paused)this.video.pause();return}if(Math.abs(this.video.currentTime-u)>0.1)this.video.currentTime=u}play(){if(this.video&&this.video.paused)this.video.play().catch(()=>{console.log("failed to play video")})}pause(){if(this.video&&!this.video.paused)this.video.pause()}seek(r){if(!this.video)return;let u=Math.max(0,(r-this._offset)/1000);this.video.currentTime=u}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 X extends g{static default_samples=new Map;static default_loads=new Map;custom_samples=new Map;constructor(r){super(r)}async load_samples(r){this.custom_samples.clear(),await this.load_into_cache(r,this.custom_samples,!1)}async load_samples_from_files(r){this.custom_samples.clear(),await this.load_files_into_cache(r,this.custom_samples)}async load_default_samples(r){await this.load_into_cache(r,X.default_samples,!0)}clear(){this.custom_samples.clear()}play(r,u,n,s,t=100,e,o=0){let h=this.get_set_name(r),f=this.get_set_name(u);if(e){let I=e.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"");if(this.play_buffer(I,t,o))return}if(this.play_sound(h,"hitnormal",s,t,o),n&i.Whistle)this.play_sound(f,"hitwhistle",s,t,o);if(n&i.Finish)this.play_sound(f,"hitfinish",s,t,o);if(n&i.Clap)this.play_sound(f,"hitclap",s,t,o)}play_sample(r,u,n,s=100,t=0){let e=this.get_set_name(r);this.play_sound(e,u,n,s,t)}play_sound(r,u,n,s,t){let e=!1;if(n>1)e=this.play_buffer(`${r}-${u}${n}`,s,t);if(!e)this.play_buffer(`${r}-${u}`,s,t)}play_buffer(r,u,n){let s=this.custom_samples.get(r)??X.default_samples.get(r);if(!s)return!1;let t=this.audio_context.createBufferSource();t.buffer=s;let e=this.audio_context.createGain();return e.gain.value=u/100,t.connect(e),e.connect(this.gain_node),t.start(n),!0}get_set_name(r){switch(r){case 3:return"drum";case 2:return"soft";default:return"normal"}}get_sample_key_from_url(r){let n=r.split("?")[0].split("#")[0].split("/").pop();if(!n)return null;if(!n.endsWith(".wav")&&!n.endsWith(".mp3")&&!n.endsWith(".ogg"))return null;return n.toLowerCase().replace(/\.(wav|mp3|ogg)$/,"")}async load_into_cache(r,u,n){if(r.length==0)return;let s=[],t=r.map(async(e)=>{let o=this.get_sample_key_from_url(e);if(!o){s.push(e);return}if(u.has(o))return;if(!n){await this.load_single_sample(e,o,u,s);return}let h=X.default_loads.get(o);if(h){await h;return}let f=this.load_single_sample(e,o,u,s).finally(()=>{X.default_loads.delete(o)});X.default_loads.set(o,f),await f});if(await Promise.all(t),s.length>0)console.warn(`[HitsoundController] Failed to load ${s.length} hitsounds`)}async load_single_sample(r,u,n,s){try{let t=await fetch(r);if(!t.ok){s.push(r);return}let e=await t.arrayBuffer();if(e.byteLength<128){s.push(r);return}let o=await this.audio_context.decodeAudioData(e.slice(0));n.set(u,o)}catch{s.push(r)}}async load_files_into_cache(r,u){if(r.size==0)return;let n=[],s=[...r.entries()].map(async([t,e])=>{let o=this.get_sample_key_from_url(t);if(!o)return;if(u.has(o))return;if(e.byteLength<128){n.push(t);return}try{let h=await this.audio_context.decodeAudioData(e.slice(0));u.set(o,h)}catch{n.push(t)}});if(await Promise.all(s),n.length>0)console.warn(`[HitsoundController] Failed to load ${n.length} hitsounds`)}dispose(){this.custom_samples.clear(),this.dispose_audio_node()}}class qr{files;audio_filename;background_filename;video_filename;video_offset;constructor(r){this.files=r.files,this.audio_filename=r.audio_filename,this.background_filename=r.background_filename,this.video_filename=r.video_filename,this.video_offset=r.video_offset}resolve(){let r=this.audio_filename?this.find_file(this.audio_filename):void 0,u=this.background_filename?this.find_file(this.background_filename):void 0,n=this.video_filename?this.find_file(this.video_filename):void 0;return{audio:r,background:u?new Blob([u]):void 0,video:n?new Blob([n]):void 0,video_offset:this.video_offset}}find_file(r){if(this.files.has(r))return this.files.get(r);let u=r.toLowerCase();for(let[n,s]of this.files)if(n.toLowerCase()===u)return s;return}}var Uu=100,Wu=20;class Zr{audio;hitsounds;resources=null;timing_points=[];timing_resolver=null;audio_offset=20;next_hit_object_index=0;constructor(r,u){this.audio=r;this.hitsounds=u}set_context(r,u,n,s){this.resources=r,this.timing_points=u,this.timing_resolver=n,this.audio_offset=s,this.next_hit_object_index=0}set_audio_offset(r){this.audio_offset=r}update_hit_index(r){if(!this.resources?.beatmap)return;let u=this.resources.beatmap.HitObjects;if(this.next_hit_object_index>0&&u[this.next_hit_object_index-1].time>r)this.next_hit_object_index=0;while(this.next_hit_object_index<u.length&&u[this.next_hit_object_index].time<r)this.next_hit_object_index++}schedule_hitsounds(r){if(!this.resources?.beatmap||!this.audio.is_playing)return;let u=this.resources.beatmap.HitObjects,n=r+Uu;while(this.next_hit_object_index<u.length&&u[this.next_hit_object_index].time<=n){let s=u[this.next_hit_object_index];if(s.time>=r-Wu)this.play_hitsound(s);this.next_hit_object_index++}}play_hitsound(r){let u=this.get_timing_point(r.time),n=this.resolve_sample_settings(u,r.hitSample);if((r.type&J.Slider)===0){this.play_node_hitsound(r.time,r.hitSound,n,n.custom_filename);return}let s=this.resources?.beatmap;if(!s)return;let t=this.timing_resolver?.get_state_at(r.time)??{base_beat_length:600,sv_multiplier:1},e=r.length??0,o=nr(e,s,t),h=Math.max(1,r.slides||1);if(o<=0||e<=0){this.play_node_hitsound(r.time,r.hitSound,n,n.custom_filename);return}let f=r.edgeSounds??[],I=r.edgeSets??[];for(let H=0;H<=h;H++){let M=r.time+o*H,B=f.length>0?f[H]??0:H==0?r.hitSound:0,p=I.length>0?I[H]:void 0,R=this.resolve_edge_sets(n,p),P=H==0?n.custom_filename:void 0;this.play_node_hitsound(M,B,{...n,...R},P)}let D=sr(s,t),T=ur({start_time:r.time,span_duration:o,span_count:h,length:e,tick_distance:D.tick_distance,min_distance_from_end:D.min_distance_from_end,get_position_at_progress:()=>[0,0]});for(let H of T.ticks){let M=this.audio.get_host_time(H.time+this.audio_offset);this.hitsounds.play_sample(n.normal_set,"slidertick",n.index,n.volume,M)}}play_node_hitsound(r,u,n,s){let t=this.audio.get_host_time(r+this.audio_offset);this.hitsounds.play(n.normal_set,n.addition_set,u,n.index,n.volume,s,t)}resolve_sample_settings(r,u){let{volume:n,sampleSet:s,sampleSet:t,sampleIndex:e}=r,o=void 0;if(u){if(u.normalSet!==0){if(s=u.normalSet,u.additionSet===0)t=s}if(u.additionSet!==0)t=u.additionSet;if(u.index!==0)e=u.index;if(u.volume!==0)n=u.volume;o=u.filename||void 0}if(s===0)s=1;if(t===0)t=s;return{normal_set:s,addition_set:t,index:e,volume:n,custom_filename:o}}resolve_edge_sets(r,u){let{normal_set:n,addition_set:s}=r;if(u){let{normalSet:t,additionSet:e}=u;if(t!==0)n=t;if(e!==0)s=e;else s=n}if(n===0)n=1;if(s===0)s=n;return{normal_set:n,addition_set:s}}get_timing_point(r){let u=this.timing_points;if(u.length==0)return{time:0,beatLength:600,meter:4,sampleSet:1,sampleIndex:1,volume:100,uninherited:1,effects:0};for(let n=u.length-1;n>=0;n--)if(u[n].time<=r)return u[n];return u[0]}}var Yu=[".wav",".mp3",".ogg"],zu=/^(normal|soft|drum)-(hitnormal|hitwhistle|hitfinish|hitclap|slidertick|sliderslide|sliderwhistle)\d*$/i,uu=(r,u,n)=>{let s=new Set;for(let o of r.HitObjects){let h=o.hitSample?.filename?.trim();if(h)s.add(h.toLowerCase())}let t=new Map,e=n?.toLowerCase();for(let[o,h]of u){let f=o.toLowerCase();if(!Ku(f))continue;if(e&&f==e)continue;let I=lu(f),D=I.replace(/\.(wav|mp3|ogg)$/,""),T=zu.test(D),H=s.has(I)||s.has(D)||s.has(f);if(T||H)t.set(o,h)}return t},Ku=(r)=>{for(let u of Yu)if(r.endsWith(u))return!0;return!1},lu=(r)=>{let u=r.split("?")[0].split("#")[0];return u.split("/").pop()??u};var Gu=0.42,wu=30;class su{backend;renderer=null;audio_context;audio;hitsounds;video=null;resources=null;animation_frame=null;skin;mods;renderer_config;start_offset;start_mode;custom_start_time;music_volume;hitsound_volume;audio_offset;background_url=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;last_timestamp=0;smooth_time=0;constructor(r){this.options=r,this.backend=r.backend??new k,this.skin=a(r.skin),this.mods=r.mods??0,this.renderer_config={...q,...r.renderer_config},this.calculate_layout(r.canvas.width,r.canvas.height,r.playfield_scale),this.start_mode=r.start_mode??(Number.isFinite(r.start_time)?"custom":"preview"),this.custom_start_time=Number.isFinite(r.start_time)?Math.max(0,r.start_time):null,this.start_offset=0,this.music_volume=r.volume??0.5,this.hitsound_volume=r.hitsound_volume??0.25,this.audio_offset=r.audio_offset??20,this.backend.initialize(r.canvas,this.renderer_config.use_high_dpi);let u=window.AudioContext||window.webkitAudioContext;if(this.audio_context=new u,this.audio=new fr(this.audio_context),this.hitsounds=new X(this.audio_context),this.hitsound_scheduler=new Zr(this.audio,this.hitsounds),this.audio.set_volume(this.music_volume),this.hitsounds.set_volume(this.hitsound_volume),r.auto_resize)this.setup_auto_resize();this.enable_fps_counter=r.enable_fps_counter??!1,this.fps_last_update=performance.now();let n=r.time_smoothing;if(Number.isFinite(n))this.time_smoothing=Math.max(0,Math.min(1,n));let s=r.max_frame_delta;if(Number.isFinite(s))this.max_frame_delta=Math.max(10,s)}async load_osz(r,u){try{let s=await new W().load_osz(r,{difficulty:u});return this.resources=s,this.setup()}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_files(r,u){try{let n=new W;return this.resources=await n.load_from_files(r,{difficulty:u}),this.setup()}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_default_hitsounds(r){if(r.length==0){console.warn("[BeatmapPlayer] No default hitsound URLs were provided");return}try{await this.hitsounds.load_default_samples(r)}catch(u){console.error("[BeatmapPlayer] Failed to load default hitsounds:",u)}}async load_custom_hitsounds(r){if(r.length==0){console.warn("[BeatmapPlayer] No custom hitsound URLs were provided"),this.hitsounds.clear();return}try{await this.hitsounds.load_samples(r)}catch(u){console.error("[BeatmapPlayer] Failed to load custom hitsounds:",u)}}async load_map_custom_hitsounds(){if(!this.resources?.beatmap)return;let r=uu(this.resources.beatmap,this.resources.files,this.resources.audio_filename);if(r.size==0){this.hitsounds.clear();return}try{await this.hitsounds.load_samples_from_files(r)}catch(u){console.error("[BeatmapPlayer] Failed to load map custom hitsounds:",u),this.hitsounds.clear()}}async load_beatmap(r,u,n,s,t){return this.resources={beatmap:r,available_difficulties:[],files:new Map,audio:u,background:n,video:s,video_offset:t},this.setup()}async load_osu_content(r,u){try{await nu();let n=await this.parse_content(r);return this.load_beatmap(n,u)}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async load_beatmap_files(r,u,n,s,t){try{await nu();let e=typeof r==="string",o=r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):null,h=await this.parse_content(e?r:o);return this.load_beatmap(h,u,n,s,t)}catch(e){let o=e instanceof Error?e.message:String(e);return this.emit("error","INVALID_BEATMAP",o),L("INVALID_BEATMAP",o)}}async setup(){if(!this.resources)return L("NOT_LOADED","No resources loaded");let{beatmap:r}=this.resources;this.timing_points=tr([...r.TimingPoints]),this.timing_resolver=new c(this.timing_points);let u=E(this.mods);this.resolve_assets();let{audio:n,video:s,video_offset:t}=this.resources;if(n)try{await this.audio.load(n,this.mods)}catch(e){let o=e instanceof Error?e.message:String(e);return this.emit("error","AUDIO_DECODE_ERROR",o),L("AUDIO_DECODE_ERROR",o)}if(this.hitsound_scheduler.set_context(this.resources,this.timing_points,this.timing_resolver,this.audio_offset),this.load_map_custom_hitsounds(),s)this.video=new Ir,await this.video.load(s,t??0);try{this.renderer=this.create_renderer(r),this.renderer.initialize(r),this.renderer.precompute()}catch(e){let o=e instanceof Error?e.message:String(e);return this.emit("error","UNSUPPORTED_MODE",o),L("UNSUPPORTED_MODE",o)}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",r,this.resources),requestAnimationFrame(()=>this.render_frame(this.start_offset)),Yr(this.resources)}async load_background(){if(this.resources)this.resolve_assets();if(!this.resources?.background||!this.renderer)return;try{let r=new Image;if(this.background_url)URL.revokeObjectURL(this.background_url);this.background_url=URL.createObjectURL(this.resources.background),r.src=this.background_url,await r.decode(),this.renderer.set_background({source:r,width:r.width,height:r.height});let u=this.audio.is_playing?this.current_time:this.start_offset;requestAnimationFrame(()=>this.render_frame(u))}catch(r){console.warn("[BeatmapPlayer] Failed to load background",r)}}resolve_assets(){if(!this.resources)return;let r=new qr(this.resources).resolve();if(!this.resources.audio&&r.audio)this.resources.audio=r.audio;if(!this.resources.background&&r.background)this.resources.background=r.background;if(!this.resources.video&&r.video)this.resources.video=r.video;if(!this.resources.video_offset&&r.video_offset)this.resources.video_offset=r.video_offset}create_renderer(r){switch(r.General.Mode){case 0:return new or(this.backend,this.skin,this.mods,this.renderer_config);case 3:return new hr(this.backend,this.skin,this.mods,this.renderer_config);case 1:case 2:default:throw Error(`Unsupported game mode: ${Tr[r.General.Mode]??r.General.Mode}`)}}get_last_object_time(){if(!this.resources?.beatmap.HitObjects.length)return 0;let r=this.resources.beatmap.HitObjects,u=0;for(let n of r){let s=n.endTime||n.time;if(s>u)u=s}return u}resolve_preview_start_offset(){if(!this.resources?.beatmap)return 0;let r=this.resources.beatmap.General.PreviewTime;if(r>0)return r;return Math.max(0,this.get_last_object_time()*Gu)}resolve_initial_start_offset(){let r=Math.max(0,this.duration);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,r));return Math.max(0,Math.min(this.resolve_preview_start_offset(),r))}return Math.max(0,Math.min(this.resolve_preview_start_offset(),r))}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(Math.max(0,this.start_offset+this.audio_offset))}catch(r){console.warn("[BeatmapPlayer] Failed to start audio",r),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=Math.max(0,this.audio.current_time-this.audio_offset),this.audio.pause(),this.video?.pause(),this.stop_render_loop(),this.emit("pause"),this.emit("statechange",!1)}set_mods(r){this.mods=r;let u=E(r);if(this.renderer?.set_mods(r),this.audio.set_speed(u),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}seek(r){this.start_offset=Math.max(0,Math.min(r,this.duration)),this.hitsound_scheduler.update_hit_index(this.start_offset),this.audio.seek(Math.max(0,this.start_offset+this.audio_offset)),this.video?.seek(this.start_offset),this.emit("seek",this.start_offset),this.render_frame(this.start_offset),this.renderer?.on_seek(this.start_offset)}async set_difficulty(r){if(!this.resources)return L("NOT_LOADED","No beatmap resources loaded");let u=this.is_playing;this.stop();try{let s=await new W().load_from_files(this.resources.files,{difficulty:r});this.resources=s;let t=await this.setup();if(t.success&&u)this.play();return t}catch(n){let s=n instanceof Error?n.message:String(n);return this.emit("error","INVALID_BEATMAP",s),L("INVALID_BEATMAP",s)}}async parse_content(r){let u=typeof r=="string"?new TextEncoder().encode(r):r;return await Eu(u)}stop(){this.pause(),this.start_offset=0,this.audio.seek(Math.max(0,this.audio_offset)),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()}get current_time(){return Math.max(0,this.audio.current_time-this.audio_offset)}get duration(){return this.audio.duration||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(r,u,n){if(this.backend.resize(r,u),this.calculate_layout(r,u,n),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}update_config(r){if(this.renderer_config={...this.renderer_config,...r},this.renderer?.update_config(this.renderer_config),this.is_loaded_flag)requestAnimationFrame(()=>this.render_frame(this.current_time))}set_skin(r){if(this.skin=a(r),this.is_loaded_flag&&this.resources?.beatmap)this.renderer=this.create_renderer(this.resources.beatmap),this.renderer.initialize(this.resources.beatmap),requestAnimationFrame(()=>this.render_frame(this.current_time))}setup_auto_resize(){this.resize_observer=new ResizeObserver(()=>{let u=this.options.canvas.parentElement;if(u){let n=u.getBoundingClientRect();this.resize(n.width,n.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(r,u,n){let e=0.9;if(Number.isFinite(n))e=n;let o=r*e/512,h=u*e/384,f=Math.min(o,h);if(this.renderer_config.scale=f,this.renderer_config.offset_x=Math.floor((r-512*f)/2),this.renderer_config.offset_y=Math.floor((u-384*f)/2),this.renderer)this.renderer.update_config(this.renderer_config)}set_volume(r){this.music_volume=r,this.audio.set_volume(r)}set_hitsound_volume(r){this.hitsound_volume=r,this.hitsounds.set_volume(r)}set_offset(r){if(this.audio_offset=r,this.hitsound_scheduler.set_audio_offset(r),this.is_loaded_flag)this.seek(this.current_time)}on(r,u){if(!this.listeners.has(r))this.listeners.set(r,new Set);this.listeners.get(r).add(u)}off(r,u){this.listeners.get(r)?.delete(u)}emit(r,...u){let n=this.listeners.get(r);if(n)for(let s of n)s(...u)}start_render_loop(){if(this.animation_frame!==null)return;this.last_timestamp=performance.now(),this.smooth_time=this.audio.current_time-this.audio_offset,this.smoothed_delta=0;let r=(u)=>{if(!this.audio.is_playing){this.animation_frame=null;return}let n=Math.max(0,u-this.last_timestamp);this.last_timestamp=u;let s=Math.min(n,this.max_frame_delta);if(this.time_smoothing>0){if(this.smoothed_delta===0)this.smoothed_delta=s;else this.smoothed_delta+=(s-this.smoothed_delta)*this.time_smoothing;s=this.smoothed_delta}this.smooth_time+=s*this.audio.speed_multiplier;let t=this.audio.current_time-this.audio_offset;if(Math.abs(this.smooth_time-t)>wu)this.smooth_time=t;else this.smooth_time+=(t-this.smooth_time)*0.1;let o=this.smooth_time;if(this.hitsound_scheduler.schedule_hitsounds(t),this.render_frame(o),this.video?.sync(o),this.emit("timeupdate",o,this.duration),o>=this.duration){this.emit("ended"),this.stop_render_loop(),this.emit("statechange",!1);return}this.animation_frame=requestAnimationFrame(r)};this.animation_frame=requestAnimationFrame(r)}stop_render_loop(){if(this.animation_frame!==null)cancelAnimationFrame(this.animation_frame),this.animation_frame=null}render_frame(r){if(this.backend.begin_frame?.(),this.backend.clear(),this.renderer?.render(r),this.enable_fps_counter){this.fps_frame_count++;let u=performance.now(),n=u-this.fps_last_update;if(n>=1000)this.current_fps=Math.round(this.fps_frame_count*1000/n),this.fps_frame_count=0,this.fps_last_update=u;let s=`14px ${this.skin.default_font??"monospace"}`;this.backend.draw_text(`${this.current_fps} FPS`,10,20,s,"rgba(255,255,255,0.8)","left","top")}this.backend.end_frame?.()}set_fps_counter(r){this.enable_fps_counter=r}}var xu=(r)=>{try{return new FontFace(r.family,r.url,{weight:r.weight,style:"normal"})}catch(u){return console.error(u),null}},cu=async(r)=>{let u=xu(r);if(!u)return!1;try{await u.load(),document.fonts.add(u)}catch(n){return console.error(n),!1}return!0};export{ju as unwrap,rn as toggle_mod,Yr as ok,_u as mods_to_string,au as mods_from_string,a as merge_skin,cu as load_font,U as is_spinner,Vr as is_slider,bu as is_ok,Ur as is_new_combo,mr as is_hold,iu as is_err,Xr as is_circle,$ as has_mod,E as get_speed_multiplier,Pr as get_rate_multiplier,G as get_mania_lane_color,Z as get_combo_color,un as get_available_mods,cr as get_adjusted_difficulty,L as err,yu as apply_rate_to_ar,Pu as apply_mods_to_difficulty,Ir as VideoController,or as StandardRenderer,fu as SpeedChangingMods,Hr as SampleSet,Dr as PLAYFIELD_WIDTH,pr as PLAYFIELD_HEIGHT,W as OszLoader,V as Mods,Du as ModNightcore,Ru as ModHidden,Br as ModHardRock,pu as ModHalfTime,Rr as ModEasy,Vu as ModDoubleTime,hr as ManiaRenderer,i as HitSoundType,J as HitObjectType,Bu as HD_FADE_OUT_MULTIPLIER,Mu as HD_FADE_IN_MULTIPLIER,Er as GridLevel,Tr as GameMode,Wr as ErrorCode,du as DifficultyChangingMods,Fr as DEFAULT_SKIN,q as DEFAULT_RENDERER_CONFIG,k as CanvasBackend,su as BeatmapPlayer,Y as BaseRenderer,fr as AudioController};
2
2
 
3
- //# debugId=B9D937DC4146A37864756E2164756E21
3
+ //# debugId=E365849A69CE2F6264756E2164756E21