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
<dl> <dt> GradientType : </dt><dd>LINEAR, RADIAL - Type of gradient color element: linear gradient or radial gradient</dd> </dl>
Typedefs
Typedef ColorAsset
Assets library entry representing a solid color.
Typedef GradientAsset
Assets library entry representing a linear or radial gradient.
GradientType.LINEAR or GradientType.RADIALstop >= 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.
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.
colors
▸ colors
The collection of colors and gradients saved in this document's Assets library.
-
- .get():
Array.<ColorAsset|GradientAsset> - .add(colorAssets):
number - .delete(colorAssets):
number
- .get():
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
var assets = require("assets"),
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.
Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset | Array.<Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset>Example
var assets = require("assets"),
redColor = new Color("red"),
blueColor = new Color("blue"),
stops = [
{ stop: 0, color: redColor },
{ stop: 1, color: blueColor },
],
numAdded = assets.colors.add([
redColor,
{ name: "True Blue", color: blueColor },
{
name: "Red Blue Gradient",
gradientType: assets.GradientType.LINEAR,
colorStops: stops,
},
]);
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.
Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset | Array.<Color | ColorAsset | LinearGradient | RadialGradient | GradientAsset>Example
var assets = require("assets"),
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.
-
- .get():
Array.<CharacterStyleAsset> - .add(charStyleAssets):
number - .delete(charStyleAssets):
number
- .get():
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
var assets = require("assets"),
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).
CharacterStyleAsset | Array.<CharacterStyleAsset>Example
var assets = require("assets"),
arialItalic = {
fontFamily: "Arial",
fontStyle: "Italic",
fontSize: 12,
fill: new Color("black"),
charSpacing: 0,
lineSpacing: 0,
underline: false,
strikethrough: false,
textTransform: "uppercase",
},
linkTextStyle = {
fontFamily: "Arial",
fontStyle: "Regular",
fontSize: 12,
fill: new Color("blue"),
charSpacing: 0,
lineSpacing: 0,
underline: false,
// (leaves optional strikethrough, textTransform, & textScript properties at default values)
},
numAdded = assets.characterStyles.add([
{ style: arialItalic }, // No name provided: uses default name
{ style: linkTextStyle, name: "Link Text" },
]);
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.
CharacterStyleAsset | Array.<CharacterStyleAsset>Example
// Delete all character style assets from the assets panel
var assets = require("assets"),
allCharacterStyles = assets.characterStyles.get(),
numDeleted = assets.characterStyles.delete(allCharacterStyles);
Kind: static method of characterStyles