The tl;dr solution to this is that having images in $lib
is a dumb requirement.
I have instead put images in static/assets/<image>
and updated the code as follows. It seems that the performance difference between $lib
and static/
is irrelevant in this scenario.
<script>
export let title;
export let bg_img;
</script>
<div
class="top-level-card flex h-35 justify-center rounded-2xl bg-cover bg-center shadow-xl"
style:background-image={`url(/assets/${bg_img})`}
>
<p class="bg-primary text-text-1 h-fit rounded-b-2xl px-3 pb-1 text-xl">{title}</p>
</div>