@bubblydoo/uxp-toolkit 0.0.8 → 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 +6 -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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { createGetDocumentHasBackgroundLayerCommand } from '../commands-library/getDocument';
|
|
2
|
+
import { createGetBackgroundLayerCommand } from '../commands-library/getLayer';
|
|
3
|
+
import { createMultiGetDocumentCommand } from '../commands-library/multiGetDocument';
|
|
4
|
+
import { batchPlayCommand, batchPlayCommands } from '../core/command';
|
|
5
5
|
|
|
6
6
|
// get layer properties like name and layerID for all layers in the document (by index)
|
|
7
|
-
export
|
|
7
|
+
export async function getDocumentLayerDescriptors(documentId: number) {
|
|
8
8
|
const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
|
|
9
9
|
createMultiGetDocumentCommand(documentId),
|
|
10
10
|
createGetDocumentHasBackgroundLayerCommand(documentId),
|
|
@@ -24,6 +24,6 @@ export const getDocumentLayerDescriptors = async (documentId: number) => {
|
|
|
24
24
|
docId: documentId,
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
export type LayerDescriptor = Awaited<ReturnType<typeof getDocumentLayerDescriptors>>[number];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { batchPlayCommand } from
|
|
4
|
-
import { createGetLayerCommand } from "../commands-library/getLayer";
|
|
1
|
+
import type { PsLayerRef } from './psLayerRef';
|
|
2
|
+
import { createGetLayerCommand } from '../commands-library/getLayer';
|
|
3
|
+
import { batchPlayCommand } from '../core/command';
|
|
5
4
|
|
|
6
5
|
export async function getLayerEffects(layerRef: PsLayerRef) {
|
|
7
6
|
const result = await batchPlayCommand(createGetLayerCommand(layerRef));
|
|
@@ -11,7 +10,8 @@ export async function getLayerEffects(layerRef: PsLayerRef) {
|
|
|
11
10
|
const effects: Record<string, boolean> = {};
|
|
12
11
|
|
|
13
12
|
for (const effect in data) {
|
|
14
|
-
if (effect !==
|
|
13
|
+
if (effect !== 'scale')
|
|
14
|
+
effects[effect] = Array.isArray(data[effect]) ? data[effect].some(e => e.enabled) : !!data[effect]?.enabled;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
return effects;
|
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createGetDocumentHasBackgroundLayerCommand } from
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { executeAsModal } from
|
|
1
|
+
/* eslint-disable ts/no-unused-expressions */
|
|
2
|
+
import type { Test } from '@bubblydoo/uxp-test-framework';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
import { app } from 'photoshop';
|
|
5
|
+
import { createGetDocumentHasBackgroundLayerCommand } from '../commands-library/getDocument';
|
|
6
|
+
import { createGetBackgroundLayerCommand } from '../commands-library/getLayer';
|
|
7
|
+
import { batchPlayCommand } from '../core/command';
|
|
8
|
+
import { executeAsModal } from '../core/executeAsModal';
|
|
9
|
+
import { openFileByPath } from '../filesystem/openFileByPath';
|
|
9
10
|
|
|
10
11
|
export const backgroundLayerTest: Test = {
|
|
11
|
-
name:
|
|
12
|
+
name: 'Has/Get Background Layer',
|
|
12
13
|
async run() {
|
|
13
|
-
const doc = await openFileByPath(
|
|
14
|
+
const doc = await openFileByPath('plugin:/fixtures/one-layer-with-bg.psd');
|
|
14
15
|
const hasBackgroundLayer = await batchPlayCommand(
|
|
15
|
-
createGetDocumentHasBackgroundLayerCommand(doc.id)
|
|
16
|
-
)
|
|
16
|
+
createGetDocumentHasBackgroundLayerCommand(doc.id),
|
|
17
|
+
);
|
|
17
18
|
expect(hasBackgroundLayer.hasBackgroundLayer).to.be.true;
|
|
18
19
|
const layer = await batchPlayCommand(
|
|
19
|
-
createGetBackgroundLayerCommand(app.activeDocument.id)
|
|
20
|
-
)
|
|
21
|
-
expect(layer.name).to.equal(
|
|
22
|
-
await executeAsModal(
|
|
20
|
+
createGetBackgroundLayerCommand(app.activeDocument.id),
|
|
21
|
+
);
|
|
22
|
+
expect(layer.name).to.equal('Background');
|
|
23
|
+
await executeAsModal('Close Document', async () => await doc.close(0));
|
|
23
24
|
|
|
24
|
-
const doc2 = await openFileByPath(
|
|
25
|
+
const doc2 = await openFileByPath('plugin:/fixtures/one-layer.psd');
|
|
25
26
|
|
|
26
27
|
const hasBackgroundLayer2 = await batchPlayCommand(
|
|
27
|
-
createGetDocumentHasBackgroundLayerCommand(doc2.id)
|
|
28
|
-
)
|
|
28
|
+
createGetDocumentHasBackgroundLayerCommand(doc2.id),
|
|
29
|
+
);
|
|
29
30
|
expect(hasBackgroundLayer2.hasBackgroundLayer).to.be.false;
|
|
30
31
|
let rejected = false;
|
|
31
32
|
try {
|
|
32
33
|
await batchPlayCommand(
|
|
33
|
-
createGetBackgroundLayerCommand(doc2.id)
|
|
34
|
-
)
|
|
35
|
-
}
|
|
34
|
+
createGetBackgroundLayerCommand(doc2.id),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
36
38
|
rejected = true;
|
|
37
39
|
}
|
|
38
40
|
expect(rejected).to.be.true;
|
|
39
41
|
|
|
40
|
-
await executeAsModal(
|
|
42
|
+
await executeAsModal('Close Document', async () => await doc2.close(0));
|
|
41
43
|
},
|
|
42
44
|
};
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { expect, it } from
|
|
2
|
-
import { photoshopLayerDescriptorsToUTLayers } from
|
|
3
|
-
import { utLayersToText } from
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { photoshopLayerDescriptorsToUTLayers } from './photoshopLayerDescriptorsToUTLayers';
|
|
3
|
+
import { utLayersToText } from './utLayersToText';
|
|
4
4
|
|
|
5
|
-
it(
|
|
5
|
+
it('parses a flat list correctly', async () => {
|
|
6
6
|
expect(
|
|
7
7
|
utLayersToText(
|
|
8
8
|
photoshopLayerDescriptorsToUTLayers(
|
|
9
9
|
[
|
|
10
10
|
{
|
|
11
|
-
name:
|
|
11
|
+
name: 'circle',
|
|
12
12
|
layerID: 4,
|
|
13
13
|
mode: {
|
|
14
|
-
_enum:
|
|
15
|
-
_value:
|
|
14
|
+
_enum: 'blendMode',
|
|
15
|
+
_value: 'normal',
|
|
16
16
|
},
|
|
17
17
|
background: false,
|
|
18
18
|
itemIndex: 5,
|
|
19
19
|
visible: true,
|
|
20
20
|
layerKind: 1,
|
|
21
21
|
layerSection: {
|
|
22
|
-
_value:
|
|
23
|
-
_enum:
|
|
22
|
+
_value: 'layerSectionContent',
|
|
23
|
+
_enum: 'layerSectionType',
|
|
24
24
|
},
|
|
25
25
|
docId: 70,
|
|
26
26
|
layerEffects: {},
|
|
27
27
|
group: true,
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
name:
|
|
30
|
+
name: 'group',
|
|
31
31
|
layerID: 6,
|
|
32
32
|
mode: {
|
|
33
|
-
_enum:
|
|
34
|
-
_value:
|
|
33
|
+
_enum: 'blendMode',
|
|
34
|
+
_value: 'passThrough',
|
|
35
35
|
},
|
|
36
36
|
background: false,
|
|
37
37
|
itemIndex: 4,
|
|
38
38
|
visible: true,
|
|
39
39
|
layerKind: 7,
|
|
40
40
|
layerSection: {
|
|
41
|
-
_value:
|
|
42
|
-
_enum:
|
|
41
|
+
_value: 'layerSectionStart',
|
|
42
|
+
_enum: 'layerSectionType',
|
|
43
43
|
},
|
|
44
44
|
docId: 70,
|
|
45
45
|
layerEffects: {},
|
|
46
46
|
group: false,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
name:
|
|
49
|
+
name: 'green square',
|
|
50
50
|
layerID: 3,
|
|
51
51
|
mode: {
|
|
52
|
-
_enum:
|
|
53
|
-
_value:
|
|
52
|
+
_enum: 'blendMode',
|
|
53
|
+
_value: 'normal',
|
|
54
54
|
},
|
|
55
55
|
background: false,
|
|
56
56
|
itemIndex: 3,
|
|
57
57
|
visible: true,
|
|
58
58
|
layerKind: 1,
|
|
59
59
|
layerSection: {
|
|
60
|
-
_value:
|
|
61
|
-
_enum:
|
|
60
|
+
_value: 'layerSectionContent',
|
|
61
|
+
_enum: 'layerSectionType',
|
|
62
62
|
},
|
|
63
63
|
docId: 70,
|
|
64
64
|
layerEffects: {},
|
|
65
65
|
group: true,
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
|
-
name:
|
|
68
|
+
name: 'red square',
|
|
69
69
|
layerID: 2,
|
|
70
70
|
mode: {
|
|
71
|
-
_enum:
|
|
72
|
-
_value:
|
|
71
|
+
_enum: 'blendMode',
|
|
72
|
+
_value: 'normal',
|
|
73
73
|
},
|
|
74
74
|
background: false,
|
|
75
75
|
itemIndex: 2,
|
|
76
76
|
visible: true,
|
|
77
77
|
layerKind: 1,
|
|
78
78
|
layerSection: {
|
|
79
|
-
_value:
|
|
80
|
-
_enum:
|
|
79
|
+
_value: 'layerSectionContent',
|
|
80
|
+
_enum: 'layerSectionType',
|
|
81
81
|
},
|
|
82
82
|
docId: 70,
|
|
83
83
|
layerEffects: {},
|
|
84
84
|
group: false,
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
name:
|
|
87
|
+
name: '</Layer group>',
|
|
88
88
|
layerID: 7,
|
|
89
89
|
mode: {
|
|
90
|
-
_enum:
|
|
91
|
-
_value:
|
|
90
|
+
_enum: 'blendMode',
|
|
91
|
+
_value: 'passThrough',
|
|
92
92
|
},
|
|
93
93
|
background: false,
|
|
94
94
|
itemIndex: 1,
|
|
95
95
|
visible: true,
|
|
96
96
|
layerKind: 13,
|
|
97
97
|
layerSection: {
|
|
98
|
-
_value:
|
|
99
|
-
_enum:
|
|
98
|
+
_value: 'layerSectionEnd',
|
|
99
|
+
_enum: 'layerSectionType',
|
|
100
100
|
},
|
|
101
101
|
docId: 70,
|
|
102
102
|
layerEffects: {},
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { LayerDescriptor } from
|
|
1
|
+
import type { LayerDescriptor } from './getDocumentLayerDescriptors';
|
|
2
2
|
|
|
3
|
-
type UTLayerKind =
|
|
3
|
+
type UTLayerKind = 'pixel' | 'adjustment-layer' | 'text' | 'curves' | 'smartObject' | 'video' | 'group' | 'threeD' | 'gradientFill' | 'pattern' | 'solidColor' | 'background';
|
|
4
4
|
|
|
5
|
-
type UTBlendMode =
|
|
5
|
+
type UTBlendMode = 'normal' | 'dissolve' | 'darken' | 'multiply' | 'colorBurn' | 'linearBurn' | 'darkerColor' | 'lighten' | 'screen' | 'colorDodge' | 'linearDodge' | 'lighterColor' | 'overlay' | 'softLight' | 'hardLight' | 'vividLight' | 'linearLight' | 'pinLight' | 'hardMix' | 'difference' | 'exclusion' | 'blendSubtraction' | 'blendDivide' | 'hue' | 'saturation' | 'color' | 'luminosity' | 'passThrough';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface UTLayerBuilder {
|
|
8
8
|
name: string;
|
|
9
9
|
docId: number;
|
|
10
10
|
id: number;
|
|
@@ -15,75 +15,75 @@ type UTLayerBuilder = {
|
|
|
15
15
|
isClippingMask: boolean;
|
|
16
16
|
background: boolean;
|
|
17
17
|
layers?: UTLayerBuilder[];
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
export type UTLayer = Readonly<Omit<UTLayerBuilder,
|
|
20
|
+
export type UTLayer = Readonly<Omit<UTLayerBuilder, 'layers'>> & {
|
|
21
21
|
layers?: UTLayer[];
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export type UTLayerMultiGetOnly = Omit<UTLayer,
|
|
24
|
+
export type UTLayerMultiGetOnly = Omit<UTLayer, 'effects'>;
|
|
25
25
|
|
|
26
26
|
const layerKindMap = new Map<number, UTLayerKind>([
|
|
27
|
-
[1,
|
|
28
|
-
[2,
|
|
29
|
-
[3,
|
|
30
|
-
[4,
|
|
31
|
-
[5,
|
|
32
|
-
[6,
|
|
33
|
-
[7,
|
|
34
|
-
[8,
|
|
35
|
-
[9,
|
|
36
|
-
[10,
|
|
37
|
-
[11,
|
|
38
|
-
[12,
|
|
27
|
+
[1, 'pixel'],
|
|
28
|
+
[2, 'adjustment-layer'], // All adjustment layers
|
|
29
|
+
[3, 'text'],
|
|
30
|
+
[4, 'curves'],
|
|
31
|
+
[5, 'smartObject'],
|
|
32
|
+
[6, 'video'],
|
|
33
|
+
[7, 'group'],
|
|
34
|
+
[8, 'threeD'],
|
|
35
|
+
[9, 'gradientFill'],
|
|
36
|
+
[10, 'pattern'],
|
|
37
|
+
[11, 'solidColor'],
|
|
38
|
+
[12, 'background'], // according to the internet but the actual value is undefined
|
|
39
39
|
]);
|
|
40
40
|
|
|
41
41
|
const blendModes: string[] = [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
'normal',
|
|
43
|
+
'dissolve',
|
|
44
|
+
'darken',
|
|
45
|
+
'multiply',
|
|
46
|
+
'colorBurn',
|
|
47
|
+
'linearBurn',
|
|
48
|
+
'darkerColor',
|
|
49
|
+
'lighten',
|
|
50
|
+
'screen',
|
|
51
|
+
'colorDodge',
|
|
52
|
+
'linearDodge',
|
|
53
|
+
'lighterColor',
|
|
54
|
+
'overlay',
|
|
55
|
+
'softLight',
|
|
56
|
+
'hardLight',
|
|
57
|
+
'vividLight',
|
|
58
|
+
'linearLight',
|
|
59
|
+
'pinLight',
|
|
60
|
+
'hardMix',
|
|
61
|
+
'difference',
|
|
62
|
+
'exclusion',
|
|
63
|
+
'blendSubtraction',
|
|
64
|
+
'blendDivide',
|
|
65
|
+
'hue',
|
|
66
|
+
'saturation',
|
|
67
|
+
'color',
|
|
68
|
+
'luminosity',
|
|
69
|
+
'passThrough',
|
|
70
70
|
] satisfies UTBlendMode[];
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
function getLayerKind(layer: LayerDescriptor): UTLayerKind {
|
|
73
73
|
const kind = layerKindMap.get(layer.layerKind);
|
|
74
74
|
if (!kind) {
|
|
75
75
|
throw new Error(`Unknown layer kind: ${layer.layerKind}`);
|
|
76
76
|
}
|
|
77
77
|
return kind;
|
|
78
|
-
}
|
|
78
|
+
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
function getBlendMode(layer: LayerDescriptor): UTBlendMode {
|
|
81
81
|
const mode = layer.mode._value;
|
|
82
82
|
if (!blendModes.includes(mode)) {
|
|
83
83
|
throw new Error(`Unknown blend mode: ${mode}`);
|
|
84
84
|
}
|
|
85
85
|
return mode as UTBlendMode;
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
export function photoshopLayerDescriptorsToUTLayers(layers: LayerDescriptor[]): UTLayer[] {
|
|
89
89
|
const root: UTLayerBuilder[] = [];
|
|
@@ -96,7 +96,7 @@ export function photoshopLayerDescriptorsToUTLayers(layers: LayerDescriptor[]):
|
|
|
96
96
|
const sectionType = determineLayerSection(layer);
|
|
97
97
|
|
|
98
98
|
// Handle group end
|
|
99
|
-
if (sectionType ===
|
|
99
|
+
if (sectionType === 'end') {
|
|
100
100
|
if (stack.length > 1) {
|
|
101
101
|
stack.pop();
|
|
102
102
|
}
|
|
@@ -121,7 +121,7 @@ export function photoshopLayerDescriptorsToUTLayers(layers: LayerDescriptor[]):
|
|
|
121
121
|
current!.layers.push(node);
|
|
122
122
|
|
|
123
123
|
// Handle group start
|
|
124
|
-
if (sectionType ===
|
|
124
|
+
if (sectionType === 'start') {
|
|
125
125
|
node.layers = [];
|
|
126
126
|
// Push children array to stack to process content
|
|
127
127
|
stack.push({ layers: node.layers });
|
|
@@ -132,22 +132,22 @@ export function photoshopLayerDescriptorsToUTLayers(layers: LayerDescriptor[]):
|
|
|
132
132
|
return root as UTLayer[];
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
function determineLayerSection(layer: LayerDescriptor): 'start' | 'end' | 'normal' {
|
|
136
136
|
const section = layer.layerSection._value;
|
|
137
|
-
const isGroupEnd
|
|
138
|
-
layer.name ===
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
const isGroupEnd
|
|
138
|
+
= layer.name === '</Layer group>'
|
|
139
|
+
|| layer.name === '</Layer set>'
|
|
140
|
+
|| section === 'layerSectionEnd';
|
|
141
141
|
|
|
142
|
-
const isGroupStart = section ===
|
|
143
|
-
return isGroupStart ?
|
|
144
|
-
}
|
|
142
|
+
const isGroupStart = section === 'layerSectionStart';
|
|
143
|
+
return isGroupStart ? 'start' : isGroupEnd ? 'end' : 'normal';
|
|
144
|
+
}
|
|
145
145
|
|
|
146
146
|
function getEffects(layer: LayerDescriptor): Record<string, boolean> {
|
|
147
147
|
const effects: Record<string, boolean> = {};
|
|
148
148
|
if (layer.layerEffects) {
|
|
149
149
|
for (const effect in layer.layerEffects) {
|
|
150
|
-
effects[effect] = Array.isArray(layer.layerEffects[effect]) ? layer.layerEffects[effect].some(
|
|
150
|
+
effects[effect] = Array.isArray(layer.layerEffects[effect]) ? layer.layerEffects[effect].some(e => e.enabled) : !!layer.layerEffects[effect]?.enabled;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
return effects;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Test } from
|
|
2
|
-
import {
|
|
3
|
-
import { openFileByPath } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { Test } from '@bubblydoo/uxp-test-framework';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { openFileByPath } from '../filesystem/openFileByPath';
|
|
4
|
+
import { getDocumentLayerDescriptors } from './getDocumentLayerDescriptors';
|
|
5
|
+
import { photoshopLayerDescriptorsToUTLayers } from './photoshopLayerDescriptorsToUTLayers';
|
|
6
6
|
|
|
7
7
|
export const photoshopLayerDescriptorsToUTLayersTest: Test = {
|
|
8
|
-
name:
|
|
9
|
-
description:
|
|
8
|
+
name: 'photoshopLayerDescriptorsToUTLayers',
|
|
9
|
+
description: 'Test the photoshopLayerDescriptorsToUTLayers function',
|
|
10
10
|
run: async () => {
|
|
11
|
-
const doc = await openFileByPath(
|
|
11
|
+
const doc = await openFileByPath('plugin:/fixtures/clipping-layers.psd');
|
|
12
12
|
const descriptors = await getDocumentLayerDescriptors(doc.id);
|
|
13
13
|
|
|
14
14
|
console.log(descriptors);
|
|
@@ -16,35 +16,35 @@ export const photoshopLayerDescriptorsToUTLayersTest: Test = {
|
|
|
16
16
|
const layers = photoshopLayerDescriptorsToUTLayers(descriptors);
|
|
17
17
|
expect(layers).to.containSubset([
|
|
18
18
|
{
|
|
19
|
-
name:
|
|
19
|
+
name: 'circle',
|
|
20
20
|
visible: true,
|
|
21
|
-
kind:
|
|
22
|
-
blendMode:
|
|
21
|
+
kind: 'pixel',
|
|
22
|
+
blendMode: 'normal',
|
|
23
23
|
isClippingMask: true,
|
|
24
24
|
effects: {},
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
name:
|
|
27
|
+
name: 'group',
|
|
28
28
|
visible: true,
|
|
29
|
-
kind:
|
|
30
|
-
blendMode:
|
|
29
|
+
kind: 'group',
|
|
30
|
+
blendMode: 'passThrough',
|
|
31
31
|
isClippingMask: false,
|
|
32
32
|
effects: {},
|
|
33
33
|
layers: [
|
|
34
34
|
{
|
|
35
|
-
name:
|
|
35
|
+
name: 'green square',
|
|
36
36
|
visible: true,
|
|
37
|
-
kind:
|
|
38
|
-
blendMode:
|
|
37
|
+
kind: 'pixel',
|
|
38
|
+
blendMode: 'normal',
|
|
39
39
|
isClippingMask: true,
|
|
40
40
|
effects: {},
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
name:
|
|
43
|
+
name: 'red square',
|
|
44
44
|
id: 2,
|
|
45
45
|
visible: true,
|
|
46
|
-
kind:
|
|
47
|
-
blendMode:
|
|
46
|
+
kind: 'pixel',
|
|
47
|
+
blendMode: 'normal',
|
|
48
48
|
isClippingMask: false,
|
|
49
49
|
effects: {},
|
|
50
50
|
},
|
|
@@ -55,28 +55,28 @@ export const photoshopLayerDescriptorsToUTLayersTest: Test = {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
export const photoshopLayerDescriptorsToUTLayersTest2: Test = {
|
|
58
|
-
name:
|
|
59
|
-
description:
|
|
58
|
+
name: 'photoshopLayerDescriptorsToUTLayers',
|
|
59
|
+
description: 'Test the photoshopLayerDescriptorsToUTLayers function',
|
|
60
60
|
run: async () => {
|
|
61
|
-
const doc = await openFileByPath(
|
|
61
|
+
const doc = await openFileByPath('plugin:/fixtures/one-layer-with-bg.psd');
|
|
62
62
|
const descriptors = await getDocumentLayerDescriptors(doc.id);
|
|
63
63
|
console.log(descriptors);
|
|
64
64
|
const layers = photoshopLayerDescriptorsToUTLayers(descriptors);
|
|
65
65
|
console.log(layers);
|
|
66
66
|
expect(layers).to.containSubset([
|
|
67
67
|
{
|
|
68
|
-
name:
|
|
68
|
+
name: 'Layer 1',
|
|
69
69
|
visible: true,
|
|
70
|
-
kind:
|
|
71
|
-
blendMode:
|
|
70
|
+
kind: 'pixel',
|
|
71
|
+
blendMode: 'normal',
|
|
72
72
|
isClippingMask: false,
|
|
73
73
|
effects: {},
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
|
-
name:
|
|
76
|
+
name: 'Background',
|
|
77
77
|
visible: true,
|
|
78
|
-
kind:
|
|
79
|
-
blendMode:
|
|
78
|
+
kind: 'background',
|
|
79
|
+
blendMode: 'normal',
|
|
80
80
|
isClippingMask: false,
|
|
81
81
|
effects: {},
|
|
82
82
|
},
|