@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.
Files changed (77) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/CHANGELOG.md +6 -0
  3. package/dist/{chunk-3CLJMC63.js → chunk-JBXCIUBZ.js} +49 -90
  4. package/dist/commands-library/index.d.ts +38 -39
  5. package/dist/commands-library/index.js +171 -171
  6. package/dist/index.d.ts +39 -41
  7. package/dist/index.js +189 -150
  8. package/dist/{psLayerRef-OY3h7srv.d.ts → psLayerRef-CGbTO4a5.d.ts} +36 -37
  9. package/package.json +8 -7
  10. package/src/commands-library/addLayerToSelection.ts +4 -4
  11. package/src/commands-library/applyLayerMask.ts +2 -2
  12. package/src/commands-library/convertMode.ts +2 -2
  13. package/src/commands-library/createColorLookupAdjustmentLayer.ts +2 -2
  14. package/src/commands-library/expandFolder.ts +4 -4
  15. package/src/commands-library/exportLUTs.ts +4 -4
  16. package/src/commands-library/getDocument.ts +7 -7
  17. package/src/commands-library/getLayer.ts +13 -13
  18. package/src/commands-library/hasVectorMask.ts +2 -2
  19. package/src/commands-library/index.ts +18 -18
  20. package/src/commands-library/loadLayerMaskAsSelection.ts +2 -2
  21. package/src/commands-library/multiGetDocument.ts +14 -14
  22. package/src/commands-library/rasterizeLayerStyle.ts +3 -3
  23. package/src/commands-library/rasterizeVectorMask.ts +2 -2
  24. package/src/commands-library/removeLayerMask.ts +2 -2
  25. package/src/commands-library/renameLayer.ts +6 -6
  26. package/src/commands-library/renameLayer.uxp-test.ts +13 -13
  27. package/src/commands-library/renderGrid.ts +2 -2
  28. package/src/commands-library/selectLayer.ts +3 -3
  29. package/src/commands-library/set3DLUTColorLookup.ts +2 -2
  30. package/src/core/batchPlay.ts +3 -3
  31. package/src/core/command.test-d.ts +11 -8
  32. package/src/core/command.ts +20 -23
  33. package/src/core/executeAsModal.ts +13 -11
  34. package/src/core/suspendHistory.ts +3 -3
  35. package/src/core/suspendHistory.uxp-test.ts +8 -8
  36. package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +8 -6
  37. package/src/dom/getFlattenedDomLayersList.ts +6 -7
  38. package/src/dom/photoshopDomLayersToTree.ts +5 -5
  39. package/src/error-sourcemaps/sourcemaps.ts +23 -21
  40. package/src/error-sourcemaps/sourcemaps.uxp-test.ts +9 -8
  41. package/src/errors/ut-error.ts +2 -2
  42. package/src/filesystem/openFileByPath.ts +4 -4
  43. package/src/general-tree/flattenTree.ts +1 -1
  44. package/src/general-tree/layerRef.ts +2 -2
  45. package/src/general-tree/mapTree.ts +1 -1
  46. package/src/general-tree/mapTreeRef.ts +1 -1
  47. package/src/general-tree/treeTypes.ts +0 -2
  48. package/src/index.ts +43 -43
  49. package/src/metadata-storage/metadataStorage.ts +31 -31
  50. package/src/metadata-storage/metadataStorage.uxp-test.ts +11 -11
  51. package/src/node-compat/path/resolvePath.ts +6 -4
  52. package/src/other/applicationInfo.ts +11 -11
  53. package/src/other/applicationInfo.uxp-test.ts +6 -6
  54. package/src/other/clipboard.ts +2 -2
  55. package/src/other/clipboard.uxp-test.ts +9 -8
  56. package/src/other/uxpEntrypoints.ts +2 -2
  57. package/src/ut-tree/getDocumentLayerDescriptors.ts +6 -6
  58. package/src/ut-tree/getLayerEffects.ts +5 -5
  59. package/src/ut-tree/hasBackgroundLayer.uxp-test.ts +25 -23
  60. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.test.ts +29 -29
  61. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +62 -62
  62. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +29 -29
  63. package/src/ut-tree/psLayerRef.ts +2 -2
  64. package/src/ut-tree/utLayersToText.test.ts +32 -32
  65. package/src/ut-tree/utLayersToText.ts +19 -19
  66. package/src/ut-tree/utLayersToTree.ts +4 -4
  67. package/src/util/utLayerPickKeysType.ts +3 -3
  68. package/src/util/utLayerToLayer.ts +14 -13
  69. package/test/index.ts +11 -11
  70. package/test/meta-tests/builtinModules.uxp-test.ts +28 -26
  71. package/test/meta-tests/executeAsModal.uxp-test.ts +14 -12
  72. package/test/meta-tests/suspendHistory.uxp-test.ts +10 -9
  73. package/tsconfig.json +5 -5
  74. package/tsup.config.ts +5 -5
  75. package/uxp-tests.json +1 -1
  76. package/vitest-photoshop-alias-plugin.ts +23 -21
  77. package/vitest.config.ts +6 -6
