Files
gnommoplayer/public/glitch/glitch_gallery/assets/index-C370CA0j.js
T

126 lines
79 KiB
JavaScript
Raw Normal View History

2026-04-11 09:21:22 +02:00
import{r as c,u as _t,c as Nt,a as We,_ as dt,D as Ht,V as ve,b as Vt,P as Tt,O as Et,S as Gt,U as Ut,d as Yt,M as Jt,R as qt,e as Xt,f as Zt,B as Qt,C as ut,A as Kt,j as e,Q as en}from"./index-CEeZxcxj.js";const Xe=new ve,ft=new ve,tn=new ve,jt=new Vt;function nn(t,n,o){const r=Xe.setFromMatrixPosition(t.matrixWorld);r.project(n);const s=o.width/2,i=o.height/2;return[r.x*s+s,-(r.y*i)+i]}function on(t,n){const o=Xe.setFromMatrixPosition(t.matrixWorld),r=ft.setFromMatrixPosition(n.matrixWorld),s=o.sub(r),i=n.getWorldDirection(tn);return s.angleTo(i)>Math.PI/2}function rn(t,n,o,r){const s=Xe.setFromMatrixPosition(t.matrixWorld),i=s.clone();i.project(n),jt.set(i.x,i.y),o.setFromCamera(jt,n);const d=o.intersectObjects(r,!0);if(d.length){const l=d[0].distance;return s.distanceTo(o.ray.origin)<l}return!0}function sn(t,n){if(n instanceof Et)return n.zoom;if(n instanceof Tt){const o=Xe.setFromMatrixPosition(t.matrixWorld),r=ft.setFromMatrixPosition(n.matrixWorld),s=n.fov*Math.PI/180,i=o.distanceTo(r);return 1/(2*Math.tan(s/2)*i)}else return 1}function an(t,n,o){if(n instanceof Tt||n instanceof Et){const r=Xe.setFromMatrixPosition(t.matrixWorld),s=ft.setFromMatrixPosition(n.matrixWorld),i=r.distanceTo(s),d=(o[1]-o[0])/(n.far-n.near),l=o[1]-d*n.far;return Math.round(d*i+l)}}const pt=t=>Math.abs(t)<1e-10?0:t;function kt(t,n,o=""){let r="matrix3d(";for(let s=0;s!==16;s++)r+=pt(n[s]*t.elements[s])+(s!==15?",":")");return o+r}const ln=(t=>n=>kt(n,t))([1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1]),cn=(t=>(n,o)=>kt(n,t(o),"translate(-50%,-50%)"))(t=>[1/t,1/t,1/t,1,-1/t,-1/t,-1/t,-1,1/t,1/t,1/t,1,1,1,1,1]);function dn(t){return t&&typeof t=="object"&&"current"in t}const Ae=c.forwardRef(({children:t,eps:n=.001,style:o,className:r,prepend:s,center:i,fullscreen:d,portal:l,distanceFactor:a,sprite:u=!1,transform:h=!1,occlude:p,onOcclude:g,castShadow:y,receiveShadow:I,material:S,geometry:L,zIndexRange:F=[16777271,0],calculatePosition:_=nn,as:v="div",wrapperClass:$,pointerEvents:A="auto",...D},W)=>{const{gl:B,camera:C,scene:te,size:j,raycaster:N,events:H,viewport:R}=_t(),[E]=c.useState(()=>document.createElement(v)),x=c.useRef(null),U=c.useRef(null),Se=c.useRef(0),G=c.useRef([0,0]),b=c.useRef(null),z=c.useRef(null),k=l?.current||H.connected||B.domElement.parentNode,w=c.useRef(null),K=c.useRef(!1),V=c.useMemo(()=>p&&p!=="blending"||Array.isArray(p)&&p.length&&dn(p[0]),[p]);c.useLayoutEffect(()=>{const X=B.domElement;p&&p==="blending"?(X.style.zIndex=`${Math.floor(F[0]/2)}`,X.style.position="absolute",X.style.pointerEvents="none"):(X.style.zIndex=null,X.style.position=null,X.style.pointerEvents=null)},[p]),c.useLayoutEffect(()=>{if(U.current){const X=x.current=Nt.createRoot(E);if(te.updateMatrixWorld(),h)E.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const O=_(U.current,C,j);E.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${O[0]}px,${O[1]}px,0);transform-origin:0 0;`}return k&&(s?k.prepend(E):k.appendChild(E)),()=>{k&&k.removeChild(E),X.unmount()}}},[k,h]),c.useLayoutEffect(()=>{$&&(E.className=$)},[$]);const re=c.useMemo(()=>h?{position:"absolute",top:0,left:0,width:j.width,height:j.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:i?"translate3d(-50%,-50%,0)":"none",...d&&{top:-j.height/2,left:-j.width/2,width:j.width,height:j.height},...o},[o,i,d,j,h]),ge=c.useMemo(()=>({position:"absolute",pointerEvents:A}),[A]);c.useLayoutEffect(()=>{if(K.current=!1,h){var X;(X=x.current)==null||X.render(c.createElement("div",{ref:b,style:re},c.createElement("div",{ref:z,style:ge},c.createElement("div",{ref:W,className:r,style:o,children:t}))))}else{var O;(O=x.current)==null||O.render(c.createElement("div",{ref:W,style:re,className:r,children:t}))}});const he=c.useRef(!0);We(X=>{if(U.current){C.updateMatrixWorld(),U.current.updateWorldMatrix(!0,!1);const O=h?G.current:_(U.current,C,j);if(h||Math.abs(Se.current-C.zoom)>n||Math.abs(G.current[0]-O[0])>n||Math.abs(G.current[1]-O[1])>n){const me=on(U.current,C);let ee=!1;V&&(Array.isArray(p)?ee=p.map(ae=>ae.current):
/*
This shader is from the THREE's SpriteMaterial.
We need to turn the backing plane into a Sprite
(make it always face the camera) if "transfrom"
is false.
*/
#include <common>
void main() {
vec2 center = vec2(0., 1.);
float rotation = 0.0;
// This is somewhat arbitrary, but it seems to work well
// Need to figure out how to derive this dynamically if it even matters
float size = 0.03;
vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
vec2 scale;
scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
if ( isPerspective ) scale *= - mvPosition.z;
vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;
vec2 rotatedPosition;
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
mvPosition.xy += rotatedPosition;
gl_Position = projectionMatrix * mvPosition;
}
`,fragmentShader:`
void main() {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
`}),[h]);return c.createElement("group",dt({},D,{ref:U}),p&&!V&&c.createElement("mesh",{castShadow:y,receiveShadow:I,ref:w},L||c.createElement("planeGeometry",null),S||c.createElement("shaderMaterial",{side:Ht,vertexShader:q.vertexShader,fragmentShader:q.fragmentShader})))});function un(t,n,o,r){var s;return s=class extends Gt{constructor(i){super({vertexShader:n,fragmentShader:o,...i});for(const d in t)this.uniforms[d]=new Ut(t[d]),Object.defineProperty(this,d,{get(){return this.uniforms[d].value},set(l){this.uniforms[d].value=l}});this.uniforms=Yt.clone(this.uniforms)}},s.key=Jt.generateUUID(),s}const pn=()=>parseInt(qt.replace(/\D+/g,"")),hn=pn(),fn=un({cellSize:.5,sectionSize:1,fadeDistance:100,fadeStrength:1,fadeFrom:1,cellThickness:.5,sectionThickness:1,cellColor:new ut,sectionColor:new ut,infiniteGrid:!1,followCamera:!1,worldCamProjPosition:new ve,worldPlanePosition:new ve},`
varying vec3 localPosition;
varying vec4 worldPosition;
uniform vec3 worldCamProjPosition;
uniform vec3 worldPlanePosition;
uniform float fadeDistance;
uniform bool infiniteGrid;
uniform bool followCamera;
void main() {
localPosition = position.xzy;
if (infiniteGrid) localPosition *= 1.0 + fadeDistance;
worldPosition = modelMatrix * vec4(localPosition, 1.0);
if (followCamera) {
worldPosition.xyz += (worldCamProjPosition - worldPlanePosition);
localPosition = (inverse(modelMatrix) * worldPosition).xyz;
}
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,`
varying vec3 localPosition;
varying vec4 worldPosition;
uniform vec3 worldCamProjPosition;
uniform float cellSize;
uniform float sectionSize;
uniform vec3 cellColor;
uniform vec3 sectionColor;
uniform float fadeDistance;
uniform float fadeStrength;
uniform float fadeFrom;
uniform float cellThickness;
uniform float sectionThickness;
float getGrid(float size, float thickness) {
vec2 r = localPosition.xz / size;
vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);
float line = min(grid.x, grid.y) + 1.0 - thickness;
return 1.0 - min(line, 1.0);
}
void main() {
float g1 = getGrid(cellSize, cellThickness);
float g2 = getGrid(sectionSize, sectionThickness);
vec3 from = worldCamProjPosition*vec3(fadeFrom);
float dist = distance(from, worldPosition.xyz);
float d = 1.0 - min(dist / fadeDistance, 1.0);
vec3 color = mix(cellColor, sectionColor, min(1.0, sectionThickness * g2));
gl_FragColor = vec4(color, (g1 + g2) * pow(d, fadeStrength));
gl_FragColor.a = mix(0.75 * gl_FragColor.a, gl_FragColor.a, g2);
if (gl_FragColor.a <= 0.0) discard;
#include <tonemapping_fragment>
#include <${hn>=154?"colorspace_fragment":"encodings_fragment"}>
}
`),xn=c.forwardRef(({args:t,cellColor:n="#000000",sectionColor:o="#2080ff",cellSize:r=.5,sectionSize:s=1,followCamera:i=!1,infiniteGrid:d=!1,fadeDistance:l=100,fadeStrength:a=1,fadeFrom:u=1,cellThickness:h=.5,sectionThickness:p=1,side:g=Qt,...y},I)=>{Xt({GridMaterial:fn});const S=c.useRef(null);c.useImperativeHandle(I,()=>S.current,[]);const L=new Zt,F=new ve(0,1,0),_=new ve(0,0,0);We(A=>{L.setFromNormalAndCoplanarPoint(F,_).applyMatrix4(S.current.matrixWorld);const D=S.current.material,W=D.uniforms.worldCamProjPosition,B=D.uniforms.worldPlanePosition;L.projectPoint(A.camera.position,W.value),B.value.set(0,0,0).applyMatrix4(S.current.matrixWorld)});const v={cellSize:r,sectionSize:s,cellColor:n,sectionColor:o,cellThickness:h,sectionThickness:p},$={fadeDistance:l,fadeStrength:a,fadeFrom:u,infiniteGrid:d,followCamera:i};return c.createElement("mesh",dt({ref:S,frustumCulled:!1},y),c.createElement("gridMaterial",dt({transparent:!0,"extensions-derivatives":!0,side:g},v,$)),c.createElement("planeGeometry",{args:t}))});function mn({vector:t,origin:n=[0,0,0],color:o="#facc15"}){const{dir:r,len:s,position:i}=c.useMemo(()=>{const l=new ve(...n),a=new ve(...t),u=l.distanceTo(a);return{dir:a.clone().sub(l).normalize(),len:u,position:l}},[t,n]),d=c.useMemo(()=>new Kt(r,i,s,o,.2*Math.min(s,1)+.1,.1*Math.min(s,1)+.05),[r,s,i,o]);return e.jsx("primitive",{object:d})}function gn(t,n=!1){const o=[];for(let r=0;r<=t;r++)for(let s=0;s<=t-r;s++){const i=t-r-s;if(i>=0)if(!n)o.push([r,s,i]);else{const d=r===0?[1]:[1,-1],l=s===0?[1]:[1,-1],a=i===0?[1]:[1,-1];for(const u of d)for(const h of l)for(const p of a)o.push([r*u,s*h,i*p])}}return o}function bn({vector:t,radius:n,distance:o,color:r}){const{position:s,quaternion:i}=c.useMemo(()=>{const d=new ve(...t).normalize(),l=new ve(0,1,0),a=new en().setFromUnitVectors(l,d);return{position:d.clone().multiplyScalar(o/2),quaternion:a}},[t,o]);return e.jsxs("mesh",{position:s,quaternion:i,children:[e.jsx("cylinderGeometry",{args:[n,n,o,32]}),e.jsx("meshStandardMaterial",{color:r,opacity:.5,transparent:!0})]})}function yn({complexity:t,lightlanes:n=!1,radius:o=.5,distance:r=5,allSectors:s=!1,cumulative:i=!1}){const d=c.useMemo(()=>{const a=[],u=i?1:t,h=t;for(let p=u;p<=h;p++){const g=gn(p,s);for(const y of g)a.push({vec:y,c:p})}return a},[t,s,i]),l=a=>{const u=i?Math.max(t,1):t;return`hsl(${270*(1-(u>1?(a-1)/(u-1):1))}, 100%, 50%)`};return e.jsx("group",{children:d.map((a,u)=>{const h=i?l(a.c):n?"#ff33c5":"#4ade80";return n?e.jsx(bn,{vector:a.vec,radius:o,distance:r,color:h},`cyl-${u}-${a.vec.join(",")}-${a.c}`):e.jsx(mn,{vector:a.vec,color:h},`vec-${u}-${a.vec.join(",")}-${a.c}`)})})}const vn="glitch:play-sound",Sn="glitch:stop-sound",ke={click:"ui.button_click",hover:"ui.button_hover",computeStart:"machine.compute_start",computeStep:"machine.compute_step",computeDone:"machine.compute_done"};function Bt(t,n){typeof window>"u"||window.dispatchEvent(new CustomEvent(t,{detail:n}))}function Ie(t,n,o){try{if(t?.playSound){t.playSound(n,o);return}}catch{}Bt(vn,{id:n,payload:o})}function jn(t,n,o){try{if(t?.stopSound){t.stopSound(n,o);return}}catch{}Bt(Sn,{id:n,payload:o})}const Ue=1e-12;function ct(t=123456789){let n=t>>>0;return function(){n|=0,n=n+1831565813|0;let r=Math.imul(n^n>>>15,1|n);return r=r+Math.imul(r^r>>>7,61|r)^r,((r^r>>>14)>>>0)/4294967296}}function Mn(t,n=Math.random){if(!Number.isFinite(t)||t<=0)return 0;if(t<30){const d=Math.exp(-t);let l=0,a=1;do l++,a*=n();while(a>d);return l-1}const o=Math.max(1e-12,n()),r=n(),s=Math.sqrt(-2*Math.log(o))*Math.cos(2*Math.PI*r),i=t+Math.sqrt(t)*s;return Math.max(0,Math.round(i))}function ot(t){return[t[0]??t.x,t[1]??t.y,t[2]??t.z]}function wn(t,n,o){return Math.sqrt(t*t+n*n+o*o)}function Rt(t){const n=2*Math.PI;let o=t%n;return o<0&&(o+=n),o}function Pn(t){const n=2*t()-1,o=2*Math.PI*t();return{theta:Math.acos(Math.max(-1,Math.min(1,n))),phi:o}}function ht(t){const n=2*Math.PI;let o=t%n;return o<0&&(o+=n),o>Math.PI&&(o=n-o),o}function Mt(t=Math.random){const n=Math.max(1e-12,t()),o=t();return Math.sqrt(-2*Math.log(n))*Math.cos(2*Math.PI*o)}function Fn(t,
@keyframes flyToDistribution {
0% {
transform: translate(0, 0) scale(1);
opacity: 0.95;
}
40% {
transform: translate(calc(var(--delta-x) * 0.3), calc(var(--delta-y) * 0.5)) scale(0.9);
opacity: 0.9;
}
85% {
transform: translate(calc(var(--delta-x) * 0.95), calc(var(--delta-y) * 0.95)) scale(0.7);
opacity: 0.85;
}
100% {
transform: translate(var(--delta-x), var(--delta-y)) scale(0.6);
opacity: 0;
}
}
.clickable-bar {
transition: all 0.2s ease;
}
.clickable-bar:hover {
transform: scaleY(1.1) scaleX(1.2);
filter: brightness(1.3);
box-shadow: 0 0 10px currentColor;
}
`})]})}function nt(){return{n:0,meanObs:0,m2Obs:0,meanIso:0,m2Iso:0}}function qn(t,n,o){const r=t.n+1,s=n-t.meanObs,i=t.meanObs+s/r,d=t.m2Obs+s*(n-i),l=o-t.meanIso,a=t.meanIso+l/r,u=t.m2Iso+l*(o-a);return{n:r,meanObs:i,m2Obs:d,meanIso:a,m2Iso:u}}function Xn({complexity:t,radius:n,distance:o,theta:r,phi:s,observationMode:i,allSectors:d,cumulative:l,K:a,orbitRadius:u,orbitVelocity:h,thetaDrift:p,thetaJitter:g,phiJitter:y,usePoisson:I,speedup:S,paused:L,sceneView:F,bottomInset:_=0,showNumericDiagnostics:v=!0,compactNumericDiagnostics:$=!1,host:A,centerDistribution:D=!1,hideFlyingBars:W=!1}){const[B,C]=c.useState({current:0,total:0,lastCheck:0,overlaps:0,currentTheory:0,binOverlapsMean:0,currentExpectedLightlane:0}),te=4,j=c.useMemo(()=>Lt({D:u,theta:r,phi:s,observationMode:i,velocity:h,thetaDrift:p,thetaJitter:g,phiJitter:y,distance:o,hitTestModel:"segment",bin_size:1,complexity:t,sub_bin_sampling:te,flux:a,lane_radius:n,allSectors:d,cumulative:l,usePoisson:I}),[u,r,s,i,h,p,g,y,t,a,n,o,d,l,I]),N=60,H=c.useRef(new Array(N).fill(-1)),R=c.useRef(new Array(N).fill(-1)),E=c.useRef(0),[x,U]=c.useState(new Array(N).fill(-1)),[Se,G]=c.useState(new Array(N).fill(-1)),b=It({flux:a,D:u,lane_radius:n,dt:1,hitTestModel:"segment",lane_length:o}),z=Math.sqrt(b),k=15,w=4*z,K=Math.max(0,b-w),V=b+w,re=I,ge=Math.max(0,Math.floor(K)),he=Math.max(ge,Math.ceil(V)),q=re?he-ge+1:k,X=re?1:Math.max(1e-9,(V-K)/k),O=m=>{if(re){const M=Math.round(m);return M<=ge?0:M>=he?q-1:M-ge}return m<K?0:m>=V?q-1:Math.floor((m-K)/X)},me=m=>re?ge+m:K+(m+.5)*X,[ee,fe]=c.useState(new Array(q).fill(0)),[ce,Y]=c.useState(new Array(q).fill(0)),[ae,ie]=c.useState(new Set),[Be,Ce]=c.useState(new Set),[Le,Te]=c.useState([]),Re=c.useRef(0),$e=c.useRef(nt()),[J,_e]=c.useState(nt()),be=c.useRef(L),Ze=c.useRef(0);c.useEffect(()=>{fe(new Array(q).fill(0)),Y(new Array(q).fill(0)),H.current.fill(-1),R.current.fill(-1),E.current=0,U(new Array(N).fill(-1)),G(new Array(N).fill(-1)),ie(new Set),Ce(new Set),Te([]),$e.current=nt(),_e(nt()),C({current:0,total:0,lastCheck:0,overlaps:0,currentTheory:0,binOverlapsMean:0,currentExpectedLightlane:0})},[t,a,n,o,u,r,s,i,h,p,g,y,d,l,I,q]);const Qe=(m,M)=>{if(m.length===0)return;let T=0,le=0,se=0,je=B.binOverlapsMean,Q=B.currentExpectedLightlane,de=$e.current;for(const ue of m){const Me=ue.lightlane,we=ue.isotropic;if(T+=Me,le=Me,se=we,je=ue.overlapsMean,Q=ue.lambdaLightlaneExpected,de=qn(de,Me,we),H.current[E.current]=Me,R.current[E.current]=we,E.current++,E.current>=N){const Ee=Math.max(10,...H.current.filter(oe=>oe>=0),...R.current.filter(oe=>oe>=0));ne([...H.current],[...R.current],Ee),H.current.fill(-1),R.current.fill(-1),E.current=0,ie(new Set),Ce(new Set)}}$e.current=de,C(ue=>({current:le,total:ue.total+T,lastCheck:Date.now(),overlaps:M,currentTheory:se,binOverlapsMean:je,currentExpectedLightlane:Q})),_e(de),U([...H.current]),G([...R.current])},Ne=c.useRef(!1),He=c.useRef(null),Ke=(m,M)=>{m.stopPropagation(),Ne.current=!0,He.current=M,m.target.setPointerCapture(m.pointerId),Ie(A,ke.click,{target:`${M}-periodogram`,action:"pointer-down"})},et=(m,M,T,le)=>{if(!Ne.current||He.current!==M)return;m.stopPropagation();const se=m.currentTarget.getBoundingClientRect(),je=m.clientX-se.left,Q=Math.floor(je/se.width*N);if(Q>=0&&Q<N){const de=T[Q],ue=M==="observed"?ae.has(Q):Be.has(Q);de>=0&&!ue&&Z(Q,de,M,le)}},f=m=>{m.stopPropagation(),Ne.current=!1,He.current=null},P=(m,M,T,le)=>{const se=window.innerWidth,je=m/N*se,Q=se/N,de=Math.max(2,M/le*80),we=T==="observed"?25:110,Ee=O(M),oe=20,Pe=se-2*oe,ze=oe+(Ee+.5)/q*Pe;return{startLeft:je,startBottom:we,barHeight:de,barWidth:Q,targetLeft:ze,targetTop:150,binIndex:Ee}},Z=(m,M,T,le)=>{if(M<0)return;const se=Date.now();se-Ze.current>=45&&(Ze.current=se,Ie(A,ke.computeStep,{target:`${T}-periodogram`,value:M}));const{startLeft:je,startBottom:Q,barHeight:de,barWidth:ue,targetLeft:Me,targetTop:we}=P(m,M,T,le),Ee={id:Re.current++,value:M,startLeft:je,startBottom:Q,barHeight:de,barWidth:ue,targetLeft:Me,targetTop:we,color:T==="observed"?pe.solid:xe.solid,type:T};Te(oe=>[...oe,Ee]),T==="observed"?(ie(oe