Refactoring
This commit is contained in:
1 parent
fd58a8d32f
commit
97e219456d
29 files changed
+45
-408
No files matched your search
Binary file not shown.
@@ -1,21 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
/* Jumps to card 3 via its dot, then back to card 1 via its dot, and reports where the page rests. */
|
||||
const [,, url, width = '1440', height = '900'] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
const snaps = await page.evaluate(() => Array.from(document.querySelectorAll('[data-deck-snap]')).map((a) => Math.round(a.getBoundingClientRect().top + window.scrollY - parseFloat(getComputedStyle(a).scrollMarginTop))));
|
||||
const dots = page.locator('[data-deck-dots] a');
|
||||
await page.evaluate((y) => window.scrollTo(0, y), snaps[2]);
|
||||
await page.waitForTimeout(800);
|
||||
const before = await page.evaluate(() => Math.round(window.scrollY));
|
||||
await dots.nth(0).click();
|
||||
await page.waitForTimeout(1500);
|
||||
const back = await page.evaluate(() => Math.round(window.scrollY));
|
||||
await dots.nth(3).click();
|
||||
await page.waitForTimeout(1500);
|
||||
const fwd = await page.evaluate(() => Math.round(window.scrollY));
|
||||
const active = await page.evaluate(() => Array.from(document.querySelectorAll('[data-deck-dots] a')).map((a) => a.getAttribute('aria-current') === 'true'));
|
||||
const hint = await page.evaluate(() => { const h = document.querySelector('[data-deck-hint]'); return { href: h?.getAttribute('href'), last: h?.hasAttribute('data-last') }; });
|
||||
console.log({ snaps, before, backTo1: back, expected1: snaps[0], fwdTo4: fwd, expected4: snaps[3], active, hint });
|
||||
await browser.close();
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Turns a generated clip into a seamless looping hero background:
|
||||
# the clip plays forward, then backward, so the loop point cannot be seen.
|
||||
# Usage: encode-hero-video.sh <source.mp4> <out-basename> [width]
|
||||
set -euo pipefail
|
||||
FFMPEG="${FFMPEG:-ffmpeg}"
|
||||
SRC="$1"; OUT="$2"; W="${3:-1920}"
|
||||
FILTER="[0:v]scale=${W}:-2:flags=lanczos,fps=25,setpts=PTS-STARTPTS,split[a][b];[b]reverse,trim=start_frame=1,setpts=PTS-STARTPTS[r];[a][r]concat=n=2:v=1[v]"
|
||||
"$FFMPEG" -y -i "$SRC" -filter_complex "$FILTER" -map "[v]" -an \
|
||||
-c:v libx264 -profile:v high -crf 30 -preset slow -pix_fmt yuv420p -movflags +faststart "${OUT}.mp4"
|
||||
"$FFMPEG" -y -i "$SRC" -filter_complex "$FILTER" -map "[v]" -an \
|
||||
-c:v libvpx-vp9 -crf 40 -b:v 0 -row-mt 1 -deadline good -cpu-used 2 "${OUT}.webm"
|
||||
ls -lh "${OUT}.mp4" "${OUT}.webm"
|
||||
@@ -1,39 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
/* Checks the hero video: does it load and play, is it gated off on phones and under reduced
|
||||
motion, and does the hero fill the viewport. */
|
||||
const [,, url, prefix] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
|
||||
async function probe(label, opts, shots = []) {
|
||||
const ctx = await browser.newContext(opts);
|
||||
const page = await ctx.newPage();
|
||||
const requested = [];
|
||||
page.on('request', (r) => { if (/\.(mp4|webm)$/.test(r.url())) requested.push(r.url().split('/').pop()); });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
await page.waitForTimeout(2500);
|
||||
const info = await page.evaluate(() => {
|
||||
const v = document.querySelector('video');
|
||||
const hero = document.querySelector('.hero');
|
||||
return {
|
||||
hasVideo: !!v,
|
||||
ready: v?.hasAttribute('data-ready') ?? null,
|
||||
paused: v?.paused ?? null,
|
||||
currentTime: v ? Math.round(v.currentTime * 10) / 10 : null,
|
||||
videoSize: v ? `${v.videoWidth}x${v.videoHeight}` : null,
|
||||
heroHeight: Math.round(hero.getBoundingClientRect().height),
|
||||
viewport: window.innerHeight,
|
||||
headerH: Math.round(document.querySelector('header').getBoundingClientRect().height),
|
||||
};
|
||||
});
|
||||
for (const t of shots) {
|
||||
await page.waitForTimeout(t);
|
||||
await page.screenshot({ path: `${prefix}-${label}-${t}.png` });
|
||||
}
|
||||
console.log(label, JSON.stringify({ ...info, requested }));
|
||||
await ctx.close();
|
||||
}
|
||||
|
||||
await probe('desktop', { viewport: { width: 1440, height: 900 } }, [0, 2500]);
|
||||
await probe('mobile', { viewport: { width: 390, height: 844 } });
|
||||
await probe('reduced', { viewport: { width: 1440, height: 900 }, reducedMotion: 'reduce' });
|
||||
await browser.close();
|
||||
@@ -1,20 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
/* Reports where the chevron hint sits at the first snap and whether anything covers it. */
|
||||
const [,, url, width = '1440', height = '900'] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
const snaps = await page.evaluate(() => Array.from(document.querySelectorAll('[data-deck-snap]')).map((a) => Math.round(a.getBoundingClientRect().top + window.scrollY - parseFloat(getComputedStyle(a).scrollMarginTop))));
|
||||
await page.evaluate((y) => window.scrollTo(0, y), snaps[0]);
|
||||
await page.waitForTimeout(800);
|
||||
const info = await page.evaluate(() => {
|
||||
const h = document.querySelector('[data-deck-hint]');
|
||||
const r = h.getBoundingClientRect();
|
||||
const cs = getComputedStyle(h);
|
||||
const svg = h.querySelector('svg').getBoundingClientRect();
|
||||
const atPoint = document.elementFromPoint(window.innerWidth / 2, window.innerHeight - 10);
|
||||
const next = document.querySelectorAll('[data-deck-card]')[1].getBoundingClientRect();
|
||||
return { hint: { top: r.top, bottom: r.bottom, h: r.height }, svg: { top: svg.top, bottom: svg.bottom }, position: cs.position, display: cs.display, bottom: cs.bottom, zIndex: cs.zIndex, opacity: cs.opacity, atPoint: atPoint && (atPoint.tagName + '.' + atPoint.className), nextCardTop: next.top, innerHeight: window.innerHeight };
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
await browser.close();
|
||||
@@ -1,14 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
const browser = await chromium.launch();
|
||||
/* Phone: the sweep should still run, the hover state should not exist. */
|
||||
const ctx = await browser.newContext({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
|
||||
const page = await ctx.newPage();
|
||||
await page.goto(process.argv[2], { waitUntil: 'networkidle' });
|
||||
await page.locator('.stages__list').scrollIntoViewIfNeeded();
|
||||
await page.waitForTimeout(2000);
|
||||
console.log('mobile shown:', JSON.stringify(await page.evaluate(() =>
|
||||
Array.from(document.querySelectorAll('[data-reveal]')).map((o) => o.hasAttribute('data-shown')))));
|
||||
console.log('grid opacity (no hover):', await page.evaluate(() =>
|
||||
getComputedStyle(document.querySelector('.grid-object__base')).opacity));
|
||||
await page.screenshot({ path: process.argv[3] });
|
||||
await browser.close();
|
||||
@@ -1,28 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
/* Scrolls to positions around each deck card's snap point and reports where the page comes to rest. */
|
||||
const [,, url, width = '1440', height = '900'] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
const info = await page.evaluate(() => {
|
||||
const cards = Array.from(document.querySelectorAll('[data-deck-snap]'));
|
||||
const cs = getComputedStyle(document.documentElement);
|
||||
return cards.map((c, i) => {
|
||||
const st = getComputedStyle(c);
|
||||
return { i, naturalTop: c.offsetTop + (c.offsetParent?.getBoundingClientRect().top ?? 0) + window.scrollY, marginTop: st.scrollMarginTop, snapAlign: st.scrollSnapAlign, snapStop: st.scrollSnapStop, htmlSnap: cs.scrollSnapType };
|
||||
});
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
// expected snap points: naturalTop - scrollMarginTop
|
||||
const results = [];
|
||||
for (const c of info) {
|
||||
const expected = Math.round(c.naturalTop - parseFloat(c.marginTop));
|
||||
for (const off of [-220, 180, 320, 352]) {
|
||||
await page.evaluate((y) => window.scrollTo({ top: y, behavior: 'auto' }), expected + off);
|
||||
await page.waitForTimeout(1200);
|
||||
const y = await page.evaluate(() => Math.round(window.scrollY));
|
||||
results.push({ card: c.i, expected, offset: off, landed: y, snapped: Math.abs(y - expected) < 2 });
|
||||
}
|
||||
}
|
||||
console.table(results);
|
||||
await browser.close();
|
||||
@@ -1,13 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
const [,, url, prefix, anchor, width = '1440', height = '900', step = '450', count = '10'] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
const start = await page.evaluate((sel) => document.querySelector(sel).getBoundingClientRect().top + window.scrollY, anchor);
|
||||
for (let i = 0; i < Number(count); i++) {
|
||||
await page.evaluate((y) => window.scrollTo(0, y), start + i * Number(step));
|
||||
await page.waitForTimeout(i === 0 ? 3000 : 1800);
|
||||
await page.screenshot({ path: `${prefix}-${String(i).padStart(2, '0')}.png` });
|
||||
}
|
||||
await browser.close();
|
||||
console.log('stack shots', count);
|
||||
@@ -1,13 +0,0 @@
|
||||
import { chromium } from 'playwright';
|
||||
const [,, url, prefix, anchor, width = '1440', height = '900', step = '450', count = '10'] = process.argv;
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
const start = await page.evaluate((sel) => document.querySelector(sel).getBoundingClientRect().top + window.scrollY, anchor);
|
||||
for (let i = 0; i < Number(count); i++) {
|
||||
await page.evaluate((y) => window.scrollTo(0, y), start + i * Number(step));
|
||||
await page.waitForTimeout(i === 0 ? 2500 : 1500);
|
||||
await page.screenshot({ path: `${prefix}-${String(i).padStart(2, '0')}.png` });
|
||||
}
|
||||
await browser.close();
|
||||
console.log('stack shots', count);
|
||||
Reference in new issue
Block a user