remove sim from formatting
parent
d3e26771b8
commit
4c04a8ae6e
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"semi": false
|
||||
}
|
||||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
40
helper.js
40
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
|
||||
};
|
||||
}
|
||||
|
|
|
|||
462
outpaint.js
462
outpaint.js
|
|
@ -1,7 +1,7 @@
|
|||
const app = window.require("photoshop").app;
|
||||
const app = window.require("photoshop").app
|
||||
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const psapi = require("./psapi");
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
const psapi = require("./psapi")
|
||||
|
||||
// async function moveToGroupCommand (to_index, layerIDs) {
|
||||
// const batchPlay = require('photoshop').action.batchPlay
|
||||
|
|
@ -39,27 +39,27 @@ const psapi = require("./psapi");
|
|||
// }
|
||||
|
||||
async function moveLayersToGroup(group_id) {
|
||||
const activeLayers = await app.activeDocument.activeLayers;
|
||||
const layerIDs = activeLayers.map((layer) => layer.id);
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const activeLayers = await app.activeDocument.activeLayers
|
||||
const layerIDs = activeLayers.map((layer) => layer.id)
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
await executeAsModal(async () => {
|
||||
await psapi.moveToGroupCommand(group_id, layerIDs);
|
||||
});
|
||||
await psapi.moveToGroupCommand(group_id, layerIDs)
|
||||
})
|
||||
}
|
||||
|
||||
async function createSnapshot() {
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
//get all layers,
|
||||
//duplicate the layers
|
||||
//create a group
|
||||
//move the duplicate layers to the group
|
||||
let snapshotLayer, snapshotGroup;
|
||||
let snapshotLayer, snapshotGroup
|
||||
try {
|
||||
const selectionInfo = await psapi.getSelectionInfoExe();
|
||||
await psapi.unSelectMarqueeExe();
|
||||
const selectionInfo = await psapi.getSelectionInfoExe()
|
||||
await psapi.unSelectMarqueeExe()
|
||||
|
||||
//get all layers
|
||||
const allLayers = await app.activeDocument.layers;
|
||||
const allLayers = await app.activeDocument.layers
|
||||
|
||||
// const allLayerNames = allLayers.map(
|
||||
// layer => `${layer.name} (${layer.opacity} %)`
|
||||
|
|
@ -68,69 +68,69 @@ async function createSnapshot() {
|
|||
// console.log(layer)
|
||||
// }
|
||||
//duplicate the layers
|
||||
let duplicatedLayers = [];
|
||||
let duplicatedLayers = []
|
||||
|
||||
// const group_id = await createGroup()
|
||||
const groupLayer = await psapi.createEmptyGroup();
|
||||
const groupLayer = await psapi.createEmptyGroup()
|
||||
|
||||
console.log("createSnapshot(), group_id:", groupLayer.id);
|
||||
console.log("createSnapshot(), group_id:", groupLayer.id)
|
||||
// let bHasBackground = false
|
||||
let indexOffset = 0;
|
||||
let indexOffset = 0
|
||||
|
||||
const result1 = await executeAsModal(async () => {
|
||||
for (layer of allLayers) {
|
||||
if (layer.id == 1) {
|
||||
//skip the background layer
|
||||
// bHasBackground = true
|
||||
indexOffset = 1;
|
||||
continue;
|
||||
indexOffset = 1
|
||||
continue
|
||||
}
|
||||
if (layer.visible) {
|
||||
const copyLayer = await layer.duplicate();
|
||||
duplicatedLayers.push(copyLayer);
|
||||
const copyLayer = await layer.duplicate()
|
||||
duplicatedLayers.push(copyLayer)
|
||||
}
|
||||
}
|
||||
|
||||
const layerIDs = duplicatedLayers.map((layer) => layer.id);
|
||||
console.log("createSnapshot, layerIDs:", layerIDs);
|
||||
const layerIDs = duplicatedLayers.map((layer) => layer.id)
|
||||
console.log("createSnapshot, layerIDs:", layerIDs)
|
||||
|
||||
//select the layer since layerIDs don't seem to have an affect on moveToGroupCommand(), don't know why!!!!
|
||||
psapi.selectLayers(duplicatedLayers);
|
||||
let group_index = await psapi.getLayerIndex(groupLayer.id);
|
||||
psapi.selectLayers(duplicatedLayers)
|
||||
let group_index = await psapi.getLayerIndex(groupLayer.id)
|
||||
|
||||
await psapi.moveToGroupCommand(group_index - indexOffset, layerIDs);
|
||||
await psapi.moveToGroupCommand(group_index - indexOffset, layerIDs)
|
||||
|
||||
await psapi.collapseGroup(duplicatedLayers[0]);
|
||||
snapshotLayer = app.activeDocument.activeLayers[0];
|
||||
await psapi.createSolidLayer(255, 255, 255);
|
||||
const whiteSolidLayer = app.activeDocument.activeLayers[0];
|
||||
await snapshotLayer.moveAbove(whiteSolidLayer);
|
||||
snapshotGroup = await psapi.createEmptyGroup();
|
||||
let snapshot_group_index = await psapi.getLayerIndex(snapshotGroup.id);
|
||||
await psapi.collapseGroup(duplicatedLayers[0])
|
||||
snapshotLayer = app.activeDocument.activeLayers[0]
|
||||
await psapi.createSolidLayer(255, 255, 255)
|
||||
const whiteSolidLayer = app.activeDocument.activeLayers[0]
|
||||
await snapshotLayer.moveAbove(whiteSolidLayer)
|
||||
snapshotGroup = await psapi.createEmptyGroup()
|
||||
let snapshot_group_index = await psapi.getLayerIndex(snapshotGroup.id)
|
||||
|
||||
await psapi.selectLayers([snapshotLayer, whiteSolidLayer]);
|
||||
await psapi.moveToGroupCommand(snapshot_group_index - indexOffset, []);
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createMaskExe();
|
||||
await psapi.selectLayers([snapshotLayer, whiteSolidLayer])
|
||||
await psapi.moveToGroupCommand(snapshot_group_index - indexOffset, [])
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createMaskExe()
|
||||
// await psapi.selectLayerChannelCommand()
|
||||
// await psapi.createSolidLayer(0, 0, 0)
|
||||
});
|
||||
})
|
||||
|
||||
return [snapshotLayer, snapshotGroup];
|
||||
return [snapshotLayer, snapshotGroup]
|
||||
} catch (e) {
|
||||
console.warn("createSnapshot Error:", e);
|
||||
console.warn("createSnapshot Error:", e)
|
||||
}
|
||||
}
|
||||
|
||||
function executeCommand(batchPlayCommandFunc) {
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
try {
|
||||
executeAsModal(async () => {
|
||||
await batchPlayCommandFunc();
|
||||
});
|
||||
await batchPlayCommandFunc()
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn("executeCommand error:", e);
|
||||
console.warn("executeCommand error:", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,61 +142,61 @@ async function snapAndFillExe(session_id) {
|
|||
//set mask image
|
||||
|
||||
try {
|
||||
let snapAndFillLayers = [];
|
||||
let snapAndFillLayers = []
|
||||
await executeAsModal(async () => {
|
||||
const selectionInfo = await psapi.getSelectionInfoExe();
|
||||
const selectionInfo = await psapi.getSelectionInfoExe()
|
||||
// await psapi.unSelectMarqueeExe()
|
||||
|
||||
//create a snapshot of canvas
|
||||
// let [snapshotLayer,snapshotGroup] = await createSnapshot()
|
||||
await psapi.snapshot_layerExe();
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0];
|
||||
const snapshotGroup = await psapi.createEmptyGroup();
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary";
|
||||
snapshotGroup.name = "Init Image Group -- temporary";
|
||||
await psapi.snapshot_layerExe()
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0]
|
||||
const snapshotGroup = await psapi.createEmptyGroup()
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary"
|
||||
snapshotGroup.name = "Init Image Group -- temporary"
|
||||
|
||||
// snapshotGroup.name = `${snapshotGroup.name}_init_image`
|
||||
await psapi.createSolidLayer(255, 255, 255);
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0];
|
||||
whiteSolidLayer.name = "Background Color -- temporary";
|
||||
snapshotLayer.moveAbove(whiteSolidLayer);
|
||||
await psapi.createSolidLayer(255, 255, 255)
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0]
|
||||
whiteSolidLayer.name = "Background Color -- temporary"
|
||||
snapshotLayer.moveAbove(whiteSolidLayer)
|
||||
console.log("[snapshotLayer,snapshotGroup]:", [
|
||||
snapshotLayer,
|
||||
snapshotGroup,
|
||||
]);
|
||||
])
|
||||
|
||||
//create a snapshot of mask
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
// let [snapshotMaskLayer,snapshotMaskGroup] = await createSnapshot()
|
||||
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
|
||||
snapAndFillLayers = [snapshotLayer, snapshotGroup, whiteSolidLayer];
|
||||
snapAndFillLayers = [snapshotLayer, snapshotGroup, whiteSolidLayer]
|
||||
|
||||
// g_init_image_related_layers['init_image_group'] = snapshotGroup
|
||||
// g_init_image_related_layers['init_image_layer'] = snapshotLayer
|
||||
// g_init_image_related_layers['solid_white'] = whiteSolidLayer
|
||||
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id);
|
||||
const path = `./server/python_server/init_images/${image_name}`;
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id)
|
||||
const path = `./server/python_server/init_images/${image_name}`
|
||||
|
||||
g_viewer_manager.initializeInitImage(
|
||||
snapshotGroup,
|
||||
snapshotLayer,
|
||||
whiteSolidLayer,
|
||||
path
|
||||
); //this will be called once a session and will add the first init image to th viewer manager
|
||||
) //this will be called once a session and will add the first init image to th viewer manager
|
||||
|
||||
for (layer of snapAndFillLayers) {
|
||||
layer.visible = false;
|
||||
layer.visible = false
|
||||
}
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
const util_layer = require("./utility/layer");
|
||||
await util_layer.collapseFolderExe([snapshotGroup], false);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
const util_layer = require("./utility/layer")
|
||||
await util_layer.collapseFolderExe([snapshotGroup], false)
|
||||
|
||||
// function timeout(ms) {
|
||||
// return new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
|
@ -219,13 +219,13 @@ async function snapAndFillExe(session_id) {
|
|||
// }
|
||||
// }
|
||||
// sleep(saveAndHide)
|
||||
});
|
||||
console.log("snapAndFillLayers: ", snapAndFillLayers);
|
||||
return snapAndFillLayers;
|
||||
})
|
||||
console.log("snapAndFillLayers: ", snapAndFillLayers)
|
||||
return snapAndFillLayers
|
||||
} catch (e) {
|
||||
console.error(`snapAndFill error: ${e}`);
|
||||
console.error(`snapAndFill error: ${e}`)
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
async function outpaintFasterExe(session_id) {
|
||||
|
|
@ -236,67 +236,67 @@ async function outpaintFasterExe(session_id) {
|
|||
//set mask image
|
||||
|
||||
try {
|
||||
let outpaintLayers = [];
|
||||
let outpaintLayers = []
|
||||
await executeAsModal(async () => {
|
||||
const selectionInfo = await psapi.getSelectionInfoExe();
|
||||
const selectionInfo = await psapi.getSelectionInfoExe()
|
||||
// await psapi.unSelectMarqueeExe()
|
||||
|
||||
//create a snapshot of canvas
|
||||
// let [snapshotLayer,snapshotGroup] = await createSnapshot()
|
||||
await psapi.snapshot_layerExe();
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0];
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary";
|
||||
const snapshotGroup = await psapi.createEmptyGroup();
|
||||
await psapi.snapshot_layerExe()
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0]
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary"
|
||||
const snapshotGroup = await psapi.createEmptyGroup()
|
||||
// snapshotGroup.name = `${snapshotGroup.name}_init_image`
|
||||
snapshotGroup.name = "Init Image Group -- temporary";
|
||||
await psapi.createSolidLayer(255, 255, 255);
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0];
|
||||
whiteSolidLayer.name = "Background Color -- temporary";
|
||||
snapshotLayer.moveAbove(whiteSolidLayer);
|
||||
snapshotGroup.name = "Init Image Group -- temporary"
|
||||
await psapi.createSolidLayer(255, 255, 255)
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0]
|
||||
whiteSolidLayer.name = "Background Color -- temporary"
|
||||
snapshotLayer.moveAbove(whiteSolidLayer)
|
||||
console.log("[snapshotLayer,snapshotGroup]:", [
|
||||
snapshotLayer,
|
||||
snapshotGroup,
|
||||
]);
|
||||
])
|
||||
|
||||
//select opaque pixel and create black fill layer
|
||||
await psapi.selectLayersExe([snapshotLayer]);
|
||||
await psapi.selectLayerChannelCommand();
|
||||
const snapshotMaskGroup = await psapi.createEmptyGroup();
|
||||
await psapi.selectLayersExe([snapshotLayer])
|
||||
await psapi.selectLayerChannelCommand()
|
||||
const snapshotMaskGroup = await psapi.createEmptyGroup()
|
||||
|
||||
await psapi.createSolidLayer(0, 0, 0);
|
||||
let solid_black_layer = app.activeDocument.activeLayers[0];
|
||||
await psapi.createSolidLayer(0, 0, 0)
|
||||
let solid_black_layer = app.activeDocument.activeLayers[0]
|
||||
//create a snapshot of mask
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
// let [snapshotMaskLayer,snapshotMaskGroup] = await createSnapshot()
|
||||
await psapi.snapshot_layerExe();
|
||||
const snapshotMaskLayer = await app.activeDocument.activeLayers[0];
|
||||
snapshotMaskLayer.name = "Mask -- Paint White to Mask -- temporary";
|
||||
await psapi.snapshot_layerExe()
|
||||
const snapshotMaskLayer = await app.activeDocument.activeLayers[0]
|
||||
snapshotMaskLayer.name = "Mask -- Paint White to Mask -- temporary"
|
||||
// const snapshotMaskGroup = await psapi.createEmptyGroup()
|
||||
|
||||
// snapshotMaskGroup.name = `${snapshotMaskGroup.name}_mask`
|
||||
snapshotMaskGroup.name = "Mask Group -- temporary";
|
||||
snapshotMaskLayer.moveBelow(solid_black_layer);
|
||||
await snapshotMaskGroup.moveAbove(snapshotGroup);
|
||||
await solid_black_layer.delete(); // should we await for the deletion?
|
||||
snapshotMaskGroup.name = "Mask Group -- temporary"
|
||||
snapshotMaskLayer.moveBelow(solid_black_layer)
|
||||
await snapshotMaskGroup.moveAbove(snapshotGroup)
|
||||
await solid_black_layer.delete() // should we await for the deletion?
|
||||
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id);
|
||||
const path = `./server/python_server/init_images/${image_name}`;
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id)
|
||||
const path = `./server/python_server/init_images/${image_name}`
|
||||
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
await psapi.selectLayers([snapshotMaskGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.selectLayers([snapshotMaskGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.selectLayers([snapshotMaskGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
await psapi.selectLayers([snapshotMaskGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
await psapi.setInitImageMask(snapshotMaskGroup, session_id);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.setInitImageMask(snapshotMaskGroup, session_id)
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
//set initial image
|
||||
//set mask image
|
||||
outpaintLayers = [
|
||||
|
|
@ -305,7 +305,7 @@ async function outpaintFasterExe(session_id) {
|
|||
snapshotLayer,
|
||||
snapshotGroup,
|
||||
whiteSolidLayer,
|
||||
];
|
||||
]
|
||||
// g_mask_related_layers['mask_group'] = snapshotMaskGroup
|
||||
// g_mask_related_layers['white_mark'] = snapshotMaskLayer
|
||||
// // g_mask_related_layers['solid_black'] = blackSolidLayer
|
||||
|
|
@ -314,7 +314,7 @@ async function outpaintFasterExe(session_id) {
|
|||
snapshotMaskLayer,
|
||||
null,
|
||||
path
|
||||
);
|
||||
)
|
||||
// g_init_image_related_layers['init_image_group'] = snapshotGroup
|
||||
// g_init_image_related_layers['init_image_layer'] = snapshotLayer
|
||||
// g_init_image_related_layers['solid_white'] = whiteSolidLayer
|
||||
|
|
@ -324,31 +324,31 @@ async function outpaintFasterExe(session_id) {
|
|||
snapshotLayer,
|
||||
whiteSolidLayer,
|
||||
path
|
||||
); //this will be called once a session and will add the first init image to th viewer manager
|
||||
) //this will be called once a session and will add the first init image to th viewer manager
|
||||
for (layer of outpaintLayers) {
|
||||
layer.visible = false;
|
||||
layer.visible = false
|
||||
}
|
||||
|
||||
//collapse the folders
|
||||
const util_layer = require("./utility/layer");
|
||||
const util_layer = require("./utility/layer")
|
||||
await util_layer.collapseFolderExe(
|
||||
[snapshotGroup, snapshotMaskGroup],
|
||||
false
|
||||
);
|
||||
});
|
||||
console.log("outpaintLayers 2: ", outpaintLayers);
|
||||
return outpaintLayers;
|
||||
)
|
||||
})
|
||||
console.log("outpaintLayers 2: ", outpaintLayers)
|
||||
return outpaintLayers
|
||||
} catch (e) {
|
||||
console.error(`outpaintFasterExe error: ${e}`);
|
||||
console.error(`outpaintFasterExe error: ${e}`)
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
async function addClippingMaskToLayer(layer, selectionInfo) {
|
||||
await psapi.selectLayers([layer]); //select the layer
|
||||
await psapi.reSelectMarqueeExe(selectionInfo); //reselect the selection
|
||||
await psapi.createClippingMaskExe(); //this will create an cliping mask and select the mask of the layer
|
||||
await psapi.selectLayers([layer]); //reselect the layer instead of the mask
|
||||
await psapi.reSelectMarqueeExe(selectionInfo); //reselect the selection
|
||||
await psapi.selectLayers([layer]) //select the layer
|
||||
await psapi.reSelectMarqueeExe(selectionInfo) //reselect the selection
|
||||
await psapi.createClippingMaskExe() //this will create an cliping mask and select the mask of the layer
|
||||
await psapi.selectLayers([layer]) //reselect the layer instead of the mask
|
||||
await psapi.reSelectMarqueeExe(selectionInfo) //reselect the selection
|
||||
|
||||
////test addClippingMaskToLayer
|
||||
// await executeAsModal(
|
||||
|
|
@ -365,70 +365,70 @@ async function outpaintExe(session_id) {
|
|||
//set mask image
|
||||
|
||||
try {
|
||||
let outpaintLayers = [];
|
||||
let outpaintLayers = []
|
||||
await executeAsModal(async () => {
|
||||
const selectionInfo = await psapi.getSelectionInfoExe();
|
||||
const selectionInfo = await psapi.getSelectionInfoExe()
|
||||
// await psapi.unSelectMarqueeExe()
|
||||
|
||||
//create a snapshot of canvas
|
||||
// let [snapshotLayer,snapshotGroup] = await createSnapshot()
|
||||
await psapi.snapshot_layerExe();
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0];
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary";
|
||||
const snapshotGroup = await psapi.createEmptyGroup();
|
||||
await psapi.snapshot_layerExe()
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0]
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary"
|
||||
const snapshotGroup = await psapi.createEmptyGroup()
|
||||
// snapshotGroup.name = `${snapshotGroup.name}_init_image`
|
||||
snapshotGroup.name = "Init Image Group -- temporary";
|
||||
await psapi.createSolidLayer(255, 255, 255); //solid white inside the Init Image Group
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0];
|
||||
whiteSolidLayer.name = "Background Color -- temporary";
|
||||
snapshotLayer.moveAbove(whiteSolidLayer); //move the snapshot layer to be the first layer in "Init Image Group"
|
||||
snapshotGroup.name = "Init Image Group -- temporary"
|
||||
await psapi.createSolidLayer(255, 255, 255) //solid white inside the Init Image Group
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0]
|
||||
whiteSolidLayer.name = "Background Color -- temporary"
|
||||
snapshotLayer.moveAbove(whiteSolidLayer) //move the snapshot layer to be the first layer in "Init Image Group"
|
||||
console.log("[snapshotLayer,snapshotGroup]:", [
|
||||
snapshotLayer,
|
||||
snapshotGroup,
|
||||
]);
|
||||
])
|
||||
|
||||
//select opaque pixel and create black fill layer
|
||||
await psapi.selectLayers([snapshotLayer]);
|
||||
await psapi.selectLayerChannelCommand();
|
||||
const snapshotMaskGroup = await psapi.createEmptyGroup();
|
||||
await psapi.selectLayers([snapshotLayer])
|
||||
await psapi.selectLayerChannelCommand()
|
||||
const snapshotMaskGroup = await psapi.createEmptyGroup()
|
||||
|
||||
await psapi.createSolidLayer(0, 0, 0);
|
||||
let solid_black_layer = app.activeDocument.activeLayers[0];
|
||||
await psapi.createSolidLayer(0, 0, 0)
|
||||
let solid_black_layer = app.activeDocument.activeLayers[0]
|
||||
//create a snapshot of mask
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
// let [snapshotMaskLayer,snapshotMaskGroup] = await createSnapshot()
|
||||
await psapi.snapshot_layerExe();
|
||||
const snapshotMaskLayer = await app.activeDocument.activeLayers[0];
|
||||
snapshotMaskLayer.name = "Mask -- Paint White to Mask -- temporary";
|
||||
await psapi.snapshot_layerExe()
|
||||
const snapshotMaskLayer = await app.activeDocument.activeLayers[0]
|
||||
snapshotMaskLayer.name = "Mask -- Paint White to Mask -- temporary"
|
||||
// const snapshotMaskGroup = await psapi.createEmptyGroup()
|
||||
|
||||
// snapshotMaskGroup.name = `${snapshotMaskGroup.name}_mask`
|
||||
snapshotMaskGroup.name = "Mask Group -- temporary";
|
||||
snapshotMaskLayer.moveBelow(solid_black_layer);
|
||||
await snapshotMaskGroup.moveAbove(snapshotGroup);
|
||||
await solid_black_layer.delete(); //
|
||||
snapshotMaskGroup.name = "Mask Group -- temporary"
|
||||
snapshotMaskLayer.moveBelow(solid_black_layer)
|
||||
await snapshotMaskGroup.moveAbove(snapshotGroup)
|
||||
await solid_black_layer.delete() //
|
||||
|
||||
await addClippingMaskToLayer(snapshotGroup, selectionInfo);
|
||||
await addClippingMaskToLayer(snapshotGroup, selectionInfo)
|
||||
|
||||
const init_image_name = await psapi.setInitImage(
|
||||
snapshotGroup,
|
||||
session_id
|
||||
);
|
||||
const init_path = `./server/python_server/init_images/${init_image_name}`;
|
||||
)
|
||||
const init_path = `./server/python_server/init_images/${init_image_name}`
|
||||
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
await addClippingMaskToLayer(snapshotMaskGroup, selectionInfo);
|
||||
await addClippingMaskToLayer(snapshotMaskGroup, selectionInfo)
|
||||
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
// await psapi.setInitImageMask(snapshotMaskGroup,session_id)
|
||||
const mask_name = await psapi.setInitImageMask(
|
||||
snapshotMaskGroup,
|
||||
session_id
|
||||
);
|
||||
const mask_path = `./server/python_server/init_images/${mask_name}`;
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
)
|
||||
const mask_path = `./server/python_server/init_images/${mask_name}`
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
//set initial image
|
||||
//set mask image
|
||||
outpaintLayers = [
|
||||
|
|
@ -437,7 +437,7 @@ async function outpaintExe(session_id) {
|
|||
snapshotLayer,
|
||||
snapshotGroup,
|
||||
whiteSolidLayer,
|
||||
];
|
||||
]
|
||||
// g_mask_related_layers['mask_group'] = snapshotMaskGroup
|
||||
// g_mask_related_layers['white_mark'] = snapshotMaskLayer
|
||||
// // g_mask_related_layers['solid_black'] = blackSolidLayer
|
||||
|
|
@ -446,7 +446,7 @@ async function outpaintExe(session_id) {
|
|||
snapshotMaskLayer,
|
||||
null,
|
||||
mask_path
|
||||
);
|
||||
)
|
||||
// g_init_image_related_layers['init_image_group'] = snapshotGroup
|
||||
// g_init_image_related_layers['init_image_layer'] = snapshotLayer
|
||||
// g_init_image_related_layers['solid_white'] = whiteSolidLayer
|
||||
|
|
@ -455,25 +455,25 @@ async function outpaintExe(session_id) {
|
|||
snapshotLayer,
|
||||
whiteSolidLayer,
|
||||
init_path
|
||||
); //this will be called once a session and will add the first init image to th viewer manager
|
||||
) //this will be called once a session and will add the first init image to th viewer manager
|
||||
|
||||
for (layer of outpaintLayers) {
|
||||
layer.visible = false;
|
||||
layer.visible = false
|
||||
}
|
||||
|
||||
//collapse the folders
|
||||
const util_layer = require("./utility/layer");
|
||||
const util_layer = require("./utility/layer")
|
||||
await util_layer.collapseFolderExe(
|
||||
[snapshotGroup, snapshotMaskGroup],
|
||||
false
|
||||
);
|
||||
});
|
||||
console.log("outpaintLayers 2: ", outpaintLayers);
|
||||
return outpaintLayers;
|
||||
)
|
||||
})
|
||||
console.log("outpaintLayers 2: ", outpaintLayers)
|
||||
return outpaintLayers
|
||||
} catch (e) {
|
||||
console.error(`outpaintExe error: ${e}`);
|
||||
console.error(`outpaintExe error: ${e}`)
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
async function inpaintFasterExe(session_id) {
|
||||
|
|
@ -484,57 +484,57 @@ async function inpaintFasterExe(session_id) {
|
|||
//set initial image
|
||||
//set mask image
|
||||
try {
|
||||
let inpaintLayers = [];
|
||||
let inpaintLayers = []
|
||||
await executeAsModal(async () => {
|
||||
const selectionInfo = await psapi.getSelectionInfoExe();
|
||||
const selectionInfo = await psapi.getSelectionInfoExe()
|
||||
|
||||
//hide the current white mark mask layer
|
||||
const white_mark_layer = await app.activeDocument.activeLayers[0];
|
||||
await psapi.selectLayers([white_mark_layer]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
const white_mark_layer = await app.activeDocument.activeLayers[0]
|
||||
await psapi.selectLayers([white_mark_layer])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
white_mark_layer.visible = false;
|
||||
white_mark_layer.name = "Mask -- Paint White to Mask -- temporary";
|
||||
white_mark_layer.visible = false
|
||||
white_mark_layer.name = "Mask -- Paint White to Mask -- temporary"
|
||||
// white_mark_layer.visible = true
|
||||
|
||||
//create a snapshot of canvas
|
||||
|
||||
// let [snapshotLayer,snapshotGroup] = await createSnapshot()
|
||||
// await psapi.snapshot_layer()
|
||||
await psapi.unselectActiveLayersExe(); //invisible layer will cause problem with merging "command is not available" type of error
|
||||
await psapi.unselectActiveLayersExe() //invisible layer will cause problem with merging "command is not available" type of error
|
||||
// await psapi.mergeVisibleExe()
|
||||
await psapi.snapshot_layerExe();
|
||||
await psapi.snapshot_layerExe()
|
||||
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0];
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary";
|
||||
const snapshotGroup = await psapi.createEmptyGroup();
|
||||
snapshotGroup.name = "Init Image Group -- temporary";
|
||||
await psapi.createSolidLayer(255, 255, 255);
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0];
|
||||
whiteSolidLayer.name = "Background Color -- temporary";
|
||||
await snapshotLayer.moveAbove(whiteSolidLayer);
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0]
|
||||
snapshotLayer.name = "Init Image Snapshot -- temporary"
|
||||
const snapshotGroup = await psapi.createEmptyGroup()
|
||||
snapshotGroup.name = "Init Image Group -- temporary"
|
||||
await psapi.createSolidLayer(255, 255, 255)
|
||||
const whiteSolidLayer = await app.activeDocument.activeLayers[0]
|
||||
whiteSolidLayer.name = "Background Color -- temporary"
|
||||
await snapshotLayer.moveAbove(whiteSolidLayer)
|
||||
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
const maskGroup = await psapi.createEmptyGroup();
|
||||
const maskGroup = await psapi.createEmptyGroup()
|
||||
// maskGroup.name = `${maskGroup.name}_mask`
|
||||
|
||||
maskGroup.name = "Mask Group -- temporary";
|
||||
maskGroup.name = "Mask Group -- temporary"
|
||||
|
||||
await psapi.createSolidLayer(0, 0, 0);
|
||||
const blackSolidLayer = await app.activeDocument.activeLayers[0];
|
||||
blackSolidLayer.name = "Don't Edit -- temporary";
|
||||
await psapi.createSolidLayer(0, 0, 0)
|
||||
const blackSolidLayer = await app.activeDocument.activeLayers[0]
|
||||
blackSolidLayer.name = "Don't Edit -- temporary"
|
||||
// snapshotLayer.moveAbove(blackSolidLayer)
|
||||
white_mark_layer.moveAbove(blackSolidLayer);
|
||||
white_mark_layer.visible = true;
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
white_mark_layer.moveAbove(blackSolidLayer)
|
||||
white_mark_layer.visible = true
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
console.log("[snapshotLayer,maskGroup]:", [snapshotLayer, maskGroup]);
|
||||
console.log("[snapshotLayer,maskGroup]:", [snapshotLayer, maskGroup])
|
||||
// //select opaque pixel and create black fill layer
|
||||
// await psapi.selectLayers([snapshotLayer])
|
||||
// await psapi.selectLayerChannelCommand()
|
||||
|
|
@ -554,31 +554,31 @@ async function inpaintFasterExe(session_id) {
|
|||
// await snapshotMaskGroup.moveAbove(snapshotGroup)
|
||||
// solid_black_layer.delete()
|
||||
|
||||
await psapi.selectLayers([maskGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.createClippingMaskExe();
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.selectLayers([maskGroup])
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.createClippingMaskExe()
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
|
||||
// await psapi.selectLayers([snapshotGroup])
|
||||
|
||||
await psapi.selectLayers([maskGroup]);
|
||||
await psapi.selectLayers([maskGroup])
|
||||
// await psapi.setInitImageMask(maskGroup,session_id)
|
||||
const mask_name = await psapi.setInitImageMask(maskGroup, session_id);
|
||||
const mask_path = `./server/python_server/init_images/${mask_name}`;
|
||||
const mask_name = await psapi.setInitImageMask(maskGroup, session_id)
|
||||
const mask_path = `./server/python_server/init_images/${mask_name}`
|
||||
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.selectLayers([snapshotGroup]);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
await psapi.selectLayers([snapshotGroup])
|
||||
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id);
|
||||
const path = `./server/python_server/init_images/${image_name}`;
|
||||
const image_name = await psapi.setInitImage(snapshotGroup, session_id)
|
||||
const path = `./server/python_server/init_images/${image_name}`
|
||||
|
||||
await psapi.reSelectMarqueeExe(selectionInfo);
|
||||
await psapi.reSelectMarqueeExe(selectionInfo)
|
||||
// await psapi.selectLayers([snapshotMaskGroup])
|
||||
// await psapi.setInitImageMask(snapshotMaskGroup)
|
||||
// //set initial image
|
||||
// //set mask image
|
||||
|
||||
await psapi.selectLayers([maskGroup]);
|
||||
await psapi.selectLayers([maskGroup])
|
||||
inpaintLayers = [
|
||||
maskGroup,
|
||||
white_mark_layer,
|
||||
|
|
@ -586,7 +586,7 @@ async function inpaintFasterExe(session_id) {
|
|||
snapshotGroup,
|
||||
snapshotLayer,
|
||||
whiteSolidLayer,
|
||||
];
|
||||
]
|
||||
// g_mask_related_layers['mask_group'] = maskGroup
|
||||
// g_mask_related_layers['white_mark'] = white_mark_layer
|
||||
// g_mask_related_layers['solid_black'] = blackSolidLayer
|
||||
|
|
@ -595,7 +595,7 @@ async function inpaintFasterExe(session_id) {
|
|||
white_mark_layer,
|
||||
blackSolidLayer,
|
||||
mask_path
|
||||
);
|
||||
)
|
||||
// g_init_image_related_layers['init_image_group'] = snapshotGroup
|
||||
// g_init_image_related_layers['init_image_layer'] = snapshotLayer
|
||||
// g_init_image_related_layers['solid_white'] = whiteSolidLayer
|
||||
|
|
@ -604,19 +604,19 @@ async function inpaintFasterExe(session_id) {
|
|||
snapshotLayer,
|
||||
whiteSolidLayer,
|
||||
path
|
||||
); //this will be called once a session and will add the first init image to th viewer manager
|
||||
) //this will be called once a session and will add the first init image to th viewer manager
|
||||
for (layer of inpaintLayers) {
|
||||
layer.visible = false;
|
||||
layer.visible = false
|
||||
}
|
||||
const util_layer = require("./utility/layer");
|
||||
const util_layer = require("./utility/layer")
|
||||
|
||||
await util_layer.collapseFolderExe([snapshotGroup, maskGroup], false);
|
||||
});
|
||||
return inpaintLayers;
|
||||
await util_layer.collapseFolderExe([snapshotGroup, maskGroup], false)
|
||||
})
|
||||
return inpaintLayers
|
||||
} catch (e) {
|
||||
console.warn("inpaintFasterExe error:", e);
|
||||
console.warn("inpaintFasterExe error:", e)
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
module.exports = {
|
||||
createSnapshot,
|
||||
|
|
@ -628,4 +628,4 @@ module.exports = {
|
|||
inpaintFasterExe,
|
||||
snapAndFillExe,
|
||||
addClippingMaskToLayer,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
498
psapi.js
498
psapi.js
|
|
@ -1,12 +1,12 @@
|
|||
const app = window.require("photoshop").app;
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const export_png = require("./export_png");
|
||||
const { selectionToFinalWidthHeight } = require("./selection");
|
||||
const app = window.require("photoshop").app
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
const export_png = require("./export_png")
|
||||
const { selectionToFinalWidthHeight } = require("./selection")
|
||||
// const { layerToSelection } = require('./helper')
|
||||
|
||||
const storage = require("uxp").storage;
|
||||
const fs = storage.localFileSystem;
|
||||
const storage = require("uxp").storage
|
||||
const fs = storage.localFileSystem
|
||||
|
||||
async function createSolidLayer(r, g, b) {
|
||||
await executeAsModal(async () => {
|
||||
|
|
@ -40,8 +40,8 @@ async function createSolidLayer(r, g, b) {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function makeGroupCommand() {
|
||||
|
|
@ -66,27 +66,27 @@ async function makeGroupCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
console.log("makeGroupCommand: ", result);
|
||||
console.log("makeGroupCommand: ", result)
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
async function createEmptyGroup(name = "New Group") {
|
||||
let groupLayer;
|
||||
let groupLayer
|
||||
await executeAsModal(async () => {
|
||||
await makeGroupCommand();
|
||||
groupLayer = app.activeDocument.activeLayers[0];
|
||||
groupLayer.name = name;
|
||||
});
|
||||
console.log("groupLayer:", groupLayer);
|
||||
return groupLayer;
|
||||
await makeGroupCommand()
|
||||
groupLayer = app.activeDocument.activeLayers[0]
|
||||
groupLayer.name = name
|
||||
})
|
||||
console.log("groupLayer:", groupLayer)
|
||||
return groupLayer
|
||||
}
|
||||
|
||||
async function moveToGroupCommand(to_index, layerIDs) {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
console.log("to_index:", to_index);
|
||||
console.log("layerIDs:", layerIDs);
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
console.log("to_index:", to_index)
|
||||
console.log("layerIDs:", layerIDs)
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -115,15 +115,15 @@ async function moveToGroupCommand(to_index, layerIDs) {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
function MoveToGroupExe(toIndex, layerIDs) {
|
||||
try {
|
||||
executeAsModal(async () => {
|
||||
await moveToGroupCommand(toIndex, layerIDs);
|
||||
});
|
||||
await moveToGroupCommand(toIndex, layerIDs)
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn("executeCommand error:", e);
|
||||
console.warn("executeCommand error:", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,67 +148,67 @@ async function getIndexCommand(layer_id) {
|
|||
},
|
||||
],
|
||||
{ synchronousExecution: true }
|
||||
)[0]["itemIndex"];
|
||||
console.log("index:", idx);
|
||||
return idx;
|
||||
)[0]["itemIndex"]
|
||||
console.log("index:", idx)
|
||||
return idx
|
||||
}
|
||||
|
||||
async function getLayerIndex(layer_id) {
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
try {
|
||||
let index;
|
||||
let index
|
||||
await executeAsModal(async () => {
|
||||
index = await getIndexCommand(layer_id);
|
||||
console.log("getIndex: ", index);
|
||||
});
|
||||
return index;
|
||||
index = await getIndexCommand(layer_id)
|
||||
console.log("getIndex: ", index)
|
||||
})
|
||||
return index
|
||||
} catch (e) {
|
||||
console.warn("getIndex error:", e);
|
||||
console.warn("getIndex error:", e)
|
||||
}
|
||||
}
|
||||
|
||||
async function unselectActiveLayers() {
|
||||
const layers = await app.activeDocument.activeLayers;
|
||||
const layers = await app.activeDocument.activeLayers
|
||||
for (layer of layers) {
|
||||
layer.selected = false;
|
||||
layer.selected = false
|
||||
}
|
||||
}
|
||||
async function unselectActiveLayersExe() {
|
||||
await executeAsModal(async () => {
|
||||
await unselectActiveLayers();
|
||||
});
|
||||
await unselectActiveLayers()
|
||||
})
|
||||
}
|
||||
async function selectLayers(layers) {
|
||||
await unselectActiveLayers();
|
||||
await unselectActiveLayers()
|
||||
for (layer of layers) {
|
||||
try {
|
||||
if (layer) {
|
||||
const is_visible = layer.visible; // don't change the visibility when selecting the layer
|
||||
layer.selected = true;
|
||||
layer.visible = is_visible;
|
||||
const is_visible = layer.visible // don't change the visibility when selecting the layer
|
||||
layer.selected = true
|
||||
layer.visible = is_visible
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function selectLayersExe(layers) {
|
||||
await executeAsModal(async () => {
|
||||
await selectLayers(layers);
|
||||
});
|
||||
await selectLayers(layers)
|
||||
})
|
||||
}
|
||||
async function selectGroup(layer) {
|
||||
await unselectActiveLayers();
|
||||
layer.parent.selected = true;
|
||||
await unselectActiveLayers()
|
||||
layer.parent.selected = true
|
||||
}
|
||||
async function collapseGroup(layer) {
|
||||
await selectGroup(layer);
|
||||
await app.activeDocument.activeLayers[0].merge();
|
||||
await selectGroup(layer)
|
||||
await app.activeDocument.activeLayers[0].merge()
|
||||
}
|
||||
|
||||
async function createMaskCommand() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -235,17 +235,17 @@ async function createMaskCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
async function createMaskExe() {
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
await executeAsModal(createMaskCommand);
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
await executeAsModal(createMaskCommand)
|
||||
}
|
||||
|
||||
//unselect the rectangular marquee selection area
|
||||
async function unSelectMarqueeCommand() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -270,12 +270,12 @@ async function unSelectMarqueeCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
async function unSelectMarqueeExe() {
|
||||
await executeAsModal(unSelectMarqueeCommand);
|
||||
await executeAsModal(unSelectMarqueeCommand)
|
||||
}
|
||||
////selection:
|
||||
async function selectMarqueeRectangularToolExe() {
|
||||
|
|
@ -298,30 +298,30 @@ async function selectMarqueeRectangularToolExe() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
return result;
|
||||
)
|
||||
return result
|
||||
}
|
||||
await executeAsModal(async () => {
|
||||
await selectMarqueeRectangularToolCommand();
|
||||
});
|
||||
await selectMarqueeRectangularToolCommand()
|
||||
})
|
||||
}
|
||||
|
||||
async function promptForMarqueeTool() {
|
||||
(async () => {
|
||||
;(async () => {
|
||||
const r1 = await dialog_box.prompt(
|
||||
"Please Select a Rectangular Area",
|
||||
"You Forgot to select a Rectangular Area",
|
||||
["Cancel", "Rectangular Marquee"]
|
||||
);
|
||||
)
|
||||
if ((r1 || "Rectangular Marquee") !== "Rectangular Marquee") {
|
||||
/* cancelled or No */
|
||||
console.log("cancel");
|
||||
console.log("cancel")
|
||||
} else {
|
||||
/* Yes */
|
||||
console.log("Rectangular Marquee");
|
||||
selectMarqueeRectangularToolExe();
|
||||
console.log("Rectangular Marquee")
|
||||
selectMarqueeRectangularToolExe()
|
||||
}
|
||||
})();
|
||||
})()
|
||||
}
|
||||
|
||||
async function selectLayerChannelCommand() {
|
||||
|
|
@ -358,7 +358,7 @@ async function selectLayerChannelCommand() {
|
|||
// modalBehavior: 'execute'
|
||||
// }
|
||||
// )
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -384,7 +384,7 @@ async function selectLayerChannelCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
async function getSelectionInfoCommand() {
|
||||
|
|
@ -410,9 +410,9 @@ async function getSelectionInfoCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
function isSelectionValid(selection) {
|
||||
|
|
@ -423,17 +423,17 @@ function isSelectionValid(selection) {
|
|||
selection.hasOwnProperty("top") &&
|
||||
selection.hasOwnProperty("bottom")
|
||||
) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
async function getSelectionInfoExe() {
|
||||
console.log("getSelectionInfo was called");
|
||||
console.log("getSelectionInfo was called")
|
||||
|
||||
try {
|
||||
const selection = (await executeAsModal(getSelectionInfoCommand))[0]
|
||||
.selection;
|
||||
.selection
|
||||
|
||||
if (isSelectionValid(selection)) {
|
||||
let selection_info = {
|
||||
|
|
@ -443,12 +443,12 @@ async function getSelectionInfoExe() {
|
|||
top: selection.top._value,
|
||||
height: selection.bottom._value - selection.top._value,
|
||||
width: selection.right._value - selection.left._value,
|
||||
};
|
||||
}
|
||||
// console.dir({selection_info})
|
||||
return selection_info;
|
||||
return selection_info
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("selection info error", e);
|
||||
console.warn("selection info error", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -491,18 +491,18 @@ async function reSelectMarqueeCommand(selectionInfo) {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
async function reSelectMarqueeExe(selectionInfo) {
|
||||
await executeAsModal(async () => {
|
||||
await reSelectMarqueeCommand(selectionInfo);
|
||||
});
|
||||
await reSelectMarqueeCommand(selectionInfo)
|
||||
})
|
||||
}
|
||||
|
||||
async function snapshot_layer() {
|
||||
let psAction = require("photoshop").action;
|
||||
let psAction = require("photoshop").action
|
||||
// const ids = (await app.activeDocument.activeLayers).map(layer => layer.id)
|
||||
const ids = await app.activeDocument.layers.map((layer) => layer.id);
|
||||
const ids = await app.activeDocument.layers.map((layer) => layer.id)
|
||||
let command = [
|
||||
// Select All Layers current layer
|
||||
{
|
||||
|
|
@ -533,35 +533,35 @@ async function snapshot_layer() {
|
|||
_target: [{ _property: "selection", _ref: "channel" }],
|
||||
to: { _enum: "ordinal", _ref: "channel", _value: "targetEnum" },
|
||||
},
|
||||
];
|
||||
]
|
||||
const result = await psAction.batchPlay(command, {
|
||||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
});
|
||||
console.log("snapshot_layer: result: ", result);
|
||||
return result;
|
||||
})
|
||||
console.log("snapshot_layer: result: ", result)
|
||||
return result
|
||||
}
|
||||
|
||||
async function snapshot_layerExe() {
|
||||
try {
|
||||
await executeAsModal(
|
||||
async () => {
|
||||
await snapshot_layer();
|
||||
await snapshot_layer()
|
||||
},
|
||||
{
|
||||
commandName: "Action Commands",
|
||||
}
|
||||
);
|
||||
)
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
// await runModalFunction();
|
||||
|
||||
async function fillAndGroup() {
|
||||
let result;
|
||||
let psAction = require("photoshop").action;
|
||||
let result
|
||||
let psAction = require("photoshop").action
|
||||
|
||||
// let newCommand =[
|
||||
// // snapshotLayer
|
||||
|
|
@ -592,13 +592,13 @@ async function fillAndGroup() {
|
|||
// {"_obj":"select","_target":[{"_name":"Layer 4 copy","_ref":"layer"}],"layerID":[17,15],"makeVisible":false,"selectionModifier":{"_enum":"selectionModifierType","_value":"addToSelectionContinuous"}},
|
||||
// Make Group
|
||||
// {"_obj":"make","_target":[{"_ref":"layerSection"}],"from":{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"},"layerSectionEnd":19,"layerSectionStart":18,"name":"Group 1"}
|
||||
];
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0];
|
||||
await makeGroupCommand();
|
||||
const groupLayer = app.activeDocument.activeLayers[0];
|
||||
result = await psAction.batchPlay(command, {});
|
||||
const fillLayer = app.activeDocument.activeLayers[0];
|
||||
snapshotLayer.moveAbove(fillLayer);
|
||||
]
|
||||
const snapshotLayer = await app.activeDocument.activeLayers[0]
|
||||
await makeGroupCommand()
|
||||
const groupLayer = app.activeDocument.activeLayers[0]
|
||||
result = await psAction.batchPlay(command, {})
|
||||
const fillLayer = app.activeDocument.activeLayers[0]
|
||||
snapshotLayer.moveAbove(fillLayer)
|
||||
// await app.activeDocument.activeLayers[0].moveAbove()
|
||||
// const layerIDs = []
|
||||
// const to_index = await getIndexCommand(groupLayer.id)
|
||||
|
|
@ -608,40 +608,40 @@ async function fillAndGroup() {
|
|||
async function fillAndGroupExe() {
|
||||
await require("photoshop").core.executeAsModal(fillAndGroup, {
|
||||
commandName: "Action Commands",
|
||||
});
|
||||
})
|
||||
}
|
||||
async function fastSnapshot() {
|
||||
await snapshot_layerExe();
|
||||
await fillAndGroupExe();
|
||||
await snapshot_layerExe()
|
||||
await fillAndGroupExe()
|
||||
}
|
||||
|
||||
function layerToFileName(layer, session_id) {
|
||||
file_name = `${layer.name}_${layer.id}_${session_id}`;
|
||||
return file_name;
|
||||
file_name = `${layer.name}_${layer.id}_${session_id}`
|
||||
return file_name
|
||||
}
|
||||
function layerNameToFileName(layer_name, layer_id, session_id) {
|
||||
file_name = `${layer_name}_${layer_id}_${session_id}`;
|
||||
return file_name;
|
||||
file_name = `${layer_name}_${layer_id}_${session_id}`
|
||||
return file_name
|
||||
}
|
||||
async function exportPngCommand(session_id) {
|
||||
try {
|
||||
// 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 layer = await app.activeDocument.activeLayers[0];
|
||||
const old_name = layer.name;
|
||||
)
|
||||
const layer = await app.activeDocument.activeLayers[0]
|
||||
const old_name = layer.name
|
||||
//change the name of layer to unique name
|
||||
const file_name = layerToFileName(layer, session_id);
|
||||
layer.name = file_name;
|
||||
const id = await app.activeDocument.activeLayers[0].id;
|
||||
const file_name = layerToFileName(layer, session_id)
|
||||
layer.name = file_name
|
||||
const id = await app.activeDocument.activeLayers[0].id
|
||||
const exportCommand = {
|
||||
_obj: "exportSelectionAsFileTypePressed",
|
||||
// _target: { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' },
|
||||
|
|
@ -659,98 +659,98 @@ async function exportPngCommand(session_id) {
|
|||
sRGB: true,
|
||||
openWindow: false,
|
||||
_options: { dialogOptions: "dontDisplay" },
|
||||
};
|
||||
}
|
||||
const result = await batchPlay([exportCommand], {
|
||||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
});
|
||||
})
|
||||
|
||||
return result;
|
||||
return result
|
||||
} catch (e) {
|
||||
console.error(`exportPngCommand error:, ${e}`);
|
||||
console.error(`exportPngCommand error:, ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function exportPng(session_id) {
|
||||
console.log("exportPng() -> session_id:", session_id);
|
||||
console.log("exportPng() -> session_id:", session_id)
|
||||
try {
|
||||
const old_name = await app.activeDocument.activeLayers[0].name;
|
||||
const old_name = await app.activeDocument.activeLayers[0].name
|
||||
await executeAsModal(async () => {
|
||||
await exportPngCommand(session_id);
|
||||
});
|
||||
await exportPngCommand(session_id)
|
||||
})
|
||||
setTimeout(async () => {
|
||||
console.log("setTimeout() -> old_name: ", old_name);
|
||||
console.log("setTimeout() -> old_name: ", old_name)
|
||||
await executeAsModal(async () => {
|
||||
app.activeDocument.activeLayers[0].name = old_name;
|
||||
});
|
||||
}, 3000);
|
||||
app.activeDocument.activeLayers[0].name = old_name
|
||||
})
|
||||
}, 3000)
|
||||
//after export rename the layer to it's original name by remove the "_${id}" from the name
|
||||
} catch (e) {
|
||||
console.error(`exportPng error:, ${e}`);
|
||||
console.error(`exportPng error:, ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
// await runModalFunction();
|
||||
async function setInitImage(layer, session_id) {
|
||||
try {
|
||||
const html_manip = require("./utility/html_manip");
|
||||
const html_manip = require("./utility/html_manip")
|
||||
// const layer = await app.activeDocument.activeLayers[0]
|
||||
const old_name = layer.name;
|
||||
const sdapi = require("./sdapi");
|
||||
const old_name = layer.name
|
||||
const sdapi = require("./sdapi")
|
||||
// await exportPng(session_id)
|
||||
// image_name = await app.activeDocument.activeLayers[0].name
|
||||
|
||||
//convert layer name to a file name
|
||||
image_name = layerNameToFileName(old_name, layer.id, session_id);
|
||||
image_name = `${image_name}.png`;
|
||||
image_name = layerNameToFileName(old_name, layer.id, session_id)
|
||||
image_name = `${image_name}.png`
|
||||
|
||||
//the width and height of the exported image
|
||||
const width = html_manip.getWidth();
|
||||
const height = html_manip.getHeight();
|
||||
await newExportPng(layer, image_name, width, height);
|
||||
const width = html_manip.getWidth()
|
||||
const height = html_manip.getHeight()
|
||||
await newExportPng(layer, image_name, width, height)
|
||||
|
||||
g_init_image_name = image_name;
|
||||
console.log(image_name);
|
||||
g_init_image_name = image_name
|
||||
console.log(image_name)
|
||||
|
||||
const image_src = await sdapi.getInitImage(g_init_image_name);
|
||||
let ini_image_element = document.getElementById("init_image");
|
||||
ini_image_element.src = image_src;
|
||||
const image_src = await sdapi.getInitImage(g_init_image_name)
|
||||
let ini_image_element = document.getElementById("init_image")
|
||||
ini_image_element.src = image_src
|
||||
|
||||
return image_name;
|
||||
return image_name
|
||||
} catch (e) {
|
||||
console.error(`psapi.js setInitImage error:, ${e}`);
|
||||
console.error(`psapi.js setInitImage error:, ${e}`)
|
||||
}
|
||||
}
|
||||
async function setInitImageMask(layer, session_id) {
|
||||
try {
|
||||
const html_manip = require("./utility/html_manip");
|
||||
const html_manip = require("./utility/html_manip")
|
||||
|
||||
// const layer = await app.activeDocument.activeLayers[0]
|
||||
const old_name = layer.name;
|
||||
const sdapi = require("./sdapi");
|
||||
const old_name = layer.name
|
||||
const sdapi = require("./sdapi")
|
||||
// await exportPng(session_id)
|
||||
//get the active layer name
|
||||
// image_name = await app.activeDocument.activeLayers[0].name
|
||||
// image_name = layerNameToFileName(old_name,layer.id,random_session_id)
|
||||
image_name = layerNameToFileName(old_name, layer.id, session_id);
|
||||
image_name = `${image_name}.png`;
|
||||
const width = html_manip.getWidth();
|
||||
const height = html_manip.getHeight();
|
||||
await newExportPng(layer, image_name, width, height);
|
||||
g_init_image_mask_name = image_name; // this is the name we will send to the server
|
||||
image_name = layerNameToFileName(old_name, layer.id, session_id)
|
||||
image_name = `${image_name}.png`
|
||||
const width = html_manip.getWidth()
|
||||
const height = html_manip.getHeight()
|
||||
await newExportPng(layer, image_name, width, height)
|
||||
g_init_image_mask_name = image_name // this is the name we will send to the server
|
||||
// g_init_mask_layer = layer
|
||||
// g_mask_related_layers = {}
|
||||
console.log(image_name);
|
||||
console.log(image_name)
|
||||
|
||||
const image_src = await sdapi.getInitImage(g_init_image_mask_name); // we should replace this with getInitImagePath which return path to local disk
|
||||
const ini_image_mask_element = document.getElementById("init_image_mask");
|
||||
ini_image_mask_element.src = image_src;
|
||||
ini_image_mask_element.dataset.layer_id = layer.id;
|
||||
const image_src = await sdapi.getInitImage(g_init_image_mask_name) // we should replace this with getInitImagePath which return path to local disk
|
||||
const ini_image_mask_element = document.getElementById("init_image_mask")
|
||||
ini_image_mask_element.src = image_src
|
||||
ini_image_mask_element.dataset.layer_id = layer.id
|
||||
|
||||
//create viewer init image obj
|
||||
return image_name;
|
||||
return image_name
|
||||
} catch (e) {
|
||||
console.error(`psapi.js setInitImageMask error: `, e);
|
||||
console.error(`psapi.js setInitImageMask error: `, e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -777,20 +777,20 @@ async function cleanLayers(layers) {
|
|||
// g_init_image_related_layers = {}
|
||||
// g_mask_related_layers = {}
|
||||
// await loadViewerImages()// we should move loadViewerImages to a new file viewer.js
|
||||
console.log("cleanLayers() -> layers:", layers);
|
||||
console.log("cleanLayers() -> layers:", layers)
|
||||
for (layer of layers) {
|
||||
try {
|
||||
if (layer) {
|
||||
await executeAsModal(async () => {
|
||||
await layer.delete();
|
||||
});
|
||||
await layer.delete()
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("warning attempting to a delete layer: ", e);
|
||||
continue;
|
||||
console.warn("warning attempting to a delete layer: ", e)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
// async function cleanLayersOutpaint(layers){
|
||||
|
|
@ -823,7 +823,7 @@ async function cleanLayers(layers) {
|
|||
// return []
|
||||
// }
|
||||
async function createClippingMaskExe() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
async function createClippingMaskCommand() {
|
||||
const result = await batchPlay(
|
||||
|
|
@ -851,27 +851,27 @@ async function createClippingMaskExe() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
await executeAsModal(async () => {
|
||||
await createClippingMaskCommand();
|
||||
});
|
||||
await createClippingMaskCommand()
|
||||
})
|
||||
}
|
||||
|
||||
async function checkIfSelectionAreaIsActive() {
|
||||
try {
|
||||
let isSelectionAreaValid = await getSelectionInfoExe();
|
||||
return isSelectionAreaValid;
|
||||
let isSelectionAreaValid = await getSelectionInfoExe()
|
||||
return isSelectionAreaValid
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
async function saveUniqueDocumentIdExe(new_id) {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
async function saveUniqueDocumentIdCommand() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -902,19 +902,19 @@ async function saveUniqueDocumentIdExe(new_id) {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
await executeAsModal(async () => {
|
||||
await saveUniqueDocumentIdCommand();
|
||||
});
|
||||
await saveUniqueDocumentIdCommand()
|
||||
})
|
||||
}
|
||||
|
||||
async function readUniqueDocumentIdExe() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
async function readUniqueDocumentIdCommand() {
|
||||
const batchPlay = require("photoshop").action.batchPlay;
|
||||
const batchPlay = require("photoshop").action.batchPlay
|
||||
|
||||
const result = await batchPlay(
|
||||
[
|
||||
|
|
@ -945,26 +945,26 @@ async function readUniqueDocumentIdExe() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
console.log("readUniqueDocumentIdCommand: result ", result);
|
||||
return result;
|
||||
)
|
||||
console.log("readUniqueDocumentIdCommand: result ", result)
|
||||
return result
|
||||
}
|
||||
|
||||
let uniqueDocumentId = "";
|
||||
let uniqueDocumentId = ""
|
||||
try {
|
||||
await executeAsModal(async () => {
|
||||
uniqueDocumentId = (await readUniqueDocumentIdCommand())[0].fileInfo
|
||||
.caption;
|
||||
.caption
|
||||
if (typeof uniqueDocumentId === "string") {
|
||||
uniqueDocumentId = uniqueDocumentId.trim();
|
||||
uniqueDocumentId = uniqueDocumentId.trim()
|
||||
}
|
||||
});
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn("readUniqueDocumentIdExe: ", e);
|
||||
uniqueDocumentId = "";
|
||||
console.warn("readUniqueDocumentIdExe: ", e)
|
||||
uniqueDocumentId = ""
|
||||
}
|
||||
|
||||
return uniqueDocumentId;
|
||||
return uniqueDocumentId
|
||||
}
|
||||
|
||||
const readPng = async (image_name) => {
|
||||
|
|
@ -973,19 +973,19 @@ 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,
|
||||
// {
|
||||
|
|
@ -993,18 +993,18 @@ const readPng = async (image_name) => {
|
|||
// },
|
||||
null,
|
||||
true
|
||||
);
|
||||
)
|
||||
|
||||
// const arrayBuffer = await file.read({format: formats.binary}) ;
|
||||
// console.log(arrayBuffer, 'arrayBuffer') ;
|
||||
},
|
||||
|
||||
{ commandName: "readPng" }
|
||||
);
|
||||
)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function selectCanvasCommand() {
|
||||
// const result = await batchPlay(
|
||||
|
|
@ -1049,17 +1049,17 @@ async function selectCanvasCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
async function selectCanvasExe() {
|
||||
await executeAsModal(
|
||||
async () => {
|
||||
await selectCanvasCommand();
|
||||
await selectCanvasCommand()
|
||||
},
|
||||
{ commandName: "selectCanvasExe" }
|
||||
);
|
||||
)
|
||||
}
|
||||
async function newExportPng(layer, image_name, width, height) {
|
||||
//store layers we want to export in variables
|
||||
|
|
@ -1076,7 +1076,7 @@ async function newExportPng(layer, image_name, width, height) {
|
|||
|
||||
//create new document
|
||||
// let exportDoc = await executeAsModal(app.documents.add)
|
||||
let exportDoc;
|
||||
let exportDoc
|
||||
const makeDoc = async () => {
|
||||
let exportDoc = await app.documents.add({
|
||||
width: width,
|
||||
|
|
@ -1084,35 +1084,35 @@ async function newExportPng(layer, image_name, width, height) {
|
|||
resolution: 300,
|
||||
mode: "RGBColorMode",
|
||||
fill: "transparent",
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
await executeAsModal(
|
||||
async () => {
|
||||
// await app.documents.add()
|
||||
await makeDoc();
|
||||
exportDoc = app.activeDocument;
|
||||
await makeDoc()
|
||||
exportDoc = app.activeDocument
|
||||
|
||||
console.log("exportDoc.id: ", exportDoc.id);
|
||||
console.log("exportDoc.id: ", exportDoc.id)
|
||||
// for (layer of layersToExport) {
|
||||
|
||||
console.log(layer.id);
|
||||
const dupLayer = await layer.duplicate(exportDoc);
|
||||
await selectLayers([dupLayer]);
|
||||
console.log(layer.id)
|
||||
const dupLayer = await layer.duplicate(exportDoc)
|
||||
await selectLayers([dupLayer])
|
||||
// await selectLayerChannelCommand()
|
||||
await selectCanvasExe();
|
||||
const canvas_selection_info = await getSelectionInfoExe();
|
||||
await layerToSelection(canvas_selection_info);
|
||||
await selectCanvasExe()
|
||||
const canvas_selection_info = await getSelectionInfoExe()
|
||||
await layerToSelection(canvas_selection_info)
|
||||
// const selection_info = await getSelectionInfoExe()
|
||||
// await exportDoc.crop(selection_info)
|
||||
// export_image_name = `${layer.name}.png`
|
||||
await readPng(image_name);
|
||||
await exportDoc.closeWithoutSaving();
|
||||
await readPng(image_name)
|
||||
await exportDoc.closeWithoutSaving()
|
||||
},
|
||||
{ commandName: "NewExportPng" }
|
||||
);
|
||||
)
|
||||
// }
|
||||
} catch (e) {
|
||||
console.error(`newExportPng error: ,${e}`);
|
||||
console.error(`newExportPng error: ,${e}`)
|
||||
}
|
||||
}
|
||||
async function mergeVisibleCommand() {
|
||||
|
|
@ -1131,15 +1131,15 @@ async function mergeVisibleCommand() {
|
|||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
async function mergeVisibleExe() {
|
||||
await executeAsModal(async () => {
|
||||
await mergeVisibleCommand();
|
||||
});
|
||||
await mergeVisibleCommand()
|
||||
})
|
||||
}
|
||||
|
||||
async function layerToSelection(selection_info) {
|
||||
|
|
@ -1153,16 +1153,16 @@ async function layerToSelection(selection_info) {
|
|||
//Select from selection info
|
||||
// let selection_info = await getSelectionInfo()
|
||||
|
||||
console.log("selection_info:", selection_info);
|
||||
console.log("selection_info:", selection_info)
|
||||
|
||||
console.log("unSelect");
|
||||
console.log("unSelect")
|
||||
|
||||
function getLayerSize(layer) {
|
||||
console.log("layer.bounds:");
|
||||
console.dir(layer.bounds);
|
||||
const bounds = layer.bounds;
|
||||
const height = bounds.bottom - bounds.top;
|
||||
const width = bounds.right - bounds.left;
|
||||
console.log("layer.bounds:")
|
||||
console.dir(layer.bounds)
|
||||
const bounds = layer.bounds
|
||||
const height = bounds.bottom - bounds.top
|
||||
const width = bounds.right - bounds.left
|
||||
return {
|
||||
height: height,
|
||||
width: width,
|
||||
|
|
@ -1170,49 +1170,49 @@ async function layerToSelection(selection_info) {
|
|||
right: bounds.right,
|
||||
top: bounds.top,
|
||||
bottom: bounds.bottom,
|
||||
};
|
||||
}
|
||||
}
|
||||
//scale layer
|
||||
async function scaleLayer(layer, selection_info) {
|
||||
console.log("scaleLayer got called");
|
||||
console.log("scaleLayer got called")
|
||||
// const activeLayer = getActiveLayer()
|
||||
// const activeLayer = await app.activeDocument.activeLayers[0]
|
||||
|
||||
let layer_info = getLayerSize(layer);
|
||||
scale_x_ratio = (selection_info.width / layer_info.width) * 100;
|
||||
scale_y_ratio = (selection_info.height / layer_info.height) * 100;
|
||||
console.log("scale_x_y_ratio:", scale_x_ratio, scale_y_ratio);
|
||||
await layer.scale(scale_x_ratio, scale_y_ratio);
|
||||
let layer_info = getLayerSize(layer)
|
||||
scale_x_ratio = (selection_info.width / layer_info.width) * 100
|
||||
scale_y_ratio = (selection_info.height / layer_info.height) * 100
|
||||
console.log("scale_x_y_ratio:", scale_x_ratio, scale_y_ratio)
|
||||
await layer.scale(scale_x_ratio, scale_y_ratio)
|
||||
}
|
||||
|
||||
async function moveLayerExe(layerToMove, selection_info) {
|
||||
let layer_info = getLayerSize(layerToMove);
|
||||
top_dist = layer_info.top - selection_info.top;
|
||||
left_dist = layer_info.left - selection_info.left;
|
||||
await layerToMove.translate(-left_dist, -top_dist);
|
||||
let layer_info = getLayerSize(layerToMove)
|
||||
top_dist = layer_info.top - selection_info.top
|
||||
left_dist = layer_info.left - selection_info.left
|
||||
await layerToMove.translate(-left_dist, -top_dist)
|
||||
}
|
||||
// const activeLayer = await getActiveLayer()
|
||||
|
||||
//store all active layers
|
||||
const activeLayers = await app.activeDocument.activeLayers;
|
||||
await unSelectMarqueeExe();
|
||||
const activeLayers = await app.activeDocument.activeLayers
|
||||
await unSelectMarqueeExe()
|
||||
// await executeAsModal(unSelect, {'commandName': 'unSelect'})
|
||||
// await executeAsModal(scaleLayer, {'commandName': 'scaleLayer'})
|
||||
|
||||
await executeAsModal(
|
||||
async () => {
|
||||
for (let layer of activeLayers) {
|
||||
await selectLayers([layer]); // make sure only one layer is selected
|
||||
await scaleLayer(layer, selection_info); //scale to selection size
|
||||
await moveLayerExe(layer, selection_info); //move to selection
|
||||
await selectLayers([layer]) // make sure only one layer is selected
|
||||
await scaleLayer(layer, selection_info) //scale to selection size
|
||||
await moveLayerExe(layer, selection_info) //move to selection
|
||||
}
|
||||
},
|
||||
{ commandName: "moveLayerExe" }
|
||||
);
|
||||
)
|
||||
|
||||
// await reselect(selection_info)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1257,4 +1257,4 @@ module.exports = {
|
|||
selectCanvasExe,
|
||||
layerToSelection,
|
||||
isSelectionValid,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
294
sdapi.js
294
sdapi.js
|
|
@ -1,13 +1,13 @@
|
|||
//javascript plugin can't read images from local directory so we send a request to local server to read the image file and send it back to plugin as image string base64
|
||||
async function getInitImage(init_image_name) {
|
||||
console.log("getInitImage(): get Init Image from the server :");
|
||||
console.log("getInitImage(): get Init Image from the server :")
|
||||
const payload = {
|
||||
init_image_name: init_image_name,
|
||||
};
|
||||
}
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/getInitImage/";
|
||||
console.log(full_url);
|
||||
console.log("getInitImage payload:", payload);
|
||||
const full_url = "http://127.0.0.1:8000/getInitImage/"
|
||||
console.log(full_url)
|
||||
console.log("getInitImage payload:", payload)
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -16,14 +16,14 @@ async function getInitImage(init_image_name) {
|
|||
},
|
||||
body: JSON.stringify(payload),
|
||||
// "body": payload
|
||||
});
|
||||
})
|
||||
|
||||
let json = await request.json();
|
||||
console.log("json:");
|
||||
console.dir(json);
|
||||
base64data = json.init_image_str;
|
||||
image_src = `data:image/png;base64, ${base64data}`;
|
||||
return image_src;
|
||||
let json = await request.json()
|
||||
console.log("json:")
|
||||
console.dir(json)
|
||||
base64data = json.init_image_str
|
||||
image_src = `data:image/png;base64, ${base64data}`
|
||||
return image_src
|
||||
|
||||
// console.log(img.src)
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ async function getInitImage(init_image_name) {
|
|||
|
||||
async function requestTxt2Img(payload) {
|
||||
try {
|
||||
console.log("requestTxt2Img(): about to send a fetch request");
|
||||
console.log("requestTxt2Img(): about to send a fetch request")
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/txt2img/";
|
||||
console.log(full_url);
|
||||
const full_url = "http://127.0.0.1:8000/txt2img/"
|
||||
console.log(full_url)
|
||||
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
|
|
@ -47,25 +47,25 @@ async function requestTxt2Img(payload) {
|
|||
},
|
||||
body: JSON.stringify(payload),
|
||||
// "body": payload
|
||||
});
|
||||
})
|
||||
|
||||
let json = await request.json();
|
||||
console.log("requestTxt2Img json:");
|
||||
console.dir(json);
|
||||
let json = await request.json()
|
||||
console.log("requestTxt2Img json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
return {};
|
||||
console.warn(e)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
async function requestImg2Img(payload) {
|
||||
console.log("requestImg2Img(): about to send a fetch request");
|
||||
console.log("requestImg2Img(): about to send a fetch request")
|
||||
try {
|
||||
const full_url = "http://127.0.0.1:8000/img2img/";
|
||||
console.log(full_url);
|
||||
console.log("requestImg2Img payload is: ", payload);
|
||||
const full_url = "http://127.0.0.1:8000/img2img/"
|
||||
console.log(full_url)
|
||||
console.log("requestImg2Img payload is: ", payload)
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -74,67 +74,67 @@ async function requestImg2Img(payload) {
|
|||
},
|
||||
body: JSON.stringify(payload),
|
||||
// "body": payload
|
||||
});
|
||||
})
|
||||
|
||||
let json = await request.json();
|
||||
console.log("requestImg2Img json:");
|
||||
console.dir(json);
|
||||
let json = await request.json()
|
||||
console.log("requestImg2Img json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
return {};
|
||||
console.warn(e)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
async function requestProgress() {
|
||||
console.log("requestProgress: ");
|
||||
console.log("requestProgress: ")
|
||||
|
||||
const full_url =
|
||||
"http://127.0.0.1:8000/sdapi/v1/progress?skip_current_image=false";
|
||||
let request = await fetch(full_url);
|
||||
let json = await request.json();
|
||||
console.log("progress json:");
|
||||
console.dir(json);
|
||||
"http://127.0.0.1:8000/sdapi/v1/progress?skip_current_image=false"
|
||||
let request = await fetch(full_url)
|
||||
let json = await request.json()
|
||||
console.log("progress json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
async function requestGetModels() {
|
||||
console.log("requestGetModels: ");
|
||||
let json = [];
|
||||
console.log("requestGetModels: ")
|
||||
let json = []
|
||||
try {
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/sd-models";
|
||||
let request = await fetch(full_url);
|
||||
json = await request.json();
|
||||
console.log("models json:");
|
||||
console.dir(json);
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/sd-models"
|
||||
let request = await fetch(full_url)
|
||||
json = await request.json()
|
||||
console.log("models json:")
|
||||
console.dir(json)
|
||||
} catch (e) {
|
||||
console.warn(`issues requesting from ${full_url}`, e);
|
||||
console.warn(`issues requesting from ${full_url}`, e)
|
||||
}
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
async function requestGetSamplers() {
|
||||
console.log("requestGetSamplers: ");
|
||||
console.log("requestGetSamplers: ")
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/samplers";
|
||||
let request = await fetch(full_url);
|
||||
let json = await request.json();
|
||||
console.log("samplers json:");
|
||||
console.dir(json);
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/samplers"
|
||||
let request = await fetch(full_url)
|
||||
let json = await request.json()
|
||||
console.log("samplers json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
async function requestSwapModel(model_title) {
|
||||
console.log("requestSwapModel: ");
|
||||
console.log("requestSwapModel: ")
|
||||
// const full_url = 'http://127.0.0.1:8000/swapModel'
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options";
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options"
|
||||
payload = {
|
||||
sd_model_checkpoint: model_title,
|
||||
};
|
||||
}
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -143,26 +143,26 @@ async function requestSwapModel(model_title) {
|
|||
},
|
||||
body: JSON.stringify(payload),
|
||||
// "body": payload
|
||||
});
|
||||
})
|
||||
|
||||
let json = await request.json();
|
||||
let json = await request.json()
|
||||
|
||||
console.log("models json:");
|
||||
console.dir(json);
|
||||
console.log("models json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
async function requestInterrupt(model_title) {
|
||||
try {
|
||||
console.log("requestInterrupt: ");
|
||||
console.log("requestInterrupt: ")
|
||||
// const full_url = 'http://127.0.0.1:8000/swapModel'
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/interrupt";
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/interrupt"
|
||||
// payload = {
|
||||
// sd_model_checkpoint: model_title
|
||||
// }
|
||||
payload = "";
|
||||
payload = ""
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -171,49 +171,49 @@ async function requestInterrupt(model_title) {
|
|||
},
|
||||
// body: JSON.stringify(payload)
|
||||
// "body": payload
|
||||
});
|
||||
})
|
||||
|
||||
console.log("interrupt request:", request);
|
||||
let json = await request.json();
|
||||
console.log("interrupt request:", request)
|
||||
let json = await request.json()
|
||||
|
||||
console.log("interrupt json:");
|
||||
console.dir(json);
|
||||
console.log("interrupt json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function getVersionRequest() {
|
||||
// version = "v0.0.0"
|
||||
console.log("requestGetSamplers: ");
|
||||
console.log("requestGetSamplers: ")
|
||||
try {
|
||||
const full_url = "http://127.0.0.1:8000/version";
|
||||
let request = await fetch(full_url);
|
||||
let json = await request.json();
|
||||
console.log("version json:", json);
|
||||
version = json["version"];
|
||||
const full_url = "http://127.0.0.1:8000/version"
|
||||
let request = await fetch(full_url)
|
||||
let json = await request.json()
|
||||
console.log("version json:", json)
|
||||
version = json["version"]
|
||||
|
||||
return version;
|
||||
return version
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
version = "v0.0.0";
|
||||
console.warn(e)
|
||||
version = "v0.0.0"
|
||||
|
||||
return version;
|
||||
return version
|
||||
}
|
||||
}
|
||||
|
||||
async function changeSdUrl(new_sd_url) {
|
||||
// version = "v0.0.0"
|
||||
console.log("changeSdUrl: new_sd_url:", new_sd_url);
|
||||
console.log("changeSdUrl: new_sd_url:", new_sd_url)
|
||||
try {
|
||||
payload = {
|
||||
sd_url: new_sd_url,
|
||||
};
|
||||
}
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/sd_url/";
|
||||
console.log("changeSdUrl: payload: ", payload);
|
||||
const full_url = "http://127.0.0.1:8000/sd_url/"
|
||||
console.log("changeSdUrl: payload: ", payload)
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -221,13 +221,13 @@ async function changeSdUrl(new_sd_url) {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
|
||||
// let json = await request.json()
|
||||
// console.log('changeSdUrl:',json)
|
||||
console.log("changeSdUrl: request: ", request);
|
||||
console.log("changeSdUrl: request: ", request)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -238,13 +238,13 @@ async function changeSdUrl(new_sd_url) {
|
|||
// // return
|
||||
// }
|
||||
async function loadHistory(uniqueDocumentId) {
|
||||
let json = {};
|
||||
let json = {}
|
||||
try {
|
||||
payload = {
|
||||
uniqueDocumentId: uniqueDocumentId,
|
||||
};
|
||||
}
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/history/load";
|
||||
const full_url = "http://127.0.0.1:8000/history/load"
|
||||
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
|
|
@ -253,24 +253,24 @@ async function loadHistory(uniqueDocumentId) {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
|
||||
json = await request.json();
|
||||
console.log("loadHistory:", json);
|
||||
json = await request.json()
|
||||
console.log("loadHistory:", json)
|
||||
// console.log('loadPromptShortcut: request: ',request)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
|
||||
return [json["image_paths"], json["metadata_jsons"]];
|
||||
return [json["image_paths"], json["metadata_jsons"]]
|
||||
}
|
||||
async function loadPromptShortcut() {
|
||||
// console.log('loadPromptShortcut:')
|
||||
let json = {};
|
||||
let json = {}
|
||||
try {
|
||||
payload = {};
|
||||
payload = {}
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/prompt_shortcut/load";
|
||||
const full_url = "http://127.0.0.1:8000/prompt_shortcut/load"
|
||||
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
|
|
@ -279,25 +279,25 @@ async function loadPromptShortcut() {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
|
||||
json = await request.json();
|
||||
console.log("loadPromptShortcut:", json);
|
||||
json = await request.json()
|
||||
console.log("loadPromptShortcut:", json)
|
||||
// console.log('loadPromptShortcut: request: ',request)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
|
||||
return json["prompt_shortcut"];
|
||||
return json["prompt_shortcut"]
|
||||
}
|
||||
|
||||
async function savePromptShortcut(prompt_shortcut) {
|
||||
// console.log('loadPromptShortcut:')
|
||||
let json = {};
|
||||
let json = {}
|
||||
try {
|
||||
payload = { prompt_shortcut: prompt_shortcut };
|
||||
payload = { prompt_shortcut: prompt_shortcut }
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/prompt_shortcut/save";
|
||||
const full_url = "http://127.0.0.1:8000/prompt_shortcut/save"
|
||||
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
|
|
@ -306,23 +306,23 @@ async function savePromptShortcut(prompt_shortcut) {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
|
||||
json = await request.json();
|
||||
console.log("savePromptShortcut:", json);
|
||||
json = await request.json()
|
||||
console.log("savePromptShortcut:", json)
|
||||
// console.log('loadPromptShortcut: request: ',request)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
|
||||
return json["prompt_shortcut"];
|
||||
return json["prompt_shortcut"]
|
||||
}
|
||||
async function setInpaintMaskWeight(value) {
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options";
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options"
|
||||
try {
|
||||
payload = {
|
||||
inpainting_mask_weight: value,
|
||||
};
|
||||
}
|
||||
await fetch(full_url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -330,49 +330,49 @@ async function setInpaintMaskWeight(value) {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function requestGetConfig() {
|
||||
console.log("requestGetConfig: ");
|
||||
let json = [];
|
||||
const full_url = "http://127.0.0.1:8000/config";
|
||||
console.log("requestGetConfig: ")
|
||||
let json = []
|
||||
const full_url = "http://127.0.0.1:8000/config"
|
||||
try {
|
||||
let request = await fetch(full_url);
|
||||
json = await request.json();
|
||||
console.log("models json:");
|
||||
console.dir(json);
|
||||
let request = await fetch(full_url)
|
||||
json = await request.json()
|
||||
console.log("models json:")
|
||||
console.dir(json)
|
||||
} catch (e) {
|
||||
console.warn(`issues requesting from ${full_url}`, e);
|
||||
console.warn(`issues requesting from ${full_url}`, e)
|
||||
}
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
async function requestGetOptions() {
|
||||
console.log("requestGetOptions: ");
|
||||
let json = [];
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options";
|
||||
console.log("requestGetOptions: ")
|
||||
let json = []
|
||||
const full_url = "http://127.0.0.1:8000/sdapi/v1/options"
|
||||
try {
|
||||
let request = await fetch(full_url);
|
||||
json = await request.json();
|
||||
console.log("models json:");
|
||||
console.dir(json);
|
||||
let request = await fetch(full_url)
|
||||
json = await request.json()
|
||||
console.log("models json:")
|
||||
console.dir(json)
|
||||
} catch (e) {
|
||||
console.warn(`issues requesting from ${full_url}`, e);
|
||||
console.warn(`issues requesting from ${full_url}`, e)
|
||||
}
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
async function imageSearch(keywords) {
|
||||
let json = {};
|
||||
let json = {}
|
||||
try {
|
||||
payload = {
|
||||
keywords: keywords,
|
||||
};
|
||||
}
|
||||
|
||||
const full_url = "http://127.0.0.1:8000/search/image/";
|
||||
const full_url = "http://127.0.0.1:8000/search/image/"
|
||||
|
||||
let request = await fetch(full_url, {
|
||||
method: "POST",
|
||||
|
|
@ -381,16 +381,16 @@ async function imageSearch(keywords) {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
})
|
||||
|
||||
json = await request.json();
|
||||
console.log("imageSearch:", json);
|
||||
json = await request.json()
|
||||
console.log("imageSearch:", json)
|
||||
|
||||
return json["images"];
|
||||
return json["images"]
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -411,4 +411,4 @@ module.exports = {
|
|||
requestGetConfig,
|
||||
requestGetOptions,
|
||||
imageSearch,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
30
selection.js
30
selection.js
|
|
@ -10,47 +10,47 @@ function finalWidthHeight(
|
|||
// const selectionWidth = 256
|
||||
// const selectionHeight = 1000
|
||||
|
||||
let finalWidth = 0;
|
||||
let finalHeight = 0;
|
||||
let finalWidth = 0
|
||||
let finalHeight = 0
|
||||
|
||||
if (selectionWidth <= selectionHeight) {
|
||||
//do operation on the smaller dimension
|
||||
const scaleRatio = selectionWidth / minWidth;
|
||||
const scaleRatio = selectionWidth / minWidth
|
||||
|
||||
finalWidth = minWidth;
|
||||
finalHeight = selectionHeight / scaleRatio;
|
||||
finalWidth = minWidth
|
||||
finalHeight = selectionHeight / scaleRatio
|
||||
} else {
|
||||
const scaleRatio = selectionHeight / minHeight;
|
||||
const scaleRatio = selectionHeight / minHeight
|
||||
|
||||
finalHeight = minHeight;
|
||||
finalWidth = selectionWidth / scaleRatio;
|
||||
finalHeight = minHeight
|
||||
finalWidth = selectionWidth / scaleRatio
|
||||
}
|
||||
return [finalWidth, finalHeight];
|
||||
return [finalWidth, finalHeight]
|
||||
}
|
||||
|
||||
async function selectionToFinalWidthHeight() {
|
||||
const { getSelectionInfoExe } = require("./psapi");
|
||||
const { getSelectionInfoExe } = require("./psapi")
|
||||
try {
|
||||
const selectionInfo = await getSelectionInfoExe();
|
||||
const selectionInfo = await getSelectionInfoExe()
|
||||
const [finalWidth, finalHeight] = finalWidthHeight(
|
||||
selectionInfo.width,
|
||||
selectionInfo.height,
|
||||
512,
|
||||
512
|
||||
);
|
||||
)
|
||||
|
||||
return [
|
||||
parseInt(finalWidth),
|
||||
parseInt(finalHeight),
|
||||
selectionInfo.width,
|
||||
selectionInfo.height,
|
||||
];
|
||||
]
|
||||
} catch (e) {
|
||||
console.warn("you need a rectangular selection", e);
|
||||
console.warn("you need a rectangular selection", e)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
finalWidthHeight,
|
||||
selectionToFinalWidthHeight,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
////// Start Prompt//////////
|
||||
|
||||
function getPrompt() {
|
||||
const prompt = document.getElementById("taPrompt").value;
|
||||
return prompt;
|
||||
const prompt = document.getElementById("taPrompt").value
|
||||
return prompt
|
||||
}
|
||||
|
||||
function autoFillInPrompt(prompt_value) {
|
||||
document.getElementById("taPrompt").value = prompt_value;
|
||||
document.getElementById("taPrompt").value = prompt_value
|
||||
}
|
||||
|
||||
////// End Prompt//////////
|
||||
|
|
@ -14,12 +14,12 @@ function autoFillInPrompt(prompt_value) {
|
|||
////// Start Negative Prompt//////////
|
||||
|
||||
function getNegativePrompt() {
|
||||
const negative_prompt = document.getElementById("taNegativePrompt").value;
|
||||
return negative_prompt;
|
||||
const negative_prompt = document.getElementById("taNegativePrompt").value
|
||||
return negative_prompt
|
||||
}
|
||||
|
||||
function autoFillInNegativePrompt(negative_prompt_value) {
|
||||
document.getElementById("taNegativePrompt").value = negative_prompt_value;
|
||||
document.getElementById("taNegativePrompt").value = negative_prompt_value
|
||||
}
|
||||
|
||||
////// End Negative Prompt//////////
|
||||
|
|
@ -27,63 +27,63 @@ function autoFillInNegativePrompt(negative_prompt_value) {
|
|||
////// Start Width//////////
|
||||
|
||||
document.getElementById("slWidth").addEventListener("input", (evt) => {
|
||||
const width = evt.target.value * 64;
|
||||
document.getElementById("lWidth").textContent = width;
|
||||
});
|
||||
const width = evt.target.value * 64
|
||||
document.getElementById("lWidth").textContent = width
|
||||
})
|
||||
|
||||
function getWidth() {
|
||||
slider_width = document.getElementById("slWidth").value;
|
||||
const width = slider_width * 64;
|
||||
return width;
|
||||
slider_width = document.getElementById("slWidth").value
|
||||
const width = slider_width * 64
|
||||
return width
|
||||
}
|
||||
|
||||
function getHrWidth() {
|
||||
slider_width = document.getElementById("hrWidth").value;
|
||||
const width = slider_width * 64;
|
||||
return width;
|
||||
slider_width = document.getElementById("hrWidth").value
|
||||
const width = slider_width * 64
|
||||
return width
|
||||
}
|
||||
|
||||
function getHrHeight() {
|
||||
slider_width = document.getElementById("hrHeight").value;
|
||||
const width = slider_width * 64;
|
||||
return width;
|
||||
slider_width = document.getElementById("hrHeight").value
|
||||
const width = slider_width * 64
|
||||
return width
|
||||
}
|
||||
function autoFillInWidth(width_value) {
|
||||
document.getElementById("slWidth").value = `${width_value / 64}`;
|
||||
document.getElementById("slWidth").value = `${width_value / 64}`
|
||||
//update the label
|
||||
document.getElementById("lWidth").innerHTML = `${width_value}`;
|
||||
document.getElementById("lWidth").innerHTML = `${width_value}`
|
||||
}
|
||||
////// End Width//////////
|
||||
|
||||
////// Start Height//////////
|
||||
|
||||
document.getElementById("slHeight").addEventListener("input", (evt) => {
|
||||
const height = evt.target.value * 64;
|
||||
document.getElementById("lHeight").textContent = height;
|
||||
});
|
||||
const height = evt.target.value * 64
|
||||
document.getElementById("lHeight").textContent = height
|
||||
})
|
||||
|
||||
function getHeight() {
|
||||
slider_value = document.getElementById("slHeight").value;
|
||||
const height = slider_value * 64;
|
||||
return height;
|
||||
slider_value = document.getElementById("slHeight").value
|
||||
const height = slider_value * 64
|
||||
return height
|
||||
}
|
||||
|
||||
function autoFillInHeight(height_value) {
|
||||
document.getElementById("slHeight").value = `${height_value / 64}`;
|
||||
document.getElementById("slHeight").value = `${height_value / 64}`
|
||||
//update the label
|
||||
document.getElementById("lHeight").innerHTML = `${height_value}`;
|
||||
document.getElementById("lHeight").innerHTML = `${height_value}`
|
||||
}
|
||||
|
||||
function autoFillInHRHeight(height_value) {
|
||||
document.getElementById("hrHeight").value = `${height_value / 64}`;
|
||||
document.getElementById("hrHeight").value = `${height_value / 64}`
|
||||
//update the label
|
||||
document.getElementById("hHeight").innerHTML = `${height_value}`;
|
||||
document.getElementById("hHeight").innerHTML = `${height_value}`
|
||||
}
|
||||
|
||||
function autoFillInHRWidth(height_value) {
|
||||
document.getElementById("hrWidth").value = `${height_value / 64}`;
|
||||
document.getElementById("hrWidth").value = `${height_value / 64}`
|
||||
//update the label
|
||||
document.getElementById("hWidth").innerHTML = `${height_value}`;
|
||||
document.getElementById("hWidth").innerHTML = `${height_value}`
|
||||
}
|
||||
|
||||
////// End Height//////////
|
||||
|
|
@ -92,16 +92,16 @@ function autoFillInHRWidth(height_value) {
|
|||
document
|
||||
.querySelector("#slDenoisingStrength")
|
||||
.addEventListener("input", (evt) => {
|
||||
const label_value = evt.target.value / 100;
|
||||
const label_value = evt.target.value / 100
|
||||
// console.log("label_value: ", label_value)
|
||||
document.getElementById("lDenoisingStrength").innerHTML = `${label_value}`;
|
||||
});
|
||||
document.getElementById("lDenoisingStrength").innerHTML = `${label_value}`
|
||||
})
|
||||
|
||||
//get the value that is relevant to stable diffusion
|
||||
function getDenoisingStrength() {
|
||||
const slider_value = document.getElementById("slDenoisingStrength").value;
|
||||
const denoising_strength_value = slider_value / 100.0;
|
||||
return denoising_strength_value;
|
||||
const slider_value = document.getElementById("slDenoisingStrength").value
|
||||
const denoising_strength_value = slider_value / 100.0
|
||||
return denoising_strength_value
|
||||
}
|
||||
|
||||
// display the value the user need to see in all elements related to denoising strength attribute
|
||||
|
|
@ -110,11 +110,11 @@ function autoFillInDenoisingStrength(denoising_strength_value) {
|
|||
//update the slider
|
||||
document.getElementById("slDenoisingStrength").value = `${
|
||||
denoising_strength_value * 100
|
||||
}`;
|
||||
}`
|
||||
//update the label
|
||||
document.getElementById(
|
||||
"lDenoisingStrength"
|
||||
).innerHTML = `${denoising_strength_value}`;
|
||||
).innerHTML = `${denoising_strength_value}`
|
||||
}
|
||||
|
||||
////// End Denoising Strength//////////
|
||||
|
|
@ -122,65 +122,65 @@ function autoFillInDenoisingStrength(denoising_strength_value) {
|
|||
////// Start Hi Res Fix//////////
|
||||
|
||||
document.getElementById("chInpaintFullRes").addEventListener("click", (ev) => {
|
||||
const inpaint_padding_slider = document.getElementById("slInpaintPadding");
|
||||
const inpaint_padding_slider = document.getElementById("slInpaintPadding")
|
||||
|
||||
if (ev.target.checked) {
|
||||
inpaint_padding_slider.style.display = "block";
|
||||
inpaint_padding_slider.style.display = "block"
|
||||
} else {
|
||||
inpaint_padding_slider.style.display = "none";
|
||||
inpaint_padding_slider.style.display = "none"
|
||||
}
|
||||
});
|
||||
})
|
||||
document.getElementById("chHiResFixs").addEventListener("click", (ev) => {
|
||||
const container = document.getElementById("hi-res-sliders-container");
|
||||
const container = document.getElementById("hi-res-sliders-container")
|
||||
|
||||
if (ev.target.checked) {
|
||||
container.style.display = "flex";
|
||||
container.style.display = "flex"
|
||||
} else {
|
||||
container.style.display = "none";
|
||||
container.style.display = "none"
|
||||
}
|
||||
});
|
||||
})
|
||||
//get the value that is relevant to stable diffusion
|
||||
function getHiResFixs() {
|
||||
const isChecked = document.getElementById("chHiResFixs").checked;
|
||||
return isChecked;
|
||||
const isChecked = document.getElementById("chHiResFixs").checked
|
||||
return isChecked
|
||||
}
|
||||
|
||||
function setHiResFixs(isChecked) {
|
||||
document.getElementById("chHiResFixs").checked = isChecked;
|
||||
document.getElementById("chHiResFixs").checked = isChecked
|
||||
}
|
||||
|
||||
function sliderAddEventListener(slider_id, label_id, multiplier) {
|
||||
document.getElementById(slider_id).addEventListener("input", (evt) => {
|
||||
const sd_value = evt.target.value * multiplier; // convert slider value to SD ready value
|
||||
document.getElementById(label_id).textContent = Number(sd_value).toFixed(2);
|
||||
});
|
||||
const sd_value = evt.target.value * multiplier // convert slider value to SD ready value
|
||||
document.getElementById(label_id).textContent = Number(sd_value).toFixed(2)
|
||||
})
|
||||
}
|
||||
|
||||
//get the stable diffusion ready value from the slider with "slider_id"
|
||||
function getSliderSdValue(slider_id, multiplier) {
|
||||
const slider_value = document.getElementById(slider_id).value;
|
||||
const sd_value = slider_value * multiplier;
|
||||
return sd_value;
|
||||
const slider_value = document.getElementById(slider_id).value
|
||||
const sd_value = slider_value * multiplier
|
||||
return sd_value
|
||||
}
|
||||
function autoFillInSliderUi(sd_value, slider_id, label_id, multiplier) {
|
||||
//update the slider
|
||||
document.getElementById(slider_id).value = `${sd_value * multiplier}`;
|
||||
document.getElementById(slider_id).value = `${sd_value * multiplier}`
|
||||
//update the label
|
||||
document.getElementById(label_id).innerHTML = `${sd_value}`;
|
||||
document.getElementById(label_id).innerHTML = `${sd_value}`
|
||||
}
|
||||
|
||||
//hrWidth is from [1 to 32] * 64 => [64 to 2048]
|
||||
sliderAddEventListener("hrWidth", "hWidth", 64);
|
||||
sliderAddEventListener("hrHeight", "hHeight", 64);
|
||||
sliderAddEventListener("hrWidth", "hWidth", 64)
|
||||
sliderAddEventListener("hrHeight", "hHeight", 64)
|
||||
|
||||
//convert hrDenoisingStrength from [1, 100] * 0.01 => [0.01 to 1]
|
||||
sliderAddEventListener("hrDenoisingStrength", "hDenoisingStrength", 0.01);
|
||||
sliderAddEventListener("hrDenoisingStrength", "hDenoisingStrength", 0.01)
|
||||
|
||||
function autoFillInHiResFixs(firstphase_width, firstphase_height) {
|
||||
//update the firstphase width slider and label
|
||||
autoFillInSliderUi(firstphase_width, "hrWidth", "hWidth", 1.0 / 64);
|
||||
autoFillInSliderUi(firstphase_width, "hrWidth", "hWidth", 1.0 / 64)
|
||||
//update the firstphase height slider and label
|
||||
autoFillInSliderUi(firstphase_height, "hrHeight", "hHeight", 1.0 / 64);
|
||||
autoFillInSliderUi(firstphase_height, "hrHeight", "hHeight", 1.0 / 64)
|
||||
}
|
||||
////// End Hi Res Fix//////////
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ function autoFillInInpaintMaskWeight(sd_value) {
|
|||
"slInpaintingMaskWeight",
|
||||
"lInpaintingMaskWeight",
|
||||
100
|
||||
);
|
||||
)
|
||||
}
|
||||
////// End Inpaint Mask Weight//////////
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ function unCheckAllSamplers() {
|
|||
document
|
||||
.getElementsByClassName("rbSampler")
|
||||
|
||||
.forEach((e) => e.removeAttribute("checked"));
|
||||
.forEach((e) => e.removeAttribute("checked"))
|
||||
}
|
||||
|
||||
function getSamplerElementByName(sampler_name) {
|
||||
|
|
@ -211,10 +211,10 @@ function getSamplerElementByName(sampler_name) {
|
|||
//convert htmlCollection into an array, then user filter to get the radio button with the value equals to sampler_name
|
||||
const sampler_element = [
|
||||
...document.getElementsByClassName("rbSampler"),
|
||||
].filter((e) => e.value == sampler_name)[0];
|
||||
return sampler_element;
|
||||
].filter((e) => e.value == sampler_name)[0]
|
||||
return sampler_element
|
||||
} catch (e) {
|
||||
console.warn(`Sampler '${sampler_name}' not found ${e}`);
|
||||
console.warn(`Sampler '${sampler_name}' not found ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -223,21 +223,21 @@ function getCheckedSamplerName() {
|
|||
//return the name of the first checked sampler
|
||||
return [...document.getElementsByClassName("rbSampler")].filter(
|
||||
(e) => e.checked == true
|
||||
)[0].value;
|
||||
)[0].value
|
||||
}
|
||||
function getMode() {
|
||||
return [...document.getElementsByClassName("rbMode")].filter(
|
||||
(e) => e.checked == true
|
||||
)[0].value;
|
||||
)[0].value
|
||||
}
|
||||
|
||||
function checkSampler(sampler_name) {
|
||||
sampler_element = getSamplerElementByName(sampler_name);
|
||||
sampler_element.checked = true;
|
||||
sampler_element = getSamplerElementByName(sampler_name)
|
||||
sampler_element.checked = true
|
||||
}
|
||||
function autoFillInSampler(sampler_name) {
|
||||
// unCheckAllSamplers()
|
||||
checkSampler(sampler_name);
|
||||
checkSampler(sampler_name)
|
||||
}
|
||||
////// End Samplers//////////
|
||||
|
||||
|
|
@ -249,10 +249,10 @@ function getModelElementByHash(model_hash) {
|
|||
//return the first model menu item element with model_hash
|
||||
const model_element = [
|
||||
...document.getElementsByClassName("mModelMenuItem"),
|
||||
].filter((e) => e.dataset.model_hash == model_hash)[0];
|
||||
return model_element;
|
||||
].filter((e) => e.dataset.model_hash == model_hash)[0]
|
||||
return model_element
|
||||
} catch (e) {
|
||||
console.warn(`Model '${model_hash}' not found ${e}`);
|
||||
console.warn(`Model '${model_hash}' not found ${e}`)
|
||||
}
|
||||
}
|
||||
function getModelHashByTitle(model_title) {
|
||||
|
|
@ -260,9 +260,9 @@ function getModelHashByTitle(model_title) {
|
|||
try {
|
||||
return [...document.getElementsByClassName("mModelMenuItem")].filter(
|
||||
(e) => e.dataset.model_title == model_title
|
||||
)[0].dataset.model_hash;
|
||||
)[0].dataset.model_hash
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -271,60 +271,60 @@ function getSelectedModelHash() {
|
|||
try {
|
||||
return [...document.getElementsByClassName("mModelMenuItem")].filter(
|
||||
(e) => e.selected == true
|
||||
)[0].dataset.model_hash;
|
||||
)[0].dataset.model_hash
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
function selectModelUi(model_hash) {
|
||||
model_element = getModelElementByHash(model_hash);
|
||||
model_element.selected = true;
|
||||
model_element = getModelElementByHash(model_hash)
|
||||
model_element.selected = true
|
||||
}
|
||||
|
||||
function autoFillInModel(model_hash) {
|
||||
// unCheckAllSamplers()
|
||||
model_element = getModelElementByHash(model_hash);
|
||||
selectModelUi(model_hash);
|
||||
model_element = getModelElementByHash(model_hash)
|
||||
selectModelUi(model_hash)
|
||||
// model_element.
|
||||
const model_title = model_element.dataset.model_title;
|
||||
return model_title;
|
||||
const model_title = model_element.dataset.model_title
|
||||
return model_title
|
||||
}
|
||||
////// End Models//////////
|
||||
|
||||
////// Start Init Image && Init Image Mask//////////
|
||||
|
||||
function getInitImageElement() {
|
||||
const ini_image_element = document.getElementById("init_image");
|
||||
return ini_image_element;
|
||||
const ini_image_element = document.getElementById("init_image")
|
||||
return ini_image_element
|
||||
}
|
||||
function setInitImageSrc(image_src) {
|
||||
const ini_image_element = getInitImageElement();
|
||||
ini_image_element.src = image_src;
|
||||
const ini_image_element = getInitImageElement()
|
||||
ini_image_element.src = image_src
|
||||
}
|
||||
|
||||
function getInitImageMaskElement() {
|
||||
const ini_image_mask_element = document.getElementById("init_image_mask");
|
||||
return ini_image_mask_element;
|
||||
const ini_image_mask_element = document.getElementById("init_image_mask")
|
||||
return ini_image_mask_element
|
||||
}
|
||||
function setInitImageMaskSrc(image_src) {
|
||||
const ini_image_mask_element = getInitImageMaskElement();
|
||||
ini_image_mask_element.src = image_src;
|
||||
const ini_image_mask_element = getInitImageMaskElement()
|
||||
ini_image_mask_element.src = image_src
|
||||
}
|
||||
////// End Init Image && Init Image Mask//////////
|
||||
|
||||
////// Start Generate Buttons //////////
|
||||
|
||||
function getGenerateButtonsElements() {
|
||||
generate_buttons = [...document.getElementsByClassName("btnGenerateClass")];
|
||||
return generate_buttons;
|
||||
generate_buttons = [...document.getElementsByClassName("btnGenerateClass")]
|
||||
return generate_buttons
|
||||
}
|
||||
function setGenerateButtonsColor(addClassName, removeClassName) {
|
||||
const buttons = getGenerateButtonsElements();
|
||||
const buttons = getGenerateButtonsElements()
|
||||
buttons.forEach((button) => {
|
||||
button.classList.add(addClassName);
|
||||
button.classList.remove(removeClassName);
|
||||
});
|
||||
button.classList.add(addClassName)
|
||||
button.classList.remove(removeClassName)
|
||||
})
|
||||
}
|
||||
|
||||
////// End Generate Buttons //////////
|
||||
|
|
@ -332,12 +332,12 @@ function setGenerateButtonsColor(addClassName, removeClassName) {
|
|||
////// Start Servers Status //////////
|
||||
|
||||
function setAutomaticStatus(newStatusClass, oldStatusClass) {
|
||||
document.getElementById("automaticStatus").classList.add(newStatusClass);
|
||||
document.getElementById("automaticStatus").classList.remove(oldStatusClass);
|
||||
document.getElementById("automaticStatus").classList.add(newStatusClass)
|
||||
document.getElementById("automaticStatus").classList.remove(oldStatusClass)
|
||||
}
|
||||
function setProxyServerStatus(newStatusClass, oldStatusClass) {
|
||||
document.getElementById("proxyServerStatus").classList.add(newStatusClass);
|
||||
document.getElementById("proxyServerStatus").classList.remove(oldStatusClass);
|
||||
document.getElementById("proxyServerStatus").classList.add(newStatusClass)
|
||||
document.getElementById("proxyServerStatus").classList.remove(oldStatusClass)
|
||||
}
|
||||
////// End Servers Status //////////
|
||||
|
||||
|
|
@ -365,67 +365,67 @@ const defaultSettings = {
|
|||
seed: -1,
|
||||
samplers: null,
|
||||
mask_content: null,
|
||||
};
|
||||
}
|
||||
|
||||
document.getElementById("btnResetSettings").addEventListener("click", () => {
|
||||
autoFillDefaultSettings(defaultSettings);
|
||||
});
|
||||
autoFillDefaultSettings(defaultSettings)
|
||||
})
|
||||
document.getElementById("btnSnapshot").addEventListener("click", async () => {
|
||||
await psapi.snapshot_layerExe();
|
||||
});
|
||||
await psapi.snapshot_layerExe()
|
||||
})
|
||||
|
||||
function getBatchNumber() {
|
||||
return document.getElementById("tiNumberOfImages").value;
|
||||
return document.getElementById("tiNumberOfImages").value
|
||||
}
|
||||
function autoFillInBatchNumber(batch_number) {
|
||||
document.getElementById("tiNumberOfImages").value = String(batch_number);
|
||||
document.getElementById("tiNumberOfImages").value = String(batch_number)
|
||||
}
|
||||
|
||||
function getSteps() {
|
||||
return document.getElementById("tiNumberOfSteps").value;
|
||||
return document.getElementById("tiNumberOfSteps").value
|
||||
}
|
||||
function autoFillInSteps(steps) {
|
||||
document.getElementById("tiNumberOfSteps").value = String(steps);
|
||||
document.getElementById("tiNumberOfSteps").value = String(steps)
|
||||
}
|
||||
function autoFillDefaultSettings(default_settings) {
|
||||
autoFillSettings(default_settings);
|
||||
autoFillSettings(default_settings)
|
||||
}
|
||||
|
||||
function setCFG(cfg_value) {
|
||||
document.getElementById("slCfgScale").value = cfg_value;
|
||||
document.getElementById("slCfgScale").value = cfg_value
|
||||
}
|
||||
function getCFG() {
|
||||
return document.getElementById("slCfgScale").value;
|
||||
return document.getElementById("slCfgScale").value
|
||||
}
|
||||
|
||||
function autoFillSettings(settings) {
|
||||
try {
|
||||
//reset all UI settings except model selection and sampler selection
|
||||
autoFillInPrompt(settings["positive_prompt"]);
|
||||
autoFillInNegativePrompt(settings["negative_prompt"]);
|
||||
autoFillInBatchNumber(settings["batch_number"]);
|
||||
autoFillInSteps(settings["steps"]);
|
||||
autoFillInWidth(settings["width"]);
|
||||
autoFillInHeight(settings["height"]);
|
||||
autoFillInPrompt(settings["positive_prompt"])
|
||||
autoFillInNegativePrompt(settings["negative_prompt"])
|
||||
autoFillInBatchNumber(settings["batch_number"])
|
||||
autoFillInSteps(settings["steps"])
|
||||
autoFillInWidth(settings["width"])
|
||||
autoFillInHeight(settings["height"])
|
||||
autoFillInHiResFixs(
|
||||
settings["firstphase_width"],
|
||||
settings["firstphase_height"]
|
||||
);
|
||||
document.getElementById("slCfgScale").value = settings["cfg"];
|
||||
autoFillInDenoisingStrength(settings["denoising_strength"]);
|
||||
)
|
||||
document.getElementById("slCfgScale").value = settings["cfg"]
|
||||
autoFillInDenoisingStrength(settings["denoising_strength"])
|
||||
autoFillInSliderUi(
|
||||
settings["hi_res_denoising_strength"],
|
||||
"hrDenoisingStrength",
|
||||
"hDenoisingStrength",
|
||||
100
|
||||
);
|
||||
document.getElementById("slMaskBlur").value = settings["mask_blur"];
|
||||
)
|
||||
document.getElementById("slMaskBlur").value = settings["mask_blur"]
|
||||
document.getElementById("chInpaintFullRes").checked =
|
||||
settings["inpaint_at_full_res"];
|
||||
setHiResFixs(settings["hi_res_fix"]);
|
||||
document.getElementById("tiSeed").value = String(settings["seed"]);
|
||||
settings["inpaint_at_full_res"]
|
||||
setHiResFixs(settings["hi_res_fix"])
|
||||
document.getElementById("tiSeed").value = String(settings["seed"])
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
////// End Reset Settings Button //////////
|
||||
|
|
@ -433,62 +433,62 @@ function autoFillSettings(settings) {
|
|||
function getMaskBlur() {
|
||||
const isDisabled = document
|
||||
.getElementById("slMaskBlur")
|
||||
.hasAttribute("disabled");
|
||||
let mask_blur = 0;
|
||||
.hasAttribute("disabled")
|
||||
let mask_blur = 0
|
||||
if (isDisabled) {
|
||||
mask_blur = 0;
|
||||
mask_blur = 0
|
||||
} else {
|
||||
mask_blur = document.getElementById("slMaskBlur").value;
|
||||
mask_blur = document.getElementById("slMaskBlur").value
|
||||
}
|
||||
return mask_blur;
|
||||
return mask_blur
|
||||
}
|
||||
function getUseSharpMask() {
|
||||
const isChecked = document.getElementById("chUseSharpMask").checked;
|
||||
return isChecked;
|
||||
const isChecked = document.getElementById("chUseSharpMask").checked
|
||||
return isChecked
|
||||
}
|
||||
document.getElementById("chUseSharpMask").addEventListener("change", (ev) => {
|
||||
const isChecked = ev.target.checked;
|
||||
const isChecked = ev.target.checked
|
||||
if (isChecked) {
|
||||
document.getElementById("slMaskBlur").setAttribute("disabled");
|
||||
document.getElementById("slMaskBlur").setAttribute("disabled")
|
||||
} else {
|
||||
document.getElementById("slMaskBlur").removeAttribute("disabled");
|
||||
document.getElementById("slMaskBlur").removeAttribute("disabled")
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
document.getElementById("chUseSmartObject").addEventListener("change", (ev) => {
|
||||
const isChecked = ev.target.checked;
|
||||
const isChecked = ev.target.checked
|
||||
if (isChecked) {
|
||||
g_b_use_smart_object = true;
|
||||
g_b_use_smart_object = true
|
||||
} else {
|
||||
g_b_use_smart_object = false;
|
||||
g_b_use_smart_object = false
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
function getPromptShortcut() {
|
||||
//read json string
|
||||
//converted into json object
|
||||
const prompt_shortcut_string =
|
||||
document.getElementById("taPromptShortcut").value;
|
||||
const prompt_shortcut = JSON.parse(prompt_shortcut_string);
|
||||
return prompt_shortcut;
|
||||
document.getElementById("taPromptShortcut").value
|
||||
const prompt_shortcut = JSON.parse(prompt_shortcut_string)
|
||||
return prompt_shortcut
|
||||
}
|
||||
function setPromptShortcut(prompt_shortcut) {
|
||||
//prompt_shortcut is json object
|
||||
//convert it into pretty json string and save it in the prompt shortcut textarea
|
||||
var JSONInPrettyFormat = JSON.stringify(prompt_shortcut, undefined, 7);
|
||||
document.getElementById("taPromptShortcut").value = JSONInPrettyFormat;
|
||||
var JSONInPrettyFormat = JSON.stringify(prompt_shortcut, undefined, 7)
|
||||
document.getElementById("taPromptShortcut").value = JSONInPrettyFormat
|
||||
}
|
||||
|
||||
////start selection mode/////
|
||||
function getSelectionMode() {
|
||||
return [...document.getElementsByClassName("rbSelectionMode")].filter(
|
||||
(e) => e.checked == true
|
||||
)[0].value;
|
||||
)[0].value
|
||||
}
|
||||
function getMaskContent() {
|
||||
return [...document.getElementsByClassName("rbMaskContent")].filter(
|
||||
(e) => e.checked == true
|
||||
)[0].value;
|
||||
)[0].value
|
||||
}
|
||||
function setMaskContent(value) {
|
||||
try {
|
||||
|
|
@ -497,46 +497,46 @@ function setMaskContent(value) {
|
|||
//convert htmlCollection into an array, then user filter to get the radio button with the value equals to sampler_name
|
||||
const mask_content_element = [
|
||||
...document.getElementsByClassName("rbMaskContent"),
|
||||
].filter((e) => e.value == value)[0];
|
||||
mask_content_element.checked = true;
|
||||
return mask_content_element;
|
||||
].filter((e) => e.value == value)[0]
|
||||
mask_content_element.checked = true
|
||||
return mask_content_element
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
function addHistoryButtonsHtml(img_html) {
|
||||
// Create new container element
|
||||
const container = document.createElement("div");
|
||||
const container = document.createElement("div")
|
||||
|
||||
container.className = "viewer-image-container";
|
||||
container.className = "viewer-image-container"
|
||||
|
||||
const elem = document.getElementById("svg_sp_btn");
|
||||
const elem = document.getElementById("svg_sp_btn")
|
||||
// Create a copy of it
|
||||
const clone = elem.cloneNode(true);
|
||||
const button = clone;
|
||||
button.style.display = null;
|
||||
button.removeAttribute("id");
|
||||
const clone = elem.cloneNode(true)
|
||||
const button = clone
|
||||
button.style.display = null
|
||||
button.removeAttribute("id")
|
||||
|
||||
button.setAttribute("title", "place the image on the canvas");
|
||||
button.setAttribute("title", "place the image on the canvas")
|
||||
|
||||
// Create button element
|
||||
// const button = document.createElement('sp-button');
|
||||
button.className = "viewer-image-button";
|
||||
button.className = "viewer-image-button"
|
||||
// button.innerHTML = "Button";
|
||||
|
||||
button.addEventListener("click", async () => {
|
||||
//set init image event listener, use when settion is active
|
||||
let image_path = img_html.dataset.path;
|
||||
const image_path_escape = image_path.replace(/\o/g, "/o"); //escape string "\o" in "\output"
|
||||
await placeEmbedded(image_path_escape);
|
||||
});
|
||||
let image_path = img_html.dataset.path
|
||||
const image_path_escape = image_path.replace(/\o/g, "/o") //escape string "\o" in "\output"
|
||||
await placeEmbedded(image_path_escape)
|
||||
})
|
||||
|
||||
// Append elements to container
|
||||
container.appendChild(img_html);
|
||||
container.appendChild(button);
|
||||
container.appendChild(img_html)
|
||||
container.appendChild(button)
|
||||
|
||||
return container;
|
||||
return container
|
||||
}
|
||||
|
||||
///end selection mode////
|
||||
|
|
@ -588,4 +588,4 @@ module.exports = {
|
|||
getMaskContent,
|
||||
setMaskContent,
|
||||
addHistoryButtonsHtml,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
const { batchPlay } = require("photoshop").action;
|
||||
const { executeAsModal } = require("photoshop").core;
|
||||
const { cleanLayers, getLayerIndex, selectLayers } = require("../psapi");
|
||||
const { batchPlay } = require("photoshop").action
|
||||
const { executeAsModal } = require("photoshop").core
|
||||
const { cleanLayers, getLayerIndex, selectLayers } = require("../psapi")
|
||||
|
||||
async function createNewLayerExe(layerName) {
|
||||
await executeAsModal(async () => {
|
||||
await createNewLayerCommand(layerName);
|
||||
});
|
||||
const new_layer = await app.activeDocument.activeLayers[0];
|
||||
return new_layer;
|
||||
await createNewLayerCommand(layerName)
|
||||
})
|
||||
const new_layer = await app.activeDocument.activeLayers[0]
|
||||
return new_layer
|
||||
}
|
||||
|
||||
async function createNewLayerCommand(layerName) {
|
||||
|
|
@ -15,14 +15,14 @@ async function createNewLayerCommand(layerName) {
|
|||
name: layerName,
|
||||
opacity: 100,
|
||||
mode: "normal",
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteLayers(layers) {
|
||||
try {
|
||||
await cleanLayers(layers);
|
||||
await cleanLayers(layers)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,27 +39,27 @@ async function getIndexCommand() {
|
|||
_value: "targetEnum",
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
const result = await batchPlay([command], {
|
||||
synchronousExecution: true,
|
||||
modalBehavior: "execute",
|
||||
});
|
||||
})
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
async function getIndexExe() {
|
||||
let index;
|
||||
let index
|
||||
await executeAsModal(async () => {
|
||||
index = await getIndexCommand();
|
||||
});
|
||||
index = await getIndexCommand()
|
||||
})
|
||||
|
||||
return index;
|
||||
return index
|
||||
}
|
||||
const photoshop = require("photoshop");
|
||||
const photoshop = require("photoshop")
|
||||
|
||||
const collapseFolderCommand = async (expand = false, recursive = false) => {
|
||||
let result;
|
||||
let result
|
||||
try {
|
||||
result = await batchPlay(
|
||||
[
|
||||
|
|
@ -81,23 +81,23 @@ const collapseFolderCommand = async (expand = false, recursive = false) => {
|
|||
},
|
||||
],
|
||||
{ synchronousExecution: true }
|
||||
);
|
||||
)
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error(e.message)
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return result
|
||||
}
|
||||
async function collapseFolderExe(layers, expand = false, recursive = false) {
|
||||
for (let layer of layers) {
|
||||
try {
|
||||
await executeAsModal(async () => {
|
||||
const is_visible = await layer.visible; // don't change the visiblity of the layer when collapsing
|
||||
await selectLayers([layer]);
|
||||
await collapseFolderCommand(expand, recursive);
|
||||
layer.visible = is_visible;
|
||||
});
|
||||
const is_visible = await layer.visible // don't change the visiblity of the layer when collapsing
|
||||
await selectLayers([layer])
|
||||
await collapseFolderCommand(expand, recursive)
|
||||
layer.visible = is_visible
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -107,4 +107,4 @@ module.exports = {
|
|||
deleteLayers,
|
||||
getIndexExe,
|
||||
collapseFolderExe,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ let settings = {
|
|||
seed: null,
|
||||
samplers: null,
|
||||
mask_content: null,
|
||||
};
|
||||
}
|
||||
|
||||
let LatentNoiseSettings = {
|
||||
model: null,
|
||||
|
|
@ -44,7 +44,7 @@ let LatentNoiseSettings = {
|
|||
seed: null,
|
||||
samplers: null,
|
||||
mask_content: "2",
|
||||
};
|
||||
}
|
||||
|
||||
let FillSettings = {
|
||||
model: null,
|
||||
|
|
@ -68,7 +68,7 @@ let FillSettings = {
|
|||
seed: null,
|
||||
samplers: null,
|
||||
mask_content: "0",
|
||||
};
|
||||
}
|
||||
let OriginalSettings = {
|
||||
model: null,
|
||||
prompt_shortcut: null,
|
||||
|
|
@ -91,7 +91,7 @@ let OriginalSettings = {
|
|||
seed: null,
|
||||
samplers: null,
|
||||
mask_content: "1",
|
||||
};
|
||||
}
|
||||
|
||||
function nullAllSettings() {}
|
||||
|
||||
|
|
@ -106,4 +106,4 @@ module.exports = {
|
|||
LatentNoiseSettings,
|
||||
FillSettings,
|
||||
OriginalSettings,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,74 +2,74 @@ async function requestModelsHorde() {
|
|||
//get the models list from url
|
||||
// https://stablehorde.net/api/v2/status/models
|
||||
|
||||
console.log("requestModelsHorde: ");
|
||||
console.log("requestModelsHorde: ")
|
||||
|
||||
const full_url = "https://stablehorde.net/api/v2/status/models";
|
||||
let request = await fetch(full_url);
|
||||
let json = await request.json();
|
||||
console.log("hordes models json:");
|
||||
console.dir(json);
|
||||
const full_url = "https://stablehorde.net/api/v2/status/models"
|
||||
let request = await fetch(full_url)
|
||||
let json = await request.json()
|
||||
console.log("hordes models json:")
|
||||
console.dir(json)
|
||||
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
|
||||
function addHordeModelMenuItem(model_title, model_name) {
|
||||
// console.log(model_title,model_name)
|
||||
const menu_item_element = document.createElement("sp-menu-item");
|
||||
menu_item_element.className = "mModelMenuItemHorde";
|
||||
menu_item_element.innerHTML = model_title;
|
||||
const menu_item_element = document.createElement("sp-menu-item")
|
||||
menu_item_element.className = "mModelMenuItemHorde"
|
||||
menu_item_element.innerHTML = model_title
|
||||
|
||||
menu_item_element.dataset.name = model_name;
|
||||
return menu_item_element;
|
||||
menu_item_element.dataset.name = model_name
|
||||
return menu_item_element
|
||||
}
|
||||
|
||||
async function refreshModelsHorde() {
|
||||
try {
|
||||
let g_models_horde = await requestModelsHorde();
|
||||
let g_models_horde = await requestModelsHorde()
|
||||
// const models_menu_element = document.getElementById('mModelsMenu')
|
||||
// models_menu_element.value = ""
|
||||
//(optional): sort the models
|
||||
|
||||
g_models_horde.sort(function (a, b) {
|
||||
return b.count - a.count;
|
||||
});
|
||||
return b.count - a.count
|
||||
})
|
||||
// g_models_horde = g_models_horde.sort( compareModelCounts );
|
||||
document.getElementById("mModelsMenuHorde").innerHTML = "";
|
||||
let model_item_random = addHordeModelMenuItem("Random", "Random");
|
||||
model_item_random.selected = true;
|
||||
document.getElementById("mModelsMenuHorde").appendChild(model_item_random);
|
||||
document.getElementById("mModelsMenuHorde").innerHTML = ""
|
||||
let model_item_random = addHordeModelMenuItem("Random", "Random")
|
||||
model_item_random.selected = true
|
||||
document.getElementById("mModelsMenuHorde").appendChild(model_item_random)
|
||||
for (let model of g_models_horde) {
|
||||
console.log(model.name, model.count);
|
||||
const model_html_tile = `${model.name}: ${model.count}`;
|
||||
console.log(model.name, model.count)
|
||||
const model_html_tile = `${model.name}: ${model.count}`
|
||||
const model_item_element = addHordeModelMenuItem(
|
||||
model_html_tile,
|
||||
model.name
|
||||
);
|
||||
)
|
||||
|
||||
document
|
||||
.getElementById("mModelsMenuHorde")
|
||||
.appendChild(model_item_element);
|
||||
.appendChild(model_item_element)
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
function getModelHorde() {
|
||||
return [...document.getElementsByClassName("mModelMenuItemHorde")].filter(
|
||||
(e) => e.selected == true
|
||||
)[0].dataset.name;
|
||||
)[0].dataset.name
|
||||
}
|
||||
function getUseHorde() {
|
||||
const isChecked = document.getElementById("chUseHorde").checked;
|
||||
return isChecked;
|
||||
const isChecked = document.getElementById("chUseHorde").checked
|
||||
return isChecked
|
||||
}
|
||||
function getScriptArgs() {
|
||||
const model = getModelHorde();
|
||||
const b_nsfw = document.getElementById("chUseNSFW").checked;
|
||||
const b_shared_laion = document.getElementById("chUseSharedLaion").checked;
|
||||
const model = getModelHorde()
|
||||
const b_nsfw = document.getElementById("chUseNSFW").checked
|
||||
const b_shared_laion = document.getElementById("chUseSharedLaion").checked
|
||||
|
||||
let seed_variation = document.getElementById("slSeedVariation").value;
|
||||
seed_variation = parseInt(seed_variation);
|
||||
let seed_variation = document.getElementById("slSeedVariation").value
|
||||
seed_variation = parseInt(seed_variation)
|
||||
const script_args_json = {
|
||||
model: model,
|
||||
nsfw: b_nsfw,
|
||||
|
|
@ -78,20 +78,20 @@ function getScriptArgs() {
|
|||
post_processing_1: "None",
|
||||
post_processing_2: "None",
|
||||
post_processing_3: "None",
|
||||
};
|
||||
const script_args = Object.values(script_args_json);
|
||||
return script_args;
|
||||
}
|
||||
const script_args = Object.values(script_args_json)
|
||||
return script_args
|
||||
}
|
||||
|
||||
document
|
||||
.getElementById("btnRefreshModelsHorde")
|
||||
.addEventListener("click", async () => {
|
||||
await refreshModelsHorde();
|
||||
});
|
||||
await refreshModelsHorde()
|
||||
})
|
||||
|
||||
const script_name = "Run on Stable Horde";
|
||||
const script_name = "Run on Stable Horde"
|
||||
|
||||
refreshModelsHorde(); //refresh the model when importing the script
|
||||
refreshModelsHorde() //refresh the model when importing the script
|
||||
|
||||
module.exports = {
|
||||
requestModelsHorde,
|
||||
|
|
@ -100,4 +100,4 @@ module.exports = {
|
|||
getUseHorde,
|
||||
getScriptArgs,
|
||||
script_name,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
const sdapi = require("../../sdapi");
|
||||
const sdapi = require("../../sdapi")
|
||||
|
||||
class SdConfig {
|
||||
constructor() {
|
||||
this.config; //store sd options
|
||||
this.config //store sd options
|
||||
}
|
||||
|
||||
async getConfig() {
|
||||
try {
|
||||
this.config = await sdapi.requestGetConfig();
|
||||
return this.config;
|
||||
this.config = await sdapi.requestGetConfig()
|
||||
return this.config
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
getUpscalerModels() {
|
||||
try {
|
||||
// const upscaler_comp = this.config.components.filter(comp =>comp.props.elem_id === "txt2img_hr_upscaler")[0]
|
||||
let upscaler_comp;
|
||||
console.log("this.config: ", this.config);
|
||||
let upscaler_comp
|
||||
console.log("this.config: ", this.config)
|
||||
for (let comp of this.config.components) {
|
||||
if (comp?.props?.elem_id) {
|
||||
const elem_id = comp?.props?.elem_id;
|
||||
const elem_id = comp?.props?.elem_id
|
||||
if (elem_id === "txt2img_hr_upscaler") {
|
||||
console.log("elem_id: ", elem_id);
|
||||
upscaler_comp = comp;
|
||||
break;
|
||||
console.log("elem_id: ", elem_id)
|
||||
upscaler_comp = comp
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("upscaler_comp: ", upscaler_comp);
|
||||
const upscalers = upscaler_comp.props.choices;
|
||||
console.log("upscaler_comp: ", upscaler_comp)
|
||||
const upscalers = upscaler_comp.props.choices
|
||||
|
||||
return upscalers;
|
||||
return upscalers
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SdConfig,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
const sdapi = require("../../sdapi");
|
||||
const sdapi = require("../../sdapi")
|
||||
|
||||
class SdOptions {
|
||||
constructor() {
|
||||
// this.status = false // true if we have a valid copy of sd options, false otherwise
|
||||
this.options; //store sd options
|
||||
this.options //store sd options
|
||||
}
|
||||
|
||||
async getOptions() {
|
||||
|
|
@ -16,19 +16,19 @@ class SdOptions {
|
|||
// this.status = true
|
||||
// }
|
||||
// }
|
||||
this.options = await sdapi.requestGetOptions();
|
||||
return this.options;
|
||||
this.options = await sdapi.requestGetOptions()
|
||||
return this.options
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
getCurrentModel() {
|
||||
const current_model = this.options?.sd_model_checkpoint;
|
||||
return current_model;
|
||||
const current_model = this.options?.sd_model_checkpoint
|
||||
return current_model
|
||||
}
|
||||
getInpaintingMaskWeight() {
|
||||
const inpainting_mask_weight = this.options?.inpainting_mask_weight;
|
||||
return inpainting_mask_weight;
|
||||
const inpainting_mask_weight = this.options?.inpainting_mask_weight
|
||||
return inpainting_mask_weight
|
||||
}
|
||||
}
|
||||
// const sd_options = new SdOptions()
|
||||
|
|
@ -36,4 +36,4 @@ class SdOptions {
|
|||
|
||||
module.exports = {
|
||||
SdOptions,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,93 +1,93 @@
|
|||
const { cleanLayers } = require("../psapi");
|
||||
const { cleanLayers } = require("../psapi")
|
||||
|
||||
const SessionState = {
|
||||
Active: "active",
|
||||
Inactive: "inactive",
|
||||
};
|
||||
}
|
||||
const GarbageCollectionState = {
|
||||
Accept: "accept", // accept all generated images
|
||||
Discard: "discard", //discard all generated images
|
||||
DiscardSelected: "discard_selected",
|
||||
AcceptSelected: "accept_selected", //accept_selected only chosen images
|
||||
};
|
||||
}
|
||||
|
||||
class GenerationSession {
|
||||
constructor() {
|
||||
//this should be unique session id and it also should act as the total number of sessions been created in the project
|
||||
this.id = 0;
|
||||
this.state = SessionState["Inactive"];
|
||||
this.mode = "txt2img";
|
||||
this.selectionInfo = null;
|
||||
this.isFirstGeneration = true; // only before the first generation is requested should this be true
|
||||
this.outputGroup;
|
||||
this.prevOutputGroup;
|
||||
this.isLoadingActive = false;
|
||||
this.id = 0
|
||||
this.state = SessionState["Inactive"]
|
||||
this.mode = "txt2img"
|
||||
this.selectionInfo = null
|
||||
this.isFirstGeneration = true // only before the first generation is requested should this be true
|
||||
this.outputGroup
|
||||
this.prevOutputGroup
|
||||
this.isLoadingActive = false
|
||||
}
|
||||
isActive() {
|
||||
return this.state === SessionState["Active"];
|
||||
return this.state === SessionState["Active"]
|
||||
}
|
||||
isInactive() {
|
||||
return this.state === SessionState["Inactive"];
|
||||
return this.state === SessionState["Inactive"]
|
||||
}
|
||||
activate() {
|
||||
this.state = SessionState["Active"];
|
||||
this.state = SessionState["Active"]
|
||||
}
|
||||
deactivate() {
|
||||
this.state = SessionState["Inactive"];
|
||||
this.state = SessionState["Inactive"]
|
||||
}
|
||||
name() {
|
||||
return `session - ${this.id}`;
|
||||
return `session - ${this.id}`
|
||||
}
|
||||
async startSession() {
|
||||
this.id += 1; //increment the session id for each session we start
|
||||
this.activate();
|
||||
this.isFirstGeneration = true; // only before the first generation is requested should this be true
|
||||
this.id += 1 //increment the session id for each session we start
|
||||
this.activate()
|
||||
this.isFirstGeneration = true // only before the first generation is requested should this be true
|
||||
|
||||
console.log("current session id: ", this.id);
|
||||
console.log("current session id: ", this.id)
|
||||
try {
|
||||
const session_name = this.name();
|
||||
const activeLayers = await app.activeDocument.activeLayers;
|
||||
await psapi.unselectActiveLayersExe(); // unselect all layer so the create group is place at the top of the document
|
||||
this.prevOutputGroup = this.outputGroup;
|
||||
const outputGroup = await psapi.createEmptyGroup(session_name);
|
||||
this.outputGroup = outputGroup;
|
||||
await psapi.selectLayersExe(activeLayers);
|
||||
const session_name = this.name()
|
||||
const activeLayers = await app.activeDocument.activeLayers
|
||||
await psapi.unselectActiveLayersExe() // unselect all layer so the create group is place at the top of the document
|
||||
this.prevOutputGroup = this.outputGroup
|
||||
const outputGroup = await psapi.createEmptyGroup(session_name)
|
||||
this.outputGroup = outputGroup
|
||||
await psapi.selectLayersExe(activeLayers)
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
async endSession(garbage_collection_state) {
|
||||
try {
|
||||
this.state = SessionState["Inactive"]; // end the session by deactivate it
|
||||
this.state = SessionState["Inactive"] // end the session by deactivate it
|
||||
|
||||
this.deactivate();
|
||||
this.deactivate()
|
||||
|
||||
if (garbage_collection_state === GarbageCollectionState["Accept"]) {
|
||||
await acceptAll();
|
||||
await acceptAll()
|
||||
} else if (
|
||||
garbage_collection_state === GarbageCollectionState["Discard"]
|
||||
) {
|
||||
//this should be discardAll()
|
||||
|
||||
await discardAll();
|
||||
await discardAll()
|
||||
} else if (
|
||||
garbage_collection_state === GarbageCollectionState["DiscardSelected"]
|
||||
) {
|
||||
//this should be discardAllExcept(selectedLayers)
|
||||
await discardSelected(); //this will discard what is not been highlighted
|
||||
await discardSelected() //this will discard what is not been highlighted
|
||||
} else if (
|
||||
garbage_collection_state === GarbageCollectionState["AcceptSelected"]
|
||||
) {
|
||||
//this should be discardAllExcept(selectedLayers)
|
||||
await discard(); //this will discard what is not been highlighted
|
||||
await discard() //this will discard what is not been highlighted
|
||||
}
|
||||
|
||||
//delete the old selection area
|
||||
// g_selection = {}
|
||||
|
||||
this.isFirstGeneration = true; // only before the first generation is requested should this be true
|
||||
this.isFirstGeneration = true // only before the first generation is requested should this be true
|
||||
// const is_visible = await this.outputGroup.visible
|
||||
await util_layer.collapseFolderExe([this.outputGroup], false); // close the folder group
|
||||
await util_layer.collapseFolderExe([this.outputGroup], false) // close the folder group
|
||||
// this.outputGroup.visible = is_visible
|
||||
|
||||
if (
|
||||
|
|
@ -96,12 +96,12 @@ class GenerationSession {
|
|||
) {
|
||||
//create "Mask -- Paint White to Mask -- temporary" layer if current session was inpiant and the selected session is inpaint
|
||||
// the current inpaint session ended on inpaint
|
||||
g_b_mask_layer_exist = false;
|
||||
await util_layer.deleteLayers([g_inpaint_mask_layer]);
|
||||
await createTempInpaintMaskLayer();
|
||||
g_b_mask_layer_exist = false
|
||||
await util_layer.deleteLayers([g_inpaint_mask_layer])
|
||||
await createTempInpaintMaskLayer()
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
async closePreviousOutputGroup() {
|
||||
|
|
@ -110,20 +110,20 @@ class GenerationSession {
|
|||
|
||||
if (this.prevOutputGroup) {
|
||||
// const is_visible = await this.prevOutputGroup.visible
|
||||
await util_layer.collapseFolderExe([this.prevOutputGroup], false); // close the folder group
|
||||
await util_layer.collapseFolderExe([this.prevOutputGroup], false) // close the folder group
|
||||
// and reselect the current output folder for clarity
|
||||
await psapi.selectLayersExe([this.outputGroup]);
|
||||
await psapi.selectLayersExe([this.outputGroup])
|
||||
// this.prevOutputGroup.visible = is_visible
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
isSameMode(selected_mode) {
|
||||
if (this.mode === selected_mode) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
loadLastSession() {
|
||||
//load the last session from the server
|
||||
|
|
@ -132,12 +132,12 @@ class GenerationSession {
|
|||
//all session info will be saved in a json file in the project folder
|
||||
}
|
||||
async moveToTopOfOutputGroup(layer) {
|
||||
const output_group_id = await this.outputGroup.id;
|
||||
let group_index = await psapi.getLayerIndex(output_group_id);
|
||||
const indexOffset = 1; //1 for background, 0 if no background exist
|
||||
const output_group_id = await this.outputGroup.id
|
||||
let group_index = await psapi.getLayerIndex(output_group_id)
|
||||
const indexOffset = 1 //1 for background, 0 if no background exist
|
||||
await executeAsModal(async () => {
|
||||
await psapi.moveToGroupCommand(group_index - indexOffset, layer.id);
|
||||
});
|
||||
await psapi.moveToGroupCommand(group_index - indexOffset, layer.id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,4 +145,4 @@ module.exports = {
|
|||
GenerationSession,
|
||||
GarbageCollectionState,
|
||||
SessionState,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,6 @@ const tips_json = {
|
|||
mask_expansion:
|
||||
"the larger the value the more the mask will expand, '0' means use precise masking, use in combination with the mask blur",
|
||||
mask_content_fill: "",
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { tips_json };
|
||||
module.exports = { tips_json }
|
||||
|
|
|
|||
118
utility/ui.js
118
utility/ui.js
|
|
@ -1,6 +1,6 @@
|
|||
const { loadHistory } = require("../sdapi");
|
||||
const html_manip = require("./html_manip");
|
||||
const presets = require("./presets/preset");
|
||||
const { loadHistory } = require("../sdapi")
|
||||
const html_manip = require("./html_manip")
|
||||
const presets = require("./presets/preset")
|
||||
|
||||
class UI {
|
||||
constructor() {}
|
||||
|
|
@ -10,93 +10,93 @@ class UI {
|
|||
|
||||
const accept_class_btns = Array.from(
|
||||
document.getElementsByClassName("acceptClass")
|
||||
);
|
||||
)
|
||||
|
||||
const discard_class_btns = Array.from(
|
||||
document.getElementsByClassName("discardClass")
|
||||
);
|
||||
)
|
||||
|
||||
const discard_selected_class_btns = Array.from(
|
||||
document.getElementsByClassName("discardSelectedClass")
|
||||
);
|
||||
)
|
||||
|
||||
const accept_selected_class_btns = Array.from(
|
||||
document.getElementsByClassName("acceptSelectedClass")
|
||||
);
|
||||
)
|
||||
|
||||
//show the accept and discard buttons when a new session is active
|
||||
accept_class_btns.forEach(
|
||||
(element) => (element.style.display = "inline-block")
|
||||
);
|
||||
)
|
||||
discard_class_btns.forEach(
|
||||
(element) => (element.style.display = "inline-block")
|
||||
);
|
||||
)
|
||||
discard_selected_class_btns.forEach(
|
||||
(element) => (element.style.display = "inline-block")
|
||||
);
|
||||
)
|
||||
accept_selected_class_btns.forEach(
|
||||
(element) => (element.style.display = "inline-block")
|
||||
);
|
||||
)
|
||||
|
||||
this.generateMoreUI();
|
||||
this.generateMoreUI()
|
||||
}
|
||||
onActiveSessionUI() {}
|
||||
generateModeUI(mode) {
|
||||
const generate_btns = Array.from(
|
||||
document.getElementsByClassName("btnGenerateClass")
|
||||
);
|
||||
)
|
||||
generate_btns.forEach((element) => {
|
||||
element.textContent = `Generate ${mode}`;
|
||||
});
|
||||
html_manip.setGenerateButtonsColor("generate", "generate-more");
|
||||
element.textContent = `Generate ${mode}`
|
||||
})
|
||||
html_manip.setGenerateButtonsColor("generate", "generate-more")
|
||||
}
|
||||
generateMoreUI() {
|
||||
const generate_btns = Array.from(
|
||||
document.getElementsByClassName("btnGenerateClass")
|
||||
);
|
||||
)
|
||||
generate_btns.forEach((element) => {
|
||||
element.textContent = `Generate More`;
|
||||
});
|
||||
html_manip.setGenerateButtonsColor("generate-more", "generate");
|
||||
element.textContent = `Generate More`
|
||||
})
|
||||
html_manip.setGenerateButtonsColor("generate-more", "generate")
|
||||
}
|
||||
|
||||
onEndSessionUI() {
|
||||
const accept_class_btns = Array.from(
|
||||
document.getElementsByClassName("acceptClass")
|
||||
);
|
||||
)
|
||||
|
||||
const discard_class_btns = Array.from(
|
||||
document.getElementsByClassName("discardClass")
|
||||
);
|
||||
)
|
||||
const discard_selected_class_btns = Array.from(
|
||||
document.getElementsByClassName("discardSelectedClass")
|
||||
);
|
||||
)
|
||||
|
||||
const accept_selected_class_btns = Array.from(
|
||||
//Node: change customClass to acceptSelectedClass
|
||||
document.getElementsByClassName("acceptSelectedClass")
|
||||
);
|
||||
)
|
||||
|
||||
accept_class_btns.forEach((element) => (element.style.display = "none"));
|
||||
discard_class_btns.forEach((element) => (element.style.display = "none"));
|
||||
accept_class_btns.forEach((element) => (element.style.display = "none"))
|
||||
discard_class_btns.forEach((element) => (element.style.display = "none"))
|
||||
discard_selected_class_btns.forEach(
|
||||
(element) => (element.style.display = "none")
|
||||
);
|
||||
)
|
||||
|
||||
accept_selected_class_btns.forEach(
|
||||
(element) => (element.style.display = "none")
|
||||
);
|
||||
)
|
||||
|
||||
this.generateModeUI(g_sd_mode);
|
||||
this.generateModeUI(g_sd_mode)
|
||||
}
|
||||
|
||||
setGenerateBtnText(textContent) {
|
||||
const generate_btns = Array.from(
|
||||
document.getElementsByClassName("btnGenerateClass")
|
||||
);
|
||||
)
|
||||
generate_btns.forEach((element) => {
|
||||
element.textContent = textContent;
|
||||
});
|
||||
element.textContent = textContent
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,18 +126,18 @@ class UI {
|
|||
|
||||
class UIElement {
|
||||
constructor() {
|
||||
this.name;
|
||||
this.html_elem;
|
||||
this.sd_value;
|
||||
this.name
|
||||
this.html_elem
|
||||
this.sd_value
|
||||
}
|
||||
setValue() {}
|
||||
getValue() {}
|
||||
}
|
||||
function createUIElement(getter, setter) {
|
||||
let ui_element_obj = new ui.UIElement();
|
||||
ui_element_obj.getValue = getter;
|
||||
ui_element_obj.setValue = setter;
|
||||
return ui_element_obj;
|
||||
let ui_element_obj = new ui.UIElement()
|
||||
ui_element_obj.getValue = getter
|
||||
ui_element_obj.setValue = setter
|
||||
return ui_element_obj
|
||||
}
|
||||
class UISettings {
|
||||
// get and set the settings of the ui. the stable diffusion settings not the human friendly settings
|
||||
|
|
@ -148,37 +148,37 @@ class UISettings {
|
|||
this.width = createUIElement(
|
||||
html_manip.getWidth,
|
||||
html_manip.autoFillInWidth
|
||||
);
|
||||
)
|
||||
this.height = createUIElement(
|
||||
html_manip.getHeight,
|
||||
html_manip.autoFillInHeight
|
||||
);
|
||||
)
|
||||
this.steps = createUIElement(
|
||||
html_manip.getSteps,
|
||||
html_manip.autoFillInSteps
|
||||
);
|
||||
)
|
||||
this.batch_number = createUIElement(
|
||||
html_manip.getBatchNumber,
|
||||
html_manip.autoFillInBatchNumber
|
||||
);
|
||||
)
|
||||
this.firstphase_width = createUIElement(
|
||||
html_manip.getHrWidth,
|
||||
html_manip.autoFillInHRWidth
|
||||
);
|
||||
)
|
||||
this.firstphase_height = createUIElement(
|
||||
html_manip.getHrHeight,
|
||||
html_manip.autoFillInHRHeight
|
||||
);
|
||||
this.cfg = createUIElement(html_manip.getCFG, html_manip.setCFG);
|
||||
)
|
||||
this.cfg = createUIElement(html_manip.getCFG, html_manip.setCFG)
|
||||
this.denoising_strength = createUIElement(
|
||||
html_manip.getDenoisingStrength,
|
||||
html_manip.autoFillInDenoisingStrength
|
||||
);
|
||||
)
|
||||
|
||||
this.mask_content = createUIElement(
|
||||
html_manip.getMaskContent,
|
||||
html_manip.setMaskContent
|
||||
);
|
||||
)
|
||||
this.uiElements = {
|
||||
// model: null,
|
||||
// prompt_shortcut: null,
|
||||
|
|
@ -201,17 +201,17 @@ class UISettings {
|
|||
// seed:-1,
|
||||
// samplers: null,
|
||||
mask_content: this.mask_content,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
autoFillInSettings(settings) {
|
||||
for (const [name, value] of Object.entries(settings)) {
|
||||
if (this.uiElements.hasOwnProperty(name) && value) {
|
||||
//get the values for debugging
|
||||
const old_value = this.uiElements[name].getValue();
|
||||
console.log("(name,old_value) => newValue:", name, old_value, value);
|
||||
const old_value = this.uiElements[name].getValue()
|
||||
console.log("(name,old_value) => newValue:", name, old_value, value)
|
||||
//set the value
|
||||
this.uiElements[name].setValue(value);
|
||||
this.uiElements[name].setValue(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -219,25 +219,25 @@ class UISettings {
|
|||
// const ui_settings = new UISettings()
|
||||
|
||||
function loadPreset(ui_settings, preset) {
|
||||
console.log("preset:", preset);
|
||||
ui_settings.autoFillInSettings(preset);
|
||||
console.log("preset:", preset)
|
||||
ui_settings.autoFillInSettings(preset)
|
||||
}
|
||||
|
||||
function loadLatentNoiseSettings(ui_settings) {
|
||||
loadPreset(ui_settings, presets.LatentNoiseSettings);
|
||||
loadPreset(ui_settings, presets.LatentNoiseSettings)
|
||||
}
|
||||
|
||||
function loadFillSettings(ui_settings) {
|
||||
loadPreset(ui_settings, presets.FillSettings);
|
||||
loadPreset(ui_settings, presets.FillSettings)
|
||||
}
|
||||
function loadOriginalSettings(ui_settings) {
|
||||
loadPreset(ui_settings, presets.OriginalSettings);
|
||||
loadPreset(ui_settings, presets.OriginalSettings)
|
||||
}
|
||||
let loadedPresets = {
|
||||
fill: loadFillSettings,
|
||||
original: loadOriginalSettings,
|
||||
"latent noise": loadLatentNoiseSettings,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
UI,
|
||||
|
|
@ -247,4 +247,4 @@ module.exports = {
|
|||
loadFillSettings,
|
||||
|
||||
loadedPresets,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
360
viewer.js
360
viewer.js
|
|
@ -19,39 +19,39 @@
|
|||
// * viewe()
|
||||
// * isLayerValid()
|
||||
|
||||
const psapi = require("./psapi");
|
||||
const psapi = require("./psapi")
|
||||
|
||||
const ViewerObjState = {
|
||||
Delete: "delete",
|
||||
Unlink: "unlink",
|
||||
};
|
||||
}
|
||||
|
||||
class ViewerImage {
|
||||
constructor() {
|
||||
this.img_html = null;
|
||||
this.is_highlighted = false;
|
||||
this.can_highlight = true;
|
||||
this.is_active = false; // active is a temporary highlight
|
||||
this.state = ViewerObjState["Unlink"];
|
||||
this.img_html = null
|
||||
this.is_highlighted = false
|
||||
this.can_highlight = true
|
||||
this.is_active = false // active is a temporary highlight
|
||||
this.state = ViewerObjState["Unlink"]
|
||||
|
||||
// true will delete the layers from the layer stacks when the session ends,
|
||||
// false mean use this.state to determine whither you delete the layer or not
|
||||
this.autoDelete = false;
|
||||
this.autoDelete = false
|
||||
}
|
||||
info() {
|
||||
console.log("state: ", this.state);
|
||||
console.log("state: ", this.state)
|
||||
}
|
||||
visible(visibleOn) {}
|
||||
select() {}
|
||||
isActive() {
|
||||
return this.is_active;
|
||||
return this.is_active
|
||||
}
|
||||
active(isActive) {
|
||||
if (isActive) {
|
||||
//unlink it if it's active
|
||||
// this.state = ViewerObjState['Unlink']
|
||||
|
||||
this.img_html.classList.add("viewerImgActive");
|
||||
this.img_html.classList.add("viewerImgActive")
|
||||
} else {
|
||||
if (this.getHighlight() === false) {
|
||||
// if it's not active and it's not highlighted
|
||||
|
|
@ -59,33 +59,33 @@ class ViewerImage {
|
|||
} else {
|
||||
// this.state = ViewerObjState['Unlink'] //it's not active but it's highlighted then keep it
|
||||
}
|
||||
this.img_html.classList.remove("viewerImgActive");
|
||||
this.img_html.classList.remove("viewerImgActive")
|
||||
}
|
||||
this.is_active = isActive;
|
||||
this.is_active = isActive
|
||||
}
|
||||
setAutoDelete(auto_delete) {
|
||||
this.autoDelete = auto_delete;
|
||||
this.autoDelete = auto_delete
|
||||
}
|
||||
isLayerValid() {}
|
||||
isSameLayer(layer_id) {}
|
||||
setHighlight(is_highlighted) {
|
||||
if (this.can_highlight) {
|
||||
this.is_highlighted = is_highlighted;
|
||||
this.is_highlighted = is_highlighted
|
||||
if (this.is_highlighted) {
|
||||
// this.state = ViewerObjState['Unlink']
|
||||
this.img_html.classList.add("viewerImgSelected");
|
||||
this.img_html.classList.add("viewerImgSelected")
|
||||
} else {
|
||||
this.img_html.classList.remove("viewerImgSelected");
|
||||
this.img_html.classList.remove("viewerImgSelected")
|
||||
// this.state = ViewerObjState["Delete"]
|
||||
}
|
||||
}
|
||||
}
|
||||
getHighlight() {
|
||||
return this.is_highlighted;
|
||||
return this.is_highlighted
|
||||
}
|
||||
toggleHighlight() {
|
||||
const toggle_value = !this.getHighlight();
|
||||
this.setHighlight(toggle_value);
|
||||
const toggle_value = !this.getHighlight()
|
||||
this.setHighlight(toggle_value)
|
||||
// this.is_highlighted = !this.is_highlighted
|
||||
// this.img_html.classList.toggle("viewerImgSelected")
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ class ViewerImage {
|
|||
|
||||
async delete() {
|
||||
try {
|
||||
this.img_html.remove(); //delete the img html element
|
||||
this.img_html.remove() //delete the img html element
|
||||
|
||||
//1) it's output layer // can_highlight && this.getHighlight()
|
||||
//2) it init or mask relate layers // this.autoDelete
|
||||
|
|
@ -104,15 +104,15 @@ class ViewerImage {
|
|||
//1)
|
||||
if (this.can_highlight && (this.getHighlight() || this.is_active)) {
|
||||
//keep if can be highlighted and either is highlighted or active
|
||||
this.state = ViewerObjState["Unlink"];
|
||||
this.state = ViewerObjState["Unlink"]
|
||||
} else {
|
||||
//
|
||||
this.state = ViewerObjState["Delete"];
|
||||
this.state = ViewerObjState["Delete"]
|
||||
}
|
||||
|
||||
if (this.autoDelete) {
|
||||
//remove if it's first automated layer
|
||||
this.state = ViewerObjState["Delete"];
|
||||
this.state = ViewerObjState["Delete"]
|
||||
}
|
||||
|
||||
// else {
|
||||
|
|
@ -122,115 +122,115 @@ class ViewerImage {
|
|||
// }
|
||||
// }
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
unlink() {
|
||||
//keep the layer but unlink it from the ui
|
||||
try {
|
||||
this.img_html.remove(); //delete the img html element
|
||||
this.img_html.remove() //delete the img html element
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
addButtonHtml() {
|
||||
// Create new container element
|
||||
const container = document.createElement("div");
|
||||
const container = document.createElement("div")
|
||||
|
||||
container.className = "viewer-image-container";
|
||||
container.className = "viewer-image-container"
|
||||
|
||||
const elem = document.getElementById("svg_sp_btn");
|
||||
const elem = document.getElementById("svg_sp_btn")
|
||||
|
||||
// Create a copy of it
|
||||
const clone = elem.cloneNode(true);
|
||||
const button = clone;
|
||||
button.style.display = null;
|
||||
const clone = elem.cloneNode(true)
|
||||
const button = clone
|
||||
button.style.display = null
|
||||
button.setAttribute(
|
||||
"title",
|
||||
"use this image to generate more variance like it"
|
||||
);
|
||||
)
|
||||
|
||||
// Create button element
|
||||
// const button = document.createElement('sp-button');
|
||||
button.className = "viewer-image-button";
|
||||
button.className = "viewer-image-button"
|
||||
// button.innerHTML = "Button";
|
||||
|
||||
button.addEventListener("click", async () => {
|
||||
//set init image event listener, use when settion is active
|
||||
const layer = await app.activeDocument.activeLayers[0];
|
||||
const image_name = await psapi.setInitImage(layer, random_session_id);
|
||||
const path = `./server/python_server/init_images/${image_name}`;
|
||||
g_viewer_manager.addInitImageLayers(layer, path, false);
|
||||
});
|
||||
const layer = await app.activeDocument.activeLayers[0]
|
||||
const image_name = await psapi.setInitImage(layer, random_session_id)
|
||||
const path = `./server/python_server/init_images/${image_name}`
|
||||
g_viewer_manager.addInitImageLayers(layer, path, false)
|
||||
})
|
||||
|
||||
// Append elements to container
|
||||
container.appendChild(this.img_html);
|
||||
container.appendChild(button);
|
||||
container.appendChild(this.img_html)
|
||||
container.appendChild(button)
|
||||
|
||||
this.img_html = container;
|
||||
this.img_html = container
|
||||
}
|
||||
}
|
||||
|
||||
class OutputImage extends ViewerImage {
|
||||
constructor(layer, path) {
|
||||
super();
|
||||
this.layer = layer;
|
||||
this.path = path;
|
||||
this.img_html = null;
|
||||
super()
|
||||
this.layer = layer
|
||||
this.path = path
|
||||
this.img_html = null
|
||||
}
|
||||
visible(visibleOn) {
|
||||
try {
|
||||
super.visible(visibleOn);
|
||||
super.visible(visibleOn)
|
||||
if (this.isLayerValid()) {
|
||||
this.layer.visible = visibleOn;
|
||||
this.layer.visible = visibleOn
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
async select() {
|
||||
super.select();
|
||||
super.select()
|
||||
if (this.isLayerValid()) {
|
||||
await psapi.selectLayersExe([this.layer]);
|
||||
await psapi.selectLayersExe([this.layer])
|
||||
// console.log(`${this.layer.id} got selected`);
|
||||
}
|
||||
}
|
||||
isLayerValid() {
|
||||
super.isLayerValid();
|
||||
super.isLayerValid()
|
||||
//check if layer is defined or not
|
||||
//true if the layer is defined
|
||||
//false otherwise
|
||||
let isValid = false;
|
||||
let isValid = false
|
||||
if (typeof this.layer !== "undefined" && this.layer) {
|
||||
isValid = true;
|
||||
isValid = true
|
||||
}
|
||||
return isValid;
|
||||
return isValid
|
||||
}
|
||||
isSameLayer(layer_id) {
|
||||
super.isSameLayer(layer_id);
|
||||
const is_same = this.layer.id == layer_id;
|
||||
return is_same;
|
||||
super.isSameLayer(layer_id)
|
||||
const is_same = this.layer.id == layer_id
|
||||
return is_same
|
||||
}
|
||||
|
||||
setImgHtml(img_html) {
|
||||
super.setImgHtml();
|
||||
this.img_html = img_html;
|
||||
super.setImgHtml()
|
||||
this.img_html = img_html
|
||||
}
|
||||
async delete() {
|
||||
try {
|
||||
await super.delete();
|
||||
await super.delete()
|
||||
// this.img_html.remove()//delete the img html element
|
||||
if (this.state === ViewerObjState["Delete"]) {
|
||||
await psapi.cleanLayers([this.layer]);
|
||||
await psapi.cleanLayers([this.layer])
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
info() {
|
||||
super.info();
|
||||
super.info()
|
||||
}
|
||||
// unlink(){
|
||||
// //keep the layer but unlink it from the ui
|
||||
|
|
@ -247,13 +247,13 @@ class OutputImage extends ViewerImage {
|
|||
|
||||
class InitImage extends ViewerImage {
|
||||
constructor(init_group, init_snapshot, solid_layer, path) {
|
||||
super();
|
||||
this.init_group = init_group;
|
||||
this.init_snapshot = init_snapshot;
|
||||
this.solid_layer = solid_layer;
|
||||
super()
|
||||
this.init_group = init_group
|
||||
this.init_snapshot = init_snapshot
|
||||
this.solid_layer = solid_layer
|
||||
|
||||
this.path = path;
|
||||
this.can_highlight = false;
|
||||
this.path = path
|
||||
this.can_highlight = false
|
||||
|
||||
// if (this.autoDelete === false){
|
||||
// this.state = ViewerObjState['Unlink']
|
||||
|
|
@ -261,44 +261,44 @@ class InitImage extends ViewerImage {
|
|||
}
|
||||
visible(visibleOn) {
|
||||
try {
|
||||
super.visible(visibleOn);
|
||||
super.visible(visibleOn)
|
||||
// const isValid = this.isLayerValid()
|
||||
let visibleValues = [];
|
||||
let visibleValues = []
|
||||
if (visibleOn) {
|
||||
visibleValues = [true, true, true];
|
||||
visibleValues = [true, true, true]
|
||||
} else {
|
||||
visibleValues = [false, false, false];
|
||||
visibleValues = [false, false, false]
|
||||
}
|
||||
|
||||
if (this.isLayerValid(this.init_group)) {
|
||||
this.init_group.visible = visibleValues[0];
|
||||
this.init_group.visible = visibleValues[0]
|
||||
}
|
||||
if (this.isLayerValid(this.init_snapshot)) {
|
||||
this.init_snapshot.visible = visibleValues[1];
|
||||
this.init_snapshot.visible = visibleValues[1]
|
||||
}
|
||||
|
||||
if (this.isLayerValid(this.solid_layer)) {
|
||||
this.solid_layer.visible = visibleValues[2];
|
||||
this.solid_layer.visible = visibleValues[2]
|
||||
}
|
||||
|
||||
if (!this.autoDelete) {
|
||||
//means it's not the first init image
|
||||
|
||||
if (this.isLayerValid(this.solid_layer)) {
|
||||
this.solid_layer.visible = false; //turn it off sense the init group is above the output group, and the white solid will hide the init image reference located in the output group
|
||||
this.solid_layer.visible = false //turn it off sense the init group is above the output group, and the white solid will hide the init image reference located in the output group
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
async select() {
|
||||
super.select();
|
||||
super.select()
|
||||
|
||||
const selectLayers = [];
|
||||
const selectLayers = []
|
||||
if (this.isLayerValid(this.init_group)) {
|
||||
selectLayers.push(this.init_group);
|
||||
selectLayers.push(this.init_group)
|
||||
}
|
||||
// if (this.isLayerValid(this.init_snapshot)) {
|
||||
|
||||
|
|
@ -308,44 +308,44 @@ class InitImage extends ViewerImage {
|
|||
// selectLayers.push(this.solid_layer)
|
||||
// }
|
||||
|
||||
await psapi.selectLayersExe(selectLayers);
|
||||
await psapi.selectLayersExe(selectLayers)
|
||||
// console.log(`${this.layer.id} got selected`);
|
||||
}
|
||||
|
||||
isLayerValid(layer) {
|
||||
super.isLayerValid();
|
||||
super.isLayerValid()
|
||||
//check if layer is defined or not
|
||||
//true if the layer is defined
|
||||
//false otherwise
|
||||
// let isValid = [false,false,false]
|
||||
let isValid = false;
|
||||
let isValid = false
|
||||
if (typeof layer !== "undefined" && layer) {
|
||||
isValid = true;
|
||||
isValid = true
|
||||
}
|
||||
|
||||
return isValid;
|
||||
return isValid
|
||||
}
|
||||
isSameLayer(layer_id) {
|
||||
super.isSameLayer(layer_id);
|
||||
let is_same = false;
|
||||
super.isSameLayer(layer_id)
|
||||
let is_same = false
|
||||
if (this.isLayerValid(this.init_group)) {
|
||||
is_same = this.init_group.id == layer_id;
|
||||
is_same = this.init_group.id == layer_id
|
||||
}
|
||||
return is_same;
|
||||
return is_same
|
||||
}
|
||||
setImgHtml(img_html) {
|
||||
super.setImgHtml();
|
||||
this.img_html = img_html;
|
||||
super.setImgHtml()
|
||||
this.img_html = img_html
|
||||
}
|
||||
async delete() {
|
||||
try {
|
||||
await super.delete();
|
||||
await super.delete()
|
||||
|
||||
// this.img_html.remove()//delete the img html element
|
||||
|
||||
if (!this.autoDelete && !this.can_highlight) {
|
||||
//don't delete since it's output layer that is been used as init image
|
||||
this.state = ViewerObjState["Unlink"];
|
||||
this.state = ViewerObjState["Unlink"]
|
||||
}
|
||||
|
||||
if (this.state === ViewerObjState["Delete"]) {
|
||||
|
|
@ -353,106 +353,106 @@ class InitImage extends ViewerImage {
|
|||
this.init_group,
|
||||
this.init_snapshot,
|
||||
this.solid_layer,
|
||||
]);
|
||||
])
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class InitMaskImage extends ViewerImage {
|
||||
constructor(mask_group, white_mark, solid_black, path) {
|
||||
super();
|
||||
this.mask_group = mask_group;
|
||||
this.white_mark = white_mark;
|
||||
this.solid_black = solid_black;
|
||||
super()
|
||||
this.mask_group = mask_group
|
||||
this.white_mark = white_mark
|
||||
this.solid_black = solid_black
|
||||
|
||||
this.path = path;
|
||||
this.can_highlight = false;
|
||||
this.path = path
|
||||
this.can_highlight = false
|
||||
}
|
||||
visible(visibleOn) {
|
||||
try {
|
||||
super.visible(visibleOn);
|
||||
super.visible(visibleOn)
|
||||
// const isValid = this.isLayerValid()
|
||||
let visibleValues = [];
|
||||
let visibleValues = []
|
||||
if (visibleOn) {
|
||||
visibleValues = [true, true, false];
|
||||
visibleValues = [true, true, false]
|
||||
} else {
|
||||
visibleValues = [false, false, false];
|
||||
visibleValues = [false, false, false]
|
||||
}
|
||||
|
||||
if (this.isLayerValid(this.mask_group)) {
|
||||
this.mask_group.visible = visibleValues[0];
|
||||
this.mask_group.visible = visibleValues[0]
|
||||
}
|
||||
if (this.isLayerValid(this.white_mark)) {
|
||||
this.white_mark.visible = visibleValues[1];
|
||||
this.white_mark.visible = visibleValues[1]
|
||||
}
|
||||
if (this.isLayerValid(this.solid_black)) {
|
||||
this.solid_black.visible = visibleValues[2];
|
||||
this.solid_black.visible = visibleValues[2]
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
async select() {
|
||||
super.select();
|
||||
super.select()
|
||||
|
||||
const selectLayers = [];
|
||||
const selectLayers = []
|
||||
// if (this.isLayerValid(this.mask_group)) {
|
||||
|
||||
// selectLayers.push(this.mask_group)
|
||||
// }
|
||||
if (this.isLayerValid(this.white_mark)) {
|
||||
selectLayers.push(this.white_mark);
|
||||
selectLayers.push(this.white_mark)
|
||||
}
|
||||
// if (this.isLayerValid(this.solid_layer)) {
|
||||
// selectLayers.push(this.solid_layer)
|
||||
// }
|
||||
|
||||
await psapi.selectLayersExe(selectLayers);
|
||||
await psapi.selectLayersExe(selectLayers)
|
||||
// console.log(`${this.layer.id} got selected`);
|
||||
}
|
||||
|
||||
isLayerValid(layer) {
|
||||
super.isLayerValid();
|
||||
super.isLayerValid()
|
||||
//check if layer is defined or not
|
||||
//true if the layer is defined
|
||||
//false otherwise
|
||||
// let isValid = [false,false,false]
|
||||
let isValid = false;
|
||||
let isValid = false
|
||||
if (typeof layer !== "undefined" && layer) {
|
||||
isValid = true;
|
||||
isValid = true
|
||||
}
|
||||
|
||||
return isValid;
|
||||
return isValid
|
||||
}
|
||||
isSameLayer(layer_id) {
|
||||
super.isSameLayer(layer_id);
|
||||
let is_same = false;
|
||||
super.isSameLayer(layer_id)
|
||||
let is_same = false
|
||||
if (this.isLayerValid(this.mask_group)) {
|
||||
is_same = this.mask_group.id == layer_id;
|
||||
is_same = this.mask_group.id == layer_id
|
||||
}
|
||||
return is_same;
|
||||
return is_same
|
||||
}
|
||||
setImgHtml(img_html) {
|
||||
super.setImgHtml();
|
||||
this.img_html = img_html;
|
||||
super.setImgHtml()
|
||||
this.img_html = img_html
|
||||
}
|
||||
async delete() {
|
||||
try {
|
||||
await super.delete();
|
||||
await super.delete()
|
||||
// this.img_html.remove()//delete the img html element
|
||||
if (this.state === ViewerObjState["Delete"]) {
|
||||
await psapi.cleanLayers([
|
||||
this.mask_group,
|
||||
this.white_mark,
|
||||
this.solid_black,
|
||||
]);
|
||||
])
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -460,52 +460,52 @@ class InitMaskImage extends ViewerImage {
|
|||
class initImageLayers {
|
||||
//store info about the init image related layers
|
||||
constructor(group, snapshot, solid_background, autoDelete) {
|
||||
this.group = group;
|
||||
this.snapshot = snapshot;
|
||||
this.solid_background = solid_background;
|
||||
this.autoDelete = autoDelete;
|
||||
this.group = group
|
||||
this.snapshot = snapshot
|
||||
this.solid_background = solid_background
|
||||
this.autoDelete = autoDelete
|
||||
}
|
||||
}
|
||||
class maskLayers {
|
||||
//store info about the init image related layers
|
||||
constructor(group, white_mark, solid_background, autoDelete) {
|
||||
this.group = group;
|
||||
this.white_mark = white_mark;
|
||||
this.solid_background = solid_background;
|
||||
this.autoDelete = autoDelete;
|
||||
this.group = group
|
||||
this.white_mark = white_mark
|
||||
this.solid_background = solid_background
|
||||
this.autoDelete = autoDelete
|
||||
}
|
||||
}
|
||||
class ViewerManager {
|
||||
//viewer manager will reset after the end of the session
|
||||
//it will store
|
||||
constructor() {
|
||||
this.outputImages = [];
|
||||
this.initImages = [];
|
||||
this.initMaskImage;
|
||||
this.pathToViewerImage = {}; // quick way to check if an link image path on disk to ViewerImage object.
|
||||
this.initImageLayersJson = {}; //{path: initImageLayers}
|
||||
this.outputImages = []
|
||||
this.initImages = []
|
||||
this.initMaskImage
|
||||
this.pathToViewerImage = {} // quick way to check if an link image path on disk to ViewerImage object.
|
||||
this.initImageLayersJson = {} //{path: initImageLayers}
|
||||
|
||||
this.mask_layer;
|
||||
this.maskLayersJson = {}; //{path: MaskLayers}
|
||||
this.mask_layer
|
||||
this.maskLayersJson = {} //{path: MaskLayers}
|
||||
|
||||
//Note:move initGroup, to GenerationSession
|
||||
this.initGroup;
|
||||
this.init_solid_background;
|
||||
this.maskGroup;
|
||||
this.mask_solid_background;
|
||||
this.initGroup
|
||||
this.init_solid_background
|
||||
this.maskGroup
|
||||
this.mask_solid_background
|
||||
|
||||
//last_selected_obj
|
||||
this.last_selected_viewer_obj;
|
||||
this.last_selected_viewer_obj
|
||||
}
|
||||
initializeInitImage(group, snapshot, solid_background, path) {
|
||||
this.initGroup = group;
|
||||
this.init_solid_background = solid_background;
|
||||
this.addInitImageLayers(snapshot, path, true);
|
||||
this.initGroup = group
|
||||
this.init_solid_background = solid_background
|
||||
this.addInitImageLayers(snapshot, path, true)
|
||||
}
|
||||
initializeMask(group, white_mark, solid_background, path) {
|
||||
this.maskGroup = group;
|
||||
this.mask_solid_background = solid_background;
|
||||
this.addMaskLayers(white_mark, path, true);
|
||||
this.maskGroup = group
|
||||
this.mask_solid_background = solid_background
|
||||
this.addMaskLayers(white_mark, path, true)
|
||||
}
|
||||
addMaskLayers(white_mark, path, auto_delete) {
|
||||
try {
|
||||
|
|
@ -517,19 +517,19 @@ class ViewerManager {
|
|||
white_mark,
|
||||
this.mask_solid_background,
|
||||
auto_delete
|
||||
);
|
||||
this.maskLayersJson[path] = mask_layers;
|
||||
)
|
||||
this.maskLayersJson[path] = mask_layers
|
||||
} else {
|
||||
//for updating the mask
|
||||
|
||||
//just update the html
|
||||
const new_path = `${path}?t=${new Date().getTime()}`;
|
||||
console.log("new mask path: ", new_path);
|
||||
const new_path = `${path}?t=${new Date().getTime()}`
|
||||
console.log("new mask path: ", new_path)
|
||||
// this.maskLayersJson[path].img_html.src = new_path
|
||||
this.pathToViewerImage[path].img_html.src = new_path;
|
||||
this.pathToViewerImage[path].img_html.src = new_path
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
updateMaskLayer() {}
|
||||
|
|
@ -543,40 +543,40 @@ class ViewerManager {
|
|||
snapshot,
|
||||
this.init_solid_background,
|
||||
auto_delete
|
||||
);
|
||||
this.initImageLayersJson[path] = init_image_layers;
|
||||
)
|
||||
this.initImageLayersJson[path] = init_image_layers
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
hasViewerImage(path) {
|
||||
if (this.pathToViewerImage.hasOwnProperty(path)) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
addOutputImage(layer, path) {
|
||||
const outputImage = new OutputImage(layer, path);
|
||||
const outputImage = new OutputImage(layer, path)
|
||||
|
||||
this.outputImages.push(outputImage);
|
||||
this.pathToViewerImage[path] = outputImage; //
|
||||
return outputImage;
|
||||
this.outputImages.push(outputImage)
|
||||
this.pathToViewerImage[path] = outputImage //
|
||||
return outputImage
|
||||
}
|
||||
addInitImage(group, snapshot, solid_background, path, auto_delete) {
|
||||
const initImage = new InitImage(group, snapshot, solid_background, path);
|
||||
initImage.setAutoDelete(auto_delete);
|
||||
this.initImages.push(initImage);
|
||||
this.pathToViewerImage[path] = initImage;
|
||||
return initImage;
|
||||
const initImage = new InitImage(group, snapshot, solid_background, path)
|
||||
initImage.setAutoDelete(auto_delete)
|
||||
this.initImages.push(initImage)
|
||||
this.pathToViewerImage[path] = initImage
|
||||
return initImage
|
||||
}
|
||||
addMask(group, white_mark, solid_background, path) {
|
||||
const mask = new InitMaskImage(group, white_mark, solid_background, path);
|
||||
const mask = new InitMaskImage(group, white_mark, solid_background, path)
|
||||
|
||||
this.initMaskImage = mask;
|
||||
this.pathToViewerImage[path] = mask;
|
||||
return mask;
|
||||
this.initMaskImage = mask
|
||||
this.pathToViewerImage[path] = mask
|
||||
return mask
|
||||
}
|
||||
deleteAll() {}
|
||||
keepAll() {}
|
||||
|
|
@ -592,4 +592,4 @@ module.exports = {
|
|||
InitMaskImage,
|
||||
ViewerObjState,
|
||||
ViewerManager,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue