This commit is contained in:
Mathew Newman 2026-10-29 19:38:30 +00:00 • committed by GitHub
commit a3962e6752
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 220 additions and 44 deletions

View file

@ -34,19 +34,19 @@ import cx from 'classnames';
// We'll want to replace this with a single component shared between the PDF reader and the rest
// of the codebase.
function AnnotationBox({ data }) {
var textStyle = {
borderLeft: "2px solid " + data.color
};
// Same icons as the item pane's annotation rows
var iconType = data.type == 'image' ? 'area' : data.type;
return (
<div className="AnnotationBox">
<div className="title">{Zotero.getString('itemTypes.annotation')}</div>
<div className="container">
<div className="container" style={{ '--annotation-color': data.color }}>
<div className="header">
<img className="icon" src={`chrome://zotero/skin/16/universal/annotate-${iconType}.svg`} alt=""/>
<div>{Zotero.Cite.getLocatorString('page')} {data.pageLabel}</div>
</div>
{data.text !== undefined
? <div className="text" style={textStyle}>{data.text}</div>
? <div className="text">{data.text}</div>
: ''}
{data.type == 'image'
// TODO: Localize

View file

@ -1,42 +1,57 @@
// Styled after the item pane's annotation rows (elements/_annotationRow.scss)
.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: 1px solid var(--fill-quinary);
border-radius: 5px;
background: white;
background: var(--material-background);
color: var(--fill-primary);
.header {
display: flex;
align-items: center;
gap: 4px;
font-weight: 600;
font-size: 11px;
margin-top: 4px;
border-bottom: 1px solid #d7dad7;
padding: 0 8px 3px;
border-bottom: 1px solid var(--fill-quinary);
padding: 4px 8px;
.icon {
width: 16px;
height: 16px;
-moz-context-properties: fill;
fill: var(--annotation-color, var(--fill-secondary));
}
}
.text, .image-placeholder, .comment {
margin-left: 8px;
margin-right: 8px;
margin-bottom: 4px;
overflow-wrap: anywhere;
}
.text, .image-placeholder {
margin-top: 8px;
}
// Unlike the item pane's rows, the quote keeps the primary text color: it's what the
// user has to read to choose a version
.text {
padding-left: 7px;
margin: 5px 8px;
padding-inline-start: 6px;
border-inline-start: 2px solid var(--annotation-color, var(--fill-secondary));
}
.image-placeholder {
margin: 5px 8px;
color: var(--fill-secondary);
}
.comment {
margin-top: 4px;
padding: 3px 8px 5px;
}
}
}
}

View file

@ -1,3 +1,7 @@
@import "abstracts/variables";
@import "abstracts/functions";
@import "abstracts/mixins";
wizardpage {
overflow: hidden;
min-width: 780px;
@ -8,6 +12,8 @@ merge-group {
display: flex;
overflow: hidden auto;
gap: 8px;
// Room for the focus ring and the selected ring, which the scrollport would clip
padding: 4px;
merge-pane {
flex: 1;
@ -16,15 +22,44 @@ merge-group {
max-height: 0;
min-width: 250px;
// Each version is a card; the chosen one gets an accent ring and heading
& groupbox {
flex: 1;
margin: 0;
padding: 6px 8px;
background: var(--material-background);
border: var(--material-border-quinary);
border-radius: 5px;
@include focus-ring;
}
&[selected] h2,
&[selected] attachment-box #title {
color: red;
h2 {
font-weight: 600;
text-decoration: underline;
}
&[selected] groupbox {
border-color: var(--color-accent);
box-shadow: 0 0 0 1px var(--color-accent);
}
// Only the heading: an accent-colored attachment title would read as a link
&[selected] h2 {
color: var(--color-accent);
}
// Forced colors drop the ring's shadow and repaint the accent as plain text color,
// so mark the chosen version with a Highlight border and an underlined heading
@media (forced-colors: active) {
&[selected] groupbox {
border: 2px solid Highlight;
padding: 5px 7px;
}
// Highlight is a background color and can be unreadable as text, so underline instead
&[selected] h2 {
color: CanvasText;
text-decoration: underline;
}
}
.parent-row {
@ -39,26 +74,25 @@ merge-group {
min-width: 15em;
}
.choose-button {
margin-inline: 0;
margin-top: 6px;
}
collapsible-section {
border-bottom: none !important;
}
}
// Versions you can choose by clicking the whole card (notes and files use the button)
&:not([mergetype="note"]) {
#left-pane:active h2,
#right-pane:active h2,
#left-pane:active attachment-box #title,
#right-pane:active attachment-box #title {
color: red;
font-weight: 600;
:is(#left-pane, #right-pane):not([selected]) groupbox:hover {
background: var(--material-mix-quinary);
}
}
#left-pane:hover:not([selected]) h2,
#left-pane groupbox:focus:not([selected]) h2,
#right-pane:hover:not([selected]) h2,
#right-pane groupbox:focus:not([selected]) h2 {
text-decoration: underline;
:is(#left-pane, #right-pane):not([selected]) groupbox:active {
background: var(--material-mix-quarternary);
}
}
editable-text .input:read-only {
@ -85,3 +119,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);
}

View file

@ -1567,6 +1567,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');