{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getkribble.com/spec/document.schema.json",
  "title": "Kribble Document, version 2",
  "description": "Generated from spec/registry.json by spec/generate.ts; don't edit. The canonical form writers produce: readers accept more (spec/document.md, Validation).",
  "type": "object",
  "properties": {
    "kribble": {
      "const": 2,
      "description": "The format version."
    },
    "blocks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/context_document"
      }
    }
  },
  "required": [
    "kribble",
    "blocks"
  ],
  "additionalProperties": false,
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^\\S+$",
      "description": "Unique in the document."
    },
    "paragraph": {
      "description": "A paragraph.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "paragraph"
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ],
          "default": "left",
          "description": "Text alignment."
        },
        "text": {
          "$ref": "#/$defs/text",
          "description": "The paragraph's text."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "heading": {
      "description": "A section heading.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "heading"
        },
        "level": {
          "enum": [
            1,
            2,
            3
          ],
          "default": 1,
          "description": "1 to 3."
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ],
          "default": "left",
          "description": "Text alignment."
        },
        "text": {
          "$ref": "#/$defs/text",
          "description": "The heading's text."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "code": {
      "description": "Preformatted code.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "code"
        },
        "language": {
          "type": "string",
          "default": "",
          "description": "The language it's written in, a lowercase name (typescript, go, bash, mermaid…); empty for none."
        },
        "filename": {
          "type": "string",
          "default": "",
          "description": "Shown as a title above the code; empty for none."
        },
        "code": {
          "type": "string",
          "default": "",
          "description": "The code: plain text, lines separated by \\n."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "quote": {
      "description": "A quotation.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "quote"
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_flow"
          },
          "description": "The quotation."
        }
      },
      "required": [
        "id",
        "type",
        "blocks"
      ],
      "additionalProperties": false
    },
    "callout": {
      "description": "A highlighted box.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "callout"
        },
        "tone": {
          "enum": [
            "info",
            "success",
            "warning",
            "danger"
          ],
          "default": "info",
          "description": "How it looks: a note, a tip, a warning, a danger."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_flow"
          },
          "description": "What it says."
        }
      },
      "required": [
        "id",
        "type",
        "blocks"
      ],
      "additionalProperties": false
    },
    "list": {
      "description": "A bulleted, numbered or task list.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "list"
        },
        "style": {
          "enum": [
            "bullet",
            "ordered",
            "task"
          ],
          "default": "bullet",
          "description": "Bullets, numbers or checkboxes."
        },
        "start": {
          "type": "integer",
          "minimum": 0,
          "default": 1,
          "description": "Ordered lists: the first item's number."
        },
        "moveChecked": {
          "type": "boolean",
          "default": false,
          "description": "Task lists: checked items move to the end."
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/listItem"
          },
          "minItems": 1,
          "description": "The items."
        }
      },
      "required": [
        "id",
        "type",
        "items"
      ],
      "additionalProperties": false
    },
    "table": {
      "description": "A table.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "table"
        },
        "columns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/tableColumn"
          },
          "description": "Column widths, set when someone resizes a column; empty for automatic layout."
        },
        "rows": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/tableRow"
          },
          "minItems": 1,
          "description": "The rows."
        }
      },
      "required": [
        "id",
        "type",
        "rows"
      ],
      "additionalProperties": false
    },
    "cards": {
      "description": "A grid of cards.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "cards"
        },
        "cards": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/card"
          },
          "minItems": 1,
          "description": "The cards."
        }
      },
      "required": [
        "id",
        "type",
        "cards"
      ],
      "additionalProperties": false
    },
    "tabs": {
      "description": "Tabs, one of which shows at a time. Only at the top level of a document.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "tabs"
        },
        "group": {
          "type": "string",
          "default": "",
          "description": "Tab groups with the same name switch together: picking a tab in one picks the tab with the same label in the others."
        },
        "tabs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/tab"
          },
          "minItems": 1,
          "description": "The tabs."
        }
      },
      "required": [
        "id",
        "type",
        "tabs"
      ],
      "additionalProperties": false
    },
    "columns": {
      "description": "Side-by-side columns.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "columns"
        },
        "columns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/column"
          },
          "minItems": 1,
          "description": "The columns, of equal width."
        }
      },
      "required": [
        "id",
        "type",
        "columns"
      ],
      "additionalProperties": false
    },
    "steps": {
      "description": "Numbered steps.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "steps"
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/step"
          },
          "minItems": 1,
          "description": "The steps, numbered in order."
        }
      },
      "required": [
        "id",
        "type",
        "steps"
      ],
      "additionalProperties": false
    },
    "accordion": {
      "description": "A section that opens and closes.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "accordion"
        },
        "title": {
          "$ref": "#/$defs/text",
          "description": "What shows when it's closed."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_layout"
          },
          "description": "What shows when it's open."
        }
      },
      "required": [
        "id",
        "type",
        "blocks"
      ],
      "additionalProperties": false
    },
    "image": {
      "description": "An image.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "image"
        },
        "src": {
          "type": "string",
          "format": "uri-reference",
          "description": "The image's address: an uploaded file (/files/…) or any URL."
        },
        "alt": {
          "type": "string",
          "default": "",
          "description": "Alternative text."
        }
      },
      "required": [
        "id",
        "type",
        "src"
      ],
      "additionalProperties": false
    },
    "video": {
      "description": "A video file, played in place.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "video"
        },
        "src": {
          "type": "string",
          "format": "uri-reference",
          "description": "The video file's address."
        },
        "name": {
          "type": "string",
          "default": "",
          "description": "The file name."
        }
      },
      "required": [
        "id",
        "type",
        "src"
      ],
      "additionalProperties": false
    },
    "file": {
      "description": "A file to download.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "file"
        },
        "src": {
          "type": "string",
          "format": "uri-reference",
          "description": "The file's address."
        },
        "name": {
          "type": "string",
          "default": "",
          "description": "The file name."
        },
        "size": {
          "type": "integer",
          "minimum": 0,
          "default": 0,
          "description": "Size in bytes; 0 when unknown."
        }
      },
      "required": [
        "id",
        "type",
        "src"
      ],
      "additionalProperties": false
    },
    "embed": {
      "description": "Embedded content from another site.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "embed"
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "The page to embed. Renderers with a web view show it; others show a link card, and play YouTube and Vimeo links where they can."
        }
      },
      "required": [
        "id",
        "type",
        "url"
      ],
      "additionalProperties": false
    },
    "divider": {
      "description": "A dividing line.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "divider"
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "fileTree": {
      "description": "A file and folder tree.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "fileTree"
        },
        "entries": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/fileEntry"
          },
          "description": "The top-level files and folders."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "drawing": {
      "description": "A drawing: shapes, arrows, freehand strokes, text and images.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "drawing"
        },
        "scene": {
          "$ref": "drawing.schema.json",
          "description": "The drawing (spec/drawing.md)."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "diagram": {
      "description": "A diagram made from text, laid out by the diagram engine.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "const": "diagram"
        },
        "kind": {
          "enum": [
            "flow",
            "sequence",
            "class"
          ],
          "default": "flow",
          "description": "The kind of diagram (spec/diagram-language.md)."
        },
        "source": {
          "type": "string",
          "default": "",
          "description": "The diagram text: the source of truth."
        },
        "layout": {
          "$ref": "#/$defs/diagramLayout",
          "description": "What the user changed by hand: positions of moved boxes, and the text the scene was last laid out from."
        },
        "scene": {
          "$ref": "drawing.schema.json",
          "description": "The drawing: the elements laid out from the text (they have keys) and any drawn next to them by hand (they don't)."
        }
      },
      "required": [
        "id",
        "type"
      ],
      "additionalProperties": false
    },
    "listItem": {
      "description": "A list item.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "checked": {
          "type": "boolean",
          "default": false,
          "description": "Task lists: whether it's done."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "prefixItems": [
            {
              "anyOf": [
                {
                  "$ref": "#/$defs/paragraph"
                },
                {
                  "$ref": "#/$defs/heading"
                }
              ]
            }
          ],
          "items": {
            "$ref": "#/$defs/context_flow"
          },
          "description": "The item's content: a paragraph or heading first, then any blocks (nested lists among them)."
        }
      },
      "required": [
        "id",
        "blocks"
      ],
      "additionalProperties": false
    },
    "tableColumn": {
      "description": "A table column's width.",
      "type": "object",
      "properties": {
        "width": {
          "type": "number",
          "minimum": 0,
          "description": "The column's width as a fraction of the table's; the widths add up to 1."
        }
      },
      "required": [
        "width"
      ],
      "additionalProperties": false
    },
    "tableRow": {
      "description": "A table row.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "cells": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/tableCell"
          },
          "minItems": 1,
          "description": "The cells."
        }
      },
      "required": [
        "id",
        "cells"
      ],
      "additionalProperties": false
    },
    "tableCell": {
      "description": "A table cell.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "header": {
          "type": "boolean",
          "default": false,
          "description": "A header cell."
        },
        "colspan": {
          "type": "integer",
          "minimum": 1,
          "default": 1,
          "description": "Columns it spans."
        },
        "rowspan": {
          "type": "integer",
          "minimum": 1,
          "default": 1,
          "description": "Rows it spans."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_cell"
          },
          "description": "The cell's content."
        }
      },
      "required": [
        "id",
        "blocks"
      ],
      "additionalProperties": false
    },
    "card": {
      "description": "A card.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "default": "",
          "description": "The card's title."
        },
        "description": {
          "type": "string",
          "default": "",
          "description": "The card's text."
        },
        "cover": {
          "type": "string",
          "format": "uri-reference",
          "default": "",
          "description": "A cover image's address; empty for none."
        },
        "href": {
          "type": "string",
          "format": "uri-reference",
          "default": "",
          "description": "Where it links to; empty for nowhere. A note takes precedence."
        },
        "note": {
          "type": "string",
          "default": "",
          "description": "The note it links to; empty for none."
        },
        "noteName": {
          "type": "string",
          "default": "",
          "description": "That note's name when linked, for readers that can't look it up."
        }
      },
      "required": [
        "id"
      ],
      "additionalProperties": false
    },
    "tab": {
      "description": "A tab.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "label": {
          "type": "string",
          "default": "Tab",
          "description": "The tab's label."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_tab"
          },
          "description": "The tab's content."
        }
      },
      "required": [
        "id",
        "blocks"
      ],
      "additionalProperties": false
    },
    "column": {
      "description": "A column.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_layout"
          },
          "description": "The column's content."
        }
      },
      "required": [
        "id",
        "blocks"
      ],
      "additionalProperties": false
    },
    "step": {
      "description": "A step.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "$ref": "#/$defs/text",
          "description": "The step's title."
        },
        "blocks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/context_layout"
          },
          "description": "The step's content."
        }
      },
      "required": [
        "id",
        "blocks"
      ],
      "additionalProperties": false
    },
    "fileEntry": {
      "description": "A file or folder in a file tree.",
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The file or folder name."
        },
        "dir": {
          "type": "boolean",
          "default": false,
          "description": "A folder."
        },
        "highlight": {
          "type": "boolean",
          "default": false,
          "description": "Highlighted (the file the text is about)."
        },
        "entries": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/fileEntry"
          },
          "description": "What's inside it."
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    },
    "diagramLayout": {
      "description": "A diagram's layout state.",
      "type": "object",
      "properties": {
        "positions": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/box"
          },
          "description": "Where boxes the user moved are, by element key (n:<name>): x, y, and w and h when the user sized them."
        },
        "drawnFrom": {
          "type": "string",
          "default": "",
          "description": "The text the scene was last laid out from, to recognise renames when the text changed elsewhere."
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "context_document": {
      "description": "The document's top level.",
      "anyOf": [
        {
          "$ref": "#/$defs/paragraph"
        },
        {
          "$ref": "#/$defs/heading"
        },
        {
          "$ref": "#/$defs/code"
        },
        {
          "$ref": "#/$defs/quote"
        },
        {
          "$ref": "#/$defs/callout"
        },
        {
          "$ref": "#/$defs/list"
        },
        {
          "$ref": "#/$defs/table"
        },
        {
          "$ref": "#/$defs/cards"
        },
        {
          "$ref": "#/$defs/tabs"
        },
        {
          "$ref": "#/$defs/columns"
        },
        {
          "$ref": "#/$defs/steps"
        },
        {
          "$ref": "#/$defs/accordion"
        },
        {
          "$ref": "#/$defs/image"
        },
        {
          "$ref": "#/$defs/video"
        },
        {
          "$ref": "#/$defs/file"
        },
        {
          "$ref": "#/$defs/embed"
        },
        {
          "$ref": "#/$defs/divider"
        },
        {
          "$ref": "#/$defs/fileTree"
        },
        {
          "$ref": "#/$defs/drawing"
        },
        {
          "$ref": "#/$defs/diagram"
        }
      ]
    },
    "context_tab": {
      "description": "A tab: everything but tabs.",
      "anyOf": [
        {
          "$ref": "#/$defs/paragraph"
        },
        {
          "$ref": "#/$defs/heading"
        },
        {
          "$ref": "#/$defs/code"
        },
        {
          "$ref": "#/$defs/quote"
        },
        {
          "$ref": "#/$defs/callout"
        },
        {
          "$ref": "#/$defs/list"
        },
        {
          "$ref": "#/$defs/table"
        },
        {
          "$ref": "#/$defs/cards"
        },
        {
          "$ref": "#/$defs/columns"
        },
        {
          "$ref": "#/$defs/steps"
        },
        {
          "$ref": "#/$defs/accordion"
        },
        {
          "$ref": "#/$defs/image"
        },
        {
          "$ref": "#/$defs/video"
        },
        {
          "$ref": "#/$defs/file"
        },
        {
          "$ref": "#/$defs/embed"
        },
        {
          "$ref": "#/$defs/divider"
        },
        {
          "$ref": "#/$defs/fileTree"
        },
        {
          "$ref": "#/$defs/drawing"
        },
        {
          "$ref": "#/$defs/diagram"
        }
      ]
    },
    "context_layout": {
      "description": "A column, a step, an accordion: no layout inside layout.",
      "anyOf": [
        {
          "$ref": "#/$defs/paragraph"
        },
        {
          "$ref": "#/$defs/heading"
        },
        {
          "$ref": "#/$defs/code"
        },
        {
          "$ref": "#/$defs/quote"
        },
        {
          "$ref": "#/$defs/callout"
        },
        {
          "$ref": "#/$defs/list"
        },
        {
          "$ref": "#/$defs/table"
        },
        {
          "$ref": "#/$defs/cards"
        },
        {
          "$ref": "#/$defs/image"
        },
        {
          "$ref": "#/$defs/video"
        },
        {
          "$ref": "#/$defs/file"
        },
        {
          "$ref": "#/$defs/embed"
        },
        {
          "$ref": "#/$defs/divider"
        },
        {
          "$ref": "#/$defs/fileTree"
        },
        {
          "$ref": "#/$defs/drawing"
        },
        {
          "$ref": "#/$defs/diagram"
        }
      ]
    },
    "context_flow": {
      "description": "A quote, a callout, a list item: no tables, cards or layout.",
      "anyOf": [
        {
          "$ref": "#/$defs/paragraph"
        },
        {
          "$ref": "#/$defs/heading"
        },
        {
          "$ref": "#/$defs/code"
        },
        {
          "$ref": "#/$defs/quote"
        },
        {
          "$ref": "#/$defs/callout"
        },
        {
          "$ref": "#/$defs/list"
        },
        {
          "$ref": "#/$defs/image"
        },
        {
          "$ref": "#/$defs/video"
        },
        {
          "$ref": "#/$defs/file"
        },
        {
          "$ref": "#/$defs/embed"
        },
        {
          "$ref": "#/$defs/divider"
        },
        {
          "$ref": "#/$defs/fileTree"
        },
        {
          "$ref": "#/$defs/drawing"
        },
        {
          "$ref": "#/$defs/diagram"
        }
      ]
    },
    "context_cell": {
      "description": "A table cell: simple content.",
      "anyOf": [
        {
          "$ref": "#/$defs/paragraph"
        },
        {
          "$ref": "#/$defs/heading"
        },
        {
          "$ref": "#/$defs/code"
        },
        {
          "$ref": "#/$defs/list"
        },
        {
          "$ref": "#/$defs/image"
        },
        {
          "$ref": "#/$defs/file"
        },
        {
          "$ref": "#/$defs/divider"
        }
      ]
    },
    "box": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        },
        "w": {
          "type": "number"
        },
        "h": {
          "type": "number"
        }
      },
      "required": [
        "x",
        "y"
      ],
      "additionalProperties": false
    },
    "link": {
      "type": "object",
      "properties": {
        "href": {
          "type": "string",
          "format": "uri-reference"
        },
        "title": {
          "type": "string"
        }
      },
      "required": [
        "href"
      ],
      "additionalProperties": false
    },
    "run_text": {
      "description": "Text with the same formatting.",
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "minLength": 1
        },
        "bold": {
          "const": true
        },
        "italic": {
          "const": true
        },
        "underline": {
          "const": true
        },
        "strike": {
          "const": true
        },
        "code": {
          "const": true
        },
        "link": {
          "$ref": "#/$defs/link",
          "description": "A hyperlink: href (a URL, a #heading anchor or a relative path) and an optional title."
        }
      },
      "required": [
        "text"
      ],
      "additionalProperties": false
    },
    "run_note": {
      "description": "A link to another note, shown with the note's current name. Counts as one position.",
      "type": "object",
      "properties": {
        "note": {
          "type": "string",
          "description": "The note linked to."
        },
        "name": {
          "type": "string",
          "default": "",
          "description": "That note's name when linked, for readers that can't look it up."
        }
      },
      "required": [
        "note"
      ],
      "additionalProperties": false
    },
    "run_break": {
      "description": "A line break. Counts as one position.",
      "type": "object",
      "properties": {
        "break": {
          "const": true
        }
      },
      "required": [
        "break"
      ],
      "additionalProperties": false
    },
    "text": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "#/$defs/run_text"
          },
          {
            "$ref": "#/$defs/run_note"
          },
          {
            "$ref": "#/$defs/run_break"
          }
        ]
      },
      "description": "Text: a list of runs."
    }
  }
}
