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