Pixso Open Documentation
guide
  • 中文
  • English
guide
  • 中文
  • English
  • Plugin API

    • Brief Introduction
    • Prerequisites
    • manifest
    • Development Guide
    • Change Log
    • Plugin API Documentation

      • Overview
      • Global Object

        • pixso
        • pixso.ui
        • pixso.host
        • pixso.mouse
        • pixso.editor
        • pixso.keyboard
        • pixso.fieldset
        • pixso.viewport
        • pixso.vectorEditor
        • pixso.clientStorage
        • pixso.serverStorage
      • Node Types

        • BooleanOperationNode
        • ComponentNode
        • ComponentSetNode
        • DocumentNode
        • EllipseNode
        • FrameNode
        • GroupNode
        • InstanceNode
        • LineNode
        • PageNode
        • PolygonNode
        • RectangleNode
        • SectionNode
        • SliceNode
        • StarNode
        • TextNode
        • VectorNode
      • Data Types

        • Action
        • ArcData
        • BlendMode
        • CommandItem
        • ComponentProperties-Related
        • Constraints
        • DialogType
        • DocumentationLink
        • Effect
        • EmbedData
        • ExportSettings
        • FontName
        • Guide
        • HandleMirroring
        • HyperlinkTarget
        • Image
        • LayoutGrid
        • LetterSpacing
        • Library
        • LineHeight
        • NodeChangeProperty
        • OverflowDirection
        • Overlay
        • Paint
        • PublishStatus
        • Reaction
        • Rect-related
        • RGB & RGBA
        • StrokeCap
        • StrokeJoin
        • StyleChangeProperty
        • TextCase
        • TextDecoration
        • TextListOptions
        • ThemeType
        • ToolType
        • Transition
        • Trigger
        • Vector
    • Host API Documentation

      • Overview
      • Host API
  • Open API

    • OpenAPI Doc

TextNode

The text node represents text where both the whole node or individual character ranges can have properties such as color (fills), font size, font name, etc. When working with text nodes, there are a lot of things to consider, including mixed styles, loading fonts, and missing fonts.

Text node properties

type

  • Readonly: true
  • Type: TEXT

The type of this node, represented by the string literal TEXT

clone

  • Type: clone(): TextNode

Duplicates the text node.

hasMissingFont

  • Readonly: true
  • Type: boolean

Returns whether the text uses a font currently not available to the document.

textAlignHorizontal

  • Type: "LEFT" | "CENTER" | "RIGHT" | "JUSTIFIED"

The horizontal alignment of the text with respect to the textbox. Setting this property requires the font the be loaded.

textAlignVertical

  • Type: "TOP" | "CENTER" | "BOTTOM"

The vertical alignment of the text with respect to the textbox. Setting this property requires the font the be loaded.

textAutoResize

  • Type: "NONE" | "WIDTH_AND_HEIGHT" | "HEIGHT" | "TRUNCATE"

The behavior of how the size of the text box adjusts to fit the characters. Setting this property requires the font the be loaded.

paragraphSpacing

  • Type: number

The vertical distance between paragraphs. Setting this property requires the font to be loaded.

autoRename

  • Type: boolean

Whether updating the characters in the text node should update the name of the node.

Text content

characters

  • Type: string

The raw characters in the text node. Setting this property requires the font the be loaded.

insertCharacters

  • Type: insertCharacters(start: number,characters: string,useStyle?: "BEFORE" | "AFTER"): void

Insert characters at index start in the text, the first character in the text has an index of 0. The style of the inserted character will be consistent with the style of the previous character at that position. If a character is inserted at position 0, the style of the inserted character will match the style of the next character at that position because there are no other characters preceding it. Setting this property requires ensuring that the font is loaded.

deleteCharacters

  • Type: deleteCharacters(start: number, end: number): void

Remove characters in the text from start (inclusive) to end (exclusive).

Text range properties

fontSize

  • Type: number | pixso.mixed

The size of the font. Has minimum value of 1.

fontName

  • Type: FontName | pixso.mixed
  • Type Declaration: FontName

The font fa value mily (e.g. "Inter"), and font style (e.g. "Regular"). Setting this property to a different requires the new font to be loaded.

textCase

  • Type: TextCase | pixso.mixed Overrides the case of the raw characters in the text node. Requires the font to be loaded.
  • Type Declaration: TextCase

textDecoration

  • Type: TextDecoration | pixso.mixed
  • Type Declaration: TextDecoration

Whether the text is underlined or has a strikethrough. Requires the font to be loaded.

letterSpacing

  • Type: LetterSpacing | pixso.mixed
  • Type Declaration: LetterSpacing

