fix(library): draw the wall whole and read its time down the right edge
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
// The wall, checked where it can actually go wrong: in a browser, on a shelf long
|
||||
// enough that the wall is drawing a few of its rows and standing in for the rest.
|
||||
// enough that a day of it is a screen and the shelf is many screens of them.
|
||||
//
|
||||
// One failure is what this guards, and it is the one that has already cost a
|
||||
// white screen: a window written from the window before it. The wall measures
|
||||
// itself after every render, writes what it measured, and renders again — so an
|
||||
// input the measure takes off the window it just wrote feeds itself, pass after
|
||||
// pass, until React gives up with #185, unmounts the tree, and leaves the reader
|
||||
// with nothing (there is no error boundary under it).
|
||||
// What it guards is the wall *being* the shelf, and saying so: every frame the open
|
||||
// node holds is a card (the wall is drawn whole — no window over it, so no card
|
||||
// arriving late and no spacer standing in for one), every card sits under the band
|
||||
// of its own day, the last frame is reachable by scrolling with nothing left under
|
||||
// it, and the rail down the wall's right edge — the shelf's own time — reads the
|
||||
// day the eye is in and takes the wall to the day it is pressed for.
|
||||
//
|
||||
// The trigger is not spelled out — no browser reproduces the reader's own,
|
||||
// which is the point — so the check drives the *class*: the wall's own box
|
||||
// reported at two different heights on every pass, plus one scroll to start it.
|
||||
// That is what any read-back is, and the wall must survive it.
|
||||
// It is drawn whole for a reason this check keeps an eye on: the wall used to be a
|
||||
// window over the shelf, and a window measured off the window before it cost a
|
||||
// white screen once (React #185, no error boundary under it). None of that state is
|
||||
// left — but a resize under the wall's own eye is the same class of input, and the
|
||||
// wall re-columns and the rail re-reads through it without taking the screen down.
|
||||
//
|
||||
// npm run build && node scripts/wall-check.mjs
|
||||
// PLAYWRIGHT_CORE=<path to playwright-core/index.mjs> node scripts/wall-check.mjs
|
||||
@@ -30,6 +31,12 @@ const APP_PORT = Number(process.env.APP_PORT ?? 5033);
|
||||
const SAMPLE_PORT = Number(process.env.SAMPLE_PORT ?? 5034);
|
||||
const FRAMES = Number(process.env.FRAMES ?? 300);
|
||||
const FOLDER = 'WallRoll';
|
||||
// The second roll: a shelf of one month, which the rail reads by the day rather
|
||||
// than by the month — the other half of what the rail is (`rail` in Library.tsx),
|
||||
// and the shape a folder per event has. Its frames are two days of twenty.
|
||||
const SMALL_FOLDER = 'OneDayRoll';
|
||||
const SMALL_EACH = 20;
|
||||
const SMALL_DAYS = 2;
|
||||
// Every frame is the same bytes under a different name: what is being checked is
|
||||
// how many cards the wall will draw, not what is on them. The bytes carry no
|
||||
// EXIF, so a frame's date is its own `lastModified` — spread over the days below,
|
||||
@@ -68,6 +75,42 @@ const dayIndex = (n) => {
|
||||
};
|
||||
const dayOfName = (name) => DAY0 + dayIndex(Number((name.match(/\d+/) ?? ['1'])[0]) - 1) * DAY_MS;
|
||||
|
||||
// The second roll's own names and days: `one-0001` onwards, twenty to a day, over
|
||||
// the fourth and fifth of March 2026 — one month, two days, which is the shelf the
|
||||
// rail reads by the day.
|
||||
const smallNames = Array.from(
|
||||
{ length: SMALL_DAYS * SMALL_EACH },
|
||||
(_, i) => `one-${String(i + 1).padStart(4, '0')}.jpg`
|
||||
);
|
||||
const smallDayOfName = (name) =>
|
||||
Date.UTC(2026, 2, 4 + Math.floor((Number((name.match(/\d+/) ?? ['1'])[0]) - 1) / SMALL_EACH));
|
||||
const allNames = [...names, ...smallNames];
|
||||
// What the tree is asked for and the sample server serves: both rolls.
|
||||
const servedNames = new Set(allNames);
|
||||
// Which of the two rolls a name belongs to: the big one is the shelf this check
|
||||
// walks, the small one is a shelf of a single month.
|
||||
const dayOf = (name) => (smallNames.includes(name) ? smallDayOfName(name) : dayOfName(name));
|
||||
// The months of the big roll, and the days of the small one: what the rail has to
|
||||
// hold, read off the roll rather than written down twice.
|
||||
const monthOf = (ts) => {
|
||||
const d = new Date(ts);
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
|
||||
};
|
||||
const keyOf = (ts) => {
|
||||
const d = new Date(ts);
|
||||
return `${monthOf(ts)}-${String(d.getDate()).padStart(2, '0')}`;
|
||||
};
|
||||
const MONTHS = [...new Set(names.map((name) => monthOf(dayOf(name))))];
|
||||
const SMALL_DAY_KEYS = [...new Set(smallNames.map((name) => keyOf(dayOf(name))))];
|
||||
// The days the big roll is cut into, which is what the wall draws bands for.
|
||||
const BIG_DAYS = (() => {
|
||||
let day = 0;
|
||||
for (let i = 0; i < FRAMES; i += 1) {
|
||||
if (!i || dayOfName(names[i]) !== dayOfName(names[i - 1])) day += 1;
|
||||
}
|
||||
return day;
|
||||
})();
|
||||
|
||||
let failures = 0;
|
||||
function step(name, ok, detail = '') {
|
||||
if (!ok) failures++;
|
||||
@@ -85,7 +128,7 @@ if (!playwright) {
|
||||
const jpg = await readFile(SAMPLE_FILE);
|
||||
const sampleServer = createServer((req, res) => {
|
||||
const name = path.basename(decodeURIComponent((req.url ?? '/').split('?')[0]));
|
||||
if (!names.includes(name)) {
|
||||
if (!servedNames.has(name)) {
|
||||
res.writeHead(404).end();
|
||||
return;
|
||||
}
|
||||
@@ -159,10 +202,13 @@ await context.route('**/api/**', (route) => {
|
||||
// they are put back where the catalogue reads them, because a cloned handle is a
|
||||
// plain object with no `getFile`.
|
||||
await context.addInitScript(
|
||||
({ origin, names, folder, days }) => {
|
||||
({ origin, names, folder, days, smallNames, smallFolder, smallDays }) => {
|
||||
// `days` is the day of each frame, index-aligned with `names`: the init
|
||||
// script is cloned into the page and cannot close over the check's own scope.
|
||||
const dayOfNameIn = (name) => days[names.indexOf(name)] ?? Date.UTC(2026, 0, 1);
|
||||
const dayOfNameIn = (name) => {
|
||||
const at = names.indexOf(name);
|
||||
return at >= 0 ? days[at] : smallDays[smallNames.indexOf(name)] ?? Date.UTC(2026, 0, 1);
|
||||
};
|
||||
const fileHandle = (name) => {
|
||||
const handle = { kind: 'file', name, __fake: true };
|
||||
Object.defineProperty(handle, 'getFile', {
|
||||
@@ -190,15 +236,21 @@ await context.addInitScript(
|
||||
});
|
||||
return handle;
|
||||
};
|
||||
const root = () => dirHandle(folder, { files: names });
|
||||
window.showDirectoryPicker = async () => root();
|
||||
// The folder the reader picks: the first press is the shelf this check walks,
|
||||
// the second is the shelf of a single month (the rail's other reading). A
|
||||
// picker is one folder at a time, and a check that needs two picks is a check
|
||||
// that hands them over one after the other.
|
||||
const root = (label) =>
|
||||
label === smallFolder ? dirHandle(smallFolder, { files: smallNames }) : dirHandle(folder, { files: names });
|
||||
let picked = 0;
|
||||
window.showDirectoryPicker = async () => root(picked++ === 0 ? folder : smallFolder);
|
||||
// The day each frame was given, for the header audit below: the page's own
|
||||
// clock reads the label, so the day is read back here the same way.
|
||||
window.__dayOf = (name) => dayOfNameIn(name);
|
||||
|
||||
const revive = (row) => {
|
||||
if (row?.handle?.__fake && !Object.getOwnPropertyDescriptor(row.handle, 'getFile')) {
|
||||
row.handle = row.handle.kind === 'directory' ? root() : fileHandle(row.handle.name);
|
||||
row.handle = row.handle.kind === 'directory' ? root(row.handle.name) : fileHandle(row.handle.name);
|
||||
}
|
||||
return row;
|
||||
};
|
||||
@@ -218,7 +270,15 @@ await context.addInitScript(
|
||||
};
|
||||
}
|
||||
},
|
||||
{ origin: `http://127.0.0.1:${SAMPLE_PORT}`, names, folder: FOLDER, days: names.map(dayOfName) }
|
||||
{
|
||||
origin: `http://127.0.0.1:${SAMPLE_PORT}`,
|
||||
names,
|
||||
folder: FOLDER,
|
||||
days: names.map(dayOfName),
|
||||
smallNames,
|
||||
smallFolder: SMALL_FOLDER,
|
||||
smallDays: smallNames.map(smallDayOfName),
|
||||
}
|
||||
);
|
||||
|
||||
const page = await context.newPage();
|
||||
@@ -275,31 +335,62 @@ const dayAudit = () =>
|
||||
return out;
|
||||
});
|
||||
|
||||
// --- the wall, drawn whole ---------------------------------------------------
|
||||
await page.click('[data-key="lib-view-grid"]');
|
||||
await page.waitForSelector('.adm-grid', { timeout: 15_000 });
|
||||
await page.waitForFunction(() => document.querySelectorAll('.adm-card').length > 0, null, { timeout: 30_000 });
|
||||
// The wall is the shelf: what the open node holds is what has to be on it. A window
|
||||
// over the shelf is a shelf that tears itself open under the reader — a day drawn a
|
||||
// couple of rows deep, growing as the eye walks down it, and a frame scrolled back
|
||||
// up to built again — so this is the first thing read.
|
||||
await page.waitForFunction(
|
||||
(n) => document.querySelectorAll('.adm-grid .adm-card').length >= n,
|
||||
FRAMES,
|
||||
{ timeout: 120_000, polling: 250 }
|
||||
);
|
||||
await page.waitForTimeout(2000);
|
||||
const wall = await read();
|
||||
step('the wall draws a screenful of the shelf', wall.cards > 0 && wall.cards < FRAMES, `${wall.cards} of ${FRAMES} cards drawn`);
|
||||
step('and stands in for the rows it is not drawing', wall.wall, 'the shelf scrolls');
|
||||
step('the wall draws every frame of the roll', wall.cards === FRAMES, `${wall.cards} of ${FRAMES} cards drawn`);
|
||||
step('and it is a shelf that scrolls', wall.wall, 'the wall scrolls');
|
||||
|
||||
const days1 = await dayAudit();
|
||||
// The first screenful is one day of a mixed roll often as not — a day big enough
|
||||
// to fill it is a day at all — so what is read here is that a band stands over
|
||||
// the cards and names its day, and the cut into several days is read below, on a
|
||||
// wall scrolled off the fold.
|
||||
step('the wall draws its days over the cards', days1.sections >= 1 && days1.labelled === days1.sections, `${days1.sections} headers over ${days1.cards} cards`);
|
||||
step('the wall draws a band for every day of the roll', days1.sections === BIG_DAYS, `${days1.sections} days of ${BIG_DAYS}`);
|
||||
step('every header names the day of the cards under it', days1.bad.length === 0, JSON.stringify(days1.bad.slice(0, 2)));
|
||||
|
||||
// The same wall, scrolled to where no day starts at the fold: the headers have to
|
||||
// move with it, which is the whole risk of cutting a virtualised wall into days.
|
||||
// Read down the shelf rather than at one stop: a stop of any one fraction lands
|
||||
// inside a day big enough to fill the screen as often as it lands on a fold, so
|
||||
// what is read is that no band ever files a card under another day's header, and
|
||||
// that the shelf's own cuts move through the window as it travels.
|
||||
// What the rail is read for: the entries it holds, the entry the eye is in, and where
|
||||
// a press on one takes the wall. The day at the fold is read off the sections
|
||||
// themselves — the first one crossing the wall's top band, which is the rule the rail
|
||||
// itself reads by — and the entry the wall says it is in is read off the accent.
|
||||
const railOf = () =>
|
||||
page.evaluate(() => {
|
||||
const grid = document.querySelector('.adm-grid');
|
||||
const rail = document.querySelector('.lib-rail');
|
||||
const items = [...(rail?.querySelectorAll('.lib-rail-item') ?? [])];
|
||||
const top = grid.getBoundingClientRect().top;
|
||||
const band = top + grid.clientHeight * 0.12;
|
||||
let fold = null;
|
||||
for (const section of grid.querySelectorAll('.adm-day')) {
|
||||
const box = section.getBoundingClientRect();
|
||||
if (box.top <= band && box.bottom > top) {
|
||||
fold = (section.getAttribute('data-key') ?? '').replace('lib-day-', '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
const on = document.querySelector('.lib-rail-item.on');
|
||||
return {
|
||||
keys: items.map((b) => (b.getAttribute('data-key') ?? '').replace('lib-rail-', '')),
|
||||
labels: items.map((b) => b.textContent.trim()),
|
||||
on: on ? (on.getAttribute('data-key') ?? '').replace('lib-rail-', '') : null,
|
||||
fold,
|
||||
scroll: Math.round(rail?.scrollTop ?? 0),
|
||||
tops: items.map((b) => b.offsetTop),
|
||||
heights: items.map((b) => b.offsetHeight),
|
||||
box: rail?.clientHeight ?? 0,
|
||||
};
|
||||
});
|
||||
const stops = [0.15, 0.35, 0.55, 0.75, 0.95];
|
||||
const seenDays = new Set();
|
||||
const seenMonths = new Set();
|
||||
let scrolledBad = [];
|
||||
let railBad = [];
|
||||
for (const at of stops) {
|
||||
await page.evaluate((f) => {
|
||||
const el = document.querySelector('.adm-grid');
|
||||
@@ -308,22 +399,59 @@ for (const at of stops) {
|
||||
}, at);
|
||||
await page.waitForTimeout(900);
|
||||
const audit = await dayAudit();
|
||||
for (const section of await page.$$eval('.adm-day', (els) => els.map((e) => e.getAttribute('data-key')))) seenDays.add(section);
|
||||
scrolledBad = scrolledBad.concat(audit.bad);
|
||||
const rail = await railOf();
|
||||
// The entry the rail says the eye is in has to own the day at the fold — the month
|
||||
// its key begins with — and the entry has to be inside the rail's own box: a rail
|
||||
// read for the whole shelf and standing on its own top is a rail that says nothing.
|
||||
if (!rail.fold || !rail.on || rail.fold.slice(0, 7) !== rail.on.slice(0, 7)) {
|
||||
railBad.push({ at, fold: rail.fold, on: rail.on });
|
||||
} else {
|
||||
seenMonths.add(rail.on.slice(0, 7));
|
||||
const i = rail.keys.indexOf(rail.on);
|
||||
const y = (rail.tops[i] ?? 0) - rail.scroll;
|
||||
if (y < -2 || y + (rail.heights[i] ?? 0) > rail.box + 2) railBad.push({ at, on: rail.on, y, box: rail.box });
|
||||
}
|
||||
}
|
||||
step(
|
||||
'a scrolled wall still files every card under its own day',
|
||||
scrolledBad.length === 0 && seenDays.size > 1,
|
||||
`${seenDays.size} days through the window, ${JSON.stringify(scrolledBad.slice(0, 2))}`
|
||||
scrolledBad.length === 0,
|
||||
JSON.stringify(scrolledBad.slice(0, 2))
|
||||
);
|
||||
const rail1 = await railOf();
|
||||
const railMonths = [...new Set(rail1.keys.map((k) => k.slice(0, 7)))].sort();
|
||||
step('the rail holds the months of the shelf', railMonths.join() === [...MONTHS].sort().join(), `${rail1.keys.join(' ')}`);
|
||||
step(
|
||||
'and the entry it reads follows the eye down the shelf',
|
||||
railBad.length === 0 && seenMonths.size === MONTHS.length,
|
||||
`${seenMonths.size} of ${MONTHS.length} months read, ${JSON.stringify(railBad.slice(0, 2))}`
|
||||
);
|
||||
|
||||
// The shelf walked to its own end, a screen at a time — a jump straight to the
|
||||
// bottom is a different question, and the one this check exists for: the wall
|
||||
// stands in for the frames it is not drawing, and a spacer standing in for more
|
||||
// rows than those frames take leaves the reader at the end of the scroll with a
|
||||
// screen of nothing under the last card drawn and the rest of the roll never
|
||||
// drawn at all. What the walk is read for is that it *gets* there, standing on
|
||||
// the last frame, and that every frame of the roll was drawn on the way.
|
||||
// And the press: the month's own first day is where the wall has to stand, its header
|
||||
// just under the wall's top edge, and the entry pressed is the one read afterwards.
|
||||
const jumped = rail1.keys[1];
|
||||
await page.click(`[data-key="lib-rail-${jumped}"]`);
|
||||
await page.waitForTimeout(700);
|
||||
const landed = await page.evaluate((key) => {
|
||||
const grid = document.querySelector('.adm-grid');
|
||||
const section = grid.querySelector(`[data-key="lib-day-${key}"]`);
|
||||
const box = grid.getBoundingClientRect();
|
||||
const on = document.querySelector('.lib-rail-item.on');
|
||||
return {
|
||||
top: section ? Math.round(section.getBoundingClientRect().top - box.top) : null,
|
||||
on: on ? (on.getAttribute('data-key') ?? '').replace('lib-rail-', '') : null,
|
||||
};
|
||||
}, jumped);
|
||||
step(
|
||||
'a press on a month takes the wall to that day',
|
||||
landed.top !== null && Math.abs(landed.top - 6) <= 6 && landed.on === jumped,
|
||||
`header at ${landed.top}, entry ${landed.on}`
|
||||
);
|
||||
|
||||
// The shelf walked to its own end, a screen at a time — a jump straight to the bottom
|
||||
// is a different question, and this is the one that stops a reader at a screen of
|
||||
// nothing: what the walk is read for is that it *gets* there, standing on the last
|
||||
// frame with no room left under it.
|
||||
const walked = await page.evaluate(async () => {
|
||||
const el = document.querySelector('.adm-grid');
|
||||
const seen = new Set();
|
||||
@@ -348,35 +476,75 @@ const walked = await page.evaluate(async () => {
|
||||
top: Math.round(el.scrollTop),
|
||||
reached: el.scrollTop + el.clientHeight >= el.scrollHeight - 2,
|
||||
room: Math.round(el.scrollHeight - el.clientHeight),
|
||||
// What is left under the last card drawn: the spacer that has nothing left
|
||||
// to stand in for. A few pixels is the grid's own gap.
|
||||
// What is left under the last card drawn. A few pixels is the grid's own gap.
|
||||
gap: last ? Math.round(el.scrollHeight - (last.getBoundingClientRect().bottom - box.top + el.scrollTop)) : null,
|
||||
seen: [...seen],
|
||||
};
|
||||
});
|
||||
step('the shelf is walked to its own end', walked.reached, `stopped at ${walked.top} of ${walked.room}`);
|
||||
step('and stands on nothing there', walked.gap !== null && walked.gap <= 16, `${walked.gap}px of nothing under the last card`);
|
||||
const missed = names.filter((name) => !walked.seen.includes(`lib-photo-${FOLDER}/${name}`));
|
||||
step('every frame of the roll is drawn on the way', missed.length === 0, `${walked.seen.length} of ${names.length} drawn, first missed ${missed[0] ?? 'none'}`);
|
||||
|
||||
// The class of trigger, made to happen: one input the wall reads back off itself,
|
||||
// moving on every pass.
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.adm-grid');
|
||||
const h = el.clientHeight;
|
||||
let n = 0;
|
||||
Object.defineProperty(el, 'clientHeight', { configurable: true, get: () => (n++ % 2 ? h : h + 300) });
|
||||
el.dispatchEvent(new Event('scroll'));
|
||||
});
|
||||
await page.waitForTimeout(8000);
|
||||
// A wall resized under its own eye: the class of input that cost the screen once, when
|
||||
// the wall measured itself off itself. It re-columns, the rail re-reads, and the reader
|
||||
// is still standing in the library after it.
|
||||
await page.setViewportSize({ width: 1180, height: 820 });
|
||||
await page.waitForTimeout(700);
|
||||
await page.setViewportSize({ width: 1500, height: 950 });
|
||||
await page.waitForTimeout(700);
|
||||
const after = await read();
|
||||
const looped = errors.filter((e) => e.includes('185') || e.includes('update depth'));
|
||||
step(
|
||||
'a wall fed its own window does not take the screen down',
|
||||
!after.blank && after.cards > 0 && looped.length === 0,
|
||||
'a wall resized under its own eye does not take the screen down',
|
||||
!after.blank && after.cards === FRAMES && looped.length === 0,
|
||||
`blank=${after.blank}, cards=${after.cards}, errors=${looped.length ? looped[0] : 'none'}`
|
||||
);
|
||||
step('the wall is still the wall', after.cards > 0, `${after.cards} cards after the feed`);
|
||||
const rail2 = await railOf();
|
||||
step(
|
||||
'and its rail still reads the day at the fold',
|
||||
rail2.on !== null && rail2.fold !== null && rail2.fold.slice(0, 7) === rail2.on.slice(0, 7),
|
||||
`fold ${rail2.fold}, entry ${rail2.on}`
|
||||
);
|
||||
|
||||
// The rail's other reading: a shelf of a single month is a shelf read by the day. The
|
||||
// second folder picked is that shelf — two days of twenty frames — and the wall on it
|
||||
// is a wall of two bands.
|
||||
await page.click('[data-key="lib-add"]');
|
||||
await page.waitForSelector(`[data-key="lib-node-${SMALL_FOLDER}"]`, { timeout: 60_000 });
|
||||
await page.click(`[data-key="lib-node-${SMALL_FOLDER}"]`);
|
||||
await page.waitForFunction(
|
||||
(n) => (document.querySelector('[data-key="lib-count"]')?.textContent ?? '').includes(String(n)),
|
||||
smallNames.length,
|
||||
{ timeout: 240_000, polling: 250 }
|
||||
);
|
||||
await page.click('[data-key="lib-view-grid"]');
|
||||
await page.waitForTimeout(1500);
|
||||
const rail3 = await railOf();
|
||||
step(
|
||||
'a shelf of one month is read by the day',
|
||||
[...rail3.keys].sort().join() === [...SMALL_DAY_KEYS].sort().join() && rail3.keys.length === SMALL_DAY_KEYS.length,
|
||||
`${rail3.labels.join(' ')} / ${rail3.keys.join(' ')}`
|
||||
);
|
||||
const plainDay = SMALL_DAY_KEYS[0];
|
||||
await page.click(`[data-key="lib-rail-${plainDay}"]`);
|
||||
await page.waitForTimeout(700);
|
||||
const small = await page.evaluate((key) => {
|
||||
const grid = document.querySelector('.adm-grid');
|
||||
const section = grid.querySelector(`[data-key="lib-day-${key}"]`);
|
||||
const box = grid.getBoundingClientRect();
|
||||
const on = document.querySelector('.lib-rail-item.on');
|
||||
return {
|
||||
top: section ? Math.round(section.getBoundingClientRect().top - box.top) : null,
|
||||
cards: section ? section.querySelectorAll('.adm-card').length : 0,
|
||||
on: on?.textContent.trim() ?? null,
|
||||
};
|
||||
}, plainDay);
|
||||
step(
|
||||
'a press on a day takes the wall to it, whole',
|
||||
small.top !== null &&
|
||||
Math.abs(small.top - 6) <= 6 &&
|
||||
small.cards === SMALL_EACH &&
|
||||
small.on === String(Number(plainDay.slice(8, 10))),
|
||||
`header at ${small.top}, ${small.cards} cards, entry ${small.on}`
|
||||
);
|
||||
|
||||
await page.screenshot({ path: process.env.SHOT ?? '/tmp/wall-check.png' }).catch(() => {});
|
||||
if (errors.length) console.log('page errors:', errors.slice(0, 6).join(' // '));
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
// The wall's own model of its rows (src/ui/dateGroups.ts, `bandRows` /
|
||||
// `rowPhoto` / `photoRow`), checked where it can go wrong without a browser.
|
||||
//
|
||||
// The wall draws the rows around the reader and a spacer stands in for the rest,
|
||||
// so a model of the rows that is out of step with the shelf drawn is a reader
|
||||
// stopping at a screen of nothing with frames below them never drawn — which is
|
||||
// what a flat `count / cols` count of rows is the moment the shelf is cut into
|
||||
// days: every day spends a row on its band, and a day whose frames do not come
|
||||
// out even over the columns leaves the rest of its last row empty.
|
||||
//
|
||||
// What has to hold is that the rows tile the shelf: one window per row, in
|
||||
// order, meeting at both ends and never leaving a frame between two of them, and
|
||||
// that a frame stands in the row the browser will draw it in.
|
||||
//
|
||||
// node scripts/wall-slot-check.mjs
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import ts from 'typescript';
|
||||
|
||||
const src = readFileSync(new URL('../src/ui/dateGroups.ts', import.meta.url), 'utf8');
|
||||
const js = ts.transpileModule(src, {
|
||||
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
|
||||
}).outputText;
|
||||
const { bandRows, dayAt, rowPhoto, photoRow, rowAt, rowTop, wallLayout } = await import(
|
||||
`data:text/javascript,${encodeURIComponent(js)}`
|
||||
);
|
||||
|
||||
// The frames per day, cycling — and with them the shelves the check stands on: a
|
||||
// shelf of equal days, a shelf of single-frame days, one day of everything, and
|
||||
// the rolls in between, which is what a camera roll is and where a flat count of
|
||||
// rows stops being right.
|
||||
const SHELVES = [
|
||||
[300, [10]],
|
||||
[200, [1]],
|
||||
[120, [120]],
|
||||
[300, [1, 40, 2, 3, 60, 1, 8, 120, 4, 2, 25, 7]],
|
||||
[1, [1]],
|
||||
[7, [2, 3]],
|
||||
[0, []],
|
||||
];
|
||||
const COLUMNS = [1, 2, 3, 6, 7, 13];
|
||||
// The two steps a shelf is stacked in, in the two shapes a measurement of them can
|
||||
// come out: a band of words a good deal shorter than a row of pictures, which is
|
||||
// the shelf on screen, and the two equal, which is what the model looked like when
|
||||
// it was one step and has to keep working.
|
||||
const STEPS = [
|
||||
{ band: 44, row: 208, gap: 12 },
|
||||
{ band: 208, row: 208, gap: 12 },
|
||||
];
|
||||
|
||||
let checked = 0;
|
||||
for (const [count, pattern] of SHELVES) {
|
||||
// The first frame of every day, off the pattern — the same list the wall cuts
|
||||
// its own `dayStarts` into.
|
||||
const days = [];
|
||||
for (let i = 0, day = 0; i < count; day++) {
|
||||
days.push(i);
|
||||
i += pattern[day % pattern.length];
|
||||
}
|
||||
assert.equal(days[0] ?? 0, 0);
|
||||
|
||||
for (const cols of COLUMNS) {
|
||||
const order = bandRows(days, count, cols);
|
||||
const rows = order[days.length];
|
||||
// One band per day, and its frames under it in rows of `cols`: the rows the
|
||||
// shelf is drawn in, which is what the model has to come to.
|
||||
let drawn = 0;
|
||||
for (let k = 0; k < days.length; k++) {
|
||||
drawn += 1 + Math.ceil(((days[k + 1] ?? count) - days[k]) / cols);
|
||||
}
|
||||
assert.equal(rows, drawn, `${count} frames in ${days.length} days at ${cols} columns: ${rows} rows modelled, ${drawn} drawn`);
|
||||
|
||||
// The rows tile the shelf: row `r` draws from `rowPhoto(r)` and the next row
|
||||
// takes it up from there, the first row starts at the first frame, and the
|
||||
// row past the last answers with the end of the shelf.
|
||||
let from = rowPhoto(days, count, cols, order, 0);
|
||||
assert.equal(from, 0, `${count}/${cols}: the shelf starts at its first frame`);
|
||||
for (let r = 1; r <= rows; r++) {
|
||||
const to = rowPhoto(days, count, cols, order, r);
|
||||
assert.ok(to >= from, `${count}/${cols}: row ${r} answers ${to}, behind ${from}`);
|
||||
assert.ok(to <= count, `${count}/${cols}: row ${r} answers ${to} of ${count}`);
|
||||
if (r === rows) assert.equal(to, count, `${count}/${cols}: the last row reaches the end`);
|
||||
from = to;
|
||||
}
|
||||
|
||||
// And a frame's own row is the row it is drawn in: that row's window starts
|
||||
// at or above it, and the row after starts below it.
|
||||
for (let i = 0; i < count; i++) {
|
||||
const row = photoRow(days, cols, order, i);
|
||||
assert.ok(row >= 1 && row < rows, `${count}/${cols}: frame ${i} is drawn in row ${row} of ${rows}`);
|
||||
assert.ok(rowPhoto(days, count, cols, order, row) <= i, `${count}/${cols}: frame ${i} stands past the start of row ${row}`);
|
||||
assert.ok(rowPhoto(days, count, cols, order, row + 1) > i, `${count}/${cols}: frame ${i} stands past the end of row ${row}`);
|
||||
checked++;
|
||||
}
|
||||
|
||||
// The shelf's own height and the two spacers that stand in for the days not
|
||||
// drawn, in the two steps it is actually stacked in. What has to hold is that
|
||||
// the shelf comes out the same height whichever window is over it: a height
|
||||
// that moves with the window is the reader walking down to the end of the
|
||||
// scroll and stopping a screen short of the frames it was standing in for.
|
||||
for (const steps of STEPS) {
|
||||
const at = `${count} frames in ${days.length} days at ${cols} columns, band ${steps.band}/row ${steps.row}`;
|
||||
const layout = wallLayout(days, count, cols, steps);
|
||||
const heights = days.map(
|
||||
(start, k) => steps.band + Math.ceil(((days[k + 1] ?? count) - start) / cols) * steps.row
|
||||
);
|
||||
const drawnHeight = heights.reduce((sum, h) => sum + h, 0);
|
||||
assert.equal(layout.height, days.length ? drawnHeight + (days.length - 1) * steps.gap : 0, `${at}: the shelf is ${layout.height} tall`);
|
||||
assert.equal(layout.rows, rows, `${at}: ${layout.rows} rows of the two steps, ${rows} drawn`);
|
||||
if (!days.length) continue;
|
||||
assert.equal(layout.ends[days.length - 1], layout.height, `${at}: the last day ends at the shelf's own height`);
|
||||
|
||||
// A row stands below the row before it, and the top it stands at reads back
|
||||
// as the row it is — which is what puts a scroll where a frame is.
|
||||
let last = -1;
|
||||
for (let r = 0; r < layout.rows; r++) {
|
||||
const top = rowTop(layout, r);
|
||||
assert.ok(top > last, `${at}: row ${r} stands at ${top}, behind ${last}`);
|
||||
last = top;
|
||||
assert.equal(rowAt(layout, top), r, `${at}: row ${r} at ${top} reads back as ${rowAt(layout, top)}`);
|
||||
}
|
||||
assert.equal(rowTop(layout, layout.rows - 1) + steps.row, layout.height, `${at}: the last row reaches the shelf's own height`);
|
||||
assert.equal(dayAt(days, count - 1), days.length - 1, `${at}: the last frame is filed under the last day`);
|
||||
|
||||
// And every window of days lays out the same shelf: the spacer over it, the
|
||||
// days drawn, the spacer under it and the grid's own gaps add up to one
|
||||
// height, whichever days are drawn.
|
||||
for (let a = 0; a < days.length; a++) {
|
||||
for (let b = a; b < days.length; b++) {
|
||||
// Laid out the way the DOM lays it: a spacer where the wall draws one
|
||||
// (a height of nought is no spacer), the days drawn, the grid's gap
|
||||
// between one item and the next.
|
||||
const above = a ? Math.max(0, layout.tops[a] - steps.gap) : 0;
|
||||
const below = Math.max(0, layout.height - layout.ends[b] - steps.gap);
|
||||
const items = b - a + 1 + (above > 0 ? 1 : 0) + (below > 0 ? 1 : 0);
|
||||
let sum = 0;
|
||||
for (let k = a; k <= b; k++) sum += heights[k];
|
||||
const total = above + sum + below + (items - 1) * steps.gap;
|
||||
assert.equal(total, layout.height, `${at}: days ${a}..${b} stand ${total} tall, the shelf ${layout.height}`);
|
||||
}
|
||||
}
|
||||
checked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(`ok ${checked} frames placed on ${SHELVES.length} shelves`);
|
||||
Reference in New Issue
Block a user