### VirtualList with Dynamic Sizing and Scroll Control Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example demonstrating a VirtualList with dynamic item sizing and scroll-to-index functionality. ```svelte data[i].height} scrollToIndex={250} scrollToAlignment="center" /> ``` -------------------------------- ### Basic Virtual List Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/QUICK_START.md A fundamental example demonstrating a vertical virtual list with 10000 items and fixed item sizes. ```svelte {#snippet item({ style, index })}
{data[index]}
{/snippet}
``` -------------------------------- ### Horizontal VirtualList Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example of rendering a horizontal VirtualList with precise dimensions. Width is required. ```svelte ``` -------------------------------- ### TypeScript Setup for VirtualList Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/EXPORTS.md Demonstrates the complete TypeScript setup for using the VirtualList component, including defining props, event handlers, item size getters, and alignment. ```typescript import VirtualList from 'svelte-tiny-virtual-list'; import type { VirtualListProps, VirtualListEvents, Alignment, ItemSize } from 'svelte-tiny-virtual-list'; // Type your props const props: VirtualListProps = { itemCount: 100, itemSize: 50, height: 600 }; // Type your event handlers const handlers: VirtualListEvents = { onItemsUpdated: ({ start, end }) => { console.log(`Items ${start}-${end} visible`); } }; // Type item size function const sizeGetter: ItemSize = (index) => { return 50 + (index % 2) * 10; }; // Type alignment parameter const alignment: Alignment = 'center'; ``` -------------------------------- ### Example ItemSizeGetter Implementations Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Provides examples of how to implement the ItemSizeGetter type for alternating item sizes or sizes derived from data. ```typescript const getItemSize: ItemSizeGetter = (index) => { return 50 + (index % 2) * 10; // Alternate between 50px and 60px }; const getItemSizeFromData: ItemSizeGetter = (index) => { return items[index].displayHeight; }; ``` -------------------------------- ### Vertical VirtualList Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example of rendering a vertical VirtualList with fixed dimensions. Height is required. ```svelte ``` -------------------------------- ### Install svelte-tiny-virtual-list with pnpm Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/README.md Use pnpm to add the svelte-tiny-virtual-list package to your project dependencies. ```shell pnpm install svelte-tiny-virtual-list ``` -------------------------------- ### Svelte Example using Alignment Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Demonstrates how to use the scrollToAlignment prop in a VirtualList component to center a specific item. ```svelte ``` -------------------------------- ### Install svelte-tiny-virtual-list with npm Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/README.md Use npm to add the svelte-tiny-virtual-list package to your project dependencies. ```shell npm install svelte-tiny-virtual-list ``` -------------------------------- ### Virtual List Item Size Examples Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Illustrates different ways to configure the `itemSize` prop for the VirtualList component, including fixed, array-based, and dynamic sizing. ```svelte ``` ```svelte ``` ```svelte data[index].height} /> ``` -------------------------------- ### Basic Virtual List Usage Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/INDEX.md This example shows how to set up a virtual list with a large dataset, a button to jump to a specific item, and custom header and item rendering. It also includes basic styling and event logging for visible items. ```svelte console.log(`Visible: ${start}-${end}`)} > {#snippet item({ style, index })}
{data[index]}
{/snippet} {#snippet header()}
My Virtual List
{/snippet}
``` -------------------------------- ### Svelte Example using ScrollBehaviour Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Shows how to implement smooth scrolling to a specific index in a VirtualList component using the scrollToBehaviour prop. ```svelte ``` -------------------------------- ### Integrated Constant Usage Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/constants.md Shows how to use various constants together for handling user scrolling, calculating target offsets, and applying programmatic scrolls with smooth behavior. ```javascript import { DIRECTION, ALIGNMENT, SCROLL_PROP, SCROLL_PROP_LEGACY } from './constants.js'; // User scrolls vertically const scrollDirection = DIRECTION.VERTICAL; const currentOffset = element[SCROLL_PROP_LEGACY[scrollDirection]]; // element.scrollTop // Scroll to item 500, centered const targetOffset = getUpdatedOffsetForIndex( ALIGNMENT.CENTER, containerHeight, currentOffset, 500 ); // Apply programmatic scroll element.scroll({ [SCROLL_PROP[scrollDirection]]: targetOffset, behavior: 'smooth' }); // Result: element.scroll({ top: targetOffset, behavior: 'smooth' }) ``` -------------------------------- ### Install svelte-tiny-virtual-list with yarn Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/README.md Use yarn to add the svelte-tiny-virtual-list package to your project dependencies. ```shell yarn add svelte-tiny-virtual-list ``` -------------------------------- ### Basic Vertical List Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Demonstrates the basic usage of VirtualList for rendering a simple vertical list with fixed item heights. Ensure the component is imported and data is provided. ```svelte {#snippet item({ style, index })}
{data[index]}
{/snippet}
``` -------------------------------- ### Using VirtualList Event Handlers Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example of how to implement and pass event handlers to the VirtualList component. Ensure the handler functions match the expected signature. ```svelte ``` -------------------------------- ### Scroll to Index Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Demonstrates how to programmatically scroll the list to a specific item. Use the `scrollToIndex`, `scrollToAlignment`, and `scrollToBehaviour` props to control the scrolling behavior. ```svelte {#snippet item({ style, index })}
{data[index]}
{/snippet}
``` -------------------------------- ### Horizontal Virtual List Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/QUICK_START.md Example of a horizontal virtual list with 500 items, each with a width of 250 pixels. ```svelte {#snippet item({ style, index })}
Card {index}
{/snippet}
``` -------------------------------- ### Example Usage of onAfterScroll Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Demonstrates how to use the `onAfterScroll` event handler to detect when a user has scrolled past a certain offset. This snippet is for Svelte. ```svelte ``` -------------------------------- ### Virtual List with Animations Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/advanced-usage.md Apply Svelte transitions to items within VirtualList for animated loading. The example uses a staggered loading approach with `fade` transition. ```svelte {#snippet item({ style, index })}
{items[index]}
{/snippet}
``` -------------------------------- ### Item Size - Fixed Number Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Use a fixed number to set a uniform size for all items in the virtual list. This is the most performant option. ```typescript itemSize={50} // All items are 50px tall ``` -------------------------------- ### Virtual List Direction Examples Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Demonstrates how to configure the scroll direction for the VirtualList component. The default is vertical scrolling. ```svelte ``` ```svelte ``` -------------------------------- ### Vertical List with Fixed Height Items Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/QUICK_START.md Example of a vertical virtual list with 1000 items, each having a fixed height of 50 pixels. ```svelte {#snippet item({ style, index })}
Item {index}
{/snippet}
``` -------------------------------- ### Render VirtualList with Snippets Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example of using the VirtualList component with item, header, and footer snippets. Ensure the 'style' prop is applied to the item element. ```svelte {#snippet item({ index, style })}
Item {index}
{/snippet} {#snippet header()}
My List
{/snippet} {#snippet footer()} {/snippet}
``` -------------------------------- ### SCROLL_PROP Internal Usage Examples Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/constants.md Shows how to apply programmatic scroll using SCROLL_PROP to dynamically set the scroll property based on direction. Examples for vertical and horizontal scrolling are provided. ```javascript // Apply programmatic scroll wrapper.scroll({ [SCROLL_PROP[scrollDirection]]: scroll.offset, behavior: scrollToBehaviour }); ``` ```javascript // For vertical: wrapper.scroll({ top: 1200, behavior: 'instant' }) // For horizontal: wrapper.scroll({ left: 800, behavior: 'instant' }) ``` -------------------------------- ### Configure Initial Scroll Offset Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Sets the initial scroll position of the list in pixels. This allows the list to start at a specific offset. ```svelte ``` -------------------------------- ### Infinite Loading Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Integrates VirtualList with an infinite loading mechanism using `svelte-infinite-loading`. The `footer` slot can be used to place the `InfiniteLoading` component, which triggers data fetching when the user scrolls near the end. ```svelte {#snippet item({ style, index })}
{data[index]}
{/snippet} {#snippet footer()} {/snippet}
``` -------------------------------- ### Interactive Items with Selection Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/advanced-usage.md Implement interactive list items that support selection and keyboard navigation. This example uses `onclick` and `onkeydown` handlers to manage the selected state and arrow key navigation. ```svelte {#snippet item({ style, index })}
selectItem(index)} onkeydown={(e) => handleKeydown(e, index)} tabindex="0" > Item {items[index]}
{/snippet}
``` -------------------------------- ### Item Size - Array of Numbers Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Provide an array of numbers to specify individual sizes for each item. The array length must be at least the item count. ```typescript itemSize={[50, 60, 45, 70, 55]} // Item sizes specified individually ``` -------------------------------- ### SCROLL_CHANGE_REASON Internal Usage Examples Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/constants.md Demonstrates how to set and check the SCROLL_CHANGE_REASON when updating scroll state. Different handling is applied based on the change reason. ```javascript // When user scrolls scroll = { offset, changeReason: SCROLL_CHANGE_REASON.OBSERVED }; ``` ```javascript // When prop-driven scroll scroll = { offset: getOffsetForIndex(scrollToIndex), changeReason: SCROLL_CHANGE_REASON.REQUESTED }; ``` ```javascript // Different handling based on reason if (scroll.changeReason === SCROLL_CHANGE_REASON.REQUESTED) { wrapper.scroll({ [SCROLL_PROP[scrollDirection]]: scroll.offset, behavior: scrollToBehaviour }); } ``` -------------------------------- ### Make Multiple Items Sticky Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Provide an array of item indexes to the `stickyIndices` prop to make multiple items sticky. This example shows the first three items being made sticky. ```svelte ``` -------------------------------- ### Item Size - Dynamic Getter Function Example Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Implement an ItemSizeGetter function to dynamically calculate each item's size based on its index. This is suitable for very large, dynamic lists. ```typescript itemSize={(index) => { return data[index].height; // Get size from data }} ``` -------------------------------- ### Basic VirtualList Usage Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Demonstrates the fundamental structure for using the VirtualList component. Ensure you provide required props like itemCount, itemSize, and height/width. ```svelte {#snippet item({ index, style })}
{items[index]}
{/snippet}
``` -------------------------------- ### Optimize Item Size Calculation Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/advanced-usage.md Demonstrates fast and slow methods for calculating item sizes. Prefer memoized lookups or O(1) calculations for the `itemSize` function to maintain performance. ```svelte ``` -------------------------------- ### Component Initialization Data Flow Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/architecture.md Illustrates the sequence of events when the VirtualList component is first initialized. ```mermaid graph TD User_provides_props[User provides props (itemCount, itemSize, height, width, etc.)] VirtualList_receives_props[VirtualList receives props via $props()] Create_SizeAndPositionManager[Create SizeAndPositionManager with itemSize/itemCount/estimatedItemSize] Initialize_scroll_state[Initialize scroll state: { offset: 0, changeReason: REQUESTED }] Set_up_DOM_effect[Set up DOM effect to attach scroll event listener] Render_visible_items[Render visible items calculated from offset] User_provides_props --> VirtualList_receives_props --> Create_SizeAndPositionManager --> Initialize_scroll_state --> Set_up_DOM_effect --> Render_visible_items ``` -------------------------------- ### VirtualList with Dynamic Item Sizes Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Illustrates how to use a function for `itemSize` to handle lists where items have variable heights. This is crucial for dynamic content. ```svelte {#snippet item({ index, style })}
{items[index]}
{/snippet}
``` -------------------------------- ### Minimal Virtual List Configuration Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Use this basic configuration for a simple list with a fixed number of items and a fixed item size. ```svelte ``` -------------------------------- ### Load Data from Database/API Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/advanced-usage.md Manage data loading from a remote source, handling initial loads and subsequent data fetching as the user scrolls. Use `getKey` for stable item identification. ```svelte {#if loading}
Loading...
{:else} {#snippet item({ style, index })}
{items[index]?.name}
{/snippet}
{/if} ``` -------------------------------- ### onListItemsUpdate Prop Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/README.md A function that fires when the set of visible items in the list is updated. It provides the start and end indices of the visible items. ```APIDOC ## onListItemsUpdate ### Description Function that fires when the visible items are updated. ### Parameters - **start** (number) - Index of the first visible item. - **end** (number) - Index of the last visible item. ``` -------------------------------- ### ItemsUpdatedDetail Interface Definition Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/EXPORTS.md Represents the detail object passed to the `onItemsUpdated` event handler, indicating the start and end indices of the updated items. ```typescript interface ItemsUpdatedDetail { start: number; end: number; } ``` -------------------------------- ### Alignment Type Definition Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/EXPORTS.md Defines the possible values for controlling scroll alignment when scrolling to an item. Use 'auto', 'start', 'center', or 'end'. ```typescript type Alignment = 'auto' | 'start' | 'center' | 'end' ``` -------------------------------- ### Get Total List Size Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Retrieves the total calculated size of all items in the list. This is useful for setting the overall scrollable height/width of the container. ```javascript const manager = new SizeAndPositionManager(50, 1000, 50); const totalHeight = manager.getTotalSize(); console.log(`List height: ${totalHeight}px`); ``` -------------------------------- ### Get Size and Position for an Item Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Retrieves the calculated size and offset for a specific item index. Useful for debugging or understanding item layout. ```javascript const manager = new SizeAndPositionManager(50, 100, 50); const { size, offset } = manager.getSizeAndPositionForIndex(10); console.log(`Item 10: size=${size}px, offset=${offset}px`); ``` -------------------------------- ### VirtualList with Custom Key Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Demonstrates using the `getKey` prop to provide a custom unique identifier for each item. This is beneficial when dealing with data that has stable IDs, especially from external sources. ```svelte {#snippet item({ index, style })}
{items[index].name} (ID: {items[index].id})
{/snippet}
``` -------------------------------- ### Basic Usage of VirtualList in Svelte Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/README.md Demonstrates the basic implementation of the VirtualList component in Svelte, rendering a list of items with fixed sizes. Ensure the 'item' slot is used to define the rendering of each item. ```svelte {#snippet item({ style, index })}
Letter: {data[index]}, Row: #{index}
{/snippet}
``` -------------------------------- ### Using ItemsUpdatedDetail in Svelte Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md Example demonstrating how to use the `ItemsUpdatedDetail` object within an `onItemsUpdated` handler in a Svelte component. This allows you to calculate the number of visible items. ```svelte ``` -------------------------------- ### Realistic Production Virtual List with Dynamic Data Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Configure a virtual list for production use with dynamic item loading, variable item heights, and event handling. Ensure to implement the fetch API for data loading and handle scroll events for potential further data loading. ```svelte
{#snippet item({ index, style })}
{items[index].title}

{items[index].description}

{/snippet} {#snippet header()}
My Items
{/snippet} {#snippet footer()} {/snippet}
``` -------------------------------- ### Core Architecture Layers Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/architecture.md Illustrates the three-layer architecture of the svelte-tiny-virtual-list component, showing the interaction between the Svelte component, the SizeAndPositionManager, and constants/type definitions. ```text ┌─────────────────────────────────────────────────────────┐ │ VirtualList Component (Svelte) │ │ - Props, snippets, event handlers │ │ - Scrolling and reflow logic │ └────────────────┬────────────────────────────────────────┘ │ ┌────────────────┴────────────────────────────────────────┐ │ SizeAndPositionManager (JavaScript Class) │ │ - Size and offset calculations │ │ - Caching and memoization │ │ - Search algorithms (binary, exponential) │ └────────────────┬────────────────────────────────────────┘ │ ┌────────────────┴────────────────────────────────────────┐ │ Constants and Type Definitions │ │ - Alignment, Direction, ScrollChangeReason │ │ - TypeScript type definitions for consumer API │ └─────────────────────────────────────────────────────────┘ ``` -------------------------------- ### VirtualList onItemsUpdated Event Handler Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Callback function executed when the visible items in the VirtualList change. It receives the start and end indices of the currently visible items. ```javascript onItemsUpdated={({ start, end }) => { console.log(`Visible items: ${start} to ${end}`); }} ``` -------------------------------- ### VirtualList with Scroll to Index and Alignment Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Demonstrates controlling the scroll position using `scrollToIndex` and `scrollToAlignment`. This is useful for navigating to specific items programmatically. ```svelte {#snippet item({ index, style })}
{items[index]}
{/snippet}
``` -------------------------------- ### resetItem Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Clears cached size and position data for items starting from a specified index. This is essential when item sizes change dynamically, ensuring accurate recalculations. ```APIDOC ## resetItem(index) ### Description Clears cached size and position data for items at and after the specified index. Used when item sizes change dynamically. ### Parameters #### Path Parameters - **index** (number) - Required - The starting index from which to clear cache. ### Returns `void` ### Note This method does not immediately recalculate; calculations are performed lazily the next time sizes are requested. ### Example ```javascript const manager = new SizeAndPositionManager( (index) => data[index].height, data.length, 50 ); // After data changes: manager.resetItem(0); // Clear cache from start ``` ``` -------------------------------- ### getUpdatedOffsetForIndex Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Calculates the necessary scroll offset to bring a target item into view with a specified alignment (e.g., start, center, end). This is used for programmatic scrolling. ```APIDOC ## getUpdatedOffsetForIndex(align, containerSize, currentOffset, targetIndex) ### Description Calculates the scroll offset required to bring a specific item into view with the desired alignment. ### Parameters #### Path Parameters - **align** ('auto' | 'start' | 'center' | 'end') - Required - Desired alignment: `'start'` (top/left), `'center'` (middle), `'end'` (bottom/right), or `'auto'` (scroll minimum distance). - **containerSize** (number) - Required - Height or width of the visible viewport (in pixels). - **currentOffset** (number) - Required - The current scroll position (in pixels). - **targetIndex** (number) - Required - The index of the item to scroll to. ### Returns `number` - The scroll offset to use. ### Example ```javascript const manager = new SizeAndPositionManager(50, 1000, 50); const offset = manager.getUpdatedOffsetForIndex('center', 600, 1200, 500); wrapper.scrollTop = offset; // Scroll to item 500, centered ``` ``` -------------------------------- ### Module Organization Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/architecture.md Defines the file structure of the svelte-tiny-virtual-list library. ```tree src/lib/ ├── VirtualList.svelte Main component (Svelte 5) ├── SizeAndPositionManager.js Size/position calculation engine ├── constants.js Direction, alignment, scroll constants ├── types.d.ts TypeScript definitions ├── index.ts Public API entry point └── index.js Compiled JavaScript export ``` -------------------------------- ### Overscan Buffering Logic Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/architecture.md Adjusts the start and end indices to include a buffer of items beyond the visible range, smoothing scroll transitions. Ensure `overscanCount` is provided. ```javascript if (overscanCount) { start = Math.max(0, start - overscanCount); end = Math.min(end + overscanCount, itemCount - 1); } ``` -------------------------------- ### Initialize SizeAndPositionManager with Fixed Size Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Use this snippet to initialize the SizeAndPositionManager when all items have a uniform size. This is the most performant option. ```javascript const manager = new SizeAndPositionManager(50, 1000, 50); ``` -------------------------------- ### Calculate Scroll Offset for Item Alignment Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Calculates the necessary scroll offset to bring a target item into view with a specified alignment ('start', 'center', 'end', or 'auto'). ```javascript const manager = new SizeAndPositionManager(50, 1000, 50); const offset = manager.getUpdatedOffsetForIndex('center', 600, 1200, 500); wrapper.scrollTop = offset; // Scroll to item 500, centered ``` -------------------------------- ### Configure Fixed Item Size Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Use this for the fastest performance when all items in the list have the same dimensions. Pre-computes sizes during initialization. ```svelte ``` -------------------------------- ### Configure Dynamic Item Size Function Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/configuration.md Best for very large lists with varied item sizes, offering memory efficiency. Sizes are calculated just-in-time using a provided function. ```svelte data[index].height} itemCount={1000} estimatedItemSize={50} /> ``` -------------------------------- ### Calculate Visible Item Range Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Determines the start and end indices of items that should be rendered based on the current scroll position and container size. Includes overscan for smooth scrolling. ```javascript const manager = new SizeAndPositionManager(50, 1000, 50); const { start, end } = manager.getVisibleRange(600, 1200, 3); console.log(`Render items ${start} through ${end}`); ``` -------------------------------- ### VirtualList with Sticky Indices Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/VirtualList.md Shows how to make specific items sticky using the `stickyIndices` prop. Sticky items remain visible when scrolling past them, useful for headers or separators. ```svelte {#snippet item({ index, style })}
{items[index]}
{/snippet}
``` -------------------------------- ### Reset Item Cache for Dynamic Sizing Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/api-reference/SizeAndPositionManager.md Clears cached size and position data for items starting from a given index. This is essential when item sizes change dynamically after initial measurement. ```javascript const manager = new SizeAndPositionManager( (index) => data[index].height, data.length, 50 ); // After data changes: manager.resetItem(0); // Clear cache from start ``` -------------------------------- ### Virtual List with Dynamic Keys Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/QUICK_START.md Utilizes the `getKey` prop to provide unique keys for list items, which is crucial for efficient updates when the data changes. ```svelte {#snippet item({ style, index })}
{users[index].name}
{/snippet}
``` -------------------------------- ### ItemSizeGetter Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/types.md A function type that defines how to get the size (height or width) of an item at a specific index. It takes the item's index as a number and should return its size in pixels, which must be a positive number. ```APIDOC ## ItemSizeGetter ### Description Function type that returns the size (height or width) of an item at a given index. ### Parameters #### Path Parameters - **index** (number) - Required - Zero-based index of the item ### Returns - **number** - Size in pixels (must be positive) ### Example ```typescript const getItemSize: ItemSizeGetter = (index) => { return 50 + (index % 2) * 10; // Alternate between 50px and 60px }; const getItemSizeFromData: ItemSizeGetter = (index) => { return items[index].displayHeight; }; ``` ``` -------------------------------- ### Package.json Configuration for Svelte and Types Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/EXPORTS.md Shows the package.json configuration that specifies the main Svelte component entry point and the TypeScript definition file location. ```json { "svelte": "./dist/index.js", "types": "./dist/index.d.ts" } ``` -------------------------------- ### Source Code Hierarchy Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/architecture.md Illustrates the import and export relationships between the main files in the svelte-tiny-virtual-list project. Highlights the public entry point and core modules. ```text index.ts (public entry point) ↓ re-exports VirtualList.svelte ├─ imports → SizeAndPositionManager.js ├─ imports → constants.js └─ uses types from → types.d.ts SizeAndPositionManager.js └─ imports → constants.js ``` -------------------------------- ### Constants Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/DELIVERY_SUMMARY.txt Documentation for constants used within the svelte-tiny-virtual-list library. ```APIDOC ## Constants ### Description This section lists the constants used throughout the `svelte-tiny-virtual-list` library. ### `DEFAULT_ITEM_HEIGHT` - **Type**: `number` - **Value**: `40` - **Description**: The default height in pixels for list items when not explicitly specified. ### `DEFAULT_OVERSCAN` - **Type**: `number` - **Value**: `3` - **Description**: The default number of items to render above and below the visible viewport for smooth scrolling. ### `DEFAULT_ESTIMATED_ITEM_SIZE` - **Type**: `number` - **Value**: `50` - **Description**: The default estimated item size used by `SizeAndPositionManager` for initial calculations when item heights might not be immediately known. ``` -------------------------------- ### List with Variable Item Heights Source: https://github.com/jonasgeiler/svelte-tiny-virtual-list/blob/main/_autodocs/QUICK_START.md Demonstrates a virtual list where items have different heights. Uses a function for itemSize and provides estimatedItemSize for performance. ```svelte {#snippet item({ style, index })}
{items[index].text}
{/snippet}
```