Skip to content

Commit 06c5016

Browse files
committed
fix: browser compatibility issues
1 parent c739e80 commit 06c5016

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/lib/components/generic/InfiniteGrid.svelte

+17-10
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414
index = Math.max(0, Math.min(itemCount - 1, index + amount));
1515
};
1616
17+
const getCached = (index) => $visibleData.find(({ index: i }) => i === index)?.data || get(index);
18+
19+
let inRange = [-Infinity, Infinity];
20+
const initialized = writable(false);
1721
const dim = writable({ w: 0, h: 0 });
1822
const offset = spring(0, { stiffness, damping });
23+
1924
export const visibleData = derived(
20-
[dim, offset],
21-
([{ w, h }, $o]) => {
22-
if (!w || !h || !intiailized) return [];
25+
[dim, offset, initialized],
26+
([{ w, h }, $o, $initialized]) => {
27+
if (!w || !h || !$initialized) return [];
28+
if ($o < inRange[0] || $o > inRange[1]) return $visibleData;
2329
const cellHeight = h / cellCount;
2430
const start = Math.max(-1, Math.floor((-1 * $o) / cellHeight) - 1);
2531
const baseOffset = $o % cellHeight;
@@ -28,25 +34,26 @@
2834
.map((_, i) => {
2935
const index = i + start;
3036
const pos = baseOffset + (i - 1) * cellHeight;
31-
// don't recalculate unnecessarily
32-
if ($visibleData?.[i]?.index === index) return { ...$visibleData[i], pos };
3337
if (index < 0 || index >= itemCount) return undefined;
34-
return { data: get(index), pos, index };
38+
return { data: getCached(index), pos, index };
3539
})
3640
.filter(Boolean);
3741
},
3842
[]
3943
);
4044
41-
let intiailized = false;
45+
const updateOffset = (o) => {
46+
inRange = [o, $offset].sort((a, b) => a - b);
47+
offset.set(o, { hard: !$initialized });
48+
};
4249
4350
$: type = vertical ? 'rows' : 'columns';
4451
$: gridStyle = `grid-template-${type}: repeat(${cellCount}, 1fr);`;
4552
$: {
4653
if ($dim.w && $dim.h) {
47-
const newOffset = ((-1 * $dim.h) / cellCount) * index;
48-
offset.set(+newOffset.toFixed(2), { hard: !intiailized });
49-
if (!intiailized) intiailized = true;
54+
const newOffset = ($dim.h / cellCount) * index * -1;
55+
updateOffset(+newOffset.toFixed(3));
56+
if (!$initialized) initialized.set(true);
5057
}
5158
}
5259
</script>

src/lib/components/generic/ToggleSwitch.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
text-align: left;
2626
background: var(--sc-theme-calendar-colors-background-hover);
2727
margin: 0 auto;
28+
display: grid;
2829
}
29-
div,
30-
div * {
30+
* {
3131
transition: all 180ms cubic-bezier(1, -0.055, 0.135, 1.07);
3232
}
3333
button {

0 commit comments

Comments
 (0)