/** * ShowcaseView.js * 处理LoRA模型展示内容(图片、视频)的功能模块 */ import { showToast, copyToClipboard, getLocalExampleImageUrl, initLazyLoading, initNsfwBlurHandlers, initMetadataPanelHandlers, toggleShowcase, setupShowcaseScroll, scrollToTop } from '../../utils/uiHelpers.js'; import { state } from '../../state/index.js'; import { NSFW_LEVELS } from '../../utils/constants.js'; /** * 渲染展示内容 * @param {Array} images - 要展示的图片/视频数组 * @param {string} modelHash - Model hash for identifying local files * @returns {string} HTML内容 */ export function renderShowcaseContent(images, modelHash) { if (!images?.length) return '
No example images available
'; // Filter images based on SFW setting const showOnlySFW = state.settings.show_only_sfw; let filteredImages = images; let hiddenCount = 0; if (showOnlySFW) { filteredImages = images.filter(img => { const nsfwLevel = img.nsfwLevel !== undefined ? img.nsfwLevel : 0; const isSfw = nsfwLevel < NSFW_LEVELS.R; if (!isSfw) hiddenCount++; return isSfw; }); } // Show message if no images are available after filtering if (filteredImages.length === 0) { return `

All example images are filtered due to NSFW content settings

Your settings are currently set to show only safe-for-work content

You can change this in Settings

`; } // Show hidden content notification if applicable const hiddenNotification = hiddenCount > 0 ? `
${hiddenCount} ${hiddenCount === 1 ? 'image' : 'images'} hidden due to SFW-only setting
` : ''; return `
Scroll or click to show ${filteredImages.length} examples
`; } /** * Generate metadata panel HTML */ function generateMetadataPanel(hasParams, hasPrompts, prompt, negativePrompt, size, seed, model, steps, sampler, cfgScale, clipSkip) { // Create unique IDs for prompt copying const promptIndex = Math.random().toString(36).substring(2, 15); const negPromptIndex = Math.random().toString(36).substring(2, 15); let content = '
'; if (hasParams) { content += `
${size ? `
Size:${size}
` : ''} ${seed ? `
Seed:${seed}
` : ''} ${model ? `
Model:${model}
` : ''} ${steps ? `
Steps:${steps}
` : ''} ${sampler ? `
Sampler:${sampler}
` : ''} ${cfgScale ? `
CFG:${cfgScale}
` : ''} ${clipSkip ? `
Clip Skip:${clipSkip}
` : ''}
`; } if (!hasParams && !hasPrompts) { content += ` `; } if (prompt) { content += ` `; } if (negativePrompt) { content += ` `; } content += '
'; return content; } /** * 生成视频包装HTML */ function generateVideoWrapper(img, heightPercent, shouldBlur, nsfwText, metadataPanel, urls) { return `
${shouldBlur ? ` ` : ''} ${shouldBlur ? `

${nsfwText}

` : ''} ${metadataPanel}
`; } /** * 生成图片包装HTML */ function generateImageWrapper(img, heightPercent, shouldBlur, nsfwText, metadataPanel, urls) { return `
${shouldBlur ? ` ` : ''} Preview ${shouldBlur ? `

${nsfwText}

` : ''} ${metadataPanel}
`; } // Use the shared setupShowcaseScroll function with the correct modal ID export { setupShowcaseScroll, scrollToTop, toggleShowcase }; // Initialize the showcase scroll when this module is imported document.addEventListener('DOMContentLoaded', () => { setupShowcaseScroll('loraModal'); });