The spacing between the individual characters. Requires the font to be loaded.

lineHeight

  • Type: LineHeight | pixso.mixed
  • Type Declaration: LineHeight

The spacing between the lines in a paragraph of text. Requires the font to be loaded.

textStyleId

  • Type: sring | pixso.mixed

The id of the TextStyle object that the text properties of this node are linked to. Requires the font to be loaded.

hyperlink

  • Type: HyperlinkTarget | null | pixso.mixed
  • Type Declaration: HyperlinkTarget

A HyperlinkTarget if the text node has exactly one hyperlink, or null if the node has none.

Text range functions

getRangeFontSize

  • Type: getRangeFontSize(start: number, end: number): number | pixso.mixed

Get the fontSize from characters in range start (inclusive) to end (exclusive).

setRangeFontSize

  • Type: setRangeFontSize(start: number, end: number, value: number): void

Set the fontSize from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeFontName

  • Type: getRangeFontName(start: number,end: number): FontName | pixso.mixed

Get the fontName from characters in range start (inclusive) to end (exclusive).

setRangeFontName

  • Type: setRangeFontName(start: number, end: number, value: FontName): void

Set the fontName from characters in range start (inclusive) to end (exclusive). Requires the new font to be loaded.

getRangeAllFontNames

  • Type: getRangeAllFontNames(start: number, end: number): FontName[]

Get the fontNames from characters in range start (inclusive) to end (exclusive).

getRangeTextCase

  • Type: getRangeTextCase(start: number,end: number): TextCase | pixso.mixed
  • Type Declaration: TextCase

Get the textCase from characters in range start (inclusive) to end (exclusive).

setRangeTextCase

  • Type: setRangeTextCase(start: number, end: number, value: TextCase): void

Set the textCase from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeTextDecoration

  • Type: getRangeTextDecoration(start: number,end: number): TextDecoration | pixso.mixed
  • Type Declaration: TextDecoration

Get the textDecoration from characters in range start (inclusive) to end (exclusive).

setRangeTextDecoration

  • Type: setRangeTextDecoration(start: number,end: number,value: TextDecoration): void

Set the textDecoration from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeLetterSpacing

  • Type: getRangeLetterSpacing(start: number,end: number): LetterSpacing | pixso.mixed
  • Type Declaration: LetterSpacing

Get the letterSpacing from characters in range start (inclusive) to end (exclusive).

setRangeLetterSpacing

  • Type: setRangeLetterSpacing(start: number,end: number,value: LetterSpacing): void

Set the letterSpacing from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeLineHeight

  • Type: getRangeLineHeight(start: number,end: number): LineHeight | pixso.mixed
  • Type Declaration: LineHeight

Get the lineHeight from characters in range start (inclusive) to end (exclusive).

setRangeLineHeight

  • Type: setRangeLineHeight(start: number, end: number, value: LineHeight): void

Set the lineHeight from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeHyperlink

  • Type: getRangeHyperlink(start: number,end: number): HyperlinkTarget | null | pixso.mixed
  • Type Declaration: HyperlinkTarget

Get the hyperlink from characters in range start (inclusive) to end (exclusive). Returns a HyperlinkTarget if the range contains exactly one hyperlink, or null if the range contains none.

setRangeHyperlink

  • Type: setRangeHyperlink(start: number,end: number,value: HyperlinkTarget | null): void

Set the hyperlink from characters in range start (inclusive) to end (exclusive). Removes the hyperlink in range if value is null.

getRangeFills

  • Type: getRangeFills(start: number, end: number): Paint[] | pixso.mixed
  • Type Declaration: Paint

Get the fills from characters in range start (inclusive) to end (exclusive).

setRangeFills

  • Type: setRangeFills(start: number, end: number, value: Paint[]): void

Set the fills from characters in range start (inclusive) to end (exclusive). Requires font to be loaded.

getRangeTextStyleId

  • Type: getRangeTextStyleId(start: number,end: number): string | pixso.mixed

Get the textStyleId from characters in range start (inclusive) to end (exclusive).

setRangeTextStyleId

  • Type: setRangeTextStyleId(start: number, end: number, value: string): void

Set the textStyleId from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

getRangeFillStyleId

  • Type: getRangeFillStyleId(start: number,end: number): string | pixso.mixed

Get the fillStyleId from characters in range start (inclusive) to end (exclusive).

setRangeFillStyleId

  • Type: setRangeFillStyleId(start: number, end: number, value: string): void

Set the fillStyleId from characters in range start (inclusive) to end (exclusive). Requires the font to be loaded.

Base node properties

id

  • Readonly: true
  • Type: string

The ID of current node.

