Adds the web theme engine

This commit is contained in:
BinaryAlley committed 2026-08-19 10:27:16 -07:00
1 parent 57e8e2ed65
commit 59de6e3df6
29 files changed
+2254 -4

No files matched your search

@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Configuration;
/// <summary>
/// Data transfer object for deserializing theme engine settings.
/// </summary>
[DebuggerDisplay("Section name: {SECTION_NAME}")]
public sealed class ThemeEngineOptionsDto
{
public const string SECTION_NAME = "ThemeEngine";
/// <summary>
/// Gets or sets the directory where installed theme packages are stored.
/// </summary>
public string StoragePath { get; set; } = "Themes";
/// <summary>
/// Gets or sets the file name of the persisted theme settings.
/// </summary>
public string SettingsPath { get; set; } = "theme-settings.json";
/// <summary>
/// Gets or sets the identifier of the theme selected when no valid current theme is persisted.
/// </summary>
public string DefaultThemeId { get; set; } = "lumina-default";
/// <summary>
/// Gets or sets the maximum allowed size of an uploaded theme archive, in bytes.
/// </summary>
public long MaxArchiveBytes { get; set; } = 8 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed total size of an extracted theme archive, in bytes.
/// </summary>
public long MaxExpandedBytes { get; set; } = 24 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed size of a single file within a theme archive, in bytes.
/// </summary>
public long MaxSingleFileBytes { get; set; } = 6 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed number of entries in a theme archive.
/// </summary>
public int MaxEntries { get; set; } = 250;
/// <summary>
/// Gets or sets a value indicating whether theme templates may load script files.
/// </summary>
public bool AllowThemeScripts { get; set; }
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a content entry rendered by a theme.
/// </summary>
/// <param name="Number">The ordering number of the content entry.</param>
/// <param name="Title">The title of the content entry.</param>
/// <param name="Description">The description of the content entry.</param>
/// <param name="Meta">The metadata line of the content entry.</param>
/// <param name="Badge">The badge text of the content entry.</param>
/// <param name="Accent">The accent color of the content entry.</param>
/// <param name="Glyph">The glyph or icon of the content entry.</param>
/// <param name="Url">The URL the content entry links to.</param>
[DebuggerDisplay("Number: {Number}, Title: {Title}")]
public sealed record ContentItemDto(
string Number,
string Title,
string Description,
string Meta,
string Badge,
string Accent,
string Glyph,
string Url
);
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for an installed theme.
/// </summary>
/// <param name="Manifest">The validated theme manifest.</param>
/// <param name="Info">The display metadata of the theme.</param>
/// <param name="RootPath">The absolute path of the installed theme directory.</param>
[DebuggerDisplay("Manifest name: {Manifest.Name}")]
public sealed record InstalledThemeDto(
ThemeManifestDto Manifest,
ThemeInfoDto Info,
string RootPath
);
@@ -0,0 +1,20 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a navigation entry rendered by a theme.
/// </summary>
/// <param name="Key">The unique key of the navigation entry.</param>
/// <param name="Label">The display label of the navigation entry.</param>
/// <param name="Url">The URL the navigation entry links to.</param>
/// <param name="IsCurrent">Whether the navigation entry represents the currently displayed page.</param>
[DebuggerDisplay("Key: {Key}, Label: {Label}")]
public sealed record NavigationItemDto(
string Key,
string Label,
string Url,
bool IsCurrent
);
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the settings persisted for the theme engine.
/// </summary>
[DebuggerDisplay("CurrentThemeId: {CurrentThemeId}")]
public sealed class PersistedThemeSettingsDto
{
/// <summary>
/// Gets or sets the unique identifier of the currently selected theme.
/// </summary>
public string CurrentThemeId { get; set; } = string.Empty;
}
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a statistic rendered by a theme.
/// </summary>
/// <param name="Value">The numeric or textual value of the statistic.</param>
/// <param name="Label">The label of the statistic.</param>
/// <param name="Detail">The additional detail of the statistic.</param>
[DebuggerDisplay("Value: {Value}, Label: {Label}")]
public sealed record StatItemDto(
string Value,
string Label,
string Detail
);
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the data shown on the theme administration page.
/// </summary>
[DebuggerDisplay("CurrentThemeId: {CurrentThemeId}")]
public sealed class ThemeAdminDto
{
/// <summary>
/// Gets or sets the metadata of all installed themes.
/// </summary>
public required IReadOnlyList<ThemeInfoDto> Themes { get; init; }
/// <summary>
/// Gets or sets the unique identifier of the currently selected theme.
/// </summary>
public required string CurrentThemeId { get; init; }
/// <summary>
/// Gets or sets a value indicating whether theme templates may load script files.
/// </summary>
public required bool AllowThemeScripts { get; init; }
/// <summary>
/// Gets or sets the maximum allowed size of a theme archive, in bytes.
/// </summary>
public required long MaxArchiveBytes { get; init; }
/// <summary>
/// Gets the maximum allowed size of a theme archive, in megabytes.
/// </summary>
public double MaxArchiveMegabytes => Math.Round(MaxArchiveBytes / 1024d / 1024d, 1);
}
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using System.IO;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for an in-memory ZIP archive of an installed theme.
/// </summary>
/// <param name="FileName">The file name to expose when downloading the archive.</param>
/// <param name="Content">The ZIP archive stream positioned at its start.</param>
[DebuggerDisplay("FileName: {FileName}")]
public sealed record ThemeArchiveDto(
string FileName,
Stream Content
);
@@ -0,0 +1,26 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the display metadata of a theme.
/// </summary>
/// <param name="Id">The unique identifier of the theme.</param>
/// <param name="Name">The display name of the theme.</param>
/// <param name="Description">The description of the theme.</param>
/// <param name="Author">The author of the theme.</param>
/// <param name="Version">The version of the theme, using semantic version form.</param>
/// <param name="PreviewUrl">The URL of the theme preview image.</param>
/// <param name="IsBundled">Whether the theme ships with the application or noy.</param>
[DebuggerDisplay("Id: {Id}, Name: {Name}")]
public sealed record ThemeInfoDto(
string Id,
string Name,
string Description,
string Author,
string Version,
string PreviewUrl,
bool IsBundled
);
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Enums.Themes;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the metadata persisted alongside an installed theme.
/// </summary>
[DebuggerDisplay("Source: {Source}")]
public sealed class ThemeInstallationMetadataDto
{
/// <summary>
/// Gets or sets the source the theme was installed from.
/// </summary>
public ThemeInstallSource Source { get; set; }
/// <summary>
/// Gets or sets the UTC timestamp at which the theme was installed.
/// </summary>
public DateTimeOffset InstalledAtUtc { get; set; }
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the theme.json manifest of a theme package.
/// </summary>
[DebuggerDisplay("Id: {Id}, Name: {Name}")]
public sealed class ThemeManifestDto
{
/// <summary>
/// Gets or sets the supported schema version of the manifest.
/// </summary>
public int SchemaVersion { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the theme, a lowercase kebab-case value.
/// </summary>
public string Id { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the display name of the theme.
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the description of the theme.
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the author of the theme.
/// </summary>
public string Author { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the version of the theme, using semantic version form.
/// </summary>
public string Version { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the preview image path relative to the theme package root, or <see langword="null"/> when the theme has no preview.
/// </summary>
public string? Preview { get; set; }
/// <summary>
/// Gets or sets the template mappings from template key to an HTML file path under templates/.
/// </summary>
public Dictionary<string, string> Templates { get; set; } = new(StringComparer.OrdinalIgnoreCase);
}
@@ -0,0 +1,103 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the full model available to a theme template while rendering a page.
/// </summary>
[DebuggerDisplay("Title: {Title}")]
public sealed class ThemePageDto
{
/// <summary>
/// Gets or sets the key of the page, used to select the template to render.
/// </summary>
public required string PageKey { get; init; }
/// <summary>
/// Gets or sets the name of the site displayed by the theme.
/// </summary>
public required string SiteName { get; init; }
/// <summary>
/// Gets or sets the title of the page.
/// </summary>
public required string Title { get; init; }
/// <summary>
/// Gets or sets the description of the page.
/// </summary>
public required string Description { get; init; }
/// <summary>
/// Gets or sets the eyebrow text shown above the page title.
/// </summary>
public required string Eyebrow { get; init; }
/// <summary>
/// Gets or sets the label of the primary call to action.
/// </summary>
public required string PrimaryActionLabel { get; init; }
/// <summary>
/// Gets or sets the URL of the primary call to action.
/// </summary>
public required string PrimaryActionUrl { get; init; }
/// <summary>
/// Gets or sets the label of the secondary call to action.
/// </summary>
public required string SecondaryActionLabel { get; init; }
/// <summary>
/// Gets or sets the URL of the secondary call to action.
/// </summary>
public required string SecondaryActionUrl { get; init; }
/// <summary>
/// Gets or sets the navigation entries rendered by the theme.
/// </summary>
public required IReadOnlyList<NavigationItemDto> Navigation { get; init; }
/// <summary>
/// Gets or sets the content entries rendered by the theme.
/// </summary>
public required IReadOnlyList<ContentItemDto> Items { get; init; }
/// <summary>
/// Gets or sets the statistics rendered by the theme.
/// </summary>
public required IReadOnlyList<StatItemDto> Stats { get; init; }
/// <summary>
/// Gets or sets a value indicating whether the page is a theme preview.
/// </summary>
public bool IsPreview { get; init; }
/// <summary>
/// Gets or sets the identifier of the theme rendering the page. Populated immediately before rendering.
/// </summary>
public string ThemeId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name of the theme rendering the page. Populated immediately before rendering.
/// </summary>
public string ThemeName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the version of the theme rendering the page. Populated immediately before rendering.
/// </summary>
public string ThemeVersion { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the base URL of the theme assets. Populated immediately before rendering.
/// </summary>
public string AssetBase { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the current year. Populated immediately before rendering.
/// </summary>
public int CurrentYear { get; set; }
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a rendered document.
/// </summary>
/// <param name="Theme">The metadata of the resolved theme.</param>
/// <param name="Template">The raw template source to render.</param>
[DebuggerDisplay("Theme name: {Theme.Name}")]
public sealed record ThemeRenderDocumentDto(
ThemeInfoDto Theme,
string Template
);
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for the model resolution context used while rendering a theme template.
/// </summary>
/// <param name="Value">The model value this scope resolves expressions against.</param>
/// <param name="Parent">The parent scope, or <see langword="null"/> for the root scope.</param>
[DebuggerDisplay("Value: {Value}")]
public sealed record ThemeRenderScopeDto(
object? Value,
ThemeRenderScopeDto? Parent
);
@@ -0,0 +1,19 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a conditional or repeating section in a theme template.
/// </summary>
/// <param name="Expression">The property path expression that controls the section.</param>
/// <param name="Inverted">Whether the section renders when the resolved value is falsy instead of truthy.</param>
/// <param name="Children">The template nodes rendered when the section is active.</param>
[DebuggerDisplay("Expression: {Expression}")]
public sealed record ThemeSectionNodeDto(
string Expression,
bool Inverted,
IReadOnlyList<ThemeTemplateNodeDto> Children
) : ThemeTemplateNodeDto;
@@ -0,0 +1,6 @@
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Base type for all nodes of a parsed theme template.
/// </summary>
public abstract record ThemeTemplateNodeDto;
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a literal text segment of a theme template.
/// </summary>
/// <param name="Value">The literal text to render as-is.</param>
[DebuggerDisplay("Value: {Value}")]
public sealed record ThemeTextNodeDto(
string Value
) : ThemeTemplateNodeDto;
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.DTO.Themes;
/// <summary>
/// Data transfer object for a variable expression in a theme template.
/// </summary>
/// <param name="Expression">The property path expression to resolve.</param>
/// <param name="ShouldBeEscaped">Whether the rendered value should be HTML encoded.</param>
[DebuggerDisplay("Expression: {Expression}")]
public sealed record ThemeVariableNodeDto(
string Expression,
bool ShouldBeEscaped
) : ThemeTemplateNodeDto;