@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/index.d.ts DELETED
@@ -1,1665 +0,0 @@
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 function addAudioTrack(audioTrack: AudioTrack): Promise<void>;
7
-
8
- /**
9
- * @public
10
- * Adds a native element to the user's design.
11
- * @param element - The element to add to the user's design.
12
- */
13
- export declare function addNativeElement(
14
- element: NativeElement | NativeElementWithBox
15
- ): Promise<void>;
16
-
17
- /**
18
- * @public
19
- * Adds a new page immediately after the currently selected page.
20
- * @param opts - Configuration for the new page to be added.
21
- */
22
- export declare function addPage(opts?: {
23
- /** Elements to be added to the page */
24
- elements?: NativeElementWithBox[];
25
- /**
26
- * The page background. This can be a solid color, an image or a video.
27
- **/
28
- background?: PageBackgroundFill;
29
- /** A page title which must be no longer than 255 characters */
30
- title?: string;
31
- }): Promise<void>;
32
-
33
- /**
34
- * @public
35
- * Describes any alt-text that will be added for a11y.
36
- */
37
- export declare type AltText = {
38
- /**
39
- * The text that will appear as alt-text.
40
- */
41
- text: string;
42
- /**
43
- * An optional property that will determine whether text is shown in just the editor or both editor and view mode.
44
- * If set to true, alt-text will only be rendered inside the editor.
45
- * If set to false or omitted, alt-text will be rendered in both the editor and in view only mode.
46
- */
47
- decorative: boolean | undefined;
48
- };
49
-
50
- /**
51
- * @public
52
- * A callback that runs when an app element's data is created or updated,
53
- * or when the user selects an existing app element.
54
- */
55
- export declare type AppElementChangeHandler<A extends AppElementData> = (
56
- appElement:
57
- | {
58
- data: A;
59
- version: number;
60
- }
61
- | undefined
62
- ) => void;
63
-
64
- /**
65
- * @public
66
- * A client interface for managing app elements and app element data.
67
- */
68
- export declare interface AppElementClient<A extends AppElementData> {
69
- /**
70
- * Attaches data to the selected app element or creates a new app element if one is not selected.
71
- * If data already exists, it's overwritten.
72
- * @param appElementData - The data to attach to the app element.
73
- */
74
- addOrUpdateElement(appElementData: A, placement?: Placement): Promise<void>;
75
- /**
76
- * Registers a callback that runs when the app element's data is created or
77
- * updated and when the user selects an existing app element.
78
- * @param handler - The callback to run when the app element's data is changed
79
- * and when the user selects an existing app element.
80
- */
81
- registerOnElementChange(handler: AppElementChangeHandler<A>): void;
82
- }
83
-
84
- /**
85
- * @public
86
- * Configuration for an AppElementClient
87
- */
88
- export declare type AppElementClientConfiguration<A extends AppElementData> = {
89
- /**
90
- * The AppElementRenderer to use when rendering the app element
91
- */
92
- render: AppElementRenderer<A>;
93
- };
94
-
95
- /**
96
- * @public
97
- * The data an app can attach to an app element.
98
- */
99
- export declare type AppElementData = Record<string, Value>;
100
-
101
- /**
102
- * @public
103
- * A callback that runs when an app's element is changed.
104
- *
105
- * @remarks
106
- * This callback must return one or more elements to render within the app element.
107
- */
108
- export declare type AppElementRenderer<A extends AppElementData> = (
109
- appElementData: A
110
- ) => AppElementRendererOutput;
111
-
112
- /**
113
- * @public
114
- * A return value of {@link AppElementRenderer} function.
115
- * It is an array of elements to render within an app element.
116
- */
117
- export declare type AppElementRendererOutput = NativeSimpleElementWithBox[];
118
-
119
- /**
120
- * @public
121
- * A unique identifier that references an app runtime process
122
- */
123
- export declare type AppProcessId = string & {
124
- __appProcessId: never;
125
- };
126
-
127
- /**
128
- * @public
129
- * Options for defining the drag-and-drop behavior of audio tracks.
130
- */
131
- export declare type AudioDragConfig = {
132
- /**
133
- * The type of element.
134
- */
135
- type: "AUDIO";
136
- /**
137
- * A function that returns a reference (ref) to an audio asset in Canva's backend.
138
- */
139
- resolveAudioRef: () => Promise<{
140
- ref: AudioRef;
141
- }>;
142
- /**
143
- * The duration of the audio track, in milliseconds.
144
- */
145
- durationMs: number;
146
- /**
147
- * A human readable title for the audio track.
148
- */
149
- title: string;
150
- };
151
-
152
- /**
153
- * @public
154
- * A unique identifier that references an audio asset in Canva's backend.
155
- */
156
- export declare type AudioRef = string & {
157
- __audioRef: never;
158
- };
159
-
160
- /**
161
- * @public
162
- * An audio track that can be added to a user's design.
163
- */
164
- export declare type AudioTrack = {
165
- /**
166
- * A unique identifier that references an audio asset in Canva's backend.
167
- */
168
- ref: AudioRef;
169
- };
170
-
171
- /**
172
- * @public
173
- * The dimensions, position, and rotation of an element.
174
- *
175
- * @remarks
176
- * Units are relative to the parent container both in terms of position and size
177
- */
178
- export declare type Box = Position & (WidthAndHeight | Width | Height);
179
-
180
- declare type CommonImageDragConfig = {
181
- /**
182
- * The type of element.
183
- */
184
- type: "IMAGE";
185
- /**
186
- * The dimensions of the preview image.
187
- *
188
- * @remarks
189
- * The preview image is the image that users see under their cursor while dragging
190
- * it into their design.
191
- */
192
- previewSize: Dimensions;
193
- };
194
-
195
- /**
196
- * @public
197
- * A snapshot of some part of the document content.
198
- *
199
- * @remarks
200
- * You can mutate the values in the `contents` array and then persist those changes with the `save` method.
201
- */
202
- export declare interface ContentDraft<T> {
203
- /**
204
- * The selected content.
205
- */
206
- readonly contents: readonly T[];
207
- /**
208
- * Saves changes made to items in the `contents` array.
209
- * Once saved, those changes are reflected in the user's design.
210
- *
211
- * @remarks
212
- * Any other changes to the content since calling the `read` method, such as the user editing the content directly, will be overwritten.
213
- * Only properties that are different from the original state are written to the design.
214
- */
215
- save(): Promise<void>;
216
- }
217
-
218
- /**
219
- * @public
220
- * Represents X and Y coordinates.
221
- */
222
- export declare type Coordinates = {
223
- /**
224
- * Represents an X coordinate, in pixels.
225
- */
226
- x: number;
227
- /**
228
- * Represents a Y coordinate, in pixels.
229
- */
230
- y: number;
231
- };
232
-
233
- /**
234
- * @public
235
- * Provides methods for interacting with design overlay
236
- */
237
- export declare type DesignOverlay = {
238
- /**
239
- * Registers a callback that runs when an overlay canOpen status changed on a particular target.
240
- *
241
- * @remarks
242
- * The callback fires immediately
243
- */
244
- registerOnCanOpen<Target extends OverlayTarget>(opts: {
245
- target: Target;
246
- onCanOpen(event: OverlayOpenableEvent<Target>): void;
247
- }): () => void;
248
- };
249
-
250
- /**
251
- * @public
252
- * Provides methods for interacting with the user's selected content, such as images or text.
253
- */
254
- export declare type DesignSelection = {
255
- /**
256
- * Registers a callback that runs when a user selects an element that contains the specified type of content.
257
- *
258
- * @remarks
259
- * The callback fires immediately if content is already selected.
260
- */
261
- registerOnChange<Scope extends SelectionScope>(opts: {
262
- /**
263
- * The type of content that, when selected, triggers the `onChange` callback.
264
- */
265
- scope: Scope;
266
- /**
267
- * The callback to run when the selection changes.
268
- */
269
- onChange(event: SelectionEvent<Scope>): void;
270
- }): () => void;
271
- };
272
-
273
- /**
274
- * @public
275
- * JWT that contains the Design ID and App ID.
276
- */
277
- export declare type DesignToken = {
278
- token: string;
279
- };
280
-
281
- /**
282
- * @public
283
- * Represents a width and a height.
284
- */
285
- export declare type Dimensions = {
286
- /**
287
- * Represents a width, in pixels.
288
- */
289
- width: number;
290
- /**
291
- * Represents a height, in pixels.
292
- */
293
- height: number;
294
- };
295
-
296
- /**
297
- * @public
298
- * Callbacks that run during the lifecycle of a drag-and-drop.
299
- */
300
- export declare type DragCallback = {
301
- /**
302
- * A callback that runs when the user starts dragging an element into their design.
303
- *
304
- * @param element - The element being dragged into the user's design.
305
- */
306
- onDragStart: (element: HTMLElement) => void;
307
- /**
308
- * A callback that runs when the user finishes dragging an element into their design.
309
- *
310
- * @param element - The element being dragged into the user's design.
311
- */
312
- onDragEnd: (element: HTMLElement) => void;
313
- };
314
-
315
- /**
316
- * @public
317
- * Options for making an element draggable.
318
- */
319
- export declare type DraggableElementData = ElementData | ImageElementData;
320
-
321
- /**
322
- * @public
323
- * Represents a drag start event that occurs when initiating a drag-and-drop behavior inside the app.
324
- */
325
- export declare type DragStartEvent<E extends Element> = Pick<
326
- DragEvent,
327
- "dataTransfer" | "currentTarget" | "preventDefault" | "clientX" | "clientY"
328
- > & {
329
- currentTarget: E;
330
- };
331
-
332
- /**
333
- * @public
334
- * Options for making an `HTMLElement` draggable.
335
- */
336
- export declare type ElementData = DragCallback & {
337
- /**
338
- * The element to be made draggable.
339
- */
340
- node: HTMLElement;
341
- /**
342
- * Options for defining the drag-and-drop behavior.
343
- *
344
- * @remarks
345
- * This data is required because it can't be inferred from the `node` property.
346
- */
347
- dragData: UserSuppliedDragData;
348
- };
349
-
350
- /**
351
- * @public
352
- *
353
- * Options for defining the drag-and-drop behaviour for embeds.
354
- */
355
- export declare type EmbedDragConfig = {
356
- /**
357
- * The type of element.
358
- */
359
- type: "EMBED";
360
- /**
361
- * The dimensions of the preview image.
362
- * The preview image is the image that users see under their cursor
363
- * while dragging it into their design.
364
- */
365
- previewSize: Dimensions;
366
- /**
367
- * Represents the preview image of the embed.
368
- */
369
- previewUrl: string;
370
- /**
371
- * Represents the embed source url.
372
- */
373
- embedUrl: string;
374
- };
375
-
376
- /**
377
- * @public
378
- * Export aborted response
379
- *
380
- * @remarks
381
- * Ane export flow is considered aborted when a user closes
382
- * the export options menu.
383
- */
384
- export declare type ExportAborted = {
385
- /**
386
- * The status of the export flow when the user has aborted the export menu.
387
- */
388
- status: "ABORTED";
389
- };
390
-
391
- /**
392
- * @public
393
- * The exported file.
394
- */
395
- export declare type ExportBlob = {
396
- /**
397
- * The URL of the exported design.
398
- *
399
- * @remarks
400
- * If the user's design contains multiple pages but is exported in a format that doesn't support multiple pages, the URL will point to a ZIP file that contains each page as a separate file.
401
- *
402
- * For example:
403
- *
404
- * - If a single-page design is exported as a JPG, the URL will point to a JPG file
405
- * - If a multi-page design is exported as a JPG, the URL will point to a ZIP file that contains a separate JPG file for each page
406
- * - If a multi-page design is exported as a PDF, the URL will point to a PDF file that contains all of the pages
407
- *
408
- * The following file types support multiple pages:
409
- *
410
- * - `"GIF"`
411
- * - `"PDF_STANDARD"`
412
- * - `"PPTX"`
413
- * - `"VIDEO"`
414
- *
415
- * The following file types do not support multiple pages:
416
- *
417
- * - `"JPG"`
418
- * - `"PNG"`
419
- * - `"SVG"`
420
- */
421
- url: string;
422
- };
423
-
424
- /**
425
- * @public
426
- * Export completed response
427
- */
428
- export declare type ExportCompleted = {
429
- /**
430
- * The status of the export flow when the user has submitted the export menu.
431
- */
432
- status: "COMPLETED";
433
- /**
434
- * The title of the successful export of a design, if it has been set by the user.
435
- */
436
- title?: string;
437
- /**
438
- * The exported files.
439
- *
440
- * @remarks
441
- * This array only contains one element. This is because, if a multi-page design is exported as multiple files, the files 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.
442
- */
443
- exportBlobs: ExportBlob[];
444
- };
445
-
446
- /**
447
- * @public
448
- * The types of files that Canva supports for exported designs.
449
- */
450
- export declare type ExportFileType =
451
- | "PNG"
452
- | "JPG"
453
- | "PDF_STANDARD"
454
- | "VIDEO"
455
- | "GIF"
456
- | "PPTX"
457
- | "SVG";
458
-
459
- /**
460
- * @public
461
- * The options for configuring the export of a design.
462
- */
463
- export declare type ExportRequest = {
464
- /**
465
- * The types of files the user can export their design as.
466
- *
467
- * @remarks
468
- * You must provide at least one file type.
469
- */
470
- acceptedFileTypes: ExportFileType[];
471
- };
472
-
473
- /**
474
- * @public
475
- * The response of an export request.
476
- */
477
- export declare type ExportResponse = ExportCompleted | ExportAborted;
478
-
479
- /**
480
- * @public
481
- *
482
- * Options for defining the Drag and Drop behaviour for images uploaded
483
- * via the Content capability.
484
- */
485
- export declare type ExternalImageDragConfig = CommonImageDragConfig & {
486
- /**
487
- * The function that resolves an image ref
488
- * @remarks
489
- *
490
- * This function will be run during the drag process in order to fetch the media ref of the
491
- * external image being fetched. This function should return the result of `upload`
492
- * from the content capability.
493
- */
494
- resolveImageRef: () => Promise<{
495
- ref: ImageRef;
496
- }>;
497
- /**
498
- * The URL of the preview image.
499
- *
500
- * @remarks
501
- * The preview image is the image that users see under their cursor while dragging
502
- * it into their design.
503
- */
504
- previewUrl: string;
505
- /**
506
- * The dimensions of the full-size image.
507
- *
508
- * @remarks
509
- * The full-size image is the image that Canva uploads to the user's account and
510
- * adds to their design.
511
- *
512
- * If omitted, the value of the `previewSize` property is used as a fallback.
513
- */
514
- fullSize?: Dimensions;
515
- };
516
-
517
- /**
518
- * @public
519
- * The appearance of a path's interior.
520
- */
521
- export declare type Fill = {
522
- /**
523
- * Boolean defining whether image or video can be dropped on the fill by the user.
524
- * If set to true, images or videos can be dropped on the fill.
525
- */
526
- dropTarget?: boolean;
527
- /**
528
- * The color of the fill as a hex code.
529
- *
530
- * @remarks
531
- * The hex code must include all six characters and be prefixed with a # symbol (e.g. #ff0099).
532
- * Only one type of fill (color, image or video) can be set.
533
- */
534
- color?: string;
535
- /**
536
- * An asset (image or video) that will be used to fill the given path.
537
- *
538
- * @remarks
539
- * Only one type of fill (color, image or video) can be set.
540
- */
541
- asset?: ImageFill | VideoFill;
542
- };
543
-
544
- /**
545
- * @public
546
- * A reference to a font that can be used in other parts of the SDK.
547
- */
548
- export declare type FontRef = string & {
549
- __fontRef: never;
550
- };
551
-
552
- /**
553
- * @public
554
- * Font weights supported in the SDK.
555
- **/
556
- export declare type FontWeight =
557
- | "normal"
558
- | "thin"
559
- | "extralight"
560
- | "light"
561
- | "medium"
562
- | "semibold"
563
- | "bold"
564
- | "ultrabold"
565
- | "heavy";
566
-
567
- /**
568
- * Allows to get the context of currently selected page.
569
- * @public
570
- * @returns Page context of currently selected page
571
- */
572
- export declare function getCurrentPageContext(): Promise<PageContext>;
573
-
574
- /**
575
- * @public
576
- * Gets the default dimensions that a new page will have when it is added to a design.
577
- * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
578
- * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
579
- * design that is applied whenever a new page is created.
580
- *
581
- * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
582
- */
583
- export declare function getDefaultPageDimensions(): Promise<
584
- Dimensions | undefined
585
- >;
586
-
587
- /**
588
- * @public
589
- * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
590
- */
591
- export declare function getDesignToken(): Promise<DesignToken>;
592
-
593
- declare type Height = {
594
- width: "auto";
595
- height: number;
596
- };
597
-
598
- /**
599
- * @public
600
- * Options for defining the drag-and-drop behavior of an image element that can be defined by an
601
- * app developer.
602
- */
603
- export declare type ImageDragConfig = ExternalImageDragConfig;
604
-
605
- /**
606
- * @public
607
- * Options for defining the drag-and-drop behavior for images.
608
- */
609
- export declare type ImageDragConfigForElement<E extends Element> =
610
- E extends HTMLImageElement
611
- ? Partial<ImageDragConfig> & Pick<ImageDragConfig, "type">
612
- : ImageDragConfig;
613
-
614
- /**
615
- * @public
616
- * Options for making an `HTMLImageElement` draggable.
617
- */
618
- export declare type ImageElementData = DragCallback & {
619
- /**
620
- * The element to be made draggable.
621
- */
622
- node: HTMLImageElement;
623
- /**
624
- * Options for defining the drag-and-drop behavior.
625
- *
626
- * @remarks
627
- * If any of this data is omitted, it's inferred from the `node` property.
628
- */
629
- dragData?:
630
- | Partial<UserSuppliedImageDragData>
631
- | (Partial<UserSuppliedVideoDragData> &
632
- Pick<UserSuppliedVideoDragData, "type" | "resolveVideoRef">);
633
- };
634
-
635
- /**
636
- * @public
637
- * An image asset that will be used to fill the given path.
638
- */
639
- export declare type ImageFill = {
640
- /**
641
- * Type of an asset that will be used to fill the given path.
642
- */
643
- type: "IMAGE";
644
- /**
645
- * A unique identifier that references an image asset in Canva's backend.
646
- */
647
- ref: ImageRef;
648
- };
649
-
650
- /**
651
- * @public
652
- * A unique identifier that references an image asset in Canva's backend.
653
- */
654
- export declare type ImageRef = string & {
655
- __imageRef: never;
656
- };
657
-
658
- /**
659
- * @public
660
- * @param appElementConfig - Configuration for an AppElementClient
661
- */
662
- export declare function initAppElement<A extends AppElementData>(
663
- appElementConfig: AppElementClientConfiguration<A>
664
- ): AppElementClient<A>;
665
-
666
- /**
667
- * @public
668
- * A native element.
669
- */
670
- export declare type NativeElement =
671
- | NativeImageElement
672
- | NativeVideoElement
673
- | NativeEmbedElement
674
- | NativeTextElement
675
- | NativeShapeElement
676
- | NativeGroupElement;
677
-
678
- /**
679
- * @public
680
- * The types of elements an app can add to a user's design.
681
- */
682
- export declare type NativeElementType =
683
- | "IMAGE"
684
- | "EMBED"
685
- | "TEXT"
686
- | "SHAPE"
687
- | "VIDEO";
688
-
689
- /**
690
- * @public
691
- * An element that exists within an app or group element.
692
- */
693
- export declare type NativeElementWithBox =
694
- | NativeImageElementWithBox
695
- | NativeVideoElementWithBox
696
- | NativeEmbedElementWithBox
697
- | NativeTextElementWithBox
698
- | NativeShapeElementWithBox
699
- | NativeGroupElementWithBox;
700
-
701
- /**
702
- * @public
703
- * An element that renders an embeddable piece of media, such as a YouTube video.
704
- */
705
- export declare type NativeEmbedElement = {
706
- /**
707
- * The type of element.
708
- */
709
- type: "EMBED";
710
- /**
711
- * The URL of the embed. This URL must be supported by the Iframely API.
712
- */
713
- url: string;
714
- };
715
-
716
- /**
717
- * @public
718
- * An element that renders an embeddable piece of media, such as a YouTube video.
719
- *
720
- * @remarks
721
- * This type includes properties for controlling the position and dimensions of the
722
- * element.
723
- * It will be positioned and sized relative to its parent container.
724
- * The parent container may be an app element, or the current page.
725
- */
726
- export declare type NativeEmbedElementWithBox = {
727
- /**
728
- * The type of element.
729
- */
730
- type: "EMBED";
731
- /**
732
- * The URL of the embed.
733
- *
734
- * @remarks
735
- * This URL must be supported by the Iframely API.
736
- */
737
- url: string;
738
- } & Box;
739
-
740
- /**
741
- * @public
742
- * An element containing two or more {@link NativeElementWithBox}.
743
- */
744
- export declare type NativeGroupElement = {
745
- /**
746
- * The type of element.
747
- */
748
- type: "GROUP";
749
- /**
750
- * The inner elements contained by the group element. These elements require a Box as they are
751
- * relatively positioned to the outer boundaries of the group element.
752
- */
753
- children: NativeSimpleElementWithBox[];
754
- };
755
-
756
- /**
757
- * @public
758
- * An element containing two or more {@link NativeSimpleElementWithBox}.
759
- *
760
- * @remarks
761
- * This type includes properties for controlling the position and dimensions
762
- * of the element
763
- */
764
- export declare type NativeGroupElementWithBox = {
765
- /**
766
- * The type of element.
767
- */
768
- type: "GROUP";
769
- /**
770
- * The inner elements contained by the group element. These elements require a Box as they are
771
- * relatively positioned to the outer boundaries of the group element.
772
- */
773
- children: NativeSimpleElementWithBox[];
774
- } & Box;
775
-
776
- /**
777
- * @public
778
- * An element that renders an image in the user's design.
779
- */
780
- export declare type NativeImageElement = {
781
- /**
782
- * The type of element.
783
- */
784
- type: "IMAGE";
785
- /**
786
- * An optional object to describe alt-text that may be applied to an image.
787
- */
788
- altText?: AltText;
789
- } & (
790
- | {
791
- /**
792
- * A data URL that contains the image data.
793
- */
794
- dataUrl: string;
795
- /**
796
- * A unique identifier that references an image asset in Canva's backend.
797
- */
798
- ref?: never;
799
- }
800
- | {
801
- /**
802
- * A data URL that contains the image data.
803
- */
804
- dataUrl?: never;
805
- /**
806
- * A unique identifier that references an image asset in Canva's backend.
807
- */
808
- ref: ImageRef;
809
- }
810
- );
811
-
812
- /**
813
- * @public
814
- * An element that renders an image in the user's design.
815
- *
816
- * @remarks
817
- * This type includes properties for controlling the position and dimensions
818
- * of the element.
819
- * It will be positioned and sized relative to its parent container.
820
- * The parent container may be an app element, or the current page.
821
- */
822
- export declare type NativeImageElementWithBox = NativeImageElement & Box;
823
-
824
- /**
825
- * @public
826
- * An element that renders a vector shape.
827
- */
828
- export declare type NativeShapeElement = {
829
- /**
830
- * The type of element.
831
- */
832
- type: "SHAPE";
833
- /**
834
- * Properties for configuring the scale and cropping of a shape.
835
- *
836
- * @remarks
837
- * This is similar to the `viewBox` attribute of the <svg> element.
838
- */
839
- viewBox: ShapeViewBox;
840
- /**
841
- * The paths that define the shape of the element.
842
- *
843
- * @remarks
844
- * There must be between 1 and 30 paths. The maximum combined size of all paths must
845
- * not exceed 2kb. The maximum numbrer of unique fill colors across all paths is 6.
846
- */
847
- paths: ShapePath[];
848
- };
849
-
850
- /**
851
- * @public
852
- * An element that renders a vector shape.
853
- *
854
- * @remarks
855
- * This type includes properties for controlling the position and dimensions of the
856
- * element.
857
- * It will be positioned and sized relative to its parent container.
858
- * The parent container may be an app element, or the current page.
859
- */
860
- export declare type NativeShapeElementWithBox = {
861
- /**
862
- * The type of element.
863
- */
864
- type: "SHAPE";
865
- /**
866
- * Properties for configuring the scale and cropping of a shape.
867
- *
868
- * @remarks
869
- * This is similar to the `viewBox` attribute of the <svg> element.
870
- */
871
- viewBox: ShapeViewBox;
872
- /**
873
- * The paths that define the shape of the element.
874
- */
875
- paths: ShapePath[];
876
- } & Box;
877
-
878
- /**
879
- * @public
880
- * An element that exists within a group element.
881
- */
882
- export declare type NativeSimpleElementWithBox = Exclude<
883
- NativeElementWithBox,
884
- NativeGroupElementWithBox
885
- >;
886
-
887
- /**
888
- * @public
889
- * An element that renders text.
890
- */
891
- export declare type NativeTextElement = {
892
- /**
893
- * The type of element.
894
- */
895
- type: "TEXT";
896
- /**
897
- * The text to render within the element. In the future, each item in this
898
- * array will map to a paragraph. At the moment, only one item is supported.
899
- */
900
- children: string[];
901
- } & TextAttributes;
902
-
903
- /**
904
- * @public
905
- * An element that renders text.
906
- *
907
- * @remarks
908
- * This type includes properties for controlling the position and dimensions of the
909
- * element.
910
- * It will be positioned and sized relative to its parent container.
911
- * The parent container may be an app element, or the current page.
912
- */
913
- export declare type NativeTextElementWithBox = {
914
- /**
915
- * The type of element.
916
- */
917
- type: "TEXT";
918
- /**
919
- * The text to render within the element.
920
- *
921
- * @remarks
922
- * In the future, each item in this array will map to a paragraph. At the moment,
923
- * only one item is supported.
924
- */
925
- children: [string];
926
- /**
927
- * The width of the element. This must be an integer between 0 and 32767.
928
- */
929
- width?: number;
930
- /**
931
- * The distance from the top edge of the container.
932
- *
933
- * @remarks
934
- * This must be an integer between -32768 and 32767. This property doesn't have
935
- * any effect if the app element only contains a single element.
936
- */
937
- top: number;
938
- /**
939
- * The distance from the left edge of the container.
940
- *
941
- * @remarks
942
- * This must be an integer between -32768 and 32767. This property doesn't have
943
- * any effect if the app element only contains a single element.
944
- */
945
- left: number;
946
- /**
947
- * The rotation of the element, in degrees.
948
- *
949
- * @remarks
950
- * This must be an integer between -180 and 180.
951
- */
952
- rotation?: number;
953
- } & TextAttributes;
954
-
955
- /**
956
- * @public
957
- * An element that renders a video in the user's design.
958
- */
959
- export declare type NativeVideoElement = {
960
- /**
961
- * The type of element.
962
- */
963
- type: "VIDEO";
964
- /**
965
- * A unique identifier that references a video asset in Canva's backend.
966
- */
967
- ref: VideoRef;
968
- /**
969
- * An optional object to describe alt-text that may be applied to a video.
970
- */
971
- altText?: AltText;
972
- };
973
-
974
- /**
975
- * @public
976
- * An element that renders a video in the user's design.
977
- *
978
- * @remarks
979
- * This type includes properties for controlling the position and dimensions
980
- * of the element.
981
- * It will be positioned and sized relative to its parent container.
982
- * The parent container may be an app element, or the current page.
983
- */
984
- export declare type NativeVideoElementWithBox = NativeVideoElement & Box;
985
-
986
- /**
987
- * The types of object primitive values that can be stored within an app element's data.
988
- */
989
- declare type ObjectPrimitive = Boolean | String;
990
-
991
- /**
992
- * @public
993
- * An alias for the DesignOverlay interface, providing access to design overlay related functionality
994
- */
995
- export declare const overlay: DesignOverlay;
996
-
997
- /**
998
- * @public
999
- * Information about whether the overlay can be opened or not on a particular {@link OverlayTarget}
1000
- */
1001
- export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
1002
- /**
1003
- * An event indicating whether the overlay can be opened or not when {@link OverlayTarget} is `"image_selection"`
1004
- */
1005
- ["image_selection"]:
1006
- | OverlayUnopenableEvent
1007
- | {
1008
- canOpen: true;
1009
- /**
1010
- * Launch a new app process on an overlay on top of the current selected image fill
1011
- *
1012
- * @remarks
1013
- * `launchParameters` specifies the type of data that are provided to an app process at its launch
1014
- */
1015
- readonly open: (options: {
1016
- launchParameters?: any;
1017
- }) => Promise<AppProcessId>;
1018
- };
1019
- }[Target];
1020
-
1021
- /**
1022
- * @public
1023
- * The target to check if an overlay can be opened for
1024
- */
1025
- export declare type OverlayTarget = "image_selection";
1026
-
1027
- /**
1028
- * @public
1029
- * Information about the overlay when it can not be opened on a particular {@link OverlayTarget}
1030
- */
1031
- declare type OverlayUnopenableEvent = {
1032
- canOpen: false;
1033
- reason: string;
1034
- };
1035
-
1036
- /**
1037
- * @public
1038
- * The appearance of a page's background.
1039
- */
1040
- export declare type PageBackgroundFill = Pick<Fill, "asset" | "color">;
1041
-
1042
- /**
1043
- * @public
1044
- * Page context
1045
- */
1046
- export declare type PageContext = {
1047
- /**
1048
- * Page dimensions in px
1049
- *
1050
- * @remarks
1051
- * This value is undefined for Whiteboard and Docs
1052
- */
1053
- dimensions: PageDimensions | undefined;
1054
- };
1055
-
1056
- /**
1057
- * @public
1058
- * Page Dimensions
1059
- */
1060
- export declare type PageDimensions = {
1061
- width: number;
1062
- height: number;
1063
- };
1064
-
1065
- /**
1066
- * @public
1067
- * The outline of a path.
1068
- */
1069
- export declare type PathStroke = {
1070
- /**
1071
- * The weight of the stroke. This must be an integer between 0 and 100.
1072
- */
1073
- weight: number;
1074
- /**
1075
- * The color of the stroke as a hex code.
1076
- *
1077
- * @remarks
1078
- * The hex code must include all six characters and be prefixed with a # symbol (e.g. #ff0099).
1079
- */
1080
- color: string;
1081
- /**
1082
- * The alignment of the stroke. The only supported value is 'inset'.
1083
- */
1084
- strokeAlign: "inset";
1085
- };
1086
-
1087
- /**
1088
- * @public
1089
- * The dimensions, position, and rotation of an element.
1090
- */
1091
- export declare type Placement = Position & (WidthAndHeight | Width | Height);
1092
-
1093
- declare type Position = {
1094
- /**
1095
- * The distance from the top edge of the container.
1096
- *
1097
- * @remarks
1098
- * This must be an integer between -32768 and 32767. This property doesn't
1099
- * have any effect if the app element only contains a single element.
1100
- */
1101
- top: number;
1102
- /**
1103
- * The distance from the left edge of the container.
1104
- *
1105
- * @remarks
1106
- * This must be an integer between -32768 and 32767. This property doesn't
1107
- * have any effect if the app element only contains a single element.
1108
- */
1109
- left: number;
1110
- /**
1111
- * The rotation of the box, in degrees.
1112
- *
1113
- * @remarks
1114
- * This must be an integer between -180 and 180.
1115
- */
1116
- rotation?: number;
1117
- };
1118
-
1119
- /**
1120
- * The types of primitive values that can be stored within an app element's data.
1121
- *
1122
- * @remarks
1123
- * All types of primitives are supported except for symbols and bigints.
1124
- */
1125
- declare type Primitive = undefined | null | number | boolean | string;
1126
-
1127
- /**
1128
- * @public
1129
- * Exports the user's design as one or more static files.
1130
- * @param request - The request object containing configurations of the design export.
1131
- */
1132
- export declare function requestExport(
1133
- request: ExportRequest
1134
- ): Promise<ExportResponse>;
1135
-
1136
- /**
1137
- * @public
1138
- * An alias for the DesignSelection interface, providing access to design selection related functionality
1139
- */
1140
- export declare const selection: DesignSelection;
1141
-
1142
- /**
1143
- * @public
1144
- * Information about the user's selection. To access the selected content, call the `read` method.
1145
- */
1146
- export declare interface SelectionEvent<Scope extends SelectionScope> {
1147
- /**
1148
- * The type of content that's selected.
1149
- */
1150
- readonly scope: Scope;
1151
- /**
1152
- * The number of selected elements.
1153
- */
1154
- readonly count: number;
1155
- /**
1156
- * Creates a snapshot of the selected content and returns a *draft* object.
1157
- * The draft has a mutable `contents` property for making changes to the selected content.
1158
- * Any changes made to `contents` are not immediately persisted or reflected in the user's design.
1159
- * To persist the changes, call the `save` method that's available via the draft.
1160
- *
1161
- * @example Replacing text
1162
- * ```
1163
- * const draft = await selectionEvent.read();
1164
- *
1165
- * for(const content of draft.contents) {
1166
- * // This change won't immediately appear in the user's design
1167
- * content.text = "This is the new text";
1168
- * }
1169
- *
1170
- * // The changes will now appear in the user's design
1171
- * await draft.save();
1172
- * ```
1173
- */
1174
- read(): Promise<ContentDraft<SelectionValue<Scope>>>;
1175
- }
1176
-
1177
- /**
1178
- * @public
1179
- * The type of content that apps can detect selection changes on.
1180
- */
1181
- export declare type SelectionScope = "plaintext" | "image" | "video";
1182
-
1183
- /**
1184
- * @public
1185
- * The selected content.
1186
- *
1187
- * @remarks
1188
- * The value depends on the {@link SelectionScope}.
1189
- */
1190
- export declare type SelectionValue<Scope extends SelectionScope> = {
1191
- /**
1192
- * The selected content when {@link SelectionScope} is `"plaintext"`.
1193
- */
1194
- ["plaintext"]: {
1195
- /**
1196
- * The text content of the element as plain text.
1197
- */
1198
- text: string;
1199
- };
1200
- /**
1201
- * The selected content when {@link SelectionScope} is `"image"`.
1202
- */
1203
- ["image"]: {
1204
- /**
1205
- * A unique identifier that points to an image asset in Canva's backend.
1206
- */
1207
- ref: ImageRef;
1208
- };
1209
- /**
1210
- * The selected content when {@link SelectionScope} is `"video"`.
1211
- */
1212
- ["video"]: {
1213
- /**
1214
- * A unique identifier that points to an video asset in Canva's backend.
1215
- */
1216
- ref: VideoRef;
1217
- };
1218
- }[Scope];
1219
-
1220
- /**
1221
- * @public
1222
- * Updates the background of the user's current page. The background can be a solid color,
1223
- * an image or a video.
1224
- */
1225
- export declare function setCurrentPageBackground(
1226
- opts: PageBackgroundFill
1227
- ): Promise<void>;
1228
-
1229
- /**
1230
- * @public
1231
- * A path that defines the shape of a shape element.
1232
- */
1233
- export declare type ShapePath = {
1234
- /**
1235
- * The shape of the path.
1236
- *
1237
- * @remarks
1238
- * This accepts the same value as the `d` attribute of the SVG <path> element,
1239
- * with some limitations.
1240
- *
1241
- * The path must:
1242
- *
1243
- * - start with an M command
1244
- * - not have more than one M command
1245
- * - not use the Q command
1246
- * - be closed, either with a Z command at the end or by having the last
1247
- * coordinate match the first coordinate
1248
- */
1249
- d: string;
1250
- /**
1251
- * The appearance of the path's interior.
1252
- */
1253
- fill: Fill;
1254
- /**
1255
- * The outline of the path.
1256
- */
1257
- stroke?: PathStroke;
1258
- };
1259
-
1260
- /**
1261
- * @public
1262
- * Properties for configuring the scale and cropping of a shape.
1263
- *
1264
- * @remarks
1265
- * This is similar to the `viewBox` attribute of the <svg> element.
1266
- */
1267
- export declare type ShapeViewBox = {
1268
- /**
1269
- * The distance of the shape from the top edge of the element.
1270
- */
1271
- top: number;
1272
- /**
1273
- * The distance of the shape from the left edge of the element.
1274
- */
1275
- left: number;
1276
- /**
1277
- * The width of the view box.
1278
- */
1279
- width: number;
1280
- /**
1281
- * The height of the view box.
1282
- */
1283
- height: number;
1284
- };
1285
-
1286
- /**
1287
- * @public
1288
- * Attributes for changing the appearance of text.
1289
- */
1290
- export declare type TextAttributes = {
1291
- /**
1292
- * The size of the text.
1293
- *
1294
- * @remarks
1295
- * The default value is 16. This must be an integer between 1 and 1000.
1296
- * This property will be ignored when adding native text elements without specifying placement.
1297
- */
1298
- fontSize?: number;
1299
- /**
1300
- * The alignment of the text.
1301
- * @defaultValue 'start'
1302
- */
1303
- textAlign?: "start" | "center" | "end" | "justify";
1304
- /**
1305
- * The color of the text as a hex code.
1306
- *
1307
- * @remarks
1308
- * The hex code must include all six characters and be prefixed with a # symbol
1309
- * (e.g. #ff0099). The default value is #000000.
1310
- */
1311
- color?: string;
1312
- /**
1313
- * @public
1314
- * A reference to the font to use for this text element.
1315
- */
1316
- fontRef?: FontRef;
1317
- /**
1318
- * The weight of the font.
1319
- * @defaultValue 'normal'
1320
- */
1321
- fontWeight?: FontWeight;
1322
- /**
1323
- * The style of the font.
1324
- * @defaultValue 'normal'
1325
- */
1326
- fontStyle?: "normal" | "italic";
1327
- /**
1328
- * The decoration of the font.
1329
- * @defaultValue 'none'
1330
- */
1331
- decoration?: "none" | "underline";
1332
- };
1333
-
1334
- /**
1335
- * @public
1336
- * Options for defining the drag-and-drop behavior of a text element.
1337
- */
1338
- export declare type TextDragConfig = {
1339
- /**
1340
- * The type of element.
1341
- */
1342
- type: "TEXT";
1343
- /**
1344
- * The text content to drag.
1345
- */
1346
- children?: string[];
1347
- /**
1348
- * The alignment of the text.
1349
- * @defaultValue 'start'
1350
- */
1351
- textAlign?: "start" | "center" | "end" | "justify";
1352
- /**
1353
- * The weight of the font.
1354
- * @defaultValue 'normal'
1355
- */
1356
- fontWeight?: FontWeight;
1357
- /**
1358
- * The style of the font.
1359
- * @defaultValue 'normal'
1360
- */
1361
- fontStyle?: "normal" | "italic";
1362
- /**
1363
- * The decoration of the font.
1364
- * @defaultValue 'none'
1365
- */
1366
- decoration?: "none" | "underline";
1367
- };
1368
-
1369
- /**
1370
- * @public
1371
- * The methods for adding drag-and-drop behavior to an app.
1372
- */
1373
- export declare interface UI {
1374
- /**
1375
- * @public
1376
- * Makes the specified node draggable.
1377
- *
1378
- * @deprecated use `UI.startDrag` instead
1379
- *
1380
- * @param options - Options for making an element draggable.
1381
- */
1382
- makeDraggable(options: DraggableElementData): void;
1383
- /**
1384
- * @public
1385
- * Handles a drag event initiated inside the app to Canva, enables drag-and_drop interactions with elements outside of the app.
1386
- * @param event - The drag start event.
1387
- * @param dragData - The data to be passed to the drag handler.
1388
- */
1389
- startDrag<E extends HTMLElement>(
1390
- event: DragStartEvent<E>,
1391
- dragData:
1392
- | TextDragConfig
1393
- | AudioDragConfig
1394
- | EmbedDragConfig
1395
- | VideoDragConfigForElement<E>
1396
- | ImageDragConfigForElement<E>
1397
- ): Promise<void>;
1398
- }
1399
-
1400
- /**
1401
- * An alias for the UI interface, providing access to ui related functionality
1402
- * @public
1403
- */
1404
- export declare const ui: UI;
1405
-
1406
- /**
1407
- * @deprecated
1408
- * @public
1409
- * Options for defining the drag-and-drop behavior of audio tracks.
1410
- */
1411
- export declare type UserSuppliedAudioDragData = AudioDragConfig;
1412
-
1413
- /**
1414
- * @deprecated
1415
- * @public
1416
- *
1417
- * Options for defining the Drag and Drop behaviour for images
1418
- * which have been supplied as data urls
1419
- */
1420
- export declare type UserSuppliedDataUrlImageDragData = CommonImageDragConfig & {
1421
- /**
1422
- * The dimensions of the full-size image.
1423
- *
1424
- * @remarks
1425
- * The full-size image is the image that Canva uploads to the user's account and
1426
- * adds to their design.
1427
- *
1428
- * If omitted, the value of the `previewSize` property is used as a fallback.
1429
- */
1430
- fullSize?: Dimensions;
1431
- /**
1432
- * The data URL of the preview image.
1433
- *
1434
- * @remarks
1435
- * The preview image is the image that users see under their cursor while dragging
1436
- * it into their design.
1437
- *
1438
- * If omitted, the value of the `fullSizeSrc` property is used as a fallback.
1439
- */
1440
- previewSrc?: string;
1441
- /**
1442
- * The data URL of the full-size image.
1443
- *
1444
- * @remarks
1445
- * The full-size image is the image that Canva uploads to the user's account and
1446
- * adds to their design.
1447
- */
1448
- fullSizeSrc: string;
1449
- };
1450
-
1451
- /**
1452
- * @deprecated
1453
- * @public
1454
- * Options for defining the drag-and-drop behavior that can be defined by an app developer.
1455
- */
1456
- export declare type UserSuppliedDragData =
1457
- | UserSuppliedImageDragData
1458
- | UserSuppliedTextDragData
1459
- | UserSuppliedVideoDragData
1460
- | UserSuppliedAudioDragData;
1461
-
1462
- /**
1463
- * @deprecated
1464
- * @public
1465
- *
1466
- * Options for defining the Drag and Drop behaviour for images uploaded
1467
- * via the Content capability.
1468
- */
1469
- export declare type UserSuppliedExternalImageDragData =
1470
- CommonImageDragConfig & {
1471
- /**
1472
- * The function that resolves an image ref
1473
- * @remarks
1474
- *
1475
- * This function will be run during the drag process in order to fetch the media ref of the
1476
- * external image being fetched. This function should return the result of `upload`
1477
- * from the content capability.
1478
- */
1479
- resolveImageRef: () => Promise<{
1480
- ref: ImageRef;
1481
- }>;
1482
- /**
1483
- * The URL of the preview image.
1484
- *
1485
- * @remarks
1486
- * The preview image is the image that users see under their cursor while dragging
1487
- * it into their design.
1488
- */
1489
- previewSrc: string;
1490
- /**
1491
- * The dimensions of the full-size image.
1492
- *
1493
- * @remarks
1494
- * The full-size image is the image that Canva uploads to the user's account and
1495
- * adds to their design.
1496
- *
1497
- * If omitted, the value of the `previewSize` property is used as a fallback.
1498
- */
1499
- fullSize?: Dimensions;
1500
- };
1501
-
1502
- /**
1503
- * @deprecated
1504
- * @public
1505
- * Options for defining the drag-and-drop behavior of an image element that can be defined by an
1506
- * app developer.
1507
- */
1508
- export declare type UserSuppliedImageDragData =
1509
- | UserSuppliedDataUrlImageDragData
1510
- | UserSuppliedExternalImageDragData;
1511
-
1512
- /**
1513
- * @deprecated
1514
- * @public
1515
- * Options for defining the drag-and-drop behavior of a text element.
1516
- */
1517
- export declare type UserSuppliedTextDragData = TextDragConfig;
1518
-
1519
- /**
1520
- * @deprecated
1521
- * @public
1522
- * Options for defining the drag-and-drop behavior for videos.
1523
- */
1524
- export declare type UserSuppliedVideoDragData = {
1525
- /**
1526
- * The type of element.
1527
- */
1528
- type: "VIDEO";
1529
- /**
1530
- * The function used resolve the video ref.
1531
- * This is used in conjunction with content import.
1532
- */
1533
- resolveVideoRef: () => Promise<{
1534
- ref: VideoRef;
1535
- }>;
1536
- /**
1537
- * The dimensions of the preview image.
1538
- * @remarks
1539
- * The preview image is the image that users see under their cursor
1540
- * while dragging it into their design.
1541
- */
1542
- previewSize: Dimensions;
1543
- /**
1544
- * The dimensions of the full-size video.
1545
- * These dimensions are used when adding the video to the design
1546
- *
1547
- * If omitted, the value of the `previewSize` property is
1548
- * used as a fallback.
1549
- */
1550
- fullSize?: Dimensions;
1551
- /**
1552
- * The URL of the preview image.
1553
- *
1554
- * @remarks
1555
- * The preview image is the image that users see under their cursor while dragging
1556
- * it into their design.
1557
- */
1558
- previewSrc: string;
1559
- };
1560
-
1561
- /**
1562
- * @public
1563
- * The types of values that can be stored within an app element's data.
1564
- */
1565
- export declare type Value =
1566
- | Primitive
1567
- | ObjectPrimitive
1568
- | Exclude<Value, undefined>[]
1569
- | {
1570
- [key: string]: Value;
1571
- };
1572
-
1573
- /**
1574
- * @public
1575
- * Options for defining the drag-and-drop behavior for videos.
1576
- */
1577
- export declare type VideoDragConfig = {
1578
- /**
1579
- * The type of element.
1580
- */
1581
- type: "VIDEO";
1582
- /**
1583
- * The function used resolve the video ref.
1584
- * This is used in conjunction with content import.
1585
- */
1586
- resolveVideoRef: () => Promise<{
1587
- ref: VideoRef;
1588
- }>;
1589
- /**
1590
- * The dimensions of the preview image.
1591
- * @remarks
1592
- * The preview image is the image that users see under their cursor
1593
- * while dragging it into their design.
1594
- */
1595
- previewSize: Dimensions;
1596
- /**
1597
- * The dimensions of the full-size video.
1598
- * These dimensions are used when adding the video to the design
1599
- *
1600
- * If omitted, the value of the `previewSize` property is
1601
- * used as a fallback.
1602
- */
1603
- fullSize?: Dimensions;
1604
- /**
1605
- * The URL of the preview image.
1606
- *
1607
- * @remarks
1608
- * The preview image is the image that users see under their cursor while dragging
1609
- * it into their design.
1610
- */
1611
- previewUrl: string;
1612
- };
1613
-
1614
- /**
1615
- * @public
1616
- * Options for defining the drag-and-drop behavior for videos.
1617
- */
1618
- export declare type VideoDragConfigForElement<E extends Element> =
1619
- E extends HTMLImageElement
1620
- ? Partial<VideoDragConfig> &
1621
- Pick<VideoDragConfig, "type" | "resolveVideoRef">
1622
- : VideoDragConfig;
1623
-
1624
- /**
1625
- * @public
1626
- * A video asset that will be used to fill the given path.
1627
- */
1628
- export declare type VideoFill = {
1629
- /**
1630
- * Type of an asset that will be used to fill the given path.
1631
- */
1632
- type: "VIDEO";
1633
- /**
1634
- * A unique identifier that references a video asset in Canva's backend.
1635
- */
1636
- ref: VideoRef;
1637
- };
1638
-
1639
- /**
1640
- * @public
1641
- * A unique identifier that references a video asset in Canva's backend.
1642
- */
1643
- export declare type VideoRef = string & {
1644
- __videoRef: never;
1645
- };
1646
-
1647
- declare type Width = {
1648
- width: number;
1649
- height: "auto";
1650
- };
1651
-
1652
- declare type WidthAndHeight = {
1653
- /**
1654
- * The width of the box. If height is a number, this can be set to "auto".
1655
- * Otherwise, it must be an integer between 0 and 32767.
1656
- */
1657
- width: number;
1658
- /**
1659
- * The height of the box. If width is a number, this can be set to "auto".
1660
- * Otherwise, it must be an integer between 0 and 32767.
1661
- */
1662
- height: number;
1663
- };
1664
-
1665
- export {};