@ps-generator-bridge/sdk 0.1.0
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/LICENSE +21 -0
- package/dist/PsPhotoshopProxy-BjnvziWn.d.cts +879 -0
- package/dist/PsPhotoshopProxy-BjnvziWn.d.ts +879 -0
- package/dist/index.cjs +1131 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +210 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +1117 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.cjs +915 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +457 -0
- package/dist/plugin.d.ts +457 -0
- package/dist/plugin.js +902 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { S as ServerInfo, M as MethodName, P as ProtocolMethods, E as EventName, a as ProtocolEvents, b as PhotoshopEventName, c as PhotoshopEventMap, d as PsJsxRunner, e as PsPhotoshopProxy, f as PluginInfo, g as ProtocolMethod, h as PsLayer, i as PsDocument } from './PsPhotoshopProxy-BjnvziWn.js';
|
|
2
|
+
export { B as Bounds, j as ErrorCode, k as EventEnvelope, I as ImageChangedEvent, l as ImageChangedLayer, L as LayerSpec, m as PROTOCOL_VERSION, n as ProtocolError, o as PsBounds, p as PsRect, R as RequestEnvelope, q as ResponseEnvelope, W as WsImageResult, r as isEvent, s as isRequest, t as isResponse, u as parseFrame, v as serializeFrame } from './PsPhotoshopProxy-BjnvziWn.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transport seam (ADR 0002). The client only knows this interface; the default
|
|
6
|
+
* implementation uses the global `WebSocket`. Callers on Node 18-21 (which lack a
|
|
7
|
+
* global WebSocket) or in tests inject their own implementation.
|
|
8
|
+
*/
|
|
9
|
+
interface Transport {
|
|
10
|
+
/** Resolves once the transport is open and ready to send. */
|
|
11
|
+
ready(): Promise<void>;
|
|
12
|
+
send(data: string): void;
|
|
13
|
+
onMessage(listener: (data: string) => void): void;
|
|
14
|
+
/** Fired when the underlying connection drops (used by Connection to reconnect). */
|
|
15
|
+
onClose(listener: () => void): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a Transport from a WebSocket constructor + url. If none is injected,
|
|
20
|
+
* falls back to the global `WebSocket`, throwing an actionable error when it is
|
|
21
|
+
* absent (Node 18-21) rather than a cryptic `WebSocket is not defined`.
|
|
22
|
+
*
|
|
23
|
+
* The upgrade path (ADR 0002) — auto-resolving `ws` on Node < 22 — would slot in
|
|
24
|
+
* at `resolveGlobalWebSocket` without changing this signature.
|
|
25
|
+
*/
|
|
26
|
+
declare function createWebSocketTransport(url: string, WebSocketImpl?: typeof WebSocket): Transport;
|
|
27
|
+
|
|
28
|
+
interface RawConnectionOptions {
|
|
29
|
+
/**
|
|
30
|
+
* ws:// URL to connect to. Use `ws://<host>:<port>/ws` for the public root
|
|
31
|
+
* endpoint, or `ws://<host>:<port>/ws/{pluginId}` for a plugin-scoped raw
|
|
32
|
+
* connection that can invoke that plugin's private methods.
|
|
33
|
+
*/
|
|
34
|
+
url: string;
|
|
35
|
+
/** Inject a WebSocket implementation for Node 18-21 (e.g. the `ws` package). */
|
|
36
|
+
WebSocket?: typeof WebSocket;
|
|
37
|
+
/** Override transport creation (primary test seam); receives the per-attempt URL. */
|
|
38
|
+
transportFactory?: (url: string) => Transport;
|
|
39
|
+
/** Per-request timeout in ms (default 10000). */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
/** Max reconnect attempts after a drop before failing (default 5). */
|
|
42
|
+
maxRetries?: number;
|
|
43
|
+
/** Delay between reconnect attempts in ms (default 5000). */
|
|
44
|
+
retryDelayMs?: number;
|
|
45
|
+
/** Optional initial clientId to request via ?id= on first connect. */
|
|
46
|
+
clientId?: string;
|
|
47
|
+
}
|
|
48
|
+
type EventListener = (data: unknown) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Stateful SDK entry point (ADR 0005/0007). Owns a Transport factory and:
|
|
51
|
+
* reconnects on drop (up to maxRetries), remembers and re-sends its clientId,
|
|
52
|
+
* resolves `ready()` only once the server's `connected` handshake arrives,
|
|
53
|
+
* correlates `invoke` requests to responses, and dispatches subscribed Events.
|
|
54
|
+
*
|
|
55
|
+
* Readiness is a state machine, not a single promise: a transient drop moves it
|
|
56
|
+
* back to "connecting" so new and queued `invoke`s wait for the next handshake;
|
|
57
|
+
* exhausting the retry budget moves it to "failed" and rejects everything.
|
|
58
|
+
*/
|
|
59
|
+
declare class RawConnection {
|
|
60
|
+
private readonly options;
|
|
61
|
+
private readonly maxRetries;
|
|
62
|
+
private readonly retryDelayMs;
|
|
63
|
+
private readonly requests;
|
|
64
|
+
private readonly listeners;
|
|
65
|
+
private transport;
|
|
66
|
+
private clientId;
|
|
67
|
+
private attempts;
|
|
68
|
+
private state;
|
|
69
|
+
private failError;
|
|
70
|
+
private readyWaiters;
|
|
71
|
+
private retryTimer;
|
|
72
|
+
constructor(options: RawConnectionOptions);
|
|
73
|
+
/** The clientId assigned by the server (undefined until the first handshake). */
|
|
74
|
+
get id(): string | undefined;
|
|
75
|
+
/** Resolves once connected (handshake received); rejects if retries are exhausted. */
|
|
76
|
+
ready(): Promise<void>;
|
|
77
|
+
/** Fetch the server's identity + (when connected to PS) its Photoshop version. */
|
|
78
|
+
getServerInfo(): Promise<ServerInfo>;
|
|
79
|
+
/** Send a Request and await its correlated response. Queues during reconnect. */
|
|
80
|
+
invoke<M extends MethodName>(method: M, params: ProtocolMethods[M]["params"]): Promise<ProtocolMethods[M]["result"]>;
|
|
81
|
+
invoke(method: string, params?: unknown): Promise<unknown>;
|
|
82
|
+
/** Subscribe to a server-pushed Event. */
|
|
83
|
+
on<E extends EventName>(type: E, listener: (data: ProtocolEvents[E]) => void): void;
|
|
84
|
+
on(type: string, listener: (data: unknown) => void): void;
|
|
85
|
+
/** Unsubscribe a previously registered Event listener. */
|
|
86
|
+
off(type: string, listener: EventListener): void;
|
|
87
|
+
/** Close the connection: stop reconnecting and reject all in-flight work. */
|
|
88
|
+
close(): void;
|
|
89
|
+
private connect;
|
|
90
|
+
private buildUrl;
|
|
91
|
+
private handleMessage;
|
|
92
|
+
private handleDrop;
|
|
93
|
+
private markReady;
|
|
94
|
+
private fail;
|
|
95
|
+
private dispatchEvent;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare const DEFAULT_CONNECTION_URL = "ws://127.0.0.1:7700/ws";
|
|
99
|
+
interface ConnectionOptions extends Omit<RawConnectionOptions, "url"> {
|
|
100
|
+
/** Root ws:// URL. Defaults to ws://127.0.0.1:7700/ws. */
|
|
101
|
+
url?: string;
|
|
102
|
+
}
|
|
103
|
+
type PublicListener<K extends PhotoshopEventName> = (data: PhotoshopEventMap[K]) => void;
|
|
104
|
+
type Invoker = <M extends MethodName>(method: M, params: ProtocolMethods[M]["params"]) => Promise<ProtocolMethods[M]["result"]>;
|
|
105
|
+
declare class PublicEventClient {
|
|
106
|
+
private readonly invoke;
|
|
107
|
+
private readonly listeners;
|
|
108
|
+
private readonly wrappers;
|
|
109
|
+
private readonly activeSubscriptions;
|
|
110
|
+
private readonly pendingSubscriptions;
|
|
111
|
+
constructor(invoke: Invoker);
|
|
112
|
+
on<K extends PhotoshopEventName>(type: K, listener: PublicListener<K>): void;
|
|
113
|
+
once<K extends PhotoshopEventName>(type: K, listener: PublicListener<K>): void;
|
|
114
|
+
off<K extends PhotoshopEventName>(type: K, listener: PublicListener<K>): void;
|
|
115
|
+
dispatch(type: string, data: unknown): void;
|
|
116
|
+
replay(): void;
|
|
117
|
+
private add;
|
|
118
|
+
private remove;
|
|
119
|
+
private listenerCount;
|
|
120
|
+
private subscribe;
|
|
121
|
+
private unsubscribe;
|
|
122
|
+
}
|
|
123
|
+
declare class PublicJsxRunner implements PsJsxRunner {
|
|
124
|
+
private readonly invoke;
|
|
125
|
+
constructor(invoke: Invoker);
|
|
126
|
+
run<T = unknown>(script: string): Promise<T>;
|
|
127
|
+
execute<T = unknown>(name: string, params?: Record<string, unknown>): Promise<T>;
|
|
128
|
+
}
|
|
129
|
+
declare class PublicPluginClient {
|
|
130
|
+
private readonly getServerInfo;
|
|
131
|
+
constructor(getServerInfo: () => Promise<ServerInfo>);
|
|
132
|
+
list(): Promise<PluginInfo[]>;
|
|
133
|
+
has(id: string): Promise<boolean>;
|
|
134
|
+
}
|
|
135
|
+
declare class PublicModules {
|
|
136
|
+
private readonly invoke;
|
|
137
|
+
readonly layer: {
|
|
138
|
+
getLayerInfo: (params?: ProtocolMethods[typeof ProtocolMethod.LayerGetInfo]["params"]) => Promise<PsLayer>;
|
|
139
|
+
getLayerInfoByID: (layerID: number, options?: {
|
|
140
|
+
getChildren: boolean;
|
|
141
|
+
}) => Promise<PsLayer>;
|
|
142
|
+
getLayerInfoByIndex: (layerIndex: number, options?: {
|
|
143
|
+
getChildren: boolean;
|
|
144
|
+
}) => Promise<PsLayer>;
|
|
145
|
+
};
|
|
146
|
+
readonly document: {
|
|
147
|
+
getCurrentDocument: () => Promise<PsDocument>;
|
|
148
|
+
exportDocument: (params: ProtocolMethods[typeof ProtocolMethod.DocumentExport]["params"]) => Promise<unknown>;
|
|
149
|
+
saveDocument: (params: ProtocolMethods[typeof ProtocolMethod.DocumentSave]["params"]) => Promise<unknown>;
|
|
150
|
+
};
|
|
151
|
+
readonly action: {
|
|
152
|
+
autoCutout: () => Promise<boolean>;
|
|
153
|
+
removeBackground: () => Promise<{
|
|
154
|
+
success: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
};
|
|
157
|
+
constructor(invoke: Invoker);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Public root /ws facade. It exposes framework-owned surfaces only: Photoshop
|
|
161
|
+
* events, jsx, Photoshop DOM proxy, plugin discovery, and built-in modules.
|
|
162
|
+
*/
|
|
163
|
+
declare class Connection {
|
|
164
|
+
private readonly raw;
|
|
165
|
+
private readonly call;
|
|
166
|
+
private readonly eventClient;
|
|
167
|
+
private readonly jsxClient;
|
|
168
|
+
readonly event: Pick<PublicEventClient, "on" | "once" | "off">;
|
|
169
|
+
readonly jsx: Pick<PublicJsxRunner, "run" | "execute">;
|
|
170
|
+
readonly photoshop: PsPhotoshopProxy;
|
|
171
|
+
readonly plugin: PublicPluginClient;
|
|
172
|
+
readonly modules: PublicModules;
|
|
173
|
+
constructor(options?: ConnectionOptions);
|
|
174
|
+
get id(): string | undefined;
|
|
175
|
+
ready(): Promise<void>;
|
|
176
|
+
close(): void;
|
|
177
|
+
getServerInfo(): Promise<ServerInfo>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface PsBridgeClientOptions {
|
|
181
|
+
/** ws:// URL of the server. Required unless a custom `transport` is given. */
|
|
182
|
+
url?: string;
|
|
183
|
+
/** Inject a transport (primary seam; tests pass a FakeTransport). */
|
|
184
|
+
transport?: Transport;
|
|
185
|
+
/** Inject a WebSocket implementation for Node 18-21 (e.g. the `ws` package). */
|
|
186
|
+
WebSocket?: typeof WebSocket;
|
|
187
|
+
/** Per-request timeout in ms (default 10000). */
|
|
188
|
+
timeoutMs?: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Typed client over a {@link Transport}. Correlates each request to its response
|
|
192
|
+
* by id; rejects on protocol errors, timeouts, or close.
|
|
193
|
+
*
|
|
194
|
+
* @deprecated Use {@link Connection}, which adds reconnect, a stable clientId, and
|
|
195
|
+
* Event subscription. Retained until existing callers migrate.
|
|
196
|
+
*/
|
|
197
|
+
declare class PsBridgeClient {
|
|
198
|
+
private readonly transport;
|
|
199
|
+
private readonly requests;
|
|
200
|
+
constructor(options: PsBridgeClientOptions);
|
|
201
|
+
/** Fetch the server's identity + (when connected to PS) its Photoshop version. */
|
|
202
|
+
getServerInfo(): Promise<ServerInfo>;
|
|
203
|
+
/** Send a typed request and await its correlated response. */
|
|
204
|
+
request<M extends MethodName>(method: M, params: ProtocolMethods[M]["params"]): Promise<ProtocolMethods[M]["result"]>;
|
|
205
|
+
/** Reject all in-flight requests and close the transport. */
|
|
206
|
+
close(): void;
|
|
207
|
+
private handleMessage;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { Connection, type ConnectionOptions, DEFAULT_CONNECTION_URL, EventName, MethodName, PhotoshopEventMap, PhotoshopEventName, PluginInfo, ProtocolEvents, ProtocolMethod, ProtocolMethod as ProtocolMethodName, ProtocolMethods, PsBridgeClient, type PsBridgeClientOptions, PsDocument, PsLayer, RawConnection, type RawConnectionOptions, ServerInfo, type Transport, createWebSocketTransport };
|