From f6cebcbb7a9ab50402ba8c5647f4395d7dd2ea48 Mon Sep 17 00:00:00 2001 From: TheNEwmanator15 <3686761+Thenewmanator15@users.noreply.github.com> Date: Sat, 26 Sep 2026 12:50:28 +0100 Subject: [PATCH] Conflict window: legible dark-mode annotations, scalable headings - The annotation box had a hard-coded white background and grey borders while its text followed the theme, so in dark mode it was white text on white. Use theme tokens for background, text and borders. - Column headings were fixed at 14px by zotero.css's groupbox heading rule, so they stayed small with a larger font size setting while the rest of the window scaled. Size them relative to the page (still 14px at the default size), and do the same for the annotation box's fixed sizes. Co-Authored-By: Claude Opus 5.5 --- scss/components/_annotation.scss | 17 +++-- scss/merge.scss | 6 ++ test/tests/syncLocalTest.js | 121 +++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 7 deletions(-) diff --git a/scss/components/_annotation.scss b/scss/components/_annotation.scss index 5081b72005..718b7a70a4 100644 --- a/scss/components/_annotation.scss +++ b/scss/components/_annotation.scss @@ -1,23 +1,26 @@ .AnnotationBox { + // Sizes relative to the 13px base, so they follow Zotero's font size setting .title { font-weight: 600; - font-size: 12px; + font-size: calc(12em / 13); margin: 5px; } - + + // Theme colors rather than a fixed white box, which left dark-theme text unreadable .container { display: flex; flex-direction: column; margin: 5px; - border: 1px solid #d7dad7; + border: var(--material-border-quarternary); border-radius: 5px; - background: white; - + background: var(--material-background); + color: var(--fill-primary); + .header { font-weight: 600; - font-size: 11px; + font-size: calc(11em / 13); margin-top: 4px; - border-bottom: 1px solid #d7dad7; + border-bottom: var(--material-border-quarternary); padding: 0 8px 3px; } diff --git a/scss/merge.scss b/scss/merge.scss index 3dd6c1edf7..68841bdf00 100644 --- a/scss/merge.scss +++ b/scss/merge.scss @@ -85,3 +85,9 @@ merge-group { margin-right: 1em; font-weight: 600; } + +// zotero.css fixes groupbox headings at 14px; keep that size at the default 13px base +// but scale with the font size setting +merge-pane groupbox > label > h2 { + font-size: calc(14em / 13); +} diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js index cd7d94c893..b0d249a046 100644 --- a/test/tests/syncLocalTest.js +++ b/test/tests/syncLocalTest.js @@ -1515,6 +1515,127 @@ describe("Zotero.Sync.Data.Local", function () { describe("#showConflictResolutionWindow()", function () { + // WCAG contrast ratio between an element's text color and the first opaque + // background behind it + function getContrast(win, elem) { + var parse = s => s.match(/[\d.]+/g).map(Number); + var luminance = ([r, g, b]) => { + var [R, G, B] = [r, g, b].map((c) => { + c /= 255; + return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; + }); + return 0.2126 * R + 0.7152 * G + 0.0722 * B; + }; + var fg = parse(win.getComputedStyle(elem).color); + var bg = null; + for (let node = elem; node && node.nodeType == Node.ELEMENT_NODE; node = node.parentNode) { + let rgba = parse(win.getComputedStyle(node).backgroundColor); + if (rgba.length < 4 || rgba[3] == 1) { + bg = rgba; + break; + } + } + assert.ok(bg, "no opaque background found"); + var [l1, l2] = [luminance(fg), luminance(bg)].sort((a, b) => b - a); + return (l1 + 0.05) / (l2 + 0.05); + } + + function annotationConflict(annotation) { + var json = annotation.toJSON(); + return { + libraryID: annotation.libraryID, + key: annotation.key, + processed: false, + conflict: true, + left: json, + right: Object.assign({}, json, { annotationComment: "Changed" }), + changes: [], + conflicts: [] + }; + } + + it("should show annotation conflicts legibly in dark mode", async function () { + // The annotation box's page label needs the CSL locales + await Zotero.Styles.init(); + var attachment = await importPDFAttachment(); + var annotation = await createAnnotation('highlight', attachment); + Services.prefs.setIntPref('browser.theme.toolbar-theme', 0); + try { + var promise = waitForWindow('chrome://zotero/content/merge.xhtml', async function (dialog) { + var doc = dialog.document; + var wizard = doc.querySelector('wizard'); + try { + assert.isTrue(dialog.matchMedia('(prefers-color-scheme: dark)').matches); + + // The annotation box renders asynchronously + var container; + for (let i = 0; i < 100; i++) { + container = doc.querySelector('#left-pane .AnnotationBox .container'); + if (container) break; + await Zotero.Promise.delay(50); + } + assert.ok(container, "annotation box not rendered"); + for (let selector of ['.header', '.text', '.comment']) { + let elem = container.querySelector(selector); + assert.isAtLeast(getContrast(dialog, elem), 4.5, selector); + } + } + finally { + wizard.getButton('finish').click(); + } + }); + + Zotero.Sync.Data.Local.showConflictResolutionWindow([annotationConflict(annotation)]); + await promise; + } + finally { + Services.prefs.clearUserPref('browser.theme.toolbar-theme'); + } + }); + + it("should scale column headings with the font size", async function () { + var item = await createDataObject('item'); + var json = item.toJSON(); + var fontSize = Zotero.Prefs.get('fontSize'); + Zotero.Prefs.set('fontSize', '1.38'); + try { + var promise = waitForWindow('chrome://zotero/content/merge.xhtml', function (dialog) { + var doc = dialog.document; + var wizard = doc.querySelector('wizard'); + try { + var page = doc.querySelector('wizardpage'); + var pageSize = parseFloat(dialog.getComputedStyle(page).fontSize); + for (let h2 of doc.querySelectorAll('merge-pane h2')) { + let size = parseFloat(dialog.getComputedStyle(h2).fontSize); + // Name the rules that set the size, if it's too small + let rules = dialog.InspectorUtils.getMatchingCSSRules(h2) + .filter(r => r.style.fontSize || r.style.font) + .map(r => `${r.parentStyleSheet?.href} ${r.selectorText} ${r.style.fontSize || r.style.font}`); + assert.isAtLeast(size, pageSize, h2.textContent + " " + JSON.stringify(rules)); + } + } + finally { + wizard.getButton('finish').click(); + } + }); + + Zotero.Sync.Data.Local.showConflictResolutionWindow([{ + libraryID: item.libraryID, + key: item.key, + processed: false, + conflict: true, + left: json, + right: Object.assign({}, json, { title: "Changed" }), + changes: [], + conflicts: [] + }]); + await promise; + } + finally { + Zotero.Prefs.set('fontSize', fontSize); + } + }); + it("should show title of note parent", async function () { var parentItem = await createDataObject('item', { title: "Parent" }); var note = new Zotero.Item('note');