/** * Wires the shared daemon-sec effects into this site: the contour field * under the hero and each section banner, the dot field behind the top * of each page, and the cursor with its action pill. * * Astro's ClientRouter swaps the body on navigation, which removes the * cursor element and the canvases, so all are re-bound on every * `astro:page-load` and torn down on `astro:before-swap` (which also * hands each WebGL context back: a browser keeps only so many). */import { mountContourField } from'./contour-field';
import { mountParticleField } from'./particle-field';
import { mountCursor } from'./cursor';
const DECKS ='gtfobins|lolbas|wadcoms|loobins|daemon';
const TOOL =newRegExp(`^/(?:${DECKS})/[^/?#]+`);
const DECK =newRegExp(`^/(?:${DECKS}|catalog)/?(?:[?#].*)?$`);
let destroyCursor: (() => void) |null=null;
const fields =newSet<() => void>();
function bindFields():void {
document.querySelectorAll<HTMLCanvasElement>('canvas[data-dots]:not([data-bound])').forEach((cv) => {
cv.dataset.bound ='';
const destroy = mountParticleField(cv, {
/* This site's mode-flipping tokens; a canvas inside a .plate band reads that band's values. */ vars: { ink:'--text', base:'--base', iris:'--iris', love:'--love' },
onFail: () => cv.closest<HTMLElement>('.dmn-page-field')?.remove(),
});
fields.add(destroy);
});
}
function bindContours():void {
document.querySelectorAll<HTMLCanvasElement>('canvas[data-contour]:not([data-bound])').forEach((cv) => {
cv.dataset.bound ='';
/* No WebGL, or the context was lost: the plate's plain ground stands. */ fields.add(mountContourField(cv, { onFail: () => cv.remove() }));
});
}
function bindCursor():void {
if (document.querySelector('.dmn-cursor')) return;
destroyCursor?.();
destroyCursor = mountCursor({
linkLabel: (href) => (TOOL.test(href) ?'Read': DECK.test(href) ?'Browse':null),
/* Dark bands are `.plate`; `.plate-dawn` panels inside them are light. */ isDark: (t) => t.closest('.plate, .plate-dawn')?.classList.contains('plate') ??false,
});
}
exportfunction initDmn():void {
bindContours();
bindFields();
bindCursor();
}
document.addEventListener('astro:before-swap', () => {
fields.forEach((d) => d());
fields.clear();
});