addNativeElement
This API is deprecated, and is no longer recommended for use, and should be removed from your app.
Adds a native element to the user's design.
Usage: Basic usage
import { addNativeElement } from "@canva/design";import type { NativeElementWithBox } from "@canva/design";const element: NativeElementWithBox = {type: 'text',children: ['Legacy element'],top: 100,left: 100,width: 200};await addNativeElement(element);
Parameters
elementobjectThe element to add to the user's design.
The type has been superseded by DesignElement.
An element that's natively supported by the Canva editor.
The type has been superseded by ImageElement.
An element that renders image content.
typestringThe type of element.
The only valid value is "image".
altTextAltText | undefinedA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
dataUrlstringA data URL that contains the image data.
refImageRefA unique identifier that points to an image asset in Canva's backend.
The type has been superseded by VideoElement.
An element that renders video content.
typestringThe type of element.
The only valid value is "video".
refVideoRefA unique identifier that points to a video asset in Canva's backend.
altTextAltText | undefinedA description of the video content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
The type has been superseded by EmbedElement.
An element that renders rich media, such as a YouTube video.
typestringThe type of element.
The only valid value is "embed".
urlstringThe URL of the rich media.
This URL must be supported by the Iframely API.
The type has been superseded by TextElement.
An element that renders text content.
typestringThe type of element.
The only valid value is "text".
childrenstring[]The text content.
Only the first element in this array is used.
fontSizenumberThe size of the text.
Minimum: 1
Maximum: 100
Default value: 16
textAlignstringThe alignment of the text.
Default value: "start"
Available values:
"start""center""end""justify"
colorstringThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
fontRefFontRefA unique identifier that points to a font asset in Canva's backend.
fontWeightFontWeightThe weight (thickness) of the font.
Default value: "normal"
Available values:
"normal""thin""extralight""light""medium""semibold""bold""ultrabold""heavy"
fontStylestringThe style of the font.
Default value: "normal"
Available values:
"normal""italic"
decorationstringThe decoration of the font.
Default value: "none"
Available values:
"none""underline"
The type has been superseded by ShapeElement.
An element that renders a vector shape.
typestringThe type of element.
The only valid value is "shape".
viewBoxShapeViewBoxOptions for configuring the scale and cropping of the shape.
topnumberThe distance of the shape from the top edge of the element, in pixels.
leftnumberThe distance of the shape from the left edge of the element, in pixels.
widthnumberThe width of the view box, in pixels.
heightnumberThe height of the view box, in pixels.
pathsShapePath[]The paths that define the structure of the shape.
- There must be between 1 and 30 paths (inclusive).
- The maximum combined size of all paths must not exceed 2kb.
- The maximum number of unique fill colors across all paths is 6.
dstringThe shape of the path.
This is similar to the d attribute of an SVG's path element, with some limitations:
- The path must start with an M command.
- The path must not have more than one M command.
- The path must not use the Q command.
- The path must be closed, either by:
- Using a Z command at the end of the path
- Having the last coordinate match the first coordinate
fillFillThe appearance of the path's interior.
dropTargetbooleanIf true, users can replace a fill by dropping an image or video onto it.
colorstringThe color of the fill as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
assetobjectAn image or video to use as the fill.
An image asset that fills a path's interior.
typestringThe type of fill.
The only valid value is "image".
refImageRefA unique identifier that points to an image asset in Canva's backend.
altTextAltTextA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
A video asset that fills a path's interior.
typestringThe type of fill.
The only valid value is "video".
refVideoRefA unique identifier that points to a video asset in Canva's backend.
altTextAltTextA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
strokePathStrokeThe outline of the path.
weightnumberThe weight (thickness) of the stroke.
Minimum: 0
Maximum: 100
colorstringThe color of the stroke as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
strokeAlignstringThe alignment of the stroke.
The only valid value is "inset".
The type has been superseded by GroupElement.
An element that contains two or more elements.
typestringThe type of element.
The only valid value is "group".
childrenGroupContentAtPoint[]The elements to render within the group.
- Each element within a group must have dimensions and a position.
- The dimensions and positions are relative to the dimensions and positions of the group.
The type has been superseded by ElementAtPoint.
An element that's natively supported by the Canva editor and has positional properties.
The type has been superseded by ImageElementAtPoint.
An element that renders image content and has positional properties.
typestringThe type of element.
The only valid value is "image".
altTextAltText | undefinedA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
widthnumberA width, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
heightnumberA height, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
dataUrlstringA data URL that contains the image data.
refImageRefA unique identifier that points to an image asset in Canva's backend.
The type has been superseded by VideoElementAtPoint.
An element that renders video content and has positional properties.
typestringThe type of element.
The only valid value is "video".
refVideoRefA unique identifier that points to a video asset in Canva's backend.
altTextAltText | undefinedA description of the video content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
widthnumberA width, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
heightnumberA height, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
The type has been superseded by EmbedElementAtPoint.
An element that renders rich media, such as a YouTube video, and has positional properties.
typestringThe type of element.
The only valid value is "embed".
urlstringThe URL of the rich media.
This URL must be supported by the Iframely API.
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
widthnumberA width, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
heightnumberA height, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
The type has been superseded by TextElementAtPoint.
An element that renders text content and has positional properties.
typestringThe type of element.
The only valid value is "text".
childrenstring[]The text content.
Only the first element in this array is used.
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
fontSizenumberThe size of the text.
Minimum: 1
Maximum: 100
Default value: 16
textAlignstringThe alignment of the text.
Default value: "start"
Available values:
"start""center""end""justify"
colorstringThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
fontRefFontRefA unique identifier that points to a font asset in Canva's backend.
fontWeightFontWeightThe weight (thickness) of the font.
Default value: "normal"
Available values:
"normal""thin""extralight""light""medium""semibold""bold""ultrabold""heavy"
fontStylestringThe style of the font.
Default value: "normal"
Available values:
"normal""italic"
decorationstringThe decoration of the font.
Default value: "none"
Available values:
"none""underline"
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
widthnumberThe width of the element, in pixels.
Minimum: 0
Maximum: 32767
The type has been superseded by ShapeElementAtPoint.
An element that renders a vector shape and has positional properties.
typestringThe type of element.
The only valid value is "shape".
viewBoxShapeViewBoxOptions for configuring the scale and cropping of the shape.
topnumberThe distance of the shape from the top edge of the element, in pixels.
leftnumberThe distance of the shape from the left edge of the element, in pixels.
widthnumberThe width of the view box, in pixels.
heightnumberThe height of the view box, in pixels.
pathsShapePath[]The paths that define the structure of the shape.
- There must be between 1 and 30 paths (inclusive).
- The maximum combined size of all paths must not exceed 2kb.
- The maximum number of unique fill colors across all paths is 6.
dstringThe shape of the path.
This is similar to the d attribute of an SVG's path element, with some limitations:
- The path must start with an M command.
- The path must not have more than one M command.
- The path must not use the Q command.
- The path must be closed, either by:
- Using a Z command at the end of the path
- Having the last coordinate match the first coordinate
fillFillThe appearance of the path's interior.
dropTargetbooleanIf true, users can replace a fill by dropping an image or video onto it.
colorstringThe color of the fill as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
assetobjectAn image or video to use as the fill.
An image asset that fills a path's interior.
typestringThe type of fill.
The only valid value is "image".
refImageRefA unique identifier that points to an image asset in Canva's backend.
altTextAltTextA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
A video asset that fills a path's interior.
typestringThe type of fill.
The only valid value is "video".
refVideoRefA unique identifier that points to a video asset in Canva's backend.
altTextAltTextA description of the image content.
Use undefined for content with no description.
textstringThe text content.
decorativeboolean | undefinedIndicates where the alternative text should be displayed.
- If
true, the alternative text will only be displayed in the editor. - If
false, the alternative text will be displayed in the editor and in view-only mode.
strokePathStrokeThe outline of the path.
weightnumberThe weight (thickness) of the stroke.
Minimum: 0
Maximum: 100
colorstringThe color of the stroke as a hex code.
The hex code must include all six characters and be prefixed with a # symbol.
Example
"#ff0099"
strokeAlignstringThe alignment of the stroke.
The only valid value is "inset".
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
widthnumberA width, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
heightnumberA height, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
The type has been superseded by GroupElementAtPoint.
An element that contains two or more elements and has positional properties.
typestringThe type of element.
The only valid value is "group".
childrenGroupContentAtPoint[]The elements to render within the group.
- Each element within a group must have dimensions and a position.
- The dimensions and positions are relative to the dimensions and positions of the group.
topnumberThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
leftnumberThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
widthnumberA width, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
heightnumberA height, in pixels.
- The pixels are relative to their container.
Minimum: 0
Maximum: 32767
rotationnumberA rotation, in degrees.
Minimum: -180
Maximum: 180
Returns
Promise<void>