@uploadista/core 0.0.11 → 0.0.12
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/dist/flow/index.cjs +1 -1
- package/dist/flow/index.d.cts +2 -2
- package/dist/flow/index.d.mts +2 -2
- package/dist/flow/index.mjs +1 -1
- package/dist/{flow-DEohelFR.mjs → flow-CpDQ8dgf.mjs} +2 -2
- package/dist/flow-CpDQ8dgf.mjs.map +1 -0
- package/dist/{flow-C_doYlGf.cjs → flow-wZzF8vml.cjs} +1 -1
- package/dist/{index-DyUMSQeo.d.cts → index-DHOYyzYt.d.cts} +372 -6
- package/dist/index-DHOYyzYt.d.cts.map +1 -0
- package/dist/{index-CDzzqysG.d.mts → index-DdT18SQi.d.mts} +372 -6
- package/dist/index-DdT18SQi.d.mts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/upload/index.d.cts +1 -1
- package/dist/upload/index.d.mts +1 -1
- package/package.json +3 -3
- package/src/flow/plugins/image-plugin.ts +40 -0
- package/src/flow/plugins/types/index.ts +1 -0
- package/src/flow/plugins/types/transform-image-node.ts +283 -0
- package/dist/flow-DEohelFR.mjs.map +0 -1
- package/dist/index-CDzzqysG.d.mts.map +0 -1
- package/dist/index-DyUMSQeo.d.cts.map +0 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type of transformation to apply to an image.
|
|
5
|
+
*/
|
|
6
|
+
export type TransformationType =
|
|
7
|
+
| "resize"
|
|
8
|
+
| "blur"
|
|
9
|
+
| "rotate"
|
|
10
|
+
| "flip"
|
|
11
|
+
| "grayscale"
|
|
12
|
+
| "sepia"
|
|
13
|
+
| "brightness"
|
|
14
|
+
| "contrast"
|
|
15
|
+
| "sharpen"
|
|
16
|
+
| "watermark"
|
|
17
|
+
| "logo"
|
|
18
|
+
| "text";
|
|
19
|
+
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// Basic Transformations
|
|
22
|
+
// ============================================================================
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resize transformation parameters.
|
|
26
|
+
* Resizes the image to the specified dimensions with the given fit mode.
|
|
27
|
+
*/
|
|
28
|
+
export const resizeTransformSchema = z.object({
|
|
29
|
+
type: z.literal("resize"),
|
|
30
|
+
/** Target width in pixels (optional) */
|
|
31
|
+
width: z.number().positive().optional(),
|
|
32
|
+
/** Target height in pixels (optional) */
|
|
33
|
+
height: z.number().positive().optional(),
|
|
34
|
+
/** How the image should fit within the specified dimensions */
|
|
35
|
+
fit: z.enum(["contain", "cover", "fill"]),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type ResizeTransform = z.infer<typeof resizeTransformSchema>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Blur transformation parameters.
|
|
42
|
+
* Applies Gaussian blur to the image.
|
|
43
|
+
*/
|
|
44
|
+
export const blurTransformSchema = z.object({
|
|
45
|
+
type: z.literal("blur"),
|
|
46
|
+
/** Blur strength (sigma). Range: 0.3 to 1000 */
|
|
47
|
+
sigma: z.number().min(0.3).max(1000),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export type BlurTransform = z.infer<typeof blurTransformSchema>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Rotate transformation parameters.
|
|
54
|
+
* Rotates the image by the specified angle.
|
|
55
|
+
*/
|
|
56
|
+
export const rotateTransformSchema = z.object({
|
|
57
|
+
type: z.literal("rotate"),
|
|
58
|
+
/** Rotation angle in degrees. Positive values rotate clockwise. */
|
|
59
|
+
angle: z.number(),
|
|
60
|
+
/** Background color for exposed areas (optional, defaults to transparent) */
|
|
61
|
+
background: z.string().optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export type RotateTransform = z.infer<typeof rotateTransformSchema>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Flip transformation parameters.
|
|
68
|
+
* Flips the image horizontally or vertically.
|
|
69
|
+
*/
|
|
70
|
+
export const flipTransformSchema = z.object({
|
|
71
|
+
type: z.literal("flip"),
|
|
72
|
+
/** Direction to flip the image */
|
|
73
|
+
direction: z.enum(["horizontal", "vertical"]),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export type FlipTransform = z.infer<typeof flipTransformSchema>;
|
|
77
|
+
|
|
78
|
+
// ============================================================================
|
|
79
|
+
// Filter Transformations
|
|
80
|
+
// ============================================================================
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Grayscale transformation parameters.
|
|
84
|
+
* Converts the image to grayscale.
|
|
85
|
+
*/
|
|
86
|
+
export const grayscaleTransformSchema = z.object({
|
|
87
|
+
type: z.literal("grayscale"),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export type GrayscaleTransform = z.infer<typeof grayscaleTransformSchema>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sepia transformation parameters.
|
|
94
|
+
* Applies a sepia tone effect to the image.
|
|
95
|
+
*/
|
|
96
|
+
export const sepiaTransformSchema = z.object({
|
|
97
|
+
type: z.literal("sepia"),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export type SepiaTransform = z.infer<typeof sepiaTransformSchema>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Brightness transformation parameters.
|
|
104
|
+
* Adjusts the brightness of the image.
|
|
105
|
+
*/
|
|
106
|
+
export const brightnessTransformSchema = z.object({
|
|
107
|
+
type: z.literal("brightness"),
|
|
108
|
+
/** Brightness adjustment value. Range: -100 to +100. 0 = no change. */
|
|
109
|
+
value: z.number().min(-100).max(100),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export type BrightnessTransform = z.infer<typeof brightnessTransformSchema>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Contrast transformation parameters.
|
|
116
|
+
* Adjusts the contrast of the image.
|
|
117
|
+
*/
|
|
118
|
+
export const contrastTransformSchema = z.object({
|
|
119
|
+
type: z.literal("contrast"),
|
|
120
|
+
/** Contrast adjustment value. Range: -100 to +100. 0 = no change. */
|
|
121
|
+
value: z.number().min(-100).max(100),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export type ContrastTransform = z.infer<typeof contrastTransformSchema>;
|
|
125
|
+
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Effect Transformations
|
|
128
|
+
// ============================================================================
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Sharpen transformation parameters.
|
|
132
|
+
* Applies sharpening to the image.
|
|
133
|
+
*/
|
|
134
|
+
export const sharpenTransformSchema = z.object({
|
|
135
|
+
type: z.literal("sharpen"),
|
|
136
|
+
/** Sharpening strength (sigma). Optional, uses default if not specified. */
|
|
137
|
+
sigma: z.number().positive().optional(),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export type SharpenTransform = z.infer<typeof sharpenTransformSchema>;
|
|
141
|
+
|
|
142
|
+
// ============================================================================
|
|
143
|
+
// Advanced Transformations
|
|
144
|
+
// ============================================================================
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Position for overlays (watermarks, logos, text).
|
|
148
|
+
*/
|
|
149
|
+
export type OverlayPosition =
|
|
150
|
+
| "top-left"
|
|
151
|
+
| "top-right"
|
|
152
|
+
| "bottom-left"
|
|
153
|
+
| "bottom-right"
|
|
154
|
+
| "center";
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Watermark transformation parameters.
|
|
158
|
+
* Overlays a watermark image on the main image.
|
|
159
|
+
*/
|
|
160
|
+
export const watermarkTransformSchema = z.object({
|
|
161
|
+
type: z.literal("watermark"),
|
|
162
|
+
/** URL to the watermark image file (e.g., https://example.com/watermark.png) */
|
|
163
|
+
imagePath: z.string().min(1).url(),
|
|
164
|
+
/** Position of the watermark on the image */
|
|
165
|
+
position: z.enum([
|
|
166
|
+
"top-left",
|
|
167
|
+
"top-right",
|
|
168
|
+
"bottom-left",
|
|
169
|
+
"bottom-right",
|
|
170
|
+
"center",
|
|
171
|
+
]),
|
|
172
|
+
/** Opacity of the watermark. Range: 0 (transparent) to 1 (opaque) */
|
|
173
|
+
opacity: z.number().min(0).max(1),
|
|
174
|
+
/** Horizontal offset in pixels from the position anchor (optional) */
|
|
175
|
+
offsetX: z.number().optional(),
|
|
176
|
+
/** Vertical offset in pixels from the position anchor (optional) */
|
|
177
|
+
offsetY: z.number().optional(),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
export type WatermarkTransform = z.infer<typeof watermarkTransformSchema>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Logo transformation parameters.
|
|
184
|
+
* Overlays a logo image on the main image with scaling.
|
|
185
|
+
*/
|
|
186
|
+
export const logoTransformSchema = z.object({
|
|
187
|
+
type: z.literal("logo"),
|
|
188
|
+
/** URL to the logo image file (e.g., https://example.com/logo.png) */
|
|
189
|
+
imagePath: z.string().min(1).url(),
|
|
190
|
+
/** Position of the logo on the image */
|
|
191
|
+
position: z.enum([
|
|
192
|
+
"top-left",
|
|
193
|
+
"top-right",
|
|
194
|
+
"bottom-left",
|
|
195
|
+
"bottom-right",
|
|
196
|
+
"center",
|
|
197
|
+
]),
|
|
198
|
+
/** Scale factor for the logo. Range: 0.1 to 2.0 */
|
|
199
|
+
scale: z.number().min(0.1).max(2.0),
|
|
200
|
+
/** Horizontal offset in pixels from the position anchor (optional) */
|
|
201
|
+
offsetX: z.number().optional(),
|
|
202
|
+
/** Vertical offset in pixels from the position anchor (optional) */
|
|
203
|
+
offsetY: z.number().optional(),
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
export type LogoTransform = z.infer<typeof logoTransformSchema>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Text transformation parameters.
|
|
210
|
+
* Overlays text on the image.
|
|
211
|
+
*/
|
|
212
|
+
export const textTransformSchema = z.object({
|
|
213
|
+
type: z.literal("text"),
|
|
214
|
+
/** Text content to overlay */
|
|
215
|
+
text: z.string().min(1),
|
|
216
|
+
/** Position of the text on the image */
|
|
217
|
+
position: z.enum([
|
|
218
|
+
"top-left",
|
|
219
|
+
"top-right",
|
|
220
|
+
"bottom-left",
|
|
221
|
+
"bottom-right",
|
|
222
|
+
"center",
|
|
223
|
+
]),
|
|
224
|
+
/** Font size in pixels */
|
|
225
|
+
fontSize: z.number().positive(),
|
|
226
|
+
/** Text color (hex code or named color) */
|
|
227
|
+
color: z.string().min(1),
|
|
228
|
+
/** Font family name (optional) */
|
|
229
|
+
fontFamily: z.string().optional(),
|
|
230
|
+
/** Horizontal offset in pixels from the position anchor (optional) */
|
|
231
|
+
offsetX: z.number().optional(),
|
|
232
|
+
/** Vertical offset in pixels from the position anchor (optional) */
|
|
233
|
+
offsetY: z.number().optional(),
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
export type TextTransform = z.infer<typeof textTransformSchema>;
|
|
237
|
+
|
|
238
|
+
// ============================================================================
|
|
239
|
+
// Discriminated Union
|
|
240
|
+
// ============================================================================
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Schema for validating any transformation type.
|
|
244
|
+
* This is a discriminated union of all transformation schemas.
|
|
245
|
+
*/
|
|
246
|
+
export const transformationSchema = z.discriminatedUnion("type", [
|
|
247
|
+
resizeTransformSchema,
|
|
248
|
+
blurTransformSchema,
|
|
249
|
+
rotateTransformSchema,
|
|
250
|
+
flipTransformSchema,
|
|
251
|
+
grayscaleTransformSchema,
|
|
252
|
+
sepiaTransformSchema,
|
|
253
|
+
brightnessTransformSchema,
|
|
254
|
+
contrastTransformSchema,
|
|
255
|
+
sharpenTransformSchema,
|
|
256
|
+
watermarkTransformSchema,
|
|
257
|
+
logoTransformSchema,
|
|
258
|
+
textTransformSchema,
|
|
259
|
+
]);
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A single image transformation operation.
|
|
263
|
+
* This is a discriminated union type that can represent any transformation.
|
|
264
|
+
*/
|
|
265
|
+
export type Transformation = z.infer<typeof transformationSchema>;
|
|
266
|
+
|
|
267
|
+
// ============================================================================
|
|
268
|
+
// Transform Image Node Parameters
|
|
269
|
+
// ============================================================================
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Parameters for the transform image node.
|
|
273
|
+
* Contains an ordered array of transformations to apply sequentially.
|
|
274
|
+
*/
|
|
275
|
+
export const transformImageParamsSchema = z.object({
|
|
276
|
+
/** Ordered array of transformations to apply. Applied sequentially. */
|
|
277
|
+
transformations: z.array(transformationSchema).min(1),
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Parameters for the transform image node.
|
|
282
|
+
*/
|
|
283
|
+
export type TransformImageParams = z.infer<typeof transformImageParamsSchema>;
|