diff --git a/web/debug.js b/web/debug.js index 511de6f..daa1b66 100644 --- a/web/debug.js +++ b/web/debug.js @@ -28,7 +28,7 @@ function createDebugSection(title) { margin: '8px 0', padding: '8px', borderRadius: '4px', - backgroundColor: 'rgba(0,0,0,0.2)' + backgroundColor: 'rgba(0,0,0,0.2)', }) const header = mtb_ui.makeElement('h3', { @@ -37,7 +37,7 @@ function createDebugSection(title) { borderBottom: '1px solid rgba(255,255,255,0.1)', fontSize: '14px', fontWeight: 'bold', - color: '#9f9' + color: '#9f9', }) header.textContent = title section.appendChild(header) @@ -47,21 +47,21 @@ function createDebugSection(title) { function createDebugContent(content, type) { const wrapper = mtb_ui.makeElement('div', { - margin: '4px 0' + margin: '4px 0', }) if (type === 'text') { const text = mtb_ui.makeElement('p', { margin: '2px 0', fontFamily: 'monospace', - whiteSpace: 'pre-wrap' + whiteSpace: 'pre-wrap', }) text.innerHTML = content wrapper.appendChild(text) } else if (type === 'image') { const img = mtb_ui.makeElement('img', { width: '100%', - borderRadius: '2px' + borderRadius: '2px', }) img.src = content wrapper.appendChild(img) @@ -148,18 +148,18 @@ app.registerExtension({ const uiData = data.ui || data if (uiData.items) { - uiData.items.forEach(item => { - const inputName = item.input - if (!inputData[inputName]) { - inputData[inputName] = { text: [], b64_images: [] } - } - if (item.text) { - inputData[inputName].text.push(...item.text) - } - if (item.b64_images) { - inputData[inputName].b64_images.push(...item.b64_images) - } - }) + uiData.items.forEach((item) => { + const inputName = item.input + if (!inputData[inputName]) { + inputData[inputName] = { text: [], b64_images: [] } + } + if (item.text) { + inputData[inputName].text.push(...item.text) + } + if (item.b64_images) { + inputData[inputName].b64_images.push(...item.b64_images) + } + }) } let widgetI = 1 @@ -171,23 +171,18 @@ app.registerExtension({ const section = createDebugSection(inputName) if (content.text.length > 0) { - content.text.forEach(text => { + content.text.forEach((text) => { section.appendChild(createDebugContent(text, 'text')) }) } if (content.b64_images.length > 0) { - content.b64_images.forEach(img => { + content.b64_images.forEach((img) => { section.appendChild(createDebugContent(img, 'image')) }) } - this.addDOMWidget( - `debug_section_${widgetI}`, - 'CUSTOM', - section, - {} - ) + this.addDOMWidget(`debug_section_${widgetI}`, 'CUSTOM', section, {}) widgetI++ } diff --git a/web/imageFeed.js b/web/imageFeed.js index 9e3625a..3d13de5 100644 --- a/web/imageFeed.js +++ b/web/imageFeed.js @@ -13,40 +13,40 @@ import { api } from '../../scripts/api.js' import { app } from '../../scripts/app.js' import { LocalStorageManager } from './comfy_shared.js' const styles = { - lighbox: { - position: 'fixed', - top: 0, - left: 0, - width: '100vw', - height: '100vh', - background: 'rgba(0,0,0,0.5)', - display: 'none', - justifyContent: 'center', - alignItems: 'center', - zIndex: 999, - }, - lightboxBtn: (extra) => ({ - position: 'absolute', - top: '50%', - background: 'none', - border: 'none', - color: '#fff', - zIndex: 1000, - fontSize: '30px', - cursor: 'pointer', - pointerEvents: 'auto', - ...extra, - }), - img_list: { - minHeight: '30px', - maxHeight: '300px', - width: '100vw', - position: 'absolute', - bottom: 0, - zIndex: 10, - background: '#333', - overflow: 'auto', - }, + lighbox: { + position: 'fixed', + top: 0, + left: 0, + width: '100vw', + height: '100vh', + background: 'rgba(0,0,0,0.5)', + display: 'none', + justifyContent: 'center', + alignItems: 'center', + zIndex: 999, + }, + lightboxBtn: (extra) => ({ + position: 'absolute', + top: '50%', + background: 'none', + border: 'none', + color: '#fff', + zIndex: 1000, + fontSize: '30px', + cursor: 'pointer', + pointerEvents: 'auto', + ...extra, + }), + img_list: { + minHeight: '30px', + maxHeight: '300px', + width: '100vw', + position: 'absolute', + bottom: 0, + zIndex: 10, + background: '#333', + overflow: 'auto', + }, } let currentImageIndex = 0 @@ -58,299 +58,299 @@ const storage = new LocalStorageManager('mtb') let activated = storage.get('image_feed', false) app.registerExtension({ - name: 'mtb.ImageFeed', - setup: () => { - app.ui.settings.addSetting({ - id: 'mtb.Main.image-feed-enabled', - category: ['mtb', ' Main', 'image-feed-enabled'], - name: 'Enable Image Feed', - type: 'boolean', - defaultValue: false, - attrs: { - style: { - fontFamily: 'monospace', - }, - }, - async onChange(value) { - storage.set('image_feed', value) - activated = value - }, - }) - }, - init: async () => { - if (!activated) { - return - } - const pythongossFeed = app.extensions.find( - (e) => e.name === 'pysssss.ImageFeed', - ) - if (pythongossFeed) { - console.warn( - "[mtb] - Aborting the loading of mtb's imageFeed in favor of pysssss.ImageFeed", - ) - activated = false // just in case other methods are added later on - return - } - // - HTML & CSS - //- lightbox - const lightboxContainer = document.createElement('div') - Object.assign(lightboxContainer.style, styles.lighbox) + name: 'mtb.ImageFeed', + setup: () => { + app.ui.settings.addSetting({ + id: 'mtb.Main.image-feed-enabled', + category: ['mtb', ' Main', 'image-feed-enabled'], + name: 'Enable Image Feed', + type: 'boolean', + defaultValue: false, + attrs: { + style: { + fontFamily: 'monospace', + }, + }, + async onChange(value) { + storage.set('image_feed', value) + activated = value + }, + }) + }, + init: async () => { + if (!activated) { + return + } + const pythongossFeed = app.extensions.find( + (e) => e.name === 'pysssss.ImageFeed', + ) + if (pythongossFeed) { + console.warn( + "[mtb] - Aborting the loading of mtb's imageFeed in favor of pysssss.ImageFeed", + ) + activated = false // just in case other methods are added later on + return + } + // - HTML & CSS + //- lightbox + const lightboxContainer = document.createElement('div') + Object.assign(lightboxContainer.style, styles.lighbox) - const lightboxImage = document.createElement('img') - Object.assign(lightboxImage.style, { - maxHeight: '100%', - maxWidth: '100%', - borderRadius: '5px', - }) + const lightboxImage = document.createElement('img') + Object.assign(lightboxImage.style, { + maxHeight: '100%', + maxWidth: '100%', + borderRadius: '5px', + }) - // previous and next buttons - const lightboxPrevBtn = document.createElement('button') - const lightboxNextBtn = document.createElement('button') + // previous and next buttons + const lightboxPrevBtn = document.createElement('button') + const lightboxNextBtn = document.createElement('button') - lightboxPrevBtn.textContent = '❮' - lightboxNextBtn.textContent = '❯' + lightboxPrevBtn.textContent = '❮' + lightboxNextBtn.textContent = '❯' - Object.assign(lightboxPrevBtn.style, styles.lightboxBtn({ left: '0%' })) - Object.assign(lightboxNextBtn.style, styles.lightboxBtn({ right: '0%' })) + Object.assign(lightboxPrevBtn.style, styles.lightboxBtn({ left: '0%' })) + Object.assign(lightboxNextBtn.style, styles.lightboxBtn({ right: '0%' })) - // close button - const lightboxCloseBtn = document.createElement('button') - Object.assign( - lightboxCloseBtn.style, - styles.lightboxBtn({ right: '0', top: '0' }), - ) - lightboxCloseBtn.textContent = '❌' + // close button + const lightboxCloseBtn = document.createElement('button') + Object.assign( + lightboxCloseBtn.style, + styles.lightboxBtn({ right: '0', top: '0' }), + ) + lightboxCloseBtn.textContent = '❌' - const lightboxButtons = document.createElement('div') - Object.assign(lightboxButtons.style, { - position: 'absolute', - top: '0%', - right: '0%', - // transform: "translate(50%, -50%)", - height: '100%', - width: '100%', - background: 'none', - border: 'none', - color: '#fff', - fontSize: '30px', - cursor: 'pointer', - pointerEvents: 'none', - }) + const lightboxButtons = document.createElement('div') + Object.assign(lightboxButtons.style, { + position: 'absolute', + top: '0%', + right: '0%', + // transform: "translate(50%, -50%)", + height: '100%', + width: '100%', + background: 'none', + border: 'none', + color: '#fff', + fontSize: '30px', + cursor: 'pointer', + pointerEvents: 'none', + }) - lightboxButtons.append(lightboxPrevBtn, lightboxNextBtn, lightboxCloseBtn) - lightboxContainer.append(lightboxButtons, lightboxImage) + lightboxButtons.append(lightboxPrevBtn, lightboxNextBtn, lightboxCloseBtn) + lightboxContainer.append(lightboxButtons, lightboxImage) - //- image list - const imageListContainer = document.createElement('div') - Object.assign(imageListContainer.style, styles.img_list) + //- image list + const imageListContainer = document.createElement('div') + Object.assign(imageListContainer.style, styles.img_list) - const createImgListBtn = (text, style) => { - const btn = document.createElement('button') - btn.type = 'button' - btn.textContent = text - Object.assign(btn.style, { - ...style, - border: 'none', - color: '#fff', - background: 'none', - height: '20px', - cursor: 'pointer', - position: 'absolute', - top: '5px', - fontSize: '12px', - lineHeight: '12px', - }) - imageListContainer.append(btn) - return btn - } - const showBtn = document.createElement('button') - const closeBtn = createImgListBtn('❌', { - width: '20px', - textIndent: '-4px', - right: '5px', - }) - const loadButton = createImgListBtn('Load Session History', { - right: '90px', - }) - const clearButton = createImgListBtn('Clear', { - right: '30px', - }) + const createImgListBtn = (text, style) => { + const btn = document.createElement('button') + btn.type = 'button' + btn.textContent = text + Object.assign(btn.style, { + ...style, + border: 'none', + color: '#fff', + background: 'none', + height: '20px', + cursor: 'pointer', + position: 'absolute', + top: '5px', + fontSize: '12px', + lineHeight: '12px', + }) + imageListContainer.append(btn) + return btn + } + const showBtn = document.createElement('button') + const closeBtn = createImgListBtn('❌', { + width: '20px', + textIndent: '-4px', + right: '5px', + }) + const loadButton = createImgListBtn('Load Session History', { + right: '90px', + }) + const clearButton = createImgListBtn('Clear', { + right: '30px', + }) - //- tools popup button - showBtn.classList.add('comfy-settings-btn') - Object.assign(showBtn.style, { - right: '16px', - cursor: 'pointer', - display: 'none', - }) + //- tools popup button + showBtn.classList.add('comfy-settings-btn') + Object.assign(showBtn.style, { + right: '16px', + cursor: 'pointer', + display: 'none', + }) - //- append to DOM - document.body.append(imageListContainer) + //- append to DOM + document.body.append(imageListContainer) - showBtn.textContent = '🖼' - showBtn.onclick = () => { - imageListContainer.style.display = 'block' - showBtn.style.display = 'none' - } - document.querySelector('.comfy-settings-btn').after(showBtn) - document.querySelector('.comfy-settings-btn').after(lightboxContainer) + showBtn.textContent = '🖼' + showBtn.onclick = () => { + imageListContainer.style.display = 'block' + showBtn.style.display = 'none' + } + document.querySelector('.comfy-settings-btn').after(showBtn) + document.querySelector('.comfy-settings-btn').after(lightboxContainer) - // for (const { output } of history) { - // if (output?.images) { - // for (const src of output.images) { - // const img = document.createElement("img"); - // const but = document.createElement("button"); + // for (const { output } of history) { + // if (output?.images) { + // for (const src of output.images) { + // const img = document.createElement("img"); + // const but = document.createElement("button"); - //- callbacks - closeBtn.onclick = () => { - imageListContainer.style.display = 'none' - showBtn.style.display = 'unset' - } + //- callbacks + closeBtn.onclick = () => { + imageListContainer.style.display = 'none' + showBtn.style.display = 'unset' + } - clearButton.onclick = () => { - imageListContainer.replaceChildren(closeBtn, clearButton, loadButton) - } + clearButton.onclick = () => { + imageListContainer.replaceChildren(closeBtn, clearButton, loadButton) + } - lightboxNextBtn.onclick = () => { - currentImageIndex = (currentImageIndex + 1) % imageUrls.length - const imageUrl = imageUrls[currentImageIndex] - lightboxImage.src = imageUrl - } + lightboxNextBtn.onclick = () => { + currentImageIndex = (currentImageIndex + 1) % imageUrls.length + const imageUrl = imageUrls[currentImageIndex] + lightboxImage.src = imageUrl + } - // Modify the lightboxPrevBtn onclick callback - lightboxPrevBtn.onclick = () => { - currentImageIndex = - (currentImageIndex - 1 + imageUrls.length) % imageUrls.length - const imageUrl = imageUrls[currentImageIndex] - lightboxImage.src = imageUrl - } + // Modify the lightboxPrevBtn onclick callback + lightboxPrevBtn.onclick = () => { + currentImageIndex = + (currentImageIndex - 1 + imageUrls.length) % imageUrls.length + const imageUrl = imageUrls[currentImageIndex] + lightboxImage.src = imageUrl + } - lightboxCloseBtn.onclick = () => { - lightboxContainer.style.display = 'none' - } - lightboxImage.onclick = lightboxNextBtn.onclick - /** - * This is the function that creates the image buttons for the image list - * They are wrapped in a button so that they can be clicked and open - * the image in the lightbox. - * @param {*} src - */ - const createImageBtn = (src) => { - console.debug(`making image ${src.filename}`) - const img = document.createElement('img') - const but = document.createElement('button') + lightboxCloseBtn.onclick = () => { + lightboxContainer.style.display = 'none' + } + lightboxImage.onclick = lightboxNextBtn.onclick + /** + * This is the function that creates the image buttons for the image list + * They are wrapped in a button so that they can be clicked and open + * the image in the lightbox. + * @param {*} src + */ + const createImageBtn = (src) => { + console.debug(`making image ${src.filename}`) + const img = document.createElement('img') + const but = document.createElement('button') - Object.assign(but.style, { - height: '120px', - width: '120px', - border: 'none', - padding: 0, - margin: 0, - }) - Object.assign(img.style, { - width: '100%', - height: '100%', - objectFit: 'cover', - }) + Object.assign(but.style, { + height: '120px', + width: '120px', + border: 'none', + padding: 0, + margin: 0, + }) + Object.assign(img.style, { + width: '100%', + height: '100%', + objectFit: 'cover', + }) - img.src = `/view?filename=${encodeURIComponent(src.filename)}&type=${ - src.type - }&subfolder=${encodeURIComponent(src.subfolder)}` + img.src = `/view?filename=${encodeURIComponent(src.filename)}&type=${ + src.type + }&subfolder=${encodeURIComponent(src.subfolder)}` - imageUrls.push(img.src) + imageUrls.push(img.src) - console.debug(img.src) + console.debug(img.src) - img.onload = () => { - but.style.width = `${120 * (img.naturalWidth / img.naturalHeight)}px` - } + img.onload = () => { + but.style.width = `${120 * (img.naturalWidth / img.naturalHeight)}px` + } - but.onclick = () => { - lightboxContainer.style.display = 'flex' - // add the same image to the lightbox - lightboxImage.src = img.src - // lighboxContainer.replaceChildren(lightboxButtons, img); - } + but.onclick = () => { + lightboxContainer.style.display = 'flex' + // add the same image to the lightbox + lightboxImage.src = img.src + // lighboxContainer.replaceChildren(lightboxButtons, img); + } - // add right click menu - but.addEventListener('contextmenu', (e) => { - e.preventDefault() + // add right click menu + but.addEventListener('contextmenu', (e) => { + e.preventDefault() - if (image_menu) { - image_menu.remove() - } + if (image_menu) { + image_menu.remove() + } - image_menu = document.createElement('div') - Object.assign(image_menu.style, { - position: 'absolute', - top: `${e.clientY}px`, - left: `${e.clientX}px`, - background: '#333', - color: '#fff', - padding: '5px', - borderRadius: '5px', - zIndex: 999, - }) - const load_img = document.createElement('button') - load_img.textContent = 'Load' - load_img.onclick = () => { - app.handleFile(img.src) - } + image_menu = document.createElement('div') + Object.assign(image_menu.style, { + position: 'absolute', + top: `${e.clientY}px`, + left: `${e.clientX}px`, + background: '#333', + color: '#fff', + padding: '5px', + borderRadius: '5px', + zIndex: 999, + }) + const load_img = document.createElement('button') + load_img.textContent = 'Load' + load_img.onclick = () => { + app.handleFile(img.src) + } - image_menu.appendChild(load_img) - document.body.appendChild(image_menu) - }) + image_menu.appendChild(load_img) + document.body.appendChild(image_menu) + }) - but.append(img) - imageListContainer.prepend(but) - } + but.append(img) + imageListContainer.prepend(but) + } - loadButton.onclick = async () => { - const all_history = await api.getHistory() - for (const history of all_history.History) { - if (history.outputs) { - for (const key of Object.keys(history.outputs)) { - console.debug(key) - if (history.outputs[key].images) { - for (const im of history.outputs[key].images) { - console.debug(im) - createImageBtn(im) - } - } - } - // for (const src of outputs.outputs.images) { - // console.debug(src) - // makeImage(`${src.subfolder}/${src.filename}`) - // } - } - } - } + loadButton.onclick = async () => { + const all_history = await api.getHistory() + for (const history of all_history.History) { + if (history.outputs) { + for (const key of Object.keys(history.outputs)) { + console.debug(key) + if (history.outputs[key].images) { + for (const im of history.outputs[key].images) { + console.debug(im) + createImageBtn(im) + } + } + } + // for (const src of outputs.outputs.images) { + // console.debug(src) + // makeImage(`${src.subfolder}/${src.filename}`) + // } + } + } + } - ///////------- + ///////------- - // const all_history = await api.getHistory() - // for (const history of all_history.History) { - // if (history.outputs) { - // for (const key of Object.keys(history.outputs)) { - // for (const im of history.outputs[key].images) { - // makeImage(im) - // } - // } - // // for (const src of outputs.outputs.images) { - // // console.debug(src) - // // makeImage(`${src.subfolder}/${src.filename}`) - // // } - // } - // } + // const all_history = await api.getHistory() + // for (const history of all_history.History) { + // if (history.outputs) { + // for (const key of Object.keys(history.outputs)) { + // for (const im of history.outputs[key].images) { + // makeImage(im) + // } + // } + // // for (const src of outputs.outputs.images) { + // // console.debug(src) + // // makeImage(`${src.subfolder}/${src.filename}`) + // // } + // } + // } - //- Hook into the API - api.addEventListener('executed', ({ detail }) => { - if (detail?.output?.images) { - for (const src of detail.output.images) { - console.debug(`Adding ${src} to image feed`) - createImageBtn(src) - } - } - }) - }, + //- Hook into the API + api.addEventListener('executed', ({ detail }) => { + if (detail?.output?.images) { + for (const src of detail.output.images) { + console.debug(`Adding ${src} to image feed`) + createImageBtn(src) + } + } + }) + }, }) diff --git a/web/notify.js b/web/notify.js index df30c5a..17aac3d 100644 --- a/web/notify.js +++ b/web/notify.js @@ -59,7 +59,7 @@ function notify(message, timeout = 3000) { log('Transition out') const totalHeight = Array.from(container.children).reduce( (acc, child) => acc + child.offsetHeight + 10, // Add spacing of 10px between toasts - 0 + 0, ) container.style.height = `${totalHeight}px` @@ -83,7 +83,7 @@ function notify(message, timeout = 3000) { // Update container's height to fit new toast const totalHeight = Array.from(container.children).reduce( (acc, child) => acc + child.offsetHeight + 10, // Add spacing of 10px between toasts - 0 + 0, ) container.style.height = `${totalHeight}px`