WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ type RenditionResult = {
outputFile: File;
}

type DocumentInfo = {
/**
* Document name as displayed in the titlebar. For untitled documents, this will be a localized string such as "Untitled-1."
*/
name: string,
/**
* *Semi*-unique document identifier. Duplicating an .xd file on disk will result in two files with the same GUID. Duplicating a document via "Save As" will change its GUID; thus two *cloud* documents will never have the same GUID. The GUID of an Untitled document doesn't change when it is saved for the first time. <br><br>This returns the same value as `scenegraph.root.guid`.
*/
guid: string
};

/**
* Generate renditions of nodes in the document in a batch. Overwrites any existing files without warning.
*
Expand All @@ -72,3 +83,21 @@ export const appLanguage: string;
* User's OS-wide locale setting. May not match the XD UI, since XD does not support all world languages. Includes both language and region (e.g. "fr_CA" or "en_US").
*/
export const systemLocale: string;

/**
* Information about the document which this instance of the plugin is attached to.
*
* > **Tip**
* >
* > _This does **not** indicate the frontmost "active" document window in the XD application._
* >
* > In XD, each document window loads a separate copy of your plugin. When a given instance of your plugin calls this API, you will always receive information about the document that this instance of the plugin is attached to, even if it's not the active window.
*
* @example ```js
let application = require("application");
let documentInfo = application.activeDocument;
console.log("Document title: " + documentInfo.name);
console.log("Document ID: " + documentInfo.guid);
```
*/
export const activeDocument: DocumentInfo;
29 changes: 20 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Artboard, SceneNode} from "./scenegraph";
import {Artboard, SceneNode} from "scenegraph";

declare global {
/**
Expand All @@ -7,7 +7,7 @@ declare global {
*/
function require(module: string): void;

let module: {exports:any};
let module: { exports: any };

/**
* The selection object represents the currently selected set of nodes in the UI. You can set the selection to use it as input for commands, or to determine what is left selected for the user when your plugin’s edit operation completes.
Expand Down Expand Up @@ -37,26 +37,37 @@ declare global {
/**
* Array representing the current selection plus any locked items that the user has attempted to select.
*/
itemsIncludingLocked: Array<SceneNode>;
readonly itemsIncludingLocked: Array<SceneNode>;
/**
* True if the selection isn’t empty and consists of one or more non-Artboards. Never true at the same time as hasArtboards.
*/
hasArtwork: boolean;
readonly hasArtwork: boolean;
/**
* True if the selection isn’t empty and consists of one or more Artboards. Never true at the same time as hasArtwork.
*/
hasArtboards: boolean;
readonly hasArtboards: boolean;
/**
* The context in which selection and edit operations must occur. If the user hasn’t drilled into any container node, this value is the document root, and its scope includes all immediate children of the pasteboard (including Artboards), and all immediate children of all those Artboards.
*/
editContext: SceneNode;
readonly editContext: SceneNode;
/**
* The preferred parent to insert newly added content into. Takes into account the current edit context as well as the “focused artboard” if in the root context.
* The preferred parent to insert newly added content into. Takes into account the current edit context as well as the "focused artboard" if in the root context.
Typically this is the same parent where, for example, XD's shape drawing tools would add items.
*
* _Selected items are not necessarily all immediate children of the `insertionParent`._ They can be anywhere within the [edit context's](/reference/core/edit-context.md) scope.
*/
insertionParent: SceneNode;
readonly insertionParent: SceneNode;
/**
* The artboard the user is currently most focused on (via recent selection or edit operations). May be null, for example if no artboards exist or if the user just deleted an artboard.
*/
focusedArtboard: Artboard | null | undefined;
readonly focusedArtboard: Artboard | null | undefined;

/**
* Returns true if the node is accessible for editing in the scope of the current edit context.
* If false, the node cannot be edited given the user's current selection.
* Nodes that are currently selected are always in the current edit context.
* @param node
*/
isInEditContext(node: SceneNode): boolean;
}
}
4 changes: 3 additions & 1 deletion types/interactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const homeArtboard: Artboard | null;
*
* May include interactions that are impossible to trigger because the trigger node (or one of its ancestors) has `visible` = false.
*
* Note: currently, this API excludes all of the document's keyboard/gamepad interactions.
* > **Tip**
* >
* > Currently, this API excludes some types of interactions: keypress/gamepad, scrolling, hover, component state transitions, or non-speech audio playback.
*/
export const allInteractions: Array<{ triggerNode: SceneNode, interactions: Array<Interaction> }>;

Expand Down
125 changes: 125 additions & 0 deletions types/scenegraph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,122 @@ declare interface ScaleFactor {
scaleY: number;
}

