Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/design-studio-mcp / photoshop-uxp/main.js |
| Date | Not specified in source |
| Repository | Janady13/design-studio-mcp |
| Revision | ddff25da7f0ff1835cf273349fa8c71ce09857e4 |
| Branch | main |
| Path or archive member | photoshop-uxp/main.js |
| Original SHA-256 | 46880c4458854cb44cafa0b0a1285dad8af34ad33b9bdee3e695b32e57ef7859 |
| Git blob SHA | 0c367e9dd625b8fc876501550745a9fa21005c04 |
| Reading-copy SHA-256 | 46880c4458854cb44cafa0b0a1285dad8af34ad33b9bdee3e695b32e57ef7859 |
Recovered source transcript
Download complete source text ↓126 lines · 3.1 KB
const { entrypoints } = require("uxp");
const photoshop = require("photoshop");
const { app, core } = photoshop;
function setStatus(message) {
const node = document.getElementById("status");
if (node) node.textContent = message;
}
function getActiveDocument() {
if (!app.documents || app.documents.length === 0) return null;
return app.activeDocument;
}
function refreshDocumentStatus() {
const node = document.getElementById("documentStatus");
if (!node) return;
const doc = getActiveDocument();
if (!doc) {
node.textContent = "No Photoshop document is open.";
return;
}
node.textContent = `${doc.title || doc.name || "Untitled"} — ${doc.width} × ${doc.height}`;
}
function showLayerNames() {
const list = document.getElementById("layers");
const doc = getActiveDocument();
if (!doc) {
list.textContent = "Open a Photoshop document first.";
setStatus("No active document.");
refreshDocumentStatus();
return;
}
const layers = Array.from(doc.layers || []);
if (layers.length === 0) {
list.textContent = "This document has no top-level layers.";
setStatus("Layer list refreshed.");
return;
}
const sorted = layers
.map(layer => ({ name: layer.name, kind: layer.kind }))
.sort((a, b) => a.name.localeCompare(b.name));
list.innerHTML = `<ul>${sorted
.map(layer => `<li>${escapeHtml(layer.name)}</li>`)
.join("")}</ul>`;
setStatus(`${sorted.length} top-level layer${sorted.length === 1 ? "" : "s"} found.`);
refreshDocumentStatus();
}
function escapeHtml(value) {
return String(value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\"/g, """)
.replace(/'/g, "'");
}
async function inspectDocument() {
const doc = getActiveDocument();
if (!doc) {
setStatus("Open a Photoshop document first.");
refreshDocumentStatus();
return;
}
showLayerNames();
setStatus(`Inspected ${doc.title || doc.name || "active document"}.`);
}
async function createFrameGroup() {
const doc = getActiveDocument();
if (!doc) {
setStatus("Open a Photoshop document first.");
return;
}
try {
await core.executeAsModal(async () => {
const group = await doc.createLayerGroup({ name: "FRAME_001" });
if (group) {
setStatus("Created FRAME_001 group.");
}
}, { commandName: "Create Animation Frame Group" });
showLayerNames();
} catch (error) {
console.error(error);
setStatus(`Could not create frame group: ${error.message}`);
}
}
function wirePanel() {
const btnPopulate = document.getElementById("btnPopulate");
const btnInspect = document.getElementById("btnInspect");
const btnFrameGroup = document.getElementById("btnFrameGroup");
if (btnPopulate) btnPopulate.addEventListener("click", showLayerNames);
if (btnInspect) btnInspect.addEventListener("click", inspectDocument);
if (btnFrameGroup) btnFrameGroup.addEventListener("click", createFrameGroup);
refreshDocumentStatus();
showLayerNames();
}
entrypoints.setup({
panels: {
designStudio: {
show() {
wirePanel();
}
}
}
});