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