diff --git a/sample.canvas b/sample.canvas index 24a5902..51ab7bf 100644 --- a/sample.canvas +++ b/sample.canvas @@ -1,4 +1,5 @@ { + "$schema": "./schema.json", "nodes":[ {"id":"8132d4d894c80022","type":"file","file":"readme.md","x":-280,"y":-200,"width":570,"height":560,"color":"6"}, {"id":"7efdbbe0c4742315","type":"file","file":"_site/logo.svg","x":-280,"y":-440,"width":217,"height":80}, diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..3a9f10c --- /dev/null +++ b/schema.json @@ -0,0 +1,314 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "default": { + "edges": [], + "nodes": [] + }, + "properties": { + "edges": { + "description": "Edges are lines that connect one node to another", + "items": { + "$ref": "#/definitions/JSONCanvasEdge" + }, + "type": "array" + }, + "nodes": { + "description": "Nodes are objects within the canvas. Nodes may be text, files, links, or groups", + "items": { + "$ref": "#/definitions/JSONCanvasNode" + }, + "type": "array" + } + }, + "$defs": { + "JSONCanvasColor": { + "anyOf": [ + { + "description": "A color in hex format, e.g. #ff0000", + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "$ref": "#/definitions/JSONCanvasColorPreset" + } + ] + }, + "JSONCanvasColorPreset": { + "title": "A preset color.", + "description": "Six preset colors exist, mapped to the following numbers:\n1 red\n2 orange\n3 yellow\n4 green\n5 cyan\n6 purple", + "enum": ["1", "2", "3", "4", "5", "6"], + "type": "string" + }, + "JSONCanvasEdge": { + "additionalProperties": false, + "properties": { + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "fromNode": { + "description": "The ID of the node that the edge starts from", + "type": "string" + }, + "fromSide": { + "description": "The side of the node that the edge connects from", + "$ref": "#/definitions/JSONCanvasEdgeSide" + }, + "id": { + "description": "The ID for the edge", + "type": "string" + }, + "label": { + "description": "The text label for the edge", + "type": "string" + }, + "toEnd": { + "$ref": "#/definitions/JSONCanvasEdgeEnd" + }, + "toNode": { + "description": "The ID of the node that the edge ends at", + "type": "string" + }, + "toSide": { + "description": "The side of the node that the edge connects to", + "$ref": "#/definitions/JSONCanvasEdgeSide" + } + }, + "required": ["id", "fromNode", "toNode"], + "type": "object" + }, + "JSONCanvasEdgeEnd": { + "description": "The rendering style of the end of the edge line", + "enum": ["none", "arrow"], + "type": "string" + }, + "JSONCanvasEdgeSide": { + "description": "The side of the node that the edge connects to", + "enum": ["top", "right", "bottom", "left"], + "type": "string" + }, + "JSONCanvasFileNode": { + "additionalProperties": false, + "properties": { + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "file": { + "description": "The path to the file within the system", + "type": "string", + "minLength": 1 + }, + "height": { + "description": "The height of the node in pixels", + "type": "integer" + }, + "id": { + "description": "Unique ID for the node", + "type": "string" + }, + "subpath": { + "description": "The subpath that may link to a heading or a block. Always starts with a #", + "type": "string" + }, + "type": { + "description": "The node type", + "const": "file", + "type": "string" + }, + "width": { + "description": "The width of the node in pixels", + "type": "integer" + }, + "x": { + "description": "The x position of the node in pixels", + "type": "integer" + }, + "y": { + "description": "The y position of the node in pixels", + "type": "integer" + } + }, + "required": ["file", "height", "id", "type", "width", "x", "y"], + "type": "object" + }, + "JSONCanvasGroupNode": { + "additionalProperties": false, + "properties": { + "background": { + "description": "The path to the background image", + "type": "string" + }, + "backgroundStyle": { + "title": "The rendering style of a background image.", + "description": "Options are:\ncover - fills the entire width and height of the node.\nratio - maintains the aspect ratio of the background image.\nrepeat - repeats the image as a pattern in both x/y directions.", + "enum": ["cover", "ratio", "repeat"], + "type": "string" + }, + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "height": { + "description": "The height of the node in pixels", + "type": "integer" + }, + "id": { + "description": "Unique ID for the node", + "type": "string" + }, + "label": { + "description": "The text label for the group", + "type": "string" + }, + "type": { + "description": "The node type", + "const": "group", + "type": "string" + }, + "width": { + "description": "The width of the node in pixels", + "type": "integer" + }, + "x": { + "description": "The x position of the node in pixels", + "type": "integer" + }, + "y": { + "description": "The y position of the node in pixels", + "type": "integer" + } + }, + "required": ["height", "id", "type", "width", "x", "y"], + "type": "object" + }, + "JSONCanvasLinkNode": { + "additionalProperties": false, + "properties": { + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "height": { + "description": "The height of the node in pixels", + "type": "integer" + }, + "id": { + "description": "Unique ID for the node", + "type": "string" + }, + "type": { + "description": "The node type", + "const": "link", + "type": "string" + }, + "url": { + "type": "string" + }, + "width": { + "description": "The width of the node in pixels", + "type": "number" + }, + "x": { + "description": "The x position of the node in pixels", + "type": "number" + }, + "y": { + "description": "The y position of the node in pixels", + "type": "integer" + } + }, + "required": ["height", "id", "type", "url", "width", "x", "y"], + "type": "object" + }, + "JSONCanvasNode": { + "anyOf": [ + { + "$ref": "#/definitions/JSONCanvasNodeGeneric" + }, + { + "$ref": "#/definitions/JSONCanvasTextNode" + }, + { + "$ref": "#/definitions/JSONCanvasFileNode" + }, + { + "$ref": "#/definitions/JSONCanvasLinkNode" + }, + { + "$ref": "#/definitions/JSONCanvasGroupNode" + } + ] + }, + "JSONCanvasNodeGeneric": { + "additionalProperties": false, + "properties": { + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "height": { + "description": "The height of the node in pixels", + "type": "integer" + }, + "id": { + "description": "Unique ID for the node", + "type": "string" + }, + "type": { + "description": "The node type", + "enum": ["text", "file", "link", "group"], + "type": "string" + }, + "width": { + "description": "The width of the node in pixels", + "type": "integer" + }, + "x": { + "description": "The x position of the node in pixels", + "type": "integer" + }, + "y": { + "description": "The y position of the node in pixels", + "type": "integer" + } + }, + "required": ["id", "type", "x", "y", "width", "height"], + "type": "object" + }, + "JSONCanvasTextNode": { + "additionalProperties": false, + "properties": { + "color": { + "$ref": "#/definitions/JSONCanvasColor" + }, + "height": { + "description": "The height of the node in pixels", + "type": "number" + }, + "id": { + "description": "Unique ID for the node", + "type": "string" + }, + "text": { + "description": "Plain text with Markdown syntax", + "type": "string" + }, + "type": { + "description": "The node type", + "const": "text", + "type": "string" + }, + "width": { + "description": "The width of the node in pixels", + "type": "number" + }, + "x": { + "description": "The x position of the node in pixels", + "type": "number" + }, + "y": { + "description": "The y position of the node in pixels", + "type": "number" + } + }, + "required": ["height", "id", "text", "type", "width", "x", "y"], + "type": "object" + } + } +}