diff --git a/.prettierrc b/.prettierrc index e69de29..cce9d3c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "semi": false +} diff --git a/dialog_box.js b/dialog_box.js index 9385ff0..5d38ec1 100644 --- a/dialog_box.js +++ b/dialog_box.js @@ -11,44 +11,43 @@ async function prompt( "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)"; - }); + ].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"); + 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) => + ) + 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( @@ -73,4 +72,4 @@ async function prompt( // /* Do the delete */ // } -module.exports = { prompt }; +module.exports = { prompt } diff --git a/export_png.js b/export_png.js index f6b5070..1db811c 100644 --- a/export_png.js +++ b/export_png.js @@ -1,20 +1,20 @@ -const { executeAsModal } = require("photoshop").core; -const storage = require("uxp").storage; -const fs = storage.localFileSystem; -const formats = require("uxp").storage.formats; +const { executeAsModal } = require("photoshop").core +const storage = require("uxp").storage +const fs = storage.localFileSystem +const formats = require("uxp").storage.formats async function exportPngCommand() { - const batchPlay = require("photoshop").action.batchPlay; + 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 storage = require("uxp").storage + const fs = storage.localFileSystem - let pluginFolder = await fs.getPluginFolder(); + 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", @@ -26,20 +26,20 @@ async function exportPngCommand() { 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; + const { executeAsModal } = require("photoshop").core try { - await executeAsModal(exportPngCommand); + await executeAsModal(exportPngCommand) } catch (e) { - console.warn("exportPng error:", e); + console.warn("exportPng error:", e) } } @@ -49,39 +49,39 @@ const readPng = async (image_name) => { await executeAsModal( async (control) => { // const tempFolder = await fs.getTemporaryFolder() ; - const pluginFolder = await fs.getPluginFolder(); + 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' // ) const file = await init_images_dir.createFile(image_name, { overwrite: true, - }); + }) - const currentDocument = app.activeDocument; + 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); + 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 = @@ -97,24 +97,24 @@ async function newExportPng(layer, image_name) { //create new document let exportDoc = await executeAsModal(async () => { - return await app.documents.add; - }); + 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); + 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 readPng(image_name) // await exportDoc.closeWithoutSaving() - }); + }) // } } catch (e) { - console.warn(e); + console.warn(e) } } @@ -140,17 +140,17 @@ 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(); + 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"); + var saveFile = await saveFolder.createFile("fileName.png") const saveData = - await require("uxp").storage.localFileSystem.createSessionToken(saveFile); + await require("uxp").storage.localFileSystem.createSessionToken(saveFile) const result = await batchPlay( [ @@ -190,11 +190,11 @@ async function savePNG(saveDataTemp) { synchronousExecution: true, modalBehavior: "execute", } - ); + ) } await executeAsModal(async () => { - savePNGCommand(); - }); + savePNGCommand() + }) } ////////////////////End method 3//////////////////////////// @@ -204,4 +204,4 @@ module.exports = { readPng, savePNG, newExportPng, -}; +} diff --git a/helper.js b/helper.js index d884260..ce71e8b 100644 --- a/helper.js +++ b/helper.js @@ -1,28 +1,28 @@ -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; + 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 }); + 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( @@ -63,21 +63,21 @@ async function reselectBatchPlay(selectionInfo) { synchronousExecution: true, modalBehavior: "execute", } - ); + ) } async function reselect(selectionInfo) { await executeAsModal( async () => { - reselectBatchPlay(selectionInfo); + 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( [ @@ -102,9 +102,9 @@ async function unSelect() { synchronousExecution: true, modalBehavior: "execute", } - ); + ) - return result; + return result } // async function layerToSelectionHelper () { @@ -204,4 +204,4 @@ async function unSelect() { module.exports = { // layerToSelection -}; +} diff --git a/index.js b/index.js index 32fec8b..5487590 100644 --- a/index.js +++ b/index.js @@ -2,79 +2,79 @@ // 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(); + const isSelectionActive = await psapi.checkIfSelectionAreaIsActive() if (isSelectionActive) { - const current_selection = isSelectionActive; // Note: don't use checkIfSelectionAreaIsActive to return the selection object, change this. + 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; + return true } else { //selection has not changed - return false; + return false } } } catch (e) { - console.warn(e); - return false; + 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(); + 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(); + await selection.selectionToFinalWidthHeight() - html_manip.autoFillInWidth(width); - html_manip.autoFillInHeight(height); - html_manip.autoFillInHRWidth(hr_width); - html_manip.autoFillInHRHeight(hr_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 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) } } const eventHandler = async (event, descriptor) => { try { - console.log(event, descriptor); + console.log(event, descriptor) - const isSelectionActive = await psapi.checkIfSelectionAreaIsActive(); + const isSelectionActive = await psapi.checkIfSelectionAreaIsActive() if (isSelectionActive) { - const current_selection = isSelectionActive; // Note: don't use checkIfSelectionAreaIsActive to return the selection object, change this. + 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)) @@ -85,53 +85,53 @@ const eventHandler = async (event, descriptor) => { // 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); + 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(); + const current_mode = html_manip.getMode() if (g_generation_session.isSameMode(current_mode)) { // g_ui.startSessionUI() - g_ui.generateMoreUI(); + g_ui.generateMoreUI() } } } } catch (e) { - console.warn(e); + console.warn(e) } -}; +} require("photoshop").action.addNotificationListener( ["set", "move"], eventHandler -); +) async function getUniqueDocumentId() { try { - uniqueDocumentId = await psapi.readUniqueDocumentIdExe(); + 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; + /^[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); + 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; + 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); + console.warn("warning Document Id may not be valid", e) } - return uniqueDocumentId; + return uniqueDocumentId } // document @@ -147,36 +147,36 @@ Array.from(document.querySelectorAll(".sp-tab")).forEach((theTab) => { // 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"); + aTab.classList.add("selected") } else { - aTab.classList.remove("selected"); + 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"); + tabPage.classList.add("visible-hack") } else { - tabPage.classList.remove("visible-hack"); + tabPage.classList.remove("visible-hack") } } - ); + ) } catch (e) { - console.warn(e); + console.warn(e) } - }; -}); + } +}) document.getElementById("sp-viewer-tab").addEventListener("click", () => { - moveElementToAnotherTab("batchNumberUi", "batchNumberViewerTabContainer"); -}); + moveElementToAnotherTab("batchNumberUi", "batchNumberViewerTabContainer") +}) document .getElementById("sp-stable-diffusion-ui-tab") .addEventListener("click", () => { - moveElementToAnotherTab("batchNumberUi", "batchNumber-steps-container"); - }); + moveElementToAnotherTab("batchNumberUi", "batchNumber-steps-container") + }) // entrypoints.setup({ // panels:{ @@ -192,17 +192,17 @@ document // ) // 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 -const random_session_id = Math.floor(Math.random() * 1000000 + 1); +const random_session_id = Math.floor(Math.random() * 1000000 + 1) function getSelectedText() { // JavaScript // // Obtain the object reference for the