@canva/intents 2.5.1-beta.1 → 2.6.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +40 -22
  2. package/asset/index.d.ts +1 -1
  3. package/content/index.d.ts +1801 -1
  4. package/data/index.d.ts +1229 -1
  5. package/design/index.d.ts +41 -1
  6. package/index.d.ts +3204 -1
  7. package/lib/cjs/sdk/intents/asset/index.js +1 -15
  8. package/lib/cjs/sdk/intents/fake/{create_beta.js → create.js} +6 -9
  9. package/lib/cjs/sdk/intents/index.js +4 -2
  10. package/lib/cjs/sdk/intents/test/index.js +14 -13
  11. package/lib/cjs/sdk/intents/version.js +2 -2
  12. package/lib/esm/sdk/intents/asset/index.js +1 -1
  13. package/lib/esm/sdk/intents/fake/{create_beta.js → create.js} +4 -7
  14. package/lib/esm/sdk/intents/index.js +3 -1
  15. package/lib/esm/sdk/intents/test/index.js +9 -1
  16. package/lib/esm/sdk/intents/version.js +2 -2
  17. package/package.json +23 -23
  18. package/test/index.d.ts +11 -1
  19. package/asset/beta.d.ts +0 -190
  20. package/beta.d.ts +0 -3272
  21. package/content/beta.d.ts +0 -1864
  22. package/data/beta.d.ts +0 -1229
  23. package/design/beta.d.ts +0 -41
  24. package/lib/cjs/sdk/intents/asset/beta.js +0 -13
  25. package/lib/cjs/sdk/intents/beta.js +0 -20
  26. package/lib/cjs/sdk/intents/content/beta.js +0 -20
  27. package/lib/cjs/sdk/intents/data/beta.js +0 -20
  28. package/lib/cjs/sdk/intents/design/beta.js +0 -20
  29. package/lib/cjs/sdk/intents/test/beta.js +0 -19
  30. package/lib/esm/sdk/intents/asset/beta.js +0 -3
  31. package/lib/esm/sdk/intents/beta.js +0 -3
  32. package/lib/esm/sdk/intents/content/beta.js +0 -3
  33. package/lib/esm/sdk/intents/data/beta.js +0 -3
  34. package/lib/esm/sdk/intents/design/beta.js +0 -3
  35. package/lib/esm/sdk/intents/test/beta.js +0 -9
  36. package/test/beta.d.ts +0 -11
