Initial commit: NexusArchitect Professional Workstation Overhaul

This commit is contained in:
Debian
2026-04-24 20:27:22 +02:00
commit f3e94c4f42
193 changed files with 5809 additions and 0 deletions
@@ -0,0 +1,11 @@
<button class="nexus-btn @Class" @onclick="OnClick" disabled="@Disabled" @attributes="AdditionalAttributes">
@ChildContent
</button>
@code {
[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
[Parameter] public EventCallback<Microsoft.AspNetCore.Components.Web.MouseEventArgs> OnClick { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
}
@@ -0,0 +1,35 @@
.nexus-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 44px;
min-height: 44px;
padding: 0.5rem 1rem;
background-color: var(--nexus-card);
color: var(--nexus-neon);
border: 1px solid var(--nexus-neon);
font-family: var(--nexus-font-sans);
font-weight: 500;
font-size: 1rem;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 0 5px rgba(0, 255, 153, 0.1);
}
.nexus-btn:hover:not(:disabled) {
background-color: rgba(0, 255, 153, 0.1);
box-shadow: 0 0 15px rgba(0, 255, 153, 0.3);
}
.nexus-btn:active:not(:disabled) {
transform: scale(0.98);
}
.nexus-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
border-color: #555;
color: #555;
box-shadow: none;
}
@@ -0,0 +1,25 @@
<svg class="nexus-icon @Class" viewBox="0 0 24 24" fill="currentColor" width="@Size" height="@Size" @attributes="AdditionalAttributes">
@switch (Name.ToLowerInvariant())
{
case "robot":
<path d="M12 2a2 2 0 0 1 2 2c0 .74-.4 1.39-1 1.73V7h5a2 2 0 0 1 2 2v2a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-2a2 2 0 0 1-2-2v-2a2 2 0 0 1 2-2V9c0-1.1.9-2 2-2h5V5.73c-.6-.34-1-.99-1-1.73a2 2 0 0 1 2-2zM8 11v4h8v-4H8zm-2 0H4v4h2v-4zm14 0h-2v4h2v-4z" />
break;
case "play":
<path d="M8 5v14l11-7z" />
break;
case "check":
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
break;
default:
<!-- Fallback circle -->
<circle cx="12" cy="12" r="10" />
break;
}
</svg>
@code {
[Parameter] public string Name { get; set; } = string.Empty;
[Parameter] public string Size { get; set; } = "24";
[Parameter] public string Class { get; set; } = string.Empty;
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
}

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -0,0 +1,10 @@
.nexus-icon {
display: inline-block;
vertical-align: middle;
transition: fill 0.2s ease, filter 0.2s ease;
}
.neon-glow {
fill: var(--nexus-neon);
filter: drop-shadow(0 0 4px var(--nexus-neon));
}
@@ -0,0 +1,25 @@
<div class="nexus-typography @VariantCssClass @Class" @attributes="AdditionalAttributes">
@ChildContent
</div>
@code {
[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
[Parameter] public TypographyVariant Variant { get; set; } = TypographyVariant.UI;
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
private string VariantCssClass => Variant switch
{
TypographyVariant.Heading => "nexus-heading",
TypographyVariant.Ebook => "nexus-ebook",
TypographyVariant.UI => "nexus-ui",
_ => "nexus-ui"
};
public enum TypographyVariant
{
Heading,
Ebook,
UI
}
}
@@ -0,0 +1,25 @@
.nexus-typography {
margin: 0;
}
.nexus-heading {
font-family: var(--nexus-font-sans);
font-size: 2rem;
font-weight: 600;
color: var(--nexus-text);
margin-bottom: 1rem;
}
.nexus-ebook {
font-family: var(--nexus-font-serif);
font-size: 1.125rem;
line-height: 1.8;
color: var(--nexus-text);
margin-bottom: 1.2rem;
}
.nexus-ui {
font-family: var(--nexus-font-sans);
font-size: 1rem;
color: var(--nexus-text);
}
@@ -0,0 +1,44 @@
@using NexusReader.Web.Client.Services
@inject IQuizStateService QuizState
<div class="ai-bubble">
<div class="ai-avatar">
<NexusIcon Name="robot" Size="32" Class="neon-glow" />
</div>
<div class="ai-content">
<NexusTypography Variant="NexusTypography.TypographyVariant.UI">@Dialogue</NexusTypography>
@if (Actions != null && Actions.Any())
{
<div class="ai-actions">
@foreach (var action in Actions)
{
<NexusButton OnClick="() => HandleActionClick(action)" Disabled="@_isQuizMode">@action</NexusButton>
}
</div>
}
</div>
</div>
@code {
[Parameter] public string ContextBlockId { get; set; } = string.Empty;
[Parameter] public string Dialogue { get; set; } = string.Empty;
[Parameter] public List<string> Actions { get; set; } = new();
[Parameter] public EventCallback<string> OnActionTriggered { get; set; }
private bool _isQuizMode = false;
private async Task HandleActionClick(string action)
{
if (action.Contains("quiz", StringComparison.OrdinalIgnoreCase))
{
_isQuizMode = true;
QuizState.RequestQuiz(ContextBlockId);
}
if (OnActionTriggered.HasDelegate)
{
await OnActionTriggered.InvokeAsync(action);
}
}
}
@@ -0,0 +1,33 @@
.ai-bubble {
display: flex;
flex-direction: row;
gap: 1rem;
padding: 1.5rem;
background: rgba(30, 30, 30, 0.6);
backdrop-filter: blur(10px);
border: 1px solid rgba(0, 255, 153, 0.2);
border-left: 3px solid var(--nexus-neon);
border-radius: 8px;
box-shadow: -2px 0 10px rgba(0, 255, 153, 0.4);
}
.ai-avatar {
flex-shrink: 0;
display: flex;
align-items: flex-start;
padding-top: 0.2rem;
}
.ai-content {
display: flex;
flex-direction: column;
gap: 1rem;
flex-grow: 1;
}
.ai-actions {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 0.8rem;
}
@@ -0,0 +1,84 @@
@using MediatR
@using NexusReader.Application.Queries.Quiz
@using NexusReader.Application.Commands.Quiz
@inject IMediator Mediator
<div class="knowledge-check-container">
@if (_isLoading)
{
<div class="skeleton-loader">
<div class="shimmer"></div>
</div>
}
else if (_quiz != null)
{
@foreach (var question in _quiz.Questions)
{
<div class="quiz-block @GetBlockClass(question)">
<NexusTypography Variant="NexusTypography.TypographyVariant.UI">@question.Question</NexusTypography>
<div class="options-container">
@for (int i = 0; i < question.Options.Count; i++)
{
var index = i;
<button class="quiz-option @GetOptionClass(question, index)"
@onclick="() => SelectOptionAsync(question, index)"
disabled="@_states.ContainsKey(question)">
@question.Options[index]
</button>
}
</div>
</div>
}
}
</div>
@code {
[Parameter] public string ContextBlockId { get; set; } = string.Empty;
private bool _isLoading = true;
private QuizDto? _quiz;
private Dictionary<QuizQuestionDto, (int SelectedIndex, bool IsCorrect)> _states = new();
protected override async Task OnInitializedAsync()
{
_isLoading = true;
var query = new GetQuizQuestionsQuery(ContextBlockId);
var result = await Mediator.Send(query);
if (result.IsSuccess)
_quiz = result.Value;
_isLoading = false;
}
private async Task SelectOptionAsync(QuizQuestionDto question, int index)
{
if (_states.ContainsKey(question)) return;
var cmd = new SubmitAnswerCommand(index, question.CorrectIndex);
var res = await Mediator.Send(cmd);
_states[question] = (index, res.IsSuccess);
}
private string GetBlockClass(QuizQuestionDto question)
{
if (!_states.TryGetValue(question, out var state)) return "";
return state.IsCorrect ? "state-correct" : "state-incorrect";
}
private string GetOptionClass(QuizQuestionDto question, int index)
{
if (!_states.TryGetValue(question, out var state)) return "";
if (state.SelectedIndex == index)
return state.IsCorrect ? "option-correct" : "option-incorrect";
if (state.IsCorrect == false && question.CorrectIndex == index)
return "option-revealed-correct";
return "option-faded";
}
}
@@ -0,0 +1,107 @@
.knowledge-check-container {
width: 100%;
margin-top: 1rem;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.skeleton-loader {
width: 100%;
height: 120px;
background-color: var(--nexus-card);
border-radius: 8px;
position: relative;
overflow: hidden;
border: 1px solid rgba(255,255,255,0.05);
}
.skeleton-loader .shimmer {
position: absolute;
top: 0;
left: -100%;
width: 50%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
animation: loadingShimmer 1.5s infinite ease-in-out;
}
@keyframes loadingShimmer {
100% { left: 200%; }
}
.quiz-block {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
background-color: var(--nexus-card);
border-radius: 8px;
border: 1px solid rgba(255,255,255,0.1);
transition: all 0.3s ease;
}
.quiz-block.state-correct {
border-color: var(--nexus-neon);
box-shadow: 0 0 10px rgba(0, 255, 153, 0.1);
}
.quiz-block.state-incorrect {
border-color: rgba(255, 60, 60, 0.6);
animation: shakePulse 0.4s ease-in-out;
}
@keyframes shakePulse {
0% { transform: translateX(0); }
25% { transform: translateX(-4px); box-shadow: -4px 0 10px rgba(255,60,60,0.3); }
50% { transform: translateX(4px); box-shadow: 4px 0 10px rgba(255,60,60,0.3); }
75% { transform: translateX(-4px); box-shadow: -4px 0 10px rgba(255,60,60,0.3); }
100% { transform: translateX(0); }
}
.options-container {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.quiz-option {
padding: 0.8rem;
background-color: var(--nexus-card);
border: 1px solid rgba(255,255,255,0.1);
color: var(--nexus-text);
border-radius: 6px;
cursor: pointer;
text-align: left;
transition: all 0.2s;
font-family: var(--nexus-font-sans);
}
.quiz-option:hover:not(:disabled) {
background-color: rgba(255,255,255,0.05);
}
.quiz-option:disabled {
cursor: default;
}
.option-correct {
background-color: rgba(0, 255, 153, 0.15) !important;
border-color: var(--nexus-neon) !important;
color: white;
}
.option-incorrect {
background-color: rgba(255, 60, 60, 0.15) !important;
border-color: #ff3c3c !important;
color: white;
}
.option-revealed-correct {
border-color: var(--nexus-neon) !important;
border-style: dashed;
}
.option-faded {
opacity: 0.5;
}
@@ -0,0 +1,98 @@
@using MediatR
@using NexusReader.Application.Queries.Graph
@using Microsoft.JSInterop
@using NexusReader.Web.Client.Services
@implements IAsyncDisposable
@inject IMediator Mediator
@inject IJSRuntime JS
@inject IFocusModeService FocusMode
<div class="knowledge-graph-container" id="@ContainerId">
@if (GraphData == null)
{
<div class="loading-state">
<NexusIcon Name="robot" Size="48" Class="neon-glow" />
<NexusTypography>Analyzing Chapter Nodes...</NexusTypography>
</div>
}
</div>
@code {
[Parameter] public EventCallback<string> OnNodeSelected { get; set; }
private string ContainerId = "d3-graph-container";
private GraphDataDto? GraphData;
private IJSObjectReference? _module;
private DotNetObjectReference<KnowledgeGraph>? _dotNetHelper;
protected override void OnInitialized()
{
FocusMode.OnFocusModeChanged += HandleFocusSimulation;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var result = await Mediator.Send(new GetKnowledgeGraphQuery());
if (result.IsSuccess)
{
GraphData = result.Value;
StateHasChanged();
await InitializeGraphAsync();
}
}
}
private async Task InitializeGraphAsync()
{
_module = await JS.InvokeAsync<IJSObjectReference>("import", "./js/knowledgeGraph.js");
_dotNetHelper = DotNetObjectReference.Create(this);
await _module.InvokeVoidAsync("mount", ContainerId, GraphData, _dotNetHelper);
}
[JSInvokable]
public async Task OnNodeClicked(string nodeId)
{
if (OnNodeSelected.HasDelegate)
{
await OnNodeSelected.InvokeAsync(nodeId);
}
}
private async void HandleFocusSimulation()
{
if (_module == null) return;
try
{
if (FocusMode.IsFocusModeActive)
await _module.InvokeVoidAsync("pause");
else
await _module.InvokeVoidAsync("resume");
}
catch { }
}
public async ValueTask DisposeAsync()
{
FocusMode.OnFocusModeChanged -= HandleFocusSimulation;
try
{
if (_module is not null)
{
await _module.InvokeVoidAsync("unmount", ContainerId);
await _module.DisposeAsync();
}
}
catch (JSDisconnectedException)
{
// Ignored, the circuit is already closed
}
catch (TaskCanceledException)
{
// Ignored, the circuit is already closed
}
_dotNetHelper?.Dispose();
}
}
@@ -0,0 +1,30 @@
.knowledge-graph-container {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
overflow: hidden;
}
.loading-state {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse {
0% { opacity: 0.6; }
50% { opacity: 1; }
100% { opacity: 0.6; }
}
::deep .nexus-node-active {
stroke: var(--nexus-neon) !important;
stroke-width: 4px !important;
filter: drop-shadow(0 0 8px var(--nexus-neon));
transition: all 0.3s ease;
}
@@ -0,0 +1,86 @@
@using MediatR
@using NexusReader.Application.Queries.Reader
@using Microsoft.JSInterop
@using NexusReader.Web.Client.Services
@implements IDisposable
@inject IMediator Mediator
@inject IJSRuntime JS
@inject IThemeService ThemeService
@inject IFocusModeService FocusMode
<div class="reader-canvas @(ThemeService.IsLightMode ? "theme-light" : "")" style="padding: 2rem 0;">
<div style="display: flex; justify-content: flex-end; align-items: center; margin-bottom: 2rem; gap: 1rem; padding: 0 2rem;">
<NexusButton OnClick="@(_ => ThemeService.ToggleTheme())">
@(ThemeService.IsLightMode ? "Turn Off Lights" : "Turn On Lights")
</NexusButton>
<button @onclick="FocusMode.ToggleAsync" title="Focus Mode (F)" style="background:none; border:none; cursor:pointer; padding: 0;">
<NexusIcon Name="target" Size="28" Class="@(FocusMode.IsFocusModeActive ? "neon-glow" : "")" />
</button>
</div>
@if (ViewModel == null)
{
<NexusTypography Variant="NexusTypography.TypographyVariant.UI">@StatusMessage</NexusTypography>
}
else
{
<div class="reader-flow-container">
@foreach (var block in ViewModel.Blocks)
{
<div id="@block.Id" class="block-wrapper">
@if (block is TextSegmentBlock textSegment)
{
<NexusTypography Variant="NexusTypography.TypographyVariant.Ebook">@textSegment.Content</NexusTypography>
}
else if (block is AiActionTriggerBlock aiTrigger)
{
<AiAssistantBubble
ContextBlockId="@block.Id"
Dialogue="@aiTrigger.Dialogue"
Actions="@aiTrigger.ActionOptions"
OnActionTriggered="HandleAiAction" />
}
</div>
}
</div>
}
</div>
@code {
private ReaderPageViewModel? ViewModel;
private string StatusMessage = "Loading chapter...";
protected override async Task OnInitializedAsync()
{
ThemeService.OnThemeChanged += StateHasChanged;
var result = await Mediator.Send(new GetReaderPageQuery());
if (result.IsSuccess)
{
ViewModel = result.Value;
}
else
{
StatusMessage = "Failed to load chapter content.";
}
}
private void HandleAiAction(string action)
{
Console.WriteLine($"Action Triggered from Bubble: {action}");
}
public async Task ScrollToNodeAsync(string id)
{
try
{
await JS.InvokeVoidAsync("eval", $"document.getElementById('{id}')?.scrollIntoView({{ behavior: 'smooth', block: 'center' }});");
}
catch { }
}
public void Dispose()
{
ThemeService.OnThemeChanged -= StateHasChanged;
}
}
@@ -0,0 +1,12 @@
.reader-canvas {
max-width: 800px;
margin: 0 auto;
padding: 2rem 1rem;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.reader-flow-container {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
@@ -0,0 +1,10 @@
@inherits LayoutComponentBase
@Body
<div id="blazor-error-ui" data-nosnippet>
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
@@ -0,0 +1,20 @@
#blazor-error-ui {
color-scheme: light only;
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
box-sizing: border-box;
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
@@ -0,0 +1,31 @@
<script type="module" src="@Assets["Layout/ReconnectModal.razor.js"]"></script>
<dialog id="components-reconnect-modal" data-nosnippet>
<div class="components-reconnect-container">
<div class="components-rejoining-animation" aria-hidden="true">
<div></div>
<div></div>
</div>
<p class="components-reconnect-first-attempt-visible">
Rejoining the server...
</p>
<p class="components-reconnect-repeated-attempt-visible">
Rejoin failed... trying again in <span id="components-seconds-to-next-attempt"></span> seconds.
</p>
<p class="components-reconnect-failed-visible">
Failed to rejoin.<br />Please retry or reload the page.
</p>
<button id="components-reconnect-button" class="components-reconnect-failed-visible">
Retry
</button>
<p class="components-pause-visible">
The session has been paused by the server.
</p>
<p class="components-resume-failed-visible">
Failed to resume the session.<br />Please retry or reload the page.
</p>
<button id="components-resume-button" class="components-pause-visible components-resume-failed-visible">
Resume
</button>
</div>
</dialog>
@@ -0,0 +1,157 @@
.components-reconnect-first-attempt-visible,
.components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible,
.components-pause-visible,
.components-resume-failed-visible,
.components-rejoining-animation {
display: none;
}
#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible {
display: block;
}
#components-reconnect-modal {
background-color: white;
width: 20rem;
margin: 20vh auto;
padding: 2rem;
border: 0;
border-radius: 0.5rem;
box-shadow: 0 3px 6px 2px rgba(0, 0, 0, 0.3);
opacity: 0;
transition: display 0.5s allow-discrete, overlay 0.5s allow-discrete;
animation: components-reconnect-modal-fadeOutOpacity 0.5s both;
&[open]
{
animation: components-reconnect-modal-slideUp 1.5s cubic-bezier(.05, .89, .25, 1.02) 0.3s, components-reconnect-modal-fadeInOpacity 0.5s ease-in-out 0.3s;
animation-fill-mode: both;
}
}
#components-reconnect-modal::backdrop {
background-color: rgba(0, 0, 0, 0.4);
animation: components-reconnect-modal-fadeInOpacity 0.5s ease-in-out;
opacity: 1;
}
@keyframes components-reconnect-modal-slideUp {
0% {
transform: translateY(30px) scale(0.95);
}
100% {
transform: translateY(0);
}
}
@keyframes components-reconnect-modal-fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes components-reconnect-modal-fadeOutOpacity {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.components-reconnect-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
}
#components-reconnect-modal p {
margin: 0;
text-align: center;
}
#components-reconnect-modal button {
border: 0;
background-color: #6b9ed2;
color: white;
padding: 4px 24px;
border-radius: 4px;
}
#components-reconnect-modal button:hover {
background-color: #3b6ea2;
}
#components-reconnect-modal button:active {
background-color: #6b9ed2;
}
.components-rejoining-animation {
position: relative;
width: 80px;
height: 80px;
}
.components-rejoining-animation div {
position: absolute;
border: 3px solid #0087ff;
opacity: 1;
border-radius: 50%;
animation: components-rejoining-animation 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.components-rejoining-animation div:nth-child(2) {
animation-delay: -0.5s;
}
@keyframes components-rejoining-animation {
0% {
top: 40px;
left: 40px;
width: 0;
height: 0;
opacity: 0;
}
4.9% {
top: 40px;
left: 40px;
width: 0;
height: 0;
opacity: 0;
}
5% {
top: 40px;
left: 40px;
width: 0;
height: 0;
opacity: 1;
}
100% {
top: 0px;
left: 0px;
width: 80px;
height: 80px;
opacity: 0;
}
}
@@ -0,0 +1,63 @@
// Set up event handlers
const reconnectModal = document.getElementById("components-reconnect-modal");
reconnectModal.addEventListener("components-reconnect-state-changed", handleReconnectStateChanged);
const retryButton = document.getElementById("components-reconnect-button");
retryButton.addEventListener("click", retry);
const resumeButton = document.getElementById("components-resume-button");
resumeButton.addEventListener("click", resume);
function handleReconnectStateChanged(event) {
if (event.detail.state === "show") {
reconnectModal.showModal();
} else if (event.detail.state === "hide") {
reconnectModal.close();
} else if (event.detail.state === "failed") {
document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
} else if (event.detail.state === "rejected") {
location.reload();
}
}
async function retry() {
document.removeEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
try {
// Reconnect will asynchronously return:
// - true to mean success
// - false to mean we reached the server, but it rejected the connection (e.g., unknown circuit ID)
// - exception to mean we didn't reach the server (this can be sync or async)
const successful = await Blazor.reconnect();
if (!successful) {
// We have been able to reach the server, but the circuit is no longer available.
// We'll reload the page so the user can continue using the app as quickly as possible.
const resumeSuccessful = await Blazor.resumeCircuit();
if (!resumeSuccessful) {
location.reload();
} else {
reconnectModal.close();
}
}
} catch (err) {
// We got an exception, server is currently unavailable
document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
}
}
async function resume() {
try {
const successful = await Blazor.resumeCircuit();
if (!successful) {
location.reload();
}
} catch {
reconnectModal.classList.replace("components-reconnect-paused", "components-reconnect-resume-failed");
}
}
async function retryWhenDocumentBecomesVisible() {
if (document.visibilityState === "visible") {
await retry();
}
}
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NexusReader.Application\NexusReader.Application.csproj" />
<ProjectReference Include="..\NexusReader.Infrastructure\NexusReader.Infrastructure.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,91 @@
@page "/"
@using NexusReader.Web.Client.Services
@implements IAsyncDisposable
@inject IQuizStateService QuizState
@inject IFocusModeService FocusMode
@inject IJSRuntime JS
<PageTitle>Nexus E-Reader</PageTitle>
<div class="split-layout @(FocusMode.IsFocusModeActive ? "focus-mode-active" : "")">
<div class="reader-pane">
<ReaderCanvas @ref="readerCanvas" />
</div>
<div class="graph-pane">
<div class="graph-section">
<KnowledgeGraph OnNodeSelected="HandleNodeSelected" />
</div>
@if (!string.IsNullOrEmpty(_activeQuizBlockId))
{
<div class="quiz-section">
<KnowledgeCheck ContextBlockId="@_activeQuizBlockId" />
</div>
}
</div>
</div>
@code {
private ReaderCanvas? readerCanvas;
private string? _activeQuizBlockId;
private IJSObjectReference? _interopModule;
private IJSObjectReference? _keydownHandler;
private DotNetObjectReference<Home>? _dotNetRef;
protected override async Task OnInitializedAsync()
{
QuizState.OnQuizRequested += HandleQuizRequested;
FocusMode.OnFocusModeChanged += StateHasChanged;
await FocusMode.InitializeAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
try {
_interopModule = await JS.InvokeAsync<IJSObjectReference>("import", "./js/focusInterop.js");
_dotNetRef = DotNetObjectReference.Create(this);
_keydownHandler = await _interopModule.InvokeAsync<IJSObjectReference>("attachKeyboardListener", _dotNetRef);
} catch { } /* ignored dynamically */
}
}
[JSInvokable]
public async Task OnFocusKeypressed()
{
await FocusMode.ToggleAsync();
StateHasChanged();
}
private async Task HandleNodeSelected(string nodeId)
{
if (readerCanvas != null)
{
await readerCanvas.ScrollToNodeAsync(nodeId);
}
}
private void HandleQuizRequested(string blockId)
{
_activeQuizBlockId = blockId;
StateHasChanged();
}
public async ValueTask DisposeAsync()
{
QuizState.OnQuizRequested -= HandleQuizRequested;
FocusMode.OnFocusModeChanged -= StateHasChanged;
if (_interopModule != null && _keydownHandler != null)
{
try {
await _interopModule.InvokeVoidAsync("detachKeyboardListener", _keydownHandler);
await _interopModule.DisposeAsync();
await _keydownHandler.DisposeAsync();
} catch { } // Circuit disconnected catch explicitly
}
_dotNetRef?.Dispose();
}
}
@@ -0,0 +1,55 @@
.split-layout {
display: flex;
flex-direction: row;
width: 100%;
height: 100vh;
}
.reader-pane {
flex: 1;
overflow-y: auto;
padding: 0 2rem;
transition: all 0.3s ease;
}
.graph-pane {
flex: 1;
background: linear-gradient(135deg, #121212 0%, #1a1a1a 100%);
border-left: 1px solid rgba(255, 255, 255, 0.1);
color: #ffffff;
height: 100vh;
display: flex;
flex-direction: column;
overflow-y: auto;
max-width: 50%;
opacity: 1;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.split-layout.focus-mode-active .graph-pane {
flex: 0;
max-width: 0;
opacity: 0;
border-color: transparent;
padding: 0;
}
.graph-section {
width: 100%;
min-height: 50vh;
flex-shrink: 0;
}
.quiz-section {
padding: 0 2rem 2rem 2rem;
display: flex;
flex-direction: column;
}
.reader-pane::-webkit-scrollbar {
width: 6px;
}
.reader-pane::-webkit-scrollbar-thumb {
background-color: var(--nexus-card);
border-radius: 4px;
}
@@ -0,0 +1,5 @@
@page "/not-found"
@layout MainLayout
<h3>Not Found</h3>
<p>Sorry, the content you are looking for does not exist.</p>
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using NexusReader.Application.Abstractions.Services;
using NexusReader.Web.Client.Services;
using NexusReader.Application.Queries.Quiz;
using NexusReader.Application;
using NexusReader.Infrastructure;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddScoped<IPlatformService, WebPlatformService>();
builder.Services.AddScoped<IThemeService, ThemeService>();
builder.Services.AddScoped<IQuizStateService, QuizStateService>();
builder.Services.AddScoped<IFocusModeService, FocusModeService>();
builder.Services.AddApplication();
builder.Services.AddInfrastructure();
await builder.Build().RunAsync();
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
@@ -0,0 +1,44 @@
using Microsoft.JSInterop;
namespace NexusReader.Web.Client.Services;
public sealed class FocusModeService : IFocusModeService
{
private readonly IJSRuntime _jsRuntime;
public bool IsFocusModeActive { get; private set; }
public event Action? OnFocusModeChanged;
public FocusModeService(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}
public async Task InitializeAsync()
{
try
{
var value = await _jsRuntime.InvokeAsync<string>("localStorage.getItem", "nexus_focus_mode");
if (value == "true" && !IsFocusModeActive)
{
IsFocusModeActive = true;
OnFocusModeChanged?.Invoke();
}
}
catch
{
// Ignored during pre-rendering or unsupported environments
}
}
public async Task ToggleAsync()
{
IsFocusModeActive = !IsFocusModeActive;
OnFocusModeChanged?.Invoke();
try
{
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "nexus_focus_mode", IsFocusModeActive ? "true" : "false");
}
catch { }
}
}
@@ -0,0 +1,9 @@
namespace NexusReader.Web.Client.Services;
public interface IFocusModeService
{
bool IsFocusModeActive { get; }
event Action? OnFocusModeChanged;
Task InitializeAsync();
Task ToggleAsync();
}
@@ -0,0 +1,8 @@
namespace NexusReader.Web.Client.Services;
public interface IQuizStateService
{
string? CurrentQuizBlockId { get; }
event Action<string>? OnQuizRequested;
void RequestQuiz(string blockId);
}
@@ -0,0 +1,8 @@
namespace NexusReader.Web.Client.Services;
public interface IThemeService
{
bool IsLightMode { get; }
event Action? OnThemeChanged;
void ToggleTheme();
}
@@ -0,0 +1,13 @@
namespace NexusReader.Web.Client.Services;
public sealed class QuizStateService : IQuizStateService
{
public string? CurrentQuizBlockId { get; private set; }
public event Action<string>? OnQuizRequested;
public void RequestQuiz(string blockId)
{
CurrentQuizBlockId = blockId;
OnQuizRequested?.Invoke(blockId);
}
}
@@ -0,0 +1,13 @@
namespace NexusReader.Web.Client.Services;
public sealed class ThemeService : IThemeService
{
public bool IsLightMode { get; private set; } = false;
public event Action? OnThemeChanged;
public void ToggleTheme()
{
IsLightMode = !IsLightMode;
OnThemeChanged?.Invoke();
}
}
@@ -0,0 +1,26 @@
using Microsoft.JSInterop;
using NexusReader.Application.Abstractions.Services;
namespace NexusReader.Web.Client.Services;
public sealed class WebPlatformService : IPlatformService
{
private readonly IJSRuntime _jsRuntime;
public WebPlatformService(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}
public async Task VibrateAsync(int milliseconds)
{
try
{
await _jsRuntime.InvokeVoidAsync("navigator.vibrate", milliseconds);
}
catch
{
// Ignore on platforms without vibration
}
}
}
@@ -0,0 +1,13 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using NexusReader.Web.Client
@using NexusReader.Web.Client.Layout
@using NexusReader.Web.Client.Components.Atoms
@using NexusReader.Web.Client.Components.Molecules
@using NexusReader.Web.Client.Components.Organisms
@@ -0,0 +1,20 @@
export function attachKeyboardListener(dotNetHelper) {
const handler = (e) => {
// Exclude inputs, textareas, etc.
const activeNode = document.activeElement ? document.activeElement.nodeName.toLowerCase() : '';
if (activeNode === 'input' || activeNode === 'textarea') return;
if (e.key === 'f' || e.key === 'F') {
dotNetHelper.invokeMethodAsync('OnFocusKeypressed');
}
};
window.addEventListener('keydown', handler);
return handler;
}
export function detachKeyboardListener(handler) {
if (handler) {
window.removeEventListener('keydown', handler);
}
}
@@ -0,0 +1,150 @@
import * as d3 from 'https://esm.sh/d3@7';
let simulation;
export function mount(containerId, data, dotNetHelper) {
const container = document.getElementById(containerId);
if (!container) return;
const width = container.clientWidth || 400;
const height = container.clientHeight || 400;
// Create SVG
const svg = d3.select(container).append("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", "100%")
.attr("height", "100%");
// Radial gradient for Nebula effect
const defs = svg.append("defs");
const radialGradient = defs.append("radialGradient")
.attr("id", "nebulaGlow")
.attr("cx", "50%")
.attr("cy", "50%")
.attr("r", "50%");
radialGradient.append("stop").attr("offset", "0%").attr("stop-color", "var(--nexus-neon)").attr("stop-opacity", 1);
radialGradient.append("stop").attr("offset", "100%").attr("stop-color", "var(--nexus-neon)").attr("stop-opacity", 0);
// Root Group for Zoom
const rootGroup = svg.append("g").attr("class", "zoom-containment");
// Attach Zoom Behavior
const zoom = d3.zoom()
.scaleExtent([0.5, 4])
.on("zoom", (e) => rootGroup.attr("transform", e.transform));
svg.call(zoom);
// Subtle Link Distance & Charge
simulation = d3.forceSimulation(data.nodes)
.force("link", d3.forceLink(data.links).id(d => d.id).distance(60))
.force("charge", d3.forceManyBody().strength(-150))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("collide", d3.forceCollide().radius(25));
// Links
const link = rootGroup.append("g")
.selectAll("line")
.data(data.links)
.join("line")
.attr("stroke", "#444")
.attr("stroke-opacity", 0.6)
.attr("stroke-width", 1.5);
// Nodes
const node = rootGroup.append("g")
.selectAll("g")
.data(data.nodes)
.join("g")
.style("cursor", "pointer")
.on("click", (e, d) => {
// Remove active state from all, add to clicked
node.select("circle.node-core").classed("nexus-node-active", false);
d3.select(e.currentTarget).select("circle.node-core").classed("nexus-node-active", true);
dotNetHelper.invokeMethodAsync('OnNodeClicked', d.id);
})
.call(drag(simulation));
// Outer glow for nodes
node.append("circle")
.attr("r", 14)
.attr("fill", "url(#nebulaGlow)")
.attr("opacity", 0.4);
// Core circle
node.append("circle")
.attr("class", "node-core")
.attr("r", 6)
.attr("fill", "#888")
.attr("stroke", "#222")
.attr("stroke-width", 2);
// Labels
node.append("text")
.text(d => d.label)
.attr("x", 12)
.attr("y", 4)
.attr("fill", "#ccc")
.attr("font-family", "var(--nexus-font-sans)")
.attr("font-size", "0.75rem");
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node.attr("transform", d => `translate(${d.x},${d.y})`);
});
}
function drag(simulation) {
function dragstarted(event) {
if (!event.active) simulation.alphaTarget(0.3).restart();
event.subject.fx = event.subject.x;
event.subject.fy = event.subject.y;
}
function dragged(event) {
event.subject.fx = event.x;
event.subject.fy = event.y;
}
function dragended(event) {
if (!event.active) simulation.alphaTarget(0);
event.subject.fx = null;
event.subject.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
export function unmount(containerId) {
if (simulation) {
simulation.stop();
}
const container = document.getElementById(containerId);
if (container) {
container.innerHTML = ''; // clear svg
}
}
export function scrollToNode(id) {
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
export function pause() {
if (simulation) {
simulation.stop();
}
}
export function resume() {
if (simulation) {
// give it a gentle kick to settle if moved
simulation.alphaTarget(0.1).restart();
}
}