Text represents a text element in the Penpot application, extending the base shape interface. It includes various properties to define the text content and its styling attributes.

interface Text {
    getPluginData(key: string): string;
    setPluginData(key: string, value: string): void;
    getPluginDataKeys(): string[];
    getSharedPluginData(namespace: string, key: string): string;
    setSharedPluginData(namespace: string, key: string, value: string): void;
    getSharedPluginDataKeys(namespace: string): string[];
    id: string;
    name: string;
    parent: null | Shape;
    parentIndex: number;
    x: number;
    y: number;
    width: number;
    height: number;
    bounds: Bounds;
    center: Point;
    blocked: boolean;
    hidden: boolean;
    visible: boolean;
    proportionLock: boolean;
    constraintsHorizontal:
        | "center"
        | "left"
        | "right"
        | "leftright"
        | "scale";
    constraintsVertical:
        | "center"
        | "top"
        | "bottom"
        | "scale"
        | "topbottom";
    borderRadius: number;
    borderRadiusTopLeft: number;
    borderRadiusTopRight: number;
    borderRadiusBottomRight: number;
    borderRadiusBottomLeft: number;
    opacity: number;
    blendMode:
        | "difference"
        | "normal"
        | "darken"
        | "multiply"
        | "color-burn"
        | "lighten"
        | "screen"
        | "color-dodge"
        | "overlay"
        | "soft-light"
        | "hard-light"
        | "exclusion"
        | "hue"
        | "saturation"
        | "color"
        | "luminosity";
    shadows: Shadow[];
    blur?: Blur;
    exports: Export[];
    boardX: number;
    boardY: number;
    parentX: number;
    parentY: number;
    flipX: boolean;
    flipY: boolean;
    rotation: number;
    fills: Fill[] | "mixed";
    strokes: Stroke[];
    layoutChild?: LayoutChildProperties;
    layoutCell?: LayoutChildProperties;
    setParentIndex(index: number): void;
    isComponentInstance(): boolean;
    isComponentMainInstance(): boolean;
    isComponentCopyInstance(): boolean;
    isComponentRoot(): boolean;
    isComponentHead(): boolean;
    componentRefShape(): null | Shape;
    componentRoot(): null | Shape;
    componentHead(): null | Shape;
    component(): null | LibraryComponent;
    detach(): void;
    swapComponent(component: LibraryComponent): void;
    switchVariant(pos: number, value: string): void;
    combineAsVariants(ids: string[]): void;
    isVariantHead(): boolean;
    resize(width: number, height: number): void;
    rotate(angle: number, center?: null | {
        x: number;
        y: number;
    }): void;
    bringToFront(): void;
    bringForward(): void;
    sendToBack(): void;
    sendBackward(): void;
    export(config: Export): Promise<Uint8Array>;
    interactions: Interaction[];
    addInteraction(trigger: Trigger, action: Action, delay?: number): Interaction;
    removeInteraction(interaction: Interaction): void;
    clone(): Shape;
    remove(): void;
    type: "text";
    characters: string;
    growType: "fixed" | "auto-width" | "auto-height";
    fontId: string;
    fontFamily: string;
    fontVariantId: string;
    fontSize: string;
    fontWeight: string;
    fontStyle:
        | null
        | "normal"
        | "italic"
        | "mixed";
    lineHeight: string;
    letterSpacing: string;
    textTransform:
        | null
        | "mixed"
        | "uppercase"
        | "capitalize"
        | "lowercase";
    textDecoration:
        | null
        | "mixed"
        | "underline"
        | "line-through";
    direction:
        | null
        | "mixed"
        | "ltr"
        | "rtl";
    align:
        | null
        | "center"
        | "left"
        | "right"
        | "mixed"
        | "justify";
    verticalAlign:
        | null
        | "center"
        | "top"
        | "bottom";
    getRange(start: number, end: number): TextRange;
    applyTypography(typography: LibraryTypography): void;
}

Hierarchy (view full)

Properties

id: string

The unique identifier of the shape.

name: string

The name of the shape.

parent: null | Shape

The parent shape. If the shape is the first level the parent will be the root shape. For the root shape the parent is null

parentIndex: number

Returns the index of the current shape in the parent

x: number

The x-coordinate of the shape's position.

y: number

The y-coordinate of the shape's position.

width: number

The width of the shape.

height: number

The height of the shape.

bounds: Bounds

Returns the bounding box surrounding the current shape

