Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { between } from '../lib/math';import type { PageScope } from './page-scope';
const signal = { initial: [2000, 13000], interval: [11000, 34000], duration: [60, 140] } as const;const echo = { initial: [6000, 14000], interval: [18000, 42000], duration: [160, 300], font: '96px "LINE Seed JP Title"',} as const;
// Use the shared display clock, but give every heading its own fault schedule.export function createHighlightGlitches(scope: PageScope) { let clock = 0; const highlights = [ ...document.querySelectorAll<HTMLElement>( 'h1:not([data-title-flicker]), h2:not([data-interface-heading]), h3, h4, h5, h6, .site-wordmark-text, .landing-title-signal', ), ].map((element) => ({ element, visible: false, next: between(...signal.initial), end: 0 })); const title = document.querySelector<HTMLElement>('[data-title-flicker]'); let echoReady = false, echoNext = between(...echo.initial), echoEnd = 0; if (title) document.fonts .load(echo.font, title.querySelector('.landing-title-translation')!.textContent!) .then(() => { echoReady = !scope.signal.aborted; }); scope.defer(() => title?.classList.remove('title-echo')); const byElement = new Map(highlights.map((item) => [item.element, item])); scope.intersect(byElement.keys(), (entry) => { const item = byElement.get(entry.target as HTMLElement)!; if (entry.intersectionRatio > 0 && !item.visible) item.next = clock + between(...signal.initial); item.visible = entry.intersectionRatio > 0; }); return (time: number, moving: boolean) => { clock = time; if (title && echoReady) { const visible = byElement.get( title.querySelector<HTMLElement>('.landing-title-signal')!, )?.visible; if (echoEnd && (!moving || !visible || time >= echoEnd)) { title.classList.remove('title-echo'); echoEnd = 0; } if (moving && visible && time >= echoNext) { const duration = between(...echo.duration); title.style.setProperty('--echo-duration', `${duration}ms`); title.classList.add('title-echo'); echoEnd = time + duration; echoNext = echoEnd + between(...echo.interval); } } for (const item of highlights) { if (item.end && (!moving || time >= item.end || !item.visible)) { item.element.classList.remove('signal-slip'); item.end = 0; } if (!moving || !item.visible || time < item.next) continue; const duration = between(...signal.duration); item.element.style.setProperty('--signal-direction', Math.random() < 0.5 ? '-1' : '1'); item.element.style.setProperty('--signal-duration', `${duration}ms`); item.element.classList.add('signal-slip'); item.end = time + duration; item.next = item.end + between(...signal.interval); } };}