diff --git a/plugins/index.json b/plugins/index.json index 022c181..0af6cdc 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -19,9 +19,9 @@ }, { "id": "gallery", - "file": "plugin-gallery.e92b04e71bd5.js", - "version": "1.4.0", - "integrity": "sha256-6SsE5xvVaOqk4EZrlF62AZVSfyjlj6IoOV7Yc+3aYWw=" + "file": "plugin-gallery.6a122aea14bf.js", + "version": "1.4.1", + "integrity": "sha256-ahIq6hS/Mch9XfCLQWnPJeirbsIqSbPFE+f08F4Q6PM=" }, { "id": "image-annotate", diff --git a/plugins/runtime/plugin-gallery.e92b04e71bd5.js b/plugins/runtime/plugin-gallery.6a122aea14bf.js similarity index 88% rename from plugins/runtime/plugin-gallery.e92b04e71bd5.js rename to plugins/runtime/plugin-gallery.6a122aea14bf.js index 56b6f7a..1c3d796 100644 --- a/plugins/runtime/plugin-gallery.e92b04e71bd5.js +++ b/plugins/runtime/plugin-gallery.6a122aea14bf.js @@ -36,6 +36,31 @@ node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v) } function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) } + + // v1.4.1:底栏按钮改用图标(窄栏里「刷新/设置」会被挤成竖排两行) + var SVG_NS = 'http://www.w3.org/2000/svg' + function iconBtn (label, build, title) { + var b = el('button', { class: 'iwb-btn iwb-btn-sm iwb-gal-icobtn', title: title || label, 'aria-label': label }) + var svg = document.createElementNS(SVG_NS, 'svg') + svg.setAttribute('viewBox', '0 0 16 16') + svg.setAttribute('width', '14') + svg.setAttribute('height', '14') + svg.setAttribute('fill', 'none') + svg.setAttribute('stroke', 'currentColor') + svg.setAttribute('stroke-width', '1.5') + svg.setAttribute('stroke-linecap', 'round') + svg.setAttribute('stroke-linejoin', 'round') + svg.setAttribute('aria-hidden', 'true') + build(svg) + b.appendChild(svg) + return b + } + function svgPath (svg, d) { + var p = document.createElementNS(SVG_NS, 'path') + p.setAttribute('d', d) + svg.appendChild(p) + return p + } function sel (options, value) { var s = el('select', { class: 'iwb-input iwb-select-compact' }) for (var i = 0; i < options.length; i++) { @@ -70,10 +95,30 @@ var countEl = el('span', { class: 'iwb-gal-count', text: '0 / 0 张' }) var pickedEl = el('span', { class: 'iwb-gal-sel', text: '' }) var statusEl = el('span', { class: 'iwb-gal-status', text: '' }) - var refreshBtn = el('button', { class: 'iwb-btn iwb-btn-sm', text: '刷新', title: '重新向宿主拉取图库(图床恢复/外部改动后点这里)' }) + var refreshBtn = iconBtn('刷新', function (svg) { + svgPath(svg, 'M13.2 6.4A5.4 5.4 0 1 0 13.4 9.4') + svgPath(svg, 'M13.2 2.6v3.8H9.4') + }, '刷新:重新向宿主拉取图库(图床恢复/外部改动后点这里)') refreshBtn.addEventListener('click', function () { load(true) }) // v1.4.0:三个下拉不再占用前台(窄栏放不下、也显乱)——收进「设置」浮层,点按钮才展开。 - var setBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-gal-setbtn', text: '设置', title: '图库设置:插入尺寸 / 图幅 / 时间范围', 'aria-expanded': 'false' }) + var setBtn = iconBtn('设置', function (svg) { + var c1 = document.createElementNS(SVG_NS, 'circle') + c1.setAttribute('cx', '8'); c1.setAttribute('cy', '8'); c1.setAttribute('r', '4.2') + svg.appendChild(c1) + var c2 = document.createElementNS(SVG_NS, 'circle') + c2.setAttribute('cx', '8'); c2.setAttribute('cy', '8'); c2.setAttribute('r', '1.6') + svg.appendChild(c2) + for (var i = 0; i < 8; i++) { + var a = i * Math.PI / 4 + var x1 = (8 + Math.cos(a) * 4.2).toFixed(2) + var y1 = (8 + Math.sin(a) * 4.2).toFixed(2) + var x2 = (8 + Math.cos(a) * 5.6).toFixed(2) + var y2 = (8 + Math.sin(a) * 5.6).toFixed(2) + svgPath(svg, 'M' + x1 + ' ' + y1 + 'L' + x2 + ' ' + y2) + } + }, '图库设置:插入尺寸 / 图幅 / 时间范围') + setBtn.classList.add('iwb-gal-setbtn') + setBtn.setAttribute('aria-expanded', 'false') var settings = el('div', { class: 'iwb-gal-settings', role: 'dialog', 'aria-label': '图库设置' }) settings.style.display = 'none' var foot = el('div', { class: 'iwb-gal-foot' }, @@ -325,7 +370,7 @@ global.IWBPluginHost.register({ id: 'gallery', name: '图库', - version: '1.4.0', + version: '1.4.1', apiVersion: 1, capabilities: ['panels', 'gallery'], data: { schemaVersion: 1, maxBytes: 65536 }, diff --git a/style.css b/style.css index 3fa38ef..0705019 100644 --- a/style.css +++ b/style.css @@ -2128,6 +2128,10 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s /* 图库设置浮层(v1.4.0):三个下拉不再占前台,点「设置」从底栏上方浮出 */ .iwb-history-embedded { position: relative; } .iwb-gal-setbtn { margin-left: auto; flex: 0 0 auto; } +/* 底栏图标按钮(v1.4.1):固定方形、不换行,窄栏也不挤成竖排文字 */ +.iwb-gal-icobtn { width: 22px; height: 22px; min-width: 22px; padding: 0; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; line-height: 1; } +.iwb-gal-icobtn svg { display: block; pointer-events: none; } +.iwb-gal-icobtn:hover { color: var(--iwb-text); } .iwb-gal-setbtn-on { background: var(--iwb-layer2); border-color: var(--iwb-border-strong, var(--iwb-border)); } .iwb-gal-settings { position: absolute; right: 12px; bottom: 44px; z-index: 30; width: 186px; max-width: calc(100% - 24px); diff --git a/tests/plugin-gallery-recovery-test.js b/tests/plugin-gallery-recovery-test.js index 6e54fe3..4798dfb 100644 --- a/tests/plugin-gallery-recovery-test.js +++ b/tests/plugin-gallery-recovery-test.js @@ -30,9 +30,10 @@ async function boot ({ items, thumb, clock }) { let mounted = null const calls = { list: 0, thumb: 0 } + let patched = null const ctx = { ui: { registerPanel (p) { mounted = p.mount } }, - data: { read: async () => ({ cfg: { tile: 130 } }), patch: async () => true }, + data: { read: async () => ({ cfg: { tile: 130 } }), patch: async (d) => { patched = d; return true } }, gallery: { list: async () => { calls.list++; return { items: items.slice(), total: items.length } }, thumb: async (n) => { calls.thumb++; return thumb(n) }, @@ -46,7 +47,7 @@ async function boot ({ items, thumb, clock }) { const node = window.document.getElementById('host') mounted(node) await wait(60) - return { window, document: window.document, node, calls, clock } + return { window, document: window.document, node, calls, clock, get patched () { return patched } } } ;(async () => { @@ -92,12 +93,53 @@ async function boot ({ items, thumb, clock }) { assert.strictEqual(env.calls.list, 2, '面板重新可见且间隔 >5s 应自动重拉,实际 ' + env.calls.list) // 底部「刷新」按钮:随时强制重拉 - const btn = Array.from(env.node.querySelectorAll('.iwb-gal-foot button')).find((b) => b.textContent === '刷新') - assert.ok(btn, '底部应有「刷新」按钮') + const footBtns = Array.from(env.node.querySelectorAll('.iwb-gal-foot button')) + const btn = footBtns.find((b) => b.getAttribute('aria-label') === '刷新') + assert.ok(btn, '底部应有刷新按钮(aria-label=刷新)') + // 图标按钮:不显示文字,只有 svg + assert.strictEqual(btn.textContent.trim(), '', '刷新按钮不应再显示文字(窄栏会被挤成竖排)') + assert.ok(btn.querySelector('svg'), '刷新按钮应有 svg 图标') btn.dispatchEvent(new env.window.MouseEvent('click', { bubbles: true })) await wait(60) assert.strictEqual(env.calls.list, 3, '点「刷新」应重拉列表,实际 ' + env.calls.list) } - console.log('plugin-gallery recovery checks passed(坏图不留白块 / 自动恢复 / 防抖 / 手动刷新)') + // ---- 3) 三个下拉收进「设置」浮层(不在前台占位)---- + { + const clock = { now: 20_000 } + const good = 'data:image/svg+xml;utf8,' + encodeURIComponent('') + const env = await boot({ items: [{ name: 'a.png', w: 200, h: 300 }], thumb: () => good, clock }) + const panel = env.node.querySelector('.iwb-gal-settings') + assert.ok(panel, '应有设置浮层容器') + assert.strictEqual(panel.style.display, 'none', '设置浮层默认隐藏(不在前台展示)') + assert.strictEqual(env.node.querySelectorAll('.iwb-gal-foot select').length, 0, '底栏不应直接放下拉') + const selects = panel.querySelectorAll('select') + assert.strictEqual(selects.length, 3, '设置里应有 3 个下拉,实际 ' + selects.length) + const labels = Array.from(panel.querySelectorAll('.iwb-gal-setlabel')).map((x) => x.textContent) + assert.deepStrictEqual(labels, ['插入尺寸', '图幅', '时间范围']) + + const btn = env.node.querySelector('.iwb-gal-setbtn') + assert.strictEqual(btn.textContent.trim(), '', '设置按钮不应显示文字') + assert.ok(btn.querySelector('svg'), '设置按钮应有 svg 图标') + assert.strictEqual(btn.getAttribute('aria-label'), '设置') + btn.dispatchEvent(new env.window.MouseEvent('click', { bubbles: true })) + assert.notStrictEqual(panel.style.display, 'none', '点「设置」应展开浮层') + assert.strictEqual(btn.getAttribute('aria-expanded'), 'true') + + // 点浮层外部关闭 + env.document.body.dispatchEvent(new env.window.MouseEvent('pointerdown', { bubbles: true })) + await wait(20) + assert.strictEqual(panel.style.display, 'none', '点外部应收起浮层') + + // 改图幅 → 落盘 + 重排 + btn.dispatchEvent(new env.window.MouseEvent('click', { bubbles: true })) + const tileSel = Array.from(panel.querySelectorAll('select'))[1] + tileSel.value = '170' + tileSel.dispatchEvent(new env.window.Event('change')) + await wait(320) + assert.ok(env.patched, '改设置应通过 ctx.data 落盘') + assert.strictEqual(env.patched.cfg.tile, '170', '落盘应带新的图幅') + } + + console.log('plugin-gallery recovery checks passed(坏图不留白块 / 自动恢复 / 防抖 / 手动刷新 / 设置浮层)') })().catch((e) => { console.error(e); process.exit(1) }) \ No newline at end of file