@canva/design 2.2.0-beta.1 → 2.2.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.
package/beta.d.ts CHANGED
@@ -10,7 +10,7 @@ export declare const addAudioTrack: (audioTrack: AudioTrack) => Promise<void>;
10
10
  * Add element to responsive documents, which slot things into a text stream
11
11
  */
12
12
  export declare const addElementAtCursor: (
13
- element: ElementAtCursor | TableElement
13
+ element: ElementAtCursor,
14
14
  ) => Promise<void>;
15
15
 
16
16
  /**
@@ -18,7 +18,7 @@ export declare const addElementAtCursor: (
18
18
  * Add element to fixed designs, which use a coordinate-based positioning system.
19
19
  */
20
20
  export declare const addElementAtPoint: (
21
- element: DesignElement | ElementAtPoint | TableElement | RichtextElement
21
+ element: DesignElement | ElementAtPoint,
22
22
  ) => Promise<void>;
23
23
 
24
24
  /**
@@ -28,7 +28,7 @@ export declare const addElementAtPoint: (
28
28
  * @param element - The element to add to the user's design.
29
29
  */
30
30
  export declare const addNativeElement: (
31
- element: NativeElement | NativeElementWithBox
31
+ element: NativeElement | NativeElementWithBox,
32
32
  ) => Promise<void>;
33
33
 
34
34
  /**
@@ -88,7 +88,7 @@ export declare type AppElementChangeHandler<A extends AppElementData> = (
88
88
  */
89
89
  version: number;
90
90
  }
91
- | undefined
91
+ | undefined,
92
92
  ) => void;
93
93
 
94
94
  /**
@@ -138,14 +138,14 @@ export declare type AppElementData = Record<string, Value>;
138
138
  * @param appElementData - The data the callback must use to render the app element.
139
139
  */
140
140
  export declare type AppElementRenderer<A extends AppElementData> = (
141
- appElementData: A
141
+ appElementData: A,
142
142
  ) => AppElementRendererOutput;
143
143
 
144
144
  /**
145
145
  * @public
146
146
  * An array of one or more elements to render as output of an app element.
147
147
  */
148
- export declare type AppElementRendererOutput = NativeSimpleElementWithBox[];
148
+ export declare type AppElementRendererOutput = GroupContentAtPoint[];
149
149
 
150
150
  /**
151
151
  * @public
@@ -225,7 +225,7 @@ export declare type Bounds = {
225
225
  * @remarks
226
226
  * The position and dimensions are relative to the container.
227
227
  */
228
- export declare type Box = Position & (WidthAndHeight | Width | Height);
228
+ export declare type Box = Point & (WidthAndHeight | Width | Height);
229
229
 
230
230
  /**
231
231
  * @public
@@ -333,7 +333,7 @@ export declare type ContentType = "richtext";
333
333
  * Options for configuring where content in a design should be queried from.
334
334
  */
335
335
  declare type ContextOptions = {
336
- context: "current_page";
336
+ target: "current_page";
337
337
  };
338
338
 
339
339
  /**
@@ -355,7 +355,7 @@ export declare type Coordinates = {
355
355
  * @public
356
356
  * Creates a new RichtextRange object, which contains methods to manipulate text.
357
357
  */
358
- export declare function createRichtextRange(): RichtextRange;
358
+ export declare const createRichtextRange: () => RichtextRange;
359
359
 
360
360
  /**
361
361
  * @beta
@@ -438,7 +438,7 @@ export declare namespace DesignEditing {
438
438
  * @beta
439
439
  * Options for creating a shape path in the element builder
440
440
  */
