# `LivePanels.Canvas.Viewport`
[🔗](https://github.com/livepanels/livepanels/blob/v0.1.0/lib/livepanels/canvas/viewport.ex#L1)

Viewport command helpers.

# `anchor`

```elixir
@type anchor() :: %{
  :name =&gt; String.t(),
  :label =&gt; String.t() | nil,
  :x =&gt; number(),
  :y =&gt; number(),
  :zoom =&gt; number(),
  optional(:item_ids) =&gt; [String.t()]
}
```

# `bounds`

```elixir
@type bounds() :: %{
  left: number(),
  top: number(),
  width: number(),
  height: number(),
  right: number(),
  bottom: number()
}
```

# `command_result`

```elixir
@type command_result() :: LivePanels.Canvas.Command.result()
```

# `socket`

```elixir
@type socket() :: Phoenix.LiveView.Socket.t()
```

# `target`

```elixir
@type target() :: LivePanels.Canvas.command_target()
```

First argument accepted by viewport command helpers.

Pass a LiveView socket for a standalone command, or a
`LivePanels.Canvas.Transaction` context inside `LivePanels.Canvas.transaction/2`.

# `anchor_for_bounds`

```elixir
@spec anchor_for_bounds(String.t() | atom(), bounds(), keyword()) :: anchor() | nil
```

Builds a viewport anchor from explicit world-space bounds.

# `fit`

```elixir
@spec fit(target(), term()) :: command_result()
```

Requests a viewport fit and returns the command result.

# `fit!`

```elixir
@spec fit!(target(), term()) :: target()
```

Requests a viewport fit for a selection, visible items, bounds, or graph target.

# `fit_items`

```elixir
@spec fit_items(target(), [String.t()] | MapSet.t()) :: command_result()
```

Requests a viewport fit and returns the command result.

# `fit_items!`

```elixir
@spec fit_items!(target(), [String.t()] | MapSet.t()) :: target()
```

Requests a viewport fit around the given item ids.

# `fit_to_items_anchor`

```elixir
@spec fit_to_items_anchor(
  map(),
  String.t() | atom(),
  [String.t()] | MapSet.t(),
  keyword()
) ::
  anchor() | nil
```

Builds a viewport anchor that fits the given item ids.

# `goto_anchor`

```elixir
@spec goto_anchor(target(), String.t() | atom()) :: command_result()
```

Moves the viewport to a named anchor and returns the command result.

# `goto_anchor!`

```elixir
@spec goto_anchor!(target(), String.t() | atom()) :: target()
```

Moves the current participant's viewport to a named anchor.

# `present_anchor`

```elixir
@spec present_anchor(target(), String.t() | atom()) :: command_result()
```

Broadcasts a named anchor and returns the command result.

# `present_anchor!`

```elixir
@spec present_anchor!(target(), String.t() | atom()) :: target()
```

Broadcasts a named anchor as the suggested viewport for all participants.

# `put_anchor`

```elixir
@spec put_anchor(target(), anchor()) :: command_result()
```

Stores or replaces a named viewport anchor and returns the command result.

# `put_anchor!`

```elixir
@spec put_anchor!(target(), anchor()) :: target()
```

Stores or replaces a named viewport anchor through the canvas command path.

# `put_sequence`

```elixir
@spec put_sequence(target(), [String.t() | atom()]) :: command_result()
```

Replaces the active viewport sequence and returns the command result.

# `put_sequence!`

```elixir
@spec put_sequence!(target(), [String.t() | atom()]) :: target()
```

Replaces the active viewport sequence with the given anchor names.

# `remove_anchor`

```elixir
@spec remove_anchor(target(), String.t() | atom()) :: command_result()
```

Removes a named viewport anchor and returns the command result.

# `remove_anchor!`

```elixir
@spec remove_anchor!(target(), String.t() | atom()) :: target()
```

Removes a named viewport anchor and prunes it from the active sequence.

# `step_next`

```elixir
@spec step_next(target()) :: command_result()
```

Steps to the next anchor and returns the command result.

# `step_next!`

```elixir
@spec step_next!(target()) :: target()
```

Steps the current participant to the next anchor in the active sequence.

# `step_prev`

```elixir
@spec step_prev(target()) :: command_result()
```

Steps to the previous anchor and returns the command result.

# `step_prev!`

```elixir
@spec step_prev!(target()) :: target()
```

Steps the current participant to the previous anchor in the active sequence.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
