# pixijs-userland/pixi-viewport architecture

> Architecture diagram of the GitHub repository pixijs-userland/pixi-viewport, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pixijs-userland/pixi-viewport
- Repository: https://github.com/pixijs-userland/pixi-viewport

## Overview

##### Project type and purpose
- pixi-viewport is an open-source, highly configurable 2D “camera”/viewport library built on top of pixi.js.

##### File structure
Top-level directories and files:
- src/ – all TypeScript source
- Viewport.ts – core viewport implementation
- InputManager.ts – central event handling
- PluginManager.ts – dynamic plugin lifecycle
- plugins/ – individual behavior modules (Drag.ts, Pinch.ts, Wheel.ts, …)
- external/penner.ts – easing functions
- ease.ts – wrapper around easing
- index.ts – public entry point
- types.ts, global.d.ts – TypeScript definitions
- docs/ – JSDoc site source and generated public files
- test/ – Mocha test suites for each plugin and core functionality
- scripts/ – build‐and‐deploy helpers (append-mixins, copy)
- vite.config.ts, vite.build.ts – build configuration for packaging
- jsdoc.json – API documentation generation
- package.json – npm scripts, dependencies

##### README for additional insights
- Confirms this is a library targeting pixi.js v8+, with multiple version‐based notes.
- Shows a “Simple Example” in which a PIXI.Application is created, Viewport is instantiated with renderer.events, and plugins are enabled via fluent calls.
- Mentions JSDoc docs and live examples hosted via GitHub Pages.

##### Main components and their relationships
A. Core runtime components
- PIXI.Application & Renderer (external)
- Viewport
- InputManager
- PluginManager
- Plugins (drag, pinch, wheel, …)
- Easing functions (penner)
B. Build & documentation pipeline (offline components)
- TypeScript compiler & Vite → dist/ (ESM/CJS bundles)
- JSDoc → docs/public (GitHub Pages)
- Scripts (append-mixins, copy) → automate mixin generation & doc assets
- GitHub workflows → build, test, and deploy docs

Interaction flow at runtime:
1. PIXI emits pointer/mouse/touch events →
2. InputManager captures events →
3. PluginManager dispatches to each active Plugin →
4. Plugin calls methods on Viewport (translate, scale, clamp, bounce) →
5. Viewport updates its Transform state →
6. PIXI’s render loop draws the scene with the transformed viewport

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runtime Components
    subgraph "PIXI Host"
        PIXIApp["PIXI.Application & Renderer"]:::runtime
    end

    subgraph "Viewport Core"
        Viewport["Viewport Core"]:::runtime
        Transform["Transform State"]:::runtime
    end

    subgraph "Event Layer"
        InputMgr["InputManager"]:::runtime
        PluginMgr["PluginManager"]:::runtime
        subgraph "Plugins"
            PluginBase["Plugin<T>"]:::plugin
            Animate["Animate"]:::plugin
            Bounce["Bounce"]:::plugin
            Clamp["Clamp"]:::plugin
            ClampZoom["ClampZoom"]:::plugin
            Decelerate["Decelerate"]:::plugin
            Drag["Drag"]:::plugin
            Follow["Follow"]:::plugin
            MouseEdges["MouseEdges"]:::plugin
            Pinch["Pinch"]:::plugin
            Snap["Snap"]:::plugin
            SnapZoom["SnapZoom"]:::plugin
            Wheel["Wheel"]:::plugin
            PluginIndex["Plugin Exports"]:::plugin
        end
    end

    subgraph "Utility Layer"
        Penner["Penner Easing"]:::util
        Ease["Ease Wrapper"]:::util
        Types["Types & Declarations"]:::util
    end

    subgraph "Build & Docs Pipeline"
        TS["TypeScript Compiler & Vite"]:::build
        Dist["dist/*"]:::build
        JSDoc["JSDoc → docs/public"]:::build
        Scripts["Scripts (append-mixins, copy)"]:::build
        CI["GitHub Workflows"]:::build
    end

    Index["Public Entry (src/index.ts)"]:::runtime

    %% Runtime Flow
    PIXIApp -->|"events"| InputMgr
    InputMgr -->|"dispatch"| PluginMgr
    PluginMgr -->|"dispatch"| Animate
    PluginMgr --> Bounce
    PluginMgr --> Clamp
    PluginMgr --> ClampZoom
    PluginMgr --> Decelerate
    PluginMgr --> Drag
    PluginMgr --> Follow
    PluginMgr --> MouseEdges
    PluginMgr --> Pinch
    PluginMgr --> Snap
    PluginMgr --> SnapZoom
    PluginMgr --> Wheel
    PluginMgr --> PluginBase
    Animate -->|"calls API"| Viewport
    Bounce --> Viewport
    Clamp --> Viewport
    ClampZoom --> Viewport
    Decelerate --> Viewport
    Drag --> Viewport
    Follow --> Viewport
    MouseEdges --> Viewport
    Pinch --> Viewport
    Snap --> Viewport
    SnapZoom --> Viewport
    Wheel --> Viewport
    PluginBase --> Viewport
    Viewport --> Transform
    Transform -->|"render"| PIXIApp

    %% Utilities
    Penner --> Ease
    Ease --> Animate
    Ease --> Bounce
    Ease --> Clamp
    Ease --> ClampZoom
    Ease --> Decelerate
    Ease --> Drag
    Ease --> Follow
    Ease --> MouseEdges
    Ease --> Pinch
    Ease --> Snap
    Ease --> SnapZoom
    Ease --> Wheel
    Types --> Viewport
    Types --> InputMgr
    Types --> PluginMgr

    %% Entry Point
    Index --> Viewport
    Index --> PluginIndex

    %% Build & Docs Flow
    Scripts --> TS
    Scripts --> JSDoc
    TS --> Dist
    JSDoc -->|"generate"| Dist
    Dist -->|"npm publish"| CI
    JSDoc -->|"publish docs"| CI

    %% Click Events
    click Viewport "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/Viewport.ts"
    click InputMgr "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/InputManager.ts"
    click PluginMgr "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/PluginManager.ts"
    click PluginBase "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Plugin.ts"
    click PluginIndex "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/index.ts"
    click Animate "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Animate.ts"
    click Bounce "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Bounce.ts"
    click Clamp "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Clamp.ts"
    click ClampZoom "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/ClampZoom.ts"
    click Decelerate "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Decelerate.ts"
    click Drag "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Drag.ts"
    click Follow "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Follow.ts"
    click MouseEdges "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/MouseEdges.ts"
    click Pinch "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Pinch.ts"
    click Snap "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Snap.ts"
    click SnapZoom "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/SnapZoom.ts"
    click Wheel "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/plugins/Wheel.ts"
    click Penner "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/external/penner.ts"
    click Ease "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/ease.ts"
    click Index "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/index.ts"
    click Types "https://github.com/pixijs-userland/pixi-viewport/blob/master/src/types.ts"

    %% Styles
    classDef runtime fill:#BBE1FA,stroke:#0366d6,color:#000
    classDef plugin fill:#A6F6AF,stroke:#2e8b57,color:#000
    classDef util fill:#EEDC82,stroke:#b8860b,color:#000
    classDef build fill:#F5F5F5,stroke:#999,color:#000
```