@@ -1,11 +1,13 @@
1
- import type { Document } from "photoshop/dom/Document";
2
- import { suspendHistory, type SuspendHistoryContext } from "../core/suspendHistory";
3
- import { executeAsModal, type ExtendedExecutionContext } from "../core/executeAsModal";
1
+ import type { Document } from 'photoshop';
2
+ import type { ExtendedExecutionContext } from '../core/executeAsModal';
3
+ import type { SuspendHistoryContext } from '../core/suspendHistory';
4
+ import { executeAsModal } from '../core/executeAsModal';
5
+ import { suspendHistory } from '../core/suspendHistory';
4
6
 
5
7
  type CombinedFn<T> = (executionContext: ExtendedExecutionContext, suspendHistoryContext: SuspendHistoryContext) => Promise<T>;
6
8
 
7
- export const executeAsModalAndSuspendHistory = async <T>(commandName: string, document: Document, fn: CombinedFn<T>): Promise<T> => {
9
+ export async function executeAsModalAndSuspendHistory<T>(commandName: string, document: Document, fn: CombinedFn<T>): Promise<T> {
8
10
  return await executeAsModal(commandName, async (ctx) => {
9
- return await suspendHistory(document, commandName, (suspendHistoryContext) => fn(ctx, suspendHistoryContext));
11
+ return await suspendHistory(document, commandName, suspendHistoryContext => fn(ctx, suspendHistoryContext));
10
12
  });
11
- };
13
+ }
@@ -1,11 +1,9 @@
1
- import { constants } from "photoshop";
2
- import type { Layer as DomLayer } from "photoshop/dom/Layer";
1
+ import type { Layer as DomLayer } from 'photoshop';
2
+ import { constants } from 'photoshop';
3
3
 
4
4
  // get all layers (including nested in groups)
5
5
  // TODO: I would rename this to getAllDOMLayers to avoid confusion with UXPToolkitLayer
