Remove too many stamps
Test and deploy / test (push) Successful in 1m45s
Test and deploy / deploy (push) Successful in 21s

This commit is contained in:
2026-10-14 21:20:02 +01:00
parent d28524e8c0
commit 746f20158e
+78 -86
View File
@@ -20,20 +20,17 @@ import Link from "@/components/text/Link.vue";
import { shuffleArray } from "@/js/utils.js"; import { shuffleArray } from "@/js/utils.js";
let srcs = [ let srcs = [
"/img/stamps/portal.gif", "/img/stamps/portal.gif",
"/img/stamps/miku.gif", "/img/stamps/miku.gif",
"/img/stamps/utau.gif", "/img/stamps/utau.gif",
"/img/stamps/teto.webp", "/img/stamps/teto.webp",
"/img/stamps/3ds.jpg", "/img/stamps/3ds.jpg",
"/img/stamps/fry.png", "/img/stamps/fry.png",
"/img/stamps/ai.png", "/img/stamps/ai.png",
"/img/stamps/rei.png", "/img/stamps/rei.png",
"/img/stamps/tetris.gif", "/img/stamps/tetris.gif",
"/img/stamps/tf2.gif", "/img/stamps/tf2.gif",
"/img/stamps/demo.gif", "/img/stamps/demo.gif",
"/img/stamps/demo.gif",
"/img/stamps/demo.gif",
"/img/stamps/demo.gif",
]; ];
// Shuffled once at module evaluation, so the wall is ordered differently each // Shuffled once at module evaluation, so the wall is ordered differently each
// page load but stable while the widget is mounted. Mutates in place. // page load but stable while the widget is mounted. Mutates in place.
@@ -41,17 +38,12 @@ shuffleArray(srcs);
// The two linked stamps stay first; the shuffled local ones follow. // The two linked stamps stay first; the shuffled local ones follow.
const stamps = [ const stamps = [
{ {
src: "https://www.adam-french.co.uk/img/stamps/mine.gif", src: "https://www.adam-french.co.uk/img/stamps/mine.gif",
alt: "adam-french.co.uk", alt: "adam-french.co.uk",
href: "https://www.adam-french.co.uk", href: "https://www.adam-french.co.uk",
}, },
{ ...srcs.map((src) => ({ src, alt: src.split("/").pop().split(".")[0] })),
src: "https://jacobbarron.xyz/Banneh.gif",
alt: "jacobbarron.xyz",
href: "https://jacobbarron.xyz",
},
...srcs.map((src) => ({ src, alt: src.split("/").pop().split(".")[0] })),
]; ];
// Must match the grid track sizes in the <style> block. // Must match the grid track sizes in the <style> block.
@@ -66,10 +58,10 @@ const rows = ref(4);
// more slots than there are stamps — a ragged last row would leave a blank // more slots than there are stamps — a ragged last row would leave a blank
// strip drifting into view. // strip drifting into view.
const cells = computed(() => const cells = computed(() =>
Array.from( Array.from(
{ length: cols.value * rows.value }, { length: cols.value * rows.value },
(_, i) => stamps[i % stamps.length], (_, i) => stamps[i % stamps.length],
), ),
); );
/** /**
@@ -78,14 +70,14 @@ const cells = computed(() =>
* Rows are also raised, if need be, until every stamp appears at least once. * Rows are also raised, if need be, until every stamp appears at least once.
*/ */
function fitWall() { function fitWall() {
const el = touchscreen.value?.$el; const el = touchscreen.value?.$el;
if (!el) return; if (!el) return;
cols.value = Math.ceil(el.clientWidth / STAMP_W) + 1; cols.value = Math.ceil(el.clientWidth / STAMP_W) + 1;
rows.value = Math.max( rows.value = Math.max(
Math.ceil(el.clientHeight / STAMP_H) + 1, Math.ceil(el.clientHeight / STAMP_H) + 1,
Math.ceil(stamps.length / cols.value), Math.ceil(stamps.length / cols.value),
); );
} }
let resizeObserver = null; let resizeObserver = null;
@@ -103,79 +95,79 @@ let dy = 0.12;
* because fitWall changes the bounds whenever the cell is resized. * because fitWall changes the bounds whenever the cell is resized.
*/ */
function bounce() { function bounce() {
const el = touchscreen.value?.$el; const el = touchscreen.value?.$el;
if (!el) return; if (!el) return;
const maxX = el.scrollWidth - el.clientWidth; const maxX = el.scrollWidth - el.clientWidth;
const maxY = el.scrollHeight - el.clientHeight; const maxY = el.scrollHeight - el.clientHeight;
if (maxX > 0) { if (maxX > 0) {
posX += dx; posX += dx;
if (posX <= 0) { if (posX <= 0) {
posX = 0; posX = 0;
dx = -dx; dx = -dx;
} else if (posX >= maxX) { } else if (posX >= maxX) {
posX = maxX; posX = maxX;
dx = -dx; dx = -dx;
}
el.scrollLeft = posX;
} }
el.scrollLeft = posX; if (maxY > 0) {
} posY += dy;
if (maxY > 0) { if (posY <= 0) {
posY += dy; posY = 0;
if (posY <= 0) { dy = -dy;
posY = 0; } else if (posY >= maxY) {
dy = -dy; posY = maxY;
} else if (posY >= maxY) { dy = -dy;
posY = maxY; }
dy = -dy; el.scrollTop = posY;
} }
el.scrollTop = posY;
}
animId = requestAnimationFrame(bounce); animId = requestAnimationFrame(bounce);
} }
onMounted(() => { onMounted(() => {
fitWall(); fitWall();
// The cell's size follows the home grid's breakpoints (and the scrollbars // The cell's size follows the home grid's breakpoints (and the scrollbars
// appearing inside it), not just window resizes, so observe the element. // appearing inside it), not just window resizes, so observe the element.
resizeObserver = new ResizeObserver(fitWall); resizeObserver = new ResizeObserver(fitWall);
resizeObserver.observe(touchscreen.value.$el); resizeObserver.observe(touchscreen.value.$el);
animId = requestAnimationFrame(bounce); animId = requestAnimationFrame(bounce);
}); });
onUnmounted(() => { onUnmounted(() => {
if (animId) cancelAnimationFrame(animId); if (animId) cancelAnimationFrame(animId);
resizeObserver?.disconnect(); resizeObserver?.disconnect();
}); });
</script> </script>
<template> <template>
<Touchscreen ref="touchscreen"> <Touchscreen ref="touchscreen">
<div class="wall" :style="{ '--cols': cols }"> <div class="wall" :style="{ '--cols': cols }">
<template v-for="(stamp, i) in cells" :key="i"> <template v-for="(stamp, i) in cells" :key="i">
<Link v-if="stamp.href" bare :href="stamp.href"> <Link v-if="stamp.href" bare :href="stamp.href">
<img :src="stamp.src" :alt="stamp.alt" /> <img :src="stamp.src" :alt="stamp.alt" />
</Link> </Link>
<img v-else :src="stamp.src" :alt="stamp.alt" loading="lazy" /> <img v-else :src="stamp.src" :alt="stamp.alt" loading="lazy" />
</template> </template>
</div> </div>
</Touchscreen> </Touchscreen>
</template> </template>
<style scoped> <style scoped>
img { img {
display: block; display: block;
width: 89px; width: 89px;
height: 59px; height: 59px;
} }
/* Fixed tracks rather than flex-wrap: the wall's size comes from --cols (set /* Fixed tracks rather than flex-wrap: the wall's size comes from --cols (set
by fitWall), never from how much room the cell happens to have. */ by fitWall), never from how much room the cell happens to have. */
.wall { .wall {
display: grid; display: grid;
grid-template-columns: repeat(var(--cols), 89px); grid-template-columns: repeat(var(--cols), 89px);
grid-auto-rows: 59px; grid-auto-rows: 59px;
width: max-content; width: max-content;
} }
</style> </style>