From a8e85d067314c9d58368825492691f42d3b033fd Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Fri, 16 Oct 2026 10:02:55 +0300 Subject: [PATCH] Adds the themeable audio player bar and its theming contract. --- docs/technical/theming/Theming.md | 40 +++++- .../Core/Themes/Bundled/editorial-paper.zip | Bin 373601 -> 374932 bytes .../Core/Themes/Bundled/lumina-default.zip | Bin 373064 -> 374395 bytes .../Common/DTO/Themes/ThemeAudioPlayerDto.cs | 23 ++++ .../PresentationWebLayerServices.cs | 2 + .../Core/Themes/ThemeAudioPlayerBuilder.cs | 78 ++++++++++++ .../Core/Themes/ThemeAudioPlayerRenderer.cs | 102 +++++++++++++++ .../Core/Themes/ThemeLayoutRenderer.cs | 24 +++- .../Core/Views/Shared/_AudioPlayer.cshtml | 14 ++- .../Views/Shared/_ThemeLayoutScripts.cshtml | 1 + .../wwwroot/css/site.css | 9 ++ .../wwwroot/js/audio-player/audio-player.js | 119 +++++++++++++++--- .../js/theme-client-template-engine.js | 4 +- .../Core/Themes/ThemeLayoutRendererTests.cs | 4 +- 14 files changed, 392 insertions(+), 28 deletions(-) create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeAudioPlayerDto.cs create mode 100644 src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs create mode 100644 src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerRenderer.cs diff --git a/docs/technical/theming/Theming.md b/docs/technical/theming/Theming.md index b22ec44a..d774e536 100644 --- a/docs/technical/theming/Theming.md +++ b/docs/technical/theming/Theming.md @@ -14,6 +14,7 @@ The web client of Lumina is a themed shell: every page is rendered inside the te - [Template Resolution](#template-resolution) - [The Layout Template (shared/layout)](#the-layout-template-sharedlayout) - [The Audio Player Bar](#the-audio-player-bar) + - [The audio player sub templates](#the-audio-player-sub-templates) - [The Navigation Template (shared/nav-menu)](#the-navigation-template-sharednav-menu) - [Page Templates](#page-templates) - [The Scripts Section](#the-scripts-section) @@ -162,6 +163,9 @@ Known page keys: | `shared/layout` | The layout that wraps the shell of every page. | | `shared/nav-menu` | The navigation menu of the theme. | | `shared/not-found` | The 404 page. | +| `shared/audio-player` | The audio player bar shell. | +| `shared/audio-player/queue-item` | The queue item of the audio player bar. | +| `shared/audio-player/playlist-item` | The playlist item of the audio player bar. | | `library/written-content-library/book-library/books/index` | The books browsing page. | | `shared/file-system-browser` | The file system browser component shell. | | `shared/file-system-browser/tree-node` | The tree view node of the file system browser. | @@ -225,7 +229,7 @@ The rendered page content, navigation and scripts are inserted unescaped with `{ ### The Audio Player Bar -Every authenticated page renders the audio player bar through the `audioPlayer` field of the layout model. The bar is hidden until the user starts playback of a track, album or artist, and the global audio player script shows it, expands it and hides it again. The theming work that turns the bar into a theme template (a `shared/audio-player` page key with sub templates) is not part of this contract yet; until it lands, the bar is the application fallback markup, passed in as the `audioPlayer` field. +Every authenticated page renders the audio player bar through the `audioPlayer` field of the layout model. The bar is hidden until the user starts playback of a track, album or artist, and the global audio player script shows it, expands it and hides it again. The markup comes from the `shared/audio-player` template of the active theme; when the theme does not provide that template, the application renders its own fallback markup, so the player always has a bar to bind to. The bar is fixed to the bottom of the viewport, so the theme owns the room reserved for it on the main content element. A layout must keep these element hooks, which the audio player drives (the two id controls are bound by the global site script, which routes them to the audio player): @@ -235,8 +239,18 @@ The bar is fixed to the bottom of the viewport, so the theme owns the room reser | The bar container | `full-height` class | The bar is expanded to its full height form. | | The main content element | `audio-player-not-shown` class | The bar is hidden, so the content area uses the full height. | | The main content element | `audio-player-full-height` class | The bar is expanded, so the content area gives it the full height. | -| The full height control | `id="audio-player-full-height-toggle"` | Expands or collapses the bar. | -| The close control | `id="audio-player-close"` | Stops playback, and hides the bar while it is condensed. | +| The full height control | `id="audio-player-full-height-toggle"` | A focusable control, such as a `button`, that expands or collapses the bar. | +| The close control | `id="audio-player-close"` | A focusable control, such as a `button`, that stops playback and hides the bar while it is condensed. | + +The `shared/audio-player` template receives the following model: + +| Field | Content | +| --- | --- | +| `appBase` | The absolute base URL of the Web application, used to reference the application scripts. | +| `assetBase` | The base URL of the theme assets, used by the theme template to reference its own assets. | +| `queueItemTemplate` | The raw source of the `shared/audio-player/queue-item` sub template, inlined by the application into a plain text script element. | +| `playlistItemTemplate` | The raw source of the `shared/audio-player/playlist-item` sub template, inlined by the application into a plain text script element. | +| `strings` | The localized strings of the bar, keyed by their resource names. | A theme must reserve the space for the bar itself, as the bundled themes do: @@ -257,7 +271,25 @@ main.audio-player-full-height { The application fallback layout, which renders when the active theme cannot be loaded, reserves the room itself, because the application stylesheet does not position the content area of a theme. A theme that omits the rules above leaves the fixed bar overlapping the bottom of the page. -The markup inside the bar exposes the hook attributes the audio player script binds, such as `data-audio-player-play-pause`, `data-audio-player-progress`, `data-audio-player-current-time` and `data-audio-player-track-name`. A theme that replaces the bar markup must keep those attributes, and the play affordances of the pages use the `data-audio-player-play` trigger attribute. +The markup inside the bar exposes the ten hook attributes the audio player script binds: `data-audio-player-play-pause`, `data-audio-player-progress`, `data-audio-player-progress-played`, `data-audio-player-progress-downloaded`, `data-audio-player-current-time`, `data-audio-player-total-time`, `data-audio-player-track-name`, `data-audio-player-cover-thumbnail`, `data-audio-player-cover-image` and `data-audio-player-queue`. A theme that replaces the bar markup must keep all of them; the part of the bar whose hook is missing stays inert. The play affordances of the pages use the `data-audio-player-play` trigger attribute. + +#### The audio player sub templates + +Like the file system browser, the audio player is split into a shell template and the sub templates of its dynamic content, all provided as mirrored files under `templates/shared/audio-player/`. The shell template inlines the raw source of each sub template into a plain text script element, so that the browser never parses the theme markup into live elements and requests their resources before the player renders them: + +```html + + +``` + +The sub templates are rendered client side by the audio player script with the same Mustache syntax as the server side engine. They receive the following fields: + +| Template | Fields | +| --- | --- | +| `queue-item` | `index` (the one based position in the queue), `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration` (the formatted `m:ss` duration), `durationSeconds`, `coverArtUrl`, `isCurrent`, `isPlayed` and `isLast`. The item root must keep the `audio-player-queue-item` class, the stylesheet hook of a queue item: the player appends the rendered element as-is, so the class is what lets the theme style it. | +| `playlist-item` | `index`, `trackId`, `albumId`, `artistId`, `libraryId`, `title`, `duration`, `durationSeconds`, `coverArtUrl` and `isCurrent`. The item root must keep the `audio-player-playlist-item` class, the stylesheet hook of a playlist item. Saved playlists do not exist yet, so the shell inlines this sub template for theme authors, but nothing renders it yet; the playlist feature renders the entries of a playlist from it. | + +A theme can omit either sub template: the player then renders that part with its own built-in markup. When a theme replaces the shell, it must keep the two plain text script element ids above, the element hooks of the bar, and the `audio-player-container`, `not-shown` and `full-height` classes the player toggles. ### The Navigation Template (shared/nav-menu) diff --git a/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip b/src/Lumina.Presentation.Api/Core/Themes/Bundled/editorial-paper.zip index 7fd8df7e1038f8cc438c5349992a03a783b47139..8085208a85d9cd4f3f449750f4066d812f6d7774 100644 GIT binary patch delta 5831 zcma)A2~dr0TEf;g9a4|LBv6uVUb}` zKvo@fa1Ce_B1DC+CQ$@IBICesC>x-T|C$y;h?WY zqiZ&LO~0f=5JyK5gtf5gojEEOQOc5!35_}!*ns9R8v12>^syxO(w-4`FuLtKE*_M3 z>M(=L@6s?>x>%jnhTW37n6l1d+tN4AtO^X17R_LNH;mSl+OA-k8sgFUMAipJ*C&=0 z%IKcWW~pN@qz#p<4kL`Ky2h$eR;N8bs21n8VmLuq*do?MmZh}t7AtNz#u#_A)-zoD zNp=FZUZiitW~dD9*i}3XYxH6_8Q_sPh<%!Ia_Kg95o3sh*n1h-zA|<%4qdwUGCP6M zP;X%`)55x8FWH$4PKm?eGBynKIcyDjw#e9mV})V7xtz&rc;vr?)5*ZR!Z{NeKNELw z4l`y)XK_?DG0wS^bDJ@%eu?AvHI}XW%+X$rM+pI>4o(HBD3G+kxqxZ~WDA}Y2a#4x z>RbyZd3aL#GL+O{Mtx!A6=t?Bg3M<|;gRG$oPAP{STcnnzPpKBL1I3a?W8p`66_>9 zm|2hAq%1wv63N||MH0;OVAAuXd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o`gkr_z({Nkg1+?q2mCHMb17J|ia(#;9QV`>w2;W-uIzF=>&`bx^MSdOp(JfsJ*k*r-DaRuX1 zwE!bp5#Co$VR9=Q$0LiL@$BJ!v|_{p9ARaRkdg`>SuhwkGZ*-wRo(1kVrFm!DlWw! zv@P$;N|g|E1e+KBoPdvT0v125qVP2^W7qGBxTDO&Z*dJJ&!@wjh1P8yhk3XwPqt%g z!S)b7*7B_W$kFq(GZsQpefPYVH)EDSwUeMsxw749RucBwCrN~i*Q9plpI~mnn(mj% z2EyieW(SiFMG<8yE$Zp16(f*XcU&b0= zBZqK8BDcOmHt{5dBN6afGd4rnX;l-#udVE|Y-?DUk-2=(+$9U$2 JUkP3$@_+4tli~mX diff --git a/src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeAudioPlayerDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeAudioPlayerDto.cs new file mode 100644 index 00000000..923565b8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Themes/ThemeAudioPlayerDto.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Themes; + +/// +/// Data transfer object for the model available to the themed audio player template. +/// +/// The absolute base URL of the Web application, used to reference application scripts from the theme template. +/// The base URL of the theme assets, used by the theme template to reference its own assets. +/// The raw template source of a queue item, rendered client side for each track of the play context. +/// The raw template source of a playlist item, rendered client side for each entry of a saved playlist. +/// The localized strings of the audio player, keyed by resource name. +[DebuggerDisplay("AssetBase: {AssetBase}")] +public sealed record ThemeAudioPlayerDto( + string AppBase, + string AssetBase, + string QueueItemTemplate, + string PlaylistItemTemplate, + IReadOnlyDictionary Strings +); diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs index 8c424fe3..1f78ce97 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs @@ -351,6 +351,8 @@ public static class PresentationWebLayerServices services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs new file mode 100644 index 00000000..6f00a28f --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerBuilder.cs @@ -0,0 +1,78 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.Themes; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Localization; +using System.Collections.Generic; +#endregion + +namespace Lumina.Presentation.Web.Core.Themes; + +/// +/// Builds the audio player model for the themed component template, resolving the localized strings and theme asset URLs server side. +/// +public sealed class ThemeAudioPlayerBuilder +{ + // The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath. + private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Shared._Layout"; + private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web"; + + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IStringLocalizer _localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Injected factory used to create the localizer of the audio player resources. + /// Injected accessor for the current HTTP context. + public ThemeAudioPlayerBuilder(IStringLocalizerFactory stringLocalizerFactory, IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + _localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION); + } + + /// + /// Builds the model of the audio player for the given theme. + /// + /// The base URL of the assets of the active theme. + /// The raw template source of a queue item, or an empty string when the theme does not provide one. + /// The raw template source of a playlist item, or an empty string when the theme does not provide one. + /// The model available to the themed audio player template. + public ThemeAudioPlayerDto Build(string assetBase, string queueItemTemplate, string playlistItemTemplate) + { + Dictionary strings = new() + { + ["toggleFullHeight"] = Localize("ToggleFullHeight"), + ["toggleVisibility"] = Localize("ToggleVisibility") + }; + + return new ThemeAudioPlayerDto( + AppBase: GetAppBaseUrl(), + AssetBase: assetBase, + QueueItemTemplate: queueItemTemplate, + PlaylistItemTemplate: playlistItemTemplate, + Strings: strings); + } + + /// + /// Gets the absolute base URL of the current Web application request, used to reference the application scripts from a static theme template. + /// + /// The absolute base URL with a trailing slash, or an empty string when the current HTTP context is unavailable. + private string GetAppBaseUrl() + { + HttpRequest? request = _httpContextAccessor.HttpContext?.Request; + if (request is null) + return string.Empty; + + return $"{request.Scheme}://{request.Host}{request.PathBase}/"; + } + + /// + /// Resolves a localized audio player string. + /// + /// The resource key of the string. + /// The localized string. + private string Localize(string key) + { + return _localizer[key].Value; + } +} diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerRenderer.cs new file mode 100644 index 00000000..f7b71542 --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeAudioPlayerRenderer.cs @@ -0,0 +1,102 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DTO.Themes; +using Lumina.Presentation.Web.Common.Primitives; +using System; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Core.Themes; + +/// +/// Renders the audio player bar with a theme, inlining the sub templates of its dynamic content so that the client script can render queue items and playlist items from theme markup. +/// +public class ThemeAudioPlayerRenderer +{ + // The page keys mirror the template files of the theme packs, pinned in each theme manifest so that a missing sub template does not resolve to the component shell template. + private const string SHELL_PAGE_KEY = "shared/audio-player"; + private const string QUEUE_ITEM_PAGE_KEY = "shared/audio-player/queue-item"; + private const string PLAYLIST_ITEM_PAGE_KEY = "shared/audio-player/playlist-item"; + + private readonly ThemeService _themeService; + private readonly ThemeTemplateEngine _templateEngine; + private readonly ThemeAudioPlayerBuilder _builder; + + /// + /// Initializes a new instance of the class. + /// + /// The service that resolves the render documents. + /// The template engine used to render the component shell template. + /// The builder used to produce the component model. + public ThemeAudioPlayerRenderer(ThemeService themeService, ThemeTemplateEngine templateEngine, ThemeAudioPlayerBuilder builder) + { + _themeService = themeService; + _templateEngine = templateEngine; + _builder = builder; + } + + /// + /// Renders the themed audio player bar with the specified theme. + /// + /// The manifest id of the theme to render the bar with, normally the theme the layout was resolved with. + /// Cancellation token that can be used to stop the execution. + /// An containing either the component HTML, or an error. + public virtual async Task> RenderAsync(string themeId, CancellationToken cancellationToken) + { + try + { + ThemeRenderDocumentDto shellDocument = await _themeService.GetRenderDocumentAsync(SHELL_PAGE_KEY, themeId, cancellationToken).ConfigureAwait(false); + string assetBase = $"/theme-assets/{themeId}/assets"; + + string queueItemTemplate = await GetSubTemplateAsync(themeId, shellDocument.Template, QUEUE_ITEM_PAGE_KEY, cancellationToken).ConfigureAwait(false); + string playlistItemTemplate = await GetSubTemplateAsync(themeId, shellDocument.Template, PLAYLIST_ITEM_PAGE_KEY, cancellationToken).ConfigureAwait(false); + + ThemeAudioPlayerDto model = _builder.Build(assetBase, queueItemTemplate, playlistItemTemplate); + Result renderResult = _templateEngine.RenderPage(shellDocument.Template, model); + if (renderResult.IsFailure) + return renderResult.Errors; + + return renderResult.Value.Content + renderResult.Value.Script; + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception) + { + // The audio player bar is best effort: when the component template of the active theme cannot be loaded or rendered, the application Razor fallback is rendered instead. + return Error.NotFound(code: "Theme.Template.Unavailable", description: "The audio player theme template could not be loaded."); + } + } + + /// + /// Gets the raw template source of an audio player sub template, degrading to an empty string when the theme does not provide one. + /// + /// The manifest id of the active theme. + /// The raw template source of the component shell, used to detect the mirrored resolution falling back to the shell when a sub template is missing. + /// The page key of the sub template. + /// Cancellation token that can be used to stop the execution. + /// The raw template source, or an empty string when the theme does not provide the template. + private async Task GetSubTemplateAsync(string themeId, string shellTemplate, string pageKey, CancellationToken cancellationToken) + { + try + { + ThemeRenderDocumentDto document = await _themeService.GetRenderDocumentAsync(pageKey, themeId, cancellationToken).ConfigureAwait(false); + // When the theme does not ship the sub template, the mirrored template resolution walks up the path scopes + // and returns the component shell template instead, which the client script must not render as dynamic content. + if (string.Equals(document.Template, shellTemplate, StringComparison.Ordinal)) + return string.Empty; + + return document.Template; + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception) + { + // Each sub template is best effort: when the theme omits one, the client script renders that part with its built-in markup instead. + return string.Empty; + } + } +} diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs index ecb86226..119d6a21 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeLayoutRenderer.cs @@ -22,6 +22,7 @@ public class ThemeLayoutRenderer private readonly ThemeTemplateEngine _templateEngine; private readonly RazorViewToStringRenderer _viewRenderer; private readonly ThemeNavBuilder _navBuilder; + private readonly ThemeAudioPlayerRenderer _audioPlayerRenderer; private readonly IHttpContextAccessor _httpContextAccessor; /// @@ -31,13 +32,15 @@ public class ThemeLayoutRenderer /// The template engine used to render the documents. /// The renderer used to produce the application chrome fragments. /// The builder used to produce the navigation menu model. + /// The renderer used to produce the themed audio player bar. /// Injected accessor for the current HTTP context. - public ThemeLayoutRenderer(ThemeService themeService, ThemeTemplateEngine templateEngine, RazorViewToStringRenderer viewRenderer, ThemeNavBuilder navBuilder, IHttpContextAccessor httpContextAccessor) + public ThemeLayoutRenderer(ThemeService themeService, ThemeTemplateEngine templateEngine, RazorViewToStringRenderer viewRenderer, ThemeNavBuilder navBuilder, ThemeAudioPlayerRenderer audioPlayerRenderer, IHttpContextAccessor httpContextAccessor) { _themeService = themeService; _templateEngine = templateEngine; _viewRenderer = viewRenderer; _navBuilder = navBuilder; + _audioPlayerRenderer = audioPlayerRenderer; _httpContextAccessor = httpContextAccessor; } @@ -58,7 +61,7 @@ public class ThemeLayoutRenderer string appHead = await _viewRenderer.RenderPartialAsync("_ThemeLayoutHead", cancellationToken); string nav = await RenderNavAsync(themeId, cancellationToken); - string audioPlayer = isAuthenticated ? await _viewRenderer.RenderPartialAsync("_AudioPlayer", cancellationToken) : string.Empty; + string audioPlayer = isAuthenticated ? await RenderAudioPlayerAsync(themeId, cancellationToken) : string.Empty; string appScripts = await _viewRenderer.RenderPartialAsync("_ThemeLayoutScripts", cancellationToken); ThemeLayoutModelDto layoutModel = new( @@ -119,4 +122,21 @@ public class ThemeLayoutRenderer return await _viewRenderer.RenderPartialAsync("_NavMenu", cancellationToken); } + + /// + /// Renders the audio player bar with the theme the layout was resolved with, falling back to the application Razor markup when the theme does not provide a bar template. + /// + /// The manifest id of the theme the layout was rendered with, so that the bar always matches the shell, including a preview of another theme. + /// Cancellation token that can be used to stop the execution. + /// The rendered audio player bar HTML. + private async Task RenderAudioPlayerAsync(string themeId, CancellationToken cancellationToken) + { + // The audio player renderer already degrades to an error when the theme template is missing or cannot be + // rendered, so a failure here only means the application fallback markup is rendered instead. + Result audioPlayerResult = await _audioPlayerRenderer.RenderAsync(themeId, cancellationToken); + if (audioPlayerResult.IsSuccess) + return audioPlayerResult.Value; + + return await _viewRenderer.RenderPartialAsync("_AudioPlayer", cancellationToken); + } } diff --git a/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml b/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml index 61363d5b..29783fdf 100644 --- a/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml +++ b/src/Lumina.Presentation.Web/Core/Views/Shared/_AudioPlayer.cshtml @@ -9,9 +9,10 @@ @* APPLICATION FALLBACK AUDIO PLAYER BAR - READ BEFORE EDITING - This partial renders the audio player bar into the layout of the application and of every theme, for an - authenticated visitor. It is only the markup: the behavior lives in the global audio player script - (wwwroot/js/audio-player/), which binds to the hooks documented below. + This partial renders the audio player bar into the fallback layout of the application, for an authenticated visitor. + The themed layout renders the same bar from the 'shared/audio-player' template of the active theme instead, and only + calls this partial when the theme does not provide one. Either way, the markup is only the structure: the behavior + lives in the global audio player script (wwwroot/js/audio-player/), which binds to the hooks documented below. The bar is hidden by default. The 'hidden' attribute keeps it unrendered until the audio player script takes over, so a page load never shows the bar, not even for a frame while the stylesheets settle. The script then hands the bar @@ -26,6 +27,9 @@ binds and routes to the audio player. - The hook attributes the audio player binds: 'data-audio-player-play-pause', '-progress', '-progress-played', '-progress-downloaded', '-current-time', '-total-time', '-track-name', '-cover-thumbnail', '-cover-image' and '-queue'. + - The plain text script elements that carry the raw source of the 'shared/audio-player/queue-item' and + 'shared/audio-player/playlist-item' sub templates, with the ids 'audio-player-template-queue-item' and + 'audio-player-template-playlist-item'. The play affordances the pages hand to the player use the 'data-audio-player-play' trigger attribute. The 'The Audio Player Bar' section of docs/technical/theming/Theming.md documents this contract for theme authors. @@ -53,8 +57,8 @@
- @localizer["ToggleFullHeight"] - @localizer["ToggleVisibility"] + +
diff --git a/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml b/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml index 89faf6c9..3b80ea66 100644 --- a/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml +++ b/src/Lumina.Presentation.Web/Core/Views/Shared/_ThemeLayoutScripts.cshtml @@ -45,6 +45,7 @@ + diff --git a/src/Lumina.Presentation.Web/wwwroot/css/site.css b/src/Lumina.Presentation.Web/wwwroot/css/site.css index a53b68e9..dfa4b18f 100644 --- a/src/Lumina.Presentation.Web/wwwroot/css/site.css +++ b/src/Lumina.Presentation.Web/wwwroot/css/site.css @@ -1407,6 +1407,15 @@ html.audio-player-initializing .audio-player-container { gap: 10px; } +.audio-player-controls button { + background: none; + border: none; + padding: 0px; + color: inherit; + font: inherit; + cursor: pointer; +} + .audio-player-expanded { display: none; flex: 1 1 auto; diff --git a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player.js b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player.js index 64b05f4e..cc1c5a23 100644 --- a/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player.js +++ b/src/Lumina.Presentation.Web/wwwroot/js/audio-player/audio-player.js @@ -27,7 +27,7 @@ * - on(event, handler): subscribes to a player event, returns an unsubscribe function. * - once(event, handler), off(event, handler): one shot subscribe, and unsubscribe. * - getState(), getDescriptor(), getQueue(), getCurrentTime(), getDuration(), - * getVolume(), isMuted(), getPreferences(), getCapabilities(), getLastError(). + * getVolume(), isMuted(), getPreferences(), getCapabilities(), getLastError(), getSubTemplates(). * - destroyAsync(): releases every resource of the player. It is only used for an explicit teardown, never * by a navigation, because the navigation manager never recreates the player. * - registerEngine(name, factory): registers an engine factory on this player, by name. @@ -264,6 +264,26 @@ return text === '' ? '' : text; } + /** + * Reads the raw source of a theme sub template element of the player bar, or null when the theme does not provide one. + * + * The theme inlines the sub template sources into plain text script elements of the bar, so that the browser never + * parses the theme markup into live elements and requests their resources before the player renders them. The raw + * source is recovered by reading the element text, exactly like the file system browser does it. + * @param {string} elementId - The id of the plain text template element. + * @returns {string|null} The raw template source, or null when the element or the template engine is missing. + */ + function readSubTemplate(elementId) { + const templateElement = document.getElementById(elementId); + if (!templateElement) + return null; + // The theme template engine may be absent on a partially loaded page, in which case the built-in markup is used. + if (typeof window.renderThemeTemplate !== 'function') + return null; + // An empty template element means the theme does not provide the template, in which case the built-in markup is used. + return templateElement.textContent || null; + } + /** * Reads a play descriptor from the data attributes of a play trigger element, per * {@link LuminaAudioPlayer.PLAY_DESCRIPTOR_DATA_KEYS}. @@ -335,6 +355,8 @@ this.container = null; this.main = null; this.dom = {}; + // The raw theme sub templates of the dynamic content, read once with the bar elements and null when the theme does not provide them. + this.subTemplates = { queueItem: null, playlistItem: null }; this.descriptorClickHandler = null; this.controlHandlers = []; this.isProgressRenderScheduled = false; @@ -392,6 +414,12 @@ this.dom.progressDownloaded = query('[data-audio-player-progress-downloaded]'); this.dom.playPause = query('[data-audio-player-play-pause]'); this.dom.queue = query('[data-audio-player-queue]'); + // The sub template sources are read once, with the bar elements, because the theme markup is part of the bar + // the player was bound to, and the player is never recreated by a navigation. + this.subTemplates = { + queueItem: readSubTemplate('audio-player-template-queue-item'), + playlistItem: readSubTemplate('audio-player-template-playlist-item') + }; } /** @@ -715,6 +743,14 @@ return [...this.queue]; } + /** + * Gets the raw theme sub templates the player renders its dynamic content from. + * @returns {Object} The sub templates, with a queueItem and a playlistItem source, each null when the theme provides none. + */ + getSubTemplates() { + return { ...this.subTemplates }; + } + /** * Gets the playhead of the current track. * @returns {number} The playhead, in seconds. @@ -1272,27 +1308,82 @@ /** * Renders the ordered queue in the expanded bar. The list is only shown when the play context * holds more than one track, so that a single track never renders a one item list. + * + * Each item is rendered from the 'shared/audio-player/queue-item' sub template of the active theme when it + * provides one, so that the theme owns the structure of a queue item, and the built-in markup is used otherwise. */ renderQueue() { if (!this.dom.queue) return; this.dom.queue.innerHTML = ''; const items = this.queue.length > 1 ? this.queue : []; - for (const item of items) { - const entry = document.createElement('li'); - entry.className = 'audio-player-queue-item'; - entry.dataset.trackId = item.trackId; - const title = document.createElement('span'); - title.className = 'audio-player-queue-item-title'; - title.textContent = item.title || ''; - const duration = document.createElement('span'); - duration.className = 'audio-player-queue-item-duration'; - duration.textContent = formatDuration(item.durationInSeconds); - entry.appendChild(title); - entry.appendChild(duration); - this.dom.queue.appendChild(entry); + for (let index = 0; index < items.length; index++) { + const entry = this.renderQueueItem(items[index], index, items.length); + if (entry) + this.dom.queue.appendChild(entry); } } + + /** + * Renders one queue item, from the theme sub template when the theme provides one and from the built-in markup + * otherwise. + * @param {Object} item - The play descriptor of the item. + * @param {number} index - The zero based position of the item in the queue. + * @param {number} totalItems - The number of items in the queue. + * @returns {HTMLElement|null} The rendered queue item, or null when the markup produced no element. + */ + renderQueueItem(item, index, totalItems) { + // The model exposes only what a queue item can show, so a theme template never reaches into the player internals. + const viewModel = { + index: index + 1, + trackId: item.trackId, + albumId: item.albumId, + artistId: item.artistId, + libraryId: item.libraryId, + title: item.title || '', + duration: formatDuration(item.durationInSeconds), + durationSeconds: item.durationInSeconds, + coverArtUrl: item.coverArtUrl || '', + isCurrent: index === this.currentIndex, + isPlayed: index < this.currentIndex, + isLast: index === totalItems - 1 + }; + if (this.subTemplates.queueItem) { + try { + const container = document.createElement('div'); + container.innerHTML = window.renderThemeTemplate(this.subTemplates.queueItem, viewModel); + const entry = container.firstElementChild; + if (entry) + return entry; + } catch (error) { + // A broken theme sub template falls through to the built-in markup, so the queue never disappears. + console.error('Audio player: the theme queue item template could not be rendered.', error); + } + } + return this.buildDefaultQueueItem(viewModel); + } + + /** + * Builds one queue item with the built-in markup, used when the theme provides no queue item sub template. + * @param {Object} viewModel - The queue item model, per {@link LuminaAudioPlayer.AudioPlayer#renderQueueItem}. + * @returns {HTMLElement} The built-in queue item. + */ + buildDefaultQueueItem(viewModel) { + const entry = document.createElement('li'); + entry.className = 'audio-player-queue-item'; + entry.dataset.trackId = viewModel.trackId; + if (viewModel.isCurrent) + entry.classList.add('is-current'); + const title = document.createElement('span'); + title.className = 'audio-player-queue-item-title'; + title.textContent = viewModel.title; + const duration = document.createElement('span'); + duration.className = 'audio-player-queue-item-duration'; + duration.textContent = viewModel.duration; + entry.appendChild(title); + entry.appendChild(duration); + return entry; + } } LuminaAudioPlayer.AudioPlayer = AudioPlayer; diff --git a/src/Lumina.Presentation.Web/wwwroot/js/theme-client-template-engine.js b/src/Lumina.Presentation.Web/wwwroot/js/theme-client-template-engine.js index 64446976..e1d8c3d1 100644 --- a/src/Lumina.Presentation.Web/wwwroot/js/theme-client-template-engine.js +++ b/src/Lumina.Presentation.Web/wwwroot/js/theme-client-template-engine.js @@ -1,6 +1,6 @@ // A small, non-executable Mustache-style renderer, mirroring the subset of the server side ThemeTemplateEngine that the -// file system browser uses. The theme sub templates rendered by this script can place values and test truthiness, but cannot execute JavaScript. -// It is loaded lazily together with the file system browser dialog script, and exposed globally so that components can share it. +// file system browser and the audio player use. The theme sub templates rendered by this script can place values and test truthiness, but cannot execute JavaScript. +// It is loaded globally by the layout scripts, and exposed globally so that every component shares a single instance. (function () { 'use strict'; diff --git a/tests/UnitTests/Lumina.Presentation.Web.UnitTests/Core/Themes/ThemeLayoutRendererTests.cs b/tests/UnitTests/Lumina.Presentation.Web.UnitTests/Core/Themes/ThemeLayoutRendererTests.cs index 33616a08..7088d346 100644 --- a/tests/UnitTests/Lumina.Presentation.Web.UnitTests/Core/Themes/ThemeLayoutRendererTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Web.UnitTests/Core/Themes/ThemeLayoutRendererTests.cs @@ -85,7 +85,9 @@ public class ThemeLayoutRendererTests RazorViewToStringRenderer viewRenderer = new(_mockViewEngine, _mockTempDataProvider, _mockServiceProvider, _mockHttpContextAccessor); ThemeNavBuilder navBuilder = new(_mockUrlService, _mockStringLocalizerFactory, _mockAuthorizationService, _mockHttpContextAccessor); ThemeService themeService = new(_mockApiHttpClient); - _sut = new ThemeLayoutRenderer(themeService, new ThemeTemplateEngine(), viewRenderer, navBuilder, _mockHttpContextAccessor); + ThemeAudioPlayerBuilder audioPlayerBuilder = new(_mockStringLocalizerFactory, _mockHttpContextAccessor); + ThemeAudioPlayerRenderer audioPlayerRenderer = new(themeService, new ThemeTemplateEngine(), audioPlayerBuilder); + _sut = new ThemeLayoutRenderer(themeService, new ThemeTemplateEngine(), viewRenderer, navBuilder, audioPlayerRenderer, _mockHttpContextAccessor); } [Fact]