center: Point

Returns the geometric center of the shape

blocked: boolean

Indicates whether the shape is blocked.

hidden: boolean

Indicates whether the shape is hidden.

visible: boolean

Indicates whether the shape is visible.

proportionLock: boolean

Indicates whether the shape has proportion lock enabled.

constraintsHorizontal:
    | "center"
    | "left"
    | "right"
    | "leftright"
    | "scale"

The horizontal constraints applied to the shape.

constraintsVertical:
    | "center"
    | "top"
    | "bottom"
    | "scale"
    | "topbottom"

The vertical constraints applied to the shape.

borderRadius: number

The border radius of the shape.

borderRadiusTopLeft: number

The border radius of the top-left corner of the shape.

borderRadiusTopRight: number

The border radius of the top-right corner of the shape.

borderRadiusBottomRight: number

The border radius of the bottom-right corner of the shape.

borderRadiusBottomLeft: number

The border radius of the bottom-left corner of the shape.

opacity: number

The opacity of the shape.

blendMode:
    | "difference"
    | "normal"
    | "darken"
    | "multiply"
    | "color-burn"
    | "lighten"
    | "screen"
    | "color-dodge"
    | "overlay"
    | "soft-light"
    | "hard-light"
    | "exclusion"
    | "hue"
    | "saturation"
    | "color"
    | "luminosity"

The blend mode applied to the shape.

shadows: Shadow[]

The shadows applied to the shape.

blur?: Blur

The blur effect applied to the shape.

exports: Export[]

The export settings of the shape.

boardX: number

The x-coordinate of the shape relative to its board.

boardY: number

The y-coordinate of the shape relative to its board.

parentX: number

The x-coordinate of the shape relative to its parent.

parentY: number

The y-coordinate of the shape relative to its parent.

flipX: boolean

Indicates whether the shape is flipped horizontally.

flipY: boolean

Indicates whether the shape is flipped vertically.

rotation: number

Returns the rotation in degrees of the shape with respect to it's center.

fills: Fill[] | "mixed"

The fills applied to the shape.

strokes: Stroke[]

The strokes applied to the shape.

layoutChild?: LayoutChildProperties

Layout properties for children of the shape.

Layout properties for cells in a grid layout.

interactions: Interaction[]

The interactions for the current shape.

type

The type of the shape, which is always 'text' for text shapes.

characters: string

The characters contained within the text shape.

growType: "fixed" | "auto-width" | "auto-height"

The grow type of the text shape, defining how the text box adjusts its size. Possible values are:

  • 'fixed': Fixed size.
  • 'auto-width': Adjusts width automatically.
  • 'auto-height': Adjusts height automatically.
fontId: string

The font ID used in the text shape, or 'mixed' if multiple fonts are used.

fontFamily: string

The font family used in the text shape, or 'mixed' if multiple font families are used.

fontVariantId: string

The font variant ID used in the text shape, or 'mixed' if multiple font variants are used.

fontSize: string

The font size used in the text shape, or 'mixed' if multiple font sizes are used.

fontWeight: string

The font weight used in the text shape, or 'mixed' if multiple font weights are used.

fontStyle:
    | null
    | "normal"
    | "italic"
    | "mixed"

The font style used in the text shape, or 'mixed' if multiple font styles are used.

lineHeight: string

The line height used in the text shape, or 'mixed' if multiple line heights are used.

letterSpacing: string

The letter spacing used in the text shape, or 'mixed' if multiple letter spacings are used.

textTransform:
    | null
    | "mixed"
    | "uppercase"
    | "capitalize"
    | "lowercase"

The text transform applied to the text shape, or 'mixed' if multiple text transforms are used.

textDecoration:
    | null
    | "mixed"
    | "underline"
    | "line-through"

The text decoration applied to the text shape, or 'mixed' if multiple text decorations are used.

direction:
    | null
    | "mixed"
    | "ltr"
    | "rtl"

The text direction for the text shape, or 'mixed' if multiple directions are used.

align:
    | null
    | "center"
    | "left"
    | "right"
    | "mixed"
    | "justify"

The horizontal alignment of the text shape. It can be a specific alignment or 'mixed' if multiple alignments are used.

verticalAlign:
    | null
    | "center"
    | "top"
    | "bottom"

The vertical alignment of the text shape. It can be a specific alignment or 'mixed' if multiple alignments are used.