441
- export type ShapePathOpts = Pick<Path, "d"> & {
441
+ export type PathOpts = Pick<Path, "d"> & {
442
442
  fill?: FillOpts;
443
443
  stroke?: StrokeOpts;
444
444
  };
@@ -447,7 +447,7 @@ export declare namespace DesignEditing {
447
447
  * Options for creating a rect element.
448
448
  */
449
449
  export type CreateRectElementOpts = Required<
450
- Pick<Element, "top" | "left" | "width" | "height">
450
+ Pick<RectElement, "top" | "left" | "width" | "height">
451
451
  > & {
452
452
  fill?: FillOpts;
453
453
  } & {
@@ -460,12 +460,13 @@ export declare namespace DesignEditing {
460
460
  export type CreateShapeElementOpts = Required<
461
461
  Pick<ShapeElement, "top" | "left" | "width" | "height" | "viewBox">
462
462
  > & {
463
- paths: ShapePathOpts[];
463
+ paths: PathOpts[];
464
464
  } & Partial<Omit<ShapeElement, "type" | "paths">>;
465
465
  /**
466
466
  * @beta
467
467
  * Options for creating an embed element.
468
- */ export type CreateEmbedElementOpts = Required<
468
+ */
469
+ export type CreateEmbedElementOpts = Required<
469
470
  Pick<EmbedElement, "top" | "left" | "width" | "height" | "url">
470
471
  > &
471
472
  Partial<Omit<EmbedElement, "type">>;
@@ -510,6 +511,17 @@ export declare namespace DesignEditing {
510
511
  * Creates a richtext range.
511
512
  */
512
513
  createRichtextRange(): RichtextRange;
514
+ /**
515
+ * Creates a clone of an element.
516
+ * @returns a new element with the same properties as the argument.
517
+ */
518
+ cloneElement(element: RectElement): RectElement;
519
+ cloneElement(element: ShapeElement): ShapeElement;
520
+ cloneElement(element: EmbedElement): EmbedElement;
521
+ cloneElement(element: TextElement): TextElement;
522
+ cloneElement(
523
+ element: RectElement | ShapeElement | EmbedElement | TextElement,
524
+ ): RectElement | ShapeElement | EmbedElement | TextElement;
513
525
  }
514
526
  /**
515
527
  * @beta
@@ -695,7 +707,7 @@ export declare namespace DesignEditing {
695
707
  /**
696
708
  * A unique identifier that points to an image asset in Canva's backend.
697
709
  */
698
- imageRef: string;
710
+ imageRef: ImageRef;
699
711
  /**
700
712
  * If `true`, the image is flipped horizontally.
701
713
  */
@@ -717,7 +729,7 @@ export declare namespace DesignEditing {
717
729
  /**
718
730
  * A unique identifier that points to a video asset in Canva's backend.
719
731
  */
720
- videoRef: string;
732
+ videoRef: VideoRef;
721
733
  /**
722
734
  * If `true`, the video is flipped horizontally.
723
735
  */
@@ -1073,7 +1085,15 @@ export declare namespace DesignEditing {
1073
1085
  * @public
1074
1086
  * An element that's natively supported by the Canva editor.
1075
1087
  */
1076
- export declare type DesignElement = NativeElement;
1088
+ export declare type DesignElement =
1089
+ | ImageElement
1090
+ | VideoElement
1091
+ | EmbedElement
1092
+ | TextElement
1093
+ | ShapeElement
1094
+ | GroupElement
1095
+ | RichtextElement
1096
+ | TableElement;
1077
1097
 
1078
1098
  /**
1079
1099
  * @beta
@@ -1088,7 +1108,7 @@ export declare type DesignOpenCallback = (
1088
1108
  * Provides methods for creating elements.
1089
1109
  */
1090
1110
  elementBuilder: DesignEditing.ElementBuilder;
1091
- }
1111
+ },
1092
1112
  ) => Promise<void> | void;
1093
1113
 
1094
1114
  /**
@@ -1172,29 +1192,6 @@ export declare type Dimensions = {
1172
1192
  height: number;
1173
1193
  };
1174
1194
 
1175
- /**
1176
- * @public
1177
- * Callbacks for handling drag and drop events.
1178
- */
1179
- export declare type DragCallback = {
1180
- /**
1181
- * A callback that runs at the start of a drag event.
1182
- * @param element - The element being dragged.
1183
- */
1184
- onDragStart: (element: HTMLElement) => void;
1185
- /**
1186
- * A callback that runs at the end of a drag event.
1187
- * @param element - The element being dragged.
1188
- */
1189
- onDragEnd: (element: HTMLElement) => void;
1190
- };
1191
-
1192
- /**
1193
- * @public
1194
- * Options for adding drag and drop behavior to an `HTMLElement`.
1195
- */
1196
- export declare type DraggableElementData = ElementData | ImageElementData;
1197
-
1198
1195
  /**
1199
1196
  * @public
1200
1197
  * An event that occurs when a user starts dragging an HTML element.
@@ -1208,10 +1205,43 @@ export declare type DragStartEvent<E extends Element> = Pick<
1208
1205
 
1209
1206
  /**
1210
1207
  * @beta
1211
- * Options for configuring how a design is read.
1208
+ * Reads and edits content of the specified type from the user's design.
1209
+ * @param options - Options for configuring how the design content is read.
1210
+ * @param callback - A callback for operating on the queried content.
1211
+ */
1212
+ export declare const editContent: (
1213
+ options: EditContentOptions,
1214
+ callback: EditContentCallback,
1215
+ ) => Promise<void>;
1216
+
1217
+ /**
1218
+ * @beta
1219
+ * A callback for reading and updating the requested design content.
1220
+ * @param session - The result of reading the content in the design.
1221
+ */
1222
+ export declare type EditContentCallback = (session: {
1223
+ /**
1224
+ * The individual content items returned by a query.
1225
+ */
1226
+ readonly contents: readonly RichtextContentRange[];
1227
+ /**
1228
+ * Commits any changes made to the items in the `contents` array.
1229
+ *
1230
+ * @remarks
1231
+ * An app must call this method for any changes to be reflected in the user's design.
1232
+ */
1233
+ sync(): Promise<void>;
1234
+ }) => Promise<void> | void;
1235
+
1236
+ /**
1237
+ * @beta
1238
+ * Options for configuring how the design content is read.
1212
1239
  */
1213
- export declare type EditContentOptions<T extends ContentType> = {
1214
- contentType: T;
1240
+ export declare type EditContentOptions = {
1241
+ /**
1242
+ * The type of content to edit from the user's design
1243
+ */
1244
+ contentType: ContentType;
1215
1245
  } & ContextOptions;
1216
1246
 
1217
1247
  /**
@@ -1223,27 +1253,22 @@ export declare type ElementAtCursor =
1223
1253
  | VideoElement
1224
1254
  | EmbedElement
1225
1255
  | TextElement
1226
- | RichtextElement;
1256
+ | RichtextElement
1257
+ | TableElement;
1227
1258
 
1228
1259
  /**
1229
1260
  * @public
1230
1261
  * An element that's natively supported by the Canva editor and has positional properties.
1231
1262
  */
1232
1263
  export declare type ElementAtPoint =
1233
- | NativeElementWithBox
1264
+ | ImageElementAtPoint
1265
+ | VideoElementAtPoint
1266
+ | EmbedElementAtPoint
1267
+ | TextElementAtPoint
1268
+ | ShapeElementAtPoint
1269
+ | GroupElementAtPoint
1234
1270
  | RichtextElementAtPoint;
1235
1271
 
1236
- /**
1237
- * @public
1238
- * Options for adding drag and drop behavior to an `HTMLElement`.
1239
- */
1240
- export declare type ElementData = DragCallback & {
1241
- /**
1242
- * The `HTMLElement` to be made draggable.
1243
- */
1244
- node: HTMLElement;
1245
- };
1246
-
1247
1272
  /**
1248
1273
  * @public
1249
1274
  * Embed element to be added to the design at the end of a drag event.
@@ -1274,13 +1299,27 @@ export declare type EmbedDragConfig = {
1274
1299
  * @public
1275
1300
  * An element that renders rich media, such as a YouTube video.
1276
1301
  */
1277
- export declare type EmbedElement = NativeEmbedElement;
1302
+ export declare type EmbedElement = {
1303
+ /**
1304
+ * The type of element.
1305
+ */
1306
+ type: "embed";
1307
+ /**
1308
+ * The URL of the rich media.
1309
+ *
1310
+ * @remarks
1311
+ * This URL must be supported by the Iframely API.
1312
+ */
1313
+ url: string;
1314
+ };
1278
1315
 
1279
1316
  /**
1280
1317
  * @public
1281
1318
  * An element that renders rich media, such as a YouTube video, and has positional properties.
1282
1319
  */
1283
- export declare type EmbedElementAtPoint = NativeEmbedElementWithBox;
1320
+ export declare type EmbedElementAtPoint = EmbedElement &
1321
+ Point &
1322
+ (WidthAndHeight | Width | Height);
1284
1323
 
1285
1324
  /**
1286
1325
  * @public
@@ -1482,25 +1521,43 @@ export declare const getDefaultPageDimensions: () => Promise<
1482
1521
  * @public
1483
1522
  * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
1484
1523
  */
1485
- export declare function getDesignToken(): Promise<DesignToken>;
1524
+ export declare const getDesignToken: () => Promise<DesignToken>;
1486
1525
 
1487
1526
  /**
1488
1527
  * @public
1489
1528
  * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
1490
1529
  */
1491
- export declare type GroupContentAtPoint = NativeSimpleElementWithBox;
1530
+ export declare type GroupContentAtPoint = Exclude<
1531
+ ElementAtPoint,
1532
+ GroupElementAtPoint
1533
+ >;
1492
1534
 
1493
1535
  /**
1494
1536
  * @public
1495
1537
  * An element that contains two or more elements.
1496
1538
  */
1497
- export declare type GroupElement = NativeGroupElement;
1539
+ export declare type GroupElement = {
1540
+ /**
1541
+ * The type of element.
1542
+ */
1543
+ type: "group";
1544
+ /**
1545
+ * The elements to render within the group.
1546
+ *
1547
+ * @remarks
1548
+ * - Each element within a group must have dimensions and a position.
1549
+ * - The dimensions and positions are relative to the dimensions and positions of the group.
1550
+ */
1551
+ children: GroupContentAtPoint[];
1552
+ };
1498
1553
 
1499
1554
  /**
1500
1555
  * @public
1501
1556
  * An element that contains two or more elements and has positional properties.
1502
1557
  */
1503
- export declare type GroupElementAtPoint = NativeGroupElementWithBox;
1558
+ export declare type GroupElementAtPoint = GroupElement &
1559
+ Point &
1560
+ (WidthAndHeight | Width | Height);
1504
1561
 
1505
1562
  /**
1506
1563
  * A set of dimensions with an auto-calculated width.
@@ -1540,24 +1597,48 @@ export declare type ImageDragConfigForElement<E extends Element> =
1540
1597
  * @public
1541
1598
  * An element that renders image content.
1542
1599
  */
1543
- export declare type ImageElement = NativeImageElement;
1600
+ export declare type ImageElement = {
1601
+ /**
1602
+ * The type of element.
1603
+ */
1604
+ type: "image";
1605
+ /**
1606
+ * A description of the image content.
1607
+ *
1608
+ * @remarks
1609
+ * Use `undefined` for content with no description.
1610
+ */
1611
+ altText: AltText | undefined;
1612
+ } & (
1613
+ | {
1614
+ /**
1615
+ * A data URL that contains the image data.
1616
+ */
1617
+ dataUrl: string;
1618
+ /**
1619
+ * A unique identifier that points to an image asset in Canva's backend.
1620
+ */
1621
+ ref?: never;
1622
+ }
1623
+ | {
1624
+ /**
1625
+ * A data URL that contains the image data.
1626
+ */
1627
+ dataUrl?: never;
1628
+ /**
1629
+ * A unique identifier that points to an image asset in Canva's backend.
1630
+ */
1631
+ ref: ImageRef;
1632
+ }
1633
+ );
1544
1634
 
1545
1635
  /**
1546
1636
  * @public
1547
1637
  * An element that renders image content and has positional properties.
1548
1638
  */
1549
- export declare type ImageElementAtPoint = NativeImageElementWithBox;
1550
-
1551
- /**
1552
- * @public
1553
- * Options for adding drag and drop behavior to an `HTMLImageElement`.
1554
- */
1555
- export declare type ImageElementData = DragCallback & {
1556
- /**
1557
- * The `HTMLImageElement` to be made draggable.
1558
- */
1559
- node: HTMLImageElement;
1560
- };
1639
+ export declare type ImageElementAtPoint = ImageElement &
1640
+ Point &
1641
+ (WidthAndHeight | Width | Height);
1561
1642
 
1562
1643
  /**
1563
1644
  * @public
@@ -1572,6 +1653,13 @@ export declare type ImageFill = {
1572
1653
  * A unique identifier that points to an image asset in Canva's backend.
1573
1654
  */
1574
1655
  ref: ImageRef;
1656
+ /**
1657
+ * A description of the image content.
1658
+ *
1659
+ * @remarks
1660
+ * Use `undefined` for content with no description.
1661
+ */
1662
+ altText?: AltText;
1575
1663
  };
1576
1664
 
1577
1665
  /**
@@ -1586,9 +1674,9 @@ export declare type ImageRef = string & {
1586
1674
  * @public
1587
1675
  * @param appElementConfig - Configuration for an AppElementClient
1588
1676
  */
1589
- export declare function initAppElement<A extends AppElementData>(
1590
- appElementConfig: AppElementClientConfiguration<A>
1591
- ): AppElementClient<A>;
1677
+ export declare const initAppElement: <A extends AppElementData>(
1678
+ appElementConfig: AppElementClientConfiguration<A>,
1679
+ ) => AppElementClient<A>;
1592
1680
 
1593
1681
  /**
1594
1682
  * @public
@@ -1636,7 +1724,7 @@ export declare type InlineFormatting = {
1636
1724
  };
1637
1725
 
1638
1726
  /**
1639
- * @deprecated
1727
+ * @deprecated The type has been superseded by `DesignElement`.
1640
1728
  * @public
1641
1729
  * An element that's natively supported by the Canva editor.
1642
1730
  */
@@ -1678,279 +1766,91 @@ export declare type NativeElementWithBox =
1678
1766
  * @public
1679
1767
  * An element that renders rich media, such as a YouTube video.
1680
1768
  */
1681
- export declare type NativeEmbedElement = {
1682
- /**
1683
- * The type of element.
1684
- */
1685
- type: "embed";
1686
- /**
1687
- * The URL of the rich media.
1688
- *
1689
- * @remarks
1690
- * This URL must be supported by the Iframely API.
1691
- */
1692
- url: string;
1693
- };
1769
+ export declare type NativeEmbedElement = EmbedElement;
1694
1770
 
1695
1771
  /**
1696
1772
  * @deprecated The type has been superseded by `EmbedElementAtPoint`.
1697
1773
  * @public
1698
1774
  * An element that renders rich media, such as a YouTube video, and has positional properties.
1699
1775
  */
1700
- export declare type NativeEmbedElementWithBox = {
1701
- /**
1702
- * The type of element.
1703
- */
1704
- type: "embed";
1705
- /**
1706
- * The URL of the rich media.
1707
- *
1708
- * @remarks
1709
- * This URL must be supported by the Iframely API.
1710
- */
1711
- url: string;
1712
- } & Box;
1776
+ export declare type NativeEmbedElementWithBox = EmbedElementAtPoint;
1713
1777
 
1714
1778
  /**
1715
1779
  * @deprecated The type has been superseded by `GroupElement`.
1716
1780
  * @public
1717
1781
  * An element that contains two or more elements.
1718
1782
  */
1719
- export declare type NativeGroupElement = {
1720
- /**
1721
- * The type of element.
1722
- */
1723
- type: "group";
1724
- /**
1725
- * The elements to render within the group.
1726
- *
1727
- * @remarks
1728
- * - Each element within a group must have dimensions and a position.
1729
- * - The dimensions and positions are relative to the dimensions and positions of the group.
1730
- */
1731
- children: NativeSimpleElementWithBox[];
1732
- };
1783
+ export declare type NativeGroupElement = GroupElement;
1733
1784
 
1734
1785
  /**
1735
1786
  * @deprecated The type has been superseded by `GroupElementAtPoint`.
1736
1787
  * @public
1737
1788
  * An element that contains two or more elements and has positional properties.
1738
1789
  */
1739
- export declare type NativeGroupElementWithBox = {
1740
- /**
1741
- * The type of element.
1742
- */
1743
- type: "group";
1744
- /**
1745
- * The elements to render within the group.
1746
- *
1747
- * @remarks
1748
- * - Each element within a group must have dimensions and a position.
1749
- * - The dimensions and positions are relative to the dimensions and positions of the group.
1750
- */
1751
- children: NativeSimpleElementWithBox[];
1752
- } & Box;
1790
+ export declare type NativeGroupElementWithBox = GroupElementAtPoint;
1753
1791
 
1754
1792
  /**
1755
1793
  * @deprecated The type has been superseded by `ImageElement`.
1756
1794
  * @public
1757
1795
  * An element that renders image content.
1758
1796
  */
1759
- export declare type NativeImageElement = {
1760
- /**
1761
- * The type of element.
1762
- */
1763
- type: "image";
1764
- /**
1765
- * A description of the image content.
1766
- */
1767
- altText: AltText | undefined;
1768
- } & (
1769
- | {
1770
- /**
1771
- * A data URL that contains the image data.
1772
- */
1773
- dataUrl: string;
1774
- /**
1775
- * A unique identifier that points to an image asset in Canva's backend.
1776
- */
1777
- ref?: never;
1778
- }
1779
- | {
1780
- /**
1781
- * A data URL that contains the image data.
1782
- */
1783
- dataUrl?: never;
1784
- /**
1785
- * A unique identifier that points to an image asset in Canva's backend.
1786
- */
1787
- ref: ImageRef;
1788
- }
1789
- );
1797
+ export declare type NativeImageElement = ImageElement;
1790
1798
 
1791
1799
  /**
1792
1800
  * @deprecated The type has been superseded by `ImageElementAtPoint`.
1793
1801
  * @public
1794
1802
  * An element that renders image content and has positional properties.
1795
1803
  */
1796
- export declare type NativeImageElementWithBox = NativeImageElement & Box;
1804
+ export declare type NativeImageElementWithBox = ImageElementAtPoint;
1797
1805
 
1798
1806
  /**
1799
1807
  * @deprecated The type has been superseded by `ShapeElement`.
1800
1808
  * @public
1801
1809
  * An element that renders a vector shape.
1802
1810
  */
1803
- export declare type NativeShapeElement = {
1804
- /**
1805
- * The type of element.
1806
- */
1807
- type: "shape";
1808
- /**
1809
- * Options for configuring the scale and cropping of the shape.
1810
- */
1811
- viewBox: ShapeViewBox;
1812
- /**
1813
- * The paths that define the structure of the shape.
1814
- *
1815
- * @remarks
1816
- * - There must be between 1 and 30 paths (inclusive).
1817
- * - The maximum combined size of all paths must not exceed 2kb.
1818
- * - The maximum number of unique fill colors across all paths is 6.
1819
- */
1820
- paths: ShapePath[];
1821
- };
1811
+ export declare type NativeShapeElement = ShapeElement;
1822
1812
 
1823
1813
  /**
1824
1814
  * @deprecated The type has been superseded by `ShapeElementAtPoint`.
1825
1815
  * @public
1826
1816
  * An element that renders a vector shape and has positional properties.
1827
1817
  */
1828
- export declare type NativeShapeElementWithBox = {
1829
- /**
1830
- * The type of element.
1831
- */
1832
- type: "shape";
1833
- /**
1834
- * Options for configuring the scale and cropping of a shape.
1835
- */
1836
- viewBox: ShapeViewBox;
1837
- /**
1838
- * The paths that define the structure of the shape.
1839
- *
1840
- * @remarks
1841
- * - There must be between 1 and 30 paths (inclusive).
1842
- * - The maximum combined size of all paths must not exceed 2kb.
1843
- * - The maximum number of unique fill colors across all paths is 6.
1844
- */
1845
- paths: ShapePath[];
1846
- } & Box;
1818
+ export declare type NativeShapeElementWithBox = ShapeElementAtPoint;
1847
1819
 
1848
1820
  /**
1849
1821
  * @deprecated The type has been superseded by `GroupContentAtPoint`.
1850
1822
  * @public
1851
1823
  * An element that's natively supported by the Canva editor, can exist within a group, and has positional properties.
1852
1824
  */
1853
- export declare type NativeSimpleElementWithBox = Exclude<
1854
- NativeElementWithBox,
1855
- NativeGroupElementWithBox
1856
- >;
1825
+ export declare type NativeSimpleElementWithBox = GroupContentAtPoint;
1857
1826
 
1858
1827
  /**
1859
1828
  * @deprecated The type has been superseded by `TextElement`.
1860
1829
  * @public
1861
1830
  * An element that renders text content.
1862
1831
  */
1863
- export declare type NativeTextElement = {
1864
- /**
1865
- * The type of element.
1866
- */
1867
- type: "text";
1868
- /**
1869
- * The text content.
1870
- *
1871
- * @remarks
1872
- * Only the first element in this array is used.
1873
- */
1874
- children: string[];
1875
- } & TextAttributes;
1832
+ export declare type NativeTextElement = TextElement;
1876
1833
 
1877
1834
  /**
1878
1835
  * @deprecated The type has been superseded by `TextElementAtPoint`.
1879
1836
  * @public
1880
1837
  * An element that renders text content and has positional properties.
1881
1838
  */
1882
- export declare type NativeTextElementWithBox = {
1883
- /**
1884
- * The type of element.
1885
- */
1886
- type: "text";
1887
- /**
1888
- * The text content.
1889
- *
1890
- * @remarks
1891
- * Only the first element in this array is used.
1892
- */
1893
- children: [string];
1894
- /**
1895
- * The width of the element, in pixels.
1896
- *
1897
- * @remarks
1898
- * - Minimum: 0
1899
- * - Maximum: 32767
1900
- */
1901
- width?: number;
1902
- /**
1903
- * The distance from the top edge of the container, in pixels.
1904
- *
1905
- * @remarks
1906
- * - Minimum: -32768
1907
- * - Maximum: 32767
1908
- */
1909
- top: number;
1910
- /**
1911
- * The distance from the left edge of the container, in pixels.
1912
- *
1913
- * @remarks
1914
- * - Minimum: -32768
1915
- * - Maximum: 32767
1916
- */
1917
- left: number;
1918
- /**
1919
- * The rotation of the element, in degrees.
1920
- *
1921
- * @remarks
1922
- * - Minimum: -180
1923
- * - Maximum: 180
1924
- */
1925
- rotation?: number;
1926
- } & TextAttributes;
1839
+ export declare type NativeTextElementWithBox = TextElementAtPoint;
1927
1840
 
1928
1841
  /**
1929
1842
  * @deprecated The type has been superseded by `VideoElement`.
1930
1843
  * @public
1931
1844
  * An element that renders video content.
1932
1845
  */
1933
- export declare type NativeVideoElement = {
1934
- /**
1935
- * The type of element.
1936
- */
1937
- type: "video";
1938
- /**
1939
- * A unique identifier that points to a video asset in Canva's backend.
1940
- */
1941
- ref: VideoRef;
1942
- /**
1943
- * A description of the video content.
1944
- */
1945
- altText: AltText | undefined;
1946
- };
1846
+ export declare type NativeVideoElement = VideoElement;
1947
1847
 
1948
1848
  /**
1949
1849
  * @deprecated The type has been superseded by `VideoElementAtPoint`.
1950
1850
  * @public
1951
1851
  * An element that renders video content and has positional properties.
1952
1852
  */
1953
- export declare type NativeVideoElementWithBox = NativeVideoElement & Box;
1853
+ export declare type NativeVideoElementWithBox = VideoElementAtPoint;
1954
1854
 
1955
1855
  /**
1956
1856
  * An object primitive data type that can be used in app element data.
@@ -1961,7 +1861,7 @@ declare type ObjectPrimitive = Boolean | String;
1961
1861
  * @beta
1962
1862
  * Reads a specified part of the user's design and returns all elements in that part.
1963
1863
  *
1964
- * @param options - Options for configuring how a design is read.
1864
+ * @param options - Options for configuring how the design is read.
1965
1865
  * @param callback - A callback for operating on the design.
1966
1866
  */
1967
1867
  export declare const openDesign: (
@@ -1970,8 +1870,8 @@ export declare const openDesign: (
1970
1870
  draft: DesignEditing.DesignOpenResult,
1971
1871
  helpers: {
1972
1872
  elementBuilder: DesignEditing.ElementBuilder;
1973
- }
1974
- ) => Promise<void> | void
1873
+ },
1874
+ ) => Promise<void> | void,
1975
1875
  ) => Promise<void>;
1976
1876
 
1977
1877
  /**
@@ -2100,13 +2000,12 @@ export declare type PathStroke = {
2100
2000
  * @public
2101
2001
  * A position, set of dimensions, and rotation.
2102
2002
  */
2103
- export declare type Placement = Position & (WidthAndHeight | Width | Height);
2003
+ export declare type Placement = Point & (WidthAndHeight | Width | Height);
2104
2004
 
2105
2005
  /**
2106
- * @deprecated
2107
2006
  * A position and rotation.
2108
2007
  */
2109
- declare type Position = {
2008
+ declare type Point = {
2110
2009
  /**
2111
2010
  * The distance from the top edge of the container, in pixels.
2112
2011
  *
@@ -2143,68 +2042,26 @@ declare type Position = {
2143
2042
  */
2144
2043
  declare type Primitive = undefined | null | number | boolean | string;
2145
2044
 
2146
- /**
2147
- * @beta
2148
- * A snapshot of content returned by a query.
2149
- *
2150
- * @remarks
2151
- * The snapshot is known as the *draft*.
2152
- */
2153
- export declare interface QueryContentDraft<T> {
2154
- /**
2155
- * The individual content items returned by a query.
2156
- */
2157
- readonly contents: readonly T[];
2158
- /**
2159
- * Commits any changes made to the items in the `contents` array.
2160
- *
2161
- * @remarks
2162
- * An app must call this method for any changes to be reflected in the user's design.
2163
- */
2164
- sync(): Promise<void>;
2165
- }
2166
-
2167
- /**
2168
- * @beta
2169
- * The result of querying content in a design.
2170
- */
2171
- export declare type QueryResult<T extends ContentType> = {
2172
- ["richtext"]: QueryContentDraft<
2173
- RichtextRange & {
2174
- readonly deleted: boolean;
2175
- }
2176
- >;
2177
- }[T];
2178
-
2179
- /**
2180
- * @beta
2181
- * Reads content of the specified type from the user's design.
2182
- * @param options - Options for configuring how a design is read.
2183
- * @param callback - A callback for operating on the queried content.
2184
- */
2185
- export declare const readContent: <T extends ContentType>(
2186
- options: EditContentOptions<T>,
2187
- callback: (draft: QueryResult<T>) => Promise<void> | void
2188
- ) => Promise<void>;
2189
-
2190
- /**
2191
- * @beta
2192
- * A callback for reading and updating part of a design.
2193
- * @param draft - The result of reading the content in a design.
2194
- */
2195
- export declare type ReadContentCallback<T extends ContentType> = (
2196
- draft: QueryResult<T>
2197
- ) => Promise<void> | void;
2198
-
2199
2045
  /**
2200
2046
  * @public
2201
2047
  * Exports the user's design as one or more static files.
2202
2048
  * @param request - The request object containing configurations of the design export.
2203
2049
  */
2204
2050
  export declare const requestExport: (
2205
- request: ExportRequest
2051
+ request: ExportRequest,
2206
2052
  ) => Promise<ExportResponse>;
2207
2053
 
2054
+ /**
2055
+ * @beta
2056
+ * Provides methods for interacting with a range of formatted text.
2057
+ */
2058
+ export declare interface RichtextContentRange extends RichtextRange {
2059
+ /**
2060
+ * Indicates whether the object containing this richtext range has been deleted.
2061
+ */
2062
+ readonly deleted: boolean;
2063
+ }
2064
+
2208
2065
  /**
2209
2066
  * @public
2210
2067
  * An element that renders richtext content.
@@ -2312,7 +2169,7 @@ export declare type RichtextRange = {
2312
2169
  */
2313
2170
  appendText(
2314
2171
  characters: string,
2315
- formatting?: InlineFormatting
2172
+ formatting?: InlineFormatting,
2316
2173
  ): {
2317
2174
  bounds: Bounds;
2318
2175
  };
@@ -2326,7 +2183,7 @@ export declare type RichtextRange = {
2326
2183
  replaceText(
2327
2184
  bounds: Bounds,
2328
2185
  characters: string,
2329
- formatting?: InlineFormatting
2186
+ formatting?: InlineFormatting,
2330
2187
  ): {
2331
2188
  /**
2332
2189
  * The bounds of the replacement characters within the updated range.
@@ -2464,20 +2321,40 @@ export declare type SelectionValue<Scope extends SelectionScope> = {
2464
2321
  * an image or a video.
2465
2322
  */
2466
2323
  export declare const setCurrentPageBackground: (
2467
- opts: PageBackgroundFill
2324
+ opts: PageBackgroundFill,
2468
2325
  ) => Promise<void>;
2469
2326
 
2470
2327
  /**
2471
2328
  * @public
2472
2329
  * An element that renders a vector shape.
2473
2330
  */
2474
- export declare type ShapeElement = NativeShapeElement;
2331
+ export declare type ShapeElement = {
2332
+ /**
2333
+ * The type of element.
2334
+ */
2335
+ type: "shape";
2336
+ /**
2337
+ * Options for configuring the scale and cropping of the shape.
2338
+ */
2339
+ viewBox: ShapeViewBox;
2340
+ /**
2341
+ * The paths that define the structure of the shape.
2342
+ *
2343
+ * @remarks
2344
+ * - There must be between 1 and 30 paths (inclusive).
2345
+ * - The maximum combined size of all paths must not exceed 2kb.
2346
+ * - The maximum number of unique fill colors across all paths is 6.
2347
+ */
2348
+ paths: ShapePath[];
2349
+ };
2475
2350
 
2476
2351
  /**
2477
2352
  * @public
2478
2353
  * An element that renders a vector shape and has positional properties.
2479
2354
  */
2480
- export declare type ShapeElementAtPoint = NativeShapeElementWithBox;
2355
+ export declare type ShapeElementAtPoint = ShapeElement &
2356
+ Point &
2357
+ (WidthAndHeight | Width | Height);
2481
2358
 
2482
2359
  /**
2483
2360
  * @public
@@ -2613,39 +2490,15 @@ export declare type TextAttributes = {
2613
2490
  * @public
2614
2491
  * The dimensions, position, and rotation of a text element.
2615
2492
  */
2616
- declare type TextBox = {
2493
+ declare type TextBox = Point & {
2617
2494
  /**
2618
- * The width, in pixels.
2495
+ * The width of the element, in pixels.
2619
2496
  *
2620
2497
  * @remarks
2621
2498
  * - Minimum: 0
2622
2499
  * - Maximum: 32767
2623
2500
  */
2624
2501
  width?: number;
2625
- /**
2626
- * The distance from the top edge of the container, in pixels.
2627
- *
2628
- * @remarks
2629
- * - Minimum: -32767
2630
- * - Maximum: 32767
2631
- */
2632
- top: number;
2633
- /**
2634
- * The distance from the left edge of the container, in pixels.
2635
- *
2636
- * @remarks
2637
- * - Minimum: -32767
2638
- * - Maximum: 32767
2639
- */
2640
- left: number;
2641
- /**
2642
- * The rotation, in degrees.
2643
- *
2644
- * @remarks
2645
- * - Minimum: -180
2646
- * - Maximum: 180
2647
- */
2648
- rotation?: number;
2649
2502
  };
2650
2503
 
2651
2504
  /**
@@ -2692,13 +2545,25 @@ export declare type TextDragConfig = {
2692
2545
  * @public
2693
2546
  * An element that renders text content.
2694
2547
  */
2695
- export declare type TextElement = NativeTextElement;
2548
+ export declare type TextElement = {
2549
+ /**
2550
+ * The type of element.
2551
+ */
2552
+ type: "text";
2553
+ /**
2554
+ * The text content.
2555
+ *
2556
+ * @remarks
2557
+ * Only the first element in this array is used.
2558
+ */
2559
+ children: string[];
2560
+ } & TextAttributes;
2696
2561
 
2697
2562
  /**
2698
2563
  * @public
2699
2564
  * An element that renders text content and has positional properties.
2700
2565
  */
2701
- export declare type TextElementAtPoint = NativeTextElementWithBox;
2566
+ export declare type TextElementAtPoint = TextElement & TextBox;
2702
2567
 
2703
2568
  /**
2704
2569
  * @public
@@ -2735,7 +2600,7 @@ export declare interface UI {
2735
2600
  | AudioDragConfig
2736
2601
  | EmbedDragConfig
2737
2602
  | VideoDragConfigForElement<E>
2738
- | ImageDragConfigForElement<E>
2603
+ | ImageDragConfigForElement<E>,
2739
2604
  ): Promise<void>;
2740
2605
  /**
2741
2606
  * @public
@@ -2751,7 +2616,7 @@ export declare interface UI {
2751
2616
  | AudioDragConfig
2752
2617
  | EmbedDragConfig
2753
2618
  | VideoDragConfigForElement<E>
2754
- | ImageDragConfigForElement<E>
2619
+ | ImageDragConfigForElement<E>,
2755
2620
  ): Promise<void>;
2756
2621
  /**
2757
2622
  * @public
@@ -2765,7 +2630,7 @@ export declare interface UI {
2765
2630
  dragData:
2766
2631
  | EmbedDragConfig
2767
2632
  | VideoDragConfigForElement<E>
2768
- | ImageDragConfigForElement<E>
2633
+ | ImageDragConfigForElement<E>,
2769
2634
  ): Promise<void>;
2770
2635
  }
2771
2636
 
@@ -2834,13 +2699,31 @@ export declare type VideoDragConfigForElement<E extends Element> =
2834
2699
  * @public
2835
2700
  * An element that renders video content.
2836
2701
  */
2837
- export declare type VideoElement = NativeVideoElement;
2702
+ export declare type VideoElement = {
2703
+ /**
2704
+ * The type of element.
2705
+ */
2706
+ type: "video";
2707
+ /**
2708
+ * A unique identifier that points to a video asset in Canva's backend.
2709
+ */
2710
+ ref: VideoRef;
2711
+ /**
2712
+ * A description of the video content.
2713
+ *
2714
+ * @remarks
2715
+ * Use `undefined` for content with no description.
2716
+ */
2717
+ altText: AltText | undefined;
2718
+ };
2838
2719
 
2839
2720
  /**
2840
2721
  * @public
2841
2722
  * An element that renders video content and has positional properties.
2842
2723
  */
2843
- export declare type VideoElementAtPoint = NativeVideoElementWithBox;
2724
+ export declare type VideoElementAtPoint = VideoElement &
2725
+ Point &
2726
+ (WidthAndHeight | Width | Height);
2844
2727
 
2845
2728
  /**
2846
2729
  * @public
@@ -2855,6 +2738,13 @@ export declare type VideoFill = {
2855
2738
  * A unique identifier that points to a video asset in Canva's backend.
2856
2739
  */
2857
2740
  ref: VideoRef;
2741
+ /**
2742
+ * A description of the image content.
2743
+ *
2744
+ * @remarks
2745
+ * Use `undefined` for content with no description.
2746
+ */
2747
+ altText?: AltText;
2858
2748
  };
2859
2749
 
2860
2750
  /**
@@ -9,8 +9,11 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- readContent: function() {
13
- return readContent;
12
+ initAppElement: function() {
13
+ return initAppElement;
14
+ },
15
+ editContent: function() {
16
+ return editContent;
14
17
  },
15
18
  openDesign: function() {
16
19
  return openDesign;
@@ -32,7 +35,7 @@ function _export_star(from, to) {
32
35
  }
33
36
  var _window___canva___sdkRegistration, _window___canva__;
34
37
  const { canva_sdk } = window;
35
- const readContent = canva_sdk.design.v2.designInteraction.readContent;
38
+ const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
39
+ const editContent = canva_sdk.design.v2.designInteraction.editContent;
36
40
  const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
37
- (_window___canva__ =
38
- 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.1.0', 'beta');
41
+ (_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.2.1', 'beta');
@@ -68,12 +68,6 @@ const addElementAtPoint = canva_sdk.design.v2.designInteraction.addElementAtPoin
68
68
  const addElementAtCursor = canva_sdk.design.v2.designInteraction.addElementAtCursor;
69
69
  const addAudioTrack = canva_sdk.design.v2.designInteraction.addAudioTrack;
70
70
  const getCurrentPageContext = canva_sdk.design.v2.designInteraction.getCurrentPageContext;
71
- function initAppElement(appElementConfig) {
72
- return canva_sdk.design.v2.designInteraction.initAppElement(appElementConfig);
73
- }
74
- function getDesignToken() {
75
- return canva_sdk.design.v2.designInteraction.getDesignToken();
76
- }
77
- function createRichtextRange() {
78
- return canva_sdk.design.v2.designInteraction.createRichtextRange();
79
- }
71
+ const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
72
+ const getDesignToken = canva_sdk.design.v2.designInteraction.getDesignToken;
73
+ const createRichtextRange = canva_sdk.design.v2.designInteraction.createRichtextRange;
@@ -1,7 +1,7 @@
1
1
  var _window___canva___sdkRegistration, _window___canva__;
2
2
  const { canva_sdk } = window;
3
- export const readContent = canva_sdk.design.v2.designInteraction.readContent;
3
+ export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
4
+ export const editContent = canva_sdk.design.v2.designInteraction.editContent;
4
5
  export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
5
6
  export * from './public';
6
- (_window___canva__ =
7
- 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.1.0', 'beta');
7
+ (_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.2.1', 'beta');
@@ -11,12 +11,6 @@ export const addElementAtPoint = canva_sdk.design.v2.designInteraction.addElemen
11
11
  export const addElementAtCursor = canva_sdk.design.v2.designInteraction.addElementAtCursor;
12
12
  export const addAudioTrack = canva_sdk.design.v2.designInteraction.addAudioTrack;
13
13
  export const getCurrentPageContext = canva_sdk.design.v2.designInteraction.getCurrentPageContext;
14
- export function initAppElement(appElementConfig) {
15
- return canva_sdk.design.v2.designInteraction.initAppElement(appElementConfig);
16
- }
17
- export function getDesignToken() {
18
- return canva_sdk.design.v2.designInteraction.getDesignToken();
19
- }
20
- export function createRichtextRange() {
21
- return canva_sdk.design.v2.designInteraction.createRichtextRange();
22
- }
14
+ export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
15
+ export const getDesignToken = canva_sdk.design.v2.designInteraction.getDesignToken;
16
+ export const createRichtextRange = canva_sdk.design.v2.designInteraction.createRichtextRange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.2.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",
@@ -11,14 +11,9 @@
11
11
  "module": "./lib/esm/sdk/design/beta.js",
12
12
  "exports": {
13
13
  ".": {
14
- "require": {
15
- "types": "./beta.d.ts",
16
- "default": "./lib/cjs/sdk/design/beta.js"
17
- },
18
- "import": {
19
- "types": "./beta.d.ts",
20
- "default": "./lib/esm/sdk/design/beta.js"
21
- }
14
+ "types": "./beta.d.ts",
15
+ "require": "./lib/cjs/sdk/design/beta.js",
16
+ "import": "./lib/esm/sdk/design/beta.js"
22
17
  }
23
18
  },
24
19
  "typings": "./beta.d.ts"