@bubblydoo/uxp-toolkit 0.0.5 → 0.0.6

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @bubblydoo/uxp-toolkit@0.0.5 build /home/runner/work/uxp-toolkit/uxp-toolkit/packages/uxp-toolkit
2
+ > @bubblydoo/uxp-toolkit@0.0.6 build /home/runner/work/uxp-toolkit/uxp-toolkit/packages/uxp-toolkit
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,8 +8,8 @@
8
8
  CLI Using tsup config: /home/runner/work/uxp-toolkit/uxp-toolkit/packages/uxp-toolkit/tsup.config.ts
9
9
  CLI Target: es2022
10
10
  ESM Build start
11
- ESM dist/index.js 18.29 KB
12
- ESM ⚡️ Build success in 29ms
11
+ ESM dist/index.js 20.97 KB
12
+ ESM ⚡️ Build success in 28ms
13
13
  DTS Build start
14
- DTS ⚡️ Build success in 2357ms
15
- DTS dist/index.d.ts 11.44 KB
14
+ DTS ⚡️ Build success in 2406ms
15
+ DTS dist/index.d.ts 11.62 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @bubblydoo/uxp-toolkit
2
2
 
3
+ ## 0.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 31534d4: Fix layer descriptors exorts
8
+
3
9
  ## 0.0.5
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -200,7 +200,7 @@ declare const uxpEntrypointsSchema: z.ZodObject<{
200
200
  }, z.core.$strip>;
201
201
  }, z.core.$strip>;
202
202
 
203
- declare function createGetLayerPropertiesCommand(docId: number): UTCommandNonModifying<{
203
+ declare function createMultiGetDocumentCommand(docId: number): UTCommandNonModifying<{
204
204
  list: {
205
205
  name: string;
206
206
  layerID: number;
@@ -224,6 +224,7 @@ declare function createGetLayerPropertiesCommand(docId: number): UTCommandNonMod
224
224
  }[]> | undefined;
225
225
  }[];
226
226
  }>;
227
+
227
228
  declare const getDocumentLayerDescriptors: (documentId: number) => Promise<{
228
229
  docId: number;
229
230
  name: string;
@@ -247,6 +248,7 @@ declare const getDocumentLayerDescriptors: (documentId: number) => Promise<{
247
248
  enabled: boolean;
248
249
  }[]> | undefined;
249
250
  }[]>;
251
+ type LayerDescriptor = Awaited<ReturnType<typeof getDocumentLayerDescriptors>>[number];
250
252
 
251
253
  declare function getLayerEffects(layerRef: PsLayerRef): Promise<Record<string, boolean>>;
252
254
 
@@ -267,6 +269,7 @@ type UTLayerBuilder = {
267
269
  type UTLayer = Readonly<Omit<UTLayerBuilder, "layers">> & {
268
270
  layers?: UTLayer[];
269
271
  };
272
+ declare function photoshopLayerDescriptorsToUTLayers(layers: LayerDescriptor[]): UTLayer[];
270
273
 
271
274
  type UTLayerWithoutChildren = Omit<UTLayer, "layers">;
272
275
  declare function utLayersToTree(layer: UTLayer[]): Tree<UTLayerWithoutChildren>;
@@ -287,4 +290,4 @@ declare function parseUxpErrorSourcemaps(error: Error, opts?: {
287
290
  }): Promise<BasicStackFrame[]>;
288
291
  declare function getBasicStackFrameAbsoluteFilePath(frame: BasicStackFrame): Promise<string>;
289
292
 
290
- export { type BasicStackFrame, type CorrectBatchPlayOptions, type CorrectExecuteAsModalOptions, type CorrectExecutionContext, type ExtendedExecutionContext, type LayerRef, type PsLayerRef, type SuspendHistoryContext, type Tree, type UTCommandBase, type UTCommandModifying, type UTCommandNonModifying, type UTCommandResult, type UTLayer, type UTLayerPickKeys, type UTLayerWithoutChildren, batchPlay, batchPlayCommand, batchPlayCommands, copyToClipboard, createCommand, createGetBackgroundLayerCommand, createGetDocumentCommand, createGetDocumentHasBackgroundLayerCommand, createGetLayerPropertiesCommand, createModifyingBatchPlayContext, createRenameLayerCommand, executeAsModal, executeAsModalAndSuspendHistory, flattenTree, getBasicStackFrameAbsoluteFilePath, getFlattenedDomLayersList, getLayerEffects, getDocumentLayerDescriptors as getLayerPropertiesFromUtTree, mapTree, mapTreeRef, openFileByPath, parseUxpErrorSourcemaps, photoshopDomLayersToTree, photoshopGetApplicationInfo, readFromClipboard, suspendHistory, utLayerToDomLayer, utLayersToDomLayers, utLayersToTree, utLayersToText as utTreeToText, uxpEntrypointsSchema };
293
+ export { type BasicStackFrame, type CorrectBatchPlayOptions, type CorrectExecuteAsModalOptions, type CorrectExecutionContext, type ExtendedExecutionContext, type LayerRef, type PsLayerRef, type SuspendHistoryContext, type Tree, type UTCommandBase, type UTCommandModifying, type UTCommandNonModifying, type UTCommandResult, type UTLayer, type UTLayerPickKeys, type UTLayerWithoutChildren, batchPlay, batchPlayCommand, batchPlayCommands, copyToClipboard, createCommand, createGetBackgroundLayerCommand, createGetDocumentCommand, createGetDocumentHasBackgroundLayerCommand, createModifyingBatchPlayContext, createMultiGetDocumentCommand, createRenameLayerCommand, executeAsModal, executeAsModalAndSuspendHistory, flattenTree, getBasicStackFrameAbsoluteFilePath, getDocumentLayerDescriptors, getFlattenedDomLayersList, getLayerEffects, mapTree, mapTreeRef, openFileByPath, parseUxpErrorSourcemaps, photoshopDomLayersToTree, photoshopGetApplicationInfo, photoshopLayerDescriptorsToUTLayers, readFromClipboard, suspendHistory, utLayerToDomLayer, utLayersToDomLayers, utLayersToTree, utLayersToText as utTreeToText, uxpEntrypointsSchema };
package/dist/index.js CHANGED
@@ -354,9 +354,9 @@ var uxpEntrypointsSchema = z6.object({
354
354
  })
355
355
  });
356
356
 
357
- // src/ut-tree/getLayerProperties.ts
357
+ // src/commands-library/multiGetDocument.ts
358
358
  import { z as z7 } from "zod";
359
- function createGetLayerPropertiesCommand(docId) {
359
+ function createMultiGetDocumentCommand(docId) {
360
360
  return createCommand({
361
361
  modifying: false,
362
362
  descriptor: {
@@ -400,9 +400,11 @@ function createGetLayerPropertiesCommand(docId) {
400
400
  })
401
401
  });
402
402
  }
403
+
404
+ // src/ut-tree/getDocumentLayerDescriptors.ts
403
405
  var getDocumentLayerDescriptors = async (documentId) => {
404
406
  const [layersResult, documentHasBackgroundLayerResult] = await batchPlayCommands([
405
- createGetLayerPropertiesCommand(documentId),
407
+ createMultiGetDocumentCommand(documentId),
406
408
  createGetDocumentHasBackgroundLayerCommand(documentId)
407
409
  ]);
408
410
  const backgroundLayerResult = documentHasBackgroundLayerResult.hasBackgroundLayer ? await batchPlayCommand(createGetBackgroundLayerCommand(documentId)) : null;
@@ -429,6 +431,114 @@ async function getLayerEffects(layerRef) {
429
431
  return effects;
430
432
  }
431
433
 
434
+ // src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts
435
+ var layerKindMap = /* @__PURE__ */ new Map([
436
+ [1, "pixel"],
437
+ [2, "adjustment-layer"],
438
+ // All adjustment layers
439
+ [3, "text"],
440
+ [4, "curves"],
441
+ [5, "smartObject"],
442
+ [6, "video"],
443
+ [7, "group"],
444
+ [8, "threeD"],
445
+ [9, "gradientFill"],
446
+ [10, "pattern"],
447
+ [11, "solidColor"],
448
+ [12, "background"]
449
+ // according to the internet but the actual value is undefined
450
+ ]);
451
+ var blendModes = [
452
+ "normal",
453
+ "dissolve",
454
+ "darken",
455
+ "multiply",
456
+ "colorBurn",
457
+ "linearBurn",
458
+ "darkerColor",
459
+ "lighten",
460
+ "screen",
461
+ "colorDodge",
462
+ "linearDodge",
463
+ "lighterColor",
464
+ "overlay",
465
+ "softLight",
466
+ "hardLight",
467
+ "vividLight",
468
+ "linearLight",
469
+ "pinLight",
470
+ "hardMix",
471
+ "difference",
472
+ "exclusion",
473
+ "blendSubtraction",
474
+ "blendDivide",
475
+ "hue",
476
+ "saturation",
477
+ "color",
478
+ "luminosity",
479
+ "passThrough"
480
+ ];
481
+ var getLayerKind = (layer) => {
482
+ const kind = layerKindMap.get(layer.layerKind);
483
+ if (!kind) {
484
+ throw new Error(`Unknown layer kind: ${layer.layerKind}`);
485
+ }
486
+ return kind;
487
+ };
488
+ var getBlendMode = (layer) => {
489
+ const mode = layer.mode._value;
490
+ if (!blendModes.includes(mode)) {
491
+ throw new Error(`Unknown blend mode: ${mode}`);
492
+ }
493
+ return mode;
494
+ };
495
+ function photoshopLayerDescriptorsToUTLayers(layers) {
496
+ const root = [];
497
+ const stack = [{ layers: root }];
498
+ for (const layer of layers) {
499
+ const sectionType = determineLayerSection(layer);
500
+ if (sectionType === "end") {
501
+ if (stack.length > 1) {
502
+ stack.pop();
503
+ }
504
+ continue;
505
+ }
506
+ const node = {
507
+ name: layer.name,
508
+ docId: layer.docId,
509
+ id: layer.layerID,
510
+ visible: layer.visible,
511
+ kind: getLayerKind(layer),
512
+ blendMode: getBlendMode(layer),
513
+ isClippingMask: layer.group,
514
+ effects: getEffects(layer),
515
+ background: layer.background
516
+ };
517
+ const current = stack[stack.length - 1];
518
+ current.layers.push(node);
519
+ if (sectionType === "start") {
520
+ node.layers = [];
521
+ stack.push({ layers: node.layers });
522
+ }
523
+ }
524
+ return root;
525
+ }
526
+ var determineLayerSection = (layer) => {
527
+ const section = layer.layerSection._value;
528
+ const isGroupEnd = layer.name === "</Layer group>" || layer.name === "</Layer set>" || section === "layerSectionEnd";
529
+ const isGroupStart = section === "layerSectionStart";
530
+ return isGroupStart ? "start" : isGroupEnd ? "end" : "normal";
531
+ };
532
+ function getEffects(layer) {
533
+ const effects = {};
534
+ if (layer.layerEffects) {
535
+ for (const effect in layer.layerEffects) {
536
+ effects[effect] = Array.isArray(layer.layerEffects[effect]) ? layer.layerEffects[effect].some((e) => e.enabled) : !!layer.layerEffects[effect]?.enabled;
537
+ }
538
+ }
539
+ return effects;
540
+ }
541
+
432
542
  // src/ut-tree/utLayersToTree.ts
433
543
  function utLayersToTree(layer) {
434
544
  return layer.map((layer2) => ({
@@ -627,22 +737,23 @@ export {
627
737
  createGetBackgroundLayerCommand,
628
738
  createGetDocumentCommand,
629
739
  createGetDocumentHasBackgroundLayerCommand,
630
- createGetLayerPropertiesCommand,
631
740
  createModifyingBatchPlayContext,
741
+ createMultiGetDocumentCommand,
632
742
  createRenameLayerCommand,
633
743
  executeAsModal,
634
744
  executeAsModalAndSuspendHistory,
635
745
  flattenTree,
636
746
  getBasicStackFrameAbsoluteFilePath,
747
+ getDocumentLayerDescriptors,
637
748
  getFlattenedDomLayersList,
638
749
  getLayerEffects,
639
- getDocumentLayerDescriptors as getLayerPropertiesFromUtTree,
640
750
  mapTree,
641
751
  mapTreeRef,
642
752
  openFileByPath,
643
753
  parseUxpErrorSourcemaps,
644
754
  photoshopDomLayersToTree,
645
755
  photoshopGetApplicationInfo,
756
+ photoshopLayerDescriptorsToUTLayers,
646
757
  readFromClipboard,
647
758
  suspendHistory,
648
759
  utLayerToDomLayer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bubblydoo/uxp-toolkit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Hans Otto Wirtz <hansottowirtz@gmail.com>",
@@ -39,8 +39,8 @@
39
39
  "typescript": "^5.8.3",
40
40
  "vitest": "^4.0.18",
41
41
  "zod": "^4.3.6",
42
- "@bubblydoo/uxp-test-framework": "0.0.5",
43
- "@bubblydoo/tsconfig": "0.0.3"
42
+ "@bubblydoo/tsconfig": "0.0.3",
43
+ "@bubblydoo/uxp-test-framework": "0.0.6"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsup",
@@ -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];
@@ -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";
package/src/index.ts CHANGED
@@ -28,7 +28,10 @@ export { executeAsModalAndSuspendHistory } from "./core-wrappers/executeAsModalA
28
28
 
29
29
  // Commands library
30
30
  export { createRenameLayerCommand } from "./commands-library/renameLayer";
31
- export { createGetDocumentCommand, createGetDocumentHasBackgroundLayerCommand } from "./commands-library/getDocument";
31
+ export {
32
+ createGetDocumentCommand,
33
+ createGetDocumentHasBackgroundLayerCommand,
34
+ } from "./commands-library/getDocument";
32
35
  export { createGetBackgroundLayerCommand } from "./commands-library/getLayer";
33
36
 
34
37
  // DOM – layers
@@ -51,12 +54,13 @@ export { copyToClipboard, readFromClipboard } from "./other/clipboard";
51
54
  export { uxpEntrypointsSchema } from "./other/uxpEntrypoints";
52
55
 
53
56
  // UT tree – layer descriptors & Photoshop tree
54
- export {
55
- createGetLayerPropertiesCommand,
56
- getDocumentLayerDescriptors as getLayerPropertiesFromUtTree,
57
- } from "./ut-tree/getLayerProperties";
57
+ export { createMultiGetDocumentCommand } from "./commands-library/multiGetDocument";
58
+ export { getDocumentLayerDescriptors } from "./ut-tree/getDocumentLayerDescriptors";
58
59
  export { getLayerEffects } from "./ut-tree/getLayerEffects";
59
- export { type UTLayer } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
60
+ export {
61
+ type UTLayer,
62
+ photoshopLayerDescriptorsToUTLayers,
63
+ } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
60
64
  export { type PsLayerRef } from "./ut-tree/psLayerRef";
61
65
  export {
62
66
  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",