2026-01-18 15:55:07 +03:00
|
|
|
<!--
|
|
|
|
|
Component: FontVirtualList
|
|
|
|
|
- Renders a virtualized list of fonts
|
|
|
|
|
- Handles font registration with the manager
|
|
|
|
|
-->
|
2026-02-02 12:18:20 +03:00
|
|
|
<script lang="ts" generics="T extends UnifiedFont">
|
2026-02-06 11:53:59 +03:00
|
|
|
import {
|
|
|
|
|
Skeleton,
|
|
|
|
|
VirtualList,
|
|
|
|
|
} from '$shared/ui';
|
2026-01-18 12:55:25 +03:00
|
|
|
import type { ComponentProps } from 'svelte';
|
2026-02-06 11:53:59 +03:00
|
|
|
import { fade } from 'svelte/transition';
|
2026-02-05 11:44:16 +03:00
|
|
|
import { getFontUrl } from '../../lib';
|
|
|
|
|
import type { FontConfigRequest } from '../../model';
|
2026-02-02 12:18:20 +03:00
|
|
|
import {
|
|
|
|
|
type UnifiedFont,
|
|
|
|
|
appliedFontsManager,
|
|
|
|
|
} from '../../model';
|
2026-01-18 12:55:25 +03:00
|
|
|
|
2026-02-06 11:53:59 +03:00
|
|
|
interface Props extends
|
|
|
|
|
Omit<
|
|
|
|
|
ComponentProps<typeof VirtualList<T>>,
|
|
|
|
|
'onVisibleItemsChange'
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Callback for when visible items change
|
|
|
|
|
*/
|
2026-01-18 12:55:25 +03:00
|
|
|
onVisibleItemsChange?: (items: T[]) => void;
|
2026-02-06 11:53:59 +03:00
|
|
|
/**
|
|
|
|
|
* Callback for when near bottom is reached
|
|
|
|
|
*/
|
2026-01-30 19:21:47 +03:00
|
|
|
onNearBottom?: (lastVisibleIndex: number) => void;
|
2026-02-06 11:53:59 +03:00
|
|
|
/**
|
|
|
|
|
* Weight of the font
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* Weight of the font
|
|
|
|
|
*/
|
2026-02-02 12:18:20 +03:00
|
|
|
weight: number;
|
2026-02-06 11:53:59 +03:00
|
|
|
/**
|
|
|
|
|
* Whether the list is in a loading state
|
|
|
|
|
*/
|
|
|
|
|
isLoading?: boolean;
|
2026-01-18 12:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-06 11:53:59 +03:00
|
|
|
let {
|
|
|
|
|
items,
|
|
|
|
|
children,
|
|
|
|
|
onVisibleItemsChange,
|
|
|
|
|
onNearBottom,
|
|
|
|
|
weight,
|
|
|
|
|
isLoading = false,
|
|
|
|
|
...rest
|
|
|
|
|
}: Props = $props();
|
2026-01-18 12:55:25 +03:00
|
|
|
|
|
|
|
|
function handleInternalVisibleChange(visibleItems: T[]) {
|
2026-02-05 11:44:16 +03:00
|
|
|
const configs: FontConfigRequest[] = [];
|
|
|
|
|
|
|
|
|
|
visibleItems.forEach(item => {
|
|
|
|
|
const url = getFontUrl(item, weight);
|
|
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
|
configs.push({
|
|
|
|
|
id: item.id,
|
|
|
|
|
name: item.name,
|
|
|
|
|
weight,
|
|
|
|
|
url,
|
|
|
|
|
isVariable: item.features?.isVariable,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-01-18 12:55:25 +03:00
|
|
|
// Auto-register fonts with the manager
|
2026-02-02 12:18:20 +03:00
|
|
|
appliedFontsManager.touch(configs);
|
2026-01-18 12:55:25 +03:00
|
|
|
|
2026-02-05 11:44:16 +03:00
|
|
|
// Forward the call to any external listener
|
2026-02-02 12:18:20 +03:00
|
|
|
// onVisibleItemsChange?.(visibleItems);
|
2026-01-18 12:55:25 +03:00
|
|
|
}
|
2026-01-30 19:21:47 +03:00
|
|
|
|
|
|
|
|
function handleNearBottom(lastVisibleIndex: number) {
|
|
|
|
|
// Forward the call to any external listener
|
|
|
|
|
onNearBottom?.(lastVisibleIndex);
|
|
|
|
|
}
|
2026-01-18 12:55:25 +03:00
|
|
|
</script>
|
|
|
|
|
|
2026-02-06 11:53:59 +03:00
|
|
|
{#key isLoading}
|
|
|
|
|
<div class="relative w-full h-full" transition:fade={{ duration: 300 }}>
|
|
|
|
|
{#if isLoading}
|
2026-02-06 14:48:44 +03:00
|
|
|
<div class="flex flex-col gap-3 sm:gap-4 p-3 sm:p-4">
|
2026-02-06 11:53:59 +03:00
|
|
|
{#each Array(5) as _, i}
|
2026-02-10 23:19:27 +03:00
|
|
|
<div class="flex flex-col gap-1.5 sm:gap-2 p-3 sm:p-4 border rounded-lg sm:rounded-xl border-border-subtle bg-background-40">
|
2026-02-06 14:48:44 +03:00
|
|
|
<div class="flex items-center justify-between mb-3 sm:mb-4">
|
|
|
|
|
<Skeleton class="h-6 sm:h-8 w-1/3" />
|
|
|
|
|
<Skeleton class="h-6 sm:h-8 w-6 sm:w-8 rounded-full" />
|
2026-02-06 11:53:59 +03:00
|
|
|
</div>
|
2026-02-06 14:48:44 +03:00
|
|
|
<Skeleton class="h-24 sm:h-32 w-full" />
|
2026-02-06 11:53:59 +03:00
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<VirtualList
|
|
|
|
|
{items}
|
|
|
|
|
{...rest}
|
|
|
|
|
onVisibleItemsChange={handleInternalVisibleChange}
|
|
|
|
|
onNearBottom={handleNearBottom}
|
|
|
|
|
>
|
|
|
|
|
{#snippet children(scope)}
|
|
|
|
|
{@render children(scope)}
|
|
|
|
|
{/snippet}
|
|
|
|
|
</VirtualList>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/key}
|