Constants

CSS class constants, type aliases, and default values for the card stack library.

Type Aliases

# Test CardRole type
role: CardRole = "focused"
assert role == "focused"
role = "context"
assert role == "context"
print("CardRole type alias tests passed!")
CardRole type alias tests passed!

Scroll Navigation Constants

Thresholds for converting mouse wheel events into card navigation.

assert SCROLL_THRESHOLD == 1
assert NAVIGATION_COOLDOWN == 100
assert TRACKPAD_COOLDOWN == 250
print("Scroll constants tests passed!")
Scroll constants tests passed!

Touch Navigation Constants

Thresholds for converting touch gestures into card navigation and scale adjustments. Touch-and-drag uses the focused slot height as the step distance; these constants govern the simple-swipe fallback, momentum decay after a fast swipe, and pinch-to-zoom sensitivity.

assert TOUCH_SWIPE_THRESHOLD == 30
assert TOUCH_MOMENTUM_MIN_VELOCITY == 0.5
assert TOUCH_MOMENTUM_FRICTION == 0.95
assert TOUCH_PINCH_THRESHOLD == 30
assert TOUCH_VELOCITY_SAMPLES == 5
print("Touch constants tests passed!")
Touch constants tests passed!

localStorage Key Patterns

Key templates for persisting viewport preferences to localStorage. The prefix is interpolated at runtime to support multi-instance.


source

auto_count_storage_key


def auto_count_storage_key(
    prefix:str, # Card stack instance prefix
)->str: # localStorage key for auto card count mode

Generate localStorage key for auto card count mode.


source

card_count_storage_key


def card_count_storage_key(
    prefix:str, # Card stack instance prefix
)->str: # localStorage key for card count

Generate localStorage key for card count.


source

scale_storage_key


def scale_storage_key(
    prefix:str, # Card stack instance prefix
)->str: # localStorage key for card scale

Generate localStorage key for card scale.


source

width_storage_key


def width_storage_key(
    prefix:str, # Card stack instance prefix
)->str: # localStorage key for card width

Generate localStorage key for card width.

# Test storage key generation
assert width_storage_key("cs0") == "cs0-card-width"
assert scale_storage_key("cs0") == "cs0-card-scale"
assert card_count_storage_key("cs0") == "cs0-card-count"
assert auto_count_storage_key("cs0") == "cs0-card-count-auto"

# Multi-instance keys are unique
assert width_storage_key("text") != width_storage_key("vad")
assert auto_count_storage_key("text") != auto_count_storage_key("vad")
print("Storage key tests passed!")
Storage key tests passed!

Viewport Defaults

assert DEFAULT_VISIBLE_COUNT == 1
assert DEFAULT_CARD_WIDTH == 80
assert DEFAULT_CARD_SCALE == 100
print("Viewport default tests passed!")