@canva/design 2.4.0 → 2.4.1-beta.2

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.
@@ -383,6 +383,730 @@ export declare type Coordinates = {
383
383
  */
384
384
  export declare const createRichtextRange: () => RichtextRange;
385
385
 
386
+ /**
387
+ * @beta
388
+ * Describes a part of a design.
389
+ */
390
+ export declare type DesignContext = DesignContextOptions["type"];
391
+
392
+ /**
393
+ * @beta
394
+ * Options for configuring which part of a design to read.
395
+ */
396
+ declare type DesignContextOptions = {
397
+ /**
398
+ * The type of context.
399
+ */
400
+ type: "current_page";
401
+ };
402
+
403
+ /**
404
+ * @beta
405
+ * Provides methods for reading and updating the structure and content of a design.
406
+ */
407
+ export declare namespace DesignEditing {
408
+ /**
409
+ * @beta
410
+ * A snapshot containing a fragment of a design's structure and content.
411
+ */
412
+ export type DesignDraft<D> = Readonly<D> & {
413
+ /**
414
+ * Saves any changes made to the draft.
415
+ *
416
+ * @remarks
417
+ * - Any changes to the draft are only reflected in the design after this method is called.
418
+ * - Once this method is called, further changes to the draft are not possible.
419
+ */
420
+ save(): Promise<void>;
421
+ };
422
+ /**
423
+ * @beta
424
+ * Options for creating an image fill in the element builder
425
+ */
426
+ export type ImageFillOpts = Partial<ImageFill> &
427
+ Required<Pick<ImageFill, "type" | "imageRef">>;
428
+ /**
429
+ * @beta
430
+ * Options for creating a video fill in the element builder
431
+ */
432
+ export type VideoFillOpts = Partial<VideoFill> &
433
+ Required<Pick<VideoFill, "type" | "videoRef">>;
434
+ /**
435
+ * @beta
436
+ * Options for creating a media fill in the element builder
437
+ */
438
+ export type MediaFillOpts = ImageFillOpts | VideoFillOpts;
439
+ /**
440
+ * @beta
441
+ * Options for creating a fill in the element builder
442
+ */
443
+ export type FillOpts =
444
+ | {
445
+ color: ColorFillOpts;
446
+ media?: MediaFillOpts;
447
+ }
448
+ | {
449
+ color?: ColorFillOpts;
450
+ media: MediaFillOpts;
451
+ };
452
+ /**
453
+ * @beta
454
+ */
455
+ export type ColorFillOpts = Exclude<ColorFill, Unsupported>;
456
+ /**
457
+ * @beta
458
+ * Options for creating a stroke in the element builder
459
+ */
460
+ export type StrokeOpts = Pick<Stroke, "weight"> & {
461
+ color: ColorFillOpts;
462
+ };
463
+ /**
464
+ * @beta
465
+ * Options for creating a shape path in the element builder
466
+ */
467
+ export type PathOpts = Pick<Path, "d"> & {
468
+ fill?: FillOpts;
469
+ stroke?: StrokeOpts;
470
+ };
471
+ /**
472
+ * @beta
473
+ * Options for creating a rect element.
474
+ */
475
+ export type CreateRectElementOpts = Required<
476
+ Pick<RectElement, "top" | "left" | "width" | "height">
477
+ > & {
478
+ fill?: FillOpts;
479
+ } & {
480
+ stroke?: StrokeOpts;
481
+ } & Partial<Omit<RectElement, "fill" | "stroke" | "type">>;
482
+ /**
483
+ * @beta
484
+ * Options for creating a shape element.
485
+ */
486
+ export type CreateShapeElementOpts = Required<
487
+ Pick<ShapeElement, "top" | "left" | "width" | "height" | "viewBox">
488
+ > & {
489
+ paths: PathOpts[];
490
+ } & Partial<Omit<ShapeElement, "type" | "paths">>;
491
+ /**
492
+ * @beta
493
+ * Options for creating an embed element.
494
+ */
495
+ export type CreateEmbedElementOpts = Required<
496
+ Pick<EmbedElement, "top" | "left" | "width" | "height" | "url">
497
+ > &
498
+ Partial<Omit<EmbedElement, "type">>;
499
+ /**
500
+ * @beta
501
+ * Options for creating a text element.
502
+ */
503
+ export type CreateTextElementOpts = Required<
504
+ Pick<TextElement, "top" | "left" | "width" | "text">
505
+ > &
506
+ Partial<Omit<TextElement, "type" | "height">>;
507
+ /**
508
+ * @beta
509
+ * Provides methods for creating elements.
510
+ *
511
+ * @remarks
512
+ * These methods don't add the elements to the design. They only return elements that can
513
+ * be added to a design, such as with the `insertAfter` method.
514
+ */
515
+ export interface ElementBuilder {
516
+ /**
517
+ * Creates a rect element.
518
+ * @param opts - Options for creating the rect element.
519
+ */
520
+ createRectElement(opts: CreateRectElementOpts): RectElement;
521
+ /**
522
+ * Creates a shape element.
523
+ * @param opts - Options for creating the shape element.
524
+ */
525
+ createShapeElement(opts: CreateShapeElementOpts): ShapeElement;
526
+ /**
527
+ * Creates an embed element.
528
+ * @param opts - Options for creating the embed element.
529
+ */
530
+ createEmbedElement(opts: CreateEmbedElementOpts): EmbedElement;
531
+ /**
532
+ * Creates a text element.
533
+ * @param opts - Options for creating the text element.
534
+ */
535
+ createTextElement(opts: CreateTextElementOpts): TextElement;
536
+ /**
537
+ * Creates a richtext range.
538
+ */
539
+ createRichtextRange(): RichtextRange;
540
+ /**
541
+ * Creates a clone of an element.
542
+ * @returns a new element with the same properties as the argument.
543
+ */
544
+ cloneElement(element: RectElement): RectElement;
545
+ cloneElement(element: ShapeElement): ShapeElement;
546
+ cloneElement(element: EmbedElement): EmbedElement;
547
+ cloneElement(element: TextElement): TextElement;
548
+ cloneElement(
549
+ element: RectElement | ShapeElement | EmbedElement | TextElement,
550
+ ): RectElement | ShapeElement | EmbedElement | TextElement;
551
+ }
552
+ /**
553
+ * @beta
554
+ * The result of reading part of a design when the context is the current page.
555
+ */
556
+ export type CurrentPageResult = DesignDraft<{
557
+ /**
558
+ * The current page of the design.
559
+ */
560
+ page: FixedPage;
561
+ }>;
562
+ /**
563
+ * @beta
564
+ * The result of reading part of a design.
565
+ */
566
+ export type DesignOpenResult = CurrentPageResult;
567
+ /**
568
+ * A function called for each item in the list.
569
+ *
570
+ * @param item - The current item in the list.
571
+ * @param index - The index of the current item.
572
+ */
573
+ export type ForEachCallback<T> = (item: T, index: number) => void;
574
+ /**
575
+ * A function that determines if an item should be included in the result.
576
+ *
577
+ * @param item - The item to test.
578
+ * @returns `true` if the item should be included, otherwise `false`.
579
+ */
580
+ export type FilterPredicate<T> = (item: T) => boolean;
581
+ /**
582
+ * A type predicate function that determines if an item is of a specific type.
583
+ *
584
+ * @param item - The item to test.
585
+ * @returns `true` if the item is of type `C`, otherwise `false`.
586
+ */
587
+ export type TypeFilterPredicate<T, C extends T> = (item: T) => item is C;
588
+ /**
589
+ * A list that cannot be changed.
590
+ */
591
+ export interface ReadableList<T> {
592
+ /**
593
+ * Gets the number of items in the list.
594
+ *
595
+ * @returns The number of items.
596
+ */
597
+ count(): number;
598
+ /**
599
+ * Converts the list to an array.
600
+ *
601
+ * @returns An array containing all items. The items are the same as in the list.
602
+ */
603
+ toArray(): readonly T[];
604
+ /**
605
+ * Executes a function for each item in the list.
606
+ *
607
+ * @param callback - The function to run for each item.
608
+ */
609
+ forEach(callback: ForEachCallback<T>): void;
610
+ /**
611
+ * Creates a new array with items that match a specific type.
612
+ *
613
+ * @param filter - A function that checks if an item is of type `C`.
614
+ * @returns An array of items that are of type `C`.
615
+ */
616
+ filter<C extends T>(filter: TypeFilterPredicate<T, C>): readonly C[];
617
+ /**
618
+ * Creates a new array with items that pass a test.
619
+ *
620
+ * @param filter - A function that tests each item. Returns `true` to keep the item.
621
+ * @returns An array of items that passed the test.
622
+ */
623
+ filter(filter: FilterPredicate<T>): readonly T[];
624
+ }
625
+ /**
626
+ * @beta
627
+ * A list of items that can be changed.
628
+ */
629
+ export interface MutableList<T> {
630
+ /**
631
+ * Adds a copy of an item to the list and places it right before another item.
632
+ *
633
+ * @param ref - The existing item to place the new item before.
634
+ * If `ref` is `undefined`, the new item is added at the end of the list.
635
+ * If `ref` does not exist in the list, the operation fails.
636
+ *
637
+ * @param item - The item to add. A copy of this item will be inserted.
638
+ *
639
+ * @returns
640
+ * The added item, or `undefined` if the operation failed.
641
+ */
642
+ insertBefore(ref: T | undefined, item: T): T | undefined;
643
+ /**
644
+ * Adds a copy of an item to the list and places it right after another item.
645
+ *
646
+ * @param ref - The existing item to place the new item after.
647
+ * If `ref` is `undefined`, the new item is added at the end of the list.
648
+ * If `ref` does not exist in the list, the operation fails.
649
+ *
650
+ * @param item - The item to add. A copy of this item will be inserted.
651
+ *
652
+ * @returns
653
+ * The added item, or `undefined` if the operation failed.
654
+ */
655
+ insertAfter(ref: T | undefined, item: T): T | undefined;
656
+ /**
657
+ * Moves an existing item to a new position right before another item.
658
+ *
659
+ * @param ref - The existing item to move the item before.
660
+ * If `ref` is `undefined`, the item is moved to the end of the list.
661
+ * If `ref` does not exist in the list, the operation fails.
662
+ *
663
+ * @param item - The item to move.
664
+ * The operation fails if the item is not already in the list.
665
+ */
666
+ moveBefore(ref: T | undefined, item: T): void;
667
+ /**
668
+ * Moves an existing item to a new position right after another item.
669
+ *
670
+ * @param ref - The existing item to move the item after.
671
+ * If `ref` is `undefined`, the item is moved to the end of the list.
672
+ * If `ref` does not exist in the list, the operation fails.
673
+ *
674
+ * @param item - The item to move.
675
+ * The operation fails if the item is not already in the list.
676
+ */
677
+ moveAfter(ref: T | undefined, item: T): void;
678
+ /**
679
+ * Removes an item from the list.
680
+ *
681
+ * @param item - The item to remove from the list.
682
+ */
683
+ delete(item: T): void;
684
+ }
685
+ /**
686
+ * @beta
687
+ * A list of items that can be read and updated.
688
+ */
689
+ export interface List<T> extends ReadableList<T>, MutableList<T> {}
690
+ /**
691
+ * @beta
692
+ * Represents an element that's not supported by the Apps SDK.
693
+ */
694
+ export interface Unsupported {
695
+ /**
696
+ * The type of element.
697
+ */
698
+ readonly type: "unsupported";
699
+ }
700
+ /**
701
+ * @beta
702
+ * A single valid character in a hex code.
703
+ */
704
+ export type Hex = `123456790abcdef`[number];
705
+ /**
706
+ * @beta
707
+ * A six-character hexadecimal color code prefixed with a `#`.
708
+ */
709
+ export type HexCode = `#${Hex}${Hex}${Hex}${Hex}${Hex}${Hex}`;
710
+ /**
711
+ * @beta
712
+ * A set of dimensions.
713
+ */
714
+ export interface Dimensions {
715
+ /**
716
+ * A width, in pixels.
717
+ */
718
+ readonly width: number;
719
+ /**
720
+ * A height, in pixels.
721
+ */
722
+ readonly height: number;
723
+ }
724
+ /**
725
+ * @beta
726
+ * An image that fills the interior of a path.
727
+ */
728
+ export interface ImageFill {
729
+ /**
730
+ * The type of media.
731
+ */
732
+ readonly type: "image";
733
+ /**
734
+ * A unique identifier that points to an image asset in Canva's backend.
735
+ */
736
+ imageRef: ImageRef;
737
+ /**
738
+ * If `true`, the image is flipped horizontally.
739
+ */
740
+ flipX: boolean;
741
+ /**
742
+ * If `true`, the image is flipped vertically.
743
+ */
744
+ flipY: boolean;
745
+ }
746
+ /**
747
+ * @beta
748
+ * A video that fills the interior of a path.
749
+ */
750
+ export interface VideoFill {
751
+ /**
752
+ * The type of media.
753
+ */
754
+ readonly type: "video";
755
+ /**
756
+ * A unique identifier that points to a video asset in Canva's backend.
757
+ */
758
+ videoRef: VideoRef;
759
+ /**
760
+ * If `true`, the video is flipped horizontally.
761
+ */
762
+ flipX: boolean;
763
+ /**
764
+ * If `true`, the video is flipped vertically.
765
+ */
766
+ flipY: boolean;
767
+ }
768
+ /**
769
+ * @beta
770
+ * A media item that fills the interior of a path.
771
+ */
772
+ export type MediaFill = ImageFill | VideoFill;
773
+ /**
774
+ * @beta
775
+ * A solid color that fills the interior of a path.
776
+ */
777
+ export interface SolidFill {
778
+ /**
779
+ * The type of color.
780
+ */
781
+ readonly type: "solid";
782
+ /**
783
+ * The color of the fill, as a hex code.
784
+ *
785
+ * @remarks
786
+ * - Must be six characters long.
787
+ * - Must start with a `#`.
788
+ * - Must use lowercase letters.
789
+ */
790
+ color: HexCode;
791
+ }
792
+ /**
793
+ * @beta
794
+ * A color that fills the interior of a path.
795
+ */
796
+ export type ColorFill = SolidFill | Unsupported;
797
+ /**
798
+ * @beta
799
+ * Describes how a path is filled with color or media.
800
+ *
801
+ * @remarks
802
+ * If both `media` and `color` are defined, `media` takes precedence.
803
+ */
804
+ export interface Fill {
805
+ /**
806
+ * The media fill for the path, if any.
807
+ */
808
+ media: MediaFill | undefined;
809
+ /**
810
+ * The color fill for the path, if any.
811
+ */
812
+ color: ColorFill | undefined;
813
+ }
814
+ /**
815
+ * @beta
816
+ * The scale and cropping of a shape.
817
+ *
818
+ * @remarks
819
+ * This is similar to the `viewBox` attribute of an `SVGElement`.
820
+ */
821
+ export type AlignedBox = {
822
+ /**
823
+ * The distance of the shape from the top edge of the element, in pixels.
824
+ */
825
+ readonly top: number;
826
+ /**
827
+ * The distance of the shape from the left edge of the element, in pixels.
828
+ */
829
+ readonly left: number;
830
+ /**
831
+ * The width of the view box, in pixels.
832
+ */
833
+ readonly width: number;
834
+ /**
835
+ * The height of the view box, in pixels.
836
+ */
837
+ readonly height: number;
838
+ };
839
+ /**
840
+ * @beta
841
+ * A path that defines the structure of a shape element.
842
+ */
843
+ export interface Path {
844
+ /**
845
+ * The shape of the path.
846
+ *
847
+ * @remarks
848
+ * This is similar to the `d` attribute of an SVG's `path` element, with some limitations:
849
+ *
850
+ * - Must start with an `M` command.
851
+ * - Only one `M` command is allowed.
852
+ * - `Q` and `T` commands are not permitted.
853
+ * - The path must be closed using a `Z` command or matching start and end coordinates.
854
+ */
855
+ readonly d: string;
856
+ /**
857
+ * The appearance of the path's interior.
858
+ */
859
+ readonly fill: Fill;
860
+ /**
861
+ * The stroke (outline) of the path, if any.
862
+ */
863
+ readonly stroke: Stroke | undefined;
864
+ }
865
+ /**
866
+ * @beta
867
+ * Represents an outline, such as the border of an element.
868
+ */
869
+ export interface Stroke {
870
+ /**
871
+ * The weight (thickness) of the stroke.
872
+ *
873
+ * @remarks
874
+ * - Minimum: 0
875
+ * - Maximum: 100
876
+ */
877
+ weight: number;
878
+ /**
879
+ * The color of the stroke.
880
+ */
881
+ color: ColorFill;
882
+ }
883
+ /**
884
+ * @beta
885
+ * The basic properties of an element.
886
+ *
887
+ * @remarks
888
+ * These properties are shared by all elements in a design.
889
+ */
890
+ export interface Element extends Dimensions {
891
+ /**
892
+ * If `true`, the element is locked and cannot be modified.
893
+ */
894
+ readonly locked: boolean;
895
+ /**
896
+ * The distance from the top edge of the container, in pixels.
897
+ *
898
+ * @remarks
899
+ * - The pixels are relative to their container.
900
+ * - Minimum: -32768
901
+ * - Maximum: 32767
902
+ */
903
+ top: number;
904
+ /**
905
+ * The distance from the left edge of the container, in pixels.
906
+ *
907
+ * @remarks
908
+ * - The pixels are relative to their container.
909
+ * - Minimum: -32768
910
+ * - Maximum: 32767
911
+ */
912
+ left: number;
913
+ /**
914
+ * A rotation, in degrees.
915
+ *
916
+ * @remarks
917
+ * - Minimum: -180
918
+ * - Maximum: 180
919
+ */
920
+ rotation: number;
921
+ /**
922
+ * Transparency as a percentage.
923
+ *
924
+ * @remarks
925
+ * - Minimum: 0
926
+ * - Maximum: 1
927
+ */
928
+ transparency: number;
929
+ }
930
+ /**
931
+ * @beta
932
+ * Represents a rectangular element.
933
+ */
934
+ export interface Rect {
935
+ /**
936
+ * The type of content.
937
+ */
938
+ readonly type: "rect";
939
+ /**
940
+ * The appearance of the rectangle's interior.
941
+ */
942
+ readonly fill: Fill;
943
+ /**
944
+ * The outline of the rectangle.
945
+ */
946
+ readonly stroke: Stroke;
947
+ }
948
+ /**
949
+ * @beta
950
+ * Represents a vector shape element.
951
+ */
952
+ export interface Shape {
953
+ /**
954
+ * The type of content.
955
+ */
956
+ readonly type: "shape";
957
+ /**
958
+ * The scale and cropping of the shape.
959
+ */
960
+ viewBox: AlignedBox;
961
+ /**
962
+ * The paths that define the structure of the shape.
963
+ *
964
+ * @remarks
965
+ * - Must have between 1 and 30 paths.
966
+ * - Total size of all paths must not exceed 2kb.
967
+ * - Maximum of 6 unique fill colors across all paths.
968
+ */
969
+ readonly paths: ReadableList<Path>;
970
+ }
971
+ /**
972
+ * @beta
973
+ * Represents group content.
974
+ */
975
+ export interface Group<C> {
976
+ /**
977
+ * The type of content.
978
+ */
979
+ readonly type: "group";
980
+ /**
981
+ * The elements that exist within the group.
982
+ */
983
+ readonly contents: ReadableList<C>;
984
+ }
985
+ /**
986
+ * @beta
987
+ * Represents rich media content.
988
+ */
989
+ export interface Embed {
990
+ /**
991
+ * The type of content.
992
+ */
993
+ readonly type: "embed";
994
+ /**
995
+ * The URL of the rich media.
996
+ *
997
+ * @remarks
998
+ * This URL must be supported by the Iframely API.
999
+ */
1000
+ readonly url: string;
1001
+ }
1002
+ /**
1003
+ * @beta
1004
+ * Represents text content.
1005
+ */
1006
+ export interface Text {
1007
+ /**
1008
+ * The type of content.
1009
+ */
1010
+ readonly type: "text";
1011
+ /**
1012
+ * The text content.
1013
+ */
1014
+ readonly text: RichtextRange;
1015
+ }
1016
+ /**
1017
+ * @beta
1018
+ * An element that renders a rectangle.
1019
+ *
1020
+ * @remarks
1021
+ * The rectangle can be filled with image content, video content, or a solid color.
1022
+ */
1023
+ export interface RectElement extends Rect, Element {}
1024
+ /**
1025
+ * @beta
1026
+ * An element that renders a vector shape.
1027
+ */
1028
+ export interface ShapeElement extends Shape, Element {}
1029
+ /**
1030
+ * @beta
1031
+ * An element that renders a group of other elements.
1032
+ */
1033
+ export interface GroupElement extends Group<GroupContentElement>, Element {}
1034
+ /**
1035
+ * @beta
1036
+ * An element that embeds rich media, such as a YouTube video.
1037
+ */
1038
+ export interface EmbedElement extends Embed, Element {}
1039
+ /**
1040
+ * @beta
1041
+ * An element that renders text content.
1042
+ */
1043
+ export interface TextElement extends Text, Element {}
1044
+ /**
1045
+ * @beta
1046
+ * An element that is not supported by the Apps SDK.
1047
+ */
1048
+ export interface UnsupportedElement extends Unsupported, Element {}
1049
+ /**
1050
+ * @beta
1051
+ * An element that can exist in a group element.
1052
+ */
1053
+ export type GroupContentElement =
1054
+ | RectElement
1055
+ | ShapeElement
1056
+ | EmbedElement
1057
+ | TextElement
1058
+ | UnsupportedElement;
1059
+ /**
1060
+ * @beta
1061
+ * An element that can exist on a fixed page.
1062
+ */
1063
+ export type FixedElement =
1064
+ | RectElement
1065
+ | ShapeElement
1066
+ | GroupElement
1067
+ | EmbedElement
1068
+ | TextElement
1069
+ | UnsupportedElement;
1070
+ /**
1071
+ * @beta
1072
+ * A page with fixed dimensions.
1073
+ */
1074
+ export interface FixedPage {
1075
+ /**
1076
+ * The type of page.
1077
+ */
1078
+ readonly type: "fixed";
1079
+ /**
1080
+ * If `true`, the page is locked and cannot be modified.
1081
+ */
1082
+ readonly locked: boolean;
1083
+ /**
1084
+ * The dimensions of the page. `dimensions` is undefined for whiteboard pages.
1085
+ */
1086
+ readonly dimensions: Dimensions | undefined;
1087
+ /**
1088
+ * The background of the page. `background` is undefined for whiteboard pages.
1089
+ */
1090
+ readonly background: Fill | undefined;
1091
+ /**
1092
+ * The elements on the page.
1093
+ *
1094
+ * @remarks
1095
+ * Elements are rendered in the order they appear in the list.
1096
+ * Later elements appear on top of earlier ones.
1097
+ */
1098
+ readonly elements: List<FixedElement>;
1099
+ }
1100
+ /**
1101
+ * @beta
1102
+ * A page in a design.
1103
+ */
1104
+ export type Page = FixedPage | Unsupported;
1105
+
1106
+ {
1107
+ }
1108
+ }
1109
+
386
1110
  /**
387
1111
  * @public
388
1112
  * An element that's natively supported by the Canva editor.
@@ -397,6 +1121,62 @@ export declare type DesignElement =
397
1121
  | RichtextElement
398
1122
  | TableElement;
399
1123
 
1124
+ /**
1125
+ * @beta
1126
+ * Information about the design.
1127
+ */
1128
+ export declare type DesignMetadata = {
1129
+ /**
1130
+ * The title of the user's design.
1131
+ * @remarks
1132
+ * This is optional and will be `undefined` if the user hasn't set a title.
1133
+ */
1134
+ title?: string;
1135
+ /**
1136
+ * The default dimensions that a new page will have when it is added to a design.
1137
+ * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
1138
+ * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
1139
+ * design that is applied whenever a new page is created.
1140
+ * @remarks
1141
+ * This is optional and will be `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
1142
+ */
1143
+ defaultPageDimensions?: PageDimensions;
1144
+ /**
1145
+ * The information associated with each page of the design.
1146
+ * @remarks
1147
+ * The order of pages is not guaranteed.
1148
+ */
1149
+ pageMetadata: Iterable<PageContext>;
1150
+ /**
1151
+ * The duration of the whole design in seconds.
1152
+ * @remarks
1153
+ * This is the precise value, which differs from what is displayed in the UI as duration in Canva UI is formatted differently.
1154
+ */
1155
+ durationInSeconds: number;
1156
+ };
1157
+
1158
+ /**
1159
+ * @beta
1160
+ * A callback for reading and updating part of a design.
1161
+ * @param draft - The result of reading part of a design.
1162
+ * @param helpers - Helper methods for reading and updating the design.
1163
+ */
1164
+ export declare type DesignOpenCallback = (
1165
+ draft: DesignEditing.DesignOpenResult,
1166
+ helpers: {
1167
+ /**
1168
+ * Provides methods for creating elements.
1169
+ */
1170
+ elementBuilder: DesignEditing.ElementBuilder;
1171
+ },
1172
+ ) => Promise<void> | void;
1173
+
1174
+ /**
1175
+ * @beta
1176
+ * Options for configuring which part of a design to read.
1177
+ */
1178
+ export declare type DesignOpenOptions = DesignContextOptions;
1179
+
400
1180
  /**
401
1181
  * @public
402
1182
  * Provides methods for managing the lifecycle of overlays, such as selected image overlays.
@@ -797,6 +1577,12 @@ export declare const getDefaultPageDimensions: () => Promise<
797
1577
  Dimensions | undefined
798
1578
  >;
799
1579
 
1580
+ /**
1581
+ * @beta
1582
+ * Retrieves information about the design.
1583
+ */
1584
+ export declare const getDesignMetadata: () => Promise<DesignMetadata>;
1585
+
800
1586
  /**
801
1587
  * @public
802
1588
  * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
@@ -1137,6 +1923,23 @@ export declare type NativeVideoElementWithBox = VideoElementAtPoint;
1137
1923
  */
1138
1924
  declare type ObjectPrimitive = Boolean | String;
1139
1925
 
1926
+ /**
1927
+ * @beta
1928
+ * Reads a specified part of the user's design and returns all elements in that part.
1929
+ *
1930
+ * @param options - Options for configuring how the design is read.
1931
+ * @param callback - A callback for operating on the design.
1932
+ */
1933
+ export declare const openDesign: (
1934
+ options: DesignOpenOptions,
1935
+ callback: (
1936
+ draft: DesignEditing.DesignOpenResult,
1937
+ helpers: {
1938
+ elementBuilder: DesignEditing.ElementBuilder;
1939
+ },
1940
+ ) => Promise<void> | void,
1941
+ ) => Promise<void>;
1942
+
1140
1943
  /**
1141
1944
  * @public
1142
1945
  * An alias for the DesignOverlay interface, providing access to design overlay related functionality
@@ -1169,7 +1972,7 @@ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
1169
1972
  * @remarks
1170
1973
  * This can be any type of structured data.
1171
1974
  */
1172
- launchParameters?: any;
1975
+ launchParameters?: unknown;
1173
1976
  }) => Promise<AppProcessId>;
