ElementStateBuilder
Provides methods for creating element states.
These methods don't add the elements to the design. They only return elements that can
be added to a design, such as with the insertAfter
method.
Methods
createRectElement
function
RequiredCreates a rect element state.
Parameters
opts
CreateRectElementOpts
RequiredOptions for creating the rect element.
top
number
RequiredThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
RequiredThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
width
number
RequiredA width, in pixels.
height
number
RequiredA height, in pixels.
rotation
number
OptionalA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
OptionalTransparency as a percentage.
Minimum: 0
Maximum: 1
fill
FillOpts
OptionalDescribes how a fill is filled with color or media.
If both media
and color
are defined, media
takes precedence.
colorContainer
ColorContainerOpts
type
string
Read-onlyRequiredThe type of color.
This must be "solid"
.
color
string
RequiredThe color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
mediaContainer
MediaContainerOpts
Options for creating a media fill in the element state builder
Options for creating an image fill in the element state builder
type
string
RequiredThe type of media.
This must be "image"
.
imageRef
ImageRef
RequiredA unique identifier that points to an image asset in Canva's backend.
flipX
boolean
OptionalIf true
, the image is flipped horizontally.
flipY
boolean
OptionalIf true
, the image is flipped vertically.
Options for creating a video fill in the element state builder
type
string
RequiredThe type of media.
This must be "video"
.
videoRef
VideoRef
RequiredA unique identifier that points to a video asset in Canva's backend.
flipX
boolean
OptionalIf true
, the video is flipped horizontally.
flipY
boolean
OptionalIf true
, the video is flipped vertically.
stroke
StrokeOpts
OptionalThe outline of the rect.
weight
number
RequiredThe weight (thickness) of the stroke.
Minimum: 0
Maximum: 100
colorContainer
ColorContainerOpts
RequiredThe color of the stroke.
type
string
Read-onlyRequiredThe type of color.
This must be "solid"
.
color
string
RequiredThe color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
Returns
A state that creates a rectangle element.
The rectangle can be filled with image content, video content, or a solid color.
type
string
Read-onlyThe type of content.
This must be "rect"
.
fill
FillState
Read-onlyThe appearance of the rectangle's interior.
mediaContainer
undefined | MediaFillState
The media fill for the path, if any.
A state that creates an image fill.
type
string
Read-onlyThe type of media.
This must be "image"
.
imageRef
ImageRef
Read-onlyA unique identifier that points to an image asset in Canva's backend.
flipX
boolean
If true
, the image is flipped horizontally.
flipY
boolean
If true
, the image is flipped vertically.
A state that creates a video fill.
type
string
Read-onlyThe type of media.
This must be "video"
.
videoRef
VideoRef
Read-onlyA unique identifier that points to a video asset in Canva's backend.
flipX
boolean
If true
, the video is flipped horizontally.
flipY
boolean
If true
, the video is flipped vertically.
colorContainer
undefined | ColorFillState
The color fill for the path, if any.
A state that creates a solid color fill.
type
string
Read-onlyThe type of color.
This must be "solid"
.
color
string
The color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
Represents something that's not supported by the Apps SDK.
type
string
Read-onlyThis must be "unsupported"
.
stroke
StrokeState
Read-onlyThe outline of the rectangle.
weight
number
The weight (thickness) of the stroke.
Minimum: 0
Maximum: 100
colorContainer
ColorFillState
The color of the stroke.
A state that creates a solid color fill.
type
string
Read-onlyThe type of color.
This must be "solid"
.
color
string
The color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
Represents something that's not supported by the Apps SDK.
type
string
Read-onlyThis must be "unsupported"
.
width
number
Read-onlyA width, in pixels.
height
number
Read-onlyA height, in pixels.
locked
boolean
Read-onlyIf true
, the element is locked and cannot be modified.
top
number
Read-onlyThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
Read-onlyThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
rotation
number
Read-onlyA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
Read-onlyTransparency as a percentage.
Minimum: 0
Maximum: 1
createShapeElement
function
RequiredCreates a shape element state.
Parameters
opts
CreateShapeElementOpts
RequiredOptions for creating the shape element.
top
number
RequiredThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
RequiredThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
width
number
RequiredA width, in pixels.
height
number
RequiredA height, in pixels.
viewBox
AlignedBoxState
Read-onlyRequiredThe scale and cropping of the shape.
top
number
Read-onlyRequiredThe distance of the shape from the top edge of the element, in pixels.
left
number
Read-onlyRequiredThe distance of the shape from the left edge of the element, in pixels.
width
number
Read-onlyRequiredThe width of the view box, in pixels.
height
number
Read-onlyRequiredThe height of the view box, in pixels.
paths
PathOpts[]
RequiredThe paths that define the structure of the shape.
- Must have between 1 and 30 paths.
- Total size of all paths must not exceed 2kb.
- Maximum of 6 unique fill colors across all paths.
d
string
Requiredfill
PathFillOpts
OptionalDescribes how a fill is filled with color or media.
If both media
and color
are defined, media
takes precedence.
colorContainer
ColorContainerOpts
type
string
Read-onlyRequiredThe type of color.
This must be "solid"
.
color
string
RequiredThe color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
mediaContainer
MediaContainerOpts
Options for creating a media fill in the element state builder
Options for creating an image fill in the element state builder
type
string
RequiredThe type of media.
This must be "image"
.
imageRef
ImageRef
RequiredA unique identifier that points to an image asset in Canva's backend.
flipX
boolean
OptionalIf true
, the image is flipped horizontally.
flipY
boolean
OptionalIf true
, the image is flipped vertically.
Options for creating a video fill in the element state builder
type
string
RequiredThe type of media.
This must be "video"
.
videoRef
VideoRef
RequiredA unique identifier that points to a video asset in Canva's backend.
flipX
boolean
OptionalIf true
, the video is flipped horizontally.
flipY
boolean
OptionalIf true
, the video is flipped vertically.
isMediaEditable
boolean
stroke
StrokeOpts
OptionalThe outline of the path.
weight
number
RequiredThe weight (thickness) of the stroke.
Minimum: 0
Maximum: 100
colorContainer
ColorContainerOpts
RequiredThe color of the stroke.
type
string
Read-onlyRequiredThe type of color.
This must be "solid"
.
color
string
RequiredThe color of the fill.
This must be a valid, six-digit hex code, prefixed with a #
symbol.
- Must be six characters long.
- Must start with a
#
. - Must use lowercase letters.
Example
"#ff0099"
rotation
number
OptionalA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
OptionalTransparency as a percentage.
Minimum: 0
Maximum: 1
Returns
A state that creates a vector shape element.
type
string
Read-onlyThe type of content.
This must be "shape"
.
viewBox
AlignedBoxState
Read-onlyThe scale and cropping of the shape.
top
number
Read-onlyThe distance of the shape from the top edge of the element, in pixels.
left
number
Read-onlyThe distance of the shape from the left edge of the element, in pixels.
width
number
Read-onlyThe width of the view box, in pixels.
height
number
Read-onlyThe height of the view box, in pixels.
paths
ListState<PathState>
Read-onlyThe paths that define the structure of the shape.
- Must have between 1 and 30 paths.
- Total size of all paths must not exceed 2kb.
- Maximum of 6 unique fill colors across all paths.
For more information, see ListState.
width
number
Read-onlyA width, in pixels.
height
number
Read-onlyA height, in pixels.
locked
boolean
Read-onlyIf true
, the element is locked and cannot be modified.
top
number
Read-onlyThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
Read-onlyThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
rotation
number
Read-onlyA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
Read-onlyTransparency as a percentage.
Minimum: 0
Maximum: 1
createEmbedElement
function
RequiredCreates an embed element state.
Parameters
opts
CreateEmbedElementOpts
RequiredOptions for creating the embed element.
top
number
RequiredThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
RequiredThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
width
number
RequiredA width, in pixels.
height
number
RequiredA height, in pixels.
url
string
RequiredThe URL of the rich media.
This URL must be supported by the Iframely API.
rotation
number
OptionalA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
OptionalTransparency as a percentage.
Minimum: 0
Maximum: 1
Returns
A state that creates an embed element, such as a YouTube video.
type
string
Read-onlyThe type of content.
This must be "embed"
.
url
string
Read-onlyThe URL of the rich media.
This URL must be supported by the Iframely API.
width
number
Read-onlyA width, in pixels.
height
number
Read-onlyA height, in pixels.
locked
boolean
Read-onlyIf true
, the element is locked and cannot be modified.
top
number
Read-onlyThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
Read-onlyThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
rotation
number
Read-onlyA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
Read-onlyTransparency as a percentage.
Minimum: 0
Maximum: 1
createTextElement
function
RequiredCreates a text element state.
Parameters
opts
CreateTextElementOpts
RequiredOptions for creating the text element.
top
number
RequiredThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
RequiredThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
width
number
RequiredA width, in pixels.
text
object
RequiredThe text content.
regions
TextRegion[]
RequiredA region of richtext.
text
string
RequiredThe plaintext content of the region.
formatting
Partial<RichtextFormatting>
OptionalThe formatting of the region.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
fontRef
FontRef
OptionalA unique identifier that points to a font asset in Canva's backend.
fontSize
number
OptionalThe size of the text, in pixels.
- In the Canva editor, this number is shown as points (pts), not pixels.
Minimum: 1
Maximum: 100
textAlign
string
OptionalThe alignment of the text.
Default value: "start"
Available values:
"start"
"center"
"end"
"justify"
listLevel
number
OptionalThe list indentation level of the paragraph.
listMarker
string
OptionalThe appearance of list item markers.
This property only has an effect if listLevel
is greater than 0.
Default value: "none"
Available values:
"none"
"disc"
"circle"
"square"
"decimal"
"lower-alpha"
"lower-roman"
"checked"
"unchecked"
rotation
number
OptionalA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
OptionalTransparency as a percentage.
Minimum: 0
Maximum: 1
Returns
A state that creates a text element.
type
string
Read-onlyThe type of content.
This must be "text"
.
text
object
Read-onlyThe text content.
regions
ListState<TextRegion>
A list of items that can be read.
For more information, see ListState.
width
number
Read-onlyA width, in pixels.
height
number
Read-onlyA height, in pixels.
locked
boolean
Read-onlyIf true
, the element is locked and cannot be modified.
top
number
Read-onlyThe distance from the top edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
left
number
Read-onlyThe distance from the left edge of the container, in pixels.
- The pixels are relative to their container.
Minimum: -32768
Maximum: 32767
rotation
number
Read-onlyA rotation, in degrees.
Minimum: -180
Maximum: 180
transparency
number
Read-onlyTransparency as a percentage.
Minimum: 0
Maximum: 1
createRichtextRange
function
RequiredCreates a richtext range.
Returns
Provides methods for interacting with a range of formatted text.
formatParagraph
function
Formats all of the paragraphs that overlap the given bounds.
- The
\n
character indicates the end of a paragraph. - All paragraphs that overlap the provided bounds will be formatted in their entirety.
Parameters
bounds
Bounds
RequiredThe segment of the range on which to apply the formatting.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
formatting
RichtextFormatting
RequiredThe formatting to apply to the paragraph(s).
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
fontRef
FontRef
OptionalA unique identifier that points to a font asset in Canva's backend.
fontSize
number
OptionalThe size of the text, in pixels.
- In the Canva editor, this number is shown as points (pts), not pixels.
Minimum: 1
Maximum: 100
textAlign
string
OptionalThe alignment of the text.
Default value: "start"
Available values:
"start"
"center"
"end"
"justify"
listLevel
number
OptionalThe list indentation level of the paragraph.
listMarker
string
OptionalThe appearance of list item markers.
This property only has an effect if listLevel
is greater than 0.
Default value: "none"
Available values:
"none"
"disc"
"circle"
"square"
"decimal"
"lower-alpha"
"lower-roman"
"checked"
"unchecked"
Returns
void
formatText
function
Formats a region of text with inline formatting properties.
Parameters
bounds
Bounds
RequiredThe segment of the range on which to apply the formatting.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
formatting
InlineFormatting
RequiredThe formatting to apply to the text.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
void
appendText
function
Appends the specified characters to the end of the range.
Parameters
characters
string
RequiredThe characters to append to the richtext range.
formatting
InlineFormatting
OptionalOptions for formatting inline richtext.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
bounds
Bounds
A segment of a richtext range.
index
number
The starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
The number of characters in the segment, starting from the index.
replaceText
function
Replaces a region of text with the specified characters.
Parameters
bounds
Bounds
RequiredThe segment of the range to replace.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
characters
string
RequiredThe replacement characters.
formatting
InlineFormatting
OptionalThe formatting to apply to the replaced text.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
bounds
Bounds
The bounds of the replacement characters within the updated range.
index
number
The starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
The number of characters in the segment, starting from the index.
readPlaintext
function
Returns the current state of the richtext as plaintext.
Returns
string
readTextRegions
function
Returns the current state of the richtext as one or more text regions. Each region is an object that contains the text content and its formatting.
Returns
text
string
The plaintext content of the region.
formatting
Partial<RichtextFormatting>
OptionalThe formatting of the region.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
fontRef
FontRef
OptionalA unique identifier that points to a font asset in Canva's backend.
fontSize
number
OptionalThe size of the text, in pixels.
- In the Canva editor, this number is shown as points (pts), not pixels.
Minimum: 1
Maximum: 100
textAlign
string
OptionalThe alignment of the text.
Default value: "start"
Available values:
"start"
"center"
"end"
"justify"
listLevel
number
OptionalThe list indentation level of the paragraph.
listMarker
string
OptionalThe appearance of list item markers.
This property only has an effect if listLevel
is greater than 0.
Default value: "none"
Available values:
"none"
"disc"
"circle"
"square"
"decimal"
"lower-alpha"
"lower-roman"
"checked"
"unchecked"