@shotstack/shotstack-canvas 1.0.2 → 1.0.3

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.
@@ -0,0 +1,229 @@
1
+ declare const CANVAS_CONFIG: {
2
+ DEFAULTS: {
3
+ width: number;
4
+ height: number;
5
+ pixelRatio: number;
6
+ fontFamily: string;
7
+ fontSize: number;
8
+ color: string;
9
+ textAlign: "left";
10
+ };
11
+ LIMITS: {
12
+ minWidth: number;
13
+ maxWidth: number;
14
+ minHeight: number;
15
+ maxHeight: number;
16
+ minFontSize: number;
17
+ maxFontSize: number;
18
+ minDuration: number;
19
+ maxDuration: number;
20
+ maxTextLength: number;
21
+ };
22
+ ANIMATION_TYPES: readonly ["typewriter", "fadeIn", "slideIn", "shift", "ascend", "movingLetters"];
23
+ };
24
+
25
+ type RichTextValidated = Required<{
26
+ type: "rich-text";
27
+ text: string;
28
+ width?: number;
29
+ height?: number;
30
+ font?: {
31
+ family: string;
32
+ size: number;
33
+ weight: string | number;
34
+ style: "normal" | "italic" | "oblique";
35
+ color: string;
36
+ opacity: number;
37
+ };
38
+ style?: {
39
+ letterSpacing: number;
40
+ lineHeight: number;
41
+ textTransform: "none" | "uppercase" | "lowercase" | "capitalize";
42
+ textDecoration: "none" | "underline" | "line-through";
43
+ gradient?: {
44
+ type: "linear" | "radial";
45
+ angle: number;
46
+ stops: {
47
+ offset: number;
48
+ color: string;
49
+ }[];
50
+ };
51
+ };
52
+ stroke?: {
53
+ width: number;
54
+ color: string;
55
+ opacity: number;
56
+ };
57
+ shadow?: {
58
+ offsetX: number;
59
+ offsetY: number;
60
+ blur: number;
61
+ color: string;
62
+ opacity: number;
63
+ };
64
+ background?: {
65
+ color?: string;
66
+ opacity: number;
67
+ borderRadius: number;
68
+ };
69
+ align?: {
70
+ horizontal: "left" | "center" | "right";
71
+ vertical: "top" | "middle" | "bottom";
72
+ };
73
+ animation?: {
74
+ preset: typeof CANVAS_CONFIG.ANIMATION_TYPES[number];
75
+ speed: number;
76
+ duration?: number;
77
+ style?: "character" | "word";
78
+ direction?: "left" | "right" | "up" | "down";
79
+ };
80
+ customFonts?: {
81
+ src: string;
82
+ family: string;
83
+ weight?: string | number;
84
+ style?: string;
85
+ originalFamily?: string;
86
+ }[];
87
+ cacheEnabled: boolean;
88
+ pixelRatio: number;
89
+ }>;
90
+
91
+ type RGBA = {
92
+ r: number;
93
+ g: number;
94
+ b: number;
95
+ a: number;
96
+ };
97
+ type GradientSpec = {
98
+ kind: "solid";
99
+ color: string;
100
+ opacity: number;
101
+ } | {
102
+ kind: "linear";
103
+ angle: number;
104
+ stops: {
105
+ offset: number;
106
+ color: string;
107
+ }[];
108
+ opacity: number;
109
+ } | {
110
+ kind: "radial";
111
+ stops: {
112
+ offset: number;
113
+ color: string;
114
+ }[];
115
+ opacity: number;
116
+ };
117
+ type Glyph = {
118
+ id: number;
119
+ xAdvance: number;
120
+ xOffset: number;
121
+ yOffset: number;
122
+ cluster: number;
123
+ char?: string;
124
+ };
125
+ type ShapedLine = {
126
+ glyphs: Glyph[];
127
+ width: number;
128
+ y: number;
129
+ };
130
+ type DrawOp = {
131
+ op: "BeginFrame";
132
+ width: number;
133
+ height: number;
134
+ pixelRatio: number;
135
+ clear: boolean;
136
+ bg?: {
137
+ color?: string;
138
+ opacity: number;
139
+ radius: number;
140
+ };
141
+ } | {
142
+ op: "FillPath";
143
+ path: string;
144
+ x: number;
145
+ y: number;
146
+ fill: GradientSpec;
147
+ } | {
148
+ op: "StrokePath";
149
+ path: string;
150
+ x: number;
151
+ y: number;
152
+ width: number;
153
+ color: string;
154
+ opacity: number;
155
+ } | {
156
+ op: "DecorationLine";
157
+ from: {
158
+ x: number;
159
+ y: number;
160
+ };
161
+ to: {
162
+ x: number;
163
+ y: number;
164
+ };
165
+ width: number;
166
+ color: string;
167
+ opacity: number;
168
+ };
169
+ type EngineInit = {
170
+ width: number;
171
+ height: number;
172
+ pixelRatio?: number;
173
+ fps?: number;
174
+ };
175
+ type Renderer = {
176
+ render(ops: DrawOp[]): Promise<void>;
177
+ toPNG?: () => Promise<Buffer>;
178
+ };
179
+ type ValidAsset = RichTextValidated;
180
+
181
+ interface VideoGenerationOptions {
182
+ width: number;
183
+ height: number;
184
+ fps: number;
185
+ duration: number;
186
+ outputPath: string;
187
+ pixelRatio?: number;
188
+ /** Optional quality controls (sane defaults provided) */
189
+ crf?: number;
190
+ preset?: "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow";
191
+ tune?: "film" | "animation" | "grain" | "stillimage" | "psnr" | "ssim" | "fastdecode" | "zerolatency";
192
+ profile?: "baseline" | "main" | "high";
193
+ level?: string;
194
+ pixFmt?: string;
195
+ }
196
+
197
+ declare function createTextEngine(opts?: {
198
+ width?: number;
199
+ height?: number;
200
+ pixelRatio?: number;
201
+ fps?: number;
202
+ wasmBaseURL?: string;
203
+ }): Promise<{
204
+ validate(input: unknown): {
205
+ value: RichTextValidated;
206
+ };
207
+ registerFontFromFile(path: string, desc: {
208
+ family: string;
209
+ weight?: string | number;
210
+ style?: string;
211
+ }): Promise<void>;
212
+ registerFontFromUrl(url: string, desc: {
213
+ family: string;
214
+ weight?: string | number;
215
+ style?: string;
216
+ }): Promise<void>;
217
+ renderFrame(asset: RichTextValidated, tSeconds: number): Promise<DrawOp[]>;
218
+ createRenderer(p: {
219
+ width?: number;
220
+ height?: number;
221
+ pixelRatio?: number;
222
+ }): Promise<{
223
+ render(ops: DrawOp[]): Promise<void>;
224
+ toPNG(): Promise<Buffer>;
225
+ }>;
226
+ generateVideo(asset: RichTextValidated, options: Partial<VideoGenerationOptions>): Promise<void>;
227
+ }>;
228
+
229
+ export { type DrawOp, type EngineInit, type Glyph, type GradientSpec, type RGBA, type Renderer, type ShapedLine, type ValidAsset, createTextEngine };