1174
1977
  };
1175
1978
  }[Target];
@@ -1797,6 +2600,11 @@ export declare type TextDragConfig = {
1797
2600
  * @defaultValue "none"
1798
2601
  */
1799
2602
  decoration?: "none" | "underline";
2603
+ /**
2604
+ * @beta
2605
+ * A unique identifier that points to a font asset in Canva's backend.
2606
+ */
2607
+ fontRef?: FontRef;
1800
2608
  };
1801
2609
 
1802
2610
  /**
@@ -1851,7 +2659,7 @@ export declare interface UI {
1851
2659
  * @param event - A drag start event.
1852
2660
  * @param dragData - Element or content to be added to the design at the end of the drag event.
1853
2661
  */
1854
- startDrag<E extends HTMLElement>(
2662
+ startDrag<E extends Element>(
1855
2663
  event: DragStartEvent<E>,
1856
2664
  dragData:
1857
2665
  | TextDragConfig
@@ -1867,7 +2675,7 @@ export declare interface UI {
1867
2675
  * @param event - A drag start event.
1868
2676
  * @param dragData - Element or content to be added to the design at the end of the drag event.
1869
2677
  */
1870
- startDragToPoint<E extends HTMLElement>(
2678
+ startDragToPoint<E extends Element>(
1871
2679
  event: DragStartEvent<E>,
1872
2680
  dragData:
1873
2681
  | TextDragConfig
@@ -1883,7 +2691,7 @@ export declare interface UI {
1883
2691
  * @param event - A drag start event.
1884
2692
  * @param dragData - Element or content to be added to the design at the end of the drag event.
1885
2693
  */
1886
- startDragToCursor<E extends HTMLElement>(
2694
+ startDragToCursor<E extends Element>(
1887
2695
  event: DragStartEvent<E>,
1888
2696
  dragData:
1889
2697
  | EmbedDragConfig
@@ -1,7 +1,21 @@
1
- "use strict"
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getDesignMetadata: function() {
13
+ return getDesignMetadata;
14
+ },
15
+ openDesign: function() {
16
+ return openDesign;
17
+ }
18
+ });
5
19
  _export_star(require("./public"), exports);
6
20
  function _export_star(from, to) {
7
21
  Object.keys(from).forEach(function(k) {
@@ -17,4 +31,7 @@ function _export_star(from, to) {
17
31
  return from;
18
32
  }
19
33
  var _window___canva___sdkRegistration, _window___canva__;
20
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('design', '2.4.0', 'ga');
34
+ const { canva_sdk } = window;
35
+ const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
36
+ const getDesignMetadata = canva_sdk.design.v2.designInteraction.getDesignMetadata;
37
+ (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('design', '2.5.0', 'beta');
@@ -9,12 +9,44 @@ Object.defineProperty(exports, "FakeDesignInteractionClient", {
9
9
  }
10
10
  });
11
11
  class FakeDesignInteractionClient {
12
+ async getDesignTitle() {
13
+ await this.delay();
14
+ return 'title';
15
+ }
12
16
  async getDesignToken() {
13
17
  await this.delay();
14
18
  return {
15
19
  token: 'token'
16
20
  };
17
21
  }
22
+ async getDesignMetadata() {
23
+ await this.delay();
24
+ return {
25
+ title: 'title',
26
+ defaultPageDimensions: {
27
+ width: 800,
28
+ height: 600
29
+ },
30
+ pageMetadata: [
31
+ {
32
+ dimensions: {
33
+ width: 800,
34
+ height: 600
35
+ }
36
+ },
37
+ {
38
+ dimensions: {
39
+ width: 300,
40
+ height: 900
41
+ }
42
+ },
43
+ {
44
+ dimensions: undefined
45
+ }
46
+ ],
47
+ durationInSeconds: 30
48
+ };
49
+ }
18
50
  async addNativeElement(element) {
19
51
  await this.delay();
20
52
  }
@@ -90,6 +122,9 @@ class FakeDesignInteractionClient {
90
122
  elementBuilder: fakeElementBuilder
91
123
  });
92
124
  }
125
+ async openDesign2(options, callback) {
126
+ throw new Error('Not yet implemented');
127
+ }
93
128
  constructor(delay){
94
129
  this.delay = delay;
95
130
  this.selection = {
@@ -0,0 +1,18 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./index"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -12,6 +12,9 @@ _export(exports, {
12
12
  assertIsTestCanvaSdk: function() {
13
13
  return assertIsTestCanvaSdk;
14
14
  },
15
+ bindMethodsToClients: function() {
16
+ return bindMethodsToClients;
17
+ },
15
18
  getCanvaSdk: function() {
16
19
  return getCanvaSdk;
17
20
  },
@@ -34,8 +37,29 @@ function assertIsTestCanvaSdk() {
34
37
  }
35
38
  }
36
39
  function injectFakeAPIClients(clients) {
40
+ bindMethodsToClients(clients);
37
41
  window.canva_sdk = {
38
42
  ...getCanvaSdk(),
39
43
  ...clients
40
44
  };
41
45
  }
46
+ function bindMethodsToClients(objectToBind) {
47
+ if (typeof objectToBind !== 'object' || objectToBind == null)
48
+ return;
49
+ const classMethods = new Set();
50
+ let currentPrototype = Object.getPrototypeOf(objectToBind);
51
+ while(currentPrototype && currentPrototype !== Object.prototype){
52
+ Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
53
+ currentPrototype = Object.getPrototypeOf(currentPrototype);
54
+ }
55
+ classMethods.delete('constructor');
56
+ for (const method of classMethods) {
57
+ const originalFn = objectToBind[method];
58
+ if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
59
+ value: (...args)=>{
60
+ return originalFn.call(objectToBind, ...args);
61
+ }
62
+ });
63
+ }
64
+ Object.values(objectToBind).forEach(bindMethodsToClients);
65
+ }
@@ -1,3 +1,6 @@
1
1
  var _window___canva___sdkRegistration, _window___canva__;
2
+ const { canva_sdk } = window;
3
+ export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
4
+ export const getDesignMetadata = canva_sdk.design.v2.designInteraction.getDesignMetadata;
2
5
  export * from './public';
3
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('design', '2.4.0', 'ga');
6
+ (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('design', '2.5.0', 'beta');
@@ -1,10 +1,42 @@
1
1
  export class FakeDesignInteractionClient {
2
+ async getDesignTitle() {
3
+ await this.delay();
4
+ return 'title';
5
+ }
2
6
  async getDesignToken() {
3
7
  await this.delay();
4
8
  return {
5
9
  token: 'token'
6
10
  };
7
11
  }
12
+ async getDesignMetadata() {
13
+ await this.delay();
14
+ return {
15
+ title: 'title',
16
+ defaultPageDimensions: {
17
+ width: 800,
18
+ height: 600
19
+ },
20
+ pageMetadata: [
21
+ {
22
+ dimensions: {
23
+ width: 800,
24
+ height: 600
25
+ }
26
+ },
27
+ {
28
+ dimensions: {
29
+ width: 300,
30
+ height: 900
31
+ }
32
+ },
33
+ {
34
+ dimensions: undefined
35
+ }
36
+ ],
37
+ durationInSeconds: 30
38
+ };
39
+ }
8
40
  async addNativeElement(element) {
9
41
  await this.delay();
10
42
  }
@@ -80,6 +112,9 @@ export class FakeDesignInteractionClient {
80
112
  elementBuilder: fakeElementBuilder
81
113
  });
82
114
  }
115
+ async openDesign2(options, callback) {
116
+ throw new Error('Not yet implemented');
117
+ }
83
118
  constructor(delay){
84
119
  this.delay = delay;
85
120
  this.selection = {
@@ -0,0 +1 @@
1
+ export * from './index';
@@ -13,8 +13,29 @@ export function assertIsTestCanvaSdk() {
13
13
  }
14
14
  }
15
15
  export function injectFakeAPIClients(clients) {
16
+ bindMethodsToClients(clients);
16
17
  window.canva_sdk = {
17
18
  ...getCanvaSdk(),
18
19
  ...clients
19
20
  };
20
21
  }
22
+ export function bindMethodsToClients(objectToBind) {
23
+ if (typeof objectToBind !== 'object' || objectToBind == null)
24
+ return;
25
+ const classMethods = new Set();
26
+ let currentPrototype = Object.getPrototypeOf(objectToBind);
27
+ while(currentPrototype && currentPrototype !== Object.prototype){
28
+ Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
29
+ currentPrototype = Object.getPrototypeOf(currentPrototype);
30
+ }
31
+ classMethods.delete('constructor');
32
+ for (const method of classMethods) {
33
+ const originalFn = objectToBind[method];
34
+ if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
35
+ value: (...args)=>{
36
+ return originalFn.call(objectToBind, ...args);
37
+ }
38
+ });
39
+ }
40
+ Object.values(objectToBind).forEach(bindMethodsToClients);
41
+ }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "2.4.0",
3
+ "version": "2.4.1-beta.2",
4
4
  "description": "The Canva Apps SDK design library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
7
7
  "peerDependencies": {
8
8
  "@canva/error": "^2.0.0"
9
9
  },
10
- "main": "./lib/cjs/sdk/design/index.js",
11
- "module": "./lib/esm/sdk/design/index.js",
10
+ "main": "./lib/cjs/sdk/design/beta.js",
11
+ "module": "./lib/esm/sdk/design/beta.js",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./index.d.ts",
15
- "require": "./lib/cjs/sdk/design/index.js",
16
- "import": "./lib/esm/sdk/design/index.js"
14
+ "types": "./beta.d.ts",
15
+ "require": "./lib/cjs/sdk/design/beta.js",
16
+ "import": "./lib/esm/sdk/design/beta.js"
17
17
  },
18
18
  "./test": {
19
- "types": "./test/index.d.ts",
20
- "require": "./lib/cjs/sdk/design/test/index.js",
21
- "import": "./lib/esm/sdk/design/test/index.js"
19
+ "types": "./test/beta.d.ts",
20
+ "require": "./lib/cjs/sdk/design/test/beta.js",
21
+ "import": "./lib/esm/sdk/design/test/beta.js"
22
22
  }
23
23
  },
24
- "typings": "./index.d.ts"
25
- }
24
+ "typings": "./beta.d.ts"
25
+ }
File without changes