Search Docs
Loading...
Skip to content

Class: BlockAPI

Create, manipulate, and query the building blocks of your design.

This is the primary interface for all block-level operations. Use it to manage the entire lifecycle of blocks from creation and serialization to destruction. You can precisely control a block’s appearance by modifying its fills, strokes, and effects, or transform its position, size, and rotation. The API also includes powerful features for managing complex content like text and video, organizing blocks into groups and hierarchies, and exporting final designs to various formats.

Constructors#

Constructor#


BlockAPI

Block Lifecycle#

Manage the complete lifecycle: create, find, duplicate, destroy, and serialize blocks.

loadFromString()#


Loads blocks from a serialized string.

The blocks are not attached by default and won’t be visible until attached to a page or the scene. The UUID of the loaded blocks is replaced with a new one. A damaged string, such as one with a missing key or a value of the wrong type, fails the load and adds no block.

Parameters#

Parameter Type Description
content string A string representing the given blocks.

Returns#

Promise<number[]>

A promise that resolves with a list of handles representing the found blocks or an error.

Example#

const serializedBlocks = await engine.block.saveToString([pageBlockId]);
// Later, load those blocks
const loadedBlocks = await engine.block.loadFromString(serializedBlocks);
// Attach the first loaded block to the scene
engine.block.appendChild(sceneBlockId, loadedBlocks[0]);

Signature#

loadFromString(content: string): Promise<number[]>

loadFromArchiveURL()#


Loads blocks from a remote archive URL.

The URL should be that of a file previously saved with block.saveToArchive. The blocks are not attached by default and won’t be visible until attached to a page or the scene. The UUID of the loaded blocks is replaced with a new one.

Parameters#

Parameter Type Description
url string The URL of the blocks archive file.
options? AbortOptions An abortSignal that stops the load. The load then creates no block.

Returns#

Promise<number[]>

A promise that resolves with a list of handles representing the found blocks or an error.

Example#

// Load blocks from a remote archive
const loadedBlocks = await engine.block.loadFromArchiveURL('https://example.com/blocks.zip');
// Attach the first loaded block to the scene
engine.block.appendChild(sceneBlockId, loadedBlocks[0]);

Signature#

loadFromArchiveURL(url: string, options?: AbortOptions): Promise<number[]>

loadFromURL()#


Loads blocks from a URL.

The URL should point to a blocks file within an unzipped archive directory previously saved with block.saveToArchive. The blocks are not attached by default and won’t be visible until attached to a page or the scene. The UUID of the loaded blocks is replaced with a new one.

Parameters#

Parameter Type Description
url string The URL to the blocks file
options? AbortOptions An abortSignal that stops the load. The load then creates no block.

Returns#

Promise<number[]>

A promise that resolves with a list of block handles

Example#

// Load blocks from a URL
const loadedBlocks = await engine.block.loadFromURL('https://example.com/blocks.blocks');
// Attach the first loaded block to the scene
engine.block.appendChild(sceneBlockId, loadedBlocks[0]);

Signature#

loadFromURL(url: string, options?: AbortOptions): Promise<number[]>

saveToString()#


Saves the given blocks to a serialized string.

If a page with multiple children is given, the entire hierarchy is saved. The resources of that whole hierarchy are checked against allowedResourceSchemes and are passed to onDisallowedResourceScheme.

Performs an internal update to lay out pending changes before the save.

While a font loads, its text is laid out with another font. When the text’s size follows its content, blocks saved before the font arrives can differ from blocks saved after it. To compare two saves, first await engine.block.forceLoadResources(blocks).

The source set entries that the engine makes are buffer:// resources that only this engine holds. onDisallowedResourceScheme gets each of them, whatever allowedResourceSchemes holds. The save leaves out each entry that the callback did not move to another address, and each fill keeps them.

A page slice has no children, so the blocks that it owns on its page are saved as its children. A page slice on a page among blocks makes the update run also while features/implicitUpdatesEnabled is off. A block among blocks is saved once, as a block of its own. A block that a page slice owns is saved with its Percent position and size in design units. The copy does not follow the size of its page.

Parameters#

Parameter Type Description
blocks number[] The blocks to save.
allowedResourceSchemes? string[] The resource schemes to allow in the saved string. Defaults to [‘buffer’, ‘bundle’, ‘http’, ‘https’]. Add ‘data’ to keep data: URIs.
onDisallowedResourceScheme? (url, dataHash) => Promise<string> An optional callback that is called for each resource URL that has a scheme absent from resourceSchemesAllowed. The url parameter is the resource URL and the dataHash parameter is the hash of the resource’s data. The callback should return a new URL for the resource, which will be used in the serialized scene. The callback is expected to return the original URL if no persistence is needed. If the callback throws, rejects, or returns no string, the returned promise rejects and the blocks keep their URLs.
options? AbortOptions An abortSignal that stops a save that waits for onDisallowedResourceScheme. Later answers of the callback change nothing then.

Returns#

Promise<string>

A promise that resolves to a string representing the blocks or an error.

Example#

// Create a page with a text element
const page = engine.block.create('page');
const text = engine.block.create('text');
engine.block.appendChild(page, text);
// Save the whole page hierarchy to a string
const serialized = await engine.block.saveToString([page]);

Signature#

saveToString(blocks: number[], allowedResourceSchemes?: string[], onDisallowedResourceScheme?: (url: string, dataHash: string) => Promise<string>, options?: AbortOptions): Promise<string>

saveToArchive()#


Saves the given blocks and their assets to a zip archive.

The archive contains all assets that were accessible when this function was called. Blocks in the archived scene reference assets relative to the location of the scene file.

Performs an internal update to lay out pending changes before the save.

While a font loads, its text is laid out with another font. When the text’s size follows its content, blocks archived before the font arrives can differ from blocks archived after it. To compare two archives, first await engine.block.forceLoadResources(blocks), then compare the blocks.blocks files inside them. Each archive entry stores the time of the save.

A page slice has no children, so the blocks that it owns on its page are archived as its children. A page slice on a page among blocks makes the update run also while features/implicitUpdatesEnabled is off. A block among blocks is archived once, as a block of its own. A block that a page slice owns is saved with its Percent position and size in design units. The copy does not follow the size of its page.

Parameters#

Parameter Type Description
blocks number[] The blocks to save.
options? AbortOptions An abortSignal that stops the save.

Returns#

Promise<Blob>

A promise that resolves with a Blob on success or an error on failure.

Signature#

saveToArchive(blocks: number[], options?: AbortOptions): Promise<Blob>

create()#


Creates a new block of a given type.

// Create a new text block
const text = engine.block.create('text');
const page = engine.scene.getCurrentPage();
engine.block.appendChild(page, text);
// Create a new image block
const image = engine.block.create('graphic');
engine.block.setShape(image, engine.block.createShape('rect'));
const imageFill = engine.block.createFill('image');
engine.block.setFill(image, imageFill);
engine.block.setString(imageFill, 'fill/image/imageFileURI', 'https://img.ly/static/ubq_samples/sample_1.jpg');
engine.block.appendChild(page, image);
// Create a new video block
const video = engine.block.create('graphic');
engine.block.setShape(video, engine.block.createShape('rect'));
const videoFill = engine.block.createFill('video');
engine.block.setString(videoFill, 'fill/video/fileURI', 'https://cdn.img.ly/assets/demo/v3/ly.img.video/videos/pexels-drone-footage-of-a-surfer-barrelling-a-wave-12715991.mp4');
engine.block.setFill(video, videoFill);
engine.block.appendChild(page, video);

Parameters#

Parameter Type Description
type DesignBlockType The type of the block that shall be created.

Returns#

number

The created block’s handle.

Note#

New text and graphic blocks use clip/defaultDurationValue (5 seconds by default). Duration is provisional until an engine update after placement and media loading initializes it once using clip/initialDurationMode. Waiting for forceLoadAVResource alone does not guarantee that update has run. An explicit setDuration call takes precedence. Finish parent and time-offset placement before that update. Custom asset callbacks that defer placement across updates must set the final duration explicitly.

Signature#

create(type: DesignBlockType): number

createFromSVG()#


Creates editable graphic blocks from SVG markup, such as the SVG code that Adobe Illustrator copies.

Each shape of the SVG becomes a graphic block with a vector path shape, its fill color or gradient, and its stroke. More than one block goes into a group. Embedded images, text, filters, masks and patterns have no shape. Each such part becomes a graphic block with an image fill of only that part. The blocks are not attached to a parent. An SVG user unit is a pixel in a scene measured in pixels. In a scene measured in millimeters or inches it is a point, as Adobe Illustrator writes it.

const group = engine.block.createFromSVG('<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><circle cx="50" cy="50" r="40" fill="red"/></svg>');
engine.block.appendChild(page, group);

Parameters#

Parameter Type Description
svg string The SVG markup.

Returns#

number

The group, or the only block.

Throws#

An error when the SVG cannot be read, draws nothing, has more parts than one import creates, or has a part that cannot be drawn as an image.

Signature#

createFromSVG(svg: string): number

duplicate()#


Duplicates a block and its children. Copies the current duration, even if initialization is pending on the original. The duplicate does not resume initialization. A scene cannot be duplicated, and the call throws for it.

The duplicate of a page slice takes a copy of the blocks that the page slice owns on its page. The call runs an internal update for a page slice on a page, also while features/implicitUpdatesEnabled is off. A block that a page slice owns gets its Percent position and size in design units in the copy. The copy does not follow the size of its page.

Parameters#

Parameter Type Description
id number The block to duplicate.
attachToParent? boolean Whether the duplicated block should be attached to the original’s parent. Defaults to true.

Returns#

number

The handle of the duplicate.

Signature#

duplicate(id: number, attachToParent?: boolean): number

destroy()#


Destroys a block and its children.

A page slice destroys the blocks that it owns on its page, without a check of their scopes, as a page destroys its children. This holds for the last page slice too: its page becomes an empty page without page slices, at the same size. To keep the content, move the page slice out with movePageSliceOutOfPage first. Destroying a page slice runs an internal update.

Parameters#

Parameter Type Description
id number The block to destroy.

Returns#

void

Signature#

destroy(id: number): void

forceLoadResources()#


Forces the loading of resources for a set of blocks and their children.

This is useful for preloading resources. If a resource failed to load previously, it will be reloaded. A page slice also loads the resources of the blocks that it owns on its page. The call runs no update, so a block that no update has placed on the page slice yet is left out.

Pass an empty array to load resources for every block currently known to the engine.

Parameters#

Parameter Type Description
ids number[] The blocks whose resources should be loaded. Pass an empty array to load resources for every block currently known to the engine.
options? AbortOptions An abortSignal that ends the wait, and stops each load that no block uses and no other call waits for.

Returns#

Promise<void>

A Promise that resolves once every resource has finished loading. It rejects when a resource fails to load, or when the file of an image fill cannot be decoded. Of a source set, the load checks the smallest raster entry or the largest SVG entry. It does not check a CMYK JPEG that has no color profile of its own. The state of each block then reports the result.

Signature#

forceLoadResources(ids: number[], options?: AbortOptions): Promise<void>

Block Exploration#

Find blocks by properties like name, type, or kind.

findByName()#


Finds all blocks with a given name.

Parameters#

Parameter Type Description
name string The name to search for.

Returns#

number[]

A list of block ids.

Signature#

findByName(name: string): number[]

findByType()#


Finds all blocks with a given type.

For the stack type, the result holds the scene when the scene arranges its pages. Do not destroy that block: it is the scene.

Parameters#

Parameter Type Description
type ObjectType The type to search for.

Returns#

number[]

A list of block ids.

Signature#

findByType(type: ObjectType): number[]

findByKind()#


Finds all blocks with a given kind.

const allTitles = engine.block.findByKind('title');

Parameters#

Parameter Type Description
kind string The kind to search for.

Returns#

number[]

A list of block ids.

Signature#

findByKind(kind: string): number[]

findAll()#


Finds all blocks known to the engine.

Returns#

number[]

A list of block ids.

Signature#

findAll(): number[]

findAllPlaceholders()#


Finds all placeholder blocks in the current scene.

Returns#

number[]

A list of block ids.

Signature#

findAllPlaceholders(): number[]

findAllUnused()#


Finds all blocks that are not attached to any scene.

A block is considered unused when it has no path to a scene (no scene reference and no ancestor that belongs to a scene) and is not itself a scene. Generated blocks and render blocks (fills, effects, shapes, blurs) are excluded, matching the behaviour of BlockAPI.findAll.

This is useful for cleanup workflows and for filtering the URIs returned by EditorAPI.findAllMediaURIs before relocating resources.

Returns#

number[]

A list of block ids that are not attached to any scene.

Signature#

findAllUnused(): number[]

findAllInExclusionAreas()#


Get all blocks that overlap an exclusion area on their page.

The engine never moves a block to satisfy an exclusion area. A scene loaded from a file, or laid out through the API, can legitimately overlap one, and silently repositioning it would lose the author’s layout. Use this to warn or to highlight instead.

An exclusion area that is hidden, or that is not on a page, reports nothing. exclusionArea/constrains is not read: an advisory exclusion area has no push, so a warning is the only thing it has. A group that straddles an exclusion area is reported instead of the blocks inside it.

Returns#

number[]

A list of block ids that overlap an exclusion area, sorted ascending.

Signature#

findAllInExclusionAreas(): number[]

Block Export#

Export blocks to various formats like images, videos, and audio.

export()#


Exports a design block to a Blob. The export of a page slice gives the part of its page inside the page slice, with the bleed of the page on all four sides. At a fold, that bleed shows the content of the page slice beside it. The export of a hidden page slice shows it and its content.

Performs an internal update to resolve the final layout for the blocks. A PNG, JPEG, WebP, TGA or raw export renders all its strips in one engine call on the main thread, so the tab does not respond and does not repaint until the export ends. For a large export, use exportToStream, or turn on featureFlags.exportWorker so the export renders in a Web Worker.

A page with playback/coverTimeEnabled set exports at its playback/coverTime, and its playback time does not change. An export of a scene shows each page at its own time.

Parameters#
Parameter Type Description
handle number The design block element to export.
options? ExportOptions The options for exporting the block type, including mime type and export settings.
Returns#

Promise<Blob>

A promise that resolves with the exported image or is rejected with an error.

Call Signature#

export(
handle,
mimeType?,
options?): Promise<Blob>;

Exports a design block to a Blob. The export of a page slice gives the part of its page inside the page slice, with the bleed of the page on all four sides. At a fold, that bleed shows the content of the page slice beside it. The export of a hidden page slice shows it and its content.

Performs an internal update to resolve the final layout for the blocks.

Parameters#
Parameter Type Description
handle number The design block element to export.
mimeType? "application/octet-stream"
options? Omit<ExportOptions, "mimeType"> The options for exporting the block type
Returns#

Promise<Blob>

A promise that resolves with the exported image or is rejected with an error.

Deprecated#

Use the new export signature instead

Example#
// Before migration
const blob = await cesdk.block.export(blockId, MimeType.Png, { pngCompressionLevel: 5 })
// After migration
const blob = await cesdk.block.export(blockId, { mimeType: 'image/png', pngCompressionLevel: 5 })

Signatures#

export(handle: number, options?: ExportOptions): Promise<Blob>
export(handle: number, mimeType?: "application/octet-stream" | "application/pdf" | ImageMimeType, options?: Omit<ExportOptions, "mimeType">): Promise<Blob>

exportToStream()#


Exports a design block into a stream, chunk by chunk. A PNG, JPEG or WebP export with outputProfileMode or embedProfiles renders in one surface. It holds the whole encoded file in memory before it writes the first chunk.

Performs an internal update to resolve the final layout for the blocks. A PNG, JPEG, WebP, TGA or raw export renders in strips, one strip in each engine update, and its size is bound only by the limit of its format. With outputProfileMode or embedProfiles, a PNG, JPEG or WebP export renders in one surface, which getMaxExportSize bounds. The next strip waits until writable is ready for more. PNG and raw pixels are written as the strips render, and so is a JPEG above 358 megapixels. A smaller JPEG is written at the end, because its Huffman tables need the whole image. WebP and TGA are written at the end. A PDF is written page by page. A color mask export is not supported here. Do not change the scene while the export runs. A later strip of another size fails with ENCODE.STRIP_EXPORT_SCENE_CHANGED, but an edit that keeps the size, such as a color change, a move or video playback, is not detected: the file then shows the scene before the edit in its first strips and after it in the rest. The engine renders a strip only in an update of a visible tab, so the export pauses while the tab is hidden.

A page with playback/coverTimeEnabled set exports at its playback/coverTime, and its playback time does not change. An export of a scene shows each page at its own time.

Parameters#

Parameter Type Description
handle number The design block element to export.
writable WritableStream<Uint8Array<ArrayBufferLike>> Receives the file, for example a file in the origin private file system (FileSystemWritableFileStream), or a Node.js file through Writable.toWeb(fs.createWriteStream(path)). The stream is closed when the export succeeds and aborted when it fails.
options? ExportOptions The options for exporting the block type, including mime type and export settings. onProgress reports pages for a PDF and strips for a raster export of more than one strip.

Returns#

Promise<void>

A promise that resolves once the whole file is written, or is rejected with an error.

Signature#

exportToStream(handle: number, writable: WritableStream<Uint8Array<ArrayBufferLike>>, options?: ExportOptions): Promise<void>

exportPreview()#


Exports a small image of a block to show in your app. A preview does not count as an export.

The image is always WebP at quality 0.8 and keeps the block’s aspect ratio. A block larger than 262,144 pixels (512 × 512) in area is scaled down to fit. For a video, the preview is one still frame. Use export for a file that you deliver.

Performs an internal update to resolve the final layout for the blocks. Will not complete as long as assets are in a pending state; asset loading progresses during engine updates.

A page with playback/coverTimeEnabled set shows its playback/coverTime, and its playback time does not change. A preview of a scene shows each page at its own time.

Parameters#

Parameter Type Description
handle number The design block element to preview.

Returns#

Promise<Blob>

A promise that resolves with the WebP image or is rejected with an error.

Example#

const preview = await engine.block.exportPreview(page);
image.src = URL.createObjectURL(preview);

Signature#

exportPreview(handle: number): Promise<Blob>

exportWithColorMask()#


Exports a design block and a color mask to two separate Blobs.

Performs an internal update to resolve the final layout for the blocks.

A page with playback/coverTimeEnabled set exports at its playback/coverTime, and its playback time does not change. An export of a scene shows each page at its own time.

Parameters#
Parameter Type Description
handle number The design block element to export.
maskColorR number The red component of the special color mask color.
maskColorG number The green component of the special color mask color.
maskColorB number The blue component of the special color mask color.
options? ExportOptions The options for exporting the block type. onProgress is ignored: a color mask export reports no progress.
Returns#

Promise<Blob[]>

A promise that resolves with an array of the exported image and mask or is rejected with an error.

Call Signature#

exportWithColorMask(
handle,
mimeType,
maskColorR,
maskColorG,
maskColorB,
options?): Promise<Blob[]>;

Exports a design block and a color mask to two separate Blobs.

Performs an internal update to resolve the final layout for the blocks. Removes all pixels that exactly match the given RGB color and replaces them with transparency. The output includes two files: the masked image and the mask itself.

Parameters#
Parameter Type Description
handle number The design block element to export.
mimeType "application/octet-stream"
maskColorR number The red component of the special color mask color.
maskColorG number The green component of the special color mask color.
maskColorB number The blue component of the special color mask color.
options? Omit<ExportOptions, "mimeType"> The options for exporting the block type. onProgress is ignored: a color mask export reports no progress.
Returns#

Promise<Blob[]>

A promise that resolves with an array of the exported image and mask or is rejected with an error.

Deprecated#

Use the new exportWithColorMask signature instead

Example#
// Before migration
const blob = await cesdk.block.exportWithColorMask(
blockId,
MimeType.Png,
0.5,
0,
0,
{
pngCompressionLevel: 5
}
);
// After migration
const blob = await cesdk.block.exportWithColorMask(
blockId,
0.5,
0,
0,
{
mimeType: 'image/png',
pngCompressionLevel: 5
}
);

Signatures#

exportWithColorMask(handle: number, maskColorR: number, maskColorG: number, maskColorB: number, options?: ExportOptions): Promise<Blob[]>
exportWithColorMask(handle: number, mimeType: "application/octet-stream" | "application/pdf" | ImageMimeType, maskColorR: number, maskColorG: number, maskColorB: number, options?: Omit<ExportOptions, "mimeType">): Promise<Blob[]>

exportVideo()#


Exports a design block as a video file.

Parameters#
Parameter Type Description
handle number The page or the scene to export. A scene plays its pages one after the other, in the order of scene.getPages, each for its own duration. A page with a duration of zero does not appear. A hidden page does not appear either. The pages must have the same size, otherwise the export fails.
options? VideoExportOptions The options for exporting the video, including mime type, h264 profile, level, bitrate, time offset, duration, framerate, target width and height.
Returns#

Promise<Blob>

A promise that resolves with a video blob or is rejected with an error.

Note#

MP4 exports embed a PNG cover at the page cover time when playback/coverTimeEnabled is true, else at the page playback position. coverTimeOffset overrides both. An MP4 export of a scene uses its first frame as the cover.

Note: The export will run across multiple iterations of the update loop. In each iteration a frame is scheduled for encoding.

Example#
const page = engine.block.create('page');
// Set up a progress tracking function
const progressTracker = (renderedFrames, encodedFrames, totalFrames) => {
console.log(`Progress: ${Math.round((encodedFrames / totalFrames) * 100)}%`);
};
const videoOptions = { framerate: 30, duration: 5 };
const videoBlob = await engine.block.exportVideo(page, MimeType.Mp4, progressTracker, videoOptions);

Call Signature#

exportVideo(
handle,
mimeType?,
progressCallback?,
options?): Promise<Blob>;

Exports a design block as a video file.

Parameters#
Parameter Type Description
handle number The page or the scene to export. A scene plays its pages one after the other, in the order of scene.getPages, each for its own duration. A page with a duration of zero does not appear. A hidden page does not appear either. The pages must have the same size, otherwise the export fails.
mimeType? VideoMimeType The MIME type of the output video file.
progressCallback? (numberOfRenderedFrames, numberOfEncodedFrames, totalNumberOfFrames) => void A callback which reports on the progress of the export.
options? Omit<VideoExportOptions, "mimeType" "onProgress">
Returns#

Promise<Blob>

A promise that resolves with a video blob or is rejected with an error.

Note#

MP4 exports embed a PNG cover at the page cover time when playback/coverTimeEnabled is true, else at the page playback position. coverTimeOffset overrides both. An MP4 export of a scene uses its first frame as the cover.

Note: The export will run across multiple iterations of the update loop. In each iteration a frame is scheduled for encoding.

Deprecated#

Use the new exportVideo signature instead

Example#
// Before migration
const blob = await cesdk.block.exportVideo(blockId, 'video/mp4', handleProgress, {
targetWidth: 1920,
targetHeight: 1080,
})
// After migration
const blob = await cesdk.block.exportVideo(blockId, {
mimeType: 'video/mp4',
progressCallback: handleProgress,
targetWidth: 1920,
targetHeight: 1080,
})

Signatures#

exportVideo(handle: number, options?: VideoExportOptions): Promise<Blob>
exportVideo(handle: number, mimeType?: VideoMimeType, progressCallback?: (numberOfRenderedFrames: number, numberOfEncodedFrames: number, totalNumberOfFrames: number) => void, options?: Omit<VideoExportOptions, "mimeType" | "onProgress">): Promise<Blob>

exportAudio()#

Exports a design block as an audio file.

Parameters#

Parameter Type Description
handle number The design block element to export. Currently, only audio blocks are supported.
options? AudioExportOptions The options for exporting the audio, including mime type, progress callback, and export settings.

Returns#

Promise<Blob>

A promise that resolves with an audio blob or is rejected with an error. This API is experimental and may change or be removed in future versions.

Example#

const audioBlock = engine.block.create('audio');
// Set up a progress tracking function
const progressTracker = (renderedFrames, encodedFrames, totalFrames) => {
console.log(`Audio export progress: ${Math.round((encodedFrames / totalFrames) * 100)}%`);
};
const audioBlob = await engine.block.exportAudio(audioBlock, {
mimeType: 'audio/wav',
onProgress: progressTracker,
duration: 10
});

Signature#

exportAudio(handle: number, options?: AudioExportOptions): Promise<Blob>

Block Hierarchies#

Manage parent-child relationships and the scene graph structure.

getParent()#


Gets the parent of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The parent’s handle or null if the block has no parent.

Signature#

getParent(id: number): number

setTransformParent()#


Makes a block follow the transform of another block, or stops it from following one.

The block’s position, rotation and scale are then read in the local space of the transform parent, so the block moves with it. The block does not keep its place on screen when the link changes. Only the transform is inherited: opacity, visibility and the stacking order still come from the block’s own parent. A hidden block can be a transform parent. When the transform parent is destroyed, the block stops following it. A block whose transform is locked can neither get nor lose a link.

Required scope: ‘layer/move’

Parameters#

Parameter Type Description
id number The graphic or text block that follows.
parent number The graphic or text block to follow, or null to remove the link.

Returns#

void

Signature#

setTransformParent(id: number, parent: number): void

getTransformParent()#


Gets the block whose transform a block follows.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The transform parent, or null if the block follows none.

Signature#

getTransformParent(id: number): number

getOwningPageSlice()#


Gets the page slice that owns a block on its page.