6
- export const getFlattenedDomLayersList = (
7
- layers: DomLayer[],
8
- ): DomLayer[] => {
6
+ export function getFlattenedDomLayersList(layers: DomLayer[]): DomLayer[] {
9
7
  const allLayers: DomLayer[] = [];
10
8
 
11
9
  // Use a stack to avoid maximal call stack size (recursion) errors efficiently
@@ -20,7 +18,8 @@ export const getFlattenedDomLayersList = (
20
18
 
21
19
  while (stack.length > 0) {
22
20
  const layer = stack.pop();
23
- if (!layer) continue;
21
+ if (!layer)
22
+ continue;
24
23
 
25
24
  allLayers.push(layer);
26
25
 
@@ -40,4 +39,4 @@ export const getFlattenedDomLayersList = (
40
39
  }
41
40
 
42
41
  return allLayers;
43
- };
42
+ }
@@ -1,10 +1,10 @@
1
- import type { Layer as DomLayer } from "photoshop/dom/Layer";
2
- import type { Tree } from "../general-tree/treeTypes";
1
+ import type { Layer as DomLayer } from 'photoshop';
2
+ import type { Tree } from '../general-tree/treeTypes';
3
3
 
4
4
  // get layers recursively
5
- export const photoshopDomLayersToTree = (layers: DomLayer[]): Tree<DomLayer> => {
5
+ export function photoshopDomLayersToTree(layers: DomLayer[]): Tree<DomLayer> {
6
6
  // Get top-level layers
7
- const filteredLayers = layers.filter((layer) => layer.parent === null);
7
+ const filteredLayers = layers.filter(layer => layer.parent === null);
8
8
 
9
9
  const generateTree = (layers: DomLayer[]): Tree<DomLayer> => {
10
10
  return layers.map((layer: DomLayer) => ({
@@ -15,4 +15,4 @@ export const photoshopDomLayersToTree = (layers: DomLayer[]): Tree<DomLayer> =>
15
15
  };
16
16
 
17
17
  return generateTree(filteredLayers);
18
- };
18
+ }
@@ -1,12 +1,12 @@
1
- import ErrorStackParser from "error-stack-parser";
2
- import { SourceMapConsumer } from "source-map-js";
3
- import { storage } from "uxp";
4
- import { pathResolve } from "../node-compat/path/resolvePath";
5
- import { UTError } from "../errors/ut-error";
1
+ import ErrorStackParser from 'error-stack-parser';
2
+ import { SourceMapConsumer } from 'source-map-js';
3
+ import { storage } from 'uxp';
4
+ import { UTError } from '../errors/ut-error';
5
+ import { pathResolve } from '../node-compat/path/resolvePath';
6
6
 
7
7
  export type BasicStackFrame = Pick<
8
8
  ErrorStackParser.StackFrame,
9
- "functionName" | "fileName" | "lineNumber" | "columnNumber"
9
+ 'functionName' | 'fileName' | 'lineNumber' | 'columnNumber'
10
10
  >;
11
11
 
12
12
  export async function parseUxpErrorSourcemaps(error: Error, opts: { unsourcemappedHeaderLines?: number } = {}) {
@@ -23,19 +23,19 @@ export async function parseUxpErrorSourcemaps(error: Error, opts: { unsourcemapp
23
23
  parsedMappedError.push(frame);
24
24
  continue;
25
25
  }
26
- const entryPath = "plugin:" + frame.fileName;
27
- const file =
28
- loadedFilesCache[entryPath] ??
29
- ((await fs.getEntryWithUrl(entryPath)) as storage.File);
26
+ const entryPath = `plugin:${frame.fileName}`;
27
+ const file
28
+ = loadedFilesCache[entryPath]
29
+ ?? ((await fs.getEntryWithUrl(entryPath)) as storage.File);
30
30
  loadedFilesCache[entryPath] = file;
31
31
  if (!file.isFile) {
32
32
  parsedMappedError.push(frame);
33
33
  continue;
34
34
  }
35
- const sourcemapFileEntryPath = entryPath + ".map";
36
- const sourcemapFile =
37
- loadedFilesCache[sourcemapFileEntryPath] ??
38
- ((await fs.getEntryWithUrl(sourcemapFileEntryPath)) as storage.File);
35
+ const sourcemapFileEntryPath = `${entryPath}.map`;
36
+ const sourcemapFile
37
+ = loadedFilesCache[sourcemapFileEntryPath]
38
+ ?? ((await fs.getEntryWithUrl(sourcemapFileEntryPath)) as storage.File);
39
39
  loadedFilesCache[sourcemapFileEntryPath] = sourcemapFile;
40
40
  if (!sourcemapFile.isFile) {
41
41
  parsedMappedError.push(frame);
@@ -55,7 +55,8 @@ export async function parseUxpErrorSourcemaps(error: Error, opts: { unsourcemapp
55
55
  lineNumber: mappedFrame.line,
56
56
  columnNumber: mappedFrame.column,
57
57
  } as ErrorStackParser.StackFrame);
58
- } else {
58
+ }
59
+ else {
59
60
  parsedMappedError.push(frame);
60
61
  }
61
62
  }
@@ -74,8 +75,9 @@ function parseErrorIntoBasicStackFrames(error: Error): BasicStackFrame[] {
74
75
  columnNumber: frame.columnNumber,
75
76
  };
76
77
  });
77
- } catch (e) {
78
- throw new UTStacktraceParsingError("Failed to parse error stack trace", { cause: e });
78
+ }
79
+ catch (e) {
80
+ throw new UTStacktraceParsingError('Failed to parse error stack trace', { cause: e });
79
81
  }
80
82
  }
81
83
 
@@ -85,16 +87,16 @@ export async function getBasicStackFrameAbsoluteFilePath(frame: BasicStackFrame)
85
87
  ).localFileSystem.getPluginFolder();
86
88
  const absoluteFileName = pathResolve(
87
89
  pluginFolder.nativePath,
88
- "index.js",
90
+ 'index.js',
89
91
  frame.fileName!,
90
- ).replace(/^plugin:/, "");
92
+ ).replace(/^plugin:/, '');
91
93
  return `${absoluteFileName}:${frame.lineNumber}:${frame.columnNumber}`;
