@bubblydoo/uxp-toolkit 0.0.5 → 0.0.7

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.
Files changed (31) hide show
  1. package/.turbo/turbo-build.log +10 -6
  2. package/CHANGELOG.md +12 -0
  3. package/dist/chunk-3CLJMC63.js +234 -0
  4. package/dist/commands-library/index.d.ts +110 -0
  5. package/dist/commands-library/index.js +402 -0
  6. package/dist/index.d.ts +8 -103
  7. package/dist/index.js +156 -271
  8. package/dist/psLayerRef-OY3h7srv.d.ts +70 -0
  9. package/package.json +7 -3
  10. package/src/commands-library/addLayerToSelection.ts +33 -0
  11. package/src/commands-library/applyLayerMask.ts +42 -0
  12. package/src/commands-library/convertMode.ts +13 -0
  13. package/src/commands-library/createColorLookupAdjustmentLayer.ts +24 -0
  14. package/src/commands-library/expandFolder.ts +21 -0
  15. package/src/commands-library/exportLUTs.ts +45 -0
  16. package/src/commands-library/hasVectorMask.ts +23 -0
  17. package/src/commands-library/index.ts +29 -0
  18. package/src/commands-library/loadLayerMaskAsSelection.ts +31 -0
  19. package/src/{ut-tree/getLayerProperties.ts → commands-library/multiGetDocument.ts} +2 -29
  20. package/src/commands-library/rasterizeLayerStyle.ts +15 -0
  21. package/src/commands-library/rasterizeVectorMask.ts +23 -0
  22. package/src/commands-library/removeLayerMask.ts +19 -0
  23. package/src/commands-library/renameLayer.uxp-test.ts +1 -1
  24. package/src/commands-library/renderGrid.ts +13 -0
  25. package/src/commands-library/selectLayer.ts +26 -0
  26. package/src/commands-library/set3DLUTColorLookup.ts +61 -0
  27. package/src/index.ts +6 -10
  28. package/src/ut-tree/getDocumentLayerDescriptors.ts +29 -0
  29. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +1 -1
  30. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +1 -1
  31. package/tsup.config.ts +9 -9
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+ import type { PsLayerRef } from "../ut-tree/psLayerRef";
4
+
5
+ export function createExpandFolderCommand(layerRef: PsLayerRef) {
6
+ return createCommand({
7
+ modifying: true,
8
+ descriptor: {
9
+ _obj: 'set',
10
+ _target: {
11
+ _ref: [
12
+ { _property: 'layerSectionExpanded' },
13
+ { _ref: 'layer', _id: layerRef.id },
14
+ { _ref: 'document', _id: layerRef.docId }
15
+ ],
16
+ },
17
+ to: true,
18
+ },
19
+ schema: z.unknown(),
20
+ });
21
+ }
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export type LUTExportFormat = 'CUBE' | 'ICC' | '3DL' | 'CSP';
5
+
6
+ export interface ExportLUTsOptions {
7
+ description?: string;
8
+ gridPoints?: number;
9
+ copyright?: string;
10
+ exportFormats?: LUTExportFormat[];
11
+ lowercaseExtension?: boolean;
12
+ }
13
+
14
+ export function createExportLUTsCommand(
15
+ path: string,
16
+ options: ExportLUTsOptions = {}
17
+ ) {
18
+ const {
19
+ description = 'Exported LUT',
20
+ gridPoints = 32,
21
+ copyright = 'Copyright',
22
+ exportFormats = ['CUBE', 'ICC', '3DL', 'CSP'] as LUTExportFormat[],
23
+ lowercaseExtension = false,
24
+ } = options;
25
+
26
+ return createCommand({
27
+ modifying: true,
28
+ descriptor: {
29
+ _obj: 'export',
30
+ using: {
31
+ _obj: '$lut ',
32
+ $fpth: path,
33
+ $dscr: description,
34
+ $gPts: gridPoints,
35
+ copyright: copyright,
36
+ $wICC: exportFormats.includes('ICC'),
37
+ $w3DL: exportFormats.includes('3DL'),
38
+ $wCUB: exportFormats.includes('CUBE'),
39
+ $wCSP: exportFormats.includes('CSP'),
40
+ $lcFE: lowercaseExtension,
41
+ },
42
+ },
43
+ schema: z.unknown(),
44
+ });
45
+ }
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export function createHasVectorMaskCommand(layerId: number) {
5
+ return createCommand({
6
+ modifying: false,
7
+ descriptor: {
8
+ _obj: 'get',
9
+ _target: [
10
+ {
11
+ _property: 'hasVectorMask',
12
+ },
13
+ {
14
+ _ref: 'layer',
15
+ _id: layerId,
16
+ },
17
+ ],
18
+ },
19
+ schema: z.object({
20
+ hasVectorMask: z.boolean(),
21
+ }),
22
+ });
23
+ }
@@ -0,0 +1,29 @@
1
+ // Layer selection and manipulation
2
+ export * from './selectLayer';
3
+ export * from './addLayerToSelection';
4
+ export * from './expandFolder';
5
+
6
+ // Layer operations
7
+ export * from './getLayer';
8
+ export * from './renameLayer';
9
+ export * from './rasterizeLayerStyle';
10
+ export * from './rasterizeVectorMask';
11
+
12
+ // Layer mask operations
13
+ export * from './applyLayerMask';
14
+ export * from './removeLayerMask';
15
+ export * from './loadLayerMaskAsSelection';
16
+ export * from './hasVectorMask';
17
+
18
+ // Document operations
19
+ export * from './getDocument';
20
+ export * from './multiGetDocument';
21
+ export * from './convertMode';
22
+
23
+ // Color and LUT operations
24
+ export * from './createColorLookupAdjustmentLayer';
25
+ export * from './set3DLUTColorLookup';
26
+ export * from './exportLUTs';
27
+
28
+ // Other
29
+ export * from './renderGrid';
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export function createLoadLayerMaskAsSelectionCommand(layerId: number) {
5
+ return createCommand({
6
+ modifying: true,
7
+ descriptor: {
8
+ _obj: 'set',
9
+ _target: [
10
+ {
11
+ _ref: 'channel',
12
+ _property: 'selection',
13
+ },
14
+ ],
15
+ to: {
16
+ _ref: [
17
+ {
18
+ _ref: 'channel',
19
+ _enum: 'channel',
20
+ _value: 'mask',
21
+ },
22
+ {
23
+ _ref: 'layer',
24
+ _id: layerId,
25
+ },
26
+ ],
27
+ },
28
+ },
29
+ schema: z.unknown(),
30
+ });
31
+ }
@@ -1,9 +1,7 @@
1
1
  import { z } from "zod";
2
- import { batchPlayCommand, batchPlayCommands, createCommand } from "../core/command";
3
- import { createGetDocumentHasBackgroundLayerCommand } from "../commands-library/getDocument";
4
- import { createGetBackgroundLayerCommand } from "../commands-library/getLayer";
2
+ import { createCommand } from "../core/command";
5
3
 
6
- export function createGetLayerPropertiesCommand(docId: number) {
4
+ export function createMultiGetDocumentCommand(docId: number) {
7
5
  return createCommand({
8
6
  modifying: false,
9
7
  descriptor: {
@@ -47,28 +45,3 @@ export function createGetLayerPropertiesCommand(docId: number) {
47
45
  })
48
46
  });
49
47
  }
50
-
51
- // get layer properties like name and layerID for all layers in the document (by index)
52
- export const getDocumentLayerDescriptors = async (documentId: number) => {
53
- const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
54
- createGetLayerPropertiesCommand(documentId),
55
- createGetDocumentHasBackgroundLayerCommand(documentId),
56
- ]);
57
-
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
- }
64
-
65
- // Reverse to get bottom-up order
66
- return list.map((layerProp) => {
67
- return {
68
- ...layerProp,
69
- docId: documentId,
70
- };
71
- });
72
- };
73
-
74
- export type LayerDescriptor = Awaited<ReturnType<typeof getDocumentLayerDescriptors>>[number];
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+ import type { PsLayerRef } from "../ut-tree/psLayerRef";
4
+
5
+ export function createRasterizeLayerStyleCommand(psLayerRef: PsLayerRef) {
6
+ return createCommand({
7
+ modifying: true,
8
+ descriptor: {
9
+ _obj: 'rasterizeLayer',
10
+ _target: [{ _ref: 'layer', _id: psLayerRef.id }, { _ref: 'document', _id: psLayerRef.docId }],
11
+ what: { _enum: 'rasterizeItem', _value: 'layerStyle' },
12
+ },
13
+ schema: z.unknown(),
14
+ });
15
+ }
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export function createRasterizeVectorMaskCommand() {
5
+ return createCommand({
6
+ modifying: true,
7
+ descriptor: {
8
+ _obj: 'rasterizeLayer',
9
+ _target: [
10
+ {
11
+ _ref: 'layer',
12
+ _enum: 'ordinal',
13
+ _value: 'targetEnum',
14
+ },
15
+ ],
16
+ what: {
17
+ _enum: 'rasterizeItem',
18
+ _value: 'vectorMask',
19
+ },
20
+ },
21
+ schema: z.unknown(),
22
+ });
23
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export function createDeleteChannelCommand() {
5
+ return createCommand({
6
+ modifying: true,
7
+ descriptor: {
8
+ _obj: 'delete',
9
+ _target: [
10
+ {
11
+ _ref: 'channel',
12
+ _enum: 'ordinal',
13
+ _value: 'targetEnum',
14
+ },
15
+ ],
16
+ },
17
+ schema: z.unknown(),
18
+ });
19
+ }
@@ -1,6 +1,6 @@
1
1
  import { executeAsModal } from "../core/executeAsModal";
2
2
  import { openFileByPath } from "../filesystem/openFileByPath";
3
- import { getDocumentLayerDescriptors } from "../ut-tree/getLayerProperties";
3
+ import { getDocumentLayerDescriptors } from "../ut-tree/getDocumentLayerDescriptors";
4
4
  import type { Test } from "@bubblydoo/uxp-test-framework";
5
5
  import { expect } from "chai";
6
6
  import { app } from "photoshop";
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export function createRenderGridCommand(gridPoints: number) {
5
+ return createCommand({
6
+ modifying: true,
7
+ descriptor: {
8
+ _obj: '$3grd',
9
+ $grdP: gridPoints,
10
+ },
11
+ schema: z.unknown(),
12
+ });
13
+ }
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+ import type { PsLayerRef } from "../ut-tree/psLayerRef";
4
+
5
+ export function createSelectLayerCommand(layerRef: PsLayerRef) {
6
+ return createCommand({
7
+ modifying: true,
8
+ descriptor: {
9
+ _obj: 'select',
10
+ _target: [
11
+ {
12
+ _ref: 'layer',
13
+ _id: layerRef.id,
14
+ },
15
+ {
16
+ _ref: 'document',
17
+ _id: layerRef.docId,
18
+ },
19
+ ],
20
+ makeVisible: false,
21
+ layerID: [layerRef.id],
22
+ _isCommand: false,
23
+ },
24
+ schema: z.unknown(),
25
+ });
26
+ }
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import { createCommand } from "../core/command";
3
+
4
+ export type LUTFormatType = 'LUTFormatCUBE' | 'LUTFormat3DL' | 'LUTFormatCSP';
5
+
6
+ export interface Set3DLUTColorLookupOptions {
7
+ lutPath: string;
8
+ lutFormat?: LUTFormatType;
9
+ profileBase64?: string;
10
+ lutFileDataBase64?: string;
11
+ }
12
+
13
+ export function createSet3DLUTColorLookupCommand(options: Set3DLUTColorLookupOptions) {
14
+ const {
15
+ lutPath,
16
+ lutFormat = 'LUTFormatCUBE',
17
+ profileBase64,
18
+ lutFileDataBase64,
19
+ } = options;
20
+
21
+ return createCommand({
22
+ modifying: true,
23
+ descriptor: {
24
+ _obj: 'set',
25
+ _target: [
26
+ {
27
+ _enum: 'ordinal',
28
+ _ref: 'adjustmentLayer',
29
+ _value: 'targetEnum',
30
+ },
31
+ ],
32
+ to: {
33
+ _obj: 'colorLookup',
34
+ lookupType: {
35
+ _enum: 'colorLookupType',
36
+ _value: '3DLUT',
37
+ },
38
+ name: lutPath,
39
+ LUTFormat: {
40
+ _enum: 'LUTFormatType',
41
+ _value: lutFormat,
42
+ },
43
+ ...(profileBase64 && {
44
+ profile: {
45
+ _data: profileBase64,
46
+ _rawData: 'base64',
47
+ },
48
+ }),
49
+ ...(lutFileDataBase64 && {
50
+ LUT3DFileData: {
51
+ _data: lutFileDataBase64,
52
+ _rawData: 'base64',
53
+ },
54
+ }),
55
+ LUT3DFileName: lutPath,
56
+ },
57
+ _isCommand: true,
58
+ },
59
+ schema: z.unknown(),
60
+ });
61
+ }
package/src/index.ts CHANGED
@@ -26,11 +26,6 @@ export {
26
26
  // Core wrappers
27
27
  export { executeAsModalAndSuspendHistory } from "./core-wrappers/executeAsModalAndSuspendHistory";
28
28
 
29
- // Commands library
30
- export { createRenameLayerCommand } from "./commands-library/renameLayer";
31
- export { createGetDocumentCommand, createGetDocumentHasBackgroundLayerCommand } from "./commands-library/getDocument";
32
- export { createGetBackgroundLayerCommand } from "./commands-library/getLayer";
33
-
34
29
  // DOM – layers
35
30
  export { getFlattenedDomLayersList } from "./dom/getFlattenedDomLayersList";
36
31
  export { photoshopDomLayersToTree } from "./dom/photoshopDomLayersToTree";
@@ -51,12 +46,13 @@ export { copyToClipboard, readFromClipboard } from "./other/clipboard";
51
46
  export { uxpEntrypointsSchema } from "./other/uxpEntrypoints";
52
47
 
53
48
  // UT tree – layer descriptors & Photoshop tree
54
- export {
55
- createGetLayerPropertiesCommand,
56
- getDocumentLayerDescriptors as getLayerPropertiesFromUtTree,
57
- } from "./ut-tree/getLayerProperties";
49
+ export { createMultiGetDocumentCommand } from "./commands-library/multiGetDocument";
50
+ export { getDocumentLayerDescriptors, type LayerDescriptor } from "./ut-tree/getDocumentLayerDescriptors";
58
51
  export { getLayerEffects } from "./ut-tree/getLayerEffects";
59
- export { type UTLayer } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
52
+ export {
53
+ type UTLayer,
54
+ photoshopLayerDescriptorsToUTLayers,
55
+ } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
60
56
  export { type PsLayerRef } from "./ut-tree/psLayerRef";
61
57
  export {
62
58
  utLayersToTree,
@@ -0,0 +1,29 @@
1
+ import { batchPlayCommand, batchPlayCommands } from "../core/command";
2
+ import { createMultiGetDocumentCommand } from "../commands-library/multiGetDocument";
3
+ import { createGetDocumentHasBackgroundLayerCommand } from "../commands-library/getDocument";
4
+ import { createGetBackgroundLayerCommand } from "../commands-library/getLayer";
5
+
6
+ // get layer properties like name and layerID for all layers in the document (by index)
7
+ export const getDocumentLayerDescriptors = async (documentId: number) => {
8
+ const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
9
+ createMultiGetDocumentCommand(documentId),
10
+ createGetDocumentHasBackgroundLayerCommand(documentId),
11
+ ]);
12
+
13
+ const backgroundLayerResult = documentHasBackgroundLayerResult.hasBackgroundLayer ? await batchPlayCommand(createGetBackgroundLayerCommand(documentId)) : null;
14
+
15
+ const list = [...layersResult.list].reverse();
16
+ if (backgroundLayerResult) {
17
+ list.push(backgroundLayerResult);
18
+ }
19
+
20
+ // Reverse to get bottom-up order
21
+ return list.map((layerProp) => {
22
+ return {
23
+ ...layerProp,
24
+ docId: documentId,
25
+ };
26
+ });
27
+ };
28
+
29
+ export type LayerDescriptor = Awaited<ReturnType<typeof getDocumentLayerDescriptors>>[number];
@@ -1,4 +1,4 @@
1
- import type { LayerDescriptor } from "./getLayerProperties";
1
+ import type { LayerDescriptor } from "./getDocumentLayerDescriptors";
2
2
 
3
3
  type UTLayerKind = "pixel" | "adjustment-layer" | "text" | "curves" | "smartObject" | "video" | "group" | "threeD" | "gradientFill" | "pattern" | "solidColor" | "background";
4
4
 
@@ -2,7 +2,7 @@ import type { Test } from "@bubblydoo/uxp-test-framework";
2
2
  import { photoshopLayerDescriptorsToUTLayers } from "./photoshopLayerDescriptorsToUTLayers";
3
3
  import { openFileByPath } from "../filesystem/openFileByPath";
4
4
  import { expect } from "chai";
5
- import { getDocumentLayerDescriptors } from "./getLayerProperties";
5
+ import { getDocumentLayerDescriptors } from "./getDocumentLayerDescriptors";
6
6
 
7
7
  export const photoshopLayerDescriptorsToUTLayersTest: Test = {
8
8
  name: "photoshopLayerDescriptorsToUTLayers",
package/tsup.config.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- format: "esm",
6
- dts: true,
7
- external: ["photoshop", "uxp"],
8
- outDir: "dist",
9
- });
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts", "src/commands-library/index.ts"],
5
+ format: "esm",
6
+ dts: true,
7
+ external: ["photoshop", "uxp"],
8
+ outDir: "dist",
9
+ });