@bubblydoo/uxp-toolkit 0.0.2

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 (50) hide show
  1. package/.turbo/turbo-build.log +15 -0
  2. package/CHANGELOG.md +7 -0
  3. package/dist/index.d.ts +271 -0
  4. package/dist/index.js +733 -0
  5. package/package.json +41 -0
  6. package/src/commands-library/getLayerProperties.ts +32 -0
  7. package/src/commands-library/renameLayer.ts +15 -0
  8. package/src/commands-library/renameLayer.uxp-test.ts +32 -0
  9. package/src/core/batchPlay.ts +16 -0
  10. package/src/core/command.ts +130 -0
  11. package/src/core/executeAsModal.ts +101 -0
  12. package/src/core/suspendHistory.ts +15 -0
  13. package/src/core/suspendHistory.uxp-test.ts +18 -0
  14. package/src/core-wrappers/executeAsModalAndSuspendHistory.ts +11 -0
  15. package/src/dom/getFlattenedDomLayersList.ts +43 -0
  16. package/src/dom/photoshopDomLayersToTree.ts +18 -0
  17. package/src/error-sourcemaps/sourcemaps.ts +100 -0
  18. package/src/error-sourcemaps/sourcemaps.uxp-test.ts +24 -0
  19. package/src/errors/ut-error.ts +6 -0
  20. package/src/filesystem/openFileByPath.ts +10 -0
  21. package/src/general-tree/flattenTree.ts +12 -0
  22. package/src/general-tree/layerRef.ts +4 -0
  23. package/src/general-tree/mapTree.ts +11 -0
  24. package/src/general-tree/mapTreeRef.ts +11 -0
  25. package/src/general-tree/treeTypes.ts +7 -0
  26. package/src/index.ts +73 -0
  27. package/src/metadata-storage/metadataStorage.ts +66 -0
  28. package/src/metadata-storage/metadataStorage.uxp-test.ts +35 -0
  29. package/src/node-compat/path/resolvePath.ts +19 -0
  30. package/src/other/applicationInfo.ts +169 -0
  31. package/src/other/applicationInfo.uxp-test.ts +11 -0
  32. package/src/other/clipboard.ts +10 -0
  33. package/src/other/clipboard.uxp-test.ts +17 -0
  34. package/src/other/uxpEntrypoints.ts +9 -0
  35. package/src/ut-tree/getFlattenedLayerDescriptorsList.ts +72 -0
  36. package/src/ut-tree/getLayerEffects.ts +41 -0
  37. package/src/ut-tree/getLayerProperties.ts +35 -0
  38. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.ts +182 -0
  39. package/src/ut-tree/photoshopLayerDescriptorsToUTLayers.uxp-test.ts +52 -0
  40. package/src/ut-tree/psLayerRef.ts +4 -0
  41. package/src/ut-tree/utLayersToTree.ts +21 -0
  42. package/src/util/utLayerToLayer.ts +41 -0
  43. package/test/fixtures/clipping-layers.psd +0 -0
  44. package/test/fixtures/one-layer.psd +0 -0
  45. package/test/index.ts +21 -0
  46. package/test/meta-tests/executeAsModal.uxp-test.ts +38 -0
  47. package/test/meta-tests/suspendHistory.uxp-test.ts +27 -0
  48. package/tsconfig.json +13 -0
  49. package/tsup.config.ts +9 -0
  50. package/uxp-tests.json +13 -0