A page slice has no children, so the block is a child of the page, or of a group on the page. The page slice under the center of the block owns it. On a fold, the earlier page slice owns it. A block outside the page belongs to the nearest page slice. A block in a group belongs where its group does. The call runs an internal update when the block has no frame. It does the same when the page has page slices that no update laid out yet.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The page slice, or null for a block that is not on a page with page slices. A page and a page slice also give null.

Signature#

getOwningPageSlice(id: number): number

getPageSlices()#


Gets the page slices of a page, in reading order.

The list holds hidden page slices too. It is the order of the page slices among the children of the page.

Parameters#

Parameter Type Description
id number The page to query.

Returns#

number[]

The page slices. An empty list for a block without page slices.

Signature#

getPageSlices(id: number): number[]

getChildren()#


Gets all direct children of a block.

Children are sorted in their rendering order: Last child is rendered in front of other children.

For a scene that arranges its pages, the list leaves out the camera.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number[]

A list of block ids.

Signature#

getChildren(id: number): number[]

insertChild()#


Inserts a child block at a specific index.

An audio, text or caption block takes no children, so a call with such a parent fails. A move fails when it would put a block with a matte inside its matte source, or on another page than its source. A page slice takes no children, and it can only be a child of a page with a rect shape. A video scene takes no page slice.

A page slice that a block load or duplicate returns holds the blocks that it was saved with. The next update moves them onto the page, into the new place of the page slice.

For a scene that arranges its pages, the index counts the children without the camera.

Parameters#

Parameter Type Description
parent number The block whose children should be updated.
child number The child to insert. Can be an existing child of parent.
index number The index to insert or move to.

Returns#

void

Signature#

insertChild(parent: number, child: number, index: number): void

appendChild()#


Appends a child block to a parent.

An audio, text or caption block takes no children, so a call with such a parent fails. A move fails when it would put a block with a matte inside its matte source, or on another page than its source. A page slice takes no children, and it can only be a child of a page with a rect shape. A video scene takes no page slice.

A page slice that a block load or duplicate returns holds the blocks that it was saved with. The next update moves them onto the page, into the new place of the page slice.

Parameters#

Parameter Type Description
parent number The block whose children should be updated.
child number The child to insert. Can be an existing child of parent.

Returns#

void

Signature#

appendChild(parent: number, child: number): void

Block Layout#

Structure designs by positioning, sizing, layering, aligning, and distributing blocks.

isTransformLocked()#


Gets the transform-locked state of a block.

If true, the block’s transform can’t be changed. The lock covers the static transform: keyframe tracks on the position, rotation, size, scale, anchor or skew still animate a locked block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if transform locked, false otherwise.

Signature#

isTransformLocked(id: number): boolean

isLineOrigin()#


Checks whether a graphic block originated as a line shape. Survives the line’s conversion to a vector path during vector-edit; resets only when the shape is replaced by a non-line shape via setShape.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if the block originated as a line shape, false otherwise.

Signature#

isLineOrigin(id: number): boolean

setTransformLocked()#


Sets the transform-locked state of a block.

Parameters#

Parameter Type Description
id number The block to update.
locked boolean Whether the block’s transform should be locked.

Returns#

void

Signature#

setTransformLocked(id: number, locked: boolean): void

getPositionX()#


Gets the X position of a block.

The position is the block’s local origin: the top-left corner of its untransformed frame, in the coordinate space of its parent. Rotation turns the block, and a flip mirrors it, around the center of its frame. So for a rotated or flipped block, the position is not the visual left edge. Use getGlobalBoundingBoxX for the axis-aligned visual bounds.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The value of the x position.

Signature#

getPositionX(id: number): number

getPositionXMode()#


Gets the mode for the block’s X position.

On a page slice the mode is ‘Auto’, because the page sets its position.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Absolute" | "Percent" | "Auto"

The current mode for the x position: ‘Absolute’ or ‘Percent’.

Signature#

getPositionXMode(id: number): "Absolute" | "Percent" | "Auto"

getPositionY()#


Gets the Y position of a block.

The position is the block’s local origin: the top-left corner of its untransformed frame, in the coordinate space of its parent. Rotation turns the block, and a flip mirrors it, around the center of its frame. So for a rotated or flipped block, the position is not the visual top edge. Use getGlobalBoundingBoxY for the axis-aligned visual bounds.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The value of the y position.

Signature#

getPositionY(id: number): number

getPositionYMode()#


Gets the mode for the block’s Y position.

On a page slice the mode is ‘Auto’, because the page sets its position.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Absolute" | "Percent" | "Auto"

The current mode for the y position: ‘Absolute’ or ‘Percent’.

Signature#

getPositionYMode(id: number): "Absolute" | "Percent" | "Auto"

setPositionX()#


Sets the X position of a block.

The position refers to the block’s local space, relative to its parent with the origin at the top left. A page slice takes its position from its page, so the call fails with BLOCK.POSITION_PARENT_CONTROLLED on one.

engine.block.setPositionX(block, 0.25);

Parameters#

Parameter Type Description
id number The block to update.
value number The value of the x position.

Returns#

void

Signature#

setPositionX(id: number, value: number): void

setPositionXMode()#


Sets the mode for the block’s X position.

engine.block.setPositionXMode(block, 'Percent');

A page slice takes its position from its page, so the call fails with BLOCK.POSITION_PARENT_CONTROLLED on one.

Parameters#

Parameter Type Description
id number The block to update.
mode "Absolute" "Percent"

Returns#

void

Signature#

setPositionXMode(id: number, mode: "Absolute" | "Percent" | "Auto"): void

setPositionY()#


Sets the Y position of a block.

The position refers to the block’s local space, relative to its parent with the origin at the top left. A page slice takes its position from its page, so the call fails with BLOCK.POSITION_PARENT_CONTROLLED on one.

engine.block.setPositionY(block, 0.25);

Parameters#

Parameter Type Description
id number The block to update.
value number The value of the y position.

Returns#

void

Signature#

setPositionY(id: number, value: number): void

setPositionYMode()#


Sets the mode for the block’s Y position.

engine.block.setPositionYMode(block, 'Absolute');

A page slice takes its position from its page, so the call fails with BLOCK.POSITION_PARENT_CONTROLLED on one.

Parameters#

Parameter Type Description
id number The block to update.
mode "Absolute" "Percent"

Returns#

void

Signature#

setPositionYMode(id: number, mode: "Absolute" | "Percent" | "Auto"): void

setAlwaysOnTop()#


Sets a block to always be rendered on top of its siblings.

If true, this block’s sorting order is automatically adjusted to be higher than all other siblings without this property.

A page slice fails with BLOCK.TYPE_CANNOT_BE_ARRANGED, because its place in the page is its reading order.

Parameters#

Parameter Type Description
id number the block to update.
enabled boolean whether the block shall be always-on-top.

Returns#

void

Signature#

setAlwaysOnTop(id: number, enabled: boolean): void

setAlwaysOnBottom()#


Sets a block to always be rendered below its siblings.

If true, this block’s sorting order is automatically adjusted to be lower than all other siblings without this property.

A page slice fails with BLOCK.TYPE_CANNOT_BE_ARRANGED, because its place in the page is its reading order.

Parameters#

Parameter Type Description
id number the block to update.
enabled boolean whether the block shall always be below its siblings.

Returns#

void

Signature#

setAlwaysOnBottom(id: number, enabled: boolean): void

isAlwaysOnTop()#


Checks if a block is set to always be on top.

Parameters#

Parameter Type Description
id number the block to query.

Returns#

boolean

true if the block is set to be always-on-top, false otherwise.

Signature#

isAlwaysOnTop(id: number): boolean

isAlwaysOnBottom()#


Checks if a block is set to always be on the bottom.

Parameters#

Parameter Type Description
id number the block to query.

Returns#

boolean

true if the block is set to be always-on-bottom, false otherwise.

Signature#

isAlwaysOnBottom(id: number): boolean

bringToFront()#


Brings a block to the front of its siblings.

Updates the sorting order so that the given block has the highest sorting order.

Parameters#

Parameter Type Description
id number The id of the block to bring to the front.

Returns#

void

Signature#

bringToFront(id: number): void

sendToBack()#


Sends a block to the back of its siblings.

Updates the sorting order so that the given block has the lowest sorting order.

Parameters#

Parameter Type Description
id number The id of the block to send to the back.

Returns#

void

Signature#

sendToBack(id: number): void

bringForward()#


Brings a block one layer forward.

Updates the sorting order to be higher than its next sibling.

Parameters#

Parameter Type Description
id number The id of the block to bring forward.

Returns#

void

Signature#

bringForward(id: number): void

sendBackward()#


Sends a block one layer backward.

Updates the sorting order to be lower than its previous sibling.

Parameters#

Parameter Type Description
id number The id of the block to send backward.

Returns#

void

Signature#

sendBackward(id: number): void

getRotation()#


Gets the rotation of a block in the scene’s angle unit (radians by default).

The angle unit is configured via engine.scene.setAngleUnit().

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The block’s rotation around its center in the scene’s angle unit (radians by default).

Signature#

getRotation(id: number): number

setRotation()#


Sets the rotation of a block in the scene’s angle unit (radians by default).

Rotation is applied around the block’s center. The angle unit is configured via engine.scene.setAngleUnit().

With the setting features/implicitUpdatesEnabled off, the call updates only when a block that it reads has no layout yet, as right after an undo. It reads the block, the members of a group and each transform parent. That update also lays out every other pending change.

Parameters#

Parameter Type Description
id number The block to update.
radians number The new rotation in the scene’s angle unit (radians by default).

Returns#

void

Signature#

setRotation(id: number, radians: number): void

getWidth()#


Gets the width of a block in the current width mode.

