diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 00000000..f3491d7b --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,88 @@ +name: Website + +on: + pull_request: + paths: + - 'website/**' + - 'scripts/build-website.sh' + - 'tests/browser/engine.mjs' + - 'docs/guides/assets/dota2-short-film-canvas.jpg' + - 'docs/guides/assets/dota2-short-film.mp4' + - '.github/workflows/website.yml' + push: + branches: [main] + paths: + - 'website/**' + - 'scripts/build-website.sh' + - 'tests/browser/engine.mjs' + - 'docs/guides/assets/dota2-short-film-canvas.jpg' + - 'docs/guides/assets/dota2-short-film.mp4' + - '.github/workflows/website.yml' + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: website-${{ github.ref }} + cancel-in-progress: false + +jobs: + refresh-downloads: + if: github.event_name == 'release' && github.repository == 'ThinkFlowLab/OpenDirector' && !github.event.release.prerelease + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Start the Pages build on main + env: + GH_TOKEN: ${{ github.token }} + run: gh api --method POST "repos/$GITHUB_REPOSITORY/actions/workflows/website.yml/dispatches" -f ref=main + + build: + if: github.event_name != 'release' + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + ref: ${{ github.ref == 'refs/heads/main' && 'main' || github.sha }} + persist-credentials: false + - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + with: + node-version-file: .nvmrc + - run: node --test website/installers.test.mjs + - name: Build the website with published downloads + env: + GITHUB_TOKEN: ${{ github.token }} + run: bash scripts/build-website.sh "$RUNNER_TEMP/pages/OpenDirector" + - name: Check the built site in Chromium + run: | + npm install --prefix "$RUNNER_TEMP/browser" --no-save --no-package-lock playwright-core@1.58.2 + export PLAYWRIGHT_MODULE="$RUNNER_TEMP/browser/node_modules/playwright-core/index.mjs" + node "$RUNNER_TEMP/browser/node_modules/playwright-core/cli.js" install --with-deps --only-shell chromium + python3 -m http.server 8780 --bind 127.0.0.1 --directory "$RUNNER_TEMP/pages" & + server=$! + trap 'kill "$server"' EXIT + curl -fsS --retry 5 --retry-connrefused http://127.0.0.1:8780/OpenDirector/ -o /dev/null + node website/site.test.mjs + - if: github.repository == 'ThinkFlowLab/OpenDirector' && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 + with: + path: ${{ runner.temp }}/pages/OpenDirector + + deploy: + if: github.repository == 'ThinkFlowLab/OpenDirector' && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + needs: build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy GitHub Pages + id: deployment + uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/docs/README.md b/docs/README.md index 310bb3cd..3c224ce6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,6 +18,7 @@ This directory is the entry point for the repository's shared documentation. The | [Issue #87 Windows handoff](development/issue-87-windows-handoff.md) ([中文](development/issue-87-windows-handoff.zh-CN.md)) | Native ACL repair and final text acceptance | The shared checkpoint or native validation scope changes | | [Development lessons](development/lessons.md) | Risks identified from recent fixes | New evidence emerges or a lesson no longer applies | | [CI failure patterns](development/ci-failures.md) | Known timing-sensitive CI failures and how to tell flakes from regressions | A pattern is fixed, newly observed, or the watchlist changes | +| [Public website](../website/README.md) | Local preview, installer links, and GitHub Pages deployment | Website deployment or installer publishing changes | | [Release tags and daily cuts](development/release.md) | Public SemVer tags and the daily patch cut | The tag scheme, daily cut gate, or version-field set changes | | [UI performance design](development/ui-performance.md) | Interaction design principles, latency budgets, and measurement | A UI performance principle, target, or measurement method changes | | [macOS installation validation](development/macos-install-validation.md) | Installation and usage scenarios verified on Apple Silicon | The corresponding acceptance checks are repeated | diff --git a/docs/development/website-evidence/download-en-US.png b/docs/development/website-evidence/download-en-US.png new file mode 100644 index 00000000..154cb2d1 Binary files /dev/null and b/docs/development/website-evidence/download-en-US.png differ diff --git a/docs/development/website-evidence/download-zh-CN.png b/docs/development/website-evidence/download-zh-CN.png new file mode 100644 index 00000000..797d974b Binary files /dev/null and b/docs/development/website-evidence/download-zh-CN.png differ diff --git a/scripts/build-website.sh b/scripts/build-website.sh new file mode 100644 index 00000000..ebcb2f1a --- /dev/null +++ b/scripts/build-website.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +output=${1:?Usage: bash scripts/build-website.sh OUTPUT_DIRECTORY} +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +node --check "$root/website/site.mjs" +node --check "$root/website/ambient.mjs" +mkdir -p "$output" +node "$root/website/build.mjs" "$output/index.html" +cp "$root"/website/{site.css,showcase.css,ambient.mjs,site.mjs,logo.png} "$output/" +cp "$root/docs/guides/assets/dota2-short-film-canvas.jpg" "$output/canvas.jpg" +mkdir -p "$output/film" +cp "$root"/website/film/*.jpg "$output/film/" +cp "$root/website/film/office-preview.mp4" "$output/film/" +cp "$root/docs/guides/assets/dota2-short-film.mp4" "$output/film/we-can-still-win.mp4" diff --git a/website/README.md b/website/README.md new file mode 100644 index 00000000..59dedf83 --- /dev/null +++ b/website/README.md @@ -0,0 +1,55 @@ +# OpenDirector website + +[中文](#中文) + +## Preview + +Run these commands from the repository root. The build reads public GitHub Releases and needs network access. Run `npm ci` first if Vite is missing. + +```sh +preview=$(mktemp -d) +bash scripts/build-website.sh "$preview/dist/OpenDirector" +node_modules/.bin/vite preview "$preview" --host 127.0.0.1 --port 8780 --strictPort +``` + +Open . Vite supports the byte-range requests the player uses to jump to a shot. + +## Set up GitHub Pages + +1. In `ThinkFlowLab/OpenDirector`, a repository maintainer or admin opens **Settings > Pages**. Under **Build and deployment**, set **Source** to **GitHub Actions**. The repository supplies the [Website workflow](../.github/workflows/website.yml) and its deployment permissions. It uses GitHub's built-in token. +2. Merge the website changes into `main`. The Website workflow builds the site and runs its Chromium checks. When they pass, the workflow deploys to the `github-pages` environment. Pull requests run the checks only. To deploy the current `main` manually, open **Actions > Website > Run workflow**, select `main`, and click **Run workflow**. +3. Open the URL in the successful `deploy` job. The default address is . Switch languages and check that each download points to the expected Release asset. To roll back a site change, revert it on `main`. + +## Publish a desktop release + +1. Follow the [release guide](../docs/development/release.md). Check that Release checks and the latest nightly `gate-parity` passed. After the version-bump PR merges, push a new `vMAJOR.MINOR.PATCH` tag on that merge commit to the official repository. The tag must match the version in `apps/desktop/package.json`. +2. The [Desktop release workflow](../.github/workflows/desktop-release.yml) creates or reuses a draft for that tag. macOS and Windows each build and test their installer, then attach it and its `.sha256` file to the draft. For a release that ships both platforms, expect an Apple Silicon DMG, a Windows x64 EXE, and two checksum files. +3. Complete the [desktop acceptance checks](../docs/development/desktop.md#delivery-boundary) for each platform you plan to publish. In **Releases**, open the draft, verify its assets, review the English release notes, and click **Publish release**. Retry failed packaging jobs while the release is still a draft. +4. Publishing the release triggers a Website build on `main`. For each platform, the build selects the highest official version with an uploaded installer for that architecture. The download URL, version label and release notes come from that release. If you add an installer after publication, run **Actions > Website > Run workflow** on `main` to refresh the site. + +A Windows-only release updates the Windows download. Mac users keep the latest available Mac package. Until a platform has an official installer, its download points to the [tested desktop preview](https://github.com/FayeSpica/OpenDirector/releases/tag/v0.1.4-desktop-test.23) and carries a test-build label. If the GitHub API request fails, the build stops and the previous deployment stays online. + +OpenDirector includes the version in each installer filename. GitHub's `releases/latest/download/` looks for that exact file in the repository's latest release. Resolving the assets at build time keeps both downloads usable even when they come from different tags. Updating an installed desktop app is tracked in [#367](https://github.com/ThinkFlowLab/OpenDirector/issues/367). + +## 中文 + +### 本地预览 + +在仓库根目录运行上面的命令。构建时需要联网读取公开的 GitHub Releases。如果缺少 Vite,先运行 `npm ci`。打开 。Vite 支持分段读取视频,可以直接跳到所选镜头。 + +### 首次配置 GitHub Pages + +1. 具有 Maintain 或 Admin 权限的维护者打开官方仓库 `ThinkFlowLab/OpenDirector` 的 **Settings > Pages**,在 **Build and deployment** 中将 **Source** 设为 **GitHub Actions**。仓库提供了 [Website 工作流](../.github/workflows/website.yml),其中已声明部署权限,使用 GitHub 内置令牌。 +2. 将网站改动合入 `main`。Website 会构建网站并运行 Chromium 检查,通过后部署到 `github-pages` 环境。PR 只运行检查。需要手动部署时,打开 **Actions > Website > Run workflow**,选择 `main`,点击 **Run workflow**。 +3. 打开成功的 `deploy` 任务给出的网址,默认地址是 。切换语言,确认两个平台的下载链接指向预期的 Release 附件。如需回退网站,在 `main` 撤销对应改动。 + +### 发布桌面版 + +1. 按[版本发布指南](../docs/development/release.md)确认 Release checks 和最近一次 nightly 的 `gate-parity` 均已通过。版本号 PR 合入 `main` 后,在该合入提交上打新的 `vMAJOR.MINOR.PATCH` 标签并推到官方仓库。标签中的版本号须与 `apps/desktop/package.json` 一致。 +2. [Desktop release 工作流](../.github/workflows/desktop-release.yml)会为该标签创建或复用 Release 草稿。macOS 和 Windows 各自打包,通过本机安装和启动检查后,把安装包和对应的 `.sha256` 文件上传到同一份草稿。两个平台都发布时,草稿应包含 Apple Silicon DMG、Windows x64 EXE 和两份校验文件。 +3. 维护者在各发布平台完成[桌面版验收](../docs/development/desktop.zh-CN.md),再到 **Releases** 打开草稿,核对附件和英文发布说明,点击 **Publish release**。如果打包任务失败,在草稿状态下重跑。 +4. 公开 Release 后,Website 会在 `main` 上重新构建。对每个平台,构建脚本选取包含对应架构安装包的最高正式版本,并从该 Release 读取下载地址、版本号和发布说明。如果在公开后补传了安装包,到 **Actions > Website > Run workflow** 选择 `main` 刷新网站即可。 + +如果本次只发 Windows 包,Windows 下载会更新,Mac 用户仍能下载已有的最新 Mac 包。某个平台首次发布正式安装包前,网站提供[已验证的桌面测试版](https://github.com/FayeSpica/OpenDirector/releases/tag/v0.1.4-desktop-test.23),并标明「测试版」。如果请求 GitHub API 失败,本次构建停止,线上继续使用上一次成功部署的页面。 + +OpenDirector 的安装包文件名含版本号。GitHub 的 `releases/latest/download/<文件名>` 只在仓库最新 Release 中查找该文件。构建时按平台查找附件,即使两个安装包来自不同标签,也能给出各自的下载地址。已安装桌面应用的升级由 [#367](https://github.com/ThinkFlowLab/OpenDirector/issues/367) 跟进。 diff --git a/website/ambient.mjs b/website/ambient.mjs new file mode 100644 index 00000000..c2f3c76f --- /dev/null +++ b/website/ambient.mjs @@ -0,0 +1,116 @@ +const vertexSource = ` + attribute vec2 position; + varying vec2 uv; + void main() { + uv = vec2(position.x, -position.y) * .5 + .5; + gl_Position = vec4(position, 0., 1.); + }`; + +const fragmentSource = ` + precision highp float; + varying vec2 uv; + uniform float phase; + + float glow(vec2 p, vec2 center, vec2 radius) { + vec2 d = (p - center) / radius; + return exp(-dot(d, d)); + } + + float grain(vec2 p) { + return fract(52.9829189 * fract(dot(p, vec2(.06711056, .00583715)))); + } + + float diffusion(vec2 p) { + vec2 cell = floor(p); + vec2 t = smoothstep(vec2(0.), vec2(1.), fract(p)); + return mix(mix(grain(cell), grain(cell + vec2(1., 0.)), t.x), + mix(grain(cell + vec2(0., 1.)), grain(cell + 1.), t.x), t.y); + } + + void main() { + vec2 p = uv; + vec2 drift = vec2(cos(phase), sin(phase)); + p.y += .11 * sin(5.8 * uv.x - 1.2 + .32 * sin(phase)) + + .045 * sin(11. * uv.x + 2. * uv.y + .7 * cos(phase)) + + .075 * (diffusion(uv * vec2(9., 4.) + .5 * drift) - .5); + p.x += .036 * sin(6. * uv.y + phase); + vec3 light = vec3(.042, .069, .12); + light += glow(p, vec2(.54, .17), vec2(.76, .42)) * vec3(.059, .124, .226); + light += glow(p, vec2(.80, .22), vec2(.43, .32)) * vec3(.072, .081, .125); + light += glow(p, vec2(.78, -.025), vec2(.37, .135)) * vec3(.28, .28, .285); + light += glow(p, vec2(.045, .19), vec2(.27, .19)) * vec3(.105, .057, .129); + light += glow(p, vec2(.018, .15), vec2(.21, .065)) * vec3(.071, .049, .045); + light += glow(p, vec2(.96, .49), vec2(.40, .24)) * vec3(.051, .063, .092); + light += (grain(gl_FragCoord.xy) - .5) / 255.; + gl_FragColor = vec4(light, 1.); + }`; + +function paintAmbientLight(canvas) { + const gl = canvas.getContext("webgl", { + alpha: false, antialias: false, depth: false, stencil: false, powerPreference: "low-power", + }); + if (!gl) return; + + const program = gl.createProgram(); + for (const [type, source] of [[gl.VERTEX_SHADER, vertexSource], [gl.FRAGMENT_SHADER, fragmentSource]]) { + const shader = gl.createShader(type); + gl.shaderSource(shader, source); + gl.compileShader(shader); + gl.attachShader(program, shader); + gl.deleteShader(shader); + } + gl.linkProgram(program); + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return; + gl.useProgram(program); + const buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW); + const position = gl.getAttribLocation(program, "position"); + gl.enableVertexAttribArray(position); + gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0); + const phase = gl.getUniformLocation(program, "phase"); + const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)"); + let visible = false; + let timer; + let elapsed = 0; + let previousTime; + + function draw() { + const now = performance.now(); + if (previousTime !== undefined) elapsed += now - previousTime; + previousTime = now; + gl.uniform1f(phase, (elapsed / 16000) % (2 * Math.PI)); + gl.drawArrays(gl.TRIANGLES, 0, 3); + } + + function refresh() { + clearInterval(timer); + previousTime = undefined; + if (!visible || document.hidden || gl.isContextLost()) return; + // The soft gradients can use a smaller buffer than the displayed canvas. + const width = Math.max(1, Math.min(640, Math.ceil(canvas.clientWidth / 3))); + const height = Math.max(1, Math.min(460, Math.ceil(canvas.clientHeight / 3))); + if (canvas.width !== width || canvas.height !== height) { + canvas.width = width; + canvas.height = height; + gl.viewport(0, 0, width, height); + } + draw(); + canvas.classList.add("painted"); + if (!reducedMotion.matches) timer = setInterval(draw, 1000 / 24); + } + + new IntersectionObserver(([entry]) => { + visible = entry.isIntersecting; + refresh(); + }).observe(canvas); + new ResizeObserver(refresh).observe(canvas); + reducedMotion.addEventListener("change", refresh); + document.addEventListener("visibilitychange", refresh); + canvas.addEventListener("webglcontextlost", () => { + clearInterval(timer); + canvas.classList.remove("painted"); + }); +} + +paintAmbientLight(document.querySelector(".hero-light canvas")); diff --git a/website/build.mjs b/website/build.mjs new file mode 100644 index 00000000..7f8acc28 --- /dev/null +++ b/website/build.mjs @@ -0,0 +1,41 @@ +import { readFile, writeFile } from "node:fs/promises"; +import { resolveInstallers } from "./installers.mjs"; + +function escapeHtml(value) { + return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<"); +} + +export function renderDownloadPage(template, installers) { + const options = []; + const notes = new Map(); + for (const [system, label, format] of [["mac", "macOS (Apple silicon)", "DMG"], ["windows", "Windows (x64)", "EXE"]]) { + const name = `${label}`; + const installer = installers[system]; + if (!installer) { + options.push(`
  • ${name}Installer unavailable
  • `); + continue; + } + const test = installer.test ? ' · Test build' : ""; + options.push(`
  • ${name}${escapeHtml(installer.version)} · ${format}${test}
  • `); + notes.set(installer.notes, system); + } + + const releaseNotes = []; + for (const [url, system] of notes) { + const platform = system === "mac" ? "macOS" : "Windows"; + const label = notes.size === 1 ? "Release notes" : `${platform} release notes`; + const key = notes.size === 1 ? "notes" : `${system}Notes`; + releaseNotes.push(`${label}`); + } + return template + .replace("{{primary-hidden}}", notes.size ? "hidden" : "") + .replace("{{menu-hidden}}", notes.size ? "" : "hidden") + .replace("{{desktop-options}}", () => options.join("\n")) + .replace("{{desktop-notes}}", () => releaseNotes.join("\n")); +} + +if (import.meta.main) { + const template = await readFile(new URL("index.html", import.meta.url), "utf8"); + const installers = await resolveInstallers(); + await writeFile(process.argv[2], renderDownloadPage(template, installers)); +} diff --git a/website/film/office-preview.mp4 b/website/film/office-preview.mp4 new file mode 100644 index 00000000..884d855a Binary files /dev/null and b/website/film/office-preview.mp4 differ diff --git a/website/film/poster.jpg b/website/film/poster.jpg new file mode 100644 index 00000000..9b712369 Binary files /dev/null and b/website/film/poster.jpg differ diff --git a/website/film/shot-0.jpg b/website/film/shot-0.jpg new file mode 100644 index 00000000..c569e399 Binary files /dev/null and b/website/film/shot-0.jpg differ diff --git a/website/film/shot-1.jpg b/website/film/shot-1.jpg new file mode 100644 index 00000000..98af0958 Binary files /dev/null and b/website/film/shot-1.jpg differ diff --git a/website/film/shot-2.jpg b/website/film/shot-2.jpg new file mode 100644 index 00000000..1df02d06 Binary files /dev/null and b/website/film/shot-2.jpg differ diff --git a/website/film/shot-3.jpg b/website/film/shot-3.jpg new file mode 100644 index 00000000..680ac7ed Binary files /dev/null and b/website/film/shot-3.jpg differ diff --git a/website/film/shot-4.jpg b/website/film/shot-4.jpg new file mode 100644 index 00000000..33e3c17b Binary files /dev/null and b/website/film/shot-4.jpg differ diff --git a/website/film/shot-5.jpg b/website/film/shot-5.jpg new file mode 100644 index 00000000..e7614965 Binary files /dev/null and b/website/film/shot-5.jpg differ diff --git a/website/index.html b/website/index.html new file mode 100644 index 00000000..8a0025f3 --- /dev/null +++ b/website/index.html @@ -0,0 +1,133 @@ + + + + + + + Download OpenDirector + + + + + + + +
    + OpenDirector + +
    +
    +
    + +
    +

    OpenDirector

    +

    An open-source AI video studio

    +

    Generate shots with AI on the canvas, edit them on the timeline and export your film.

    +
    + Source installation +
    + Download OpenDirector +
    +
      {{desktop-options}}
    +
    +
    +
    +
    +
    +
    + The script, six shots and timeline for We Can Still Win on the OpenDirector canvas +
    + + +
    +
    Project canvas · We Can Still Win + Watch the short film +
    +
    +
    +
    +
    +

    We Can Still Win

    +

    Six shots follow a Dota 2 player and his former teammates.

    +
    +
    +
    + +
    Final cut01:00 · 720p · 24 fps
    +
    +
    +

    Jump to a shot

    +
    + + + + + + +
    +
    +
    +
    +
    +

    Other ways to install

    +
    +
    +

    Install with AI

    +

    Paste this prompt into your AI assistant.

    +
    + Install and start OpenDirector for me by following this skill: https://github.com/ThinkFlowLab/OpenDirector/blob/main/.agents/skills/install-opendirector/SKILL.md + +
    +
    +
    +

    Source installation

    +

    Clone the repository, then follow the guide for your operating system.

    +
    + git clone https://github.com/ThinkFlowLab/OpenDirector.git + +
    + Installation guide +
    +
    +
    +
    + + + diff --git a/website/installers.mjs b/website/installers.mjs new file mode 100644 index 00000000..f3cb9d4c --- /dev/null +++ b/website/installers.mjs @@ -0,0 +1,74 @@ +const officialRepository = "ThinkFlowLab/OpenDirector"; +const testRepository = "FayeSpica/OpenDirector"; +const testTag = "v0.1.4-desktop-test.23"; +const stableTag = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; +const versionOrder = new Intl.Collator("en", { numeric: true }); +const packageSuffixes = { + mac: "mac-arm64-adhoc.dmg", + windows: "win-x64-unsigned.exe", +}; + +function releaseUrl(value, repository, kind) { + const url = new URL(value); + if (url.origin !== "https://github.com" || !url.pathname.startsWith(`/${repository}/releases/${kind}/`)) { + throw new Error(`Unexpected GitHub ${kind} URL for ${repository}: ${url.href}`); + } + return url.href; +} + +function addInstallers(installers, release, repository, test) { + const version = release.tag_name.split("-")[0]; + for (const [system, suffix] of Object.entries(packageSuffixes)) { + if (installers[system]) continue; + const filename = `OpenDirector-${version}-${suffix}`; + const asset = release.assets.find(item => + item.name === filename && item.state === "uploaded" && item.size > 0 + ); + if (asset) { + installers[system] = { + url: releaseUrl(asset.browser_download_url, repository, "download"), + notes: releaseUrl(release.html_url, repository, "tag"), + version: release.tag_name, + test, + }; + } + } +} + +export async function resolveInstallers(fetchImpl = fetch) { + const headers = { Accept: "application/vnd.github+json" }; + if (process.env.GITHUB_TOKEN) headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`; + + async function request(path) { + const response = await fetchImpl(`https://api.github.com/repos/${path}`, { + headers, + signal: AbortSignal.timeout(30_000), + }); + if (!response.ok) throw new Error(`GitHub Releases request failed (${response.status}): ${path}`); + return response; + } + + const releases = []; + for (let page = 1; ; page++) { + const response = await request(`${officialRepository}/releases?per_page=100&page=${page}`); + const entries = await response.json(); + releases.push(...entries.filter(release => + release.draft === false && release.prerelease === false && stableTag.test(release.tag_name) + )); + if (!response.headers.get("link")?.includes('rel="next"')) break; + } + releases.sort((a, b) => versionOrder.compare(b.tag_name, a.tag_name)); + + const installers = {}; + for (const release of releases) { + addInstallers(installers, release, officialRepository, false); + if (installers.mac && installers.windows) return installers; + } + + const response = await request(`${testRepository}/releases/tags/${testTag}`); + const release = await response.json(); + if (release.tag_name === testTag && release.draft === false) { + addInstallers(installers, release, testRepository, true); + } + return installers; +} diff --git a/website/installers.test.mjs b/website/installers.test.mjs new file mode 100644 index 00000000..784563ad --- /dev/null +++ b/website/installers.test.mjs @@ -0,0 +1,96 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { resolveInstallers } from "./installers.mjs"; + +const official = "ThinkFlowLab/OpenDirector"; +const fork = "FayeSpica/OpenDirector"; +const testTag = "v0.1.4-desktop-test.23"; +const mac = "mac-arm64-adhoc.dmg"; +const windows = "win-x64-unsigned.exe"; + +function release(tag, packages, repository = official) { + const base = `https://github.com/${repository}/releases`; + return { + tag_name: tag, + draft: false, + prerelease: repository === fork, + html_url: `${base}/tag/${tag}`, + assets: packages.map(suffix => { + const name = `OpenDirector-${tag.split("-")[0]}-${suffix}`; + return { name, state: "uploaded", size: 42, browser_download_url: `${base}/download/${tag}/${name}?id=42` }; + }), + }; +} + +function github(...routes) { + return async url => { + const { pathname, search } = new URL(url); + const [path, response] = routes.shift() ?? []; + assert.equal(pathname + search, `/repos/${path}`, `unexpected request: ${url}`); + return response; + }; +} + +const firstPage = `${official}/releases?per_page=100&page=1`; +const secondPage = `${official}/releases?per_page=100&page=2`; +const fallback = `${fork}/releases/tags/${testTag}`; +const nextPage = { headers: { Link: `; rel="next"` } }; + +test("selects the highest published stable version independently for each platform across pages", async () => { + const both = release("v1.9.9", [mac, windows]); + const winOnly = release("v1.10.0", [windows, "mac-x64-adhoc.dmg", `${mac}.sha256`]); + const entries = [ + { ...release("v2.0.0", [mac, windows]), draft: true }, + { ...release("v3.0.0", [mac, windows]), prerelease: true }, + release("v4.0.0-rc.1", [mac, windows]), + release("v2.00.0", [mac, windows]), + release("v1.11.0", []), + both, + ]; + const installers = await resolveInstallers(github( + [firstPage, Response.json(entries, nextPage)], + [secondPage, Response.json([winOnly])], + )); + assert.deepEqual(installers, { + mac: { url: both.assets[0].browser_download_url, notes: both.html_url, version: "v1.9.9", test: false }, + windows: { url: winOnly.assets[0].browser_download_url, notes: winOnly.html_url, version: "v1.10.0", test: false }, + }); +}); + +test("uses only the pinned public test release for a platform with no official installer", async () => { + const winOnly = release("v1.0.0", [windows, mac, mac, mac]); + winOnly.assets[1].state = "starter"; + winOnly.assets[2].size = 0; + winOnly.assets[3].name = `OpenDirector-v0.9.0-${mac}`; + const preview = release(testTag, [mac, windows], fork); + const installers = await resolveInstallers(github( + [firstPage, Response.json([winOnly])], + [fallback, Response.json(preview)], + )); + assert.deepEqual(installers.mac, { url: preview.assets[0].browser_download_url, notes: preview.html_url, version: testTag, test: true }); + assert.equal(installers.windows.url, winOnly.assets[0].browser_download_url); +}); + +test("omits assets unavailable from both the official and pinned public release", async () => { + const preview = release(testTag, [mac], fork); + const resolve = candidate => resolveInstallers(github([firstPage, Response.json([])], [fallback, Response.json(candidate)])); + assert.deepEqual(Object.keys(await resolve(preview)), ["mac"]); + assert.deepEqual(await resolve({ ...preview, draft: true }), {}); +}); + +test("fails the build if a release API page or fallback request fails", async () => { + await assert.rejects(resolveInstallers(github( + [firstPage, Response.json([release("v1.0.0", [mac, windows])], nextPage)], + [secondPage, new Response(null, { status: 403 })], + )), /GitHub Releases request failed \(403\)/); + await assert.rejects(resolveInstallers(github( + [firstPage, Response.json([])], [fallback, new Response(null, { status: 503 })], + )), /GitHub Releases request failed \(503\)/); + await assert.rejects(resolveInstallers(async () => { throw new Error("network timeout"); }), /network timeout/); +}); + +test("rejects an installer URL outside its source repository", async () => { + const candidate = release("v1.0.0", [mac, windows]); + candidate.assets[0].browser_download_url = "https://example.org/unexpected.dmg"; + await assert.rejects(resolveInstallers(github([firstPage, Response.json([candidate])])), /Unexpected GitHub download URL/); +}); diff --git a/website/logo.png b/website/logo.png new file mode 100644 index 00000000..357d7c0f Binary files /dev/null and b/website/logo.png differ diff --git a/website/showcase.css b/website/showcase.css new file mode 100644 index 00000000..7887ab4c --- /dev/null +++ b/website/showcase.css @@ -0,0 +1,258 @@ +.canvas-shots a[aria-current="true"] { + box-shadow: 0 0 0 2px #a6c5ff, 0 0 0 4px #90b5ff18; +} + +/* Place these layers over the timeline and output nodes of the project canvas. */ +.canvas-timeline, .canvas-output { + position: absolute; + pointer-events: none; +} + +.canvas-timeline { + inset: 82.65% 39.85% auto 31.72%; + height: 1.5%; + display: flex; + opacity: 0; +} +.canvas-timeline[data-active] { opacity: 1; } +.canvas-timeline i { + position: relative; + width: calc(100% / 6); + height: 100%; + margin-inline-start: calc(var(--shot-index, 0) * 100% / 6); + border-radius: 2px; + box-shadow: inset 0 0 0 1px #dcebff; + background: #96baf1; +} +.canvas-timeline i::before { + content: ""; + position: absolute; + left: 0; + bottom: -300%; + height: 440%; + border-left: 1px solid #dcebff; +} + +.canvas-output { + inset: 67.50% 7.68% auto 64.60%; + aspect-ratio: 16 / 9; + overflow: hidden; + border-radius: 3px; + /* Keep the canvas controls overlapping the lower right corner visible. */ + clip-path: polygon(0 0, 100% 0, 100% 87.5%, 80% 87.5%, 80% 100%, 0 100%); +} +.canvas-output :is(img, video) { + display: block; + width: 100%; + height: 100%; + object-fit: cover; + border: 0; + border-radius: 0; + box-shadow: none; +} +@media (prefers-reduced-motion: no-preference) { + .canvas-shots a { transition: box-shadow 180ms ease-out; } + .canvas-timeline { transition: opacity 180ms ease-out; } + .canvas-output video:not([hidden]) { animation: reveal-shot 180ms ease-out; } +} +@keyframes reveal-shot { + from { opacity: 0; } + to { opacity: 1; } +} + +.workflow.shell, +.install.shell { + padding-block: clamp(64px, 9vw, 136px); +} + +.workflow { + scroll-margin-top: 52px; +} + +.workflow h2, +.install h2 { + margin: 0; + font-size: clamp(1.8rem, 3vw, 2.35rem); + font-weight: 450; + line-height: 1.2; + letter-spacing: -.035em; +} + +.film-heading { + max-width: 38rem; + margin: 0 auto clamp(32px, 5vw, 64px); + text-align: center; +} + +.film-heading p, +.install-methods p { + color: var(--muted); + font-size: 1rem; + line-height: 1.65; + text-wrap: pretty; +} + +.film-heading p { + margin: 16px auto 0; +} + +.screening { + display: grid; + grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); + gap: clamp(18px, 3vw, 40px); + align-items: center; +} + +.film-player video { + display: block; + width: 100%; + height: auto; + aspect-ratio: 16 / 9; + background: black; + border-radius: 10px; +} + +.film-spec { + display: flex; + justify-content: space-between; + align-items: baseline; + margin-block-start: 11px; + color: var(--muted); + font-size: .82rem; + font-variant-numeric: tabular-nums; +} + +.shot-board h3, +.install-methods h3 { + margin: 0; + font-size: 1.2rem; + line-height: 1.4; + font-weight: 500; +} + +.shots { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 16px 10px; + margin-block-start: 20px; +} + +.film-shot { + min-width: 0; + padding: 0; + border: none; + background: transparent; + text-align: start; + color: var(--muted); +} + +.film-shot img { + display: block; + width: 100%; + height: auto; + aspect-ratio: 16 / 9; + object-fit: cover; + border-radius: 5px; + opacity: .72; +} + +.film-shot[aria-pressed="true"], +.film-shot:hover, +.film-shot:focus-visible { + color: white; +} + +.film-shot[aria-pressed="true"] img, +.film-shot:hover img, +.film-shot:focus-visible img { + opacity: 1; +} + +.film-shot[aria-pressed="true"] img { + outline: 1px solid #ebdfc7; + outline-offset: 2px; +} + +.shot-caption { + display: block; + margin-block-start: 6px; + font-size: .82rem; + line-height: 1.4; +} + +.shot-caption time { + display: block; + font-size: .75rem; + color: #a7a5a1; + font-variant-numeric: tabular-nums; +} + +.install-methods { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 20px; + margin-block-start: clamp(26px, 4vw, 48px); +} + +.install-methods article { + padding: clamp(20px, 3vw, 38px); + border: 1px solid #ffffff18; + border-radius: 16px; + background: #161617; +} + +.install-methods p { + margin: 10px 0 20px; +} + +.install-snippet { + display: flex; + gap: .75rem; + align-items: start; + padding: 12px; + border: 1px solid #ffffff12; + background: #212122; + border-radius: 8px; +} + +.install-snippet code { + flex: 1; + min-width: 0; + color: #dfdfe2; + font: .82rem/1.6 ui-monospace, "SFMono-Regular", Consolas, monospace; + overflow-wrap: anywhere; + user-select: all; +} + +.install-snippet button { + border: 0; + border-radius: 4px; + padding: 4px; + background: transparent; + color: #c4c3c2; + font-size: .8rem; +} + +.install-snippet button:hover { + background: #ffffff12; + color: white; +} + +.install-methods a { + display: inline-block; + margin-block-start: 14px; + color: var(--muted); + font-size: .875rem; + text-underline-offset: .23em; +} + +@media (max-width: 900px) { + .screening { grid-template-columns: 1fr; } + .shots { grid-template-columns: repeat(6, minmax(0, 1fr)); } +} + +@media (max-width: 650px) { + .shots { grid-template-columns: repeat(3, minmax(0, 1fr)); } + .install-methods { grid-template-columns: 1fr; } + .film-heading { text-align: start; } +} diff --git a/website/site.css b/website/site.css new file mode 100644 index 00000000..f8d042c2 --- /dev/null +++ b/website/site.css @@ -0,0 +1,266 @@ +:root { + color-scheme: dark; + font-family: "Helvetica Neue", "PingFang SC", "Microsoft YaHei", Arial, sans-serif; + -webkit-font-smoothing: antialiased; + background: #0c0e11; + color: #f4f5f7; + --muted: #adb3be; + --line: #ffffff26; +} +*, *::before, *::after { box-sizing: border-box; } +body, figure, h1, p { margin: 0; } +body { min-height: 100vh; } +button, summary { cursor: pointer; font: inherit; } +a { color: inherit; text-underline-offset: .22em; } +:focus-visible { outline: 2px solid #a9d9ff; outline-offset: 4px; } +[hidden] { display: none !important; } +.shell { width: min(1140px, calc(100% - 64px)); margin-inline: auto; } + +.brand, .languages, .actions, .scroll-actions, .footer { display: flex; align-items: center; } +.top { + --compact-width: 980px; + position: fixed; + z-index: 10; + inset: 8px 0 auto; + width: calc(100% - 48px); + max-width: 1280px; + margin-inline: auto; + display: flex; + justify-content: space-between; + align-items: center; + height: 42px; + padding-inline: 0; + border-radius: 24px; + isolation: isolate; + transition: max-width 550ms cubic-bezier(.2,.8,.25,1), padding 500ms cubic-bezier(.2,.8,.25,1); +} +@media (min-width: 1560px) { .top { --compact-width: 1180px; } } +.top::before { + content: ""; + position: absolute; + inset: 0; + z-index: -1; + pointer-events: none; + border: 1px solid #ffffff20; + border-radius: inherit; + background: #56585d; + opacity: 0; + transition: opacity 400ms ease; +} +@supports ((backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px))) { + .top::before { + background: rgb(156 158 164 / 46%); + -webkit-backdrop-filter: blur(12px); + backdrop-filter: blur(12px); + } +} +.top.is-scrolled { max-width: var(--compact-width); padding-inline: 16px 7px; } +.top.is-scrolled::before { opacity: 1; } +.brand { gap: 8px; color: white; font-size: 1.03rem; font-weight: 600; letter-spacing: -.025em; text-decoration: none; } +.brand img { width: 26px; height: 26px; border-radius: 6px; } +.nav { display: grid; justify-items: end; align-items: center; } +.nav > * { grid-area: 1/1; transition: opacity 240ms ease, visibility 240ms; } +.scroll-actions, .is-scrolled .languages { opacity: 0; visibility: hidden; pointer-events: none; } +.is-scrolled .scroll-actions { opacity: 1; visibility: visible; pointer-events: auto; } +.scroll-actions { gap: 12px; } +.languages { padding: 2px; border-radius: 20px; background: #ffffff07; border: 1px solid #ffffff30; } +.languages button { min-height: 25px; min-width: 39px; border: 0; border-radius: 14px; background: none; color: #c7ced9; font-size: .77rem; } +.languages [aria-pressed="true"] { background: #ffffff35; color: white; } + +.opening { + isolation: isolate; + position: relative; + overflow: clip; + padding: 68px 0 52px; + view-timeline: --opening block; +} +.hero-light { + position: absolute; + inset: 0; + z-index: -1; + pointer-events: none; + background: + radial-gradient(ellipse 40% 27% at 82% -4%, #9a9ba8aa, transparent), + radial-gradient(ellipse 36% 30% at 0% 24%, #5b466c8c, transparent), + radial-gradient(ellipse 76% 62% at 68% 21%, #354c72, #1e3555 60%, transparent), + #101b2d; + mask-image: linear-gradient(#000 0%, #000 25%, #000d 53%, #0006 78%, transparent 100%); +} +.hero-light canvas { + display: block; + width: 100%; + height: 100%; + opacity: 0; +} +.hero-light canvas.painted { opacity: 1; } +.hero { + position: relative; + z-index: 2; + text-align: center; + padding-block: clamp(96px, 8.8vw, 136px) clamp(44px, 4.2vw, 60px); +} +h1, .tagline { + font-size: clamp(2rem, 3.1vw, 2.5rem); + font-weight: 400; + line-height: 1.42; + letter-spacing: -.035em; +} +.tagline { margin-top: 1px; letter-spacing: -.025em; text-wrap: balance; } +.intro { max-width: 38rem; margin: 25px auto 34px; color: #c0c8d7; font-size: 1rem; font-weight: 400; line-height: 1.8; text-wrap: balance; } + +.actions { + position: relative; + z-index: 3; + justify-content: center; + width: max-content; + max-width: 100%; + margin-inline: auto; +} +.primary, .nav-github { + display: inline-flex; + justify-content: center; + align-items: center; + gap: 7px; + white-space: nowrap; + text-decoration: none; + font-weight: 500; +} +.primary { + min-height: 42px; + padding: 0 17px; + border-radius: 23px; + background: #fafafa; + color: #151619; + font-size: .9375rem; + transition: background-color .15s; +} +.primary:is(:hover, :focus-visible) { background: #e9e9ec; } +.actions > a.primary::before, .actions > a.primary[hidden] + details summary::before { + content: ""; + width: 16px; + height: 16px; + flex: none; + background: currentColor; + mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 1.5v8.4m-3-3 3 3 3-3M2 11v2a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-2'/%3E%3C/svg%3E") center / contain no-repeat; +} +.actions summary { list-style: none; } +.actions summary::-webkit-details-marker { display: none; } +.actions summary::after { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); } +.actions > a.primary:has(+ details:not([hidden])) { border-radius: 23px 0 0 23px; } +.actions > a.primary:not([hidden]) + details summary { position: relative; border-radius: 0 23px 23px 0; padding-inline: 15px; } +.actions > a.primary:not([hidden]) + details summary::before { content: ""; position: absolute; left: 0; width: 1px; height: 45%; background: #18181b23; } +.actions > a.primary:not([hidden]) + details summary span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } +.download-panel { + color-scheme: light; + position: absolute; + top: calc(100% + 8px); + right: 0; + width: max-content; + min-width: max(100%, 192px); + max-width: calc(100vw - 32px); + padding: 4px; + text-align: start; + color: #17181b; + background: #fff; + border-radius: 12px; + box-shadow: 0 8px 26px #0003; + transform-origin: top center; +} +details[open] .download-panel { animation: download-in 350ms cubic-bezier(.19,1,.22,1) both; } +@keyframes download-in { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } } +.download-panel ul { margin: 0; padding: 0; list-style: none; } +.download-panel li > * { display: block; border-radius: 8px; padding: 8px 10px; font-size: .9375rem; line-height: 1.4; text-decoration: none; } +.download-panel small { display: block; margin-top: 2px; color: #646b76; font-size: .75rem; } +.download-panel a:is(:hover, :focus-visible) { background: #f1f2f4; } +.download-panel a:focus-visible { outline-color: #3568ac; outline-offset: -2px; } +.nav-github, .scroll-actions .primary { min-height: 31px; padding-inline: 11px; border-radius: 18px; font-size: .85rem; } +.nav-github { border: 1px solid #ffffff45; color: white; background: #ffffff09; } +.nav-github:is(:hover, :focus-visible) { background: #ffffff24; } +.scroll-actions .actions > a.primary:not([hidden]) + details summary { padding-inline: 11px; } +.scroll-actions .actions > a.primary::before, .scroll-actions .actions > a.primary[hidden] + details summary::before { width: 14px; height: 14px; } +@media (prefers-reduced-motion: reduce) { + .top, .top::before, .nav > *, .primary { transition: none; } + details[open] .download-panel { animation: none; } +} + +.preview { width: min(1020px, calc(100% - 56px)); } +.canvas-stage { position: relative; } +.canvas-shots { + position: absolute; + inset: 13.2% 8.6% 41.6% 30%; + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-template-rows: repeat(2, 1fr); + gap: 21% 5.5%; + pointer-events: none; +} +.canvas-shots a { + display: grid; + place-items: center; + pointer-events: auto; + border-radius: 4px; +} +.canvas-shots a:is(:hover, :focus-visible) { background: #0b142a55; outline: 2px solid #e7d8ac; } +.canvas-shots a:is(:hover, :focus-visible)::after { + content: ""; + width: 0; + height: 0; + border-block: 7px solid transparent; + border-left: 11px solid white; + filter: drop-shadow(0 1px 3px #222); +} +.canvas-image { display: block; line-height: 0; cursor: zoom-in; } +.canvas-image img { width: 100%; height: auto; display: block; border-radius: 14px; border: 1px solid #d6e0ed36; box-shadow: 0 18px 56px #05081055; } +.preview figcaption { display: flex; gap: 16px; justify-content: space-between; align-items: baseline; margin: 13px 2px 0; font-size: .85rem; color: #b1b6bf; } +.preview figcaption a { color: #e6e9ef; } + +.footer { flex-wrap: wrap; gap: 12px 24px; padding-block: 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; } +.footer span { margin-inline-end: auto; color: #eef1f4; } + +@media (max-width: 660px) { + .shell { width: calc(100% - 36px); } + .top { width: calc(100% - 20px); padding-inline: 8px; } + .top.is-scrolled { padding-inline: 12px 5px; } + .hero { padding-block: clamp(62px, 16vw, 90px) 38px; } + .preview { width: calc(100% - 28px); } + .hero-light { background-size: 150% 100%; background-position: center; } + .intro { max-width: 21rem; margin-block: 19px 24px; } + .hero .download-panel { left: 50%; right: auto; translate: -50% 0; } + .opening { padding-block: 58px 30px; } + .scroll-actions { gap: 6px; } + .nav-github { padding: 0; width: 32px; } + .nav-github span { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; } + .preview figcaption { font-size: .8rem; } +} + +@media (prefers-reduced-motion: no-preference) { + .hero h1, .hero .tagline { animation: title-arrival .9s cubic-bezier(.2,.7,.2,1) backwards; } + .hero .intro { animation: title-arrival .8s .15s ease-out backwards; } + .hero .actions { animation: soft-arrival .7s .3s ease-out backwards; } + .canvas-stage { animation: soft-arrival .8s .4s ease-out backwards; } + .hero-light canvas.painted { transition: opacity 1.8s ease-out; } + @supports (animation-timeline: --opening) { + .preview, .hero-light canvas { + animation: preview-depth linear both; + animation-timeline: --opening; + animation-range: exit-crossing 0% exit-crossing 65%; + } + .hero-light canvas { animation-name: light-depth; } + } +} +@keyframes title-arrival { + from { opacity: 0; filter: blur(8px); transform: translateY(20px); } + to { opacity: 1; filter: blur(0); transform: translateY(0); } +} +@keyframes soft-arrival { + from { opacity: 0; transform: translateY(16px); } + to { opacity: 1; transform: translateY(0); } +} +@keyframes preview-depth { + from { transform: perspective(1600px) rotateX(0) scale(1); } + to { transform: perspective(1600px) rotateX(5deg) scale(.985); } +} +@keyframes light-depth { + from { filter: blur(0); } + to { filter: blur(20px); } +} diff --git a/website/site.mjs b/website/site.mjs new file mode 100644 index 00000000..3207a813 --- /dev/null +++ b/website/site.mjs @@ -0,0 +1,356 @@ +const repository = "https://github.com/ThinkFlowLab/OpenDirector"; +const localeKey = "opendirector.website.locale"; +const messages = { + "en-US": { + shortDownload: "Download", + shortInstall: "Install", + projectCaption: "Project canvas · We Can Still Win", + fullCanvas: "Open the full-size canvas image", + filmLink: "Watch the short film", + workflow: "We Can Still Win", + filmIntro: "Six shots follow a Dota 2 player and his former teammates.", + finalCut: "Final cut", + shots: "Jump to a shot", + otherInstall: "Other ways to install", + aiBody: "Paste this prompt into your AI assistant.", + sourceBody: "Clone the repository, then follow the guide for your operating system.", + installPrompt: "Install and start OpenDirector for me by following this skill: https://github.com/ThinkFlowLab/OpenDirector/blob/main/.agents/skills/install-opendirector/SKILL.md", + copy: "Copy", + copied: "Copied", + copyManual: "Select and copy", + shot0: "At the café", + shot1: "One more game", + shot2: "Late at the office", + shot3: "The group chat", + shot4: "Bedtime", + shot5: "Back at the desk", + title: "Download OpenDirector", + navigation: "Site", + language: "Language", + headline: "An open-source AI video studio", + intro: "Generate shots with AI on the canvas, edit them on the timeline and export your film.", + downloads: "Download OpenDirector", + all: "All downloads", + chooseMac: "Choose a macOS download", + macDownload: "Download for macOS", + windowsDownload: "Download for Windows", + testBuild: "Test build", + mac: "macOS (Apple silicon)", + windows: "Windows (x64)", + unavailable: "Installer unavailable", + notes: "Release notes", + macNotes: "macOS release notes", + windowsNotes: "Windows release notes", + source: "Source installation", + guide: "Installation guide", + aiInstall: "Install with AI", + preview: "The script, six shots and timeline for We Can Still Win on the OpenDirector canvas", + }, + "zh-CN": { + shortDownload: "下载", + shortInstall: "安装", + projectCaption: "工程画布 · 我们还能赢", + fullCanvas: "打开原尺寸画布截图", + filmLink: "观看成片", + workflow: "我们还能赢", + filmIntro: "六个镜头讲述一个 Dota 2 玩家和老队友的故事。", + finalCut: "导出成片", + shots: "跳到镜头", + otherInstall: "其他安装方式", + aiBody: "复制这句话,发给你正在使用的 AI 助手。", + sourceBody: "克隆仓库,再按照对应系统的安装指南完成配置。", + installPrompt: "请按照这个 skill 帮我安装并启动 OpenDirector:https://github.com/ThinkFlowLab/OpenDirector/blob/main/.agents/skills/install-opendirector/SKILL.md", + copy: "复制", + copied: "已复制", + copyManual: "请选中复制", + shot0: "一起开黑", + shot1: "再来一局", + shot2: "加班的夜晚", + shot3: "群里的消息", + shot4: "哄孩子入睡", + shot5: "回到电脑前", + title: "下载 OpenDirector", + navigation: "站点导航", + language: "语言", + headline: "开源 AI 影像工作台", + intro: "和 AI 助手在画布上生成镜头,在时间线上剪辑,再导出影片。", + downloads: "下载 OpenDirector", + all: "所有下载", + chooseMac: "选择 macOS 安装包", + macDownload: "下载 macOS 版", + windowsDownload: "下载 Windows 版", + testBuild: "测试版", + mac: "macOS(Apple 芯片)", + windows: "Windows(x64)", + unavailable: "暂无安装包", + notes: "发布说明", + macNotes: "macOS 发布说明", + windowsNotes: "Windows 发布说明", + source: "从源码安装", + guide: "安装指南", + aiInstall: "用 AI 安装", + preview: "OpenDirector 画布上显示《我们还能赢》的剧本、六个分镜和时间线", + }, +}; + +const heroActions = document.querySelector(".hero .actions"); +const installers = new Map([...heroActions.querySelectorAll("a[data-system]")].map(link => [link.dataset.system, link.href])); + +const header = document.querySelector(".top"); +const scrollActions = header.querySelector(".scroll-actions"); +const headerActions = scrollActions.appendChild(heroActions.cloneNode(true)); +const downloadControls = [heroActions, headerActions].map((actions) => ({ + recommended: actions.querySelector("a.primary"), + downloads: actions.querySelector("details"), + summary: actions.querySelector("summary"), + compact: actions === headerActions, +})); +const languages = document.querySelectorAll("[data-lang]"); + +function readLocale() { + try { + const saved = localStorage.getItem(localeKey); + if (Object.hasOwn(messages, saved)) return saved; + } catch {} + return /^zh(?:-|$)/i.test(navigator.language) ? "zh-CN" : "en-US"; +} + +async function detectPlatform() { + const { userAgentData, userAgent } = navigator; + if (userAgentData?.mobile || /Android|iPhone|iPad|iPod/i.test(userAgent) + || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)) return {}; + const platform = userAgentData?.platform || navigator.platform; + const system = /^mac/i.test(platform) ? "mac" : /^win/i.test(platform) ? "windows" : null; + if (!system || !userAgentData?.getHighEntropyValues) return { system }; + + try { + const { architecture, bitness, wow64 } = await userAgentData.getHighEntropyValues([ + "architecture", "bitness", "wow64", + ]); + if (!architecture || !bitness) return { system }; + const compatible = system === "mac" + ? architecture === "arm" && bitness === "64" + : architecture === "x86" && (bitness === "64" || wow64 === true); + return { system, compatible }; + } catch { + return { system }; + } +} + +let locale = readLocale(); +let platform = {}; + +function render() { + const copy = messages[locale]; + const chinese = locale === "zh-CN"; + document.documentElement.lang = locale; + document.title = copy.title; + for (const element of document.querySelectorAll("[data-text]")) { + element.textContent = copy[element.dataset.text]; + } + for (const element of document.querySelectorAll("[data-label]")) { + element.setAttribute(element instanceof HTMLImageElement ? "alt" : "aria-label", copy[element.dataset.label]); + } + for (const button of languages) { + button.setAttribute("aria-pressed", String(button.dataset.lang === locale)); + } + for (const link of document.querySelectorAll("[data-install]")) { + link.href = `${repository}/blob/main/docs/guides/installation${chinese ? ".zh-CN" : ""}.md`; + } + for (const link of document.querySelectorAll("[data-ai]")) { + link.href = chinese + ? `${repository}/blob/main/README.zh-CN.md#一句话安装` + : `${repository}#install-with-ai`; + } + + updateDownloadButtons(); +} + +function updateDownloadButtons() { + const copy = messages[locale]; + const installer = platform.compatible && installers.get(platform.system); + let menuLabel = copy.downloads; + if (installer) menuLabel = copy.all; + else if (platform.system === "mac" && platform.compatible === undefined && installers.has("mac")) menuLabel = copy.chooseMac; + + for (const { recommended, summary, compact } of downloadControls) { + if (!installers.size) { + recommended.href = "#install-heading"; + recommended.textContent = compact ? copy.shortInstall : copy.source; + recommended.setAttribute("aria-label", copy.source); + continue; + } + recommended.hidden = !installer; + if (installer) { + recommended.href = installer; + const label = copy[`${platform.system}Download`]; + recommended.textContent = compact ? copy.shortDownload : label; + recommended.setAttribute("aria-label", label); + } else { + recommended.removeAttribute("href"); + } + summary.querySelector("span").textContent = compact && !installer ? copy.shortDownload : menuLabel; + summary.setAttribute("aria-label", menuLabel); + } +} + +for (const button of languages) { + button.addEventListener("click", () => { + locale = button.dataset.lang; + try { localStorage.setItem(localeKey, locale); } catch {} + render(); + }); +} +function closeOutsideDownloads(event) { + for (const { downloads } of downloadControls) { + if (downloads.open && !downloads.contains(event.target)) downloads.open = false; + } +} +document.addEventListener("pointerdown", closeOutsideDownloads); +document.addEventListener("focusin", closeOutsideDownloads); +for (const { downloads, summary } of downloadControls) { + downloads.addEventListener("keydown", (event) => { + if (event.key !== "Escape" || !downloads.open) return; + downloads.open = false; + summary.focus(); + }); +} + +const film = document.querySelector(".film-player video"); +const shots = [...document.querySelectorAll(".film-shot")]; +const stage = document.querySelector(".canvas-stage"); +const canvasShots = document.querySelector(".canvas-shots"); +const timeline = document.querySelector(".canvas-timeline"); +const outputStill = document.querySelector(".canvas-output img"); +const outputClip = document.querySelector(".canvas-output video"); +const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)"); +let stageVisible = false; +let demoPhase = "idle"; +let demoTimer; +let selectedShot = null; + +function markTimeline(index) { + timeline.style.setProperty("--shot-index", index); + timeline.toggleAttribute("data-active", true); +} + +function showFilmShot(index) { + if (selectedShot === index) return; + selectedShot = index; + clearTimeout(demoTimer); + outputClip.pause(); + outputClip.hidden = true; + shots.forEach((shot, i) => { + shot.setAttribute("aria-pressed", String(i === index)); + canvasShots.children[i].setAttribute("aria-current", String(i === index)); + }); + markTimeline(index); + outputStill.src = shots[index].querySelector("img").src; + outputStill.hidden = false; +} + +for (const [index, shot] of shots.entries()) { + const link = document.createElement("a"); + link.href = "#film"; + link.dataset.label = shot.querySelector("[data-text]").dataset.text; + canvasShots.append(link); + + function playShot(event) { + showFilmShot(index); + film.currentTime = Number(shot.dataset.at); + const trigger = event.currentTarget; + film.play().catch((error) => { + if (error.name !== "AbortError" && document.activeElement === trigger) film.focus(); + }); + } + shot.addEventListener("click", playShot); + link.addEventListener("click", playShot); +} + +function syncFilmShot() { + const index = shots.findLastIndex((shot) => Number(shot.dataset.at) <= film.currentTime); + if (index >= 0) showFilmShot(index); +} +film.addEventListener("play", syncFilmShot); +film.addEventListener("seeking", syncFilmShot); +film.addEventListener("timeupdate", () => { if (selectedShot !== null) syncFilmShot(); }); +// WebKit leaves a failed playback request in the playing state. +film.addEventListener("error", () => film.pause()); + +const officeShot = shots.findIndex((shot) => shot.dataset.at === "20"); +function runCanvasDemo() { + clearTimeout(demoTimer); + if (selectedShot !== null || reducedMotion.matches || !stageVisible || document.hidden) { + outputClip.pause(); + return; + } + if (demoPhase === "idle") { + canvasShots.children[officeShot].setAttribute("aria-current", "true"); + demoPhase = "selected"; + } + if (demoPhase === "selected") { + demoTimer = setTimeout(() => { + markTimeline(officeShot); + demoPhase = "timeline"; + runCanvasDemo(); + }, 500); + } else if (demoPhase === "timeline") { + demoTimer = setTimeout(() => { + outputClip.poster = shots[officeShot].querySelector("img").src; + outputClip.src = "./film/office-preview.mp4"; + outputClip.hidden = false; + demoPhase = "preview"; + runCanvasDemo(); + }, 480); + } else if (demoPhase === "preview" && !outputClip.ended && outputClip.paused) { + outputClip.play().catch((error) => { + // An interrupted preview can resume. Other failures leave its poster on screen. + if (error.name !== "AbortError") demoPhase = "poster"; + }); + } +} +new IntersectionObserver(([entry]) => { + stageVisible = entry.intersectionRatio >= .55; + runCanvasDemo(); +}, { threshold: .55 }).observe(stage); +document.addEventListener("visibilitychange", runCanvasDemo); +reducedMotion.addEventListener("change", runCanvasDemo); + +for (const button of document.querySelectorAll("[data-copy]")) { + const code = button.parentElement.querySelector("code"); + let reset; + button.addEventListener("click", async () => { + clearTimeout(reset); + try { + await navigator.clipboard.writeText(code.textContent); + button.textContent = messages[locale].copied; + } catch { + const range = document.createRange(); + range.selectNodeContents(code); + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + button.textContent = messages[locale].copyManual; + } + reset = setTimeout(() => { button.textContent = messages[locale].copy; }, 1800); + }); +} + +const languageGroup = header.querySelector(".languages"); +languageGroup.hidden = false; +function updateHeader() { + const compact = window.scrollY > 80; + if (compact === header.classList.contains("is-scrolled")) return; + header.classList.toggle("is-scrolled", compact); + const outgoing = compact ? languageGroup : scrollActions; + if (outgoing.contains(document.activeElement)) header.querySelector(".brand").focus({ preventScroll: true }); + languageGroup.inert = compact; + scrollActions.inert = !compact; + if (!compact) headerActions.querySelector("details").open = false; +} +window.addEventListener("scroll", updateHeader, { passive: true }); +updateHeader(); + +render(); +platform = await detectPlatform(); +updateDownloadButtons(); diff --git a/website/site.test.mjs b/website/site.test.mjs new file mode 100644 index 00000000..2fe14fb9 --- /dev/null +++ b/website/site.test.mjs @@ -0,0 +1,107 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import { launchBrowser } from "../tests/browser/engine.mjs"; +import { renderDownloadPage } from "./build.mjs"; + +const url = process.env.WEBSITE_URL ?? "http://127.0.0.1:8780/OpenDirector/"; +const browser = await launchBrowser(); +try { + const staticPage = await browser.newPage({ javaScriptEnabled: false, locale: "en-US" }); + await staticPage.goto(url); + const links = await staticPage.locator(".hero details a[data-system]").all(); + const downloads = []; + const notes = new Set(); + if (links.length) { + await staticPage.locator(".hero summary").click(); + for (const link of links) { + assert.ok(await link.isVisible()); + const href = await link.getAttribute("href"); + const asset = new URL(href); + assert.equal(asset.origin, "https://github.com"); + const parts = asset.pathname.match(/^(.+\/releases)\/download\/([^/]+)\/.+\.(dmg|exe)$/); + assert.ok(parts, href); + assert.ok((await link.locator("small").innerText()).includes(decodeURIComponent(parts[2]))); + notes.add(`${asset.origin}${parts[1]}/tag/${parts[2]}`); + downloads.push(href); + } + } else { + assert.equal(await staticPage.locator(".hero summary").isVisible(), false); + assert.equal(await staticPage.locator(".hero .actions > a").getAttribute("href"), "#install-heading"); + } + const footnotes = await staticPage.locator(".footer a[href*='/releases/']").evaluateAll(anchors => anchors.map(a => a.href)); + assert.deepEqual(new Set(footnotes), notes); + await staticPage.close(); + + const page = await browser.newPage({ locale: "zh-CN", reducedMotion: "reduce" }); + await page.addInitScript(() => { + Object.defineProperty(navigator, "userAgentData", { + value: { platform: "macOS", getHighEntropyValues: async () => ({ architecture: "x86", bitness: "64" }) }, + }); + }); + await page.goto(url); + const menu = page.locator(".hero summary"); + if (downloads.length) { + await menu.click(); + assert.equal(await menu.getAttribute("aria-label"), "下载 OpenDirector"); + assert.equal(await page.locator(".hero .actions > a").isVisible(), false); + for (const downloadUrl of downloads) { + assert.equal(await page.locator(`.hero details a[href="${downloadUrl}"]`).isVisible(), true); + } + await menu.press("Escape"); + } else { + assert.equal(await page.locator(".hero .actions").getByRole("link").getAttribute("href"), "#install-heading"); + } + await page.getByRole("button", { name: "EN", exact: true }).click(); + assert.equal(await page.locator("html").getAttribute("lang"), "en-US"); + + await page.route("**/film/we-can-still-win.mp4", route => route.fulfill({ status: 404 })); + const film = page.locator(".film-player video"); + const requestedFilm = page.waitForRequest("**/film/we-can-still-win.mp4"); + await page.getByRole("button", { name: /Bedtime/ }).click(); + await requestedFilm; + await page.waitForFunction(() => document.querySelector(".film-player video").error !== null); + assert.equal(await film.evaluate(video => video.paused), true); + await page.close(); + + const template = await readFile(new URL("index.html", import.meta.url), "utf8"); + const releases = { + mac: { + version: "v1.2.1-test.3", test: true, + url: "https://github.com/example/test/releases/download/v1.2.1-test.3/preview.dmg", + notes: "https://github.com/example/test/releases/tag/v1.2.1-test.3", + }, + windows: { + version: "v1.3.0", test: false, + url: "https://github.com/example/official/releases/download/v1.3.0/installer.exe", + notes: "https://github.com/example/official/releases/tag/v1.3.0", + }, + }; + for (const [system, platform, architecture] of [["mac", "macOS", "arm"], ["windows", "Windows", "x86"]]) { + const release = releases[system]; + const client = await browser.newPage({ locale: "zh-CN", reducedMotion: "reduce" }); + await client.addInitScript(({ platform, architecture }) => { + Object.defineProperty(navigator, "userAgentData", { + value: { platform, getHighEntropyValues: async () => ({ architecture, bitness: "64" }) }, + }); + }, { platform, architecture }); + await client.route(url, route => route.fulfill({ contentType: "text/html", body: renderDownloadPage(template, releases) })); + await client.goto(url); + const recommended = client.locator(".hero .actions > a"); + await recommended.waitFor({ state: "visible" }); + assert.equal(await recommended.getAttribute("href"), release.url); + assert.equal(await client.locator(".scroll-actions .actions > a").getAttribute("href"), release.url); + for (const [lang, notesLabel, testLabel] of [["zh-CN", "发布说明", "测试版"], ["en-US", "release notes", "Test build"]]) { + await client.locator(`button[data-lang="${lang}"]`).click(); + await client.locator(".hero summary").click(); + const detail = await client.locator(`.hero details [data-system="${system}"] small`).innerText(); + assert.ok(detail.includes(release.version)); + assert.equal(detail.includes(testLabel), release.test); + const note = client.getByRole("link", { name: `${platform} ${notesLabel}`, exact: true }); + assert.equal(await note.getAttribute("href"), release.notes); + await client.locator(".hero summary").press("Escape"); + } + await client.close(); + } +} finally { + await browser.close(); +}