openprototype 1.1.0 → 1.2.0
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 +77 -31
- package/README.zh-CN.md +78 -30
- package/bin/cli.js +72 -4
- package/package.json +1 -1
- package/product/demo/pc/index.html +6 -0
- package/runtime/shell/onboarding.css +184 -0
- package/runtime/shell/onboarding.js +422 -0
- package/templates/product-shell/index.html +6 -0
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Let product managers run "requirements → PRD → HTML prototype" as a single c
|
|
|
11
11
|
*A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
|
|
12
12
|
|
|
13
13
|

|
|
14
|
-

|
|
15
15
|

|
|
16
16
|

|
|
17
17
|
|
|
@@ -37,7 +37,7 @@ The recurring pain points when a PM builds prototypes:
|
|
|
37
37
|
|
|
38
38
|
1. **PRD (`.md`) and prototype (`.html`) sit side by side in the same directory** — browse in one place, keep them aligned in one place.
|
|
39
39
|
2. **The AI Agent on the right automatically carries "current page + current PRD" context.** Say "change field X to XX" and it edits only the relevant part instead of rewriting the whole page; it can also pick up the **red-marked** incremental changes in the PRD and land them precisely.
|
|
40
|
-
3. **A built-in red-line checker**
|
|
40
|
+
3. **A built-in red-line checker** covers script order, the data layer, status constants, the font stack, and `mode=view` physical hiding. The companion `auto-test` skill tells the Agent to run it after prototype edits.
|
|
41
41
|
|
|
42
42
|
> In one sentence: **a local workbench with guardrails, built for "PM + AI prototyping."**
|
|
43
43
|
|
|
@@ -47,11 +47,12 @@ The recurring pain points when a PM builds prototypes:
|
|
|
47
47
|
|
|
48
48
|
- 🌲 **Navigation tree** — scans the product directory to auto-generate a page tree, with fuzzy title search, version badges (read from the PRD version table), and review markers.
|
|
49
49
|
- 👁 **Live preview** — the middle iframe renders the prototype page directly; click on the left and see it instantly.
|
|
50
|
+
- 🧭 **First-run tour** — the first time you open the workbench, a 5-step bubble walkthrough covers create a page → find it → preview it → change it with the Agent → update it from the PRD. It shows once, and the "?" next to the sidebar title replays it anytime.
|
|
50
51
|
- 🤖 **Context-aware AI Agent** — connects to your local [OpenCode](https://opencode.ai); every message automatically carries the current page + PRD path, with one-click "update the page per the PRD's red-marked content."
|
|
51
52
|
- 🧱 **Zero-backend data layer** — `BaseDataManager` does CRUD via localStorage, so prototypes ship with interactive fake data and no database to spin up.
|
|
52
|
-
- ✅ **Automated red-line checks** — static rules
|
|
53
|
-
- 📦 **Scaffold distribution** — `create` starts a project from scratch, `init` grafts it into an existing project, `add-product` adds a product, and `npm update` upgrades the framework.
|
|
54
|
-
- 🖥 **Cross-platform** — macOS / Windows / Linux; the OpenCode path is auto-detected.
|
|
53
|
+
- ✅ **Automated red-line checks** — static rules work out of the box; install Playwright and Chromium to add real-browser smoke tests.
|
|
54
|
+
- 📦 **Scaffold distribution** — `create` starts a project from scratch, `init` grafts it into an existing project, `add-product` adds a product, and `npm update openprototype` upgrades the framework runtime.
|
|
55
|
+
- 🖥 **Cross-platform** — manual serving works on macOS / Windows / Linux; the background service currently supports macOS / Windows only, and the OpenCode path is auto-detected.
|
|
55
56
|
|
|
56
57
|
---
|
|
57
58
|
|
|
@@ -77,7 +78,7 @@ The recurring pain points when a PM builds prototypes:
|
|
|
77
78
|
|
|
78
79
|
## 🚀 Quick start
|
|
79
80
|
|
|
80
|
-
> Prerequisite: Node ≥ 16. The AI panel additionally needs local [OpenCode](https://opencode.ai) (see
|
|
81
|
+
> Prerequisite: the core runtime needs Node ≥ 16. Use Node ≥ 18 for Playwright smoke tests or repository development. The AI panel additionally needs local [OpenCode](https://opencode.ai) (see below; it can be installed later).
|
|
81
82
|
|
|
82
83
|
### Scenario ①: Start a project from scratch
|
|
83
84
|
|
|
@@ -85,22 +86,44 @@ The recurring pain points when a PM builds prototypes:
|
|
|
85
86
|
npx openprototype create myapp
|
|
86
87
|
cd myapp
|
|
87
88
|
npm install
|
|
88
|
-
npm run serve
|
|
89
89
|
# Open http://127.0.0.1:8082/product/demo/pc/index.html
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
On macOS / Windows, `npm install` registers and starts the project's background service by default. Open the URL above when installation finishes; do not run `npm run serve` as well, or the two processes will compete for the same port. On Linux, when the background service is disabled, or if automatic installation fails, run:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run serve
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The first run ships with an interactive demo product (customer list + form + PRD); follow it to add your own pages.
|
|
93
99
|
|
|
94
|
-
### Scenario ②: Graft into an existing project
|
|
100
|
+
### Scenario ②: Graft into an existing project
|
|
95
101
|
|
|
96
102
|
```bash
|
|
97
103
|
cd your-project
|
|
98
104
|
npm i openprototype
|
|
99
|
-
npx openprototype init
|
|
105
|
+
npx openprototype init
|
|
100
106
|
npx openprototype add-product shop
|
|
101
|
-
|
|
107
|
+
# Open http://127.0.0.1:8082/product/shop/pc/index.html
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`init` does not overwrite existing template files. It adds missing assets and merges `package.json` scripts, but it also rewrites `package.json` and, by default, registers and starts an OS background service on macOS / Windows. On Linux or with the service disabled, run `npm run serve` manually. If the background service is already running, run `npx openprototype service restart` after `add-product` so the Agent loads the new product's write scope.
|
|
111
|
+
|
|
112
|
+
### Background service
|
|
113
|
+
|
|
114
|
+
The background service keeps the workbench available after login and is registered separately for each project. It currently supports macOS LaunchAgent and Windows Task Scheduler; use `npm run serve` on Linux.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npx openprototype service status
|
|
118
|
+
npx openprototype service restart
|
|
119
|
+
npx openprototype service logs
|
|
120
|
+
npx openprototype service uninstall
|
|
102
121
|
```
|
|
103
122
|
|
|
123
|
+
- To prevent automatic registration, set `OPENPROTOTYPE_SERVICE_AUTO_INSTALL=0` before the first `npm install` / `init`, or set `"service": { "autoInstall": false }` in the config beforehand.
|
|
124
|
+
- `service stop` stops the current process only; it will start again at the next login. Use `service uninstall` to remove it permanently.
|
|
125
|
+
- After adding a product or changing the port or Node path, run `service restart` to load the new configuration. Run it after a package upgrade too if the install hook did not restart the service successfully.
|
|
126
|
+
|
|
104
127
|
---
|
|
105
128
|
|
|
106
129
|
## 🤖 How the AI Agent works
|
|
@@ -115,7 +138,8 @@ You type in the panel ──▶ local server (/api/agent) ──▶ OpenCode
|
|
|
115
138
|
|
|
116
139
|
- **Context carried automatically**: click any page on the left and the top of the panel shows "This message will carry: page X / PRD Y" — no need to paste paths manually.
|
|
117
140
|
- **Incremental update per PRD red-marks**: one click sends the PRD content marked `<span style="color:red">…</span>` as the **only edit scope** to the Agent — it edits only the red-marked parts, treats un-marked history as background, and won't rewrite or "optimize on the side."
|
|
118
|
-
- **Local
|
|
141
|
+
- **Local by default**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only.
|
|
142
|
+
- **LAN exposure boundary**: with `--host 0.0.0.0`, LAN clients still cannot call write or Agent endpoints, but they can read non-hidden files that the static server can reach under the project root—not only prototype pages. Use this only on a trusted network and in a dedicated prototype project with no secrets or other sensitive files.
|
|
119
143
|
|
|
120
144
|
### Install OpenCode (prerequisite for the AI panel)
|
|
121
145
|
|
|
@@ -138,7 +162,7 @@ your-project/
|
|
|
138
162
|
├─ proto-kit.config.json # Ports / OpenCode / product list (the single config entry)
|
|
139
163
|
├─ AGENTS.md # Collaboration conventions for the AI (a generic template you own and can edit)
|
|
140
164
|
├─ CONVENTIONS.md # Explanation of the page red lines the checker enforces (coupled to the runtime)
|
|
141
|
-
├─ skills/ # xiaojia (restrained editing) + auto-test (
|
|
165
|
+
├─ skills/ # xiaojia (restrained editing) + auto-test (requires checks after editing)
|
|
142
166
|
├─ rules/ # Empty directory: put your team's own PRD templates / UI guidelines here
|
|
143
167
|
└─ product/<id>/pc/
|
|
144
168
|
├─ index.html # Navigation shell (thin, references the /_kit runtime)
|
|
@@ -150,10 +174,14 @@ The three-layer separation determines **who is responsible for updates**, which
|
|
|
150
174
|
|
|
151
175
|
| Layer | Content | Ownership | Update method |
|
|
152
176
|
|-------|---------|-----------|---------------|
|
|
153
|
-
| **Runtime** | Server / shared engine / Agent panel / check scripts | Framework (mounted at `/_kit/`) | `npm update
|
|
154
|
-
| **Editable assets** | `AGENTS.md` `CONVENTIONS.md` `skills/` + your own `rules/` | You own them | `openprototype update`
|
|
177
|
+
| **Runtime** | Server / shared engine / Agent panel / first-run tour / check scripts | Framework (mounted at `/_kit/`) | `npm update openprototype` |
|
|
178
|
+
| **Editable assets** | `AGENTS.md` `CONVENTIONS.md` `skills/` + your own `rules/` | You own them | `npx openprototype update` prints manual comparison and merge guidance |
|
|
155
179
|
| **Business content** | Your product PRDs / prototypes / data | You own them | You maintain them yourself |
|
|
156
180
|
|
|
181
|
+
> **The product shell (`product/<id>/pc/index.html`) is copied at scaffold time and does not upgrade with the package.** When the framework adds a new shell entry point (such as the first-run tour), run `npx openprototype init` once after upgrading to patch it in — the patch is idempotent, skips shells that already have it, and leaves your own edits alone.
|
|
182
|
+
>
|
|
183
|
+
> First-run tour switches: add `?tour=off` to the URL to suppress it for that load; in the browser console, `window.ProtoTour.reset()` clears the "already seen" flag and `window.ProtoTour.start()` replays it on demand.
|
|
184
|
+
|
|
157
185
|
> The framework ships only the **minimal generic conventions** (page red lines + editing restraint). Methodology like PRD templates, UI guidelines, and business terminology **belongs to you** — put it in `rules/` and `product/<id>/`; it's not distributed with the framework and won't be overwritten on upgrade.
|
|
158
186
|
|
|
159
187
|
**Engine fallback resolution**: when a page references `../shared/xxx.js` by relative path and that file doesn't exist under `product/<id>/shared/`, the server automatically falls back to the framework's built-in engine (equivalent to `/_kit/shared/`). Therefore:
|
|
@@ -166,18 +194,25 @@ The three-layer separation determines **who is responsible for updates**, which
|
|
|
166
194
|
|
|
167
195
|
## 🧪 Quality assurance: the red-line checker
|
|
168
196
|
|
|
169
|
-
`openprototype check`
|
|
197
|
+
`npx openprototype check` always runs the static red-line checks. After Playwright and Chromium are installed, it also runs real-browser smoke tests (see [CONVENTIONS.md](templates/CONVENTIONS.md) for details):
|
|
170
198
|
|
|
171
199
|
- Fixed script load order · data must go through `BaseDataManager` (no page-level localStorage)
|
|
172
200
|
- Status labels as constants (no hardcoded `<option>`) · no Google Fonts (system font stack)
|
|
173
201
|
- `?mode=view` physical hiding (`display:none`, not `disabled`) · no console errors when opening a page
|
|
174
202
|
|
|
175
203
|
```bash
|
|
176
|
-
|
|
177
|
-
|
|
204
|
+
npm run check # Scan all pages
|
|
205
|
+
npm run check:changed # Scan only git changes
|
|
178
206
|
```
|
|
179
207
|
|
|
180
|
-
|
|
208
|
+
Enable the browser layer once:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npm i -D playwright
|
|
212
|
+
npx playwright install chromium
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
When Playwright or Chromium is missing, do not rely on browser-layer results; install both before treating `check` as the full check suite. The companion `auto-test` skill tells the Agent to run checks after every prototype edit and fix all ERRORs before delivery; this is an Agent workflow rule, not a server-side file watcher.
|
|
181
216
|
|
|
182
217
|
---
|
|
183
218
|
|
|
@@ -186,13 +221,17 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
|
|
|
186
221
|
```json
|
|
187
222
|
{
|
|
188
223
|
"port": 8082,
|
|
189
|
-
"host": "127.0.0.1",
|
|
224
|
+
"host": "127.0.0.1",
|
|
225
|
+
"service": {
|
|
226
|
+
"autoInstall": true
|
|
227
|
+
},
|
|
190
228
|
"opencode": {
|
|
191
|
-
"bin": "auto",
|
|
229
|
+
"bin": "auto",
|
|
192
230
|
"model": "deepseek/deepseek-v4-flash",
|
|
193
231
|
"agent": "build",
|
|
194
232
|
"host": "127.0.0.1",
|
|
195
|
-
"port": 4097
|
|
233
|
+
"port": 4097,
|
|
234
|
+
"startTimeoutMs": 15000
|
|
196
235
|
},
|
|
197
236
|
"products": [
|
|
198
237
|
{ "id": "demo", "roots": ["pc"] }
|
|
@@ -200,23 +239,29 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
|
|
|
200
239
|
}
|
|
201
240
|
```
|
|
202
241
|
|
|
242
|
+
`host` defaults to `127.0.0.1`. Setting it to `0.0.0.0` exposes static file reads to the LAN, so review the security boundary above first. A long-running background service also requires an explicit `npx openprototype service install --allow-lan`.
|
|
243
|
+
|
|
203
244
|
Environment variables can override temporarily: `PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`.
|
|
204
|
-
You can also use `
|
|
245
|
+
You can also use `npx openprototype serve --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
|
|
205
246
|
|
|
206
247
|
---
|
|
207
248
|
|
|
208
249
|
## 📟 Commands
|
|
209
250
|
|
|
251
|
+
The table uses `npx` for the default local-project installation. You can omit `npx` after a global installation. `create` adds npm script aliases, and `init` does the same when the project already has a `package.json`, so day-to-day commands can use `npm run serve`, `npm run check`, `npm run check:changed`, and `npm run nav:sync`.
|
|
252
|
+
|
|
210
253
|
| Command | Purpose |
|
|
211
254
|
|---------|---------|
|
|
212
|
-
| `openprototype create <dir>` | Create a new project from scratch
|
|
213
|
-
| `openprototype init` |
|
|
214
|
-
| `openprototype add-product <id
|
|
215
|
-
| `openprototype serve` | Start the
|
|
216
|
-
| `openprototype
|
|
217
|
-
| `openprototype
|
|
218
|
-
| `openprototype
|
|
219
|
-
| `openprototype
|
|
255
|
+
| `npx openprototype create <dir>` | Create a new project from scratch with a runnable demo |
|
|
256
|
+
| `npx openprototype init` | Add missing assets, merge scripts, and install the background service when configured |
|
|
257
|
+
| `npx openprototype add-product <id> [--title <name>]` | Add a PC product shell with an optional display name |
|
|
258
|
+
| `npx openprototype serve [--port <port>] [--host <address>]` | Start the foreground server with optional temporary listen overrides |
|
|
259
|
+
| `npx openprototype service <action>` | Manage the background service: `install/start/stop/restart/status/logs/uninstall/prune` |
|
|
260
|
+
| `npx openprototype check [--changed] [--static-only] [path]` | Check all pages, Git changes, or a path; optionally run static rules only |
|
|
261
|
+
| `npx openprototype nav:sync` | Scan product directories and rebuild `nav-tree.json` |
|
|
262
|
+
| `npx openprototype doctor` | Check Node / OpenCode / config / Playwright / background service health |
|
|
263
|
+
| `npm update openprototype` | Upgrade the runtime package within the version range in `package.json` |
|
|
264
|
+
| `npx openprototype update` | Print manual editable-asset comparison and merge guidance; does not upgrade |
|
|
220
265
|
|
|
221
266
|
---
|
|
222
267
|
|
|
@@ -236,6 +281,7 @@ Feature requests and feedback are welcome in Issues.
|
|
|
236
281
|
PRs welcome. Development conventions:
|
|
237
282
|
|
|
238
283
|
- Use only Node built-in modules; the runtime has zero dependencies (the checker's Playwright is a devDependency).
|
|
284
|
+
- The core runtime supports Node ≥ 16; installing the current Playwright dependency and running the full checks requires Node ≥ 18.
|
|
239
285
|
- Run `npm run check` after changing the runtime; after changing the shell / Agent panel, start the server locally and test the three columns for real.
|
|
240
286
|
- Keep the repository **free of any private information** (company / personal / intranet addresses / secrets).
|
|
241
287
|
|
package/README.zh-CN.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
|
|
12
12
|
|
|
13
13
|

|
|
14
|
-

|
|
15
15
|

|
|
16
16
|

|
|
17
17
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
1. **PRD(`.md`)和原型(`.html`)同目录并排放**,一处浏览、一处对齐。
|
|
39
39
|
2. **右侧 AI Agent 自动携带「当前页面 + 当前 PRD」上下文**,你说"把某字段改成 XX",它只改相关部分、不整页重写;还能识别 PRD 里**标红**的增量改动精准落地。
|
|
40
|
-
3.
|
|
40
|
+
3. **内置红线检查器**覆盖脚本顺序、数据层、状态常量化、字体栈与 `mode=view` 物理隐藏;配套 `auto-test` skill 会要求 Agent 在改完原型后执行检查。
|
|
41
41
|
|
|
42
42
|
> 一句话:**给"PM + AI 做原型"这件事,配一套有护栏的本地工作台。**
|
|
43
43
|
|
|
@@ -47,11 +47,12 @@
|
|
|
47
47
|
|
|
48
48
|
- 🌲 **树形导航** —— 扫描产品目录自动生成页面树,支持标题模糊搜索、版本号徽标(从 PRD 版本表读取)、审核标记。
|
|
49
49
|
- 👁 **即时预览** —— 中间 iframe 直接渲染原型页面,点左侧即看。
|
|
50
|
+
- 🧭 **新手引导** —— 首次打开工作台自动弹出 5 步气泡,把「新建页面 → 找页面 → 预览 → Agent 改页面 → 按 PRD 更新」走一遍;看过一次就不再出现,侧栏标题旁的「?」可随时重看。
|
|
50
51
|
- 🤖 **上下文感知的 AI Agent** —— 接本机 [OpenCode](https://opencode.ai),每条消息自动带当前页面 + PRD 路径;一键"按 PRD 标红内容更新页面"。
|
|
51
52
|
- 🧱 **零后端的数据层** —— `BaseDataManager` 用 localStorage 做 CRUD,原型自带可交互假数据,不用起数据库。
|
|
52
|
-
- ✅ **自动化红线检查** ——
|
|
53
|
-
- 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update`
|
|
54
|
-
- 🖥 **跨平台** —— macOS / Windows / Linux
|
|
53
|
+
- ✅ **自动化红线检查** —— 静态规则开箱可用;安装 Playwright 与 Chromium 后可增加真实浏览器冒烟测试。
|
|
54
|
+
- 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update openprototype` 升级框架运行时。
|
|
55
|
+
- 🖥 **跨平台** —— macOS / Windows / Linux 均可手动启动;常驻服务目前仅支持 macOS / Windows,OpenCode 路径自动探测。
|
|
55
56
|
|
|
56
57
|
---
|
|
57
58
|
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
|
|
78
79
|
## 🚀 快速开始
|
|
79
80
|
|
|
80
|
-
>
|
|
81
|
+
> 前置:核心运行时需要 Node ≥ 16;若要运行 Playwright 冒烟测试或参与仓库开发,请使用 Node ≥ 18。AI 面板另需本机 [OpenCode](https://opencode.ai)(见后文,可后装)。
|
|
81
82
|
|
|
82
83
|
### 场景 ①:从零建项目
|
|
83
84
|
|
|
@@ -85,22 +86,44 @@
|
|
|
85
86
|
npx openprototype create myapp
|
|
86
87
|
cd myapp
|
|
87
88
|
npm install
|
|
88
|
-
npm run serve
|
|
89
89
|
# 打开 http://127.0.0.1:8082/product/demo/pc/index.html
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
macOS / Windows 上,`npm install` 默认会注册并启动项目常驻服务,安装完成后直接打开上面的地址;不要再执行 `npm run serve`,否则会与常驻服务争用端口。Linux、禁用常驻服务或自动安装失败时,再执行:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm run serve
|
|
96
|
+
```
|
|
97
|
+
|
|
92
98
|
首跑就带一个可交互的 demo 产品(客户列表 + 表单 + PRD),照着它加自己的页面即可。
|
|
93
99
|
|
|
94
|
-
### 场景
|
|
100
|
+
### 场景 ②:植入已有项目
|
|
95
101
|
|
|
96
102
|
```bash
|
|
97
103
|
cd 你的项目
|
|
98
104
|
npm i openprototype
|
|
99
|
-
npx openprototype init
|
|
105
|
+
npx openprototype init
|
|
100
106
|
npx openprototype add-product shop
|
|
101
|
-
|
|
107
|
+
# 打开 http://127.0.0.1:8082/product/shop/pc/index.html
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`init` 不覆盖已有模板文件,会补充缺失资产并合并 `package.json` 脚本;但它也会修改 `package.json`,且默认在 macOS / Windows 上注册并启动系统常驻服务。Linux 或未启用常驻服务时,运行 `npm run serve` 手动启动。如果常驻服务已经运行,`add-product` 修改配置后执行一次 `npx openprototype service restart`,让 Agent 加载新产品的写入范围。
|
|
111
|
+
|
|
112
|
+
### 常驻服务
|
|
113
|
+
|
|
114
|
+
常驻服务让工作台在登录后自动运行,每个项目独立注册。它目前仅支持 macOS LaunchAgent 与 Windows 计划任务;Linux 请使用 `npm run serve`。
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npx openprototype service status
|
|
118
|
+
npx openprototype service restart
|
|
119
|
+
npx openprototype service logs
|
|
120
|
+
npx openprototype service uninstall
|
|
102
121
|
```
|
|
103
122
|
|
|
123
|
+
- 不想自动注册:在首次 `npm install` / `init` 前设置 `OPENPROTOTYPE_SERVICE_AUTO_INSTALL=0`,或提前在配置中设置 `"service": { "autoInstall": false }`。
|
|
124
|
+
- `service stop` 只停止本次运行,下次登录仍会启动;永久取消请用 `service uninstall`。
|
|
125
|
+
- 新增产品、修改端口或 Node 路径后,运行 `service restart` 让常驻服务加载新配置;升级包的安装钩子未自动重启成功时也应执行它。
|
|
126
|
+
|
|
104
127
|
---
|
|
105
128
|
|
|
106
129
|
## 🤖 AI Agent 怎么工作
|
|
@@ -115,7 +138,8 @@ npm run serve
|
|
|
115
138
|
|
|
116
139
|
- **自动带上下文**:点左侧任一页面,面板顶部就显示「本条消息将携带:页面 X / PRD Y」,无需你手动贴路径。
|
|
117
140
|
- **按 PRD 标红增量更新**:一键把 PRD 里 `<span style="color:red">…</span>` 标红的内容作为**唯一改动范围**发给 Agent —— 只改标红处,未标红的历史内容当背景,不重写、不"顺手优化"。
|
|
118
|
-
-
|
|
141
|
+
- **默认仅本机访问**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求。
|
|
142
|
+
- **局域网开放边界**:使用 `--host 0.0.0.0` 后,局域网设备虽然不能调用写入与 Agent 接口,但能读取项目根目录下服务器可访问的非隐藏文件,不仅是原型页面。只应在可信网络和专用原型项目中使用,并确保项目中没有密钥或其他敏感文件。
|
|
119
143
|
|
|
120
144
|
### 安装 OpenCode(AI 面板前置)
|
|
121
145
|
|
|
@@ -138,7 +162,7 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
|
|
|
138
162
|
├─ proto-kit.config.json # 端口 / OpenCode / 产品列表(唯一配置入口)
|
|
139
163
|
├─ AGENTS.md # 给 AI 的协作规范(通用模板,你拥有可改)
|
|
140
164
|
├─ CONVENTIONS.md # 检查器强制的页面红线说明(和运行时耦合)
|
|
141
|
-
├─ skills/ # xiaojia(编码克制)+ auto-test
|
|
165
|
+
├─ skills/ # xiaojia(编码克制)+ auto-test(要求改完运行检查)
|
|
142
166
|
├─ rules/ # 空目录:放你团队自己的 PRD 模板 / UI 规范
|
|
143
167
|
└─ product/<id>/pc/
|
|
144
168
|
├─ index.html # 导航壳(薄,引用 /_kit 运行时)
|
|
@@ -150,10 +174,16 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
|
|
|
150
174
|
|
|
151
175
|
| 层 | 内容 | 归属 | 更新方式 |
|
|
152
176
|
|----|------|------|----------|
|
|
153
|
-
| **运行时** | 服务器 / shared 引擎 / Agent 面板 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update`
|
|
154
|
-
| **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `openprototype update`
|
|
177
|
+
| **运行时** | 服务器 / shared 引擎 / Agent 面板 / 新手引导 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update openprototype` |
|
|
178
|
+
| **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `npx openprototype update` 输出手工对比与合并指引 |
|
|
155
179
|
| **业务内容** | 你的产品 PRD / 原型 / 数据 | 你拥有 | 你自己维护 |
|
|
156
180
|
|
|
181
|
+
> **产品壳(`product/<id>/pc/index.html`)是脚手架时复制的,不随包升级。** 框架给壳加了新入口(比如新手引导)时,
|
|
182
|
+
> 升级后跑一次 `npx openprototype init` 即可补上——幂等,已有的会跳过,你自己改过的部分不动。
|
|
183
|
+
>
|
|
184
|
+
> 新手引导的开关:URL 加 `?tour=off` 本次不弹;浏览器控制台执行 `window.ProtoTour.reset()` 可重置"已看过"标记,
|
|
185
|
+
> `window.ProtoTour.start()` 直接手动开一次。
|
|
186
|
+
|
|
157
187
|
> 框架只带**最小通用规范**(页面红线 + 编码克制)。PRD 模板、UI 规范、业务术语这类**方法论属于你**,放进 `rules/` 与 `product/<id>/`,不随框架分发、也不被升级覆盖。
|
|
158
188
|
|
|
159
189
|
**引擎回退解析**:页面用相对路径引用 `../shared/xxx.js` 时,若 `product/<id>/shared/` 下没有该文件,服务器自动回退到框架内置引擎(等价 `/_kit/shared/`)。因此:
|
|
@@ -166,18 +196,25 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
|
|
|
166
196
|
|
|
167
197
|
## 🧪 质量保障:红线检查器
|
|
168
198
|
|
|
169
|
-
`openprototype check`
|
|
199
|
+
`npx openprototype check` 会执行静态红线检查;安装 Playwright 与 Chromium 后,还会执行真实浏览器冒烟测试(详见 [CONVENTIONS.md](templates/CONVENTIONS.md)):
|
|
170
200
|
|
|
171
201
|
- 脚本加载顺序固定 · 数据必须走 `BaseDataManager`(禁页面级 localStorage)
|
|
172
202
|
- 状态文案常量化(禁硬编码 `<option>`)· 禁 Google Fonts(系统字体栈)
|
|
173
203
|
- `?mode=view` 物理隐藏(`display:none`,非 `disabled`)· 打开页面无 console 报错
|
|
174
204
|
|
|
175
205
|
```bash
|
|
176
|
-
|
|
177
|
-
|
|
206
|
+
npm run check # 扫全部页面
|
|
207
|
+
npm run check:changed # 只扫 git 改动
|
|
178
208
|
```
|
|
179
209
|
|
|
180
|
-
|
|
210
|
+
首次启用浏览器层:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
npm i -D playwright
|
|
214
|
+
npx playwright install chromium
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
未安装 Playwright 或 Chromium 时不能依赖浏览器层结果;安装完成后再把 `check` 视为完整检查。配套的 `auto-test` skill 会要求 Agent 在每次改完原型后运行检查并修完 ERROR;这是一条 Agent 工作流约定,不是服务器文件监听器。
|
|
181
218
|
|
|
182
219
|
---
|
|
183
220
|
|
|
@@ -186,13 +223,17 @@ openprototype check --changed # 只扫 git 改动
|
|
|
186
223
|
```json
|
|
187
224
|
{
|
|
188
225
|
"port": 8082,
|
|
189
|
-
"host": "127.0.0.1",
|
|
226
|
+
"host": "127.0.0.1",
|
|
227
|
+
"service": {
|
|
228
|
+
"autoInstall": true
|
|
229
|
+
},
|
|
190
230
|
"opencode": {
|
|
191
|
-
"bin": "auto",
|
|
231
|
+
"bin": "auto",
|
|
192
232
|
"model": "deepseek/deepseek-v4-flash",
|
|
193
233
|
"agent": "build",
|
|
194
234
|
"host": "127.0.0.1",
|
|
195
|
-
"port": 4097
|
|
235
|
+
"port": 4097,
|
|
236
|
+
"startTimeoutMs": 15000
|
|
196
237
|
},
|
|
197
238
|
"products": [
|
|
198
239
|
{ "id": "demo", "roots": ["pc"] }
|
|
@@ -200,23 +241,29 @@ openprototype check --changed # 只扫 git 改动
|
|
|
200
241
|
}
|
|
201
242
|
```
|
|
202
243
|
|
|
244
|
+
`host` 默认为 `127.0.0.1`。设为 `0.0.0.0` 会向局域网开放静态文件读取,请先阅读上面的安全边界;长期运行的常驻服务还需显式执行 `npx openprototype service install --allow-lan`。
|
|
245
|
+
|
|
203
246
|
环境变量可临时覆盖:`PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`。
|
|
204
|
-
也可用 `
|
|
247
|
+
也可用 `npx openprototype serve --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
|
|
205
248
|
|
|
206
249
|
---
|
|
207
250
|
|
|
208
251
|
## 📟 命令
|
|
209
252
|
|
|
253
|
+
下表按“项目本地安装 `openprototype`”的默认场景统一使用 `npx`;如果已全局安装,可以省略 `npx`。`create` 会写入常用 npm scripts,`init` 在项目已有 `package.json` 时也会补充,因此日常可使用 `npm run serve`、`npm run check`、`npm run check:changed` 和 `npm run nav:sync`。
|
|
254
|
+
|
|
210
255
|
| 命令 | 作用 |
|
|
211
256
|
|------|------|
|
|
212
|
-
| `openprototype create <dir>` | 从零创建新项目(含可运行 demo) |
|
|
213
|
-
| `openprototype init` |
|
|
214
|
-
| `openprototype add-product <id
|
|
215
|
-
| `openprototype serve` |
|
|
216
|
-
| `openprototype
|
|
217
|
-
| `openprototype
|
|
218
|
-
| `openprototype
|
|
219
|
-
| `openprototype
|
|
257
|
+
| `npx openprototype create <dir>` | 从零创建新项目(含可运行 demo) |
|
|
258
|
+
| `npx openprototype init` | 补充缺失资产、合并脚本,并按配置安装常驻服务 |
|
|
259
|
+
| `npx openprototype add-product <id> [--title <名称>]` | 新增一个 PC 产品壳,可指定显示名称 |
|
|
260
|
+
| `npx openprototype serve [--port <端口>] [--host <地址>]` | 前台启动本地服务器,可临时覆盖监听配置 |
|
|
261
|
+
| `npx openprototype service <action>` | 管理常驻服务:`install/start/stop/restart/status/logs/uninstall/prune` |
|
|
262
|
+
| `npx openprototype check [--changed] [--static-only] [路径]` | 检查全部、Git 改动或指定范围;可只跑静态规则 |
|
|
263
|
+
| `npx openprototype nav:sync` | 扫描产品目录并重建 `nav-tree.json` |
|
|
264
|
+
| `npx openprototype doctor` | 体检 Node / OpenCode / 配置 / Playwright / 常驻服务 |
|
|
265
|
+
| `npm update openprototype` | 按 `package.json` 的版本范围升级框架运行时包 |
|
|
266
|
+
| `npx openprototype update` | 仅打印可编辑资产的手工对比与合并指引,不执行升级 |
|
|
220
267
|
|
|
221
268
|
---
|
|
222
269
|
|
|
@@ -236,6 +283,7 @@ openprototype check --changed # 只扫 git 改动
|
|
|
236
283
|
欢迎 PR。开发约定:
|
|
237
284
|
|
|
238
285
|
- 只用 Node 内置模块,运行时零依赖(检查器的 Playwright 是 devDependency)。
|
|
286
|
+
- 核心运行时支持 Node ≥ 16;完整安装当前 Playwright 依赖并跑检查需 Node ≥ 18。
|
|
239
287
|
- 改运行时后跑 `npm run check`;改壳 / Agent 面板后本地起服务实测三栏。
|
|
240
288
|
- 保持仓库**无任何私有信息**(公司 / 个人 / 内网地址 / 密钥)。
|
|
241
289
|
|
package/bin/cli.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* openprototype CLI
|
|
6
6
|
*
|
|
7
7
|
* openprototype create <dir> 从零创建一个新项目(场景①)
|
|
8
|
-
* openprototype init
|
|
8
|
+
* openprototype init 把框架植入当前已有项目(保留已有模板,可能安装常驻服务)
|
|
9
9
|
* openprototype add-product <id> 新增一个产品壳(默认 pc)
|
|
10
10
|
* openprototype serve 启动本地服务器
|
|
11
11
|
* openprototype service <action> 管理本地常驻服务
|
|
@@ -97,6 +97,69 @@ function scaffoldProductShell(projectRoot, productId, productTitle) {
|
|
|
97
97
|
writeFileSafe(path.join(dir, 'nav-tree.json'), '[]\n');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
// 新手引导的两行引用标签。壳 HTML 是脚手架时复制的、不会随 npm update 升级,
|
|
101
|
+
// 所以老项目的壳里没有这两行;这里在 init 时补进去(真正的逻辑在 /_kit/shell/onboarding.*,会随包升级)。
|
|
102
|
+
const ONBOARDING_MARK = 'onboarding:start';
|
|
103
|
+
const ONBOARDING_HEAD = [
|
|
104
|
+
'<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->',
|
|
105
|
+
'<link rel="stylesheet" href="/_kit/shell/onboarding.css">',
|
|
106
|
+
'<!-- onboarding:end -->'
|
|
107
|
+
].join('\n');
|
|
108
|
+
const ONBOARDING_BODY = [
|
|
109
|
+
'<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->',
|
|
110
|
+
'<script src="/_kit/shell/onboarding.js"></script>',
|
|
111
|
+
'<!-- onboarding:end -->'
|
|
112
|
+
].join('\n');
|
|
113
|
+
|
|
114
|
+
/** 列出 product/<id>/<root>/index.html —— 已生成的产品壳 */
|
|
115
|
+
function listProductShells(projectRoot) {
|
|
116
|
+
const shells = [];
|
|
117
|
+
const productDir = path.join(projectRoot, 'product');
|
|
118
|
+
if (!fs.existsSync(productDir)) return shells;
|
|
119
|
+
for (const productId of fs.readdirSync(productDir)) {
|
|
120
|
+
const dir = path.join(productDir, productId);
|
|
121
|
+
if (!fs.statSync(dir).isDirectory()) continue;
|
|
122
|
+
for (const rootName of fs.readdirSync(dir)) {
|
|
123
|
+
const shell = path.join(dir, rootName, 'index.html');
|
|
124
|
+
if (fs.existsSync(shell)) shells.push(shell);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return shells;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 给已有的产品壳补上新手引导的引用标签。
|
|
132
|
+
* 幂等:见到 onboarding:start 就跳过;壳里没有 agent-panel 标记的一律不动(不是本框架的壳)。
|
|
133
|
+
* 引导的 <script> 必须排在 agent-panel.js 之后,那里才定义了 window.PROTO_KIT。
|
|
134
|
+
*/
|
|
135
|
+
function patchShellOnboarding(projectRoot) {
|
|
136
|
+
let patched = 0;
|
|
137
|
+
for (const shell of listProductShells(projectRoot)) {
|
|
138
|
+
const rel = path.relative(projectRoot, shell);
|
|
139
|
+
let html = fs.readFileSync(shell, 'utf8');
|
|
140
|
+
if (html.includes(ONBOARDING_MARK)) { info(C.dim(' 跳过(已有引导入口): ') + rel); continue; }
|
|
141
|
+
if (!html.includes('/_kit/shell/agent-panel.js')) { info(C.dim(' 跳过(非本框架的壳): ') + rel); continue; }
|
|
142
|
+
|
|
143
|
+
const headAnchor = '<!-- agent-panel:end -->';
|
|
144
|
+
const bodyAnchor = '<script src="/_kit/shell/agent-panel.js"></script>';
|
|
145
|
+
const headAt = html.indexOf(headAnchor);
|
|
146
|
+
const bodyAt = html.indexOf(bodyAnchor);
|
|
147
|
+
if (headAt === -1 || bodyAt === -1) { info(C.dim(' 跳过(壳结构不认识): ') + rel); continue; }
|
|
148
|
+
|
|
149
|
+
// 先补后面的、再补前面的,免得插入把后一个位置的下标顶偏
|
|
150
|
+
const bodyEnd = html.indexOf(headAnchor, bodyAt);
|
|
151
|
+
const bodyInsertAt = bodyEnd === -1 ? bodyAt + bodyAnchor.length : bodyEnd + headAnchor.length;
|
|
152
|
+
html = html.slice(0, bodyInsertAt) + '\n' + ONBOARDING_BODY + html.slice(bodyInsertAt);
|
|
153
|
+
const headInsertAt = headAt + headAnchor.length;
|
|
154
|
+
html = html.slice(0, headInsertAt) + '\n' + ONBOARDING_HEAD + html.slice(headInsertAt);
|
|
155
|
+
|
|
156
|
+
fs.writeFileSync(shell, html);
|
|
157
|
+
ok('已补上新手引导入口 ' + rel);
|
|
158
|
+
patched++;
|
|
159
|
+
}
|
|
160
|
+
return patched;
|
|
161
|
+
}
|
|
162
|
+
|
|
100
163
|
/** 新项目 package.json 里本框架的依赖版本(已发布 npm,语义化版本管理) */
|
|
101
164
|
function kitDependencySpec() {
|
|
102
165
|
const pkg = readJson(path.join(PKG_ROOT, 'package.json'), {});
|
|
@@ -168,7 +231,7 @@ function cmdCreate(argv) {
|
|
|
168
231
|
async function cmdInit() {
|
|
169
232
|
const root = process.cwd();
|
|
170
233
|
let serviceInstallDenied = false;
|
|
171
|
-
info(C.b('\n把 openprototype
|
|
234
|
+
info(C.b('\n把 openprototype 植入当前项目(保留已有模板,按配置安装常驻服务)…\n'));
|
|
172
235
|
|
|
173
236
|
copyIfAbsent(path.join(TPL, 'skills'), path.join(root, 'skills'));
|
|
174
237
|
copyIfAbsent(path.join(TPL, 'AGENTS.md'), path.join(root, 'AGENTS.md'));
|
|
@@ -178,6 +241,8 @@ async function cmdInit() {
|
|
|
178
241
|
ok('写入 ' + CONFIG_FILENAME);
|
|
179
242
|
} else info(C.dim(' 跳过(已存在): ') + CONFIG_FILENAME);
|
|
180
243
|
|
|
244
|
+
patchShellOnboarding(root);
|
|
245
|
+
|
|
181
246
|
// 合并 package.json 脚本(不覆盖用户已有脚本)
|
|
182
247
|
const pkgPath = path.join(root, 'package.json');
|
|
183
248
|
if (fs.existsSync(pkgPath)) {
|
|
@@ -396,6 +461,9 @@ function cmdUpdate() {
|
|
|
396
461
|
info(C.b('\n更新 openprototype\n'));
|
|
397
462
|
info('运行时(服务器 / shared 引擎 / Agent 面板 / 检查脚本)随包升级:');
|
|
398
463
|
info(C.g(' npm update openprototype\n'));
|
|
464
|
+
info('产品壳(product/*/*/index.html)是脚手架时复制的,不随包升级。');
|
|
465
|
+
info('升级后跑一次下面这条,可给已有的壳补上新功能入口(幂等,已有的会跳过):');
|
|
466
|
+
info(C.g(' npx openprototype init\n'));
|
|
399
467
|
info('可编辑资产(rules / prompts / workflow / AGENTS.md)由你拥有,不会被自动覆盖。');
|
|
400
468
|
info('想同步最新模板时,对比这些目录后按需合并:');
|
|
401
469
|
info(C.dim(' node_modules/openprototype/templates/ → 你项目里的 AGENTS.md / CONVENTIONS.md / skills/'));
|
|
@@ -409,11 +477,11 @@ ${C.b('openprototype')} — 本地原型工作台脚手架
|
|
|
409
477
|
|
|
410
478
|
用法:
|
|
411
479
|
${C.g('openprototype create <dir>')} 从零创建新项目
|
|
412
|
-
${C.g('openprototype init')}
|
|
480
|
+
${C.g('openprototype init')} 补充缺失资产、合并脚本,并按配置安装常驻服务
|
|
413
481
|
${C.g('openprototype add-product <id>')} 新增一个产品壳(默认 pc)
|
|
414
482
|
${C.g('openprototype serve')} 启动本地服务器
|
|
415
483
|
${C.g('openprototype service <action>')} 管理常驻服务(install/start/stop/restart/status/logs/uninstall/prune)
|
|
416
|
-
${C.g('openprototype check [--changed]')}
|
|
484
|
+
${C.g('openprototype check [--changed]')} 自动化检查(静态红线;安装 Playwright 后增加冒烟)
|
|
417
485
|
${C.g('openprototype nav:sync')} 重建各产品 nav-tree.json
|
|
418
486
|
${C.g('openprototype doctor')} 体检(Node / OpenCode / 配置 / Playwright)
|
|
419
487
|
${C.g('openprototype update')} 如何更新框架
|
package/package.json
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
<!-- agent-panel:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
8
8
|
<link rel="stylesheet" href="/_kit/shell/agent-panel.css">
|
|
9
9
|
<!-- agent-panel:end -->
|
|
10
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
11
|
+
<link rel="stylesheet" href="/_kit/shell/onboarding.css">
|
|
12
|
+
<!-- onboarding:end -->
|
|
10
13
|
<style>
|
|
11
14
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
12
15
|
|
|
@@ -1519,5 +1522,8 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1519
1522
|
<script>window.PROTO_KIT = { productId: 'demo', productTitle: 'Demo' };</script>
|
|
1520
1523
|
<script src="/_kit/shell/agent-panel.js"></script>
|
|
1521
1524
|
<!-- agent-panel:end -->
|
|
1525
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
1526
|
+
<script src="/_kit/shell/onboarding.js"></script>
|
|
1527
|
+
<!-- onboarding:end -->
|
|
1522
1528
|
</body>
|
|
1523
1529
|
</html>
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* 新手引导 — 首次打开工作台时的分步气泡提示。
|
|
2
|
+
层级说明:blocker(10040) < spotlight(10050) < bubble(10060)。
|
|
3
|
+
外壳内现有最高层级是新建弹窗遮罩 10000、toast 9999,故整体压在它们之上。 */
|
|
4
|
+
|
|
5
|
+
/* 吃掉引导期间的所有点击;spotlight 自身不接收事件,靠这一层拦截 */
|
|
6
|
+
.tour-blocker {
|
|
7
|
+
position: fixed;
|
|
8
|
+
inset: 0;
|
|
9
|
+
z-index: 10040;
|
|
10
|
+
cursor: default;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* 高亮框:用一个超大扩散的 box-shadow 直接在遮罩上"挖洞",
|
|
14
|
+
省掉切四块遮罩的麻烦,且天生跟随目标矩形 */
|
|
15
|
+
.tour-spotlight {
|
|
16
|
+
position: fixed;
|
|
17
|
+
z-index: 10050;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
border-radius: 8px;
|
|
20
|
+
outline: 2px solid #1677ff;
|
|
21
|
+
outline-offset: 0;
|
|
22
|
+
box-shadow: 0 0 0 9999px rgba(16, 22, 32, 0.45);
|
|
23
|
+
transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tour-bubble {
|
|
27
|
+
position: fixed;
|
|
28
|
+
z-index: 10060;
|
|
29
|
+
width: 320px;
|
|
30
|
+
max-width: calc(100vw - 24px);
|
|
31
|
+
padding: 14px 16px 12px;
|
|
32
|
+
border-radius: 10px;
|
|
33
|
+
background: #fff;
|
|
34
|
+
color: #20242d;
|
|
35
|
+
font-size: 13px;
|
|
36
|
+
line-height: 1.6;
|
|
37
|
+
box-shadow: 0 8px 24px rgba(16, 22, 32, 0.18);
|
|
38
|
+
transition: top 0.18s ease, left 0.18s ease;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* 箭头:8px 实心三角,四个方向各自贴边 */
|
|
42
|
+
.tour-bubble-arrow {
|
|
43
|
+
position: absolute;
|
|
44
|
+
width: 0;
|
|
45
|
+
height: 0;
|
|
46
|
+
border: 8px solid transparent;
|
|
47
|
+
}
|
|
48
|
+
.tour-bubble-arrow.is-top {
|
|
49
|
+
bottom: -16px;
|
|
50
|
+
border-top-color: #fff;
|
|
51
|
+
}
|
|
52
|
+
.tour-bubble-arrow.is-bottom {
|
|
53
|
+
top: -16px;
|
|
54
|
+
border-bottom-color: #fff;
|
|
55
|
+
}
|
|
56
|
+
.tour-bubble-arrow.is-left {
|
|
57
|
+
right: -16px;
|
|
58
|
+
border-left-color: #fff;
|
|
59
|
+
}
|
|
60
|
+
.tour-bubble-arrow.is-right {
|
|
61
|
+
left: -16px;
|
|
62
|
+
border-right-color: #fff;
|
|
63
|
+
}
|
|
64
|
+
/* 气泡被 clamp 回视口后箭头可能指偏,此时干脆藏掉,别指错地方 */
|
|
65
|
+
.tour-bubble-arrow.is-hidden {
|
|
66
|
+
display: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.tour-step-index {
|
|
70
|
+
font-size: 11px;
|
|
71
|
+
color: #7b8495;
|
|
72
|
+
letter-spacing: 0.02em;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.tour-title {
|
|
76
|
+
margin: 2px 0 6px;
|
|
77
|
+
font-size: 14px;
|
|
78
|
+
font-weight: 600;
|
|
79
|
+
color: #20242d;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.tour-body {
|
|
83
|
+
color: #4a5262;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.tour-body b {
|
|
87
|
+
color: #20242d;
|
|
88
|
+
font-weight: 600;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.tour-actions {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: 6px;
|
|
95
|
+
margin-top: 12px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.tour-actions-spacer {
|
|
99
|
+
flex: 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.tour-btn {
|
|
103
|
+
padding: 4px 12px;
|
|
104
|
+
border: 1px solid #dfe5ee;
|
|
105
|
+
border-radius: 4px;
|
|
106
|
+
background: #fff;
|
|
107
|
+
color: #4a5262;
|
|
108
|
+
font-family: inherit;
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
line-height: 1.5;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.tour-btn:hover {
|
|
116
|
+
background: #f0f5ff;
|
|
117
|
+
border-color: #bfdbff;
|
|
118
|
+
color: #1677ff;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.tour-btn-primary {
|
|
122
|
+
border-color: #1677ff;
|
|
123
|
+
background: #1677ff;
|
|
124
|
+
color: #fff;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.tour-btn-primary:hover {
|
|
128
|
+
background: #0d5edb;
|
|
129
|
+
border-color: #0d5edb;
|
|
130
|
+
color: #fff;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.tour-skip {
|
|
134
|
+
padding: 4px 2px;
|
|
135
|
+
border: 0;
|
|
136
|
+
background: transparent;
|
|
137
|
+
color: #7b8495;
|
|
138
|
+
font-family: inherit;
|
|
139
|
+
font-size: 12px;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.tour-skip:hover {
|
|
144
|
+
color: #1677ff;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.tour-btn:focus-visible,
|
|
148
|
+
.tour-skip:focus-visible,
|
|
149
|
+
.tour-replay-btn:focus-visible {
|
|
150
|
+
outline: 2px solid #1677ff;
|
|
151
|
+
outline-offset: 2px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* 侧栏标题行里的「?」重放入口,由 onboarding.js 运行时注入。
|
|
155
|
+
尺寸与 .copy-address-btn 对齐,保证同一行视觉齐平 */
|
|
156
|
+
.tour-replay-btn {
|
|
157
|
+
flex-shrink: 0;
|
|
158
|
+
width: 24px;
|
|
159
|
+
height: 24px;
|
|
160
|
+
padding: 0;
|
|
161
|
+
border: 1px solid #dfe5ee;
|
|
162
|
+
border-radius: 50%;
|
|
163
|
+
background: #fff;
|
|
164
|
+
color: #7b8495;
|
|
165
|
+
font-family: inherit;
|
|
166
|
+
font-size: 12px;
|
|
167
|
+
line-height: 1;
|
|
168
|
+
cursor: pointer;
|
|
169
|
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.tour-replay-btn:hover {
|
|
173
|
+
background: #edf6ff;
|
|
174
|
+
border-color: #1677ff;
|
|
175
|
+
color: #1677ff;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* 低动效偏好下去掉位移过渡,避免引导跳来跳去引起不适 */
|
|
179
|
+
@media (prefers-reduced-motion: reduce) {
|
|
180
|
+
.tour-spotlight,
|
|
181
|
+
.tour-bubble {
|
|
182
|
+
transition: none;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 新手引导 — 首次打开工作台时,用分步气泡把主要功能走一遍。
|
|
3
|
+
*
|
|
4
|
+
* 设计约束(改这个文件前先看一眼):
|
|
5
|
+
* 1. 外壳 HTML 是脚手架时复制的、之后不会自动升级,所以引导逻辑必须留在 /_kit/ 下,
|
|
6
|
+
* 外壳里只有一对 <!-- onboarding:start/end --> 引用标签。
|
|
7
|
+
* 2. runtime/shell/ 不在 static-check 的 NON_PAGE_DIRS 白名单里,会被当页面文件扫描,
|
|
8
|
+
* 所以存储访问沿用 agent-panel.js 的 window['localStorage'] 写法绕开 FORBIDDEN_STORAGE 红线。
|
|
9
|
+
* 3. 不改动外壳内联脚本和 agent-panel.js:锚点就绪靠 rAF 轮询等,重放按钮靠运行时注入。
|
|
10
|
+
*
|
|
11
|
+
* 调试:window.ProtoTour.reset() 清除"已看过"标记;URL 加 ?tour=off 可整体关闭。
|
|
12
|
+
*/
|
|
13
|
+
(function() {
|
|
14
|
+
const KIT = window.PROTO_KIT || {};
|
|
15
|
+
const NS = (KIT.productId || 'proto') + '-navigator';
|
|
16
|
+
const SEEN_KEY = NS + '-onboarding-seen';
|
|
17
|
+
const TOUR_VERSION = '1'; // 引导改版时 +1,可让老用户重新看一次
|
|
18
|
+
const tourStorage = window['localStorage']; // 见文件头约束 2,勿改成点号访问
|
|
19
|
+
|
|
20
|
+
const GAP = 12; // 气泡与高亮框的间距
|
|
21
|
+
const MARGIN = 12; // 气泡与视口边缘的最小留白
|
|
22
|
+
const PAD = 4; // 高亮框相对目标元素的外扩
|
|
23
|
+
const READY_TIMEOUT = 8000;
|
|
24
|
+
const VISIBLE_TIMEOUT = 20000; // 标签页迟迟不可见时的兜底,见 waitVisible
|
|
25
|
+
|
|
26
|
+
// ── 步骤配置 ──────────────────────────────────────────
|
|
27
|
+
// selector 支持字符串或数组(数组取并集包围盒,一次框住相邻的几个元素);
|
|
28
|
+
// fallback 在主锚点不可见时兜底(例如 Agent 栏处于折叠态)。
|
|
29
|
+
const STEPS = [
|
|
30
|
+
{
|
|
31
|
+
selector: ['#newFolderBtn', '#newPageBtn'],
|
|
32
|
+
placement: 'bottom',
|
|
33
|
+
title: '第一步 · 先把页面建起来',
|
|
34
|
+
body: '点 <b>新建文件夹</b> 分模块,点 <b>新建页面</b> 建一个原型页。建完会自动写进左侧导航树,不用手动改配置。'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
selector: ['#navSearchInput', '#sidebarTree'],
|
|
38
|
+
placement: 'right',
|
|
39
|
+
title: '第二步 · 在这儿找页面',
|
|
40
|
+
body: '左侧是全部原型页面,按目录分组。页面多了就在 <b>搜索</b> 框里输标题关键字,支持模糊匹配;拖动条目还能直接调整顺序。'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
selector: '#previewPlaceholder',
|
|
44
|
+
fallback: '#previewFrame',
|
|
45
|
+
placement: 'left',
|
|
46
|
+
title: '第三步 · 点开就能预览',
|
|
47
|
+
body: '点左侧任意页面,这里直接渲染出来,右上角 <b>在新标签打开 ↗</b> 可以全屏看。页面右下角还有个 <b>PRD</b> 悬浮按钮,随时能看和改这一页的需求说明。'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
selector: '#agentInput',
|
|
51
|
+
fallback: '#agentPanel',
|
|
52
|
+
placement: 'left',
|
|
53
|
+
title: '第四步 · 用大白话改页面',
|
|
54
|
+
body: '选中页面后,在这里描述你要改什么,比如「表格加一列负责人」。Agent 会直接改代码,中间的预览会自动刷新。'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
selector: '#agentPrdUpdateBtn',
|
|
58
|
+
fallback: '#agentPanel',
|
|
59
|
+
placement: 'left',
|
|
60
|
+
title: '第五步 · 按 PRD 标红一键更新',
|
|
61
|
+
body: '在 PRD 里把要改的地方标红,回到这里点这个按钮,Agent 就会按标红内容改页面。<b>需要先选中一个页面,按钮才可点。</b>'
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
// ── 运行状态 ──────────────────────────────────────────
|
|
66
|
+
const state = {
|
|
67
|
+
active: false,
|
|
68
|
+
steps: [], // 本次要走的步骤(已过滤掉这版外壳里不存在的锚点)
|
|
69
|
+
index: 0,
|
|
70
|
+
shown: 0, // 实际展示过的步数,用来判断结束时该不该记"已看过"
|
|
71
|
+
lastFocus: null,
|
|
72
|
+
reposition: null
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
let els = {};
|
|
76
|
+
|
|
77
|
+
// ── 工具 ──────────────────────────────────────────────
|
|
78
|
+
// offsetParent 为 null 就说明自身或某个祖先 display:none —— 正是"Agent 栏折叠了"这种要走
|
|
79
|
+
// fallback 的情况(本引导的锚点都不是 position:fixed,不会误判)。
|
|
80
|
+
// 刻意不量 getBoundingClientRect 的宽高:布局还没排完时(刚导航完、标签页在后台)
|
|
81
|
+
// 量出来会是 0,把本该展示的步骤误判成不可见而跳过。
|
|
82
|
+
function isVisible(el) {
|
|
83
|
+
return !!el && el.offsetParent !== null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const selectorList = sel => (Array.isArray(sel) ? sel : [sel]);
|
|
87
|
+
|
|
88
|
+
/** 解析一个步骤的锚点:主 selector 全不可见时退回 fallback,都不行返回 [] */
|
|
89
|
+
function resolveTargets(step) {
|
|
90
|
+
const pick = sel => selectorList(sel).map(s => document.querySelector(s)).filter(isVisible);
|
|
91
|
+
const main = pick(step.selector);
|
|
92
|
+
if (main.length) return main;
|
|
93
|
+
return step.fallback ? pick(step.fallback) : [];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 这一步在当前这版外壳里存不存在(只看 DOM 里有没有,不量尺寸)。
|
|
98
|
+
* 步骤清单按"存在"过滤而不是按"可见"过滤:布局偶尔会有一瞬间量不到尺寸
|
|
99
|
+
* (刚导航完还没排版、标签页在后台等),按可见过滤会把步骤永久少算一条。
|
|
100
|
+
* 真正的可见性判断留到 go() 展示那一刻做。
|
|
101
|
+
*/
|
|
102
|
+
function stepExists(step) {
|
|
103
|
+
const has = sel => selectorList(sel).some(s => document.querySelector(s));
|
|
104
|
+
return has(step.selector) || (step.fallback ? has(step.fallback) : false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 多个元素的并集包围盒 */
|
|
108
|
+
function unionRect(targets) {
|
|
109
|
+
let top = Infinity, left = Infinity, right = -Infinity, bottom = -Infinity;
|
|
110
|
+
targets.forEach(el => {
|
|
111
|
+
const r = el.getBoundingClientRect();
|
|
112
|
+
top = Math.min(top, r.top);
|
|
113
|
+
left = Math.min(left, r.left);
|
|
114
|
+
right = Math.max(right, r.right);
|
|
115
|
+
bottom = Math.max(bottom, r.bottom);
|
|
116
|
+
});
|
|
117
|
+
return { top, left, right, bottom, width: right - left, height: bottom - top };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function clamp(value, min, max) {
|
|
121
|
+
return Math.max(min, Math.min(max, value));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ── DOM ───────────────────────────────────────────────
|
|
125
|
+
function buildDom() {
|
|
126
|
+
const blocker = document.createElement('div');
|
|
127
|
+
blocker.className = 'tour-blocker';
|
|
128
|
+
|
|
129
|
+
const spotlight = document.createElement('div');
|
|
130
|
+
spotlight.className = 'tour-spotlight';
|
|
131
|
+
|
|
132
|
+
const bubble = document.createElement('div');
|
|
133
|
+
bubble.className = 'tour-bubble';
|
|
134
|
+
bubble.setAttribute('role', 'dialog');
|
|
135
|
+
bubble.setAttribute('aria-modal', 'true');
|
|
136
|
+
bubble.setAttribute('aria-labelledby', 'tourTitle');
|
|
137
|
+
bubble.innerHTML = [
|
|
138
|
+
'<div class="tour-bubble-arrow"></div>',
|
|
139
|
+
'<div class="tour-step-index" id="tourStepIndex"></div>',
|
|
140
|
+
'<div class="tour-title" id="tourTitle"></div>',
|
|
141
|
+
'<div class="tour-body" id="tourBody"></div>',
|
|
142
|
+
'<div class="tour-actions">',
|
|
143
|
+
' <button class="tour-skip" id="tourSkipBtn" type="button">跳过引导</button>',
|
|
144
|
+
' <span class="tour-actions-spacer"></span>',
|
|
145
|
+
' <button class="tour-btn" id="tourPrevBtn" type="button">上一步</button>',
|
|
146
|
+
' <button class="tour-btn tour-btn-primary" id="tourNextBtn" type="button">下一步</button>',
|
|
147
|
+
'</div>'
|
|
148
|
+
].join('');
|
|
149
|
+
|
|
150
|
+
document.body.appendChild(blocker);
|
|
151
|
+
document.body.appendChild(spotlight);
|
|
152
|
+
document.body.appendChild(bubble);
|
|
153
|
+
|
|
154
|
+
els = {
|
|
155
|
+
blocker,
|
|
156
|
+
spotlight,
|
|
157
|
+
bubble,
|
|
158
|
+
arrow: bubble.querySelector('.tour-bubble-arrow'),
|
|
159
|
+
stepIndex: bubble.querySelector('#tourStepIndex'),
|
|
160
|
+
title: bubble.querySelector('#tourTitle'),
|
|
161
|
+
body: bubble.querySelector('#tourBody'),
|
|
162
|
+
skip: bubble.querySelector('#tourSkipBtn'),
|
|
163
|
+
prev: bubble.querySelector('#tourPrevBtn'),
|
|
164
|
+
next: bubble.querySelector('#tourNextBtn')
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
els.skip.addEventListener('click', () => stop(true));
|
|
168
|
+
els.prev.addEventListener('click', () => go(state.index - 1));
|
|
169
|
+
els.next.addEventListener('click', () => go(state.index + 1));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function teardownDom() {
|
|
173
|
+
[els.blocker, els.spotlight, els.bubble].forEach(el => { if (el) el.remove(); });
|
|
174
|
+
els = {};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── 定位 ──────────────────────────────────────────────
|
|
178
|
+
/**
|
|
179
|
+
* 把气泡贴到高亮矩形旁边:首选方向放不下就翻到对侧;两侧都放不下且目标本身足够大
|
|
180
|
+
* (典型如"整个中间预览区"),就直接居中盖在目标上,比硬挤到边上压住目标边缘好看;
|
|
181
|
+
* 目标很小则退回 clamp 回视口,免得气泡把目标整个遮住。
|
|
182
|
+
* 箭头指向目标中心;目标中心落在气泡范围外时直接藏掉,免得指错地方。
|
|
183
|
+
*/
|
|
184
|
+
function place(rect, placement) {
|
|
185
|
+
const vw = window.innerWidth;
|
|
186
|
+
const vh = window.innerHeight;
|
|
187
|
+
const bw = els.bubble.offsetWidth;
|
|
188
|
+
const bh = els.bubble.offsetHeight;
|
|
189
|
+
|
|
190
|
+
const horizontal = placement === 'left' || placement === 'right';
|
|
191
|
+
const fitsBefore = horizontal ? rect.left - GAP - bw >= MARGIN : rect.top - GAP - bh >= MARGIN;
|
|
192
|
+
const fitsAfter = horizontal
|
|
193
|
+
? rect.right + GAP + bw <= vw - MARGIN
|
|
194
|
+
: rect.bottom + GAP + bh <= vh - MARGIN;
|
|
195
|
+
const roomInside = horizontal ? rect.width > bw + 40 : rect.height > bh + 40;
|
|
196
|
+
|
|
197
|
+
if (!fitsBefore && !fitsAfter && roomInside) {
|
|
198
|
+
const left = clamp(rect.left + rect.width / 2 - bw / 2, MARGIN, Math.max(MARGIN, vw - bw - MARGIN));
|
|
199
|
+
const top = clamp(rect.top + rect.height / 2 - bh / 2, MARGIN, Math.max(MARGIN, vh - bh - MARGIN));
|
|
200
|
+
els.bubble.style.left = left + 'px';
|
|
201
|
+
els.bubble.style.top = top + 'px';
|
|
202
|
+
els.arrow.className = 'tour-bubble-arrow is-hidden';
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let dir = placement;
|
|
207
|
+
if (dir === 'bottom' && !fitsAfter && fitsBefore) dir = 'top';
|
|
208
|
+
else if (dir === 'top' && !fitsBefore && fitsAfter) dir = 'bottom';
|
|
209
|
+
else if (dir === 'right' && !fitsAfter && fitsBefore) dir = 'left';
|
|
210
|
+
else if (dir === 'left' && !fitsBefore && fitsAfter) dir = 'right';
|
|
211
|
+
|
|
212
|
+
let left, top;
|
|
213
|
+
if (dir === 'bottom' || dir === 'top') {
|
|
214
|
+
left = rect.left + rect.width / 2 - bw / 2;
|
|
215
|
+
top = dir === 'bottom' ? rect.bottom + GAP : rect.top - GAP - bh;
|
|
216
|
+
} else {
|
|
217
|
+
left = dir === 'right' ? rect.right + GAP : rect.left - GAP - bw;
|
|
218
|
+
top = rect.top + rect.height / 2 - bh / 2;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
left = clamp(left, MARGIN, Math.max(MARGIN, vw - bw - MARGIN));
|
|
222
|
+
top = clamp(top, MARGIN, Math.max(MARGIN, vh - bh - MARGIN));
|
|
223
|
+
|
|
224
|
+
els.bubble.style.left = left + 'px';
|
|
225
|
+
els.bubble.style.top = top + 'px';
|
|
226
|
+
|
|
227
|
+
// 箭头
|
|
228
|
+
els.arrow.className = 'tour-bubble-arrow is-' + dir;
|
|
229
|
+
if (dir === 'bottom' || dir === 'top') {
|
|
230
|
+
const centerX = rect.left + rect.width / 2;
|
|
231
|
+
if (centerX < left + 16 || centerX > left + bw - 16) els.arrow.classList.add('is-hidden');
|
|
232
|
+
else { els.arrow.style.left = (centerX - left - 8) + 'px'; els.arrow.style.top = ''; }
|
|
233
|
+
} else {
|
|
234
|
+
const centerY = rect.top + rect.height / 2;
|
|
235
|
+
if (centerY < top + 16 || centerY > top + bh - 16) els.arrow.classList.add('is-hidden');
|
|
236
|
+
else { els.arrow.style.top = (centerY - top - 8) + 'px'; els.arrow.style.left = ''; }
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** 重新量一遍当前步的锚点并摆好高亮框和气泡(resize / scroll 时也走这里) */
|
|
241
|
+
function reposition() {
|
|
242
|
+
const step = state.steps[state.index];
|
|
243
|
+
if (!step) return;
|
|
244
|
+
const targets = resolveTargets(step);
|
|
245
|
+
if (!targets.length) return;
|
|
246
|
+
|
|
247
|
+
const rect = unionRect(targets);
|
|
248
|
+
els.spotlight.style.left = (rect.left - PAD) + 'px';
|
|
249
|
+
els.spotlight.style.top = (rect.top - PAD) + 'px';
|
|
250
|
+
els.spotlight.style.width = (rect.width + PAD * 2) + 'px';
|
|
251
|
+
els.spotlight.style.height = (rect.height + PAD * 2) + 'px';
|
|
252
|
+
|
|
253
|
+
place({
|
|
254
|
+
left: rect.left - PAD,
|
|
255
|
+
top: rect.top - PAD,
|
|
256
|
+
right: rect.right + PAD,
|
|
257
|
+
bottom: rect.bottom + PAD,
|
|
258
|
+
width: rect.width + PAD * 2,
|
|
259
|
+
height: rect.height + PAD * 2
|
|
260
|
+
}, step.placement);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ── 步骤切换 ──────────────────────────────────────────
|
|
264
|
+
function go(index) {
|
|
265
|
+
if (index < 0) return;
|
|
266
|
+
// 一条都没真正展示过就走到头,说明是异常情况(锚点全都量不到),
|
|
267
|
+
// 别把"已看过"记下来,否则用户会白白错过这次引导
|
|
268
|
+
if (index >= state.steps.length) return stop(state.shown > 0);
|
|
269
|
+
|
|
270
|
+
state.index = index;
|
|
271
|
+
const step = state.steps[index];
|
|
272
|
+
const targets = resolveTargets(step);
|
|
273
|
+
|
|
274
|
+
// 走到这一步时锚点没了(比如中途切了页面),跳过它继续往下
|
|
275
|
+
if (!targets.length) return go(index + 1);
|
|
276
|
+
state.shown++;
|
|
277
|
+
|
|
278
|
+
targets[0].scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
279
|
+
|
|
280
|
+
els.stepIndex.textContent = `第 ${index + 1} 步 / 共 ${state.steps.length} 步`;
|
|
281
|
+
els.title.textContent = step.title;
|
|
282
|
+
els.body.innerHTML = step.body;
|
|
283
|
+
els.prev.hidden = index === 0;
|
|
284
|
+
els.next.textContent = index === state.steps.length - 1 ? '开始使用' : '下一步';
|
|
285
|
+
|
|
286
|
+
reposition();
|
|
287
|
+
els.next.focus();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function onKeyDown(e) {
|
|
291
|
+
if (!state.active) return;
|
|
292
|
+
if (e.key === 'Escape') { e.preventDefault(); stop(true); }
|
|
293
|
+
else if (e.key === 'ArrowRight') { e.preventDefault(); go(state.index + 1); }
|
|
294
|
+
else if (e.key === 'ArrowLeft') { e.preventDefault(); if (state.index > 0) go(state.index - 1); }
|
|
295
|
+
else if (e.key === 'Tab') {
|
|
296
|
+
// 焦点锁在气泡内,别让 Tab 跑到被遮住的界面上
|
|
297
|
+
const focusable = Array.from(els.bubble.querySelectorAll('button')).filter(b => !b.hidden);
|
|
298
|
+
if (!focusable.length) return;
|
|
299
|
+
const first = focusable[0];
|
|
300
|
+
const last = focusable[focusable.length - 1];
|
|
301
|
+
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
302
|
+
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ── 启停 ──────────────────────────────────────────────
|
|
307
|
+
function start() {
|
|
308
|
+
if (state.active) return;
|
|
309
|
+
|
|
310
|
+
const steps = STEPS.filter(stepExists);
|
|
311
|
+
if (!steps.length) return; // 界面还没就绪到能引导的程度,安静退出
|
|
312
|
+
|
|
313
|
+
state.active = true;
|
|
314
|
+
state.steps = steps;
|
|
315
|
+
state.index = 0;
|
|
316
|
+
state.shown = 0;
|
|
317
|
+
state.lastFocus = document.activeElement;
|
|
318
|
+
|
|
319
|
+
buildDom();
|
|
320
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
321
|
+
state.reposition = () => { if (state.active) reposition(); };
|
|
322
|
+
window.addEventListener('resize', state.reposition);
|
|
323
|
+
window.addEventListener('scroll', state.reposition, true); // capture:侧栏树自己也会滚
|
|
324
|
+
|
|
325
|
+
go(0);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** persist=true 表示这是用户主动看完/跳过,记下来下次不再自动弹 */
|
|
329
|
+
function stop(persist) {
|
|
330
|
+
if (!state.active) return;
|
|
331
|
+
state.active = false;
|
|
332
|
+
|
|
333
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
334
|
+
window.removeEventListener('resize', state.reposition);
|
|
335
|
+
window.removeEventListener('scroll', state.reposition, true);
|
|
336
|
+
state.reposition = null;
|
|
337
|
+
|
|
338
|
+
teardownDom();
|
|
339
|
+
|
|
340
|
+
if (persist) {
|
|
341
|
+
try { tourStorage.setItem(SEEN_KEY, TOUR_VERSION); } catch (err) { /* 隐私模式下写不进去,忽略 */ }
|
|
342
|
+
}
|
|
343
|
+
if (state.lastFocus && state.lastFocus.focus) state.lastFocus.focus();
|
|
344
|
+
state.lastFocus = null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function reset() {
|
|
348
|
+
try { tourStorage.removeItem(SEEN_KEY); } catch (err) { /* 同上 */ }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ── 就绪等待 ──────────────────────────────────────────
|
|
352
|
+
// 导航树要等 nav-tree.json 拉完才有内容,Agent 面板要等 agent-panel.js 建完 DOM。
|
|
353
|
+
// 用轮询而不是去改那两处现有代码派发事件,保持零侵入;超时也照常开场(步骤会自动过滤)。
|
|
354
|
+
// 这里刻意用 setTimeout 而不是 requestAnimationFrame:后台标签页里 rAF 会被完全冻结,
|
|
355
|
+
// 连超时都不会推进,工作台在后台标签打开时引导就永远不会出现。
|
|
356
|
+
// 标签页在后台时不开场:一来用户根本没在看,白白消耗掉唯一一次首开引导;
|
|
357
|
+
// 二来后台标签的布局可能量到 0 宽高,会把步骤误判成"锚点不可见"而跳过。
|
|
358
|
+
// 加超时兜底:个别嵌入式浏览器会一直报 hidden,不能让引导永远卡在这儿等。
|
|
359
|
+
// 超时后照常开场也是安全的 —— 步骤清单按"存在"过滤,且一条都没展示成功时不会记"已看过"。
|
|
360
|
+
function waitVisible() {
|
|
361
|
+
if (document.visibilityState !== 'hidden') return Promise.resolve();
|
|
362
|
+
return new Promise(resolve => {
|
|
363
|
+
const timer = setTimeout(finish, VISIBLE_TIMEOUT);
|
|
364
|
+
function finish() {
|
|
365
|
+
clearTimeout(timer);
|
|
366
|
+
document.removeEventListener('visibilitychange', onChange);
|
|
367
|
+
resolve();
|
|
368
|
+
}
|
|
369
|
+
function onChange() { if (document.visibilityState !== 'hidden') finish(); }
|
|
370
|
+
document.addEventListener('visibilitychange', onChange);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function waitReady() {
|
|
375
|
+
return new Promise(resolve => {
|
|
376
|
+
const t0 = Date.now();
|
|
377
|
+
(function tick() {
|
|
378
|
+
const treeReady = !!document.querySelector('#sidebarTree .file-row, #sidebarTree .folder');
|
|
379
|
+
const agentReady = !!document.getElementById('agentInput');
|
|
380
|
+
if ((treeReady && agentReady) || Date.now() - t0 > READY_TIMEOUT) return resolve();
|
|
381
|
+
setTimeout(tick, 100);
|
|
382
|
+
})();
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// ── 重放入口 ──────────────────────────────────────────
|
|
387
|
+
// 外壳 HTML 是冻结的,所以这个按钮在运行时注入到侧栏标题行(.copy-address-btn 旁边)。
|
|
388
|
+
function injectReplayButton() {
|
|
389
|
+
const row = document.querySelector('.sidebar-title-row');
|
|
390
|
+
if (!row || row.querySelector('.tour-replay-btn')) return;
|
|
391
|
+
const btn = document.createElement('button');
|
|
392
|
+
btn.className = 'tour-replay-btn';
|
|
393
|
+
btn.type = 'button';
|
|
394
|
+
btn.textContent = '?';
|
|
395
|
+
btn.title = '重新看一遍新手引导';
|
|
396
|
+
btn.setAttribute('aria-label', '重新看一遍新手引导');
|
|
397
|
+
btn.addEventListener('click', start);
|
|
398
|
+
row.appendChild(btn);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// ── 入口 ──────────────────────────────────────────────
|
|
402
|
+
async function init() {
|
|
403
|
+
injectReplayButton();
|
|
404
|
+
|
|
405
|
+
if (new URLSearchParams(window.location.search).get('tour') === 'off') return;
|
|
406
|
+
let seen = null;
|
|
407
|
+
try { seen = tourStorage.getItem(SEEN_KEY); } catch (err) { return; }
|
|
408
|
+
if (seen === TOUR_VERSION) return;
|
|
409
|
+
|
|
410
|
+
await waitVisible();
|
|
411
|
+
await waitReady();
|
|
412
|
+
start();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
window.ProtoTour = { start, stop: () => stop(false), reset };
|
|
416
|
+
|
|
417
|
+
if (document.readyState === 'loading') {
|
|
418
|
+
document.addEventListener('DOMContentLoaded', init);
|
|
419
|
+
} else {
|
|
420
|
+
init();
|
|
421
|
+
}
|
|
422
|
+
})();
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
<!-- agent-panel:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
8
8
|
<link rel="stylesheet" href="/_kit/shell/agent-panel.css">
|
|
9
9
|
<!-- agent-panel:end -->
|
|
10
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
11
|
+
<link rel="stylesheet" href="/_kit/shell/onboarding.css">
|
|
12
|
+
<!-- onboarding:end -->
|
|
10
13
|
<style>
|
|
11
14
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
12
15
|
|
|
@@ -1519,5 +1522,8 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1519
1522
|
<script>window.PROTO_KIT = { productId: '{{PRODUCT_ID}}', productTitle: '{{PRODUCT_TITLE}}' };</script>
|
|
1520
1523
|
<script src="/_kit/shell/agent-panel.js"></script>
|
|
1521
1524
|
<!-- agent-panel:end -->
|
|
1525
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
1526
|
+
<script src="/_kit/shell/onboarding.js"></script>
|
|
1527
|
+
<!-- onboarding:end -->
|
|
1522
1528
|
</body>
|
|
1523
1529
|
</html>
|