@dilemmagx/orchestra 1.1.0 → 1.2.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.
- package/LICENSE +673 -0
- package/README.md +147 -57
- package/dist/core/color.d.ts +87 -0
- package/dist/core/image.d.ts +63 -0
- package/dist/core/nodes.d.ts +431 -0
- package/dist/core/pipeline.d.ts +46 -0
- package/dist/core/random.d.ts +35 -0
- package/dist/core/sources.d.ts +107 -0
- package/dist/core/types.d.ts +46 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +7 -0
- package/package.json +3 -1
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { ImageBuffer } from './image';
|
|
2
|
+
import { ColorInput } from './color';
|
|
3
|
+
import { ImageSource, Pixel, PixelLike } from './types';
|
|
4
|
+
import { SeededRandom } from './random';
|
|
5
|
+
import { ResizeOptions, type TextOptions } from './sources';
|
|
6
|
+
export declare const DEFAULT_IMAGE_KEY = "image";
|
|
7
|
+
/**
|
|
8
|
+
* Runtime context shared across nodes in a pipeline run.
|
|
9
|
+
*/
|
|
10
|
+
export type NodeContext = {
|
|
11
|
+
random: SeededRandom;
|
|
12
|
+
stash: Map<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* State passed between nodes in a pipeline run.
|
|
16
|
+
*/
|
|
17
|
+
export type NodeState = {
|
|
18
|
+
images: Record<string, ImageBuffer>;
|
|
19
|
+
data: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Result returned by a node execution.
|
|
23
|
+
*/
|
|
24
|
+
export type NodeResult = {
|
|
25
|
+
images?: Record<string, ImageBuffer>;
|
|
26
|
+
data?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
type NodeRunner<TParams> = {
|
|
29
|
+
bivarianceHack(context: NodeContext, state: NodeState, params: TParams): Promise<NodeResult> | NodeResult;
|
|
30
|
+
}['bivarianceHack'];
|
|
31
|
+
/**
|
|
32
|
+
* Pipeline node definition.
|
|
33
|
+
*/
|
|
34
|
+
export type NodeDefinition<TParams = unknown> = {
|
|
35
|
+
name: string;
|
|
36
|
+
params?: TParams;
|
|
37
|
+
inputs?: string[];
|
|
38
|
+
outputs?: string[];
|
|
39
|
+
run: NodeRunner<TParams>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Alias for image-focused nodes.
|
|
43
|
+
*/
|
|
44
|
+
export type ImageNode<TParams = unknown> = NodeDefinition<TParams>;
|
|
45
|
+
/**
|
|
46
|
+
* Image node with typed parameters metadata.
|
|
47
|
+
*/
|
|
48
|
+
export type ParametricNode<TParams> = ImageNode<TParams> & {
|
|
49
|
+
params: TParams;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Definition for a reusable node.
|
|
53
|
+
*/
|
|
54
|
+
export declare function defineNode<TParams>(definition: NodeDefinition<TParams>): NodeDefinition<TParams>;
|
|
55
|
+
/**
|
|
56
|
+
* Image node input definition.
|
|
57
|
+
*/
|
|
58
|
+
export type ImageNodeOptions = {
|
|
59
|
+
input?: string;
|
|
60
|
+
output?: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 2D pixel matrix representation.
|
|
64
|
+
*/
|
|
65
|
+
export type PixelMatrix = Pixel[][];
|
|
66
|
+
/**
|
|
67
|
+
* Context provided to pixel-based node handlers.
|
|
68
|
+
*/
|
|
69
|
+
export type PixelNodeInfo<TParams> = {
|
|
70
|
+
context: NodeContext;
|
|
71
|
+
image: ImageBuffer;
|
|
72
|
+
state: NodeState;
|
|
73
|
+
params: TParams;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Handler signature for pixel-based nodes.
|
|
79
|
+
*/
|
|
80
|
+
export type PixelNodeRunner<TParams> = (pixels: PixelMatrix, info: PixelNodeInfo<TParams>) => PixelMatrix | ImageBuffer | Promise<PixelMatrix | ImageBuffer>;
|
|
81
|
+
/**
|
|
82
|
+
* Simplified node definition.
|
|
83
|
+
*/
|
|
84
|
+
export type SimpleNodeDefinition<TParams> = {
|
|
85
|
+
name?: string;
|
|
86
|
+
params?: TParams;
|
|
87
|
+
input?: string;
|
|
88
|
+
output?: string;
|
|
89
|
+
run: PixelNodeRunner<TParams>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Creates a node that reads a single image key and writes a single image key.
|
|
93
|
+
*/
|
|
94
|
+
export declare function createImageNode<TParams>(name: string, params: TParams, run: (context: NodeContext, image: ImageBuffer, params: TParams, state: NodeState) => Promise<ImageBuffer> | ImageBuffer, options?: ImageNodeOptions): ImageNode<TParams>;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a node that operates on a 2D pixel matrix.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createPixelNode<TParams>(name: string, params: TParams, run: PixelNodeRunner<TParams>, options?: ImageNodeOptions): ImageNode<TParams>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a simplified pixel-based node with optional name and parameters.
|
|
101
|
+
*/
|
|
102
|
+
export declare function node<TParams>(definition: SimpleNodeDefinition<TParams>): ImageNode<TParams>;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the image associated with the given key.
|
|
105
|
+
*/
|
|
106
|
+
export declare function getImage(state: NodeState, key?: string): ImageBuffer;
|
|
107
|
+
/**
|
|
108
|
+
* Merges a node result into a state snapshot.
|
|
109
|
+
*/
|
|
110
|
+
export declare function mergeNodeState(state: NodeState, result: NodeResult): NodeState;
|
|
111
|
+
/**
|
|
112
|
+
* Runs a node and returns its raw result.
|
|
113
|
+
*/
|
|
114
|
+
export declare function runNode(node: ImageNode, context: NodeContext, state: NodeState): Promise<NodeResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Runs a node and returns a single image output.
|
|
117
|
+
*/
|
|
118
|
+
export declare function runNodeImage(node: ImageNode, context: NodeContext, state: NodeState, outputKey?: string): Promise<ImageBuffer>;
|
|
119
|
+
/**
|
|
120
|
+
* Selector used to choose pixels for masked execution.
|
|
121
|
+
*/
|
|
122
|
+
export type PixelSelector = (pixel: Pixel, x: number, y: number, context: NodeContext) => boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Masking options for nodes.
|
|
125
|
+
*/
|
|
126
|
+
export type SelectionOptions = {
|
|
127
|
+
mode?: SelectionMode;
|
|
128
|
+
outsideColor?: ColorInput;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Masking mode for selection.
|
|
132
|
+
*/
|
|
133
|
+
export type SelectionMode = 'preserve' | 'clip';
|
|
134
|
+
/**
|
|
135
|
+
* Image source input accepted by nodes.
|
|
136
|
+
*/
|
|
137
|
+
export type ImageInput = ImageSource | ImageBuffer | ImageNode;
|
|
138
|
+
/**
|
|
139
|
+
* Mask source for color mapping.
|
|
140
|
+
*/
|
|
141
|
+
export type MaskMapSource = ImageInput;
|
|
142
|
+
/**
|
|
143
|
+
* Color-to-source mapping entry.
|
|
144
|
+
*/
|
|
145
|
+
export type MaskMapEntry = {
|
|
146
|
+
color: ColorInput;
|
|
147
|
+
tolerance?: number;
|
|
148
|
+
source?: MaskMapSource;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Options for mask mapping nodes.
|
|
152
|
+
*/
|
|
153
|
+
export type MaskMapOptions = {
|
|
154
|
+
defaultColor?: ColorInput;
|
|
155
|
+
resize?: ResizeOptions;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Rectangle selector options.
|
|
159
|
+
*/
|
|
160
|
+
export type RectSelectorOptions = {
|
|
161
|
+
x: number;
|
|
162
|
+
y: number;
|
|
163
|
+
width: number;
|
|
164
|
+
height: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Circle selector options.
|
|
168
|
+
*/
|
|
169
|
+
export type CircleSelectorOptions = {
|
|
170
|
+
cx: number;
|
|
171
|
+
cy: number;
|
|
172
|
+
radius: number;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Creates a rectangle selector.
|
|
176
|
+
*/
|
|
177
|
+
export declare function createRectSelector(options: RectSelectorOptions): PixelSelector;
|
|
178
|
+
/**
|
|
179
|
+
* Creates a circle selector.
|
|
180
|
+
*/
|
|
181
|
+
export declare function createCircleSelector(options: CircleSelectorOptions): PixelSelector;
|
|
182
|
+
/**
|
|
183
|
+
* Creates a luminance-based selector.
|
|
184
|
+
*/
|
|
185
|
+
export declare function createLumaSelector(threshold: number): PixelSelector;
|
|
186
|
+
/**
|
|
187
|
+
* Creates an alpha-based selector.
|
|
188
|
+
*/
|
|
189
|
+
export declare function createAlphaSelector(threshold: number): PixelSelector;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a node with typed parameters stored in the node metadata.
|
|
192
|
+
*/
|
|
193
|
+
export declare function createParamNode<TParams>(name: string, params: TParams, run: (context: NodeContext, image: ImageBuffer, params: TParams) => ImageBuffer): ParametricNode<TParams>;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a masked node that only processes selected pixels.
|
|
196
|
+
*/
|
|
197
|
+
export declare function createMaskedNode(node: ImageNode, selector: PixelSelector, options?: SelectionOptions, io?: ImageNodeOptions): ImageNode;
|
|
198
|
+
/**
|
|
199
|
+
* Creates a node that composites sources based on a color mask.
|
|
200
|
+
*/
|
|
201
|
+
export declare function createMaskMapNode(mask: MaskMapSource, entries: MaskMapEntry[], options?: MaskMapOptions): ImageNode;
|
|
202
|
+
/**
|
|
203
|
+
* Creates a node that removes pixels outside the selection.
|
|
204
|
+
*/
|
|
205
|
+
export declare function createSelectionCropNode(selector: PixelSelector, options?: SelectionOptions): ImageNode;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a node that maps every pixel using a custom mapper.
|
|
208
|
+
*/
|
|
209
|
+
export declare function createMapNode(name: string, mapper: (pixel: Pixel, x: number, y: number, context: NodeContext) => PixelLike): ImageNode;
|
|
210
|
+
/**
|
|
211
|
+
* Creates a node that fills the image with a single color.
|
|
212
|
+
*/
|
|
213
|
+
export declare function createFillNode(color: ColorInput): ImageNode;
|
|
214
|
+
/**
|
|
215
|
+
* Options for creating a noise node.
|
|
216
|
+
*/
|
|
217
|
+
export type NoiseOptions = {
|
|
218
|
+
min?: number;
|
|
219
|
+
max?: number;
|
|
220
|
+
alpha?: number;
|
|
221
|
+
grayscale?: boolean;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Options for creating a value noise node.
|
|
225
|
+
*/
|
|
226
|
+
export type ValueNoiseOptions = {
|
|
227
|
+
scale?: number;
|
|
228
|
+
octaves?: number;
|
|
229
|
+
persistence?: number;
|
|
230
|
+
lacunarity?: number;
|
|
231
|
+
min?: number;
|
|
232
|
+
max?: number;
|
|
233
|
+
alpha?: number;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Options for creating a Voronoi noise node.
|
|
237
|
+
*/
|
|
238
|
+
export type VoronoiNoiseOptions = {
|
|
239
|
+
scale?: number;
|
|
240
|
+
jitter?: number;
|
|
241
|
+
min?: number;
|
|
242
|
+
max?: number;
|
|
243
|
+
alpha?: number;
|
|
244
|
+
mode?: 'distance' | 'edge';
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Options for creating a fractal noise node.
|
|
248
|
+
*/
|
|
249
|
+
export type FractalNoiseOptions = {
|
|
250
|
+
scale?: number;
|
|
251
|
+
octaves?: number;
|
|
252
|
+
persistence?: number;
|
|
253
|
+
lacunarity?: number;
|
|
254
|
+
min?: number;
|
|
255
|
+
max?: number;
|
|
256
|
+
alpha?: number;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Options for creating a Perlin noise node.
|
|
260
|
+
*/
|
|
261
|
+
export type PerlinNoiseOptions = {
|
|
262
|
+
scale?: number;
|
|
263
|
+
octaves?: number;
|
|
264
|
+
persistence?: number;
|
|
265
|
+
lacunarity?: number;
|
|
266
|
+
min?: number;
|
|
267
|
+
max?: number;
|
|
268
|
+
alpha?: number;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Options for creating a turbulence noise node.
|
|
272
|
+
*/
|
|
273
|
+
export type TurbulenceNoiseOptions = {
|
|
274
|
+
scale?: number;
|
|
275
|
+
octaves?: number;
|
|
276
|
+
persistence?: number;
|
|
277
|
+
lacunarity?: number;
|
|
278
|
+
min?: number;
|
|
279
|
+
max?: number;
|
|
280
|
+
alpha?: number;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Options for creating a ridged noise node.
|
|
284
|
+
*/
|
|
285
|
+
export type RidgedNoiseOptions = {
|
|
286
|
+
scale?: number;
|
|
287
|
+
octaves?: number;
|
|
288
|
+
persistence?: number;
|
|
289
|
+
lacunarity?: number;
|
|
290
|
+
min?: number;
|
|
291
|
+
max?: number;
|
|
292
|
+
alpha?: number;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Creates a node that applies seeded noise to every pixel.
|
|
296
|
+
*/
|
|
297
|
+
export declare function createNoiseNode(options?: NoiseOptions): ImageNode;
|
|
298
|
+
/**
|
|
299
|
+
* Creates a node that generates value noise.
|
|
300
|
+
*/
|
|
301
|
+
export declare function createValueNoiseNode(options?: ValueNoiseOptions): ImageNode;
|
|
302
|
+
/**
|
|
303
|
+
* Creates a node that generates Voronoi noise.
|
|
304
|
+
*/
|
|
305
|
+
export declare function createVoronoiNoiseNode(options?: VoronoiNoiseOptions): ImageNode;
|
|
306
|
+
/**
|
|
307
|
+
* Creates a node that generates fractal value noise.
|
|
308
|
+
*/
|
|
309
|
+
export declare function createFractalNoiseNode(options?: FractalNoiseOptions): ImageNode;
|
|
310
|
+
/**
|
|
311
|
+
* Creates a node that generates Perlin noise.
|
|
312
|
+
*/
|
|
313
|
+
export declare function createPerlinNoiseNode(options?: PerlinNoiseOptions): ImageNode;
|
|
314
|
+
/**
|
|
315
|
+
* Creates a node that generates turbulence noise.
|
|
316
|
+
*/
|
|
317
|
+
export declare function createTurbulenceNoiseNode(options?: TurbulenceNoiseOptions): ImageNode;
|
|
318
|
+
/**
|
|
319
|
+
* Creates a node that generates ridged noise.
|
|
320
|
+
*/
|
|
321
|
+
export declare function createRidgedNoiseNode(options?: RidgedNoiseOptions): ImageNode;
|
|
322
|
+
/**
|
|
323
|
+
* Options for convolution nodes.
|
|
324
|
+
*/
|
|
325
|
+
export type ConvolutionOptions = {
|
|
326
|
+
normalize?: boolean;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Creates a convolution node using an odd square kernel.
|
|
330
|
+
*/
|
|
331
|
+
export declare function createConvolutionNode(name: string, kernel: number[][], options?: ConvolutionOptions): ImageNode;
|
|
332
|
+
/**
|
|
333
|
+
* Creates a node that inverts RGB values.
|
|
334
|
+
*/
|
|
335
|
+
export declare function createInvertNode(): ImageNode;
|
|
336
|
+
/**
|
|
337
|
+
* Creates a node that converts RGB to grayscale.
|
|
338
|
+
*/
|
|
339
|
+
export declare function createGrayscaleNode(): ImageNode;
|
|
340
|
+
/**
|
|
341
|
+
* Creates a node that applies gamma correction.
|
|
342
|
+
*/
|
|
343
|
+
export declare function createGammaNode(gamma: number): ImageNode;
|
|
344
|
+
/**
|
|
345
|
+
* Creates a node that shifts brightness by a delta.
|
|
346
|
+
*/
|
|
347
|
+
export declare function createBrightnessNode(delta: number): ImageNode;
|
|
348
|
+
/**
|
|
349
|
+
* Creates a node that adjusts contrast around the midtone.
|
|
350
|
+
*/
|
|
351
|
+
export declare function createContrastNode(factor: number): ImageNode;
|
|
352
|
+
/**
|
|
353
|
+
* Creates a node that applies a binary threshold.
|
|
354
|
+
*/
|
|
355
|
+
export declare function createThresholdNode(threshold: number, low?: number, high?: number): ImageNode;
|
|
356
|
+
/**
|
|
357
|
+
* Creates a node that fills the image with a random color.
|
|
358
|
+
*/
|
|
359
|
+
export declare function createRandomFillNode(alpha?: number): ImageNode;
|
|
360
|
+
/**
|
|
361
|
+
* Creates a node that adds Gaussian noise.
|
|
362
|
+
*/
|
|
363
|
+
export declare function createGaussianNoiseNode(mean?: number, stdDev?: number, alpha?: number, grayscale?: boolean): ImageNode;
|
|
364
|
+
/**
|
|
365
|
+
* Creates a node that applies salt and pepper noise.
|
|
366
|
+
*/
|
|
367
|
+
export declare function createSaltPepperNoiseNode(probability?: number, salt?: ColorInput, pepper?: ColorInput): ImageNode;
|
|
368
|
+
/**
|
|
369
|
+
* Creates a checkerboard pattern node.
|
|
370
|
+
*/
|
|
371
|
+
export declare function createCheckerboardNode(tileSize: number, colorA: ColorInput, colorB: ColorInput): ImageNode;
|
|
372
|
+
/**
|
|
373
|
+
* Options for drawing a rectangle.
|
|
374
|
+
*/
|
|
375
|
+
export type RectOptions = {
|
|
376
|
+
x: number;
|
|
377
|
+
y: number;
|
|
378
|
+
width: number;
|
|
379
|
+
height: number;
|
|
380
|
+
color: ColorInput;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Creates a node that draws a rectangle.
|
|
384
|
+
*/
|
|
385
|
+
export declare function createRectNode(options: RectOptions): ImageNode;
|
|
386
|
+
/**
|
|
387
|
+
* Options for drawing a circle.
|
|
388
|
+
*/
|
|
389
|
+
export type CircleOptions = {
|
|
390
|
+
cx: number;
|
|
391
|
+
cy: number;
|
|
392
|
+
radius: number;
|
|
393
|
+
color: ColorInput;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Creates a node that draws a circle.
|
|
397
|
+
*/
|
|
398
|
+
export declare function createCircleNode(options: CircleOptions): ImageNode;
|
|
399
|
+
/**
|
|
400
|
+
* Creates a node that maps colors to the nearest palette entry.
|
|
401
|
+
*/
|
|
402
|
+
export declare function createPaletteMapNode(palette: ColorInput[]): ImageNode;
|
|
403
|
+
/**
|
|
404
|
+
* Builds a normalized box kernel.
|
|
405
|
+
*/
|
|
406
|
+
export declare function buildBoxKernel(size: number): number[][];
|
|
407
|
+
/**
|
|
408
|
+
* Builds a Gaussian kernel with the given size and sigma.
|
|
409
|
+
*/
|
|
410
|
+
export declare function buildGaussianKernel(size: number, sigma?: number): number[][];
|
|
411
|
+
/**
|
|
412
|
+
* Creates a Gaussian blur node.
|
|
413
|
+
*/
|
|
414
|
+
export declare function createGaussianBlurNode(size?: number, sigma?: number): ImageNode;
|
|
415
|
+
/**
|
|
416
|
+
* Creates a sharpening node.
|
|
417
|
+
*/
|
|
418
|
+
export declare function createSharpenNode(): ImageNode;
|
|
419
|
+
/**
|
|
420
|
+
* Creates an edge detection node.
|
|
421
|
+
*/
|
|
422
|
+
export declare function createEdgeDetectNode(): ImageNode;
|
|
423
|
+
/**
|
|
424
|
+
* Creates a node that resizes the image to the target dimensions.
|
|
425
|
+
*/
|
|
426
|
+
export declare function createResizeNode(width: number, height: number, options?: ResizeOptions): ImageNode;
|
|
427
|
+
/**
|
|
428
|
+
* Creates a node that renders text onto an image.
|
|
429
|
+
*/
|
|
430
|
+
export declare function createTextNode(options: TextOptions): ImageNode<TextOptions>;
|
|
431
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ImageBuffer } from './image';
|
|
2
|
+
import { ImageSource } from './types';
|
|
3
|
+
import { SeededRandom } from './random';
|
|
4
|
+
import { ImageNode, NodeState } from './nodes';
|
|
5
|
+
/**
|
|
6
|
+
* Options for running a pipeline.
|
|
7
|
+
*/
|
|
8
|
+
export type PipelineOptions = {
|
|
9
|
+
seed?: number | string;
|
|
10
|
+
random?: SeededRandom;
|
|
11
|
+
data?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Supported inputs for running a pipeline.
|
|
15
|
+
*/
|
|
16
|
+
export type PipelineInput = ImageSource | ImageBuffer | NodeState;
|
|
17
|
+
/**
|
|
18
|
+
* Sequential pipeline that runs image nodes in order.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Pipeline {
|
|
21
|
+
private nodes;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new pipeline with optional initial nodes.
|
|
24
|
+
*/
|
|
25
|
+
constructor(nodes?: ImageNode[]);
|
|
26
|
+
/**
|
|
27
|
+
* Appends nodes to the pipeline.
|
|
28
|
+
*/
|
|
29
|
+
add(...nodes: ImageNode[]): this;
|
|
30
|
+
/**
|
|
31
|
+
* Executes the pipeline against an input source or buffer.
|
|
32
|
+
*/
|
|
33
|
+
run(input: PipelineInput, options?: PipelineOptions): Promise<ImageBuffer>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes the pipeline and returns the full node state.
|
|
36
|
+
*/
|
|
37
|
+
runState(input: PipelineInput, options?: PipelineOptions): Promise<NodeState>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a small example pipeline for quick sanity checks.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createExamplePipeline(): Pipeline;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a pipeline with the provided nodes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pipeline(...nodes: ImageNode[]): Pipeline;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic RNG powered by a 32-bit seed.
|
|
3
|
+
*/
|
|
4
|
+
export declare class SeededRandom {
|
|
5
|
+
private state;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new RNG with a specific seed.
|
|
8
|
+
*/
|
|
9
|
+
constructor(seed: number);
|
|
10
|
+
/**
|
|
11
|
+
* Returns a float in the range [0, 1).
|
|
12
|
+
*/
|
|
13
|
+
next(): number;
|
|
14
|
+
/**
|
|
15
|
+
* Alias of next() for semantic clarity.
|
|
16
|
+
*/
|
|
17
|
+
nextFloat(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Returns an integer in the inclusive range [min, max].
|
|
20
|
+
*/
|
|
21
|
+
nextInt(min: number, max: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a float in the range [min, max).
|
|
24
|
+
*/
|
|
25
|
+
nextRange(min: number, max: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a normally distributed random number.
|
|
28
|
+
*/
|
|
29
|
+
nextGaussian(mean?: number, stdDev?: number): number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a seeded RNG from a number or string seed.
|
|
33
|
+
* When omitted, the seed is derived from current time.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createRandom(seed?: number | string): SeededRandom;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ImageBuffer } from './image';
|
|
2
|
+
import { ColorInput } from './color';
|
|
3
|
+
import { ImageSource, PixelLike, PixelFormat } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an ImageSource from a local file path.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sourceFromPath(path: string): ImageSource;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an ImageSource from a remote URL.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sourceFromUrl(url: string): ImageSource;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an ImageSource from a data URI.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sourceFromDataUri(dataUri: string): ImageSource;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an ImageSource from a raw image buffer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sourceFromBuffer(buffer: Buffer): ImageSource;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an empty ImageSource with optional fill color.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sourceFromEmpty(width: number, height: number, format?: PixelFormat, fill?: PixelLike): ImageSource;
|
|
24
|
+
/**
|
|
25
|
+
* Loads an image source into an ImageBuffer.
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadImage(source: ImageSource): Promise<ImageBuffer>;
|
|
28
|
+
/**
|
|
29
|
+
* Output encoding options for image serialization.
|
|
30
|
+
*/
|
|
31
|
+
export type SaveImageOptions = {
|
|
32
|
+
format?: 'png' | 'jpeg' | 'webp';
|
|
33
|
+
quality?: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Resize options for image buffers.
|
|
37
|
+
*/
|
|
38
|
+
export type ResizeOptions = {
|
|
39
|
+
fit?: 'contain' | 'cover' | 'fill' | 'inside' | 'outside';
|
|
40
|
+
withoutEnlargement?: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Text font source configuration.
|
|
44
|
+
*/
|
|
45
|
+
export type TextFontSource = {
|
|
46
|
+
filePath?: string;
|
|
47
|
+
data?: Buffer;
|
|
48
|
+
mime?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Text font configuration.
|
|
52
|
+
*/
|
|
53
|
+
export type TextFont = {
|
|
54
|
+
family: string;
|
|
55
|
+
source?: TextFontSource;
|
|
56
|
+
weight?: number | string;
|
|
57
|
+
style?: 'normal' | 'italic' | 'oblique';
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Text layout options.
|
|
61
|
+
*/
|
|
62
|
+
export type TextLayout = {
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
maxWidth?: number;
|
|
66
|
+
maxLines?: number;
|
|
67
|
+
align?: 'left' | 'center' | 'right';
|
|
68
|
+
lineHeight?: number;
|
|
69
|
+
letterSpacing?: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Text style options.
|
|
73
|
+
*/
|
|
74
|
+
export type TextStyle = {
|
|
75
|
+
fontSize?: number;
|
|
76
|
+
color?: ColorInput;
|
|
77
|
+
bold?: boolean;
|
|
78
|
+
italic?: boolean;
|
|
79
|
+
underline?: boolean;
|
|
80
|
+
strikethrough?: boolean;
|
|
81
|
+
opacity?: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Text rendering options.
|
|
85
|
+
*/
|
|
86
|
+
export type TextOptions = {
|
|
87
|
+
text: string;
|
|
88
|
+
font: TextFont;
|
|
89
|
+
layout: TextLayout;
|
|
90
|
+
style?: TextStyle;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Serializes an ImageBuffer to an encoded image buffer.
|
|
94
|
+
*/
|
|
95
|
+
export declare function imageToBuffer(image: ImageBuffer, options?: SaveImageOptions): Promise<Buffer>;
|
|
96
|
+
/**
|
|
97
|
+
* Saves an ImageBuffer to a local file.
|
|
98
|
+
*/
|
|
99
|
+
export declare function saveImage(image: ImageBuffer, outputPath: string, options?: SaveImageOptions): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Resizes an ImageBuffer and returns a new buffer.
|
|
102
|
+
*/
|
|
103
|
+
export declare function resizeImage(image: ImageBuffer, width: number, height: number, options?: ResizeOptions): Promise<ImageBuffer>;
|
|
104
|
+
/**
|
|
105
|
+
* Renders text onto an ImageBuffer.
|
|
106
|
+
*/
|
|
107
|
+
export declare function renderText(image: ImageBuffer, options: TextOptions): Promise<ImageBuffer>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pixel storage format for an ImageBuffer.
|
|
3
|
+
* - rgba8/rgb8/gray8 use 0-255 integer channels.
|
|
4
|
+
* - rgba32f uses 0-1 floating point channels.
|
|
5
|
+
*/
|
|
6
|
+
export type PixelFormat = 'rgba8' | 'rgb8' | 'gray8' | 'rgba32f';
|
|
7
|
+
/**
|
|
8
|
+
* Fully expanded pixel with RGBA channels in 0-255 space.
|
|
9
|
+
*/
|
|
10
|
+
export type Pixel = {
|
|
11
|
+
r: number;
|
|
12
|
+
g: number;
|
|
13
|
+
b: number;
|
|
14
|
+
a: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Pixel-like input that can omit alpha (defaults to 255).
|
|
18
|
+
*/
|
|
19
|
+
export type PixelLike = {
|
|
20
|
+
r: number;
|
|
21
|
+
g: number;
|
|
22
|
+
b: number;
|
|
23
|
+
a?: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Supported image inputs for pipelines.
|
|
27
|
+
*/
|
|
28
|
+
export type ImageSource = {
|
|
29
|
+
type: 'path';
|
|
30
|
+
path: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'url';
|
|
33
|
+
url: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'datauri';
|
|
36
|
+
dataUri: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'buffer';
|
|
39
|
+
buffer: Buffer;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'empty';
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
format?: PixelFormat;
|
|
45
|
+
fill?: PixelLike;
|
|
46
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { ColorInput, HslColor, HslaColor, HsvColor, HsvaColor, RgbColor, RgbaColor, } from './core/color';
|
|
2
|
+
export { colorDistance, hexToRgba, hslaToRgba, hsvaToRgba, rgbaToHex, rgbaToHsla, rgbaToHsva, toRgba, } from './core/color';
|
|
3
|
+
export type { Pixel, PixelFormat, PixelLike, ImageSource } from './core/types';
|
|
4
|
+
export { ImageBuffer } from './core/image';
|
|
5
|
+
export { SeededRandom, createRandom } from './core/random';
|
|
6
|
+
export type { ResizeOptions, SaveImageOptions, TextFont, TextFontSource, TextLayout, TextOptions, TextStyle, } from './core/sources';
|
|
7
|
+
export { imageToBuffer, loadImage, renderText, resizeImage, saveImage, sourceFromBuffer, sourceFromDataUri, sourceFromEmpty, sourceFromPath, sourceFromUrl, } from './core/sources';
|
|
8
|
+
export type { CircleSelectorOptions, ImageInput, ImageNode, ImageNodeOptions, MaskMapEntry, MaskMapOptions, MaskMapSource, NodeDefinition, NodeContext, NodeResult, NodeState, ParametricNode, PixelMatrix, PixelNodeInfo, PixelNodeRunner, PixelSelector, FractalNoiseOptions, PerlinNoiseOptions, RectSelectorOptions, SelectionMode, SelectionOptions, SimpleNodeDefinition, ValueNoiseOptions, RidgedNoiseOptions, TurbulenceNoiseOptions, VoronoiNoiseOptions, } from './core/nodes';
|
|
9
|
+
export { DEFAULT_IMAGE_KEY, createBrightnessNode, createCircleSelector, createCheckerboardNode, createCircleNode, createConvolutionNode, createContrastNode, createAlphaSelector, createEdgeDetectNode, createFillNode, createGammaNode, createGaussianBlurNode, createGaussianNoiseNode, createGrayscaleNode, createInvertNode, createImageNode, createPixelNode, createLumaSelector, createMapNode, createMaskMapNode, createMaskedNode, createNoiseNode, createFractalNoiseNode, createPerlinNoiseNode, createRidgedNoiseNode, createTurbulenceNoiseNode, createValueNoiseNode, createVoronoiNoiseNode, createPaletteMapNode, createParamNode, createRandomFillNode, createRectSelector, createResizeNode, createSelectionCropNode, createRectNode, createSaltPepperNoiseNode, createSharpenNode, createThresholdNode, createTextNode, defineNode, getImage, mergeNodeState, node, runNode, runNodeImage, buildBoxKernel, buildGaussianKernel, } from './core/nodes';
|
|
10
|
+
export type { PipelineInput, PipelineOptions } from './core/pipeline';
|
|
11
|
+
export { Pipeline, createExamplePipeline, pipeline } from './core/pipeline';
|