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";
let srcs = [
"/img/stamps/portal.gif",
"/img/stamps/miku.gif",
"/img/stamps/utau.gif",
"/img/stamps/teto.webp",
"/img/stamps/3ds.jpg",
"/img/stamps/fry.png",
"/img/stamps/ai.png",
"/img/stamps/rei.png",
"/img/stamps/tetris.gif",
"/img/stamps/tf2.gif",
"/img/stamps/demo.gif",
"/img/stamps/demo.gif",
"/img/stamps/demo.gif",
"/img/stamps/demo.gif",
"/img/stamps/portal.gif",
"/img/stamps/miku.gif",
"/img/stamps/utau.gif",
"/img/stamps/teto.webp",
"/img/stamps/3ds.jpg",
"/img/stamps/fry.png",
"/img/stamps/ai.png",
"/img/stamps/rei.png",
"/img/stamps/tetris.gif",
"/img/stamps/tf2.gif",
"/img/stamps/demo.gif",
];
// Shuffled once at module evaluation, so the wall is ordered differently each
// 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.
const stamps = [
{
src: "https://www.adam-french.co.uk/img/stamps/mine.gif",
alt: "adam-french.co.uk",
href: "https://www.adam-french.co.uk",
},
{
src: "https://jacobbarron.xyz/Banneh.gif",
alt: "jacobbarron.xyz",
href: "https://jacobbarron.xyz",
},
...srcs.map((src) => ({ src, alt: src.split("/").pop().split(".")[0] })),
{
src: "https://www.adam-french.co.uk/img/stamps/mine.gif",
alt: "adam-french.co.uk",
href: "https://www.adam-french.co.uk",
},
...srcs.map((src) => ({ src, alt: src.split("/").pop().split(".")[0] })),
];
// 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
// strip drifting into view.
const cells = computed(() =>
Array.from(
{ length: cols.value * rows.value },
(_, i) => stamps[i % stamps.length],
),
Array.from(
{ length: cols.value * rows.value },
(_, 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.
*/
function fitWall() {
const el = touchscreen.value?.$el;
if (!el) return;
const el = touchscreen.value?.$el;
if (!el) return;
cols.value = Math.ceil(el.clientWidth / STAMP_W) + 1;
rows.value = Math.max(
Math.ceil(el.clientHeight / STAMP_H) + 1,
Math.ceil(stamps.length / cols.value),
);
cols.value = Math.ceil(el.clientWidth / STAMP_W) + 1;
rows.value = Math.max(
Math.ceil(el.clientHeight / STAMP_H) + 1,
Math.ceil(stamps.length / cols.value),
);
}
let resizeObserver = null;
@@ -103,79 +95,79 @@ let dy = 0.12;
* because fitWall changes the bounds whenever the cell is resized.
*/
function bounce() {
const el = touchscreen.value?.$el;
if (!el) return;
const el = touchscreen.value?.$el;
if (!el) return;
const maxX = el.scrollWidth - el.clientWidth;
const maxY = el.scrollHeight - el.clientHeight;
const maxX = el.scrollWidth - el.clientWidth;
const maxY = el.scrollHeight - el.clientHeight;
if (maxX > 0) {
posX += dx;
if (posX <= 0) {
posX = 0;
dx = -dx;
} else if (posX >= maxX) {
posX = maxX;
dx = -dx;
if (maxX > 0) {
posX += dx;
if (posX <= 0) {
posX = 0;
dx = -dx;
} else if (posX >= maxX) {
posX = maxX;
dx = -dx;
}
el.scrollLeft = posX;
}
el.scrollLeft = posX;
}
if (maxY > 0) {
posY += dy;
if (posY <= 0) {
posY = 0;
dy = -dy;
} else if (posY >= maxY) {
posY = maxY;
dy = -dy;
if (maxY > 0) {
posY += dy;
if (posY <= 0) {
posY = 0;
dy = -dy;
} else if (posY >= maxY) {
posY = maxY;
dy = -dy;
}
el.scrollTop = posY;
}
el.scrollTop = posY;
}
animId = requestAnimationFrame(bounce);
animId = requestAnimationFrame(bounce);
}
onMounted(() => {
fitWall();
// The cell's size follows the home grid's breakpoints (and the scrollbars
// appearing inside it), not just window resizes, so observe the element.
resizeObserver = new ResizeObserver(fitWall);
resizeObserver.observe(touchscreen.value.$el);
animId = requestAnimationFrame(bounce);
fitWall();
// The cell's size follows the home grid's breakpoints (and the scrollbars
// appearing inside it), not just window resizes, so observe the element.
resizeObserver = new ResizeObserver(fitWall);
resizeObserver.observe(touchscreen.value.$el);
animId = requestAnimationFrame(bounce);
});
onUnmounted(() => {
if (animId) cancelAnimationFrame(animId);
resizeObserver?.disconnect();
if (animId) cancelAnimationFrame(animId);
resizeObserver?.disconnect();
});
</script>
<template>
<Touchscreen ref="touchscreen">
<div class="wall" :style="{ '--cols': cols }">
<template v-for="(stamp, i) in cells" :key="i">
<Link v-if="stamp.href" bare :href="stamp.href">
<img :src="stamp.src" :alt="stamp.alt" />
</Link>
<img v-else :src="stamp.src" :alt="stamp.alt" loading="lazy" />
</template>
</div>
</Touchscreen>
<Touchscreen ref="touchscreen">
<div class="wall" :style="{ '--cols': cols }">
<template v-for="(stamp, i) in cells" :key="i">
<Link v-if="stamp.href" bare :href="stamp.href">
<img :src="stamp.src" :alt="stamp.alt" />
</Link>
<img v-else :src="stamp.src" :alt="stamp.alt" loading="lazy" />
</template>
</div>
</Touchscreen>
</template>
<style scoped>
img {
display: block;
width: 89px;
height: 59px;
display: block;
width: 89px;
height: 59px;
}
/* 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. */
.wall {
display: grid;
grid-template-columns: repeat(var(--cols), 89px);
grid-auto-rows: 59px;
width: max-content;
display: grid;
grid-template-columns: repeat(var(--cols), 89px);
grid-auto-rows: 59px;
width: max-content;
}
</style>