# Models


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Token

------------------------------------------------------------------------

### Token

``` python

def Token(
    text:str, index:int, metadata:Any=None
)->None:

```

*A single token in the token grid.*

``` python
t = Token("hello", 0)
assert t.text == "hello"
assert t.index == 0
assert t.metadata is None

t_meta = Token("world", 1, metadata={"confidence": 0.95})
assert t_meta.metadata["confidence"] == 0.95
print("Token tests passed!")
```

    Token tests passed!

## TokenRenderContext

------------------------------------------------------------------------

### TokenRenderContext

``` python

def TokenRenderContext(
    token:Token, is_selected:bool, is_anchor:bool, is_focus:bool, selection_mode:str
)->None:

```

*Context passed to per-token styling callbacks.*

``` python
t = Token("test", 0)
ctx = TokenRenderContext(token=t, is_selected=True, is_anchor=True, is_focus=True, selection_mode="word")
assert ctx.is_selected is True
assert ctx.selection_mode == "word"
print("TokenRenderContext tests passed!")
```

    TokenRenderContext tests passed!

## TokenSelectorState

------------------------------------------------------------------------

### TokenSelectorState

``` python

def TokenSelectorState(
    anchor:int=0, focus:int=0, word_count:int=0, active:bool=False
)->None:

```

*Mutable runtime state for a token selector instance.*

``` python
s = TokenSelectorState()
assert s.anchor == 0
assert s.focus == 0
assert s.word_count == 0
assert s.active is False

# Mutable
s.anchor = 5
s.focus = 8
s.word_count = 20
assert s.anchor == 5
assert s.focus == 8

# Span selection state
s_span = TokenSelectorState(anchor=3, focus=7, word_count=20)
assert s_span.anchor != s_span.focus

print("TokenSelectorState tests passed!")
```

    TokenSelectorState tests passed!
