From 672dbda1cfddf1e0a18b8c2eb2afab1f70c71649 Mon Sep 17 00:00:00 2001 From: lein2023 <121925374+lein2023@users.noreply.github.com> Date: Tue, 23 May 2023 17:05:02 +0800 Subject: [PATCH] Modify the interface language to display as_ zh-CN Modify the interface language to display as_ zh-CN --- LICENSE.md | 42 +- README.md | 347 +- dialog_box.js | 156 +- enum.js | 114 +- helper.js | 240 +- index.html | 5886 +++++++++++++------------ index.js | 9496 ++++++++++++++++++++--------------------- install.py | 106 +- manifest.json | 10 +- outpaint.js | 1036 ++--- package.json | 62 +- psapi.js | 3196 +++++++------- requirements.txt | 50 +- sdapi_py_re.js | 1590 +++---- selection.js | 334 +- start_server_MacOS.sh | 34 +- thumbnail.js | 80 +- update_plugin.sh | 2 +- viewer.js | 1722 ++++---- 19 files changed, 12234 insertions(+), 12269 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 40defe74..0de47211 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2022 Abdullah Alfaraj - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2022 Abdullah Alfaraj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 01a96c9e..854bda11 100644 --- a/README.md +++ b/README.md @@ -1,188 +1,159 @@ - - -# Auto-Photoshop-StableDiffusion-Plugin -[![Become a Patron!](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/AbdullahAlfaraj) -[![discord badge]][discord link] - -[discord badge]: https://flat.badgen.net/discord/members/3mVEtrddXJ -[discord link]: https://discord.gg/3mVEtrddXJ - - - -With Auto-Photoshop-StableDiffusion-Plugin, you can directly use the capabilities of Automatic1111 Stable Diffusion in Photoshop without switching between programs. This allows you to easily use Stable Diffusion AI in a familiar environment. You can edit your Stable Diffusion image with all your favorite tools and save it right in Photoshop. - -# Table of Contents -- [Auto-Photoshop-StableDiffusion-Plugin](#auto-photoshop-stablediffusion-plugin) -- [Table of Contents](#table-of-contents) -- [Demo:](#demo) -- [Support Us On Patreon](#support-us-on-patreon) -- [How to Install](#how-to-install) - - [Method 1: One Click Installer](#method-1-one-click-installer) - - [Method 2: The Unzip Method](#method-2-the-unzip-method) - - [Method 3: The UXP Method (for Developers/Programmers Only)](#method-3-the-uxp-method-instruction-for-developers) - -- [FAQ and Known Issues](#faq-and-known-issues) - - [What Photoshop version do I need to run the plugin?](#what-photoshop-version-do-i-need-to-run-the-plugin) - - [Path Doesn't Exist](#path-doesnt-exist) - - [Plugin Load Failed](#plugin-load-failed) - - [No application are connected to the service](#no-application-are-connected-to-the-service) - - [Load command failed in App with ID PS and Version X.X.X](#load-command-failed-in-app-with-id-ps-and-version-xxx) - - [Exception in ASGI application / Expecting value: line 1 column 1](#exception-in-asgi-application--expecting-value-line-1-column-1) - - [No Generations and Plugin Server doesn't send messages. (Remote setup)](#no-generations-and-plugin-server-doesnt-send-messages-remote-setup) - -- [No GPU Options](#no-gpu-options) - - [Stable Horde](#stable-horde) - - [Colab](#colab) - -# Support Us On Patreon: -By supporting us on [Patreon](https://www.patreon.com/AbdullahAlfaraj), you’ll help us continue to develop and improve the Auto-Photoshop-StableDiffusion-Plugin, making it even easier for you to use Stable Diffusion AI in a familiar environment. As a supporter, you’ll have the opportunity to provide feedback and suggestions for future development. Plus, you’ll get early access to new features and tutorials, as well as exclusive art tutorials and tips from a professional artist. We’re passionate about making AI approachable to artists and with your help, we can continue to do just that. -# Auto-Photoshop-SD Backers and Sponsors: -**💎 Diamond:** -| [![Ronny Khalil](https://images.weserv.nl/?url=https://raw.githubusercontent.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/206b56c911f67ede3ca3a934d0bce8c1d68a2113/docs/profile_image/A934E4F0-7778-47E9-A395-531BFF2E61F1_1_105_c.jpeg&h=80&w=80&fit=cover&mask=circle&maxage=7d)](https://ronnykhalil.com/) | ![zachary](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=zachary) -|:---:|:---:| -| [Ronny Khalil](https://ronnykhalil.com/) | zachary - -**🥇 Gold:** -| ![Alex ](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Alex+) -|:---:| -| Alex - -**🥈 Silver:** -| ![Amith Thomas](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Amith+Thomas) | ![Olivier Lefebvre](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Olivier+Lefebvre) | ![xiao yuan](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=xiao+yuan) | ![Ezra Blake](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Ezra+Blake) -|:---:|:---:|:---:|:---:| -| Amith Thomas | Olivier Lefebvre | xiao yuan | Ezra Blake - -**🥉 Copper:** -| ![Sebastian Karbowniczek](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Sebastian+Karbowniczek) | ![Arthur Liu](https://ui-avatars.com/api/?background=random&color=fff&rounded=true&name=Arthur+Liu) -|:---:|:---:| -| Sebastian Karbowniczek | Arthur Liu - - - - - - - - -# How To Install: -Use method 1 or 2 if you are an Artist -use method 3 if you are a Developer/Programmer - - -# Method 1: One Click Installer - -1) Download the [.ccx](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/releases/latest) file -2) run the ccx file . that's all. you will be able to use all of stable diffusion modes (txt2img, img2img, inpainting and outpainting), check the [tutorials](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/wiki) section to master the tool. - -![install_plugin_1](https://user-images.githubusercontent.com/7842232/217213943-3e2a588d-3ed8-4757-ba69-9846b55a1b36.gif) - - -3) (optional step) Install the Auto-Photoshop-SD Extension from Automatic1111. the extension will allow you to use the smart masking and image search features - - a) Copy Auto-Photoshop plugin url -![copy_githup_url_2](https://user-images.githubusercontent.com/7842232/217213998-367873ce-2c09-4c42-a5fa-0044415e3908.gif) - -- b) Paste the url in auto1111's extension tab and click install - -![install_extension_3](https://user-images.githubusercontent.com/7842232/217214062-4c2fef9e-8d49-46a0-aa3b-80c4975f8a70.gif) - -- c) Make sure the Auto-Photoshop plugin is listed, then click "Apply and Restart UI" - -![apply_and_restart_4](https://user-images.githubusercontent.com/7842232/217214116-2e30d7b8-aeb6-44df-aff3-4788a56cd800.gif) - - - -# Method 2: The Unzip Method -1) Download the [.zip](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/releases/latest) file -2) Unzip it in a folder with the same name -3) move the unzipped folder to the Photoshop Plugin folder -4) (optional step) Install the Auto-Photoshop-SD Extension from Automatic1111. the extension will allow you to use the smart masking and image search features -![image](https://user-images.githubusercontent.com/7842232/223751539-1a3013aa-aa1d-4058-87ae-e8b3fdfc5ec8.png) - - - -# Method 3: The UXP method (Instruction for Developers): -For artists we recommend you use [the one click installer](#one-click-installer). If you are a developer Watch the any of these videos or follow the instruction bellow. - - - - - -For artists we recommend you use [the one click installer](#one-click-installer) -## First time running the plugin (local Automatic1111): -1) download the plugin: -``` -git clone https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin.git -``` -2) run "start_server.bat" inside "Auto-Photoshop-StableDiffusion-Plugin" directory -3) go to where you have [automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) installed. -Edit the "webui-user.bat" in automatic1111 - change this line -``` -set COMMANDLINE_ARGS= -``` -to -``` -set COMMANDLINE_ARGS= --api -``` -that will allow the plugin to communicate with the automatic1111 project. After saving close the "webui-user.bat" file and run it normally. - -4) run photoshop. go to edit -> prefrences -> plugins - 1) make sure you check "Enable Developer Mode" checkbox -5) install "Adobe UXP Developer Tool" from here [Installation (adobe.com)](https://developer.adobe.com/photoshop/uxp/devtool/installation/) - this tool will add the plugin into photoshop -6) run Adobe UXP Developer Tool and click on "Add Plugin" button in the top right. Navigate to where you have "Auto-Photoshop-StableDiffusion-Plugin" folder and open "manifest.json" -7) select the plugin and click on Actions -> Load Selected -that's it. - -## First time running the plugin (remote Automatic1111): -__The remote webui must also have `--api` set in `COMMANDLINE_ARGS`. You can check if api access is enabled by appending "/docs#" to the end of the url. If the documentation includes `/sdapi/v1/samplers` then api access is enabled.__ - -1) download the plugin: -``` -git clone https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin.git -``` -1) edit [start_server.bat](start_server.bat) (or start_server.sh if on linux) to point to the remote installation of Automatic1111 -2) run "start_server.bat" inside "Auto-Photoshop-StableDiffusion-Plugin" directory -3) run photoshop. go to edit -> prefrences -> plugins - 1) make sure you check "Enable Developer Mode" checkbox -4) install "Adobe UXP Developer Tool" from here [Installation (adobe.com)](https://developer.adobe.com/photoshop/uxp/devtool/installation/) - this tool will add the plugin into photoshop -5) run Adobe UXP Developer Tool and click on "Add Plugin" button in the top right. Navigate to where you have "Auto-Photoshop-StableDiffusion-Plugin" folder and open "manifest.json" -6) select the plugin and click on Actions -> Load Selected -that's it. - - - - - - -# Demo: -[![Click Here to Watch Demo](https://i3.ytimg.com/vi/VL_gbQai79E/maxresdefault.jpg)](https://youtu.be/VL_gbQai79E "Stable diffusion AI Photoshop Plugin Free and Open Source") - - -# FAQ and Known Issues -## What Photoshop version do I need to run the plugin? -The minimum Photoshop version that the plugin supports is Photoshop v24 - -## Plugin Load Failed -There are a few issues that can result in this error, please follow the instructions for the corresponding error message in the UDT logs - -### No application are connected to the service -This error occurs when Photoshop is not started before the plugin is attempted to be loaded. Simply start photoshop then restart UXP and load the plugin - - -## Exception in ASGI application / Expecting value: line 1 column 1 -This error occurs due to mismatched expectations between the plugin and the Automatic1111 backend. -It can be solved by both updating the version of the Automatic111 backend to the latest verion, and making sure "Save text information about generation parameters as chunks to png files" setting is enabled within the UI. - -## No Generations and Plugin Server doesn't send messages. (Remote setup) -This error occurs when the remote server does not have the api enabled. You can verify this by attempting to go to the URL you access the webui at and appending "/docs#" to the end of the url. If you have permissions, make relaunch the remote instance with the "--api" flag. - -# No GPU Options: -we provide two options to use the auto-photoshp plugin without GPU. -## Stable Horde -This is an awesome free crowdsourced distributed cluster of Stable Diffusion workers. If you like this service, consider joining the horde yourself! -the horde is enabled completely by the generosity of volunteers so make sure you don't overwhelm the service and help join the cause if you can. -read more on their [github page](https://github.com/db0/AI-Horde) -## Colab: -we link to this [Colab](https://colab.research.google.com/drive/1nbcx_WOneRmYv9idBO33pN5CbxXrqZHu?usp=sharing#scrollTo=Y4ebYsPqTrGb) directly inside plugin find it in the settings tab. you only need to run it. no need to change any of the settings. copy the gradio.live url the colab will generate and paste it into ```sd url``` field in the settings tab. + + +# Auto-Photoshop-StableDiffusion-Plugin +[![Become a Patron!](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/AbdullahAlfaraj) +[![discord badge]][discord link] + +[discord badge]: https://flat.badgen.net/discord/members/3mVEtrddXJ +[discord link]: https://discord.gg/3mVEtrddXJ + + + +With Auto-Photoshop-StableDiffusion-Plugin, you can directly use the capabilities of Automatic1111 Stable Diffusion in Photoshop without switching between programs. This allows you to easily use Stable Diffusion AI in a familiar environment. You can edit your Stable Diffusion image with all your favorite tools and save it right in Photoshop. + +# Table of Contents +- [Auto-Photoshop-StableDiffusion-Plugin](#auto-photoshop-stablediffusion-plugin) +- [Table of Contents](#table-of-contents) +- [Demo:](#demo) +- [Support Us On Patreon](#support-us-on-patreon) +- [How to Install](#how-to-install) + - [Method 1: One Click Installer](#method-1-one-click-installer) + - [Method 2: The Unzip Method](#method-2-the-unzip-method) + - [Method 3: The UXP Method (for Developers/Programmers Only)](#method-3-the-uxp-method-instruction-for-developers) + +- [FAQ and Known Issues](#faq-and-known-issues) + - [What Photoshop version do I need to run the plugin?](#what-photoshop-version-do-i-need-to-run-the-plugin) + - [Path Doesn't Exist](#path-doesnt-exist) + - [Plugin Load Failed](#plugin-load-failed) + - [No application are connected to the service](#no-application-are-connected-to-the-service) + - [Load command failed in App with ID PS and Version X.X.X](#load-command-failed-in-app-with-id-ps-and-version-xxx) + - [Exception in ASGI application / Expecting value: line 1 column 1](#exception-in-asgi-application--expecting-value-line-1-column-1) + - [No Generations and Plugin Server doesn't send messages. (Remote setup)](#no-generations-and-plugin-server-doesnt-send-messages-remote-setup) + +- [No GPU Options](#no-gpu-options) + - [Stable Horde](#stable-horde) + - [Colab](#colab) + +# Support Us On Patreon: +By supporting us on [Patreon](https://www.patreon.com/AbdullahAlfaraj), you’ll help us continue to develop and improve the Auto-Photoshop-StableDiffusion-Plugin, making it even easier for you to use Stable Diffusion AI in a familiar environment. As a supporter, you’ll have the opportunity to provide feedback and suggestions for future development. Plus, you’ll get early access to new features and tutorials, as well as exclusive art tutorials and tips from a professional artist. We’re passionate about making AI approachable to artists and with your help, we can continue to do just that. +# How To Install: +Use method 1 or 2 if you are an Artist +use method 3 if you are a Developer/Programmer + + +# Method 1: One Click Installer + +1) Download the [.ccx](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/releases/latest) file +2) run the ccx file . that's all. you will be able to use all of stable diffusion modes (txt2img, img2img, inpainting and outpainting), check the [tutorials](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/wiki) section to master the tool. + +![install_plugin_1](https://user-images.githubusercontent.com/7842232/217213943-3e2a588d-3ed8-4757-ba69-9846b55a1b36.gif) + + +3) (optional step) Install the Auto-Photoshop-SD Extension from Automatic1111. the extension will allow you to use the smart masking and image search features + - a) Copy Auto-Photoshop plugin url +![copy_githup_url_2](https://user-images.githubusercontent.com/7842232/217213998-367873ce-2c09-4c42-a5fa-0044415e3908.gif) + +- b) Paste the url in auto1111's extension tab and click install + +![install_extension_3](https://user-images.githubusercontent.com/7842232/217214062-4c2fef9e-8d49-46a0-aa3b-80c4975f8a70.gif) + +- c) Make sure the Auto-Photoshop plugin is listed, then click "Apply and Restart UI" + +![apply_and_restart_4](https://user-images.githubusercontent.com/7842232/217214116-2e30d7b8-aeb6-44df-aff3-4788a56cd800.gif) + + + +# Method 2: The Unzip Method +1) Download the [.zip](https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/releases/latest) file +2) Unzip it in a folder with the same name +3) move the unzipped folder to the Photoshop Plugin folder +4) (optional step) Install the Auto-Photoshop-SD Extension from Automatic1111. the extension will allow you to use the smart masking and image search features +![image](https://user-images.githubusercontent.com/7842232/223751539-1a3013aa-aa1d-4058-87ae-e8b3fdfc5ec8.png) + + + +# Method 3: The UXP method (Instruction for Developers): +For artists we recommend you use [the one click installer](#one-click-installer). If you are a developer Watch the any of these videos or follow the instruction bellow. + + + + + +For artists we recommend you use [the one click installer](#one-click-installer) +## First time running the plugin (local Automatic1111): +1) download the plugin: +``` +git clone https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin.git +``` +2) run "start_server.bat" inside "Auto-Photoshop-StableDiffusion-Plugin" directory +3) go to where you have [automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) installed. +Edit the "webui-user.bat" in automatic1111 + change this line +``` +set COMMANDLINE_ARGS= +``` +to +``` +set COMMANDLINE_ARGS= --api +``` +that will allow the plugin to communicate with the automatic1111 project. After saving close the "webui-user.bat" file and run it normally. + +4) run photoshop. go to edit -> prefrences -> plugins + 1) make sure you check "Enable Developer Mode" checkbox +5) install "Adobe UXP Developer Tool" from here [Installation (adobe.com)](https://developer.adobe.com/photoshop/uxp/devtool/installation/) + this tool will add the plugin into photoshop +6) run Adobe UXP Developer Tool and click on "Add Plugin" button in the top right. Navigate to where you have "Auto-Photoshop-StableDiffusion-Plugin" folder and open "manifest.json" +7) select the plugin and click on Actions -> Load Selected +that's it. + +## First time running the plugin (remote Automatic1111): +__The remote webui must also have `--api` set in `COMMANDLINE_ARGS`. You can check if api access is enabled by appending "/docs#" to the end of the url. If the documentation includes `/sdapi/v1/samplers` then api access is enabled.__ + +1) download the plugin: +``` +git clone https://github.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin.git +``` +1) edit [start_server.bat](start_server.bat) (or start_server.sh if on linux) to point to the remote installation of Automatic1111 +2) run "start_server.bat" inside "Auto-Photoshop-StableDiffusion-Plugin" directory +3) run photoshop. go to edit -> prefrences -> plugins + 1) make sure you check "Enable Developer Mode" checkbox +4) install "Adobe UXP Developer Tool" from here [Installation (adobe.com)](https://developer.adobe.com/photoshop/uxp/devtool/installation/) + this tool will add the plugin into photoshop +5) run Adobe UXP Developer Tool and click on "Add Plugin" button in the top right. Navigate to where you have "Auto-Photoshop-StableDiffusion-Plugin" folder and open "manifest.json" +6) select the plugin and click on Actions -> Load Selected +that's it. + + + + + + +# Demo: +[![Click Here to Watch Demo](https://i3.ytimg.com/vi/VL_gbQai79E/maxresdefault.jpg)](https://youtu.be/VL_gbQai79E "Stable diffusion AI Photoshop Plugin Free and Open Source") + +# FAQ and Known Issues +## What Photoshop version do I need to run the plugin? +The minimum Photoshop version that the plugin supports is Photoshop v24 + +## Plugin Load Failed +There are a few issues that can result in this error, please follow the instructions for the corresponding error message in the UDT logs + +### No application are connected to the service +This error occurs when Photoshop is not started before the plugin is attempted to be loaded. Simply start photoshop then restart UXP and load the plugin + + +## Exception in ASGI application / Expecting value: line 1 column 1 +This error occurs due to mismatched expectations between the plugin and the Automatic1111 backend. +It can be solved by both updating the version of the Automatic111 backend to the latest verion, and making sure "Save text information about generation parameters as chunks to png files" setting is enabled within the UI. + +## No Generations and Plugin Server doesn't send messages. (Remote setup) +This error occurs when the remote server does not have the api enabled. You can verify this by attempting to go to the URL you access the webui at and appending "/docs#" to the end of the url. If you have permissions, make relaunch the remote instance with the "--api" flag. + +# No GPU Options: +we provide two options to use the auto-photoshp plugin without GPU. +## Stable Horde +This is an awesome free crowdsourced distributed cluster of Stable Diffusion workers. If you like this service, consider joining the horde yourself! +the horde is enabled completely by the generosity of volunteers so make sure you don't overwhelm the service and help join the cause if you can. +read more on their [github page](https://github.com/db0/AI-Horde) +## Colab: +we link to this [Colab](https://colab.research.google.com/drive/1nbcx_WOneRmYv9idBO33pN5CbxXrqZHu?usp=sharing#scrollTo=Y4ebYsPqTrGb) directly inside plugin find it in the settings tab. you only need to run it. no need to change any of the settings. copy the gradio.live url the colab will generate and paste it into ```sd url``` field in the settings tab. diff --git a/dialog_box.js b/dialog_box.js index 1dc465fb..329db6f0 100644 --- a/dialog_box.js +++ b/dialog_box.js @@ -1,78 +1,78 @@ -async function prompt( - heading, - body, - buttons = ['Cancel', 'Ok'], - options = { title: heading, size: { width: 360, height: 280 } } -) { - const [dlgEl, formEl, headingEl, dividerEl, bodyEl, footerEl] = [ - 'dialog', - 'form', - 'sp-heading', - 'sp-divider', - 'sp-body', - 'footer', - ].map((tag) => document.createElement(tag)) - ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => { - el.style.margin = '6px' - el.style.width = 'calc(100% - 12px)' - }) - - formEl.setAttribute('method', 'dialog') - formEl.addEventListener('submit', () => dlgEl.close()) - - footerEl.style.marginTop = '26px' - - dividerEl.setAttribute('size', 'large') - - headingEl.textContent = heading - - bodyEl.textContent = body - - buttons.forEach((btnText, idx) => { - const btnEl = document.createElement('sp-button') - btnEl.setAttribute( - 'variant', - idx === buttons.length - 1 ? btnText.variant || 'cta' : 'secondary' - ) - if (idx === buttons.length - 1) - btnEl.setAttribute('autofocus', 'autofocus') - if (idx < buttons.length - 1) btnEl.setAttribute('quiet') - btnEl.textContent = btnText.text || btnText - btnEl.style.marginLeft = '12px' - btnEl.addEventListener('click', () => - dlgEl.close(btnText.text || btnText) - ) - footerEl.appendChild(btnEl) - }) - ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => - formEl.appendChild(el) - ) - dlgEl.appendChild(formEl) - document.body.appendChild(dlgEl) - - return dlgEl.uxpShowModal(options) -} - -// const r1 = await prompt( -// 'Upload Large File', -// 'This is a large file (over 100MB) -- it may take a few moments to upload.', -// ['Skip', 'Upload'] -// ) -// if ((r1 || 'Upload') !== 'Upload') { -// /* cancelled or No */ -// } else { -// /* Yes */ -// } - -// const r2 = await prompt( -// 'Delete File', -// 'Are you sure you wish to delete this file? This action cannot be undone.', -// ['Cancel', { variant: 'warning', text: 'Delete' }] -// ) -// if (r2 !== 'Delete') { -// /* nope, don't do it! */ -// } else { -// /* Do the delete */ -// } - -module.exports = { prompt } +async function prompt( + heading, + body, + buttons = ['Cancel', 'Ok'], + options = { title: heading, size: { width: 360, height: 280 } } +) { + const [dlgEl, formEl, headingEl, dividerEl, bodyEl, footerEl] = [ + 'dialog', + 'form', + 'sp-heading', + 'sp-divider', + 'sp-body', + 'footer', + ].map((tag) => document.createElement(tag)) + ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => { + el.style.margin = '6px' + el.style.width = 'calc(100% - 12px)' + }) + + formEl.setAttribute('method', 'dialog') + formEl.addEventListener('submit', () => dlgEl.close()) + + footerEl.style.marginTop = '26px' + + dividerEl.setAttribute('size', 'large') + + headingEl.textContent = heading + + bodyEl.textContent = body + + buttons.forEach((btnText, idx) => { + const btnEl = document.createElement('sp-button') + btnEl.setAttribute( + 'variant', + idx === buttons.length - 1 ? btnText.variant || 'cta' : 'secondary' + ) + if (idx === buttons.length - 1) + btnEl.setAttribute('autofocus', 'autofocus') + if (idx < buttons.length - 1) btnEl.setAttribute('quiet') + btnEl.textContent = btnText.text || btnText + btnEl.style.marginLeft = '12px' + btnEl.addEventListener('click', () => + dlgEl.close(btnText.text || btnText) + ) + footerEl.appendChild(btnEl) + }) + ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => + formEl.appendChild(el) + ) + dlgEl.appendChild(formEl) + document.body.appendChild(dlgEl) + + return dlgEl.uxpShowModal(options) +} + +// const r1 = await prompt( +// 'Upload Large File', +// 'This is a large file (over 100MB) -- it may take a few moments to upload.', +// ['Skip', 'Upload'] +// ) +// if ((r1 || 'Upload') !== 'Upload') { +// /* cancelled or No */ +// } else { +// /* Yes */ +// } + +// const r2 = await prompt( +// 'Delete File', +// 'Are you sure you wish to delete this file? This action cannot be undone.', +// ['Cancel', { variant: 'warning', text: 'Delete' }] +// ) +// if (r2 !== 'Delete') { +// /* nope, don't do it! */ +// } else { +// /* Do the delete */ +// } + +module.exports = { prompt } diff --git a/enum.js b/enum.js index 1cf996a2..17f04907 100644 --- a/enum.js +++ b/enum.js @@ -1,57 +1,57 @@ -const clickTypeEnum = { - Click: 'click', - ShiftClick: 'shift_click', - AltClick: 'alt_click', - SecondClick: 'second_click', //when we click a thumbnail that is active/ has orange border -} -const generationModeEnum = { - Txt2Img: 'txt2img', - Img2Img: 'img2img', - Inpaint: 'inpaint', - Outpaint: 'outpaint', - Upscale: 'upscale', -} - -const AutomaticStatusEnum = { - NoApi: 'no_api', - Offline: 'offline', - RunningNoApi: 'running_no_api', - RunningWithApi: 'running_with_api', -} - -const ViewerObjectTypeEnum = { - OutputImage: 'output_image', - InitImage: 'init_image', - MaskImage: 'mask_image', -} - -const RequestStateEnum = { - Generating: 'generating', // in the generation process - Interrupted: 'interrupted', // canceled/ interrupted - Finished: 'finished', // finished generating -} -const DocumentTypeEnum = { - NoBackground: 'no_background', - ImageBackground: 'image_background', - SolidBackground: 'solid_background', - ArtBoard: 'artboard', -} -const BackgroundHistoryEnum = { - CorrectBackground: 'correct_background', - NoBackground: 'no_background', -} - -const PresetTypeEnum = { - SDPreset: 'sd_preset', - ControlNetPreset: 'controlnet_preset', -} -module.exports = { - clickTypeEnum, - generationModeEnum, - AutomaticStatusEnum, - ViewerObjectTypeEnum, - RequestStateEnum, - DocumentTypeEnum, - BackgroundHistoryEnum, - PresetTypeEnum, -} +const clickTypeEnum = { + Click: 'click', + ShiftClick: 'shift_click', + AltClick: 'alt_click', + SecondClick: 'second_click', //when we click a thumbnail that is active/ has orange border +} +const generationModeEnum = { + Txt2Img: 'txt2img', + Img2Img: 'img2img', + Inpaint: 'inpaint', + Outpaint: 'outpaint', + Upscale: 'upscale', +} + +const AutomaticStatusEnum = { + NoApi: 'no_api', + Offline: 'offline', + RunningNoApi: 'running_no_api', + RunningWithApi: 'running_with_api', +} + +const ViewerObjectTypeEnum = { + OutputImage: 'output_image', + InitImage: 'init_image', + MaskImage: 'mask_image', +} + +const RequestStateEnum = { + Generating: 'generating', // in the generation process + Interrupted: 'interrupted', // canceled/ interrupted + Finished: 'finished', // finished generating +} +const DocumentTypeEnum = { + NoBackground: 'no_background', + ImageBackground: 'image_background', + SolidBackground: 'solid_background', + ArtBoard: 'artboard', +} +const BackgroundHistoryEnum = { + CorrectBackground: 'correct_background', + NoBackground: 'no_background', +} + +const PresetTypeEnum = { + SDPreset: 'sd_preset', + ControlNetPreset: 'controlnet_preset', +} +module.exports = { + clickTypeEnum, + generationModeEnum, + AutomaticStatusEnum, + ViewerObjectTypeEnum, + RequestStateEnum, + DocumentTypeEnum, + BackgroundHistoryEnum, + PresetTypeEnum, +} diff --git a/helper.js b/helper.js index 58993d84..2fc5f2f3 100644 --- a/helper.js +++ b/helper.js @@ -1,120 +1,120 @@ -const { unselectActiveLayers } = require('./psapi') - -const app = window.require('photoshop').app - -function getActiveLayer() { - let activeLayers = app.activeDocument.activeLayers - // console.dir(getSize()) - for (const layer of activeLayers) { - console.dir({ layer }) - const name = layer.name - console.dir({ name }) - let layer_size = getLayerSize(layer) - console.dir({ layer_size }) - } - - return activeLayers[0] -} - -function getSize() { - let doc = app.activeDocument - return { height: doc.height, width: doc.width } -} - -const { batchPlay } = require('photoshop').action -const { executeAsModal } = require('photoshop').core - -async function reselectBatchPlay(selectionInfo) { - const result = await batchPlay( - [ - { - _obj: 'set', - _target: [ - { - _ref: 'channel', - _property: 'selection', - }, - ], - to: { - _obj: 'rectangle', - top: { - _unit: 'pixelsUnit', - _value: selectionInfo.top, - }, - left: { - _unit: 'pixelsUnit', - _value: selectionInfo.left, - }, - bottom: { - _unit: 'pixelsUnit', - _value: selectionInfo.bottom, - }, - right: { - _unit: 'pixelsUnit', - _value: selectionInfo.right, - }, - }, - _options: { - dialogOptions: 'dontDisplay', - }, - }, - ], - { - synchronousExecution: true, - modalBehavior: 'execute', - } - ) -} - -async function reselect(selectionInfo) { - await executeAsModal( - async () => { - reselectBatchPlay(selectionInfo) - }, - { commandName: 'reselect' } - ) -} - -//unselect the rectangular marquee selection area -async function unSelect() { - const batchPlay = require('photoshop').action.batchPlay - - const result = await batchPlay( - [ - { - _obj: 'set', - _target: [ - { - _ref: 'channel', - _property: 'selection', - }, - ], - to: { - _enum: 'ordinal', - _value: 'none', - }, - _options: { - dialogOptions: 'dontDisplay', - }, - }, - ], - { - synchronousExecution: true, - modalBehavior: 'execute', - } - ) - - return result -} - -/** - * Convert 1d index to 2d array - * @param {number} index sequential index - * @param {number} width width of 2d array - * @returns {number[]} [x,y] - */ -function indexToXY(index, width) { - return [index % width, Math.floor(index / width)] -} - -module.exports = {} +const { unselectActiveLayers } = require('./psapi') + +const app = window.require('photoshop').app + +function getActiveLayer() { + let activeLayers = app.activeDocument.activeLayers + // console.dir(getSize()) + for (const layer of activeLayers) { + console.dir({ layer }) + const name = layer.name + console.dir({ name }) + let layer_size = getLayerSize(layer) + console.dir({ layer_size }) + } + + return activeLayers[0] +} + +function getSize() { + let doc = app.activeDocument + return { height: doc.height, width: doc.width } +} + +const { batchPlay } = require('photoshop').action +const { executeAsModal } = require('photoshop').core + +async function reselectBatchPlay(selectionInfo) { + const result = await batchPlay( + [ + { + _obj: 'set', + _target: [ + { + _ref: 'channel', + _property: 'selection', + }, + ], + to: { + _obj: 'rectangle', + top: { + _unit: 'pixelsUnit', + _value: selectionInfo.top, + }, + left: { + _unit: 'pixelsUnit', + _value: selectionInfo.left, + }, + bottom: { + _unit: 'pixelsUnit', + _value: selectionInfo.bottom, + }, + right: { + _unit: 'pixelsUnit', + _value: selectionInfo.right, + }, + }, + _options: { + dialogOptions: 'dontDisplay', + }, + }, + ], + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) +} + +async function reselect(selectionInfo) { + await executeAsModal( + async () => { + reselectBatchPlay(selectionInfo) + }, + { commandName: 'reselect' } + ) +} + +//unselect the rectangular marquee selection area +async function unSelect() { + const batchPlay = require('photoshop').action.batchPlay + + const result = await batchPlay( + [ + { + _obj: 'set', + _target: [ + { + _ref: 'channel', + _property: 'selection', + }, + ], + to: { + _enum: 'ordinal', + _value: 'none', + }, + _options: { + dialogOptions: 'dontDisplay', + }, + }, + ], + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) + + return result +} + +/** + * Convert 1d index to 2d array + * @param {number} index sequential index + * @param {number} width width of 2d array + * @returns {number[]} [x,y] + */ +function indexToXY(index, width) { + return [index % width, Math.floor(index / width)] +} + +module.exports = {} diff --git a/index.html b/index.html index a3a60f7c..51ac8d49 100644 --- a/index.html +++ b/index.html @@ -1,2945 +1,2941 @@ - - - - - - - - - - - - -
-
-
- Stable Diffusion -
-
- Viewer -
-
- ControlNet -
- - - - - -
- Horde -
-
- Extras -
- -
- Settings -
-
- A - P -
- v0.0.0 -
- -
-
-
-
    - -
- -
- -
-
-
- View your generated images on the canvas -
-
-
- - - - - -
- - - - - -
- -
-
- - - -
- - Progress... - - -
- - -
-
- - Thumbnail Size: - - Square 1:1 -
-
- -
- - - -
- -
- - -
- -
- - -
- -
-
- -
-
- - - - - - -
- -
- - -
- -
- Disable ControlNet Tab -
- - -
-
-
-
- -
- history of all the images you generated -
- Seed:00000000000 -
-
-
-
- - -
-
- -
-
-
-
- -
- Explore Lexica for prompts and inspiration -
-
-
- Search: - - - - -
- - -
- -
-
- -
-
- -
- Image Search Engine -
-
-
- Search: - - -
-
- -
-
-
-
- Prompt Shortcut: a single word that represent a - prompt -
- Key for new prompt shortcut - -
-
- Value for new prompt shortcut - - -
-
- -
-
- - - - - - -
-
- - -
-
-
- -
-
- Horde Key: - -
- - - Select Backend: - - Native Horde - Auto1111 Horde Extension - Auto1111 Only - - - - -
- NSFW - Share with LION - -
-
-
-
- - - Resize - 2 - -
-
- - -
- - - - -
-
- -
- No work in progress -
-
- Upscaler 1: - - - - - - -
- Upscaler 2: - - - - - - -
-
- - - Upscaler 2 visibility: - - 0 - -
-
- - - GFPGAN visibility: - - 0 - -
-
- - - CodeFormer visibility: - - 0 - -
-
- - - CodeFormer weight: - - 0 - -
-
-
- -
-
- -
- - Preset Type: - - SD Preset - ControlNet Preset - -
- - - - -
- - - - - -
-
- -
-
- -
-
-
-
- -
- - Settings - Custom Presets - -
-
- SD Url: - -
- use sharp mask - Smart Object - Live Progress Image - - Restore Original Prompt - Image Cfg Scale Slider - - - - Your PC Speed(optimization): - - Slow PC - Fast PC - - - - - Use Colab -
- - Select Extension: - - Proxy Server - Auto111 Extension - None - - -
-
- - Folder Path (read only): - - -
-
- -
- - - - -
- - - - - - - - - - - - -
- -
-
-
- - Progress... - - -
-
- - - - - - - -
- -
-
- - -
- - - -
-
- - - -
- - - -
- Edit Text -
- -
- - - - - - -
-
- - -
- - - -
- -
- -
- - - - - -
-
- - -
- - - - - - - - - - -
-
-
- - -
- -
- - -
- -
- -
-
- - - - txt2img - img2img - inpaint - outpaint - - - -
-
- - -
- - - - - - - - - - -
-
- - -
- -
-
- -
-
-
-
-
- -
-
- -
-
-
-
-
-
-
-
-
-
- Batch Size: -
-
- Batch Count: -
-
- Steps: -
-
-
-
-
-
- Selection Mode: -
- - -
- - Width: - 512 - - - - Height: - 512 - - - - -
- -
- - CFG Scale: - - - - - Denoising Strength: - 0.7 - -
- - - - Mask Blur: - - - - Mask Expansion: - - - -
- - Inpainting conditioning mask - strength: - 1 - -
- -
- - Mask Content: - fill - original - latent noise - latent nothing - -
- -
- Inpaint at Full Res - Restore Faces - Hi Res Fix -
- - - Inpaint Padding: - 0 - - -
-
- -
- Seed: - - -
- - - Select Sampler: - Euler a - Euler - LMS - Heun - DPM2 - DPM2 a - DPM++ 2S a - DPM++ 2M - DPM++ SDE - DPM fast - DPM adaptive - LMS Karras - DPM2 Karras - DPM2 a Karras - DPM++ 2S a Karras - DPM++ 2M Karras - DPM++ SDE Karras - -
-
-
-
- - + + + + + + + + + + + + +
+
+
+ 稳定扩散 +
+
+ 查看 +
+
+ ControlNet +
+ + + + + +
+ Horde +
+
+ 扩展 +
+ +
+ 设置 +
+
+ fox:汉化版 + 2228232003 +
+ v0.0.0 +
+ +
+
+
+
    + +
