Files
image-workbench-desktop/src/ui-components.js
T

55 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;(function (global) {
'use strict'
const React = global.React
if (!React || !React.createElement) return
const el = React.createElement
function ResultImg(props) {
const useState = React.useState
const [hover, setHover] = useState(false)
const item = props.item || {}
const doCopyRef = () => { props.onCopyRef && props.onCopyRef(item.url) }
const doCopyLink = () => {
// 统一走 IWBClipboardCopy(2026-11-24)
try { if (global.IWBClipboardCopy) global.IWBClipboardCopy.copyText(item.url) } catch (e) { /* ignore */ }
}
return el('div', {
className: 'iwb-rimg',
onMouseEnter: () => setHover(true),
onMouseLeave: () => setHover(false),
},
// 单击只让节点选中(不弹预览),双击才开大图:与输出节点结果图同一手势。
el('img', { className: props.cls || 'iwb-result-thumb', src: item.url, alt: 'img', loading: 'lazy', title: '双击放大', onClick: (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } }, onDoubleClick: (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } if (props.onPreview) props.onPreview(item.url) } }),
hover ? el('div', { className: 'iwb-rimg-actions' },
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制为参考图节点', onClick: doCopyRef }, props.copyIcon || '⧉', ' 复制到画布'),
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片链接', onClick: doCopyLink }, '🔗 链接'),
) : null,
)
}
// 共享「下载浮层」:底部渐变 + 下载(可选复制),hover/focus 才出现。
// 图库插件是原生 DOM,用同一组 token 在插件 CSS 里复刻;宿主这里只需一个 React 组件。
// pointer-events:浮层条本身不吃事件(否则会挡住图片点击/双击),只有悬停后按钮才可点。
function ResultDownloadOverlay (props) {
const p = props || {}
const stopDown = (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } }
return el('div', { className: 'iwb-dl-ov' },
p.children,
el('div', { className: 'iwb-dl-bar' },
p.onCopyRef ? el('button', {
className: 'iwb-dl-btn iwb-dl-btn-ghost',
title: p.copyTitle || '插入为参考图节点',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); p.onCopyRef() },
}, p.copyIcon || null, el('span', { className: 'iwb-dl-txt' }, p.copyLabel || '复制')) : null,
el('button', {
className: 'iwb-dl-btn',
title: p.downloadTitle || '下载原图',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); if (p.onDownload) p.onDownload() },
}, p.icon || null, el('span', { className: 'iwb-dl-txt' }, p.label || '下载')),
),
)
}
global.IWBResultImg = ResultImg
global.IWBResultDownloadOverlay = ResultDownloadOverlay
})(typeof window !== 'undefined' ? window : globalThis)