neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
Log in to mark this repository.
Shader backgrounds from party-slut: site-wide, per browser, /shaders
59d9458 · gmorell · 2026-12-03 05:26
Message
{commit_body(@commit)}
Files changed
modified
Dockerfile
+1
−1
| 16 | 16 | |
| 17 | 17 | RUN cd assets \ |
| 18 | 18 | && ./node_modules/.bin/tailwindcss -c tailwind.config.js -i f/css/style.css -o f/css/app.css \ |
| 19 | − && ./node_modules/.bin/esbuild f/js/src.js --bundle --minify --outfile=f/js/app.js \ | |
| 19 | + && ./node_modules/.bin/esbuild f/js/src.js --bundle --minify --loader:.frag=text --outfile=f/js/app.js \ | |
| 20 | 20 | && mkdir -p f/webfonts \ |
| 21 | 21 | && cp node_modules/@fortawesome/fontawesome-free/webfonts/*.woff2 f/webfonts/ \ |
| 22 | 22 | && cp node_modules/@fortawesome/fontawesome-free/webfonts/*.ttf f/webfonts/ |
modified
Justfile
+1
−1
| 22 | 22 | |
| 23 | 23 | # Bundle + minify JS (src.js -> app.js) |
| 24 | 24 | js: |
| 25 | − cd {{assets_dir}} && {{esbuild}} {{js_in}} --bundle --minify --outfile={{js_out}} | |
| 25 | + cd {{assets_dir}} && {{esbuild}} {{js_in}} --bundle --minify --loader:.frag=text --outfile={{js_out}} | |
| 26 | 26 | |
| 27 | 27 | # Watch CSS for changes; webfonts/JS rebuild on dep/source change |
| 28 | 28 | watch: webfonts js |
modified
README.md
+22
−0
| 361 | 361 | `src/handlers/focus.rs` (modelled on pin_flip's focus mode and shared pages, |
| 362 | 362 | and cartosnap's shared-trip stepping). |
| 363 | 363 | |
| 364 | +### Shader backgrounds | |
| 365 | + | |
| 366 | +Behind every page (both layouts) a WebGL2 pattern drifts slowly: neiam's | |
| 367 | +moire wallpaper and its relatives (Moire, Halftone, Bokeh, Starfield, Prism, | |
| 368 | +Oil on glass, Bubbles, Absorbing spheres, Alternate), ported from | |
| 369 | +party-slut. `/shaders` (Theme menu → Shaders, or the profile page) has a live | |
| 370 | +preview of each, the effect toggles and each pattern's own controls, and an | |
| 371 | +Off. The choice is per browser, in localStorage (`app:shader`), like the | |
| 372 | +theme. A browser that hasn't chosen gets **Oil on glass at 7% coverage**, set | |
| 373 | +once in `src/handlers/shaders.rs` and handed to the script on | |
| 374 | +`<body data-shader-default>`. | |
| 375 | + | |
| 376 | +Readability comes first: while a pattern is on, the content column sits on an | |
| 377 | +opaque base-100 panel, so text is on exactly the theme's own colours, and the | |
| 378 | +header, menus, cards and the reader overlay are opaque already. With | |
| 379 | +`prefers-reduced-motion` it draws one still frame unless "Always move" is on. | |
| 380 | +A hidden tab draws nothing, and without WebGL2 there's simply no background. | |
| 381 | +The fragment shaders in `assets/f/js/shaders/*.frag` are neiam-device's | |
| 382 | +`moire/shaders/*.frag`, byte for byte (copy them again when they change | |
| 383 | +there). esbuild inlines them (`--loader:.frag=text`, in the Justfile and | |
| 384 | +Dockerfile). | |
| 385 | + | |
| 364 | 386 | ## Link previews |
| 365 | 387 | |
| 366 | 388 | Paste a URL into Slack, Discord, iMessage or <https://www.linkpreview.app> and |
modified
assets/f/css/style.css
+32
−0
| 56 | 56 | .prose .footnote-definition > p { margin: 0; } |
| 57 | 57 | .prose .footnote-definition-label { opacity: 0.7; } |
| 58 | 58 | .prose .footnote-definition:target { background-color: oklch(var(--p) / 0.12); border-radius: 0.25rem; } |
| 59 | + | |
| 60 | +/* Shader background (f/js/shader_background.js). The canvas sits behind | |
| 61 | + everything; while it's on, the content column becomes an opaque base-100 | |
| 62 | + panel, so the pattern shows only around it and text contrast is exactly | |
| 63 | + the theme's own. The header, menus, cards and the reader overlay have | |
| 64 | + opaque backgrounds already. */ | |
| 65 | +#site-shader { | |
| 66 | + position: fixed; | |
| 67 | + inset: 0; | |
| 68 | + width: 100vw; | |
| 69 | + height: 100vh; | |
| 70 | + z-index: -1; | |
| 71 | + pointer-events: none; | |
| 72 | +} | |
| 73 | +html[data-shader] #content > div { | |
| 74 | + background-color: var(--fallback-b1, oklch(var(--b1))); | |
| 75 | + border-radius: var(--rounded-box, 1rem); | |
| 76 | + padding: 1.25rem; | |
| 77 | +} | |
| 78 | +@media (min-width: 640px) { | |
| 79 | + html[data-shader] #content > div { | |
| 80 | + padding: 2rem; | |
| 81 | + } | |
| 82 | +} | |
| 83 | +/* /shaders: the card in use. */ | |
| 84 | +[data-shader-card][data-active] { | |
| 85 | + outline: 4px solid oklch(var(--a)); | |
| 86 | + outline-offset: 4px; | |
| 87 | +} | |
| 88 | +.shader-unsupported canvas { | |
| 89 | + visibility: hidden; | |
| 90 | +} |
added
assets/f/js/shader_background.js
+183
−0
| 1 | +// The site-wide shader background and the /shaders controls. From | |
| 2 | +// party-slut's assets/f/js/shader_background.js (itself neiam-org's, with | |
| 3 | +// LiveView hooks replaced by delegation and htmx swap events), without its | |
| 4 | +// per-party backgrounds. | |
| 5 | +// | |
| 6 | +// The choice lives in this browser's localStorage under "app:shader", | |
| 7 | +// beside "app:theme": a pattern ("off" for none) and the effect settings, | |
| 8 | +// which the /shaders previews share. A browser that hasn't chosen gets the | |
| 9 | +// site default, which the server puts on <body data-shader-default> (see | |
| 10 | +// src/handlers/shaders.rs: Oil on glass at 7% coverage), so there is one | |
| 11 | +// place it's set. | |
| 12 | +// | |
| 13 | +// While a pattern is on, a fixed canvas sits behind the page and | |
| 14 | +// <html data-shader> puts the content column on an opaque base-100 panel | |
| 15 | +// (style.css): text never sits on the pattern. The colours follow the site | |
| 16 | +// theme. Reduced motion gets one still frame unless "Always move" is on; a | |
| 17 | +// hidden tab stops drawing; no WebGL2, no background. | |
| 18 | + | |
| 19 | +import { createField, DEFAULTS, SETTINGS_EVENT } from "./shader_field" | |
| 20 | + | |
| 21 | +const KEY = "app:shader" | |
| 22 | + | |
| 23 | +function siteDefault() { | |
| 24 | + try { | |
| 25 | + return JSON.parse(document.body?.dataset.shaderDefault || "{}") | |
| 26 | + } catch { | |
| 27 | + return {} | |
| 28 | + } | |
| 29 | +} | |
| 30 | + | |
| 31 | +function load() { | |
| 32 | + let saved = {} | |
| 33 | + try { | |
| 34 | + saved = JSON.parse(localStorage.getItem(KEY) || "{}") | |
| 35 | + } catch {} | |
| 36 | + return { ...DEFAULTS, pattern: "off", ...siteDefault(), ...saved } | |
| 37 | +} | |
| 38 | + | |
| 39 | +let current = null | |
| 40 | +let background = null | |
| 41 | +const previews = new Map() | |
| 42 | + | |
| 43 | +const on = pattern => !!pattern && pattern !== "off" && pattern !== "none" | |
| 44 | + | |
| 45 | +function apply() { | |
| 46 | + const pattern = current.pattern | |
| 47 | + if (on(pattern) && !background) { | |
| 48 | + const canvas = document.createElement("canvas") | |
| 49 | + canvas.id = "site-shader" | |
| 50 | + canvas.setAttribute("aria-hidden", "true") | |
| 51 | + // Placed here as well as in style.css: a stylesheet older than this | |
| 52 | + // script would otherwise leave a 300x150 inline canvas atop the page. | |
| 53 | + Object.assign(canvas.style, { | |
| 54 | + position: "fixed", | |
| 55 | + inset: "0", | |
| 56 | + width: "100vw", | |
| 57 | + height: "100vh", | |
| 58 | + zIndex: "-1", | |
| 59 | + pointerEvents: "none", | |
| 60 | + }) | |
| 61 | + document.body.prepend(canvas) | |
| 62 | + let field = null | |
| 63 | + try { | |
| 64 | + field = createField(canvas, () => current, { fps: 30, maxScale: 1 }) | |
| 65 | + } catch (e) { | |
| 66 | + console.error("shader background:", e) | |
| 67 | + } | |
| 68 | + if (!field) { | |
| 69 | + canvas.remove() | |
| 70 | + return | |
| 71 | + } | |
| 72 | + background = { canvas, field } | |
| 73 | + } else if (!on(pattern) && background) { | |
| 74 | + background.field.destroy() | |
| 75 | + background.canvas.remove() | |
| 76 | + background = null | |
| 77 | + } | |
| 78 | + document.documentElement.toggleAttribute("data-shader", !!background) | |
| 79 | +} | |
| 80 | + | |
| 81 | +// Merge `patch` into this browser's settings, save, and apply. | |
| 82 | +window.appSetShader = function (patch) { | |
| 83 | + current = { ...current, ...patch } | |
| 84 | + try { | |
| 85 | + localStorage.setItem(KEY, JSON.stringify(current)) | |
| 86 | + } catch {} | |
| 87 | + apply() | |
| 88 | + syncControls() | |
| 89 | + window.dispatchEvent(new CustomEvent(SETTINGS_EVENT, { detail: current })) | |
| 90 | +} | |
| 91 | + | |
| 92 | +// --- previews: <canvas data-shader-preview="oil"> --------------------------- | |
| 93 | + | |
| 94 | +function mountPreviews() { | |
| 95 | + for (const [canvas, field] of previews) { | |
| 96 | + if (!canvas.isConnected) { | |
| 97 | + field.destroy() | |
| 98 | + previews.delete(canvas) | |
| 99 | + } | |
| 100 | + } | |
| 101 | + for (const canvas of document.querySelectorAll("canvas[data-shader-preview]")) { | |
| 102 | + if (previews.has(canvas)) continue | |
| 103 | + let field = null | |
| 104 | + try { | |
| 105 | + field = createField(canvas, () => ({ ...current, pattern: canvas.dataset.shaderPreview })) | |
| 106 | + } catch (e) { | |
| 107 | + console.error("shader preview:", e) | |
| 108 | + } | |
| 109 | + if (field) previews.set(canvas, field) | |
| 110 | + else canvas.closest("[data-shader-card]")?.classList.add("shader-unsupported") | |
| 111 | + } | |
| 112 | +} | |
| 113 | + | |
| 114 | +// --- the /shaders controls, inside [data-shader-controls] ------------------- | |
| 115 | +// [data-use="pattern"] sets the background | |
| 116 | +// input[type=checkbox][data-setting="name"] boolean settings | |
| 117 | +// input[type=range][data-setting="name"] numeric settings | |
| 118 | +// select[data-setting="name"] numeric settings, as options | |
| 119 | +// [data-shader-card="pattern"] given data-active when in use | |
| 120 | +// [data-shader-current] the current pattern's name | |
| 121 | +// [data-shader-value="name"] a setting's value | |
| 122 | +// [data-shader-when="pattern"] shown only while it is in use | |
| 123 | + | |
| 124 | +function syncControls() { | |
| 125 | + for (const root of document.querySelectorAll("[data-shader-controls]")) { | |
| 126 | + for (const input of root.querySelectorAll("[data-setting]")) { | |
| 127 | + const v = current[input.dataset.setting] | |
| 128 | + if (input.type === "checkbox") input.checked = !!v | |
| 129 | + else input.value = v | |
| 130 | + } | |
| 131 | + for (const card of root.querySelectorAll("[data-shader-card]")) { | |
| 132 | + card.toggleAttribute("data-active", card.dataset.shaderCard === current.pattern) | |
| 133 | + } | |
| 134 | + const card = root.querySelector(`[data-shader-card="${current.pattern}"]`) | |
| 135 | + for (const out of root.querySelectorAll("[data-shader-current]")) { | |
| 136 | + out.textContent = card ? card.dataset.name : "Off" | |
| 137 | + } | |
| 138 | + for (const el of root.querySelectorAll("[data-shader-when]")) { | |
| 139 | + el.hidden = el.dataset.shaderWhen !== current.pattern | |
| 140 | + } | |
| 141 | + for (const out of root.querySelectorAll("[data-shader-value]")) { | |
| 142 | + out.textContent = current[out.dataset.shaderValue] | |
| 143 | + } | |
| 144 | + } | |
| 145 | +} | |
| 146 | + | |
| 147 | +document.addEventListener("click", e => { | |
| 148 | + const use = e.target.closest("[data-shader-controls] [data-use]") | |
| 149 | + if (use) window.appSetShader({ pattern: use.dataset.use }) | |
| 150 | +}) | |
| 151 | + | |
| 152 | +document.addEventListener("input", e => { | |
| 153 | + const input = e.target | |
| 154 | + if (input.dataset?.setting && input.closest("[data-shader-controls]")) { | |
| 155 | + const value = input.type === "checkbox" ? input.checked : Number(input.value) | |
| 156 | + window.appSetShader({ [input.dataset.setting]: value }) | |
| 157 | + } | |
| 158 | +}) | |
| 159 | + | |
| 160 | +function sync() { | |
| 161 | + if (!current) current = load() | |
| 162 | + if (background && !background.canvas.isConnected) document.body.prepend(background.canvas) | |
| 163 | + for (const stray of document.querySelectorAll("#site-shader")) { | |
| 164 | + if (stray !== background?.canvas) stray.remove() | |
| 165 | + } | |
| 166 | + apply() | |
| 167 | + syncControls() | |
| 168 | + mountPreviews() | |
| 169 | +} | |
| 170 | + | |
| 171 | +if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", sync) | |
| 172 | +else sync() | |
| 173 | +// hx-boost swaps #content: previews and controls come and go. | |
| 174 | +document.addEventListener("htmx:afterSettle", sync) | |
| 175 | +document.addEventListener("htmx:historyRestore", sync) | |
| 176 | +// htmx snapshots <body> for the back button. Keep the canvas out of it, or | |
| 177 | +// going back would restore a blank copy beside the live one. | |
| 178 | +document.addEventListener("htmx:beforeHistorySave", () => { | |
| 179 | + const canvas = background?.canvas | |
| 180 | + if (!canvas) return | |
| 181 | + canvas.remove() | |
| 182 | + queueMicrotask(() => canvas.isConnected || document.body.prepend(canvas)) | |
| 183 | +}) |
added
assets/f/js/shader_balls.js
+191
−0
Click to load diff…
added
assets/f/js/shader_field.js
+389
−0
Click to load diff…
added
assets/f/js/shaders/bubbles.frag
+144
−0
Click to load diff…
added
assets/f/js/shaders/field.frag
+279
−0
Click to load diff…
added
assets/f/js/shaders/oil.frag
+110
−0
Click to load diff…
added
assets/f/js/shaders/prism.frag
+153
−0
Click to load diff…
added
assets/f/js/shaders/spheres.frag
+139
−0
Click to load diff…
modified
assets/f/js/src.js
+4
−0
Click to load diff…
modified
src/handlers/mod.rs
+1
−0
Click to load diff…
added
src/handlers/shaders.rs
+150
−0
Click to load diff…
modified
src/web.rs
+3
−0
Click to load diff…
modified
templates/_theme_toggle.html
+2
−0
Click to load diff…
modified
templates/auth/profile.html
+5
−0
Click to load diff…
modified
templates/root.html
+1
−0
Click to load diff…
added
templates/shaders.html
+149
−0
Click to load diff…
modified
tests/moderation_db.rs
+33
−0
Click to load diff…
modified
tests/templates.rs
+20
−0
Click to load diff…
Parents: 313874d