92
94
  }
93
95
 
94
96
  export class UTStacktraceParsingError extends UTError {
95
- public override readonly name = "UTStacktraceParsingError";
97
+ public override readonly name = 'UTStacktraceParsingError';
96
98
 
97
99
  constructor(message: string, opts: ErrorOptions = {}) {
98
100
  super(message, opts);
99
101
  }
100
- }
102
+ }
@@ -1,24 +1,25 @@
1
- import type { Test } from "@bubblydoo/uxp-test-framework";
2
- import { parseUxpErrorSourcemaps } from "./sourcemaps";
3
- import { expect } from "chai";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { parseUxpErrorSourcemaps } from './sourcemaps';
4
4
 
5
5
  function throwError() {
6
- throw new Error("Uncaught error"); // this error should stay exactly here in the source code, see below
6
+ throw new Error('Uncaught error'); // this error should stay exactly here in the source code, see below
7
7
  }
8
8
 
9
9
  export const sourcemapsTest: Test = {
10
- name: "sourcemaps: should parse error sourcemaps",
10
+ name: 'sourcemaps: should parse error sourcemaps',
11
11
  async run() {
12
12
  let error: Error;
13
13
  try {
14
14
  throwError();
15
- } catch (e) {
15
+ }
16
+ catch (e) {
16
17
  error = e as Error;
17
18
  }
18
19
  const parsedError = await parseUxpErrorSourcemaps(error!);
19
20
  console.log(parsedError);
20
- expect(parsedError[0]!.fileName).to.include("sourcemaps.uxp-test.ts");
21
+ expect(parsedError[0]!.fileName).to.include('sourcemaps.uxp-test.ts');
21
22
  expect(parsedError[0]!.lineNumber).to.eq(6);
22
23
  expect(parsedError[0]!.columnNumber).to.eq(8);
23
24
  },
24
- };
25
+ };
@@ -1,6 +1,6 @@
1
1
  export class UTError extends Error {
2
2
  constructor(message: string, opts: ErrorOptions = {}) {
3
3
  super(message, opts);
4
- this.name = "UTError";
4
+ this.name = 'UTError';
5
5
  }
6
- }
6
+ }
@@ -1,10 +1,10 @@
1
- import { app } from "photoshop";
2
- import { storage } from "uxp";
3
- import { executeAsModal } from "../core/executeAsModal";
1
+ import { app } from 'photoshop';
2
+ import { storage } from 'uxp';
3
+ import { executeAsModal } from '../core/executeAsModal';
4
4
 
5
5
  export async function openFileByPath(path: string) {
6
6
  const fs = (storage as any).localFileSystem;
7
7
  const file = (await fs.getEntryWithUrl(path)) as storage.File;
8
- const doc = await executeAsModal("Open file", () => app.open(file as any));
8
+ const doc = await executeAsModal('Open file', () => app.open(file as any));
9
9
  return doc;
10
10
  }
@@ -1,4 +1,4 @@
1
- import type { Tree } from "./treeTypes";
1
+ import type { Tree } from './treeTypes';
2
2
 
