{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://draggable.co.uk/template.schema.json",
  "title": "Draggable template",
  "description": "A diagram for https://draggable.co.uk. Give boxes and connections only (no x/y) and Draggable lays the diagram out itself. See https://draggable.co.uk/llms.txt.",
  "type": "object",
  "required": ["boxes"],
  "properties": {
    "name": { "type": "string", "maxLength": 64, "description": "Name shown in the template list." },
    "title": { "type": "string", "description": "Heading drawn above the diagram (simple mode)." },
    "subtitle": { "type": "string", "description": "Line under the heading (simple mode)." },
    "layout": { "enum": ["down", "right"], "description": "Direction of the flow in simple mode. Ignored when lanes are used." },
    "lanes": {
      "description": "Swimlanes, top to bottom. Optional: lanes named on boxes are created automatically.",
      "type": "array",
      "items": {
        "anyOf": [
          { "type": "string" },
          {
            "type": "object",
            "required": ["name"],
            "properties": { "name": { "type": "string" }, "color": { "type": "string", "description": "CSS colour for the lane." } }
          }
        ]
      }
    },
    "boxes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id"],
        "properties": {
          "id": { "type": "string", "description": "Unique id; connections refer to it." },
          "text": { "type": "string", "description": "The wording in the box. Keep it short." },
          "shape": {
            "description": "Kind of step. Friendly names (first group) or short keys (second group).",
            "enum": [
              "process", "start", "end", "decision", "input", "output", "database", "document", "subprocess",
              "preparation", "manual", "delay", "offpage", "note", "cloud", "ellipse", "triangle", "arrow", "text",
              "rect", "pill", "diamond", "para", "hex", "cyl", "doc", "sub", "trap"
            ]
          },
          "lane": { "type": "string", "description": "Swimlane this box belongs to." },
          "x": { "type": "number", "description": "Exact mode only. Omit for automatic layout." },
          "y": { "type": "number", "description": "Exact mode only. Omit for automatic layout." },
          "width": { "type": "number", "minimum": 1 },
          "height": { "type": "number", "minimum": 1 },
          "color": { "type": "string", "description": "Fill, any CSS colour. Omit for the standard colours." },
          "textColor": { "type": "string" },
          "fontSize": { "type": "number", "minimum": 8, "maximum": 72 },
          "bold": { "type": "boolean" },
          "borderWidth": { "type": "number", "minimum": 0, "maximum": 12 },
          "borderColor": { "type": "string" },
          "borderDash": { "type": "boolean" },
          "alignH": { "enum": ["left", "center", "right"] },
          "alignV": { "enum": ["top", "middle", "bottom"] },
          "zIndex": { "type": "integer" },
          "locked": { "type": "boolean", "description": "Background box that cannot be clicked; lines pass over it." },
          "background": { "type": "boolean", "description": "A background box unlocked for editing; Draggable offers to re-lock it. Use locked when creating." },
          "container": { "type": "boolean", "description": "Frame that carries the boxes inside it when dragged." }
        }
      }
    },
    "tours": {
      "description": "Exact mode only: recorded walkthroughs played while presenting, one per scenario. Each frame is [seconds, cx, cy, w, h]: the time from the start, and the centre and size of the area in view, in canvas units. Times never go backwards; the view moves smoothly between frames.",
      "type": "array",
      "items": { "$ref": "#/$defs/tour" }
    },
    "tour": { "$ref": "#/$defs/tour", "description": "Older templates: a single tour. Read as a tours list of one." },
    "connections": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["from", "to"],
        "properties": {
          "from": { "type": "string", "description": "Id of the box the line starts at." },
          "to": { "type": "string", "description": "Id of the box the arrow points to." },
          "label": { "type": "string", "maxLength": 80 },
          "style": { "enum": ["elbow", "straight", "curve"] },
          "dash": { "type": "boolean" },
          "color": { "type": "string" },
          "width": { "type": "integer", "minimum": 1, "maximum": 8 },
          "arrow": { "type": "boolean", "description": "Arrowhead at the end. Default true." },
          "arrowStart": { "type": "boolean" },
          "fromSide": { "enum": ["T", "R", "B", "L"] },
          "toSide": { "enum": ["T", "R", "B", "L"] },
          "labelAt": { "type": "number", "minimum": 0.05, "maximum": 0.95 },
          "z": { "type": "integer", "description": "Its layer among the lines: higher is drawn on top. Leave out for the usual layer, where lines with a label are drawn above lines without." },
          "bends": { "description": "Corners of a hand-routed elbow line, as \"x1,y1 x2,y2 …\" or a list of {x, y}. Leave out for automatic routing.", "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "object", "properties": { "x": { "type": "number" }, "y": { "type": "number" } } } }] }
        }
      }
    }
  },
  "$defs": {
    "tour": {
      "type": "object",
      "required": ["frames"],
      "properties": {
        "name": { "type": "string", "maxLength": 64, "description": "What the tour walks through, e.g. the scenario." },
        "focus": { "enum": ["shape"], "description": "During playback, the shape in the middle of the view glows, to draw the eye to it." },
        "path": { "enum": ["lines"], "description": "Between views, travel along the connector lines from the shape at one view to the shape at the next, instead of straight across." },
        "pace": { "enum": ["even"], "description": "Play every glide at one steady speed, timed by the distance it covers, instead of the recorded times. Pauses keep their length." },
        "frames": {
          "type": "array",
          "minItems": 2,
          "items": { "type": "array", "minItems": 5, "maxItems": 5, "items": { "type": "number" } }
        }
      }
    }
  }
}
