release: prepare Shift 0.1.15

Unify the front-end component library under src/ui and drop the duplicate
OCR core copies at the root of public/tesseract.
main
mula.liu 2026-11-30 16:24:26 +08:00
parent 968fe15291
commit 5cffbcafd9
28 changed files with 2834 additions and 2672 deletions

View File

@ -10,6 +10,17 @@ repository, not in the source tree. See [`docs/INSTALL.md`](docs/INSTALL.md)
for installation and [`docs/RELEASE.md`](docs/RELEASE.md) for the channel
itself.
## 0.1.15 — 2026-11-30
### Changed
- Unified the front-end component library: the main window, editor, annotation
toolbar, capture overlay, sharing panels, settings and update screens now use
one set of buttons, inputs, tabs, switches, banners, badges and progress
controls from `src/ui`.
- Removed the duplicate OCR core copies at the root of `public/tesseract`; the
worker already loads everything from `/tesseract/core/`.
## 0.1.14 — 2026-11-20
### Fixed

View File

@ -296,7 +296,7 @@ Each is overridable in Settings. File actions offer a *collect everything in one
Installing for the first time? [`docs/INSTALL.md`](docs/INSTALL.md) covers both platforms, first-run permissions and troubleshooting.
A new macOS machine installs **`Shift-0.1.14-macOS-universal.dmg`**: builds are ad-hoc signed and not notarized, so Gatekeeper calls Shift an unidentified developer. Double-click the image, drag `Shift.app` to /Applications, then allow the first launch once (right-click → Open, or Allow in System Settings → Privacy & Security). In-app updates download the same image without a browser, so they never prompt. Details in `docs/RELEASE.md`.
A new macOS machine installs **`Shift-0.1.15-macOS-universal.dmg`**: builds are ad-hoc signed and not notarized, so Gatekeeper calls Shift an unidentified developer. Double-click the image, drag `Shift.app` to /Applications, then allow the first launch once (right-click → Open, or Allow in System Settings → Privacy & Security). In-app updates download the same image without a browser, so they never prompt. Details in `docs/RELEASE.md`.
The update channel is the upstream repository: a `releases` branch holding the installers plus `shift-update.json`, which names each artifact, its size and its SHA256. The feed URL is derived from the git remote at build time - Gitea, GitHub and GitLab forms are known, and `SHIFT_UPDATE_URL` overrides it - so no update service has to be deployed anywhere.
@ -381,7 +381,7 @@ pnpm mac:release
scripts/build-windows-release.sh
```
The release pipeline deliberately emits exactly two installers: `Shift-0.1.14-macOS-universal.dmg` and `Shift-Setup-0.1.14-win-x64.exe`. The macOS app is one universal Mach-O including universal drag, PDF-render and doc-render sidecars. Windows ARM64 uses the x64 installer through the update manifest's compatibility fallback. Full details are in `docs/BUILD_WINDOWS.md` and `docs/RELEASE.md`.
The release pipeline deliberately emits exactly two installers: `Shift-0.1.15-macOS-universal.dmg` and `Shift-Setup-0.1.15-win-x64.exe`. The macOS app is one universal Mach-O including universal drag, PDF-render and doc-render sidecars. Windows ARM64 uses the x64 installer through the update manifest's compatibility fallback. Full details are in `docs/BUILD_WINDOWS.md` and `docs/RELEASE.md`.
**Permissions (macOS).** Screen Recording for capture, Files & Folders for the output folders you choose, Microphone when recording with audio, and Local Network for **Send to a device**. Shift checks Screen Recording before opening the overlay, so a denial surfaces an actionable error rather than a black screenshot. A denied Local Network grant is quieter: Shift still sends its beacons and still answers anyone who addresses it directly, but it receives no group traffic, so the device list simply stays empty. Ad-hoc signed builds get a new code identity on every rebuild and macOS keys these grants to that identity, so an upgrade can ask again; distribution with Developer ID keeps them stable.

View File

@ -298,7 +298,7 @@ Shift 会持续维护局域网内其他 Shift 实例的列表,并据此提供
第一次安装?macOS 与 Windows 的安装步骤、首次运行授权与故障排查见 [`docs/INSTALL.md`](docs/INSTALL.md)。
新的 macOS 机器请安装 **`Shift-0.1.14-macOS-universal.dmg`**:本项目的构建采用 ad-hoc 签名且未做公证,Gatekeeper 会把 Shift 判为身份不明的开发者。双击挂载镜像,把 `Shift.app` 拖进「应用程序」,然后允许首次启动一次(右键 → 打开,或在「系统设置 → 隐私与安全性」中点「允许」)。软件内升级自己下载的是同一个镜像、不经浏览器,因此不会弹窗。详见 `docs/RELEASE.md`。
新的 macOS 机器请安装 **`Shift-0.1.15-macOS-universal.dmg`**:本项目的构建采用 ad-hoc 签名且未做公证,Gatekeeper 会把 Shift 判为身份不明的开发者。双击挂载镜像,把 `Shift.app` 拖进「应用程序」,然后允许首次启动一次(右键 → 打开,或在「系统设置 → 隐私与安全性」中点「允许」)。软件内升级自己下载的是同一个镜像、不经浏览器,因此不会弹窗。详见 `docs/RELEASE.md`。
更新通道就是上游仓库:一条 `releases` 分支保存安装包以及 `shift-update.json` 清单,清单写明每个安装包的名称、体积与 SHA256。更新源地址在构建时由 git 远端推导——已适配 Gitea、GitHub、GitLab 三种形式,也可用 `SHIFT_UPDATE_URL` 覆盖——因此无需额外部署任何更新服务。
@ -372,7 +372,7 @@ pnpm mac:release
scripts/build-windows-release.sh
```
发布链只产出两个安装包:`Shift-0.1.14-macOS-universal.dmg` 与 `Shift-Setup-0.1.14-win-x64.exe`。macOS 是单个通用 Mach-O,内含通用版的拖拽、PDF 渲染与文档渲染伴生进程;Windows ARM64 通过更新清单的兼容回退使用 x64 安装包。完整步骤见 `docs/BUILD_WINDOWS.md` 与 `docs/RELEASE.md`。
发布链只产出两个安装包:`Shift-0.1.15-macOS-universal.dmg` 与 `Shift-Setup-0.1.15-win-x64.exe`。macOS 是单个通用 Mach-O,内含通用版的拖拽、PDF 渲染与文档渲染伴生进程;Windows ARM64 通过更新清单的兼容回退使用 x64 安装包。完整步骤见 `docs/BUILD_WINDOWS.md` 与 `docs/RELEASE.md`。
**权限(macOS)。** 截图与录屏需要「屏幕录制」,输出目录需要「文件与文件夹」授权,带声音录屏需要「麦克风」,「发送到设备」需要「本地网络」。Shift 会在打开截图遮罩前先检查屏幕录制权限,因此被拒绝时给出的是可操作的提示,而不是一张全黑的截图。「本地网络」被拒绝时比较安静:Shift 仍会发出广播、也能回应主动找它的实例,但收不到组播,设备列表于是始终为空。ad-hoc 签名每次重新构建都会得到新的代码身份,而 macOS 正是按这个身份记录上述授权,所以升级后可能重新询问;改用 Developer ID 签名即可保持稳定。

View File

