diff --git a/Docs/ApplicationTheme/PlotDirector.md b/Docs/ApplicationTheme/PlotDirector.md new file mode 100644 index 00000000..ad71b456 --- /dev/null +++ b/Docs/ApplicationTheme/PlotDirector.md @@ -0,0 +1,81 @@ +# PlotDirector house application theme + +Baseline: `ccdae5d`. Development only. + +Uses the existing `ApplicationAppearance` registry, `data-app-theme` semantic CSS tokens, normal authenticated appearance POST, Dapper repository and `UserAppearance_SaveTheme`. The selector now has seven themes; existing six keys/names/palettes remain intact. Forward-only migration 207 adds the new key to SQL validation and does not update user rows. + +## Palette + +| Token | Value | +| --- | --- | +| `--pd-workspace` | `#f8f1e6` | +| `--pd-surface` | `#fffaf2` | +| `--pd-surface-2` | `#f1e8da` | +| `--pd-elevated` | `#fffcf7` | +| `--pd-chrome` | `#eee3d3` | +| `--pd-chrome-secondary` | `#f8f1e6` | +| `--pd-border` | `#9a897a` | +| `--pd-border-subtle` | `#ddd0bf` | +| `--pd-text` | `#332b29` | +| `--pd-muted` | `#6c6059` | +| `--pd-heading` | `#48243c` | +| `--pd-accent` | `#59243f` | +| `--pd-accent-hover` | `#40192e` | +| `--pd-selected` | `#eadce5` | +| `--pd-hover` | `#f0e6e9` | +| `--pd-focus` | `#75445f` | +| `--pd-on-accent` | `#fffaf2` | +| `--pd-danger` | `#a33040` | +| `--pd-warning` | `#805d19` | +| `--pd-success` | `#4e6844` | +| `--pd-info` | `#326a87` | +| `--pd-icon-books` | `#356b9b` | +| `--pd-icon-planning` | `#386f6a` | +| `--pd-icon-calendar` | `#965537` | +| `--pd-icon-characters` | `#735594` | +| `--pd-icon-locations` | `#4e7046` | +| `--pd-icon-relationships` | `#99466d` | +| `--pd-icon-review` | `#805d19` | +| `--pd-data-1` | `#59243f` | +| `--pd-data-2` | `#356b9b` | +| `--pd-data-3` | `#4e7046` | +| `--pd-data-4` | `#966020` | +| `--pd-data-5` | `#735594` | +| `--pd-data-6` | `#287b7d` | +| `--pd-data-7` | `#a63d50` | +| `--pd-data-8` | `#596579` | +| `--pd-data-9` | `#955735` | +| `--pd-data-10` | `#876b25` | +| `--pd-data-11` | `#7c4279` | +| `--pd-shadow` | `0 3px 12px rgb(61 36 29 / 6%)` | + +The standard canvas/section/nested/card/control/chip/event and disabled-text aliases inherit the new palette through the existing bridge. Bootstrap primitives receive house-scoped tokens/styles for panels, modals/confirmation, menus, fields, tables, alerts/toasts, badges, tabs, buttons/groups, hover, focus and disabled states. Existing ribbon/navigation/context menu, resizable relationship panes, scene editor and plot map already use semantic tokens. No workspace layout was changed. + +## Typography and visualisation + +Existing application sans-serif typography remains structurally unchanged, including page titles; no serif overrides were introduced. UI fonts remain Segoe UI/system sans-serif. The 11 `pd-data-*` colours form the coordinated analytical palette. Story Health/Timeline metric charts consume those tokens, including on live theme changes; axis and chapter labels now use theme text/grid tokens rather than fixed low-contrast literals. Legends/toggles retain named metrics, point markers, and visibility controls. Existing author-chosen plot-line/entity colours are preserved so visual identity and meaning do not change on switching themes. The house theme does not recolour manuscript data. + +## Preference and public isolation + +New/no-preference accounts use `plotdirector`, persisted by the existing OnlyIfUnset workflow. Explicit stored choices always win. Legacy explicit light/dark device preferences still migrate to warm-light/warm-dark; no bulk user update, renamed theme, or forced switch occurs. Anonymous installed login recognises the new key, retaining the cached choice. Ordinary public pages and ordinary web login continue using `data-site-theme=public`, independent of application selection; only installed authentication may adopt application tokens. + +Select the theme: sign into Development, open the account/name menu at the top right, then under **Theme** choose **PlotDirector**. It saves automatically. The same preference applies in the installed PWA. + +## Verification + +- Build passed (two existing nullable warnings); full executable harness: 392 PASS. +- Existing toolbar persistence/keyboard/mobile tests passed. +- Focus/Weave narrative map tests passed with the house theme added. +- Relationship workspace test passed with the house theme added (75 characters/300 scenes, selection, drag/drop, search, responsive and PWA). +- Actual installed PWA suite passed: 20 Razor pages, all seven themes at 2560/1440/900, first-paint layout stability, one ribbon row, context menus and keyboard behaviour. +- PWA metadata/service-worker tests passed including the house chrome colour. +- Metric browser geometry/interaction suite passed after token-based series and label changes. +- House palette tests passed on dashboard, Timeline and Relationships at 390/768/1440. + +Contrast: primary text 10.45–13.51:1 and muted text 4.59–5.94:1 on six principal surfaces; primary button 11.55:1 (hover 14.47:1); control boundary 3.24:1; focus indicator 5.77–7.35:1; status badges >=5.69:1; all 11 chart series >=4.78:1 against the chart surface. Soft decorative separators are intentionally lighter; colour is not the only state cue. Disabled text is a darker mix of muted/body tokens and retained at full opacity in the house controls. + +## Bounded legacy audit + +Corrected the metric-chart hard-coded chapter/axis label styling and fixed per-series palette as part of this theme. Existing authored plot-line colours and relationship type/state colours remain intentional data encodings, not brand overrides. Older illustration/import/review surfaces retain some page-level decorative colours and gradients in plotline-theme.css/site.css; this task does not rewrite those large legacy stylesheets. Their shared controls now consume house primitives. A future audit may standardise those decorative treatments; do not blanket-recolour user-authored data or replace all historical literals. + +Deployment and real Development verification are recorded in Deployment.md. diff --git a/PlotLine.Tests/AppearanceTests.cs b/PlotLine.Tests/AppearanceTests.cs index f83d7e3e..927a4534 100644 --- a/PlotLine.Tests/AppearanceTests.cs +++ b/PlotLine.Tests/AppearanceTests.cs @@ -7,7 +7,7 @@ internal static class AppearanceTests { public static void RegistryAndPersistence() { - if (ApplicationAppearance.Themes.Count != 6 || ApplicationAppearance.IsValid("dark")) throw new Exception("All six explicit theme identifiers required."); + if (ApplicationAppearance.Themes.Count != 7 || !ApplicationAppearance.IsValid(ApplicationAppearance.DefaultTheme) || ApplicationAppearance.IsValid("dark")) throw new Exception("All seven explicit theme identifiers required."); var store = new AppearanceMemoryPreferences(); var controller = new AppearanceController(new ToolbarTestUser(4), store); controller.Theme("modern-dark").GetAwaiter().GetResult(); @@ -18,6 +18,8 @@ internal static class AppearanceTests if (!store.GetAsync(5).Result.ShowProjectContextMenu || !store.GetAsync(5).Result.ShowBookContextMenu) throw new Exception("Application bar menus default visible."); store.SaveApplicationBarAsync(5, false, true).GetAwaiter().GetResult(); if (store.GetAsync(5).Result.ShowProjectContextMenu || !store.GetAsync(5).Result.ShowBookContextMenu) throw new Exception("Application bar preferences are independent per user."); + controller.Theme("plotdirector").GetAwaiter().GetResult(); + if(store.GetAsync(4).Result.ThemeKey != "plotdirector") throw new Exception("House theme must persist through normal selection."); if (controller.Theme("invalid").Result is not BadRequestResult) throw new Exception("Invalid themes rejected."); if (ApplicationRibbon.ActiveCategory("StoryCalendar", "Calendar") != "story" || ApplicationRibbon.ActiveCategory("Books", "Overview") != "book") throw new Exception("Category maps feature routes."); foreach (var command in ApplicationRibbon.Categories.SelectMany(x => x.Groups).SelectMany(x => x.Commands)) diff --git a/PlotLine.Tests/Browser/application-pwa.cjs b/PlotLine.Tests/Browser/application-pwa.cjs index e736b442..3cea3b90 100644 --- a/PlotLine.Tests/Browser/application-pwa.cjs +++ b/PlotLine.Tests/Browser/application-pwa.cjs @@ -42,7 +42,7 @@ const server = http.createServer((req, res) => { const dimensions = await page.evaluate(async src => { const img = new Image(); img.src = src; await img.decode(); return `${img.naturalWidth}x${img.naturalHeight}`; }, icon.src); assert.equal(dimensions, icon.sizes); } - for (const [theme, color] of Object.entries({ 'modern-light': '#f0f1f3', 'modern-dark': '#24272c', 'warm-light': '#f2e9dc', 'warm-dark': '#251e18' })) { + for (const [theme, color] of Object.entries({ 'plotdirector': '#eee3d3', 'modern-light': '#f0f1f3', 'modern-dark': '#24272c', 'warm-light': '#f2e9dc', 'warm-dark': '#251e18' })) { await page.evaluate(theme => { document.documentElement.dataset.appTheme = theme; window.dispatchEvent(new Event('plotdirector:theme-changed')); }, theme); assert.equal(await page.locator('meta[name="theme-color"]').getAttribute('content'), color); } @@ -77,6 +77,6 @@ const server = http.createServer((req, res) => { assert.equal(await page.locator('[data-pwa-install]').textContent(), 'PlotDirector Desktop'); await page.evaluate(() => window.dispatchEvent(new Event('appinstalled'))); assert.equal(await page.locator('[data-pwa-install-item]').isVisible(), false); - console.log('PASS PWA: manifest/icons, four theme metadata values, real worker activation/update without lost edits, no Cache Storage, private data unavailable offline, install action.'); + console.log('PASS PWA: manifest/icons, five theme metadata values, real worker activation/update without lost edits, no Cache Storage, private data unavailable offline, install action.'); } finally { await browser.close(); await new Promise(resolve => server.close(resolve)); } })().catch(error => { console.error(error); process.exitCode = 1; }); diff --git a/PlotLine.Tests/Browser/house-theme-dev.cjs b/PlotLine.Tests/Browser/house-theme-dev.cjs new file mode 100644 index 00000000..96e0ae1d --- /dev/null +++ b/PlotLine.Tests/Browser/house-theme-dev.cjs @@ -0,0 +1,24 @@ +// Real Development account only. No login screenshots, traces, credentials or author data output. +const{chromium}=require('playwright'),fs=require('node:fs'),os=require('node:os'),path=require('node:path'),assert=require('node:assert/strict'); +const base='https://dev.plotdirector.com';let stage='setup'; +(async()=>{const file=process.argv[2];assert(file?.startsWith('/tmp/pd-dev-browser-'));const id=JSON.parse(fs.readFileSync(file));assert.equal(id.Database,'PlotDirector_Development');assert(id.Email.startsWith('pwa-browser-'));assert(id.SceneID&&id.LineAID); +const profile=fs.mkdtempSync(path.join(os.tmpdir(),'pd-house-theme-'));const ctx=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1440,height:1000}});const cdp=await ctx.browser().newBrowserCDPSession();let installed=false; +try{const page=ctx.pages()[0];stage='login';await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(id.Email);await page.locator('[name=Password]').fill(id.Password);await page.locator('form button[type=submit]').click();await page.waitForURL(base+'/Projects'); +assert.equal(await page.locator('html').getAttribute('data-app-theme'),'plotdirector','New account with no preference should use house theme');await page.waitForFunction(()=>!document.querySelector('[data-app-theme-choice]').disabled); +const q=`projectId=${id.ProjectID}&bookId=${id.BookID}`; +const routes=[['home','/Projects'],['dashboard','/Projects/Details/'+id.ProjectID],['chapters','/Books/Details/'+id.BookID],['scene','/Scenes/Edit/'+id.SceneID],['timeline','/Timeline?'+q],['plot-focus','/PlotLineWorkspace?'+q+'&plotLineId='+id.LineAID],['plot-weave','/PlotLineWorkspace?'+q+'&plotLineId='+id.LineAID+'&plotLineId='+id.LineBID],['relationships','/RelationshipMap?projectId='+id.ProjectID],['story-flow','/Analytics?'+q],['form','/Projects/Edit/'+id.ProjectID]]; +async function inspect(p,mode,width){await p.setViewportSize({width,height:1000});for(const[label,url]of routes){stage=mode+'/'+width+'/'+label;const response=await p.goto(base+url);assert.equal(response.status(),200,stage);assert.equal(await p.locator('html').getAttribute('data-app-theme'),'plotdirector');assert(!p.url().includes('/Account/')); + if(label==='scene')assert.equal(await p.locator('[data-scene-area-command]').count(),6); + if(label==='story-flow')assert.equal(await p.locator('canvas[data-metric-canvas], [data-metric-shape-chart] canvas').count(),1); + await p.screenshot({path:`/tmp/house-theme-live-${mode}-${label}-${width}.png`});} +} +await inspect(page,'web',1440);await inspect(page,'web',390); +stage='theme persistence';await page.goto(base+'/Projects');await page.locator('#accountMenuButton').click();assert.equal(await page.locator('[data-app-theme-choice]').count(),7);await page.locator('[data-app-theme-choice=modern-dark]').click();await page.waitForFunction(()=>!document.querySelector('[data-app-theme-choice]').disabled);await page.reload();assert.equal(await page.locator('html').getAttribute('data-app-theme'),'modern-dark');await page.locator('#accountMenuButton').click();await page.locator('[data-app-theme-choice=plotdirector]').click();await page.waitForFunction(()=>!document.querySelector('[data-app-theme-choice]').disabled); +stage='install';await page.goto(base+'/Projects');const manifestId=base+'/Projects';await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/Projects'});installed=true;await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=ctx.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url:base+'/Projects'});const app=await opened;await app.waitForLoadState();assert(await app.evaluate(()=>matchMedia('(display-mode: standalone)').matches));await inspect(app,'pwa',1440);await inspect(app,'pwa',390); +stage='scene areas';await app.setViewportSize({width:1440,height:1000});await app.goto(base+'/Scenes/Edit/'+id.SceneID);for(const area of ['overview','story','people','world','writer','continuity']){await app.locator(`[data-scene-area-command=${area}]`).click();assert.equal(await app.locator(`[data-scene-area-command=${area}]`).getAttribute('aria-pressed'),'true');} +stage='context menu';await app.goto(base+'/Books/Details/'+id.BookID);const target=app.locator('[data-pd-context]').first();assert(await target.count());await target.click({button:'right'});await app.screenshot({path:'/tmp/house-theme-live-context-menu.png'});await app.keyboard.press('Escape'); +stage='modal';await app.locator('#customiseToolbar').evaluate(e=>bootstrap.Modal.getOrCreateInstance(e).show());await app.locator('#customiseToolbar.show').waitFor();await app.screenshot({path:'/tmp/house-theme-live-modal.png'});await app.locator('#customiseToolbar').evaluate(e=>bootstrap.Modal.getInstance(e).hide()); +stage='public isolation';for(const theme of ['plotdirector','modern-dark','baby-blue']){await page.evaluate(t=>localStorage.setItem('plotdirector.applicationTheme',t),theme);for(const url of ['/','/features','/writing-problems','/writing-problems/comparing-different-story-versions','/Account/Login']){await page.goto(base+url);assert.equal(await page.locator('html').getAttribute('data-site-theme'),'public');assert.equal(await page.locator('html').getAttribute('data-app-theme'),null);}} +stage='PWA login';await app.evaluate(()=>localStorage.setItem('plotdirector.applicationTheme','plotdirector'));await app.goto(base+'/Account/Login');assert.equal(await app.locator('html').getAttribute('data-app-theme'),'plotdirector');await app.screenshot({path:'/tmp/house-theme-live-pwa-login.png'}); +console.log('PASS real Development: new-user default; explicit alternate persistence; 10 pages at 390/1440 in web and actual installed PWA; Focus/Weave; six Scene areas; modal/context menu; public and web-login isolation across three cached themes; PWA login.'); +}catch(e){console.error('FAILED',stage,e.message);process.exitCode=1;}finally{if(installed)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});await ctx.close();fs.rmSync(profile,{recursive:true,force:true});}})(); diff --git a/PlotLine.Tests/Browser/house-theme-seed.cjs b/PlotLine.Tests/Browser/house-theme-seed.cjs new file mode 100644 index 00000000..b78a6b3e --- /dev/null +++ b/PlotLine.Tests/Browser/house-theme-seed.cjs @@ -0,0 +1,9 @@ +// Dedicated Development verification account only; never prints credentials or manuscript content. +const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict'); +(async()=>{const file=process.argv[2];assert(file?.startsWith('/tmp/pd-dev-browser-'));const id=JSON.parse(fs.readFileSync(file));assert.equal(id.Database,'PlotDirector_Development');assert(id.Email.startsWith('pwa-browser-'));const b=await chromium.launch();let stage='login';try{const p=await b.newPage();await p.route('**/Appearance/Theme',r=>r.fulfill({json:{themeKey:'warm-light'}}));await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(id.Email);await p.locator('[name=Password]').fill(id.Password);await p.locator('form button[type=submit]').click();await p.waitForURL('**/Projects'); +async function save(){await Promise.all([p.waitForNavigation(),p.locator('main form button[type=submit]').first().click()]);assert(!await p.locator('.validation-summary-errors').count());} +if(!id.ProjectID){stage='project';await p.goto('https://dev.plotdirector.com/Projects/Create');await p.locator('[name=ProjectName]').fill('House Theme Verification');await save();id.ProjectID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.ProjectID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});} +if(!id.BookID){stage='book';await p.goto('https://dev.plotdirector.com/Books/Create?projectId='+id.ProjectID);await p.locator('[name=BookTitle]').fill('The Glass Harbour');await save();id.BookID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.BookID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});} +if(!id.ChapterID){stage='chapter';await p.goto('https://dev.plotdirector.com/Chapters/Create?bookId='+id.BookID);await p.locator('[name=ChapterTitle]').fill('The Unopened Letter');await save();id.ChapterID=Number(new URL(p.url()).pathname.split('/').at(-1));assert(id.ChapterID>0);fs.writeFileSync(file,JSON.stringify(id),{mode:0o600});} +await p.goto('https://dev.plotdirector.com/Scenes/Create?chapterId='+id.ChapterID);console.log('Fixture project/book/chapter created through Development UI. Scene create controls:',await p.locator('form').evaluateAll(fs=>fs.map(f=>({action:f.getAttribute('action'),fields:[...f.querySelectorAll('input,select,textarea')].map(i=>i.name).filter(n=>!n.includes('Token'))})).filter(f=>f.fields.some(n=>n.includes('Scene'))))); +}catch(e){console.error('Failed stage',stage,e.message);process.exitCode=1;}finally{await b.close();}})(); diff --git a/PlotLine.Tests/Browser/house-theme.cjs b/PlotLine.Tests/Browser/house-theme.cjs new file mode 100644 index 00000000..b78a2821 --- /dev/null +++ b/PlotLine.Tests/Browser/house-theme.cjs @@ -0,0 +1,16 @@ +const {chromium}=require('playwright');const assert=require('node:assert/strict'); +(async()=>{const b=await chromium.launch();try{const page=await b.newPage({viewport:{width:1440,height:1000}});await page.goto('http://127.0.0.1:5238/fixture?page=dashboard'); +await page.locator('#accountMenuButton').click();assert.equal(await page.locator('[data-app-theme-choice]').count(),7);await page.locator('[data-app-theme-choice=plotdirector]').click();await page.waitForFunction(()=>!document.querySelector('[data-app-theme-choice]').disabled);await page.keyboard.press('Escape');assert.equal(await page.locator('html').getAttribute('data-app-theme'),'plotdirector'); +const pairs=await page.evaluate(()=>{ + const style=getComputedStyle(document.documentElement),ctx=document.createElement('canvas').getContext('2d'); + const lum=color=>{ctx.fillStyle=color;ctx.fillRect(0,0,1,1);return [...ctx.getImageData(0,0,1,1).data].slice(0,3).map(n=>n/255).map(n=>n<=.04045?n/12.92:((n+.055)/1.055)**2.4).reduce((a,n,i)=>a+n*[.2126,.7152,.0722][i],0)}; + const token=n=>style.getPropertyValue('--pd-'+n).trim();const ratio=(a,c)=>(Math.max(lum(a),lum(c))+.05)/(Math.min(lum(a),lum(c))+.05); + const checks=[];for(const bg of ['workspace','surface','surface-2','selected','hover','elevated'])for(const fg of ['text','muted','heading'])checks.push([fg+'/'+bg,ratio(token(fg),token(bg)),4.5]); + checks.push(['button',ratio(token('on-accent'),token('accent')),4.5],['button hover',ratio(token('on-accent'),token('accent-hover')),4.5],['control boundary',ratio(token('border'),token('surface')),3]); + for(const bg of ['workspace','surface','selected'])checks.push(['focus/'+bg,ratio(token('focus'),token(bg)),3]); + for(const fg of ['success','danger','warning','info'])checks.push([fg+' badge',ratio(token('on-accent'),token(fg)),4.5]); + for(let i=1;i<=11;i++)checks.push(['data '+i,ratio(token('data-'+i),token('surface')),3]);return checks; +});for(const[name,value,minimum]of pairs)assert(value>=minimum,`${name}: ${value}`);console.log('CONTRAST',JSON.stringify(pairs)); +for(const size of [390,768,1440]){await page.setViewportSize({width:size,height:1000});for(const view of ['dashboard','timeline','relationships']){await page.goto('http://127.0.0.1:5238/fixture?page='+view);assert.equal(await page.locator('html').getAttribute('data-app-theme'),'plotdirector');await page.screenshot({path:`/tmp/house-theme-${view}-${size}.png`});}} +console.log('PASS house theme: seven choices, selection persists, all surface text/button/status/focus/data contrasts; dashboard, Timeline, relationships at 390/768/1440'); +}finally{await b.close();}})().catch(e=>{console.error(e);process.exit(1)}); diff --git a/PlotLine.Tests/Browser/plot-line-map.cjs b/PlotLine.Tests/Browser/plot-line-map.cjs index 10bd8c46..7813267e 100644 --- a/PlotLine.Tests/Browser/plot-line-map.cjs +++ b/PlotLine.Tests/Browser/plot-line-map.cjs @@ -48,7 +48,7 @@ const assert = require('node:assert/strict'); await page.locator('#plot-inspector-content h2').waitFor(); assert.equal(await page.locator('#plot-inspector').getAttribute('aria-hidden'), 'false'); await page.keyboard.press('Escape'); - for (const theme of ['modern-dark', 'warm-dark', 'modern-light']) { + for (const theme of ['modern-dark', 'warm-dark', 'modern-light', 'plotdirector']) { await page.evaluate(theme => { document.documentElement.dataset.appTheme = theme; document.documentElement.dataset.theme = theme.endsWith('dark') ? 'dark' : 'light'; }, theme); const colors = await page.locator('.plot-map-callout button').first().evaluate(el => ({ bg: getComputedStyle(el).backgroundColor, fg: getComputedStyle(el).color })); assert.notEqual(colors.bg, colors.fg); diff --git a/PlotLine.Tests/Browser/pwa-desktop.cjs b/PlotLine.Tests/Browser/pwa-desktop.cjs index 0362b9db..5a583add 100644 --- a/PlotLine.Tests/Browser/pwa-desktop.cjs +++ b/PlotLine.Tests/Browser/pwa-desktop.cjs @@ -41,7 +41,7 @@ async function ready(page) { const app = await opened; await app.waitForLoadState(); assert(await app.evaluate(() => matchMedia('(display-mode: standalone)').matches)); const themes = await app.locator('[data-app-theme-choice]').evaluateAll(nodes => nodes.map(node => node.dataset.appThemeChoice)); - assert.equal(themes.length, 6); + assert.equal(themes.length, 7); await require('./pwa-first-paint.cjs')(app, tab); for (const url of urls) { await app.goto(base + url); @@ -219,7 +219,7 @@ async function ready(page) { await ready(app); assert.equal(await app.locator('.pd-context-group[aria-label="Manage"] > details').getAttribute('data-always-compact'), 'true'); assert.deepEqual(failures, []); - console.log('PASS PWA desktop: real installed/browser separation; 20 real Razor pages; semantic composed-command uniqueness and single Enter/integrated-button search; all six themes at 2560/1440/900; one active ribbon row without title strip; direct wide commands and measured responsive overflow; compact menus, keyboard Escape/focus, collapsed ribbon, route/scope deduplication, search form behavior, section jump focus, page help, fragment lifecycle.'); + console.log('PASS PWA desktop: real installed/browser separation; 20 real Razor pages; semantic composed-command uniqueness and single Enter/integrated-button search; all seven themes at 2560/1440/900; one active ribbon row without title strip; direct wide commands and measured responsive overflow; compact menus, keyboard Escape/focus, collapsed ribbon, route/scope deduplication, search form behavior, section jump focus, page help, fragment lifecycle.'); } finally { await cdp.send('PWA.uninstall', { manifestId }).catch(() => {}); await context.close(); fs.rmSync(profile, { recursive: true, force: true }); diff --git a/PlotLine.Tests/Browser/relationship-workspace.cjs b/PlotLine.Tests/Browser/relationship-workspace.cjs index 80735a2d..ca2d8846 100644 --- a/PlotLine.Tests/Browser/relationship-workspace.cjs +++ b/PlotLine.Tests/Browser/relationship-workspace.cjs @@ -130,7 +130,7 @@ const base = 'http://127.0.0.1:5238'; } } await page.setViewportSize({width:1600,height:1000}); - for (const theme of ['modern-light','modern-dark','warm-light','warm-dark']) { + for (const theme of ['modern-light','modern-dark','warm-light','warm-dark','plotdirector']) { await page.evaluate(theme => { document.documentElement.dataset.appTheme = theme; document.documentElement.dataset.theme = theme.endsWith('dark') ? 'dark':'light'; }, theme); await page.waitForTimeout(100); const themeState = await page.evaluate(() => { diff --git a/PlotLine/Services/ApplicationAppearance.cs b/PlotLine/Services/ApplicationAppearance.cs index 49c62232..7d6add4d 100644 --- a/PlotLine/Services/ApplicationAppearance.cs +++ b/PlotLine/Services/ApplicationAppearance.cs @@ -2,12 +2,14 @@ namespace PlotLine.Services; public sealed class ApplicationAppearance { + public const string DefaultTheme = "plotdirector"; public string? ThemeKey { get; set; } public bool RibbonCollapsed { get; set; } public bool ShowProjectContextMenu { get; set; } = true; public bool ShowBookContextMenu { get; set; } = true; public static IReadOnlyDictionary Themes { get; } = new Dictionary { + ["plotdirector"] = "PlotDirector", ["modern-light"] = "Modern Light", ["modern-dark"] = "Modern Dark", ["warm-light"] = "Warm Light", ["warm-dark"] = "Warm Dark", ["rose-pink"] = "Rose Pink", ["baby-blue"] = "Baby Blue" diff --git a/PlotLine/Sql/207_PlotDirectorApplicationTheme.sql b/PlotLine/Sql/207_PlotDirectorApplicationTheme.sql new file mode 100644 index 00000000..5a7b38c9 --- /dev/null +++ b/PlotLine/Sql/207_PlotDirectorApplicationTheme.sql @@ -0,0 +1,22 @@ +-- Additive registry change only: existing explicit preferences remain untouched. +SET ANSI_NULLS ON; +GO +SET QUOTED_IDENTIFIER ON; +GO +CREATE OR ALTER PROCEDURE dbo.UserAppearance_SaveTheme + @UserID int, + @ThemeKey nvarchar(32), + @OnlyIfUnset bit = 0 +AS +BEGIN + SET NOCOUNT ON; + + IF @ThemeKey NOT IN ('plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue') OR @ThemeKey IS NULL + THROW 50001, 'Unknown application theme', 1; + + UPDATE dbo.AppUser + SET ApplicationThemeKey = @ThemeKey + WHERE UserID = @UserID + AND (@OnlyIfUnset = 0 OR ApplicationThemeKey IS NULL); +END; +GO diff --git a/PlotLine/Views/Shared/_Layout.cshtml b/PlotLine/Views/Shared/_Layout.cshtml index f0db68d0..8ff36346 100644 --- a/PlotLine/Views/Shared/_Layout.cshtml +++ b/PlotLine/Views/Shared/_Layout.cshtml @@ -99,7 +99,7 @@ const saved = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(appearance.ThemeKey)); let legacy = null; try { legacy = localStorage.getItem('plotline.theme'); } catch { } - const theme = saved || (legacy === 'dark' ? 'warm-dark' : 'warm-light'); + const theme = saved || (legacy === 'dark' ? 'warm-dark' : legacy === 'light' ? 'warm-light' : '@ApplicationAppearance.DefaultTheme'); document.documentElement.dataset.appTheme = theme; document.documentElement.dataset.theme = theme.endsWith('-dark') ? 'dark' : 'light'; document.documentElement.dataset.bsTheme = document.documentElement.dataset.theme; diff --git a/PlotLine/wwwroot/css/application-shell.css b/PlotLine/wwwroot/css/application-shell.css index 63714a64..43123d9b 100644 --- a/PlotLine/wwwroot/css/application-shell.css +++ b/PlotLine/wwwroot/css/application-shell.css @@ -14,6 +14,20 @@ html[data-app-theme] { --pd-event-surface: var(--pd-elevated); --pd-event-text: var(--pd-text); --pd-event-muted: var(--pd-muted); --pd-event-border: var(--pd-border); --pd-disabled-text: color-mix(in srgb, var(--pd-muted) 82%, var(--pd-text)); } +/* House theme: UI typography stays sans-serif; chart/entity colours remain distinct. */ +html[data-app-theme="plotdirector"] { + --pd-workspace: #f8f1e6; --pd-surface: #fffaf2; --pd-surface-2: #f1e8da; --pd-elevated: #fffcf7; + --pd-chrome: #eee3d3; --pd-chrome-secondary: #f8f1e6; --pd-border: #9a897a; --pd-border-subtle: #ddd0bf; + --pd-text: #332b29; --pd-muted: #6c6059; --pd-heading: #48243c; --pd-accent: #59243f; --pd-accent-hover: #40192e; + --pd-selected: #eadce5; --pd-hover: #f0e6e9; --pd-focus: #75445f; --pd-on-accent: #fffaf2; + --pd-danger: #a33040; --pd-warning: #805d19; --pd-success: #4e6844; --pd-info: #326a87; + --pd-icon-books: #356b9b; --pd-icon-planning: #386f6a; --pd-icon-calendar: #965537; --pd-icon-characters: #735594; + --pd-icon-locations: #4e7046; --pd-icon-relationships: #99466d; --pd-icon-review: #805d19; + --pd-data-1: #59243f; --pd-data-2: #356b9b; --pd-data-3: #4e7046; --pd-data-4: #966020; + --pd-data-5: #735594; --pd-data-6: #287b7d; --pd-data-7: #a63d50; --pd-data-8: #596579; + --pd-data-9: #955735; --pd-data-10: #876b25; --pd-data-11: #7c4279; + --pd-shadow: 0 3px 12px rgb(61 36 29 / 6%); +} html[data-app-theme="modern-light"] { --pd-workspace: #f4f5f7; --pd-surface: #fff; --pd-surface-2: #f0f2f5; --pd-elevated: #fff; --pd-chrome: #f0f1f3; --pd-chrome-secondary: #fafbfc; --pd-border: #d4d8df; --pd-border-subtle: #e7e9ed; @@ -132,6 +146,7 @@ html[data-app-theme] .app-layout { .pd-theme-picker button { display: flex; align-items: center; gap: 6px; font-size: 11px; padding: 8px 6px; border: 1px solid var(--pd-border); border-radius: 4px; background: var(--pd-surface); color: var(--pd-text); white-space: nowrap; } .pd-theme-picker [aria-pressed="true"] { border-color: var(--pd-accent); background: var(--pd-selected); } .pd-theme-swatch { width: 13px; height: 13px; border-radius: 50%; border: 1px solid #8a8a8a; flex-shrink: 0; } +[data-swatch="plotdirector"] { background: #59243f; } [data-swatch="modern-light"] { background: #f4f5f7; } [data-swatch="modern-dark"] { background: #25282d; } [data-swatch="warm-light"] { background: #f4ebdd; } [data-swatch="warm-dark"] { background: #30271f; } [data-swatch="rose-pink"] { background: #efd5de; } [data-swatch="baby-blue"] { background: #cfe4f1; } @@ -558,3 +573,95 @@ html[data-standalone="true"] .app-layout > .pd-application-header > .pd-shell { .pd-context-search-submit:hover { background: var(--pd-hover); } .pd-context-search-field:focus-within { outline: 2px solid var(--pd-focus); outline-offset: 2px; } @media (max-width:1199px) { .pd-context-search-field { width: 150px; } } + +/* House-theme primitives. Scope excludes public pages, including ordinary web login. */ +html[data-app-theme="plotdirector"] .app-layout { + --bs-primary: #59243f; --bs-primary-rgb: 89,36,63; + --bs-success-rgb: 78,104,68; --bs-danger-rgb: 163,48,64; + --bs-warning-rgb: 128,93,25; --bs-info-rgb: 50,106,135; + --bs-secondary-rgb: 108,96,89; --bs-light-rgb: 241,232,218; + --bs-emphasis-color: var(--pd-text); --bs-secondary-bg: var(--pd-surface-2); + font-family: var(--pd-font-ui); +} +html[data-app-theme="plotdirector"] .app-layout :is(.card,.panel,.modal-content,.dropdown-menu,.offcanvas,.list-group-item) { + background-color: var(--pd-surface); color: var(--pd-text); border-color: var(--pd-border-subtle); +} +html[data-app-theme="plotdirector"] .app-layout :is(.modal-header,.modal-footer,.card-header,.card-footer) { + background: var(--pd-chrome-secondary); border-color: var(--pd-border-subtle); color: var(--pd-text); +} +html[data-app-theme="plotdirector"] .app-layout :is(.form-control,.form-select,.input-group-text) { + background-color: var(--pd-control); color: var(--pd-text); border-color: var(--pd-border); +} +html[data-app-theme="plotdirector"] .app-layout :is(input,textarea)::placeholder { color: var(--pd-muted); opacity: 1; } +html[data-app-theme="plotdirector"] .app-layout :is(.form-control,.form-select):disabled { + background-color: var(--pd-surface-2); color: var(--pd-disabled-text); opacity: 1; +} +html[data-app-theme="plotdirector"] .app-layout :is(a,button,input,textarea,select,summary,[tabindex]):focus-visible { + outline: 2px solid var(--pd-focus); outline-offset: 2px; +} +html[data-app-theme="plotdirector"] .app-layout :is(.form-control,.form-select):focus { box-shadow: 0 0 0 3px #75445f26; border-color: var(--pd-focus); } +html[data-app-theme="plotdirector"] .app-layout :is(.form-check-input:checked,.progress-bar) { background-color: var(--pd-accent); border-color: var(--pd-accent); } +html[data-app-theme="plotdirector"] .app-layout .btn-primary { + --bs-btn-bg: var(--pd-accent); --bs-btn-border-color: var(--pd-accent); --bs-btn-color: var(--pd-on-accent); + --bs-btn-hover-bg: var(--pd-accent-hover); --bs-btn-hover-border-color: var(--pd-accent-hover); --bs-btn-hover-color: var(--pd-on-accent); + --bs-btn-active-bg: var(--pd-accent-hover); --bs-btn-active-border-color: var(--pd-accent-hover); --bs-btn-active-color: var(--pd-on-accent); + background: var(--pd-accent); color: var(--pd-on-accent); border-color: var(--pd-accent); +} +html[data-app-theme="plotdirector"] .app-layout .btn-primary:is(:hover,:active,.active) { background: var(--pd-accent-hover); border-color: var(--pd-accent-hover); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-secondary,.btn-outline-secondary) { + --bs-btn-color: var(--pd-text); --bs-btn-border-color: var(--pd-border); + --bs-btn-hover-color: var(--pd-text); --bs-btn-hover-bg: var(--pd-hover); --bs-btn-hover-border-color: var(--pd-border); + --bs-btn-active-color: var(--pd-text); --bs-btn-active-bg: var(--pd-selected); --bs-btn-active-border-color: var(--pd-accent); + background-color: var(--pd-surface-2); color: var(--pd-text); border-color: var(--pd-border); +} +html[data-app-theme="plotdirector"] .app-layout :is(.btn-secondary,.btn-outline-secondary):hover { background-color: var(--pd-hover); } +html[data-app-theme="plotdirector"] .app-layout .btn:disabled { opacity: 1; color: var(--pd-disabled-text) !important; background: var(--pd-surface-2) !important; border-color: var(--pd-border-subtle) !important; } +html[data-app-theme="plotdirector"] .app-layout :is(.text-muted,.muted,.form-text) { color: var(--pd-muted) !important; } +html[data-app-theme="plotdirector"] .app-layout :is(.nav-tabs,.nav-pills) .nav-link { color: var(--pd-accent); } +html[data-app-theme="plotdirector"] .app-layout :is(.nav-tabs,.nav-pills) .nav-link.active, +html[data-app-theme="plotdirector"] .app-layout .dropdown-item:is(:active,.active) { background: var(--pd-selected); color: var(--pd-heading); border-color: var(--pd-border); } +html[data-app-theme="plotdirector"] .app-layout .dropdown-item { color: var(--pd-text); } +html[data-app-theme="plotdirector"] .app-layout .dropdown-item:is(:hover,:focus) { background: var(--pd-hover); } +html[data-app-theme="plotdirector"] .app-layout .table { + --bs-table-bg: var(--pd-surface); --bs-table-color: var(--pd-text); --bs-table-border-color: var(--pd-border-subtle); + --bs-table-striped-bg: var(--pd-chrome-secondary); --bs-table-striped-color: var(--pd-text); + --bs-table-hover-bg: var(--pd-hover); --bs-table-hover-color: var(--pd-text); --bs-table-active-bg: var(--pd-selected); --bs-table-active-color: var(--pd-text); +} +html[data-app-theme="plotdirector"] .app-layout .table thead { --bs-table-bg: var(--pd-surface-2); --bs-table-color: var(--pd-text); } +html[data-app-theme="plotdirector"] .app-layout :is(.alert,.toast) { color: var(--pd-text); background: var(--pd-surface); border-color: var(--pd-border); } +html[data-app-theme="plotdirector"] .app-layout .alert-success { background: #e8edde; border-color: var(--pd-success); } +html[data-app-theme="plotdirector"] .app-layout .alert-danger { background: #f5e4e4; border-color: var(--pd-danger); } +html[data-app-theme="plotdirector"] .app-layout .alert-warning { background: #f2e9d5; border-color: var(--pd-warning); } +html[data-app-theme="plotdirector"] .app-layout .alert-info { background: #e4edf1; border-color: var(--pd-info); } +html[data-app-theme="plotdirector"] .app-layout .tooltip { --bs-tooltip-bg: var(--pd-text); --bs-tooltip-color: var(--pd-on-accent); } +html[data-app-theme="plotdirector"] .app-layout :is(.badge.bg-warning,.badge.bg-info,.badge.bg-light) { color: var(--pd-on-accent) !important; } +html[data-app-theme="plotdirector"] .app-layout .badge.bg-light { background: var(--pd-surface-2) !important; color: var(--pd-text) !important; } +html[data-app-theme="plotdirector"] .app-layout { scrollbar-color: var(--pd-border) var(--pd-workspace); } +/* Installed reauthentication has no .app-layout, but shares the same palette. */ +html[data-app-theme="plotdirector"] .public-auth { + --plotline-bg: var(--pd-workspace); --plotline-bg-warm: var(--pd-workspace); + --plotline-text: var(--pd-text); --plotline-text-muted: var(--pd-muted); + --plotline-accent: var(--pd-accent); --plotline-accent-dark: var(--pd-accent-hover); + --plotline-accent-soft: var(--pd-selected); --plotline-surface: var(--pd-surface); + --app-input-bg: var(--pd-surface); --app-input-text: var(--pd-text); +} +html[data-app-theme="plotdirector"] .public-auth .btn-primary { background: var(--pd-accent); border-color: var(--pd-accent); color: var(--pd-on-accent); } +html[data-app-theme="plotdirector"] .public-auth :is(.form-control,.form-select) { color: var(--pd-text); background: var(--pd-control); border-color: var(--pd-border); } +html[data-app-theme="plotdirector"] .public-auth :is(a,button,input):focus-visible { outline: 2px solid var(--pd-focus); outline-offset: 2px; } +html[data-app-theme="plotdirector"] .app-layout .btn-outline-primary { color: var(--pd-accent); border-color: var(--pd-accent); background: transparent; } +html[data-app-theme="plotdirector"] .app-layout .btn-outline-primary:is(:hover,:active,.active) { color: var(--pd-on-accent); background: var(--pd-accent); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-success,.btn-outline-success) { --pd-button-tone: var(--pd-success); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-danger,.btn-outline-danger) { --pd-button-tone: var(--pd-danger); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-warning,.btn-outline-warning) { --pd-button-tone: var(--pd-warning); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-info,.btn-outline-info) { --pd-button-tone: var(--pd-info); } +html[data-app-theme="plotdirector"] .app-layout :is(.btn-success,.btn-danger,.btn-warning,.btn-info) { + background: var(--pd-button-tone); border-color: var(--pd-button-tone); color: var(--pd-on-accent); +} +html[data-app-theme="plotdirector"] .app-layout :is(.btn-outline-success,.btn-outline-danger,.btn-outline-warning,.btn-outline-info) { + background: transparent; border-color: var(--pd-button-tone); color: var(--pd-button-tone); +} +html[data-app-theme="plotdirector"] .app-layout :is(.btn-outline-success,.btn-outline-danger,.btn-outline-warning,.btn-outline-info):is(:hover,:active,.active) { + background: var(--pd-button-tone); color: var(--pd-on-accent); +} +html[data-app-theme="plotdirector"] .app-layout :is(.text-bg-warning,.text-bg-info) { color: var(--pd-on-accent) !important; } +html[data-app-theme="plotdirector"] .pd-shell [aria-disabled="true"] { opacity: 1; color: var(--pd-disabled-text) !important; } diff --git a/PlotLine/wwwroot/js/application-shell.js b/PlotLine/wwwroot/js/application-shell.js index caaeeaf6..44868530 100644 --- a/PlotLine/wwwroot/js/application-shell.js +++ b/PlotLine/wwwroot/js/application-shell.js @@ -1,7 +1,7 @@ (() => { const shell = document.querySelector('[data-ribbon-shell]'); if (!shell) return; - const appearance = window.plotdirectorAppearance || { theme: 'warm-light', migrate: false }; + const appearance = window.plotdirectorAppearance || { theme: 'plotdirector', migrate: false }; const form = shell.querySelector('[data-appearance-form]'); const status = shell.querySelector('[data-appearance-status]'); const tabs = [...shell.querySelectorAll('[data-ribbon-tab]')]; diff --git a/PlotLine/wwwroot/js/public-auth-theme.js b/PlotLine/wwwroot/js/public-auth-theme.js index d63377ee..7fbe11d5 100644 --- a/PlotLine/wwwroot/js/public-auth-theme.js +++ b/PlotLine/wwwroot/js/public-auth-theme.js @@ -1,7 +1,7 @@ // Only authentication may adopt the application palette, and only in an installed window. (() => { const root = document.documentElement; - const themes = ['warm-light', 'warm-dark', 'modern-light', 'modern-dark', 'rose-pink', 'baby-blue']; + const themes = ['plotdirector', 'warm-light', 'warm-dark', 'modern-light', 'modern-dark', 'rose-pink', 'baby-blue']; const apply = () => { const legacyStyles = document.getElementById("public-auth-base"); if (legacyStyles) legacyStyles.media = window.PlotDirectorPwa?.standalone ? "all" : "not all"; @@ -16,7 +16,7 @@ legacy = localStorage.getItem('plotline.theme'); } catch { } const preferred = window.plotdirectorAuthTheme || cached; - const theme = themes.includes(preferred) ? preferred : legacy === 'dark' ? 'warm-dark' : 'warm-light'; + const theme = themes.includes(preferred) ? preferred : legacy === 'dark' ? 'warm-dark' : legacy === 'light' ? 'warm-light' : 'plotdirector'; delete root.dataset.siteTheme; root.dataset.appTheme = theme; root.dataset.theme = root.dataset.bsTheme = theme.endsWith('-dark') ? 'dark' : 'light'; diff --git a/PlotLine/wwwroot/js/site.js b/PlotLine/wwwroot/js/site.js index b4cc4734..043f5f95 100644 --- a/PlotLine/wwwroot/js/site.js +++ b/PlotLine/wwwroot/js/site.js @@ -560,7 +560,7 @@ return; } - const colours = [ + const legacyColours = [ "#2f6f63", "#b35f3b", "#6750a4", @@ -640,8 +640,9 @@ } ctx.save(); - ctx.strokeStyle = "rgba(47, 111, 99, 0.16)"; - ctx.fillStyle = "rgba(82, 75, 65, 0.58)"; + const palette = getComputedStyle(chart.canvas); + ctx.strokeStyle = palette.getPropertyValue('--pd-border-subtle').trim() || "rgba(47, 111, 99, 0.16)"; + ctx.fillStyle = palette.getPropertyValue('--pd-muted').trim() || "rgba(82, 75, 65, 0.58)"; ctx.lineWidth = 1; ctx.font = "700 10px system-ui, -apple-system, Segoe UI, sans-serif"; @@ -732,12 +733,14 @@ viewport.append(canvas); } const defaultMetrics = new Set(payload.defaultMetrics?.length ? payload.defaultMetrics : globalDefaultMetrics); + const chartTokens = () => getComputedStyle(root); + const seriesColour = index => chartTokens().getPropertyValue(`--pd-data-${index % legacyColours.length + 1}`).trim() || legacyColours[index % legacyColours.length]; const columnCount = payload.scenes.length; root.dataset.sceneCount = String(columnCount); const tickLabelInterval = columnCount > 80 ? 10 : columnCount > 40 ? 5 : columnCount > 24 ? 4 : columnCount > 14 ? 2 : 1; const datasets = payload.metrics.map((metric, metricIndex) => { const pointMap = new Map(metric.points.map((point) => [point.sceneId, point.value])); - const colour = colours[metricIndex % colours.length]; + const colour = seriesColour(metricIndex); return { label: metric.metricName, metricTypeId: metric.metricTypeId, @@ -905,6 +908,23 @@ } }); + const applyChartTheme = () => { + const tokens = chartTokens(); + const text = tokens.getPropertyValue('--pd-muted').trim(); + const grid = tokens.getPropertyValue('--pd-border-subtle').trim(); + datasets.forEach((dataset, index) => { + dataset.borderColor = dataset.backgroundColor = dataset.pointBackgroundColor = seriesColour(index); + dataset.pointBorderColor = tokens.getPropertyValue('--pd-surface').trim() || '#fff'; + toggleHost.querySelectorAll('.metric-toggle-pill')[index]?.style.setProperty('--metric-colour', dataset.borderColor); + }); + for (const scale of Object.values(chart.options.scales)) { + if (text) scale.ticks.color = text; + if (grid) scale.grid = { ...scale.grid, color: grid }; + } + chart.update('none'); + }; + applyChartTheme(); + window.addEventListener('plotdirector:theme-changed', applyChartTheme); const zoom = root.querySelector("[data-metric-zoom]"); if (zoom) { const zoomLabel = root.querySelector("[data-metric-zoom-label]");