Home Reference Source
import {Layer} from './api/Layer.js'
public class | source

Layer

Extends:

WrappedObject → Layer

Direct Subclass:

Indirect Subclass:

Represents a Sketch layer.

Static Method Summary

Static Public Methods
public static

tests(): dictionary

Return a list of tests to run for this class.

Constructor Summary

Public Constructor
public

constructor(layer: MSLayer, document: Document)

Make a new layer object.

Member Summary

Public Members
public get

Return the parent container of this layer.

public get

The frame of the layer.

public set

frame(frame: Rectangle): *

Set the frame of the layer.

public get

Return the index of this layer in it's container. The layer at the back of the container (visualy) will be layer 0. The layer at the front will be layer n - 1 (if there are n layers).

public get

Is this an artboard?

public get

isGroup: bool: boolean

Is this a group?

public get

isImage: bool: boolean

Is this an image layer?

public get

isPage: bool: boolean

Is this a page?

public get

isShape: bool: boolean

Is this a shape layer?

public get

isText: bool: boolean

Is this a text layer?

public set

name(name: string): *

Set the name of the layer.

public get

name: string: *

The name of the layer.

Method Summary

Public Methods
public

Add this layer to the selected layers.

public

Deselect this layer.

public

Duplicate this layer.

public

export(options: dictionary)

Export this layer (and the ones below it), using the options supplied.

public

Returns a list of export options with any missing ones replaced by default values.

public

Convert a rectangle in the coordinates that this layer uses to absolute (page) coordinates.

public

Convert a rectangle in the coordinates that this layer uses to it's parent's coordinates.

public

Move this layer backwards in its container.

public

Move this layer forward in its container.

public

Move this layer to the back of its container.

public

Move this layer to the front of its container.

public

remove()

Remove this layer from its parent.

public

select()

Select the layer.

Inherited Summary

From class WrappedObject
public static

tests(): dictionary

Return a list of tests to run for this class.

public get

id: string: *

Returns the object ID of the wrapped Sketch model object.

public get

Returns the wrapped Sketch object.

Static Public Methods

public static tests(): dictionary source

Return a list of tests to run for this class.

Return:

dictionary

A dictionary containing the tests to run. Each key is the name of a test, each value is a function which takes a Tester instance.

Public Constructors

public constructor(layer: MSLayer, document: Document) source

Make a new layer object.

Params:

NameTypeAttributeDescription
layer MSLayer

The underlying model object from Sketch.

document Document

The document that the layer belongs to.

Public Members

public get container: Group: * source

Return the parent container of this layer.

Return:

Group

The containing layer of this layer.

public get frame: Rectangle: * source

The frame of the layer. This is given in coordinates that are local to the parent of the layer.

Return:

Rectangle

The layer's frame.

public set frame(frame: Rectangle): * source

Set the frame of the layer. This will move and/or resize the layer as appropriate. The new frame should be given in coordinates that are local to the parent of the layer.

public get index: number: * source

Return the index of this layer in it's container. The layer at the back of the container (visualy) will be layer 0. The layer at the front will be layer n - 1 (if there are n layers).

Return:

number

The layer order.

public get isArtboard: *: boolean source

Is this an artboard?

All Layer objects respond to this method, but only Artboard objects return true.

Return:

*

true for instances of Artboard, false for any other layer type.

public get isGroup: bool: boolean source

Is this a group?

All Layer objects respond to this method, but only Groups or things that inherit from groups return true.

Return:

bool

true for instances of Group, false for any other layer type.

public get isImage: bool: boolean source

Is this an image layer?

All Layer objects respond to this method, but only image layers return true.

Return:

bool

true for instances of Group, false for any other layer type.

public get isPage: bool: boolean source

Is this a page?

All Layer objects respond to this method, but only pages return true.

Return:

bool

true for instances of Group, false for any other layer type.

public get isShape: bool: boolean source

Is this a shape layer?

All Layer objects respond to this method, but only shape layers (rectangles, ovals, paths etc) return true.

Return:

bool

true for instances of Group, false for any other layer type.

public get isText: bool: boolean source

Is this a text layer?

All Layer objects respond to this method, but only text layers return true.

Return:

bool

true for instances of Group, false for any other layer type.

public set name(name: string): * source

Set the name of the layer.

public get name: string: * source

The name of the layer.

Return:

string

The layer's name.

Public Methods

public addToSelection() source

Add this layer to the selected layers. Any other layers that were previously selected will remain selected.

public deselect() source

Deselect this layer. Any other layers that were previously selected will remain selected.

public duplicate(): Layer source

Duplicate this layer. A new identical layer will be inserted into the parent of this layer.

Return:

Layer

A new layer identical to this one.

public export(options: dictionary) source

Export this layer (and the ones below it), using the options supplied.

Params:

NameTypeAttributeDescription
options dictionary

Options indicating which layers to export, which sizes and formats to use, etc.

public exportOptionsMergedWithDefaults(options: *): * source

Returns a list of export options with any missing ones replaced by default values.

Params:

NameTypeAttributeDescription
options *

Return:

*

public localRectToPageRect(rect: Rectangle): Rectangle source

Convert a rectangle in the coordinates that this layer uses to absolute (page) coordinates.

Params:

NameTypeAttributeDescription
rect Rectangle

The rectangle to convert.

Return:

Rectangle

The converted rectangle expressed in page coordinates.

public localRectToParentRect(rect: Rectangle): Rectangle source

Convert a rectangle in the coordinates that this layer uses to it's parent's coordinates.

Params:

NameTypeAttributeDescription
rect Rectangle

The rectangle to convert.

Return:

Rectangle

The converted rectangle expressed in the coordinate system of the parent layer.

public moveBackward() source

Move this layer backwards in its container.

public moveForward() source

Move this layer forward in its container.

public moveToBack() source

Move this layer to the back of its container.

public moveToFront() source

Move this layer to the front of its container.

public remove() source

Remove this layer from its parent.

public select() source

Select the layer. This will clear the previous selection. Use addToSelection() if you wish to preserve the existing selection.

See something wrong or incomplete? Improve this page.