// import {helloHelper} from 'helper.js' // helloHelper2 = require('./helper.js') // for organizational proposes // let g_sdapi_path = 'sdapi' const g_image_not_found_url = 'https://images.unsplash.com/source-404?fit=crop&fm=jpg&h=800&q=60&w=1200' const _log = console.log const _warn = console.warn const _error = console.error let g_timer_value = 300 // temporary global variable for testing the timer pause function let g_version = 'v1.3.2' 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 Jimp = require('./jimp/browser/lib/jimp.min') const Enum = require('./enum') const helper = require('./helper') const sdapi = require('./sdapi_py_re') // const exportHelper = require('./export_png') const psapi = require('./psapi') const app = window.require('photoshop').app const constants = require('photoshop').constants const { batchPlay } = require('photoshop').action const { executeAsModal } = require('photoshop').core // const dialog_box = require('./dialog_box') // const {entrypoints} = require('uxp') const { sd_tab_store } = require('./typescripts/dist/bundle') const html_manip = require('./utility/html_manip') // const export_png = require('./export_png') 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 { getSettings } = require('./utility/session') 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 settings_tab = require('./utility/tab/settings') //load tabs const image_search_tab = require('./utility/tab/image_search_tab') // const share_tab = require('./utility/tab/share_tab') const api = require('./utility/api') const { scripts, main, after_detailer_script, control_net, logger, toJS, viewer, preview, // session_ts, session_store, progress, sd_tab_ts, // sd_tab_store, sam, settings_tab_ts, one_button_prompt, enum_ts, multiPrompts, ui_ts, preset, preset_util, dialog_box, sd_tab_util, node_fs, io_ts, extra_page, selection_ts, stores, lexica, api_ts, } = require('./typescripts/dist/bundle') const io = require('./utility/io') function setLogMethod(should_log_to_file = true) { let timer_id if (should_log_to_file) { console.log = (data, ...optional_param) => { try { _log(data, ...optional_param) // const error = new Error({ data, ...optional_param }); const formattedOutput = logger.formateLog( data, ...optional_param ) io.IOLog.saveLogToFile({ log: formattedOutput }, 'log.txt') } catch (e) { _warn('error while logging: ') _warn(e) } } console.warn = (data, ...optional_param) => { try { _warn(data, ...optional_param) const error = new Error() const stackTrace = error.stack const formattedOutput = logger.formateLog( data, ...optional_param ) io.IOLog.saveLogToFile( { warning: formattedOutput, stackTrace }, 'log.txt' ) } catch (e) { _warn('error while logging: ') _warn(e) } } console.error = (data, ...optional_param) => { try { _error(data, ...optional_param) const error = new Error() const stackTrace = error.stack const formattedOutput = logger.formateLog( data, ...optional_param ) io.IOLog.saveLogToFile( { error: formattedOutput, stackTrace }, 'log.txt' ) } catch (e) { _error('error while logging: ') _error(e) } } } else { console.log = _log console.warn = _warn console.error = _error } } setLogMethod(settings_tab_ts.store.data.should_log_to_file) // const { // script_args, // script_name, // } = require('./ultimate_sd_upscaler/dist/ultimate_sd_upscaler') let g_horde_generator = new horde_native.hordeGenerator() let g_automatic_status = Enum.AutomaticStatusEnum['Offline'] let g_current_batch_index = 0 let g_is_laso_inapint_mode = true //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 } } async function calcWidthHeightFromSelection(selectionInfo) { //set the width and height, hrWidth, and hrHeight using selection info and selection mode const selection_mode = sd_tab_store.data.selection_mode if (selection_mode === 'ratio') { //change (width and height) and (hrWidth, hrHeight) to match the ratio of selection const base_size = sd_tab_util.helper_store.data.base_size const [width, height, hr_width, hr_height] = await selection.selectionToFinalWidthHeight( selectionInfo, base_size, base_size ) // console.log('width,height: ', width, 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 [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 new_selection_info = await psapi.getSelectionInfoExe() session_store.updateProperty( 'current_selection_info', new_selection_info ) // const isSelectionActive = await psapi.checkIfSelectionAreaIsActive() if (new_selection_info) { await calcWidthHeightFromSelection(new_selection_info) } } 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', 'addTo', 'subtractFrom'], 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) } } // 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) } } }) // 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