parent

  • Readonly: true
  • Type: (BaseNode & ChildrenMixin) | null

Get the parent node of the current node.

index

  • Readonly: true
  • Type: number

Get the sequential index of the current node at the same level.

name

  • Type: string

The name of the layer that appears in the layers panel.

removed

  • Readonly: true
  • Type: boolean

Returns true if the node was removed. if the plugin stays open for a while and stores references to the node, you should defensively write code and check that the node has not been removed by the user.

toString

  • Type: string

Returns a string representation of the node.

remove

  • Type: remove():void

Removes this node and all of its children from the document.

setRelaunchData

  • Type: data: {[command: string]: string}): void

Sets state on the node to show a button and description when the node is selected.

getRelaunchData

  • Type: getRelaunchData(): { [command: string]: string }

Retreives the reluanch data stored on this node using setRelaunchData

getPluginData

  • Type: getPluginData(key: string): string

Retrieves custom information that was stored on this node or style. To get a value type other than a string, decode it first via JSON.parse.

setPluginData

  • Type: setPluginData(key: string, value: string): void

Lets you store custom information on any node or style, private to your plugin. If you want to store a value type other than a string, please encode it first via JSON.stringify.

getPluginDataKeys

  • Type: getPluginDataKeys(): string[]

Retrieves a list of all keys stored on this node or style.

getSharedPluginData

  • Type: getSharedPluginData(namespace: string, key: string): string

Get the shared data stored on a specific namespace.

setSharedPluginData

  • Type: setSharedPluginData(namespace: string, key: string, value: string): void

This allows you to store custom information on any node. You can retrieve it later by calling getSharedPluginData with the same namespace and key. To find all the data on a node stored in a specific namespace, use getSharpedPluginDataKeys.

Any data you write using this API can be read by any plug-in. The purpose is to allow plugins to interoperate with each other. If you do not want other plugins to be able to read your data, use setPluginData instead.

You must also provide the namespace parameter to avoid key conflicts with other plugins. This parameter is mandatory to prevent multiple plugins from using common key names (such as data) and overwriting each other. We recommend passing a value that identifies your plugin. This namespace can be provided to the authors of other plugins so that they can read data from your plugin.

namespace is a unique string used to identify your plugin and avoid key conflicts with other plugins. The namespace must contain at least 3 alphanumeric characters.

getSharedPluginDataKeys

  • Type: getSharedPluginDataKeys(namespace: string): string[]

Retrieves a list of all keys stored on this node or style using setSharedPluginData. This enables iterating through all data stored in a given namespace.

Scene node properties

visible

  • Type: boolean

Whether the node is visible or not. This property does not affect the ability of the plugin to access the node.

locked

  • Type: boolean

Whether the node is locked to prevent certain user interactions on the canvas, such as selection and dragging. This property does not affect the ability of the plugin to write these properties.

componentPropertyReferences

  • Type: { [nodeProperty in 'visible' | 'characters' | 'mainComponent']?: string} | null

All component properties that are attached on this node. The value in the key-value pair refers to the component property name as returned by componentPropertyDefinitions on the containing component, component set or main component (for instances).

A node can only have componentPropertyReferences if it is a component sublayer or an instance sublayer。

Blend-related

opacity

  • Type: number

Reads or sets the transparency of the layer, the value of which must be in the [0, 1] range.

blendMode

  • Type: BlendMode
  • Type Declaration: BlendMode

The blend mode of the layer.

isMask

  • Type: boolean

Whether the layer is a mask or not.

effects

  • Type: ReadonlyArray<Effect>

Returns an array of effects, see Effect for details on the data structure.

effectStyleId

  • Type: string

The id of the effect style linked to the current node, i.e. the id of the EffectStyle object linked to the effects property of the current node.

Layout-related

x

  • Type: number

The position of the layer node, equivalent to relativeTransform[0][2].

y

  • Type: number

The position of the layer node, equivalent to relativeTransform[1][2].

width

  • Readonly: true
  • Type: number

The width of the layer node.

height

  • Readonly: true
  • Type: number

The height of the layer node.

relativeTransform

  • Type: Transform
  • Type Declaration: Transform

The position of the layer node relative to its parent is represented as a transformation matrix. Note: relativeTransform does not work for auto layout normal sublayers. Relativetransform still works for sublayers with absolute positioning.

absoluteTransform

  • Readonly: true
  • Type: Transform
  • Type Declaration: Transform

The position of a layer node relative to the page containing it is presented as a transformation matrix.

absoluteBoundingBox

  • Readonly: true
  • Type: Rect | null
  • Type Declaration: Rect

Node boundaries that do not include rendering attributes such as shadows or strokes.

