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-01-18 12:55:25 +03:00
|
|
|
import { VirtualList } from '$shared/ui';
|
|
|
|
|
import type { ComponentProps } from 'svelte';
|
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
|
|
|
|
|
|
|
|
interface Props extends Omit<ComponentProps<typeof VirtualList<T>>, 'onVisibleItemsChange'> {
|
|
|
|
|
onVisibleItemsChange?: (items: T[]) => void;
|
2026-01-30 19:21:47 +03:00
|
|
|
onNearBottom?: (lastVisibleIndex: number) => void;
|
2026-02-02 12:18:20 +03:00
|
|
|
weight: number;
|
2026-01-18 12:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-02 12:18:20 +03:00
|
|
|
let { items, children, onVisibleItemsChange, onNearBottom, weight, ...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>
|
|
|
|
|
|
|
|
|
|
<VirtualList
|
|
|
|
|
{items}
|
|
|
|
|
{...rest}
|
|
|
|
|
onVisibleItemsChange={handleInternalVisibleChange}
|
2026-01-30 19:21:47 +03:00
|
|
|
onNearBottom={handleNearBottom}
|
2026-01-18 12:55:25 +03:00
|
|
|
>
|
|
|
|
|
{#snippet children(scope)}
|
|
|
|
|
{@render children(scope)}
|
|
|
|
|
{/snippet}
|
|
|
|
|
</VirtualList>
|