Tune pinboard styling and Muuri-driven dynamic item widths

This commit is contained in:
Jürgen Mummert
2026-03-04 18:50:49 +01:00
parent ab5e9b30b5
commit 42a816d347
2 changed files with 29 additions and 9 deletions

View File

@@ -44,6 +44,25 @@
layoutEasing: 'ease',
});
const toPx = (value) => {
const parsed = Number.parseFloat(value);
return Number.isNaN(parsed) ? 0 : parsed;
};
const updateItemWidths = () => {
const boardStyles = window.getComputedStyle(board);
const boardWidth = board.clientWidth;
const gap = toPx(boardStyles.getPropertyValue('--pin-gap')) || 20;
const minItemWidth = 260;
const columns = Math.max(1, Math.floor((boardWidth + gap) / (minItemWidth + gap)));
const itemWidth = Math.max(220, Math.floor((boardWidth - (columns - 1) * gap) / columns));
ordered.forEach((note) => {
note.style.width = `${itemWidth}px`;
});
};
const bringToFront = (note) => {
zCounter += 1;
note.style.zIndex = String(zCounter);
@@ -59,6 +78,7 @@
});
const relayout = () => {
updateItemWidths();
grid.refreshItems().layout();
};