Socket
Socket
Sign inDemoInstall

blackprint-interpreter

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    blackprint-interpreter


Version published
Maintainers
1
Created

Readme

Source

Blackprint

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

9lM3o2Trur

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

FAQs

Last updated on 15 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc