diff --git a/.prettierrc b/.prettierrc index cce9d3c..e74ed9f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,6 @@ { - "semi": false + "trailingComma": "es5", + "tabWidth": 4, + "semi": false, + "singleQuote": true } diff --git a/dialog_box.js b/dialog_box.js index 5d38ec1..1dc465f 100644 --- a/dialog_box.js +++ b/dialog_box.js @@ -1,53 +1,56 @@ async function prompt( - heading, - body, - buttons = ["Cancel", "Ok"], - options = { title: heading, size: { width: 360, height: 280 } } + 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)" - }) + 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()) + formEl.setAttribute('method', 'dialog') + formEl.addEventListener('submit', () => dlgEl.close()) - footerEl.style.marginTop = "26px" + footerEl.style.marginTop = '26px' - dividerEl.setAttribute("size", "large") + dividerEl.setAttribute('size', 'large') - headingEl.textContent = heading + headingEl.textContent = heading - bodyEl.textContent = body + bodyEl.textContent = body - buttons.forEach((btnText, idx) => { - const btnEl = document.createElement("sp-button") - btnEl.setAttribute( - "variant", - idx === buttons.length - 1 ? btnText.variant || "cta" : "secondary" + 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) ) - 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) + dlgEl.appendChild(formEl) + document.body.appendChild(dlgEl) - return dlgEl.uxpShowModal(options) + return dlgEl.uxpShowModal(options) } // const r1 = await prompt( diff --git a/export_png.js b/export_png.js index 1db811c..87393b7 100644 --- a/export_png.js +++ b/export_png.js @@ -1,121 +1,121 @@ -const { executeAsModal } = require("photoshop").core -const storage = require("uxp").storage +const { executeAsModal } = require('photoshop').core +const storage = require('uxp').storage const fs = storage.localFileSystem -const formats = require("uxp").storage.formats +const formats = require('uxp').storage.formats async function exportPngCommand() { - const batchPlay = require("photoshop").action.batchPlay - // const result = await batchPlay { _obj: “exportSelectionAsFileTypePressed”} + const batchPlay = require('photoshop').action.batchPlay + // const result = await batchPlay { _obj: “exportSelectionAsFileTypePressed”} - // const destFolder = (await storage.localFileSystem.getDataFolder()).nativePath; - const storage = require("uxp").storage - const fs = storage.localFileSystem + // const destFolder = (await storage.localFileSystem.getDataFolder()).nativePath; + const storage = require('uxp').storage + const fs = storage.localFileSystem - let pluginFolder = await fs.getPluginFolder() - // await fs.getFolder("./init_images") - let init_images_dir = await pluginFolder.getEntry( - "./server/python_server/init_images" - ) + let pluginFolder = await fs.getPluginFolder() + // await fs.getFolder("./init_images") + let init_images_dir = await pluginFolder.getEntry( + './server/python_server/init_images' + ) - const exportCommand = { - _obj: "exportSelectionAsFileTypePressed", - _target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" }, - fileType: "png", - quality: 32, - metadata: 0, - destFolder: init_images_dir.nativePath, - sRGB: true, - openWindow: false, - _options: { dialogOptions: "dontDisplay" }, - } - const result = await batchPlay([exportCommand], { - synchronousExecution: true, - modalBehavior: "execute", - }) + const exportCommand = { + _obj: 'exportSelectionAsFileTypePressed', + _target: { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' }, + fileType: 'png', + quality: 32, + metadata: 0, + destFolder: init_images_dir.nativePath, + sRGB: true, + openWindow: false, + _options: { dialogOptions: 'dontDisplay' }, + } + const result = await batchPlay([exportCommand], { + synchronousExecution: true, + modalBehavior: 'execute', + }) - return result + return result } async function exportPng() { - const { executeAsModal } = require("photoshop").core - try { - await executeAsModal(exportPngCommand) - } catch (e) { - console.warn("exportPng error:", e) - } + const { executeAsModal } = require('photoshop').core + try { + await executeAsModal(exportPngCommand) + } catch (e) { + console.warn('exportPng error:', e) + } } const readPng = async (image_name) => { - // image_name = 'test.png' - try { - await executeAsModal( - async (control) => { - // const tempFolder = await fs.getTemporaryFolder() ; - const pluginFolder = await fs.getPluginFolder() + // image_name = 'test.png' + try { + await executeAsModal( + async (control) => { + // const tempFolder = await fs.getTemporaryFolder() ; + const pluginFolder = await fs.getPluginFolder() - let init_images_dir = await pluginFolder.getEntry( - "./server/python_server/init_images" + let init_images_dir = await pluginFolder.getEntry( + './server/python_server/init_images' + ) + // let init_images_dir = await pluginFolder.getEntry( + // './server/python_server/init_images' + // ) + const file = await init_images_dir.createFile(image_name, { + overwrite: true, + }) + + const currentDocument = app.activeDocument + await currentDocument.saveAs.png( + file, + { + compression: 6, + }, + true + ) + + // const arrayBuffer = await file.read({format: formats.binary}) ; + // console.log(arrayBuffer, 'arrayBuffer') ; + }, + + { commandName: 'readPng' } ) - // let init_images_dir = await pluginFolder.getEntry( - // './server/python_server/init_images' - // ) - const file = await init_images_dir.createFile(image_name, { - overwrite: true, - }) - - const currentDocument = app.activeDocument - await currentDocument.saveAs.png( - file, - { - compression: 6, - }, - true - ) - - // const arrayBuffer = await file.read({format: formats.binary}) ; - // console.log(arrayBuffer, 'arrayBuffer') ; - }, - - { commandName: "readPng" } - ) - } catch (e) { - console.warn(e) - } + } catch (e) { + console.warn(e) + } } -const psapi = require("./psapi") +const psapi = require('./psapi') async function newExportPng(layer, image_name) { - //store layers we want to export in variables - // let layerToExports = - // create new document - // duplicate the layers to the new documnet - //select the layer channel selectLayerChannelCommand - //document.crop - //export using readPng() + //store layers we want to export in variables + // let layerToExports = + // create new document + // duplicate the layers to the new documnet + //select the layer channel selectLayerChannelCommand + //document.crop + //export using readPng() - try { - //get the active layers - // const layersToExport = app.activeDocument.activeLayers + try { + //get the active layers + // const layersToExport = app.activeDocument.activeLayers - //create new document - let exportDoc = await executeAsModal(async () => { - return await app.documents.add - }) + //create new document + let exportDoc = await executeAsModal(async () => { + return await app.documents.add + }) - // for (layer of layersToExport) { - await executeAsModal(async () => { - console.log(layer.id) - const dupLayer = await layer.duplicate(exportDoc) - await psapi.selectLayers([dupLayer]) - await psapi.selectLayerChannelCommand() - const selection_info = await psapi.getSelectionInfoExe() - await exportDoc.crop(selection_info) - // export_image_name = `${layer.name}.png` - await readPng(image_name) - // await exportDoc.closeWithoutSaving() - }) - // } - } catch (e) { - console.warn(e) - } + // for (layer of layersToExport) { + await executeAsModal(async () => { + console.log(layer.id) + const dupLayer = await layer.duplicate(exportDoc) + await psapi.selectLayers([dupLayer]) + await psapi.selectLayerChannelCommand() + const selection_info = await psapi.getSelectionInfoExe() + await exportDoc.crop(selection_info) + // export_image_name = `${layer.name}.png` + await readPng(image_name) + // await exportDoc.closeWithoutSaving() + }) + // } + } catch (e) { + console.warn(e) + } } ///////////////////////Start method 3/////////////////////// @@ -140,68 +140,70 @@ For the save function, if running UXP AP1 version 1 then use "wait" for modalBeh If running on UXP API version 2 then use "execute" for modalBahavior, or remove the options and use {} so the options go to default. */ async function savePNG(saveDataTemp) { - const batchPlay = require("photoshop").action.batchPlay + const batchPlay = require('photoshop').action.batchPlay - async function savePNGCommand() { - var saveFolder = - await require("uxp").storage.localFileSystem.getPluginFolder() + async function savePNGCommand() { + var saveFolder = + await require('uxp').storage.localFileSystem.getPluginFolder() - // Again, my variable here is global and assigned earlier. The value is changed during a batch loop for each file. - var saveFile = await saveFolder.createFile("fileName.png") + // Again, my variable here is global and assigned earlier. The value is changed during a batch loop for each file. + var saveFile = await saveFolder.createFile('fileName.png') - const saveData = - await require("uxp").storage.localFileSystem.createSessionToken(saveFile) + const saveData = + await require('uxp').storage.localFileSystem.createSessionToken( + saveFile + ) - const result = await batchPlay( - [ - { - _obj: "save", - as: { - _obj: "PNGFormat", - method: { - _enum: "PNGMethod", - _value: "quick", - }, - PNGInterlaceType: { - _enum: "PNGInterlaceType", - _value: "PNGInterlaceNone", - }, - PNGFilter: { - _enum: "PNGFilter", - _value: "PNGFilterAdaptive", - }, - compression: 6, - }, - in: { - _path: saveData, - _kind: "local", - }, - saveStage: { - _enum: "saveStageType", - _value: "saveBegin", - }, - _isCommand: false, - _options: { - dialogOptions: "dontDisplay", - }, - }, - ], - { - synchronousExecution: true, - modalBehavior: "execute", - } - ) - } - await executeAsModal(async () => { - savePNGCommand() - }) + const result = await batchPlay( + [ + { + _obj: 'save', + as: { + _obj: 'PNGFormat', + method: { + _enum: 'PNGMethod', + _value: 'quick', + }, + PNGInterlaceType: { + _enum: 'PNGInterlaceType', + _value: 'PNGInterlaceNone', + }, + PNGFilter: { + _enum: 'PNGFilter', + _value: 'PNGFilterAdaptive', + }, + compression: 6, + }, + in: { + _path: saveData, + _kind: 'local', + }, + saveStage: { + _enum: 'saveStageType', + _value: 'saveBegin', + }, + _isCommand: false, + _options: { + dialogOptions: 'dontDisplay', + }, + }, + ], + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) + } + await executeAsModal(async () => { + savePNGCommand() + }) } ////////////////////End method 3//////////////////////////// module.exports = { - exportPng, - readPng, - savePNG, - newExportPng, + exportPng, + readPng, + savePNG, + newExportPng, } diff --git a/helper.js b/helper.js index ce71e8b..f36b4e5 100644 --- a/helper.js +++ b/helper.js @@ -1,110 +1,110 @@ -const { unselectActiveLayers } = require("./psapi") +const { unselectActiveLayers } = require('./psapi') -const app = window.require("photoshop").app +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 }) - } + 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] + return activeLayers[0] } function getSize() { - let doc = app.activeDocument - return { height: doc.height, width: doc.width } + let doc = app.activeDocument + return { height: doc.height, width: doc.width } } -const { batchPlay } = require("photoshop").action -const { executeAsModal } = require("photoshop").core +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", - }, + 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', + }, + }, ], - 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", - } - ) + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) } async function reselect(selectionInfo) { - await executeAsModal( - async () => { - reselectBatchPlay(selectionInfo) - }, - { commandName: "reselect" } - ) + await executeAsModal( + async () => { + reselectBatchPlay(selectionInfo) + }, + { commandName: 'reselect' } + ) } //unselect the rectangular marquee selection area async function unSelect() { - const batchPlay = require("photoshop").action.batchPlay + const batchPlay = require('photoshop').action.batchPlay - const result = await batchPlay( - [ - { - _obj: "set", - _target: [ - { - _ref: "channel", - _property: "selection", - }, + const result = await batchPlay( + [ + { + _obj: 'set', + _target: [ + { + _ref: 'channel', + _property: 'selection', + }, + ], + to: { + _enum: 'ordinal', + _value: 'none', + }, + _options: { + dialogOptions: 'dontDisplay', + }, + }, ], - to: { - _enum: "ordinal", - _value: "none", - }, - _options: { - dialogOptions: "dontDisplay", - }, - }, - ], - { - synchronousExecution: true, - modalBehavior: "execute", - } - ) + { + synchronousExecution: true, + modalBehavior: 'execute', + } + ) - return result + return result } // async function layerToSelectionHelper () { @@ -203,5 +203,5 @@ async function unSelect() { // } module.exports = { - // layerToSelection + // layerToSelection } diff --git a/index.html b/index.html index 69df257..fdcdc18 100644 --- a/index.html +++ b/index.html @@ -1,1072 +1,1128 @@ - - - - - - - - - -
-
-
- Stable Diffusion UI -
-
Viewer
-
- History -
-
- Prompts library -
-
Horde
-
- Settings -
-
- A - P -
- v0.0.0 -
- -
-
- View your generated images on the canvas -
-
-
- - - - - - -
- + + +
+
+
+ Stable Diffusion UI +
+
+ Viewer +
+
+ History +
+
+ Prompts library +
+
+ Horde +
+
+ Settings +
+
+ A + P +
+ v0.0.0 +
+ +
+
+ View your generated images on the canvas +
+
+
+ + + + + + +
+ - - - - -
+ + + + +
-
-
- - - + + -
- - Progress... - -
+
+ + Progress... + +
- -
-
- -
-
-
- -
-
-
- -
-
- -
-
- history of all the images you generated -
- Seed:00000000000 -
-
-
-
- Search: - - - -
-
- -
-
- -
- Prompt Shortcut: a single word that represent a prompt -
- Key for new prompt shortcut - -
-
- Value for new prompt shortcut - - -
-
- -
-
- - - - - - -
-
- - -
-
-
- -
- Use Stable Diffusion Horde - -
- NSFW - Share with LION - -
-
- -
- -
- SD Url: -
- use sharp mask - Smart Object - Use Silent Import - - Use Colab -
- -
- - - - -
-
- - - -
- - - - -
- - - - - - - -
-
- -
-
- - Progress... - - prompt shortcut -
-
- - -
- - - -
-
- - - -
- - - -
- Edit Text -
- - -
-
- -
- - + +
+
+ +
+
+
+ +
+
+
+ +
-
- -
-
+
+
+ history of all the images you generated +
+ Seed:00000000000 +
+
+
+
+ Search: - - - txt2img - img2img - inpaint - outpaint - - - -
-
- - -
- - - - - - - - - - -
-
- - -
- + Image Search + + +
+
+ -
-
- -
-
-
-
-
- -
-
- -
-
-
-
-
-
-
-
-
-
- Images: + /> +
+
+ +
+ Prompt Shortcut: a single word that represent a + prompt +
+ Key for new prompt shortcut + +
+
+ Value for new prompt shortcut + + +
+
+
- Steps: + + + + + + +
+
+ +
-
-
-
-
- Selection Mode: +
+ +
+ Use Stable Diffusion Horde + +
+ NSFW + Share with LION + +
- - - - - - -
-
- - Width: - 512 - - - Height: - 512 - -
- + + + + + +
+ + + +
+
+ + + +
+ + + + +
+ + + + + + + +
+
+ +
+
+ + Progress... + + prompt shortcut +
+
+ + +
+ + + +
+
+ + + +
+ + + +
+ Edit Text +
+ + +
+
+ +
+ + +
+ +
+ +
+
+ + + + txt2img + img2img + inpaint + outpaint + + + +
+
+ + +
+ + + + + + + + + + +
+
+ + +
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+ Images: +
+
+ Steps: +
+
+
+
+
+
+ Selection Mode: +
+ + +
+ + Width: + 512 + + + Height: + 512 + +
+ -
- - CFG Scale: - - +
+ + CFG Scale: + + - - Denoising Strength: - 0.7 - -
+ + Denoising Strength: + 0.7 + +
- - Mask Blur: - - - - Mask Expansion: - - + + Mask Blur: + + + + Mask Expansion: + + -
- - Inpainting conditioning mask strength: - 1 - -
+
+ + Inpainting conditioning mask + strength: + 1 + +
-
- - Mask Content: - fill - original - latent noise - latent nothing - -
+
+ + Mask Content: + fill + original + latent noise + latent nothing + +
-
- Inpaint at Full Res - Restore Faces - Hi Res Fix -
- - - Inpaint Padding: - 0 - - + + +
+
+ Hi Res Steps: +
+
+
+ + Hi Res Output Width: + 512 + + + Hi Res Output Height: + 512 + + + + High Res Denoising Strength: + 0.58 + +
+
+ + Inpaint Padding: + 0 + + -
-
- -
- Seed: - - +
+
+ +
+ 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 + +
+
- - - 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 5487590..1f41319 100644 --- a/index.js +++ b/index.js @@ -2,136 +2,139 @@ // helloHelper2 = require('./helper.js') // for organizational proposes -const helper = require("./helper") -const sdapi = require("./sdapi") -const exportHelper = require("./export_png") -const outpaint = require("./outpaint") -const psapi = require("./psapi") -const app = window.require("photoshop").app +const helper = require('./helper') +const sdapi = require('./sdapi') +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 { 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 util_layer = 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 script_horde = require("./utility/sd_scripts/horde") +const html_manip = require('./utility/html_manip') +const export_png = require('./export_png') +const viewer = require('./viewer') +const selection = require('./selection') +const util_layer = 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 script_horde = require('./utility/sd_scripts/horde') 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. + 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_selection)) { - return true - } else { - //selection has not changed + if (await hasSelectionChanged(current_selection, g_selection)) { + return true + } else { + //selection has not changed + return false + } + } + } catch (e) { + console.warn(e) return false - } } - } catch (e) { - console.warn(e) - return false - } } 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() + //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) - } + 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) + } } const eventHandler = async (event, descriptor) => { - try { - console.log(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. + 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() + 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)) + // 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() + // const new_selection = await psapi.getSelectionInfoExe() - if (await hasSelectionChanged(current_selection, g_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() - g_ui.generateModeUI(selected_mode) - } else { - //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.isSameMode(current_mode)) { - // g_ui.startSessionUI() - g_ui.generateMoreUI() + if (await hasSelectionChanged(current_selection, g_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() + g_ui.generateModeUI(selected_mode) + } else { + //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.isSameMode(current_mode)) { + // g_ui.startSessionUI() + g_ui.generateMoreUI() + } + } } - } + } catch (e) { + console.warn(e) } - } catch (e) { - console.warn(e) - } } -require("photoshop").action.addNotificationListener( - ["set", "move"], - eventHandler +require('photoshop').action.addNotificationListener( + ['set', 'move'], + eventHandler ) async function getUniqueDocumentId() { - try { - uniqueDocumentId = await psapi.readUniqueDocumentIdExe() + try { + uniqueDocumentId = await psapi.readUniqueDocumentIdExe() - console.log("getUniqueDocumentId(): uniqueDocumentId: ", uniqueDocumentId) + 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 + // 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' + // 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 + 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 + } + } catch (e) { + console.warn('warning Document Id may not be valid', e) } - } catch (e) { - console.warn("warning Document Id may not be valid", e) - } - return uniqueDocumentId + return uniqueDocumentId } // document @@ -141,42 +144,44 @@ async function getUniqueDocumentId() { // }) // attach event listeners for tabs -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')).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) } - }) - 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) } - } }) -document.getElementById("sp-viewer-tab").addEventListener("click", () => { - moveElementToAnotherTab("batchNumberUi", "batchNumberViewerTabContainer") +document.getElementById('sp-viewer-tab').addEventListener('click', () => { + moveElementToAnotherTab('batchNumberUi', 'batchNumberViewerTabContainer') }) document - .getElementById("sp-stable-diffusion-ui-tab") - .addEventListener("click", () => { - moveElementToAnotherTab("batchNumberUi", "batchNumber-steps-container") - }) + .getElementById('sp-stable-diffusion-ui-tab') + .addEventListener('click', () => { + moveElementToAnotherTab('batchNumberUi', 'batchNumber-steps-container') + }) // entrypoints.setup({ // panels:{ @@ -195,37 +200,37 @@ document const random_session_id = Math.floor(Math.random() * 1000000 + 1) function getSelectedText() { - // JavaScript - // // Obtain the object reference for the