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

61 lines
3.2 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 useEffect = React.useEffect
const [hover, setHover] = useState(false)
const item = props.item || {}
// 2026-12-02:落地状态展示改在输出节点体(ui-node-bodies);本组件全仓无调用点,保持纯展示
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 才出现。
// 2026-12-03(用户裁定):只改输出节点这一处呈现 —— 底部横条会压住矮图的中心,改成只占右下角。
// 约束(上一次改造踩过的坑):① 容器 pointer-events:none、只有按钮 auto;② 不改任何类名之外的 DOM 结构;
// ③ 不动 z-index 层级表、不动 token 体系;旧的 .iwb-dl-bar 样式保留在 CSS 里可随时回退。
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-corner' },
p.onCopyRef ? el('button', {
className: 'iwb-dl-round',
title: p.copyTitle || '插入为参考图节点',
'aria-label': p.copyLabel || '复制',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); p.onCopyRef() },
}, p.copyIcon || '⧉') : null,
el('button', {
className: 'iwb-dl-round iwb-dl-round-primary',
title: p.downloadTitle || '下载原图',
'aria-label': p.label || '下载',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); if (p.onDownload) p.onDownload() },
}, p.icon || '↓'),
),
)
}
global.IWBResultImg = ResultImg
global.IWBResultDownloadOverlay = ResultDownloadOverlay
})(typeof window !== 'undefined' ? window : globalThis)