Blazor.GSAP 1.1.1

dotnet add package Blazor.GSAP --version 1.1.1
                    
NuGet\Install-Package Blazor.GSAP -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazor.GSAP" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blazor.GSAP" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Blazor.GSAP" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blazor.GSAP --version 1.1.1
                    
#r "nuget: Blazor.GSAP, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blazor.GSAP@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazor.GSAP&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Blazor.GSAP&version=1.1.1
                    
Install as a Cake Tool

โšก Blazor.GSAP

NuGetNuGet downloadsLicense: MIT.NET Support

A lightweight, zero-boilerplate Blazor wrapper for GSAP (GreenSock Animation Platform).

It simplifies JavaScript interoperability by providing a base class that handles dynamic script loading, collocated file imports, and automatic resource cleanup (disposing timelines) on component destruction.

Designed to be fully compatible with Blazor Server, WebAssembly, and .NET MAUI Hybrid.


โœจ Features

Feature Description
๐Ÿš€ Zero Setup No need to manually add <script> tags to index.html. It injects GSAP dynamically.
โœจ Boilerplate-Free Just inherit from GsapComponentBase and start animating.
๐Ÿ“ฑ MAUI Hybrid Ready Uses a robust script injection strategy that works perfectly in strict WebView environments.
๐Ÿงน Auto-Cleanup Automatically calls killAll() when the component is disposed to prevent memory leaks and "ghost" animations.
๐Ÿ“‚ Collocated JS Support Automatically detects and loads [Component].razor.js files.

๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

dotnet add package Blazor.GSAP

๐Ÿš€ Quick Start

Get started in 3 simple steps.

1๏ธโƒฃ Write your animation logic

Create a JavaScript file with the same name as your component in the same directory.

๐Ÿ“„ Pages/Home.razor.js

export function animateBox() {
  // โœ… Use gsap directly. The base class ensures it is loaded.
  gsap.to(".box", {
    rotation: +360,
    duration: 1,
    repeat: -1,
    ease: "none",
  });
}

2๏ธโƒฃ Create your component

Inherit from GsapComponentBase in your Razor component (.razor).

๐Ÿ“„ Pages/Home.razor

@page "/"
@using Blazor.GSAP
@inherits GsapComponentBase

<div class="box"></div>

@code {
    /// <summary>
    /// Lifecycle hook invoked after the GSAP core library and the component-specific JavaScript module have been successfully loaded and initialized.
    /// </summary>
    /// <remarks>
    /// <para>
    /// <strong>Override this method to implement your GSAP animation logic.</strong>
    /// </para>
    /// <para>
    /// This method is intended to be used instead of <see cref="GsapComponentBase.OnAfterRenderAsync"/> for animation initialization.
    /// It guarantees that both the GSAP core and the current component's module (<see cref="GsapComponentBase.JSModule"/>) are available, preventing potential null reference errors during JS interop.
    /// </para>
    /// </remarks>
    protected override async Task OnGsapLoadedAsync() {
        await JSModule.InvokeVoidAsync("animateBox");
    }
}

3๏ธโƒฃ That's it!

  • โœ… No index.html modification required.
  • โœ… No manual Dispose logic required (animations stop automatically when you leave the page).

๐Ÿ”Œ Plugin Usage

Get started by creating a component that uses the SplitText plugin.

1๏ธโƒฃ Write your animation logic

Create a JavaScript file with the same name as your component in the same directory.

๐Ÿ“„ Pages/SplitText.razor.js

// Save instance state
let splitInstance;
let currentAnimation;

function setup() {
  // Revert existing instances to prevent duplicates
  if (splitInstance) splitInstance.revert();
  if (currentAnimation) currentAnimation.revert();

  // Create a new SplitText instance
  splitInstance = new SplitText(".text", { type: "chars,words,lines" });
}

export function init() {
  // โœ… Register the plugin
  gsap.registerPlugin(SplitText);
  setup();
  window.addEventListener("resize", setup);
}

