Compare commits
153
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
deac7513fd | ||
|
|
f0568342b1 | ||
|
|
b9c110709d | ||
|
|
c9bb3b09f3 | ||
|
|
4f4e64a989 | ||
|
|
9959096ab3 | ||
|
|
e7f8e68909 | ||
|
|
eb6880b11f | ||
|
|
ba9a4448e4 | ||
|
|
5ff3318fb9 | ||
|
|
8c6ed43078 | ||
|
|
9ed18827a8 | ||
|
|
352cac6031 | ||
|
|
2d2738f3a1 | ||
|
|
27a641903c | ||
|
|
89c2dca424 | ||
|
|
b8718d6810 | ||
|
|
17fd3be13b | ||
|
|
e7d54cb0a8 | ||
|
|
1aba7a0c94 | ||
|
|
4fc4e469c2 | ||
|
|
7cb4379e41 | ||
|
|
f5a5712628 | ||
|
|
56962dca0b | ||
|
|
e9da55cced | ||
|
|
ced0482ed8 | ||
|
|
3a563950ba | ||
|
|
eec5ab6c9b | ||
|
|
385a73c111 | ||
|
|
89d3cfc619 | ||
|
|
ae9b07fe91 | ||
|
|
cb56ffdfda | ||
|
|
34ba29f04f | ||
|
|
65ea7cd64c | ||
|
|
51cfa56f26 | ||
|
|
9f148f06ef | ||
|
|
178b36c477 | ||
|
|
d8f1e89e74 | ||
|
|
b914c76df4 | ||
|
|
98ed47673f | ||
|
|
1ceb241b89 | ||
|
|
efe58236e1 | ||
|
|
dbf3adfc77 | ||
|
|
b10a3bf28d | ||
|
|
09730c7ee9 | ||
|
|
4c6ef7098c | ||
|
|
7a15511582 | ||
|
|
1fa7a8d24a | ||
|
|
2c96524f6b | ||
|
|
2c2ad434bc | ||
|
|
a3d289da21 | ||
|
|
79d631ce86 | ||
|
|
98826f9ee3 | ||
|
|
89eb3053c6 | ||
|
|
aca659615e | ||
|
|
f97fbf6330 | ||
|
|
64db27155a | ||
|
|
e02b5f4345 | ||
|
|
59403a4867 | ||
|
|
5d4bdf5400 | ||
|
|
4539668c06 | ||
|
|
d151df3512 | ||
|
|
ca1764b2c4 | ||
|
|
c9d06b8388 | ||
|
|
4f92ec12dc | ||
|
|
d190cc6433 | ||
|
|
c917d267eb | ||
|
|
99649b0ecd | ||
|
|
675ccf5016 | ||
|
|
f65f037cff | ||
|
|
b2c3dd18d0 | ||
|
|
a4f69164dd | ||
|
|
06fa7f0a9b | ||
|
|
928ffa0de0 | ||
|
|
d42cc3a409 | ||
|
|
00f03de106 | ||
|
|
e6400b35c3 | ||
|
|
59ccc66de4 | ||
|
|
8180607754 | ||
|
|
501e46965a | ||
|
|
5c34856c6a | ||
|
|
8b72967381 | ||
|
|
2fb6372252 | ||
|
|
8078f6495e | ||
|
|
013bb6ba13 | ||
|
|
5e09a587e2 | ||
|
|
aa4ec99c0b | ||
|
|
a5081a81bb | ||
|
|
3e55a83169 | ||
|
|
c25144138d | ||
|
|
59b6393e8a | ||
|
|
930ca2b02a | ||
|
|
b318bae3d2 | ||
|
|
acbf31c26e | ||
|
|
c3eb72fb10 | ||
|
|
c8ae61a3ed | ||
|
|
3ea7c239ac | ||
|
|
344da1bb45 | ||
|
|
f51626040c | ||
|
|
8523120f6c | ||
|
|
3d21bf6457 | ||
|
|
dfe08dcb3c | ||
|
|
87384f124d | ||
|
|
7e9d73d702 | ||
|
|
e8a15cca75 | ||
|
|
e00f211031 | ||
|
|
ebf277158b | ||
|
|
b0258f9ab6 | ||
|
|
59588ef4cc | ||
|
|
b89b181173 | ||
|
|
57efde3eea | ||
|
|
8670619690 | ||
|
|
2495c5bde7 | ||
|
|
5da8f6d3f1 | ||
|
|
ceb97aecee | ||
|
|
da0c3f35c2 | ||
|
|
070a4818f9 | ||
|
|
a487fd3d44 | ||
|
|
61b279a2ca | ||
|
|
c7f619a36d | ||
|
|
43b02a3a1c | ||
|
|
7c7eff40ee | ||
|
|
ca43f08f03 | ||
|
|
3dde0b15b4 | ||
|
|
02fba5aef0 | ||
|
|
9b98eb1a7e | ||
|
|
758e76572f | ||
|
|
b904e9739e | ||
|
|
70b50dc654 | ||
|
|
dccac9d88b | ||
|
|
6c3b21232c | ||
|
|
fa13eb5997 | ||
|
|
21b1c70acb | ||
|
|
df5361cf6e | ||
|
|
7119dcf356 | ||
|
|
fe1d3fcaa6 | ||
|
|
e5e1c25c24 | ||
|
|
a1d0a8e980 | ||
|
|
0cbfc15a60 | ||
|
|
f52aeaa46e | ||
|
|
f7e2b786c7 | ||
|
|
2dc43b701f | ||
|
|
5b2e49f052 | ||
|
|
57070a5720 | ||
|
|
01391ee8b8 | ||
|
|
0c42831cab | ||
|
|
c78da782a2 | ||
|
|
35133d4c23 | ||
|
|
f8998faef0 | ||
|
|
bab181b12f | ||
|
|
a74978d09a | ||
|
|
136fdf58f5 | ||
|
|
329b4638c3 |
No files matched your search
@@ -1,175 +1,199 @@
|
|||||||
# IWB 插件仓
|
# IWB 插件仓(桌面客户端)
|
||||||
|
|
||||||
本仓**只写插件**,不复制宿主契约。宿主(`image-workbench-web` / 工作树 `iwb-arch`)负责提供并演进
|
本仓**只写插件**,是桌面宿主 `image-workbench-desktop`(Tauri v2 客户端,数据全部落本机)的插件源仓。
|
||||||
`window.IWBPluginHost` 契约;这里只消费它。
|
宿主负责提供并演进 `window.IWBPluginHost` 契约,这里只消费它;本仓不复制宿主契约、不改宿主代码。
|
||||||
|
|
||||||
## 为什么能"不动主仓"
|
插件是**可信代码**:与画布同页、同源、同 JS 上下文运行(宿主动态注入 `<script>`),可读画布数据、可发网络请求。
|
||||||
|
只写你信任的插件。
|
||||||
|
|
||||||
插件**不复制宿主契约**,只消费 `window.IWBPluginHost`。两条落地路径**都不需要改宿主代码**:
|
## 插件怎么到用户手里
|
||||||
|
|
||||||
- **路径 A(推荐,实际采用)**:运行时从 KV 加载 —— 本仓开发 → 上传 KV → 刷新即生效(**不重编译、不部署宿主**)。
|
桌面客户端**不随包发布插件**,插件全部从插件市场安装到本机资料目录:
|
||||||
- **路径 B**:构建期并入 —— 本仓开发 → `src/plugin-<id>.js`(宿主构建**自动发现** `plugin-*.js` 并排序追加)→ 宿主 verify → 部署。
|
|
||||||
|
|
||||||
两条路都**不需要改宿主的代码 / 清单 / 快照**。详见下文「两条合入路径」与「运行时机制」。
|
```
|
||||||
|
本仓 <id>/src/index.js
|
||||||
## 两条合入路径(同一条契约,不同部署形态)
|
→ 桌面仓 node scripts/sync-plugins-from-repo.js # 拷到 plugins/runtime/,内容寻址命名 + SRI
|
||||||
|
→ 桌面仓 node scripts/gen-market.js # 生成 market/index.json + market/plugins/*
|
||||||
宿主(`iwb-arch`)同时提供两条路径;**当前唯一真实插件 `xianyi-cutout` 走的是路径 A**。
|
→ 上传 market/ 到 NAS /vol8/web/iwb-market/ # market.maqiart.eu.org(纯静态)
|
||||||
|
→ 用户在客户端「设置 → 插件 / 市场」安装
|
||||||
### 路径 A:运行时发布到 KV(推荐,本仓插件实际采用)
|
|
||||||
|
|
||||||
源码迁出主仓,经 Cloudflare Function `functions/plugins/[[path]].js` + KV(binding `PLUGINS`)**同源运行时加载**。
|
|
||||||
上传后**刷新浏览器即生效**,不重编译、不 deploy 主仓。
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /Users/qiqi/open/github/iwb-arch
|
|
||||||
# 发布器算 SHA-256(SRI integrity)→ 写 plugins/index.json → 上传 KV;输入文件名须为 plugin-<id>.js
|
|
||||||
cp /绝对路径/<插件目录>/src/index.js /tmp/plugin-<id>.js
|
|
||||||
node scripts/plugins-publish.mjs /tmp/plugin-<id>.js --upload --version <id>=<ver>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- **发布器必须写出 `SHA-256`(SRI integrity)到 `plugins/index.json`**;宿主用 `<script integrity>` 强制校验,
|
- 市场索引:`https://market.maqiart.eu.org/index.json`,每个条目带 `sha256` 与 `integrity`。
|
||||||
**缺失/不符即拒载(fail-closed)** —— 这是硬要求。
|
- 安装落点:`<资料目录>/plugins/`(macOS 默认 `~/Documents/ImageWorkbench/plugins/`)。
|
||||||
- 推荐 `plugins-publish.mjs`(默认 dry-run、`--upload` 才写 KV;输入文件名须为 `plugin-<id>.js`)。
|
加载时校验 sha256/integrity,**不符即拒载(fail-closed)**。
|
||||||
`plugins-publish.sh`(`<id> <file> [version]`)**现已同样产出 `integrity`**,可放心使用。
|
|
||||||
- A2 Function 已在**测试站与正式站**上线;本地发布后刷新浏览器即生效。
|
|
||||||
|
|
||||||
### 路径 B:构建期并入 `src/plugin-<id>.js`
|
开发者调试不必走市场:用「开发者模式」直接加载本机未签名代码,见下文「本地调试」。
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /Users/qiqi/open/github/iwb-arch
|
|
||||||
scripts/plugins-sync.sh <本仓路径或 URL> <插件 id> [源文件,默认 dist/plugin.js] [--force]
|
|
||||||
npm run verify # 全绿
|
|
||||||
npm run deploy:test # 发到测试站
|
|
||||||
```
|
|
||||||
|
|
||||||
`scripts/build.js` 自动发现 `src/plugin-*.js`(按文件名排序追加),合入**不需要改主仓任何代码**。
|
|
||||||
`plugins-sync.sh` 会打印来源 `仓库@tag (sha)`,请把它写进宿主的提交信息,便于追溯。
|
|
||||||
|
|
||||||
## 校验(本地 + CI)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run validate # 契约:ibwPlugin 字段、entry 语法、entry 内 manifest(id/apiVersion/version/name/capabilities)与 package.json 一致
|
|
||||||
```
|
|
||||||
|
|
||||||
`.github/workflows/ci.yml` 在 push / PR 时跑同一条命令(只读源码,不需要网络或依赖)。
|
|
||||||
|
|
||||||
## 插件契约(写插件前必读)
|
## 插件契约(写插件前必读)
|
||||||
|
|
||||||
每个插件 = **一个 IIFE 文件**,加载时向宿主注册:
|
每个插件 = **一个 IIFE 文件**,脚本执行时向宿主注册:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
;(function (global) {
|
;(function (global) {
|
||||||
if (!global.IWBPluginHost) return
|
'use strict'
|
||||||
global.IWBPluginHost.register(manifest, function (ctx) {
|
global.IWBPluginHost.register({
|
||||||
|
id: 'hello-world', name: '示例插件', version: '0.1.0', apiVersion: 1,
|
||||||
|
capabilities: ['nodeActions', 'canvas']
|
||||||
|
}, function (ctx) {
|
||||||
// 在这里用 ctx 注册能力;返回 { dispose } 可选
|
// 在这里用 ctx 注册能力;返回 { dispose } 可选
|
||||||
return {}
|
return {}
|
||||||
})
|
})
|
||||||
})(typeof window !== 'undefined' ? window : globalThis)
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
```
|
```
|
||||||
|
|
||||||
**manifest**:`id`(`^[a-z][a-z0-9-]{2,31}$`)、`name`、`version`、`apiVersion`、`capabilities`、可选 `settings`(每项 `{type:'text'|'number'|'boolean', label, desc, default}`)。
|
**manifest 必填**:`id`(`^[a-z][a-z0-9-]{2,31}$`)、`name`、`version`、`apiVersion`(当前 `1`)、`capabilities`。
|
||||||
|
可选 `settings`:对象 `{ 键: { label, desc, default, type } }`,`type` 为 `text` / `number` / `boolean`。
|
||||||
|
|
||||||
**恒定提供**:`ctx.settings` / `ctx.log` / `ctx.storage`(按插件 id 隔离)/ `ctx.events`。
|
**恒定提供**(`ctx` 上一定有):
|
||||||
|
|
||||||
**声明式能力**(在 `capabilities` 里声明后才发放):
|
| API | 用途 |
|
||||||
|
|---|---|
|
||||||
|
| `ctx.settings` | `all()` / `get(k)` / `set(k,v)` / `onChange(fn)`;缺省值取 manifest 的 `settings[].default` |
|
||||||
|
| `ctx.storage` | `ctx.storage.namespace(ns)` → `{ get, set, remove, keys }`,按插件 id + 命名空间隔离 |
|
||||||
|
| `ctx.log(...)` | 写宿主日志 |
|
||||||
|
| `ctx.events` | `on(name,fn)` / `emit(name,payload)` |
|
||||||
|
|
||||||
| capability | `ctx.` 下的 API | 用途 |
|
**声明式能力**(在 `capabilities` 里声明后才发放到 `ctx`):
|
||||||
|
|
||||||
|
| capability | 挂到 ctx 的 key | 用途 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `commands` | `ctx.commands.register({id,title,icon,run})` | 右键菜单「插件命令」 |
|
| `panels` | `ctx.ui` | `registerPanel({id,title,mount(el)})`,资源中心新增插件面板 |
|
||||||
| `nodeActions` | `ctx.nodeActions.register({id,title,icon,appliesTo(node),run(node)})` | 节点漂浮菜单按钮 |
|
| `commands` | `ctx.commands` | `register({id,title,icon,run})`,右键菜单「插件命令」 |
|
||||||
| `nodeTypes` | `ctx.nodes.register({id,title,defaults,run})` | 通用插件节点 `type:'plugin'` 的变体 |
|
| `nodeActions` | `ctx.nodeActions` | `register({id,title,icon,appliesTo(node),run(node)})`,节点漂浮菜单按钮 |
|
||||||
| `panels` | `ctx.ui.registerPanel({id,title,mount(el)})` | 资源中心新增插件面板 |
|
| `nodeTypes` | `ctx.nodes` | `register({id,title,ports,height,color,render})`,通用插件节点变体 |
|
||||||
| `generationHooks` | `ctx.generation.use({beforeRequest,afterResult})` | 改写生图请求体 / 处理归档结果 |
|
| `generationHooks` | `ctx.generation` | `use({beforeRequest,afterResult})`,改写生图请求 / 处理归档结果 |
|
||||||
| `providers` | `ctx.providers.register({id,name,baseUrl,key,models})` | 外部服务提供方(可直接当生图后端) |
|
| `providers` | `ctx.providers` | `register({id,name,baseUrl,key,models})`,外部服务提供方 |
|
||||||
| `canvas` | `ctx.canvas.getNodes()/listNodeTypes()/getSelectedNode()/getNodeImage(id)` | 只读画布(`getNodeImage` 异步直出 dataURL) |
|
| `canvas` | `ctx.canvas` | 只读画布:`getNodes()` / `listNodeTypes()` / `getSelectedNode()` / `getNodeImage(id)` / `screenToWorld()` |
|
||||||
| `canvasWrite` | `ctx.canvas.createNode(...)/createImageNode({dataUrl,name})/setNodeImage(id,dataUrl)` | 受控写画布 |
|
| `canvasWrite` | `ctx.canvas`(合并) | 受控写画布:`createNode()` / `createImageNode()` / `setNodeImage()`。注意**没有 `ctx.canvasWrite`**,仍需同时声明本能力 |
|
||||||
|
|
||||||
**硬约束**:
|
未声明的能力在 `ctx` 上是 undefined,调用会抛错。插件 id 重复会被拒绝注册(先注册者生效)。
|
||||||
- 插件是**可信代码**(无沙箱):可读画布数据、可发网络请求。只合入你信任的代码。
|
工厂抛异常会被宿主隔离;`dispose()`(以及工厂返回值里的 `dispose`)里清理你自己加的 DOM / 定时器 / 监听器。
|
||||||
- **不得依赖其他插件的加载顺序**(自动发现按文件名排序,彼此独立)。
|
|
||||||
- **不得引用宿主的内部实现**(宿主的守门测试会检查:`src/*.js` 不能引用 `app.js` 定义的全局)——只用 `ctx`。
|
|
||||||
- CSP:页面只放行 `'self'` + `https:` + `http://127.0.0.1:30092` / `http://localhost:30092`。要连别的 http 地址会被拦。
|
|
||||||
|
|
||||||
## 目录约定
|
## 桌面环境约束(CSP)
|
||||||
|
|
||||||
```
|
宿主的内容安全策略在 `image-workbench-desktop/src-tauri/tauri.conf.json`,要点:
|
||||||
template/ # 最小可运行插件(复制它开始;手写单文件)
|
|
||||||
xianyi-cutout/ # 真实插件:鲜艺抠图(A2 运行时插件,已发布到宿主 KV;手写单文件)
|
- `script-src 'self' blob:`:经典脚本 IIFE,禁 `eval` / `new Function` / CDN;blob 注入用于本地开发插件。
|
||||||
white-bg-800/ # 真实插件:白底图(移植自 iwb-cutout-extension;已发布到宿主 KV;手写单文件)
|
- `style-src 'self' 'unsafe-inline'`:样式用 JS 注入 `<style>`。
|
||||||
image-annotate/ # 真实插件:标注 / 修图(编辑器移植自 iwb-plaus;需要构建,见下节)
|
- `connect-src` 放行 `self` / `ipc:` / `https:` / `blob:` / `data:` 及本机 `127.0.0.1:30092`、`localhost:30092`(本地抠图服务)。
|
||||||
batch-export/ # 真实插件:批量出图(panels 面板 + 串行队列 + 可选抠图 + 双版本 + ZIP + 行内单张下载;手写单文件)
|
**其它本机端口未放行**(如 ai-chat 用的 Magpie `3425`)——要连需改宿主 CSP 并重新打包客户端。
|
||||||
scripts/ # validate.mjs(CI 必跑)+ build-plugin.mjs(仅需构建的插件用)
|
- `img-src` / `font-src` 放行 `data:`、`blob:`,`https:`(字体仅 `data:`)。
|
||||||
|
|
||||||
|
因为 CSP 里 `connect-src` 含 `blob:`/`data:`,在客户端里 `fetch(blob:)` / `fetch(data:)` 是允许的;
|
||||||
|
但测试用的合成宿主可能按更严的策略跑,插件保留本地解码兜底更稳妥。
|
||||||
|
|
||||||
|
## 目录与插件清单
|
||||||
|
|
||||||
|
顶层目录**有 `package.json` 才会被当成插件**(`scripts/validate.mjs` 的发现规则);
|
||||||
|
多插件共用的源码可放顶层 `shared/`,无需改校验器或 CI。
|
||||||
|
|
||||||
|
| 目录 | 插件 | 形态 |
|
||||||
|
|---|---|---|
|
||||||
|
| `template/` | 最小可运行模板(复制它开始,手写单文件) | 模板 |
|
||||||
|
| `xianyi-cutout/` | 鲜艺抠图:调本机服务抠图 → 透明底节点 | 手写单文件 |
|
||||||
|
| `white-bg-800/` | 白底图:等比居中合成白底/透明大图(双版本,≤500KB) | 手写单文件 |
|
||||||
|
| `batch-export/` | 批量出图:面板 + 串行队列 + 抠图 + 合成 + ZIP / 单张下载 | 手写单文件 |
|
||||||
|
| `blank-canvas/` | 空白画布:给空 ref 节点填纯白图 | 手写单文件 |
|
||||||
|
| `image-annotate/` | 标注 / 修图:全屏单张图片编辑器(选区 / 图层 / 裁剪…) | **需构建** |
|
||||||
|
| `image-vectorize/` | 位图转矢量:potrace 单色 / 灰度描摹 → SVG / PNG | **需构建** |
|
||||||
|
| `style-source/` | 风格库:367 风格面板 → 插预览图 / 提示词 / 样式节点 | 手写单文件 |
|
||||||
|
| `ai-chat/` | AI 对话:直连本机 Magpie 网关的浮窗流式对话 | 手写单文件 · 实验/需本机 Magpie+CSP |
|
||||||
|
|
||||||
|
> 桌面仓的同步脚本 `sync-plugins-from-repo.js` 里有一份**上架白名单**(当前为
|
||||||
|
> `batch-export / blank-canvas / image-annotate / image-vectorize / style-source / white-bg-800 / xianyi-cutout`)。
|
||||||
|
> **新增插件要上架市场,必须把 id 加进那份白名单**,并在桌面仓 `plugins/meta.json` 补名称 / 描述 / 图标等展示信息。
|
||||||
|
|
||||||
|
## 快速开始:5 分钟做出第一个插件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp -r template my-plugin # 复制模板
|
||||||
|
# 改 my-plugin/package.json 的 name,以及 my-plugin/src/index.js 里的 id / name
|
||||||
|
npm run validate # 校验 manifest 与 package.json 是否一致
|
||||||
```
|
```
|
||||||
|
|
||||||
> 顶层目录**没有 `package.json` 就不会被当成插件**(`scripts/validate.mjs` 的发现规则),
|
把 `my-plugin/src/index.js` 拷到 `<资料目录>/plugins/local/my-plugin/plugin.js`,
|
||||||
> 因此将来两个以上插件共用的源码可以放顶层 `shared/`,不需要改校验器或 CI。
|
客户端「设置 → 插件」打开**开发者模式**并重启 —— 右键菜单里就能看到新命令。
|
||||||
|
本地调试免签名、免市场,改完代码重启一次即可重新加载(详见「本地调试」)。
|
||||||
|
|
||||||
## 需要构建的插件(复杂插件)
|
## 开发、构建、校验
|
||||||
|
|
||||||
编辑器/多文件类插件用 ESM 写,构建成单文件 IIFE 产物:
|
```bash
|
||||||
|
npm install # esbuild 是 devDependency,只有构建时需要
|
||||||
|
|
||||||
|
npm run validate # 契约校验:manifest 与 package.json 一致、entry 语法、无重复 id
|
||||||
|
npm run build -- image-annotate # 需要构建的插件:ESM 源码 → 单文件 IIFE 产物
|
||||||
|
```
|
||||||
|
|
||||||
|
校验脚本是 `scripts/validate.mjs`(只读源码、不联网、无依赖),CI 配置在 `.github/workflows/ci.yml`。
|
||||||
|
**CI 只校验、不构建**:所以 `src/index.js` 产物必须提交进仓,不能只提交源码等 CI 来构建。
|
||||||
|
|
||||||
|
### 手写单文件插件
|
||||||
|
|
||||||
|
`src/index.js` 即最终产物(IIFE),改完直接 `npm run validate`。模板见 `template/`。
|
||||||
|
|
||||||
|
### 需要构建的插件(编辑器 / 多文件类)
|
||||||
|
|
||||||
|
用 ESM 写,esbuild 打成单文件 IIFE:
|
||||||
|
|
||||||
```
|
```
|
||||||
<插件>/
|
<插件>/
|
||||||
plugin/entry.js # 打包入口(import 编辑器 + 胶水,导出工厂到全局)
|
plugin/entry.js # 打包入口
|
||||||
plugin/manifest.banner.js # 手写 manifest(单引号,原样放产物最前)
|
plugin/manifest.banner.js # 手写 manifest(单引号,原样放产物最前)
|
||||||
plugin/manifest.footer.js # 手写注册 IIFE(原样放产物最后)
|
plugin/manifest.footer.js # 手写注册 IIFE(原样放产物最后)
|
||||||
plugin/editor/…、*.css # 源码;CSS 以 text loader 内联
|
plugin/editor/…、*.css # 源码;CSS 以 text loader 内联
|
||||||
src/index.js # 构建产物(提交进仓,CI 只校验不构建)
|
src/index.js # 构建产物(提交进仓,CI 只校验不构建)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
分三段拼接的原因:esbuild 会把字符串统一改写成双引号,而校验器只认单引号 manifest,
|
||||||
|
且用「文件里第一个 `id` 字面量」判定插件 id,manifest 必须排在 bundle 之前。
|
||||||
|
`version` 只有一处真源:构建时从 `package.json` 注入 banner 的 `__PLUGIN_VERSION__`。
|
||||||
|
|
||||||
|
## 本地调试(开发者模式)
|
||||||
|
|
||||||
|
1. 把单文件产物放到 `<资料目录>/plugins/local/<插件 id>/plugin.js`。
|
||||||
|
2. 客户端「设置 → 插件」打开**开发者模式**(不开则 `plugins/local/` 下的插件不会加载)。
|
||||||
|
3. 重启客户端(插件在启动时加载);改完代码再重启一次即可重新加载。
|
||||||
|
|
||||||
|
开发者模式下的插件**不校验签名**(免 SRI / sha256),仅限本机调试;正式分发走市场。
|
||||||
|
|
||||||
|
各插件 `tools/harness.mjs` 是本地端到端测试(合成宿主 + 真实 Chromium),改完插件先跑它;
|
||||||
|
需要 Playwright(可从桌面仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定)。
|
||||||
|
|
||||||
|
## 发布到市场
|
||||||
|
|
||||||
|
前提:源码已提交,并在桌面仓完成同步与重建市场。步骤:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install # esbuild 是 devDependency,只有构建时需要
|
# 1) 本仓:改版本(package.json 与 src/index.js 的 manifest.version 保持一致)→ 构建 → 校验 → 提交
|
||||||
npm run build -- image-annotate # 含产物自检:首个 id / register / version / 无 eval
|
npm run build -- <需构建的插件> # 手写单文件跳过
|
||||||
npm run validate
|
npm run validate
|
||||||
|
|
||||||
|
# 2) 桌面仓:同步源仓产物(内容寻址命名 + SRI),再生成市场
|
||||||
|
cd /Users/qiqi/open/github/image-workbench-desktop
|
||||||
|
node scripts/sync-plugins-from-repo.js # 默认读 ../iwb-plugins-desktop
|
||||||
|
node scripts/gen-market.js
|
||||||
|
|
||||||
|
# 3) 把 market/ 上传到 NAS /vol8/web/iwb-market/(market.maqiart.eu.org)
|
||||||
```
|
```
|
||||||
|
|
||||||
**为什么分三段拼接**:esbuild 会把字符串统一改写成双引号,而校验器只认单引号 manifest;
|
- 同步脚本按白名单读取每个 `<id>/src/index.js`,生成 `plugin-<id>.<sha12>.js`(sha256 前 12 位),
|
||||||
且校验器用「文件里第一个 id 字面量」判定插件 id,manifest 必须排在 bundle 之前。
|
重建 `plugins/index.json`;内容不变时产物名与清单完全一致(幂等,可用 `git diff` 验证)。
|
||||||
`version` 只有一处真源 —— 构建时用 `package.json` 的 `version` 替换 banner 里的 `__PLUGIN_VERSION__`。
|
- `gen-market.js` 读 `plugins/index.json` + `plugins/meta.json`,写出市场索引,每个条目带 `sha256` 与 `integrity`。
|
||||||
|
- **版本两处一起改**:`package.json` 的 `version` 与 `src/index.js` 里 manifest 的 `version`(`validate` 会校验一致)。
|
||||||
|
- 发布后回读市场索引确认版本与文件哈希已更新,再在客户端市场里刷新、安装验证——不能只看命令退出码。
|
||||||
|
历史上出过「字节传了、清单没换」导致用户仍拿到旧版的事故(见 `style-source/README.md`)。
|
||||||
|
|
||||||
每个插件目录含 `src/index.js`(IIFE 产物)与 `package.json`(`version` + `ibwPlugin.entry` 供人读,
|
## 排障速查
|
||||||
`version` 用于来源追溯)。合入/发布时把 `src/index.js` 交给对应脚本:路径 A 交给发布器
|
|
||||||
(`.mjs` 需先拷成 `plugin-<id>.js` 再传文件;`.sh` 直接传 `<id> <file>`),路径 B 传 `plugins-sync.sh` 的第三参数(默认 `dist/plugin.js`)。
|
|
||||||
|
|
||||||
## 运行时机制(插件怎么跑 / 为什么发布更新不用宿主)
|
| 现象 | 常见原因 / 排查方向 |
|
||||||
|
|
||||||
**运行位置**:插件与画布/生图**同页、同源、同 JS 上下文**(由 `app.js` 动态插 `<script src="/plugins/<file>">`)。
|
|
||||||
|
|
||||||
- **可信代码,无沙箱**:与核心同权限(可读画布、可发网络)。只合入你信任的代码。
|
|
||||||
- **插件彼此独立**:不得依赖加载顺序;生命周期由 `plugin-host.js` 管(`register` / `activate` / `deactivate` / `dispose`),
|
|
||||||
存储按插件 id **命名空间隔离**、工厂异常被 try/catch **隔离**。
|
|
||||||
- **但依赖宿主契约** `window.IWBPluginHost`(没有它 IIFE 直接 `return`)——**不是**脱离宿主的独立进程/沙箱。
|
|
||||||
|
|
||||||
**发布/更新为何不用宿主**(A2 的设计核心):
|
|
||||||
|
|
||||||
- 运行时**唯一数据源是 KV**:宿主 `functions/plugins/[[path]].js` 读 `env.PLUGINS`(键 `plugins/index.json` + `plugins/<file>`),
|
|
||||||
`app.js` 明说「**更新只需上传到 KV、刷新即生效**」。
|
|
||||||
- 宿主**没有**插件 id 白名单 / 硬编码清单 ⇒ 新增插件 id **不需要改宿主**。
|
|
||||||
- 宿主仓里的 `plugins/index.json` 只是**本地记录**(`dist/` 不含 `plugins/`,function 直读 KV)⇒ 加/改插件**不必**在宿主提交。
|
|
||||||
- `scripts/plugins-publish.{sh,mjs}` 只是**便利脚本**(从宿主 `wrangler.toml` 读 KV namespace id、本地算 SHA-256、`wrangler kv put`),
|
|
||||||
**不改宿主代码、不重编译、不部署宿主**。可直接用裸命令绕过:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 只需 KV namespace id(宿主 wrangler.toml 的 [[kv_namespaces]] id)
|
|
||||||
wrangler kv key put --namespace-id <PLUGINS_ID> --remote "plugins/plugin-<id>.js" --path <本仓插件文件>
|
|
||||||
wrangler kv key put --namespace-id <PLUGINS_ID> --remote "plugins/index.json" --path <清单>
|
|
||||||
```
|
|
||||||
|
|
||||||
**仅两个前置/例外**(都不是"改宿主功能"):
|
|
||||||
|
|
||||||
1. **一次性前置**:A2 Function 需先在目标环境**上线一次**。正式站若未部署,`/plugins/index.json` 会走 SPA 兜底、插件不加载;
|
|
||||||
上线之后,插件发布/更新与宿主无关。
|
|
||||||
2. **新能力例外**:插件用到现有 8 项能力之外的新能力时,才需回宿主扩契约(见下节)。
|
|
||||||
|
|
||||||
## 什么时候必须改宿主
|
|
||||||
|
|
||||||
| 情形 | 动主仓? |
|
|
||||||
|---|---|
|
|---|---|
|
||||||
| **发布/更新插件**(仅用现有能力,A2 Function 已上线) | **不用**——上传 KV + 刷新即生效(见上节) |
|
| 插件完全不加载,状态 `not-registered` | manifest 的 `id` 与产物文件名 `plugin-<id>.js` 的 id 不一致;或 `capabilities` 写错——注意能力名与 ctx key 不同(`nodeTypes` → `ctx.nodes`、`panels` → `ctx.ui`),写错会静默失效 |
|
||||||
| 只用上表能力、纯加文件 | **不用** |
|
| 状态 `error`,提示「脚本完整性校验失败(integrity 不符或加载失败)」 | SRI 校验不符或文件 404;重跑同步脚本并回读市场索引,确认清单指向的哈希文件确实存在 |
|
||||||
| 需要**新的能力/API** | 要——那是一次性契约扩展(宿主侧) |
|
| 状态 `error`,提示「外部插件不可用 / 完整性校验失败(外部插件)」 | 市场条目缺 `src` 或 `integrity`;重跑 `gen-market.js` 重建索引 |
|
||||||
| 需要放宽 CSP / 改构建语义 | 要(安全或架构变更) |
|
| 装了新版本却还是旧行为 | 多半是清单没更新(版本字节传了但索引没换);对照市场索引里的 `sha256` 与客户端实际加载文件算一遍 |
|
||||||
| A2 Function 首次上线(正式站) | 要——一次性 `npm run deploy`(之后与插件发布无关) |
|
| 面板能开,但节点体是无样式裸 DOM / 图片铺满 | CSS 只在面板 `mount()` 里注入了——从存档直接进画布时面板从不 mount。**在脚本执行时就注入 `<style>`**(定义 `ensureStyle()` 并紧跟 CSS 常量调用),关键元素再补行内尺寸兜底 |
|
||||||
|
| 节点里输入框一输入就失焦 | `render()` 里重建了 DOM。幂等同步、不重建;输入框 `pointerdown` 阻止冒泡;`activeElement` 是自己时跳过 value 覆盖 |
|
||||||
|
| 本机服务连不上(如抠图 / Magpie) | 检查 CSP `connect-src`:桌面版只放行本机 `30092`,其它端口(如 `3425`)需改 `tauri.conf.json` 并重新打包客户端 |
|
||||||
|
| 连了多条线却只出一个任务 | 任务身份按 `ownerNodeId`(节点自己)而非 `sourceNodeId`(文本真实来源),多条路径会归约到同一 owner;这是宿主侧语义,排查时别误判为插件丢线 |
|
||||||
|
|
||||||
即:**契约是接口**;插件在接口内玩,宿主只是"收文件的"。**发布 ≠ 改宿主**。
|
遇到具体插件的问题,先去对应 `README.md` 的历史版本章节,多数坑都记着来龙去脉。
|
||||||
+23
-10
@@ -1,6 +1,6 @@
|
|||||||
# AI 对话(ai-chat)
|
# AI 对话(ai-chat)
|
||||||
|
|
||||||
浮窗式 AI 对话插件:直接连你本机的 **[Magpie](https://github.com/yetone/magpie)**(OpenAI 兼容网关,默认 `http://127.0.0.1:3425/v1`),在画布上方开聊。不嵌网页、不走后端代理(Pages Function 跑在边缘、连不到本机 `127.0.0.1`,故插件直连)。
|
浮窗式 AI 对话插件:直接连你本机的 **[Magpie](https://github.com/yetone/magpie)**(OpenAI 兼容网关,默认 `http://127.0.0.1:3425/v1`),在画布上方开聊。不嵌网页、不走后端代理——桌面客户端没有服务端,插件直接连本机网关。
|
||||||
|
|
||||||
## 能力
|
## 能力
|
||||||
|
|
||||||
@@ -16,13 +16,18 @@
|
|||||||
|
|
||||||
| 项 | 默认 | 说明 |
|
| 项 | 默认 | 说明 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Magpie 地址 | `http://127.0.0.1:3425/v1` | 本机 Magpie 端点。改端口需同步放宽宿主 `_headers` 的 `connect-src`。 |
|
| Magpie 地址 | `http://127.0.0.1:3425/v1` | 本机 Magpie 端点。改端口需同步放宽桌面宿主 `src-tauri/tauri.conf.json` 的 CSP `connect-src`。 |
|
||||||
| API Key | `magpie` | Magpie 走 loopback,任意值均可(只认本机)。 |
|
| API Key | `magpie` | Magpie 走 loopback,任意值均可(只认本机)。 |
|
||||||
|
|
||||||
## 前置
|
## 前置
|
||||||
|
|
||||||
1. 本机跑起 Magpie,并配好你想用的 provider(详见 Magpie 文档)。
|
1. 本机跑起 Magpie,并配好你想用的 provider(详见 Magpie 文档)。
|
||||||
2. 宿主 `_headers` 的 `connect-src` 已放行 `http://127.0.0.1:3425` 与 `http://localhost:3425`(本仓已加)。
|
2. 桌面宿主 CSP 的 `connect-src` 默认**未放行 `3425`**(只放了 `30092` 抠图端口)。
|
||||||
|
要用本插件需先在 `image-workbench-desktop/src-tauri/tauri.conf.json` 的 `connect-src` 里加
|
||||||
|
`http://127.0.0.1:3425 http://localhost:3425`,再重新打包客户端(见根 README「桌面环境约束」)。
|
||||||
|
|
||||||
|
> ⚠️ 因为 CSP 需改宿主并重新打包,本插件当前**不在市场同步白名单里**(见根 README),
|
||||||
|
> 只能以「开发者模式」本机加载使用。
|
||||||
|
|
||||||
## 用法
|
## 用法
|
||||||
|
|
||||||
@@ -39,11 +44,19 @@
|
|||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
手写单文件(IIFE),`src/index.js` 即产物,无需构建:
|
手写单文件(IIFE),`src/index.js` 即产物,无需构建。本插件因需改宿主 CSP(见「前置」),
|
||||||
|
暂以开发者模式本机加载:把 `src/index.js` 放到 `<资料目录>/plugins/local/ai-chat/plugin.js`,
|
||||||
|
打开客户端开发者模式后重启。若要纳入市场,需先把 id 加进桌面仓同步脚本的白名单、改好 CSP 并重新打包客户端,
|
||||||
|
再走根 README「发布到市场」的链路。
|
||||||
|
|
||||||
```bash
|
## 状态:实验性,默认不上市场(2026-11-22 明确)
|
||||||
# 路径 A:运行时发布到 KV(推荐)
|
|
||||||
cp src/index.js /tmp/plugin-ai-chat.js
|
本插件**不在** `plugins/index.json` / `market/index.json` 的同步白名单里(见根 README 与 `image-workbench-desktop/scripts/sync-plugins-from-repo.js` 的 `DEV_ONLY_IDS`)。原因:
|
||||||
node ../../image-workbench-web/scripts/plugins-publish.mjs /tmp/plugin-ai-chat.js --upload --version ai-chat=1.0.0
|
|
||||||
# 注:实际发布需把全部插件一并传入,保持 index.json 完整(见宿主发布流程)
|
1. 依赖**本机 Magpie** 网关(默认 `127.0.0.1:3425`),多数用户没有;
|
||||||
```
|
2. 需要宿主 CSP `connect-src` 放行 `3425`,必须**改客户端并重新打包**才生效。
|
||||||
|
|
||||||
|
因此它只作为「开发者直装」保留:
|
||||||
|
|
||||||
|
- 目录里已有 `manifest.json`(`main` 指向 `src/index.js`);想本机试用,把整个 `ai-chat/` 放到资料目录 `plugins/ai-chat/`,并在宿主 CSP 里放行 3425 后重启;
|
||||||
|
- 不随客户端发版、不进市场,避免用户装了连不上。
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "ai-chat",
|
||||||
|
"name": "AI 对话",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"apiVersion": 1,
|
||||||
|
"main": "src/index.js",
|
||||||
|
"description": "浮窗直连本机 Magpie(OpenAI 兼容网关)的 AI 对话插件;需本机网关 + 宿主 CSP 放行 3425 端口,默认不上市场。",
|
||||||
|
"author": "official",
|
||||||
|
"icon": "💬",
|
||||||
|
"tags": ["AI", "对话", "实验"],
|
||||||
|
"files": {}
|
||||||
|
}
|
||||||
+13
-22
@@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
自写 STORE(无压缩)写入器,零依赖:
|
自写 STORE(无压缩)写入器,零依赖:
|
||||||
|
|
||||||
- **为什么不用 JSZip**:宿主 CSP 是 `script-src 'self'`,CDN 动态插 script 会被拦死(宿主 `storage-zip.js` 记着这条教训)。
|
- **为什么不用 JSZip**:桌面宿主 CSP 是 `script-src 'self' blob:`,CDN 动态插 script 会被拦死(宿主 `storage-zip.js` 记着这条教训)。
|
||||||
- **为什么 STORE**:图片本身已是 PNG/JPEG,DEFLATE 几乎不减体积,还白花 CPU。
|
- **为什么 STORE**:图片本身已是 PNG/JPEG,DEFLATE 几乎不减体积,还白花 CPU。
|
||||||
- **文件名 UTF-8**:写 general purpose bit 11(`0x0800`),中文名在 Windows 资源管理器 / macOS 归档实用工具里正常。
|
- **文件名 UTF-8**:写 general purpose bit 11(`0x0800`),中文名在 Windows 资源管理器 / macOS 归档实用工具里正常。
|
||||||
⚠️ **macOS 命令行 `unzip`(Info-ZIP 6.0)不认这个标志位**,会解成乱码并报 `Illegal byte sequence` —— 是那个老工具的锅,
|
⚠️ **macOS 命令行 `unzip`(Info-ZIP 6.0)不认这个标志位**,会解成乱码并报 `Illegal byte sequence` —— 是那个老工具的锅,
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
## CSP / 权限
|
## CSP / 权限
|
||||||
|
|
||||||
- 只声明 `panels` + `canvas`(只读),**不要 `canvasWrite`** —— 本插件不写画布。
|
- 只声明 `panels` + `canvas`(只读),**不要 `canvasWrite`** —— 本插件不写画布。
|
||||||
- 抠图请求打到 `apiUrl`,CSP 只放行 `127.0.0.1` / `localhost` 的 `30092`;改别的地址会被浏览器拦。
|
- 抠图请求打到 `apiUrl`,桌面宿主 CSP 只放行 `127.0.0.1` / `localhost` 的 `30092`;改别的地址会被拦。
|
||||||
- `createObjectURL` 下载走 `a.click()`;`img-src` 放行 `blob:`,解码用 blob URL 并即时释放。
|
- `createObjectURL` 下载走 `a.click()`;`img-src` 放行 `blob:`,解码用 blob URL 并即时释放。
|
||||||
|
|
||||||
## 验证(开发用)
|
## 验证(开发用)
|
||||||
@@ -93,39 +93,30 @@ mock 宿主 + 真实 Chromium,覆盖:manifest / 面板注册与挂载 / 列
|
|||||||
队列跑通 / **ZIP 用系统 `unzip -t` 验结构与 CRC + python3 zipfile 验中文名与 8 个条目 + PNG/JPEG magic** /
|
队列跑通 / **ZIP 用系统 `unzip -t` 验结构与 CRC + python3 zipfile 验中文名与 8 个条目 + PNG/JPEG magic** /
|
||||||
抠图分支(mock `/rmbg`)/ 失败行内提示 / 参数持久化 / 静态检查(无 eval、无 `fetch(data:)`)。
|
抠图分支(mock `/rmbg`)/ 失败行内提示 / 参数持久化 / 静态检查(无 eval、无 `fetch(data:)`)。
|
||||||
|
|
||||||
需要 Playwright(可从宿主仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定)+ 系统 `unzip`、`python3`,不进 CI。
|
需要 Playwright(可从桌面仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定)+ 系统 `unzip`、`python3`,不进 CI。
|
||||||
|
|
||||||
**发布后必须再跑一次真站**(mock 抓不到宿主 CSS / 真实 CSP / 真实面板挂载):
|
**发布后必须再跑一次真机**(mock 抓不到宿主 CSS / 真实 CSP / 真实面板挂载):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node batch-export/tools/e2e-site.mjs # 测试站
|
node batch-export/tools/e2e-site.mjs
|
||||||
IWB_BASE_URL=https://iwb.maqiart.eu.org node batch-export/tools/e2e-site.mjs # 正式站
|
|
||||||
```
|
```
|
||||||
|
|
||||||
覆盖:真实 KV 加载 + SRI + 资源中心 tab 出现 + 面板挂载 + 列表 2 行 +
|
覆盖:市场安装加载 + SRI + 资源中心 tab 出现 + 面板挂载 + 列表 2 行 +
|
||||||
**勾选框与文字同行(1.0.1 修的就是这个:`.iwb-bx-f input{width:100%}` 把 checkbox 撑满整行)** +
|
**勾选框与文字同行(1.0.1 修的就是这个:`.iwb-bx-f input{width:100%}` 把 checkbox 撑满整行)** +
|
||||||
队列跑通 + 下载 ZIP + python3 校验 4 条目 / CRC / PNG·JPEG magic / UTF-8 名。
|
队列跑通 + 下载 ZIP + python3 校验 4 条目 / CRC / PNG·JPEG magic / UTF-8 名。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
|
本仓只产出 `src/index.js`(手写单文件 IIFE)。发布走桌面仓的市场链路,见根 README「发布到市场」:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /Users/qiqi/open/github/image-workbench-web
|
npm run validate
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/batch-export/src/index.js /tmp/plugin-batch-export.js
|
# 桌面仓:node scripts/sync-plugins-from-repo.js && node scripts/gen-market.js
|
||||||
# ⚠️ 必须把所有插件文件一起传入:发布器用「传入的文件」重建 plugins/index.json,不做合并
|
# 再把 market/ 上传到 NAS(market.maqiart.eu.org)
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/white-bg-800/src/index.js /tmp/plugin-white-bg-800.js
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/xianyi-cutout/src/index.js /tmp/plugin-xianyi-cutout.js
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/image-annotate/src/index.js /tmp/plugin-image-annotate.js
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/blank-canvas/src/index.js /tmp/plugin-blank-canvas.js
|
|
||||||
node scripts/plugins-publish.mjs /tmp/plugin-batch-export.js /tmp/plugin-white-bg-800.js \
|
|
||||||
/tmp/plugin-xianyi-cutout.js /tmp/plugin-image-annotate.js /tmp/plugin-blank-canvas.js \
|
|
||||||
--version batch-export=1.1.0 # 默认 dry-run,检查 diff 后再加 --upload
|
|
||||||
```
|
```
|
||||||
|
|
||||||
发布后刷新即生效;新插件在「设置 → 插件」里**默认未启用**,需手动勾选。
|
桌面仓同步脚本按白名单一次重建全部插件清单。改版本时同步 `package.json` 的 `version`
|
||||||
|
与 `src/index.js` 里 manifest 的 `version`。发布后回读市场索引确认版本与哈希已更新,再在客户端市场安装验证。
|
||||||
⚠️ `--upload` 时脚本按清单顺序逐个 put,最后才 put `index.json`。代理抖动会让它在半路 `fetch failed` 退出,
|
|
||||||
此时**清单可能已经指向还没上传成功的文件**(1.0.1 发布时踩过)⇒ 线上 fail-closed 直接不加载。
|
|
||||||
稳妥做法:先把插件字节 put 上去,`curl` 确认 200 且大小对,再 put `index.json`。
|
|
||||||
|
|
||||||
## 版本记录
|
## 版本记录
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/batch-export",
|
"name": "@iwb-plugin/batch-export",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.0",
|
"version": "1.2.2",
|
||||||
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "batch-export",
|
"id": "batch-export",
|
||||||
|
|||||||
+22
-12
@@ -454,37 +454,47 @@
|
|||||||
'.iwb-bx-name{flex:1;min-width:70px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
'.iwb-bx-name{flex:1;min-width:70px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
||||||
'.iwb-bx-tag{font-size:11px;white-space:nowrap;color:var(--iwb-text2,#4d5668);',
|
'.iwb-bx-tag{font-size:11px;white-space:nowrap;color:var(--iwb-text2,#4d5668);',
|
||||||
'max-width:46%;min-width:0;overflow:hidden;text-overflow:ellipsis}',
|
'max-width:46%;min-width:0;overflow:hidden;text-overflow:ellipsis}',
|
||||||
'.iwb-bx-tag-ok{color:#1d9e75}',
|
// 状态色不能直接当文字色:宿主 --iwb-ok 亮色是 #22c55e,压在浅页面上对比只有 2.13。
|
||||||
'.iwb-bx-tag-err{color:#d85a30}',
|
// 照 design-tokens.md §3 的 iwb-mk-badge 范例,用 color-mix 往 --iwb-text 压 18%,亮暗两端都读得清。
|
||||||
|
'.iwb-bx-tag-ok{color:color-mix(in srgb,var(--iwb-ok,#1d9e75) 82%,var(--iwb-text,#1c2333))}',
|
||||||
|
'.iwb-bx-tag-err{color:color-mix(in srgb,var(--iwb-err,#d85a30) 82%,var(--iwb-text,#1c2333))}',
|
||||||
// 行内单张下载:常驻不悬浮(要一眼看出「这行能下什么」),无产物时灰掉但保留占位,
|
// 行内单张下载:常驻不悬浮(要一眼看出「这行能下什么」),无产物时灰掉但保留占位,
|
||||||
// 避免产物出现时行宽突然变化导致列表跳动。
|
// 避免产物出现时行宽突然变化导致列表跳动。
|
||||||
'.iwb-bx-dl{flex:0 0 auto;padding:2px 6px;border-radius:5px;font-size:11px;line-height:1.5;',
|
'.iwb-bx-dl{flex:0 0 auto;padding:2px 6px;border-radius:5px;font-size:11px;line-height:1.5;',
|
||||||
'font-family:ui-monospace,SFMono-Regular,Menlo,monospace;border:1px solid var(--iwb-border,#d5d9e0);',
|
'font-family:ui-monospace,SFMono-Regular,Menlo,monospace;border:1px solid var(--iwb-border,#d5d9e0);',
|
||||||
'background:transparent;color:var(--iwb-text2,#4d5668);cursor:pointer}',
|
'background:transparent;color:var(--iwb-text2,#4d5668);cursor:pointer}',
|
||||||
'.iwb-bx-dl-on{background:var(--iwb-layer,#f0f1f4);color:var(--iwb-text,#1c2333);border-color:var(--iwb-text2,#4d5668)}',
|
'.iwb-bx-dl-on{background:var(--iwb-layer,#f0f1f4);color:var(--iwb-text,#1c2333);border-color:var(--iwb-text2,#4d5668)}',
|
||||||
'.iwb-bx-dl-on:hover{border-color:#2f6fed;color:#2f6fed}',
|
'.iwb-bx-dl-on:hover{border-color:var(--iwb-brand,#2f6fed);color:var(--iwb-brand-text,#2f6fed)}',
|
||||||
'.iwb-bx-dl[disabled]{opacity:.45;cursor:not-allowed;border-color:var(--iwb-border,#d5d9e0)}',
|
'.iwb-bx-dl[disabled]{opacity:.45;cursor:not-allowed;border-color:var(--iwb-border,#d5d9e0)}',
|
||||||
'.iwb-bx-empty{padding:24px 12px;text-align:center;color:var(--iwb-text2,#4d5668)}',
|
'.iwb-bx-empty{padding:24px 12px;text-align:center;color:var(--iwb-text2,#4d5668)}',
|
||||||
// 缩略图:小方图(30px)常驻在行首,跑完换成产物本身,一眼能对上「哪张图、出了什么」
|
// 缩略图:小方图(30px)常驻在行首,跑完换成产物本身,一眼能对上「哪张图、出了什么」
|
||||||
'.iwb-bx-thumb{width:30px;height:30px;flex:0 0 auto;object-fit:contain;border-radius:5px;',
|
'.iwb-bx-thumb{width:30px;height:30px;flex:0 0 auto;object-fit:contain;border-radius:5px;',
|
||||||
'border:1px solid var(--iwb-border,#d5d9e0);background:#fff;cursor:zoom-in;padding:1px}',
|
'border:1px solid var(--iwb-border,#d5d9e0);background:#fff/*iwb:content*/;cursor:zoom-in;padding:1px}',
|
||||||
'.iwb-bx-thumb-out{border-color:#1d9e75;cursor:zoom-in}',
|
'.iwb-bx-thumb-out{border-color:var(--iwb-ok,#1d9e75);cursor:zoom-in}',
|
||||||
'.iwb-bx-thumb-ph{background:var(--iwb-layer,#f0f1f4);cursor:default}',
|
'.iwb-bx-thumb-ph{background:var(--iwb-layer,#f0f1f4);cursor:default}',
|
||||||
'.iwb-bx-done{display:none;align-items:center;gap:6px;padding:9px 12px;font-size:11px;',
|
'.iwb-bx-done{display:none;align-items:center;gap:6px;padding:9px 12px;font-size:11px;',
|
||||||
'color:#1d9e75;background:rgba(29,158,117,.08);border-top:1px solid var(--iwb-border,#d5d9e0)}',
|
'color:color-mix(in srgb,var(--iwb-ok,#1d9e75) 82%,var(--iwb-text,#1c2333));',
|
||||||
|
'background:color-mix(in srgb,var(--iwb-ok,#1d9e75) 8%,transparent);',
|
||||||
|
'border-top:1px solid var(--iwb-border,#d5d9e0)}',
|
||||||
'.iwb-bx-zoom{position:fixed;inset:0;z-index:99999;display:flex;align-items:center;justify-content:center;',
|
'.iwb-bx-zoom{position:fixed;inset:0;z-index:99999;display:flex;align-items:center;justify-content:center;',
|
||||||
'background:rgba(0,0,0,.72);cursor:zoom-out}',
|
'background:rgba(0,0,0,.72);cursor:zoom-out}',
|
||||||
'.iwb-bx-zoom img{max-width:86vw;max-height:86vh;border-radius:8px;background:#fff}',
|
'.iwb-bx-zoom img{max-width:86vw;max-height:86vh;border-radius:8px;background:#fff/*iwb:content*/}',
|
||||||
// 双类选择器:单靠 .iwb-bx-btn-hot 会被后定义的 .iwb-bx-btn 背景覆盖(同特异性,后者胜)
|
// 主/热按钮此前是纯蓝 #2f6fed 实心 + 白字:与项目「全灰阶、无蓝」的配色约束冲突,
|
||||||
'.iwb-bx-btn.iwb-bx-btn-hot{background:#1d9e75;border-color:#1d9e75;color:#fff}',
|
// 且暗色下亮绿底压白字对比度不足。改成宿主语义色成对反相 + 状态色描边,
|
||||||
|
// var() 兜底保留私有值,脱离宿主独立运行时不退化。
|
||||||
|
'.iwb-bx-btn.iwb-bx-btn-hot{',
|
||||||
|
'background:color-mix(in srgb,var(--iwb-ok,#1d9e75) 14%,transparent);',
|
||||||
|
'border-color:color-mix(in srgb,var(--iwb-ok,#1d9e75) 82%,var(--iwb-text,#1c2333));',
|
||||||
|
'color:color-mix(in srgb,var(--iwb-ok,#1d9e75) 82%,var(--iwb-text,#1c2333))}',
|
||||||
'.iwb-bx-foot{display:flex;align-items:center;gap:8px;padding:10px 12px;',
|
'.iwb-bx-foot{display:flex;align-items:center;gap:8px;padding:10px 12px;',
|
||||||
'border-top:1px solid var(--iwb-border,#d5d9e0)}',
|
'border-top:1px solid var(--iwb-border,#d5d9e0)}',
|
||||||
'.iwb-bx-prog{flex:1;height:4px;border-radius:2px;background:var(--iwb-border,#d5d9e0);overflow:hidden}',
|
'.iwb-bx-prog{flex:1;height:4px;border-radius:2px;background:var(--iwb-border,#d5d9e0);overflow:hidden}',
|
||||||
'.iwb-bx-prog i{display:block;height:100%;width:0;background:#2f6fed;transition:width .15s}',
|
'.iwb-bx-prog i{display:block;height:100%;width:0;background:var(--iwb-brand-text,#2f6fed);transition:width .15s}',
|
||||||
'.iwb-bx-btn{padding:5px 10px;border-radius:6px;border:1px solid var(--iwb-border,#d5d9e0);',
|
'.iwb-bx-btn{padding:5px 10px;border-radius:6px;border:1px solid var(--iwb-border,#d5d9e0);',
|
||||||
'background:var(--iwb-layer,#f0f1f4);color:inherit;font:inherit;cursor:pointer;white-space:nowrap}',
|
'background:var(--iwb-layer,#f0f1f4);color:inherit;font:inherit;cursor:pointer;white-space:nowrap}',
|
||||||
'.iwb-bx-btn[disabled]{opacity:.45;cursor:not-allowed}',
|
'.iwb-bx-btn[disabled]{opacity:.45;cursor:not-allowed}',
|
||||||
'.iwb-bx-btn-primary{background:#2f6fed;border-color:#2f6fed;color:#fff}',
|
'.iwb-bx-btn-primary{background:var(--iwb-text,#2f6fed);border-color:var(--iwb-text,#2f6fed);',
|
||||||
|
'color:var(--iwb-layer,#fff)}',
|
||||||
].join('')
|
].join('')
|
||||||
|
|
||||||
function ensureStyle() {
|
function ensureStyle() {
|
||||||
@@ -500,7 +510,7 @@
|
|||||||
global.IWBPluginHost.register({
|
global.IWBPluginHost.register({
|
||||||
id: 'batch-export',
|
id: 'batch-export',
|
||||||
name: '批量出图',
|
name: '批量出图',
|
||||||
version: '1.2.0',
|
version: '1.2.2',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'canvas'],
|
capabilities: ['panels', 'canvas'],
|
||||||
settings: {
|
settings: {
|
||||||
|
|||||||
@@ -31,12 +31,13 @@
|
|||||||
- 合成:`canvas(w,h)` → `fillStyle='#ffffff'` → `fillRect` → `toDataURL('image/png')`。
|
- 合成:`canvas(w,h)` → `fillStyle='#ffffff'` → `fillRect` → `toDataURL('image/png')`。
|
||||||
- 写回:`ctx.canvas.setNodeImage(nodeId, dataUrl)`(原地覆盖,`url` 清空)。注意宿主把 `canvasWrite` 的 API **合并进 `ctx.canvas`**,`ctx.canvasWrite` 并不存在 —— 但 manifest 的 `capabilities` 仍须同时声明 `canvas` 与 `canvasWrite`,否则拿不到写接口。
|
- 写回:`ctx.canvas.setNodeImage(nodeId, dataUrl)`(原地覆盖,`url` 清空)。注意宿主把 `canvasWrite` 的 API **合并进 `ctx.canvas`**,`ctx.canvasWrite` 并不存在 —— 但 manifest 的 `capabilities` 仍须同时声明 `canvas` 与 `canvasWrite`,否则拿不到写接口。
|
||||||
- 空白判定:`node.type === 'ref' && !data.data && !data.url`(与上游 `isEmptyRefNode` 等价)。
|
- 空白判定:`node.type === 'ref' && !data.data && !data.url`(与上游 `isEmptyRefNode` 等价)。
|
||||||
- 样式用宿主 CSS 变量(`--iwb-panel/--iwb-text/--iwb-border/--iwb-layer`),明暗主题自适应;CSP 允许 `style-src 'unsafe-inline'`。
|
- 样式用宿主 CSS 变量(`--iwb-panel/--iwb-text/--iwb-border/--iwb-layer`),明暗主题自适应;桌面宿主 CSP 允许 `style-src 'unsafe-inline'`。
|
||||||
|
|
||||||
## 已知限制
|
## 已知限制
|
||||||
- `setNodeImage` 不改节点名,所以不会像上游那样命名为 `<名字>_blank_<W>x<h>.png`(节点名保持不变)。若需要文件名,得宿主开放"改节点名"的写接口。
|
- `setNodeImage` 不改节点名,所以不会像上游那样命名为 `<名字>_blank_<W>x<h>.png`(节点名保持不变)。若需要文件名,得宿主开放"改节点名"的写接口。
|
||||||
- 1K 纯白 PNG 的 dataURL 约 30–34 KB,落库时会被宿主引用化为 `{__blob}`(超过 3000 字符阈值),属正常路径。
|
- 1K 纯白 PNG 的 dataURL 约 30–34 KB,落库时会被宿主引用化为 `{__blob}`(超过 3000 字符阈值),属正常路径。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
与其它插件一致:先 `npm run validate`,再由宿主仓的 `scripts/plugins-publish.mjs` 以哈希名入库。
|
与其它插件一致:本仓只产出 `src/index.js`(手写单文件 IIFE),先 `npm run validate`,再走桌面仓的市场链路
|
||||||
⚠️ 发布时**必须把所有插件文件一起传入**(发布器用传入的文件重建清单,不做合并)。
|
(同步 → 生市场 → 上传 `market/` 到 NAS),见根 README「发布到市场」。
|
||||||
|
桌面仓同步脚本按白名单一次重建全部插件清单,改版本时同步 `package.json` 与 manifest 的 `version`。
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
# browser · 应用内浏览器
|
||||||
|
|
||||||
|
两种用法,共用同一套宿主命令:
|
||||||
|
|
||||||
|
- **画布节点**:网页直接长在画布上,跟着节点平移缩放,能和参考图并排对照。
|
||||||
|
- **独立窗口**:资源中心 →「浏览器」面板,网页在单独窗口里打开,不占画布。
|
||||||
|
|
||||||
|
## 画布内的网页节点
|
||||||
|
|
||||||
|
> **需要客户端 v3.25.29+**。
|
||||||
|
> v3.25.24~26 有「一动就白」(移动/缩放节点或画布后内容消失),v3.25.29 之前
|
||||||
|
> 还有「地址栏被网页盖住」与「内容不跟着画布缩放」两个问题 —— 都已修好。
|
||||||
|
> 旧客户端上插件会直接在节点里写明需要升级,不会只留一块白板。
|
||||||
|
|
||||||
|
画布空白处**右键 →「插件: 网页」**(插件节点不进双击菜单,这是宿主的既定规则),
|
||||||
|
得到一个 560×520 的网页节点:
|
||||||
|
|
||||||
|
```
|
||||||
|
[←][→][⟳] [ 地址栏 ] [− 100% +] | [↗][✕]
|
||||||
|
┌──────────────────────────────────────────┐
|
||||||
|
│ 网页本体(原生子 webview,盖在锚点上) │
|
||||||
|
└──────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
| 控件 | 行为 |
|
||||||
|
|---|---|
|
||||||
|
| `←` `→` | 后退 / 前进(走页面自身的 history) |
|
||||||
|
| `⟳` | 刷新;**加载中变成「停止」**,点了只中断请求,不销毁视图 |
|
||||||
|
| 地址栏 | 回车加载,`Esc` 还原;**站内跳转后自动显示当前真实地址** |
|
||||||
|
| `− 100% +` | 内容缩放设定框:点百分比可直接输入(如 `150`、`150%`),回车生效;双击回 100%;范围 25%~300% |
|
||||||
|
| `↗` | 用独立窗口/浏览器面板打开当前页面(方便多屏、需要网址栏时) |
|
||||||
|
| `✕` | 关闭网页但保留节点,点 `⟳` 或重新输入网址即可恢复 |
|
||||||
|
|
||||||
|
其它行为:
|
||||||
|
|
||||||
|
- 地址存进节点数据,下次打开画布自动恢复;标题为空时自动用站点名(多个网页节点并排时分得清)。
|
||||||
|
- **内容缩放 = 该节点缩放 × 画布缩放**:缩小画布时网页像图片一样一起缩小,不会按原宽度重排。
|
||||||
|
- 节点可以像普通节点那样拖动、缩放、编组、复制。
|
||||||
|
- **拖动节点要用标题栏**:网页区域的鼠标事件由网页自己消费,这是原生子 webview 的物理属性。
|
||||||
|
- 原生视图会被裁到「节点 ∩ 画布」,且上边界不越过工具栏 —— 按钮永远点得到。
|
||||||
|
- 画布切到别的工作区、被模态遮罩挡住、节点完全移出画布时才隐藏;平移/缩放过程全程可见。
|
||||||
|
- 缩到画布 15% 以下(节点体走 LOD 降级)时节点体会被替换,网页随之回收;放大回来会重建。
|
||||||
|
|
||||||
|
## 它解决什么
|
||||||
|
|
||||||
|
画布里的网页内容有两条死路,都走不通:
|
||||||
|
|
||||||
|
- **iframe**:主窗口 CSP 是 `default-src 'self'`,外部网址被拦;就算加了 `frame-src`,百度/GitHub 等站点都发 `X-Frame-Options` / `frame-ancestors`,拒绝被嵌。实测 GitHub、站酷、Figma、Pinterest 全部拒绝,只有维基/百度/B站/花瓣这类允许。
|
||||||
|
- **`<a target=_blank>`**:桌面 webview 里点外链会把**整个应用**导航成网页(宿主 `ui-desktop-shell.js` 专门拦截了这种行为)。
|
||||||
|
|
||||||
|
正解是原生 webview:独立窗口用 `WebviewWindow`,画布节点用 `Window::add_child` 子 webview。两者加载的都是网站自己的页面,**不受主窗口 CSP 约束**,也没有任何 IPC 权限——既能正常上网,又碰不到宿主 API。
|
||||||
|
|
||||||
|
## 用法(独立窗口)
|
||||||
|
|
||||||
|
资源中心 →「浏览器」面板:
|
||||||
|
|
||||||
|
- 地址栏输入网址,`回车` 或点「打开」。没写协议自动补 `https://`。
|
||||||
|
- 点书签快捷打开。默认四个:风格库 / 百度 / 必应 / GitHub。
|
||||||
|
- 重复打开不同网址会**复用同一个窗口**:聚焦过去并导航到新地址,不会越开越多。
|
||||||
|
- 地址栏下面一排控制:`← 后退` `→ 前进` `⟳ 刷新` `✕ 关闭`,左侧圆点显示窗口是否还开着、当前在哪个站。外部页里跳走之后从这里退回来,不用重新输网址。
|
||||||
|
|
||||||
|
书签自定义:设置 → 插件 →「应用内浏览器」→ `书签`,每行一个,格式 `名称 | 网址`(网址可省略 `https://`,`#` 开头是注释)。留空恢复默认。
|
||||||
|
|
||||||
|
## 依赖宿主命令(重要)
|
||||||
|
|
||||||
|
插件调用桌面仓的命令(`__TAURI__.core.invoke`),实现在 `image-workbench-desktop/src-tauri/src/lib.rs`。
|
||||||
|
|
||||||
|
**独立窗口:**
|
||||||
|
|
||||||
|
| 命令 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `open_browser_window` | 打开/复用独立窗口并导航(原生 `navigate`,不往外部页面注入 JS) |
|
||||||
|
| `browser_control` | `back` / `forward` / `reload` / `close` |
|
||||||
|
| `browser_state` | 返回 `{ open, url }`,面板据此显示当前站点、启用或禁用按钮 |
|
||||||
|
|
||||||
|
**画布节点:**
|
||||||
|
|
||||||
|
| 命令 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `canvas_webview_metrics` | 返回窗口边框尺寸(渲染层据此算「原生层 vs DOM」的坐标原点差) |
|
||||||
|
| `canvas_webview_ensure` | 按节点 id 建子 webview(已存在则只校正 rect / zoom) |
|
||||||
|
| `canvas_webview_bounds` | 位置/尺寸/可见性/缩放,渲染层按需推(热路径) |
|
||||||
|
| `canvas_webview_navigate` | 导航到新地址 |
|
||||||
|
| `canvas_webview_action` | `back` / `forward` / `reload` / `stop` / `close` |
|
||||||
|
| `canvas_webview_state` | 返回 `{ open, url }` |
|
||||||
|
| `canvas_webview_close_all` | 回收全部 `cwv-*` 子 webview(切工作区/退出时) |
|
||||||
|
|
||||||
|
**位置同步的三个坑(宿主 `src/canvas-webview.js` 与 `lib.rs` 里都有注释)**:
|
||||||
|
|
||||||
|
1. 子 webview 的 `LogicalPosition` 以**窗口边框**为原点,DOM 矩形以**内容视图**为原点,
|
||||||
|
差一个标题栏高度(macOS 标准标题栏 32pt)。不补这一下,网页整体上浮压住工具栏。
|
||||||
|
2. macOS 上 `hide()` 之后再 `show()` 会静默失效(都返回 Ok,网页永久不绘制)⇒ 隐藏一律用
|
||||||
|
「挪到窗口外」。
|
||||||
|
3. `get_webview_window("main")` 在出现任何子 webview 之后永久返回 `None` ⇒ 取窗口用
|
||||||
|
`get_window("main")`。
|
||||||
|
|
||||||
|
子 webview 的 label 是 `cwv-<节点id>`,同样不在 capabilities 里 ⇒ 无 IPC 权限。
|
||||||
|
插件把状态写到锚点属性上(`data-iwb-cwv` / `-url` / `-zoom` / `-paused`),
|
||||||
|
宿主读属性驱动原生层,反向则通过 `document` 上的 `iwb-cwv-state` 事件回传加载态与真实地址。
|
||||||
|
|
||||||
|
**没有这些命令的宿主**(例如旧版客户端、或合成测试宿主):`open_browser_window` 会失败,插件自动降级到 `window.open`(系统默认浏览器),不会崩;导航按钮保持禁用。
|
||||||
|
|
||||||
|
## 契约
|
||||||
|
|
||||||
|
- manifest:`id: 'browser'`,`version: '1.4.0'`,`apiVersion: 1`,`capabilities: ['panels', 'nodeTypes']`。
|
||||||
|
- 只注册一个面板与一个节点类型(`web`,无端口,宽 560 / 高 520)。
|
||||||
|
- CSS 在脚本执行时就注入(`#iwb-browser-style`),不依赖面板 mount——避免存档直入时无样式。
|
||||||
|
- 样式用宿主 CSS 变量(`--iwb-text` / `--iwb-layer` / `--iwb-border` 等),带兜底色,明暗主题都能看。
|
||||||
|
|
||||||
|
## 开发 / 测试
|
||||||
|
|
||||||
|
手写单文件 IIFE,`src/index.js` 即产物,无需构建。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run validate # 契约校验
|
||||||
|
node browser/tools/harness.mjs # 本地测试(纯 node,62 项:manifest / 面板 / URL 补全 /
|
||||||
|
# 命令调用 / 回退 / 书签 / 画布节点工具栏 / 缩放框 /
|
||||||
|
# 暂停与恢复 / 状态回填 / 编辑输入不被覆盖)
|
||||||
|
```
|
||||||
|
|
||||||
|
改完从市场重新同步到桌面仓(见根 README「发布到市场」)。**新增插件要上架,必须把 `browser` 加进桌面仓 `sync-plugins-from-repo.js` 的白名单,并在 `plugins/meta.json` 补展示信息**;只在本地开发者模式用则不用。
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/browser",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.7.1",
|
||||||
|
"description": "应用内浏览器:独立窗口打开网页,或在画布节点里内嵌网页(跟随画布缩放,可单独调内容缩放)",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "browser",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,523 @@
|
|||||||
|
// 应用内浏览器插件的本地契约测试(纯 node,不依赖 playwright / 真浏览器)。
|
||||||
|
//
|
||||||
|
// 用最小 DOM / window stub 跑真实 src/index.js(IIFE),验证:
|
||||||
|
// manifest 字段 / 面板注册 / CSS 脚本执行时就注入 / URL 补全与校验 /
|
||||||
|
// 地址栏提交与书签点击都走 open_browser_window 命令 / 命令失败回退 window.open /
|
||||||
|
// 无 Tauri 回退 / 书签自定义解析 /
|
||||||
|
// 导航控制按钮的启用-禁用 / 后退走 browser_control / 状态行显示当前网址 /
|
||||||
|
// 反复 mount 不累积 settings 订阅。
|
||||||
|
//
|
||||||
|
// 运行:node browser/tools/harness.mjs (退出码 0 = 全过)
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import vm from 'node:vm'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
const source = readFileSync(ENTRY, 'utf8')
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const check = (name, ok, detail) => {
|
||||||
|
if (!ok) failed++
|
||||||
|
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 深度按 class 找节点:书签条现在包在 .iwb-browser-bmwrap 里,不再是面板根的子节点
|
||||||
|
const findClass = (root, cls) => {
|
||||||
|
if (!root) return null
|
||||||
|
const queue = [root]
|
||||||
|
while (queue.length) {
|
||||||
|
const n = queue.shift()
|
||||||
|
if (n.className === cls) return n
|
||||||
|
if (Array.isArray(n.children)) queue.push(...n.children)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 极简 DOM stub(带可触发的事件监听) ----------
|
||||||
|
function makeNode(tag) {
|
||||||
|
const node = {
|
||||||
|
tagName: String(tag || 'div').toUpperCase(),
|
||||||
|
style: {},
|
||||||
|
attrs: {},
|
||||||
|
children: [],
|
||||||
|
className: '',
|
||||||
|
_text: '',
|
||||||
|
_listeners: {},
|
||||||
|
classList: {
|
||||||
|
_set: new Set(),
|
||||||
|
add(c) { this._set.add(c) },
|
||||||
|
remove(c) { this._set.delete(c) },
|
||||||
|
contains(c) { return this._set.has(c) },
|
||||||
|
},
|
||||||
|
set textContent(v) { this._text = String(v) },
|
||||||
|
get textContent() { return this._text },
|
||||||
|
setAttribute(k, v) { this.attrs[k] = String(v) },
|
||||||
|
getAttribute(k) { return this.attrs[k] },
|
||||||
|
removeAttribute(k) { delete this.attrs[k] },
|
||||||
|
appendChild(c) { this.children.push(c); return c },
|
||||||
|
addEventListener(name, fn) { (this._listeners[name] || (this._listeners[name] = [])).push(fn) },
|
||||||
|
fire(name, ev) {
|
||||||
|
const e = Object.assign({ preventDefault() {}, stopPropagation() {}, key: '' }, ev || {})
|
||||||
|
;(this._listeners[name] || []).forEach((fn) => fn(e))
|
||||||
|
},
|
||||||
|
value: '',
|
||||||
|
focus() { this._focused = true },
|
||||||
|
blur() { this._focused = false },
|
||||||
|
select() { this._selected = true },
|
||||||
|
set innerHTML(v) { if (v === '') this.children = [] }
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeDom() {
|
||||||
|
const styles = new Map()
|
||||||
|
return {
|
||||||
|
_styles: styles,
|
||||||
|
createElement(tag) { return makeNode(tag) },
|
||||||
|
createTextNode(t) { return { _text: String(t), nodeType: 3 } },
|
||||||
|
_listeners: {},
|
||||||
|
activeElement: null,
|
||||||
|
addEventListener(name, fn) { (this._listeners[name] || (this._listeners[name] = [])).push(fn) },
|
||||||
|
dispatchEvent(ev) { (this._listeners[ev.type] || []).forEach((fn) => fn(ev)); return true },
|
||||||
|
getElementById(id) { return styles.get(id) || null },
|
||||||
|
head: { appendChild(n) { styles.set(n.id, n) } },
|
||||||
|
documentElement: { appendChild(n) { styles.set(n.id, n) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPlugin({ invokeImpl, prefs, canvas } = {}) {
|
||||||
|
const calls = []
|
||||||
|
const doc = makeDom()
|
||||||
|
let registered = null
|
||||||
|
let panel = null
|
||||||
|
let nodeType = null
|
||||||
|
const settings = Object.assign({}, prefs || {})
|
||||||
|
const settingsListeners = []
|
||||||
|
let unsubscribed = 0
|
||||||
|
|
||||||
|
const hostObj = {
|
||||||
|
IWBPluginHost: {
|
||||||
|
register(manifest, factory) {
|
||||||
|
registered = manifest
|
||||||
|
factory({
|
||||||
|
log() {},
|
||||||
|
settings: {
|
||||||
|
get(k) { return settings[k] },
|
||||||
|
onChange(fn) {
|
||||||
|
settingsListeners.push(fn)
|
||||||
|
return function () { unsubscribed++ }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ui: {
|
||||||
|
registerPanel(p) { panel = p }
|
||||||
|
},
|
||||||
|
nodes: {
|
||||||
|
register(v) { nodeType = v; return true }
|
||||||
|
},
|
||||||
|
// 旧宿主没有 canvasWrite:不传 canvas 就是那条路径(ctx.canvas 为 undefined)
|
||||||
|
...(canvas ? { canvas } : {})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
__TAURI__: invokeImpl
|
||||||
|
? { core: { invoke: (name, args) => { calls.push({ name, args }); return invokeImpl(name, args) } } }
|
||||||
|
: undefined,
|
||||||
|
open(url) { calls.push({ name: 'window.open', args: { url } }); return null },
|
||||||
|
URL
|
||||||
|
}
|
||||||
|
const sandbox = {
|
||||||
|
window: hostObj, globalThis: hostObj,
|
||||||
|
document: doc, URL, console, Promise, setTimeout, clearTimeout
|
||||||
|
}
|
||||||
|
vm.runInNewContext(source, sandbox, { filename: 'browser/src/index.js' })
|
||||||
|
return {
|
||||||
|
registered, panel, calls, doc, nodeType,
|
||||||
|
get unsubscribed() { return unsubscribed },
|
||||||
|
fireSetting: (name) => settingsListeners.forEach((fn) => fn(name)),
|
||||||
|
setSetting: (k, v) => { settings[k] = v }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountPanel(panel, doc) {
|
||||||
|
const root = doc.createElement('div')
|
||||||
|
panel.mount(root)
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
const openCalls = (r) => r.calls.filter((c) => c.name === 'open_browser_window')
|
||||||
|
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
|
||||||
|
|
||||||
|
// 默认:打开成功、browser_state 报「窗口未打开」
|
||||||
|
const okInvoke = () => (name) => {
|
||||||
|
if (name === 'browser_state') return Promise.resolve({ open: false, url: '' })
|
||||||
|
return Promise.resolve(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- manifest / 注册 / CSS ----------
|
||||||
|
{
|
||||||
|
const { registered, panel, doc } = runPlugin()
|
||||||
|
check('manifest id = browser', registered && registered.id === 'browser')
|
||||||
|
// 版本号只在一处维护(package.json),断言改为一致性检查,免得每次发版手工改测试
|
||||||
|
const pkgVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
||||||
|
check('manifest version 与 package.json 一致(' + pkgVersion + ')',
|
||||||
|
registered && registered.version === pkgVersion, registered && registered.version)
|
||||||
|
check('manifest apiVersion = 1', registered && registered.apiVersion === 1)
|
||||||
|
check('manifest capabilities = panels + nodeTypes + canvasWrite', registered && JSON.stringify(registered.capabilities) === '["panels","nodeTypes","canvasWrite"]',
|
||||||
|
registered && JSON.stringify(registered.capabilities))
|
||||||
|
check('manifest 声明 bookmarks 设置', registered && !!registered.settings.bookmarks)
|
||||||
|
check('注册了面板 browser-panel', !!panel && panel.id === 'browser-panel' && typeof panel.mount === 'function')
|
||||||
|
check('CSS 在脚本执行时就注入(未 mount 已存在)', doc.getElementById('iwb-browser-style') !== null)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 面板 = 内嵌浏览器(结构) ----------
|
||||||
|
{
|
||||||
|
const { panel, doc } = runPlugin()
|
||||||
|
let mountOk = true
|
||||||
|
let root
|
||||||
|
try { root = mountPanel(panel, doc) } catch (e) { mountOk = false; console.error(e) }
|
||||||
|
check('mount 成功', mountOk)
|
||||||
|
const bar = root && root.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const stage = root && root.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
check('面板换成浏览器工具栏 + 内容区', !!bar && !!stage)
|
||||||
|
const anchorOf = (r) => {
|
||||||
|
const s = r.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
return s && s.children.find((c) => c.attrs['data-iwb-cwv'] === 'panel:browser')
|
||||||
|
}
|
||||||
|
const anchor = anchorOf(root)
|
||||||
|
check('内容区里有原生网页锚点 panel:browser', !!anchor)
|
||||||
|
check('锚点标记 scope=panel(不跟画布缩放)', anchor && anchor.attrs['data-iwb-cwv-scope'] === 'panel')
|
||||||
|
check('未输入网址时锚点不带 url(不建视图)', anchor && anchor.attrs['data-iwb-cwv-url'] === undefined)
|
||||||
|
const strip = findClass(root, 'iwb-browser-strip')
|
||||||
|
const chips = strip ? strip.children.filter((c) => c.className === 'iwb-browser-chip') : []
|
||||||
|
check('底部书签条默认 4 个 chip', chips.length === 4, '实际 ' + chips.length)
|
||||||
|
const closeBtn = bar.children.find((c) => c.attrs.title && c.attrs.title.indexOf('关闭这个网页') >= 0)
|
||||||
|
check('面板隐藏「✕ 关闭这个网页」(关掉面板就等于关闭)', !!closeBtn && closeBtn.style.display === 'none')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 地址栏提交:写锚点属性(不再开独立窗口) ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin({ invokeImpl: okInvoke() })
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const bar = root.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const input = bar.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const stage = root.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const anchor = stage.children.find((c) => c.attrs['data-iwb-cwv'] === 'panel:browser')
|
||||||
|
input.value = 'www.baidu.com'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
check('回车不再调用 open_browser_window(内嵌,不开窗口)', openCalls(r).length === 0, JSON.stringify(r.calls))
|
||||||
|
check('URL 自动补 https 且写进锚点', anchor.attrs['data-iwb-cwv-url'] === 'https://www.baidu.com/',
|
||||||
|
anchor.attrs['data-iwb-cwv-url'])
|
||||||
|
input.value = 'javascript:alert(1)'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
check('非法协议被拒(锚点仍是上一个合法地址)',
|
||||||
|
anchor.attrs['data-iwb-cwv-url'] === 'https://www.baidu.com/', anchor.attrs['data-iwb-cwv-url'])
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 书签点击:导航当前内嵌浏览器 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin({ invokeImpl: okInvoke() })
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const strip = findClass(root, 'iwb-browser-strip')
|
||||||
|
const chips = strip.children.filter((c) => c.className === 'iwb-browser-chip')
|
||||||
|
const stage = root.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const anchor = stage.children.find((c) => c.attrs['data-iwb-cwv'] === 'panel:browser')
|
||||||
|
chips[0].fire('click', {})
|
||||||
|
check('书签点击写锚点 url', !!anchor.attrs['data-iwb-cwv-url'] && /^https:\/\//.test(anchor.attrs['data-iwb-cwv-url']),
|
||||||
|
anchor.attrs['data-iwb-cwv-url'])
|
||||||
|
check('书签点击同样不开独立窗口', openCalls(r).length === 0, JSON.stringify(r.calls))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 面板「↗」:把当前页放到画布上(canvasWrite) ----------
|
||||||
|
{
|
||||||
|
const created = []
|
||||||
|
const r = runPlugin({
|
||||||
|
invokeImpl: okInvoke(),
|
||||||
|
canvas: { createNode: (type, x, y, data) => { created.push({ type, x, y, data }); return 'n-1' } }
|
||||||
|
})
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const bar = root.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const input = bar.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const stage = root.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const anchor = stage.children.find((c) => c.attrs['data-iwb-cwv'] === 'panel:browser')
|
||||||
|
const outBtn = bar.children.find((c) => c.attrs.title && c.attrs.title.indexOf('画布上打开') >= 0)
|
||||||
|
check('面板工具栏有「在画布上打开」按钮', !!outBtn)
|
||||||
|
input.value = 'pinterest.com'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
outBtn.fire('click', {})
|
||||||
|
check('点击后创建了 web 节点', created.length === 1 && created[0].type === 'web',
|
||||||
|
JSON.stringify(created.map((c) => c.type)))
|
||||||
|
check('新节点带上当前网址', created.length === 1 && created[0].data.url === 'https://pinterest.com/',
|
||||||
|
created.length ? created[0].data.url : '(无)')
|
||||||
|
check('新节点不带 paused(默认直接加载)', created.length === 1 && created[0].data.paused === false)
|
||||||
|
check('放到画布时不再开独立窗口', openCalls(r).length === 0, JSON.stringify(r.calls))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 旧宿主(没有 canvasWrite):↗ 回退独立窗口,不报错 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin({ invokeImpl: okInvoke() })
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const bar = root.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const input = bar.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const outBtn = bar.children.find((c) => c.attrs.title && c.attrs.title.indexOf('画布上打开') >= 0)
|
||||||
|
input.value = 'example.com'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
let threw = false
|
||||||
|
try { outBtn.fire('click', {}) } catch (e) { threw = true }
|
||||||
|
check('旧宿主点 ↗ 不抛异常', !threw)
|
||||||
|
check('旧宿主点 ↗ 退回独立窗口', openCalls(r).length === 1, JSON.stringify(r.calls.map((c) => c.name)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 无 Tauri:面板仍可用(内嵌视图由客户端建,插件只写属性) ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin() // 无 __TAURI__
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const bar = root.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const input = bar.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const stage = root.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const anchor = stage.children.find((c) => c.attrs['data-iwb-cwv'] === 'panel:browser')
|
||||||
|
input.value = 'example.com'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
check('无 Tauri 时地址栏仍写入锚点(不弹系统浏览器)',
|
||||||
|
anchor.attrs['data-iwb-cwv-url'] === 'https://example.com/' && r.calls.length === 0,
|
||||||
|
JSON.stringify(r.calls))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 反复 mount 不累积设置订阅 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin()
|
||||||
|
mountPanel(r.panel, r.doc)
|
||||||
|
mountPanel(r.panel, r.doc)
|
||||||
|
mountPanel(r.panel, r.doc)
|
||||||
|
check('重复 mount 会解掉上一个设置订阅(3 次 mount ⇒ 解绑 2 次)', r.unsubscribed === 2, '实际 ' + r.unsubscribed)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 书签数据层(分组 / 排序 / 兼容旧文本) ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin()
|
||||||
|
const spec = r.registered.settings.bookmarks
|
||||||
|
check('书签设置声明为 custom(交给插件自己渲染)', spec.type === 'custom' && typeof spec.render === 'function')
|
||||||
|
const api = spec.api
|
||||||
|
check('插件暴露了书签纯函数(供 harness 断言)', !!api && typeof api.parse === 'function')
|
||||||
|
|
||||||
|
// 空值 ⇒ 默认书签,且落在「常用」一个分组里
|
||||||
|
const d0 = api.parse('')
|
||||||
|
check('空值给默认书签', d0.groups.length === 1 && d0.groups[0].items.length === 4,
|
||||||
|
JSON.stringify(d0.groups.map((g) => g.items.length)))
|
||||||
|
|
||||||
|
// 旧文本(老客户端/老用户)⇒ 自动迁成分组,不丢数据
|
||||||
|
const d1 = api.parse('MDN | developer.mozilla.org\n# 注释行\n\nOpenAI|openai.com')
|
||||||
|
check('旧文本格式迁成一个分组', d1.groups.length === 1 && d1.groups[0].items.length === 2,
|
||||||
|
JSON.stringify(d1.groups.map((g) => g.items.length)))
|
||||||
|
check('迁移后自动补协议', d1.groups[0].items[0].url === 'https://developer.mozilla.org/',
|
||||||
|
d1.groups[0].items[0].url)
|
||||||
|
|
||||||
|
// 新 JSON 结构
|
||||||
|
const src = {
|
||||||
|
v: 2,
|
||||||
|
groups: [
|
||||||
|
{ id: 'g1', name: '设计', items: [{ id: 'i1', title: '花瓣', url: 'huaban.com' }, { id: 'i2', title: 'Behance', url: 'https://www.behance.net/' }] },
|
||||||
|
{ id: 'g2', name: '空组', items: [] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const d2 = api.parse(JSON.stringify(src))
|
||||||
|
check('JSON 分组解析(保留空分组)', d2.groups.length === 2 && d2.groups[1].items.length === 0)
|
||||||
|
check('JSON 里的地址也走 normalizeUrl', d2.groups[0].items[0].url === 'https://huaban.com/', d2.groups[0].items[0].url)
|
||||||
|
check('按分组取书签', api.items(d2, 'g1').length === 2 && api.items(d2, 'g2').length === 0)
|
||||||
|
check('取全部书签', api.items(d2, '').length === 2)
|
||||||
|
|
||||||
|
// 空地址是「没填完的草稿行」:留在设置里,但不出现在面板
|
||||||
|
const d3 = api.normalize({ groups: [{ id: 'g', name: 'x', items: [{ id: 'a', title: '待填', url: '' }, { id: 'b', title: '有', url: 'a.com' }] }] })
|
||||||
|
check('空地址草稿行保留在数据里', d3.groups[0].items.length === 2)
|
||||||
|
check('空地址草稿行不进面板', api.items(d3, '').length === 1)
|
||||||
|
|
||||||
|
// 排序算法
|
||||||
|
const arr = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
|
||||||
|
check('拖动排序:前移到后', api.move(arr.slice(), 0, 2).map((x) => x.id).join('') === 'bca')
|
||||||
|
check('拖动排序:后移到前', api.move(arr.slice(), 2, 0).map((x) => x.id).join('') === 'cab')
|
||||||
|
check('拖动排序:越界不动', api.move(arr.slice(), 0, 9).map((x) => x.id).join('') === 'abc')
|
||||||
|
check('stringify 后再 parse 结构不丢', api.parse(api.stringify(d2)).groups[0].items.length === 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 面板:分组 chip 切换 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin()
|
||||||
|
const twoGroups = {
|
||||||
|
v: 2,
|
||||||
|
groups: [
|
||||||
|
{ id: 'g1', name: '设计', items: [{ id: 'i1', title: '花瓣', url: 'huaban.com' }] },
|
||||||
|
{ id: 'g2', name: '工具', items: [{ id: 'i2', title: 'MDN', url: 'developer.mozilla.org' }, { id: 'i3', title: 'GitHub', url: 'github.com' }] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
r.setSetting('bookmarks', JSON.stringify(twoGroups))
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const gbar = findClass(root, 'iwb-browser-groups')
|
||||||
|
const gchips = gbar ? gbar.children.filter((c) => String(c.className).indexOf('iwb-browser-gchip') === 0) : []
|
||||||
|
check('多分组时出现分组条(全部 + 2 组)', gchips.length === 3, '实际 ' + gchips.length)
|
||||||
|
const strip = findClass(root, 'iwb-browser-strip')
|
||||||
|
const countChips = () => strip.children.filter((c) => c.className === 'iwb-browser-chip').length
|
||||||
|
check('默认显示全部书签', countChips() === 3, '实际 ' + countChips())
|
||||||
|
gchips[2].fire('click', {})
|
||||||
|
check('点分组只显示该组书签', countChips() === 2, '实际 ' + countChips())
|
||||||
|
gchips[1].fire('click', {})
|
||||||
|
check('切到另一组', countChips() === 1, '实际 ' + countChips())
|
||||||
|
gchips[0].fire('click', {})
|
||||||
|
check('回到「全部」', countChips() === 3, '实际 ' + countChips())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 面板:只有一个分组时不显示分组条 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin()
|
||||||
|
const root = mountPanel(r.panel, r.doc)
|
||||||
|
const gbar = findClass(root, 'iwb-browser-groups')
|
||||||
|
check('单分组隐藏分组条', !!gbar && gbar.style.display === 'none')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 画布内网页节点 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin({ invokeImpl: okInvoke() })
|
||||||
|
const nt = r.nodeType
|
||||||
|
check('注册了画布节点类型 web', !!nt && nt.id === 'web' && nt.title === '网页')
|
||||||
|
check('节点类型无端口(网页节点不参与连线)', JSON.stringify(nt.ports) === '{"in":false,"out":false}')
|
||||||
|
check('节点类型默认数据含 url/zoom/paused',
|
||||||
|
nt.defaults && 'url' in nt.defaults && nt.defaults.zoom === 1 && nt.defaults.paused === false,
|
||||||
|
JSON.stringify(nt.defaults))
|
||||||
|
check('节点类型带自定义渲染函数', typeof nt.render === 'function')
|
||||||
|
|
||||||
|
const updates = []
|
||||||
|
const props = { onUpdate(id, patch) { updates.push({ id, patch }) } }
|
||||||
|
const host = r.doc.createElement('div')
|
||||||
|
const node = { id: 'n1', data: { url: '' } }
|
||||||
|
nt.render(node, props, host)
|
||||||
|
|
||||||
|
check('节点体切成 flex 列布局(iwb-cwv-body)', host.classList.contains('iwb-cwv-body'))
|
||||||
|
const bar = host.children.find((c) => c.className === 'iwb-cwv-bar')
|
||||||
|
const stage = host.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
check('节点体含工具栏与内容区', !!bar && !!stage)
|
||||||
|
check('工具栏在内容区之前(原生视图只盖内容区,不会压住按钮)',
|
||||||
|
host.children.indexOf(bar) === 0 && host.children.indexOf(stage) === 1)
|
||||||
|
const anchor = stage && stage.children.find((c) => c.className === 'iwb-cwv-anchor')
|
||||||
|
check('内容区有原生 webview 锚点', !!anchor)
|
||||||
|
check('锚点带节点 id(宿主据此摆位置)', anchor && anchor.attrs['data-iwb-cwv'] === 'n1',
|
||||||
|
anchor && JSON.stringify(anchor.attrs))
|
||||||
|
check('空地址时不写锚点 url', anchor && anchor.attrs['data-iwb-cwv-url'] === undefined)
|
||||||
|
|
||||||
|
const input = bar.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const navBtns = bar.children.filter((c) => c.tagName === 'BUTTON')
|
||||||
|
check('工具栏 5 个动作按钮(← → ⟳ ↗ ✕)', navBtns.length === 5, '实际 ' + navBtns.length)
|
||||||
|
check('地址栏初始禁用全部动作按钮', navBtns.every((b) => b.disabled === true))
|
||||||
|
|
||||||
|
// 缩放设定框:− [100%] +,百分比是可输入的
|
||||||
|
const zoomBox = bar.children.find((c) => c.className === 'iwb-cwv-zoom')
|
||||||
|
const zpct = zoomBox && zoomBox.children.find((c) => c.tagName === 'INPUT')
|
||||||
|
const zoomBtns = zoomBox ? zoomBox.children.filter((c) => c.tagName === 'BUTTON') : []
|
||||||
|
check('工具栏有缩放设定框「− 100% +」',
|
||||||
|
!!zpct && zpct.value === '100%' && zoomBtns.length === 2, zpct && zpct.value)
|
||||||
|
check('缩放框排在地址栏之后、关闭按钮之前',
|
||||||
|
bar.children.indexOf(input) < bar.children.indexOf(zoomBox)
|
||||||
|
&& bar.children.indexOf(zoomBox) < bar.children.indexOf(navBtns[4]))
|
||||||
|
check('锚点默认缩放 1', anchor.attrs['data-iwb-cwv-zoom'] === '1', JSON.stringify(anchor.attrs))
|
||||||
|
|
||||||
|
// 输入网址回车 → 写节点数据 + 立刻更新锚点(不等 React 重渲染)
|
||||||
|
input.value = 'baidu.com'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
check('回车提交写回节点 data.url', updates.length === 1 && updates[0].patch.url === 'https://baidu.com/',
|
||||||
|
JSON.stringify(updates))
|
||||||
|
check('空标题时自动用站点名(多个网页节点才分得清)',
|
||||||
|
updates[0] && updates[0].patch.title === 'baidu.com', JSON.stringify(updates[0] && updates[0].patch))
|
||||||
|
check('回车后锚点 url 同步(宿主下一帧即可导航)',
|
||||||
|
anchor.attrs['data-iwb-cwv-url'] === 'https://baidu.com/', JSON.stringify(anchor.attrs))
|
||||||
|
check('填了网址后动作按钮启用', navBtns.every((b) => b.disabled === false))
|
||||||
|
|
||||||
|
// 控制按钮 → 发 canvas_webview_action(不是 browser_control)
|
||||||
|
navBtns[0].fire('click', {})
|
||||||
|
const acts = r.calls.filter((c) => c.name === 'canvas_webview_action')
|
||||||
|
check('后退按钮走 canvas_webview_action(back)',
|
||||||
|
acts.length === 1 && acts[0].args.action === 'back' && acts[0].args.id === 'n1', JSON.stringify(acts))
|
||||||
|
|
||||||
|
// 缩放:+ 按钮一次 +10%,并把值写回节点;锚点属性立刻更新(宿主下一帧推 zoom)
|
||||||
|
zoomBtns[1].fire('click', {})
|
||||||
|
check('放大按钮把缩放调到 110%', zpct.value === '110%' && anchor.attrs['data-iwb-cwv-zoom'] === '1.1',
|
||||||
|
zpct.value + ' / ' + anchor.attrs['data-iwb-cwv-zoom'])
|
||||||
|
check('缩放值写回节点数据', updates.some((u) => u.patch.zoom === 1.1), JSON.stringify(updates))
|
||||||
|
zoomBtns[0].fire('click', {})
|
||||||
|
check('缩小按钮把缩放调回 100%', zpct.value === '100%', zpct.value)
|
||||||
|
|
||||||
|
// 直接输入百分比
|
||||||
|
zpct.value = '150%'
|
||||||
|
zpct.fire('keydown', { key: 'Enter' })
|
||||||
|
check('缩放框支持直接输入百分比', anchor.attrs['data-iwb-cwv-zoom'] === '1.5', anchor.attrs['data-iwb-cwv-zoom'])
|
||||||
|
zpct.value = '900%'
|
||||||
|
zpct.fire('keydown', { key: 'Enter' })
|
||||||
|
check('缩放上限 300%', anchor.attrs['data-iwb-cwv-zoom'] === '3', anchor.attrs['data-iwb-cwv-zoom'])
|
||||||
|
zpct.value = '10%'
|
||||||
|
zpct.fire('keydown', { key: 'Enter' })
|
||||||
|
check('缩放下限 25%', anchor.attrs['data-iwb-cwv-zoom'] === '0.25', anchor.attrs['data-iwb-cwv-zoom'])
|
||||||
|
|
||||||
|
// ✕ 暂停:写 paused 到锚点与节点数据(宿主要看到它才不会立刻重建视图)
|
||||||
|
const closeBtn = navBtns[4]
|
||||||
|
closeBtn.fire('click', {})
|
||||||
|
check('✕ 把节点标记为 paused(宿主据此关掉视图并保持关闭)',
|
||||||
|
anchor.attrs['data-iwb-cwv-paused'] === '1'
|
||||||
|
&& updates.some((u) => u.patch.paused === true), JSON.stringify(anchor.attrs))
|
||||||
|
check('✕ 之后给出可继续的提示', /已关闭/.test(stage.children.find((c) => c.className === 'iwb-cwv-empty')._text))
|
||||||
|
|
||||||
|
// 暂停态点 ⟳:恢复加载(先解除 paused,再让宿主重建)
|
||||||
|
const beforeResume = r.calls.filter((c) => c.name === 'canvas_webview_action').length
|
||||||
|
navBtns[2].fire('click', {})
|
||||||
|
check('暂停态点 ⟳ 恢复加载(不向已关闭的视图发命令)',
|
||||||
|
anchor.attrs['data-iwb-cwv-paused'] === undefined
|
||||||
|
&& updates.some((u) => u.patch.paused === false)
|
||||||
|
&& r.calls.filter((c) => c.name === 'canvas_webview_action').length === beforeResume,
|
||||||
|
JSON.stringify(updates.slice(-2)))
|
||||||
|
|
||||||
|
// 宿主回报状态:站内跳转后的真实地址要回填地址栏,加载中 ⟳ 变成「停止」
|
||||||
|
r.doc.dispatchEvent({ type: 'iwb-cwv-state', detail: { id: 'n1', loading: true, url: 'https://baidu.com/s?wd=x' } })
|
||||||
|
check('站内跳转后地址栏跟着页面地址走', input.value === 'https://baidu.com/s?wd=x', input.value)
|
||||||
|
check('加载中 ⟳ 变「停止」', navBtns[2].getAttribute('data-act') === 'stop',
|
||||||
|
navBtns[2].getAttribute('data-act'))
|
||||||
|
r.doc.dispatchEvent({ type: 'iwb-cwv-state', detail: { id: 'n1', loading: false, url: 'https://baidu.com/s?wd=x' } })
|
||||||
|
check('加载完成 ⟳ 复原', navBtns[2].getAttribute('data-act') === 'reload')
|
||||||
|
|
||||||
|
// 重渲染不能覆盖正在编辑的输入框(否则每敲一个字都被顶回去)
|
||||||
|
node.data.url = 'https://www.baidu.com/'
|
||||||
|
input.value = 'zhihu.com' // 用户正在输入,还没回车
|
||||||
|
r.doc.activeElement = input
|
||||||
|
nt.render(node, props, host)
|
||||||
|
check('重渲染不覆盖正在编辑的输入', input.value === 'zhihu.com', input.value)
|
||||||
|
|
||||||
|
// 非法地址:标红且不写数据
|
||||||
|
r.doc.activeElement = null
|
||||||
|
const before = updates.length
|
||||||
|
input.value = 'javascript:alert(1)'
|
||||||
|
input.fire('keydown', { key: 'Enter' })
|
||||||
|
check('非法协议被拒绝且不写回', updates.length === before && input.attrs['aria-invalid'] === 'true',
|
||||||
|
JSON.stringify(input.attrs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 无 Tauri 时节点给出明确提示 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin()
|
||||||
|
const nt = r.nodeType
|
||||||
|
const host = r.doc.createElement('div')
|
||||||
|
nt.render({ id: 'n2', data: { url: 'https://www.baidu.com/' } }, { onUpdate() {} }, host)
|
||||||
|
const stage = host.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const empty = stage.children.find((c) => c.className === 'iwb-cwv-empty')
|
||||||
|
check('网页版节点显示「需要桌面客户端」提示', /桌面客户端/.test(empty._text), empty._text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 旧客户端(有 Tauri、但没有画布 webview 引擎)必须提示升级 ----------
|
||||||
|
{
|
||||||
|
const r = runPlugin({ invokeImpl: okInvoke() })
|
||||||
|
const nt = r.nodeType
|
||||||
|
const host = r.doc.createElement('div')
|
||||||
|
nt.render({ id: 'n3', data: { url: 'https://www.baidu.com/' } }, { onUpdate() {} }, host)
|
||||||
|
const stage = host.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
|
const empty = stage.children.find((c) => c.className === 'iwb-cwv-empty')
|
||||||
|
check('旧客户端(无 canvas-webview 引擎)提示升级而不是白屏',
|
||||||
|
/v3\.25\.24|更新客户端/.test(empty._text), empty._text)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n[harness] ' + (failed === 0 ? '全部通过' : failed + ' 项失败'))
|
||||||
|
process.exit(failed === 0 ? 0 : 1)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/gallery",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.6.12",
|
||||||
|
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "gallery",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1,
|
||||||
|
"style": "styles.css"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,571 @@
|
|||||||
|
// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里)
|
||||||
|
//
|
||||||
|
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove)+ panels。
|
||||||
|
// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。
|
||||||
|
// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。
|
||||||
|
;(function (global) {
|
||||||
|
'use strict'
|
||||||
|
if (!global.IWBPluginHost) return
|
||||||
|
|
||||||
|
var PANEL_ID = 'gallery-panel'
|
||||||
|
var DEF = { insertK: '1k', tile: 110, range: '' }
|
||||||
|
// v1.6.2:图幅=**实际显示宽度上限**(此前只当「算列数」用,独列时会被拉到撑满面板,选「小」也很大)
|
||||||
|
// v1.6.3:新增「极小」64px 档(面板窄时想一行看更多图)
|
||||||
|
var TILES = [[64, '极小'], [80, '小'], [110, '中'], [150, '大'], [200, '特大']]
|
||||||
|
var KS = [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']]
|
||||||
|
var RANGES = [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']]
|
||||||
|
|
||||||
|
function el (tag, attrs) {
|
||||||
|
var node = document.createElement(tag)
|
||||||
|
if (attrs) {
|
||||||
|
for (var k in attrs) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(attrs, k)) continue
|
||||||
|
var v = attrs[k]
|
||||||
|
if (v === null || v === undefined) continue
|
||||||
|
if (k === 'class') node.className = v
|
||||||
|
else if (k === 'text') node.textContent = v
|
||||||
|
else if (k === 'style') node.setAttribute('style', v)
|
||||||
|
else node.setAttribute(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 变参子节点(第三位起),支持数组与字符串
|
||||||
|
for (var i = 2; i < arguments.length; i++) append(node, arguments[i])
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
function append (node, v) {
|
||||||
|
if (v === null || v === undefined || v === false) return
|
||||||
|
if (Array.isArray(v)) { for (var i = 0; i < v.length; i++) append(node, v[i]); return }
|
||||||
|
node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v)
|
||||||
|
}
|
||||||
|
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
||||||
|
|
||||||
|
// v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行)
|
||||||
|
var SVG_NS = 'http://www.w3.org/2000/svg'
|
||||||
|
function iconBtn (label, build, title) {
|
||||||
|
var b = el('button', { class: 'iwb-btn iwb-btn-sm iwb-gal-icobtn', title: title || label, 'aria-label': label })
|
||||||
|
var svg = document.createElementNS(SVG_NS, 'svg')
|
||||||
|
svg.setAttribute('viewBox', '0 0 16 16')
|
||||||
|
svg.setAttribute('width', '14')
|
||||||
|
svg.setAttribute('height', '14')
|
||||||
|
svg.setAttribute('fill', 'none')
|
||||||
|
svg.setAttribute('stroke', 'currentColor')
|
||||||
|
svg.setAttribute('stroke-width', '1.5')
|
||||||
|
svg.setAttribute('stroke-linecap', 'round')
|
||||||
|
svg.setAttribute('stroke-linejoin', 'round')
|
||||||
|
svg.setAttribute('aria-hidden', 'true')
|
||||||
|
build(svg)
|
||||||
|
b.appendChild(svg)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
function svgPath (svg, d) {
|
||||||
|
var p = document.createElementNS(SVG_NS, 'path')
|
||||||
|
p.setAttribute('d', d)
|
||||||
|
svg.appendChild(p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
function sel (options, value) {
|
||||||
|
var s = el('select', { class: 'iwb-input iwb-select-compact' })
|
||||||
|
for (var i = 0; i < options.length; i++) {
|
||||||
|
var o = el('option', { value: String(options[i][0]), text: options[i][1] })
|
||||||
|
if (String(options[i][0]) === String(value)) o.selected = true
|
||||||
|
s.appendChild(o)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount (host, ctx) {
|
||||||
|
clear(host)
|
||||||
|
host.classList.add('iwb-plugin-node-body')
|
||||||
|
host.style.minHeight = '0'
|
||||||
|
|
||||||
|
var cfg = Object.assign({}, DEF)
|
||||||
|
var items = []
|
||||||
|
var thumbCache = {}
|
||||||
|
var thumbPending = {} // 进行中的缩略图请求(v1.6.9)
|
||||||
|
var total = 0
|
||||||
|
var limit = 100
|
||||||
|
var picked = {}
|
||||||
|
var gridW = 320
|
||||||
|
var raf = 0
|
||||||
|
var failed = {} // v1.6.0:缩略图仍失败的 name 集合(据此显示「N 张失败」+ 全部重试)
|
||||||
|
|
||||||
|
var head = el('div', { class: 'iwb-gal-head' })
|
||||||
|
var actions = el('div', { class: 'iwb-gal-actions' })
|
||||||
|
head.appendChild(actions)
|
||||||
|
|
||||||
|
var grid = el('div', { class: 'iwb-history-grid' })
|
||||||
|
var empty = el('div', { class: 'iwb-hint', text: '暂无图片 · 运行生图后会出现在这里' })
|
||||||
|
var more = el('div', { class: 'iwb-history-more' })
|
||||||
|
// v1.1.0:底部横栏 —— 左边张数/已选,右边三个设定(右对齐)
|
||||||
|
var countEl = el('span', { class: 'iwb-gal-count', text: '0 / 0 张' })
|
||||||
|
var pickedEl = el('span', { class: 'iwb-gal-sel', text: '' })
|
||||||
|
var statusEl = el('span', { class: 'iwb-gal-status', text: '' })
|
||||||
|
var failEl = el('span', { class: 'iwb-gal-fail', text: '' })
|
||||||
|
failEl.style.display = 'none'
|
||||||
|
failEl.addEventListener('click', function () { retryAll() })
|
||||||
|
var refreshBtn = iconBtn('刷新', function (svg) {
|
||||||
|
svgPath(svg, 'M13.2 6.4A5.4 5.4 0 1 0 13.4 9.4')
|
||||||
|
svgPath(svg, 'M13.2 2.6v3.8H9.4')
|
||||||
|
}, '刷新:重新向宿主拉取图库(图床恢复/外部改动后点这里)')
|
||||||
|
refreshBtn.addEventListener('click', function () { load(true) })
|
||||||
|
// v1.4.0:三个下拉不再占用前台(窄栏放不下、也显乱)——收进「设置」浮层,点按钮才展开。
|
||||||
|
var setBtn = iconBtn('设置', function (svg) {
|
||||||
|
var c1 = document.createElementNS(SVG_NS, 'circle')
|
||||||
|
c1.setAttribute('cx', '8'); c1.setAttribute('cy', '8'); c1.setAttribute('r', '4.2')
|
||||||
|
svg.appendChild(c1)
|
||||||
|
var c2 = document.createElementNS(SVG_NS, 'circle')
|
||||||
|
c2.setAttribute('cx', '8'); c2.setAttribute('cy', '8'); c2.setAttribute('r', '1.6')
|
||||||
|
svg.appendChild(c2)
|
||||||
|
for (var i = 0; i < 8; i++) {
|
||||||
|
var a = i * Math.PI / 4
|
||||||
|
var x1 = (8 + Math.cos(a) * 4.2).toFixed(2)
|
||||||
|
var y1 = (8 + Math.sin(a) * 4.2).toFixed(2)
|
||||||
|
var x2 = (8 + Math.cos(a) * 5.6).toFixed(2)
|
||||||
|
var y2 = (8 + Math.sin(a) * 5.6).toFixed(2)
|
||||||
|
svgPath(svg, 'M' + x1 + ' ' + y1 + 'L' + x2 + ' ' + y2)
|
||||||
|
}
|
||||||
|
}, '图库设置:插入尺寸 / 图幅 / 时间范围')
|
||||||
|
setBtn.classList.add('iwb-gal-setbtn')
|
||||||
|
setBtn.setAttribute('aria-expanded', 'false')
|
||||||
|
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
|
||||||
|
settings.style.display = 'none'
|
||||||
|
// 2026-11-24:底栏加「打开本地图库目录」图标(文件夹),放在设置图标左边;只桌面端可用。
|
||||||
|
var folderBtn = iconBtn('打开本地目录', function (svg) {
|
||||||
|
svgPath(svg, 'M2 4.5h4l1.5 2H14v6.5H2z')
|
||||||
|
}, '在系统文件管理器里打开本地图库目录(images/gallery)')
|
||||||
|
folderBtn.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (!ctx.gallery || typeof ctx.gallery.openFolder !== 'function') { setStatus('仅桌面端可打开本地目录'); return }
|
||||||
|
Promise.resolve(ctx.gallery.openFolder()).then(function (r) {
|
||||||
|
if (r && r.ok === false) setStatus('打开失败:' + ((r && r.error) || '仅桌面端可用'))
|
||||||
|
}).catch(function (err) { setStatus('打开失败:' + ((err && err.message) || err)) })
|
||||||
|
})
|
||||||
|
folderBtn.style.display = (typeof window !== 'undefined' && window.__TAURI__ && window.__TAURI__.core) ? '' : 'none'
|
||||||
|
// v1.4.2:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
|
||||||
|
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, folderBtn, setBtn)
|
||||||
|
var foot = el('div', { class: 'iwb-gal-foot' },
|
||||||
|
el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, failEl, statusEl), tools)
|
||||||
|
var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot, settings])
|
||||||
|
|
||||||
|
function setOpen (open) {
|
||||||
|
settings.style.display = open ? '' : 'none'
|
||||||
|
setBtn.setAttribute('aria-expanded', open ? 'true' : 'false')
|
||||||
|
setBtn.classList.toggle('iwb-gal-setbtn-on', !!open)
|
||||||
|
if (open) document.addEventListener('pointerdown', onDocDown, true)
|
||||||
|
else document.removeEventListener('pointerdown', onDocDown, true)
|
||||||
|
}
|
||||||
|
function onDocDown (e) {
|
||||||
|
if (settings.contains(e.target) || setBtn.contains(e.target)) return
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
setBtn.addEventListener('click', function (e) { e.stopPropagation(); setOpen(settings.style.display === 'none') })
|
||||||
|
host.appendChild(wrap)
|
||||||
|
|
||||||
|
function count () { return Object.keys(picked).length }
|
||||||
|
|
||||||
|
// ---- v1.6.0 右键菜单:单张操作(插入 / 下载 / 预览 / 复制文件名 / 删除)----
|
||||||
|
var menuEl = null
|
||||||
|
function closeMenu () {
|
||||||
|
if (menuEl && menuEl.parentNode) menuEl.parentNode.removeChild(menuEl)
|
||||||
|
menuEl = null
|
||||||
|
document.removeEventListener('pointerdown', onMenuDown, true)
|
||||||
|
document.removeEventListener('keydown', onMenuKey, true)
|
||||||
|
}
|
||||||
|
function onMenuDown (e) { if (menuEl && !menuEl.contains(e.target)) closeMenu() }
|
||||||
|
function onMenuKey (e) { if (e.key === 'Escape') closeMenu() }
|
||||||
|
function openMenu (e, it) {
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
closeMenu()
|
||||||
|
var menu = el('div', { class: 'iwb-ctxmenu iwb-gal-menu', style: 'left:' + e.clientX + 'px;top:' + e.clientY + 'px' })
|
||||||
|
menu.appendChild(el('div', { class: 'iwb-ctx-title', text: it.name }))
|
||||||
|
function item (label, fn) {
|
||||||
|
var b = el('button', { class: 'iwb-ctx-item', text: label })
|
||||||
|
b.addEventListener('click', function (ev) { ev.stopPropagation(); closeMenu(); fn() })
|
||||||
|
menu.appendChild(b)
|
||||||
|
}
|
||||||
|
item('插入画布', function () {
|
||||||
|
Promise.resolve(ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }))
|
||||||
|
.then(function () { setStatus('已插入:' + it.name) })
|
||||||
|
.catch(function () { setStatus('插入失败') })
|
||||||
|
})
|
||||||
|
item('下载', function () { doDownload([it.name]) })
|
||||||
|
item('预览大图', function () { try { ctx.gallery.preview(it.name) } catch (err) { /* ignore */ } })
|
||||||
|
item('复制文件名', function () {
|
||||||
|
try {
|
||||||
|
var p = global.navigator && global.navigator.clipboard && global.navigator.clipboard.writeText(it.name)
|
||||||
|
if (p && p.then) p.then(function () { setStatus('已复制文件名') }).catch(function () { setStatus('复制失败(剪贴板不可用)') })
|
||||||
|
else setStatus('复制失败(剪贴板不可用)')
|
||||||
|
} catch (err) { setStatus('复制失败(剪贴板不可用)') }
|
||||||
|
})
|
||||||
|
item('删除这张', function () {
|
||||||
|
var C = global.IWBUIConfirm
|
||||||
|
var ask = (C && C.askOrNative) ? C.askOrNative('删除「' + it.name + '」?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除「' + it.name + '」?'))
|
||||||
|
ask.then(function (ok) {
|
||||||
|
if (!ok) return
|
||||||
|
items = items.filter(function (x) { return x.name !== it.name })
|
||||||
|
total = Math.max(0, total - 1)
|
||||||
|
delete picked[it.name]
|
||||||
|
render()
|
||||||
|
Promise.resolve(ctx.gallery.remove([it.name])).then(function () { setTimeout(load, 250) }).catch(function () {})
|
||||||
|
}).catch(function () {})
|
||||||
|
})
|
||||||
|
document.body.appendChild(menu)
|
||||||
|
menuEl = menu
|
||||||
|
setTimeout(function () {
|
||||||
|
document.addEventListener('pointerdown', onMenuDown, true)
|
||||||
|
document.addEventListener('keydown', onMenuKey, true)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- v1.6.0 多选拖入画布:宿主 drop 只认单张,这里在捕获阶段接管整批 ----
|
||||||
|
// 仅当 dataTransfer 带 application/x-iwb-gallery-batch 时生效,其余拖放行为完全不变。
|
||||||
|
function onDocDrop (e) {
|
||||||
|
var raw = ''
|
||||||
|
try { raw = (e.dataTransfer && e.dataTransfer.getData('application/x-iwb-gallery-batch')) || '' } catch (err) { return }
|
||||||
|
if (!raw) return
|
||||||
|
var names = []
|
||||||
|
try { names = JSON.parse(raw) } catch (err) { return }
|
||||||
|
if (!names || names.length < 2) return
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
Promise.resolve(ctx.gallery.insert(names, { insertK: cfg.insertK || '1k' })).then(function (r) {
|
||||||
|
if (r && r.ok === false) { setStatus('批量插入失败'); return }
|
||||||
|
setStatus('已插入 ' + names.length + ' 张')
|
||||||
|
}).catch(function () { setStatus('批量插入失败') })
|
||||||
|
}
|
||||||
|
document.addEventListener('drop', onDocDrop, true)
|
||||||
|
// v1.6.0:失败计数集中在底栏;点它 = 全部重试(整墙重挂,重新向宿主取缩略图)
|
||||||
|
function updateFail () {
|
||||||
|
var n = Object.keys(failed).length
|
||||||
|
if (!n) { failEl.style.display = 'none'; failEl.textContent = ''; return }
|
||||||
|
failEl.style.display = ''
|
||||||
|
failEl.textContent = n + ' 张失败 · 重试'
|
||||||
|
failEl.title = '点击重新加载这 ' + n + ' 张的缩略图'
|
||||||
|
}
|
||||||
|
function retryAll () {
|
||||||
|
failed = {}
|
||||||
|
updateFail()
|
||||||
|
setStatus('重试中…')
|
||||||
|
render()
|
||||||
|
}
|
||||||
|
function pickedNames () { return Object.keys(picked) }
|
||||||
|
|
||||||
|
function renderHead () {
|
||||||
|
clear(actions)
|
||||||
|
countEl.textContent = items.length + ' / ' + total + ' 张'
|
||||||
|
pickedEl.textContent = count() ? ('已选 ' + count()) : ''
|
||||||
|
var n = count()
|
||||||
|
function btn (label, title0, fn, need, danger) {
|
||||||
|
var b = el('button', { class: 'iwb-btn iwb-btn-sm' + (danger ? ' iwb-btn-danger' : '') + (need && !n ? ' iwb-gal-off' : ''), text: label, title: need && !n ? '先选中图片' : title0 })
|
||||||
|
b.addEventListener('click', function () { if (need && !n) return; fn() })
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
actions.appendChild(btn('全选', '全选当前筛选结果', function () { for (var i = 0; i < items.length; i++) picked[items[i].name] = 1; render() }))
|
||||||
|
actions.appendChild(btn('反选', '反选当前筛选结果', function () { for (var i = 0; i < items.length; i++) { var k = items[i].name; if (picked[k]) delete picked[k]; else picked[k] = 1 } render() }))
|
||||||
|
actions.appendChild(btn('插入', '把选中的图片插入画布(尺寸按「设置 → 插入尺寸」)', function () {
|
||||||
|
var names = pickedNames()
|
||||||
|
var k = cfg.insertK || '1k'
|
||||||
|
Promise.resolve(ctx.gallery.insert(names, { insertK: k })).then(function (r) {
|
||||||
|
if (r && r.ok === false) { setStatus('插入失败'); return }
|
||||||
|
setStatus('已插入 ' + names.length + ' 张(' + String(k).toUpperCase() + ')')
|
||||||
|
}).catch(function () { setStatus('插入失败') })
|
||||||
|
}, true))
|
||||||
|
actions.appendChild(btn('下载', '下载选中的图片', function () { doDownload(pickedNames()) }, true))
|
||||||
|
actions.appendChild(btn('删除', '删除选中的图片(不可恢复)', function () {
|
||||||
|
var C = global.IWBUIConfirm
|
||||||
|
var ask = C && C.askOrNative ? C.askOrNative('删除选中的 ' + n + ' 张图片?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除选中的 ' + n + ' 张图片?'))
|
||||||
|
var names = pickedNames()
|
||||||
|
ask.then(function (ok) {
|
||||||
|
if (!ok) return
|
||||||
|
// 先本地摘掉,避免删除后还渲染一格「图片已丢失」;随后再向宿主重拉(等它删完+刷新)
|
||||||
|
items = items.filter(function (x) { return names.indexOf(x.name) < 0 })
|
||||||
|
total = Math.max(0, total - names.length)
|
||||||
|
picked = {}
|
||||||
|
render()
|
||||||
|
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
|
||||||
|
setTimeout(load, 250)
|
||||||
|
})
|
||||||
|
}).catch(function () {})
|
||||||
|
}, true, true))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置浮层内容只建一次(不随每次 render 重建,避免下拉被重置)
|
||||||
|
function buildSettings () {
|
||||||
|
clear(settings)
|
||||||
|
settings.appendChild(el('div', { class: 'iwb-gal-settings-title', text: '图库设置' }))
|
||||||
|
function row (key, options, label, hint) {
|
||||||
|
var s = sel(options, cfg[key])
|
||||||
|
s.title = hint || label
|
||||||
|
s.setAttribute('aria-label', label)
|
||||||
|
s.addEventListener('change', function () {
|
||||||
|
cfg[key] = s.value
|
||||||
|
saveCfg()
|
||||||
|
if (key === 'range') { limit = 100; load() } else if (key === 'tile') render()
|
||||||
|
})
|
||||||
|
return el('label', { class: 'iwb-gal-setrow' }, el('span', { class: 'iwb-gal-setlabel', text: label }), s)
|
||||||
|
}
|
||||||
|
settings.appendChild(row('insertK', KS, '插入尺寸', '插入画布时的图片尺寸'))
|
||||||
|
settings.appendChild(row('tile', TILES, '图幅', '图库图片显示宽度'))
|
||||||
|
settings.appendChild(row('range', RANGES, '时间范围', '按生成时间筛选'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderGrid () {
|
||||||
|
clear(grid)
|
||||||
|
var gap = 6
|
||||||
|
// 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值,
|
||||||
|
// 只靠 ResizeObserver 会在「变成 0 再回来」期间漏掉,导致必须拖宽度才出图。
|
||||||
|
var liveW = availableW()
|
||||||
|
if (liveW > 0 && Math.abs(liveW - gridW) > 1) gridW = liveW
|
||||||
|
if (!gridW) gridW = 320
|
||||||
|
var tileW = Math.max(40, Number(cfg.tile) || 110)
|
||||||
|
var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap)))
|
||||||
|
// v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
|
||||||
|
// 以前 min(图幅, 均分) 会留下右侧空白,看起来像没补齐。
|
||||||
|
var colW = Math.max(40, (gridW - gap * (n - 1)) / n)
|
||||||
|
var cols = []
|
||||||
|
var heights = []
|
||||||
|
for (var c = 0; c < n; c++) { cols.push([]); heights.push(0) }
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
var it = items[i]
|
||||||
|
var ratio = (it.w && it.h) ? (it.h / it.w) : 1
|
||||||
|
var min = 0
|
||||||
|
for (var j = 1; j < n; j++) if (heights[j] < heights[min]) min = j
|
||||||
|
cols[min].push(it)
|
||||||
|
heights[min] += colW * ratio + gap
|
||||||
|
}
|
||||||
|
for (var ci = 0; ci < cols.length; ci++) {
|
||||||
|
var col = el('div', { class: 'iwb-history-col', style: 'width:' + Math.round(colW) + 'px;flex:0 0 auto' })
|
||||||
|
for (var k = 0; k < cols[ci].length; k++) col.appendChild(itemNode(cols[ci][k]))
|
||||||
|
grid.appendChild(col)
|
||||||
|
}
|
||||||
|
empty.style.display = items.length ? 'none' : ''
|
||||||
|
clear(more)
|
||||||
|
if (total > items.length) {
|
||||||
|
var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: '显示更多(' + (total - items.length) + ' 张)' })
|
||||||
|
b.addEventListener('click', function () { limit += 100; load() })
|
||||||
|
more.appendChild(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function itemNode (it) {
|
||||||
|
var on = !!picked[it.name]
|
||||||
|
var box = el('div', { class: 'iwb-history-item' + (count() ? ' iwb-history-managed' : '') + (on ? ' iwb-history-selected' : '') })
|
||||||
|
// 缩略图是**异步**的(ctx.gallery.thumb 返回 Promise):先占位,拿到地址再挂 img。
|
||||||
|
// v1.2.0:加载失败自动重试 2 次(图片还没落盘/临时不可读),仍失败才显示可点击重试的占位。
|
||||||
|
box.title = it.name + '(单击单选 · Shift+单击多选 · 双击放大 · 拖到画布=参考图节点)'
|
||||||
|
var holder = el('div', { class: 'iwb-history-missing', text: '加载中…' })
|
||||||
|
box.appendChild(holder)
|
||||||
|
var tries = 0
|
||||||
|
function fail (text) {
|
||||||
|
tries = 999
|
||||||
|
holder.textContent = text || '缩略图加载失败(点击重试)'
|
||||||
|
holder.style.cursor = 'pointer'
|
||||||
|
holder.onclick = function () { failed[it.name] = 1; tries = 0; boot() }
|
||||||
|
failed[it.name] = 1
|
||||||
|
updateFail()
|
||||||
|
}
|
||||||
|
function boot () {
|
||||||
|
if (tries >= 999) return
|
||||||
|
holder.style.cursor = ''
|
||||||
|
holder.onclick = null
|
||||||
|
holder.textContent = '加载中…'
|
||||||
|
// v1.6.9:缩略图地址按名字缓存,且进行中的请求共享同一 Promise ——
|
||||||
|
// 重排/重测会重建 DOM,不共享就会对同一张图重复取 N 次。
|
||||||
|
var key = it.name
|
||||||
|
if (thumbCache[key]) { var u0 = thumbCache[key]; Promise.resolve().then(function () { paint(u0) }).catch(function () { /* ignore */ }); return }
|
||||||
|
if (!thumbPending[key]) {
|
||||||
|
thumbPending[key] = Promise.resolve(ctx.gallery.thumb(key)).then(function (url) {
|
||||||
|
if (url && typeof url === 'string') thumbCache[key] = url
|
||||||
|
delete thumbPending[key]
|
||||||
|
return url
|
||||||
|
}, function (e) { delete thumbPending[key]; throw e })
|
||||||
|
}
|
||||||
|
thumbPending[key].then(paint).catch(function () { fail('缩略图加载失败(点击重试)') })
|
||||||
|
}
|
||||||
|
function paint (url) {
|
||||||
|
if (!url || typeof url !== 'string') { fail('图片已丢失'); return }
|
||||||
|
if (!box.isConnected) return
|
||||||
|
var img = el('img', { src: url, alt: '', loading: 'eager', draggable: 'true' })
|
||||||
|
if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h)
|
||||||
|
img.addEventListener('load', function () {
|
||||||
|
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
||||||
|
if (!img.naturalWidth) { tries++; if (tries <= 2) { setTimeout(boot, 400 * tries); return } if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)'); return }
|
||||||
|
if (holder.parentNode === box) box.replaceChild(img, holder)
|
||||||
|
if (failed[it.name]) { delete failed[it.name]; updateFail() }
|
||||||
|
})
|
||||||
|
img.addEventListener('error', function () {
|
||||||
|
tries++
|
||||||
|
if (tries <= 2) { setTimeout(boot, 400 * tries); return }
|
||||||
|
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||||
|
fail('缩略图加载失败(点击重试)')
|
||||||
|
})
|
||||||
|
img.addEventListener('click', function (e) { pick(it.name, !!(e && e.shiftKey)) })
|
||||||
|
img.addEventListener('dblclick', function () { ctx.gallery.preview(it.name) })
|
||||||
|
img.addEventListener('dragstart', function (e) {
|
||||||
|
try {
|
||||||
|
var names = (picked[it.name] && count() > 1) ? pickedNames() : [it.name]
|
||||||
|
e.dataTransfer.setData('application/x-iwb-localref', names[0])
|
||||||
|
e.dataTransfer.setData('application/x-iwb-gallery-orig', names[0])
|
||||||
|
// 多选:额外带一批名字,由本插件在 document 捕获阶段接管(宿主 drop 只认单张)
|
||||||
|
if (names.length > 1) {
|
||||||
|
e.dataTransfer.setData('application/x-iwb-gallery-batch', JSON.stringify(names))
|
||||||
|
setStatus('拖动 ' + names.length + ' 张')
|
||||||
|
}
|
||||||
|
e.dataTransfer.effectAllowed = 'copy'
|
||||||
|
} catch (err) { /* ignore */ }
|
||||||
|
})
|
||||||
|
img.style.display = 'none'
|
||||||
|
box.appendChild(img)
|
||||||
|
// v1.6.9:坏图/超时兜底 —— 某些坏字节既不触发 load 也不触发 error,700ms 后直接判定失败(可点击重试)
|
||||||
|
setTimeout(function () {
|
||||||
|
try {
|
||||||
|
if (!img.parentNode) return
|
||||||
|
if (img.naturalWidth > 0) return
|
||||||
|
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||||
|
fail('缩略图加载失败(点击重试)')
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
}, 2000)
|
||||||
|
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
|
||||||
|
if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) }
|
||||||
|
else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }
|
||||||
|
}
|
||||||
|
boot()
|
||||||
|
box.addEventListener('contextmenu', function (e) { openMenu(e, it) })
|
||||||
|
var acts = el('div', { class: 'iwb-history-actions' })
|
||||||
|
function act (label, title, fn) {
|
||||||
|
var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: label, title: title })
|
||||||
|
b.addEventListener('click', function (e) { e.stopPropagation(); fn() })
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
acts.appendChild(act('插入', '插入到画布(参考图节点)', function () { ctx.gallery.insert([it.name]).catch(function () {}) }))
|
||||||
|
acts.appendChild(act('下载', '下载到本地', function () { doDownload([it.name]) }))
|
||||||
|
box.appendChild(acts)
|
||||||
|
return box
|
||||||
|
}
|
||||||
|
|
||||||
|
var statusTimer = 0
|
||||||
|
function setStatus (text) {
|
||||||
|
statusEl.textContent = text || ''
|
||||||
|
clearTimeout(statusTimer)
|
||||||
|
if (text) statusTimer = setTimeout(function () { statusEl.textContent = '' }, 4000)
|
||||||
|
}
|
||||||
|
function doDownload (names) {
|
||||||
|
setStatus('下载中…')
|
||||||
|
return Promise.resolve(ctx.gallery.download(names)).then(function (r) {
|
||||||
|
var failed = (r && r.failed) || []
|
||||||
|
var ok = (r && r.count) || 0
|
||||||
|
if (failed.length) setStatus(failed.length + ' 张下载失败,可再点一次重试')
|
||||||
|
else setStatus(ok ? ('已下载 ' + ok + ' 张') : '没有可下载的图片')
|
||||||
|
}).catch(function () { setStatus('下载失败,可再点一次重试') })
|
||||||
|
}
|
||||||
|
|
||||||
|
function pick (name, shift) {
|
||||||
|
if (shift) { if (picked[name]) delete picked[name]; else picked[name] = 1 } else { picked = {}; picked[name] = 1 }
|
||||||
|
render()
|
||||||
|
}
|
||||||
|
|
||||||
|
function render () { renderHead(); renderGrid(); global.requestAnimationFrame(function () { try { measure() } catch (e) {} }); setTimeout(function () { try { measure() } catch (e) {} }, 150) }
|
||||||
|
|
||||||
|
function load (force) {
|
||||||
|
if (force) setStatus('刷新中…')
|
||||||
|
return Promise.resolve(ctx.gallery.list({ range: cfg.range, limit: limit })).then(function (r) {
|
||||||
|
items = (r && r.items) || []
|
||||||
|
total = (r && r.total) || items.length
|
||||||
|
lastLoadAt = Date.now()
|
||||||
|
failed = {}
|
||||||
|
render()
|
||||||
|
}).catch(function () { items = []; total = 0; render() })
|
||||||
|
}
|
||||||
|
|
||||||
|
var saveTimer = 0
|
||||||
|
function saveCfg () {
|
||||||
|
clearTimeout(saveTimer)
|
||||||
|
saveTimer = setTimeout(function () {
|
||||||
|
try { var p = ctx.data && ctx.data.patch({ cfg: cfg }); if (p && p.catch) p.catch(function () {}) } catch (e) { /* 配置存不下不影响使用 */ }
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 宽度测量:列数只由「面板宽 / 图幅」决定
|
||||||
|
// v1.6.5:面板刚挂载时 grid 宽度可能是 0,而 grid 宽度又取决于列宽 → RO 不会触发,图库一直空白。
|
||||||
|
function availableW () {
|
||||||
|
// v1.6.6:优先量「会随面板拉伸的外层容器」,而不是 grid 自身
|
||||||
|
// (grid 现在是 flex-start + 内容宽度,面板变宽它不会变宽 → RO 不触发 → 列数永不补齐)
|
||||||
|
var w = wrap ? wrap.clientWidth : 0
|
||||||
|
if (!w && wrap && wrap.parentNode) w = wrap.parentNode.clientWidth
|
||||||
|
if (!w) w = grid.clientWidth
|
||||||
|
return w || 0
|
||||||
|
}
|
||||||
|
function measure () {
|
||||||
|
var w = availableW()
|
||||||
|
if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() }
|
||||||
|
}
|
||||||
|
var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(function () { measure() }) : null
|
||||||
|
if (ro) { if (wrap) ro.observe(wrap); if (wrap && wrap.parentNode) ro.observe(wrap.parentNode); ro.observe(grid) }
|
||||||
|
measure()
|
||||||
|
var tries = 0
|
||||||
|
function retry () {
|
||||||
|
if (gridW > 0 || tries++ > 40) { if (gridW <= 0) { gridW = Math.max(160, Number(cfg.tile) || 110) * 2; renderGrid() } return }
|
||||||
|
measure()
|
||||||
|
if (gridW <= 0) global.requestAnimationFrame(retry)
|
||||||
|
}
|
||||||
|
global.requestAnimationFrame(retry)
|
||||||
|
// v1.6.7:再补几次延时重测(停靠栏展开动画、首帧布局未完成时能在 1s 内自愈)
|
||||||
|
;[120, 400, 900].forEach(function (ms) { setTimeout(function () { try { measure(); if (gridW > 0) renderGrid() } catch (e) { /* ignore */ } }, ms) })
|
||||||
|
|
||||||
|
// v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次,
|
||||||
|
// 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。
|
||||||
|
var lastLoadAt = 0
|
||||||
|
var autoRefresh = function () {
|
||||||
|
if (Date.now() - lastLoadAt < 5000) return
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (typeof IntersectionObserver === 'function') {
|
||||||
|
var io = new IntersectionObserver(function (entries) {
|
||||||
|
for (var i = 0; i < entries.length; i++) {
|
||||||
|
if (entries[i].isIntersecting) {
|
||||||
|
// v1.6.7:面板真正可见后再量一次宽度并重排(首帧可能还是 0 宽)
|
||||||
|
try { measure(); renderGrid() } catch (e) { /* ignore */ }
|
||||||
|
autoRefresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, { threshold: 0.15 })
|
||||||
|
io.observe(wrap)
|
||||||
|
}
|
||||||
|
document.addEventListener('visibilitychange', function () { if (!document.hidden) autoRefresh() })
|
||||||
|
window.addEventListener('focus', autoRefresh)
|
||||||
|
} catch (e) { /* 环境不支持则只保留手动刷新 */ }
|
||||||
|
|
||||||
|
// 先读配置,再拉列表
|
||||||
|
Promise.resolve(ctx.data && ctx.data.read ? ctx.data.read() : {}).then(function (d) {
|
||||||
|
if (d && d.cfg) cfg = Object.assign({}, DEF, d.cfg)
|
||||||
|
buildSettings() // 设置浮层里的下拉要反映读到的配置
|
||||||
|
return load()
|
||||||
|
}).catch(function () { buildSettings(); load() })
|
||||||
|
|
||||||
|
return function dispose () {
|
||||||
|
if (ro) { try { ro.disconnect() } catch (e) { /* ignore */ } }
|
||||||
|
try { document.removeEventListener('pointerdown', onMenuDown, true) } catch (e) { /* ignore */ }
|
||||||
|
try { document.removeEventListener('keydown', onMenuKey, true) } catch (e) { /* ignore */ }
|
||||||
|
try { document.removeEventListener('drop', onDocDrop, true) } catch (e) { /* ignore */ }
|
||||||
|
closeMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global.IWBPluginHost.register({
|
||||||
|
id: 'gallery',
|
||||||
|
name: '图库',
|
||||||
|
version: '1.6.12',
|
||||||
|
apiVersion: 1,
|
||||||
|
capabilities: ['panels', 'gallery'],
|
||||||
|
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||||
|
}, function (ctx) {
|
||||||
|
ctx.ui.registerPanel({
|
||||||
|
id: PANEL_ID,
|
||||||
|
title: '图库',
|
||||||
|
icon: 'ref',
|
||||||
|
mount: function (host) { return mount(host, ctx) },
|
||||||
|
})
|
||||||
|
return {}
|
||||||
|
})
|
||||||
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/* 图库插件样式(v1.5.0)
|
||||||
|
* 为什么放插件里:宿主 style.css 只在客户端发版时更新,而这里是「设置浮层/图标按钮/紧凑间距」这类
|
||||||
|
* 高频视觉调整——随插件更新即可生效,不必重发桌面端。选择器均带 .iwb-gal-* / .iwb-history-* 前缀,
|
||||||
|
* 且比宿主同名规则更具体(.iwb-gal-foot .iwb-gal-icobtn),宿主旧样式不会盖回来。
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* ---- 面板留白:边缘收小,避免窄栏里浪费空间 ---- */
|
||||||
|
.iwb-history-embedded { padding: 6px 6px 4px; gap: 6px; }
|
||||||
|
.iwb-history-embedded .iwb-history-grid { gap: 6px; padding: 0 0 2px; justify-content: flex-start; }
|
||||||
|
/* 列宽由插件按「图幅」写死(style width),这里禁用宿主的 flex:1 拉伸 */
|
||||||
|
.iwb-history-embedded .iwb-history-col { flex: 0 0 auto; gap: 6px; }
|
||||||
|
|
||||||
|
/* ---- 顶栏 ---- */
|
||||||
|
.iwb-gal-head { display: flex; align-items: center; gap: 6px; min-height: 0; }
|
||||||
|
.iwb-gal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||||
|
.iwb-gal-actions .iwb-btn-sm { padding: 2px 6px; }
|
||||||
|
|
||||||
|
/* ---- 底栏:左信息 / 右工具组 ---- */
|
||||||
|
.iwb-gal-foot {
|
||||||
|
display: flex; align-items: center; justify-content: space-between; gap: 6px;
|
||||||
|
min-width: 0; padding-top: 6px; border-top: 1px solid var(--iwb-border);
|
||||||
|
}
|
||||||
|
.iwb-gal-foot-left { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; overflow: hidden; }
|
||||||
|
.iwb-gal-count { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; }
|
||||||
|
.iwb-gal-sel { font-size: 11px; color: var(--iwb-brand); white-space: nowrap; }
|
||||||
|
.iwb-gal-status { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; max-width: none; }
|
||||||
|
.iwb-gal-tools { display: flex; align-items: center; gap: 0; flex: 0 0 auto; margin-left: auto; }
|
||||||
|
|
||||||
|
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ---- */
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn,
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn:hover,
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn:active {
|
||||||
|
width: 20px; height: 20px; min-width: 20px; padding: 0; box-sizing: border-box;
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
|
||||||
|
border: 0; box-shadow: none; background: transparent; border-radius: 6px;
|
||||||
|
color: var(--iwb-text2); line-height: 1; transform: none;
|
||||||
|
}
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn svg { display: block; pointer-events: none; }
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn:hover { background: var(--iwb-layer2); color: var(--iwb-text); }
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-brand) 60%, transparent); outline-offset: 1px; }
|
||||||
|
.iwb-gal-setbtn-on { color: var(--iwb-brand); background: var(--iwb-layer2); }
|
||||||
|
|
||||||
|
/* ---- 设置浮层(三个下拉不占前台) ---- */
|
||||||
|
.iwb-gal-settings {
|
||||||
|
position: absolute; right: 8px; bottom: 34px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
|
||||||
|
display: flex; flex-direction: column; gap: 8px; padding: 8px 10px;
|
||||||
|
background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 8px;
|
||||||
|
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
|
||||||
|
}
|
||||||
|
.iwb-gal-settings-title { font-size: 11px; font-weight: 600; color: var(--iwb-text2); }
|
||||||
|
.iwb-gal-setrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--iwb-text2); }
|
||||||
|
.iwb-gal-setlabel { flex: 0 0 auto; }
|
||||||
|
.iwb-gal-setrow select { flex: 1 1 auto; width: auto; min-width: 58px; max-width: 92px; height: 22px; font-size: 11px; padding: 0 2px 0 4px; }
|
||||||
|
|
||||||
|
/* ---- 图片墙 ---- */
|
||||||
|
.iwb-history-grid { overscroll-behavior: contain; }
|
||||||
|
.iwb-history-embedded .iwb-history-item { position: relative; flex: none; width: 100%; }
|
||||||
|
.iwb-history-embedded .iwb-history-item img {
|
||||||
|
width: 100%; height: auto; display: block; object-fit: contain; margin: 0 auto;
|
||||||
|
border-radius: 6px; border: 1px solid var(--iwb-border); background: var(--iwb-layer2); cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-history-missing {
|
||||||
|
display: flex; align-items: center; justify-content: center; text-align: center;
|
||||||
|
min-height: 84px; padding: 8px; border-radius: 6px; border: 1px dashed var(--iwb-border);
|
||||||
|
font-size: 11px; color: var(--iwb-text2); background: var(--iwb-layer2); word-break: break-all;
|
||||||
|
}
|
||||||
|
.iwb-history-actions { display: flex; gap: 4px; padding: 4px 2px 0; }
|
||||||
|
.iwb-history-actions .iwb-btn-sm { padding: 2px 6px; font-size: 11px; }
|
||||||
|
.iwb-history-more { display: flex; justify-content: center; padding: 4px 0 2px; }
|
||||||
|
/* 只作用于图库自己的空态提示:不加前缀会泄漏到设置页等使用 .iwb-hint 的地方(文字被居中) */
|
||||||
|
.iwb-history-embedded .iwb-hint { font-size: 11px; color: var(--iwb-text2); text-align: center; padding: 12px 6px; }
|
||||||
|
/* ---- v1.6.0:失败统计 / 右键菜单标题(v1.6.1 去掉搜索框)---- */
|
||||||
|
.iwb-gal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||||
|
.iwb-gal-fail {
|
||||||
|
font-size: 11px; color: var(--iwb-err); cursor: pointer; white-space: nowrap;
|
||||||
|
text-decoration: underline dotted; text-underline-offset: 2px;
|
||||||
|
}
|
||||||
|
.iwb-gal-fail:hover { color: var(--iwb-err); opacity: .85; }
|
||||||
|
.iwb-gal-menu .iwb-ctx-title { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/grouplib",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.5",
|
||||||
|
"description": "节点组:左栏收藏的节点组列表(分组/改名/删除/拖入画布实例化),数据由宿主 grouplib 能力提供",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "grouplib",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,455 @@
|
|||||||
|
// iwb-plugin: 节点组库 —— 左侧「节点组」面板(宿主只提供 ctx.grouplib 数据能力,界面全部在插件里)
|
||||||
|
//
|
||||||
|
// 依赖客户端能力:grouplib(list/save/remove/instantiate/notify/onChanged)+ panels。
|
||||||
|
// 数据仍在宿主持有(收藏的节点组快照 + 分组),插件不存副本,避免两份真相。
|
||||||
|
// 视觉:复用宿主 .iwb-lib-* / .iwb-pcard / .iwb-chip / .iwb-gmgr-* 类名(style.css 已有)。
|
||||||
|
;(function (global) {
|
||||||
|
'use strict'
|
||||||
|
if (!global.IWBPluginHost) return
|
||||||
|
|
||||||
|
var PANEL_ID = 'grouplib-panel'
|
||||||
|
|
||||||
|
function el (tag, attrs) {
|
||||||
|
var node = document.createElement(tag)
|
||||||
|
if (attrs) {
|
||||||
|
for (var k in attrs) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(attrs, k)) continue
|
||||||
|
var v = attrs[k]
|
||||||
|
if (v === null || v === undefined) continue
|
||||||
|
if (k === 'class') node.className = v
|
||||||
|
else if (k === 'text') node.textContent = v
|
||||||
|
else if (k === 'style') node.setAttribute('style', v)
|
||||||
|
else node.setAttribute(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 2; i < arguments.length; i++) append(node, arguments[i])
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
function append (node, v) {
|
||||||
|
if (v === null || v === undefined || v === false) return
|
||||||
|
if (Array.isArray(v)) { for (var i = 0; i < v.length; i++) append(node, v[i]); return }
|
||||||
|
node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v)
|
||||||
|
}
|
||||||
|
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
||||||
|
|
||||||
|
function ask (text, opts) {
|
||||||
|
var C = global.IWBUIConfirm
|
||||||
|
if (C && typeof C.askOrNative === 'function') return C.askOrNative(text, opts)
|
||||||
|
return Promise.resolve(global.confirm(String(text)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount (host, ctx) {
|
||||||
|
clear(host)
|
||||||
|
host.classList.add('iwb-plugin-node-body')
|
||||||
|
host.style.minHeight = '0'
|
||||||
|
|
||||||
|
var list = [] // [{id, name, group, ...snapshot}]
|
||||||
|
var ggroups = [] // [{id, name}]
|
||||||
|
var filter = 'all'
|
||||||
|
var manage = false
|
||||||
|
var picked = {} // id -> 1(管理模式多选)
|
||||||
|
var editing = '' // 正在改名的 id
|
||||||
|
var newOpen = false
|
||||||
|
var managerOpen = false
|
||||||
|
|
||||||
|
var api = ctx.grouplib || {}
|
||||||
|
|
||||||
|
function notify (text, type) { try { api.notify && api.notify(text, type || 'ok') } catch (e) { /* ignore */ } }
|
||||||
|
function groupsOf () {
|
||||||
|
if (ggroups && ggroups.length) return ggroups
|
||||||
|
var seen = []
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
var g = String((list[i] && list[i].group) || '').trim()
|
||||||
|
if (g && !seen.some(function (x) { return x.name === g })) seen.push({ id: g, name: g })
|
||||||
|
}
|
||||||
|
return seen
|
||||||
|
}
|
||||||
|
function save (next, nextGroups) {
|
||||||
|
var groups = next || list
|
||||||
|
var gs = nextGroups || groupsOf()
|
||||||
|
list = groups
|
||||||
|
ggroups = gs
|
||||||
|
render()
|
||||||
|
return Promise.resolve(api.save({ groups: groups, groupGroups: gs })).then(function (r) {
|
||||||
|
if (r && r.ok === false) { notify(r.error || '节点组保存失败,请重试', 'err'); return r }
|
||||||
|
return r || { ok: true }
|
||||||
|
}).catch(function () { notify('节点组保存失败,请重试', 'err') })
|
||||||
|
}
|
||||||
|
|
||||||
|
var body = el('div', { class: 'iwb-lib-body' })
|
||||||
|
var fixed = el('div', { class: 'iwb-lib-fixed' })
|
||||||
|
var scrollBox = el('div', { class: 'iwb-lib-scroll' })
|
||||||
|
var wrap = el('div', { class: 'iwb-groups-embedded' }, body)
|
||||||
|
body.appendChild(fixed)
|
||||||
|
body.appendChild(scrollBox)
|
||||||
|
host.appendChild(wrap)
|
||||||
|
|
||||||
|
var loadError = '' // '' = 正常;否则是给用户看的原因(据此区分「真没收藏」和「能力没拿到」)
|
||||||
|
function load () {
|
||||||
|
if (typeof api.list !== 'function') {
|
||||||
|
loadError = '节点组能力未就绪(客户端需 ≥ 3.25.56)'
|
||||||
|
list = []; ggroups = []
|
||||||
|
render()
|
||||||
|
return Promise.resolve(false)
|
||||||
|
}
|
||||||
|
return Promise.resolve(api.list()).then(function (r) {
|
||||||
|
loadError = ''
|
||||||
|
list = (r && r.groups) || []
|
||||||
|
ggroups = (r && r.groupGroups) || []
|
||||||
|
render()
|
||||||
|
return true
|
||||||
|
}).catch(function (e) {
|
||||||
|
loadError = '读取失败:' + ((e && e.message) || e || '未知错误')
|
||||||
|
list = []; ggroups = []
|
||||||
|
render()
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function countOf (name) {
|
||||||
|
if (name === 'all') return list.length
|
||||||
|
if (name === '__none__') return list.filter(function (g) { return !String((g && g.group) || '').trim() }).length
|
||||||
|
return list.filter(function (g) { return (g && g.group) === name }).length
|
||||||
|
}
|
||||||
|
function visible () {
|
||||||
|
if (filter === '__none__') return list.filter(function (g) { return !String((g && g.group) || '').trim() })
|
||||||
|
if (filter !== 'all') return list.filter(function (g) { return (g && g.group) === filter })
|
||||||
|
return list.slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
function assignGroup (ids, group) {
|
||||||
|
return save(list.map(function (x) { return ids.indexOf(x.id) >= 0 ? Object.assign({}, x, { group: group || '' }) : x }))
|
||||||
|
.then(function () { notify('已移动到' + (group || '未分组')) })
|
||||||
|
}
|
||||||
|
|
||||||
|
function openMenu (e, g) {
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
closeMenu()
|
||||||
|
var menu = el('div', { class: 'iwb-ctxmenu iwb-lib-group-menu', style: 'left:' + e.clientX + 'px;top:' + e.clientY + 'px' })
|
||||||
|
menu.appendChild(el('div', { class: 'iwb-ctx-title', text: '移动到分组' }))
|
||||||
|
var mk = function (label, value) {
|
||||||
|
var b = el('button', { class: 'iwb-ctx-item', text: label })
|
||||||
|
b.addEventListener('click', function () { closeMenu(); assignGroup([g.id], value) })
|
||||||
|
menu.appendChild(b)
|
||||||
|
}
|
||||||
|
mk('未分组', '')
|
||||||
|
groupsOf().forEach(function (gr) { mk(gr.name, gr.name) })
|
||||||
|
document.body.appendChild(menu)
|
||||||
|
menu._iwbOwner = wrap
|
||||||
|
setTimeout(function () { document.addEventListener('pointerdown', onDocDown, true) }, 0)
|
||||||
|
}
|
||||||
|
var openMenuEl = null
|
||||||
|
function closeMenu () {
|
||||||
|
if (openMenuEl && openMenuEl.parentNode) openMenuEl.parentNode.removeChild(openMenuEl)
|
||||||
|
openMenuEl = null
|
||||||
|
document.removeEventListener('pointerdown', onDocDown, true)
|
||||||
|
var old = document.querySelector('.iwb-lib-group-menu')
|
||||||
|
if (old && old.parentNode) old.parentNode.removeChild(old)
|
||||||
|
}
|
||||||
|
function onDocDown (e) {
|
||||||
|
var m = document.querySelector('.iwb-lib-group-menu')
|
||||||
|
if (m && m.contains(e.target)) return
|
||||||
|
closeMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 分组管理弹窗 ----
|
||||||
|
var modalHost = null
|
||||||
|
function openManager () {
|
||||||
|
closeManager()
|
||||||
|
managerOpen = true
|
||||||
|
var mask = el('div', { class: 'iwb-modal-mask' })
|
||||||
|
var modal = el('div', { class: 'iwb-modal iwb-modal-sm' })
|
||||||
|
var head = el('div', { class: 'iwb-modal-head' })
|
||||||
|
var title = el('span', { class: 'iwb-toolbar-title' })
|
||||||
|
var closeBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '关闭', text: '✕' })
|
||||||
|
closeBtn.addEventListener('click', closeManager)
|
||||||
|
head.appendChild(title); head.appendChild(closeBtn)
|
||||||
|
var bodyEl = el('div', { class: 'iwb-modal-body' })
|
||||||
|
modal.appendChild(head); modal.appendChild(bodyEl)
|
||||||
|
mask.appendChild(modal)
|
||||||
|
mask.addEventListener('wheel', function (e) { e.stopPropagation() })
|
||||||
|
mask.addEventListener('pointerdown', function (e) { if (e.target === mask) closeManager() })
|
||||||
|
document.body.appendChild(mask)
|
||||||
|
modalHost = mask
|
||||||
|
renderManager(title, bodyEl)
|
||||||
|
}
|
||||||
|
function closeManager () {
|
||||||
|
managerOpen = false
|
||||||
|
if (modalHost && modalHost.parentNode) modalHost.parentNode.removeChild(modalHost)
|
||||||
|
modalHost = null
|
||||||
|
render()
|
||||||
|
}
|
||||||
|
function renderManager (title, bodyEl) {
|
||||||
|
var gs = groupsOf()
|
||||||
|
title.textContent = '管理节点组分组(' + gs.length + ')'
|
||||||
|
clear(bodyEl)
|
||||||
|
if (!gs.length) bodyEl.appendChild(el('div', { class: 'iwb-hint', text: '暂无分组。可在下方新建。' }))
|
||||||
|
gs.forEach(function (g, i) {
|
||||||
|
var row = el('div', { class: 'iwb-gmgr-row' })
|
||||||
|
var nameEl = el('span', { class: 'iwb-gmgr-name', text: g.name })
|
||||||
|
row.appendChild(nameEl)
|
||||||
|
row.appendChild(el('span', { class: 'iwb-gmgr-count', text: countOf(g.name) + ' 组' }))
|
||||||
|
var rn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '重命名', text: '重命名' })
|
||||||
|
rn.addEventListener('click', function () {
|
||||||
|
var input = el('input', { class: 'iwb-input iwb-grow', value: g.name })
|
||||||
|
row.replaceChild(input, nameEl)
|
||||||
|
input.focus(); input.select()
|
||||||
|
var commit = function () {
|
||||||
|
var n = String(input.value || '').trim()
|
||||||
|
if (!n || n === g.name) { renderManager(title, bodyEl); return }
|
||||||
|
if (groupsOf().some(function (x) { return x.name === n })) { renderManager(title, bodyEl); return }
|
||||||
|
var ng = groupsOf().map(function (x) { return x.name === g.name ? { id: n, name: n } : x })
|
||||||
|
var nl = list.map(function (x) { return x.group === g.name ? Object.assign({}, x, { group: n }) : x })
|
||||||
|
if (filter === g.name) filter = n
|
||||||
|
save(nl, ng).then(function () { if (managerOpen) openManager() })
|
||||||
|
}
|
||||||
|
input.addEventListener('keydown', function (e) {
|
||||||
|
if (e.key === 'Enter') { e.preventDefault(); commit() }
|
||||||
|
if (e.key === 'Escape') renderManager(title, bodyEl)
|
||||||
|
})
|
||||||
|
input.addEventListener('blur', commit)
|
||||||
|
})
|
||||||
|
row.appendChild(rn)
|
||||||
|
var up = el('button', { class: 'iwb-btn iwb-btn-sm', title: '上移', text: '↑' })
|
||||||
|
up.disabled = i === 0
|
||||||
|
up.addEventListener('click', function () { swap(i, -1) })
|
||||||
|
row.appendChild(up)
|
||||||
|
var down = el('button', { class: 'iwb-btn iwb-btn-sm', title: '下移', text: '↓' })
|
||||||
|
down.disabled = i === gs.length - 1
|
||||||
|
down.addEventListener('click', function () { swap(i, 1) })
|
||||||
|
row.appendChild(down)
|
||||||
|
var del = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除分组(组内节点组移至未分组)', text: '删除' })
|
||||||
|
del.addEventListener('click', function () {
|
||||||
|
ask('删除节点组分组「' + g.name + '」?组内节点组将移至「未分组」(不删除节点组)。', { title: '删除分组', okText: '删除' }).then(function (ok) {
|
||||||
|
if (!ok) return
|
||||||
|
var ng = groupsOf().filter(function (x) { return x.name !== g.name })
|
||||||
|
var nl = list.map(function (x) { return x.group === g.name ? Object.assign({}, x, { group: '' }) : x })
|
||||||
|
if (filter === g.name) filter = 'all'
|
||||||
|
save(nl, ng).then(function () { if (managerOpen) openManager() })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
row.appendChild(del)
|
||||||
|
bodyEl.appendChild(row)
|
||||||
|
})
|
||||||
|
var addRow = el('div', { class: 'iwb-row' })
|
||||||
|
var input = el('input', { class: 'iwb-input iwb-grow', placeholder: '新分组名称' })
|
||||||
|
var addBtn = el('button', { class: 'iwb-btn', text: '+ 添加' })
|
||||||
|
var doAdd = function () {
|
||||||
|
var n = String(input.value || '').trim()
|
||||||
|
if (!n) return
|
||||||
|
if (groupsOf().some(function (x) { return x.name === n })) { input.value = ''; return }
|
||||||
|
input.value = ''
|
||||||
|
save(list, groupsOf().concat([{ id: n, name: n }])).then(function () { if (managerOpen) openManager() })
|
||||||
|
}
|
||||||
|
input.addEventListener('keydown', function (e) { if (e.key === 'Enter') doAdd() })
|
||||||
|
addBtn.addEventListener('click', doAdd)
|
||||||
|
addRow.appendChild(input); addRow.appendChild(addBtn)
|
||||||
|
bodyEl.appendChild(addRow)
|
||||||
|
}
|
||||||
|
function swap (i, dir) {
|
||||||
|
var gs = groupsOf().slice()
|
||||||
|
var ni = i + dir
|
||||||
|
if (ni < 0 || ni >= gs.length) return
|
||||||
|
var t = gs[i]; gs[i] = gs[ni]; gs[ni] = t
|
||||||
|
save(list, gs).then(function () { if (managerOpen) openManager() })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 渲染 ----
|
||||||
|
function render () {
|
||||||
|
clear(fixed); clear(scrollBox)
|
||||||
|
var gs = groupsOf()
|
||||||
|
|
||||||
|
var topRow = el('div', { class: 'iwb-row' })
|
||||||
|
var mgBtn = el('button', { class: 'iwb-btn iwb-btn-sm' + (manage ? ' iwb-btn-primary' : ''), text: manage ? '退出管理' : '管理' })
|
||||||
|
mgBtn.addEventListener('click', function () { manage = !manage; picked = {}; render() })
|
||||||
|
topRow.appendChild(mgBtn)
|
||||||
|
var refresh = el('button', { class: 'iwb-btn iwb-btn-sm', title: '重新向宿主拉取节点组', text: '↻' })
|
||||||
|
refresh.addEventListener('click', function () { load() })
|
||||||
|
topRow.appendChild(refresh)
|
||||||
|
if (manage && Object.keys(picked).length) {
|
||||||
|
var mv = el('select', { class: 'iwb-input' })
|
||||||
|
mv.appendChild(el('option', { value: '__move__', text: '移动到分组…' }))
|
||||||
|
mv.appendChild(el('option', { value: '', text: '未分组' }))
|
||||||
|
gs.forEach(function (g) { mv.appendChild(el('option', { value: g.name, text: g.name })) })
|
||||||
|
mv.addEventListener('change', function () {
|
||||||
|
if (mv.value === '__move__') return
|
||||||
|
var ids = Object.keys(picked)
|
||||||
|
picked = {}
|
||||||
|
assignGroup(ids, mv.value)
|
||||||
|
})
|
||||||
|
topRow.appendChild(mv)
|
||||||
|
}
|
||||||
|
fixed.appendChild(topRow)
|
||||||
|
|
||||||
|
// 分类胶囊:宿主 .iwb-lib-chips 是 nowrap(配 .iwb-lib-chips-scroll 才单行滚动),
|
||||||
|
// 分组多时右侧胶囊会被面板宽度裁掉看不见 ⇒ 这里改成「适应面板宽度自动换行」,
|
||||||
|
// 换行规则在插件自带 styles.css 的 .iwb-glp-chips 里(样式随插件发,不用等客户端发版)
|
||||||
|
var chips = el('div', { class: 'iwb-lib-chips iwb-glp-chips' })
|
||||||
|
function chip (label, value, count, extra) {
|
||||||
|
var b = el('button', { class: 'iwb-chip' + (filter === value ? ' iwb-chip-active' : '') + (extra || ''), title: value === '__none__' ? '未分组;拖拽节点组卡片到此 = 移出分组' : (value === 'all' ? '' : '拖拽节点组卡片到此 = 移动到该分组') })
|
||||||
|
b.appendChild(document.createTextNode(label))
|
||||||
|
b.appendChild(el('span', { class: 'iwb-chip-count', text: String(count) }))
|
||||||
|
b.addEventListener('click', function () { newOpen = false; filter = value; render() })
|
||||||
|
b.addEventListener('dragover', function (e) { e.preventDefault(); e.stopPropagation() })
|
||||||
|
b.addEventListener('drop', function (e) {
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
var gid = e.dataTransfer && e.dataTransfer.getData('application/x-iwb-groupid')
|
||||||
|
if (!gid) return
|
||||||
|
assignGroup([gid], value === 'all' || value === '__none__' ? '' : value)
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
chips.appendChild(chip('全部', 'all', list.length))
|
||||||
|
chips.appendChild(chip('未分组', '__none__', countOf('__none__'), ' iwb-chip-drop'))
|
||||||
|
gs.forEach(function (g) { chips.appendChild(chip(g.name, g.name, countOf(g.name), ' iwb-chip-drop')) })
|
||||||
|
var addChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '新建分组', text: '+' })
|
||||||
|
addChip.addEventListener('click', function () { newOpen = !newOpen; render() })
|
||||||
|
chips.appendChild(addChip)
|
||||||
|
var mgChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '管理分组(重命名 / 排序 / 删除)', text: '⚙' })
|
||||||
|
mgChip.addEventListener('click', openManager)
|
||||||
|
chips.appendChild(mgChip)
|
||||||
|
fixed.appendChild(chips)
|
||||||
|
|
||||||
|
if (newOpen) {
|
||||||
|
var row = el('div', { class: 'iwb-row' })
|
||||||
|
var inp = el('input', { class: 'iwb-input iwb-grow', placeholder: '新分组名称' })
|
||||||
|
var ok = el('button', { class: 'iwb-btn iwb-btn-primary', text: '确定' })
|
||||||
|
var no = el('button', { class: 'iwb-btn', text: '取消' })
|
||||||
|
ok.addEventListener('click', function () {
|
||||||
|
var n = String(inp.value || '').trim()
|
||||||
|
if (n && !groupsOf().some(function (x) { return x.name === n })) save(list, groupsOf().concat([{ id: n, name: n }]))
|
||||||
|
filter = n || filter
|
||||||
|
newOpen = false
|
||||||
|
render()
|
||||||
|
})
|
||||||
|
no.addEventListener('click', function () { newOpen = false; render() })
|
||||||
|
inp.addEventListener('keydown', function (e) { if (e.key === 'Enter') ok.click() })
|
||||||
|
row.appendChild(inp); row.appendChild(ok); row.appendChild(no)
|
||||||
|
fixed.appendChild(row)
|
||||||
|
setTimeout(function () { try { inp.focus() } catch (e) { /* ignore */ } }, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 卡片
|
||||||
|
var cards = el('div', { class: 'iwb-lib-cards' })
|
||||||
|
var items = visible()
|
||||||
|
items.forEach(function (g) {
|
||||||
|
var isEditing = editing === g.id
|
||||||
|
var card = el('div', {
|
||||||
|
class: 'iwb-glp-card iwb-pcard' + (isEditing ? ' iwb-pcard-editing' : '') + (manage && picked[g.id] ? ' iwb-pcard-selected' : ''),
|
||||||
|
'data-manage': manage ? '1' : '0',
|
||||||
|
draggable: isEditing ? 'false' : 'true',
|
||||||
|
title: manage ? '单击选中 · 右上「移动到分组」' : '双击改名 · 拖到画布实例化 · 右键移动到分组',
|
||||||
|
})
|
||||||
|
card.addEventListener('dragstart', function (e) {
|
||||||
|
if (isEditing) return
|
||||||
|
try { card.classList.add('iwb-glp-dragging') } catch (err) { /* ignore */ }
|
||||||
|
try {
|
||||||
|
e.stopPropagation()
|
||||||
|
e.dataTransfer.setData('application/x-iwb-group', JSON.stringify(g.id))
|
||||||
|
e.dataTransfer.setData('application/x-iwb-groupid', g.id)
|
||||||
|
e.dataTransfer.effectAllowed = 'copy'
|
||||||
|
} catch (err) { /* ignore */ }
|
||||||
|
})
|
||||||
|
card.addEventListener('dragend', function () {
|
||||||
|
try { card.classList.remove('iwb-glp-dragging') } catch (err) { /* ignore */ }
|
||||||
|
})
|
||||||
|
card.addEventListener('contextmenu', function (e) {
|
||||||
|
if (manage) { e.preventDefault(); picked[g.id] = picked[g.id] ? 0 : 1; render(); return }
|
||||||
|
openMenu(e, g)
|
||||||
|
})
|
||||||
|
card.addEventListener('dblclick', function (e) {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (manage) return
|
||||||
|
editing = g.id
|
||||||
|
render()
|
||||||
|
})
|
||||||
|
|
||||||
|
var rowEl = el('div', { class: 'iwb-row' })
|
||||||
|
if (isEditing) {
|
||||||
|
var input = el('input', { class: 'iwb-input iwb-grow iwb-pname-input', value: g.name || '', placeholder: '组名' })
|
||||||
|
var cancel = false
|
||||||
|
var commit = function () {
|
||||||
|
if (cancel) return
|
||||||
|
editing = ''
|
||||||
|
var n = String(input.value || '').trim() || g.name
|
||||||
|
if (n !== g.name) save(list.map(function (x) { return x.id === g.id ? Object.assign({}, x, { name: n }) : x }))
|
||||||
|
else render()
|
||||||
|
}
|
||||||
|
input.addEventListener('keydown', function (e) {
|
||||||
|
if (e.key === 'Enter') { e.stopPropagation(); commit() }
|
||||||
|
if (e.key === 'Escape') { e.stopPropagation(); cancel = true; editing = ''; render() }
|
||||||
|
})
|
||||||
|
input.addEventListener('blur', commit)
|
||||||
|
rowEl.appendChild(input)
|
||||||
|
setTimeout(function () { try { input.focus(); input.select() } catch (e) { /* ignore */ } }, 0)
|
||||||
|
} else {
|
||||||
|
var nameEl = el('span', { class: 'iwb-pname', title: '双击改名', text: g.name || '分组' })
|
||||||
|
rowEl.appendChild(nameEl)
|
||||||
|
var btns = el('span', { class: 'iwb-pbtns' })
|
||||||
|
var del = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除节点组', text: '✕' })
|
||||||
|
del.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation()
|
||||||
|
ask('删除节点组「' + (g.name || '') + '」?', { title: '删除节点组', okText: '删除' }).then(function (ok) {
|
||||||
|
if (!ok) return
|
||||||
|
list = list.filter(function (x) { return x.id !== g.id })
|
||||||
|
render()
|
||||||
|
Promise.resolve(api.remove(g.id)).catch(function () {})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
btns.appendChild(del)
|
||||||
|
rowEl.appendChild(btns)
|
||||||
|
}
|
||||||
|
card.appendChild(rowEl)
|
||||||
|
if (manage) {
|
||||||
|
card.addEventListener('click', function () {
|
||||||
|
picked[g.id] = picked[g.id] ? 0 : 1
|
||||||
|
if (!picked[g.id]) delete picked[g.id]
|
||||||
|
render()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
card.addEventListener('click', function (e) { e.stopPropagation() })
|
||||||
|
}
|
||||||
|
cards.appendChild(card)
|
||||||
|
})
|
||||||
|
scrollBox.appendChild(cards)
|
||||||
|
if (!items.length) {
|
||||||
|
var hint = loadError
|
||||||
|
? loadError
|
||||||
|
: (list.length
|
||||||
|
? '当前分组下没有节点组(共 ' + list.length + ' 个,切到「全部」查看)'
|
||||||
|
: '宿主返回 0 个收藏节点组。画布编组后点组右上角「收藏」,或用右键菜单「收藏选中节点」。')
|
||||||
|
scrollBox.appendChild(el('div', { class: 'iwb-hint iwb-glp-empty', text: hint }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 宿主侧变化(画布收藏节点组 / 其它标签页同步)→ 重拉
|
||||||
|
var off = null
|
||||||
|
try { off = api.onChanged && api.onChanged(function () { load() }) } catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
load()
|
||||||
|
|
||||||
|
return function dispose () {
|
||||||
|
try { if (typeof off === 'function') off() } catch (e) { /* ignore */ }
|
||||||
|
closeMenu()
|
||||||
|
if (modalHost && modalHost.parentNode) modalHost.parentNode.removeChild(modalHost)
|
||||||
|
modalHost = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global.IWBPluginHost.register({
|
||||||
|
id: 'grouplib',
|
||||||
|
name: '节点组',
|
||||||
|
version: '1.0.5',
|
||||||
|
apiVersion: 1,
|
||||||
|
capabilities: ['panels', 'grouplib'],
|
||||||
|
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||||
|
}, function (ctx) {
|
||||||
|
ctx.ui.registerPanel({
|
||||||
|
id: PANEL_ID,
|
||||||
|
title: '节点组',
|
||||||
|
icon: 'group',
|
||||||
|
// 宿主只调用 mount(node)(一个参数):必须在这里把工厂 ctx 注入,否则面板里 ctx 是 undefined ⇒ 首渲染抛异常 ⇒ 整块空白
|
||||||
|
mount: function (host) { return mount(host, ctx) },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* grouplib(节点组)自带样式
|
||||||
|
作用域全部带 .iwb-glp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||||
|
|
||||||
|
/* 分类胶囊「适应面板宽度」自动换行。
|
||||||
|
宿主的 .iwb-lib-chips 是 flex-wrap: nowrap(配合 .iwb-lib-chips-scroll 才做单行横向滚动),
|
||||||
|
分组多时右侧胶囊会被面板宽度裁掉、看不见也用不了。
|
||||||
|
这里用双类选择器提高优先级(不依赖样式注入顺序),让它按宽度折行。 */
|
||||||
|
.iwb-lib-chips.iwb-glp-chips {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
row-gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* + / ⚙ 是动作按钮,不是分组名:不参与压缩,并与最后一个分组稍作分隔 */
|
||||||
|
.iwb-glp-chips .iwb-glp-add {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* v1.0.4(2026-11-21):卡片交互态 + 空态 + 拖拽反馈。
|
||||||
|
颜色只走宿主 token(--iwb-plugin-* / --iwb-*),不写死。 */
|
||||||
|
.iwb-glp-card { transition: background .12s ease, border-color .12s ease; }
|
||||||
|
.iwb-glp-card .iwb-pname { font-weight: 600; }
|
||||||
|
/* 删除按钮:平时隐藏,悬停/键盘聚焦才出现,减少视觉噪音 */
|
||||||
|
.iwb-glp-card .iwb-pbtns { opacity: 0; transition: opacity .12s ease; }
|
||||||
|
.iwb-glp-card:hover .iwb-pbtns,
|
||||||
|
.iwb-glp-card:focus-within .iwb-pbtns { opacity: 1; }
|
||||||
|
/* 管理模式的选中标记:右上角圆点 */
|
||||||
|
.iwb-glp-card[data-manage="1"]::after {
|
||||||
|
content: ''; position: absolute; right: 8px; top: 8px; width: 12px; height: 12px;
|
||||||
|
border-radius: 50%; border: 1.5px solid var(--iwb-border2, #b9bfca); background: transparent;
|
||||||
|
}
|
||||||
|
.iwb-glp-card[data-manage="1"].iwb-pcard-selected::after {
|
||||||
|
background: var(--iwb-brand, #6b7280); border-color: var(--iwb-brand, #6b7280);
|
||||||
|
}
|
||||||
|
/* 拖拽中:半透明 + 轻微缩放,明确"正在搬运" */
|
||||||
|
.iwb-glp-dragging { opacity: .55; }
|
||||||
|
/* 空态:虚线框 */
|
||||||
|
.iwb-glp-empty {
|
||||||
|
margin: 4px 0; padding: 12px 12px; border-radius: 10px; text-align: center;
|
||||||
|
border: 1px dashed var(--iwb-border2, #b9bfca); color: var(--iwb-text2, #4d5668);
|
||||||
|
font-size: 12px; line-height: 1.7;
|
||||||
|
}
|
||||||
+40
-45
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
### 移植改动之一:CSP 适配
|
### 移植改动之一:CSP 适配
|
||||||
`plugin/editor/dom.js` 的 `loadImage()`:上游用 `fetch(dataURL)` 把 dataURL 转成 blob URL(避免 `img.src` 在整个编辑会话里
|
`plugin/editor/dom.js` 的 `loadImage()`:上游用 `fetch(dataURL)` 把 dataURL 转成 blob URL(避免 `img.src` 在整个编辑会话里
|
||||||
持有几十 MB 的 base64 字符串)。但宿主 CSP 是 `connect-src 'self' https: …`,**不含 `data:`** ⇒ `fetch(data:)` 必被浏览器拦,
|
持有几十 MB 的 base64 字符串)。合成宿主的 CSP 常把 `connect-src` 限为 `'self' https:`、**不含 `data:`** ⇒ `fetch(data:)` 被拦
|
||||||
每次打开编辑器都产生一次 CSP 违规(上游的 `catch` 回退让它「还能用」,所以功能看起来正常、只在控制台报错)。
|
(桌面客户端的 CSP 含 `data:`,但测试用的合成宿主按更严策略跑,故仍按最严口径处理)。
|
||||||
现改为**纯本地解码**(`atob` → `Uint8Array` → `Blob` → blob URL),与上游行为一致(同样拿到 blob URL),且不依赖 CSP/网络。
|
现改为**纯本地解码**(`atob` → `Uint8Array` → `Blob` → blob URL),与上游行为一致(同样拿到 blob URL),且不依赖 CSP/网络。
|
||||||
> 这类问题**只有带 CSP 的真站能测出来**(无 CSP 的 mock 页永远绿)。真实站点用例见 `image-annotate/tools/e2e-site.mjs`。
|
> 这类问题**只有带 CSP 的真机/合成宿主能测出来**(无 CSP 的 mock 页永远绿)。用例见 `image-annotate/tools/e2e-site.mjs`。
|
||||||
|
|
||||||
### v1.1:选区、便利版 UI、单张输出
|
### v1.1:选区、便利版 UI、单张输出
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
侧栏保留调色板全量 + 笔刷大小(滑杆/数字/快捷点)+ 缩放行。
|
侧栏保留调色板全量 + 笔刷大小(滑杆/数字/快捷点)+ 缩放行。
|
||||||
|
|
||||||
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,79 项);
|
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,79 项);
|
||||||
`node image-annotate/tools/e2e-site.mjs`(真站 CSP/SRI,发布后)。
|
`node image-annotate/tools/e2e-site.mjs`(桌面客户端 CSP/SRI,发布后)。
|
||||||
|
|
||||||
## v1.2.2
|
## v1.2.2
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ content 只有 416px,文字工具多出「底色」tab 时已经超出 3px —
|
|||||||
去色不再隐藏,竖线也就没有「悬空」问题,头部结构变成纯静态。
|
去色不再隐藏,竖线也就没有「悬空」问题,头部结构变成纯静态。
|
||||||
|
|
||||||
测试:harness 231 项(新增「去色是第一格 / 加底色 tab 后头部纹丝不动 / 文字色下去色置灰」3 条,
|
测试:harness 231 项(新增「去色是第一格 / 加底色 tab 后头部纹丝不动 / 文字色下去色置灰」3 条,
|
||||||
另有 4 条旧断言从看 `.hidden` 改成看 `.disabled`);真站 e2e 40 项(改为校验 `noneFirst` + 15 色)。
|
另有 4 条旧断言从看 `.hidden` 改成看 `.disabled`);桌面客户端 e2e 40 项(改为校验 `noneFirst` + 15 色)。
|
||||||
|
|
||||||
## v1.19.0:右栏调色模块退场 / 头部一行装完 / 常用色 16 个 + 最近两排
|
## v1.19.0:右栏调色模块退场 / 头部一行装完 / 常用色 16 个 + 最近两排
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ content 只有 416px,文字工具多出「底色」tab 时已经超出 3px —
|
|||||||
- **分隔线从 `#313244` 提到 `#3b3b4e`**。没有小标题时,这条线是唯一能看出「常用 / 最近」分界的东西,
|
- **分隔线从 `#313244` 提到 `#3b3b4e`**。没有小标题时,这条线是唯一能看出「常用 / 最近」分界的东西,
|
||||||
按原色画在深底上几乎看不见。
|
按原色画在深底上几乎看不见。
|
||||||
|
|
||||||
**验证**:harness 229 项、真站 e2e 40 项全绿。新增 harness 断言:头部四个控件同一水平线 + 去色在图钉左边 +
|
**验证**:harness 229 项、桌面客户端 e2e 40 项全绿。新增 harness 断言:头部四个控件同一水平线 + 去色在图钉左边 +
|
||||||
两者之间有竖线 + 三 tab(文字工具)时头部不横向溢出、常用色 16 个严格 8 列 2 行、最近色网格 8 列 2 排、
|
两者之间有竖线 + 三 tab(文字工具)时头部不横向溢出、常用色 16 个严格 8 列 2 行、最近色网格 8 列 2 排、
|
||||||
弹层宽高区间、右栏第一个模块是「图片调节」且无 `[data-color-surface]`。
|
弹层宽高区间、右栏第一个模块是「图片调节」且无 `[data-color-surface]`。
|
||||||
|
|
||||||
@@ -607,10 +607,10 @@ applyTextStyle(textBtn.dataset.optText, textBtn.dataset.value, true)
|
|||||||
|
|
||||||
三条硬约束:
|
三条硬约束:
|
||||||
|
|
||||||
1. **CSP 拦死了第三方字体**。宿主 `_headers` 是 `default-src 'self'`,`font-src` 回落它,
|
1. **CSP 不放行第三方字体**。桌面宿主 CSP 是 `default-src 'self'`,`font-src` 只放行 `data:`,
|
||||||
`https:` 只放给了 `img-src` / `connect-src`。Google Fonts 或任何字体 CDN 都会被浏览器直接拒绝。
|
不放行 `https:`。Google Fonts 或任何字体 CDN 都会被拦。
|
||||||
2. **中文字体太大**。本机参照:宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB;插件产物现在 392KB,
|
2. **中文字体太大**。本机参照:宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB;插件产物现在 392KB,
|
||||||
内联等于涨 5–150 倍。子集化到 3500 常用字约 0.8–1.5MB/个,能接受,但要放宿主静态目录,
|
内联等于涨 5–150 倍。子集化到 3500 常用字约 0.8–1.5MB/个,能接受,但要改宿主 CSP/资源,
|
||||||
发布链得一起改。
|
发布链得一起改。
|
||||||
3. **异步字体的时序坑**。Web 字体异步加载,字体没 ready 就 `measureText`,量出来的是 fallback
|
3. **异步字体的时序坑**。Web 字体异步加载,字体没 ready 就 `measureText`,量出来的是 fallback
|
||||||
的宽度 —— 选中框和实际字形错位,导出还可能画成 fallback。系统字体同步可用,没有这个问题。
|
的宽度 —— 选中框和实际字形错位,导出还可能画成 fallback。系统字体同步可用,没有这个问题。
|
||||||
@@ -956,11 +956,11 @@ Esc 取消不留空对象、选择工具未选中仍有 3 个图标、只选颜
|
|||||||
顶栏「导出」左边新增「复制」:把当前结果编码成 PNG 塞进 `ClipboardItem`,
|
顶栏「导出」左边新增「复制」:把当前结果编码成 PNG 塞进 `ClipboardItem`,
|
||||||
可直接粘到聊天窗口 / 后台上传框,**不关闭编辑器**。
|
可直接粘到聊天窗口 / 后台上传框,**不关闭编辑器**。
|
||||||
|
|
||||||
- 走 `toPngBlob()`,优先 `createImageBitmap` —— 宿主页 CSP 常禁 `img-src: blob:`,
|
- 走 `toPngBlob()`,优先 `createImageBitmap` —— 稳妥起见不依赖 `img-src: blob:` 放行
|
||||||
用 `new Image()` 解码会直接失败。
|
(合成宿主的 CSP 常禁 blob:,用 `new Image()` 解码会失败)。
|
||||||
- 失败必须**说清楚**:非安全上下文(如 `about:blank`)没有 `navigator.clipboard`,
|
- 失败必须**说清楚**:非安全上下文(如 `about:blank`)没有 `navigator.clipboard`,
|
||||||
提示「当前浏览器不支持复制图片,请用「导出」下载」,而不是静默无反应。
|
提示「当前环境不支持复制图片,请用「导出」下载」,而不是静默无反应。
|
||||||
真实 https / localhost 下已验证可用(`navigator.clipboard.read()` 能读回 `image/png`)。
|
桌面客户端下已验证可用(`navigator.clipboard.read()` 能读回 `image/png`)。
|
||||||
|
|
||||||
### 两条踩过的坑
|
### 两条踩过的坑
|
||||||
|
|
||||||
@@ -977,7 +977,7 @@ Esc 取消不留空对象、选择工具未选中仍有 3 个图标、只选颜
|
|||||||
|
|
||||||
## v1.8.3:图层面板交互修复(滑杆能拖、图层能拖排)
|
## v1.8.3:图层面板交互修复(滑杆能拖、图层能拖排)
|
||||||
|
|
||||||
线上两个反馈,根子在同一个属性上:
|
用户反馈的两个问题,根子在同一个属性上:
|
||||||
|
|
||||||
1. **不透明度滑杆只能点、不能拖** —— 点了滑杆轨道数值会跳,但按住拖动毫无反应。
|
1. **不透明度滑杆只能点、不能拖** —— 点了滑杆轨道数值会跳,但按住拖动毫无反应。
|
||||||
2. **图层拖不动排序** —— 拖了松手顺序不变,看起来像没实现。
|
2. **图层拖不动排序** —— 拖了松手顺序不变,看起来像没实现。
|
||||||
@@ -1044,17 +1044,14 @@ harness 里专门有一条用例守着它。
|
|||||||
|
|
||||||
## v1.8.1:修复 SRI 加载失败(发布通道改内容寻址)
|
## v1.8.1:修复 SRI 加载失败(发布通道改内容寻址)
|
||||||
|
|
||||||
v1.8.0 上线后线上报「脚本完整性校验失败(integrity 不符或加载失败)」,插件直接不可用。
|
v1.8.0 上线后报「脚本完整性校验失败(integrity 不符或加载失败)」,插件直接不可用。
|
||||||
|
|
||||||
原因不在插件代码,在发布通道:`scripts/plugins-publish.sh` 用的是**固定文件名**
|
原因不在插件代码,在发布通道:早期用的是**固定文件名** `plugin-image-annotate.js`,
|
||||||
`plugin-image-annotate.js`,而清单里的 `integrity` 随内容每次变化。
|
而清单里的 `integrity` 随内容每次变化。客户端只要还留着旧字节,新 integrity 就对不上 ⇒ SRI 判失败。
|
||||||
客户端只要还留着旧字节(浏览器磁盘/内存缓存、中间代理),新 integrity 就对不上 ⇒ SRI 判失败。
|
|
||||||
`no-cache + ETag` 的语义只是「可缓存但须回源校验」,管不住已经骗到手的旧副本。
|
|
||||||
|
|
||||||
修法:文件名改为内容寻址 `plugin-image-annotate.<sha256前12位>.js`,与 `plugins-publish.mjs`
|
修法:文件名改为内容寻址 `plugin-image-annotate.<sha256前12位>.js`。内容变 ⇒ 文件名变 ⇒
|
||||||
的 `storedNameOf` 对齐。内容变 ⇒ 文件名变 ⇒ 新版本必然是新 URL,SRI 必中;
|
新版本必然是新 URL,SRI 必中。这正是现在桌面仓同步脚本 `sync-plugins-from-repo.js` 的做法
|
||||||
同时命中 Functions 的 `IMMUTABLE_JS_RE`,拿到 `public, max-age=31536000, immutable`,
|
(它按 sha256 前 12 位命名并重建带 SRI 的清单),所以这条坑不会再踩。
|
||||||
355KB 的产物不必每次 304 回源协商。
|
|
||||||
|
|
||||||
插件本体代码与 v1.8.0 逐字相同,`src/index.js` 只有 manifest 里的版本号不同。
|
插件本体代码与 v1.8.0 逐字相同,`src/index.js` 只有 manifest 里的版本号不同。
|
||||||
|
|
||||||
@@ -1197,35 +1194,33 @@ npm run validate # 契约校验
|
|||||||
|
|
||||||
> 注意:banner 的**注释**里也不能出现 id + 冒号 + 单引号的组合,否则会被校验器当成 manifest 抢走(踩过一次)。
|
> 注意:banner 的**注释**里也不能出现 id + 冒号 + 单引号的组合,否则会被校验器当成 manifest 抢走(踩过一次)。
|
||||||
|
|
||||||
## 发布(按 HANDBOOK 第八节:先提交 → 合主干 → 再发布)
|
## 发布
|
||||||
|
源码与产物先提交进本仓(`src/index.js` 是 esbuild 产物,必须提交;CI 只校验不构建):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1) 源码与产物先落库,并确保 HEAD 已在 origin/main(脚本会强制校验这两条)
|
|
||||||
cd /Users/qiqi/open/github/iwb-plugins
|
|
||||||
npm run build -- image-annotate && npm run validate
|
npm run build -- image-annotate && npm run validate
|
||||||
git add image-annotate && git commit -m "feat(image-annotate): v1.7.0 ..." && git push
|
# 提交并推送本仓改动
|
||||||
git switch main && git merge --ff-only <你的分支> && git push
|
|
||||||
|
|
||||||
# 2) 用带守卫的发布脚本(旧 plugins-publish.mjs 会绕过校验,不要再用)
|
|
||||||
cd /Users/qiqi/open/github/image-workbench-web
|
|
||||||
scripts/plugins-publish.sh image-annotate \
|
|
||||||
/Users/qiqi/open/github/iwb-plugins/image-annotate/src/index.js 1.7.0
|
|
||||||
|
|
||||||
# 3) 脚本会打 annotated tag 但不会推,手动补
|
|
||||||
git -C /Users/qiqi/open/github/iwb-plugins push origin [email protected]
|
|
||||||
```
|
```
|
||||||
脚本的三道前置校验:工作区干净、HEAD 是 `origin/main` 的祖先、`wrangler.toml` 有 KV namespace。
|
|
||||||
任一条不满足直接拒发(紧急热修才用 `IWB_PUBLISH_SKIP_CHECKS=1`,事后必须补合并与 tag)。
|
|
||||||
|
|
||||||
发布脚本**默认与线上清单合并**(本次没传的插件原样保留),只传自己的文件即可;`--remove` 才是从清单移除。
|
再走桌面仓的市场链路(见根 README「发布到市场」):
|
||||||
版本两处一起改:`package.json`(构建时注入 manifest)+ 脚本第 3 个参数。上传后回读校验清单与本地一致。
|
|
||||||
发布后刷新即生效(KV 为测试站/正式站共享;新插件在插件管理里**默认未启用**,需手动开启)。
|
```bash
|
||||||
|
cd /Users/qiqi/open/github/image-workbench-desktop
|
||||||
|
node scripts/sync-plugins-from-repo.js # 内容寻址命名 + SRI,重建清单
|
||||||
|
node scripts/gen-market.js # 生成 market/index.json
|
||||||
|
# 把 market/ 上传到 NAS /vol8/web/iwb-market/(market.maqiart.eu.org)
|
||||||
|
```
|
||||||
|
|
||||||
|
桌面仓同步脚本按白名单一次重建全部插件清单,新版本文件名随内容哈希变化 ⇒ 不会撞旧 SRI。
|
||||||
|
版本以 `package.json` 为准(构建时注入 manifest),改版本后重新构建再提交。
|
||||||
|
发布后回读市场索引确认版本与哈希已更新,再在客户端市场安装验证——不能只看命令退出码。
|
||||||
|
|
||||||
## 验证(可选,开发用)
|
## 验证(可选,开发用)
|
||||||
`tools/e2e-site.mjs`:**带 CSP 的真实站点**端到端(真 KV 加载 + 浏览器 SRI + 漂浮菜单 → 编辑器 → 覆盖/新建),
|
`tools/e2e-site.mjs`:**桌面客户端**端到端(市场安装 + SRI + 漂浮菜单 → 编辑器 → 覆盖/新建),
|
||||||
另含 v1.0.5 的图层顺序回归:画图形 + 粘贴截图 → 唯一高亮、点重叠区选中最上层截图、四个排序按钮逐一生效、原图始终在最底。
|
另含 v1.0.5 的图层顺序回归:画图形 + 粘贴截图 → 唯一高亮、点重叠区选中最上层截图、四个排序按钮逐一生效、原图始终在最底。
|
||||||
需要 Playwright(可从宿主仓 `node_modules` 或全局解析),**不进 CI**(本仓 CI 只跑 `npm run validate`,不联网、无依赖)。
|
需要 Playwright(可从桌面仓 `node_modules` 或全局解析),**不进 CI**(本仓 CI 只跑 `npm run validate`,不联网、无依赖)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
IWB_BASE_URL=https://test.image-workbench-web.pages.dev node image-annotate/tools/e2e-site.mjs
|
node image-annotate/tools/e2e-site.mjs
|
||||||
```
|
```
|
||||||
> 为什么值得留着:mock 页没有 CSP,`connect-src` 类问题(如 `fetch(dataURL)`)在 mock 下永远绿,只有真站能抓出来。
|
> 为什么值得留着:mock 页没有 CSP,`connect-src` 类问题(如 `fetch(dataURL)`)在 mock 下永远绿,只有真机能抓出来。
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# 简化版 PS(Image Editor Lite)目标与实施分析
|
# 简化版 PS(Image Editor Lite)目标与实施分析
|
||||||
|
|
||||||
> 基线:`image-annotate` v1.0.5(`plugin-image-annotate.cfecb6e2ec17.js`),宿主 `image-workbench-web` 插件 API v1。
|
> 基线:`image-annotate` v1.0.5(`plugin-image-annotate.cfecb6e2ec17.js`),桌面宿主 `image-workbench-desktop` 插件 API v1。
|
||||||
> 本文只做目标定义、差距分析、UI/架构/分期设计,**不含代码改动**。改动前先确认文末「待拍板」一节。
|
> 本文只做目标定义、差距分析、UI/架构/分期设计,**不含代码改动**。改动前先确认文末「待拍板」一节。
|
||||||
>
|
>
|
||||||
> **范围裁定(用户确认)**:只做**单张图片**的编辑与输出,**不做批量出图 / 多图队列 / 批量导出**;
|
> **范围裁定(用户确认)**:只做**单张图片**的编辑与输出,**不做批量出图 / 多图队列 / 批量导出**;
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
| 视图 | `editor/viewport.js` | zoom 0.1–10、自由平移、`overlayPad` 交互外扩、`getPos()` 统一坐标换算 |
|
| 视图 | `editor/viewport.js` | zoom 0.1–10、自由平移、`overlayPad` 交互外扩、`getPos()` 统一坐标换算 |
|
||||||
| 输出 | `editor/index.js#exportResult` | 固定 PNG `toBlob` → `glue.js` 转 dataURL → `setNodeImage` / `createImageNode` |
|
| 输出 | `editor/index.js#exportResult` | 固定 PNG `toBlob` → `glue.js` 转 dataURL → `setNodeImage` / `createImageNode` |
|
||||||
| 内存 | `editor/index.js#releaseEditorMemory` | `close()` 释放所有像素、原图、历史;**会话状态不保留** |
|
| 内存 | `editor/index.js#releaseEditorMemory` | `close()` 释放所有像素、原图、历史;**会话状态不保留** |
|
||||||
| 宿主 | `plugin/glue.js` | 只对 `ref` 节点暴露;`ctx.canvas.*`;`ctx.storage` 是宿主提供的小 KV(localStorage),**不是像素仓库** |
|
| 宿主 | `plugin/glue.js` | 只对 `ref` 节点暴露;`ctx.canvas.*`;`ctx.storage` 是宿主提供的小容量命名空间 KV,**不是像素仓库** |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@
|
|||||||
| overlay 单 canvas 多用 | 裁剪遮罩、选中框、笔刷环、放置预览、提示文字全在 `S.overlayCanvas`,共用 `clearOverlay()`;**加蚂蚁线必然互相擦除** | P0 |
|
| overlay 单 canvas 多用 | 裁剪遮罩、选中框、笔刷环、放置预览、提示文字全在 `S.overlayCanvas`,共用 `clearOverlay()`;**加蚂蚁线必然互相擦除** | P0 |
|
||||||
| `editor.css` 补丁堆积 | 1340 行,后半段大量 `!important`;工具栏 `position:absolute; top:68px`,撤销按钮 `right:154px` 等魔数;`.iwb-editor-footer` 空且 `display:none`;`.iwb-editor-zoom-hint` 绝对定位 | P0 |
|
| `editor.css` 补丁堆积 | 1340 行,后半段大量 `!important`;工具栏 `position:absolute; top:68px`,撤销按钮 `right:154px` 等魔数;`.iwb-editor-footer` 空且 `display:none`;`.iwb-editor-zoom-hint` 绝对定位 | P0 |
|
||||||
| 无响应式 / 无亮色主题 | 窄窗口下 290px 图层面板 + 44px 工具栏挤压画布 | P5 |
|
| 无响应式 / 无亮色主题 | 窄窗口下 290px 图层面板 + 44px 工具栏挤压画布 | P5 |
|
||||||
| 关闭即清空 | 无草稿、无二次编辑;`ctx.storage` 只是 localStorage 小 KV | P5 |
|
| 关闭即清空 | 无草稿、无二次编辑;`ctx.storage` 只是宿主提供的小容量命名空间 KV | P5 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -290,14 +290,14 @@ getCompositeCanvas() // 当前这一张
|
|||||||
|
|
||||||
| 期 | 交付 | 验收 |
|
| 期 | 交付 | 验收 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| **P0 地基 + 轻量 UI** | 精简顶栏、就地选项栏、状态栏、图层面板可收起、命令层、状态机、overlay 分层、toast、CSS 重构、快捷键映射层、定义 `resetDraw` 语义、放置免二次确认 | 功能零变化;**高频动作点击层级 ≤1**、无新增弹窗;真站 e2e 22/22 全绿;`npm run build` + `npm run validate`;发布契约 6/6 |
|
| **P0 地基 + 轻量 UI** | 精简顶栏、就地选项栏、状态栏、图层面板可收起、命令层、状态机、overlay 分层、toast、CSS 重构、快捷键映射层、定义 `resetDraw` 语义、放置免二次确认 | 功能零变化;**高频动作点击层级 ≤1**、无新增弹窗;桌面客户端 e2e 22/22 全绿;`npm run build` + `npm run validate`;发布契约 6/6 |
|
||||||
| **P1 选区核心** | 矩形/椭圆/多边形/套索;加选减选、全选/反选/取消、羽化、蚂蚁线;**选区浮动操作条 + 右键菜单**;复制/剪切到新层、Delete 清除(**仅当前层**)、填充/描边;附带「还原原图」与「≤500KB」预设 | 框选后浮动条一步完成复制;Ctrl+J 新层像素正确且原层不变;**Delete 后其它层像素原样、当前层挖空且可撤销**;base 锁定提示;「还原原图」后只剩 base 且 Ctrl+Z 能全恢复;预设输出 ≤500KB;选区与裁剪/放置互斥;三条入口结果一致 |
|
| **P1 选区核心** | 矩形/椭圆/多边形/套索;加选减选、全选/反选/取消、羽化、蚂蚁线;**选区浮动操作条 + 右键菜单**;复制/剪切到新层、Delete 清除(**仅当前层**)、填充/描边;附带「还原原图」与「≤500KB」预设 | 框选后浮动条一步完成复制;Ctrl+J 新层像素正确且原层不变;**Delete 后其它层像素原样、当前层挖空且可撤销**;base 锁定提示;「还原原图」后只剩 base 且 Ctrl+Z 能全恢复;预设输出 ≤500KB;选区与裁剪/放置互斥;三条入口结果一致 |
|
||||||
| **P2 图像与裁剪** | 非破坏性裁剪(路线 1)、画布大小、图像大小、90° 旋转 / 翻转、尺寸预设(点击即用)、裁剪可撤销 | 裁剪后图层数不减、Ctrl+Z 能回退;文字/形状 `rotation` 保留;800×800 预设尺寸精确 |
|
| **P2 图像与裁剪** | 非破坏性裁剪(路线 1)、画布大小、图像大小、90° 旋转 / 翻转、尺寸预设(点击即用)、裁剪可撤销 | 裁剪后图层数不减、Ctrl+Z 能回退;文字/形状 `rotation` 保留;800×800 预设尺寸精确 |
|
||||||
| **P3 图层增强** | 缩略图、重命名、混合模式、图层蒙版(选区→蒙版)、多选/简化编组、历史面板 | 蒙版可显隐/删除且不影响原像素;混合模式在合成与导出一致 |
|
| **P3 图层增强** | 缩略图、重命名、混合模式、图层蒙版(选区→蒙版)、多选/简化编组、历史面板 | 蒙版可显隐/删除且不影响原像素;混合模式在合成与导出一致 |
|
||||||
| **P4 单张输出** | PNG/JPG/WebP + 质量 + ≤500KB 策略 + 背景切换 + 下载/剪贴板 + 记住上次预设 | 单张导出尺寸/体积达标;透明像素正确;导出不污染画布;**无队列、无批量入口** |
|
| **P4 单张输出** | PNG/JPG/WebP + 质量 + ≤500KB 策略 + 背景切换 + 下载/剪贴板 + 记住上次预设 | 单张导出尺寸/体积达标;透明像素正确;导出不污染画布;**无队列、无批量入口** |
|
||||||
| **P5 打磨** | 右键菜单补全、全量快捷键、草稿、亮色主题、响应式、无障碍 | 窄窗口可用;草稿只存元数据不存像素 |
|
| **P5 打磨** | 右键菜单补全、全量快捷键、草稿、亮色主题、响应式、无障碍 | 窄窗口可用;草稿只存元数据不存像素 |
|
||||||
|
|
||||||
每一期都走同一条发布链:`plugin/editor/*.js` → `npm run build -- image-annotate` → `npm run validate` → **先提交源码并合进 `origin/main`** → 宿主仓 `scripts/plugins-publish.sh image-annotate <插件路径> <版本>`(带守卫,拒发脏工作区/未合主干)→ 补推 tag → 真站 e2e(带 CSP)。版本两处同步(`package.json` + 脚本参数),禁止手改 `plugins/index.json`。
|
每一期都走同一条发布链:`plugin/editor/*.js` → `npm run build -- image-annotate` → `npm run validate` → 提交源码进本仓 → 桌面仓 `node scripts/sync-plugins-from-repo.js` + `node scripts/gen-market.js`(内容寻址 + SRI,自动重建清单)→ 上传 `market/` 到 NAS → 客户端市场安装验证(带 CSP)。版本以 `package.json` 为准(构建时注入 manifest),禁止手改桌面仓 `plugins/index.json`。
|
||||||
|
|
||||||
### 6.1 实施进度(v1.1.0,2026-11-04 已交付)
|
### 6.1 实施进度(v1.1.0,2026-11-04 已交付)
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
|
|
||||||
**浮动操作条已按 §8 决策先做出来上线,等待用户真站体验后裁定**;它是纯视图(只调 `runCommand`),替换或移除不影响选区命令。
|
**浮动操作条已按 §8 决策先做出来上线,等待用户在桌面客户端体验后裁定**;它是纯视图(只调 `runCommand`),替换或移除不影响选区命令。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -341,11 +341,11 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
||||||
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
||||||
| 选项栏横向排布 | `.iwb-editor-optionbar-body` 是 `overflow-x: auto` 的 flex。**任何 `margin-left: auto` 都会把其后内容整组推到最右**,排满时直接滚出可视区 —— `v1.9.1` 就是 `.iwb-opt-sep` 带了 `auto`,导致选区按钮在选择工具下「消失」。留白只允许放在末尾的 `.iwb-opt-hint`;中文双字按钮必须 `white-space: nowrap`,否则会竖排 |
|
| 选项栏横向排布 | `.iwb-editor-optionbar-body` 是 `overflow-x: auto` 的 flex。**任何 `margin-left: auto` 都会把其后内容整组推到最右**,排满时直接滚出可视区 —— `v1.9.1` 就是 `.iwb-opt-sep` 带了 `auto`,导致选区按钮在选择工具下「消失」。留白只允许放在末尾的 `.iwb-opt-hint`;中文双字按钮必须 `white-space: nowrap`,否则会竖排 |
|
||||||
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
| 草稿持久化 | `ctx.storage` 是宿主提供的命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
||||||
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
||||||
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
||||||
| 发布契约 | 文件名 `plugin-image-annotate.js`、id 一致、SRI、内容寻址名、清单合并、tag 反查;脚本守卫强制「工作区干净 + HEAD 已在 origin/main」 |
|
| 发布契约 | 文件名 `plugin-image-annotate.<sha12>.js`(内容寻址)、id 一致、SRI;桌面仓同步脚本按白名单重建市场清单;版本以 `package.json` 为准 |
|
||||||
| 测试 | 本地 mock 探针(直接注入 `src/index.js` + mock host)用于发布前验证;真站 e2e(CSP / KV / SRI)用于发布后验证;两者都保留 |
|
| 测试 | 本地 mock 探针(直接注入 `src/index.js` + mock host)用于发布前验证;桌面客户端 e2e(CSP / 市场安装 / SRI)用于发布后验证;两者都保留 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 1 | **选区 `Delete` 只作用当前图层** | 用 `S.selection.path` 对**当前活动层**做 `destination-out`,不动其它层;`base` 处于锁定态时给 toast 提示「原图层已锁定,请先解锁」,不提供「清所有可见层」入口。清除走 `execute()`,可 Ctrl+Z。 |
|
| 1 | **选区 `Delete` 只作用当前图层** | 用 `S.selection.path` 对**当前活动层**做 `destination-out`,不动其它层;`base` 处于锁定态时给 toast 提示「原图层已锁定,请先解锁」,不提供「清所有可见层」入口。清除走 `execute()`,可 Ctrl+Z。 |
|
||||||
| 2 | **「清空标注」=全部还原** | 一键回到**刚打开这张图时的初始态**:删除所有非 `base` 图层(含粘贴/导入/选区复制产生的层)、清空所有绘制像素、复位变换与选区、保留 `base` 原始像素。整步记一个历史快照,**可撤销**。按钮标签改为「还原原图」避免歧义;不再留空白层。 |
|
| 2 | **「清空标注」=全部还原** | 一键回到**刚打开这张图时的初始态**:删除所有非 `base` 图层(含粘贴/导入/选区复制产生的层)、清空所有绘制像素、复位变换与选区、保留 `base` 原始像素。整步记一个历史快照,**可撤销**。按钮标签改为「还原原图」避免歧义;不再留空白层。 |
|
||||||
| 3 | **≤500KB 做成输出预设** | 输出面板新增可切换预设「电商 800×800 · ≤500KB」:尺寸 800×800、长边占比 80%(640px)、透明 PNG 或白底 JPG **由用户当前选的单一格式决定,一次只产一个结果**;编码质量迭代到 ≤500KB。预设选择存 `ctx.settings`,下次打开沿用。默认仍是「原尺寸 PNG」,不默认启用预设。 |
|
| 3 | **≤500KB 做成输出预设** | 输出面板新增可切换预设「电商 800×800 · ≤500KB」:尺寸 800×800、长边占比 80%(640px)、透明 PNG 或白底 JPG **由用户当前选的单一格式决定,一次只产一个结果**;编码质量迭代到 ≤500KB。预设选择存 `ctx.settings`,下次打开沿用。默认仍是「原尺寸 PNG」,不默认启用预设。 |
|
||||||
| 4 | **浮动操作条:先做,体验后定** | 本轮按 §4.1 实现选区旁的浮动条并上线,供用户真站体验;「好不好用、要不要保留/换位置/改内容」由体验结论决定,**不作为开工前置条件**。实现上保持它是纯视图(`floating.js` 只调用命令层),日后替换或移除不影响选区功能。 |
|
| 4 | **浮动操作条:先做,体验后定** | 本轮按 §4.1 实现选区旁的浮动条并上线,供用户在桌面客户端体验;「好不好用、要不要保留/换位置/改内容」由体验结论决定,**不作为开工前置条件**。实现上保持它是纯视图(`floating.js` 只调用命令层),日后替换或移除不影响选区功能。 |
|
||||||
|
|
||||||
配套已按推荐默认落地(无需再问):不设菜单栏、数字键 1–0 保留兼容、`Ctrl+V` 维持「贴为新图层」、选区贴入用 `Ctrl+Shift+V`、正式分叉不回灌 `iwb-plaus`、优先级 **P0 → P1**,输出预设随 P1 一起带上(改动小)。
|
配套已按推荐默认落地(无需再问):不设菜单栏、数字键 1–0 保留兼容、`Ctrl+V` 维持「贴为新图层」、选区贴入用 `Ctrl+Shift+V`、正式分叉不回灌 `iwb-plaus`、优先级 **P0 → P1**,输出预设随 P1 一起带上(改动小)。
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.20.1",
|
"version": "1.20.7",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
+142
-9
@@ -46,12 +46,32 @@ import { toast } from './commands.js'
|
|||||||
invert: {
|
invert: {
|
||||||
label: '反白', hint: '反相:明暗翻转,白底变黑底',
|
label: '反白', hint: '反相:明暗翻转,白底变黑底',
|
||||||
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
||||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'invert(' + (v / 100) + ')') }
|
render: (canvas, v) => {
|
||||||
|
if (v <= 0) return
|
||||||
|
const k = v / 100
|
||||||
|
if (FILTER_SUPPORTED) { filterCanvas(canvas, 'invert(' + k + ')'); return }
|
||||||
|
// 线性插值到反相值:out = c + (255 - 2c) * k
|
||||||
|
const ok = mapPixels(canvas, (r, g, b) => [
|
||||||
|
clamp255(r + (255 - 2 * r) * k),
|
||||||
|
clamp255(g + (255 - 2 * g) * k),
|
||||||
|
clamp255(b + (255 - 2 * b) * k)
|
||||||
|
])
|
||||||
|
if (!ok) blendFallback(canvas, 'invert', k)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
gray: {
|
gray: {
|
||||||
label: '灰度', hint: '去色,保留明暗层次',
|
label: '灰度', hint: '去色,保留明暗层次',
|
||||||
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
||||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'grayscale(' + (v / 100) + ')') }
|
render: (canvas, v) => {
|
||||||
|
if (v <= 0) return
|
||||||
|
const k = v / 100
|
||||||
|
if (FILTER_SUPPORTED) { filterCanvas(canvas, 'grayscale(' + k + ')'); return }
|
||||||
|
const okGray = mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b)
|
||||||
|
return [clamp255(r + (y - r) * k), clamp255(g + (y - g) * k), clamp255(b + (y - b) * k)]
|
||||||
|
})
|
||||||
|
if (!okGray) blendFallback(canvas, 'gray', k)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
boost: {
|
boost: {
|
||||||
label: '增强', hint: '提亮并加对比,适合发灰的截图',
|
label: '增强', hint: '提亮并加对比,适合发灰的截图',
|
||||||
@@ -59,10 +79,20 @@ import { toast } from './commands.js'
|
|||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return
|
if (v <= 0) return
|
||||||
const k = v / 100
|
const k = v / 100
|
||||||
// v1.15:旧系数 1+0.12k / 1+0.1k / 1+0.06k 拉满只有 1.12 倍亮度,肉眼看不出变化
|
if (FILTER_SUPPORTED) {
|
||||||
// (用户反馈「效果现在弱了一些」)。现在拉满 = 1.4 倍亮度 / 1.25 倍对比 / 1.2 倍饱和,
|
filterCanvas(canvas, 'brightness(' + (1 + 0.4 * k).toFixed(3) + ') contrast(' + (1 + 0.25 * k).toFixed(3) + ') saturate(' + (1 + 0.2 * k).toFixed(3) + ')')
|
||||||
// 对应「一眼能看出变亮变通透」,但仍然不过曝 —— 再往上压会先把高光切掉。
|
return
|
||||||
filterCanvas(canvas, 'brightness(' + (1 + 0.4 * k).toFixed(3) + ') contrast(' + (1 + 0.25 * k).toFixed(3) + ') saturate(' + (1 + 0.2 * k).toFixed(3) + ')')
|
}
|
||||||
|
const bright = 1 + 0.4 * k, contrast = 1 + 0.25 * k, sat = 1 + 0.2 * k
|
||||||
|
mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b)
|
||||||
|
const out = [r, g, b].map((c) => {
|
||||||
|
let v2 = y + (c - y) * sat
|
||||||
|
v2 = (v2 - 128) * contrast + 128
|
||||||
|
return clamp255(v2 * bright)
|
||||||
|
})
|
||||||
|
return out
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contrast: {
|
contrast: {
|
||||||
@@ -71,13 +101,24 @@ import { toast } from './commands.js'
|
|||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return
|
if (v <= 0) return
|
||||||
const k = v / 100
|
const k = v / 100
|
||||||
filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.6 * k).toFixed(3) + ')')
|
if (FILTER_SUPPORTED) { filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.6 * k).toFixed(3) + ')'); return }
|
||||||
|
const c = 1 + 1.6 * k
|
||||||
|
mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b)
|
||||||
|
const gray = y * k + ((r + g + b) / 3) * (1 - k)
|
||||||
|
const v2 = (gray - 128) * c + 128
|
||||||
|
return [clamp255(v2), clamp255(v2), clamp255(v2)]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
soft: {
|
soft: {
|
||||||
label: '柔化', hint: '模糊,弱化背景',
|
label: '柔化', hint: '模糊,弱化背景',
|
||||||
param: '半径', unit: 'px', min: 0, max: 16, step: 0.5, def: (canvas) => softRadius(canvas),
|
param: '半径', unit: 'px', min: 0, max: 16, step: 0.5, def: (canvas) => softRadius(canvas),
|
||||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'blur(' + v + 'px)') }
|
render: (canvas, v) => {
|
||||||
|
if (v <= 0) return
|
||||||
|
if (FILTER_SUPPORTED) filterCanvas(canvas, 'blur(' + v + 'px)')
|
||||||
|
else blurCanvas(canvas, v)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mosaic: {
|
mosaic: {
|
||||||
label: '马赛克', hint: '像素化,用于打码手机号/地址等隐私信息',
|
label: '马赛克', hint: '像素化,用于打码手机号/地址等隐私信息',
|
||||||
@@ -115,6 +156,93 @@ import { toast } from './commands.js'
|
|||||||
ctx.restore()
|
ctx.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ctx.filter 支持性:Chrome/Edge 支持,macOS WKWebView 长期不支持(赋值会被忽略)。
|
||||||
|
// 不支持时下面全部走像素级兜底,否则「只有马赛克有效」——马赛克本来就不依赖 filter。
|
||||||
|
// ctx.filter 支持性:不能只看「属性是否可赋值」——WKWebView 里属性存在但绘制时被忽略,
|
||||||
|
// 赋值检测会误判为支持。这里做功能性探测:红块过 invert(1) 之后必须变青。
|
||||||
|
const FILTER_SUPPORTED = (function () {
|
||||||
|
try {
|
||||||
|
const src = document.createElement('canvas')
|
||||||
|
src.width = 2; src.height = 2
|
||||||
|
const sctx = src.getContext('2d')
|
||||||
|
sctx.fillStyle = '#ff0000'
|
||||||
|
sctx.fillRect(0, 0, 2, 2)
|
||||||
|
const dst = document.createElement('canvas')
|
||||||
|
dst.width = 2; dst.height = 2
|
||||||
|
const dctx = dst.getContext('2d')
|
||||||
|
dctx.filter = 'invert(1)'
|
||||||
|
dctx.drawImage(src, 0, 0)
|
||||||
|
const d = dctx.getImageData(0, 0, 1, 1).data
|
||||||
|
return d[0] < 60 && d[1] > 180 && d[2] > 180
|
||||||
|
} catch (e) { return false }
|
||||||
|
})()
|
||||||
|
|
||||||
|
/** 逐像素处理(设备像素坐标系直接写回);画布被跨域图污染时 getImageData 会抛错 → 返回 false */
|
||||||
|
function mapPixels(canvas, fn) {
|
||||||
|
const w = canvas.width, h = canvas.height
|
||||||
|
if (!w || !h) return false
|
||||||
|
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||||
|
let img
|
||||||
|
try { img = ctx.getImageData(0, 0, w, h) } catch (e) { return false }
|
||||||
|
const d = img.data
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] === 0) continue
|
||||||
|
const out = fn(d[i], d[i + 1], d[i + 2])
|
||||||
|
d[i] = out[0]; d[i + 1] = out[1]; d[i + 2] = out[2]
|
||||||
|
}
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
|
ctx.putImageData(img, 0, 0)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 混合模式兜底(读不到像素时):反相用 difference+白,去色用 saturation+灰 */
|
||||||
|
function blendFallback(canvas, mode, strength) {
|
||||||
|
const k = typeof strength === 'number' ? Math.max(0, Math.min(1, strength)) : 1
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
const copy = document.createElement('canvas')
|
||||||
|
copy.width = canvas.width
|
||||||
|
copy.height = canvas.height
|
||||||
|
copy.getContext('2d').drawImage(canvas, 0, 0)
|
||||||
|
ctx.save()
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
|
ctx.globalAlpha = 1
|
||||||
|
if (mode === 'invert') { ctx.globalCompositeOperation = 'difference'; ctx.fillStyle = '#ffffff' }
|
||||||
|
else { ctx.globalCompositeOperation = 'saturation'; ctx.fillStyle = '#808080' }
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
||||||
|
// 按强度混回原图(k=1 全反相,k=0 原样)
|
||||||
|
if (k < 1) {
|
||||||
|
ctx.globalCompositeOperation = 'source-over'
|
||||||
|
ctx.globalAlpha = 1 - k
|
||||||
|
ctx.drawImage(copy, 0, 0)
|
||||||
|
}
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
function luma(r, g, b) { return 0.2126 * r + 0.7152 * g + 0.0722 * b }
|
||||||
|
function clamp255(v) { return v < 0 ? 0 : (v > 255 ? 255 : v) }
|
||||||
|
|
||||||
|
/** 模糊兜底:缩到 1/n 再平滑放大,效果接近 blur 且比卷积快得多 */
|
||||||
|
function blurCanvas(canvas, radius) {
|
||||||
|
const w = canvas.width, h = canvas.height
|
||||||
|
if (!w || !h || radius <= 0) return
|
||||||
|
const n = Math.max(2, Math.min(16, Math.round(radius * 1.6)))
|
||||||
|
const sw = Math.max(1, Math.round(w / n))
|
||||||
|
const sh = Math.max(1, Math.round(h / n))
|
||||||
|
const tmp = document.createElement('canvas')
|
||||||
|
tmp.width = sw; tmp.height = sh
|
||||||
|
const tctx = tmp.getContext('2d')
|
||||||
|
tctx.imageSmoothingEnabled = true
|
||||||
|
tctx.drawImage(canvas, 0, 0, sw, sh)
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
ctx.save()
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
|
ctx.globalAlpha = 1
|
||||||
|
ctx.globalCompositeOperation = 'copy'
|
||||||
|
ctx.imageSmoothingEnabled = true
|
||||||
|
ctx.drawImage(tmp, 0, 0, w, h)
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
|
||||||
/** 马赛克:缩到 1/block 再关掉平滑放大,比逐像素 getImageData 快一个量级 */
|
/** 马赛克:缩到 1/block 再关掉平滑放大,比逐像素 getImageData 快一个量级 */
|
||||||
function pixelateCanvas(canvas, block) {
|
function pixelateCanvas(canvas, block) {
|
||||||
const w = canvas.width, h = canvas.height
|
const w = canvas.width, h = canvas.height
|
||||||
@@ -205,7 +333,12 @@ import { toast } from './commands.js'
|
|||||||
ctx.drawImage(st.source, 0, 0)
|
ctx.drawImage(st.source, 0, 0)
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
|
|
||||||
fx.render(target.canvas, value)
|
try {
|
||||||
|
fx.render(target.canvas, value)
|
||||||
|
} catch (e) {
|
||||||
|
toast('效果失败:' + ((e && e.message) || e), 'error')
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
|
||||||
// 像素变了:包围盒要重算,吸管合成缓存要作废
|
// 像素变了:包围盒要重算,吸管合成缓存要作废
|
||||||
target._bounds = undefined
|
target._bounds = undefined
|
||||||
|
|||||||
@@ -357,6 +357,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
function onMouseMove(e) {
|
function onMouseMove(e) {
|
||||||
// 记下修饰键:拖动按 Alt 时临时关掉吸附(想停在「差一点点」的位置时用)
|
// 记下修饰键:拖动按 Alt 时临时关掉吸附(想停在「差一点点」的位置时用)
|
||||||
S._altDown = !!e.altKey
|
S._altDown = !!e.altKey
|
||||||
|
// 自愈:拖出窗口/切换应用会丢 mouseup,isDrawing 会永远为 true,后续操作被忽略
|
||||||
|
if (S.isDrawing && e.buttons === 0) {
|
||||||
|
S.isDrawing = false
|
||||||
|
const up = Object.prototype.hasOwnProperty.call(DRAW_UP_HANDLERS, S.tool) ? DRAW_UP_HANDLERS[S.tool] : null
|
||||||
|
try { if (up) up(getPos(e)) } catch (err) { /* 收笔失败不影响后续 */ }
|
||||||
|
}
|
||||||
// 图片放置拖拽
|
// 图片放置拖拽
|
||||||
if (S.placingImage && S.placingHandle && S.placingStart) {
|
if (S.placingImage && S.placingHandle && S.placingStart) {
|
||||||
onPlacementDragMove(e); return
|
onPlacementDragMove(e); return
|
||||||
@@ -2640,6 +2646,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 将 canvas 鼠标事件绑定到活跃图层 canvas(在 setupCanvas 后调用,仅绑定一次) */
|
/** 将 canvas 鼠标事件绑定到活跃图层 canvas(在 setupCanvas 后调用,仅绑定一次) */
|
||||||
|
// 交互状态复位:窗口失焦 / 指针取消 / 切标签页时兜底
|
||||||
|
function resetPointerState() {
|
||||||
|
S.isDrawing = false
|
||||||
|
S.marquee = null
|
||||||
|
S.lassoPts = null
|
||||||
|
S.textDrag = null
|
||||||
|
S.bitmapDrag = null
|
||||||
|
S.shapeDrag = null
|
||||||
|
S.penDragPt = -1
|
||||||
|
S.penDragPending = null
|
||||||
|
S.placingHandle = null
|
||||||
|
S.panning = false
|
||||||
|
S.interaction = 'idle'
|
||||||
|
if (S.strokeCanvas) S.strokeCanvas.style.display = 'none'
|
||||||
|
document.body.style.cursor = ''
|
||||||
|
document.body.style.userSelect = ''
|
||||||
|
try { renderObjects() } catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
|
||||||
export function bindCanvasEvents() {
|
export function bindCanvasEvents() {
|
||||||
if (S._canvasEventsBound) return
|
if (S._canvasEventsBound) return
|
||||||
S._canvasEventsBound = true
|
S._canvasEventsBound = true
|
||||||
@@ -2649,6 +2674,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
S.canvasStack.addEventListener('mousemove', onMouseMove)
|
S.canvasStack.addEventListener('mousemove', onMouseMove)
|
||||||
S.canvasStack.addEventListener('mousemove', onCanvasHover)
|
S.canvasStack.addEventListener('mousemove', onCanvasHover)
|
||||||
window.addEventListener('mouseup', onMouseUp)
|
window.addEventListener('mouseup', onMouseUp)
|
||||||
|
window.addEventListener('blur', resetPointerState)
|
||||||
|
document.addEventListener('pointercancel', resetPointerState)
|
||||||
|
document.addEventListener('visibilitychange', () => { if (document.hidden) resetPointerState() })
|
||||||
S.canvasStack.addEventListener('contextmenu', (e) => {
|
S.canvasStack.addEventListener('contextmenu', (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (S.open && !S.placingImage) showSelectionContext(e)
|
if (S.open && !S.placingImage) showSelectionContext(e)
|
||||||
|
|||||||
@@ -15,3 +15,5 @@ import { createGlue } from './glue.js'
|
|||||||
;(typeof window !== 'undefined' ? window : globalThis).__IWB_ANNOTATE_FACTORY__ = function (ctx) {
|
;(typeof window !== 'undefined' ? window : globalThis).__IWB_ANNOTATE_FACTORY__ = function (ctx) {
|
||||||
return createGlue(ctx, editorCss)
|
return createGlue(ctx, editorCss)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build-rev: 2026-11-17 (cache-bust)
|
||||||
@@ -6,11 +6,14 @@
|
|||||||
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
||||||
//
|
//
|
||||||
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
||||||
|
// skin: 'private' = 本插件自带整套调色板(Catppuccin 深色工具 UI),不跟随宿主主题。
|
||||||
|
// 代价由宿主契约测试钉死:声明 private 的插件不得引用宿主颜色 var(--iwb-*),只能自洽。
|
||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '__PLUGIN_VERSION__',
|
version: '__PLUGIN_VERSION__',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
|
skin: 'private',
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
exportPreset: { type: 'string', default: 'original' },
|
exportPreset: { type: 'string', default: 'original' },
|
||||||
|
|||||||
@@ -7,3 +7,5 @@
|
|||||||
return global.__IWB_ANNOTATE_FACTORY__(ctx)
|
return global.__IWB_ANNOTATE_FACTORY__(ctx)
|
||||||
})
|
})
|
||||||
})(typeof window !== 'undefined' ? window : globalThis)
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
|
|
||||||
|
// build-rev: 2026-11-17T17 (pointer-self-heal)
|
||||||
+190
-7
@@ -6,11 +6,14 @@
|
|||||||
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
||||||
//
|
//
|
||||||
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
||||||
|
// skin: 'private' = 本插件自带整套调色板(Catppuccin 深色工具 UI),不跟随宿主主题。
|
||||||
|
// 代价由宿主契约测试钉死:声明 private 的插件不得引用宿主颜色 var(--iwb-*),只能自洽。
|
||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.20.1',
|
version: '1.20.7',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
|
skin: 'private',
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
exportPreset: { type: 'string', default: 'original' },
|
exportPreset: { type: 'string', default: 'original' },
|
||||||
@@ -3899,7 +3902,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
step: 1,
|
step: 1,
|
||||||
def: () => 100,
|
def: () => 100,
|
||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v > 0) filterCanvas(canvas, "invert(" + v / 100 + ")");
|
if (v <= 0) return;
|
||||||
|
const k = v / 100;
|
||||||
|
if (FILTER_SUPPORTED) {
|
||||||
|
filterCanvas(canvas, "invert(" + k + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ok = mapPixels(canvas, (r, g, b) => [
|
||||||
|
clamp255(r + (255 - 2 * r) * k),
|
||||||
|
clamp255(g + (255 - 2 * g) * k),
|
||||||
|
clamp255(b + (255 - 2 * b) * k)
|
||||||
|
]);
|
||||||
|
if (!ok) blendFallback(canvas, "invert", k);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
gray: {
|
gray: {
|
||||||
@@ -3912,7 +3926,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
step: 1,
|
step: 1,
|
||||||
def: () => 100,
|
def: () => 100,
|
||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v > 0) filterCanvas(canvas, "grayscale(" + v / 100 + ")");
|
if (v <= 0) return;
|
||||||
|
const k = v / 100;
|
||||||
|
if (FILTER_SUPPORTED) {
|
||||||
|
filterCanvas(canvas, "grayscale(" + k + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const okGray = mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b);
|
||||||
|
return [clamp255(r + (y - r) * k), clamp255(g + (y - g) * k), clamp255(b + (y - b) * k)];
|
||||||
|
});
|
||||||
|
if (!okGray) blendFallback(canvas, "gray", k);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
boost: {
|
boost: {
|
||||||
@@ -3927,7 +3951,20 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return;
|
if (v <= 0) return;
|
||||||
const k = v / 100;
|
const k = v / 100;
|
||||||
filterCanvas(canvas, "brightness(" + (1 + 0.4 * k).toFixed(3) + ") contrast(" + (1 + 0.25 * k).toFixed(3) + ") saturate(" + (1 + 0.2 * k).toFixed(3) + ")");
|
if (FILTER_SUPPORTED) {
|
||||||
|
filterCanvas(canvas, "brightness(" + (1 + 0.4 * k).toFixed(3) + ") contrast(" + (1 + 0.25 * k).toFixed(3) + ") saturate(" + (1 + 0.2 * k).toFixed(3) + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const bright = 1 + 0.4 * k, contrast = 1 + 0.25 * k, sat = 1 + 0.2 * k;
|
||||||
|
mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b);
|
||||||
|
const out = [r, g, b].map((c) => {
|
||||||
|
let v2 = y + (c - y) * sat;
|
||||||
|
v2 = (v2 - 128) * contrast + 128;
|
||||||
|
return clamp255(v2 * bright);
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contrast: {
|
contrast: {
|
||||||
@@ -3942,7 +3979,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return;
|
if (v <= 0) return;
|
||||||
const k = v / 100;
|
const k = v / 100;
|
||||||
filterCanvas(canvas, "grayscale(" + k.toFixed(3) + ") contrast(" + (1 + 1.6 * k).toFixed(3) + ")");
|
if (FILTER_SUPPORTED) {
|
||||||
|
filterCanvas(canvas, "grayscale(" + k.toFixed(3) + ") contrast(" + (1 + 1.6 * k).toFixed(3) + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const c = 1 + 1.6 * k;
|
||||||
|
mapPixels(canvas, (r, g, b) => {
|
||||||
|
const y = luma(r, g, b);
|
||||||
|
const gray = y * k + (r + g + b) / 3 * (1 - k);
|
||||||
|
const v2 = (gray - 128) * c + 128;
|
||||||
|
return [clamp255(v2), clamp255(v2), clamp255(v2)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
soft: {
|
soft: {
|
||||||
@@ -3955,7 +4002,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
step: 0.5,
|
step: 0.5,
|
||||||
def: (canvas) => softRadius(canvas),
|
def: (canvas) => softRadius(canvas),
|
||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v > 0) filterCanvas(canvas, "blur(" + v + "px)");
|
if (v <= 0) return;
|
||||||
|
if (FILTER_SUPPORTED) filterCanvas(canvas, "blur(" + v + "px)");
|
||||||
|
else blurCanvas(canvas, v);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mosaic: {
|
mosaic: {
|
||||||
@@ -3995,6 +4044,100 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.drawImage(tmp, 0, 0);
|
ctx.drawImage(tmp, 0, 0);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
var FILTER_SUPPORTED = function() {
|
||||||
|
try {
|
||||||
|
const src = document.createElement("canvas");
|
||||||
|
src.width = 2;
|
||||||
|
src.height = 2;
|
||||||
|
const sctx = src.getContext("2d");
|
||||||
|
sctx.fillStyle = "#ff0000";
|
||||||
|
sctx.fillRect(0, 0, 2, 2);
|
||||||
|
const dst = document.createElement("canvas");
|
||||||
|
dst.width = 2;
|
||||||
|
dst.height = 2;
|
||||||
|
const dctx = dst.getContext("2d");
|
||||||
|
dctx.filter = "invert(1)";
|
||||||
|
dctx.drawImage(src, 0, 0);
|
||||||
|
const d = dctx.getImageData(0, 0, 1, 1).data;
|
||||||
|
return d[0] < 60 && d[1] > 180 && d[2] > 180;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
function mapPixels(canvas, fn) {
|
||||||
|
const w = canvas.width, h = canvas.height;
|
||||||
|
if (!w || !h) return false;
|
||||||
|
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
||||||
|
let img;
|
||||||
|
try {
|
||||||
|
img = ctx.getImageData(0, 0, w, h);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const d = img.data;
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] === 0) continue;
|
||||||
|
const out = fn(d[i], d[i + 1], d[i + 2]);
|
||||||
|
d[i] = out[0];
|
||||||
|
d[i + 1] = out[1];
|
||||||
|
d[i + 2] = out[2];
|
||||||
|
}
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
|
ctx.putImageData(img, 0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function blendFallback(canvas, mode, strength) {
|
||||||
|
const k = typeof strength === "number" ? Math.max(0, Math.min(1, strength)) : 1;
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
const copy = document.createElement("canvas");
|
||||||
|
copy.width = canvas.width;
|
||||||
|
copy.height = canvas.height;
|
||||||
|
copy.getContext("2d").drawImage(canvas, 0, 0);
|
||||||
|
ctx.save();
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
if (mode === "invert") {
|
||||||
|
ctx.globalCompositeOperation = "difference";
|
||||||
|
ctx.fillStyle = "#ffffff";
|
||||||
|
} else {
|
||||||
|
ctx.globalCompositeOperation = "saturation";
|
||||||
|
ctx.fillStyle = "#808080";
|
||||||
|
}
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
if (k < 1) {
|
||||||
|
ctx.globalCompositeOperation = "source-over";
|
||||||
|
ctx.globalAlpha = 1 - k;
|
||||||
|
ctx.drawImage(copy, 0, 0);
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
function luma(r, g, b) {
|
||||||
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||||
|
}
|
||||||
|
function clamp255(v) {
|
||||||
|
return v < 0 ? 0 : v > 255 ? 255 : v;
|
||||||
|
}
|
||||||
|
function blurCanvas(canvas, radius) {
|
||||||
|
const w = canvas.width, h = canvas.height;
|
||||||
|
if (!w || !h || radius <= 0) return;
|
||||||
|
const n = Math.max(2, Math.min(16, Math.round(radius * 1.6)));
|
||||||
|
const sw = Math.max(1, Math.round(w / n));
|
||||||
|
const sh = Math.max(1, Math.round(h / n));
|
||||||
|
const tmp = document.createElement("canvas");
|
||||||
|
tmp.width = sw;
|
||||||
|
tmp.height = sh;
|
||||||
|
const tctx = tmp.getContext("2d");
|
||||||
|
tctx.imageSmoothingEnabled = true;
|
||||||
|
tctx.drawImage(canvas, 0, 0, sw, sh);
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
ctx.save();
|
||||||
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
ctx.globalCompositeOperation = "copy";
|
||||||
|
ctx.imageSmoothingEnabled = true;
|
||||||
|
ctx.drawImage(tmp, 0, 0, w, h);
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
function pixelateCanvas(canvas, block) {
|
function pixelateCanvas(canvas, block) {
|
||||||
const w = canvas.width, h = canvas.height;
|
const w = canvas.width, h = canvas.height;
|
||||||
if (!w || !h) return;
|
if (!w || !h) return;
|
||||||
@@ -4072,7 +4215,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.drawImage(st.source, 0, 0);
|
ctx.drawImage(st.source, 0, 0);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
fx.render(target.canvas, value);
|
try {
|
||||||
|
fx.render(target.canvas, value);
|
||||||
|
} catch (e) {
|
||||||
|
toast("效果失败:" + (e && e.message || e), "error");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
target._bounds = void 0;
|
target._bounds = void 0;
|
||||||
S.pickerComposite = null;
|
S.pickerComposite = null;
|
||||||
}
|
}
|
||||||
@@ -4847,6 +4995,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
};
|
};
|
||||||
function onMouseMove(e) {
|
function onMouseMove(e) {
|
||||||
S._altDown = !!e.altKey;
|
S._altDown = !!e.altKey;
|
||||||
|
if (S.isDrawing && e.buttons === 0) {
|
||||||
|
S.isDrawing = false;
|
||||||
|
const up = Object.prototype.hasOwnProperty.call(DRAW_UP_HANDLERS, S.tool) ? DRAW_UP_HANDLERS[S.tool] : null;
|
||||||
|
try {
|
||||||
|
if (up) up(getPos(e));
|
||||||
|
} catch (err) {
|
||||||
|
}
|
||||||
|
}
|
||||||
if (S.placingImage && S.placingHandle && S.placingStart) {
|
if (S.placingImage && S.placingHandle && S.placingStart) {
|
||||||
onPlacementDragMove(e);
|
onPlacementDragMove(e);
|
||||||
return;
|
return;
|
||||||
@@ -6875,6 +7031,26 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
renderLayerPanel();
|
renderLayerPanel();
|
||||||
finishCreateTool("shape", shape.id);
|
finishCreateTool("shape", shape.id);
|
||||||
}
|
}
|
||||||
|
function resetPointerState() {
|
||||||
|
S.isDrawing = false;
|
||||||
|
S.marquee = null;
|
||||||
|
S.lassoPts = null;
|
||||||
|
S.textDrag = null;
|
||||||
|
S.bitmapDrag = null;
|
||||||
|
S.shapeDrag = null;
|
||||||
|
S.penDragPt = -1;
|
||||||
|
S.penDragPending = null;
|
||||||
|
S.placingHandle = null;
|
||||||
|
S.panning = false;
|
||||||
|
S.interaction = "idle";
|
||||||
|
if (S.strokeCanvas) S.strokeCanvas.style.display = "none";
|
||||||
|
document.body.style.cursor = "";
|
||||||
|
document.body.style.userSelect = "";
|
||||||
|
try {
|
||||||
|
renderObjects();
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
function bindCanvasEvents() {
|
function bindCanvasEvents() {
|
||||||
if (S._canvasEventsBound) return;
|
if (S._canvasEventsBound) return;
|
||||||
S._canvasEventsBound = true;
|
S._canvasEventsBound = true;
|
||||||
@@ -6882,6 +7058,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
S.canvasStack.addEventListener("mousemove", onMouseMove);
|
S.canvasStack.addEventListener("mousemove", onMouseMove);
|
||||||
S.canvasStack.addEventListener("mousemove", onCanvasHover);
|
S.canvasStack.addEventListener("mousemove", onCanvasHover);
|
||||||
window.addEventListener("mouseup", onMouseUp);
|
window.addEventListener("mouseup", onMouseUp);
|
||||||
|
window.addEventListener("blur", resetPointerState);
|
||||||
|
document.addEventListener("pointercancel", resetPointerState);
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (document.hidden) resetPointerState();
|
||||||
|
});
|
||||||
S.canvasStack.addEventListener("contextmenu", (e) => {
|
S.canvasStack.addEventListener("contextmenu", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (S.open && !S.placingImage) showSelectionContext(e);
|
if (S.open && !S.placingImage) showSelectionContext(e);
|
||||||
@@ -9130,3 +9311,5 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
})
|
})
|
||||||
})(typeof window !== 'undefined' ? window : globalThis)
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
|
|
||||||
|
// build-rev: 2026-11-17T17 (pointer-self-heal)
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ potrace 与其 JS 移植都是 **GPL-2.0**(见 `plugin/vendor/potrace/LICENSE`
|
|||||||
npm run build -- image-vectorize # plugin/ → src/index.js(esbuild IIFE)
|
npm run build -- image-vectorize # plugin/ → src/index.js(esbuild IIFE)
|
||||||
npm run validate # 契约校验
|
npm run validate # 契约校验
|
||||||
node image-vectorize/tools/harness.mjs # 本地端到端(合成宿主 + 真 Chromium,64 项)
|
node image-vectorize/tools/harness.mjs # 本地端到端(合成宿主 + 真 Chromium,64 项)
|
||||||
node image-vectorize/tools/e2e-site.mjs # 真站(KV / SRI / CSP / 真实画布桥)
|
node image-vectorize/tools/e2e-site.mjs # 桌面客户端端到端(市场安装 / SRI / CSP / 真实画布桥)
|
||||||
|
|
||||||
# 拿真实素材调参数(不进 CI,最快看到效果):
|
# 拿真实素材调参数(不进 CI,最快看到效果):
|
||||||
node image-vectorize/tools/trace-cli.mjs ~/Desktop/menu.png --mode gray --levels 3
|
node image-vectorize/tools/trace-cli.mjs ~/Desktop/menu.png --mode gray --levels 3
|
||||||
@@ -146,14 +146,16 @@ node image-vectorize/tools/trace-cli.mjs ~/Desktop/logo.png --mode mono --no-spl
|
|||||||
# → 产物 SVG + 一张「原图 / 结果」对比图(~-/tmp/vz-cli/)
|
# → 产物 SVG + 一张「原图 / 结果」对比图(~-/tmp/vz-cli/)
|
||||||
```
|
```
|
||||||
|
|
||||||
发布:
|
发布:本仓只产出 `src/index.js`(构建产物),发布走桌面仓的市场链路,见根 README「发布到市场」:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp image-vectorize/src/index.js /tmp/plugin-image-vectorize.js
|
npm run build -- image-vectorize && npm run validate
|
||||||
cd ../image-workbench-web && node scripts/plugins-publish.mjs /tmp/plugin-image-vectorize.js \
|
# 桌面仓:node scripts/sync-plugins-from-repo.js && node scripts/gen-market.js
|
||||||
--version image-vectorize=0.3.0 --upload
|
# 再把 market/ 上传到 NAS(market.maqiart.eu.org)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
改版本时同步 `package.json` 的 `version`(构建时注入 manifest)与桌面仓同步脚本读取的版本。
|
||||||
|
|
||||||
## 已知限制
|
## 已知限制
|
||||||
|
|
||||||
- **照片不适合**:potrace 只懂明暗,照片会被压成几块灰阶(这不是 bug,是算法定位)
|
- **照片不适合**:potrace 只懂明暗,照片会被压成几块灰阶(这不是 bug,是算法定位)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-vectorize",
|
"name": "@iwb-plugin/image-vectorize",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.4.2",
|
"version": "0.6.1",
|
||||||
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-vectorize",
|
"id": "image-vectorize",
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
||||||
//
|
//
|
||||||
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
||||||
|
// skin: 'private' = 自绘深色工具 UI(#1b1b22 系列),不跟随宿主主题。
|
||||||
|
// 代价由宿主契约测试钉死:声明 private 的插件不得引用宿主颜色 var(--iwb-*),只能自洽。
|
||||||
var __IWB_VECTORIZE_MANIFEST__ = {
|
var __IWB_VECTORIZE_MANIFEST__ = {
|
||||||
id: 'image-vectorize',
|
id: 'image-vectorize',
|
||||||
name: '位图转矢量',
|
name: '位图转矢量',
|
||||||
version: '__PLUGIN_VERSION__',
|
version: '__PLUGIN_VERSION__',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
|
skin: 'private',
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
preset: { type: 'string', default: 'text' },
|
preset: { type: 'string', default: 'text' },
|
||||||
|
|||||||
@@ -16,15 +16,15 @@
|
|||||||
.vz-modal {
|
.vz-modal {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 92vw;
|
width: 100vw;
|
||||||
height: 88vh;
|
height: 100vh;
|
||||||
min-width: 760px;
|
min-width: 0;
|
||||||
min-height: 520px;
|
min-height: 0;
|
||||||
max-width: 1680px;
|
max-width: none;
|
||||||
background: #1b1b22;
|
background: #1b1b22;
|
||||||
border: 1px solid #33333f;
|
border: 0;
|
||||||
border-radius: 12px;
|
border-radius: 0;
|
||||||
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
|
box-shadow: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +75,16 @@
|
|||||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||||
.vz-btn:active { background: #2f2f3a; }
|
.vz-btn:active { background: #2f2f3a; }
|
||||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||||
/* 顶栏四颗按钮统一走上面这套描边配色(曾经有一颗 .vz-btn-primary 绿色主按钮,
|
/* 顶栏「保存为节点 / 复制 SVG / 下载 SVG」三颗走上面这套灰色描边配色。
|
||||||
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
「关闭」单独用编辑器主色调(.vz-seg 选中态同款 #33566f)填充,与产出操作区分、防误点。
|
||||||
|
2026-11-19:原「取消」改名「关闭」并按主色调取色(行为不变,仍是 data-act="cancel" 退出编辑器)。 */
|
||||||
|
.vz-btn-close {
|
||||||
|
background: #33566f;
|
||||||
|
border-color: #33566f;
|
||||||
|
color: #eaf6ff;
|
||||||
|
}
|
||||||
|
.vz-btn-close:hover { background: #3d6480; border-color: #4a7394; }
|
||||||
|
.vz-btn-close:active { background: #2c4a60; }
|
||||||
|
|
||||||
/* ---------- 主体 ---------- */
|
/* ---------- 主体 ---------- */
|
||||||
.vz-body {
|
.vz-body {
|
||||||
@@ -512,7 +520,7 @@
|
|||||||
|
|
||||||
/* 窄屏:面板转到底部 */
|
/* 窄屏:面板转到底部 */
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.vz-modal { width: 96vw; height: 92vh; min-width: 0; }
|
.vz-modal { width: 100vw; height: 100vh; min-width: 0; }
|
||||||
.vz-body { flex-direction: column; }
|
.vz-body { flex-direction: column; }
|
||||||
.vz-panel { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid #2e2e3a; }
|
.vz-panel { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid #2e2e3a; }
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ function viewHTML(name) {
|
|||||||
'<button type="button" class="vz-btn" data-act="save">保存为节点</button>' +
|
'<button type="button" class="vz-btn" data-act="save">保存为节点</button>' +
|
||||||
'<button type="button" class="vz-btn" data-act="copy">复制 SVG</button>' +
|
'<button type="button" class="vz-btn" data-act="copy">复制 SVG</button>' +
|
||||||
'<button type="button" class="vz-btn" data-act="svg">下载 SVG</button>' +
|
'<button type="button" class="vz-btn" data-act="svg">下载 SVG</button>' +
|
||||||
'<button type="button" class="vz-btn" data-act="cancel">取消</button>' +
|
'<button type="button" class="vz-btn vz-btn-close" data-act="cancel">关闭</button>' +
|
||||||
'</header>' +
|
'</header>' +
|
||||||
'<div class="vz-body">' +
|
'<div class="vz-body">' +
|
||||||
'<div class="vz-preview" data-preview>' +
|
'<div class="vz-preview" data-preview>' +
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
// ⚠️ 因此本文件的注释里不要写出那种字面量形态(会抢先匹配),要描述就直接说「id 字面量」。
|
||||||
//
|
//
|
||||||
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
// 版本占位符由构建脚本用 package.json 的 version 替换,保证两处永不漂移。
|
||||||
|
// skin: 'private' = 自绘深色工具 UI(#1b1b22 系列),不跟随宿主主题。
|
||||||
|
// 代价由宿主契约测试钉死:声明 private 的插件不得引用宿主颜色 var(--iwb-*),只能自洽。
|
||||||
var __IWB_VECTORIZE_MANIFEST__ = {
|
var __IWB_VECTORIZE_MANIFEST__ = {
|
||||||
id: 'image-vectorize',
|
id: 'image-vectorize',
|
||||||
name: '位图转矢量',
|
name: '位图转矢量',
|
||||||
version: '0.4.2',
|
version: '0.6.1',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
|
skin: 'private',
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
preset: { type: 'string', default: 'text' },
|
preset: { type: 'string', default: 'text' },
|
||||||
@@ -2023,15 +2026,15 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
.vz-modal {
|
.vz-modal {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 92vw;
|
width: 100vw;
|
||||||
height: 88vh;
|
height: 100vh;
|
||||||
min-width: 760px;
|
min-width: 0;
|
||||||
min-height: 520px;
|
min-height: 0;
|
||||||
max-width: 1680px;
|
max-width: none;
|
||||||
background: #1b1b22;
|
background: #1b1b22;
|
||||||
border: 1px solid #33333f;
|
border: 0;
|
||||||
border-radius: 12px;
|
border-radius: 0;
|
||||||
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
|
box-shadow: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2082,8 +2085,16 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||||
.vz-btn:active { background: #2f2f3a; }
|
.vz-btn:active { background: #2f2f3a; }
|
||||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||||
/* 顶栏四颗按钮统一走上面这套描边配色(曾经有一颗 .vz-btn-primary 绿色主按钮,
|
/* 顶栏「保存为节点 / 复制 SVG / 下载 SVG」三颗走上面这套灰色描边配色。
|
||||||
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
「关闭」单独用编辑器主色调(.vz-seg 选中态同款 #33566f)填充,与产出操作区分、防误点。
|
||||||
|
2026-11-19:原「取消」改名「关闭」并按主色调取色(行为不变,仍是 data-act="cancel" 退出编辑器)。 */
|
||||||
|
.vz-btn-close {
|
||||||
|
background: #33566f;
|
||||||
|
border-color: #33566f;
|
||||||
|
color: #eaf6ff;
|
||||||
|
}
|
||||||
|
.vz-btn-close:hover { background: #3d6480; border-color: #4a7394; }
|
||||||
|
.vz-btn-close:active { background: #2c4a60; }
|
||||||
|
|
||||||
/* ---------- 主体 ---------- */
|
/* ---------- 主体 ---------- */
|
||||||
.vz-body {
|
.vz-body {
|
||||||
@@ -2519,7 +2530,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
|
|
||||||
/* 窄屏:面板转到底部 */
|
/* 窄屏:面板转到底部 */
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.vz-modal { width: 96vw; height: 92vh; min-width: 0; }
|
.vz-modal { width: 100vw; height: 100vh; min-width: 0; }
|
||||||
.vz-body { flex-direction: column; }
|
.vz-body { flex-direction: column; }
|
||||||
.vz-panel { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid #2e2e3a; }
|
.vz-panel { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid #2e2e3a; }
|
||||||
}
|
}
|
||||||
@@ -3016,7 +3027,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
}).join("") + '</div></div><div class="vz-row vz-row-switch"><div class="vz-row-text">按孤岛拆分<span>每个连通块一个图层,粘到 Figma 可单独选中;笔画不连的汉字会分成几块</span></div><label class="vz-switch"><input type="checkbox" data-check="splitIslands"' + (params.splitIslands ? " checked" : "") + '><i></i></label></div></div><div class="vz-group"><div class="vz-stats"><span><b data-stat="elements">–</b> 元素</span><span><b data-stat="levels">–</b> 层</span><span><b data-stat="bytes">–</b></span><span><b data-stat="ms">–</b></span></div></div><div class="vz-group"><button type="button" class="vz-adv-toggle" data-act="adv" aria-expanded="' + (advOpen ? "true" : "false") + '">高级参数<span data-adv-caret>' + (advOpen ? "▴" : "▾") + '</span></button><div class="vz-adv" data-adv' + (advOpen ? "" : " hidden") + '><div class="vz-row"><div class="vz-row-label">阈值<span>自动按直方图取,手动可救极端图</span></div><div class="vz-seg" data-seg-group="thrMode"><button type="button" data-seg="thrMode" data-value="auto">自动</button><button type="button" data-seg="thrMode" data-value="manual">手动</button></div></div><div data-thr-row hidden>' + rangeHTML("threshold", "阈值取值", 0, 255, 1, params.threshold >= 0 ? params.threshold : 128, "") + '</div><div class="vz-row"><div class="vz-row-label">反相<span>黑底白字时打开</span></div><div class="vz-seg" data-seg-group="invert">' + segHTML("invert", [["0", "正片"], ["1", "负片"]], params.invert ? 1 : 0) + '</div></div><div class="vz-row"><div class="vz-row-label">填充 / 背景<span>填充仅「纯单色」生效 · 背景作预览底</span></div><div class="vz-swatches"><input type="color" class="vz-color" data-color="color" value="' + esc(params.color) + '" title="填充色(纯单色生效)"><input type="color" class="vz-color" data-color="bg" value="' + esc(params.bg) + '" title="背景色(预览底;勾「带底」写入导出)"><label class="vz-mini" title="导出 / 复制时把背景色一起写进 SVG(默认不带,粘到 Figma 是透明底)"><input type="checkbox" data-check="bgExport"' + (params.bgExport ? " checked" : "") + "><span>带底</span></label></div></div></div></div>";
|
}).join("") + '</div></div><div class="vz-row vz-row-switch"><div class="vz-row-text">按孤岛拆分<span>每个连通块一个图层,粘到 Figma 可单独选中;笔画不连的汉字会分成几块</span></div><label class="vz-switch"><input type="checkbox" data-check="splitIslands"' + (params.splitIslands ? " checked" : "") + '><i></i></label></div></div><div class="vz-group"><div class="vz-stats"><span><b data-stat="elements">–</b> 元素</span><span><b data-stat="levels">–</b> 层</span><span><b data-stat="bytes">–</b></span><span><b data-stat="ms">–</b></span></div></div><div class="vz-group"><button type="button" class="vz-adv-toggle" data-act="adv" aria-expanded="' + (advOpen ? "true" : "false") + '">高级参数<span data-adv-caret>' + (advOpen ? "▴" : "▾") + '</span></button><div class="vz-adv" data-adv' + (advOpen ? "" : " hidden") + '><div class="vz-row"><div class="vz-row-label">阈值<span>自动按直方图取,手动可救极端图</span></div><div class="vz-seg" data-seg-group="thrMode"><button type="button" data-seg="thrMode" data-value="auto">自动</button><button type="button" data-seg="thrMode" data-value="manual">手动</button></div></div><div data-thr-row hidden>' + rangeHTML("threshold", "阈值取值", 0, 255, 1, params.threshold >= 0 ? params.threshold : 128, "") + '</div><div class="vz-row"><div class="vz-row-label">反相<span>黑底白字时打开</span></div><div class="vz-seg" data-seg-group="invert">' + segHTML("invert", [["0", "正片"], ["1", "负片"]], params.invert ? 1 : 0) + '</div></div><div class="vz-row"><div class="vz-row-label">填充 / 背景<span>填充仅「纯单色」生效 · 背景作预览底</span></div><div class="vz-swatches"><input type="color" class="vz-color" data-color="color" value="' + esc(params.color) + '" title="填充色(纯单色生效)"><input type="color" class="vz-color" data-color="bg" value="' + esc(params.bg) + '" title="背景色(预览底;勾「带底」写入导出)"><label class="vz-mini" title="导出 / 复制时把背景色一起写进 SVG(默认不带,粘到 Figma 是透明底)"><input type="checkbox" data-check="bgExport"' + (params.bgExport ? " checked" : "") + "><span>带底</span></label></div></div></div></div>";
|
||||||
}
|
}
|
||||||
function viewHTML(name) {
|
function viewHTML(name) {
|
||||||
return '<div class="vz-root"><div class="vz-modal" role="dialog" aria-modal="true" aria-label="位图转矢量"><header class="vz-header"><span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span><div class="vz-spacer"></div><button type="button" class="vz-btn" data-act="save">保存为节点</button><button type="button" class="vz-btn" data-act="copy">复制 SVG</button><button type="button" class="vz-btn" data-act="svg">下载 SVG</button><button type="button" class="vz-btn" data-act="cancel">取消</button></header><div class="vz-body"><div class="vz-preview" data-preview><img class="vz-stage" data-stage="vector" alt="矢量预览" draggable="false"><img class="vz-stage" data-stage="original" alt="原图" draggable="false" hidden><div class="vz-badge" data-badge>矢量预览</div><div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div><div class="vz-hint">空格 对比原图 · 滚轮缩放 · 拖动平移 · 双击复位</div><div class="vz-zoom" data-zoom-chip hidden title="点击回到 100%"><b data-zoom-val>100%</b><span>复位</span></div></div><aside class="vz-panel" data-panel></aside></div></div></div>';
|
return '<div class="vz-root"><div class="vz-modal" role="dialog" aria-modal="true" aria-label="位图转矢量"><header class="vz-header"><span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span><div class="vz-spacer"></div><button type="button" class="vz-btn" data-act="save">保存为节点</button><button type="button" class="vz-btn" data-act="copy">复制 SVG</button><button type="button" class="vz-btn" data-act="svg">下载 SVG</button><button type="button" class="vz-btn vz-btn-close" data-act="cancel">关闭</button></header><div class="vz-body"><div class="vz-preview" data-preview><img class="vz-stage" data-stage="vector" alt="矢量预览" draggable="false"><img class="vz-stage" data-stage="original" alt="原图" draggable="false" hidden><div class="vz-badge" data-badge>矢量预览</div><div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div><div class="vz-hint">空格 对比原图 · 滚轮缩放 · 拖动平移 · 双击复位</div><div class="vz-zoom" data-zoom-chip hidden title="点击回到 100%"><b data-zoom-val>100%</b><span>复位</span></div></div><aside class="vz-panel" data-panel></aside></div></div></div>';
|
||||||
}
|
}
|
||||||
var ALPHA_TONE = { hard: 0.4, normal: 1, round: 1.2 };
|
var ALPHA_TONE = { hard: 0.4, normal: 1, round: 1.2 };
|
||||||
var toneOf = (alphaMax) => alphaMax <= 0.6 ? "hard" : alphaMax >= 1.1 ? "round" : "normal";
|
var toneOf = (alphaMax) => alphaMax <= 0.6 ? "hard" : alphaMax >= 1.1 ? "round" : "normal";
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# promptlib 样式基线(重要)
|
||||||
|
|
||||||
|
- 正确基线:**v1.8.8**(commit `178b36c`)
|
||||||
|
- 当前 v1.8.17 的样式与 1.8.8 视觉一致,仅颜色做了 `var(--plp-cN, #原色)` 兜底包装
|
||||||
|
- 禁止批量改写颜色 token / 重写 CSS 声明(曾导致文字不可见、灰块、伪类失效)
|
||||||
|
- 插入变量:禁止在 blur 记录选区;用 `execCommand("insertText")` 在光标处插入
|
||||||
|
- 改样式后必须截图核对再发市场
|
||||||
|
|
||||||
|
详细说明见桌面仓 `docs/standards/promptlib-style-baseline.md`。
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# promptlib Token 迁移映射表(第一批:颜色)
|
||||||
|
|
||||||
|
> 依据:`image-workbench-desktop/docs/standards/design-tokens.md` 与 `plugin-theme.md`。
|
||||||
|
> 原则:**视觉目标仍是 1.8.8 基线**;先迁颜色(语义明确),尺寸后续单独批次 + 截图 diff。
|
||||||
|
|
||||||
|
## 1. 颜色映射(已落地 1.8.22)
|
||||||
|
|
||||||
|
| 原值 | Token | 用途 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `#fff` / `#ffffff`(background) | `--iwb-plugin-card` | 卡片/弹窗内白底 |
|
||||||
|
| `#fbfcfd` / `#fcfcfd` | `--iwb-field` | 输入框/编辑区底 |
|
||||||
|
| `#fafafb` / `#fafbfc` | `--iwb-plugin-surface` | 面板根 |
|
||||||
|
| `#f5f6f7` `#f3f4f7` `#f2f4f7` `#eef0f4` `#f4f5f7` `#f4f6f9` `#f1f3f5` | `--iwb-plugin-inset` | 内嵌/分组底 |
|
||||||
|
| `#eef0f3` `#eef1f4` `#e9ecf1` `#e7e9ee` `#d7dbe2` | `--iwb-plugin-hover` | 悬停/次级块 |
|
||||||
|
| `#d5d9e0` `#e3e5e9` `#e6e8ec` `#eceef2` `#e2e6ec` `#e8eaee` `#eef0f2` `#dfe3e9` `#f1f3f5` `#f3f5f8` `#eef0f3` | `--iwb-plugin-border` | 常规描边/分割线 |
|
||||||
|
| `#b9bfca` `#c2c7cf` `#9aa3ad` | `--iwb-border2` | 强调描边 |
|
||||||
|
| `#1d2129` `#1c2333` `#2f3540` `#3f4450` `#3a4048` `#33383f` | `--iwb-text` | 主文字 |
|
||||||
|
| `#5b6472` `#4d5668` `#8b929c` `#8a919c` | `--iwb-text2` | 次要文字 |
|
||||||
|
| `#9aa1ac` `#aab0ba` `#b3b9c2` `#c2c7cf` | `--iwb-text-dim` | 占位/弱说明 |
|
||||||
|
| `#5a3fd0` `#5a4bd0` `#7c4dff` `#6b4dff` `#8b7ff0` | `--iwb-plp-accent` | 插件强调色(高饱和,允许自有) |
|
||||||
|
| `#f1ecff` `#f4f0ff` | `--iwb-plp-accent-soft` | 强调色浅底 |
|
||||||
|
| `#cfc3ff` `#d8cbff` `#d9d3ff` | `--iwb-plp-accent-border` | 强调色描边 |
|
||||||
|
| `#d97706` | `--iwb-warn` | 警告 |
|
||||||
|
| `#c0392b` | `--iwb-err` | 错误/删除 |
|
||||||
|
|
||||||
|
白色文字(压在封面/渐变上)保留 `#fff`,属内容色。
|
||||||
|
|
||||||
|
## 2. 尺寸迁移(已完成 1.8.23)
|
||||||
|
|
||||||
|
迁移结果:promptlib 散值清零(字号/圆角/间距全部落入闭集),棘轮基线已下调;视觉对比无换行/溢出。
|
||||||
|
|
||||||
|
| 类别 | 目标闭集 | 归并规则 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 字号 | 11/12/13/14/15/17/20/24 | 10→11、10.5→11、11.5→12、12.5→13、13.5→14、16→15、18→17 |
|
||||||
|
| 圆角 | 6/8/10/12/14/999 | 2/3/4→6、7/9→8、11→10、16→14 |
|
||||||
|
| 间距 | 0/2/4/6/8/10/12/16/20/24/32/40/48/64 | 1→2、3→4、5→6、7→6、9→8、14→12、18→16 |
|
||||||
|
|
||||||
|
尺寸批次要求:亮/暗两套截图 diff + 逐项确认后再发布。
|
||||||
|
|
||||||
|
## 3. 复查命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node scripts/token-audit.js --plugins
|
||||||
|
node tests/plugin-theme-contract-test.js
|
||||||
|
node tests/plugin-scale-contract-test.js
|
||||||
|
npm run test:visual
|
||||||
|
```
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/promptlib",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.11.0",
|
||||||
|
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "promptlib",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,579 @@
|
|||||||
|
.iwb-promptlib, .iwb-plp-dialog, .iwb-plp-mask, .iwb-plp-dragghost, .iwb-plp-placebox{--iwb-plp-accent:#6b4dff;--iwb-plp-accent-soft:#f1ecff;--iwb-plp-accent-border:#d9d3ff}
|
||||||
|
/* promptlib(提示词库)自带样式
|
||||||
|
作用域全部带 .iwb-plp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||||
|
|
||||||
|
/* 分组胶囊「适应面板宽度」自动换行。
|
||||||
|
宿主的 .iwb-lib-chips 是 flex-wrap: nowrap(配 .iwb-lib-chips-scroll 做单行横向滚动 + 右侧渐隐),
|
||||||
|
分组多时靠后的分类看不见也点不到。双类选择器提高优先级(不依赖样式注入顺序)。 */
|
||||||
|
.iwb-lib-chips.iwb-plp-chips {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
row-gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* + / ⚙ 是动作按钮,不是分组名:不参与压缩,并与最后一个分组稍作分隔 */
|
||||||
|
.iwb-plp-chips .iwb-plp-add {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* v1.0.2(2026-11-21):卡片化 —— 白卡 + 悬停 + 文本三行截断。
|
||||||
|
颜色一律走宿主 --iwb-plugin-* / --iwb-* token,不在插件里写死。 */
|
||||||
|
.iwb-promptlib .iwb-pname { font-weight: 600; }
|
||||||
|
.iwb-promptlib .iwb-ptext {
|
||||||
|
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
|
||||||
|
overflow: hidden; color: var(--iwb-text2, #4d5668);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-cards { gap: 8px; }
|
||||||
|
|
||||||
|
/* v1.1.0(2026-11-21):封面网格 + 长文详情 + 宽编辑弹窗。
|
||||||
|
颜色全部走宿主 token,不写死。 */
|
||||||
|
.iwb-plp-card {
|
||||||
|
position: relative; border-radius: 10px; overflow: hidden; cursor: pointer;
|
||||||
|
aspect-ratio: 1 / 1; border: 1px solid var(--iwb-border, #d5d9e0);
|
||||||
|
transition: border-color .12s ease, transform .12s ease;
|
||||||
|
}
|
||||||
|
.iwb-plp-card:hover { border-color: var(--iwb-border2, #b9bfca); }
|
||||||
|
.iwb-plp-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||||
|
.iwb-plp-t {
|
||||||
|
position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 6px 6px;
|
||||||
|
background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,.66));
|
||||||
|
color: var(--plp-c1, #fff); font-size: 11px; line-height: 1.35; max-height: 48%;
|
||||||
|
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
|
||||||
|
text-shadow: 0 1px 2px rgba(0,0,0,.35);
|
||||||
|
}
|
||||||
|
/* 详情:长文阅读 */
|
||||||
|
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 2px 0 8px; position: sticky; top: 0; z-index: 2; background: var(--iwb-plugin-surface, #fafafb); }
|
||||||
|
.iwb-plp-dtop { align-items: flex-start; gap: 10px; margin-bottom: 8px; }
|
||||||
|
.iwb-plp-dthumb { flex: 0 0 84px; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--iwb-border, #d5d9e0); }
|
||||||
|
.iwb-plp-dmeta { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
|
||||||
|
.iwb-plp-dtitle { font-size: 13px; font-weight: 600; color: var(--iwb-text, #1c2333); line-height: 1.45; }
|
||||||
|
.iwb-plp-dtext {
|
||||||
|
font-size: 12px; line-height: 1.75; color: var(--iwb-text2, #4d5668);
|
||||||
|
white-space: pre-wrap; word-break: break-word; padding: 4px 0 12px;
|
||||||
|
}
|
||||||
|
.iwb-plp-dfoot { display: flex; align-items: center; gap: 6px; padding: 8px 0 2px; position: sticky; bottom: 0; background: var(--iwb-plugin-surface, #fafafb); }
|
||||||
|
/* 编辑弹窗:760 宽 + 大文本框 */
|
||||||
|
.iwb-promptlib-editor { width: 760px; max-width: 94vw; }
|
||||||
|
.iwb-promptlib-editor .iwb-modal-body { max-height: 78vh; }
|
||||||
|
.iwb-promptlib-text { min-height: 360px; height: 44vh; font-size: 13px; line-height: 1.9; resize: vertical; }
|
||||||
|
.iwb-plp-editor-cover { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
|
||||||
|
.iwb-plp-editor-thumb { flex: 0 0 96px; width: 96px; height: 128px; border-radius: 8px; overflow: hidden; border: 1px solid var(--iwb-border, #d5d9e0); }
|
||||||
|
.iwb-plp-editor-coverops { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
|
||||||
|
/* v1.2.0:可拖动 / 可缩放的详情与编辑弹窗(同宽 880×640,最小 640×420) */
|
||||||
|
.iwb-plp-mask { background: transparent; display: block; }
|
||||||
|
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 14px;
|
||||||
|
box-shadow: 0 24px 60px rgba(0,0,0,.28); }
|
||||||
|
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 10px 12px;
|
||||||
|
border-bottom: 1px solid var(--iwb-border, #d5d9e0); cursor: move; user-select: none; }
|
||||||
|
.iwb-plp-grip { display: grid; grid-template-columns: repeat(3, 3px); gap: 2px; margin-right: 6px; }
|
||||||
|
.iwb-plp-grip i { width: 3px; height: 3px; border-radius: 50%; background: var(--iwb-border2, #b9bfca); display: block; }
|
||||||
|
.iwb-plp-dbody { flex: 1 1 auto; min-height: 0; display: flex; gap: 12px; padding: 12px; }
|
||||||
|
.iwb-plp-dcov { flex: 0 0 210px; width: 210px; height: 280px; border-radius: 10px; overflow: hidden;
|
||||||
|
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||||
|
.iwb-plp-dright { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.iwb-plp-dtext { flex: 1 1 auto; min-height: 0; overflow: auto; white-space: pre-wrap; word-break: break-word;
|
||||||
|
font-size: 12px; line-height: 1.9; color: var(--iwb-text2, #4d5668); }
|
||||||
|
.iwb-plp-dfooter { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
|
||||||
|
border-top: 1px solid var(--iwb-border, #d5d9e0); }
|
||||||
|
.iwb-plp-resize { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize;
|
||||||
|
background: linear-gradient(135deg, transparent 0 45%, var(--iwb-border2, #b9bfca) 45% 50%, transparent 50% 62%, var(--iwb-border2, #b9bfca) 62% 67%, transparent 67%); }
|
||||||
|
/* 编辑:左栏固定 240,右栏大文本框 */
|
||||||
|
.iwb-plp-eleft { flex: 0 0 240px; width: 240px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
|
||||||
|
.iwb-plp-ecov { width: 240px; height: 300px; border-radius: 10px; overflow: hidden;
|
||||||
|
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||||
|
.iwb-plp-lrow { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--iwb-text2, #4d5668); }
|
||||||
|
.iwb-plp-etext { flex: 1 1 auto; min-height: 0; height: auto; resize: none; font-size: 12px; line-height: 1.9; }
|
||||||
|
/* 输入框边框柔化(用户反馈现在的边框太深) */
|
||||||
|
.iwb-plp-dialog .iwb-input { border-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 72%, transparent); }
|
||||||
|
.iwb-plp-dialog .iwb-input:focus { border-color: var(--iwb-brand, #6b7280); box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-brand, #6b7280) 14%, transparent); }
|
||||||
|
|
||||||
|
/* v1.2.1:去掉弹窗里多余的线框(用户反馈“线框太多、太明显”) */
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov,
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov { border-color: transparent; }
|
||||||
|
.iwb-plp-dialog .iwb-plp-dhead { border-bottom-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 45%, transparent); }
|
||||||
|
.iwb-plp-dialog .iwb-plp-dfooter { border-top-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 45%, transparent); }
|
||||||
|
/* 输入框:默认无边框,用浅底区分;聚焦才出现细描边 */
|
||||||
|
.iwb-plp-dialog .iwb-input {
|
||||||
|
border-color: transparent;
|
||||||
|
background: var(--iwb-plugin-inset, #f5f6f7);
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog .iwb-input:hover { background: var(--iwb-plugin-hover, #eef1f4); }
|
||||||
|
.iwb-plp-dialog .iwb-input:focus {
|
||||||
|
background: var(--iwb-panel, #fff);
|
||||||
|
border-color: color-mix(in srgb, var(--iwb-brand, #6b7280) 55%, transparent);
|
||||||
|
box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-brand, #6b7280) 12%, transparent);
|
||||||
|
}
|
||||||
|
/* 正文编辑区:无边框、无底色,像一张纸 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-etext { border-color: transparent; background: transparent; box-shadow: none; }
|
||||||
|
.iwb-plp-dialog .iwb-plp-etext:focus { border-color: transparent; box-shadow: none; background: transparent; }
|
||||||
|
/* 左侧封面区的两个按钮:去掉按钮描边,弱化成文字按钮 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-eleft .iwb-btn { border-color: transparent; background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||||
|
.iwb-plp-dialog .iwb-plp-eleft .iwb-btn:hover { background: var(--iwb-plugin-hover, #eef1f4); }
|
||||||
|
|
||||||
|
/* v1.3.3:封面比例不定 —— 详情/编辑里完整显示(contain,不裁切);列表保持方形裁切(网格整齐) */
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov img,
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov img { object-fit: contain; background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov,
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov { background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||||
|
.iwb-plp-card .iwb-plp-cover { object-fit: cover; object-position: center; }
|
||||||
|
|
||||||
|
/* v1.3.4:瀑布流(列式)+ 卡片定宽不随面板拉伸;面板底色统一走 --iwb-plugin-surface */
|
||||||
|
.iwb-promptlib .iwb-plp-card {
|
||||||
|
display: inline-block; width: 100%; margin: 0 0 8px;
|
||||||
|
break-inside: avoid; -webkit-column-break-inside: avoid;
|
||||||
|
aspect-ratio: auto; /* 高度交给图片原始比例 */
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-plp-cover { width: 100%; height: auto; object-fit: contain; }
|
||||||
|
/* 统一插件灰:面板底(宿主会给 --iwb-plugin-surface,这里只留兜底) */
|
||||||
|
.iwb-promptlib { background: transparent; }
|
||||||
|
|
||||||
|
/* v1.3.5:无封面的提示词也给一个方形占位(否则瀑布流里会塌成一条线) */
|
||||||
|
.iwb-promptlib .iwb-plp-card.no-cover { aspect-ratio: 1 / 1; }
|
||||||
|
.iwb-promptlib .iwb-plp-card.no-cover .iwb-plp-t { max-height: 60%; }
|
||||||
|
|
||||||
|
/* v1.4.7:恢复瀑布流列规则(1.4.0 清理 CSS 时把这组规则一起删掉了,列表退化成单列、卡片被拉满宽) */
|
||||||
|
.iwb-promptlib .iwb-lib-cards { display: block; column-width: 122px; column-gap: 8px; grid-template-columns: none; }
|
||||||
|
.iwb-promptlib .iwb-plp-card { display: inline-block; width: 100%; margin: 0 0 8px; break-inside: avoid; -webkit-column-break-inside: avoid; aspect-ratio: auto; }
|
||||||
|
.iwb-promptlib .iwb-plp-cover { width: 100%; height: auto; object-fit: contain; }
|
||||||
|
.iwb-promptlib .iwb-plp-card.no-cover { aspect-ratio: 1 / 1; }
|
||||||
|
|
||||||
|
/* v1.5.0:模板节点 + 变量标记 */
|
||||||
|
.iwb-plp-vdot{position:absolute;right:8px;top:8px;width:7px;height:7px;border-radius:50%;background:var(--iwb-plp-accent, #7c4dff);box-shadow:0 0 0 2px var(--iwb-plp-dot-ring, rgba(255,255,255,.75))}
|
||||||
|
.iwb-plp-node{display:flex;flex-direction:column;gap:6px;padding:8px 10px;font-size:12px;color:var(--iwb-text,#1c2333)}
|
||||||
|
.iwb-plp-nhead{display:flex;align-items:center;gap:8px}
|
||||||
|
.iwb-plp-nthumb{width:44px;height:44px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
||||||
|
.iwb-plp-ntitle{font-weight:600;font-size: 13px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
||||||
|
.iwb-plp-nvars{display:flex;flex-direction:column;gap:4px}
|
||||||
|
.iwb-plp-nrow{display:flex;align-items:center;gap:6px;height:26px}
|
||||||
|
.iwb-plp-nk{width:64px;flex:0 0 64px;color:var(--iwb-text2,#5b6472);font-size: 12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.iwb-plp-nin{flex:1;height:24px;font-size: 12px}
|
||||||
|
.iwb-plp-nref{display:flex;align-items:center;gap:6px;font-size: 12px;color:var(--iwb-text2,#5b6472);border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px}
|
||||||
|
.iwb-plp-nref em{font-style:normal;color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-nprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;color:var(--iwb-text2,#5b6472);font-size: 12px;line-height:1.6;max-height:88px;overflow:hidden}
|
||||||
|
|
||||||
|
/* v1.5.0:变量编辑器 / 详情变量 */
|
||||||
|
.iwb-plp-emid{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}
|
||||||
|
.iwb-plp-vars{border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px;display:flex;flex-direction:column;gap:6px;background:var(--iwb-plugin-surface,#fff)}
|
||||||
|
.iwb-plp-vhead{display:flex;align-items:center;gap:8px;font-size: 12px;color:var(--iwb-text2,#5b6472)}
|
||||||
|
.iwb-plp-vhint{color:var(--iwb-text2,#8b929c);font-size:11px}
|
||||||
|
.iwb-plp-vchips{display:flex;flex-wrap:wrap;gap:6px}
|
||||||
|
.iwb-plp-vchip{display:inline-flex;align-items:center;gap:4px;padding: 2px 6px;border-radius:6px;background:color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 10%, transparent);color:var(--iwb-plp-accent, #5a4bd0);font-size: 12px}
|
||||||
|
.iwb-plp-vx{font-style:normal;cursor:pointer;color:var(--iwb-plp-accent, #8b7ff0);font-weight:700}
|
||||||
|
.iwb-plp-vrows{display:flex;flex-direction:column;gap: 6px}
|
||||||
|
.iwb-plp-vrow{display:flex;align-items:center;gap:8px}
|
||||||
|
.iwb-plp-vk{width:92px;flex:0 0 92px;font-size: 12px;color:var(--iwb-text2,#5b6472);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.iwb-plp-vin{flex:1;height:26px;font-size: 12px}
|
||||||
|
.iwb-plp-vprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;font-size: 12px;line-height:1.6;color:var(--iwb-text2,#5b6472);max-height:72px;overflow:auto;white-space:pre-wrap}
|
||||||
|
.iwb-plp-dvars{display:flex;flex-direction:column;gap: 6px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
|
||||||
|
|
||||||
|
/* v1.5.6:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
|
||||||
|
.iwb-plp-nthumb{width:56px;height:56px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
||||||
|
.iwb-plp-ntitlebox{min-width:0;display:flex;flex-direction:column;gap:2px}
|
||||||
|
.iwb-plp-ntitle{font-weight:600;font-size: 13px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
||||||
|
.iwb-plp-nmeta{font-size: 11px;color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-nempty{font-size:11px;color:var(--iwb-text2,#8b929c);padding:2px 0}
|
||||||
|
.iwb-plp-nwarn{font-size:11px;line-height:1.5;color:var(--iwb-warn,#d97706)}
|
||||||
|
|
||||||
|
/* v1.5.10:设置页 */
|
||||||
|
.iwb-plp-settings{display:flex;flex-direction:column;gap: 16px}
|
||||||
|
/* 2026-11-24:插件设置页跟随宿主的设置分组 token(不再自画卡片,避免卡片套卡片) */
|
||||||
|
.iwb-plp-ssec{border:0;border-top:1px solid var(--iwb-set-divider,var(--iwb-border,#e3e5e9));border-radius:0;padding:var(--iwb-space-12) 0 0;display:flex;flex-direction:column;gap:var(--iwb-space-8)}
|
||||||
|
.iwb-plp-ssec:first-child{border-top:0;padding-top:0}
|
||||||
|
.iwb-plp-stitle{font-weight:600;font-size:var(--iwb-font-md,13px);color:var(--iwb-text,#2a2f36)}
|
||||||
|
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-set-input-border,var(--iwb-border,#eef0f2));border-radius:var(--iwb-radius-card,10px);overflow:hidden}
|
||||||
|
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding: 6px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
|
||||||
|
.iwb-plp-sgrow:first-child{border-top:0}
|
||||||
|
.iwb-plp-sgrip{width:12px;height:12px;background:radial-gradient(var(--iwb-text2,#c2c7cf) 1px,transparent 1px);background-size:4px 4px;border-radius: 6px;flex:0 0 auto}
|
||||||
|
.iwb-plp-sgname{width:170px;height:26px;font-size:12px}
|
||||||
|
.iwb-plp-sgcount{font-size: 12px;color:var(--iwb-text2,#8b929c);width:56px}
|
||||||
|
.iwb-plp-sadd{display:flex;gap:8px;align-items:center}
|
||||||
|
.iwb-plp-sbtns{display:flex;gap:8px;align-items:center}
|
||||||
|
.iwb-plp-sopt{display:flex;gap:8px;align-items:center;font-size:12px;color:var(--iwb-text2,#4d5668)}
|
||||||
|
.iwb-plp-settings{max-height:calc(100vh - 230px);overflow:auto;padding-right:4px}
|
||||||
|
|
||||||
|
/* v1.6.2:正文上方工具行 */
|
||||||
|
.iwb-plp-etool{display:flex;align-items:center;gap:8px}
|
||||||
|
.iwb-plp-insvar{border:1px solid var(--iwb-plp-accent,#d9d3ff);background:color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 8%,transparent);color:var(--iwb-plp-accent,#5a4bd0);font-weight:600}
|
||||||
|
|
||||||
|
/* v1.6.5:宿主基础样式的插件作用域副本 —— 宿主改全局样式不再影响插件 */
|
||||||
|
.iwb-promptlib .iwb-grow {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-row {
|
||||||
|
display: flex; gap: 6px; align-items: center;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-hint {
|
||||||
|
font-size: 11px; color: var(--iwb-text2); margin-top: 4px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-toolbar-title {
|
||||||
|
font-weight: 700; font-size: 13px; margin-right: 2px;
|
||||||
|
}
|
||||||
|
.iwb-plp-mask {
|
||||||
|
position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300; display: flex; align-items: center; justify-content: center;
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog {
|
||||||
|
width: 680px; max-width: calc(100vw - 60px); max-height: 82vh; background: var(--iwb-panel); border: 1px solid var(--iwb-border2); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog-head {
|
||||||
|
display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--iwb-border);
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog-body {
|
||||||
|
padding: 12px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; max-height: 62vh;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-body {
|
||||||
|
flex: 1; overflow: hidden; padding: 12px 12px; display: flex; flex-direction: column; gap: 8px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-fixed {
|
||||||
|
flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-scroll {
|
||||||
|
flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-chips-scroll::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-chips-scroll > .iwb-chip:last-child {
|
||||||
|
margin-right: 16px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-searchscope-back {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; padding: 0; border: none; border-radius: 999px; background: transparent; color: var(--iwb-text2); font-size: 13px; line-height: 1; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-lib-searchscope-back:hover {
|
||||||
|
background: color-mix(in srgb, var(--iwb-text) 12%, transparent); color: var(--iwb-text);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip {
|
||||||
|
flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--iwb-text2); cursor: pointer; white-space: nowrap; transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip:hover {
|
||||||
|
color: var(--iwb-text); border-color: var(--iwb-border2);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip-active {
|
||||||
|
background: var(--iwb-panel); border-color: var(--iwb-border2); color: var(--iwb-text); font-weight: 600;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip-active:hover {
|
||||||
|
color: var(--iwb-text);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip-count {
|
||||||
|
font-size: 11px; opacity: 0.8;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-chip-add {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-pcard .iwb-btn:hover {
|
||||||
|
opacity: 1; color: var(--iwb-text); background: transparent;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-pcard .iwb-btn-starred {
|
||||||
|
color: var(--iwb-text); opacity: 1;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-pcard {
|
||||||
|
border: 1px solid var(--iwb-border); border-radius: 8px; padding: 8px 10px; background: var(--iwb-panel);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-tag {
|
||||||
|
display: inline-block; background: color-mix(in srgb, var(--iwb-text) 7%, transparent); color: var(--iwb-text2); border-radius: 6px; font-size: 11px; padding: 2px 6px; margin: 4px 4px 0 0;
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog-sm {
|
||||||
|
width: 460px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-pcard {
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-pcard:active {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-primary .iwb-ic {
|
||||||
|
width: 15px; height: 15px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn:hover {
|
||||||
|
border-color: var(--iwb-brand); color: var(--iwb-brand);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn:active {
|
||||||
|
transform: translateY(1px);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn:focus-visible {
|
||||||
|
outline: 2px solid color-mix(in srgb, var(--iwb-brand) 60%, transparent); outline-offset: 1px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn:disabled {
|
||||||
|
opacity: 0.45; cursor: not-allowed; transform: none;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-primary {
|
||||||
|
background: var(--iwb-brand); border-color: var(--iwb-brand); color: var(--iwb-on-brand);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-primary:hover {
|
||||||
|
background: color-mix(in srgb, var(--iwb-brand) 85%, var(--iwb-text)); border-color: var(--iwb-brand); color: var(--iwb-on-brand);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-sm {
|
||||||
|
padding: 4px 6px; font-size: 11px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-danger {
|
||||||
|
color: var(--iwb-err);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-btn-danger:hover {
|
||||||
|
border-color: var(--iwb-err); color: var(--iwb-err);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctxmenu {
|
||||||
|
position: fixed; min-width: 196px; max-width: 240px; max-height: calc(100vh - 24px); overflow-y: auto; padding: 6px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.28), 0 2px 8px rgba(0,0,0,0.16); z-index: 91; display: flex; flex-direction: column; gap: 2px;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-title {
|
||||||
|
font-size: 11px; font-weight: 700; color: var(--iwb-text2); letter-spacing: 1px; padding: 6px 10px 2px; text-transform: uppercase;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item {
|
||||||
|
display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border: none; border-radius: 8px; background: transparent; color: var(--iwb-text); font-size: 13px; cursor: pointer; text-align: left;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item .iwb-ic {
|
||||||
|
width: 14px; height: 14px; flex: 0 0 auto; color: var(--iwb-text2);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item:hover:not(:disabled) {
|
||||||
|
background: color-mix(in srgb, var(--iwb-brand) 12%, transparent); color: var(--iwb-text);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item:hover:not(:disabled) .iwb-ic {
|
||||||
|
color: var(--iwb-brand);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item:disabled {
|
||||||
|
opacity: 0.38; cursor: default;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger {
|
||||||
|
color: var(--iwb-err);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger .iwb-ic {
|
||||||
|
color: var(--iwb-err);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger:hover:not(:disabled) {
|
||||||
|
background: color-mix(in srgb, var(--iwb-err) 10%, transparent); color: var(--iwb-err);
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-ctx-sep {
|
||||||
|
height: 1px; margin: 4px 6px; background: var(--iwb-border); flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
.iwb-promptlib .iwb-drawer-spacer {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
/* v1.10.1:详情底部分享组(文本/文件分享)与插入组之间的竖向分割线 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-foot-vsep {
|
||||||
|
display: inline-block; width: 1px; height: 18px; flex: 0 0 auto;
|
||||||
|
align-self: center; margin: 0 12px; background: var(--iwb-border);
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog .iwb-section-sub {
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
.iwb-plp-mask.iwb-mask-ghost .iwb-settings-modal {
|
||||||
|
box-shadow: 0 24px 60px rgba(0,0,0,.32);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* v1.6.7:卡片长按可拖的视觉反馈 */
|
||||||
|
.iwb-plp-card{cursor:grab}
|
||||||
|
.iwb-plp-card.is-armed{border-color:var(--iwb-plp-accent,#7c4dff);box-shadow:0 0 0 2px color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 20%,transparent)}
|
||||||
|
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98);cursor:grabbing}
|
||||||
|
|
||||||
|
/* v1.6.8:卡片悬停放大 + 按下/拖拽反馈 */
|
||||||
|
.iwb-plp-card{transition:transform .14s ease, box-shadow .14s ease, border-color .14s ease, opacity .14s ease}
|
||||||
|
.iwb-plp-card:hover{transform:scale(1.03);box-shadow:0 8px 22px rgba(0,0,0,.14);z-index:2}
|
||||||
|
.iwb-plp-card.is-pressed{border-color:var(--iwb-plp-accent,#7c4dff);box-shadow:0 0 0 2px color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 22%,transparent)}
|
||||||
|
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98)}
|
||||||
|
|
||||||
|
/* v1.6.9:拖拽虚拟卡片(跟手预览) */
|
||||||
|
.iwb-plp-dragghost{width:168px;display:flex;align-items:center;gap:8px;padding:8px 10px;background:var(--iwb-panel,#fff);border:2px solid var(--iwb-plp-accent,#7c4dff);border-radius: 10px;box-shadow:0 12px 28px rgba(0,0,0,.22);font-size:12px;pointer-events:none;z-index: var(--iwb-z-anchor, 3200)}
|
||||||
|
.iwb-plp-ghostcov{width:38px;height:38px;border-radius:8px;object-fit:cover;flex:0 0 auto;background:var(--iwb-plugin-inset,#eef0f2)}
|
||||||
|
.iwb-plp-ghosttxt{min-width:0;display:flex;flex-direction:column;gap:2px}
|
||||||
|
.iwb-plp-ghostname{font-weight:600;color:var(--iwb-text,#1c2333);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.iwb-plp-ghosthint{font-size: 11px;color:var(--iwb-plp-accent,#5a4bd0)}
|
||||||
|
|
||||||
|
/* v1.6.10:悬停放大改为「内层背景层缩放」——卡片命中区域不变,渐变卡不再闪烁 */
|
||||||
|
.iwb-plp-bg{position:absolute;inset:0;overflow:hidden;border-radius:inherit;transition:transform .16s ease;will-change:transform;backface-visibility:hidden}
|
||||||
|
.iwb-plp-card:hover .iwb-plp-bg{transform:scale(1.045)}
|
||||||
|
.iwb-plp-card:hover{border-color:var(--iwb-border2,#b9bfca);box-shadow:0 8px 22px rgba(0,0,0,.14)}
|
||||||
|
/* 取消卡片本体的缩放/层级切换(闪烁与边缘点击丢失的来源) */
|
||||||
|
.iwb-plp-card{transform:none}
|
||||||
|
.iwb-plp-card:hover{transform:none;z-index:auto}
|
||||||
|
.iwb-plp-card.is-dragging{opacity:.55}
|
||||||
|
.iwb-plp-bg,.iwb-plp-cover{pointer-events:none}
|
||||||
|
|
||||||
|
/* v1.6.11:封面卡瀑布流高度由图片决定 —— 背景层必须是普通流,不能绝对定位(否则卡塌成一条线) */
|
||||||
|
.iwb-plp-bg{position:relative;inset:auto;width:100%}
|
||||||
|
.iwb-plp-card.no-cover .iwb-plp-bg{position:absolute;inset:0}
|
||||||
|
.iwb-plp-bg .iwb-plp-cover{width:100%;height:auto;object-fit:contain;display:block}
|
||||||
|
|
||||||
|
/* v1.6.13:未选中时变量输入框不拦截指针 —— 单击节点=选中/可拖动;选中后再点输入框编辑 */
|
||||||
|
.iwb-plp-node:not(.is-selected) input{pointer-events:none}
|
||||||
|
.iwb-plp-card{user-select:none}
|
||||||
|
body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webkit-user-select:none!important}
|
||||||
|
.iwb-plp-placeghost{border-style:dashed!important;pointer-events:none}
|
||||||
|
.iwb-plp-placehint{font-size: 11px;color:var(--iwb-plp-accent,#5a4bd0);margin-top:2px}
|
||||||
|
.iwb-plp-placebox{position:fixed;left:-9999px;top:0;z-index: var(--iwb-z-anchor, 3200);pointer-events:none;border:2px dashed var(--iwb-plp-accent,#6b4dff);border-radius:12px;background:color-mix(in srgb,var(--iwb-plp-accent,#6b4dff) 9%,transparent);display:flex;align-items:center;justify-content:center;box-shadow:0 10px 26px rgba(30,20,80,.10)}
|
||||||
|
.iwb-plp-placebox-t{font-size:12px;color:var(--iwb-plp-accent,#5a3fd0);background:rgba(255,255,255,.82);border-radius:999px;padding: 4px 10px}
|
||||||
|
/* v1.6.23:放置指示改为灰色小方框 */
|
||||||
|
.iwb-plp-placebox{border: 2px dashed var(--iwb-border2, #9aa3ad);border-radius:10px;background:rgba(122,130,142,.10);box-shadow:none}
|
||||||
|
.iwb-plp-placebox-t{font-size:11px;color: var(--plp-c3, #6b7280);background:rgba(255,255,255,.75);padding:2px 8px}
|
||||||
|
/* v1.7.0:编辑面板三栏 + 可拖宽;详情封面放大、变量高亮 */
|
||||||
|
.iwb-plp-eleft{flex:0 0 236px;width:236px}
|
||||||
|
.iwb-plp-emid{flex:1 1 auto;min-width:220px;display:flex;flex-direction:column;min-height:0}
|
||||||
|
.iwb-plp-emid .iwb-plp-etext{flex:1 1 auto;min-height:0;resize:none}
|
||||||
|
.iwb-plp-esplit{flex:0 0 10px;cursor:col-resize;display:flex;align-items:center;justify-content:center;border-radius:6px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||||
|
.iwb-plp-esplit:hover{background:var(--iwb-plugin-hover,#e9ecf1)}
|
||||||
|
.iwb-plp-eright{flex:0 0 auto;width:300px;min-width:190px;max-width:460px;display:flex;flex-direction:column;min-height:0;background:var(--iwb-plugin-surface,#fafbfc);border:1px solid var(--iwb-border,#e6e8ec);border-radius:10px;padding:8px}
|
||||||
|
.iwb-plp-vars{flex:1 1 auto;min-height:0;display:flex;flex-direction:column}
|
||||||
|
.iwb-plp-vrows{flex:1 1 auto;min-height:0;overflow:auto}
|
||||||
|
.iwb-plp-vitem{padding:4px 0;border-bottom:1px dashed var(--iwb-border,#eceef2)}
|
||||||
|
.iwb-plp-vrow2{display:flex;align-items:center;gap:6px}
|
||||||
|
.iwb-plp-vname{flex:1 1 auto;min-width:0;height:32px}
|
||||||
|
.iwb-plp-vi{flex:0 0 auto;width:24px;height:24px;padding:0;border-radius:50%;border:1px solid var(--iwb-border,#dfe3e9);background: var(--iwb-plugin-card, #fff);color: var(--iwb-text-dim, #9aa1ac);font-size:11px;line-height:22px;text-align:center}
|
||||||
|
.iwb-plp-vi.is-open{background: var(--iwb-plp-accent-soft, #f1ecff);border-color: var(--iwb-plp-accent-border, #d8cbff);color: var(--iwb-plp-accent, #5a3fd0)}
|
||||||
|
.iwb-plp-vdesc{width:100%;height:28px;margin-top: 6px;border-style:dashed;background: var(--iwb-field, #fbfcfd);font-size: 12px;color: var(--plp-c3, #6b7280)}
|
||||||
|
.iwb-plp-dcov{flex:0 0 auto;width:180px;height:180px;border-radius:12px;overflow:hidden}
|
||||||
|
.iwb-plp-dvar{background: var(--iwb-plp-accent-soft, #f1ecff);color: var(--iwb-plp-accent, #5a3fd0);border-radius: 6px;padding:0 4px;font-weight:500}
|
||||||
|
/* v1.7.1:编辑面板视觉精修——输入框比底色更亮、去多余边框、细分隔线 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-dbody{gap:10px;padding:12px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-eleft{flex:0 0 236px;width:236px;background: var(--iwb-plugin-card, #fff);border: 1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:12px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid{background: var(--iwb-plugin-card, #fff);border: 1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:10px 12px 12px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext{border: 1px solid var(--iwb-plugin-border, #eef0f3);background: var(--iwb-field, #fbfcfd);border-radius: 8px;padding:10px 12px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-esplit{flex:0 0 6px;background:transparent;border-radius: 6px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-esplit:hover{background: var(--iwb-plugin-hover, #e7e9ee)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-esplit::before{content:'';display:block;width:2px;height:30px;border-radius: 6px;background: var(--iwb-plugin-hover, #d7dbe2)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-eright{background:transparent;border:0;padding:2px 0 0}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vitem{border:0;padding:2px 0}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vrow2{gap:6px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vname{background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px;padding:0 10px;font-size: 13px;color: var(--iwb-text, #33383f)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vname:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vi{background:transparent;border:0;color: var(--iwb-text-dim, #aab0ba);width:22px;height:22px;line-height:20px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vi:hover{background: var(--iwb-plugin-inset, #eef0f4);color: var(--plp-c3, #6b7280)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plp-accent-soft, #f1ecff);color: var(--iwb-plp-accent, #5a3fd0)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vdesc{background: var(--iwb-field, #fbfcfd);border: 1px dashed var(--iwb-plugin-border, #e2e6ec);border-radius: 8px;height:28px;margin-top:4px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-lrow span{color: var(--iwb-text2, #8a919c);font-size: 12px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-lrow .iwb-input{background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-lrow .iwb-input:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff)}
|
||||||
|
/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */
|
||||||
|
.iwb-plp-ewrap{position:relative;flex:1 1 auto;min-height:0;display:flex;border-radius: 8px;background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eef0f3)}
|
||||||
|
.iwb-plp-ewrap:focus-within{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||||
|
.iwb-plp-ewrap .iwb-plp-etext{flex:1 1 auto;min-height:0;border:0;background:transparent;box-shadow:none;color:transparent;caret-color:var(--plp-c22, #1d2129);position:relative;z-index:1;resize:none}
|
||||||
|
.iwb-plp-ewrap .iwb-plp-etext:focus{background:transparent;border:0;box-shadow:none}
|
||||||
|
.iwb-plp-hl{position:absolute;inset:0;padding:10px 12px;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;font-size:13px;line-height:1.9;color: var(--iwb-text2, #5b6472);pointer-events:none;z-index:0}
|
||||||
|
.iwb-plp-hlvar{color: var(--iwb-text, #1d2129);font-weight:600}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plugin-hover, #eef0f3);color: var(--iwb-text2, #5b6472)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vdesc{background:transparent;border: 1px dashed var(--iwb-plugin-border, #dfe3e9)}
|
||||||
|
.iwb-plp-dvar{background:transparent;color: var(--iwb-text, #1d2129);font-weight:600;padding:0}
|
||||||
|
.iwb-plp-hres{height:6px;margin: -4px 0 0;cursor:ns-resize;flex:0 0 auto;border-radius: 6px}
|
||||||
|
.iwb-plp-hres:hover{background: var(--iwb-plugin-hover, #e7e9ee)}
|
||||||
|
/* 正文可见性:textarea 透明,显示下方高亮层 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap{flex:1 1 auto;min-height:0;position:relative;display:flex;background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eef0f3);border-radius: 8px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{background:transparent!important;color:transparent!important;border:0!important;box-shadow:none!important;padding:10px 12px}
|
||||||
|
.iwb-plp-dialog .iwb-plp-hl{padding:10px 12px;font-size:13px;line-height:1.9}
|
||||||
|
.iwb-plp-namebox{min-height:34px;height:34px;line-height:1.45;padding: 6px 10px;resize:vertical;overflow:auto;font-size: 13px}
|
||||||
|
.iwb-plp-insvar{color: var(--iwb-text, #1d2129)!important;background: var(--iwb-plugin-card, #fff)!important;border-color: var(--iwb-plugin-border, #e2e6ec)!important}
|
||||||
|
.iwb-plp-insvar:hover{background: var(--iwb-plugin-inset, #f4f6f9)!important}
|
||||||
|
/* v1.7.5:编辑封面卡在框内;详情封面放大 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov{width:100%;height:250px;overflow:hidden;border-radius:12px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov{width:264px;height:264px;flex:0 0 auto;overflow:hidden;border-radius:12px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||||
|
/* v1.7.6:封面完整展示(contain),不裁剪 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{object-fit:contain;background:transparent}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover{object-fit:contain;background:transparent}
|
||||||
|
.iwb-plp-dialog .iwb-plp-ecov{background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov{background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||||
|
/* v1.7.7:编辑区文字层与高亮层使用完全一致的字体度量,修复光标/选区错位 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext,
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-hl{
|
||||||
|
font-family:-apple-system,BlinkMacSystemFont,'PingFang SC','Helvetica Neue',system-ui,sans-serif!important;
|
||||||
|
font-size:13px!important;
|
||||||
|
line-height:1.85!important;
|
||||||
|
letter-spacing:0!important;
|
||||||
|
padding:10px 12px!important;
|
||||||
|
margin:0!important;
|
||||||
|
border:0!important;
|
||||||
|
box-sizing:border-box!important;
|
||||||
|
white-space:pre-wrap!important;
|
||||||
|
overflow-wrap:break-word!important;
|
||||||
|
word-break:break-word!important;
|
||||||
|
tab-size:4!important;
|
||||||
|
}
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{overflow-y:auto!important;scrollbar-gutter:stable}
|
||||||
|
/* v1.9.3:高亮层与 textarea 用同样的滚动条占位,避免换行位置不一致导致色块漂移 */
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-hl{overflow:hidden!important;scrollbar-gutter:stable}
|
||||||
|
/* v1.7.9:详情正文独立滚动,长文不再压到底部按钮 */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{overflow:hidden;align-items:stretch}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:hidden}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow:auto;padding-right:10px;margin-bottom:6px}
|
||||||
|
/* v1.8.0:详情标题/分组/标签移到封面下方;编辑标签改为输入+加号 */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
||||||
|
.iwb-plp-dleftcol{flex:0 0 264px;width:264px;display:flex;flex-direction:column;min-width:0}
|
||||||
|
.iwb-plp-dtitle{font-size: 17px;font-weight:650;line-height:1.35;margin-top: 12px;color:var(--iwb-text,#1d2129)}
|
||||||
|
.iwb-plp-dmeta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:8px}
|
||||||
|
.iwb-plp-dgroup{font-size: 12px;background: var(--iwb-plugin-inset, #eef0f4);color: var(--iwb-text2, #5b6472);border-radius:999px;padding: 2px 8px}
|
||||||
|
.iwb-plp-dtag{font-size: 12px;background: var(--iwb-plp-accent-soft, #f4f0ff);color: var(--iwb-plp-accent, #5a3fd0);border-radius:999px;padding: 2px 8px}
|
||||||
|
.iwb-plp-dlen{font-size: 12px;color: var(--iwb-text-dim, #9aa1ac)}
|
||||||
|
.iwb-plp-tagwrap{display:flex;flex-direction:column;gap:6px;flex:1;min-width:0}
|
||||||
|
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap: 6px}
|
||||||
|
.iwb-plp-tagchip{display:inline-flex;align-items:center;gap:4px;font-size: 12px;background: var(--iwb-plugin-inset, #eef0f4);border-radius:999px;padding:2px 8px;color: var(--iwb-text, #3f4450)}
|
||||||
|
.iwb-plp-tagx{cursor:pointer;color: var(--iwb-text-dim, #9aa1ac);font-style:normal}
|
||||||
|
.iwb-plp-tagx:hover{color: var(--iwb-err, #c0392b)}
|
||||||
|
.iwb-plp-tagrow{display:flex;gap:6px}
|
||||||
|
.iwb-plp-tagin{flex:1;min-width:0;height:30px}
|
||||||
|
.iwb-plp-lrow-tags{align-items:flex-start}
|
||||||
|
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;font-size:15px;line-height:28px}
|
||||||
|
/* v1.8.1:详情标题/分组/标签左对齐并带标题;标签加号对齐修复 */
|
||||||
|
.iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top:16px;color:var(--iwb-text,#1d2129)}
|
||||||
|
.iwb-plp-dmeta{display:flex;flex-direction:column;gap: 6px;margin-top:12px;align-items:flex-start}
|
||||||
|
.iwb-plp-dmrow{display:flex;align-items:center;gap:10px;width:100%}
|
||||||
|
.iwb-plp-dmk{flex:0 0 30px;width:30px;font-size: 12px;color: var(--iwb-text-dim, #9aa1ac)}
|
||||||
|
.iwb-plp-dmv{display:flex;flex-wrap:wrap;align-items:center;gap: 6px;min-width:0}
|
||||||
|
.iwb-plp-dgroup{font-size:12px;color: var(--iwb-text, #3f4450);background: var(--iwb-plugin-inset, #f2f4f7);border-radius:6px;padding: 2px 8px}
|
||||||
|
.iwb-plp-dtag{font-size: 12px;color: var(--iwb-plp-accent, #5a3fd0);background: var(--iwb-plp-accent-soft, #f4f0ff);border-radius:6px;padding: 2px 8px}
|
||||||
|
.iwb-plp-dempty{font-size:12px;color: var(--iwb-text-dim, #b3b9c2)}
|
||||||
|
.iwb-plp-dlen{font-size:12px;color: var(--iwb-text2, #8a919c)}
|
||||||
|
.iwb-plp-tagrow{display:flex;align-items:center;gap:6px}
|
||||||
|
.iwb-plp-tagin{height:30px;border-radius:8px}
|
||||||
|
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;border-radius:8px;background: var(--iwb-plugin-inset, #f2f4f7);border: 1px solid var(--iwb-plugin-border, #e2e6ec);color: var(--iwb-text2, #5b6472);font-size: 15px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
|
||||||
|
.iwb-plp-tagadd:hover{background: var(--iwb-plugin-hover, #e9ecf1)}
|
||||||
|
/* v1.8.2:详情左右两栏卡片化 + 分割线 */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{gap: 12px;padding:16px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dleftcol{flex:0 0 300px;width:300px;padding:12px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff);align-self:flex-start}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dcov{width:100%;height:270px;border-radius:10px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top: 12px;color:var(--iwb-text,#1d2129)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top:12px;padding-top:12px;border-top: 1px solid var(--iwb-plugin-border, #eef0f3);gap:8px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;padding: 12px 16px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff);overflow:hidden}
|
||||||
|
.iwb-plp-dsec{font-size: 12px;font-weight:600;color: var(--iwb-text2, #8a919c);letter-spacing:.04em;padding-bottom:8px;margin-bottom:8px;border-bottom: 1px solid var(--iwb-plugin-border, #eef0f3);flex:0 0 auto}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow:auto;padding-right:10px;font-size: 14px;line-height:2;color: var(--iwb-text, #3a4048)}
|
||||||
|
/* v1.8.3:详情左卡片撑到底、四边等距;正文恢复滚动不被底部遮挡 */
|
||||||
|
.iwb-plp-dialog-detail{display:flex;flex-direction:column;overflow:hidden}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{display:flex;flex:1 1 auto;min-height:0;overflow:hidden;gap: 12px;padding:16px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dleftcol{align-self:stretch;display:flex;flex-direction:column;overflow:auto;padding:12px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;overflow:hidden;display:flex;flex-direction:column;padding: 12px 16px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;scrollbar-width:thin;padding-right:8px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dfooter{flex:0 0 auto}
|
||||||
|
/* v1.8.4:右卡片纵向拉伸填满,正文出现滚动条 */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:stretch!important}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dright{align-self:stretch!important;height:100%;max-height:100%;overflow:hidden!important}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 0;min-height:0;overflow-y:auto!important;overflow-x:hidden}
|
||||||
|
/* v1.8.7:详情标题缩小;分组/标签去底色;元信息加分割线与行高 */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:17px!important;font-weight:650;margin-top:12px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top:12px;padding-top: 12px;border-top: 1px solid var(--iwb-plugin-border, #eef0f3);gap:10px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmrow{gap:6px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmk{flex:0 0 auto;width:auto;font-size:12px;line-height:1.6;color: var(--iwb-text-dim, #9aa1ac)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dgroup,.iwb-plp-dialog-detail .iwb-plp-dtag{background:transparent!important;padding:0!important;border-radius:0!important;font-size: 13px;line-height:1.6;color: var(--iwb-text, #2f3540)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtag{color: var(--iwb-plp-accent, #5a3fd0);}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dlen{font-size: 13px;line-height:1.6;color: var(--iwb-text, #2f3540)}
|
||||||
|
/* v1.8.8:详情标题 14px;元信息行间浅分割线;封面底色更接近白色(编辑/详情统一) */
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:14px!important;font-weight:650;line-height:1.5;margin-top:12px}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmeta{gap:0}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmrow{padding: 6px 0;border-bottom: 1px solid var(--iwb-plugin-border, #f3f5f8)}
|
||||||
|
.iwb-plp-dialog-detail .iwb-plp-dmrow:last-child{border-bottom:0}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov,.iwb-plp-dialog .iwb-plp-ecov{background: var(--iwb-field, #fcfcfd)!important}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover,.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{background:transparent!important}
|
||||||
|
/* v1.8.19:编辑区高亮变量不得加粗——加粗会改变字形宽度,导致点击位置逐次向左偏移 */
|
||||||
|
.iwb-plp-hlvar{font-weight:400!important;letter-spacing:normal!important}
|
||||||
|
/* v1.9.3:变量着色改为「textarea 只负责文字 + 背层只画浅主色色块」——
|
||||||
|
两层字体/换行/滚动条占位由 v1.7.7 规则保持一致,变量 span 沿用 400 字重(不加粗,宽度不漂移),
|
||||||
|
文字仍由 textarea 自己画(可见),所以插入点/点击/选区完全不受影响。
|
||||||
|
注:v1.8.20 停用高亮层是因为当时「透明 textarea + 背层画文字」两层文字错位;本版不画文字,只画色块,不会复发。 */
|
||||||
|
.iwb-plp-ewrap .iwb-plp-hl{display:block!important;color:transparent!important;-webkit-text-fill-color:transparent!important}
|
||||||
|
.iwb-plp-hlvar{color:transparent!important;-webkit-text-fill-color:transparent!important;background:color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 16%, transparent);border-radius:6px;box-shadow:0 0 0 1px color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 22%, transparent)}
|
||||||
|
.iwb-plp-ewrap .iwb-plp-etext{color:var(--iwb-text,#2a2f36)!important;background:transparent!important}
|
||||||
|
/* v1.8.21:正文文字必须可见(覆盖旧的 transparent !important) */
|
||||||
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{color:var(--iwb-text,#2a2f36)!important;caret-color:var(--iwb-text,#2a2f36)!important;-webkit-text-fill-color:var(--iwb-text,#2a2f36)!important}
|
||||||
|
/* v1.9.3:右侧变量名与详情正文里的变量也用主色呼应(只读区,零功能风险) */
|
||||||
|
.iwb-plp-dialog .iwb-plp-vname{color:var(--iwb-plp-accent,#5a3fd0)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-dvar{color:var(--iwb-plp-accent,#5a3fd0);background:var(--iwb-plp-accent-soft,#f1ecff);border-radius:6px;padding:0 2px}
|
||||||
|
/* 回滚开关:若真机发现任何点击/光标异常,把下行打开即回到 v1.8.20 纯 textarea 状态。
|
||||||
|
.iwb-plp-ewrap .iwb-plp-hl{display:none!important} */
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// promptlib 本地契约测试(纯 node):
|
||||||
|
// - v1.9.2:分享带封面开关
|
||||||
|
// - v1.9.3:编辑区变量浅主色底色(方案 C,只画色块不改输入)
|
||||||
|
// - v1.10.0:文本分享 / 文件分享双路径 + 顶部三按钮 + 右键去分类 + 设置去导入入口
|
||||||
|
// - v1.10.1:移除「分享时附带封面图片」开关 + 详情底部分享/插入组间竖向分割线
|
||||||
|
// 运行:node promptlib/tools/harness.mjs (退出码 0 = 全过)
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import vm from 'node:vm'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const ROOT = path.resolve(HERE, '..')
|
||||||
|
const src = fs.readFileSync(path.join(ROOT, 'src/index.js'), 'utf8')
|
||||||
|
const css = fs.readFileSync(path.join(ROOT, 'styles.css'), 'utf8')
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 1) 版本 / manifest ----
|
||||||
|
ok("manifest.version = 1.11.0", /version:\s*'1\.11\.0'/.test(src))
|
||||||
|
ok('package.json version = 1.11.0',
|
||||||
|
JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version === '1.11.0')
|
||||||
|
ok('manifest 已移除「分享时附带封面图片」开关声明',
|
||||||
|
!/shareWithCover:\s*\{\s*type:\s*'boolean'/.test(src))
|
||||||
|
ok('源码不再定义/读取 shareWithCover 设置',
|
||||||
|
!/function shareWithCover \(\)/.test(src) && !/S\.get\('shareWithCover'\)/.test(src))
|
||||||
|
|
||||||
|
// ---- 2) sharePayload 两条显式分支 ----
|
||||||
|
const m = src.match(/ function sharePayload \(p, withCover\) \{[\s\S]*?\n \}\n function shareFileName/)
|
||||||
|
ok('从 src 找到 sharePayload(p, withCover)', !!m)
|
||||||
|
const fnSrc = m ? m[0].replace(/\n function shareFileName$/, '') : ''
|
||||||
|
const sandbox = {
|
||||||
|
SHARE_TAG: 'IWB-PROMPT-SHARE',
|
||||||
|
varsOf: () => [],
|
||||||
|
coverToDataUrl: () => { throw new Error('不该读封面') },
|
||||||
|
Promise, JSON, String, Number, Array, Object,
|
||||||
|
}
|
||||||
|
vm.createContext(sandbox)
|
||||||
|
vm.runInContext(fnSrc, sandbox)
|
||||||
|
const p = { name: '测试词', text: '一只猫', group: '分组A', tags: ['x'], cover: { img: 'a.jpg' } }
|
||||||
|
|
||||||
|
const textPlain = await sandbox.sharePayload(p, false)
|
||||||
|
const bodyPlain = JSON.parse(textPlain.split('\n')[1])
|
||||||
|
ok('文本分享(false):分享文本无 cover 字段', !('cover' in bodyPlain.sharing))
|
||||||
|
ok('文本分享(false):不读封面(stub 抛错未触发)', true)
|
||||||
|
ok('文本分享(false):名字/正文/分组仍在',
|
||||||
|
bodyPlain.sharing.name === '测试词' && bodyPlain.sharing.text === '一只猫' && bodyPlain.sharing.group === '分组A')
|
||||||
|
|
||||||
|
sandbox.coverToDataUrl = () => Promise.resolve('data:image/jpeg;base64,AAAA')
|
||||||
|
const textFile = await sandbox.sharePayload(p, true)
|
||||||
|
const bodyFile = JSON.parse(textFile.split('\n')[1])
|
||||||
|
ok('文件分享(true):分享文本带 cover', bodyFile.sharing.cover === 'data:image/jpeg;base64,AAAA')
|
||||||
|
|
||||||
|
// ---- 3) v1.10.0 UI 契约 ----
|
||||||
|
ok('文本分享复制纯文字(doShareText 用 api.copy)',
|
||||||
|
/function doShareText \(p\)[\s\S]{0,260}api\.copy\(text\)/.test(src))
|
||||||
|
ok('文件分享导出为文件(doShareFile 用 api.exportText)',
|
||||||
|
/function doShareFile \(p\)[\s\S]{0,260}api\.exportText\(shareFileName\(p\), text\)/.test(src))
|
||||||
|
ok('文件名做安全化(过滤 \\/:*?"<>|)',
|
||||||
|
/replace\(\/\[\\\\\/:\*\?"<>\|]\/g, '_'\)/.test(src))
|
||||||
|
ok('剪贴板导入与文件导入共用 importShareItem(1 定义 + 2 调用)',
|
||||||
|
(src.match(/importShareItem\s*\(item\)/g) || []).length >= 3)
|
||||||
|
ok('文件导入走 api.importText()',
|
||||||
|
/function importShareFromFile \(\)[\s\S]{0,160}api\.importText\(\)/.test(src))
|
||||||
|
ok('顶部三按钮:文件 / 文本 / 新建',
|
||||||
|
/text: '文件'[\s\S]{0,200}text: '文本'[\s\S]{0,200}text: '新建'/.test(src))
|
||||||
|
ok('右键菜单已去掉「移动到分组」分类',
|
||||||
|
!/移动到分组/.test(src))
|
||||||
|
ok('右键菜单含 文本分享 / 文件分享(iwb-ctx-item 项)',
|
||||||
|
/iwb-ctx-item', text: '文本分享'[\s\S]{0,260}iwb-ctx-item', text: '文件分享'/.test(src))
|
||||||
|
ok('详情底部含 文本分享 / 文件分享 两按钮',
|
||||||
|
/text: '文本分享'/.test(src) && /text: '文件分享'/.test(src))
|
||||||
|
ok('详情底部分享组与插入组之间是竖向分割线(DOM 顺序:文件分享 → 竖线 → 复制全文)',
|
||||||
|
/footEl\.appendChild\(shareFile\)[\s\S]{0,240}iwb-plp-foot-vsep[\s\S]{0,160}footEl\.appendChild\(cp\)/.test(src))
|
||||||
|
ok('竖线样式:1px 宽 / 18px 高 / 边框色 / 居中',
|
||||||
|
/\.iwb-plp-foot-vsep\s*\{[^}]*width:\s*1px[^}]*height:\s*18px[^}]*align-self:\s*center[^}]*background:\s*var\(--iwb-border\)/.test(css))
|
||||||
|
ok('设置面板不再有单条导入入口(impShareBtn 已移除)',
|
||||||
|
!/impShareBtn/.test(src))
|
||||||
|
ok('旧的「分享…」按钮(带图完整版)已删除',
|
||||||
|
!/text: '分享'/.test(src) && !/function doShare \(p\)/.test(src))
|
||||||
|
|
||||||
|
// ---- 4) v1.9.3 变量着色样式不变量(回归保护)----
|
||||||
|
ok('高亮层恢复显示(不再 display:none)',
|
||||||
|
/\.iwb-plp-ewrap \.iwb-plp-hl\{display:block!important/.test(css))
|
||||||
|
ok('高亮层整层文字透明(不与 textarea 重影)',
|
||||||
|
/\.iwb-plp-ewrap \.iwb-plp-hl\{[^}]*color:transparent!important[^}]*-webkit-text-fill-color:transparent!important/.test(css))
|
||||||
|
ok('变量 span 只画主色背景、不画文字',
|
||||||
|
/\.iwb-plp-hlvar\{[^}]*color:transparent!important[^}]*background:color-mix\(in srgb, var\(--iwb-plp-accent/.test(css))
|
||||||
|
ok('变量 span 不加粗(避开点击偏移根因)',
|
||||||
|
/\.iwb-plp-hlvar\{font-weight:400!important/.test(css))
|
||||||
|
ok('textarea 文字仍可见(-webkit-text-fill-color 兜底)',
|
||||||
|
/\.iwb-plp-etext\{color:var\(--iwb-text[^}]*-webkit-text-fill-color:var\(--iwb-text/.test(css))
|
||||||
|
ok('高亮层与 textarea 滚动条占位一致',
|
||||||
|
/\.iwb-plp-emid \.iwb-plp-ewrap \.iwb-plp-hl\{overflow:hidden!important;scrollbar-gutter:stable\}/.test(css))
|
||||||
|
ok('高亮层跟随 textarea 横向滚动',
|
||||||
|
/hl\.scrollTop = textIn\.scrollTop; hl\.scrollLeft = textIn\.scrollLeft/.test(src))
|
||||||
|
ok('右侧变量名与详情变量用主色呼应',
|
||||||
|
/\.iwb-plp-vname\{color:var\(--iwb-plp-accent/.test(css) && /\.iwb-plp-dvar\{color:var\(--iwb-plp-accent/.test(css))
|
||||||
|
|
||||||
|
// ---- 5) v1.11.0 封面文件治理(P1)----
|
||||||
|
// 目标:① 保存/上传时把内联 base64 落成文件;② 孤儿封面能被回收;③ 回收不能误删。
|
||||||
|
// 纯文本断言跑不了真实 FS ⇒ 这里用「函数抽出来 + 假 fileApi」跑行为。
|
||||||
|
ok('封面命名统一走 coverFileName(哈希只在它内部实现一次)',
|
||||||
|
/function coverFileName \(dataUrl\)/.test(src) && (src.match(/var h = 5381/g) || []).length === 1 && (src.match(/coverFileName\(/g) || []).length >= 6)
|
||||||
|
ok('保存路径先落文件(ensureCoverFile 包住 doSave)',
|
||||||
|
/function doSave \(\)[\s\S]{0,600}ensureCoverFile\(c\.cover\)/.test(src))
|
||||||
|
ok('上传封面即落文件(不再把 dataURL 写回 draft.cover)',
|
||||||
|
/api\.putCover\([\s\S]{0,400}ensureCoverFile\(r\.ref\)/.test(src))
|
||||||
|
ok('删词条后安排一次回收', /已删除'[\s\S]{0,80}scheduleCoverGc\(/.test(src))
|
||||||
|
ok('启动加载后安排一次回收(等 convertInlineCovers 写完)',
|
||||||
|
/convertInlineCovers\(\)[\s\S]{0,120}scheduleCoverGc\(4000\)/.test(src))
|
||||||
|
ok('自动回收有「数据来源」闸门(不是插件 JSON 读来的就不删)',
|
||||||
|
/!o\.manual && !dataFromPlugin\) return Promise\.resolve\(\{ removed: 0, bytes: 0, skipped: 'no-source' \}\)/.test(src))
|
||||||
|
ok('keep 为空时不删(空集合 = 全删的形状)',
|
||||||
|
/if \(!kept && !o\.manual\) return Promise\.resolve\(\{ removed: 0, bytes: 0, skipped: 'empty' \}\)/.test(src))
|
||||||
|
ok('只删图片扩展名文件', src.includes('/\\.(jpg|jpeg|png|webp)$/i.test(name)'))
|
||||||
|
ok('设置页有显式清理入口 + 现读一次数据',
|
||||||
|
/text: '清理未引用封面'/.test(src) && /plpGcCoverFiles\(FA, plpCoverNamesOf\(state\.prompts\), \{ manual: true \}\)/.test(src))
|
||||||
|
ok('pending(刚 put 未被引用)不会被回收',
|
||||||
|
/Object\.keys\(pendingCoverNames\)\.forEach\(function \(n\) \{ names\.push\(n\) \}\)/.test(src))
|
||||||
|
|
||||||
|
// 行为:抽出 plpGcCoverFiles 本体,用假 fileApi 验证「只删未被引用的图片文件」
|
||||||
|
const gcMatch = src.match(/ function plpGcCoverFiles \(FA, keepNames, opts\) \{[\s\S]*?\n \}\n/)
|
||||||
|
ok('从 src 抽出 plpGcCoverFiles', !!gcMatch)
|
||||||
|
if (gcMatch) {
|
||||||
|
const removed = []
|
||||||
|
const fakeFA = {
|
||||||
|
list: async () => [
|
||||||
|
{ name: 'cused1.jpg', size: 100 },
|
||||||
|
{ name: 'corphan1.jpg', size: 200 },
|
||||||
|
{ name: 'cshared.jpg', size: 300 },
|
||||||
|
{ name: 'notes.txt', size: 1 },
|
||||||
|
],
|
||||||
|
remove: async (name) => { removed.push(name); return { ok: true } },
|
||||||
|
}
|
||||||
|
const gcSandbox = { Promise, JSON, String, Number, Array, Object, RegExp, console }
|
||||||
|
vm.createContext(gcSandbox)
|
||||||
|
vm.runInContext('var PLP_GC_BUSY = false\n' + gcMatch[0] + '\nthis.gc = plpGcCoverFiles', gcSandbox)
|
||||||
|
const r1 = await gcSandbox.gc(fakeFA, ['cused1.jpg'], {})
|
||||||
|
ok('回收:只删未引用图片(保留引用项与非图片文件)',
|
||||||
|
JSON.stringify(removed) === '["corphan1.jpg","cshared.jpg"]')
|
||||||
|
ok('回收:返回删除数与字节数', r1.removed === 2 && r1.bytes === 500)
|
||||||
|
const r2 = await gcSandbox.gc(fakeFA, [], {})
|
||||||
|
ok('回收:keep 为空且非人工 ⇒ 不删(skipped=empty)', r2.skipped === 'empty' && r2.removed === 0)
|
||||||
|
const r3 = await gcSandbox.gc(null, [], {})
|
||||||
|
ok('回收:无文件能力 ⇒ skipped=no-fs', r3.skipped === 'no-fs')
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
# sticky · 便利贴(v1.0.7)
|
||||||
|
|
||||||
|
画布上的便签节点:一张纸片,写多行文字,能调字号、粗细、背景色,能拖大拖小。
|
||||||
|
**不连线、不进生图链路**——纯标注用途(说明节点、分组标题、随手记)。
|
||||||
|
|
||||||
|
## 设计由来
|
||||||
|
|
||||||
|
用户要一个"在画布上建立说明文字"的插件。最初设想是"标题节点",后来改成便签:
|
||||||
|
不要单独的"标题"概念——**便签上方那条"便利贴"标签是宿主强制的标题带**(插件节点的
|
||||||
|
`hasTitle: true` 写死,只有中继节点才不显示),注册节点名即可,用户不用再填标题字段。
|
||||||
|
想当说明标题就把字号调大(**无上限**,A+ 每点一次 +2),想放多行正文就用小字(默认 14)。
|
||||||
|
|
||||||
|
> v1.0.1 修复三个真机问题:① 节点拖动变大后下半漏出宿主底色(根容器改 `flex:1` 撑满);
|
||||||
|
> ② 字号被闭集钳在 24(改为无上限、±2 步进);③ 正文单击即编辑(改为照宿主文本节点那样
|
||||||
|
> **单击选中/拖动、双击才进编辑**)。
|
||||||
|
>
|
||||||
|
> v1.0.2 修复两个体验问题:① 便签高度不能贴近文字(下方一大块空白)——textarea 改为
|
||||||
|
> **高度随内容自适应**(`flex:0 0 auto` + JS 按 `scrollHeight` 算高),节点外框 `height:auto`
|
||||||
|
> 会跟着收缩,resize 手柄就能拖到贴字;② 色板弹在便签右下角、盖住 resize 手柄——
|
||||||
|
> 色板 DOM 从根节点挪进**工具条**(`top:100%` 落在调色按钮正下方)。
|
||||||
|
> 选中气泡上的「节点颜色」按钮是宿主画的、对本插件无效,需改宿主才能去掉——本版不动。
|
||||||
|
>
|
||||||
|
> v1.0.3 修掉「v1.0.2 看着修了其实没修透」的高度问题:宿主 `NodeCard` 把 `node.h` 写成
|
||||||
|
> 外框 `minHeight`(`height:auto`),旧的 `h` 仍在撑着外框,所以正文贴字了、下面还是一截空白,
|
||||||
|
> resize 手柄也拖不下去。现在插件在渲染时按「工具条 + 正文」算内容高度,首次遇到旧 `h`
|
||||||
|
> 明显大于内容时把它校正到内容高度,并同步覆盖外框 `minHeight`;用户后续拖大的 `h` 会保留,
|
||||||
|
> 仍能拖大拖小。调色圆点移到工具条**最右上**,色板 `right:8px` 正对圆点右缘、落其下方。
|
||||||
|
>
|
||||||
|
> v1.0.4 修掉最后一行空白:textarea 没写 `rows`,浏览器默认是 **2 行**;`fitBody()` 把高度
|
||||||
|
> 设成 `auto` 再读 `scrollHeight` 时,单行文字也被算成两行高,于是一行字和两行字的便签一样高。
|
||||||
|
> 现在显式 `rows="1"`,`scrollHeight` 才等于真实内容行数;多行文本照常换行、高度跟着涨。
|
||||||
|
>
|
||||||
|
> v1.0.5 统一圆角:纸片内圈从写死的 10px 改成 `calc(var(--iwb-node-radius, 14px) - 1px)`,
|
||||||
|
> 与宿主节点选中框(外圈 14px + 1px 边框)对齐,选中时两层边缘不再错开。
|
||||||
|
>
|
||||||
|
> v1.0.6 修行高回缩:v1.0.3 为了「内容长高时 resize 起点不滞后」把 `node.h` 顶到内容高度,
|
||||||
|
> 但文本从两行删回一行时这个 h 没跟着降,外框就一直留着两行高。现在区分**自动跟随**与
|
||||||
|
> **用户手动拖尺寸**:自动写出的 h 双向贴合内容(长高就涨、缩回就降);用户拖手柄改过 h
|
||||||
|
> 后退出自动跟随,手动尺寸照旧保留。
|
||||||
|
>
|
||||||
|
> v1.0.7 修自定义调色后面板不退出:预设色块点完会收起,但色轮走的是隐藏的原生
|
||||||
|
> `<input type="color">`,`change` 回调只写 `bgColor`、没关浮层,选完色色板仍压在便签上。
|
||||||
|
> 现在**点色轮打开系统取色器时即收起**(确认/取消都不留浮层),自定义色 `change` 到达时再兜底收一次。
|
||||||
|
|
||||||
|
## 长什么样
|
||||||
|
|
||||||
|
画布上是一张暖色纸片(圆角、细边、一点阴影),顶上一条工具条:
|
||||||
|
|
||||||
|
| 控件 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `−` / `+` | 字号缩放,每步 ±2,下限 6、**无上限** |
|
||||||
|
| `B` | 正文粗细在 400 / 600 间切换(按钮高亮表示已加粗) |
|
||||||
|
| 圆点 | 展开色板:8 个预设色 + 底部彩虹色轮;**色板落在圆点正下方**,不挡 resize 手柄 |
|
||||||
|
| 色轮 | 调起系统颜色选择器,可选任意色;点开即收起色板,选完色不再压在便签上 |
|
||||||
|
| 正文区 | 多行 textarea,透明底,随字号自动换行;**单击=选中/拖动节点,双击=进入编辑,失焦/ESC 退出** |
|
||||||
|
|
||||||
|
选中节点后宿主自带的浮动气泡(信息 / 删除、复制、缩放手柄)照常出现,不是本插件画的。
|
||||||
|
|
||||||
|
## 状态存在哪
|
||||||
|
|
||||||
|
全部写进节点 `data`,走 `props.onUpdate(node.id, patch)`,随画布落盘:
|
||||||
|
|
||||||
|
| 字段 | 默认 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `text` | `''` | 多行正文 |
|
||||||
|
| `fontSize` | `14` | 任意有限数(下限 6),A± 每步 ±2,无上限 |
|
||||||
|
| `fontWeight` | `400` | `400` / `600` |
|
||||||
|
| `bgColor` | `#FCE8B0` | 纸片背景色 |
|
||||||
|
|
||||||
|
**文字颜色不存**——运行时按背景亮度自动取深色 `#1c2333` 或白色 `#ffffff`(阈值 Y=0.55),
|
||||||
|
深色纸片不会配黑字看不见。这是运行时计算,源码里没有写死的中性色,不触发守门测试。
|
||||||
|
|
||||||
|
## 关键实现点
|
||||||
|
|
||||||
|
- **注册**:`ctx.nodes.register({ id:'sticky', title:'便利贴', ports:{in:false,out:false}, height:180, render })`
|
||||||
|
—— `ports` 全关,纯标注节点;宿主生成的类型是 `plugin:sticky:sticky`。
|
||||||
|
- **节点尺寸**:节点缩放用宿主自带手柄(右下角 `.iwb-resize`,对插件节点天然生效),插件不写
|
||||||
|
`w/h`。两层 flex 各管一件事:**根容器 `.iwb-sticky-node` 用 `flex:1 1 auto; min-height:0` 撑满**
|
||||||
|
宿主容器 `.iwb-plugin-node-body`(flex 列、`padding:0`)——只写 `height:100%` 在 WKWebView 下
|
||||||
|
对 flex 项算不准,拖大后下半会露出宿主底色(v1.0.0 的问题);**textarea 反过来用 `flex:0 0 auto`
|
||||||
|
+ JS 按 `scrollHeight` 算高**(`rows="1"` 去掉浏览器默认 2 行的预留;文本/字号变了才重算,
|
||||||
|
缓存 `fitText/fitSize` 避免每次 render reflow),
|
||||||
|
让内容自然高度贴着文字(v1.0.2)。**外框 minHeight(v1.0.3)**:宿主 `NodeCard` 的
|
||||||
|
`style.minHeight = node.h` 才是拖不下去的真凶——插件在 `fitOuterBox()` 里用
|
||||||
|
`工具条 offsetHeight + 正文 style.height + 2px 边框` 算内容高度,首次把旧 `h` 校正到该值,
|
||||||
|
并直接把宿主外框的 `minHeight` 覆盖掉。插件自动写出的 h **双向跟随内容**(v1.0.6:
|
||||||
|
两行退回一行会缩回去);一旦检测到 h 被外部拖手柄改写,就退出自动跟随、尊重手动尺寸,
|
||||||
|
所以拖大拖小仍然有效。
|
||||||
|
- **色板定位**:色板挂在工具条 `tools`(`position:relative`)内而非便签根节点,CSS `top:100%`
|
||||||
|
落在调色圆点正下方;挂在根节点时会贴便签底部右下角、盖住 resize 手柄(v1.0.2 的问题)。
|
||||||
|
圆点用 `margin-left:auto` 推到工具条最右上(v1.0.3),色板 `right:8px` 与圆点右缘对齐。
|
||||||
|
- **样式时机**:CSS 在脚本执行时就注入唯一 `<style id="iwb-sticky-style">`,不等 setup / mount
|
||||||
|
—— 从存档直接进画布(面板从不 mount)时节点也有样式。
|
||||||
|
- **幂等同步**:`render(node, props, host)` 每次渲染都被宿主无依赖地调一次;插件缓存 host 上的
|
||||||
|
骨架 `host.__sticky`,只在数据真的变了才写 DOM;**编辑态(`st.editing`)或 `document.activeElement
|
||||||
|
=== textarea`** 时跳过 `value` 覆盖,否则用户打字会被打断/失焦。sync 只碰 style 和 bold/dot 的
|
||||||
|
className,不动 textarea 的 editing class,重渲染不会失焦。
|
||||||
|
- **单击/双击编辑**:照宿主文本节点的做法——textarea 默认 `readonly`,宿主 CSS
|
||||||
|
`.iwb-node textarea[readonly]{pointer-events:none}` 让**单击穿透**给节点卡片(选中/拖动);
|
||||||
|
双击由插件在 root 上接管(宿主 `onDoubleClick` 只处理内置文本类型,不管 `plugin:` 节点),
|
||||||
|
解除 readonly + focus 进入编辑;失焦 / ESC 退出。编辑态下 `pointerdown`/`mousedown`/`keydown`
|
||||||
|
不冒泡给宿主,避免拖节点和触发画布快捷键。插件自己维护 `st.editing`,不依赖宿主的
|
||||||
|
`props.editingBody`(那是给内置文本节点用的)。
|
||||||
|
- **面板**:一个「+ 插入便利贴」按钮 → `ctx.canvas.createNode('plugin:sticky:sticky', null, null, {...})`,
|
||||||
|
坐标 `null/null` 走宿主 `findSpot()`(视口中心螺旋找空位),插件不自己算坐标。
|
||||||
|
|
||||||
|
## 校验
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node sticky/tools/harness.mjs # 纯 node,58 项:注册/渲染/字号无上限/贴字自适应/rows=1/外框 minHeight 双向回缩/圆角对齐/色板定位/自定义色后面板收起/双击编辑/换色/文本/幂等/插入
|
||||||
|
npm run validate # 全仓契约校验
|
||||||
|
```
|
||||||
|
|
||||||
|
## 发布
|
||||||
|
|
||||||
|
本仓是桌面客户端的插件源仓。发布链路(详见根 README):
|
||||||
|
|
||||||
|
```
|
||||||
|
sticky/src/index.js → 桌面仓 sync-plugins-from-repo.js → plugins/runtime/plugin-sticky.<sha12>.js
|
||||||
|
→ gen-market.js → market/index.json + zip → 上传 NAS
|
||||||
|
```
|
||||||
|
|
||||||
|
上架需在桌面仓 `scripts/sync-plugins-from-repo.js` 的 `IDS` 白名单和 `plugins/meta.json` 里加入 `sticky`。
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/sticky",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.7",
|
||||||
|
"description": "画布便利贴:多行文本 + 字号/粗细调节 + 8 色背景,纯标注节点不连线",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "sticky",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,469 @@
|
|||||||
|
// iwb-plugin: 画布便利贴 —— 多行文本 + 字号/粗细调节 + 8 色背景,纯标注节点不连线。
|
||||||
|
//
|
||||||
|
// 设计口径(用户 2026-11-24 确认):
|
||||||
|
// - 不要"标题"概念:便签上方那条"便利贴"标签是宿主强制的标题带(hasTitle 写死),
|
||||||
|
// 节点名注册成"便利贴"即可,用户不用再填标题字段。
|
||||||
|
// - 想当说明标题就把字号调大(无上限,A+ 每点一次 +2),想放多行正文就用小字(默认 14)。
|
||||||
|
// - 不连线:ports:{in:false,out:false}。
|
||||||
|
// - 节点缩放用宿主自带手柄(右下角),插件不设宽高。
|
||||||
|
//
|
||||||
|
// 状态全部存 node.data(props.onUpdate 写回,随画布落盘):
|
||||||
|
// text / fontSize / fontWeight / bgColor
|
||||||
|
// 字号:A−/A+ 每步 ±2,下限 6、无上限(用户明确要求去掉最大字号限制);
|
||||||
|
// 8 个预设色是运行时数据、色轮走系统颜色选择器,源码里不写死中性色(守门只卡字面量)。
|
||||||
|
;(function (global) {
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
if (!global.IWBPluginHost) return
|
||||||
|
|
||||||
|
// 必须在脚本执行时就注入:面板可能瞬间挂载、节点可能从存档直接出现(面板从不 mount)。
|
||||||
|
function ensureStyle() {
|
||||||
|
if (typeof document === 'undefined' || !document.createElement) return
|
||||||
|
if (document.getElementById('iwb-sticky-style')) return
|
||||||
|
var css = '' +
|
||||||
|
'#iwb-sticky-style{}' +
|
||||||
|
'[hidden]{display:none!important}' +
|
||||||
|
'.iwb-sticky-panel{display:flex;flex-direction:column;gap:12px;font-size:13px;color:var(--iwb-text,#1c2333)}' +
|
||||||
|
'.iwb-sticky-panel-tip{font-size:12px;line-height:1.6;color:var(--iwb-text2,#4d5668);opacity:.9}' +
|
||||||
|
'.iwb-sticky-add{cursor:pointer;border:1px solid var(--iwb-brand,#6b7280);border-radius:8px;background:var(--iwb-layer2,#fff);color:var(--iwb-text,#1c2333);font-size:13px;padding:10px 14px;font-family:inherit}' +
|
||||||
|
'.iwb-sticky-add:hover{background:var(--iwb-hover,#f0f1f4)}' +
|
||||||
|
'.iwb-sticky-list{display:flex;flex-direction:column;gap:8px;margin-top:4px}' +
|
||||||
|
'.iwb-sticky-row{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 10px;border:1px solid var(--iwb-border,#d5d9e0);border-radius:8px;background:var(--iwb-layer,#f5f6f8)}' +
|
||||||
|
'.iwb-sticky-row-txt{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}' +
|
||||||
|
'.iwb-sticky-go{cursor:pointer;border:1px solid var(--iwb-border,#d5d9e0);border-radius:6px;background:var(--iwb-layer2,#fff);color:var(--iwb-text,#1c2333);font-size:12px;padding:4px 10px;white-space:nowrap;font-family:inherit}' +
|
||||||
|
'.iwb-sticky-go:hover{border-color:var(--iwb-brand,#6b7280)}' +
|
||||||
|
// ---- 节点体 ----
|
||||||
|
// 宿主容器 .iwb-plugin-node-body 是 flex 列且 padding:0;这里必须 flex:1 撑满,
|
||||||
|
// 不能只写 height:100%(WKWebView 下百分比对 flex 项算不准,拖大后下半露出宿主底色)。
|
||||||
|
// 圆角对齐宿主节点:外框 .iwb-node 用 var(--iwb-node-radius)=14px 且有 1px 边框,
|
||||||
|
// 纸片在框内 ⇒ 内圈半径 = 外圈 - 1px,选中时两层边缘才不会错开。
|
||||||
|
'.iwb-sticky-node{position:relative;display:flex;flex-direction:column;flex:1 1 auto;min-height:0;width:100%;box-sizing:border-box;border-radius:calc(var(--iwb-node-radius, 14px) - 1px);overflow:visible}' +
|
||||||
|
'.iwb-sticky-tools{display:flex;align-items:center;gap:6px;padding:6px 8px;border-bottom:1px solid rgba(0,0,0,.08);flex:0 0 auto;position:relative;z-index:2}' +
|
||||||
|
'.iwb-sticky-btn{cursor:pointer;border:1px solid rgba(0,0,0,.2);border-radius:6px;background:transparent;color:inherit;font-size:11px;padding:2px 6px;font-family:inherit;line-height:1.4;user-select:none}' +
|
||||||
|
'.iwb-sticky-btn:hover{background:rgba(0,0,0,.07)}' +
|
||||||
|
'.iwb-sticky-btn-on{font-weight:600;background:rgba(0,0,0,.1)}' +
|
||||||
|
// 调色圆点推到工具条最右端(右上),色板 right:8px 与圆点右缘对齐,落在其正下方。
|
||||||
|
'.iwb-sticky-dot{display:inline-block;width:14px;height:14px;border-radius:50%;border:1px solid rgba(0,0,0,.25);cursor:pointer;vertical-align:middle;padding:0;margin-left:auto}' +
|
||||||
|
'.iwb-sticky-dot-on{box-shadow:0 0 0 2px rgba(0,0,0,.55)}' +
|
||||||
|
'.iwb-sticky-pal{position:absolute;top:100%;right:8px;z-index:20;display:grid;grid-template-columns:repeat(4,18px);gap:8px 6px;padding:10px;border-radius:10px;border:1px solid var(--iwb-border,#d5d9e0);background:var(--iwb-layer2,#fff);box-shadow:0 4px 16px rgba(0,0,0,.18)}' +
|
||||||
|
'.iwb-sticky-pal-sw{width:18px;height:18px;border-radius:50%;border:1px solid rgba(0,0,0,.2);cursor:pointer;padding:0}' +
|
||||||
|
'.iwb-sticky-wheel{grid-column:1/-1;display:flex;justify-content:center;padding-top:8px;border-top:1px solid var(--iwb-border,#d5d9e0)}' +
|
||||||
|
'.iwb-sticky-wheel-btn{cursor:pointer;width:22px;height:22px;border-radius:50%;border:0;padding:0;background:conic-gradient(#e24b4a,#ef9f27,#fac775,#639922,#1d9e75,#378add,#7f77dd,#d4537e,#e24b4a)}' +
|
||||||
|
// 高度随内容自适应(贴字):不再 flex:1 撑满剩余空间,否则字号大/文字少时
|
||||||
|
// 下方留出大片空白;高度由 syncSkeleton 按行数×字号算,宿主外框 height:auto
|
||||||
|
// 会跟着内容收缩,resize 手柄就能拖到贴字。overflow:hidden 避免自适应高度出滚动条。
|
||||||
|
'.iwb-sticky-body{flex:0 0 auto;min-height:1.7em;width:100%;box-sizing:border-box;resize:none;border:0;outline:0;background:transparent;color:inherit;font-family:inherit;line-height:1.7;padding:12px;overflow:hidden;overflow-wrap:anywhere;cursor:move}' +
|
||||||
|
// 与宿主文本节点一致:只读态单击穿透给节点拖动/选中;双击进入编辑才变 text 光标。
|
||||||
|
// 宿主 style.css 有 `.iwb-node textarea[readonly]{pointer-events:none}`,这里用自身 class 兜底。
|
||||||
|
'.iwb-sticky-body.iwb-sticky-editing{cursor:text}' +
|
||||||
|
'.iwb-sticky-body::placeholder{opacity:.45}' +
|
||||||
|
'.iwb-sticky-color-input{position:absolute;width:0;height:0;opacity:0;pointer-events:none}'
|
||||||
|
try {
|
||||||
|
var styleEl = el('style', { text: css })
|
||||||
|
styleEl.setAttribute('id', 'iwb-sticky-style')
|
||||||
|
;(document.head || document.documentElement).appendChild(styleEl)
|
||||||
|
} catch (e) { /* 样式注入失败不影响功能 */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 插件面板/节点体是真实 DOM(不是 React vDOM):createElement + addEventListener。
|
||||||
|
function el(tag, attrs, kids) {
|
||||||
|
var node = document.createElement(tag)
|
||||||
|
if (attrs) {
|
||||||
|
for (var key in attrs) {
|
||||||
|
var value = attrs[key]
|
||||||
|
if (value === null || value === undefined) continue
|
||||||
|
if (key === 'class' || key === 'className') node.className = value
|
||||||
|
else if (key === 'text') node.textContent = String(value)
|
||||||
|
else if (key === 'hidden') node.hidden = Boolean(value)
|
||||||
|
else if (key.slice(0, 2) === 'on') node.addEventListener(key.slice(2).toLowerCase(), value)
|
||||||
|
else node.setAttribute(key, String(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (kids !== null && kids !== undefined) {
|
||||||
|
var list = Array.isArray(kids) ? kids : [kids]
|
||||||
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
if (list[i] === null || list[i] === undefined || list[i] === false) continue
|
||||||
|
node.appendChild(typeof list[i] === 'string' ? document.createTextNode(list[i]) : list[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
var MIN_SIZE = 6 // 下限(用户只要求取消上限,下限保留防误操作缩到看不见)
|
||||||
|
var SIZE_STEP = 2 // A−/A+ 每步 ±2
|
||||||
|
var DEFAULT_SIZE = 14
|
||||||
|
var PALETTE = [
|
||||||
|
{ name: '黄', value: '#FCE8B0' },
|
||||||
|
{ name: '粉', value: '#F4C0D1' },
|
||||||
|
{ name: '橙', value: '#EF9F27' },
|
||||||
|
{ name: '绿', value: '#9FE1CB' },
|
||||||
|
{ name: '蓝', value: '#B5D4F4' },
|
||||||
|
{ name: '浅紫', value: '#CECBF6' },
|
||||||
|
{ name: '玫红', value: '#ED93B1' },
|
||||||
|
{ name: '灰', value: '#D3D1C7' },
|
||||||
|
]
|
||||||
|
var DEFAULT_BG = '#FCE8B0'
|
||||||
|
|
||||||
|
// 只保证是 >= 下限的有限数,不再钳到闭集/上限;A+ 可无限放大。
|
||||||
|
function normSize(v) {
|
||||||
|
var n = Number(v)
|
||||||
|
if (!isFinite(n) || n < MIN_SIZE) return DEFAULT_SIZE
|
||||||
|
return Math.round(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 依据背景亮度取黑/白文字(运行时计算,源码里不写死中性色)。
|
||||||
|
function textColorOf(hex) {
|
||||||
|
var m = /^#?([0-9a-f]{6})$/i.exec(String(hex || ''))
|
||||||
|
if (!m) return '#1c2333'
|
||||||
|
var n = parseInt(m[1], 16)
|
||||||
|
var r = (n >> 16) & 255, g = (n >> 8) & 255, b = n & 255
|
||||||
|
// 相对亮度(sRGB 简化)
|
||||||
|
var lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255
|
||||||
|
return lum < 0.55 ? '#ffffff' : '#1c2333'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 脚本执行时就注入(不等 setup / mount,存档直入画布也有样式)。
|
||||||
|
ensureStyle()
|
||||||
|
|
||||||
|
var ctxRef = null
|
||||||
|
|
||||||
|
// ---------------- 节点体 ----------------
|
||||||
|
// 宿主契约:render(node, props, host) 往 host 这个真实 DOM 里画,不是返回 vDOM。
|
||||||
|
// host 由宿主固定、不重建;插件自己缓存骨架 + 幂等同步,编辑中的 textarea 不覆盖值。
|
||||||
|
function renderSticky(node, props, host) {
|
||||||
|
ensureStyle()
|
||||||
|
var data = (node && node.data) || {}
|
||||||
|
var st = host.__sticky
|
||||||
|
if (!st) {
|
||||||
|
host.textContent = ''
|
||||||
|
st = host.__sticky = buildSkeleton(host, props)
|
||||||
|
}
|
||||||
|
st.node = node
|
||||||
|
st.props = props
|
||||||
|
syncSkeleton(st, data, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildSkeleton(host, props) {
|
||||||
|
var root = el('div', { className: 'iwb-sticky-node' })
|
||||||
|
var tools = el('div', { className: 'iwb-sticky-tools' })
|
||||||
|
|
||||||
|
var minus = el('button', { className: 'iwb-sticky-btn', type: 'button', title: '缩小字号', 'data-act': 'minus' }, '−')
|
||||||
|
var plus = el('button', { className: 'iwb-sticky-btn', type: 'button', title: '放大字号', 'data-act': 'plus' }, '+')
|
||||||
|
var bold = el('button', { className: 'iwb-sticky-btn', type: 'button', title: '切换粗细', 'data-act': 'bold' }, 'B')
|
||||||
|
var dot = el('button', { className: 'iwb-sticky-dot', type: 'button', title: '背景色', 'data-act': 'palette' })
|
||||||
|
var pal = el('div', { className: 'iwb-sticky-pal', hidden: true })
|
||||||
|
var colorInput = el('input', { type: 'color', className: 'iwb-sticky-color-input', 'data-act': 'color' })
|
||||||
|
// rows=1 是关键:textarea 默认 rows=2,fitBody() 把高度设 auto 读 scrollHeight 时,
|
||||||
|
// 单行文字也会被算成两行高(用户报的“预留了一行文本高度”)。显式 1 行后,
|
||||||
|
// scrollHeight 才等于真实内容行数——多行文本仍会自动换行、高度跟着涨。
|
||||||
|
var body = el('textarea', { className: 'iwb-sticky-body', rows: '1', spellcheck: 'false', placeholder: '双击编辑…' })
|
||||||
|
// 对齐宿主文本节点:默认只读。宿主 CSS `.iwb-node textarea[readonly]{pointer-events:none}`
|
||||||
|
// ⇒ 单击穿透给节点卡片(选中/拖动);双击由本插件在 root 上接管进入编辑。
|
||||||
|
body.readOnly = true
|
||||||
|
body.setAttribute('readonly', '')
|
||||||
|
|
||||||
|
tools.appendChild(minus); tools.appendChild(plus); tools.appendChild(bold); tools.appendChild(dot)
|
||||||
|
// 色板挂在工具条内(tools 已 position:relative):CSS top:100% 落在调色按钮正下方,
|
||||||
|
// 而不是贴整个便签底部右下角(那样会盖住宿主 resize 手柄、且离按钮很远)。
|
||||||
|
tools.appendChild(pal)
|
||||||
|
root.appendChild(tools); root.appendChild(colorInput); root.appendChild(body)
|
||||||
|
host.appendChild(root)
|
||||||
|
|
||||||
|
var st = { root: root, tools: tools, minus: minus, plus: plus, bold: bold, dot: dot,
|
||||||
|
pal: pal, colorInput: colorInput, body: body, data: null, palOpen: false, editing: false }
|
||||||
|
|
||||||
|
function onTool(e) {
|
||||||
|
var t = e.target || {}
|
||||||
|
var act = t.getAttribute && t.getAttribute('data-act')
|
||||||
|
if (!act) return
|
||||||
|
e.stopPropagation && e.stopPropagation()
|
||||||
|
var d = (st.node && st.node.data) || {}
|
||||||
|
var up = st.props && st.props.onUpdate
|
||||||
|
var id = st.node && st.node.id
|
||||||
|
if (!up || !id) return
|
||||||
|
if (act === 'minus' || act === 'plus') {
|
||||||
|
var cur = normSize(d.fontSize == null ? DEFAULT_SIZE : d.fontSize)
|
||||||
|
var next = act === 'minus' ? Math.max(MIN_SIZE, cur - SIZE_STEP) : cur + SIZE_STEP
|
||||||
|
if (next !== cur) up(id, { fontSize: next })
|
||||||
|
} else if (act === 'bold') {
|
||||||
|
up(id, { fontWeight: d.fontWeight === 600 ? 400 : 600 })
|
||||||
|
} else if (act === 'palette') {
|
||||||
|
st.palOpen = !st.palOpen
|
||||||
|
pal.hidden = !st.palOpen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tools.addEventListener('click', onTool)
|
||||||
|
|
||||||
|
// 色板里的色块 + 色轮(事件委托到 pal)
|
||||||
|
for (var i = 0; i < PALETTE.length; i++) {
|
||||||
|
var sw = el('button', { type: 'button', className: 'iwb-sticky-pal-sw', 'data-bg': PALETTE[i].value,
|
||||||
|
title: PALETTE[i].name, style: 'background:' + PALETTE[i].value })
|
||||||
|
pal.appendChild(sw)
|
||||||
|
}
|
||||||
|
var wheelWrap = el('div', { className: 'iwb-sticky-wheel' })
|
||||||
|
var wheel = el('button', { type: 'button', className: 'iwb-sticky-wheel-btn', title: '自定义颜色', 'data-act': 'wheel' })
|
||||||
|
wheelWrap.appendChild(wheel); pal.appendChild(wheelWrap)
|
||||||
|
|
||||||
|
function onPal(e) {
|
||||||
|
var t = e.target || {}
|
||||||
|
e.stopPropagation && e.stopPropagation()
|
||||||
|
var up = st.props && st.props.onUpdate
|
||||||
|
var id = st.node && st.node.id
|
||||||
|
if (!up || !id) return
|
||||||
|
var bg = t.getAttribute && t.getAttribute('data-bg')
|
||||||
|
if (bg) {
|
||||||
|
up(id, { bgColor: bg })
|
||||||
|
st.palOpen = false; pal.hidden = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var act = t.getAttribute && t.getAttribute('data-act')
|
||||||
|
if (act === 'wheel') {
|
||||||
|
// 点开系统取色器后这个浮层就完成使命:无论最终确认还是取消都先收起,
|
||||||
|
// 避免取色器关闭后色板还压在便签上(用户报的“自定义调色后面板不退出”)。
|
||||||
|
st.palOpen = false; pal.hidden = true
|
||||||
|
try { colorInput.click() } catch (e2) { /* noop */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pal.addEventListener('click', onPal)
|
||||||
|
|
||||||
|
function onColor(e) {
|
||||||
|
var up = st.props && st.props.onUpdate
|
||||||
|
var id = st.node && st.node.id
|
||||||
|
if (up && id && e.target && e.target.value) up(id, { bgColor: e.target.value })
|
||||||
|
// 自定义色确认后兜底再收一次(个别平台 change 先于上面的收起逻辑到达)。
|
||||||
|
st.palOpen = false; pal.hidden = true
|
||||||
|
}
|
||||||
|
colorInput.addEventListener('change', onColor)
|
||||||
|
|
||||||
|
// ---- 正文编辑状态机(照宿主文本节点:双击进编辑、失焦退出、只读态单击穿透)----
|
||||||
|
function setEditing(on) {
|
||||||
|
st.editing = on
|
||||||
|
body.readOnly = !on
|
||||||
|
if (on) { try { body.removeAttribute('readonly') } catch (e2) { /* noop */ } }
|
||||||
|
else body.setAttribute('readonly', '')
|
||||||
|
body.className = 'iwb-sticky-body' + (on ? ' iwb-sticky-editing' : '')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 双击进入编辑:绑在 root 上(不是 readonly textarea —— 它 pointer-events:none 收不到双击)。
|
||||||
|
// 宿主卡片 onDoubleClick 只处理内置文本类型,plugin: 节点它不接管,所以这里自己 stopPropagation。
|
||||||
|
function onDblClick(e) {
|
||||||
|
// 工具条/色板/按钮上的双击不进编辑
|
||||||
|
var t = e.target || {}
|
||||||
|
if (t.getAttribute && t.getAttribute('data-act')) return
|
||||||
|
if (t.getAttribute && t.getAttribute('data-bg')) return
|
||||||
|
e.stopPropagation && e.stopPropagation()
|
||||||
|
setEditing(true)
|
||||||
|
try { body.focus() } catch (e2) { /* noop */ }
|
||||||
|
}
|
||||||
|
root.addEventListener('dblclick', onDblClick)
|
||||||
|
|
||||||
|
// 编辑态:按下/按键不冒泡给宿主(否则会拖节点 / 触发画布快捷键);失焦退出编辑。
|
||||||
|
;['pointerdown', 'mousedown'].forEach(function (ev) {
|
||||||
|
body.addEventListener(ev, function (e) {
|
||||||
|
if (st.editing) e.stopPropagation && e.stopPropagation()
|
||||||
|
// 只读态不拦:让宿主选中节点 + 拖动
|
||||||
|
})
|
||||||
|
})
|
||||||
|
body.addEventListener('keydown', function (e) {
|
||||||
|
e.stopPropagation && e.stopPropagation()
|
||||||
|
if (e.key === 'Escape') { try { body.blur() } catch (e2) { /* noop */ } }
|
||||||
|
})
|
||||||
|
body.addEventListener('blur', function () { setEditing(false) })
|
||||||
|
|
||||||
|
// 输入即写回(防抖交给宿主的 commitCanvas),编辑中不重建 DOM 故不失焦。
|
||||||
|
function onInput(e) {
|
||||||
|
var up = st.props && st.props.onUpdate
|
||||||
|
var id = st.node && st.node.id
|
||||||
|
if (up && id) up(id, { text: e.target.value })
|
||||||
|
e.stopPropagation && e.stopPropagation()
|
||||||
|
}
|
||||||
|
body.addEventListener('input', onInput)
|
||||||
|
|
||||||
|
st._listeners = { tools: onTool, pal: onPal, color: onColor, input: onInput, dblclick: onDblClick, setEditing: setEditing }
|
||||||
|
return st
|
||||||
|
}
|
||||||
|
|
||||||
|
// textarea 高度贴字:数据(文本/字号)变了才重算,避免每次 render 都 reflow。
|
||||||
|
// 设 auto → 读 scrollHeight → 写回,是 textarea 自适应的标准做法;浏览器里行数/自动换行都算准。
|
||||||
|
function fitBody(st, text, size) {
|
||||||
|
if (st.fitText === text && st.fitSize === size) return
|
||||||
|
st.fitText = text; st.fitSize = size
|
||||||
|
var b = st.body
|
||||||
|
var prev = b.style.height
|
||||||
|
b.style.height = 'auto'
|
||||||
|
var h = b.scrollHeight
|
||||||
|
b.style.height = (h && h > 0 ? h : Math.max(1, text.split('\n').length) * Math.round(size * 1.7) + 24) + 'px'
|
||||||
|
// 高度没变就不留空字符串(兼容 stub:style.height 是普通对象)
|
||||||
|
if (!b.style.height && prev) b.style.height = prev
|
||||||
|
}
|
||||||
|
|
||||||
|
// 宿主 NodeCard 把 node.h 当作 minHeight 写在外框上(style.minHeight = node.h, height:auto)。
|
||||||
|
// 这就是 v1.0.2「内容贴字了但外框还有一截空白、手柄拖不下去」的真正原因:插件只改了
|
||||||
|
// textarea 高度,外框仍被 node.h 撑住。这里做两件事:
|
||||||
|
// 1. 内容高度 = 工具条 + 正文(不用 root.offsetHeight:root 会被旧的 minHeight 拉高,
|
||||||
|
// 读出来还是旧高度,会自我锁死);
|
||||||
|
// 2. 首次遇到「旧 h 明显大于内容」时把 node.h 校正到内容高度,顺手把外框 minHeight
|
||||||
|
// 覆盖成同一个值——resize 起点 (onResizeStart 读 n0.h) 才和实际视觉一致,拖小立刻生效。
|
||||||
|
// 区分两种 h:
|
||||||
|
// - 插件自动跟随内容写出的 h:内容长高就涨、缩回就降(v1.0.6 修的「两行退回一行不缩」);
|
||||||
|
// - 用户拖手柄改出的 h:h 相对上一帧变了 ⇒ 尊重手动尺寸,只在内容超过它时顶一下。
|
||||||
|
// 首次遇到的旧大 h 校正一次(staleH),之后进入自动跟随。
|
||||||
|
function fitOuterBox(st, node) {
|
||||||
|
if (!st || !st.root || !node) return
|
||||||
|
var toolsH = st.tools.offsetHeight || 30
|
||||||
|
var bodyH = parseFloat(st.body.style.height) || 0
|
||||||
|
if (!bodyH) return
|
||||||
|
var content = Math.round(toolsH + bodyH + 2) // +2 = 宿主节点上下各 1px 边框
|
||||||
|
var h = Number(node.h) || 0
|
||||||
|
if (st.staleH == null) st.staleH = h
|
||||||
|
|
||||||
|
if (st.lastBoxH != null && h !== st.lastBoxH) {
|
||||||
|
// 外部(用户拖手柄)改了 h:退出自动跟随,保留手动尺寸
|
||||||
|
st.autoFollow = false
|
||||||
|
} else if (st.autoFollow == null) {
|
||||||
|
// 首帧:旧 h 若明显大于内容,先校正一次,然后进入自动跟随
|
||||||
|
if (h > content + 2 && st.staleH === h) { node.h = content; h = content }
|
||||||
|
st.autoFollow = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (st.autoFollow) {
|
||||||
|
// 自动跟随:文本/字号增减都双向贴合(这是两行退回一行能缩回去的关键)
|
||||||
|
if (Math.abs(h - content) > 1) { node.h = content; h = content }
|
||||||
|
} else if (h < content - 2) {
|
||||||
|
// 手动尺寸只在内容超出时才顶高,不覆盖用户主动拖大的高度
|
||||||
|
node.h = content; h = content
|
||||||
|
}
|
||||||
|
st.lastBoxH = h
|
||||||
|
var floor = Math.max(content, Number(node.h) || 0)
|
||||||
|
// root → host(.iwb-plugin-node-body) → card(.iwb-node)
|
||||||
|
var card = st.root.parentNode && st.root.parentNode.parentNode
|
||||||
|
if (card && card.style && card.style.minHeight !== floor + 'px') card.style.minHeight = floor + 'px'
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncSkeleton(st, data, node) {
|
||||||
|
var bg = data.bgColor || DEFAULT_BG
|
||||||
|
var size = normSize(data.fontSize == null ? DEFAULT_SIZE : data.fontSize)
|
||||||
|
var weight = data.fontWeight === 600 ? 600 : 400
|
||||||
|
var text = data.text == null ? '' : String(data.text)
|
||||||
|
var color = textColorOf(bg)
|
||||||
|
|
||||||
|
// 幂等:只在值真的变了才写 DOM,避免重建/覆盖正在编辑的 textarea。
|
||||||
|
if (st.root.style.background !== bg) st.root.style.background = bg
|
||||||
|
if (st.root.style.color !== color) st.root.style.color = color
|
||||||
|
if (!st.editing && document.activeElement !== st.body && st.body.value !== text) st.body.value = text
|
||||||
|
if (st.body.style.fontSize !== size + 'px') st.body.style.fontSize = size + 'px'
|
||||||
|
if (st.body.style.fontWeight !== String(weight)) st.body.style.fontWeight = String(weight)
|
||||||
|
fitBody(st, text, size)
|
||||||
|
fitOuterBox(st, node)
|
||||||
|
if (st.bold.className !== 'iwb-sticky-btn' + (weight === 600 ? ' iwb-sticky-btn-on' : '')) {
|
||||||
|
st.bold.className = 'iwb-sticky-btn' + (weight === 600 ? ' iwb-sticky-btn-on' : '')
|
||||||
|
}
|
||||||
|
if (st.dot.style.background !== bg) st.dot.style.background = bg
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- 面板 ----------------
|
||||||
|
var ctxForPanel = null
|
||||||
|
var noteList = []
|
||||||
|
|
||||||
|
function refreshList() {
|
||||||
|
if (!ctxForPanel) return
|
||||||
|
var host = ctxForPanel.__stickyPanelRoot
|
||||||
|
if (!host || typeof host.innerHTML !== 'undefined' && !host.innerHTML && !host.appendChild) return
|
||||||
|
var list = host.querySelector ? host.querySelector('.iwb-sticky-list') : null
|
||||||
|
if (!list) return
|
||||||
|
// 尽力从画布读回便利贴节点(只读画布能力给了 getNodes)
|
||||||
|
var nodes = []
|
||||||
|
try {
|
||||||
|
var api = ctxRef && ctxRef.canvas
|
||||||
|
if (api && typeof api.getNodes === 'function') nodes = api.getNodes() || []
|
||||||
|
} catch (e) { nodes = [] }
|
||||||
|
var mine = nodes.filter(function (n) { return String(n.type || '').indexOf('plugin:sticky:') === 0 })
|
||||||
|
// 用最近插入的本地记录补足(getNodes 快照不含自定义状态没关系,这里只显示文本)
|
||||||
|
var seen = {}
|
||||||
|
var rows = []
|
||||||
|
mine.concat(noteList).forEach(function (n) {
|
||||||
|
var key = n.id
|
||||||
|
if (!key || seen[key]) return
|
||||||
|
seen[key] = 1
|
||||||
|
var text = String((n.data && n.data.text) || '').replace(/\s+/g, ' ').slice(0, 30) || '(空便利贴)'
|
||||||
|
rows.push({ id: key, text: text })
|
||||||
|
})
|
||||||
|
while (list.firstChild) list.removeChild(list.firstChild)
|
||||||
|
rows.slice(-20).forEach(function (r) {
|
||||||
|
var row = el('div', { className: 'iwb-sticky-row' })
|
||||||
|
row.appendChild(el('span', { className: 'iwb-sticky-row-txt' }, r.text))
|
||||||
|
var go = el('button', { className: 'iwb-sticky-go', type: 'button' }, '定位')
|
||||||
|
go.addEventListener('click', function () {
|
||||||
|
try { if (ctxRef && ctxRef.canvas && typeof ctxRef.canvas.focusNode === 'function') ctxRef.canvas.focusNode(r.id) } catch (e) { /* noop */ }
|
||||||
|
})
|
||||||
|
row.appendChild(go)
|
||||||
|
list.appendChild(row)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountPanel(host, ctx) {
|
||||||
|
ensureStyle()
|
||||||
|
ctxForPanel = ctx
|
||||||
|
host.textContent = ''
|
||||||
|
host.style.minWidth = '0'; host.style.minHeight = '0'; host.style.height = '100%'
|
||||||
|
var wrap = el('div', { className: 'iwb-sticky-panel' })
|
||||||
|
wrap.appendChild(el('div', { className: 'iwb-sticky-panel-tip' },
|
||||||
|
'在画布上放一张便利贴:字调大当说明标题,字调小放多行正文。点右下角拖动手柄可改变便签大小。'))
|
||||||
|
var add = el('button', { className: 'iwb-sticky-add', type: 'button' }, '+ 插入便利贴')
|
||||||
|
add.addEventListener('click', function () { insertNote() })
|
||||||
|
wrap.appendChild(add)
|
||||||
|
var list = el('div', { className: 'iwb-sticky-list' })
|
||||||
|
wrap.appendChild(list)
|
||||||
|
host.appendChild(wrap)
|
||||||
|
ctxForPanel.__stickyPanelRoot = host
|
||||||
|
refreshList()
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertNote() {
|
||||||
|
var api = ctxRef && ctxRef.canvas
|
||||||
|
if (!api || typeof api.createNode !== 'function') return null
|
||||||
|
var id = api.createNode('plugin:sticky:sticky', null, null, {
|
||||||
|
text: '', fontSize: DEFAULT_SIZE, fontWeight: 400, bgColor: DEFAULT_BG,
|
||||||
|
})
|
||||||
|
if (id) {
|
||||||
|
noteList.push({ id: id, data: { text: '' } })
|
||||||
|
refreshList()
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
function dispose() {
|
||||||
|
ctxRef = null
|
||||||
|
ctxForPanel = null
|
||||||
|
noteList = []
|
||||||
|
}
|
||||||
|
|
||||||
|
global.IWBPluginHost.register({
|
||||||
|
id: 'sticky',
|
||||||
|
name: '便利贴',
|
||||||
|
version: '1.0.7',
|
||||||
|
apiVersion: 1,
|
||||||
|
capabilities: ['panels', 'nodeTypes', 'canvas'],
|
||||||
|
}, function (ctx) {
|
||||||
|
ctxRef = ctx
|
||||||
|
if (ctx.nodes && typeof ctx.nodes.register === 'function') {
|
||||||
|
ctx.nodes.register({
|
||||||
|
id: 'sticky',
|
||||||
|
title: '便利贴',
|
||||||
|
defaults: {},
|
||||||
|
ports: { in: false, out: false },
|
||||||
|
height: 180,
|
||||||
|
render: renderSticky,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ctx.ui && typeof ctx.ui.registerPanel === 'function') {
|
||||||
|
ctx.ui.registerPanel({
|
||||||
|
id: 'sticky',
|
||||||
|
title: '便利贴',
|
||||||
|
icon: 'note',
|
||||||
|
mount: mountPanel,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return { dispose: dispose }
|
||||||
|
})
|
||||||
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
@@ -0,0 +1,343 @@
|
|||||||
|
// 便利贴插件本地契约测试(纯 node,不依赖 playwright / 真浏览器)。
|
||||||
|
// 用最小 DOM / window stub 跑真实 src/index.js(IIFE),验证:
|
||||||
|
// manifest 字段 / 节点类型注册(标题/不连线/height)/ 面板注册 /
|
||||||
|
// CSS 脚本执行时就注入 / 字号闭集与 A+/A− / 粗细切换 / 8 色背景 + 色轮自定义 /
|
||||||
|
// 多行文本写回 data / 幂等同步(编辑中不覆盖、值变才写 DOM)/ 插入走 createNode(null,null)。
|
||||||
|
//
|
||||||
|
// 运行:node sticky/tools/harness.mjs (退出码 0 = 全过)
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import vm from 'node:vm'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
const source = readFileSync(ENTRY, 'utf8')
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const check = (name, ok, detail) => {
|
||||||
|
if (!ok) failed++
|
||||||
|
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 极简 DOM stub ----------
|
||||||
|
function makeNode(tag) {
|
||||||
|
return {
|
||||||
|
tagName: String(tag).toUpperCase(),
|
||||||
|
children: [], parentNode: null, _text: '', attrs: {}, listeners: {},
|
||||||
|
style: {}, className: '', hidden: false, value: '',
|
||||||
|
// textarea 自适应高度需要 scrollHeight:按「行数 × 行高 + 上下 padding」模拟。
|
||||||
|
get scrollHeight() {
|
||||||
|
if (String(tag).toUpperCase() !== 'TEXTAREA') return 0
|
||||||
|
const lines = Math.max(1, String(this.value || '').split('\n').length)
|
||||||
|
const size = parseFloat(this.style.fontSize) || 14
|
||||||
|
return Math.ceil(lines * size * 1.7) + 24
|
||||||
|
},
|
||||||
|
get textContent() { return this._text },
|
||||||
|
set textContent(v) { this._text = String(v); this.children = [] },
|
||||||
|
get firstChild() { return this.children[0] || null },
|
||||||
|
appendChild(c) { this.children.push(c); c.parentNode = this; return c },
|
||||||
|
removeChild(c) { const i = this.children.indexOf(c); if (i >= 0) this.children.splice(i, 1); return c },
|
||||||
|
setAttribute(k, v) { this.attrs[k] = String(v); if (k === 'style') this.style = parseStyle(String(v)) },
|
||||||
|
removeAttribute(k) { delete this.attrs[k] },
|
||||||
|
getAttribute(k) { return k in this.attrs ? this.attrs[k] : null },
|
||||||
|
focus() { this.__doc && (this.__doc.activeElement = this) },
|
||||||
|
blur() { this.__doc && this.__doc.activeElement === this && (this.__doc.activeElement = null); this.fire('blur') },
|
||||||
|
addEventListener(ev, fn) { (this.listeners[ev] = this.listeners[ev] || []).push(fn) },
|
||||||
|
fire(ev, data) {
|
||||||
|
const payload = Object.assign({ target: this, stopPropagation() {} }, data)
|
||||||
|
let n = this
|
||||||
|
while (n) {
|
||||||
|
;(n.listeners[ev] || []).forEach((fn) => fn(payload))
|
||||||
|
n = n.parentNode
|
||||||
|
}
|
||||||
|
},
|
||||||
|
querySelector(cls) {
|
||||||
|
const needle = cls.replace('.', '')
|
||||||
|
const q = [this]
|
||||||
|
while (q.length) {
|
||||||
|
const n = q.shift()
|
||||||
|
if (String(n.className).split(/\s+/).indexOf(needle) >= 0) return n
|
||||||
|
q.push(...(n.children || []))
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
click() { this.fire('click') },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function parseStyle(s) {
|
||||||
|
const out = {}
|
||||||
|
s.split(';').forEach((part) => {
|
||||||
|
const i = part.indexOf(':')
|
||||||
|
if (i > 0) out[part.slice(0, i).trim()] = part.slice(i + 1).trim()
|
||||||
|
})
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPlugin() {
|
||||||
|
const head = makeNode('head')
|
||||||
|
const bodyEl = makeNode('body')
|
||||||
|
const document = {
|
||||||
|
head, documentElement: head, body: bodyEl, activeElement: null,
|
||||||
|
createElement: (tag) => { const n = makeNode(tag); n.__doc = document; return n },
|
||||||
|
createTextNode: (t) => ({ nodeType: 3, textContent: String(t) }),
|
||||||
|
getElementById: (id) => findById(head, id) || findById(bodyEl, id),
|
||||||
|
}
|
||||||
|
const registrations = []
|
||||||
|
let panelApi = null, nodeApi = null
|
||||||
|
const updates = []
|
||||||
|
const createCalls = []
|
||||||
|
const host = {
|
||||||
|
IWBPluginHost: {
|
||||||
|
register(manifest, factory) {
|
||||||
|
registrations.push({ manifest, factory })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
document,
|
||||||
|
React: null,
|
||||||
|
}
|
||||||
|
const ctx = {
|
||||||
|
nodes: { register(def) { nodeApi = def; return true } },
|
||||||
|
ui: { registerPanel(def) { panelApi = def; return true } },
|
||||||
|
canvas: {
|
||||||
|
createNode(type, x, y, data) { createCalls.push({ type, x, y, data }); return 'n1' },
|
||||||
|
getNodes() { return [] },
|
||||||
|
focusNode() {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const sandbox = Object.assign(host, {
|
||||||
|
console: { log() {}, warn() {}, error() {} },
|
||||||
|
window: host,
|
||||||
|
globalThis: host,
|
||||||
|
})
|
||||||
|
vm.createContext(sandbox)
|
||||||
|
vm.runInContext(source, sandbox)
|
||||||
|
// 触发工厂
|
||||||
|
registrations[0].factory(ctx)
|
||||||
|
return { registrations, manifest: registrations[0].manifest, nodeApi, panelApi, ctx, updates, createCalls, document, head }
|
||||||
|
}
|
||||||
|
function findById(root, id) {
|
||||||
|
if (root.attrs && root.attrs.id === id) return root
|
||||||
|
for (const c of root.children || []) { const r = findById(c, id); if (r) return r }
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 测试 ----------
|
||||||
|
const r = runPlugin()
|
||||||
|
|
||||||
|
check('manifest.id = sticky', r.manifest.id === 'sticky')
|
||||||
|
check('manifest.name = 便利贴', r.manifest.name === '便利贴')
|
||||||
|
check('manifest.version = 1.0.7', r.manifest.version === '1.0.7')
|
||||||
|
check('manifest.apiVersion = 1', r.manifest.apiVersion === 1)
|
||||||
|
check('capabilities 含 panels/nodeTypes/canvas',
|
||||||
|
['panels', 'nodeTypes', 'canvas'].every((c) => r.manifest.capabilities.includes(c)))
|
||||||
|
check('CSS 在脚本执行时就注入(#iwb-sticky-style)', !!findById(r.head, 'iwb-sticky-style'))
|
||||||
|
|
||||||
|
check('节点类型已注册', !!r.nodeApi)
|
||||||
|
check('节点 ports 全关(不连线)', r.nodeApi && r.nodeApi.ports.in === false && r.nodeApi.ports.out === false)
|
||||||
|
check('节点 title = 便利贴', r.nodeApi && r.nodeApi.title === '便利贴')
|
||||||
|
check('节点有 render 函数', r.nodeApi && typeof r.nodeApi.render === 'function')
|
||||||
|
check('面板已注册', !!r.panelApi && typeof r.panelApi.mount === 'function')
|
||||||
|
|
||||||
|
// 构造节点 host 并渲染(带 onUpdate 收集 patch)
|
||||||
|
function makeNodeHost() {
|
||||||
|
const h = makeNode('div')
|
||||||
|
h.__updates = []
|
||||||
|
const props = { onUpdate(id, patch) { h.__updates.push({ id, patch }) } }
|
||||||
|
const node = { id: 'n1', type: 'plugin:sticky:sticky', data: { text: '标题', fontSize: 14, fontWeight: 400, bgColor: '#FCE8B0' } }
|
||||||
|
r.nodeApi.render(node, props, h)
|
||||||
|
return { h, node, props }
|
||||||
|
}
|
||||||
|
const nh = makeNodeHost()
|
||||||
|
check('节点体注入 .iwb-sticky-node', !!findByClass(nh.h, 'iwb-sticky-node'))
|
||||||
|
check('节点体有工具条 A+/A−/B + 色板按钮', !!findByClass(nh.h, 'iwb-sticky-tools') && !!findByClass(nh.h, 'iwb-sticky-pal'))
|
||||||
|
check('节点体有 textarea', findByClass(nh.h, 'iwb-sticky-body') && findByClass(nh.h, 'iwb-sticky-body').tagName === 'TEXTAREA')
|
||||||
|
check('默认文本同步到 textarea', findByClass(nh.h, 'iwb-sticky-body').value === '标题')
|
||||||
|
|
||||||
|
// v1.0.2:色板挂在工具条内(top:100% 落调色按钮下方),不再贴便签底部右下角盖住 resize 手柄
|
||||||
|
const toolsBox = findByClass(nh.h, 'iwb-sticky-tools')
|
||||||
|
const palBox = findByClass(nh.h, 'iwb-sticky-pal')
|
||||||
|
check('色板挂在工具条内(跟随调色按钮,不盖 resize 手柄)', palBox && palBox.parentNode === toolsBox)
|
||||||
|
check('色板 CSS top:100%(落按钮下方)', /\.iwb-sticky-pal\{position:absolute;top:100%/.test(injectedCssOf(r)))
|
||||||
|
// v1.0.2:textarea 高度随内容自适应(flex:0 0 auto + JS 写 height)
|
||||||
|
check('textarea flex:0 0 auto(不 flex 撑满留白)', /\.iwb-sticky-body\{flex:0 0 auto/.test(injectedCssOf(r)))
|
||||||
|
function injectedCssOf(rr) { return (findById(rr.head, 'iwb-sticky-style') || {}).textContent || '' }
|
||||||
|
const taInit = findByClass(nh.h, 'iwb-sticky-body')
|
||||||
|
check('textarea 显式 rows=1(不预留默认第二行)', taInit.getAttribute('rows') === '1')
|
||||||
|
check('textarea 初始高度按内容算出(贴字)', parseFloat(taInit.style.height) > 0)
|
||||||
|
check('调色圆点推到工具条最右(右上)', /\.iwb-sticky-dot\{[^}]*margin-left:auto/.test(injectedCssOf(r)))
|
||||||
|
|
||||||
|
// v1.0.3:宿主外框 minHeight 来自 node.h —— 旧 h 会把便签撑出一截空白且手柄拖不下去。
|
||||||
|
// 用带父节点卡片的 host 复现:渲染后必须把外框 minHeight 校正成内容高度,并同步改正 node.h。
|
||||||
|
const card = makeNode('div')
|
||||||
|
card.style.minHeight = '360px'
|
||||||
|
const host2 = makeNode('div')
|
||||||
|
card.appendChild(host2)
|
||||||
|
const node2 = { id: 'n2', type: 'plugin:sticky:sticky', h: 360,
|
||||||
|
data: { text: '范例', fontSize: 40, fontWeight: 600, bgColor: '#FCE8B0' } }
|
||||||
|
r.nodeApi.render(node2, { onUpdate() {} }, host2)
|
||||||
|
const expectedH = Math.round(30 + parseFloat(findByClass(host2, 'iwb-sticky-body').style.height) + 2)
|
||||||
|
check('外框 minHeight 覆盖为内容高度(不再被旧 h 撑住)', card.style.minHeight === expectedH + 'px',
|
||||||
|
'card=' + card.style.minHeight + ' expected=' + expectedH + 'px')
|
||||||
|
check('旧 node.h 校正为内容高度(resize 起点贴字)', node2.h === expectedH, 'h=' + node2.h)
|
||||||
|
// 用户之后手动拖大的 h 不能被再次压回(仍然可拖大拖小)
|
||||||
|
node2.h = 260
|
||||||
|
r.nodeApi.render(node2, { onUpdate() {} }, host2)
|
||||||
|
check('用户拖大后的 h 保留(可拖大)', node2.h === 260 && card.style.minHeight === '260px',
|
||||||
|
'h=' + node2.h + ' minH=' + card.style.minHeight)
|
||||||
|
|
||||||
|
// v1.0.6:自动跟随内容的 h 必须双向伸缩——两行退回一行时外框要跟着缩回去。
|
||||||
|
const card3 = makeNode('div')
|
||||||
|
const host3 = makeNode('div')
|
||||||
|
card3.appendChild(host3)
|
||||||
|
const node3 = { id: 'n3', type: 'plugin:sticky:sticky',
|
||||||
|
data: { text: '一行', fontSize: 40, fontWeight: 400, bgColor: '#FCE8B0' } }
|
||||||
|
const pass3 = { onUpdate() {} }
|
||||||
|
r.nodeApi.render(node3, pass3, host3)
|
||||||
|
const hOneLine = node3.h
|
||||||
|
node3.data.text = '第一行\n第二行'
|
||||||
|
r.nodeApi.render(node3, pass3, host3)
|
||||||
|
const hTwoLines = node3.h
|
||||||
|
check('文本一行变两行:外框自动长高', hTwoLines > hOneLine, hOneLine + ' → ' + hTwoLines)
|
||||||
|
node3.data.text = '一行'
|
||||||
|
r.nodeApi.render(node3, pass3, host3)
|
||||||
|
check('文本两行退回一行:外框自动缩回(v1.0.6)',
|
||||||
|
node3.h === hOneLine && card3.style.minHeight === hOneLine + 'px',
|
||||||
|
'h=' + node3.h + ' minH=' + card3.style.minHeight)
|
||||||
|
|
||||||
|
function findByClass(root, cls) {
|
||||||
|
const needle = cls.split('.').filter(Boolean).pop()
|
||||||
|
const q = [root]
|
||||||
|
while (q.length) {
|
||||||
|
const n = q.shift()
|
||||||
|
if (String(n.className).split(/\s+/).indexOf(needle) >= 0) return n
|
||||||
|
q.push(...(n.children || []))
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const btn = (cls) => {
|
||||||
|
const q = [nh.h]
|
||||||
|
while (q.length) {
|
||||||
|
const n = q.shift()
|
||||||
|
if (String(n.className).split(/\s+/).indexOf(cls) >= 0) return n
|
||||||
|
q.push(...(n.children || []))
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// A+ → +2 步进(无上限)
|
||||||
|
btn('iwb-sticky-btn') // 占位,实际按 data-act 找
|
||||||
|
const plus = nh.h.querySelectorAll ? null : findByAct(nh.h, 'plus')
|
||||||
|
function findByAct(root, act) {
|
||||||
|
const q = [root]
|
||||||
|
while (q.length) {
|
||||||
|
const n = q.shift()
|
||||||
|
if (n.attrs && n.attrs['data-act'] === act) return n
|
||||||
|
q.push(...(n.children || []))
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
findByAct(nh.h, 'plus').fire('click', { target: findByAct(nh.h, 'plus') })
|
||||||
|
check('A+ 写 fontSize=16(+2 步进)', nh.h.__updates.some((u) => u.patch.fontSize === 16))
|
||||||
|
findByAct(nh.h, 'minus').fire('click', { target: findByAct(nh.h, 'minus') })
|
||||||
|
check('A− 写 fontSize=12(−2 步进)', nh.h.__updates.some((u) => u.patch.fontSize === 12))
|
||||||
|
// 无上限:把数据设成 100,A+ 仍继续涨(旧闭集会钳回 24)
|
||||||
|
nh.node.data.fontSize = 100
|
||||||
|
nh.h.__updates.length = 0
|
||||||
|
findByAct(nh.h, 'plus').fire('click', { target: findByAct(nh.h, 'plus') })
|
||||||
|
check('字号无上限(100 → 102)', nh.h.__updates.some((u) => u.patch.fontSize === 102))
|
||||||
|
// 字号变大 → textarea 高度跟着涨(贴字自适应)
|
||||||
|
const taSize = findByClass(nh.h, 'iwb-sticky-body')
|
||||||
|
const hBefore = parseFloat(taSize.style.height)
|
||||||
|
nh.node.data.fontSize = 40
|
||||||
|
r.nodeApi.render(nh.node, nh.props, nh.h)
|
||||||
|
check('字号 14→40 时 textarea 高度重算变大', parseFloat(taSize.style.height) > hBefore)
|
||||||
|
nh.node.data.fontSize = 14
|
||||||
|
findByAct(nh.h, 'bold').fire('click', { target: findByAct(nh.h, 'bold') })
|
||||||
|
check('B 切 fontWeight=600', nh.h.__updates.some((u) => u.patch.fontWeight === 600))
|
||||||
|
|
||||||
|
// 色板:展开 + 点第 3 个色块(橙)写 bgColor
|
||||||
|
const paletteBtn = findByAct(nh.h, 'palette')
|
||||||
|
paletteBtn.fire('click', { target: paletteBtn })
|
||||||
|
const pal = findByClass(nh.h, 'iwb-sticky-pal')
|
||||||
|
check('点背景按钮展开色板', pal.hidden === false)
|
||||||
|
const swatches = []
|
||||||
|
;(function walk(n) { (n.children || []).forEach((c) => { if (String(c.className).indexOf('iwb-sticky-pal-sw') >= 0) swatches.push(c); walk(c) }) })(pal)
|
||||||
|
check('色板有 8 个预设色', swatches.length === 8)
|
||||||
|
swatches[2].fire('click', { target: swatches[2] })
|
||||||
|
check('点色块写 bgColor=#EF9F27', nh.h.__updates.some((u) => u.patch.bgColor === '#EF9F27'))
|
||||||
|
check('选色后色板收起', pal.hidden === true)
|
||||||
|
check('有色轮自定义按钮', !!findByAct(nh.h, 'wheel'))
|
||||||
|
|
||||||
|
// v1.0.7:自定义调色(色轮)也必须自动收起面板
|
||||||
|
paletteBtn.fire('click', { target: paletteBtn })
|
||||||
|
check('再次展开色板(自定义调色前)', pal.hidden === false)
|
||||||
|
const wheelBtn = findByAct(nh.h, 'wheel')
|
||||||
|
wheelBtn.fire('click', { target: wheelBtn })
|
||||||
|
check('点色轮打开取色器时色板自动收起', pal.hidden === true)
|
||||||
|
const colorInput = findByAct(nh.h, 'color')
|
||||||
|
check('有隐藏的原生取色 input', !!colorInput && colorInput.tagName === 'INPUT')
|
||||||
|
paletteBtn.fire('click', { target: paletteBtn })
|
||||||
|
nh.h.__updates.length = 0
|
||||||
|
colorInput.value = '#C0392B'
|
||||||
|
colorInput.fire('change', { target: colorInput })
|
||||||
|
check('自定义色写回 bgColor', nh.h.__updates.some((u) => u.patch.bgColor === '#C0392B'))
|
||||||
|
check('自定义色确认后色板保持收起', pal.hidden === true)
|
||||||
|
|
||||||
|
// ---- 单击选中 / 双击编辑状态机 ----
|
||||||
|
const ta = findByClass(nh.h, 'iwb-sticky-body')
|
||||||
|
check('正文默认只读(单击穿透给节点选中/拖动)', ta.readOnly === true && ta.getAttribute('readonly') !== null)
|
||||||
|
const injectedCss = (findById(r.head, 'iwb-sticky-style') || {}).textContent || ''
|
||||||
|
check('根容器 flex:1 撑满宿主(修拖动后漏底)', /\.iwb-sticky-node\{[^}]*flex:1 1 auto/.test(injectedCss))
|
||||||
|
check('纸片圆角对齐宿主节点(node-radius - 1px 边框)',
|
||||||
|
/\.iwb-sticky-node\{[^}]*border-radius:calc\(var\(--iwb-node-radius, 14px\) - 1px\)/.test(injectedCss))
|
||||||
|
const rootNode = findByClass(nh.h, 'iwb-sticky-node')
|
||||||
|
const dblEv = { target: ta, stopPropagation() {} }
|
||||||
|
rootNode.fire('dblclick', dblEv)
|
||||||
|
check('双击正文进入编辑(解除 readonly)', ta.readOnly === false && ta.className.indexOf('iwb-sticky-editing') >= 0)
|
||||||
|
check('双击后 textarea 获得焦点', r.document.activeElement === ta)
|
||||||
|
// 编辑态下 pointerdown 冒泡被拦(不拖节点)
|
||||||
|
let downStopped = false
|
||||||
|
ta.fire('pointerdown', { target: ta, stopPropagation() { downStopped = true } })
|
||||||
|
check('编辑态 pointerdown 不冒泡给宿主', downStopped)
|
||||||
|
// 失焦退出编辑、恢复只读
|
||||||
|
ta.fire('blur')
|
||||||
|
check('失焦退出编辑(恢复 readonly)', ta.readOnly === true && ta.className.indexOf('iwb-sticky-editing') < 0)
|
||||||
|
|
||||||
|
// 多行文本写回(编辑态)
|
||||||
|
ta.fire('dblclick', { target: ta, stopPropagation() {} })
|
||||||
|
ta.value = '第一行\n第二行\n第三行'
|
||||||
|
ta.fire('input', { target: ta })
|
||||||
|
check('多行文本写回 data.text', nh.h.__updates.some((u) => u.patch.text === '第一行\n第二行\n第三行'))
|
||||||
|
|
||||||
|
// 幂等同步:编辑中不覆盖正在输入的 textarea
|
||||||
|
const active = ta
|
||||||
|
r.document.activeElement = active
|
||||||
|
nh.node.data.text = '外部改的值'
|
||||||
|
r.nodeApi.render(nh.node, nh.props, nh.h)
|
||||||
|
check('编辑中的 textarea 不被外部数据覆盖', ta.value === '第一行\n第二行\n第三行')
|
||||||
|
ta.fire('blur') // 退出编辑态
|
||||||
|
r.document.activeElement = null
|
||||||
|
nh.node.data.text = '外部改的值'
|
||||||
|
r.nodeApi.render(nh.node, nh.props, nh.h)
|
||||||
|
check('非编辑态 textarea 跟随数据更新', ta.value === '外部改的值')
|
||||||
|
|
||||||
|
// 深/浅背景自动取文字色(运行时算,不写死)
|
||||||
|
const st = nh.h.__sticky
|
||||||
|
check('浅色背景取深色文字', st.root.style.color === '#1c2333')
|
||||||
|
nh.node.data.bgColor = '#1F3350'
|
||||||
|
r.nodeApi.render(nh.node, nh.props, nh.h)
|
||||||
|
check('深色背景取白色文字', st.root.style.color === '#ffffff')
|
||||||
|
|
||||||
|
// 面板插入便利贴走 createNode(null,null)
|
||||||
|
const panelHost = makeNode('div')
|
||||||
|
r.panelApi.mount(panelHost, r.ctx)
|
||||||
|
const addBtn = findByClass(panelHost, 'iwb-sticky-add')
|
||||||
|
addBtn.fire('click', { target: addBtn })
|
||||||
|
check('插入便利贴调 canvas.createNode', r.createCalls.length === 1)
|
||||||
|
check('createNode 类型 = plugin:sticky:sticky', r.createCalls[0] && r.createCalls[0].type === 'plugin:sticky:sticky')
|
||||||
|
check('createNode 坐标 null/null(宿主找空位)', r.createCalls[0] && r.createCalls[0].x === null && r.createCalls[0].y === null)
|
||||||
|
check('插入带默认样式数据', r.createCalls[0] && r.createCalls[0].data.fontSize === 14 && r.createCalls[0].data.bgColor === '#FCE8B0')
|
||||||
|
|
||||||
|
console.log('\n' + (failed ? '✗ ' + failed + ' 项失败' : '✓ 全部通过'))
|
||||||
|
process.exit(failed ? 1 : 0)
|
||||||
+13
-12
@@ -57,8 +57,8 @@
|
|||||||
|
|
||||||
### v1.3.2(2026-11-14)注入点再提前到脚本执行 + 缩略图内联兜底
|
### v1.3.2(2026-11-14)注入点再提前到脚本执行 + 缩略图内联兜底
|
||||||
|
|
||||||
1.3.1 那一版**发布链路上只传了字节、KV 清单没换**(线上仍指 1.3.0 的 hash),所以用户看到的还是坏的那版。
|
1.3.1 那一版**发布链路上只传了字节、市场清单没换**(市场仍指 1.3.0 的 hash),所以用户看到的还是坏的那版。
|
||||||
连带教训:只验证「本地/合成宿主通过」不够,发布后必须回读线上清单与字节(见宿主 `scripts/plugins-publish.sh` 末尾的验收三步)。
|
连带教训:只验证「本地/合成宿主通过」不够,发布后必须回读市场索引与字节(见根 README「发布到市场」末尾的验收要求)。
|
||||||
|
|
||||||
这次的改动:
|
这次的改动:
|
||||||
|
|
||||||
@@ -179,31 +179,32 @@
|
|||||||
|
|
||||||
## 不需要改宿主 CSP
|
## 不需要改宿主 CSP
|
||||||
|
|
||||||
数据与图片都是公网 `https://`,宿主 `_headers` 的 `img-src … https:` / `connect-src … https:` 已经放行。对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
数据与图片都是公网 `https://`,桌面宿主 `tauri.conf.json` 的 `img-src … https:` / `connect-src … https:` 已经放行。
|
||||||
|
对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
||||||
|
|
||||||
## 测试(三层,从快到慢)
|
## 测试(三层,从快到慢)
|
||||||
|
|
||||||
| 层 | 命令 | 覆盖什么 | 依赖 |
|
| 层 | 命令 | 覆盖什么 | 依赖 |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、截图 | 无(自带 mock 宿主) |
|
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、截图 | 无(自带 mock 宿主) |
|
||||||
| 线上真网 | `node tools/e2e-real.mjs`(10 项) | 线上 `styles.json` 真拉的到、真 CSP、卡片渲染、样式节点入口 | 网络 |
|
| 线上数据真网 | `node tools/e2e-real.mjs`(10 项) | styles.json 真拉得到、卡片渲染、样式节点入口 | 网络 |
|
||||||
| 测试站端到端 | `node tools/e2e-test-site.mjs`(15 项) | **宿主新接口到底接上没有**:双击进画布 → 开资源库 → 点「样式节点」→ 节点体由插件渲染、示例图默认勾选、变量输入不失焦、多变量不裁切、收起生效 | 宿主已发测试站(`SITE=` 换地址,`HEADED=1` 看着跑) |
|
| 桌面客户端端到端 | `node tools/e2e-test-site.mjs`(15 项) | **宿主新接口到底接上没有**:进画布 → 开资源库 → 点「样式节点」→ 节点体由插件渲染、示例图默认勾选、变量输入不失焦、多变量不裁切、收起生效 | 桌面客户端已装本插件(`SITE=` 换地址,`HEADED=1` 看着跑) |
|
||||||
|
|
||||||
前两支只验插件自己;**第三支才验宿主**,发布宿主改动后必跑。
|
前两支只验插件自己;**第三支才验宿主**,发布宿主改动后必跑。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
`src/index.js` 是手写单文件 IIFE,不构建。走宿主仓带守卫的发布脚本(会拒发「宿主工作区脏」和「HEAD 不在 origin/main」):
|
`src/index.js` 是手写单文件 IIFE,不构建。发布走桌面仓的市场链路,见根 README「发布到市场」:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp src/index.js /tmp/plugin-style-source.js
|
npm run validate
|
||||||
cd ../image-workbench-web
|
# 桌面仓:node scripts/sync-plugins-from-repo.js && node scripts/gen-market.js
|
||||||
scripts/plugins-publish.sh style-source /tmp/plugin-style-source.js 1.3.0
|
# 再把 market/ 上传到 NAS(market.maqiart.eu.org)
|
||||||
```
|
```
|
||||||
|
|
||||||
脚本会算 SRI、生成内容寻址名 `plugin-style-source.<hash12>.js`、**合并**进 KV 清单,并把宿主仓本地的 `plugins/index.json` 一起改掉(**记得提交那一处改动**)。它顺手打的 tag `style-source@1.3.0` **不会自动推**:`git push origin style-source@1.3.0`。
|
桌面仓同步脚本会算 SRI、生成内容寻址名 `plugin-style-source.<hash12>.js`,按白名单重建市场清单;
|
||||||
|
改版本时同步 `package.json` 的 `version` 与 `src/index.js` 里 manifest 的 `version`。
|
||||||
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
|
展示用的图标 / 描述在桌面仓 `plugins/meta.json` 里维护。
|
||||||
|
|
||||||
## 数据结构(上游 styles.json)
|
## 数据结构(上游 styles.json)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/style-source",
|
"name": "@iwb-plugin/style-source",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.3.2",
|
"version": "1.3.3",
|
||||||
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "style-source",
|
"id": "style-source",
|
||||||
|
|||||||
@@ -138,7 +138,7 @@
|
|||||||
position: fixed; z-index: 2147483000; left: 0; top: 0; pointer-events: none;
|
position: fixed; z-index: 2147483000; left: 0; top: 0; pointer-events: none;
|
||||||
padding: 5px 10px; border-radius: 6px; font-size: 12px; line-height: 1.2;
|
padding: 5px 10px; border-radius: 6px; font-size: 12px; line-height: 1.2;
|
||||||
font-family: inherit; white-space: nowrap;
|
font-family: inherit; white-space: nowrap;
|
||||||
background: rgba(22, 26, 34, .88); color: #fff;
|
background: color-mix(in srgb, var(--iwb-text, #1c2333) 88%, transparent); color: var(--iwb-on-brand, #fff);
|
||||||
border: 1px dashed rgba(255, 255, 255, .55);
|
border: 1px dashed rgba(255, 255, 255, .55);
|
||||||
transform: translate(-2px, -2px);
|
transform: translate(-2px, -2px);
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@
|
|||||||
position: absolute; left: 50%; bottom: 46px; z-index: 20;
|
position: absolute; left: 50%; bottom: 46px; z-index: 20;
|
||||||
transform: translateX(-50%) translateY(6px);
|
transform: translateX(-50%) translateY(6px);
|
||||||
max-width: 88%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
max-width: 88%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
background: rgba(22, 26, 34, .9); color: #fff;
|
background: color-mix(in srgb, var(--iwb-text, #1c2333) 90%, transparent); color: var(--iwb-on-brand, #fff);
|
||||||
font-size: var(--fs-md, 12px); padding: 6px 12px; border-radius: 14px;
|
font-size: var(--fs-md, 12px); padding: 6px 12px; border-radius: 14px;
|
||||||
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
|
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
|
||||||
}
|
}
|
||||||
@@ -338,7 +338,7 @@
|
|||||||
.iwb-ssn-row > input:focus { outline: none; border-color: var(--iwb-brand, #1677ff); }
|
.iwb-ssn-row > input:focus { outline: none; border-color: var(--iwb-brand, #1677ff); }
|
||||||
.iwb-ssn-row > input::placeholder { color: var(--iwb-text2, #6b7280); opacity: .6; }
|
.iwb-ssn-row > input::placeholder { color: var(--iwb-text2, #6b7280); opacity: .6; }
|
||||||
.iwb-ssn-foot { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--iwb-text2, #6b7280); }
|
.iwb-ssn-foot { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--iwb-text2, #6b7280); }
|
||||||
.iwb-ssn-warn { color: #d97706; }
|
.iwb-ssn-warn { color: var(--iwb-warn, #d97706); }
|
||||||
.iwb-ssn-empty { padding: 6px 2px; font-size: 11px; color: var(--iwb-text2, #6b7280); line-height: 1.6; }
|
.iwb-ssn-empty { padding: 6px 2px; font-size: 11px; color: var(--iwb-text2, #6b7280); line-height: 1.6; }
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -1384,7 +1384,7 @@
|
|||||||
global.IWBPluginHost.register({
|
global.IWBPluginHost.register({
|
||||||
id: 'style-source',
|
id: 'style-source',
|
||||||
name: '风格库',
|
name: '风格库',
|
||||||
version: '1.3.2',
|
version: '1.3.3',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
|
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
|
||||||
settings: {
|
settings: {
|
||||||
|
|||||||
+10
-12
@@ -83,29 +83,27 @@
|
|||||||
> 注意:默认值只对**没保存过设置**的环境生效;已存过 `ratioPct=85` 的旧记录会继续沿用 85,需要手动改成 80。
|
> 注意:默认值只对**没保存过设置**的环境生效;已存过 `ratioPct=85` 的旧记录会继续沿用 85,需要手动改成 80。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
本仓只产出 `src/index.js`(手写单文件 IIFE)。发布走桌面仓的市场链路,见根 README「发布到市场」:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /Users/qiqi/open/github/image-workbench-web
|
npm run validate
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/white-bg-800/src/index.js /tmp/plugin-white-bg-800.js
|
# 桌面仓:node scripts/sync-plugins-from-repo.js && node scripts/gen-market.js
|
||||||
# ⚠️ 必须把所有插件文件一起传入:发布器用「传入的文件」重建 plugins/index.json,不做合并。
|
# 再把 market/ 上传到 NAS(market.maqiart.eu.org)
|
||||||
# 只传自己 → 别的插件会从清单里消失(image-annotate 已实测踩到)。
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/xianyi-cutout/src/index.js /tmp/plugin-xianyi-cutout.js
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/image-annotate/src/index.js /tmp/plugin-image-annotate.js
|
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/blank-canvas/src/index.js /tmp/plugin-blank-canvas.js
|
|
||||||
node scripts/plugins-publish.mjs /tmp/plugin-white-bg-800.js /tmp/plugin-xianyi-cutout.js \
|
|
||||||
/tmp/plugin-image-annotate.js /tmp/plugin-blank-canvas.js \
|
|
||||||
--version white-bg-800=1.2.0 # 默认 dry-run,检查 diff 后再加 --upload
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
桌面仓的同步脚本按白名单**一次重建全部插件清单**(不用逐个传文件),改版本时同步
|
||||||
|
`package.json` 的 `version` 与 `src/index.js` 里 manifest 的 `version`。
|
||||||
|
|
||||||
## 验证(开发用)
|
## 验证(开发用)
|
||||||
- `tools/harness.mjs`:本地 mock 端到端 —— 合成宿主 + `addScriptTag` 加载插件源码本体,在真实 Chromium 里验证
|
- `tools/harness.mjs`:本地 mock 端到端 —— 合成宿主 + `addScriptTag` 加载插件源码本体,在真实 Chromium 里验证
|
||||||
manifest / 注册 / `appliesTo` / 白底与透明底 / `fitRect` 居中 / 夹取 / 命名 / 写回 / 错误提示,
|
manifest / 注册 / `appliesTo` / 白底与透明底 / `fitRect` 居中 / 夹取 / 命名 / 写回 / 错误提示,
|
||||||
以及**格式归一化、jpeg 体积、500KB 自动降质、PNG 超限报错、透明底+jpeg 防黑底、双版本双节点与部分成功**。需要 Playwright
|
以及**格式归一化、jpeg 体积、500KB 自动降质、PNG 超限报错、透明底+jpeg 防黑底、双版本双节点与部分成功**。需要 Playwright
|
||||||
(可从宿主仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定),不进 CI。
|
(可从桌面仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定),不进 CI。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node white-bg-800/tools/harness.mjs
|
node white-bg-800/tools/harness.mjs
|
||||||
```
|
```
|
||||||
- `tools/e2e-site.mjs`:带 CSP 的真实站点端到端(真 KV + SRI + 漂浮菜单 → 新建节点),透明底等设置类用例由 harness 覆盖。
|
- `tools/e2e-site.mjs`:真实桌面客户端的端到端(市场安装 + SRI + 漂浮菜单 → 新建节点),透明底等设置类用例由 harness 覆盖。
|
||||||
|
|
||||||
> harness 里的 mock `ctx.log` 必须是**函数**(真实宿主如此),早先写成对象导致凡是走 `ctx.log` 的分支全炸。
|
> harness 里的 mock `ctx.log` 必须是**函数**(真实宿主如此),早先写成对象导致凡是走 `ctx.log` 的分支全炸。
|
||||||
> 另外几何断言在有损格式下要留 ±4px 容差(jpeg 边缘振铃),精确几何用 `format=png` 的用例测。
|
> 另外几何断言在有损格式下要留 ±4px 容差(jpeg 边缘振铃),精确几何用 `format=png` 的用例测。
|
||||||
@@ -8,6 +8,8 @@ POST {apiUrl}/rmbg?crop=true|false # 默认 http://localhost:30092
|
|||||||
Content-Type: application/octet-stream # 原始图片字节;无 token、无 JSON
|
Content-Type: application/octet-stream # 原始图片字节;无 token、无 JSON
|
||||||
→ 返回原始 PNG 字节
|
→ 返回原始 PNG 字节
|
||||||
```
|
```
|
||||||
|
> 桌面宿主 CSP 的 `connect-src` 放行了 `127.0.0.1:30092` / `localhost:30092`,所以这个本机地址可用;
|
||||||
|
> 改到其它端口需改宿主 `src-tauri/tauri.conf.json` 的 CSP 并重新打包客户端。
|
||||||
比原扩展多做的:**补齐了超时**(`AbortController` + 可配 `timeoutMs`,原版没有任何超时)。
|
比原扩展多做的:**补齐了超时**(`AbortController` + 可配 `timeoutMs`,原版没有任何超时)。
|
||||||
|
|
||||||
## 入口
|
## 入口
|
||||||
@@ -17,14 +19,16 @@ Content-Type: application/octet-stream # 原始图片字节;无 token、无 JS
|
|||||||
## 设置
|
## 设置
|
||||||
| 键 | 说明 |
|
| 键 | 说明 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `apiUrl` | 本地服务地址。**CSP 仅放行 `127.0.0.1` / `localhost` 的 30092 端口** |
|
| `apiUrl` | 本地服务地址。**桌面宿主 CSP 仅放行 `127.0.0.1` / `localhost` 的 30092 端口** |
|
||||||
| `crop` | 抠图后裁掉多余透明像素(对应接口 `crop` 参数) |
|
| `crop` | 抠图后裁掉多余透明像素(对应接口 `crop` 参数) |
|
||||||
| `timeoutMs` | 超时毫秒(默认 120000) |
|
| `timeoutMs` | 超时毫秒(默认 120000) |
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
本仓只产出 `src/index.js`(手写单文件 IIFE)。发布走桌面仓的市场链路,见根 README「发布到市场」:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /Users/qiqi/open/github/image-workbench-web
|
npm run validate
|
||||||
# 两个发布器现在都会写 SRI integrity(.mjs 默认 dry-run,--upload 才写 KV)
|
# 桌面仓:同步 → 生市场 → 上传 market/ 到 NAS(market.maqiart.eu.org)
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/xianyi-cutout/src/index.js /tmp/plugin-xianyi-cutout.js
|
|
||||||
node scripts/plugins-publish.mjs /tmp/plugin-xianyi-cutout.js --upload --version xianyi-cutout=1.0.1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
改版本时同步 `package.json` 的 `version` 与 `src/index.js` manifest 的 `version`。
|
||||||
Reference in new issue
Block a user