@bubblydoo/uxp-toolkit 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-3CLJMC63.js → chunk-JBXCIUBZ.js} +49 -90
- package/dist/commands-library/index.d.ts +38 -39
- package/dist/commands-library/index.js +171 -171
- package/dist/index.d.ts +39 -41
- package/dist/index.js +189 -150
- package/dist/{psLayerRef-OY3h7srv.d.ts → psLayerRef-CGbTO4a5.d.ts} +36 -37
- package/package.json +8 -7
- package/src/commands-library/addLayerToSelection.ts +4 -4
- package/src/commands-library/applyLayerMask.ts +2 -2
- package/src/commands-library/convertMode.ts +2 -2
- package/src/commands-library/createColorLookupAdjustmentLayer.ts +2 -2
- package/src/commands-library/expandFolder.ts +4 -4
- package/src/commands-library/exportLUTs.ts +4 -4
- package/src/commands-library/getDocument.ts +7 -7
- package/src/commands-library/getLayer.ts +13 -13
- package/src/commands-library/hasVectorMask.ts +2 -2
- package/src/commands-library/index.ts +18 -18
- package/src/commands-library/loadLayerMaskAsSelection.ts +2 -2
- package/src/commands-library/multiGetDocument.ts +14 -14
- package/src/commands-library/rasterizeLayerStyle.ts +3 -3
- package/src/commands-library/rasterizeVectorMask.ts +2 -2
- package/src/commands-library/removeLayerMask.ts +2 -2
- package/src/commands-library/renameLayer.ts +6 -6
- package/src/commands-library/renameLayer.uxp-test.ts +13 -13
- package/src/commands-library/renderGrid.ts +2 -2
- package/src/commands-library/selectLayer.ts +3 -3
- package/src/commands-library/set3DLUTColorLookup.ts +2 -2
- package/src/core/batchPlay.ts +3 -3
- package/src/core/command.test-d.ts +11 -8
- package/src/core/command.ts +20 -23
- package/src/core/executeAsModal.ts +13 -11
- package/src/core/suspendHistory.ts +3 -3
- package/src/core/suspendHistory.uxp-test.ts +8 -8
- package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +8 -6
- package/src/dom/getFlattenedDomLayersList.ts +6 -7
- package/src/dom/photoshopDomLayersToTree.ts +5 -5
- package/src/error-sourcemaps/sourcemaps.ts +23 -21
- package/src/error-sourcemaps/sourcemaps.uxp-test.ts +9 -8
- package/src/errors/ut-error.ts +2 -2
- package/src/filesystem/openFileByPath.ts +4 -4
- package/src/general-tree/flattenTree.ts +1 -1
- package/src/general-tree/layerRef.ts +2 -2
- package/src/general-tree/mapTree.ts +1 -1
- package/src/general-tree/mapTreeRef.ts +1 -1
- package/src/general-tree/treeTypes.ts +0 -2
- package/src/index.ts +43 -43
- package/src/metadata-storage/metadataStorage.ts +31 -31
- package/src/metadata-storage/metadataStorage.uxp-test.ts +11 -11
- package/src/node-compat/path/resolvePath.ts +6 -4
- package/src/other/applicationInfo.ts +11 -11
- package/src/other/applicationInfo.uxp-test.ts +6 -6
- package/src/other/clipboard.ts +2 -2
- package/src/other/clipboard.uxp-test.ts +9 -8
- package/src/other/uxpEntrypoints.ts +2 -2
- package/src/ut-tree/getDocumentLayerDescriptors.ts +6 -6
- package/src/ut-tree/getLayerEffects.ts +5 -5
- package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +25 -23
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +29 -29
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +62 -62
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +29 -29
- package/src/ut-tree/psLayerRef.ts +2 -2
- package/src/ut-tree/utLayersToText.test.ts +32 -32
- package/src/ut-tree/utLayersToText.ts +19 -19
- package/src/ut-tree/utLayersToTree.ts +4 -4
- package/src/util/utLayerPickKeysType.ts +3 -3
- package/src/util/utLayerToLayer.ts +14 -13
- package/test/index.ts +11 -11
- package/test/meta-tests/builtinModules.uxp-test.ts +28 -26
- package/test/meta-tests/executeAsModal.uxp-test.ts +14 -12
- package/test/meta-tests/suspendHistory.uxp-test.ts +10 -9
- package/tsconfig.json +5 -5
- package/tsup.config.ts +5 -5
- package/uxp-tests.json +1 -1
- package/vitest-photoshop-alias-plugin.ts +23 -21
- package/vitest.config.ts +6 -6
package/dist/index.js
CHANGED
|
@@ -7,9 +7,44 @@ import {
|
|
|
7
7
|
createGetDocumentHasBackgroundLayerCommand,
|
|
8
8
|
createGetLayerCommand,
|
|
9
9
|
createModifyingBatchPlayContext,
|
|
10
|
-
createMultiGetDocumentCommand
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
createMultiGetDocumentCommand
|
|
11
|
+
} from "./chunk-JBXCIUBZ.js";
|
|
12
|
+
|
|
13
|
+
// src/core/executeAsModal.ts
|
|
14
|
+
import { core } from "photoshop";
|
|
15
|
+
var originalExecuteAsModal = core.executeAsModal;
|
|
16
|
+
async function executeAsModal(commandName, fn, opts) {
|
|
17
|
+
let error;
|
|
18
|
+
let result;
|
|
19
|
+
await originalExecuteAsModal(async (executionContext) => {
|
|
20
|
+
const abortController = new AbortController();
|
|
21
|
+
executionContext.onCancel = () => {
|
|
22
|
+
abortController.abort();
|
|
23
|
+
};
|
|
24
|
+
const extendedExecutionContext = {
|
|
25
|
+
isCancelled: executionContext.isCancelled,
|
|
26
|
+
reportProgress: executionContext.reportProgress,
|
|
27
|
+
hostControl: executionContext.hostControl,
|
|
28
|
+
signal: abortController.signal,
|
|
29
|
+
...createModifyingBatchPlayContext()
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
result = await fn(extendedExecutionContext);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error("error in executeAsModal");
|
|
35
|
+
console.error(e);
|
|
36
|
+
error = e;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
commandName,
|
|
40
|
+
...opts
|
|
41
|
+
});
|
|
42
|
+
if (error) {
|
|
43
|
+
throw error;
|
|
44
|
+
} else {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
13
48
|
|
|
14
49
|
// src/core/suspendHistory.ts
|
|
15
50
|
async function suspendHistory(document, historyStateName, fn) {
|
|
@@ -21,15 +56,15 @@ async function suspendHistory(document, historyStateName, fn) {
|
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
// src/core-wrappers/executeAsModalAndSuspendHistory.ts
|
|
24
|
-
|
|
59
|
+
async function executeAsModalAndSuspendHistory(commandName, document, fn) {
|
|
25
60
|
return await executeAsModal(commandName, async (ctx) => {
|
|
26
61
|
return await suspendHistory(document, commandName, (suspendHistoryContext) => fn(ctx, suspendHistoryContext));
|
|
27
62
|
});
|
|
28
|
-
}
|
|
63
|
+
}
|
|
29
64
|
|
|
30
65
|
// src/dom/getFlattenedDomLayersList.ts
|
|
31
66
|
import { constants } from "photoshop";
|
|
32
|
-
|
|
67
|
+
function getFlattenedDomLayersList(layers) {
|
|
33
68
|
const allLayers = [];
|
|
34
69
|
const stack = [];
|
|
35
70
|
for (let i = layers.length - 1; i >= 0; i--) {
|
|
@@ -37,7 +72,8 @@ var getFlattenedDomLayersList = (layers) => {
|
|
|
37
72
|
}
|
|
38
73
|
while (stack.length > 0) {
|
|
39
74
|
const layer = stack.pop();
|
|
40
|
-
if (!layer)
|
|
75
|
+
if (!layer)
|
|
76
|
+
continue;
|
|
41
77
|
allLayers.push(layer);
|
|
42
78
|
if (layer.kind === constants.LayerKind.GROUP) {
|
|
43
79
|
const children = layer.layers;
|
|
@@ -49,10 +85,10 @@ var getFlattenedDomLayersList = (layers) => {
|
|
|
49
85
|
}
|
|
50
86
|
}
|
|
51
87
|
return allLayers;
|
|
52
|
-
}
|
|
88
|
+
}
|
|
53
89
|
|
|
54
90
|
// src/dom/photoshopDomLayersToTree.ts
|
|
55
|
-
|
|
91
|
+
function photoshopDomLayersToTree(layers) {
|
|
56
92
|
const filteredLayers = layers.filter((layer) => layer.parent === null);
|
|
57
93
|
const generateTree = (layers2) => {
|
|
58
94
|
return layers2.map((layer) => ({
|
|
@@ -62,13 +98,119 @@ var photoshopDomLayersToTree = (layers) => {
|
|
|
62
98
|
}));
|
|
63
99
|
};
|
|
64
100
|
return generateTree(filteredLayers);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/error-sourcemaps/sourcemaps.ts
|
|
104
|
+
import ErrorStackParser from "error-stack-parser";
|
|
105
|
+
import { SourceMapConsumer } from "source-map-js";
|
|
106
|
+
import { storage } from "uxp";
|
|
107
|
+
|
|
108
|
+
// src/errors/ut-error.ts
|
|
109
|
+
var UTError = class extends Error {
|
|
110
|
+
constructor(message, opts = {}) {
|
|
111
|
+
super(message, opts);
|
|
112
|
+
this.name = "UTError";
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/node-compat/path/resolvePath.ts
|
|
117
|
+
import { resolve as nativeResolve } from "path";
|
|
118
|
+
function pathResolve(...pathSegments) {
|
|
119
|
+
const urlOrString = nativeResolve(...pathSegments);
|
|
120
|
+
if (typeof urlOrString === "string") {
|
|
121
|
+
return urlOrString;
|
|
122
|
+
}
|
|
123
|
+
if (isUrl(urlOrString)) {
|
|
124
|
+
return urlOrString.toString();
|
|
125
|
+
}
|
|
126
|
+
throw new Error("Unexpected URL object");
|
|
127
|
+
}
|
|
128
|
+
function isUrl(urlOrString) {
|
|
129
|
+
return urlOrString instanceof URL;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/error-sourcemaps/sourcemaps.ts
|
|
133
|
+
async function parseUxpErrorSourcemaps(error, opts = {}) {
|
|
134
|
+
const parsedError = parseErrorIntoBasicStackFrames(error);
|
|
135
|
+
const unsourcemappedHeaderLines = opts.unsourcemappedHeaderLines ?? 0;
|
|
136
|
+
const loadedFilesCache = {};
|
|
137
|
+
const fs = storage.localFileSystem;
|
|
138
|
+
const parsedMappedError = [];
|
|
139
|
+
for (const frame of parsedError) {
|
|
140
|
+
if (!frame.fileName || !frame.lineNumber || !frame.columnNumber) {
|
|
141
|
+
parsedMappedError.push(frame);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const entryPath = `plugin:${frame.fileName}`;
|
|
145
|
+
const file = loadedFilesCache[entryPath] ?? await fs.getEntryWithUrl(entryPath);
|
|
146
|
+
loadedFilesCache[entryPath] = file;
|
|
147
|
+
if (!file.isFile) {
|
|
148
|
+
parsedMappedError.push(frame);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const sourcemapFileEntryPath = `${entryPath}.map`;
|
|
152
|
+
const sourcemapFile = loadedFilesCache[sourcemapFileEntryPath] ?? await fs.getEntryWithUrl(sourcemapFileEntryPath);
|
|
153
|
+
loadedFilesCache[sourcemapFileEntryPath] = sourcemapFile;
|
|
154
|
+
if (!sourcemapFile.isFile) {
|
|
155
|
+
parsedMappedError.push(frame);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const sourcemapContents = await sourcemapFile.read({});
|
|
159
|
+
const sourcemap = JSON.parse(sourcemapContents);
|
|
160
|
+
const smc = new SourceMapConsumer(sourcemap);
|
|
161
|
+
const mappedFrame = smc.originalPositionFor({
|
|
162
|
+
line: frame.lineNumber - unsourcemappedHeaderLines,
|
|
163
|
+
column: frame.columnNumber
|
|
164
|
+
});
|
|
165
|
+
if (mappedFrame.source && mappedFrame.line && mappedFrame.column) {
|
|
166
|
+
parsedMappedError.push({
|
|
167
|
+
...frame,
|
|
168
|
+
fileName: mappedFrame.source,
|
|
169
|
+
lineNumber: mappedFrame.line,
|
|
170
|
+
columnNumber: mappedFrame.column
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
parsedMappedError.push(frame);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return parsedMappedError;
|
|
177
|
+
}
|
|
178
|
+
function parseErrorIntoBasicStackFrames(error) {
|
|
179
|
+
try {
|
|
180
|
+
const frames = ErrorStackParser.parse(error);
|
|
181
|
+
return frames.map((frame) => {
|
|
182
|
+
return {
|
|
183
|
+
functionName: frame.functionName,
|
|
184
|
+
fileName: frame.fileName,
|
|
185
|
+
lineNumber: frame.lineNumber,
|
|
186
|
+
columnNumber: frame.columnNumber
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
throw new UTStacktraceParsingError("Failed to parse error stack trace", { cause: e });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function getBasicStackFrameAbsoluteFilePath(frame) {
|
|
194
|
+
const pluginFolder = await storage.localFileSystem.getPluginFolder();
|
|
195
|
+
const absoluteFileName = pathResolve(
|
|
196
|
+
pluginFolder.nativePath,
|
|
197
|
+
"index.js",
|
|
198
|
+
frame.fileName
|
|
199
|
+
).replace(/^plugin:/, "");
|
|
200
|
+
return `${absoluteFileName}:${frame.lineNumber}:${frame.columnNumber}`;
|
|
201
|
+
}
|
|
202
|
+
var UTStacktraceParsingError = class extends UTError {
|
|
203
|
+
name = "UTStacktraceParsingError";
|
|
204
|
+
constructor(message, opts = {}) {
|
|
205
|
+
super(message, opts);
|
|
206
|
+
}
|
|
65
207
|
};
|
|
66
208
|
|
|
67
209
|
// src/filesystem/openFileByPath.ts
|
|
68
210
|
import { app } from "photoshop";
|
|
69
|
-
import { storage } from "uxp";
|
|
211
|
+
import { storage as storage2 } from "uxp";
|
|
70
212
|
async function openFileByPath(path) {
|
|
71
|
-
const fs =
|
|
213
|
+
const fs = storage2.localFileSystem;
|
|
72
214
|
const file = await fs.getEntryWithUrl(path);
|
|
73
215
|
const doc = await executeAsModal("Open file", () => app.open(file));
|
|
74
216
|
return doc;
|
|
@@ -110,9 +252,6 @@ function mapTreeRef(tree, mapFn) {
|
|
|
110
252
|
|
|
111
253
|
// src/other/applicationInfo.ts
|
|
112
254
|
import { z } from "zod";
|
|
113
|
-
async function photoshopGetApplicationInfo() {
|
|
114
|
-
return await batchPlayCommand(photoshopApplicationInfoCommand);
|
|
115
|
-
}
|
|
116
255
|
var photoshopAppInfoSchema = z.object({
|
|
117
256
|
active: z.boolean(),
|
|
118
257
|
autoShowHomeScreen: z.boolean(),
|
|
@@ -157,6 +296,9 @@ var photoshopApplicationInfoCommand = createCommand({
|
|
|
157
296
|
},
|
|
158
297
|
schema: photoshopAppInfoSchema
|
|
159
298
|
});
|
|
299
|
+
async function photoshopGetApplicationInfo() {
|
|
300
|
+
return await batchPlayCommand(photoshopApplicationInfoCommand);
|
|
301
|
+
}
|
|
160
302
|
|
|
161
303
|
// src/other/clipboard.ts
|
|
162
304
|
async function copyToClipboard(text) {
|
|
@@ -180,7 +322,7 @@ var uxpEntrypointsSchema = z2.object({
|
|
|
180
322
|
});
|
|
181
323
|
|
|
182
324
|
// src/ut-tree/getDocumentLayerDescriptors.ts
|
|
183
|
-
|
|
325
|
+
async function getDocumentLayerDescriptors(documentId) {
|
|
184
326
|
const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
|
|
185
327
|
createMultiGetDocumentCommand(documentId),
|
|
186
328
|
createGetDocumentHasBackgroundLayerCommand(documentId)
|
|
@@ -196,7 +338,7 @@ var getDocumentLayerDescriptors = async (documentId) => {
|
|
|
196
338
|
docId: documentId
|
|
197
339
|
};
|
|
198
340
|
});
|
|
199
|
-
}
|
|
341
|
+
}
|
|
200
342
|
|
|
201
343
|
// src/ut-tree/getLayerEffects.ts
|
|
202
344
|
async function getLayerEffects(layerRef) {
|
|
@@ -204,7 +346,8 @@ async function getLayerEffects(layerRef) {
|
|
|
204
346
|
const data = result.layerEffects || {};
|
|
205
347
|
const effects = {};
|
|
206
348
|
for (const effect in data) {
|
|
207
|
-
if (effect !== "scale")
|
|
349
|
+
if (effect !== "scale")
|
|
350
|
+
effects[effect] = Array.isArray(data[effect]) ? data[effect].some((e) => e.enabled) : !!data[effect]?.enabled;
|
|
208
351
|
}
|
|
209
352
|
return effects;
|
|
210
353
|
}
|
|
@@ -256,20 +399,20 @@ var blendModes = [
|
|
|
256
399
|
"luminosity",
|
|
257
400
|
"passThrough"
|
|
258
401
|
];
|
|
259
|
-
|
|
402
|
+
function getLayerKind(layer) {
|
|
260
403
|
const kind = layerKindMap.get(layer.layerKind);
|
|
261
404
|
if (!kind) {
|
|
262
405
|
throw new Error(`Unknown layer kind: ${layer.layerKind}`);
|
|
263
406
|
}
|
|
264
407
|
return kind;
|
|
265
|
-
}
|
|
266
|
-
|
|
408
|
+
}
|
|
409
|
+
function getBlendMode(layer) {
|
|
267
410
|
const mode = layer.mode._value;
|
|
268
411
|
if (!blendModes.includes(mode)) {
|
|
269
412
|
throw new Error(`Unknown blend mode: ${mode}`);
|
|
270
413
|
}
|
|
271
414
|
return mode;
|
|
272
|
-
}
|
|
415
|
+
}
|
|
273
416
|
function photoshopLayerDescriptorsToUTLayers(layers) {
|
|
274
417
|
const root = [];
|
|
275
418
|
const stack = [{ layers: root }];
|
|
@@ -301,12 +444,12 @@ function photoshopLayerDescriptorsToUTLayers(layers) {
|
|
|
301
444
|
}
|
|
302
445
|
return root;
|
|
303
446
|
}
|
|
304
|
-
|
|
447
|
+
function determineLayerSection(layer) {
|
|
305
448
|
const section = layer.layerSection._value;
|
|
306
449
|
const isGroupEnd = layer.name === "</Layer group>" || layer.name === "</Layer set>" || section === "layerSectionEnd";
|
|
307
450
|
const isGroupStart = section === "layerSectionStart";
|
|
308
451
|
return isGroupStart ? "start" : isGroupEnd ? "end" : "normal";
|
|
309
|
-
}
|
|
452
|
+
}
|
|
310
453
|
function getEffects(layer) {
|
|
311
454
|
const effects = {};
|
|
312
455
|
if (layer.layerEffects) {
|
|
@@ -317,25 +460,6 @@ function getEffects(layer) {
|
|
|
317
460
|
return effects;
|
|
318
461
|
}
|
|
319
462
|
|
|
320
|
-
// src/ut-tree/utLayersToTree.ts
|
|
321
|
-
function utLayersToTree(layer) {
|
|
322
|
-
return layer.map((layer2) => ({
|
|
323
|
-
ref: {
|
|
324
|
-
name: layer2.name,
|
|
325
|
-
docId: layer2.docId,
|
|
326
|
-
id: layer2.id,
|
|
327
|
-
visible: layer2.visible,
|
|
328
|
-
kind: layer2.kind,
|
|
329
|
-
blendMode: layer2.blendMode,
|
|
330
|
-
isClippingMask: layer2.isClippingMask,
|
|
331
|
-
effects: layer2.effects,
|
|
332
|
-
background: layer2.background
|
|
333
|
-
},
|
|
334
|
-
name: layer2.name,
|
|
335
|
-
children: layer2.layers ? utLayersToTree(layer2.layers) : void 0
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
|
|
339
463
|
// src/ut-tree/utLayersToText.ts
|
|
340
464
|
var VISIBLE_ICON = "\u25EF";
|
|
341
465
|
var INVISIBLE_ICON = "\u2298";
|
|
@@ -354,7 +478,8 @@ function utLayersToText(tree, depth = 0) {
|
|
|
354
478
|
const visible = layer.visible ? VISIBLE_ICON : INVISIBLE_ICON;
|
|
355
479
|
const line = [visible, prefix, clippingMask, group, name, effects, blend].filter(Boolean).join(" ");
|
|
356
480
|
if (layer.layers) {
|
|
357
|
-
return line
|
|
481
|
+
return `${line}
|
|
482
|
+
${utLayersToText(layer.layers, depth + 1)}`;
|
|
358
483
|
}
|
|
359
484
|
return line;
|
|
360
485
|
}).join("\n");
|
|
@@ -363,6 +488,25 @@ function isSpecialBlendMode(layer) {
|
|
|
363
488
|
return layer.kind === "group" ? layer.blendMode !== "passThrough" : layer.blendMode !== "normal";
|
|
364
489
|
}
|
|
365
490
|
|
|
491
|
+
// src/ut-tree/utLayersToTree.ts
|
|
492
|
+
function utLayersToTree(layer) {
|
|
493
|
+
return layer.map((layer2) => ({
|
|
494
|
+
ref: {
|
|
495
|
+
name: layer2.name,
|
|
496
|
+
docId: layer2.docId,
|
|
497
|
+
id: layer2.id,
|
|
498
|
+
visible: layer2.visible,
|
|
499
|
+
kind: layer2.kind,
|
|
500
|
+
blendMode: layer2.blendMode,
|
|
501
|
+
isClippingMask: layer2.isClippingMask,
|
|
502
|
+
effects: layer2.effects,
|
|
503
|
+
background: layer2.background
|
|
504
|
+
},
|
|
505
|
+
name: layer2.name,
|
|
506
|
+
children: layer2.layers ? utLayersToTree(layer2.layers) : void 0
|
|
507
|
+
}));
|
|
508
|
+
}
|
|
509
|
+
|
|
366
510
|
// src/util/utLayerToLayer.ts
|
|
367
511
|
import { app as app2 } from "photoshop";
|
|
368
512
|
function utLayerToDomLayer(layer) {
|
|
@@ -380,7 +524,8 @@ function utLayerToDomLayer(layer) {
|
|
|
380
524
|
return domLayer;
|
|
381
525
|
}
|
|
382
526
|
function utLayersToDomLayers(layers) {
|
|
383
|
-
if (layers.length === 0)
|
|
527
|
+
if (layers.length === 0)
|
|
528
|
+
return [];
|
|
384
529
|
const docId = layers[0].docId;
|
|
385
530
|
if (!layers.every((l) => l.docId === docId)) {
|
|
386
531
|
throw new Error("All layers must be from the same document.");
|
|
@@ -400,112 +545,6 @@ function utLayersToDomLayers(layers) {
|
|
|
400
545
|
return domLayer;
|
|
401
546
|
});
|
|
402
547
|
}
|
|
403
|
-
|
|
404
|
-
// src/error-sourcemaps/sourcemaps.ts
|
|
405
|
-
import ErrorStackParser from "error-stack-parser";
|
|
406
|
-
import { SourceMapConsumer } from "source-map-js";
|
|
407
|
-
import { storage as storage2 } from "uxp";
|
|
408
|
-
|
|
409
|
-
// src/node-compat/path/resolvePath.ts
|
|
410
|
-
import { resolve as nativeResolve } from "path";
|
|
411
|
-
function pathResolve(...pathSegments) {
|
|
412
|
-
const urlOrString = nativeResolve(...pathSegments);
|
|
413
|
-
if (typeof urlOrString === "string") {
|
|
414
|
-
return urlOrString;
|
|
415
|
-
}
|
|
416
|
-
if (isUrl(urlOrString)) {
|
|
417
|
-
return urlOrString.toString();
|
|
418
|
-
}
|
|
419
|
-
throw new Error("Unexpected URL object");
|
|
420
|
-
}
|
|
421
|
-
function isUrl(urlOrString) {
|
|
422
|
-
return urlOrString instanceof URL;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// src/errors/ut-error.ts
|
|
426
|
-
var UTError = class extends Error {
|
|
427
|
-
constructor(message, opts = {}) {
|
|
428
|
-
super(message, opts);
|
|
429
|
-
this.name = "UTError";
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// src/error-sourcemaps/sourcemaps.ts
|
|
434
|
-
async function parseUxpErrorSourcemaps(error, opts = {}) {
|
|
435
|
-
const parsedError = parseErrorIntoBasicStackFrames(error);
|
|
436
|
-
const unsourcemappedHeaderLines = opts.unsourcemappedHeaderLines ?? 0;
|
|
437
|
-
const loadedFilesCache = {};
|
|
438
|
-
const fs = storage2.localFileSystem;
|
|
439
|
-
const parsedMappedError = [];
|
|
440
|
-
for (const frame of parsedError) {
|
|
441
|
-
if (!frame.fileName || !frame.lineNumber || !frame.columnNumber) {
|
|
442
|
-
parsedMappedError.push(frame);
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
const entryPath = "plugin:" + frame.fileName;
|
|
446
|
-
const file = loadedFilesCache[entryPath] ?? await fs.getEntryWithUrl(entryPath);
|
|
447
|
-
loadedFilesCache[entryPath] = file;
|
|
448
|
-
if (!file.isFile) {
|
|
449
|
-
parsedMappedError.push(frame);
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
const sourcemapFileEntryPath = entryPath + ".map";
|
|
453
|
-
const sourcemapFile = loadedFilesCache[sourcemapFileEntryPath] ?? await fs.getEntryWithUrl(sourcemapFileEntryPath);
|
|
454
|
-
loadedFilesCache[sourcemapFileEntryPath] = sourcemapFile;
|
|
455
|
-
if (!sourcemapFile.isFile) {
|
|
456
|
-
parsedMappedError.push(frame);
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
const sourcemapContents = await sourcemapFile.read({});
|
|
460
|
-
const sourcemap = JSON.parse(sourcemapContents);
|
|
461
|
-
const smc = new SourceMapConsumer(sourcemap);
|
|
462
|
-
const mappedFrame = smc.originalPositionFor({
|
|
463
|
-
line: frame.lineNumber - unsourcemappedHeaderLines,
|
|
464
|
-
column: frame.columnNumber
|
|
465
|
-
});
|
|
466
|
-
if (mappedFrame.source && mappedFrame.line && mappedFrame.column) {
|
|
467
|
-
parsedMappedError.push({
|
|
468
|
-
...frame,
|
|
469
|
-
fileName: mappedFrame.source,
|
|
470
|
-
lineNumber: mappedFrame.line,
|
|
471
|
-
columnNumber: mappedFrame.column
|
|
472
|
-
});
|
|
473
|
-
} else {
|
|
474
|
-
parsedMappedError.push(frame);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return parsedMappedError;
|
|
478
|
-
}
|
|
479
|
-
function parseErrorIntoBasicStackFrames(error) {
|
|
480
|
-
try {
|
|
481
|
-
const frames = ErrorStackParser.parse(error);
|
|
482
|
-
return frames.map((frame) => {
|
|
483
|
-
return {
|
|
484
|
-
functionName: frame.functionName,
|
|
485
|
-
fileName: frame.fileName,
|
|
486
|
-
lineNumber: frame.lineNumber,
|
|
487
|
-
columnNumber: frame.columnNumber
|
|
488
|
-
};
|
|
489
|
-
});
|
|
490
|
-
} catch (e) {
|
|
491
|
-
throw new UTStacktraceParsingError("Failed to parse error stack trace", { cause: e });
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
async function getBasicStackFrameAbsoluteFilePath(frame) {
|
|
495
|
-
const pluginFolder = await storage2.localFileSystem.getPluginFolder();
|
|
496
|
-
const absoluteFileName = pathResolve(
|
|
497
|
-
pluginFolder.nativePath,
|
|
498
|
-
"index.js",
|
|
499
|
-
frame.fileName
|
|
500
|
-
).replace(/^plugin:/, "");
|
|
501
|
-
return `${absoluteFileName}:${frame.lineNumber}:${frame.columnNumber}`;
|
|
502
|
-
}
|
|
503
|
-
var UTStacktraceParsingError = class extends UTError {
|
|
504
|
-
name = "UTStacktraceParsingError";
|
|
505
|
-
constructor(message, opts = {}) {
|
|
506
|
-
super(message, opts);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
548
|
export {
|
|
510
549
|
batchPlay,
|
|
511
550
|
batchPlayCommand,
|
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { ActionDescriptor } from 'photoshop
|
|
1
|
+
import * as photoshop from 'photoshop';
|
|
2
|
+
import { action, ActionDescriptor } from 'photoshop';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
declare function createMultiGetDocumentCommand(docId: number): UTCommandNonModifying<{
|
|
6
|
+
list: {
|
|
7
|
+
name: string;
|
|
8
|
+
layerID: number;
|
|
9
|
+
visible: boolean;
|
|
10
|
+
group: boolean;
|
|
11
|
+
layerSection: {
|
|
12
|
+
_value: "layerSectionStart" | "layerSectionEnd" | "layerSectionContent";
|
|
13
|
+
_enum: "layerSectionType";
|
|
14
|
+
};
|
|
15
|
+
layerKind: number;
|
|
16
|
+
itemIndex: number;
|
|
17
|
+
background: boolean;
|
|
18
|
+
mode: {
|
|
19
|
+
_enum: "blendMode";
|
|
20
|
+
_value: string;
|
|
21
|
+
};
|
|
22
|
+
layerEffects?: Record<string, {
|
|
23
|
+
enabled?: boolean | undefined;
|
|
24
|
+
} | {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
}[]> | undefined;
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
5
29
|
|
|
6
30
|
type P = Parameters<typeof action.batchPlay>;
|
|
7
31
|
type CorrectBatchPlayOptions = P[1] & {
|
|
8
32
|
immediateRedraw?: boolean;
|
|
9
33
|
};
|
|
10
|
-
declare function batchPlay(actions: P[0], options?: CorrectBatchPlayOptions): Promise<
|
|
34
|
+
declare function batchPlay(actions: P[0], options?: CorrectBatchPlayOptions): Promise<photoshop.ActionDescriptor[]>;
|
|
11
35
|
|
|
12
|
-
interface UTCommandBase<T
|
|
36
|
+
interface UTCommandBase<T> {
|
|
13
37
|
descriptor: ActionDescriptor;
|
|
14
38
|
schema: z.ZodSchema<T>;
|
|
15
39
|
}
|
|
16
|
-
interface UTCommandModifying<T
|
|
40
|
+
interface UTCommandModifying<T> extends UTCommandBase<T> {
|
|
17
41
|
modifying: true;
|
|
18
42
|
}
|
|
19
|
-
interface UTCommandNonModifying<T
|
|
43
|
+
interface UTCommandNonModifying<T> extends UTCommandBase<T> {
|
|
20
44
|
modifying: false;
|
|
21
45
|
}
|
|
22
|
-
declare function createCommand<TReturn
|
|
46
|
+
declare function createCommand<TReturn, TModifying extends boolean>(obj: {
|
|
23
47
|
descriptor: ActionDescriptor;
|
|
24
48
|
schema: z.ZodSchema<TReturn>;
|
|
25
49
|
modifying: TModifying;
|
|
26
50
|
}): TModifying extends true ? UTCommandModifying<TReturn> : UTCommandNonModifying<TReturn>;
|
|
27
51
|
type UTCommandResult<C> = C extends UTCommandBase<infer T> ? T : never;
|
|
28
52
|
type BatchPlayOptions = Parameters<typeof batchPlay>[1];
|
|
29
|
-
declare function batchPlayCommandBase<T
|
|
53
|
+
declare function batchPlayCommandBase<T>(command: UTCommandBase<T>, options?: BatchPlayOptions): Promise<T>;
|
|
30
54
|
declare function batchPlayCommandsBase<TCommands extends Array<UTCommandBase<any>>>(commands: readonly [...TCommands], options?: BatchPlayOptions): Promise<{
|
|
31
55
|
[K in keyof TCommands]: UTCommandResult<TCommands[K]>;
|
|
32
56
|
}>;
|
|
33
|
-
declare function batchPlayCommand<T
|
|
57
|
+
declare function batchPlayCommand<T>(command: UTCommandNonModifying<T>, options?: BatchPlayOptions): Promise<T>;
|
|
34
58
|
declare function batchPlayCommands<TCommands extends Array<UTCommandNonModifying<any>>>(commands: readonly [...TCommands], options?: BatchPlayOptions): Promise<{ [K in keyof TCommands]: UTCommandResult<TCommands[K]>; }>;
|
|
35
59
|
declare function createModifyingBatchPlayContext(): {
|
|
36
60
|
batchPlayCommand: typeof batchPlayCommandBase;
|
|
37
61
|
batchPlayCommands: typeof batchPlayCommandsBase;
|
|
38
62
|
};
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
list: {
|
|
42
|
-
name: string;
|
|
43
|
-
layerID: number;
|
|
44
|
-
visible: boolean;
|
|
45
|
-
group: boolean;
|
|
46
|
-
layerSection: {
|
|
47
|
-
_value: "layerSectionStart" | "layerSectionEnd" | "layerSectionContent";
|
|
48
|
-
_enum: "layerSectionType";
|
|
49
|
-
};
|
|
50
|
-
layerKind: number;
|
|
51
|
-
itemIndex: number;
|
|
52
|
-
background: boolean;
|
|
53
|
-
mode: {
|
|
54
|
-
_enum: "blendMode";
|
|
55
|
-
_value: string;
|
|
56
|
-
};
|
|
57
|
-
layerEffects?: Record<string, {
|
|
58
|
-
enabled?: boolean | undefined;
|
|
59
|
-
} | {
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
}[]> | undefined;
|
|
62
|
-
}[];
|
|
63
|
-
}>;
|
|
64
|
-
|
|
65
|
-
type PsLayerRef = {
|
|
64
|
+
interface PsLayerRef {
|
|
66
65
|
id: number;
|
|
67
66
|
docId: number;
|
|
68
|
-
}
|
|
67
|
+
}
|
|
69
68
|
|
|
70
69
|
export { type CorrectBatchPlayOptions as C, type PsLayerRef as P, type UTCommandBase as U, type UTCommandModifying as a, type UTCommandNonModifying as b, createModifyingBatchPlayContext as c, type UTCommandResult as d, batchPlay as e, batchPlayCommand as f, batchPlayCommands as g, createCommand as h, createMultiGetDocumentCommand as i };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bubblydoo/uxp-toolkit",
|
|
3
|
-
"version": "0.0.7",
|
|
4
|
-
"license": "MIT",
|
|
5
3
|
"type": "module",
|
|
4
|
+
"version": "0.0.9",
|
|
6
5
|
"author": "Hans Otto Wirtz <hansottowirtz@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/bubblydoo/uxp-toolkit/tree/main/packages/uxp-toolkit",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "https://github.com/bubblydoo/uxp-toolkit.git"
|
|
10
11
|
},
|
|
11
|
-
"homepage": "https://github.com/bubblydoo/uxp-toolkit/tree/main/packages/uxp-toolkit",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
@@ -32,10 +32,8 @@
|
|
|
32
32
|
"xmlbuilder2": "^4.0.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@adobe-uxp-types/uxp": "^0.0.9",
|
|
36
35
|
"@types/chai": "^5.2.3",
|
|
37
36
|
"@types/node": "^20.8.7",
|
|
38
|
-
"@types/photoshop": "^25.0.2",
|
|
39
37
|
"chai": "^6.2.2",
|
|
40
38
|
"dedent": "^1.7.1",
|
|
41
39
|
"rollup": "^4.57.0",
|
|
@@ -43,13 +41,16 @@
|
|
|
43
41
|
"typescript": "^5.8.3",
|
|
44
42
|
"vitest": "^4.0.18",
|
|
45
43
|
"zod": "^4.3.6",
|
|
44
|
+
"@adobe-uxp-types/photoshop": "0.1.0",
|
|
45
|
+
"@adobe-uxp-types/uxp": "0.1.0",
|
|
46
46
|
"@bubblydoo/tsconfig": "0.0.3",
|
|
47
|
-
"@bubblydoo/uxp-test-framework": "0.0.
|
|
47
|
+
"@bubblydoo/uxp-test-framework": "0.0.9"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup",
|
|
51
51
|
"test": "vitest run",
|
|
52
52
|
"uxp-test:build": "uxp-test build",
|
|
53
|
-
"uxp-test:dev": "uxp-test dev"
|
|
53
|
+
"uxp-test:dev": "uxp-test dev",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { PsLayerRef } from '../ut-tree/psLayerRef';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createCommand } from '../core/command';
|
|
4
4
|
|
|
5
5
|
export function createAddLayerToSelectionCommand(
|
|
6
6
|
layerRef: PsLayerRef,
|
|
7
|
-
previousLayerRef: PsLayerRef
|
|
7
|
+
previousLayerRef: PsLayerRef,
|
|
8
8
|
) {
|
|
9
9
|
return createCommand({
|
|
10
10
|
modifying: true,
|