app: cherry-pick rune's pause and sound fixes onto the checkout

Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch
ported, carrying the four commits of upstream issues 1320 (a pause while
a clip is layered holds the layer's picture and time) and 1325 (a video's
sound is read ahead of the clock and leads it). Both were written against
eb9f1104 and ported across the refactors since. The faults are the first
two and the third in docs/rune-upstream.md; the app's workarounds in
review.rs stay until the fixes arrive upstream.
This commit is contained in:
vhaudiquet committed 2026-11-22 22:16:30 +01:00
1 parent 80fef698ce
commit 5bf262b82b
3795 files changed
+663463 -28

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
// Prints the layout rects (points) of a story's slotted elements, for matching Rune layouts.
// usage: node scripts/kit/rects.mjs <story-id> [light|dark] [click-selector]
import { openStory, playwright, serve } from "./storybook.mjs"
const [id, scheme = "light", click] = process.argv.slice(2)
const server = await serve()
const browser = await playwright().chromium.launch()
const page = await browser.newPage({ viewport: { width: 720, height: 900 } })
await openStory(page, server.url, id, scheme)
if (click) {
await page.locator(click).first().click()
await page.waitForTimeout(500)
}
const rows = await page.evaluate(() => {
const out = []
for (const el of document.querySelectorAll("[data-component], [data-slot], [role], button, input, label, span, svg")) {
const r = el.getBoundingClientRect()
if (!r.width || !r.height) continue
const cs = getComputedStyle(el)
const name = el.getAttribute("data-component") ?? el.getAttribute("data-slot") ?? el.getAttribute("role") ?? el.tagName.toLowerCase()
const t = el.children.length === 0 ? (el.textContent ?? "").trim().slice(0, 24) : ""
out.push(`${name.padEnd(32)} ${[r.x, r.y, r.width, r.height].map((v) => v.toFixed(2).padStart(8)).join(" ")} ${cs.fontSize}/${cs.lineHeight} ${cs.fontWeight} ${t}`)
}
return out
})
console.log(rows.join("\n"))
await browser.close()
server.close()
+61
View File
@@ -0,0 +1,61 @@
// Renders Storybook stories to PNG in headless Chromium, for scripts/kit-diff.py.
//
// stdin: JSON [{ id, scheme, width, height?, out, actions? }]
// actions: [{ click | hover | focus: selector, nth?: n }] run before the shot.
// Without `height`, the viewport is fitted to the story (frame padding included).
// stdout: JSON [{ id, scheme, width, height }]
import fs from "node:fs"
import { openStory, playwright, serve } from "./storybook.mjs"
const jobs = JSON.parse(fs.readFileSync(0, "utf8"))
const server = await serve()
const browser = await playwright().chromium.launch()
const results = []
for (const job of jobs) {
const page = await browser.newPage({ viewport: { width: job.width, height: 1600 }, deviceScaleFactor: job.scale ?? 2 })
await page.emulateMedia({ reducedMotion: "reduce" })
await openStory(page, server.url, job.id, job.scheme)
for (const a of job.actions ?? []) {
const [kind, selector] = Object.entries(a).find(([k]) => ["click", "hover", "focus", "press"].includes(k))
const loc = page.locator(selector).nth(a.nth ?? 0)
try {
if (kind === "click") await loc.click({ timeout: 5000 })
if (kind === "hover") await loc.hover({ timeout: 5000 })
if (kind === "focus") await loc.focus({ timeout: 5000 })
if (kind === "press") await page.keyboard.press(selector)
} catch (e) {
process.stderr.write(`${job.id}: ${kind} ${selector} failed: ${e.message.split("\n")[0]}\n`)
}
await page.waitForTimeout(a.wait ?? 400)
}
// Pause every animation at its end so overlays are fully in.
await page.evaluate(() => {
for (const a of document.getAnimations()) {
try {
const t = a.effect?.getComputedTiming()
if (t && Number.isFinite(t.endTime)) a.currentTime = t.endTime
else a.currentTime = 0
a.pause()
} catch {}
}
})
const height =
job.height ??
(await page.evaluate(() => {
const frame = document.querySelector("#storybook-root > div")
let bottom = 0
for (const el of frame?.children ?? []) bottom = Math.max(bottom, el.getBoundingClientRect().bottom)
for (const el of document.querySelectorAll("[data-popper-positioner], [role=dialog], [role=tooltip], .toast-v2-region"))
bottom = Math.max(bottom, el.getBoundingClientRect().bottom)
return Math.ceil(bottom + 24)
}))
await page.setViewportSize({ width: job.width, height })
await page.waitForTimeout(100)
await page.screenshot({ path: job.out })
results.push({ id: job.id, scheme: job.scheme, width: job.width, height })
await page.close()
}
await browser.close()
server.close()
process.stdout.write(JSON.stringify(results))
+62
View File
@@ -0,0 +1,62 @@
// Shared helpers for the kit scripts: serve a static Storybook build and open stories in
// headless Chromium through the OpenCode checkout's own Playwright.
//
// OPENCODE (env) points at an opencode checkout with `bun install` done and
// `packages/storybook/storybook-static` built (`bun run --cwd packages/storybook build`).
import fs from "node:fs"
import http from "node:http"
import path from "node:path"
import { createRequire } from "node:module"
export const opencode = process.env.OPENCODE ?? path.resolve(import.meta.dirname, "../../../opencode")
const storybookPkg = path.join(opencode, "packages/storybook/package.json")
export const staticDir = process.env.STORYBOOK_STATIC ?? path.join(opencode, "packages/storybook/storybook-static")
const types = {
".html": "text/html",
".js": "text/javascript",
".mjs": "text/javascript",
".css": "text/css",
".json": "application/json",
".svg": "image/svg+xml",
".woff2": "font/woff2",
".woff": "font/woff",
".ttf": "font/ttf",
".png": "image/png",
}
export async function serve() {
if (!fs.existsSync(path.join(staticDir, "iframe.html"))) {
throw new Error(`no Storybook build at ${staticDir}; run \`bun run --cwd packages/storybook build\` in ${opencode}`)
}
const server = http.createServer((req, res) => {
const url = decodeURIComponent(req.url.split("?")[0])
const file = path.join(staticDir, url === "/" ? "index.html" : url)
if (!file.startsWith(staticDir) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) {
res.statusCode = 404
return res.end()
}
res.setHeader("content-type", types[path.extname(file)] ?? "application/octet-stream")
fs.createReadStream(file).pipe(res)
})
await new Promise((ok) => server.listen(0, "127.0.0.1", ok))
return { url: `http://127.0.0.1:${server.address().port}`, close: () => server.close() }
}
export function playwright() {
return createRequire(storybookPkg)("@playwright/test")
}
/** Open a story with the given scheme; the decorator's padding stays, Storybook's own body padding goes. */
export async function openStory(page, base, id, scheme) {
await page.goto(`${base}/iframe.html?id=${id}&viewMode=story&globals=theme:${scheme}`)
await page.waitForSelector("#storybook-root > *", { timeout: 15000 })
await page.addStyleTag({
content: `body.sb-main-padded, body { padding: 0 !important; margin: 0 !important; }
html, body { background: var(--background-base) !important; }
*, *::before, *::after { transition: none !important; animation-play-state: paused !important; caret-color: transparent !important; }`,
})
await page.evaluate(() => document.fonts.ready)
await page.waitForTimeout(250)
}