// ==UserScript== // @name Singularity // @namespace https://github.com/shmidtqq65/singularity // @version 1.0.0 // @description A black hole that eats any website. Press Alt+S to open it, Esc or Alt+S again to put the page back. // @author shmidtqq // @license MIT // @homepageURL https://github.com/shmidtqq65/singularity // @downloadURL https://raw.githubusercontent.com/shmidtqq65/singularity/main/userscript/singularity.user.js // @updateURL https://raw.githubusercontent.com/shmidtqq65/singularity/main/userscript/singularity.user.js // @match *://*/* // @grant none // @run-at document-idle // @noframes // ==/UserScript== (function () { 'use strict'; function run() { (()=>{'use strict';const t=window,n=document,o=t.__singularity;if(o&&o.alive)return void o.toggle();const e='@shmidtqq',s=2*Math.PI,r=!!t.__SG_MANUAL,a=Object.assign({sound:!0,hud:!0,autostart:!0},t.__SG_OPTIONS||{}),i=(t,n,o)=>to?o:t,c=(t,n,o)=>t+(n-t)*o,l=(t,n)=>void 0===n?Math.random()*t:t+Math.random()*(n-t),h=t=>t<=0?0:t>=1?1:t*t*(3-2*t),f=()=>performance.now(),u=t=>1-Math.pow(1-i(t,0,1),3),M=t=>Math.round(t).toLocaleString('en-US');function p(t,n,o){const e=nt.r?n-t.r:0,s=ot.b?o-t.b:0;return Math.sqrt(e*e+s*s)}const d=new Map;let g=null;function m(t){if(!t)return[0,0,0,0];let o=d.get(t);if(o)return o;const e=/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/.exec(t);if(e){let t=void 0===e[4]?1:+e[4];e[5]&&(t/=100),o=[+e[1],+e[2],+e[3],t]}else if('transparent'===t)o=[0,0,0,0];else try{if(!g){const t=n.createElement('canvas');t.width=t.height=1,g=t.getContext('2d',{willReadFrequently:!0})}g.clearRect(0,0,1,1),g.fillStyle='#000',g.fillStyle=t,g.fillRect(0,0,1,1);const e=g.getImageData(0,0,1,1).data;o=[e[0],e[1],e[2],e[3]/255]}catch(t){o=[128,128,128,1]}return d.size>3e3&&d.clear(),d.set(t,o),o}const b='lighter',w='source-over',y=(t,n)=>{t.globalCompositeOperation=n},v=(t,n)=>'rgba('+(0|t[0])+','+(0|t[1])+','+(0|t[2])+','+(void 0===n?t[3]:n)+')';function x(t){if(!t||'none'===t)return null;const n=[],o=/rgba?\([^)]+\)|#[0-9a-f]{3,8}\b|oklch\([^)]+\)|hsla?\([^)]+\)/gi;let e;for(;(e=o.exec(t))&&n.length<6;){const t=m(e[0]);t[3]>.05&&n.push(t)}return n.length?n:null}const S=[[0,[255,64,10]],[.3,[255,118,24]],[.55,[255,182,72]],[.78,[255,236,196]],[1,[206,228,255]]],k=[],E=[];for(let t=0;t<64;t++){const n=t/63;let o=0;for(;oS[o+1][0];)o++;const e=S[o],s=S[o+1],r=(n-e[0])/(s[0]-e[0]),a=[c(e[1][0],s[1][0],r),c(e[1][1],s[1][1],r),c(e[1][2],s[1][2],r)];E.push(a),k.push('rgb('+(0|a[0])+','+(0|a[1])+','+(0|a[2])+')')}const T=t=>0|i((t-.25)/.75*63,0,63),A=n.documentElement;let C=t.innerWidth,R=t.innerHeight,I=A.clientWidth||C,F=Math.min(t.devicePixelRatio||1,2),L=.5;const N=!(!t.matchMedia||!t.matchMedia('(pointer: coarse)').matches),O=!!(t.CSS&&CSS.highlights&&t.Highlight),W='sg-void';let G=null;const P={alive:!0,phase:'play',paused:!1,hud:!1!==a.hud,o:!1,t:0,frame:0,u:f(),host:(location.hostname||'this page').replace(/^www\./,'')},U={tokens:0,shown:0,chars:0,images:0,blocks:0,merged:0,made:0,radiated:0};let B=[],D=0;const H=[],q=[],z=[],j=[];let V=0,$=[],K=0,Y=0,X=0,J=0,_='255,255,255',Q=0,Z=0,tt=0,nt=0,ot=0,et=0,st=null,rt=0;const at=new Map,it=new WeakMap;function ct(t,n,o){let e=at.get(t);e||(e=new Map,at.set(t,e),it.has(t)||it.set(t,t.getAttribute('style'))),e.has(n)||e.set(n,[t.style.getPropertyValue(n),t.style.getPropertyPriority(n)]),t.style.setProperty(n,o,'important')}function lt(t,n){const o=at.get(t);if(!o||!o.has(n))return;const e=o.get(n);e[0]?t.style.setProperty(n,e[0],e[1]):t.style.removeProperty(n),o.delete(n),o.size||(at.delete(t),ft(t))}let ht=null;function ft(t){const o=it.get(t);if(void 0===o)return;const e=t.getAttribute('style');if(null!==o){if(e!==o)try{ht||(ht=n.createElement('div')),ht.setAttribute('style',o),ht.style.cssText&&ht.style.cssText===t.style.cssText&&t.setAttribute('style',o)}catch(t){}}else''===e&&t.removeAttribute('style')}function ut(t){const n=at.get(t);if(n){for(const[o,e]of n)e[0]?t.style.setProperty(o,e[0],e[1]):t.style.removeProperty(o);at.delete(t),ft(t)}}const Mt=[];function pt(t,n,o){Mt.push(t,n,o)}const dt=new Map;function gt(t,n){let o=dt.get(t);o||(o=new Set,dt.set(t,o)),t.hasAttribute(n)||(t.setAttribute(n,''),o.add(n))}let mt=null;const bt=[];function wt(t){if(mt)try{if(!t.adoptedStyleSheets||t.adoptedStyleSheets.indexOf(mt)>=0)return;t.adoptedStyleSheets=t.adoptedStyleSheets.concat([mt]),bt.push(t)}catch(t){}}const yt=[],vt=new Map;function xt(t){let n=vt.get(t);return void 0===n&&(n=yt.length,yt.push(t),vt.set(t,n),j.push([])),n}let St=new WeakMap;function kt(t){let n=1,o=t,e=0;const s=[];for(;o&&1===o.nodeType&&e<40;){const t=St.get(o);if(void 0!==t){n=t;break}s.push(o),o=o.parentElement||o.parentNode&&o.parentNode.host||null,e++}for(let t=s.length-1;t>=0;t--){let o=1;try{o=parseFloat(getComputedStyle(s[t]).opacity)}catch(t){}n*=isNaN(o)?1:o,St.set(s[t],n)}return n}let Et=new WeakMap;function Tt(t,n){let o=Et.get(t);if(o)return o;n=n||getComputedStyle(t);const e=parseFloat(n.fontSize)||16,s=(n.fontStyle&&'normal'!==n.fontStyle?n.fontStyle+' ':'')+('small-caps'===n.fontVariantCaps?'small-caps ':'')+(n.fontWeight||'400')+' '+e+'px '+(n.fontFamily||'sans-serif');let r=m(n.color);const a=n.webkitTextFillColor;if(a&&a!==n.color){const t=m(a);if(t[3]>.05)r=t;else{const t=x(n.backgroundImage);r=t?t[0]:[235,235,235,1]}}return o={M:xt(s),p:r,size:e,op:kt(t),tt:n.textTransform||'none'},o.op>=.03&&Et.set(t,o),o}let At=new WeakSet,Ct=new WeakMap,Rt=new WeakMap;const It=new Set,Ft=new Set;let Lt=new WeakSet;const Nt=[],Ot=new Set;let Wt=[],Gt=0;function Pt(t){t.done||Ot.has(t)||(Ot.add(t),Wt.push(t))}function Ut(t,n){let o=Ct.get(t);o||(o=[],Ct.set(t,o)),o.push(n),Pt(n)}const Bt=/\s/;let Dt=null;try{Dt=new Intl.Segmenter(void 0,{granularity:'grapheme'})}catch(t){Dt=null}class Ht{constructor(t,o,e){this.kind=0,this.node=t,this.S=o,this.T=e,this.seed=100*Math.random(),this.A(),this.r=n.createRange()}A(){const t=this.node.data;this.data=t;const n=[],o=[],e=[],s=this.T.tt;let r=!0;const a=(t,a)=>{const i=Bt.test(t);if(!i){let i=t;'uppercase'===s?i=t.toUpperCase():'lowercase'===s?i=t.toLowerCase():'capitalize'===s&&r&&(i=t.toUpperCase()),n.push(a),o.push(t.length),e.push(i)}r=i};if(Dt&&t.length<2e4)for(const n of Dt.segment(t))a(n.segment,n.index);else{let n=0;for(const o of t)a(o,n),n+=o.length}this.C=n,this.len=o,this.ch=e,this.n=n.length,this.rel=new Float32Array(4*this.n),this.R=0,this.I=new Uint8Array(this.n),this.F=0,this.L=-1,this.N=-1,this.O=this.O||[],this.W=1+(0|this.W),this.done=0===this.n,this.G=this.G||!1}rect(){const t=this.node;if(!t.isConnected)return null;if(t.data!==this.data&&(this.P(),this.done))return null;this.r.selectNodeContents(t);const n=this.r.getBoundingClientRect();return n.width||n.height?(this.U={l:n.left,t:n.top,r:n.right,b:n.bottom,w:n.width,h:n.height},this.U):null}P(){for(const t of this.O)try{G&&G.delete(t)}catch(t){}this.O=[],this.A()}measure(t){t.w===this.L&&t.h===this.N||(this.R=0,this.L=t.w,this.N=t.h);const n=this.r,o=this.node,e=this.rel;for(;this.Ret));){const s=this.R;try{n.setStart(o,this.C[s]),n.setEnd(o,this.C[s]+this.len[s]);const r=n.getBoundingClientRect();e[4*s]=r.left-t.l,e[4*s+1]=r.top-t.t,e[4*s+2]=r.width,e[4*s+3]=r.height}catch(t){e[4*s+2]=0}this.R++}return this.R}}const qt={IMG:'img',VIDEO:'video',CANVAS:'canvas',IFRAME:'frame',EMBED:'frame',OBJECT:'frame',INPUT:'input',TEXTAREA:'input',SELECT:'input',METER:'input',PROGRESS:'input'},zt={SCRIPT:1,STYLE:1,NOSCRIPT:1,TEMPLATE:1,HEAD:1,META:1,LINK:1,TITLE:1,BR:1,WBR:1,SOURCE:1,TRACK:1,PARAM:1,AREA:1,MAP:1,DATALIST:1,OPTION:1,OPTGROUP:1,SLOT:0};function jt(t){let n;try{n=t.getBoundingClientRect()}catch(t){return null}return n&&(n.width||n.height)?{l:n.left,t:n.top,r:n.right,b:n.bottom,w:n.width,h:n.height}:null}class Vt{constructor(t,n,o){this.kind=1,this.S=t,this.type=n,this.seed=100*Math.random(),this.done=!1,this.B=o&&o.objectFit||'fill',this.filter=o&&o.filter&&'none'!==o.filter?o.filter:'',this.p=o?m(o.color):[120,120,120,1],this.D=o?m(o.backgroundColor):[0,0,0,0],this.H=!0}rect(){return jt(this.S)}}class $t{constructor(t,n,o){this.kind=2,this.S=t,this.seed=100*Math.random(),this.done=!1,this.D=m(n.backgroundColor),this.grad=x(n.backgroundImage),this.q=o,this.j=null,this.V=!1;const e=Math.max(parseFloat(n.borderTopWidth)||0,parseFloat(n.borderRightWidth)||0,parseFloat(n.borderBottomWidth)||0,parseFloat(n.borderLeftWidth)||0),s=m(n.borderTopColor),r=m(n.borderBottomColor),a=m(n.borderLeftColor);this.L=e,this.$=s[3]>.05?s:r[3]>.05?r:a,this.H='inline'!==n.display&&'contents'!==n.display&&'table-row'!==n.display&&'table-cell'!==n.display}rect(){return jt(this.S)}K(){if(this.V||!this.q)return;this.V=!0;const t=new Image;t.decoding='async',t.onload=()=>{this.j=t},t.src=this.q}}class Kt{constructor(t,n){this.kind=3,this.S=t,this.Y=n,this.done=!1,this.seed=100*Math.random()}rect(){return jt(this.S)}}class Yt{constructor(t,n){this.kind=4,this.S=t,this.done=!1;const o=Tt(t,n);this.T=o;const e=n.listStyleType;this.ch='circle'===e?'◦':'square'===e?'▪':'disc'===e?'•':'decimal'===e?((t=>{let n=1,o=t;for(;o=o.previousElementSibling;)'LI'===o.tagName&&n++;const e=t.parentElement;return e&&e.start>1&&(n+=e.start-1),n})(t)||1)+'.':'•';const s=parseFloat(n.lineHeight);this.lh=isNaN(s)?1.3*o.size:s,this.X='inside'===n.listStylePosition}rect(){return jt(this.S)}J(t){return{x:this.X?t.l+.5*this.T.size:t.l-.75*this.T.size,y:t.t+this.lh/2}}}function Xt(t){if(!t||'none'===t||'normal'===t)return null;const n=/^"((?:[^"\\]|\\.)*)"$/.exec(t.trim());if(n){const t=n[1].replace(/\\(.)/g,'$1');return/\S/.test(t)?{text:t}:null}return/url\(/.test(t)||/counter|attr/.test(t)?{box:!0}:null}let Jt=0;function _t(t){return t&&t.hasAttribute&&t.hasAttribute('data-singularity')}function Qt(t,n){for(let o=t.firstChild;o;o=o.nextSibling)if(3===o.nodeType&&!Rt.has(o)&&/\S/.test(o.data)){const e=Tt(t,n);if(e.op<.03)continue;const s=new Ht(o,t,e);Rt.set(o,s),It.add(s),Ut(t,s)}}function Zt(t,o){if(At.has(t)||_t(t))return;if(--Jt<0&&!o)return;At.add(t);const e=t.tagName;if(!e||zt[e])return;if(t===A||t===n.body){try{Qt(t,getComputedStyle(t))}catch(t){}return}if(t instanceof SVGElement){if(t.ownerSVGElement){const n=(t=>{let n=t;for(;n&&n.ownerSVGElement;)n=n.ownerSVGElement;return n&&n.tagName&&'svg'===n.tagName.toLowerCase()?n:null})(t);return void(n&&!At.has(n)&&Zt(n,o))}let n=null;try{n=getComputedStyle(t)}catch(t){}if(n&&('none'===n.display||'hidden'===n.visibility))return;const e=new Vt(t,'svg',n);e.p=n?m(n.color):e.p;const s=n?m(n.fill):null;return s&&s[3]>.05&&'none'!==n.fill&&(e.p=s),void Ut(t,e)}let s;try{s=getComputedStyle(t)}catch(t){return}if('none'===s.display)return void At.delete(t);const r=qt[e];if(r){if('hidden'===s.visibility)return;if('INPUT'===e&&'hidden'===t.type)return;return void Ut(t,new Vt(t,r,s))}if('hidden'!==s.visibility){Qt(t,s);const n=m(s.backgroundColor),o=s.backgroundImage,r=s.boxShadow&&'none'!==s.boxShadow,a=(parseFloat(s.borderTopWidth)||0)+(parseFloat(s.borderBottomWidth)||0)+(parseFloat(s.borderLeftWidth)||0)+(parseFloat(s.borderRightWidth)||0)>.3&&(m(s.borderTopColor)[3]>.05||m(s.borderBottomColor)[3]>.05||m(s.borderLeftColor)[3]>.05);let i=null;if(o&&'none'!==o){const t=/url\(["']?([^"')]+)["']?\)/.exec(o);t&&(i=t[1])}(n[3]>.04||o&&'none'!==o||a||r)&&Ut(t,new $t(t,s,i));const c=[];for(const n of['::before','::after']){let o;try{o=getComputedStyle(t,n)}catch(t){o=null}if(!o||'none'===o.display)continue;const e=Xt(o.content);e&&c.push({which:n,text:e.text||null,box:!!e.box,T:e.text?tn(o):null,p:m(o.color),D:m(o.backgroundColor)})}c.length&&Ut(t,new Kt(t,c)),'LI'===e&&'list-item'===s.display&&'none'!==s.listStyleType&&'none'===s.listStyleImage&&Ut(t,new Yt(t,s))}const a=t.shadowRoot;let i=o;if(!i){const n=jt(t);i=n&&n.w*n.h{const n=Ct.get(t);if(n)for(const t of n)t.done||Pt(t);for(let n=t.firstChild;n;n=n.nextSibling)if(3===n.nodeType&&!Rt.has(n)&&/\S/.test(n.data)){try{Qt(t,getComputedStyle(t))}catch(t){}break}})(t);if(Zt(t,!1),!At.has(t))return;const s=t.shadowRoot;if(s&&s.elementsFromPoint&&(0|e)<6){wt(s);let r=null;try{r=s.elementsFromPoint(n,o)}catch(t){r=null}if(r)for(const s of r)s!==t&&nn(s,n,o,1+(0|e))}}function on(t,o){if(t<0||o<0||t>=I||o>=R)return;let e;try{e=n.elementsFromPoint(t,o)}catch(t){return}for(let n=0;net)return;const n=t.pi++,e=o*Math.sqrt(.6180339887498949*n%1),s=2.399963229728653*n+t.phase;on(t.x+Math.cos(s)*e,t.y+Math.sin(s)*e)}}function sn(t,n){let o=null,e=1e18;for(const s of B){if(!s.alive)continue;const r=(s.x-t)*(s.x-t)+(s.y-n)*(s.y-n);r=t.n&&(t.done=!0);const a=t.T;wn(r,t.ch[o],a.M,a.p,a.op,e,s,t.rel[4*o+3]||a.size,.25),Nt.push({k:0,c:t,i:o,g:t.W}),U.chars++,ot--,Lt.has(t.S)||(t=>{let o=t,e=0;for(;o&&o!==A&&o!==n.body&&e<6;){if(!Lt.has(o)){Lt.add(o);try{const t=getComputedStyle(o);t.textDecorationLine&&'none'!==t.textDecorationLine&&pt(o,'text-decoration-color','transparent')}catch(t){}}o=o.parentElement,e++}})(t.S)}const hn=new Map;function fn(t,n,o,e){const s=t.S,r=o.x-(n.l+n.r)/2,a=o.y-(n.t+n.b)/2,c=Math.hypot(r,a)||1,l=i(1-p(n,o.x,o.y)/(1.1*o.rcap),0,1)*o.Z;if(l<=.01)return;const h=(e?11:7)*l,f=t.seed,u=r/c*h+Math.sin(41*P.t+f)*h*.22,M=a/c*h+Math.cos(37*P.t+1.7*f)*h*.22;pt(s,'translate',u.toFixed(1)+'px '+M.toFixed(1)+'px'),pt(s,'rotate',(Math.sin(23*P.t+f)*l*2.4).toFixed(2)+'deg'),hn.set(s,P.frame)}function un(t){for(let n=0;nR+40||n.r<-40||n.l>I+40)return 0!==t.kind&&un(t.S),!1;let o=null,e=1e9;for(const t of B){if(!t.alive||t.Z<.25)continue;const s=p(n,t.x,t.y)/t._;s1.12)return 0!==t.kind&&un(t.S),!1;switch(t.kind){case 0:{if(!t.G&&s>o.rcap)return!0;if(0===t.measure(n))return!0;const e=o.rcap,r=e*e,a=t.rel,i=o.x,c=o.y,l=o.nt;for(let s=0;s.55)continue}else{const t=h-i,n=f-c,o=t*t+n*n;if(o>r)continue;const s=Math.sqrt(o)/e,a=s<.5?.85*l+.15:(1-s)/.5*.45*l;if(Math.random()>a)continue}if(ot<=0||an()>=rn())return!0;ln(t,s,h,f,sn(h,f)||o)}return!t.done}case 1:{const e=Math.max(n.w,n.h),r=t.G||'collapse'===P.phase||e<=o.cap;return r&&(t.G||s<.4*o.rcap)&&an(){t.done=!0;const e=t.S,s=(t=>{const n=t.S;try{if('img'===t.type)return n.complete&&n.naturalWidth>0?{src:n,nw:n.naturalWidth,nh:n.naturalHeight,B:t.B,filter:t.filter}:null;if('video'===t.type)return n.readyState>=2?{src:n,nw:n.videoWidth,nh:n.videoHeight,B:'fill'===t.B?'contain':t.B}:null;if('canvas'===t.type)return n.width&&n.height?{src:n,nw:n.width,nh:n.height,B:'fill'}:null}catch(t){}return null})(t);if((t=>{pt(t,'visibility','hidden')})(e),un(e),xn(n,o,s,'svg'===t.type?t.p:'input'===t.type?t.D[3]>.1?t.D:[235,236,240,1]:'frame'===t.type?[30,32,38,1]:[150,156,166,1],'input'===t.type?4:Math.max(1,n.w*n.h/750),'img'===t.type||'svg'===t.type||'video'===t.type),'input'===t.type){const e=(t=>{const n=t.tagName,o=((t.type||'')+'').toLowerCase();return'SELECT'===n?t.selectedIndex>=0&&t.options[t.selectedIndex]?t.options[t.selectedIndex].text+'':'':'TEXTAREA'===n?(t.value||t.placeholder||'')+'':'INPUT'!==n?'':'password'===o?t.value?'••••••••':(t.placeholder||'')+'':/^(hidden|file|checkbox|radio|range|color|image)$/.test(o)?'':(t.value||t.placeholder||'')+''})(t.S).slice(0,40);if(e){let s;try{s=Tt(t.S)}catch(t){s=null}if(s){let t=n.l+8;for(const r of e)' '!==r&&wn(o,r,s.M,s.p,s.op,t,n.t+n.h/2,s.size,.25),t+=.55*s.size}}}'input'!==t.type&&'frame'!==t.type&&U.images++,Nt.push({k:1,S:e}),Po.ot(Math.min(1,Math.sqrt(n.w*n.h)/400))})(t,n,o),!1):(s<1.1*o.rcap&&t.H&&e<.7*Math.min(I,R)&&fn(t,n,o,r),!0)}case 2:{const e=n.w*n.h;if(e>I*R*.55&&'collapse'!==P.phase)return!0;if(e>I*R*.92)return!1;t.q&&!t.j&&t.K();const r=Math.max(n.w,n.h),a=t.G||'collapse'===P.phase||r<=1.1*o.cap,i=Math.hypot((n.l+n.r)/2-o.x,(n.t+n.b)/2-o.y),c=Math.hypot(n.w,n.h);return a&&(t.G||(c<1.3*o.rcap?s<.32*o.rcap:i<.6*o.rcap))&&an(){t.done=!0;const e=t.S;un(e);const s=t.j?{src:t.j,nw:t.j.naturalWidth,nh:t.j.naturalHeight,B:'cover'}:null;s?xn(n,o,s,t.D,Math.max(1,n.w*n.h/1500),!1):(t.D[3]>.04||t.grad)&&vn(n,o,t.D[3]>.04?t.D:null,t.grad),t.L>.3&&t.$[3]>.05&&((t,n,o,e)=>{const s=Math.max(1.5,Math.min(e,4)),r=Math.max(1,Math.round(t.w/34)),a=Math.max(1,Math.round(t.h/34));for(let e=0;e{Jt=3e3;const n=t=>{At.has(t)||Zt(t,!0);const o=Ct.get(t);if(o)for(const t of o)t.done||(t.G=!0,Pt(t));if(!('svg'===t.tagName||t instanceof SVGElement)){for(let o=t.firstElementChild;o;o=o.nextElementSibling){if(Jt--<0)return;n(o)}if(t.shadowRoot)for(let o=t.shadowRoot.firstElementChild;o;o=o.nextElementSibling)n(o)}};n(t)})(e)})(t,n,o),!1):(t.H&&s<1.1*o.rcap&&r<.6*Math.min(I,R)&&fn(t,n,o,a),!0)}case 3:return!t.G&&s>.75*o.rcap||an()>=rn()||(((t,n,o)=>{t.done=!0,gt(t.S,'data-sg-np');const e=!t.S.firstChild||1===t.S.childNodes.length&&3===t.S.firstChild.nodeType&&!/\S/.test(t.S.firstChild.data);for(const s of t.Y){const t=e?(n.l+n.r)/2:'::before'===s.which?n.l+6:n.r-6,r=e?(n.t+n.b)/2:n.t+Math.min(n.h,24)/2;if(s.text&&s.T){let n=t-(s.text.length-1)*s.T.size*.3;for(const t of s.text)t.trim()&&wn(o,t,s.T.M,s.T.p,1,n,r,s.T.size,.25),n+=.6*s.T.size}else s.box&&yn(t-6,r-6,12,12,s.D[3]>.05?s.D:s.p,o,.5)}Nt.push({k:3,S:t.S})})(t,n,o),!1);case 4:{const e=t.J(n),s=Math.hypot(e.x-o.x,e.y-o.y);return!t.G&&s>.8*o.rcap||(((t,n,o,e)=>{t.done=!0,gt(t.S,'data-sg-nm'),wn(o,t.ch,t.T.M,t.T.p,t.T.op,e.x,e.y,t.T.size,.25),Nt.push({k:4,S:t.S})})(t,0,o,e),!1)}}return!1}function pn(t){if(ot<=0)return;let n=60;for(const o of Ot){if(0!==o.kind||o.done||!o.U||n<=0)continue;const e=o.U,s=p(e,t.x,t.y),r=Math.hypot(Math.max(Math.abs(e.l-t.x),Math.abs(e.r-t.x)),Math.max(Math.abs(e.t-t.y),Math.abs(e.b-t.y)));if(!(t.rr+26)&&0!==o.measure(e))for(let s=0;s0;s++){if(o.I[s]||0===o.rel[4*s+2])continue;const r=e.l+o.rel[4*s]+o.rel[4*s+2]/2,a=e.t+o.rel[4*s+1]+o.rel[4*s+3]/2,i=Math.hypot(r-t.x,a-t.y);if(Math.abs(i-t.r)>26)continue;if(Math.random()>.5*t.et)continue;const c=sn(r,a);if(!c||an()>=rn())return;ln(o,s,r,a,c),n--}}}function dn(){for(let t=0;t0){ct(t.S,'color','transparent'),ct(t.S,'-webkit-text-fill-color','transparent');const n=Ct.get(t.S);if(n)for(const t of n)0!==t.kind||t.done||(t.G=!0,Pt(t))}Ft.clear();for(const[t,n]of hn)n!==P.frame&&un(t)}const gn=[];function mn(){return gn.pop()||{}}function bn(t,n,o,e,s){t.st=-l(10,60)*s,t.rt=(l(30,110)+.35*n.rcap)*s,t.it=l(-35,35)*s+.2*n.vx,t.ct=l(-35,25)*s-l(0,45)*s+.2*n.vy,t.vx=t.it,t.vy=t.ct}function wn(t,n,o,e,s,r,a,c,h){const f=mn();f.k=0,f.ch=n,f.M=o,f.p=e,f.lt=i(s*(void 0===e[3]?1:e[3]),0,1),f.x=r,f.y=a,f.a=0,f.ht=l(-5,5),f.ft=0,f.t=0,f.h=t,f.ut=c,f.Mt=h,f.T=1,f.dt=1,f.gt=l(.75,1.35),f.bt=-1,f.wt='',bn(f,t,0,0,1),j[o].push(f),V++}function yn(t,n,o,e,s,r,a){const i=mn();i.k=2,i.x=t+o/2,i.y=n+e/2,i.w=o,i.yt=e,i.p=s,i.lt=void 0===s[3]?1:s[3],i.a=0,i.ht=l(-3,3),i.ft=0,i.t=0,i.h=r,i.Mt=a||.2,i.T=1,i.dt=1,i.gt=l(.8,1.3),i.ut=Math.max(o,e),i.bt=-1,i.wt='',bn(i,r,0,0,.8),z.push(i)}function vn(t,n,o,e){const s=i(Math.sqrt(t.w*t.h/48),9,34),r=Math.max(1,Math.round(t.w/s)),a=Math.max(1,Math.round(t.h/s)),c=t.w/r,l=t.h/a;for(let s=0;sd[n*(M+1)+t];let m;const b=Math.min(1,Math.sqrt(22e5/f));try{m=n.createElement('canvas'),m.width=Math.ceil(c*b),m.height=Math.ceil(h*b);const t=m.getContext('2d');t.scale(b,b),e.filter&&(t.filter=e.filter),((t,n,o,e)=>{let s=o,r=e,a=0,i=0;const c=n.nw,l=n.nh;if(c&&l&&'fill'!==n.B){let t=1;'contain'===n.B||'scale-down'===n.B?t=Math.min(o/c,e/l):'cover'===n.B&&(t=Math.max(o/c,e/l)),'scale-down'===n.B&&(t=Math.min(1,t)),s=c*t,r=l*t,a=(o-s)/2,i=(e-r)/2}t.drawImage(n.src,a,i,s,r)})(t,e,c,h)}catch(n){return void vn(t,o,s,null)}const w=[];for(let t=0;t900)return;const a=mn();a.k=3,a.x=t,a.y=n,a.vx=o,a.vy=e,a.Et=s,a.t=0,a.Tt=r,q.push(a)}function kn(t,n){let o=t.h;if(!(o&&o.alive||(o=t.h=o&&o.At&&o.At.alive?o.At:sn(t.x,t.y),o)))return t.vy+=900*n,t.x+=t.vx*n,t.y+=t.vy*n,t.lt*=.97,t.y.02;const e=t.x-o.x,r=t.y-o.y,a=Math.sqrt(e*e+r*r)+1e-4;if(a<.92*o.Ct)return!1;const c=Math.atan2(r,e),l=Math.sqrt(o.Rt/Math.max(a,o.Ct)),h=i(1.3-a/(1.15*o.rcap),0,1),f=i((t.t-2)/3,0,1),u=l*(.13+.17*h+.6*f)*t.gt,M=Math.min(1,(.8+3.6*h)*n),p=Math.min(1,(1.6+2.8*h+4*f)*n);t.rt+=(.97*l-t.rt)*M,t.st+=(-u-t.st)*p;const d=Math.min(1,(.7+5.5*h)*n);t.it+=(o.vx-t.it)*d,t.ct+=(o.vy-t.ct)*d;let g=a+t.st*n;const m=g<.92*o.Ct;m&&(g=.9*o.Ct);const b=c+t.rt*o.It/(.5*(a+g))*n,w=Math.cos(b),y=Math.sin(b);t.x+=t.it*n+(g*w-e),t.y+=t.ct*n+(g*y-r);const v=w*o.It;if(t.vx=t.it+w*t.st+-y*o.It*t.rt,t.vy=t.ct+y*t.st+v*t.rt,m)return!1;const x=i((1.1*o.rcap-a)/Math.max(1,1.1*o.rcap-1.2*o.Ct),0,1);t.ft+=(x-t.ft)*Math.min(1,(x>t.ft?2.4:.5)*n);const S=Math.hypot(t.st,t.rt);return t.T=1+Math.min(2.8,S/520)*t.ft*t.ft,t.dt=1-.5*t.ft*t.ft,t.a+=((t,n)=>{let o=t-n;for(;o>Math.PI;)o-=s;for(;o<-Math.PI;)o+=s;return o})(Math.atan2(t.vy-o.vy,t.vx-o.vx),t.a)*Math.min(1,5*t.ft*n)+t.ht*n*(1-t.ft),t.t+=n,!0}function En(t){const n=t.h;if(n&&n.alive&&(n.m+=6*t.Mt,n.Ft+=1,Math.random()<.18)){const o=t.x-n.x,e=t.y-n.y,s=Math.hypot(o,e)||1,r=n.It*l(200,500);Sn(n.x+o/s*n.Ct,n.y+e/s*n.Ct,-e/s*r+n.vx,o/s*r+n.vy,l(.2,.5),0|l(30,63))}U.tokens+=t.Mt,Po.Lt()}function Tn(t){const n=Math.min(I,R),o='collapse'===P.phase;let e=10+1.12*Math.sqrt(t.m);var s;e=Math.min(e,n*(o?.16:.105)),t.Z=(s=i(s=t.Nt,0,1),1+2.6*Math.pow(s-1,3)+1.6*Math.pow(s-1,2)),t.Ct=e*t.Z;let r=(3*e+40+5.5*Math.min(t.age,24)+(t.Ot||0))*t.Z;o&&t.boost&&(r=Math.max(r,c(r,.75*Math.hypot(I,R),t.boost))),t.rcap=Math.max(1,r),t._=1.65*t.rcap,t.cap=o?1e9:5.2*e+40+2.2*Math.sqrt(t.m);const a=Math.min(t.rcap,.5*n);t.Rt=39.47841760435743*a*a*a/(1.35*1.35)*Math.max(.05,t.Z),t.nt=i(.35+.25*t.age,.35,1)}function An(t,n,o){if(!isFinite(t)||!isFinite(n))return null;if(B.filter(t=>t.alive).length>=7)return oo('max 7 holes. drag them together to merge'),null;const e={id:++D,x:t,y:n,vx:0,vy:0,Wt:t,Gt:n,m:o||70,It:Math.random()<.5?-1:1,age:0,Nt:0,Z:0,alive:!0,drag:!1,Ft:0,Pt:0,pi:1e3*Math.random()|0,phase:l(s),At:null,Ut:l(s),boost:0,Ct:0,rcap:0,_:0,cap:0,Rt:0,nt:.35};return Tn(e),B.push(e),U.made++,Hn(e),Po.Bt(),H.push({x:t,y:n,r:0,v:420,max:210,et:.55,Et:0,Dt:!0,p:'255,236,210'}),e}function Cn(t,n){const o=t.m>=n.m?t:n,e=o===t?n:t,r=t.m+n.m;o.x=(t.x*t.m+n.x*n.m)/r,o.y=(t.y*t.m+n.y*n.m)/r,o.vx=(t.vx*t.m+n.vx*n.m)/r+l(-60,60),o.vy=(t.vy*t.m+n.vy*n.m)/r+l(-60,60),o.m=.95*r,U.radiated+=.05*r,o.Pt=1,(e.drag||o.drag)&&(o.drag=!0,vo&&vo.h===e&&(vo.h=o)),e.alive=!1,e.At=o,qn(e),U.merged++,K=Math.min(18,K+10+.05*Math.sqrt(r)),Q=1,Z=o.x,tt=o.y,nt=Math.max(260,2.6*o.rcap),H.push({x:o.x,y:o.y,r:o.Ct,v:1100,max:.7*Math.hypot(I,R),et:1,Et:0,Dt:!0,p:'255,248,236'}),H.push({x:o.x,y:o.y,r:.5*o.Ct,v:760,max:.45*Math.hypot(I,R),et:.6,Et:0,Dt:!1,p:'190,220,255'});for(let t=0;t<70;t++){const t=l(s),n=l(250,1100);Sn(o.x,o.y,Math.cos(t)*n,Math.sin(t)*n,l(.3,.9),0|l(35,63))}Po.Ht(Math.min(1,.5+Math.sqrt(r)/200)),oo('merged · 5% of the mass left as a gravitational wave')}let Rn,In,Fn,Ln,Nn,On;const Wn=new Map;let Gn=!1,Pn=[null,null];function Un(t,o,e){const s=n.createElement(t);s.setAttribute('data-singularity','');const r=s.style,a=(t,n)=>r.setProperty(t,n,'important');a('all','initial'),a('position','fixed'),a('left','0'),a('top','0'),a('margin','0'),a('padding','0'),a('border','0'),a('pointer-events','none'),a('z-index',2147483e3+o+''),a('display','block');for(const t in e||{})a(t,e[t]);return s}function Bn(){let o=0,e=0;if(Rn){const t=Rn.getBoundingClientRect();o=t.width,e=t.height}o&&e||(o=A.clientWidth||t.innerWidth,e='CSS1Compat'===n.compatMode&&A.clientHeight||t.innerHeight),C=o,R=e,I=Math.min(A.clientWidth||o,o),F=Math.min(t.devicePixelRatio||1,2),C*R*F*F>83e5&&(F=Math.max(1,Math.sqrt(83e5/(C*R)))),L=Math.min(.6,.5*F),Fn&&(Fn.width=Math.round(C*F),Fn.height=Math.round(R*F),In.width=Math.round(C*L),In.height=Math.round(R*L))}function Dn(t){const o=192,e=n.createElement('canvas');e.width=e.height=o;const s=e.getContext('2d'),r=s.createImageData(o,o);for(let n=0;n1e-4){const n=Math.pow(c,1.25)*Math.pow(1-c,.75)*3.1,o=.9*t,e=-.6;l=(-a/c*o+s/c*e)*n,h=(s/c*o+a/c*e)*n}const f=4*(n*o+e);r.data[f]=i(128+127*l,0,255),r.data[f+1]=i(128+127*h,0,255),r.data[f+2]=128,r.data[f+3]=255}return s.putImageData(r,0,0),e.toDataURL('image/png')}function Hn(t){const o=Un('div',2,{width:'1000px',height:'1000px','border-radius':'50%',background:'radial-gradient(circle closest-side, rgba(3,3,9,0.985) 0%, rgba(3,3,9,0.96) 24%, rgba(5,4,13,0.84) 40%, rgba(6,5,15,0.55) 56%, rgba(6,5,15,0.25) 72%, rgba(6,5,15,0.07) 88%, rgba(6,5,15,0) 100%)','transform-origin':'0 0','will-change':'transform'});A.insertBefore(o,In);const e={qt:o,lens:null,zt:null,jt:null,scale:-1};if(Gn){const o='http://www.w3.org/2000/svg',s='sg-lens-'+t.id+'-'+(1e6*Math.random()|0),r=(t,e)=>{const s=n.createElementNS(o,t);for(const t in e)s.setAttribute(t,e[t]);return s},a=r('filter',{id:s,x:0,y:0,width:1,height:1,primitiveUnits:'objectBoundingBox','color-interpolation-filters':'sRGB'}),i=r('feImage',{href:Pn[t.It>0?0:1],x:0,y:0,width:1,height:1,preserveAspectRatio:'none',result:'m'}),c=r('feDisplacementMap',{in:'SourceGraphic',in2:'m',scale:.1,xChannelSelector:'R',yChannelSelector:'G'});a.appendChild(i),a.appendChild(c),On.appendChild(a);const l=Un('div',3,{width:'1000px',height:'1000px','border-radius':'50%','backdrop-filter':'url(#'+s+')','-webkit-backdrop-filter':'url(#'+s+')','mask-image':'radial-gradient(circle closest-side, #000 55%, transparent 100%)','-webkit-mask-image':'radial-gradient(circle closest-side, #000 55%, transparent 100%)','transform-origin':'0 0','will-change':'transform'});A.insertBefore(l,In),e.lens=l,e.zt=a,e.jt=c}Wn.set(t,e)}function qn(t){const n=Wn.get(t);n&&(n.qt.remove(),n.lens&&n.lens.remove(),n.zt&&n.zt.remove(),Wn.delete(t))}let zn=null,jn=null;function Vn(){const t=384,o=n.createElement('canvas');o.width=o.height=t;const e=o.getContext('2d'),s=e.createImageData(t,t),r=64,a=new Float32Array(r*r);for(let t=0;t{const o=0|(t=(t%r+r)%r),e=0|(n=(n%r+r)%r),s=t-o,i=n-e,l=a[(e+1)%r*r+o],h=a[(e+1)%r*r+(o+1)%r],f=s*s*(3-2*s),u=i*i*(3-2*i);return c(c(a[e*r+o],a[e*r+(o+1)%r],f),c(l,h,f),u)};for(let n=0;n=1||a<.16){s.data[c+3]=0;continue}const f=Math.atan2(r,e),u=.5+.5*Math.sin(3*f+9*Math.log(a)+2.4*l(14*a,4*f)),M=.6*l(40*a+3*f,18*f)+.4,p=Math.pow(1-a,1.6)*h((a-.16)/.12)*(.35+.65*u)*M,d=i(1-(a-.16)/.6,0,1),g=E[0|i(63*(.85*d+.1),0,63)];s.data[c]=g[0],s.data[c+1]=g[1],s.data[c+2]=g[2],s.data[c+3]=i(255*p*1.6,0,255)}e.putImageData(s,0,0),zn=o}function $n(t,n){const o=F*n.dt,e=Math.cos(n.a),s=Math.sin(n.a),r=n.T,a=1/Math.sqrt(n.T);t.setTransform(e*r*o,s*r*o,-s*a*o,e*a*o,(n.x+Y)*F,(n.y+X)*F)}function Kn(t){const n=15*i(t.ft/.62,0,1)|0;if(n!==t.bt){const o=t.p,e=E[0],s=n/15;t.wt='rgb('+(0|c(o[0],e[0],s))+','+(0|c(o[1],e[1],s))+','+(0|c(o[2],e[2],s))+')',t.bt=n}return t.wt}const Yn=Array.from({length:16},()=>[]);let Xn=0,Jn=-1;function _n(t,n){const o=(n.x+Y)*F,e=(n.y+X)*F,r=Math.max(.5,n.Ct*F*(n.Vt?n.$t:1));y(t,w),t.globalAlpha=1;const a=t.createRadialGradient(o,e,.9*r,o,e,2.6*r);a.addColorStop(0,'rgba(255,190,120,'+(.18+.25*n.Pt).toFixed(3)+')'),a.addColorStop(.35,'rgba(255,120,40,'+(.06+.1*n.Pt).toFixed(3)+')'),a.addColorStop(1,'rgba(255,80,20,0)'),y(t,b),t.fillStyle=a,t.beginPath(),t.arc(o,e,2.6*r,0,s),t.fill(),y(t,w);const i=t.createRadialGradient(o,e,.55*r,o,e,1.08*r);let c;i.addColorStop(0,'#000'),i.addColorStop(.8,'#000'),i.addColorStop(1,'rgba(0,0,0,0)'),t.fillStyle=i,t.beginPath(),t.arc(o,e,1.08*r,0,s),t.fill(),y(t,b);try{c=t.createConicGradient(.35*n.Ut+(n.It>0?0:Math.PI),o,e),c.addColorStop(0,'rgba(255,248,230,1)'),c.addColorStop(.25,'rgba(255,214,150,0.75)'),c.addColorStop(.5,'rgba(255,150,70,0.22)'),c.addColorStop(.75,'rgba(255,214,150,0.75)'),c.addColorStop(1,'rgba(255,248,230,1)')}catch(t){c='rgba(255,230,190,0.9)'}t.strokeStyle=c,t.lineWidth=Math.max(1.2*F,.075*r),t.globalAlpha=.95,t.beginPath(),t.arc(o,e,1.02*r,0,s),t.stroke(),t.lineWidth=Math.max(2*F,.26*r),t.globalAlpha=.22+.2*n.Pt,t.beginPath(),t.arc(o,e,1.12*r,0,s),t.stroke(),t.globalAlpha=1,y(t,w)}const Qn='ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',Zn='ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';let to=null;const no=[];function oo(t){st={msg:t,t:0}}function eo(t,n,o,e,s,r){t.beginPath(),t.roundRect?t.roundRect(n,o,e,s,r):(t.moveTo(n+r,o),t.arcTo(n+e,o,n+e,o+s,r),t.arcTo(n+e,o+s,n,o+s,r),t.arcTo(n,o+s,n,o,r),t.arcTo(n,o,n+e,o,r),t.closePath())}let so=null,ro=0;function ao(){const t=1200,o=630,r=330,a=322,c=76,h=Math.PI,u=n.createElement('canvas');u.width=t,u.height=o;const p=u.getContext('2d');p.fillStyle='#09090e',p.fillRect(0,0,t,o),p.fillStyle='#fff';for(let n=0;n<260;n++){p.globalAlpha=l(.15,.7);const n=l(.6,1.6);p.fillRect(l(t),l(o),n,n)}const d=[];for(let t=Nt.length-1;t>=0&&d.length<420;t--){const n=Nt[t];0===n.k&&n.g===n.c.W&&d.push(n.c.ch[n.i])}const g=n.createElement('canvas');g.width=t,g.height=o;const m=g.getContext('2d');y(m,b);const v=(t,n,o,e,s,i,c)=>{m.globalAlpha=i,m.strokeStyle=s,m.lineWidth=c,m.beginPath(),m.ellipse(r,a,t,n,0,o,e),m.stroke()},x=t=>{for(let n=0;n<110;n++){const o=n/109,e=c*(1.5+2.7*o),s=Math.pow(1-o,1.3),r=t?0:h;v(e,.115*e,r,r+h,k[0|i(63*(.12+.78*s),0,63)],(.02+.12*s)*l(.5,1),1.3+1.2*s),o<.3&&v(e,.115*e,t?.55*h:h,t?h:1.45*h,'#fff',.09*(1-o/.3),2)}};x(!1);for(let t=0;t<80;t++){const n=t/79,o=c*(1.04+.7*n),e=k[0|i(63*(.18+.62*(1-n)),0,63)],s=(.03+.22*Math.pow(1-n,1.6))*l(.6,1);v(1.04*o,o,h,2*h,e,s,1.7),n<.3&&v(1.02*o,.97*o,.06*h,.94*h,e,s/2,1.7)}y(m,w),m.globalAlpha=1;const S=m.createRadialGradient(r,a,.7*c,r,a,78.28);S.addColorStop(.9,'#000'),S.addColorStop(1,'rgba(0,0,0,0)'),m.fillStyle=S,m.beginPath(),m.arc(r,a,78.28,0,s),m.fill(),y(m,b),v(78.66,78.66,0,s,'#fff4de',.95,1.6),v(80.56,80.56,0,s,'#ffd296',.25,6),x(!0),m.textAlign='center',m.textBaseline='middle',d.forEach((t,n)=>{const o=n%3,e=c*l(1.6,4.5),s=.115*e,f=(o?l(.06,.94):l(1.06,1.94))*h,u=r+Math.cos(f)*e,M=a+Math.sin(f)*s,p=i(1-(e/c-1.6)/2.9,0,1);!o&&Math.hypot(u-r,M-a)<1.1*c||(m.setTransform(1,0,0,1,u,M),m.rotate(Math.atan2(Math.cos(f)*s,-Math.sin(f)*e)),m.scale(1.7,.42),m.globalAlpha=(.25+.55*p)*(.73+.27*Math.cos(f)),m.fillStyle=k[0|i(63*(.3+.65*p),0,63)],m.font='600 '+(10+5*p|0)+'px '+Zn,m.fillText(t,0,0))}),p.globalAlpha=1,p.drawImage(g,0,0),y(p,b);try{p.filter='blur(10px)',p.globalAlpha=.5,p.drawImage(g,0,0),p.filter='blur(34px)',p.globalAlpha=.32,p.drawImage(g,0,0),p.filter='none'}catch(t){}y(p,w),p.globalAlpha=1;const E=(t,n,o,e,s)=>{p.font=e,p.fillStyle=s,p.fillText(t,n,o)},T=P.host.length>24?P.host.slice(0,23)+'…':P.host;return E('SINGULARITY',640,112,'700 15px '+Qn,'#ffb35c'),E('I fed '+T,640,170,'800 44px '+Zn,'#f6f1e8'),E('to a black hole.',640,222,'800 44px '+Zn,'#f6f1e8'),[[U.tokens,'tokens ingested'],[U.images,1===U.images?'image':'images'],[U.merged,1===U.merged?'hole merged':'holes merged'],[0,'humans asked']].forEach((t,n)=>{const o=640+n%2*250,e=300+104*(n>>1);E(M(t[0]),o,e,'800 46px '+Zn,'#f6f1e8'),E(t[1],o,e+28,'500 15px '+Qn,'rgba(246,241,232,.55)')}),E('ate it in '+(()=>{const t=Math.max(0,Math.round((f()-P.u)/1e3));return Math.floor(t/60)+':'+(t%60+'').padStart(2,'0')})()+' · github.com/shmidtqq65/singularity',640,560,'500 14px '+Qn,'rgba(246,241,232,.45)'),E(e,640,584,'500 14px '+Qn,'#ffb35c'),u}function io(){try{(so||ao()).toBlob(t=>{if(!t)return;const o=n.createElement('a');o.href=URL.createObjectURL(t),o.download='singularity-'+P.host.replace(/[^a-z0-9.-]/gi,'_')+'.png',o.setAttribute('data-singularity',''),A.appendChild(o),o.click(),setTimeout(()=>{URL.revokeObjectURL(o.href),o.remove()},4e3)},'image/png')}catch(t){oo('could not save the image on this page')}}let co=0,lo=0;function ho(){if('play'===P.phase){P.phase='collapse',P.paused=!1,P.o=!1,co=0,B.some(t=>t.alive)||An(I/2,R/2,400);for(const t of B)t.drag=!1;vo=null,oo('collapse')}}let fo=0,uo=null,Mo=!1;function po(t){if('white'===P.phase)return void(t&&(Mo=!0));const n=P.phase;P.paused=!1,P.phase='white',P.o=!1,Mo=!!t,fo=0,vo=null;let o=null,e=-1;for(const t of B)t.alive&&t.m>e&&(e=t.m,o={x:t.x,y:t.y});uo=o||{x:I/2,y:R/2};for(const t of B)t.alive=!1,qn(t);B=[];for(const t of j){for(const n of t)gn.push(n);t.length=0}for(const t of z)t.vt=null,gn.push(t);z.length=0,V=0,$=[];const s=[];for(let t=Nt.length-1;t>=0;t--){const n=Nt[t];if(0===n.k){const t=n.c;if(n.g!==t.W||!t.node.isConnected||s.length>5e3)continue;let o=null;try{t.r.setStart(t.node,t.C[n.i]),t.r.setEnd(t.node,t.C[n.i]+t.len[n.i]),o=t.r.getBoundingClientRect()}catch(t){o=null}if(!o||o.bottom<0||o.top>R||o.right<0||o.left>I||!o.width&&!o.height)continue;s.push({k:0,c:t,i:n.i,ch:t.ch[n.i],M:t.T.M,p:t.T.p,x1:o.left+o.width/2,y1:o.top+o.height/2})}else if(1===n.k&&s.length<5400){const t=jt(n.S);t&&t.b>0&&t.t=o.x&&t<=o.x+o.w&&n>=o.y&&n<=o.y+o.h)return o;return null}function Eo(t){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()}function To(t){A.getAttribute('data-sg-cur')!==t&&A.setAttribute('data-sg-cur',t)}function Ao(t){if(!P.alive||!t.isTrusted)return;Po.resume();const n=t.clientX,o=t.clientY;if(n>=I)return;Eo(t);const e=ko(n,o);if(e)return void Oo(e.act);if(((t,n)=>P.hud&&'card'!==P.phase&&to&&t>=to.x&&t<=to.x+to.w&&n>=to.y&&n<=to.y+to.h)(n,o))return;if('play'!==P.phase&&'collapse'!==P.phase)return;if(2===t.button)return;const s=So(n,o);if(s)return void Co(s,t);if('touch'===t.pointerType)return void(xo={x:n,y:o,id:t.pointerId,t:f()});if('play'!==P.phase)return;const r=An(n,o);r&&Co(r,t)}function Co(t,n){t.drag=!0,t.o=!1,t.Wt=n.clientX,t.Gt=n.clientY,vo={h:t,id:n.pointerId,px:n.clientX,Qt:n.clientY,pt:f(),vx:0,vy:0},To('grabbing')}function Ro(t){if(!P.alive)return;const n=t.clientX,o=t.clientY;if(vo&&t.pointerId===vo.id){Eo(t);const e=f(),s=Math.max(1,e-vo.pt)/1e3;return vo.vx=c(vo.vx,(n-vo.px)/s,.35),vo.vy=c(vo.vy,(o-vo.Qt)/s,.35),vo.px=n,vo.Qt=o,vo.pt=e,vo.h.Wt=n,void(vo.h.Gt=o)}xo&&t.pointerId===xo.id&&Math.hypot(n-xo.x,o-xo.y)>10&&(xo=null),'mouse'===t.pointerType&&(ko(n,o)?To('pointer'):So(n,o)?To('grab'):To(''))}function Io(t){if(P.alive){if(vo&&t.pointerId===vo.id){Eo(t);const n=vo.h;n.drag=!1;const o=(f()-vo.pt)/1e3>.12?0:1;return n.vx=i(vo.vx*o,-2200,2200),n.vy=i(vo.vy*o,-2200,2200),vo=null,void To(So(t.clientX,t.clientY)?'grab':'')}xo&&t.pointerId===xo.id&&(Eo(t),'play'===P.phase&&f()-xo.t<450&&An(xo.x,xo.y),xo=null)}}function Fo(t){vo&&t.pointerId===vo.id&&(vo.h.drag=!1,vo=null,To('')),xo&&t.pointerId===xo.id&&(xo=null)}function Lo(t){P.alive&&t.isTrusted&&('touchstart'!==t.type&&'touchmove'!==t.type?Eo(t):vo&&t.preventDefault())}function No(t){if(!P.alive||t.ctrlKey||t.metaKey||t.altKey)return;const n=t.key;let o=!0;'Escape'===n?po(!0):'Enter'===n?'card'===P.phase?Oo('again'):ho():'h'===n||'H'===n?P.hud=!P.hud:'m'===n||'M'===n?(Po.toggle(),oo(Po.on?'sound on':'sound off')):'a'===n||'A'===n?'play'===P.phase&&yo():'p'===n||'P'===n?(P.paused=!P.paused,oo(P.paused?'paused':'resumed')):'r'===n||'R'===n?po(!1):'s'===n||'S'===n?'card'===P.phase&&!1!==a.save?io():o=!1:(' '===n||n.length>1)&&(o=!1),(o||1===n.length&&' '!==n)&&Eo(t)}function Oo(t){'close'===t?po(!0):'sound'===t?Po.toggle():'save'===t?io():'restore'===t?po(!1):'again'===t&&(P.phase='play',so=null,An(I/2,R/2,200))}const Wo=[];function Go(t,n,o,e){t.addEventListener(n,o,e),Wo.push([t,n,o,e])}const Po={ctx:null,Zt:null,on:!1!==a.sound,tn:null,hum:null,nn:null,en:null,sn:null,rn:null,an:0,cn:0,init(){if(!this.ctx)try{const n=t.AudioContext||t.webkitAudioContext;if(!n)return;const o=new n;this.ctx=o;const e=o.createDynamicsCompressor();e.threshold.value=-16,e.ratio.value=4;const s=o.createGain();s.gain.value=this.on?.55:0,s.connect(e),e.connect(o.destination),this.Zt=s;const r=2*o.sampleRate,a=o.createBuffer(1,r,o.sampleRate),i=a.getChannelData(0);for(let t=0;tt.alive);let o=0,e=0;for(const t of n)o=Math.max(o,Math.min(1,.25+Math.sqrt(t.m)/90)),e+=t.Pt;'collapse'===P.phase&&(o=Math.min(1.4,.8+co/6)),'card'!==P.phase&&'white'!==P.phase||(o=0);const s=this.ctx.currentTime;if(this.nn.gain.setTargetAtTime(this.on?.42*o:0,s,.25),this.en.frequency.setTargetAtTime(110+120*e+('collapse'===P.phase?90*co:0),s,.3),this.an+=t,this.ok()&&this.cn>0&&this.an>.035){const t=this.cn;this.ln(.03+.03*Math.random(),'bandpass',2400+3800*Math.random(),1.4,Math.min(.11,.016*Math.sqrt(t))),this.cn=0,this.an=0}},ot(t){if(this.ok()){for(let n=0;n<4;n++)this.ln(.06+.12*Math.random(),'highpass',1800+2500*Math.random(),.7,.12*(.4+t),.025*n+.02*Math.random());this.tone(160,50,.25,'sine',.22*(.3+t))}},Bt(){this.ok()&&(this.tone(220,36,.7,'sine',.35),this.ln(.45,'lowpass',600,.5,.12))},hn(t){if(!this.ctx||!this.sn)return;const n=this.ctx.currentTime;this.sn.frequency.setTargetAtTime(38+420*t*t,n,.05),this.rn.gain.setTargetAtTime(this.on?.16*t:0,n,.06)},Ht(t){this.ok()&&(this.tone(90,24,1.8,'sine',.7*t),this.tone(55,30,2.4,'triangle',.25*t),this.ln(1.2,'lowpass',420,.4,.4*t),this.ln(.35,'highpass',3e3,.4,.08*t,.02))},fn(){this.ok()&&(this.tone(120,20,3.2,'sine',.9),this.ln(2.6,'lowpass',900,.3,.55),[523.3,659.3,784,1046.5].forEach((t,n)=>this.tone(t,.995*t,2.6,'sine',.05,.25+.07*n)))},Jt(){this.ok()&&(this.tone(60,900,1.6,'sine',.22),[1046.5,1318.5,1568,2093].forEach((t,n)=>this.tone(t,t,1.8,'sine',.045,.1+.12*n)),this.ln(1.2,'highpass',4200,.5,.05))},close(){try{this.ctx&&this.ctx.close()}catch(t){}this.ctx=null}};let Uo=0,Bo=0;function Do(t){P.t+=t,P.paused?dn():function(t){P.frame++,P.frame%90==0&&(St=new WeakMap),(t=>{if(!P.o||'play'!==P.phase)return;mo+=t;let o=B.find(t=>t.alive);if(o||(o=An(I/2,.45*R,160),o)){if(o.o=!0,o.Wt=I/2+Math.sin(.37*mo)*I*.3+Math.sin(.91*mo)*I*.06,o.Gt=.48*R+Math.sin(.53*mo+1)*R*.24,wo||(wo=(()=>{const t=n.scrollingElement||A;if(t.scrollHeight>t.clientHeight+40)return t;let o=null,e=0;for(const t of n.querySelectorAll('body *')){if(t.clientHeight<.4*R)continue;const n=getComputedStyle(t);if(!/(auto|scroll)/.test(n.overflowY)||t.scrollHeight<=t.clientHeight+40)continue;const s=t.clientWidth*t.clientHeight;s>e&&(e=s,o=t)}return o||t})()),bo+=(Wt.length>60?18:70)*t,bo>=1){const t=Math.floor(bo);bo-=t;try{wo.scrollBy({top:t,behavior:'instant'})}catch(n){wo.scrollTop+=t}}wo.scrollTop>=wo.scrollHeight-wo.clientHeight-2&&mo>3?(P._t||(P._t=mo),mo-P._t>6&&(P.o=!1,ho())):P._t=0}})(t),(t=>{const n=B.filter(t=>t.alive);let o=0;for(let e=0;e.5&&a.Z>.5){Cn(r,a);continue}const h=i/l,f=c/l,u=.11*('collapse'===P.phase?3:1),M=u*a.Rt/(l*l+400),p=u*r.Rt/(l*l+400),d=3e3;r.vx+=h*Math.min(d,M)*t,r.vy+=f*Math.min(d,M)*t,a.vx-=h*Math.min(d,p)*t,a.vy-=f*Math.min(d,p)*t;const g=.8*(r.rcap+a.rcap);if(la.m?r.It:a.It,s=.55;r.vx+=-f*e*Math.min(d,M)*s*t,r.vy+=h*e*Math.min(d,M)*s*t,a.vx-=-f*e*Math.min(d,p)*s*t,a.vy-=h*e*Math.min(d,p)*s*t,o=Math.max(o,n)}}Po.hn(o);const e=I/2,s=R/2;for(const o of n){if(!o.alive)continue;if(o.age+=t,o.Nt=Math.min(1,o.Nt+t/.75),o.Ut+=t*(.6+.8*o.Pt)*o.It,o.drag){const n=260,e=2*Math.sqrt(n)*.85;o.vx+=((o.Wt-o.x)*n-o.vx*e)*t,o.vy+=((o.Gt-o.y)*n-o.vy*e)*t}else if('collapse'===P.phase||'implode'===P.phase){const n=9,r=2*Math.sqrt(n);o.vx+=((e-o.x)*n-o.vx*r)*t,o.vy+=((s-o.y)*n-o.vy*r)*t}else if(o.o){const n=14,e=2*Math.sqrt(n)*.9;o.vx+=((o.Wt-o.x)*n-o.vx*e)*t,o.vy+=((o.Gt-o.y)*n-o.vy*e)*t}else{const n=Math.exp(-.9*t);o.vx*=n,o.vy*=n}const n=2600,r=Math.hypot(o.vx,o.vy);r>n&&(o.vx*=n/r,o.vy*=n/r),o.x+=o.vx*t,o.y+=o.vy*t;const a=Math.max(8,.8*o.Ct);o.xI-a&&(o.x=I-a,o.vx=.55*-Math.abs(o.vx)),o.yR-a&&(o.y=R-a,o.vy=.55*-Math.abs(o.vy)),o.un=c(o.un||0,o.Ft/Math.max(t,.001),Math.min(1,2.5*t)),o.Ft=0,o.Pt+=(i(o.un/160,0,1)-o.Pt)*Math.min(1,2*t),o.age>1.5&&(o.Ot=i((o.Ot||0)+(o.un<25?22:-30)*t,0,.2*Math.min(I,R))),Tn(o)}B=B.filter(t=>t.alive||t.Vt)})(t),'play'!==P.phase&&'collapse'!==P.phase||(()=>{const t=f();et=t+('collapse'===P.phase?10:5.5),ot='collapse'===P.phase?520:240,Jt=900;const n=B.filter(t=>t.alive&&t.Z>.25);if(n.length){let t=30;'collapse'===P.phase&&(t=60);const o=Math.max(5,Math.floor(t/n.length));for(const t of n)en(t,o)}for(const t of H)if(t.Dt)for(let n=0;n<10;n++){const n=l(s);on(t.x+Math.cos(n)*t.r,t.y+Math.sin(n)*t.r)}const o=Wt.length;let e=0;for(;e=Wt.length&&(Gt=0);const t=Wt[Gt];let n=!1;try{n=Mn(t)}catch(t){n=!1}if(n?Gt++:(Ot.delete(t),Wt[Gt]=Wt[Wt.length-1],Wt.pop()),e++,f()>et+1.5)break}for(const t of H)t.Dt&&pn(t)})(),(t=>{let n=0;for(let o=0;o=e.Et?gn.push(e):(e.x+=e.vx*t,e.y+=e.vy*t,e.vx*=1-1.5*t,e.vy*=1-1.5*t,q[o++]=e)}q.length=o})(t),(t=>{for(let n=H.length-1;n>=0;n--){const o=H[n];o.r+=o.v*t,o.Et+=t,o.r>o.max&&H.splice(n,1)}})(t),dn(),(t=>{if('collapse'===P.phase){co+=t;const n=B.filter(t=>t.alive);if(1===n.length){const o=n[0];o.boost=i(o.boost+t/4.5,0,1);const e=Wt.length;(co>4&&o.boost>.85&&an()<40&&e<3||co>14)&&(P.phase='implode',lo=0,o.Vt=!0,o.$t=1)}}else if('implode'===P.phase){lo+=t;for(const t of B)t.Vt&&(t.$t=Math.max(0,1-u(lo/.7)));if(lo>.7){const t=B.find(t=>t.Vt),n=t?t.x:I/2,o=t?t.y:R/2;for(const t of B)t.alive=!1,t.Vt=!1,qn(t);B=[],J=1.1,_='255,252,245',K=22,H.push({x:n,y:o,r:0,v:1600,max:Math.hypot(I,R),et:1,Et:0,Dt:!1,p:'255,250,240'});for(let t=0;t<160;t++){const t=l(s),e=l(300,1600);Sn(n,o,Math.cos(t)*e,Math.sin(t)*e,l(.4,1.4),0|l(40,63))}Po.fn(),P.phase='card',so=null}}})(t)}(t),function(t){const o=Nn,r=Ln;if(!o)return;K>.05?(K*=Math.exp(-5.5*t),Y=Math.sin(71*P.t)*K,X=Math.cos(63*P.t)*K*.8):(K=0,Y=0,X=0),r.setTransform(1,0,0,1,0,0),y(r,'destination-out'),r.globalAlpha=1,r.fillStyle='rgba(0,0,0,'+(1-Math.pow(2e-5,t)).toFixed(3)+')',r.fillRect(0,0,In.width,In.height),y(r,b),jn||(()=>{const t=n.createElement('canvas');t.width=t.height=256;const o=t.getContext('2d');for(let t=0;t<70;t++){const t=Math.pow(Math.random(),3);o.globalAlpha=.35+.65*t,o.fillStyle=Math.random()<.15?'#ffd9b0':Math.random()<.3?'#cfe0ff':'#ffffff';const n=.6+1.6*t;o.fillRect(256*Math.random(),256*Math.random(),n,n)}jn=t})();for(const t of B){if(!t.alive&&!t.Vt)continue;const n=1.3*t.rcap*L*(t.Vt?t.$t:1);if(n<4)continue;const o=(t.x+Y)*L,e=(t.y+X)*L;r.save(),r.beginPath(),r.arc(o,e,n,0,s),r.clip(),r.globalAlpha=.16*t.Z;const a=jn.width,i=Math.floor((o-n)/a)*a,c=Math.floor((e-n)/a)*a;for(let t=i;t{if(t.ft<.18)return;const n=0|i((t.ft-.18)/.82*15,0,15);c[n].push(t)};for(let t=0;t.01&&o.drawImage(n.vt,n.xt,n.St,n.w,n.yt),n.ft>.2){y(o,b),o.globalAlpha=.9*h((n.ft-.2)/.6),o.fillStyle=k[T(n.ft)];const t=n.kt;o.beginPath(),o.moveTo(t[0][0],t[0][1]),o.lineTo(t[1][0],t[1][1]),o.lineTo(t[2][0],t[2][1]),o.closePath(),o.fill()}}else n.ft<.62&&(y(o,w),o.globalAlpha=n.lt*e,o.fillStyle=Kn(n),o.fillRect(-n.w/2,-n.yt/2,n.w,n.yt)),n.ft>.3&&(y(o,b),o.globalAlpha=.85*h((n.ft-.3)/.5),o.fillStyle=k[T(n.ft)],o.fillRect(-n.w/2,-n.yt/2,n.w,n.yt))}for(let t=0;t<2;t++){y(o,t?b:w);for(let n=0;n.62)continue;$n(o,n);const e=h((n.ft-.3)/.32);o.globalAlpha=t?Math.min(1,(.35+.65*n.lt)*e):n.lt*(1-e),o.fillStyle=t?k[T(n.ft)]:Kn(n),o.fillText(n.ch,0,0)}}}}o.setTransform(1,0,0,1,0,0),y(o,b);for(const t of q){const n=1-t.t/t.Et;o.globalAlpha=n,o.fillStyle=k[t.Tt];const e=(1.2+1.8*n)*F;o.fillRect((t.x+Y)*F-e/2,(t.y+X)*F-e/2,e,e)}if(o.globalAlpha=1,y(o,w),Q>.01){const n=(Z+Y)*F,e=(tt+X)*F,r=nt*F*(1.25-.25*Q),a=o.createRadialGradient(n,e,0,n,e,r);a.addColorStop(0,'rgba(255,252,240,'+(.95*Q).toFixed(3)+')'),a.addColorStop(.18,'rgba(255,214,150,'+(.6*Q).toFixed(3)+')'),a.addColorStop(.5,'rgba(255,140,60,'+(.18*Q).toFixed(3)+')'),a.addColorStop(1,'rgba(255,120,40,0)'),y(o,b),o.fillStyle=a,o.beginPath(),o.arc(n,e,r,0,s),o.fill(),y(o,w),Q*=Math.exp(-3.2*t)}for(const t of B)(t.alive||t.Vt)&&_n(o,t);for(const t of H){const n=(1-t.r/t.max)*t.et;n<=.01||(o.globalAlpha=.65*n,o.strokeStyle='rgb('+t.p+')',o.lineWidth=Math.max(1,2.2*F*n),o.beginPath(),o.arc((t.x+Y)*F,(t.y+X)*F,t.r*F,0,s),o.stroke())}y(o,w),o.globalAlpha=1,((t,n)=>{if('white'!==P.phase)return;fo+=n;const o=uo.x,e=uo.y,r=i(1-(fo-1.6)/1.2,0,1)*i(fo/.3,0,1);if(r>0){t.setTransform(1,0,0,1,0,0),y(t,b);const n=70*F*(.6+.4*r),a=t.createRadialGradient(o*F,e*F,0,o*F,e*F,2.2*n);a.addColorStop(0,'rgba(255,255,255,'+r+')'),a.addColorStop(.25,'rgba(225,238,255,'+.7*r+')'),a.addColorStop(1,'rgba(160,200,255,0)'),t.fillStyle=a,t.beginPath(),t.arc(o*F,e*F,2.2*n,0,s),t.fill()}let a=0,c=-1;t.textAlign='center',t.textBaseline='middle';for(const n of $){if(n.done)continue;const o=(fo-n.delay)/n.Xt;if(o<0){a++;continue}if(o>=1){if(n.done=!0,0===n.k){const t=n.c;t.I[n.i]&&(t.I[n.i]=0,t.F--,t.done=!1,cn(t))}else 1===n.k&&ut(n.S);continue}a++;const e=u(o),s=1-e,r=(1-e)*(1-e)*n.Kt+2*(1-e)*e*n.cx+e*e*n.x1,i=(1-e)*(1-e)*n.Yt+2*(1-e)*e*n.cy+e*e*n.y1;if(0===n.k)n.M!==c&&(t.font=yt[n.M],c=n.M),t.setTransform(F,0,0,F,r*F,i*F),y(t,w),t.globalAlpha=Math.min(1,4*o),t.fillStyle=v(n.p,1),t.fillText(n.ch,0,0),s>.25&&(y(t,b),t.globalAlpha=.9*(s-.25),t.fillStyle='#dceaff',t.fillText(n.ch,0,0));else{t.setTransform(F,0,0,F,r*F,i*F),y(t,b),t.globalAlpha=.5*(1-o),t.fillStyle='#dceaff';const s=.25+.75*e;t.fillRect(-n.w*s/2,-n.h*s/2,n.w*s,n.h*s)}}t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,y(t,w),(fo>.5&&0===a||fo>6)&&(()=>{if(go(),$=[],Mo)qo();else{P.phase='play',P.u=f();for(const t in U)U[t]=0;rt=7.5,oo('page restored · click to start again')}})()})(o,t),J>.003&&(o.globalAlpha=Math.min(1,J),o.fillStyle='rgb('+_+')',o.fillRect(0,0,Fn.width,Fn.height),J*=Math.exp(-('card'===P.phase?2.6:4.2)*t),o.globalAlpha=1),((t,n)=>{if(no.length=0,U.shown+=(U.tokens-U.shown)*Math.min(1,6*n),'card'===P.phase)return void((t,n)=>{so||(so=ao(),ro=0),ro+=n;const o=u(ro/.9),e=Math.min(.86*I,900)/1200,s=1200*e,r=630*e,i=(I-s)/2,c=Math.max(20,(R-r)/2-34)+18*(1-o);t.setTransform(F,0,0,F,0,0),t.globalAlpha=o,t.shadowColor='rgba(255,140,60,0.25)',t.shadowBlur=60,t.drawImage(so,i,c,s,r),t.shadowBlur=0,t.strokeStyle='rgba(255,255,255,0.12)',t.lineWidth=1,t.strokeRect(i+.5,c+.5,s-1,r-1);const l=[['save image','save'],['white hole · restore','restore'],['keep eating','again']].filter(t=>'save'!==t[1]||!1!==a.save);t.font='600 12px '+Qn;let h=0;const f=l.map(n=>t.measureText(n[0]).width+34);for(const t of f)h+=t+10;let M=(I-h+10)/2;const p=c+r+18;l.forEach((n,o)=>{const e=f[o];eo(t,M,p,e,34,17),t.fillStyle=1===o?'rgba(255,179,92,0.95)':'rgba(20,21,28,0.92)',t.fill(),t.strokeStyle='rgba(255,255,255,0.14)',t.stroke(),t.fillStyle=1===o?'#140c04':'#f6f1e8',t.textAlign='center',t.textBaseline='middle',t.fillText(n[0],M+e/2,p+17.5),no.push({x:M,y:p,w:e,h:34,act:n[1]}),M+=e+10}),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0)})(t,n);if(!P.hud)return;const o=I<560,r=o?204:238,c=112,l=I-r-(o?10:16),h=o?10:16;to={x:l,y:h,w:r,h:c},t.setTransform(F,0,0,F,0,0),y(t,w),t.globalAlpha=1,eo(t,l,h,r,c,12),t.fillStyle='rgba(8,9,14,0.84)',t.fill(),t.strokeStyle='rgba(255,255,255,0.10)',t.lineWidth=1,t.stroke(),t.fillStyle='rgba(255,170,90,'+(.6+.4*Math.sin(3*P.t)).toFixed(2)+')',t.beginPath(),t.arc(l+16,h+17,3.2,0,s),t.fill(),t.textAlign='left',t.textBaseline='middle',t.font='700 11px '+Qn,t.fillStyle='#f4efe6',t.fillText('SINGULARITY',l+26,h+17.5);const f=l+r-22,p=h+17;t.font='600 12px '+Qn,t.fillStyle='rgba(244,239,230,0.75)',t.textAlign='center',t.fillText('×',f,p+.5),no.push({x:f-9,y:p-9,w:18,h:18,act:'close'});{const n=f-26,o=p;t.fillStyle=t.strokeStyle=Po.on?'rgba(244,239,230,0.75)':'rgba(244,239,230,0.3)',t.beginPath(),t.moveTo(n-4,o-2),t.lineTo(n-1.5,o-2),t.lineTo(n+2,o-5),t.lineTo(n+2,o+5),t.lineTo(n-1.5,o+2),t.lineTo(n-4,o+2),t.closePath(),t.fill(),t.lineWidth=1.2,t.beginPath(),Po.on?(t.arc(n+3,o,3.2,-.9,.9),t.moveTo(n+5.6,o-4.6),t.arc(n+3,o,5.6,-.9,.9)):(t.moveTo(n+4,o-3),t.lineTo(n+9,o+3),t.moveTo(n+9,o-3),t.lineTo(n+4,o+3)),t.stroke()}no.push({x:f-35,y:p-9,w:20,h:18,act:'sound'});const d=[['TOKENS INGESTED',M(U.shown)],['MASS',(.8+U.shown/4e3).toFixed(2)+'×10⁶ M☉'],['HOLES · MERGED',B.filter(t=>t.alive).length+' · '+U.merged]];let g=h+40;for(const n of d)t.textAlign='left',t.font='500 9.5px '+Qn,t.fillStyle='rgba(244,239,230,0.48)',t.fillText(n[0],l+14,g),t.textAlign='right',t.font='600 11px '+Qn,t.fillStyle='#f4efe6',t.fillText(n[1],l+r-14,g),g+=17;t.textAlign='left',t.font='500 9px '+Qn,t.fillStyle='rgba(244,239,230,0.38)',t.fillText(P.o?'autopilot on · a to stop':U.tokens>1200?'enter: collapse it all':'esc: restore the page',l+14,h+c-13),t.textAlign='right',t.fillStyle='rgba(255,170,90,0.75)',t.fillText(e,l+r-14,h+c-13);const m=(n,o,e,s)=>{t.font='500 11px '+Qn;const r=t.measureText(n).width+28;t.globalAlpha=s,eo(t,(I-r)/2,o,r,28,14),t.fillStyle='rgba(8,9,14,0.84)',t.fill(),t.textAlign='center',t.fillStyle=e,t.fillText(n,I/2,o+14.5),t.globalAlpha=1};rt+=n,rt<7.5&&'play'===P.phase&&m(N?'tap: new hole · drag a hole to move it · two holes merge':'click: new hole · drag & throw · merge two · enter: collapse · esc: restore · a: autopilot · h: hide',R-52,'#f4efe6',i(Math.min(rt/.4,(7.5-rt)/.8),0,1)),st&&(st.t+=n,st.t>3.2?st=null:m(st.msg,22,'#ffd9a8',i(Math.min(st.t/.25,(3.2-st.t)/.6),0,1))),t.setTransform(1,0,0,1,0,0)})(o,t),(()=>{for(const[t,n]of Wn){if(!t.alive&&!t.Vt){qn(t);continue}const o=Math.max(1,2.7*t.rcap*(t.Vt?t.$t:1)),e=o/1e3,s='translate3d('+(t.x+Y-o/2).toFixed(1)+'px,'+(t.y+X-o/2).toFixed(1)+'px,0) scale('+e.toFixed(4)+')';if(n.qt.style.setProperty('transform',s,'important'),n.lens){const o=Math.max(1,3.3*t.rcap*(t.Vt?t.$t:1)),e=o/1e3;n.lens.style.setProperty('transform','translate3d('+(t.x+Y-o/2).toFixed(1)+'px,'+(t.y+X-o/2).toFixed(1)+'px,0) scale('+e.toFixed(4)+')','important');const s=(.17+.1*t.Pt)*t.Z;Math.abs(s-n.scale)>.004&&(n.jt.setAttribute('scale',s.toFixed(3)),n.scale=s)}}})(),Xn+=(('play'===P.phase?Math.min(.42,U.tokens/14e3):'white'===P.phase?0:'card'===P.phase?1:.92)-Xn)*Math.min(1,t*('white'===P.phase?1.8:.9)),Math.abs(Xn-Jn)>.004&&(Rn.style.setProperty('opacity',Xn.toFixed(3),'important'),Jn=Xn)}(P.paused?0:t),Po.update(t)}function Ho(n){if(!P.alive)return;Uo=t.requestAnimationFrame(Ho);const o=Bo?Math.min(.05,(n-Bo)/1e3):1/60;Bo=n;try{Do(o)}catch(n){if(t.__SG_DEBUG)throw n}}function qo(){P.alive=!1,Uo&&t.cancelAnimationFrame(Uo);try{go()}catch(t){}if(G)try{CSS.highlights.delete(W)}catch(t){}for(const[t,n,o,e]of Wo)t.removeEventListener(n,o,e);Wo.length=0;for(const[t]of Wn)qn(t);for(const t of[Rn,In,Fn,On])t&&t.remove();A.removeAttribute('data-sg-cur'),(()=>{for(const t of bt)try{t.adoptedStyleSheets=t.adoptedStyleSheets.filter(t=>t!==mt)}catch(t){}bt.length=0})(),Po.close(),zo.alive=!1}const zo={alive:!0,version:'1.0.0',toggle(){'white'===P.phase?qo():po(!0)},stop(){return qo()},restore(){return po(!1)},collapse(){return ho()},autopilot(){return yo()},addHole(t,n,o){return An(t,n,o)},step(t){return Do(t||1/60)},debug:{holes(){return B},drag(t,n,o){t&&(t.drag=!0,t.Wt=n,t.Gt=o)},release(t,n,o){t&&(t.drag=!1,t.vx=n||0,t.vy=o||0)}},stats(){return Object.assign({particles:an(),active:Wt.length,holes:B.filter(t=>t.alive).length,phase:P.phase,highlight:!!G,lens:Gn},U)},state:P};(()=>{if(!(n.body&&A instanceof HTMLElement))return P.alive=!1,void(zo.alive=!1);if((()=>{try{mt=new CSSStyleSheet,mt.replaceSync('::highlight('+W+'){color:transparent;-webkit-text-fill-color:transparent;text-shadow:none;background-color:transparent;text-decoration-color:transparent}[data-sg-np]::before,[data-sg-np]::after{visibility:hidden!important}[data-sg-nm]::marker{color:transparent!important}[data-sg-cur],[data-sg-cur] *{cursor:crosshair!important}[data-sg-cur] iframe,[data-sg-cur] embed,[data-sg-cur] object{pointer-events:none!important}[data-sg-cur=grab],[data-sg-cur=grab] *{cursor:grab!important}[data-sg-cur=grabbing],[data-sg-cur=grabbing] *{cursor:grabbing!important}[data-sg-cur=pointer],[data-sg-cur=pointer] *{cursor:pointer!important}'),wt(n)}catch(t){mt=null}if(O)try{G=new Highlight,G.priority=1e3,CSS.highlights.set(W,G)}catch(t){G=null}})(),Rn=Un('div',1,{width:'100vw',height:'100vh',background:'radial-gradient(ellipse at 50% 45%, rgba(8,8,16,0.9) 0%, rgba(2,3,8,0.985) 100%)',opacity:'0'}),In=Un('canvas',5,{width:'100vw',height:'100vh','mix-blend-mode':'screen',filter:'blur(1.5px)'}),Fn=Un('canvas',6,{width:'100vw',height:'100vh'}),A.appendChild(Rn),A.appendChild(In),A.appendChild(Fn),Ln=In.getContext('2d'),Nn=Fn.getContext('2d'),On=n.createElementNS('http://www.w3.org/2000/svg','svg'),On.setAttribute('data-singularity',''),On.setAttribute('width','0'),On.setAttribute('height','0'),On.style.setProperty('position','fixed','important'),On.style.setProperty('left','-10px','important'),On.style.setProperty('pointer-events','none','important'),A.appendChild(On),Bn(),(()=>{try{if(!(t.CSS&&CSS.supports&&CSS.supports('backdrop-filter','url(#a)')))return;Pn=[Dn(1),Dn(-1)];const n=new Image;n.onload=()=>{Gn=!0;for(const t of B)if(t.alive){const n=Wn.get(t);n&&n.lens||(qn(t),Hn(t))}},n.src=Pn[0]}catch(t){Gn=!1}})(),(()=>{const n={capture:!0,passive:!1};Go(t,'pointerdown',Ao,n),Go(t,'pointermove',Ro,n),Go(t,'pointerup',Io,n),Go(t,'pointercancel',Fo,n);for(const o of['click','dblclick','auxclick','contextmenu','mousedown','mouseup','dragstart','selectstart','touchstart','touchmove'])Go(t,o,Lo,n);Go(t,'keydown',No,!0),Go(t,'resize',Bn,!1)})(),A.setAttribute('data-sg-cur',''),Po.init(),t.__singularity=zo,!1!==a.autostart){const t=a.at&&isFinite(a.at.x)?{x:i(a.at.x,20,I-20),y:i(a.at.y,20,R-20)}:(()=>{let t={x:I/2,y:R/2},o=-1;for(let e=1;e<=5;e++)for(let s=1;s<=7;s++){const r=I*s/8,a=R*e/6;let i=0;for(let t=0;t<5;t++){const o=r+(t%2?30:-30)*(t>2?1:.5),e=a+18*(t-2);let s=null;try{s=n.caretRangeFromPoint?n.caretRangeFromPoint(o,e):null}catch(t){s=null}if(s&&s.startContainer&&3===s.startContainer.nodeType&&/\S/.test(s.startContainer.data)){const t=s.getBoundingClientRect();t&&Math.abs(t.top+t.height/2-e)<20&&i++}}const c=i-Math.hypot(r-I/2,a-R/2)/Math.max(I,R)*2.5;i>0&&c>o&&(o=c,t={x:r,y:a})}return t})();An(t.x,t.y,90)}r||(Uo=t.requestAnimationFrame(Ho))})()})(); } window.addEventListener('keydown', function (e) { if (!e.altKey || e.ctrlKey || e.metaKey || e.repeat || e.code !== 'KeyS') return; var t = e.target; if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return; e.preventDefault(); run(); }, true); })();