commit: f22b6d798fd9ba4e60c39d6681cbfec0fd854330
parent 5f4e6342eb7ccfa22e7b5bcbb9a9257c89121a7c
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Tue, 8 Jan 2019 15:23:48 +1200
Standardized
Diffstat:
10 files changed, 344 insertions(+), 420 deletions(-)
diff --git a/scripts/database/recipes.js b/scripts/database/recipes.js
@@ -2221,4 +2221,4 @@ CRACKERS
Black sesame seeds : 1 tbsp
Flax seeds : 1 tbsp
-`
-\ No newline at end of file
+`
diff --git a/scripts/lib/riven.graph.js b/scripts/lib/riven.graph.js
@@ -1,250 +1,229 @@
-function Riven_Graph()
-{
- Riven.call(this);
+function Riven_Graph () {
+ Riven.call(this)
var GRID_SIZE = 20
- this.el = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+ this.el = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
document.body.appendChild(this.el)
-
- this.graph = function()
- {
- var html = "";
- for(id in this.network){
- var node = this.network[id];
- html += draw_routes(node);
+
+ this.graph = function () {
+ var html = ''
+ for (id in this.network) {
+ var node = this.network[id]
+ html += draw_routes(node)
}
- for(id in this.network){
- var node = this.network[id];
- html += draw_node(node);
+ for (id in this.network) {
+ var node = this.network[id]
+ html += draw_node(node)
}
- this.el.innerHTML = html;
+ this.el.innerHTML = html
}
- function draw_routes(node)
- {
- var html = "";
- for(id in node.ports){
+ function draw_routes (node) {
+ var html = ''
+ for (id in node.ports) {
var port = node.ports[id]
- var pos = port ? get_port_position(port) : {x:0,y:0}
- for(route_id in port.routes){
- var route = port.routes[route_id];
- if(!route){ continue; }
- html += route ? draw_connection(port,route) : ""
+ var pos = port ? get_port_position(port) : { x: 0, y: 0 }
+ for (route_id in port.routes) {
+ var route = port.routes[route_id]
+ if (!route) { continue }
+ html += route ? draw_connection(port, route) : ''
}
}
return `<g id='routes'>${html}</g>`
}
- function draw_node(node)
- {
- var rect = get_rect(node);
+ function draw_node (node) {
+ var rect = get_rect(node)
return `
<g class='node ${node.is_mesh ? 'mesh' : ''}' id='node_${node.id}'>
- <rect rx='2' ry='2' x=${rect.x} y=${rect.y-(GRID_SIZE/2)} width="${rect.w}" height="${rect.h}" class='${node.children.length == 0 ? "fill" : ""}'/>
- <text x="${rect.x+(rect.w/2)}" y="${rect.y+rect.h+(GRID_SIZE/2)}">${node.label}</text>
+ <rect rx='2' ry='2' x=${rect.x} y=${rect.y - (GRID_SIZE / 2)} width="${rect.w}" height="${rect.h}" class='${node.children.length == 0 ? 'fill' : ''}'/>
+ <text x="${rect.x + (rect.w / 2)}" y="${rect.y + rect.h + (GRID_SIZE / 2)}">${node.label}</text>
${draw_ports(node)}
${draw_glyph(node)}
</g>`
}
- function draw_ports(node)
- {
- var html = "";
- for(id in node.ports){
- html += draw_port(node.ports[id]);
+ function draw_ports (node) {
+ var html = ''
+ for (id in node.ports) {
+ html += draw_port(node.ports[id])
}
return html
}
- function draw_glyph(node)
- {
- var rect = get_rect(node);
- return !node.is_mesh && node.glyph ? `<path class='glyph' transform="translate(${rect.x+(GRID_SIZE/4)},${rect.y-(GRID_SIZE/4)}) scale(0.1)" d='${node.glyph}'/>` : ""
+ function draw_glyph (node) {
+ var rect = get_rect(node)
+ return !node.is_mesh && node.glyph ? `<path class='glyph' transform="translate(${rect.x + (GRID_SIZE / 4)},${rect.y - (GRID_SIZE / 4)}) scale(0.1)" d='${node.glyph}'/>` : ''
}
- function draw_port(port)
- {
- var pos = port ? get_port_position(port) : {x:0,y:0}
- return `<g id='${port.host.id}_port_${port.id}'>${(port.type == PORT_TYPES.request || port.type == PORT_TYPES.answer)? `<path d='${draw_diamond(pos)}' class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? "route" : ""}' />` : `<circle cx='${pos.x}' cy="${pos.y}" r="${parseInt(GRID_SIZE/6)}" class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? "route" : ""}'/>`}</g>`
+ function draw_port (port) {
+ var pos = port ? get_port_position(port) : { x: 0, y: 0 }
+ return `<g id='${port.host.id}_port_${port.id}'>${(port.type == PORT_TYPES.request || port.type == PORT_TYPES.answer) ? `<path d='${draw_diamond(pos)}' class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}' />` : `<circle cx='${pos.x}' cy="${pos.y}" r="${parseInt(GRID_SIZE / 6)}" class='port ${port.type} ${port.host.ports[id] && port.host.ports[id].route ? 'route' : ''}'/>`}</g>`
}
- function draw_connection(a,b,type)
- {
- if(is_bidirectional(a.host,b.host)){
- return a.type != PORT_TYPES.output ? draw_connection_bidirectional(a,b) : ""
+ function draw_connection (a, b, type) {
+ if (is_bidirectional(a.host, b.host)) {
+ return a.type != PORT_TYPES.output ? draw_connection_bidirectional(a, b) : ''
}
-
- return a.type == PORT_TYPES.output ? draw_connection_output(a,b) : draw_connection_request(a,b)
+
+ return a.type == PORT_TYPES.output ? draw_connection_output(a, b) : draw_connection_request(a, b)
}
- function is_bidirectional(a,b)
- {
- for(id in a.ports.output.routes){
+ function is_bidirectional (a, b) {
+ for (id in a.ports.output.routes) {
var route_a = a.ports.output.routes[id]
- for(id in a.ports.request.routes){
+ for (id in a.ports.request.routes) {
var route_b = a.ports.request.routes[id]
- if(route_a.host.id == route_b.host.id){
- return true;
+ if (route_a.host.id == route_b.host.id) {
+ return true
}
}
}
return false
}
- function draw_connection_output(a,b)
- {
+ function draw_connection_output (a, b) {
var pos_a = get_port_position(a)
var pos_b = get_port_position(b)
- var pos_m = middle(pos_a,pos_b)
- var pos_c1 = {x:(pos_m.x+(pos_a.x+GRID_SIZE))/2,y:pos_a.y}
- var pos_c2 = {x:(pos_m.x+(pos_b.x-GRID_SIZE))/2,y:pos_b.y}
+ var pos_m = middle(pos_a, pos_b)
+ var pos_c1 = { x: (pos_m.x + (pos_a.x + GRID_SIZE)) / 2, y: pos_a.y }
+ var pos_c2 = { x: (pos_m.x + (pos_b.x - GRID_SIZE)) / 2, y: pos_b.y }
- var path = ""
+ var path = ''
- path += `M${pos_a.x},${pos_a.y} L${pos_a.x+GRID_SIZE},${pos_a.y} `
+ path += `M${pos_a.x},${pos_a.y} L${pos_a.x + GRID_SIZE},${pos_a.y} `
path += `Q${pos_c1.x},${pos_c1.y} ${pos_m.x},${pos_m.y} `
- path += `Q ${pos_c2.x},${pos_c2.y} ${pos_b.x-GRID_SIZE},${pos_b.y}`
+ path += `Q ${pos_c2.x},${pos_c2.y} ${pos_b.x - GRID_SIZE},${pos_b.y}`
path += `L${pos_b.x},${pos_b.y}`
return `<path d="${path}" class='route output'/>
<circle cx='${pos_m.x}' cy='${pos_m.y}' r='2' fill='white'></circle>`
}
- function draw_connection_request(a,b)
- {
+ function draw_connection_request (a, b) {
var pos_a = get_port_position(a)
var pos_b = get_port_position(b)
- var pos_m = middle(pos_a,pos_b)
- var pos_c1 = {x:pos_a.x,y:(pos_m.y+(pos_a.y+GRID_SIZE))/2}
- var pos_c2 = {x:pos_b.x,y:(pos_m.y+(pos_b.y-GRID_SIZE))/2}
+ var pos_m = middle(pos_a, pos_b)
+ var pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 }
+ var pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 }
- var path = ""
+ var path = ''
- path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y+GRID_SIZE} `
+ path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y + GRID_SIZE} `
path += `Q${pos_c1.x},${pos_c1.y} ${pos_m.x},${pos_m.y} `
- path += `Q ${pos_c2.x},${pos_c2.y} ${pos_b.x},${pos_b.y-GRID_SIZE}`
+ path += `Q ${pos_c2.x},${pos_c2.y} ${pos_b.x},${pos_b.y - GRID_SIZE}`
path += `L${pos_b.x},${pos_b.y}`
return `<path d="${path}" class='route request'/>
<circle cx='${pos_m.x}' cy='${pos_m.y}' r='2' fill='white'></circle>`
}
- function draw_connection_bidirectional(a,b)
- {
+ function draw_connection_bidirectional (a, b) {
var pos_a = get_port_position(a)
var pos_b = get_port_position(b)
- var pos_m = middle(pos_a,pos_b)
- var pos_c1 = {x:pos_a.x,y:(pos_m.y+(pos_a.y+GRID_SIZE))/2}
- var pos_c2 = {x:pos_b.x,y:(pos_m.y+(pos_b.y-GRID_SIZE))/2}
+ var pos_m = middle(pos_a, pos_b)
+ var pos_c1 = { x: pos_a.x, y: (pos_m.y + (pos_a.y + GRID_SIZE)) / 2 }
+ var pos_c2 = { x: pos_b.x, y: (pos_m.y + (pos_b.y - GRID_SIZE)) / 2 }
- var path = ""
+ var path = ''
- path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y+GRID_SIZE} `
+ path += `M${pos_a.x},${pos_a.y} L${pos_a.x},${pos_a.y + GRID_SIZE} `
path += `L${pos_a.x},${pos_m.y} L${pos_b.x},${pos_m.y}`
- path += `L${pos_b.x},${pos_b.y-GRID_SIZE} L${pos_b.x},${pos_b.y}`
+ path += `L${pos_b.x},${pos_b.y - GRID_SIZE} L${pos_b.x},${pos_b.y}`
return `<path d="${path}" class='route bidirectional'/>`
}
-
- function draw_diamond(pos)
- {
- var r = GRID_SIZE/6
- return `M${pos.x-(r)},${pos.y} L${pos.x},${pos.y-(r)} L${pos.x+(r)},${pos.y} L${pos.x},${pos.y+(r)} Z`
+
+ function draw_diamond (pos) {
+ var r = GRID_SIZE / 6
+ return `M${pos.x - (r)},${pos.y} L${pos.x},${pos.y - (r)} L${pos.x + (r)},${pos.y} L${pos.x},${pos.y + (r)} Z`
}
- function get_port_position(port)
- {
+ function get_port_position (port) {
var rect = get_rect(port.host)
- var offset = {x:0,y:0}
- if(port.type == PORT_TYPES.output){
- offset = {x:GRID_SIZE*2,y:GRID_SIZE/2}
- }
- else if(port.type == PORT_TYPES.input){
- offset = {x:0,y:GRID_SIZE/2}
- }
- else if(port.type == PORT_TYPES.answer){
- offset = {x:GRID_SIZE,y:-GRID_SIZE*0.5}
- }
- else if(port.type == PORT_TYPES.request){
- offset = {x:GRID_SIZE,y:GRID_SIZE*1.5}
+ var offset = { x: 0, y: 0 }
+ if (port.type == PORT_TYPES.output) {
+ offset = { x: GRID_SIZE * 2, y: GRID_SIZE / 2 }
+ } else if (port.type == PORT_TYPES.input) {
+ offset = { x: 0, y: GRID_SIZE / 2 }
+ } else if (port.type == PORT_TYPES.answer) {
+ offset = { x: GRID_SIZE, y: -GRID_SIZE * 0.5 }
+ } else if (port.type == PORT_TYPES.request) {
+ offset = { x: GRID_SIZE, y: GRID_SIZE * 1.5 }
}
- return {x:rect.x+offset.x,y:rect.y+offset.y}
+ return { x: rect.x + offset.x, y: rect.y + offset.y }
}
- function get_rect(node)
- {
+ function get_rect (node) {
var rect = node.rect
- var x = node.rect.x * GRID_SIZE;
- var y = node.rect.y * GRID_SIZE;
- var w = node.rect.w * GRID_SIZE;
- var h = node.rect.h * GRID_SIZE;
-
- if(node.parent){
- var offset = get_rect(node.parent);
- x += offset.x;
- y += offset.y;
+ var x = node.rect.x * GRID_SIZE
+ var y = node.rect.y * GRID_SIZE
+ var w = node.rect.w * GRID_SIZE
+ var h = node.rect.h * GRID_SIZE
+
+ if (node.parent) {
+ var offset = get_rect(node.parent)
+ x += offset.x
+ y += offset.y
}
- return {x:x,y:y,w:w,h:h}
+ return { x: x, y: y, w: w, h: h }
}
- function distance(a,b)
- {
- return Math.sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) );
+ function distance (a, b) {
+ return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
}
- function diagonal(a,b)
- {
+ function diagonal (a, b) {
return a.x == b.x || a.y == b.y || a.y - a.x == b.y - b.x || b.y - a.x == a.y - b.x
}
- function middle(a,b)
- {
- return {x:(a.x+b.x)/2,y:(a.y+b.y)/2}
+ function middle (a, b) {
+ return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }
}
// Cursor
this.cursor = {
- host:null,
- el:document.createElement("cursor"),
- pos:{x:0,y:0},
- offset:{x:0,y:0},
- origin:null,
- install: function(host){
- this.host = host;
+ host: null,
+ el: document.createElement('cursor'),
+ pos: { x: 0, y: 0 },
+ offset: { x: 0, y: 0 },
+ origin: null,
+ install: function (host) {
+ this.host = host
document.body.appendChild(this.el)
- document.addEventListener('mousedown',(e)=>{ this.touch({x:e.clientX,y:e.clientY},true); e.preventDefault(); });
- document.addEventListener('mousemove',(e)=>{ this.touch({x:e.clientX,y:e.clientY},false); e.preventDefault(); });
- document.addEventListener('mouseup', (e)=>{ this.touch({x:e.clientX,y:e.clientY}); e.preventDefault(); });
+ document.addEventListener('mousedown', (e) => { this.touch({ x: e.clientX, y: e.clientY }, true); e.preventDefault() })
+ document.addEventListener('mousemove', (e) => { this.touch({ x: e.clientX, y: e.clientY }, false); e.preventDefault() })
+ document.addEventListener('mouseup', (e) => { this.touch({ x: e.clientX, y: e.clientY }); e.preventDefault() })
},
- update: function(){
- this.host.el.style.left = `${parseInt(this.offset.x)}px`;
- this.host.el.style.top = `${parseInt(this.offset.y)}px`;
- document.body.style.backgroundPosition = `${parseInt(this.offset.x/2)}px ${parseInt(this.offset.y/2)}px`;
+ update: function () {
+ this.host.el.style.left = `${parseInt(this.offset.x)}px`
+ this.host.el.style.top = `${parseInt(this.offset.y)}px`
+ document.body.style.backgroundPosition = `${parseInt(this.offset.x / 2)}px ${parseInt(this.offset.y / 2)}px`
},
- touch: function(pos,click = null){
- if(click == true){
- this.origin = pos;
- return;
+ touch: function (pos, click = null) {
+ if (click == true) {
+ this.origin = pos
+ return
}
- if(this.origin){
- this.offset.x += (pos.x - this.origin.x)/2;
- this.offset.y += (pos.y - this.origin.y)/2;
- this.update();
- this.origin = pos;
+ if (this.origin) {
+ this.offset.x += (pos.x - this.origin.x) / 2
+ this.offset.y += (pos.y - this.origin.y) / 2
+ this.update()
+ this.origin = pos
}
- if(click == null){
- this.origin = null;
- return;
+ if (click == null) {
+ this.origin = null
+ return
}
- this.pos = pos;
+ this.pos = pos
},
- magnet: function(val){
- return (parseInt(val/GRID_SIZE)*GRID_SIZE)+(GRID_SIZE/2);
+ magnet: function (val) {
+ return (parseInt(val / GRID_SIZE) * GRID_SIZE) + (GRID_SIZE / 2)
}
}
- this.cursor.install(this);
+ this.cursor.install(this)
}
diff --git a/scripts/lib/riven.js b/scripts/lib/riven.js
@@ -1,163 +1,144 @@
// "Don't forget, the portal combination's in my journal."" — Catherine
-function Riven()
-{
+function Riven () {
this.network = {}
}
// QUERY
-function Ø(s,network = RIVEN.network)
-{
- var id = s.toLowerCase();
- if(id.indexOf(" ") > -1){
- var node_id = id.split(" ")[0];
- var port_id = id.split(" ")[1];
- return network[node_id] && network[node_id].ports[port_id] ? network[node_id].ports[port_id] : null;
- }
- else if(network[id]){
- return network[id];
- }
- else{
- return new Node(id);
+function Ø (s, network = RIVEN.network) {
+ var id = s.toLowerCase()
+ if (id.indexOf(' ') > -1) {
+ var node_id = id.split(' ')[0]
+ var port_id = id.split(' ')[1]
+ return network[node_id] && network[node_id].ports[port_id] ? network[node_id].ports[port_id] : null
+ } else if (network[id]) {
+ return network[id]
+ } else {
+ return new Node(id)
}
}
// NODE
-function Node(id,rect={x:0,y:0,w:2,h:2})
-{
- this.id = id;
+function Node (id, rect = { x: 0, y: 0, w: 2, h: 2 }) {
+ this.id = id
this.ports = {}
- this.rect = rect;
- this.parent = null;
- this.children = [];
- this.label = id;
-
- this.setup = function()
- {
- this.ports.input = new Port(this,"in",PORT_TYPES.input)
- this.ports.output = new Port(this,"out",PORT_TYPES.output)
- this.ports.answer = new Port(this,"answer",PORT_TYPES.answer)
- this.ports.request = new Port(this,"request",PORT_TYPES.request)
+ this.rect = rect
+ this.parent = null
+ this.children = []
+ this.label = id
+
+ this.setup = function () {
+ this.ports.input = new Port(this, 'in', PORT_TYPES.input)
+ this.ports.output = new Port(this, 'out', PORT_TYPES.output)
+ this.ports.answer = new Port(this, 'answer', PORT_TYPES.answer)
+ this.ports.request = new Port(this, 'request', PORT_TYPES.request)
}
- this.create = function(pos = {x:0,y:0},type = Node,...params)
- {
- var node = new type(this.id,rect,...params)
+ this.create = function (pos = { x: 0, y: 0 }, type = Node, ...params) {
+ var node = new type(this.id, rect, ...params)
this.rect.x = pos.x
this.rect.y = pos.y
- node.setup();
+ node.setup()
RIVEN.network[node.id] = node
return node
}
- this.mesh = function(pos,n)
- {
- var node = new Mesh(this.id,pos)
+ this.mesh = function (pos, n) {
+ var node = new Mesh(this.id, pos)
node.rect.x = pos.x
node.rect.y = pos.y
- node.setup();
+ node.setup()
RIVEN.network[node.id] = node
- if(n instanceof Array){
- for(id in n){
- n[id].parent = node;
- node.children.push(n[id]);
- node.update();
+ if (n instanceof Array) {
+ for (id in n) {
+ n[id].parent = node
+ node.children.push(n[id])
+ node.update()
}
+ } else {
+ n.parent = node
+ node.children.push(n)
+ node.update()
}
- else{
- n.parent = node;
- node.children.push(n);
- node.update();
- }
- return node;
+ return node
}
// Connect
- this.connect = function(q,type = ROUTE_TYPES.output)
- {
- if(q instanceof Array){
- for(id in q){
- this.connect(q[id],type)
+ this.connect = function (q, type = ROUTE_TYPES.output) {
+ if (q instanceof Array) {
+ for (id in q) {
+ this.connect(q[id], type)
}
- }
- else{
- this.ports[type == ROUTE_TYPES.request ? "request" : "output"].connect(`${q} ${type == ROUTE_TYPES.request ? "answer" : "input"}`,type);
+ } else {
+ this.ports[type == ROUTE_TYPES.request ? 'request' : 'output'].connect(`${q} ${type == ROUTE_TYPES.request ? 'answer' : 'input'}`, type)
}
}
- this.syphon = function(q)
- {
- this.connect(q,ROUTE_TYPES.request)
+ this.syphon = function (q) {
+ this.connect(q, ROUTE_TYPES.request)
}
- this.bind = function(q)
- {
+ this.bind = function (q) {
this.connect(q)
this.syphon(q)
}
// Target
- this.signal = function(target)
- {
- for(port_id in this.ports){
+ this.signal = function (target) {
+ for (port_id in this.ports) {
var port = this.ports[port_id]
- for(route_id in port.routes){
- var route = port.routes[route_id];
- if(!route || !route.host || route.host.id != target.toLowerCase()){ continue; }
+ for (route_id in port.routes) {
+ var route = port.routes[route_id]
+ if (!route || !route.host || route.host.id != target.toLowerCase()) { continue }
return route.host
}
}
- return null;
+ return null
}
// SEND/RECEIVE
- this.send = function(payload)
- {
- for(route_id in this.ports.output.routes){
- var route = this.ports.output.routes[route_id];
- if(!route){ continue; }
+ this.send = function (payload) {
+ for (route_id in this.ports.output.routes) {
+ var route = this.ports.output.routes[route_id]
+ if (!route) { continue }
route.host.receive(payload)
}
}
-
- this.receive = function(q)
- {
+
+ this.receive = function (q) {
var port = this.ports.output
- for(route_id in port.routes){
- var route = port.routes[route_id];
- if(route){
- route.host.receive(q)
+ for (route_id in port.routes) {
+ var route = port.routes[route_id]
+ if (route) {
+ route.host.receive(q)
}
}
}
- this.bang = function()
- {
+ this.bang = function () {
this.send(true)
}
// REQUEST/ANSWER
- this.answer = function(q)
- {
+ this.answer = function (q) {
return this.request(q)
}
- this.request = function(q)
- {
- var payload = {};
- for(route_id in this.ports.request.routes){
- var route = this.ports.request.routes[route_id];
- if(!route){ continue; }
+ this.request = function (q) {
+ var payload = {}
+ for (route_id in this.ports.request.routes) {
+ var route = this.ports.request.routes[route_id]
+ if (!route) { continue }
var answer = route.host.answer(q)
- if(!answer){ continue; }
+ if (!answer) { continue }
payload[route.host.id] = answer
}
return payload
@@ -165,58 +146,54 @@ function Node(id,rect={x:0,y:0,w:2,h:2})
// PORT
- function Port(host,id,type = PORT_TYPES.default)
- {
- this.host = host;
- this.id = id;
- this.type = type;
- this.routes = [];
+ function Port (host, id, type = PORT_TYPES.default) {
+ this.host = host
+ this.id = id
+ this.type = type
+ this.routes = []
- this.connect = function(b,type = "transit")
- {
+ this.connect = function (b, type = 'transit') {
this.routes.push(Ø(b))
}
}
// MESH
- function Mesh(id,rect)
- {
- Node.call(this,id,rect);
+ function Mesh (id, rect) {
+ Node.call(this, id, rect)
- this.is_mesh = true;
+ this.is_mesh = true
- this.setup = function(){}
+ this.setup = function () {}
- this.update = function()
- {
- var bounds = {x:0,y:0};
- for(id in this.children){
- var node = this.children[id];
+ this.update = function () {
+ var bounds = { x: 0, y: 0 }
+ for (id in this.children) {
+ var node = this.children[id]
bounds.x = node.rect.x > bounds.x ? node.rect.x : bounds.x
bounds.y = node.rect.y > bounds.y ? node.rect.y : bounds.y
}
- this.rect.w = bounds.x+4;
- this.rect.h = bounds.y+5;
+ this.rect.w = bounds.x + 4
+ this.rect.h = bounds.y + 5
}
}
}
-var PORT_TYPES = {default:"default",input:"input",output:"output",request:"request",answer:"answer"}
-var ROUTE_TYPES = {default:"default",request:"request"}
+var PORT_TYPES = { default: 'default', input: 'input', output: 'output', request: 'request', answer: 'answer' }
+var ROUTE_TYPES = { default: 'default', request: 'request' }
var NODE_GLYPHS = {
- default: "M150,60 L150,60 L60,150 L150,240 L240,150 Z",
- router:"M60,120 L60,120 L150,120 L240,60 M60,150 L60,150 L240,150 M60,180 L60,180 L150,180 L240,240",
- parser:"M60,60 L60,60 L240,60 M120,120 A30,30 0 0,1 150,150 M150,150 A30,30 0 0,0 180,180 M180,180 L180,180 L240,180 M120,120 L120,120 L60,120 M60,240 L60,240 L240,240 M240,120 L240,120 L180,120 M60,180 L60,180 L120,180",
- entry:"M60,150 L60,150 L240,150 L240,150 L150,240 M150,60 L150,60 L240,150",
- bang:"M150,60 L150,60 L150,180 M150,240 L150,240 L150,240",
- value:"M60,60 L60,60 L240,60 L240,240 L60,240 Z M60,150 L60,150 L240,150",
- equal:"M60,60 L60,60 L240,60 M60,120 L60,120 L240,120 M60,180 L60,180 L240,180 M60,240 L60,240 L240,240",
- render:"M60,60 L60,60 L240,60 L240,240 L60,240 Z M240,150 L240,150 L150,150 L150,240",
- database:"M60,60 L60,60 L240,60 L240,240 L60,240 Z M120,120 L120,120 L180,120 M120,180 L120,180 L180,180 M120,150 L120,150 L180,150",
- cache:"M60,60 L60,60 L240,60 L240,240 L60,240 Z",
- builder:"M60,60 L60,60 L150,120 L240,120 M60,150 L60,150 L240,150 M60,240 L60,240 L150,180 L240,180",
- selector:"M90,60 L90,60 L60,60 L60,90 M60,210 L60,210 L60,240 L90,240 M210,240 L210,240 L240,240 L240,210 M240,90 L240,90 L240,60 L210,60",
- dom: "M150,60 L150,60 L60,150 L150,240 L240,150 Z",
- template: "M150,60 L150,60 L240,150 L150,240 L60,150 Z M120,150 L120,150 L180,150 M150,120 L150,120 L150,180",
-}
-\ No newline at end of file
+ default: 'M150,60 L150,60 L60,150 L150,240 L240,150 Z',
+ router: 'M60,120 L60,120 L150,120 L240,60 M60,150 L60,150 L240,150 M60,180 L60,180 L150,180 L240,240',
+ parser: 'M60,60 L60,60 L240,60 M120,120 A30,30 0 0,1 150,150 M150,150 A30,30 0 0,0 180,180 M180,180 L180,180 L240,180 M120,120 L120,120 L60,120 M60,240 L60,240 L240,240 M240,120 L240,120 L180,120 M60,180 L60,180 L120,180',
+ entry: 'M60,150 L60,150 L240,150 L240,150 L150,240 M150,60 L150,60 L240,150',
+ bang: 'M150,60 L150,60 L150,180 M150,240 L150,240 L150,240',
+ value: 'M60,60 L60,60 L240,60 L240,240 L60,240 Z M60,150 L60,150 L240,150',
+ equal: 'M60,60 L60,60 L240,60 M60,120 L60,120 L240,120 M60,180 L60,180 L240,180 M60,240 L60,240 L240,240',
+ render: 'M60,60 L60,60 L240,60 L240,240 L60,240 Z M240,150 L240,150 L150,150 L150,240',
+ database: 'M60,60 L60,60 L240,60 L240,240 L60,240 Z M120,120 L120,120 L180,120 M120,180 L120,180 L180,180 M120,150 L120,150 L180,150',
+ cache: 'M60,60 L60,60 L240,60 L240,240 L60,240 Z',
+ builder: 'M60,60 L60,60 L150,120 L240,120 M60,150 L60,150 L240,150 M60,240 L60,240 L150,180 L240,180',
+ selector: 'M90,60 L90,60 L60,60 L60,90 M60,210 L60,210 L60,240 L90,240 M210,240 L210,240 L240,240 L240,210 M240,90 L240,90 L240,60 L210,60',
+ dom: 'M150,60 L150,60 L60,150 L150,240 L240,150 Z',
+ template: 'M150,60 L150,60 L240,150 L150,240 L60,150 Z M120,150 L120,150 L180,150 M150,120 L150,120 L150,180'
+}
diff --git a/scripts/nodes/database.js b/scripts/nodes/database.js
@@ -1,14 +1,12 @@
-function DatabaseNode(id,rect)
-{
- Node.call(this,id,rect);
+function DatabaseNode (id, rect) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.builder
- this.cache = null;
+ this.cache = null
- this.receive = function(q)
- {
- this.cache = this.cache ? this.cache : this.request();
+ this.receive = function (q) {
+ this.cache = this.cache ? this.cache : this.request()
this.send(this.request(this.cache))
}
-}
-\ No newline at end of file
+}
diff --git a/scripts/nodes/document.js b/scripts/nodes/document.js
@@ -1,11 +1,9 @@
-function DocumentNode(id,rect,...params)
-{
- Node.call(this,id,rect);
+function DocumentNode (id, rect, ...params) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.dom
-
- this.receive = function(content)
- {
+
+ this.receive = function (content) {
document.title = content.title
}
-}
-\ No newline at end of file
+}
diff --git a/scripts/nodes/indental.js b/scripts/nodes/indental.js
@@ -1,78 +1,70 @@
-function IndentalNode(id,rect,type)
-{
- Node.call(this,id,rect);
+function IndentalNode (id, rect, type) {
+ Node.call(this, id, rect)
- this.type = type;
+ this.type = type
this.glyph = NODE_GLYPHS.database
- this.answer = function(q)
- {
- if(!DATABASE[this.id]){
+ this.answer = function (q) {
+ if (!DATABASE[this.id]) {
console.warn(`Missing /database/${this.id}.js`)
- return null;
+ return null
}
- if(this.cache){
- return this.cache;
+ if (this.cache) {
+ return this.cache
}
- this.label = this.type ? `${this.id}=${this.type.name}` : `${this.id}`;
- this.cache = parse(DATABASE[this.id],this.type)
- return this.cache;
+ this.label = this.type ? `${this.id}=${this.type.name}` : `${this.id}`
+ this.cache = parse(DATABASE[this.id], this.type)
+ return this.cache
}
- function parse(data,type)
- {
- return build(data.split("\n").map(liner),type)
-
- function build(lines,type)
- {
+ function parse (data, type) {
+ return build(data.split('\n').map(liner), type)
+
+ function build (lines, type) {
// Assoc lines
var stack = {}
var target = lines[0]
- for(id in lines){
+ for (id in lines) {
var line = lines[id]
- if(line.skip){ continue; }
- target = stack[line.indent-2];
- if(target){ target.children.push(line) }
+ if (line.skip) { continue }
+ target = stack[line.indent - 2]
+ if (target) { target.children.push(line) }
stack[line.indent] = line
}
// Format
var h = {}
- for(id in lines){
- var line = lines[id];
- if(line.skip || line.indent > 0){ continue; }
+ for (id in lines) {
+ var line = lines[id]
+ if (line.skip || line.indent > 0) { continue }
var key = line.content.toUpperCase()
- h[key] = type ? new type(key,format(line)) : format(line)
+ h[key] = type ? new type(key, format(line)) : format(line)
}
return h
}
- function format(line)
- {
- var a = [];
- var h = {};
- for(id in line.children){
- var child = line.children[id];
- if(child.key){ h[child.key.toUpperCase()] = child.value }
- else if(child.children.length == 0 && child.content){ a.push(child.content) }
- else{ h[child.content.toUpperCase()] = format(child) }
+ function format (line) {
+ var a = []
+ var h = {}
+ for (id in line.children) {
+ var child = line.children[id]
+ if (child.key) { h[child.key.toUpperCase()] = child.value } else if (child.children.length == 0 && child.content) { a.push(child.content) } else { h[child.content.toUpperCase()] = format(child) }
}
return a.length > 0 ? a : h
}
- function liner(line)
- {
+ function liner (line) {
return {
- indent:line.search(/\S|$/),
- content:line.trim(),
- skip:line == "" || line.substr(0,1) == "~",
- key:line.indexOf(" : ") > -1 ? line.split(" : ")[0].trim() : null,
- value:line.indexOf(" : ") > -1 ? line.split(" : ")[1].trim() : null,
- children:[]
+ indent: line.search(/\S|$/),
+ content: line.trim(),
+ skip: line == '' || line.substr(0, 1) == '~',
+ key: line.indexOf(' : ') > -1 ? line.split(' : ')[0].trim() : null,
+ value: line.indexOf(' : ') > -1 ? line.split(' : ')[1].trim() : null,
+ children: []
}
}
}
}
-var DATABASE = {};
-\ No newline at end of file
+var DATABASE = {}
diff --git a/scripts/nodes/query.js b/scripts/nodes/query.js
@@ -1,54 +1,49 @@
-function QueryNode(id,rect)
-{
- Node.call(this,id,rect);
+function QueryNode (id, rect) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.entry
- this.label = "query"
+ this.label = 'query'
- this.bang = function(input = window.location.hash)
- {
+ this.bang = function (input = window.location.hash) {
var target = input.to_url() === '' ? 'home' : input.to_url()
- Ø("view").el.className = `${target.to_path()} loading`
-
+ Ø('view').el.className = `${target.to_path()} loading`
+
this.label = `${this.id}|${target}`
this.send(target)
- if(target === ''){
- window.history.replaceState(undefined, undefined, "#" + target)
- }
- else {
+ if (target === '') {
+ window.history.replaceState(undefined, undefined, '#' + target)
+ } else {
window.location.hash = target.to_url()
}
- setTimeout(()=>{ window.scrollTo(0,0); },250)
+ setTimeout(() => { window.scrollTo(0, 0) }, 250)
}
}
-var detectBackOrForward = function(onBack, onForward)
-{
- hashHistory = [window.location.hash];
- historyLength = window.history.length;
+var detectBackOrForward = function (onBack, onForward) {
+ hashHistory = [window.location.hash]
+ historyLength = window.history.length
- return function()
- {
- var hash = window.location.hash, length = window.history.length;
+ return function () {
+ var hash = window.location.hash; var length = window.history.length
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
- hashHistory = hashHistory.slice(0, -1);
- onBack();
+ hashHistory = hashHistory.slice(0, -1)
+ onBack()
} else {
- hashHistory.push(hash);
- onForward();
+ hashHistory.push(hash)
+ onForward()
}
} else {
- hashHistory.push(hash);
- historyLength = length;
+ hashHistory.push(hash)
+ historyLength = length
}
}
-};
+}
-window.addEventListener("hashchange", detectBackOrForward(
- function() { console.log("back"); Ø('query').bang() },
- function() { console.log("forward"); Ø('query').bang() }
-));
+window.addEventListener('hashchange', detectBackOrForward(
+ function () { console.log('back'); Ø('query').bang() },
+ function () { console.log('forward'); Ø('query').bang() }
+))
diff --git a/scripts/nodes/router.js b/scripts/nodes/router.js
@@ -1,39 +1,36 @@
-function RouterNode(id,rect)
-{
- Node.call(this,id,rect);
+function RouterNode (id, rect) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.router
- this.receive = function(q)
- {
- var target = q.indexOf(":") > -1 ? q.split(":")[0].replace(/\+/g," ") : q.replace(/\+/g," ")
- var params = q.indexOf(":") > -1 ? q.split(":")[1] : null
- var db = this.request("database").database;
- var data = find(target.toUpperCase(),db)
+ this.receive = function (q) {
+ var target = q.indexOf(':') > -1 ? q.split(':')[0].replace(/\+/g, ' ') : q.replace(/\+/g, ' ')
+ var params = q.indexOf(':') > -1 ? q.split(':')[1] : null
+ var db = this.request('database').database
+ var data = find(target.toUpperCase(), db)
this.label = `${this.id}|${target}|${params}`
- console.log(this.id,`${data ? data.type : '?'}->${target}[${params}]`);
+ console.log(this.id, `${data ? data.type : '?'}->${target}[${params}]`)
this.send({
- name:target,
- type:data ? data.type : null,
- result:data ? data.result : null,
- params:params,
- tables:db
+ name: target,
+ type: data ? data.type : null,
+ result: data ? data.result : null,
+ params: params,
+ tables: db
})
}
- function find(key,db)
- {
- if(parseInt(key) > 0){ return null; }
-
- for(id in db){
+ function find (key, db) {
+ if (parseInt(key) > 0) { return null }
+
+ for (id in db) {
var table = db[id]
- if(table[key]){
- return {type:id,result:table[key]}
+ if (table[key]) {
+ return { type: id, result: table[key] }
}
}
- return {type:null,result:null}
+ return { type: null, result: null }
}
-}
-\ No newline at end of file
+}
diff --git a/scripts/nodes/template.js b/scripts/nodes/template.js
@@ -1,22 +1,20 @@
-function TemplateNode(id,rect)
-{
- Node.call(this,id,rect);
+function TemplateNode (id, rect) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.parser
- this.cache = null;
+ this.cache = null
- this.receive = function(q)
- {
- var assoc = this.signal(q.type ? q.type.slice(0, -1) : "page");
+ this.receive = function (q) {
+ var assoc = this.signal(q.type ? q.type.slice(0, -1) : 'page')
var payload = assoc.answer(q)
this.send(payload)
this.label = `template:${assoc.id}`
-
+
// Install Dom
- document.body.appendChild(this.signal("view").answer())
+ document.body.appendChild(this.signal('view').answer())
- setTimeout(()=>{ Ø("view").el.className = `${q.name} ready` },250)
+ setTimeout(() => { Ø('view').el.className = `${q.name} ready` }, 250)
}
-}
-\ No newline at end of file
+}
diff --git a/scripts/templates/search.js b/scripts/templates/search.js
@@ -1,22 +1,20 @@
-function SearchTemplate(id,rect)
-{
- Node.call(this,id,rect);
+function SearchTemplate (id, rect) {
+ Node.call(this, id, rect)
this.glyph = NODE_GLYPHS.render
// Create the recipe body
- this.answer = function(q)
- {
- var html = ""
+ this.answer = function (q) {
+ var html = ''
return {
core: {
- content: "sup",
- related:"hello"
+ content: 'sup',
+ related: 'hello'
}
}
return html
}
-}
-\ No newline at end of file
+}