Giter VIP home page Giter VIP logo

sketchapi's Introduction

Sketch API — Alpha

This is a prototype Javascript API for Sketch. It's still a work in progress, but the intention is to make something which is:

  • native Javascript
  • an easily understandable subset of the full internals of Sketch
  • fully supported by Bohemian between releases (ie we try not to change it, unlike our internal API which we can and do change whenever we need to)
  • still allows you to drop down to our internal API when absolutely necessary.

The idea is to keep this API as lean-and-mean as possible. The main reason for that is that if we (Bohemian) are committing ourselves to making sure that we don't break it, then it's essential that doing so doesn't become an unmanageable task.

The API would be a very core layer which interfaces with Sketch itself. Even with the small amount that I've done so far, I can definitely see the temptation to broaden the API and add lots of convenience methods and/or higher-level code that builds on the API. I think that's something that we should do as a community, but it makes sense to try to keep it separate from the core API effort. — @samdeane

api layers

There's no reason why we couldn't maintain two libraries, and have the utilities one only work with calls to the api one. That could have a lot more community input, and as long as it just calls the API, it should stay stable (if the API does!).

Again, this is very much a work in progress, so comments and suggestions for this API are welcome - send them to [email protected], or open an issue to have a public discussion.

Install

The API comes bundled inside Sketch, so no installation is required.

Usage

Example script:

var sketch = context.api()

log(sketch.api_version)
log(sketch.version)
log(sketch.build)
log(sketch.full_version)


var document = sketch.frontDocument;
var selection = document.selection;
var page = document.selectedPage;

var group = page.newGroup({frame:sketch.rectangle(0, 0, 100, 100), name:"Test"});
var rect = group.newShape({frame:sketch.rectangle(10, 10, 80, 80)});

log(selection.is_empty());
selection.iterate(function(item) { log(item.name); } );

selection.clear();
log(selection.is_empty());

group.select();
rect.add_to_selection();

sketch.input("Test", "default");
sketch.select("Test", ["One", "Two"], 1);
sketch.message("Hello mum!");
sketch.alert("Title", "message");

Acknowledgements

We would like to thank:

  • Andrey Shakhmin, for his inspiration during the Hamburg Hackathon, where he showed us how to use node modules inside Sketch.
  • The Sketch plugin community everywhere, for such awesome work.

Development

If you want to build the library locally, you need to run this on the project's root folder (this assumes you already have node installed):

npm install -g gulp
npm install

Once that's ready, you can run:

gulp

to compile the library. By default, it will be saved to ../SketchPluginManager/Source/SketchAPI.js. You can specify your own output path by using the --output argument:

gulp --output Output/SketchAPI.js

To have Sketch use the .js file you just built, you can run this:

defaults write com.bohemiancoding.sketch3 SketchAPILocation "/path/to/SketchAPI.js"

and Sketch will load the external .js file instead of the bundled version.

Testing

TBD

sketchapi's People

Contributors

samdeane avatar bomberstudios avatar kgn avatar

Watchers

mntz avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.