add light mode

This commit is contained in:
John Gatward committed 2026-10-08 12:21:58 +01:00
1 parent 874ea1f8bf
commit c744979818
11 files changed
+689 -35

No files matched your search

+121
View File
@@ -37,6 +37,7 @@ function element(dataset = {}, textContent = '') {
scrollIntoView() {
this.scrolledIntoView = true;
},
contains: () => false,
};
}
@@ -112,6 +113,126 @@ function fixture({ missingFilter = false, reducedMotion = false } = {}) {
};
}
function animatedFixture(options) {
const f = fixture(options);
const animations = [];
const listeners = new Map();
const media = {
matches: options?.reducedMotion ?? false,
addEventListener: (name, listener) =>
listeners.set(`motion-${name}`, listener),
};
f.context.window.matchMedia = () => media;
f.context.window.addEventListener = (name, listener) =>
listeners.set(name, listener);
f.context.window.getComputedStyle = () => ({ opacity: '1' });
for (const card of f.cards) {
card.getBoundingClientRect = () => {
const index = f.visible().indexOf(card);
return { left: (index % 3) * 300, top: Math.floor(index / 3) * 200 };
};
card.animate = (frames, timing) => {
const animation = {
card,
frames,
timing,
cancelled: false,
cancel() {
this.cancelled = true;
},
addEventListener(name, listener) {
if (name === 'finish') this.finish = listener;
},
};
animations.push(animation);
return animation;
};
}
return { ...f, animations, listeners, media };
}
test('filtering moves retained cards and fades in new cards without delaying results', () => {
const f = animatedFixture();
f.start();
assert.equal(f.animations.length, 0);
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
rust.click();
assert.equal(f.visible().length, 1);
assert.equal(
f.controls.get('#project-count').textContent,
'Showing 1 of 1 project (Rust)'
);
assert.ok(
f.animations.some(
(animation) => animation.frames[0].transform !== 'translate(0px, 0px)'
)
);
assert.ok(
f.animations.every((animation) => animation.timing.duration === 280)
);
f.chips[0].click();
assert.equal(f.visible().length, 9);
assert.ok(
f.animations.some((animation) => animation.frames[0].opacity === 0)
);
});
test('rapid filter changes cancel old animations and finish on the latest selection', () => {
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
const previous = [...f.animations];
f.chips[0].click();
assert.ok(previous.every((animation) => animation.cancelled));
const current = f.animations.filter((animation) => !animation.cancelled);
previous.forEach((animation) => animation.finish());
f.listeners.get('resize')();
assert.ok(current.every((animation) => animation.cancelled));
assert.equal(f.visible().length, 9);
});
test('reduced motion is instant and enabling it cancels in-flight animations', () => {
const reduced = animatedFixture({ reducedMotion: true });
reduced.start();
reduced.chips.find((chip) => chip.dataset.filter === 'rust').click();
assert.equal(reduced.visible().length, 1);
assert.equal(reduced.animations.length, 0);
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
f.media.matches = true;
f.listeners.get('motion-change')();
assert.ok(f.animations.every((animation) => animation.cancelled));
const count = f.animations.length;
f.chips[0].click();
assert.equal(f.animations.length, count);
assert.equal(f.visible().length, 9);
});
test('filtering restores focus when the focused project becomes hidden', () => {
const f = fixture();
f.start();
const focused = f.cards.find((card) => !card.dataset.tech.includes('rust'));
f.context.document.activeElement = focused;
focused.contains = (target) => target === focused;
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
rust.click();
assert.equal(focused.hidden, true);
assert.equal(rust.focused, true);
});
test('keyboard focus immediately settles a moving project', () => {
const f = animatedFixture();
f.start();
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
const animation = f.animations[0];
f.controls.get('#project-grid').dispatch('focusin', {
target: { closest: () => animation.card },
});
assert.equal(animation.cancelled, true);
});
test('projects start collapsed with an accurate count and remaining label', () => {
const f = fixture();
f.start();