Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1d4f90374 | ||
|
|
e20dda594b | ||
|
|
e614fca7a3 | ||
|
|
c1001ed61e | ||
|
|
2a484dac05 | ||
|
|
b48418c9ae | ||
|
|
a923834595 | ||
|
|
b00a59f4ba | ||
|
|
3eb8900b51 | ||
|
|
01253fceea | ||
|
|
dd294a75cd | ||
|
|
0ea25fcea2 | ||
|
|
d43b1520dc | ||
|
|
37c7c4b666 | ||
|
|
e97c9beb0d | ||
|
|
89841c4d4d | ||
|
|
99269aa0ae | ||
|
|
8f1f7ea7a7 | ||
|
|
48d86f3e0f | ||
|
|
4092eb5437 | ||
|
|
7c348e60c7 | ||
|
|
deac7513fd | ||
|
|
f0568342b1 | ||
|
|
b9c110709d | ||
|
|
c9bb3b09f3 | ||
|
|
4f4e64a989 | ||
|
|
9959096ab3 | ||
|
|
e7f8e68909 | ||
|
|
eb6880b11f | ||
|
|
ba9a4448e4 | ||
|
|
5ff3318fb9 | ||
|
|
8c6ed43078 | ||
|
|
9ed18827a8 | ||
|
|
352cac6031 | ||
|
|
2d2738f3a1 | ||
|
|
27a641903c | ||
|
|
89c2dca424 | ||
|
|
b8718d6810 | ||
|
|
17fd3be13b | ||
|
|
e7d54cb0a8 | ||
|
|
1aba7a0c94 | ||
|
|
4fc4e469c2 |
No files matched your search
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@iwb-plugin/album",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.1.2",
|
||||||
|
"description": "相册:一个节点装多张本地图(只引用不复制),宫格自适应分页,一图一任务 / 批量两种模式批量生图",
|
||||||
|
"ibwPlugin": {
|
||||||
|
"id": "album",
|
||||||
|
"entry": "src/index.js",
|
||||||
|
"apiVersion": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,849 @@
|
|||||||
|
// 相册节点(2026-11-26,iwb-plugin: album)
|
||||||
|
//
|
||||||
|
// 一件事:把「多个图片节点」收成一个节点——宫格装 N 张本地图,接提示词/组合做批量生图。
|
||||||
|
//
|
||||||
|
// 三条关键设计(都对宿主有依赖,别在插件里重造):
|
||||||
|
// ① 只引用不复制:item.src = { __file: '/abs/a.png' };宿主生成时才读盘(ctx.images.reference / dataUrl)
|
||||||
|
// ② 任务展开由宿主任务图做:data.outKind='images' + data.items,宿主按 albumMode 展开成 N 个任务
|
||||||
|
// (一图一任务)或分批(批量,每组 ≤12 张);本插件只负责「数据 + 界面」
|
||||||
|
// ③ 分页容量随节点尺寸实时算:拖大 = 一页装更多(装得下就隐藏分页条),缩小 = 自动多页;
|
||||||
|
// 只有 data.onlyPage 打开时才把可见区间写进 data.pageRange 交给宿主过滤
|
||||||
|
;(function (global) {
|
||||||
|
'use strict'
|
||||||
|
if (!global.IWBPluginHost) return
|
||||||
|
|
||||||
|
// 密度档位 = 目标单元格边长(px)。1.1.0 修正:旧值 {S:64, M:48, L:100} 里 M 比 S 还小,
|
||||||
|
// 于是「中格」每页装 30 张(比小格的 20 张还多),档位语义是反的。现在 S < M < L 严格递增。
|
||||||
|
const DENSITY = { S: 64, M: 80, L: 104 }
|
||||||
|
// ⚠ 下面这一组必须与 styles.css 逐个对齐(换了 box-sizing / padding 就会算错容量 ⇒ 最后一行被裁)。
|
||||||
|
// 宿主全局 * { box-sizing: border-box },所以 CSS 里写的 height 已含 padding。
|
||||||
|
const GAP = 4 // .iwb-album-grid 的 gap = --iwb-space-4
|
||||||
|
const PAD_X = 16 // 宫格左右 padding 合计(.iwb-album-grid 左右各 --iwb-space-8)
|
||||||
|
const PAD_Y = 8 // 上下 padding 合计(.iwb-album-grid 2px + 6px)
|
||||||
|
const BAR_H = 26 // 状态栏
|
||||||
|
const TOOLS_H = 25 // 工具条(padding 2+2 + 按钮 21)
|
||||||
|
const PAGER_H = 26 // 分页条 / 一页提示条
|
||||||
|
const HINT_H = 28 // 批量模式提示行(含 margin-bottom 4)
|
||||||
|
const DEFAULT_H = 470 // 注册时声明的默认高度(与 height 字段保持一致)
|
||||||
|
const THUMB_EDGE = 256
|
||||||
|
const THUMB_Q = 0.8
|
||||||
|
const IMG_EXT = ['png', 'jpg', 'jpeg', 'webp', 'gif', 'avif', 'bmp', 'svg']
|
||||||
|
|
||||||
|
const STATE = new WeakMap() // host 元素 → 渲染状态(一个容器一个实例)
|
||||||
|
|
||||||
|
// ── 小工具 ──────────────────────────────────────────────
|
||||||
|
function el (tag, attrs, kids) {
|
||||||
|
const node = document.createElement(tag)
|
||||||
|
if (attrs) for (const k in attrs) {
|
||||||
|
const v = attrs[k]
|
||||||
|
if (v === null || v === undefined || v === false) continue
|
||||||
|
if (k === 'className') node.className = v
|
||||||
|
else if (k === 'text') node.textContent = v
|
||||||
|
else if (k === 'style' && typeof v === 'object') Object.assign(node.style, v)
|
||||||
|
else if (k.slice(0, 2) === 'on' && typeof v === 'function') node.addEventListener(k.slice(2).toLowerCase(), v)
|
||||||
|
else node.setAttribute(k, v === true ? '' : String(v))
|
||||||
|
}
|
||||||
|
for (const kid of (Array.isArray(kids) ? kids : (kids ? [kids] : []))) {
|
||||||
|
if (kid === null || kid === undefined || kid === false) continue
|
||||||
|
node.appendChild(typeof kid === 'string' ? document.createTextNode(kid) : kid)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
// 可点击元素:宿主在节点体上的 pointerdown 会启动「拖动节点」,单击事件因此被吞。
|
||||||
|
// 所有可点击的非 input/button 元素都必须挡住 pointerdown(与 ui-node-bodies 里 stop 的用法一致)。
|
||||||
|
function onTap (el0, fn) {
|
||||||
|
el0.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
el0.addEventListener('click', (e) => { e.stopPropagation(); fn(e) })
|
||||||
|
return el0
|
||||||
|
}
|
||||||
|
function hash32 (s) {
|
||||||
|
let h = 0x811c9dc5
|
||||||
|
const str = String(s || '')
|
||||||
|
for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = (h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24))) >>> 0 }
|
||||||
|
return ('00000000' + h.toString(16)).slice(-8)
|
||||||
|
}
|
||||||
|
const extOf = (p) => { const m = /\.([a-z0-9]{1,5})$/i.exec(String(p || '')); return m ? m[1].toLowerCase() : '' }
|
||||||
|
const isImagePath = (p) => IMG_EXT.indexOf(extOf(p)) >= 0
|
||||||
|
const fileRefOf = (src) => (src && typeof src === 'object' && typeof src.__file === 'string') ? src.__file : ''
|
||||||
|
const nameOf = (p) => String(p || '').replace(/^.*[\\/]/, '')
|
||||||
|
const str = (v) => (v == null ? '' : String(v))
|
||||||
|
|
||||||
|
// ── 缩略图(插件私有缓存,几十 KB/张,不碰画布存储)────────────
|
||||||
|
const thumbNameOf = (key) => 't-' + hash32(key) + '.jpg'
|
||||||
|
|
||||||
|
// 缩略图缓存键(1.1.0 修「串味」):旧实现是 `fileRefOf(src) || it.name`,一旦固化(src 变成
|
||||||
|
// {__blob})或从别处导入,路径就没了 ⇒ 键退化成纯文件名 ⇒ 不同目录下的 1.png 共用同一张缩略图。
|
||||||
|
// 现在按引用本身取键:路径 → 路径;blob/cache → 各自 id;dataURL → 内容哈希;只有都没有才退回文件名。
|
||||||
|
function thumbKeyOf (it) {
|
||||||
|
const src = (it && it.src) != null ? it.src : it
|
||||||
|
const path = fileRefOf(src)
|
||||||
|
if (path) return 'f:' + path
|
||||||
|
if (src && typeof src === 'object') {
|
||||||
|
if (typeof src.__blob === 'string' && src.__blob) return 'b:' + src.__blob
|
||||||
|
if (typeof src.__cache === 'string' && src.__cache) return 'c:' + src.__cache
|
||||||
|
}
|
||||||
|
if (typeof src === 'string' && src) {
|
||||||
|
if (src.length > 4096) return 'd:' + hash32(src.slice(0, 2048) + src.slice(-2048) + ':' + src.length)
|
||||||
|
return 'd:' + hash32(src)
|
||||||
|
}
|
||||||
|
const n = (it && (it.name || it.size)) || ''
|
||||||
|
return 'n:' + str(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeThumb (dataUrl) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
try {
|
||||||
|
const img = new Image()
|
||||||
|
img.onload = () => {
|
||||||
|
try {
|
||||||
|
const scale = Math.min(1, THUMB_EDGE / Math.max(img.naturalWidth || 1, img.naturalHeight || 1))
|
||||||
|
const w = Math.max(1, Math.round((img.naturalWidth || 1) * scale))
|
||||||
|
const h = Math.max(1, Math.round((img.naturalHeight || 1) * scale))
|
||||||
|
const cv = document.createElement('canvas')
|
||||||
|
cv.width = w; cv.height = h
|
||||||
|
const c2 = cv.getContext('2d')
|
||||||
|
c2.drawImage(img, 0, 0, w, h)
|
||||||
|
resolve(cv.toDataURL('image/jpeg', THUMB_Q))
|
||||||
|
} catch (e) { resolve('') }
|
||||||
|
}
|
||||||
|
img.onerror = () => resolve('')
|
||||||
|
img.src = dataUrl
|
||||||
|
} catch (e) { resolve('') }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 容量:随节点宽高实时算(放大 = 一页装更多)────────────────
|
||||||
|
function capacityOf (width, height, density, hasHint) {
|
||||||
|
const target = DENSITY[density] || DENSITY.S
|
||||||
|
const innerW = Math.max(0, width - 4 - PAD_X)
|
||||||
|
const innerH = Math.max(0, height - 4 - BAR_H - TOOLS_H - PAGER_H - (hasHint ? HINT_H : 0) - PAD_Y)
|
||||||
|
const cols = Math.max(1, Math.floor((innerW + GAP) / (target + GAP)))
|
||||||
|
const cell = Math.floor((innerW - (cols - 1) * GAP) / cols) || target
|
||||||
|
const rows = Math.max(1, Math.floor((innerH + GAP) / (cell + GAP)))
|
||||||
|
return { cols, rows, cell: Math.max(20, cell), capacity: Math.max(1, cols * rows) }
|
||||||
|
}
|
||||||
|
|
||||||
|
function measure (host) {
|
||||||
|
const rect = host.getBoundingClientRect()
|
||||||
|
return { width: Math.round(rect.width || 0), height: Math.round(rect.height || 0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 数据读写 ────────────────────────────────────────────
|
||||||
|
function itemsOf (node) {
|
||||||
|
const d = (node && node.data) || {}
|
||||||
|
return Array.isArray(d.items) ? d.items : []
|
||||||
|
}
|
||||||
|
function update (props, node, patch, snapshot) {
|
||||||
|
try { if (snapshot && typeof props.onSnapshot === 'function') props.onSnapshot() } catch (e) { /* 撤销快照失败不影响写入 */ }
|
||||||
|
try { props.onUpdate(node.id, patch) } catch (e) { /* 宿主不可写时保持只读 */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 外壳 ────────────────────────────────────────────────
|
||||||
|
function buildShell (ctx, node, props, host) {
|
||||||
|
const st = {
|
||||||
|
nodeId: node.id,
|
||||||
|
thumbs: new Map(), // key → dataURL(内存缓存)
|
||||||
|
pending: new Map(), // key → Promise(并发去重:格子挂载和预生成会同时要同一张)
|
||||||
|
missing: new Set(), // 失联文件的 key
|
||||||
|
busy: '',
|
||||||
|
checkedMissing: false,
|
||||||
|
sig: '',
|
||||||
|
cap: null, // 最近一次容量计算(拖拽排序换算页码要用)
|
||||||
|
}
|
||||||
|
const bar = el('div', { className: 'iwb-album-bar' })
|
||||||
|
const track = el('span', { className: 'iwb-album-track' }, el('i', null))
|
||||||
|
const modeLabel = el('label', { className: 'iwb-album-toggle' }, track, document.createTextNode('一图一任务'))
|
||||||
|
modeLabel.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
modeLabel.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
// ⚠ 必须读 st.node(每次 sync 更新),不能读 buildShell 捕获的 node ——
|
||||||
|
// 那是**挂载时**的旧数据,连点两次会一直算出同一个 next(实测:永远停在批量)。
|
||||||
|
const cur = st.node || node
|
||||||
|
const d = (cur && cur.data) || {}
|
||||||
|
const next = d.albumMode === 'batch' ? 'per-image' : 'batch'
|
||||||
|
update(st.props || props, cur, { albumMode: next })
|
||||||
|
})
|
||||||
|
const count = el('span', { className: 'iwb-album-count' })
|
||||||
|
// 一键清空(2026-11-26 用户需求):只清本节点持有的 items,删源文件与画布存储一概不碰。
|
||||||
|
// 走 snapshot:true ⇒ ⌘Z 能整批恢复,所以不加二次确认弹窗(多一步点击反而更烦)。
|
||||||
|
const btnClear = el('button', { className: 'iwb-album-btn iwb-album-clear', title: '清空相册(⌘Z 可撤销;不会删除磁盘上的原文件)' }, '清空')
|
||||||
|
bar.appendChild(modeLabel); bar.appendChild(count); bar.appendChild(btnClear)
|
||||||
|
|
||||||
|
const btnAdd = el('button', { className: 'iwb-album-btn', title: '选择本地图片(桌面端只引用,不复制字节)' }, '+ 添加图片')
|
||||||
|
const btnDir = el('button', { className: 'iwb-album-btn', title: '按文件夹批量添加' }, '文件夹')
|
||||||
|
const btnSettle = el('button', { className: 'iwb-album-btn', title: '把引用复制进画布存储(删源文件/分享画布前用)' }, '固化')
|
||||||
|
const seg = el('span', { className: 'iwb-album-seg' })
|
||||||
|
const segs = {}
|
||||||
|
for (const key of ['S', 'M', 'L']) {
|
||||||
|
const s = onTap(el('span', { title: key === 'S' ? '小格(默认)' : (key === 'M' ? '中格' : '大格') }, key), () => update(st.props || props, st.node || node, { density: key }))
|
||||||
|
segs[key] = s; seg.appendChild(s)
|
||||||
|
}
|
||||||
|
const tools = el('div', { className: 'iwb-album-tools' }, [btnAdd, btnDir, btnSettle, seg])
|
||||||
|
|
||||||
|
const hint = el('div', { className: 'iwb-album-hint' })
|
||||||
|
const grid = el('div', { className: 'iwb-album-grid' })
|
||||||
|
const empty = el('div', { className: 'iwb-album-empty' }, [
|
||||||
|
el('div', { className: 'box' }, '+'),
|
||||||
|
el('div', null, '把图片拖到这里,或点「添加图片」选本地文件'),
|
||||||
|
el('div', { style: { fontSize: '10px', opacity: '.85' } }, '支持 PNG / JPG / WebP / GIF / AVIF / SVG'),
|
||||||
|
])
|
||||||
|
const pager = el('div', { className: 'iwb-album-pager' })
|
||||||
|
const onepage = el('div', { className: 'iwb-album-onepage' }, '全部图片一页展示')
|
||||||
|
// 节点内 hover 预览层已于 1.1.1 移除(用户实测:鼠标移到放大镜上时预览层盖住图标,反而点不到)。
|
||||||
|
// 现在只看大图走「点击放大镜 → 宿主全屏预览(props.onPreview)」,点图片外或 Esc 自动退出。
|
||||||
|
|
||||||
|
host.textContent = ''
|
||||||
|
const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage])
|
||||||
|
host.appendChild(root)
|
||||||
|
Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint })
|
||||||
|
|
||||||
|
// 按钮绑定(用闭包里的当前 node/props:每次 sync 会更新 st.node/st.props)
|
||||||
|
btnAdd.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btnAdd.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, host, false) })
|
||||||
|
btnDir.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btnDir.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, host, true) })
|
||||||
|
btnSettle.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btnSettle.addEventListener('click', (e) => { e.stopPropagation(); settleAll(ctx, st) })
|
||||||
|
btnClear.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btnClear.addEventListener('click', (e) => { e.stopPropagation(); clearAll(ctx, st) })
|
||||||
|
|
||||||
|
// 拖拽入图:桌面端拿不到绝对路径 ⇒ 按「方案 1」复制进画布存储
|
||||||
|
host.addEventListener('dragover', (e) => { e.preventDefault(); e.stopPropagation() })
|
||||||
|
host.addEventListener('drop', (e) => {
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
const files = Array.from((e.dataTransfer && e.dataTransfer.files) || [])
|
||||||
|
if (files.length) importDropped(ctx, st, files)
|
||||||
|
})
|
||||||
|
return st
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 同步(宿主每次重渲染都会调用;必须可增量)──────────────────
|
||||||
|
function sync (ctx, st, node, props) {
|
||||||
|
st.node = node; st.props = props
|
||||||
|
const d = (node && node.data) || {}
|
||||||
|
const items = itemsOf(node)
|
||||||
|
const density = DENSITY[d.density] ? d.density : 'S'
|
||||||
|
const mode = d.albumMode === 'batch' ? 'batch' : 'per-image'
|
||||||
|
// 尺寸来源:**只认显式 node.h 或变体默认高度**(2026-11-26 修"插入后慢慢变矮")。
|
||||||
|
// ⚠ 绝不能用 props.measuredH / 自身 getBoundingClientRect():插件节点体是内容撑开的,
|
||||||
|
// 我们按它写回高度 ⇒ 卡片变矮 ⇒ 下次量到更矮 ⇒ 一路缩水。
|
||||||
|
// 拖拽调整尺寸时宿主会把新高度写进 node.h,那才是权威值。
|
||||||
|
const measured = measure(st.root)
|
||||||
|
const cardW = Number(node.w) || measured.width || 300
|
||||||
|
const cardH = Number(node.h) || DEFAULT_H
|
||||||
|
const wantH = Math.max(120, Math.round(cardH) - 4) + 'px'
|
||||||
|
if (st.root.style.height !== wantH) st.root.style.height = wantH
|
||||||
|
const cap = capacityOf(cardW, cardH, density, mode === 'batch')
|
||||||
|
st.cap = cap // 拖拽排序换算「本页第 i 格 → 全局第几格」要用(旧代码用格子数,把「+添加」也算进去了)
|
||||||
|
const pages = Math.max(1, Math.ceil(items.length / cap.capacity))
|
||||||
|
const page = Math.max(0, Math.min(pages - 1, Number(d.page) || 0))
|
||||||
|
const from = page * cap.capacity
|
||||||
|
const to = Math.min(items.length, from + cap.capacity)
|
||||||
|
const selected = items.filter((it) => it && it.on !== false).length
|
||||||
|
|
||||||
|
// 一图一任务开关 / 计数 / 密度高亮 / 固化可用性
|
||||||
|
st.track.className = 'iwb-album-track' + (mode === 'per-image' ? ' on' : '')
|
||||||
|
st.count.innerHTML = ''
|
||||||
|
st.count.appendChild(document.createTextNode('已选 '))
|
||||||
|
st.count.appendChild(el('b', null, String(selected)))
|
||||||
|
st.count.appendChild(document.createTextNode('/' + items.length + ' · 每页 ' + cap.capacity))
|
||||||
|
for (const k in st.segs) st.segs[k].className = (density === k ? 'on' : '')
|
||||||
|
const hasFileRef = items.some((it) => fileRefOf(it && it.src))
|
||||||
|
st.btnSettle.style.display = hasFileRef ? '' : 'none'
|
||||||
|
// 「文件夹」只在能做路径引用的宿主里有意义(桌面端)。旧写法 `canReference() || true` 恒真,
|
||||||
|
// 于是在不支持路径引用的宿主里点它永远没反应(这类宿主仍可用「+ 添加图片」走文件选择器)。
|
||||||
|
const canRef = !!(ctx.images && typeof ctx.images.canReference === 'function' && ctx.images.canReference())
|
||||||
|
st.btnDir.style.display = canRef ? '' : 'none'
|
||||||
|
st.btnClear.style.display = items.length ? '' : 'none'
|
||||||
|
if (st.busy) { st.btnAdd.textContent = st.busy } else { st.btnAdd.textContent = '+ 添加图片' }
|
||||||
|
|
||||||
|
// 批量模式提示:N 张 → M 个任务(每组 ≤ 12)
|
||||||
|
if (mode === 'batch' && items.length) {
|
||||||
|
st.hint.style.display = ''
|
||||||
|
st.hint.innerHTML = ''
|
||||||
|
st.hint.appendChild(document.createTextNode('整本一次请求:'))
|
||||||
|
st.hint.appendChild(el('b', null, items.length + ' 张 → ' + Math.ceil(items.length / 12) + ' 个任务'))
|
||||||
|
st.hint.appendChild(document.createTextNode('(每组 ≤ 12 张)'))
|
||||||
|
} else st.hint.style.display = 'none'
|
||||||
|
|
||||||
|
// 分页条 / 一页展示
|
||||||
|
// 空节点不再显示「全部 0 张一页展示」那条灰条(2026-11-26):它压着空态提示,说的还是废话。
|
||||||
|
const showPager = pages > 1
|
||||||
|
const showOne = !showPager && items.length > 0
|
||||||
|
st.pager.style.display = showPager ? '' : 'none'
|
||||||
|
st.onepage.style.display = showOne ? '' : 'none'
|
||||||
|
if (showOne) st.onepage.textContent = '全部 ' + items.length + ' 张一页展示 · 无需翻页'
|
||||||
|
if (showPager) {
|
||||||
|
st.pager.innerHTML = ''
|
||||||
|
const pg = el('span', { className: 'iwb-album-pg' })
|
||||||
|
const prev = onTap(el('span', { title: '上一页' }, '‹'), () => { if (page > 0) update(st.props, st.node, { page: page - 1 }) })
|
||||||
|
const next = onTap(el('span', { title: '下一页' }, '›'), () => { if (page < pages - 1) update(st.props, st.node, { page: page + 1 }) })
|
||||||
|
pg.appendChild(prev); pg.appendChild(el('b', null, (page + 1) + '/' + pages)); pg.appendChild(next)
|
||||||
|
st.pager.appendChild(pg)
|
||||||
|
const only = el('label', { className: 'iwb-album-mini' }, [
|
||||||
|
el('span', { className: 'iwb-album-track' + (d.onlyPage === true ? ' on' : '') }, el('i', null)),
|
||||||
|
document.createTextNode('仅本页参与'),
|
||||||
|
])
|
||||||
|
only.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
only.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
update(st.props, st.node, { onlyPage: !(d.onlyPage === true) })
|
||||||
|
})
|
||||||
|
st.pager.appendChild(only)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仅本页参与:把可见区间写回 data.pageRange(宿主任务图据此过滤;关闭时清掉)
|
||||||
|
const wantRange = (d.onlyPage === true) ? [from, to] : null
|
||||||
|
const curRange = Array.isArray(d.pageRange) ? d.pageRange : null
|
||||||
|
const rangeChanged = (!!wantRange !== !!curRange) || (wantRange && curRange && (wantRange[0] !== curRange[0] || wantRange[1] !== curRange[1]))
|
||||||
|
if (rangeChanged || (Number(d.page) || 0) !== page) {
|
||||||
|
update(st.props, st.node, { page: page, pageRange: wantRange })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 宫格(签名不变就不重建:避免每帧重排导致闪烁/丢拖拽态)
|
||||||
|
const sig = [node.id, density, page, cap.capacity, mode, items.length, d.onlyPage === true ? 1 : 0,
|
||||||
|
items.map((it) => thumbKeyOf(it) + (it && it.on === false ? ':0' : ':1')).join(','), Array.from(st.missing).join(',')].join('|')
|
||||||
|
if (sig !== st.sig) {
|
||||||
|
st.sig = sig
|
||||||
|
st.grid.innerHTML = ''
|
||||||
|
st.grid.style.gridTemplateColumns = 'repeat(' + cap.cols + ', 1fr)'
|
||||||
|
if (!items.length) {
|
||||||
|
st.grid.style.display = 'none'; st.empty.style.display = ''
|
||||||
|
} else {
|
||||||
|
st.grid.style.display = ''; st.empty.style.display = 'none'
|
||||||
|
for (let i = from; i < to; i++) st.grid.appendChild(cellOf(ctx, st, items[i], i, mode))
|
||||||
|
if (to - from < cap.capacity) {
|
||||||
|
const add = el('button', { className: 'iwb-album-cell iwb-album-add', title: '添加图片' }, [el('b', null, '+'), el('span', null, '添加')])
|
||||||
|
add.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, st.root, false) })
|
||||||
|
st.grid.appendChild(add)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
st.grid.style.gridTemplateColumns = 'repeat(' + cap.cols + ', 1fr)'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 失联检测(每个节点一次;文件被移动/删除时给出明确提示)
|
||||||
|
if (!st.checkedMissing && items.some((it) => fileRefOf(it && it.src))) {
|
||||||
|
st.checkedMissing = true
|
||||||
|
checkMissing(ctx, st, items).then((changed) => { if (changed) { st.sig = ''; try { sync(ctx, st, st.node, st.props) } catch (e) { /* ignore */ } } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 单元格 ──────────────────────────────────────────────
|
||||||
|
// 放大镜图标(内联 SVG,CSP 禁外部资源):圆 + 手柄,10px 下仍看得清
|
||||||
|
function zoomIcon () {
|
||||||
|
const NS = 'http://www.w3.org/2000/svg'
|
||||||
|
const mk = (tag, attrs) => {
|
||||||
|
const n = document.createElementNS(NS, tag)
|
||||||
|
for (const k in attrs) n.setAttribute(k, attrs[k])
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
const svg = mk('svg', { viewBox: '0 0 24 24', 'aria-hidden': 'true' })
|
||||||
|
svg.appendChild(mk('circle', { cx: 10, cy: 10, r: 7, fill: 'none', stroke: 'currentColor', 'stroke-width': 2.4 }))
|
||||||
|
svg.appendChild(mk('path', { d: 'M15.2 15.2 21 21', fill: 'none', stroke: 'currentColor', 'stroke-width': 2.4, 'stroke-linecap': 'round' }))
|
||||||
|
return svg
|
||||||
|
}
|
||||||
|
function cellOf (ctx, st, it, index, mode) {
|
||||||
|
const src = it && it.src
|
||||||
|
const path = fileRefOf(src)
|
||||||
|
const key = thumbKeyOf(it)
|
||||||
|
const on = !(it && it.on === false)
|
||||||
|
const missing = path && st.missing.has(path)
|
||||||
|
const btn = el('button', {
|
||||||
|
className: 'iwb-album-cell' + (on ? ' sel' : ' off') + (missing ? ' missing' : ''),
|
||||||
|
title: (it && it.name ? it.name : ('图 ' + (index + 1))) + (missing ? '(文件已不在原位置:点一下重新定位)' : ''),
|
||||||
|
})
|
||||||
|
const img = el('img', { alt: '', draggable: 'false' })
|
||||||
|
const cached = st.thumbs.get(key)
|
||||||
|
if (cached) img.src = cached
|
||||||
|
// 不设 img.src = '':空字符串会向页面 URL 发一次请求(控制台 ERR_UNKNOWN_URL_SCHEME)。
|
||||||
|
// 不设 src 属性时 <img> 什么都不做,缩略图到了再赋上即可。
|
||||||
|
else loadThumb(ctx, st, it, key).then((url) => { if (url && img.isConnected !== false) img.src = url })
|
||||||
|
btn.appendChild(img)
|
||||||
|
btn.appendChild(el('span', { className: 'iwb-album-idx' }, String(index + 1)))
|
||||||
|
// 批次角标(右上角那个「1」)已删除:顶栏「N 张 → M 个任务」已经说清楚,角标是重复信息,
|
||||||
|
// 还会和删除按钮抢同一个角。位置让给了 ×。
|
||||||
|
const del = el('span', { className: 'iwb-album-del', title: '移除(不删除磁盘上的原文件)' }, '×')
|
||||||
|
del.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
del.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
items.splice(index, 1)
|
||||||
|
// 删除后留在当前页(旧实现硬编码 page:0,第 2 页删一张直接跳回第 1 页)。
|
||||||
|
// 只做「页数变少时往回收」,正常情况 page 不动。
|
||||||
|
const capNow = st.cap || { capacity: 20 }
|
||||||
|
const pagesNow = Math.max(1, Math.ceil(items.length / capNow.capacity))
|
||||||
|
const pageNow = Math.max(0, Number((st.node.data || {}).page) || 0)
|
||||||
|
update(st.props, st.node, { items: items, page: Math.min(pageNow, pagesNow - 1) }, true)
|
||||||
|
})
|
||||||
|
btn.appendChild(del)
|
||||||
|
// 放大镜(右下角):点开插件自带的全屏查看器,可 ← → 切换整本相册(1.1.2)。
|
||||||
|
// 1.1.1 的 hover 预览已废(那层会盖住放大镜本身)。
|
||||||
|
const zoom = el('span', { className: 'iwb-album-zoom', title: '查看大图(← → 切换,点击空白处或 Esc 关闭)' }, zoomIcon())
|
||||||
|
zoom.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
zoom.addEventListener('click', (e) => { e.stopPropagation(); openFull(ctx, st, index) })
|
||||||
|
btn.appendChild(zoom)
|
||||||
|
btn.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btn.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (missing) { relocate(ctx, st, index); return }
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
if (!items[index]) return
|
||||||
|
items[index] = Object.assign({}, items[index], { on: !on })
|
||||||
|
update(st.props, st.node, { items })
|
||||||
|
})
|
||||||
|
// 拖拽排序
|
||||||
|
btn.addEventListener('pointerdown', (e) => {
|
||||||
|
if (e.button !== 0) return
|
||||||
|
const startX = e.clientX, startY = e.clientY
|
||||||
|
let moved = false
|
||||||
|
const target = { index: index }
|
||||||
|
const onMove = (ev) => {
|
||||||
|
const dx = ev.clientX - startX, dy = ev.clientY - startY
|
||||||
|
if (!moved && Math.abs(dx) + Math.abs(dy) < 5) return
|
||||||
|
moved = true
|
||||||
|
btn.classList.add('dragging')
|
||||||
|
const cells = Array.from(st.grid.querySelectorAll('.iwb-album-cell'))
|
||||||
|
let hit = cells.length - 1
|
||||||
|
for (let i = 0; i < cells.length; i++) {
|
||||||
|
const r = cells[i].getBoundingClientRect()
|
||||||
|
if (ev.clientX < r.left + r.width / 2 + (r.width * 0.1) && ev.clientY < r.bottom && ev.clientX > r.left - r.width) { hit = i; break }
|
||||||
|
}
|
||||||
|
cells.forEach((c, i) => c.classList.toggle('dropbefore', i === hit))
|
||||||
|
target.index = hit
|
||||||
|
}
|
||||||
|
const onUp = () => {
|
||||||
|
document.removeEventListener('pointermove', onMove)
|
||||||
|
document.removeEventListener('pointerup', onUp)
|
||||||
|
btn.classList.remove('dragging')
|
||||||
|
Array.from(st.grid.querySelectorAll('.dropbefore')).forEach((c) => c.classList.remove('dropbefore'))
|
||||||
|
if (!moved) return
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
// 1.1.0 修跨页错位:本页起点 = page × **每页容量**(旧代码乘的是「本页格子数」,而格子数里
|
||||||
|
// 还含末尾那个「+添加」格 ⇒ 第 2 页永远算少一格,把 21 号拖到第 2 位会插到全局第 13 位)。
|
||||||
|
const capNow = st.cap || { capacity: 20 }
|
||||||
|
const pageNow = Math.max(0, Number((st.node.data || {}).page) || 0)
|
||||||
|
const pageStart = pageNow * capNow.capacity
|
||||||
|
const realCount = Math.min(capNow.capacity, Math.max(0, items.length - pageStart))
|
||||||
|
const srcIndex = index
|
||||||
|
let dest = pageStart + Math.min(target.index, realCount)
|
||||||
|
if (dest === srcIndex || dest < 0) return
|
||||||
|
const [movedItem] = items.splice(srcIndex, 1)
|
||||||
|
if (dest > srcIndex) dest -= 1
|
||||||
|
items.splice(Math.max(0, Math.min(items.length, dest)), 0, movedItem)
|
||||||
|
update(st.props, st.node, { items: items }, true)
|
||||||
|
}
|
||||||
|
document.addEventListener('pointermove', onMove)
|
||||||
|
document.addEventListener('pointerup', onUp)
|
||||||
|
})
|
||||||
|
return btn
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 缩略图取用:内存 → 插件文件 → 现做 ───────────────────
|
||||||
|
// 并发去重(1.1.0):格子一挂载就各自要缩略图,而 addPaths 又顺序预热一遍 ⇒ 同一张图会被读两次盘。
|
||||||
|
// 用 pending 表把同 key 的请求合成一个 Promise(否则导入 30 张会解 60 次原图,内存直接翻倍)。
|
||||||
|
async function loadThumb (ctx, st, it, key) {
|
||||||
|
if (st.thumbs.has(key)) return st.thumbs.get(key)
|
||||||
|
const flight = st.pending && st.pending.get(key)
|
||||||
|
if (flight) return flight
|
||||||
|
const p = loadThumbInner(ctx, st, it, key).finally(() => { if (st.pending) st.pending.delete(key) })
|
||||||
|
if (st.pending) st.pending.set(key, p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
async function loadThumbInner (ctx, st, it, key) {
|
||||||
|
if (st.thumbs.has(key)) return st.thumbs.get(key)
|
||||||
|
const name = thumbNameOf(key)
|
||||||
|
try {
|
||||||
|
if (ctx.files) {
|
||||||
|
const got = await ctx.files.get(name)
|
||||||
|
if (got && got.ok && got.url) { st.thumbs.set(key, got.url); return got.url }
|
||||||
|
}
|
||||||
|
} catch (e) { /* 没缓存就现做 */ }
|
||||||
|
let dataUrl = ''
|
||||||
|
const src = it && it.src
|
||||||
|
try {
|
||||||
|
if (fileRefOf(src)) dataUrl = await ctx.images.dataUrl(src)
|
||||||
|
else if (typeof src === 'string') dataUrl = src
|
||||||
|
else dataUrl = await ctx.images.dataUrl(src)
|
||||||
|
} catch (e) { dataUrl = '' }
|
||||||
|
if (!dataUrl) return ''
|
||||||
|
const thumb = await makeThumb(dataUrl)
|
||||||
|
if (!thumb) return ''
|
||||||
|
st.thumbs.set(key, thumb)
|
||||||
|
// 内存里已经有一张就够本会话用了;写盘失败(配额满)不影响显示
|
||||||
|
try { if (ctx.files) await ctx.files.put(name, thumb) } catch (e) { /* ignore */ }
|
||||||
|
return thumb
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 看大图:插件自带全屏查看器(1.1.2 起支持 ← → 切换)──────────
|
||||||
|
// 历史:1.1.0 做过「hover 节点内浮大图 + 点击全屏」两套,hover 层把放大镜盖住了 ⇒ 1.1.1 删掉。
|
||||||
|
// 1.1.2:宿主 props.onPreview 只收「已解析好的 URL 列表」,一本 30 张的相册要左右切换,
|
||||||
|
// 就得开窗前把 30 张原图全转成 dataURL(几十上百 MB,还可能卡住主线程)。所以改成自建查看器:
|
||||||
|
// 只解码当前这张 + 预取左右各一张(最多 3 张常驻),切换即时、内存可控。
|
||||||
|
// 交互沿用宿主那套肌肉记忆:点图片外的空白 / Esc 退出,← → 切换,滚轮也切。
|
||||||
|
const FS_KEEP = 3 // 同时保留的原图张数(当前 + 左右各一)
|
||||||
|
|
||||||
|
function closeViewer (st) {
|
||||||
|
const v = st && st.viewer
|
||||||
|
if (!v) return
|
||||||
|
st.viewer = null
|
||||||
|
try { window.removeEventListener('keydown', v.onKey, true) } catch (e) { /* ignore */ }
|
||||||
|
try { window.removeEventListener('wheel', v.onWheel, true) } catch (e) { /* ignore */ }
|
||||||
|
if (v.root && v.root.parentNode) v.root.parentNode.removeChild(v.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
function openFull (ctx, st, index) {
|
||||||
|
closeViewer(st)
|
||||||
|
const items = itemsOf(st.node)
|
||||||
|
const total = items.length
|
||||||
|
if (!total) return
|
||||||
|
const pick = (i) => items[((i % total) + total) % total]
|
||||||
|
const keyAt = (i) => thumbKeyOf(pick(i))
|
||||||
|
let cur = Math.max(0, Math.min(total - 1, Number(index) || 0))
|
||||||
|
let curUrl = '' // 当前显示图的地址(复制/下载用)
|
||||||
|
let token = 0
|
||||||
|
const cache = new Map() // key → 原图 URL
|
||||||
|
const pending = new Map() // key → Promise(预取与切页会同时要同一张)
|
||||||
|
|
||||||
|
const img = el('img', { alt: '', draggable: 'false' })
|
||||||
|
const count = el('span', { className: 'iwb-album-fs-count' })
|
||||||
|
const name = el('span', { className: 'iwb-album-fs-name' })
|
||||||
|
const btnCopy = el('button', { className: 'iwb-album-fs-btn', title: '复制当前图片到剪贴板(PNG)' }, '复制')
|
||||||
|
const btnDl = el('button', { className: 'iwb-album-fs-btn', title: '下载当前图片' }, '下载')
|
||||||
|
const bar = el('div', { className: 'iwb-album-fs-bar' }, [count, name, btnCopy, btnDl])
|
||||||
|
const hint = el('div', { className: 'iwb-album-fs-hint' }, '点击空白处或按 Esc 关闭 · ← → 切换')
|
||||||
|
const btnPrev = el('button', { className: 'iwb-album-fs-nav prev', title: '上一张(←)' }, '‹')
|
||||||
|
const btnNext = el('button', { className: 'iwb-album-fs-nav next', title: '下一张(→)' }, '›')
|
||||||
|
const root = el('div', { className: 'iwb-album-fs' + (total > 1 ? '' : ' single') }, [img, btnPrev, btnNext, bar, hint])
|
||||||
|
|
||||||
|
// 原图按需读:命中缓存直接用;读盘失败就保持缩略图(不白屏、不报错)
|
||||||
|
const fullOf = (i) => {
|
||||||
|
const it = pick(i)
|
||||||
|
const key = keyAt(i)
|
||||||
|
if (cache.has(key)) return Promise.resolve(cache.get(key))
|
||||||
|
const flight = pending.get(key)
|
||||||
|
if (flight) return flight
|
||||||
|
if (!ctx.images || typeof ctx.images.dataUrl !== 'function') return Promise.resolve('')
|
||||||
|
const p = Promise.resolve(ctx.images.dataUrl(it && it.src)).then((u) => {
|
||||||
|
pending.delete(key)
|
||||||
|
if (!u) return ''
|
||||||
|
cache.set(key, u)
|
||||||
|
// 只留当前 + 左右各一张:4K 图的 dataURL 一张就几 MB,全书缓存直接爆内存
|
||||||
|
const keep = new Set([keyAt(cur), keyAt(cur + 1), keyAt(cur - 1)])
|
||||||
|
if (cache.size > FS_KEEP) for (const k of Array.from(cache.keys())) if (!keep.has(k)) cache.delete(k)
|
||||||
|
return u
|
||||||
|
}).catch(() => { pending.delete(key); return '' })
|
||||||
|
pending.set(key, p)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
const paint = (i) => {
|
||||||
|
const it = pick(i)
|
||||||
|
const my = ++token
|
||||||
|
const cached = cache.get(keyAt(i))
|
||||||
|
const thumb = st.thumbs.get(keyAt(i)) || ''
|
||||||
|
// 先用缩略图占位(切换时不会闪一块黑),原图到了再换上;缩略图也还没好就现做
|
||||||
|
if (cached) { img.src = cached; curUrl = cached }
|
||||||
|
else if (thumb) { img.src = thumb; curUrl = thumb }
|
||||||
|
else {
|
||||||
|
img.removeAttribute('src'); curUrl = ''
|
||||||
|
loadThumb(ctx, st, it, keyAt(i)).then((u) => { if (u && my === token) { img.src = u; curUrl = u } }).catch(() => {})
|
||||||
|
}
|
||||||
|
fullOf(i).then((u) => { if (u && my === token) { img.src = u; curUrl = u } }).catch(() => {})
|
||||||
|
count.textContent = (i + 1) + ' / ' + total
|
||||||
|
name.textContent = (it && it.name) || ('图 ' + (i + 1))
|
||||||
|
if (total > 1) { fullOf(i + 1).catch(() => {}); fullOf(i - 1).catch(() => {}) }
|
||||||
|
}
|
||||||
|
const go = (delta) => { cur = ((cur + delta) % total + total) % total; paint(cur) }
|
||||||
|
const close = () => closeViewer(st)
|
||||||
|
|
||||||
|
img.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
img.addEventListener('click', (e) => e.stopPropagation())
|
||||||
|
for (const [btn, delta] of [[btnPrev, -1], [btnNext, 1]]) {
|
||||||
|
btn.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btn.addEventListener('click', (e) => { e.stopPropagation(); go(delta) })
|
||||||
|
}
|
||||||
|
// 复制 / 下载:宿主预览层原本有这两个按钮,不能因为换成自建查看器就丢掉
|
||||||
|
const flash = (msg) => {
|
||||||
|
hint.textContent = msg
|
||||||
|
clearTimeout(flash.timer)
|
||||||
|
flash.timer = setTimeout(() => { hint.textContent = '点击空白处或按 Esc 关闭 · ← → 切换' }, 1800)
|
||||||
|
}
|
||||||
|
const toPngBlob = (url) => new Promise((resolve, reject) => {
|
||||||
|
const im = new Image()
|
||||||
|
im.onload = () => {
|
||||||
|
try {
|
||||||
|
const cv = document.createElement('canvas')
|
||||||
|
cv.width = im.naturalWidth || 1; cv.height = im.naturalHeight || 1
|
||||||
|
cv.getContext('2d').drawImage(im, 0, 0)
|
||||||
|
cv.toBlob((b) => b ? resolve(b) : reject(new Error('toBlob 失败')), 'image/png')
|
||||||
|
} catch (e) { reject(e) }
|
||||||
|
}
|
||||||
|
im.onerror = () => reject(new Error('图片加载失败'))
|
||||||
|
im.src = url
|
||||||
|
})
|
||||||
|
for (const btn of [btnCopy, btnDl]) btn.addEventListener('pointerdown', (e) => e.stopPropagation())
|
||||||
|
btnDl.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (!curUrl) return
|
||||||
|
try {
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = curUrl
|
||||||
|
a.download = (pick(cur) && pick(cur).name) || ('image-' + (cur + 1) + '.png')
|
||||||
|
document.body.appendChild(a); a.click()
|
||||||
|
if (a.parentNode) a.parentNode.removeChild(a)
|
||||||
|
} catch (err) { flash('下载失败:' + String((err && err.message) || err)) }
|
||||||
|
})
|
||||||
|
btnCopy.addEventListener('click', async (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (!curUrl) return
|
||||||
|
try {
|
||||||
|
const png = await toPngBlob(curUrl)
|
||||||
|
if (navigator.clipboard && typeof navigator.clipboard.write === 'function' && typeof ClipboardItem !== 'undefined') {
|
||||||
|
await navigator.clipboard.write([new ClipboardItem({ 'image/png': png })])
|
||||||
|
} else {
|
||||||
|
// WKWebView 常没有 ClipboardItem ⇒ 走宿主的原生 arboard 通道(与图库预览同一实现)
|
||||||
|
const D = window.IWBDesktop
|
||||||
|
if (!D || !D.clipboardWriteImage || !(await D.clipboardWriteImage(png))) throw new Error('当前环境不支持图片剪贴板')
|
||||||
|
}
|
||||||
|
flash('已复制图片到剪贴板(PNG)')
|
||||||
|
} catch (err) { flash('复制失败:' + String((err && err.message) || err)) }
|
||||||
|
})
|
||||||
|
|
||||||
|
// 整个浮层吃掉指针事件:否则点空白会把画布的「取消选中/框选」一起触发
|
||||||
|
root.addEventListener('pointerdown', (e) => { e.stopPropagation(); if (e.target === root || e.target === bar) close() })
|
||||||
|
root.addEventListener('click', (e) => e.stopPropagation())
|
||||||
|
root.addEventListener('pointerup', (e) => e.stopPropagation())
|
||||||
|
root.addEventListener('dblclick', (e) => e.stopPropagation())
|
||||||
|
|
||||||
|
// 键盘:捕获阶段吃掉,避免宿主把 ← → 当成「微调节点」
|
||||||
|
const onKey = (e) => {
|
||||||
|
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close() }
|
||||||
|
else if (e.key === 'ArrowLeft') { e.preventDefault(); e.stopPropagation(); go(-1) }
|
||||||
|
else if (e.key === 'ArrowRight') { e.preventDefault(); e.stopPropagation(); go(1) }
|
||||||
|
}
|
||||||
|
// 滚轮也切(大图查看器的通用手势);40ms 节流,避免一次滑到底翻好几张
|
||||||
|
let wheelLock = 0
|
||||||
|
const onWheel = (e) => {
|
||||||
|
if (total < 2) return
|
||||||
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
const now = Date.now()
|
||||||
|
if (now - wheelLock < 40) return
|
||||||
|
const d = Math.abs(e.deltaY) > Math.abs(e.deltaX) ? e.deltaY : e.deltaX
|
||||||
|
if (Math.abs(d) < 2) return
|
||||||
|
wheelLock = now
|
||||||
|
go(d > 0 ? 1 : -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(root)
|
||||||
|
paint(cur)
|
||||||
|
window.addEventListener('keydown', onKey, true)
|
||||||
|
window.addEventListener('wheel', onWheel, { passive: false, capture: true })
|
||||||
|
st.viewer = { root, onKey, onWheel }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 一键清空 ────────────────────────────────────────────
|
||||||
|
function clearAll (ctx, st) {
|
||||||
|
const items = itemsOf(st.node)
|
||||||
|
if (!items.length) return
|
||||||
|
st.thumbs.clear(); st.pending.clear(); st.missing.clear()
|
||||||
|
st.checkedMissing = false // 清空后再导入要重新做一次失联检测
|
||||||
|
closeViewer(st) // 正在看大图时清空 ⇒ 先把浮层收掉(别留个没有数据的空查看器)
|
||||||
|
update(st.props, st.node, { items: [], page: 0, pageRange: null }, true)
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 导入:选择器 / 文件夹 / 拖入 / 固化 / 重新定位 ──────────
|
||||||
|
async function pickFiles (ctx, st, host, directory) {
|
||||||
|
if (st.busy) return
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
// 桌面端:系统选择器给绝对路径 ⇒ 只引用(不复制字节)
|
||||||
|
if (ctx.images && ctx.images.canReference()) {
|
||||||
|
st.busy = '选择中…'; st.sig = ''; sync(ctx, st, st.node, st.props)
|
||||||
|
try {
|
||||||
|
const picked = await ctx.images.pick({ multiple: true, directory: !!directory })
|
||||||
|
st.busy = ''
|
||||||
|
if (!picked.length) { st.sig = ''; sync(ctx, st, st.node, st.props); return }
|
||||||
|
// 目录要展开成图片文件:pick 返回目录路径本身不是图片,之前直接过滤 ⇒ 「文件夹」点了没反应
|
||||||
|
let paths = []
|
||||||
|
if (directory) {
|
||||||
|
for (const dir of picked) {
|
||||||
|
try { const got = await ctx.images.listImages(dir); for (const f of (got || [])) paths.push(f) } catch (e) { /* 单个目录失败不阻断 */ }
|
||||||
|
}
|
||||||
|
} else paths = picked.slice()
|
||||||
|
if (!paths.length) { st.sig = ''; sync(ctx, st, st.node, st.props); return }
|
||||||
|
await addPaths(ctx, st, paths)
|
||||||
|
} catch (e) { st.busy = ''; st.sig = ''; sync(ctx, st, st.node, st.props) }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 不支持路径引用的宿主:退回文件选择 + 复制进画布存储
|
||||||
|
const input = document.createElement('input')
|
||||||
|
input.type = 'file'; input.accept = 'image/*'; input.multiple = true
|
||||||
|
input.style.display = 'none'
|
||||||
|
document.body.appendChild(input)
|
||||||
|
input.addEventListener('change', () => {
|
||||||
|
const files = Array.from(input.files || [])
|
||||||
|
document.body.removeChild(input)
|
||||||
|
if (files.length) importDropped(ctx, st, files)
|
||||||
|
})
|
||||||
|
input.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addPaths (ctx, st, paths) {
|
||||||
|
const list = paths.filter(isImagePath)
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
st.busy = '导入 ' + (i + 1) + '/' + list.length; st.sig = ''; sync(ctx, st, st.node, st.props)
|
||||||
|
const ref = await ctx.images.reference(list[i])
|
||||||
|
if (!ref || !ref.ok) continue
|
||||||
|
items.push({ src: { __file: ref.item.path }, name: ref.item.name, size: ref.item.size, mtime: ref.item.mtime, on: true })
|
||||||
|
}
|
||||||
|
st.busy = ''
|
||||||
|
st.checkedMissing = false // 新图要重新做一次失联检测(否则清空后再导入,检测永远不再跑)
|
||||||
|
update(st.props, st.node, { items }, true)
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
// 顺序预生成缩略图(避免一次读几十张原图造成内存尖峰)。
|
||||||
|
// 1.1.0:进度写进「+ 添加图片」按钮(旧实现 busy 在这里已经清空 ⇒ 导入 500 张时界面像卡死);
|
||||||
|
// 只改按钮文字、不重置 sig ⇒ 不触发整块宫格重建(重建 500 次比读盘本身还慢)。
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const it = items[i]
|
||||||
|
const key = thumbKeyOf(it)
|
||||||
|
if (!key || st.thumbs.has(key)) continue
|
||||||
|
st.busy = '缩略图 ' + (i + 1) + '/' + items.length
|
||||||
|
st.btnAdd.textContent = st.busy
|
||||||
|
await loadThumb(ctx, st, it, key)
|
||||||
|
}
|
||||||
|
st.busy = ''
|
||||||
|
st.btnAdd.textContent = '+ 添加图片'
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function importDropped (ctx, st, files) {
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const f = files[i]
|
||||||
|
if (!f || !/^image\//i.test(f.type || '')) continue
|
||||||
|
st.busy = '复制 ' + (i + 1) + '/' + files.length; st.sig = ''; sync(ctx, st, st.node, st.props)
|
||||||
|
const dataUrl = await new Promise((resolve) => {
|
||||||
|
try { const r = new FileReader(); r.onload = () => resolve(String(r.result || '')); r.onerror = () => resolve(''); r.readAsDataURL(f) } catch (e) { resolve('') }
|
||||||
|
})
|
||||||
|
if (!dataUrl) continue
|
||||||
|
let res = null
|
||||||
|
try { res = await ctx.images.importDataUrl(dataUrl, { keepOriginal: (st.node.data && st.node.data.keepOriginal !== false) }) } catch (e) { res = null }
|
||||||
|
if (!res || !res.ok) continue
|
||||||
|
const src = res.ref || res.data
|
||||||
|
if (!src) continue
|
||||||
|
const name = f.name || ('图 ' + (items.length + 1))
|
||||||
|
items.push({ src, name: name, size: f.size || 0, on: true })
|
||||||
|
const thumb = await makeThumb(dataUrl)
|
||||||
|
// 键必须和 cellOf / loadThumb 完全一致(thumbKeyOf),否则写进缓存也命中不到
|
||||||
|
if (thumb) {
|
||||||
|
const key = thumbKeyOf(items[items.length - 1])
|
||||||
|
st.thumbs.set(key, thumb)
|
||||||
|
try { if (ctx.files) await ctx.files.put(thumbNameOf(key), thumb) } catch (e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st.busy = ''
|
||||||
|
st.checkedMissing = false
|
||||||
|
update(st.props, st.node, { items }, true)
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 固化:把 __file 引用换成宿主存储引用(删源文件/分享画布前用)
|
||||||
|
async function settleAll (ctx, st) {
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
let done = 0
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const it = items[i]
|
||||||
|
const path = fileRefOf(it && it.src)
|
||||||
|
if (!path) continue
|
||||||
|
st.busy = '固化 ' + (++done) + '…'; st.sig = ''; sync(ctx, st, st.node, st.props)
|
||||||
|
try {
|
||||||
|
const res = await ctx.images.importPath(path, { keepOriginal: (st.node.data && st.node.data.keepOriginal !== false) })
|
||||||
|
if (res && res.ok && (res.ref || res.data)) items[i] = Object.assign({}, it, { src: res.ref || res.data })
|
||||||
|
} catch (e) { /* 单张失败不打断整批 */ }
|
||||||
|
}
|
||||||
|
st.busy = ''
|
||||||
|
update(st.props, st.node, { items }, true)
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkMissing (ctx, st, items) {
|
||||||
|
let changed = false
|
||||||
|
for (const it of items) {
|
||||||
|
const path = fileRefOf(it && it.src)
|
||||||
|
if (!path) continue
|
||||||
|
try {
|
||||||
|
const r = await ctx.images.stat(path)
|
||||||
|
const missing = !(r && r.ok && r.exists)
|
||||||
|
if (missing && !st.missing.has(path)) { st.missing.add(path); changed = true }
|
||||||
|
if (!missing && st.missing.has(path)) { st.missing.delete(path); changed = true }
|
||||||
|
} catch (e) { /* 检测失败按存在处理 */ }
|
||||||
|
}
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
// 失联重定位:点失联格 → 选一张同名/任意图片替换
|
||||||
|
async function relocate (ctx, st, index) {
|
||||||
|
if (!ctx.images || !ctx.images.canReference()) return
|
||||||
|
const items = itemsOf(st.node).slice()
|
||||||
|
const cur = items[index]
|
||||||
|
if (!cur) return
|
||||||
|
const paths = await ctx.images.pick({ multiple: false })
|
||||||
|
if (!paths || !paths.length) return
|
||||||
|
const ref = await ctx.images.reference(paths[0])
|
||||||
|
if (!ref || !ref.ok) return
|
||||||
|
const oldPath = fileRefOf(cur.src)
|
||||||
|
st.missing.delete(oldPath)
|
||||||
|
items[index] = Object.assign({}, cur, { src: { __file: ref.item.path }, name: ref.item.name, size: ref.item.size, mtime: ref.item.mtime })
|
||||||
|
update(st.props, st.node, { items }, true)
|
||||||
|
st.sig = ''
|
||||||
|
sync(ctx, st, st.node, st.props)
|
||||||
|
loadThumb(ctx, st, items[index], thumbKeyOf(items[index])).then(() => { st.sig = ''; try { sync(ctx, st, st.node, st.props) } catch (e) { /* ignore */ } })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ── 注册 ────────────────────────────────────────────────
|
||||||
|
global.IWBPluginHost.register({
|
||||||
|
id: 'album',
|
||||||
|
name: '相册',
|
||||||
|
version: '1.1.2',
|
||||||
|
apiVersion: 1,
|
||||||
|
capabilities: ['nodeTypes', 'images', 'files'],
|
||||||
|
settings: {
|
||||||
|
keepOriginal: { type: 'boolean', label: '默认保留原图(不压缩)', desc: '开启后导入不进 1600 长边压缩,分辨率不损失(占用更高)。节点内可单独改。', default: true },
|
||||||
|
},
|
||||||
|
}, function (ctx) {
|
||||||
|
ctx.nodes.register({
|
||||||
|
id: 'album',
|
||||||
|
title: '相册',
|
||||||
|
icon: 'puzzle',
|
||||||
|
width: 300,
|
||||||
|
height: 470,
|
||||||
|
ports: { in: true, out: true },
|
||||||
|
defaults: { outKind: 'images', items: [], albumMode: 'per-image', density: 'S', page: 0, onlyPage: false, keepOriginal: ctx.settings.get('keepOriginal') !== false },
|
||||||
|
render: function (node, props, host) {
|
||||||
|
// 自愈(2026-11-26):旧版本/兜底路径建出来的节点可能没有 outKind,
|
||||||
|
// 那样连线规则会把相册当普通插件节点(只能连中继)。这里补写一次默认值。
|
||||||
|
try {
|
||||||
|
const d0 = node && node.data
|
||||||
|
if (d0 && d0.outKind !== 'images') {
|
||||||
|
props.onUpdate(node.id, { outKind: 'images', items: Array.isArray(d0.items) ? d0.items : [] })
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
let st = STATE.get(host)
|
||||||
|
if (!st || st.nodeId !== node.id) { st = buildShell(ctx, node, props, host); STATE.set(host, st) }
|
||||||
|
try { sync(ctx, st, node, props) } catch (e) {
|
||||||
|
// 渲染失败降级成一行可读文本(绝不让整块画布白屏)
|
||||||
|
try { host.textContent = ''; const tip = document.createElement('div'); tip.className = 'iwb-hint'; tip.textContent = '相册渲染失败:' + String((e && e.message) || e); host.appendChild(tip) } catch (e2) { /* ignore */ }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return {}
|
||||||
|
})
|
||||||
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/* 相册节点体(2026-11-26)
|
||||||
|
* 宿主只给一块空容器(.iwb-plugin-node-body),所有排版由这里决定。
|
||||||
|
* 尺寸全部用像素而不是 rem:节点宽度是可拖拽的(264~600),rem 会跟着宿主字号漂移。
|
||||||
|
*/
|
||||||
|
.iwb-album { position: relative; display: flex; flex-direction: column; height: 100%; overflow: hidden; font-size: 11px; color: var(--iwb-node-text); }
|
||||||
|
.iwb-album-bar, .iwb-album-tools, .iwb-album-pager, .iwb-album-onepage {
|
||||||
|
display: flex; align-items: center; gap: var(--iwb-space-6); padding: var(--iwb-space-4) var(--iwb-space-8); flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
.iwb-album-bar { border-bottom: 1px solid color-mix(in srgb, var(--iwb-border) 55%, transparent); height: 26px; }
|
||||||
|
.iwb-album-tools { padding-top: var(--iwb-space-2); padding-bottom: var(--iwb-space-2); }
|
||||||
|
.iwb-album-toggle { display: inline-flex; align-items: center; gap: var(--iwb-space-4); font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); white-space: nowrap; cursor: pointer; }
|
||||||
|
.iwb-album-track { width: 22px; height: 12px; border-radius: 999px; background: var(--iwb-border); position: relative; flex: 0 0 auto; transition: background .15s; }
|
||||||
|
.iwb-album-track i { position: absolute; top: 1.5px; left: 1.5px; width: 9px; height: 9px; border-radius: 50%; background: var(--iwb-panel); transition: left .15s; }
|
||||||
|
.iwb-album-track.on { background: var(--iwb-brand); }
|
||||||
|
.iwb-album-track.on i { left: 11.5px; }
|
||||||
|
.iwb-album-count { margin-left: auto; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
|
.iwb-album-count b { color: var(--iwb-node-text); font-weight: 600; }
|
||||||
|
.iwb-album-btn { height: 21px; padding: 0 var(--iwb-space-8); border: 1px solid var(--iwb-border); border-radius: var(--iwb-radius-chip); background: var(--iwb-panel); color: var(--iwb-node-text2); font-size: var(--iwb-font-2xs); display: inline-flex; align-items: center; gap: var(--iwb-space-4); cursor: pointer; white-space: nowrap; }
|
||||||
|
.iwb-album-btn:hover { border-color: var(--iwb-brand); color: var(--iwb-node-text); }
|
||||||
|
.iwb-album-btn.on { border-color: var(--iwb-brand); color: var(--iwb-node-text); }
|
||||||
|
/* 清空:常驻在顶栏最右,只有相册里有图时才出现。hover 转红是为了和「添加」一类中性操作区分开。 */
|
||||||
|
.iwb-album-clear { flex: 0 0 auto; padding: 0 var(--iwb-space-6); }
|
||||||
|
.iwb-album-clear:hover { border-color: #c0392b; color: #c0392b; }
|
||||||
|
.iwb-album-seg { margin-left: auto; display: inline-flex; border: 1px solid var(--iwb-border); border-radius: var(--iwb-radius-chip); overflow: hidden; }
|
||||||
|
.iwb-album-seg span { width: 21px; height: 21px; display: inline-flex; align-items: center; justify-content: center; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); background: var(--iwb-panel); cursor: pointer; }
|
||||||
|
.iwb-album-seg span.on { background: var(--iwb-brand); color: var(--iwb-on-brand); }
|
||||||
|
.iwb-album-grid { display: grid; gap: var(--iwb-space-4); padding: var(--iwb-space-2) var(--iwb-space-8) var(--iwb-space-6); overflow: hidden; align-content: start; flex: 1 1 auto; min-height: 0; }
|
||||||
|
/* 格子固定正方形(2026-11-26):此前高度由图片比例决定 —— 4 张 16:9 宽图会变成 22px 细条、
|
||||||
|
竖图撑到 167px,和 capacityOf() 按方形算的容量是两套账(最后一行常被裁一半)。
|
||||||
|
aspect-ratio 让每一格高 = 宽,容量因此可精确预测,宫格也终于整齐。
|
||||||
|
padding:0 必须显式写:<button> 的 UA 默认内边距会把图顶出边框。 */
|
||||||
|
.iwb-album-cell { position: relative; aspect-ratio: 1 / 1; padding: 0; border-radius: var(--iwb-radius-chip); overflow: hidden; background: color-mix(in srgb, var(--iwb-border) 55%, transparent); border: 1px solid var(--iwb-border); cursor: grab; }
|
||||||
|
.iwb-album-cell img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-drag: none; }
|
||||||
|
.iwb-album-cell.off img { opacity: .38; }
|
||||||
|
/* 选中线 2px → 1px(用户:太粗)。1px 在浅底上仍分得清「选中」与「描边」。 */
|
||||||
|
.iwb-album-cell.sel { outline: 1px solid var(--iwb-brand); outline-offset: -1px; }
|
||||||
|
.iwb-album-cell.missing { outline: 1px dashed #c0392b; outline-offset: -1px; }
|
||||||
|
.iwb-album-cell.missing::after { content: '失联'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: var(--iwb-font-2xs); color: #c0392b; background: rgba(255,255,255,.72); }
|
||||||
|
.iwb-album-cell.dragging { opacity: .45; }
|
||||||
|
.iwb-album-cell.dropbefore { box-shadow: -3px 0 0 0 var(--iwb-brand); }
|
||||||
|
.iwb-album-idx { position: absolute; left: var(--iwb-space-2); top: var(--iwb-space-2); min-width: 14px; height: 14px; padding: 0 var(--iwb-space-4); border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; font-size: var(--iwb-font-2xs); display: flex; align-items: center; justify-content: center; }
|
||||||
|
/* 批次角标已移除(2026-11-26):顶栏「N 张 → M 个任务」已经说清楚,每格右上角再挂个「1」是重复信息。
|
||||||
|
位置让给删除按钮:右下角要留给放大镜。 */
|
||||||
|
.iwb-album-del { position: absolute; right: var(--iwb-space-2); top: var(--iwb-space-2); width: 15px; height: 15px; border-radius: 50%; background: var(--iwb-panel); color: var(--iwb-node-text2); font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center; opacity: 0; cursor: pointer; }
|
||||||
|
.iwb-album-cell:hover .iwb-album-del { opacity: 1; }
|
||||||
|
/* 放大镜:右下角,hover 才出现(静息态不抢视觉,和 × 一致)。
|
||||||
|
17px 圆 / 12px 图标:再小镜片就缩成一团白点。
|
||||||
|
z-index 高于图与角标:1.1.0 时它被节点内预览层(z-index 9)盖住 ⇒ 用户反馈「滑过去就点不到」,
|
||||||
|
那层已在 1.1.1 删除;这里仍显式抬一层,避免以后再加浮层时重犯。 */
|
||||||
|
.iwb-album-zoom { position: absolute; right: var(--iwb-space-2); bottom: var(--iwb-space-2); z-index: 3; width: 17px; height: 17px; border-radius: 50%; background: var(--iwb-panel); color: var(--iwb-node-text2); display: flex; align-items: center; justify-content: center; opacity: 0; cursor: zoom-in; transition: opacity .12s; }
|
||||||
|
.iwb-album-cell:hover .iwb-album-zoom, .iwb-album-cell:focus-within .iwb-album-zoom { opacity: 1; }
|
||||||
|
.iwb-album-zoom:hover { color: var(--iwb-brand); }
|
||||||
|
.iwb-album-zoom svg { width: 12px; height: 12px; display: block; }
|
||||||
|
/* 全屏查看器(1.1.2):挂在 document.body 上,所以是 position: fixed + 自备层级。
|
||||||
|
810 = 宿主图片预览层(--iwb-z-preview: 800)之上一层,盖住画布但不抢系统弹窗。
|
||||||
|
为什么不用宿主 onPreview:那个接口只收「已解析好的 URL 列表」,整本相册要一次全转 dataURL。 */
|
||||||
|
.iwb-album-fs { position: fixed; inset: 0; z-index: 810; display: flex; align-items: center; justify-content: center; background: rgba(10, 12, 18, .92); cursor: zoom-out; }
|
||||||
|
.iwb-album-fs img { max-width: 92vw; max-height: 88vh; width: auto; height: auto; object-fit: contain; display: block; border-radius: 8px; box-shadow: 0 8px 40px rgba(0, 0, 0, .5); cursor: default; }
|
||||||
|
.iwb-album-fs-nav { position: fixed; top: 50%; transform: translateY(-50%); width: 46px; height: 64px; padding: 0; border: none; border-radius: 8px; background: rgba(255, 255, 255, .1); color: #fff; font-size: 30px; line-height: 1; display: flex; align-items: center; justify-content: center; cursor: pointer; }
|
||||||
|
.iwb-album-fs-nav:hover { background: rgba(255, 255, 255, .22); }
|
||||||
|
.iwb-album-fs-nav.prev { left: 18px; }
|
||||||
|
.iwb-album-fs-nav.next { right: 18px; }
|
||||||
|
.iwb-album-fs.single .iwb-album-fs-nav { display: none; }
|
||||||
|
/* 计数条要放「复制/下载」按钮,所以本身吃事件;点条上空白仍然算点外部(关闭) */
|
||||||
|
.iwb-album-fs-bar { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: 80vw; padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 12px; }
|
||||||
|
.iwb-album-fs-btn { height: 22px; padding: 0 9px; border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px; background: rgba(255, 255, 255, .08); color: #fff; font-size: 11px; cursor: pointer; flex: 0 0 auto; }
|
||||||
|
.iwb-album-fs-btn:hover { background: rgba(255, 255, 255, .22); }
|
||||||
|
.iwb-album-fs-count { font-variant-numeric: tabular-nums; }
|
||||||
|
.iwb-album-fs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .72; }
|
||||||
|
.iwb-album-fs-hint { position: fixed; left: 50%; bottom: 6px; transform: translateX(-50%); color: rgba(255, 255, 255, .45); font-size: 11px; white-space: nowrap; pointer-events: none; }
|
||||||
|
.iwb-album-add { border: 1px dashed var(--iwb-border); background: transparent; color: var(--iwb-node-text2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--iwb-space-2); font-size: var(--iwb-font-2xs); border-radius: var(--iwb-radius-chip); cursor: pointer; }
|
||||||
|
.iwb-album-add b { font-size: 15px; line-height: 1; font-weight: 600; }
|
||||||
|
.iwb-album-pager { border-top: 1px solid color-mix(in srgb, var(--iwb-border) 55%, transparent); height: 26px; }
|
||||||
|
.iwb-album-onepage { border-top: 1px solid color-mix(in srgb, var(--iwb-border) 55%, transparent); height: 26px; color: var(--iwb-node-text2); font-size: var(--iwb-font-2xs); }
|
||||||
|
.iwb-album-pg { display: inline-flex; align-items: center; border: 1px solid var(--iwb-border); border-radius: var(--iwb-radius-chip); background: var(--iwb-panel); }
|
||||||
|
.iwb-album-pg span { width: 17px; height: 17px; display: flex; align-items: center; justify-content: center; font-size: var(--iwb-font-2xs); cursor: pointer; color: var(--iwb-node-text2); }
|
||||||
|
.iwb-album-pg b { font-weight: 600; color: var(--iwb-node-text); padding: 0 2px; font-size: var(--iwb-font-2xs); }
|
||||||
|
.iwb-album-mini { display: inline-flex; align-items: center; gap: var(--iwb-space-4); margin-left: auto; font-size: var(--iwb-font-2xs); color: var(--iwb-node-text2); white-space: nowrap; }
|
||||||
|
.iwb-album-hint { margin: 0 8px 4px; padding: 4px 6px; border-radius: var(--iwb-radius-chip); background: rgba(107,114,128,.10); border: 1px solid rgba(107,114,128,.22); color: var(--iwb-node-text2); font-size: var(--iwb-font-2xs); line-height: 1.45; }
|
||||||
|
.iwb-album-hint b { color: var(--iwb-node-text); }
|
||||||
|
.iwb-album-empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--iwb-space-6); color: var(--iwb-node-text2); font-size: 11px; text-align: center; padding: 0 var(--iwb-space-12); }
|
||||||
|
.iwb-album-empty .box { width: 66px; height: 50px; border: 1.5px dashed var(--iwb-border); border-radius: var(--iwb-radius-chip); display: flex; align-items: center; justify-content: center; font-size: var(--iwb-font-xl); color: var(--iwb-node-text2); }
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/* album 插件自测(v1.1.0,2026-11-26)
|
||||||
|
*
|
||||||
|
* 为什么要有它:这个插件此前**零自动化测试**(宿主侧 tests/album-task-graph-test.js 只覆盖任务展开)。
|
||||||
|
* 而 1.1.0 动的是「宫格尺寸 = 分页容量」这条最脆的链:capacityOf() 里的常量必须和 styles.css 逐个对齐,
|
||||||
|
* 错 1px 就会「最后一行被裁一半」,而那种错误肉眼要盯很久才发现。这里把它变成断言。
|
||||||
|
*
|
||||||
|
* 两部分:
|
||||||
|
* 一、静态断言:源码 / 样式里的关键实现必须还在(防回归,不依赖浏览器)
|
||||||
|
* 二、算术断言:把常量段 + capacityOf / thumbKeyOf 从 IIFE 里抽出来,在 vm 里真跑
|
||||||
|
*
|
||||||
|
* 浏览器渲染验证(方形格子、裁切、点击放大)不在这里 —— 那需要 playwright,
|
||||||
|
* 跨仓依赖不适合当门禁。跑法见 README「验证」一节。
|
||||||
|
*/
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import vm from 'node:vm'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
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')
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'))
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, extra) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name + (cond ? '' : (' » ' + (extra == null ? '' : extra))))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 一、版本与注册契约 ───────────────────────────────────────
|
||||||
|
ok('package.json version = 1.1.2', pkg.version === '1.1.2', pkg.version)
|
||||||
|
ok('manifest.version = 1.1.2', /version:\s*'1\.1\.2'/.test(src))
|
||||||
|
ok('id = album', /id:\s*'album'/.test(src))
|
||||||
|
ok('capabilities 含 nodeTypes / images / files',
|
||||||
|
/capabilities:\s*\['nodeTypes',\s*'images',\s*'files'\]/.test(src))
|
||||||
|
ok('默认 outKind = images(宿主靠它认「多图源」,决定连线白名单 + 任务展开)',
|
||||||
|
/defaults:\s*\{[^}]*outKind:\s*'images'/.test(src))
|
||||||
|
ok('端口 in/out 都在(相册要接提示词、要出图)', /ports:\s*\{\s*in:\s*true,\s*out:\s*true\s*\}/.test(src))
|
||||||
|
|
||||||
|
// ── 二、容量常量必须与 styles.css 对齐 ────────────────────────
|
||||||
|
// 宿主全局 * { box-sizing: border-box },所以 CSS 的 height 已含 padding;JS 侧照抄即可。
|
||||||
|
const cssGap = /\.iwb-album-grid\s*\{[^}]*gap:\s*var\(--iwb-space-4\)/.test(css) ? 4 : -1
|
||||||
|
ok('宫格 gap = 4px(CSS 用 --iwb-space-4)', cssGap === 4)
|
||||||
|
ok('JS GAP 与 CSS 一致(4)', /const GAP = 4\b/.test(src))
|
||||||
|
ok('PAD_X = 16(左右各 --iwb-space-8)', /const PAD_X = 16\b/.test(src))
|
||||||
|
ok('PAD_Y = 8(宫格 padding 2 + 6)', /const PAD_Y = 8\b/.test(src))
|
||||||
|
ok('BAR_H = 26(顶栏 height: 26px)', /const BAR_H = 26\b/.test(src))
|
||||||
|
ok('TOOLS_H = 25(工具条 padding 2+2 + 按钮 21)', /const TOOLS_H = 25\b/.test(src))
|
||||||
|
ok('PAGER_H = 26(分页条 height: 26px)', /const PAGER_H = 26\b/.test(src))
|
||||||
|
ok('HINT_H = 28(提示行 24 + margin-bottom 4)', /const HINT_H = 28\b/.test(src))
|
||||||
|
ok('顶栏确实 height: 26px', /\.iwb-album-bar\s*\{[^}]*height:\s*26px/.test(css))
|
||||||
|
ok('分页条确实 height: 26px', /\.iwb-album-pager\s*\{[^}]*height:\s*26px/.test(css))
|
||||||
|
|
||||||
|
// ── 三、把纯逻辑抽出来在 vm 里真跑 ────────────────────────────
|
||||||
|
const from = src.indexOf(' const DENSITY')
|
||||||
|
const to = src.indexOf(' // ── 数据读写')
|
||||||
|
ok('能定位到常量段与 capacityOf(抽出来跑算术)', from > 0 && to > from, from + '/' + to)
|
||||||
|
let sandbox = {}
|
||||||
|
if (from > 0 && to > from) {
|
||||||
|
// const / 箭头函数在 vm 顶层是词法的,不会自动挂到 sandbox 上 ⇒ 显式导出一份
|
||||||
|
const code = src.slice(from, to) + '\n;globalThis.__album = { DENSITY: DENSITY, capacityOf: capacityOf, thumbKeyOf: thumbKeyOf, thumbNameOf: thumbNameOf }\n'
|
||||||
|
sandbox = { document: { createElement: () => ({ style: {}, appendChild() {} }) }, setTimeout, clearTimeout, Math, String, Number, Array, Object, Map, Set, Promise, JSON, RegExp, console, window: {} }
|
||||||
|
vm.createContext(sandbox)
|
||||||
|
vm.runInContext(code, sandbox, { filename: 'album-slice.js' })
|
||||||
|
Object.assign(sandbox, sandbox.__album || {})
|
||||||
|
}
|
||||||
|
|
||||||
|
const cap = sandbox.capacityOf
|
||||||
|
const DENSITY = sandbox.DENSITY
|
||||||
|
ok('DENSITY 三档严格递增(旧值 M:48 < S:64 是 bug:中格比小格还小)',
|
||||||
|
DENSITY && DENSITY.S < DENSITY.M && DENSITY.M < DENSITY.L, JSON.stringify(DENSITY))
|
||||||
|
|
||||||
|
if (typeof cap === 'function') {
|
||||||
|
// 默认节点 300×470(DEFAULT_H),这是用户最常看到的那一档
|
||||||
|
const s = cap(300, 470, 'S', false)
|
||||||
|
const m = cap(300, 470, 'M', false)
|
||||||
|
const l = cap(300, 470, 'L', false)
|
||||||
|
ok('300×470 小格 = 4 列(实测渲染 4 列 68px)', s.cols === 4, JSON.stringify(s))
|
||||||
|
ok('每页容量随档位递减 S > M > L(旧的 M 反而最多)',
|
||||||
|
s.capacity > m.capacity && m.capacity > l.capacity,
|
||||||
|
[s.capacity, m.capacity, l.capacity].join(' / '))
|
||||||
|
ok('小格每页 20 张(批量导入的常见预期值)', s.capacity === 20, String(s.capacity))
|
||||||
|
// 关键几何不变量:cols 个 cell + (cols-1) 个 gap 必须装得进内容宽度,
|
||||||
|
// rows 个 cell + (rows-1) 个 gap 必须装得进内容高度。差 1px 就会让最后一行被裁。
|
||||||
|
const fits = (w, h, d, hint) => {
|
||||||
|
const c = cap(w, h, d, hint)
|
||||||
|
const innerW = w - 4 - 16
|
||||||
|
const innerH = h - 4 - 26 - 25 - 26 - (hint ? 28 : 0) - 8
|
||||||
|
const needW = c.cols * c.cell + (c.cols - 1) * 4
|
||||||
|
const needH = c.rows * c.cell + (c.rows - 1) * 4
|
||||||
|
return { c, okW: needW <= innerW, okH: needH <= innerH, needW, needH, innerW, innerH }
|
||||||
|
}
|
||||||
|
let allFit = true
|
||||||
|
const misses = []
|
||||||
|
for (const w of [264, 280, 300, 360, 420, 520, 600]) {
|
||||||
|
for (const h of [300, 380, 470, 560, 700]) {
|
||||||
|
for (const d of ['S', 'M', 'L']) {
|
||||||
|
for (const hint of [false, true]) {
|
||||||
|
const r = fits(w, h, d, hint)
|
||||||
|
if (!r.okW || !r.okH) { allFit = false; misses.push(w + 'x' + h + ' ' + d + (hint ? '+hint ' : ' ') + JSON.stringify([r.needW, r.innerW, r.needH, r.innerH])) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ok('35 种节点尺寸 × 3 档 × 有无提示行:算出的容量都能装进可视区(不会裁掉最后一行)',
|
||||||
|
allFit, misses.slice(0, 3).join(' | '))
|
||||||
|
const min = cap(180, 160, 'S', true)
|
||||||
|
ok('极小节点也不返回 0 列 0 行(否则宫格空白)', min.cols >= 1 && min.rows >= 1 && min.capacity >= 1, JSON.stringify(min))
|
||||||
|
}
|
||||||
|
|
||||||
|
// thumbKeyOf:固化后(src 变成 {__blob})不能退化成纯文件名(否则同名文件串味)
|
||||||
|
const tk = sandbox.thumbKeyOf
|
||||||
|
if (typeof tk === 'function') {
|
||||||
|
const a1 = tk({ src: { __file: '/a/1.png' }, name: '1.png' })
|
||||||
|
const a2 = tk({ src: { __file: '/b/1.png' }, name: '1.png' })
|
||||||
|
ok('同名不同目录的本地图 → 不同键(旧实现两处都是 "1.png",缩略图互相覆盖)', a1 !== a2, a1 + ' vs ' + a2)
|
||||||
|
const b1 = tk({ src: { __blob: 'x1' }, name: '1.png' })
|
||||||
|
const b2 = tk({ src: { __blob: 'x2' }, name: '1.png' })
|
||||||
|
ok('固化后按 __blob id 取键,不退化到文件名', b1 !== b2 && b1.indexOf('b:') === 0, b1 + ' vs ' + b2)
|
||||||
|
ok('同一引用取键稳定(拖拽排序后不会重建缩略图)', tk({ src: { __file: '/a/1.png' }, name: '1.png' }) === a1)
|
||||||
|
ok('键做成了文件安全的形式(t-<hash8>.jpg,符合插件文件白名单)',
|
||||||
|
/^[a-z0-9][a-z0-9_-]{0,63}\.jpg$/.test(sandbox.thumbNameOf(a1)), sandbox.thumbNameOf(a1))
|
||||||
|
} else ok('thumbKeyOf 可被抽取执行', false)
|
||||||
|
|
||||||
|
// ── 四、交互:清空 / 放大镜 / 固定方形 / 细边线 ────────────────
|
||||||
|
ok('有「清空」按钮', /className:\s*'iwb-album-btn iwb-album-clear'/.test(src))
|
||||||
|
ok('清空走快照(⌘Z 能整体撤销)',
|
||||||
|
/function clearAll[\s\S]{0,700}update\(st\.props, st\.node, \{ items: \[\], page: 0, pageRange: null \}, true\)/.test(src))
|
||||||
|
ok('清空只在有图时出现', /st\.btnClear\.style\.display = items\.length \? '' : 'none'/.test(src))
|
||||||
|
ok('清空后重置失联检测(否则清空再导入永远不检测)', /function clearAll[\s\S]{0,600}st\.checkedMissing = false/.test(src))
|
||||||
|
|
||||||
|
ok('格子固定正方形(aspect-ratio: 1 / 1)', /\.iwb-album-cell\s*\{[^}]*aspect-ratio:\s*1 \/ 1/.test(css))
|
||||||
|
ok('格子显式 padding: 0(button 默认内边距会把图顶出边框)', /\.iwb-album-cell\s*\{[^}]*padding:\s*0;/.test(css))
|
||||||
|
ok('选中线 1px(用户:2px 太粗)', /\.iwb-album-cell\.sel\s*\{[^}]*outline:\s*1px solid/.test(css))
|
||||||
|
ok('失联虚线同步 1px', /\.iwb-album-cell\.missing\s*\{[^}]*outline:\s*1px dashed/.test(css))
|
||||||
|
|
||||||
|
ok('放大镜元素存在(右下角)', /className:\s*'iwb-album-zoom'/.test(src))
|
||||||
|
// 1.1.1 用户裁定:hover 方案(A)实测把放大镜盖住了 ⇒ 只留「点击看大图」。
|
||||||
|
ok('不再有 hover 预览(pointerenter 触发 showPreview)', !/pointerenter'[\s\S]{0,80}showPreview/.test(src))
|
||||||
|
ok('showPreview / hidePreview / 节点内预览层代码彻底删除', !/function showPreview|function hidePreview|iwb-album-preview/.test(src + css))
|
||||||
|
ok('CSS 里没有节点内预览层(.iwb-album-preview)', !/iwb-album-preview/.test(css))
|
||||||
|
ok('放大镜 z-index 高于图片与角标(不再被任何浮层压住)',
|
||||||
|
/\.iwb-album-zoom\s*\{[^}]*z-index:\s*[1-9]/.test(css))
|
||||||
|
ok('放大镜在键盘聚焦时也可见(focus-within,不只 hover)',
|
||||||
|
/\.iwb-album-cell:focus-within \.iwb-album-zoom/.test(css))
|
||||||
|
ok('放大镜点击开查看器并带上 item 下标(整本相册可切换)',
|
||||||
|
/zoom\.addEventListener\('click',[\s\S]{0,120}openFull\(ctx, st, index\)/.test(src))
|
||||||
|
|
||||||
|
// 1.1.2:自带全屏查看器(宿主 onPreview 只收现成 URL 列表 ⇒ 整本要全转 dataURL,内存顶不住)
|
||||||
|
ok('查看器挂在 document.body(节点有 transform,inside 节点的 fixed 会错位)',
|
||||||
|
/document\.body\.appendChild\(root\)/.test(src))
|
||||||
|
ok('查看器自带左右按钮 + ← → 键盘切换',
|
||||||
|
/className:\s*'iwb-album-fs-nav prev'/.test(src) &&
|
||||||
|
/className:\s*'iwb-album-fs-nav next'/.test(src) &&
|
||||||
|
/e\.key === 'ArrowLeft'[\s\S]{0,120}go\(-1\)/.test(src) &&
|
||||||
|
/e\.key === 'ArrowRight'[\s\S]{0,120}go\(1\)/.test(src))
|
||||||
|
ok('循环切换(首尾相连,不会卡在最后一张)', /const go = \(delta\) => \{ cur = \(\(cur \+ delta\) % total \+ total\) % total/.test(src))
|
||||||
|
ok('点空白 / Esc 关闭', /if \(e\.target === root \|\| e\.target === bar\) close\(\)/.test(src) && /e\.key === 'Escape'[\s\S]{0,80}close\(\)/.test(src))
|
||||||
|
ok('原图只留 3 张(当前 + 左右预取),不整本缓存 4K dataURL',
|
||||||
|
/const FS_KEEP = 3/.test(src) && /cache\.size|keep = new Set\(\[keyAt\(cur\), keyAt\(cur \+ 1\), keyAt\(cur - 1\)\]\)/.test(src))
|
||||||
|
ok('先用缩略图占位再换原图(切页不闪黑)', /const thumb = st\.thumbs\.get\(keyAt\(i\)\) \|\| ''/.test(src))
|
||||||
|
ok('切页与预取并发去重(pending 表)', /const flight = pending\.get\(key\)/.test(src))
|
||||||
|
ok('键盘在捕获阶段吃掉(否则宿主把 ← → 当微调节点)',
|
||||||
|
/window\.addEventListener\('keydown', onKey, true\)/.test(src))
|
||||||
|
ok('关闭时摘掉键盘/滚轮监听(不残留全局监听)',
|
||||||
|
/removeEventListener\('keydown', v\.onKey, true\)/.test(src) && /removeEventListener\('wheel', v\.onWheel, true\)/.test(src))
|
||||||
|
ok('查看器层级在宿主预览层(800)之上', /\.iwb-album-fs\s*\{[^}]*z-index:\s*8[1-9][0-9]/.test(css))
|
||||||
|
ok('查看器带「复制 / 下载」(不因换查看器丢掉宿主预览原有能力)',
|
||||||
|
/iwb-album-fs-btn'/.test(src) && /'复制'/.test(src) && /'下载'/.test(src))
|
||||||
|
ok('复制转 PNG + 无 ClipboardItem 时走宿主原生通道',
|
||||||
|
/cv\.toBlob\([\s\S]{0,80}'image\/png'\)/.test(src) && /IWBDesktop[\s\S]{0,120}clipboardWriteImage/.test(src))
|
||||||
|
ok('查看器不再依赖宿主 props.onPreview(那接口要一次性给全 URL 列表)',
|
||||||
|
!/props\.onPreview\(/.test(src))
|
||||||
|
|
||||||
|
// ── 五、已修复的老 bug 必须有防回归断言 ───────────────────────
|
||||||
|
ok('批次角标彻底移除(右上角那个「1」是重复信息)',
|
||||||
|
!src.includes('iwb-album-batch') && !css.includes('iwb-album-batch'))
|
||||||
|
ok('不再有 img.src = \'\'(会向页面 URL 发空请求,控制台报 ERR_UNKNOWN_URL_SCHEME)',
|
||||||
|
!/\.src = ''/.test(src.split('\n').filter((l) => l.trim().indexOf('//') !== 0).join('\n')))
|
||||||
|
ok('跨页拖拽用「每页容量」换算,不用「本页格子数」',
|
||||||
|
/pageStart = pageNow \* capNow\.capacity/.test(src) && !/page \* cellCount/.test(src))
|
||||||
|
ok('删除不再硬编码跳回第 1 页', !/\{ items, page: 0 \}/.test(src) && /page: Math\.min\(pageNow, pagesNow - 1\)/.test(src))
|
||||||
|
ok('空节点不再显示「全部 0 张一页展示」(压着空态提示的废话)',
|
||||||
|
/const showOne = !showPager && items\.length > 0/.test(src))
|
||||||
|
ok('「文件夹」按钮不再 canReference() || true(不支持路径引用时点了没反应)',
|
||||||
|
!/\|\| true \? '' : 'none'/.test(src))
|
||||||
|
ok('addPaths 里没有 keep 死变量', !/const keep = \(st\.node\.data/.test(src))
|
||||||
|
ok('缩略图请求并发去重(st.pending,否则导入 30 张要解 60 次原图)',
|
||||||
|
/const flight = st\.pending && st\.pending\.get\(key\)/.test(src))
|
||||||
|
ok('缩略图预生成有进度(500 张导入时不会看起来卡死)', /st\.busy = '缩略图 '/.test(src))
|
||||||
|
ok('新导入后重置 checkedMissing', /function addPaths[\s\S]{0,900}st\.checkedMissing = false/.test(src))
|
||||||
|
|
||||||
|
// ── 六、宿主契约不能碰 ───────────────────────────────────────
|
||||||
|
ok('仍然只写 items / page / pageRange 这几个字段给宿主(不新增宿主不认识的键)',
|
||||||
|
/outKind: 'images'/.test(src) && /pageRange: wantRange/.test(src))
|
||||||
|
ok('只引用不复制:本地图仍写 { __file: 路径 }', /\{ __file: ref\.item\.path \}/.test(src))
|
||||||
|
ok('缩略图仍存宿主插件沙箱(ctx.files),不塞进节点数据',
|
||||||
|
/ctx\.files\.put\(name, thumb\)/.test(src) && !/thumbs[\s\S]{0,40}onUpdate/.test(src))
|
||||||
|
ok('没有引入 import/export(必须是经典脚本 IIFE,CSP script-src self)',
|
||||||
|
!/^\s*(import|export)\s/m.test(src) && /^;\(function \(global\)/m.test(src))
|
||||||
|
ok('样式只能 JS 内联注入之外的地方没有新增 <style> 标签', !/<style/.test(src))
|
||||||
|
|
||||||
|
console.log('\n' + (failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过'))
|
||||||
|
process.exit(failed ? 1 : 0)
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/* album 全屏查看器「真浏览器」冒烟(1.1.2)
|
||||||
|
*
|
||||||
|
* 为什么要单独跑:查看器是挂在 document.body 上的全局浮层 + 全局键盘/滚轮监听,
|
||||||
|
* 静态断言只能证明「代码里有这些字符串」,证明不了点开、切页、Esc/空白关闭真的能跑。
|
||||||
|
* 这里用 Chromium 装一个合成宿主,加载插件源码本体,走完整交互。
|
||||||
|
*
|
||||||
|
* 运行:node album/tools/viewer-e2e.mjs
|
||||||
|
* 依赖 playwright(宿主仓 node_modules;或 IWB_PLAYWRIGHT_ROOT 指定目录)。
|
||||||
|
* 不进 npm test:跨仓依赖,CI 上不一定装得齐。
|
||||||
|
*/
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { createRequire } from 'node:module'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const ROOT = path.resolve(HERE, '..')
|
||||||
|
const src = readFileSync(path.join(ROOT, 'src/index.js'), 'utf8')
|
||||||
|
const css = readFileSync(path.join(ROOT, 'styles.css'), 'utf8')
|
||||||
|
|
||||||
|
let chromium = null
|
||||||
|
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT,
|
||||||
|
'/Users/qiqi/open/github/image-workbench-desktop', ROOT]) {
|
||||||
|
if (!base) continue
|
||||||
|
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch (e) { /* 试下一个 */ }
|
||||||
|
}
|
||||||
|
if (!chromium) {
|
||||||
|
console.error('✗ 找不到 playwright:请安装,或设 IWB_PLAYWRIGHT_ROOT=/path/to/repo')
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, extra) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name + (cond ? '' : (' » ' + (extra == null ? '' : extra))))
|
||||||
|
}
|
||||||
|
|
||||||
|
const browser = await chromium.launch({ headless: true })
|
||||||
|
const page = await browser.newPage({ viewport: { width: 1100, height: 800 } })
|
||||||
|
page.on('pageerror', (e) => { failed++; console.log('✗ 页面脚本异常 » ' + e.message) })
|
||||||
|
await page.setContent('<!doctype html><html><head><meta charset="utf-8"></head><body style="margin:0"><div id="host" style="width:300px;height:470px;position:relative"></div></body></html>')
|
||||||
|
await page.addStyleTag({ content: css })
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const colors = ['#e57373', '#81c784', '#64b5f6', '#ffd54f', '#ba68c8']
|
||||||
|
window.__urls = colors.map((c) => 'data:image/svg+xml;base64,' + btoa(
|
||||||
|
'<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><rect width="60" height="60" fill="' + c + '"/></svg>'))
|
||||||
|
window.__items = window.__urls.map((u, i) => ({ src: u, name: '图' + (i + 1) + '.svg', on: true }))
|
||||||
|
window.IWBPluginHost = {
|
||||||
|
register (meta, factory) {
|
||||||
|
window.__meta = meta
|
||||||
|
const ctx = {
|
||||||
|
nodes: { register (spec) { window.__spec = spec } },
|
||||||
|
images: {
|
||||||
|
canReference: () => false,
|
||||||
|
dataUrl: async (v) => String(v || ''),
|
||||||
|
thumb: () => '',
|
||||||
|
pick: async () => [],
|
||||||
|
stat: async () => ({ ok: true, exists: true }),
|
||||||
|
listImages: async () => [],
|
||||||
|
},
|
||||||
|
files: { get: async () => ({ ok: false }), put: async () => ({ ok: true }) },
|
||||||
|
settings: { get: () => true },
|
||||||
|
}
|
||||||
|
window.__ctx = ctx
|
||||||
|
factory(ctx)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await page.addScriptTag({ content: src })
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.__render = (items) => {
|
||||||
|
// 不清 host:宿主每次重渲染复用同一个容器,插件靠 STATE 增量更新;
|
||||||
|
// 这里手动清空会把插件的 root 摘掉,STATE 还拿着游离节点 ⇒ 界面空白(测试自身不能造这种场景)
|
||||||
|
const host = document.getElementById('host')
|
||||||
|
const node = { id: 'n1', w: 300, h: 470, data: { outKind: 'images', items: items, albumMode: 'per-image', density: 'S', page: 0, onlyPage: false } }
|
||||||
|
const props = { onUpdate () {}, onSnapshot () {}, onPreview (u) { window.__hostPreview = u } }
|
||||||
|
window.__spec.render(node, props, host)
|
||||||
|
}
|
||||||
|
window.__render(window.__items)
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
await page.waitForFunction(() => document.querySelectorAll('.iwb-album-cell').length >= 5, null, { timeout: 10000 })
|
||||||
|
} catch (e) {
|
||||||
|
console.log('DEBUG host =', (await page.evaluate(() => document.getElementById('host').innerHTML)).slice(0, 1200))
|
||||||
|
console.log('DEBUG meta =', await page.evaluate(() => JSON.stringify(window.__meta)))
|
||||||
|
console.log('DEBUG spec =', await page.evaluate(() => String(window.__spec && window.__spec.id)))
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1) 点放大镜 → 全屏查看器
|
||||||
|
await page.locator('.iwb-album-zoom').first().click({ force: true })
|
||||||
|
await page.waitForFunction(() => document.querySelectorAll('.iwb-album-fs').length === 1)
|
||||||
|
ok('点放大镜开出全屏查看器', true)
|
||||||
|
ok('计数显示 1 / 5', await page.locator('.iwb-album-fs-count').textContent() === '1 / 5')
|
||||||
|
ok('原图异步换上(不是只显示缩略图)', await page.waitForFunction(
|
||||||
|
() => { const im = document.querySelector('.iwb-album-fs img'); return !!im && (im.getAttribute('src') || '').indexOf('data:image/svg+xml') === 0 },
|
||||||
|
null, { timeout: 5000 }).then(() => true).catch(() => false))
|
||||||
|
ok('左右箭头按钮都渲染出来了', await page.locator('.iwb-album-fs-nav').count() === 2)
|
||||||
|
|
||||||
|
// 2) 键盘切换(含首尾循环)
|
||||||
|
await page.keyboard.press('ArrowRight')
|
||||||
|
ok('→ 切到第 2 张', await page.locator('.iwb-album-fs-count').textContent() === '2 / 5')
|
||||||
|
await page.keyboard.press('ArrowLeft')
|
||||||
|
await page.keyboard.press('ArrowLeft')
|
||||||
|
ok('← 从第 1 张循环到最后一张', await page.locator('.iwb-album-fs-count').textContent() === '5 / 5')
|
||||||
|
await page.keyboard.press('ArrowRight')
|
||||||
|
ok('再从最后一张循环回第 1 张', await page.locator('.iwb-album-fs-count').textContent() === '1 / 5')
|
||||||
|
|
||||||
|
// 3) 按钮 / 滚轮切换
|
||||||
|
await page.locator('.iwb-album-fs-nav.next').click()
|
||||||
|
ok('下一张按钮生效', await page.locator('.iwb-album-fs-count').textContent() === '2 / 5')
|
||||||
|
await page.mouse.move(550, 400)
|
||||||
|
await page.mouse.wheel(0, 120)
|
||||||
|
await page.waitForTimeout(80)
|
||||||
|
ok('滚轮向下切一张', await page.locator('.iwb-album-fs-count').textContent() === '3 / 5')
|
||||||
|
|
||||||
|
// 3b) 宿主预览原有的「复制 / 下载」能力不能丢
|
||||||
|
ok('查看器带复制 / 下载按钮', await page.locator('.iwb-album-fs-btn').count() === 2)
|
||||||
|
await page.locator('.iwb-album-fs-btn').nth(1).click()
|
||||||
|
ok('点下载不会把查看器关掉', await page.locator('.iwb-album-fs').count() === 1)
|
||||||
|
await page.locator('.iwb-album-fs-btn').first().click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
ok('点复制不会报错 / 不关闭(无剪贴板权限时也只给提示)', await page.locator('.iwb-album-fs').count() === 1)
|
||||||
|
|
||||||
|
// 4) 点空白关闭;键盘监听要摘干净(关掉后再按 → 不能影响画布)
|
||||||
|
await page.mouse.click(8, 8)
|
||||||
|
ok('点图片外的空白关闭', await page.locator('.iwb-album-fs').count() === 0)
|
||||||
|
ok('关闭后画布没有被误删格子', await page.locator('.iwb-album-cell').count() === 6)
|
||||||
|
await page.locator('.iwb-album-zoom').first().click({ force: true })
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
ok('Esc 关闭', await page.locator('.iwb-album-fs').count() === 0)
|
||||||
|
await page.keyboard.press('ArrowRight')
|
||||||
|
ok('关闭后不再残留键盘监听(→ 不报错、不重建浮层)', await page.locator('.iwb-album-fs').count() === 0)
|
||||||
|
|
||||||
|
// 5) 只有一张图时不显示左右按钮
|
||||||
|
await page.evaluate(() => window.__render([window.__items[0]]))
|
||||||
|
try {
|
||||||
|
await page.waitForFunction(() => document.querySelectorAll('.iwb-album-cell').length === 2, null, { timeout: 5000 })
|
||||||
|
} catch (e) {
|
||||||
|
console.log('DEBUG single host =', (await page.evaluate(() => document.getElementById('host').innerHTML)).slice(0, 600))
|
||||||
|
console.log('DEBUG cells =', await page.evaluate(() => document.querySelectorAll('.iwb-album-cell').length))
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
await page.locator('.iwb-album-zoom').first().click({ force: true })
|
||||||
|
const single = await page.evaluate(() => {
|
||||||
|
const root = document.querySelector('.iwb-album-fs')
|
||||||
|
const nav = document.querySelector('.iwb-album-fs-nav')
|
||||||
|
return { cls: root && root.className, display: nav ? getComputedStyle(nav).display : 'missing' }
|
||||||
|
})
|
||||||
|
ok('单图查看器隐藏左右按钮', (single.cls || '').indexOf('single') >= 0 && single.display === 'none', JSON.stringify(single))
|
||||||
|
ok('单图计数 1 / 1', await page.locator('.iwb-album-fs-count').textContent() === '1 / 1')
|
||||||
|
await page.mouse.click(8, 8)
|
||||||
|
|
||||||
|
// 6) 查看器挂到 body(不是节点里),事件不会穿透到画布
|
||||||
|
const inBody = await page.evaluate(() => {
|
||||||
|
window.__render(window.__items)
|
||||||
|
document.querySelector('.iwb-album-zoom').click()
|
||||||
|
const root = document.querySelector('.iwb-album-fs')
|
||||||
|
return !!root && root.parentNode === document.body
|
||||||
|
})
|
||||||
|
ok('浮层挂在 document.body(不受节点 transform 影响)', inBody)
|
||||||
|
ok('开启查看器没有走宿主 props.onPreview', await page.evaluate(() => typeof window.__hostPreview === 'undefined'))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
|
||||||
|
await browser.close()
|
||||||
|
console.log('\n' + (failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过'))
|
||||||
|
process.exit(failed ? 1 : 0)
|
||||||
@@ -95,15 +95,9 @@ mock 宿主 + 真实 Chromium,覆盖:manifest / 面板注册与挂载 / 列
|
|||||||
|
|
||||||
需要 Playwright(可从桌面仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定)+ 系统 `unzip`、`python3`,不进 CI。
|
需要 Playwright(可从桌面仓 `node_modules` 解析,或 `IWB_PLAYWRIGHT_ROOT` 指定)+ 系统 `unzip`、`python3`,不进 CI。
|
||||||
|
|
||||||
**发布后必须再跑一次真机**(mock 抓不到宿主 CSS / 真实 CSP / 真实面板挂载):
|
harness 用真实 Chromium 注入宿主 CSS 变量与 CSP 约束,覆盖面板挂载、勾选框与文字同行
|
||||||
|
(1.0.1 修的就是这个:`.iwb-bx-f input{width:100%}` 把 checkbox 撑满整行)、队列跑通、
|
||||||
```bash
|
下载 ZIP + python3 校验条目 / CRC / PNG·JPEG magic / UTF-8 名。发布后在客户端市场里确认版本与加载状态即可。
|
||||||
node batch-export/tools/e2e-site.mjs
|
|
||||||
```
|
|
||||||
|
|
||||||
覆盖:市场安装加载 + SRI + 资源中心 tab 出现 + 面板挂载 + 列表 2 行 +
|
|
||||||
**勾选框与文字同行(1.0.1 修的就是这个:`.iwb-bx-f input{width:100%}` 把 checkbox 撑满整行)** +
|
|
||||||
队列跑通 + 下载 ZIP + python3 校验 4 条目 / CRC / PNG·JPEG magic / UTF-8 名。
|
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/batch-export",
|
"name": "@iwb-plugin/batch-export",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "batch-export",
|
"id": "batch-export",
|
||||||
|
|||||||
+20
-10
@@ -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/*iwb:content*/;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:content*/}',
|
'.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.1',
|
version: '1.2.2',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'canvas'],
|
capabilities: ['panels', 'canvas'],
|
||||||
settings: {
|
settings: {
|
||||||
|
|||||||
@@ -1,282 +0,0 @@
|
|||||||
// 真实站点端到端(开发用,不进 CI)—— batch-export「批量出图」。
|
|
||||||
//
|
|
||||||
// 为什么需要它:harness.mjs 用的是 mock 宿主,面板样式与真实宿主 CSS 变量、真实 CSP、真实
|
|
||||||
// 画布桥都不会被执行到。发布后跑一遍这个脚本,能抓到 mock 里永远绿的问题 ——
|
|
||||||
// 例如 `.iwb-bx-f input{width:100%}` 把 checkbox 撑满整行、把标签挤到面板最右(1.0.0 首次发布即中招)。
|
|
||||||
//
|
|
||||||
// 它不 mock /plugins/*:走真实 KV 加载 + 浏览器 SRI(fail-closed)+ 真实资源中心面板挂载。
|
|
||||||
//
|
|
||||||
// 运行(需要 Playwright + python3):
|
|
||||||
// node batch-export/tools/e2e-site.mjs # 默认测试站
|
|
||||||
// IWB_BASE_URL=https://iwb.maqiart.eu.org node batch-export/tools/e2e-site.mjs # 正式站
|
|
||||||
// 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定)。
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { execFileSync } from 'node:child_process'
|
|
||||||
import { readFileSync, existsSync, statSync } from 'node:fs'
|
|
||||||
import path from 'node:path'
|
|
||||||
import os from 'node:os'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/batch-export/tools
|
|
||||||
const REPO = path.resolve(HERE, '../..') // <repo>
|
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
|
||||||
|
|
||||||
let chromium = null
|
|
||||||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
|
||||||
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ }
|
|
||||||
}
|
|
||||||
if (!chromium) {
|
|
||||||
console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT:')
|
|
||||||
console.error(' IWB_PLAYWRIGHT_ROOT=/path/to/repo node batch-export/tools/e2e-site.mjs')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE = process.env.IWB_BASE_URL || 'https://test.image-workbench-web.pages.dev'
|
|
||||||
const WANT_VERSION = JSON.parse(readFileSync(path.join(REPO, 'batch-export/package.json'), 'utf8')).version
|
|
||||||
const ZIP_OUT = path.join(os.tmpdir(), 'iwb-batch-e2e.zip')
|
|
||||||
|
|
||||||
let failed = 0
|
|
||||||
const check = (name, ok, detail) => {
|
|
||||||
if (!ok) failed++
|
|
||||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('目标站点:' + BASE + '(期望插件版本 ' + WANT_VERSION + ')')
|
|
||||||
const browser = await chromium.launch()
|
|
||||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, acceptDownloads: true })
|
|
||||||
const consoleErrors = []
|
|
||||||
page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) })
|
|
||||||
page.on('pageerror', (e) => consoleErrors.push('pageerror: ' + e.message))
|
|
||||||
|
|
||||||
// 造两张 200×120 的参考图(非正方形,等比缩放/居中被真正练到)
|
|
||||||
await page.goto('about:blank')
|
|
||||||
const PNG = await page.evaluate(() => {
|
|
||||||
const c = document.createElement('canvas')
|
|
||||||
c.width = 200; c.height = 120
|
|
||||||
const x = c.getContext('2d')
|
|
||||||
x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 200, 120)
|
|
||||||
return c.toDataURL('image/png')
|
|
||||||
})
|
|
||||||
|
|
||||||
// 插件系统是 opt-in(新插件默认不启用),种子必须显式 enabled
|
|
||||||
await page.addInitScript((d) => {
|
|
||||||
localStorage.clear()
|
|
||||||
localStorage.setItem('iwb_web_cfg', JSON.stringify({ providers: [], canvas: {} }))
|
|
||||||
const ws = {
|
|
||||||
workspaces: [{
|
|
||||||
id: 'w1', name: 'W',
|
|
||||||
nodes: [
|
|
||||||
{ id: 'r1', type: 'ref', x: 140, y: 140, data: { url: '', data: d.png, name: '菜单A.png', localName: null } },
|
|
||||||
{ id: 'r2', type: 'ref', x: 460, y: 140, data: { url: '', data: d.png, name: '菜单B.png', localName: null } },
|
|
||||||
],
|
|
||||||
edges: [], groups: [],
|
|
||||||
}],
|
|
||||||
activeId: 'w1', rev: 1,
|
|
||||||
}
|
|
||||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
|
||||||
localStorage.setItem('iwb_ws_active', ws.activeId)
|
|
||||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0]))
|
|
||||||
localStorage.setItem('iwb_web_outputs', JSON.stringify([]))
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'batch-export': { enabled: true, settings: {}, data: {} } }))
|
|
||||||
}, { png: PNG })
|
|
||||||
|
|
||||||
// ---------- 1) 站点可达 ----------
|
|
||||||
const resp = await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' })
|
|
||||||
check('站点可达', Boolean(resp && resp.ok()), resp && String(resp.status()))
|
|
||||||
|
|
||||||
// ---------- 2) 真实 KV 加载 + 启用 ----------
|
|
||||||
await page.waitForFunction(() => window.IWBPluginHost && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 30000 })
|
|
||||||
await page.waitForFunction(() => window.IWBPluginHost.list().some((x) => x.id === 'batch-export'), null, { timeout: 20000 })
|
|
||||||
const info = await page.evaluate(() => {
|
|
||||||
const p = window.IWBPluginHost.list().find((x) => x.id === 'batch-export')
|
|
||||||
return p ? { version: p.version, enabled: p.enabled, active: p.active, capabilities: p.capabilities, error: p.error } : null
|
|
||||||
})
|
|
||||||
check('从真实 KV 加载并启用(active)', Boolean(info && info.active && info.enabled && !info.error), JSON.stringify(info))
|
|
||||||
check('线上版本 = batch-export/package.json(' + WANT_VERSION + ')', Boolean(info && info.version === WANT_VERSION), info && info.version)
|
|
||||||
|
|
||||||
// ---------- 3) 面板 tab ----------
|
|
||||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
|
||||||
await page.locator('.iwb-canvas:not(.iwb-canvas-hidden)').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
check('画布打开、2 个 ref 节点', (await page.locator('.iwb-node[data-node-id^="r"]').count()) === 2)
|
|
||||||
await page.locator('button[title^="资源中心"]').first().click()
|
|
||||||
const tab = page.locator('.iwb-res-tab', { hasText: '批量出图' })
|
|
||||||
check('资源中心出现「批量出图」tab', (await tab.count()) >= 1)
|
|
||||||
await tab.first().click()
|
|
||||||
await page.waitForTimeout(1200)
|
|
||||||
const mounted = await page.locator('.iwb-full-panel-plugin').count()
|
|
||||||
check('面板已挂载(真实宿主容器)', mounted >= 1)
|
|
||||||
// 宿主 .iwb-full-main 是 flex 行容器,只给图库/节点组容器 width:100%;插件容器不撑满就会按内容收缩
|
|
||||||
const widthInfo = await page.evaluate(() => {
|
|
||||||
const main = document.querySelector('.iwb-full-main')
|
|
||||||
const box = document.querySelector('.iwb-bx')
|
|
||||||
return {
|
|
||||||
main: main ? Math.round(main.clientWidth) : 0,
|
|
||||||
box: box ? Math.round(box.clientWidth) : 0,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('面板撑满内容区宽度(不按内容收缩)',
|
|
||||||
widthInfo.main > 0 && widthInfo.box >= widthInfo.main - 2, JSON.stringify(widthInfo))
|
|
||||||
const rows = await page.locator('.iwb-bx-item').count()
|
|
||||||
check('面板列出 2 个 ref 节点', rows === 2, 'rows=' + rows)
|
|
||||||
|
|
||||||
// 1.0.0 首发的真实 bug:checkbox 被 .iwb-bx-f input{width:100%} 撑满整行,标签被挤到最右
|
|
||||||
const chk = await page.evaluate(() => {
|
|
||||||
const lab = document.querySelector('.iwb-bx-rowchk')
|
|
||||||
if (!lab) return null
|
|
||||||
const input = lab.querySelector('input[type=checkbox]')
|
|
||||||
const span = lab.querySelector('span')
|
|
||||||
if (!input || !span) return null
|
|
||||||
const a = input.getBoundingClientRect()
|
|
||||||
const b = span.getBoundingClientRect()
|
|
||||||
return { gap: Math.round(b.left - a.right), sameLine: Math.abs(a.top - b.top) < 12, inputW: Math.round(a.width) }
|
|
||||||
})
|
|
||||||
check('「走本地鲜艺抠图」勾选框与文字同行且紧邻', Boolean(chk && chk.sameLine && chk.gap >= 0 && chk.gap <= 12 && chk.inputW <= 24), JSON.stringify(chk))
|
|
||||||
const cutLabel = await page.evaluate(() => {
|
|
||||||
const s = document.querySelector('.iwb-bx-rowchk span')
|
|
||||||
return s ? s.textContent.trim() : ''
|
|
||||||
})
|
|
||||||
check('抠图开关文案写明「本地鲜艺抠图」+ 端口', /鲜艺/.test(cutLabel) && /30092/.test(cutLabel), cutLabel)
|
|
||||||
|
|
||||||
// 1.1.0:配置区与列表之间要有明显的隔断(灰底小节头),操作按钮归到列表区
|
|
||||||
const sec = await page.evaluate(() => {
|
|
||||||
const s = document.querySelector('.iwb-bx-sec')
|
|
||||||
if (!s) return null
|
|
||||||
const bar = document.querySelector('.iwb-bx-bar')
|
|
||||||
const a = s.getBoundingClientRect()
|
|
||||||
const b = bar.getBoundingClientRect()
|
|
||||||
return {
|
|
||||||
text: (s.textContent || '').trim().slice(0, 24),
|
|
||||||
btns: Array.from(s.querySelectorAll('button')).map((x) => x.textContent.trim()),
|
|
||||||
bg: getComputedStyle(s).backgroundColor,
|
|
||||||
belowConfig: a.top >= b.bottom - 1,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('隔断:「待处理节点」小节头在配置区正下方,带灰底 + 全选/清空/刷新',
|
|
||||||
Boolean(sec && sec.belowConfig && sec.text.indexOf('待处理节点') === 0 &&
|
|
||||||
JSON.stringify(sec.btns) === JSON.stringify(['全选', '清空', '刷新']) && sec.bg !== 'rgba(0, 0, 0, 0)'),
|
|
||||||
JSON.stringify(sec))
|
|
||||||
|
|
||||||
// 1.1.0:缩略图必须**跑之前**就在(30px 显示 / 64px 源图)
|
|
||||||
if (rows) {
|
|
||||||
const preThumb = await page.evaluate(() => {
|
|
||||||
const imgs = Array.from(document.querySelectorAll('.iwb-bx-item img.iwb-bx-thumb'))
|
|
||||||
return { n: imgs.length, w: imgs[0] ? imgs[0].naturalWidth : 0, cssW: imgs[0] ? Math.round(imgs[0].getBoundingClientRect().width) : 0 }
|
|
||||||
})
|
|
||||||
check('列表行首常驻源图缩略图(2 张、64px 位图 / 30px 显示)',
|
|
||||||
preThumb.n === 2 && preThumb.w === 64 && preThumb.cssW === 30, JSON.stringify(preThumb))
|
|
||||||
|
|
||||||
// 1.1.0 的 bug:「清空」后勾选框视觉上仍勾着(el() 用 setAttribute('checked','false'))
|
|
||||||
await page.getByRole('button', { name: '清空', exact: true }).click()
|
|
||||||
const cleared = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-bx-item input[type=checkbox]')).map((c) => c.checked))
|
|
||||||
check('「清空」真的取消勾选', cleared.length === 2 && cleared.every((v) => v === false), JSON.stringify(cleared))
|
|
||||||
await page.getByRole('button', { name: '全选', exact: true }).click()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- 4) 跑队列 ----------
|
|
||||||
if (!rows) {
|
|
||||||
console.log('\n' + (await page.locator('.iwb-full-panel-plugin').first().innerText()))
|
|
||||||
} else {
|
|
||||||
await page.getByRole('button', { name: '全选', exact: true }).click()
|
|
||||||
await page.getByRole('button', { name: '开始出图', exact: true }).click()
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const b = Array.from(document.querySelectorAll('button')).find((x) => x.textContent.trim() === '导出 ZIP')
|
|
||||||
return b && !b.disabled
|
|
||||||
}, null, { timeout: 120000 })
|
|
||||||
const fails = await page.locator('.iwb-bx-item', { hasText: '失败' }).count()
|
|
||||||
check('队列跑完、无失败项', fails === 0, 'fail=' + fails)
|
|
||||||
|
|
||||||
// 跑完必须「看得见图」:行内缩略图 + 一条说明产物在哪的提示条(1.0.1 之前只有一行文字,用户以为没产出)
|
|
||||||
const thumbs = await page.locator('.iwb-bx-thumb').count()
|
|
||||||
check('行内显示产物缩略图(2 张)', thumbs === 2, 'thumbs=' + thumbs)
|
|
||||||
const thumbOk = thumbs ? await page.evaluate(() => {
|
|
||||||
const im = document.querySelector('.iwb-bx-thumb')
|
|
||||||
return { src: String(im.getAttribute('src') || '').slice(0, 5), w: im.naturalWidth, h: im.naturalHeight }
|
|
||||||
}) : null
|
|
||||||
check('缩略图是真解码出来的位图(800×800)', Boolean(thumbOk && thumbOk.src === 'blob:' && thumbOk.w === 800 && thumbOk.h === 800), JSON.stringify(thumbOk))
|
|
||||||
|
|
||||||
// ---------- 4.5) 行内单张下载(1.2.0):不依赖 ZIP,产物在内存里直接落盘 ----------
|
|
||||||
const dlState = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-bx-item .iwb-bx-dl')).map((b) => ({
|
|
||||||
text: b.textContent, disabled: b.disabled, title: b.title,
|
|
||||||
})))
|
|
||||||
check('行内下载:每行 JPG / PNG 各一个(2 行 = 4 个)',
|
|
||||||
dlState.length === 4 && dlState[0].text === 'JPG' && dlState[1].text === 'PNG',
|
|
||||||
JSON.stringify(dlState.map((b) => b.text)))
|
|
||||||
check('行内下载:双版本跑完后全部可点', dlState.every((b) => b.disabled === false), JSON.stringify(dlState.map((b) => b.disabled)))
|
|
||||||
const [jpgDl] = await Promise.all([
|
|
||||||
page.waitForEvent('download', { timeout: 30000 }),
|
|
||||||
page.locator('.iwb-bx-item').first().locator('.iwb-bx-dl').first().click(),
|
|
||||||
])
|
|
||||||
check('行内下载:点 JPG 直接下载单张(不必先导出 ZIP)',
|
|
||||||
/\.jpg$/.test(jpgDl.suggestedFilename()), jpgDl.suggestedFilename())
|
|
||||||
const doneText = await page.locator('.iwb-bx-done').first().innerText()
|
|
||||||
check('完成提示条说明「已生成 → 点导出 ZIP」(不写入画布)', /已生成 4 个文件/.test(doneText) && /导出 ZIP/.test(doneText) && /不写入画布/.test(doneText), doneText)
|
|
||||||
// 1.0.2 的坑:.iwb-bx-btn-hot 与 .iwb-bx-btn 同特异性且定义在前,背景被覆盖 → 高亮没生效
|
|
||||||
const zipBg = await page.evaluate(() => {
|
|
||||||
const b = Array.from(document.querySelectorAll('button')).find((x) => x.textContent.trim() === '导出 ZIP')
|
|
||||||
return b ? getComputedStyle(b).backgroundColor : ''
|
|
||||||
})
|
|
||||||
check('导出按钮转为高亮(rgb(29,158,117))', zipBg === 'rgb(29, 158, 117)', zipBg)
|
|
||||||
|
|
||||||
// ---------- 5) 导出 ZIP 并用 python3 校验(系统 unzip 对 UTF-8 名会乱码,见 README) ----------
|
|
||||||
const [download] = await Promise.all([
|
|
||||||
page.waitForEvent('download', { timeout: 60000 }),
|
|
||||||
page.getByRole('button', { name: '导出 ZIP', exact: true }).click(),
|
|
||||||
])
|
|
||||||
await download.saveAs(ZIP_OUT)
|
|
||||||
check('ZIP 已下载', existsSync(ZIP_OUT), existsSync(ZIP_OUT) ? statSync(ZIP_OUT).size + ' bytes' : '缺失')
|
|
||||||
const doneAfter = await page.locator('.iwb-bx-done').first().innerText()
|
|
||||||
check('导出后提示条显示已下载的文件名', /已下载 batch_.*\.zip/.test(doneAfter), doneAfter)
|
|
||||||
try {
|
|
||||||
const report = execFileSync('python3', ['-c', `
|
|
||||||
import zipfile, sys
|
|
||||||
z = zipfile.ZipFile(sys.argv[1])
|
|
||||||
assert z.testzip() is None, 'CRC 损坏'
|
|
||||||
for i in z.infolist():
|
|
||||||
b = z.read(i.filename)
|
|
||||||
ext = i.filename.rsplit('.', 1)[-1]
|
|
||||||
ok = b[:4] == b'\\x89PNG' if ext == 'png' else b[:3] == b'\\xff\\xd8\\xff'
|
|
||||||
print('%-28s %7dB %s %s' % (i.filename, i.file_size, '格式OK' if ok else '格式BAD', 'utf8' if i.flag_bits & 0x800 else 'nomb'))
|
|
||||||
`, ZIP_OUT], { encoding: 'utf8' })
|
|
||||||
console.log(report.trim())
|
|
||||||
const lines = report.trim().split('\n').filter(Boolean)
|
|
||||||
check('ZIP 4 个条目(2 张 × 双版本)', lines.length === 4, 'entries=' + lines.length)
|
|
||||||
check('ZIP 条目格式与 UTF-8 文件名标记正确', lines.every((l) => /格式OK/.test(l) && /utf8/.test(l)))
|
|
||||||
check('双版本命名 <原名>_800x800.png/.jpg', lines.some((l) => /菜单A_800x800\.png/.test(l)) && lines.some((l) => /菜单A_800x800\.jpg/.test(l)))
|
|
||||||
} catch (e) {
|
|
||||||
check('ZIP 结构校验(python3)', false, String((e && e.stdout) || (e && e.message)).slice(0, 200))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- 6) 切到「图库 / 节点组」时不得串页(1.1.0) ----------
|
|
||||||
// 真机现象:切到「图库」后批量面板还压在图片上方 —— 宿主两端都渲染成 div 且无 key,
|
|
||||||
// React 复用同一 DOM 节点,只清理自己管理的子节点,插件 mount 进去的根节点留在原地。
|
|
||||||
const clickedGallery = await page.evaluate(() => {
|
|
||||||
const t = Array.from(document.querySelectorAll('.iwb-res-tab')).find((x) => /图库/.test(x.textContent))
|
|
||||||
if (t) t.click()
|
|
||||||
return Boolean(t)
|
|
||||||
})
|
|
||||||
await page.waitForTimeout(1200)
|
|
||||||
const gallery = await page.evaluate(() => ({
|
|
||||||
historyMounted: document.querySelectorAll('.iwb-history-embedded').length,
|
|
||||||
panelsInDom: document.querySelectorAll('.iwb-bx').length,
|
|
||||||
panelInsideHistory: Boolean(document.querySelector('.iwb-history-embedded .iwb-bx')),
|
|
||||||
}))
|
|
||||||
check('切到「图库」:批量面板自动摘除,图库内不再混入插件 DOM',
|
|
||||||
clickedGallery && gallery.historyMounted >= 1 && gallery.panelsInDom === 0 && gallery.panelInsideHistory === false,
|
|
||||||
JSON.stringify(gallery))
|
|
||||||
|
|
||||||
await page.locator('.iwb-res-tab', { hasText: '批量出图' }).first().click()
|
|
||||||
await page.waitForTimeout(1500)
|
|
||||||
const backRows = await page.locator('.iwb-bx-item').count()
|
|
||||||
const backThumbs = await page.locator('.iwb-bx-item img.iwb-bx-thumb').count()
|
|
||||||
check('切回「批量出图」:面板自动重新挂载、列表与缩略图仍在',
|
|
||||||
backRows === 2 && backThumbs === 2, 'rows=' + backRows + ' thumbs=' + backThumbs)
|
|
||||||
|
|
||||||
// ---------- 7) 无 CSP / SRI 拦截、无页面错误 ----------
|
|
||||||
const bad = consoleErrors.filter((t) => /Content Security Policy|integrity|Refused to (execute|load|connect)/i.test(t))
|
|
||||||
check('无 CSP / SRI 拦截报错', bad.length === 0, bad.slice(0, 2).join(' | '))
|
|
||||||
check('无页面级运行时错误', consoleErrors.length === 0, consoleErrors.slice(0, 3).join(' | '))
|
|
||||||
|
|
||||||
await browser.close()
|
|
||||||
console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过'))
|
|
||||||
process.exit(failed ? 1 : 0)
|
|
||||||
@@ -16,7 +16,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/batch-export/tools
|
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/batch-export/tools
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
|
||||||
let chromium = null
|
let chromium = null
|
||||||
|
|||||||
@@ -163,7 +163,7 @@
|
|||||||
|
|
||||||
// 把网址放到画布上:新建一个「网页」节点并带上地址(宿主 canvasWrite 能力)。
|
// 把网址放到画布上:新建一个「网页」节点并带上地址(宿主 canvasWrite 能力)。
|
||||||
// 宿主 createNode 认变体 id('web')—— 不在内置 NODE_TYPES 里时会自动走 addPluginNode。
|
// 宿主 createNode 认变体 id('web')—— 不在内置 NODE_TYPES 里时会自动走 addPluginNode。
|
||||||
// 返回 false 表示这个宿主没提供该能力(旧客户端 / 网页版),调用方自己选退路。
|
// 返回 false 表示这个宿主没提供该能力(旧客户端),调用方自己选退路。
|
||||||
function toCanvasNode(ctx, raw) {
|
function toCanvasNode(ctx, raw) {
|
||||||
var url = normalizeUrl(raw)
|
var url = normalizeUrl(raw)
|
||||||
if (!url) return false
|
if (!url) return false
|
||||||
@@ -647,9 +647,9 @@
|
|||||||
setZoom(st, clampZoom(pz0 / 100), false)
|
setZoom(st, clampZoom(pz0 / 100), false)
|
||||||
st.empty.textContent = '在上方地址栏输入网址,网页会显示在这里'
|
st.empty.textContent = '在上方地址栏输入网址,网页会显示在这里'
|
||||||
// 面板内浏览同样要靠宿主的原生 webview 引擎(src/canvas-webview.js):
|
// 面板内浏览同样要靠宿主的原生 webview 引擎(src/canvas-webview.js):
|
||||||
// 没有它(网页版 / 旧客户端)就是一块白板,必须说清原因而不是干等。
|
// 没有它(旧客户端 / 合成测试宿主)就是一块白板,必须说清原因而不是干等。
|
||||||
var hasEngine = !!(global.IWBCanvasWebview || (global.window && global.window.IWBCanvasWebview))
|
var hasEngine = !!(global.IWBCanvasWebview || (global.window && global.window.IWBCanvasWebview))
|
||||||
if (!invoke()) st.empty.textContent = '面板内浏览需要桌面客户端;网页版请用系统浏览器打开。'
|
if (!invoke()) st.empty.textContent = '面板内浏览需要桌面客户端;请用系统浏览器打开。'
|
||||||
else if (!hasEngine) st.empty.textContent = '当前客户端还没有面板内浏览能力(需要 v3.25.30 及以上)。\n请先更新客户端。'
|
else if (!hasEngine) st.empty.textContent = '当前客户端还没有面板内浏览能力(需要 v3.25.30 及以上)。\n请先更新客户端。'
|
||||||
// 面板关掉就没了,「✕ 关闭这个网页」在面板里没有意义
|
// 面板关掉就没了,「✕ 关闭这个网页」在面板里没有意义
|
||||||
st.close.style.display = 'none'
|
st.close.style.display = 'none'
|
||||||
@@ -930,7 +930,7 @@
|
|||||||
st.empty.textContent = '在地址栏输入网址,网页会显示在这个节点里'
|
st.empty.textContent = '在地址栏输入网址,网页会显示在这个节点里'
|
||||||
} else if (!supported) {
|
} else if (!supported) {
|
||||||
st.empty.style.display = ''
|
st.empty.style.display = ''
|
||||||
st.empty.textContent = '画布内网页需要桌面客户端;网页版请用左侧「浏览器」面板。'
|
st.empty.textContent = '画布内网页需要桌面客户端;请用左侧「浏览器」面板。'
|
||||||
} else if (!engine) {
|
} else if (!engine) {
|
||||||
st.empty.style.display = ''
|
st.empty.style.display = ''
|
||||||
st.empty.textContent = '当前客户端还没有画布内网页能力(需要 v3.25.29 及以上)。\n请先更新客户端;升级前可以点上方 ↗ 用「浏览器」面板打开。'
|
st.empty.textContent = '当前客户端还没有画布内网页能力(需要 v3.25.29 及以上)。\n请先更新客户端;升级前可以点上方 ↗ 用「浏览器」面板打开。'
|
||||||
|
|||||||
@@ -504,7 +504,7 @@ const okInvoke = () => (name) => {
|
|||||||
nt.render({ id: 'n2', data: { url: 'https://www.baidu.com/' } }, { onUpdate() {} }, host)
|
nt.render({ id: 'n2', data: { url: 'https://www.baidu.com/' } }, { onUpdate() {} }, host)
|
||||||
const stage = host.children.find((c) => c.className === 'iwb-cwv-stage')
|
const stage = host.children.find((c) => c.className === 'iwb-cwv-stage')
|
||||||
const empty = stage.children.find((c) => c.className === 'iwb-cwv-empty')
|
const empty = stage.children.find((c) => c.className === 'iwb-cwv-empty')
|
||||||
check('网页版节点显示「需要桌面客户端」提示', /桌面客户端/.test(empty._text), empty._text)
|
check('旧客户端节点显示「需要桌面客户端」提示', /桌面客户端/.test(empty._text), empty._text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 旧客户端(有 Tauri、但没有画布 webview 引擎)必须提示升级 ----------
|
// ---------- 旧客户端(有 Tauri、但没有画布 webview 引擎)必须提示升级 ----------
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/gallery",
|
"name": "@iwb-plugin/gallery",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.6.9",
|
"version": "1.7.2",
|
||||||
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
|
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "gallery",
|
"id": "gallery",
|
||||||
|
|||||||
+64
-12
@@ -1,8 +1,17 @@
|
|||||||
// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里)
|
// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里)
|
||||||
//
|
//
|
||||||
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove)+ panels。
|
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove/onChanged)+ panels。
|
||||||
// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。
|
// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。
|
||||||
// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。
|
// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。
|
||||||
|
//
|
||||||
|
// v1.7.0(2026-11-24):
|
||||||
|
// ① 订阅 ctx.gallery.onChanged —— 出图途中宿主每归档一张就通知,面板立刻长出新图;
|
||||||
|
// 此前只有「面板重新可见且距上次拉取 >5s」一个入口,而生成时面板一直可见 ⇒ 永远不刷。
|
||||||
|
// ② 格子「插入」补 insertK(与右键/顶部一致,尺寸档不再被忽略)。
|
||||||
|
// ③ 插入/删除补「插入中…」状态,删除改成等宿主删完再重拉(固定 250ms 会拉到未删完的清单)。
|
||||||
|
// 注:搜索框在 v1.6.1 已按用户意见移除,不再加回。
|
||||||
|
// v1.7.2(2026-11-25):按用户意见去掉**图片卡片上**的「插入」按钮,卡片只保留「下载」;
|
||||||
|
// 顶部工具栏「插入 / 下载」和右键菜单的「插入画布」保持不变。
|
||||||
;(function (global) {
|
;(function (global) {
|
||||||
'use strict'
|
'use strict'
|
||||||
if (!global.IWBPluginHost) return
|
if (!global.IWBPluginHost) return
|
||||||
@@ -40,16 +49,20 @@
|
|||||||
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
|
||||||
|
|
||||||
// v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行)
|
// v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行)
|
||||||
|
// v1.7.1:14px 在底栏里太小(齿轮细节几乎看不清)。按宿主 design-tokens.md §3.8
|
||||||
|
// 图标尺寸闭集 14/16/18 取最大档 --iwb-icon-lg(18),描边按规范 1.6;
|
||||||
|
// 命中区 ≥28×28 由 styles.css 的按钮尺寸兜住(图形放大不等于点击区变大)。
|
||||||
var SVG_NS = 'http://www.w3.org/2000/svg'
|
var SVG_NS = 'http://www.w3.org/2000/svg'
|
||||||
|
var ICON_PX = 18
|
||||||
function iconBtn (label, build, title) {
|
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 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')
|
var svg = document.createElementNS(SVG_NS, 'svg')
|
||||||
svg.setAttribute('viewBox', '0 0 16 16')
|
svg.setAttribute('viewBox', '0 0 16 16')
|
||||||
svg.setAttribute('width', '14')
|
svg.setAttribute('width', String(ICON_PX))
|
||||||
svg.setAttribute('height', '14')
|
svg.setAttribute('height', String(ICON_PX))
|
||||||
svg.setAttribute('fill', 'none')
|
svg.setAttribute('fill', 'none')
|
||||||
svg.setAttribute('stroke', 'currentColor')
|
svg.setAttribute('stroke', 'currentColor')
|
||||||
svg.setAttribute('stroke-width', '1.5')
|
svg.setAttribute('stroke-width', '1.6')
|
||||||
svg.setAttribute('stroke-linecap', 'round')
|
svg.setAttribute('stroke-linecap', 'round')
|
||||||
svg.setAttribute('stroke-linejoin', 'round')
|
svg.setAttribute('stroke-linejoin', 'round')
|
||||||
svg.setAttribute('aria-hidden', 'true')
|
svg.setAttribute('aria-hidden', 'true')
|
||||||
@@ -129,8 +142,20 @@
|
|||||||
setBtn.setAttribute('aria-expanded', 'false')
|
setBtn.setAttribute('aria-expanded', 'false')
|
||||||
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
|
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
|
||||||
settings.style.display = 'none'
|
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:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
|
// v1.4.2:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
|
||||||
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, setBtn)
|
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, folderBtn, setBtn)
|
||||||
var foot = el('div', { class: 'iwb-gal-foot' },
|
var foot = el('div', { class: 'iwb-gal-foot' },
|
||||||
el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, failEl, statusEl), tools)
|
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])
|
var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot, settings])
|
||||||
@@ -172,6 +197,7 @@
|
|||||||
menu.appendChild(b)
|
menu.appendChild(b)
|
||||||
}
|
}
|
||||||
item('插入画布', function () {
|
item('插入画布', function () {
|
||||||
|
setStatus('插入中…(取本地原图 → 按插入尺寸压缩)')
|
||||||
Promise.resolve(ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }))
|
Promise.resolve(ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }))
|
||||||
.then(function () { setStatus('已插入:' + it.name) })
|
.then(function () { setStatus('已插入:' + it.name) })
|
||||||
.catch(function () { setStatus('插入失败') })
|
.catch(function () { setStatus('插入失败') })
|
||||||
@@ -190,11 +216,14 @@
|
|||||||
var ask = (C && C.askOrNative) ? C.askOrNative('删除「' + it.name + '」?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除「' + it.name + '」?'))
|
var ask = (C && C.askOrNative) ? C.askOrNative('删除「' + it.name + '」?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除「' + it.name + '」?'))
|
||||||
ask.then(function (ok) {
|
ask.then(function (ok) {
|
||||||
if (!ok) return
|
if (!ok) return
|
||||||
|
// 先本地摘掉,避免删除后还渲染一格「图片已丢失」
|
||||||
items = items.filter(function (x) { return x.name !== it.name })
|
items = items.filter(function (x) { return x.name !== it.name })
|
||||||
total = Math.max(0, total - 1)
|
total = Math.max(0, total - 1)
|
||||||
delete picked[it.name]
|
delete picked[it.name]
|
||||||
render()
|
render()
|
||||||
Promise.resolve(ctx.gallery.remove([it.name])).then(function () { setTimeout(load, 250) }).catch(function () {})
|
// v1.7.0:等宿主真的删完再重拉(旧写法固定 setTimeout 250ms,磁盘慢/多张时会拉到还没删完的清单,
|
||||||
|
// 格子里出现「图片已丢失」,用户以为删坏了)
|
||||||
|
return Promise.resolve(ctx.gallery.remove([it.name])).then(function () { return load() }).catch(function () {})
|
||||||
}).catch(function () {})
|
}).catch(function () {})
|
||||||
})
|
})
|
||||||
document.body.appendChild(menu)
|
document.body.appendChild(menu)
|
||||||
@@ -215,6 +244,7 @@
|
|||||||
try { names = JSON.parse(raw) } catch (err) { return }
|
try { names = JSON.parse(raw) } catch (err) { return }
|
||||||
if (!names || names.length < 2) return
|
if (!names || names.length < 2) return
|
||||||
e.preventDefault(); e.stopPropagation()
|
e.preventDefault(); e.stopPropagation()
|
||||||
|
setStatus('插入中…(' + names.length + ' 张)')
|
||||||
Promise.resolve(ctx.gallery.insert(names, { insertK: cfg.insertK || '1k' })).then(function (r) {
|
Promise.resolve(ctx.gallery.insert(names, { insertK: cfg.insertK || '1k' })).then(function (r) {
|
||||||
if (r && r.ok === false) { setStatus('批量插入失败'); return }
|
if (r && r.ok === false) { setStatus('批量插入失败'); return }
|
||||||
setStatus('已插入 ' + names.length + ' 张')
|
setStatus('已插入 ' + names.length + ' 张')
|
||||||
@@ -252,6 +282,7 @@
|
|||||||
actions.appendChild(btn('插入', '把选中的图片插入画布(尺寸按「设置 → 插入尺寸」)', function () {
|
actions.appendChild(btn('插入', '把选中的图片插入画布(尺寸按「设置 → 插入尺寸」)', function () {
|
||||||
var names = pickedNames()
|
var names = pickedNames()
|
||||||
var k = cfg.insertK || '1k'
|
var k = cfg.insertK || '1k'
|
||||||
|
setStatus('插入中…(' + names.length + ' 张)')
|
||||||
Promise.resolve(ctx.gallery.insert(names, { insertK: k })).then(function (r) {
|
Promise.resolve(ctx.gallery.insert(names, { insertK: k })).then(function (r) {
|
||||||
if (r && r.ok === false) { setStatus('插入失败'); return }
|
if (r && r.ok === false) { setStatus('插入失败'); return }
|
||||||
setStatus('已插入 ' + names.length + ' 张(' + String(k).toUpperCase() + ')')
|
setStatus('已插入 ' + names.length + ' 张(' + String(k).toUpperCase() + ')')
|
||||||
@@ -270,7 +301,7 @@
|
|||||||
picked = {}
|
picked = {}
|
||||||
render()
|
render()
|
||||||
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
|
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
|
||||||
setTimeout(load, 250)
|
return load() // v1.7.0:等宿主真删完再重拉(固定延时会拉到未删完的清单)
|
||||||
})
|
})
|
||||||
}).catch(function () {})
|
}).catch(function () {})
|
||||||
}, true, true))
|
}, true, true))
|
||||||
@@ -300,6 +331,11 @@
|
|||||||
function renderGrid () {
|
function renderGrid () {
|
||||||
clear(grid)
|
clear(grid)
|
||||||
var gap = 6
|
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 tileW = Math.max(40, Number(cfg.tile) || 110)
|
||||||
var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap)))
|
var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap)))
|
||||||
// v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
|
// v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
|
||||||
@@ -368,7 +404,7 @@
|
|||||||
function paint (url) {
|
function paint (url) {
|
||||||
if (!url || typeof url !== 'string') { fail('图片已丢失'); return }
|
if (!url || typeof url !== 'string') { fail('图片已丢失'); return }
|
||||||
if (!box.isConnected) return
|
if (!box.isConnected) return
|
||||||
var img = el('img', { src: url, alt: '', loading: 'lazy', draggable: 'true' })
|
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)
|
if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h)
|
||||||
img.addEventListener('load', function () {
|
img.addEventListener('load', function () {
|
||||||
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
||||||
@@ -407,7 +443,7 @@
|
|||||||
if (img.parentNode === box) box.replaceChild(holder, img)
|
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||||
fail('缩略图加载失败(点击重试)')
|
fail('缩略图加载失败(点击重试)')
|
||||||
} catch (e) { /* ignore */ }
|
} catch (e) { /* ignore */ }
|
||||||
}, 700)
|
}, 2000)
|
||||||
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
|
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
|
||||||
if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) }
|
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('缩略图加载失败(点击重试)') } }
|
else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }
|
||||||
@@ -420,7 +456,7 @@
|
|||||||
b.addEventListener('click', function (e) { e.stopPropagation(); fn() })
|
b.addEventListener('click', function (e) { e.stopPropagation(); fn() })
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
acts.appendChild(act('插入', '插入到画布(参考图节点)', function () { ctx.gallery.insert([it.name]).catch(function () {}) }))
|
// v1.7.2:图片卡片上只留「下载」;插入仍可从顶部工具栏或右键菜单进入。
|
||||||
acts.appendChild(act('下载', '下载到本地', function () { doDownload([it.name]) }))
|
acts.appendChild(act('下载', '下载到本地', function () { doDownload([it.name]) }))
|
||||||
box.appendChild(acts)
|
box.appendChild(acts)
|
||||||
return box
|
return box
|
||||||
@@ -447,7 +483,7 @@
|
|||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
|
|
||||||
function render () { renderHead(); renderGrid() }
|
function render () { renderHead(); renderGrid(); global.requestAnimationFrame(function () { try { measure() } catch (e) {} }); setTimeout(function () { try { measure() } catch (e) {} }, 150) }
|
||||||
|
|
||||||
function load (force) {
|
function load (force) {
|
||||||
if (force) setStatus('刷新中…')
|
if (force) setStatus('刷新中…')
|
||||||
@@ -497,11 +533,25 @@
|
|||||||
|
|
||||||
// v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次,
|
// v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次,
|
||||||
// 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。
|
// 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。
|
||||||
|
// v1.7.0:这只是**兜底**。主通道改成宿主主动通知(下面 onChanged)—— 生成途中面板一直是可见的,
|
||||||
|
// 靠「可见性变化」触发永远等不到,用户看到的就是「生图完成但图库没图」。
|
||||||
var lastLoadAt = 0
|
var lastLoadAt = 0
|
||||||
var autoRefresh = function () {
|
var autoRefresh = function () {
|
||||||
if (Date.now() - lastLoadAt < 5000) return
|
if (Date.now() - lastLoadAt < 5000) return
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
var unsubChanged = null
|
||||||
|
var changedTimer = 0
|
||||||
|
try {
|
||||||
|
var G = ctx.gallery
|
||||||
|
if (G && typeof G.onChanged === 'function') {
|
||||||
|
unsubChanged = G.onChanged(function () {
|
||||||
|
// 合并同一批的连续通知(一张图会触发「归档完成」一次),260ms 内只重拉一次
|
||||||
|
clearTimeout(changedTimer)
|
||||||
|
changedTimer = setTimeout(function () { load() }, 260)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) { /* 旧宿主没有 onChanged:退回可见性刷新 + 手动刷新 */ }
|
||||||
try {
|
try {
|
||||||
if (typeof IntersectionObserver === 'function') {
|
if (typeof IntersectionObserver === 'function') {
|
||||||
var io = new IntersectionObserver(function (entries) {
|
var io = new IntersectionObserver(function (entries) {
|
||||||
@@ -528,6 +578,8 @@
|
|||||||
|
|
||||||
return function dispose () {
|
return function dispose () {
|
||||||
if (ro) { try { ro.disconnect() } catch (e) { /* ignore */ } }
|
if (ro) { try { ro.disconnect() } catch (e) { /* ignore */ } }
|
||||||
|
clearTimeout(changedTimer)
|
||||||
|
try { if (typeof unsubChanged === 'function') unsubChanged() } catch (e) { /* ignore */ }
|
||||||
try { document.removeEventListener('pointerdown', onMenuDown, true) } catch (e) { /* ignore */ }
|
try { document.removeEventListener('pointerdown', onMenuDown, true) } catch (e) { /* ignore */ }
|
||||||
try { document.removeEventListener('keydown', onMenuKey, true) } catch (e) { /* ignore */ }
|
try { document.removeEventListener('keydown', onMenuKey, true) } catch (e) { /* ignore */ }
|
||||||
try { document.removeEventListener('drop', onDocDrop, true) } catch (e) { /* ignore */ }
|
try { document.removeEventListener('drop', onDocDrop, true) } catch (e) { /* ignore */ }
|
||||||
@@ -538,7 +590,7 @@
|
|||||||
global.IWBPluginHost.register({
|
global.IWBPluginHost.register({
|
||||||
id: 'gallery',
|
id: 'gallery',
|
||||||
name: '图库',
|
name: '图库',
|
||||||
version: '1.6.9',
|
version: '1.7.2',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'gallery'],
|
capabilities: ['panels', 'gallery'],
|
||||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||||
|
|||||||
+21
-10
@@ -13,7 +13,7 @@
|
|||||||
/* ---- 顶栏 ---- */
|
/* ---- 顶栏 ---- */
|
||||||
.iwb-gal-head { display: flex; align-items: center; gap: 6px; min-height: 0; }
|
.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 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||||
.iwb-gal-actions .iwb-btn-sm { padding: 2px 7px; }
|
.iwb-gal-actions .iwb-btn-sm { padding: 2px 6px; }
|
||||||
|
|
||||||
/* ---- 底栏:左信息 / 右工具组 ---- */
|
/* ---- 底栏:左信息 / 右工具组 ---- */
|
||||||
.iwb-gal-foot {
|
.iwb-gal-foot {
|
||||||
@@ -24,26 +24,37 @@
|
|||||||
.iwb-gal-count { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; }
|
.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-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-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; }
|
/* v1.7.1:图标放大后三个按钮不再紧贴(4px 是 spacing 闭集值) */
|
||||||
|
.iwb-gal-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; margin-left: auto; }
|
||||||
|
|
||||||
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ---- */
|
/* ---- 图标按钮:无外框、无底色,只在悬停时给一点反馈 ----
|
||||||
|
v1.7.1:命中区 20×20 → 28×28(design-tokens.md §3.8「≥28×28」),
|
||||||
|
图形 14 → var(--iwb-icon-lg) 18;CSS 尺寸覆盖 SVG 的 presentation attribute,
|
||||||
|
属性里的 18 只作宿主 token 缺失时的兜底。 */
|
||||||
.iwb-gal-foot .iwb-gal-icobtn,
|
.iwb-gal-foot .iwb-gal-icobtn,
|
||||||
.iwb-gal-foot .iwb-gal-icobtn:hover,
|
.iwb-gal-foot .iwb-gal-icobtn:hover,
|
||||||
.iwb-gal-foot .iwb-gal-icobtn:active {
|
.iwb-gal-foot .iwb-gal-icobtn:active {
|
||||||
width: 20px; height: 20px; min-width: 20px; padding: 0; box-sizing: border-box;
|
width: 28px; height: 28px; min-width: 28px; padding: 0; box-sizing: border-box;
|
||||||
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
|
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
|
||||||
border: 0; box-shadow: none; background: transparent; border-radius: 4px;
|
border: 0; box-shadow: none; background: transparent; border-radius: 6px;
|
||||||
color: var(--iwb-text2); line-height: 1; transform: none;
|
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 svg {
|
||||||
|
display: block; pointer-events: none;
|
||||||
|
width: var(--iwb-icon-lg, 18px); height: var(--iwb-icon-lg, 18px);
|
||||||
|
}
|
||||||
.iwb-gal-foot .iwb-gal-icobtn:hover { background: var(--iwb-layer2); color: var(--iwb-text); }
|
.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-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-setbtn-on { color: var(--iwb-brand); background: var(--iwb-layer2); }
|
||||||
|
|
||||||
/* ---- 设置浮层(三个下拉不占前台) ---- */
|
/* ---- 设置浮层(三个下拉不占前台) ----
|
||||||
|
bottom 随底栏高度走:底栏 = padding-top 6 + border 1 + 按钮 28,再加容器底 4 → 39,
|
||||||
|
取 40 让浮层正好停在底栏上沿之外;仍用 34 会被放大后的图标压住。
|
||||||
|
z-index 按 §3.6 层级表走 --iwb-z-ctx-menu(面板内菜单浮层):原先裸写 30,
|
||||||
|
这行一改动就被 token-lint 当成新增裸值拦下;91 仍低于 curtain(100)/command(120)。 */
|
||||||
.iwb-gal-settings {
|
.iwb-gal-settings {
|
||||||
position: absolute; right: 8px; bottom: 34px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
|
position: absolute; right: 8px; bottom: 40px; z-index: var(--iwb-z-ctx-menu, 91); width: 176px; max-width: calc(100% - 16px);
|
||||||
display: flex; flex-direction: column; gap: 8px; padding: 9px 10px;
|
display: flex; flex-direction: column; gap: 8px; padding: 8px 10px;
|
||||||
background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 8px;
|
background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 8px;
|
||||||
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
|
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
|
||||||
}
|
}
|
||||||
@@ -65,7 +76,7 @@
|
|||||||
font-size: 11px; color: var(--iwb-text2); background: var(--iwb-layer2); word-break: break-all;
|
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 { display: flex; gap: 4px; padding: 4px 2px 0; }
|
||||||
.iwb-history-actions .iwb-btn-sm { padding: 1px 6px; font-size: 10px; }
|
.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-history-more { display: flex; justify-content: center; padding: 4px 0 2px; }
|
||||||
/* 只作用于图库自己的空态提示:不加前缀会泄漏到设置页等使用 .iwb-hint 的地方(文字被居中) */
|
/* 只作用于图库自己的空态提示:不加前缀会泄漏到设置页等使用 .iwb-hint 的地方(文字被居中) */
|
||||||
.iwb-history-embedded .iwb-hint { font-size: 11px; color: var(--iwb-text2); text-align: center; padding: 12px 6px; }
|
.iwb-history-embedded .iwb-hint { font-size: 11px; color: var(--iwb-text2); text-align: center; padding: 12px 6px; }
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/* 图库底栏图标「真浏览器」核对(v1.7.1)
|
||||||
|
* 静态断言只能证明代码里有 18/28,证明不了宿主 style.css + 插件 CSS 叠完后真的是这个尺寸。
|
||||||
|
* 这里加载宿主 token/style + 插件源码本体,用合成 ctx 挂载真实面板,量 computed、验浮层不压底栏,
|
||||||
|
* 并出「改前 14/20」与「改后 18/28」的亮色对比图 + 改后暗色图。
|
||||||
|
*
|
||||||
|
* 运行:node gallery/tools/foot-visual-check.mjs
|
||||||
|
* 依赖宿主仓 playwright(跨仓依赖,不进默认 npm test)。
|
||||||
|
*/
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const HOST = path.resolve(HERE, '..', '..', '..', 'image-workbench-desktop')
|
||||||
|
const PW = pathToFileURL(path.resolve(HOST, 'node_modules', 'playwright', 'index.mjs')).href
|
||||||
|
const { chromium } = await import(PW)
|
||||||
|
const SRC = path.resolve(HERE, '..', 'src', 'index.js')
|
||||||
|
const CSS = path.resolve(HERE, '..', 'styles.css')
|
||||||
|
const TOKENS = path.resolve(HOST, 'src', 'design-tokens.css')
|
||||||
|
const HOSTCSS = path.resolve(HOST, 'style.css')
|
||||||
|
const cssText = readFileSync(CSS, 'utf8')
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, actual) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name + (actual === undefined ? '' : ' → ' + JSON.stringify(actual)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const browser = await chromium.launch()
|
||||||
|
const page = await browser.newPage({ viewport: { width: 760, height: 520 }, deviceScaleFactor: 2 })
|
||||||
|
const errors = []
|
||||||
|
page.on('pageerror', (e) => errors.push(String(e)))
|
||||||
|
|
||||||
|
await page.setContent(`<!doctype html><html><head><meta charset="utf-8"></head>
|
||||||
|
<body style="margin:0;background:#f2f3f5">
|
||||||
|
<div style="padding:16px"><div id="host" style="width:320px;height:240px;display:flex;flex-direction:column;background:var(--iwb-panel)"></div></div>
|
||||||
|
</body></html>`)
|
||||||
|
await page.evaluate(() => { window.__TAURI__ = { core: {} }; window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } } })
|
||||||
|
await page.addStyleTag({ path: TOKENS })
|
||||||
|
await page.addStyleTag({ path: HOSTCSS })
|
||||||
|
await page.addStyleTag({ path: CSS })
|
||||||
|
await page.addScriptTag({ path: SRC })
|
||||||
|
|
||||||
|
const version = await page.evaluate(() => {
|
||||||
|
const names = Array.from({ length: 17 }, (_, i) => 'img-' + (i + 1) + '.png')
|
||||||
|
const items = names.map((name) => ({ name: name, w: 80, h: 80 }))
|
||||||
|
const thumb = 'data:image/svg+xml,' + encodeURIComponent(
|
||||||
|
'<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><rect width="80" height="80" fill="#dfe3e9"/></svg>')
|
||||||
|
const ctx = {
|
||||||
|
ui: { registerPanel: (p) => { window.__panel = p } },
|
||||||
|
data: { read: async () => ({}), patch: async () => ({ ok: true }) },
|
||||||
|
gallery: {
|
||||||
|
list: async () => ({ items: items, total: 17 }),
|
||||||
|
thumb: async () => thumb,
|
||||||
|
onChanged: () => () => {},
|
||||||
|
insert: async () => ({ ok: true }), remove: async () => ({ ok: true }),
|
||||||
|
download: async () => ({ ok: true }), preview: () => {}, openFolder: async () => ({ ok: true }),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
window.__reg.factory(ctx)
|
||||||
|
window.__panel.mount(document.getElementById('host'))
|
||||||
|
return window.__reg.meta.version
|
||||||
|
})
|
||||||
|
ok('插件版本 = 1.7.2', version === '1.7.2', version)
|
||||||
|
await page.waitForTimeout(700)
|
||||||
|
|
||||||
|
const geo = await page.evaluate(() => {
|
||||||
|
const btns = Array.from(document.querySelectorAll('.iwb-gal-icobtn'))
|
||||||
|
const cs = (el) => getComputedStyle(el)
|
||||||
|
const tools = document.querySelector('.iwb-gal-tools')
|
||||||
|
const settings = document.querySelector('.iwb-gal-settings')
|
||||||
|
const foot = document.querySelector('.iwb-gal-foot')
|
||||||
|
return {
|
||||||
|
buttons: btns.length,
|
||||||
|
labels: btns.map((b) => b.getAttribute('aria-label')),
|
||||||
|
btnW: btns.map((b) => cs(b).width),
|
||||||
|
btnH: btns.map((b) => cs(b).height),
|
||||||
|
svgW: btns.map((b) => cs(b.querySelector('svg')).width),
|
||||||
|
svgAttr: btns.map((b) => b.querySelector('svg').getAttribute('width')),
|
||||||
|
gap: cs(tools).columnGap,
|
||||||
|
settingsBottom: cs(settings).bottom,
|
||||||
|
settingsZ: cs(settings).zIndex,
|
||||||
|
footH: cs(foot).height,
|
||||||
|
count: document.querySelector('.iwb-gal-count').textContent,
|
||||||
|
folderVisible: btns[1] && cs(btns[1]).display !== 'none',
|
||||||
|
cardActions: Array.from(document.querySelectorAll('.iwb-history-actions')).map((a) =>
|
||||||
|
Array.from(a.querySelectorAll('button')).map((b) => b.textContent.trim())),
|
||||||
|
toolbarLabels: Array.from(document.querySelectorAll('.iwb-gal-actions button')).map((b) => b.textContent.trim()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('几何 / 计算样式 =', JSON.stringify(geo))
|
||||||
|
ok('三个图标都在(刷新 / 打开本地目录 / 设置)', geo.buttons === 3 && geo.folderVisible, geo.labels)
|
||||||
|
ok('每张图卡片只剩「下载」', geo.cardActions.length > 0 && geo.cardActions.every((a) => a.join(',') === '下载'), geo.cardActions.slice(0, 3))
|
||||||
|
ok('顶部工具栏仍保留「插入」', geo.toolbarLabels.indexOf('插入') >= 0, geo.toolbarLabels)
|
||||||
|
ok('计数文字仍是 17 / 17 张(没动左侧信息区)', geo.count === '17 / 17 张', geo.count)
|
||||||
|
ok('命中区真的 28×28(不是只改了源码字符串)',
|
||||||
|
geo.btnW.every((w) => w === '28px') && geo.btnH.every((h) => h === '28px'), [geo.btnW, geo.btnH])
|
||||||
|
ok('图形真的 18×18(--iwb-icon-lg 生效)',
|
||||||
|
geo.svgW.every((w) => w === '18px') && geo.svgAttr.every((w) => w === '18'), geo.svgW)
|
||||||
|
ok('按钮间距 4px', geo.gap === '4px', geo.gap)
|
||||||
|
ok('设置浮层 bottom = 40px,底栏高度跟着长到 35px',
|
||||||
|
geo.settingsBottom === '40px' && geo.footH === '35px', [geo.settingsBottom, geo.footH])
|
||||||
|
ok('浮层层级真的取到 --iwb-z-ctx-menu(91)', geo.settingsZ === '91', geo.settingsZ)
|
||||||
|
|
||||||
|
// 设置浮层展开后不能被放大的底栏压住
|
||||||
|
await page.locator('button[aria-label="设置"]').click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
const overlap = await page.evaluate(() => {
|
||||||
|
const s = document.querySelector('.iwb-gal-settings').getBoundingClientRect()
|
||||||
|
const f = document.querySelector('.iwb-gal-foot').getBoundingClientRect()
|
||||||
|
return { settingsBottom: s.bottom, footTop: f.top, display: getComputedStyle(document.querySelector('.iwb-gal-settings')).display }
|
||||||
|
})
|
||||||
|
ok('设置浮层打开时停在底栏上沿之外(不压住图标)',
|
||||||
|
overlap.display !== 'none' && overlap.settingsBottom <= overlap.footTop + 1, overlap)
|
||||||
|
await page.locator('button[aria-label="设置"]').click()
|
||||||
|
await page.mouse.move(0, 0)
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
|
||||||
|
// 改前(1.7.0 口径)用同特异性覆盖规则模拟,不依赖 git 历史,脚本以后也能复跑
|
||||||
|
const old = await page.addStyleTag({ content: `
|
||||||
|
.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; }
|
||||||
|
.iwb-gal-foot .iwb-gal-icobtn svg { width:14px; height:14px; }
|
||||||
|
.iwb-gal-tools { gap:0; }
|
||||||
|
.iwb-gal-settings { bottom:34px; }` })
|
||||||
|
await page.waitForTimeout(100)
|
||||||
|
const beforeGeo = await page.evaluate(() => ({
|
||||||
|
btn: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).width,
|
||||||
|
svg: getComputedStyle(document.querySelector('.iwb-gal-icobtn svg')).width,
|
||||||
|
}))
|
||||||
|
ok('覆盖出的「改前」确实是 14px 图形 / 20px 命中区',
|
||||||
|
beforeGeo.svg === '14px' && beforeGeo.btn === '20px', beforeGeo)
|
||||||
|
const before = (await page.locator('.iwb-gal-foot').screenshot()).toString('base64')
|
||||||
|
await old.evaluate((el) => el.remove())
|
||||||
|
await page.waitForTimeout(100)
|
||||||
|
const after = (await page.locator('.iwb-gal-foot').screenshot()).toString('base64')
|
||||||
|
await page.screenshot({ path: '/tmp/gal-foot-171-light.png', fullPage: true })
|
||||||
|
|
||||||
|
// 暗色:token 自动跟随,尺寸不变
|
||||||
|
await page.evaluate(() => document.documentElement.classList.add('theme-dark'))
|
||||||
|
await page.waitForTimeout(150)
|
||||||
|
const dark = await page.evaluate(() => ({
|
||||||
|
btn: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).width,
|
||||||
|
svg: getComputedStyle(document.querySelector('.iwb-gal-icobtn svg')).width,
|
||||||
|
color: getComputedStyle(document.querySelector('.iwb-gal-icobtn')).color,
|
||||||
|
}))
|
||||||
|
ok('暗色下尺寸不变、图标色跟随 token', dark.btn === '28px' && dark.svg === '18px', dark)
|
||||||
|
await page.locator('.iwb-gal-foot').screenshot({ path: '/tmp/gal-foot-171-dark.png' })
|
||||||
|
await page.screenshot({ path: '/tmp/gal-foot-171-dark-full.png', fullPage: true })
|
||||||
|
|
||||||
|
// 对比图:两列底部对齐,标签用英文避免字体缺失
|
||||||
|
const cmp = await browser.newPage({ viewport: { width: 780, height: 240 }, deviceScaleFactor: 2 })
|
||||||
|
await cmp.setContent(`<!doctype html><html><head><meta charset="utf-8"></head>
|
||||||
|
<body style="margin:0;background:#fff;font-family:-apple-system,Helvetica,Arial,sans-serif">
|
||||||
|
<div style="display:flex;align-items:flex-end;gap:24px;padding:20px">
|
||||||
|
<div><div style="font-size:14px;font-weight:600;color:#333;margin-bottom:10px">BEFORE · 14px icon / 20x20 hit area</div>
|
||||||
|
<img src="data:image/png;base64,${before}" style="display:block;border:1px solid #e3e5e9"></div>
|
||||||
|
<div><div style="font-size:14px;font-weight:600;color:#333;margin-bottom:10px">AFTER · 18px icon / 28x28 hit area</div>
|
||||||
|
<img src="data:image/png;base64,${after}" style="display:block;border:1px solid #e3e5e9"></div>
|
||||||
|
</div></body></html>`)
|
||||||
|
await cmp.screenshot({ path: '/tmp/gal-foot-171-compare.png', fullPage: true })
|
||||||
|
|
||||||
|
ok('页面无 JS 报错', errors.length === 0, errors)
|
||||||
|
console.log('截图:/tmp/gal-foot-171-compare.png(对比)、-light.png、-dark.png、暗色全图')
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
|
await browser.close()
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/* 图库底栏图标的静态闸门(v1.7.1)
|
||||||
|
* 只改尺寸,不改交互;这些断言把「设计 token 口径」钉住,防止以后调样式时又缩回 14px/20×20。
|
||||||
|
* 运行:node gallery/tools/harness.mjs(已并入根 npm test)
|
||||||
|
*/
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const ROOT = path.resolve(HERE, '..')
|
||||||
|
const src = readFileSync(path.join(ROOT, 'src/index.js'), 'utf8')
|
||||||
|
const css = readFileSync(path.join(ROOT, 'styles.css'), 'utf8')
|
||||||
|
const pkg = JSON.parse(readFileSync(path.join(ROOT, 'package.json'), 'utf8'))
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, actual) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name + (actual === undefined ? '' : ' → ' + JSON.stringify(actual)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 版本两处一致 ----
|
||||||
|
ok('package.json version = 1.7.2', pkg.version === '1.7.2', pkg.version)
|
||||||
|
ok('manifest.version = 1.7.2', /version:\s*'1\.7\.2'/.test(src))
|
||||||
|
|
||||||
|
// ---- 图标尺寸:宿主 design-tokens.md §3.8 闭集 14/16/18,取最大档 ----
|
||||||
|
ok('SVG 尺寸常量 ICON_PX = 18', /\bvar ICON_PX = 18\b/.test(src))
|
||||||
|
ok('SVG width/height 都取 ICON_PX(不是写死 14)',
|
||||||
|
/setAttribute\('width', String\(ICON_PX\)\)/.test(src) &&
|
||||||
|
/setAttribute\('height', String\(ICON_PX\)\)/.test(src))
|
||||||
|
ok('描边按规范 stroke-width 1.6', /setAttribute\('stroke-width', '1\.6'\)/.test(src))
|
||||||
|
ok('CSS 图形尺寸走 --iwb-icon-lg(宿主 token 缺失才兜底 18px)',
|
||||||
|
/\.iwb-gal-foot \.iwb-gal-icobtn svg\s*\{[^}]*width:\s*var\(--iwb-icon-lg, 18px\)[^}]*height:\s*var\(--iwb-icon-lg, 18px\)/.test(css))
|
||||||
|
ok('命中区 28×28(§3.8「≥28×28」)',
|
||||||
|
/width:\s*28px;\s*height:\s*28px;\s*min-width:\s*28px/.test(css))
|
||||||
|
ok('工具组间距 4px(三个大图标不再紧贴)', /\.iwb-gal-tools\s*\{[^}]*gap:\s*4px/.test(css))
|
||||||
|
ok('设置浮层 bottom 随底栏长高到 40px(仍用 34 会被图标压住)',
|
||||||
|
/\.iwb-gal-settings\s*\{[^}]*bottom:\s*40px/.test(css))
|
||||||
|
ok('浮层层级走 --iwb-z-*(不写死裸 z-index,token-lint 会拦)',
|
||||||
|
/\.iwb-gal-settings\s*\{[^}]*z-index:\s*var\(--iwb-z-ctx-menu, 91\)/.test(css) &&
|
||||||
|
!/z-index:\s*\d+/.test(css))
|
||||||
|
|
||||||
|
// ---- 反向断言:旧的「小图标」写法不得回流 ----
|
||||||
|
ok('不再有 14px 的 SVG 属性', !/setAttribute\('(?:width|height)', '14'\)/.test(src))
|
||||||
|
ok('不再有 stroke-width 1.5', !/setAttribute\('stroke-width', '1\.5'\)/.test(src))
|
||||||
|
ok('不再有 20×20 命中区', !/width:\s*20px;\s*height:\s*20px;\s*min-width:\s*20px/.test(css))
|
||||||
|
ok('不再有 gap: 0 的紧贴按钮', !/gap:\s*0\s*;/.test(css))
|
||||||
|
ok('不再有 bottom: 34px', !/bottom:\s*34px/.test(css))
|
||||||
|
|
||||||
|
// ---- 交互与契约不变 ----
|
||||||
|
ok('三个图标仍是刷新 / 打开本地目录 / 设置',
|
||||||
|
/iconBtn\('刷新'/.test(src) && /iconBtn\('打开本地目录'/.test(src) && /iconBtn\('设置'/.test(src))
|
||||||
|
ok('按钮类名未变(宿主旧 .iwb-btn-sm 不会盖回来)',
|
||||||
|
/class:\s*'iwb-btn iwb-btn-sm iwb-gal-icobtn'/.test(src) &&
|
||||||
|
/\.iwb-gal-foot \.iwb-gal-icobtn/.test(css))
|
||||||
|
ok('悬停 / 键盘聚焦反馈仍在',
|
||||||
|
/\.iwb-gal-foot \.iwb-gal-icobtn:hover\s*\{[^}]*background/.test(css) &&
|
||||||
|
/\.iwb-gal-foot \.iwb-gal-icobtn:focus-visible/.test(css))
|
||||||
|
ok('左侧计数 / 选中 / 状态文字字号没被顺手改掉',
|
||||||
|
/\.iwb-gal-count\s*\{[^}]*font-size:\s*11px/.test(css) &&
|
||||||
|
/\.iwb-gal-sel\s*\{[^}]*font-size:\s*11px/.test(css))
|
||||||
|
|
||||||
|
// ---- v1.7.2:图片卡片只留下载;顶部/右键插入入口不回退 ----
|
||||||
|
ok('图片卡片上没有「插入」按钮', !/acts\.appendChild\(act\('插入'/.test(src))
|
||||||
|
ok('图片卡片保留「下载」按钮', /acts\.appendChild\(act\('下载'/.test(src))
|
||||||
|
ok('顶部工具栏「插入」仍在', /actions\.appendChild\(btn\('插入'/.test(src))
|
||||||
|
ok('右键菜单「插入画布」仍在', /item\('插入画布'/.test(src))
|
||||||
|
|
||||||
|
// ---- 尺寸闭集(对齐宿主 plugin-scale-contract,防止放大时又引入散值)----
|
||||||
|
const FONT = new Set([11, 12, 13, 14, 15, 17, 20, 24])
|
||||||
|
const RADIUS = new Set([6, 8, 10, 12, 14, 999])
|
||||||
|
const SPACE = new Set([0, 2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 64])
|
||||||
|
const stray = []
|
||||||
|
for (const m of css.matchAll(/([a-z-]+)\s*:\s*([^;{}]+)/g)) {
|
||||||
|
const prop = m[1].toLowerCase()
|
||||||
|
const val = m[2].trim()
|
||||||
|
if (val.includes('var(')) continue
|
||||||
|
const px = [...val.matchAll(/([0-9.]+)px/g)].map((x) => Number(x[1]))
|
||||||
|
if (prop === 'font-size' && px.some((n) => !FONT.has(n))) stray.push('font-size:' + val)
|
||||||
|
else if (prop === 'border-radius' && px.some((n) => !RADIUS.has(n))) stray.push('border-radius:' + val)
|
||||||
|
else if (/^(gap|row-gap|column-gap)$/.test(prop) || /^(padding|margin)/.test(prop)) {
|
||||||
|
if (px.some((n) => !SPACE.has(n))) stray.push(prop + ':' + val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ok('CSS 字号 / 圆角 / 间距无新增散值', stray.length === 0, stray)
|
||||||
|
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过(gallery 1.7.2 卡片只留下载)')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/grouplib",
|
"name": "@iwb-plugin/grouplib",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "节点组:左栏收藏的节点组列表(分组/改名/删除/拖入画布实例化),数据由宿主 grouplib 能力提供",
|
"description": "节点组:左栏收藏的节点组列表(分组/改名/删除/拖入画布实例化),数据由宿主 grouplib 能力提供",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "grouplib",
|
"id": "grouplib",
|
||||||
|
|||||||
@@ -439,7 +439,7 @@
|
|||||||
global.IWBPluginHost.register({
|
global.IWBPluginHost.register({
|
||||||
id: 'grouplib',
|
id: 'grouplib',
|
||||||
name: '节点组',
|
name: '节点组',
|
||||||
version: '1.0.4',
|
version: '1.0.5',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'grouplib'],
|
capabilities: ['panels', 'grouplib'],
|
||||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
.iwb-glp-dragging { opacity: .55; }
|
.iwb-glp-dragging { opacity: .55; }
|
||||||
/* 空态:虚线框 */
|
/* 空态:虚线框 */
|
||||||
.iwb-glp-empty {
|
.iwb-glp-empty {
|
||||||
margin: 4px 0; padding: 14px 12px; border-radius: 10px; text-align: center;
|
margin: 4px 0; padding: 12px 12px; border-radius: 10px; text-align: center;
|
||||||
border: 1px dashed var(--iwb-border2, #b9bfca); color: var(--iwb-text2, #4d5668);
|
border: 1px dashed var(--iwb-border2, #b9bfca); color: var(--iwb-text2, #4d5668);
|
||||||
font-size: 12px; line-height: 1.7;
|
font-size: 12px; line-height: 1.7;
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
持有几十 MB 的 base64 字符串)。合成宿主的 CSP 常把 `connect-src` 限为 `'self' https:`、**不含 `data:`** ⇒ `fetch(data:)` 被拦
|
持有几十 MB 的 base64 字符串)。合成宿主的 CSP 常把 `connect-src` 限为 `'self' https:`、**不含 `data:`** ⇒ `fetch(data:)` 被拦
|
||||||
(桌面客户端的 CSP 含 `data:`,但测试用的合成宿主按更严策略跑,故仍按最严口径处理)。
|
(桌面客户端的 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/harness.mjs` 的 CSP 段。
|
||||||
|
|
||||||
### v1.1:选区、便利版 UI、单张输出
|
### v1.1:选区、便利版 UI、单张输出
|
||||||
|
|
||||||
@@ -66,8 +66,7 @@
|
|||||||
- **侧栏去重**:移除硬度/透明两条滑杆(与就地选项栏画笔/橡皮态完全重复);
|
- **侧栏去重**:移除硬度/透明两条滑杆(与就地选项栏画笔/橡皮态完全重复);
|
||||||
侧栏保留调色板全量 + 笔刷大小(滑杆/数字/快捷点)+ 缩放行。
|
侧栏保留调色板全量 + 笔刷大小(滑杆/数字/快捷点)+ 缩放行。
|
||||||
|
|
||||||
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,79 项);
|
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主 + 真实 Chromium,覆盖 CSP / 图层排序 / 输出几何,发布前必跑)。
|
||||||
`node image-annotate/tools/e2e-site.mjs`(桌面客户端 CSP/SRI,发布后)。
|
|
||||||
|
|
||||||
## v1.2.2
|
## v1.2.2
|
||||||
|
|
||||||
@@ -1216,11 +1215,12 @@ node scripts/gen-market.js # 生成 market/index.json
|
|||||||
发布后回读市场索引确认版本与哈希已更新,再在客户端市场安装验证——不能只看命令退出码。
|
发布后回读市场索引确认版本与哈希已更新,再在客户端市场安装验证——不能只看命令退出码。
|
||||||
|
|
||||||
## 验证(可选,开发用)
|
## 验证(可选,开发用)
|
||||||
`tools/e2e-site.mjs`:**桌面客户端**端到端(市场安装 + SRI + 漂浮菜单 → 编辑器 → 覆盖/新建),
|
`tools/harness.mjs`:合成宿主 + 真实 Chromium,覆盖 CSP 适配、图层顺序回归(画图形 + 粘贴截图 → 唯一高亮、
|
||||||
另含 v1.0.5 的图层顺序回归:画图形 + 粘贴截图 → 唯一高亮、点重叠区选中最上层截图、四个排序按钮逐一生效、原图始终在最底。
|
点重叠区选中最上层截图、四个排序按钮逐一生效、原图始终在最底)、输出几何与编辑器命令。
|
||||||
需要 Playwright(可从桌面仓 `node_modules` 或全局解析),**不进 CI**(本仓 CI 只跑 `npm run validate`,不联网、无依赖)。
|
需要 Playwright(可从桌面仓 `node_modules` 或全局解析),**不进 CI**(本仓 CI 只跑 `npm run validate`,不联网、无依赖)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node image-annotate/tools/e2e-site.mjs
|
node image-annotate/tools/harness.mjs
|
||||||
```
|
```
|
||||||
> 为什么值得留着:mock 页没有 CSP,`connect-src` 类问题(如 `fetch(dataURL)`)在 mock 下永远绿,只有真机能抓出来。
|
> 为什么必须是真 Chromium:mock 页没有 CSP,`connect-src` 类问题(如 `fetch(dataURL)`)在纯 mock 下永远绿,
|
||||||
|
> harness 里的合成宿主带 CSP 闸门才能抓出来。
|
||||||
@@ -1,437 +0,0 @@
|
|||||||
// 真实站点端到端(开发用,不进 CI)。
|
|
||||||
//
|
|
||||||
// 为什么需要它:mock 页没有 CSP,`connect-src` 一类问题(例如 `fetch(dataURL)` 被
|
|
||||||
// `connect-src 'self' https: …` 拦掉)在 mock 下永远绿,只有带 CSP 的真站能抓出来。
|
|
||||||
// 它不 mock /plugins/*:走真实 KV + 浏览器 SRI 校验 + 真实画布桥。
|
|
||||||
//
|
|
||||||
// 运行:
|
|
||||||
// node image-annotate/tools/e2e-site.mjs
|
|
||||||
// IWB_BASE_URL=https://iwb.maqiart.eu.org node image-annotate/tools/e2e-site.mjs
|
|
||||||
// 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定)。
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { readFileSync } from 'node:fs'
|
|
||||||
import path from 'node:path'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/image-annotate/tools
|
|
||||||
const REPO = path.resolve(HERE, '../..') // <repo>
|
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
|
||||||
|
|
||||||
let chromium = null
|
|
||||||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
|
||||||
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ }
|
|
||||||
}
|
|
||||||
if (!chromium) {
|
|
||||||
console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT:')
|
|
||||||
console.error(' npm i -D playwright # 本仓或宿主仓皆可')
|
|
||||||
console.error(' IWB_PLAYWRIGHT_ROOT=/path/to/repo node image-annotate/tools/e2e-site.mjs')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE = process.env.IWB_BASE_URL || 'https://test.image-workbench-web.pages.dev'
|
|
||||||
const WANT_VERSION = JSON.parse(readFileSync(path.join(REPO, 'image-annotate/package.json'), 'utf8')).version
|
|
||||||
const CFG = { providers: [], canvas: {} }
|
|
||||||
const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
|
|
||||||
|
|
||||||
let failed = 0
|
|
||||||
const check = (name, ok, detail) => {
|
|
||||||
if (!ok) failed++
|
|
||||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
|
||||||
}
|
|
||||||
const poll = async (fn, timeout = 25000, step = 250) => {
|
|
||||||
const end = Date.now() + timeout
|
|
||||||
for (;;) {
|
|
||||||
let v
|
|
||||||
try { v = await fn() } catch { v = false }
|
|
||||||
if (v) return v
|
|
||||||
if (Date.now() > end) return false
|
|
||||||
await new Promise((r) => setTimeout(r, step))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('目标站点:' + BASE + '(期望插件版本 ' + WANT_VERSION + ')')
|
|
||||||
const browser = await chromium.launch()
|
|
||||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } })
|
|
||||||
const consoleErrors = []
|
|
||||||
page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) })
|
|
||||||
page.on('pageerror', (e) => consoleErrors.push('pageerror: ' + e.message + ' @ ' + String(e.stack || '').split('\n').slice(1, 4).join(' | ')))
|
|
||||||
page.on('dialog', (d) => { consoleErrors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) })
|
|
||||||
|
|
||||||
// 造一张真实的 96x64 PNG 作为节点图片
|
|
||||||
await page.goto('about:blank')
|
|
||||||
const PNG = await page.evaluate(() => {
|
|
||||||
const c = document.createElement('canvas')
|
|
||||||
c.width = 96; c.height = 64
|
|
||||||
const x = c.getContext('2d')
|
|
||||||
x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 96, 64)
|
|
||||||
x.fillStyle = '#ffffff'; x.fillRect(20, 12, 56, 40)
|
|
||||||
return c.toDataURL('image/png')
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.addInitScript((d) => {
|
|
||||||
localStorage.clear()
|
|
||||||
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
|
|
||||||
const ws = JSON.parse(JSON.stringify(d.ws))
|
|
||||||
ws.workspaces[0].nodes = [{ id: 'r1', type: 'ref', x: 140, y: 140, data: { url: '', data: d.png, name: 'src.png', localName: null } }]
|
|
||||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
|
||||||
localStorage.setItem('iwb_ws_active', ws.activeId)
|
|
||||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0]))
|
|
||||||
localStorage.setItem('iwb_web_outputs', JSON.stringify([]))
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'image-annotate': { enabled: true, settings: {}, data: {} } }))
|
|
||||||
}, { cfg: CFG, ws: WS, png: PNG })
|
|
||||||
|
|
||||||
const resp = await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' })
|
|
||||||
check('站点可达', Boolean(resp && resp.ok()), resp && String(resp.status()))
|
|
||||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 30000 })
|
|
||||||
|
|
||||||
// ---------- 1) 真实 KV 加载 + SRI + 启用 ----------
|
|
||||||
const active = await poll(async () => page.evaluate(() => {
|
|
||||||
const p = window.IWBPluginHost.list().find((x) => x.id === 'image-annotate')
|
|
||||||
return p && p.active ? { version: p.version, enabled: p.enabled, capabilities: p.capabilities, error: p.error } : false
|
|
||||||
}))
|
|
||||||
check('从真实 KV 加载并启用(SRI 通过)', Boolean(active), JSON.stringify(active))
|
|
||||||
check('线上版本 = package.json(' + WANT_VERSION + ')', Boolean(active && active.version === WANT_VERSION), active && active.version)
|
|
||||||
|
|
||||||
const scripts = await page.evaluate(() => Array.from(document.querySelectorAll('script[src*="/plugins/"]')).map((s) => ({ src: s.getAttribute('src'), integrity: s.getAttribute('integrity') || '' })))
|
|
||||||
// 文件名两种都合法:plugins-publish.mjs 产内容寻址名(.<hash12>.js,可 immutable 缓存),
|
|
||||||
// plugins-publish.sh(带主干守卫的合规通道)产固定名(plugin-image-annotate.js,走 no-cache+ETag)。
|
|
||||||
// 断言的关键是「必须带 integrity」,与命名策略无关。
|
|
||||||
check('插件脚本用 SRI(sha256) 加载', scripts.some((s) => /^\/plugins\/plugin-image-annotate(\.[a-f0-9]{12})?\.js$/.test(s.src) && /^sha256-/.test(s.integrity)), JSON.stringify(scripts))
|
|
||||||
|
|
||||||
// ---------- 2) 打开工作区 + 节点存在 ----------
|
|
||||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
|
||||||
await page.locator('.iwb-canvas:not(.iwb-canvas-hidden)').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
check('工作区打开、种子节点在画布', (await page.locator('.iwb-node[data-node-id="r1"]').count()) === 1)
|
|
||||||
|
|
||||||
// ---------- 3) 入口:节点漂浮菜单(回落右键插件命令)----------
|
|
||||||
const openEditor = async () => {
|
|
||||||
await page.locator('.iwb-node[data-node-id="r1"]').click()
|
|
||||||
const btn = page.locator('.iwb-node-floatbar button[title="标注 / 修图"]')
|
|
||||||
if (await btn.count()) { await btn.click(); return '漂浮菜单' }
|
|
||||||
await page.locator('.iwb-canvas').click({ button: 'right', position: { x: 900, y: 620 } })
|
|
||||||
await page.locator('.iwb-ctxmenu .iwb-ctx-item').filter({ hasText: '标注 / 修图:选中节点' }).click()
|
|
||||||
return '右键命令'
|
|
||||||
}
|
|
||||||
const entry = await openEditor()
|
|
||||||
check('节点入口可触发(漂浮菜单或右键命令)', true, entry)
|
|
||||||
|
|
||||||
// ---------- 4) 编辑器打开(真实 CSP 下注入样式)----------
|
|
||||||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
const opened = await page.evaluate(() => {
|
|
||||||
const el = document.querySelector('#iwb-editor-overlay')
|
|
||||||
const style = document.getElementById('iwb-annotate-style')
|
|
||||||
return {
|
|
||||||
display: getComputedStyle(el).display,
|
|
||||||
position: getComputedStyle(el).position,
|
|
||||||
zIndex: getComputedStyle(el).zIndex,
|
|
||||||
bg: getComputedStyle(el).backgroundColor,
|
|
||||||
styleInjected: Boolean(style && style.textContent.includes('.iwb-editor-')),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('编辑器浮层可见', opened.display === 'flex' && opened.position === 'fixed')
|
|
||||||
check('样式注入生效(CSP unsafe-inline)', opened.styleInjected)
|
|
||||||
check('浮层压住宿主 UI', Number(opened.zIndex) >= 999998, 'z=' + opened.zIndex + ' bg=' + opened.bg)
|
|
||||||
|
|
||||||
// ---------- 4.5) 剪贴板粘贴:⌘V 把剪贴板图片贴为新图层 ----------
|
|
||||||
// 合成 ClipboardEvent(带 image/png File),粘贴应进入「图片放置」模式;回车确认后图层面板 +1 项。
|
|
||||||
// SKIP_PASTE=1 可跳过(隔离「粘贴」与「覆盖写回」两条链路的排查用)。
|
|
||||||
const SKIP_PASTE = process.env.SKIP_PASTE === '1'
|
|
||||||
if (!SKIP_PASTE) {
|
|
||||||
// 先画一个矢量矩形,制造「截图 + 图形」共存场景 —— 这是 z 撞车 / 排序按钮失效的复现前提
|
|
||||||
const imgBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
|
||||||
await page.mouse.move(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(imgBox.x + imgBox.width * 0.75, imgBox.y + imgBox.height * 0.75, { steps: 8 })
|
|
||||||
await page.mouse.up()
|
|
||||||
await page.waitForTimeout(200)
|
|
||||||
const layersBefore = await page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list > *').length)
|
|
||||||
await page.evaluate((png) => {
|
|
||||||
const bin = atob(png.split(',')[1])
|
|
||||||
const bytes = new Uint8Array(bin.length)
|
|
||||||
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)
|
|
||||||
const dt = new DataTransfer()
|
|
||||||
dt.items.add(new File([bytes], 'paste.png', { type: 'image/png' }))
|
|
||||||
document.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }))
|
|
||||||
}, PNG)
|
|
||||||
await page.waitForTimeout(800) // FileReader → loadImage → 进入放置模式
|
|
||||||
await page.keyboard.press('Enter') // 确认放置 → 落层
|
|
||||||
const pasted = await poll(async () => page.evaluate((n) => document.querySelectorAll('.iwb-editor-layer-list > *').length > n, layersBefore))
|
|
||||||
check('⌘V 粘贴剪贴板图片 → 确认后图层面板 +1', Boolean(pasted), '图层项 ' + layersBefore + ' → ' + await page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list > *').length))
|
|
||||||
|
|
||||||
// ---------- 4.6) 图层顺序回归(2026-11-04 修):z 唯一 / 选中唯一 / 四个排序按钮 ----------
|
|
||||||
const panelSeq = () => page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-layer-list .iwb-layer-item'))
|
|
||||||
.map((n) => n.querySelector('.iwb-layer-name')?.textContent).join(' > '))
|
|
||||||
const activeCount = () => page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list .iwb-layer-item.active').length)
|
|
||||||
check('图层面板只有一个选中项(画笔目标改用 ✎ 标记)', (await activeCount()) === 1,
|
|
||||||
'active=' + await activeCount() + ' / ' + await panelSeq())
|
|
||||||
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
|
||||||
await page.mouse.click(imgBox.x + imgBox.width * 0.5, imgBox.y + imgBox.height * 0.5)
|
|
||||||
await page.waitForTimeout(150)
|
|
||||||
const activeItem = await page.evaluate(() => {
|
|
||||||
const n = document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active')
|
|
||||||
return n && { type: n.dataset.layerType, name: n.querySelector('.iwb-layer-name')?.textContent }
|
|
||||||
})
|
|
||||||
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
|
||||||
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
|
||||||
|
|
||||||
// v1.13 起顶栏四个层级按钮已删除(改为图层拖动 + Ctrl+]/[ 快捷键),
|
|
||||||
// 这里改为断言「按钮确实没了」+ 用快捷键验证排序仍然可用。
|
|
||||||
check('顶栏不再有层级排序按钮(改用图层拖动 + Ctrl+]/[)',
|
|
||||||
(await page.locator('.iwb-editor-layer-btn').count()) === 0 &&
|
|
||||||
(await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0,
|
|
||||||
'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count())
|
|
||||||
|
|
||||||
// v1.18(用户 2026-11-10):撤销 / 重做 / 还原 从顶栏搬到工具条最右,
|
|
||||||
// 「适应窗口 / 收起侧栏」退到它前面两位。这里断言「末尾是撤销组、视图按钮在其前」
|
|
||||||
// —— 光看版本号挡不住产物没重建。
|
|
||||||
const toolsOrder = await page.evaluate(() => {
|
|
||||||
const kids = Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
|
||||||
const acts = kids.filter((n) => n.dataset && n.dataset.action).map((n) => n.dataset.action)
|
|
||||||
const hist = kids[kids.length - 1]
|
|
||||||
return {
|
|
||||||
tail: acts.slice(-2),
|
|
||||||
lastIsHistory: Boolean(hist && hist.classList.contains('iwb-editor-history')),
|
|
||||||
histActs: [...(hist ? hist.querySelectorAll('[data-action]') : [])].map((b) => b.dataset.action),
|
|
||||||
headerHasHistory: Boolean(document.querySelector('.iwb-editor-header .iwb-editor-history')),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('工具栏最右是「撤销/重做/还原」组(视图按钮在其前)',
|
|
||||||
JSON.stringify(toolsOrder.tail) === JSON.stringify(['zoomFit', 'togglePanels']) &&
|
|
||||||
toolsOrder.lastIsHistory && toolsOrder.histActs.join(',') === 'undo,redo,reset' &&
|
|
||||||
!toolsOrder.headerHasHistory, JSON.stringify(toolsOrder))
|
|
||||||
|
|
||||||
const before = await panelSeq()
|
|
||||||
const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent)
|
|
||||||
await page.keyboard.press('Control+[') // 下移一层
|
|
||||||
const afterDown = await panelSeq()
|
|
||||||
check('Ctrl+[ 下移一层改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
|
||||||
await page.keyboard.press('Control+]') // 上移一层
|
|
||||||
check('Ctrl+] 上移一层恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
|
||||||
|
|
||||||
await page.keyboard.press('Control+Shift+[') // 置底
|
|
||||||
const afterBottom = await panelSeq()
|
|
||||||
check('Ctrl+Shift+[ 置底生效(元素不会消失)',
|
|
||||||
afterBottom !== before && afterBottom.endsWith(String(activeName)), afterBottom)
|
|
||||||
check('置底后原图不再被钉在最底 —— 图层可以压到原图下面(v1.13 解封)',
|
|
||||||
!afterBottom.endsWith('原图'), afterBottom)
|
|
||||||
await page.keyboard.press('Control+Shift+]') // 置顶
|
|
||||||
check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
|
||||||
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
|
||||||
|
|
||||||
// v1.15 图片调节:真站确认面板存在、11 项按参数表生成(DOM 由 adjust.js 生成,
|
|
||||||
// 构建时漏带就会是 0 行 —— 这类「打包产物缺模块」只有真站能发现)
|
|
||||||
const adjRowCount = await page.locator('.iwb-editor-adj-row').count()
|
|
||||||
const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents()
|
|
||||||
check('右侧栏「图片调节」11 项齐全',
|
|
||||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
|
||||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
|
||||||
check('调节面板认到了作用层(不是「无图层」)',
|
|
||||||
(await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层',
|
|
||||||
await page.locator('.iwb-editor-adj-target').textContent())
|
|
||||||
|
|
||||||
// v1.19:右栏常驻调色面板已删(用户 2026-11-10),颜色只剩工具栏弹层一处。
|
|
||||||
// 真站里 DOM 与 CSS 分别打包,这里同时验「右栏干净」和「弹层头部一行 / 16 色 8 列」——
|
|
||||||
// 样式漏打包时,头部会退回竖排或色块掉成 6 列,这条会直接露出来。
|
|
||||||
const sideColor = await page.evaluate(() => ({
|
|
||||||
hasSide: Boolean(document.querySelector('.iwb-editor-left [data-color-surface]')),
|
|
||||||
firstSection: (document.querySelector('.iwb-editor-left > section') || {}).className || '',
|
|
||||||
}))
|
|
||||||
check('右栏调色模块已删(第一个模块是图片调节)',
|
|
||||||
sideColor.hasSide === false && /iwb-editor-adj/.test(sideColor.firstSection),
|
|
||||||
JSON.stringify(sideColor))
|
|
||||||
|
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
|
||||||
await page.waitForTimeout(240)
|
|
||||||
const popShape = await page.evaluate(() => {
|
|
||||||
const pop = document.querySelector('.iwb-editor-color-pop')
|
|
||||||
if (!pop) return null
|
|
||||||
const r = (el) => el.getBoundingClientRect()
|
|
||||||
const head = r(pop.querySelector('.iwb-color-pop-head'))
|
|
||||||
const items = [pop.querySelector('[data-action="palettePick"]'),
|
|
||||||
pop.querySelector('.iwb-editor-color-hex-input'),
|
|
||||||
pop.querySelector('[data-action="pinColorPop"]')].map((el) => {
|
|
||||||
const b = r(el)
|
|
||||||
return { c: b.top + b.height / 2, l: b.left, r: b.right }
|
|
||||||
})
|
|
||||||
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
|
||||||
const grid = pop.querySelector('.iwb-editor-color-swatches')
|
|
||||||
return {
|
|
||||||
w: Math.round(r(pop).width),
|
|
||||||
sameRow: items.every((it) =>
|
|
||||||
Math.abs(it.c - (head.top + head.height / 2)) < 3 && it.l >= head.left - 1 && it.r <= head.right + 1),
|
|
||||||
common: sw.length,
|
|
||||||
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
|
|
||||||
swatch: sw.length ? Math.round(r(sw[0]).width) : 0,
|
|
||||||
// v1.20:去色占常用色第一格(20px 同尺寸、第一排最左)
|
|
||||||
noneFirst: grid.children[0] === pop.querySelector('[data-color-none]'),
|
|
||||||
cells: grid.children.length,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('色板弹层:头部一行(吸管 / 色值 / 图钉同排)+ 去色占常用色第一格 + 15 色 8 列',
|
|
||||||
Boolean(popShape) && popShape.sameRow && popShape.noneFirst && popShape.cells === 16 &&
|
|
||||||
popShape.common === 15 && popShape.cols === 8 && popShape.swatch === 20 && popShape.w === 440,
|
|
||||||
JSON.stringify(popShape))
|
|
||||||
await page.keyboard.press('Escape')
|
|
||||||
await page.waitForTimeout(140)
|
|
||||||
|
|
||||||
const sideBefore = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
|
||||||
const sideGrip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
|
||||||
if (sideGrip) {
|
|
||||||
await page.mouse.move(sideGrip.x + 3, sideGrip.y + 120)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(sideGrip.x + 3 - 70, sideGrip.y + 120, { steps: 6 })
|
|
||||||
await page.mouse.up()
|
|
||||||
await page.waitForTimeout(180)
|
|
||||||
}
|
|
||||||
const sideAfter = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
|
||||||
check('右栏可以拖宽(不再固定 220)', sideAfter >= sideBefore + 60, sideBefore + ' → ' + sideAfter)
|
|
||||||
await page.locator('.iwb-editor-side-resizer').dblclick()
|
|
||||||
await page.waitForTimeout(150)
|
|
||||||
|
|
||||||
// v1.17:描边可以是「无色」。真站要验的是按钮真的出现在描边槽、点完对象上真的关了,
|
|
||||||
// 而不只是 CSS 里多了个类 —— 形状消失与否只有跑起来才知道。
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
|
||||||
await page.mouse.move(imgBox.x + imgBox.width * 0.12, imgBox.y + imgBox.height * 0.12)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(imgBox.x + imgBox.width * 0.30, imgBox.y + imgBox.height * 0.30, { steps: 6 })
|
|
||||||
await page.mouse.up()
|
|
||||||
await page.waitForTimeout(250)
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
|
||||||
await page.mouse.click(imgBox.x + imgBox.width * 0.21, imgBox.y + imgBox.height * 0.21)
|
|
||||||
await page.waitForTimeout(200)
|
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
|
||||||
await page.waitForTimeout(250)
|
|
||||||
const noneOnStroke = await page.evaluate(() => {
|
|
||||||
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
|
||||||
// v1.20:去色不再 hidden,改用 disabled 表达「这个上下文不能去色」
|
|
||||||
return Boolean(n) && Boolean(n.offsetParent) && !n.disabled
|
|
||||||
})
|
|
||||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
|
||||||
await page.waitForTimeout(300)
|
|
||||||
const noStrokeState = await page.evaluate(() => {
|
|
||||||
const d = window.__iwbEditor.__debug()
|
|
||||||
const s = d.shapes.find((x) => x.id === d.selectedShapeId)
|
|
||||||
return s ? { strokeOn: s.strokeOn, fill: s.fill } : null
|
|
||||||
})
|
|
||||||
check('真站:描边能置「无」(去掉描边顺手切实心,对象不会消失)',
|
|
||||||
noneOnStroke && Boolean(noStrokeState) && noStrokeState.strokeOn === false && noStrokeState.fill === true,
|
|
||||||
JSON.stringify({ noneOnStroke, noStrokeState }))
|
|
||||||
await page.keyboard.press('Escape')
|
|
||||||
await page.waitForTimeout(120)
|
|
||||||
|
|
||||||
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
|
||||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
|
||||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
|
||||||
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
|
||||||
const famBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
|
||||||
await page.mouse.click(famBox.x + 60, famBox.y + 60)
|
|
||||||
await page.waitForTimeout(300)
|
|
||||||
await page.evaluate(() => {
|
|
||||||
const el = document.querySelector('.iwb-editor-text-input')
|
|
||||||
if (!el) return
|
|
||||||
el.focus()
|
|
||||||
el.value = '字体测试'
|
|
||||||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
|
||||||
})
|
|
||||||
await page.keyboard.press('Enter')
|
|
||||||
await page.waitForTimeout(400)
|
|
||||||
|
|
||||||
const famOpts = await page.locator(FAM_SEL + ' option').allTextContents()
|
|
||||||
check('真站选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
|
||||||
famOpts.length === 4, JSON.stringify(famOpts))
|
|
||||||
|
|
||||||
const wSans = ((await famDbg()).texts.find((t) => t.text === '字体测试') || {}).box
|
|
||||||
await page.selectOption(FAM_SEL, 'serif')
|
|
||||||
await page.waitForTimeout(320)
|
|
||||||
const tSerif = (await famDbg()).texts.find((t) => t.text === '字体测试')
|
|
||||||
check('真站切换宋体生效,且中文宽度不变(全角等宽,版面不跳动)',
|
|
||||||
Boolean(tSerif && tSerif.fontFamily === 'serif' && wSans && Math.abs(tSerif.box.w - wSans.w) <= 1),
|
|
||||||
(wSans ? wSans.w : '?') + ' → ' + (tSerif ? tSerif.box.w : '?'))
|
|
||||||
await page.keyboard.press('Delete')
|
|
||||||
await page.waitForTimeout(200)
|
|
||||||
|
|
||||||
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- 4.7) v1.1:选区 / 单层 Delete / 还原原图 / ≤500KB 预设 ----------
|
|
||||||
const dbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
|
||||||
const v11Box = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
|
||||||
await page.mouse.move(v11Box.x + v11Box.width * 0.25, v11Box.y + v11Box.height * 0.25)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(v11Box.x + v11Box.width * 0.7, v11Box.y + v11Box.height * 0.7, { steps: 8 })
|
|
||||||
await page.mouse.up()
|
|
||||||
await page.waitForTimeout(150)
|
|
||||||
const v11sel = (await dbg()).selection
|
|
||||||
check('v1.1 框选 + 浮动操作条出现', Boolean(v11sel && v11sel.w > 5 && v11sel.h > 5) &&
|
|
||||||
await page.locator('.iwb-editor-sel-bar').isVisible(), JSON.stringify(v11sel))
|
|
||||||
const v11px = (x, y) => page.evaluate(({ px, py }) => {
|
|
||||||
const d = window.__iwbEditor.__debug()
|
|
||||||
// 1.2.1 起默认没有 id='draw' 的预建层:填充落进「当前活动层」,
|
|
||||||
// 所以这里读活动层像素而不是写死 'draw'
|
|
||||||
return { base: d.pixel('base', px, py), draw: d.pixel(d.activeLayerId, px, py), activeId: d.activeLayerId }
|
|
||||||
}, { px: x, py: y })
|
|
||||||
const vcX = Math.round(v11sel.x + v11sel.w / 2)
|
|
||||||
const vcY = Math.round(v11sel.y + v11sel.h / 2)
|
|
||||||
const v11before = await v11px(vcX, vcY)
|
|
||||||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click()
|
|
||||||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click()
|
|
||||||
const v11after = await v11px(vcX, vcY)
|
|
||||||
check('v1.1 Delete 只清当前层(base 像素原样)',
|
|
||||||
v11after.draw[3] === 0 && JSON.stringify(v11after.base) === JSON.stringify(v11before.base),
|
|
||||||
'draw=' + JSON.stringify(v11after.draw) + ' base=' + JSON.stringify(v11after.base))
|
|
||||||
await page.keyboard.press('Control+z')
|
|
||||||
const v11layersBeforeReset = (await dbg()).layers.length
|
|
||||||
await page.locator('[data-action="reset"]').click()
|
|
||||||
check('v1.1 还原原图=只剩原图单层(1.2.1 起不预建画笔层)', (await dbg()).layers.length === 1, JSON.stringify((await dbg()).layers))
|
|
||||||
await page.keyboard.press('Control+z')
|
|
||||||
check('v1.1 还原原图可 Ctrl+Z 撤销', (await dbg()).layers.length === v11layersBeforeReset,
|
|
||||||
'层数 ' + v11layersBeforeReset + ' → 2 → ' + (await dbg()).layers.length)
|
|
||||||
await page.locator('[data-action="toggleExportSettings"]').click()
|
|
||||||
await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click()
|
|
||||||
check('v1.1 ≤500KB 输出预设可切换', (await dbg()).exportOptions.maxKB === 500,
|
|
||||||
JSON.stringify((await dbg()).exportOptions))
|
|
||||||
await page.locator('[data-export-key="preset"][data-export-value="original"]').click()
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
|
||||||
|
|
||||||
// ---------- 5) 覆盖:回写真机画布 ----------
|
|
||||||
await page.mouse.move(400, 300)
|
|
||||||
await page.mouse.down()
|
|
||||||
await page.mouse.move(760, 520, { steps: 8 })
|
|
||||||
await page.mouse.up()
|
|
||||||
await page.locator('[data-action="replace"]').click()
|
|
||||||
|
|
||||||
const replaced = await poll(async () => page.evaluate((orig) => {
|
|
||||||
const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}')
|
|
||||||
const n = (ws.nodes || []).find((x) => x.id === 'r1')
|
|
||||||
if (!n) return false
|
|
||||||
const v = n.data && (typeof n.data.data === 'string' ? n.data.data : (n.data.data && (n.data.data.__blob || JSON.stringify(n.data.data))))
|
|
||||||
return (ws.nodes.length === 1 && v && v !== orig) ? { nodes: ws.nodes.length, changed: true } : false
|
|
||||||
}, PNG))
|
|
||||||
check('「覆盖」写回原节点(节点数不变、内容已变)', Boolean(replaced), JSON.stringify(replaced))
|
|
||||||
check('编辑器导出后关闭', (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false)
|
|
||||||
|
|
||||||
// ---------- 6) 新建:真机画布新增节点 ----------
|
|
||||||
await openEditor()
|
|
||||||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
await page.locator('[data-action="newNode"]').click()
|
|
||||||
const created = await poll(async () => page.evaluate(() => {
|
|
||||||
const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}')
|
|
||||||
return (ws.nodes || []).length === 2 ? { nodes: 2 } : false
|
|
||||||
}))
|
|
||||||
check('「新建」在真机画布新增节点', Boolean(created), JSON.stringify(created))
|
|
||||||
await page.locator('.iwb-canvas').waitFor({ state: 'visible' })
|
|
||||||
check('画布渲染出 2 个节点', (await page.locator('.iwb-node').count()) === 2)
|
|
||||||
|
|
||||||
// ---------- 7) 无 CSP / 运行时错误 ----------
|
|
||||||
const bad = consoleErrors.filter((t) => /Content Security Policy|integrity|Refused to (execute|load|connect)/i.test(t))
|
|
||||||
check('无 CSP / SRI 拦截报错', bad.length === 0, bad.slice(0, 2).join(' | '))
|
|
||||||
check('无页面级运行时错误', consoleErrors.length === 0, consoleErrors.slice(0, 3).join(' | '))
|
|
||||||
|
|
||||||
await browser.close()
|
|
||||||
console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过'))
|
|
||||||
process.exit(failed ? 1 : 0)
|
|
||||||
@@ -13,7 +13,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
// 版本真源是 package.json(构建时注入 manifest),探针不再硬编码,免得每次发版都要改测试
|
// 版本真源是 package.json(构建时注入 manifest),探针不再硬编码,免得每次发版都要改测试
|
||||||
const PKG_VERSION = JSON.parse(readFileSync(path.resolve(HERE, '../package.json'), 'utf8')).version
|
const PKG_VERSION = JSON.parse(readFileSync(path.resolve(HERE, '../package.json'), 'utf8')).version
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ potrace 与其 JS 移植都是 **GPL-2.0**(见 `plugin/vendor/potrace/LICENSE`
|
|||||||
```bash
|
```bash
|
||||||
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 项,含 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
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { createRequire } from 'node:module'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const PLUGIN = path.resolve(HERE, '../plugin')
|
const PLUGIN = path.resolve(HERE, '../plugin')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
|
|
||||||
export function esbuildModule() {
|
export function esbuildModule() {
|
||||||
|
|||||||
@@ -1,276 +0,0 @@
|
|||||||
// 真实站点端到端(开发用,不进 CI)。
|
|
||||||
//
|
|
||||||
// 与 harness 的分工:harness 用合成宿主,能验功能但不能验真实 CSP/网络;这里走真站 ——
|
|
||||||
// 真实的 `_headers`(**不含 wasm-unsafe-eval**)、真实 KV、浏览器 SRI 校验、真实画布桥。
|
|
||||||
// v0.2 是纯 JS potrace,所以这里反而要断言「wasm 仍被 CSP 拦住」——防止有人为了别的功能
|
|
||||||
// 悄悄把 'wasm-unsafe-eval' 加回去。
|
|
||||||
//
|
|
||||||
// 运行:
|
|
||||||
// node image-vectorize/tools/e2e-site.mjs
|
|
||||||
// IWB_BASE_URL=https://iwb.maqiart.eu.org node image-vectorize/tools/e2e-site.mjs
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { readFileSync } from 'node:fs'
|
|
||||||
import path from 'node:path'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
||||||
const REPO = path.resolve(HERE, '../..')
|
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
|
||||||
|
|
||||||
let chromium = null
|
|
||||||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
|
||||||
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ }
|
|
||||||
}
|
|
||||||
if (!chromium) {
|
|
||||||
console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE = process.env.IWB_BASE_URL || 'https://test.image-workbench-web.pages.dev'
|
|
||||||
const PLUGIN_ID = 'image-vectorize'
|
|
||||||
const WANT_VERSION = JSON.parse(readFileSync(path.join(REPO, 'image-vectorize/package.json'), 'utf8')).version
|
|
||||||
const CFG = { providers: [], canvas: {} }
|
|
||||||
const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
|
|
||||||
|
|
||||||
let failed = 0
|
|
||||||
const check = (name, ok, detail) => {
|
|
||||||
if (!ok) failed++
|
|
||||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
|
||||||
}
|
|
||||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
||||||
const poll = async (fn, timeout = 25000, step = 250) => {
|
|
||||||
const end = Date.now() + timeout
|
|
||||||
for (;;) {
|
|
||||||
let v
|
|
||||||
try { v = await fn() } catch { v = false }
|
|
||||||
if (v) return v
|
|
||||||
if (Date.now() > end) return false
|
|
||||||
await sleep(step)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('目标站点:' + BASE + '(期望插件版本 ' + WANT_VERSION + ')')
|
|
||||||
const browser = await chromium.launch()
|
|
||||||
// 剪贴板要显式授权(真站是 https,安全上下文成立;本地 file/about:blank 测不到这条)
|
|
||||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } })
|
|
||||||
try {
|
|
||||||
await context.grantPermissions(['clipboard-read', 'clipboard-write'], { origin: new URL(BASE).origin })
|
|
||||||
} catch (error) {
|
|
||||||
console.log('(剪贴板授权失败,相关断言会跳过:' + (error && error.message) + ')')
|
|
||||||
}
|
|
||||||
const page = await context.newPage()
|
|
||||||
const consoleErrors = []
|
|
||||||
page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) })
|
|
||||||
page.on('pageerror', (e) => consoleErrors.push('pageerror: ' + e.message))
|
|
||||||
page.on('dialog', (d) => { consoleErrors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) })
|
|
||||||
|
|
||||||
await page.goto('about:blank')
|
|
||||||
const PNG = await page.evaluate(() => {
|
|
||||||
const c = document.createElement('canvas')
|
|
||||||
c.width = 320; c.height = 320
|
|
||||||
const g = c.getContext('2d')
|
|
||||||
g.fillStyle = '#ffffff'; g.fillRect(0, 0, 320, 320)
|
|
||||||
g.fillStyle = '#e8422f'; g.beginPath(); g.arc(96, 96, 58, 0, Math.PI * 2); g.fill()
|
|
||||||
g.fillStyle = '#1f5fa8'; g.beginPath(); g.roundRect(170, 130, 120, 84, 12); g.fill()
|
|
||||||
g.fillStyle = '#111111'; g.font = 'bold 38px "PingFang SC", sans-serif'; g.fillText('菜单', 96, 250)
|
|
||||||
return c.toDataURL('image/png')
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.addInitScript((d) => {
|
|
||||||
localStorage.clear()
|
|
||||||
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
|
|
||||||
const ws = JSON.parse(JSON.stringify(d.ws))
|
|
||||||
ws.workspaces[0].nodes = [{ id: 'r1', type: 'ref', x: 140, y: 140, data: { url: '', data: d.png, name: 'src.png', localName: null } }]
|
|
||||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
|
||||||
localStorage.setItem('iwb_ws_active', ws.activeId)
|
|
||||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0]))
|
|
||||||
localStorage.setItem('iwb_web_outputs', JSON.stringify([]))
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ [d.id]: { enabled: true, settings: {}, data: {} } }))
|
|
||||||
}, { cfg: CFG, ws: WS, png: PNG, id: PLUGIN_ID })
|
|
||||||
|
|
||||||
const resp = await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' })
|
|
||||||
check('站点可达', Boolean(resp && resp.ok()), resp && String(resp.status()))
|
|
||||||
|
|
||||||
// ---------- 1) 真实 KV 加载 + SRI ----------
|
|
||||||
await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 30000 })
|
|
||||||
const active = await poll(async () => page.evaluate((id) => {
|
|
||||||
const p = window.IWBPluginHost.list().find((x) => x.id === id)
|
|
||||||
return p && p.active ? { version: p.version, enabled: p.enabled, capabilities: p.capabilities, error: p.error } : false
|
|
||||||
}, PLUGIN_ID))
|
|
||||||
check('从真实 KV 加载并启用(SRI 通过)', Boolean(active), JSON.stringify(active))
|
|
||||||
check('线上版本 = package.json(' + WANT_VERSION + ')', Boolean(active && active.version === WANT_VERSION), active && active.version)
|
|
||||||
|
|
||||||
const scripts = await page.evaluate(() => Array.from(document.querySelectorAll('script[src*="/plugins/"]')).map((s) => ({ src: s.getAttribute('src'), integrity: s.getAttribute('integrity') || '' })))
|
|
||||||
check('插件脚本用 SRI(sha256) 加载',
|
|
||||||
scripts.some((s) => s.src.indexOf('/plugins/plugin-' + PLUGIN_ID + '.') === 0 && /^sha256-/.test(s.integrity)),
|
|
||||||
JSON.stringify(scripts.map((s) => s.src)))
|
|
||||||
|
|
||||||
// ---------- 2) 宿主 CSP 不再放行 wasm(v0.2 纯 JS,不需要放宽) ----------
|
|
||||||
const cspProbe = await page.evaluate(async () => {
|
|
||||||
try {
|
|
||||||
const b = Uint8Array.from(atob('AGFzbQEAAAA='), (c) => c.charCodeAt(0))
|
|
||||||
await WebAssembly.instantiate(b)
|
|
||||||
return 'ok'
|
|
||||||
} catch (e) { return 'blocked: ' + e.message }
|
|
||||||
})
|
|
||||||
check('宿主 CSP 仍禁止 wasm 编译(本插件是纯 JS,不该再放宽)', cspProbe.indexOf('blocked') === 0, cspProbe.slice(0, 120))
|
|
||||||
|
|
||||||
// ---------- 3) 打开工作区 ----------
|
|
||||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
|
||||||
await page.locator('.iwb-canvas:not(.iwb-canvas-hidden)').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
check('工作区打开、种子节点在画布', (await page.locator('.iwb-node[data-node-id="r1"]').count()) === 1)
|
|
||||||
|
|
||||||
// ---------- 4) 入口 → 模态 ----------
|
|
||||||
await page.locator('.iwb-node[data-node-id="r1"]').click()
|
|
||||||
const floatBtn = page.locator('.iwb-node-floatbar button[title="位图转矢量"]')
|
|
||||||
let entry = ''
|
|
||||||
if (await floatBtn.count()) {
|
|
||||||
await floatBtn.click()
|
|
||||||
entry = '漂浮菜单'
|
|
||||||
} else {
|
|
||||||
await page.locator('.iwb-canvas').click({ button: 'right', position: { x: 900, y: 620 } })
|
|
||||||
await page.locator('.iwb-ctxmenu .iwb-ctx-item').filter({ hasText: '位图转矢量' }).first().click()
|
|
||||||
entry = '右键命令'
|
|
||||||
}
|
|
||||||
await page.locator('.vz-modal').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
check('节点入口可触发(' + entry + ')', true)
|
|
||||||
check('样式注入生效(CSP unsafe-inline)', await page.evaluate(() => {
|
|
||||||
const s = document.getElementById('iwb-vectorize-style')
|
|
||||||
return Boolean(s && s.textContent.indexOf('.vz-') >= 0)
|
|
||||||
}))
|
|
||||||
|
|
||||||
// 用户 2026-11-09:取消与保存为节点互换,四颗按钮同一套描边配色(绿色主按钮已去掉)。
|
|
||||||
// 这条同时是「线上真的是新版」的活体证据 —— 光看版本号挡不住产物没重建。
|
|
||||||
check('顶栏顺序 保存为节点→复制→下载→取消,四颗同色', await page.evaluate(() => {
|
|
||||||
const btns = [...document.querySelectorAll('.vz-header .vz-btn')]
|
|
||||||
if (btns.map((b) => b.dataset.act).join(',') !== 'save,copy,svg,cancel') return false
|
|
||||||
const colors = new Set(btns.map((b) => getComputedStyle(b).backgroundColor + '|' + getComputedStyle(b).color))
|
|
||||||
return colors.size === 1
|
|
||||||
}))
|
|
||||||
|
|
||||||
// ---------- 5) 真站 CSP 下引擎能跑 ----------
|
|
||||||
const paths = await poll(async () => {
|
|
||||||
// 统计项是「元素」,合并模式下会带后缀「(N 孤岛合并)」,只取前面的数字
|
|
||||||
const t = await page.locator('[data-stat="elements"]').textContent()
|
|
||||||
const m = /^\s*(\d+)/.exec(t || '')
|
|
||||||
return m && Number(m[1]) > 0 ? m[1] : false
|
|
||||||
}, 30000)
|
|
||||||
check('真站描摹成功(纯 JS 引擎,无 wasm)', Boolean(paths), '元素=' + paths)
|
|
||||||
check('默认按孤岛拆分(元素数 > 层数)', Number(paths) > 3, '元素=' + paths)
|
|
||||||
check('预览为 blob: SVG', await page.evaluate(() => {
|
|
||||||
const v = document.querySelector('[data-stage="vector"]')
|
|
||||||
return Boolean(v && /^blob:/.test(v.src) && !v.hidden)
|
|
||||||
}))
|
|
||||||
|
|
||||||
const stats = await page.evaluate(() => ({
|
|
||||||
levels: Number(document.querySelector('[data-stat="levels"]').textContent),
|
|
||||||
bytes: document.querySelector('[data-stat="bytes"]').textContent,
|
|
||||||
ms: document.querySelector('[data-stat="ms"]').textContent,
|
|
||||||
}))
|
|
||||||
check('灰度层数正常(3 层)', stats.levels >= 3, JSON.stringify(stats))
|
|
||||||
|
|
||||||
// ---------- 5.5) 面板形态:高级默认打开 + 精度默认精细 ----------
|
|
||||||
check('高级参数默认展开', await page.evaluate(() => {
|
|
||||||
const box = document.querySelector('[data-adv]')
|
|
||||||
return Boolean(box && !box.hidden)
|
|
||||||
}))
|
|
||||||
check('精度默认「精细」', await page.evaluate(() => {
|
|
||||||
const a = document.querySelector('[data-seg-group="precision"] button.active')
|
|
||||||
return Boolean(a && a.dataset.value === 'fine')
|
|
||||||
}))
|
|
||||||
// v0.3.1:预览白底 + 填充/背景并排(真站 CSP 下 CSS 得真生效,不能只信本地)
|
|
||||||
check('预览区白底、无棋盘格', await page.evaluate(() => {
|
|
||||||
const cs = getComputedStyle(document.querySelector('.vz-preview'))
|
|
||||||
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(cs.backgroundColor)
|
|
||||||
return Boolean(m) && Number(m[1]) > 240 && cs.backgroundImage === 'none'
|
|
||||||
}))
|
|
||||||
check('「填充 / 背景」两个色块并排在同一行', await page.evaluate(() => {
|
|
||||||
const a = document.querySelector('[data-color="color"]')
|
|
||||||
const b = document.querySelector('[data-color="bg"]')
|
|
||||||
if (!a || !b) return false
|
|
||||||
const ra = a.getBoundingClientRect()
|
|
||||||
const rb = b.getBoundingClientRect()
|
|
||||||
return Math.abs(ra.top - rb.top) < 2 && rb.left > ra.right - 1
|
|
||||||
}))
|
|
||||||
|
|
||||||
// v0.4.0:预览缩放 / 平移(真站上鼠标手势得真能走通,不能只信本地合成宿主)
|
|
||||||
const pvBox = await page.locator('.vz-preview').boundingBox()
|
|
||||||
await page.mouse.move(pvBox.x + pvBox.width / 2 + 40, pvBox.y + pvBox.height / 2 - 20)
|
|
||||||
await page.mouse.wheel(0, -300)
|
|
||||||
await sleep(220)
|
|
||||||
// 断言「换算比例」而不是「比容器大」:正方形图 fit 进宽屏预览后本来就比容器窄,
|
|
||||||
// 拿 rect.width > clientWidth 会比较,放大了也可能不成立(实测真站 549 vs 1011)
|
|
||||||
check('滚轮放大预览、倍率胶囊出现', await page.evaluate(() => {
|
|
||||||
const p = document.querySelector('.vz-preview')
|
|
||||||
const v = document.querySelector('[data-stage="vector"]')
|
|
||||||
const z = Number(p.style.getPropertyValue('--vz-zoom') || 1)
|
|
||||||
const chip = document.querySelector('[data-zoom-chip]')
|
|
||||||
const ratio = v.getBoundingClientRect().width / v.clientWidth
|
|
||||||
return z > 1.1 && Boolean(chip) && !chip.hidden && Math.abs(ratio - z) < 0.02
|
|
||||||
}))
|
|
||||||
await page.mouse.dblclick(pvBox.x + pvBox.width / 2, pvBox.y + pvBox.height / 2)
|
|
||||||
await sleep(220)
|
|
||||||
check('双击复位回 100%', await page.evaluate(() => {
|
|
||||||
const p = document.querySelector('.vz-preview')
|
|
||||||
return Number(p.style.getPropertyValue('--vz-zoom') || 1) === 1
|
|
||||||
}))
|
|
||||||
|
|
||||||
// 回归:平滑滚轮(小数 deltaY)在真站也必须缩放。旧逻辑靠整数步长识别鼠标,会把这类滚轮当平移。
|
|
||||||
await page.evaluate(() => {
|
|
||||||
const p = document.querySelector('.vz-preview')
|
|
||||||
const r = p.getBoundingClientRect()
|
|
||||||
p.dispatchEvent(new WheelEvent('wheel', {
|
|
||||||
deltaY: -12.5, deltaMode: 0, bubbles: true, cancelable: true,
|
|
||||||
clientX: r.left + r.width / 2, clientY: r.top + r.height / 2,
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
await sleep(160)
|
|
||||||
check('真站:小数步长滚轮照样放大', await page.evaluate(() => {
|
|
||||||
const p = document.querySelector('.vz-preview')
|
|
||||||
return Number(p.style.getPropertyValue('--vz-zoom') || 1) > 1.001
|
|
||||||
}))
|
|
||||||
await page.mouse.dblclick(pvBox.x + pvBox.width / 2, pvBox.y + pvBox.height / 2)
|
|
||||||
await sleep(160)
|
|
||||||
|
|
||||||
// ---------- 5.6) 复制到剪贴板(真写,读回校验口味) ----------
|
|
||||||
await page.locator('[data-act="copy"]').click()
|
|
||||||
await sleep(400)
|
|
||||||
const clip = await page.evaluate(async () => {
|
|
||||||
try {
|
|
||||||
const items = await navigator.clipboard.read()
|
|
||||||
const types = items[0] ? items[0].types : []
|
|
||||||
let svg = ''
|
|
||||||
if (types.indexOf('image/svg+xml') >= 0) svg = await (await items[0].getType('image/svg+xml')).text()
|
|
||||||
return { types, svg, status: (document.querySelector('[data-status-text]') || {}).textContent || '' }
|
|
||||||
} catch (e) { return { error: String(e && e.message) } }
|
|
||||||
})
|
|
||||||
if (clip.error) {
|
|
||||||
check('复制 SVG 写入剪贴板', false, clip.error)
|
|
||||||
} else {
|
|
||||||
check('复制 SVG:剪贴板含 image/svg+xml(Figma 按矢量粘贴)',
|
|
||||||
clip.types.indexOf('image/svg+xml') >= 0 && clip.svg.indexOf('<svg') === 0 && clip.svg.indexOf('<path') > 0,
|
|
||||||
clip.types.join(',') + ' / ' + clip.svg.length + 'B')
|
|
||||||
check('复制后给了反馈', /已复制/.test(clip.status), clip.status)
|
|
||||||
// 拆分是这个版本的核心诉求:粘到 Figma 必须是多个可单独选中的图层,而不是一个整体
|
|
||||||
const pathCount = (clip.svg.match(/<path/g) || []).length
|
|
||||||
check('剪贴板里是多个独立 path(Figma 可单独选中,不是一个整体)', pathCount >= 5 && !/<g\b/.test(clip.svg), 'path 元素=' + pathCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- 6) 保存为节点(真实画布桥) ----------
|
|
||||||
await page.locator('[data-act="save"]').click()
|
|
||||||
const saved = await poll(async () => (await page.locator('.iwb-node').count()) >= 2, 25000)
|
|
||||||
check('保存为节点:画布新增一个图片节点', Boolean(saved), 'nodes=' + await page.locator('.iwb-node').count())
|
|
||||||
check('模态已关闭', (await page.locator('.vz-root').count()) === 0)
|
|
||||||
|
|
||||||
const fatal = consoleErrors.filter((e) => /Content Security Policy|Refused to|SRI|integrity/i.test(e))
|
|
||||||
check('无 CSP / SRI 报错', fatal.length === 0, fatal.slice(0, 2).join(' | '))
|
|
||||||
if (consoleErrors.length) {
|
|
||||||
console.log('')
|
|
||||||
console.log('控制台错误(' + consoleErrors.length + ' 条,前 5 条):')
|
|
||||||
for (const e of consoleErrors.slice(0, 5)) console.log(' ' + String(e).slice(0, 180))
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('')
|
|
||||||
console.log(failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过')
|
|
||||||
await browser.close()
|
|
||||||
process.exit(failed ? 1 : 0)
|
|
||||||
@@ -16,7 +16,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
const WANT_VERSION = JSON.parse(readFileSync(path.join(HERE, '../package.json'), 'utf8')).version
|
const WANT_VERSION = JSON.parse(readFileSync(path.join(HERE, '../package.json'), 'utf8')).version
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { bundleEngine } from './bundle-engine.mjs'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
|
|
||||||
let chromium = null
|
let chromium = null
|
||||||
for (const base of [HOST_REPO, REPO, process.cwd()]) {
|
for (const base of [HOST_REPO, REPO, process.cwd()]) {
|
||||||
|
|||||||
+8
-1
@@ -5,7 +5,14 @@
|
|||||||
"description": "IWB 插件仓:只写插件,不复制宿主契约",
|
"description": "IWB 插件仓:只写插件,不复制宿主契约",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"validate": "node scripts/validate.mjs",
|
"validate": "node scripts/validate.mjs",
|
||||||
"build": "node scripts/build-plugin.mjs"
|
"build": "node scripts/build-plugin.mjs",
|
||||||
|
"test": "npm run validate && npm run test:album && npm run test:promptlib && npm run test:gallery",
|
||||||
|
"test:album": "node album/tools/harness.mjs",
|
||||||
|
"test:album:e2e": "node album/tools/viewer-e2e.mjs",
|
||||||
|
"test:gallery": "node gallery/tools/harness.mjs",
|
||||||
|
"test:gallery:visual": "node gallery/tools/foot-visual-check.mjs",
|
||||||
|
"test:promptlib": "node promptlib/tools/harness.mjs && node promptlib/tools/vars-editor-test.mjs",
|
||||||
|
"test:promptlib:visual": "node promptlib/tools/vars-panel-visual-check.mjs"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "^0.24.2"
|
"esbuild": "^0.24.2"
|
||||||
|
|||||||
@@ -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
|
||||||
|
```
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/promptlib",
|
"name": "@iwb-plugin/promptlib",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.8.21",
|
"version": "1.13.1",
|
||||||
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "promptlib",
|
"id": "promptlib",
|
||||||
|
|||||||
+618
-134
File diff suppressed because it is too large.
Load diff
+158
-121
@@ -1,3 +1,4 @@
|
|||||||
|
.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(提示词库)自带样式
|
/* promptlib(提示词库)自带样式
|
||||||
作用域全部带 .iwb-plp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
作用域全部带 .iwb-plp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||||
|
|
||||||
@@ -34,9 +35,9 @@
|
|||||||
.iwb-plp-card:hover { border-color: var(--iwb-border2, #b9bfca); }
|
.iwb-plp-card:hover { border-color: var(--iwb-border2, #b9bfca); }
|
||||||
.iwb-plp-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
|
.iwb-plp-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||||
.iwb-plp-t {
|
.iwb-plp-t {
|
||||||
position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 7px 6px;
|
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));
|
background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,.66));
|
||||||
color: var(--plp-c1, #fff); font-size: 10.5px; line-height: 1.35; max-height: 48%;
|
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;
|
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
|
||||||
text-shadow: 0 1px 2px rgba(0,0,0,.35);
|
text-shadow: 0 1px 2px rgba(0,0,0,.35);
|
||||||
}
|
}
|
||||||
@@ -54,26 +55,26 @@
|
|||||||
/* 编辑弹窗:760 宽 + 大文本框 */
|
/* 编辑弹窗:760 宽 + 大文本框 */
|
||||||
.iwb-promptlib-editor { width: 760px; max-width: 94vw; }
|
.iwb-promptlib-editor { width: 760px; max-width: 94vw; }
|
||||||
.iwb-promptlib-editor .iwb-modal-body { max-height: 78vh; }
|
.iwb-promptlib-editor .iwb-modal-body { max-height: 78vh; }
|
||||||
.iwb-promptlib-text { min-height: 360px; height: 44vh; font-size: 12.5px; line-height: 1.9; resize: vertical; }
|
.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-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-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; }
|
.iwb-plp-editor-coverops { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
|
||||||
/* v1.2.0:可拖动 / 可缩放的详情与编辑弹窗(同宽 880×640,最小 640×420) */
|
/* v1.2.0:可拖动 / 可缩放的详情与编辑弹窗(同宽 880×640,最小 640×420) */
|
||||||
.iwb-plp-mask { background: transparent; display: block; }
|
.iwb-plp-mask { background: transparent; display: block; }
|
||||||
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 16px;
|
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 14px;
|
||||||
box-shadow: 0 24px 60px rgba(0,0,0,.28); }
|
box-shadow: 0 24px 60px rgba(0,0,0,.28); }
|
||||||
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 10px 14px;
|
.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; }
|
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 { 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-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: 14px; padding: 14px; }
|
.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;
|
.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); }
|
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-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;
|
.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); }
|
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 14px;
|
.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); }
|
border-top: 1px solid var(--iwb-border, #d5d9e0); }
|
||||||
.iwb-plp-resize { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize;
|
.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%); }
|
background: linear-gradient(135deg, transparent 0 45%, var(--iwb-border2, #b9bfca) 45% 50%, transparent 50% 62%, var(--iwb-border2, #b9bfca) 62% 67%, transparent 67%); }
|
||||||
@@ -81,7 +82,7 @@
|
|||||||
.iwb-plp-eleft { flex: 0 0 240px; width: 240px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
|
.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;
|
.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); }
|
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: 10px; color: var(--iwb-text2, #4d5668); }
|
.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-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 { border-color: color-mix(in srgb, var(--iwb-border, #d5d9e0) 72%, transparent); }
|
||||||
@@ -143,48 +144,51 @@
|
|||||||
.iwb-plp-node{display:flex;flex-direction:column;gap:6px;padding:8px 10px;font-size:12px;color:var(--iwb-text,#1c2333)}
|
.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-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-nthumb{width:44px;height:44px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
||||||
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
.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-nvars{display:flex;flex-direction:column;gap:4px}
|
||||||
.iwb-plp-nrow{display:flex;align-items:center;gap:6px;height:26px}
|
/* v1.12.1:标签列定宽(此前是 flex:0 0 auto,宽度跟着名称长短变 ⇒ 每个变量输入框左边缘错位)。
|
||||||
.iwb-plp-nk{width:64px;flex:0 0 64px;color:var(--iwb-text2,#5b6472);font-size:11.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
v1.13.0:用户要求按 4 字定宽 ⇒ 56px(12px 字号 × 4 + 8px 余量)。超过 4 字的名称省略号截断,完整名称在 title 里。 */
|
||||||
.iwb-plp-nin{flex:1;height:24px;font-size:11.5px}
|
.iwb-plp-nrow{display:flex;align-items:flex-start;gap:6px;min-height:26px}
|
||||||
.iwb-plp-nref{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--iwb-text2,#5b6472);border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px}
|
.iwb-plp-nk{flex:0 0 56px;width:56px;max-width:56px;padding-top:4px;color:var(--iwb-text2,#5b6472);font-size: 12px;line-height:1.35;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.iwb-plp-nin{flex:1 1 auto;min-width:0;height:auto;min-height:24px;padding:2px 8px;line-height:1.5;font-size: 12px;resize:none;overflow-y:hidden}
|
||||||
|
.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-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:11.5px;line-height:1.6;max-height:88px;overflow:hidden}
|
.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:变量编辑器 / 详情变量 */
|
/* v1.5.0:变量编辑器 / 详情变量 */
|
||||||
.iwb-plp-emid{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}
|
.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-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:11.5px;color:var(--iwb-text2,#5b6472)}
|
.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-vchips{display:flex;flex-wrap:wrap;gap:6px}
|
||||||
.iwb-plp-vchip{display:inline-flex;align-items:center;gap:4px;padding:1px 7px;border-radius:6px;background:color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 10%, transparent);color:var(--iwb-plp-accent, #5a4bd0);font-size:11.5px}
|
.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-vx{font-style:normal;cursor:pointer;color:var(--iwb-plp-accent, #8b7ff0);font-weight:700}
|
||||||
.iwb-plp-vrows{display:flex;flex-direction:column;gap:5px}
|
.iwb-plp-vrows{display:flex;flex-direction:column;gap: 6px}
|
||||||
.iwb-plp-vrow{display:flex;align-items:center;gap:8px}
|
.iwb-plp-vrow{display:flex;align-items:center;gap:8px}
|
||||||
.iwb-plp-vk{width:92px;flex:0 0 92px;font-size:11.5px;color:var(--iwb-text2,#5b6472);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
.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:11.5px}
|
.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:11.5px;line-height:1.6;color:var(--iwb-text2,#5b6472);max-height:72px;overflow:auto;white-space:pre-wrap}
|
.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:5px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
|
.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:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
|
/* v1.5.6:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
|
||||||
.iwb-plp-nthumb{width:56px;height:56px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
.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-ntitlebox{min-width:0;display:flex;flex-direction:column;gap:2px}
|
||||||
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
.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:10.5px;color:var(--iwb-text2,#8b929c)}
|
.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-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)}
|
.iwb-plp-nwarn{font-size:11px;line-height:1.5;color:var(--iwb-warn,#d97706)}
|
||||||
|
|
||||||
/* v1.5.10:设置页 */
|
/* v1.5.10:设置页 */
|
||||||
.iwb-plp-settings{display:flex;flex-direction:column;gap:18px}
|
.iwb-plp-settings{display:flex;flex-direction:column;gap: 16px}
|
||||||
.iwb-plp-ssec{border:1px solid var(--iwb-border,#e3e5e9);border-radius:12px;padding:12px 14px;display:flex;flex-direction:column;gap:8px}
|
/* 2026-11-24:插件设置页跟随宿主的设置分组 token(不再自画卡片,避免卡片套卡片) */
|
||||||
.iwb-plp-stitle{font-weight:600;font-size:12.5px}
|
.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-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-border,#eef0f2);border-radius:10px;overflow:hidden}
|
.iwb-plp-ssec:first-child{border-top:0;padding-top:0}
|
||||||
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding:7px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
|
.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-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:3px;flex:0 0 auto}
|
.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-sgname{width:170px;height:26px;font-size:12px}
|
||||||
.iwb-plp-sgcount{font-size:11.5px;color:var(--iwb-text2,#8b929c);width:56px}
|
.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-sadd{display:flex;gap:8px;align-items:center}
|
||||||
.iwb-plp-sbtns{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-sopt{display:flex;gap:8px;align-items:center;font-size:12px;color:var(--iwb-text2,#4d5668)}
|
||||||
@@ -192,6 +196,8 @@
|
|||||||
|
|
||||||
/* v1.6.2:正文上方工具行 */
|
/* v1.6.2:正文上方工具行 */
|
||||||
.iwb-plp-etool{display:flex;align-items:center;gap:8px}
|
.iwb-plp-etool{display:flex;align-items:center;gap:8px}
|
||||||
|
/* v1.13.0:中列变窄时按钮文字会被挤成「+ 插入变 / 量」,按钮不参与收缩,让右边的灰字提示去换行 */
|
||||||
|
.iwb-plp-insvar{flex:0 0 auto;white-space:nowrap}
|
||||||
.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}
|
.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:宿主基础样式的插件作用域副本 —— 宿主改全局样式不再影响插件 */
|
/* v1.6.5:宿主基础样式的插件作用域副本 —— 宿主改全局样式不再影响插件 */
|
||||||
@@ -202,7 +208,7 @@ flex: 1;
|
|||||||
display: flex; gap: 6px; align-items: center;
|
display: flex; gap: 6px; align-items: center;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-hint {
|
.iwb-promptlib .iwb-hint {
|
||||||
font-size: 10px; color: var(--iwb-text2); margin-top: 4px;
|
font-size: 11px; color: var(--iwb-text2); margin-top: 4px;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-toolbar-title {
|
.iwb-promptlib .iwb-toolbar-title {
|
||||||
font-weight: 700; font-size: 13px; margin-right: 2px;
|
font-weight: 700; font-size: 13px; margin-right: 2px;
|
||||||
@@ -217,10 +223,10 @@ width: 680px; max-width: calc(100vw - 60px); max-height: 82vh; background: var(-
|
|||||||
display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--iwb-border);
|
display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--iwb-border);
|
||||||
}
|
}
|
||||||
.iwb-plp-dialog-body {
|
.iwb-plp-dialog-body {
|
||||||
padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; max-height: 62vh;
|
padding: 12px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; max-height: 62vh;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-lib-body {
|
.iwb-promptlib .iwb-lib-body {
|
||||||
flex: 1; overflow: hidden; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
|
flex: 1; overflow: hidden; padding: 12px 12px; display: flex; flex-direction: column; gap: 8px;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-lib-fixed {
|
.iwb-promptlib .iwb-lib-fixed {
|
||||||
flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
|
flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
|
||||||
@@ -232,7 +238,7 @@ flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction:
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-lib-chips-scroll > .iwb-chip:last-child {
|
.iwb-promptlib .iwb-lib-chips-scroll > .iwb-chip:last-child {
|
||||||
margin-right: 18px;
|
margin-right: 16px;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-lib-searchscope-back {
|
.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;
|
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;
|
||||||
@@ -241,7 +247,7 @@ display: inline-flex; align-items: center; justify-content: center; width: 15px;
|
|||||||
background: color-mix(in srgb, var(--iwb-text) 12%, transparent); color: var(--iwb-text);
|
background: color-mix(in srgb, var(--iwb-text) 12%, transparent); color: var(--iwb-text);
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-chip {
|
.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: 3px 10px; font-size: 12px; color: var(--iwb-text2); cursor: pointer; white-space: nowrap; transition: all 0.15s;
|
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 {
|
.iwb-promptlib .iwb-chip:hover {
|
||||||
color: var(--iwb-text); border-color: var(--iwb-border2);
|
color: var(--iwb-text); border-color: var(--iwb-border2);
|
||||||
@@ -253,7 +259,7 @@ background: var(--iwb-panel); border-color: var(--iwb-border2); color: var(--iwb
|
|||||||
color: var(--iwb-text);
|
color: var(--iwb-text);
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-chip-count {
|
.iwb-promptlib .iwb-chip-count {
|
||||||
font-size: 10px; opacity: 0.8;
|
font-size: 11px; opacity: 0.8;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-chip-add {
|
.iwb-promptlib .iwb-chip-add {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
@@ -268,7 +274,7 @@ color: var(--iwb-text); opacity: 1;
|
|||||||
border: 1px solid var(--iwb-border); border-radius: 8px; padding: 8px 10px; background: var(--iwb-panel);
|
border: 1px solid var(--iwb-border); border-radius: 8px; padding: 8px 10px; background: var(--iwb-panel);
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-tag {
|
.iwb-promptlib .iwb-tag {
|
||||||
display: inline-block; background: color-mix(in srgb, var(--iwb-text) 7%, transparent); color: var(--iwb-text2); border-radius: 4px; font-size: 10px; padding: 1px 6px; margin: 3px 4px 0 0;
|
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 {
|
.iwb-plp-dialog-sm {
|
||||||
width: 460px;
|
width: 460px;
|
||||||
@@ -301,7 +307,7 @@ background: var(--iwb-brand); border-color: var(--iwb-brand); color: var(--iwb-o
|
|||||||
background: color-mix(in srgb, var(--iwb-brand) 85%, var(--iwb-text)); border-color: var(--iwb-brand); color: var(--iwb-on-brand);
|
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 {
|
.iwb-promptlib .iwb-btn-sm {
|
||||||
padding: 3px 7px; font-size: 11px;
|
padding: 4px 6px; font-size: 11px;
|
||||||
}
|
}
|
||||||
.iwb-promptlib .iwb-btn-danger {
|
.iwb-promptlib .iwb-btn-danger {
|
||||||
color: var(--iwb-err);
|
color: var(--iwb-err);
|
||||||
@@ -313,10 +319,10 @@ border-color: var(--iwb-err); color: var(--iwb-err);
|
|||||||
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;
|
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 {
|
.iwb-promptlib .iwb-ctx-title {
|
||||||
font-size: 10px; font-weight: 700; color: var(--iwb-text2); letter-spacing: 1px; padding: 6px 10px 2px; text-transform: uppercase;
|
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 {
|
.iwb-promptlib .iwb-ctx-item {
|
||||||
display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: none; border-radius: 8px; background: transparent; color: var(--iwb-text); font-size: 12.5px; cursor: pointer; text-align: left;
|
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 {
|
.iwb-promptlib .iwb-ctx-item .iwb-ic {
|
||||||
width: 14px; height: 14px; flex: 0 0 auto; color: var(--iwb-text2);
|
width: 14px; height: 14px; flex: 0 0 auto; color: var(--iwb-text2);
|
||||||
@@ -345,6 +351,11 @@ height: 1px; margin: 4px 6px; background: var(--iwb-border); flex: 0 0 auto;
|
|||||||
.iwb-promptlib .iwb-drawer-spacer {
|
.iwb-promptlib .iwb-drawer-spacer {
|
||||||
flex: 1 1 auto;
|
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 {
|
.iwb-plp-dialog .iwb-section-sub {
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
@@ -364,11 +375,11 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32);
|
|||||||
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98)}
|
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98)}
|
||||||
|
|
||||||
/* v1.6.9:拖拽虚拟卡片(跟手预览) */
|
/* 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:11px;box-shadow:0 12px 28px rgba(0,0,0,.22);font-size:12px;pointer-events:none;z-index:99999}
|
.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-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-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-ghostname{font-weight:600;color:var(--iwb-text,#1c2333);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
.iwb-plp-ghosthint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0)}
|
.iwb-plp-ghosthint{font-size: 11px;color:var(--iwb-plp-accent,#5a4bd0)}
|
||||||
|
|
||||||
/* v1.6.10:悬停放大改为「内层背景层缩放」——卡片命中区域不变,渐变卡不再闪烁 */
|
/* 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-bg{position:absolute;inset:0;overflow:hidden;border-radius:inherit;transition:transform .16s ease;will-change:transform;backface-visibility:hidden}
|
||||||
@@ -390,11 +401,11 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32);
|
|||||||
.iwb-plp-card{user-select:none}
|
.iwb-plp-card{user-select:none}
|
||||||
body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webkit-user-select:none!important}
|
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-placeghost{border-style:dashed!important;pointer-events:none}
|
||||||
.iwb-plp-placehint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0);margin-top:2px}
|
.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:99999;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{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:3px 10px}
|
.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:放置指示改为灰色小方框 */
|
/* v1.6.23:放置指示改为灰色小方框 */
|
||||||
.iwb-plp-placebox{border: 2px dashed var(--plp-c2, #9aa3ad);border-radius:10px;background:rgba(122,130,142,.10);box-shadow:none}
|
.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}
|
.iwb-plp-placebox-t{font-size:11px;color: var(--plp-c3, #6b7280);background:rgba(255,255,255,.75);padding:2px 8px}
|
||||||
/* v1.7.0:编辑面板三栏 + 可拖宽;详情封面放大、变量高亮 */
|
/* v1.7.0:编辑面板三栏 + 可拖宽;详情封面放大、变量高亮 */
|
||||||
.iwb-plp-eleft{flex:0 0 236px;width:236px}
|
.iwb-plp-eleft{flex:0 0 236px;width:236px}
|
||||||
@@ -405,54 +416,60 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
|||||||
.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-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-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-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-vitem{padding:4px 0}
|
||||||
.iwb-plp-vrow2{display:flex;align-items:center;gap:6px}
|
.iwb-plp-vrow2{display:flex;align-items:center;gap:6px}
|
||||||
.iwb-plp-vname{flex:1 1 auto;min-width:0;height:32px}
|
.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(--plp-c1, #fff);color: var(--plp-c4, #9aa1ac);font-size:11px;line-height:22px;text-align:center}
|
.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-vi.is-open{background: var(--plp-c5, #f1ecff);border-color: var(--plp-c6, #d8cbff);color: var(--plp-c7, #5a3fd0)}
|
/* v1.12.0:变量编辑器折叠两态(收起一行名称+摘要,展开四字段)与内容多行框 */
|
||||||
.iwb-plp-vdesc{width:100%;height:28px;margin-top:5px;border-style:dashed;background: var(--plp-c8, #fbfcfd);font-size:11.5px;color: var(--plp-c3, #6b7280)}
|
.iwb-plp-vrow2{cursor:pointer}
|
||||||
|
.iwb-plp-vcaret{flex:0 0 12px;width:12px;text-align:center;font-size:11px;line-height:32px;color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-vlabelx{flex:1 1 auto;min-width:0;font-size:13px;line-height:32px;color:var(--iwb-text,#2a2f36);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.iwb-plp-vlabelx.is-empty{color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-vsum{flex:0 0 auto;font-size:11px;line-height:32px;white-space:nowrap;color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-vfield{display:flex;align-items:flex-start;gap:8px;margin-top:6px}
|
||||||
|
.iwb-plp-vflabel{flex:0 0 40px;padding-top:8px;font-size:12px;color:var(--iwb-text2,#8b929c)}
|
||||||
|
.iwb-plp-vbody{flex:1 1 auto;min-width:0}
|
||||||
|
.iwb-plp-vbody .iwb-input{width:100%}
|
||||||
|
.iwb-plp-vbody .iwb-plp-vdesc{margin-top:0}
|
||||||
|
.iwb-plp-vdef{height:auto;min-height:66px;padding:4px 10px;line-height:1.65;font-size:12px;resize:none;overflow-y:hidden}
|
||||||
.iwb-plp-dcov{flex:0 0 auto;width:180px;height:180px;border-radius:12px;overflow:hidden}
|
.iwb-plp-dcov{flex:0 0 auto;width:180px;height:180px;border-radius:12px;overflow:hidden}
|
||||||
.iwb-plp-dvar{background: var(--plp-c5, #f1ecff);color: var(--plp-c7, #5a3fd0);border-radius:4px;padding:0 4px;font-weight:500}
|
.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:编辑面板视觉精修——输入框比底色更亮、去多余边框、细分隔线 */
|
/* v1.7.1:编辑面板视觉精修——输入框比底色更亮、去多余边框、细分隔线 */
|
||||||
.iwb-plp-dialog .iwb-plp-dbody{gap:10px;padding:12px;background: var(--plp-c9, #f4f5f7)}
|
.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(--plp-c1, #fff);border: 1px solid var(--plp-c10, #e6e8ec);border-radius:12px;padding:12px}
|
.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(--plp-c1, #fff);border: 1px solid var(--plp-c10, #e6e8ec);border-radius:12px;padding:10px 12px 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(--plp-c11, #eef0f3);background: var(--plp-c8, #fbfcfd);border-radius:9px;padding:10px 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(--plp-c1, #fff);border-color: var(--plp-c12, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
.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:4px}
|
.iwb-plp-dialog .iwb-plp-esplit{flex:0 0 6px;background:transparent;border-radius: 6px}
|
||||||
.iwb-plp-dialog .iwb-plp-esplit:hover{background: var(--plp-c13, #e7e9ee)}
|
.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:2px;background: var(--plp-c14, #d7dbe2)}
|
.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-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-vitem{padding:2px 0}
|
||||||
.iwb-plp-dialog .iwb-plp-vrow2{gap:6px}
|
.iwb-plp-dialog .iwb-plp-vrow2{gap:6px}
|
||||||
.iwb-plp-dialog .iwb-plp-vname{background: var(--plp-c8, #fbfcfd);border: 1px solid var(--plp-c15, #eceef2);border-radius:8px;height:32px;padding:0 10px;font-size:12.5px;color: var(--plp-c16, #33383f)}
|
.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(--plp-c1, #fff);border-color: var(--plp-c12, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
.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(--plp-c17, #aab0ba);width:22px;height:22px;line-height:20px}
|
.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-vi:hover{background: var(--plp-c18, #eef0f4);color: var(--plp-c3, #6b7280)}
|
.iwb-plp-dialog .iwb-plp-lrow span{color: var(--iwb-text2, #8a919c);font-size: 12px}
|
||||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--plp-c5, #f1ecff);color: var(--plp-c7, #5a3fd0)}
|
.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-vdesc{background: var(--plp-c8, #fbfcfd);border: 1px dashed var(--plp-c19, #e2e6ec);border-radius:7px;height:28px;margin-top:4px}
|
.iwb-plp-dialog .iwb-plp-lrow .iwb-input:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff)}
|
||||||
.iwb-plp-dialog .iwb-plp-lrow span{color: var(--plp-c20, #8a919c);font-size:11.5px}
|
|
||||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input{background: var(--plp-c8, #fbfcfd);border: 1px solid var(--plp-c15, #eceef2);border-radius:8px;height:32px}
|
|
||||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input:focus{background: var(--plp-c1, #fff);border-color: var(--plp-c12, #cfc3ff)}
|
|
||||||
/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */
|
/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */
|
||||||
.iwb-plp-ewrap{position:relative;flex:1 1 auto;min-height:0;display:flex;border-radius:9px;background: var(--plp-c8, #fbfcfd);border: 1px solid var(--plp-c11, #eef0f3)}
|
.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(--plp-c1, #fff);border-color: var(--plp-c12, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
.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{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-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(--plp-c21, #5b6472);pointer-events:none;z-index:0}
|
.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(--plp-c22, #1d2129);font-weight:600}
|
.iwb-plp-hlvar{color: var(--iwb-text, #1d2129);font-weight:600}
|
||||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--plp-c11, #eef0f3);color: var(--plp-c21, #5b6472)}
|
.iwb-plp-dialog .iwb-plp-vdesc{background:transparent;border: 1px dashed var(--iwb-plugin-border, #dfe3e9)}
|
||||||
.iwb-plp-dialog .iwb-plp-vdesc{background:transparent;border: 1px dashed var(--plp-c23, #dfe3e9)}
|
.iwb-plp-dvar{background:transparent;color: var(--iwb-text, #1d2129);font-weight:600;padding:0}
|
||||||
.iwb-plp-dvar{background:transparent;color: var(--plp-c22, #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{height:6px;margin:-3px 0 0;cursor:ns-resize;flex:0 0 auto;border-radius:3px}
|
.iwb-plp-hres:hover{background: var(--iwb-plugin-hover, #e7e9ee)}
|
||||||
.iwb-plp-hres:hover{background: var(--plp-c13, #e7e9ee)}
|
|
||||||
/* 正文可见性:textarea 透明,显示下方高亮层 */
|
/* 正文可见性:textarea 透明,显示下方高亮层 */
|
||||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap{flex:1 1 auto;min-height:0;position:relative;display:flex;background: var(--plp-c8, #fbfcfd);border: 1px solid var(--plp-c11, #eef0f3);border-radius:9px}
|
.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-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-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:7px 10px;resize:vertical;overflow:auto;font-size:12.5px}
|
.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(--plp-c22, #1d2129)!important;background: var(--plp-c1, #fff)!important;border-color: var(--plp-c19, #e2e6ec)!important}
|
.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(--plp-c24, #f4f6f9)!important}
|
.iwb-plp-insvar:hover{background: var(--iwb-plugin-inset, #f4f6f9)!important}
|
||||||
/* v1.7.5:编辑封面卡在框内;详情封面放大 */
|
/* 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{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 .iwb-plp-ecov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||||
@@ -481,7 +498,8 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
|||||||
tab-size:4!important;
|
tab-size:4!important;
|
||||||
}
|
}
|
||||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{overflow-y:auto!important;scrollbar-gutter:stable}
|
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{overflow-y:auto!important;scrollbar-gutter:stable}
|
||||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-hl{overflow:hidden!important}
|
/* 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:详情正文独立滚动,长文不再压到底部按钮 */
|
/* v1.7.9:详情正文独立滚动,长文不再压到底部按钮 */
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dbody{overflow:hidden;align-items:stretch}
|
.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-dright{flex:1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:hidden}
|
||||||
@@ -489,48 +507,48 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
|||||||
/* v1.8.0:详情标题/分组/标签移到封面下方;编辑标签改为输入+加号 */
|
/* v1.8.0:详情标题/分组/标签移到封面下方;编辑标签改为输入+加号 */
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
.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-dleftcol{flex:0 0 264px;width:264px;display:flex;flex-direction:column;min-width:0}
|
||||||
.iwb-plp-dtitle{font-size:18px;font-weight:650;line-height:1.35;margin-top:14px;color:var(--iwb-text,#1d2129)}
|
.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-dmeta{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:8px}
|
||||||
.iwb-plp-dgroup{font-size:11.5px;background: var(--plp-c18, #eef0f4);color: var(--plp-c21, #5b6472);border-radius:999px;padding:2px 9px}
|
.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:11.5px;background: var(--plp-c25, #f4f0ff);color: var(--plp-c7, #5a3fd0);border-radius:999px;padding:2px 9px}
|
.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:11.5px;color: var(--plp-c4, #9aa1ac)}
|
.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-tagwrap{display:flex;flex-direction:column;gap:6px;flex:1;min-width:0}
|
||||||
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap:5px}
|
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap: 6px}
|
||||||
.iwb-plp-tagchip{display:inline-flex;align-items:center;gap:4px;font-size:11.5px;background: var(--plp-c18, #eef0f4);border-radius:999px;padding:2px 8px;color: var(--plp-c26, #3f4450)}
|
.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(--plp-c4, #9aa1ac);font-style:normal}
|
.iwb-plp-tagx{cursor:pointer;color: var(--iwb-text-dim, #9aa1ac);font-style:normal}
|
||||||
.iwb-plp-tagx:hover{color: var(--plp-c27, #c0392b)}
|
.iwb-plp-tagx:hover{color: var(--iwb-err, #c0392b)}
|
||||||
.iwb-plp-tagrow{display:flex;gap:6px}
|
.iwb-plp-tagrow{display:flex;gap:6px}
|
||||||
.iwb-plp-tagin{flex:1;min-width:0;height:30px}
|
.iwb-plp-tagin{flex:1;min-width:0;height:30px}
|
||||||
.iwb-plp-lrow-tags{align-items:flex-start}
|
.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}
|
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;font-size:15px;line-height:28px}
|
||||||
/* v1.8.1:详情标题/分组/标签左对齐并带标题;标签加号对齐修复 */
|
/* 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-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:7px;margin-top:12px;align-items:flex-start}
|
.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-dmrow{display:flex;align-items:center;gap:10px;width:100%}
|
||||||
.iwb-plp-dmk{flex:0 0 30px;width:30px;font-size:11.5px;color: var(--plp-c4, #9aa1ac)}
|
.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:5px;min-width:0}
|
.iwb-plp-dmv{display:flex;flex-wrap:wrap;align-items:center;gap: 6px;min-width:0}
|
||||||
.iwb-plp-dgroup{font-size:12px;color: var(--plp-c26, #3f4450);background: var(--plp-c28, #f2f4f7);border-radius:6px;padding:2px 9px}
|
.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:11.5px;color: var(--plp-c7, #5a3fd0);background: var(--plp-c25, #f4f0ff);border-radius:6px;padding:2px 9px}
|
.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(--plp-c29, #b3b9c2)}
|
.iwb-plp-dempty{font-size:12px;color: var(--iwb-text-dim, #b3b9c2)}
|
||||||
.iwb-plp-dlen{font-size:12px;color: var(--plp-c20, #8a919c)}
|
.iwb-plp-dlen{font-size:12px;color: var(--iwb-text2, #8a919c)}
|
||||||
.iwb-plp-tagrow{display:flex;align-items:center;gap:6px}
|
.iwb-plp-tagrow{display:flex;align-items:center;gap:6px}
|
||||||
.iwb-plp-tagin{height:30px;border-radius:8px}
|
.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(--plp-c28, #f2f4f7);border: 1px solid var(--plp-c19, #e2e6ec);color: var(--plp-c21, #5b6472);font-size:16px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
|
.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(--plp-c30, #e9ecf1)}
|
.iwb-plp-tagadd:hover{background: var(--iwb-plugin-hover, #e9ecf1)}
|
||||||
/* v1.8.2:详情左右两栏卡片化 + 分割线 */
|
/* v1.8.2:详情左右两栏卡片化 + 分割线 */
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dbody{gap:14px;padding:16px;background: var(--plp-c9, #f4f5f7)}
|
.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(--plp-c31, #e8eaee);border-radius:14px;background: var(--plp-c1, #fff);align-self:flex-start}
|
.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-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:14px;color:var(--iwb-text,#1d2129)}
|
.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(--plp-c11, #eef0f3);gap:8px}
|
.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:14px 16px;border: 1px solid var(--plp-c31, #e8eaee);border-radius:14px;background: var(--plp-c1, #fff);overflow:hidden}
|
.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:11.5px;font-weight:600;color: var(--plp-c20, #8a919c);letter-spacing:.04em;padding-bottom:8px;margin-bottom:8px;border-bottom: 1px solid var(--plp-c11, #eef0f3);flex:0 0 auto}
|
.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:13.5px;line-height:2;color: var(--plp-c32, #3a4048)}
|
.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:详情左卡片撑到底、四边等距;正文恢复滚动不被底部遮挡 */
|
/* v1.8.3:详情左卡片撑到底、四边等距;正文恢复滚动不被底部遮挡 */
|
||||||
.iwb-plp-dialog-detail{display:flex;flex-direction:column;overflow:hidden}
|
.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:14px;padding:16px;background: var(--plp-c9, #f4f5f7)}
|
.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(--plp-c31, #e8eaee);border-radius:14px;background: var(--plp-c1, #fff)}
|
.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:14px 16px;border: 1px solid var(--plp-c31, #e8eaee);border-radius:14px;background: var(--plp-c1, #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-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}
|
.iwb-plp-dialog-detail .iwb-plp-dfooter{flex:0 0 auto}
|
||||||
/* v1.8.4:右卡片纵向拉伸填满,正文出现滚动条 */
|
/* v1.8.4:右卡片纵向拉伸填满,正文出现滚动条 */
|
||||||
@@ -539,23 +557,42 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
|||||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 0;min-height:0;overflow-y:auto!important;overflow-x:hidden}
|
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 0;min-height:0;overflow-y:auto!important;overflow-x:hidden}
|
||||||
/* v1.8.7:详情标题缩小;分组/标签去底色;元信息加分割线与行高 */
|
/* 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-dtitle{font-size:17px!important;font-weight:650;margin-top:12px}
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top:12px;padding-top:14px;border-top: 1px solid var(--plp-c11, #eef0f3);gap:10px}
|
.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-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(--plp-c4, #9aa1ac)}
|
.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:12.5px;line-height:1.6;color: var(--plp-c33, #2f3540)}
|
.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(--plp-c7, #5a3fd0);}
|
.iwb-plp-dialog-detail .iwb-plp-dtag{color: var(--iwb-plp-accent, #5a3fd0);}
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dlen{font-size:12.5px;line-height:1.6;color: var(--plp-c33, #2f3540)}
|
.iwb-plp-dialog-detail .iwb-plp-dlen{font-size: 13px;line-height:1.6;color: var(--iwb-text, #2f3540)}
|
||||||
/* v1.8.8:详情标题 14px;元信息行间浅分割线;封面底色更接近白色(编辑/详情统一) */
|
/* 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-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-dmeta{gap:0}
|
||||||
.iwb-plp-dialog-detail .iwb-plp-dmrow{padding:7px 0;border-bottom: 1px solid var(--plp-c34, #f3f5f8)}
|
.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-detail .iwb-plp-dmrow:last-child{border-bottom:0}
|
||||||
.iwb-plp-dialog .iwb-plp-dcov,.iwb-plp-dialog .iwb-plp-ecov{background: var(--plp-c35, #fcfcfd)!important}
|
.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}
|
.iwb-plp-dialog .iwb-plp-dcov .iwb-plp-cover,.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{background:transparent!important}
|
||||||
/* v1.8.19:编辑区高亮变量不得加粗——加粗会改变字形宽度,导致点击位置逐次向左偏移 */
|
/* v1.8.19:编辑区高亮变量不得加粗——加粗会改变字形宽度,导致点击位置逐次向左偏移 */
|
||||||
.iwb-plp-hlvar{font-weight:400!important;letter-spacing:normal!important}
|
.iwb-plp-hlvar{font-weight:400!important;letter-spacing:normal!important}
|
||||||
/* v1.8.20:编辑区不再用透明 textarea+高亮层(两层字体/换行差异会让点击坐标逐次偏移);正文直接由 textarea 渲染,插入点 100% 对应光标 */
|
/* v1.9.3:变量着色改为「textarea 只负责文字 + 背层只画浅主色色块」——
|
||||||
.iwb-plp-ewrap .iwb-plp-hl{display:none!important}
|
两层字体/换行/滚动条占位由 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}
|
.iwb-plp-ewrap .iwb-plp-etext{color:var(--iwb-text,#2a2f36)!important;background:transparent!important}
|
||||||
/* v1.8.21:高亮层隐藏后,正文文字必须可见(覆盖旧的 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}
|
.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} */
|
||||||
|
/* v1.13.1:变量栏去掉 i 圆按钮,按设计 token 在「行与行之间」画分割线(位置 2)。
|
||||||
|
依据 design-tokens.md §3.11:--iwb-set-divider 是容器内行间线,首行不画线。
|
||||||
|
注意该变量只在 .iwb-settings-modal 作用域定义,插件面板不在其中 ⇒ 按同一公式就地兜底,
|
||||||
|
否则会掉到全强度 --iwb-border(比规范深一档)。暗色下 --iwb-border 自动换值。
|
||||||
|
用相邻兄弟选择器,首项自然不画、末项之后也没有线;标题下与展开字段前都不另画线,
|
||||||
|
避免一屏出现三层线。整行 hover + 展开态 caret 接替原来 i 按钮的「可点击」提示。 */
|
||||||
|
.iwb-plp-vitem + .iwb-plp-vitem{border-top:var(--iwb-bw, 1px) solid var(--iwb-set-divider, color-mix(in srgb, var(--iwb-border) 55%, transparent));padding-top:var(--iwb-space-8)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vrow2{padding:0 var(--iwb-space-4)}
|
||||||
|
.iwb-plp-dialog .iwb-plp-vrow2:hover{background:var(--iwb-plugin-hover);border-radius:var(--iwb-radius-control, var(--iwb-radius-card))}
|
||||||
|
.iwb-plp-vitem.is-open .iwb-plp-vcaret{color:var(--iwb-plp-accent, var(--iwb-text2))}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
// 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.13.1", /version:\s*'1\.13\.1'/.test(src))
|
||||||
|
ok('package.json version = 1.13.1',
|
||||||
|
JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version === '1.13.1')
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 8) v1.12.0 变量四字段(名称/内容/说明/占位符)+ 节点多行变量框 ----
|
||||||
|
ok('节点变量框已换成 textarea 且显式 rows=1(默认 2 行会把单行撑成两行高)',
|
||||||
|
src.includes("el('textarea', { class: 'iwb-input iwb-plp-nin', rows: '1'"))
|
||||||
|
ok('自动增高三步:先 height=auto 再读 scrollHeight',
|
||||||
|
/ta\.style\.height = 'auto'[\s\S]{0,160}scrollHeight/.test(src))
|
||||||
|
ok('节点变量框拦 pointerdown(宿主白名单不含 textarea,否则拖选文字会拖动节点)',
|
||||||
|
src.includes("inp.addEventListener('pointerdown'") && src.includes('e.stopPropagation()'))
|
||||||
|
ok('节点变量框只在内容溢出时拦滚轮(不破坏画布缩放)',
|
||||||
|
src.includes('if (inp.scrollHeight > inp.clientHeight + 1) e.stopPropagation()'))
|
||||||
|
ok('v1.13.0 插入变量时选中的原文直接当占位符(塞不进 {} 才退到变量N)',
|
||||||
|
src.includes('var embed = contentKeyOf(picked)') && src.includes("if (picked) varEd.preset(name, { def: picked })"))
|
||||||
|
ok('v1.12.3 编辑器只有三个输入项(名称/内容/说明),占位符框已移除',
|
||||||
|
src.includes("'变量名称(节点上最多显示 4 字)'") &&
|
||||||
|
src.includes("class: 'iwb-input iwb-plp-vdef', rows: '3'") &&
|
||||||
|
src.includes("placeholder: '说明(可选)'") &&
|
||||||
|
!src.includes('iwb-plp-vkey') && !src.includes('占位符(≤'))
|
||||||
|
ok('v1.12.3 变量区的功能性说明文案已删(顶部 hint / 橙色 tip / 底部 khint)',
|
||||||
|
!src.includes('名称只影响显示 · 内容可多行 · 与正文双向同步') &&
|
||||||
|
!src.includes('iwb-plp-vtip') && !src.includes('iwb-plp-vkhint'))
|
||||||
|
ok('sync 保留 label 与 def(旧实现每次 sync 吃掉名称与内容)',
|
||||||
|
src.includes('label: prev.label, desc: prev.desc, def: prev.def'))
|
||||||
|
ok('v1.13.0 内容框显示「内容」,空时退回正文里的键',
|
||||||
|
src.includes('function bodyOf (v) { return v.def || v.key }'))
|
||||||
|
ok('v1.12.3 新建节点不再预填 vars(输入框默认为空)',
|
||||||
|
src.includes('vars: {}, cover:') && !src.includes('vars: defaultVarsOf'))
|
||||||
|
ok('v1.12.3 节点 placeholder 取「说明 → 内容」(不填说明时展示内容文案)',
|
||||||
|
src.includes('placeholder: v.desc || v.def ||'))
|
||||||
|
ok('v1.12.3 节点输入框默认空(不再回退 def 当 value)',
|
||||||
|
src.includes("inp.value = String((d.vars && d.vars[v.key]) || '')"))
|
||||||
|
ok('v1.12.3 留空时输出用内容兜底(否则 outputText 会把这段从提示词删掉)',
|
||||||
|
src.includes('vv[k] = st.inputs[k].value || st.defOf(k)') &&
|
||||||
|
src.includes('eff[k] = String(raw[k] || \'\') || defOf(k)'))
|
||||||
|
ok('v1.12.3 vars 只存原始输入(空就是空,下次打开仍为空)',
|
||||||
|
src.includes('var patch = { vars: raw, text: outputText'))
|
||||||
|
ok('v1.12.3 「未填」只统计既没填也没内容的变量',
|
||||||
|
src.includes('!st.defOf(k).trim()) missing++'))
|
||||||
|
ok('v1.12.3 defOf 挂在 st 上(scheduleUpdate 与 syncTplNode 是两个函数,局部声明会 ReferenceError)',
|
||||||
|
src.includes('st.defOf = function (k)') &&
|
||||||
|
src.includes("var defOf = (typeof st.defOf === 'function') ? st.defOf"))
|
||||||
|
ok('v1.12.3 空框按 placeholder 折行量高度(提示第二行不被裁)',
|
||||||
|
src.includes('ta.value = ph; restore = true') && src.includes('if (restore) { ta.value = \'\''))
|
||||||
|
ok('样式:变量行不再是固定 26px 单行',
|
||||||
|
!css.includes('.iwb-plp-nrow{display:flex;align-items:center;gap:6px;height:26px}') &&
|
||||||
|
css.includes('.iwb-plp-nrow{display:flex;align-items:flex-start;gap:6px;min-height:26px}'))
|
||||||
|
ok('样式:变量框不再固定 24px 高',
|
||||||
|
!css.includes('.iwb-plp-nin{flex:1;height:24px') && css.includes('min-height:24px'))
|
||||||
|
ok('样式:收起态摘要与三角已定义',
|
||||||
|
css.includes('.iwb-plp-vsum{') && css.includes('.iwb-plp-vcaret{'))
|
||||||
|
ok('样式:内容多行框 3 行起步(min-height 66px,overflow 由 JS 控制)',
|
||||||
|
css.includes('.iwb-plp-vdef{height:auto;min-height:66px'))
|
||||||
|
|
||||||
|
ok('v1.13.0 节点变量标签列定宽 4 字(56px),输入框左边缘才对齐',
|
||||||
|
css.includes('.iwb-plp-nk{flex:0 0 56px;width:56px;max-width:56px') &&
|
||||||
|
!css.includes('.iwb-plp-nk{flex:0 0 auto'))
|
||||||
|
ok('v1.13.0 名称框提示说明「节点上最多显示 4 字」',
|
||||||
|
src.includes("'变量名称(节点上最多显示 4 字)'"))
|
||||||
|
|
||||||
|
// ---- 10) v1.13.0 名称 ⇄ 正文联动 + 内容框 10 行 ----
|
||||||
|
ok('v1.13.0 内容框上限 10 行(VDEF_MAX 212,用户要求 +4 行)',
|
||||||
|
/var VDEF_MAX = 212/.test(src) && !/var VDEF_MAX = 132/.test(src))
|
||||||
|
ok('v1.13.0 占位符上限与所有正则一致(KEY_MAX 60,5 处 {1,60})',
|
||||||
|
/var KEY_MAX = 60/.test(src) &&
|
||||||
|
(src.match(/\{1,60\}/g) || []).length >= 6 &&
|
||||||
|
!/\{1,24\}/.test(src))
|
||||||
|
ok('v1.13.0 内容 → 正文联动:改内容即改 {…}(curText 取实时正文,不吃防抖的旧值)',
|
||||||
|
src.includes('function curText ()') &&
|
||||||
|
src.includes('var next = contentKeyOf(area.value)') &&
|
||||||
|
src.includes("cur.split('{' + old + '}').join('{' + next + '}')"))
|
||||||
|
ok('v1.13.0 名称只改节点显示,不动正文',
|
||||||
|
/nameIn\.addEventListener\('input', function \(\) \{\s*\n\s*v\.label = nameIn\.value\s*\n\s*title\.textContent = v\.label \|\| v\.key/.test(src))
|
||||||
|
ok('v1.13.0 内容塞不进 {} 时保留原键 + 摘要里提示(绝不硬塞,免得变量被识别掉)',
|
||||||
|
src.includes('正文未同步(需单行 ≤') &&
|
||||||
|
/v1\.13\.0: 不|v1\.13\.0:不再在打开时改写正文/.test(src))
|
||||||
|
ok('v1.13.0 抽屉把实时正文 getText 交给编辑器',
|
||||||
|
src.includes('getText: function () { return textIn.value }'))
|
||||||
|
|
||||||
|
// ---- 9) v1.12.2 搜索框常驻(中文输入法组合态不被重建打断)----
|
||||||
|
ok('v1.12.2 搜索框不再在 render 里 clear(fixed) 重建(render 只清其余节点)',
|
||||||
|
!/function render \(\) \{\s*\n\s*clear\(fixed\); clear\(scrollBox\)/.test(src) &&
|
||||||
|
src.includes('Array.prototype.slice.call(fixed.children).forEach'))
|
||||||
|
ok('v1.12.2 搜索框只创建一次(ensureSearchRow 复用同一个节点)',
|
||||||
|
src.includes('function ensureSearchRow ()') && src.includes('if (searchRow) return searchRow'))
|
||||||
|
ok('v1.12.2 输入法组合态:compositionstart/end + 组合中不重排',
|
||||||
|
src.includes("searchEl.addEventListener('compositionstart'") &&
|
||||||
|
src.includes("searchEl.addEventListener('compositionend'") &&
|
||||||
|
/composing \|\| \(e && e\.isComposing\)\) return/.test(src))
|
||||||
|
ok('v1.12.2 结果重排走 120ms 防抖(打字不再逐键全量重建)',
|
||||||
|
src.includes('function scheduleResults ()') && src.includes('setTimeout(function () { searchTimer = 0; render() }, 120)'))
|
||||||
|
ok('v1.12.2 清空搜索后焦点回到搜索框',
|
||||||
|
/query = ''; render\(\)\s*\n\s*if \(searchEl\)/.test(src))
|
||||||
|
|
||||||
|
// ---- 11) v1.13.1 变量栏:去 i 按钮 + 行间分割线(位置 2) ----
|
||||||
|
ok('v1.13.1 源码不再创建 i 圆按钮(iwb-plp-vi / iBtn 全清)',
|
||||||
|
!/\biwb-plp-vi\b/.test(src) && !/iBtn/.test(src))
|
||||||
|
ok('v1.13.1 样式表不再有 .iwb-plp-vi 规则(词边界防误伤 vitem/vin)',
|
||||||
|
!/\biwb-plp-vi\b/.test(css))
|
||||||
|
ok('v1.13.1 变量行只挂 caret / 名称 / 摘要三项(整行点击是唯一入口)',
|
||||||
|
/row\.appendChild\(caret\); row\.appendChild\(title\); row\.appendChild\(sum\)\s*$/m.test(src))
|
||||||
|
// 依据 design-tokens.md §3.11:容器内行间用 --iwb-set-divider,首行不画线。
|
||||||
|
ok('v1.13.1 分割线用 --iwb-set-divider(1px 实线,暗色自动跟随)',
|
||||||
|
/\.iwb-plp-vitem \+ \.iwb-plp-vitem\{[^}]*border-top:var\(--iwb-bw, 1px\) solid var\(--iwb-set-divider/.test(css))
|
||||||
|
ok('v1.13.1 该 token 只在设置弹窗作用域定义 ⇒ 按同公式就地兜底,不掉到全强度边框',
|
||||||
|
/var\(--iwb-set-divider, color-mix\(in srgb, var\(--iwb-border\) 55%, transparent\)\)/.test(css) &&
|
||||||
|
!/var\(--iwb-set-divider, var\(--iwb-plugin-border/.test(css))
|
||||||
|
ok('v1.13.1 用相邻兄弟选择器 ⇒ 首行不画线、末行之后也没有线',
|
||||||
|
/\.iwb-plp-vitem \+ \.iwb-plp-vitem\{/.test(css) &&
|
||||||
|
!/\.iwb-plp-vitem:last-child\{[^}]*border-bottom/.test(css))
|
||||||
|
ok('v1.13.1 旧的每行虚线边框已删除',
|
||||||
|
!/\.iwb-plp-vitem\{[^}]*border-bottom:1px dashed/.test(css))
|
||||||
|
ok('v1.13.1 dialog 作用域不再用 border:0 盖掉行间线',
|
||||||
|
!/\.iwb-plp-dialog \.iwb-plp-vitem\{[^}]*border:0/.test(css))
|
||||||
|
ok('v1.13.1 标题下 / 展开字段前都不另画线(一屏只留一层线)',
|
||||||
|
!/\.iwb-plp-vhead\{[^}]*border/.test(css) &&
|
||||||
|
!/\.iwb-plp-vfield\{[^}]*border-top/.test(css))
|
||||||
|
ok('v1.13.1 去掉 i 后补整行 hover 反馈(接替「可点击」提示)',
|
||||||
|
/\.iwb-plp-dialog \.iwb-plp-vrow2:hover\{[^}]*var\(--iwb-plugin-hover\)/.test(css))
|
||||||
|
ok('v1.13.1 展开态 caret 用主色呼应状态',
|
||||||
|
/\.iwb-plp-vitem\.is-open \.iwb-plp-vcaret\{[^}]*var\(--iwb-plp-accent/.test(css))
|
||||||
|
ok('v1.13.1 新增尺寸全走 token(无裸 px/font-size)',
|
||||||
|
/\.iwb-plp-vitem \+ \.iwb-plp-vitem\{[^}]*padding-top:var\(--iwb-space-8\)/.test(css) &&
|
||||||
|
/\.iwb-plp-dialog \.iwb-plp-vrow2\{padding:0 var\(--iwb-space-4\)/.test(css))
|
||||||
|
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
// 搜索框中文输入法回归验证(v1.12.2 起)
|
||||||
|
// 为什么单独一个脚本:宿主 CI 里没有 playwright,跑不进 harness 门禁;但改搜索框时值得手动跑一次。
|
||||||
|
// 依赖宿主仓的 playwright:image-workbench-desktop/node_modules/playwright。
|
||||||
|
// 用法:node promptlib/tools/plp-search-ime-check.mjs
|
||||||
|
// PLP_SRC=/path/to/other/index.js node promptlib/tools/plp-search-ime-check.mjs # 对照旧版
|
||||||
|
// 覆盖:组合态中搜索框不被重建 / 不按拼音过滤 / 光标不跳末尾 / 上屏后过滤生效
|
||||||
|
// CDP Input.imeSetComposition 走真实输入法通道
|
||||||
|
// 验证 promptlib 搜索框:中文输入法组合态不再被打断(v1.12.2)
|
||||||
|
// 做法:真实 Chromium 加载插件源码 + 最小宿主 stub,挂载面板后
|
||||||
|
// ① 模拟 compositionstart → input(拼音) → compositionend(中文)
|
||||||
|
// ② 用 CDP Input.imeSetComposition 走真实输入法通道
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||||
|
// playwright 装在宿主仓(插件仓没有 node_modules);按本级目录推,别写死绝对路径
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const PW = pathToFileURL(path.resolve(HERE, '..', '..', '..', 'image-workbench-desktop', 'node_modules', 'playwright', 'index.mjs')).href
|
||||||
|
const { chromium } = await import(PW)
|
||||||
|
|
||||||
|
const SRC = process.env.PLP_SRC || path.resolve(HERE, '..', 'src', 'index.js')
|
||||||
|
|
||||||
|
const browser = await chromium.launch()
|
||||||
|
const page = await browser.newPage({ viewport: { width: 900, height: 700 } })
|
||||||
|
const errors = []
|
||||||
|
page.on('pageerror', (e) => errors.push(String(e)))
|
||||||
|
|
||||||
|
await page.setContent('<!doctype html><html><body style="margin:0"><div id="host"></div></body></html>')
|
||||||
|
|
||||||
|
// 宿主 stub:捕获 register → 拿到 factory
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } }
|
||||||
|
})
|
||||||
|
|
||||||
|
await page.addScriptTag({ path: SRC })
|
||||||
|
|
||||||
|
const mountInfo = await page.evaluate(() => {
|
||||||
|
const prompts = [
|
||||||
|
{ id: 'a', name: '水光肌底妆', text: '水光 底妆 提亮 通透', group: '美妆' },
|
||||||
|
{ id: 'b', name: '复古胶片', text: '胶片 颗粒 暖调 怀旧', group: '风格' },
|
||||||
|
{ id: 'c', name: '水果静物', text: '水果 静物 清新', group: '美妆' },
|
||||||
|
{ id: 'd', name: '水波纹背景', text: '水波 纹理 背景', group: '风格' },
|
||||||
|
]
|
||||||
|
const groups = [{ id: '美妆', name: '美妆' }, { id: '风格', name: '风格' }]
|
||||||
|
const data = { schemaVersion: 3, prompts, groups }
|
||||||
|
const ctx = {
|
||||||
|
data: {
|
||||||
|
read: async () => data,
|
||||||
|
write: async () => ({ ok: true }),
|
||||||
|
set: async () => ({ ok: true }),
|
||||||
|
get: async () => null,
|
||||||
|
},
|
||||||
|
promptlib: {
|
||||||
|
list: async () => ({ prompts, groups }),
|
||||||
|
save: async () => ({ ok: true }),
|
||||||
|
insert: async () => ({ ok: true }),
|
||||||
|
notify: () => {},
|
||||||
|
onChanged: () => () => {},
|
||||||
|
filePut: async () => ({ ok: true }),
|
||||||
|
fileGet: async () => '',
|
||||||
|
fileList: async () => [],
|
||||||
|
fileRemove: async () => ({ ok: true }),
|
||||||
|
fileStat: async () => ({ count: 0, bytes: 0 }),
|
||||||
|
},
|
||||||
|
files: {
|
||||||
|
put: async () => ({ ok: true }),
|
||||||
|
get: async () => '',
|
||||||
|
list: async () => [],
|
||||||
|
remove: async () => ({ ok: true }),
|
||||||
|
stat: async () => ({ count: 0, bytes: 0 }),
|
||||||
|
},
|
||||||
|
storage: { set: () => {}, get: () => null },
|
||||||
|
ui: { registerPanel: (p) => { window.__panel = p }, toast: () => {} },
|
||||||
|
}
|
||||||
|
window.__reg.factory(ctx)
|
||||||
|
const host = document.getElementById('host')
|
||||||
|
window.__dispose = window.__panel.mount(host)
|
||||||
|
return { meta: window.__reg.meta.version, hasPanel: !!window.__panel }
|
||||||
|
})
|
||||||
|
console.log('插件版本', mountInfo.meta, '面板已注册', mountInfo.hasPanel)
|
||||||
|
|
||||||
|
await page.waitForTimeout(600)
|
||||||
|
|
||||||
|
const countCards = () => page.evaluate(() => document.querySelectorAll('.iwb-plp-card').length)
|
||||||
|
const before = await countCards()
|
||||||
|
console.log('初始卡片数', before)
|
||||||
|
|
||||||
|
// ---- ① 合成事件:组合态期间搜索框不能被重建、列表不能按拼音过滤 ----
|
||||||
|
const synth = await page.evaluate(async () => {
|
||||||
|
const host = document.getElementById('host')
|
||||||
|
const el = host.querySelector('input.iwb-grow')
|
||||||
|
el.__mark = 'same-node'
|
||||||
|
el.focus()
|
||||||
|
el.setSelectionRange(2, 2)
|
||||||
|
|
||||||
|
const fire = (type, extra) => el.dispatchEvent(new (type === 'input' ? InputEvent : CompositionEvent)(type, Object.assign({ bubbles: true }, extra || {})))
|
||||||
|
|
||||||
|
fire('compositionstart', { data: '' })
|
||||||
|
// 拼音逐个上屏:真实输入法每敲一个字母都会派发 isComposing=true 的 input
|
||||||
|
el.value = '水'
|
||||||
|
fire('input', { isComposing: true, data: 'shui' })
|
||||||
|
el.value = '水s'
|
||||||
|
fire('input', { isComposing: true, data: 'shuis' })
|
||||||
|
await new Promise((r) => setTimeout(r, 250)) // 超过 120ms 防抖窗口
|
||||||
|
|
||||||
|
const during = {
|
||||||
|
sameNode: host.querySelector('input.iwb-grow') === el,
|
||||||
|
connected: el.isConnected,
|
||||||
|
mark: el.__mark,
|
||||||
|
cards: document.querySelectorAll('.iwb-plp-card').length,
|
||||||
|
selStart: el.selectionStart,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上屏
|
||||||
|
el.value = '水'
|
||||||
|
el.dispatchEvent(new CompositionEvent('compositionend', { bubbles: true, data: '水' }))
|
||||||
|
await new Promise((r) => setTimeout(r, 300))
|
||||||
|
|
||||||
|
const after = {
|
||||||
|
sameNode: host.querySelector('input.iwb-grow') === el,
|
||||||
|
value: el.value,
|
||||||
|
cards: document.querySelectorAll('.iwb-plp-card').length,
|
||||||
|
names: Array.from(document.querySelectorAll('.iwb-plp-t')).map((n) => n.textContent),
|
||||||
|
}
|
||||||
|
return { during, after }
|
||||||
|
})
|
||||||
|
console.log('组合态中 :', JSON.stringify(synth.during))
|
||||||
|
console.log('上屏之后 :', JSON.stringify(synth.after))
|
||||||
|
|
||||||
|
// ---- ② CDP 真实输入法通道 ----
|
||||||
|
const cdp = await page.context().newCDPSession(page)
|
||||||
|
await page.evaluate(() => { const el = document.querySelector('#host input.iwb-grow'); el.value = ''; el.focus() })
|
||||||
|
await cdp.send('Input.imeSetComposition', { text: 'shui', selectionStart: 4, selectionEnd: 4 })
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
const composingState = await page.evaluate(() => document.querySelector('#host input.iwb-grow').value)
|
||||||
|
await cdp.send('Input.insertText', { text: '水' })
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const imeState = await page.evaluate(() => ({
|
||||||
|
value: document.querySelector('#host input.iwb-grow').value,
|
||||||
|
cards: document.querySelectorAll('.iwb-plp-card').length,
|
||||||
|
names: Array.from(document.querySelectorAll('.iwb-plp-t')).map((n) => n.textContent),
|
||||||
|
}))
|
||||||
|
console.log('imeSetComposition 后 value =', JSON.stringify(composingState))
|
||||||
|
console.log('真实输入法提交后 :', JSON.stringify(imeState))
|
||||||
|
|
||||||
|
// ---- 判定 ----
|
||||||
|
const checks = [
|
||||||
|
['组合态中搜索框未被重建(同一节点)', synth.during.sameNode === true],
|
||||||
|
['组合态中搜索框仍在文档里(没被移除)', synth.during.connected === true],
|
||||||
|
['组合态中保留自定义属性(未被克隆替换)', synth.during.mark === 'same-node'],
|
||||||
|
['组合态中不按拼音过滤(卡片数不变)', synth.during.cards === before],
|
||||||
|
['组合态中光标位置不被打到末尾', synth.during.selStart === 2],
|
||||||
|
['上屏后搜索框仍是同一节点', synth.after.sameNode === true],
|
||||||
|
['上屏后搜索框值 = 水', synth.after.value === '水'],
|
||||||
|
['上屏后过滤到 3 条含水的结果', synth.after.cards === 3],
|
||||||
|
['真实输入法:组合态拼音留在框内', composingState === 'shui'],
|
||||||
|
['真实输入法:提交后可搜到 3 条', imeState.cards === 3],
|
||||||
|
]
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
for (const [name, okv] of checks) { if (!okv) failed++; console.log((okv ? '✓ ' : '✗ ') + name) }
|
||||||
|
if (errors.length) { console.log('页面异常:', errors.slice(0, 3)) }
|
||||||
|
console.log(failed ? `✗ ${failed} 项失败` : '✓ 全部通过')
|
||||||
|
await page.screenshot({ path: '/tmp/plp-search.png' })
|
||||||
|
await browser.close()
|
||||||
|
process.exit(failed ? 1 : 0)
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
// 变量编辑器 + 模板节点 渲染验证(v1.12.3)
|
||||||
|
// 真实 Chromium 挂载 promptlib 面板,走「新建」弹窗与模板节点 render,
|
||||||
|
// 断言用户能看到的三件事:
|
||||||
|
// ① 变量区只有 名称 / 内容 / 说明 三个输入项,没有占位符、没有功能性说明文案
|
||||||
|
// ② 内容框是多行(3 行起步,不再被压成一行裁切)
|
||||||
|
// ③ 节点输入框默认为空,不填说明时灰字显示「内容」文案
|
||||||
|
// 依赖宿主仓 playwright:node promptlib/tools/plp-vars-editor-check.mjs
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const PW = pathToFileURL(path.resolve(HERE, '..', '..', '..', 'image-workbench-desktop', 'node_modules', 'playwright', 'index.mjs')).href
|
||||||
|
const { chromium } = await import(PW)
|
||||||
|
const SRC = process.env.PLP_SRC || path.resolve(HERE, '..', 'src', 'index.js')
|
||||||
|
const CSS = path.resolve(HERE, '..', 'styles.css')
|
||||||
|
|
||||||
|
const browser = await chromium.launch()
|
||||||
|
const page = await browser.newPage({ viewport: { width: 1080, height: 900 }, deviceScaleFactor: 2 })
|
||||||
|
const errors = []
|
||||||
|
page.on('pageerror', (e) => errors.push(String(e)))
|
||||||
|
|
||||||
|
await page.setContent('<!doctype html><html><head><meta charset="utf-8"></head><body style="margin:0"><div id="host"></div><div id="nodehost"></div></body></html>')
|
||||||
|
await page.addStyleTag({ path: CSS })
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } }
|
||||||
|
})
|
||||||
|
await page.addScriptTag({ path: SRC })
|
||||||
|
|
||||||
|
const info = await page.evaluate(() => {
|
||||||
|
const prompts = [{ id: 'a', name: '示例', text: '风格 {主色调}', group: '默认' }]
|
||||||
|
const groups = [{ id: '默认', name: '默认' }]
|
||||||
|
const data = { schemaVersion: 3, prompts, groups }
|
||||||
|
let nodeDef = null
|
||||||
|
const ctx = {
|
||||||
|
data: { read: async () => data, write: async () => ({ ok: true }), set: async () => ({ ok: true }), get: async () => null },
|
||||||
|
promptlib: {
|
||||||
|
list: async () => ({ prompts, groups }), save: async () => ({ ok: true }), insert: async () => ({ ok: true }),
|
||||||
|
notify: () => {}, onChanged: () => () => {},
|
||||||
|
filePut: async () => ({ ok: true }), fileGet: async () => '', fileList: async () => [], fileRemove: async () => ({ ok: true }), fileStat: async () => ({ count: 0, bytes: 0 }),
|
||||||
|
},
|
||||||
|
files: { put: async () => ({ ok: true }), get: async () => '', list: async () => [], remove: async () => ({ ok: true }), stat: async () => ({ count: 0, bytes: 0 }) },
|
||||||
|
storage: { set: () => {}, get: () => null },
|
||||||
|
ui: { registerPanel: (p) => { window.__panel = p }, toast: () => {} },
|
||||||
|
nodes: { register: (def) => { nodeDef = def } },
|
||||||
|
canvas: { screenToWorld: (x, y) => ({ x, y }) },
|
||||||
|
canvasWrite: { createNode: () => 'n1', createImageNode: () => 'n2' },
|
||||||
|
}
|
||||||
|
window.__reg.factory(ctx)
|
||||||
|
window.__panel.mount(document.getElementById('host'))
|
||||||
|
|
||||||
|
// 模板节点:同样用真实 render
|
||||||
|
const node = {
|
||||||
|
id: 'n1',
|
||||||
|
data: {
|
||||||
|
name: '测试模板',
|
||||||
|
tpl: '风格 {主色调},背景 {留白}',
|
||||||
|
vdefs: [
|
||||||
|
{ key: '主色调', label: '主色调', desc: '', def: '橙红 金色描边' },
|
||||||
|
{ key: '留白', label: '留白', desc: '画面留白比例', def: '四周留 10%' },
|
||||||
|
],
|
||||||
|
vars: {}, // 默认为空(新节点就是这个状态)
|
||||||
|
outKind: 'prompt',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// 收集节点写回的 patch —— 用户最关心的「留空时提示词还有没有内容」只能从这里看
|
||||||
|
window.__patches = []
|
||||||
|
const props = { onUpdate: (id, patch) => { window.__patches.push(patch) }, onSelect: () => {}, selected: false }
|
||||||
|
nodeDef.render(node, props, document.getElementById('nodehost'))
|
||||||
|
return { version: window.__reg.meta.version, nodeTitle: nodeDef.title }
|
||||||
|
})
|
||||||
|
console.log('插件版本', info.version, '| 节点', info.nodeTitle)
|
||||||
|
|
||||||
|
await page.waitForTimeout(500)
|
||||||
|
|
||||||
|
// ---- 打开「新建」弹窗,正文里写一段带变量的提示词 ----
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const btn = Array.from(document.querySelectorAll('#host button')).find((b) => b.textContent.trim() === '新建')
|
||||||
|
btn.click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(400)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const ta = document.querySelector('.iwb-plp-etext')
|
||||||
|
ta.value = '一个顶部金色、顶部和底部有金色边缘、底部悬挂红色,整体风格 {主色调}'
|
||||||
|
ta.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
// 展开第一个变量
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const row = document.querySelector('.iwb-plp-vrow2')
|
||||||
|
if (row) row.click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(400)
|
||||||
|
|
||||||
|
const dom = await page.evaluate(() => {
|
||||||
|
const q = (s) => document.querySelectorAll(s).length
|
||||||
|
const area = document.querySelector('.iwb-plp-vdef')
|
||||||
|
const nodeIns = Array.from(document.querySelectorAll('#nodehost .iwb-plp-nin'))
|
||||||
|
const text = document.querySelector('.iwb-plp-vars').textContent
|
||||||
|
return {
|
||||||
|
counts: { name: q('.iwb-plp-vname'), def: q('.iwb-plp-vdef'), desc: q('.iwb-plp-vdesc'), key: q('.iwb-plp-vkey') },
|
||||||
|
areaH: area ? Math.round(area.getBoundingClientRect().height) : 0,
|
||||||
|
areaRows: area ? area.getAttribute('rows') : '',
|
||||||
|
varText: text.replace(/\s+/g, ' ').trim().slice(0, 80),
|
||||||
|
nodeInputs: nodeIns.map((n) => ({ tag: n.tagName, value: n.value, ph: n.placeholder })),
|
||||||
|
nodeLabels: Array.from(document.querySelectorAll('#nodehost .iwb-plp-nk')).map((n) => n.textContent),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('编辑器输入项', JSON.stringify(dom.counts))
|
||||||
|
console.log('内容框高 / rows =', dom.areaH, '/', dom.areaRows)
|
||||||
|
console.log('变量区文案 =', JSON.stringify(dom.varText))
|
||||||
|
console.log('节点输入框 =', JSON.stringify(dom.nodeInputs))
|
||||||
|
console.log('节点标签 =', JSON.stringify(dom.nodeLabels))
|
||||||
|
|
||||||
|
// ---- v1.13.0:改内容 ⇒ 正文 {…} 同步(用户报的「没关联」)+ 输入框不失焦 ----
|
||||||
|
const link = await page.evaluate(async () => {
|
||||||
|
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||||
|
const area = document.querySelector('.iwb-plp-vdef')
|
||||||
|
const nameIn = document.querySelector('.iwb-plp-vname')
|
||||||
|
const ta = document.querySelector('.iwb-plp-etext')
|
||||||
|
const before = ta.value
|
||||||
|
area.focus()
|
||||||
|
area.value = '主色'
|
||||||
|
area.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
await wait(80)
|
||||||
|
const afterContent = ta.value
|
||||||
|
const focusOnArea = document.activeElement === area
|
||||||
|
nameIn.value = '主面积色'
|
||||||
|
nameIn.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
await wait(80)
|
||||||
|
return {
|
||||||
|
before,
|
||||||
|
afterContent,
|
||||||
|
afterName: ta.value,
|
||||||
|
focused: focusOnArea,
|
||||||
|
hl: document.querySelectorAll('.iwb-plp-hlvar').length,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('改内容前正文 =', JSON.stringify(link.before), '→', JSON.stringify(link.afterContent))
|
||||||
|
|
||||||
|
// ---- v1.13.0:内容框最高 10 行(212px)后框内滚动 ----
|
||||||
|
const areaMax = await page.evaluate(() => {
|
||||||
|
const area = document.querySelector('.iwb-plp-vdef')
|
||||||
|
area.value = Array.from({ length: 20 }, (_, i) => '第' + (i + 1) + '行内容').join('\n')
|
||||||
|
area.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
return { h: Math.round(area.getBoundingClientRect().height), scroll: area.scrollHeight > area.clientHeight + 1 }
|
||||||
|
})
|
||||||
|
// ---- v1.13.0:节点变量名列定宽 4 字(56px)----
|
||||||
|
const nkWidth = await page.evaluate(() => {
|
||||||
|
const nk = document.querySelector('#nodehost .iwb-plp-nk')
|
||||||
|
return nk ? Math.round(nk.getBoundingClientRect().width) : 0
|
||||||
|
})
|
||||||
|
console.log('内容框封顶高 =', areaMax.h, '| 滚动 =', areaMax.scroll, '| 节点名宽 =', nkWidth)
|
||||||
|
|
||||||
|
// ---- 留空 / 填写 / 再清空:看节点写回的 text 与 vars ----
|
||||||
|
const flow = await page.evaluate(async () => {
|
||||||
|
const ta = document.querySelectorAll('#nodehost .iwb-plp-nin')[0]
|
||||||
|
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||||
|
// 已填:用用户输入
|
||||||
|
ta.value = '深蓝'
|
||||||
|
ta.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
await wait(420)
|
||||||
|
const filled = window.__patches[window.__patches.length - 1]
|
||||||
|
// 清空:回到内容兜底
|
||||||
|
ta.value = ''
|
||||||
|
ta.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
await wait(420)
|
||||||
|
const cleared = window.__patches[window.__patches.length - 1]
|
||||||
|
return {
|
||||||
|
filledText: filled && filled.text,
|
||||||
|
filledVars: filled && filled.vars,
|
||||||
|
clearedText: cleared && cleared.text,
|
||||||
|
clearedVars: cleared && cleared.vars,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('填写后 text =', JSON.stringify(flow.filledText))
|
||||||
|
console.log('清空后 text =', JSON.stringify(flow.clearedText), '| vars =', JSON.stringify(flow.clearedVars))
|
||||||
|
|
||||||
|
await page.screenshot({ path: '/tmp/plp-vars-1123.png', fullPage: true })
|
||||||
|
|
||||||
|
const checks = [
|
||||||
|
['编辑器只有 名称/内容/说明 三项(无占位符框)', dom.counts.key === 0 && dom.counts.name === 1 && dom.counts.def === 1 && dom.counts.desc === 1],
|
||||||
|
['内容框 rows=3', dom.areaRows === '3'],
|
||||||
|
['内容框实际高度 ≥ 60px(3 行,不再被压成一行)', dom.areaH >= 60],
|
||||||
|
['变量区没有功能性说明文案', !/名称只影响显示|与正文双向同步/.test(dom.varText)],
|
||||||
|
['变量区没有「占位符」字眼', !/占位符/.test(dom.varText)],
|
||||||
|
['节点输入框默认为空(2 个都是空 value)', dom.nodeInputs.length === 2 && dom.nodeInputs.every((n) => n.value === '')],
|
||||||
|
['无说明时 placeholder = 内容文案', dom.nodeInputs[0] && dom.nodeInputs[0].ph === '橙红 金色描边'],
|
||||||
|
['有说明时 placeholder = 说明', dom.nodeInputs[1] && dom.nodeInputs[1].ph === '画面留白比例'],
|
||||||
|
['节点仍是 textarea(可多行)', dom.nodeInputs.every((n) => n.tag === 'TEXTAREA')],
|
||||||
|
['填写后提示词用填写值', /深蓝/.test(flow.filledText || '') && !/橙红 金色描边/.test(flow.filledText || '')],
|
||||||
|
['填写值写进 vars', flow.filledVars && flow.filledVars['主色调'] === '深蓝'],
|
||||||
|
['清空后提示词回到「内容」兜底(不丢内容)', /橙红 金色描边/.test(flow.clearedText || '') && !/\{主色调\}/.test(flow.clearedText || '')],
|
||||||
|
['清空后 vars 里是空串(输入框下次仍为空)', flow.clearedVars && flow.clearedVars['主色调'] === ''],
|
||||||
|
['v1.13.0 改内容 ⇒ 正文 {…} 同步改名(联动)', /\{主色调\}/.test(link.before) && /\{主色\}/.test(link.afterContent) && !/\{主色调\}/.test(link.afterContent)],
|
||||||
|
['v1.13.0 改内容时高亮块仍在(正文重绘后不丢色)', link.hl >= 1],
|
||||||
|
['v1.13.0 改内容时焦点留在内容框(不重绘整行)', link.focused === true],
|
||||||
|
['v1.13.0 改名称不动正文(名称只影响节点显示)', link.afterName === link.afterContent],
|
||||||
|
['v1.13.0 内容框最多 10 行(约 222px 盒高)后框内滚动', areaMax.h > 200 && areaMax.h <= 230 && areaMax.scroll === true],
|
||||||
|
['v1.13.0 节点变量名列定宽 4 字(56px)', nkWidth === 56],
|
||||||
|
]
|
||||||
|
let failed = 0
|
||||||
|
for (const [name, okv] of checks) { if (!okv) failed++; console.log((okv ? '✓ ' : '✗ ') + name) }
|
||||||
|
if (errors.length) console.log('页面异常:', errors.slice(0, 3))
|
||||||
|
console.log(failed ? `✗ ${failed} 项失败` : '✓ 全部通过')
|
||||||
|
await browser.close()
|
||||||
|
process.exit(failed ? 1 : 0)
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
// promptlib v1.12.0 变量编辑器行为测试(纯 node + 极简 DOM stub)
|
||||||
|
// 覆盖三件静态断言看不出来的事:
|
||||||
|
// 1) 输入名称/内容后 list() 带 label / def
|
||||||
|
// 2) sync 之后 label / def 不被吃掉(旧实现会)
|
||||||
|
// 3) v1.13.0:正文 {} 里放的就是内容 —— 改内容,正文跟着改;名称只影响节点显示
|
||||||
|
// 运行:node promptlib/tools/vars-editor-test.mjs
|
||||||
|
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')
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, extra) => { if (!cond) failed++; console.log((cond ? '✓ ' : '✗ ') + name + (cond ? '' : ' » ' + (extra || ''))) }
|
||||||
|
|
||||||
|
// ---- 从真实源码里切出:变量检测/自适应/长名判定 + 变量编辑器 ----
|
||||||
|
const helpers = src.slice(src.indexOf(' function detectVars (text) {'), src.indexOf(' // 提交给下游/生图的文本'))
|
||||||
|
const editorStart = src.indexOf(' // ===== v1.5.0:变量编辑器')
|
||||||
|
const editorEndMark = ' return { node: box, sync: sync, preset: preset, list: function () { return list }, values: values }\n }'
|
||||||
|
const editorEnd = src.indexOf(editorEndMark)
|
||||||
|
if (editorStart < 0 || editorEnd < 0) { console.error('✗ 找不到 makeVarsEditor 源码段'); process.exit(1) }
|
||||||
|
const editor = src.slice(editorStart, editorEnd + editorEndMark.length)
|
||||||
|
|
||||||
|
// ---- 极简 DOM stub(只实现编辑器用到的 API)----
|
||||||
|
function makeEl (tag, attrs, ...kids) {
|
||||||
|
const n = {
|
||||||
|
tag,
|
||||||
|
className: (attrs && attrs.class) || '',
|
||||||
|
textContent: (attrs && attrs.text != null) ? String(attrs.text) : '',
|
||||||
|
title: '',
|
||||||
|
value: '',
|
||||||
|
rows: (attrs && attrs.rows != null) ? String(attrs.rows) : '',
|
||||||
|
style: {},
|
||||||
|
children: [],
|
||||||
|
listeners: {},
|
||||||
|
}
|
||||||
|
n.appendChild = (c) => { n.children.push(c); return c }
|
||||||
|
n.addEventListener = (ev, fn) => { n.listeners[ev] = fn }
|
||||||
|
n.focus = () => { n.focused = true }
|
||||||
|
n.blur = () => {}
|
||||||
|
kids.forEach((k) => { if (k) n.appendChild(k) })
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
const walk = (n, out = []) => { out.push(n); (n.children || []).forEach((c) => walk(c, out)); return out }
|
||||||
|
const byClass = (root, cls) => walk(root).filter((n) => String(n.className || '').split(/\s+/).includes(cls))[0]
|
||||||
|
const fire = (n, ev, extra) => { if (n && n.listeners[ev]) n.listeners[ev](Object.assign({ stopPropagation () {}, preventDefault () {}, target: n }, extra || {})) }
|
||||||
|
|
||||||
|
const sandbox = {
|
||||||
|
el: makeEl,
|
||||||
|
clear: (n) => { n.children.length = 0 },
|
||||||
|
notify: (msg) => { sandbox.__notified.push(String(msg)) },
|
||||||
|
__notified: [],
|
||||||
|
setTimeout,
|
||||||
|
console,
|
||||||
|
}
|
||||||
|
vm.createContext(sandbox)
|
||||||
|
vm.runInContext(helpers + '\n' + editor, sandbox)
|
||||||
|
const makeVarsEditor = sandbox.makeVarsEditor
|
||||||
|
ok('能从真实源码跑起 makeVarsEditor', typeof makeVarsEditor === 'function')
|
||||||
|
|
||||||
|
// ---- 1) 新建:正文里的 {变量} 自动进入列表 ----
|
||||||
|
const text1 = '风格 {主色},背景 {留白}'
|
||||||
|
let t1 = text1
|
||||||
|
const ed = makeVarsEditor(text1, [], (t) => { t1 = t }, { getText: () => t1 })
|
||||||
|
ok('自动识别 2 个变量', ed.list().length === 2 && ed.list()[0].key === '主色')
|
||||||
|
ok('默认收起(首项展开区无名称框)', !byClass(ed.node, 'iwb-plp-vname'))
|
||||||
|
|
||||||
|
// ---- 2) 展开后填名称与多行内容 ----
|
||||||
|
const item0 = byClass(ed.node, 'iwb-plp-vrow2')
|
||||||
|
fire(item0, 'click')
|
||||||
|
const nameIn = byClass(ed.node, 'iwb-plp-vname')
|
||||||
|
const area = byClass(ed.node, 'iwb-plp-vdef')
|
||||||
|
ok('展开后出现名称框与内容框', !!nameIn && !!area)
|
||||||
|
nameIn.value = '主色调'
|
||||||
|
fire(nameIn, 'input')
|
||||||
|
area.value = '橙红\n金色描边'
|
||||||
|
fire(area, 'input')
|
||||||
|
ok('名称写入 label', ed.list()[0].label === '主色调')
|
||||||
|
ok('多行内容写入 def(换行保留)', ed.list()[0].def === '橙红\n金色描边')
|
||||||
|
ok('v1.13.0 名称只写 label,不改正文', t1 === text1)
|
||||||
|
|
||||||
|
// ---- 3) 正文改动触发 sync,label/def 不能被吃掉(旧实现的 bug)----
|
||||||
|
t1 = t1 + ',再加 {补充}'
|
||||||
|
ed.sync(t1)
|
||||||
|
ok('sync 后变量数 3', ed.list().length === 3)
|
||||||
|
ok('sync 后 label 仍在', ed.list()[0].label === '主色调')
|
||||||
|
ok('sync 后 def 仍在', ed.list()[0].def === '橙红\n金色描边')
|
||||||
|
ok('新增变量默认空名称', ed.list()[2].label === '')
|
||||||
|
|
||||||
|
// ---- 3b) 用户直接在正文里改 {} 的字 ⇒ 名称/说明不能丢(内容跟着这段字走)----
|
||||||
|
t1 = t1.replace('{主色}', '{深红金}')
|
||||||
|
ed.sync(t1)
|
||||||
|
ok('正文里直接改占位符 ⇒ 名称不丢', ed.list()[0].label === '主色调')
|
||||||
|
ok('正文里直接改占位符 ⇒ 内容 = 新键', ed.list()[0].def === '深红金', JSON.stringify(ed.list()))
|
||||||
|
|
||||||
|
// ---- 4) v1.13.0:正文占位符 = 内容原文(老数据本来就该这样,不再改写)----
|
||||||
|
const LONG = '一个顶部金色、顶部和底部有金色边缘、底部悬挂红色'
|
||||||
|
const longText = '{' + LONG + '}'
|
||||||
|
let patched = longText
|
||||||
|
const ed2 = makeVarsEditor(longText, [{ key: LONG, label: '物品名称', desc: '主题内容描述', def: '' }], (t) => { patched = t }, { getText: () => patched })
|
||||||
|
ok('打开时正文保持原样(不动存档、不偷偷改名)', patched === longText && ed2.list()[0].key === LONG)
|
||||||
|
const it2 = byClass(ed2.node, 'iwb-plp-vrow2')
|
||||||
|
fire(it2, 'click')
|
||||||
|
const area2 = byClass(ed2.node, 'iwb-plp-vdef')
|
||||||
|
ok('内容框显示的就是正文里 {…} 那段字', area2 && area2.value === LONG)
|
||||||
|
ok('收起摘要显示内容字数', walk(ed2.node).some((n) => /内容 \d+ 字/.test(String(n.textContent || ''))))
|
||||||
|
ok('v1.12.3 展开区只有 名称/内容/说明 三个输入(占位符框已移除)',
|
||||||
|
!!byClass(ed2.node, 'iwb-plp-vname') && !!byClass(ed2.node, 'iwb-plp-vdef') &&
|
||||||
|
!!byClass(ed2.node, 'iwb-plp-vdesc') && !byClass(ed2.node, 'iwb-plp-vkey'))
|
||||||
|
ok('v1.12.3 内容框是多行 textarea(rows=3)',
|
||||||
|
area2.tag === 'textarea' && area2.rows === '3')
|
||||||
|
|
||||||
|
// 改内容 ⇒ 正文跟着改(用户要的「关联」)
|
||||||
|
area2.value = '一个顶部金色、顶部和底部有银色边缘、底部悬挂红色'
|
||||||
|
fire(area2, 'input')
|
||||||
|
ok('v1.13.0 改内容 ⇒ 正文 {…} 立刻跟着改',
|
||||||
|
patched === '{一个顶部金色、顶部和底部有银色边缘、底部悬挂红色}' &&
|
||||||
|
ed2.list()[0].key === '一个顶部金色、顶部和底部有银色边缘、底部悬挂红色')
|
||||||
|
ok('改内容后名称不受影响', ed2.list()[0].label === '物品名称')
|
||||||
|
|
||||||
|
// 名称改回:不应影响正文
|
||||||
|
const nameIn2 = byClass(ed2.node, 'iwb-plp-vname')
|
||||||
|
const beforeName = patched
|
||||||
|
nameIn2.value = '主色'
|
||||||
|
fire(nameIn2, 'input')
|
||||||
|
ok('v1.13.0 改名称不动正文', patched === beforeName && ed2.list()[0].label === '主色')
|
||||||
|
|
||||||
|
// 内容塞不进 {}(含换行 / 超 60 字)⇒ 正文保留原键,不硬塞
|
||||||
|
const beforeBreak = patched
|
||||||
|
area2.value = '第一行\n第二行'
|
||||||
|
fire(area2, 'input')
|
||||||
|
ok('v1.13.0 内容含换行 ⇒ 正文保留原键(塞不进 {} 就不塞)',
|
||||||
|
patched === beforeBreak && ed2.list()[0].def === '第一行\n第二行')
|
||||||
|
ok('v1.13.0 摘要提示「正文未同步」', walk(ed2.node).some((n) => /正文未同步/.test(String(n.textContent || ''))))
|
||||||
|
|
||||||
|
// ---- 5) 顶部功能性说明文案与橙色提示都不再渲染 ----
|
||||||
|
ok('v1.12.3 顶部只剩「变量」标签(无功能说明)',
|
||||||
|
!walk(ed2.node).some((n) => String(n.textContent || '').indexOf('名称只影响显示') >= 0))
|
||||||
|
ok('v1.12.3 不再出现「占位符」相关提示',
|
||||||
|
!walk(ed2.node).some((n) => String(n.textContent || '').indexOf('占位符') >= 0))
|
||||||
|
|
||||||
|
// ---- 6) preset:插入长句后内容落位、默认展开 ----
|
||||||
|
const ed4 = makeVarsEditor('{变量1}', [], () => {})
|
||||||
|
ed4.preset('变量1', { def: '一整句原文' })
|
||||||
|
ok('preset 写入内容', ed4.list()[0].def === '一整句原文')
|
||||||
|
ok('preset 展开该变量(出现名称框)', !!byClass(ed4.node, 'iwb-plp-vname'))
|
||||||
|
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
// 变量栏视觉核对(v1.13.1):真实 Chromium 挂载 promptlib 编辑弹窗,亮/暗两套截图。
|
||||||
|
// 依据 docs/standards/promptlib-style-baseline.md §四「发布前检查清单」:
|
||||||
|
// 静态渲染截图核对(颜色、滚动、输入框描边)+ 真机连点验证 selectionStart 不漂移。
|
||||||
|
// 依赖宿主仓 playwright:node promptlib/tools/vars-panel-visual-check.mjs
|
||||||
|
import path from 'node:path'
|
||||||
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||||
|
|
||||||
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const HOST = path.resolve(HERE, '..', '..', '..', 'image-workbench-desktop')
|
||||||
|
const PW = pathToFileURL(path.resolve(HOST, 'node_modules', 'playwright', 'index.mjs')).href
|
||||||
|
const { chromium } = await import(PW)
|
||||||
|
const SRC = path.resolve(HERE, '..', 'src', 'index.js')
|
||||||
|
const CSS = path.resolve(HERE, '..', 'styles.css')
|
||||||
|
const TOKENS = path.resolve(HOST, 'src', 'design-tokens.css')
|
||||||
|
const HOSTCSS = path.resolve(HOST, 'style.css')
|
||||||
|
|
||||||
|
let failed = 0
|
||||||
|
const ok = (name, cond, actual) => {
|
||||||
|
if (!cond) failed++
|
||||||
|
console.log((cond ? '✓ ' : '✗ ') + name + (actual === undefined ? '' : ' → ' + JSON.stringify(actual)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const browser = await chromium.launch()
|
||||||
|
const page = await browser.newPage({ viewport: { width: 1200, height: 900 }, deviceScaleFactor: 2 })
|
||||||
|
const errors = []
|
||||||
|
page.on('pageerror', (e) => errors.push(String(e)))
|
||||||
|
|
||||||
|
await page.setContent('<!doctype html><html><head><meta charset="utf-8"></head><body style="margin:0"><div id="host"></div></body></html>')
|
||||||
|
await page.addStyleTag({ path: TOKENS })
|
||||||
|
await page.addStyleTag({ path: HOSTCSS })
|
||||||
|
await page.addStyleTag({ path: CSS })
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.IWBPluginHost = { register: (meta, factory) => { window.__reg = { meta, factory } } }
|
||||||
|
})
|
||||||
|
await page.addScriptTag({ path: SRC })
|
||||||
|
|
||||||
|
const info = await page.evaluate(() => {
|
||||||
|
const prompts = [{ id: 'a', name: '示例', text: '风格 {写实摄影}', group: '默认' }]
|
||||||
|
const groups = [{ id: '默认', name: '默认' }]
|
||||||
|
const data = { schemaVersion: 3, prompts, groups }
|
||||||
|
const ctx = {
|
||||||
|
data: { read: async () => data, write: async () => ({ ok: true }), set: async () => ({ ok: true }), get: async () => null },
|
||||||
|
promptlib: {
|
||||||
|
list: async () => ({ prompts, groups }), save: async () => ({ ok: true }), insert: async () => ({ ok: true }),
|
||||||
|
notify: () => {}, onChanged: () => () => {},
|
||||||
|
filePut: async () => ({ ok: true }), fileGet: async () => '', fileList: async () => [], fileRemove: async () => ({ ok: true }), fileStat: async () => ({ count: 0, bytes: 0 }),
|
||||||
|
},
|
||||||
|
files: { put: async () => ({ ok: true }), get: async () => '', list: async () => [], remove: async () => ({ ok: true }), stat: async () => ({ count: 0, bytes: 0 }) },
|
||||||
|
storage: { set: () => {}, get: () => null },
|
||||||
|
ui: { registerPanel: (p) => { window.__panel = p }, toast: () => {} },
|
||||||
|
nodes: { register: () => {} },
|
||||||
|
canvas: { screenToWorld: (x, y) => ({ x, y }) },
|
||||||
|
canvasWrite: { createNode: () => 'n1', createImageNode: () => 'n2' },
|
||||||
|
}
|
||||||
|
window.__reg.factory(ctx)
|
||||||
|
window.__panel.mount(document.getElementById('host'))
|
||||||
|
return { version: window.__reg.meta.version }
|
||||||
|
})
|
||||||
|
ok('插件版本 = 1.13.1', info.version === '1.13.1', info.version)
|
||||||
|
|
||||||
|
// 打开「新建」弹窗,正文写四个变量,展开第 2 行
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const btn = Array.from(document.querySelectorAll('#host button')).find((b) => b.textContent.trim() === '新建')
|
||||||
|
btn.click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(350)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const ta = document.querySelector('.iwb-plp-etext')
|
||||||
|
ta.value = '风格 {写实摄影},字体 {手写书法},人物 {女生},卖点 {价格与利益点},画面简洁'
|
||||||
|
ta.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(450)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const rows = document.querySelectorAll('.iwb-plp-vrow2')
|
||||||
|
if (rows[1]) rows[1].click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(250)
|
||||||
|
|
||||||
|
const geo = await page.evaluate(() => {
|
||||||
|
const items = Array.from(document.querySelectorAll('.iwb-plp-vitem'))
|
||||||
|
const rows = Array.from(document.querySelectorAll('.iwb-plp-vrow2'))
|
||||||
|
const head = document.querySelector('.iwb-plp-vhead')
|
||||||
|
const caret = document.querySelector('.iwb-plp-vitem.is-open .iwb-plp-vcaret')
|
||||||
|
const border = (el) => {
|
||||||
|
const s = getComputedStyle(el)
|
||||||
|
return { top: s.borderTopWidth, bottom: s.borderBottomWidth, color: s.borderTopColor, padTop: s.paddingTop }
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
iBtn: document.querySelectorAll('.iwb-plp-vi').length,
|
||||||
|
items: items.length,
|
||||||
|
rows: rows.length,
|
||||||
|
borders: items.map(border),
|
||||||
|
headBorder: head ? getComputedStyle(head).borderBottomWidth : '',
|
||||||
|
vfieldBorder: getComputedStyle(document.querySelector('.iwb-plp-vfield') || document.body).borderTopWidth,
|
||||||
|
caretOpen: caret ? getComputedStyle(caret).color : '',
|
||||||
|
caretClosed: rows[0] ? getComputedStyle(rows[0].querySelector('.iwb-plp-vcaret')).color : '',
|
||||||
|
rowPad: rows[0] ? getComputedStyle(rows[0]).padding : '',
|
||||||
|
hlvar: document.querySelectorAll('.iwb-plp-hlvar').length,
|
||||||
|
inputs: document.querySelectorAll('.iwb-plp-vname, .iwb-plp-vdef, .iwb-plp-vdesc').length,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('几何 / 计算样式 =', JSON.stringify(geo))
|
||||||
|
|
||||||
|
ok('不再渲染 i 圆按钮', geo.iBtn === 0, geo.iBtn)
|
||||||
|
ok('4 个变量都渲染出来', geo.items === 4 && geo.rows === 4, geo.items)
|
||||||
|
ok('首行不画线(顶部/底部都 0)',
|
||||||
|
geo.borders[0] && geo.borders[0].top === '0px' && geo.borders[0].bottom === '0px', geo.borders[0])
|
||||||
|
ok('第 2/3/4 行顶部各 1px 实线(位置 2)',
|
||||||
|
geo.borders.slice(1).every((b) => b && b.top === '1px'), geo.borders.slice(1).map((b) => b.top))
|
||||||
|
ok('末行之后没有多余的线', geo.borders[3] && geo.borders[3].bottom === '0px', geo.borders[3])
|
||||||
|
// color-mix 在 Chromium 里会解析成 color(srgb … / a),老版本则是 rgba(…, a)
|
||||||
|
const alphaOf = (s) => {
|
||||||
|
const str = String(s)
|
||||||
|
const m = str.match(/rgba\([^)]*,\s*([\d.]+)\)/) || str.match(/color\([^)]*\/\s*([\d.]+)\)/)
|
||||||
|
return m ? Number(m[1]) : 1
|
||||||
|
}
|
||||||
|
ok('线色是规范 55% 淡线(半透明,没掉到全强度 --iwb-border)',
|
||||||
|
/^(rgba\(|color\(srgb)/.test(geo.borders[1].color) && Math.abs(alphaOf(geo.borders[1].color) - 0.55) < 0.02, geo.borders[1].color)
|
||||||
|
ok('标题下不画线(组标题靠间距分层)', geo.headBorder === '0px', geo.headBorder)
|
||||||
|
ok('展开字段前不另画线', geo.vfieldBorder === '0px', geo.vfieldBorder)
|
||||||
|
ok('展开态 caret 用主色、与收起态可区分',
|
||||||
|
geo.caretOpen !== geo.caretClosed && /^rgb\(/.test(geo.caretOpen), { open: geo.caretOpen, closed: geo.caretClosed })
|
||||||
|
ok('展开态三个输入框仍在,且输入框描边未丢', geo.inputs === 3, geo.inputs)
|
||||||
|
ok('正文变量浅主色色块仍在(v1.9.3 两层着色没被破坏)', geo.hlvar >= 1, geo.hlvar)
|
||||||
|
|
||||||
|
// hover:整行反馈接替被删掉的 i 按钮
|
||||||
|
await page.locator('.iwb-plp-vrow2').nth(2).hover()
|
||||||
|
await page.waitForTimeout(80)
|
||||||
|
const hoverBg = await page.evaluate(() => getComputedStyle(document.querySelectorAll('.iwb-plp-vrow2')[2]).backgroundColor)
|
||||||
|
ok('整行 hover 有浅底反馈', hoverBg !== 'rgba(0, 0, 0, 0)' && hoverBg !== 'transparent', hoverBg)
|
||||||
|
|
||||||
|
// 基线硬要求:连点正文 textarea 三次,selectionStart 不能逐次左移
|
||||||
|
const ta = page.locator('.iwb-plp-etext')
|
||||||
|
const box = await ta.boundingBox()
|
||||||
|
const clicks = []
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
await page.mouse.click(box.x + 120, box.y + 18)
|
||||||
|
clicks.push(await page.evaluate(() => document.querySelector('.iwb-plp-etext').selectionStart))
|
||||||
|
}
|
||||||
|
ok('正文连点 3 次 selectionStart 不漂移(两层着色未复发)',
|
||||||
|
clicks[0] === clicks[1] && clicks[1] === clicks[2], clicks)
|
||||||
|
|
||||||
|
await page.mouse.move(0, 0)
|
||||||
|
await page.screenshot({ path: '/tmp/plp-vars-1131-light.png', fullPage: true })
|
||||||
|
|
||||||
|
// 暗色:同一套 token 自动跟随
|
||||||
|
await page.evaluate(() => document.documentElement.classList.add('theme-dark'))
|
||||||
|
await page.waitForTimeout(150)
|
||||||
|
const dark = await page.evaluate(() => ({
|
||||||
|
border: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[1]).borderTopColor,
|
||||||
|
width: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[1]).borderTopWidth,
|
||||||
|
first: getComputedStyle(document.querySelectorAll('.iwb-plp-vitem')[0]).borderTopWidth,
|
||||||
|
}))
|
||||||
|
ok('暗色下线宽不变、颜色自动跟随 token',
|
||||||
|
dark.width === '1px' && dark.first === '0px' && dark.border !== geo.borders[1].color, dark)
|
||||||
|
await page.screenshot({ path: '/tmp/plp-vars-1131-dark.png', fullPage: true })
|
||||||
|
|
||||||
|
ok('页面无 JS 报错', errors.length === 0, errors)
|
||||||
|
console.log('截图:/tmp/plp-vars-1131-light.png、/tmp/plp-vars-1131-dark.png')
|
||||||
|
console.log(failed ? ('✗ ' + failed + ' 项失败') : '✓ 全部通过')
|
||||||
|
if (failed) process.exitCode = 1
|
||||||
|
await browser.close()
|
||||||
@@ -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)
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
`ensureStyle()` 原本只在 `mount()`(面板)里调用 ⇒ **没打开过「风格库」面板**时,节点体是无样式的裸 DOM,
|
`ensureStyle()` 原本只在 `mount()`(面板)里调用 ⇒ **没打开过「风格库」面板**时,节点体是无样式的裸 DOM,
|
||||||
`<img class="iwb-ssn-thumb">` 按原图尺寸铺满整个节点(真机表现:图片"跑出来了")。
|
`<img class="iwb-ssn-thumb">` 按原图尺寸铺满整个节点(真机表现:图片"跑出来了")。
|
||||||
现在 setup 注册变体前注入一次,`renderStyleNode()` 里再兜一次(幂等)。
|
现在 setup 注册变体前注入一次,`renderStyleNode()` 里再兜一次(幂等)。
|
||||||
回归用例:`tools/e2e-test-site.mjs` 第 9 段(不开面板直接进存档画布,断言缩略图宽高 ≈56px)。
|
回归用例:`tools/harness.mjs` 的「样式表在脚本执行时就已注入(不开面板、不跑 setup 也在)」闸门,以及缩略图 56px 方块的断言。
|
||||||
|
|
||||||
### v1.3.2(2026-11-14)注入点再提前到脚本执行 + 缩略图内联兜底
|
### v1.3.2(2026-11-14)注入点再提前到脚本执行 + 缩略图内联兜底
|
||||||
|
|
||||||
@@ -182,15 +182,14 @@
|
|||||||
数据与图片都是公网 `https://`,桌面宿主 `tauri.conf.json` 的 `img-src … https:` / `connect-src … https:` 已经放行。
|
数据与图片都是公网 `https://`,桌面宿主 `tauri.conf.json` 的 `img-src … https:` / `connect-src … https:` 已经放行。
|
||||||
对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
||||||
|
|
||||||
## 测试(三层,从快到慢)
|
## 测试(两层,从快到慢)
|
||||||
|
|
||||||
| 层 | 命令 | 覆盖什么 | 依赖 |
|
| 层 | 命令 | 覆盖什么 | 依赖 |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、截图 | 无(自带 mock 宿主) |
|
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、CSS 注入闸门、截图 | 无(自带 mock 宿主 + 真 Chromium) |
|
||||||
| 线上数据真网 | `node tools/e2e-real.mjs`(10 项) | styles.json 真拉得到、卡片渲染、样式节点入口 | 网络 |
|
| 线上数据真网 | `node tools/e2e-real.mjs`(10 项) | styles.json 真拉得到、卡片渲染、样式节点入口 | 网络 |
|
||||||
| 桌面客户端端到端 | `node tools/e2e-test-site.mjs`(15 项) | **宿主新接口到底接上没有**:进画布 → 开资源库 → 点「样式节点」→ 节点体由插件渲染、示例图默认勾选、变量输入不失焦、多变量不裁切、收起生效 | 桌面客户端已装本插件(`SITE=` 换地址,`HEADED=1` 看着跑) |
|
|
||||||
|
|
||||||
前两支只验插件自己;**第三支才验宿主**,发布宿主改动后必跑。
|
两支都验插件自己;发布宿主改动后,在桌面客户端市场里确认版本与加载状态,并用真实存档画布核对样式节点体(harness 的 CSS 闸门已覆盖「不开面板直接进画布」这一关键场景)。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
|
||||||
let chromium = null
|
let chromium = null
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
// 真机验收:**测试站上「宿主新接口 + 本插件」端到端**跑通(harness / e2e-real 都覆盖不到的那一层)。
|
|
||||||
//
|
|
||||||
// 为什么单独一支:
|
|
||||||
// - `tools/harness.mjs` 跑在合成宿主里,验不了「宿主的 PluginDomBody / 声明式参考图」是否真的接上;
|
|
||||||
// - `tools/e2e-real.mjs` 验的是「线上真网 + 插件面板」,不去点画布、不落节点。
|
|
||||||
// 这支脚本在**真的 test 站**里:双击进工作台 → 开资源库 → 点风格 → 点「样式节点」→ 检查节点体与输入体验。
|
|
||||||
//
|
|
||||||
// 用法:
|
|
||||||
// node tools/e2e-test-site.mjs # 默认 https://test.image-workbench-web.pages.dev/
|
|
||||||
// SITE=https://xxx.pages.dev/ node tools/e2e-test-site.mjs
|
|
||||||
// HEADED=1 node tools/e2e-test-site.mjs # 看着它跑
|
|
||||||
//
|
|
||||||
// 前置:宿主已部署含「插件节点体 + 声明式参考图」的版本,且 style-source 已在 KV 清单里。
|
|
||||||
// 全程只读:不动线上数据,浏览器用一次性 profile(跑完即弃)。
|
|
||||||
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import path from 'node:path'
|
|
||||||
import fs from 'node:fs'
|
|
||||||
|
|
||||||
const HERE = path.dirname(new URL(import.meta.url).pathname)
|
|
||||||
let chromium = null
|
|
||||||
for (const base of [path.resolve(HERE, '../..'), path.resolve(HERE, '../../../image-workbench-web'), process.cwd()]) {
|
|
||||||
const pkg = path.join(base, 'package.json')
|
|
||||||
if (!fs.existsSync(pkg)) continue
|
|
||||||
try { chromium = createRequire(pkg)('playwright').chromium; break } catch { /* 换下一个 */ }
|
|
||||||
}
|
|
||||||
if (!chromium) {
|
|
||||||
console.error('找不到 playwright:请在插件仓根目录或宿主仓(image-workbench-web)里跑')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
const SITE = process.env.SITE || 'https://test.image-workbench-web.pages.dev/'
|
|
||||||
let failed = 0
|
|
||||||
const check = (name, ok, detail) => {
|
|
||||||
if (!ok) failed++
|
|
||||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
|
||||||
}
|
|
||||||
const shot = (name) => page.screenshot({ path: path.join(HERE, 'shot-testsite-' + name + '.png') }).catch(() => {})
|
|
||||||
|
|
||||||
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
|
|
||||||
const browser = await chromium.launch({
|
|
||||||
headless: process.env.HEADED !== '1',
|
|
||||||
...(proxy ? { proxy: { server: proxy } } : {}),
|
|
||||||
})
|
|
||||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
|
||||||
const errors = []
|
|
||||||
page.on('pageerror', (e) => errors.push(String(e)))
|
|
||||||
|
|
||||||
await page.goto(SITE, { waitUntil: 'domcontentloaded' })
|
|
||||||
await page.waitForTimeout(1200)
|
|
||||||
// 启停状态只落 localStorage['iwb_plugins'](真机同款键)
|
|
||||||
await page.evaluate(() => {
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
|
|
||||||
})
|
|
||||||
await page.reload({ waitUntil: 'domcontentloaded' })
|
|
||||||
await page.waitForTimeout(4000)
|
|
||||||
|
|
||||||
// ── 1. 宿主版本:三处新接口的特征串(压缩后函数名会变,只能查字符串) ──────────
|
|
||||||
const host = await page.evaluate(async () => {
|
|
||||||
const src = await (await fetch('/app.js', { cache: 'no-store' })).text()
|
|
||||||
const ver = await (await fetch('/version.json', { cache: 'no-store' })).json().catch(() => ({}))
|
|
||||||
return {
|
|
||||||
pluginBody: src.includes('iwb-plugin-node-body'),
|
|
||||||
selfRef: src.includes('style-ref.png'),
|
|
||||||
combineTag: src.includes('iwb-combine-src-tag'),
|
|
||||||
version: ver.version || '',
|
|
||||||
len: src.length,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('测试站 app.js 含插件节点体 + 声明式参考图 + 组合来源标签', host.pluginBody && host.selfRef && host.combineTag,
|
|
||||||
JSON.stringify({ version: host.version, len: host.len }))
|
|
||||||
|
|
||||||
// ── 2. 插件已启用并激活 ───────────────────────────────────────────────────
|
|
||||||
const list = await page.evaluate(() => {
|
|
||||||
const h = window.IWBPluginHost
|
|
||||||
if (!h) return { noHost: true }
|
|
||||||
const l = typeof h.list === 'function' ? h.list() : []
|
|
||||||
return { list: l.map((p) => ({ id: p.id, version: p.version, enabled: p.enabled, active: p.active, error: p.error })) }
|
|
||||||
})
|
|
||||||
const me = (list.list || []).find((p) => p.id === 'style-source')
|
|
||||||
check('style-source 已启用并激活', Boolean(me && me.active), JSON.stringify(me))
|
|
||||||
|
|
||||||
// ── 3. 进工作台(首页卡片是「双击打开」,单击只是选中) ──────────────────────
|
|
||||||
await page.locator('.iwb-home-card').first().dblclick({ timeout: 8000 })
|
|
||||||
await page.waitForTimeout(3000)
|
|
||||||
const entered = await page.evaluate(() => ({ cards: document.querySelectorAll('.iwb-home-card').length }))
|
|
||||||
check('双击首页卡片进入画布', entered.cards === 0, JSON.stringify(entered))
|
|
||||||
|
|
||||||
// ── 4. 资源库 → 风格库 tab(N 是宿主「开关资源库」的快捷键) ──────────────────
|
|
||||||
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
|
|
||||||
await page.keyboard.press('n')
|
|
||||||
await page.waitForTimeout(1200)
|
|
||||||
const tabs = await page.evaluate(() => [...document.querySelectorAll('.iwb-res-tab')].map((b) => (b.textContent || '').trim()))
|
|
||||||
await page.evaluate(() => {
|
|
||||||
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
|
|
||||||
if (hit) hit.click()
|
|
||||||
})
|
|
||||||
check('资源库里有「风格库」tab', tabs.includes('风格库'), JSON.stringify(tabs))
|
|
||||||
|
|
||||||
// 风格数据是直连 GitHub Pages 拉的,首次没缓存时快时慢 ⇒ 轮询,别写死等待
|
|
||||||
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
|
|
||||||
await page.waitForTimeout(300)
|
|
||||||
const cards = await page.locator('.iwb-ss-card').count()
|
|
||||||
check('风格库渲染出卡片', cards > 0, String(cards))
|
|
||||||
|
|
||||||
// ── 5. 详情页底部三颗按钮:同行、均分、「样式节点」在最左(不是替换掉原来两颗) ──
|
|
||||||
await page.locator('.iwb-ss-card').first().click()
|
|
||||||
await page.waitForTimeout(900)
|
|
||||||
const footInfo = await page.evaluate(() => {
|
|
||||||
const btns = [...document.querySelectorAll('.iwb-ss-dfoot .iwb-ss-btn')]
|
|
||||||
return { labels: btns.map((b) => (b.textContent || '').trim()), tops: btns.map((b) => Math.round(b.getBoundingClientRect().top)) }
|
|
||||||
})
|
|
||||||
check('详情页底部三颗按钮同行,「样式节点」在最左',
|
|
||||||
footInfo.labels.length === 3 && footInfo.labels[0] === '样式节点' && new Set(footInfo.tops).size <= 1,
|
|
||||||
JSON.stringify(footInfo))
|
|
||||||
|
|
||||||
// ── 6. 点「样式节点」→ 节点落地,节点体由插件渲染 ─────────────────────────────
|
|
||||||
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
|
|
||||||
await page.waitForTimeout(1600)
|
|
||||||
await page.keyboard.press('Escape')
|
|
||||||
await page.waitForTimeout(400)
|
|
||||||
await page.keyboard.press('f')
|
|
||||||
await page.waitForTimeout(700)
|
|
||||||
await shot('node')
|
|
||||||
|
|
||||||
const node1 = await page.evaluate(() => {
|
|
||||||
const b = document.querySelector('.iwb-plugin-node-body')
|
|
||||||
if (!b) return { bodies: 0 }
|
|
||||||
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
|
|
||||||
return {
|
|
||||||
bodies: document.querySelectorAll('.iwb-plugin-node-body').length,
|
|
||||||
hasRoot: Boolean(b.querySelector('.iwb-ssn')),
|
|
||||||
name: (b.querySelector('.iwb-ssn-name') || {}).textContent || '',
|
|
||||||
code: (b.querySelector('.iwb-ssn-code') || {}).textContent || '',
|
|
||||||
rows: rows.length,
|
|
||||||
refChecked: b.querySelector('.iwb-ssn-ref input') ? b.querySelector('.iwb-ssn-ref input').checked : null,
|
|
||||||
hasRunBtn: [...b.querySelectorAll('button')].some((x) => /运行|生成/.test(x.textContent)),
|
|
||||||
foot: (b.querySelector('.iwb-ssn-foot') || {}).textContent || '',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('样式节点落地且节点体由插件渲染(.iwb-ssn 存在)', node1.hasRoot === true, JSON.stringify(node1).slice(0, 300))
|
|
||||||
check('节点体有名称/编号/变量行,示例图默认勾选,且没有生成按钮',
|
|
||||||
Boolean(node1.name) && Boolean(node1.code) && node1.refChecked === true && node1.hasRunBtn === false,
|
|
||||||
JSON.stringify(node1).slice(0, 300))
|
|
||||||
|
|
||||||
// ── 7. 变量输入不失焦、值不被重渲染覆盖(PluginDomBody 固定容器生效) ─────────
|
|
||||||
const typing = await page.evaluate(async () => {
|
|
||||||
const b = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
|
|
||||||
const input = b && b.querySelector('.iwb-ssn-row input')
|
|
||||||
if (!input) return { noBody: true }
|
|
||||||
input.focus()
|
|
||||||
input.value = '真机测试值'
|
|
||||||
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
||||||
await new Promise((r) => setTimeout(r, 700))
|
|
||||||
const b2 = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
|
|
||||||
const input2 = b2.querySelector('.iwb-ssn-row input')
|
|
||||||
return { sameInput: input === input2, kept: input2.value, focusKept: document.activeElement === input2 }
|
|
||||||
})
|
|
||||||
check('变量输入不失焦、值不被重渲染覆盖',
|
|
||||||
typing.sameInput === true && typing.kept === '真机测试值' && typing.focusKept === true, JSON.stringify(typing))
|
|
||||||
|
|
||||||
// ── 8. 变量多的样式:全部露出、不裁切、单行 28px、收起/展开生效 ──────────────
|
|
||||||
// 上一步把焦点留在了变量输入框里;宿主的快捷键在 INPUT 上直接 return ⇒ 先 blur,否则按 n 只会打出一个字母
|
|
||||||
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
|
|
||||||
await page.keyboard.press('n')
|
|
||||||
await page.waitForTimeout(1200)
|
|
||||||
await page.evaluate(() => {
|
|
||||||
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
|
|
||||||
if (hit) hit.click()
|
|
||||||
})
|
|
||||||
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
|
|
||||||
|
|
||||||
let picked = null
|
|
||||||
const total = await page.locator('.iwb-ss-card').count()
|
|
||||||
for (let i = 0; i < Math.min(total, 30); i++) {
|
|
||||||
await page.locator('.iwb-ss-card').nth(i).click()
|
|
||||||
await page.waitForTimeout(380)
|
|
||||||
const info = await page.evaluate(() => ({
|
|
||||||
n: document.querySelectorAll('.iwb-ss-dbody .iwb-ss-var').length,
|
|
||||||
title: (document.querySelector('.iwb-ss-dtitle') || {}).textContent || '',
|
|
||||||
}))
|
|
||||||
if (info.n >= 3) { picked = { idx: i, ...info }; break }
|
|
||||||
}
|
|
||||||
check('能找到一个变量 ≥3 的样式(用于压力验证)', Boolean(picked), JSON.stringify(picked))
|
|
||||||
|
|
||||||
if (picked) {
|
|
||||||
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
|
|
||||||
await page.waitForTimeout(1600)
|
|
||||||
await page.keyboard.press('Escape')
|
|
||||||
await page.waitForTimeout(400)
|
|
||||||
await page.keyboard.press('f')
|
|
||||||
await page.waitForTimeout(700)
|
|
||||||
await shot('multivar')
|
|
||||||
|
|
||||||
const multi = await page.evaluate(() => {
|
|
||||||
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
|
|
||||||
const b = all[all.length - 1]
|
|
||||||
if (!b) return { noBody: true }
|
|
||||||
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
|
|
||||||
return {
|
|
||||||
bodies: all.length,
|
|
||||||
rows: rows.length,
|
|
||||||
labels: rows.map((x) => ((x.querySelector('label') || {}).textContent || '')).filter(Boolean),
|
|
||||||
rowH: rows.length ? Math.round(rows[0].getBoundingClientRect().height) : 0,
|
|
||||||
hiddenRows: rows.filter((x) => x.getBoundingClientRect().height < 8).length,
|
|
||||||
scrollH: b.scrollHeight,
|
|
||||||
clientH: b.clientHeight,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('变量多的样式:所有变量行都露出、无零高行', multi.rows >= 3 && multi.hiddenRows === 0, JSON.stringify(multi).slice(0, 320))
|
|
||||||
check('节点体没有裁切(scrollHeight ≈ clientHeight)', Math.abs(multi.scrollH - multi.clientH) <= 2,
|
|
||||||
JSON.stringify({ s: multi.scrollH, c: multi.clientH }))
|
|
||||||
check('变量单行高度 28px 量级', multi.rowH >= 24 && multi.rowH <= 32, String(multi.rowH))
|
|
||||||
|
|
||||||
const collapsed = await page.evaluate(async () => {
|
|
||||||
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
|
|
||||||
const b = all[all.length - 1]
|
|
||||||
const btn = b && b.querySelector('.iwb-ssn-toggle')
|
|
||||||
if (!btn) return { noBtn: true }
|
|
||||||
const before = Math.round(b.querySelector('.iwb-ssn-vars').getBoundingClientRect().height)
|
|
||||||
btn.click()
|
|
||||||
await new Promise((r) => setTimeout(r, 500))
|
|
||||||
const box = b.querySelector('.iwb-ssn-vars')
|
|
||||||
return { before, after: Math.round(box.getBoundingClientRect().height), hidden: box.classList.contains('is-hidden'), tip: btn.title }
|
|
||||||
})
|
|
||||||
check('「收起变量」生效(变量区收起,按钮变成「展开变量」)',
|
|
||||||
collapsed.hidden === true && collapsed.after === 0 && collapsed.tip === '展开变量', JSON.stringify(collapsed))
|
|
||||||
await shot('collapsed')
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 9. 冷启动:**一次都没打开过「风格库」面板**,节点体也必须是有样式的 ──────────────
|
|
||||||
// v1.3.1 修的事故:CSS 原先进在 mount() 里,从存档打开画布时面板不 mount ⇒ `<img class="iwb-ssn-thumb">`
|
|
||||||
// 拿不到 56px 约束,按原图尺寸铺满整个节点(用户原话「图片都跑出来了」)。
|
|
||||||
{
|
|
||||||
const COLD_NODE = {
|
|
||||||
id: 'cold1', type: 'plugin:style-source:style', x: 260, y: 200, w: 300, h: 380,
|
|
||||||
data: {
|
|
||||||
variant: 'style', styleId: 'cold-style', name: '冷启动样式', code: 'ST9999', outKind: 'prompt',
|
|
||||||
promptTpl: '一张{主体}的图', varMeta: [{ key: '主体', label: '主体' }], vars: { 主体: '手表' },
|
|
||||||
text: '一张手表的图', preview: 'https://example.invalid/cold.png', refName: 'ST9999.png',
|
|
||||||
refOn: true, refUrl: 'https://example.invalid/cold.png', collapsed: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const ws = { workspaces: [{ id: 'w1', name: '冷启动', nodes: [COLD_NODE], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
|
|
||||||
const ctx2 = await browser.newContext({ viewport: { width: 1400, height: 900 } })
|
|
||||||
const p2 = await ctx2.newPage()
|
|
||||||
await p2.addInitScript(({ ws, board }) => {
|
|
||||||
localStorage.clear()
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
|
|
||||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
|
||||||
localStorage.setItem('iwb_ws_active', 'w1')
|
|
||||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(board))
|
|
||||||
}, { ws, board: ws.workspaces[0] })
|
|
||||||
await p2.goto(SITE, { waitUntil: 'domcontentloaded' })
|
|
||||||
await p2.waitForTimeout(1500)
|
|
||||||
await p2.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick().catch(() => {})
|
|
||||||
await p2.waitForFunction(() => Boolean(document.querySelector('.iwb-plugin-node-body')), null, { timeout: 20000 }).catch(() => {})
|
|
||||||
const cold = await p2.evaluate(() => {
|
|
||||||
const th = document.querySelector('.iwb-ssn-thumb')
|
|
||||||
const body = document.querySelector('.iwb-plugin-node-body')
|
|
||||||
const node = document.querySelector('.iwb-node')
|
|
||||||
return {
|
|
||||||
hasBody: Boolean(body),
|
|
||||||
hasStyle: Boolean(document.getElementById('iwb-ss-style')),
|
|
||||||
thumbW: th ? Math.round(th.getBoundingClientRect().width) : 0,
|
|
||||||
thumbH: th ? Math.round(th.getBoundingClientRect().height) : 0,
|
|
||||||
nodeW: node ? Math.round(node.getBoundingClientRect().width) : 0,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
check('冷启动(没开过风格库):节点体成立 + 样式已注入', cold.hasBody && cold.hasStyle, JSON.stringify(cold))
|
|
||||||
check('冷启动:缩略图被 CSS 约束在 56px(不是按原图铺满节点)',
|
|
||||||
cold.thumbW >= 40 && cold.thumbW <= 62 && cold.thumbH >= 40 && cold.thumbH <= 62,
|
|
||||||
JSON.stringify({ w: cold.thumbW, h: cold.thumbH, nodeW: cold.nodeW }))
|
|
||||||
await p2.screenshot({ path: path.join(HERE, 'shot-testsite-coldstart.png') }).catch(() => {})
|
|
||||||
await ctx2.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
check('全程无页面 JS 异常', errors.length === 0, errors.slice(0, 3).join(' | '))
|
|
||||||
|
|
||||||
await browser.close()
|
|
||||||
console.log('')
|
|
||||||
console.log(failed === 0 ? '全部通过' : failed + ' 项失败')
|
|
||||||
process.exit(failed === 0 ? 0 : 1)
|
|
||||||
@@ -18,7 +18,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/style-source/tools
|
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/style-source/tools
|
||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
const STYLES_JSON = '/Users/qiqi/open/github/style-source/data/styles.json'
|
const STYLES_JSON = '/Users/qiqi/open/github/style-source/data/styles.json'
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ npm run validate
|
|||||||
```bash
|
```bash
|
||||||
node white-bg-800/tools/harness.mjs
|
node white-bg-800/tools/harness.mjs
|
||||||
```
|
```
|
||||||
- `tools/e2e-site.mjs`:真实桌面客户端的端到端(市场安装 + SRI + 漂浮菜单 → 新建节点),透明底等设置类用例由 harness 覆盖。
|
- 发布后回读市场索引 + 客户端市场里确认版本与加载状态;透明底等设置类用例由 harness 覆盖。
|
||||||
|
|
||||||
> harness 里的 mock `ctx.log` 必须是**函数**(真实宿主如此),早先写成对象导致凡是走 `ctx.log` 的分支全炸。
|
> harness 里的 mock `ctx.log` 必须是**函数**(真实宿主如此),早先写成对象导致凡是走 `ctx.log` 的分支全炸。
|
||||||
> 另外几何断言在有损格式下要留 ±4px 容差(jpeg 边缘振铃),精确几何用 `format=png` 的用例测。
|
> 另外几何断言在有损格式下要留 ±4px 容差(jpeg 边缘振铃),精确几何用 `format=png` 的用例测。
|
||||||
@@ -1,228 +0,0 @@
|
|||||||
// 真实站点端到端(开发用,不进 CI)—— white-bg-800「白底图」。
|
|
||||||
//
|
|
||||||
// 为什么需要它:mock 页没有 CSP,`connect-src` 一类问题(例如 `fetch(dataURL)` 被
|
|
||||||
// `connect-src 'self' https: …` 拦掉,因为宿主 CSP 的 `connect-src` 不含 `data:`)
|
|
||||||
// 在 mock 下永远绿,只有带真实 KV + 浏览器 SRI + 真实 CSP 的真站能抓出来。
|
|
||||||
// 它不 mock /plugins/*:走真实 KV 加载 + 浏览器 SRI(fail-closed)校验 + 真实画布桥。
|
|
||||||
//
|
|
||||||
// 运行(需要 Playwright):
|
|
||||||
// node white-bg-800/tools/e2e-site.mjs # 默认测试站
|
|
||||||
// IWB_BASE_URL=https://iwb.maqiart.eu.org node white-bg-800/tools/e2e-site.mjs # 正式站
|
|
||||||
// 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定)。
|
|
||||||
import { createRequire } from 'node:module'
|
|
||||||
import { readFileSync } from 'node:fs'
|
|
||||||
import path from 'node:path'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/white-bg-800/tools
|
|
||||||
const REPO = path.resolve(HERE, '../..') // <repo>
|
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
|
||||||
|
|
||||||
let chromium = null
|
|
||||||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
|
||||||
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ }
|
|
||||||
}
|
|
||||||
if (!chromium) {
|
|
||||||
console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT:')
|
|
||||||
console.error(' npm i -D playwright # 本仓或宿主仓皆可')
|
|
||||||
console.error(' IWB_PLAYWRIGHT_ROOT=/path/to/repo node white-bg-800/tools/e2e-site.mjs')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE = process.env.IWB_BASE_URL || 'https://test.image-workbench-web.pages.dev'
|
|
||||||
const WANT_VERSION = JSON.parse(readFileSync(path.join(REPO, 'white-bg-800/package.json'), 'utf8')).version
|
|
||||||
const CFG = { providers: [], canvas: {} }
|
|
||||||
const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
|
|
||||||
|
|
||||||
let failed = 0
|
|
||||||
const check = (name, ok, detail) => {
|
|
||||||
if (!ok) failed++
|
|
||||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
|
||||||
}
|
|
||||||
const poll = async (fn, timeout = 25000, step = 250) => {
|
|
||||||
const end = Date.now() + timeout
|
|
||||||
for (;;) {
|
|
||||||
let v
|
|
||||||
try { v = await fn() } catch { v = false }
|
|
||||||
if (v) return v
|
|
||||||
if (Date.now() > end) return false
|
|
||||||
await new Promise((r) => setTimeout(r, step))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('目标站点:' + BASE + '(期望插件版本 ' + WANT_VERSION + ')')
|
|
||||||
const browser = await chromium.launch()
|
|
||||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } })
|
|
||||||
const consoleErrors = []
|
|
||||||
page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) })
|
|
||||||
page.on('pageerror', (e) => consoleErrors.push('pageerror: ' + e.message))
|
|
||||||
|
|
||||||
// 造一张真实的 96x64 PNG 作为节点图片(故意非正方形,让 800 方画布的等比缩放/居中被真正练到)
|
|
||||||
await page.goto('about:blank')
|
|
||||||
const PNG = await page.evaluate(() => {
|
|
||||||
const c = document.createElement('canvas')
|
|
||||||
c.width = 96; c.height = 64
|
|
||||||
const x = c.getContext('2d')
|
|
||||||
x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 96, 64)
|
|
||||||
x.fillStyle = '#ffffff'; x.fillRect(20, 12, 56, 40)
|
|
||||||
return c.toDataURL('image/png')
|
|
||||||
})
|
|
||||||
|
|
||||||
// 插件系统是 opt-in(新插件默认不启用),种子必须显式 enabled
|
|
||||||
await page.addInitScript((d) => {
|
|
||||||
localStorage.clear()
|
|
||||||
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
|
|
||||||
const ws = JSON.parse(JSON.stringify(d.ws))
|
|
||||||
ws.workspaces[0].nodes = [{ id: 'r1', type: 'ref', x: 140, y: 140, data: { url: '', data: d.png, name: 'src.png', localName: null } }]
|
|
||||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
|
||||||
localStorage.setItem('iwb_ws_active', ws.activeId)
|
|
||||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0]))
|
|
||||||
localStorage.setItem('iwb_web_outputs', JSON.stringify([]))
|
|
||||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'white-bg-800': { enabled: true, settings: {}, data: {} } }))
|
|
||||||
}, { cfg: CFG, ws: WS, png: PNG })
|
|
||||||
|
|
||||||
// ---------- 1) 站点可达 ----------
|
|
||||||
const resp = await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' })
|
|
||||||
check('站点可达', Boolean(resp && resp.ok()), resp && String(resp.status()))
|
|
||||||
|
|
||||||
// ---------- 2) 宿主就绪 + 真实 KV 加载并启用 ----------
|
|
||||||
const hostReady = await poll(async () => page.evaluate(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true), 30000)
|
|
||||||
check('window.IWBPluginHost 就绪(initialized)', Boolean(hostReady))
|
|
||||||
const active = await poll(async () => page.evaluate(() => {
|
|
||||||
const p = window.IWBPluginHost.list().find((x) => x.id === 'white-bg-800')
|
|
||||||
return p && p.active ? { version: p.version, enabled: p.enabled, capabilities: p.capabilities, error: p.error } : false
|
|
||||||
}))
|
|
||||||
check('从真实 KV 加载并启用(active)', Boolean(active), JSON.stringify(active))
|
|
||||||
|
|
||||||
// ---------- 3) 版本 ----------
|
|
||||||
check('线上版本 = white-bg-800/package.json(' + WANT_VERSION + ')', Boolean(active && active.version === WANT_VERSION), active && active.version)
|
|
||||||
|
|
||||||
// ---------- 4) SRI ----------
|
|
||||||
const scripts = await page.evaluate(() => Array.from(document.querySelectorAll('script[src*="/plugins/"]')).map((s) => ({ src: s.getAttribute('src'), integrity: s.getAttribute('integrity') || '' })))
|
|
||||||
check('插件脚本用 SRI(sha256) 加载', scripts.some((s) => /plugin-white-bg-800(\.[0-9a-f]{12})?\.js$/.test(s.src) && /^sha256-/.test(s.integrity)), JSON.stringify(scripts))
|
|
||||||
|
|
||||||
// ---------- 5) 打开工作区 + 种子节点 ----------
|
|
||||||
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
|
|
||||||
await page.locator('.iwb-canvas:not(.iwb-canvas-hidden)').waitFor({ state: 'visible', timeout: 30000 })
|
|
||||||
check('工作区打开、种子节点在画布', (await page.locator('.iwb-node[data-node-id="r1"]').count()) === 1)
|
|
||||||
|
|
||||||
// ---------- 6) 入口:节点漂浮菜单(title 是静态字面量「白底图」;回落右键插件命令)----------
|
|
||||||
const triggerWhiteBg = async () => {
|
|
||||||
await page.locator('.iwb-node[data-node-id="r1"]').click()
|
|
||||||
const btn = page.locator('.iwb-node-floatbar button[title="白底图"]')
|
|
||||||
if (await btn.count()) { await btn.click(); return '漂浮菜单' }
|
|
||||||
await page.locator('.iwb-canvas').click({ button: 'right', position: { x: 900, y: 620 } })
|
|
||||||
await page.locator('.iwb-ctx-item').filter({ hasText: '白底图:选中节点' }).click()
|
|
||||||
return '右键命令'
|
|
||||||
}
|
|
||||||
const entry = await triggerWhiteBg()
|
|
||||||
check('节点入口可触发(漂浮菜单或右键命令)', true, entry)
|
|
||||||
|
|
||||||
// ---------- 7) 默认「新建」:恰好 2 个节点、新节点为 src_800x800.png ----------
|
|
||||||
const created = await poll(async () => page.evaluate(() => {
|
|
||||||
const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}')
|
|
||||||
const nodes = ws.nodes || []
|
|
||||||
if (nodes.length !== 2) return false
|
|
||||||
const n = nodes.find((x) => x.id !== 'r1') || nodes[1]
|
|
||||||
return { nodes: nodes.length, name: n.data && n.data.name }
|
|
||||||
}))
|
|
||||||
const wsNodes = created ? created.nodes : await page.evaluate(() => (JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}').nodes || []).length)
|
|
||||||
check('默认「新建」:iwb_ws_w1 恰好 2 个节点', wsNodes === 2, 'nodes=' + wsNodes)
|
|
||||||
check('新节点 data.name = src_800x800.jpg(默认 format=jpeg)', Boolean(created && /^src_800x800\.jpg$/.test(created.name || '')), created && String(created.name))
|
|
||||||
|
|
||||||
// ---------- 8) 页内解引用 + 解码新建 JPEG:800x800、左上像素为白色 ----------
|
|
||||||
// 宿主「C3」引用模型:localStorage 里只存引用,字节在别处 —— 假设 localStorage 里有 base64 是
|
|
||||||
// 不可能的(by design)。两种引用形态都要认:
|
|
||||||
// a) { __blob: 'imgblob_<hash>_<len>' } → IndexedDB(src/image-blob-store.js)
|
|
||||||
// b) { __cache: '<同源 URL>' } → 宿主把大 dataURL 外置成 /__iwb_cache__/xxx(当前线上形态)
|
|
||||||
// 故在页内经 IWBImageBlobStore 解引用或同源 fetch __cache(CSP connect-src 'self' 放行)。
|
|
||||||
const resolved = await poll(async () => page.evaluate(async () => {
|
|
||||||
// 读节点图(按优先级解引用):a) data: 字符串直用 b) {__blob} 引用解引用 c) 其余形态给诊断失败
|
|
||||||
const resolveNodeDataUrl = async (d) => {
|
|
||||||
if (typeof d === 'string' && /^data:/.test(d)) return { dataUrl: d, via: 'data:' } // a)
|
|
||||||
if (d && typeof d === 'object' && typeof d.__cache === 'string' && d.__cache) { // b2) 宿主把大 dataURL 外置成同源缓存引用
|
|
||||||
const toDataUrl = (blob) => new Promise((res) => {
|
|
||||||
const fr = new FileReader()
|
|
||||||
fr.onload = () => res(String(fr.result || ''))
|
|
||||||
fr.onerror = () => res('')
|
|
||||||
fr.readAsDataURL(blob)
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
// /__iwb_cache__/<hash> 由 SW 直出;冷启动 SW 未接管时该路径会落到 Pages 404(返回 HTML)。
|
|
||||||
// 故优先直接读 Cache Storage,读不到再走 fetch(此时 SW 已接管)。
|
|
||||||
const abs = new URL(d.__cache, location.origin).href
|
|
||||||
if (typeof caches !== 'undefined') {
|
|
||||||
const hit = (await caches.match(abs)) || (await caches.match(d.__cache))
|
|
||||||
if (hit) {
|
|
||||||
const blob = await hit.blob()
|
|
||||||
const u = await toDataUrl(blob)
|
|
||||||
return u ? { dataUrl: u, via: '__cache(CS ' + blob.type + ')' } : { error: '__cache 读不出字节(' + d.__cache + ')' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const resp = await fetch(abs)
|
|
||||||
const blob = await resp.blob()
|
|
||||||
const u = await toDataUrl(blob)
|
|
||||||
return u ? { dataUrl: u, via: '__cache(fetch ' + blob.type + ')' } : { error: '__cache 读不出字节(' + d.__cache + ')' }
|
|
||||||
} catch (e) {
|
|
||||||
return { error: '__cache 抓取抛错: ' + ((e && e.message) || String(e)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d && typeof d === 'object' && typeof d.__blob === 'string' && d.__blob) { // b)
|
|
||||||
const Lib = window.IWBImageBlobStore
|
|
||||||
if (!Lib) return { error: 'window.IWBImageBlobStore 缺失' }
|
|
||||||
try {
|
|
||||||
let u = ''
|
|
||||||
if (typeof Lib.resolveDataUrl === 'function') {
|
|
||||||
u = await Lib.resolveDataUrl(d.__blob)
|
|
||||||
} else if (typeof Lib.create === 'function') {
|
|
||||||
// 与 app.js:730 同一构造:idb 用宿主同一存储运行时(get 直出 Blob)
|
|
||||||
const idb = (window.IWBStorageRuntime && window.IWBStorageRuntime.indexedDb) ||
|
|
||||||
(window.IWBStorageFallbackIndexeddb && window.IWBStorageContract && window.IWBStorageFallbackIndexeddb.create({ contract: window.IWBStorageContract.indexedDb }))
|
|
||||||
if (!idb || typeof idb.get !== 'function') return { error: '取不到宿主 idb(IWBStorageRuntime.indexedDb)' }
|
|
||||||
u = await Lib.create({ idb }).resolveDataUrl(d.__blob)
|
|
||||||
} else {
|
|
||||||
return { error: 'IWBImageBlobStore 无 resolveDataUrl / create' }
|
|
||||||
}
|
|
||||||
return (typeof u === 'string' && u) ? { dataUrl: u, via: '__blob' } : { error: '解引用未返回字节(' + d.__blob + ')' }
|
|
||||||
} catch (e) {
|
|
||||||
return { error: '解引用抛错: ' + ((e && e.message) || String(e)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { error: '未知 data 形态: ' + (d == null ? String(d) : typeof d) + ' keys=' + (d && typeof d === 'object' ? Object.keys(d).join(',') : '-') + ' sample=' + JSON.stringify(d).slice(0, 220) } // c)
|
|
||||||
}
|
|
||||||
const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}')
|
|
||||||
const nodes = ws.nodes || []
|
|
||||||
const n = nodes.length === 2 ? (nodes.find((x) => x.id !== 'r1') || nodes[1]) : null
|
|
||||||
if (!n) return false // 新节点未就绪 → 重试
|
|
||||||
const r = await resolveNodeDataUrl(n.data && n.data.data)
|
|
||||||
if (r.error) return { error: r.error }
|
|
||||||
if (!/^data:image\/jpeg;base64,/.test(r.dataUrl)) return { error: '解引用结果不是 JPEG dataURL(via=' + r.via + '): ' + String(r.dataUrl).slice(0, 40) }
|
|
||||||
const img = new Image()
|
|
||||||
const ok = await new Promise((res) => { img.onload = () => res(true); img.onerror = () => res(false); img.src = r.dataUrl })
|
|
||||||
if (!ok) return { dataOk: true, via: r.via, decodeError: 'Image 解码失败' }
|
|
||||||
const c = document.createElement('canvas')
|
|
||||||
c.width = img.naturalWidth; c.height = img.naturalHeight
|
|
||||||
const x = c.getContext('2d')
|
|
||||||
x.drawImage(img, 0, 0)
|
|
||||||
const px = x.getImageData(0, 0, 1, 1).data
|
|
||||||
return { dataOk: true, via: r.via, w: img.naturalWidth, h: img.naturalHeight, px: [px[0], px[1], px[2], px[3]] }
|
|
||||||
}))
|
|
||||||
const d = resolved || {}
|
|
||||||
const dDiag = d.error || d.decodeError || (resolved ? '' : '轮询超时:新节点未出现')
|
|
||||||
check('新节点 data 为 JPEG 字节(引用已解析)', Boolean(d.dataOk), d.dataOk ? d.via : dDiag)
|
|
||||||
check('新建 JPEG 解码尺寸 = 800x800', Boolean(d.dataOk && d.w === 800 && d.h === 800), d.dataOk ? d.w + 'x' + d.h : dDiag)
|
|
||||||
// jpeg 有损:纯白角落允许 ±5 的压缩抖动,但 alpha 必须不透明
|
|
||||||
check('新建 JPEG 左上像素 ≈ 白色且不透明', Boolean(d.dataOk && d.px && d.px[0] >= 250 && d.px[1] >= 250 && d.px[2] >= 250 && d.px[3] === 255), JSON.stringify(d.px) || dDiag)
|
|
||||||
|
|
||||||
// 透明模式(transparent)不在此二次跑(需改设置再整轮重放,易碎)——由 white-bg-800/tools/harness.mjs 覆盖。
|
|
||||||
|
|
||||||
// ---------- 9) 无 CSP / SRI 拦截 ----------
|
|
||||||
const bad = consoleErrors.filter((t) => /Content Security Policy|integrity|Refused to (execute|load|connect)/i.test(t))
|
|
||||||
check('无 CSP / SRI 拦截报错', bad.length === 0, bad.slice(0, 2).join(' | '))
|
|
||||||
|
|
||||||
// ---------- 10) 无页面级运行时错误 ----------
|
|
||||||
check('无页面级运行时错误', consoleErrors.length === 0, consoleErrors.slice(0, 3).join(' | '))
|
|
||||||
|
|
||||||
await browser.close()
|
|
||||||
console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过'))
|
|
||||||
process.exit(failed ? 1 : 0)
|
|
||||||
@@ -15,7 +15,7 @@ import { fileURLToPath } from 'node:url'
|
|||||||
|
|
||||||
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/white-bg-800/tools
|
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <repo>/white-bg-800/tools
|
||||||
const REPO = path.resolve(HERE, '../..') // <repo>
|
const REPO = path.resolve(HERE, '../..') // <repo>
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-desktop'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
|
||||||
let chromium = null
|
let chromium = null
|
||||||
|
|||||||
Reference in new issue
Block a user