README
Blackprint Interpreter for JavaScript
Run exported Blackprint on any JavaScript environment.
This repository is designed to be used together with Blackprint as the interpreter on the Browser, Node.js, Deno, and other JavaScript environment.
Documentation
Warning: This project haven't reach it stable version (semantic versioning at v1.0.0)
The available API is similar with Blackprint.Sketch The documentation here only write the different API
Register new node interface type
An interface is designed for communicate the node handler with the JavaScript's runtime API. Because there're no HTML to be controlled, this would be little different with the browser version.
// -> (node identifier, callback)
Blackprint.Interpreter.registerInterface('logger', function(self, bind){
// `bind` is used for bind `self` property with a function
// And polyfill for ScarletsFrame element binding system
var myLog = '...';
bind({
get log(){
return myLog;
},
set log(val){
myLog = val;
console.log(val);
}
});
// After that, you can get/set from `self` like a normal property
// self.log === '...';
// In the self object, it simillar with: https://github.com/Blackprint/Blackprint
self.clickMe = function(){...}
});
Node handler registration
This is where we register our logic with Blackprint.
If you already have the browser version, you can just copy it without changes.
It should be compatible if it's not accessing any Browser API.
// -> (namespace, callback)
Blackprint.Interpreter.registerNode('myspace/button', function(handle, node){
// Use node handler from instance.registerInterface('button')
node.type = 'button';
node.title = "My simple button";
// Called after `.button` have been clicked
handle.onclicked = function(ev){
console.log("Henlo", ev);
}
});
Node handler registration
// Create Blackprint Interpreter instance, `instance` in this documentation will refer to this
var instance = new Blackprint.Interpreter();
// Example: Create new node (after registration)
var node = instance.createNode('math/multiply', {/* node options */});
// Clear all nodes on this instance
instance.clearNodes();
// Example: Import nodes from JSON (after registration)
instance.importJSON(/* JSON || Object */);
Example

This repository provide an example with the JSON too, and you can try it with Node.js or Deno:
# Change your working directory into empty folder first
$ git clone --depth 1 https://github.com/Blackprint/interpreter-js .
$ npm i
$ node ./example/init.js