@@ -0,0 +1,15 @@
1
+
2
+ > @bubblydoo/uxp-toolkit@0.0.2 build /home/runner/work/uxp-toolkit/uxp-toolkit/packages/uxp-toolkit
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/uxp-toolkit/uxp-toolkit/packages/uxp-toolkit/tsup.config.ts
9
+ CLI Target: es2022
10
+ ESM Build start
11
+ ESM dist/index.js 19.84 KB
12
+ ESM ⚡️ Build success in 37ms
13
+ DTS Build start
14
+ DTS ⚡️ Build success in 2537ms
15
+ DTS dist/index.d.ts 10.96 KB
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @bubblydoo/uxp-toolkit
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 3cafb8e: Initial setup
@@ -0,0 +1,271 @@
1
+ import * as photoshop_dom_CoreModules from 'photoshop/dom/CoreModules';
2
+ import { ActionDescriptor } from 'photoshop/dom/CoreModules';
3
+ import { action } from 'photoshop';
4
+ import { z } from 'zod';
5
+ import * as photoshop_dom_Document from 'photoshop/dom/Document';
6
+ import { Document } from 'photoshop/dom/Document';
7
+ import { Layer } from 'photoshop/dom/Layer';
8
+ import ErrorStackParser from 'error-stack-parser';
9
+
10
+ type P = Parameters<typeof action.batchPlay>;
11
+ type CorrectBatchPlayOptions = P[1] & {
12
+ immediateRedraw?: boolean;
13
+ };
14
+ declare function batchPlay(actions: P[0], options?: CorrectBatchPlayOptions): Promise<photoshop_dom_CoreModules.ActionDescriptor[]>;
15
+
16
+ interface UTCommandBase<T extends any> {
17
+ descriptor: ActionDescriptor;
18
+ schema: z.ZodSchema<T>;
19
+ }
20
+ interface UTCommandModifying<T extends any> extends UTCommandBase<T> {
21
+ modifying: true;
22
+ }
23
+ interface UTCommandNonModifying<T extends any> extends UTCommandBase<T> {
24
+ modifying: false;
25
+ }
26
+ declare function createCommand<TReturn extends any, TModifying extends boolean>(obj: {
27
+ descriptor: ActionDescriptor;
28
+ schema: z.ZodSchema<TReturn>;
29
+ modifying: TModifying;
30
+ }): TModifying extends true ? UTCommandModifying<TReturn> : UTCommandNonModifying<TReturn>;
31
+ type UTCommandResult<C> = C extends UTCommandBase<infer T> ? T : never;
32
+ type BatchPlayOptions = Parameters<typeof batchPlay>[1];
33
+ declare function batchPlayCommandBase<T extends any>(command: UTCommandBase<T>, options?: BatchPlayOptions): Promise<T>;
34
+ declare function batchPlayCommandsBase<TCommands extends Array<UTCommandBase<any>>>(commands: readonly [...TCommands], options?: BatchPlayOptions): Promise<{
35
+ [K in keyof TCommands]: UTCommandResult<TCommands[K]>;
36
+ }>;
37
+ declare function batchPlayCommand<T extends any>(command: UTCommandNonModifying<T>, options?: BatchPlayOptions): Promise<T>;
38
+ declare function batchPlayCommands<TCommands extends Array<UTCommandNonModifying<any>>>(commands: readonly [...TCommands], options?: BatchPlayOptions): Promise<{ [K in keyof TCommands]: UTCommandResult<TCommands[K]>; }>;
39
+ declare function createModifyingBatchPlayContext(): {
40
+ batchPlayCommand: typeof batchPlayCommandBase;
41
+ batchPlayCommands: typeof batchPlayCommandsBase;
42
+ };
43
+
44
+ type CorrectExecutionContext = {
45
+ /**
46
+ * True if user has cancelled the modal interaction.
47
+ *
48
+ * User can cancel by hitting the Escape key, or by pressing the "Cancel" button in the progress bar.
49
+ */
50
+ isCancelled: boolean;
51
+ /**
52
+ * If assigned a method, it will be called when user cancels the modal interaction.
53
+ */
54
+ onCancel: () => void;
55
+ /**
56
+ * Call this to customize the progress bar.
57
+ */
58
+ reportProgress: (info: {
59
+ value: number;
60
+ commandName?: string;
61
+ }) => void;
62
+ /**
63
+ * Use the methods in here to control Photoshop state
64
+ */
65
+ hostControl: {
66
+ /**
67
+ * Call to suspend history on a target document, returns the suspension ID which can be used for resumeHistory
68
+ */
69
+ suspendHistory: (info: {
70
+ documentID: number;
71
+ name: string;
72
+ }) => Promise<number>;
73
+ /**
74
+ * Call to resume history on a target document
75
+ */
76
+ resumeHistory: (suspensionID: number, commit: boolean) => Promise<void>;
77
+ /** Register a document to be closed when the modal scope exits. See below for details. */
78
+ registerAutoCloseDocument: (documentID: number) => Promise<void>;
79
+ /** Unregister a document from being closed when the modal scope exits */
80
+ unregisterAutoCloseDocument: (documentID: number) => Promise<void>;
81
+ };
82
+ };
83
+ type CorrectExecuteAsModalOptions = {
84
+ commandName: string;
85
+ interactive?: boolean;
86
+ timeOut?: number;
87
+ };
88
+ type ExtendedExecutionContext = Omit<CorrectExecutionContext, "onCancel"> & ReturnType<typeof createModifyingBatchPlayContext> & {
89
+ signal: AbortSignal;
90
+ };
91
+ type OptionsWithoutCommandName = Omit<CorrectExecuteAsModalOptions, "commandName">;
92
+ declare function executeAsModal<T>(commandName: string, fn: (executionContext: ExtendedExecutionContext) => Promise<T>, opts?: OptionsWithoutCommandName): Promise<T>;
93
+
94
+ type SuspendHistoryContext = {};
95
+ declare function suspendHistory<T>(document: Document, historyStateName: string, fn: (context: SuspendHistoryContext) => Promise<T>): Promise<T>;
96
+
97
+ type CombinedFn<T> = (executionContext: ExtendedExecutionContext, suspendHistoryContext: SuspendHistoryContext) => Promise<T>;
98
+ declare const executeAsModalAndSuspendHistory: <T>(commandName: string, document: Document, fn: CombinedFn<T>) => Promise<T>;
99
+
100
+ declare const getLayerProperties$1: (document: Document) => Promise<{
101
+ name: string;
102
+ layerID: number;
103
+ visible?: boolean | undefined;
104
+ }[]>;
105
+
106
+ type PsLayerRef = {
107
+ id: number;
108
+ docId: number;
109
+ };
110
+
111
+ declare function createRenameLayerCommand(layerRef: PsLayerRef, newName: string): UTCommandModifying<unknown>;
112
+
113
+ declare const getFlattenedDomLayersList: (layers: Layer[]) => Layer[];
114
+
115
+ type Tree<TRef = unknown> = {
116
+ ref: TRef;
117
+ name: string;
118
+ children?: Tree<TRef>;
119
+ }[];
120
+
121
+ declare const photoshopDomLayersToTree: (layers: Layer[]) => Tree<Layer>;
122
+
123
+ declare function openFileByPath(path: string): Promise<photoshop_dom_Document.Document>;
124
+
125
+ declare function flattenTree<T>(tree: Tree<T>): Tree<T>[0][];
126
+
127
+ declare function mapTree<TRef, TMappedRef>(tree: Tree<TRef>, mapFn: (node: TRef) => TMappedRef): Tree<TMappedRef>;
128
+
129
+ declare function mapTreeRef<TRef, TMappedRef>(tree: Tree<TRef>, mapFn: (node: TRef) => TMappedRef): Tree<TMappedRef>;
130
+
131
+ type LayerRef = {
132
+ id: number;
133
+ docId: number;
134
+ };
135
+
136
+ declare function photoshopGetApplicationInfo(): Promise<{
137
+ active: boolean;
138
+ autoShowHomeScreen: boolean;
139
+ available: number;
140
+ buildNumber: string;
141
+ documentArea: {
142
+ left: number;
143
+ top: number;
144
+ right: number;
145
+ bottom: number;
146
+ };
147
+ hostName: string;
148
+ hostVersion: {
149
+ versionMajor: number;
150
+ versionMinor: number;
151
+ versionFix: number;
152
+ };
153
+ localeInfo: {
154
+ decimalPoint: string;
155
+ };
156
+ osVersion: string;
157
+ panelList: {
158
+ ID: string;
159
+ name: string;
160
+ obscured: boolean;
161
+ visible: boolean;
162
+ }[];
163
+ }>;
164
+
165
+ declare function copyToClipboard(text: string): Promise<void>;
166
+ declare function readFromClipboard(): Promise<string>;
167
+
168
+ declare const uxpEntrypointsSchema: z.ZodObject<{
169
+ _pluginInfo: z.ZodObject<{
170
+ id: z.ZodString;
171
+ name: z.ZodString;
172
+ version: z.ZodString;
173
+ }, z.core.$strip>;
174
+ }, z.core.$strip>;
175
+
176
+ declare const layerDescriptorSchema: z.ZodObject<{
177
+ name: z.ZodString;
178
+ layerID: z.ZodNumber;
179
+ mode: z.ZodObject<{
180
+ _enum: z.ZodLiteral<"blendMode">;
181
+ _value: z.ZodString;
182
+ }, z.core.$strip>;
183
+ background: z.ZodBoolean;
184
+ itemIndex: z.ZodNumber;
185
+ visible: z.ZodBoolean;
186
+ layerKind: z.ZodNumber;
187
+ layerSection: z.ZodObject<{
188
+ _value: z.ZodEnum<{
189
+ layerSectionStart: "layerSectionStart";
190
+ layerSectionEnd: "layerSectionEnd";
191
+ layerSectionContent: "layerSectionContent";
192
+ }>;
193
+ _enum: z.ZodLiteral<"layerSectionType">;
194
+ }, z.core.$strip>;
195
+ }, z.core.$strip>;
196
+ type LayerDescriptor = z.infer<typeof layerDescriptorSchema> & {
197
+ docId: number;
198
+ };
199
+ declare const getFlattenedLayerDescriptorsList: (documentId: number) => Promise<{
200
+ docId: number;
201
+ name: string;
202
+ layerID: number;
203
+ mode: {
204
+ _enum: "blendMode";
205
+ _value: string;
206
+ };
207
+ background: boolean;
208
+ itemIndex: number;
209
+ visible: boolean;
210
+ layerKind: number;
211
+ layerSection: {
212
+ _value: "layerSectionStart" | "layerSectionEnd" | "layerSectionContent";
213
+ _enum: "layerSectionType";
214
+ };
215
+ }[]>;
216
+
217
+ declare function createGetLayerPropertiesCommand(docId: number): UTCommandNonModifying<{
218
+ list: {
219
+ name: string;
220
+ layerID: number;
221
+ visible?: boolean | undefined;
222
+ }[];
223
+ }>;
224
+ declare const getLayerProperties: (documentId: number) => Promise<{
225
+ name: string;
226
+ layerID: number;
227
+ visible?: boolean | undefined;
228
+ }[]>;
229
+
230
+ declare function createGetLayerCommand(layerRef: PsLayerRef): UTCommandNonModifying<{
231
+ layerID: number;
232
+ group?: boolean | undefined;
233
+ layerEffects?: Record<string, {
234
+ enabled?: boolean | undefined;
235
+ } | {
236
+ enabled: boolean;
237
+ }[]> | undefined;
238
+ }>;
239
+ declare function getLayerEffects(layerRef: PsLayerRef): Promise<Record<string, boolean>>;
240
+
241
+ type UTLayerKind = "pixel" | "adjustment-layer" | "text" | "curves" | "smartObject" | "video" | "group" | "threeD" | "gradientFill" | "pattern" | "solidColor" | "background";
242
+ 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";
243
+ type UTLayerBuilder = {
244
+ name: string;
245
+ docId: number;
246
+ id: number;
247
+ visible: boolean;
248
+ kind: UTLayerKind;
249
+ blendMode: UTBlendMode;
250
+ effects: Record<string, boolean>;
251
+ isClippingMask: boolean;
252
+ layers?: UTLayerBuilder[];
253
+ };
254
+ type UTLayer = Readonly<Omit<UTLayerBuilder, "layers">> & {
255
+ layers?: UTLayer[];
256
+ };
257
+ declare const photoshopLayerDescriptorsToUTLayers: (layers: LayerDescriptor[]) => Promise<UTLayer[]>;
258
+
259
+ type UTLayerWithoutChildren = Omit<UTLayer, "layers">;
260
+ declare function utLayersToTree(layer: UTLayer[]): Tree<UTLayerWithoutChildren>;
261
+
262
+ declare function utLayerToDomLayer(layer: UTLayer): Layer;
263
+ declare function utLayersToDomLayers(layers: UTLayer[]): Layer[];
264
+
265
+ type BasicStackFrame = Pick<ErrorStackParser.StackFrame, "functionName" | "fileName" | "lineNumber" | "columnNumber">;
266
+ declare function parseUxpErrorSourcemaps(error: Error, opts?: {
267
+ unsourcemappedHeaderLines?: number;
268
+ }): Promise<BasicStackFrame[]>;
269
+ declare function getBasicStackFrameAbsoluteFilePath(frame: BasicStackFrame): Promise<string>;
270
+
271
+ export { type BasicStackFrame, type CorrectBatchPlayOptions, type CorrectExecuteAsModalOptions, type CorrectExecutionContext, type ExtendedExecutionContext, type LayerDescriptor, type LayerRef, type PsLayerRef, type SuspendHistoryContext, type Tree, type UTCommandBase, type UTCommandModifying, type UTCommandNonModifying, type UTCommandResult, type UTLayer, type UTLayerWithoutChildren, batchPlay, batchPlayCommand, batchPlayCommands, copyToClipboard, createCommand, createGetLayerCommand as createGetLayerEffectsCommand, createGetLayerPropertiesCommand, createModifyingBatchPlayContext, createRenameLayerCommand, executeAsModal, executeAsModalAndSuspendHistory, flattenTree, getBasicStackFrameAbsoluteFilePath, getFlattenedDomLayersList, getFlattenedLayerDescriptorsList, getLayerEffects, getLayerProperties$1 as getLayerProperties, getLayerProperties as getLayerPropertiesFromUtTree, mapTree, mapTreeRef, openFileByPath, parseUxpErrorSourcemaps, photoshopDomLayersToTree, photoshopGetApplicationInfo, photoshopLayerDescriptorsToUTLayers, readFromClipboard, suspendHistory, utLayerToDomLayer, utLayersToDomLayers, utLayersToTree, uxpEntrypointsSchema };