3
3
  export function flattenTree<T>(tree: Tree<T>): Tree<T>[0][] {
4
4
  const result: Tree<T>[0][] = [];
@@ -1,4 +1,4 @@
1
- export type LayerRef = {
1
+ export interface LayerRef {
2
2
  id: number;
3
3
  docId: number;
4
- };
4
+ }
@@ -1,4 +1,4 @@
1
- import type { Tree } from "./treeTypes";
1
+ import type { Tree } from './treeTypes';
2
2
 
3
3
  export function mapTree<TRef, TMappedRef>(tree: Tree<TRef>, mapFn: (node: TRef) => TMappedRef): Tree<TMappedRef> {
4
4
  return tree.map((node) => {
@@ -1,4 +1,4 @@
1
- import type { Tree } from "./treeTypes";
1
+ import type { Tree } from './treeTypes';
2
2
 
3
3
  export function mapTreeRef<TRef, TMappedRef>(tree: Tree<TRef>, mapFn: (node: TRef) => TMappedRef): Tree<TMappedRef> {
4
4
  return tree.map((node) => {
@@ -3,5 +3,3 @@ export type Tree<TRef = unknown> = {
3
3
  name: string;
4
4
  children?: Tree<TRef>;
5
5
  }[];
6
-
7
-
package/src/index.ts CHANGED
@@ -1,74 +1,74 @@
1
+ // UT tree – layer descriptors & Photoshop tree
2
+ export { createMultiGetDocumentCommand } from './commands-library/multiGetDocument';
3
+ // Core wrappers
4
+ export { executeAsModalAndSuspendHistory } from './core-wrappers/executeAsModalAndSuspendHistory';
5
+
1
6
  // Core – batchPlay & command building
2
- export { batchPlay, type CorrectBatchPlayOptions } from "./core/batchPlay";
7
+ export { batchPlay, type CorrectBatchPlayOptions } from './core/batchPlay';
3
8
  export {
4
- createCommand,
5
9
  batchPlayCommand,
6
10
  batchPlayCommands,
11
+ createCommand,
7
12
  createModifyingBatchPlayContext,
8
13
  type UTCommandBase,
9
14
  type UTCommandModifying,
10
15
  type UTCommandNonModifying,
11
16
  type UTCommandResult,
12
- } from "./core/command";
17
+ } from './core/command';
13
18
 
14
19
  // Core – execution context
15
20
  export {
16
- executeAsModal,
17
- type CorrectExecutionContext,
18
21
  type CorrectExecuteAsModalOptions,
22
+ type CorrectExecutionContext,
23
+ executeAsModal,
19
24
  type ExtendedExecutionContext,
20
- } from "./core/executeAsModal";
25
+ } from './core/executeAsModal';
26
+
21
27
  export {
22
28
  suspendHistory,
23
29
  type SuspendHistoryContext,
24
- } from "./core/suspendHistory";
25
-
26
- // Core wrappers
27
- export { executeAsModalAndSuspendHistory } from "./core-wrappers/executeAsModalAndSuspendHistory";
28
-
30
+ } from './core/suspendHistory';
29
31
  // DOM – layers
30
- export { getFlattenedDomLayersList } from "./dom/getFlattenedDomLayersList";
31
- export { photoshopDomLayersToTree } from "./dom/photoshopDomLayersToTree";
32
+ export { getFlattenedDomLayersList } from './dom/getFlattenedDomLayersList';
32
33
 
33
- // Filesystem
34
- export { openFileByPath } from "./filesystem/openFileByPath";
34
+ export { photoshopDomLayersToTree } from './dom/photoshopDomLayersToTree';
35
35
 
36
+ // Error sourcemaps
37
+ export {
38
+ type BasicStackFrame,
39
+ getBasicStackFrameAbsoluteFilePath,
40
+ parseUxpErrorSourcemaps,
41
+ } from './error-sourcemaps/sourcemaps';
42
+ // Filesystem
43
+ export { openFileByPath } from './filesystem/openFileByPath';
36
44
  // General tree
37
- export { flattenTree } from "./general-tree/flattenTree";
38
- export { mapTree } from "./general-tree/mapTree";
39
- export { mapTreeRef } from "./general-tree/mapTreeRef";
40
- export { type Tree } from "./general-tree/treeTypes";
41
- export { type LayerRef } from "./general-tree/layerRef";
45
+ export { flattenTree } from './general-tree/flattenTree';
46
+ export { type LayerRef } from './general-tree/layerRef';
47
+ export { mapTree } from './general-tree/mapTree';
42
48
 
49
+ export { mapTreeRef } from './general-tree/mapTreeRef';
50
+ export { type Tree } from './general-tree/treeTypes';
43
51
  // Other
44
- export { photoshopGetApplicationInfo } from "./other/applicationInfo";
45
- export { copyToClipboard, readFromClipboard } from "./other/clipboard";
46
- export { uxpEntrypointsSchema } from "./other/uxpEntrypoints";
52
+ export { photoshopGetApplicationInfo } from './other/applicationInfo';
47
53
 
48
- // UT tree layer descriptors & Photoshop tree
49
- export { createMultiGetDocumentCommand } from "./commands-library/multiGetDocument";
50
- export { getDocumentLayerDescriptors, type LayerDescriptor } from "./ut-tree/getDocumentLayerDescriptors";
51
- export { getLayerEffects } from "./ut-tree/getLayerEffects";
54
+ export { copyToClipboard, readFromClipboard } from './other/clipboard';
55
+ export { uxpEntrypointsSchema } from './other/uxpEntrypoints';
56
+ export { getDocumentLayerDescriptors, type LayerDescriptor } from './ut-tree/getDocumentLayerDescriptors';
57
+ export { getLayerEffects } from './ut-tree/getLayerEffects';
52
58
  export {
53
- type UTLayer,
54
59
  photoshopLayerDescriptorsToUTLayers,
55
- } from "./ut-tree/photoshopLayerDescriptorsToUTLayers";
56
- export { type PsLayerRef } from "./ut-tree/psLayerRef";
60
+ type UTLayer,
61
+ } from './ut-tree/photoshopLayerDescriptorsToUTLayers';
62
+ export { type PsLayerRef } from './ut-tree/psLayerRef';
63
+
64
+ // UT tree – text
65
+ export { utLayersToText as utTreeToText } from './ut-tree/utLayersToText';
66
+
57
67
  export {
58
68
  utLayersToTree,
59
69
  type UTLayerWithoutChildren,
60
- } from "./ut-tree/utLayersToTree";
61
-
62
- // UT tree – text
63
- export { utLayersToText as utTreeToText } from "./ut-tree/utLayersToText";
70
+ } from './ut-tree/utLayersToTree';
71
+ export { type UTLayerPickKeys } from './util/utLayerPickKeysType';
64
72
 
65
73
  // Util
66
- export { utLayerToDomLayer, utLayersToDomLayers } from "./util/utLayerToLayer";
67
- export { type UTLayerPickKeys } from "./util/utLayerPickKeysType";
68
-
69
- // Error sourcemaps
70
- export {
71
- parseUxpErrorSourcemaps,
72
- getBasicStackFrameAbsoluteFilePath,
73
- type BasicStackFrame,
74
- } from "./error-sourcemaps/sourcemaps";
74
+ export { utLayersToDomLayers, utLayerToDomLayer } from './util/utLayerToLayer';
@@ -1,61 +1,53 @@
1
- import { convert } from "xmlbuilder2";
2
- import type { Document } from "photoshop/dom/Document";
3
- import { batchPlayCommand, createCommand, executeAsModal } from "@bubblydoo/uxp-toolkit";
4
- import { z } from "zod";
1
+ import type { Document } from 'photoshop';
2
+ import { batchPlayCommand, createCommand, executeAsModal } from '@bubblydoo/uxp-toolkit';
3
+ import { convert } from 'xmlbuilder2';
4
+ import { z } from 'zod';
5
5
 
6
- export const readDocumentMetadata = async (document: Document, { key, prefix }: { key: string, prefix: string }) => {
7
- const converted = await readAllDocumentMetadata(document);
8
- const property =
9
- converted["x:xmpmeta"]["rdf:RDF"]["rdf:Description"][`${prefix}:${key}`];
10
-
11
- return property;
12
- };
13
-
14
- export const readAllDocumentMetadata = async (document: Document) => {
6
+ export async function readAllDocumentMetadata(document: Document) {
15
7
  const metadata = await batchPlayCommand(
16
8
  createCommand({
17
9
  modifying: false,
18
10
  descriptor: {
19
- _obj: "get",
11
+ _obj: 'get',
20
12
  _target: {
21
13
  _ref: [
22
- { _property: "XMPMetadataAsUTF8" },
23
- { _ref: "document", _id: document.id },
14
+ { _property: 'XMPMetadataAsUTF8' },
15
+ { _ref: 'document', _id: document.id },
24
16
  ],
25
17
  },
26
18
  },
27
19
  schema: z.object({
28
20
  XMPMetadataAsUTF8: z.any(),
29
- })
30
- })
21
+ }),
22
+ }),
31
23
  );
