diff --git a/.github/workflows/debug-build.yml b/.github/workflows/debug-build.yml index ab42c62b..e8cce632 100644 --- a/.github/workflows/debug-build.yml +++ b/.github/workflows/debug-build.yml @@ -4,9 +4,13 @@ on: push: paths-ignore: - '**.md' + - 'website/**' + - '.github/workflows/website.yml' pull_request: paths-ignore: - '**.md' + - 'website/**' + - '.github/workflows/website.yml' workflow_dispatch: concurrency: diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 00000000..1efb6502 --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,43 @@ +name: Website + +on: + push: + paths: + - 'website/**' + - 'docs/assets/app-icon.svg' + - 'docs/licenses/Material-Symbols-Apache-2.0.txt' + - '.github/workflows/website.yml' + pull_request: + paths: + - 'website/**' + - 'docs/assets/app-icon.svg' + - 'docs/licenses/Material-Symbols-Apache-2.0.txt' + - '.github/workflows/website.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: website + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '24' + cache: npm + cache-dependency-path: website/package-lock.json + - run: npm ci + - run: npm run check + - run: npm run build + - run: npm run test:build + - run: npm run test:worker + - uses: actions/upload-artifact@v4 + with: + name: wheelplay-website + path: website/dist/ + if-no-files-found: error diff --git a/README.md b/README.md index f9473e10..768c2fec 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ WheelPlay is an Android-hosted CarPlay server for local networks. It streams you Install the app on an Android device and open the displayed address in your car's browser. No browser-side client installation or additional server is required. +## Product website + +The Astro product website lives in [`website/`](website/README.md), separately from the Android-hosted LAN client. With Node.js 24 LTS, run `npm ci --prefix website`, then `npm run site:dev` for live development or `npm run site:build` to generate `website/dist/`. See the [website guide](website/README.md) for Cloudflare Pages and Workers deployment. + ## Features - **Browser display and touch control**: CarPlay streaming, touch input, and fullscreen display. diff --git a/README.zh-CN.md b/README.zh-CN.md index b85de3b3..519c14d4 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -6,6 +6,10 @@ WheelPlay 是一款 Android 局域网 CarPlay 服务端应用,可将 iPhone 应用安装在 Android 设备上,车机通过浏览器访问即可使用,无需安装客户端或部署额外服务器。 +## 项目官网 + +Astro 官网位于 [`website/`](website/README.md),与 Android 内置的局域网浏览器客户端独立。推荐 Node.js 24 LTS,在仓库根目录先运行 `npm ci --prefix website` 安装官网依赖,再运行 `npm run site:dev` 开发预览,或运行 `npm run site:build` 生成 `website/dist/`。Cloudflare Pages 和 Workers 部署配置见[官网说明](website/README.md)。 + ## 功能 - **浏览器显示与触控**:支持 CarPlay 画面串流、触摸操作和全屏显示。 diff --git a/package.json b/package.json index acd28e67..664799cd 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,11 @@ "node": ">=22" }, "scripts": { + "site:dev": "npm run dev --prefix website", + "site:preview": "npm run preview --prefix website", + "site:build": "npm run build --prefix website", + "site:check": "npm run check --prefix website", + "site:test": "npm run test:build --prefix website && npm run test:worker --prefix website", "dev": "node scripts/preview.mjs", "demo": "node scripts/preview.mjs --demo", "test": "node --test test/*.test.js", diff --git a/website/.gitignore b/website/.gitignore new file mode 100644 index 00000000..746cf851 --- /dev/null +++ b/website/.gitignore @@ -0,0 +1,5 @@ +dist/ +.wrangler/ +.astro/ +.dev.vars +.dev.vars.* diff --git a/website/README.md b/website/README.md new file mode 100644 index 00000000..3181cc76 --- /dev/null +++ b/website/README.md @@ -0,0 +1,159 @@ +# WheelPlay 官网(Astro) + +独立于 Android 内置浏览器客户端的 Astro 静态产品官网。页面由 Astro 组件在构建时生成,浏览器仅加载全局 CSS 和少量 TypeScript 编译出的主题、标签页交互脚本,无需 React/Vue hydration 或服务端运行时。没有远程字体、分析 SDK 或设备连接请求;只有深浅主题偏好会写入 localStorage。下载按钮通过 `/download` 的 Cloudflare Worker 查询 GitHub Actions 元数据,再重定向到 GitHub 产物页面。 + +## 本地开发 + +推荐 Node.js 24 LTS(Astro 7.4.2 要求至少 Node.js 22.23.4)。官网依赖与仓库根目录的 Android 开发工具独立,不需要 Android SDK。 + +从仓库根目录运行: + +```sh +npm ci --prefix website +npm run site:dev +``` + +开发地址为 `http://127.0.0.1:4173`,修改 Astro 组件、样式和脚本会自动更新。自定义端口可运行 `npm --prefix website run dev -- --port 4180`。 + +```sh +npm run site:check # Astro 模板和 TypeScript 检查 +npm run site:build # 输出 website/dist/ +npm run site:test # 构建产物、CSP、下载与缓存行为测试 +npm run site:preview # Astro 预览已构建产物 +``` + +`site:preview` 不会重新构建,请先运行 `site:build`。Astro 开发/预览服务器仅提供静态官网,不运行 `/download`,也不解释 Cloudflare 的 `_headers`。如需验证下载、CSP 和响应头,先构建,再选择一个 Cloudflare 本地运行器: + +```sh +npx wrangler@4.152.0 pages dev --cwd website --port 4174 +# 或独立 Worker +npx wrangler@4.152.0 dev --config website/wrangler.worker.jsonc --port 4174 +``` + +## 项目结构 + +| 路径 | 用途 | +| --- | --- | +| `astro.config.mjs` | 静态输出、开发端口、CSS/JS 外部文件策略 | +| `src/layouts/BaseLayout.astro` | HTML 外壳、SEO 元数据、全局样式 | +| `src/pages/index.astro` | 组合首页各功能区 | +| `src/pages/docs/*.md` | 使用指南、常见问题正文及页面元数据 | +| `src/layouts/DocsLayout.astro` | 文档导航、自动目录和共享页面布局 | +| `src/styles/docs.css` | Markdown 正文排版、深浅主题和移动端样式 | +| `src/pages/404.astro` | 独立 404 页面与 `noindex` 元数据 | +| `src/components/` | 品牌、导航、首屏、交互示意、功能、使用步骤、FAQ、页脚 | +| `src/scripts/` | 类型检查和打包后的主题/标签页交互 | +| `src/styles/global.css` | 既有响应式样式、深浅主题、减少动态效果支持 | +| `src/pages/assets/` | 构建时生成的图标和许可证静态资源路由 | +| `public/_headers` | 原样复制到构建目录的静态资源响应头 | +| `public/_routes.json` | 只让 Pages 的下载路径进入 Functions | +| `worker/download.ts` | GitHub 构建解析、内存/边缘缓存、302 重定向 | +| `worker/index.ts` | Workers 下载入口和 ASSETS 静态资源绑定 | +| `functions/download.ts` | Pages Functions 入口,复用同一解析器 | +| `test/download.test.mjs` | 下载选择、缓存、并发、限流和错误回归测试 | +| `test/build.test.mjs` | 构建产物和 CSP 回归检查 | +| `wrangler.jsonc` | Pages 默认配置 | +| `wrangler.worker.jsonc` | Workers Static Assets 配置 | + +共享图标与许可证由静态资源路由直接导入 `docs/` 中的原文件,保留 `/assets/app-icon.svg` 和 `/assets/Material-Symbols-Apache-2.0.txt` 地址。这两条资源路由构建后是静态文件,不需要运行时 API,也不维护重复素材或额外拷贝脚本。下载解析则由独立 Worker/Pages Function 处理;应保留完整仓库供构建和部署使用。 + +Astro 组件中的 ` diff --git a/website/src/components/FAQ.astro b/website/src/components/FAQ.astro new file mode 100644 index 00000000..05ec6d39 --- /dev/null +++ b/website/src/components/FAQ.astro @@ -0,0 +1,84 @@ +
+
+

GOOD TO KNOW.

+

出发之前,
你可能想知道。

+ 阅读完整常见问题 +
+
+
+ + 我的车机可以使用吗? + +

+ 车机浏览器需要支持现代网页与触控,并能通过局域网访问 Android + 服务设备。不同品牌、系统版本和网络环境的兼容性不同,无法保证所有车型可用。建议先在车辆停稳后验证。 +

+
+
+ + 使用 WheelPlay 需要 Root 吗? + +

+ 普通局域网连接和 Web 服务无需 + Root。针对限制私有网段访问的浏览器,项目提供实验性的 Tesla + 兼容模式,包括免 Root VPN 与 Root + 热点路由两种方案,均需按设备实测。查看兼容模式说明 ↗ +

+
+
+ + 声音和麦克风从哪里走? + +

+ 默认由 Android + 处理音频和麦克风,可在设置中启用浏览器路由。浏览器麦克风需要可信的本地 + HTTPS 证书及相应浏览器能力;不支持时可继续使用 Android 麦克风。查看音频配置说明 ↗ +

+
+
+ + 需要服务器或公网连接吗? + +

+ CarPlay 串流由 Android + 在局域网内提供,无需额外云端服务器;导航、音乐等 App + 的在线内容仍可能需要互联网。服务仅用于可信局域网,请勿暴露到公网。本官网只提供介绍与使用指引,不承载设备连接。 +

+
+
+ + 为什么安装后需要导入认证资源? + +

+ 公开分发的开源构建默认不包含 CarPlay 认证资源。需要在「设置 → + CarPlay 认证资源」导入有效资源,通过校验后才能启动服务。导入在 + Android 本机完成。查看支持的导入方式 ↗ +

+
+
+ 它是开源项目吗? +

+ 是。WheelPlay 基于 DiPlay / xcertplay 开发,项目采用 GPL-3.0 + 许可证并保留上游及第三方声明。你可以阅读源码、提交问题或参与改进;第三方组件与素材遵循各自许可证。查看许可证 ↗ +

+
+
+
diff --git a/website/src/components/Features.astro b/website/src/components/Features.astro new file mode 100644 index 00000000..81ec4c9c --- /dev/null +++ b/website/src/components/Features.astro @@ -0,0 +1,59 @@ +
+
+
+

LESS SETUP. MORE POSSIBILITY.

+

屏幕之间,
不必有那么多距离。

+
+

让 Android 做好连接,
让车机浏览器专注于眼前的体验。

+
+
+
+ 01 / DISPLAY +

打开浏览器,就是新视野。

+

+ 显示、触控、全屏,一张网页就能完成。车机端无需安装额外客户端。 +

+
+ 触摸操作全屏显示 +
+
+
+ 02 / STREAM +

为不同的屏幕,留一条路。

+

+ 支持 WebRTC + 视频直通,也提供图片兼容模式。按你的设备和网络,选择合适的串流方式。 +

+
+ H.264 / HEVCJPEG / WebP +
+
+
+ 03 / CONTROL +

合不合适,由你来调。

+

+ 调整分辨率、帧率与安全区域,选择音频输出和定位来源,让设置适应你的使用习惯。 +

+
+ 显示偏好音频路由 +
+
+
+
diff --git a/website/src/components/GettingStarted.astro b/website/src/components/GettingStarted.astro new file mode 100644 index 00000000..6166c656 --- /dev/null +++ b/website/src/components/GettingStarted.astro @@ -0,0 +1,75 @@ +
+
+
+

READY WHEN YOU ARE.

+

从这里,
开始连接。

+

+ 准备一部 iPhone、一台 Android 9+ 设备,
以及支持现代网页与触控的车机浏览器。 +

+ 下载最新开发构建 +

+ 自动前往 main 分支最新成功构建的
wheelplay-debug-apk + 产物页面,结果最多缓存 5 分钟。
下载需要登录 GitHub,且产物可能过期。 +

