npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

photoshop-script-api

v1.0.4

Published

photoshop script api 此项目旨在实现一套完整的API,用来封装photoshop插件开发过程中,宿主提供的能力合集。

Readme

photoshop-script-api

中文

About

When develop CEP Panels in Photoshop, we use Javascript DOM API to communicate with the host, It's easily understood and used, but insufficient interfaces offered to accomplish complex works. There is another way call "Action Descriptor" which is more powerful and comprehensive, while extremely confusing to learn and use.

This project wraps the AM codes and build a friendly use js api to offer powerful and sufficient interfaces for Photoshop plugin development.

install

This project is written in TypeScript. If you use ts in your codes, just clone this project and import the source code as you want.

Typescript

import the index.ts file in your project

import { Document } from "./photoshop-script-api/src/index";

const doc = new Document();
$.writeln(doc.name());

Javascript

In plain javascript way, you can install the npm module which has been compiled and published.

install the module from npm

npm install photoshop-script-api

include the main.js file in your code

#include "./node_modules/photoshop-script-api/dist/main.js"

var a = new $.Application();
alert(a.version());

usages

Classes

This module includes some Classes listed below

  1. Application
  2. Document
  3. Layer
  4. Artboard
  5. History
  6. Rect
  7. Selection
  8. Shape
  9. Size
  10. Color
  11. Stroke
  12. MetaData
  13. ...

more will be added in future

in order to avoid namespace conflict, all class names are prefixed with "$", so you can use them like this

var app = new $.Application();

each Class offers some useful api to make things happen, you can check out the code to get more detail.

below snippets are some simple examples to demonstrate how to use the api

Application

Application indicates the Photoshop application itself, it offers some useful api to get the application information

var theApp = new $.Application();

// open a file
theApp.open("/path/to/a/file");

// get the host version
theApp.getHostVersion();    // CC2022

// get the host installation path
theApp.getApplicationPath();       // /Applications/Adobe Photoshop 2022/Adobe Photoshop 2022.app

Documents

Document indicates the opened document in Photoshop, it offers some useful api to get the document information

// get current active document
var doc = $.Document.activeDocument();
if (doc == null) {
    alert("no doucment opened");
    return;
}
alert(doc.name());  // alert document name
$.writeln(doc.length());    // document size in bytes
doc.trim(); // trim document transparent area

Layer

Layer indicates the layer in Photoshop, it helps you to manipulate the layer easily.


// get selected layers
var layers = $.Layer.getSelectedLayers();
for (var i=0; i<layers.length; i++) {
    var layer = layers[i];
    $.writeln(layer.name());    // layer name
    $.writeln(layer.index());    // layer index
}

var layer = $.Layer.getLayerByIndex(10);
layer.setName('an awesome name');   // set a new name for layer
var bounds = layer.getBounds();   // get the postion & size of the layer
var size = bounds.size();
$.writeln(size.toString());  // 200 x 100  ( output layer size)

layer.hide();   // hide the layer
layer.show();   // show the layer
layer.select(); // set select the layer
layer.toSelection();    // create a selection with the layer bounds
layer.rasterize();    // rasterize the layer

// you can also use codes like jQuery
layer.selct().toSelection().hide();

Selection

Selection indicates the selection in Photoshop. You can create or get the selection and manipulate it.

// create a selection
var bounds = new $.Rect(100, 100, 100, 100);
var selection = new $.Selection(bounds);
selection.create();

Canvas

Canvas makes easy to draw shapes in document

// we create a canvas to hold shapes
var canvas = new $.Canvas();

// create a circle
var circle = new $.Circle(new Point(100, 100), 50);
// create a rectangle
var rect = new $.Rect(100, 100, 100, 100);
// create a line
var line = new $.Line(new Point(100, 100), new Point(200, 200));
// add shappe to canvas
canvas.add(circle);
canvas.add(rect);
canvas.add(line);

// we set the color of the shape
canvas.setFillColor($.SolidColor.fromHexString("#ff5c5c"));
// we paint
canvas.paint();

Guide

Guide wraps the guide api in Photoshop, it helps you to create or remove guides easily.

// create a guide
$.Guide.add({position: 10, direction: 'horizontal'});
// get all guides
var guides = $.Guide.all();
for (var i=0; i<guides.length; i++) {
    var guide = guides[i];
    $.writeln(guide.position());
    $.writeln(guide.direction());
}

History

History offers some useful api to manipulate the history stack in Photoshop.

// step backword
History.previous();
// go to the history state
History.go(3);

// save the current history state
// and do your stuff, then restore the history state
History.saveState();
// do your stuff here...
History.restoreState();

other classes are similar to use, you can check out the code to get more detail.

if any questions, please post an issue.

About Me

Ten years Software Engineer from China, former Senior Engineer of Baidu Inc. Head in web, mobile, media development, in love with design. Have several welcome products for designers in China.

Design Mirror - The best preview tool

Cutterman - Assets expoter