32
24
 
33
25
  return convert(metadata.XMPMetadataAsUTF8, {
34
- format: "object",
26
+ format: 'object',
35
27
  }) as any;
36
- };
28
+ }
37
29
 
38
- export const writeDocumentMetadata = async (document: Document, newProperty: { key: string, value: string, prefix: string, prefixNamespace: string }) => {
30
+ export async function writeDocumentMetadata(document: Document, newProperty: { key: string; value: string; prefix: string; prefixNamespace: string }) {
39
31
  const initialMetadata = await readAllDocumentMetadata(document);
40
- const obj = convert(initialMetadata, { format: "object" }) as any;
41
- obj["x:xmpmeta"]["rdf:RDF"]["rdf:Description"][
32
+ const obj = convert(initialMetadata, { format: 'object' }) as any;
33
+ obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][
42
34
  `@xmlns:${newProperty.prefix}`
43
35
  ] = newProperty.prefixNamespace;
44
- obj["x:xmpmeta"]["rdf:RDF"]["rdf:Description"][
36
+ obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][
45
37
  `${newProperty.prefix}:${newProperty.key}`
46
38
  ] = newProperty.value;
47
- const newXmpString = convert(obj, { format: "xml" });
48
- await executeAsModal("Set Metadata", async (ctx) => {
39
+ const newXmpString = convert(obj, { format: 'xml' });
40
+ await executeAsModal('Set Metadata', async (ctx) => {
49
41
  const command = createCommand({
50
42
  modifying: true,
51
43
  descriptor: {
52
- _obj: "set",
44
+ _obj: 'set',
53
45
  _target: [
54
- { _ref: "property", _property: "XMPMetadataAsUTF8" },
55
- { _ref: "document", _id: document.id },
46
+ { _ref: 'property', _property: 'XMPMetadataAsUTF8' },
47
+ { _ref: 'document', _id: document.id },
56
48
  ],
57
49
  to: {
58
- _obj: "document",
50
+ _obj: 'document',
59
51
  XMPMetadataAsUTF8: newXmpString,
60
52
  },
61
53
  },
@@ -63,4 +55,12 @@ export const writeDocumentMetadata = async (document: Document, newProperty: { k
63
55
  });
64
56
  await ctx.batchPlayCommand(command, { synchronousExecution: true });
65
57
  });
66
- };
58
+ }
59
+
60
+ export async function readDocumentMetadata(document: Document, { key, prefix }: { key: string; prefix: string }) {
61
+ const converted = await readAllDocumentMetadata(document);
62
+ const property
63
+ = converted['x:xmpmeta']['rdf:RDF']['rdf:Description'][`${prefix}:${key}`];
64
+
65
+ return property;
66
+ }
@@ -1,21 +1,21 @@
1
- import { openFileByPath } from "../filesystem/openFileByPath";
2
- import type { Test } from "@bubblydoo/uxp-test-framework";
3
- import { expect } from "chai";
4
- import { app } from "photoshop";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { app } from 'photoshop';
4
+ import { openFileByPath } from '../filesystem/openFileByPath';
5
5
  import {
6
6
  readDocumentMetadata,
7
7
  writeDocumentMetadata,
8
- } from "./metadataStorage";
8
+ } from './metadataStorage';
9
9
 
10
- const TEST_PREFIX = "bubblytest";
11
- const TEST_PREFIX_NAMESPACE = "https://example.com/bubbly-test";
12
- const TEST_KEY = "testKey";
13
- const TEST_VALUE = "test-value-written-by-uxp-test";
10
+ const TEST_PREFIX = 'bubblytest';
11
+ const TEST_PREFIX_NAMESPACE = 'https://example.com/bubbly-test';
12
+ const TEST_KEY = 'testKey';
13
+ const TEST_VALUE = 'test-value-written-by-uxp-test';
14
14
 
15
15
  export const metadataStorageTest: Test = {
16
- name: "Metadata Storage",
16
+ name: 'Metadata Storage',
17
17
  async run() {
18
- await openFileByPath("plugin:/fixtures/one-layer.psd");
18
+ await openFileByPath('plugin:/fixtures/one-layer.psd');
19
19
  const document = app.activeDocument!;
20
20
 
21
21
  await writeDocumentMetadata(document, {
@@ -1,17 +1,19 @@
1
- import { resolve as nativeResolve } from "path";
1
+ // eslint-disable-next-line unicorn/prefer-node-protocol
2
+ import { resolve as nativeResolve } from 'path';
2
3
 
3
- /** for some reason native path.resolve in UXP returns a URL object
4
+ /**
5
+ * for some reason native path.resolve in UXP returns a URL object
4
6
  * this function converts it to a string
5
7
  */
6
8
  export function pathResolve(...pathSegments: string[]): string {
7
9
  const urlOrString = nativeResolve(...pathSegments) as URL | string;
8
- if (typeof urlOrString === "string") {
10
+ if (typeof urlOrString === 'string') {
9
11
  return urlOrString;
10
12
  }
11
13
  if (isUrl(urlOrString)) {
12
14
  return urlOrString.toString();
13
15
  }
14
- throw new Error("Unexpected URL object");
16
+ throw new Error('Unexpected URL object');
15
17
  }
16
18
 
17
19
  function isUrl(urlOrString: any): urlOrString is URL {
@@ -1,9 +1,5 @@
1
- import { z } from "zod";
2
- import { batchPlayCommand, createCommand } from "../core/command";
3
-
4
- export async function photoshopGetApplicationInfo() {
5
- return await batchPlayCommand(photoshopApplicationInfoCommand);
6
- }
1
+ import { z } from 'zod';
2
+ import { batchPlayCommand, createCommand } from '../core/command';
7
3
 
8
4
  const photoshopAppInfoSchema = z.object({
9
5
  active: z.boolean(),
@@ -32,25 +28,29 @@ const photoshopAppInfoSchema = z.object({
32
28
  name: z.string(),
33
29
  obscured: z.boolean(),
34
30
  visible: z.boolean(),
35
- })
31
+ }),
36
32
  ),
37
33
  });
38
34
 
39
35
  const photoshopApplicationInfoCommand = createCommand({
40
36
  modifying: false,
41
37
  descriptor: {
42
- _obj: "get",
38
+ _obj: 'get',
43
39
  _target: [
44
40
  {
45
- _ref: "application",
46
- _enum: "ordinal",
47
- _value: "targetEnum",
41
+ _ref: 'application',
42
+ _enum: 'ordinal',
43
+ _value: 'targetEnum',
48
44
  },
49
45
  ],
50
46
  },
51
47
  schema: photoshopAppInfoSchema,
52
48
  });
53
49
 
50
+ export async function photoshopGetApplicationInfo() {
51
+ return await batchPlayCommand(photoshopApplicationInfoCommand);
52
+ }
53
+
54
54
  // $PnCK: {_enum: "cursorKind", _value: "brushSize"}
55
55
  // MRUColorList: (2) [{…}, {…}]
56
56
  // active: false
@@ -1,11 +1,11 @@
1
- import { photoshopGetApplicationInfo } from "./applicationInfo";
2
- import type { Test } from "@bubblydoo/uxp-test-framework";
3
- import { expect } from "chai";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { photoshopGetApplicationInfo } from './applicationInfo';
4
4
 
5
5
  export const applicationInfoTest: Test = {
6
- name: "Application Info",
6
+ name: 'Application Info',
7
7
  async run() {
8
8
  const info = await photoshopGetApplicationInfo();
9
- expect(info.hostName).to.include("Adobe Photoshop");
9
+ expect(info.hostName).to.include('Adobe Photoshop');
10
10
  },
11
- }
11
+ };
@@ -1,10 +1,10 @@
1
1
  export async function copyToClipboard(text: string): Promise<void> {
2
2
  await navigator.clipboard.writeText({
3
- "text/plain": text,
3
+ 'text/plain': text,
4
4
  } as any);
5
5
  }
6
6
 
7
7
  export async function readFromClipboard(): Promise<string> {
8
8
  const clipboard = await navigator.clipboard.readText();
9
- return (clipboard as any)["text/plain"];
9
+ return (clipboard as any)['text/plain'];
10
10
  }
@@ -1,17 +1,18 @@
1
- import type { Test } from "@bubblydoo/uxp-test-framework";
2
- import { copyToClipboard, readFromClipboard } from "./clipboard";
3
- import { expect } from "chai";
1
+ import type { Test } from '@bubblydoo/uxp-test-framework';
2
+ import { expect } from 'chai';
3
+ import { copyToClipboard, readFromClipboard } from './clipboard';
4
4
 
5
5
  export const clipboardTest: Test = {
6
- name: "should copy and read from clipboard",
6
+ name: 'should copy and read from clipboard',
7
7
  async run() {
8
8
  const originalClipboard = await readFromClipboard();
9
9
  try {
10
- await copyToClipboard("test");
10
+ await copyToClipboard('test');
11
11
  const clipboard = await readFromClipboard();
12
- expect(clipboard).to.eq("test");
13
- } finally {
12
+ expect(clipboard).to.eq('test');
13
+ }
14
+ finally {
14
15
  await copyToClipboard(originalClipboard);
15
16
  }
16
17
  },
17
- };
18
+ };