# pofulu/sparkar-pftween architecture

> Architecture diagram of the GitHub repository pofulu/sparkar-pftween, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pofulu/sparkar-pftween
- Repository: https://github.com/pofulu/sparkar-pftween

## Overview

##### Project Type and Purpose
- Project Type: It’s an animation tweening library tailored for Spark AR.
- Purpose: To offer a fluent API for creating tween animations (similar to DOTween) with support for multiple output types (scalar, vector signals, etc.), callbacks for events (start, update, complete), and both synchronous and async (clip) execution modes.
- Integration: It serves as both a standalone library that can be imported into Spark AR projects and as an npm module. There’s also an included demo (PFTweenDemo) that shows practical usage.

##### File Structure
- Top-Level Files:
– PFTween.js and PFTween.d.ts contain the core library implementation and type definitions.
– package.json is used for npm distribution.
– README.md provides usage documentation and detailed explanations.
- Demo Directory:
– The “PFTweenDemo” folder contains a Spark AR project file (PFTweenDemo.arproj) and a collection of sample scripts (Demo0.ts, Demo1.ts, etc.) that demonstrate various tweening scenarios.
– The “scripts” subdirectory within the demo shows the different approaches to creating and managing animations.
- Other Resources: Configuration files such as .gitignore and LICENSE are present as well as additional resources (like textures and README.assets) used in demonstration aspects.

##### Core Components
a. Core Tweening Engine (PFTween Library):
– Represent the central PFTween module and its API.
– Include method chaining (setEase, onStart, onUpdate, etc.) and property endpoints (.scalar, .pack2, .clip, .progress).
– Highlight support for various easing functions and event callbacks.

b. Spark AR Integration Layer:
– Show the connection between the tween’s output signals (e.g., ScalarSignal, Point2DSignal) and Spark AR scene objects (e.g., plane transforms, materials).
– Indicate integration points such as interacting with modules like Scene, Materials, and TouchGestures.

c. Demo/Usage Examples:
– Illustrate that the demo project (PFTweenDemo) encapsulates real-world applications of the library.

d. External and Supporting Modules:
– A block representing third-party or external dependencies (like npm for distribution, and external easing libraries referenced via URLs).
– (Optional) Components for animation control patterns (like reusable animation controllers with build/replay/stop functions).

##### Architectural Patterns and Design Principles
- The builder/chain pattern is evident in the way the tween is configured (e.g., chaining setEase, onStart, setLoops).
- Separation of concerns: The tween library is decoupled from the Spark AR environment (it simply produces signals that are then applied in AR scenes).
- Asynchronous control is provided via Promise-based “clip” functions for sequencing animations.
- Reusability: The library supports both one-off animations and reusable tweens (using build() to return controllers).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Library Layer"
        N2["PFTween Core Library"]:::core
        N3["Tween API (Chaining&Callbacks)"]:::core
    end

    N1["External Modules & npm"]:::external
    N4["Spark AR Scene"]:::core
    N5["Demo Project (PFTweenDemo)"]:::demo

    N1 -->|"npmDistribution"| N2
    N3 -->|"propertyUpdate"| N4
    N4 -->|"onCallbacks"| N3
    N5 -->|"usesTweenAPI"| N3
    N5 -->|"drivesScene"| N4

    click N2 "https://github.com/pofulu/sparkar-pftween/blob/master/PFTween.js"
    click N2 "https://github.com/pofulu/sparkar-pftween/blob/master/PFTween.d.ts"
    click N4 "https://github.com/pofulu/sparkar-pftween/blob/master/PFTweenDemo/PFTweenDemo.arproj"
    click N4 "https://github.com/pofulu/sparkar-pftween/blob/master/PFTweenDemo/scripts/PFTween.ts"
    click N5 "https://github.com/pofulu/sparkar-pftween/tree/master/PFTweenDemo/scripts"
    click N1 "https://github.com/pofulu/sparkar-pftween/blob/master/package.json"

    classDef core fill:#add8e6,stroke:#000,stroke-width:1px
    classDef demo fill:#90ee90,stroke:#000,stroke-width:1px
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px
```