+ 也可以从源码构建 +
+
    +
  1. + 01 +
    +

    在 Android 上,准备好 WheelPlay

    +

    + 安装并打开应用。开源构建默认不含 CarPlay + 认证资源,请先在设置中导入有效资源,校验通过后启动服务。 +

    + 查看认证资源导入说明 +
    +
  2. +
  3. + 02 +
    +

    同一网络,打开同一个入口

    +

    + 让 Android 与车机接入同一局域网,在车机浏览器中打开 WheelPlay + 应用显示的访问地址。 +

    + 使用 App 中的实际地址,无需访问本官网连接。 +
    +
  4. +
  5. + 03 +
    +

    配对、连接,把 CarPlay 带上车

    +

    + 扫描网页二维码或输入配对码,启动显示。保持 Android + 应用在前台,按提示通过 USB 或无线连接 iPhone,并允许使用 + CarPlay。 +

    + 阅读完整使用步骤 +
    +
  6. +
+
+
diff --git a/website/src/components/Hero.astro b/website/src/components/Hero.astro new file mode 100644 index 00000000..60b12a07 --- /dev/null +++ b/website/src/components/Hero.astro @@ -0,0 +1,45 @@ +
+ 为你的车机,打开一种新可能 +

让 CarPlay,
在浏览器里就位。

+

+ 一部 Android,一块车机屏幕。
把 iPhone + 的熟悉体验,带到你的每一次出发。 +

+
+ 开始使用 WheelPlay阅读使用文档 +
+
+ Android 9+车机无需安装 App局域网直连 +
+
diff --git a/website/src/components/SiteFooter.astro b/website/src/components/SiteFooter.astro new file mode 100644 index 00000000..0fc60e97 --- /dev/null +++ b/website/src/components/SiteFooter.astro @@ -0,0 +1,26 @@ +--- +import Brand from "./Brand.astro"; +--- + + diff --git a/website/src/components/SiteHeader.astro b/website/src/components/SiteHeader.astro new file mode 100644 index 00000000..718d9078 --- /dev/null +++ b/website/src/components/SiteHeader.astro @@ -0,0 +1,43 @@ +--- +import Brand from "./Brand.astro"; +--- + + + + diff --git a/website/src/layouts/BaseLayout.astro b/website/src/layouts/BaseLayout.astro new file mode 100644 index 00000000..debca62b --- /dev/null +++ b/website/src/layouts/BaseLayout.astro @@ -0,0 +1,40 @@ +--- +import "../styles/global.css"; + +interface Props { + title?: string; + description?: string; + socialDescription?: string; + noIndex?: boolean; + bodyClass?: string; +} +const { + title = "WheelPlay · 让 CarPlay,在浏览器里就位", + description = "WheelPlay 是开源的 Android 局域网 CarPlay 服务端。将 iPhone 的 CarPlay 带到车机浏览器,支持触控、USB 与无线连接,无需在车机安装客户端。", + socialDescription = "一部 Android,一块车机屏幕。通过局域网,在浏览器里显示和操作 iPhone 的 CarPlay。", + noIndex = false, + bodyClass, +} = Astro.props; +--- + + + + + + + + + + + + + + + {noIndex && } + {title} + + + + + + diff --git a/website/src/layouts/DocsLayout.astro b/website/src/layouts/DocsLayout.astro new file mode 100644 index 00000000..2fb7e8a2 --- /dev/null +++ b/website/src/layouts/DocsLayout.astro @@ -0,0 +1,53 @@ +--- +import type { MarkdownLayoutProps } from "astro"; +import BaseLayout from "./BaseLayout.astro"; +import SiteHeader from "../components/SiteHeader.astro"; +import SiteFooter from "../components/SiteFooter.astro"; +import "../styles/docs.css"; + +type Props = MarkdownLayoutProps<{ + title: string; + description: string; +}>; + +const { frontmatter, headings } = Astro.props; +const sections = headings.filter(({ depth }) => depth === 2); +const pages = [ + { href: "/docs/", label: "使用指南" }, + { href: "/docs/faq/", label: "常见问题" }, +]; +const currentPath = Astro.url.pathname.replace(/\/$/, ""); +--- + + + + +
+ +
+
+

{frontmatter.title}

+

{frontmatter.description}

+
+
+
+
+ +
diff --git a/website/src/pages/404.astro b/website/src/pages/404.astro new file mode 100644 index 00000000..a475fb62 --- /dev/null +++ b/website/src/pages/404.astro @@ -0,0 +1,16 @@ +--- +import BaseLayout from "../layouts/BaseLayout.astro"; +import Brand from "../components/Brand.astro"; +--- + + +
+ +

404 / WRONG TURN

+

换条路,
回到出发点。

+

这个页面不存在,或已经移动。

