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:
1 parent
80fef698ce
commit
5bf262b82b
3795 files changed
+663463
-28
No files matched your search
Vendored
+130
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bun
|
||||
// `bun run build [--mode dev]`: the page is the Rune app in app/. This builds it to wasm (src/wasm/), bundles
|
||||
// src/main.ts and the Worker with Vite into Build Output, then has the app write its own static HTML (`--html`) into
|
||||
// index.html and 404.html, and adds robots.txt, sitemap.xml and llms.txt.
|
||||
// Needs Rust with the wasm32-unknown-unknown target, the wasm-bindgen CLI at the version in Cargo.lock and binaryen's
|
||||
// wasm-opt (`--no-opt` skips it).
|
||||
import { readFileSync, writeFileSync } from "node:fs"
|
||||
import { join, relative, resolve } from "node:path"
|
||||
import { parseArgs } from "node:util"
|
||||
import { getWorkerAssetsDir } from "@cloudflare/build-output-utils"
|
||||
import { $ } from "bun"
|
||||
import { BASE_PATH, hostForMode } from "../src/base"
|
||||
import { DESCRIPTION, REPO, SHARE_TITLE, TITLE } from "../src/meta"
|
||||
|
||||
const { values } = parseArgs({
|
||||
options: { mode: { type: "string", default: "production" }, "no-opt": { type: "boolean", default: false } },
|
||||
})
|
||||
const production = values.mode !== "dev"
|
||||
const origin = `https://${hostForMode(values.mode)}${BASE_PATH}`
|
||||
|
||||
const www = resolve(import.meta.dirname, "..")
|
||||
const repo = resolve(www, "..")
|
||||
// The commit the page tells you to pin: the one it was built from (or $RUNE_REV, outside a checkout).
|
||||
const rev = process.env.RUNE_REV ?? (await $`git rev-parse --short=12 HEAD`.cwd(repo).text()).trim()
|
||||
const env = { ...process.env, RUNE_REV: rev }
|
||||
const cargo = process.env.CARGO ?? "cargo"
|
||||
// The widths the static page is taken at: its breakpoints and the narrowest phone.
|
||||
const widths = "360,400,560,760,860,1000"
|
||||
|
||||
// Smallest wasm: optimized for size with whole-program LTO, then wasm-opt. `--no-opt` builds quicker and larger.
|
||||
const size = values["no-opt"] ? {} : { CARGO_PROFILE_RELEASE_OPT_LEVEL: "z", CARGO_PROFILE_RELEASE_LTO: "fat" }
|
||||
const opt = values["no-opt"] ? [] : ["--opt"]
|
||||
await $`scripts/web-build.sh rune-www --out www/src/wasm --no-html ${opt}`.cwd(repo).env({ ...env, ...size })
|
||||
await $`tsc --noEmit`.cwd(www)
|
||||
await $`vite build --mode ${values.mode}`.cwd(www)
|
||||
|
||||
const dir = getWorkerAssetsDir(www)
|
||||
const built = readFileSync(join(dir, "index.html"), "utf8")
|
||||
const escape = (s: string) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">")
|
||||
|
||||
const jsonld = {
|
||||
"@context": "https://schema.org",
|
||||
"@graph": [
|
||||
{ "@type": "WebSite", name: "Rune", url: `${origin}/` },
|
||||
{
|
||||
"@type": "SoftwareSourceCode",
|
||||
name: "Rune",
|
||||
description: DESCRIPTION,
|
||||
url: `${origin}/`,
|
||||
codeRepository: REPO,
|
||||
programmingLanguage: "Rust",
|
||||
runtimePlatform: ["macOS", "Windows", "Linux", "Web (WebGPU)", "iOS"],
|
||||
author: { "@type": "Organization", name: "Anomaly", url: "https://anoma.ly" },
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const head = (path: string, title: string, description: string, html: string) =>
|
||||
html
|
||||
.replace("<!--robots-->", production ? "" : `<meta name="robots" content="noindex, nofollow" />`)
|
||||
.replace("<!--jsonld-->", path === "/" ? `<script type="application/ld+json">${JSON.stringify(jsonld)}</script>` : "")
|
||||
.replaceAll("__URL__", `${origin}${path}`)
|
||||
.replaceAll("__SHARE_TITLE__", escape(path === "/" ? SHARE_TITLE : title))
|
||||
.replaceAll("__TITLE__", escape(title))
|
||||
.replaceAll("__DESCRIPTION__", escape(description))
|
||||
.replaceAll("__ORIGIN__", origin)
|
||||
|
||||
// The app lays itself out at each width and writes the page into the template; run from public/ so it finds the fonts.
|
||||
const page = async (file: string, template: string, extra: Record<string, string> = {}) => {
|
||||
const path = join(dir, file)
|
||||
writeFileSync(path, template)
|
||||
await $`${cargo} run -q -p rune-www -- --html ${path} --html-widths ${widths} --html-template ${path}`
|
||||
.cwd(join(www, "public"))
|
||||
.env({ ...env, ...extra })
|
||||
}
|
||||
|
||||
await page("index.html", head("/", TITLE, DESCRIPTION, built))
|
||||
// The Worker serves this for any missing path under the base, with a 404. It has no wasm and no canonical URL.
|
||||
const notFound = head("/404", "Not found · Rune", "There's no page here.", built)
|
||||
.replace(/\s*<script type="module"[^>]*><\/script>/g, "")
|
||||
.replace(/\s*<link rel="modulepreload"[^>]*>/g, "")
|
||||
.replace(/\s*<link rel="canonical"[^>]*>/, "")
|
||||
await page("404.html", notFound, { RUNE_WWW_PAGE: "404" })
|
||||
|
||||
// Dev is for checking before release: keep it out of search.
|
||||
writeFileSync(
|
||||
join(dir, "robots.txt"),
|
||||
production ? `User-agent: *\nAllow: /\n\nSitemap: ${origin}/sitemap.xml\n` : "User-agent: *\nDisallow: /\n",
|
||||
)
|
||||
if (production) {
|
||||
writeFileSync(
|
||||
join(dir, "sitemap.xml"),
|
||||
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n <url><loc>${origin}/</loc></url>\n</urlset>\n`,
|
||||
)
|
||||
}
|
||||
|
||||
// llms.txt (llmstxt.org): what Rune is and where to read more.
|
||||
writeFileSync(
|
||||
join(dir, "llms.txt"),
|
||||
[
|
||||
"# Rune",
|
||||
"",
|
||||
`> ${DESCRIPTION}`,
|
||||
"",
|
||||
"Rune is a Rust UI framework. Views are plain Rust functions of state; Rune diffs them, lays them out with Taffy,",
|
||||
"animates layout and properties with springs, and draws every frame with one instanced GPU draw. It runs on macOS",
|
||||
"(its own Metal backend), Windows, Linux, iOS (embedded in UIKit or SwiftUI) and the web (WebGPU, experimental).",
|
||||
"",
|
||||
"This page is itself a Rune app: the HTML is what the app writes with `--html`, and the canvas is the same app.",
|
||||
"",
|
||||
"## Source",
|
||||
"",
|
||||
`- [anomalyco/rune](${REPO}): the code`,
|
||||
`- [crates/rune/README.md](${REPO}/blob/dev/crates/rune/README.md): the framework guide`,
|
||||
`- [WEB.md](${REPO}/blob/dev/WEB.md): building a Rune app for the browser`,
|
||||
`- [CHANGELOG.md](${REPO}/blob/dev/CHANGELOG.md): what changed, newest first`,
|
||||
`- [www/app](${REPO}/tree/dev/www/app): this page's source`,
|
||||
"",
|
||||
"## Use it",
|
||||
"",
|
||||
"Add Rune to Cargo.toml pinned to a commit:",
|
||||
"",
|
||||
"```toml",
|
||||
`rune = { git = "${REPO}", rev = "${rev}" }`,
|
||||
"```",
|
||||
"",
|
||||
].join("\n"),
|
||||
)
|
||||
|
||||
console.log(`Built ${production ? "production" : "dev"} into ${relative(www, dir)}/`)
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bun
|
||||
// `bun scripts/icons.ts`: draws the brand into public/: favicon.svg and favicon.ico (16 and 32) from the 16-cell ᚱ on
|
||||
// transparent; apple-touch-icon.png (180), icon-192.png and icon-512.png from the wordmark's ᚱ on black; and og.png
|
||||
// (1200 × 630), the whole wordmark on black. Every cell is a whole number of pixels, so the PNGs are written directly,
|
||||
// with no browser.
|
||||
import { writeFileSync } from "node:fs"
|
||||
import { join, resolve } from "node:path"
|
||||
import { deflateSync } from "node:zlib"
|
||||
import { ICON16, INK, WORDMARK, oklch, runs, type Grid } from "../src/brand/pixels"
|
||||
|
||||
const out = resolve(import.meta.dirname, "..", "public")
|
||||
const ink = oklch(...INK).map(c => Math.round(c * 255)) as [number, number, number]
|
||||
const hex = `#${ink.map(c => c.toString(16).padStart(2, "0")).join("")}`
|
||||
|
||||
const crcTable = Array.from({ length: 256 }, (_, n) => {
|
||||
let c = n
|
||||
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
|
||||
return c >>> 0
|
||||
})
|
||||
const crc = (bytes: Uint8Array) => {
|
||||
let c = 0xffffffff
|
||||
for (const b of bytes) c = crcTable[(c ^ b) & 0xff]! ^ (c >>> 8)
|
||||
return (c ^ 0xffffffff) >>> 0
|
||||
}
|
||||
function chunk(type: string, data: Uint8Array) {
|
||||
const body = new Uint8Array(4 + data.length)
|
||||
body.set(new TextEncoder().encode(type))
|
||||
body.set(data, 4)
|
||||
const out = new Uint8Array(12 + data.length)
|
||||
const dv = new DataView(out.buffer)
|
||||
dv.setUint32(0, data.length)
|
||||
out.set(body, 4)
|
||||
dv.setUint32(8 + data.length, crc(body))
|
||||
return out
|
||||
}
|
||||
|
||||
/** `rows` at `px` pixels a cell, centred in a `width` × `height` image on `background` (null for transparent), as an
|
||||
* RGBA PNG. */
|
||||
function png(rows: Grid, px: number, background: [number, number, number] | null, width: number, height = width) {
|
||||
const w = rows[0]!.length * px, h = rows.length * px
|
||||
const ox = Math.floor((width - w) / 2), oy = Math.floor((height - h) / 2)
|
||||
const raw = new Uint8Array(height * (width * 4 + 1))
|
||||
for (let y = 0; y < height; y++) {
|
||||
const row = y * (width * 4 + 1)
|
||||
for (let x = 0; x < width; x++) {
|
||||
const cx = Math.floor((x - ox) / px), cy = Math.floor((y - oy) / px)
|
||||
const on = x >= ox && y >= oy && rows[cy]?.[cx] === "#"
|
||||
const rgb = on ? ink : background
|
||||
if (rgb) raw.set([...rgb, 255], row + 1 + x * 4)
|
||||
}
|
||||
}
|
||||
const header = new Uint8Array(13)
|
||||
const dv = new DataView(header.buffer)
|
||||
dv.setUint32(0, width)
|
||||
dv.setUint32(4, height)
|
||||
header.set([8, 6, 0, 0, 0], 8)
|
||||
const parts = [new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", header), chunk("IDAT", deflateSync(raw)), chunk("IEND", new Uint8Array())]
|
||||
return Buffer.concat(parts)
|
||||
}
|
||||
|
||||
/** An ICO holding PNGs, one entry per size. */
|
||||
function ico(images: { png: Uint8Array; size: number }[]) {
|
||||
const header = 6 + 16 * images.length
|
||||
const out = new Uint8Array(header + images.reduce((n, i) => n + i.png.length, 0))
|
||||
const dv = new DataView(out.buffer)
|
||||
dv.setUint16(2, 1, true)
|
||||
dv.setUint16(4, images.length, true)
|
||||
let offset = header
|
||||
images.forEach(({ png, size }, k) => {
|
||||
const e = 6 + 16 * k
|
||||
out[e] = size
|
||||
out[e + 1] = size
|
||||
dv.setUint16(e + 4, 1, true)
|
||||
dv.setUint16(e + 6, 32, true)
|
||||
dv.setUint32(e + 8, png.length, true)
|
||||
dv.setUint32(e + 12, offset, true)
|
||||
out.set(png, offset)
|
||||
offset += png.length
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
const rune = WORDMARK.glyphs[0]!.rows
|
||||
const black: [number, number, number] = [0, 0, 0]
|
||||
for (const [name, size, px] of [["icon-512.png", 512, 32], ["icon-192.png", 192, 12], ["apple-touch-icon.png", 180, 12]] as const) {
|
||||
writeFileSync(join(out, name), png(rune, px, black, size))
|
||||
}
|
||||
writeFileSync(join(out, "favicon.ico"), ico([32, 16].map(size => ({ size, png: png(ICON16, size / 16, null, size) }))))
|
||||
const word = Array.from({ length: WORDMARK.height }, (_, y) =>
|
||||
Array.from({ length: WORDMARK.width }, (_, x) => (WORDMARK.glyphs.some(g => g.rows[y]?.[x - g.x] === "#") ? "#" : ".")).join(""))
|
||||
writeFileSync(join(out, "og.png"), png(word, 24, black, 1200, 630))
|
||||
const rects = runs(ICON16).map(([x, y, w, h]) => `<rect x="${x}" y="${y}" width="${w}" height="${h}"/>`).join("")
|
||||
writeFileSync(join(out, "favicon.svg"), `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" shape-rendering="crispEdges" fill="${hex}">${rects}</svg>\n`)
|
||||
console.log(`Icons in ${ink.join(",")} (${hex}) → ${out}`)
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bun
|
||||
// `bun run images`: cuts the page's images from Rune's own renders in demo/ into AVIF at the sizes the page shows
|
||||
// them, into public/img/. The widths and aspect ratios here match the `Picture`s in app/src/sections.rs.
|
||||
// Needs ImageMagick 7 with AVIF. The outputs are committed, so a build never needs it.
|
||||
import { mkdirSync, rmSync, statSync } from "node:fs"
|
||||
import { join, resolve } from "node:path"
|
||||
import { $ } from "bun"
|
||||
|
||||
// Gallery tiles are 16:9, so crop renders of other shapes to 16:9 here. `smooth` is for soft gradients on black, which
|
||||
// band in 8-bit: it encodes 10-bit AVIF at a higher quality.
|
||||
type Spec = { src: string; crop?: [number, number, number, number]; widths: number[]; smooth?: boolean }
|
||||
|
||||
const repo = resolve(import.meta.dirname, "..", "..")
|
||||
const www = resolve(import.meta.dirname, "..")
|
||||
const out = join(www, "public", "img")
|
||||
|
||||
export const specs: Record<string, Spec> = {
|
||||
hello: { src: "site/public/shots/hello-on.png", widths: [320, 640] },
|
||||
"opencode-session": { src: "demo/opencode/session-top.png", widths: [720, 1120, 1680, 2240] },
|
||||
"opencode-home": { src: "demo/opencode/home.png", widths: [560, 1100] },
|
||||
"opencode-streaming": { src: "demo/opencode/streaming.png", widths: [560, 1100] },
|
||||
// `cargo run --release -p site-scenes` renders these into target/; they aren't committed.
|
||||
metal: { src: "target/site-scenes/metal.png", widths: [760, 1520], smooth: true },
|
||||
glass: { src: "target/site-scenes/glass.png", crop: [240, 135, 1440, 810], widths: [380, 760], smooth: true },
|
||||
light: { src: "target/site-scenes/light.png", crop: [240, 135, 1440, 810], widths: [380, 760], smooth: true },
|
||||
}
|
||||
|
||||
rmSync(out, { recursive: true, force: true })
|
||||
mkdirSync(out, { recursive: true })
|
||||
let bytes = 0
|
||||
for (const [name, spec] of Object.entries(specs)) {
|
||||
const src = join(repo, spec.src)
|
||||
const crop = spec.crop ? ["-crop", `${spec.crop[2]}x${spec.crop[3]}+${spec.crop[0]}+${spec.crop[1]}`, "+repage"] : []
|
||||
const w0 = spec.crop ? spec.crop[2] : Number(await $`magick identify -format "%w" ${src}`.text())
|
||||
const widths = spec.widths.filter(w => w <= w0)
|
||||
for (const w of widths) {
|
||||
const [quality, depth] = spec.smooth ? [70, 10] : [52, 8]
|
||||
const file = join(out, `${name}-${w}.avif`)
|
||||
await $`magick ${src} ${crop} -resize ${w}x -strip -depth ${depth} -quality ${quality} ${file}`.quiet()
|
||||
bytes += statSync(file).size
|
||||
}
|
||||
}
|
||||
console.log(`${Object.keys(specs).length} images, ${(bytes / 1024).toFixed(0)} KB → public/img/`)
|
||||
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bun
|
||||
// `bun run serve [--port 4253]`: serves the built site through worker.ts, with a stand-in for the ASSETS binding that
|
||||
// reads the build output, so the base path, 404 page and headers are the Worker's own. Run `bun run build` first.
|
||||
import { existsSync, statSync } from "node:fs"
|
||||
import { extname, join, resolve } from "node:path"
|
||||
import { parseArgs } from "node:util"
|
||||
import { brotliCompressSync, constants } from "node:zlib"
|
||||
import { getWorkerAssetsDir } from "@cloudflare/build-output-utils"
|
||||
import worker from "../worker"
|
||||
|
||||
const { values } = parseArgs({ options: { port: { type: "string", default: "4253" }, host: { type: "string", default: "127.0.0.1" } } })
|
||||
const dir = getWorkerAssetsDir(resolve(import.meta.dirname, ".."))
|
||||
if (!existsSync(join(dir, "index.html"))) throw new Error(`${dir}/index.html not found; run \`bun run build\` first`)
|
||||
|
||||
const file = (p: string) => existsSync(p) && statSync(p).isFile() ? p : undefined
|
||||
|
||||
// Static assets as Cloudflare serves them with html_handling "auto-trailing-slash": /x finds x.html or x/index.html.
|
||||
const ASSETS = {
|
||||
async fetch(request: Request) {
|
||||
const path = decodeURIComponent(new URL(request.url).pathname)
|
||||
const base = join(dir, path)
|
||||
const hit = path.endsWith("/") ? file(join(base, "index.html")) : file(base) ?? file(`${base}.html`)
|
||||
if (!hit) return new Response("Not found", { status: 404 })
|
||||
const html = extname(hit) === ".html"
|
||||
return new Response(Bun.file(hit), { headers: html ? { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-cache" } : {} })
|
||||
},
|
||||
}
|
||||
|
||||
// Cloudflare compresses text and wasm on the way out; do the same so timings here are close to the real thing.
|
||||
const squeezable = /^(text\/|application\/(javascript|json|wasm|manifest\+json)|image\/(svg|x-icon)|font\/(ttf|otf))/
|
||||
const squeezed = new Map<string, Buffer>()
|
||||
|
||||
const server = Bun.serve({
|
||||
hostname: values.host,
|
||||
port: Number(values.port),
|
||||
async fetch(request) {
|
||||
const response = await worker.fetch(request, { ASSETS, CANONICAL_HOST: "localhost", ANY_HOST: "1" })
|
||||
const type = response.headers.get("Content-Type") ?? ""
|
||||
if (!response.ok || !squeezable.test(type) || !request.headers.get("Accept-Encoding")?.includes("br")) return response
|
||||
const key = new URL(request.url).pathname
|
||||
let body = squeezed.get(key)
|
||||
if (!body) {
|
||||
body = brotliCompressSync(new Uint8Array(await response.arrayBuffer()), { params: { [constants.BROTLI_PARAM_QUALITY]: 5 } })
|
||||
squeezed.set(key, body)
|
||||
}
|
||||
const headers = new Headers(response.headers)
|
||||
headers.set("Content-Encoding", "br")
|
||||
headers.delete("Content-Length")
|
||||
return new Response(new Uint8Array(body), { status: response.status, headers })
|
||||
},
|
||||
})
|
||||
console.log(`rune-www on ${server.url}rune/`)
|
||||
Reference in new issue
Block a user