@bubblydoo/uxp-toolkit 0.0.3 → 0.0.5
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 +5 -5
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +77 -58
- package/dist/index.js +196 -276
- package/package.json +6 -3
- package/src/commands-library/getDocument.ts +36 -0
- package/src/commands-library/getDocument.txt +62 -0
- package/src/commands-library/getLayer.ts +56 -0
- package/src/commands-library/getLayer.txt +186 -0
- package/src/commands-library/renameLayer.uxp-test.ts +4 -4
- package/src/core/command.test-d.ts +25 -0
- package/src/index.ts +22 -17
- package/src/ut-tree/getLayerEffects.ts +3 -26
- package/src/ut-tree/getLayerProperties.ts +46 -7
- package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +42 -0
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +114 -0
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +30 -58
- package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +36 -3
- package/src/ut-tree/utLayersToText.test.ts +94 -0
- package/src/ut-tree/utLayersToText.ts +32 -0
- package/src/ut-tree/utLayersToTree.ts +2 -1
- package/src/util/utLayerPickKeysType.ts +5 -0
- package/test/fixtures/one-layer-with-bg.psd +0 -0
- package/test/index.ts +4 -1
- package/vitest-photoshop-alias-plugin.ts +41 -0
- package/vitest.config.ts +17 -0
- package/src/commands-library/getLayerProperties.ts +0 -32
- package/src/ut-tree/getFlattenedLayerDescriptorsList.ts +0 -72
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Object
|
|
2
|
+
// EXIF: "EXIF tag 100274 Normal\rEXIF tag 100282 72.0\rEXIF tag 100283 72.0\rEXIF tag 100296 Inches\rEXIF tag 100305 Adobe Photoshop 27.3 (20251221.m.3348 0256c3c) (Macintosh)\rEXIF tag 100306 2026:01:30 11:20:57\rEXIF tag 140961 Uncalibrated\rEXIF tag 140962 100\rEXIF tag 140963 100\r"
|
|
3
|
+
// XMPMetadataAsUTF8: "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc
|
|
4
|
+
// backgroundSaveInfo: {isPendingNormalSave: false}
|
|
5
|
+
// bigNudgeH: 655360
|
|
6
|
+
// bigNudgeV: 655360
|
|
7
|
+
// center: {_obj: "paint", horizontal: {…}, vertical: {…}}
|
|
8
|
+
// clippingPathInfo: {_obj: "clippingInfo", clippingPathIndex: -1, clippingPathFlatness: 0}
|
|
9
|
+
// contentCredentialsEnabled: false
|
|
10
|
+
// copyright: false
|
|
11
|
+
// count: 3
|
|
12
|
+
// depth: 8
|
|
13
|
+
// documentID: 101
|
|
14
|
+
// duotoneInk: 0
|
|
15
|
+
// extension: (3) ["PSD", "PDD", "PSDT"]
|
|
16
|
+
// fileInfo: {_obj: "fileInfo"}
|
|
17
|
+
// fileReference: {_path: "/Users/otto/Code/projects/bubbly/uxp-toolkit/packa…t/uxp-tests-plugin/fixtures/one-layer-with-bg.psd", _kind: "local"}
|
|
18
|
+
// format: "Photoshop"
|
|
19
|
+
// genTechModelsUsed: []
|
|
20
|
+
// generatorSettings: {_obj: "generatorSettings"}
|
|
21
|
+
// guidesVisibility: true
|
|
22
|
+
// hasBackgroundLayer: true
|
|
23
|
+
// height: {_unit: "distanceUnit", _value: 100}
|
|
24
|
+
// histogram: (256) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1698, 19, 5, 10, 3, 11, 6, 7, 4, 1, 2, 2, 4, 2, 3, 0, 2, 4, 2, 0, 4, 1, 4, 1, 3, 4, 0, …]
|
|
25
|
+
// isCloudDoc: false
|
|
26
|
+
// isDirty: false
|
|
27
|
+
// isUsingGenTech: false
|
|
28
|
+
// itemIndex: 2
|
|
29
|
+
// manage: {_enum: "manage", _value: "none"}
|
|
30
|
+
// measurementScale: {_obj: "measurementScale", _target: Array(2), to: {…}}
|
|
31
|
+
// mimeType: "application/vnd.adobe.photoshop"
|
|
32
|
+
// mode: {_enum: "colorSpace", _value: "RGBColor"}
|
|
33
|
+
// numberOfChannels: 3
|
|
34
|
+
// numberOfLayers: 1
|
|
35
|
+
// numberOfPaths: 0
|
|
36
|
+
// patternPreviewMode: false
|
|
37
|
+
// pixelScaleFactor: {_unit: "noneUnit", _value: 1}
|
|
38
|
+
// printColorHandling: {_enum: "printColorHandling", _value: "printerManaged"}
|
|
39
|
+
// printCopies: 1
|
|
40
|
+
// printCurrentPrinter: "EPSON ET-8500 Series"
|
|
41
|
+
// printOutput: {_obj: "printOutput", postScriptColor: true, intent: {…}, printSixteenBit: false, printerName: "", …}
|
|
42
|
+
// printOutputOptions: {_obj: "printOutputOptions", caption: false, calibrationBars: false, registrationMarks: false, cornerCropMarks: false, …}
|
|
43
|
+
// printerList: ["Brother MFC-L3750CDW series"]
|
|
44
|
+
// quickMask: false
|
|
45
|
+
// resolution: {_unit: "densityUnit", _value: 72}
|
|
46
|
+
// rulerOriginH: 0
|
|
47
|
+
// rulerOriginV: 0
|
|
48
|
+
// rulersVisibility: true
|
|
49
|
+
// selectionEdgesVisible: false
|
|
50
|
+
// slices: {bounds: {…}, slices: Array(1)}
|
|
51
|
+
// smartGuidesVisibility: true
|
|
52
|
+
// targetLayers: [{…}]
|
|
53
|
+
// targetLayersIDs: [{…}]
|
|
54
|
+
// targetLayersIndexes: [{…}]
|
|
55
|
+
// targetPathIndex: -1
|
|
56
|
+
// targetPathVisibility: true
|
|
57
|
+
// title: "one-layer-with-bg.psd"
|
|
58
|
+
// visible: true
|
|
59
|
+
// watermark: false
|
|
60
|
+
// width: {_unit: "distanceUnit", _value: 100}
|
|
61
|
+
// workPathIndex: -1
|
|
62
|
+
// zoom: {_unit: "percentUnit", _value: 30.830188679245282}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { createCommand } from "../core/command";
|
|
3
|
+
import type { PsLayerRef } from "../ut-tree/psLayerRef";
|
|
4
|
+
|
|
5
|
+
const layerSchema = z.object({
|
|
6
|
+
name: z.string(),
|
|
7
|
+
visible: z.boolean(),
|
|
8
|
+
group: z.boolean(),
|
|
9
|
+
layerSection: z.object({
|
|
10
|
+
_value: z.enum([
|
|
11
|
+
"layerSectionStart",
|
|
12
|
+
"layerSectionEnd",
|
|
13
|
+
"layerSectionContent",
|
|
14
|
+
]),
|
|
15
|
+
_enum: z.literal("layerSectionType"),
|
|
16
|
+
}),
|
|
17
|
+
layerKind: z.number(),
|
|
18
|
+
itemIndex: z.number(),
|
|
19
|
+
background: z.boolean(),
|
|
20
|
+
mode: z.object({
|
|
21
|
+
_enum: z.literal("blendMode"),
|
|
22
|
+
_value: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
layerID: z.number(),
|
|
25
|
+
layerEffects: z.record(z.string(), z.object({
|
|
26
|
+
// "scale" does not have an "enabled" property, that's why it's optional
|
|
27
|
+
enabled: z.boolean().optional(),
|
|
28
|
+
}).or(z.array(z.object({
|
|
29
|
+
enabled: z.boolean(),
|
|
30
|
+
})))).optional(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export function createGetLayerCommand(layerRef: PsLayerRef) {
|
|
34
|
+
return createCommand({
|
|
35
|
+
modifying: false,
|
|
36
|
+
descriptor: {
|
|
37
|
+
_obj: "get",
|
|
38
|
+
_target: [
|
|
39
|
+
{ _ref: "layer", _id: layerRef.id },
|
|
40
|
+
{ _ref: "document", _id: layerRef.docId },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
schema: layerSchema,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createGetBackgroundLayerCommand(docId: number) {
|
|
48
|
+
return createCommand({
|
|
49
|
+
modifying: false,
|
|
50
|
+
descriptor: {
|
|
51
|
+
_obj: "get",
|
|
52
|
+
_target: { _ref: [{ _ref: "layer", "_property": "background" }, { _ref: "document", _id: docId }] },
|
|
53
|
+
},
|
|
54
|
+
schema: layerSchema,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layerID": 1,
|
|
3
|
+
"group": false,
|
|
4
|
+
"name": "Background",
|
|
5
|
+
"color": {
|
|
6
|
+
"_enum": "color",
|
|
7
|
+
"_value": "none"
|
|
8
|
+
},
|
|
9
|
+
"visible": true,
|
|
10
|
+
"mode": {
|
|
11
|
+
"_enum": "blendMode",
|
|
12
|
+
"_value": "normal"
|
|
13
|
+
},
|
|
14
|
+
"opacity": 255,
|
|
15
|
+
"itemIndex": 1,
|
|
16
|
+
"count": 2,
|
|
17
|
+
"preserveTransparency": true,
|
|
18
|
+
"layerFXVisible": false,
|
|
19
|
+
"globalAngle": 90,
|
|
20
|
+
"background": true,
|
|
21
|
+
"layerSection": {
|
|
22
|
+
"_enum": "layerSectionType",
|
|
23
|
+
"_value": "layerSectionContent"
|
|
24
|
+
},
|
|
25
|
+
"layerLocking": {
|
|
26
|
+
"_obj": "layerLocking",
|
|
27
|
+
"protectTransparency": true,
|
|
28
|
+
"protectComposite": false,
|
|
29
|
+
"protectPosition": true,
|
|
30
|
+
"protectArtboardAutonest": true,
|
|
31
|
+
"protectAll": false
|
|
32
|
+
},
|
|
33
|
+
"targetChannels": [
|
|
34
|
+
{
|
|
35
|
+
"_ref": "channel",
|
|
36
|
+
"_index": 1
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"_ref": "channel",
|
|
40
|
+
"_index": 2
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"_ref": "channel",
|
|
44
|
+
"_index": 3
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"visibleChannels": [
|
|
48
|
+
{
|
|
49
|
+
"_ref": "channel",
|
|
50
|
+
"_index": 1
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"_ref": "channel",
|
|
54
|
+
"_index": 2
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"_ref": "channel",
|
|
58
|
+
"_index": 3
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"channelRestrictions": [
|
|
62
|
+
{
|
|
63
|
+
"_enum": "channel",
|
|
64
|
+
"_value": "red"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"_enum": "channel",
|
|
68
|
+
"_value": "grain"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"_enum": "channel",
|
|
72
|
+
"_value": "blue"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"fillOpacity": 255,
|
|
76
|
+
"hasUserMask": false,
|
|
77
|
+
"hasVectorMask": false,
|
|
78
|
+
"proportionalScaling": false,
|
|
79
|
+
"layerKind": 1,
|
|
80
|
+
"hasFilterMask": false,
|
|
81
|
+
"userMaskDensity": 255,
|
|
82
|
+
"userMaskFeather": 0,
|
|
83
|
+
"vectorMaskDensity": 255,
|
|
84
|
+
"vectorMaskFeather": 0,
|
|
85
|
+
"filterMaskDensity": 255,
|
|
86
|
+
"filterMaskFeather": 0,
|
|
87
|
+
"bounds": {
|
|
88
|
+
"_obj": "rectangle",
|
|
89
|
+
"top": {
|
|
90
|
+
"_unit": "pixelsUnit",
|
|
91
|
+
"_value": 0
|
|
92
|
+
},
|
|
93
|
+
"left": {
|
|
94
|
+
"_unit": "pixelsUnit",
|
|
95
|
+
"_value": 0
|
|
96
|
+
},
|
|
97
|
+
"bottom": {
|
|
98
|
+
"_unit": "pixelsUnit",
|
|
99
|
+
"_value": 100
|
|
100
|
+
},
|
|
101
|
+
"right": {
|
|
102
|
+
"_unit": "pixelsUnit",
|
|
103
|
+
"_value": 100
|
|
104
|
+
},
|
|
105
|
+
"width": {
|
|
106
|
+
"_unit": "pixelsUnit",
|
|
107
|
+
"_value": 100
|
|
108
|
+
},
|
|
109
|
+
"height": {
|
|
110
|
+
"_unit": "pixelsUnit",
|
|
111
|
+
"_value": 100
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"boundsNoEffects": {
|
|
115
|
+
"_obj": "rectangle",
|
|
116
|
+
"top": {
|
|
117
|
+
"_unit": "pixelsUnit",
|
|
118
|
+
"_value": 0
|
|
119
|
+
},
|
|
120
|
+
"left": {
|
|
121
|
+
"_unit": "pixelsUnit",
|
|
122
|
+
"_value": 0
|
|
123
|
+
},
|
|
124
|
+
"bottom": {
|
|
125
|
+
"_unit": "pixelsUnit",
|
|
126
|
+
"_value": 100
|
|
127
|
+
},
|
|
128
|
+
"right": {
|
|
129
|
+
"_unit": "pixelsUnit",
|
|
130
|
+
"_value": 100
|
|
131
|
+
},
|
|
132
|
+
"width": {
|
|
133
|
+
"_unit": "pixelsUnit",
|
|
134
|
+
"_value": 100
|
|
135
|
+
},
|
|
136
|
+
"height": {
|
|
137
|
+
"_unit": "pixelsUnit",
|
|
138
|
+
"_value": 100
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"boundsNoMask": {
|
|
142
|
+
"_obj": "rectangle",
|
|
143
|
+
"top": {
|
|
144
|
+
"_unit": "pixelsUnit",
|
|
145
|
+
"_value": 0
|
|
146
|
+
},
|
|
147
|
+
"left": {
|
|
148
|
+
"_unit": "pixelsUnit",
|
|
149
|
+
"_value": 0
|
|
150
|
+
},
|
|
151
|
+
"bottom": {
|
|
152
|
+
"_unit": "pixelsUnit",
|
|
153
|
+
"_value": 100
|
|
154
|
+
},
|
|
155
|
+
"right": {
|
|
156
|
+
"_unit": "pixelsUnit",
|
|
157
|
+
"_value": 100
|
|
158
|
+
},
|
|
159
|
+
"width": {
|
|
160
|
+
"_unit": "pixelsUnit",
|
|
161
|
+
"_value": 100
|
|
162
|
+
},
|
|
163
|
+
"height": {
|
|
164
|
+
"_unit": "pixelsUnit",
|
|
165
|
+
"_value": 100
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"useAlignedRendering": false,
|
|
169
|
+
"generatorSettings": {
|
|
170
|
+
"_obj": "generatorSettings"
|
|
171
|
+
},
|
|
172
|
+
"keyOriginType": [],
|
|
173
|
+
"fillEnabled": false,
|
|
174
|
+
"animationProtection": {
|
|
175
|
+
"_obj": "animationProtection",
|
|
176
|
+
"animationUnifyPosition": false,
|
|
177
|
+
"animationUnifyEffects": false,
|
|
178
|
+
"animationUnifyVisibility": false,
|
|
179
|
+
"animationPropagate": true
|
|
180
|
+
},
|
|
181
|
+
"isSyntheticFill": false,
|
|
182
|
+
"artboardEnabled": false,
|
|
183
|
+
"vectorMaskEmpty": true,
|
|
184
|
+
"textWarningLevel": 0,
|
|
185
|
+
"parentLayerID": -1
|
|
186
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { executeAsModal } from "../core/executeAsModal";
|
|
2
2
|
import { openFileByPath } from "../filesystem/openFileByPath";
|
|
3
|
-
import {
|
|
3
|
+
import { getDocumentLayerDescriptors } from "../ut-tree/getLayerProperties";
|
|
4
4
|
import type { Test } from "@bubblydoo/uxp-test-framework";
|
|
5
5
|
import { expect } from "chai";
|
|
6
6
|
import { app } from "photoshop";
|
|
7
7
|
import { createRenameLayerCommand } from "./renameLayer";
|
|
8
8
|
|
|
9
9
|
async function getFirstLayer() {
|
|
10
|
-
const allLayers = await
|
|
10
|
+
const allLayers = await getDocumentLayerDescriptors(app.activeDocument.id);
|
|
11
11
|
return {
|
|
12
12
|
ref: {
|
|
13
13
|
id: allLayers[0]!.layerID,
|
|
@@ -15,7 +15,7 @@ async function getFirstLayer() {
|
|
|
15
15
|
},
|
|
16
16
|
name: allLayers[0]!.name,
|
|
17
17
|
};
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
export const renameLayerTest: Test = {
|
|
21
21
|
name: "Rename Layer",
|
|
@@ -29,4 +29,4 @@ export const renameLayerTest: Test = {
|
|
|
29
29
|
const layer2 = await getFirstLayer();
|
|
30
30
|
expect(layer2.name).to.equal("New Name");
|
|
31
31
|
},
|
|
32
|
-
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expectTypeOf, test } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
createCommand,
|
|
5
|
+
type UTCommandResult,
|
|
6
|
+
} from "./command";
|
|
7
|
+
|
|
8
|
+
describe("UTCommandResult type tests", () => {
|
|
9
|
+
test("extracts result type from non-modifying command", () => {
|
|
10
|
+
const command = createCommand({
|
|
11
|
+
descriptor: { _obj: "get" },
|
|
12
|
+
schema: z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
count: z.number(),
|
|
15
|
+
}),
|
|
16
|
+
modifying: false,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
type Result = UTCommandResult<typeof command>;
|
|
20
|
+
|
|
21
|
+
expectTypeOf<Result>().toEqualTypeOf<{
|
|
22
|
+
name: string;
|
|
23
|
+
count: number;
|
|
24
|
+
}>();
|
|
25
|
+
});});
|
package/src/index.ts
CHANGED
|
@@ -18,14 +18,18 @@ export {
|
|
|
18
18
|
type CorrectExecuteAsModalOptions,
|
|
19
19
|
type ExtendedExecutionContext,
|
|
20
20
|
} from "./core/executeAsModal";
|
|
21
|
-
export {
|
|
21
|
+
export {
|
|
22
|
+
suspendHistory,
|
|
23
|
+
type SuspendHistoryContext,
|
|
24
|
+
} from "./core/suspendHistory";
|
|
22
25
|
|
|
23
26
|
// Core wrappers
|
|
24
27
|
export { executeAsModalAndSuspendHistory } from "./core-wrappers/executeAsModalAndSuspendHistory";
|
|
25
28
|
|
|
26
29
|
// Commands library
|
|
27
|
-
export { getLayerProperties } from "./commands-library/getLayerProperties";
|
|
28
30
|
export { createRenameLayerCommand } from "./commands-library/renameLayer";
|
|
31
|
+
export { createGetDocumentCommand, createGetDocumentHasBackgroundLayerCommand } from "./commands-library/getDocument";
|
|
32
|
+
export { createGetBackgroundLayerCommand } from "./commands-library/getLayer";
|
|
29
33
|
|
|
30
34
|
// DOM – layers
|
|
31
35
|
export { getFlattenedDomLayersList } from "./dom/getFlattenedDomLayersList";
|
|
@@ -47,27 +51,28 @@ export { copyToClipboard, readFromClipboard } from "./other/clipboard";
|
|
|
47
51
|
export { uxpEntrypointsSchema } from "./other/uxpEntrypoints";
|
|
48
52
|
|
|
49
53
|
// UT tree – layer descriptors & Photoshop tree
|
|
50
|
-
export {
|
|
51
|
-
getFlattenedLayerDescriptorsList,
|
|
52
|
-
type LayerDescriptor,
|
|
53
|
-
} from "./ut-tree/getFlattenedLayerDescriptorsList";
|
|
54
54
|
export {
|
|
55
55
|
createGetLayerPropertiesCommand,
|
|
56
|
-
|
|
56
|
+
getDocumentLayerDescriptors as getLayerPropertiesFromUtTree,
|
|
57
57
|
} from "./ut-tree/getLayerProperties";
|
|
58
|
-
export {
|
|
59
|
-
|
|
60
|
-
getLayerEffects,
|
|
61
|
-
} from "./ut-tree/getLayerEffects";
|
|
62
|
-
export {
|
|
63
|
-
photoshopLayerDescriptorsToUTLayers,
|
|
64
|
-
type UTLayer,
|
|
65
|
-
} from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
|
|
58
|
+
export { getLayerEffects } from "./ut-tree/getLayerEffects";
|
|
59
|
+
export { type UTLayer } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
|
|
66
60
|
export { type PsLayerRef } from "./ut-tree/psLayerRef";
|
|
67
|
-
export {
|
|
61
|
+
export {
|
|
62
|
+
utLayersToTree,
|
|
63
|
+
type UTLayerWithoutChildren,
|
|
64
|
+
} from "./ut-tree/utLayersToTree";
|
|
65
|
+
|
|
66
|
+
// UT tree – text
|
|
67
|
+
export { utLayersToText as utTreeToText } from "./ut-tree/utLayersToText";
|
|
68
68
|
|
|
69
69
|
// Util
|
|
70
70
|
export { utLayerToDomLayer, utLayersToDomLayers } from "./util/utLayerToLayer";
|
|
71
|
+
export { type UTLayerPickKeys } from "./util/utLayerPickKeysType";
|
|
71
72
|
|
|
72
73
|
// Error sourcemaps
|
|
73
|
-
export {
|
|
74
|
+
export {
|
|
75
|
+
parseUxpErrorSourcemaps,
|
|
76
|
+
getBasicStackFrameAbsoluteFilePath,
|
|
77
|
+
type BasicStackFrame,
|
|
78
|
+
} from "./error-sourcemaps/sourcemaps";
|
|
@@ -1,36 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import { type PsLayerRef } from "./psLayerRef";
|
|
3
|
-
import { batchPlayCommand
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export function createGetLayerCommand(layerRef: PsLayerRef) {
|
|
7
|
-
return createCommand({
|
|
8
|
-
modifying: false,
|
|
9
|
-
descriptor: {
|
|
10
|
-
_obj: "get",
|
|
11
|
-
_target: [
|
|
12
|
-
{ _ref: "layer", _id: layerRef.id },
|
|
13
|
-
{ _ref: "document", _id: layerRef.docId },
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
schema: z.object({
|
|
17
|
-
layerID: z.number(),
|
|
18
|
-
group: z.boolean().optional(),
|
|
19
|
-
layerEffects: z.record(z.string(), z.object({
|
|
20
|
-
// "scale" does not have an "enabled" property, that's why it's optional
|
|
21
|
-
enabled: z.boolean().optional(),
|
|
22
|
-
}).or(z.array(z.object({
|
|
23
|
-
enabled: z.boolean(),
|
|
24
|
-
})))).optional(),
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
3
|
+
import { batchPlayCommand } from "../core/command";
|
|
4
|
+
import { createGetLayerCommand } from "../commands-library/getLayer";
|
|
28
5
|
|
|
29
6
|
export async function getLayerEffects(layerRef: PsLayerRef) {
|
|
30
7
|
const result = await batchPlayCommand(createGetLayerCommand(layerRef));
|
|
31
8
|
|
|
32
9
|
const data = result.layerEffects || {};
|
|
33
|
-
|
|
10
|
+
|
|
34
11
|
const effects: Record<string, boolean> = {};
|
|
35
12
|
|
|
36
13
|
for (const effect in data) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { batchPlayCommand, createCommand } from "../core/command";
|
|
2
|
+
import { batchPlayCommand, batchPlayCommands, createCommand } from "../core/command";
|
|
3
|
+
import { createGetDocumentHasBackgroundLayerCommand } from "../commands-library/getDocument";
|
|
4
|
+
import { createGetBackgroundLayerCommand } from "../commands-library/getLayer";
|
|
3
5
|
|
|
4
6
|
export function createGetLayerPropertiesCommand(docId: number) {
|
|
5
7
|
return createCommand({
|
|
@@ -8,7 +10,7 @@ export function createGetLayerPropertiesCommand(docId: number) {
|
|
|
8
10
|
_obj: "multiGet",
|
|
9
11
|
_target: { _ref: [{ _ref: "document", _id: docId }] },
|
|
10
12
|
extendedReference: [
|
|
11
|
-
["name", "layerID", "visible"],
|
|
13
|
+
["name", "layerID", "visible", "group", "layerSection", "layerKind", "itemIndex", "background", "mode", "layerEffects"],
|
|
12
14
|
{ _obj: "layer", index: 1, count: -1 },
|
|
13
15
|
],
|
|
14
16
|
},
|
|
@@ -17,7 +19,29 @@ export function createGetLayerPropertiesCommand(docId: number) {
|
|
|
17
19
|
z.object({
|
|
18
20
|
name: z.string(),
|
|
19
21
|
layerID: z.number(),
|
|
20
|
-
visible: z.boolean()
|
|
22
|
+
visible: z.boolean(),
|
|
23
|
+
group: z.boolean(),
|
|
24
|
+
layerSection: z.object({
|
|
25
|
+
_value: z.enum([
|
|
26
|
+
"layerSectionStart",
|
|
27
|
+
"layerSectionEnd",
|
|
28
|
+
"layerSectionContent",
|
|
29
|
+
]),
|
|
30
|
+
_enum: z.literal("layerSectionType"),
|
|
31
|
+
}),
|
|
32
|
+
layerKind: z.number(),
|
|
33
|
+
itemIndex: z.number(),
|
|
34
|
+
background: z.boolean(),
|
|
35
|
+
mode: z.object({
|
|
36
|
+
_enum: z.literal("blendMode"),
|
|
37
|
+
_value: z.string(),
|
|
38
|
+
}),
|
|
39
|
+
layerEffects: z.record(z.string(), z.object({
|
|
40
|
+
// "scale" does not have an "enabled" property, that's why it's optional
|
|
41
|
+
enabled: z.boolean().optional(),
|
|
42
|
+
}).or(z.array(z.object({
|
|
43
|
+
enabled: z.boolean(),
|
|
44
|
+
})))).optional(),
|
|
21
45
|
})
|
|
22
46
|
)
|
|
23
47
|
})
|
|
@@ -25,11 +49,26 @@ export function createGetLayerPropertiesCommand(docId: number) {
|
|
|
25
49
|
}
|
|
26
50
|
|
|
27
51
|
// get layer properties like name and layerID for all layers in the document (by index)
|
|
28
|
-
export const
|
|
29
|
-
const
|
|
52
|
+
export const getDocumentLayerDescriptors = async (documentId: number) => {
|
|
53
|
+
const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
|
|
54
|
+
createGetLayerPropertiesCommand(documentId),
|
|
55
|
+
createGetDocumentHasBackgroundLayerCommand(documentId),
|
|
56
|
+
]);
|
|
30
57
|
|
|
31
|
-
const
|
|
58
|
+
const backgroundLayerResult = documentHasBackgroundLayerResult.hasBackgroundLayer ? await batchPlayCommand(createGetBackgroundLayerCommand(documentId)) : null;
|
|
59
|
+
|
|
60
|
+
const list = [...layersResult.list].reverse();
|
|
61
|
+
if (backgroundLayerResult) {
|
|
62
|
+
list.push(backgroundLayerResult);
|
|
63
|
+
}
|
|
32
64
|
|
|
33
65
|
// Reverse to get bottom-up order
|
|
34
|
-
return
|
|
66
|
+
return list.map((layerProp) => {
|
|
67
|
+
return {
|
|
68
|
+
...layerProp,
|
|
69
|
+
docId: documentId,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
35
72
|
};
|
|
73
|
+
|
|
74
|
+
export type LayerDescriptor = Awaited<ReturnType<typeof getDocumentLayerDescriptors>>[number];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { app } from "photoshop";
|
|
2
|
+
import { openFileByPath } from "../filesystem/openFileByPath";
|
|
3
|
+
import { batchPlayCommand } from "../core/command";
|
|
4
|
+
import { expect } from "chai";
|
|
5
|
+
import { createGetDocumentHasBackgroundLayerCommand } from "../commands-library/getDocument";
|
|
6
|
+
import type { Test } from "@bubblydoo/uxp-test-framework";
|
|
7
|
+
import { createGetBackgroundLayerCommand } from "../commands-library/getLayer";
|
|
8
|
+
import { executeAsModal } from "../core/executeAsModal";
|
|
9
|
+
|
|
10
|
+
export const backgroundLayerTest: Test = {
|
|
11
|
+
name: "Has/Get Background Layer",
|
|
12
|
+
async run() {
|
|
13
|
+
const doc = await openFileByPath("plugin:/fixtures/one-layer-with-bg.psd");
|
|
14
|
+
const hasBackgroundLayer = await batchPlayCommand(
|
|
15
|
+
createGetDocumentHasBackgroundLayerCommand(doc.id)
|
|
16
|
+
)
|
|
17
|
+
expect(hasBackgroundLayer.hasBackgroundLayer).to.be.true;
|
|
18
|
+
const layer = await batchPlayCommand(
|
|
19
|
+
createGetBackgroundLayerCommand(app.activeDocument.id)
|
|
20
|
+
)
|
|
21
|
+
expect(layer.name).to.equal("Background");
|
|
22
|
+
await executeAsModal("Close Document", async () => await doc.close(0));
|
|
23
|
+
|
|
24
|
+
const doc2 = await openFileByPath("plugin:/fixtures/one-layer.psd");
|
|
25
|
+
|
|
26
|
+
const hasBackgroundLayer2 = await batchPlayCommand(
|
|
27
|
+
createGetDocumentHasBackgroundLayerCommand(doc2.id)
|
|
28
|
+
)
|
|
29
|
+
expect(hasBackgroundLayer2.hasBackgroundLayer).to.be.false;
|
|
30
|
+
let rejected = false;
|
|
31
|
+
try {
|
|
32
|
+
await batchPlayCommand(
|
|
33
|
+
createGetBackgroundLayerCommand(doc2.id)
|
|
34
|
+
)
|
|
35
|
+
} catch (e) {
|
|
36
|
+
rejected = true;
|
|
37
|
+
}
|
|
38
|
+
expect(rejected).to.be.true;
|
|
39
|
+
|
|
40
|
+
await executeAsModal("Close Document", async () => await doc2.close(0));
|
|
41
|
+
},
|
|
42
|
+
};
|