@canva/design 2.7.3 → 2.7.4-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 CHANGED
@@ -1,5092 +1 @@
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
- * @example Add audio track to design
7
- * ```typescript
8
- * import { addAudioTrack } from "@canva/design";
9
- * import type { AudioTrack } from "@canva/design";
10
- * import type { AudioRef } from "@canva/asset";
11
- *
12
- * const exampleAudioRef = "YOUR_AUDIO_REF" as AudioRef;
13
- *
14
- * const audioTrack: AudioTrack = {
15
- * ref: exampleAudioRef
16
- * };
17
- *
18
- * await addAudioTrack(audioTrack);
19
- * ```
20
- */
21
- export declare const addAudioTrack: (audioTrack: AudioTrack) => Promise<void>;
22
-
23
- /**
24
- * @public
25
- * Add element to responsive documents, which slot things into a text stream
26
- *
27
- * @example Insert an image at cursor position
28
- * ```typescript
29
- * import { addElementAtCursor } from "@canva/design";
30
- * import type { ImageElement } from "@canva/design";
31
- * import type { ImageRef } from "@canva/asset";
32
- *
33
- * const exampleImageRef = "YOUR_IMAGE_REF" as ImageRef;
34
- *
35
- * const imageElement: ImageElement = {
36
- * type: 'image',
37
- * ref: exampleImageRef,
38
- * altText: { text: 'Product image', decorative: false }
39
- * };
40
- *
41
- * await addElementAtCursor(imageElement);
42
- * ```
43
- *
44
- * @example Insert a video at cursor position
45
- * ```typescript
46
- * import { addElementAtCursor } from "@canva/design";
47
- * import type { VideoElement } from "@canva/design";
48
- * import type { VideoRef } from "@canva/asset";
49
- *
50
- * const exampleVideoRef = "YOUR_VIDEO_REF" as VideoRef;
51
- *
52
- * const videoElement: VideoElement = {
53
- * type: 'video',
54
- * ref: exampleVideoRef,
55
- * altText: { text: 'Product demo', decorative: false }
56
- * };
57
- *
58
- * await addElementAtCursor(videoElement);
59
- * ```
60
- *
61
- * @example Insert embedded content at cursor position
62
- * ```typescript
63
- * import { addElementAtCursor } from "@canva/design";
64
- * import type { EmbedElement } from "@canva/design";
65
- *
66
- * const embedElement: EmbedElement = {
67
- * type: 'embed',
68
- * url: 'https://www.youtube.com/watch?v=...'
69
- * };
70
- *
71
- * await addElementAtCursor(embedElement);
72
- * ```
73
- *
74
- * @example Insert text at cursor position
75
- * ```typescript
76
- * import { addElementAtCursor } from "@canva/design";
77
- * import type { TextElement } from "@canva/design";
78
- *
79
- * const textElement: TextElement = {
80
- * type: 'text',
81
- * children: ['Hello World'],
82
- * fontSize: 24,
83
- * color: '#000000'
84
- * };
85
- *
86
- * await addElementAtCursor(textElement);
87
- * ```
88
- *
89
- * @example Insert formatted text at cursor position
90
- * ```typescript
91
- * import { addElementAtCursor, createRichtextRange } from "@canva/design";
92
- * import type { RichtextElement } from "@canva/design";
93
- *
94
- * const range = createRichtextRange();
95
- * range.appendText('Rich Text Content', { color: '#000000' });
96
- *
97
- * const richtextElement: RichtextElement = {
98
- * type: 'richtext',
99
- * range
100
- * };
101
- *
102
- * await addElementAtCursor(richtextElement);
103
- * ```
104
- *
105
- * @example Insert a table at cursor position
106
- * ```typescript
107
- * import { addElementAtCursor } from "@canva/design";
108
- * import type { TableElement } from "@canva/design";
109
- *
110
- * const tableElement: TableElement = {
111
- * type: 'table',
112
- * rows: [
113
- * {
114
- * cells: [
115
- * { type: 'string', value: 'Header 1' },
116
- * { type: 'string', value: 'Header 2' }
117
- * ]
118
- * },
119
- * {
120
- * cells: [
121
- * { type: 'string', value: 'Data 1' },
122
- * { type: 'string', value: 'Data 2' }
123
- * ]
124
- * }
125
- * ]
126
- * };
127
- *
128
- * await addElementAtCursor(tableElement);
129
- * ```
130
- */
131
- export declare const addElementAtCursor: (
132
- element: ElementAtCursor,
133
- ) => Promise<void>;
134
-
135
- /**
136
- * @public
137
- * Add element to fixed designs, which use a coordinate-based positioning system.
138
- *
139
- * @example Insert an image at specific coordinates
140
- * ```typescript
141
- * import { addElementAtPoint } from "@canva/design";
142
- * import type { ImageElementAtPoint } from "@canva/design";
143
- * import type { ImageRef } from "@canva/asset";
144
- *
145
- * const exampleImageRef = "YOUR_IMAGE_REF" as ImageRef;
146
- *
147
- * const imageElement: ImageElementAtPoint = {
148
- * type: 'image',
149
- * ref: exampleImageRef,
150
- * altText: { text: 'Product image', decorative: false },
151
- * top: 100,
152
- * left: 100,
153
- * width: 300,
154
- * height: 200
155
- * };
156
- *
157
- * await addElementAtPoint(imageElement);
158
- * ```
159
- *
160
- * @example Insert a video at specific coordinates
161
- * ```typescript
162
- * import { addElementAtPoint } from "@canva/design";
163
- * import type { VideoElementAtPoint } from "@canva/design";
164
- * import type { VideoRef } from "@canva/asset";
165
- *
166
- * const exampleVideoRef = "YOUR_VIDEO_REF" as VideoRef;
167
- *
168
- * const videoElement: VideoElementAtPoint = {
169
- * type: 'video',
170
- * ref: exampleVideoRef,
171
- * altText: { text: 'Product demo', decorative: false },
172
- * top: 100,
173
- * left: 100,
174
- * width: 400,
175
- * height: 300
176
- * };
177
- *
178
- * await addElementAtPoint(videoElement);
179
- * ```
180
- *
181
- * @example Insert embedded content at specific coordinates
182
- * ```typescript
183
- * import { addElementAtPoint } from "@canva/design";
184
- * import type { EmbedElementAtPoint } from "@canva/design";
185
- *
186
- * const embedElement: EmbedElementAtPoint = {
187
- * type: 'embed',
188
- * url: 'https://www.youtube.com/watch?v=...',
189
- * top: 100,
190
- * left: 100,
191
- * width: 560,
192
- * height: 315
193
- * };
194
- *
195
- * await addElementAtPoint(embedElement);
196
- * ```
197
- *
198
- * @example Insert text at specific coordinates
199
- * ```typescript
200
- * import { addElementAtPoint } from "@canva/design";
201
- * import type { TextElementAtPoint } from "@canva/design";
202
- *
203
- * const textElement: TextElementAtPoint = {
204
- * type: 'text',
205
- * children: ['Hello World'],
206
- * top: 100,
207
- * left: 100,
208
- * width: 200,
209
- * fontSize: 24,
210
- * color: '#000000',
211
- * textAlign: 'justify'
212
- * };
213
- *
214
- * await addElementAtPoint(textElement);
215
- * ```
216
- */
217
- export declare const addElementAtPoint: (
218
- element: DesignElement | ElementAtPoint,
219
- ) => Promise<void>;
220
-
221
- /**
222
- * @deprecated
223
- * @public
224
- * Adds a native element to the user's design.
225
- * @param element - The element to add to the user's design.
226
- *
227
- * @example Basic usage
228
- * ```typescript
229
- * import { addNativeElement } from "@canva/design";
230
- * import type { NativeElementWithBox } from "@canva/design";
231
- *
232
- * const element: NativeElementWithBox = {
233
- * type: 'text',
234
- * children: ['Legacy element'],
235
- * top: 100,
236
- * left: 100,
237
- * width: 200
238
- * };
239
- *
240
- * await addNativeElement(element);
241
- * ```
242
- */
243
- export declare const addNativeElement: (
244
- element: NativeElement | NativeElementWithBox,
245
- ) => Promise<void>;
246
-
247
- /**
248
- * @public
249
- * Adds a new page immediately after the currently selected page.
250
- * @param opts - Configuration for the new page to be added.
251
- *
252
- * @example Create empty page
253
- * ```typescript
254
- * import { addPage } from "@canva/design";
255
- *
256
- * await addPage();
257
- * ```
258
- *
259
- * @example Create page with title
260
- * ```typescript
261
- * import { addPage } from "@canva/design";
262
- *
263
- * await addPage({
264
- * title: 'My New Page'
265
- * });
266
- * ```
267
- *
268
- * @example Create page with background color
269
- * ```typescript
270
- * import { addPage } from "@canva/design";
271
- * import type { PageBackgroundFill } from "@canva/design";
272
- *
273
- * const background: PageBackgroundFill = {
274
- * color: '#F5F5F5',
275
- * };
276
- *
277
- * await addPage({ background });
278
- * ```
279
- *
280
- * @example Create page with background image
281
- * ```typescript
282
- * import { addPage } from "@canva/design";
283
- * import type { PageBackgroundFill } from "@canva/design";
284
- * import type { ImageRef } from "@canva/asset";
285
- *
286
- * const exampleImageRef = "YOUR_IMAGE_REF" as ImageRef;
287
- *
288
- * const background: PageBackgroundFill = {
289
- * asset: {
290
- * type: 'image',
291
- * ref: exampleImageRef,
292
- * altText: { text: 'Background image', decorative: true }
293
- * },
294
- * };
295
- *
296
- * await addPage({ background });
297
- * ```
298
- *
299
- * @example Create page with multiple elements
300
- * ```typescript
301
- * import { addPage } from "@canva/design";
302
- * import type { TextElementAtPoint, ImageElementAtPoint } from "@canva/design";
303
- * import type { ImageRef } from "@canva/asset";
304
- *
305
- * const exampleImageRef = "YOUR_IMAGE_REF" as ImageRef;
306
- *
307
- * await addPage({
308
- * elements: [
309
- * {
310
- * type: 'text',
311
- * children: ['Page Title'],
312
- * top: 50,
313
- * left: 100,
314
- * width: 400,
315
- * fontSize: 32,
316
- * textAlign: 'center'
317
- * } as TextElementAtPoint,
318
- * {
319
- * type: 'text',
320
- * children: ['Subtitle text'],
321
- * top: 100,
322
- * left: 100,
323
- * width: 400,
324
- * fontSize: 18,
325
- * textAlign: 'center'
326
- * } as TextElementAtPoint,
327
- * {
328
- * type: 'image',
329
- * ref: exampleImageRef,
330
- * altText: { text: 'Featured image', decorative: false },
331
- * top: 150,
332
- * left: 200,
333
- * width: 200,
334
- * height: 200
335
- * } as ImageElementAtPoint,
336
- * ]
337
- * });
338
- * ```
339
- */
340
- export declare const addPage: (opts?: {
341
- /** Elements to be added to the page */
342
- elements?: ElementAtPoint[];
343
- /**
344
- * The page background. This can be a solid color, an image or a video.
345
- **/
346
- background?: PageBackgroundFill;
347
- /** A page title which must be no longer than 255 characters */
348
- title?: string;
349
- }) => Promise<void>;
350
-
351
- /**
352
- * @public
353
- * Alternative text for a11y compliance.
354
- */
355
- export declare type AltText = {
356
- /**
357
- * The text content.
358
- */
359
- text: string;
360
- /**
361
- * Indicates where the alternative text should be displayed.
362
- *
363
- * @remarks
364
- * - If `true`, the alternative text will only be displayed in the editor.
365
- * - If `false`, the alternative text will be displayed in the editor and in view-only mode.
366
- */
367
- decorative: boolean | undefined;
368
- };
369
-
370
- /**
371
- * @public
372
- * A callback that runs when:
373
- *
374
- * - the app element is created
375
- * - the app element's data is updated
376
- * - the user selects an existing app element
377
- *
378
- * @param appElement - Information about the app element that was changed.
379
- *
380
- * @example Handle element selection
381
- * ```typescript
382
- * import { initAppElement } from "@canva/design";
383
- *
384
- * const appElement = initAppElement<{ content: string }>({
385
- * render: (data) => {
386
- * // Render based on data
387
- * return [{
388
- * type: 'text',
389
- * children: [data.content || 'Default text'],
390
- * top: 0,
391
- * left: 0,
392
- * width: 200
393
- * }];
394
- * }
395
- * });
396
- *
397
- * appElement.registerOnElementChange((element) => {
398
- * if (element) {
399
- * // Element selected or created, do something with the `element.data`
400
- * } else {
401
- * // No element selected
402
- * }
403
- * });
404
- * ```
405
- *
406
- * @example Update element data when selected
407
- * ```typescript
408
- * import { initAppElement } from "@canva/design";
409
- *
410
- * const appElement = initAppElement<{
411
- * content: string;
412
- * lastSelected: number;
413
- * lastUpdated: number;
414
- * metadata: { lastEdited: number; editCount: number };
415
- * }>({
416
- * render: (data) => {
417
- * // Render based on data
418
- * return [{
419
- * type: 'text',
420
- * children: [data.content || 'Default text'],
421
- * top: 0,
422
- * left: 0,
423
- * width: 200
424
- * }];
425
- * }
426
- * });
427
- *
428
- * appElement.registerOnElementChange(async (element) => {
429
- * if (element) {
430
- * // Use the update method to modify the element's data
431
- * await element.update({
432
- * data: {
433
- * ...element.data,
434
- * lastSelected: Date.now()
435
- * }
436
- * });
437
- * }
438
- * });
439
- * ```
440
- */
441
- export declare type AppElementChangeHandler<A extends AppElementData> = (
442
- appElement:
443
- | {
444
- /**
445
- * The app element data in its most recent state.
446
- */
447
- data: A;
448
- /**
449
- * The version number of the app.
450
- */
451
- version: number;
452
- /**
453
- * Function to update the app element data.
454
- *
455
- * @param opts - The data and placement to update the app element with.
456
- *
457
- * @example Update element data only
458
- * ```typescript
459
- * if (element) {
460
- * await element.update({
461
- * data: {
462
- * ...element.data,
463
- * content: 'Updated content',
464
- * lastUpdated: Date.now()
465
- * }
466
- * });
467
- * }
468
- * ```
469
- *
470
- * @example Update data and placement
471
- * ```typescript
472
- * if (element) {
473
- * await element.update({
474
- * data: {
475
- * ...element.data,
476
- * content: 'Positioned element'
477
- * },
478
- * placement: {
479
- * top: 200,
480
- * left: 200,
481
- * width: 300,
482
- * height: 100
483
- * }
484
- * });
485
- * }
486
- * ```
487
- *
488
- * @example Add metadata to element
489
- * ```typescript
490
- * if (element) {
491
- * await element.update({
492
- * data: {
493
- * ...element.data,
494
- * metadata: {
495
- * ...(element.data.metadata || {}),
496
- * lastEdited: Date.now(),
497
- * editCount: (element.data.metadata?.editCount || 0) + 1,
498
- * },
499
- * },
500
- * });
501
- * }
502
- * ```
503
- */
504
- update: (opts: AppElementOptions<A>) => Promise<void>;
505
- }
506
- | undefined,
507
- ) => void;
508
-
509
- /**
510
- * @public
511
- * A client that provides methods for creating and managing the lifecycle of an app element.
512
- */
513
- export declare interface AppElementClient<A extends AppElementData> {
514
- /**
515
- * @deprecated This type has been superseded, use `addElement` or `registerOnElementChange` instead.
516
- * If an app element is selected, the element's data is overwritten and the element is re-rendered.
517
- * Otherwise, the provided data is used to create a new app element.
518
- * @param appElementData - The data to attach to the app element. Existing data will be overwritten.
519
- * @param placement - The position, dimensions, and rotation of the app element.
520
- *
521
- * @example Create or update an element (deprecated)
522
- * ```typescript
523
- * import { initAppElement } from "@canva/design";
524
- *
525
- * // Initialize the app element client
526
- * const appElement = initAppElement<{ content: string; timestamp: number }>({
527
- * render: (data) => {
528
- * return [{
529
- * type: 'text',
530
- * children: [data.content || 'Default text'],
531
- * top: 100,
532
- * left: 100,
533
- * width: 200
534
- * }];
535
- * }
536
- * });
537
- *
538
- * // Create a new element or update selected element
539
- * await appElement.addOrUpdateElement({
540
- * content: 'Hello from the app',
541
- * timestamp: Date.now()
542
- * });
543
- * ```
544
- *
545
- * @example Update with specific placement (deprecated)
546
- * ```typescript
547
- * import { initAppElement } from "@canva/design";
548
- *
549
- * const appElement = initAppElement<{ content: string }>({
550
- * render: (data) => {
551
- * return [{
552
- * type: 'text',
553
- * children: [data.content || 'Default text'],
554
- * top: 0,
555
- * left: 0,
556
- * width: 200
557
- * }];
558
- * }
559
- * });
560
- *
561
- * // Create or update with specific placement
562
- * await appElement.addOrUpdateElement(
563
- * {
564
- * content: 'Positioned content'
565
- * },
566
- * {
567
- * top: 200,
568
- * left: 200,
569
- * width: 300,
570
- * height: 100
571
- * }
572
- * );
573
- * ```
574
- */
575
- addOrUpdateElement(appElementData: A, placement?: Placement): Promise<void>;
576
- /**
577
- * Adds a new app element to the design.
578
- * @param opts - The data and placement of the app element.
579
- *
580
- * @example Add new element with data
581
- * ```typescript
582
- * import { initAppElement } from "@canva/design";
583
- *
584
- * const appElement = initAppElement<{ content: string; id: string }>({
585
- * render: (data) => {
586
- * return [{
587
- * type: 'text',
588
- * children: [data.content || 'Default text'],
589
- * top: 0,
590
- * left: 0,
591
- * width: 200
592
- * }];
593
- * }
594
- * });
595
- *
596
- * // Add a new element
597
- * await appElement.addElement({
598
- * data: {
599
- * content: 'New element content',
600
- * id: 'element-' + Date.now()
601
- * }
602
- * });
603
- * ```
604
- *
605
- * @example Add element with specific placement
606
- * ```typescript
607
- * import { initAppElement } from "@canva/design";
608
- *
609
- * const appElement = initAppElement<{
610
- * title: string;
611
- * description: string;
612
- * createdAt: number;
613
- * }>({
614
- * render: (data) => {
615
- * return [{
616
- * type: 'text',
617
- * children: [data.title || 'Default title'],
618
- * top: 0,
619
- * left: 0,
620
- * width: 300,
621
- * fontWeight: 'bold',
622
- * fontSize: 24
623
- * }, {
624
- * type: 'text',
625
- * children: [data.description || 'Default description'],
626
- * top: 50,
627
- * left: 0,
628
- * width: 300
629
- * }];
630
- * }
631
- * });
632
- *
633
- * // Add element with specific placement
634
- * await appElement.addElement({
635
- * data: {
636
- * title: 'Element Title',
637
- * description: 'This is a description of the element',
638
- * createdAt: Date.now()
639
- * },
640
- * placement: {
641
- * top: 100,
642
- * left: 100,
643
- * width: 400,
644
- * height: 150,
645
- * rotation: 0
646
- * }
647
- * });
648
- * ```
649
- */
650
- addElement(opts: AppElementOptions<A>): Promise<void>;
651
- /**
652
- * A callback that runs when:
653
- *
654
- * - the app element is created
655
- * - the app element's data is updated
656
- * - the user selects an existing app element
657
- *
658
- * @param handler - The callback to run when the app element changes.
659
- *
660
- * @example Handle element selection and update
661
- * ```typescript
662
- * import { initAppElement } from "@canva/design";
663
- *
664
- * const appElement = initAppElement<{ content: string }>({
665
- * render: (data) => {
666
- * return [{
667
- * type: 'text',
668
- * children: [data.content || 'Default text'],
669
- * top: 0,
670
- * left: 0,
671
- * width: 200
672
- * }];
673
- * }
674
- * });
675
- *
676
- * // Register a handler for element changes
677
- * appElement.registerOnElementChange((element) => {
678
- * if (element) {
679
- * // Element is created or selected
680
- * // Optionally update the element
681
- * // element.update({
682
- * // data: { ...element.data, lastSelected: Date.now() }
683
- * // });
684
- * } else {
685
- * // No element is selected
686
- * }
687
- * });
688
- * ```
689
- *
690
- * @example Update element when selected
691
- * ```typescript
692
- * import { initAppElement } from "@canva/design";
693
- *
694
- * const appElement = initAppElement<{
695
- * content: string;
696
- * metadata: { created: number; lastSelected: number };
697
- * }>({
698
- * render: (data) => {
699
- * // Render based on data
700
- * return [{
701
- * type: 'text',
702
- * children: [data.content || ''],
703
- * top: 0,
704
- * left: 0,
705
- * width: 200
706
- * }];
707
- * }
708
- * });
709
- *
710
- * // Update element when selected
711
- * appElement.registerOnElementChange(async (element) => {
712
- * if (element) {
713
- * // Check if this is a newly created or a selected element
714
- * const isNewElement = !element.data.metadata?.created;
715
- *
716
- * if (isNewElement) {
717
- * // Update a new element with initial metadata
718
- * await element.update({
719
- * data: {
720
- * ...element.data,
721
- * metadata: {
722
- * created: Date.now(),
723
- * lastSelected: Date.now()
724
- * }
725
- * }
726
- * });
727
- * } else {
728
- * // Update existing element's last selected time
729
- * await element.update({
730
- * data: {
731
- * ...element.data,
732
- * metadata: {
733
- * ...element.data.metadata,
734
- * lastSelected: Date.now()
735
- * }
736
- * }
737
- * });
738
- * }
739
- * }
740
- * });
741
- * ```
742
- */
743
- registerOnElementChange(handler: AppElementChangeHandler<A>): void;
744
- }
745
-
746
- /**
747
- * @public
748
- * Options for creating an app element client.
749
- */
750
- export declare type AppElementClientConfiguration<A extends AppElementData> = {
751
- /**
752
- * Registers a callback that renders an app element based on the data it receives.
753
- */
754
- render: AppElementRenderer<A>;
755
- };
756
-
757
- /**
758
- * @public
759
- * The data associated with an app element.
760
- */
761
- export declare type AppElementData = Record<string, Value>;
762
-
763
- /**
764
- * @public
765
- * Used to add or update an app element to the design.
766
- * The update function is provided in the AppElementChangeHandler callback (registerOnElementChange).
767
- */
768
- export declare type AppElementOptions<A extends AppElementData> = {
769
- /**
770
- * The data to attach to the app element.
771
- */
772
- data: A;
773
- /**
774
- * The position, dimensions, and rotation of the app element.
775
- */
776
- placement?: Placement;
777
- };
778
-
779
- /**
780
- * @public
781
- * A callback function that renders an app element based on the data it receives.
782
- * @param appElementData - The data the callback must use to render the app element.
783
- */
784
- export declare type AppElementRenderer<A extends AppElementData> = (
785
- appElementData: A,
786
- ) => AppElementRendererOutput;
787
-
788
- /**
789
- * @public
790
- * An array of one or more elements to render as output of an app element.
791
- */
792
- export declare type AppElementRendererOutput = GroupContentAtPoint[];
793
-
794
- /**
795
- * @public
796
- * A unique identifier that references an app runtime process
797
- */
798
- export declare type AppProcessId = string & {
799
- __appProcessId: never;
800
- };
801
-
802
- /**
803
- * @public
804
- * Audio track to be added to the design at the end of a drag event.
805
- */
806
- export declare type AudioDragConfig = {
807
- /**
808
- * The type of element.
809
- */
810
- type: "audio";
811
- /**
812
- * A function that returns a reference (ref) to an audio asset in Canva's backend.
813
- */
814
- resolveAudioRef: () => Promise<{
815
- ref: AudioRef;
816
- }>;
817
- /**
818
- * The duration of the audio track, in milliseconds.
819
- */
820
- durationMs: number;
821
- /**
822
- * A human readable title for the audio track.
823
- */
824
- title: string;
825
- };
826
-
827
- /**
828
- * @public
829
- * A unique identifier that references an audio asset in Canva's backend.
830
- */
831
- export declare type AudioRef = string & {
832
- __audioRef: never;
833
- };
834
-
835
- /**
836
- * @public
837
- * An audio track that can be added to a design.
838
- */
839
- export declare type AudioTrack = {
840
- /**
841
- * A unique identifier that points to an audio asset in Canva's backend.
842
- */
843
- ref: AudioRef;
844
- };
845
-
846
- /**
847
- * @public
848
- * A segment of a richtext range.
849
- */
850
- export declare type Bounds = {
851
- /**
852
- * The starting position of the segment.
853
- *
854
- * @remarks
855
- * This is zero-based, meaning the first character of the range is at index 0.
856
- */
857
- index: number;
858
- /**
859
- * The number of characters in the segment, starting from the index.
860
- */
861
- length: number;
862
- };
863
-
864
- /**
865
- * @deprecated
866
- * @public
867
- * A position, rotation, and set of dimensions.
868
- *
869
- * @remarks
870
- * The position and dimensions are relative to the container.
871
- */
872
- export declare type Box = Point & (WidthAndHeight | Width | Height);
873
-
874
- /**
875
- * @public
876
- * An individual cell in a table element.
877
- */
878
- export declare type Cell = {
879
- /**
880
- * The attributes of the cell.
881
- */
882
- attributes?: CellAttributes;
883
- /**
884
- * The number of columns that the cell occupies.
885
- */
886
- colSpan?: number;
887
- /**
888
- * The number of rows that the cell occupies.
889
- */
890
- rowSpan?: number;
891
- } & CellContent;
892
-
893
- /**
894
- * @public
895
- * Additional attributes of table cell.
896
- */
897
- declare type CellAttributes = {
898
- /**
899
- * The background color of the cell, as a hex code.
900
- */
901
- backgroundColor?: string;
902
- } & TextAttributes;
903
-
904
- /**
905
- * @public
906
- * The content of a table element's cell.
907
- * Cell only supports plain text.
908
- */
909
- declare type CellContent =
910
- | {
911
- /**
912
- * Indicates that the cell doesn't have any content.
913
- */
914
- type: "empty";
915
- }
916
- | {
917
- /**
918
- * Indicates that the cell contains plaintext content.
919
- */
920
- type: "string";
921
- /**
922
- * The plaintext content of the cell.
923
- *
924
- * @remarks
925
- * If an empty string is provided, the `type` will change to `"empty"`.
926
- */
927
- value: string;
928
- };
929
-
930
- /**
931
- * Image element or content to be added to the design at the end of a drag event.
932
- */
933
- declare type CommonImageDragConfig = {
934
- /**
935
- * The type of element.
936
- */
937
- type: "image";
938
- /**
939
- * The dimensions of the preview image.
940
- */
941
- previewSize: Dimensions;
942
- };
943
-
944
- /**
945
- * @public
946
- * A snapshot of content from a user's design.
947
- */
948
- export declare interface ContentDraft<T> {
949
- /**
950
- * The individual content items that exist within the snapshot.
951
- *
952
- * @remarks
953
- * Any changes made to this array won't be reflected in the user's design until the `save` method is called.
954
- */
955
- readonly contents: readonly T[];
956
- /**
957
- * Saves changes made to the content items in the `contents` array.
958
- *
959
- * @remarks
960
- * Once this method is called:
961
- *
962
- * - Any changes the app has made to to the content will be reflected in the user's design.
963
- * - Any changes the user has made to the content since the snapshot was created may be overwritten.
964
- * - Only properties that are different from the original state will be written to the design.
965
- *
966
- * @example Save changes to selected text
967
- * ```typescript
968
- * import { selection } from "@canva/design";
969
- *
970
- * selection.registerOnChange({
971
- * scope: 'plaintext',
972
- * onChange: async (event) => {
973
- * if (event.count > 0) {
974
- * const draft = await event.read();
975
- *
976
- * // Make changes to the content
977
- * for (const content of draft.contents) {
978
- * content.text = content.text.toUpperCase();
979
- * }
980
- *
981
- * // Save the changes to the design
982
- * await draft.save();
983
- * }
984
- * }
985
- * });
986
- * ```
987
- *
988
- * @example Modify then save rich text content
989
- * ```typescript
990
- * import { selection } from "@canva/design";
991
- *
992
- * selection.registerOnChange({
993
- * scope: 'richtext',
994
- * onChange: async (event) => {
995
- * if (event.count > 0) {
996
- * const draft = await event.read();
997
- * const range = draft.contents[0];
998
- *
999
- * // Get the plain text
1000
- * const text = range.readPlaintext();
1001
- *
1002
- * // Apply formatting to the entire text
1003
- * range.formatText(
1004
- * { index: 0, length: text.length },
1005
- * { fontWeight: 'bold', color: '#0066CC' }
1006
- * );
1007
- *
1008
- * // Save the formatted text back to the design
1009
- * await draft.save();
1010
- * }
1011
- * }
1012
- * });
1013
- * ```
1014
- */
1015
- save(): Promise<void>;
1016
- }
1017
-
1018
- /**
1019
- * @public
1020
- * A type of content that can be read from a user's design.
1021
- */
1022
- export declare type ContentType = "richtext";
1023
-
1024
- /**
1025
- * @public
1026
- * Options for configuring where content in a design should be queried from.
1027
- */
1028
- export declare type ContextOptions = {
1029
- target: "current_page";
1030
- };
1031
-
1032
- /**
1033
- * @public
1034
- * A set of X and Y coordinates.
1035
- */
1036
- export declare type Coordinates = {
1037
- /**
1038
- * X coordinate, in pixels.
1039
- */
1040
- x: number;
1041
- /**
1042
- * Y coordinate, in pixels.
1043
- */
1044
- y: number;
1045
- };
1046
-
1047
- /**
1048
- * @public
1049
- * Creates a new RichtextRange object, which contains methods to manipulate text.
1050
- *
1051
- * @example Create formatted text range
1052
- * ```typescript
1053
- * import { createRichtextRange } from "@canva/design";
1054
- * import type { InlineFormatting } from "@canva/design";
1055
- *
1056
- * const range = createRichtextRange();
1057
- *
1058
- * range.appendText('Hello World', {
1059
- * color: '#000000',
1060
- * fontWeight: 'bold'
1061
- * } as InlineFormatting);
1062
- * ```
1063
- *
1064
- * @example Format paragraph styles
1065
- * ```typescript
1066
- * import { createRichtextRange } from "@canva/design";
1067
- * import type { RichtextFormatting } from "@canva/design";
1068
- *
1069
- * const range = createRichtextRange();
1070
- *
1071
- * const bounds = range.appendText('Centered Title\n');
1072
- * range.formatParagraph(bounds.bounds, {
1073
- * fontSize: 32,
1074
- * textAlign: 'center'
1075
- * } as RichtextFormatting);
1076
- * ```
1077
- *
1078
- * @example Create bulleted list
1079
- * ```typescript
1080
- * import { createRichtextRange } from "@canva/design";
1081
- *
1082
- * const range = createRichtextRange();
1083
- *
1084
- * const item = range.appendText('List item\n');
1085
- * range.formatParagraph(item.bounds, {
1086
- * fontSize: 16,
1087
- * listLevel: 1,
1088
- * listMarker: 'disc'
1089
- * });
1090
- * ```
1091
- *
1092
- * @example Extract text content
1093
- * ```typescript
1094
- * import { createRichtextRange } from "@canva/design";
1095
- *
1096
- * const range = createRichtextRange();
1097
- * range.appendText('Sample text');
1098
- *
1099
- * // Get plain text content
1100
- * const text = range.readPlaintext();
1101
- *
1102
- * // Get formatted regions
1103
- * const regions = range.readTextRegions();
1104
- * ```
1105
- *
1106
- * @example Replace text with formatting
1107
- * ```typescript
1108
- * import { createRichtextRange } from "@canva/design";
1109
- *
1110
- * const range = createRichtextRange();
1111
- * range.appendText('Original text');
1112
- *
1113
- * // Replace text while adding formatting
1114
- * range.replaceText(
1115
- * { index: 0, length: range.readPlaintext().length },
1116
- * 'Modified',
1117
- * { color: '#0066CC', decoration: 'underline' }
1118
- * );
1119
- * ```
1120
- */
1121
- export declare const createRichtextRange: () => RichtextRange;
1122
-
1123
- /**
1124
- * @public
1125
- * Describes a part of a design.
1126
- */
1127
- export declare type DesignContext = DesignContextOptions["type"];
1128
-
1129
- /**
1130
- * @public
1131
- * Options for configuring which part of a design to read.
1132
- */
1133
- declare type DesignContextOptions = {
1134
- /**
1135
- * The type of context.
1136
- */
1137
- type: "current_page";
1138
- };
1139
-
1140
- /**
1141
- * @public
1142
- * Provides methods for reading and updating the structure and content of a design.
1143
- */
1144
- export declare namespace DesignEditing {
1145
- /**
1146
- * @public
1147
- * Options for creating an image fill in the element state builder
1148
- */
1149
- export type ImageFillOpts = {
1150
- /**
1151
- * The type of media.
1152
- */
1153
- type: "image";
1154
- /**
1155
- * A unique identifier that points to an image asset in Canva's backend.
1156
- */
1157
- imageRef: ImageRef;
1158
- /**
1159
- * If `true`, the image is flipped horizontally.
1160
- */
1161
- flipX?: boolean;
1162
- /**
1163
- * If `true`, the image is flipped vertically.
1164
- */
1165
- flipY?: boolean;
1166
- };
1167
- /**
1168
- * @public
1169
- * Options for creating a video fill in the element state builder
1170
- */
1171
- export type VideoFillOpts = {
1172
- /**
1173
- * The type of media.
1174
- */
1175
- type: "video";
1176
- /**
1177
- * A unique identifier that points to a video asset in Canva's backend.
1178
- */
1179
- videoRef: VideoRef;
1180
- /**
1181
- * If `true`, the video is flipped horizontally.
1182
- */
1183
- flipX?: boolean;
1184
- /**
1185
- * If `true`, the video is flipped vertically.
1186
- */
1187
- flipY?: boolean;
1188
- };
1189
- /**
1190
- * @public
1191
- * Options for creating a media fill in the element state builder
1192
- */
1193
- export type MediaContainerOpts = ImageFillOpts | VideoFillOpts;
1194
- /**
1195
- * @public
1196
- * Options for creating a fill in the element state builder
1197
- */
1198
- export type FillOpts =
1199
- | {
1200
- colorContainer: ColorContainerOpts;
1201
- mediaContainer?: MediaContainerOpts;
1202
- }
1203
- | {
1204
- colorContainer?: ColorContainerOpts;
1205
- mediaContainer: MediaContainerOpts;
1206
- };
1207
- /**
1208
- * @public
1209
- * Options for creating a fill of a shape in the element state builder
1210
- */
1211
- export type PathFillOpts =
1212
- | {
1213
- colorContainer: ColorContainerOpts;
1214
- mediaContainer?: MediaContainerOpts;
1215
- isMediaEditable?: boolean;
1216
- }
1217
- | {
1218
- colorContainer?: ColorContainerOpts;
1219
- mediaContainer: MediaContainerOpts;
1220
- isMediaEditable?: boolean;
1221
- };
1222
- /**
1223
- * @public
1224
- */
1225
- export type ColorContainerOpts = SolidFillState;
1226
- /**
1227
- * @public
1228
- * Options for creating a stroke in the element state builder
1229
- */
1230
- export type StrokeOpts = {
1231
- /**
1232
- * The weight (thickness) of the stroke.
1233
- *
1234
- * @remarks
1235
- * - Minimum: 0
1236
- * - Maximum: 100
1237
- */
1238
- weight: number;
1239
- /**
1240
- * The color of the stroke.
1241
- */
1242
- colorContainer: ColorContainerOpts;
1243
- };
1244
- /**
1245
- * @public
1246
- * Options for creating a shape path in the element state builder
1247
- */
1248
- export type PathOpts = {
1249
- d: string;
1250
- /**
1251
- * Describes how a fill is filled with color or media.
1252
- *
1253
- * @remarks
1254
- * If both `media` and `color` are defined, `media` takes precedence.
1255
- */
1256
- fill?: PathFillOpts;
1257
- /**
1258
- * The outline of the path.
1259
- */
1260
- stroke?: StrokeOpts;
1261
- };
1262
- /**
1263
- * @public
1264
- * Options for creating a rect element.
1265
- */
1266
- export type CreateRectElementOpts = {
1267
- /**
1268
- * The distance from the top edge of the container, in pixels.
1269
- *
1270
- * @remarks
1271
- * - The pixels are relative to their container.
1272
- * - Minimum: -32768
1273
- * - Maximum: 32767
1274
- */
1275
- top: number;
1276
- /**
1277
- * The distance from the left edge of the container, in pixels.
1278
- *
1279
- * @remarks
1280
- * - The pixels are relative to their container.
1281
- * - Minimum: -32768
1282
- * - Maximum: 32767
1283
- */
1284
- left: number;
1285
- /**
1286
- * A rotation, in degrees.
1287
- *
1288
- * @remarks
1289
- * - Minimum: -180
1290
- * - Maximum: 180
1291
- */
1292
- rotation?: number;
1293
- /**
1294
- * Transparency as a percentage.
1295
- *
1296
- * @remarks
1297
- * - Minimum: 0
1298
- * - Maximum: 1
1299
- */
1300
- transparency?: number;
1301
- /**
1302
- * A width, in pixels.
1303
- */
1304
- width: number;
1305
- /**
1306
- * A height, in pixels.
1307
- */
1308
- height: number;
1309
- /**
1310
- * Describes how a fill is filled with color or media.
1311
- *
1312
- * @remarks
1313
- * If both `media` and `color` are defined, `media` takes precedence.
1314
- */
1315
- fill?: FillOpts;
1316
- /**
1317
- * The outline of the rect.
1318
- */
1319
- stroke?: StrokeOpts;
1320
- };
1321
- /**
1322
- * @public
1323
- * Options for creating a shape element.
1324
- */
1325
- export type CreateShapeElementOpts = {
1326
- /**
1327
- * The distance from the top edge of the container, in pixels.
1328
- *
1329
- * @remarks
1330
- * - The pixels are relative to their container.
1331
- * - Minimum: -32768
1332
- * - Maximum: 32767
1333
- */
1334
- top: number;
1335
- /**
1336
- * The distance from the left edge of the container, in pixels.
1337
- *
1338
- * @remarks
1339
- * - The pixels are relative to their container.
1340
- * - Minimum: -32768
1341
- * - Maximum: 32767
1342
- */
1343
- left: number;
1344
- /**
1345
- * A rotation, in degrees.
1346
- *
1347
- * @remarks
1348
- * - Minimum: -180
1349
- * - Maximum: 180
1350
- */
1351
- rotation?: number;
1352
- /**
1353
- * Transparency as a percentage.
1354
- *
1355
- * @remarks
1356
- * - Minimum: 0
1357
- * - Maximum: 1
1358
- */
1359
- transparency?: number;
1360
- /**
1361
- * A width, in pixels.
1362
- */
1363
- width: number;
1364
- /**
1365
- * A height, in pixels.
1366
- */
1367
- height: number;
1368
- /**
1369
- * The scale and cropping of the shape.
1370
- */
1371
- readonly viewBox: AlignedBoxState;
1372
- /**
1373
- * The paths that define the structure of the shape.
1374
- *
1375
- * @remarks
1376
- * - Must have between 1 and 30 paths.
1377
- * - Total size of all paths must not exceed 2kb.
1378
- * - Maximum of 6 unique fill colors across all paths.
1379
- */
1380
- paths: PathOpts[];
1381
- };
1382
- /**
1383
- * @public
1384
- * Options for creating an embed element.
1385
- */
1386
- export type CreateEmbedElementOpts = {
1387
- /**
1388
- * The distance from the top edge of the container, in pixels.
1389
- *
1390
- * @remarks
1391
- * - The pixels are relative to their container.
1392
- * - Minimum: -32768
1393
- * - Maximum: 32767
1394
- */
1395
- top: number;
1396
- /**
1397
- * The distance from the left edge of the container, in pixels.
1398
- *
1399
- * @remarks
1400
- * - The pixels are relative to their container.
1401
- * - Minimum: -32768
1402
- * - Maximum: 32767
1403
- */
1404
- left: number;
1405
- /**
1406
- * A rotation, in degrees.
1407
- *
1408
- * @remarks
1409
- * - Minimum: -180
1410
- * - Maximum: 180
1411
- */
1412
- rotation?: number;
1413
- /**
1414
- * Transparency as a percentage.
1415
- *
1416
- * @remarks
1417
- * - Minimum: 0
1418
- * - Maximum: 1
1419
- */
1420
- transparency?: number;
1421
- /**
1422
- * A width, in pixels.
1423
- */
1424
- width: number;
1425
- /**
1426
- * A height, in pixels.
1427
- */
1428
- height: number;
1429
- /**
1430
- * The URL of the rich media.
1431
- *
1432
- * @remarks
1433
- * This URL must be supported by the Iframely API.
1434
- */
1435
- url: string;
1436
- };
1437
- /**
1438
- * @public
1439
- * Options for creating a text element.
1440
- */
1441
- export type CreateTextElementOpts = {
1442
- /**
1443
- * The distance from the top edge of the container, in pixels.
1444
- *
1445
- * @remarks
1446
- * - The pixels are relative to their container.
1447
- * - Minimum: -32768
1448
- * - Maximum: 32767
1449
- */
1450
- top: number;
1451
- /**
1452
- * The distance from the left edge of the container, in pixels.
1453
- *
1454
- * @remarks
1455
- * - The pixels are relative to their container.
1456
- * - Minimum: -32768
1457
- * - Maximum: 32767
1458
- */
1459
- left: number;
1460
- /**
1461
- * A width, in pixels.
1462
- */
1463
- width: number;
1464
- /**
1465
- * The text content.
1466
- */
1467
- text: {
1468
- regions: readonly TextRegion[];
1469
- };
1470
- /**
1471
- * A rotation, in degrees.
1472
- *
1473
- * @remarks
1474
- * - Minimum: -180
1475
- * - Maximum: 180
1476
- */
1477
- rotation?: number;
1478
- /**
1479
- * Transparency as a percentage.
1480
- *
1481
- * @remarks
1482
- * - Minimum: 0
1483
- * - Maximum: 1
1484
- */
1485
- transparency?: number;
1486
- };
1487
- /**
1488
- * @public
1489
- * Provides methods for creating element states.
1490
- *
1491
- * @remarks
1492
- * These methods don't add the elements to the design. They only return elements that can
1493
- * be added to a design, such as with the `insertAfter` method.
1494
- *
1495
- * @preventInline
1496
- */
1497
- export interface ElementStateBuilder {
1498
- /**
1499
- * Creates a rect element state.
1500
- * @param opts - Options for creating the rect element.
1501
- */
1502
- createRectElement(opts: CreateRectElementOpts): RectElementState;
1503
- /**
1504
- * Creates a shape element state.
1505
- * @param opts - Options for creating the shape element.
1506
- */
1507
- createShapeElement(opts: CreateShapeElementOpts): ShapeElementState;
1508
- /**
1509
- * Creates an embed element state.
1510
- * @param opts - Options for creating the embed element.
1511
- */
1512
- createEmbedElement(opts: CreateEmbedElementOpts): EmbedElementState;
1513
- /**
1514
- * Creates a text element state.
1515
- * @param opts - Options for creating the text element.
1516
- */
1517
- createTextElement(opts: CreateTextElementOpts): TextElementState;
1518
- /**
1519
- * Creates a richtext range.
1520
- */
1521
- createRichtextRange(): RichtextRange;
1522
- }
1523
- /**
1524
- * @public
1525
- * Async methods for handling more complex operations.
1526
- */
1527
- export interface AsyncOperations {
1528
- /**
1529
- * Group specified elements.
1530
- *
1531
- * @param opts - Options for grouping elements.
1532
- *
1533
- * @returns a new group element containing all the given elements.
1534
- */
1535
- group(opts: AsyncOperationsGroupOpts): Promise<GroupElement>;
1536
- /**
1537
- * Ungroup a group element.
1538
- *
1539
- * @param opts - Options for ungrouping a group element.
1540
- *
1541
- * @returns new elements that are ungrouped from the given group.
1542
- */
1543
- ungroup(
1544
- opts: AsyncOperationsUngroupOpts,
1545
- ): Promise<readonly AbsoluteElement[]>;
1546
- }
1547
- /**
1548
- * @public
1549
- * Options for `group` operation.
1550
- */
1551
- export interface AsyncOperationsGroupOpts {
1552
- /**
1553
- * Elements to be grouped.
1554
- */
1555
- elements: readonly Exclude<GroupContentElement, UnsupportedElement>[];
1556
- }
1557
- /**
1558
- * @public
1559
- * Options for `ungroup` operation.
1560
- */
1561
- export interface AsyncOperationsUngroupOpts {
1562
- /**
1563
- * Group element to be ungroup.
1564
- */
1565
- element: GroupElement;
1566
- }
1567
- /**
1568
- * @public
1569
- * Helpers for use with supported pages.
1570
- *
1571
- * @remarks
1572
- * Not applicable to unsupported pages.
1573
- *
1574
- * @preventInline
1575
- */
1576
- export type PageHelpers = AsyncOperations & {
1577
- /**
1578
- * Build an element state that can be used to create an element with the `insert` methods of
1579
- * the page's element list
1580
- */
1581
- elementStateBuilder: DesignEditing.ElementStateBuilder;
1582
- };
1583
- /**
1584
- * @public
1585
- * Session received by the `openDesign` callback when opening the current page.
1586
- */
1587
- export type CurrentPageSession<
1588
- Page = DesignEditing.Page,
1589
- Helpers = DesignEditing.PageHelpers,
1590
- > = Readonly<{
1591
- /**
1592
- * The current page of the design.
1593
- */
1594
- page: Page;
1595
- /**
1596
- * These are various utilities that allow apps to do more complex operations on the page.
1597
- */
1598
- helpers: Helpers;
1599
- /**
1600
- * Saves any changes made during the session while keeping the session open.
1601
- *
1602
- * @remarks
1603
- * - Any changes in the session are only reflected in the design after this method is called.
1604
- * - Once this method is called, further changes in the session can still be made.
1605
- */
1606
- sync(): Promise<void>;
1607
- }>;
1608
- /**
1609
- * @deprecated The type has been superseded by `CurrentPageSession`.
1610
- * @public
1611
- * Session received by the `openDesign` callback when opening the current page.
1612
- */
1613
- export type CurrentPageResult = CurrentPageSession;
1614
-
1615
- /**
1616
- * A function called for each item in the list.
1617
- *
1618
- * @param item - The current item in the list.
1619
- */
1620
- export type ForEachCallback<M> = (item: M) => void;
1621
- /**
1622
- * A function that determines if an item should be included in the result.
1623
- *
1624
- * @param item - The item to test.
1625
- * @returns `true` if the item should be included, otherwise `false`.
1626
- */
1627
- export type FilterPredicate<M> = (item: M) => boolean;
1628
- /**
1629
- * A type predicate function that determines if an item is of a specific type.
1630
- *
1631
- * @param item - The item to test.
1632
- * @returns `true` if the item is of type `C`, otherwise `false`.
1633
- */
1634
- export type TypeFilterPredicate<M, C extends M> = (item: M) => item is C;
1635
- /**
1636
- * @public
1637
- * A list that cannot be changed.
1638
- *
1639
- * @preventInline
1640
- */
1641
- export interface ReadableList<M> {
1642
- /**
1643
- * Gets the number of items in the list.
1644
- *
1645
- * @returns The number of items.
1646
- */
1647
- count(): number;
1648
- /**
1649
- * Converts the list to an array.
1650
- *
1651
- * @returns An array containing all items. The items are the same as in the list.
1652
- */
1653
- toArray(): readonly M[];
1654
- /**
1655
- * Executes a function for each item in the list.
1656
- *
1657
- * @param callback - The function to run for each item.
1658
- */
1659
- forEach(callback: ForEachCallback<M>): void;
1660
- /**
1661
- * Creates a new array with items that match a specific type.
1662
- *
1663
- * @param filter - A function that checks if an item is of type `C`.
1664
- * @returns An array of items that are of type `C`.
1665
- */
1666
- filter<C extends M>(filter: TypeFilterPredicate<M, C>): readonly C[];
1667
- /**
1668
- * Creates a new array with items that pass a test.
1669
- *
1670
- * @param filter - A function that tests each item. Returns `true` to keep the item.
1671
- * @returns An array of items that passed the test.
1672
- */
1673
- filter(filter: FilterPredicate<M>): readonly M[];
1674
- }
1675
- /**
1676
- * @public
1677
- * A list of items that can be read.
1678
- *
1679
- * @preventInline
1680
- */
1681
- export interface ListState<T> extends Iterable<T | undefined> {
1682
- join(separator?: string): string;
1683
- slice(start?: number, end?: number): EditableListState<T>;
1684
- indexOf(searchElement: T, fromIndex?: number): number;
1685
- lastIndexOf(searchElement: T, fromIndex?: number): number;
1686
- every<S extends T>(
1687
- predicate: (value: T, index: number) => value is S,
1688
- ): this is ListState<S>;
1689
- every(predicate: (value: T, index: number) => unknown): boolean;
1690
- some(predicate: (value: T, index: number) => unknown): boolean;
1691
- forEach(callbackFn: (value: T, index: number) => void): void;
1692
- map<U>(callbackFn: (value: T, index: number) => U): EditableListState<U>;
1693
- filter<S extends T>(
1694
- predicate: (value: T, index: number) => value is S,
1695
- ): S[];
1696
- filter(predicate: (value: T, index: number) => unknown): T[];
1697
- reduce(
1698
- callbackFn: (
1699
- previousValue: T,
1700
- currentValue: T,
1701
- currentIndex: number,
1702
- ) => T,
1703
- initialValue?: T,
1704
- ): T;
1705
- reduce<U>(
1706
- callbackFn: (
1707
- previousValue: U,
1708
- currentValue: T,
1709
- currentIndex: number,
1710
- ) => U,
1711
- initialValue: U,
1712
- ): U;
1713
- reduceRight(
1714
- callbackFn: (
1715
- previousValue: T,
1716
- currentValue: T,
1717
- currentIndex: number,
1718
- ) => T,
1719
- initialValue?: T,
1720
- ): T;
1721
- reduceRight<U>(
1722
- callbackFn: (
1723
- previousValue: U,
1724
- currentValue: T,
1725
- currentIndex: number,
1726
- ) => U,
1727
- initialValue: U,
1728
- ): U;
1729
- find<S extends T>(
1730
- predicate: (value: T | undefined, index: number) => value is S,
1731
- ): S | undefined;
1732
- find(
1733
- predicate: (value: T | undefined, index: number) => unknown,
1734
- ): T | undefined;
1735
- flatMap<U>(
1736
- callback: (value: T, index: number, array: T[]) => U | readonly U[],
1737
- ): U[];
1738
- readonly length: number;
1739
- readonly [n: number]: T;
1740
- at(index: number): T | undefined;
1741
- }
1742
- /**
1743
- * @public
1744
- * A list of items that can be read and updated.
1745
- */
1746
- export type EditableListState<T> = ListState<T> & {
1747
- length: number;
1748
- pop(): T | undefined;
1749
- push(...items: T[]): number;
1750
- shift(): T | undefined;
1751
- splice(start: number, deleteCount?: number): EditableListState<T>;
1752
- splice(
1753
- start: number,
1754
- deleteCount: number,
1755
- ...items: T[]
1756
- ): EditableListState<T>;
1757
- unshift(...items: T[]): number;
1758
- [n: number]: T;
1759
- };
1760
- /**
1761
- * @public
1762
- * A list of items that can be read and updated.
1763
- *
1764
- * @preventInline
1765
- */
1766
- export interface List<S, M> extends ReadableList<M> {
1767
- /**
1768
- * Adds a copy of an item to the list and places it right before another item.
1769
- *
1770
- * @param ref - The existing item to place the new item before.
1771
- * If `ref` is `undefined`, the new item is added at the end of the list.
1772
- * If `ref` does not exist in the list, the operation fails.
1773
- *
1774
- * @param item - The item to add. A copy of this item will be inserted.
1775
- *
1776
- * @returns
1777
- * The added item, or `undefined` if the operation failed.
1778
- */
1779
- insertBefore(ref: M | undefined, item: S): M | undefined;
1780
- /**
1781
- * Adds a copy of an item to the list and places it right after another item.
1782
- *
1783
- * @param ref - The existing item to place the new item after.
1784
- * If `ref` is `undefined`, the new item is added at the end of the list.
1785
- * If `ref` does not exist in the list, the operation fails.
1786
- *
1787
- * @param item - The item to add. A copy of this item will be inserted.
1788
- *
1789
- * @returns
1790
- * The added item, or `undefined` if the operation failed.
1791
- */
1792
- insertAfter(ref: M | undefined, item: S): M | undefined;
1793
- /**
1794
- * Moves an existing item to a new position right before another item.
1795
- *
1796
- * @param ref - The existing item to move the item before.
1797
- * If `ref` is `undefined`, the item is moved to the end of the list.
1798
- * If `ref` does not exist in the list, the operation fails.
1799
- *
1800
- * @param item - The item to move.
1801
- * The operation fails if the item is not already in the list.
1802
- */
1803
- moveBefore(ref: M | undefined, item: M): void;
1804
- /**
1805
- * Moves an existing item to a new position right after another item.
1806
- *
1807
- * @param ref - The existing item to move the item after.
1808
- * If `ref` is `undefined`, the item is moved to the end of the list.
1809
- * If `ref` does not exist in the list, the operation fails.
1810
- *
1811
- * @param item - The item to move.
1812
- * The operation fails if the item is not already in the list.
1813
- */
1814
- moveAfter(ref: M | undefined, item: M): void;
1815
- /**
1816
- * Removes an item from the list.
1817
- *
1818
- * @param item - The item to remove from the list.
1819
- */
1820
- delete(item: M): void;
1821
- }
1822
- /**
1823
- * @public
1824
- * Represents something that's not supported by the Apps SDK.
1825
- */
1826
- export interface Unsupported {
1827
- readonly type: "unsupported";
1828
- }
1829
- /**
1830
- * @public
1831
- * A state that creates a set of dimensions.
1832
- */
1833
- export interface DimensionsState {
1834
- /**
1835
- * A width, in pixels.
1836
- */
1837
- readonly width: number;
1838
- /**
1839
- * A height, in pixels.
1840
- */
1841
- readonly height: number;
1842
- }
1843
- /**
1844
- * @public
1845
- * A set of dimensions.
1846
- */
1847
- export type Dimensions = DimensionsState;
1848
- /**
1849
- * @public
1850
- * A state that creates an image fill.
1851
- */
1852
- export interface ImageFillState {
1853
- /**
1854
- * The type of media.
1855
- */
1856
- readonly type: "image";
1857
- /**
1858
- * A unique identifier that points to an image asset in Canva's backend.
1859
- */
1860
- readonly imageRef: ImageRef;
1861
- /**
1862
- * If `true`, the image is flipped horizontally.
1863
- */
1864
- flipX: boolean;
1865
- /**
1866
- * If `true`, the image is flipped vertically.
1867
- */
1868
- flipY: boolean;
1869
- }
1870
- /**
1871
- * @public
1872
- * An image that fills the interior of a media.
1873
- */
1874
- export type ImageFill = ImageFillState;
1875
- /**
1876
- * @public
1877
- * A state that creates a video fill.
1878
- */
1879
- export interface VideoFillState {
1880
- /**
1881
- * The type of media.
1882
- */
1883
- readonly type: "video";
1884
- /**
1885
- * A unique identifier that points to a video asset in Canva's backend.
1886
- */
1887
- readonly videoRef: VideoRef;
1888
- /**
1889
- * If `true`, the video is flipped horizontally.
1890
- */
1891
- flipX: boolean;
1892
- /**
1893
- * If `true`, the video is flipped vertically.
1894
- */
1895
- flipY: boolean;
1896
- }
1897
- /**
1898
- * @public
1899
- * A video that fills the interior of a media.
1900
- */
1901
- export type VideoFill = VideoFillState;
1902
- /**
1903
- * @public
1904
- * A state that creates a media fill.
1905
- */
1906
- export type MediaFillState = ImageFillState | VideoFillState;
1907
- /**
1908
- * @public
1909
- * A media item that fills an interior.
1910
- */
1911
- export type MediaFill = ImageFill | VideoFill;
1912
- /**
1913
- * @public
1914
- * A state that creates a solid color fill.
1915
- */
1916
- export interface SolidFillState {
1917
- /**
1918
- * The type of color.
1919
- */
1920
- readonly type: "solid";
1921
- /**
1922
- * The color of the fill.
1923
- * This must be a valid, six-digit hex code, prefixed with a `#` symbol.
1924
- *
1925
- * @remarks
1926
- * - Must be six characters long.
1927
- * - Must start with a `#`.
1928
- * - Must use lowercase letters.
1929
- * @example "#ff0099"
1930
- */
1931
- color: string;
1932
- }
1933
- /**
1934
- * @public
1935
- * A solid color that fills an interior.
1936
- */
1937
- export type SolidFill = SolidFillState;
1938
- /**
1939
- * @public
1940
- * A state that creates a color fill.
1941
- */
1942
- export type ColorFillState = SolidFillState | Unsupported;
1943
- /**
1944
- * @public
1945
- * A color that fills an interior.
1946
- */
1947
- export type ColorFill = SolidFill | Unsupported;
1948
- /**
1949
- * @public
1950
- * A state that creates a fill with color or media.
1951
- *
1952
- * @remarks
1953
- * If both `media` and `color` are defined, `media` takes precedence.
1954
- */
1955
- export interface FillState {
1956
- /**
1957
- * The media fill for the path, if any.
1958
- */
1959
- mediaContainer: MediaFillState | undefined;
1960
- /**
1961
- * The color fill for the path, if any.
1962
- */
1963
- colorContainer: ColorFillState | undefined;
1964
- }
1965
- /**
1966
- * @public
1967
- * A state that creates a shape path fill with color or media.
1968
- *
1969
- * @remarks
1970
- * If both `media` and `color` are defined, `media` takes precedence.
1971
- */
1972
- export interface PathFillState {
1973
- /**
1974
- * Defines whether the media fill is editable.
1975
- */
1976
- isMediaEditable: boolean;
1977
- /**
1978
- * The media fill for the path, if any.
1979
- */
1980
- mediaContainer: MediaFillState | undefined;
1981
- /**
1982
- * The color fill for the path, if any.
1983
- */
1984
- colorContainer: ColorFillState | undefined;
1985
- }
1986
- /**
1987
- * @public
1988
- * Describes how a fill of a shape path is filled with color or media.
1989
- *
1990
- * @remarks
1991
- * If both `media` and `color` are defined, `media` takes precedence.
1992
- */
1993
- export type PathFill =
1994
- | PathFillWithEditableMedia
1995
- | PathFillWithNonEditableMedia;
1996
- export interface PathFillWithEditableMedia {
1997
- readonly isMediaEditable: true;
1998
- /**
1999
- * A media fill, if any.
2000
- */
2001
- readonly mediaContainer: {
2002
- set(state: MediaFillState | undefined): void;
2003
- ref: MediaFill | undefined;
2004
- };
2005
- /**
2006
- * A color fill, if any.
2007
- */
2008
- readonly colorContainer: {
2009
- set(state: SolidFillState | undefined): void;
2010
- ref: ColorFill | undefined;
2011
- };
2012
- }
2013
- export interface PathFillWithNonEditableMedia {
2014
- readonly isMediaEditable: false;
2015
- /**
2016
- * A media fill, if any.
2017
- * MediaFill is not editable
2018
- */
2019
- readonly mediaContainer: {
2020
- ref: MediaFill | undefined;
2021
- };
2022
- /**
2023
- * A color fill, if any.
2024
- */
2025
- readonly colorContainer: {
2026
- set(state: SolidFillState | undefined): void;
2027
- ref: ColorFill | undefined;
2028
- };
2029
- }
2030
- /**
2031
- * @public
2032
- * Describes how a fill is filled with color or media.
2033
- *
2034
- * @remarks
2035
- * If both `media` and `color` are defined, `media` takes precedence.
2036
- *
2037
- * @preventInline
2038
- */
2039
- export interface Fill {
2040
- /**
2041
- * A media fill, if any.
2042
- */
2043
- readonly mediaContainer: {
2044
- set(state: MediaFillState | undefined): void;
2045
- ref: MediaFill | undefined;
2046
- };
2047
- /**
2048
- * A color fill, if any.
2049
- */
2050
- readonly colorContainer: {
2051
- set(state: SolidFillState | undefined): void;
2052
- ref: ColorFill | undefined;
2053
- };
2054
- }
2055
- /**
2056
- * @public
2057
- * A state that creates the scale and cropping of a shape.
2058
- *
2059
- * @remarks
2060
- * This is similar to the `viewBox` attribute of an `SVGElement`.
2061
- */
2062
- export interface AlignedBoxState {
2063
- /**
2064
- * The distance of the shape from the top edge of the element, in pixels.
2065
- */
2066
- readonly top: number;
2067
- /**
2068
- * The distance of the shape from the left edge of the element, in pixels.
2069
- */
2070
- readonly left: number;
2071
- /**
2072
- * The width of the view box, in pixels.
2073
- */
2074
- readonly width: number;
2075
- /**
2076
- * The height of the view box, in pixels.
2077
- */
2078
- readonly height: number;
2079
- }
2080
- /**
2081
- * @public
2082
- * The scale and cropping of a shape.
2083
- *
2084
- * @remarks
2085
- * This is similar to the `viewBox` attribute of an `SVGElement`.
2086
- */
2087
- export type AlignedBox = AlignedBoxState;
2088
- /**
2089
- * @public
2090
- * A state that creates a path that defines the structure of a shape element.
2091
- */
2092
- export interface PathState {
2093
- /**
2094
- * The shape of the path.
2095
- *
2096
- * @remarks
2097
- * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
2098
- *
2099
- * - Must start with an `M` command.
2100
- * - Only one `M` command is allowed.
2101
- * - `Q` and `T` commands are not permitted.
2102
- * - The path must be closed using a `Z` command or matching start and end coordinates.
2103
- */
2104
- readonly d: string;
2105
- /**
2106
- * The appearance of the path's interior.
2107
- */
2108
- readonly fill: PathFillState;
2109
- /**
2110
- * The stroke (outline) of the path, if any.
2111
- */
2112
- readonly stroke: StrokeState | undefined;
2113
- }
2114
- /**
2115
- * @public
2116
- * A path that defines the structure of a shape element.
2117
- *
2118
- * @preventInline
2119
- */
2120
- export type Path = {
2121
- /**
2122
- * The shape of the path.
2123
- *
2124
- * @remarks
2125
- * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
2126
- *
2127
- * - Must start with an `M` command.
2128
- * - Only one `M` command is allowed.
2129
- * - `Q` and `T` commands are not permitted.
2130
- * - The path must be closed using a `Z` command or matching start and end coordinates.
2131
- */
2132
- readonly d: string;
2133
- /**
2134
- * The appearance of the path's interior.
2135
- */
2136
- readonly fill: PathFill;
2137
- /**
2138
- * The stroke (outline) of the path, if any.
2139
- */
2140
- readonly stroke: Stroke | undefined;
2141
- };
2142
- /**
2143
- * @public
2144
- * A state that creates an outline, such as the border of an element.
2145
- */
2146
- export interface StrokeState {
2147
- /**
2148
- * The weight (thickness) of the stroke.
2149
- *
2150
- * @remarks
2151
- * - Minimum: 0
2152
- * - Maximum: 100
2153
- */
2154
- weight: number;
2155
- /**
2156
- * The color of the stroke.
2157
- */
2158
- colorContainer: ColorFillState;
2159
- }
2160
- /**
2161
- * @public
2162
- * Represents an outline, such as the border of an element.
2163
- *
2164
- * @preventInline
2165
- */
2166
- export type Stroke = {
2167
- /**
2168
- * The weight (thickness) of the stroke.
2169
- *
2170
- * @remarks
2171
- * - Minimum: 0
2172
- * - Maximum: 100
2173
- */
2174
- weight: number;
2175
- /**
2176
- * The color of the stroke.
2177
- */
2178
- readonly colorContainer: {
2179
- ref: ColorFill;
2180
- set(state: SolidFillState): void;
2181
- };
2182
- };
2183
- /**
2184
- * @public
2185
- * The basic properties of the state of an element.
2186
- *
2187
- * @remarks
2188
- * These properties are shared by all elements in a design.
2189
- */
2190
- export interface ElementState extends DimensionsState {
2191
- /**
2192
- * If `true`, the element is locked and cannot be modified.
2193
- */
2194
- readonly locked: boolean;
2195
- /**
2196
- * The distance from the top edge of the container, in pixels.
2197
- *
2198
- * @remarks
2199
- * - The pixels are relative to their container.
2200
- * - Minimum: -32768
2201
- * - Maximum: 32767
2202
- */
2203
- readonly top: number;
2204
- /**
2205
- * The distance from the left edge of the container, in pixels.
2206
- *
2207
- * @remarks
2208
- * - The pixels are relative to their container.
2209
- * - Minimum: -32768
2210
- * - Maximum: 32767
2211
- */
2212
- readonly left: number;
2213
- /**
2214
- * A rotation, in degrees.
2215
- *
2216
- * @remarks
2217
- * - Minimum: -180
2218
- * - Maximum: 180
2219
- */
2220
- readonly rotation: number;
2221
- /**
2222
- * Transparency as a percentage.
2223
- *
2224
- * @remarks
2225
- * - Minimum: 0
2226
- * - Maximum: 1
2227
- */
2228
- readonly transparency: number;
2229
- }
2230
- /**
2231
- * @public
2232
- * The basic properties of an element.
2233
- *
2234
- * @remarks
2235
- * These properties are shared by all elements in a design.
2236
- */
2237
- export type Element = DimensionsState & {
2238
- /**
2239
- * If `true`, the element is locked and cannot be modified.
2240
- */
2241
- readonly locked: boolean;
2242
- /**
2243
- * The distance from the top edge of the container, in pixels.
2244
- *
2245
- * @remarks
2246
- * - The pixels are relative to their container.
2247
- * - Minimum: -32768
2248
- * - Maximum: 32767
2249
- */
2250
- top: number;
2251
- /**
2252
- * The distance from the left edge of the container, in pixels.
2253
- *
2254
- * @remarks
2255
- * - The pixels are relative to their container.
2256
- * - Minimum: -32768
2257
- * - Maximum: 32767
2258
- */
2259
- left: number;
2260
- /**
2261
- * A rotation, in degrees.
2262
- *
2263
- * @remarks
2264
- * - Minimum: -180
2265
- * - Maximum: 180
2266
- */
2267
- rotation: number;
2268
- /**
2269
- * Transparency as a percentage.
2270
- *
2271
- * @remarks
2272
- * - Minimum: 0
2273
- * - Maximum: 1
2274
- */
2275
- transparency: number;
2276
- };
2277
- /**
2278
- * @public
2279
- * A state that creates a rectangular element.
2280
- */
2281
- export interface RectState {
2282
- /**
2283
- * The type of content.
2284
- */
2285
- readonly type: "rect";
2286
- /**
2287
- * The appearance of the rectangle's interior.
2288
- */
2289
- readonly fill: FillState;
2290
- /**
2291
- * The outline of the rectangle.
2292
- */
2293
- readonly stroke: StrokeState;
2294
- }
2295
- /**
2296
- * @public
2297
- * Represents a rectangular element.
2298
- */
2299
- export type Rect = {
2300
- /**
2301
- * The element type
2302
- */
2303
- readonly type: "rect";
2304
- readonly fill: Fill;
2305
- /**
2306
- * The outline of the rectangle.
2307
- */
2308
- readonly stroke: Stroke;
2309
- };
2310
- /**
2311
- * @public
2312
- * A state that creates a vector shape element.
2313
- */
2314
- export interface ShapeState {
2315
- /**
2316
- * The type of content.
2317
- */
2318
- readonly type: "shape";
2319
- /**
2320
- * The scale and cropping of the shape.
2321
- */
2322
- readonly viewBox: AlignedBoxState;
2323
- /**
2324
- * The paths that define the structure of the shape.
2325
- *
2326
- * @remarks
2327
- * - Must have between 1 and 30 paths.
2328
- * - Total size of all paths must not exceed 2kb.
2329
- * - Maximum of 6 unique fill colors across all paths.
2330
- */
2331
- readonly paths: ListState<PathState>;
2332
- }
2333
- /**
2334
- * @public
2335
- * Represents a vector shape element.
2336
- */
2337
- export type Shape = {
2338
- /**
2339
- * The type of content.
2340
- */
2341
- readonly type: "shape";
2342
- /**
2343
- * The scale and cropping of the shape.
2344
- */
2345
- readonly viewBox: AlignedBox;
2346
- /**
2347
- * The paths that define the structure of the shape.
2348
- */
2349
- readonly paths: ReadableList<Path>;
2350
- };
2351
- /**
2352
- * @public
2353
- * A state that creates group content.
2354
- */
2355
- export interface GroupState {
2356
- /**
2357
- * The type of content.
2358
- */
2359
- readonly type: "group";
2360
- /**
2361
- * The elements that exist within the group.
2362
- */
2363
- readonly contents: ListState<GroupContentElementState>;
2364
- }
2365
- /**
2366
- * @public
2367
- * Represents group content.
2368
- */
2369
- export type Group = {
2370
- /**
2371
- * The type of content.
2372
- */
2373
- readonly type: "group";
2374
- /**
2375
- * The elements that exist within the group.
2376
- */
2377
- readonly contents: ReadableList<GroupContentElement>;
2378
- };
2379
- /**
2380
- * @public
2381
- * A state that creates rich media content.
2382
- */
2383
- export interface EmbedState {
2384
- /**
2385
- * The type of content.
2386
- */
2387
- readonly type: "embed";
2388
- /**
2389
- * The URL of the rich media.
2390
- *
2391
- * @remarks
2392
- * This URL must be supported by the Iframely API.
2393
- */
2394
- readonly url: string;
2395
- }
2396
- /**
2397
- * @public
2398
- * Represents rich media content.
2399
- */
2400
- export type Embed = EmbedState;
2401
- /**
2402
- * @public
2403
- * A state that creates text content.
2404
- */
2405
- export interface TextState {
2406
- /**
2407
- * The type of content.
2408
- */
2409
- readonly type: "text";
2410
- /**
2411
- * The text content.
2412
- */
2413
- readonly text: {
2414
- regions: ListState<TextRegion>;
2415
- };
2416
- }
2417
- /**
2418
- * @public
2419
- * Represents text content.
2420
- */
2421
- export type Text = {
2422
- readonly type: "text";
2423
- readonly text: RichtextRange;
2424
- };
2425
- /**
2426
- * @public
2427
- * A state that creates a rectangle element.
2428
- *
2429
- * @remarks
2430
- * The rectangle can be filled with image content, video content, or a solid color.
2431
- */
2432
- export type RectElementState = RectState & ElementState;
2433
- /**
2434
- * @public
2435
- * An element that renders a rectangle.
2436
- *
2437
- * @remarks
2438
- * The rectangle can be filled with image content, video content, or a solid color.
2439
- */
2440
- export type RectElement = Rect & Element;
2441
- /**
2442
- * @public
2443
- * A state that creates a vector shape element.
2444
- */
2445
- export type ShapeElementState = ShapeState & ElementState;
2446
- /**
2447
- * @public
2448
- * An element that renders a vector shape.
2449
- */
2450
- export type ShapeElement = Shape & Element;
2451
- /**
2452
- * @public
2453
- * A state that creates a group element.
2454
- */
2455
- export type GroupElementState = GroupState & ElementState;
2456
- /**
2457
- * @public
2458
- * An element that renders a group of other elements.
2459
- */
2460
- export type GroupElement = Group & Element;
2461
- /**
2462
- * @public
2463
- * A state that creates an embed element, such as a YouTube video.
2464
- */
2465
- export type EmbedElementState = EmbedState & ElementState;
2466
- /**
2467
- * @public
2468
- * An element that embeds rich media, such as a YouTube video.
2469
- */
2470
- export type EmbedElement = Embed & Element;
2471
- /**
2472
- * @public
2473
- * A state that creates a text element.
2474
- */
2475
- export type TextElementState = TextState & ElementState;
2476
- /**
2477
- * @public
2478
- * An element that renders text content.
2479
- */
2480
- export type TextElement = Text & Element;
2481
- /**
2482
- * @public
2483
- * An element state that is not supported by the Apps SDK.
2484
- */
2485
- export type UnsupportedElementState = Unsupported & ElementState;
2486
- /**
2487
- * @public
2488
- * An element that is not supported by the Apps SDK.
2489
- */
2490
- export type UnsupportedElement = Unsupported & Readonly<Element>;
2491
- /**
2492
- * @public
2493
- * An element state that can exist in a group content state.
2494
- */
2495
- export type GroupContentElementState =
2496
- | RectElementState
2497
- | ShapeElementState
2498
- | EmbedElementState
2499
- | TextElementState
2500
- | UnsupportedElementState;
2501
- /**
2502
- * @public
2503
- * An element that can exist in a group element.
2504
- *
2505
- * @preventInline
2506
- */
2507
- export type GroupContentElement =
2508
- | RectElement
2509
- | ShapeElement
2510
- | EmbedElement
2511
- | TextElement
2512
- | UnsupportedElement;
2513
- /**
2514
- * @public
2515
- * An element state that can exist on an absolute page state.
2516
- *
2517
- * @preventInline
2518
- */
2519
- export type AbsoluteElementState =
2520
- | RectElementState
2521
- | ShapeElementState
2522
- | GroupElementState
2523
- | EmbedElementState
2524
- | TextElementState
2525
- | UnsupportedElementState;
2526
- /**
2527
- * @public
2528
- * An element that can exist on an absolute page.
2529
- *
2530
- * @preventInline
2531
- */
2532
- export type AbsoluteElement =
2533
- | RectElement
2534
- | ShapeElement
2535
- | GroupElement
2536
- | EmbedElement
2537
- | TextElement
2538
- | UnsupportedElement;
2539
- /**
2540
- * @public
2541
- * An element state that can be inserted into a page.
2542
- */
2543
- export type InsertableElementState =
2544
- | RectElementState
2545
- | ShapeElementState
2546
- | EmbedElementState
2547
- | TextElementState;
2548
- /**
2549
- * @public
2550
- * A list of elements.
2551
- *
2552
- * @preventInline
2553
- */
2554
- export interface ElementList
2555
- extends List<AbsoluteElementState, AbsoluteElement> {
2556
- insertBefore(
2557
- ref: AbsoluteElement | undefined,
2558
- state: EmbedElementState,
2559
- ): EmbedElement;
2560
- insertBefore(
2561
- ref: AbsoluteElement | undefined,
2562
- state: TextElementState,
2563
- ): TextElement;
2564
- insertBefore(
2565
- ref: AbsoluteElement | undefined,
2566
- state: ShapeElementState,
2567
- ): ShapeElement;
2568
- insertBefore(
2569
- ref: AbsoluteElement | undefined,
2570
- state: RectElementState,
2571
- ): RectElement;
2572
- insertBefore(
2573
- ref: AbsoluteElement | undefined,
2574
- state: InsertableElementState,
2575
- ): AbsoluteElement;
2576
- insertAfter(
2577
- ref: AbsoluteElement | undefined,
2578
- state: EmbedElementState,
2579
- ): EmbedElement;
2580
- insertAfter(
2581
- ref: AbsoluteElement | undefined,
2582
- state: TextElementState,
2583
- ): TextElement;
2584
- insertAfter(
2585
- ref: AbsoluteElement | undefined,
2586
- state: ShapeElementState,
2587
- ): ShapeElement;
2588
- insertAfter(
2589
- ref: AbsoluteElement | undefined,
2590
- state: RectElementState,
2591
- ): RectElement;
2592
- insertAfter(
2593
- ref: AbsoluteElement | undefined,
2594
- state: InsertableElementState,
2595
- ): AbsoluteElement;
2596
- }
2597
-
2598
- /**
2599
- * @public
2600
- * A page with either fixed or unbounded dimensions.
2601
- *
2602
- * @preventInline
2603
- */
2604
- export type AbsolutePage = {
2605
- /**
2606
- * The type of page.
2607
- */
2608
- readonly type: "absolute";
2609
- /**
2610
- * If `true`, the page is locked and cannot be modified.
2611
- */
2612
- readonly locked: boolean;
2613
- /**
2614
- * The dimensions of the page. `dimensions` is undefined for whiteboard pages.
2615
- */
2616
- readonly dimensions: Dimensions | undefined;
2617
- /**
2618
- * The background of the page. `background` is undefined for whiteboard pages.
2619
- */
2620
- readonly background: Fill | undefined;
2621
- /**
2622
- * The elements on the page.
2623
- *
2624
- * @remarks
2625
- * Elements are rendered in the order they appear in the list.
2626
- * Later elements appear on top of earlier ones.
2627
- */
2628
- readonly elements: ElementList;
2629
- };
2630
-
2631
- /**
2632
- * @public
2633
- * A page in a design.
2634
- *
2635
- * @remarks
2636
- * - Currently, only absolute pages are supported.
2637
- * - Other page types are represented as `Unsupported`.
2638
- * - Additional page types may be supported in future releases.
2639
- */
2640
- export type Page = AbsolutePage | Unsupported;
2641
-
2642
- {
2643
- }
2644
- }
2645
-
2646
- /**
2647
- * @public
2648
- * An element that's natively supported by the Canva editor.
2649
- */
2650
- export declare type DesignElement =
2651
- | ImageElement
2652
- | VideoElement
2653
- | EmbedElement
2654
- | TextElement
2655
- | ShapeElement
2656
- | GroupElement
2657
- | RichtextElement
2658
- | TableElement;
2659
-
2660
- /**
2661
- * @public
2662
- * Information about the design.
2663
- */
2664
- export declare type DesignMetadata = {
2665
- /**
2666
- * The title of the user's design.
2667
- * @remarks
2668
- * This is optional and will be `undefined` if the user hasn't set a title.
2669
- */
2670
- title?: string;
2671
- /**
2672
- * The default dimensions that a new page will have when it is added to a design.
2673
- * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
2674
- * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
2675
- * design that is applied whenever a new page is created.
2676
- * @remarks
2677
- * This is optional and will be `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
2678
- */
2679
- defaultPageDimensions?: PageDimensions;
2680
- /**
2681
- * The information associated with each page of the design.
2682
- * @remarks
2683
- * The order of pages is not guaranteed.
2684
- */
2685
- pageMetadata: Iterable<PageMetadata>;
2686
- /**
2687
- * The duration of the whole design in seconds.
2688
- * @remarks
2689
- * This is the precise value, which differs from what is displayed in the UI as duration in Canva UI is formatted differently.
2690
- */
2691
- durationInSeconds: number;
2692
- };
2693
-
2694
- /**
2695
- * @public
2696
- * A callback for reading and updating part of a design.
2697
- * @param session - Session received by the `openDesign` callback.
2698
- */
2699
- export declare type DesignOpenCallback = (
2700
- session: DesignEditing.CurrentPageSession,
2701
- ) => Promise<void>;
2702
-
2703
- /**
2704
- * @public
2705
- * Options for configuring which part of a design to read.
2706
- */
2707
- export declare type DesignOpenOptions = DesignContextOptions;
2708
-
2709
- /**
2710
- * @public
2711
- * Provides methods for managing the lifecycle of overlays, such as selected image overlays.
2712
- */
2713
- export declare type DesignOverlay = {
2714
- /**
2715
- * Registers a callback that runs when the `canOpen` state of an overlay target changes.
2716
- * @param opts - Options for configuring the callback.
2717
- *
2718
- * @example Register overlay handler
2719
- * ```typescript
2720
- * import { overlay } from "@canva/design";
2721
- *
2722
- * overlay.registerOnCanOpen({
2723
- * target: 'image_selection',
2724
- * onCanOpen: async (event) => {
2725
- * if (event.canOpen) {
2726
- * // Can open overlay for selected image
2727
- * }
2728
- * }
2729
- * });
2730
- * ```
2731
- *
2732
- * @example Open image editing overlay
2733
- * ```typescript
2734
- * import { overlay } from "@canva/design";
2735
- *
2736
- * overlay.registerOnCanOpen({
2737
- * target: 'image_selection',
2738
- * onCanOpen: async (event) => {
2739
- * if (event.canOpen) {
2740
- * const processId = await event.open({
2741
- * launchParameters: {
2742
- * mode: 'edit'
2743
- * }
2744
- * });
2745
- * // Overlay process started, with `processId`
2746
- * }
2747
- * }
2748
- * });
2749
- * ```
2750
- *
2751
- * @example Open overlay with filters
2752
- * ```typescript
2753
- * import { overlay } from "@canva/design";
2754
- *
2755
- * overlay.registerOnCanOpen({
2756
- * target: 'image_selection',
2757
- * onCanOpen: async (event) => {
2758
- * if (event.canOpen) {
2759
- * await event.open({
2760
- * launchParameters: {
2761
- * mode: 'edit',
2762
- * filters: ['brightness', 'contrast', 'saturation']
2763
- * }
2764
- * });
2765
- * }
2766
- * }
2767
- * });
2768
- * ```
2769
- *
2770
- * @example Handle overlay unavailability
2771
- * ```typescript
2772
- * import { overlay } from "@canva/design";
2773
- *
2774
- * overlay.registerOnCanOpen({
2775
- * target: 'image_selection',
2776
- * onCanOpen: async (event) => {
2777
- * if (!event.canOpen) {
2778
- * // Cannot open overlay, handle specific reasons
2779
- * switch (event.reason) {
2780
- * case 'no_selection':
2781
- * // No image is selected
2782
- * break;
2783
- * case 'invalid_selection':
2784
- * // Selected content cannot be edited
2785
- * break;
2786
- * }
2787
- * }
2788
- * }
2789
- * });
2790
- * ```
2791
- */
2792
- registerOnCanOpen<Target extends OverlayTarget>(opts: {
2793
- /**
2794
- * The target to check the `canOpen` state of.
2795
- */
2796
- target: Target;
2797
- /**
2798
- * A callback that runs when the `canOpen` state of the specified target changes.
2799
- *
2800
- * @param event - Information about whether or not an overlay can be opened for the specified target.
2801
- *
2802
- * @remarks
2803
- * This callback fires immediately.
2804
- */
2805
- onCanOpen(event: OverlayOpenableEvent<Target>): void;
2806
- }): () => void;
2807
- };
2808
-
2809
- /**
2810
- * @public
2811
- * Provides methods for interacting with selected content.
2812
- */
2813
- export declare type DesignSelection = {
2814
- /**
2815
- * Registers a callback that runs when the specified type of content is selected.
2816
- *
2817
- * @param opts - Options for configuring the content selection callback.
2818
- *
2819
- * @remarks
2820
- * This callback fires immediately if content is already selected when the callback is registered.
2821
- *
2822
- * @example Handling plaintext selection
2823
- * ```typescript
2824
- * import { selection } from "@canva/design";
2825
- *
2826
- * selection.registerOnChange({
2827
- * scope: 'plaintext',
2828
- * onChange: async (event) => {
2829
- * if (event.count > 0) {
2830
- * const draft = await event.read();
2831
- * // Do something with the selected text, e.g. `draft.contents[0].text`
2832
- * }
2833
- * }
2834
- * });
2835
- * ```
2836
- *
2837
- * @example Handling image selection
2838
- * ```typescript
2839
- * import { selection } from "@canva/design";
2840
- *
2841
- * selection.registerOnChange({
2842
- * scope: 'image',
2843
- * onChange: async (event) => {
2844
- * if (event.count > 0) {
2845
- * const draft = await event.read();
2846
- * // Do something with the selected image ref, e.g. `draft.contents[0].ref`
2847
- * }
2848
- * }
2849
- * });
2850
- * ```
2851
- *
2852
- * @example Handling video selection
2853
- * ```typescript
2854
- * import { selection } from "@canva/design";
2855
- *
2856
- * selection.registerOnChange({
2857
- * scope: 'video',
2858
- * onChange: async (event) => {
2859
- * if (event.count > 0) {
2860
- * const draft = await event.read();
2861
- * // Do something with the selected video ref, e.g. `draft.contents[0].ref`
2862
- * }
2863
- * }
2864
- * });
2865
- * ```
2866
- *
2867
- * @example Handling richtext selection
2868
- * ```typescript
2869
- * import { selection } from "@canva/design";
2870
- *
2871
- * selection.registerOnChange({
2872
- * scope: 'richtext',
2873
- * onChange: async (event) => {
2874
- * if (event.count > 0) {
2875
- * const draft = await event.read();
2876
- * const range = draft.contents[0];
2877
- * // Do something with the selected richtext, e.g. `range.readPlaintext()`
2878
- * }
2879
- * }
2880
- * });
2881
- * ```
2882
- */
2883
- registerOnChange<Scope extends SelectionScope>(opts: {
2884
- /**
2885
- * The type of content that triggers a selection change event.
2886
- */
2887
- scope: Scope;
2888
- /**
2889
- * The callback to run when the selected content changes.
2890
- * @param event - Information about the selection change event.
2891
- */
2892
- onChange(event: SelectionEvent<Scope>): void;
2893
- }): () => void;
2894
- };
2895
-
2896
- /**
2897
- * @public
2898
- * JWT that contains the Design ID and App ID.
2899
- */
2900
- export declare type DesignToken = {
2901
- token: string;
2902
- };
2903
-
2904
- /**
2905
- * @public
2906
- * A set of dimensions.
2907
- */
2908
- export declare type Dimensions = {
2909
- /**
2910
- * A width, in pixels.
2911
- */
2912
- width: number;
2913
- /**
2914
- * A height, in pixels.
2915
- */
2916
- height: number;
2917
- };
2918
-
2919
- /**
2920
- * @public
2921
- * An event that occurs when a user starts dragging an HTML element.
2922
- */
2923
- export declare type DragStartEvent<E extends Element> = Pick<
2924
- DragEvent,
2925
- "dataTransfer" | "currentTarget" | "preventDefault" | "clientX" | "clientY"
2926
- > & {
2927
- currentTarget: E;
2928
- };
2929
-
2930
- /**
2931
- * @public
2932
- * Reads and edits content of the specified type from the user's design.
2933
- * @param options - Options for configuring how a design is read.
2934
- * @param callback - A callback for operating on the read content.
2935
- *
2936
- * @example Read richtext content
2937
- * ```typescript
2938
- * import { editContent } from "@canva/design";
2939
- *
2940
- * await editContent(
2941
- * { contentType: 'richtext', target: 'current_page' },
2942
- * async (session) => {
2943
- * // Do something with the richtext content, e.g. `session.contents`
2944
- * }
2945
- * );
2946
- * ```
2947
- */
2948
- export declare const editContent: (
2949
- options: EditContentOptions,
2950
- callback: EditContentCallback,
2951
- ) => Promise<void>;
2952
-
2953
- /**
2954
- * @public
2955
- * A callback for reading and updating the requested design content.
2956
- * @param session - The result of reading the content in the design.
2957
- */
2958
- export declare type EditContentCallback = (
2959
- session: RichtextContentSession,
2960
- ) => Promise<void> | void;
2961
-
2962
- /**
2963
- * @public
2964
- * Options for configuring how the design content is read.
2965
- */
2966
- export declare type EditContentOptions = {
2967
- /**
2968
- * The type of content to edit from the user's design
2969
- */
2970
- contentType: ContentType;
2971
- } & ContextOptions;
2972
-
2973
- /**
2974
- * @public
2975
- * Elements targeting a cursor are a subset of the base Element
2976
- **/
2977
- export declare type ElementAtCursor =
2978
- | ImageElement
2979
- | VideoElement
2980
- | EmbedElement
2981
- | TextElement
2982
- | RichtextElement
2983
- | TableElement;
2984
-
2985
- /**
2986
- * @public
2987
- * An element that's natively supported by the Canva editor and has positional properties.
2988
- */
2989
- export declare type ElementAtPoint =
2990
- | ImageElementAtPoint
2991
- | VideoElementAtPoint
2992
- | EmbedElementAtPoint
2993
- | TextElementAtPoint
2994
- | ShapeElementAtPoint
2995
- | GroupElementAtPoint
2996
- | RichtextElementAtPoint;
2997
-
2998
- /**
2999
- * @public
3000
- * Embed element to be added to the design at the end of a drag event.
3001
- */
3002
- export declare type EmbedDragConfig = {
3003
- /**
3004
- * The type of element.
3005
- */
3006
- type: "embed";
3007
- /**
3008
- * The dimensions of the preview image.
3009
- */
3010
- previewSize: Dimensions;
3011
- /**
3012
- * The URL of an image to display under the user's cursor during the drag and drop event.
3013
- */
3014
- previewUrl: string;
3015
- /**
3016
- * The URL of media that can be embedded, such as the URL of a YouTube video.
3017
- *
3018
- * @remarks
3019
- * This URL must be supported by the Iframely API.
3020
- */
3021
- embedUrl: string;
3022
- };
3023
-
3024
- /**
3025
- * @public
3026
- * An element that renders rich media, such as a YouTube video.
3027
- */
3028
- export declare type EmbedElement = {
3029
- /**
3030
- * The type of element.
3031
- */
3032
- type: "embed";
3033
- /**
3034
- * The URL of the rich media.
3035
- *
3036
- * @remarks
3037
- * This URL must be supported by the Iframely API.
3038
- */
3039
- url: string;
3040
- };
3041
-
3042
- /**
3043
- * @public
3044
- * An element that renders rich media, such as a YouTube video, and has positional properties.
3045
- */
3046
- export declare type EmbedElementAtPoint = EmbedElement &
3047
- Point &
3048
- (WidthAndHeight | Width | Height);
3049
-
3050
- /**
3051
- * @public
3052
- * The result when a user abandons the export flow, such as by closing the export menu.
3053
- */
3054
- export declare type ExportAborted = {
3055
- /**
3056
- * The status of the export flow.
3057
- */
3058
- status: "aborted";
3059
- };
3060
-
3061
- /**
3062
- * @public
3063
- * The exported file.
3064
- */
3065
- export declare type ExportBlob = {
3066
- /**
3067
- * The URL of the exported design.
3068
- *
3069
- * @remarks
3070
- * If a user's design contains multiple pages but is exported in a format that doesn't support multiple pages,
3071
- * this URL will point to a ZIP file that contains each page as a separate file.
3072
- *
3073
- * For example:
3074
- *
3075
- * - If a single-page design is exported as a JPG, the URL will point to a JPG file.
3076
- * - 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.
3077
- * - If a multi-page design is exported as a PDF file, the URL will point to a PDF file.
3078
- *
3079
- * The following file types support multiple pages:
3080
- *
3081
- * - `"GIF"`
3082
- * - `"PDF_STANDARD"`
3083
- * - `"PPTX"`
3084
- * - `"VIDEO"`
3085
- *
3086
- * The following file types do not support multiple pages:
3087
- *
3088
- * - `"JPG"`
3089
- * - `"PNG"`
3090
- * - `"SVG"`
3091
- */
3092
- url: string;
3093
- };
3094
-
3095
- /**
3096
- * @public
3097
- * The result when a user successfully completes an export flow.
3098
- */
3099
- export declare type ExportCompleted = {
3100
- /**
3101
- * The status of the export flow.
3102
- */
3103
- status: "completed";
3104
- /**
3105
- * The title of the design, if set by the user.
3106
- */
3107
- title?: string;
3108
- /**
3109
- * The exported files.
3110
- *
3111
- * @remarks
3112
- * This array only contains one element. This is because, if a multi-page design is exported as multiple files, the files
3113
- * 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.
3114
- */
3115
- exportBlobs: ExportBlob[];
3116
- };
3117
-
3118
- /**
3119
- * @public
3120
- * The types of files that Canva supports for exported designs.
3121
- */
3122
- export declare type ExportFileType =
3123
- | "png"
3124
- | "jpg"
3125
- | "pdf_standard"
3126
- | "video"
3127
- | "gif"
3128
- | "pptx"
3129
- | "svg";
3130
-
3131
- /**
3132
- * @public
3133
- * Options for configuring the export of a design.
3134
- */
3135
- export declare type ExportRequest = {
3136
- /**
3137
- * The types of files the user can export their design as.
3138
- *
3139
- * @remarks
3140
- * You must provide at least one file type.
3141
- */
3142
- acceptedFileTypes: ExportFileType[];
3143
- };
3144
-
3145
- /**
3146
- * @public
3147
- * The result of exporting a design.
3148
- */
3149
- export declare type ExportResponse = ExportCompleted | ExportAborted;
3150
-
3151
- /**
3152
- * @public
3153
- * Image element or content to be added to the design at the end of a drag event.
3154
- *
3155
- * @remarks
3156
- * This type is only used when the image data is from an external URL.
3157
- */
3158
- export declare type ExternalImageDragConfig = CommonImageDragConfig & {
3159
- /**
3160
- * A function that returns a reference (ref) to an audio asset in Canva's backend.
3161
- */
3162
- resolveImageRef: () => Promise<{
3163
- ref: ImageRef;
3164
- }>;
3165
- /**
3166
- * The URL of an image to display under the user's cursor during the drag and drop event.
3167
- */
3168
- previewUrl: string;
3169
- /**
3170
- * The dimensions of the full-size image.
3171
- */
3172
- fullSize?: Dimensions;
3173
- };
3174
-
3175
- /**
3176
- * @public
3177
- * The appearance of a path's interior.
3178
- *
3179
- * @remarks
3180
- * The `color` and `asset` properties are mutually exclusive.
3181
- */
3182
- export declare type Fill = {
3183
- /**
3184
- * If `true`, users can replace a fill by dropping an image or video onto it.
3185
- */
3186
- dropTarget?: boolean;
3187
- /**
3188
- * The color of the fill as a hex code.
3189
- *
3190
- * @remarks
3191
- * The hex code must include all six characters and be prefixed with a `#` symbol.
3192
- *
3193
- * @example
3194
- * "#ff0099"
3195
- */
3196
- color?: string;
3197
- /**
3198
- * An image or video to use as the fill.
3199
- */
3200
- asset?: ImageFill | VideoFill;
3201
- };
3202
-
3203
- /**
3204
- * @public
3205
- * A reference to a font that can be used in other parts of the SDK.
3206
- */
3207
- export declare type FontRef = string & {
3208
- __fontRef: never;
3209
- };
3210
-
3211
- /**
3212
- * @public
3213
- * Font weights supported in the SDK.
3214
- **/
3215
- export declare type FontWeight =
3216
- | "normal"
3217
- | "thin"
3218
- | "extralight"
3219
- | "light"
3220
- | "medium"
3221
- | "semibold"
3222
- | "bold"
3223
- | "ultrabold"
3224
- | "heavy";
3225
-
3226
- /**
3227
- * Allows to get the context of currently selected page.
3228
- * @public
3229
- * @returns Page context of currently selected page
3230
- *
3231
- * @example Get current page information
3232
- * ```typescript
3233
- * import { getCurrentPageContext } from "@canva/design";
3234
- *
3235
- * const pageContext = await getCurrentPageContext();
3236
- * if (pageContext.dimensions) {
3237
- * // Do something with the page dimensions, e.g. `pageContext.dimensions.width` and `pageContext.dimensions.height`
3238
- * } else {
3239
- * // This page type does not have fixed dimensions, e.g. Whiteboard or Doc
3240
- * }
3241
- * ```
3242
- */
3243
- export declare const getCurrentPageContext: () => Promise<PageContext>;
3244
-
3245
- /**
3246
- * @deprecated
3247
- * @public
3248
- * Gets the default dimensions that a new page will have when it is added to a design.
3249
- * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
3250
- * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
3251
- * design that is applied whenever a new page is created.
3252
- *
3253
- * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
3254
- *
3255
- * @example Get default page dimensions
3256
- * ```typescript
3257
- * import { getDefaultPageDimensions } from "@canva/design";
3258
- *
3259
- * const dimensions = await getDefaultPageDimensions();
3260
- *
3261
- * if (dimensions) {
3262
- * // Do something with the dimensions, e.g. `dimensions.width` and `dimensions.height`
3263
- * } else {
3264
- * // This design type does not have fixed dimensions, e.g. Whiteboard or Doc
3265
- * }
3266
- * ```
3267
- *
3268
- * @example Center element using page dimensions
3269
- * ```typescript
3270
- * import { getDefaultPageDimensions, addElementAtPoint } from "@canva/design";
3271
- * import type { ImageElementAtPoint } from "@canva/design";
3272
- *
3273
- * const dimensions = await getDefaultPageDimensions();
3274
- *
3275
- * if (dimensions) {
3276
- * const elementWidth = 300;
3277
- * const elementHeight = 200;
3278
- *
3279
- * const element: ImageElementAtPoint = {
3280
- * type: 'image',
3281
- * dataUrl: 'data:image/png;base64,...',
3282
- * altText: { text: 'Centered image', decorative: false },
3283
- * top: (dimensions.height - elementHeight) / 2,
3284
- * left: (dimensions.width - elementWidth) / 2,
3285
- * width: elementWidth,
3286
- * height: elementHeight
3287
- * };
3288
- *
3289
- * await addElementAtPoint(element);
3290
- * }
3291
- * ```
3292
- */
3293
- export declare const getDefaultPageDimensions: () => Promise<
3294
- Dimensions | undefined
3295
- >;
3296
-
3297
- /**
3298
- * @public
3299
- * Retrieves information about the design.
3300
- *
3301
- * @example Get design metadata
3302
- * ```typescript
3303
- * import { getDesignMetadata } from "@canva/design";
3304
- *
3305
- * const metadata = await getDesignMetadata();
3306
- *
3307
- * const { title, defaultPageDimensions, pageMetadata, durationInSeconds } = metadata;
3308
- * ```
3309
- */
3310
- export declare const getDesignMetadata: () => Promise<DesignMetadata>;
3311
-
3312
- /**
3313
- * @public
3314
- * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
3315
- *
3316
- * @example Get design token
3317
- * ```typescript
3318
- * import { getDesignToken } from "@canva/design";
3319
- *
3320
- * const { token } = await getDesignToken();
3321
- * ```
3322
- *
3323
- * @example Verify token with backend service
3324
- * ```typescript
3325
- * import { getDesignToken } from "@canva/design";
3326
- *
3327
- * const { token } = await getDesignToken();
3328
- *
3329
- * const verifyResponse = await fetch('https://your-backend.com/verify', {
3330
- * method: 'POST',
3331
- * headers: {
3332
- * 'Content-Type': 'application/json'
3333
- * },
3334
- * body: JSON.stringify({ token })
3335
- * });
3336
- *
3337
- * const json = await verifyResponse.json();
3338
- * const { designId, appId, userId } = json;
3339
- * ```
3340
- */
3341
- export declare const getDesignToken: () => Promise<DesignToken>;
3342
-
3343
- /**
3344
- * @public
3345
- * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
3346
- */
3347
- export declare type GroupContentAtPoint = Exclude<
3348
- ElementAtPoint,
3349
- GroupElementAtPoint
3350
- >;
3351
-
3352
- /**
3353
- * @public
3354
- * An element that contains two or more elements.
3355
- */
3356
- export declare type GroupElement = {
3357
- /**
3358
- * The type of element.
3359
- */
3360
- type: "group";
3361
- /**
3362
- * The elements to render within the group.
3363
- *
3364
- * @remarks
3365
- * - Each element within a group must have dimensions and a position.
3366
- * - The dimensions and positions are relative to the dimensions and positions of the group.
3367
- */
3368
- children: GroupContentAtPoint[];
3369
- };
3370
-
3371
- /**
3372
- * @public
3373
- * An element that contains two or more elements and has positional properties.
3374
- */
3375
- export declare type GroupElementAtPoint = GroupElement &
3376
- Point &
3377
- (WidthAndHeight | Width | Height);
3378
-
3379
- /**
3380
- * A set of dimensions with an auto-calculated width.
3381
- */
3382
- declare type Height = {
3383
- /**
3384
- * Indicates that the width should be auto-calculated.
3385
- */
3386
- width: "auto";
3387
- /**
3388
- * A height, in pixels.
3389
- *
3390
- * @remarks
3391
- * - The pixels are relative to their container.
3392
- * - Minimum: 0
3393
- * - Maximum: 32767
3394
- */
3395
- height: number;
3396
- };
3397
-
3398
- /**
3399
- * @public
3400
- * Image element or content to be added to the design at the end of a drag event.
3401
- */
3402
- export declare type ImageDragConfig = ExternalImageDragConfig;
3403
-
3404
- /**
3405
- * @public
3406
- * Image element or content to be added to the design at the end of a drag event.
3407
- */
3408
- export declare type ImageDragConfigForElement<E extends Element> =
3409
- E extends HTMLImageElement
3410
- ? Partial<ImageDragConfig> & Pick<ImageDragConfig, "type">
3411
- : ImageDragConfig;
3412
-
3413
- /**
3414
- * @public
3415
- * An element that renders image content.
3416
- */
3417
- export declare type ImageElement = {
3418
- /**
3419
- * The type of element.
3420
- */
3421
- type: "image";
3422
- /**
3423
- * A description of the image content.
3424
- *
3425
- * @remarks
3426
- * Use `undefined` for content with no description.
3427
- */
3428
- altText: AltText | undefined;
3429
- } & (
3430
- | {
3431
- /**
3432
- * A data URL that contains the image data.
3433
- */
3434
- dataUrl: string;
3435
- /**
3436
- * A unique identifier that points to an image asset in Canva's backend.
3437
- */
3438
- ref?: never;
3439
- }
3440
- | {
3441
- /**
3442
- * A data URL that contains the image data.
3443
- */
3444
- dataUrl?: never;
3445
- /**
3446
- * A unique identifier that points to an image asset in Canva's backend.
3447
- */
3448
- ref: ImageRef;
3449
- }
3450
- );
3451
-
3452
- /**
3453
- * @public
3454
- * An element that renders image content and has positional properties.
3455
- */
3456
- export declare type ImageElementAtPoint = ImageElement &
3457
- Point &
3458
- (WidthAndHeight | Width | Height);
3459
-
3460
- /**
3461
- * @public
3462
- * An image asset that fills a path's interior.
3463
- */
3464
- export declare type ImageFill = {
3465
- /**
3466
- * The type of fill.
3467
- */
3468
- type: "image";
3469
- /**
3470
- * A unique identifier that points to an image asset in Canva's backend.
3471
- */
3472
- ref: ImageRef;
3473
- /**
3474
- * A description of the image content.
3475
- *
3476
- * @remarks
3477
- * Use `undefined` for content with no description.
3478
- */
3479
- altText?: AltText;
3480
- };
3481
-
3482
- /**
3483
- * @public
3484
- * A unique identifier that references an image asset in Canva's backend.
3485
- */
3486
- export declare type ImageRef = string & {
3487
- __imageRef: never;
3488
- };
3489
-
3490
- /**
3491
- * @public
3492
- * @param appElementConfig - Configuration for an AppElementClient
3493
- *
3494
- * @example Initialize app element client
3495
- * ```typescript
3496
- * import { initAppElement } from "@canva/design";
3497
- *
3498
- * const appElement = initAppElement<{ content: string }>({
3499
- * render: (data) => {
3500
- * return [{
3501
- * type: 'text',
3502
- * children: [data.content],
3503
- * top: 100,
3504
- * left: 100,
3505
- * width: 200
3506
- * }];
3507
- * }
3508
- * });
3509
- * ```
3510
- *
3511
- * @example Initialize V2 app element client
3512
- * ```typescript
3513
- * import { initAppElement } from "@canva/design";
3514
- *
3515
- * const appElement = initAppElement<{ content: string }>({
3516
- * render: (data) => {
3517
- * return [{
3518
- * type: 'text',
3519
- * children: [data.content],
3520
- * top: 100,
3521
- * left: 100,
3522
- * width: 200
3523
- * }];
3524
- * }
3525
- * });
3526
- * ```
3527
- */
3528
- export declare const initAppElement: <A extends AppElementData>(
3529
- appElementConfig: AppElementClientConfiguration<A>,
3530
- ) => AppElementClient<A>;
3531
-
3532
- /**
3533
- * @public
3534
- * Options for formatting inline richtext.
3535
- */
3536
- export declare type InlineFormatting = {
3537
- /**
3538
- * The color of the text as a hex code.
3539
- *
3540
- * @remarks
3541
- * The hex code must include all six characters and be prefixed with a `#` symbol.
3542
- *
3543
- * @example
3544
- * "#ff0099"
3545
- */
3546
- color?: string;
3547
- /**
3548
- * The weight (thickness) of the font.
3549
- *
3550
- * @remarks
3551
- * The available font weights depend on the font.
3552
- *
3553
- * @defaultValue "normal"
3554
- */
3555
- fontWeight?: FontWeight;
3556
- /**
3557
- * The style of the font.
3558
- * @defaultValue "normal"
3559
- */
3560
- fontStyle?: "normal" | "italic";
3561
- /**
3562
- * The decoration of the text.
3563
- * @defaultValue "none"
3564
- */
3565
- decoration?: "none" | "underline";
3566
- /**
3567
- * The strikethrough of the text.
3568
- * @defaultValue "none"
3569
- */
3570
- strikethrough?: "none" | "strikethrough";
3571
- /**
3572
- * An external URL that the text links to.
3573
- */
3574
- link?: string;
3575
- };
3576
-
3577
- /**
3578
- * @deprecated The type has been superseded by `DesignElement`.
3579
- * @public
3580
- * An element that's natively supported by the Canva editor.
3581
- */
3582
- export declare type NativeElement =
3583
- | NativeImageElement
3584
- | NativeVideoElement
3585
- | NativeEmbedElement
3586
- | NativeTextElement
3587
- | NativeShapeElement
3588
- | NativeGroupElement;
3589
-
3590
- /**
3591
- * @deprecated
3592
- * @public
3593
- * The types of elements an app can add to a user's design.
3594
- */
3595
- export declare type NativeElementType =
3596
- | "image"
3597
- | "embed"
3598
- | "text"
3599
- | "shape"
3600
- | "video";
3601
-
3602
- /**
3603
- * @deprecated The type has been superseded by `ElementAtPoint`.
3604
- * @public
3605
- * An element that's natively supported by the Canva editor and has positional properties.
3606
- */
3607
- export declare type NativeElementWithBox =
3608
- | NativeImageElementWithBox
3609
- | NativeVideoElementWithBox
3610
- | NativeEmbedElementWithBox
3611
- | NativeTextElementWithBox
3612
- | NativeShapeElementWithBox
3613
- | NativeGroupElementWithBox;
3614
-
3615
- /**
3616
- * @deprecated The type has been superseded by `EmbedElement`.
3617
- * @public
3618
- * An element that renders rich media, such as a YouTube video.
3619
- */
3620
- export declare type NativeEmbedElement = EmbedElement;
3621
-
3622
- /**
3623
- * @deprecated The type has been superseded by `EmbedElementAtPoint`.
3624
- * @public
3625
- * An element that renders rich media, such as a YouTube video, and has positional properties.
3626
- */
3627
- export declare type NativeEmbedElementWithBox = EmbedElementAtPoint;
3628
-
3629
- /**
3630
- * @deprecated The type has been superseded by `GroupElement`.
3631
- * @public
3632
- * An element that contains two or more elements.
3633
- */
3634
- export declare type NativeGroupElement = GroupElement;
3635
-
3636
- /**
3637
- * @deprecated The type has been superseded by `GroupElementAtPoint`.
3638
- * @public
3639
- * An element that contains two or more elements and has positional properties.
3640
- */
3641
- export declare type NativeGroupElementWithBox = GroupElementAtPoint;
3642
-
3643
- /**
3644
- * @deprecated The type has been superseded by `ImageElement`.
3645
- * @public
3646
- * An element that renders image content.
3647
- */
3648
- export declare type NativeImageElement = ImageElement;
3649
-
3650
- /**
3651
- * @deprecated The type has been superseded by `ImageElementAtPoint`.
3652
- * @public
3653
- * An element that renders image content and has positional properties.
3654
- */
3655
- export declare type NativeImageElementWithBox = ImageElementAtPoint;
3656
-
3657
- /**
3658
- * @deprecated The type has been superseded by `ShapeElement`.
3659
- * @public
3660
- * An element that renders a vector shape.
3661
- */
3662
- export declare type NativeShapeElement = ShapeElement;
3663
-
3664
- /**
3665
- * @deprecated The type has been superseded by `ShapeElementAtPoint`.
3666
- * @public
3667
- * An element that renders a vector shape and has positional properties.
3668
- */
3669
- export declare type NativeShapeElementWithBox = ShapeElementAtPoint;
3670
-
3671
- /**
3672
- * @deprecated The type has been superseded by `GroupContentAtPoint`.
3673
- * @public
3674
- * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
3675
- */
3676
- export declare type NativeSimpleElementWithBox = GroupContentAtPoint;
3677
-
3678
- /**
3679
- * @deprecated The type has been superseded by `TextElement`.
3680
- * @public
3681
- * An element that renders text content.
3682
- */
3683
- export declare type NativeTextElement = TextElement;
3684
-
3685
- /**
3686
- * @deprecated The type has been superseded by `TextElementAtPoint`.
3687
- * @public
3688
- * An element that renders text content and has positional properties.
3689
- */
3690
- export declare type NativeTextElementWithBox = TextElementAtPoint;
3691
-
3692
- /**
3693
- * @deprecated The type has been superseded by `VideoElement`.
3694
- * @public
3695
- * An element that renders video content.
3696
- */
3697
- export declare type NativeVideoElement = VideoElement;
3698
-
3699
- /**
3700
- * @deprecated The type has been superseded by `VideoElementAtPoint`.
3701
- * @public
3702
- * An element that renders video content and has positional properties.
3703
- */
3704
- export declare type NativeVideoElementWithBox = VideoElementAtPoint;
3705
-
3706
- /**
3707
- * An object primitive data type that can be used in app element data.
3708
- */
3709
- declare type ObjectPrimitive = Boolean | String;
3710
-
3711
- /**
3712
- * @public
3713
- *
3714
- * Reads a specified part of the user's design and returns all elements in that part.
3715
- *
3716
- * @param options - Options for configuring how the design is read.
3717
- * @param callback - A callback for operating on the design.
3718
- */
3719
- export declare const openDesign: (
3720
- options: DesignOpenOptions,
3721
- callback: DesignOpenCallback,
3722
- ) => Promise<void>;
3723
-
3724
- /**
3725
- * @public
3726
- * An alias for the DesignOverlay interface, providing access to design overlay related functionality
3727
- */
3728
- export declare const overlay: DesignOverlay;
3729
-
3730
- /**
3731
- * @public
3732
- * Information about whether or not an overlay can be opened for the specified target.
3733
- */
3734
- export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
3735
- /**
3736
- * Information about whether or not an overlay can be opened or not for a selected image.
3737
- */
3738
- ["image_selection"]:
3739
- | OverlayUnopenableEvent
3740
- | {
3741
- /**
3742
- * Indicates that the overlay can be opened for the selected image.
3743
- */
3744
- canOpen: true;
3745
- /**
3746
- * Opens an overlay for the selected image.
3747
- * @param opts - Options for launching the process associated with the overlay.
3748
- */
3749
- readonly open: (options: {
3750
- /**
3751
- * Parameters to pass to the overlay when it opens.
3752
- *
3753
- * @remarks
3754
- * This can be any type of structured data.
3755
- */
3756
- launchParameters?: unknown;
3757
- }) => Promise<AppProcessId>;
3758
- };
3759
- }[Target];
3760
-
3761
- /**
3762
- * @public
3763
- * An entity that an overlay can be opened for.
3764
- */
3765
- export declare type OverlayTarget = "image_selection";
3766
-
3767
- /**
3768
- * @public
3769
- * Information about an overlay that can't be opened for the specified target.
3770
- */
3771
- declare type OverlayUnopenableEvent = {
3772
- /**
3773
- * Indicates that the overlay can't be opened for the specified target.
3774
- */
3775
- canOpen: false;
3776
- /**
3777
- * Indicates the reason the overlay can't be opened for the specified target.
3778
- */
3779
- reason: string;
3780
- };
3781
-
3782
- /**
3783
- * @public
3784
- * The appearance of a page's background.
3785
- */
3786
- export declare type PageBackgroundFill = Pick<Fill, "asset" | "color">;
3787
-
3788
- /**
3789
- * @public
3790
- * Information about a page.
3791
- */
3792
- export declare type PageContext = {
3793
- /**
3794
- * The dimensions of the page, in pixels.
3795
- *
3796
- * @remarks
3797
- * This may be `undefined` because some types of pages don't have dimensions, such as whiteboards.
3798
- */
3799
- dimensions: PageDimensions | undefined;
3800
- };
3801
-
3802
- /**
3803
- * @public
3804
- * A set of page dimensions, in pixels.
3805
- */
3806
- export declare type PageDimensions = {
3807
- /**
3808
- * The width of the page, in pixels.
3809
- */
3810
- width: number;
3811
- /**
3812
- * The height of the page, in pixels.
3813
- */
3814
- height: number;
3815
- };
3816
-
3817
- /**
3818
- * @public
3819
- * Information about a page.
3820
- */
3821
- export declare type PageMetadata = {
3822
- /**
3823
- * The dimensions of the page, in pixels.
3824
- *
3825
- * @remarks
3826
- * This may be `undefined` because some types of pages don't have dimensions, such as whiteboards.
3827
- */
3828
- dimensions?: PageDimensions;
3829
- };
3830
-
3831
- /**
3832
- * @public
3833
- * The outline of a path.
3834
- */
3835
- export declare type PathStroke = {
3836
- /**
3837
- * The weight (thickness) of the stroke.
3838
- *
3839
- * @remarks
3840
- * - Minimum: 0
3841
- * - Maximum: 100
3842
- */
3843
- weight: number;
3844
- /**
3845
- * The color of the stroke as a hex code.
3846
- *
3847
- * @remarks
3848
- * The hex code must include all six characters and be prefixed with a `#` symbol.
3849
- *
3850
- * @example
3851
- * "#ff0099"
3852
- */
3853
- color: string;
3854
- /**
3855
- * The alignment of the stroke.
3856
- */
3857
- strokeAlign: "inset";
3858
- };
3859
-
3860
- /**
3861
- * @public
3862
- * A position, set of dimensions, and rotation.
3863
- */
3864
- export declare type Placement = Point & (WidthAndHeight | Width | Height);
3865
-
3866
- /**
3867
- * A position and rotation.
3868
- */
3869
- declare type Point = {
3870
- /**
3871
- * The distance from the top edge of the container, in pixels.
3872
- *
3873
- * @remarks
3874
- * - The pixels are relative to their container.
3875
- * - Minimum: -32768
3876
- * - Maximum: 32767
3877
- */
3878
- top: number;
3879
- /**
3880
- * The distance from the left edge of the container, in pixels.
3881
- *
3882
- * @remarks
3883
- * - The pixels are relative to their container.
3884
- * - Minimum: -32768
3885
- * - Maximum: 32767
3886
- */
3887
- left: number;
3888
- /**
3889
- * A rotation, in degrees.
3890
- *
3891
- * @remarks
3892
- * - Minimum: -180
3893
- * - Maximum: 180
3894
- */
3895
- rotation?: number;
3896
- };
3897
-
3898
- /**
3899
- * A primitive data type that can be used in app element data.
3900
- *
3901
- * @remarks
3902
- * All primitive data types are supported except for symbols and bigints.
3903
- */
3904
- declare type Primitive = undefined | null | number | boolean | string;
3905
-
3906
- /**
3907
- * @public
3908
- * Exports the user's design as one or more static files.
3909
- * @param request - The request object containing configurations of the design export.
3910
- */
3911
- export declare const requestExport: (
3912
- request: ExportRequest,
3913
- ) => Promise<ExportResponse>;
3914
-
3915
- /**
3916
- * @public
3917
- * Provides methods for interacting with a range of formatted text.
3918
- */
3919
- export declare interface RichtextContentRange extends RichtextRange {
3920
- /**
3921
- * Indicates whether the object containing this richtext range has been deleted.
3922
- */
3923
- readonly deleted: boolean;
3924
- }
3925
-
3926
- /**
3927
- * @public
3928
- * A callback for reading and updating the requested design content.
3929
- * @param session - The result of reading the content in the design.
3930
- *
3931
- * @example Read and update richtext content
3932
- * ```typescript
3933
- * import { editContent } from "@canva/design";
3934
- *
3935
- * await editContent(
3936
- * { contentType: 'richtext', target: 'current_page' },
3937
- * async (session) => {
3938
- * // Read the content
3939
- * const contents = session.contents;
3940
- *
3941
- * if (contents.length > 0) {
3942
- * const range = contents[0];
3943
- *
3944
- * // Modify the content (e.g., adding text)
3945
- * range.appendText("\nAppended text from app");
3946
- *
3947
- * // Sync changes back to the design
3948
- * await session.sync();
3949
- * }
3950
- * }
3951
- * );
3952
- * ```
3953
- *
3954
- * @example Format all richtext content in the design
3955
- * ```typescript
3956
- * import { editContent } from "@canva/design";
3957
- *
3958
- * await editContent(
3959
- * { contentType: 'richtext', target: 'current_page' },
3960
- * async (session) => {
3961
- * // Process each richtext range in the content
3962
- * for (const range of session.contents) {
3963
- * // Skip if the content has been deleted
3964
- * if (range.deleted) continue;
3965
- *
3966
- * // Get the text content
3967
- * const text = range.readPlaintext();
3968
- * if (text.length === 0) continue;
3969
- *
3970
- * // Apply consistent formatting
3971
- * range.formatParagraph(
3972
- * { index: 0, length: text.length },
3973
- * {
3974
- * fontRef: 'YOUR_FONT_REF',
3975
- * fontSize: 16,
3976
- * textAlign: 'start'
3977
- * }
3978
- * );
3979
- * }
3980
- *
3981
- * // Sync all changes back to the design
3982
- * await session.sync();
3983
- * }
3984
- * );
3985
- * ```
3986
- *
3987
- * @example Modify content without saving changes
3988
- * ```typescript
3989
- * import { editContent } from "@canva/design";
3990
- *
3991
- * await editContent(
3992
- * { contentType: 'richtext', target: 'current_page' },
3993
- * async (session) => {
3994
- * // Read and analyze the content without making changes
3995
- * for (const range of session.contents) {
3996
- * const text = range.readPlaintext();
3997
- * // Do something with the content preview, e.g. `text.substring(0, 50)`
3998
- *
3999
- * // No call to session.sync() means no changes are saved
4000
- * }
4001
- *
4002
- * // Since we're not calling sync(), no changes will be made to the design
4003
- * }
4004
- * );
4005
- * ```
4006
- */
4007
- export declare interface RichtextContentSession {
4008
- /**
4009
- * Richtext content in the design.
4010
- */
4011
- readonly contents: readonly RichtextContentRange[];
4012
- /**
4013
- * Saves any changes made during the session while keeping the transaction open.
4014
- *
4015
- * @remarks
4016
- * - Any changes in the session are only reflected in the design after this method is called.
4017
- * - Once this method is called, further changes in the session can still be made.
4018
- *
4019
- * @example Sync changes after modifying content
4020
- * ```typescript
4021
- * import { editContent } from "@canva/design";
4022
- *
4023
- * await editContent(
4024
- * { contentType: 'richtext', target: 'current_page' },
4025
- * async (session) => {
4026
- * if (session.contents.length > 0) {
4027
- * const range = session.contents[0];
4028
- *
4029
- * // Make modifications to the content
4030
- * range.appendText(" - Modified by app");
4031
- *
4032
- * try {
4033
- * // Save changes back to the design
4034
- * await session.sync();
4035
- * } catch (error) {
4036
- * console.error('Failed to sync changes:', error);
4037
- * }
4038
- * }
4039
- * }
4040
- * );
4041
- * ```
4042
- */
4043
- sync(): Promise<void>;
4044
- }
4045
-
4046
- /**
4047
- * @public
4048
- * An element that renders richtext content.
4049
- */
4050
- export declare type RichtextElement = {
4051
- /**
4052
- * The type of element.
4053
- */
4054
- type: "richtext";
4055
- /**
4056
- * The richtext content.
4057
- */
4058
- range: RichtextRange;
4059
- };
4060
-
4061
- /**
4062
- * @public
4063
- * An element that renders richtext content.
4064
- *
4065
- * @remarks
4066
- * This type includes properties for controlling the position and dimensions of the
4067
- * element.
4068
- * It will be positioned and sized relative to its parent container.
4069
- * The parent container may be an app element, or the current page.
4070
- */
4071
- export declare type RichtextElementAtPoint = RichtextElement & TextBox;
4072
-
4073
- /**
4074
- * @public
4075
- * Options for formatting richtext.
4076
- */
4077
- export declare type RichtextFormatting = InlineFormatting & {
4078
- /**
4079
- * @public
4080
- * A unique identifier that points to a font asset in Canva's backend.
4081
- */
4082
- fontRef?: FontRef;
4083
- /**
4084
- * The size of the text, in pixels.
4085
- *
4086
- * @remarks
4087
- * - In the Canva editor, this number is shown as points (pts), not pixels.
4088
- * - Minimum: 1
4089
- * - Maximum: 100
4090
- */
4091
- fontSize?: number;
4092
- /**
4093
- * The alignment of the text.
4094
- * @defaultValue "start"
4095
- */
4096
- textAlign?: "start" | "center" | "end" | "justify";
4097
- /**
4098
- * The list indentation level of the paragraph.
4099
- */
4100
- listLevel?: number;
4101
- /**
4102
- * The appearance of list item markers.
4103
- *
4104
- * @remarks
4105
- * This property only has an effect if `listLevel` is greater than 0.
4106
- *
4107
- * @defaultValue "none"
4108
- */
4109
- listMarker?:
4110
- | "none"
4111
- | "disc"
4112
- | "circle"
4113
- | "square"
4114
- | "decimal"
4115
- | "lower-alpha"
4116
- | "lower-roman"
4117
- | "checked"
4118
- | "unchecked";
4119
- };
4120
-
4121
- /**
4122
- * @public
4123
- * Provides methods for interacting with a range of formatted text.
4124
- */
4125
- export declare type RichtextRange = {
4126
- /**
4127
- * Formats all of the paragraphs that overlap the given bounds.
4128
- *
4129
- * @param bounds - The segment of the range on which to apply the formatting.
4130
- * @param formatting - The formatting to apply to the paragraph(s).
4131
- *
4132
- * @remarks
4133
- * - The `\n` character indicates the end of a paragraph.
4134
- * - All paragraphs that overlap the provided bounds will be formatted in their entirety.
4135
- *
4136
- * @example Format paragraph as a heading
4137
- * ```typescript
4138
- * import { createRichtextRange } from "@canva/design";
4139
- *
4140
- * const range = createRichtextRange();
4141
- *
4142
- * range.appendText("Heading Text\nRegular paragraph text.");
4143
- *
4144
- * // Format just the first paragraph as a heading
4145
- * range.formatParagraph(
4146
- * { index: 0, length: 12 }, // Only need to include part of the paragraph
4147
- * {
4148
- * fontSize: 24,
4149
- * fontWeight: 'bold',
4150
- * textAlign: 'center'
4151
- * }
4152
- * );
4153
- * ```
4154
- *
4155
- * @example Create a bulleted list
4156
- * ```typescript
4157
- * import { createRichtextRange } from "@canva/design";
4158
- *
4159
- * const range = createRichtextRange();
4160
- * const text = "Item 1\nItem 2\nItem 3";
4161
- * range.appendText(text);
4162
- *
4163
- * // Format all paragraphs as a bulleted list
4164
- * range.formatParagraph(
4165
- * { index: 0, length: text.length },
4166
- * {
4167
- * listLevel: 1,
4168
- * listMarker: 'disc'
4169
- * }
4170
- * );
4171
- * ```
4172
- */
4173
- formatParagraph(bounds: Bounds, formatting: RichtextFormatting): void;
4174
- /**
4175
- * Formats a region of text with inline formatting properties.
4176
- *
4177
- * @param bounds - The segment of the range on which to apply the formatting.
4178
- * @param formatting - The formatting to apply to the text.
4179
- *
4180
- * @example Format specific words in a paragraph
4181
- * ```typescript
4182
- * import { createRichtextRange } from "@canva/design";
4183
- *
4184
- * const range = createRichtextRange();
4185
- * range.appendText("This text contains important information.");
4186
- *
4187
- * // Format just the word "important"
4188
- * range.formatText(
4189
- * { index: 16, length: 9 },
4190
- * {
4191
- * fontWeight: 'bold',
4192
- * color: '#FF0000'
4193
- * }
4194
- * );
4195
- * ```
4196
- *
4197
- * @example Add a link to text
4198
- * ```typescript
4199
- * import { createRichtextRange } from "@canva/design";
4200
- *
4201
- * const range = createRichtextRange();
4202
- * range.appendText("Visit our website for more information.");
4203
- *
4204
- * // Add a link to "our website"
4205
- * range.formatText(
4206
- * { index: 6, length: 11 },
4207
- * {
4208
- * link: "https://www.example.com",
4209
- * decoration: 'underline',
4210
- * color: '#0066CC'
4211
- * }
4212
- * );
4213
- * ```
4214
- */
4215
- formatText(bounds: Bounds, formatting: InlineFormatting): void;
4216
- /**
4217
- * Appends the specified characters to the end of the range.
4218
- *
4219
- * @param characters - The characters to append to the richtext range.
4220
- * @param formatting - Optional formatting to apply to the appended text.
4221
- *
4222
- * @example Append plain text
4223
- * ```typescript
4224
- * import { createRichtextRange } from "@canva/design";
4225
- *
4226
- * const range = createRichtextRange();
4227
- * range.appendText("First paragraph. ");
4228
- *
4229
- * // Append more text to the existing content
4230
- * const result = range.appendText("This is additional text.");
4231
- *
4232
- * // The bounds of the newly added text are returned
4233
- * // Do something with the bounds - result.bounds, e.g. { index: 17, length: 24 }
4234
- * ```
4235
- *
4236
- * @example Append formatted text
4237
- * ```typescript
4238
- * import { createRichtextRange } from "@canva/design";
4239
- *
4240
- * const range = createRichtextRange();
4241
- * range.appendText("Normal text followed by ");
4242
- *
4243
- * // Append formatted text
4244
- * range.appendText("bold red text", {
4245
- * fontWeight: 'bold',
4246
- * color: '#FF0000'
4247
- * });
4248
- *
4249
- * // Append a new paragraph
4250
- * range.appendText("\nThis is a new paragraph.");
4251
- * ```
4252
- */
4253
- appendText(
4254
- characters: string,
4255
- formatting?: InlineFormatting,
4256
- ): {
4257
- bounds: Bounds;
4258
- };
4259
- /**
4260
- * Replaces a region of text with the specified characters.
4261
- *
4262
- * @param bounds - The segment of the range to replace.
4263
- * @param characters - The replacement characters.
4264
- * @param formatting - The formatting to apply to the replaced text.
4265
- *
4266
- * @example Replace text while maintaining some formatting
4267
- * ```typescript
4268
- * import { createRichtextRange } from "@canva/design";
4269
- *
4270
- * const range = createRichtextRange();
4271
- * range.appendText("This text needs correction.");
4272
- *
4273
- * // Replace "needs correction" with "is correct"
4274
- * const result = range.replaceText(
4275
- * { index: 10, length: 16 },
4276
- * "is correct"
4277
- * );
4278
- *
4279
- * // The bounds of the replaced text are returned
4280
- * // Do something with the bounds - result.bounds, e.g. { index: 10, length: 10 }
4281
- * ```
4282
- *
4283
- * @example Replace text with formatted text
4284
- * ```typescript
4285
- * import { createRichtextRange } from "@canva/design";
4286
- *
4287
- * const range = createRichtextRange();
4288
- * range.appendText("Regular text that needs emphasis.");
4289
- *
4290
- * // Replace "needs emphasis" with formatted text
4291
- * range.replaceText(
4292
- * { index: 17, length: 15 },
4293
- * "is important",
4294
- * {
4295
- * fontWeight: 'bold',
4296
- * fontStyle: 'italic',
4297
- * color: '#0066CC'
4298
- * }
4299
- * );
4300
- * ```
4301
- */
4302
- replaceText(
4303
- bounds: Bounds,
4304
- characters: string,
4305
- formatting?: InlineFormatting,
4306
- ): {
4307
- /**
4308
- * The bounds of the replacement characters within the updated range.
4309
- */
4310
- bounds: Bounds;
4311
- };
4312
- /**
4313
- * Returns the current state of the richtext as plaintext.
4314
- *
4315
- * @example Extract plain text content
4316
- * ```typescript
4317
- * import { createRichtextRange } from "@canva/design";
4318
- *
4319
- * const range = createRichtextRange();
4320
- * range.appendText("First paragraph.\n", { fontWeight: 'bold' });
4321
- * range.appendText("Second paragraph with formatting.", { color: '#FF0000' });
4322
- *
4323
- * // Get plain text content without formatting
4324
- * const plainText = range.readPlaintext();
4325
- * // Do something with the plain text - plainText, e.g. "First paragraph.\nSecond paragraph with formatting."
4326
- * ```
4327
- *
4328
- * @example Search within text content
4329
- * ```typescript
4330
- * import { createRichtextRange } from "@canva/design";
4331
- *
4332
- * const range = createRichtextRange();
4333
- * range.appendText("This text contains a searchable term.");
4334
- *
4335
- * // Search for a specific word
4336
- * const plainText = range.readPlaintext();
4337
- * const searchTerm = "searchable";
4338
- * const index = plainText.indexOf(searchTerm);
4339
- *
4340
- * if (index !== -1) {
4341
- * // Format the found term
4342
- * range.formatText(
4343
- * { index, length: searchTerm.length },
4344
- * { fontWeight: 'bold', decoration: 'underline' }
4345
- * );
4346
- * }
4347
- * ```
4348
- */
4349
- readPlaintext(): string;
4350
- /**
4351
- * Returns the current state of the richtext as one or more text regions.
4352
- * Each region is an object that contains the text content and its formatting.
4353
- *
4354
- * @example Get text with formatting information
4355
- * ```typescript
4356
- * import { createRichtextRange } from "@canva/design";
4357
- *
4358
- * const range = createRichtextRange();
4359
- * range.appendText("Normal text ", {});
4360
- * range.appendText("bold text", { fontWeight: 'bold' });
4361
- * range.appendText(" and ", {});
4362
- * range.appendText("red text", { color: '#FF0000' });
4363
- *
4364
- * // Get formatted regions
4365
- * const regions = range.readTextRegions();
4366
- * // Do something with the regions, e.g.
4367
- * // [
4368
- * // { text: "Normal text ", formatting: {} },
4369
- * // { text: "bold text", formatting: { fontWeight: 'bold' } },
4370
- * // { text: " and ", formatting: {} },
4371
- * // { text: "red text", formatting: { color: '#FF0000' } }
4372
- * // ]
4373
- * ```
4374
- *
4375
- * @example Analyze formatting variations
4376
- * ```typescript
4377
- * import { createRichtextRange } from "@canva/design";
4378
- *
4379
- * const range = createRichtextRange();
4380
- * range.appendText("Mixed ", {});
4381
- * range.appendText("formatted ", { fontWeight: 'bold' });
4382
- * range.appendText("text", { color: '#0066CC' });
4383
- *
4384
- * // Analyze formatting variations
4385
- * const regions = range.readTextRegions();
4386
- * const formattingTypes = regions.map(region => {
4387
- * const formatting = region.formatting || {};
4388
- * return {
4389
- * text: region.text,
4390
- * hasWeight: !!formatting.fontWeight,
4391
- * hasColor: !!formatting.color
4392
- * };
4393
- * });
4394
- * ```
4395
- */
4396
- readTextRegions(): TextRegion[];
4397
- };
4398
-
4399
- /**
4400
- * @public
4401
- * An alias for the DesignSelection interface, providing access to design selection related functionality
4402
- */
4403
- export declare const selection: DesignSelection;
4404
-
4405
- /**
4406
- * @public
4407
- * Information about the user's selection. To access the selected content, call the `read` method.
4408
- */
4409
- export declare interface SelectionEvent<Scope extends SelectionScope> {
4410
- /**
4411
- * The type of content that's selected.
4412
- */
4413
- readonly scope: Scope;
4414
- /**
4415
- * The number of selected elements.
4416
- */
4417
- readonly count: number;
4418
- /**
4419
- * Creates a snapshot of the selected content and returns a *draft* object.
4420
- * The draft has a mutable `contents` property for making changes to the selected content.
4421
- * Any changes made to `contents` are not immediately persisted or reflected in the user's design.
4422
- * To persist the changes, call the `save` method that's available via the draft.
4423
- *
4424
- * @example Read and modify plaintext selection
4425
- * ```typescript
4426
- * import { selection } from "@canva/design";
4427
- *
4428
- * selection.registerOnChange({
4429
- * scope: 'plaintext',
4430
- * onChange: async (event) => {
4431
- * if (event.count > 0) {
4432
- * // Read the content
4433
- * const draft = await event.read();
4434
- *
4435
- * // Handle selected text `draft.contents[0].text`
4436
- *
4437
- * // Modify the text if needed
4438
- * // draft.contents[0].text = 'Modified text';
4439
- * // await draft.save();
4440
- * }
4441
- * }
4442
- * });
4443
- * ```
4444
- *
4445
- * @example Read and analyze image selection
4446
- * ```typescript
4447
- * import { selection } from "@canva/design";
4448
- *
4449
- * selection.registerOnChange({
4450
- * scope: 'image',
4451
- * onChange: async (event) => {
4452
- * // Check if any images are selected
4453
- * if (event.count === 0) {
4454
- * // Handle no images selected case
4455
- * return;
4456
- * }
4457
- *
4458
- * // Read the content
4459
- * const draft = await event.read();
4460
- *
4461
- * // Get information about selected images
4462
- * const imageRefs = draft.contents.map(content => content.ref);
4463
- *
4464
- * // The ref can be used with other API methods
4465
- * }
4466
- * });
4467
- * ```
4468
- *
4469
- * @example Process multiple selected items
4470
- * ```typescript
4471
- * import { selection } from "@canva/design";
4472
- *
4473
- * selection.registerOnChange({
4474
- * scope: 'richtext',
4475
- * onChange: async (event) => {
4476
- * if (event.count > 0) {
4477
- * const draft = await event.read();
4478
- *
4479
- * // Process each selected range
4480
- * draft.contents.forEach((range) => {
4481
- * // Do something with the range content and formatted regions, with `range.readPlaintext()` and `range.readTextRegions()`
4482
- * });
4483
- * }
4484
- * }
4485
- * });
4486
- * ```
4487
- */
4488
- read(): Promise<ContentDraft<SelectionValue<Scope>>>;
4489
- }
4490
-
4491
- /**
4492
- * @public
4493
- * Information about a user's selection.
4494
- */
4495
- export declare interface SelectionEvent<Scope extends SelectionScope> {
4496
- /**
4497
- * The type of content.
4498
- */
4499
- readonly scope: Scope;
4500
- /**
4501
- * The number of content items in the user's selection.
4502
- */
4503
- readonly count: number;
4504
- /**
4505
- * Returns a snapshot of the content in the user's selection.
4506
- *
4507
- * @remarks
4508
- * The snapshot is known as the *draft*.
4509
- */
4510
- read(): Promise<ContentDraft<SelectionValue<Scope>>>;
4511
- }
4512
-
4513
- /**
4514
- * @public
4515
- * A type of content that supports selection events.
4516
- */
4517
- export declare type SelectionScope =
4518
- | "plaintext"
4519
- | "image"
4520
- | "video"
4521
- | "richtext";
4522
-
4523
- /**
4524
- * @public
4525
- * A piece of selected content.
4526
- *
4527
- * @remarks
4528
- * The available properties depend on the type (scope) of content.
4529
- */
4530
- export declare type SelectionValue<Scope extends SelectionScope> = {
4531
- /**
4532
- * A selected range of plaintext.
4533
- */
4534
- ["plaintext"]: {
4535
- /**
4536
- * The text content.
4537
- */
4538
- text: string;
4539
- };
4540
- /**
4541
- * A selected image.
4542
- */
4543
- ["image"]: {
4544
- /**
4545
- * A unique identifier that points to an image asset in Canva's backend.
4546
- */
4547
- ref: ImageRef;
4548
- };
4549
- /**
4550
- * A selected video.
4551
- */
4552
- ["video"]: {
4553
- /**
4554
- * A unique identifier that points to an video asset in Canva's backend.
4555
- */
4556
- ref: VideoRef;
4557
- };
4558
- /**
4559
- * A selected range of formatted text.
4560
- */
4561
- ["richtext"]: RichtextRange;
4562
- }[Scope];
4563
-
4564
- /**
4565
- * @public
4566
- * Updates the background of the user's current page. The background can be a solid color,
4567
- * an image or a video.
4568
- *
4569
- * @example Set background color
4570
- * ```typescript
4571
- * import { setCurrentPageBackground } from "@canva/design";
4572
- * import type { PageBackgroundFill } from "@canva/design";
4573
- *
4574
- * const background: PageBackgroundFill = {
4575
- * color: '#F5F5F5',
4576
- * };
4577
- *
4578
- * await setCurrentPageBackground(background);
4579
- * ```
4580
- *
4581
- * @example Set background image
4582
- * ```typescript
4583
- * import { setCurrentPageBackground } from "@canva/design";
4584
- * import type { PageBackgroundFill } from "@canva/design";
4585
- * import type { ImageRef } from "@canva/asset";
4586
- *
4587
- * const exampleImageRef = "YOUR_IMAGE_REF" as ImageRef;
4588
- *
4589
- * const background: PageBackgroundFill = {
4590
- * asset: {
4591
- * type: 'image',
4592
- * ref: exampleImageRef,
4593
- * altText: { text: 'Background image', decorative: true }
4594
- * },
4595
- * };
4596
- *
4597
- * await setCurrentPageBackground(background);
4598
- * ```
4599
- *
4600
- * @example Set background video
4601
- * ```typescript
4602
- * import { setCurrentPageBackground } from "@canva/design";
4603
- * import type { PageBackgroundFill } from "@canva/design";
4604
- * import type { VideoRef } from "@canva/asset";
4605
- *
4606
- * const exampleVideoRef = "YOUR_VIDEO_REF" as VideoRef;
4607
- *
4608
- * const background: PageBackgroundFill = {
4609
- * asset: {
4610
- * type: 'video',
4611
- * ref: exampleVideoRef,
4612
- * altText: { text: 'Background video', decorative: true }
4613
- * },
4614
- * };
4615
- *
4616
- * await setCurrentPageBackground(background);
4617
- * ```
4618
- */
4619
- export declare const setCurrentPageBackground: (
4620
- opts: PageBackgroundFill,
4621
- ) => Promise<void>;
4622
-
4623
- /**
4624
- * @public
4625
- * An element that renders a vector shape.
4626
- */
4627
- export declare type ShapeElement = {
4628
- /**
4629
- * The type of element.
4630
- */
4631
- type: "shape";
4632
- /**
4633
- * Options for configuring the scale and cropping of the shape.
4634
- */
4635
- viewBox: ShapeViewBox;
4636
- /**
4637
- * The paths that define the structure of the shape.
4638
- *
4639
- * @remarks
4640
- * - There must be between 1 and 30 paths (inclusive).
4641
- * - The maximum combined size of all paths must not exceed 2kb.
4642
- * - The maximum number of unique fill colors across all paths is 6.
4643
- */
4644
- paths: ShapePath[];
4645
- };
4646
-
4647
- /**
4648
- * @public
4649
- * An element that renders a vector shape and has positional properties.
4650
- */
4651
- export declare type ShapeElementAtPoint = ShapeElement &
4652
- Point &
4653
- (WidthAndHeight | Width | Height);
4654
-
4655
- /**
4656
- * @public
4657
- * A path that defines the structure of a shape element.
4658
- */
4659
- export declare type ShapePath = {
4660
- /**
4661
- * The shape of the path.
4662
- *
4663
- * @remarks
4664
- * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
4665
- *
4666
- * - The path must start with an M command.
4667
- * - The path must not have more than one M command.
4668
- * - The path must not use the Q command.
4669
- * - The path must be closed, either by:
4670
- * - Using a Z command at the end of the path
4671
- * - Having the last coordinate match the first coordinate
4672
- */
4673
- d: string;
4674
- /**
4675
- * The appearance of the path's interior.
4676
- */
4677
- fill: Fill;
4678
- /**
4679
- * The outline of the path.
4680
- */
4681
- stroke?: PathStroke;
4682
- };
4683
-
4684
- /**
4685
- * @public
4686
- * Options for configuring the scale and cropping of a shape.
4687
- *
4688
- * @remarks
4689
- * This is similar to the `viewBox` attribute of an `SVGElement`.
4690
- */
4691
- export declare type ShapeViewBox = {
4692
- /**
4693
- * The distance of the shape from the top edge of the element, in pixels.
4694
- */
4695
- top: number;
4696
- /**
4697
- * The distance of the shape from the left edge of the element, in pixels.
4698
- */
4699
- left: number;
4700
- /**
4701
- * The width of the view box, in pixels.
4702
- */
4703
- width: number;
4704
- /**
4705
- * The height of the view box, in pixels.
4706
- */
4707
- height: number;
4708
- };
4709
-
4710
- /**
4711
- * @public
4712
- * An element that renders a table.
4713
- */
4714
- export declare type TableElement = {
4715
- /**
4716
- * The type of element.
4717
- */
4718
- type: "table";
4719
- /**
4720
- * The rows of the table.
4721
- */
4722
- rows: {
4723
- /**
4724
- * The cells (columns) of the row.
4725
- *
4726
- * @remarks
4727
- * Each row must have the same number of cells.
4728
- */
4729
- cells: (Cell | null | undefined)[];
4730
- }[];
4731
- };
4732
-
4733
- /**
4734
- * @public
4735
- * Options for configuring the appearance of text.
4736
- */
4737
- export declare type TextAttributes = {
4738
- /**
4739
- * The size of the text.
4740
- *
4741
- * @remarks
4742
- * - Minimum: 1
4743
- * - Maximum: 100
4744
- *
4745
- * @defaultValue 16
4746
- */
4747
- fontSize?: number;
4748
- /**
4749
- * The alignment of the text.
4750
- * @defaultValue "start"
4751
- */
4752
- textAlign?: "start" | "center" | "end" | "justify";
4753
- /**
4754
- * The color of the text as a hex code.
4755
- *
4756
- * @remarks
4757
- * The hex code must include all six characters and be prefixed with a `#` symbol.
4758
- *
4759
- * @example
4760
- * "#ff0099"
4761
- */
4762
- color?: string;
4763
- /**
4764
- * @public
4765
- * A unique identifier that points to a font asset in Canva's backend.
4766
- */
4767
- fontRef?: FontRef;
4768
- /**
4769
- * The weight (thickness) of the font.
4770
- * @defaultValue "normal"
4771
- */
4772
- fontWeight?: FontWeight;
4773
- /**
4774
- * The style of the font.
4775
- * @defaultValue "normal"
4776
- */
4777
- fontStyle?: "normal" | "italic";
4778
- /**
4779
- * The decoration of the font.
4780
- * @defaultValue "none"
4781
- */
4782
- decoration?: "none" | "underline";
4783
- };
4784
-
4785
- /**
4786
- * @public
4787
- * The dimensions, position, and rotation of a text element.
4788
- */
4789
- declare type TextBox = Point & {
4790
- /**
4791
- * The width of the element, in pixels.
4792
- *
4793
- * @remarks
4794
- * - Minimum: 0
4795
- * - Maximum: 32767
4796
- */
4797
- width?: number;
4798
- };
4799
-
4800
- /**
4801
- * @public
4802
- * Text element or content to be added to the design at the end of a drag event.
4803
- */
4804
- export declare type TextDragConfig = {
4805
- /**
4806
- * The type of element.
4807
- */
4808
- type: "text";
4809
- /**
4810
- * The text content to drag.
4811
- */
4812
- children?: string[];
4813
- /**
4814
- * The alignment of the text.
4815
- * @defaultValue "start"
4816
- */
4817
- textAlign?: "start" | "center" | "end" | "justify";
4818
- /**
4819
- * The weight (thickness) of the font.
4820
- * @defaultValue "normal"
4821
- */
4822
- fontWeight?: FontWeight;
4823
- /**
4824
- * The style of the font.
4825
- * @defaultValue "normal"
4826
- */
4827
- fontStyle?: "normal" | "italic";
4828
- /**
4829
- * The decoration of the font.
4830
- * @defaultValue "none"
4831
- */
4832
- decoration?: "none" | "underline";
4833
- };
4834
-
4835
- /**
4836
- * @public
4837
- * An element that renders text content.
4838
- */
4839
- export declare type TextElement = {
4840
- /**
4841
- * The type of element.
4842
- */
4843
- type: "text";
4844
- /**
4845
- * The text content.
4846
- *
4847
- * @remarks
4848
- * Only the first element in this array is used.
4849
- */
4850
- children: string[];
4851
- } & TextAttributes;
4852
-
4853
- /**
4854
- * @public
4855
- * An element that renders text content and has positional properties.
4856
- */
4857
- export declare type TextElementAtPoint = TextElement & TextBox;
4858
-
4859
- /**
4860
- * @public
4861
- * A region of richtext.
4862
- */
4863
- export declare type TextRegion = {
4864
- /**
4865
- * The plaintext content of the region.
4866
- */
4867
- text: string;
4868
- /**
4869
- * The formatting of the region.
4870
- */
4871
- formatting?: Partial<RichtextFormatting>;
4872
- };
4873
-
4874
- /**
4875
- * @public
4876
- * Provides methods for adding drag and drop behavior to an app.
4877
- */
4878
- export declare interface UI {
4879
- /**
4880
- * @deprecated The method has been superseded by `startDragToPoint`.
4881
- * @public
4882
- * Adds the specified element or content to a design at the end of a drag event.
4883
- *
4884
- * @param event - A drag start event.
4885
- * @param dragData - Element or content to be added to the design at the end of the drag event.
4886
- */
4887
- startDrag<E extends Element>(
4888
- event: DragStartEvent<E>,
4889
- dragData:
4890
- | TextDragConfig
4891
- | AudioDragConfig
4892
- | EmbedDragConfig
4893
- | VideoDragConfigForElement<E>
4894
- | ImageDragConfigForElement<E>,
4895
- ): Promise<void>;
4896
- /**
4897
- * @public
4898
- * Adds the specified element or content to fixed designs, which use a coordinate-based positioning system at the end of a drag event.
4899
- *
4900
- * @param event - A drag start event.
4901
- * @param dragData - Element or content to be added to the design at the end of the drag event.
4902
- */
4903
- startDragToPoint<E extends Element>(
4904
- event: DragStartEvent<E>,
4905
- dragData:
4906
- | TextDragConfig
4907
- | AudioDragConfig
4908
- | EmbedDragConfig
4909
- | VideoDragConfigForElement<E>
4910
- | ImageDragConfigForElement<E>,
4911
- ): Promise<void>;
4912
- /**
4913
- * @public
4914
- * Adds the specified element or content to responsive documents, which slot things into a text stream at the end of a drag event.
4915
- *
4916
- * @param event - A drag start event.
4917
- * @param dragData - Element or content to be added to the design at the end of the drag event.
4918
- */
4919
- startDragToCursor<E extends Element>(
4920
- event: DragStartEvent<E>,
4921
- dragData:
4922
- | EmbedDragConfig
4923
- | VideoDragConfigForElement<E>
4924
- | ImageDragConfigForElement<E>,
4925
- ): Promise<void>;
4926
- }
4927
-
4928
- /**
4929
- * An alias for the UI interface, providing access to ui related functionality
4930
- * @public
4931
- */
4932
- export declare const ui: UI;
4933
-
4934
- /**
4935
- * @public
4936
- * A data type that can be used in app element data.
4937
- */
4938
- export declare type Value =
4939
- | Primitive
4940
- | ObjectPrimitive
4941
- | Exclude<Value, undefined>[]
4942
- | {
4943
- [key: string]: Value;
4944
- };
4945
-
4946
- /**
4947
- * @public
4948
- * Video element or content to be added to the design at the end of a drag event.
4949
- */
4950
- export declare type VideoDragConfig = {
4951
- /**
4952
- * The type of element.
4953
- */
4954
- type: "video";
4955
- /**
4956
- * A function that returns a reference (ref) to a video asset in Canva's backend.
4957
- */
4958
- resolveVideoRef: () => Promise<{
4959
- ref: VideoRef;
4960
- }>;
4961
- /**
4962
- * The dimensions of the preview image.
4963
- */
4964
- previewSize: Dimensions;
4965
- /**
4966
- * The dimensions of the full-size video.
4967
- *
4968
- * @remarks
4969
- * - These dimensions are used when adding the video to the design
4970
- * - If omitted, the `previewSize` dimensions are used as a fallback.
4971
- */
4972
- fullSize?: Dimensions;
4973
- /**
4974
- * The URL of an image to display under the user's cursor during the drag and drop event.
4975
- */
4976
- previewUrl: string;
4977
- };
4978
-
4979
- /**
4980
- * @public
4981
- * Video element or content to be added to the design at the end of a drag event.
4982
- */
4983
- export declare type VideoDragConfigForElement<E extends Element> =
4984
- E extends HTMLImageElement
4985
- ? Partial<VideoDragConfig> &
4986
- Pick<VideoDragConfig, "type" | "resolveVideoRef">
4987
- : VideoDragConfig;
4988
-
4989
- /**
4990
- * @public
4991
- * An element that renders video content.
4992
- */
4993
- export declare type VideoElement = {
4994
- /**
4995
- * The type of element.
4996
- */
4997
- type: "video";
4998
- /**
4999
- * A unique identifier that points to a video asset in Canva's backend.
5000
- */
5001
- ref: VideoRef;
5002
- /**
5003
- * A description of the video content.
5004
- *
5005
- * @remarks
5006
- * Use `undefined` for content with no description.
5007
- */
5008
- altText: AltText | undefined;
5009
- };
5010
-
5011
- /**
5012
- * @public
5013
- * An element that renders video content and has positional properties.
5014
- */
5015
- export declare type VideoElementAtPoint = VideoElement &
5016
- Point &
5017
- (WidthAndHeight | Width | Height);
5018
-
5019
- /**
5020
- * @public
5021
- * A video asset that fills a path's interior.
5022
- */
5023
- export declare type VideoFill = {
5024
- /**
5025
- * The type of fill.
5026
- */
5027
- type: "video";
5028
- /**
5029
- * A unique identifier that points to a video asset in Canva's backend.
5030
- */
5031
- ref: VideoRef;
5032
- /**
5033
- * A description of the image content.
5034
- *
5035
- * @remarks
5036
- * Use `undefined` for content with no description.
5037
- */
5038
- altText?: AltText;
5039
- };
5040
-
5041
- /**
5042
- * @public
5043
- * A unique identifier that references a video asset in Canva's backend.
5044
- */
5045
- export declare type VideoRef = string & {
5046
- __videoRef: never;
5047
- };
5048
-
5049
- /**
5050
- * A set of dimensions with an auto-calculated height.
5051
- */
5052
- declare type Width = {
5053
- /**
5054
- * A width, in pixels.
5055
- *
5056
- * @remarks
5057
- * - The pixels are relative to their container.
5058
- * - Minimum: 0
5059
- * - Maximum: 32767
5060
- */
5061
- width: number;
5062
- /**
5063
- * Indicates that the height should be auto-calculated.
5064
- */
5065
- height: "auto";
5066
- };
5067
-
5068
- /**
5069
- * A set of dimensions, in pixels.
5070
- */
5071
- declare type WidthAndHeight = {
5072
- /**
5073
- * A width, in pixels.
5074
- *
5075
- * @remarks
5076
- * - The pixels are relative to their container.
5077
- * - Minimum: 0
5078
- * - Maximum: 32767
5079
- */
5080
- width: number;
5081
- /**
5082
- * A height, in pixels.
5083
- *
5084
- * @remarks
5085
- * - The pixels are relative to their container.
5086
- * - Minimum: 0
5087
- * - Maximum: 32767
5088
- */
5089
- height: number;
5090
- };
5091
-
5092
- export {};
1
+ export * from "./beta";