getNestedBoundaryBox

  • Type:getNestedBoundaryBox(): NestedBoundaryBox
  • Type Declaration: NestedBoundaryBox

Get the boundaryBox information of the current layer and all its sublayers

absoluteRenderBounds

  • Readonly: true
  • Type: Rect | null
  • Type Declaration: Rect

The actual boundaries of the node, including shadows, bold strokes, and anything else that might fall outside the node's regular bounding box, which is defined in x, y, width, and in height. x and y inside this property represents the absolute position of the node on the page. If the node is not visible, this value will be null.

constrainProportions

  • Type: boolean

After the switch, when the user resizes the layer via the Properties panel, it makes the layer maintain its scale.

rotation

  • Type: number

The rotation angle of the layer node. The value range is [-180, 180]. The values are equivalent to.

Math.atan2(-relativeTransform[1][0], relativeTransform[0][0]);

layoutAlign

  • Type: "STRETCH" | "INHERIT"

Applies only to direct child levels of the auto layout frame, otherwise ignore. Determines if the layer should be stretched along the inverse axis of the parent. The default is INHERIT.

layoutGrow

  • Type: number

This property applies only to direct child levels of the auto layout frame, otherwise it is ignored. Determines whether the layer should be stretched along the main axis of its parent. 0 corresponds to fixed size, 1 to stretched.

resize

  • Type: resize(width: number, height: number): void

Resizes the node. If the node contains child nodes with constraints, it applies those constraints during resizing. If the parent has an automatic layout, it causes the parent to resize.

resizeWithoutConstraints

  • Type: resizeWithoutConstraints(width: number, height: number): void

Resize nodes. If the parent is not automatically laid out, the children of the node will never resize, even if those children are constrained. If the parent has automatic layout, the parent child nodes and nodes of the node are resized (this constraint cannot be ignored).

rescale

  • Type: rescale(scale: number): void

Rescales the node. This API function is the equivalent of using the Scale Tool from the toolbar.

constraints

  • Type: Constraints
  • Type Declaration: Constraints

Constraints of this node relative to its containing FrameNode, if any.

Geometry-related

fills

  • Type: ReadonlyArray<Paint> | pixso.mixed
  • Type Declaration: Paint

The fill of the layer.

// set fills
node.fills = newFills;

fillStyleId

  • Type: string | pixso.mixed

The id of the fill style linked to the current node, i.e. the id of the PaintStyle object linked to the fills property of the current node.

strokes

  • Type: ReadonlyArray<Paint>
  • Type Declaration: Paint

Stroke of the layer.

strokeStyleId

  • Type: string

The id of the stroke style linked to the current node, i.e. the id of the PaintStyle object linked to the strokes property of the current node.

strokeWeight

  • Type: number

The thickness of the stroke in all four directions, in pixels. It must be non-negative and can be a decimal number. Note that if a single-edge stroke is set such as strokeTopWeight, the single-edge stroke will prevail; if strokeWeight is set, a single-edge stroke in all four directions will be set at the same time.

strokeJoin

  • Type: StrokeJoin | pixso.mixed
  • Type Declaration: StrokeJoin

Edge decoration.

  • 'MITER'
  • 'BEVEL'
  • 'ROUND'

strokeAlign

  • Type: "CENTER" | "INSIDE" | "OUTSIDE"

The alignment of the stroke relative to the layer boundary.

  • 'CENTER'
  • 'INSIDE'
  • 'OUTSIDE'

dashPattern

  • Type: ReadonlyArray<number>

Specifies a list of numbers in pixels for the length of alternate strokes and gaps.

strokeCap

  • Type: StrokeCap | pixso.mixed
  • Type Declaration: StrokeCap

The endpoints are decorated.

strokeMiterLimit

  • Type: number

The miter limit on the stroke. This is the same as the SVG miter limit.

Reaction prototyping-related

reactions

  • Type: ReadonlyArray<Reaction>

A list of reactions on this node, which includes the methods in the prototype that interact with this node and the behavior of that interaction.

Export-related

exportSettings

  • Type: exportSettings: ReadonlyArray<ExportSettings>
  • Type Declaration: ExportSettings

The export settings for the node.

exportAsync

  • Type: exportAsync(settings?: ExportSettings): Promise<Uint8Array>
  • Type Declaration: ExportSettings

Export the node as a encoded image.

HWDC

exportJsonAsync

  • Type: exportJsonAsync(): Promise<string>

Export the JSON data of the node, which includes all the information of the node.

exportHexAsync

  • Type: exportHexAsync(hex: string): Promise<string>

Export the Hex data of the node, which includes all the information of the node.


Prev
StarNode
Next
VectorNode