{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getkribble.com/spec/drawing.schema.json",
  "title": "Kribble drawing scene",
  "description": "A drawing's or a diagram's scene, as a document holds it (spec/drawing.md). Elements are in stacking order: later ones on top. Readers ignore fields and element types they don't know, so objects allow more than is listed.",
  "type": "object",
  "properties": {
    "elements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/element"
      },
      "description": "The elements, in stacking order: later on top."
    },
    "background": {
      "type": "string",
      "default": "#ffffff",
      "description": "The canvas colour (renderers in a dark theme may ignore it)."
    },
    "height": {
      "type": "number",
      "description": "The block's height in the note, in CSS pixels (absent: the editor's default)."
    }
  },
  "$defs": {
    "point": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        }
      },
      "required": [
        "x",
        "y"
      ]
    },
    "binding": {
      "type": "object",
      "description": "What a line's end is attached to.",
      "properties": {
        "elementId": {
          "type": "string"
        },
        "focus": {
          "$ref": "#/$defs/point",
          "description": "The point aimed at, as a fraction of the element's box."
        },
        "bindCenter": {
          "$ref": "#/$defs/point",
          "description": "The element's centre when bound (legacy resolution)."
        },
        "gap": {
          "type": "number",
          "description": "The end sits this far outside the outline; the points are resolved."
        },
        "dy": {
          "type": "number",
          "description": "On a lifeline: this far below its top."
        }
      },
      "required": [
        "elementId",
        "focus",
        "bindCenter"
      ]
    },
    "arrowhead": {
      "enum": [
        "none",
        "arrow",
        "bar",
        "dot",
        "circle_outline",
        "triangle",
        "triangle_outline",
        "diamond",
        "diamond_outline"
      ]
    },
    "element": {
      "type": "object",
      "required": [
        "id",
        "type",
        "x",
        "y",
        "w",
        "h"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "description": "rect, ellipse, diamond, line, arrow, draw, text, image, or a diagram shape (spec/drawing.md)."
        },
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        },
        "w": {
          "type": "number"
        },
        "h": {
          "type": "number"
        },
        "stroke": {
          "type": "string",
          "description": "A CSS colour, or auto for the theme's ink."
        },
        "fill": {
          "type": "string",
          "description": "A CSS colour, or none."
        },
        "strokeWidth": {
          "type": "number"
        },
        "strokeStyle": {
          "enum": [
            "solid",
            "dashed",
            "dotted"
          ]
        },
        "opacity": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "rounded": {
          "type": "boolean"
        },
        "text": {
          "type": "string",
          "description": "The label or text, as typed."
        },
        "wrapped": {
          "type": "string",
          "description": "The text as the editor laid it out, with the line breaks of wrapping, when wrapping broke a line. Renderers draw this (else text), splitting on \\n only."
        },
        "fontSize": {
          "type": "number"
        },
        "fontFamily": {
          "enum": [
            "sans",
            "mono",
            "serif"
          ]
        },
        "weight": {
          "type": "number"
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ]
        },
        "valign": {
          "enum": [
            "top",
            "middle",
            "bottom"
          ]
        },
        "angle": {
          "type": "number",
          "default": 0
        },
        "fillStyle": {
          "enum": [
            "solid",
            "hachure",
            "cross-hatch"
          ],
          "default": "solid"
        },
        "roughness": {
          "enum": [
            0,
            1,
            2
          ],
          "default": 0
        },
        "groupIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "locked": {
          "type": "boolean"
        },
        "key": {
          "type": "string",
          "description": "Diagram blocks: the part of the text it comes from."
        },
        "cells": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "abstract": {
          "type": "boolean"
        },
        "dividers": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "laneSizes": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "head": {
          "enum": [
            "box",
            "actor"
          ]
        },
        "gaps": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "points": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 2,
            "maxItems": 3
          }
        },
        "start": {
          "anyOf": [
            {
              "$ref": "#/$defs/binding"
            },
            {
              "type": "null"
            }
          ]
        },
        "end": {
          "anyOf": [
            {
              "$ref": "#/$defs/binding"
            },
            {
              "type": "null"
            }
          ]
        },
        "route": {
          "enum": [
            "straight",
            "curved",
            "elbow"
          ],
          "default": "straight"
        },
        "startArrowhead": {
          "$ref": "#/$defs/arrowhead"
        },
        "endArrowhead": {
          "$ref": "#/$defs/arrowhead"
        },
        "startLabel": {
          "type": "string"
        },
        "endLabel": {
          "type": "string"
        },
        "labelAt": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "selfLoop": {
          "type": "boolean"
        },
        "routed": {
          "type": "boolean"
        },
        "pen": {
          "type": "number",
          "description": "Freehand outline algorithm: absent for the original, 2 for the current one."
        },
        "autoResize": {
          "type": "boolean",
          "default": true
        },
        "src": {
          "type": "string",
          "description": "Images: an uploaded file or a data: URL."
        }
      }
    }
  }
}
