@canva/design 1.10.0 → 2.0.0-beta.1

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/beta.d.ts ADDED
@@ -0,0 +1,2910 @@
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
+ * @beta
333
+ * Options for configuring where content in a design should be queried from.
334
+ */
335
+ declare type ContextOptions = {
336
+ context: "current_page";
337
+ };
338
+
339
+ /**
340
+ * @public
341
+ * A set of X and Y coordinates.
342
+ */
343
+ export declare type Coordinates = {
344
+ /**
345
+ * X coordinate, in pixels.
346
+ */
347
+ x: number;
348
+ /**
349
+ * Y coordinate, in pixels.
350
+ */
351
+ y: number;
352
+ };
353
+
354
+ /**
355
+ * @public
356
+ * Creates a new RichtextRange object, which contains methods to manipulate text.
357
+ */
358
+ export declare function createRichtextRange(): RichtextRange;
359
+
360
+ /**
361
+ * @beta
362
+ * Describes a part of a design.
363
+ */
364
+ export declare type DesignContext = DesignContextOptions["type"];
365
+
366
+ /**
367
+ * @beta
368
+ * Options for configuring which part of a design to read.
369
+ */
370
+ declare type DesignContextOptions = {
371
+ /**
372
+ * The type of context.
373
+ */
374
+ type: "current_page";
375
+ };
376
+
377
+ /**
378
+ * @beta
379
+ * Provides methods for reading and updating the structure and content of a design.
380
+ */
381
+ export declare namespace DesignEditing {
382
+ /**
383
+ * @beta
384
+ * A snapshot containing a fragment of a design's structure and content.
385
+ */
386
+ export type DesignDraft<D> = Readonly<D> & {
387
+ /**
388
+ * Saves any changes made to the draft.
389
+ *
390
+ * @remarks
391
+ * - Any changes to the draft are only reflected in the design after this method is called.
392
+ * - Once this method is called, further changes to the draft are not possible.
393
+ */
394
+ save(): Promise<void>;
395
+ };
396
+ /**
397
+ * @beta
398
+ * Options for creating an image fill in the element builder
399
+ */
400
+ export type ImageFillOpts = Partial<ImageFill> &
401
+ Required<Pick<ImageFill, "type" | "imageRef">>;
402
+ /**
403
+ * @beta
404
+ * Options for creating a video fill in the element builder
405
+ */
406
+ export type VideoFillOpts = Partial<VideoFill> &
407
+ Required<Pick<VideoFill, "type" | "videoRef">>;
408
+ /**
409
+ * @beta
410
+ * Options for creating a media fill in the element builder
411
+ */
412
+ export type MediaFillOpts = ImageFillOpts | VideoFillOpts;
413
+ /**
414
+ * @beta
415
+ * Options for creating a fill in the element builder
416
+ */
417
+ export type FillOpts =
418
+ | {
419
+ color: ColorFillOpts;
420
+ media?: MediaFillOpts;
421
+ }
422
+ | {
423
+ color?: ColorFillOpts;
424
+ media: MediaFillOpts;
425
+ };
426
+ /**
427
+ * @beta
428
+ */
429
+ export type ColorFillOpts = Exclude<ColorFill, Unsupported>;
430
+ /**
431
+ * @beta
432
+ * Options for creating a stroke in the element builder
433
+ */
434
+ export type StrokeOpts = Pick<Stroke, "weight"> & {
435
+ color: ColorFillOpts;
436
+ };
437
+ /**
438
+ * @beta
439
+ * Options for creating a shape path in the element builder
440
+ */
441
+ export type ShapePathOpts = Pick<Path, "d"> & {
442
+ fill?: FillOpts;
443
+ stroke?: StrokeOpts;
444
+ };
445
+ /**
446
+ * @beta
447
+ * Options for creating a rect element.
448
+ */
449
+ export type CreateRectElementOpts = Required<
450
+ Pick<Element, "top" | "left" | "width" | "height">
451
+ > & {
452
+ fill?: FillOpts;
453
+ } & {
454
+ stroke?: StrokeOpts;
455
+ } & Partial<Omit<RectElement, "fill" | "stroke" | "type">>;
456
+ /**
457
+ * @beta
458
+ * Options for creating a shape element.
459
+ */
460
+ export type CreateShapeElementOpts = Required<
461
+ Pick<ShapeElement, "top" | "left" | "width" | "height" | "viewBox">
462
+ > & {
463
+ paths: ShapePathOpts[];
464
+ } & Partial<Omit<ShapeElement, "type" | "paths">>;
465
+ /**
466
+ * @beta
467
+ * Options for creating an embed element.
468
+ */ export type CreateEmbedElementOpts = Required<
469
+ Pick<EmbedElement, "top" | "left" | "width" | "height" | "url">
470
+ > &
471
+ Partial<Omit<EmbedElement, "type">>;
472
+ /**
473
+ * @beta
474
+ * Options for creating a text element.
475
+ */
476
+ export type CreateTextElementOpts = Required<
477
+ Pick<TextElement, "top" | "left" | "width" | "text">
478
+ > &
479
+ Partial<Omit<TextElement, "type" | "height">>;
480
+ /**
481
+ * @beta
482
+ * Provides methods for creating elements.
483
+ *
484
+ * @remarks
485
+ * These methods don't add the elements to the design. They only return elements that can
486
+ * be added to a design, such as with the `insertAfter` method.
487
+ */
488
+ export interface ElementBuilder {
489
+ /**
490
+ * Creates a rect element.
491
+ * @param opts - Options for creating the rect element.
492
+ */
493
+ createRectElement(opts: CreateRectElementOpts): RectElement;
494
+ /**
495
+ * Creates a shape element.
496
+ * @param opts - Options for creating the shape element.
497
+ */
498
+ createShapeElement(opts: CreateShapeElementOpts): ShapeElement;
499
+ /**
500
+ * Creates an embed element.
501
+ * @param opts - Options for creating the embed element.
502
+ */
503
+ createEmbedElement(opts: CreateEmbedElementOpts): EmbedElement;
504
+ /**
505
+ * Creates a text element.
506
+ * @param opts - Options for creating the text element.
507
+ */
508
+ createTextElement(opts: CreateTextElementOpts): TextElement;
509
+ /**
510
+ * Creates a richtext range.
511
+ */
512
+ createRichtextRange(): RichtextRange;
513
+ }
514
+ /**
515
+ * @beta
516
+ * The result of reading part of a design when the context is the current page.
517
+ */
518
+ export type CurrentPageResult = DesignDraft<{
519
+ /**
520
+ * The current page of the design.
521
+ */
522
+ page: FixedPage;
523
+ }>;
524
+ /**
525
+ * @beta
526
+ * The result of reading part of a design.
527
+ */
528
+ export type DesignOpenResult = CurrentPageResult;
529
+ /**
530
+ * A function called for each item in the list.
531
+ *
532
+ * @param item - The current item in the list.
533
+ * @param index - The index of the current item.
534
+ */
535
+ export type ForEachCallback<T> = (item: T, index: number) => void;
536
+ /**
537
+ * A function that determines if an item should be included in the result.
538
+ *
539
+ * @param item - The item to test.
540
+ * @returns `true` if the item should be included, otherwise `false`.
541
+ */
542
+ export type FilterPredicate<T> = (item: T) => boolean;
543
+ /**
544
+ * A type predicate function that determines if an item is of a specific type.
545
+ *
546
+ * @param item - The item to test.
547
+ * @returns `true` if the item is of type `C`, otherwise `false`.
548
+ */
549
+ export type TypeFilterPredicate<T, C extends T> = (item: T) => item is C;
550
+ /**
551
+ * A list that cannot be changed.
552
+ */
553
+ export interface ReadableList<T> {
554
+ /**
555
+ * Gets the number of items in the list.
556
+ *
557
+ * @returns The number of items.
558
+ */
559
+ count(): number;
560
+ /**
561
+ * Converts the list to an array.
562
+ *
563
+ * @returns An array containing all items. The items are the same as in the list.
564
+ */
565
+ toArray(): readonly T[];
566
+ /**
567
+ * Executes a function for each item in the list.
568
+ *
569
+ * @param callback - The function to run for each item.
570
+ */
571
+ forEach(callback: ForEachCallback<T>): void;
572
+ /**
573
+ * Creates a new array with items that match a specific type.
574
+ *
575
+ * @param filter - A function that checks if an item is of type `C`.
576
+ * @returns An array of items that are of type `C`.
577
+ */
578
+ filter<C extends T>(filter: TypeFilterPredicate<T, C>): readonly C[];
579
+ /**
580
+ * Creates a new array with items that pass a test.
581
+ *
582
+ * @param filter - A function that tests each item. Returns `true` to keep the item.
583
+ * @returns An array of items that passed the test.
584
+ */
585
+ filter(filter: FilterPredicate<T>): readonly T[];
586
+ }
587
+ /**
588
+ * @beta
589
+ * A list of items that can be changed.
590
+ */
591
+ export interface MutableList<T> {
592
+ /**
593
+ * Adds a copy of an item to the list and places it right before another item.
594
+ *
595
+ * @param ref - The existing item to place the new item before.
596
+ * If `ref` is `undefined`, the new item is added at the end of the list.
597
+ * If `ref` does not exist in the list, the operation fails.
598
+ *
599
+ * @param item - The item to add. A copy of this item will be inserted.
600
+ *
601
+ * @returns
602
+ * The added item, or `undefined` if the operation failed.
603
+ */
604
+ insertBefore(ref: T | undefined, item: T): T | undefined;
605
+ /**
606
+ * Adds a copy of an item to the list and places it right after another item.
607
+ *
608
+ * @param ref - The existing item to place the new item after.
609
+ * If `ref` is `undefined`, the new item is added at the end of the list.
610
+ * If `ref` does not exist in the list, the operation fails.
611
+ *
612
+ * @param item - The item to add. A copy of this item will be inserted.
613
+ *
614
+ * @returns
615
+ * The added item, or `undefined` if the operation failed.
616
+ */
617
+ insertAfter(ref: T | undefined, item: T): T | undefined;
618
+ /**
619
+ * Moves an existing item to a new position right before another item.
620
+ *
621
+ * @param ref - The existing item to move the item before.
622
+ * If `ref` is `undefined`, the item is moved to the end of the list.
623
+ * If `ref` does not exist in the list, the operation fails.
624
+ *
625
+ * @param item - The item to move.
626
+ * The operation fails if the item is not already in the list.
627
+ */
628
+ moveBefore(ref: T | undefined, item: T): void;
629
+ /**
630
+ * Moves an existing item to a new position right after another item.
631
+ *
632
+ * @param ref - The existing item to move the item after.
633
+ * If `ref` is `undefined`, the item is moved to the end of the list.
634
+ * If `ref` does not exist in the list, the operation fails.
635
+ *
636
+ * @param item - The item to move.
637
+ * The operation fails if the item is not already in the list.
638
+ */
639
+ moveAfter(ref: T | undefined, item: T): void;
640
+ /**
641
+ * Removes an item from the list.
642
+ *
643
+ * @param item - The item to remove from the list.
644
+ */
645
+ delete(item: T): void;
646
+ }
647
+ /**
648
+ * @beta
649
+ * A list of items that can be read and updated.
650
+ */
651
+ export interface List<T> extends ReadableList<T>, MutableList<T> {}
652
+ /**
653
+ * @beta
654
+ * Represents an element that's not supported by the Apps SDK.
655
+ */
656
+ export interface Unsupported {
657
+ /**
658
+ * The type of element.
659
+ */
660
+ readonly type: "unsupported";
661
+ }
662
+ /**
663
+ * @beta
664
+ * A single valid character in a hex code.
665
+ */
666
+ export type Hex = `123456790abcdef`[number];
667
+ /**
668
+ * @beta
669
+ * A six-character hexadecimal color code prefixed with a `#`.
670
+ */
671
+ export type HexCode = `#${Hex}${Hex}${Hex}${Hex}${Hex}${Hex}`;
672
+ /**
673
+ * @beta
674
+ * A set of dimensions.
675
+ */
676
+ export interface Dimensions {
677
+ /**
678
+ * A width, in pixels.
679
+ */
680
+ readonly width: number;
681
+ /**
682
+ * A height, in pixels.
683
+ */
684
+ readonly height: number;
685
+ }
686
+ /**
687
+ * @beta
688
+ * An image that fills the interior of a path.
689
+ */
690
+ export interface ImageFill {
691
+ /**
692
+ * The type of media.
693
+ */
694
+ readonly type: "image";
695
+ /**
696
+ * A unique identifier that points to an image asset in Canva's backend.
697
+ */
698
+ imageRef: string;
699
+ /**
700
+ * If `true`, the image is flipped horizontally.
701
+ */
702
+ flipX: boolean;
703
+ /**
704
+ * If `true`, the image is flipped vertically.
705
+ */
706
+ flipY: boolean;
707
+ }
708
+ /**
709
+ * @beta
710
+ * A video that fills the interior of a path.
711
+ */
712
+ export interface VideoFill {
713
+ /**
714
+ * The type of media.
715
+ */
716
+ readonly type: "video";
717
+ /**
718
+ * A unique identifier that points to a video asset in Canva's backend.
719
+ */
720
+ videoRef: string;
721
+ /**
722
+ * If `true`, the video is flipped horizontally.
723
+ */
724
+ flipX: boolean;
725
+ /**
726
+ * If `true`, the video is flipped vertically.
727
+ */
728
+ flipY: boolean;
729
+ }
730
+ /**
731
+ * @beta
732
+ * A media item that fills the interior of a path.
733
+ */
734
+ export type MediaFill = ImageFill | VideoFill;
735
+ /**
736
+ * @beta
737
+ * A solid color that fills the interior of a path.
738
+ */
739
+ export interface SolidFill {
740
+ /**
741
+ * The type of color.
742
+ */
743
+ readonly type: "solid";
744
+ /**
745
+ * The color of the fill, as a hex code.
746
+ *
747
+ * @remarks
748
+ * - Must be six characters long.
749
+ * - Must start with a `#`.
750
+ * - Must use lowercase letters.
751
+ */
752
+ color: HexCode;
753
+ }
754
+ /**
755
+ * @beta
756
+ * A color that fills the interior of a path.
757
+ */
758
+ export type ColorFill = SolidFill | Unsupported;
759
+ /**
760
+ * @beta
761
+ * Describes how a path is filled with color or media.
762
+ *
763
+ * @remarks
764
+ * If both `media` and `color` are defined, `media` takes precedence.
765
+ */
766
+ export interface Fill {
767
+ /**
768
+ * The media fill for the path, if any.
769
+ */
770
+ media: MediaFill | undefined;
771
+ /**
772
+ * The color fill for the path, if any.
773
+ */
774
+ color: ColorFill | undefined;
775
+ }
776
+ /**
777
+ * @beta
778
+ * The scale and cropping of a shape.
779
+ *
780
+ * @remarks
781
+ * This is similar to the `viewBox` attribute of an `SVGElement`.
782
+ */
783
+ export type AlignedBox = {
784
+ /**
785
+ * The distance of the shape from the top edge of the element, in pixels.
786
+ */
787
+ readonly top: number;
788
+ /**
789
+ * The distance of the shape from the left edge of the element, in pixels.
790
+ */
791
+ readonly left: number;
792
+ /**
793
+ * The width of the view box, in pixels.
794
+ */
795
+ readonly width: number;
796
+ /**
797
+ * The height of the view box, in pixels.
798
+ */
799
+ readonly height: number;
800
+ };
801
+ /**
802
+ * @beta
803
+ * A path that defines the structure of a shape element.
804
+ */
805
+ export interface Path {
806
+ /**
807
+ * The shape of the path.
808
+ *
809
+ * @remarks
810
+ * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
811
+ *
812
+ * - Must start with an `M` command.
813
+ * - Only one `M` command is allowed.
814
+ * - `Q` and `T` commands are not permitted.
815
+ * - The path must be closed using a `Z` command or matching start and end coordinates.
816
+ */
817
+ readonly d: string;
818
+ /**
819
+ * The appearance of the path's interior.
820
+ */
821
+ readonly fill: Fill;
822
+ /**
823
+ * The stroke (outline) of the path, if any.
824
+ */
825
+ readonly stroke: Stroke | undefined;
826
+ }
827
+ /**
828
+ * @beta
829
+ * Represents an outline, such as the border of an element.
830
+ */
831
+ export interface Stroke {
832
+ /**
833
+ * The weight (thickness) of the stroke.
834
+ *
835
+ * @remarks
836
+ * - Minimum: 0
837
+ * - Maximum: 100
838
+ */
839
+ weight: number;
840
+ /**
841
+ * The color of the stroke.
842
+ */
843
+ color: ColorFill;
844
+ }
845
+ /**
846
+ * @beta
847
+ * The basic properties of an element.
848
+ *
849
+ * @remarks
850
+ * These properties are shared by all elements in a design.
851
+ */
852
+ export interface Element extends Dimensions {
853
+ /**
854
+ * If `true`, the element is locked and cannot be modified.
855
+ */
856
+ readonly locked: boolean;
857
+ /**
858
+ * The distance from the top edge of the container, in pixels.
859
+ *
860
+ * @remarks
861
+ * - The pixels are relative to their container.
862
+ * - Minimum: -32768
863
+ * - Maximum: 32767
864
+ */
865
+ top: number;
866
+ /**
867
+ * The distance from the left edge of the container, in pixels.
868
+ *
869
+ * @remarks
870
+ * - The pixels are relative to their container.
871
+ * - Minimum: -32768
872
+ * - Maximum: 32767
873
+ */
874
+ left: number;
875
+ /**
876
+ * A rotation, in degrees.
877
+ *
878
+ * @remarks
879
+ * - Minimum: -180
880
+ * - Maximum: 180
881
+ */
882
+ rotation: number;
883
+ /**
884
+ * Transparency as a percentage.
885
+ *
886
+ * @remarks
887
+ * - Minimum: 0
888
+ * - Maximum: 1
889
+ */
890
+ transparency: number;
891
+ }
892
+ /**
893
+ * @beta
894
+ * Represents a rectangular element.
895
+ */
896
+ export interface Rect {
897
+ /**
898
+ * The type of content.
899
+ */
900
+ readonly type: "rect";
901
+ /**
902
+ * The appearance of the rectangle's interior.
903
+ */
904
+ readonly fill: Fill;
905
+ /**
906
+ * The outline of the rectangle.
907
+ */
908
+ readonly stroke: Stroke;
909
+ }
910
+ /**
911
+ * @beta
912
+ * Represents a vector shape element.
913
+ */
914
+ export interface Shape {
915
+ /**
916
+ * The type of content.
917
+ */
918
+ readonly type: "shape";
919
+ /**
920
+ * The scale and cropping of the shape.
921
+ */
922
+ viewBox: AlignedBox;
923
+ /**
924
+ * The paths that define the structure of the shape.
925
+ *
926
+ * @remarks
927
+ * - Must have between 1 and 30 paths.
928
+ * - Total size of all paths must not exceed 2kb.
929
+ * - Maximum of 6 unique fill colors across all paths.
930
+ */
931
+ readonly paths: ReadableList<Path>;
932
+ }
933
+ /**
934
+ * @beta
935
+ * Represents group content.
936
+ */
937
+ export interface Group<C> {
938
+ /**
939
+ * The type of content.
940
+ */
941
+ readonly type: "group";
942
+ /**
943
+ * The elements that exist within the group.
944
+ */
945
+ readonly contents: ReadableList<C>;
946
+ }
947
+ /**
948
+ * @beta
949
+ * Represents rich media content.
950
+ */
951
+ export interface Embed {
952
+ /**
953
+ * The type of content.
954
+ */
955
+ readonly type: "embed";
956
+ /**
957
+ * The URL of the rich media.
958
+ *
959
+ * @remarks
960
+ * This URL must be supported by the Iframely API.
961
+ */
962
+ readonly url: string;
963
+ }
964
+ /**
965
+ * @beta
966
+ * Represents text content.
967
+ */
968
+ export interface Text {
969
+ /**
970
+ * The type of content.
971
+ */
972
+ readonly type: "text";
973
+ /**
974
+ * The text content.
975
+ */
976
+ readonly text: RichtextRange;
977
+ }
978
+ /**
979
+ * @beta
980
+ * An element that renders a rectangle.
981
+ *
982
+ * @remarks
983
+ * The rectangle can be filled with image content, video content, or a solid color.
984
+ */
985
+ export interface RectElement extends Rect, Element {}
986
+ /**
987
+ * @beta
988
+ * An element that renders a vector shape.
989
+ */
990
+ export interface ShapeElement extends Shape, Element {}
991
+ /**
992
+ * @beta
993
+ * An element that renders a group of other elements.
994
+ */
995
+ export interface GroupElement extends Group<GroupContentElement>, Element {}
996
+ /**
997
+ * @beta
998
+ * An element that embeds rich media, such as a YouTube video.
999
+ */
1000
+ export interface EmbedElement extends Embed, Element {}
1001
+ /**
1002
+ * @beta
1003
+ * An element that renders text content.
1004
+ */
1005
+ export interface TextElement extends Text, Element {}
1006
+ /**
1007
+ * @beta
1008
+ * An element that is not supported by the Apps SDK.
1009
+ */
1010
+ export interface UnsupportedElement extends Unsupported, Element {}
1011
+ /**
1012
+ * @beta
1013
+ * An element that can exist in a group element.
1014
+ */
1015
+ export type GroupContentElement =
1016
+ | RectElement
1017
+ | ShapeElement
1018
+ | EmbedElement
1019
+ | TextElement
1020
+ | UnsupportedElement;
1021
+ /**
1022
+ * @beta
1023
+ * An element that can exist on a fixed page.
1024
+ */
1025
+ export type FixedElement =
1026
+ | RectElement
1027
+ | ShapeElement
1028
+ | GroupElement
1029
+ | EmbedElement
1030
+ | TextElement
1031
+ | UnsupportedElement;
1032
+ /**
1033
+ * @beta
1034
+ * A page with fixed dimensions.
1035
+ */
1036
+ export interface FixedPage {
1037
+ /**
1038
+ * The type of page.
1039
+ */
1040
+ readonly type: "fixed";
1041
+ /**
1042
+ * If `true`, the page is locked and cannot be modified.
1043
+ */
1044
+ readonly locked: boolean;
1045
+ /**
1046
+ * The dimensions of the page. `dimensions` is undefined for whiteboard pages.
1047
+ */
1048
+ readonly dimensions: Dimensions | undefined;
1049
+ /**
1050
+ * The background of the page. `background` is undefined for whiteboard pages.
1051
+ */
1052
+ readonly background: Fill | undefined;
1053
+ /**
1054
+ * The elements on the page.
1055
+ *
1056
+ * @remarks
1057
+ * Elements are rendered in the order they appear in the list.
1058
+ * Later elements appear on top of earlier ones.
1059
+ */
1060
+ readonly elements: List<FixedElement>;
1061
+ }
1062
+ /**
1063
+ * @beta
1064
+ * A page in a design.
1065
+ */
1066
+ export type Page = FixedPage | Unsupported;
1067
+
1068
+ {
1069
+ }
1070
+ }
1071
+
1072
+ /**
1073
+ * @public
1074
+ * An element that's natively supported by the Canva editor.
1075
+ */
1076
+ export declare type DesignElement = NativeElement;
1077
+
1078
+ /**
1079
+ * @beta
1080
+ * A callback for reading and updating part of a design.
1081
+ * @param draft - The result of reading part of a design.
1082
+ * @param helpers - Helper methods for reading and updating the design.
1083
+ */
1084
+ export declare type DesignOpenCallback = (
1085
+ draft: DesignEditing.DesignOpenResult,
1086
+ helpers: {
1087
+ /**
1088
+ * Provides methods for creating elements.
1089
+ */
1090
+ elementBuilder: DesignEditing.ElementBuilder;
1091
+ }
1092
+ ) => Promise<void> | void;
1093
+
1094
+ /**
1095
+ * @beta
1096
+ * Options for configuring which part of a design to read.
1097
+ */
1098
+ export declare type DesignOpenOptions = DesignContextOptions;
1099
+
1100
+ /**
1101
+ * @public
1102
+ * Provides methods for managing the lifecycle of overlays, such as selected image overlays.
1103
+ */
1104
+ export declare type DesignOverlay = {
1105
+ /**
1106
+ * Registers a callback that runs when the `canOpen` state of an overlay target changes.
1107
+ * @param opts - Options for configuring the callback.
1108
+ */
1109
+ registerOnCanOpen<Target extends OverlayTarget>(opts: {
1110
+ /**
1111
+ * The target to check the `canOpen` state of.
1112
+ */
1113
+ target: Target;
1114
+ /**
1115
+ * A callback that runs when the `canOpen` state of the specified target changes.
1116
+ *
1117
+ * @param event - Information about whether or not an overlay can be opened for the specified target.
1118
+ *
1119
+ * @remarks
1120
+ * This callback fires immediately.
1121
+ */
1122
+ onCanOpen(event: OverlayOpenableEvent<Target>): void;
1123
+ }): () => void;
1124
+ };
1125
+
1126
+ /**
1127
+ * @public
1128
+ * Provides methods for interacting with selected content.
1129
+ */
1130
+ export declare type DesignSelection = {
1131
+ /**
1132
+ * Registers a callback that runs when the specified type of content is selected.
1133
+ *
1134
+ * @param opts - Options for configuring the content selection callback.
1135
+ *
1136
+ * @remarks
1137
+ * This callback fires immediately if content is already selected when the callback is registered.
1138
+ */
1139
+ registerOnChange<Scope extends SelectionScope>(opts: {
1140
+ /**
1141
+ * The type of content that triggers a selection change event.
1142
+ */
1143
+ scope: Scope;
1144
+ /**
1145
+ * The callback to run when the selected content changes.
1146
+ * @param event - Information about the selection change event.
1147
+ */
1148
+ onChange(event: SelectionEvent<Scope>): void;
1149
+ }): () => void;
1150
+ };
1151
+
1152
+ /**
1153
+ * @public
1154
+ * JWT that contains the Design ID and App ID.
1155
+ */
1156
+ export declare type DesignToken = {
1157
+ token: string;
1158
+ };
1159
+
1160
+ /**
1161
+ * @public
1162
+ * A set of dimensions.
1163
+ */
1164
+ export declare type Dimensions = {
1165
+ /**
1166
+ * A width, in pixels.
1167
+ */
1168
+ width: number;
1169
+ /**
1170
+ * A height, in pixels.
1171
+ */
1172
+ height: number;
1173
+ };
1174
+
1175
+ /**
1176
+ * @public
1177
+ * Callbacks for handling drag and drop events.
1178
+ */
1179
+ export declare type DragCallback = {
1180
+ /**
1181
+ * A callback that runs at the start of a drag event.
1182
+ * @param element - The element being dragged.
1183
+ */
1184
+ onDragStart: (element: HTMLElement) => void;
1185
+ /**
1186
+ * A callback that runs at the end of a drag event.
1187
+ * @param element - The element being dragged.
1188
+ */
1189
+ onDragEnd: (element: HTMLElement) => void;
1190
+ };
1191
+
1192
+ /**
1193
+ * @public
1194
+ * Options for adding drag and drop behavior to an `HTMLElement`.
1195
+ */
1196
+ export declare type DraggableElementData = ElementData | ImageElementData;
1197
+
1198
+ /**
1199
+ * @public
1200
+ * An event that occurs when a user starts dragging an HTML element.
1201
+ */
1202
+ export declare type DragStartEvent<E extends Element> = Pick<
1203
+ DragEvent,
1204
+ "dataTransfer" | "currentTarget" | "preventDefault" | "clientX" | "clientY"
1205
+ > & {
1206
+ currentTarget: E;
1207
+ };
1208
+
1209
+ /**
1210
+ * @beta
1211
+ * Options for configuring how a design is read.
1212
+ */
1213
+ export declare type EditContentOptions<T extends ContentType> = {
1214
+ contentType: T;
1215
+ } & ContextOptions;
1216
+
1217
+ /**
1218
+ * @public
1219
+ * Elements targeting a cursor are a subset of the base Element
1220
+ **/
1221
+ export declare type ElementAtCursor =
1222
+ | ImageElement
1223
+ | VideoElement
1224
+ | EmbedElement
1225
+ | TextElement
1226
+ | RichtextElement;
1227
+
1228
+ /**
1229
+ * @public
1230
+ * An element that's natively supported by the Canva editor and has positional properties.
1231
+ */
1232
+ export declare type ElementAtPoint =
1233
+ | NativeElementWithBox
1234
+ | RichtextElementAtPoint;
1235
+
1236
+ /**
1237
+ * @public
1238
+ * Options for adding drag and drop behavior to an `HTMLElement`.
1239
+ */
1240
+ export declare type ElementData = DragCallback & {
1241
+ /**
1242
+ * The `HTMLElement` to be made draggable.
1243
+ */
1244
+ node: HTMLElement;
1245
+ };
1246
+
1247
+ /**
1248
+ * @public
1249
+ * Embed element to be added to the design at the end of a drag event.
1250
+ */
1251
+ export declare type EmbedDragConfig = {
1252
+ /**
1253
+ * The type of element.
1254
+ */
1255
+ type: "embed";
1256
+ /**
1257
+ * The dimensions of the preview image.
1258
+ */
1259
+ previewSize: Dimensions;
1260
+ /**
1261
+ * The URL of an image to display under the user's cursor during the drag and drop event.
1262
+ */
1263
+ previewUrl: string;
1264
+ /**
1265
+ * The URL of media that can be embedded, such as the URL of a YouTube video.
1266
+ *
1267
+ * @remarks
1268
+ * This URL must be supported by the Iframely API.
1269
+ */
1270
+ embedUrl: string;
1271
+ };
1272
+
1273
+ /**
1274
+ * @public
1275
+ * An element that renders rich media, such as a YouTube video.
1276
+ */
1277
+ export declare type EmbedElement = NativeEmbedElement;
1278
+
1279
+ /**
1280
+ * @public
1281
+ * An element that renders rich media, such as a YouTube video, and has positional properties.
1282
+ */
1283
+ export declare type EmbedElementAtPoint = NativeEmbedElementWithBox;
1284
+
1285
+ /**
1286
+ * @public
1287
+ * The result when a user abandons the export flow, such as by closing the export menu.
1288
+ */
1289
+ export declare type ExportAborted = {
1290
+ /**
1291
+ * The status of the export flow.
1292
+ */
1293
+ status: "aborted";
1294
+ };
1295
+
1296
+ /**
1297
+ * @public
1298
+ * The exported file.
1299
+ */
1300
+ export declare type ExportBlob = {
1301
+ /**
1302
+ * The URL of the exported design.
1303
+ *
1304
+ * @remarks
1305
+ * If a user's design contains multiple pages but is exported in a format that doesn't support multiple pages,
1306
+ * this URL will point to a ZIP file that contains each page as a separate file.
1307
+ *
1308
+ * For example:
1309
+ *
1310
+ * - If a single-page design is exported as a JPG, the URL will point to a JPG file.
1311
+ * - 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.
1312
+ * - If a multi-page design is exported as a PDF file, the URL will point to a PDF file.
1313
+ *
1314
+ * The following file types support multiple pages:
1315
+ *
1316
+ * - `"GIF"`
1317
+ * - `"PDF_STANDARD"`
1318
+ * - `"PPTX"`
1319
+ * - `"VIDEO"`
1320
+ *
1321
+ * The following file types do not support multiple pages:
1322
+ *
1323
+ * - `"JPG"`
1324
+ * - `"PNG"`
1325
+ * - `"SVG"`
1326
+ */
1327
+ url: string;
1328
+ };
1329
+
1330
+ /**
1331
+ * @public
1332
+ * The result when a user successfully completes an export flow.
1333
+ */
1334
+ export declare type ExportCompleted = {
1335
+ /**
1336
+ * The status of the export flow.
1337
+ */
1338
+ status: "completed";
1339
+ /**
1340
+ * The title of the design, if set by the user.
1341
+ */
1342
+ title?: string;
1343
+ /**
1344
+ * The exported files.
1345
+ *
1346
+ * @remarks
1347
+ * This array only contains one element. This is because, if a multi-page design is exported as multiple files, the files
1348
+ * 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.
1349
+ */
1350
+ exportBlobs: ExportBlob[];
1351
+ };
1352
+
1353
+ /**
1354
+ * @public
1355
+ * The types of files that Canva supports for exported designs.
1356
+ */
1357
+ export declare type ExportFileType =
1358
+ | "png"
1359
+ | "jpg"
1360
+ | "pdf_standard"
1361
+ | "video"
1362
+ | "gif"
1363
+ | "pptx"
1364
+ | "svg";
1365
+
1366
+ /**
1367
+ * @public
1368
+ * Options for configuring the export of a design.
1369
+ */
1370
+ export declare type ExportRequest = {
1371
+ /**
1372
+ * The types of files the user can export their design as.
1373
+ *
1374
+ * @remarks
1375
+ * You must provide at least one file type.
1376
+ */
1377
+ acceptedFileTypes: ExportFileType[];
1378
+ };
1379
+
1380
+ /**
1381
+ * @public
1382
+ * The result of exporting a design.
1383
+ */
1384
+ export declare type ExportResponse = ExportCompleted | ExportAborted;
1385
+
1386
+ /**
1387
+ * @public
1388
+ * Image element or content to be added to the design at the end of a drag event.
1389
+ *
1390
+ * @remarks
1391
+ * This type is only used when the image data is from an external URL.
1392
+ */
1393
+ export declare type ExternalImageDragConfig = CommonImageDragConfig & {
1394
+ /**
1395
+ * A function that returns a reference (ref) to an audio asset in Canva's backend.
1396
+ */
1397
+ resolveImageRef: () => Promise<{
1398
+ ref: ImageRef;
1399
+ }>;
1400
+ /**
1401
+ * The URL of an image to display under the user's cursor during the drag and drop event.
1402
+ */
1403
+ previewUrl: string;
1404
+ /**
1405
+ * The dimensions of the full-size image.
1406
+ */
1407
+ fullSize?: Dimensions;
1408
+ };
1409
+
1410
+ /**
1411
+ * @public
1412
+ * The appearance of a path's interior.
1413
+ *
1414
+ * @remarks
1415
+ * The `color` and `asset` properties are mutually exclusive.
1416
+ */
1417
+ export declare type Fill = {
1418
+ /**
1419
+ * If `true`, users can replace a fill by dropping an image or video onto it.
1420
+ */
1421
+ dropTarget?: boolean;
1422
+ /**
1423
+ * The color of the fill as a hex code.
1424
+ *
1425
+ * @remarks
1426
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
1427
+ *
1428
+ * @example
1429
+ * " #ff0099"
1430
+ */
1431
+ color?: string;
1432
+ /**
1433
+ * An image or video to use as the fill.
1434
+ */
1435
+ asset?: ImageFill | VideoFill;
1436
+ };
1437
+
1438
+ /**
1439
+ * @public
1440
+ * A reference to a font that can be used in other parts of the SDK.
1441
+ */
1442
+ export declare type FontRef = string & {
1443
+ __fontRef: never;
1444
+ };
1445
+
1446
+ /**
1447
+ * @public
1448
+ * Font weights supported in the SDK.
1449
+ **/
1450
+ export declare type FontWeight =
1451
+ | "normal"
1452
+ | "thin"
1453
+ | "extralight"
1454
+ | "light"
1455
+ | "medium"
1456
+ | "semibold"
1457
+ | "bold"
1458
+ | "ultrabold"
1459
+ | "heavy";
1460
+
1461
+ /**
1462
+ * Allows to get the context of currently selected page.
1463
+ * @public
1464
+ * @returns Page context of currently selected page
1465
+ */
1466
+ export declare const getCurrentPageContext: () => Promise<PageContext>;
1467
+
1468
+ /**
1469
+ * @public
1470
+ * Gets the default dimensions that a new page will have when it is added to a design.
1471
+ * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
1472
+ * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
1473
+ * design that is applied whenever a new page is created.
1474
+ *
1475
+ * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
1476
+ */
1477
+ export declare const getDefaultPageDimensions: () => Promise<
1478
+ Dimensions | undefined
1479
+ >;
1480
+
1481
+ /**
1482
+ * @public
1483
+ * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
1484
+ */
1485
+ export declare function getDesignToken(): Promise<DesignToken>;
1486
+
1487
+ /**
1488
+ * @public
1489
+ * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
1490
+ */
1491
+ export declare type GroupContentAtPoint = NativeSimpleElementWithBox;
1492
+
1493
+ /**
1494
+ * @public
1495
+ * An element that contains two or more elements.
1496
+ */
1497
+ export declare type GroupElement = NativeGroupElement;
1498
+
1499
+ /**
1500
+ * @public
1501
+ * An element that contains two or more elements and has positional properties.
1502
+ */
1503
+ export declare type GroupElementAtPoint = NativeGroupElementWithBox;
1504
+
1505
+ /**
1506
+ * A set of dimensions with an auto-calculated width.
1507
+ */
1508
+ declare type Height = {
1509
+ /**
1510
+ * Indicates that the width should be auto-calculated.
1511
+ */
1512
+ width: "auto";
1513
+ /**
1514
+ * A height, in pixels.
1515
+ *
1516
+ * @remarks
1517
+ * - The pixels are relative to their container.
1518
+ * - Minimum: 0
1519
+ * - Maximum: 32767
1520
+ */
1521
+ height: number;
1522
+ };
1523
+
1524
+ /**
1525
+ * @public
1526
+ * Image element or content to be added to the design at the end of a drag event.
1527
+ */
1528
+ export declare type ImageDragConfig = ExternalImageDragConfig;
1529
+
1530
+ /**
1531
+ * @public
1532
+ * Image element or content to be added to the design at the end of a drag event.
1533
+ */
1534
+ export declare type ImageDragConfigForElement<E extends Element> =
1535
+ E extends HTMLImageElement
1536
+ ? Partial<ImageDragConfig> & Pick<ImageDragConfig, "type">
1537
+ : ImageDragConfig;
1538
+
1539
+ /**
1540
+ * @public
1541
+ * An element that renders image content.
1542
+ */
1543
+ export declare type ImageElement = NativeImageElement;
1544
+
1545
+ /**
1546
+ * @public
1547
+ * An element that renders image content and has positional properties.
1548
+ */
1549
+ export declare type ImageElementAtPoint = NativeImageElementWithBox;
1550
+
1551
+ /**
1552
+ * @public
1553
+ * Options for adding drag and drop behavior to an `HTMLImageElement`.
1554
+ */
1555
+ export declare type ImageElementData = DragCallback & {
1556
+ /**
1557
+ * The `HTMLImageElement` to be made draggable.
1558
+ */
1559
+ node: HTMLImageElement;
1560
+ };
1561
+
1562
+ /**
1563
+ * @public
1564
+ * An image asset that fills a path's interior.
1565
+ */
1566
+ export declare type ImageFill = {
1567
+ /**
1568
+ * The type of fill.
1569
+ */
1570
+ type: "image";
1571
+ /**
1572
+ * A unique identifier that points to an image asset in Canva's backend.
1573
+ */
1574
+ ref: ImageRef;
1575
+ };
1576
+
1577
+ /**
1578
+ * @public
1579
+ * A unique identifier that references an image asset in Canva's backend.
1580
+ */
1581
+ export declare type ImageRef = string & {
1582
+ __imageRef: never;
1583
+ };
1584
+
1585
+ /**
1586
+ * @public
1587
+ * @param appElementConfig - Configuration for an AppElementClient
1588
+ */
1589
+ export declare function initAppElement<A extends AppElementData>(
1590
+ appElementConfig: AppElementClientConfiguration<A>
1591
+ ): AppElementClient<A>;
1592
+
1593
+ /**
1594
+ * @public
1595
+ * Options for formatting inline richtext.
1596
+ */
1597
+ export declare type InlineFormatting = {
1598
+ /**
1599
+ * The color of the text as a hex code.
1600
+ *
1601
+ * @remarks
1602
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
1603
+ *
1604
+ * @example
1605
+ * "#ff0099"
1606
+ */
1607
+ color?: string;
1608
+ /**
1609
+ * The weight (thickness) of the font.
1610
+ *
1611
+ * @remarks
1612
+ * The available font weights depend on the font.
1613
+ *
1614
+ * @defaultValue "normal"
1615
+ */
1616
+ fontWeight?: FontWeight;
1617
+ /**
1618
+ * The style of the font.
1619
+ * @defaultValue "normal"
1620
+ */
1621
+ fontStyle?: "normal" | "italic";
1622
+ /**
1623
+ * The decoration of the text.
1624
+ * @defaultValue "none"
1625
+ */
1626
+ decoration?: "none" | "underline";
1627
+ /**
1628
+ * The strikethrough of the text.
1629
+ * @defaultValue "none"
1630
+ */
1631
+ strikethrough?: "none" | "strikethrough";
1632
+ /**
1633
+ * An external URL that the text links to.
1634
+ */
1635
+ link?: string;
1636
+ };
1637
+
1638
+ /**
1639
+ * @deprecated
1640
+ * @public
1641
+ * An element that's natively supported by the Canva editor.
1642
+ */
1643
+ export declare type NativeElement =
1644
+ | NativeImageElement
1645
+ | NativeVideoElement
1646
+ | NativeEmbedElement
1647
+ | NativeTextElement
1648
+ | NativeShapeElement
1649
+ | NativeGroupElement;
1650
+
1651
+ /**
1652
+ * @public
1653
+ * The types of elements an app can add to a user's design.
1654
+ */
1655
+ export declare type NativeElementType =
1656
+ | "image"
1657
+ | "embed"
1658
+ | "text"
1659
+ | "shape"
1660
+ | "video";
1661
+
1662
+ /**
1663
+ * @deprecated The type has been superseded by `ElementAtPoint`.
1664
+ * @public
1665
+ * An element that's natively supported by the Canva editor and has positional properties.
1666
+ */
1667
+ export declare type NativeElementWithBox =
1668
+ | NativeImageElementWithBox
1669
+ | NativeVideoElementWithBox
1670
+ | NativeEmbedElementWithBox
1671
+ | NativeTextElementWithBox
1672
+ | NativeShapeElementWithBox
1673
+ | NativeGroupElementWithBox;
1674
+
1675
+ /**
1676
+ * @deprecated The type has been superseded by `EmbedElement`.
1677
+ * @public
1678
+ * An element that renders rich media, such as a YouTube video.
1679
+ */
1680
+ export declare type NativeEmbedElement = {
1681
+ /**
1682
+ * The type of element.
1683
+ */
1684
+ type: "embed";
1685
+ /**
1686
+ * The URL of the rich media.
1687
+ *
1688
+ * @remarks
1689
+ * This URL must be supported by the Iframely API.
1690
+ */
1691
+ url: string;
1692
+ };
1693
+
1694
+ /**
1695
+ * @deprecated The type has been superseded by `EmbedElementAtPoint`.
1696
+ * @public
1697
+ * An element that renders rich media, such as a YouTube video, and has positional properties.
1698
+ */
1699
+ export declare type NativeEmbedElementWithBox = {
1700
+ /**
1701
+ * The type of element.
1702
+ */
1703
+ type: "embed";
1704
+ /**
1705
+ * The URL of the rich media.
1706
+ *
1707
+ * @remarks
1708
+ * This URL must be supported by the Iframely API.
1709
+ */
1710
+ url: string;
1711
+ } & Box;
1712
+
1713
+ /**
1714
+ * @deprecated The type has been superseded by `GroupElement`.
1715
+ * @public
1716
+ * An element that contains two or more elements.
1717
+ */
1718
+ export declare type NativeGroupElement = {
1719
+ /**
1720
+ * The type of element.
1721
+ */
1722
+ type: "group";
1723
+ /**
1724
+ * The elements to render within the group.
1725
+ *
1726
+ * @remarks
1727
+ * - Each element within a group must have dimensions and a position.
1728
+ * - The dimensions and positions are relative to the dimensions and positions of the group.
1729
+ */
1730
+ children: NativeSimpleElementWithBox[];
1731
+ };
1732
+
1733
+ /**
1734
+ * @deprecated The type has been superseded by `GroupElementAtPoint`.
1735
+ * @public
1736
+ * An element that contains two or more elements and has positional properties.
1737
+ */
1738
+ export declare type NativeGroupElementWithBox = {
1739
+ /**
1740
+ * The type of element.
1741
+ */
1742
+ type: "group";
1743
+ /**
1744
+ * The elements to render within the group.
1745
+ *
1746
+ * @remarks
1747
+ * - Each element within a group must have dimensions and a position.
1748
+ * - The dimensions and positions are relative to the dimensions and positions of the group.
1749
+ */
1750
+ children: NativeSimpleElementWithBox[];
1751
+ } & Box;
1752
+
1753
+ /**
1754
+ * @deprecated The type has been superseded by `ImageElement`.
1755
+ * @public
1756
+ * An element that renders image content.
1757
+ */
1758
+ export declare type NativeImageElement = {
1759
+ /**
1760
+ * The type of element.
1761
+ */
1762
+ type: "image";
1763
+ /**
1764
+ * A description of the image content.
1765
+ */
1766
+ altText: AltText | undefined;
1767
+ } & (
1768
+ | {
1769
+ /**
1770
+ * A data URL that contains the image data.
1771
+ */
1772
+ dataUrl: string;
1773
+ /**
1774
+ * A unique identifier that points to an image asset in Canva's backend.
1775
+ */
1776
+ ref?: never;
1777
+ }
1778
+ | {
1779
+ /**
1780
+ * A data URL that contains the image data.
1781
+ */
1782
+ dataUrl?: never;
1783
+ /**
1784
+ * A unique identifier that points to an image asset in Canva's backend.
1785
+ */
1786
+ ref: ImageRef;
1787
+ }
1788
+ );
1789
+
1790
+ /**
1791
+ * @deprecated The type has been superseded by `ImageElementAtPoint`.
1792
+ * @public
1793
+ * An element that renders image content and has positional properties.
1794
+ */
1795
+ export declare type NativeImageElementWithBox = NativeImageElement & Box;
1796
+
1797
+ /**
1798
+ * @deprecated The type has been superseded by `ShapeElement`.
1799
+ * @public
1800
+ * An element that renders a vector shape.
1801
+ */
1802
+ export declare type NativeShapeElement = {
1803
+ /**
1804
+ * The type of element.
1805
+ */
1806
+ type: "shape";
1807
+ /**
1808
+ * Options for configuring the scale and cropping of the shape.
1809
+ */
1810
+ viewBox: ShapeViewBox;
1811
+ /**
1812
+ * The paths that define the structure of the shape.
1813
+ *
1814
+ * @remarks
1815
+ * - There must be between 1 and 30 paths (inclusive).
1816
+ * - The maximum combined size of all paths must not exceed 2kb.
1817
+ * - The maximum number of unique fill colors across all paths is 6.
1818
+ */
1819
+ paths: ShapePath[];
1820
+ };
1821
+
1822
+ /**
1823
+ * @deprecated The type has been superseded by `ShapeElementAtPoint`.
1824
+ * @public
1825
+ * An element that renders a vector shape and has positional properties.
1826
+ */
1827
+ export declare type NativeShapeElementWithBox = {
1828
+ /**
1829
+ * The type of element.
1830
+ */
1831
+ type: "shape";
1832
+ /**
1833
+ * Options for configuring the scale and cropping of a shape.
1834
+ */
1835
+ viewBox: ShapeViewBox;
1836
+ /**
1837
+ * The paths that define the structure of the shape.
1838
+ *
1839
+ * @remarks
1840
+ * - There must be between 1 and 30 paths (inclusive).
1841
+ * - The maximum combined size of all paths must not exceed 2kb.
1842
+ * - The maximum number of unique fill colors across all paths is 6.
1843
+ */
1844
+ paths: ShapePath[];
1845
+ } & Box;
1846
+
1847
+ /**
1848
+ * @deprecated The type has been superseded by `GroupContentAtPoint`.
1849
+ * @public
1850
+ * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
1851
+ */
1852
+ export declare type NativeSimpleElementWithBox = Exclude<
1853
+ NativeElementWithBox,
1854
+ NativeGroupElementWithBox
1855
+ >;
1856
+
1857
+ /**
1858
+ * @deprecated The type has been superseded by `TextElement`.
1859
+ * @public
1860
+ * An element that renders text content.
1861
+ */
1862
+ export declare type NativeTextElement = {
1863
+ /**
1864
+ * The type of element.
1865
+ */
1866
+ type: "text";
1867
+ /**
1868
+ * The text content.
1869
+ *
1870
+ * @remarks
1871
+ * Only the first element in this array is used.
1872
+ */
1873
+ children: string[];
1874
+ } & TextAttributes;
1875
+
1876
+ /**
1877
+ * @deprecated The type has been superseded by `TextElementAtPoint`.
1878
+ * @public
1879
+ * An element that renders text content and has positional properties.
1880
+ */
1881
+ export declare type NativeTextElementWithBox = {
1882
+ /**
1883
+ * The type of element.
1884
+ */
1885
+ type: "text";
1886
+ /**
1887
+ * The text content.
1888
+ *
1889
+ * @remarks
1890
+ * Only the first element in this array is used.
1891
+ */
1892
+ children: [string];
1893
+ /**
1894
+ * The width of the element, in pixels.
1895
+ *
1896
+ * @remarks
1897
+ * - Minimum: 0
1898
+ * - Maximum: 32767
1899
+ */
1900
+ width?: number;
1901
+ /**
1902
+ * The distance from the top edge of the container, in pixels.
1903
+ *
1904
+ * @remarks
1905
+ * - Minimum: -32768
1906
+ * - Maximum: 32767
1907
+ */
1908
+ top: number;
1909
+ /**
1910
+ * The distance from the left edge of the container, in pixels.
1911
+ *
1912
+ * @remarks
1913
+ * - Minimum: -32768
1914
+ * - Maximum: 32767
1915
+ */
1916
+ left: number;
1917
+ /**
1918
+ * The rotation of the element, in degrees.
1919
+ *
1920
+ * @remarks
1921
+ * - Minimum: -180
1922
+ * - Maximum: 180
1923
+ */
1924
+ rotation?: number;
1925
+ } & TextAttributes;
1926
+
1927
+ /**
1928
+ * @deprecated The type has been superseded by `VideoElement`.
1929
+ * @public
1930
+ * An element that renders video content.
1931
+ */
1932
+ export declare type NativeVideoElement = {
1933
+ /**
1934
+ * The type of element.
1935
+ */
1936
+ type: "video";
1937
+ /**
1938
+ * A unique identifier that points to a video asset in Canva's backend.
1939
+ */
1940
+ ref: VideoRef;
1941
+ /**
1942
+ * A description of the video content.
1943
+ */
1944
+ altText: AltText | undefined;
1945
+ };
1946
+
1947
+ /**
1948
+ * @deprecated The type has been superseded by `VideoElementAtPoint`.
1949
+ * @public
1950
+ * An element that renders video content and has positional properties.
1951
+ */
1952
+ export declare type NativeVideoElementWithBox = NativeVideoElement & Box;
1953
+
1954
+ /**
1955
+ * An object primitive data type that can be used in app element data.
1956
+ */
1957
+ declare type ObjectPrimitive = Boolean | String;
1958
+
1959
+ /**
1960
+ * @beta
1961
+ * Reads a specified part of the user's design and returns all elements in that part.
1962
+ *
1963
+ * @param options - Options for configuring how a design is read.
1964
+ * @param callback - A callback for operating on the design.
1965
+ */
1966
+ export declare const openDesign: (
1967
+ options: DesignOpenOptions,
1968
+ callback: (
1969
+ draft: DesignEditing.DesignOpenResult,
1970
+ helpers: {
1971
+ elementBuilder: DesignEditing.ElementBuilder;
1972
+ }
1973
+ ) => Promise<void> | void
1974
+ ) => Promise<void>;
1975
+
1976
+ /**
1977
+ * @public
1978
+ * An alias for the DesignOverlay interface, providing access to design overlay related functionality
1979
+ */
1980
+ export declare const overlay: DesignOverlay;
1981
+
1982
+ /**
1983
+ * @public
1984
+ * Information about whether or not an overlay can be opened for the specified target.
1985
+ */
1986
+ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
1987
+ /**
1988
+ * Information about whether or not an overlay can be opened or not for a selected image.
1989
+ */
1990
+ ["image_selection"]:
1991
+ | OverlayUnopenableEvent
1992
+ | {
1993
+ /**
1994
+ * Indicates that the overlay can be opened for the selected image.
1995
+ */
1996
+ canOpen: true;
1997
+ /**
1998
+ * Opens an overlay for the selected image.
1999
+ * @param opts - Options for launching the process associated with the overlay.
2000
+ */
2001
+ readonly open: (options: {
2002
+ /**
2003
+ * Parameters to pass to the overlay when it opens.
2004
+ *
2005
+ * @remarks
2006
+ * This can be any type of structured data.
2007
+ */
2008
+ launchParameters?: any;
2009
+ }) => Promise<AppProcessId>;
2010
+ };
2011
+ }[Target];
2012
+
2013
+ /**
2014
+ * @public
2015
+ * An entity that an overlay can be opened for.
2016
+ */
2017
+ export declare type OverlayTarget = "image_selection";
2018
+
2019
+ /**
2020
+ * @public
2021
+ * Information about an overlay that can't be opened for the specified target.
2022
+ */
2023
+ declare type OverlayUnopenableEvent = {
2024
+ /**
2025
+ * Indicates that the overlay can't be opened for the specified target.
2026
+ */
2027
+ canOpen: false;
2028
+ /**
2029
+ * Indicates the reason the overlay can't be opened for the specified target.
2030
+ */
2031
+ reason: string;
2032
+ };
2033
+
2034
+ /**
2035
+ * @public
2036
+ * The appearance of a page's background.
2037
+ */
2038
+ export declare type PageBackgroundFill = Pick<Fill, "asset" | "color">;
2039
+
2040
+ /**
2041
+ * @public
2042
+ * Information about a page.
2043
+ */
2044
+ export declare type PageContext = {
2045
+ /**
2046
+ * The dimensions of the page, in pixels.
2047
+ *
2048
+ * @remarks
2049
+ * This may be `undefined` because some types of pages don't have dimensions, such as whiteboards.
2050
+ */
2051
+ dimensions: PageDimensions | undefined;
2052
+ };
2053
+
2054
+ /**
2055
+ * @public
2056
+ * A set of page dimensions, in pixels.
2057
+ */
2058
+ export declare type PageDimensions = {
2059
+ /**
2060
+ * The width of the page, in pixels.
2061
+ */
2062
+ width: number;
2063
+ /**
2064
+ * The height of the page, in pixels.
2065
+ */
2066
+ height: number;
2067
+ };
2068
+
2069
+ /**
2070
+ * @public
2071
+ * The outline of a path.
2072
+ */
2073
+ export declare type PathStroke = {
2074
+ /**
2075
+ * The weight (thickness) of the stroke.
2076
+ *
2077
+ * @remarks
2078
+ * - Minimum: 0
2079
+ * - Maximum: 100
2080
+ */
2081
+ weight: number;
2082
+ /**
2083
+ * The color of the stroke as a hex code.
2084
+ *
2085
+ * @remarks
2086
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
2087
+ *
2088
+ * @example
2089
+ * "#ff0099"
2090
+ */
2091
+ color: string;
2092
+ /**
2093
+ * The alignment of the stroke.
2094
+ */
2095
+ strokeAlign: "inset";
2096
+ };
2097
+
2098
+ /**
2099
+ * @public
2100
+ * A position, set of dimensions, and rotation.
2101
+ */
2102
+ export declare type Placement = Position & (WidthAndHeight | Width | Height);
2103
+
2104
+ /**
2105
+ * @deprecated
2106
+ * A position and rotation.
2107
+ */
2108
+ declare type Position = {
2109
+ /**
2110
+ * The distance from the top edge of the container, in pixels.
2111
+ *
2112
+ * @remarks
2113
+ * - The pixels are relative to their container.
2114
+ * - Minimum: -32768
2115
+ * - Maximum: 32767
2116
+ */
2117
+ top: number;
2118
+ /**
2119
+ * The distance from the left edge of the container, in pixels.
2120
+ *
2121
+ * @remarks
2122
+ * - The pixels are relative to their container.
2123
+ * - Minimum: -32768
2124
+ * - Maximum: 32767
2125
+ */
2126
+ left: number;
2127
+ /**
2128
+ * A rotation, in degrees.
2129
+ *
2130
+ * @remarks
2131
+ * - Minimum: -180
2132
+ * - Maximum: 180
2133
+ */
2134
+ rotation?: number;
2135
+ };
2136
+
2137
+ /**
2138
+ * A primitive data type that can be used in app element data.
2139
+ *
2140
+ * @remarks
2141
+ * All primitive data types are supported except for symbols and bigints.
2142
+ */
2143
+ declare type Primitive = undefined | null | number | boolean | string;
2144
+
2145
+ /**
2146
+ * @beta
2147
+ * A snapshot of content returned by a query.
2148
+ *
2149
+ * @remarks
2150
+ * The snapshot is known as the *draft*.
2151
+ */
2152
+ export declare interface QueryContentDraft<T> {
2153
+ /**
2154
+ * The individual content items returned by a query.
2155
+ */
2156
+ readonly contents: readonly T[];
2157
+ /**
2158
+ * Commits any changes made to the items in the `contents` array.
2159
+ *
2160
+ * @remarks
2161
+ * An app must call this method for any changes to be reflected in the user's design.
2162
+ */
2163
+ sync(): Promise<void>;
2164
+ }
2165
+
2166
+ /**
2167
+ * @beta
2168
+ * The result of querying content in a design.
2169
+ */
2170
+ export declare type QueryResult<T extends ContentType> = {
2171
+ ["richtext"]: QueryContentDraft<
2172
+ RichtextRange & {
2173
+ readonly deleted: boolean;
2174
+ }
2175
+ >;
2176
+ }[T];
2177
+
2178
+ /**
2179
+ * @beta
2180
+ * Reads content of the specified type from the user's design.
2181
+ * @param options - Options for configuring how a design is read.
2182
+ * @param callback - A callback for operating on the queried content.
2183
+ */
2184
+ export declare const readContent: <T extends ContentType>(
2185
+ options: EditContentOptions<T>,
2186
+ callback: (draft: QueryResult<T>) => Promise<void> | void
2187
+ ) => Promise<void>;
2188
+
2189
+ /**
2190
+ * @beta
2191
+ * A callback for reading and updating part of a design.
2192
+ * @param draft - The result of reading the content in a design.
2193
+ */
2194
+ export declare type ReadContentCallback<T extends ContentType> = (
2195
+ draft: QueryResult<T>
2196
+ ) => Promise<void> | void;
2197
+
2198
+ /**
2199
+ * @public
2200
+ * Exports the user's design as one or more static files.
2201
+ * @param request - The request object containing configurations of the design export.
2202
+ */
2203
+ export declare const requestExport: (
2204
+ request: ExportRequest
2205
+ ) => Promise<ExportResponse>;
2206
+
2207
+ /**
2208
+ * @public
2209
+ * An element that renders richtext content.
2210
+ */
2211
+ export declare type RichtextElement = {
2212
+ /**
2213
+ * The type of element.
2214
+ */
2215
+ type: "richtext";
2216
+ /**
2217
+ * The richtext content.
2218
+ */
2219
+ range: RichtextRange;
2220
+ };
2221
+
2222
+ /**
2223
+ * @public
2224
+ * An element that renders richtext content.
2225
+ *
2226
+ * @remarks
2227
+ * This type includes properties for controlling the position and dimensions of the
2228
+ * element.
2229
+ * It will be positioned and sized relative to its parent container.
2230
+ * The parent container may be an app element, or the current page.
2231
+ */
2232
+ export declare type RichtextElementAtPoint = RichtextElement & TextBox;
2233
+
2234
+ /**
2235
+ * @public
2236
+ * Options for formatting richtext.
2237
+ */
2238
+ export declare type RichtextFormatting = InlineFormatting & {
2239
+ /**
2240
+ * @public
2241
+ * A unique identifier that points to a font asset in Canva's backend.
2242
+ */
2243
+ fontRef?: FontRef;
2244
+ /**
2245
+ * The size of the text, in pixels.
2246
+ *
2247
+ * @remarks
2248
+ * - In the Canva editor, this number is shown as points (pts), not pixels.
2249
+ * - Minimum: 1
2250
+ * - Maximum: 100
2251
+ */
2252
+ fontSize?: number;
2253
+ /**
2254
+ * The alignment of the text.
2255
+ * @defaultValue "start"
2256
+ */
2257
+ textAlign?: "start" | "center" | "end" | "justify";
2258
+ /**
2259
+ * The list indentation level of the paragraph.
2260
+ */
2261
+ listLevel?: number;
2262
+ /**
2263
+ * The appearance of list item markers.
2264
+ *
2265
+ * @remarks
2266
+ * This property only has an effect if `listLevel` is greater than 0.
2267
+ *
2268
+ * @defaultValue "none"
2269
+ */
2270
+ listMarker?:
2271
+ | "none"
2272
+ | "disc"
2273
+ | "circle"
2274
+ | "square"
2275
+ | "decimal"
2276
+ | "lower-alpha"
2277
+ | "lower-roman"
2278
+ | "checked"
2279
+ | "unchecked";
2280
+ };
2281
+
2282
+ /**
2283
+ * @public
2284
+ * Provides methods for interacting with a range of formatted text.
2285
+ */
2286
+ export declare type RichtextRange = {
2287
+ /**
2288
+ * Formats all of the paragraphs that overlap the given bounds.
2289
+ *
2290
+ * @param bounds - The segment of the range on which to apply the formatting.
2291
+ * @param formatting - The formatting to apply to the paragraph(s).
2292
+ *
2293
+ * @remarks
2294
+ * - The `\n` character indicates the end of a paragraph.
2295
+ * - All paragraphs that overlap the provided bounds will be formatted in their entirety.
2296
+ *
2297
+ */
2298
+ formatParagraph(bounds: Bounds, formatting: RichtextFormatting): void;
2299
+ /**
2300
+ * Formats a region of text with inline formatting properties.
2301
+ *
2302
+ * @param bounds - The segment of the range on which to apply the formatting.
2303
+ * @param formatting - The formatting to apply to the text.
2304
+ */
2305
+ formatText(bounds: Bounds, formatting: InlineFormatting): void;
2306
+ /**
2307
+ * Appends the specified characters to the end of the range.
2308
+ *
2309
+ * @param characters - The characters to append to the richtext range.
2310
+ * @param fo -
2311
+ */
2312
+ appendText(
2313
+ characters: string,
2314
+ formatting?: InlineFormatting
2315
+ ): {
2316
+ bounds: Bounds;
2317
+ };
2318
+ /**
2319
+ * Replaces a region of text with the specified characters.
2320
+ *
2321
+ * @param bounds - The segment of the range to replace.
2322
+ * @param characters - The replacement characters.
2323
+ * @param formatting - The formatting to apply to the replaced text.
2324
+ */
2325
+ replaceText(
2326
+ bounds: Bounds,
2327
+ characters: string,
2328
+ formatting?: InlineFormatting
2329
+ ): {
2330
+ /**
2331
+ * The bounds of the replacement characters within the updated range.
2332
+ */
2333
+ bounds: Bounds;
2334
+ };
2335
+ /**
2336
+ * Returns the current state of the richtext as plaintext.
2337
+ */
2338
+ readPlaintext(): string;
2339
+ /**
2340
+ * Returns the current state of the richtext as one or more text regions.
2341
+ * Each region is an object that contains the text content and its formatting.
2342
+ */
2343
+ readTextRegions(): TextRegion[];
2344
+ };
2345
+
2346
+ /**
2347
+ * @public
2348
+ * An alias for the DesignSelection interface, providing access to design selection related functionality
2349
+ */
2350
+ export declare const selection: DesignSelection;
2351
+
2352
+ /**
2353
+ * @public
2354
+ * Information about the user's selection. To access the selected content, call the `read` method.
2355
+ */
2356
+ export declare interface SelectionEvent<Scope extends SelectionScope> {
2357
+ /**
2358
+ * The type of content that's selected.
2359
+ */
2360
+ readonly scope: Scope;
2361
+ /**
2362
+ * The number of selected elements.
2363
+ */
2364
+ readonly count: number;
2365
+ /**
2366
+ * Creates a snapshot of the selected content and returns a *draft* object.
2367
+ * The draft has a mutable `contents` property for making changes to the selected content.
2368
+ * Any changes made to `contents` are not immediately persisted or reflected in the user's design.
2369
+ * To persist the changes, call the `save` method that's available via the draft.
2370
+ *
2371
+ * @example Replacing text
2372
+ * ```
2373
+ * const draft = await selectionEvent.read();
2374
+ *
2375
+ * for(const content of draft.contents) {
2376
+ * // This change won't immediately appear in the user's design
2377
+ * content.text = "This is the new text";
2378
+ * }
2379
+ *
2380
+ * // The changes will now appear in the user's design
2381
+ * await draft.save();
2382
+ * ```
2383
+ */
2384
+ read(): Promise<ContentDraft<SelectionValue<Scope>>>;
2385
+ }
2386
+
2387
+ /**
2388
+ * @public
2389
+ * Information about a user's selection.
2390
+ */
2391
+ export declare interface SelectionEvent<Scope extends SelectionScope> {
2392
+ /**
2393
+ * The type of content.
2394
+ */
2395
+ readonly scope: Scope;
2396
+ /**
2397
+ * The number of content items in the user's selection.
2398
+ */
2399
+ readonly count: number;
2400
+ /**
2401
+ * Returns a snapshot of the content in the user's selection.
2402
+ *
2403
+ * @remarks
2404
+ * The snapshot is known as the *draft*.
2405
+ */
2406
+ read(): Promise<ContentDraft<SelectionValue<Scope>>>;
2407
+ }
2408
+
2409
+ /**
2410
+ * @public
2411
+ * A type of content that supports selection events.
2412
+ */
2413
+ export declare type SelectionScope =
2414
+ | "plaintext"
2415
+ | "image"
2416
+ | "video"
2417
+ | "richtext";
2418
+
2419
+ /**
2420
+ * @public
2421
+ * A piece of selected content.
2422
+ *
2423
+ * @remarks
2424
+ * The available properties depend on the type (scope) of content.
2425
+ */
2426
+ export declare type SelectionValue<Scope extends SelectionScope> = {
2427
+ /**
2428
+ * A selected range of plaintext.
2429
+ */
2430
+ ["plaintext"]: {
2431
+ /**
2432
+ * The text content.
2433
+ */
2434
+ text: string;
2435
+ };
2436
+ /**
2437
+ * A selected image.
2438
+ */
2439
+ ["image"]: {
2440
+ /**
2441
+ * A unique identifier that points to an image asset in Canva's backend.
2442
+ */
2443
+ ref: ImageRef;
2444
+ };
2445
+ /**
2446
+ * A selected video.
2447
+ */
2448
+ ["video"]: {
2449
+ /**
2450
+ * A unique identifier that points to an video asset in Canva's backend.
2451
+ */
2452
+ ref: VideoRef;
2453
+ };
2454
+ /**
2455
+ * A selected range of formatted text.
2456
+ */
2457
+ ["richtext"]: RichtextRange;
2458
+ }[Scope];
2459
+
2460
+ /**
2461
+ * @public
2462
+ * Updates the background of the user's current page. The background can be a solid color,
2463
+ * an image or a video.
2464
+ */
2465
+ export declare const setCurrentPageBackground: (
2466
+ opts: PageBackgroundFill
2467
+ ) => Promise<void>;
2468
+
2469
+ /**
2470
+ * @public
2471
+ * An element that renders a vector shape.
2472
+ */
2473
+ export declare type ShapeElement = NativeShapeElement;
2474
+
2475
+ /**
2476
+ * @public
2477
+ * An element that renders a vector shape and has positional properties.
2478
+ */
2479
+ export declare type ShapeElementAtPoint = NativeShapeElementWithBox;
2480
+
2481
+ /**
2482
+ * @public
2483
+ * A path that defines the structure of a shape element.
2484
+ */
2485
+ export declare type ShapePath = {
2486
+ /**
2487
+ * The shape of the path.
2488
+ *
2489
+ * @remarks
2490
+ * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
2491
+ *
2492
+ * - The path must start with an M command.
2493
+ * - The path must not have more than one M command.
2494
+ * - The path must not use the Q command.
2495
+ * - The path must be closed, either by:
2496
+ * - Using a Z command at the end of the path
2497
+ * - Having the last coordinate match the first coordinate
2498
+ */
2499
+ d: string;
2500
+ /**
2501
+ * The appearance of the path's interior.
2502
+ */
2503
+ fill: Fill;
2504
+ /**
2505
+ * The outline of the path.
2506
+ */
2507
+ stroke?: PathStroke;
2508
+ };
2509
+
2510
+ /**
2511
+ * @public
2512
+ * Options for configuring the scale and cropping of a shape.
2513
+ *
2514
+ * @remarks
2515
+ * This is similar to the `viewBox` attribute of an `SVGElement`.
2516
+ */
2517
+ export declare type ShapeViewBox = {
2518
+ /**
2519
+ * The distance of the shape from the top edge of the element, in pixels.
2520
+ */
2521
+ top: number;
2522
+ /**
2523
+ * The distance of the shape from the left edge of the element, in pixels.
2524
+ */
2525
+ left: number;
2526
+ /**
2527
+ * The width of the view box, in pixels.
2528
+ */
2529
+ width: number;
2530
+ /**
2531
+ * The height of the view box, in pixels.
2532
+ */
2533
+ height: number;
2534
+ };
2535
+
2536
+ /**
2537
+ * @public
2538
+ * An element that renders a table.
2539
+ */
2540
+ export declare type TableElement = {
2541
+ /**
2542
+ * The type of element.
2543
+ */
2544
+ type: "table";
2545
+ /**
2546
+ * The rows of the table.
2547
+ */
2548
+ rows: {
2549
+ /**
2550
+ * The cells (columns) of the row.
2551
+ *
2552
+ * @remarks
2553
+ * Each row must have the same number of cells.
2554
+ */
2555
+ cells: (Cell | null | undefined)[];
2556
+ }[];
2557
+ };
2558
+
2559
+ /**
2560
+ * @public
2561
+ * Options for configuring the appearance of text.
2562
+ */
2563
+ export declare type TextAttributes = {
2564
+ /**
2565
+ * The size of the text.
2566
+ *
2567
+ * @remarks
2568
+ * - Minimum: 1
2569
+ * - Maximum: 100
2570
+ *
2571
+ * @defaultValue 16
2572
+ */
2573
+ fontSize?: number;
2574
+ /**
2575
+ * The alignment of the text.
2576
+ * @defaultValue "start"
2577
+ */
2578
+ textAlign?: "start" | "center" | "end" | "justify";
2579
+ /**
2580
+ * The color of the text as a hex code.
2581
+ *
2582
+ * @remarks
2583
+ * The hex code must include all six characters and be prefixed with a `#` symbol.
2584
+ *
2585
+ * @example
2586
+ * "#ff0099"
2587
+ */
2588
+ color?: string;
2589
+ /**
2590
+ * @public
2591
+ * A unique identifier that points to a font asset in Canva's backend.
2592
+ */
2593
+ fontRef?: FontRef;
2594
+ /**
2595
+ * The weight (thickness) of the font.
2596
+ * @defaultValue "normal"
2597
+ */
2598
+ fontWeight?: FontWeight;
2599
+ /**
2600
+ * The style of the font.
2601
+ * @defaultValue "normal"
2602
+ */
2603
+ fontStyle?: "normal" | "italic";
2604
+ /**
2605
+ * The decoration of the font.
2606
+ * @defaultValue "none"
2607
+ */
2608
+ decoration?: "none" | "underline";
2609
+ };
2610
+
2611
+ /**
2612
+ * @public
2613
+ * The dimensions, position, and rotation of a text element.
2614
+ */
2615
+ declare type TextBox = {
2616
+ /**
2617
+ * The width, in pixels.
2618
+ *
2619
+ * @remarks
2620
+ * - Minimum: 0
2621
+ * - Maximum: 32767
2622
+ */
2623
+ width?: number;
2624
+ /**
2625
+ * The distance from the top edge of the container, in pixels.
2626
+ *
2627
+ * @remarks
2628
+ * - Minimum: -32767
2629
+ * - Maximum: 32767
2630
+ */
2631
+ top: number;
2632
+ /**
2633
+ * The distance from the left edge of the container, in pixels.
2634
+ *
2635
+ * @remarks
2636
+ * - Minimum: -32767
2637
+ * - Maximum: 32767
2638
+ */
2639
+ left: number;
2640
+ /**
2641
+ * The rotation, in degrees.
2642
+ *
2643
+ * @remarks
2644
+ * - Minimum: -180
2645
+ * - Maximum: 180
2646
+ */
2647
+ rotation?: number;
2648
+ };
2649
+
2650
+ /**
2651
+ * @public
2652
+ * Text element or content to be added to the design at the end of a drag event.
2653
+ */
2654
+ export declare type TextDragConfig = {
2655
+ /**
2656
+ * The type of element.
2657
+ */
2658
+ type: "text";
2659
+ /**
2660
+ * The text content to drag.
2661
+ */
2662
+ children?: string[];
2663
+ /**
2664
+ * The alignment of the text.
2665
+ * @defaultValue "start"
2666
+ */
2667
+ textAlign?: "start" | "center" | "end" | "justify";
2668
+ /**
2669
+ * The weight (thickness) of the font.
2670
+ * @defaultValue "normal"
2671
+ */
2672
+ fontWeight?: FontWeight;
2673
+ /**
2674
+ * The style of the font.
2675
+ * @defaultValue "normal"
2676
+ */
2677
+ fontStyle?: "normal" | "italic";
2678
+ /**
2679
+ * The decoration of the font.
2680
+ * @defaultValue "none"
2681
+ */
2682
+ decoration?: "none" | "underline";
2683
+ /**
2684
+ * @beta
2685
+ * A unique identifier that points to a font asset in Canva's backend.
2686
+ */
2687
+ fontRef?: FontRef;
2688
+ };
2689
+
2690
+ /**
2691
+ * @public
2692
+ * An element that renders text content.
2693
+ */
2694
+ export declare type TextElement = NativeTextElement;
2695
+
2696
+ /**
2697
+ * @public
2698
+ * An element that renders text content and has positional properties.
2699
+ */
2700
+ export declare type TextElementAtPoint = NativeTextElementWithBox;
2701
+
2702
+ /**
2703
+ * @public
2704
+ * A region of richtext.
2705
+ */
2706
+ export declare type TextRegion = {
2707
+ /**
2708
+ * The plaintext content of the region.
2709
+ */
2710
+ text: string;
2711
+ /**
2712
+ * The formatting of the region.
2713
+ */
2714
+ formatting?: Partial<RichtextFormatting>;
2715
+ };
2716
+
2717
+ /**
2718
+ * @public
2719
+ * Provides methods for adding drag and drop behavior to an app.
2720
+ */
2721
+ export declare interface UI {
2722
+ /**
2723
+ * @deprecated The method has been superseded by `startDragToPoint`.
2724
+ * @public
2725
+ * Adds the specified element or content to a design at the end of a drag event.
2726
+ *
2727
+ * @param event - A drag start event.
2728
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
2729
+ */
2730
+ startDrag<E extends HTMLElement>(
2731
+ event: DragStartEvent<E>,
2732
+ dragData:
2733
+ | TextDragConfig
2734
+ | AudioDragConfig
2735
+ | EmbedDragConfig
2736
+ | VideoDragConfigForElement<E>
2737
+ | ImageDragConfigForElement<E>
2738
+ ): Promise<void>;
2739
+ /**
2740
+ * @public
2741
+ * Adds the specified element or content to fixed designs, which use a coordinate-based positioning system at the end of a drag event.
2742
+ *
2743
+ * @param event - A drag start event.
2744
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
2745
+ */
2746
+ startDragToPoint<E extends HTMLElement>(
2747
+ event: DragStartEvent<E>,
2748
+ dragData:
2749
+ | TextDragConfig
2750
+ | AudioDragConfig
2751
+ | EmbedDragConfig
2752
+ | VideoDragConfigForElement<E>
2753
+ | ImageDragConfigForElement<E>
2754
+ ): Promise<void>;
2755
+ /**
2756
+ * @public
2757
+ * Adds the specified element or content to responsive documents, which slot things into a text stream at the end of a drag event.
2758
+ *
2759
+ * @param event - A drag start event.
2760
+ * @param dragData - Element or content to be added to the design at the end of the drag event.
2761
+ */
2762
+ startDragToCursor<E extends HTMLElement>(
2763
+ event: DragStartEvent<E>,
2764
+ dragData:
2765
+ | EmbedDragConfig
2766
+ | VideoDragConfigForElement<E>
2767
+ | ImageDragConfigForElement<E>
2768
+ ): Promise<void>;
2769
+ }
2770
+
2771
+ /**
2772
+ * An alias for the UI interface, providing access to ui related functionality
2773
+ * @public
2774
+ */
2775
+ export declare const ui: UI;
2776
+
2777
+ /**
2778
+ * @public
2779
+ * A data type that can be used in app element data.
2780
+ */
2781
+ export declare type Value =
2782
+ | Primitive
2783
+ | ObjectPrimitive
2784
+ | Exclude<Value, undefined>[]
2785
+ | {
2786
+ [key: string]: Value;
2787
+ };
2788
+
2789
+ /**
2790
+ * @public
2791
+ * Video element or content to be added to the design at the end of a drag event.
2792
+ */
2793
+ export declare type VideoDragConfig = {
2794
+ /**
2795
+ * The type of element.
2796
+ */
2797
+ type: "video";
2798
+ /**
2799
+ * A function that returns a reference (ref) to a video asset in Canva's backend.
2800
+ */
2801
+ resolveVideoRef: () => Promise<{
2802
+ ref: VideoRef;
2803
+ }>;
2804
+ /**
2805
+ * The dimensions of the preview image.
2806
+ */
2807
+ previewSize: Dimensions;
2808
+ /**
2809
+ * The dimensions of the full-size video.
2810
+ *
2811
+ * @remarks
2812
+ * - These dimensions are used when adding the video to the design
2813
+ * - If omitted, the `previewSize` dimensions are used as a fallback.
2814
+ */
2815
+ fullSize?: Dimensions;
2816
+ /**
2817
+ * The URL of an image to display under the user's cursor during the drag and drop event.
2818
+ */
2819
+ previewUrl: string;
2820
+ };
2821
+
2822
+ /**
2823
+ * @public
2824
+ * Video element or content to be added to the design at the end of a drag event.
2825
+ */
2826
+ export declare type VideoDragConfigForElement<E extends Element> =
2827
+ E extends HTMLImageElement
2828
+ ? Partial<VideoDragConfig> &
2829
+ Pick<VideoDragConfig, "type" | "resolveVideoRef">
2830
+ : VideoDragConfig;
2831
+
2832
+ /**
2833
+ * @public
2834
+ * An element that renders video content.
2835
+ */
2836
+ export declare type VideoElement = NativeVideoElement;
2837
+
2838
+ /**
2839
+ * @public
2840
+ * An element that renders video content and has positional properties.
2841
+ */
2842
+ export declare type VideoElementAtPoint = NativeVideoElementWithBox;
2843
+
2844
+ /**
2845
+ * @public
2846
+ * A video asset that fills a path's interior.
2847
+ */
2848
+ export declare type VideoFill = {
2849
+ /**
2850
+ * The type of fill.
2851
+ */
2852
+ type: "video";
2853
+ /**
2854
+ * A unique identifier that points to a video asset in Canva's backend.
2855
+ */
2856
+ ref: VideoRef;
2857
+ };
2858
+
2859
+ /**
2860
+ * @public
2861
+ * A unique identifier that references a video asset in Canva's backend.
2862
+ */
2863
+ export declare type VideoRef = string & {
2864
+ __videoRef: never;
2865
+ };
2866
+
2867
+ /**
2868
+ * A set of dimensions with an auto-calculated height.
2869
+ */
2870
+ declare type Width = {
2871
+ /**
2872
+ * A width, in pixels.
2873
+ *
2874
+ * @remarks
2875
+ * - The pixels are relative to their container.
2876
+ * - Minimum: 0
2877
+ * - Maximum: 32767
2878
+ */
2879
+ width: number;
2880
+ /**
2881
+ * Indicates that the height should be auto-calculated.
2882
+ */
2883
+ height: "auto";
2884
+ };
2885
+
2886
+ /**
2887
+ * A set of dimensions, in pixels.
2888
+ */
2889
+ declare type WidthAndHeight = {
2890
+ /**
2891
+ * A width, in pixels.
2892
+ *
2893
+ * @remarks
2894
+ * - The pixels are relative to their container.
2895
+ * - Minimum: 0
2896
+ * - Maximum: 32767
2897
+ */
2898
+ width: number;
2899
+ /**
2900
+ * A height, in pixels.
2901
+ *
2902
+ * @remarks
2903
+ * - The pixels are relative to their container.
2904
+ * - Minimum: 0
2905
+ * - Maximum: 32767
2906
+ */
2907
+ height: number;
2908
+ };
2909
+
2910
+ export {};