export function animateChars() {
  if (currentAnimation) currentAnimation.revert();

  currentAnimation = gsap.from(splitInstance.chars, {
    x: 150,
    opacity: 0,
    duration: 0.7,
    ease: "power4",
    stagger: 0.04,
  });
}

2๏ธโƒฃ Create your component (C# Code-behind)

Create a .razor.cs partial class to handle logic. This is where you define which GSAP plugins are required.

๐Ÿ“„ Pages/SplitText.razor.cs

using Microsoft.JSInterop;

namespace YourNamespace.Pages;

public partial class SplitText
{
    /// <summary>
    /// ๐Ÿ”Œ Define required plugins here.
    /// The base class ensures these are loaded before OnGsapLoadedAsync is called.
    /// </summary>
    protected override GsapPlugin[] RequiredPlugins { get; } = [GsapPlugin.SplitText];

    /// <summary>
    /// ๐Ÿš€ Lifecycle hook invoked after GSAP and your JS module are loaded.
    /// </summary>
    protected override async Task OnGsapLoadedAsync()
    {
        // Initialize your GSAP logic (e.g., registering plugins, setting up timelines)
        await JSModule.InvokeVoidAsync("init");
    }

    private async Task AnimateChars()
    {
        await JSModule.InvokeVoidAsync("animateChars");
    }
}

3๏ธโƒฃ Create your view (Razor)

Inherit from GsapComponentBase in your Razor component.

๐Ÿ“„ Pages/SplitText.razor

@page "/split-text"
@inherits GsapComponentBase

<div class="container">
    <button @onclick="AnimateChars">Animate Characters</button>

    <div class="text">
        Break apart HTML text into characters, words, and/or lines for easy animation.
    </div>
</div>

4๏ธโƒฃ That's it! By specifying RequiredPlugins, you unlock the full power of GSAP's ecosystem with zero boilerplate:

  • โœ… Automatic Script Loading: The library dynamically injects the necessary plugin scripts (like SplitText.min.js) only when needed, keeping your index.html clean.
  • โœ… Guaranteed Initialization: The OnGsapLoadedAsync hook ensures that both the core GSAP library and your requested plugins are fully loaded before your animation logic runs.
  • โœ… Memory Safe: Just like the core library, plugin instances and timelines are cleaned up automatically when the component is disposed.

โš™๏ธ How it works

๐Ÿ’‰ Dynamic Injection

The library uses a smart injection strategy. Instead of standard ES modules (which can cause issues in MAUI Hybrid WebViews due to strict mode), it dynamically injects a <script> tag. This ensures GSAP is registered globally on the window object, making it compatible with all standard GSAP plugins.

โ™ป๏ธ Automatic Disposal

GsapComponentBase implements IAsyncDisposable. When your Blazor component is disposed:

  1. ๐Ÿ›‘ It calls gsap.globalTimeline.getChildren().forEach(t => t.kill()).
  2. ๐Ÿ—‘๏ธ It disposes of the collocated JS module.
  3. ๐Ÿ›ก๏ธ It ensures no memory leaks occur in your SPA.

๐Ÿ“œ License

The C# source code in this package is licensed under the MIT License.

โš ๏ธ Important License Notice

This is an unofficial wrapper. The underlying GreenSock Animation Platform (GSAP) is a proprietary library subject to the Standard GreenSock License.

While GSAP is free for most use cases, it is not MIT licensed. Commercial usage in products sold to multiple customers (e.g., SaaS, templates) may require a "Business Green" license from GreenSock.

This package is not affiliated with or endorsed by GreenSock.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 496 12/9/2025
1.1.0 454 12/9/2025
1.0.8 437 12/8/2025
1.0.7 447 12/8/2025
1.0.6 441 12/8/2025
1.0.5 432 12/8/2025
1.0.4 435 12/8/2025
1.0.3 370 12/8/2025
1.0.2 372 12/8/2025
1.0.1 359 12/8/2025
1.0.0 351 12/8/2025