/**
* (**Since:** XD 29)
*
* Stores metadata accessible to multiple plugins, separated into silos by plugin ID. Your plugin can read & write the storage for its own plugin ID, but storage for other plugin IDs is *read-only*.
*
* Each per-plugin storage silo is a collection of key-value pairs. Keys and values must both be strings.
*
* *Each* scenenode has its own metadata storage, accessed via `SceneNode.sharedPluginData`. To store general metadata that is not specific to one scenenode, use `sharedPluginData` on the document's scenegraph root.
* @example ```js
* // This example shows how to save & retrieve rich JSON data in shared metadata storage.
// See below for simpler examples of using individual APIs.
const PLUGIN_ID = "<your manifest's plugin ID here>";
let richObject = {
list: [2, 4, 6],
name: "Hello world"
};
node.sharedPluginData.setItem(PLUGIN_ID, "richData", JSON.stringify(richObject));

// Later on...
// (This could be in a different plugin, if it passes the original plugin's ID here)
let jsonString = node.sharedPluginData.getItem(PLUGIN_ID, "richData");
if (jsonString) { // may be undefined
let richObjectCopy = JSON.parse(jsonString);
console.log(richObjectCopy.list.length); // 3
}
*/
declare interface PerPluginStorage {
/**
* Returns a map where key is plugin ID and value is a nested map containing all the shared metadata for that plugin ID (i.e. the result of calling `getForPluginId()` with that ID).
*/
getAll(): { [key: string]: {[key:string]: string} };

/**
* Returns a map of key-value string pairs containing all shared metadata stored on this node by the given plugin. May be an empty object (zero keys), but is never null.
*
* This map is a clone of the stored metadata, so modifying it has no effect.
* @param pluginId
*
* @example
*const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
let mySharedMetadata = node.sharedPluginData.getForPluginId(MY_PLUGIN_ID);
console.log("My shared 'foo' & 'bar' values:",
mySharedMetadata.foo, mySharedMetadata.bar);


console.log("Plugin B's shared 'foo' value:",
node.sharedPluginData.getForPluginId("B").foo);
*/
getForPluginId(pluginId: string): {[key:string]: string};

/**
* Returns a list of all keys stored on this node by the given plugin. May be empty (length zero), but is never null.
* @param pluginId
*
* @example
* console.log("All properties stored by plugin A on this node:",
node.sharedPluginData.keys("A"));
*/
keys(pluginId: string): string[];

/**
* Returns the value stored under the given key on this node by the given plugin, or `undefined` if the plugin hasn't stored anything under the given key.
*
* Because metadata is stored separately per plugin, two plugins can store two different values under the same key.
* @param pluginId
* @param key
*
* @example
* // These are two different values, stored independently per plugin
console.log("Plugin A's 'foo' value:", node.sharedPluginData.getItem("A", "foo"));
console.log("Plugin B's 'foo' value:", node.sharedPluginData.getItem("B", "foo"));
*/
getItem(pluginId: string, key: string): string | undefined;

/**
* Set a metadata key which can be read by any other plugin.
* @param pluginId *Must* be equal to your plugin's ID.
* @param key
* @param value If undefined, behaves as if you'd called `removeItem()` instead.
*
* @example
const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");

node.sharedPluginData.setItem("other_plugin_id", "foo", "42");
// ^ ERROR: other plugin's metadata is read-only

console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"
*/
setItem(pluginId: string, key: string, value: string | undefined): void;

/**
* Clears a shared metadata key stored by your plugin.
* @param pluginId *Must* be equal to your plugin's ID.
* @param key
* @example
const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");
console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"

node.sharedPluginData.removeItem(MY_PLUGIN_ID, "foo");
console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // undefined
*/
removeItem(pluginId: string, key:string): void;

/**
* Provided for convenience: you can `console.log(node.sharedPluginData)` to see the value of `getAll()`.
*/
toString(): string;

/**
* Provided for convenience: you can include a `PerPluginStorage` object inside data you are going to convert to JSON, even though it is not a plain JavaScript object. Returns the same value as `getAll()`.
*/
toJSON(): object;
}

/**
* Represents the children of a scenenode. Typically accessed via the SceneNode.children property.
*/
Expand Down Expand Up @@ -319,6 +435,15 @@ export class ImageFill {
*/
scaleBehaviour: string;

// TODO: assetId: string (readonly?)
/**
* (**Since**: XD 29)
*
* A unique identifier for the image asset used by this ImageFill. May be shared by other ImageFills, including those with different cropping, size,
rotation, or mirroring. If identical images are imported into XD from separate sources, they may have different `assetId`s however.
*/
assetId: string;

/**
* Format the image data was originally encoded in, such as `image/gif` or `image/jpeg`.
*/
Expand Down