Methods

  • Retrieves the data for our own plugin, given a specific key.

    Parameters

    • key: string

      The key for which to retrieve the data.

    Returns string

    Returns the data associated with the key as a string.

    const data = shape.getPluginData('exampleKey');
    console.log(data);
  • Sets the plugin-specific data for the given key.

    Parameters

    • key: string

      The key for which to set the data.

    • value: string

      The data to set for the key.

    Returns void

    shape.setPluginData('exampleKey', 'exampleValue');
    
  • Retrieves all the keys for the plugin-specific data.

    Returns string[]

    Returns an array of strings representing all the keys.

    const keys = shape.getPluginDataKeys();
    console.log(keys);
  • If we know the namespace of an external plugin, this is the way to get their data.

    Parameters

    • namespace: string

      The namespace for the shared data.

    • key: string

      The key for which to retrieve the data.

    Returns string

    Returns the shared data associated with the key as a string.

    const sharedData = shape.getSharedPluginData('exampleNamespace', 'exampleKey');
    console.log(sharedData);
  • Sets the shared plugin-specific data for the given namespace and key.

    Parameters

    • namespace: string

      The namespace for the shared data.

    • key: string

      The key for which to set the data.

    • value: string

      The data to set for the key.

    Returns void

    shape.setSharedPluginData('exampleNamespace', 'exampleKey', 'exampleValue');
    
  • Retrieves all the keys for the shared plugin-specific data in the given namespace.

    Parameters

    • namespace: string

      The namespace for the shared data.

    Returns string[]

    Returns an array of strings representing all the keys in the namespace.

    const sharedKeys = shape.getSharedPluginDataKeys('exampleNamespace');
    console.log(sharedKeys);
  • Changes the index inside the parent of the current shape. This method will shift the indexes of the shapes around that position to match the index. If the index is greater than the number of elements it will positioned last.

    Parameters

    • index: number

      the new index for the shape to be in

    Returns void

  • Returns null | Shape

    Returns the root of the component tree structure for the current shape. If the current shape is already a root will return itself.

  • Returns null | Shape

    Returns the head of the component tree structure for the current shape. If the current shape is already a head will return itself.

  • If the current shape is a component it will remove the component information and leave the shape as a "basic shape"

    Returns void

  • Switch a VariantComponent copy to the nearest one that has the specified property value

    Parameters

    • pos: number

      The position of the poroperty to update

    • value: string

      The new value of the property

    Returns void

  • Combine several standard Components into a VariantComponent. Similar to doing it with the contextual menu on the Penpot interface. The current shape must be a component main instance.

    Parameters

    • ids: string[]

      A list of ids of the main instances of the components to combine with this one.

    Returns void

  • Returns boolean

    Returns true when the current shape is the head of a components tree nested structure, and that component is a VariantComponent

  • Resizes the shape to the specified width and height.

    Parameters

    • width: number

      The new width of the shape.

    • height: number

      The new height of the shape.

    Returns void

    shape.resize(200, 100);
    
  • Rotates the shape in relation with the given center.

    Parameters

    • angle: number

      Angle in degrees to rotate.

    • Optionalcenter: null | {
          x: number;
          y: number;
      }

      Center of the transform rotation. If not send will use the geometri center of the shapes.

    Returns void

    shape.rotate(45);
    
  • Generates an export from the current shape.

    Parameters

    Returns Promise<Uint8Array>

    shape.export({ type: 'png', scale: 2 });
    
  • Adds a new interaction to the shape.

    Parameters

    • trigger: Trigger

      defines the conditions under which the action will be triggered

    • action: Action

      defines what will be executed when the trigger happens

    • Optionaldelay: number

      for the type of trigger after-delay will specify the time after triggered. Ignored otherwise.

    Returns Interaction

    shape.addInteraction('click', { type: 'navigate-to', destination: anotherBoard });
    
  • Removes the interaction from the shape.

    Parameters

    • interaction: Interaction

      is the interaction to remove from the shape

    Returns void

    shape.removeInteraction(interaction);
    
  • Gets a text range within the text shape.

    Parameters

    • start: number

      The start index of the text range.

    • end: number

      The end index of the text range.

    Returns TextRange

    Returns a TextRange object representing the specified text range.

    const textRange = textShape.getRange(0, 10);
    console.log(textRange.characters);
  • Applies a typography style to the text shape.

    Parameters

    Returns void

    This method sets various typography properties for the text shape according to the given typography style.

    textShape.applyTypography(typography);