RuneCanvas-Oktq94Ck.js

2.6 KB · raw

1import{M as e,S as t,b as n,j as r,k as i,x as a,y as o}from"./index-CgtUDPnm.js";var s=a(`<canvas class=peach-rune-canvas style=display:block>`),c=17,l=c*2.3,u=c*1.35,d=c*.18,f=[18,24,14],p=`#F49C70`;function m(){let e=getComputedStyle(document.documentElement).getPropertyValue(`--peach-accent`).trim();return/^#[0-9a-fA-F]{6}$/.test(e)?e:p}function h(a){let h,g=0,_=!1,v=p,y=[244,156,112];function b(e){v=e,y=[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}return e(()=>{let e=h.getContext(`2d`);if(!e)return;b(m());let t=new MutationObserver(()=>{let e=m();e!==v&&b(e)});t.observe(document.documentElement,{attributes:!0,attributeFilter:[`style`]});let n=a.width,i=a.height,o=Math.ceil(n/(u+d))+4,s=Math.floor(i/l)+1,p=s*o,x=Math.min(8,Math.max(3,Math.floor(p*.03))),S=()=>({row:Math.floor(Math.random()*s),col:Math.floor(Math.random()*o),phase:Math.random(),speed:.4+Math.random()*.4,lifetime:2e3+Math.random()*3e3,age:0}),C=Array.from({length:x},S),w=Array.from({length:s},()=>Math.random()*a.runeString.length*(u+d)),T=a.runeString.length*(u+d)||1,E=performance.now(),D=t=>{let r=Math.min(t-E,64);E=t,e.clearRect(0,0,n,i),e.fillStyle=`#1a1410`,e.fillRect(0,0,n,i),e.font=`${c}px PeachScript, monospace`,e.textBaseline=`alphabetic`;let p=new Map;for(let e of C){e.age+=r,e.phase=(e.phase+e.speed*r/1e3)%1;let t=e.age/e.lifetime,n=Math.sin(t*Math.PI),i=Math.sin(e.phase*Math.PI*2)*.5+.5,a=Math.max(0,n)*i*.85;p.set(`${e.row},${e.col}`,a),e.age>=e.lifetime&&Object.assign(e,S())}let[m,h,_]=y,v=a.runeString,b=v.length;if(b===0){g=requestAnimationFrame(D);return}for(let t=0;t<s;t++){let i=f[t%f.length];w[t]=(w[t]+i*r/1e3)%T;let a=t*l+c+12;for(let r=0;r<o;r++){let i=r*(u+d)-w[t]%(u+d);if(i<-u||i>n+u)continue;let o=v[((Math.floor(w[t]/(u+d))+r)%b+b)%b],s=p.get(`${t},${r}`)??0;s>.01?(e.save(),e.shadowColor=`rgba(${m}, ${h}, ${_}, ${s*.9})`,e.shadowBlur=10,e.fillStyle=`rgba(${m}, ${h}, ${_}, ${.6+s*.4})`,e.fillText(o,i,a),e.restore()):(e.fillStyle=`rgba(245, 240, 234, 0.82)`,e.fillText(o,i,a))}}g=requestAnimationFrame(D)},O=()=>{_||(_=!0,E=performance.now(),g=requestAnimationFrame(D))},k=()=>{_&&(_=!1,cancelAnimationFrame(g))},A=()=>{document.hidden?k():O()};document.addEventListener(`visibilitychange`,A),document.fonts.load(`${c}px PeachScript`).finally(O),r(()=>{k(),t.disconnect(),document.removeEventListener(`visibilitychange`,A)})}),(()=>{var e=s(),r=h;return typeof r==`function`?t(r,e):h=e,i(t=>{var r=a.width,i=a.height,s=`${a.width}px`,c=`${a.height}px`;return r!==t.e&&o(e,`width`,t.e=r),i!==t.t&&o(e,`height`,t.t=i),s!==t.a&&n(e,`width`,t.a=s),c!==t.o&&n(e,`height`,t.o=c),t},{e:void 0,t:void 0,a:void 0,o:void 0}),e})()}export{h as t};