Compare commits
36
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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,170 @@
|
||||
#!/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',
|
||||
'/Users/qiqi/open/github/image-workbench-web', 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)
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/batch-export",
|
||||
"private": true,
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
||||
"ibwPlugin": {
|
||||
"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-tag{font-size:11px;white-space:nowrap;color:var(--iwb-text2,#4d5668);',
|
||||
'max-width:46%;min-width:0;overflow:hidden;text-overflow:ellipsis}',
|
||||
'.iwb-bx-tag-ok{color:#1d9e75}',
|
||||
'.iwb-bx-tag-err{color:#d85a30}',
|
||||
// 状态色不能直接当文字色:宿主 --iwb-ok 亮色是 #22c55e,压在浅页面上对比只有 2.13。
|
||||
// 照 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;',
|
||||
'font-family:ui-monospace,SFMono-Regular,Menlo,monospace;border:1px solid var(--iwb-border,#d5d9e0);',
|
||||
'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: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-empty{padding:24px 12px;text-align:center;color:var(--iwb-text2,#4d5668)}',
|
||||
// 缩略图:小方图(30px)常驻在行首,跑完换成产物本身,一眼能对上「哪张图、出了什么」
|
||||
'.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}',
|
||||
'.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-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;',
|
||||
'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-btn-hot 会被后定义的 .iwb-bx-btn 背景覆盖(同特异性,后者胜)
|
||||
'.iwb-bx-btn.iwb-bx-btn-hot{background:#1d9e75;border-color:#1d9e75;color:#fff}',
|
||||
// 主/热按钮此前是纯蓝 #2f6fed 实心 + 白字:与项目「全灰阶、无蓝」的配色约束冲突,
|
||||
// 且暗色下亮绿底压白字对比度不足。改成宿主语义色成对反相 + 状态色描边,
|
||||
// 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;',
|
||||
'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 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);',
|
||||
'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-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('')
|
||||
|
||||
function ensureStyle() {
|
||||
@@ -500,7 +510,7 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'batch-export',
|
||||
name: '批量出图',
|
||||
version: '1.2.1',
|
||||
version: '1.2.2',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'canvas'],
|
||||
settings: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/gallery",
|
||||
"private": true,
|
||||
"version": "1.6.9",
|
||||
"version": "1.7.0",
|
||||
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
|
||||
"ibwPlugin": {
|
||||
"id": "gallery",
|
||||
|
||||
+61
-9
@@ -1,8 +1,15 @@
|
||||
// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里)
|
||||
//
|
||||
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove)+ panels。
|
||||
// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove/onChanged)+ panels。
|
||||
// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。
|
||||
// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。
|
||||
//
|
||||
// v1.7.0(2026-11-24):
|
||||
// ① 订阅 ctx.gallery.onChanged —— 出图途中宿主每归档一张就通知,面板立刻长出新图;
|
||||
// 此前只有「面板重新可见且距上次拉取 >5s」一个入口,而生成时面板一直可见 ⇒ 永远不刷。
|
||||
// ② 格子「插入」补 insertK(与右键/顶部一致,尺寸档不再被忽略)。
|
||||
// ③ 插入/删除补「插入中…」状态,删除改成等宿主删完再重拉(固定 250ms 会拉到未删完的清单)。
|
||||
// 注:搜索框在 v1.6.1 已按用户意见移除,不再加回。
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
if (!global.IWBPluginHost) return
|
||||
@@ -129,8 +136,20 @@
|
||||
setBtn.setAttribute('aria-expanded', 'false')
|
||||
var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' })
|
||||
settings.style.display = 'none'
|
||||
// 2026-11-24:底栏加「打开本地图库目录」图标(文件夹),放在设置图标左边;只桌面端可用。
|
||||
var folderBtn = iconBtn('打开本地目录', function (svg) {
|
||||
svgPath(svg, 'M2 4.5h4l1.5 2H14v6.5H2z')
|
||||
}, '在系统文件管理器里打开本地图库目录(images/gallery)')
|
||||
folderBtn.addEventListener('click', function (e) {
|
||||
e.stopPropagation()
|
||||
if (!ctx.gallery || typeof ctx.gallery.openFolder !== 'function') { setStatus('仅桌面端可打开本地目录'); return }
|
||||
Promise.resolve(ctx.gallery.openFolder()).then(function (r) {
|
||||
if (r && r.ok === false) setStatus('打开失败:' + ((r && r.error) || '仅桌面端可用'))
|
||||
}).catch(function (err) { setStatus('打开失败:' + ((err && err.message) || err)) })
|
||||
})
|
||||
folderBtn.style.display = (typeof window !== 'undefined' && window.__TAURI__ && window.__TAURI__.core) ? '' : 'none'
|
||||
// v1.4.2:刷新与设置同放右侧工具组(此前刷新在左侧信息区,空间不足时会向右溢出、压住设置图标)
|
||||
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, setBtn)
|
||||
var tools = el('div', { class: 'iwb-gal-tools' }, refreshBtn, folderBtn, setBtn)
|
||||
var foot = el('div', { class: 'iwb-gal-foot' },
|
||||
el('div', { class: 'iwb-gal-foot-left' }, countEl, pickedEl, failEl, statusEl), tools)
|
||||
var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, more, empty, foot, settings])
|
||||
@@ -172,6 +191,7 @@
|
||||
menu.appendChild(b)
|
||||
}
|
||||
item('插入画布', function () {
|
||||
setStatus('插入中…(取本地原图 → 按插入尺寸压缩)')
|
||||
Promise.resolve(ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }))
|
||||
.then(function () { setStatus('已插入:' + it.name) })
|
||||
.catch(function () { setStatus('插入失败') })
|
||||
@@ -190,11 +210,14 @@
|
||||
var ask = (C && C.askOrNative) ? C.askOrNative('删除「' + it.name + '」?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除「' + it.name + '」?'))
|
||||
ask.then(function (ok) {
|
||||
if (!ok) return
|
||||
// 先本地摘掉,避免删除后还渲染一格「图片已丢失」
|
||||
items = items.filter(function (x) { return x.name !== it.name })
|
||||
total = Math.max(0, total - 1)
|
||||
delete picked[it.name]
|
||||
render()
|
||||
Promise.resolve(ctx.gallery.remove([it.name])).then(function () { setTimeout(load, 250) }).catch(function () {})
|
||||
// v1.7.0:等宿主真的删完再重拉(旧写法固定 setTimeout 250ms,磁盘慢/多张时会拉到还没删完的清单,
|
||||
// 格子里出现「图片已丢失」,用户以为删坏了)
|
||||
return Promise.resolve(ctx.gallery.remove([it.name])).then(function () { return load() }).catch(function () {})
|
||||
}).catch(function () {})
|
||||
})
|
||||
document.body.appendChild(menu)
|
||||
@@ -215,6 +238,7 @@
|
||||
try { names = JSON.parse(raw) } catch (err) { return }
|
||||
if (!names || names.length < 2) return
|
||||
e.preventDefault(); e.stopPropagation()
|
||||
setStatus('插入中…(' + names.length + ' 张)')
|
||||
Promise.resolve(ctx.gallery.insert(names, { insertK: cfg.insertK || '1k' })).then(function (r) {
|
||||
if (r && r.ok === false) { setStatus('批量插入失败'); return }
|
||||
setStatus('已插入 ' + names.length + ' 张')
|
||||
@@ -252,6 +276,7 @@
|
||||
actions.appendChild(btn('插入', '把选中的图片插入画布(尺寸按「设置 → 插入尺寸」)', function () {
|
||||
var names = pickedNames()
|
||||
var k = cfg.insertK || '1k'
|
||||
setStatus('插入中…(' + names.length + ' 张)')
|
||||
Promise.resolve(ctx.gallery.insert(names, { insertK: k })).then(function (r) {
|
||||
if (r && r.ok === false) { setStatus('插入失败'); return }
|
||||
setStatus('已插入 ' + names.length + ' 张(' + String(k).toUpperCase() + ')')
|
||||
@@ -270,7 +295,7 @@
|
||||
picked = {}
|
||||
render()
|
||||
return Promise.resolve(ctx.gallery.remove(names)).then(function () {
|
||||
setTimeout(load, 250)
|
||||
return load() // v1.7.0:等宿主真删完再重拉(固定延时会拉到未删完的清单)
|
||||
})
|
||||
}).catch(function () {})
|
||||
}, true, true))
|
||||
@@ -300,6 +325,11 @@
|
||||
function renderGrid () {
|
||||
clear(grid)
|
||||
var gap = 6
|
||||
// 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值,
|
||||
// 只靠 ResizeObserver 会在「变成 0 再回来」期间漏掉,导致必须拖宽度才出图。
|
||||
var liveW = availableW()
|
||||
if (liveW > 0 && Math.abs(liveW - gridW) > 1) gridW = liveW
|
||||
if (!gridW) gridW = 320
|
||||
var tileW = Math.max(40, Number(cfg.tile) || 110)
|
||||
var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap)))
|
||||
// v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」——
|
||||
@@ -368,7 +398,7 @@
|
||||
function paint (url) {
|
||||
if (!url || typeof url !== 'string') { fail('图片已丢失'); 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)
|
||||
img.addEventListener('load', function () {
|
||||
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
||||
@@ -407,7 +437,7 @@
|
||||
if (img.parentNode === box) box.replaceChild(holder, img)
|
||||
fail('缩略图加载失败(点击重试)')
|
||||
} catch (e) { /* ignore */ }
|
||||
}, 700)
|
||||
}, 2000)
|
||||
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
|
||||
if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) }
|
||||
else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }
|
||||
@@ -420,7 +450,13 @@
|
||||
b.addEventListener('click', function (e) { e.stopPropagation(); fn() })
|
||||
return b
|
||||
}
|
||||
acts.appendChild(act('插入', '插入到画布(参考图节点)', function () { ctx.gallery.insert([it.name]).catch(function () {}) }))
|
||||
acts.appendChild(act('插入', '插入到画布(参考图节点 · 尺寸按「设置 → 插入尺寸」)', function () {
|
||||
// v1.7.0:格子里的「插入」此前没带 insertK,宿主按默认 1k 处理 —— 与右键菜单/顶部「插入」不一致
|
||||
setStatus('插入中…')
|
||||
ctx.gallery.insert([it.name], { insertK: cfg.insertK || '1k' }).then(function () {
|
||||
setStatus('已插入:' + it.name)
|
||||
}).catch(function () { setStatus('插入失败') })
|
||||
}))
|
||||
acts.appendChild(act('下载', '下载到本地', function () { doDownload([it.name]) }))
|
||||
box.appendChild(acts)
|
||||
return box
|
||||
@@ -447,7 +483,7 @@
|
||||
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) {
|
||||
if (force) setStatus('刷新中…')
|
||||
@@ -497,11 +533,25 @@
|
||||
|
||||
// v1.3.0:自动恢复 —— 面板重新可见(切回 tab / 窗口聚焦 / 后台回来)且距上次拉取 >5s 时重拉一次,
|
||||
// 这样图床恢复、后台补图后不必手动刷新;同时保留底部「刷新」按钮做即时重试。
|
||||
// v1.7.0:这只是**兜底**。主通道改成宿主主动通知(下面 onChanged)—— 生成途中面板一直是可见的,
|
||||
// 靠「可见性变化」触发永远等不到,用户看到的就是「生图完成但图库没图」。
|
||||
var lastLoadAt = 0
|
||||
var autoRefresh = function () {
|
||||
if (Date.now() - lastLoadAt < 5000) return
|
||||
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 {
|
||||
if (typeof IntersectionObserver === 'function') {
|
||||
var io = new IntersectionObserver(function (entries) {
|
||||
@@ -528,6 +578,8 @@
|
||||
|
||||
return function dispose () {
|
||||
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('keydown', onMenuKey, true) } catch (e) { /* ignore */ }
|
||||
try { document.removeEventListener('drop', onDocDrop, true) } catch (e) { /* ignore */ }
|
||||
@@ -538,7 +590,7 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'gallery',
|
||||
name: '图库',
|
||||
version: '1.6.9',
|
||||
version: '1.7.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'gallery'],
|
||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@
|
||||
/* ---- 顶栏 ---- */
|
||||
.iwb-gal-head { display: flex; align-items: center; gap: 6px; min-height: 0; }
|
||||
.iwb-gal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||
.iwb-gal-actions .iwb-btn-sm { padding: 2px 7px; }
|
||||
.iwb-gal-actions .iwb-btn-sm { padding: 2px 6px; }
|
||||
|
||||
/* ---- 底栏:左信息 / 右工具组 ---- */
|
||||
.iwb-gal-foot {
|
||||
@@ -32,7 +32,7 @@
|
||||
.iwb-gal-foot .iwb-gal-icobtn:active {
|
||||
width: 20px; height: 20px; min-width: 20px; padding: 0; box-sizing: border-box;
|
||||
display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
|
||||
border: 0; box-shadow: none; background: transparent; border-radius: 4px;
|
||||
border: 0; box-shadow: none; background: transparent; border-radius: 6px;
|
||||
color: var(--iwb-text2); line-height: 1; transform: none;
|
||||
}
|
||||
.iwb-gal-foot .iwb-gal-icobtn svg { display: block; pointer-events: none; }
|
||||
@@ -43,7 +43,7 @@
|
||||
/* ---- 设置浮层(三个下拉不占前台) ---- */
|
||||
.iwb-gal-settings {
|
||||
position: absolute; right: 8px; bottom: 34px; z-index: 30; width: 176px; max-width: calc(100% - 16px);
|
||||
display: flex; flex-direction: column; gap: 8px; padding: 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;
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
|
||||
}
|
||||
@@ -65,7 +65,7 @@
|
||||
font-size: 11px; color: var(--iwb-text2); background: var(--iwb-layer2); word-break: break-all;
|
||||
}
|
||||
.iwb-history-actions { display: flex; gap: 4px; padding: 4px 2px 0; }
|
||||
.iwb-history-actions .iwb-btn-sm { padding: 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-hint 的地方(文字被居中) */
|
||||
.iwb-history-embedded .iwb-hint { font-size: 11px; color: var(--iwb-text2); text-align: center; padding: 12px 6px; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/grouplib",
|
||||
"private": true,
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "节点组:左栏收藏的节点组列表(分组/改名/删除/拖入画布实例化),数据由宿主 grouplib 能力提供",
|
||||
"ibwPlugin": {
|
||||
"id": "grouplib",
|
||||
|
||||
@@ -439,7 +439,7 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'grouplib',
|
||||
name: '节点组',
|
||||
version: '1.0.4',
|
||||
version: '1.0.5',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'grouplib'],
|
||||
data: { schemaVersion: 1, maxBytes: 65536 },
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
.iwb-glp-dragging { opacity: .55; }
|
||||
/* 空态:虚线框 */
|
||||
.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);
|
||||
font-size: 12px; line-height: 1.7;
|
||||
}
|
||||
+4
-1
@@ -5,7 +5,10 @@
|
||||
"description": "IWB 插件仓:只写插件,不复制宿主契约",
|
||||
"scripts": {
|
||||
"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",
|
||||
"test:album": "node album/tools/harness.mjs",
|
||||
"test:album:e2e": "node album/tools/viewer-e2e.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"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",
|
||||
"private": true,
|
||||
"version": "1.8.21",
|
||||
"version": "1.13.0",
|
||||
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
||||
"ibwPlugin": {
|
||||
"id": "promptlib",
|
||||
|
||||
+618
-134
File diff suppressed because it is too large.
Load diff
+152
-119
@@ -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(提示词库)自带样式
|
||||
作用域全部带 .iwb-plp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */
|
||||
|
||||
@@ -34,9 +35,9 @@
|
||||
.iwb-plp-card:hover { border-color: var(--iwb-border2, #b9bfca); }
|
||||
.iwb-plp-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.iwb-plp-t {
|
||||
position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 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));
|
||||
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;
|
||||
text-shadow: 0 1px 2px rgba(0,0,0,.35);
|
||||
}
|
||||
@@ -54,26 +55,26 @@
|
||||
/* 编辑弹窗:760 宽 + 大文本框 */
|
||||
.iwb-promptlib-editor { width: 760px; max-width: 94vw; }
|
||||
.iwb-promptlib-editor .iwb-modal-body { max-height: 78vh; }
|
||||
.iwb-promptlib-text { min-height: 360px; height: 44vh; font-size: 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-thumb { flex: 0 0 96px; width: 96px; height: 128px; border-radius: 8px; overflow: hidden; border: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
.iwb-plp-editor-coverops { display: flex; flex-direction: column; gap: 8px; }
|
||||
|
||||
/* v1.2.0:可拖动 / 可缩放的详情与编辑弹窗(同宽 880×640,最小 640×420) */
|
||||
.iwb-plp-mask { background: transparent; display: block; }
|
||||
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 16px;
|
||||
.iwb-plp-dialog { display: flex; flex-direction: column; overflow: hidden; border-radius: 14px;
|
||||
box-shadow: 0 24px 60px rgba(0,0,0,.28); }
|
||||
.iwb-plp-dhead { display: flex; align-items: center; gap: 6px; padding: 10px 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; }
|
||||
.iwb-plp-grip { display: grid; grid-template-columns: repeat(3, 3px); gap: 2px; margin-right: 6px; }
|
||||
.iwb-plp-grip i { width: 3px; height: 3px; border-radius: 50%; background: var(--iwb-border2, #b9bfca); display: block; }
|
||||
.iwb-plp-dbody { flex: 1 1 auto; min-height: 0; display: flex; gap: 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;
|
||||
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-dright { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
|
||||
.iwb-plp-dtext { flex: 1 1 auto; min-height: 0; overflow: auto; white-space: pre-wrap; word-break: break-word;
|
||||
font-size: 12px; line-height: 1.9; color: var(--iwb-text2, #4d5668); }
|
||||
.iwb-plp-dfooter { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 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); }
|
||||
.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%); }
|
||||
@@ -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-ecov { width: 240px; height: 300px; border-radius: 10px; overflow: hidden;
|
||||
border: 1px solid var(--iwb-border, #d5d9e0); background: var(--iwb-plugin-inset, #f5f6f7); }
|
||||
.iwb-plp-lrow { display: flex; flex-direction: column; gap: 4px; font-size: 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-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-nhead{display:flex;align-items:center;gap:8px}
|
||||
.iwb-plp-nthumb{width:44px;height:44px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
||||
.iwb-plp-ntitle{font-weight:600;font-size: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-nrow{display:flex;align-items:center;gap:6px;height:26px}
|
||||
.iwb-plp-nk{width:64px;flex:0 0 64px;color:var(--iwb-text2,#5b6472);font-size:11.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.iwb-plp-nin{flex:1;height:24px;font-size:11.5px}
|
||||
.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}
|
||||
/* v1.12.1:标签列定宽(此前是 flex:0 0 auto,宽度跟着名称长短变 ⇒ 每个变量输入框左边缘错位)。
|
||||
v1.13.0:用户要求按 4 字定宽 ⇒ 56px(12px 字号 × 4 + 8px 余量)。超过 4 字的名称省略号截断,完整名称在 title 里。 */
|
||||
.iwb-plp-nrow{display:flex;align-items:flex-start;gap:6px;min-height:26px}
|
||||
.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-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:变量编辑器 / 详情变量 */
|
||||
.iwb-plp-emid{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}
|
||||
.iwb-plp-vars{border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px;display:flex;flex-direction:column;gap:6px;background:var(--iwb-plugin-surface,#fff)}
|
||||
.iwb-plp-vhead{display:flex;align-items:center;gap:8px;font-size:11.5px;color:var(--iwb-text2,#5b6472)}
|
||||
.iwb-plp-vhint{color:var(--iwb-text2,#8b929c);font-size:11px}
|
||||
.iwb-plp-vhead{display:flex;align-items:center;gap:8px;font-size: 12px;color:var(--iwb-text2,#5b6472)}
|
||||
.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-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-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-vin{flex:1;height:26px;font-size:11.5px}
|
||||
.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-dvars{display:flex;flex-direction:column;gap:5px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
|
||||
.iwb-plp-vk{width:92px;flex:0 0 92px;font-size: 12px;color:var(--iwb-text2,#5b6472);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.iwb-plp-vin{flex:1;height:26px;font-size: 12px}
|
||||
.iwb-plp-vprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;font-size: 12px;line-height:1.6;color:var(--iwb-text2,#5b6472);max-height:72px;overflow:auto;white-space:pre-wrap}
|
||||
.iwb-plp-dvars{display:flex;flex-direction:column;gap: 6px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
|
||||
|
||||
/* v1.5.6:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
|
||||
.iwb-plp-nthumb{width:56px;height:56px;border-radius:8px;object-fit:cover;flex:0 0 auto}
|
||||
.iwb-plp-ntitlebox{min-width:0;display:flex;flex-direction:column;gap:2px}
|
||||
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;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-ntitle{font-weight:600;font-size: 13px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
||||
.iwb-plp-nmeta{font-size: 11px;color:var(--iwb-text2,#8b929c)}
|
||||
.iwb-plp-nempty{font-size:11px;color:var(--iwb-text2,#8b929c);padding:2px 0}
|
||||
.iwb-plp-nwarn{font-size:11px;line-height:1.5;color:var(--iwb-warn,#d97706)}
|
||||
|
||||
/* v1.5.10:设置页 */
|
||||
.iwb-plp-settings{display:flex;flex-direction:column;gap:18px}
|
||||
.iwb-plp-ssec{border:1px solid var(--iwb-border,#e3e5e9);border-radius:12px;padding:12px 14px;display:flex;flex-direction:column;gap:8px}
|
||||
.iwb-plp-stitle{font-weight:600;font-size:12.5px}
|
||||
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-border,#eef0f2);border-radius:10px;overflow:hidden}
|
||||
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding:7px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
|
||||
.iwb-plp-settings{display:flex;flex-direction:column;gap: 16px}
|
||||
/* 2026-11-24:插件设置页跟随宿主的设置分组 token(不再自画卡片,避免卡片套卡片) */
|
||||
.iwb-plp-ssec{border:0;border-top:1px solid var(--iwb-set-divider,var(--iwb-border,#e3e5e9));border-radius:0;padding:var(--iwb-space-12) 0 0;display:flex;flex-direction:column;gap:var(--iwb-space-8)}
|
||||
.iwb-plp-ssec:first-child{border-top:0;padding-top:0}
|
||||
.iwb-plp-stitle{font-weight:600;font-size:var(--iwb-font-md,13px);color:var(--iwb-text,#2a2f36)}
|
||||
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-set-input-border,var(--iwb-border,#eef0f2));border-radius:var(--iwb-radius-card,10px);overflow:hidden}
|
||||
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding: 6px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
|
||||
.iwb-plp-sgrow:first-child{border-top:0}
|
||||
.iwb-plp-sgrip{width:12px;height:12px;background:radial-gradient(var(--iwb-text2,#c2c7cf) 1px,transparent 1px);background-size:4px 4px;border-radius: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-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-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)}
|
||||
@@ -192,6 +196,8 @@
|
||||
|
||||
/* v1.6.2:正文上方工具行 */
|
||||
.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}
|
||||
|
||||
/* v1.6.5:宿主基础样式的插件作用域副本 —— 宿主改全局样式不再影响插件 */
|
||||
@@ -202,7 +208,7 @@ flex: 1;
|
||||
display: flex; gap: 6px; align-items: center;
|
||||
}
|
||||
.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 {
|
||||
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);
|
||||
}
|
||||
.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 {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
.iwb-promptlib .iwb-lib-chips-scroll > .iwb-chip:last-child {
|
||||
margin-right: 18px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
.iwb-promptlib .iwb-lib-searchscope-back {
|
||||
display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; padding: 0; border: none; border-radius: 999px; background: transparent; color: var(--iwb-text2); font-size: 13px; line-height: 1; cursor: pointer;
|
||||
@@ -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);
|
||||
}
|
||||
.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 {
|
||||
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);
|
||||
}
|
||||
.iwb-promptlib .iwb-chip-count {
|
||||
font-size: 10px; opacity: 0.8;
|
||||
font-size: 11px; opacity: 0.8;
|
||||
}
|
||||
.iwb-promptlib .iwb-chip-add {
|
||||
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);
|
||||
}
|
||||
.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 {
|
||||
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);
|
||||
}
|
||||
.iwb-promptlib .iwb-btn-sm {
|
||||
padding: 3px 7px; font-size: 11px;
|
||||
padding: 4px 6px; font-size: 11px;
|
||||
}
|
||||
.iwb-promptlib .iwb-btn-danger {
|
||||
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;
|
||||
}
|
||||
.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 {
|
||||
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 {
|
||||
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 {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
/* v1.10.1:详情底部分享组(文本/文件分享)与插入组之间的竖向分割线 */
|
||||
.iwb-plp-dialog .iwb-plp-foot-vsep {
|
||||
display: inline-block; width: 1px; height: 18px; flex: 0 0 auto;
|
||||
align-self: center; margin: 0 12px; background: var(--iwb-border);
|
||||
}
|
||||
.iwb-plp-dialog .iwb-section-sub {
|
||||
margin-top: 2px;
|
||||
}
|
||||
@@ -364,11 +375,11 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32);
|
||||
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98)}
|
||||
|
||||
/* v1.6.9:拖拽虚拟卡片(跟手预览) */
|
||||
.iwb-plp-dragghost{width:168px;display:flex;align-items:center;gap:8px;padding:8px 10px;background:var(--iwb-panel,#fff);border:2px solid var(--iwb-plp-accent,#7c4dff);border-radius: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-ghosttxt{min-width:0;display:flex;flex-direction:column;gap:2px}
|
||||
.iwb-plp-ghostname{font-weight:600;color:var(--iwb-text,#1c2333);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.iwb-plp-ghosthint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0)}
|
||||
.iwb-plp-ghosthint{font-size: 11px;color:var(--iwb-plp-accent,#5a4bd0)}
|
||||
|
||||
/* v1.6.10:悬停放大改为「内层背景层缩放」——卡片命中区域不变,渐变卡不再闪烁 */
|
||||
.iwb-plp-bg{position:absolute;inset:0;overflow:hidden;border-radius:inherit;transition:transform .16s ease;will-change:transform;backface-visibility:hidden}
|
||||
@@ -390,11 +401,11 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32);
|
||||
.iwb-plp-card{user-select:none}
|
||||
body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webkit-user-select:none!important}
|
||||
.iwb-plp-placeghost{border-style:dashed!important;pointer-events:none}
|
||||
.iwb-plp-placehint{font-size:10.5px;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-t{font-size:12px;color:var(--iwb-plp-accent,#5a3fd0);background:rgba(255,255,255,.82);border-radius:999px;padding:3px 10px}
|
||||
.iwb-plp-placehint{font-size: 11px;color:var(--iwb-plp-accent,#5a4bd0);margin-top:2px}
|
||||
.iwb-plp-placebox{position:fixed;left:-9999px;top:0;z-index: var(--iwb-z-anchor, 3200);pointer-events:none;border:2px dashed var(--iwb-plp-accent,#6b4dff);border-radius:12px;background:color-mix(in srgb,var(--iwb-plp-accent,#6b4dff) 9%,transparent);display:flex;align-items:center;justify-content:center;box-shadow:0 10px 26px rgba(30,20,80,.10)}
|
||||
.iwb-plp-placebox-t{font-size:12px;color:var(--iwb-plp-accent,#5a3fd0);background:rgba(255,255,255,.82);border-radius:999px;padding: 4px 10px}
|
||||
/* v1.6.23:放置指示改为灰色小方框 */
|
||||
.iwb-plp-placebox{border: 2px dashed var(--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}
|
||||
/* v1.7.0:编辑面板三栏 + 可拖宽;详情封面放大、变量高亮 */
|
||||
.iwb-plp-eleft{flex:0 0 236px;width:236px}
|
||||
@@ -408,51 +419,63 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
||||
.iwb-plp-vitem{padding:4px 0;border-bottom:1px dashed var(--iwb-border,#eceef2)}
|
||||
.iwb-plp-vrow2{display:flex;align-items:center;gap:6px}
|
||||
.iwb-plp-vname{flex:1 1 auto;min-width:0;height:32px}
|
||||
.iwb-plp-vi{flex:0 0 auto;width:24px;height:24px;padding:0;border-radius:50%;border:1px solid var(--iwb-border,#dfe3e9);background: var(--plp-c1, #fff);color: var(--plp-c4, #9aa1ac);font-size:11px;line-height:22px;text-align:center}
|
||||
.iwb-plp-vi.is-open{background: var(--plp-c5, #f1ecff);border-color: var(--plp-c6, #d8cbff);color: var(--plp-c7, #5a3fd0)}
|
||||
.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-vi{flex:0 0 auto;width:24px;height:24px;padding:0;border-radius:50%;border:1px solid var(--iwb-border,#dfe3e9);background: var(--iwb-plugin-card, #fff);color: var(--iwb-text-dim, #9aa1ac);font-size:11px;line-height:22px;text-align:center}
|
||||
.iwb-plp-vi.is-open{background: var(--iwb-plp-accent-soft, #f1ecff);border-color: var(--iwb-plp-accent-border, #d8cbff);color: var(--iwb-plp-accent, #5a3fd0)}
|
||||
.iwb-plp-vdesc{width:100%;height:28px;margin-top: 6px;border-style:dashed;background: var(--iwb-field, #fbfcfd);font-size: 12px;color: var(--plp-c3, #6b7280)}
|
||||
/* v1.12.0:变量编辑器折叠两态(收起一行名称+摘要,展开四字段)与内容多行框 */
|
||||
.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-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:编辑面板视觉精修——输入框比底色更亮、去多余边框、细分隔线 */
|
||||
.iwb-plp-dialog .iwb-plp-dbody{gap:10px;padding:12px;background: var(--plp-c9, #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-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 .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: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-esplit{flex:0 0 6px;background:transparent;border-radius:4px}
|
||||
.iwb-plp-dialog .iwb-plp-esplit:hover{background: var(--plp-c13, #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-dbody{gap:10px;padding:12px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||
.iwb-plp-dialog .iwb-plp-eleft{flex:0 0 236px;width:236px;background: var(--iwb-plugin-card, #fff);border: 1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:12px}
|
||||
.iwb-plp-dialog .iwb-plp-emid{background: var(--iwb-plugin-card, #fff);border: 1px solid var(--iwb-plugin-border, #e6e8ec);border-radius:12px;padding:10px 12px 12px}
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext{border: 1px solid var(--iwb-plugin-border, #eef0f3);background: var(--iwb-field, #fbfcfd);border-radius: 8px;padding:10px 12px}
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-etext:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||
.iwb-plp-dialog .iwb-plp-esplit{flex:0 0 6px;background:transparent;border-radius: 6px}
|
||||
.iwb-plp-dialog .iwb-plp-esplit:hover{background: var(--iwb-plugin-hover, #e7e9ee)}
|
||||
.iwb-plp-dialog .iwb-plp-esplit::before{content:'';display:block;width:2px;height:30px;border-radius: 6px;background: var(--iwb-plugin-hover, #d7dbe2)}
|
||||
.iwb-plp-dialog .iwb-plp-eright{background:transparent;border:0;padding:2px 0 0}
|
||||
.iwb-plp-dialog .iwb-plp-vitem{border:0;padding:2px 0}
|
||||
.iwb-plp-dialog .iwb-plp-vrow2{gap:6px}
|
||||
.iwb-plp-dialog .iwb-plp-vname{background: var(--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: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-vi{background:transparent;border:0;color: var(--plp-c17, #aab0ba);width:22px;height:22px;line-height:20px}
|
||||
.iwb-plp-dialog .iwb-plp-vi:hover{background: var(--plp-c18, #eef0f4);color: var(--plp-c3, #6b7280)}
|
||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--plp-c5, #f1ecff);color: var(--plp-c7, #5a3fd0)}
|
||||
.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 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)}
|
||||
.iwb-plp-dialog .iwb-plp-vname{background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px;padding:0 10px;font-size: 13px;color: var(--iwb-text, #33383f)}
|
||||
.iwb-plp-dialog .iwb-plp-vname:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||
.iwb-plp-dialog .iwb-plp-vi{background:transparent;border:0;color: var(--iwb-text-dim, #aab0ba);width:22px;height:22px;line-height:20px}
|
||||
.iwb-plp-dialog .iwb-plp-vi:hover{background: var(--iwb-plugin-inset, #eef0f4);color: var(--plp-c3, #6b7280)}
|
||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plp-accent-soft, #f1ecff);color: var(--iwb-plp-accent, #5a3fd0)}
|
||||
.iwb-plp-dialog .iwb-plp-vdesc{background: var(--iwb-field, #fbfcfd);border: 1px dashed var(--iwb-plugin-border, #e2e6ec);border-radius: 8px;height:28px;margin-top:4px}
|
||||
.iwb-plp-dialog .iwb-plp-lrow span{color: var(--iwb-text2, #8a919c);font-size: 12px}
|
||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input{background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eceef2);border-radius:8px;height:32px}
|
||||
.iwb-plp-dialog .iwb-plp-lrow .iwb-input:focus{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff)}
|
||||
/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */
|
||||
.iwb-plp-ewrap{position:relative;flex:1 1 auto;min-height:0;display:flex;border-radius:9px;background: var(--plp-c8, #fbfcfd);border: 1px solid var(--plp-c11, #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{position:relative;flex:1 1 auto;min-height:0;display:flex;border-radius: 8px;background: var(--iwb-field, #fbfcfd);border: 1px solid var(--iwb-plugin-border, #eef0f3)}
|
||||
.iwb-plp-ewrap:focus-within{background: var(--iwb-plugin-card, #fff);border-color: var(--iwb-plp-accent-border, #cfc3ff);box-shadow:0 0 0 3px rgba(107,77,255,.08)}
|
||||
.iwb-plp-ewrap .iwb-plp-etext{flex:1 1 auto;min-height:0;border:0;background:transparent;box-shadow:none;color:transparent;caret-color:var(--plp-c22, #1d2129);position:relative;z-index:1;resize:none}
|
||||
.iwb-plp-ewrap .iwb-plp-etext:focus{background:transparent;border:0;box-shadow:none}
|
||||
.iwb-plp-hl{position:absolute;inset:0;padding:10px 12px;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;font-size:13px;line-height:1.9;color: var(--plp-c21, #5b6472);pointer-events:none;z-index:0}
|
||||
.iwb-plp-hlvar{color: var(--plp-c22, #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(--plp-c23, #dfe3e9)}
|
||||
.iwb-plp-dvar{background:transparent;color: var(--plp-c22, #1d2129);font-weight:600;padding:0}
|
||||
.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(--plp-c13, #e7e9ee)}
|
||||
.iwb-plp-hl{position:absolute;inset:0;padding:10px 12px;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;font-size:13px;line-height:1.9;color: var(--iwb-text2, #5b6472);pointer-events:none;z-index:0}
|
||||
.iwb-plp-hlvar{color: var(--iwb-text, #1d2129);font-weight:600}
|
||||
.iwb-plp-dialog .iwb-plp-vi.is-open{background: var(--iwb-plugin-hover, #eef0f3);color: var(--iwb-text2, #5b6472)}
|
||||
.iwb-plp-dialog .iwb-plp-vdesc{background:transparent;border: 1px dashed var(--iwb-plugin-border, #dfe3e9)}
|
||||
.iwb-plp-dvar{background:transparent;color: var(--iwb-text, #1d2129);font-weight:600;padding:0}
|
||||
.iwb-plp-hres{height:6px;margin: -4px 0 0;cursor:ns-resize;flex:0 0 auto;border-radius: 6px}
|
||||
.iwb-plp-hres:hover{background: var(--iwb-plugin-hover, #e7e9ee)}
|
||||
/* 正文可见性:textarea 透明,显示下方高亮层 */
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap{flex:1 1 auto;min-height:0;position:relative;display:flex;background: var(--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-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-insvar{color: var(--plp-c22, #1d2129)!important;background: var(--plp-c1, #fff)!important;border-color: var(--plp-c19, #e2e6ec)!important}
|
||||
.iwb-plp-insvar:hover{background: var(--plp-c24, #f4f6f9)!important}
|
||||
.iwb-plp-namebox{min-height:34px;height:34px;line-height:1.45;padding: 6px 10px;resize:vertical;overflow:auto;font-size: 13px}
|
||||
.iwb-plp-insvar{color: var(--iwb-text, #1d2129)!important;background: var(--iwb-plugin-card, #fff)!important;border-color: var(--iwb-plugin-border, #e2e6ec)!important}
|
||||
.iwb-plp-insvar:hover{background: var(--iwb-plugin-inset, #f4f6f9)!important}
|
||||
/* v1.7.5:编辑封面卡在框内;详情封面放大 */
|
||||
.iwb-plp-dialog .iwb-plp-ecov{width:100%;height:250px;overflow:hidden;border-radius:12px;background:var(--iwb-plugin-inset,#f3f4f7)}
|
||||
.iwb-plp-dialog .iwb-plp-ecov .iwb-plp-cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;border-radius:12px}
|
||||
@@ -481,7 +504,8 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
||||
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-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:详情正文独立滚动,长文不再压到底部按钮 */
|
||||
.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}
|
||||
@@ -489,48 +513,48 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki
|
||||
/* v1.8.0:详情标题/分组/标签移到封面下方;编辑标签改为输入+加号 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{align-items:flex-start}
|
||||
.iwb-plp-dleftcol{flex:0 0 264px;width:264px;display:flex;flex-direction:column;min-width:0}
|
||||
.iwb-plp-dtitle{font-size: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-dgroup{font-size:11.5px;background: var(--plp-c18, #eef0f4);color: var(--plp-c21, #5b6472);border-radius:999px;padding:2px 9px}
|
||||
.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-dlen{font-size:11.5px;color: var(--plp-c4, #9aa1ac)}
|
||||
.iwb-plp-dgroup{font-size: 12px;background: var(--iwb-plugin-inset, #eef0f4);color: var(--iwb-text2, #5b6472);border-radius:999px;padding: 2px 8px}
|
||||
.iwb-plp-dtag{font-size: 12px;background: var(--iwb-plp-accent-soft, #f4f0ff);color: var(--iwb-plp-accent, #5a3fd0);border-radius:999px;padding: 2px 8px}
|
||||
.iwb-plp-dlen{font-size: 12px;color: var(--iwb-text-dim, #9aa1ac)}
|
||||
.iwb-plp-tagwrap{display:flex;flex-direction:column;gap:6px;flex:1;min-width:0}
|
||||
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap:5px}
|
||||
.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-tagx{cursor:pointer;color: var(--plp-c4, #9aa1ac);font-style:normal}
|
||||
.iwb-plp-tagx:hover{color: var(--plp-c27, #c0392b)}
|
||||
.iwb-plp-tagchips{display:flex;flex-wrap:wrap;gap: 6px}
|
||||
.iwb-plp-tagchip{display:inline-flex;align-items:center;gap:4px;font-size: 12px;background: var(--iwb-plugin-inset, #eef0f4);border-radius:999px;padding:2px 8px;color: var(--iwb-text, #3f4450)}
|
||||
.iwb-plp-tagx{cursor:pointer;color: var(--iwb-text-dim, #9aa1ac);font-style:normal}
|
||||
.iwb-plp-tagx:hover{color: var(--iwb-err, #c0392b)}
|
||||
.iwb-plp-tagrow{display:flex;gap:6px}
|
||||
.iwb-plp-tagin{flex:1;min-width:0;height:30px}
|
||||
.iwb-plp-lrow-tags{align-items:flex-start}
|
||||
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;font-size:15px;line-height:28px}
|
||||
/* v1.8.1:详情标题/分组/标签左对齐并带标题;标签加号对齐修复 */
|
||||
.iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top:16px;color:var(--iwb-text,#1d2129)}
|
||||
.iwb-plp-dmeta{display:flex;flex-direction:column;gap: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-dmk{flex:0 0 30px;width:30px;font-size:11.5px;color: var(--plp-c4, #9aa1ac)}
|
||||
.iwb-plp-dmv{display:flex;flex-wrap:wrap;align-items:center;gap:5px;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-dtag{font-size:11.5px;color: var(--plp-c7, #5a3fd0);background: var(--plp-c25, #f4f0ff);border-radius:6px;padding:2px 9px}
|
||||
.iwb-plp-dempty{font-size:12px;color: var(--plp-c29, #b3b9c2)}
|
||||
.iwb-plp-dlen{font-size:12px;color: var(--plp-c20, #8a919c)}
|
||||
.iwb-plp-dmk{flex:0 0 30px;width:30px;font-size: 12px;color: var(--iwb-text-dim, #9aa1ac)}
|
||||
.iwb-plp-dmv{display:flex;flex-wrap:wrap;align-items:center;gap: 6px;min-width:0}
|
||||
.iwb-plp-dgroup{font-size:12px;color: var(--iwb-text, #3f4450);background: var(--iwb-plugin-inset, #f2f4f7);border-radius:6px;padding: 2px 8px}
|
||||
.iwb-plp-dtag{font-size: 12px;color: var(--iwb-plp-accent, #5a3fd0);background: var(--iwb-plp-accent-soft, #f4f0ff);border-radius:6px;padding: 2px 8px}
|
||||
.iwb-plp-dempty{font-size:12px;color: var(--iwb-text-dim, #b3b9c2)}
|
||||
.iwb-plp-dlen{font-size:12px;color: var(--iwb-text2, #8a919c)}
|
||||
.iwb-plp-tagrow{display:flex;align-items:center;gap:6px}
|
||||
.iwb-plp-tagin{height:30px;border-radius:8px}
|
||||
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;border-radius:8px;background: var(--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:hover{background: var(--plp-c30, #e9ecf1)}
|
||||
.iwb-plp-tagadd{flex:0 0 auto;width:30px;height:30px;padding:0;border-radius:8px;background: var(--iwb-plugin-inset, #f2f4f7);border: 1px solid var(--iwb-plugin-border, #e2e6ec);color: var(--iwb-text2, #5b6472);font-size: 15px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
|
||||
.iwb-plp-tagadd:hover{background: var(--iwb-plugin-hover, #e9ecf1)}
|
||||
/* v1.8.2:详情左右两栏卡片化 + 分割线 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{gap:14px;padding:16px;background: var(--plp-c9, #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-dbody{gap: 12px;padding:16px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dleftcol{flex:0 0 300px;width:300px;padding:12px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff);align-self:flex-start}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dcov{width:100%;height:270px;border-radius:10px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top:14px;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-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-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-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-dtitle{font-size:20px;font-weight:650;line-height:1.35;margin-top: 12px;color:var(--iwb-text,#1d2129)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top:12px;padding-top:12px;border-top: 1px solid var(--iwb-plugin-border, #eef0f3);gap:8px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;display:flex;flex-direction:column;padding: 12px 16px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff);overflow:hidden}
|
||||
.iwb-plp-dsec{font-size: 12px;font-weight:600;color: var(--iwb-text2, #8a919c);letter-spacing:.04em;padding-bottom:8px;margin-bottom:8px;border-bottom: 1px solid var(--iwb-plugin-border, #eef0f3);flex:0 0 auto}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow:auto;padding-right:10px;font-size: 14px;line-height:2;color: var(--iwb-text, #3a4048)}
|
||||
/* v1.8.3:详情左卡片撑到底、四边等距;正文恢复滚动不被底部遮挡 */
|
||||
.iwb-plp-dialog-detail{display:flex;flex-direction:column;overflow:hidden}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dbody{display:flex;flex:1 1 auto;min-height:0;overflow:hidden;gap:14px;padding:16px;background: var(--plp-c9, #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-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-dbody{display:flex;flex:1 1 auto;min-height:0;overflow:hidden;gap: 12px;padding:16px;background: var(--iwb-plugin-inset, #f4f5f7)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dleftcol{align-self:stretch;display:flex;flex-direction:column;overflow:auto;padding:12px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dright{flex:1 1 auto;min-width:0;min-height:0;overflow:hidden;display:flex;flex-direction:column;padding: 12px 16px;border: 1px solid var(--iwb-plugin-border, #e8eaee);border-radius:14px;background: var(--iwb-plugin-card, #fff)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtext{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;scrollbar-width:thin;padding-right:8px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dfooter{flex:0 0 auto}
|
||||
/* v1.8.4:右卡片纵向拉伸填满,正文出现滚动条 */
|
||||
@@ -539,23 +563,32 @@ 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}
|
||||
/* v1.8.7:详情标题缩小;分组/标签去底色;元信息加分割线与行高 */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:17px!important;font-weight:650;margin-top:12px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{margin-top:12px;padding-top: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-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-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-dtag{color: var(--plp-c7, #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-dmk{flex:0 0 auto;width:auto;font-size:12px;line-height:1.6;color: var(--iwb-text-dim, #9aa1ac)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dgroup,.iwb-plp-dialog-detail .iwb-plp-dtag{background:transparent!important;padding:0!important;border-radius:0!important;font-size: 13px;line-height:1.6;color: var(--iwb-text, #2f3540)}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtag{color: var(--iwb-plp-accent, #5a3fd0);}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dlen{font-size: 13px;line-height:1.6;color: var(--iwb-text, #2f3540)}
|
||||
/* v1.8.8:详情标题 14px;元信息行间浅分割线;封面底色更接近白色(编辑/详情统一) */
|
||||
.iwb-plp-dialog-detail .iwb-plp-dtitle{font-size:14px!important;font-weight:650;line-height:1.5;margin-top:12px}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmeta{gap:0}
|
||||
.iwb-plp-dialog-detail .iwb-plp-dmrow{padding: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 .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}
|
||||
/* v1.8.19:编辑区高亮变量不得加粗——加粗会改变字形宽度,导致点击位置逐次向左偏移 */
|
||||
.iwb-plp-hlvar{font-weight:400!important;letter-spacing:normal!important}
|
||||
/* v1.8.20:编辑区不再用透明 textarea+高亮层(两层字体/换行差异会让点击坐标逐次偏移);正文直接由 textarea 渲染,插入点 100% 对应光标 */
|
||||
.iwb-plp-ewrap .iwb-plp-hl{display:none!important}
|
||||
/* v1.9.3:变量着色改为「textarea 只负责文字 + 背层只画浅主色色块」——
|
||||
两层字体/换行/滚动条占位由 v1.7.7 规则保持一致,变量 span 沿用 400 字重(不加粗,宽度不漂移),
|
||||
文字仍由 textarea 自己画(可见),所以插入点/点击/选区完全不受影响。
|
||||
注:v1.8.20 停用高亮层是因为当时「透明 textarea + 背层画文字」两层文字错位;本版不画文字,只画色块,不会复发。 */
|
||||
.iwb-plp-ewrap .iwb-plp-hl{display:block!important;color:transparent!important;-webkit-text-fill-color:transparent!important}
|
||||
.iwb-plp-hlvar{color:transparent!important;-webkit-text-fill-color:transparent!important;background:color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 16%, transparent);border-radius:6px;box-shadow:0 0 0 1px color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 22%, transparent)}
|
||||
.iwb-plp-ewrap .iwb-plp-etext{color:var(--iwb-text,#2a2f36)!important;background:transparent!important}
|
||||
/* v1.8.21:高亮层隐藏后,正文文字必须可见(覆盖旧的 transparent !important) */
|
||||
/* v1.8.21:正文文字必须可见(覆盖旧的 transparent !important) */
|
||||
.iwb-plp-dialog .iwb-plp-emid .iwb-plp-ewrap .iwb-plp-etext{color:var(--iwb-text,#2a2f36)!important;caret-color:var(--iwb-text,#2a2f36)!important;-webkit-text-fill-color:var(--iwb-text,#2a2f36)!important}
|
||||
/* v1.9.3:右侧变量名与详情正文里的变量也用主色呼应(只读区,零功能风险) */
|
||||
.iwb-plp-dialog .iwb-plp-vname{color:var(--iwb-plp-accent,#5a3fd0)}
|
||||
.iwb-plp-dialog .iwb-plp-dvar{color:var(--iwb-plp-accent,#5a3fd0);background:var(--iwb-plp-accent-soft,#f1ecff);border-radius:6px;padding:0 2px}
|
||||
/* 回滚开关:若真机发现任何点击/光标异常,把下行打开即回到 v1.8.20 纯 textarea 状态。
|
||||
.iwb-plp-ewrap .iwb-plp-hl{display:none!important} */
|
||||
@@ -0,0 +1,244 @@
|
||||
// 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.0", /version:\s*'1\.13\.0'/.test(src))
|
||||
ok('package.json version = 1.13.0',
|
||||
JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version === '1.13.0')
|
||||
ok('manifest 已移除「分享时附带封面图片」开关声明',
|
||||
!/shareWithCover:\s*\{\s*type:\s*'boolean'/.test(src))
|
||||
ok('源码不再定义/读取 shareWithCover 设置',
|
||||
!/function shareWithCover \(\)/.test(src) && !/S\.get\('shareWithCover'\)/.test(src))
|
||||
|
||||
// ---- 2) sharePayload 两条显式分支 ----
|
||||
const m = src.match(/ function sharePayload \(p, withCover\) \{[\s\S]*?\n \}\n function shareFileName/)
|
||||
ok('从 src 找到 sharePayload(p, withCover)', !!m)
|
||||
const fnSrc = m ? m[0].replace(/\n function shareFileName$/, '') : ''
|
||||
const sandbox = {
|
||||
SHARE_TAG: 'IWB-PROMPT-SHARE',
|
||||
varsOf: () => [],
|
||||
coverToDataUrl: () => { throw new Error('不该读封面') },
|
||||
Promise, JSON, String, Number, Array, Object,
|
||||
}
|
||||
vm.createContext(sandbox)
|
||||
vm.runInContext(fnSrc, sandbox)
|
||||
const p = { name: '测试词', text: '一只猫', group: '分组A', tags: ['x'], cover: { img: 'a.jpg' } }
|
||||
|
||||
const textPlain = await sandbox.sharePayload(p, false)
|
||||
const bodyPlain = JSON.parse(textPlain.split('\n')[1])
|
||||
ok('文本分享(false):分享文本无 cover 字段', !('cover' in bodyPlain.sharing))
|
||||
ok('文本分享(false):不读封面(stub 抛错未触发)', true)
|
||||
ok('文本分享(false):名字/正文/分组仍在',
|
||||
bodyPlain.sharing.name === '测试词' && bodyPlain.sharing.text === '一只猫' && bodyPlain.sharing.group === '分组A')
|
||||
|
||||
sandbox.coverToDataUrl = () => Promise.resolve('data:image/jpeg;base64,AAAA')
|
||||
const textFile = await sandbox.sharePayload(p, true)
|
||||
const bodyFile = JSON.parse(textFile.split('\n')[1])
|
||||
ok('文件分享(true):分享文本带 cover', bodyFile.sharing.cover === 'data:image/jpeg;base64,AAAA')
|
||||
|
||||
// ---- 3) v1.10.0 UI 契约 ----
|
||||
ok('文本分享复制纯文字(doShareText 用 api.copy)',
|
||||
/function doShareText \(p\)[\s\S]{0,260}api\.copy\(text\)/.test(src))
|
||||
ok('文件分享导出为文件(doShareFile 用 api.exportText)',
|
||||
/function doShareFile \(p\)[\s\S]{0,260}api\.exportText\(shareFileName\(p\), text\)/.test(src))
|
||||
ok('文件名做安全化(过滤 \\/:*?"<>|)',
|
||||
/replace\(\/\[\\\\\/:\*\?"<>\|]\/g, '_'\)/.test(src))
|
||||
ok('剪贴板导入与文件导入共用 importShareItem(1 定义 + 2 调用)',
|
||||
(src.match(/importShareItem\s*\(item\)/g) || []).length >= 3)
|
||||
ok('文件导入走 api.importText()',
|
||||
/function importShareFromFile \(\)[\s\S]{0,160}api\.importText\(\)/.test(src))
|
||||
ok('顶部三按钮:文件 / 文本 / 新建',
|
||||
/text: '文件'[\s\S]{0,200}text: '文本'[\s\S]{0,200}text: '新建'/.test(src))
|
||||
ok('右键菜单已去掉「移动到分组」分类',
|
||||
!/移动到分组/.test(src))
|
||||
ok('右键菜单含 文本分享 / 文件分享(iwb-ctx-item 项)',
|
||||
/iwb-ctx-item', text: '文本分享'[\s\S]{0,260}iwb-ctx-item', text: '文件分享'/.test(src))
|
||||
ok('详情底部含 文本分享 / 文件分享 两按钮',
|
||||
/text: '文本分享'/.test(src) && /text: '文件分享'/.test(src))
|
||||
ok('详情底部分享组与插入组之间是竖向分割线(DOM 顺序:文件分享 → 竖线 → 复制全文)',
|
||||
/footEl\.appendChild\(shareFile\)[\s\S]{0,240}iwb-plp-foot-vsep[\s\S]{0,160}footEl\.appendChild\(cp\)/.test(src))
|
||||
ok('竖线样式:1px 宽 / 18px 高 / 边框色 / 居中',
|
||||
/\.iwb-plp-foot-vsep\s*\{[^}]*width:\s*1px[^}]*height:\s*18px[^}]*align-self:\s*center[^}]*background:\s*var\(--iwb-border\)/.test(css))
|
||||
ok('设置面板不再有单条导入入口(impShareBtn 已移除)',
|
||||
!/impShareBtn/.test(src))
|
||||
ok('旧的「分享…」按钮(带图完整版)已删除',
|
||||
!/text: '分享'/.test(src) && !/function doShare \(p\)/.test(src))
|
||||
|
||||
// ---- 4) v1.9.3 变量着色样式不变量(回归保护)----
|
||||
ok('高亮层恢复显示(不再 display:none)',
|
||||
/\.iwb-plp-ewrap \.iwb-plp-hl\{display:block!important/.test(css))
|
||||
ok('高亮层整层文字透明(不与 textarea 重影)',
|
||||
/\.iwb-plp-ewrap \.iwb-plp-hl\{[^}]*color:transparent!important[^}]*-webkit-text-fill-color:transparent!important/.test(css))
|
||||
ok('变量 span 只画主色背景、不画文字',
|
||||
/\.iwb-plp-hlvar\{[^}]*color:transparent!important[^}]*background:color-mix\(in srgb, var\(--iwb-plp-accent/.test(css))
|
||||
ok('变量 span 不加粗(避开点击偏移根因)',
|
||||
/\.iwb-plp-hlvar\{font-weight:400!important/.test(css))
|
||||
ok('textarea 文字仍可见(-webkit-text-fill-color 兜底)',
|
||||
/\.iwb-plp-etext\{color:var\(--iwb-text[^}]*-webkit-text-fill-color:var\(--iwb-text/.test(css))
|
||||
ok('高亮层与 textarea 滚动条占位一致',
|
||||
/\.iwb-plp-emid \.iwb-plp-ewrap \.iwb-plp-hl\{overflow:hidden!important;scrollbar-gutter:stable\}/.test(css))
|
||||
ok('高亮层跟随 textarea 横向滚动',
|
||||
/hl\.scrollTop = textIn\.scrollTop; hl\.scrollLeft = textIn\.scrollLeft/.test(src))
|
||||
ok('右侧变量名与详情变量用主色呼应',
|
||||
/\.iwb-plp-vname\{color:var\(--iwb-plp-accent/.test(css) && /\.iwb-plp-dvar\{color:var\(--iwb-plp-accent/.test(css))
|
||||
|
||||
// ---- 5) v1.11.0 封面文件治理(P1)----
|
||||
// 目标:① 保存/上传时把内联 base64 落成文件;② 孤儿封面能被回收;③ 回收不能误删。
|
||||
// 纯文本断言跑不了真实 FS ⇒ 这里用「函数抽出来 + 假 fileApi」跑行为。
|
||||
ok('封面命名统一走 coverFileName(哈希只在它内部实现一次)',
|
||||
/function coverFileName \(dataUrl\)/.test(src) && (src.match(/var h = 5381/g) || []).length === 1 && (src.match(/coverFileName\(/g) || []).length >= 6)
|
||||
ok('保存路径先落文件(ensureCoverFile 包住 doSave)',
|
||||
/function doSave \(\)[\s\S]{0,600}ensureCoverFile\(c\.cover\)/.test(src))
|
||||
ok('上传封面即落文件(不再把 dataURL 写回 draft.cover)',
|
||||
/api\.putCover\([\s\S]{0,400}ensureCoverFile\(r\.ref\)/.test(src))
|
||||
ok('删词条后安排一次回收', /已删除'[\s\S]{0,80}scheduleCoverGc\(/.test(src))
|
||||
ok('启动加载后安排一次回收(等 convertInlineCovers 写完)',
|
||||
/convertInlineCovers\(\)[\s\S]{0,120}scheduleCoverGc\(4000\)/.test(src))
|
||||
ok('自动回收有「数据来源」闸门(不是插件 JSON 读来的就不删)',
|
||||
/!o\.manual && !dataFromPlugin\) return Promise\.resolve\(\{ removed: 0, bytes: 0, skipped: 'no-source' \}\)/.test(src))
|
||||
ok('keep 为空时不删(空集合 = 全删的形状)',
|
||||
/if \(!kept && !o\.manual\) return Promise\.resolve\(\{ removed: 0, bytes: 0, skipped: 'empty' \}\)/.test(src))
|
||||
ok('只删图片扩展名文件', src.includes('/\\.(jpg|jpeg|png|webp)$/i.test(name)'))
|
||||
ok('设置页有显式清理入口 + 现读一次数据',
|
||||
/text: '清理未引用封面'/.test(src) && /plpGcCoverFiles\(FA, plpCoverNamesOf\(state\.prompts\), \{ manual: true \}\)/.test(src))
|
||||
ok('pending(刚 put 未被引用)不会被回收',
|
||||
/Object\.keys\(pendingCoverNames\)\.forEach\(function \(n\) \{ names\.push\(n\) \}\)/.test(src))
|
||||
|
||||
// 行为:抽出 plpGcCoverFiles 本体,用假 fileApi 验证「只删未被引用的图片文件」
|
||||
const gcMatch = src.match(/ function plpGcCoverFiles \(FA, keepNames, opts\) \{[\s\S]*?\n \}\n/)
|
||||
ok('从 src 抽出 plpGcCoverFiles', !!gcMatch)
|
||||
if (gcMatch) {
|
||||
const removed = []
|
||||
const fakeFA = {
|
||||
list: async () => [
|
||||
{ name: 'cused1.jpg', size: 100 },
|
||||
{ name: 'corphan1.jpg', size: 200 },
|
||||
{ name: 'cshared.jpg', size: 300 },
|
||||
{ name: 'notes.txt', size: 1 },
|
||||
],
|
||||
remove: async (name) => { removed.push(name); return { ok: true } },
|
||||
}
|
||||
const gcSandbox = { Promise, JSON, String, Number, Array, Object, RegExp, console }
|
||||
vm.createContext(gcSandbox)
|
||||
vm.runInContext('var PLP_GC_BUSY = false\n' + gcMatch[0] + '\nthis.gc = plpGcCoverFiles', gcSandbox)
|
||||
const r1 = await gcSandbox.gc(fakeFA, ['cused1.jpg'], {})
|
||||
ok('回收:只删未引用图片(保留引用项与非图片文件)',
|
||||
JSON.stringify(removed) === '["corphan1.jpg","cshared.jpg"]')
|
||||
ok('回收:返回删除数与字节数', r1.removed === 2 && r1.bytes === 500)
|
||||
const r2 = await gcSandbox.gc(fakeFA, [], {})
|
||||
ok('回收:keep 为空且非人工 ⇒ 不删(skipped=empty)', r2.skipped === 'empty' && r2.removed === 0)
|
||||
const r3 = await gcSandbox.gc(null, [], {})
|
||||
ok('回收:无文件能力 ⇒ skipped=no-fs', r3.skipped === 'no-fs')
|
||||
}
|
||||
|
||||
// ---- 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))
|
||||
|
||||
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,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)
|
||||
Reference in new issue
Block a user