Edit in GitHubLog an issue

assets

Represents the document styles listed in the Assets panel. Styles can be added and removed manually by the user, so there's no guarantee that these styles are currently used anywhere in the document's content.

Since: XD 15

Enums

GradientType :
LINEAR, RADIAL - Type of gradient color element: linear gradient or radial gradient

Typedefs

Typedef ColorAsset

Assets library entry representing a solid color.

PropertyTypeDescription
name
?string
Name of the Assets entry, if it is explicitly named. (The UI shows an auto-generated label for any unnamed assets).
color
Color
Color of the asset

Typedef GradientAsset

Assets library entry representing a linear or radial gradient.

PropertyTypeDescription
name
?string
Name of the Assets entry, if it is explicitly named. (The UI shows an auto-generated label for any unnamed assets).
gradientType
GradientType
Either GradientType.LINEAR or GradientType.RADIAL
colorStops
Array.< {stop: number, color: Color} >
Array of color stops used in the gradient, where stop >= 0 and <= 1, and the values are strictly increasing. Same format as the colorStops property of a LinearGradient object.

Typedef CharacterStyleAsset

Assets library entry representing a set of text character styles.

PropertyTypeDescription
name
?string
Name of the Assets entry, if it is explicitly named. (The UI shows an auto-generated label for any unnamed assets).
style
CharacterStyle
Object containing the style properties

Typedef CharacterStyle

Character style properties. See documentation for the Text node type for more details.

When creating a new character style, all properties are mandatory except those with default values specified here. When deleting an existing character style, always pass the exact object returned by characterStyles.get() (with all properties fully specified) to avoid any ambiguity.

PropertyTypeDescription
fontFamily
string
the font family
fontStyle
string
the style of the font
fontSize
number
the size of the font
fill
Color
the Color of the font fill
charSpacing
number
the character spacing
lineSpacing
number
the line spacing
underline
boolean
whether underline is turned on
strikethrough
?boolean
(Since: XD 19) Default false; whether strikethrough is turned on
textTransform
?string
(Since: XD 19) Default "none"; one of "none", "uppercase", "lowercase", or "titlecase"
textScript
?string
(Since: XD 20) Default "none"; one of "none", "superscript", or "subscript"

colors

colors

The collection of colors and gradients saved in this document's Assets library.


colors.get()

colors.get(): Array.<ColorAsset|GradientAsset>

Get a list of all color/gradient assets, in the order they appear in the Assets panel.

The list may contain a mix of solid Color assets and/or gradient assets. If there are no color/gradient assets, an empty array is returned.

Example

Copied to your clipboard
1var assets = require("assets"),
2 allColors = assets.colors.get();

Kind: static method of colors


colors.add()

colors.add(colorAssets): number

Add color/gradient assets to the collection. Returns the number of assets added (may be less than requested if duplicates already exist).

The list may contain a mix of solid Color assets and/or gradient assets. Items are not added if a duplicate color/gradient already exists in the collection, regardless of its name.

ParamType
colorAssets
Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset | Array.<Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset>

Example

Copied to your clipboard
1var assets = require("assets"),
2 redColor = new Color("red"),
3 blueColor = new Color("blue"),
4 stops = [
5 { stop: 0, color: redColor },
6 { stop: 1, color: blueColor },
7 ],
8 numAdded = assets.colors.add([
9 redColor,
10 { name: "True Blue", color: blueColor },
11 {
12 name: "Red Blue Gradient",
13 gradientType: assets.GradientType.LINEAR,
14 colorStops: stops,
15 },
16 ]);

Kind: static method of colors


colors.delete()

colors.delete(colorAssets): number

Delete color/gradient assets from the collection. Returns the number of assets deleted (may be less than requested if some didn't exist).

The list may contain a mix of solid Color assets and/or gradient assets. Assets with the same color/gradient are removed even if their names differ. Assets that already don't exist in the collection are silently ignored. Typically you will pass asset objects returned from get() directly to this function.

ParamType
colorAssets
Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset | Array.<Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset>

Example

Copied to your clipboard
1var assets = require("assets"),
2 numDeleted = assets.colors.delete(new Color("red"));

Kind: static method of colors

characterStyles

characterStyles

The collection of character styles saved in this document's Assets library.


characterStyles.get()

characterStyles.get(): Array.<CharacterStyleAsset>

Get a list of all character style assets, in the order they appear in the Assets panel.

If there are no character style assets, an empty array is returned.

Example

Copied to your clipboard
1var assets = require("assets"),
2 allCharacterStyles = assets.characterStyles.get();

Kind: static method of characterStyles


characterStyles.add()

characterStyles.add(charStyleAssets): number

Add one or more character style assets to the collection. Returns the number of assets added (may be less than requested if duplicates already exist).

Items are not added if a duplicate character style already exists in the collection, regardless of its name. All character style properties must be fully specified (no properties are optional).

ParamType
charStyleAssets
CharacterStyleAsset | Array.<CharacterStyleAsset>

Example

Copied to your clipboard
1var assets = require("assets"),
2 arialItalic = {
3 fontFamily: "Arial",
4 fontStyle: "Italic",
5 fontSize: 12,
6 fill: new Color("black"),
7 charSpacing: 0,
8 lineSpacing: 0,
9 underline: false,
10 strikethrough: false,
11 textTransform: "uppercase",
12 },
13 linkTextStyle = {
14 fontFamily: "Arial",
15 fontStyle: "Regular",
16 fontSize: 12,
17 fill: new Color("blue"),
18 charSpacing: 0,
19 lineSpacing: 0,
20 underline: false,
21 // (leaves optional strikethrough, textTransform, & textScript properties at default values)
22 },
23 numAdded = assets.characterStyles.add([
24 { style: arialItalic }, // No name provided: uses default name
25 { style: linkTextStyle, name: "Link Text" },
26 ]);

Kind: static method of characterStyles


characterStyles.delete()

characterStyles.delete(charStyleAssets): number

Delete one or more character style assets from the collection. Returns the number of assets deleted (may be less than requested if some didn't exist).

Assets with the same character style are removed even if their names differ. Assets that already don't exist in the collection are silently ignored. All character style properties must be fully specified (no properties are optional).

To avoid ambiguity, pass the exact asset objects returned from get() directly to this function.

ParamType
charStyleAssets
CharacterStyleAsset | Array.<CharacterStyleAsset>

Example

Copied to your clipboard
1// Delete all character style assets from the assets panel
2var assets = require("assets"),
3 allCharacterStyles = assets.characterStyles.get(),
4 numDeleted = assets.characterStyles.delete(allCharacterStyles);

Kind: static method of characterStyles

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2023 Adobe. All rights reserved.