@ -1,4 +1,4 @@
Shift 0.1.14 - macOS 通用(universal)
Shift 0.1.15 - macOS 通用(universal)
本文件说明 macOS 安装包是怎么打出来的、在其它机器上会遇到什么,以及如何自己校验。
完整细节见仓库 docs/RELEASE.md 的「macOS packaging」和 docs/ENGINEERING-NOTES.md
@ -8,7 +8,7 @@ Shift 0.1.14 - macOS 通用(universal)
关于这个安装包
--------------
Shift 的 macOS 产物只有一个:Shift-0.1.14-macOS-universal.dmg,通用二进制,Apple silicon 与
Shift 的 macOS 产物只有一个:Shift-0.1.15-macOS-universal.dmg,通用二进制,Apple silicon 与
Intel 都能用。它既是新机器的首次安装方式,也是软件内升级的载体(更新清单里的 macos
键指向它)。清单的键必须是 .dmg,因为软件内升级的交接脚本要用 hdiutil 挂载镜像再
取出应用包;早期曾随包发布的 .pkg 在验证过 DMG 可用后就撤掉了,不为它多维护一份
@ -23,7 +23,7 @@ Intel 都能用。它既是新机器的首次安装方式,也是软件内升
----------------
新机器首次安装
1. 下载并双击 Shift-0.1.14-macOS-universal.dmg 挂载镜像。
1. 下载并双击 Shift-0.1.15-macOS-universal.dmg 挂载镜像。
2. 把 Shift.app 拖进「应用程序」(或任何你有权限的位置)。
3. 首次启动会被拦:「无法打开,因为来自身份不明的开发者」。点取消,然后
右键 Shift.app → 打开,或在「系统设置 → 隐私与安全性」中点「仍要打开」。
@ -70,7 +70,7 @@ macOS 权限
pnpm tauri build --target universal-apple-darwin --bundles app,dmg
`pnpm mac:release` 会构建、校验并复制为 artifacts/Shift-0.1.14-macOS-universal.dmg。
`pnpm mac:release` 会构建、校验并复制为 artifacts/Shift-0.1.15-macOS-universal.dmg。
发布流程(清单、签名、推送)见仓库 docs/RELEASE.md。
若希望更新通道能校验来源,构建时把 ed25519 公钥编进去(发布流程见仓库
@ -96,7 +96,7 @@ docs/RELEASE.md 的「Signing the channel」):
镜像完整性:
hdiutil verify Shift-0.1.14-macOS-universal.dmg
hdiutil verify Shift-0.1.15-macOS-universal.dmg
校验后仍打不开的话,请确认不是在压缩包预览窗口里运行的,并按上面的「新机器首次安装」
处理首次允许:右键 → 打开,或在「系统设置 → 隐私与安全性」中点「仍要打开」。

View File