const width = engine.block.getWidth(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The value of the block’s width.

Signature#

getWidth(id: number): number

getWidthMode()#


Gets the mode for the block’s width.

const widthMode = engine.block.getWidthMode(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Absolute" | "Percent" | "Auto"

The current mode for the width: ‘Absolute’, ‘Percent’ or ‘Auto’.

Signature#

getWidthMode(id: number): "Absolute" | "Percent" | "Auto"

getHeight()#


Gets the height of a block in the current height mode.

const height = engine.block.getHeight(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The value of the block’s height.

Signature#

getHeight(id: number): number

getHeightMode()#


Gets the mode for the block’s height.

const heightMode = engine.block.getHeightMode(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Absolute" | "Percent" | "Auto"

The current mode for the height: ‘Absolute’, ‘Percent’ or ‘Auto’.

Signature#

getHeightMode(id: number): "Absolute" | "Percent" | "Auto"

setWidth()#


Sets the width of a block in the current width mode.

If the crop is maintained, the crop values will be automatically adjusted. A new width of a page with page slices goes to its last page slice on a horizontal axis. On a vertical axis, it goes to every page slice. A page slice that this shrinks stops at 25 pixels at the DPI of the scene. So the page can end up wider than asked. A width of 0 or less on a page slice fails with BLOCK.PAGE_SLICE_SIZE_INVALID.

engine.block.setWidth(block, 2.5, true);

Parameters#

Parameter Type Description
id number The block to update.
value number The new width of the block.
maintainCrop? boolean Whether or not the crop values, if available, should be automatically adjusted. A Percent size, left or top stays Percent.

Returns#

void

Signature#

setWidth(id: number, value: number, maintainCrop?: boolean): void

setWidthMode()#


Sets the mode for the block’s width.

A switch between Absolute and Percent keeps the stored width and reads it in the new mode. Set the width after the mode, without maintainCrop: otherwise the crop is adjusted from the size that the old number has in the new mode. setSize changes the mode and the size in one call.

engine.block.setWidthMode(block, 'Percent');

A page slice, and a page that holds page slices, take only the Absolute mode. Another mode fails with BLOCK.PAGE_SLICE_SIZE_MODE_INVALID.

Parameters#

Parameter Type Description
id number The block to update.
mode "Absolute" "Percent"

Returns#

void

Signature#

setWidthMode(id: number, mode: "Absolute" | "Percent" | "Auto"): void

setHeight()#


Sets the height of a block in the current height mode.

If the crop is maintained, the crop values will be automatically adjusted. A new height of a page with page slices goes to every page slice on a horizontal axis. On a vertical axis, it goes to the last page slice. A page slice that this shrinks stops at 25 pixels at the DPI of the scene. So the page can end up higher than asked. A height of 0 or less on a page slice fails with BLOCK.PAGE_SLICE_SIZE_INVALID.

engine.block.setHeight(block, 0.5);
engine.block.setHeight(block, 2.5, true);

Parameters#

Parameter Type Description
id number The block to update.
value number The new height of the block.
maintainCrop? boolean Whether or not the crop values, if available, should be automatically adjusted. A Percent size, left or top stays Percent.

Returns#

void

Signature#

setHeight(id: number, value: number, maintainCrop?: boolean): void

setHeightMode()#


Sets the mode for the block’s height.

A switch between Absolute and Percent keeps the stored height and reads it in the new mode. Set the height after the mode, without maintainCrop: otherwise the crop is adjusted from the size that the old number has in the new mode. setSize changes the mode and the size in one call.

engine.block.setHeightMode(block, 'Percent');

A page slice, and a page that holds page slices, take only the Absolute mode. Another mode fails with BLOCK.PAGE_SLICE_SIZE_MODE_INVALID.

Parameters#

Parameter Type Description
id number The block to update.
mode "Absolute" "Percent"

Returns#

void

Signature#

setHeightMode(id: number, mode: "Absolute" | "Percent" | "Auto"): void

getFrameX()#


Gets the final calculated X position of a block’s frame.

The position is only available after an internal update loop.

const frameX = engine.block.getFrameX(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The layout position on the x-axis.

Signature#

getFrameX(id: number): number

getFrameY()#


Gets the final calculated Y position of a block’s frame.

The position is only available after an internal update loop.

const frameY = engine.block.getFrameY(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The layout position on the y-axis.

Signature#

getFrameY(id: number): number

getFrameWidth()#


Gets the final calculated width of a block’s frame.

The width is only available after an internal update loop.

const frameWidth = engine.block.getFrameWidth(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The layout width.

Signature#

getFrameWidth(id: number): number

getFrameHeight()#


Gets the final calculated height of a block’s frame.

The height is only available after an internal update loop.

const frameHeight = engine.block.getFrameHeight(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The layout height.

Signature#

getFrameHeight(id: number): number

hasTransformAnchor()#


Checks whether a block has its own anchor.

Setting transform/anchor/x or transform/anchor/y, even to 0, or giving one of them keyframes, gives a block an anchor. A rotation keyframe track turns a block with an anchor around the anchor, and a block without one around its frame center, as setRotation does.

Parameters#

Parameter Type Description
id number A graphic, text or caption block.

Returns#

boolean

Whether the block has an anchor.

Signature#

hasTransformAnchor(id: number): boolean

getGlobalBoundingBoxX()#


Gets the X position of the block’s global bounding box.

The position is in the scene’s global coordinate space, with the origin at the top left.

A block with a transform parent is placed where its transform parents are at the current playback time. Its own transform stays static, like that of every other block. For such a block the call evaluates the animations of its transform parents at that time.

const globalX = engine.block.getGlobalBoundingBoxX(block);

Parameters#

Parameter Type Description
id number The block whose bounding box should be calculated.

Returns#

number

The x coordinate of the axis-aligned bounding box.

Signature#

getGlobalBoundingBoxX(id: number): number

getGlobalBoundingBoxY()#


Gets the Y position of the block’s global bounding box.

The position is in the scene’s global coordinate space, with the origin at the top left.

A block with a transform parent is placed where its transform parents are at the current playback time. Its own transform stays static, like that of every other block. For such a block the call evaluates the animations of its transform parents at that time.

const globalY = engine.block.getGlobalBoundingBoxY(block);

Parameters#

Parameter Type Description
id number The block whose bounding box should be calculated.

Returns#

number

The y coordinate of the axis-aligned bounding box.

Signature#

getGlobalBoundingBoxY(id: number): number

getGlobalBoundingBoxWidth()#


Gets the width of the block’s global bounding box.

The width is in the scene’s global coordinate space.

A block with a transform parent is placed where its transform parents are at the current playback time. Its own transform stays static, like that of every other block. For such a block the call evaluates the animations of its transform parents at that time.

const globalWidth = engine.block.getGlobalBoundingBoxWidth(block);

Parameters#

Parameter Type Description
id number The block whose bounding box should be calculated.

Returns#

number

The width of the axis-aligned bounding box.

Signature#

getGlobalBoundingBoxWidth(id: number): number

getGlobalBoundingBoxHeight()#


Gets the height of the block’s global bounding box.

The height is in the scene’s global coordinate space.

A block with a transform parent is placed where its transform parents are at the current playback time. Its own transform stays static, like that of every other block. For such a block the call evaluates the animations of its transform parents at that time.

const globalHeight = engine.block.getGlobalBoundingBoxHeight(block);

Parameters#

Parameter Type Description
id number The block whose bounding box should be calculated.

Returns#

number

The height of the axis-aligned bounding box.

Signature#

getGlobalBoundingBoxHeight(id: number): number

getScreenSpaceBoundingBoxXYWH()#


Gets the screen-space bounding box for a set of blocks.

const boundingBox = engine.block.getScreenSpaceBoundingBoxXYWH([block]);

Parameters#

Parameter Type Description
ids number[] The block to query.

Returns#

XYWH

The position and size of the bounding box.

Signature#

getScreenSpaceBoundingBoxXYWH(ids: number[]): XYWH

alignHorizontally()#


Aligns blocks horizontally.

Aligns multiple blocks within their bounding box or a single block to its parent.

Parameters#

Parameter Type Description
ids number[] A non-empty array of block ids.
horizontalBlockAlignment "Auto" "Right"

Returns#

void

Signature#

alignHorizontally(ids: number[], horizontalBlockAlignment: "Auto" | "Right" | "Left" | "Center" | "Justify"): void

alignVertically()#


Aligns blocks vertically.

Aligns multiple blocks within their bounding box or a single block to its parent.

Parameters#

Parameter Type Description
ids number[] A non-empty array of block ids.
verticalBlockAlignment "Center" "Top"

Returns#

void

Signature#

alignVertically(ids: number[], verticalBlockAlignment: "Center" | "Top" | "Bottom"): void

distributeHorizontally()#


Distributes blocks horizontally with even spacing.

Distributes multiple blocks horizontally within their bounding box.

Parameters#

Parameter Type Description
ids number[] A non-empty array of block ids.

Returns#

void

Signature#

distributeHorizontally(ids: number[]): void

distributeVertically()#


Distributes blocks vertically with even spacing.

Distributes multiple blocks vertically within their bounding box.

Parameters#

Parameter Type Description
ids number[] A non-empty array of block ids.

Returns#

void

Signature#

distributeVertically(ids: number[]): void

fillParent()#


Resizes and positions a block to fill its parent.

The crop values of the block are reset if it can be cropped. A block that follows a transform parent stops following it.

A page slice takes its position from its page, so the call fails with BLOCK.POSITION_PARENT_CONTROLLED on one.

Parameters#

Parameter Type Description
id number The block that should fill its parent.

Returns#

void

Signature#

fillParent(id: number): void

resizeContentAware()#


Resizes blocks while adjusting content to fit.

The content of the blocks is automatically adjusted to fit the new dimensions. Full-page blocks are resized to remain as full-page afterwards, while the blocks that are not full-page get resized as a group to the same scale factor and centered. A page with page slices scales every page slice by one factor. Full-page blocks still fill the spread. Other content uses one scale factor. It stays relative to the center of its page slice. A page slice returns an error, because its page sets its size. A spread with a zero width or height returns an error.

const pages = engine.scene.getPages();
engine.block.resizeContentAware(pages, width: 100.0, 100.0);

Performs an internal update to lay out pending changes, also with the setting features/implicitUpdatesEnabled off. A block with no layout on a page that single page mode hides returns an error.

Parameters#

Parameter Type Description
ids number[] The blocks to resize.
width number The new width of the blocks.
height number The new height of the blocks.

Returns#

void

Signature#

resizeContentAware(ids: number[], width: number, height: number): void

scale()#


Scales a block and its children proportionally.

This updates the position, size and style properties (e.g. stroke width) of the block and its children around the specified anchor point.

With the setting features/implicitUpdatesEnabled off, the call updates only when a block that it reads has no layout yet, as right after an undo. It reads the block, every child of it and each transform parent. That update also lays out every other pending change.

// Scale a block to double its size, anchored at the center.
engine.block.scale(block, 2.0, 0.5, 0.5);

Scaling a page slice changes its size, and the page places its page slices again. A scale of 0 or less on a page slice fails with BLOCK.PAGE_SLICE_SIZE_INVALID.

Parameters#

Parameter Type Description
id number The block that should be scaled.
scale number The scale factor to be applied to the current properties of the block.
anchorX? number The relative position along the width of the block around which the scaling should occur (0=left, 0.5=center, 1=right). Defaults to 0.
anchorY? number The relative position along the height of the block around which the scaling should occur (0=top, 0.5=center, 1=bottom). Defaults to 0.

Returns#

void

Signature#

scale(id: number, scale: number, anchorX?: number, anchorY?: number): void

Block Selection & Visibility#

Manage a block’s selection state and visibility on the canvas.

select()#


Selects a block, deselecting all others.

Parameters#

Parameter Type Description
id number The block to be selected.

Returns#

void

Signature#

select(id: number): void

setSelected()#


Sets the selection state of a block.

A page slice and its page are never selected together: selecting one deselects the other.

Parameters#

Parameter Type Description
id number The block to query.
selected boolean Whether or not the block should be selected.

Returns#

void

Signature#

setSelected(id: number, selected: boolean): void

isSelected()#


Gets the selection state of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if the block is selected, false otherwise.

Signature#

isSelected(id: number): boolean

findAllSelected()#


Finds all currently selected blocks.

Returns#

number[]

An array of block ids.

Signature#

findAllSelected(): number[]

isVisible()#


Gets the visibility state of a block.

Reports the visibility you set, not the current view. A page that single page mode takes out of view stays visible; use scene.getCurrentPages to read the view.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if visible, false otherwise.

Signature#

isVisible(id: number): boolean

setVisible()#


Sets the visibility state of a block.

A hidden page slice hides the blocks that it owns, as a hidden parent hides its children. They show in no canvas and no export, and take no hit. It keeps its room in the page. The blocks keep their own visibility.

Parameters#

Parameter Type Description
id number The block to update.
visible boolean Whether the block shall be visible.

Returns#

void

Signature#

setVisible(id: number, visible: boolean): void

Block Appearance#

Control general appearance, including opacity, blend modes, flipping, and other visual properties.

isClipped()#


Gets the clipped state of a block.

If true, the block should clip its contents to its frame.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if clipped, false otherwise.

Signature#

isClipped(id: number): boolean

setClipped()#


Sets the clipped state of a block.

A clipped page slice cuts the blocks that it owns at its folds and at the page edges with their bleed. A click beside the page still selects them.

Parameters#

Parameter Type Description
id number The block to update.
clipped boolean Whether the block should clips its contents to its frame.

Returns#

void

Signature#

setClipped(id: number, clipped: boolean): void

getMatte()#


Gets the matte of a block.

Parameters#

Parameter Type Description
id number The block to query. Graphic, text and group blocks are supported.

Returns#

BlockMatte

The matte source and mode, or null when the block has no matte.

Signature#

getMatte(id: number): BlockMatte

setMatte()#


Masks a block with the rendered alpha or luminance of another block, like a track matte.

A block used as a matte source is not drawn on its own. If the source draws nothing, for example because it is hidden or outside its time range, an 'Alpha' or 'Luma' matte hides the block and an inverted matte shows it whole. SVG export does not apply mattes, so a matted block exports whole.

Required scope: ‘layer/clipping’ on the block, and ‘layer/visibility’ on the source, which stops drawing on its own.

Parameters#

Parameter Type Description
id number The block to mask. Graphic, text and group blocks are supported.
source number The block whose rendering masks the block, or null to remove the matte. It must be on the same page as the block, or both must be on no page. It may not be the block itself, one of its parents, or a block that the block or one of its parents masks, or a block that contains such a block.
mode? MatteMode The channel of the source that masks the block. Defaults to 'Alpha'.

Returns#

void

Signature#

setMatte(id: number, source: number, mode?: MatteMode): void

getFlipHorizontal()#


Gets the horizontal flip state of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

A boolean indicating whether the block is flipped horizontally.

Signature#

getFlipHorizontal(id: number): boolean

getFlipVertical()#


Gets the vertical flip state of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

A boolean indicating whether the block is flipped vertically.

Signature#

getFlipVertical(id: number): boolean

setFlipHorizontal()#


Sets the horizontal flip state of a block.

With the setting features/implicitUpdatesEnabled off, the call updates only when a block that it reads has no layout yet, as right after an undo. It reads the block, the members of a group and each transform parent. That update also lays out every other pending change. The block is mirrored around the center of its frame, so its rendered bounds do not move. For a block without rotation, anchor or skew, turning the flip on moves getPositionX and getFrameX to the visual right edge (x + width). Turning it off moves them back. getGlobalBoundingBoxX stays the same.

Parameters#

Parameter Type Description
id number The block to update.
flip boolean If the flip should be enabled.

Returns#

void

Signature#

setFlipHorizontal(id: number, flip: boolean): void

setFlipVertical()#


Sets the vertical flip state of a block.

With the setting features/implicitUpdatesEnabled off, the call updates only when a block that it reads has no layout yet, as right after an undo. It reads the block, the members of a group and each transform parent. That update also lays out every other pending change. The block is mirrored around the center of its frame, so its rendered bounds do not move. For a block without rotation, anchor or skew, turning the flip on moves getPositionY and getFrameY to the visual bottom edge (y + height). Turning it off moves them back. getGlobalBoundingBoxY stays the same.

Parameters#

Parameter Type Description
id number The block to update.
flip boolean If the flip should be enabled.

Returns#

void

Signature#

setFlipVertical(id: number, flip: boolean): void

supportsOpacity()#


Checks if a block supports opacity.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports opacity.

Signature#

supportsOpacity(id: number): boolean

setOpacity()#


Sets the opacity of a block.

Parameters#

Parameter Type Description
id number The block whose opacity should be set.
opacity number The opacity to be set. The valid range is 0 to 1.

Returns#

void

Signature#

setOpacity(id: number, opacity: number): void

getOpacity()#


Gets the opacity of a block.

Parameters#

Parameter Type Description
id number The block whose opacity should be queried.

Returns#

number

The opacity value.

Signature#

getOpacity(id: number): number

supportsBlendMode()#


Checks if a block supports blend modes.

False for a page slice, which draws no blend mode.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports blend modes.

Signature#

supportsBlendMode(id: number): boolean

setBlendMode()#


Sets the blend mode of a block.

Parameters#

Parameter Type Description
id number The block whose blend mode should be set.
blendMode "Color"

Returns#

void

Signature#

setBlendMode(id: number, blendMode: "Color" | "PassThrough" | "Normal" | "Darken" | "Multiply" | "ColorBurn" | "LinearBurn" | "DarkenColor" | "Lighten" | "Screen" | "ColorDodge" | "LinearDodge" | "LightenColor" | "Overlay" | "SoftLight" | "HardLight" | "VividLight" | "LinearLight" | "PinLight" | "HardMix" | "Difference" | "Exclusion" | "Subtract" | "Divide" | "Hue" | "Saturation" | "Luminosity"): void

getBlendMode()#


Gets the blend mode of a block.

Parameters#

Parameter Type Description
id number The block whose blend mode should be queried.

Returns#

| "Color" | "PassThrough" | "Normal" | "Darken" | "Multiply" | "ColorBurn" | "LinearBurn" | "DarkenColor" | "Lighten" | "Screen" | "ColorDodge" | "LinearDodge" | "LightenColor" | "Overlay" | "SoftLight" | "HardLight" | "VividLight" | "LinearLight" | "PinLight" | "HardMix" | "Difference" | "Exclusion" | "Subtract" | "Divide" | "Hue" | "Saturation" | "Luminosity"

The blend mode.

Signature#

getBlendMode(id: number): "Color" | "PassThrough" | "Normal" | "Darken" | "Multiply" | "ColorBurn" | "LinearBurn" | "DarkenColor" | "Lighten" | "Screen" | "ColorDodge" | "LinearDodge" | "LightenColor" | "Overlay" | "SoftLight" | "HardLight" | "VividLight" | "LinearLight" | "PinLight" | "HardMix" | "Difference" | "Exclusion" | "Subtract" | "Divide" | "Hue" | "Saturation" | "Luminosity"

supportsBackgroundColor()#


Checks if a block supports a background color.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports a background color.

Signature#

supportsBackgroundColor(id: number): boolean

setBackgroundColorEnabled()#


Enables or disables the background of a block.

engine.block.setBackgroundColorEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose background should be enabled or disabled.
enabled boolean If true, the background will be enabled.

Returns#

void

Signature#

setBackgroundColorEnabled(id: number, enabled: boolean): void

isBackgroundColorEnabled()#


Checks if the background of a block is enabled.

const backgroundColorIsEnabled = engine.block.isBackgroundColorEnabled(block);

Parameters#

Parameter Type Description
id number The block whose background state should be queried.

Returns#

boolean

True, if background is enabled.

Signature#

isBackgroundColorEnabled(id: number): boolean

Block Fills#

Create, configure, and manage block fills, including solid colors, gradients, and images.

createFill()#


Creates a new fill block.

const solidColoFill = engine.block.createFill('color');
// Longhand fill types are also supported
const imageFill = engine.block.createFill('//ly.img.ubq/fill/image');

Parameters#

Parameter Type Description
type FillType The type of the fill object that shall be created.

Returns#

number

The created fill’s handle.

Signature#

createFill(type: FillType): number

supportsContentFillMode()#


Checks if a block supports content fill modes.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block has a content fill mode.

Signature#

supportsContentFillMode(id: number): boolean

setContentFillMode()#


Sets the content fill mode of a block.

engine.block.setContentFillMode(image, 'Cover');

Parameters#

Parameter Type Description
id number The block to update.
mode "Crop" "Cover"

Returns#

void

Signature#

setContentFillMode(id: number, mode: "Crop" | "Cover" | "Contain"): void

getContentFillMode()#


Gets the content fill mode of a block.

engine.block.getContentFillMode(image);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Crop" | "Cover" | "Contain"

The current mode: ‘Crop’, ‘Cover’ or ‘Contain’.

Signature#

getContentFillMode(id: number): "Crop" | "Cover" | "Contain"

setContentFillHorizontalAlignment()#


Sets the horizontal alignment of the content fill within a block.

Only affects ‘Contain’ and ‘Cover’ fill modes; has no visible effect in ‘Crop’ mode, where the user positions the content explicitly.

engine.block.setContentFillHorizontalAlignment(image, 'Left');

Parameters#

Parameter Type Description
id number The block to update.
alignment "Right" "Left"

Returns#

void

Signature#

setContentFillHorizontalAlignment(id: number, alignment: "Right" | "Left" | "Center"): void

getContentFillHorizontalAlignment()#


Gets the horizontal alignment of the content fill within a block.

engine.block.getContentFillHorizontalAlignment(image);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Right" | "Left" | "Center"

The current alignment: ‘Left’, ‘Center’ or ‘Right’.

Signature#

getContentFillHorizontalAlignment(id: number): "Right" | "Left" | "Center"

setContentFillVerticalAlignment()#


Sets the vertical alignment of the content fill within a block.

Only affects ‘Contain’ and ‘Cover’ fill modes; has no visible effect in ‘Crop’ mode, where the user positions the content explicitly.

engine.block.setContentFillVerticalAlignment(image, 'Top');

Parameters#

Parameter Type Description
id number The block to update.
alignment "Center" "Top"

Returns#

void

Signature#

setContentFillVerticalAlignment(id: number, alignment: "Center" | "Top" | "Bottom"): void

getContentFillVerticalAlignment()#


Gets the vertical alignment of the content fill within a block.

engine.block.getContentFillVerticalAlignment(image);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

"Center" | "Top" | "Bottom"

The current alignment: ‘Top’, ‘Center’ or ‘Bottom’.

Signature#

getContentFillVerticalAlignment(id: number): "Center" | "Top" | "Bottom"

setGradientColorStops()#


Sets the color stops for a gradient property.

engine.block.setGradientColorStops(gradientFill, 'fill/gradient/colors', [
{ color: { r: 1.0, g: 0.8, b: 0.2, a: 1.0 }, stop: 0 },
{ color: { r: 0.3, g: 0.4, b: 0.7, a: 1.0 }, stop: 1 }
]);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property string The name of the property to set, e.g. ‘fill/gradient/colors’.
colors GradientColorStop[] An array of gradient color stops.

Returns#

void

Signature#

setGradientColorStops(id: number, property: string, colors: GradientColorStop[]): void

getGradientColorStops()#


Gets the color stops from a gradient property.

engine.block.getGradientColorStops(gradientFill, 'fill/gradient/colors');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property string The name of the property to query.

Returns#

GradientColorStop[]

The gradient colors.

Signature#

getGradientColorStops(id: number, property: string): GradientColorStop[]

getSourceSet()#


Gets the source set from a block property.

const sourceSet = engine.block.getSourceSet(imageFill, 'fill/image/sourceSet');

Parameters#

Parameter Type Description
id number The block that should be queried.
property SourceSetPropertyName The name of the property to query, e.g. ‘fill/image/sourceSet’.

Returns#

Source[]

The block’s source set.

Signature#

getSourceSet(id: number, property: SourceSetPropertyName): Source[]

setSourceSet()#


Sets the source set for a block property.

The crop and content fill mode of the associated block will be reset to default values.

engine.block.setSourceSet(imageFill, 'fill/image/sourceSet', [{
uri: 'https://example.com/sample.jpg',
width: 800,
height: 600
}]);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property SourceSetPropertyName The name of the property to set.
sourceSet Source[] The block’s new source set.

Returns#

void

Signature#

setSourceSet(id: number, property: SourceSetPropertyName, sourceSet: Source[]): void

addImageFileURIToSourceSet()#


Adds an image file URI to a source set property.

If an image with the same width already exists in the source set, it will be replaced.

await engine.block.addImageFileURIToSourceSet(imageFill, 'fill/image/sourceSet', 'https://example.com/sample.jpg');

Parameters#

Parameter Type Description
id number The block to update.
property SourceSetPropertyName The name of the property to modify.
uri string The source to add to the source set.
options? AbortOptions An abortSignal that stops the download of the image. The source set stays unchanged then.

Returns#

Promise<void>

A promise that resolves when the operation is complete.

Signature#

addImageFileURIToSourceSet(id: number, property: SourceSetPropertyName, uri: string, options?: AbortOptions): Promise<void>

addVideoFileURIToSourceSet()#


Adds a video file URI to a source set property.

If a video with the same width already exists in the source set, it will be replaced.

await engine.block.addVideoFileURIToSourceSet(videoFill, 'fill/video/sourceSet', 'https://example.com/sample.mp4');

Parameters#

Parameter Type Description
id number The block to update.
property SourceSetPropertyName The name of the property to modify.
uri string The source to add to the source set.
options? AbortOptions An abortSignal that stops the download of the video. The source set stays unchanged then.

Returns#

Promise<void>

A promise that resolves when the operation is complete.

Signature#

addVideoFileURIToSourceSet(id: number, property: SourceSetPropertyName, uri: string, options?: AbortOptions): Promise<void>

supportsFill()#


Checks if a block supports a fill.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports a fill.

Signature#

supportsFill(id: number): boolean

isFillEnabled()#


Checks if the fill of a block is enabled.

The flag does not depend on an attached fill block. It defaults to true, so a fresh graphic reports its fill as enabled while getFill returns an invalid block. Check that result with isValid.

engine.block.isFillEnabled(block);

Parameters#

Parameter Type Description
id number The block whose fill state should be queried.

Returns#

boolean

The fill state.

Signature#

isFillEnabled(id: number): boolean

setFillEnabled()#


Enables or disables the fill of a block.

engine.block.setFillEnabled(block, false);

Parameters#

Parameter Type Description
id number The block whose fill should be enabled or disabled.
enabled boolean If true, the fill will be enabled.

Returns#

void

Signature#

setFillEnabled(id: number, enabled: boolean): void

getFillOverprint()#


Queries whether the fill of a block is marked as overprint for PDF export.

const overprint = engine.block.getFillOverprint(block);

Parameters#

Parameter Type Description
id number The block whose fill overprint flag should be queried.

Returns#

boolean

The fill overprint flag.

Signature#

getFillOverprint(id: number): boolean

setFillOverprint()#


Marks the fill of a block as overprint for PDF export.

The flag is only honored by the PDF writer when the fill uses a spot color (Separation/DeviceN). For process-color fills it is a silent no-op. On-screen rendering ignores the flag.

engine.block.setFillOverprint(block, true);

Parameters#

Parameter Type Description
id number The block whose fill overprint flag should be set.
overprint boolean If true, the fill is marked as overprint in exported PDFs.

Returns#

void

Signature#

setFillOverprint(id: number, overprint: boolean): void

getFill()#


Gets the fill block attached to a given block.

For example, a graphic has no fill right after create('graphic'), although isFillEnabled returns true.

const fill = engine.block.getFill(block);
if (engine.block.isValid(fill)) {
const fillType = engine.block.getType(fill);
}

Parameters#

Parameter Type Description
id number The block whose fill block should be returned.

Returns#

number

The block that currently defines the given block’s fill, or an invalid block if unset. Check the result with isValid.

Signature#

getFill(id: number): number

setFill()#


Sets the fill block for a given block.

The previous fill block is not destroyed automatically.

On a page slice, the call also enables the fill, because a new page slice has its fill disabled.

Parameters#

Parameter Type Description
id number The block whose fill should be changed.
fill number The new fill block.

Returns#

void

Signature#

setFill(id: number, fill: number): void

setFillSolidColor()#


Sets the solid fill color of a block.

Parameters#

Parameter Type Description
id number The block whose fill color should be set.
r number The red color component in the range of 0 to 1.
g number The green color component in the range of 0 to 1.
b number The blue color component in the range of 0 to 1.
a? number The alpha color component in the range of 0 to 1. Defaults to 1.

Returns#

void

Signature#

setFillSolidColor(id: number, r: number, g: number, b: number, a?: number): void

getFillSolidColor()#


Gets the solid fill color of a block as RGBA values.

Parameters#

Parameter Type Description
id number The block whose fill color should be queried.

Returns#

RGBA

The fill color.

Signature#

getFillSolidColor(id: number): RGBA

unstable_setImportedImageDefinition()#

Attaches the color definition found beside the fill’s current JPEG bytes.

The engine then decodes the JPEG samples in the given color space, instead of reading the JPEG’s own metadata. Finish writing an image buffer before calling this method.

The definition describes the image bytes it was read from, so it applies only while the image still holds them. A write that changes the bytes switches it off, and writing the same bytes back switches it on again. unstable_getImportedImageDefinition throws while it is off. Raw image-buffer writes do not change recorded definitions or create undoable image bytes. Remote content must stay unchanged while the definition is attached.

The engine owns mask bytes and reuses identical content. Change a mask only through this method. A write to a mask buffer makes the mask fail its hash check, so it no longer decodes. An undo step retains its recorded metadata and mask bytes. Masks are dependent image assets. Scene and block strings store their URLs and metadata, not their bytes. Use onDisallowedResourceScheme to persist mask bytes and return durable URLs, or save an archive that includes them. Allowing the buffer scheme does not persist bytes; the destination engine must restore those buffers separately. Missing or mismatched masks fail to decode.

Parameters#

Parameter Type Description
id number The image fill.
definition ImportedImageDefinitionInput The color definition of the fill’s current image.

Returns#

void

Throws#

Error if the block is not an image fill, has no image, uses a source set, or the definition is invalid. Unstable until the general design of image color provenance is settled. It then becomes stable or is replaced.


unstable_getImportedImageDefinition()#

Reads the color definition of the fill’s current image.

Parameters#

Parameter Type Description
id number The image fill.

Returns#

ImportedImageDefinitionInfo

The definition of the current image bytes.

Throws#

Error if the block is not an image fill or no definition applies. Unstable until the general design of image color provenance is settled. It then becomes stable or is replaced.

Block Shapes#

Create and configure shape blocks and geometric forms.

createShape()#


Creates a new shape block of a given type.

const star = engine.block.createShape('star');
// Longhand shape types are also supported
const rect = engine.block.createShape('//ly.img.ubq/shape/rect');

Parameters#

Parameter Type Description
type ShapeType The type of the shape object that shall be created.

Returns#

number

The created shape’s handle.

Signature#

createShape(type: ShapeType): number

supportsShape()#


Checks if a block supports having a shape.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block has a shape property, an error otherwise.

Signature#

supportsShape(id: number): boolean

getShape()#


Gets the shape block attached to a given block.

For example, a graphic has no shape right after create('graphic').

Parameters#

Parameter Type Description
id number The block whose shape block should be returned.

Returns#

number

The block that currently defines the given block’s shape, or an invalid block if unset. Check the result with isValid.

Signature#

getShape(id: number): number

setShape()#


Sets the shape block for a given block.

Note that the previous shape block is not destroyed automatically. The new shape is disconnected from its previously attached block. A page with page slices takes only a rect shape.

Parameters#

Parameter Type Description
id number The block whose shape should be changed.
shape number The new shape.

Returns#

void

Signature#

setShape(id: number, shape: number): void

getSubshapes()#


Gets the subshapes of a compound shape, in the order in which they combine.

const compound = engine.block.createShape('compound');
engine.block.appendSubshape(compound, engine.block.createShape('rect'));
const subshapes = engine.block.getSubshapes(compound);

Parameters#

Parameter Type Description
id number The compound shape block to query.

Returns#

number[]

The subshape blocks.

Signature#

getSubshapes(id: number): number[]

insertSubshape()#


Inserts a subshape into a compound shape at a given index.

The subshape at index 0 is the base, and each later subshape combines with the result so far by shape/compound/mode. The placement properties of the subshape (shape/position/x, shape/width, shape/rotation, …) place it in the compound’s coordinate space. A shape has one owner, so the subshape is detached from its previous block or compound shape. Line shapes cannot be subshapes. The call fails when the shape tree would nest more than 128 shapes.

Parameters#

Parameter Type Description
id number The compound shape block.
subshapeId number The shape block to insert.
index number The index in the range [0, number of subshapes].

Returns#

void

Signature#

insertSubshape(id: number, subshapeId: number, index: number): void

appendSubshape()#


Appends a subshape to a compound shape.

A shape has one owner, so the subshape is detached from its previous block or compound shape. Line shapes cannot be subshapes. The call fails when the shape tree would nest more than 128 shapes.

Parameters#

Parameter Type Description
id number The compound shape block.
subshapeId number The shape block to append.

Returns#

void

Signature#

appendSubshape(id: number, subshapeId: number): void

removeSubshape()#


Removes the subshape at a given index from a compound shape. The subshape is not destroyed.

Parameters#

Parameter Type Description
id number The compound shape block.
index number The index of the subshape to remove.

Returns#

void

Signature#

removeSubshape(id: number, index: number): void

Block Text#

Create, edit, and style text content.

replaceText()#


Replaces a range of text in a text block.

engine.block.replaceText(text, 'Hello World');
engine.block.replaceText(text, 'Alex', 6, 11);

Parameters#

Parameter Type Description
id number The text block into which to insert the given text.
text string The text which should replace the selected range in the block.
from? number The start index of the UTF-16 range to replace. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range to replace. Defaults to the end of the current selection or text.

Returns#

void

Signature#

replaceText(id: number, text: string, from?: number, to?: number): void

getTextAsHTML()#


Gets a range of a text block as HTML with its formatting, for the clipboard.

The HTML states the color, background color, weight, italic, decorations, script style, case, font size and typeface of each run as inline CSS. It states the list style, list level and alignment of each paragraph. Other apps read it on paste, and replaceTextWithHTML reads every property back. The typeface applies only when a typeface of the scene holds its font file. The font size and the line height are CSS values, so other apps show them as the block does.

document.addEventListener('copy', (event) => {
event.clipboardData?.setData('text/html', engine.block.getTextAsHTML(text));
event.preventDefault();
});

Parameters#

Parameter Type Description
id number The text block to read.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

string

The HTML, or an empty string for an empty range.

Signature#

getTextAsHTML(id: number, from?: number, to?: number): string

replaceTextWithHTML()#


Replaces a range of a text block with the text and the formatting of HTML, such as the HTML of a paste.

HTML from getTextAsHTML sets every property it carries. Its typeface applies only when a typeface of the scene holds its font file. Otherwise the text keeps the typeface at the cursor, with the weight and style of the source. HTML of another app, such as Google Docs, Word, a web page or an Apple app, sets weight, italic and decorations. It also sets the script style, case, colors, font size, letter spacing, line height, lists and alignment. A CSS px is one pixel of a scene whose font size unit is 'Pixel'. The text takes the first font family of the HTML that a typeface of the asset sources has. Without such a typeface, it keeps the typeface at the cursor. A gray, black or white that covers the largest part of the text is the default color of that app. It is not applied, and the same rule applies to the background color. A pasted paragraph without a list keeps the list of the target paragraph. Without the text/character scope, only the text is inserted, with the style at the cursor. Without the fill/change scope, or when the text color is bound to a variable, no color is pasted. When the font size or the typeface of the block is bound to a variable, it is not pasted. While the block is being edited and no range is given, the selection is replaced and the cursor moves behind the inserted text.

engine.block.replaceTextWithHTML(text, '<p><b>Hello</b> <i>world</i></p>');
document.addEventListener('paste', (event) => {
const html = event.clipboardData?.getData('text/html');
if (html) {
engine.block.replaceTextWithHTML(text, html);
event.preventDefault();
}
});

Parameters#

Parameter Type Description
id number The text block into which to insert the HTML.
html string The HTML. Markup that is not supported keeps only its text.
from? number The start index of the UTF-16 range to replace. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range to replace. If from is not negative and to is negative, the HTML is inserted at from. Otherwise it defaults to the end of the current selection or text.

Returns#

void

Signature#

replaceTextWithHTML(id: number, html: string, from?: number, to?: number): void

removeText()#


Removes a range of text from a text block.

engine.block.removeText(text, 0, 6);

Parameters#

Parameter Type Description
id number The text block from which the selected text should be removed.
from? number The start index of the UTF-16 range to remove. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range to remove. Defaults to the end of the current selection or text.

Returns#

void

Signature#

removeText(id: number, from?: number, to?: number): void

setTextColor()#


Sets the color for a range of text.

engine.block.setTextColor(text, { r: 0.0, g: 0.0, b: 0.0, a: 1.0 }, 1, 4);

Parameters#

Parameter Type Description
id number The text block whose color should be changed.
color Color The new color of the selected text range.
from? number The start index of the UTF-16 range to change. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range to change. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextColor(id: number, color: Color, from?: number, to?: number): void

getTextColors()#


Gets the unique colors within a range of text.

const colorsInRange = engine.block.getTextColors(text, 2, 5);

Parameters#

Parameter Type Description
id number The text block whose colors should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

Color[]

The ordered unique list of colors.

Signature#

getTextColors(id: number, from?: number, to?: number): Color[]

setTextBackgroundColor()#


Sets the background color for a range of text. The background is drawn as a rectangle behind each affected text run, or as a band along the curve for text on a path. A fully transparent color removes the background from the range. The run background is independent of the block-level background color (‘backgroundColor/color’); it is drawn on top of the block-level background.

engine.block.setTextBackgroundColor(text, { r: 1.0, g: 1.0, b: 0.0, a: 1.0 }, 1, 4);

Parameters#

Parameter Type Description
id number The text block whose background color should be changed.
color Color The new background color of the selected text range.
from? number The start index of the UTF-16 range to change. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range to change. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextBackgroundColor(id: number, color: Color, from?: number, to?: number): void

getTextBackgroundColors()#


Gets the unique background colors within a range of text. Text without a background color is reported as a fully transparent color.

const backgroundColorsInRange = engine.block.getTextBackgroundColors(text, 2, 5);

Parameters#

Parameter Type Description
id number The text block whose background colors should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

Color[]

The ordered unique list of background colors.

Signature#

getTextBackgroundColors(id: number, from?: number, to?: number): Color[]

setTextFontWeight()#


Sets the font weight for a range of text.

engine.block.setTextFontWeight(text, 'bold', 0, 5);

Parameters#

Parameter Type Description
id number The text block whose weight should be changed.
fontWeight FontWeight The new weight of the selected text range.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextFontWeight(id: number, fontWeight: FontWeight, from?: number, to?: number): void

getTextFontWeights()#


Gets the unique font weights within a range of text.

const fontWeights = engine.block.getTextFontWeights(text, 0, 6);

Parameters#

Parameter Type Description
id number The text block whose font weights should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

FontWeight[]

The ordered unique list of font weights.

Signature#

getTextFontWeights(id: number, from?: number, to?: number): FontWeight[]

setTextFontSize()#


Sets the font size for a range of text.

// With numeric fontSize (in points)
engine.block.setTextFontSize(text, 12, 0, 5);
// With font size and options object
engine.block.setTextFontSize(text, 16, { unit: 'Pixel' });
engine.block.setTextFontSize(text, 24, { unit: 'Point', from: 0, to: 10 });
Parameters#
Parameter Type Description
id number The text block whose font size should be changed.
fontSize number The new font size value.
options? TextFontSizeOptions An options object with unit, from, and to properties.
Returns#

void

Call Signature#

setTextFontSize(
id,
fontSize,
from?,
to?): void;

Sets the font size for a range of text.

Parameters#
Parameter Type Description
id number The text block whose font size should be changed.
fontSize number The new font size in points.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.
Returns#

void

Deprecated#

Use the new signature with options object instead.

Example#
// Before migration
engine.block.setTextFontSize(text, 18, 0, 5);
// After migration
engine.block.setTextFontSize(text, 18, { from: 0, to: 5 });

Signatures#

setTextFontSize(id: number, fontSize: number, options?: TextFontSizeOptions): void
setTextFontSize(id: number, fontSize: number, from?: number, to?: number): void

getTextFontSizes()#


Gets the unique font sizes within a range of text.

// Get all font sizes
const fontSizes = engine.block.getTextFontSizes(text);
// Get font sizes for a range
const fontSizes = engine.block.getTextFontSizes(text, 0, 10);
// With options object
const sizesInPx = engine.block.getTextFontSizes(text, { unit: 'Pixel' });
const sizesInRange = engine.block.getTextFontSizes(text, { unit: 'Millimeter', from: 5, to: 15 });
Parameters#
Parameter Type Description
id number The text block whose font sizes should be returned.
options? TextFontSizeOptions An options object with unit, from, and to properties.
Returns#

number[]

The ordered unique list of font sizes.

Call Signature#

getTextFontSizes(
id,
from?,
to?): number[];

Gets the unique font sizes within a range of text.

Parameters#
Parameter Type Description
id number The text block whose font sizes should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.
Returns#

number[]

The ordered unique list of font sizes in points.

Deprecated#

Use the new signature with options object instead.

Example#
// Before migration
const fontSizes = engine.block.getTextFontSizes(text, 0, 10);
// After migration
const fontSizes = engine.block.getTextFontSizes(text, { from: 0, to: 10 });

Signatures#

getTextFontSizes(id: number, options?: TextFontSizeOptions): number[]
getTextFontSizes(id: number, from?: number, to?: number): number[]

setTextFontStyle()#


Sets the font style for a range of text.

engine.block.setTextFontStyle(text, 'italic', 0, 5);

Parameters#

Parameter Type Description
id number The text block whose style should be changed.
fontStyle FontStyle The new style of the selected text range.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextFontStyle(id: number, fontStyle: FontStyle, from?: number, to?: number): void

setTextFontWeightAndStyle()#


Sets the font weight and the font style for a range of text in one step.

Each run gets the font of its typeface with exactly this weight and style. Separate calls to setTextFontWeight and setTextFontStyle pass through a face in between, so they fail when the typeface lacks that face.

engine.block.setTextFontWeightAndStyle(text, 'bold', 'italic', 0, 5);

Parameters#

Parameter Type Description
id number The text block whose weight and style should be changed.
fontWeight FontWeight The new weight of the selected text range.
fontStyle FontStyle The new style of the selected text range.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Throws#

Error with code BLOCK.TEXT_UNSUPPORTED_FONT_FACE when the typeface of a run has no font with this weight and style. That run keeps its font, and the other runs of the range change. A run with a font request from setFontRequest takes the face into its request and gets no error.

Signature#

setTextFontWeightAndStyle(id: number, fontWeight: FontWeight, fontStyle: FontStyle, from?: number, to?: number): void

getTextFontStyles()#


Gets the unique font styles within a range of text.

const fontStyles = engine.block.getTextFontStyles(text);

Parameters#

Parameter Type Description
id number The text block whose font styles should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

FontStyle[]

The ordered unique list of font styles.

Signature#

getTextFontStyles(id: number, from?: number, to?: number): FontStyle[]

getTextCases()#


Gets the unique text cases within a range of text.

const textCases = engine.block.getTextCases(text);

Parameters#

Parameter Type Description
id number The text block whose text cases should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

TextCase[]

The ordered list of text cases.

Signature#

getTextCases(id: number, from?: number, to?: number): TextCase[]

setTextCase()#


Sets the text case for a range of text.

engine.block.setTextCase(text, 'Titlecase');

Parameters#

Parameter Type Description
id number The text block whose text case should be changed.
textCase TextCase The new text case value.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextCase(id: number, textCase: TextCase, from?: number, to?: number): void

getTextScriptStyles()#


Gets the unique text script styles within a range of text.

const scriptStyles = engine.block.getTextScriptStyles(text);
// e.g., ['Normal', 'Superscript']

Parameters#

Parameter Type Description
id number The text block whose script styles should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

ScriptStyle[]

The ordered list of unique script styles.

Signature#

getTextScriptStyles(id: number, from?: number, to?: number): ScriptStyle[]

setTextScriptStyle()#


Sets the script style for a range of text.

Superscript and subscript text is scaled down and shifted off the regular baseline. The block properties ‘text/superscriptFontScale’, ‘text/superscriptVerticalShift’, ‘text/subscriptFontScale’ and ‘text/subscriptVerticalShift’ adjust the scale and shift.

engine.block.setTextScriptStyle(text, 'Superscript');

Parameters#

Parameter Type Description
id number The text block whose script style should be changed.
scriptStyle ScriptStyle The new script style.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextScriptStyle(id: number, scriptStyle: ScriptStyle, from?: number, to?: number): void

getTextDecorations()#


Gets the unique text decoration configurations within a range of text.

Each element of the returned array is a decoration configuration representing a unique combination of lines, style, color, and thickness found in the range.

const decorations = engine.block.getTextDecorations(text);
// e.g., [{ lines: ['None'] }, { lines: ['Underline'], style: 'Dashed' }]

Parameters#

Parameter Type Description
id number The text block whose text decorations should be returned.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

TextDecorationConfig[]

The ordered list of unique decoration configurations.

Signature#

getTextDecorations(id: number, from?: number, to?: number): TextDecorationConfig[]

setTextDecoration()#


Sets the text decoration for a range of text.

The config specifies which decoration lines, style, underline color, thickness, and offset to apply. Use { lines: ['None'] } to remove all decorations.

engine.block.setTextDecoration(text, { lines: ['Underline'] });
engine.block.setTextDecoration(text, { lines: ['Underline', 'Strikethrough'], style: 'Dashed' });
engine.block.setTextDecoration(text, { lines: ['Overline'], style: 'Wavy', underlineThickness: 2.0 });
engine.block.setTextDecoration(text, { lines: ['None'] }); // Remove decorations

Parameters#

Parameter Type Description
id number The text block whose text decoration should be changed.
config TextDecorationConfig The decoration configuration to apply.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextDecoration(id: number, config: TextDecorationConfig, from?: number, to?: number): void

setTextKerning()#


Sets kerning for a grapheme range.

Applies an additional offset in em units on top of the font’s built-in kern. 1.0 equals the run’s font size, so the offset scales proportionally with text size.

engine.block.setTextKerning(text, 0.1); // add 10% of font size as extra spacing
engine.block.setTextKerning(text, -0.05, 0, 5); // tighten first 5 graphemes
engine.block.setTextKerning(text, 0); // reset to no extra offset

Parameters#

Parameter Type Description
id number The text block to modify.
kerning number Additional kerning in em units (1.0 = one full em). Use 0 for no extra offset.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextKerning(id: number, kerning: number, from?: number, to?: number): void

getTextKernings()#


Returns the unique kerning values across the grapheme range.

const kernings = engine.block.getTextKernings(text); // e.g. [0] or [0.1, 0]

Parameters#

Parameter Type Description
id number The text block to query.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

number[]

Signature#

getTextKernings(id: number, from?: number, to?: number): number[]

setTextOpenTypeFeatures()#


Sets the OpenType features of a text range, such as tnum for digits of equal width.

The list replaces the features that the range had, and an empty list removes them. When a tag repeats, the last entry wins. The features apply after the ligature and kerning settings of the block, so an entry for liga or kern overrides them in the range. A tag that the font does not have changes nothing. editor.getFontInfo lists the features of a font. Required scope: “text/character”

engine.block.setTextOpenTypeFeatures(text, [{ tag: 'tnum', value: 1 }]); // digits of equal width
engine.block.setTextOpenTypeFeatures(text, [{ tag: 'liga', value: 0 }], 0, 5); // no ligatures in the first 5
engine.block.setTextOpenTypeFeatures(text, []); // remove all features

Parameters#

Parameter Type Description
id number The text block to modify.
features OpenTypeFeature[] The features. Each tag has four ASCII characters. A value of 0 turns the feature off, 1 turns it on, and a larger value selects an alternate by its index.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Throws#

An error with the code BLOCK.TEXT_INVALID_OPENTYPE_TAG when a tag is not four ASCII characters, and BLOCK.TEXT_TOO_MANY_OPENTYPE_SETTINGS when the list has more than 64 entries.

Signature#

setTextOpenTypeFeatures(id: number, features: OpenTypeFeature[], from?: number, to?: number): void

getTextOpenTypeFeatures()#


Returns the unique OpenType feature lists across a text range.

Each list holds one entry per tag, sorted by tag. A range without features returns one empty list.

const features = engine.block.getTextOpenTypeFeatures(text); // e.g. [[]] or [[{ tag: 'tnum', value: 1 }], []]

Parameters#

Parameter Type Description
id number The text block to query.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

OpenTypeFeature[][]

The unique feature lists in the range.

Signature#

getTextOpenTypeFeatures(id: number, from?: number, to?: number): OpenTypeFeature[][]

setTextVariationAxes()#


Sets the variation axis values of a text range, such as wdth for the width of a variable font.

The list replaces the axis values that the range had, and an empty list removes them. When a tag repeats, the last entry wins. An axis without a value keeps the value that the font file and the font weight and style select. A wght entry overrides the font weight with any value, such as 450, and setTextFontWeight does not remove it. An ital or slnt entry overrides the font style in the same way, and setTextFontStyle does not remove it either. The font clamps a value to the range of its axis, and an axis that the font does not have changes nothing. Values keep three decimals. editor.getFontInfo lists the axes of a font. Required scope: “text/character”

engine.block.setTextVariationAxes(text, [{ tag: 'wdth', value: 75 }]); // a narrower width
engine.block.setTextVariationAxes(text, [{ tag: 'wght', value: 450 }], 0, 5); // a weight between two named ones
engine.block.setTextVariationAxes(text, []); // remove all axis values

Parameters#

Parameter Type Description
id number The text block to modify.
axes VariationAxisValue[] The axis values. Each tag has four ASCII characters.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Throws#

An error with the code BLOCK.TEXT_INVALID_OPENTYPE_TAG when a tag is not four ASCII characters, BLOCK.TEXT_INVALID_VARIATION_AXIS_VALUE when a value is not finite, and BLOCK.TEXT_TOO_MANY_OPENTYPE_SETTINGS when the list has more than 64 entries.

Signature#

setTextVariationAxes(id: number, axes: VariationAxisValue[], from?: number, to?: number): void

getTextVariationAxes()#


Returns the unique variation axis value lists across a text range.

Each list holds one entry per tag, sorted by tag. A range without axis values returns one empty list.

const axes = engine.block.getTextVariationAxes(text); // e.g. [[]] or [[{ tag: 'wdth', value: 75 }]]

Parameters#

Parameter Type Description
id number The text block to query.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

VariationAxisValue[][]

The unique axis value lists in the range.

Signature#

getTextVariationAxes(id: number, from?: number, to?: number): VariationAxisValue[][]

setTextBaselineShift()#


Sets the baseline shift for a grapheme range.

Moves the glyphs of the range up from the baseline, or down for a negative value. The value is in design units. The line height does not change.

engine.block.setTextBaselineShift(text, 4); // raise the whole text by 4 design units
engine.block.setTextBaselineShift(text, -2, 0, 5); // lower the first 5 graphemes
engine.block.setTextBaselineShift(text, 0); // back on the baseline

Parameters#

Parameter Type Description
id number The text block to modify.
baselineShift number The vertical offset in design units. Positive values move the glyphs up.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

setTextBaselineShift(id: number, baselineShift: number, from?: number, to?: number): void

getTextBaselineShifts()#


Returns the unique baseline shift values across the grapheme range, in design units.

const shifts = engine.block.getTextBaselineShifts(text); // e.g. [0] or [4, 0]

Parameters#

Parameter Type Description
id number The text block to query.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

number[]

The unique baseline shift values in text order.

Signature#

getTextBaselineShifts(id: number, from?: number, to?: number): number[]

toggleTextDecorationUnderline()#


Toggles the underline decoration for a text range.

If any part of the range does not have underline, the entire range gets underline. If the entire range already has underline, it is removed. Other decoration lines (strikethrough, overline) on each text run are preserved.

engine.block.toggleTextDecorationUnderline(text);

Parameters#

Parameter Type Description
id number The text block to modify.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

toggleTextDecorationUnderline(id: number, from?: number, to?: number): void

toggleTextDecorationStrikethrough()#


Toggles the strikethrough decoration for a text range.

If any part of the range does not have strikethrough, the entire range gets strikethrough. If the entire range already has strikethrough, it is removed. Other decoration lines (underline, overline) on each text run are preserved.

engine.block.toggleTextDecorationStrikethrough(text);

Parameters#

Parameter Type Description
id number The text block to modify.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

toggleTextDecorationStrikethrough(id: number, from?: number, to?: number): void

toggleTextDecorationOverline()#


Toggles the overline decoration for a text range.

If any part of the range does not have overline, the entire range gets overline. If the entire range already has overline, it is removed. Other decoration lines (underline, strikethrough) on each text run are preserved.

engine.block.toggleTextDecorationOverline(text);

Parameters#

Parameter Type Description
id number The text block to modify.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

toggleTextDecorationOverline(id: number, from?: number, to?: number): void

getTextHorizontalAlignment()#


Gets the paragraph-level horizontal alignment override for a specific paragraph, or the block-level alignment.

const alignment = engine.block.getTextHorizontalAlignment(text, 0);
const blockAlignment = engine.block.getTextHorizontalAlignment(text); // paragraphIndex defaults to -1
// e.g. 'Left' | 'Right' | 'Center' | 'Justify' | 'Auto' | undefined

Parameters#

Parameter Type Description
id number The text block to query.
paragraphIndex? number The 0-based index of the paragraph to query. Negative values return the block-level text/horizontalAlignment setting.

Returns#

"Auto" | "Right" | "Left" | "Center" | "Justify"

The paragraph override, undefined if no override is set, or the block-level alignment when paragraphIndex < 0.

Signature#

getTextHorizontalAlignment(id: number, paragraphIndex?: number): "Auto" | "Right" | "Left" | "Center" | "Justify"

setTextHorizontalAlignment()#


Sets the paragraph-level horizontal alignment override for one or all paragraphs.

engine.block.setTextHorizontalAlignment(text, 'Center', 0);
engine.block.setTextHorizontalAlignment(text, undefined, 0); // clear override
engine.block.setTextHorizontalAlignment(text, 'Right'); // apply to all
engine.block.setTextHorizontalAlignment(text, 'Justify'); // stretch every line but each paragraph's last

Parameters#

Parameter Type Description
id number The text block to modify.
alignment "Auto" "Right"
paragraphIndex? number The 0-based index of the paragraph. Negative values clear all paragraph-level alignment overrides and, when alignment is provided, apply that alignment to the whole text block.

Returns#

void

Signature#

setTextHorizontalAlignment(id: number, alignment: "Auto" | "Right" | "Left" | "Center" | "Justify", paragraphIndex?: number): void

getTextListStyle()#


Gets the list style for a specific paragraph of a text block.

const listStyle = engine.block.getTextListStyle(text, 0);

Parameters#

Parameter Type Description
id number The text block whose list style should be returned.
paragraphIndex number The 0-based index of the paragraph. Must be non-negative: unlike the setter, a negative index throws.

Returns#

ListStyle

The list style of the paragraph.

Signature#

getTextListStyle(id: number, paragraphIndex: number): ListStyle

setTextListStyle()#


Sets the list style for a specific paragraph or all paragraphs of a text block.

engine.block.setTextListStyle(text, 'Unordered');
engine.block.setTextListStyle(text, 'Ordered', 0, 2);

Parameters#

Parameter Type Description
id number The text block whose list style should be changed.
listStyle ListStyle The list style to apply.
paragraphIndex? number The 0-based index of the paragraph to modify. Negative values apply to all paragraphs.
listLevel? number Optional list nesting level to set atomically with the list style (0 = outermost). When omitted the existing list level of each paragraph is preserved. Has no visual effect when listStyle is ‘None’.

Returns#

void

Signature#

setTextListStyle(id: number, listStyle: ListStyle, paragraphIndex?: number, listLevel?: number): void

getTextListLevel()#


Gets the list nesting level for a specific paragraph of a text block.

const listLevel = engine.block.getTextListLevel(text, 0);

Parameters#

Parameter Type Description
id number The text block whose list level should be returned.
paragraphIndex number The 0-based index of the paragraph. Must be non-negative: unlike the setter, a negative index throws.

Returns#

number

The list nesting level of the paragraph.

Signature#

getTextListLevel(id: number, paragraphIndex: number): number

setTextListLevel()#


Sets the list nesting level for a specific paragraph or all paragraphs of a text block.

engine.block.setTextListLevel(text, 1);
engine.block.setTextListLevel(text, 2, 0);

Parameters#

Parameter Type Description
id number The text block whose list level should be changed.
listLevel number The list nesting level (0 = outermost).
paragraphIndex? number The 0-based index of the paragraph to modify. Negative values apply to all paragraphs.

Returns#

void

Signature#

setTextListLevel(id: number, listLevel: number, paragraphIndex?: number): void

getTextParagraphIndices()#


Returns the 0-based paragraph indices that overlap the given UTF-16 range.

The range is half-open (exclusive): from is inclusive, to is exclusive (one past the last code unit of interest). When from === to the range is a cursor position and the paragraph containing from is returned. This convention matches getTextCursorRange, so the values it returns can be passed directly without adjustment.

Negative values for either parameter cause all paragraph indices to be returned.

const indices = engine.block.getTextParagraphIndices(text);
const { from, to } = engine.block.getTextCursorRange();
const indices = engine.block.getTextParagraphIndices(text, from, to);

Parameters#

Parameter Type Description
id number The text block to query.
from? number The inclusive start UTF-16 index. Negative values reference the entire text.
to? number The exclusive end UTF-16 index. Negative values reference the entire text.

Returns#

number[]

The paragraph indices overlapping the range.

Signature#

getTextParagraphIndices(id: number, from?: number, to?: number): number[]

setTextLineHeight()#


Sets the line height multiplier for a specific paragraph or all paragraphs of a text block.

engine.block.setTextLineHeight(text, 1.5);
engine.block.setTextLineHeight(text, 1.5, 0);
engine.block.setTextLineHeight(text, null); // reset all paragraphs to block default

Parameters#

Parameter Type Description
id number The text block to modify.
lineHeight number The line height multiplier, or null to reset to the block-level default.
paragraphIndex? number The 0-based index of the paragraph to modify. Negative values apply to all paragraphs.

Returns#

void

Signature#

setTextLineHeight(id: number, lineHeight: number, paragraphIndex?: number): void

getTextLineHeight()#


Returns the line height multiplier for a specific paragraph of a text block.

Returns the per-paragraph override if one is set, otherwise returns the block-level lineHeight.

const lineHeight = engine.block.getTextLineHeight(text, 0);

Parameters#

Parameter Type Description
id number The text block to query.
paragraphIndex number The 0-based index of the paragraph. Must be non-negative: unlike the setter, a negative index throws.

Returns#

number

The line height multiplier for the paragraph.

Signature#

getTextLineHeight(id: number, paragraphIndex: number): number

canToggleBoldFont()#


Checks if the bold font weight can be toggled for a range of text.

Returns true if any part of the range is not bold and the bold font is available.

const canToggleBold = engine.block.canToggleBoldFont(text);

Parameters#

Parameter Type Description
id number The text block to check.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

boolean

Whether the font weight can be toggled.

Signature#

canToggleBoldFont(id: number, from?: number, to?: number): boolean

canToggleItalicFont()#


Checks if the italic font style can be toggled for a range of text.

Returns true if any part of the range is not italic and the italic font is available.

const canToggleItalic = engine.block.canToggleItalicFont(text);

Parameters#

Parameter Type Description
id number The text block to check.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

boolean

Whether the font style can be toggled.

Signature#

canToggleItalicFont(id: number, from?: number, to?: number): boolean

toggleBoldFont()#


Toggles the font weight of a text range between bold and normal.

If any part of the range is not bold, the entire range becomes bold. If the entire range is already bold, it becomes normal.

engine.block.toggleBoldFont(text);

Parameters#

Parameter Type Description
id number The text block to modify.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

toggleBoldFont(id: number, from?: number, to?: number): void

toggleItalicFont()#


Toggles the font style of a text range between italic and normal.

If any part of the range is not italic, the entire range becomes italic. If the entire range is already italic, it becomes normal.

engine.block.toggleItalicFont(text);

Parameters#

Parameter Type Description
id number The text block to modify.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Signature#

toggleItalicFont(id: number, from?: number, to?: number): void

setFont()#


Sets the font and typeface for an entire text block.

Existing formatting is reset.

engine.block.setFont(text, font.uri, typeface);

Parameters#

Parameter Type Description
id number The text block whose font should be changed.
fontFileUri string The URI of the new font file.
typeface Typeface The typeface of the new font.

Returns#

void

Note#

Saved scenes, archives, and blocks use content-based typeface IDs. Upgrade all readers to support these IDs before saving content with this engine.

Signature#

setFont(id: number, fontFileUri: string, typeface: Typeface): void

setFontRequest()#


Sets an authored font request for a UTF-16 source-text range. Omitting both bounds sets the whole block, including while text is selected. Resolution is asynchronous; forceLoadResources waits for pending providers and fonts. Concrete font setters replace the request on their range.

Parameters#

Parameter Type
id number
request FontRequest
from? number
to? number

Returns#

void

Signature#

setFontRequest(id: number, request: FontRequest, from?: number, to?: number): void

getFontRequests()#


Returns unique authored font requests in a UTF-16 source-text range. Omitted bounds use the current selection, or the whole text without a selection.

Parameters#

Parameter Type
id number
from? number
to? number

Returns#

FontRequest[]

Signature#

getFontRequests(id: number, from?: number, to?: number): FontRequest[]

setTypeface()#


Sets the typeface for a range of text.

The current formatting is retained as much as possible.

engine.block.setTypeface(text, typeface, 2, 5);

Parameters#

Parameter Type Description
id number The text block whose font should be changed.
typeface Typeface The new typeface.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

void

Note#

Saved scenes, archives, and blocks use content-based typeface IDs. Upgrade all readers to support these IDs before saving content with this engine.

Signature#

setTypeface(id: number, typeface: Typeface, from?: number, to?: number): void

getTypeface()#


Gets the base typeface of a text block.

This does not return the typefaces of individual text runs.

const defaultTypeface = engine.block.getTypeface(text);

Parameters#

Parameter Type Description
id number The text block whose typeface should be queried.

Returns#

Typeface

the typeface property of the text block.

Signature#

getTypeface(id: number): Typeface

getTypefaces()#


Gets the unique typefaces within a range of text.

const currentTypefaces = engine.block.getTypefaces(text);

Parameters#

Parameter Type Description
id number The text block whose typefaces should be queried.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.

Returns#

Typeface[]

The unique typefaces in the range.

Signature#

getTypefaces(id: number, from?: number, to?: number): Typeface[]

getTextRuns()#


Gets all text runs within a range of text.

Each run represents a contiguous span of text with uniform formatting. Each fontSize is in points unless you pass unit. 'Pixel' converts with the scene’s scene/dpi, so it throws without a scene.

const runs = engine.block.getTextRuns(text);
const runsInPixels = engine.block.getTextRuns(text, { unit: 'Pixel' });
Parameters#
Parameter Type Description
id number The text block to query.
options? TextFontSizeOptions The unit of the run font sizes, and the UTF-16 range from and to. The range defaults to the current selection or the whole text.
Returns#

TextRunInfo[]

The ordered list of text runs covering the requested range.

Call Signature#

getTextRuns(
id,
from?,
to?): TextRunInfo[];

Gets all text runs within a range of text.

Parameters#
Parameter Type Description
id number The text block to query.
from? number The start index of the UTF-16 range. Defaults to the start of the current selection or text.
to? number The end index of the UTF-16 range. Defaults to the end of the current selection or text.
Returns#

TextRunInfo[]

The ordered list of text runs covering the requested range.

Signatures#

getTextRuns(id: number, options?: TextFontSizeOptions): TextRunInfo[]
getTextRuns(id: number, from?: number, to?: number): TextRunInfo[]

getTextCursorRange()#


Gets the current text cursor or selection range.

Returns the UTF-16 indices of the selected range of the text block that is currently being edited. The range is half-open (exclusive): from is the index of the first selected code unit, to is one past the last selected code unit. When from === to the cursor is positioned between characters with no text selected.

const selectedRange = engine.block.getTextCursorRange();

Returns#

Range

The selected UTF-16 range or { from: -1, to: -1 } if no text block is being edited.

Signature#

getTextCursorRange(): Range_2

setTextCursorRange()#


Sets the text cursor range (selection) within the text block that is currently being edited.

Parameters#

Parameter Type Description
range Range The UTF-16 range to set as the selection. If from equals to, the cursor is positioned at that index. If from and to are set to -1, the whole text is selected.

Returns#

void

Throws#

Error if no text block is currently being edited or if the range is invalid.

Signature#

setTextCursorRange(range: Range_2): void

getTextRenderDiagnostics()#


Gets the current fonts, missing glyphs and planar layout of a text block.

Run and missing-glyph ranges are half-open UTF-16 offsets in fontUsage.text, after case transformations and template resolution. Effective font sizes use the scene’s font-size unit. Layout includes hidden lines; its overshoot and required height use local design units before strokes, effects and animations. Layout is absent while resources are pending, without a current shape, or for text on a path. resolved font usage does not guarantee glyph coverage.

This updates pending layout synchronously without changing serialized block properties. It does not wait for downloads; use forceLoadResources first when the snapshot must include loaded fonts.

Parameters#

Parameter Type Description
id number The text block to query.

Returns#

TextRenderDiagnostics

The current rendering diagnostics.

Throws#

If the block is invalid or is not text.

Signature#

getTextRenderDiagnostics(id: number): TextRenderDiagnostics

getTextVisibleLineCount()#


Gets the number of visible lines in a text block.

const lineCount = engine.block.getTextVisibleLineCount(text);

Parameters#

Parameter Type Description
id number The text block whose line count should be returned.

Returns#

number

The number of lines in the text block.

Signature#

getTextVisibleLineCount(id: number): number

getTextVisibleLineGlobalBoundingBoxXYWH()#


Gets the global bounding box of a visible line of text.

The values are in the scene’s global coordinate space.

const lineBoundingBox = engine.block.getTextVisibleLineGlobalBoundingBoxXYWH(text, 0);

Parameters#

Parameter Type Description
id number The text block whose line bounding box should be returned.
lineIndex number The index of the line whose bounding box should be returned.

Returns#

XYWH

The bounding box of the line.

Signature#

getTextVisibleLineGlobalBoundingBoxXYWH(id: number, lineIndex: number): XYWH

getTextVisibleLineContent()#


Gets the text content of a visible line.

Parameters#

Parameter Type Description
id number The text block whose line content should be returned.
lineIndex number The index of the line whose content should be returned.

Returns#

string

The text content of the line.

Signature#

getTextVisibleLineContent(id: number, lineIndex: number): string

getTextCharacterInkBoxes()#


Returns the tight ink-paint bounding box for each grapheme in the range. One entry per grapheme in [from, to). Non-printable graphemes get a zero-rect. Coordinates are in global scene space.

Parameters#

Parameter Type Description
id number The text block to query.
from? number Start grapheme index (-1 = start of cursor selection or 0).
to? number End grapheme index (-1 = end of cursor selection or text length).

Returns#

CharacterInkBox[]

Array of CharacterInkBox, one per grapheme in range, in text order.

Signature#

getTextCharacterInkBoxes(id: number, from?: number, to?: number): CharacterInkBox[]

getTextEffectiveHorizontalAlignment()#


Gets the effective horizontal alignment of a text block. If the alignment is set to Auto, this returns the resolved alignment (Left or Right) based on the text direction of the first logical run. This never returns ‘Auto’.

Parameters#

Parameter Type Description
id number The text block whose effective alignment should be returned.

Returns#

"Right" | "Left" | "Center" | "Justify"

The effective alignment (‘Left’, ‘Right’, ‘Center’, or ‘Justify’). Only 'Auto' is resolved — 'Justify' is itself an effective alignment and is returned verbatim.

Signature#

getTextEffectiveHorizontalAlignment(id: number): "Right" | "Left" | "Center" | "Justify"

setTextOnPath()#


Sets the SVG path that the text baseline follows. Pass null to restore normal straight-line text layout.

Parameters#

Parameter Type Description
id number The text block to modify.
svgPath string An SVG path string in the block’s local coordinate space, or null to clear.

Returns#

void

Signature#

setTextOnPath(id: number, svgPath: string): void

getTextOnPath()#


Gets the SVG path currently used as the text baseline.

Parameters#

Parameter Type Description
id number The text block to query.

Returns#

string

The SVG path string, or null if no path is set.

Signature#

getTextOnPath(id: number): string

setTextOnPathOffset()#


Sets the start offset along the baseline path as a proportion of the path length. Values are clamped to [-1, 1]; 1 and -1 wrap back to the path start.

Parameters#

Parameter Type Description
id number The text block to modify.
offset number The proportional offset. Positive values move the text forward along the path.

Returns#

void

Signature#

setTextOnPathOffset(id: number, offset: number): void

getTextOnPathOffset()#


Gets the start offset along the baseline path as a proportion of the path length.

Parameters#

Parameter Type Description
id number The text block to query.

Returns#

number

The proportional offset in [-1, 1].

Signature#

getTextOnPathOffset(id: number): number

setTextOnPathFlipped()#


Sets whether text is placed on the opposite side of the baseline path.

Parameters#

Parameter Type Description
id number The text block to modify.
flipped boolean When true, text sits on the underside of the curve and reads in the reverse direction.

Returns#

void

Signature#

setTextOnPathFlipped(id: number, flipped: boolean): void

getTextOnPathFlipped()#


Gets whether the text-on-path rendering is flipped.

Parameters#

Parameter Type Description
id number The text block to query.

Returns#

boolean

true when text is on the underside of the curve.

Signature#

getTextOnPathFlipped(id: number): boolean

Block Video#

Manage time-based media like video and audio, including playback, timing, and controls.

createCaptionsFromURI()#


Creates new caption blocks from an SRT or VTT file URI.

Parameters#

Parameter Type Description
uri string The URI for the captions file to load. Supported file formats are: SRT and VTT.
options? AbortOptions An abortSignal that stops the download of the file. No caption block is created then.

Returns#

Promise<number[]>

A promise that resolves with a list of the created caption blocks.

Signature#

createCaptionsFromURI(uri: string, options?: AbortOptions): Promise<number[]>

supportsDuration()#


Checks if a block supports a duration property.

False for a page slice, which always lasts as long as its page.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true if the block supports a duration property.

Signature#

supportsDuration(id: number): boolean

setDuration()#


Sets the playback duration of a block.

The duration defines how long the block is active in the scene during playback. Note: A clip on a track without automatic offsets keeps its transitions. The next clip of each transition moves, with the clips that transitions join after it, until the overlap equals the transition duration again. The overlap is at most half of either clip. With transition/overlap disabled, or with a group clip on either side, the clips meet at the cut.

Parameters#

Parameter Type Description
id number The block whose duration should be changed.
duration number The new duration in seconds. Infinity is allowed; NaN or a negative value is an error.

Returns#

void

Signature#

setDuration(id: number, duration: number): void

getDuration()#


Gets the playback duration of a block. For a scene, the sum of the durations of its pages, without the pages hidden with setVisible(false).

Parameters#

Parameter Type Description
id number The block whose duration should be returned.

Returns#

number

The block’s duration in seconds.

Signature#

getDuration(id: number): number

setPageDurationSource()#


Sets a block as the page’s duration source.

This causes the page’s total duration to be automatically determined by this block.

Parameters#

Parameter Type Description
page number The page block for which it should be enabled.
id number The block that should become the duration source.

Returns#

void

Signature#

setPageDurationSource(page: number, id: number): void

isPageDurationSource()#


Checks if a block is the duration source for its page.

Parameters#

Parameter Type Description
id number The block whose duration source property should be queried.

Returns#

boolean

true if the block is a duration source for a page.

Signature#

isPageDurationSource(id: number): boolean

supportsPageDurationSource()#


Checks if a block can be set as the page’s duration source.

Parameters#

Parameter Type Description
page number The page to check against.
id number The block to query.

Returns#

boolean

true, if the block can be marked as the page’s duration source.

Signature#

supportsPageDurationSource(page: number, id: number): boolean

removePageDurationSource()#


Removes a block as the page’s duration source.

If a scene or page is given, it is deactivated for all blocks within it.

Parameters#

Parameter Type Description
id number The block whose duration source property should be removed.

Returns#

void

Signature#

removePageDurationSource(id: number): void

supportsTimeOffset()#


Checks if a block supports a time offset.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports a time offset.

Signature#

supportsTimeOffset(id: number): boolean

setTimeOffset()#


Sets the time offset of a block relative to its parent.

The time offset controls when the block first becomes active in the timeline.

Parameters#

Parameter Type Description
id number The block whose time offset should be changed.
offset number The new time offset in seconds.

Returns#

void

Signature#

setTimeOffset(id: number, offset: number): void

getTimeOffset()#


Gets the time offset of a block relative to its parent.

Parameters#

Parameter Type Description
id number The block whose time offset should be queried.

Returns#

number

The time offset of the block in seconds.

Signature#

getTimeOffset(id: number): number

supportsTrim()#


Checks if a block supports trim properties.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports trim properties.

Signature#

supportsTrim(id: number): boolean

setTrimOffset()#


Sets the trim offset of a block’s media content.

This sets the time within the media clip where playback should begin.

Parameters#

Parameter Type Description
id number The block whose trim should be updated.
offset number The new trim offset, in timeline seconds. At speed 2, an offset of 1 skips 2 seconds of the source.

Returns#

void

Signature#

setTrimOffset(id: number, offset: number): void

getTrimOffset()#


Gets the trim offset of a block’s media content.

Parameters#

Parameter Type Description
id number The block whose trim offset should be queried.

Returns#

number

the trim offset in seconds.

Signature#

getTrimOffset(id: number): number

setTrimLength()#


Sets the trim length of a block’s media content.

This is the duration of the media clip that should be used for playback. Note: A clip whose duration this changes keeps its transitions, as with setDuration.

Parameters#

Parameter Type Description
id number The object whose trim length should be updated.
length number The new trim length in seconds.

Returns#

void

Signature#

setTrimLength(id: number, length: number): void

getTrimLength()#


Gets the trim length of a block’s media content.

Parameters#

Parameter Type Description
id number The object whose trim length should be queried.

Returns#

number

The trim length of the object in seconds.

Signature#

getTrimLength(id: number): number

setPlaying()#


Sets whether a block should play its content during active playback.

Note that playing a page switches the editor to the Playback edit mode. From 0.2 s after the start, a change to the position, size, rotation, fill or text of a content block ends that mode. So does a change to the opacity, adjustments, shape or volume of any block, the page included. The editor returns to the Transform edit mode, which stops the playback. While a page plays, only a change on that page counts. A change to a block on another page, or to a block that is not in the scene, keeps the playback running.

Parameters#

Parameter Type Description
id number The block that should be updated.
enabled boolean Whether the block should be playing its contents.

Returns#

void

Signature#

setPlaying(id: number, enabled: boolean): void

isPlaying()#


Checks if a block is playing its content.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

whether the block is playing during playback.

Signature#

isPlaying(id: number): boolean

supportsPlaybackTime()#


Checks if a block supports a playback time property.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

whether the block supports a playback time property.

Signature#

supportsPlaybackTime(id: number): boolean

setPlaybackTime()#


Sets the current playback time of a block’s content.

Parameters#

Parameter Type Description
id number The block whose playback time should be updated.
time number The new playback time of the block in seconds.

Returns#

void

Signature#

setPlaybackTime(id: number, time: number): void

getPlaybackTime()#


Gets the current playback time of a block’s content. During an export, this returns the time of the playhead and not the time of the exported frame.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The playback time of the block in seconds.

Signature#

getPlaybackTime(id: number): number

setSoloPlaybackEnabled()#


Enables or disables solo playback for a block.

When enabled, only this block’s content will play while the rest of the scene remains paused.

engine.block.setSoloPlaybackEnabled(videoFill, true);

Parameters#

Parameter Type Description
id number The block or fill to update.
enabled boolean Whether solo playback should be enabled.

Returns#

void

Signature#

setSoloPlaybackEnabled(id: number, enabled: boolean): void

isSoloPlaybackEnabled()#


Checks if solo playback is enabled for a block.

engine.block.isSoloPlaybackEnabled(videoFill);

Parameters#

Parameter Type Description
id number The block or fill to query.

Returns#

boolean

Whether solo playback is enabled for this block.

Signature#

isSoloPlaybackEnabled(id: number): boolean

supportsPlaybackControl()#


Checks if a block supports playback controls.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block supports playback control.

Signature#

supportsPlaybackControl(id: number): boolean

setLooping()#


Sets whether a block’s media content should loop.

Parameters#

Parameter Type Description
id number The block or video fill to update.
looping boolean Whether the block should loop to the beginning or stop.

Returns#

void

Signature#

setLooping(id: number, looping: boolean): void

isLooping()#


Checks if a block’s media content is set to loop.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block is looping.

Signature#

isLooping(id: number): boolean

setMuted()#


Sets whether the audio of a block is muted.

Parameters#

Parameter Type Description
id number The block or video fill to update.
muted boolean Whether the audio should be muted.

Returns#

void

Signature#

setMuted(id: number, muted: boolean): void

isForceMuted()#


Checks if a block’s audio is muted due to engine rules.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block is force muted.

Signature#

isForceMuted(id: number): boolean

isMuted()#


Checks if a block’s audio is muted.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block is muted.

Signature#

isMuted(id: number): boolean

setVolume()#


Sets the audio volume of a block.

Parameters#

Parameter Type Description
id number The block or video fill to update.
volume number The desired volume, ranging from 0.0 to 1.0.

Returns#

void

Signature#

setVolume(id: number, volume: number): void

getVolume()#


Gets the audio volume of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The volume, ranging from 0.0 to 1.0.

Signature#

getVolume(id: number): number

setAudioFadeIn()#


Sets an audio fade-in for a block. The audio ramps up from silence to the block’s volume over the given duration at the start of the block.

Parameters#

Parameter Type Description
id number The audio block or video fill to update.
duration number The fade-in duration in seconds. A value of 0 disables the fade-in and negative values are clamped to 0. Positive infinity is an error.
easing? "Linear"

Returns#

void

Signature#

setAudioFadeIn(id: number, duration: number, easing?: "Linear" | "EaseIn" | "EaseOut" | "EaseInOut" | "EaseInQuart" | "EaseOutQuart" | "EaseInOutQuart" | "EaseInQuint" | "EaseOutQuint" | "EaseInOutQuint" | "EaseInBack" | "EaseOutBack" | "EaseInOutBack" | "EaseInSpring" | "EaseOutSpring" | "EaseInOutSpring"): void

setAudioFadeOut()#


Sets an audio fade-out for a block. The audio ramps down from the block’s volume to silence over the given duration at the end of the block.

Parameters#

Parameter Type Description
id number The audio block or video fill to update.
duration number The fade-out duration in seconds. A value of 0 disables the fade-out and negative values are clamped to 0. Positive infinity is an error.
easing? "Linear"

Returns#

void

Signature#

setAudioFadeOut(id: number, duration: number, easing?: "Linear" | "EaseIn" | "EaseOut" | "EaseInOut" | "EaseInQuart" | "EaseOutQuart" | "EaseInOutQuart" | "EaseInQuint" | "EaseOutQuint" | "EaseInOutQuint" | "EaseInBack" | "EaseOutBack" | "EaseInOutBack" | "EaseInSpring" | "EaseOutSpring" | "EaseInOutSpring"): void

setPlaybackSpeed()#


Sets the playback speed multiplier of a block that supports playback control. Note: This also adjusts the trim and duration of the block. Video fills running faster than 3.0x are force muted until reduced to 3.0x or below. An audio block that createAudioFromVideo extracts from a video faster than 3.0x keeps that speed and is force muted too. This method still rejects a speed above 3.0x for it. On a group, the speed changes no duration and acts only when group/composition is true: the children then run that many times faster. A clip whose duration this changes keeps its transitions, as with setDuration.

Parameters#

Parameter Type Description
id number The block, video fill or group to update.
speed number The desired playback speed multiplier. Valid range is [0.25, 3.0] for audio blocks and [0.25, infinity) for video fills and groups.

Returns#

void

Signature#

setPlaybackSpeed(id: number, speed: number): void

getPlaybackSpeed()#


Gets the playback speed multiplier of a block that supports playback control.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The playback speed multiplier.

Signature#

getPlaybackSpeed(id: number): number

forceLoadAVResource()#


Forces the loading of a block’s audio/video resource.

If the resource failed to load previously, it will be reloaded. A buffer:// source loads like a file. The call finishes once the engine can read the video, audio or Lottie in the buffer, with the images that a Lottie references. It fails when the buffer holds no file that it can read. A missing or empty buffer, or raw audio samples on an audio block, finish at once.

Parameters#

Parameter Type Description
id number The video fill or audio block whose resource should be loaded.
options? AbortOptions An abortSignal that ends the wait. It stops the download, unless a block or another call needs the file. The engine reads every video fill at each update, so the download of a video fill goes on.

Returns#

Promise<void>

A Promise that resolves once the resource has finished loading.

Signature#

forceLoadAVResource(id: number, options?: AbortOptions): Promise<void>

unstable_isAVResourceLoaded()#

Checks if a block’s audio/video resource is loaded. A buffer:// source counts as loaded once the engine has read its file, with the images that a Lottie references. A missing or empty buffer, or raw audio samples on an audio block, count as loaded.

Parameters#

Parameter Type Description
id number The video fill or audio block.

Returns#

boolean

The loading state of the resource. This API is experimental and may change or be removed in future versions.


getAVResourceTotalDuration()#


Gets the total duration of a block’s audio/video resource.

Parameters#

Parameter Type Description
id number The video fill or audio block.

Returns#

number

The video or audio file duration in seconds.

Signature#

getAVResourceTotalDuration(id: number): number

getVideoWidth()#


Gets the width of a block’s video resource.

Parameters#

Parameter Type Description
id number The video fill block.

Returns#

number

The video width in pixels, or 0 for a file without a video track.

Signature#

getVideoWidth(id: number): number

getVideoHeight()#


Gets the height of a block’s video resource.

Parameters#

Parameter Type Description
id number The video fill block.

Returns#

number

The video height in pixels, or 0 for a file without a video track.

Signature#

getVideoHeight(id: number): number

generateVideoThumbnailSequence()#


Generate a sequence of thumbnails for the given video fill or design block.

Note: Only one request per block runs at a time. A second request for the same block waits for the first to finish instead of failing. Note: For a video fill, cancelling has no effect once the first frame has been scheduled — the remaining frames are still delivered. Cancel before the first frame arrives, or ignore results from a request you have abandoned. Design block sequences cancel at any time. Note: A frame arrives at the end of an engine update. An engine call inside onFrame sees the scene without the state that the thumbnail renders with. For an argument that this call rejects, onFrame runs before the call returns.

Parameters#

Parameter Type Description
id number The video fill or design block.
thumbnailHeight number The height of each thumbnail.
timeBegin number The start time in seconds for the thumbnail sequence.
timeEnd number The end time in seconds for the thumbnail sequence.
numberOfFrames number The number of frames to generate.
onFrame (frameIndex, result) => void A callback that receives the frame index and image data. In Node.js the image data is a plain object with the fields of ImageData.

Returns#

A function to cancel the thumbnail generation request.

() => void

Signature#

generateVideoThumbnailSequence(id: number, thumbnailHeight: number, timeBegin: number, timeEnd: number, numberOfFrames: number, onFrame: (frameIndex: number, result: Error | ImageData) => void): () => void

generateAudioThumbnailSequence()#


Generate a thumbnail sequence for the given audio block or video fill.

A thumbnail in this case is a chunk of samples in the range of 0 to 1. In case stereo data is requested, the samples are interleaved, starting with the left channel. Note: numberOfSamples counts samples per channel. The callback fires ceil(numberOfSamples / samplesPerChunk) times and the last chunk may be shorter. Note: The Float32Array is a view into engine memory that is only valid for the duration of the callback. Copy it before storing it. Note: A chunk arrives at the end of an engine update, and no chunk arrives after a cancel. For an argument that this call rejects, onChunk runs before the call returns.

Parameters#

Parameter Type Description
id number The audio block or video fill.
samplesPerChunk number The number of samples per chunk.
timeBegin number The start time in seconds for the thumbnail sequence.
timeEnd number The end time in seconds for the thumbnail sequence.
numberOfSamples number The total number of samples to generate.
numberOfChannels number The number of channels in the output (1 for mono, 2 for stereo).
onChunk (chunkIndex, result) => void A callback that receives the chunk index and sample data.

Returns#

A function to cancel the thumbnail generation request.

() => void

Signature#

generateAudioThumbnailSequence(id: number, samplesPerChunk: number, timeBegin: number, timeEnd: number, numberOfSamples: number, numberOfChannels: number, onChunk: (chunkIndex: number, result: Error | Float32Array<ArrayBufferLike>) => void): () => void

setNativePixelBuffer()#


Updates a pixel stream fill block with a new pixel buffer.

Parameters#

Parameter Type Description
id number The pixel stream fill block.
buffer HTMLCanvasElement HTMLVideoElement

Returns#

void

Signature#

setNativePixelBuffer(id: number, buffer: HTMLCanvasElement | HTMLVideoElement): void

Block Animations#

Create and manage animations and timeline-based effects.

setKeyframes()#


Replaces the keyframes of a block property.

Keyframe times are normalized over the block’s duration, from 0 to 1, and the keyframes are sorted by time. A fill, shape or effect uses the duration of the block it is attached to. Setting the static value of the property does not change its keyframes.

The keyframes belong to the block that owns the property. Replacing a fill, shape or effect does not move them to the new block. Scaling the block or changing the design unit also converts the keyframes of length and position properties, such as corner radii and position. Rotating or flipping the block turns or mirrors the keyframes of its position, rotation and skew with it. A group’s keyframes turn with the group. A turn other than a half turn joins position/x and position/y tracks into one position track. They must share the mode, the times and the easings, and no position track may exist. Other axis tracks cannot turn: their Absolute values move with the block, and their Relative values stay.

A rotation track turns a graphic or text without an anchor around its frame center, as setRotation does. With transform/anchor/x or transform/anchor/y set, even to 0, it turns around the anchor.

The vec2 properties position (a block) and shape/position (a shape) animate the /x and /y properties together. Their spatialOut and spatialIn tangents curve the motion path. getVec2 and setVec2 read and write their static value. A position/x or position/y track overrides that axis of a position track. Position keyframes are in design units, also when the position mode is 'Percent'.

const fill = engine.block.getFill(block);
engine.block.setKeyframes(fill, 'fill/color/value', [
{ time: 0, value: { type: 'Color', value: { r: 1, g: 0, b: 0, a: 1 } } },
{ time: 1, value: { type: 'Color', value: { r: 0, g: 0, b: 1, a: 1 } }, easing: { type: 'Hold' } }
]);

Required scope: ‘appearance/animation’ and the scope that the setter of the property needs, such as ‘layer/move’ for position or ‘layer/rotate’ for rotation. A transform/scale/x or transform/scale/y keyframe that shows a scale with another sign than the static scale also needs ‘layer/flip’.

Parameters#

Parameter Type Description
id number The block that owns the property, for example a graphic, fill, shape or effect block.
property string The property path. isPropertyAnimatable must return true for it.
keyframes Keyframe[] At least one keyframe, with unique times from 0 to 1 and values of the property’s kind.
mode? TrackMode 'Absolute' replaces the static value, 'Relative' adds to it. Relative needs a float or vec2 property. Defaults to 'Absolute'.

Returns#

void

Signature#

setKeyframes(id: number, property: string, keyframes: Keyframe_2[], mode?: TrackMode): void

getKeyframes()#


Gets the keyframes of a block property, sorted by time.

Parameters#

Parameter Type Description
id number The block that owns the property.
property string The animatable property path.

Returns#

Keyframe[]

The keyframes, or an empty array for an animatable property without keyframes.

Throws#

BLOCK.KEYFRAMES_PROPERTY_NOT_ANIMATABLE when the property has no keyframes and isPropertyAnimatable returns false.

Signature#

getKeyframes(id: number, property: string): Keyframe_2[]

getKeyframeMode()#


Gets the mode of the keyframes of a block property.

Parameters#

Parameter Type Description
id number The block that owns the property.
property string The animatable property path.

Returns#

TrackMode

The mode.

Throws#

BLOCK.KEYFRAMES_NO_TRACK when the property has no keyframes, or BLOCK.KEYFRAMES_PROPERTY_NOT_ANIMATABLE when isPropertyAnimatable also returns false.

Signature#

getKeyframeMode(id: number, property: string): TrackMode

getAnimatedValue()#


Gets the value that the keyframes give a block property at a time.

A Relative track adds the static value. A property without keyframes gives its static value. A position/x or position/y track overrides that axis of a position track. Without its own track, position/x gives the x of the position track. An angle is in the angle unit of the scene. Animation presets and the turn along a motion path are not included. A rotation track also moves a block without an anchor, so that it turns around its frame centre. That move is not included either.

Parameters#

Parameter Type Description
id number The block that owns the property.
property string The animatable property path, e.g. opacity.
time number The normalized time over the block’s playback/duration, from 0 to 1, as keyframe times are.

Returns#

KeyframeValue

The value, of the property’s kind.

Throws#

BLOCK.KEYFRAMES_TIME_OUT_OF_RANGE for a time outside [0, 1], or BLOCK.KEYFRAMES_PROPERTY_NOT_ANIMATABLE when the property has no keyframes and isPropertyAnimatable returns false.

Signature#

getAnimatedValue(id: number, property: string, time: number): KeyframeValue

removeKeyframes()#


Removes the keyframes of a block property, so its static value applies again.

Removing from an animatable property without keyframes does nothing. Throws BLOCK.KEYFRAMES_PROPERTY_NOT_ANIMATABLE when the property has no keyframes and isPropertyAnimatable returns false.

Required scope: the scopes that setKeyframes needs for the removed track.

Parameters#

Parameter Type Description
id number The block that owns the property.
property string The animatable property path.

Returns#

void

Signature#

removeKeyframes(id: number, property: string): void

getAnimatedProperties()#


Lists the properties of a block that have keyframes.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

string[]

The property paths, sorted.

Signature#

getAnimatedProperties(id: number): string[]

isPropertyAnimatable()#


Checks whether a property of a block can have keyframes.

Parameters#

Parameter Type Description
id number The block to query.
property string The property path.

Returns#

boolean

True when the block has the property and it is animatable. False for a property the block does not have.

Signature#

isPropertyAnimatable(id: number, property: string): boolean

createAnimation()#


Creates a new animation block.

Parameters#

Parameter Type Description
type AnimationType The type of animation to create.

Returns#

number

The handle of the new animation instance.

Signature#

createAnimation(type: AnimationType): number

supportsAnimation()#


Checks if a block supports animation.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block supports animation.

Signature#

supportsAnimation(id: number): boolean

setInAnimation()#


Sets the “in” animation of a block.

The animation is removed from every other block that uses it.

Parameters#

Parameter Type Description
id number The block whose “in” animation should be set.
animation number The animation to set.

Returns#

void

Signature#

setInAnimation(id: number, animation: number): void

setLoopAnimation()#


Sets the “loop” animation of a block.

The animation is removed from every other block that uses it.

Parameters#

Parameter Type Description
id number The block whose “loop” animation should be set.
animation number The animation to set.

Returns#

void

Signature#

setLoopAnimation(id: number, animation: number): void

setOutAnimation()#


Sets the “out” animation of a block.

The animation is removed from every other block that uses it.

Parameters#

Parameter Type Description
id number The block whose “out” animation should be set.
animation number The animation to set.

Returns#

void

Signature#

setOutAnimation(id: number, animation: number): void

getInAnimation()#


Gets the “in” animation of a block.

Parameters#

Parameter Type Description
id number The block whose “in” animation should be queried.

Returns#

number

The “in” animation of the block, or an invalid block if unset. Check the result with isValid.

Signature#

getInAnimation(id: number): number

getLoopAnimation()#


Gets the “loop” animation of a block.

Parameters#

Parameter Type Description
id number The block whose “loop” animation should be queried.

Returns#

number

The “loop” animation of the block, or an invalid block if unset. Check the result with isValid.

Signature#

getLoopAnimation(id: number): number

getOutAnimation()#


Gets the “out” animation of a block.

Parameters#

Parameter Type Description
id number The block whose “out” animation should be queried.

Returns#

number

The “out” animation of the block, or an invalid block if unset. Check the result with isValid.

Signature#

getOutAnimation(id: number): number

Block Groups#

Create and manage groups of blocks.

isGroupable()#


Checks if a set of blocks can be grouped.

A scene block, a page or a page slice cannot be grouped, and neither can a block together with a group it sits inside, which would make that group a child of itself. A caption or a caption track cannot be grouped either, because a caption plays from the caption track of its page. Blocks that already belong to a group can be grouped again, which is how a group inside a group is made.

const groupable = engine.block.isGroupable([block1, block2])

Parameters#

Parameter Type Description
ids number[] An array of block ids.

Returns#

boolean

Whether the blocks can be grouped together.

Signature#

isGroupable(ids: number[]): boolean

group()#


Groups multiple blocks into a new group block.

The blocks keep their times on the timeline. The group spans from the earliest start to the latest end of the blocks, and their time offsets become relative to the group. Grouping does not change the children’s positions: they stay relative to the group’s parent, not to the group. In nested groups, they stay relative to the first ancestor that is not a group. The engine computes the group’s position and size from the children’s combined bounds. Moving the group moves all of its children by the same offset.

if (engine.block.isGroupable([block1, block2])) {
const group = engine.block.group([block1, block2]);
}

Parameters#

Parameter Type Description
ids number[] A non-empty array of block ids.

Returns#

number

The block id of the created group.

Signature#

group(ids: number[]): number

ungroup()#


Ungroups a group block, releasing its children.

The children keep their times on the timeline, so their time offsets become relative to their new parent. A caption goes onto the first caption track of the page instead, at its time, and takes the track’s animations. Ungrouping creates the caption track when the page has none.

engine.block.ungroup(group);

Parameters#

Parameter Type Description
id number The group id from a previous call to group.

Returns#

void

Signature#

ungroup(id: number): void

enterGroup()#


Changes selection to a block within a selected group.

Nothing happens if the target is not a group.

engine.block.enterGroup(group);

Parameters#

Parameter Type Description
id number The group id from a previous call to group.

Returns#

void

Signature#

enterGroup(id: number): void

exitGroup()#


Changes selection from a block to its parent group.

Nothing happens if the block is not part of a group.

engine.block.exitGroup(member1);

Parameters#

Parameter Type Description
id number A block id.

Returns#

void

Signature#

exitGroup(id: number): void

Block State#

Query the intrinsic state or identity of a block, such as its name, UUID, or lock status.

getType()#


Gets the longhand type of a given block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

ObjectTypeLonghand

The block’s type.

Signature#

getType(id: number): ObjectTypeLonghand

setName()#


Sets the name of a block.

Parameters#

Parameter Type Description
id number The block to update.
name string The name to set.

Returns#

void

Signature#

setName(id: number, name: string): void

getName()#


Gets the name of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

string

The block’s name.

Signature#

getName(id: number): string

getUUID()#


Gets the unique universal identifier (UUID) of a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

string

The block’s UUID.

Signature#

getUUID(id: number): string

isValid()#


Checks if a block handle is valid.

A block becomes invalid once it has been destroyed.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block is valid.

Signature#

isValid(id: number): boolean

referencesAnyVariables()#


Checks if a block references any text variables.

This check does not recurse into children and ignores variable bindings.

Parameters#

Parameter Type Description
id number The block to inspect.

Returns#

boolean

true if the block references variables and false otherwise.

Signature#

referencesAnyVariables(id: number): boolean

isIncludedInExport()#


Checks if a block is included in exports.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block is included on the exported result, false otherwise.

Signature#

isIncludedInExport(id: number): boolean

setIncludedInExport()#


Sets whether a block should be included in exports.

Parameters#

Parameter Type Description
id number The block whose exportable state should be set.
enabled boolean If true, the block will be included on the exported result.

Returns#

void

Signature#

setIncludedInExport(id: number, enabled: boolean): void

isVisibleAtCurrentPlaybackTime()#


Checks if a block is visible at the current scene playback time.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

Whether the block should be visible on the canvas at the current playback time.

Signature#

isVisibleAtCurrentPlaybackTime(id: number): boolean

getState()#


Gets the current state of a block.

A block’s state is determined by its own state and that of its shape, fill, and effects. A block whose CMYK or spot color needs the document CMYK profile is pending while that profile loads. With soft proofing on, a block that draws inside a page is pending while the proof profile loads. It reports a SoftProof error only when it has no other error or pending state. Runs an engine update for a resource that nothing asked for yet, while the scene has a change to lay out. A font set just before this call is then reported as pending. An ‘Error’ state carries the catalog error of the failed load in engineError when the engine knows it, such as a .lottie archive that cannot be read or a video that cannot be decoded. It has the same fields as a thrown engine error.

const state = engine.block.getState(block);
if (state.type === 'Error' && state.engineError) {
console.log(state.engineError.code, state.engineError.message);
}

Parameters#

Parameter Type Description
id number The block to query.

Returns#

BlockState

The block’s state: ‘Ready’, ‘Pending’, or ‘Error’.

Signature#

getState(id: number): BlockState

setState()#


Sets the state of a block.

engine.block.setState(video, {type: 'Pending', progress: 0.5});
engine.block.setState(page, {type: 'Ready'});
engine.block.setState(image, {type: 'Error', error: 'ImageDecoding'});

While an image fill is pending, the engine adds no automatic source set entries to it.

Parameters#

Parameter Type Description
id number The block whose state should be set.
state BlockState The new state to set.

Returns#

void

Signature#

setState(id: number, state: BlockState): void

Block Crop#

Crop, scale, translate, and transform block content.

supportsCrop()#


Checks if a block supports cropping.

engine.block.supportsCrop(image);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

true, if the block supports cropping.

Signature#

supportsCrop(id: number): boolean

setCropScaleX()#


Sets the horizontal crop scale of a block.

engine.block.setCropScaleX(image, 2.0);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
scaleX number The scale in x direction.

Returns#

void

Signature#

setCropScaleX(id: number, scaleX: number): void

setCropScaleY()#


Sets the vertical crop scale of a block.

engine.block.setCropScaleY(image, 1.5);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
scaleY number The scale in y direction.

Returns#

void

Signature#

setCropScaleY(id: number, scaleY: number): void

setCropRotation()#


Sets the crop rotation of a block in the scene’s angle unit (radians by default).

engine.block.setCropRotation(image, Math.PI);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
rotation number The rotation in the scene’s angle unit (radians by default).

Returns#

void

Signature#

setCropRotation(id: number, rotation: number): void

setCropScaleRatio()#


Sets the uniform crop scale ratio of a block.

This scales the content up or down from the center of the crop frame. On a page with a bleed, the ratio and the center of the scale include the bleed. This needs the setting page/imageFillCoversBleed, which is on by default.

engine.block.setCropScaleRatio(image, 3.0);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
scaleRatio number The crop scale ratio.

Returns#

void

Signature#

setCropScaleRatio(id: number, scaleRatio: number): void

setCropTranslationX()#


Sets the horizontal crop translation of a block in percentage of the crop frame width.

engine.block.setCropTranslationX(image, -1.0);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
translationX number The translation in x direction.

Returns#

void

Signature#

setCropTranslationX(id: number, translationX: number): void

setCropTranslationY()#


Sets the vertical crop translation of a block in percentage of the crop frame height.

engine.block.setCropTranslationY(image, 1.0);

Parameters#

Parameter Type Description
id number The block whose crop should be set.
translationY number The translation in y direction.

Returns#

void

Signature#

setCropTranslationY(id: number, translationY: number): void

resetCrop()#


Resets the crop of a block to its default state.

The block’s content fill mode is set to ‘Cover’.

engine.block.resetCrop(image);

Parameters#

Parameter Type Description
id number The block whose crop should be reset.

Returns#

void

Signature#

resetCrop(id: number): void

getCropScaleX()#


Gets the horizontal crop scale of a block.

const scaleX = engine.block.getCropScaleX(image);

Parameters#

Parameter Type Description
id number The block whose scale should be queried.

Returns#

number

The scale on the x axis.

Signature#

getCropScaleX(id: number): number

getCropScaleY()#


Gets the vertical crop scale of a block.

const scaleY = engine.block.getCropScaleY(image);

Parameters#

Parameter Type Description
id number The block whose scale should be queried.

Returns#

number

The scale on the y axis.

Signature#

getCropScaleY(id: number): number

getCropRotation()#


Gets the crop rotation of a block in the scene’s angle unit (radians by default).

const cropRotation = engine.block.getCropRotation(image);

Parameters#

Parameter Type Description
id number The block whose crop rotation should be queried.

Returns#

number

The crop rotation in the scene’s angle unit (radians by default).

Signature#

getCropRotation(id: number): number

getCropScaleRatio()#


Gets the uniform crop scale ratio of a block. On a page with a bleed, a ratio of 1 means that the content covers the page and its bleed. This needs the setting page/imageFillCoversBleed, which is on by default.

const cropScaleRatio = engine.block.getCropScaleRatio(image);

Parameters#

Parameter Type Description
id number The block whose crop scale ratio should be queried.

Returns#

number

The crop scale ratio.

Signature#

getCropScaleRatio(id: number): number

getCropTranslationX()#


Gets the horizontal crop translation of a block in percentage of the crop frame width.

const cropTranslationX = engine.block.getCropTranslationX(image);

Parameters#

Parameter Type Description
id number The block whose translation should be queried.

Returns#

number

The translation on the x axis.

Signature#

getCropTranslationX(id: number): number

getCropTranslationY()#


Gets the vertical crop translation of a block in percentage of the crop frame height.

const cropTranslationY = engine.block.getCropTranslationY(image);

Parameters#

Parameter Type Description
id number The block whose translation should be queried.

Returns#

number

The translation on the y axis.

Signature#

getCropTranslationY(id: number): number

adjustCropToFillFrame()#


Adjusts the crop position and scale of the given image block to fill its crop frame, while maintaining the position and size of the crop frame. On a page with a bleed, the content also covers the bleed, and the ratio includes the bleed. This needs the setting page/imageFillCoversBleed, which is on by default.

const adjustedScaleRatio = engine.block.adjustCropToFillFrame(image, 1.0);

Parameters#

Parameter Type Description
id number The block whose crop should be adjusted.
minScaleRatio number The minimal crop scale ratio to use.

Returns#

number

The adjusted scale ratio.

Signature#

adjustCropToFillFrame(id: number, minScaleRatio: number): number

flipCropHorizontal()#


Flips the content horizontally within its crop frame.

engine.block.flipCropHorizontal(image);

Parameters#

Parameter Type Description
id number The block whose crop should be updated.

Returns#

void

Signature#

flipCropHorizontal(id: number): void

flipCropVertical()#


Flips the content vertically within its crop frame.

engine.block.flipCropVertical(image);

Parameters#

Parameter Type Description
id number The block whose crop should be updated.

Returns#

void

Signature#

flipCropVertical(id: number): void

isCropAspectRatioLocked()#


Checks if the crop aspect ratio is locked for a block.

When locked, crop handles will maintain the current aspect ratio during resize.

const isLocked = engine.block.isCropAspectRatioLocked(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if aspect ratio is locked, false otherwise.

Signature#

isCropAspectRatioLocked(id: number): boolean

setCropAspectRatioLocked()#


Sets whether the crop aspect ratio should be locked for a block.

When enabled, crop handles will maintain the current aspect ratio. When disabled, free resizing is allowed.

engine.block.setCropAspectRatioLocked(block, true);

Parameters#

Parameter Type Description
id number The block to update.
locked boolean Whether aspect ratio should be locked.

Returns#

void

Signature#

setCropAspectRatioLocked(id: number, locked: boolean): void

canRevertToOriginalRatio()#


Checks whether the “Original” crop preset (ContentAspectRatio) can be applied to a block.

This runs the same preliminary check the apply path performs: it resolves the intrinsic content dimensions from the block’s image/video fill (an image fill resolves only from its sourceSet; a video fill resolves from its sourceSet or the first decoded frame). Use it to gate UI that would otherwise call the preset and fail — e.g. an unreplaced placeholder image fill with an empty sourceSet.

const canRevert = engine.block.canRevertToOriginalRatio(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if the preset would resolve, false if it cannot (no/placeholder fill, empty sourceSet, video not yet decoded, or unsupported fill type).

Signature#

canRevertToOriginalRatio(id: number): boolean

Block Events#

Subscribe to user actions and state changes related to blocks.

onSelectionChanged#


Subscribes to changes in the selection.

Parameters#

Parameter Type Description
callback () => void This function is called at the end of the engine update if the selection has changed.

Returns#

A method to unsubscribe.

() => void


onClicked#


Subscribes to block click events.

Parameters#

Parameter Type Description
callback (id) => void This function is called at the end of the engine update if a block has been clicked.

Returns#

A method to unsubscribe.

() => void


onStateChanged#


Subscribes to state changes for a set of blocks.

The state is determined by the block and its associated shape, fill, and effects.

const unsubscribe = engine.block.onStateChanged([], (blocks) => {
blocks.forEach(block => console.log(block));
});

Parameters#

Parameter Type Description
ids number[] A list of block IDs to monitor. If empty, all blocks are monitored.
callback (ids) => void The function to call when a state changes.

Returns#

A function to unsubscribe from the event.

() => void

Block Utils#

Check block capabilities like alignability or distributability.

isAlignable()#


Checks if a set of blocks can be aligned.

A page slice cannot be aligned, so the result is false when ids holds one.

Parameters#

Parameter Type Description
ids number[] An array of block ids.

Returns#

boolean

Whether the blocks can be aligned.

Signature#

isAlignable(ids: number[]): boolean

isDistributable()#


Checks if a set of blocks can be distributed.

A page slice cannot be distributed, so the result is false when ids holds one.

Parameters#

Parameter Type Description
ids number[] An array of block ids.

Returns#

boolean

Whether the blocks can be distributed.

Signature#

isDistributable(ids: number[]): boolean

Block Kind#

Get and set a block’s ‘kind’ identifier for custom categorization.

getKind()#


Gets the kind of a given block.

const kind = engine.block.getKind(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

string

The block’s kind.

Signature#

getKind(id: number): string

setKind()#


Sets the kind of a given block, a custom string for categorization of blocks.

engine.block.setKind(text, 'title');

Parameters#

Parameter Type Description
id number The block whose kind should be changed.
kind string The new kind.

Returns#

void

Signature#

setKind(id: number, kind: string): void

Block Properties#

Get and set any block property by name using low-level, generic accessors.

setVariableBinding()#


Binds a block property to a color, number, image or typeface variable.

The property takes the variable’s current value at once, and follows every later change of the variable. Color variables bind to color properties and number variables to float properties. Image variables bind only to fill/image/imageFileURI, fill/image/previewFileURI and fill/video/fileURI. Typeface variables bind only to text/typeface and caption/typeface. A direct write to a bound property fails with BLOCK.PROPERTY_BOUND until the binding is removed. A bound typeface also locks setTypeface and setFont. On a text block, a variable bound to fill/solid/color or the font size sets every run of the text, and setTextColor or setTextFontSize fails for any range. Keyframes, undo and scene loads still change it. Changing the design unit converts a bound length. A number variable whose bound properties all hold its value converts with them. Otherwise the variable keeps its value, and the next variable write sets the lengths in the new unit.

engine.variable.setColor('brand', { r: 1, g: 0, b: 0, a: 1 });
engine.block.setVariableBinding(colorFill, 'fill/color/value', 'brand');

Parameters#

Parameter Type Description
id number The block that has the property.
property string The property path.
key string The key of an existing color, number, image or typeface variable.

Returns#

void

Signature#

setVariableBinding(id: number, property: string, key: string): void

getVariableBinding()#


Gets the variable that a block property is bound to.

Parameters#

Parameter Type Description
id number The block that has the property.
property string The property path.

Returns#

string

The variable key, or null if the property is not bound.

Signature#

getVariableBinding(id: number, property: string): string

removeVariableBinding()#


Removes the variable binding of a block property. The property keeps its current value.

Parameters#

Parameter Type Description
id number The block that has the property.
property string The property path.

Returns#

void

Signature#

removeVariableBinding(id: number, property: string): void

findAllVariableBindings()#


Gets the properties of a block that are bound to a variable.

Parameters#

Parameter Type Description
id number The block to inspect.

Returns#

string[]

The bound property paths.

Signature#

findAllVariableBindings(id: number): string[]

findAllProperties()#


Gets all available properties of a block.

Parameters#

Parameter Type Description
id number The block whose properties should be queried.

Returns#

string[]

A list of the property names.

Signature#

findAllProperties(id: number): string[]

isPropertyReadable()#


Checks if a property is readable.

Parameters#

Parameter Type Description
property string The name of the property to check.

Returns#

boolean

Whether the property is readable. Returns false for unknown properties.

Signature#

isPropertyReadable(property: string): boolean

isPropertyWritable()#


Checks if a property is writable.

Parameters#

Parameter Type Description
property string The name of the property to check.

Returns#

boolean

Whether the property is writable. Returns false for unknown properties.

Signature#

isPropertyWritable(property: string): boolean

getPropertyType()#


Gets the type of a property by its name.

Parameters#

Parameter Type Description
property string The name of the property whose type should be queried.

Returns#

PropertyType

The property type.

Signature#

getPropertyType(property: string): PropertyType

getEnumValues()#


Gets all possible values of an enum property.

Type Parameters#

Type Parameter Default type
T string

Parameters#

Parameter Type Description
enumProperty string The name of the property whose enum values should be queried.

Returns#

T[]

A list of the enum value names as a string array.

Signature#

getEnumValues(enumProperty: string): T[]

setBool()#


Sets a boolean property on a block.

engine.block.setBool(scene, 'scene/aspectRatioLock', false);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property BoolPropertyName The name of the property to set.
value boolean The value to set.

Returns#

void

Signature#

setBool(id: number, property: BoolPropertyName, value: boolean): void

getBool()#


Gets a boolean property from a block.

engine.block.getBool(scene, 'scene/aspectRatioLock');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property BoolPropertyName The name of the property to query.

Returns#

boolean

The value of the property.

Signature#

getBool(id: number, property: BoolPropertyName): boolean

setInt()#


Sets an integer property on a block.

engine.block.setInt(starShape, 'shape/star/points', points + 2);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property IntPropertyName The name of the property to set.
value number The value to set.

Returns#

void

Signature#

setInt(id: number, property: IntPropertyName, value: number): void

getInt()#


Gets an integer property from a block.

engine.block.setInt(starShape, 'shape/star/points', points + 2);

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property IntPropertyName The name of the property to query.

Returns#

number

The value of the property.

Signature#

getInt(id: number, property: IntPropertyName): number

setFloat()#


Sets a float property on a block.

engine.block.setFloat(text, "text/letterSpacing", 0.2);
engine.block.setFloat(text, "text/lineHeight", 1.2);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property FloatPropertyName The name of the property to set.
value number The value to set.

Returns#

void

Signature#

setFloat(id: number, property: FloatPropertyName, value: number): void

getFloat()#


Gets a float property from a block.

engine.block.getFloat(starShape, 'shape/star/innerDiameter');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property FloatPropertyName The name of the property to query.

Returns#

number

The value of the property.

Signature#

getFloat(id: number, property: FloatPropertyName): number

setDouble()#


Sets a double-precision float property on a block.

engine.block.setDouble(audio, 'playback/duration', 1.0);

Parameters#

Parameter Type Description
id number The block whose property should be set.
property DoublePropertyName The name of the property to set.
value number The value to set.

Returns#

void

Signature#

setDouble(id: number, property: DoublePropertyName, value: number): void

getDouble()#


Gets a double-precision float property from a block.

engine.block.getDouble(audio, 'playback/duration');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property DoublePropertyName The name of the property to query.

Returns#

number

The value of the property.

Signature#

getDouble(id: number, property: DoublePropertyName): number

setVec2()#


Sets a vec2 property on a block. position sets position/x and position/y, and shape/position sets shape/position/x and shape/position/y, with the checks of those properties. Either both components change or neither does.

engine.block.setVec2(block, 'position', { x: 100, y: 50 });

Parameters#

Parameter Type Description
id number The block whose property should be set.
property Vec2PropertyName The name of the property to set.
value Vec2 The value to set.

Returns#

void

Signature#

setVec2(id: number, property: Vec2PropertyName, value: Vec2): void

getVec2()#


Gets a vec2 property from a block.

const { x, y } = engine.block.getVec2(block, 'position');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property Vec2PropertyName The name of the property to query.

Returns#

Vec2

The value of the property.

Signature#

getVec2(id: number, property: Vec2PropertyName): Vec2

setString()#


Sets a string property on a block.

engine.block.setString(text, 'text/text', 'Hello World');
engine.block.setString(imageFill, 'fill/image/imageFileURI', 'https://example.com/sample.jpg');

Parameters#

Parameter Type Description
id number The block whose property should be set.
property StringPropertyName The name of the property to set.
value string The value to set.

Returns#

void

Signature#

setString(id: number, property: StringPropertyName, value: string): void

getString()#


Gets a string property from a block.

engine.block.getString(text, 'text/text');
engine.block.getString(imageFill, 'fill/image/imageFileURI');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property StringPropertyName The name of the property to query.

Returns#

string

The value of the property.

Signature#

getString(id: number, property: StringPropertyName): string

setColor()#


Sets a color property on a block.

// Set the block's fill color to white.
engine.block.setColor(colorFill, 'fill/color/value', { r: 1, g: 1, b: 1, a: 1 });

Parameters#

Parameter Type Description
id number The block whose property should be set.
property ColorPropertyName The name of the property to set.
value Color The value to set.

Returns#

void

Signature#

setColor(id: number, property: ColorPropertyName, value: Color): void

getColor()#


Gets a color property from a block.

engine.block.getColor(colorFill, 'fill/color/value');

Parameters#

Parameter Type Description
id number The block whose property should be queried.
property ColorPropertyName The name of the property to query.

Returns#

Color

The value of the property.

Signature#

getColor(id: number, property: ColorPropertyName): Color

setEnum()#


Sets an enum property on a block. Setting scene/mode to Video fails with BLOCK.PAGE_SLICE_IN_VIDEO_SCENE when the scene holds a page slice.

engine.block.setEnum(text, 'text/horizontalAlignment', 'Center');
engine.block.setEnum(text, 'text/verticalAlignment', 'Center');
Type Parameters#
Type Parameter
T extends keyof BlockEnumType
Parameters#
Parameter Type Description
id number The block whose property should be set.
property T The name of the property to set.
value BlockEnumType[T] The enum value as a string.
Returns#

void

Call Signature#

setEnum(
id,
property,
value): void;

Sets an enum property on a block. Setting scene/mode to Video fails with BLOCK.PAGE_SLICE_IN_VIDEO_SCENE when the scene holds a page slice.

engine.block.setEnum(text, 'text/horizontalAlignment', 'Center');
engine.block.setEnum(text, 'text/verticalAlignment', 'Center');
Parameters#
Parameter Type Description
id number The block whose property should be set.
property string The name of the property to set.
value string The enum value as a string.
Returns#

void

Signatures#

setEnum(id: number, property: T, value: BlockEnumType[T]): void
setEnum(id: number, property: string, value: string): void

getEnum()#


Gets an enum property from a block.

engine.block.getEnum(text, 'text/horizontalAlignment');
engine.block.getEnum(text, 'text/verticalAlignment');
Type Parameters#
Type Parameter
T extends keyof BlockEnumType
Parameters#
Parameter Type Description
id number The block whose property should be queried.
property T The name of the property to query.
Returns#

BlockEnumType[T]

The value as a string.

Call Signature#

getEnum(id, property): string;

Gets an enum property from a block.

engine.block.getEnum(text, 'text/horizontalAlignment');
engine.block.getEnum(text, 'text/verticalAlignment');
Parameters#
Parameter Type Description
id number The block whose property should be queried.
property string The name of the property to query.
Returns#

string

The value as a string.

Signatures#

getEnum(id: number, property: T): BlockEnumType[T]
getEnum(id: number, property: string): string

Block Strokes#

Control stroke appearance, including color, width, style, and position.

supportsStroke()#


Checks if a block supports a stroke.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if the block supports a stroke.

Signature#

supportsStroke(id: number): boolean

setStrokeEnabled()#


Enables or disables the stroke of a block.

engine.block.setStrokeEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose stroke should be enabled or disabled.
enabled boolean If true, the stroke will be enabled.

Returns#

void

Signature#

setStrokeEnabled(id: number, enabled: boolean): void

isStrokeEnabled()#


Checks if the stroke of a block is enabled.

const strokeIsEnabled = engine.block.isStrokeEnabled(block);

Parameters#

Parameter Type Description
id number The block whose stroke state should be queried.

Returns#

boolean

True if the block’s stroke is enabled.

Signature#

isStrokeEnabled(id: number): boolean

setStrokeOverprint()#


Marks the stroke of a block as overprint for PDF export.

The flag is only honored by the PDF writer when the stroke uses a spot color (Separation/DeviceN). For process-color strokes it is a silent no-op. On-screen rendering ignores the flag.

engine.block.setStrokeOverprint(block, true);

Parameters#

Parameter Type Description
id number The block whose stroke overprint flag should be set.
overprint boolean If true, the stroke is marked as overprint in exported PDFs.

Returns#

void

Signature#

setStrokeOverprint(id: number, overprint: boolean): void

getStrokeOverprint()#


Queries whether the stroke of a block is marked as overprint for PDF export.

const overprint = engine.block.getStrokeOverprint(block);

Parameters#

Parameter Type Description
id number The block whose stroke overprint flag should be queried.

Returns#

boolean

The stroke overprint flag.

Signature#

getStrokeOverprint(id: number): boolean

setStrokeColor()#


Sets the stroke color of a block.

Parameters#

Parameter Type Description
id number The block whose stroke color should be set.
color Color The color to set.

Returns#

void

Signature#

setStrokeColor(id: number, color: Color): void

getStrokeColor()#


Gets the stroke color of a block.

Parameters#

Parameter Type Description
id number The block whose stroke color should be queried.

Returns#

Color

The stroke color.

Signature#

getStrokeColor(id: number): Color

setStrokeWidth()#


Sets the stroke width of a block.

When the dash pattern is a preset’s pattern at the old width, it is scaled to the new width. Any other dash pattern keeps its lengths.

Parameters#

Parameter Type Description
id number The block whose stroke width should be set.
width number The stroke width to be set.

Returns#

void

Signature#

setStrokeWidth(id: number, width: number): void

getStrokeWidth()#


Gets the stroke width of a block.

Parameters#

Parameter Type Description
id number The block whose stroke width should be queried.

Returns#

number

The stroke’s width.

Signature#

getStrokeWidth(id: number): number

setStrokeStyle()#


Sets the stroke style of a block.

Parameters#

Parameter Type Description
id number The block whose stroke style should be set.
style "Dashed"

Returns#

void

Signature#

setStrokeStyle(id: number, style: "Dashed" | "DashedRound" | "Dotted" | "LongDashed" | "LongDashedRound" | "Solid"): void

getStrokeStyle()#


Gets the stroke style of a block.

Parameters#

Parameter Type Description
id number The block whose stroke style should be queried.

Returns#

| "Dashed" | "DashedRound" | "Dotted" | "LongDashed" | "LongDashedRound" | "Solid"

The stroke’s style.

Signature#

getStrokeStyle(id: number): "Dashed" | "DashedRound" | "Dotted" | "LongDashed" | "LongDashedRound" | "Solid"

setStrokePosition()#


Sets the stroke position of a block.

Parameters#

Parameter Type Description
id number The block whose stroke position should be set.
position "Center" "Inner"

Returns#

void

Signature#

setStrokePosition(id: number, position: "Center" | "Inner" | "Outer"): void

getStrokePosition()#


Gets the stroke position of a block.

Parameters#

Parameter Type Description
id number The block whose stroke position should be queried.

Returns#

"Center" | "Inner" | "Outer"

The stroke position.

Signature#

getStrokePosition(id: number): "Center" | "Inner" | "Outer"

setStrokeCornerGeometry()#


Sets the stroke corner geometry of a block.

Parameters#

Parameter Type Description
id number The block whose stroke corner geometry should be set.
cornerGeometry "Bevel" "Miter"

Returns#

void

Signature#

setStrokeCornerGeometry(id: number, cornerGeometry: "Bevel" | "Miter" | "Round"): void

getStrokeCornerGeometry()#


Gets the stroke corner geometry of a block.

Parameters#

Parameter Type Description
id number The block whose stroke corner geometry should be queried.

Returns#

"Bevel" | "Miter" | "Round"

The stroke corner geometry.

Signature#

getStrokeCornerGeometry(id: number): "Bevel" | "Miter" | "Round"

setStrokeStartCap()#


Sets the cap geometry at the start of an open stroked path. Use this with setStrokeEndCap to set distinct caps for each end of a stroke (for set both ends at once and is preserved for backwards compatibility.

Parameters#

Parameter Type Description
id number The block whose stroke start cap should be set.
cap "Round" "Butt"

Returns#

void

Signature#

setStrokeStartCap(id: number, cap: "Round" | "Butt" | "Square"): void

getStrokeStartCap()#


Gets the cap geometry at the start of an open stroked path.

Parameters#

Parameter Type Description
id number The block whose stroke start cap should be queried.

Returns#

"Round" | "Butt" | "Square"

The start cap.

Signature#

getStrokeStartCap(id: number): "Round" | "Butt" | "Square"

setStrokeEndCap()#


Sets the cap geometry at the end of an open stroked path. Use this with setStrokeStartCap to set distinct caps for each end of a stroke.

Parameters#

Parameter Type Description
id number The block whose stroke end cap should be set.
cap "Round" "Butt"

Returns#

void

Signature#

setStrokeEndCap(id: number, cap: "Round" | "Butt" | "Square"): void

getStrokeEndCap()#


Gets the cap geometry at the end of an open stroked path.

Parameters#

Parameter Type Description
id number The block whose stroke end cap should be queried.

Returns#

"Round" | "Butt" | "Square"

The end cap.

Signature#

getStrokeEndCap(id: number): "Round" | "Butt" | "Square"

setStrokeDashStartCap()#


Sets the cap geometry at the leading edge of each dash piece (excluding the line’s actual start). Only takes effect when a dash pattern is active. Distinct from setStrokeStartCap, which only applies to the start of the open path itself.

Parameters#

Parameter Type Description
id number The block whose dash start cap should be set.
cap "Round" "Butt"

Returns#

void

Signature#

setStrokeDashStartCap(id: number, cap: "Round" | "Butt" | "Square"): void

getStrokeDashStartCap()#


Gets the cap geometry at the leading edge of each dash piece.

Parameters#

Parameter Type Description
id number The block whose dash start cap should be queried.

Returns#

"Round" | "Butt" | "Square"

The dash start cap.

Signature#

getStrokeDashStartCap(id: number): "Round" | "Butt" | "Square"

setStrokeDashEndCap()#


Sets the cap geometry at the trailing edge of each dash piece (excluding the line’s actual end). Only takes effect when a dash pattern is active. Distinct from setStrokeEndCap, which only applies to the end of the open path itself.

Parameters#

Parameter Type Description
id number The block whose dash end cap should be set.
cap "Round" "Butt"

Returns#

void

Signature#

setStrokeDashEndCap(id: number, cap: "Round" | "Butt" | "Square"): void

getStrokeDashEndCap()#


Gets the cap geometry at the trailing edge of each dash piece.

Parameters#

Parameter Type Description
id number The block whose dash end cap should be queried.

Returns#

"Round" | "Butt" | "Square"

The dash end cap.

Signature#

getStrokeDashEndCap(id: number): "Round" | "Butt" | "Square"

setStrokeDashArray()#


Sets a custom dash pattern for the block’s stroke. Semantics match SVG’s stroke-dasharray: alternating on/off lengths in design-unit space. When the pattern is non-empty it overrides the preset implied by StrokeStyle. Pass an empty array to fall back to the preset.

Parameters#

Parameter Type Description
id number The block whose stroke dash pattern should be set.
dashArray number[] Alternating on/off lengths. Odd-length arrays are doubled to an even length, matching SVG behaviour.

Returns#

void

Signature#

setStrokeDashArray(id: number, dashArray: number[]): void

getStrokeDashArray()#


Gets the custom dash pattern of the block’s stroke.

Parameters#

Parameter Type Description
id number The block whose stroke dash pattern should be queried.

Returns#

number[]

The dash pattern, or an empty array if no custom pattern is set.

Signature#

getStrokeDashArray(id: number): number[]

setStrokeDashOffset()#


Sets the dash offset of the block’s stroke. Semantics match SVG’s stroke-dashoffset. Ignored when the custom dash pattern is empty.

Parameters#

Parameter Type Description
id number The block whose stroke dash offset should be set.
dashOffset number The dash offset in design-unit space.

Returns#

void

Signature#

setStrokeDashOffset(id: number, dashOffset: number): void

getStrokeDashOffset()#


Gets the dash offset of the block’s stroke.

Parameters#

Parameter Type Description
id number The block whose stroke dash offset should be queried.

Returns#

number

The dash offset.

Signature#

getStrokeDashOffset(id: number): number

getStrokeFill()#


Gets the fill block that paints the stroke of a block.

Parameters#

Parameter Type Description
id number The block whose stroke fill should be returned. Graphic blocks and pages are supported.

Returns#

number

The fill block that paints the stroke, or null when the stroke uses its color.

Signature#

getStrokeFill(id: number): number

setStrokeFill()#


Paints the stroke of a block with a fill block, for example a gradient, instead of the stroke color.

Color, gradient, stripe and image fills are supported; video and pixel stream fills are rejected. An image covers the frame of the block and the part of the stroke outside it. The crop, the effects and the blur of the block apply only to its fill. The previous stroke fill block is not destroyed automatically. The fill block may not be the block’s own fill. A stroke color with alpha 0 still hides the stroke; the fill’s own colors set the opacity otherwise.

Required scope: ‘stroke/change’

Parameters#

Parameter Type Description
id number The block whose stroke should be painted. Graphic blocks and pages are supported.
fill number The fill block, or null to paint the stroke with its color again.

Returns#

void

Signature#

setStrokeFill(id: number, fill: number): void

Block Drop Shadow#

Configure drop shadow effects, including blur, color, and offset.

supportsDropShadow()#


Checks if a block supports a drop shadow.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True if the block supports a drop shadow.

Signature#

supportsDropShadow(id: number): boolean

setDropShadowEnabled()#


Enables or disables the drop shadow of a block.

engine.block.setDropShadowEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose drop shadow should be enabled or disabled.
enabled boolean If true, the drop shadow will be enabled.

Returns#

void

Signature#

setDropShadowEnabled(id: number, enabled: boolean): void

isDropShadowEnabled()#


Checks if the drop shadow of a block is enabled.

const dropShadowIsEnabled = engine.block.isDropShadowEnabled(block);

Parameters#

Parameter Type Description
id number The block whose drop shadow state should be queried.

Returns#

boolean

True if the block’s drop shadow is enabled.

Signature#

isDropShadowEnabled(id: number): boolean

setDropShadowColor()#


Sets the drop shadow color of a block.

Parameters#

Parameter Type Description
id number The block whose drop shadow color should be set.
color Color The color to set.

Returns#

void

Signature#

setDropShadowColor(id: number, color: Color): void

getDropShadowColor()#


Gets the drop shadow color of a block.

Parameters#

Parameter Type Description
id number The block whose drop shadow color should be queried.

Returns#

Color

The drop shadow color.

Signature#

getDropShadowColor(id: number): Color

setDropShadowOffsetX()#


Sets the drop shadow’s horizontal offset.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s X offset should be set.
offsetX number The X offset to be set.

Returns#

void

Signature#

setDropShadowOffsetX(id: number, offsetX: number): void

getDropShadowOffsetX()#


Gets the drop shadow’s horizontal offset.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s X offset should be queried.

Returns#

number

The offset.

Signature#

getDropShadowOffsetX(id: number): number

setDropShadowOffsetY()#


Sets the drop shadow’s vertical offset.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s Y offset should be set.
offsetY number The Y offset to be set.

Returns#

void

Signature#

setDropShadowOffsetY(id: number, offsetY: number): void

getDropShadowOffsetY()#


Gets the drop shadow’s vertical offset.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s Y offset should be queried.

Returns#

number

The offset.

Signature#

getDropShadowOffsetY(id: number): number

setDropShadowBlurRadiusX()#


Sets the drop shadow’s horizontal blur radius.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s blur radius should be set.
blurRadiusX number The blur radius to be set.

Returns#

void

Signature#

setDropShadowBlurRadiusX(id: number, blurRadiusX: number): void

getDropShadowBlurRadiusX()#


Gets the drop shadow’s horizontal blur radius.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s blur radius should be queried.

Returns#

number

The blur radius.

Signature#

getDropShadowBlurRadiusX(id: number): number

setDropShadowBlurRadiusY()#


Sets the drop shadow’s vertical blur radius.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s blur radius should be set.
blurRadiusY number The blur radius to be set.

Returns#

void

Signature#

setDropShadowBlurRadiusY(id: number, blurRadiusY: number): void

getDropShadowBlurRadiusY()#


Gets the drop shadow’s vertical blur radius.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s blur radius should be queried.

Returns#

number

The blur radius.

Signature#

getDropShadowBlurRadiusY(id: number): number

setDropShadowClip()#


Sets the drop shadow’s clipping behavior.

This only applies to shapes.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s clip should be set.
clip boolean The drop shadow’s clip to be set.

Returns#

void

Signature#

setDropShadowClip(id: number, clip: boolean): void

getDropShadowClip()#


Gets the drop shadow’s clipping behavior.

Parameters#

Parameter Type Description
id number The block whose drop shadow’s clipping should be queried.

Returns#

boolean

The drop shadow’s clipping state.

Signature#

getDropShadowClip(id: number): boolean

Block Effects#

Create, manage, and apply various visual effects to blocks.

createEffect()#


Creates a new effect block.

Parameters#

Parameter Type Description
type EffectType The type of the effect.

Returns#

number

The created effect’s handle.

Signature#

createEffect(type: EffectType): number

supportsEffects()#


Checks if a block supports effects.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block can render effects, false otherwise.

Signature#

supportsEffects(id: number): boolean

getEffects()#


Gets all effects attached to a block.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number[]

A list of effects or an error, if the block doesn’t support effects.

Signature#

getEffects(id: number): number[]

insertEffect()#


Inserts an effect into a block’s effect list at a given index.

Parameters#

Parameter Type Description
id number The block to update.
effectId number The effect to insert.
index number The index at which the effect shall be inserted.

Returns#

void

Signature#

insertEffect(id: number, effectId: number, index: number): void

appendEffect()#


Appends an effect to a block’s effect list.

Parameters#

Parameter Type Description
id number The block to append the effect to.
effectId number The effect to append.

Returns#

void

Signature#

appendEffect(id: number, effectId: number): void

removeEffect()#


Removes an effect from a block’s effect list at a given index.

Parameters#

Parameter Type Description
id number The block to remove the effect from.
index number The index where the effect is stored.

Returns#

void

Signature#

removeEffect(id: number, index: number): void

setEffectEnabled()#


Sets the enabled state of an effect block.

engine.block.setEffectEnabled(effects[0], false);

Parameters#

Parameter Type Description
effectId number The ‘effect’ block to update.
enabled boolean The new state.

Returns#

void

Signature#

setEffectEnabled(effectId: number, enabled: boolean): void

isEffectEnabled()#


Queries if an effect block is enabled.

engine.block.isEffectEnabled(effects[0]);

Parameters#

Parameter Type Description
effectId number The ‘effect’ block to query.

Returns#

boolean

True, if the effect is enabled. False otherwise.

Signature#

isEffectEnabled(effectId: number): boolean

setEffectSource()#


Sets the block that an effect reads, such as the map of a displacement map effect.

The source still draws on its own. It is read without its position and rotation, and also when it is hidden.

Required scope: ‘appearance/effect’ on every block the effect is attached to.

const effect = engine.block.createEffect('displacement_map');
engine.block.setEffectSource(effect, mapBlock);

Parameters#

Parameter Type Description
effectId number The ‘effect’ block to update. Only the displacement map effect reads a source.
source number A graphic, text or group block, or null to remove the source.

Returns#

void

Signature#

setEffectSource(effectId: number, source: number): void

getEffectSource()#


Gets the block that an effect reads.

const mapBlock = engine.block.getEffectSource(effect);

Parameters#

Parameter Type Description
effectId number The ‘effect’ block to query. Only the displacement map effect reads a source.

Returns#

number

The source block, or null when the effect has no source.

Signature#

getEffectSource(effectId: number): number

Block Text Animators#

createTextAnimator()#


Creates a new text animator block.

A text animator changes the glyphs of a text block that its range selector covers: their position, scale, rotation, skew, opacity, colors, stroke width, tracking and blur. Attach it to a text block with appendTextAnimator or insertTextAnimator. Every property of a text animator can have keyframes.

const animator = engine.block.createTextAnimator();
engine.block.setFloat(animator, 'text_animator/positionY', -20);
engine.block.setFloat(animator, 'text_animator/selectorEnd', 0.5);
engine.block.appendTextAnimator(text, animator);

Returns#

number

The created text animator’s handle.

Signature#

createTextAnimator(): number

supportsTextAnimators()#


Checks if a block supports text animators. Text and caption blocks do.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports text animators, false otherwise.

Signature#

supportsTextAnimators(id: number): boolean

getTextAnimators()#


Gets the text animators of a block, in the order they apply.

Parameters#

Parameter Type Description
id number The text block to query.

Returns#

number[]

The text animators of the block.

Throws#

Error if the block doesn’t support text animators.

Signature#

getTextAnimators(id: number): number[]

insertTextAnimator()#


Inserts a text animator into a block’s text animators at a given index. A text animator belongs to one block at a time.

Required scope: ‘appearance/animation’

Parameters#

Parameter Type Description
id number The text block to update.
animatorId number The text animator to insert.
index number The index at which the text animator shall be inserted.

Returns#

void

Throws#

Error if the block doesn’t support text animators, the block to insert is not a text animator or already belongs to a block, or the index is out of bounds.

Signature#

insertTextAnimator(id: number, animatorId: number, index: number): void

appendTextAnimator()#


Appends a text animator to a block’s text animators. A text animator belongs to one block at a time.

Required scope: ‘appearance/animation’

Parameters#

Parameter Type Description
id number The text block to update.
animatorId number The text animator to append.

Returns#

void

Throws#

Error if the block doesn’t support text animators, or the block to append is not a text animator or already belongs to a block.

Signature#

appendTextAnimator(id: number, animatorId: number): void

removeTextAnimator()#


Removes the text animator at a given index from a block. The text animator is not destroyed.

Required scope: ‘appearance/animation’

Parameters#

Parameter Type Description
id number The text block to update.
index number The index of the text animator to remove.

Returns#

void

Throws#

Error if the block doesn’t support text animators or the index is out of bounds.

Signature#

removeTextAnimator(id: number, index: number): void

Block Blur#

Apply and configure blur effects on blocks.

createBlur()#


Creates a new blur block.

Parameters#

Parameter Type Description
type BlurType The type of blur.

Returns#

number

The handle of the newly created blur.

Signature#

createBlur(type: BlurType): number

supportsBlur()#


Checks if a block supports blur.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports blur.

Signature#

supportsBlur(id: number): boolean

setBlur()#


Sets the blur effect for a block.

Parameters#

Parameter Type Description
id number The block to update.
blurId number A ‘blur’ block to apply.

Returns#

void

Signature#

setBlur(id: number, blurId: number): void

getBlur()#


Gets the blur block of a given design block.

For example, a graphic has no blur right after create('graphic'), although isBlurEnabled returns true.

const blur = engine.block.getBlur(block);
if (engine.block.isValid(blur)) {
const blurType = engine.block.getType(blur);
}

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number

The ‘blur’ block, or an invalid block if unset. Check the result with isValid.

Signature#

getBlur(id: number): number

setBlurEnabled()#


Enables or disables the blur effect on a block.

engine.block.setBlurEnabled(block, true);

Parameters#

Parameter Type Description
id number The block to update.
enabled boolean The new enabled value.

Returns#

void

Signature#

setBlurEnabled(id: number, enabled: boolean): void

isBlurEnabled()#


Checks if blur is enabled for a block.

The flag does not depend on an attached blur block. It defaults to true, so a fresh graphic reports its blur as enabled while getBlur returns an invalid block. Check that result with isValid.

const isBlurEnabled = engine.block.isBlurEnabled(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the blur is enabled. False otherwise.

Signature#

isBlurEnabled(id: number): boolean

Block Placeholder#

Manage placeholder functionality, controls, and behavior.

setPlaceholderEnabled()#


Enables or disables the placeholder function for a block.

When set to true, the given block becomes selectable by users and its placeholder capabilities are enabled in Adopter mode.

engine.block.setPlaceholderEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose placeholder function should be enabled or disabled.
enabled boolean Whether the function should be enabled or disabled.

Returns#

void

Signature#

setPlaceholderEnabled(id: number, enabled: boolean): void

isPlaceholderEnabled()#


Checks if the placeholder function for a block is enabled and can be selected by users in Adopter mode.

const placeholderIsEnabled = engine.block.isPlaceholderEnabled(block);

Parameters#

Parameter Type Description
id number The block whose placeholder function state should be queried.

Returns#

boolean

The enabled state of the placeholder function.

Signature#

isPlaceholderEnabled(id: number): boolean

supportsPlaceholderBehavior()#


Checks if a block supports placeholder behavior.

const placeholderBehaviorSupported = engine.block.supportsPlaceholderBehavior(block);

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports placeholder behavior.

Signature#

supportsPlaceholderBehavior(id: number): boolean

setPlaceholderBehaviorEnabled()#


Enables or disables the placeholder behavior for a block.

When its fill block is set to true, an image block will act as a placeholder, showing a control overlay and a replacement button.

engine.block.setPlaceholderBehaviorEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose placeholder behavior should be enabled or disabled.
enabled boolean Whether the placeholder behavior should be enabled or disabled.

Returns#

void

Signature#

setPlaceholderBehaviorEnabled(id: number, enabled: boolean): void

isPlaceholderBehaviorEnabled()#


Checks if the placeholder behavior for a block is enabled.

engine.block.setPlaceholderBehaviorEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose placeholder behavior state should be queried.

Returns#

boolean

The enabled state of the placeholder behavior.

Signature#

isPlaceholderBehaviorEnabled(id: number): boolean

supportsPlaceholderControls()#


Checks if a block supports placeholder controls, e.g. a control overlay and a replacement button.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports placeholder controls.

Signature#

supportsPlaceholderControls(id: number): boolean

setPlaceholderControlsOverlayEnabled()#


Enables or disables the placeholder overlay pattern.

engine.block.setPlaceholderControlsOverlayEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose placeholder overlay should be enabled or disabled.
enabled boolean Whether the placeholder overlay should be shown or not.

Returns#

void

Signature#

setPlaceholderControlsOverlayEnabled(id: number, enabled: boolean): void

isPlaceholderControlsOverlayEnabled()#


Checks if the placeholder overlay pattern is enabled.

const overlayEnabled = engine.block.isPlaceholderControlsOverlayEnabled(block);

Parameters#

Parameter Type Description
id number The block whose placeholder overlay visibility state should be queried.

Returns#

boolean

The visibility state of the block’s placeholder overlay pattern.

Signature#

isPlaceholderControlsOverlayEnabled(id: number): boolean

setPlaceholderControlsButtonEnabled()#


Enables or disables the placeholder button.

engine.block.setPlaceholderControlsButtonEnabled(block, true);

Parameters#

Parameter Type Description
id number The block whose placeholder button should be shown or not.
enabled boolean Whether the placeholder button should be shown or not.

Returns#

void

Signature#

setPlaceholderControlsButtonEnabled(id: number, enabled: boolean): void

isPlaceholderControlsButtonEnabled()#


Checks if the placeholder button is enabled.

const buttonEnabled = engine.block.isPlaceholderControlsButtonEnabled(block);

Parameters#

Parameter Type Description
id number The block whose placeholder button visibility state should be queried.

Returns#

boolean

The visibility state of the block’s placeholder button.

Signature#

isPlaceholderControlsButtonEnabled(id: number): boolean

Block Scopes#

Manage permissions and capabilities per block.

setScopeEnabled()#


Enables or disables a scope for a block.

// Allow the user to move the image block.
engine.block.setScopeEnabled(image, 'layer/move', true);

Parameters#

Parameter Type Description
id number The block whose scope should be enabled or disabled.
key Scope The scope to enable or disable.
enabled boolean Whether the scope should be enabled or disabled.

Returns#

void

Signature#

setScopeEnabled(id: number, key: Scope, enabled: boolean): void

isScopeEnabled()#


Checks if a scope is enabled for a block.

engine.block.isScopeEnabled(image, 'layer/move');

Parameters#

Parameter Type Description
id number The block whose scope state should be queried.
key Scope The scope to query.

Returns#

boolean

The enabled state of the scope for the given block.

Signature#

isScopeEnabled(id: number, key: Scope): boolean

isAllowedByScope()#


Checks if an operation is allowed by a block’s scopes.

// This will return true when the global scope is set to 'Defer'.
engine.block.isAllowedByScope(image, 'layer/move');

Parameters#

Parameter Type Description
id number The block to check.
key Scope The scope to check.

Returns#

boolean

Whether the scope is allowed for the given block.

Signature#

isAllowedByScope(id: number, key: Scope): boolean

Block Boolean Operations#

Combine multiple blocks into a single new block using boolean path operations.

isCombinable()#


Checks if a set of blocks can be combined using a boolean operation.

Only graphics blocks and text blocks can be combined. All blocks must have the “lifecycle/duplicate” scope enabled.

Parameters#

Parameter Type Description
ids number[] An array of block ids.

Returns#

boolean

Whether the blocks can be combined.

Signature#

isCombinable(ids: number[]): boolean

combine()#


Performs a boolean operation on a set of blocks.

All blocks must be combinable. See isCombinable. The parent, fill and sort order of the new block is that of the prioritized block. When the prioritized block has no fill, the new block has none.

Parameters#

Parameter Type Description
ids number[] The blocks to combine. They will be destroyed if “lifecycle/destroy” scope is enabled.
op BooleanOperation The boolean operation to perform.

Returns#

number

The newly created block or an error.

Signature#

combine(ids: number[], op: BooleanOperation): number

Block Cutout#

Create cutout operations and path-based modifications.

createCutoutFromBlocks()#


Creates a cutout block from the contours of other blocks.

The path is derived from either existing vector paths or by vectorizing the block’s appearance.

Performs an internal update to lay out pending changes, because the cutout reads the blocks’ layout. With the setting features/implicitUpdatesEnabled off, the update runs only when a passed block has no layout, and it then lays out all pending changes. A block with no layout on a page that single page mode hides returns an error.

Parameters#

Parameter Type Description
ids number[] The blocks whose shape will serve as the basis for the cutout’s path.
vectorizeDistanceThreshold? number Max deviation from the original contour during vectorization.
simplifyDistanceThreshold? number Max deviation for path simplification. 0 disables simplification.
useExistingShapeInformation? boolean If true, use existing vector paths.

Returns#

number

The newly created block or an error.

Signature#

createCutoutFromBlocks(ids: number[], vectorizeDistanceThreshold?: number, simplifyDistanceThreshold?: number, useExistingShapeInformation?: boolean): number

createCutoutFromPath()#


Creates a cutout block from an SVG path string.

Parameters#

Parameter Type Description
path string An SVG string describing a path.

Returns#

number

The newly created block or an error.

Signature#

createCutoutFromPath(path: string): number

createCutoutFromOperation()#


Creates a new cutout block by performing a boolean operation on existing cutout blocks.

Parameters#

Parameter Type Description
ids number[] The cutout blocks with which to perform to the operation.
op CutoutOperation The boolean operation to perform.

Returns#

number

The newly created block or an error.

Signature#

createCutoutFromOperation(ids: number[], op: CutoutOperation): number

Block#

split()#


Splits a block at the specified time.

The original block will be trimmed to end at the split time, and the returned duplicate will start at the split time and continue to the original end time.

const duplicate = engine.block.split(video, 10.0);

Parameters#

Parameter Type Description
id number The block to split.
atTime number The time (in seconds) relative to the block’s time offset where the split should occur.
options? SplitOptions The options for configuring the split operation.

Returns#

number

The newly created second half of the split block.

Signature#

split(id: number, atTime: number, options?: SplitOptions): number

Block Analysis#

getDominantColors()#


Extracts the dominant colors from the rendered appearance of a block.

Performs an internal update to resolve the final layout for the block. Will not complete as long as assets are in a pending state; asset loading progresses during engine updates. Crops, color adjustments, and effects applied to the block are reflected in the returned palette. Fully or mostly transparent pixels are excluded from the analysis.

Parameters#

Parameter Type Description
handle number The design block element to analyze. Must be attached to a scene and render visible content.
options? DominantColorsOptions See DominantColorsOptions.

Returns#

Promise<DominantColor[]>

A promise that resolves with the dominant colors sorted by weight, descending.

Signature#

getDominantColors(handle: number, options?: DominantColorsOptions): Promise<DominantColor[]>

Block Audio#

getAudioTrackCountFromVideo()#


Gets the number of available audio tracks in a video fill block.

const trackCount = engine.block.getAudioTrackCountFromVideo(videoBlock);
console.log(`Video has ${trackCount} audio tracks`);

Parameters#

Parameter Type Description
videoFillBlock number The video fill block to examine.

Returns#

number

The number of audio tracks.

Throws#

Will throw an error if the block is not a video fill or has no audio.

Signature#

getAudioTrackCountFromVideo(videoFillBlock: number): number

createAudioFromVideo()#


Creates a new audio block by extracting a specific audio track from a video fill block.

// Extract the first audio track (usually the main mix) with trim settings
const audioBlock = engine.block.createAudioFromVideo(videoFillBlock, 0);
// Extract full audio track without trim settings
const audioBlock = engine.block.createAudioFromVideo(videoFillBlock, 0, { keepTrimSettings: false });
// Extract a specific track, keep trim settings, and mute the original video
const dialogueTrack = engine.block.createAudioFromVideo(videoFillBlock, 1, { keepTrimSettings: true, muteOriginalVideo: true });

Note: The audio block can still load after this call returns. When the video file is not completely in memory, for example an uploaded or a remote video, the audio comes from the file in the background. Until it is complete, unstable_isAVResourceLoaded returns false, forceLoadAVResource waits for it, and the block is pending once it is in the scene.

Parameters#

Parameter Type Description
videoFillBlock number The video fill block to extract audio from.
trackIndex number The index of the audio track to extract (0-based).
options? AudioFromVideoOptions Options for the audio extraction operation.

Returns#

number

The handle of the newly created audio block with extracted audio from the specified track.

Throws#

Will throw an error if the track index is invalid or the block has no audio.

Signature#

createAudioFromVideo(videoFillBlock: number, trackIndex: number, options?: AudioFromVideoOptions): number

createAudiosFromVideo()#


Creates multiple audio blocks by extracting all audio tracks from a video fill block.

// Extract all audio tracks from a video with trim settings
const audioBlocks = engine.block.createAudiosFromVideo(videoFillBlock);
console.log(`Created ${audioBlocks.length} audio blocks`);
// Extract all tracks without trim settings (full audio)
const audioBlocks = engine.block.createAudiosFromVideo(videoFillBlock, { keepTrimSettings: false });
// Extract all tracks with trim settings and mute the original video
const audioBlocks = engine.block.createAudiosFromVideo(videoFillBlock, { keepTrimSettings: true, muteOriginalVideo: true });

Note: The audio blocks can still load after this call returns, as with createAudioFromVideo.

Parameters#

Parameter Type Description
videoFillBlock number The video fill block to extract audio from.
options? AudioFromVideoOptions Options for the audio extraction operation.

Returns#

number[]

An array of handles for the newly created audio blocks, one per track.

Throws#

Will throw an error if the block has no audio or extraction fails.

Signature#

createAudiosFromVideo(videoFillBlock: number, options?: AudioFromVideoOptions): number[]

getAudioInfoFromVideo()#


Gets information about all audio tracks from a video fill block.

// Get information about all audio tracks
const trackInfos = engine.block.getAudioInfoFromVideo(videoFillBlock);
console.log(`Video has ${trackInfos.length} audio tracks`);
// Display track information
trackInfos.forEach((track, index) => {
console.log(`Track ${index}: ${track.channels} channels, ${track.sampleRate}Hz, ${track.language}`);
});
// Use track info to create audio blocks selectively
const englishTracks = trackInfos.filter(track => track.language === 'eng');
const audioBlocks = englishTracks.map(track =>
engine.block.createAudioFromVideo(videoFillBlock, track.trackIndex)
);

Parameters#

Parameter Type Description
videoFillBlock number The video fill block to analyze for audio track information.

Returns#

AudioTrackInfo[]

An array containing information about each audio track.

Throws#

Will throw an error if the block is not a video fill or has no audio.

Signature#

getAudioInfoFromVideo(videoFillBlock: number): AudioTrackInfo[]

Block Components#

convertToComponent()#


Makes a block a main component, so that instances can follow it.

Parameters#

Parameter Type Description
block number The block.

Returns#

void

Signature#

convertToComponent(block: number): void

isComponent()#


Checks whether a block is a main component.

Parameters#

Parameter Type Description
block number The block.

Returns#

boolean

The result.

Signature#

isComponent(block: number): boolean

createInstance()#


Creates an instance of a main component. Attach it with appendChild. An instance follows every property that it does not override. Its children cannot be added, reordered or destroyed. Hide a child with setVisible.

Parameters#

Parameter Type Description
component number The component.

Returns#

number

The result.

Signature#

createInstance(component: number): number

isInstance()#


Checks whether a block is the top block of an instance.

Parameters#

Parameter Type Description
block number The block.

Returns#

boolean

The result.

Signature#

isInstance(block: number): boolean

getMainComponent()#


Gets the main component of an instance.

Parameters#

Parameter Type Description
instance number The instance.

Returns#

number

The result.

Signature#

getMainComponent(instance: number): number

detachInstance()#


Turns an instance into plain blocks that no longer follow the main component.

Parameters#

Parameter Type Description
instance number The instance.

Returns#

void

Signature#

detachInstance(instance: number): void

resetInstance()#


Removes all overrides of an instance.

Parameters#

Parameter Type Description
instance number The instance.

Returns#

void

Signature#

resetInstance(instance: number): void

combineAsVariants()#


Moves main components into a new container as variants of one component.

Parameters#

Parameter Type Description
components number[] The components.

Returns#

number

The result.

Signature#

combineAsVariants(components: number[]): number

setVariantProperty()#


Sets the value of a variant property on a main component.

Parameters#

Parameter Type Description
component number The component.
name string The name.
value string The value.

Returns#

void

Signature#

setVariantProperty(component: number, name: string, value: string): void

getVariantProperty()#


Gets the value of a variant property of a main component.

Parameters#

Parameter Type Description
component number The component.
name string The name.

Returns#

string

The result.

Signature#

getVariantProperty(component: number, name: string): string

findAllVariantProperties()#


Gets the sorted names of the variant properties of a main component.

Parameters#

Parameter Type Description
component number The component.

Returns#

string[]

The result.

Signature#

findAllVariantProperties(component: number): string[]

setInstanceVariant()#


Switches an instance to the variant with this property value. Overrides stay, and layers match by name.

Parameters#

Parameter Type Description
instance number The instance.
name string The name.
value string The value.

Returns#

void

Signature#

setInstanceVariant(instance: number, name: string, value: string): void

addComponentProperty()#


Publishes a property of a block inside a main component under a name that instances can set.

Parameters#

Parameter Type Description
component number The component.
name string The name.
target number The target.
property string The property.

Returns#

void

Signature#

addComponentProperty(component: number, name: string, target: number, property: string): void

findAllComponentProperties()#


Gets the sorted names of the published properties of a main component.

Parameters#

Parameter Type Description
component number The component.

Returns#

string[]

The result.

Signature#

findAllComponentProperties(component: number): string[]

setComponentProperty()#


Sets a published property on an instance as text. This is an override.

Parameters#

Parameter Type Description
instance number The instance.
name string The name.
value string The value.

Returns#

void

Signature#

setComponentProperty(instance: number, name: string, value: string): void

getComponentProperty()#


Gets a published property of an instance as text.

Parameters#

Parameter Type Description
instance number The instance.
name string The name.

Returns#

string

The result.

Signature#

getComponentProperty(instance: number, name: string): string

Block Masks#

Cut blocks down to the shapes of their masks.

createMask()#


Creates a new mask block.

A mask cuts its block down to the area of the mask’s shape. Give the mask a shape with setShape; a mask without a shape has no effect. The shape is evaluated in the frame of the block that the mask is attached to. The mask properties are mask/mode, mask/opacity, mask/feather, mask/expansion and mask/inverted.

const mask = engine.block.createMask();
engine.block.setShape(mask, engine.block.createShape('ellipse'));
engine.block.appendMask(block, mask);

Returns#

number

The created mask’s handle.

Signature#

createMask(): number

supportsMasks()#


Checks if a block supports masks. Graphic, text and group blocks do.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports masks, false otherwise.

Signature#

supportsMasks(id: number): boolean

getMasks()#


Gets the masks of a block, in the order in which they combine.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

number[]

The masks of the block.

Throws#

Error if the block does not support masks.

Signature#

getMasks(id: number): number[]

insertMask()#


Inserts a mask into a block’s masks at a given index.

Required scope: ‘layer/clipping’

Parameters#

Parameter Type Description
id number The block to mask.
maskId number The mask to insert. A mask can be used by more than one block.
index number The index in the range [0, number of masks]. The masks combine in the order of their indices.

Returns#

void

Throws#

Error if the block does not support masks, the mask is not a mask or the index is out of range.

Signature#

insertMask(id: number, maskId: number, index: number): void

appendMask()#


Appends a mask to a block’s masks.

Required scope: ‘layer/clipping’

Parameters#

Parameter Type Description
id number The block to mask.
maskId number The mask to append. A mask can be used by more than one block.

Returns#

void

Throws#

Error if the block does not support masks or the mask is not a mask.

Signature#

appendMask(id: number, maskId: number): void

removeMask()#


Removes the mask at the given index from a block’s masks. The mask block is not destroyed.

Required scope: ‘layer/clipping’

Parameters#

Parameter Type Description
id number The block to remove the mask from.
index number The index of the mask.

Returns#

void

Throws#

Error if the block does not support masks or the index is out of range.

Signature#

removeMask(id: number, index: number): void

Block Metadata#

setMetadata()#


Sets a metadata value for a given key on a block.

If the key does not exist, it will be added.

Parameters#

Parameter Type Description
id number The block whose metadata will be accessed.
key string The key used to identify the desired piece of metadata.
value string The value to set.

Returns#

void

Signature#

setMetadata(id: number, key: string, value: string): void

getMetadata()#


Gets a metadata value for a given key from a block.

Parameters#

Parameter Type Description
id number The block whose metadata will be accessed.
key string The key used to identify the desired piece of metadata.

Returns#

string

The value associated with the key.

Signature#

getMetadata(id: number, key: string): string

hasMetadata()#


Checks if a block has metadata for a given key.

Parameters#

Parameter Type Description
id number The block whose metadata will be accessed.
key string The key used to identify the desired piece of metadata.

Returns#

boolean

Whether the key exists.

Signature#

hasMetadata(id: number, key: string): boolean

findAllMetadata()#


Finds all metadata keys on a block.

Parameters#

Parameter Type Description
id number The block whose metadata will be accessed.

Returns#

string[]

A list of all metadata keys on this block.

Signature#

findAllMetadata(id: number): string[]

removeMetadata()#


Removes metadata for a given key from a block.

Parameters#

Parameter Type Description
id number The block whose metadata will be accessed.
key string The key used to identify the desired piece of metadata.

Returns#

void

Signature#

removeMetadata(id: number, key: string): void

Block Modifiers#

createModifier()#


Creates a new shape modifier block.

A modifier changes the path of a shape, or draws the shape several times. Attach it to a shape with appendModifier or insertModifier.

const trim = engine.block.createModifier('trim');
engine.block.setFloat(trim, 'modifier/trim/end', 0.5);
engine.block.appendModifier(engine.block.getShape(graphic), trim);

Parameters#

Parameter Type Description
type ModifierType The type of the modifier.

Returns#

number

The created modifier’s handle.

Signature#

createModifier(type: ModifierType): number

supportsModifiers()#


Checks if a block supports modifiers. Every shape block does.

Parameters#

Parameter Type Description
id number The block to query.

Returns#

boolean

True, if the block supports modifiers, false otherwise.

Signature#

supportsModifiers(id: number): boolean

getModifiers()#


Gets the modifiers of a shape, in the order they apply to its path.

Parameters#

Parameter Type Description
id number The shape to query.

Returns#

number[]

The modifiers of the shape.

Throws#

Error if the block doesn’t support modifiers.

Signature#

getModifiers(id: number): number[]

insertModifier()#


Inserts a modifier into a shape’s modifier list at a given index.

Required scope: ‘shape/change’ on every block that uses the shape.

Parameters#

Parameter Type Description
id number The shape to update.
modifierId number The modifier to insert.
index number The index at which the modifier shall be inserted.

Returns#

void

Throws#

Error if the block doesn’t support modifiers, the block to insert is not a modifier, or the index is out of bounds.

Signature#

insertModifier(id: number, modifierId: number, index: number): void

appendModifier()#


Appends a modifier to a shape’s modifier list.

Required scope: ‘shape/change’ on every block that uses the shape.

Parameters#

Parameter Type Description
id number The shape to update.
modifierId number The modifier to append.

Returns#

void

Throws#

Error if the block doesn’t support modifiers or the block to append is not a modifier.

Signature#

appendModifier(id: number, modifierId: number): void

removeModifier()#


Removes a modifier from a shape’s modifier list at a given index. The modifier is not destroyed.

Required scope: ‘shape/change’ on every block that uses the shape.

Parameters#

Parameter Type Description
id number The shape to update.
index number The index of the modifier to remove.

Returns#

void

Throws#

Error if the block doesn’t support modifiers or the index is out of bounds.

Signature#

removeModifier(id: number, index: number): void

Block Transitions#

createTransition()#


Creates a new transition block.

Its saved transition/overlap boolean starts at the current value of clip/defaultTransitionOverlapEnabled (engine default: true).

The created block is standalone until assigned to a clip with setTransition. Once assigned, it is owned by that clip: it is destroyed together with the clip, and the engine also destroys it automatically when the two clips stop being timeline-adjacent on the track (e.g. after a manual gap is introduced).

Parameters#

Parameter Type Description
type TransitionType The type of transition to create.

Returns#

number

The handle of the new transition instance.

Signature#

createTransition(type: TransitionType): number

supportsTransition()#


Checks whether a clip can own an outgoing clip-to-clip transition.

Clips inside a video track qualify, group clips included. Audio, caption and cutout blocks report false, and so do blocks outside a video track. A group that holds only audio blocks reports false too.

Parameters#

Parameter Type Description
id number The clip block to check.

Returns#

boolean

Whether the block can own an outgoing transition.

Signature#

supportsTransition(id: number): boolean

setTransition()#


Assigns the outgoing transition of a clip.

A previously assigned transition block is detached but not destroyed automatically. Throws an error if the given transition block is invalid or already assigned to another clip. Both the clip and its following clip on the track must support transitions, see supportsTransition. To clear a clip’s transition, use removeTransition instead. With transition/overlap=false on the transition block, transitions preserve clip timing and hold endpoint frames across the cut. This property is saved in scenes; older scenes without it use true. New transitions initialize it from clip/defaultTransitionOverlapEnabled. A group clip on either side ignores transition/overlap: the clips meet at the cut, and the saved value stays.

Parameters#

Parameter Type Description
id number The outgoing clip that owns the transition relation.
transition number The transition block to assign.

Returns#

void

Signature#

setTransition(id: number, transition: number): void

removeTransition()#


Removes the outgoing transition of a clip.

The removed transition block is detached but not destroyed automatically. Removing from a clip without an assigned transition is a no-op.

Parameters#

Parameter Type Description
id number The outgoing clip whose transition relation should be cleared.

Returns#

void

Signature#

removeTransition(id: number): void

getTransition()#


Gets the outgoing transition assigned to a clip.

Parameters#

Parameter Type Description
id number The outgoing clip whose transition relation should be queried.

Returns#

number

The assigned transition block, or an invalid block if unset. Check the result with isValid.

Signature#

getTransition(id: number): number

Helper#

Convenient high-level functions that combine multiple operations into single, easy-to-use methods for common tasks like adding media, applying effects, and positioning blocks.

setSize()#


Update a block’s size.

The size of a group is always Absolute: a group takes width and height in design units and no sizeMode. A group keeps its aspect ratio, so height decides its size.

A width or a height of 0 or less on a page slice fails with BLOCK.PAGE_SLICE_SIZE_INVALID.

Parameters#

Parameter Type Description
id number The block to update.
width number The new width of the block, in sizeMode if it is set and in the block’s width mode otherwise.
height number The new height of the block, in sizeMode if it is set and in the block’s height mode otherwise.
options? { maintainCrop?: boolean; sizeMode?: SizeMode; } Optional parameters for the size. Properties: - maintainCrop - Whether or not the crop values, if available, should be automatically adjusted. A Percent size, left or top stays Percent. With a sizeMode, the crop is adjusted from the frame that the block has before the call. The call can run an internal update before it changes the block. - sizeMode - The size mode: Absolute, Percent or Auto. width and height are in this mode. Auto holds no size, so width and height make both axes Absolute again.
options.maintainCrop? boolean -
options.sizeMode? SizeMode -

Returns#

void

Signature#

setSize(id: number, width: number, height: number, options?: object): void

setPosition()#


Update a block’s position.

Parameters#

Parameter Type Description
id number The block to update.
x number The new x position of the block.
y number The new y position of the block.
options? { positionMode?: PositionMode; } Optional parameters for the position. Properties: - positionMode - The position mode: absolute, percent or undefined.
options.positionMode? PositionMode -

Returns#

void

Signature#

setPosition(id: number, x: number, y: number, options?: object): void

addImage()#


Adds an image to the current page. The image will be automatically loaded and sized appropriately. In Video mode, timeline and animation options can be applied.

Parameters#

Parameter Type Description
url string URL or path to the image file
options? AddImageOptions Configuration options for the image

Returns#

Promise<number>

Promise that resolves to the ID of the created image block

Throws#

Error if no current page exists

Signature#

addImage(url: string, options?: AddImageOptions): Promise<number>

addVideo()#


Adds a video block to the current scene page. The video will be positioned and sized according to the provided parameters. Timeline and animation effects can be applied.

Parameters#

Parameter Type Description
url string URL or path to the video file
width number Width of the video in scene design units
height number Height of the video in scene design units
options? AddVideoOptions Configuration options for the video

Returns#

Promise<number>

Promise that resolves to the ID of the created video block

Throws#

Error if no current page exists

Signature#

addVideo(url: string, width: number, height: number, options?: AddVideoOptions): Promise<number>

applyAnimation()#


Applies an animation to a block.

Parameters#

Parameter Type Description
block number The ID of the block to apply the animation to
animation? AnimationOptions The animation configuration options

Returns#

void

Signature#

applyAnimation(block: number, animation?: AnimationOptions): void

applyDropShadow()#


Applies a drop shadow effect to any block.

Parameters#

Parameter Type Description
block number The ID of the block to apply the shadow to
options? DropShadowOptions Shadow configuration options. If not provided, enables shadow with default settings

Returns#

void

Signature#

applyDropShadow(block: number, options?: DropShadowOptions): void

generateThumbnailAtTimeOffset()#


Generates a thumbnail image of the scene at a specific time.

Parameters#

Parameter Type Description
height number Height of the thumbnail in scene design units (maximum 512)
time number Time position in seconds to capture the thumbnail

Returns#

Promise<Blob>

Promise that resolves to a Blob containing the PNG thumbnail image

Throws#

Error if no page exists or if height exceeds 512 pixels. It also throws without a canvas that has a 2D context: Node.js has neither a DOM nor an OffscreenCanvas.

Signature#

generateThumbnailAtTimeOffset(height: number, time: number): Promise<Blob>

getBackgroundTrack()#


Gets the background track of the current scene. The background track is the track that determines the page duration.

Returns#

number

The ID of the background track, or null if none exists

Signature#

getBackgroundTrack(): number

moveToBackgroundTrack()#


Moves a block to the background track. This is useful for organizing content in video scenes where you want certain elements to be part of the background layer. The background track is the track that determines the page duration. If no background track exists, one will be created automatically.

Parameters#

Parameter Type Description
block number The ID of the block to move to the background track

Returns#

void

Signature#

moveToBackgroundTrack(block: number): void

Other#

movePageSliceIntoPage()#


Moves a page without page slices, or a page slice of another page, into a page with page slices.

The content of the moved page or page slice moves along and keeps its ids. A moved page slice keeps its id. A page becomes a new page slice, and its id becomes invalid. The page slice keeps its size along the axis of page and takes the shared size across it. The moved content is placed above the content of page, in its own order. When the move takes the last page slice of its page, that page stays as an empty page without page slices. The move fails when a content block would change the page slice that owns it. Conversion keeps the supported appearance keyframes. Tracks of a page slice use the playback clock of its page. Conversion refuses preset animations and other tracks, such as geometry and crop tracks. convertSourceToPage refuses a remaining page slice with preset animations or keyframes. Runs an internal update even when implicit updates are disabled. Records no undo step: call addUndoStep after the move, as after any other edit. Fails while the engine switches the active history.

Parameters#

Parameter Type Description
pageOrPageSlice number A page without page slices, or a page slice of another page of the same scene.
page number A page with page slices.
index number The position of the moved page slice among the page slices of page, hidden ones too, in [0, number of page slices].
options? MovePageSliceOptions The options of the move. convertSourceToPage makes a source page with one page slice left a page without page slices.

Returns#

number

The id of the moved page slice.

Signature#

movePageSliceIntoPage(pageOrPageSlice: number, page: number, index: number, options?: MovePageSliceOptions): number

movePageSliceOutOfPage()#


Moves a page slice and its content to a new page without page slices.

The new page joins the parent of the source page. The id of the page slice becomes invalid. The content keeps its ids. The page slices after it close the gap. An enabled fill of the page slice stays. Otherwise the new page takes the fill of the source page when convertSourceToPage acts, and a white fill when it does not. When the move takes the last page slice, the source stays as an empty page without page slices. Conversion keeps the supported appearance keyframes. Tracks of a page slice use the playback clock of its page. Conversion refuses preset animations and other tracks, such as geometry and crop tracks. convertSourceToPage refuses a remaining page slice with preset animations or keyframes. Runs an internal update even when implicit updates are disabled. Records no undo step: call addUndoStep after the move, as after any other edit. Fails while the engine switches the active history.

Parameters#

Parameter Type Description
pageSlice number A page slice of a page in a scene.
index number The position of the new page among the pages of the scene, before the move, in [0, number of pages]. The source page counts. Other children of the scene do not count.
options? MovePageSliceOptions The options of the move. convertSourceToPage makes a source page with one page slice left a page without page slices.

Returns#

number

The id of the new page.

Signature#

movePageSliceOutOfPage(pageSlice: number, index: number, options?: MovePageSliceOptions): number