+ 返回首页 +
+
diff --git a/website/src/pages/assets/Material-Symbols-Apache-2.0.txt.ts b/website/src/pages/assets/Material-Symbols-Apache-2.0.txt.ts new file mode 100644 index 00000000..aec9542e --- /dev/null +++ b/website/src/pages/assets/Material-Symbols-Apache-2.0.txt.ts @@ -0,0 +1,7 @@ +import type { APIRoute } from "astro"; +import license from "../../../../docs/licenses/Material-Symbols-Apache-2.0.txt?raw"; + +export const GET: APIRoute = () => + new Response(license, { + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }); diff --git a/website/src/pages/assets/app-icon.svg.ts b/website/src/pages/assets/app-icon.svg.ts new file mode 100644 index 00000000..6f99baee --- /dev/null +++ b/website/src/pages/assets/app-icon.svg.ts @@ -0,0 +1,6 @@ +import type { APIRoute } from "astro"; +import icon from "../../../../docs/assets/app-icon.svg?raw"; + +// Pre-render the shared repository asset at its existing public URL. +export const GET: APIRoute = () => + new Response(icon, { headers: { "Content-Type": "image/svg+xml" } }); diff --git a/website/src/pages/docs/faq.md b/website/src/pages/docs/faq.md new file mode 100644 index 00000000..bd6a4d83 --- /dev/null +++ b/website/src/pages/docs/faq.md @@ -0,0 +1,59 @@ +--- +layout: ../../layouts/DocsLayout.astro +title: 常见问题 +description: 关于设备兼容、下载、连接和音频的常见疑问。 +--- + +第一次使用时,建议先按[使用指南](/docs/)完成安装、认证资源导入和配对。 + +## 我的车机可以使用吗? + +车机浏览器需要支持现代网页与触控,并能通过局域网访问 Android 服务设备。不同品牌、系统版本与网络环境的兼容性不同,无法保证所有车型可用,请在车辆停稳后验证。 + +画面流畅度还取决于 iPhone 输出、网络质量、Android 性能与浏览器解码能力。 + +## 使用 WheelPlay 需要 Root 吗? + +普通局域网连接和 Web 服务无需 Root。 + +针对限制私有网段访问的浏览器,应用提供实验性的 Tesla 兼容模式。免 Root VPN 方案需要 Android VPN 授权,Root 热点路由方案需要 Root。两种方案均需根据设备实测,详见[兼容模式说明](https://github.com/fython/wheelplay/blob/main/docs/TESLA_HTTP.md)。 + +## 为什么安装后需要导入认证资源? + +公开分发的开源构建默认不包含 CarPlay 认证资源。需要在 **设置 → CarPlay 认证资源** 中导入有效资源,通过校验后才能启动服务。 + +导入在 Android 本机完成,资源保存在应用私有目录,不上传、不参与备份。具体格式和操作步骤见[认证资源导入说明](https://github.com/fython/wheelplay/blob/main/docs/AUTHENTICATION_IMPORT.md)。 + +## 为什么下载时会跳转到 GitHub? + +[下载入口](/download)会选择指定工作流 `main` 分支最新成功构建中的 `wheelplay-debug-apk`,然后跳转到 GitHub 的产物页面。官网不存储或转发安装包。 + +- GitHub 下载构建产物可能要求先登录账户。 +- 构建产物有有效期;过期或已删除的产物无法下载。 +- 最新成功构建没有对应产物时,入口不会自动选择更旧的构建。 +- 下载结果最多缓存 5 分钟,新构建完成后可能需要稍等才会更新。 +- GitHub 暂时不可用或限流时,请稍后重试,也可手动打开[构建列表](https://github.com/fython/wheelplay/actions/workflows/debug-build.yml)。 + +## 声音和麦克风从哪里走? + +默认由 Android 处理音频和麦克风,可在 **设置 → 音频与麦克风** 中启用浏览器路由。 + +浏览器麦克风需要可信的本地 HTTPS 证书及相应浏览器能力;不支持时可继续使用 Android 麦克风。启用 HTTPS 后需要从 HTTPS 入口重新配对并授权,详见[音频配置说明](https://github.com/fython/wheelplay/blob/main/docs/BROWSER_AUDIO.md)。 + +## 需要服务器或公网连接吗? + +CarPlay 串流由 Android 在局域网内提供,无需额外云端服务器;导航、音乐等 App 的在线内容仍可能需要互联网。 + +服务仅用于可信局域网,请勿暴露到公网。本官网提供介绍、下载与使用指引,设备连接应使用应用显示的局域网地址。 + +## 为什么浏览器需要重新配对? + +设备记忆与浏览器及访问地址绑定。清理浏览器数据、禁用本地存储、切换 HTTP / HTTPS 或改变主机、端口后,都需要重新配对。 + +在 Android 应用中移除已记住的浏览器,也会使该浏览器的旧凭据失效。同一时间仅允许一个浏览器控制会话。 + +## 它是开源项目吗? + +是。WheelPlay 基于 DiPlay / xcertplay 开发,采用 GPL-3.0 许可证并保留上游及第三方声明;第三方组件与素材遵循各自许可证。 + +可以阅读[源码](https://github.com/fython/wheelplay)、查看[许可证](https://github.com/fython/wheelplay/blob/main/LICENSE),或通过 [GitHub Issues](https://github.com/fython/wheelplay/issues)反馈问题。 diff --git a/website/src/pages/docs/index.md b/website/src/pages/docs/index.md new file mode 100644 index 00000000..4aa4ba8b --- /dev/null +++ b/website/src/pages/docs/index.md @@ -0,0 +1,67 @@ +--- +layout: ../../layouts/DocsLayout.astro +title: 使用指南 +description: 从安装到配对,将 iPhone 的 CarPlay 连接到车机浏览器。 +--- + +WheelPlay 安装在 Android 设备上,通过局域网向车机浏览器提供 CarPlay 画面与触控。车机无需安装客户端,也无需部署额外服务器。 + +## 准备设备 + +- 一台运行 **Android 9 或更高版本**的服务设备。 +- 一部支持 CarPlay 的 iPhone。 +- 支持现代网页与触控、能访问 Android 服务设备的车机浏览器。 +- Android 与车机可以互相访问的局域网。 + +不同车机、系统版本和网络环境的兼容性不同,请在车辆停稳后完成首次配置和验证。 + +## 下载与安装 + +在 Android 设备上打开[下载最新开发构建](/download),前往 GitHub 下载 `wheelplay-debug-apk`,解压后安装其中的 APK。 + +下载入口选择 `debug-build.yml` 工作流中 `main` 分支最新成功构建的产物,结果最多缓存 5 分钟。GitHub 下载可能需要登录;构建产物过期或最新构建没有对应产物时,可稍后再试或查看[构建列表](https://github.com/fython/wheelplay/actions/workflows/debug-build.yml)。 + +需要自行编译时,请阅读项目的[源码构建说明](https://github.com/fython/wheelplay/blob/main/README.zh-CN.md#构建)。 + +## 导入认证资源 + +公开分发的开源构建默认不包含 CarPlay 认证资源。在 Android 应用中打开 **设置 → CarPlay 认证资源**,导入有效资源。校验通过后,应用才能启动服务。 + +支持选择 `identity.pk8` 和 `certificate.p7b`,或从有效的 DiPlay APK 导入。导入与校验在 Android 本机完成,资源保存在应用私有目录,不上传、不参与备份。 + +完整步骤见[认证资源导入说明](https://github.com/fython/wheelplay/blob/main/docs/AUTHENTICATION_IMPORT.md)。 + +## 打开车机浏览器 + +1. 在 Android 服务设备上安装并启动 WheelPlay,完成认证资源配置。 +2. 将 Android 与车机连接到同一局域网。 +3. 在车机浏览器中打开 **WheelPlay 应用显示的实际访问地址**。 + +本官网提供下载和使用指引,连接设备时应使用应用中的局域网地址。 + +## 配对并连接 iPhone + +1. 首次使用时,在 WheelPlay 中扫描车机网页上的二维码并确认配对;也可以在网页输入配对码。 +2. 选择网页选项,点击「启动显示」。 +3. 保持 Android 应用在前台,按应用提示通过 USB 或无线方式连接 iPhone。 +4. 完成设备选择或授权,并在 iPhone 上允许使用 CarPlay。 +5. 连接完成后,在车机浏览器中查看和操作 CarPlay。 + +已记住的浏览器可在后续访问时恢复配对。清理浏览器数据、禁用存储、切换 HTTP / HTTPS 或更换访问地址后,需要重新配对。 + +在 **设置 → 浏览器设备 → 连接过的设备** 中可以查看、重命名或移除设备。移除后会立即断开该设备,并要求下次重新配对。同一时间仅允许一个浏览器控制会话。 + +## 音频与麦克风 + +默认由 Android 设备处理音频与麦克风。在 **设置 → 音频与麦克风** 中可以选择浏览器路由。 + +浏览器麦克风要求受信任的本地 HTTPS 证书及对应浏览器能力,需从 HTTPS 入口重新配对并授权。不支持时可继续使用 Android 麦克风。配置步骤见[浏览器音频说明](https://github.com/fython/wheelplay/blob/main/docs/BROWSER_AUDIO.md)。 + +## 连接遇到问题 + +- 确认认证资源已经通过校验,Android 应用中的服务已启动。 +- 确认车机与 Android 能通过局域网互相访问,并使用应用显示的地址。 +- 浏览器限制私有网段访问时,可查看[实验性兼容模式](https://github.com/fython/wheelplay/blob/main/docs/TESLA_HTTP.md)。 +- 更多兼容性、权限和下载问题见[常见问题](/docs/faq/)。 + +服务仅用于可信局域网,请勿将其暴露到公网。导航、音乐等 App 的在线内容仍可能需要互联网。 diff --git a/website/src/pages/index.astro b/website/src/pages/index.astro new file mode 100644 index 00000000..e97559ab --- /dev/null +++ b/website/src/pages/index.astro @@ -0,0 +1,25 @@ +--- +import BaseLayout from "../layouts/BaseLayout.astro"; +import SiteHeader from "../components/SiteHeader.astro"; +import Hero from "../components/Hero.astro"; +import ExperiencePreview from "../components/ExperiencePreview.astro"; +import Features from "../components/Features.astro"; +import GettingStarted from "../components/GettingStarted.astro"; +import FAQ from "../components/FAQ.astro"; +import Closing from "../components/Closing.astro"; +import SiteFooter from "../components/SiteFooter.astro"; +--- + + + + +
+ + + + + + +
+ +
diff --git a/website/src/scripts/preview-tabs.ts b/website/src/scripts/preview-tabs.ts new file mode 100644 index 00000000..d870b025 --- /dev/null +++ b/website/src/scripts/preview-tabs.ts @@ -0,0 +1,39 @@ +// These panels are illustrations; switching tabs never contacts a device. +const preview = document.querySelector(".preview-panel"); +const tabs = [ + ...(preview?.querySelectorAll('[role="tab"]') ?? []), +]; +const mode = preview?.querySelector("#preview-mode"); + +function selectTab(tab: HTMLButtonElement) { + for (const candidate of tabs) { + const selected = candidate === tab; + candidate.setAttribute("aria-selected", String(selected)); + candidate.tabIndex = selected ? 0 : -1; + const panelId = candidate.getAttribute("aria-controls"); + const panel = panelId ? document.getElementById(panelId) : null; + if (panel) panel.hidden = !selected; + } + if (mode) mode.textContent = `${tab.dataset.view?.toUpperCase()} / PREVIEW`; +} + +for (const [index, tab] of tabs.entries()) { + tab.addEventListener("click", () => selectTab(tab)); + tab.addEventListener("keydown", (event) => { + const targets: Record = { + ArrowRight: (index + 1) % tabs.length, + ArrowLeft: (index + tabs.length - 1) % tabs.length, + Home: 0, + End: tabs.length - 1, + }; + const targetIndex = targets[event.key]; + if (targetIndex === undefined) return; + const target = tabs[targetIndex]; + if (!target) return; + event.preventDefault(); + selectTab(target); + target.focus(); + }); +} + +export {}; diff --git a/website/src/scripts/theme.ts b/website/src/scripts/theme.ts new file mode 100644 index 00000000..67804169 --- /dev/null +++ b/website/src/scripts/theme.ts @@ -0,0 +1,45 @@ +type Theme = "light" | "dark"; + +const themeButton = document.querySelector(".theme-toggle"); +const themeColor = document.querySelector( + 'meta[name="theme-color"]', +); +const preference = window.matchMedia("(prefers-color-scheme: dark)"); +let chosenTheme: Theme | null = null; +try { + const savedTheme = localStorage.getItem("wheelplay-site-theme"); + if (savedTheme === "light" || savedTheme === "dark") chosenTheme = savedTheme; +} catch { + // Storage is optional; the toggle still works for this visit. +} + +function applyTheme(theme: Theme) { + document.documentElement.dataset.theme = theme; + const dark = theme === "dark"; + themeButton?.setAttribute("aria-pressed", String(dark)); + themeButton?.setAttribute( + "aria-label", + dark ? "切换到浅色主题" : "切换到深色主题", + ); + if (themeColor) themeColor.content = dark ? "#101720" : "#f8fafc"; +} + +applyTheme(chosenTheme || (preference.matches ? "dark" : "light")); +if (themeButton) { + themeButton.hidden = false; + themeButton.addEventListener("click", () => { + chosenTheme = + document.documentElement.dataset.theme === "dark" ? "light" : "dark"; + applyTheme(chosenTheme); + try { + localStorage.setItem("wheelplay-site-theme", chosenTheme); + } catch { + // Continue without persistence. + } + }); +} +preference.addEventListener("change", (event) => { + if (!chosenTheme) applyTheme(event.matches ? "dark" : "light"); +}); + +export {}; diff --git a/website/src/styles/docs.css b/website/src/styles/docs.css new file mode 100644 index 00000000..fcd4d1d6 --- /dev/null +++ b/website/src/styles/docs.css @@ -0,0 +1,148 @@ +.docs-layout { + display: grid; + grid-template-columns: 210px minmax(0, 1fr); + gap: 64px; + padding-block: 64px; + align-items: start; +} +.docs-sidebar { + position: sticky; + top: 112px; + max-height: calc(100svh - 136px); + overflow-y: auto; +} +.docs-sidebar nav { + display: grid; + gap: 6px; +} +.docs-sidebar a { + display: block; + padding: 8px 12px; + border-radius: 6px; + color: var(--muted); + overflow-wrap: anywhere; +} +.docs-sidebar a:hover, +.docs-sidebar a[aria-current="page"] { + color: var(--blue); + background: var(--blue-soft); +} +.docs-toc { + border-top: 1px solid var(--line); + margin-top: 28px; + padding-top: 24px; + font-size: 13px; +} +.docs-toc > p { + font-weight: 600; + margin-bottom: 8px; +} +.docs-main { + min-width: 0; + max-width: 760px; +} +.docs-heading { + padding-bottom: 28px; + border-bottom: 1px solid var(--line); + margin-bottom: 28px; +} +.docs-heading h1 { + font-size: clamp(30px, 5vw, 44px); + line-height: 1.3; + letter-spacing: -1px; +} +.docs-heading p { + color: var(--muted); + margin-top: 16px; + line-height: 1.9; +} +.docs-content { + font-size: 15px; + line-height: 1.95; + overflow-wrap: anywhere; +} +.docs-content :is(p, ul, ol, pre, blockquote, table) { + margin-block: 18px; +} +.docs-content h2 { + font-size: 25px; + letter-spacing: -0.5px; + margin-top: 44px; + margin-bottom: 18px; +} +.docs-content h3 { + font-size: 19px; + margin-block: 28px 14px; +} +.docs-content a { + color: var(--blue); + text-decoration: underline; + text-underline-offset: 4px; +} +.docs-content :is(ul, ol) { + padding-left: 24px; +} +.docs-content li + li { + margin-top: 8px; +} +.docs-content code { + padding: 2px 5px; + border-radius: 4px; + background: var(--soft); + font-size: 0.9em; +} +.docs-content pre { + padding: 18px; + overflow-x: auto; + background: var(--soft); + border: 1px solid var(--line); + border-radius: 8px; +} +.docs-content pre code { + padding: 0; +} +.docs-content blockquote { + margin-inline: 0; + border-left: 3px solid var(--blue); + padding-left: 20px; + color: var(--muted); +} +.docs-content table { + display: block; + overflow-x: auto; + border-collapse: collapse; +} +.docs-content :is(th, td) { + border: 1px solid var(--line); + padding: 10px 14px; + text-align: left; +} +@media (max-width: 760px) { + .docs-layout { + grid-template-columns: 1fr; + gap: 32px; + padding-block: 32px; + } + .docs-sidebar { + position: static; + max-height: none; + } + .docs-sidebar nav:first-child { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + .docs-sidebar .eyebrow { + grid-column: 1 / -1; + margin-bottom: 4px; + } + .docs-toc { + grid-template-columns: repeat(2, minmax(0, 1fr)); + margin-top: 16px; + padding-top: 16px; + } + .docs-toc > p { + grid-column: 1 / -1; + } + .docs-content h2 { + font-size: 23px; + } +} diff --git a/website/src/styles/global.css b/website/src/styles/global.css new file mode 100644 index 00000000..816423f3 --- /dev/null +++ b/website/src/styles/global.css @@ -0,0 +1,2034 @@ +@charset "UTF-8"; +:root { + color-scheme: light; + --bg: #f8fafc; + --surface: #fff; + --soft: #f0f4f8; + --text: #17263d; + --muted: #637084; + --faint: #6b7a90; + --line: #e0e6ee; + --blue: #2869e8; + --blue-soft: #eaf1ff; + --green: #399268; + --shadow: 0 18px 60px -28px #203b6a45; + font-family: + Inter, + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + "PingFang SC", + "Microsoft YaHei", + sans-serif; + font-synthesis: none; +} +:root[data-theme="dark"] { + color-scheme: dark; + --bg: #101720; + --surface: #17212e; + --soft: #1c2939; + --text: #e7edf6; + --muted: #adb9ca; + --faint: #9aabc3; + --line: #2d3b4e; + --blue: #87adff; + --blue-soft: #203558; + --green: #75caa0; + --shadow: 0 18px 60px -28px #0009; +} +@media (prefers-color-scheme: dark) { + :root:not([data-theme]) { + color-scheme: dark; + --bg: #101720; + --surface: #17212e; + --soft: #1c2939; + --text: #e7edf6; + --muted: #adb9ca; + --faint: #9aabc3; + --line: #2d3b4e; + --blue: #87adff; + --blue-soft: #203558; + --green: #75caa0; + --shadow: 0 18px 60px -28px #0009; + } +} +* { + box-sizing: border-box; +} +html { + scroll-behavior: smooth; + scroll-padding-top: 96px; +} +body { + margin: 0; + background: var(--bg); + color: var(--text); + font-size: 14px; + line-height: 1.65; + -webkit-font-smoothing: antialiased; +} +a { + color: inherit; + text-decoration: none; +} +button { + font: inherit; + cursor: pointer; +} +svg { + display: block; +} +img { + display: block; + max-width: 100%; +} +button, +a, +summary { + -webkit-tap-highlight-color: transparent; +} +button:focus-visible, +a:focus-visible, +summary:focus-visible, +[tabindex="0"]:focus-visible { + outline: 3px solid var(--blue); + outline-offset: 5px; +} +a, +button { + touch-action: manipulation; +} +[hidden] { + display: none !important; +} +::selection { + background: #bed5ff; + color: #152b52; +} +h1, +h2, +h3, +p { + margin: 0; +} +h1, +h2, +h3 { + font-weight: 650; +} +h2 { + font-size: 38px; + line-height: 1.4; + letter-spacing: -1.6px; +} +h3 { + font-size: 18px; + line-height: 1.5; +} +.container { + width: min(1160px, calc(100% - 64px)); + margin-inline: auto; +} +.mono, +.eyebrow, +.feature-number { + font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; +} +.eyebrow { + font-size: 11px; + letter-spacing: 1.7px; + font-weight: 600; + color: var(--blue); + margin-bottom: 18px; +} +.section { + padding-block: 96px; +} +.skip-link { + position: fixed; + top: 12px; + left: 16px; + transform: translateY(-160%); + z-index: 100; + background: var(--surface); + padding: 10px 20px; +} +.skip-link:focus { + transform: translateY(0); +} +.site-header { + height: 76px; + border-bottom: 1px solid var(--line); + background: var(--bg); +} +.header-inner { + height: 100%; + width: min(1320px, calc(100% - 64px)); + margin: auto; + display: flex; + align-items: center; + justify-content: space-between; + gap: 24px; +} +.brand { + display: inline-flex; + align-items: center; + gap: 10px; + font-size: 20px; + font-weight: 700; + letter-spacing: -0.65px; + flex-shrink: 0; +} +.brand img { + border-radius: 9px; +} +.brand-label { + font-size: 10px; + letter-spacing: 0.3px; + font-weight: 500; + margin-left: 3px; + color: var(--muted); + border: 1px solid var(--line); + border-radius: 5px; + padding: 2px 6px; +} +.site-header nav { + display: flex; + gap: 32px; + color: var(--muted); + font-size: 13px; +} +.site-header nav a:hover, +.text-link:hover, +.site-footer a:hover { + color: var(--blue); +} +.header-actions { + display: flex; + align-items: center; + gap: 22px; +} +.icon-button { + width: 36px; + height: 36px; + display: grid; + place-items: center; + border: 1px solid transparent; + border-radius: 7px; + background: none; + color: var(--muted); +} +.icon-button:hover { + background: var(--soft); + border-color: var(--line); +} +.icon-button svg { + width: 19px; + height: 19px; +} +.github-link { + display: flex; + align-items: center; + gap: 9px; + font-size: 12px; + font-weight: 600; +} +.github-link svg { + width: 18px; + height: 18px; +} +.github-link > span:last-child { + color: var(--faint); +} +.hero { + text-align: center; + padding-top: 65px; + padding-bottom: 42px; +} +.announcement { + display: inline-flex; + gap: 9px; + align-items: center; + font-size: 11px; + font-weight: 500; + background: var(--blue-soft); + border: 1px solid color-mix(in srgb, var(--blue) 15%, transparent); + color: var(--blue); + padding: 5px 12px; + border-radius: 20px; + margin-bottom: 23px; +} +.announcement > span:last-child { + margin-left: 4px; +} +.status-dot { + display: inline-block; + width: 6px; + height: 6px; + border-radius: 50%; + background: var(--green); + flex-shrink: 0; +} +.announcement .status-dot { + background: var(--blue); +} +h1 { + font-size: clamp(40px, 4.4vw, 62px); + font-weight: 700; + line-height: 1.28; + letter-spacing: -2.6px; +} +h1 > span { + color: var(--blue); +} +.hero-description { + font-size: 16px; + line-height: 1.9; + color: var(--muted); + margin-top: 19px; + letter-spacing: 0.3px; +} +.hero-actions { + display: flex; + justify-content: center; + gap: 12px; + margin-top: 26px; +} +.button { + min-height: 45px; + padding: 11px 19px; + border-radius: 7px; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 11px; + font-size: 13px; + font-weight: 600; + line-height: 1.4; + transition: + background 0.18s, + transform 0.18s; + white-space: nowrap; +} +.button:hover { + transform: translateY(-2px); +} +.button svg { + width: 16px; + height: 16px; +} +.primary { + background: #2869e8; + color: white; + border: 1px solid #2869e8; + box-shadow: 0 3px 6px #2869e81a; +} +.primary:hover { + background: #1859d9; +} +.secondary { + background: var(--surface); + border: 1px solid var(--line); +} +.secondary:hover { + background: var(--soft); +} +.hero-notes { + display: flex; + justify-content: center; + gap: 25px; + margin-top: 20px; + font-size: 10px; + color: var(--muted); +} +.hero-notes span { + display: flex; + gap: 5px; + align-items: center; +} +.hero-notes svg { + width: 12px; + height: 12px; + fill: none; + stroke: var(--green); + stroke-width: 1.7; +} +.workspace { + background: var(--surface); + border: 1px solid var(--line); + border-radius: 12px; + box-shadow: var(--shadow); + overflow: hidden; +} +.workspace-bar { + height: 44px; + padding: 0 16px; + display: flex; + align-items: center; + gap: 20px; + border-bottom: 1px solid var(--line); + background: var(--surface); +} +.window-dots { + display: flex; + gap: 5px; +} +.window-dots i { + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--line); +} +.window-dots i:first-child { + background: #e6acaa; +} +.window-dots i:nth-child(2) { + background: #e6c88c; +} +.window-dots i:nth-child(3) { + background: #9acbb0; +} +.workspace-title { + font-size: 10px; + color: var(--muted); + flex: 1; +} +.workspace-title > span { + margin: 0 9px; + color: var(--faint); +} +.demo-badge { + font-size: 9px; + letter-spacing: 1px; + color: var(--muted); + border: 1px solid var(--line); + padding: 1px 7px; + border-radius: 4px; +} +.workspace-body { + display: grid; + grid-template-columns: 30% 70%; +} +.source-panel { + padding: 24px 24px 18px; + border-right: 1px solid var(--line); + display: flex; + flex-direction: column; +} +.panel-heading { + display: flex; + align-items: center; + gap: 9px; + font-size: 11px; + font-weight: 600; +} +.small-icon { + color: var(--blue); + font-size: 20px; + line-height: 1; +} +.panel-heading .mono { + font-size: 9px; + color: var(--faint); + margin-left: auto; + font-weight: 400; +} +.device-flow { + margin-top: 25px; +} +.device-step { + display: flex; + align-items: center; + gap: 11px; + position: relative; +} +.device-icon { + width: 40px; + height: 40px; + border: 1px solid var(--line); + border-radius: 10px; + display: grid; + place-items: center; + background: var(--bg); + flex-shrink: 0; +} +.device-icon svg { + width: 22px; + height: 22px; + fill: none; + stroke: var(--muted); + stroke-width: 1.5; +} +.app-icon { + border: 0; +} +.device-step strong { + font-size: 11px; + font-weight: 600; +} +.device-step p { + font-size: 10px; + color: var(--muted); + margin-top: 2px; +} +.step-number { + margin-left: auto; + font: 9px monospace; + color: var(--faint); +} +.flow-line { + height: 36px; + margin: 5px 0 5px 20px; + border-left: 1px dashed var(--line); + display: flex; + align-items: center; +} +.flow-line span { + font-size: 9px; + color: var(--muted); + margin-left: 30px; +} +.local-note { + display: flex; + gap: 9px; + border-top: 1px solid var(--line); + margin-top: 25px; + padding-top: 16px; +} +.local-note svg { + width: 17px; + height: 17px; + fill: none; + stroke: var(--green); + stroke-width: 1.5; + flex-shrink: 0; +} +.local-note strong { + font-size: 10px; + font-weight: 500; +} +.local-note p { + font-size: 9px; + color: var(--muted); + margin-top: 3px; +} +.preview-panel { + min-width: 0; + background: var(--bg); +} +.preview-toolbar { + height: 52px; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 20px; + border-bottom: 1px solid var(--line); + gap: 10px; +} +.preview-tabs { + display: flex; + gap: 6px; +} +.preview-tabs button { + font-size: 10px; + font-weight: 500; + color: var(--muted); + border: 1px solid transparent; + background: none; + border-radius: 5px; + padding: 5px 10px; + min-height: 32px; +} +.preview-tabs button[aria-selected="true"] { + background: var(--surface); + color: var(--blue); + border-color: var(--line); + box-shadow: 0 2px 3px #142b4c06; +} +.preview-tabs button:hover { + color: var(--blue); +} +.preview-label { + display: flex; + align-items: center; + gap: 5px; + font-size: 9px; + color: var(--muted); + white-space: nowrap; +} +.display-shell { + padding: 20px 20px 15px; +} +.car-display { + height: 288px; + background: #17202a; + color: #f4f6fa; + border: 5px solid #202a37; + border-radius: 13px; + display: flex; + overflow: hidden; + box-shadow: 0 8px 18px #0f223024; +} +.car-sidebar { + display: flex; + align-items: center; + flex-direction: column; + width: 48px; + padding: 13px 0 10px; + flex-shrink: 0; + background: #222e3b; +} +.car-time { + font-size: 12px; + font-weight: 650; +} +.signal { + font-size: 8px; + color: #b5c2d3; + margin-bottom: 16px; + margin-top: 2px; +} +.dock-icon { + display: grid; + place-items: center; + width: 29px; + height: 29px; + margin-bottom: 11px; + border-radius: 8px; + font-size: 24px; + font-weight: 500; + line-height: 1; + color: white; +} +.map-icon { + background: #4b93a6; +} +.music-icon { + background: #e55c76; +} +.phone-icon { + background: #57a179; +} +.dock-home { + font-size: 24px; + line-height: 1; + margin-top: auto; +} +.map-surface { + position: relative; + flex: 1; + min-width: 0; + overflow: hidden; +} +.map-art { + width: 100%; + height: 100%; + display: block; +} +.turn-card { + display: flex; + gap: 10px; + align-items: center; + position: absolute; + top: 12px; + left: 12px; + right: 12px; + background: #253c38; + box-shadow: 0 3px 7px #20352930; + border-radius: 8px; + padding: 12px; +} +.turn-card > span { + font-size: 29px; + line-height: 1; +} +.turn-card strong { + font-size: 13px; + font-weight: 650; + display: block; +} +.turn-card div > span { + font-size: 9px; + color: #d6e5dc; +} +.arrival-card { + position: absolute; + bottom: 10px; + left: 10px; + right: 10px; + background: #fffffff5; + border-radius: 8px; + padding: 9px 12px; + color: #243647; + box-shadow: 0 3px 10px #20352915; +} +.arrival-card strong { + font-size: 20px; + line-height: 1.2; + display: block; +} +.arrival-card small { + font-size: 11px; + font-weight: 500; +} +.arrival-card > span { + font-size: 9px; + color: #566774; +} +.arrival-card .route-symbol { + position: absolute; + right: 13px; + top: 17px; + font-size: 20px; + color: #328263; +} +.dashboard-widgets { + width: 30%; + padding: 9px; + display: flex; + flex-direction: column; + gap: 8px; + min-width: 145px; +} +.mini-music { + background: #30383e; + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + padding: 12px 6px 8px; + border-radius: 8px; +} +.album-art { + position: relative; + overflow: hidden; + background: #d5bca0; + width: 76px; + height: 76px; + border-radius: 5px; + isolation: isolate; +} +.album-art:before, +.album-art:after { + content: ""; + position: absolute; + border-radius: 50%; + width: 115%; + height: 65%; + background: #6e7c73; + left: -25%; + bottom: -9%; + transform: rotate(24deg); +} +.album-art:after { + left: 35%; + bottom: -10%; + background: #3e625c; + transform: rotate(-25deg); +} +.album-art > span { + position: absolute; + right: 15%; + top: 14%; + width: 21%; + height: 21%; + border-radius: 50%; + background: #f6e4bd; +} +.mini-music > strong { + font-size: 12px; + font-weight: 500; + margin-top: 9px; +} +.mini-music > span { + font-size: 8px; + color: #c1c7cb; + margin-top: 1px; +} +.music-controls { + display: flex; + align-items: center; + justify-content: center; + gap: 24px; + font-size: 23px; + line-height: 1.2; + margin-top: 12px; + color: #edf3f6; +} +.music-controls > span { + font-size: 20px; +} +.destination-widget { + display: flex; + gap: 7px; + align-items: center; + padding: 11px 7px; + background: #30383e; + border-radius: 8px; +} +.home-symbol { + font-size: 25px; + color: #aacbf5; +} +.destination-widget strong { + font-size: 10px; + display: block; + font-weight: 500; +} +.destination-widget div > span { + font-size: 7px; + color: #c1c7cb; +} +.preview-status { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 21px 14px; + font-size: 9px; + color: var(--muted); +} +.preview-status > span:first-child { + display: flex; + align-items: center; + gap: 6px; +} +.preview-status .mono { + font-size: 8px; + letter-spacing: 0.7px; +} +.demo-caption { + display: flex; + justify-content: center; + align-items: baseline; + gap: 6px; + font-size: 10px; + color: var(--muted); + margin-top: 17px; + line-height: 1.8; + text-align: center; +} +.demo-caption > span { + color: var(--blue); +} +.music-display { + padding: 26px; + align-items: center; + justify-content: center; + gap: 28px; + background: #24322f; +} +.music-art-large { + width: 168px; + height: 190px; + flex-shrink: 0; +} +.music-art-large > div { + position: relative; + z-index: 2; + color: #354b42; + font-size: 28px; + font-weight: 800; + line-height: 0.95; + letter-spacing: -2px; + padding: 17px; +} +.music-copy .eyebrow { + font-size: 7px; + letter-spacing: 0.8px; + color: #c4d4c5; + margin-bottom: 8px; +} +.music-copy h3 { + font-size: 20px; + font-weight: 550; + line-height: 1.4; +} +.music-copy p { + font-size: 9px; + line-height: 1.9; + color: #c4d4ce; + margin-top: 9px; +} +.illustrated-track { + display: flex; + flex-direction: column; + margin-top: 16px; + gap: 3px; +} +.illustrated-track > span:first-child { + font-size: 11px; +} +.illustrated-track > span:last-child { + font-size: 8px; + color: #c4d4ce; +} +.track-progress { + height: 2px; + background: #63736e; + margin-top: 9px; +} +.track-progress span { + display: block; + height: 100%; + width: 35%; + background: #e4eadf; +} +.music-copy .music-controls { + font-size: 20px; + margin-top: 7px; + gap: 28px; +} +.music-copy .music-controls > span { + font-size: 14px; +} +.connection-display { + align-items: center; + flex-direction: column; + justify-content: center; + background: #202e43; + text-align: center; + gap: 7px; +} +.connection-symbol { + font-size: 32px; + color: #a3c1f7; + line-height: 0.8; +} +.connection-display h3 { + font-size: 20px; + line-height: 1.4; + font-weight: 550; +} +.connection-display p { + font-size: 10px; + color: #c2d0e4; + line-height: 1.7; +} +.pair-code { + display: flex; + gap: 6px; + margin: 4px 0; +} +.pair-code span { + font: 22px monospace; + border: 1px solid #51627d; + background: #2c3e58; + border-radius: 5px; + padding: 5px 10px; +} +.connection-footnote { + font-size: 8px; + color: #b2c5e1; +} +.section-intro { + display: flex; + justify-content: space-between; + align-items: flex-end; + margin-bottom: 42px; +} +.section-intro > p { + color: var(--muted); + line-height: 1.9; + font-size: 13px; + padding-bottom: 5px; +} +.feature-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + border-top: 1px solid var(--line); + border-bottom: 1px solid var(--line); +} +.feature-grid article { + padding: 28px 30px 30px 0; +} +.feature-grid article + article { + border-left: 1px solid var(--line); + padding-left: 30px; +} +.feature-number { + font-size: 9px; + color: var(--faint); + letter-spacing: 1.3px; + display: block; +} +.feature-icon { + width: 30px; + height: 30px; + fill: none; + stroke: var(--blue); + stroke-width: 1.5; + margin: 25px 0 20px; +} +.feature-grid h3 { + font-size: 17px; + letter-spacing: -0.4px; +} +.feature-grid p { + color: var(--muted); + font-size: 12px; + line-height: 1.9; + margin-top: 12px; + max-width: 300px; +} +.feature-tags { + display: flex; + gap: 7px; + margin-top: 22px; +} +.feature-tags span { + font-size: 9px; + color: var(--muted); + background: var(--soft); + border-radius: 4px; + padding: 3px 7px; +} +.start-section { + border-block: 1px solid var(--line); + background: var(--surface); +} +.start-layout { + display: grid; + grid-template-columns: 1fr 1.2fr; + gap: 80px; +} +.start-intro > p:not(.eyebrow) { + color: var(--muted); + font-size: 12px; + line-height: 1.9; + margin-top: 20px; +} +.start-intro .button { + margin-top: 24px; +} +.start-intro .download-note { + font-size: 10px !important; + line-height: 1.9 !important; + margin-top: 12px !important; +} +.start-intro code { + font-size: 10px; +} +.text-link { + color: var(--blue); + font-size: 11px; + font-weight: 500; + display: inline-block; +} +.text-link > span { + margin-left: 4px; +} +.start-intro .text-link { + margin-top: 14px; +} +.setup-steps { + list-style: none; + padding: 0; + margin: 0; +} +.setup-steps li { + display: flex; + gap: 22px; + position: relative; + padding-bottom: 32px; +} +.setup-steps li:not(:last-child):before { + content: ""; + position: absolute; + left: 17px; + top: 43px; + bottom: 7px; + width: 1px; + background: var(--line); +} +.setup-steps li:last-child { + padding-bottom: 0; +} +.setup-number { + flex-shrink: 0; + display: grid; + place-items: center; + font: 11px monospace; + width: 36px; + height: 36px; + border: 1px solid var(--line); + border-radius: 50%; + color: var(--blue); + background: var(--bg); +} +.setup-steps h3 { + font-size: 16px; + line-height: 1.7; + margin-top: 4px; +} +.setup-steps p { + color: var(--muted); + font-size: 12px; + line-height: 1.9; + margin-top: 9px; + max-width: 430px; +} +.setup-steps .text-link { + margin-top: 9px; +} +.step-hint { + display: block; + font-size: 10px; + color: var(--muted); + padding-left: 9px; + border-left: 2px solid var(--line); + margin-top: 10px; +} +.faq-section { + display: grid; + grid-template-columns: 1fr 1.2fr; + gap: 80px; +} +.faq-intro .text-link { + margin-top: 24px; +} +.faq-list details { + border-bottom: 1px solid var(--line); +} +.faq-list details:first-child { + border-top: 1px solid var(--line); +} +.faq-list summary { + display: flex; + justify-content: space-between; + gap: 16px; + align-items: center; + list-style: none; + cursor: pointer; + padding: 21px 0; + font-size: 13px; + font-weight: 550; +} +.faq-list summary::-webkit-details-marker { + display: none; +} +.faq-list summary > span { + font-size: 20px; + font-weight: 300; + color: var(--faint); + transition: transform 0.2s; +} +.faq-list details[open] summary > span { + transform: rotate(45deg); +} +.faq-list details > p { + font-size: 12px; + color: var(--muted); + line-height: 1.9; + padding: 0 24px 22px 0; +} +.faq-list p a { + color: var(--blue); + text-decoration: underline; + text-underline-offset: 3px; +} +.closing { + display: flex; + align-items: center; + justify-content: space-between; + gap: 32px; + padding: 38px; + background: var(--blue-soft); + border: 1px solid color-mix(in srgb, var(--blue) 12%, transparent); + border-radius: 10px; +} +.closing .eyebrow { + font-size: 9px; + letter-spacing: 1.4px; + margin-bottom: 12px; +} +.closing h2 { + font-size: 25px; + letter-spacing: -0.8px; +} +.closing p:not(.eyebrow) { + color: var(--muted); + font-size: 12px; + margin-top: 9px; +} +.closing .button { + font-size: 12px; +} +.site-footer { + margin-top: 68px; + padding-bottom: 25px; +} +.footer-top { + display: flex; + align-items: center; + gap: 25px; + padding-bottom: 24px; + border-bottom: 1px solid var(--line); +} +.footer-top .brand { + font-size: 17px; +} +.footer-top > span { + font-size: 10px; + color: var(--muted); +} +.footer-top > div { + margin-left: auto; + display: flex; + gap: 23px; + font-size: 10px; + color: var(--muted); +} +.footer-bottom { + display: flex; + justify-content: space-between; + gap: 20px; + padding-top: 18px; + font-size: 9px; + color: var(--muted); +} +.footer-bottom p { + text-align: right; +} +.not-found { + min-height: 100svh; + display: grid; + place-items: center; + padding: 32px; +} +.not-found main { + max-width: 600px; +} +.not-found .brand { + margin-bottom: 60px; +} +.not-found h1 { + font-size: 54px; +} +.not-found main > p:not(.eyebrow) { + color: var(--muted); + margin-top: 20px; +} +.not-found .button { + margin-top: 28px; +} +@media (min-width: 1500px) { + .hero { + padding-top: 80px; + padding-bottom: 50px; + } +} +@media (max-width: 1000px) { + .workspace-body { + grid-template-columns: 31% 69%; + } + .source-panel { + padding: 20px 16px 16px; + } + .panel-heading .mono { + display: none; + } + .device-step { + gap: 8px; + } + .device-step strong { + font-size: 10px; + } + .device-step p { + font-size: 9px; + } + .step-number { + display: none; + } + .car-display { + height: 272px; + } + .display-shell { + padding: 16px 14px 12px; + } + .preview-toolbar { + padding-inline: 14px; + } + .dashboard-widgets { + min-width: 124px; + padding: 7px; + } + .destination-widget { + padding: 8px 5px; + } + .destination-widget div > span { + font-size: 6px; + } + .source-panel .local-note { + margin-top: auto; + } + .device-flow { + margin-bottom: 24px; + } + .preview-label { + display: none; + } + .turn-card { + padding: 9px; + gap: 6px; + left: 8px; + right: 8px; + } + .turn-card strong { + font-size: 11px; + } + .turn-card div > span { + font-size: 8px; + } + .music-display { + padding: 22px 15px; + gap: 18px; + } + .music-art-large { + width: 125px; + height: 170px; + } + .music-copy h3 { + font-size: 18px; + } + .start-layout, + .faq-section { + gap: 40px; + } + .feature-grid h3 { + font-size: 15px; + } + .feature-grid article { + padding-right: 22px; + } + .feature-grid article + article { + padding-left: 22px; + } + .footer-top { + gap: 15px; + } + .footer-top > div { + gap: 13px; + } +} +@media (max-width: 760px) { + .container, + .header-inner { + width: calc(100% - 40px); + } + .site-header { + height: 66px; + } + .site-header nav { + gap: 18px; + font-size: 12px; + } + .brand { + font-size: 18px; + } + .brand-label { + display: none; + } + .header-actions { + gap: 10px; + } + .github-link span { + display: none; + } + .hero { + padding-top: 48px; + padding-bottom: 34px; + } + h1 { + font-size: 48px; + letter-spacing: -2px; + } + .hero-description { + font-size: 14px; + } + .hero-notes { + gap: 17px; + } + .workspace-body { + display: flex; + flex-direction: column; + } + .source-panel { + border-right: 0; + border-bottom: 1px solid var(--line); + padding: 17px 18px; + } + .panel-heading { + font-size: 10px; + } + .panel-heading .mono { + display: block; + } + .device-flow { + display: flex; + align-items: center; + justify-content: space-between; + margin: 17px 0 0; + gap: 6px; + } + .device-step { + flex-direction: column; + gap: 7px; + text-align: center; + flex: 1; + } + .device-step strong { + font-size: 10px; + white-space: nowrap; + } + .device-step p { + display: none; + } + .flow-line { + height: 1px; + min-width: 12px; + width: 22px; + margin: 0 0 22px; + border-left: 0; + border-top: 1px dashed var(--line); + flex: 0 1 22px; + } + .flow-line span { + display: none; + } + .local-note { + display: none; + } + .preview-toolbar { + height: 50px; + padding: 0 18px; + } + .preview-label { + display: flex; + } + .display-shell { + padding: 16px 16px 12px; + } + .car-display { + height: 280px; + } + .dashboard-widgets { + min-width: 145px; + } + .turn-card { + padding: 12px; + left: 12px; + right: 12px; + } + .turn-card strong { + font-size: 13px; + } + .turn-card div > span { + font-size: 9px; + } + .mini-music { + padding-top: 13px; + } + .destination-widget { + padding: 10px; + } + .destination-widget div > span { + font-size: 7px; + } + .preview-status { + padding: 0 18px 13px; + } + .demo-caption { + font-size: 9px; + padding-inline: 10px; + } + .section { + padding-block: 64px; + } + h2 { + font-size: 32px; + letter-spacing: -1.3px; + } + .section-intro { + margin-bottom: 28px; + gap: 20px; + } + .section-intro > p { + font-size: 11px; + } + .feature-grid article { + padding: 22px 16px 24px 0; + } + .feature-grid article + article { + padding-left: 16px; + } + .feature-grid h3 { + font-size: 14px; + } + .feature-grid p { + font-size: 11px; + } + .feature-number { + font-size: 8px; + } + .feature-tags { + flex-wrap: wrap; + gap: 4px; + } + .feature-tags span { + font-size: 8px; + } + .feature-icon { + margin-block: 20px 16px; + } + .start-layout, + .faq-section { + grid-template-columns: 1fr; + gap: 38px; + } + .start-intro h2 br, + .faq-intro h2 br { + display: none; + } + .start-intro > p:not(.eyebrow) { + margin-top: 14px; + } + .start-intro .download-note br { + display: none; + } + .setup-steps p { + max-width: 100%; + } + .setup-steps li { + gap: 18px; + } + .faq-intro .text-link { + margin-top: 14px; + } + .closing { + padding: 28px; + align-items: flex-start; + flex-direction: column; + gap: 24px; + } + .closing h2 { + font-size: 22px; + } + .footer-top { + flex-wrap: wrap; + } + .footer-top > div { + width: 100%; + margin: 0; + gap: 20px; + } + .footer-bottom { + flex-direction: column; + gap: 8px; + } + .footer-bottom p { + text-align: left; + } + .site-footer { + margin-top: 44px; + } + .music-art-large { + width: 165px; + height: 190px; + } + .music-display { + gap: 25px; + } + .music-copy h3 { + font-size: 20px; + } +} +@media (max-width: 480px) { + .container, + .header-inner { + width: calc(100% - 32px); + } + .header-inner { + gap: 12px; + } + .brand { + font-size: 17px; + gap: 8px; + } + .brand img { + width: 28px; + height: 28px; + border-radius: 7px; + } + .site-header nav { + gap: 14px; + font-size: 11px; + } + .site-header nav a:first-child { + display: none; + } + .header-actions { + gap: 5px; + } + .github-link { + display: none; + } + .icon-button { + width: 32px; + height: 36px; + } + .hero { + padding-top: 39px; + } + .announcement { + font-size: 10px; + margin-bottom: 23px; + padding: 4px 10px; + } + h1 { + font-size: 41px; + line-height: 1.35; + letter-spacing: -2px; + } + .hero-description { + font-size: 13px; + margin-top: 17px; + } + .hero-actions { + gap: 8px; + margin-top: 24px; + } + .button { + font-size: 11px; + padding: 11px 13px; + gap: 6px; + min-height: 44px; + } + .hero-notes { + gap: 12px; + font-size: 9px; + margin-top: 17px; + } + .hero-notes svg { + width: 10px; + } + .workspace-bar { + padding: 0 12px; + gap: 12px; + height: 38px; + } + .workspace-title { + font-size: 9px; + } + .workspace-title > span { + margin-inline: 5px; + } + .demo-badge { + font-size: 8px; + padding: 1px 5px; + letter-spacing: 0; + } + .window-dots { + gap: 4px; + } + .window-dots i { + width: 6px; + height: 6px; + } + .source-panel { + padding: 14px; + } + .device-icon { + width: 34px; + height: 34px; + border-radius: 8px; + } + .device-icon svg { + width: 19px; + } + .device-step strong { + font-size: 9px; + } + .preview-toolbar { + padding: 0 10px; + height: 48px; + } + .preview-tabs { + gap: 2px; + } + .preview-tabs button { + font-size: 10px; + padding-inline: 9px; + min-height: 36px; + } + .preview-label { + font-size: 8px; + } + .display-shell { + padding: 10px 9px; + } + .car-display { + height: 235px; + border-width: 4px; + border-radius: 10px; + } + .car-sidebar { + width: 35px; + padding-top: 10px; + } + .car-time { + font-size: 10px; + } + .signal { + font-size: 6px; + margin-bottom: 12px; + } + .dock-icon { + width: 24px; + height: 24px; + font-size: 19px; + margin-bottom: 9px; + border-radius: 6px; + } + .dock-home { + font-size: 22px; + } + .dashboard-widgets { + min-width: 95px; + width: 31%; + padding: 6px; + gap: 6px; + } + .album-art { + width: 57px; + height: 57px; + } + .mini-music { + padding: 9px 4px 6px; + } + .mini-music > strong { + font-size: 9px; + margin-top: 8px; + } + .mini-music > span { + font-size: 7px; + } + .music-controls { + gap: 14px; + font-size: 20px; + margin-top: 11px; + } + .music-controls > span { + font-size: 15px; + } + .destination-widget { + padding: 9px 5px; + gap: 5px; + } + .destination-widget strong { + font-size: 8px; + } + .destination-widget div > span { + display: none; + } + .home-symbol { + font-size: 22px; + } + .turn-card { + left: 6px; + right: 6px; + top: 8px; + gap: 7px; + padding: 8px; + } + .turn-card > span { + font-size: 25px; + } + .turn-card strong { + font-size: 10px; + } + .turn-card div > span { + font-size: 7px; + } + .arrival-card { + bottom: 8px; + left: 6px; + right: 6px; + padding: 8px; + } + .arrival-card strong { + font-size: 17px; + } + .arrival-card small { + font-size: 9px; + } + .arrival-card > span { + font-size: 7px; + } + .arrival-card .route-symbol { + right: 8px; + font-size: 17px; + } + .preview-status { + font-size: 8px; + padding: 0 12px 11px; + } + .preview-status .mono { + font-size: 7px; + letter-spacing: 0.1px; + } + .demo-caption { + font-size: 9px; + margin-top: 13px; + padding: 0 6px; + } + .section { + padding-block: 54px; + } + .eyebrow { + font-size: 9px; + letter-spacing: 1.2px; + margin-bottom: 14px; + } + h2 { + font-size: 29px; + } + .section-intro { + display: block; + margin-bottom: 26px; + } + .section-intro > p { + font-size: 12px; + margin-top: 15px; + } + .section-intro > p br { + display: none; + } + .feature-grid { + grid-template-columns: 1fr; + } + .feature-grid article, + .feature-grid article + article { + padding: 26px 0; + border-left: 0; + position: relative; + } + .feature-grid article + article { + border-top: 1px solid var(--line); + } + .feature-icon { + position: absolute; + right: 3px; + top: 21px; + width: 26px; + height: 26px; + margin: 0; + } + .feature-number { + font-size: 9px; + } + .feature-grid h3 { + font-size: 17px; + margin-top: 20px; + } + .feature-grid p { + font-size: 12px; + margin-top: 10px; + max-width: 100%; + } + .feature-tags { + margin-top: 16px; + gap: 7px; + } + .feature-tags span { + font-size: 9px; + } + .setup-steps li { + gap: 14px; + } + .setup-steps h3 { + font-size: 14px; + } + .setup-steps p { + font-size: 12px; + } + .setup-number { + width: 32px; + height: 32px; + font-size: 10px; + } + .setup-steps li:not(:last-child):before { + left: 15px; + top: 39px; + } + .start-intro > p:not(.eyebrow) { + font-size: 12px; + } + .start-intro .button { + font-size: 12px; + } + .faq-section { + gap: 28px; + } + .faq-list summary { + font-size: 12px; + min-height: 64px; + padding-block: 18px; + } + .faq-list details > p { + font-size: 12px; + padding-right: 8px; + } + .closing { + padding: 25px 22px; + } + .closing h2 { + font-size: 20px; + line-height: 1.6; + } + .closing .eyebrow { + font-size: 8px; + letter-spacing: 0.8px; + } + .closing p:not(.eyebrow) { + font-size: 11px; + } + .closing .button { + font-size: 11px; + } + .footer-top > span { + font-size: 9px; + } + .footer-bottom { + font-size: 8px; + } + .music-display { + padding: 16px 10px; + gap: 15px; + } + .music-art-large { + width: 93px; + height: 135px; + } + .music-art-large > div { + font-size: 23px; + padding: 12px; + } + .music-copy .eyebrow { + font-size: 6px; + letter-spacing: 0; + margin-bottom: 8px; + } + .music-copy h3 { + font-size: 17px; + } + .music-copy p { + font-size: 8px; + line-height: 1.7; + margin-top: 7px; + } + .illustrated-track { + margin-top: 10px; + } + .illustrated-track > span:first-child { + font-size: 9px; + } + .illustrated-track > span:last-child { + font-size: 7px; + } + .music-copy .music-controls { + font-size: 18px; + } + .connection-display { + gap: 5px; + } + .connection-symbol { + font-size: 28px; + } + .connection-display h3 { + font-size: 17px; + } + .connection-display p { + font-size: 9px; + } + .pair-code { + gap: 5px; + } + .pair-code span { + font-size: 20px; + padding: 4px 8px; + } + .connection-footnote { + font-size: 7px; + } +} +@media (prefers-reduced-motion: reduce) { + html { + scroll-behavior: auto; + } + *, + *:before, + *:after { + transition: none !important; + animation: none !important; + } + .button:hover { + transform: none; + } +} + +/* Keep decorative symbols independent of installed font glyphs. */ +.small-icon svg { + width: 18px; + height: 18px; +} +.turn-card > span svg { + width: 27px; + height: 27px; +} +.demo-caption > span svg { + width: 12px; + height: 12px; +} +.connection-symbol svg { + width: 28px; + height: 28px; +} +.dock-icon svg { + width: 19px; + height: 19px; +} +/* Body copy remains readable outside the compact illustrative workspace. */ +.feature-grid p, +.setup-steps p, +.faq-list details > p, +.start-intro > p:not(.eyebrow) { + font-size: 14px; +} +.text-link { + font-size: 12px; +} +.footer-top > span, +.footer-top > div { + font-size: 11px; +} +.footer-bottom { + font-size: 10px; +} +@media (max-width: 480px) { + .feature-grid p, + .setup-steps p, + .faq-list details > p, + .start-intro > p:not(.eyebrow) { + font-size: 13px; + } + .turn-card > span svg { + width: 21px; + height: 21px; + } + .footer-top > span { + font-size: 9px; + } + .footer-bottom { + font-size: 9px; + } +} diff --git a/website/test/build.test.mjs b/website/test/build.test.mjs new file mode 100644 index 00000000..7295c28d --- /dev/null +++ b/website/test/build.test.mjs @@ -0,0 +1,79 @@ +import assert from "node:assert/strict"; +import { readFile, stat } from "node:fs/promises"; +import test from "node:test"; + +const dist = new URL("../dist/", import.meta.url); + +for (const page of ["index.html", "404.html", "docs/index.html", "docs/faq/index.html"]) { + test(`${page} ships external assets compatible with the Cloudflare CSP`, async () => { + const html = await readFile(new URL(page, dist), "utf8"); + assert.doesNotMatch( + html, + /]*)>([\s\S]*?)<\/script>/gi), + ]; + if (page === "index.html") + assert.ok(scripts.length > 0, "Homepage must load its interactions"); + if (page === "index.html") + assert.match( + html, + /href="\/download"/, + "Download button must use the resolver", + ); + const sources = []; + for (const [, attributes, content] of scripts) { + assert.equal(content.trim(), "", "Astro must not inline small scripts"); + const source = attributes.match(/\bsrc="([^"]+)"/); + assert.ok(source, "Scripts must have an external source"); + sources.push(source[1]); + } + const styles = [...html.matchAll(/]*rel="stylesheet"[^>]*>/gi)]; + assert.ok( + styles.length > 0, + "Global styles must be emitted for every route", + ); + sources.push(...styles.map(([tag]) => tag.match(/\bhref="([^"]+)"/)[1])); + for (const source of sources) { + assert.match( + source, + /^\/_astro\//, + "Only locally bundled assets may load", + ); + assert.ok((await stat(new URL(`.${source}`, dist))).isFile(), source); + } + if (page === "404.html") + assert.match(html, /name="robots" content="noindex"/); + if (page.startsWith("docs/")) { + assert.equal([...html.matchAll(/]*id="([^"]+)"/g)]; + assert.ok(headings.length > 0, "Markdown headings must be rendered"); + for (const [, id] of headings) { + assert.ok(html.includes(`href="#${id}"`), `Missing TOC link for ${id}`); + } + assert.match(html, /href="\/docs\/"/); + assert.match(html, /href="\/docs\/faq\/"/); + } + }); +} + +test("static routes preserve the repository icon, license, and Cloudflare headers", async () => { + for (const [output, input] of [ + ["assets/app-icon.svg", "../docs/assets/app-icon.svg"], + [ + "assets/Material-Symbols-Apache-2.0.txt", + "../docs/licenses/Material-Symbols-Apache-2.0.txt", + ], + ["_headers", "public/_headers"], + ["_routes.json", "public/_routes.json"], + ]) { + const expected = new URL(input, new URL("../", import.meta.url)); + assert.deepEqual( + await readFile(new URL(output, dist)), + await readFile(expected), + ); + } +}); diff --git a/website/test/download.test.mjs b/website/test/download.test.mjs new file mode 100644 index 00000000..ecf165f6 --- /dev/null +++ b/website/test/download.test.mjs @@ -0,0 +1,347 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { createDownloadHandler } from "../worker/download.ts"; + +const START = Date.parse("2026-10-23T12:00:00Z"); +const RUN_ID = 39951112470; +const ARTIFACT_ID = 12501440441; +const LOCATION = `https://github.com/fython/wheelplay/actions/runs/${RUN_ID}/artifacts/${ARTIFACT_ID}`; +const run = (id = RUN_ID) => ({ + id, + head_branch: "main", + status: "completed", + conclusion: "success", +}); +const artifact = (overrides = {}) => ({ + id: ARTIFACT_ID, + name: "wheelplay-debug-apk", + expired: false, + expires_at: new Date(START + 86_400_000).toISOString(), + ...overrides, +}); + +function harness( + responses = [{ workflow_runs: [run()] }, { artifacts: [artifact()] }], +) { + let time = START; + const calls = []; + const writes = []; + const stored = new Map(); + const cache = { + async match(key) { + return stored.get(key.url)?.clone(); + }, + async put(key, response) { + stored.set(key.url, response.clone()); + }, + }; + const ctx = { + waitUntil(promise) { + writes.push(promise); + }, + }; + const fetch = async (url, init) => { + calls.push({ url, init }); + const response = responses.shift(); + if (typeof response === "function") return response(); + if (response instanceof Response) return response; + assert.ok(response, "Unexpected extra GitHub API request"); + return Response.json(response); + }; + const makeHandler = () => createDownloadHandler({ fetch, now: () => time }); + const handler = makeHandler(); + return { + cache, + ctx, + calls, + stored, + responses, + makeHandler, + advance(ms) { + time += ms; + }, + async flush() { + await Promise.all(writes); + }, + get(path = "/download", options = {}, env = {}) { + return handler( + new Request(`https://wheelplay.example${path}`, options), + env, + ctx, + cache, + ); + }, + }; +} + +test("cold request makes two bounded metadata calls and returns only the GitHub UI redirect", async () => { + const h = harness(); + const response = await h.get( + "/download", + {}, + { GITHUB_TOKEN: "test-secret" }, + ); + assert.equal(response.status, 302); + assert.equal(response.headers.get("Location"), LOCATION); + assert.equal(await response.text(), ""); + assert.equal(response.headers.get("Cache-Control"), "no-store"); + assert.equal(h.calls.length, 2); + const runs = new URL(h.calls[0].url); + assert.equal( + runs.pathname, + "/repos/fython/wheelplay/actions/workflows/debug-build.yml/runs", + ); + assert.deepEqual(Object.fromEntries(runs.searchParams), { + branch: "main", + status: "success", + per_page: "1", + }); + const artifacts = new URL(h.calls[1].url); + assert.equal( + artifacts.pathname, + `/repos/fython/wheelplay/actions/runs/${RUN_ID}/artifacts`, + ); + assert.equal(artifacts.searchParams.get("name"), "wheelplay-debug-apk"); + assert.equal(artifacts.searchParams.get("per_page"), "100"); + for (const { init } of h.calls) { + assert.equal(init.headers.Authorization, "Bearer test-secret"); + assert.equal(init.redirect, "manual"); + assert.ok(init.signal instanceof AbortSignal); + } + await h.flush(); + const cached = [...h.stored.values()][0]; + assert.equal(cached.headers.get("Cache-Control"), "public, max-age=300"); + assert.equal((await cached.clone().text()).includes("test-secret"), false); +}); + +test("memory and edge hits ignore query strings, client cache headers, and HEAD method", async () => { + const h = harness(); + await h.get(); + await h.flush(); + const head = await h.get("/download?force=1", { + method: "HEAD", + headers: { "Cache-Control": "no-cache" }, + }); + assert.equal(head.headers.get("Location"), LOCATION); + assert.equal(await head.text(), ""); + assert.equal(h.calls.length, 2); + const otherIsolate = h.makeHandler(); + const cached = await otherIsolate( + new Request("https://wheelplay.example/download/?random=2"), + {}, + h.ctx, + h.cache, + ); + assert.equal(cached.headers.get("Location"), LOCATION); + assert.equal(h.calls.length, 2); + assert.equal(h.stored.size, 1); + assert.match([...h.stored.keys()][0], /\/__wheelplay\/download-cache\/v1$/); +}); + +test("concurrent clicks share one in-flight query", async () => { + let release; + const first = new Promise((resolve) => { + release = resolve; + }); + const h = harness([() => first, { artifacts: [artifact()] }]); + const requests = Array.from({ length: 20 }, (_, i) => + h.get(`/download?request=${i}`), + ); + await new Promise((resolve) => setImmediate(resolve)); + assert.equal(h.calls.length, 1); + release(Response.json({ workflow_runs: [run()] })); + const results = await Promise.all(requests); + assert.ok( + results.every((response) => response.headers.get("Location") === LOCATION), + ); + assert.equal(h.calls.length, 2); +}); + +test("five-minute expiry re-resolves the latest successful run", async () => { + const h = harness(); + await h.get(); + await h.flush(); + h.advance(300_001); + h.responses.push( + { workflow_runs: [run(RUN_ID + 1)] }, + { artifacts: [artifact({ id: ARTIFACT_ID + 1 })] }, + ); + const fresh = await h.get(); + assert.equal(h.calls.length, 4); + assert.equal( + fresh.headers.get("Location"), + `https://github.com/fython/wheelplay/actions/runs/${RUN_ID + 1}/artifacts/${ARTIFACT_ID + 1}`, + ); +}); + +test("cache freshness never exceeds the artifact expiry", async () => { + const h = harness([ + { workflow_runs: [run()] }, + { + artifacts: [ + artifact({ expires_at: new Date(START + 2_000).toISOString() }), + ], + }, + ]); + await h.get(); + await h.flush(); + assert.equal( + [...h.stored.values()][0].headers.get("Cache-Control"), + "public, max-age=2", + ); + h.advance(2_001); + h.responses.push( + { workflow_runs: [run()] }, + { artifacts: [artifact({ expired: true })] }, + ); + const response = await h.get(); + assert.equal(response.status, 404); + assert.equal(response.headers.get("Location"), null); +}); + +test("no successful run is negatively cached for one minute", async () => { + const h = harness([{ workflow_runs: [] }]); + assert.equal((await h.get()).status, 404); + await h.flush(); + const otherIsolate = h.makeHandler(); + assert.equal( + ( + await otherIsolate( + new Request("https://wheelplay.example/download"), + {}, + h.ctx, + h.cache, + ) + ).status, + 404, + ); + assert.equal(h.calls.length, 1); + h.advance(60_001); + h.responses.push({ workflow_runs: [run()] }, { artifacts: [artifact()] }); + assert.equal((await h.get()).status, 302); +}); + +for (const [name, artifacts] of [ + ["missing", []], + ["wrong name", [artifact({ name: "wheelplay-browser-runtime-tests" })]], + ["expired flag", [artifact({ expired: true })]], + [ + "expired timestamp", + [artifact({ expires_at: new Date(START - 1).toISOString() })], + ], + ["invalid timestamp", [artifact({ expires_at: "invalid" })]], +]) { + test(`${name} artifact does not fall back to an older build`, async () => { + const h = harness([{ workflow_runs: [run()] }, { artifacts }]); + assert.equal((await h.get()).status, 404); + assert.equal((await h.get()).status, 404); + assert.equal(h.calls.length, 2); + }); +} + +test("a similarly named artifact cannot redirect the user elsewhere", async () => { + const h = harness([ + { workflow_runs: [run()] }, + { + artifacts: [ + artifact({ name: "wheelplay-debug-apk-malicious", id: 1 }), + artifact({ + archive_download_url: "https://elsewhere.example/archive.zip", + }), + ], + }, + ]); + assert.equal((await h.get()).headers.get("Location"), LOCATION); +}); + +for (const [name, response, expected] of [ + [ + "primary rate limit", + new Response("rate limit", { + status: 403, + headers: { + "X-RateLimit-Remaining": "0", + "X-RateLimit-Reset": String(START / 1_000 + 600), + }, + }), + 600, + ], + [ + "secondary rate limit", + new Response("rate limit", { + status: 429, + headers: { "Retry-After": "120" }, + }), + 120, + ], + ["unavailable", new Response("upstream details", { status: 500 }), 60], + [ + "unexpected API redirect", + new Response(null, { + status: 302, + headers: { Location: "https://elsewhere.example/archive.zip" }, + }), + 60, + ], + ["invalid JSON", new Response("invalid", { status: 200 }), 60], + ["invalid shape", Response.json({ message: "not runs" }), 60], + [ + "timeout", + () => Promise.reject(new DOMException("Timed out", "TimeoutError")), + 60, + ], +]) { + test(`${name} returns a safe cached error and backs off`, async () => { + const h = harness([response]); + const result = await h.get(); + assert.equal(result.status, 503); + assert.equal(result.headers.get("Retry-After"), String(expected)); + assert.equal(result.headers.get("Location"), null); + assert.doesNotMatch(await result.text(), /upstream details/); + await h.get(); + assert.equal(h.calls.length, 1); + await h.flush(); + const otherIsolate = h.makeHandler(); + assert.equal( + ( + await otherIsolate( + new Request("https://wheelplay.example/download"), + {}, + h.ctx, + h.cache, + ) + ).status, + 503, + ); + assert.equal(h.calls.length, 1); + }); +} + +test("unusable latest-run metadata never redirects to the wrong branch", async () => { + const h = harness([ + { workflow_runs: [{ ...run(), head_branch: "feature" }] }, + ]); + assert.equal((await h.get()).status, 503); + assert.equal(h.calls.length, 1); +}); + +test("unsupported methods and paths do not query GitHub", async () => { + const h = harness(); + assert.equal((await h.get("/download", { method: "POST" })).status, 405); + assert.equal((await h.get("/download/anything")).status, 404); + assert.equal(h.calls.length, 0); +}); + +test("cache service failure leaves a usable in-memory redirect", async () => { + const h = harness(); + h.cache.match = async () => { + throw new Error("cache unavailable"); + }; + h.cache.put = async () => { + throw new Error("cache unavailable"); + }; + assert.equal((await h.get()).headers.get("Location"), LOCATION); + await h.flush(); + assert.equal((await h.get()).headers.get("Location"), LOCATION); + assert.equal(h.calls.length, 2); +}); diff --git a/website/tsconfig.json b/website/tsconfig.json new file mode 100644 index 00000000..adbbd073 --- /dev/null +++ b/website/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "astro/tsconfigs/strict", + "include": [".astro/types.d.ts", "**/*"], + "exclude": ["dist", "node_modules"] +} diff --git a/website/worker/download.ts b/website/worker/download.ts new file mode 100644 index 00000000..ed012fd0 --- /dev/null +++ b/website/worker/download.ts @@ -0,0 +1,245 @@ +const REPOSITORY = "fython/wheelplay"; +const WORKFLOW = "debug-build.yml"; +const ARTIFACT = "wheelplay-debug-apk"; +const API = `https://api.github.com/repos/${REPOSITORY}/actions`; +const WORKFLOW_URL = `https://github.com/${REPOSITORY}/actions/workflows/${WORKFLOW}`; +const SUCCESS_TTL = 300; +const FAILURE_TTL = 60; +const TIMEOUT_MS = 5_000; + +export interface DownloadEnv { + /** Optional Worker/Pages secret; never returned to the browser. */ + GITHUB_TOKEN?: string; +} + +export interface DownloadContext { + waitUntil(promise: Promise): void; +} + +export interface DownloadCache { + match(request: Request): Promise; + put(request: Request, response: Response): Promise; +} + +interface Result { + status: 302 | 404 | 503; + location?: string; + message?: string; + validUntil: number; +} + +interface Run { + id: number; + head_branch: string; + status: string; + conclusion: string; +} + +interface Artifact { + id: number; + name: string; + expired: boolean; + expires_at: string; +} + +class GitHubUnavailable extends Error { + retryAfter: number; + constructor(retryAfter = FAILURE_TTL) { + super("GitHub metadata unavailable"); + this.retryAfter = retryAfter; + } +} + +const validId = (id: number) => Number.isSafeInteger(id) && id > 0; + +/** One bounded memory record and one in-flight lookup per isolate; no user-keyed map. */ +export function createDownloadHandler({ + fetch: fetchMetadata = globalThis.fetch, + now = Date.now, +}: { + fetch?: typeof globalThis.fetch; + now?: () => number; +} = {}) { + let memory: Result | undefined; + let pending: Promise | undefined; + + async function github(path: string, env: DownloadEnv): Promise { + const headers: Record = { + Accept: "application/vnd.github+json", + "X-GitHub-Api-Version": "2026-03-10", + "User-Agent": "WheelPlay-Download-Resolver", + }; + if (env.GITHUB_TOKEN) headers.Authorization = `Bearer ${env.GITHUB_TOKEN}`; + const response = await fetchMetadata(`${API}/${path}`, { + headers, + signal: AbortSignal.timeout(TIMEOUT_MS), + // workerd supports manual/follow, not the browser-only "error" mode. + redirect: "manual", + cache: "no-store", + }); + if (!response.ok) { + // Respect primary/secondary rate limits without repeatedly parsing error bodies. + const retry = response.headers.get("Retry-After"); + const retrySeconds = retry + ? /^\d+$/.test(retry) + ? Number(retry) + : (Date.parse(retry) - now()) / 1_000 + : 0; + const resetSeconds = + response.headers.get("X-RateLimit-Remaining") === "0" + ? Number(response.headers.get("X-RateLimit-Reset")) - now() / 1_000 + : 0; + const backoff = Math.max( + FAILURE_TTL, + retrySeconds || 0, + resetSeconds || 0, + ); + await response.body?.cancel(); + throw new GitHubUnavailable(Math.min(3_600, Math.ceil(backoff))); + } + return response.json() as Promise; + } + + function failure( + status: 404 | 503, + message: string, + ttl = FAILURE_TTL, + ): Result { + return { status, message, validUntil: now() + ttl * 1_000 }; + } + + async function resolve(env: DownloadEnv): Promise { + try { + const runs = await github<{ workflow_runs: Run[] }>( + `workflows/${WORKFLOW}/runs?branch=main&status=success&per_page=1`, + env, + ); + if (!Array.isArray(runs.workflow_runs)) throw new GitHubUnavailable(); + const run = runs.workflow_runs[0]; + if (!run) return failure(404, "暂时没有 main 分支的成功构建。"); + if ( + !validId(run.id) || + run.head_branch !== "main" || + run.status !== "completed" || + run.conclusion !== "success" + ) { + throw new GitHubUnavailable(); + } + // GitHub filters by exact name; retain the local check and bound the result size. + const result = await github<{ artifacts: Artifact[] }>( + `runs/${run.id}/artifacts?name=${ARTIFACT}&per_page=100&direction=desc`, + env, + ); + if (!Array.isArray(result.artifacts)) throw new GitHubUnavailable(); + const artifact = result.artifacts.find( + (item) => + item.name === ARTIFACT && + item.expired === false && + validId(item.id) && + Date.parse(item.expires_at) > now(), + ); + if (!artifact) + return failure( + 404, + "最新成功构建中的 wheelplay-debug-apk 不存在或已过期,请稍后再试。", + ); + return { + status: 302, + // Construct the UI URL, never request archive_download_url or relay ZIP/APK bytes. + location: `https://github.com/${REPOSITORY}/actions/runs/${run.id}/artifacts/${artifact.id}`, + validUntil: Math.min( + now() + SUCCESS_TTL * 1_000, + Date.parse(artifact.expires_at), + ), + }; + } catch (error) { + return failure( + 503, + "暂时无法查询 GitHub 构建,请稍后重试,或手动打开构建列表。", + error instanceof GitHubUnavailable ? error.retryAfter : FAILURE_TTL, + ); + } + } + + async function lookup( + env: DownloadEnv, + ctx: DownloadContext, + cache: DownloadCache, + key: Request, + ): Promise { + try { + const cached = await cache.match(key); + if (cached) { + const result = (await cached.json()) as Result; + if (result.validUntil > now()) return result; + } + } catch { + // Cache eviction or cache service failure must not break the download entry. + } + const result = await resolve(env); + const ttl = Math.floor((result.validUntil - now()) / 1_000); + if (ttl > 0) { + // Store a tiny metadata response, including failures, rather than a large API body. + const cached = Response.json(result, { + headers: { "Cache-Control": `public, max-age=${ttl}` }, + }); + ctx.waitUntil(cache.put(key, cached).catch(() => {})); + } + return result; + } + + return async function download( + request: Request, + env: DownloadEnv, + ctx: DownloadContext, + cache: DownloadCache, + ): Promise { + const url = new URL(request.url); + if (url.pathname !== "/download" && url.pathname !== "/download/") { + return new Response("Not found", { status: 404 }); + } + if (request.method !== "GET" && request.method !== "HEAD") { + return new Response("Method not allowed", { + status: 405, + headers: { Allow: "GET, HEAD" }, + }); + } + let result = memory; + if (!result || result.validUntil <= now()) { + if (!pending) { + // Ignore query strings, cookies and client cache headers so they cannot bust the cache. + const key = new Request( + new URL("/__wheelplay/download-cache/v1", url.origin), + { method: "GET" }, + ); + pending = lookup(env, ctx, cache, key).then( + (value) => (memory = value), + ); + } + const current = pending; + try { + result = await current; + } finally { + if (pending === current) pending = undefined; + } + } + const headers: Record = { + "Cache-Control": "no-store", + "X-Content-Type-Options": "nosniff", + "Referrer-Policy": "no-referrer", + }; + if (result.status === 302 && result.location) { + headers.Location = result.location; + return new Response(null, { status: 302, headers }); + } + headers["Content-Type"] = "text/plain; charset=utf-8"; + headers["Retry-After"] = String( + Math.max(1, Math.ceil((result.validUntil - now()) / 1_000)), + ); + const body = `${result.message}\n\nGitHub 构建列表:${WORKFLOW_URL}\n`; + return new Response(request.method === "HEAD" ? null : body, { + status: result.status, + headers, + }); + }; +} diff --git a/website/worker/index.ts b/website/worker/index.ts new file mode 100644 index 00000000..4fd926fa --- /dev/null +++ b/website/worker/index.ts @@ -0,0 +1,28 @@ +import { createDownloadHandler } from "./download.ts"; +import type { + DownloadEnv, + DownloadContext, + DownloadCache, +} from "./download.ts"; + +interface Env extends DownloadEnv { + ASSETS: { fetch(request: Request): Promise }; +} + +const download = createDownloadHandler(); + +export default { + async fetch( + request: Request, + env: Env, + ctx: DownloadContext, + ): Promise { + const { pathname } = new URL(request.url); + if (pathname === "/download" || pathname.startsWith("/download/")) { + const cache = (caches as CacheStorage & { default: DownloadCache }) + .default; + return download(request, env, ctx, cache); + } + return env.ASSETS.fetch(request); + }, +}; diff --git a/website/wrangler.jsonc b/website/wrangler.jsonc new file mode 100644 index 00000000..556f2053 --- /dev/null +++ b/website/wrangler.jsonc @@ -0,0 +1,6 @@ +{ + "$schema": "https://raw.githubusercontent.com/cloudflare/workers-sdk/main/packages/wrangler/config-schema.json", + "name": "wheelplay-website", + "compatibility_date": "2026-10-23", + "pages_build_output_dir": "./dist", +} diff --git a/website/wrangler.worker.jsonc b/website/wrangler.worker.jsonc new file mode 100644 index 00000000..e93c9de5 --- /dev/null +++ b/website/wrangler.worker.jsonc @@ -0,0 +1,13 @@ +{ + "$schema": "https://raw.githubusercontent.com/cloudflare/workers-sdk/main/packages/wrangler/config-schema.json", + "name": "wheelplay-website", + "main": "./worker/index.ts", + "compatibility_date": "2026-10-23", + "assets": { + "binding": "ASSETS", + "run_worker_first": ["/download", "/download/*"], + "directory": "./dist", + "html_handling": "auto-trailing-slash", + "not_found_handling": "404-page", + }, +}