@ -12,8 +12,8 @@ An orphan branch named `releases` holds exactly one release:
releases/
├── shift-update.json
├── shift-update.sig
├── Shift-0.1.14-macOS-universal.dmg
└── Shift-Setup-0.1.14-win-x64.exe
├── Shift-0.1.15-macOS-universal.dmg
└── Shift-Setup-0.1.15-win-x64.exe
```
`shift-update.json` names the version and, per platform, the artifact file, its size in
@ -22,12 +22,12 @@ bytes and its SHA256:
```json
{
"schema": 1,
"version": "0.1.14",
"version": "0.1.15",
"date": "2026-10-26",
"notes": "",
"artifacts": {
"macos": { "file": "Shift-0.1.14-macOS-universal.dmg", "sha256": "…", "size": 0 },
"windows": { "file": "Shift-Setup-0.1.14-win-x64.exe", "sha256": "…", "size": 0 }
"macos": { "file": "Shift-0.1.15-macOS-universal.dmg", "sha256": "…", "size": 0 },
"windows": { "file": "Shift-Setup-0.1.15-win-x64.exe", "sha256": "…", "size": 0 }
}
}
```

View File

@ -1,7 +1,7 @@
{
"name": "shift",
"private": true,
"version": "0.1.14",
"version": "0.1.15",
"license": "GPL-3.0-only",
"type": "module",
"scripts": {

File diff suppressed because one or more lines are too long

2
src-tauri/Cargo.lock generated
View File

@ -3899,7 +3899,7 @@ dependencies = [
[[package]]
name = "shift"
version = "0.1.14"
version = "0.1.15"
dependencies = [
"base64 0.22.1",
"calamine",

View File

@ -1,6 +1,6 @@
[package]
name = "shift"
version = "0.1.14"
version = "0.1.15"
description = "A radial file utility with screenshot, recording and OCR."
authors = ["mula.liu"]
license = "GPL-3.0-only"

View File

@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Shift",
"version": "0.1.14",
"version": "0.1.15",
"identifier": "app.nex.shift",
"build": {
"beforeDevCommand": "pnpm dev",

View File

@ -7,6 +7,7 @@ import { api } from "../lib/api";
import { messageFrom, normalizeSelection } from "../lib/utils";
import { FEEDBACK } from "../lib/feedback";
import type { CaptureSession, RecordingCapabilities } from "../types";
import { Button, IconButton, Kbd, Surface, Toolbar } from "../ui/primitives";
interface Point {
x: number;
@ -216,8 +217,9 @@ export function CaptureOverlay() {
{Math.max(0, Math.round(selection.width))} × {Math.max(0, Math.round(selection.height))}
</div>
</div>
<div
<Toolbar
ref={toolbarRef}
tone="dark"
className="capture-toolbar"
style={{ top: toolbarTop, left: toolbarLeft }}
onPointerDown={(event) => event.stopPropagation()}
@ -226,17 +228,21 @@ export function CaptureOverlay() {
{session.mode === "recording" ? (
<>
{capabilities.audio ? (
<button
className={`capture-tool ${audio ? "is-selected" : ""}`}
<IconButton
label={t("audio")}
variant="toolbar"
size="md"
active={audio}
onClick={() => setAudio((value) => !value)}
title={t("audio")}
>
{audio ? <Mic size={17} /> : <MicOff size={17} />}
</button>
</IconButton>
) : null}
{capabilities.fps ? (
<button
className="capture-tool capture-fps"
<Button
variant="toolbar"
size="md"
className="capture-fps"
onClick={() =>
setFps(
FRAME_RATES[
@ -248,42 +254,49 @@ export function CaptureOverlay() {
>
<Gauge size={15} />
{fps}
</button>
</Button>
) : null}
<button className="capture-tool capture-record" onClick={() => void confirm()}>
<Button variant="toolbar-danger" size="md" onClick={() => void confirm()}>
<Square size={14} fill="currentColor" />
{t("startRecording")}
</button>
</Button>
</>
) : (
<button className="capture-tool capture-confirm" onClick={() => void confirm()}>
<Button variant="toolbar-primary" size="md" onClick={() => void confirm()}>
<Check size={18} strokeWidth={2.4} />
{t("confirm")}
</button>
</Button>
)}
<button className="capture-tool" onClick={() => void cancel()} title={t("cancel")}>
<IconButton
label={t("cancel")}
variant="toolbar"
size="md"
onClick={() => void cancel()}
>
<X size={17} />
</button>
</div>
</IconButton>
</Toolbar>
</>
) : (
<div className="capture-start-hint">
<Surface variant="dark" radius="lg" className="capture-start-hint">
<span className="capture-icon">
{session.mode === "recording" ? <ScanLine size={22} /> : <ScanLine size={22} />}
</span>
<div>
<strong>{t("dragSelect")}</strong>
</div>
<kbd>ESC</kbd>
</div>
<Kbd tone="dark">ESC</Kbd>
</Surface>
)}
{busy ? (
<div className="capture-processing" role="status" aria-live="polite">
<Surface variant="dark" radius="md" className="capture-processing" role="status" aria-live="polite">
<LoaderCircle size={20} className="spin" />
{status || t("processing")}
</div>
</Surface>
) : status ? (
<div className="capture-status" role="status" aria-live="polite">{status}</div>
<Surface variant="dark" radius="md" className="capture-status" role="status" aria-live="polite">
{status}
</Surface>
) : null}
</div>
);

View File

@ -24,6 +24,14 @@ import { basename, dirname, extensionOf, IS_MAC, messageFrom } from "../lib/util
import { history } from "../lib/history";
import type { EditorInfo } from "../types";
import { ImageAnnotator } from "./ImageAnnotator";
import {
Button,
IconButton,
ProgressBar,
Textarea,
Toast,
Toolbar,
} from "../ui/primitives";
export function Editor() {
const { t } = useI18n();
@ -141,7 +149,7 @@ export function Editor() {
setOcrRunning(true);
setOcrText("");
setOcrProgress(0);
setOcrFailed(false);
setOcrFailed(false);
setOcrStatus(t("ocrRunning"));
try {
const source = isTauri() ? convertFileSrc(current.path) : current.path;
@ -198,55 +206,72 @@ export function Editor() {
<div className="editor-title" data-tauri-drag-region>
{name}
</div>
<button
className="home-icon-button editor-close"
<IconButton
label={t("close")}
variant="ghost"
size="md"
className="editor-close"
onClick={() => void api.closeEditor()}
aria-label={t("close")}
title={t("close")}
>
<X size={16} />
</button>
</IconButton>
</header>
<div className="editor-toolbar">
<Toolbar tone="light" variant="bar">
<div className="editor-tool-group">
<button className="editor-button" onClick={() => void copy()}>
<Button variant="secondary" size="sm" onClick={() => void copy()}>
<Copy size={16} />
{t("copy")}
</button>
<button className="editor-button" onClick={() => void saveAs()}>
</Button>
<Button variant="secondary" size="sm" onClick={() => void saveAs()}>
<Clipboard size={16} />
{t("saveAs")}
</button>
</Button>
{session.kind === "image" ? (
<button className={`editor-button ${ocrOpen ? "is-active" : ""}`} onClick={() => void runOcr()}>
<Button
variant="secondary"
size="sm"
active={ocrOpen}
onClick={() => void runOcr()}
>
<ScanText size={16} />
{t("ocr")}
</button>
</Button>
) : null}
{session.kind === "image" ? (
<button
className="editor-button"
<Button
variant="secondary"
size="sm"
onClick={() => void pinToScreen()}
disabled={pinBusy}
>
{pinBusy ? <LoaderCircle size={16} className="spin" /> : <Pin size={16} />}
{t("pin")}
</button>
</Button>
) : null}
</div>
<div className="editor-tool-group">
<span className="editor-path" title={session.path}>
{dirname(session.path)}
</span>
<button className="editor-icon" title={t("open")} onClick={() => void api.openFile(session.path)}>
<IconButton
label={t("open")}
variant="ghost"
size="sm"
onClick={() => void api.openFile(session.path)}
>
<ExternalLink size={16} />
</button>
<button className="editor-icon" title={t("revealFile")} onClick={() => void api.revealFile(session.path)}>
</IconButton>
<IconButton
label={t("revealFile")}
variant="ghost"
size="sm"
onClick={() => void api.revealFile(session.path)}
>
<FolderOpen size={16} />
</button>
</IconButton>
</div>
</div>
</Toolbar>
<main className={`editor-main ${ocrOpen ? "has-ocr" : ""}`}>
<section className="editor-canvas">
@ -271,7 +296,9 @@ export function Editor() {
<div className="editor-file-fallback">
<FileText size={54} strokeWidth={1.4} />
<strong>{name}</strong>
<button onClick={() => void api.openFile(session.path)}>{t("open")}</button>
<Button variant="inverse" size="sm" onClick={() => void api.openFile(session.path)}>
{t("open")}
</Button>
</div>
)}
</section>
@ -283,14 +310,14 @@ export function Editor() {
<span className="ocr-eyebrow">{t("ocr")}</span>
<h2>{t("ocrTitle")}</h2>
</div>
<button
className="editor-icon"
<IconButton
label={t("close")}
variant="ghost"
size="sm"
onClick={() => setOcrOpen(false)}
aria-label={t("close")}
title={t("close")}
>
<X size={16} />
</button>
</IconButton>
</div>
{ocrRunning ? (
<div className="ocr-progress">
@ -299,41 +326,45 @@ export function Editor() {
<span>{ocrStatus}</span>
<b>{Math.round(ocrProgress * 100)}%</b>
</div>
<div className="ocr-progress-bar">
<span style={{ width: `${Math.max(4, ocrProgress * 100)}%` }} />
</div>
<ProgressBar value={Math.max(4, ocrProgress * 100)} size="sm" />
</div>
) : null}
<textarea
className="ocr-output"
<Textarea
className="ocr-output ui-textarea--mono"
value={ocrText}
onChange={(event) => setOcrText(event.target.value)}
placeholder={t(ocrFailed ? "ocrNothing" : "ocrEmpty")}
spellCheck={false}
/>
<div className="ocr-actions">
<button className="editor-primary" onClick={() => void writeText(ocrText).then(() => flashNotice(t("copyText")))}>
<Button
variant="primary"
size="sm"
onClick={() => void writeText(ocrText).then(() => flashNotice(t("copyText")))}
>
<Copy size={15} />
{t("copyText")}
</button>
<button className="editor-secondary" onClick={() => void runOcr()}>
</Button>
<Button variant="secondary" size="sm" onClick={() => void runOcr()}>
<ScanText size={15} />
{t("extractText")}
</button>
</Button>
</div>
</aside>
) : null}
</main>
{copied ? (
<div
className={`editor-toast ${copiedIsError ? "is-error" : ""}`}
<Toast
tone={copiedIsError ? "error" : "neutral"}
size="sm"
className="editor-toast"
role={copiedIsError ? "alert" : "status"}
aria-live="polite"
>
{copiedIsError ? <CircleAlert size={15} /> : <Check size={15} />}
{copied}
</div>
</Toast>
) : null}
</div>
);

View File

@ -25,6 +25,14 @@ import { useEffect, useRef, useState } from "react";
import { useI18n } from "../i18n";
import { api } from "../lib/api";
import { messageFrom } from "../lib/utils";
import {
Button,
IconButton,
Input,
Toast,
Toolbar,
ToolbarDivider,
} from "../ui/primitives";
type Tool =
| "rectangle"
@ -563,63 +571,84 @@ export function ImageAnnotator({ path, onSaved }: Props) {
return (
<div className="annotator-shell">
<div className="annotator-toolbar">
<Toolbar tone="dark" className="annotator-toolbar">
{tools.map(({ id, icon: Icon, label }) => (
<button
<Button
key={id}
className={`annotator-tool ${tool === id ? "is-active" : ""}`}
variant="toolbar"
size="sm"
active={tool === id}
title={label}
onClick={() => setTool(id)}
>
<Icon size={15} />
<span>{label}</span>
</button>
</Button>
))}
<span className="annotator-separator" />
<ToolbarDivider />
{tool === "stamp"
? stamps.map(({ id, icon: Icon, label }) => (
<button
<IconButton
key={id}
className={`annotator-tool annotator-stamp ${stamp === id ? "is-active" : ""}`}
label={label}
variant="toolbar"
size="sm"
active={stamp === id}
title={label}
onClick={() => setStamp(id)}
>
<Icon size={15} />
</button>
</IconButton>
))
: null}
<span className="annotator-separator" />
<ToolbarDivider />
{cropRect ? (
<button className="annotator-tool is-primary" onClick={applyCrop}>
<Button
variant="toolbar-primary"
size="sm"
title={t("applyCrop")}
onClick={applyCrop}
>
<Check size={15} />
{t("applyCrop")}
</button>
<span>{t("applyCrop")}</span>
</Button>
) : null}
<button className="annotator-tool" onClick={addBackground} title={t("addBackground")}>
<Button variant="toolbar" size="sm" onClick={addBackground} title={t("addBackground")}>
<ImagePlus size={15} />
{t("addBackground")}
</button>
<button className="annotator-tool" onClick={removeBackground} title={t("cutout")}>
<span>{t("addBackground")}</span>
</Button>
<Button variant="toolbar" size="sm" onClick={removeBackground} title={t("cutout")}>
<Scissors size={15} />
{t("cutout")}
</button>
<button
className="annotator-tool"
title={t("undo")}
<span>{t("cutout")}</span>
</Button>
<IconButton
label={t("undo")}
variant="toolbar"
size="sm"
disabled={annotations.length === 0 && imageHistory.length === 0}
onClick={undo}
>
<Undo2 size={15} />
</button>
<button className="annotator-tool is-primary" onClick={() => void saveCopy(false)}>
</IconButton>
<Button
variant="toolbar-primary"
size="sm"
title={t("saveCopy")}
onClick={() => void saveCopy(false)}
>
{busy && !copying ? <LoaderCircle size={15} className="spin" /> : <Save size={15} />}
{t("saveCopy")}
</button>
<button className="annotator-tool" onClick={() => void saveCopy(true)}>
<span>{t("saveCopy")}</span>
</Button>
<Button
variant="toolbar"
size="sm"
title={t("copy")}
onClick={() => void saveCopy(true)}
>
{copying ? <LoaderCircle size={15} className="spin" /> : <Copy size={15} />}
{t("copy")}
</button>
</div>
<span>{t("copy")}</span>
</Button>
</Toolbar>
<div className="annotator-canvas-wrap">
<canvas
ref={canvasRef}
@ -686,10 +715,15 @@ export function ImageAnnotator({ path, onSaved }: Props) {
event.currentTarget.releasePointerCapture(event.pointerId);
}}
/>
{error ? <div className="annotator-error" role="alert">{error}</div> : null}
{error ? (
<Toast tone="error" size="sm" className="annotator-error" role="alert">
{error}
</Toast>
) : null}
{textPoint ? (
<div className="annotator-text-entry">
<input
<Toolbar tone="dark" className="annotator-text-entry">
<Input
className="ui-input--dark ui-input--compact"
autoFocus
value={textDraft}
placeholder={t("textAnnotation")}
@ -716,9 +750,10 @@ export function ImageAnnotator({ path, onSaved }: Props) {
}
}}
/>
<button
aria-label={t("confirm")}
title={t("confirm")}
<IconButton
label={t("confirm")}
variant="toolbar-primary"
size="sm"
onClick={() => {
if (!textDraft.trim()) return;
setAnnotations((current) => [
@ -737,8 +772,8 @@ export function ImageAnnotator({ path, onSaved }: Props) {
}}
>
<Check size={14} />
</button>
</div>
</IconButton>
</Toolbar>
) : null}
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ import { useEffect, useRef, useState } from "react";
import { useI18n } from "../i18n";
import { api } from "../lib/api";
import { decodeHexParam, messageFrom } from "../lib/utils";
import { IconButton } from "../ui/primitives";
interface PinnedPreview {
id: number;
@ -141,20 +142,22 @@ export function PinnedImage() {
)}
</div>
<div className="pin-actions">
<button
type="button"
title={t(enlarged ? "restorePin" : "enlargePin")}
<IconButton
label={t(enlarged ? "restorePin" : "enlargePin")}
variant="glass-dark"
size="xs"
active={enlarged}
aria-pressed={enlarged}
onClick={() => void zoom()}
>
{enlarged ? <Minimize2 size={13} /> : <Maximize2 size={13} />}
</button>
<button type="button" title={t("copy")} onClick={() => void copy()}>
</IconButton>
<IconButton label={t("copy")} variant="glass-dark" size="xs" onClick={() => void copy()}>
<Copy size={13} />
</button>
<button type="button" title={t("close")} onClick={() => void api.closePin()}>
</IconButton>
<IconButton label={t("close")} variant="glass-dark" size="xs" onClick={() => void api.closePin()}>
<X size={13} />
</button>
</IconButton>
</div>
</div>
);

View File

@ -54,6 +54,7 @@ import { FEEDBACK, outcomeMessage } from "../lib/feedback";
import type { FileInfo, RadialContext } from "../types";
import { useI18n } from "../i18n";
import { SharePanel } from "./SharePanel";
import { Button, IconButton } from "../ui/primitives";
const SIZE = 760;
const CENTER = SIZE / 2;
@ -820,8 +821,9 @@ export function RadialMenu() {
const position = polar((OUTER + INNER) / 2 - 2, angle);
const Icon = wedge.icon;
return (
<button
<Button
key={`label-${wedge.id}`}
variant="plain"
className={`radial-label ${ring === "formats" ? "is-format" : ""} ${hovered === index ? "is-active" : ""}`}
style={{ left: position.x, top: position.y }}
onPointerEnter={() => {
@ -840,7 +842,7 @@ export function RadialMenu() {
<Icon size={wedge.id === "convert" ? 23 : 22} strokeWidth={1.8} />
)}
<span>{wedge.label}</span>
</button>
</Button>
);
})}
@ -896,9 +898,15 @@ export function RadialMenu() {
<CircleAlert size={24} strokeWidth={1.8} aria-hidden="true" />
<strong>{t("actionFailed")}</strong>
<span className="radial-error-message">{error}</span>
<button type="button" onClick={() => setError(null)} aria-label={t("close")}>
<IconButton
label={t("close")}
variant="secondary"
size="xs"
className="radial-error-close"
onClick={() => setError(null)}
>
<X size={14} />
</button>
</IconButton>
</div>
) : null}
</div>

View File

@ -5,6 +5,7 @@ import { useI18n } from "../i18n";
import { api } from "../lib/api";
import { formatDuration, messageFrom } from "../lib/utils";
import type { RecordingInfo } from "../types";
import { Button } from "../ui/primitives";
export function RecorderHud() {
const { t } = useI18n();
@ -63,10 +64,16 @@ export function RecorderHud() {
{error || t("record")}
</span>
</div>
<button type="button" className="recorder-stop" onClick={() => void stop()} disabled={stopping}>
<Button
variant="danger"
size="sm"
className="recorder-stop"
onClick={() => void stop()}
disabled={stopping}
>
{stopping ? <LoaderCircle size={15} className="spin" /> : <Square size={14} fill="currentColor" />}
{stopping ? t("processing") : t("stopRecording")}
</button>
</Button>
</div>
);
}

View File

@ -8,6 +8,7 @@ import { useI18n } from "../i18n";
import { api } from "../lib/api";
import { basename, decodeHexParam, messageFrom } from "../lib/utils";
import type { CaptureResult } from "../types";
import { Button, IconButton, ProgressBar, Surface } from "../ui/primitives";
const THUMB_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "gif", "bmp", "tiff", "tif"];
@ -110,7 +111,9 @@ export function ResultCard() {
const percent = ttl > 0 ? (remaining / ttl) * 100 : 0;
return (
<div
<Surface
variant="solid"
radius="lg"
className="result-card"
onMouseEnter={pause}
onMouseLeave={resume}
@ -136,25 +139,25 @@ export function ResultCard() {
{note ? <em>{note}</em> : null}
</div>
<div className="result-card-actions">
<button title={t("copy")} onClick={() => void copy()}>
<IconButton label={t("copy")} size="xs" onClick={() => void copy()}>
<Copy size={14} />
</button>
</IconButton>
{info.kind === "image" ? (
<button title={t("pin")} onClick={() => void pin()}>
<IconButton label={t("pin")} size="xs" onClick={() => void pin()}>
<Images size={14} />
</button>
</IconButton>
) : null}
<button title={t("sendTo")} onClick={() => void send()}>
<IconButton label={t("sendTo")} size="xs" onClick={() => void send()}>
<Send size={14} />
</button>
<button title={t("revealFile")} onClick={() => void reveal()}>
</IconButton>
<IconButton label={t("revealFile")} size="xs" onClick={() => void reveal()}>
<FolderSearch size={14} />
</button>
<button className="result-card-open" onClick={() => void open()}>
</IconButton>
<Button variant="primary" size="xs" className="result-card-open" onClick={() => void open()}>
{t("edit")}
</button>
</Button>
</div>
<div className="result-card-fuse" style={{ width: `${percent}%` }} />
</div>
<ProgressBar value={percent} size="xs" className="result-card-fuse" />
</Surface>
);
}

View File

@ -12,6 +12,7 @@ import {
import { useI18n } from "../i18n";
import { api } from "../lib/api";
import type { HotkeyStatus, RuntimeInfo, WriteCheck } from "../types";
import { Badge, Button, Code, Surface } from "../ui/primitives";
type State = "checking" | "ok" | "problem" | "unknown";
@ -162,16 +163,16 @@ export function SetupPanel({
return (
<div className="setup-scrim" role="dialog" aria-modal="true" aria-label={t("setupTitle")}>
<div className="setup-card">
<Surface variant="solid" radius="lg" className="setup-card">
<header className="setup-head">
<div>
<h2>{t("setupTitle")}</h2>
<p>{t("setupIntro")}</p>
</div>
<button className="setup-refresh" onClick={() => void refresh()}>
<Button variant="outline" size="xs" onClick={() => void refresh()}>
<RefreshCw size={13} />
{t("setupRecheck")}
</button>
</Button>
</header>
<ul className="setup-list">
@ -194,12 +195,21 @@ export function SetupPanel({
)}
</small>
{row.action ? (
<button className="settings-link" onClick={row.action.run}>
<Button variant="quiet" size="xs" onClick={row.action.run}>
{row.action.label}
</button>
</Button>
) : null}
</span>
<span className={`setup-state is-${row.state}`}>
<Badge
tone={
row.state === "ok"
? "success"
: row.state === "problem"
? "danger"
: "neutral"
}
className="setup-state"
>
{row.state === "ok" ? (
<Check size={16} />
) : row.state === "problem" ? (
@ -212,7 +222,7 @@ export function SetupPanel({
? "setupStateProblem"
: "setupStateUnknown",
)}
</span>
</Badge>
</li>
);
})}
@ -221,18 +231,18 @@ export function SetupPanel({
{checks ? (
<div className="setup-paths">
{checks.map((check) => (
<code key={check.kind}>{check.path}</code>
<Code key={check.kind}>{check.path}</Code>
))}
</div>
) : null}
<footer className="setup-foot">
<span>{t("setupFootnote")}</span>
<button className="runtime-install" onClick={onDone}>
<Button variant="outline" size="sm" onClick={onDone}>
{t("setupStart")}
</button>
</Button>
</footer>
</div>
</Surface>
</div>
);
}

View File

@ -5,6 +5,7 @@ import { useI18n } from "../i18n";
import { api } from "../lib/api";
import { decodeHexParam, formatBytes } from "../lib/utils";
import type { ShareOffer } from "../types";
import { Badge, Button, ProgressBar, Surface } from "../ui/primitives";
function readOffer(): ShareOffer | null {
const raw = decodeHexParam(new URLSearchParams(window.location.search).get("offer"));
@ -74,7 +75,7 @@ export function ShareNotice() {
const ratio = offer.timeoutSeconds > 0 ? left / offer.timeoutSeconds : 0;
return (
<div className="share-notice" data-tauri-drag-region>
<Surface variant="solid" radius="lg" className="share-notice" data-tauri-drag-region>
<div className="share-notice-head" data-tauri-drag-region>
<span className="share-notice-glyph">
<Inbox size={16} />
@ -82,27 +83,25 @@ export function ShareNotice() {
<span className="share-notice-kicker" data-tauri-drag-region>
{t("shareNoticeKicker", { peer: offer.peerName })}
</span>
<span className={`share-notice-count ${ratio < 0.25 ? "is-low" : ""}`}>
<Badge tone={ratio < 0.25 ? "danger" : "accent"} className="share-notice-count">
{expired ? t("shareNoticeExpired") : `${left}s`}
</span>
</Badge>
</div>
<div className="share-notice-file" title={offer.fileName}>
<strong data-tauri-drag-region>{offer.fileName}</strong>
<small>{formatBytes(offer.size)}</small>
</div>
<div className="share-notice-actions">
<button className="share-notice-decline" onClick={() => void answer(false)}>
<Button variant="secondary" size="md" block onClick={() => void answer(false)}>
<X size={14} />
{t("shareNoticeDecline")}
</button>
<button className="share-notice-accept" onClick={() => void answer(true)}>
</Button>
<Button variant="primary" size="md" block onClick={() => void answer(true)}>
<Check size={14} />
{t("shareNoticeAccept")}
</button>
</Button>
</div>
<div className="share-notice-bar">
<span style={{ width: `${(ratio * 100).toFixed(1)}%` }} />
</div>
</div>
<ProgressBar value={ratio * 100} size="xs" className="share-notice-bar" />
</Surface>
);
}

View File

@ -2,7 +2,6 @@ import { isTauri } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import {
Apple,
Check,
CircleAlert,
File as FileIcon,
GripVertical,
@ -19,6 +18,16 @@ import { api } from "../lib/api";
import { parseSharePaths, SHARE_PATHS_TYPE } from "../lib/dragOut";
import { basename, dirname, formatBytes, messageFrom } from "../lib/utils";
import type { SharePeer, ShareTransfer } from "../types";
import {
Banner,
Button,
Checkbox,
EmptyState,
IconButton,
Kbd,
ProgressBar,
Surface,
} from "../ui/primitives";
interface SharePanelProps {
paths: string[];
@ -197,7 +206,9 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
if (!closeDisabled) onClose();
}}
/>
<div
<Surface
variant="solid"
radius="xl"
className="share-panel"
role="dialog"
aria-modal="true"
@ -210,20 +221,20 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
<div className="share-head-copy">
<h2>{t("shareTitle")}</h2>
</div>
<button
className="home-icon-button"
<IconButton
label={t("close")}
variant="ghost"
size="md"
onClick={() => {
if (!closeDisabled) onClose();
}}
aria-label={t("close")}
title={t("close")}
disabled={closeDisabled}
>
<X size={16} />
</button>
</IconButton>
</header>
<section className="share-files" aria-label={t("shareFiles")}>
<Surface variant="inset" radius="md" className="share-files" aria-label={t("shareFiles")}>
<div className="share-files-head">
<strong>{t("shareFiles")}</strong>
<span>{t("shareSelectionCount", {
@ -231,29 +242,28 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
total: paths.length,
})}</span>
{paths.length > 1 ? (
<label className="share-select-all">
<input
type="checkbox"
checked={allSelected}
onChange={toggleAll}
disabled={closeDisabled}
/>
<span className="share-checkmark" aria-hidden="true">
{allSelected ? <Check size={10} /> : null}
</span>
<Checkbox
className="share-select-all"
checked={allSelected}
onChange={toggleAll}
disabled={closeDisabled}
>
{t("shareSelectAll")}
</label>
</Checkbox>
) : null}
</div>
<div className="share-file-list" role="group" aria-label={t("shareFiles")}>
{paths.map((path) => {
const checked = selectedPaths.includes(path);
return (
<label
<Checkbox
key={path}
className={`share-file-row ${checked ? "is-checked" : ""}`}
title={path}
draggable={!closeDisabled}
checked={checked}
onChange={() => togglePath(path)}
disabled={closeDisabled}
onDragStart={(event) => {
const files = checked ? selectedPaths : [path];
event.dataTransfer.effectAllowed = "copy";
@ -263,43 +273,36 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
);
}}
>
<input
type="checkbox"
checked={checked}
onChange={() => togglePath(path)}
disabled={closeDisabled}
/>
<span className="share-checkmark" aria-hidden="true">
{checked ? <Check size={10} /> : null}
</span>
<FileIcon size={13} />
<span className="share-file-copy">
<strong>{basename(path)}</strong>
<small>{dirname(path)}</small>
</span>
<GripVertical className="share-file-grip" size={13} aria-hidden="true" />
</label>
</Checkbox>
);
})}
</div>
</section>
</Surface>
{peers.length === 0 ? (
<div className="share-empty">
<span className="share-empty-glyph">
{searching ? <LoaderCircle size={17} className="spin" /> : <Radar size={17} />}
</span>
<strong>{searching ? t("shareSearching") : t("shareNoPeers")}</strong>
</div>
<EmptyState
className="share-empty"
glyph={searching ? <LoaderCircle size={17} className="spin" /> : <Radar size={17} />}
title={searching ? t("shareSearching") : t("shareNoPeers")}
/>
) : (
<div className="share-grid">
{peers.map((peer) => {
const active = busyPeer === peer.id;
const dropTarget = dragOverPeer === peer.id;
return (
<button
<Button
key={peer.id}
className={`share-peer ${active ? "is-active" : ""} ${dropTarget ? "is-drop-target" : ""}`}
variant="card"
size="lg"
active={active}
className={`share-peer ${dropTarget ? "is-drop-target" : ""}`}
onClick={() => void send(peer)}
disabled={selectedPaths.length === 0 || (closeDisabled && !active)}
title={peer.address}
@ -334,28 +337,26 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
<span className="share-peer-meta">
{t(PLATFORM_LABEL[peer.platform] ?? "shareLinux")}
</span>
</button>
</Button>
);
})}
</div>
)}
{waitingFor ? (
<div className="share-progress">
<Surface variant="inset" radius="md" className="share-progress">
<div className="share-progress-head">
<span className="share-progress-wait">
<LoaderCircle size={12} className="spin" />
{t("shareWaiting", { peer: waitingFor })}
</span>
</div>
<div className="share-bar is-indeterminate">
<span />
</div>
</div>
<ProgressBar indeterminate className="share-bar" />
</Surface>
) : null}
{sending && progress && !waitingFor ? (
<div className="share-progress">
<Surface variant="inset" radius="md" className="share-progress">
<div className="share-progress-head">
<span>
{t("shareSendingTo", {
@ -367,32 +368,36 @@ export function SharePanel({ paths, onClose, onNotice }: SharePanelProps) {
{formatBytes(progress.sent)} / {formatBytes(progress.total)}
</small>
</div>
<div className="share-bar">
<span style={{ width: `${(ratio * 100).toFixed(1)}%` }} />
</div>
</div>
<ProgressBar value={ratio * 100} className="share-bar" />
</Surface>
) : null}
{failure ? (
<div className="share-error" role="alert">
<CircleAlert size={13} />
<Banner
tone="danger"
icon={<CircleAlert size={13} />}
inline
className="share-error"
role="alert"
>
{failure}
</div>
</Banner>
) : null}
<footer className="share-foot">
<button
className="share-reshow"
<Button
variant="outline"
size="xs"
onClick={searchAgain}
disabled={closeDisabled}
title={t("shareRefresh")}
>
<RefreshCw size={12} className={searching ? "spin" : ""} />
{searching ? t("shareSearching") : t("shareRefresh")}
</button>
<kbd>Esc</kbd>
</Button>
<Kbd>Esc</Kbd>
</footer>
</div>
</Surface>
</>
);
}

View File

@ -13,6 +13,17 @@ import {
import { useI18n } from "../i18n";
import { useUpdateFlow } from "../lib/useUpdate";
import { formatBytes } from "../lib/utils";
import {
Badge,
Banner,
Button,
Code,
ProgressBar,
Section,
SectionTitle,
Surface,
SwitchRow,
} from "../ui/primitives";
interface Props {
/** Raw URL of the manifest, so the panel can name the feed it just queried. */
@ -72,7 +83,7 @@ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: P
const failed = status?.state === "error" || status?.state === "unavailable";
return (
<section className="home-settings-section">
<Section>
{/* The two facts an update answer has to be read against come first: which
machine and which Shift version is asking, then where updates come from.
Both precede the Updates heading so a screenshot of this panel already
@ -84,11 +95,11 @@ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: P
{system ? (
<span className="update-system-host">
<strong>{system.osVersion || system.platform}</strong>
<small>{architectureLabel(system.architecture)}</small>
<Badge>{architectureLabel(system.architecture)}</Badge>
<em>Shift {system.appVersion}</em>
</span>
) : (
<span className="update-system-pending">{t("updateSystemPending")}</span>
<Badge className="update-system-pending">{t("updateSystemPending")}</Badge>
)}
</div>
<div className="update-meta-line">
@ -97,29 +108,35 @@ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: P
{/* Only a status backed by a manifest may claim anything about trust: an
errored check has no manifest to have verified. */}
{status && status.state !== "error" ? (
<span className={`update-trust is-${status.signed ? "signed" : "unsigned"}`}>
<Badge
tone={status.signed ? "success" : "neutral"}
plain
className="update-trust"
>
<ShieldCheck size={13} />
{t(status.signed ? "updateSigned" : "updateUnsigned")}
</span>
</Badge>
) : null}
<code title={feedUrl}>{feedUrl || t("updateFeedNone")}</code>
<Code title={feedUrl}>{feedUrl || t("updateFeedNone")}</Code>
</div>
</div>
<div className="runtime-section-head">
<div className="home-section-title">
<Sparkle size={17} />
{t("updates")}
</div>
<button
className="settings-link runtime-refresh"
onClick={() => void check()}
disabled={checking || downloading}
>
<RefreshCw size={13} className={checking ? "spin" : ""} />
{checking ? t("updateChecking") : t("updateCheckNow")}
</button>
</div>
<SectionTitle
icon={<Sparkle size={17} />}
actions={
<Button
variant="quiet"
size="xs"
onClick={() => void check()}
disabled={checking || downloading}
>
<RefreshCw size={13} className={checking ? "spin" : ""} />
{checking ? t("updateChecking") : t("updateCheckNow")}
</Button>
}
>
{t("updates")}
</SectionTitle>
<div className="update-status-row">
<span className={`update-state is-${status?.state ?? "idle"}`}>
@ -137,10 +154,10 @@ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: P
</span>
{available && status ? (
<span className="update-arrow">
<span className="update-new">
<Badge tone="success" className="update-new">
<Sparkle size={13} />
{status.availableVersion}
</span>
</Badge>
<small>{status.date}</small>
</span>
) : null}
@ -149,96 +166,94 @@ export function UpdatePanel({ feedUrl, autoCheck, onAutoCheckChange, system }: P
{status?.notes ? <p className="update-notes">{status.notes}</p> : null}
{status?.fileName ? (
<div className="update-artifact">
<Surface variant="inset" radius="md" className="update-artifact">
<PackageOpen size={15} />
<span className="update-artifact-name" title={status.fileName}>
{status.fileName}
</span>
<span className="update-artifact-size">{formatBytes(status.size)}</span>
</div>
</Surface>
) : null}
{percent !== null ? (
<div
<ProgressBar
value={percent}
tone="success"
size="lg"
className="update-progress"
role="progressbar"
aria-valuenow={percent}
aria-valuemin={0}
aria-valuemax={100}
>
<div className="update-progress-fill" style={{ width: `${percent}%` }} />
<span>
{progress ? `${formatBytes(progress.downloaded)} / ${formatBytes(progress.total)}` : ""}
</span>
</div>
label={
progress ? `${formatBytes(progress.downloaded)} / ${formatBytes(progress.total)}` : ""
}
/>
) : null}
{status?.sha256 ? (
<code className="update-hash" title={status.sha256}>
<Code className="update-hash" title={status.sha256}>
<ShieldCheck size={13} />
SHA256 {verified ? status.sha256 : `${status.sha256.slice(0, 16)}…`}
</code>
</Code>
) : null}
{status?.message && (failed || verified) ? (
<div
className={`runtime-error ${verified ? "is-ok" : ""}`}
<Banner
tone={verified ? "success" : "danger"}
icon={verified ? <ShieldCheck size={15} /> : undefined}
compact
className="runtime-error"
role={verified ? "status" : "alert"}
>
<span>{verified ? t("updateVerified") : status.message}</span>
</div>
{verified ? t("updateVerified") : status.message}
</Banner>
) : null}
{/* An install that could not run leaves the verified download in place, so it
is reported beside the button instead of rewriting the status. */}
{installError ? (
<div className="runtime-error" role="alert">
<span>{installError}</span>
</div>
<Banner tone="danger" compact className="runtime-error" role="alert">
{installError}
</Banner>
) : null}
<div className="update-actions">
{available && !verified ? (
<button
className="update-action is-commit"
<Button
variant="primary"
size="md"
onClick={() => void download()}
disabled={downloading}
>
{downloading ? <LoaderCircle size={15} className="spin" /> : <Download size={15} />}
{downloading ? t("updateDownloading") : t("updateDownload")}
</button>
</Button>
) : null}
{verified ? (
<button
className="update-action is-commit"
<Button
variant="primary"
size="md"
onClick={() => void install()}
disabled={installing}
>
{installing ? <LoaderCircle size={15} className="spin" /> : <Check size={15} />}
{installing ? t("updateInstalling") : t("updateInstall")}
</button>
</Button>
) : null}
{/* An install is a countdown to this process exiting, so the row drops the
choice that only resets what is already decided. */}
{verified && !installing ? (
<button className="update-action" onClick={() => void clear()}>
<Button variant="secondary" size="md" onClick={() => void clear()}>
<X size={15} />
{t("updateDiscard")}
</button>
</Button>
) : null}
</div>
<label className="home-toggle-row home-toggle-divider">
<strong>{t("updateAutoCheck")}</strong>
<button
className={`home-toggle ${autoCheck ? "is-on" : ""}`}
onClick={() => onAutoCheckChange(!autoCheck)}
aria-pressed={autoCheck}
>
<span />
</button>
</label>
<SwitchRow
label={t("updateAutoCheck")}
checked={autoCheck}
onChange={onAutoCheckChange}
divider
/>
<p className="runtime-summary">{t("updateBody")}</p>
</section>
</Section>
);
}

View File

@ -1,6 +1,8 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./ui/tokens.css";
import "./ui/components.css";
import "./styles.css";
createRoot(document.getElementById("root")!).render(

File diff suppressed because it is too large Load Diff

1166
src/ui/components.css 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,478 @@
import {
forwardRef,
type ButtonHTMLAttributes,
type ElementType,
type HTMLAttributes,
type InputHTMLAttributes,
type LabelHTMLAttributes,
type ReactNode,
type TextareaHTMLAttributes,
} from "react";
import { Check, Search, X } from "lucide-react";
function cx(...parts: Array<string | false | null | undefined>) {
return parts.filter(Boolean).join(" ");
}
export type ButtonVariant =
| "primary"
| "secondary"
| "ghost"
| "quiet"
| "outline"
| "danger"
| "success"
| "toolbar"
| "toolbar-primary"
| "toolbar-danger"
| "inverse"
| "glass-dark"
| "plain"
| "card"
| "tab";
export type ButtonSize = "xs" | "sm" | "md" | "lg" | "xl";
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: ButtonVariant;
size?: ButtonSize;
iconOnly?: boolean;
active?: boolean;
block?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
{
variant = "secondary",
size = "md",
iconOnly = false,
active = false,
block = false,
className,
type = "button",
...props
},
ref,
) {
return (
<button
ref={ref}
type={type}
className={cx(
"ui-button",
`ui-button--${variant}`,
`ui-button--${size}`,
iconOnly && "ui-button--icon",
block && "ui-button--block",
active && "is-active",
className,
)}
data-active={active || undefined}
{...props}
/>
);
});
export interface IconButtonProps extends Omit<ButtonProps, "children" | "iconOnly"> {
label: string;
children: ReactNode;
}
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
{ label, title, variant = "ghost", size = "sm", className, children, ...props },
ref,
) {
return (
<Button
ref={ref}
variant={variant}
size={size}
iconOnly
aria-label={label}
title={title ?? label}
className={className}
{...props}
>
{children}
</Button>
);
});
export type SurfaceVariant =
| "glass"
| "solid"
| "muted"
| "inset"
| "danger"
| "dark"
| "plain";
export type SurfaceRadius = "sm" | "md" | "lg" | "xl" | "hero";
export interface SurfaceProps extends HTMLAttributes<HTMLDivElement> {
variant?: SurfaceVariant;
radius?: SurfaceRadius;
as?: ElementType;
}
export function Surface({
variant = "glass",
radius = "lg",
as: Component = "div",
className,
...props
}: SurfaceProps) {
return (
<Component
className={cx(
"ui-surface",
`ui-surface--${variant}`,
`ui-surface--radius-${radius}`,
className,
)}
{...props}
/>
);
}
export interface SectionProps extends HTMLAttributes<HTMLElement> {}
export function Section({ className, ...props }: SectionProps) {
return <section className={cx("ui-section", className)} {...props} />;
}
export interface SectionTitleProps extends HTMLAttributes<HTMLDivElement> {
icon?: ReactNode;
actions?: ReactNode;
}
export function SectionTitle({ icon, actions, children, className, ...props }: SectionTitleProps) {
return (
<div className={cx("ui-section-title", className)} {...props}>
{icon}
<span className="ui-section-title__copy">{children}</span>
{actions ? <span className="ui-section-title__actions">{actions}</span> : null}
</div>
);
}
export type BadgeTone = "neutral" | "accent" | "success" | "danger" | "warning" | "info";
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
tone?: BadgeTone;
plain?: boolean;
}
export function Badge({ tone = "neutral", plain = false, className, ...props }: BadgeProps) {
return (
<span
className={cx("ui-badge", `ui-badge--${tone}`, plain && "ui-badge--plain", className)}
{...props}
/>
);
}
export type BannerTone = "accent" | "success" | "danger" | "neutral";
export interface BannerProps extends HTMLAttributes<HTMLDivElement> {
tone?: BannerTone;
icon?: ReactNode;
action?: ReactNode;
compact?: boolean;
inline?: boolean;
}
export function Banner({
tone = "accent",
icon,
action,
compact = false,
inline = false,
children,
className,
...props
}: BannerProps) {
return (
<div
className={cx(
"ui-banner",
`ui-banner--${tone}`,
compact && "ui-banner--compact",
inline && "ui-banner--inline",
className,
)}
{...props}
>
{icon}
<span className="ui-banner__copy">{children}</span>
{action ? <span className="ui-banner__action">{action}</span> : null}
</div>
);
}
export interface SwitchRowProps {
label: ReactNode;
checked: boolean;
onChange: (checked: boolean) => void;
divider?: boolean;
disabled?: boolean;
className?: string;
}
export function SwitchRow({
label,
checked,
onChange,
divider = false,
disabled = false,
className,
}: SwitchRowProps) {
return (
<div className={cx("ui-switch-row", divider && "ui-switch-row--divider", className)}>
<span className="ui-switch-row__label">{label}</span>
<button
type="button"
role="switch"
aria-checked={checked}
className="ui-switch"
disabled={disabled}
onClick={() => onChange(!checked)}
/>
</div>
);
}
export interface SegmentedOption<T extends string> {
value: T;
label: ReactNode;
}
export interface SegmentedProps<T extends string> {
value: T;
options: Array<SegmentedOption<T>>;
onChange: (value: T) => void;
ariaLabel: string;
className?: string;
}
export function Segmented<T extends string>({
value,
options,
onChange,
ariaLabel,
className,
}: SegmentedProps<T>) {
return (
<div className={cx("ui-segmented", className)} role="radiogroup" aria-label={ariaLabel}>
{options.map((option) => (
<button
key={option.value}
type="button"
role="radio"
aria-checked={value === option.value}
className="ui-segmented__item"
onClick={() => onChange(option.value)}
>
{option.label}
</button>
))}
</div>
);
}
export const Input = forwardRef<HTMLInputElement, InputHTMLAttributes<HTMLInputElement>>(
function Input({ className, ...props }, ref) {
return <input ref={ref} className={cx("ui-input", className)} {...props} />;
},
);
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaHTMLAttributes<HTMLTextAreaElement>>(
function Textarea({ className, ...props }, ref) {
return <textarea ref={ref} className={cx("ui-textarea", className)} {...props} />;
},
);
export interface SearchFieldProps {
value: string;
onChange: (value: string) => void;
placeholder: string;
clearLabel: string;
className?: string;
}
export function SearchField({
value,
onChange,
placeholder,
clearLabel,
className,
}: SearchFieldProps) {
return (
<label className={cx("ui-search", className)}>
<Search size={15} />
<input
className="ui-search__input"
value={value}
placeholder={placeholder}
onChange={(event) => onChange(event.target.value)}
/>
{value ? (
<IconButton
label={clearLabel}
variant="ghost"
size="xs"
onClick={() => onChange("")}
>
<X size={13} />
</IconButton>
) : null}
</label>
);
}
export interface ProgressBarProps {
value?: number;
indeterminate?: boolean;
tone?: "accent" | "success";
size?: "xs" | "sm" | "md" | "lg";
label?: ReactNode;
className?: string;
}
export function ProgressBar({
value = 0,
indeterminate = false,
tone = "accent",
size = "sm",
label,
className,
}: ProgressBarProps) {
return (
<div
className={cx(
"ui-progress",
`ui-progress--${size}`,
`ui-progress--${tone}`,
indeterminate && "ui-progress--indeterminate",
className,
)}
role="progressbar"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={indeterminate ? undefined : Math.round(value)}
>
<span
className="ui-progress__fill"
style={indeterminate ? undefined : { width: `${Math.max(0, Math.min(100, value))}%` }}
/>
{label ? <span className="ui-progress__label">{label}</span> : null}
</div>
);
}
export interface EmptyStateProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
glyph?: ReactNode;
title?: ReactNode;
}
export function EmptyState({ glyph, title, children, className, ...props }: EmptyStateProps) {
return (
<div className={cx("ui-empty", className)} {...props}>
{glyph ? <span className="ui-empty__glyph">{glyph}</span> : null}
{title ? <strong className="ui-empty__title">{title}</strong> : null}
{children ? <p className="ui-empty__copy">{children}</p> : null}
</div>
);
}
export interface ToastProps extends HTMLAttributes<HTMLDivElement> {
tone?: "neutral" | "error";
size?: "sm" | "md";
}
export function Toast({ tone = "neutral", size = "md", className, ...props }: ToastProps) {
return (
<div className={cx("ui-toast", `ui-toast--${tone}`, `ui-toast--${size}`, className)} {...props} />
);
}
export interface ToolbarProps extends HTMLAttributes<HTMLDivElement> {
tone?: "light" | "dark";
variant?: "floating" | "bar";
}
export const Toolbar = forwardRef<HTMLDivElement, ToolbarProps>(function Toolbar(
{ tone = "light", variant = "floating", className, ...props },
ref,
) {
return (
<div
ref={ref}
className={cx(
"ui-toolbar",
`ui-toolbar--${variant}`,
tone === "dark" && "ui-toolbar--dark",
className,
)}
{...props}
/>
);
});
export function ToolbarDivider({ className }: { className?: string }) {
return <span className={cx("ui-toolbar__divider", className)} aria-hidden="true" />;
}
export function CheckboxMark({ checked }: { checked: boolean }) {
return (
<span className="ui-checkbox__box" data-checked={checked || undefined} aria-hidden="true">
{checked ? <Check size={11} strokeWidth={3} /> : null}
</span>
);
}
export interface CheckboxProps
extends Omit<LabelHTMLAttributes<HTMLLabelElement>, "onChange"> {
checked: boolean;
onChange: (checked: boolean) => void;
disabled?: boolean;
}
export const Checkbox = forwardRef<HTMLLabelElement, CheckboxProps>(function Checkbox(
{ checked, onChange, disabled = false, className, children, ...props },
ref,
) {
return (
<label ref={ref} className={cx("ui-checkbox", className)} {...props}>
<input
type="checkbox"
checked={checked}
disabled={disabled}
onChange={() => onChange(!checked)}
/>
<CheckboxMark checked={checked} />
{children}
</label>
);
});
export interface KbdProps {
children: ReactNode;
tone?: "light" | "dark";
size?: "sm" | "md";
}
export function Kbd({ children, tone = "light", size = "md" }: KbdProps) {
return (
<kbd className={cx("ui-kbd", `ui-kbd--${tone}`, `ui-kbd--${size}`)}>
{children}
</kbd>
);
}
export function Code({ children, className, ...props }: HTMLAttributes<HTMLElement>) {
return (
<code className={cx("ui-code", className)} {...props}>
{children}
</code>
);
}

123
src/ui/tokens.css 100644
View File

@ -0,0 +1,123 @@
:root {
color-scheme: light;
font-family:
-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC",
"Hiragino Sans GB", "Microsoft YaHei", sans-serif;
color: var(--ui-text);
background: transparent;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
--ui-font-sans:
-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC",
"Hiragino Sans GB", "Microsoft YaHei", sans-serif;
--ui-font-mono: "SFMono-Regular", "SF Mono", "Cascadia Code", ui-monospace, monospace;
--ui-text: #342019;
--ui-text-strong: #2d1a11;
--ui-text-soft: #6f5447;
--ui-text-muted: #92786a;
--ui-text-faint: #aa9081;
--ui-text-on-dark: #fff7f1;
--ui-text-on-accent: #fff8f2;
--ui-bg: #f5eee7;
--ui-bg-elevated: #fbf7f2;
--ui-surface: rgba(255, 252, 249, 0.78);
--ui-surface-strong: #fffbf7;
--ui-surface-solid: #fff;
--ui-surface-hover: #fff;
--ui-surface-muted: rgba(91, 55, 35, 0.055);
--ui-surface-inset: rgba(255, 255, 255, 0.62);
--ui-surface-dark: rgba(31, 26, 25, 0.9);
--ui-border: rgba(89, 51, 34, 0.1);
--ui-border-soft: rgba(89, 51, 34, 0.07);
--ui-border-strong: rgba(89, 51, 34, 0.18);
--ui-border-on-dark: rgba(255, 255, 255, 0.14);
--ui-accent: #f26a33;
--ui-accent-strong: #d94f1f;
--ui-accent-soft: #fff0e5;
--ui-accent-wash: rgba(242, 106, 51, 0.1);
--ui-accent-line: rgba(242, 106, 51, 0.24);
--ui-focus: rgba(242, 106, 51, 0.55);
--ui-focus-ring: 0 0 0 3px rgba(242, 106, 51, 0.14);
--ui-success: #14794a;
--ui-success-strong: #0f6439;
--ui-success-soft: #edf8f1;
--ui-danger: #b8442a;
--ui-danger-strong: #9c3d2f;
--ui-danger-soft: #fff0ed;
--ui-warning: #a84c29;
--ui-warning-soft: #fff1e7;
--ui-info: #4b6fa8;
--ui-info-soft: #eaf0fb;
--ui-shadow-xs: 0 2px 7px rgba(74, 43, 27, 0.08);
--ui-shadow-sm: 0 8px 24px rgba(74, 43, 27, 0.09);
--ui-shadow-md: 0 14px 38px rgba(74, 43, 27, 0.14);
--ui-shadow-lg: 0 28px 76px rgba(62, 33, 18, 0.22);
--ui-shadow-dark: 0 16px 44px rgba(0, 0, 0, 0.28);
--ui-radius-xs: 7px;
--ui-radius-sm: 10px;
--ui-radius-md: 13px;
--ui-radius-lg: 16px;
--ui-radius-xl: 22px;
--ui-radius-hero: 26px;
--ui-radius-pill: 999px;
--ui-space-1: 2px;
--ui-space-2: 4px;
--ui-space-3: 6px;
--ui-space-4: 8px;
--ui-space-5: 10px;
--ui-space-6: 12px;
--ui-space-7: 16px;
--ui-space-8: 20px;
--ui-space-9: 24px;
--ui-space-10: 32px;
--ui-control-xs: 26px;
--ui-control-sm: 32px;
--ui-control-md: 36px;
--ui-control-lg: 44px;
--ui-control-xl: 46px;
--ui-text-3xs: 11px;
--ui-text-2xs: 12.5px;
--ui-text-xs: 13.5px;
--ui-text-sm: 14.5px;
--ui-text-md: 16px;
--ui-text-lg: 18px;
--ui-text-xl: 21px;
--ui-text-hero: clamp(28px, 3vw, 38px);
--ui-dimmed: 0.55;
--ui-duration-fast: 140ms;
--ui-duration: 180ms;
--ui-ease: cubic-bezier(0.22, 0.68, 0.32, 1);
/* Compatibility aliases for view-level layout code while it is migrated. */
--ink: var(--ui-text);
--muted: var(--ui-text-muted);
--orange: var(--ui-accent);
--orange-deep: var(--ui-accent-strong);
--cream: #fff6ee;
--paper: var(--ui-bg-elevated);
--line: var(--ui-border);
--text-3xs: var(--ui-text-3xs);
--text-2xs: var(--ui-text-2xs);
--text-xs: var(--ui-text-xs);
--text-sm: var(--ui-text-sm);
--text-md: var(--ui-text-md);
--text-lg: var(--ui-text-lg);
--text-xl: var(--ui-text-xl);
--text-hero: var(--ui-text-hero);
--dimmed: var(--ui-dimmed);
--radius-sm: var(--ui-radius-md);
--radius-md: var(--ui-radius-lg);
}