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

Document

Extends:

WrappedObject → Document

A Sketch document.

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(document: MSDocument, application: Application)

Make a new document object.

Member Summary

Public Members
public get

pages: list: *

Returns a list of the pages in this document.

public get

The layers that the user has selected in the currently selected page.

public get

The current page that the user has selected.

Method Summary

Public Methods
public

Center the view of the document window on a given layer.

public

iterateWithNativeLayers(layers: array, filter: function(layer: Layer), block: function(layer: Layer))

Iterate through a bunch of native Sketch layers, executing a block.

public

layerNamed(layer_name: *): Layer

Find the first layer in this document which has the given name.

public

layerWithID(layer_id: *): Layer

Find the first layer in this document which has the given id.

public

wrapObject(sketchObject: object): WrappedObject

Return a wrapped version of a Sketch object.

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(document: MSDocument, application: Application) source

Make a new document object.

Params:

NameTypeAttributeDescription
document MSDocument

The underlying MSDocument object.

application Application

The application object.

Note that constructing one of these doesn't actually create a Sketch document. Instead you pass in the underlying MSDocument that this object represents.

If you do want to create a new document, you can do so with Application#newDocument.

Public Members

public get pages: list: * source

Returns a list of the pages in this document.

Return:

list

The pages.

public get selectedLayers: Selection: * source

The layers that the user has selected in the currently selected page.

Return:

Selection

A selection object representing the layers that the user has selected in the currently selected page.

public get selectedPage: Page: * source

The current page that the user has selected.

Return:

Page

A page object representing the page that the user is currently viewing.

Public Methods

public centerOnLayer(layer: Layer) source

Center the view of the document window on a given layer.

Params:

NameTypeAttributeDescription
layer Layer

The layer to center on.

public iterateWithNativeLayers(layers: array, filter: function(layer: Layer), block: function(layer: Layer)) source

Iterate through a bunch of native Sketch layers, executing a block. Used internally by Group and Selection.

Params:

NameTypeAttributeDescription
layers array

The layers to iterate over.

filter function(layer: Layer)

A filter function to call for each layer. If it returns false, the layer is skipped.

block function(layer: Layer)

The function to execute for each layer.

public layerNamed(layer_name: *): Layer source

Find the first layer in this document which has the given name.

Params:

NameTypeAttributeDescription
layer_name *

Return:

Layer

A layer object, if one was found.

public layerWithID(layer_id: *): Layer source

Find the first layer in this document which has the given id.

Params:

NameTypeAttributeDescription
layer_id *

Return:

Layer

A layer object, if one was found.

public wrapObject(sketchObject: object): WrappedObject source

Return a wrapped version of a Sketch object. We don't know about all Sketch object types, but for some we will return a special subclass. The fallback position is just to return an instance of WrappedObject.

Params:

NameTypeAttributeDescription
sketchObject object

The underlying sketch object that we're wrapping.

Return:

WrappedObject

A javascript object (subclass of WrappedObject), which represents the Sketch object we were given.

See something wrong or incomplete? Improve this page.