diff --git a/jsoncanvas.schema.json b/jsoncanvas.schema.json new file mode 100644 index 0000000..ba68bb7 --- /dev/null +++ b/jsoncanvas.schema.json @@ -0,0 +1,163 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/JsonCanvas", + "definitions": { + "JsonCanvas": { + "type": "object", + "properties": { + "nodes": { + "type": "array", + "items": { + "$ref": "#/definitions/CanvasNode" + } + }, + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/Edge" + } + } + }, + "additionalProperties": false, + "description": "Top-level interface for the JSON Canvas Spec" + }, + "CanvasNode": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "text", + "file", + "link", + "group" + ] + }, + "x": { + "type": "number" + }, + "y": { + "type": "number" + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + }, + "color": { + "$ref": "#/definitions/CanvasColor" + } + }, + "required": [ + "id", + "type", + "x", + "y", + "width", + "height" + ], + "additionalProperties": false, + "description": "Base node interface for common attributes" + }, + "CanvasColor": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "number", + "const": 1 + }, + { + "type": "number", + "const": 2 + }, + { + "type": "number", + "const": 3 + }, + { + "type": "number", + "const": 4 + }, + { + "type": "number", + "const": 5 + }, + { + "type": "number", + "const": 6 + } + ], + "description": "Type for color, either a string for hex values or a number for preset colors" + }, + "Edge": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "fromNode": { + "type": "string" + }, + "fromSide": { + "type": "string", + "enum": [ + "top", + "right", + "bottom", + "left" + ], + "description": "Optional side of the node where the edge starts" + }, + "fromEnd": { + "type": "string", + "enum": [ + "none", + "arrow" + ], + "description": "Optional style of the edge end" + }, + "toNode": { + "type": "string" + }, + "toSide": { + "type": "string", + "enum": [ + "top", + "right", + "bottom", + "left" + ], + "description": "Optional side of the node where the edge ends" + }, + "toEnd": { + "type": "string", + "enum": [ + "none", + "arrow" + ], + "description": "Optional style of the edge end" + }, + "color": { + "$ref": "#/definitions/CanvasColor" + }, + "label": { + "type": "string", + "description": "Optional label for the edge" + } + }, + "required": [ + "id", + "fromNode", + "toNode" + ], + "additionalProperties": false, + "description": "Edge interface for connections between nodes" + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..4690034 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,118 @@ +/** + * Top-level interface for the JSON Canvas Spec + */ +export interface JsonCanvas { + nodes?: CanvasNode[]; + edges?: Edge[]; +} + +export default JsonCanvas; + +/** + * Base node interface for common attributes + */ +export interface CanvasNode { + id: string; + type: "text" | "file" | "link" | "group"; + x: number; + y: number; + width: number; + height: number; + color?: CanvasColor; +} + +/** + * Extended node interface for TextNode type + */ +export interface TextNode extends CanvasNode { + type: "text"; + /** + * Text content with Markdown syntax + */ + text: string; +} + +/** + * Extended node interface for FileNode type + */ +export interface FileNode extends CanvasNode { + type: "file"; + /** + * Path to the file + */ + file: string; + /** + * Optional subpath within the file + */ + subpath?: string; +} + +/** + * Extended node interface for LinkNode type + */ +export interface LinkNode extends CanvasNode { + type: "link"; + /** + * URL the node references + */ + url: string; +} + +/** + * Extended node interface for GroupNode type + */ +export interface GroupNode extends CanvasNode { + type: "group"; + /** + * Optional text label for the group + */ + label?: string; + /** + * Optional path to a background image + */ + background?: string; + /** + * Optional rendering style of the background + */ + backgroundStyle?: "cover" | "ratio" | "repeat"; +} + +/** + * Union type for all node types + */ +export type AllNodes = TextNode | FileNode | LinkNode | GroupNode; + +/** + * Edge interface for connections between nodes + */ +export interface Edge { + id: string; + fromNode: string; + /** + * Optional side of the node where the edge starts + */ + fromSide?: "top" | "right" | "bottom" | "left"; + /** + * Optional style of the edge end + */ + fromEnd?: "none" | "arrow"; + toNode: string; + /** + * Optional side of the node where the edge ends + */ + toSide?: "top" | "right" | "bottom" | "left"; + /** + * Optional style of the edge end + */ + toEnd?: "none" | "arrow"; + color?: CanvasColor; + /** + * Optional label for the edge + */ + label?: string; +} + +/** + * Type for color, either a string for hex values or a number for preset colors + */ +export type CanvasColor = string | 1 | 2 | 3 | 4 | 5 | 6;