@canva/design 1.11.0-beta.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,2085 @@
1
+ /**
2
+ * Adds an audio track to the user's design.
3
+ * @public
4
+ * @param audioTrack - The audio track to add to the user's design.
5
+ */
6
+ export declare const addAudioTrack: (audioTrack: AudioTrack) => Promise<void>;
7
+
8
+ /**
9
+ * @public
10
+ * Add element to responsive documents, which slot things into a text stream
11
+ */
12
+ export declare const addElementAtCursor: (
13
+ element: ElementAtCursor | TableElement
14
+ ) => Promise<void>;
15
+
16
+ /**
17
+ * @public
18
+ * Add element to fixed designs, which use a coordinate-based positioning system.
19
+ */
20
+ export declare const addElementAtPoint: (
21
+ element: DesignElement | ElementAtPoint | TableElement | RichtextElement
22
+ ) => Promise<void>;
23
+
24
+ /**
25
+ * @deprecated
26
+ * @public
27
+ * Adds a native element to the user's design.
28
+ * @param element - The element to add to the user's design.
29
+ */
30
+ export declare const addNativeElement: (
31
+ element: NativeElement | NativeElementWithBox
32
+ ) => Promise<void>;
33
+
34
+ /**
35
+ * @public
36
+ * Adds a new page immediately after the currently selected page.
37
+ * @param opts - Configuration for the new page to be added.
38
+ */
39
+ export declare const addPage: (opts?: {
40
+ /** Elements to be added to the page */
41
+ elements?: ElementAtPoint[];
42
+ /**
43
+ * The page background. This can be a solid color, an image or a video.
44
+ **/
45
+ background?: PageBackgroundFill;
46
+ /** A page title which must be no longer than 255 characters */
47
+ title?: string;
48
+ }) => Promise<void>;
49
+
50
+ /**
51
+ * @public
52
+ * Alternative text for a11y compliance.
53
+ */
54
+ export declare type AltText = {
55
+ /**
56
+ * The text content.
57
+ */
58
+ text: string;
59
+ /**
60
+ * Indicates where the alternative text should be displayed.
61
+ *
62
+ * @remarks
63
+ * - If `true`, the alternative text will only be displayed in the editor.
64
+ * - If `false`, the alternative text will be displayed in the editor and in view-only mode.
65
+ */
66
+ decorative: boolean | undefined;
67
+ };
68
+
69
+ /**
70
+ * @public
71
+ * A callback that runs when:
72
+ *
73
+ * - the app element is created
74
+ * - the app element's data is updated
75
+ * - the user selects an existing app element
76
+ *
77
+ * @param appElement - Information about the app element that was changed.
78
+ */
79
+ export declare type AppElementChangeHandler<A extends AppElementData> = (
80
+ appElement:
81
+ | {
82
+ /**
83
+ * The app element data in its most recent state.
84
+ */
85
+ data: A;
86
+ /**
87
+ * The version number of the app.
88
+ */
89
+ version: number;
90
+ }
91
+ | undefined
92
+ ) => void;
93
+
94
+ /**
95
+ * @public
96
+ * A client that provides methods for creating and managing the lifecycle of an app element.
97
+ */
98
+ export declare interface AppElementClient<A extends AppElementData> {
99
+ /**
100
+ * If an app element is selected, the element's data is overwritten and the element is re-rendered.
101
+ * Otherwise, the provided data is used to create a new app element.
102
+ * @param appElementData - The data to attach to the app element. Existing data will be overwritten.
103
+ * @param placement - The position, dimensions, and rotation of the app element.
104
+ */
105
+ addOrUpdateElement(appElementData: A, placement?: Placement): Promise<void>;
106
+ /**
107
+ * A callback that runs when:
108
+ *
109
+ * - the app element is created
110
+ * - the app element's data is updated
111
+ * - the user selects an existing app element
112
+ *
113
+ * @param handler - The callback to run when the app element changes.
114
+ */
115
+ registerOnElementChange(handler: AppElementChangeHandler<A>): void;
116
+ }
117
+
118
+ /**
119
+ * @public
120
+ * Options for creating an app element client.
121
+ */
122
+ export declare type AppElementClientConfiguration<A extends AppElementData> = {
123
+ /**
124
+ * Registers a callback that renders an app element based on the data it receives.
125
+ */
126
+ render: AppElementRenderer<A>;
127
+ };
128
+
129
+ /**
130
+ * @public
131
+ * The data associated with an app element.
132
+ */
133
+ export declare type AppElementData = Record<string, Value>;
134
+
135
+ /**
136
+ * @public
137
+ * A callback function that renders an app element based on the data it receives.
138
+ * @param appElementData - The data the callback must use to render the app element.
139
+ */
140
+ export declare type AppElementRenderer<A extends AppElementData> = (
141
+ appElementData: A
142
+ ) => AppElementRendererOutput;
143
+
144
+ /**
145
+ * @public
146
+ * An array of one or more elements to render as output of an app element.
147
+ */
148
+ export declare type AppElementRendererOutput = NativeSimpleElementWithBox[];
149
+
150
+ /**
151
+ * @public
152
+ * A unique identifier that references an app runtime process
153
+ */
154
+ export declare type AppProcessId = string & {
155
+ __appProcessId: never;
156
+ };
157
+
158
+ /**
159
+ * @public
160
+ * Audio track to be added to the design at the end of a drag event.
161
+ */
162
+ export declare type AudioDragConfig = {
163
+ /**
164
+ * The type of element.
165
+ */
166
+ type: "audio";
167
+ /**
168
+ * A function that returns a reference (ref) to an audio asset in Canva's backend.
169
+ */
170
+ resolveAudioRef: () => Promise<{
171
+ ref: AudioRef;
172
+ }>;
173
+ /**
174
+ * The duration of the audio track, in milliseconds.
175
+ */
176
+ durationMs: number;
177
+ /**
178
+ * A human readable title for the audio track.
179
+ */
180
+ title: string;
181
+ };
182
+
183
+ /**
184
+ * @public
185
+ * A unique identifier that references an audio asset in Canva's backend.
186
+ */
187
+ export declare type AudioRef = string & {
188
+ __audioRef: never;
189
+ };
190
+
191
+ /**
192
+ * @public
193
+ * An audio track that can be added to a design.
194
+ */
195
+ export declare type AudioTrack = {
196
+ /**
197
+ * A unique identifier that points to an audio asset in Canva's backend.
198
+ */
199
+ ref: AudioRef;
200
+ };
201
+
202
+ /**
203
+ * @public
204
+ * A segment of a richtext range.
205
+ */
206
+ export declare type Bounds = {
207
+ /**
208
+ * The starting position of the segment.
209
+ *
210
+ * @remarks
211
+ * This is zero-based, meaning the first character of the range is at index 0.
212
+ */
213
+ index: number;
214
+ /**
215
+ * The number of characters in the segment, starting from the index.
216
+ */
217
+ length: number;
218
+ };
219
+
220
+ /**
221
+ * @deprecated
222
+ * @public
223
+ * A position, rotation, and set of dimensions.
224
+ *
225
+ * @remarks
226
+ * The position and dimensions are relative to the container.
227
+ */
228
+ export declare type Box = Position & (WidthAndHeight | Width | Height);
229
+
230
+ /**
231
+ * @public
232
+ * An individual cell in a table element.
233
+ */
234
+ export declare type Cell = {
235
+ /**
236
+ * The attributes of the cell.
237
+ */
238
+ attributes?: CellAttributes;
239
+ /**
240
+ * The number of columns that the cell occupies.
241
+ */
242
+ colSpan?: number;
243
+ /**
244
+ * The number of rows that the cell occupies.
245
+ */
246
+ rowSpan?: number;
247
+ } & CellContent;
248
+
249
+ /**
250
+ * @public
251
+ * Additional attributes of table cell.
252
+ */
253
+ declare type CellAttributes = {
254
+ /**
255
+ * The background color of the cell, as a hex code.
256
+ */
257
+ backgroundColor?: string;
258
+ } & TextAttributes;
259
+
260
+ /**
261
+ * @public
262
+ * The content of a table element's cell.
263
+ * Cell only supports plain text.
264
+ */
265
+ declare type CellContent =
266
+ | {
267
+ /**
268
+ * Indicates that the cell doesn't have any content.
269
+ */
270
+ type: "empty";
271
+ }
272
+ | {
273
+ /**
274
+ * Indicates that the cell contains plaintext content.
275
+ */
276
+ type: "string";
277
+ /**
278
+ * The plaintext content of the cell.
279
+ *
280
+ * @remarks
281
+ * If an empty string is provided, the `type` will change to `"empty"`.
282
+ */
283
+ value: string;
284
+ };
285
+
286
+ /**
287
+ * Image element or content to be added to the design at the end of a drag event.
288
+ */
289
+ declare type CommonImageDragConfig = {
290
+ /**
291
+ * The type of element.
292
+ */
293
+ type: "image";
294
+ /**
295
+ * The dimensions of the preview image.
296
+ */
297
+ previewSize: Dimensions;
298
+ };
299
+
300
+ /**
301
+ * @public
302
+ * A snapshot of content from a user's design.
303
+ */
304
+ export declare interface ContentDraft<T> {
305
+ /**
306
+ * The individual content items that exist within the snapshot.
307
+ *
308
+ * @remarks
309
+ * Any changes made to this array won't be reflected in the user's design until the `save` method is called.
310
+ */
311
+ readonly contents: readonly T[];
312
+ /**
313
+ * Saves changes made to the content items in the `contents` array.
314
+ *
315
+ * @remarks
316
+ * Once this method is called:
317
+ *
318
+ * - Any changes the app has made to to the content will be reflected in the user's design.
319
+ * - Any changes the user has made to the content since the snapshot was created may be overwritten.
320
+ * - Only properties that are different from the original state will be written to the design.
321
+ */
322
+ save(): Promise<void>;
323
+ }
324
+
325
+ /**
326
+ * @public
327
+ * A type of content that can be read from a user's design.
328
+ */
329
+ export declare type ContentType = "richtext";
330
+
331
+ /**
332
+ * @public
333
+ * A set of X and Y coordinates.
334
+ */
335
+ export declare type Coordinates = {
336
+ /**
337
+ * X coordinate, in pixels.
338
+ */
339
+ x: number;
340
+ /**
341
+ * Y coordinate, in pixels.
342
+ */
343
+ y: number;
344
+ };
345
+
346
+ /**
347
+ * @public
348
+ * Creates a new RichtextRange object, which contains methods to manipulate text.
349
+ */
350
+ export declare function createRichtextRange(): RichtextRange;
351
+
352
+ /**
353
+ * @public
354
+ * An element that's natively supported by the Canva editor.
355
+ */
356
+ export declare type DesignElement = NativeElement;
357
+
358
+ /**
359
+ * @public
360
+ * Provides methods for managing the lifecycle of overlays, such as selected image overlays.
361
+ */
362
+ export declare type DesignOverlay = {
363
+ /**
364
+ * Registers a callback that runs when the `canOpen` state of an overlay target changes.
365
+ * @param opts - Options for configuring the callback.
366
+ */
367
+ registerOnCanOpen<Target extends OverlayTarget>(opts: {
368
+ /**
369
+ * The target to check the `canOpen` state of.
370
+ */
371
+ target: Target;
372
+ /**
373
+ * A callback that runs when the `canOpen` state of the specified target changes.
374
+ *
375
+ * @param event - Information about whether or not an overlay can be opened for the specified target.
376
+ *
377
+ * @remarks
378
+ * This callback fires immediately.
379
+ */
380
+ onCanOpen(event: OverlayOpenableEvent<Target>): void;
381
+ }): () => void;
382
+ };
383
+
384
+ /**
385
+ * @public
386
+ * Provides methods for interacting with selected content.
387
+ */
388
+ export declare type DesignSelection = {
389
+ /**
390
+ * Registers a callback that runs when the specified type of content is selected.
391
+ *
392
+ * @param opts - Options for configuring the content selection callback.
393
+ *
394
+ * @remarks
395
+ * This callback fires immediately if content is already selected when the callback is registered.
396
+ */
397
+ registerOnChange<Scope extends SelectionScope>(opts: {
398
+ /**
399
+ * The type of content that triggers a selection change event.
400
+ */
401
+ scope: Scope;
402
+ /**
403
+ * The callback to run when the selected content changes.
404
+ * @param event - Information about the selection change event.
405
+ */
406
+ onChange(event: SelectionEvent<Scope>): void;
407
+ }): () => void;
408
+ };
409
+
410
+ /**
411
+ * @public
412
+ * JWT that contains the Design ID and App ID.
413
+ */
414
+ export declare type DesignToken = {
415
+ token: string;
416
+ };
417
+
418
+ /**
419
+ * @public
420
+ * A set of dimensions.
421
+ */
422
+ export declare type Dimensions = {
423
+ /**
424
+ * A width, in pixels.
425
+ */
426
+ width: number;
427
+ /**
428
+ * A height, in pixels.
429
+ */
430
+ height: number;
431
+ };
432
+
433
+ /**
434
+ * @public
435
+ * Callbacks for handling drag and drop events.
436
+ */
437
+ export declare type DragCallback = {
438
+ /**
439
+ * A callback that runs at the start of a drag event.
440
+ * @param element - The element being dragged.
441
+ */
442
+ onDragStart: (element: HTMLElement) => void;
443
+ /**
444
+ * A callback that runs at the end of a drag event.
445
+ * @param element - The element being dragged.
446
+ */
447
+ onDragEnd: (element: HTMLElement) => void;
448
+ };
449
+
450
+ /**
451
+ * @public
452
+ * Options for adding drag and drop behavior to an `HTMLElement`.
453
+ */
454
+ export declare type DraggableElementData = ElementData | ImageElementData;
455
+
456
+ /**
457
+ * @public
458
+ * An event that occurs when a user starts dragging an HTML element.
459
+ */
460
+ export declare type DragStartEvent<E extends Element> = Pick<
461
+ DragEvent,
462
+ "dataTransfer" | "currentTarget" | "preventDefault" | "clientX" | "clientY"
463
+ > & {
464
+ currentTarget: E;
465
+ };
466
+
467
+ /**
468
+ * @public
469
+ * Elements targeting a cursor are a subset of the base Element
470
+ **/
471
+ export declare type ElementAtCursor =
472
+ | ImageElement
473
+ | VideoElement
474
+ | EmbedElement
475
+ | TextElement
476
+ | RichtextElement;
477
+
478
+ /**
479
+ * @public
480
+ * An element that's natively supported by the Canva editor and has positional properties.
481
+ */
482
+ export declare type ElementAtPoint =
483
+ | NativeElementWithBox
484
+ | RichtextElementAtPoint;
485
+
486
+ /**
487
+ * @public
488
+ * Options for adding drag and drop behavior to an `HTMLElement`.
489
+ */
490
+ export declare type ElementData = DragCallback & {
491
+ /**
492
+ * The `HTMLElement` to be made draggable.
493
+ */
494
+ node: HTMLElement;
495
+ };
496
+
497
+ /**
498
+ * @public
499
+ * Embed element to be added to the design at the end of a drag event.
500
+ */
501
+ export declare type EmbedDragConfig = {
502
+ /**
503
+ * The type of element.
504
+ */
505
+ type: "embed";
506
+ /**
507
+ * The dimensions of the preview image.
508
+ */
509
+ previewSize: Dimensions;
510
+ /**
511
+ * The URL of an image to display under the user's cursor during the drag and drop event.
512
+ */
513
+ previewUrl: string;
514
+ /**
515
+ * The URL of media that can be embedded, such as the URL of a YouTube video.
516
+ *
517
+ * @remarks
518
+ * This URL must be supported by the Iframely API.
519
+ */
520
+ embedUrl: string;
521
+ };
522
+
523
+ /**
524
+ * @public
525
+ * An element that renders rich media, such as a YouTube video.
526
+ */
527
+ export declare type EmbedElement = NativeEmbedElement;
528
+
529
+ /**
530
+ * @public
531
+ * An element that renders rich media, such as a YouTube video, and has positional properties.
532
+ */
533
+ export declare type EmbedElementAtPoint = NativeEmbedElementWithBox;
534
+
535
+ /**
536
+ * @public
537
+ * The result when a user abandons the export flow, such as by closing the export menu.
538
+ */
539
+ export declare type ExportAborted = {
540
+ /**
541
+ * The status of the export flow.
542
+ */
543
+ status: "aborted";
544
+ };
545
+
546
+ /**
547
+ * @public
548
+ * The exported file.
549
+ */
550
+ export declare type ExportBlob = {
551
+ /**
552
+ * The URL of the exported design.
553
+ *
554
+ * @remarks
555
+ * If a user's design contains multiple pages but is exported in a format that doesn't support multiple pages,
556
+ * this URL will point to a ZIP file that contains each page as a separate file.
557
+ *
558
+ * For example:
559
+ *
560
+ * - If a single-page design is exported as a JPG, the URL will point to a JPG file.
561
+ * - If a multi-page design is exported as a JPG, the URL will point to a ZIP file that contains a JPG file for each page.
562
+ * - If a multi-page design is exported as a PDF file, the URL will point to a PDF file.
563
+ *
564
+ * The following file types support multiple pages:
565
+ *
566
+ * - `"GIF"`
567
+ * - `"PDF_STANDARD"`
568
+ * - `"PPTX"`
569
+ * - `"VIDEO"`
570
+ *
571
+ * The following file types do not support multiple pages:
572
+ *
573
+ * - `"JPG"`
574
+ * - `"PNG"`
575
+ * - `"SVG"`
576
+ */
577
+ url: string;
578
+ };
579
+
580
+ /**
581
+ * @public
582
+ * The result when a user successfully completes an export flow.
583
+ */
584
+ export declare type ExportCompleted = {
585
+ /**
586
+ * The status of the export flow.
587
+ */
588
+ status: "completed";
589
+ /**
590
+ * The title of the design, if set by the user.
591
+ */
592
+ title?: string;
593
+ /**
594
+ * The exported files.
595
+ *
596
+ * @remarks
597
+ * This array only contains one element. This is because, if a multi-page design is exported as multiple files, the files
598
+ * are exported in a ZIP file. In the future, there'll be an option for each file to be a separate element in the array.
599
+ */
600
+ exportBlobs: ExportBlob[];
601
+ };
602
+
603
+ /**
604
+ * @public
605
+ * The types of files that Canva supports for exported designs.
606
+ */
607
+ export declare type ExportFileType =
608
+ | "png"
609
+ | "jpg"
610
+ | "pdf_standard"
611
+ | "video"
612
+ | "gif"
613
+ | "pptx"
614
+ | "svg";
615
+
616
+ /**
617
+ * @public
618
+ * Options for configuring the export of a design.
619
+ */
620
+ export declare type ExportRequest = {
621
+ /**
622
+ * The types of files the user can export their design as.
623
+ *
624
+ * @remarks
625
+ * You must provide at least one file type.
626
+ */
627
+ acceptedFileTypes: ExportFileType[];
628
+ };
629
+
630
+ /**
631
+ * @public
632
+ * The result of exporting a design.
633
+ */
634
+ export declare type ExportResponse = ExportCompleted | ExportAborted;
635
+
636
+ /**
637
+ * @public
638
+ * Image element or content to be added to the design at the end of a drag event.
639
+ *
640
+ * @remarks
641
+ * This type is only used when the image data is from an external URL.
642
+ */
643
+ export declare type ExternalImageDragConfig = CommonImageDragConfig & {
644
+ /**
645
+ * A function that returns a reference (ref) to an audio asset in Canva's backend.
646
+ */
647
+ resolveImageRef: () => Promise<{
648
+ ref: ImageRef;
649
+ }>;
650
+ /**
651
+ * The URL of an image to display under the user's cursor during the drag and drop event.
652
+ */
653
+ previewUrl: string;
654
+ /**
655
+ * The dimensions of the full-size image.
656
+ */
657
+ fullSize?: Dimensions;
658
+ };
659
+
660
+ /**
661
+ * @public
662
+ * The appearance of a path's interior.
663
+ *
664
+ * @remarks
665
+ * The `color` and `asset` properties are mutually exclusive.
666
+ */
667
+ export declare type Fill = {
668
+ /**
669
+ * If `true`, users can replace a fill by dropping an image or video onto it.
670
+ */
671
+ dropTarget?: boolean;
672
+ /**
673
+ * The color of the fill as a hex code.
674
+ *
675
+ * @remarks
676
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
677
+ *
678
+ * @example
679
+ * " #ff0099"
680
+ */
681
+ color?: string;
682
+ /**
683
+ * An image or video to use as the fill.
684
+ */
685
+ asset?: ImageFill | VideoFill;
686
+ };
687
+
688
+ /**
689
+ * @public
690
+ * A reference to a font that can be used in other parts of the SDK.
691
+ */
692
+ export declare type FontRef = string & {
693
+ __fontRef: never;
694
+ };
695
+
696
+ /**
697
+ * @public
698
+ * Font weights supported in the SDK.
699
+ **/
700
+ export declare type FontWeight =
701
+ | "normal"
702
+ | "thin"
703
+ | "extralight"
704
+ | "light"
705
+ | "medium"
706
+ | "semibold"
707
+ | "bold"
708
+ | "ultrabold"
709
+ | "heavy";
710
+
711
+ /**
712
+ * Allows to get the context of currently selected page.
713
+ * @public
714
+ * @returns Page context of currently selected page
715
+ */
716
+ export declare const getCurrentPageContext: () => Promise<PageContext>;
717
+
718
+ /**
719
+ * @public
720
+ * Gets the default dimensions that a new page will have when it is added to a design.
721
+ * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
722
+ * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
723
+ * design that is applied whenever a new page is created.
724
+ *
725
+ * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
726
+ */
727
+ export declare const getDefaultPageDimensions: () => Promise<
728
+ Dimensions | undefined
729
+ >;
730
+
731
+ /**
732
+ * @public
733
+ * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
734
+ */
735
+ export declare function getDesignToken(): Promise<DesignToken>;
736
+
737
+ /**
738
+ * @public
739
+ * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
740
+ */
741
+ export declare type GroupContentAtPoint = NativeSimpleElementWithBox;
742
+
743
+ /**
744
+ * @public
745
+ * An element that contains two or more elements.
746
+ */
747
+ export declare type GroupElement = NativeGroupElement;
748
+
749
+ /**
750
+ * @public
751
+ * An element that contains two or more elements and has positional properties.
752
+ */
753
+ export declare type GroupElementAtPoint = NativeGroupElementWithBox;
754
+
755
+ /**
756
+ * A set of dimensions with an auto-calculated width.
757
+ */
758
+ declare type Height = {
759
+ /**
760
+ * Indicates that the width should be auto-calculated.
761
+ */
762
+ width: "auto";
763
+ /**
764
+ * A height, in pixels.
765
+ *
766
+ * @remarks
767
+ * - The pixels are relative to their container.
768
+ * - Minimum: 0
769
+ * - Maximum: 32767
770
+ */
771
+ height: number;
772
+ };
773
+
774
+ /**
775
+ * @public
776
+ * Image element or content to be added to the design at the end of a drag event.
777
+ */
778
+ export declare type ImageDragConfig = ExternalImageDragConfig;
779
+
780
+ /**
781
+ * @public
782
+ * Image element or content to be added to the design at the end of a drag event.
783
+ */
784
+ export declare type ImageDragConfigForElement<E extends Element> =
785
+ E extends HTMLImageElement
786
+ ? Partial<ImageDragConfig> & Pick<ImageDragConfig, "type">
787
+ : ImageDragConfig;
788
+
789
+ /**
790
+ * @public
791
+ * An element that renders image content.
792
+ */
793
+ export declare type ImageElement = NativeImageElement;
794
+
795
+ /**
796
+ * @public
797
+ * An element that renders image content and has positional properties.
798
+ */
799
+ export declare type ImageElementAtPoint = NativeImageElementWithBox;
800
+
801
+ /**
802
+ * @public
803
+ * Options for adding drag and drop behavior to an `HTMLImageElement`.
804
+ */
805
+ export declare type ImageElementData = DragCallback & {
806
+ /**
807
+ * The `HTMLImageElement` to be made draggable.
808
+ */
809
+ node: HTMLImageElement;
810
+ };
811
+
812
+ /**
813
+ * @public
814
+ * An image asset that fills a path's interior.
815
+ */
816
+ export declare type ImageFill = {
817
+ /**
818
+ * The type of fill.
819
+ */
820
+ type: "image";
821
+ /**
822
+ * A unique identifier that points to an image asset in Canva's backend.
823
+ */
824
+ ref: ImageRef;
825
+ };
826
+
827
+ /**
828
+ * @public
829
+ * A unique identifier that references an image asset in Canva's backend.
830
+ */
831
+ export declare type ImageRef = string & {
832
+ __imageRef: never;
833
+ };
834
+
835
+ /**
836
+ * @public
837
+ * @param appElementConfig - Configuration for an AppElementClient
838
+ */
839
+ export declare function initAppElement<A extends AppElementData>(
840
+ appElementConfig: AppElementClientConfiguration<A>
841
+ ): AppElementClient<A>;
842
+
843
+ /**
844
+ * @public
845
+ * Options for formatting inline richtext.
846
+ */
847
+ export declare type InlineFormatting = {
848
+ /**
849
+ * The color of the text as a hex code.
850
+ *
851
+ * @remarks
852
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
853
+ *
854
+ * @example
855
+ * "#ff0099"
856
+ */
857
+ color?: string;
858
+ /**
859
+ * The weight (thickness) of the font.
860
+ *
861
+ * @remarks
862
+ * The available font weights depend on the font.
863
+ *
864
+ * @defaultValue "normal"
865
+ */
866
+ fontWeight?: FontWeight;
867
+ /**
868
+ * The style of the font.
869
+ * @defaultValue "normal"
870
+ */
871
+ fontStyle?: "normal" | "italic";
872
+ /**
873
+ * The decoration of the text.
874
+ * @defaultValue "none"
875
+ */
876
+ decoration?: "none" | "underline";
877
+ /**
878
+ * The strikethrough of the text.
879
+ * @defaultValue "none"
880
+ */
881
+ strikethrough?: "none" | "strikethrough";
882
+ /**
883
+ * An external URL that the text links to.
884
+ */
885
+ link?: string;
886
+ };
887
+
888
+ /**
889
+ * @deprecated
890
+ * @public
891
+ * An element that's natively supported by the Canva editor.
892
+ */
893
+ export declare type NativeElement =
894
+ | NativeImageElement
895
+ | NativeVideoElement
896
+ | NativeEmbedElement
897
+ | NativeTextElement
898
+ | NativeShapeElement
899
+ | NativeGroupElement;
900
+
901
+ /**
902
+ * @public
903
+ * The types of elements an app can add to a user's design.
904
+ */
905
+ export declare type NativeElementType =
906
+ | "image"
907
+ | "embed"
908
+ | "text"
909
+ | "shape"
910
+ | "video";
911
+
912
+ /**
913
+ * @deprecated The type has been superseded by `ElementAtPoint`.
914
+ * @public
915
+ * An element that's natively supported by the Canva editor and has positional properties.
916
+ */
917
+ export declare type NativeElementWithBox =
918
+ | NativeImageElementWithBox
919
+ | NativeVideoElementWithBox
920
+ | NativeEmbedElementWithBox
921
+ | NativeTextElementWithBox
922
+ | NativeShapeElementWithBox
923
+ | NativeGroupElementWithBox;
924
+
925
+ /**
926
+ * @deprecated The type has been superseded by `EmbedElement`.
927
+ * @public
928
+ * An element that renders rich media, such as a YouTube video.
929
+ */
930
+ export declare type NativeEmbedElement = {
931
+ /**
932
+ * The type of element.
933
+ */
934
+ type: "embed";
935
+ /**
936
+ * The URL of the rich media.
937
+ *
938
+ * @remarks
939
+ * This URL must be supported by the Iframely API.
940
+ */
941
+ url: string;
942
+ };
943
+
944
+ /**
945
+ * @deprecated The type has been superseded by `EmbedElementAtPoint`.
946
+ * @public
947
+ * An element that renders rich media, such as a YouTube video, and has positional properties.
948
+ */
949
+ export declare type NativeEmbedElementWithBox = {
950
+ /**
951
+ * The type of element.
952
+ */
953
+ type: "embed";
954
+ /**
955
+ * The URL of the rich media.
956
+ *
957
+ * @remarks
958
+ * This URL must be supported by the Iframely API.
959
+ */
960
+ url: string;
961
+ } & Box;
962
+
963
+ /**
964
+ * @deprecated The type has been superseded by `GroupElement`.
965
+ * @public
966
+ * An element that contains two or more elements.
967
+ */
968
+ export declare type NativeGroupElement = {
969
+ /**
970
+ * The type of element.
971
+ */
972
+ type: "group";
973
+ /**
974
+ * The elements to render within the group.
975
+ *
976
+ * @remarks
977
+ * - Each element within a group must have dimensions and a position.
978
+ * - The dimensions and positions are relative to the dimensions and positions of the group.
979
+ */
980
+ children: NativeSimpleElementWithBox[];
981
+ };
982
+
983
+ /**
984
+ * @deprecated The type has been superseded by `GroupElementAtPoint`.
985
+ * @public
986
+ * An element that contains two or more elements and has positional properties.
987
+ */
988
+ export declare type NativeGroupElementWithBox = {
989
+ /**
990
+ * The type of element.
991
+ */
992
+ type: "group";
993
+ /**
994
+ * The elements to render within the group.
995
+ *
996
+ * @remarks
997
+ * - Each element within a group must have dimensions and a position.
998
+ * - The dimensions and positions are relative to the dimensions and positions of the group.
999
+ */
1000
+ children: NativeSimpleElementWithBox[];
1001
+ } & Box;
1002
+
1003
+ /**
1004
+ * @deprecated The type has been superseded by `ImageElement`.
1005
+ * @public
1006
+ * An element that renders image content.
1007
+ */
1008
+ export declare type NativeImageElement = {
1009
+ /**
1010
+ * The type of element.
1011
+ */
1012
+ type: "image";
1013
+ /**
1014
+ * A description of the image content.
1015
+ */
1016
+ altText: AltText | undefined;
1017
+ } & (
1018
+ | {
1019
+ /**
1020
+ * A data URL that contains the image data.
1021
+ */
1022
+ dataUrl: string;
1023
+ /**
1024
+ * A unique identifier that points to an image asset in Canva's backend.
1025
+ */
1026
+ ref?: never;
1027
+ }
1028
+ | {
1029
+ /**
1030
+ * A data URL that contains the image data.
1031
+ */
1032
+ dataUrl?: never;
1033
+ /**
1034
+ * A unique identifier that points to an image asset in Canva's backend.
1035
+ */
1036
+ ref: ImageRef;
1037
+ }
1038
+ );
1039
+
1040
+ /**
1041
+ * @deprecated The type has been superseded by `ImageElementAtPoint`.
1042
+ * @public
1043
+ * An element that renders image content and has positional properties.
1044
+ */
1045
+ export declare type NativeImageElementWithBox = NativeImageElement & Box;
1046
+
1047
+ /**
1048
+ * @deprecated The type has been superseded by `ShapeElement`.
1049
+ * @public
1050
+ * An element that renders a vector shape.
1051
+ */
1052
+ export declare type NativeShapeElement = {
1053
+ /**
1054
+ * The type of element.
1055
+ */
1056
+ type: "shape";
1057
+ /**
1058
+ * Options for configuring the scale and cropping of the shape.
1059
+ */
1060
+ viewBox: ShapeViewBox;
1061
+ /**
1062
+ * The paths that define the structure of the shape.
1063
+ *
1064
+ * @remarks
1065
+ * - There must be between 1 and 30 paths (inclusive).
1066
+ * - The maximum combined size of all paths must not exceed 2kb.
1067
+ * - The maximum number of unique fill colors across all paths is 6.
1068
+ */
1069
+ paths: ShapePath[];
1070
+ };
1071
+
1072
+ /**
1073
+ * @deprecated The type has been superseded by `ShapeElementAtPoint`.
1074
+ * @public
1075
+ * An element that renders a vector shape and has positional properties.
1076
+ */
1077
+ export declare type NativeShapeElementWithBox = {
1078
+ /**
1079
+ * The type of element.
1080
+ */
1081
+ type: "shape";
1082
+ /**
1083
+ * Options for configuring the scale and cropping of a shape.
1084
+ */
1085
+ viewBox: ShapeViewBox;
1086
+ /**
1087
+ * The paths that define the structure of the shape.
1088
+ *
1089
+ * @remarks
1090
+ * - There must be between 1 and 30 paths (inclusive).
1091
+ * - The maximum combined size of all paths must not exceed 2kb.
1092
+ * - The maximum number of unique fill colors across all paths is 6.
1093
+ */
1094
+ paths: ShapePath[];
1095
+ } & Box;
1096
+
1097
+ /**
1098
+ * @deprecated The type has been superseded by `GroupContentAtPoint`.
1099
+ * @public
1100
+ * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
1101
+ */
1102
+ export declare type NativeSimpleElementWithBox = Exclude<
1103
+ NativeElementWithBox,
1104
+ NativeGroupElementWithBox
1105
+ >;
1106
+
1107
+ /**
1108
+ * @deprecated The type has been superseded by `TextElement`.
1109
+ * @public
1110
+ * An element that renders text content.
1111
+ */
1112
+ export declare type NativeTextElement = {
1113
+ /**
1114
+ * The type of element.
1115
+ */
1116
+ type: "text";
1117
+ /**
1118
+ * The text content.
1119
+ *
1120
+ * @remarks
1121
+ * Only the first element in this array is used.
1122
+ */
1123
+ children: string[];
1124
+ } & TextAttributes;
1125
+
1126
+ /**
1127
+ * @deprecated The type has been superseded by `TextElementAtPoint`.
1128
+ * @public
1129
+ * An element that renders text content and has positional properties.
1130
+ */
1131
+ export declare type NativeTextElementWithBox = {
1132
+ /**
1133
+ * The type of element.
1134
+ */
1135
+ type: "text";
1136
+ /**
1137
+ * The text content.
1138
+ *
1139
+ * @remarks
1140
+ * Only the first element in this array is used.
1141
+ */
1142
+ children: [string];
1143
+ /**
1144
+ * The width of the element, in pixels.
1145
+ *
1146
+ * @remarks
1147
+ * - Minimum: 0
1148
+ * - Maximum: 32767
1149
+ */
1150
+ width?: number;
1151
+ /**
1152
+ * The distance from the top edge of the container, in pixels.
1153
+ *
1154
+ * @remarks
1155
+ * - Minimum: -32768
1156
+ * - Maximum: 32767
1157
+ */
1158
+ top: number;
1159
+ /**
1160
+ * The distance from the left edge of the container, in pixels.
1161
+ *
1162
+ * @remarks
1163
+ * - Minimum: -32768
1164
+ * - Maximum: 32767
1165
+ */
1166
+ left: number;
1167
+ /**
1168
+ * The rotation of the element, in degrees.
1169
+ *
1170
+ * @remarks
1171
+ * - Minimum: -180
1172
+ * - Maximum: 180
1173
+ */
1174
+ rotation?: number;
1175
+ } & TextAttributes;
1176
+
1177
+ /**
1178
+ * @deprecated The type has been superseded by `VideoElement`.
1179
+ * @public
1180
+ * An element that renders video content.
1181
+ */
1182
+ export declare type NativeVideoElement = {
1183
+ /**
1184
+ * The type of element.
1185
+ */
1186
+ type: "video";
1187
+ /**
1188
+ * A unique identifier that points to a video asset in Canva's backend.
1189
+ */
1190
+ ref: VideoRef;
1191
+ /**
1192
+ * A description of the video content.
1193
+ */
1194
+ altText: AltText | undefined;
1195
+ };
1196
+
1197
+ /**
1198
+ * @deprecated The type has been superseded by `VideoElementAtPoint`.
1199
+ * @public
1200
+ * An element that renders video content and has positional properties.
1201
+ */
1202
+ export declare type NativeVideoElementWithBox = NativeVideoElement & Box;
1203
+
1204
+ /**
1205
+ * An object primitive data type that can be used in app element data.
1206
+ */
1207
+ declare type ObjectPrimitive = Boolean | String;
1208
+
1209
+ /**
1210
+ * @public
1211
+ * An alias for the DesignOverlay interface, providing access to design overlay related functionality
1212
+ */
1213
+ export declare const overlay: DesignOverlay;
1214
+
1215
+ /**
1216
+ * @public
1217
+ * Information about whether or not an overlay can be opened for the specified target.
1218
+ */
1219
+ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
1220
+ /**
1221
+ * Information about whether or not an overlay can be opened or not for a selected image.
1222
+ */
1223
+ ["image_selection"]:
1224
+ | OverlayUnopenableEvent
1225
+ | {
1226
+ /**
1227
+ * Indicates that the overlay can be opened for the selected image.
1228
+ */
1229
+ canOpen: true;
1230
+ /**
1231
+ * Opens an overlay for the selected image.
1232
+ * @param opts - Options for launching the process associated with the overlay.
1233
+ */
1234
+ readonly open: (options: {
1235
+ /**
1236
+ * Parameters to pass to the overlay when it opens.
1237
+ *
1238
+ * @remarks
1239
+ * This can be any type of structured data.
1240
+ */
1241
+ launchParameters?: any;
1242
+ }) => Promise<AppProcessId>;
1243
+ };
1244
+ }[Target];
1245
+
1246
+ /**
1247
+ * @public
1248
+ * An entity that an overlay can be opened for.
1249
+ */
1250
+ export declare type OverlayTarget = "image_selection";
1251
+
1252
+ /**
1253
+ * @public
1254
+ * Information about an overlay that can't be opened for the specified target.
1255
+ */
1256
+ declare type OverlayUnopenableEvent = {
1257
+ /**
1258
+ * Indicates that the overlay can't be opened for the specified target.
1259
+ */
1260
+ canOpen: false;
1261
+ /**
1262
+ * Indicates the reason the overlay can't be opened for the specified target.
1263
+ */
1264
+ reason: string;
1265
+ };
1266
+
1267
+ /**
1268
+ * @public
1269
+ * The appearance of a page's background.
1270
+ */
1271
+ export declare type PageBackgroundFill = Pick<Fill, "asset" | "color">;
1272
+
1273
+ /**
1274
+ * @public
1275
+ * Information about a page.
1276
+ */
1277
+ export declare type PageContext = {
1278
+ /**
1279
+ * The dimensions of the page, in pixels.
1280
+ *
1281
+ * @remarks
1282
+ * This may be `undefined` because some types of pages don't have dimensions, such as whiteboards.
1283
+ */
1284
+ dimensions: PageDimensions | undefined;
1285
+ };
1286
+
1287
+ /**
1288
+ * @public
1289
+ * A set of page dimensions, in pixels.
1290
+ */
1291
+ export declare type PageDimensions = {
1292
+ /**
1293
+ * The width of the page, in pixels.
1294
+ */
1295
+ width: number;
1296
+ /**
1297
+ * The height of the page, in pixels.
1298
+ */
1299
+ height: number;
1300
+ };
1301
+
1302
+ /**
1303
+ * @public
1304
+ * The outline of a path.
1305
+ */
1306
+ export declare type PathStroke = {
1307
+ /**
1308
+ * The weight (thickness) of the stroke.
1309
+ *
1310
+ * @remarks
1311
+ * - Minimum: 0
1312
+ * - Maximum: 100
1313
+ */
1314
+ weight: number;
1315
+ /**
1316
+ * The color of the stroke as a hex code.
1317
+ *
1318
+ * @remarks
1319
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
1320
+ *
1321
+ * @example
1322
+ * "#ff0099"
1323
+ */
1324
+ color: string;
1325
+ /**
1326
+ * The alignment of the stroke.
1327
+ */
1328
+ strokeAlign: "inset";
1329
+ };
1330
+
1331
+ /**
1332
+ * @public
1333
+ * A position, set of dimensions, and rotation.
1334
+ */
1335
+ export declare type Placement = Position & (WidthAndHeight | Width | Height);
1336
+
1337
+ /**
1338
+ * @deprecated
1339
+ * A position and rotation.
1340
+ */
1341
+ declare type Position = {
1342
+ /**
1343
+ * The distance from the top edge of the container, in pixels.
1344
+ *
1345
+ * @remarks
1346
+ * - The pixels are relative to their container.
1347
+ * - Minimum: -32768
1348
+ * - Maximum: 32767
1349
+ */
1350
+ top: number;
1351
+ /**
1352
+ * The distance from the left edge of the container, in pixels.
1353
+ *
1354
+ * @remarks
1355
+ * - The pixels are relative to their container.
1356
+ * - Minimum: -32768
1357
+ * - Maximum: 32767
1358
+ */
1359
+ left: number;
1360
+ /**
1361
+ * A rotation, in degrees.
1362
+ *
1363
+ * @remarks
1364
+ * - Minimum: -180
1365
+ * - Maximum: 180
1366
+ */
1367
+ rotation?: number;
1368
+ };
1369
+
1370
+ /**
1371
+ * A primitive data type that can be used in app element data.
1372
+ *
1373
+ * @remarks
1374
+ * All primitive data types are supported except for symbols and bigints.
1375
+ */
1376
+ declare type Primitive = undefined | null | number | boolean | string;
1377
+
1378
+ /**
1379
+ * @public
1380
+ * Exports the user's design as one or more static files.
1381
+ * @param request - The request object containing configurations of the design export.
1382
+ */
1383
+ export declare const requestExport: (
1384
+ request: ExportRequest
1385
+ ) => Promise<ExportResponse>;
1386
+
1387
+ /**
1388
+ * @public
1389
+ * An element that renders richtext content.
1390
+ */
1391
+ export declare type RichtextElement = {
1392
+ /**
1393
+ * The type of element.
1394
+ */
1395
+ type: "richtext";
1396
+ /**
1397
+ * The richtext content.
1398
+ */
1399
+ range: RichtextRange;
1400
+ };
1401
+
1402
+ /**
1403
+ * @public
1404
+ * An element that renders richtext content.
1405
+ *
1406
+ * @remarks
1407
+ * This type includes properties for controlling the position and dimensions of the
1408
+ * element.
1409
+ * It will be positioned and sized relative to its parent container.
1410
+ * The parent container may be an app element, or the current page.
1411
+ */
1412
+ export declare type RichtextElementAtPoint = RichtextElement & TextBox;
1413
+
1414
+ /**
1415
+ * @public
1416
+ * Options for formatting richtext.
1417
+ */
1418
+ export declare type RichtextFormatting = InlineFormatting & {
1419
+ /**
1420
+ * @public
1421
+ * A unique identifier that points to a font asset in Canva's backend.
1422
+ */
1423
+ fontRef?: FontRef;
1424
+ /**
1425
+ * The size of the text, in pixels.
1426
+ *
1427
+ * @remarks
1428
+ * - In the Canva editor, this number is shown as points (pts), not pixels.
1429
+ * - Minimum: 1
1430
+ * - Maximum: 100
1431
+ */
1432
+ fontSize?: number;
1433
+ /**
1434
+ * The alignment of the text.
1435
+ * @defaultValue "start"
1436
+ */
1437
+ textAlign?: "start" | "center" | "end" | "justify";
1438
+ /**
1439
+ * The list indentation level of the paragraph.
1440
+ */
1441
+ listLevel?: number;
1442
+ /**
1443
+ * The appearance of list item markers.
1444
+ *
1445
+ * @remarks
1446
+ * This property only has an effect if `listLevel` is greater than 0.
1447
+ *
1448
+ * @defaultValue "none"
1449
+ */
1450
+ listMarker?:
1451
+ | "none"
1452
+ | "disc"
1453
+ | "circle"
1454
+ | "square"
1455
+ | "decimal"
1456
+ | "lower-alpha"
1457
+ | "lower-roman"
1458
+ | "checked"
1459
+ | "unchecked";
1460
+ };
1461
+
1462
+ /**
1463
+ * @public
1464
+ * Provides methods for interacting with a range of formatted text.
1465
+ */
1466
+ export declare type RichtextRange = {
1467
+ /**
1468
+ * Formats all of the paragraphs that overlap the given bounds.
1469
+ *
1470
+ * @param bounds - The segment of the range on which to apply the formatting.
1471
+ * @param formatting - The formatting to apply to the paragraph(s).
1472
+ *
1473
+ * @remarks
1474
+ * - The `\n` character indicates the end of a paragraph.
1475
+ * - All paragraphs that overlap the provided bounds will be formatted in their entirety.
1476
+ *
1477
+ */
1478
+ formatParagraph(bounds: Bounds, formatting: RichtextFormatting): void;
1479
+ /**
1480
+ * Formats a region of text with inline formatting properties.
1481
+ *
1482
+ * @param bounds - The segment of the range on which to apply the formatting.
1483
+ * @param formatting - The formatting to apply to the text.
1484
+ */
1485
+ formatText(bounds: Bounds, formatting: InlineFormatting): void;
1486
+ /**
1487
+ * Appends the specified characters to the end of the range.
1488
+ *
1489
+ * @param characters - The characters to append to the richtext range.
1490
+ * @param fo -
1491
+ */
1492
+ appendText(
1493
+ characters: string,
1494
+ formatting?: InlineFormatting
1495
+ ): {
1496
+ bounds: Bounds;
1497
+ };
1498
+ /**
1499
+ * Replaces a region of text with the specified characters.
1500
+ *
1501
+ * @param bounds - The segment of the range to replace.
1502
+ * @param characters - The replacement characters.
1503
+ * @param formatting - The formatting to apply to the replaced text.
1504
+ */
1505
+ replaceText(
1506
+ bounds: Bounds,
1507
+ characters: string,
1508
+ formatting?: InlineFormatting
1509
+ ): {
1510
+ /**
1511
+ * The bounds of the replacement characters within the updated range.
1512
+ */
1513
+ bounds: Bounds;
1514
+ };
1515
+ /**
1516
+ * Returns the current state of the richtext as plaintext.
1517
+ */
1518
+ readPlaintext(): string;
1519
+ /**
1520
+ * Returns the current state of the richtext as one or more text regions.
1521
+ * Each region is an object that contains the text content and its formatting.
1522
+ */
1523
+ readTextRegions(): TextRegion[];
1524
+ };
1525
+
1526
+ /**
1527
+ * @public
1528
+ * An alias for the DesignSelection interface, providing access to design selection related functionality
1529
+ */
1530
+ export declare const selection: DesignSelection;
1531
+
1532
+ /**
1533
+ * @public
1534
+ * Information about the user's selection. To access the selected content, call the `read` method.
1535
+ */
1536
+ export declare interface SelectionEvent<Scope extends SelectionScope> {
1537
+ /**
1538
+ * The type of content that's selected.
1539
+ */
1540
+ readonly scope: Scope;
1541
+ /**
1542
+ * The number of selected elements.
1543
+ */
1544
+ readonly count: number;
1545
+ /**
1546
+ * Creates a snapshot of the selected content and returns a *draft* object.
1547
+ * The draft has a mutable `contents` property for making changes to the selected content.
1548
+ * Any changes made to `contents` are not immediately persisted or reflected in the user's design.
1549
+ * To persist the changes, call the `save` method that's available via the draft.
1550
+ *
1551
+ * @example Replacing text
1552
+ * ```
1553
+ * const draft = await selectionEvent.read();
1554
+ *
1555
+ * for(const content of draft.contents) {
1556
+ * // This change won't immediately appear in the user's design
1557
+ * content.text = "This is the new text";
1558
+ * }
1559
+ *
1560
+ * // The changes will now appear in the user's design
1561
+ * await draft.save();
1562
+ * ```
1563
+ */
1564
+ read(): Promise<ContentDraft<SelectionValue<Scope>>>;
1565
+ }
1566
+
1567
+ /**
1568
+ * @public
1569
+ * Information about a user's selection.
1570
+ */
1571
+ export declare interface SelectionEvent<Scope extends SelectionScope> {
1572
+ /**
1573
+ * The type of content.
1574
+ */
1575
+ readonly scope: Scope;
1576
+ /**
1577
+ * The number of content items in the user's selection.
1578
+ */
1579
+ readonly count: number;
1580
+ /**
1581
+ * Returns a snapshot of the content in the user's selection.
1582
+ *
1583
+ * @remarks
1584
+ * The snapshot is known as the *draft*.
1585
+ */
1586
+ read(): Promise<ContentDraft<SelectionValue<Scope>>>;
1587
+ }
1588
+
1589
+ /**
1590
+ * @public
1591
+ * A type of content that supports selection events.
1592
+ */
1593
+ export declare type SelectionScope =
1594
+ | "plaintext"
1595
+ | "image"
1596
+ | "video"
1597
+ | "richtext";
1598
+
1599
+ /**
1600
+ * @public
1601
+ * A piece of selected content.
1602
+ *
1603
+ * @remarks
1604
+ * The available properties depend on the type (scope) of content.
1605
+ */
1606
+ export declare type SelectionValue<Scope extends SelectionScope> = {
1607
+ /**
1608
+ * A selected range of plaintext.
1609
+ */
1610
+ ["plaintext"]: {
1611
+ /**
1612
+ * The text content.
1613
+ */
1614
+ text: string;
1615
+ };
1616
+ /**
1617
+ * A selected image.
1618
+ */
1619
+ ["image"]: {
1620
+ /**
1621
+ * A unique identifier that points to an image asset in Canva's backend.
1622
+ */
1623
+ ref: ImageRef;
1624
+ };
1625
+ /**
1626
+ * A selected video.
1627
+ */
1628
+ ["video"]: {
1629
+ /**
1630
+ * A unique identifier that points to an video asset in Canva's backend.
1631
+ */
1632
+ ref: VideoRef;
1633
+ };
1634
+ /**
1635
+ * A selected range of formatted text.
1636
+ */
1637
+ ["richtext"]: RichtextRange;
1638
+ }[Scope];
1639
+
1640
+ /**
1641
+ * @public
1642
+ * Updates the background of the user's current page. The background can be a solid color,
1643
+ * an image or a video.
1644
+ */
1645
+ export declare const setCurrentPageBackground: (
1646
+ opts: PageBackgroundFill
1647
+ ) => Promise<void>;
1648
+
1649
+ /**
1650
+ * @public
1651
+ * An element that renders a vector shape.
1652
+ */
1653
+ export declare type ShapeElement = NativeShapeElement;
1654
+
1655
+ /**
1656
+ * @public
1657
+ * An element that renders a vector shape and has positional properties.
1658
+ */
1659
+ export declare type ShapeElementAtPoint = NativeShapeElementWithBox;
1660
+
1661
+ /**
1662
+ * @public
1663
+ * A path that defines the structure of a shape element.
1664
+ */
1665
+ export declare type ShapePath = {
1666
+ /**
1667
+ * The shape of the path.
1668
+ *
1669
+ * @remarks
1670
+ * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
1671
+ *
1672
+ * - The path must start with an M command.
1673
+ * - The path must not have more than one M command.
1674
+ * - The path must not use the Q command.
1675
+ * - The path must be closed, either by:
1676
+ * - Using a Z command at the end of the path
1677
+ * - Having the last coordinate match the first coordinate
1678
+ */
1679
+ d: string;
1680
+ /**
1681
+ * The appearance of the path's interior.
1682
+ */
1683
+ fill: Fill;
1684
+ /**
1685
+ * The outline of the path.
1686
+ */
1687
+ stroke?: PathStroke;
1688
+ };
1689
+
1690
+ /**
1691
+ * @public
1692
+ * Options for configuring the scale and cropping of a shape.
1693
+ *
1694
+ * @remarks
1695
+ * This is similar to the `viewBox` attribute of an `SVGElement`.
1696
+ */
1697
+ export declare type ShapeViewBox = {
1698
+ /**
1699
+ * The distance of the shape from the top edge of the element, in pixels.
1700
+ */
1701
+ top: number;
1702
+ /**
1703
+ * The distance of the shape from the left edge of the element, in pixels.
1704
+ */
1705
+ left: number;
1706
+ /**
1707
+ * The width of the view box, in pixels.
1708
+ */
1709
+ width: number;
1710
+ /**
1711
+ * The height of the view box, in pixels.
1712
+ */
1713
+ height: number;
1714
+ };
1715
+
1716
+ /**
1717
+ * @public
1718
+ * An element that renders a table.
1719
+ */
1720
+ export declare type TableElement = {
1721
+ /**
1722
+ * The type of element.
1723
+ */
1724
+ type: "table";
1725
+ /**
1726
+ * The rows of the table.
1727
+ */
1728
+ rows: {
1729
+ /**
1730
+ * The cells (columns) of the row.
1731
+ *
1732
+ * @remarks
1733
+ * Each row must have the same number of cells.
1734
+ */
1735
+ cells: (Cell | null | undefined)[];
1736
+ }[];
1737
+ };
1738
+
1739
+ /**
1740
+ * @public
1741
+ * Options for configuring the appearance of text.
1742
+ */
1743
+ export declare type TextAttributes = {
1744
+ /**
1745
+ * The size of the text.
1746
+ *
1747
+ * @remarks
1748
+ * - Minimum: 1
1749
+ * - Maximum: 100
1750
+ *
1751
+ * @defaultValue 16
1752
+ */
1753
+ fontSize?: number;
1754
+ /**
1755
+ * The alignment of the text.
1756
+ * @defaultValue "start"
1757
+ */
1758
+ textAlign?: "start" | "center" | "end" | "justify";
1759
+ /**
1760
+ * The color of the text as a hex code.
1761
+ *
1762
+ * @remarks
1763
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
1764
+ *
1765
+ * @example
1766
+ * "#ff0099"
1767
+ */
1768
+ color?: string;
1769
+ /**
1770
+ * @public
1771
+ * A unique identifier that points to a font asset in Canva's backend.
1772
+ */
1773
+ fontRef?: FontRef;
1774
+ /**
1775
+ * The weight (thickness) of the font.
1776
+ * @defaultValue "normal"
1777
+ */
1778
+ fontWeight?: FontWeight;
1779
+ /**
1780
+ * The style of the font.
1781
+ * @defaultValue "normal"
1782
+ */
1783
+ fontStyle?: "normal" | "italic";
1784
+ /**
1785
+ * The decoration of the font.
1786
+ * @defaultValue "none"
1787
+ */
1788
+ decoration?: "none" | "underline";
1789
+ };
1790
+
1791
+ /**
1792
+ * @public
1793
+ * The dimensions, position, and rotation of a text element.
1794
+ */
1795
+ declare type TextBox = {
1796
+ /**
1797
+ * The width, in pixels.
1798
+ *
1799
+ * @remarks
1800
+ * - Minimum: 0
1801
+ * - Maximum: 32767
1802
+ */
1803
+ width?: number;
1804
+ /**
1805
+ * The distance from the top edge of the container, in pixels.
1806
+ *
1807
+ * @remarks
1808
+ * - Minimum: -32767
1809
+ * - Maximum: 32767
1810
+ */
1811
+ top: number;
1812
+ /**
1813
+ * The distance from the left edge of the container, in pixels.
1814
+ *
1815
+ * @remarks
1816
+ * - Minimum: -32767
1817
+ * - Maximum: 32767
1818
+ */
1819
+ left: number;
1820
+ /**
1821
+ * The rotation, in degrees.
1822
+ *
1823
+ * @remarks
1824
+ * - Minimum: -180
1825
+ * - Maximum: 180
1826
+ */
1827
+ rotation?: number;
1828
+ };
1829
+
1830
+ /**
1831
+ * @public
1832
+ * Text element or content to be added to the design at the end of a drag event.
1833
+ */
1834
+ export declare type TextDragConfig = {
1835
+ /**
1836
+ * The type of element.
1837
+ */
1838
+ type: "text";
1839
+ /**
1840
+ * The text content to drag.
1841
+ */
1842
+ children?: string[];
1843
+ /**
1844
+ * The alignment of the text.
1845
+ * @defaultValue "start"
1846
+ */
1847
+ textAlign?: "start" | "center" | "end" | "justify";
1848
+ /**
1849
+ * The weight (thickness) of the font.
1850
+ * @defaultValue "normal"
1851
+ */
1852
+ fontWeight?: FontWeight;
1853
+ /**
1854
+ * The style of the font.
1855
+ * @defaultValue "normal"
1856
+ */
1857
+ fontStyle?: "normal" | "italic";
1858
+ /**
1859
+ * The decoration of the font.
1860
+ * @defaultValue "none"
1861
+ */
1862
+ decoration?: "none" | "underline";
1863
+ };
1864
+
1865
+ /**
1866
+ * @public
1867
+ * An element that renders text content.
1868
+ */
1869
+ export declare type TextElement = NativeTextElement;
1870
+
1871
+ /**
1872
+ * @public
1873
+ * An element that renders text content and has positional properties.
1874
+ */
1875
+ export declare type TextElementAtPoint = NativeTextElementWithBox;
1876
+
1877
+ /**
1878
+ * @public
1879
+ * A region of richtext.
1880
+ */
1881
+ export declare type TextRegion = {
1882
+ /**
1883
+ * The plaintext content of the region.
1884
+ */
1885
+ text: string;
1886
+ /**
1887
+ * The formatting of the region.
1888
+ */
1889
+ formatting?: Partial<RichtextFormatting>;
1890
+ };
1891
+
1892
+ /**
1893
+ * @public
1894
+ * Provides methods for adding drag and drop behavior to an app.
1895
+ */
1896
+ export declare interface UI {
1897
+ /**
1898
+ * @deprecated The method has been superseded by `startDragToPoint`.
1899
+ * @public
1900
+ * Adds the specified element or content to a design at the end of a drag event.
1901
+ *
1902
+ * @param event - A drag start event.
1903
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
1904
+ */
1905
+ startDrag<E extends HTMLElement>(
1906
+ event: DragStartEvent<E>,
1907
+ dragData:
1908
+ | TextDragConfig
1909
+ | AudioDragConfig
1910
+ | EmbedDragConfig
1911
+ | VideoDragConfigForElement<E>
1912
+ | ImageDragConfigForElement<E>
1913
+ ): Promise<void>;
1914
+ /**
1915
+ * @public
1916
+ * Adds the specified element or content to fixed designs, which use a coordinate-based positioning system at the end of a drag event.
1917
+ *
1918
+ * @param event - A drag start event.
1919
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
1920
+ */
1921
+ startDragToPoint<E extends HTMLElement>(
1922
+ event: DragStartEvent<E>,
1923
+ dragData:
1924
+ | TextDragConfig
1925
+ | AudioDragConfig
1926
+ | EmbedDragConfig
1927
+ | VideoDragConfigForElement<E>
1928
+ | ImageDragConfigForElement<E>
1929
+ ): Promise<void>;
1930
+ /**
1931
+ * @public
1932
+ * Adds the specified element or content to responsive documents, which slot things into a text stream at the end of a drag event.
1933
+ *
1934
+ * @param event - A drag start event.
1935
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
1936
+ */
1937
+ startDragToCursor<E extends HTMLElement>(
1938
+ event: DragStartEvent<E>,
1939
+ dragData:
1940
+ | EmbedDragConfig
1941
+ | VideoDragConfigForElement<E>
1942
+ | ImageDragConfigForElement<E>
1943
+ ): Promise<void>;
1944
+ }
1945
+
1946
+ /**
1947
+ * An alias for the UI interface, providing access to ui related functionality
1948
+ * @public
1949
+ */
1950
+ export declare const ui: UI;
1951
+
1952
+ /**
1953
+ * @public
1954
+ * A data type that can be used in app element data.
1955
+ */
1956
+ export declare type Value =
1957
+ | Primitive
1958
+ | ObjectPrimitive
1959
+ | Exclude<Value, undefined>[]
1960
+ | {
1961
+ [key: string]: Value;
1962
+ };
1963
+
1964
+ /**
1965
+ * @public
1966
+ * Video element or content to be added to the design at the end of a drag event.
1967
+ */
1968
+ export declare type VideoDragConfig = {
1969
+ /**
1970
+ * The type of element.
1971
+ */
1972
+ type: "video";
1973
+ /**
1974
+ * A function that returns a reference (ref) to a video asset in Canva's backend.
1975
+ */
1976
+ resolveVideoRef: () => Promise<{
1977
+ ref: VideoRef;
1978
+ }>;
1979
+ /**
1980
+ * The dimensions of the preview image.
1981
+ */
1982
+ previewSize: Dimensions;
1983
+ /**
1984
+ * The dimensions of the full-size video.
1985
+ *
1986
+ * @remarks
1987
+ * - These dimensions are used when adding the video to the design
1988
+ * - If omitted, the `previewSize` dimensions are used as a fallback.
1989
+ */
1990
+ fullSize?: Dimensions;
1991
+ /**
1992
+ * The URL of an image to display under the user's cursor during the drag and drop event.
1993
+ */
1994
+ previewUrl: string;
1995
+ };
1996
+
1997
+ /**
1998
+ * @public
1999
+ * Video element or content to be added to the design at the end of a drag event.
2000
+ */
2001
+ export declare type VideoDragConfigForElement<E extends Element> =
2002
+ E extends HTMLImageElement
2003
+ ? Partial<VideoDragConfig> &
2004
+ Pick<VideoDragConfig, "type" | "resolveVideoRef">
2005
+ : VideoDragConfig;
2006
+
2007
+ /**
2008
+ * @public
2009
+ * An element that renders video content.
2010
+ */
2011
+ export declare type VideoElement = NativeVideoElement;
2012
+
2013
+ /**
2014
+ * @public
2015
+ * An element that renders video content and has positional properties.
2016
+ */
2017
+ export declare type VideoElementAtPoint = NativeVideoElementWithBox;
2018
+
2019
+ /**
2020
+ * @public
2021
+ * A video asset that fills a path's interior.
2022
+ */
2023
+ export declare type VideoFill = {
2024
+ /**
2025
+ * The type of fill.
2026
+ */
2027
+ type: "video";
2028
+ /**
2029
+ * A unique identifier that points to a video asset in Canva's backend.
2030
+ */
2031
+ ref: VideoRef;
2032
+ };
2033
+
2034
+ /**
2035
+ * @public
2036
+ * A unique identifier that references a video asset in Canva's backend.
2037
+ */
2038
+ export declare type VideoRef = string & {
2039
+ __videoRef: never;
2040
+ };
2041
+
2042
+ /**
2043
+ * A set of dimensions with an auto-calculated height.
2044
+ */
2045
+ declare type Width = {
2046
+ /**
2047
+ * A width, in pixels.
2048
+ *
2049
+ * @remarks
2050
+ * - The pixels are relative to their container.
2051
+ * - Minimum: 0
2052
+ * - Maximum: 32767
2053
+ */
2054
+ width: number;
2055
+ /**
2056
+ * Indicates that the height should be auto-calculated.
2057
+ */
2058
+ height: "auto";
2059
+ };
2060
+
2061
+ /**
2062
+ * A set of dimensions, in pixels.
2063
+ */
2064
+ declare type WidthAndHeight = {
2065
+ /**
2066
+ * A width, in pixels.
2067
+ *
2068
+ * @remarks
2069
+ * - The pixels are relative to their container.
2070
+ * - Minimum: 0
2071
+ * - Maximum: 32767
2072
+ */
2073
+ width: number;
2074
+ /**
2075
+ * A height, in pixels.
2076
+ *
2077
+ * @remarks
2078
+ * - The pixels are relative to their container.
2079
+ * - Minimum: 0
2080
+ * - Maximum: 32767
2081
+ */
2082
+ height: number;
2083
+ };
2084
+
2085
+ export {};