{
  "$comment": "The Kribble Document Format, version 2: every block, part and run, their fields and where blocks may go. Normative, with spec/document.md. spec/generate.ts derives the JSON Schema, the reference, the TypeScript types and the copy Go embeds from it; edit this file, then run pnpm spec:generate.",
  "format": "kribble-document",
  "version": 2,
  "groups": {
    "text": "Blocks of text: paragraphs, headings, code.",
    "media": "Blocks that show one thing: images, videos, files, embeds, dividers, file trees, drawings, diagrams.",
    "flow": "Containers of running content: quotes, callouts, lists.",
    "structure": "Tables and cards.",
    "layout": "Blocks that lay content out: tabs, columns, steps, accordions."
  },
  "contexts": {
    "document": { "allows": ["text", "media", "flow", "structure", "layout"], "description": "The document's top level." },
    "tab": { "allows": ["text", "media", "flow", "structure", "columns", "steps", "accordion"], "description": "A tab: everything but tabs." },
    "layout": { "allows": ["text", "media", "flow", "structure"], "description": "A column, a step, an accordion: no layout inside layout." },
    "flow": { "allows": ["text", "media", "flow"], "description": "A quote, a callout, a list item: no tables, cards or layout." },
    "cell": { "allows": ["paragraph", "heading", "code", "list", "image", "file", "divider"], "description": "A table cell: simple content." }
  },
  "blocks": [
    {
      "type": "paragraph",
      "group": "text",
      "fields": {
        "align": { "kind": "enum", "values": ["left", "center", "right"], "default": "left", "description": "Text alignment." },
        "text": { "kind": "text", "description": "The paragraph's text." }
      },
      "description": "A paragraph."
    },
    {
      "type": "heading",
      "group": "text",
      "fields": {
        "level": { "kind": "enum", "values": [1, 2, 3], "default": 1, "description": "1 to 3." },
        "align": { "kind": "enum", "values": ["left", "center", "right"], "default": "left", "description": "Text alignment." },
        "text": { "kind": "text", "description": "The heading's text." }
      },
      "description": "A section heading."
    },
    {
      "type": "code",
      "group": "text",
      "fields": {
        "language": { "kind": "string", "default": "", "description": "The language it's written in, a lowercase name (typescript, go, bash, mermaid…); empty for none." },
        "filename": { "kind": "string", "default": "", "description": "Shown as a title above the code; empty for none." },
        "code": { "kind": "string", "default": "", "description": "The code: plain text, lines separated by \\n." }
      },
      "description": "Preformatted code."
    },
    {
      "type": "quote",
      "group": "flow",
      "fields": {
        "blocks": { "kind": "blocks", "context": "flow", "description": "The quotation." }
      },
      "description": "A quotation."
    },
    {
      "type": "callout",
      "group": "flow",
      "fields": {
        "tone": { "kind": "enum", "values": ["info", "success", "warning", "danger"], "default": "info", "description": "How it looks: a note, a tip, a warning, a danger." },
        "blocks": { "kind": "blocks", "context": "flow", "description": "What it says." }
      },
      "description": "A highlighted box."
    },
    {
      "type": "list",
      "group": "flow",
      "fields": {
        "style": { "kind": "enum", "values": ["bullet", "ordered", "task"], "default": "bullet", "description": "Bullets, numbers or checkboxes." },
        "start": { "kind": "integer", "min": 0, "default": 1, "description": "Ordered lists: the first item's number." },
        "moveChecked": { "kind": "boolean", "default": false, "description": "Task lists: checked items move to the end." },
        "items": { "kind": "parts", "part": "listItem", "min": 1, "description": "The items." }
      },
      "description": "A bulleted, numbered or task list."
    },
    {
      "type": "table",
      "group": "structure",
      "fields": {
        "columns": { "kind": "parts", "part": "tableColumn", "default": [], "description": "Column widths, set when someone resizes a column; empty for automatic layout." },
        "rows": { "kind": "parts", "part": "tableRow", "min": 1, "description": "The rows." }
      },
      "description": "A table."
    },
    {
      "type": "cards",
      "group": "structure",
      "fields": {
        "cards": { "kind": "parts", "part": "card", "min": 1, "description": "The cards." }
      },
      "description": "A grid of cards."
    },
    {
      "type": "tabs",
      "group": "layout",
      "fields": {
        "group": { "kind": "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": { "kind": "parts", "part": "tab", "min": 1, "description": "The tabs." }
      },
      "description": "Tabs, one of which shows at a time. Only at the top level of a document."
    },
    {
      "type": "columns",
      "group": "layout",
      "fields": {
        "columns": { "kind": "parts", "part": "column", "min": 1, "description": "The columns, of equal width." }
      },
      "description": "Side-by-side columns."
    },
    {
      "type": "steps",
      "group": "layout",
      "fields": {
        "steps": { "kind": "parts", "part": "step", "min": 1, "description": "The steps, numbered in order." }
      },
      "description": "Numbered steps."
    },
    {
      "type": "accordion",
      "group": "layout",
      "fields": {
        "title": { "kind": "text", "description": "What shows when it's closed." },
        "blocks": { "kind": "blocks", "context": "layout", "description": "What shows when it's open." }
      },
      "description": "A section that opens and closes."
    },
    {
      "type": "image",
      "group": "media",
      "fields": {
        "src": { "kind": "string", "required": true, "format": "uri-reference", "description": "The image's address: an uploaded file (/files/…) or any URL." },
        "alt": { "kind": "string", "default": "", "description": "Alternative text." }
      },
      "description": "An image."
    },
    {
      "type": "video",
      "group": "media",
      "fields": {
        "src": { "kind": "string", "required": true, "format": "uri-reference", "description": "The video file's address." },
        "name": { "kind": "string", "default": "", "description": "The file name." }
      },
      "description": "A video file, played in place."
    },
    {
      "type": "file",
      "group": "media",
      "fields": {
        "src": { "kind": "string", "required": true, "format": "uri-reference", "description": "The file's address." },
        "name": { "kind": "string", "default": "", "description": "The file name." },
        "size": { "kind": "integer", "min": 0, "default": 0, "description": "Size in bytes; 0 when unknown." }
      },
      "description": "A file to download."
    },
    {
      "type": "embed",
      "group": "media",
      "fields": {
        "url": { "kind": "string", "required": true, "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." }
      },
      "description": "Embedded content from another site."
    },
    {
      "type": "divider",
      "group": "media",
      "fields": {},
      "description": "A dividing line."
    },
    {
      "type": "fileTree",
      "group": "media",
      "fields": {
        "entries": { "kind": "parts", "part": "fileEntry", "default": [], "description": "The top-level files and folders." }
      },
      "description": "A file and folder tree."
    },
    {
      "type": "drawing",
      "group": "media",
      "fields": {
        "scene": { "kind": "scene", "description": "The drawing (spec/drawing.md)." }
      },
      "description": "A drawing: shapes, arrows, freehand strokes, text and images."
    },
    {
      "type": "diagram",
      "group": "media",
      "fields": {
        "kind": { "kind": "enum", "values": ["flow", "sequence", "class"], "default": "flow", "description": "The kind of diagram (spec/diagram-language.md)." },
        "source": { "kind": "string", "default": "", "description": "The diagram text: the source of truth." },
        "layout": { "kind": "part", "part": "diagramLayout", "description": "What the user changed by hand: positions of moved boxes, and the text the scene was last laid out from." },
        "scene": { "kind": "scene", "description": "The drawing: the elements laid out from the text (they have keys) and any drawn next to them by hand (they don't)." }
      },
      "description": "A diagram made from text, laid out by the diagram engine."
    }
  ],
  "parts": [
    {
      "type": "listItem",
      "id": true,
      "fields": {
        "checked": { "kind": "boolean", "default": false, "description": "Task lists: whether it's done." },
        "blocks": { "kind": "blocks", "context": "flow", "first": ["paragraph", "heading"], "description": "The item's content: a paragraph or heading first, then any blocks (nested lists among them)." }
      },
      "description": "A list item."
    },
    {
      "type": "tableColumn",
      "id": false,
      "fields": {
        "width": { "kind": "number", "min": 0, "required": true, "description": "The column's width as a fraction of the table's; the widths add up to 1." }
      },
      "description": "A table column's width."
    },
    {
      "type": "tableRow",
      "id": true,
      "fields": {
        "cells": { "kind": "parts", "part": "tableCell", "min": 1, "description": "The cells." }
      },
      "description": "A table row."
    },
    {
      "type": "tableCell",
      "id": true,
      "fields": {
        "header": { "kind": "boolean", "default": false, "description": "A header cell." },
        "colspan": { "kind": "integer", "min": 1, "default": 1, "description": "Columns it spans." },
        "rowspan": { "kind": "integer", "min": 1, "default": 1, "description": "Rows it spans." },
        "blocks": { "kind": "blocks", "context": "cell", "description": "The cell's content." }
      },
      "description": "A table cell."
    },
    {
      "type": "card",
      "id": true,
      "fields": {
        "title": { "kind": "string", "default": "", "description": "The card's title." },
        "description": { "kind": "string", "default": "", "description": "The card's text." },
        "cover": { "kind": "string", "default": "", "format": "uri-reference", "description": "A cover image's address; empty for none." },
        "href": { "kind": "string", "default": "", "format": "uri-reference", "description": "Where it links to; empty for nowhere. A note takes precedence." },
        "note": { "kind": "string", "default": "", "description": "The note it links to; empty for none." },
        "noteName": { "kind": "string", "default": "", "description": "That note's name when linked, for readers that can't look it up." }
      },
      "description": "A card."
    },
    {
      "type": "tab",
      "id": true,
      "fields": {
        "label": { "kind": "string", "default": "Tab", "description": "The tab's label." },
        "blocks": { "kind": "blocks", "context": "tab", "description": "The tab's content." }
      },
      "description": "A tab."
    },
    {
      "type": "column",
      "id": true,
      "fields": {
        "blocks": { "kind": "blocks", "context": "layout", "description": "The column's content." }
      },
      "description": "A column."
    },
    {
      "type": "step",
      "id": true,
      "fields": {
        "title": { "kind": "text", "description": "The step's title." },
        "blocks": { "kind": "blocks", "context": "layout", "description": "The step's content." }
      },
      "description": "A step."
    },
    {
      "type": "fileEntry",
      "id": false,
      "fields": {
        "name": { "kind": "string", "required": true, "description": "The file or folder name." },
        "dir": { "kind": "boolean", "default": false, "description": "A folder." },
        "highlight": { "kind": "boolean", "default": false, "description": "Highlighted (the file the text is about)." },
        "entries": { "kind": "parts", "part": "fileEntry", "default": [], "description": "What's inside it." }
      },
      "description": "A file or folder in a file tree."
    },
    {
      "type": "diagramLayout",
      "id": false,
      "fields": {
        "positions": { "kind": "map", "of": "box", "default": {}, "description": "Where boxes the user moved are, by element key (n:<name>): x, y, and w and h when the user sized them." },
        "drawnFrom": { "kind": "string", "default": "", "description": "The text the scene was last laid out from, to recognise renames when the text changed elsewhere." }
      },
      "description": "A diagram's layout state."
    }
  ],
  "runs": {
    "text": {
      "fields": {
        "text": { "kind": "string", "required": true, "description": "The text; never empty." },
        "bold": { "kind": "boolean", "default": false, "description": "Bold." },
        "italic": { "kind": "boolean", "default": false, "description": "Italic." },
        "underline": { "kind": "boolean", "default": false, "description": "Underlined." },
        "strike": { "kind": "boolean", "default": false, "description": "Struck through." },
        "code": { "kind": "boolean", "default": false, "description": "Inline code." },
        "link": { "kind": "link", "description": "A hyperlink: href (a URL, a #heading anchor or a relative path) and an optional title." }
      },
      "description": "Text with the same formatting."
    },
    "note": {
      "fields": {
        "note": { "kind": "string", "required": true, "description": "The note linked to." },
        "name": { "kind": "string", "default": "", "description": "That note's name when linked, for readers that can't look it up." }
      },
      "description": "A link to another note, shown with the note's current name. Counts as one position."
    },
    "break": {
      "fields": {
        "break": { "kind": "boolean", "required": true, "description": "Always true." }
      },
      "description": "A line break. Counts as one position."
    }
  }
}
