@canva/intents 2.0.2-beta.3 → 2.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/CHANGELOG.md +15 -0
- package/asset/index.d.ts +1 -1
- package/content/index.d.ts +1440 -1
- package/data/index.d.ts +1229 -1
- package/design/index.d.ts +41 -1
- package/index.d.ts +2821 -1
- package/lib/cjs/sdk/intents/asset/index.js +1 -15
- package/lib/cjs/sdk/intents/content/index.js +4 -2
- package/lib/cjs/sdk/intents/content/{beta.js → public.js} +0 -2
- package/lib/cjs/sdk/intents/fake/create.js +3 -0
- package/lib/cjs/sdk/intents/index.js +4 -2
- package/lib/cjs/sdk/intents/public.js +8 -4
- package/lib/cjs/sdk/intents/version.js +17 -4
- package/lib/esm/sdk/intents/asset/index.js +1 -1
- package/lib/esm/sdk/intents/content/index.js +3 -1
- package/lib/esm/sdk/intents/content/public.js +2 -0
- package/lib/esm/sdk/intents/fake/create.js +3 -0
- package/lib/esm/sdk/intents/index.js +3 -1
- package/lib/esm/sdk/intents/public.js +2 -1
- package/lib/esm/sdk/intents/version.js +3 -1
- package/package.json +23 -23
- package/test/index.d.ts +11 -1
- package/asset/beta.d.ts +0 -236
- package/beta.d.ts +0 -1309
- package/content/beta.d.ts +0 -1410
- package/data/beta.d.ts +0 -1242
- package/design/beta.d.ts +0 -43
- package/lib/cjs/sdk/intents/asset/beta.js +0 -14
- package/lib/cjs/sdk/intents/beta.js +0 -20
- package/lib/cjs/sdk/intents/data/beta.js +0 -20
- package/lib/cjs/sdk/intents/design/beta.js +0 -20
- package/lib/cjs/sdk/intents/test/beta.js +0 -18
- package/lib/esm/sdk/intents/asset/beta.js +0 -4
- package/lib/esm/sdk/intents/beta.js +0 -3
- package/lib/esm/sdk/intents/content/beta.js +0 -4
- package/lib/esm/sdk/intents/data/beta.js +0 -3
- package/lib/esm/sdk/intents/design/beta.js +0 -3
- package/lib/esm/sdk/intents/test/beta.js +0 -1
- package/test/beta.d.ts +0 -11
package/content/beta.d.ts
DELETED
|
@@ -1,1410 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @beta
|
|
3
|
-
* {@link PublishContentError} indicating a custom error occurred in your app's implementation.
|
|
4
|
-
*
|
|
5
|
-
* Return this for application-specific errors such as:
|
|
6
|
-
*
|
|
7
|
-
* - Validation failures
|
|
8
|
-
* - Authentication errors
|
|
9
|
-
* - Rate limiting
|
|
10
|
-
* - Platform-specific restrictions
|
|
11
|
-
*
|
|
12
|
-
* @example Returning custom error with message
|
|
13
|
-
* ```ts
|
|
14
|
-
* if (userQuotaExceeded) {
|
|
15
|
-
* return {
|
|
16
|
-
* status: 'app_error',
|
|
17
|
-
* message: 'You have reached your monthly publish limit. Please upgrade your plan.'
|
|
18
|
-
* };
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare type AppError = {
|
|
23
|
-
status: "app_error";
|
|
24
|
-
/**
|
|
25
|
-
* User-friendly message explaining the error.
|
|
26
|
-
*/
|
|
27
|
-
message?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @beta
|
|
32
|
-
* Base file requirement interface.
|
|
33
|
-
*/
|
|
34
|
-
declare interface BaseFileRequirement {
|
|
35
|
-
/**
|
|
36
|
-
* File format for this requirement.
|
|
37
|
-
*/
|
|
38
|
-
format: PublishFileFormat;
|
|
39
|
-
/**
|
|
40
|
-
* Maximum file size in megabytes.
|
|
41
|
-
*
|
|
42
|
-
* Example: `10` for 10 MB maximum
|
|
43
|
-
*/
|
|
44
|
-
maxFileSizeMb?: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @beta
|
|
49
|
-
* Base interface for exported files.
|
|
50
|
-
*/
|
|
51
|
-
export declare interface BaseOutputFile {
|
|
52
|
-
/**
|
|
53
|
-
* File format.
|
|
54
|
-
*/
|
|
55
|
-
format: PublishFileFormat;
|
|
56
|
-
/**
|
|
57
|
-
* URL to download the exported file.
|
|
58
|
-
*
|
|
59
|
-
* Your app should download from this URL and upload to your platform.
|
|
60
|
-
*/
|
|
61
|
-
url: string;
|
|
62
|
-
/**
|
|
63
|
-
* Metadata about the source content used to create this exported file.
|
|
64
|
-
*/
|
|
65
|
-
contentMetadata: ContentMetadata;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @beta
|
|
70
|
-
* Base interface for all preview types.
|
|
71
|
-
*
|
|
72
|
-
* Contains common properties shared by image and video previews.
|
|
73
|
-
*/
|
|
74
|
-
export declare interface BasePreview {
|
|
75
|
-
/**
|
|
76
|
-
* Unique identifier for this preview.
|
|
77
|
-
*
|
|
78
|
-
* Use this ID with `requestPreviewUpgrade` to upgrade video thumbnails.
|
|
79
|
-
*/
|
|
80
|
-
id: string;
|
|
81
|
-
/**
|
|
82
|
-
* Type of media in this preview.
|
|
83
|
-
*/
|
|
84
|
-
kind: PreviewKind;
|
|
85
|
-
/**
|
|
86
|
-
* Current state of the preview.
|
|
87
|
-
*/
|
|
88
|
-
status: PreviewStatus;
|
|
89
|
-
/**
|
|
90
|
-
* Width of the preview in pixels.
|
|
91
|
-
*/
|
|
92
|
-
widthPx: number;
|
|
93
|
-
/**
|
|
94
|
-
* Height of the preview in pixels.
|
|
95
|
-
*/
|
|
96
|
-
heightPx: number;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @beta
|
|
101
|
-
* Metadata about the source content used to create an exported file.
|
|
102
|
-
*/
|
|
103
|
-
export declare type ContentMetadata = DesignContentMetadata;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @beta
|
|
107
|
-
* Main interface for implementing the ContentPublisher intent.
|
|
108
|
-
*
|
|
109
|
-
* Implementing the ContentPublisher intent enables apps to publish contents to external platforms.
|
|
110
|
-
* This allows users to configure publish settings, preview their designs, and share with others.
|
|
111
|
-
*
|
|
112
|
-
* The publishing flow follows this process:
|
|
113
|
-
*
|
|
114
|
-
* 1. User initiates publish action
|
|
115
|
-
* 2. Your app provides publish configuration via `getPublishConfiguration`
|
|
116
|
-
* 3. User selects an output type
|
|
117
|
-
* 4. Your app renders settings UI via `renderSettingsUi`
|
|
118
|
-
* 5. Your app renders preview UI via `renderPreviewUi`
|
|
119
|
-
* 6. User reviews settings and preview
|
|
120
|
-
* 7. Your app publishes the content via `publishContent`
|
|
121
|
-
*/
|
|
122
|
-
export declare type ContentPublisherIntent = {
|
|
123
|
-
/**
|
|
124
|
-
* Provides the configuration for the publishing platform.
|
|
125
|
-
*
|
|
126
|
-
* This action is called when the user initiates the publish flow and needs to
|
|
127
|
-
* select an output type for the target platform.
|
|
128
|
-
*
|
|
129
|
-
* Use this to define different publishing configurations for your platform,
|
|
130
|
-
* such as social media posts, videos, or other output types.
|
|
131
|
-
*
|
|
132
|
-
* @returns A promise resolving to the publish configuration or an error
|
|
133
|
-
*
|
|
134
|
-
* @example Defining publish configuration for a social media platform
|
|
135
|
-
* ```ts
|
|
136
|
-
* import type { GetPublishConfigurationResponse } from '@canva/intents/content';
|
|
137
|
-
*
|
|
138
|
-
* async function getPublishConfiguration(): Promise<GetPublishConfigurationResponse> {
|
|
139
|
-
* return {
|
|
140
|
-
* status: 'completed',
|
|
141
|
-
* outputTypes: [
|
|
142
|
-
* {
|
|
143
|
-
* id: 'instagram_post',
|
|
144
|
-
* displayName: 'Instagram Post',
|
|
145
|
-
* mediaSlots: [
|
|
146
|
-
* {
|
|
147
|
-
* id: 'main_image',
|
|
148
|
-
* displayName: 'Post Image',
|
|
149
|
-
* fileCount: { min: 1, max: 10 },
|
|
150
|
-
* accepts: {
|
|
151
|
-
* image: { format: 'jpg', aspectRatio: { min: 0.8, max: 1.91 } }
|
|
152
|
-
* }
|
|
153
|
-
* }
|
|
154
|
-
* ]
|
|
155
|
-
* }
|
|
156
|
-
* ]
|
|
157
|
-
* };
|
|
158
|
-
* }
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
getPublishConfiguration: () => Promise<GetPublishConfigurationResponse>;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Renders a user interface for configuring publish settings.
|
|
165
|
-
*
|
|
166
|
-
* This action is called after the user selects an output type. Your UI should
|
|
167
|
-
* allow users to configure platform-specific settings such as captions, tags,
|
|
168
|
-
* privacy settings, or publishing destinations.
|
|
169
|
-
*
|
|
170
|
-
* Use the `updatePublishSettings` callback to save user settings and validate them.
|
|
171
|
-
* Settings are stored in the `publishRef` string (maximum 5KB).
|
|
172
|
-
*
|
|
173
|
-
* @param request - Configuration and callbacks for the publish settings UI.
|
|
174
|
-
*
|
|
175
|
-
* @example Rendering a settings UI with publish configuration
|
|
176
|
-
* ```ts
|
|
177
|
-
* import { createRoot } from 'react-dom/client';
|
|
178
|
-
* import type { RenderSettingsUiRequest } from '@canva/intents/content';
|
|
179
|
-
*
|
|
180
|
-
* function renderSettingsUi(request: RenderSettingsUiRequest): void {
|
|
181
|
-
* const SettingsUiApp = () => (
|
|
182
|
-
* <AppUiProvider>
|
|
183
|
-
* <SettingsUi request={request} />
|
|
184
|
-
* </AppUiProvider>
|
|
185
|
-
* );
|
|
186
|
-
*
|
|
187
|
-
* createRoot().render(<SettingsUiApp />)
|
|
188
|
-
* }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
renderSettingsUi: (request: RenderSettingsUiRequest) => void;
|
|
192
|
-
/**
|
|
193
|
-
* Renders a user interface for previewing the content.
|
|
194
|
-
*
|
|
195
|
-
* This action is called after the settings UI is rendered. Your UI should display
|
|
196
|
-
* a preview of how the content will appear on the target platform.
|
|
197
|
-
*
|
|
198
|
-
* Previews update dynamically as users modify their content or settings. For videos,
|
|
199
|
-
* start with lightweight thumbnails and use `requestPreviewUpgrade` to load full
|
|
200
|
-
* video previews on demand to optimize performance.
|
|
201
|
-
*
|
|
202
|
-
* @param request - Configuration and callbacks for the preview UI.
|
|
203
|
-
*
|
|
204
|
-
* @example Rendering a preview UI with video optimization
|
|
205
|
-
* ```ts
|
|
206
|
-
* import { createRoot } from 'react-dom/client';
|
|
207
|
-
* import type { RenderPreviewUiRequest } from '@canva/intents/content';
|
|
208
|
-
*
|
|
209
|
-
* function renderPreviewUi(request: RenderPreviewUiRequest): void {
|
|
210
|
-
* const PreviewUiApp = () => (
|
|
211
|
-
* <AppUiProvider>
|
|
212
|
-
* <PreviewUi request={request} />
|
|
213
|
-
* </AppUiProvider>
|
|
214
|
-
* );
|
|
215
|
-
*
|
|
216
|
-
* createRoot().render(<PreviewUiApp />)
|
|
217
|
-
* }
|
|
218
|
-
* ```
|
|
219
|
-
*/
|
|
220
|
-
renderPreviewUi: (request: RenderPreviewUiRequest) => void;
|
|
221
|
-
/**
|
|
222
|
-
* Publishes the content to the external platform.
|
|
223
|
-
*
|
|
224
|
-
* This action is called when the user confirms the publish action after reviewing
|
|
225
|
-
* settings and preview. Your implementation should send the exported files
|
|
226
|
-
* to your platform's API.
|
|
227
|
-
*
|
|
228
|
-
* The `outputMedia` contains production-ready files that match the requirements
|
|
229
|
-
* specified in your output types. The `publishRef` contains the user's settings
|
|
230
|
-
* from the settings UI.
|
|
231
|
-
*
|
|
232
|
-
* @param request - Parameters for the publish operation.
|
|
233
|
-
* @returns A promise resolving to either a successful result with the published content details or an error.
|
|
234
|
-
*
|
|
235
|
-
* @example Publishing content to an external platform
|
|
236
|
-
* ```ts
|
|
237
|
-
* import type { PublishContentRequest, PublishContentResponse } from '@canva/intents/content';
|
|
238
|
-
*
|
|
239
|
-
* async function publishContent(request: PublishContentRequest): Promise<PublishContentResponse> {
|
|
240
|
-
* const { publishRef, outputType, outputMedia } = request;
|
|
241
|
-
*
|
|
242
|
-
* try {
|
|
243
|
-
* // Parse settings from publishRef
|
|
244
|
-
* const settings = publishRef ? JSON.parse(publishRef) : {};
|
|
245
|
-
*
|
|
246
|
-
* // Upload files to your platform
|
|
247
|
-
* const uploadedFiles = await Promise.all(
|
|
248
|
-
* outputMedia.flatMap(media =>
|
|
249
|
-
* media.files.map(file => uploadFile(file.url))
|
|
250
|
-
* )
|
|
251
|
-
* );
|
|
252
|
-
*
|
|
253
|
-
* // Create post on your platform
|
|
254
|
-
* const result = await createPost({
|
|
255
|
-
* files: uploadedFiles,
|
|
256
|
-
* caption: settings.caption
|
|
257
|
-
* });
|
|
258
|
-
*
|
|
259
|
-
* return {
|
|
260
|
-
* status: 'completed',
|
|
261
|
-
* externalId: result.id,
|
|
262
|
-
* externalUrl: result.url
|
|
263
|
-
* };
|
|
264
|
-
* } catch (error) {
|
|
265
|
-
* return {
|
|
266
|
-
* status: 'remote_request_failed'
|
|
267
|
-
* };
|
|
268
|
-
* }
|
|
269
|
-
* }
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
publishContent: (
|
|
273
|
-
request: PublishContentRequest,
|
|
274
|
-
) => Promise<PublishContentResponse>;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @beta
|
|
279
|
-
* Metadata specific to design content.
|
|
280
|
-
*/
|
|
281
|
-
export declare interface DesignContentMetadata {
|
|
282
|
-
type: "design";
|
|
283
|
-
/**
|
|
284
|
-
* A signed JWT token containing the design id
|
|
285
|
-
*/
|
|
286
|
-
designToken: string;
|
|
287
|
-
/**
|
|
288
|
-
* The pages that make up the exported metadata
|
|
289
|
-
*/
|
|
290
|
-
pages: OutputPageMetadata[];
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* @beta
|
|
295
|
-
* A function that can be called to dispose of a callback.
|
|
296
|
-
*/
|
|
297
|
-
export declare type Disposer = () => void;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* @beta
|
|
301
|
-
* Exported PDF file ready for publishing.
|
|
302
|
-
*
|
|
303
|
-
* Contains the final PDF document that should be uploaded to your platform.
|
|
304
|
-
* The document format is `pdf_standard` and the file is ready to use.
|
|
305
|
-
*/
|
|
306
|
-
export declare type DocumentOutputFile = BaseOutputFile;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* @beta
|
|
310
|
-
* Document preview in various states.
|
|
311
|
-
*
|
|
312
|
-
* Documents transition through states: `"loading"` → `"thumbnail"`.
|
|
313
|
-
* Start with a lightweight thumbnail of the first page for quick preview rendering.
|
|
314
|
-
*/
|
|
315
|
-
export declare type DocumentPreview =
|
|
316
|
-
| DocumentPreviewLoading
|
|
317
|
-
| DocumentPreviewThumbnail
|
|
318
|
-
| DocumentPreviewError;
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* @beta
|
|
322
|
-
* Document preview that failed to generate.
|
|
323
|
-
*
|
|
324
|
-
* Display an error state to the user.
|
|
325
|
-
*/
|
|
326
|
-
export declare interface DocumentPreviewError extends BasePreview {
|
|
327
|
-
kind: "document";
|
|
328
|
-
status: "error";
|
|
329
|
-
/**
|
|
330
|
-
* The error message to display to the user.
|
|
331
|
-
*/
|
|
332
|
-
message: string;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* @beta
|
|
337
|
-
* Document preview that is currently being generated.
|
|
338
|
-
*
|
|
339
|
-
* Display a loading state until the preview transitions to `"thumbnail"` or `"error"`.
|
|
340
|
-
*/
|
|
341
|
-
export declare interface DocumentPreviewLoading extends BasePreview {
|
|
342
|
-
kind: "document";
|
|
343
|
-
status: "loading";
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @beta
|
|
348
|
-
* Document preview with first page thumbnail available.
|
|
349
|
-
*
|
|
350
|
-
* This is the initial state for document previews. Show the thumbnail image
|
|
351
|
-
* of the first page along with the page count to give users a preview of
|
|
352
|
-
* the document before publishing.
|
|
353
|
-
*/
|
|
354
|
-
export declare interface DocumentPreviewThumbnail extends BasePreview {
|
|
355
|
-
kind: "document";
|
|
356
|
-
status: "thumbnail";
|
|
357
|
-
/**
|
|
358
|
-
* Format of the thumbnail image.
|
|
359
|
-
*/
|
|
360
|
-
thumbnailFormat: "png" | "jpg";
|
|
361
|
-
/**
|
|
362
|
-
* URL to the first page thumbnail.
|
|
363
|
-
*
|
|
364
|
-
* Display this lightweight image to preview the document content.
|
|
365
|
-
*/
|
|
366
|
-
thumbnailUrl: string;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* @beta
|
|
371
|
-
* Document file requirements for a media slot.
|
|
372
|
-
*
|
|
373
|
-
* Note: Document output types use image previews (PNG thumbnails) in the preview UI.
|
|
374
|
-
* The actual document file is only generated for the final output in OutputMedia.
|
|
375
|
-
*
|
|
376
|
-
* @example Document requirements
|
|
377
|
-
* ```ts
|
|
378
|
-
* const documentReq: DocumentRequirement = {
|
|
379
|
-
* format: 'pdf_standard',
|
|
380
|
-
* size: 'a4',
|
|
381
|
-
* maxFileSizeMb: 50
|
|
382
|
-
* };
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
export declare interface DocumentRequirement extends BaseFileRequirement {
|
|
386
|
-
/**
|
|
387
|
-
* Supported document export format.
|
|
388
|
-
* Currently supports PDF standard format.
|
|
389
|
-
*/
|
|
390
|
-
format: "pdf_standard";
|
|
391
|
-
/**
|
|
392
|
-
* The document size of the export file.
|
|
393
|
-
*/
|
|
394
|
-
size: DocumentSize;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* @beta
|
|
399
|
-
* Document size for document exports.
|
|
400
|
-
*/
|
|
401
|
-
export declare type DocumentSize = "a4" | "a3" | "letter" | "legal";
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* @beta
|
|
405
|
-
* Exact value range constraint.
|
|
406
|
-
* @example Exact value range
|
|
407
|
-
* ```ts
|
|
408
|
-
* const exactValue: ValueRange = { exact: 1 }; // Must be exactly 1
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
export declare type ExactValueRange = {
|
|
412
|
-
exact: number;
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* @beta
|
|
417
|
-
* Successful response from getting publish configuration.
|
|
418
|
-
*/
|
|
419
|
-
export declare type GetPublishConfigurationCompleted = {
|
|
420
|
-
status: "completed";
|
|
421
|
-
/**
|
|
422
|
-
* Array of available output types for your platform.
|
|
423
|
-
*
|
|
424
|
-
* Define different output types for various content formats that
|
|
425
|
-
* your platform supports (e.g., posts, stories, videos).
|
|
426
|
-
*/
|
|
427
|
-
outputTypes: OutputType[];
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* @beta
|
|
432
|
-
* {@link GetPublishConfigurationError} error indicating a custom error occurred.
|
|
433
|
-
*/
|
|
434
|
-
export declare type GetPublishConfigurationError = AppError;
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* @beta
|
|
438
|
-
* Response from getting publish configuration.
|
|
439
|
-
*/
|
|
440
|
-
export declare type GetPublishConfigurationResponse =
|
|
441
|
-
| GetPublishConfigurationCompleted
|
|
442
|
-
| GetPublishConfigurationError;
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* @beta
|
|
446
|
-
* Exported image file ready for publishing.
|
|
447
|
-
*/
|
|
448
|
-
export declare interface ImageOutputFile extends BaseOutputFile {
|
|
449
|
-
/**
|
|
450
|
-
* Width of the image in pixels.
|
|
451
|
-
*/
|
|
452
|
-
widthPx: number;
|
|
453
|
-
/**
|
|
454
|
-
* Height of the image in pixels.
|
|
455
|
-
*/
|
|
456
|
-
heightPx: number;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* @beta
|
|
461
|
-
* Image preview in various states.
|
|
462
|
-
*/
|
|
463
|
-
export declare type ImagePreview =
|
|
464
|
-
| ImagePreviewLoading
|
|
465
|
-
| ImagePreviewReady
|
|
466
|
-
| ImagePreviewError;
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* @beta
|
|
470
|
-
* Image preview that failed to generate.
|
|
471
|
-
*
|
|
472
|
-
* Display an error state to the user.
|
|
473
|
-
*/
|
|
474
|
-
export declare interface ImagePreviewError extends BasePreview {
|
|
475
|
-
kind: "image";
|
|
476
|
-
status: "error";
|
|
477
|
-
/**
|
|
478
|
-
* @deprecated Use `message` instead.
|
|
479
|
-
* Optional, user-facing error message to display in the preview UI.
|
|
480
|
-
*/
|
|
481
|
-
userFacingErrorMessage?: string;
|
|
482
|
-
/**
|
|
483
|
-
* The error message to display to the user.
|
|
484
|
-
*/
|
|
485
|
-
message: string;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* @beta
|
|
490
|
-
* Image preview that is currently being generated.
|
|
491
|
-
*
|
|
492
|
-
* Display a loading state until the preview transitions to `"ready"` or `"error"`.
|
|
493
|
-
*/
|
|
494
|
-
export declare interface ImagePreviewLoading extends BasePreview {
|
|
495
|
-
kind: "image";
|
|
496
|
-
status: "loading";
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* @beta
|
|
501
|
-
* Image preview that is ready to display.
|
|
502
|
-
*
|
|
503
|
-
* Contains the URL to the preview image.
|
|
504
|
-
*/
|
|
505
|
-
export declare interface ImagePreviewReady extends BasePreview {
|
|
506
|
-
kind: "image";
|
|
507
|
-
status: "ready";
|
|
508
|
-
/**
|
|
509
|
-
* Image format of the preview.
|
|
510
|
-
*/
|
|
511
|
-
format: "png" | "jpg";
|
|
512
|
-
/**
|
|
513
|
-
* URL to the preview image.
|
|
514
|
-
*
|
|
515
|
-
* Use this URL to display the preview to users.
|
|
516
|
-
*/
|
|
517
|
-
url: string;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* @beta
|
|
522
|
-
* Image file requirements for a media slot.
|
|
523
|
-
*
|
|
524
|
-
* Specifies format, aspect ratio, and size constraints for images.
|
|
525
|
-
*
|
|
526
|
-
* @example Image requirements for social media post
|
|
527
|
-
* ```ts
|
|
528
|
-
* const imageReq: ImageRequirement = {
|
|
529
|
-
* format: 'jpg',
|
|
530
|
-
* aspectRatio: { min: 0.8, max: 1.91 },
|
|
531
|
-
* maxFileSizeMb: 8
|
|
532
|
-
* };
|
|
533
|
-
* ```
|
|
534
|
-
*/
|
|
535
|
-
export declare interface ImageRequirement extends BaseFileRequirement {
|
|
536
|
-
/**
|
|
537
|
-
* Supported image format.
|
|
538
|
-
*/
|
|
539
|
-
format: "png" | "jpg";
|
|
540
|
-
/**
|
|
541
|
-
* Aspect ratio constraint (width / height).
|
|
542
|
-
*
|
|
543
|
-
* Examples:
|
|
544
|
-
* - `{ exact: 16/9 }`: Widescreen (16:9)
|
|
545
|
-
* - `{ min: 0.8, max: 1.91 }`: Instagram range
|
|
546
|
-
*/
|
|
547
|
-
aspectRatio?: ValueRange;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* @beta
|
|
552
|
-
* Maximum value range constraint.
|
|
553
|
-
* @example Maximum value range
|
|
554
|
-
* ```ts
|
|
555
|
-
* const maxValue: ValueRange = { max: 10 }; // At most 10
|
|
556
|
-
* ```
|
|
557
|
-
*/
|
|
558
|
-
export declare type MaxValueRange = {
|
|
559
|
-
max: number;
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* @beta
|
|
564
|
-
* Configuration for a media slot within an output type.
|
|
565
|
-
*
|
|
566
|
-
* Defines what type of media is accepted, requirements, and constraints.
|
|
567
|
-
*
|
|
568
|
-
* @example Image slot with aspect ratio requirements
|
|
569
|
-
* ```ts
|
|
570
|
-
* const thumbnailSlot: MediaSlot = {
|
|
571
|
-
* id: 'thumbnail',
|
|
572
|
-
* displayName: 'Video Thumbnail',
|
|
573
|
-
* fileCount: { exact: 1 },
|
|
574
|
-
* accepts: {
|
|
575
|
-
* image: {
|
|
576
|
-
* format: 'jpg',
|
|
577
|
-
* aspectRatio: { exact: 16/9 },
|
|
578
|
-
* maxFileSizeMb: 2
|
|
579
|
-
* }
|
|
580
|
-
* }
|
|
581
|
-
* };
|
|
582
|
-
* ```
|
|
583
|
-
*/
|
|
584
|
-
export declare type MediaSlot = {
|
|
585
|
-
/**
|
|
586
|
-
* Unique identifier for this media slot within the output type.
|
|
587
|
-
*/
|
|
588
|
-
id: string;
|
|
589
|
-
/**
|
|
590
|
-
* User-facing name for this media slot.
|
|
591
|
-
*
|
|
592
|
-
* Examples: `"Post Image"`, `"Video Thumbnail"`, `"Main Video"`.
|
|
593
|
-
*/
|
|
594
|
-
displayName: string;
|
|
595
|
-
/**
|
|
596
|
-
* Number of files accepted in this slot.
|
|
597
|
-
*
|
|
598
|
-
* Use this to specify single or multiple file requirements.
|
|
599
|
-
* Examples:
|
|
600
|
-
* - `{ exact: 1 }`: Exactly one file
|
|
601
|
-
* - `{ min: 1, max: 10 }`: Between 1 and 10 files
|
|
602
|
-
* - undefined: Any number of files
|
|
603
|
-
*/
|
|
604
|
-
fileCount?: ValueRange;
|
|
605
|
-
/**
|
|
606
|
-
* File type requirements for this slot.
|
|
607
|
-
*
|
|
608
|
-
* Note the following behavior:
|
|
609
|
-
*
|
|
610
|
-
* - Provide at least one of `image` or `video`
|
|
611
|
-
* - If both are provided, files for this slot may be either images or videos; each file
|
|
612
|
-
* must satisfy the corresponding requirement for its media type
|
|
613
|
-
* - To restrict the slot to a single media type, provide only that requirement
|
|
614
|
-
* - `fileCount` applies across all files accepted by the slot regardless of media type
|
|
615
|
-
* - Document output types will show image previews (PNG thumbnail) in preview UI
|
|
616
|
-
*/
|
|
617
|
-
accepts: {
|
|
618
|
-
image?: ImageRequirement;
|
|
619
|
-
video?: VideoRequirement;
|
|
620
|
-
document?: DocumentRequirement;
|
|
621
|
-
};
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* @beta
|
|
626
|
-
* Minimum and maximum value range constraint.
|
|
627
|
-
* Ranges are inclusive `(min ≤ value ≤ max)`.
|
|
628
|
-
* @example Minimum and maximum value range
|
|
629
|
-
* ```ts
|
|
630
|
-
* const minMaxValue: ValueRange = { min: 1, max: 10 }; // Between 1 and 10
|
|
631
|
-
* ```
|
|
632
|
-
*/
|
|
633
|
-
export declare type MinMaxValueRange = {
|
|
634
|
-
min: number;
|
|
635
|
-
max: number;
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* @beta
|
|
640
|
-
* Minimum value range constraint.
|
|
641
|
-
* @example Minimum value range
|
|
642
|
-
* ```ts
|
|
643
|
-
* const minValue: ValueRange = { min: 3 }; // At least 3
|
|
644
|
-
* ```
|
|
645
|
-
*/
|
|
646
|
-
export declare type MinValueRange = {
|
|
647
|
-
min: number;
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* @beta
|
|
652
|
-
* Exported file ready for publishing.
|
|
653
|
-
*/
|
|
654
|
-
export declare type OutputFile =
|
|
655
|
-
| ImageOutputFile
|
|
656
|
-
| VideoOutputFile
|
|
657
|
-
| DocumentOutputFile;
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* @beta
|
|
661
|
-
* Production-ready exported files for a specific media slot.
|
|
662
|
-
*
|
|
663
|
-
* These are the final files that should be uploaded to your platform.
|
|
664
|
-
*/
|
|
665
|
-
export declare type OutputMedia = {
|
|
666
|
-
/**
|
|
667
|
-
* ID of the media slot these files belong to.
|
|
668
|
-
*
|
|
669
|
-
* Matches a media slot ID from your output type definition.
|
|
670
|
-
*/
|
|
671
|
-
mediaSlotId: string;
|
|
672
|
-
/**
|
|
673
|
-
* Array of exported files for this media slot.
|
|
674
|
-
*
|
|
675
|
-
* Files match the requirements specified in your media slot configuration.
|
|
676
|
-
*/
|
|
677
|
-
files: OutputFile[];
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* @beta
|
|
682
|
-
* Metadata about a specific page in the exported content.
|
|
683
|
-
*/
|
|
684
|
-
export declare type OutputPageMetadata = {
|
|
685
|
-
/**
|
|
686
|
-
* The unique identifier for the page.
|
|
687
|
-
*/
|
|
688
|
-
pageId: string | undefined;
|
|
689
|
-
/**
|
|
690
|
-
* The position of the page within the design, starting from 1 for the first page.
|
|
691
|
-
*/
|
|
692
|
-
pageNumber: number;
|
|
693
|
-
};
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* @beta
|
|
697
|
-
* Configuration for an output type.
|
|
698
|
-
*
|
|
699
|
-
* Defines a specific publishing format your platform supports,
|
|
700
|
-
* including what media is required and accepted file types.
|
|
701
|
-
*
|
|
702
|
-
* @example Defining an Instagram post output type
|
|
703
|
-
* ```ts
|
|
704
|
-
* const instagramPost: OutputType = {
|
|
705
|
-
* id: 'instagram_post',
|
|
706
|
-
* displayName: 'Instagram Post',
|
|
707
|
-
* mediaSlots: [
|
|
708
|
-
* {
|
|
709
|
-
* id: 'main_image',
|
|
710
|
-
* displayName: 'Post Image',
|
|
711
|
-
* fileCount: { min: 1, max: 10 },
|
|
712
|
-
* accepts: {
|
|
713
|
-
* image: {
|
|
714
|
-
* format: 'jpg',
|
|
715
|
-
* aspectRatio: { min: 0.8, max: 1.91 },
|
|
716
|
-
* maxFileSizeMb: 8
|
|
717
|
-
* }
|
|
718
|
-
* }
|
|
719
|
-
* }
|
|
720
|
-
* ]
|
|
721
|
-
* };
|
|
722
|
-
* ```
|
|
723
|
-
*/
|
|
724
|
-
export declare type OutputType = {
|
|
725
|
-
/**
|
|
726
|
-
* Unique identifier for this output type.
|
|
727
|
-
*
|
|
728
|
-
* Use descriptive IDs like `"instagram_post"` or `"youtube_video"`.
|
|
729
|
-
*/
|
|
730
|
-
id: string;
|
|
731
|
-
/**
|
|
732
|
-
* User-facing name for this output type.
|
|
733
|
-
*
|
|
734
|
-
* This is displayed to users when selecting where to publish.
|
|
735
|
-
* Examples: `"Instagram Post"`, `"YouTube Video"`, `"Twitter Post"`.
|
|
736
|
-
*/
|
|
737
|
-
displayName: string;
|
|
738
|
-
/**
|
|
739
|
-
* Array of media slots defining what content is needed.
|
|
740
|
-
*
|
|
741
|
-
* Each slot represents a piece of media required for publishing,
|
|
742
|
-
* such as a main image, thumbnail, or video.
|
|
743
|
-
*/
|
|
744
|
-
mediaSlots: MediaSlot[];
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* @beta
|
|
749
|
-
* Action to be taken after publishing completes successfully.
|
|
750
|
-
*/
|
|
751
|
-
export declare type PostPublishAction = PostPublishActionRedirect;
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* @beta
|
|
755
|
-
* Redirect action to navigate the user to a URL after publishing.
|
|
756
|
-
*
|
|
757
|
-
* @example Redirecting to content editor
|
|
758
|
-
* ```ts
|
|
759
|
-
* const postPublishAction: PostPublishActionRedirect = {
|
|
760
|
-
* type: 'redirect',
|
|
761
|
-
* url: 'https://example.com/posts/12345/edit'
|
|
762
|
-
* };
|
|
763
|
-
* ```
|
|
764
|
-
*/
|
|
765
|
-
export declare type PostPublishActionRedirect = {
|
|
766
|
-
type: "redirect";
|
|
767
|
-
/**
|
|
768
|
-
* The URL to redirect the user to after publishing.
|
|
769
|
-
*/
|
|
770
|
-
url: string;
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* @beta
|
|
775
|
-
*
|
|
776
|
-
* Prepares a {@link ContentPublisherIntent|Content Publisher Intent}.
|
|
777
|
-
*
|
|
778
|
-
* @example
|
|
779
|
-
* ```tsx
|
|
780
|
-
* import { prepareContentPublisher } from "@canva/intents/content";
|
|
781
|
-
*
|
|
782
|
-
* prepareContentPublisher({
|
|
783
|
-
* getPublishConfiguration: async (params) => {
|
|
784
|
-
* // Implement the logic to get the publish configuration
|
|
785
|
-
* },
|
|
786
|
-
* renderSettingsUi: (params) => {
|
|
787
|
-
* // Implement the UI for settings view
|
|
788
|
-
* },
|
|
789
|
-
* renderPreviewUi: (params) => {
|
|
790
|
-
* // Implement the UI for preview view
|
|
791
|
-
* },
|
|
792
|
-
* publishContent: async (params) => {
|
|
793
|
-
* // Implement the logic to publish the content
|
|
794
|
-
* },
|
|
795
|
-
* });
|
|
796
|
-
* ```
|
|
797
|
-
*/
|
|
798
|
-
export declare const prepareContentPublisher: (
|
|
799
|
-
implementation: ContentPublisherIntent,
|
|
800
|
-
) => void;
|
|
801
|
-
|
|
802
|
-
/**
|
|
803
|
-
* @beta
|
|
804
|
-
* Preview item for an image or video.
|
|
805
|
-
*
|
|
806
|
-
* Check the `kind` and `status` properties to determine the type and state.
|
|
807
|
-
*/
|
|
808
|
-
export declare type Preview = ImagePreview | VideoPreview | DocumentPreview;
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* @beta
|
|
812
|
-
* Type of preview media.
|
|
813
|
-
*/
|
|
814
|
-
export declare type PreviewKind = "image" | "video" | "document";
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* @beta
|
|
818
|
-
* Preview media for a specific media slot.
|
|
819
|
-
*
|
|
820
|
-
* Contains preview URLs and metadata for images or videos in the design.
|
|
821
|
-
*/
|
|
822
|
-
export declare type PreviewMedia = {
|
|
823
|
-
/**
|
|
824
|
-
* ID of the media slot this preview belongs to.
|
|
825
|
-
*
|
|
826
|
-
* Matches a media slot ID from your output type definition.
|
|
827
|
-
*/
|
|
828
|
-
mediaSlotId: string;
|
|
829
|
-
/**
|
|
830
|
-
* Array of preview items for this media slot.
|
|
831
|
-
*
|
|
832
|
-
* May contain multiple previews if the media slot accepts multiple files.
|
|
833
|
-
*/
|
|
834
|
-
previews: Preview[];
|
|
835
|
-
};
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* @beta
|
|
839
|
-
* State of a preview item.
|
|
840
|
-
*/
|
|
841
|
-
export declare type PreviewStatus =
|
|
842
|
-
| "loading"
|
|
843
|
-
| "thumbnail"
|
|
844
|
-
| "upgrading"
|
|
845
|
-
| "ready"
|
|
846
|
-
| "error";
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* @beta
|
|
850
|
-
* Successful response from publishing a content.
|
|
851
|
-
*
|
|
852
|
-
* @example Basic successful publish
|
|
853
|
-
* ```ts
|
|
854
|
-
* return {
|
|
855
|
-
* status: 'completed',
|
|
856
|
-
* externalId: 'post_12345',
|
|
857
|
-
* externalUrl: 'https://example.com/posts/12345'
|
|
858
|
-
* };
|
|
859
|
-
* ```
|
|
860
|
-
*
|
|
861
|
-
* @example Successful publish with redirect
|
|
862
|
-
* ```ts
|
|
863
|
-
* return {
|
|
864
|
-
* status: 'completed',
|
|
865
|
-
* externalId: 'video_67890',
|
|
866
|
-
* externalUrl: 'https://example.com/videos/67890',
|
|
867
|
-
* postPublishAction: {
|
|
868
|
-
* type: 'redirect',
|
|
869
|
-
* url: 'https://example.com/videos/67890/edit'
|
|
870
|
-
* }
|
|
871
|
-
* };
|
|
872
|
-
* ```
|
|
873
|
-
*/
|
|
874
|
-
export declare type PublishContentCompleted = {
|
|
875
|
-
status: "completed";
|
|
876
|
-
/**
|
|
877
|
-
* Unique identifier returned from your external platform. You can use this for:
|
|
878
|
-
*
|
|
879
|
-
* - Tracking published content
|
|
880
|
-
* - Fetching insights data for the published content
|
|
881
|
-
* - Linking back to the content in future operations
|
|
882
|
-
*/
|
|
883
|
-
externalId?: string;
|
|
884
|
-
/**
|
|
885
|
-
* Direct URL to the published content on your platform.
|
|
886
|
-
*
|
|
887
|
-
* Users can visit this URL to view their published content.
|
|
888
|
-
* This may be displayed to users or used for sharing.
|
|
889
|
-
*/
|
|
890
|
-
externalUrl?: string;
|
|
891
|
-
/**
|
|
892
|
-
* Optional action to perform after publishing completes.
|
|
893
|
-
*
|
|
894
|
-
* Currently supports redirecting users to a specific URL after publishing.
|
|
895
|
-
*/
|
|
896
|
-
postPublishAction?: PostPublishAction;
|
|
897
|
-
};
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* @beta
|
|
901
|
-
* Error response from publishing a content.
|
|
902
|
-
*
|
|
903
|
-
* Return the appropriate error type based on the failure:
|
|
904
|
-
*
|
|
905
|
-
* - `"remote_request_failed"`: Network or API errors with your platform
|
|
906
|
-
* - `"app_error"`: Custom application errors with optional message
|
|
907
|
-
*/
|
|
908
|
-
export declare type PublishContentError = RemoteRequestFailedError | AppError;
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* @beta
|
|
912
|
-
* Parameters required for publishing the content.
|
|
913
|
-
* Contains all the information needed to send the content to your external platform.
|
|
914
|
-
*/
|
|
915
|
-
export declare type PublishContentRequest = {
|
|
916
|
-
/**
|
|
917
|
-
* Platform-specific settings reference containing user configurations.
|
|
918
|
-
*
|
|
919
|
-
* This is the same reference you saved via `updatePublishSettings` in the settings UI.
|
|
920
|
-
* Parse this string to retrieve the user's publish settings (e.g., captions, tags, privacy).
|
|
921
|
-
*
|
|
922
|
-
* Maximum size: 5KB
|
|
923
|
-
*/
|
|
924
|
-
publishRef?: string;
|
|
925
|
-
/**
|
|
926
|
-
* The output type selected by the user for this publish operation.
|
|
927
|
-
*
|
|
928
|
-
* This matches one of the output types you provided in `getPublishConfiguration`.
|
|
929
|
-
*/
|
|
930
|
-
outputType: OutputType;
|
|
931
|
-
/**
|
|
932
|
-
* Production-ready exported files matching the requirements from your output type.
|
|
933
|
-
*
|
|
934
|
-
* These files are ready to upload to your platform and match the format, size,
|
|
935
|
-
* and aspect ratio requirements specified in your media slots.
|
|
936
|
-
*/
|
|
937
|
-
outputMedia: OutputMedia[];
|
|
938
|
-
};
|
|
939
|
-
|
|
940
|
-
/**
|
|
941
|
-
* @beta
|
|
942
|
-
* Response from a publish content operation.
|
|
943
|
-
*
|
|
944
|
-
* This can be either a successful completion or an error response.
|
|
945
|
-
*/
|
|
946
|
-
export declare type PublishContentResponse =
|
|
947
|
-
| PublishContentCompleted
|
|
948
|
-
| PublishContentError;
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* @beta
|
|
952
|
-
* Supported file formats for publishing.
|
|
953
|
-
*/
|
|
954
|
-
export declare type PublishFileFormat = "png" | "jpg" | "mp4" | "pdf_standard";
|
|
955
|
-
|
|
956
|
-
/**
|
|
957
|
-
* @beta
|
|
958
|
-
* Validation state indicating whether publish settings are complete and valid.
|
|
959
|
-
*/
|
|
960
|
-
export declare type PublishRefValidityState =
|
|
961
|
-
| "valid"
|
|
962
|
-
| "invalid_missing_required_fields"
|
|
963
|
-
| "invalid_authentication_required";
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* @beta
|
|
967
|
-
* Configuration for publish settings.
|
|
968
|
-
*
|
|
969
|
-
* Contains the user's settings and their validation state. Use this to
|
|
970
|
-
* control whether the publish button is enabled.
|
|
971
|
-
*/
|
|
972
|
-
export declare type PublishSettings = {
|
|
973
|
-
/**
|
|
974
|
-
* Serialized platform-specific settings for publishing.
|
|
975
|
-
*
|
|
976
|
-
* Store all information your app needs to publish the content in this string.
|
|
977
|
-
* This might include:
|
|
978
|
-
*
|
|
979
|
-
* - Captions or descriptions
|
|
980
|
-
* - Tags or hashtags
|
|
981
|
-
* - Privacy settings
|
|
982
|
-
* - Publishing destination (account, page, etc.)
|
|
983
|
-
* - Scheduling information
|
|
984
|
-
*
|
|
985
|
-
* This reference will be provided to your `publishContent` method when publishing.
|
|
986
|
-
*
|
|
987
|
-
* Maximum size: 5KB
|
|
988
|
-
*
|
|
989
|
-
* @example Serializing settings
|
|
990
|
-
* ```ts
|
|
991
|
-
* const settings = {
|
|
992
|
-
* caption: 'Check out my design!',
|
|
993
|
-
* tags: ['design', 'creative'],
|
|
994
|
-
* privacy: 'public'
|
|
995
|
-
* };
|
|
996
|
-
* const publishRef = JSON.stringify(settings);
|
|
997
|
-
* ```
|
|
998
|
-
*/
|
|
999
|
-
publishRef?: string;
|
|
1000
|
-
/**
|
|
1001
|
-
* Validation state of the publish settings.
|
|
1002
|
-
*
|
|
1003
|
-
* Controls whether the publish button is enabled:
|
|
1004
|
-
*
|
|
1005
|
-
* - `"valid"`: Settings are complete and valid, publish button is enabled
|
|
1006
|
-
* - `"invalid_missing_required_fields"`: Required settings are missing, publish button is disabled
|
|
1007
|
-
* - `"invalid_authentication_required"`: User must authenticate before publishing can proceed
|
|
1008
|
-
*/
|
|
1009
|
-
validityState: PublishRefValidityState;
|
|
1010
|
-
};
|
|
1011
|
-
|
|
1012
|
-
/**
|
|
1013
|
-
* @beta
|
|
1014
|
-
* {@link PublishContentError} indicating failure of the remote request to the external platform.
|
|
1015
|
-
*
|
|
1016
|
-
* Return this error for:
|
|
1017
|
-
*
|
|
1018
|
-
* - Network connectivity issues
|
|
1019
|
-
* - API endpoint failures
|
|
1020
|
-
* - HTTP errors from your platform
|
|
1021
|
-
* - Timeout errors
|
|
1022
|
-
*
|
|
1023
|
-
* @example Handling network errors
|
|
1024
|
-
* ```ts
|
|
1025
|
-
* try {
|
|
1026
|
-
* await uploadToExternalPlatform(file);
|
|
1027
|
-
* } catch (error) {
|
|
1028
|
-
* return { status: 'remote_request_failed' };
|
|
1029
|
-
* }
|
|
1030
|
-
* ```
|
|
1031
|
-
*/
|
|
1032
|
-
export declare type RemoteRequestFailedError = {
|
|
1033
|
-
status: "remote_request_failed";
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* @beta
|
|
1038
|
-
* Configuration required for rendering the preview UI.
|
|
1039
|
-
*
|
|
1040
|
-
* Provides callbacks for managing preview media and responding to preview updates.
|
|
1041
|
-
*/
|
|
1042
|
-
export declare type RenderPreviewUiRequest = {
|
|
1043
|
-
/**
|
|
1044
|
-
* Callback to upgrade video thumbnail previews to full video media.
|
|
1045
|
-
*
|
|
1046
|
-
* Call this function when you need full video previews instead of lightweight thumbnails.
|
|
1047
|
-
* This helps optimize performance by deferring full video loading until needed.
|
|
1048
|
-
*
|
|
1049
|
-
* Upgrades may complete asynchronously; listen to `registerOnPreviewChange` for updates
|
|
1050
|
-
* to receive the upgraded video previews.
|
|
1051
|
-
*
|
|
1052
|
-
* @param previewIds - Array of preview IDs to upgrade from thumbnail to full video
|
|
1053
|
-
*
|
|
1054
|
-
* @example Upgrading video previews on user interaction
|
|
1055
|
-
* ```ts
|
|
1056
|
-
* // When user clicks on a video thumbnail, upgrade to full video
|
|
1057
|
-
* if (preview.kind === 'video' && preview.status === 'thumbnail') {
|
|
1058
|
-
* requestPreviewUpgrade([preview.id]);
|
|
1059
|
-
* }
|
|
1060
|
-
* ```
|
|
1061
|
-
*/
|
|
1062
|
-
requestPreviewUpgrade: (previewIds: string[]) => void;
|
|
1063
|
-
/**
|
|
1064
|
-
* Registers a callback to be invoked when preview data changes.
|
|
1065
|
-
*
|
|
1066
|
-
* This callback is triggered when:
|
|
1067
|
-
*
|
|
1068
|
-
* - The design content changes
|
|
1069
|
-
* - The output type changes
|
|
1070
|
-
* - Preview media is upgraded from thumbnail to full video
|
|
1071
|
-
* - Export settings are modified
|
|
1072
|
-
*
|
|
1073
|
-
* Use this to update your preview UI in real-time as users modify their design.
|
|
1074
|
-
*
|
|
1075
|
-
* @param callback - The callback invoked when preview data is updated
|
|
1076
|
-
* @returns A disposer function that cleans up the registered callback
|
|
1077
|
-
*
|
|
1078
|
-
* @example Handling preview updates
|
|
1079
|
-
* ```ts
|
|
1080
|
-
* const disposer = registerOnPreviewChange(({ previewMedia, outputType, publishRef }) => {
|
|
1081
|
-
* // Update your preview UI with the new preview media
|
|
1082
|
-
* previewMedia.forEach((media) => {
|
|
1083
|
-
* media.previews.forEach((preview) => {
|
|
1084
|
-
* if (preview.status === 'ready') {
|
|
1085
|
-
* displayPreview(preview);
|
|
1086
|
-
* }
|
|
1087
|
-
* });
|
|
1088
|
-
* });
|
|
1089
|
-
* });
|
|
1090
|
-
*
|
|
1091
|
-
* // Clean up when preview UI is unmounted
|
|
1092
|
-
* onUnmount(() => disposer());
|
|
1093
|
-
* ```
|
|
1094
|
-
*/
|
|
1095
|
-
registerOnPreviewChange: (
|
|
1096
|
-
callback: (opts: {
|
|
1097
|
-
previewMedia: PreviewMedia[];
|
|
1098
|
-
/** The output type that the preview data is for */
|
|
1099
|
-
outputType: OutputType;
|
|
1100
|
-
/** The current publish settings reference, if available */
|
|
1101
|
-
publishRef?: string;
|
|
1102
|
-
}) => void,
|
|
1103
|
-
) => Disposer;
|
|
1104
|
-
};
|
|
1105
|
-
|
|
1106
|
-
/**
|
|
1107
|
-
* @beta
|
|
1108
|
-
* Configuration for the publish settings UI.
|
|
1109
|
-
*
|
|
1110
|
-
* This type provides the necessary callbacks and configuration for rendering
|
|
1111
|
-
* a custom publish settings interface where users configure platform-specific options.
|
|
1112
|
-
*/
|
|
1113
|
-
export declare type RenderSettingsUiRequest = {
|
|
1114
|
-
/**
|
|
1115
|
-
* Callback to save and validate the user's publish settings.
|
|
1116
|
-
*
|
|
1117
|
-
* Call this function whenever the user modifies their settings to:
|
|
1118
|
-
*
|
|
1119
|
-
* - Save the settings for later use in `publishContent`
|
|
1120
|
-
* - Validate that required fields are filled
|
|
1121
|
-
* - Enable or disable the publish button based on validity
|
|
1122
|
-
*
|
|
1123
|
-
* Store all necessary publishing information in the `publishRef` string.
|
|
1124
|
-
* This will be provided to your `publishContent` method when the user publishes.
|
|
1125
|
-
*
|
|
1126
|
-
* @param settings - The new publish settings to save
|
|
1127
|
-
* @returns A promise that resolves when the settings are successfully saved
|
|
1128
|
-
* @throws Will throw `CanvaError('bad_request')` if {@link PublishSettings.publishRef} exceeds 5KB.
|
|
1129
|
-
*
|
|
1130
|
-
* @example Updating settings as user types
|
|
1131
|
-
* ```ts
|
|
1132
|
-
* // As user fills in form fields, update settings
|
|
1133
|
-
* function handleCaptionChange(caption: string) {
|
|
1134
|
-
* const settings = { caption, tags: currentTags };
|
|
1135
|
-
* const publishRef = JSON.stringify(settings);
|
|
1136
|
-
*
|
|
1137
|
-
* updatePublishSettings({
|
|
1138
|
-
* publishRef,
|
|
1139
|
-
* validityState: caption ? 'valid' : 'invalid_missing_required_fields'
|
|
1140
|
-
* });
|
|
1141
|
-
* }
|
|
1142
|
-
* ```
|
|
1143
|
-
*/
|
|
1144
|
-
updatePublishSettings: (
|
|
1145
|
-
publishSettings: PublishSettings,
|
|
1146
|
-
) => Promise<UpdatePublishSettingsResponse>;
|
|
1147
|
-
/**
|
|
1148
|
-
* Registers a callback to be invoked when the settings UI context changes.
|
|
1149
|
-
*
|
|
1150
|
-
* This callback is triggered when the user changes the output type in the publish flow.
|
|
1151
|
-
* Use this to update your settings UI to match the requirements of the new output type.
|
|
1152
|
-
*
|
|
1153
|
-
* @param callback - The callback invoked when settings context is updated.
|
|
1154
|
-
* @returns A disposer function that cleans up the registered callback.
|
|
1155
|
-
*
|
|
1156
|
-
* @example Adapting UI for different output types
|
|
1157
|
-
* ```ts
|
|
1158
|
-
* registerOnSettingsUiContextChange((context) => {
|
|
1159
|
-
* if (context.outputType.id === 'instagram_post') {
|
|
1160
|
-
* // Show Instagram-specific settings
|
|
1161
|
-
* showHashtagField();
|
|
1162
|
-
* } else if (context.outputType.id === 'instagram_story') {
|
|
1163
|
-
* // Show instagram_story settings
|
|
1164
|
-
* showCaptionField();
|
|
1165
|
-
* }
|
|
1166
|
-
* });
|
|
1167
|
-
* ```
|
|
1168
|
-
*/
|
|
1169
|
-
registerOnSettingsUiContextChange: (
|
|
1170
|
-
callback: (context: SettingsUiContext) => void,
|
|
1171
|
-
) => Disposer;
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
* @beta
|
|
1176
|
-
* Context information for the publish settings UI.
|
|
1177
|
-
*
|
|
1178
|
-
* Provides information about the current state of the settings UI to help
|
|
1179
|
-
* you adapt the interface based on the selected output type.
|
|
1180
|
-
*/
|
|
1181
|
-
export declare type SettingsUiContext = {
|
|
1182
|
-
/**
|
|
1183
|
-
* The currently selected output type.
|
|
1184
|
-
*
|
|
1185
|
-
* Use this to customize your settings UI based on the requirements
|
|
1186
|
-
* of different output types.
|
|
1187
|
-
*/
|
|
1188
|
-
outputType: OutputType;
|
|
1189
|
-
};
|
|
1190
|
-
|
|
1191
|
-
/**
|
|
1192
|
-
* @beta
|
|
1193
|
-
* Successful response from updating the publish settings.
|
|
1194
|
-
*/
|
|
1195
|
-
export declare type UpdatePublishSettingsCompleted = {
|
|
1196
|
-
status: "completed";
|
|
1197
|
-
};
|
|
1198
|
-
|
|
1199
|
-
/**
|
|
1200
|
-
* @beta
|
|
1201
|
-
* Response from updating the publish settings.
|
|
1202
|
-
*/
|
|
1203
|
-
export declare type UpdatePublishSettingsResponse =
|
|
1204
|
-
UpdatePublishSettingsCompleted;
|
|
1205
|
-
|
|
1206
|
-
/**
|
|
1207
|
-
* @beta
|
|
1208
|
-
* Numeric value range constraint.
|
|
1209
|
-
* Used to specify requirements for aspect ratios, durations, file counts, etc.
|
|
1210
|
-
*/
|
|
1211
|
-
export declare type ValueRange =
|
|
1212
|
-
| ExactValueRange
|
|
1213
|
-
| MinValueRange
|
|
1214
|
-
| MaxValueRange
|
|
1215
|
-
| MinMaxValueRange;
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* @beta
|
|
1219
|
-
* Exported video file ready for publishing.
|
|
1220
|
-
*/
|
|
1221
|
-
export declare interface VideoOutputFile extends BaseOutputFile {
|
|
1222
|
-
/**
|
|
1223
|
-
* Width of the video in pixels.
|
|
1224
|
-
*/
|
|
1225
|
-
widthPx: number;
|
|
1226
|
-
/**
|
|
1227
|
-
* Height of the video in pixels.
|
|
1228
|
-
*/
|
|
1229
|
-
heightPx: number;
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
/**
|
|
1233
|
-
* @beta
|
|
1234
|
-
* Video preview in various states.
|
|
1235
|
-
*
|
|
1236
|
-
* Videos transition through states: `"loading"` → `"thumbnail"` → `"upgrading"` → `"ready"`.
|
|
1237
|
-
* Start with thumbnails for better performance, then upgrade to full video using `requestPreviewUpgrade`.
|
|
1238
|
-
*/
|
|
1239
|
-
export declare type VideoPreview =
|
|
1240
|
-
| VideoPreviewLoading
|
|
1241
|
-
| VideoPreviewThumbnail
|
|
1242
|
-
| VideoPreviewUpgrading
|
|
1243
|
-
| VideoPreviewReady
|
|
1244
|
-
| VideoPreviewError;
|
|
1245
|
-
|
|
1246
|
-
/**
|
|
1247
|
-
* @beta
|
|
1248
|
-
* Video preview that failed to generate.
|
|
1249
|
-
*
|
|
1250
|
-
* Display an error state to the user.
|
|
1251
|
-
*/
|
|
1252
|
-
export declare interface VideoPreviewError extends BasePreview {
|
|
1253
|
-
kind: "video";
|
|
1254
|
-
status: "error";
|
|
1255
|
-
/**
|
|
1256
|
-
* @deprecated Use `message` instead.
|
|
1257
|
-
* Optional, user-facing error message to display in the preview UI.
|
|
1258
|
-
*/
|
|
1259
|
-
userFacingErrorMessage?: string;
|
|
1260
|
-
/**
|
|
1261
|
-
* The error message to display to the user.
|
|
1262
|
-
*/
|
|
1263
|
-
message: string;
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
/**
|
|
1267
|
-
* @beta
|
|
1268
|
-
* Video preview that is currently being generated.
|
|
1269
|
-
*
|
|
1270
|
-
* Display a loading state until the preview transitions to `"thumbnail"` or `"error"`.
|
|
1271
|
-
*/
|
|
1272
|
-
export declare interface VideoPreviewLoading extends BasePreview {
|
|
1273
|
-
kind: "video";
|
|
1274
|
-
status: "loading";
|
|
1275
|
-
/**
|
|
1276
|
-
* Video duration in milliseconds.
|
|
1277
|
-
*/
|
|
1278
|
-
durationMs?: number;
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
/**
|
|
1282
|
-
* @beta
|
|
1283
|
-
* Video preview with full video ready to play.
|
|
1284
|
-
*
|
|
1285
|
-
* Contains URLs for both the video and thumbnail.
|
|
1286
|
-
*/
|
|
1287
|
-
export declare interface VideoPreviewReady extends BasePreview {
|
|
1288
|
-
kind: "video";
|
|
1289
|
-
status: "ready";
|
|
1290
|
-
/**
|
|
1291
|
-
* Video format.
|
|
1292
|
-
*/
|
|
1293
|
-
format: "mp4";
|
|
1294
|
-
/**
|
|
1295
|
-
* URL to the full video.
|
|
1296
|
-
*
|
|
1297
|
-
* Use this URL in a video player.
|
|
1298
|
-
*/
|
|
1299
|
-
url: string;
|
|
1300
|
-
/**
|
|
1301
|
-
* Format of the thumbnail image.
|
|
1302
|
-
*/
|
|
1303
|
-
thumbnailFormat: "png" | "jpg";
|
|
1304
|
-
/**
|
|
1305
|
-
* URL to the thumbnail image.
|
|
1306
|
-
*
|
|
1307
|
-
* Can be used as a poster image for the video player.
|
|
1308
|
-
*/
|
|
1309
|
-
thumbnailUrl: string;
|
|
1310
|
-
/**
|
|
1311
|
-
* Video duration in milliseconds.
|
|
1312
|
-
*/
|
|
1313
|
-
durationMs?: number;
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
/**
|
|
1317
|
-
* @beta
|
|
1318
|
-
* Video preview with lightweight thumbnail available.
|
|
1319
|
-
*
|
|
1320
|
-
* This is the initial state for video previews. Show the thumbnail image
|
|
1321
|
-
* and call `requestPreviewUpgrade` when the user needs the full video.
|
|
1322
|
-
*/
|
|
1323
|
-
export declare interface VideoPreviewThumbnail extends BasePreview {
|
|
1324
|
-
kind: "video";
|
|
1325
|
-
status: "thumbnail";
|
|
1326
|
-
/**
|
|
1327
|
-
* Format of the thumbnail image.
|
|
1328
|
-
*/
|
|
1329
|
-
thumbnailFormat: "png" | "jpg";
|
|
1330
|
-
/**
|
|
1331
|
-
* URL to the thumbnail image.
|
|
1332
|
-
*
|
|
1333
|
-
* Display this lightweight image until full video is needed.
|
|
1334
|
-
*/
|
|
1335
|
-
thumbnailUrl: string;
|
|
1336
|
-
/**
|
|
1337
|
-
* Video duration in milliseconds.
|
|
1338
|
-
*/
|
|
1339
|
-
durationMs?: number;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
/**
|
|
1343
|
-
* @beta
|
|
1344
|
-
* Video preview that is being upgraded from thumbnail to full video.
|
|
1345
|
-
*
|
|
1346
|
-
* Display the thumbnail with a loading indicator until the video is ready.
|
|
1347
|
-
*/
|
|
1348
|
-
export declare interface VideoPreviewUpgrading extends BasePreview {
|
|
1349
|
-
kind: "video";
|
|
1350
|
-
status: "upgrading";
|
|
1351
|
-
/**
|
|
1352
|
-
* Format of the thumbnail image.
|
|
1353
|
-
*/
|
|
1354
|
-
thumbnailFormat: "png" | "jpg";
|
|
1355
|
-
/**
|
|
1356
|
-
* URL to the thumbnail image.
|
|
1357
|
-
*
|
|
1358
|
-
* Continue showing the thumbnail while the full video loads.
|
|
1359
|
-
*/
|
|
1360
|
-
thumbnailUrl: string;
|
|
1361
|
-
/**
|
|
1362
|
-
* Video duration in milliseconds.
|
|
1363
|
-
*/
|
|
1364
|
-
durationMs?: number;
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
/**
|
|
1368
|
-
* @beta
|
|
1369
|
-
* Video file requirements for a media slot.
|
|
1370
|
-
*
|
|
1371
|
-
* Specifies format, aspect ratio, duration, and size constraints for videos.
|
|
1372
|
-
*
|
|
1373
|
-
* @example Video requirements for YouTube
|
|
1374
|
-
* ```ts
|
|
1375
|
-
* const videoReq: VideoRequirement = {
|
|
1376
|
-
* format: 'mp4',
|
|
1377
|
-
* aspectRatio: { exact: 16/9 },
|
|
1378
|
-
* durationMs: { min: 1000, max: 600000 },
|
|
1379
|
-
* maxFileSizeMb: 100
|
|
1380
|
-
* };
|
|
1381
|
-
* ```
|
|
1382
|
-
*/
|
|
1383
|
-
export declare interface VideoRequirement extends BaseFileRequirement {
|
|
1384
|
-
/**
|
|
1385
|
-
* Supported video format.
|
|
1386
|
-
*/
|
|
1387
|
-
format: "mp4";
|
|
1388
|
-
/**
|
|
1389
|
-
* Aspect ratio constraint (width / height).
|
|
1390
|
-
*
|
|
1391
|
-
* Examples:
|
|
1392
|
-
* - `{ exact: 16/9 }`: Widescreen
|
|
1393
|
-
* - `{ exact: 9/16 }`: Vertical/Story format
|
|
1394
|
-
*/
|
|
1395
|
-
aspectRatio?: ValueRange;
|
|
1396
|
-
/**
|
|
1397
|
-
* Duration constraint in milliseconds.
|
|
1398
|
-
*
|
|
1399
|
-
* Examples:
|
|
1400
|
-
* - `{ max: 60000 }`: Maximum 60 seconds
|
|
1401
|
-
* - `{ min: 3000, max: 600000 }`: Between 3 seconds and 10 minutes
|
|
1402
|
-
*/
|
|
1403
|
-
durationMs?: ValueRange;
|
|
1404
|
-
/**
|
|
1405
|
-
* @deprecated use durationMs instead.
|
|
1406
|
-
*/
|
|
1407
|
-
duration?: ValueRange;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
export {};
|