How pixijs-userland/pixi-viewport works
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