Convenience router factory that wires up standard card stack routes (Tier 2 API).
init_card_stack_router
Factory function that creates an APIRouter with all standard card stack routes wired up. Returns a tuple of (APIRouter, CardStackUrls) so the consumer has access to the route URLs for keyboard navigation and component rendering.
For consumers who need custom before/after logic in their handlers (e.g., resetting a caret position before entering split mode), use the Tier 1 response builder functions from routes.handlers directly instead.
def init_card_stack_router( config:CardStackConfig, # Card stack configuration state_getter:Callable, # Function to get current state state_setter:Callable, # Function to save state get_items:Callable, # Function to get current items list render_card:Callable, # Card renderer callback: (item, CardRenderContext) -> FT route_prefix:str='/card-stack', # Route prefix for all card stack routes progress_label:str='Item', # Label for progress indicator)->Tuple: # (router, urls) tuple
Initialize an APIRouter with all standard card stack routes.
Tests
from cjm_fasthtml_card_stack.core.config import _reset_prefix_counterfrom cjm_fasthtml_card_stack.core.models import CardRenderContextfrom fasthtml.common import Div, Span# Simple render_card for testingdef _test_render(item, ctx: CardRenderContext):return Div(Span(f"{item}"), cls=f"card-{ctx.card_role}")# Simple state storage_reset_prefix_counter()_state = CardStackState()_items = [f"Test item {i}"for i inrange(10)]def _get_state(): return _statedef _set_state(s): global _state; _state = sdef _get_items(): return _itemsprint("Test setup ready.")