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.
Blackprint.Interpreter.registerInterface('logger', function(self, bind){
var myLog = '...';
bind({
get log(){
return myLog;
},
set log(val){
myLog = val;
console.log(val);
}
});
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.
Blackprint.Interpreter.registerNode('myspace/button', function(handle, node){
node.type = 'button';
node.title = "My simple button";
handle.onclicked = function(ev){
console.log("Henlo", ev);
}
});
Node handler registration
var instance = new Blackprint.Interpreter();
var node = instance.createNode('math/multiply', {});
instance.clearNodes();
instance.importJSON();
Example
This repository provide an example with the JSON too, and you can try it with Node.js or Deno:
$ git clone --depth 1 https://github.com/Blackprint/interpreter-js .
$ npm i
$ node ./example/init.js