package/beta.d.ts DELETED
@@ -1,3272 +0,0 @@
1
- /**
2
- * @beta
3
- * Cancelled response where the generation was not completed.
4
- * We use only 'cancelled' since we don't expect app developers to handle any statuses further (e.g. blocked, failed).
5
- * These will be handled on Canva's AI generation surface.
6
- */
7
- declare type AiContentCancelledResponse = {
8
- status: 'cancelled';
9
- };
10
-
11
- /**
12
- * @beta
13
- * Completed response for AI content generation.
14
- * The value is the AI content generated for the app.
15
- */
16
- declare type AiContentCompletedResponse = {
17
- status: 'completed';
18
- value: string;
19
- };
20
-
21
- /**
22
- * @beta
23
- * All possible AI content request types.
24
- */
25
- declare type AiContentRequest = SocialCaptionRequest;
26
-
27
- /**
28
- * @beta
29
- * All possible AI content response types.
30
- */
31
- declare type AiContentResponse = AiContentCompletedResponse | AiContentCancelledResponse;
32
-
33
- /**
34
- * @beta
35
- * All possible statuses for an AI content response.
36
- *
37
- */
38
- declare type AiContentResponseStatus = 'completed' | 'cancelled';
39
-
40
- /**
41
- * @beta
42
- * Possible content type for AI content generation.
43
- * Future types will be added here, e.g. 'hashtags'.
44
- */
45
- declare type AiContentType = 'social_caption';
46
-
47
- /**
48
- * @public
49
- * A disclosure identifying if the app generated this asset using AI.
50
- *
51
- * @remarks
52
- * Helps users make informed decisions about the content they interact with.
53
- *
54
- * AI is generally defined as any machine system that, given an objective, infers how to generate an output from an input.
55
- * Some examples include "generative AI", "large language models", and "machine learning".
56
- *
57
- * **App Generated**
58
- *
59
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
60
- * the app makes a request to a third-party service to do so.
61
- *
62
- * A significantly altered asset means the AI changes key information or details, such as
63
- * removing or replacing key components in the original content, which can include applying style transfer, or changing facial expressions.
64
- *
65
- * Label this asset as 'app_generated' under these conditions:
66
- *
67
- * The following is true:
68
- *
69
- * - The app generates the asset in response to a user's request (including past requests), for example, the asset is not from an asset library.
70
- *
71
- * And any of these conditions are also true:
72
- *
73
- * - The AI creates entirely new content from scratch.
74
- * - The AI introduces new multimedia, details, or creative elements not originally present.
75
- * - The AI removes and replaces the asset's key components.
76
- * - The AI alters the asset's appearance, meaning, or context in a way that conveys a different message than the original.
77
- *
78
- * **None**
79
- *
80
- * 'none' indicates when the asset wasn't generated by the app as a part of any user's specific request, for example, a third-party
81
- * request, or when the asset wasn't significantly altered by AI.
82
- */
83
- declare type AiDisclosure = 'app_generated' | 'none';
84
-
85
- declare type AllOrNone<T> = T | Never<T>;
86
-
87
- /**
88
- * @public
89
- * {@link GetDataTableError} indicating custom error occurred in the app's implementation.
90
- * This can be used to indicate specific issues that are not covered by other error types.
91
- */
92
- declare type AppError = {
93
- /**
94
- * A custom error occurred in your app.
95
- *
96
- * Return this for application-specific errors that don't fit
97
- * the other categories. Include a descriptive message explaining
98
- * the error to the user.
99
- */
100
- status: 'app_error';
101
- /**
102
- * Optional message explaining the error.
103
- */
104
- message?: string;
105
- };
106
-
107
- /**
108
- * @public
109
- * {@link PublishContentError} indicating a custom error occurred in your app's implementation.
110
- *
111
- * Return this for application-specific errors such as:
112
- *
113
- * - Validation failures
114
- * - Authentication errors
115
- * - Rate limiting
116
- * - Platform-specific restrictions
117
- *
118
- * @example Returning custom error with message
119
- * ```ts
120
- * if (userQuotaExceeded) {
121
- * return {
122
- * status: 'app_error',
123
- * message: 'You have reached your monthly publish limit. Please upgrade your plan.'
124
- * };
125
- * }
126
- * ```
127
- */
128
- declare type AppError_2 = {
129
- status: 'app_error';
130
- /**
131
- * (required) The raw error message, for logging purposes. It will not display in the UI.
132
- * To display custom error messages in the UI use `localizedMessageId`.
133
- *
134
- * This should typically be the javascript error.message or a REST JSON error message
135
- * body passed without modification.
136
- *
137
- * WARNING: Do not include personally identifiable information (PII) in this
138
- * message, such as names, emails, usernames, etc.
139
- */
140
- message: string;
141
- /**
142
- * (optional) Message ID of the translated error message that will be
143
- * displayed to the user. The message ID should be present and uploaded in
144
- * your translation file. If omitted, Canva will display a generic error
145
- * message.
146
- */
147
- localizedMessageId?: string;
148
- /** HTTP status code, if applicable */
149
- httpCode?: number;
150
- /**
151
- * Used only by app developer. Canva does not use this value. Use this to pass
152
- * additional information like JSON to your settings frame.
153
- */
154
- appDefinedPayload?: string;
155
- /**
156
- * (optional) Source of the error if it relates to a component on the Canva
157
- * UI. When present, the error may render near a relevant Canva component.
158
- * When omitted, the cause is considered unspecified or "generic".
159
- */
160
- errorCause?: ErrorCause;
161
- };
162
-
163
- /**
164
- * @public
165
- * {@link InvocationContext} indicating a custom error occurred during data refresh.
166
- * Triggered when getDataTable returned 'app_error' status.
167
- * UI should display the error message and help users recover.
168
- */
169
- declare type AppErrorInvocationContext = {
170
- /**
171
- * A custom error occurred during data refresh.
172
- *
173
- * This occurs when `getDataTable` returned 'app_error' during a refresh attempt.
174
- * Your UI should display the error message and help users recover from the specific
175
- * issue.
176
- */
177
- reason: 'app_error';
178
- /**
179
- * The data source reference that caused the error during refresh.
180
- */
181
- dataSourceRef?: DataSourceRef;
182
- /**
183
- * The error message to display to the user.
184
- */
185
- message?: string;
186
- };
187
-
188
- /**
189
- * @beta
190
- * Base interface for AI content requests.
191
- */
192
- declare type BaseAiContentRequest = {
193
- /**
194
- * The type of AI content generation which determines
195
- * the kind of content the AI will generate.
196
- */
197
- type: AiContentType;
198
- /**
199
- * If a current value exists in the field, the AI content generation
200
- * will be an edit-first experience.
201
- * i.e. When the user has already entered a value in the field, the AI will
202
- * generate a new value using the existing value as a starting point.
203
- */
204
- currentValue?: string;
205
- /**
206
- * The label chosen by the app developer for the field.
207
- * It will be used in the UI to customize the copy.
208
- * Required since it is essential context for the AI to generate the content.
209
- */
210
- fieldLabel: string;
211
- };
212
-
213
- /**
214
- * @public
215
- * Base file requirement interface.
216
- */
217
- declare interface BaseFileRequirement {
218
- /**
219
- * File format for this requirement.
220
- */
221
- format: PublishFileFormat;
222
-
223
- }
224
-
225
- /**
226
- * @public
227
- * Base interface for exported files.
228
- */
229
- declare interface BaseOutputFile {
230
- /**
231
- * File format.
232
- */
233
- format: PublishFileFormat;
234
- /**
235
- * URL to download the exported file.
236
- *
237
- * Your app should download from this URL and upload to your platform.
238
- */
239
- url: string;
240
- /**
241
- * Metadata about the source content used to create this exported file.
242
- */
243
- contentMetadata: ContentMetadata;
244
- }
245
-
246
- /**
247
- * @public
248
- * Base interface for all preview types.
249
- *
250
- * Contains common properties shared by all preview types.
251
- */
252
- declare interface BasePreview {
253
- /**
254
- * Unique identifier for this preview.
255
- *
256
- * Use this ID with `requestPreviewUpgrade` to upgrade video thumbnails.
257
- */
258
- id: string;
259
- /**
260
- * Type of media in this preview.
261
- */
262
- kind: PreviewKind;
263
- /**
264
- * Current state of the preview.
265
- */
266
- status: PreviewStatus;
267
- }
268
-
269
- /**
270
- * @public
271
- * Base metadata available for a selected media item in a media slot.
272
- *
273
- * Canva populates this when returning {@link OutputType} in Settings UI contexts.
274
- * Apps should not set this value.
275
- */
276
- declare interface BaseSelection {
277
- /**
278
- * Metadata about the source content represented by this selection.
279
- */
280
- selectionMetadata?: readonly SelectionMetadata[];
281
- }
282
-
283
- /**
284
- * @public
285
- * Cell containing a boolean value.
286
- *
287
- * @example Creating a boolean cell
288
- * ```ts
289
- * import type { BooleanDataTableCell } from '@canva/intents/data';
290
- *
291
- * const isActiveCell: BooleanDataTableCell = {
292
- * type: 'boolean',
293
- * value: true
294
- * };
295
- * ```
296
- *
297
- * @example Creating a boolean cell with false value
298
- * ```ts
299
- * import type { BooleanDataTableCell } from '@canva/intents/data';
300
- *
301
- * const isCompleteCell: BooleanDataTableCell = {
302
- * type: 'boolean',
303
- * value: false
304
- * };
305
- * ```
306
- *
307
- * @example Creating an empty boolean cell
308
- * ```ts
309
- * import type { BooleanDataTableCell } from '@canva/intents/data';
310
- *
311
- * const emptyBooleanCell: BooleanDataTableCell = {
312
- * type: 'boolean',
313
- * value: undefined
314
- * };
315
- * ```
316
- */
317
- declare type BooleanDataTableCell = {
318
- /**
319
- * Indicates this cell contains a boolean value.
320
- */
321
- type: 'boolean';
322
- /**
323
- * Boolean value (true or false).
324
- *
325
- * Use `undefined` for an empty cell.
326
- */
327
- value: boolean | undefined;
328
- };
329
-
330
- /**
331
- * @public
332
- * Configuration for a table column.
333
- */
334
- declare type ColumnConfig = {
335
- /**
336
- * Name for the column, displayed as header text.
337
- *
338
- * If `undefined`, the column will have no header text.
339
- */
340
- name: string | undefined;
341
- /**
342
- * Expected data type for cells in this column.
343
- *
344
- * Use a specific `DataType` for columns with consistent types,
345
- * or `'variant'` for columns that may contain mixed types.
346
- */
347
- type: DataType | 'variant';
348
- };
349
-
350
- declare namespace content {
351
- export {
352
- prepareContentPublisher,
353
- Disposer,
354
- PublishContentRequest,
355
- Preview,
356
- PreviewMedia,
357
- RenderPreviewUiInvocationContext,
358
- PublishPreviewUiInvocationContext,
359
- RenderPreviewUiRequest,
360
- ContentPublisherIntent,
361
- RenderSettingsUiInvocationContext,
362
- PublishSettingsUiInvocationContext,
363
- RenderSettingsUiRequest,
364
- OnContextChange,
365
- SettingsUiContext,
366
- PublishSettingsSettingsUiContext,
367
- PublishErrorSettingsUiContext,
368
- PublishErrorClearedSettingsUiContext,
369
- PublishError,
370
- PublishSettings,
371
- PublishRefValidityState,
372
- UpdatePublishSettingsResponse,
373
- UpdatePublishSettingsCompleted,
374
- PublishContentResponse,
375
- PublishContentCompleted,
376
- PostPublishAction,
377
- PostPublishActionRedirect,
378
- PublishContentError,
379
- RemoteRequestFailedError_2 as RemoteRequestFailedError,
380
- AppError_2 as AppError,
381
- ErrorCause,
382
- GetPublishConfigurationResponse,
383
- GetPublishConfigurationCompleted,
384
- GetPublishConfigurationError,
385
- OutputType,
386
- OutputTypeConfiguration,
387
- MediaSlot,
388
- ImageRequirement,
389
- VideoRequirement,
390
- DocumentRequirement,
391
- EmailRequirement,
392
- BaseSelection,
393
- MediaSelection,
394
- ImageSelection,
395
- VideoSelection,
396
- DocumentSelection,
397
- EmailSelection,
398
- SelectionMetadata,
399
- SelectionDesignMetadata,
400
- DocumentSize,
401
- PublishFileFormat,
402
- ExactValueRange,
403
- MinValueRange,
404
- MaxValueRange,
405
- MinMaxValueRange,
406
- ValueRange,
407
- DocumentPreview,
408
- DocumentPreviewLoading,
409
- DocumentPreviewThumbnail,
410
- DocumentPreviewError,
411
- ImagePreview,
412
- ImagePreviewLoading,
413
- ImagePreviewReady,
414
- ImagePreviewError,
415
- VideoPreview,
416
- VideoPreviewLoading,
417
- VideoPreviewThumbnail,
418
- VideoPreviewUpgrading,
419
- VideoPreviewReady,
420
- VideoPreviewError,
421
- EmailPreview,
422
- EmailPreviewLoading,
423
- EmailPreviewReady,
424
- EmailPreviewError,
425
- BasePreview,
426
- SizedPreview,
427
- PreviewKind,
428
- PreviewStatus,
429
- OutputMedia,
430
- OutputFile,
431
- ImageOutputFile,
432
- VideoOutputFile,
433
- BaseOutputFile,
434
- DocumentOutputFile,
435
- EmailOutputFile,
436
- ContentMetadata,
437
- DesignContentMetadata,
438
- OutputPageMetadata,
439
- AiContentType,
440
- SocialCaptionRequest,
441
- AiContentRequest,
442
- AiContentResponseStatus,
443
- AiContentCompletedResponse,
444
- AiContentCancelledResponse,
445
- AiContentResponse,
446
- RequestAiContent
447
- }
448
- }
449
- export { content }
450
-
451
- /**
452
- * @public
453
- * Metadata about the source content used to create an exported file.
454
- */
455
- declare type ContentMetadata = DesignContentMetadata;
456
-
457
- /**
458
- * @public
459
- * Main interface for implementing the ContentPublisher intent.
460
- *
461
- * Implementing the ContentPublisher intent enables apps to publish contents to external platforms.
462
- * This allows users to configure publish settings, preview their designs, and share with others.
463
- *
464
- * The publishing flow follows this process:
465
- *
466
- * 1. User initiates publish action
467
- * 2. Your app provides publish configuration via `getPublishConfiguration`
468
- * 3. User selects an output type
469
- * 4. Your app renders settings UI via `renderSettingsUi`
470
- * 5. Your app renders preview UI via `renderPreviewUi`
471
- * 6. User reviews settings and preview
472
- * 7. Your app publishes the content via `publishContent`
473
- */
474
- declare type ContentPublisherIntent = {
475
- /**
476
- * Provides the configuration for the publishing platform.
477
- *
478
- * This action is called when the user initiates the publish flow and needs to
479
- * select an output type for the target platform.
480
- *
481
- * Use this to define different publishing configurations for your platform,
482
- * such as social media posts, videos, or other output types.
483
- *
484
- * @returns A promise resolving to the publish configuration or an error
485
- *
486
- * @example Defining publish configuration for a social media platform
487
- * ```ts
488
- * import type { GetPublishConfigurationResponse } from '@canva/intents/content';
489
- *
490
- * async function getPublishConfiguration(): Promise<GetPublishConfigurationResponse> {
491
- * return {
492
- * status: 'completed',
493
- * outputTypes: [
494
- * {
495
- * id: 'instagram_post',
496
- * displayName: 'Instagram Post',
497
- * mediaSlots: [
498
- * {
499
- * id: 'main_image',
500
- * displayName: 'Post Image',
501
- * fileCount: { min: 1, max: 10 },
502
- * accepts: {
503
- * image: { format: 'jpg', aspectRatio: { min: 0.8, max: 1.91 } }
504
- * }
505
- * }
506
- * ]
507
- * }
508
- * ]
509
- * };
510
- * }
511
- * ```
512
- */
513
- getPublishConfiguration: () => Promise<GetPublishConfigurationResponse>;
514
-
515
- /**
516
- * Renders a user interface for configuring publish settings.
517
- *
518
- * This action is called after the user selects an output type. Your UI should
519
- * allow users to configure platform-specific settings such as captions, tags,
520
- * privacy settings, or publishing destinations.
521
- *
522
- * Use the `updatePublishSettings` callback to save user settings and validate them.
523
- * Settings are stored in the `publishRef` string (maximum 32KB).
524
- *
525
- * @param request - Configuration and callbacks for the publish settings UI.
526
- *
527
- * @example Rendering a settings UI with publish configuration
528
- * ```ts
529
- * import { createRoot } from 'react-dom/client';
530
- * import type { RenderSettingsUiRequest } from '@canva/intents/content';
531
- *
532
- * function renderSettingsUi(request: RenderSettingsUiRequest): void {
533
- * const SettingsUiApp = () => (
534
- * <AppUiProvider>
535
- * <SettingsUi request={request} />
536
- * </AppUiProvider>
537
- * );
538
- *
539
- * createRoot().render(<SettingsUiApp />)
540
- * }
541
- * ```
542
- */
543
- renderSettingsUi: (request: RenderSettingsUiRequest) => void;
544
- /**
545
- * Renders a user interface for previewing the content.
546
- *
547
- * This action is called after the settings UI is rendered. Your UI should display
548
- * a preview of how the content will appear on the target platform.
549
- *
550
- * Previews update dynamically as users modify their content or settings. For videos,
551
- * start with lightweight thumbnails and use `requestPreviewUpgrade` to load full
552
- * video previews on demand to optimize performance.
553
- *
554
- * @param request - Configuration and callbacks for the preview UI.
555
- *
556
- * @example Rendering a preview UI with video optimization
557
- * ```ts
558
- * import { createRoot } from 'react-dom/client';
559
- * import type { RenderPreviewUiRequest } from '@canva/intents/content';
560
- *
561
- * function renderPreviewUi(request: RenderPreviewUiRequest): void {
562
- * const PreviewUiApp = () => (
563
- * <AppUiProvider>
564
- * <PreviewUi request={request} />
565
- * </AppUiProvider>
566
- * );
567
- *
568
- * createRoot().render(<PreviewUiApp />)
569
- * }
570
- * ```
571
- */
572
- renderPreviewUi: (request: RenderPreviewUiRequest) => void;
573
- /**
574
- * Publishes the content to the external platform.
575
- *
576
- * This action is called when the user confirms the publish action after reviewing
577
- * settings and preview. Your implementation should send the exported files
578
- * to your platform's API.
579
- *
580
- * The `outputMedia` contains production-ready files that match the requirements
581
- * specified in your output types. The `publishRef` contains the user's settings
582
- * from the settings UI.
583
- *
584
- * @param request - Parameters for the publish operation.
585
- * @returns A promise resolving to either a successful result with the published content details or an error.
586
- *
587
- * @example Publishing content to an external platform
588
- * ```ts
589
- * import type { PublishContentRequest, PublishContentResponse } from '@canva/intents/content';
590
- *
591
- * async function publishContent(request: PublishContentRequest): Promise<PublishContentResponse> {
592
- * const { publishRef, outputType, outputMedia } = request;
593
- *
594
- * try {
595
- * // Parse settings from publishRef
596
- * const settings = publishRef ? JSON.parse(publishRef) : {};
597
- *
598
- * // Upload files to your platform
599
- * const uploadedFiles = await Promise.all(
600
- * outputMedia.flatMap(media =>
601
- * media.files.map(file => uploadFile(file.url))
602
- * )
603
- * );
604
- *
605
- * // Create post on your platform
606
- * const result = await createPost({
607
- * files: uploadedFiles,
608
- * caption: settings.caption
609
- * });
610
- *
611
- * return {
612
- * status: 'completed',
613
- * externalId: result.id,
614
- * externalUrl: result.url
615
- * };
616
- * } catch (error) {
617
- * return {
618
- * status: 'remote_request_failed'
619
- * };
620
- * }
621
- * }
622
- * ```
623
- */
624
- publishContent: (request: PublishContentRequest) => Promise<PublishContentResponse>;
625
-
626
- };
627
-
628
- declare namespace data {
629
- export {
630
- prepareDataConnector,
631
- DataConnectorIntent,
632
- GetDataTableRequest,
633
- RenderSelectionUiRequest,
634
- InvocationContext,
635
- GetDataTableResponse,
636
- GetDataTableCompleted,
637
- DataTableMetadata,
638
- GetDataTableError,
639
- UpdateDataRefResponse,
640
- DataSourceRef,
641
- DataTableLimit,
642
- DataType,
643
- DataTable,
644
- ColumnConfig,
645
- DataTableRow,
646
- DataTableCell,
647
- DateDataTableCell,
648
- StringDataTableCell,
649
- NumberDataTableCell,
650
- NumberCellMetadata,
651
- BooleanDataTableCell,
652
- MediaCollectionDataTableCell,
653
- DataTableImageUpload,
654
- DataTableVideoUpload
655
- }
656
- }
657
- export { data }
658
-
659
- /**
660
- * @public
661
- * Main interface for implementing the Data Connector intent.
662
- *
663
- * Implementing the Data Connector intent enables apps to import external data into Canva.
664
- * This allows users to select, preview, and refresh data from external sources.
665
- */
666
- declare type DataConnectorIntent = {
667
- /**
668
- * Gets structured data from an external source.
669
- *
670
- * This action is called in two scenarios:
671
- *
672
- * - During data selection to preview data before import (when {@link RenderSelectionUiRequest.updateDataRef} is called).
673
- * - When refreshing previously imported data (when the user requests an update).
674
- *
675
- * @param request - Parameters for the data fetching operation.
676
- * @returns A promise resolving to either a successful result with data or an error.
677
- *
678
- * @example Getting data from an external source
679
- * ```ts
680
- * import type { GetDataTableRequest, GetDataTableResponse } from '@canva/intents/data';
681
- *
682
- * async function getDataTable(request: GetDataTableRequest): Promise<GetDataTableResponse> {
683
- * const { dataSourceRef, limit, signal } = request;
684
- *
685
- * // Check if the operation has been aborted.
686
- * if (signal.aborted) {
687
- * return { status: 'app_error', message: 'The data fetch operation was cancelled.' };
688
- * }
689
- *
690
- * // ... data fetching logic using dataSourceRef, limit, and signal ...
691
- *
692
- * // Placeholder for a successful result.
693
- * return {
694
- * status: 'completed',
695
- * dataTable: { rows: [{ cells: [{ type: 'string', value: 'Fetched data' }] }] }
696
- * };
697
- * }
698
- * ```
699
- */
700
- getDataTable: (request: GetDataTableRequest) => Promise<GetDataTableResponse>;
701
-
702
- /**
703
- * Renders a user interface for selecting and configuring data from your external sources.
704
- *
705
- * @param request - Configuration and callbacks for the data selection UI.
706
- *
707
- * @example Rendering a data selection UI
708
- * ```ts
709
- * import type { RenderSelectionUiRequest } from '@canva/intents/data';
710
- *
711
- * async function renderSelectionUi(request: RenderSelectionUiRequest): Promise<void> {
712
- * // UI rendering logic.
713
- * // Example: if user selects data 'ref123'.
714
- * const selectedRef = { source: 'ref123', title: 'My Selected Table' };
715
- * try {
716
- * const result = await request.updateDataRef(selectedRef);
717
- * if (result.status === 'completed') {
718
- * console.log('Selection valid and preview updated.');
719
- * } else {
720
- * console.error('Selection error:', result.status);
721
- * }
722
- * } catch (error) {
723
- * console.error('An unexpected error occurred during data ref update:', error);
724
- * }
725
- * }
726
- * ```
727
- */
728
- renderSelectionUi: (request: RenderSelectionUiRequest) => void;
729
- };
730
-
731
- /**
732
- * @public
733
- * {@link InvocationContext} indicating initial data selection flow or edit of existing data.
734
- */
735
- declare type DataSelectionInvocationContext = {
736
- /**
737
- * Initial data selection or editing existing data.
738
- *
739
- * This is the standard flow when:
740
- *
741
- * - A user is selecting data for the first time
742
- * - A user is editing a previous selection
743
- *
744
- * If `dataSourceRef` is provided, this indicates an edit flow, and you should
745
- * pre-populate your UI with this selection.
746
- */
747
- reason: 'data_selection';
748
- /**
749
- * If dataSourceRef is provided, this is an edit of existing data flow and UI should be pre-populated.
750
- */
751
- dataSourceRef?: DataSourceRef;
752
- };
753
-
754
- /**
755
- * @public
756
- * Reference to an external data source that can be used to fetch data.
757
- * Created by Data Connector apps and stored by Canva for data refresh operations.
758
- *
759
- * You create this object in your data selection UI and pass it to the
760
- * `updateDataRef` callback. Canva stores this reference and uses it for
761
- * future data refresh operations.
762
- *
763
- * Maximum size: 5KB
764
- *
765
- * @example Defining how to locate external data
766
- * ```ts
767
- * const dataSourceRef: DataSourceRef = {
768
- * source: JSON.stringify({
769
- * reportId: "monthly_sales_001",
770
- * filters: { year: 2023, region: "NA" }
771
- * }),
772
- * title: "Monthly Sales Report (NA, 2023)"
773
- * };
774
- * ```
775
- */
776
- declare type DataSourceRef = {
777
- /**
778
- * Information needed to identify and retrieve data from your source.
779
- *
780
- * This string should contain all the information your app needs to
781
- * fetch the exact data selection later. Typically, this is a serialized
782
- * object with query parameters, identifiers, or filters.
783
- *
784
- * You are responsible for encoding and decoding this value appropriately.
785
- *
786
- * Maximum size: 5KB
787
- */
788
- source: string;
789
- /**
790
- * A human-readable description of the data reference.
791
- *
792
- * This title may be displayed to users in the Canva interface to help
793
- * them identify the data source.
794
- *
795
- * Maximum length: 255 characters
796
- */
797
- title?: string;
798
- };
799
-
800
- /**
801
- * @public
802
- * Structured tabular data for import into Canva.
803
- *
804
- * This format allows you to provide typed data with proper formatting
805
- * to ensure it displays correctly in Canva designs.
806
- *
807
- * @example Creating a data table
808
- * ```ts
809
- * import type { ColumnConfig, DataTableCell, DataTable, DataTableRow } from '@canva/intents/data';
810
- *
811
- * const myTable: DataTable = {
812
- * columnConfigs: [
813
- * { name: 'Name', type: 'string' },
814
- * { name: 'Age', type: 'number' },
815
- * { name: 'Subscribed', type: 'boolean' },
816
- * { name: 'Join Date', type: 'date' }
817
- * ],
818
- * rows: [
819
- * {
820
- * cells: [
821
- * { type: 'string', value: 'Alice' },
822
- * { type: 'number', value: 30 },
823
- * { type: 'boolean', value: true },
824
- * { type: 'date', value: Math.floor(new Date('2023-01-15').getTime() / 1000) }
825
- * ]
826
- * },
827
- * {
828
- * cells: [
829
- * { type: 'string', value: 'Bob' },
830
- * { type: 'number', value: 24 },
831
- * { type: 'boolean', value: false },
832
- * { type: 'date', value: Math.floor(new Date('2022-07-20').getTime() / 1000) }
833
- * ]
834
- * }
835
- * ]
836
- * };
837
- * ```
838
- */
839
- declare type DataTable = {
840
- /**
841
- * Column definitions with names and data types.
842
- *
843
- * These help Canva interpret and display your data correctly.
844
- */
845
- columnConfigs?: ColumnConfig[];
846
- /**
847
- * The data rows containing the actual values.
848
- *
849
- * Each row contains an array of cells with typed data values.
850
- */
851
- rows: DataTableRow[];
852
- };
853
-
854
- /**
855
- * @public
856
- * Generic type for table cells that resolves to a specific cell type.
857
- */
858
- declare type DataTableCell<T extends DataType = DataType> = {
859
- date: DateDataTableCell;
860
- string: StringDataTableCell;
861
- number: NumberDataTableCell;
862
- boolean: BooleanDataTableCell;
863
- media: MediaCollectionDataTableCell;
864
- }[T];
865
-
866
- /**
867
- * @public
868
- * Options for uploading an image asset to the user's private media library.
869
- */
870
- declare type DataTableImageUpload = Omit<ImageUploadOptions, 'type' | 'parentRef'> & {
871
- /**
872
- * Indicates this value contains options for image uploading.
873
- */
874
- type: 'image_upload';
875
- };
876
-
877
- /**
878
- * @public
879
- * Maximum dimensions for imported data tables.
880
- */
881
- declare type DataTableLimit = {
882
- /**
883
- * The maximum number of rows allowed.
884
- *
885
- * Your app should ensure data does not exceed this limit.
886
- */
887
- row: number;
888
- /**
889
- * The maximum number of columns allowed.
890
- *
891
- * Your app should ensure data does not exceed this limit.
892
- */
893
- column: number;
894
- };
895
-
896
- /**
897
- * @public
898
- * Metadata providing additional context about the imported data.
899
- */
900
- declare type DataTableMetadata = {
901
- /**
902
- * A human-readable description of the dataset.
903
- *
904
- * This description helps users understand what data they are importing.
905
- */
906
- description?: string;
907
- /**
908
- * Information about the data provider or source.
909
- */
910
- providerInfo?: {
911
- /**
912
- * Name of the data provider.
913
- */
914
- name: string;
915
- /**
916
- * URL to the provider's website or related resource.
917
- */
918
- url?: string;
919
- };
920
- };
921
-
922
- /**
923
- * @public
924
- * A row in the data table.
925
- *
926
- * @example Creating a single row of data cells
927
- * ```ts
928
- * import type { DataTableCell, DataTableRow } from '@canva/intents/data';
929
- *
930
- * const row: DataTableRow = {
931
- * cells: [
932
- * { type: 'string', value: 'Product Alpha' },
933
- * { type: 'number', value: 199.99 },
934
- * { type: 'boolean', value: true }
935
- * ]
936
- * };
937
- * ```
938
- */
939
- declare type DataTableRow = {
940
- /**
941
- * Array of cells containing the data values.
942
- *
943
- * Each cell must have a type that matches the corresponding column definition (if provided).
944
- */
945
- cells: DataTableCell<DataType>[];
946
- };
947
-
948
- /**
949
- * @public
950
- * Options for uploading a video asset to the user's private media library.
951
- */
952
- declare type DataTableVideoUpload = Omit<VideoUploadOptions, 'type' | 'parentRef'> & {
953
- /**
954
- * Indicates this value contains options for video uploading.
955
- */
956
- type: 'video_upload';
957
- };
958
-
959
- /**
960
- * @public
961
- * Data types supported for table cells.
962
- */
963
- declare type DataType = 'string' | 'number' | 'date' | 'boolean' | 'media';
964
-
965
- /**
966
- * @public
967
- * Cell containing a date value.
968
- *
969
- * @example Creating a date cell
970
- * ```ts
971
- * import type { DateDataTableCell } from '@canva/intents/data';
972
- *
973
- * const todayCell: DateDataTableCell = {
974
- * type: 'date',
975
- * value: Math.floor(Date.now() / 1000) // Unix timestamp in seconds
976
- * };
977
- *
978
- * const emptyDateCell: DateDataTableCell = {
979
- * type: 'date',
980
- * value: undefined
981
- * };
982
- * ```
983
- */
984
- declare type DateDataTableCell = {
985
- /**
986
- * Indicates this cell contains a date value.
987
- */
988
- type: 'date';
989
- /**
990
- * Unix timestamp in seconds representing the date.
991
- *
992
- * Use `undefined` for an empty cell.
993
- */
994
- value: number | undefined;
995
- };
996
-
997
- declare namespace design {
998
- export {
999
- prepareDesignEditor,
1000
- DesignEditorIntent
1001
- }
1002
- }
1003
- export { design }
1004
-
1005
- /**
1006
- * @public
1007
- * Metadata specific to design content.
1008
- */
1009
- declare interface DesignContentMetadata {
1010
- type: 'design';
1011
- /**
1012
- * A signed JWT token containing the design id
1013
- */
1014
- designToken: string;
1015
- /**
1016
- * The user given title of the design
1017
- */
1018
- title: string | undefined;
1019
- /**
1020
- * The pages that make up the exported metadata
1021
- */
1022
- pages: OutputPageMetadata[];
1023
-
1024
- }
1025
-
1026
- /**
1027
- * @public
1028
- *
1029
- * Main interface for implementing the DesignEditor intent.
1030
- *
1031
- * Implementing the DesignEditor Intent enables apps to assist users in editing designs,
1032
- * by presenting interactive and creative tooling alongside the Canva design surface.
1033
- */
1034
- declare type DesignEditorIntent = {
1035
- /**
1036
- * Renders the UI containing the app’s functionality.
1037
- *
1038
- * @example
1039
- * ```tsx
1040
- * function render() {
1041
- * // render your UI using your preferred framework
1042
- * }
1043
- * ```
1044
- */
1045
- render: () => void;
1046
- };
1047
-
1048
- /**
1049
- * @public
1050
- * A set of dimensions.
1051
- */
1052
- declare type Dimensions = {
1053
- /**
1054
- * A width, in pixels.
1055
- */
1056
- width: number;
1057
- /**
1058
- * A height, in pixels.
1059
- */
1060
- height: number;
1061
- };
1062
-
1063
- /**
1064
- * @public
1065
- * A function that can be called to dispose of a callback.
1066
- */
1067
- declare type Disposer = () => void;
1068
-
1069
- /**
1070
- * @public
1071
- * Exported PDF file ready for publishing.
1072
- *
1073
- * Contains the final PDF document that should be uploaded to your platform.
1074
- * The document format is `pdf_standard` and the file is ready to use.
1075
- */
1076
- declare type DocumentOutputFile = BaseOutputFile;
1077
-
1078
- /**
1079
- * @public
1080
- * Document preview in various states.
1081
- *
1082
- * Documents transition through states: `"loading"` → `"thumbnail"`.
1083
- * Start with a lightweight thumbnail of the first page for quick preview rendering.
1084
- */
1085
- declare type DocumentPreview = DocumentPreviewLoading | DocumentPreviewThumbnail | DocumentPreviewError;
1086
-
1087
- /**
1088
- * @public
1089
- * Document preview that failed to generate.
1090
- *
1091
- * Display an error state to the user.
1092
- */
1093
- declare interface DocumentPreviewError extends SizedPreview {
1094
- kind: 'document';
1095
- status: 'error';
1096
- /**
1097
- * The error message to display to the user.
1098
- */
1099
- message: string;
1100
- }
1101
-
1102
- /**
1103
- * @public
1104
- * Document preview that is currently being generated.
1105
- *
1106
- * Display a loading state until the preview transitions to `"thumbnail"` or `"error"`.
1107
- */
1108
- declare interface DocumentPreviewLoading extends SizedPreview {
1109
- kind: 'document';
1110
- status: 'loading';
1111
- }
1112
-
1113
- /**
1114
- * @public
1115
- * Document preview with first page thumbnail available.
1116
- *
1117
- * This is the initial state for document previews. Show the thumbnail image
1118
- * of the first page along with the page count to give users a preview of
1119
- * the document before publishing.
1120
- */
1121
- declare interface DocumentPreviewThumbnail extends SizedPreview {
1122
- kind: 'document';
1123
- status: 'thumbnail';
1124
- /**
1125
- * Format of the thumbnail image.
1126
- */
1127
- thumbnailFormat: 'png' | 'jpg';
1128
- /**
1129
- * URL to the first page thumbnail.
1130
- *
1131
- * Display this lightweight image to preview the document content.
1132
- */
1133
- thumbnailUrl: string;
1134
- }
1135
-
1136
- /**
1137
- * @public
1138
- * Document file requirements for a media slot.
1139
- *
1140
- * Note: Document output types use image previews (PNG thumbnails) in the preview UI.
1141
- * The actual document file is only generated for the final output in OutputMedia.
1142
- *
1143
- * @example Document requirements
1144
- * ```ts
1145
- * const documentReq: DocumentRequirement = {
1146
- * format: 'pdf_standard',
1147
- * size: 'a4',
1148
- * };
1149
- * ```
1150
- */
1151
- declare interface DocumentRequirement extends BaseFileRequirement {
1152
- /**
1153
- * Supported document export format.
1154
- * Currently supports PDF standard format.
1155
- */
1156
- format: 'pdf_standard';
1157
- /**
1158
- * The document size of the export file.
1159
- */
1160
- size: DocumentSize;
1161
- }
1162
-
1163
- /**
1164
- * @public
1165
- * Selection metadata for a document media item.
1166
- */
1167
- declare interface DocumentSelection extends BaseSelection {
1168
- kind: 'document';
1169
- }
1170
-
1171
- /**
1172
- * @public
1173
- * Document size for document exports.
1174
- */
1175
- declare type DocumentSize = 'a4' | 'a3' | 'letter' | 'legal';
1176
-
1177
- /**
1178
- * @public
1179
- * Exported email file ready for publishing.
1180
- *
1181
- * Contains the final HTML bundle that should be uploaded to your platform.
1182
- */
1183
- declare type EmailOutputFile = BaseOutputFile;
1184
-
1185
- /**
1186
- * @public
1187
- * Email preview in various states.
1188
- *
1189
- * Display a loading state until the preview transitions to `"ready"` or `"error"`.
1190
- */
1191
- declare type EmailPreview = EmailPreviewLoading | EmailPreviewReady | EmailPreviewError;
1192
-
1193
- /**
1194
- * @public
1195
- * Email preview in an error state.
1196
- *
1197
- * Display an error state to the user.
1198
- */
1199
- declare interface EmailPreviewError extends BasePreview {
1200
- kind: 'email';
1201
- status: 'error';
1202
- message: string;
1203
- }
1204
-
1205
- /**
1206
- * @public
1207
- * Email preview in a loading state.
1208
- *
1209
- * Display a loading spinner until the preview transitions to `"ready"` or `"error"`.
1210
- */
1211
- declare interface EmailPreviewLoading extends BasePreview {
1212
- kind: 'email';
1213
- status: 'loading';
1214
- }
1215
-
1216
- /**
1217
- * @public
1218
- * Email preview in a ready state.
1219
- *
1220
- * Display the email preview.
1221
- */
1222
- declare interface EmailPreviewReady extends BasePreview {
1223
- kind: 'email';
1224
- status: 'ready';
1225
- /**
1226
- * URL to the single html file that represents the email.
1227
- */
1228
- url: string;
1229
- }
1230
-
1231
- /**
1232
- * @public
1233
- * Email file requirements for a media slot, currently only supports HTML bundle format.
1234
- *
1235
- * Note: Email output types use html_standalone previews in the preview UI.
1236
- * The actual email file is only generated for the final output in OutputMedia.
1237
- *
1238
- * @example Email bundle requirements
1239
- * ```ts
1240
- * const emailReq: EmailRequirement = {
1241
- * format: 'html_bundle',
1242
- * };
1243
- * ```
1244
- */
1245
- declare interface EmailRequirement extends BaseFileRequirement {
1246
- format: 'html_bundle' | 'html_standalone';
1247
- }
1248
-
1249
- /**
1250
- * @public
1251
- * Selection metadata for an email media item.
1252
- */
1253
- declare interface EmailSelection extends BaseSelection {
1254
- kind: 'email';
1255
- }
1256
-
1257
- /**
1258
- * @public
1259
- *
1260
- * The cause of an error
1261
- */
1262
- declare type ErrorCause = 'invalid_selection' | 'invalid_format';
1263
-
1264
- /**
1265
- * @public
1266
- * Exact value range constraint.
1267
- * @example Exact value range
1268
- * ```ts
1269
- * const exactValue: ValueRange = { exact: 1 }; // Must be exactly 1
1270
- * ```
1271
- */
1272
- declare type ExactValueRange = {
1273
- exact: number;
1274
- };
1275
-
1276
- /**
1277
- * @public
1278
- * Successful result from `getDataTable` action.
1279
- */
1280
- declare type GetDataTableCompleted = {
1281
- /**
1282
- * Indicates the operation completed successfully
1283
- */
1284
- status: 'completed';
1285
- /**
1286
- * The fetched data formatted as a data table.
1287
- */
1288
- dataTable: DataTable;
1289
- /**
1290
- * Optional metadata providing additional context about the data.
1291
- */
1292
- metadata?: DataTableMetadata;
1293
- };
1294
-
1295
- /**
1296
- * @public
1297
- * Error results that can be returned from `getDataTable` method.
1298
- */
1299
- declare type GetDataTableError = OutdatedSourceRefError | RemoteRequestFailedError | AppError;
1300
-
1301
- /**
1302
- * @public
1303
- * Parameters for the getDataTable action.
1304
- */
1305
- declare type GetDataTableRequest = {
1306
- /**
1307
- * Reference to the data source to fetch.
1308
- *
1309
- * This contains the information needed to identify and retrieve the specific data
1310
- * that was previously selected by the user.
1311
- *
1312
- * Use this to query your external data service.
1313
- */
1314
- dataSourceRef: DataSourceRef;
1315
- /**
1316
- * Maximum row and column limits for the imported data.
1317
- *
1318
- * Your app must ensure the returned data does not exceed these limits.
1319
- *
1320
- * If the requested data would exceed these limits, either:
1321
- *
1322
- * - Truncate the data to fit within limits, or
1323
- * - Return a 'data_table_limit_exceeded' error
1324
- */
1325
- limit: DataTableLimit;
1326
- /**
1327
- * Standard DOM AbortSignal for cancellation support.
1328
- *
1329
- * Your app should monitor this signal and abort any ongoing operations if it becomes aborted.
1330
- */
1331
- signal: AbortSignal;
1332
- };
1333
-
1334
- /**
1335
- * @public
1336
- * Result returned from the `getDataTable` action.
1337
- */
1338
- declare type GetDataTableResponse = GetDataTableCompleted | GetDataTableError;
1339
-
1340
- /**
1341
- * @public
1342
- * Successful response from getting publish configuration.
1343
- */
1344
- declare type GetPublishConfigurationCompleted = {
1345
- status: 'completed';
1346
- /**
1347
- * Array of available output types for your platform.
1348
- *
1349
- * Define different output types for various content formats that
1350
- * your platform supports (e.g., posts, stories, videos).
1351
- */
1352
- outputTypes: OutputTypeConfiguration[];
1353
- };
1354
-
1355
- /**
1356
- * @public
1357
- * {@link GetPublishConfigurationError} error indicating a custom error occurred.
1358
- */
1359
- declare type GetPublishConfigurationError = AppError_2;
1360
-
1361
- /**
1362
- * @public
1363
- * Response from getting publish configuration.
1364
- */
1365
- declare type GetPublishConfigurationResponse = GetPublishConfigurationCompleted | GetPublishConfigurationError;
1366
-
1367
- /**
1368
- * @public
1369
- * The MIME type of an image file that's supported by Canva's backend.
1370
- */
1371
- declare type ImageMimeType = 'image/jpeg' | 'image/heic' | 'image/png' | 'image/svg+xml' | 'image/webp' | 'image/tiff';
1372
-
1373
- /**
1374
- * @public
1375
- * Exported image file ready for publishing.
1376
- */
1377
- declare interface ImageOutputFile extends BaseOutputFile {
1378
- /**
1379
- * Width of the image in pixels.
1380
- */
1381
- widthPx: number;
1382
- /**
1383
- * Height of the image in pixels.
1384
- */
1385
- heightPx: number;
1386
- }
1387
-
1388
- /**
1389
- * @public
1390
- * Image preview in various states.
1391
- */
1392
- declare type ImagePreview = ImagePreviewLoading | ImagePreviewReady | ImagePreviewError;
1393
-
1394
- /**
1395
- * @public
1396
- * Image preview that failed to generate.
1397
- *
1398
- * Display an error state to the user.
1399
- */
1400
- declare interface ImagePreviewError extends SizedPreview {
1401
- kind: 'image';
1402
- status: 'error';
1403
-
1404
- /**
1405
- * The error message to display to the user.
1406
- */
1407
- message: string;
1408
- }
1409
-
1410
- /**
1411
- * @public
1412
- * Image preview that is currently being generated.
1413
- *
1414
- * Display a loading state until the preview transitions to `"ready"` or `"error"`.
1415
- */
1416
- declare interface ImagePreviewLoading extends SizedPreview {
1417
- kind: 'image';
1418
- status: 'loading';
1419
- }
1420
-
1421
- /**
1422
- * @public
1423
- * Image preview that is ready to display.
1424
- *
1425
- * Contains the URL to the preview image.
1426
- */
1427
- declare interface ImagePreviewReady extends SizedPreview {
1428
- kind: 'image';
1429
- status: 'ready';
1430
- /**
1431
- * Image format of the preview.
1432
- */
1433
- format: 'png' | 'jpg';
1434
- /**
1435
- * URL to the preview image.
1436
- *
1437
- * Use this URL to display the preview to users.
1438
- */
1439
- url: string;
1440
- }
1441
-
1442
- /**
1443
- * @public
1444
- * A unique identifier that points to an image asset in Canva's backend.
1445
- */
1446
- declare type ImageRef = string & {
1447
- __imageRef: never;
1448
- };
1449
-
1450
- /**
1451
- * @public
1452
- * Image file requirements for a media slot.
1453
- *
1454
- * Specifies format, aspect ratio, and size constraints for images.
1455
- *
1456
- * @example Image requirements for social media post
1457
- * ```ts
1458
- * const imageReq: ImageRequirement = {
1459
- * format: 'jpg',
1460
- * aspectRatio: { min: 0.8, max: 1.91 },
1461
- * };
1462
- * ```
1463
- */
1464
- declare type ImageRequirement = BaseFileRequirement & {
1465
- /**
1466
- * Aspect ratio constraint (width / height).
1467
- *
1468
- * Examples:
1469
- * - `{ exact: 16/9 }`: Widescreen (16:9)
1470
- * - `{ min: 0.8, max: 1.91 }`: Instagram range
1471
- */
1472
- aspectRatio?: ValueRange;
1473
- } & ({
1474
- /**
1475
- * JPG image export.
1476
- */
1477
- format: 'jpg';
1478
- } | {
1479
- /**
1480
- * PNG image export.
1481
- */
1482
- format: 'png';
1483
- /**
1484
- * Controls transparent-background support for PNG exports.
1485
- *
1486
- * @remarks
1487
- * - Only applies when `format` is `'png'`
1488
- * - If omitted or `false`, Canva exports a standard opaque PNG
1489
- * - If `true`, Canva shows a `Transparent background` toggle in the publish flow
1490
- * - Users without the required Canva entitlement may be prompted to upgrade before a transparent export is produced
1491
- *
1492
- * @defaultValue false
1493
- */
1494
- allowTransparentBackground?: boolean;
1495
- });
1496
-
1497
- /**
1498
- * @public
1499
- * Selection metadata for an image media item.
1500
- */
1501
- declare interface ImageSelection extends BaseSelection {
1502
- kind: 'image';
1503
- }
1504
-
1505
- /**
1506
- * @public
1507
- * Options for uploading an image asset to the user's private media library.
1508
- */
1509
- declare type ImageUploadOptions = {
1510
- /**
1511
- * The type of asset.
1512
- */
1513
- type: 'image';
1514
- /**
1515
- * A human-readable name for the image asset.
1516
- *
1517
- * @remarks
1518
- * This name is displayed in the user's media library and helps users identify
1519
- * and find the asset later. If not provided, Canva will generate a name based
1520
- * on the asset's URL or a unique identifier.
1521
- *
1522
- * Requirements:
1523
- * - Minimum length: 1 character (empty strings are not allowed)
1524
- * - Maximum length: 255 characters
1525
- */
1526
- name?: string;
1527
- /**
1528
- * The ref of the original asset from which this new asset was derived.
1529
- *
1530
- * @remarks
1531
- * For example, if an app applies an effect to an image, `parentRef` should contain the ref of the original image.
1532
- */
1533
- parentRef?: ImageRef;
1534
- /**
1535
- * The URL of the image file to upload.
1536
- * This can be an external URL or a data URL.
1537
- *
1538
- * @remarks
1539
- * Requirements for external URLs:
1540
- *
1541
- * - Must use HTTPS
1542
- * - Must return a `200` status code
1543
- * - `Content-Type` must match the file's MIME type
1544
- * - Must be publicly accessible (i.e. not a localhost URL)
1545
- * - Must not redirect
1546
- * - Must not contain an IP address
1547
- * - Maximum length: 4096 characters
1548
- * - Must not contain whitespace
1549
- * - Must not contain these characters: `>`, `<`, `{`, `}`, `^`, backticks
1550
- * - Maximum file size: 50MB
1551
- *
1552
- * Requirements for data URLs:
1553
- *
1554
- * - Must include `;base64` for base64-encoded data
1555
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
1556
- *
1557
- * Requirements for SVGs:
1558
- *
1559
- * - Disallowed elements:
1560
- * - `a`
1561
- * - `altglyph`
1562
- * - `altglyphdef`
1563
- * - `altglyphitem`
1564
- * - `animate`
1565
- * - `animatemotion`
1566
- * - `animatetransform`
1567
- * - `cursor`
1568
- * - `discard`
1569
- * - `font`
1570
- * - `font-face`
1571
- * - `font-face-format`
1572
- * - `font-face-name`
1573
- * - `font-face-src`
1574
- * - `font-face-uri`
1575
- * - `foreignobject`
1576
- * - `glyph`
1577
- * - `glyphref`
1578
- * - `missing-glyph`
1579
- * - `mpath`
1580
- * - `script`
1581
- * - `set`
1582
- * - `switch`
1583
- * - `tref`
1584
- * - Disallowed attributes:
1585
- * - `crossorigin`
1586
- * - `lang`
1587
- * - `media`
1588
- * - `onload`
1589
- * - `ping`
1590
- * - `referrerpolicy`
1591
- * - `rel`
1592
- * - `rendering-intent`
1593
- * - `requiredextensions`
1594
- * - `requiredfeatures`
1595
- * - `systemlanguage`
1596
- * - `tabindex`
1597
- * - `transform-origin`
1598
- * - `unicode`
1599
- * - `vector-effect`
1600
- * - The `href` attribute of an `image` element only supports data URLs for PNG and JPEG images.
1601
- * - The URL in the `href` attribute must not point to a location outside of the SVG.
1602
- * - The `style` attribute must not use the `mix-blend-mode` property.
1603
- */
1604
- url: string;
1605
- /**
1606
- * The MIME type of the image file.
1607
- */
1608
- mimeType: ImageMimeType;
1609
- /**
1610
- * The URL of a thumbnail image to display while the image is queued for upload.
1611
- * This can be an external URL or a data URL.
1612
- *
1613
- * @remarks
1614
- * Requirements for external URLs:
1615
- *
1616
- * - Must use HTTPS
1617
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
1618
- * - Must be a PNG, JPEG, or SVG file
1619
- * - Maximum length: 4096 characters
1620
- *
1621
- * Requirements for data URLs:
1622
- *
1623
- * - Must include `;base64` for base64-encoded data
1624
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
1625
- */
1626
- thumbnailUrl: string;
1627
- /**
1628
- * A disclosure identifying if the app generated this image using AI
1629
- *
1630
- * @remarks
1631
- * Helps users make informed decisions about the content they interact with.
1632
- * See {@link AiDisclosure} for the full definition.
1633
- *
1634
- * **App Generated**
1635
- *
1636
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
1637
- * the app requests a third-party service to take similar action on an image using AI.
1638
- *
1639
- * Required for the following cases (this list is not exhaustive):
1640
- * | Case | Reason |
1641
- * | -- | -- |
1642
- * | AI generates a new image from scratch | Creates new creative content |
1643
- * | AI changes the style of the image e.g. makes it cartoon | Significantly alters the style |
1644
- * | AI removes an object and replaces it with new content | Creates new creative content |
1645
- * | AI changes the facial expression of a person in an image | Can alter content's original meaning |
1646
- * | AI composites multiple images together | Significantly alters context |
1647
- * | AI expands an image by generating new content to fill the edges | Creates new creative content |
1648
- * | AI replaces background by generating new content | Creates new creative content |
1649
- *
1650
- * **None**
1651
- *
1652
- * 'none' indicates when the app doesn't create or significantly alter an asset using AI, or as a part of a request
1653
- * to third-party hosted content.
1654
- *
1655
- * Required for the following cases (this list is not exhaustive):
1656
- * | Case | Reason |
1657
- * | -- | -- |
1658
- * | Asset comes from an asset library | Didn't generate the asset itself |
1659
- * | AI corrects red eyes | A minor correction |
1660
- * | AI removes background without replacement | Doesn't change original meaning by itself |
1661
- * | AI changes the color of an object in an image | Doesn't change original meaning by itself |
1662
- * | AI detects image defects and suggests manual fixes | Didn't change the asset itself |
1663
- * | AI adjusts brightness and contrast on an image | Doesn't change original meaning by itself |
1664
- * | AI upscales an image | Doesn't change original meaning by itself |
1665
- */
1666
- aiDisclosure: AiDisclosure;
1667
-
1668
- } & AllOrNone<Dimensions>;
1669
-
1670
- /**
1671
- * @public
1672
- * Information explaining why the data selection UI was launched.
1673
- */
1674
- declare type InvocationContext = DataSelectionInvocationContext | OutdatedSourceRefInvocationContext | AppErrorInvocationContext;
1675
-
1676
- /**
1677
- * @public
1678
- * Maximum value range constraint.
1679
- * @example Maximum value range
1680
- * ```ts
1681
- * const maxValue: ValueRange = { max: 10 }; // At most 10
1682
- * ```
1683
- */
1684
- declare type MaxValueRange = {
1685
- max: number;
1686
- };
1687
-
1688
- /**
1689
- * @public
1690
- * Cell containing a media collection (images) value.
1691
- *
1692
- * @example Creating a media cell with an image
1693
- * ```ts
1694
- * import type { MediaCollectionDataTableCell } from '@canva/intents/data';
1695
- *
1696
- * const mediaCell: MediaCollectionDataTableCell = {
1697
- * type: 'media',
1698
- * value: [{
1699
- * type: 'image_upload',
1700
- * url: 'https://www.canva.dev/example-assets/image-import/image.jpg',
1701
- * mimeType: 'image/jpeg',
1702
- * thumbnailUrl: 'https://www.canva.dev/example-assets/image-import/thumbnail.jpg',
1703
- * aiDisclosure: 'none'
1704
- * }]
1705
- * };
1706
- * ```
1707
- *
1708
- * @example Creating an empty media cell
1709
- * ```ts
1710
- * import type { MediaCollectionDataTableCell } from '@canva/intents/data';
1711
- *
1712
- * const emptyMediaCell: MediaCollectionDataTableCell = {
1713
- * type: 'media',
1714
- * value: []
1715
- * };
1716
- * ```
1717
- */
1718
- declare type MediaCollectionDataTableCell = {
1719
- /**
1720
- * Indicates this cell contains a media collection.
1721
- */
1722
- type: 'media';
1723
- /**
1724
- * Media collection values.
1725
- *
1726
- * Use empty array for an empty cell.
1727
- */
1728
- value: (DataTableImageUpload | DataTableVideoUpload)[];
1729
- };
1730
-
1731
- /**
1732
- * @public
1733
- * Metadata about a selected media item in a media slot.
1734
- */
1735
- declare type MediaSelection = ImageSelection | VideoSelection | DocumentSelection | EmailSelection;
1736
-
1737
- /**
1738
- * @public
1739
- * Configuration for a media slot within an output type.
1740
- *
1741
- * Defines what type of media is accepted, requirements, and constraints.
1742
- *
1743
- * @example Image slot with aspect ratio requirements
1744
- * ```ts
1745
- * const thumbnailSlot: MediaSlot = {
1746
- * id: 'thumbnail',
1747
- * displayName: 'Video Thumbnail',
1748
- * fileCount: { exact: 1 },
1749
- * accepts: {
1750
- * image: {
1751
- * format: 'jpg',
1752
- * aspectRatio: { exact: 16/9 },
1753
- * }
1754
- * }
1755
- * };
1756
- * ```
1757
- */
1758
- declare type MediaSlot = {
1759
- /**
1760
- * Unique identifier for this media slot within the output type.
1761
- */
1762
- id: string;
1763
- /**
1764
- * User-facing name for this media slot.
1765
- *
1766
- * Examples: `"Post Image"`, `"Video Thumbnail"`, `"Main Video"`.
1767
- */
1768
- displayName: string;
1769
- /**
1770
- * Number of files accepted in this slot.
1771
- *
1772
- * Use this to specify single or multiple file requirements.
1773
- * Examples:
1774
- * - `{ exact: 1 }`: Exactly one file
1775
- * - `{ min: 1, max: 10 }`: Between 1 and 10 files
1776
- * - undefined: Any number of files
1777
- */
1778
- fileCount?: ValueRange;
1779
- /**
1780
- * File type requirements for this slot.
1781
- *
1782
- * Note the following behavior:
1783
- *
1784
- * - Provide at least one of `image` or `video`
1785
- * - If both are provided, files for this slot may be either images or videos; each file
1786
- * must satisfy the corresponding requirement for its media type
1787
- * - To restrict the slot to a single media type, provide only that requirement
1788
- * - `fileCount` applies across all files accepted by the slot regardless of media type
1789
- * - Document output types will show image previews (PNG thumbnail) in preview UI
1790
- */
1791
- accepts: {
1792
- image?: ImageRequirement;
1793
- video?: VideoRequirement;
1794
- document?: DocumentRequirement;
1795
- /**
1796
- * Email output types will show a single html file (canva hosted assets) preview in preview UI
1797
- */
1798
- email?: EmailRequirement;
1799
- };
1800
- /**
1801
- * @public
1802
- * Current selection for this slot.
1803
- *
1804
- * Canva populates this only when returning {@link OutputType} in Settings UI contexts
1805
- * such as {@link RenderSettingsUiInvocationContext} and {@link PublishSettingsSettingsUiContext}.
1806
- * Apps should not set this value when defining output types in
1807
- * {@link ContentPublisherIntent.getPublishConfiguration}.
1808
- */
1809
- readonly selection?: readonly MediaSelection[];
1810
- };
1811
-
1812
- /**
1813
- * @public
1814
- * Minimum and maximum value range constraint.
1815
- * Ranges are inclusive `(min ≤ value ≤ max)`.
1816
- * @example Minimum and maximum value range
1817
- * ```ts
1818
- * const minMaxValue: ValueRange = { min: 1, max: 10 }; // Between 1 and 10
1819
- * ```
1820
- */
1821
- declare type MinMaxValueRange = {
1822
- min: number;
1823
- max: number;
1824
- };
1825
-
1826
- /**
1827
- * @public
1828
- * Minimum value range constraint.
1829
- * @example Minimum value range
1830
- * ```ts
1831
- * const minValue: ValueRange = { min: 3 }; // At least 3
1832
- * ```
1833
- */
1834
- declare type MinValueRange = {
1835
- min: number;
1836
- };
1837
-
1838
- declare type Never<T> = {
1839
- [key in keyof T]?: never;
1840
- };
1841
-
1842
- /**
1843
- * @public
1844
- * Formatting metadata for number cells.
1845
- *
1846
- * @example Formatting as currency
1847
- * ```ts
1848
- * import type { NumberDataTableCell } from '@canva/intents/data';
1849
- *
1850
- * const currencyCell: NumberDataTableCell = {
1851
- * type: 'number',
1852
- * value: 1234.57,
1853
- * metadata: { formatting: '[$$]#,##0.00' }
1854
- * };
1855
- * ```
1856
- *
1857
- * @example Formatting as a percentage
1858
- * ```ts
1859
- * import type { NumberDataTableCell } from '@canva/intents/data';
1860
- *
1861
- * const percentCell: NumberDataTableCell = {
1862
- * type: 'number',
1863
- * value: 0.1234,
1864
- * metadata: { formatting: '0.00%' }
1865
- * };
1866
- * ```
1867
- *
1868
- * @example Applying a thousands separator
1869
- * ```ts
1870
- * import type { NumberDataTableCell } from '@canva/intents/data';
1871
- *
1872
- * const largeNumberCell: NumberDataTableCell = {
1873
- * type: 'number',
1874
- * value: 1234567.89234,
1875
- * metadata: { formatting: '#,##0.00' }
1876
- * };
1877
- * ```
1878
- */
1879
- declare type NumberCellMetadata = {
1880
- /**
1881
- * Formatting pattern using Office Open XML Format.
1882
- *
1883
- * These patterns control how numbers are displayed to users,
1884
- * including currency symbols, decimal places, and separators.
1885
- */
1886
- formatting?: string;
1887
- };
1888
-
1889
- /**
1890
- * @public
1891
- * Cell containing a numeric value.
1892
- *
1893
- * @example Creating a number cell
1894
- * ```ts
1895
- * import type { NumberCellMetadata, NumberDataTableCell } from '@canva/intents/data';
1896
- *
1897
- * const priceCell: NumberDataTableCell = {
1898
- * type: 'number',
1899
- * value: 29.99,
1900
- * metadata: { formatting: '[$$]#,##0.00' }
1901
- * };
1902
- *
1903
- * const quantityCell: NumberDataTableCell = {
1904
- * type: 'number',
1905
- * value: 150
1906
- * };
1907
- *
1908
- * const emptyNumberCell: NumberDataTableCell = {
1909
- * type: 'number',
1910
- * value: undefined
1911
- * };
1912
- * ```
1913
- */
1914
- declare type NumberDataTableCell = {
1915
- /**
1916
- * Indicates this cell contains a number value.
1917
- */
1918
- type: 'number';
1919
- /**
1920
- * Numeric value within safe integer range.
1921
- *
1922
- * Valid range: `Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`
1923
- *
1924
- * Invalid values:
1925
- *
1926
- * - Infinity or -Infinity
1927
- * - NaN
1928
- * - Negative zero (-0)
1929
- * - Denormalized numbers
1930
- *
1931
- * Use `undefined` for an empty cell.
1932
- */
1933
- value: number | undefined;
1934
- /**
1935
- * Optional formatting information for displaying the number.
1936
- *
1937
- * @example Applying display formatting to a number
1938
- * ```ts
1939
- * import type { NumberCellMetadata } from '@canva/intents/data';
1940
- *
1941
- * const currencyFormatting: NumberCellMetadata = { formatting: '[$USD]#,##0.00' };
1942
- * const percentageFormatting: NumberCellMetadata = { formatting: '0.00%' };
1943
- * ```
1944
- */
1945
- metadata?: NumberCellMetadata;
1946
- };
1947
-
1948
- /** @public */
1949
- declare type OnContextChange = (context: SettingsUiContext) => void;
1950
-
1951
- /**
1952
- * @public
1953
- * {@link GetDataTableError} indicating the data source reference is no longer valid.
1954
- * This will trigger a re-selection flow for the user.
1955
- */
1956
- declare type OutdatedSourceRefError = {
1957
- /**
1958
- * The data source reference is no longer valid.
1959
- *
1960
- * Return this error when the DataSourceRef cannot be used to retrieve data,
1961
- * for example:
1962
- *
1963
- * - The referenced dataset has been deleted
1964
- * - Access permissions have changed
1965
- * - The structure of the data has fundamentally changed
1966
- *
1967
- * This will trigger a re-selection flow, allowing the user to choose a new
1968
- * data source.
1969
- */
1970
- status: 'outdated_source_ref';
1971
- };
1972
-
1973
- /**
1974
- * @public
1975
- * {@link InvocationContext} indicating an error occurred because the previously selected data source reference is no longer valid.
1976
- * Triggered when getDataTable returned 'outdated_source_ref' during data refresh.
1977
- * UI should guide the user to reselect or reconfigure their data.
1978
- */
1979
- declare type OutdatedSourceRefInvocationContext = {
1980
- /**
1981
- * Previously selected data source reference is no longer valid.
1982
- *
1983
- * This occurs when `getDataTable` returned 'outdated_source_ref' during a
1984
- * refresh attempt. Your UI should guide the user to select a new data source
1985
- * or update their selection.
1986
- *
1987
- * The outdated reference is provided to help you suggest an appropriate replacement.
1988
- */
1989
- reason: 'outdated_source_ref';
1990
- /**
1991
- * The outdated data source reference that caused the error during refresh.
1992
- */
1993
- dataSourceRef?: DataSourceRef;
1994
- };
1995
-
1996
- /**
1997
- * @public
1998
- * Exported file ready for publishing.
1999
- */
2000
- declare type OutputFile = ImageOutputFile | VideoOutputFile | DocumentOutputFile;
2001
-
2002
- /**
2003
- * @public
2004
- * Production-ready exported files for a specific media slot.
2005
- *
2006
- * These are the final files that should be uploaded to your platform.
2007
- */
2008
- declare type OutputMedia = {
2009
- /**
2010
- * ID of the media slot these files belong to.
2011
- *
2012
- * Matches a media slot ID from your output type definition.
2013
- */
2014
- mediaSlotId: string;
2015
- /**
2016
- * Array of exported files for this media slot.
2017
- *
2018
- * Files match the requirements specified in your media slot configuration.
2019
- */
2020
- files: OutputFile[];
2021
- };
2022
-
2023
- /**
2024
- * @public
2025
- * Metadata about a specific page in the exported content.
2026
- */
2027
- declare type OutputPageMetadata = {
2028
- /**
2029
- * The unique identifier for the page.
2030
- */
2031
- pageId: string | undefined;
2032
- /**
2033
- * The position of the page within the design, starting from 1 for the first page.
2034
- */
2035
- pageNumber: number;
2036
- };
2037
-
2038
- /**
2039
- * @public
2040
- * Configuration for an output type.
2041
- *
2042
- * Defines a specific publishing format your platform supports,
2043
- * including what media is required and accepted file types.
2044
- *
2045
- * @example Defining an Instagram post output type
2046
- * ```ts
2047
- * const instagramPost: OutputType = {
2048
- * id: 'instagram_post',
2049
- * displayName: 'Instagram Post',
2050
- * mediaSlots: [
2051
- * {
2052
- * id: 'main_image',
2053
- * displayName: 'Post Image',
2054
- * fileCount: { min: 1, max: 10 },
2055
- * accepts: {
2056
- * image: {
2057
- * format: 'jpg',
2058
- * aspectRatio: { min: 0.8, max: 1.91 },
2059
- * }
2060
- * }
2061
- * }
2062
- * ]
2063
- * };
2064
- * ```
2065
- */
2066
- declare type OutputType = {
2067
- /**
2068
- * Unique identifier for this output type.
2069
- *
2070
- * Use descriptive IDs like `"instagram_post"` or `"youtube_video"`.
2071
- */
2072
- id: string;
2073
- /**
2074
- * User-facing name for this output type.
2075
- *
2076
- * This is displayed to users when selecting where to publish.
2077
- * Examples: `"Instagram Post"`, `"YouTube Video"`, `"Twitter Post"`.
2078
- */
2079
- displayName: string;
2080
- /**
2081
- * Array of media slots defining what content is needed.
2082
- *
2083
- * Each slot represents a piece of media required for publishing,
2084
- * such as a main image, thumbnail, or video.
2085
- */
2086
- mediaSlots: MediaSlot[];
2087
- };
2088
-
2089
- /**
2090
- * @public
2091
- * Configuration for an output type as provided by apps in
2092
- * {@link ContentPublisherIntent.getPublishConfiguration}.
2093
- *
2094
- * This is the authored shape of an output type. It omits the
2095
- * {@link MediaSlot.selection} field which is populated by Canva
2096
- * when returning {@link OutputType} in Settings UI contexts.
2097
- *
2098
- * @example Defining output type configuration for a social media platform
2099
- * ```ts
2100
- * const outputType: OutputTypeConfiguration = {
2101
- * id: 'instagram_post',
2102
- * displayName: 'Instagram Post',
2103
- * mediaSlots: [
2104
- * {
2105
- * id: 'main_image',
2106
- * displayName: 'Post Image',
2107
- * fileCount: { min: 1, max: 10 },
2108
- * accepts: {
2109
- * image: { format: 'jpg', aspectRatio: { min: 0.8, max: 1.91 } }
2110
- * }
2111
- * }
2112
- * ]
2113
- * };
2114
- * ```
2115
- */
2116
- declare type OutputTypeConfiguration = {
2117
- /**
2118
- * Unique identifier for this output type.
2119
- *
2120
- * Use descriptive IDs like `"instagram_post"` or `"youtube_video"`.
2121
- */
2122
- id: string;
2123
- /**
2124
- * User-facing name for this output type.
2125
- *
2126
- * This is displayed to users when selecting where to publish.
2127
- * Examples: `"Instagram Post"`, `"YouTube Video"`, `"Twitter Post"`.
2128
- */
2129
- displayName: string;
2130
- /**
2131
- * Array of media slots defining what content is needed.
2132
- *
2133
- * Each slot represents a piece of media required for publishing,
2134
- * such as a main image, thumbnail, or video.
2135
- * The {@link MediaSlot.selection} field is omitted here because apps
2136
- * do not provide selection data when defining output types.
2137
- */
2138
- mediaSlots: Omit<MediaSlot, 'selection'>[];
2139
- };
2140
-
2141
- /**
2142
- * @public
2143
- * Action to be taken after publishing completes successfully.
2144
- */
2145
- declare type PostPublishAction = PostPublishActionRedirect;
2146
-
2147
- /**
2148
- * @public
2149
- * Redirect action to navigate the user to a URL after publishing.
2150
- *
2151
- * @example Redirecting to content editor
2152
- * ```ts
2153
- * const postPublishAction: PostPublishActionRedirect = {
2154
- * type: 'redirect',
2155
- * url: 'https://example.com/posts/12345/edit'
2156
- * };
2157
- * ```
2158
- */
2159
- declare type PostPublishActionRedirect = {
2160
- type: 'redirect';
2161
- /**
2162
- * The URL to redirect the user to after publishing.
2163
- */
2164
- url: string;
2165
- };
2166
-
2167
- /**
2168
- * @public
2169
- *
2170
- * Prepares a {@link ContentPublisherIntent|Content Publisher Intent}.
2171
- *
2172
- * @example
2173
- * ```tsx
2174
- * import { prepareContentPublisher } from "@canva/intents/content";
2175
- *
2176
- * prepareContentPublisher({
2177
- * getPublishConfiguration: async (params) => {
2178
- * // Implement the logic to get the publish configuration
2179
- * },
2180
- * renderSettingsUi: (params) => {
2181
- * // Implement the UI for settings view
2182
- * },
2183
- * renderPreviewUi: (params) => {
2184
- * // Implement the UI for preview view
2185
- * },
2186
- * publishContent: async (params) => {
2187
- * // Implement the logic to publish the content
2188
- * },
2189
- * });
2190
- * ```
2191
- */
2192
- declare const prepareContentPublisher: (implementation: ContentPublisherIntent) => void;
2193
-
2194
- /**
2195
- * @public
2196
- *
2197
- * Prepares a {@link DataConnectorIntent|DataConnector Intent}.
2198
- *
2199
- * @example
2200
- * ```tsx
2201
- * import { prepareDataConnector } from "@canva/intents/data";
2202
- *
2203
- * prepareDataConnector({
2204
- * getDataTable: async (params) => {
2205
- * // Implement the logic to fetch the data table
2206
- * },
2207
- * renderSelectionUi: (params) => {
2208
- * // Implement the UI for the data table selection
2209
- * },
2210
- * });
2211
- * ```
2212
- */
2213
- declare const prepareDataConnector: (implementation: DataConnectorIntent) => void;
2214
-
2215
- /**
2216
- * @public
2217
- *
2218
- * Prepares a {@link DesignEditorIntent|DesignEditor Intent}.
2219
- *
2220
- * @example
2221
- * ```tsx
2222
- * import { prepareDesignEditor } from '@canva/intents/design';
2223
- *
2224
- * prepareDesignEditor({
2225
- * render: async () => {
2226
- * // TODO: Implement the logic to render your app's UI
2227
- * },
2228
- * });
2229
- * ```
2230
- */
2231
- declare const prepareDesignEditor: (implementation: DesignEditorIntent) => void;
2232
-
2233
- /**
2234
- * @public
2235
- * Preview item for an image or video.
2236
- *
2237
- * Check the `kind` and `status` properties to determine the type and state.
2238
- */
2239
- declare type Preview = ImagePreview | VideoPreview | DocumentPreview | EmailPreview;
2240
-
2241
- /**
2242
- * @public
2243
- * Type of preview media.
2244
- */
2245
- declare type PreviewKind = 'image' | 'video' | 'document' | 'email';
2246
-
2247
- /**
2248
- * @public
2249
- * Preview media for a specific media slot.
2250
- *
2251
- * Contains preview URLs and metadata for images or videos in the design.
2252
- */
2253
- declare type PreviewMedia = {
2254
- /**
2255
- * ID of the media slot this preview belongs to.
2256
- *
2257
- * Matches a media slot ID from your output type definition.
2258
- */
2259
- mediaSlotId: string;
2260
- /**
2261
- * Array of preview items for this media slot.
2262
- *
2263
- * May contain multiple previews if the media slot accepts multiple files.
2264
- */
2265
- previews: Preview[];
2266
- };
2267
-
2268
- /**
2269
- * @public
2270
- * State of a preview item.
2271
- */
2272
- declare type PreviewStatus = 'loading' | 'thumbnail' | 'upgrading' | 'ready' | 'error';
2273
-
2274
- /**
2275
- * @public
2276
- * Successful response from publishing a content.
2277
- *
2278
- * @example Basic successful publish
2279
- * ```ts
2280
- * return {
2281
- * status: 'completed',
2282
- * externalId: 'post_12345',
2283
- * externalUrl: 'https://example.com/posts/12345'
2284
- * };
2285
- * ```
2286
- *
2287
- * @example Successful publish with redirect
2288
- * ```ts
2289
- * return {
2290
- * status: 'completed',
2291
- * externalId: 'video_67890',
2292
- * externalUrl: 'https://example.com/videos/67890',
2293
- * postPublishAction: {
2294
- * type: 'redirect',
2295
- * url: 'https://example.com/videos/67890/edit'
2296
- * }
2297
- * };
2298
- * ```
2299
- */
2300
- declare type PublishContentCompleted = {
2301
- status: 'completed';
2302
- /**
2303
- * Unique identifier returned from your external platform. You can use this for:
2304
- *
2305
- * - Tracking published content
2306
- * - Fetching insights data for the published content
2307
- * - Linking back to the content in future operations
2308
- */
2309
- externalId?: string;
2310
- /**
2311
- * Direct URL to the published content on your platform.
2312
- *
2313
- * Users can visit this URL to view their published content.
2314
- * This may be displayed to users or used for sharing.
2315
- */
2316
- externalUrl?: string;
2317
- /**
2318
- * Optional action to perform after publishing completes.
2319
- *
2320
- * Currently supports redirecting users to a specific URL after publishing.
2321
- */
2322
- postPublishAction?: PostPublishAction;
2323
- };
2324
-
2325
- /**
2326
- * @public
2327
- * Error response from publishing a content.
2328
- *
2329
- * Return the appropriate error type based on the failure:
2330
- *
2331
- * - `"remote_request_failed"`: Network or API errors with your platform
2332
- * - `"app_error"`: Custom application errors with optional message
2333
- */
2334
- declare type PublishContentError = RemoteRequestFailedError_2 | AppError_2;
2335
-
2336
- /**
2337
- * @public
2338
- * Parameters required for publishing the content.
2339
- * Contains all the information needed to send the content to your external platform.
2340
- */
2341
- declare type PublishContentRequest = {
2342
- /**
2343
- * Platform-specific settings reference containing user configurations.
2344
- *
2345
- * This is the same reference you saved via `updatePublishSettings` in the settings UI.
2346
- * Parse this string to retrieve the user's publish settings (e.g., captions, tags, privacy).
2347
- *
2348
- * Maximum size: 32KB
2349
- */
2350
- publishRef?: string;
2351
- /**
2352
- * The output type selected by the user for this publish operation.
2353
- *
2354
- * This matches one of the output types you provided in `getPublishConfiguration`.
2355
- */
2356
- outputType: OutputTypeConfiguration;
2357
- /**
2358
- * Production-ready exported files matching the requirements from your output type.
2359
- *
2360
- * These files are ready to upload to your platform and match the format, size,
2361
- * and aspect ratio requirements specified in your media slots.
2362
- */
2363
- outputMedia: OutputMedia[];
2364
- };
2365
-
2366
- /**
2367
- * @public
2368
- * Response from a publish content operation.
2369
- *
2370
- * This can be either a successful completion or an error response.
2371
- */
2372
- declare type PublishContentResponse = PublishContentCompleted | PublishContentError;
2373
-
2374
- /** @public */
2375
- declare type PublishError = {
2376
- appDefinedPayload?: string;
2377
- };
2378
-
2379
- /**
2380
- * @public
2381
- * Signals that the publish error was cleared.
2382
- */
2383
- declare type PublishErrorClearedSettingsUiContext = {
2384
- reason: 'publish_error_cleared';
2385
- };
2386
-
2387
- /**
2388
- * @public
2389
- * Provides information about an error that occurred in publishContent.
2390
- */
2391
- declare type PublishErrorSettingsUiContext = {
2392
- reason: 'publish_error';
2393
- /**
2394
- * The error that occurred. Undefined means no error occurred or the previous
2395
- * error was cleared by Canva.
2396
- */
2397
- error: PublishError;
2398
- };
2399
-
2400
- /**
2401
- * @public
2402
- * Supported file formats for publishing.
2403
- */
2404
- declare type PublishFileFormat = 'png' | 'jpg' | 'mp4' | 'pdf_standard' | 'html_bundle' | 'html_standalone';
2405
-
2406
- /**
2407
- * @public
2408
- * Initial payload provided from cache.
2409
- */
2410
- declare type PublishPreviewUiInvocationContext = {
2411
- /**
2412
- * Initial preview data and context provided when the preview UI is rendered.
2413
- */
2414
- reason: 'publish';
2415
- /**
2416
- * Initial preview media to display
2417
- * This will only be used for scheduling and not caching
2418
- */
2419
- previewMedia?: PreviewMedia[];
2420
- /** Information about the current output type being previewed */
2421
- outputType?: OutputType;
2422
- /** Current publish reference, if available */
2423
- publishRef?: string;
2424
- };
2425
-
2426
- /**
2427
- * @public
2428
- * Validation state indicating whether publish settings are complete and valid.
2429
- */
2430
- declare type PublishRefValidityState = 'valid' | 'invalid_missing_required_fields' | 'invalid_authentication_required';
2431
-
2432
- /**
2433
- * @public
2434
- * Configuration for publish settings.
2435
- *
2436
- * Contains the user's settings and their validation state. Use this to
2437
- * control whether the publish button is enabled.
2438
- */
2439
- declare type PublishSettings = {
2440
- /**
2441
- * Serialized platform-specific settings for publishing.
2442
- *
2443
- * Store all information your app needs to publish the content in this string.
2444
- * This might include:
2445
- *
2446
- * - Captions or descriptions
2447
- * - Tags or hashtags
2448
- * - Privacy settings
2449
- * - Publishing destination (account, page, etc.)
2450
- * - Scheduling information
2451
- *
2452
- * This reference will be provided to your `publishContent` method when publishing.
2453
- *
2454
- * Maximum size: 32KB
2455
- *
2456
- * @example Serializing settings
2457
- * ```ts
2458
- * const settings = {
2459
- * caption: 'Check out my design!',
2460
- * tags: ['design', 'creative'],
2461
- * privacy: 'public'
2462
- * };
2463
- * const publishRef = JSON.stringify(settings);
2464
- * ```
2465
- */
2466
- publishRef?: string;
2467
- /**
2468
- * Validation state of the publish settings.
2469
- *
2470
- * Controls whether the publish button is enabled:
2471
- *
2472
- * - `"valid"`: Settings are complete and valid, publish button is enabled
2473
- * - `"invalid_missing_required_fields"`: Required settings are missing, publish button is disabled
2474
- * - `"invalid_authentication_required"`: User must authenticate before publishing can proceed
2475
- */
2476
- validityState: PublishRefValidityState;
2477
- };
2478
-
2479
- /**
2480
- * @public
2481
- * Provides information about the current state of the settings UI to help
2482
- * you adapt the interface based on the selected output type.
2483
- */
2484
- declare type PublishSettingsSettingsUiContext = {
2485
- reason: 'publish_settings';
2486
- /**
2487
- * The currently selected output type.
2488
- *
2489
- * Use this to customize your settings UI based on the requirements
2490
- * of different output types.
2491
- */
2492
- outputType: OutputType;
2493
- };
2494
-
2495
- /**
2496
- * @public
2497
- * Initial payload provided from cache.
2498
- */
2499
- declare type PublishSettingsUiInvocationContext = {
2500
- /**
2501
- * Initial settings and context provided when the settings UI is rendered.
2502
- */
2503
- reason: 'publish';
2504
- /** Current publish reference to populate the UI, if any exist */
2505
- publishRef?: string;
2506
- /** Information about the current output type being configured */
2507
- outputType?: OutputType;
2508
- };
2509
-
2510
- /**
2511
- * @public
2512
- * {@link GetDataTableError} indicating failure to fetch data from the external source.
2513
- * Typically due to network issues or API failures.
2514
- */
2515
- declare type RemoteRequestFailedError = {
2516
- /**
2517
- * Failed to fetch data from the external source.
2518
- *
2519
- * Return this error for network issues, API failures, or other
2520
- * connectivity problems that prevent data retrieval.
2521
- */
2522
- status: 'remote_request_failed';
2523
- };
2524
-
2525
- /**
2526
- * @public
2527
- * {@link PublishContentError} indicating failure of the remote request to the external platform.
2528
- *
2529
- * Return this error for:
2530
- *
2531
- * - Network connectivity issues
2532
- * - API endpoint failures
2533
- * - HTTP errors from your platform
2534
- * - Timeout errors
2535
- *
2536
- * @example Handling network errors
2537
- * ```ts
2538
- * try {
2539
- * await uploadToExternalPlatform(file);
2540
- * } catch (error) {
2541
- * return { status: 'remote_request_failed' };
2542
- * }
2543
- * ```
2544
- */
2545
- declare type RemoteRequestFailedError_2 = {
2546
- status: 'remote_request_failed';
2547
- };
2548
-
2549
- /**
2550
- * @public
2551
- * Initial payload provided when the preview UI is rendered.
2552
- * Contains the preview data and settings needed to initialize the preview interface.
2553
- */
2554
- declare type RenderPreviewUiInvocationContext = PublishPreviewUiInvocationContext;
2555
-
2556
- /**
2557
- * @public
2558
- * Configuration required for rendering the preview UI.
2559
- *
2560
- * Provides callbacks for managing preview media and responding to preview updates.
2561
- */
2562
- declare type RenderPreviewUiRequest = {
2563
- /**
2564
- * @public
2565
- * The initial preview data and context provided when the preview UI is rendered.
2566
- *
2567
- * Contains the initial preview media, output type information, and any existing
2568
- * publish settings needed to properly display the preview interface.
2569
- */
2570
- invocationContext: RenderPreviewUiInvocationContext;
2571
- /**
2572
- * Callback to upgrade video thumbnail previews to full video media.
2573
- *
2574
- * Call this function when you need full video previews instead of lightweight thumbnails.
2575
- * This helps optimize performance by deferring full video loading until needed.
2576
- *
2577
- * Upgrades may complete asynchronously; listen to `registerOnPreviewChange` for updates
2578
- * to receive the upgraded video previews.
2579
- *
2580
- * @param previewIds - Array of preview IDs to upgrade from thumbnail to full video
2581
- *
2582
- * @example Upgrading video previews on user interaction
2583
- * ```ts
2584
- * // When user clicks on a video thumbnail, upgrade to full video
2585
- * if (preview.kind === 'video' && preview.status === 'thumbnail') {
2586
- * requestPreviewUpgrade([preview.id]);
2587
- * }
2588
- * ```
2589
- */
2590
- requestPreviewUpgrade: (previewIds: string[]) => void;
2591
- /**
2592
- * Registers a callback to be invoked when preview data changes.
2593
- *
2594
- * This callback is triggered when:
2595
- *
2596
- * - The design content changes
2597
- * - The output type changes
2598
- * - Preview media is upgraded from thumbnail to full video
2599
- * - Export settings are modified
2600
- *
2601
- * Use this to update your preview UI in real-time as users modify their design.
2602
- *
2603
- * @param callback - The callback invoked when preview data is updated
2604
- * @returns A disposer function that cleans up the registered callback
2605
- *
2606
- * @example Handling preview updates
2607
- * ```ts
2608
- * const disposer = registerOnPreviewChange(({ previewMedia, outputType, publishRef }) => {
2609
- * // Update your preview UI with the new preview media
2610
- * previewMedia.forEach((media) => {
2611
- * media.previews.forEach((preview) => {
2612
- * if (preview.status === 'ready') {
2613
- * displayPreview(preview);
2614
- * }
2615
- * });
2616
- * });
2617
- * });
2618
- *
2619
- * // Clean up when preview UI is unmounted
2620
- * onUnmount(() => disposer());
2621
- * ```
2622
- */
2623
- registerOnPreviewChange: (callback: (opts: {
2624
- previewMedia: PreviewMedia[];
2625
- /** The output type that the preview data is for */
2626
- outputType: OutputType;
2627
- /** The current publish settings reference, if available */
2628
- publishRef?: string;
2629
- }) => void) => Disposer;
2630
- };
2631
-
2632
- /**
2633
- * @public
2634
- * Parameters for rendering the data selection UI.
2635
- */
2636
- declare type RenderSelectionUiRequest = {
2637
- /**
2638
- * Context information about why the data selection UI is being launched.
2639
- *
2640
- * Use this to adapt your UI for different scenarios:
2641
- *
2642
- * - 'data_selection': Initial data selection or editing existing data
2643
- * - 'outdated_source_ref': Previous reference is no longer valid, guide user to reselect
2644
- * - 'app_error': Custom error occurred, show error message and recovery options
2645
- *
2646
- * When `dataSourceRef` is provided, pre-populate your UI with this selection.
2647
- */
2648
- invocationContext: InvocationContext;
2649
- /**
2650
- * Maximum allowed rows and columns for the imported data.
2651
- *
2652
- * Your UI should inform users of these constraints and prevent or warn about
2653
- * selections that would exceed them. This helps users understand why certain
2654
- * data sets might not be available for selection.
2655
- */
2656
- limit: DataTableLimit;
2657
- /**
2658
- * Callback to preview selected data before finalizing import.
2659
- *
2660
- * Call this function when the user selects data to:
2661
- *
2662
- * 1. Show a preview of the selected data to the user
2663
- * 2. Validate that the selection meets system requirements
2664
- *
2665
- * Calling this function will trigger your `getDataTable` implementation.
2666
- * Wait for the promise to resolve to determine if the selection is valid.
2667
- *
2668
- * @param dataSourceRef - Reference object identifying the selected data
2669
- * @returns Promise resolving to success or an error result
2670
- * @throws Will throw CanvaError('bad_request') if
2671
- * 1. {@link DataSourceRef.source} exceeds 5kb.
2672
- * 2. {@link DataSourceRef.title} exceeds 255 characters.
2673
- * 3. {@link GetDataTableCompleted.dataTable} exceeds {@link DataTableLimit} or contains invalid data.
2674
- */
2675
- updateDataRef: (dataSourceRef: DataSourceRef) => Promise<UpdateDataRefResponse>;
2676
- };
2677
-
2678
- /**
2679
- * @public
2680
- * Initial payload provided when the publish settings UI is rendered.
2681
- * Contains the current settings state needed to initialize the settings interface.
2682
- */
2683
- declare type RenderSettingsUiInvocationContext = PublishSettingsUiInvocationContext;
2684
-
2685
- /**
2686
- * @public
2687
- * Configuration for the publish settings UI.
2688
- *
2689
- * This type provides the necessary callbacks and configuration for rendering
2690
- * a custom publish settings interface where users configure platform-specific options.
2691
- */
2692
- declare type RenderSettingsUiRequest = {
2693
- /**
2694
- * @public
2695
- * The initial settings and context provided when the settings UI is rendered.
2696
- *
2697
- * Contains any previously saved publish settings and information about the current output type being configured.
2698
- * Use this to restore the UI to its previous state or initialise it with appropriate defaults.
2699
- */
2700
- invocationContext: RenderSettingsUiInvocationContext;
2701
- /**
2702
- * Callback to save and validate the user's publish settings.
2703
- *
2704
- * Call this function whenever the user modifies their settings to:
2705
- *
2706
- * - Save the settings for later use in `publishContent`
2707
- * - Validate that required fields are filled
2708
- * - Enable or disable the publish button based on validity
2709
- *
2710
- * Store all necessary publishing information in the `publishRef` string.
2711
- * This will be provided to your `publishContent` method when the user publishes.
2712
- *
2713
- * @param settings - The new publish settings to save
2714
- * @returns A promise that resolves when the settings are successfully saved
2715
- * @throws Will throw `CanvaError('bad_request')` if {@link PublishSettings.publishRef} exceeds 32KB.
2716
- *
2717
- * @example Updating settings as user types
2718
- * ```ts
2719
- * // As user fills in form fields, update settings
2720
- * function handleCaptionChange(caption: string) {
2721
- * const settings = { caption, tags: currentTags };
2722
- * const publishRef = JSON.stringify(settings);
2723
- *
2724
- * updatePublishSettings({
2725
- * publishRef,
2726
- * validityState: caption ? 'valid' : 'invalid_missing_required_fields'
2727
- * });
2728
- * }
2729
- * ```
2730
- */
2731
- updatePublishSettings: (publishSettings: PublishSettings) => Promise<UpdatePublishSettingsResponse>;
2732
-
2733
- /**
2734
- * Registers a callback to be invoked when the settings UI context changes.
2735
- *
2736
- * This callback is triggered when:
2737
- * - the user changes the output type in the publish flow.
2738
- * - an error occurs in the publish flow.
2739
- *
2740
- * Use this to respond to Canva changes and update your settings UI accordingly.
2741
- *
2742
- * @param opts - The options for registering a callback.
2743
- * @returns A disposer function that cleans up the registered callback.
2744
- *
2745
- * @example Adapting UI for different output types
2746
- * ```ts
2747
- * registerOnContextChange({
2748
- * onContextChange: (ctx) => {
2749
- * if (ctx.reason === 'publish_settings') {
2750
- * if (ctx.outputType.id === 'instagram_post') {
2751
- * showHashtagField();
2752
- * }
2753
- * }
2754
- * if (ctx.reason === 'publish_error') {
2755
- * setError(ctx.error);
2756
- * }
2757
- * }
2758
- * });
2759
- * ```
2760
- */
2761
- registerOnContextChange: (opts: {
2762
- onContextChange: OnContextChange;
2763
- }) => Disposer;
2764
- /**
2765
- * @beta
2766
- * Function to trigger a request for AI content.
2767
- *
2768
- * Use this function to trigger a request for AI content.
2769
- *
2770
- * @param request - The request for AI content.
2771
- * @returns A promise resolving to the AI content response with a status of 'completed' or 'cancelled'.
2772
- * @example Requesting AI content
2773
- * ```ts
2774
- * async function onGenerateCaption() {
2775
- * const result = await requestAiContent({
2776
- * type: 'social_caption',
2777
- * currentValue: settings.caption,
2778
- * fieldLabel: 'Caption',
2779
- * hints: {
2780
- * maxLength: 2200,
2781
- * },
2782
- * });
2783
- *
2784
- * if (result.status !== 'completed') {
2785
- * return;
2786
- * }
2787
- * const nextSettings = { ...settings, caption: result.value };
2788
- * // ... set local state
2789
- * await updatePublishSettings({
2790
- * publishRef: JSON.stringify(nextSettings),
2791
- * validityState: 'valid',
2792
- * });
2793
- * }
2794
- * ```
2795
- */
2796
- requestAiContent: RequestAiContent;
2797
- };
2798
-
2799
- /**
2800
- * @beta
2801
- * Function to trigger a request for AI content.
2802
- */
2803
- declare type RequestAiContent = (request: AiContentRequest) => Promise<AiContentResponse>;
2804
-
2805
- /**
2806
- * @public
2807
- * Metadata specific to design content represented by a media selection.
2808
- */
2809
- declare interface SelectionDesignMetadata {
2810
- type: 'design';
2811
- /**
2812
- * A signed JWT token containing the design id
2813
- */
2814
- designToken: string;
2815
- /**
2816
- * The user given title of the design
2817
- */
2818
- title: string | undefined;
2819
- }
2820
-
2821
- /**
2822
- * @public
2823
- * Metadata about the source content represented by a media selection.
2824
- */
2825
- declare type SelectionMetadata = SelectionDesignMetadata;
2826
-
2827
- /**
2828
- * @public
2829
- * Context information for the publish settings UI.
2830
- */
2831
- declare type SettingsUiContext = PublishSettingsSettingsUiContext | PublishErrorSettingsUiContext | PublishErrorClearedSettingsUiContext;
2832
-
2833
- /**
2834
- * @public
2835
- * Base interface for all preview types that have a fixed width and height.
2836
- */
2837
- declare interface SizedPreview extends BasePreview {
2838
- /**
2839
- * Width of the preview in pixels.
2840
- */
2841
- widthPx: number;
2842
- /**
2843
- * Height of the preview in pixels.
2844
- */
2845
- heightPx: number;
2846
- }
2847
-
2848
- /**
2849
- * @beta
2850
- * Request for social caption generation.
2851
- */
2852
- declare type SocialCaptionRequest = BaseAiContentRequest & {
2853
- type: 'social_caption';
2854
- /**
2855
- * Hints for how the AI should generate the caption.
2856
- */
2857
- hints?: {
2858
- /**
2859
- * The maximum length of the caption.
2860
- */
2861
- maxLength?: number;
2862
- };
2863
- };
2864
-
2865
- /**
2866
- * @public
2867
- * Cell containing a text value.
2868
- *
2869
- * @example Creating a string cell
2870
- * ```ts
2871
- * import type { StringDataTableCell } from '@canva/intents/data';
2872
- *
2873
- * const nameCell: StringDataTableCell = {
2874
- * type: 'string',
2875
- * value: 'John Doe'
2876
- * };
2877
- *
2878
- * const emptyStringCell: StringDataTableCell = {
2879
- * type: 'string',
2880
- * value: undefined
2881
- * };
2882
- * ```
2883
- */
2884
- declare type StringDataTableCell = {
2885
- /**
2886
- * Indicates this cell contains a string value.
2887
- */
2888
- type: 'string';
2889
- /**
2890
- * Text content of the cell.
2891
- *
2892
- * Maximum length: 10,000 characters
2893
- *
2894
- * Use `undefined` for an empty cell.
2895
- */
2896
- value: string | undefined;
2897
- };
2898
-
2899
- /**
2900
- * @public
2901
- * Successful result from the {@link RenderSelectionUiRequest.updateDataRef} callback.
2902
- */
2903
- declare type UpdateDataRefCompleted = {
2904
- /**
2905
- * The data selection was successful and can be previewed.
2906
- */
2907
- status: 'completed';
2908
- };
2909
-
2910
- /**
2911
- * @public
2912
- * Result returned from the {@link RenderSelectionUiRequest.updateDataRef} callback.
2913
- * Indicates whether {@link DataSourceRef} update succeeded or failed.
2914
- */
2915
- declare type UpdateDataRefResponse = UpdateDataRefCompleted | GetDataTableError;
2916
-
2917
- /**
2918
- * @public
2919
- * Successful response from updating the publish settings.
2920
- */
2921
- declare type UpdatePublishSettingsCompleted = {
2922
- status: 'completed';
2923
- };
2924
-
2925
- /**
2926
- * @public
2927
- * Response from updating the publish settings.
2928
- */
2929
- declare type UpdatePublishSettingsResponse = UpdatePublishSettingsCompleted;
2930
-
2931
- /**
2932
- * @public
2933
- * Numeric value range constraint.
2934
- * Used to specify requirements for aspect ratios, durations, file counts, etc.
2935
- */
2936
- declare type ValueRange = ExactValueRange | MinValueRange | MaxValueRange | MinMaxValueRange;
2937
-
2938
- /**
2939
- * @public
2940
- * The MIME type of a video file that's supported by Canva's backend.
2941
- *
2942
- * @remarks
2943
- * - GIFs are treated as videos, not images.
2944
- * - `"application/json"` is only used for Lottie files.
2945
- */
2946
- declare type VideoMimeType = 'video/avi' | 'video/x-msvideo' | 'image/gif' | 'video/x-m4v' | 'video/x-matroska' | 'video/quicktime' | 'video/mp4' | 'video/mpeg' | 'video/webm' | 'application/json';
2947
-
2948
- /**
2949
- * @public
2950
- * Exported video file ready for publishing.
2951
- */
2952
- declare interface VideoOutputFile extends BaseOutputFile {
2953
- /**
2954
- * Width of the video in pixels.
2955
- */
2956
- widthPx: number;
2957
- /**
2958
- * Height of the video in pixels.
2959
- */
2960
- heightPx: number;
2961
- }
2962
-
2963
- /**
2964
- * @public
2965
- * Video preview in various states.
2966
- *
2967
- * Videos transition through states: `"loading"` → `"thumbnail"` → `"upgrading"` → `"ready"`.
2968
- * Start with thumbnails for better performance, then upgrade to full video using `requestPreviewUpgrade`.
2969
- */
2970
- declare type VideoPreview = VideoPreviewLoading | VideoPreviewThumbnail | VideoPreviewUpgrading | VideoPreviewReady | VideoPreviewError;
2971
-
2972
- /**
2973
- * @public
2974
- * Video preview that failed to generate.
2975
- *
2976
- * Display an error state to the user.
2977
- */
2978
- declare interface VideoPreviewError extends SizedPreview {
2979
- kind: 'video';
2980
- status: 'error';
2981
-
2982
- /**
2983
- * The error message to display to the user.
2984
- */
2985
- message: string;
2986
- }
2987
-
2988
- /**
2989
- * @public
2990
- * Video preview that is currently being generated.
2991
- *
2992
- * Display a loading state until the preview transitions to `"thumbnail"` or `"error"`.
2993
- */
2994
- declare interface VideoPreviewLoading extends SizedPreview {
2995
- kind: 'video';
2996
- status: 'loading';
2997
- /**
2998
- * Video duration in milliseconds.
2999
- */
3000
- durationMs?: number;
3001
- }
3002
-
3003
- /**
3004
- * @public
3005
- * Video preview with full video ready to play.
3006
- *
3007
- * Contains URLs for both the video and thumbnail.
3008
- */
3009
- declare interface VideoPreviewReady extends SizedPreview {
3010
- kind: 'video';
3011
- status: 'ready';
3012
- /**
3013
- * Video format.
3014
- */
3015
- format: 'mp4';
3016
- /**
3017
- * URL to the full video.
3018
- *
3019
- * Use this URL in a video player.
3020
- */
3021
- url: string;
3022
- /**
3023
- * Format of the thumbnail image.
3024
- */
3025
- thumbnailFormat: 'png' | 'jpg';
3026
- /**
3027
- * URL to the thumbnail image.
3028
- *
3029
- * Can be used as a poster image for the video player.
3030
- */
3031
- thumbnailUrl: string;
3032
- /**
3033
- * Video duration in milliseconds.
3034
- */
3035
- durationMs?: number;
3036
- }
3037
-
3038
- /**
3039
- * @public
3040
- * Video preview with lightweight thumbnail available.
3041
- *
3042
- * This is the initial state for video previews. Show the thumbnail image
3043
- * and call `requestPreviewUpgrade` when the user needs the full video.
3044
- */
3045
- declare interface VideoPreviewThumbnail extends SizedPreview {
3046
- kind: 'video';
3047
- status: 'thumbnail';
3048
- /**
3049
- * Format of the thumbnail image.
3050
- */
3051
- thumbnailFormat: 'png' | 'jpg';
3052
- /**
3053
- * URL to the thumbnail image.
3054
- *
3055
- * Display this lightweight image until full video is needed.
3056
- */
3057
- thumbnailUrl: string;
3058
- /**
3059
- * Video duration in milliseconds.
3060
- */
3061
- durationMs?: number;
3062
- }
3063
-
3064
- /**
3065
- * @public
3066
- * Video preview that is being upgraded from thumbnail to full video.
3067
- *
3068
- * Display the thumbnail with a loading indicator until the video is ready.
3069
- */
3070
- declare interface VideoPreviewUpgrading extends SizedPreview {
3071
- kind: 'video';
3072
- status: 'upgrading';
3073
- /**
3074
- * Format of the thumbnail image.
3075
- */
3076
- thumbnailFormat: 'png' | 'jpg';
3077
- /**
3078
- * URL to the thumbnail image.
3079
- *
3080
- * Continue showing the thumbnail while the full video loads.
3081
- */
3082
- thumbnailUrl: string;
3083
- /**
3084
- * Video duration in milliseconds.
3085
- */
3086
- durationMs?: number;
3087
- }
3088
-
3089
- /**
3090
- * @public
3091
- * A unique identifier that points to a video asset in Canva's backend.
3092
- */
3093
- declare type VideoRef = string & {
3094
- __videoRef: never;
3095
- };
3096
-
3097
- /**
3098
- * @public
3099
- * Video file requirements for a media slot.
3100
- *
3101
- * Specifies format, aspect ratio, duration, and size constraints for videos.
3102
- *
3103
- * @example Video requirements for YouTube
3104
- * ```ts
3105
- * const videoReq: VideoRequirement = {
3106
- * format: 'mp4',
3107
- * aspectRatio: { exact: 16/9 },
3108
- * durationMs: { min: 1000, max: 600000 },
3109
- * };
3110
- * ```
3111
- */
3112
- declare interface VideoRequirement extends BaseFileRequirement {
3113
- /**
3114
- * Supported video format.
3115
- */
3116
- format: 'mp4';
3117
- /**
3118
- * Aspect ratio constraint (width / height).
3119
- *
3120
- * Examples:
3121
- * - `{ exact: 16/9 }`: Widescreen
3122
- * - `{ exact: 9/16 }`: Vertical/Story format
3123
- */
3124
- aspectRatio?: ValueRange;
3125
- /**
3126
- * Duration constraint in milliseconds.
3127
- *
3128
- * Examples:
3129
- * - `{ max: 60000 }`: Maximum 60 seconds
3130
- * - `{ min: 3000, max: 600000 }`: Between 3 seconds and 10 minutes
3131
- */
3132
- durationMs?: ValueRange;
3133
-
3134
- }
3135
-
3136
- /**
3137
- * @public
3138
- * Selection metadata for a video media item.
3139
- */
3140
- declare interface VideoSelection extends BaseSelection {
3141
- kind: 'video';
3142
- /**
3143
- * Duration of the selected video in milliseconds.
3144
- */
3145
- durationMs: number;
3146
- }
3147
-
3148
- /**
3149
- * @public
3150
- * Options for uploading a video asset to the user's private media library.
3151
- */
3152
- declare type VideoUploadOptions = {
3153
- /**
3154
- * The type of asset.
3155
- */
3156
- type: 'video';
3157
- /**
3158
- * A human-readable name for the video asset.
3159
- *
3160
- * @remarks
3161
- * This name is displayed in the user's media library and helps users identify
3162
- * and find the asset later. If not provided, Canva will generate a name based
3163
- * on the asset's URL or a unique identifier.
3164
- *
3165
- * Requirements:
3166
- * - Minimum length: 1 character (empty strings are not allowed)
3167
- * - Maximum length: 255 characters
3168
- */
3169
- name?: string;
3170
- /**
3171
- * The ref of the original asset from which this new asset was derived.
3172
- *
3173
- * @remarks
3174
- * For example, if an app applies an effect to a video, `parentRef` should contain the ref of the original video.
3175
- */
3176
- parentRef?: VideoRef;
3177
- /**
3178
- * The URL of the video file to upload.
3179
- *
3180
- * @remarks
3181
- * Requirements:
3182
- *
3183
- * - Must use HTTPS
3184
- * - Must return a `200` status code
3185
- * - `Content-Type` must match the file's MIME type
3186
- * - Must be publicly accessible (i.e. not a localhost URL)
3187
- * - Must not redirect
3188
- * - Must not contain an IP address
3189
- * - Maximum length: 4096 characters
3190
- * - Must not contain whitespace
3191
- * - Must not contain these characters: `>`, `<`, `{`, `}`, `^`, backticks
3192
- * - Maximum file size: 1000MB (1GB)
3193
- */
3194
- url: string;
3195
- /**
3196
- * The MIME type of the video file.
3197
- */
3198
- mimeType: VideoMimeType;
3199
- /**
3200
- * The URL of a thumbnail video to display while the video is queued for upload.
3201
- *
3202
- * @remarks
3203
- * Requirements:
3204
- *
3205
- * - Must use HTTPS
3206
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
3207
- * - Maximum length: 4096 characters
3208
- * - The dimensions of the thumbnail video must match the video's aspect ratio to prevent the thumbnail from appearing squashed or stretched
3209
- * - Must not be an AVI file. Although our APIs support uploading AVI videos, Canva can't preview them because of native support of browsers
3210
- */
3211
- thumbnailVideoUrl?: string;
3212
- /**
3213
- * The URL of a thumbnail image to use as a fallback if `thumbnailVideoUrl` isn't provided.
3214
- * This can be an external URL or a data URL.
3215
- *
3216
- * @remarks
3217
- * Requirements for external URLs:
3218
- *
3219
- * - Must use HTTPS
3220
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
3221
- * - Must be a PNG, JPEG, or SVG file
3222
- * - Maximum length: 4096 characters
3223
- *
3224
- * Requirements for data URLs:
3225
- *
3226
- * - Must include `;base64` for base64-encoded data
3227
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
3228
- * - The dimensions of the thumbnail must match the video's aspect ratio to prevent the thumbnail from appearing squashed or stretched
3229
- */
3230
- thumbnailImageUrl: string;
3231
- /**
3232
- * A disclosure identifying if the app generated this video using AI.
3233
- *
3234
- * @remarks
3235
- * Helps users make informed decisions about the content they interact with.
3236
- * See {@link AiDisclosure} for the full definition.
3237
- *
3238
- * **App Generated**
3239
- *
3240
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
3241
- * the app requests a third-party service to take similar action on a video using AI.
3242
- *
3243
- * Required for the following cases (this list is not exhaustive):
3244
- * | Case | Reason |
3245
- * | -- | -- |
3246
- * | AI generates a new video from scratch | Creates new creative content |
3247
- * | AI changes the style of the video e.g. makes it cartoon | Significantly alters the style |
3248
- * | AI adds subtitles that rely on subjective interpretation | Creates new creative content |
3249
- * | AI expands a video by generating new content to fill the edges | Creates new creative content |
3250
- * | AI animates an image | Creates new creative content |
3251
- * | AI fixes defects e.g. blur in a video by generating details | Creates new creative content |
3252
- * | AI generates a talking head presenter | Creates new creative content |
3253
- *
3254
- * **None**
3255
- *
3256
- * 'none' indicates when the app doesn't create or significantly alter an asset using AI, or as a part of
3257
- * a request to third-party hosted content.
3258
- *
3259
- * Required for the following cases (this list is not exhaustive):
3260
- * | Case | Reason |
3261
- * | -- | -- |
3262
- * | Asset comes from an asset library | Didn't generate the asset itself |
3263
- * | AI corrects red eyes | A minor correction |
3264
- * | AI adjusts brightness and contrast on a video | Doesn't change original meaning by itself |
3265
- * | AI creates a slow motion effect in a video | Doesn't change original meaning by itself |
3266
- * | AI adds AI word-by-word transcribed subtitles to a video | Doesn't change original meaning by itself |
3267
- */
3268
- aiDisclosure: AiDisclosure;
3269
-
3270
- } & AllOrNone<Dimensions>;
3271
-
3272
- export { }