mirror of
https://github.com/bspeice/speice.io
synced 2024-12-22 16:48:10 -05:00
1 line
71 KiB
JavaScript
1 line
71 KiB
JavaScript
|
"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["7618"],{43766:function(s,e,n){n.r(e),n.d(e,{metadata:()=>a,contentTitle:()=>E,default:()=>D,assets:()=>A,toc:()=>R,frontMatter:()=>C});var a=n("36613"),t=n("85893"),l=n("50065"),i=n("67"),r=n("87320"),m=n("67294"),c=n("1905"),h=n("42974"),o=n("37955"),d=n("5886");function p(s){let{paint:e,children:n}=s,{width:a,height:t,setPainter:l}=(0,m.useContext)(r.wn);return(0,m.useEffect)(()=>{l(function*(s){let{width:e,height:n,transforms:a,final:t,paint:l}=s,i=e*n,r=10*i,m=Array(i).fill(0),c=(s,a)=>{let[t,l]=(0,d.n)(s,a,e);if(t<0||t>=e||l<0||l>=n)return;let i=(0,d.j)(t,l,e,1);m[i]+=1},[p,x]=[(0,h.J)(),(0,h.J)()];for(let s=0;s<r;s++){let[i,r]=(0,o.m)(a);[p,x]=r(p,x);let[h,d]=t(p,x);s>20&&c(h,d),s%1e5==0&&(yield l(e,n,m))}yield l(e,n,m)}({width:a,height:t,transforms:c.y7,final:c.SV,paint:e}))},[a,t]),n}function x(s,e,n){let a=new ImageData(s,e),t=0;for(let s of n)t=Math.max(t,s);for(let s=0;s<n.length;s++){let e=4*s;a.data[e]=0,a.data[e+1]=0,a.data[e+2]=0;let l=n[s]/t*255;a.data[e+3]=l}return a}function j(s,e,n){let a=new ImageData(s,e),t=n.map(Math.log),l=-1/0;for(let s of t)l=Math.max(l,s);for(let s=0;s<n.length;s++){let e=4*s;a.data[e]=0,a.data[e+1]=0,a.data[e+2]=0;let n=t[s]/l*255;a.data[e+3]=n}return a}function g(s,e){let n=3*Math.floor(e*(s.length/3));return[s[n],s[n+1],s[n+2]]}function u(s,e,n){return s*(1-n)+e*n}function N(s,e,n,a,t,l){let i=s*e,r=new ImageData(s,e);for(let s=0;s<i;s++){let e=Math.log10(l[s])/(1.5*l[s]),i=4*s,m=n[s]*e*255;r.data[i]=m;let c=a[s]*e*255;r.data[i+1]=c;let h=t[s]*e*255;r.data[i+2]=h;let o=l[s]*e*255;r.data[i+3]=o}return r}var f=n("57037"),y=n("84239");let v=s=>{let{height:e,palette:n,children:a}=s,l=(0,m.useRef)(null),[i,r]=(0,m.useState)(0);(0,m.useEffect)(()=>{l&&r(l.current.offsetWidth)},[l]);let c=(0,m.useRef)(null),h=(0,m.useMemo)(()=>{if(0===i)return;let s=new ImageData(i,e);for(let a=0;a<i;a++){let[t,l,r]=g(n,a/i);for(let n=0;n<e;n++){let e=(0,d.j)(a,n,i,4);s.data[e]=255*t,s.data[e+1]=255*l,s.data[e+2]=255*r,s.data[e+3]=255}}return s},[i,e,n]);(0,m.useEffect)(()=>{c&&h&&c.current.getContext("2d").putImageData(h,0,0)},[c,h]);let o={filter:"dark"===(0,y.I)().colorMode?"invert(1)":""};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{ref:l,style:{width:"100%",height:e},children:i>0?(0,t.jsx)("canvas",{ref:c,width:i,height:e,style:o}):null}),a]})},w=s=>{let{title:e,palette:n,transformColor:a,setTransformColor:l,resetTransformColor:i,children:r}=s,m=(0,t.jsx)("button",{className:f.Z.inputReset,onClick:i,children:"Reset"}),[c,h,o]=g(n,a.color),d=`rgb(${Math.floor(255*c)},${Math.floor(255*h)},${Math.floor(255*o)})`,{colorMode:p}=(0,y.I)();return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:f.Z.inputGroup,style:{display:"grid",gridTemplateColumns:"2fr 2fr 1fr"},children:[(0,t.jsxs)("p",{className:f.Z.inputTitle,style:{gridColumn:"1/-1"},children:[e," ",m]}),(0,t.jsxs)("div",{className:f.Z.inputElement,children:[(0,t.jsxs)("p",{children:["Color: ",a.color]}),(0,t.jsx)("input",{type:"range",min:0,max:1,step:.001,value:a.color,onInput:s=>l({...a,color:Number(s.currentTarget.value)})})]}),(0,t.jsxs)("div",{className:f.Z.inputElement,children:[(0,t.jsxs)("p",{children:["Speed: ",a.colorSpeed]}),(0,t.jsx)("input",{type:"range",min:0,max:1,step:.001,value:a.colorSpeed,onInput:s=>l({...a,colorSpeed:Number(s.currentTarget.value)})})]}),(0,t.jsx)("div",{className:f.Z.inputElement,style:{width:"100%",height:"100%",backgroundColor:d,filter:"dark"===p?"invert(1)":""}})]}),r]})};function b(s){let{children:e}=s,{width:n,height:a,setPainter:l}=(0,m.useContext)(r.wn),i={color:c.N3,colorSpeed:.5},[p,x]=(0,m.useState)(i),j={color:c.yV,colorSpeed:.5},[u,f]=(0,m.useState)(j),y={color:c.iD,colorSpeed:.5},[b,C]=(0,m.useState)(y),E={color:c.sB,colorSpeed:0},[A,R]=(0,m.useState)(E);return(0,m.useEffect)(()=>{l(function*(s){let{width:e,height:n,transforms:a,final:t,palette:l,colors:i,finalColor:r}=s,m=e*n,c=Array(m).fill(0),p=Array(m).fill(0),x=Array(m).fill(0),j=Array(m).fill(0),u=(s,n,a)=>{let[t,i]=(0,d.n)(s,n,e);if(t<
|