WidgetStudio.Contracts 0.2.0

dotnet add package WidgetStudio.Contracts --version 0.2.0
                    
NuGet\Install-Package WidgetStudio.Contracts -Version 0.2.0
                    
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="WidgetStudio.Contracts" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WidgetStudio.Contracts" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="WidgetStudio.Contracts" />
                    
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 WidgetStudio.Contracts --version 0.2.0
                    
#r "nuget: WidgetStudio.Contracts, 0.2.0"
                    
#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 WidgetStudio.Contracts@0.2.0
                    
#: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=WidgetStudio.Contracts&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=WidgetStudio.Contracts&version=0.2.0
                    
Install as a Cake Tool

WidgetStudio.Contracts

C# contracts for the widget JSON rendered by the @lieselthuriot/widget-renderer Angular package. Build widgets in a .NET API, serialize them with the included source-generated context, and render them in the browser.

The package targets netstandard2.0.

Installation

dotnet add package WidgetStudio.Contracts

Usage

using System.Text.Json;
using WidgetStudio.Contracts;
using WidgetStudio.Contracts.Elements;
using WidgetStudio.Contracts.Enums;
using WidgetStudio.Contracts.Styles;

var widget = new WidgetContract
{
    Id = "hello-widget",
    Size = WidgetSize.Square,
    Rows = [GridTrack.Auto],
    Columns = [GridTrack.Star()],
    Background = new BackgroundConfig
    {
        Color = WidgetColor.Rgb(23, 32, 51),
        Sensitive = false,
        Repeat = false,
        Size = BackgroundSize.Cover,
        Anchor = ElementAnchor.Center,
    },
    Refresh = new RefreshConfig { Enabled = true, Label = "Refresh widget" },
    Elements =
    [
        new TextElement
        {
            Grid = new ElementGrid { Row = 0, Column = 0, RowSpan = 1, ColumnSpan = 1, Anchor = ElementAnchor.Center },
            Sensitive = false,
            Text = "Hello from .NET",
            Style = new TextStyle
            {
                Color = WidgetColor.White,
                Font = new TextFontStyle { Size = 16, Bold = true },
                Align = TextAlign.Center,
                Wrap = true,
            },
        },
    ],
};

var json = JsonSerializer.Serialize(widget, WidgetJsonContext.Default.WidgetContract);

Always serialize with WidgetJsonContext. It emits camel-case property names, lowercase enum values, space-separated anchor values such as "top left", and the type discriminator required by the renderer's polymorphic element model. It also omits null properties. The default JsonSerializerOptions do not produce the renderer wire format.

This package is primarily a serialization layer. When deserializing external JSON with WidgetJsonContext, put each polymorphic discriminator before the object's other properties: type first for widget elements and kind first for progress items. JSON produced by WidgetJsonContext already has this order.

Layout fingerprints

WidgetFingerprint.Compute returns a stable ID of a widget's look, such as wfp:1:3f9c…, and matches computeWidgetFingerprint from @lieselthuriot/widget-renderer. Use it to gate user-built widgets behind an approval step:

var fingerprint = widget.ComputeFingerprint(); // or WidgetFingerprint.Compute(json)
var approved = fingerprint is not null && approvedLayouts.Contains(fingerprint);

Content that can differ per visitor is ignored: the widget Id, text, button labels, image alt text, chart titles, chart and progress data, button URLs and bodies, and the refresh label. Only whether text, labels, alt text, and titles are empty is included. Styles, positions, element order, image sources, and the background are included. Compute returns null when the JSON cannot be deserialized or the widget has no rows or columns; validate payloads with the renderer for the full rule set.

Colors

Use WidgetColor to create renderer-compatible hexadecimal colors without formatting channel values by hand:

using WidgetStudio.Contracts;

var background = WidgetColor.Rgb(16, 24, 39);       // #101827
var overlay = WidgetColor.Rgba(16, 24, 39, 184);    // #101827b8
var softBlue = WidgetColor.Pastel(WidgetColor.Blue); // #8080ff
var transparent = WidgetColor.Transparent;           // #00000000

Pastel accepts #RGB, #RRGGBB, and #RRGGBBAA values, blends the color toward white, and preserves an input alpha channel. Its default blend amount is 50%; pass a value from 0 to 1 as the second argument to control the blend.

Compatibility

The package and the npm renderer share the same JSON wire format, and the repository tests serialized contracts against the built renderer. Use matching versions of WidgetStudio.Contracts and @lieselthuriot/widget-renderer.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.2.0 85 11/6/2026
0.1.0 106 10/27/2026