@squadbase/vantage-template 0.1.0-dev.c40b771 → 0.1.0-dev1.f48cfad
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/base-template/.squadbase/skills/vantage-app/SKILL.md +6 -6
- package/base-template/.squadbase/skills/vantage-design/SKILL.md +137 -0
- package/base-template/.squadbase/skills/vantage-design/references/extract.md +110 -0
- package/base-template/.squadbase/skills/vantage-design/references/format.md +172 -0
- package/base-template/.squadbase/skills/vantage-design/references/presets.md +110 -0
- package/base-template/.squadbase/skills/vantage-design/scripts/contrast.mjs +166 -0
- package/base-template/AGENTS.md +62 -229
- package/base-template/DESIGN.md +108 -0
- package/base-template/agents/api.md +49 -0
- package/base-template/agents/csv.md +32 -0
- package/base-template/agents/doc.md +73 -0
- package/base-template/agents/page.md +187 -0
- package/base-template/agents/slide.md +41 -0
- package/base-template/agents/xlsx.md +33 -0
- package/base-template/automations/.gitkeep +0 -0
- package/base-template/bun.lock +907 -0
- package/base-template/package.json +2 -2
- package/base-template/pipelines/pyproject.toml +5 -0
- package/base-template/squadbase.yml +1 -0
- package/base-template/src/index.tsx +53 -8
- package/dist/index.js +15 -6
- package/package.json +2 -2
- package/ui-templates/chart-grid/pages/index.tsx +1 -1
- package/ui-templates/chart-grid-ja/pages/index.tsx +1 -1
- package/ui-templates/funnel/pages/index.tsx +2 -2
- package/ui-templates/funnel-ja/pages/index.tsx +2 -2
- package/base-template/package-lock.json +0 -5767
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// WCAG 2.x contrast ratio between two CSS colours. No dependencies.
|
|
3
|
+
//
|
|
4
|
+
// node contrast.mjs <foreground> <background>
|
|
5
|
+
// node contrast.mjs '#ffffff' 'oklch(0.205 0 0)'
|
|
6
|
+
// node contrast.mjs 'oklch(0.985 0 0)' 'var(--color-sky-700)'
|
|
7
|
+
//
|
|
8
|
+
// Accepts: #rgb / #rgba / #rrggbb / #rrggbbaa, rgb()/rgba(), oklch(), and
|
|
9
|
+
// Tailwind palette references `var(--color-<name>-<step>)` (resolved from
|
|
10
|
+
// node_modules/tailwindcss/theme.css, searched upward from the cwd).
|
|
11
|
+
// A translucent foreground is composited over the background first; the
|
|
12
|
+
// background is treated as opaque.
|
|
13
|
+
|
|
14
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
15
|
+
import { dirname, join } from "node:path"
|
|
16
|
+
|
|
17
|
+
function usage(message) {
|
|
18
|
+
if (message) console.error(`error: ${message}`)
|
|
19
|
+
console.error("usage: node contrast.mjs <foreground> <background>")
|
|
20
|
+
console.error(" colours: #hex, rgb(), oklch(), var(--color-<name>-<step>)")
|
|
21
|
+
process.exit(2)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// --- parsing ---------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
function parseNumber(token, percentScale = 1) {
|
|
27
|
+
const t = token.trim()
|
|
28
|
+
if (t === "none") return 0
|
|
29
|
+
if (t.endsWith("%")) return (Number.parseFloat(t) / 100) * percentScale
|
|
30
|
+
const n = Number.parseFloat(t)
|
|
31
|
+
if (Number.isNaN(n)) throw new Error(`not a number: ${token}`)
|
|
32
|
+
return n
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function splitArgs(body) {
|
|
36
|
+
const [main, alpha] = body.split("/")
|
|
37
|
+
const parts = main.trim().split(/[\s,]+/).filter(Boolean)
|
|
38
|
+
return { parts, alpha: alpha === undefined ? 1 : parseNumber(alpha, 1) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function srgbToLinear(c) {
|
|
42
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function linearToSrgb(c) {
|
|
46
|
+
const v = Math.min(1, Math.max(0, c))
|
|
47
|
+
return v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Returns gamma-encoded sRGB channels in [0, 1] plus alpha.
|
|
51
|
+
function parseHex(input) {
|
|
52
|
+
let hex = input.slice(1)
|
|
53
|
+
if (![3, 4, 6, 8].includes(hex.length) || /[^0-9a-f]/i.test(hex)) {
|
|
54
|
+
throw new Error(`bad hex colour: ${input}`)
|
|
55
|
+
}
|
|
56
|
+
if (hex.length <= 4) hex = [...hex].map((c) => c + c).join("")
|
|
57
|
+
const n = (i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255
|
|
58
|
+
return { r: n(0), g: n(2), b: n(4), a: hex.length === 8 ? n(6) : 1 }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parseRgb(body) {
|
|
62
|
+
const { parts, alpha } = splitArgs(body)
|
|
63
|
+
if (parts.length === 4) return parseRgb(`${parts.slice(0, 3).join(" ")} / ${parts[3]}`)
|
|
64
|
+
if (parts.length !== 3) throw new Error(`bad rgb(): ${body}`)
|
|
65
|
+
const [r, g, b] = parts.map((p) => parseNumber(p, 255) / 255)
|
|
66
|
+
return { r, g, b, a: alpha }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parseOklch(body) {
|
|
70
|
+
const { parts, alpha } = splitArgs(body)
|
|
71
|
+
if (parts.length !== 3) throw new Error(`bad oklch(): ${body}`)
|
|
72
|
+
const L = parseNumber(parts[0], 1)
|
|
73
|
+
const C = parseNumber(parts[1], 0.4)
|
|
74
|
+
const H = (Number.parseFloat(parts[2]) || 0) * (Math.PI / 180)
|
|
75
|
+
const a = C * Math.cos(H)
|
|
76
|
+
const bb = C * Math.sin(H)
|
|
77
|
+
const l_ = (L + 0.3963377774 * a + 0.2158037573 * bb) ** 3
|
|
78
|
+
const m_ = (L - 0.1055613458 * a - 0.0638541728 * bb) ** 3
|
|
79
|
+
const s_ = (L - 0.0894841775 * a - 1.291485548 * bb) ** 3
|
|
80
|
+
const r = 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_
|
|
81
|
+
const g = -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_
|
|
82
|
+
const b = -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_
|
|
83
|
+
return { r: linearToSrgb(r), g: linearToSrgb(g), b: linearToSrgb(b), a: alpha }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let tailwindTheme
|
|
87
|
+
function findTailwindTheme() {
|
|
88
|
+
if (tailwindTheme !== undefined) return tailwindTheme
|
|
89
|
+
tailwindTheme = null
|
|
90
|
+
let dir = process.cwd()
|
|
91
|
+
for (;;) {
|
|
92
|
+
for (const rel of [
|
|
93
|
+
"node_modules/tailwindcss/theme.css",
|
|
94
|
+
"node_modules/@squadbase/vantage/node_modules/tailwindcss/theme.css",
|
|
95
|
+
]) {
|
|
96
|
+
const file = join(dir, rel)
|
|
97
|
+
if (existsSync(file)) {
|
|
98
|
+
tailwindTheme = readFileSync(file, "utf8")
|
|
99
|
+
return tailwindTheme
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const parent = dirname(dir)
|
|
103
|
+
if (parent === dir) return tailwindTheme
|
|
104
|
+
dir = parent
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveVar(input) {
|
|
109
|
+
const name = input.match(/^var\(\s*(--color-[a-z]+-\d+)\s*\)$/)?.[1]
|
|
110
|
+
if (!name) throw new Error(`only var(--color-<name>-<step>) can be resolved: ${input}`)
|
|
111
|
+
const theme = findTailwindTheme()
|
|
112
|
+
if (!theme) throw new Error(`tailwindcss/theme.css not found from ${process.cwd()}; pass the value instead`)
|
|
113
|
+
const value = theme.match(new RegExp(`${name}:\\s*([^;]+);`))?.[1]
|
|
114
|
+
if (!value) throw new Error(`${name} is not in tailwindcss/theme.css`)
|
|
115
|
+
return value.trim()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function parseColor(raw) {
|
|
119
|
+
const input = raw.trim().toLowerCase()
|
|
120
|
+
if (input.startsWith("#")) return parseHex(input)
|
|
121
|
+
if (input.startsWith("var(")) return parseColor(resolveVar(input))
|
|
122
|
+
const fn = input.match(/^([a-z]+)\((.*)\)$/)
|
|
123
|
+
if (fn) {
|
|
124
|
+
if (fn[1] === "rgb" || fn[1] === "rgba") return parseRgb(fn[2])
|
|
125
|
+
if (fn[1] === "oklch") return parseOklch(fn[2])
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`unsupported colour: ${raw}`)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- contrast --------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
function composite(fg, bg) {
|
|
133
|
+
const mix = (f, b) => f * fg.a + b * (1 - fg.a)
|
|
134
|
+
return { r: mix(fg.r, bg.r), g: mix(fg.g, bg.g), b: mix(fg.b, bg.b), a: 1 }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function luminance({ r, g, b }) {
|
|
138
|
+
return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function toHex({ r, g, b }) {
|
|
142
|
+
const h = (c) => Math.round(Math.min(1, Math.max(0, c)) * 255).toString(16).padStart(2, "0")
|
|
143
|
+
return `#${h(r)}${h(g)}${h(b)}`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const [fgArg, bgArg] = process.argv.slice(2)
|
|
147
|
+
if (!fgArg || !bgArg) usage()
|
|
148
|
+
|
|
149
|
+
let fg
|
|
150
|
+
let bg
|
|
151
|
+
try {
|
|
152
|
+
bg = { ...parseColor(bgArg), a: 1 }
|
|
153
|
+
fg = composite(parseColor(fgArg), bg)
|
|
154
|
+
} catch (error) {
|
|
155
|
+
usage(error.message)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const [hi, lo] = [luminance(fg), luminance(bg)].sort((x, y) => y - x)
|
|
159
|
+
const ratio = (hi + 0.05) / (lo + 0.05)
|
|
160
|
+
const verdict = (min) => (ratio >= min ? "PASS" : "FAIL")
|
|
161
|
+
|
|
162
|
+
console.log(`foreground ${fgArg} (${toHex(fg)})`)
|
|
163
|
+
console.log(`background ${bgArg} (${toHex(bg)})`)
|
|
164
|
+
console.log(`contrast ${ratio.toFixed(2)}:1`)
|
|
165
|
+
console.log(`AA normal text (>= 4.5:1): ${verdict(4.5)}`)
|
|
166
|
+
console.log(`AA large text / UI (>= 3:1): ${verdict(3)}`)
|
package/base-template/AGENTS.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# AGENTS.md — Vantage アプリの地図
|
|
2
2
|
|
|
3
3
|
このファイルは、**Vantage(`@squadbase/vantage`)アプリを作るコーディングエージェント**が
|
|
4
|
-
最初に読むための地図です。アプリ作者(= `index.tsx` を書く側)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
>
|
|
9
|
-
>
|
|
10
|
-
>
|
|
4
|
+
最初に読むための地図です。アプリ作者(= `index.tsx` を書く側)が守るべき規約・不変条件を
|
|
5
|
+
1 ページに集約し、種類ごとの詳しいレシピは `agents/` 配下の知識ファイルに分けています。
|
|
6
|
+
|
|
7
|
+
> このファイルと `agents/*.md` は、いずれも **Vantage フレームワークが所有する正本**の
|
|
8
|
+
> コピーです。手で書き換えても、`vantage upgrade` を実行するとフレームワーク同梱の正本から
|
|
9
|
+
> 再同期されて上書きされます。アプリ固有のメモは別ファイル(例: `README.md`)に書いてください。
|
|
10
|
+
> 例外はプロジェクトルートの `DESIGN.md` で、これは**ユーザーが所有**します(`vantage upgrade` も
|
|
11
|
+
> `vantage add agents` も触らない。→「デザインの意図(DESIGN.md)」)。
|
|
11
12
|
>
|
|
12
13
|
> 手順を伴う踏み込んだワークフローは、同梱の Claude Code Skill に分かれています。このファイルは
|
|
13
|
-
>
|
|
14
|
-
>
|
|
14
|
+
> 「地図」、`agents/*.md` は「種類ごとの静的リファレンス」、Skill は「手順書」という役割分担です。
|
|
15
|
+
> **配置済みの Skill を先に探す**手順は末尾の「さらに詳しく(同梱 Skill)」にあります。
|
|
15
16
|
|
|
16
17
|
## Vantage とは
|
|
17
18
|
|
|
@@ -39,8 +40,8 @@ UI キット・開発サーバー・API サーバー・ビルドはすべて Van
|
|
|
39
40
|
- **色はセマンティックトークンで書く。** `text-foreground`・`text-muted-foreground`・`bg-card`・
|
|
40
41
|
`border-border`。トークンがライト / ダークの両方を持つので `dark:` を並べる必要が無い。
|
|
41
42
|
素のパレット + `dark:`(`text-slate-900 dark:text-slate-100`)を混ぜると、その 1 か所だけ
|
|
42
|
-
手動で 2 モードを管理することになる(
|
|
43
|
-
`--secondary`・`--border` は背景・境界用で、文字色に使うと読めない。
|
|
43
|
+
手動で 2 モードを管理することになる(→ `agents/page.md` の「ダークモードは opt-in」)。
|
|
44
|
+
`--muted`・`--accent`・`--secondary`・`--border` は背景・境界用で、文字色に使うと読めない。
|
|
44
45
|
- **`.vantage/` と `dist/` は生成物。** 編集しない・読みにいかない(gitignore 済み)。任意の CLI
|
|
45
46
|
コマンド、または `vantage upgrade` で再生成される。
|
|
46
47
|
- **`definePage` の値はリテラルで書く。** title/description/navLabel はビルド時に静的抽出される
|
|
@@ -93,6 +94,9 @@ root/
|
|
|
93
94
|
| `@squadbase/vantage/query` | `useApiQuery`・`useApiMutation`・`apiJson`・`apiFetch`・`apiUrl`・`ApiError`、ほか `useQuery`/`useMutation` など TanStack Query の再エクスポート |
|
|
94
95
|
| `@squadbase/vantage/ui` | shadcn/ui(Base UI バリアント)プリミティブ(`Button`・`Loading`・`ErrorState`・`Empty` ほか) |
|
|
95
96
|
| `@squadbase/vantage/components` | 複合パーツ(`PageShell`・`DashboardCardPreset`・`DataTablePreset`・`EChart` ほか) |
|
|
97
|
+
| `@squadbase/vantage/table` | `FilePageView`・`TableViewer`(データファイルページの表ビューア) |
|
|
98
|
+
| `@squadbase/vantage/slide` | `SlideDeck`・`Slide`・`Steps`・`Step`・`MorphElement`・`useSlideNumber`・`useIsActiveSlide`(スライド専用。1920×1080 の固定キャンバス) |
|
|
99
|
+
| `@squadbase/vantage/doc` | `Document`(ドキュメント専用。中の素の HTML 要素に見出し・表などのスタイルが当たる) |
|
|
96
100
|
| `@squadbase/vantage/markdown` | `MarkdownRenderer`(Shiki を隔離するための専用サブパス) |
|
|
97
101
|
| `@squadbase/vantage/server` | `ApiContext`・`ApiHandler`・`HttpError`・`isHttpError`・`json`(server/ 側でのみ使う) |
|
|
98
102
|
|
|
@@ -101,207 +105,37 @@ root/
|
|
|
101
105
|
`server/` ディレクトリがあれば **fullstack**、無ければ **SPA**。`vantage-manifest.json` の
|
|
102
106
|
`mode` はここから自動で決まり、手で書く設定は無い。**SPA から始めて fullstack へ「昇格」する
|
|
103
107
|
必要はない** ― テンプレートから始めた場合は最初から `server/` があり、その時点で fullstack。
|
|
104
|
-
下の 2
|
|
105
|
-
|
|
106
|
-
- `server/` が**ある** → 「API を持つ(fullstack モード)」を見る。データは自前の `/api/*` から
|
|
107
|
-
`useApiQuery` で取る。
|
|
108
|
-
- `server/` が**無い** → 「最小アプリ(2 ファイル)」の構成。外部 API を直接叩くなら `useQuery`。
|
|
109
|
-
自前の API が要るようになったら `server/api/*.ts` を足すだけでよい(設定変更は不要)。
|
|
110
|
-
|
|
111
|
-
## 最小アプリ(2 ファイル)
|
|
112
|
-
|
|
113
|
-
`package.json` と `index.tsx` の 2 ファイルだけで動く。
|
|
114
|
-
|
|
115
|
-
`package.json`:
|
|
116
|
-
|
|
117
|
-
```json
|
|
118
|
-
{
|
|
119
|
-
"name": "my-dashboard",
|
|
120
|
-
"private": true,
|
|
121
|
-
"type": "module",
|
|
122
|
-
"scripts": {
|
|
123
|
-
"dev": "vantage dev",
|
|
124
|
-
"build": "vantage build",
|
|
125
|
-
"preview": "vantage preview",
|
|
126
|
-
"check": "vantage check",
|
|
127
|
-
"routes": "vantage routes"
|
|
128
|
-
},
|
|
129
|
-
"dependencies": {
|
|
130
|
-
"@squadbase/vantage": "^0.5.0",
|
|
131
|
-
"react": "^19.2.7",
|
|
132
|
-
"react-dom": "^19.2.7"
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
108
|
+
下の 2 つは段階ではなく、いま自分がどちらにいるかを確かめるための地図として読む。
|
|
136
109
|
|
|
137
|
-
`
|
|
110
|
+
- `server/` が**ある** → データは自前の `/api/*` から `useApiQuery` で取る(→ `agents/api.md`)。
|
|
111
|
+
- `server/` が**無い** → 外部 API を直接叩くなら `useQuery`(→ `agents/page.md`)。自前の API が
|
|
112
|
+
要るようになったら `server/api/*.ts` を足すだけでよい(設定変更は不要)。
|
|
138
113
|
|
|
139
|
-
|
|
140
|
-
export default function Dashboard() {
|
|
141
|
-
return (
|
|
142
|
-
<main className="p-6">
|
|
143
|
-
<h1 className="text-2xl font-semibold">Dashboard</h1>
|
|
144
|
-
</main>
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
```
|
|
114
|
+
## デザインの意図(DESIGN.md)
|
|
148
115
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
pnpm check # 静的診断(エラーがあれば exit 1)
|
|
153
|
-
pnpm routes # ページ/API の URL マップ
|
|
154
|
-
```
|
|
116
|
+
プロジェクトルートに `DESIGN.md` があれば、**UI(ページ・スライド・コンポーネント)を書く前に
|
|
117
|
+
読む。** 色・チャート・書体・レイアウトの使い分けがトークン名で書いてあるので、それに従って
|
|
118
|
+
トークンで書く(値は `styles.css` にあり、`DESIGN.md` には色コードを書かない)。
|
|
155
119
|
|
|
156
|
-
`
|
|
157
|
-
|
|
158
|
-
|
|
120
|
+
- **会話中の指示は `DESIGN.md` より優先する。** 同じ指示が繰り返されたら、`DESIGN.md` への
|
|
121
|
+
反映をユーザーに提案する。
|
|
122
|
+
- **「色を変えて」「ブランドに合わせて」などデザイン全体の変更は、ファイルごとに直さない。**
|
|
123
|
+
Skill `vantage-design` の手順で `DESIGN.md` と `styles.css` をまとめて更新する。
|
|
124
|
+
- `DESIGN.md` はユーザーの持ち物。`vantage upgrade` は書き換えない。
|
|
159
125
|
|
|
160
|
-
##
|
|
126
|
+
## 何を書くか → どのファイルを読むか
|
|
161
127
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
`MISSING_DEFAULT_EXPORT`)。以下の「ファイル」列はページルートからの相対パス。
|
|
128
|
+
**書こうとしている種類のファイルだけを開けばよい。** まず該当する 1 ファイルを readFiles で
|
|
129
|
+
読んでから書き始める。
|
|
165
130
|
|
|
166
|
-
|
|
|
131
|
+
| 書こうとしているもの | 読むファイル |
|
|
167
132
|
| --- | --- |
|
|
168
|
-
|
|
|
169
|
-
| `
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `_error.tsx` | ルートが throw したときのエラーページ |
|
|
175
|
-
|
|
176
|
-
`components/`・`hooks/`・`lib/`・`server/`・`public/` はどの階層でもルート走査の対象外
|
|
177
|
-
(ページにならない)。それ以外のディレクトリ名は URL のセグメントになる(→「ディレクトリ構造」)。
|
|
178
|
-
|
|
179
|
-
```tsx
|
|
180
|
-
import { definePage } from "@squadbase/vantage"
|
|
181
|
-
|
|
182
|
-
// title は document.title、navLabel は useRoutes() で組むナビの表示名(既定は title)
|
|
183
|
-
export const page = definePage({ title: "Monthly Analysis · Acme", navLabel: "Monthly" })
|
|
184
|
-
|
|
185
|
-
export default function MonthlyAnalysis() {
|
|
186
|
-
return <main className="p-6">…</main>
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### ナビはルート一覧から組む
|
|
191
|
-
|
|
192
|
-
`useRoutes()` がページルート一覧(スキャン順)を返すので、リンク配列を手で持たない。
|
|
193
|
-
`useCurrentRoute()` は現在のルート(404 なら `undefined`)。
|
|
194
|
-
|
|
195
|
-
```tsx
|
|
196
|
-
import { Link, useCurrentRoute, useRoutes } from "@squadbase/vantage/router"
|
|
197
|
-
|
|
198
|
-
// 動的ルートは URL が定まらないので外す。label は navLabel → title → path の順
|
|
199
|
-
const routes = useRoutes().filter((r) => !r.dynamic)
|
|
200
|
-
const current = useCurrentRoute()
|
|
201
|
-
|
|
202
|
-
routes.map((r) => (
|
|
203
|
-
<Link key={r.path} to={r.to} activeClassName="font-semibold">
|
|
204
|
-
{r.label}
|
|
205
|
-
</Link>
|
|
206
|
-
))
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
`RouteInfo`: `path`(`/sales/:id`)・`to`(`/sales/$id`)・`params`・`dynamic`・`index`・`label`・
|
|
210
|
-
`title`・`description`・`navLabel`。
|
|
211
|
-
|
|
212
|
-
### フィルタ状態は URL に置く
|
|
213
|
-
|
|
214
|
-
リロードで消えず、URL をそのまま共有できる。`useState` と同じ形。
|
|
215
|
-
|
|
216
|
-
```tsx
|
|
217
|
-
import { useSearchParam, useSearchState } from "@squadbase/vantage/router"
|
|
218
|
-
|
|
219
|
-
const [region, setRegion] = useSearchParam("region", "all") // 常に string
|
|
220
|
-
const [segments, setSegments] = useSearchState<string[]>("segments", []) // JSON になる値
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
デフォルト値(または `null`)を書くとキーは URL から消える。履歴は既定で `replace`
|
|
224
|
-
(`{ replace: false }` で push)。
|
|
225
|
-
|
|
226
|
-
### 動的パラメータの「3 つの綴り」を同期させる
|
|
227
|
-
|
|
228
|
-
崩すと静かにマッチしなくなる不変条件:
|
|
229
|
-
|
|
230
|
-
- ファイル名 `sales/[customerId].tsx`
|
|
231
|
-
- 表示ルート `/sales/:customerId`
|
|
232
|
-
- リンクトークン `to="/sales/$customerId"` + `params={{ customerId }}`
|
|
233
|
-
|
|
234
|
-
```tsx
|
|
235
|
-
import { Link, useParams } from "@squadbase/vantage/router"
|
|
236
|
-
|
|
237
|
-
<Link to="/sales/$customerId" params={{ customerId: row.id }}>{row.name}</Link>
|
|
238
|
-
|
|
239
|
-
// 詳細ページ側で取り出す
|
|
240
|
-
const { customerId } = useParams()
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## データ取得(server を持たない fetch)
|
|
244
|
-
|
|
245
|
-
外部 API を叩くだけなら `server/` は不要。`@squadbase/vantage/query` の `useQuery` を使う:
|
|
246
|
-
|
|
247
|
-
```tsx
|
|
248
|
-
import { useQuery } from "@squadbase/vantage/query"
|
|
249
|
-
import { Loading, ErrorState } from "@squadbase/vantage/ui"
|
|
250
|
-
|
|
251
|
-
const q = useQuery({ queryKey: ["stats"], queryFn: () => fetch("/…").then((r) => r.json()) })
|
|
252
|
-
if (q.isPending) return <Loading />
|
|
253
|
-
if (q.isError) return <ErrorState message={(q.error as Error).message} />
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
`QueryClient` は Vantage が 1 つだけ管理する(staleTime 30s・retry 1・
|
|
257
|
-
refetchOnWindowFocus false・networkMode "always")。挙動を変えたいときはクエリ側のオプションで
|
|
258
|
-
上書きする。
|
|
259
|
-
自分の `server/api` を叩くときは `useQuery` ではなく `useApiQuery`(→「API を持つ(fullstack
|
|
260
|
-
モード)」)。
|
|
261
|
-
|
|
262
|
-
## API を持つ(fullstack モード)
|
|
263
|
-
|
|
264
|
-
**`server/` ディレクトリがあれば fullstack モード**(無いアプリに足せば、その時点で切り替わる)。
|
|
265
|
-
`server/api/**` の各ファイルが API ルートになる。
|
|
266
|
-
|
|
267
|
-
`server/api/monthly-analysis.ts` → `GET /api/monthly-analysis`:
|
|
268
|
-
|
|
269
|
-
```ts
|
|
270
|
-
import type { ApiContext } from "@squadbase/vantage/server"
|
|
271
|
-
import { HttpError } from "@squadbase/vantage/server"
|
|
272
|
-
|
|
273
|
-
export async function GET({ params, env }: ApiContext) {
|
|
274
|
-
if (!env.API_KEY) throw new HttpError(500, "API_KEY missing")
|
|
275
|
-
return Response.json({ ok: true })
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
- API モジュールは**大文字の HTTP メソッド**(`GET`/`POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`)を
|
|
280
|
-
エクスポートする。それ以外の名前は `INVALID_API_EXPORT` エラー。
|
|
281
|
-
- 動的 API も `[id].ts` 記法: `server/api/customers/[id].ts` → `GET /api/customers/:id`。
|
|
282
|
-
`params.id` で取り出す(`noUncheckedIndexedAccess` が効くので narrowing が要る)。
|
|
283
|
-
- **クライアントに見せたいエラーは `HttpError(status, msg)` を throw する。** それ以外の throw は
|
|
284
|
-
ログに記録され汎用の 500 に丸められる。
|
|
285
|
-
- **シークレットは `ApiContext.env` にだけ届く**(クライアントには決して届かない)。
|
|
286
|
-
|
|
287
|
-
クライアント側からは `useApiQuery` で `/api/*` を叩く。ベース URL の解決・JSON パース・
|
|
288
|
-
非 2xx の `ApiError` 化・クエリキー(`["api", url]`)が入っている:
|
|
289
|
-
|
|
290
|
-
```tsx
|
|
291
|
-
import { useApiQuery, useApiMutation } from "@squadbase/vantage/query"
|
|
292
|
-
|
|
293
|
-
const q = useApiQuery<Customer>(`/api/customers/${customerId}`)
|
|
294
|
-
if (q.isError) return <ErrorState message={q.error.message} /> // HttpError のメッセージ
|
|
295
|
-
|
|
296
|
-
// クエリ文字列は search で。undefined の項目は落ちる
|
|
297
|
-
const rows = useApiQuery<Row[]>("/api/customers", { search: { segment } })
|
|
298
|
-
|
|
299
|
-
// 書き込み。変数がそのまま JSON ボディになる
|
|
300
|
-
const save = useApiMutation<Customer, Payload>("/api/customers", { method: "POST" })
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
`ApiError` は `message`・`status`・`body`・`requestId` を持つ。hook が使えない場所では
|
|
304
|
-
`apiJson(path, init)`、生の `Response` が要るときは `apiFetch`。
|
|
133
|
+
| ダッシュボード / 通常ページ(`.tsx`) | `agents/page.md` |
|
|
134
|
+
| API(`server/`) | `agents/api.md` |
|
|
135
|
+
| スライド(`.slide.tsx`) | `agents/slide.md` |
|
|
136
|
+
| ドキュメント(`.doc.tsx`) | `agents/doc.md` |
|
|
137
|
+
| `.xlsx` ページ | `agents/xlsx.md` |
|
|
138
|
+
| `.csv` ページ | `agents/csv.md` |
|
|
305
139
|
|
|
306
140
|
## 環境変数
|
|
307
141
|
|
|
@@ -309,30 +143,6 @@ const save = useApiMutation<Customer, Payload>("/api/customers", { method: "POST
|
|
|
309
143
|
のみ。** `VITE_` 系の公開 API は無い。
|
|
310
144
|
- サーバー側のシークレットは `ApiContext.env.MY_SECRET` で読む(`server/` 内のみ)。
|
|
311
145
|
|
|
312
|
-
## 組み込み UI / コンポーネントの入口
|
|
313
|
-
|
|
314
|
-
- **プリミティブ**は `@squadbase/vantage/ui` から import する(`Button`・`Loading`・
|
|
315
|
-
`ErrorState`・`Empty`・`Select`・`Checkbox` ほか)。
|
|
316
|
-
- **複合パーツ**は `@squadbase/vantage/components` から(`PageShell`・`DashboardCardPreset`・
|
|
317
|
-
`DataTablePreset`・`EChart` ほか)。
|
|
318
|
-
- **どの名前が import 可能か / props の詳細は `vantage docs` で引く。** ガイドとコンポーネント
|
|
319
|
-
リファレンスはパッケージに同梱されていて、オフラインでも読める(→「ドキュメントを引く」)。
|
|
320
|
-
**名前が分からないとき**はやりたいことで `vantage search` する(→ 同節)。
|
|
321
|
-
- **UI は import して使うのが既定。取り出す(eject)必要はない。** `vantage add ui|block` は
|
|
322
|
-
ソースを手元にコピーして**改造したいとき専用**のコマンドで、取り出せるのは
|
|
323
|
-
`ui: data-table` と `block: sales-overview` の 2 つだけ。それ以外の名前は import 専用で
|
|
324
|
-
`add` の対象ではない(未知名で実行すると候補が一覧表示される)。
|
|
325
|
-
|
|
326
|
-
### ダークモードは opt-in
|
|
327
|
-
|
|
328
|
-
ダークのトークンが効くのは、祖先に `.dark` か `[data-theme="dark"]` が付いているときだけ。
|
|
329
|
-
**OS / ブラウザの設定(`prefers-color-scheme`)は見ない。** `dark:` ユーティリティも同じ
|
|
330
|
-
スイッチに繋いであるので(`theme.css` の `@custom-variant dark`)、自分でクラスを付けない限り
|
|
331
|
-
アプリは常にライトで描かれる ― `dark:` を書いてもそこだけダークになることはない。
|
|
332
|
-
|
|
333
|
-
明暗を切り替えたいときは、レイアウトのルート要素などに `.dark` / `data-theme="dark"` を
|
|
334
|
-
自分で付ける。
|
|
335
|
-
|
|
336
146
|
## ドキュメントを引く(`vantage docs` / `vantage search`)
|
|
337
147
|
|
|
338
148
|
```bash
|
|
@@ -378,6 +188,8 @@ body・レスポンスの status と形)まで出る。`vantage check --json` /
|
|
|
378
188
|
|
|
379
189
|
- **`vantage-app`** — アプリを一から作る / 構成を広げるときの進め方と検証の順序
|
|
380
190
|
- **`vantage-add-feature`** — 既存アプリに page / api / ui を 1 つ足す定型
|
|
191
|
+
- **`vantage-slide`** — `.slide.tsx` でスライドデッキを書く(キャンバスの予算・段階表示・pptx 書き出し)
|
|
192
|
+
- **`vantage-design`** — `DESIGN.md` と `styles.css` をまとめて作る / 直す(配色・書体・ブランド合わせ)
|
|
381
193
|
- **`vantage-pitfalls`** — Base UI(≠ Radix)の癖など、静かに壊れる落とし穴のリファレンス
|
|
382
194
|
- **`project-storage`** — Squadbase の Project Storage(アップロード済みファイル)をブラウザから読み書きする
|
|
383
195
|
|
|
@@ -399,6 +211,9 @@ vantage add skill --all --dir .claude/skills # 置き場所を指定(既定は
|
|
|
399
211
|
配置済みのコピーを新しいバージョンに更新したいときだけ `--force` を付ける(見つかった場所を
|
|
400
212
|
そのまま書き換える)。
|
|
401
213
|
|
|
214
|
+
**役割分担:** Skill = 手順書(踏み込んだワークフロー) / `agents/*.md` = 種類ごとの静的
|
|
215
|
+
リファレンス / `AGENTS.md`(このファイル) = 地図。
|
|
216
|
+
|
|
402
217
|
---
|
|
403
218
|
|
|
404
219
|
# テンプレート固有の規約(Squadbase テンプレート)
|
|
@@ -515,4 +330,22 @@ const res = await fetch(`${baseUrl}/queries/${QUERY_ID}?since=2026-01-01`, {
|
|
|
515
330
|
`ErrorState` は見出しを `div` / `p` で描くのでそのまま使ってよい。
|
|
516
331
|
- **データ取得の失敗は各ページが `ErrorState` で出す。** `BuildRecovery` が拾うのは
|
|
517
332
|
「レンダリングが throw した」場合だけで、`useApiQuery` の `isError` はページの責任
|
|
518
|
-
(→
|
|
333
|
+
(→ `agents/page.md` の「データ取得」)。
|
|
334
|
+
|
|
335
|
+
## 依存の追加とスクリプトの実行は bun で
|
|
336
|
+
|
|
337
|
+
このプロジェクトの package manager は **bun** です(`squadbase.yml` の `package_manager: bun`、
|
|
338
|
+
lockfile は `bun.lock`)。Squadbase のサンドボックスは bun と依存のキャッシュを持っており、
|
|
339
|
+
`bun install` はキャッシュだけで終わります。上のフレームワーク規約に出てくる
|
|
340
|
+
`pnpm install` / `pnpm dev` / `pnpm check` は、そのまま `bun install` / `bun run dev` /
|
|
341
|
+
`bun run check` に読み替えてください。
|
|
342
|
+
|
|
343
|
+
### 追加の不変条件
|
|
344
|
+
|
|
345
|
+
- **依存を足すときは `bun add <pkg>`(開発用は `bun add -d <pkg>`)。** `npm install` や
|
|
346
|
+
`pnpm add` を使わない — `package-lock.json` / `pnpm-lock.yaml` が生えて `bun.lock` と別の断面に
|
|
347
|
+
なり、次回起動時の install が lockfile を作り直す。
|
|
348
|
+
- **`bun.lock` を消さない・手で編集しない。** `package.json` の依存を直接書き換えたときは
|
|
349
|
+
`bun install` を一度走らせて `bun.lock` を追従させ、両方を同じコミットに入れる。
|
|
350
|
+
- スクリプトは `bun run <script>`(`bun run dev` / `bun run build` / `bun run check` /
|
|
351
|
+
`bun run routes`)。`npm run <script>` でも動くが、install に npm を使わないこと。
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
DESIGN.md — このアプリの「見た目の意図」を書くファイルです。
|
|
3
|
+
|
|
4
|
+
- 実際の色・角丸・書体の値は src/styles.css にあります。ここにはトークン名(--primary など)と
|
|
5
|
+
使い分けのルールだけを書き、色コードは書きません。
|
|
6
|
+
- エージェントはページ・スライド・コンポーネントを書く前にこのファイルを読みます。
|
|
7
|
+
会話の中での指示はこのファイルより優先されます。
|
|
8
|
+
- 「このサイトに合わせて」「色を落ち着いた感じに」と頼めば、このファイルと styles.css を
|
|
9
|
+
まとめて更新します。
|
|
10
|
+
- このファイルはあなたのものです。`vantage upgrade` が書き換えることはありません。
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
# デザイン
|
|
14
|
+
|
|
15
|
+
## 全体のトーン (Overview)
|
|
16
|
+
|
|
17
|
+
- 落ち着いた無彩色のベースに、データだけが色を持つ業務ダッシュボード。
|
|
18
|
+
- 装飾より読みやすさを優先する。影・グラデーション・アニメーションは最小限。
|
|
19
|
+
- 数字が主役。1 画面で伝えたいことを 1 つに絞り、補足は小さく添える。
|
|
20
|
+
- ブランド素材: なし(ロゴを使う場合は `public/brand/logo.svg` のように `public/` 配下のパスで書く)
|
|
21
|
+
|
|
22
|
+
## 色 (Colors)
|
|
23
|
+
|
|
24
|
+
色は必ずトークン(Tailwind のセマンティッククラス)で指定する。素のパレット(`bg-blue-600` など)や
|
|
25
|
+
色コードを直接書かない。
|
|
26
|
+
|
|
27
|
+
| 役割 | トークン | 使う場所 |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| 主色 (Primary) | `--primary` / `--primary-foreground` | 主要ボタン、選択中の状態。既定は無彩色 |
|
|
30
|
+
| 強調 (Accent) | `--chart-1` | 1 つだけ目立たせたい数値・系列・リンク的な強調 |
|
|
31
|
+
| 良い (Positive) | `--chart-2` | 前期比のプラスなど、良い変化の小さな印 |
|
|
32
|
+
| 悪い (Negative) | `--destructive` | 前期比のマイナス、エラー、削除操作 |
|
|
33
|
+
| 注意 (Warning) | 専用トークンなし | 文言とアイコンで示し、色は `--muted-foreground` |
|
|
34
|
+
| 背景の段階 | `--background` → `--card` → `--muted` | ページ → カード → カード内の区画・ホバー |
|
|
35
|
+
| 境界 | `--border` / `--input` / `--ring` | 罫線、入力欄、フォーカス |
|
|
36
|
+
| 文字 | `--foreground` / `--muted-foreground` | 本文 / 補足・ラベル・単位 |
|
|
37
|
+
|
|
38
|
+
- `--muted`・`--accent`・`--secondary`・`--border` は背景・境界用。文字色に使わない。
|
|
39
|
+
- 増減(▲▼・前期比)は向きで色を分ける: 増加・プラスは `--chart-2`(または `--primary`)、
|
|
40
|
+
減少・マイナスは `--destructive`。下向きの矢印やマイナスを `--primary` で塗らない。
|
|
41
|
+
- ライトとダークの両方がトークンで決まるので `dark:` を並べない。
|
|
42
|
+
|
|
43
|
+
## チャート (Charts)
|
|
44
|
+
|
|
45
|
+
- 系列の順番は `--chart-1` → `--chart-2` → `--chart-3` → `--chart-4` → `--chart-5`
|
|
46
|
+
(現在はプリセット `blue`: 青 → ティール → フクシア → バイオレット → グレー)。
|
|
47
|
+
- 1 系列だけを目立たせるときは、その系列を `--chart-1`、残りをすべて `--chart-5`(グレー)にする。
|
|
48
|
+
- 良い / 悪いを色で塗り分けるときは `--chart-2` / `--destructive`。色だけに頼らず ▲▼ や符号も添える。
|
|
49
|
+
- 系列は 5 つまで。それ以上はグループ化するか「その他」にまとめる。
|
|
50
|
+
- 禁止: 同じチャートで `--destructive` を普通の系列色として使う(悪い値に見える)。
|
|
51
|
+
- 禁止: 隣り合う系列に `--chart-3` と `--chart-4` を並べて細い線で描く(見分けにくい)。
|
|
52
|
+
- 配色を丸ごと変えるときは `npx @squadbase/vantage-template chart <preset>` を使う
|
|
53
|
+
(`blue` / `ocean` / `sunset` / `forest` / `berry` / `mono`)。
|
|
54
|
+
|
|
55
|
+
## 書体 (Typography)
|
|
56
|
+
|
|
57
|
+
| 用途 | 指定 | 備考 |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| 見出し・本文 | システムフォント(`body` の `font-family`) | Web フォントは使わない |
|
|
60
|
+
| 数字 | 同上 + `tabular-nums` | 桁がそろうように必ず付ける |
|
|
61
|
+
| スライドの見出し | `--slide-font-display` | 既定は日本語を含むシステムフォント |
|
|
62
|
+
| スライドの本文 | `--slide-font-body` | 既定は見出しと同じ |
|
|
63
|
+
|
|
64
|
+
サイズの段階(ダッシュボード):
|
|
65
|
+
|
|
66
|
+
- ページ見出し: `text-2xl font-bold`
|
|
67
|
+
- カード見出し・ラベル: `text-sm font-medium text-muted-foreground`
|
|
68
|
+
- KPI の数値: `text-3xl font-semibold tabular-nums`
|
|
69
|
+
- 本文・表: `text-sm`
|
|
70
|
+
- 注釈・出典: `text-xs text-muted-foreground`
|
|
71
|
+
|
|
72
|
+
スライドのサイズは `--slide-size-hero`(表紙・大きな数字)と `--slide-size-body`(本文)を基準にする。
|
|
73
|
+
|
|
74
|
+
## レイアウトと密度 (Layout)
|
|
75
|
+
|
|
76
|
+
- 情報はカード(`bg-card` + `border-border`)で区切る。角丸は `--radius` に従う(個別に変えない)。
|
|
77
|
+
- グリッドの間隔は `gap-4`。セクション間は `gap-6` 程度。
|
|
78
|
+
- KPI は 1 行に 2〜4 枚。その下にチャート、最後に明細の表。
|
|
79
|
+
- 密度は「中」。余白を削って詰め込むより、ページを分ける。
|
|
80
|
+
|
|
81
|
+
## 成果物の種類ごとの規則 (Per-artifact)
|
|
82
|
+
|
|
83
|
+
### ダッシュボード
|
|
84
|
+
|
|
85
|
+
- 先頭に KPI カード、次にトレンドのチャート、最後に明細の表。
|
|
86
|
+
- 各 KPI には比較対象(前月比・目標比など)を 1 つ添える。
|
|
87
|
+
- チャートのタイトルは結論を書く(「売上推移」より「売上は 3 か月連続で増加」)。
|
|
88
|
+
|
|
89
|
+
### スライド
|
|
90
|
+
|
|
91
|
+
- 1 枚に 1 メッセージ。見出しに結論を書く。
|
|
92
|
+
- 色は `--slide-bg` / `--slide-fg` / `--slide-accent` / `--slide-muted` を使う
|
|
93
|
+
(既定では `--background` / `--foreground` / `--primary` / `--muted-foreground` に連動)。
|
|
94
|
+
- 強調色は 1 枚につき 1 か所まで。
|
|
95
|
+
|
|
96
|
+
## Do / Don't
|
|
97
|
+
|
|
98
|
+
Do:
|
|
99
|
+
|
|
100
|
+
- トークンと Tailwind のセマンティッククラスで色を指定する。
|
|
101
|
+
- 数値には単位と比較対象を付ける。
|
|
102
|
+
- 色の意味(良い / 悪い / 強調)をアプリ全体でそろえる。
|
|
103
|
+
|
|
104
|
+
Don't:
|
|
105
|
+
|
|
106
|
+
- 色コードや素のパレットクラスを直接書く。
|
|
107
|
+
- 1 画面で強調色を何か所にも使う。
|
|
108
|
+
- 3D チャート・円グラフの多用・装飾目的のグラデーション。
|