+ +
+ +
+
+
+ 查看画布上生成的图像 +
+
+
+ + + + + +
+ + + + + +
+ +
+
+ + + +
+ + 进度... + + +
+ + +
+
+ + 缩略图尺寸: + + 正方形 1:1 +
+
+ +
+ + + +
+ +
+ + +
+ +
+ + +
+ +
+
+ +
+
+ + + + + + +
+ +
+ + +
+ +
+ 禁用 ControlNet 选项 +
+ + +
+
+
+
+ +
+ 生成图像的所有历史记录 +
+ 种子:00000000000 +
+
+
+
+ + +
+
+ +
+
+
+
+ +
+ 浏览词库以获取提示和灵感 +
+
+
+ 搜索: + + + + +
+ + +
+ +
+
+ +
+
+ +
+ 图像搜索引擎 +
+
+
+ 搜索: + + +
+
+ +
+
+
+
+ 提示快捷方式: 代表提示的单个单词 +
+ 新建快捷提示词 + +
+
+ 翻译问题:这里的快捷方式可以理解为类似【快捷标签|便签】 + + +
+
+ +
+
+ + + + + + +
+
+ + +
+
+
+ +
+
+ Horde Key: + +
+ + + (Select Backend) 选择后端: + + Native Horde + Auto1111 Horde Extension + Auto1111 Only + + + + +
+ (NSFW) R18+ + (Share with LION) 分享到 LION + +
+
+
+
+ + + 调整大小: + 2 + +
+
+ + +
+ + + + +
+
+ +
+ No work in progress +
+
+ Upscaler 1: + + + + + + +
+ Upscaler 2: + + + + + + +
+
+ + + Upscaler 2 强度: + + 0 + +
+
+ + + GFPGAN 强度: + + 0 + +
+
+ + + CodeFormer 可见度: + + 0 + +
+
+ + + CodeFormer 权重: + + 0 + +
+
+
+ +
+
+ +
+ + Preset Type: + + SD Preset + ControlNet Preset + +
+ + + + +
+ + + + + +
+
+ +
+
+ +
+
+
+
+ +
+ + 设置 + 自定义预设 + +
+
+ SD Url: + +
+ 使用锐化遮罩 + 智能对象 + 实时进度图像 + + 恢复原始提示 + 图像配置缩放滑块 + + + + 对电脑性能(优化): + + 低配 PC + 高配 PC + + + + + 使用 Colab +
+ + 选择扩展: + + 代理 server + Auto111 Extension + + + +
+
+ + 文件夹路径 (只读): + + +
+
+ +
+ + + + +
+ + + + + + + + + + + + +
+ +
+
+
+ + 进度... + + +
+
+ + + + + + + +
+ +
+
+ + +
+ + + +
+
+ + + +
+ + + +
+ Edit Text +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ +
+ +
+ + + + + +
+
+ + +
+ + + + + + + + + + +
+
+
+ + +
+ +
+ + +
+ +
+ +
+
+ + + + 文生图 + 图生图 + 修复 + 填充 + + + +
+
+ + +
+ + + + + + + + + + +
+
+ + +
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+ 总批次数: +
+
+ 单批数量: +
+
+ 迭代步数: +
+
+
+
+
+
+ 选择模式: +
+ + +
+ + 宽度: + 512 + + + + 高度: + 512 + + + + +
+ +
+ + 提示词引导系数: + + + + + 重绘幅度: + 0.7 + +
+ + + + 蒙版模糊: + + + + 蒙版扩张: + + + +
+ + 修复蒙版权重: + 1 + +
+ +
+ + 蒙版内容: + 填充 + 原始 + 隐藏噪点 + 隐藏缺失 + +
+ +
+ 在完整分辨率下修复 + 面部修复 + 高分辨率修复 +
+ + + Inpaint Padding: + 0 + + +
+
+ +
+ 随机种子: + + +
+ + + Select Sampler: + Euler a + Euler + LMS + Heun + DPM2 + DPM2 a + DPM++ 2S a + DPM++ 2M + DPM++ SDE + DPM fast + DPM adaptive + LMS Karras + DPM2 Karras + DPM2 a Karras + DPM++ 2S a Karras + DPM++ 2M Karras + DPM++ SDE Karras + +
+
+
+
+ + diff --git a/index.js b/index.js index c1879866..106c1b1c 100644 --- a/index.js +++ b/index.js @@ -1,4748 +1,4748 @@ -const io = require('./utility/io') -const log = console.log -const warn = console.warn -const error = console.error -const should_log = false -if (should_log) { - window.addEventListener('error', (event) => { - const [a, b, c, d, e] = [1, 2, 3, 4, 5] - console.log(`message: ${a}`) - console.log(`source: ${b}`) - console.log(`lineno: ${c}`) - console.log(`colno: ${d}`) - console.log(`error: ${e}`) - }) - - console.log = (data, ...optional_param) => { - log(data, ...optional_param) - io.IOLog.saveLogToFile({ data, ...optional_param }, 'log.txt') - } - console.warn = (data, ...optional_param) => { - try { - warn(data, ...optional_param) - io.IOLog.saveLogToFile({ data, ...optional_param }, 'warn.txt') - } catch (e) { - warn('error while logging: ') - warn(e) - } - } - console.error = (data, ...optional_param) => { - error(data, ...optional_param) - io.IOLog.saveLogToFile({ data, ...optional_param }, 'error.txt') - } -} - -// import {helloHelper} from 'helper.js' -// helloHelper2 = require('./helper.js') -// for organizational proposes -// let g_sdapi_path = 'sdapi' -let g_version = 'v1.2.4' -let g_sd_url = 'http://127.0.0.1:7860' -let g_online_data_url = - 'https://raw.githubusercontent.com/AbdullahAlfaraj/Auto-Photoshop-StableDiffusion-Plugin/master/utility/online_data.json' -const Enum = require('./enum') -const helper = require('./helper') -const sd_tab = require('./utility/tab/sd') -// let g_sdapi_path = 'sdapi_py_re' -// const sdapi = require(`./${g_sdapi_path}`) -const sdapi = require('./sdapi_py_re') - -// const exportHelper = require('./export_png') -const outpaint = require('./outpaint') -const psapi = require('./psapi') -const app = window.require('photoshop').app - -const { batchPlay } = require('photoshop').action -const { executeAsModal } = require('photoshop').core -const dialog_box = require('./dialog_box') -// const {entrypoints} = require('uxp') -const html_manip = require('./utility/html_manip') -// const export_png = require('./export_png') -const viewer = require('./viewer') -const selection = require('./selection') -const layer_util = require('./utility/layer') -const sd_options = require('./utility/sdapi/options') -const sd_config = require('./utility/sdapi/config') -const session = require('./utility/session') -const ui = require('./utility/ui') -const preset_util = require('./utility/presets/preset') -const script_horde = require('./utility/sd_scripts/horde') -const prompt_shortcut = require('./utility/sdapi/prompt_shortcut') -const formats = require('uxp').storage.formats -const storage = require('uxp').storage -const shell = require('uxp').shell -const fs = storage.localFileSystem -const horde_native = require('./utility/sdapi/horde_native') - -const dummy = require('./utility/dummy') -const general = require('./utility/general') -const thumbnail = require('./thumbnail') -const note = require('./utility/notification') -const sampler_data = require('./utility/sampler') -const settings_tab = require('./utility/tab/settings') -const control_net = require('./utility/tab/control_net') -//load tabs -const history_tab = require('./utility/tab/history_tab') -const image_search_tab = require('./utility/tab/image_search_tab') -const lexica_tab = require('./utility/tab/lexica_tab') -const share_tab = require('./utility/tab/share_tab') -let g_horde_generator = new horde_native.hordeGenerator() -let g_automatic_status = Enum.AutomaticStatusEnum['Offline'] -let g_models_status = false -let g_current_batch_index = 0 -//REFACTOR: move to session.js -async function hasSessionSelectionChanged() { - try { - const isSelectionActive = await psapi.checkIfSelectionAreaIsActive() - if (isSelectionActive) { - const current_selection = isSelectionActive // Note: don't use checkIfSelectionAreaIsActive to return the selection object, change this. - - if ( - await hasSelectionChanged( - current_selection, - g_generation_session.selectionInfo - ) - ) { - return true - } else { - //selection has not changed - return false - } - } - } catch (e) { - console.warn(e) - return false - } -} -//REFACTOR: move to selection.js, add selection mode as attribute (linked to rbSelectionMode event) -async function calcWidthHeightFromSelection() { - //set the width and height, hrWidth, and hrHeight using selection info and selection mode - const selection_mode = html_manip.getSelectionMode() - if (selection_mode === 'ratio') { - //change (width and height) and (hrWidth, hrHeight) to match the ratio of selection - const [width, height, hr_width, hr_height] = - await selection.selectionToFinalWidthHeight() - - html_manip.autoFillInWidth(width) - html_manip.autoFillInHeight(height) - html_manip.autoFillInHRWidth(hr_width) - html_manip.autoFillInHRHeight(hr_height) - } else if (selection_mode === 'precise') { - const selectionInfo = await psapi.getSelectionInfoExe() - const [width, height, hr_width, hr_height] = [ - selectionInfo.width, - selectionInfo.height, - 0, - 0, - ] - html_manip.autoFillInWidth(width) - html_manip.autoFillInHeight(height) - } -} -//REFACTOR: rename to newSelectionEventHandler and move to session.js -const eventHandler = async (event, descriptor) => { - try { - console.log(event, descriptor) - - const isSelectionActive = await psapi.checkIfSelectionAreaIsActive() - if (isSelectionActive) { - const current_selection = isSelectionActive // Note: don't use checkIfSelectionAreaIsActive to return the selection object, change this. - - await calcWidthHeightFromSelection() - - // console.log(` (${final_width}* ${final_height})/(${current_selection.width} * ${current_selection.height})`) - // console.log("detail density: ",(final_width* final_height)/(current_selection.width * current_selection.height)) - - // const new_selection = await psapi.getSelectionInfoExe() - - if ( - await hasSelectionChanged( - current_selection, - g_generation_session.selectionInfo - ) //new selection - ) { - // endSessionUI //red color - // if selection has changed : change the color and text generate btn "Generate" color "red" - // g_ui.endSessionUI() - // const selected_mode = html_manip.getMode() - const selected_mode = getCurrentGenerationModeByValue(g_sd_mode) - g_ui.generateModeUI(selected_mode) - } else { - // it's the same selection and the session is active - - //indicate that the session will continue. only if the session we are in the same mode as the session's mode - // startSessionUI// green color - const current_mode = html_manip.getMode() - if ( - g_generation_session.isActive() && // the session is active - g_generation_session.isSameMode(current_mode) //same mode - ) { - // g_ui.startSessionUI() - g_ui.generateMoreUI() - } - } - } - } catch (e) { - console.warn(e) - } -} -//REFACTOR: move to generation_settings.js -function getCurrentGenerationModeByValue(value) { - for (let key in generationMode) { - if ( - generationMode.hasOwnProperty(key) && - generationMode[key] === value - ) { - return key - } - } - return undefined -} - -require('photoshop').action.addNotificationListener( - ['set', 'move'], - eventHandler -) -//REFACTOR: move to document.js -async function getUniqueDocumentId() { - console.warn( - 'getUniqueDocumentId is deprecated, instead use the methods in IOFolder' - ) - try { - let uniqueDocumentId = await psapi.readUniqueDocumentIdExe() - - console.log( - 'getUniqueDocumentId(): uniqueDocumentId: ', - uniqueDocumentId - ) - - // Regular expression to check if string is a valid UUID - const regexExp = - /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi - - // String with valid UUID separated by dash - // const str = 'a24a6ea4-ce75-4665-a070-57453082c256' - - const isValidId = regexExp.test(uniqueDocumentId) // true - console.log('isValidId: ', isValidId) - if (isValidId == false) { - let uuid = self.crypto.randomUUID() - console.log(uuid) // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f" - await psapi.saveUniqueDocumentIdExe(uuid) - uniqueDocumentId = uuid - } - return uniqueDocumentId - } catch (e) { - console.warn('warning Document Id may not be valid', e) - } -} - -// document -// .getElementById('btnLinkCurrentDocument') -// .addEventListener('click', async () => { -// await getUniqueDocumentId() -// }) - -// attach event listeners for tabs -//REFACTOR: move to html_manip.js (?) - if there is no business logic here and it's only for UI. -Array.from(document.querySelectorAll('.sp-tab')).forEach((theTab) => { - theTab.onclick = () => { - try { - // localStorage.setItem("currentTab", theTab.getAttribute("id")); - Array.from(document.querySelectorAll('.sp-tab')).forEach((aTab) => { - if (aTab.getAttribute('id') === theTab.getAttribute('id')) { - aTab.classList.add('selected') - } else { - aTab.classList.remove('selected') - } - }) - Array.from(document.querySelectorAll('.sp-tab-page')).forEach( - (tabPage) => { - if ( - tabPage - .getAttribute('id') - .startsWith(theTab.getAttribute('id')) - ) { - tabPage.classList.add('visible-hack') - } else { - tabPage.classList.remove('visible-hack') - } - } - ) - } catch (e) { - console.warn(e) - } - } -}) -//REFACTOR: move to events.js -document.getElementById('sp-viewer-tab').addEventListener('click', async () => { - if ( - g_generation_session.isActive() && - g_generation_session.mode === 'upscale' - ) { - g_sd_mode = 'upscale' - } else { - g_sd_mode = html_manip.getMode() - } -}) -//REFACTOR: move to events.js -document.getElementById('sp-viewer-tab').addEventListener('click', async () => { - moveElementToAnotherTab('batchNumberUi', 'batchNumberViewerTabContainer') - await displayUpdate() -}) -//REFACTOR: move to events.js -document - .getElementById('sp-stable-diffusion-ui-tab') - .addEventListener('click', () => { - moveElementToAnotherTab('batchNumberUi', 'batchNumber-steps-container') - }) -// entrypoints.setup({ - -// panels:{ -// vanilla: ()=>{ -// console.log("you are in the vanilla panel") -// }, -// experimental_1: ()=>{ -// console.log("you are in the experimental_1 panel") - -// } -// } -// } -// ) -// just a number that shouldn't unique enough that we will use when save files. -// each session will get a number from 1 to 1000000 -//REFACTOR: move to session.js -const random_session_id = Math.floor(Math.random() * 1000000 + 1) -//REFACTOR: move to helpers.js (or other utility file) -function getSelectedText() { - // JavaScript - // // Obtain the object reference for the