{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:liuska:schema:template:v1",
  "title": "liuska template",
  "description": "A liuska template: page setup, fonts, styles, header/footer and positioned elements with {{ }} data bindings. Every template has \"version\": 1.",
  "$ref": "#/$defs/templateV1",
  "$defs": {
    "templateV1": {
      "title": "Template v1",
      "type": "object",
      "required": [
        "version",
        "page",
        "elements"
      ],
      "properties": {
        "$schema": {
          "type": "string",
          "description": "Path or URL of this JSON Schema, so editors such as VS Code validate the file and show hover docs. Ignored by liuska."
        },
        "version": {
          "const": 1,
          "description": "Template format version. Must be 1."
        },
        "name": {
          "type": "string",
          "description": "Human-readable template name, shown in the designer and in `liuska serve` template listings."
        },
        "page": {
          "$ref": "#/$defs/page"
        },
        "units": {
          "const": "pt",
          "default": "pt",
          "description": "Unit of all plain numbers in the template: PDF points (1/72 inch; A4 is 595 x 842 pt). Dimension strings such as \"10mm\", \"2cm\", \"1in\" or \"50%\" are accepted wherever a dimension is allowed."
        },
        "locale": {
          "$ref": "#/$defs/locale"
        },
        "fonts": {
          "type": "array",
          "description": "Font files to load, in addition to the bundled default font. Each entry registers one style of a family; reference the family via `fontFamily`. Fonts are parsed once per engine and only the used glyphs are embedded.",
          "items": {
            "$ref": "#/$defs/font"
          }
        },
        "fontFallback": {
          "type": "array",
          "description": "Font families tried, in order, for characters the element's font has no glyph for (symbols, CJK, emoji-free dingbats...). Each name resolves like `fontFamily` (declared `fonts`, FontDirs, bundled). The bundled font is always tried last unless the list contains \"none\".",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "examples": [
            [
              "Noto Sans Symbols 2",
              "Noto Sans CJK"
            ],
            [
              "none"
            ]
          ]
        },
        "kerning": {
          "type": "boolean",
          "default": true,
          "description": "Apply the fonts' pair kerning (OpenType GPOS `kern` feature or the legacy `kern` table). The bundled font has no kerning data."
        },
        "defaultStyle": {
          "$ref": "#/$defs/style",
          "description": "Style applied to every element before its named `style` and inline style properties. Typical: fontFamily, fontSize, color."
        },
        "styles": {
          "type": "object",
          "description": "Named, reusable styles. An element references one with `\"style\": \"name\"`; its inline style properties override the named style.",
          "additionalProperties": {
            "$ref": "#/$defs/style"
          },
          "propertyNames": {
            "pattern": "^[A-Za-z_][A-Za-z0-9_.-]*$"
          }
        },
        "header": {
          "$ref": "#/$defs/band",
          "description": "Header band drawn on every page at the top of the content area (inside the margins). Element coordinates are relative to the header box. `{{page}}` and `{{pages}}` are available."
        },
        "footer": {
          "$ref": "#/$defs/band",
          "description": "Footer band drawn on every page at the bottom of the content area (inside the margins). Element coordinates are relative to the footer box. `{{page}}` and `{{pages}}` are available, e.g. \"Page {{page}} of {{pages}}\"."
        },
        "elements": {
          "type": "array",
          "description": "Body elements. Coordinates are relative to the page's top-left corner (margins are NOT applied to x/y). The body area available for flowing tables is the page height minus margins, header and footer.",
          "items": {
            "$ref": "#/$defs/element"
          }
        },
        "sampleData": {
          "description": "Optional inline sample data used by the designer's live preview and by `liuska render` when no data is given.",
          "type": [
            "object",
            "array"
          ]
        },
        "sampleDataFile": {
          "type": "string",
          "description": "Optional path (relative to the template file) of a JSON file with sample data for the designer preview."
        },
        "repeatGap": {
          "type": "number",
          "minimum": 0,
          "default": 8,
          "description": "Space in points kept between a repeated element (`repeat`) and the flowing content on the pages where it is drawn as a repeat: tables continue this far below a repeated strip at the top, and end this far above one at the bottom."
        },
        "pdf": {
          "type": "object",
          "description": "PDF output settings: PDF/A archival conformance, PDF/UA accessibility, tagged PDF, document metadata and embedded files. See docs/pdf-standards.md.",
          "properties": {
            "conformance": {
              "type": "string",
              "enum": ["none", "PDF/A-2b", "PDF/A-2u", "PDF/A-2a", "PDF/A-3b", "PDF/A-3u", "PDF/A-3a"],
              "default": "none",
              "description": "PDF/A level. b = visual appearance (sRGB OutputIntent, XMP, embedded fonts, file ID); u = b + Unicode text; a = u + tagged structure. PDF/A-3 additionally allows `attachments` (needed for ZUGFeRD / Factur-X). Spellings like \"pdfa-3b\" or \"3b\" are accepted by the renderer."
            },
            "ua": {
              "type": "boolean",
              "default": false,
              "description": "Claim PDF/UA-1 (ISO 14289-1): tagged structure, document title shown in the viewer, language, alt text for figures. Implies `tagged`. Combine with `conformance` for PDF/A + PDF/UA."
            },
            "tagged": {
              "type": "boolean",
              "default": false,
              "description": "Write a structure tree (headings, paragraphs, tables with TH/TD, figures with alt text, artifacts for decoration and header/footer) without claiming PDF/UA. Implied by `ua` and by PDF/A level a."
            },
            "lang": {
              "type": "string",
              "description": "Document language (BCP 47, e.g. \"fi-FI\"). Default: the template `locale`, else en-US."
            },
            "metadata": {
              "type": "object",
              "description": "Document properties written to the Info dictionary and XMP. All fields are template strings with {{ }} bindings.",
              "properties": {
                "title": { "type": "string", "description": "Document title (default: template `name`). Shown in the viewer title bar when tagged." },
                "author": { "type": "string" },
                "subject": { "type": "string" },
                "keywords": {
                  "description": "Keywords: a string or an array of strings (joined with \", \").",
                  "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }]
                },
                "creator": { "type": "string", "description": "Creating application (default \"liuska\")." },
                "created": { "type": "string", "description": "Creation date: \"now\", 2006-01-02, RFC 3339 (2006-01-02T15:04:05Z) or a binding that yields one. Without it no date is written, so output is byte-identical for identical input." },
                "modified": { "type": "string", "description": "Modification date, same formats as `created` (default: `created`)." }
              },
              "additionalProperties": false
            },
            "attachments": {
              "type": "array",
              "description": "Embedded files. Allowed in plain PDF and PDF/A-3; not in PDF/A-2.",
              "items": {
                "type": "object",
                "required": ["name"],
                "properties": {
                  "name": { "type": "string", "minLength": 1, "description": "File name shown in the viewer's attachment list (bindings allowed)." },
                  "src": { "type": "string", "description": "File path relative to the template, or a data: URI." },
                  "content": { "type": "string", "description": "Inline text content (template string), used when `src` is not set. Written as UTF-8." },
                  "mimeType": { "type": "string", "description": "MIME type, e.g. \"text/xml\" (default application/octet-stream)." },
                  "description": { "type": "string" },
                  "relationship": {
                    "enum": ["Source", "Data", "Alternative", "Supplement", "Unspecified"],
                    "default": "Unspecified",
                    "description": "PDF/A-3 AFRelationship of the file to the document (Factur-X / ZUGFeRD use Alternative or Data)."
                  }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^(x-|_)": {
          "description": "Tool-specific metadata (for example designer state). Ignored by the renderer."
        }
      },
      "additionalProperties": false
    },
    "page": {
      "type": "object",
      "description": "Page size, orientation and margins.",
      "properties": {
        "size": {
          "description": "Paper size: a named size or an explicit {\"width\", \"height\"} in points (or dimension strings).",
          "default": "A4",
          "anyOf": [
            {
              "enum": [
                "A4",
                "A3",
                "A5",
                "Letter",
                "Legal"
              ],
              "description": "Named paper size. A4 = 595 x 842 pt, A3 = 842 x 1191 pt, A5 = 420 x 595 pt, Letter = 612 x 792 pt, Legal = 612 x 1008 pt (portrait)."
            },
            {
              "type": "object",
              "description": "Custom page size (portrait dimensions; `orientation: landscape` swaps them).",
              "required": [
                "width",
                "height"
              ],
              "properties": {
                "width": {
                  "$ref": "#/$defs/absoluteDimension",
                  "description": "Page width."
                },
                "height": {
                  "$ref": "#/$defs/absoluteDimension",
                  "description": "Page height."
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "orientation": {
          "enum": [
            "portrait",
            "landscape"
          ],
          "default": "portrait",
          "description": "Page orientation. \"landscape\" swaps width and height of `size`."
        },
        "margins": {
          "$ref": "#/$defs/margins"
        }
      },
      "additionalProperties": false
    },
    "margins": {
      "type": "object",
      "description": "Page margins. The header and footer bands sit inside the margins; flowing tables use the space between them.",
      "properties": {
        "top": {
          "$ref": "#/$defs/absoluteDimension",
          "description": "Top margin.",
          "default": 0
        },
        "right": {
          "$ref": "#/$defs/absoluteDimension",
          "description": "Right margin.",
          "default": 0
        },
        "bottom": {
          "$ref": "#/$defs/absoluteDimension",
          "description": "Bottom margin.",
          "default": 0
        },
        "left": {
          "$ref": "#/$defs/absoluteDimension",
          "description": "Left margin.",
          "default": 0
        }
      },
      "additionalProperties": false
    },
    "locale": {
      "description": "Locale for number, percent, currency and date formatting (decimal and thousands separators, currency placement). Supported at least: en-US, fi-FI, de-DE, sv-SE.",
      "default": "en-US",
      "anyOf": [
        {
          "enum": [
            "en-US",
            "fi-FI",
            "de-DE",
            "sv-SE"
          ]
        },
        {
          "type": "string",
          "pattern": "^[a-z]{2,3}(-[A-Z]{2})?$"
        }
      ]
    },
    "font": {
      "type": "object",
      "description": "One font file registered under a family name and style.",
      "required": [
        "family",
        "src"
      ],
      "properties": {
        "family": {
          "type": "string",
          "description": "Family name used in `fontFamily`, e.g. \"Inter\"."
        },
        "style": {
          "enum": [
            "regular",
            "bold",
            "italic",
            "bold-italic"
          ],
          "default": "regular",
          "description": "Which face of the family this file provides. `bold`/`italic` style properties pick the matching face."
        },
        "src": {
          "type": "string",
          "description": "Path to a TTF/OTF file, relative to the template file (also searched in the engine's FontDirs)."
        }
      },
      "additionalProperties": false
    },
    "band": {
      "type": "object",
      "required": [
        "height"
      ],
      "properties": {
        "height": {
          "$ref": "#/$defs/absoluteDimension",
          "description": "Height of the band. It is subtracted from the body area on every page."
        },
        "elements": {
          "type": "array",
          "description": "Elements in the band; coordinates are relative to the band's top-left corner.",
          "items": {
            "$ref": "#/$defs/element"
          }
        }
      },
      "additionalProperties": false
    },
    "absoluteDimension": {
      "description": "A length: a number in points, or a string with a unit: \"12\", \"12pt\", \"10mm\", \"2cm\", \"1in\".",
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "string",
          "pattern": "^-?[0-9]+(\\.[0-9]+)?\\s*(pt|px|mm|cm|in)?$"
        }
      ]
    },
    "dimension": {
      "description": "A length: a number in points, or a string with a unit: \"12pt\", \"10mm\", \"2cm\", \"1in\", or a percentage of the containing box (\"50%\"; for body elements the page content width/height).",
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "string",
          "pattern": "^-?[0-9]+(\\.[0-9]+)?\\s*(pt|px|mm|cm|in|%)?$"
        }
      ]
    },
    "color": {
      "type": "string",
      "description": "Color as hex: #rgb, #rrggbb or #rrggbbaa.",
      "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$"
    },
    "dataPath": {
      "type": "string",
      "description": "Path into the data using dot/index notation, without braces: `customer.name`, `report.rows`, `rows[0].total`.",
      "pattern": "^[^{}|]+$"
    },
    "format": {
      "type": "string",
      "description": "A filter chain in the binding filter syntax without the leading `|`, e.g. `currency:\"EUR\"`, `number:2`, `percent:1`, `compact` (1.2k / 3.4M, locale-aware), `date:\"02.01.2006\"`, `upper`, `default:\"—\"`. Several filters can be chained with `|`.",
      "examples": [
        "currency:\"EUR\"",
        "number:0",
        "compact",
        "compact:1,\"plain\"",
        "number:2",
        "percent:1",
        "date:\"2006-01-02\"",
        "upper",
        "default:\"—\""
      ]
    },
    "padding": {
      "description": "Inner spacing: one number for all sides, or per side.",
      "anyOf": [
        {
          "$ref": "#/$defs/absoluteDimension"
        },
        {
          "type": "object",
          "properties": {
            "top": {
              "$ref": "#/$defs/absoluteDimension",
              "description": "Top padding."
            },
            "right": {
              "$ref": "#/$defs/absoluteDimension",
              "description": "Right padding."
            },
            "bottom": {
              "$ref": "#/$defs/absoluteDimension",
              "description": "Bottom padding."
            },
            "left": {
              "$ref": "#/$defs/absoluteDimension",
              "description": "Left padding."
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "styleProps": {
      "description": "Style properties. Usable inline on any element, in named `styles`, in `defaultStyle` and in table row/header/column styles.",
      "properties": {
        "fontFamily": {
          "type": "string",
          "description": "Font family name: the bundled default or a family registered in `fonts`."
        },
        "fontSize": {
          "type": "number",
          "exclusiveMinimum": 0,
          "description": "Font size in points."
        },
        "bold": {
          "type": "boolean",
          "default": false,
          "description": "Use the bold face of the font family."
        },
        "italic": {
          "type": "boolean",
          "default": false,
          "description": "Use the italic face of the font family."
        },
        "color": {
          "$ref": "#/$defs/color",
          "description": "Text color."
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ],
          "default": "left",
          "description": "Horizontal text alignment inside the box."
        },
        "valign": {
          "enum": [
            "top",
            "middle",
            "bottom"
          ],
          "default": "top",
          "description": "Vertical text alignment inside the box."
        },
        "lineHeight": {
          "type": "number",
          "exclusiveMinimum": 0,
          "description": "Line height as a multiple of the font size, e.g. 1.2."
        },
        "fill": {
          "$ref": "#/$defs/color",
          "description": "Background fill color of the box (rect, text box, table cell)."
        },
        "stroke": {
          "$ref": "#/$defs/color",
          "description": "Outline / line color."
        },
        "strokeWidth": {
          "type": "number",
          "minimum": 0,
          "description": "Outline / line width in points."
        },
        "radius": {
          "type": "number",
          "minimum": 0,
          "description": "Corner radius in points (rect and boxed elements)."
        },
        "padding": {
          "$ref": "#/$defs/padding"
        },
        "opacity": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "default": 1,
          "description": "Opacity from 0 (invisible) to 1 (opaque)."
        }
      }
    },
    "style": {
      "type": "object",
      "description": "A set of style properties.",
      "$ref": "#/$defs/styleProps",
      "unevaluatedProperties": false
    },
    "anchorEdge": {
      "type": "object",
      "description": "Pins one edge of this element to an edge of another element. Used to stack elements under a growing table: anchored elements move when the target grows or flows onto later pages.",
      "required": [
        "targetId",
        "edge"
      ],
      "properties": {
        "targetId": {
          "type": "string",
          "description": "`id` of the element to anchor to, or \"page\" for the page edges."
        },
        "edge": {
          "enum": [
            "left",
            "right",
            "top",
            "bottom"
          ],
          "description": "Edge of the target element to attach to."
        },
        "offset": {
          "type": "number",
          "default": 0,
          "description": "Distance in points from the target edge."
        }
      },
      "additionalProperties": false
    },
    "anchors": {
      "type": "object",
      "description": "Anchors keyed by this element's edge (left/right/top/bottom). Example: {\"top\": {\"targetId\": \"items\", \"edge\": \"bottom\", \"offset\": 10}} places the element 10 pt under the table `items`, following it across pages.",
      "properties": {
        "left": {
          "$ref": "#/$defs/anchorEdge"
        },
        "right": {
          "$ref": "#/$defs/anchorEdge"
        },
        "top": {
          "$ref": "#/$defs/anchorEdge"
        },
        "bottom": {
          "$ref": "#/$defs/anchorEdge"
        }
      },
      "additionalProperties": false
    },
    "elementBase": {
      "description": "Fields shared by all element types.",
      "$ref": "#/$defs/styleProps",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Unique element id. Required to be the target of `anchors`; the designer always sets one."
        },
        "type": {
          "type": "string",
          "description": "Element type."
        },
        "x": {
          "$ref": "#/$defs/dimension",
          "default": 0,
          "description": "Left edge. Body elements: relative to the page's left edge (margins not applied). Header/footer/group children: relative to the containing box."
        },
        "y": {
          "$ref": "#/$defs/dimension",
          "default": 0,
          "description": "Top edge. Body elements: relative to the page's top edge (margins not applied). Header/footer/group children: relative to the containing box."
        },
        "width": {
          "$ref": "#/$defs/dimension",
          "description": "Box width: points, unit string or percentage of the containing width (\"100%\" = page content width for body elements)."
        },
        "height": {
          "$ref": "#/$defs/dimension",
          "description": "Box height: points, unit string or percentage of the containing height."
        },
        "style": {
          "type": "string",
          "description": "Name of a style in the template's `styles`. Inline style properties override it."
        },
        "anchors": {
          "$ref": "#/$defs/anchors"
        },
        "visibleIf": {
          "$ref": "#/$defs/dataPath",
          "description": "Data path; the element is drawn only if the value is truthy (not missing, null, false, 0, \"\" or empty array)."
        },
        "rotation": {
          "type": "number",
          "default": 0,
          "description": "Rotation in degrees (clockwise) around the element's top-left corner."
        },
        "repeat": {
          "description": "Draw this element on other pages too. \"all\" (or true): every page of the document. \"following\": every page after the one it is laid out on. \"none\" (or false, the default): once. The element is laid out once and drawn at the same position on the other pages; flowing content (tables, anchored elements) starts below it (upper half of the body) or ends above it (lower half) on those pages, with `repeatGap` between. Only for top-level body elements: header/footer and group children and pageBreak ignore it, and tables cannot repeat (use `repeatHeader`). A repeated element may only anchor to the page or to other repeated elements. To repeat several elements together, put them in a group and set `repeat` on the group.",
          "default": "none",
          "anyOf": [
            {
              "enum": [
                "all",
                "following",
                "none"
              ]
            },
            {
              "type": "boolean"
            }
          ]
        },
        "alt": {
          "type": "string",
          "description": "Alternative text (template string) for tagged PDF / PDF/UA. Images and figure groups need it to be tagged as a Figure; an image without alt is tagged as a decorative artifact. Charts default to their title."
        },
        "role": {
          "type": "string",
          "enum": ["P", "H1", "H2", "H3", "H4", "H5", "H6", "Caption", "BlockQuote", "Note", "Code", "Span", "Figure", "Sect", "Div", "artifact"],
          "description": "Structure tag in tagged PDF output. Defaults: text = P, image/chart = Figure, table = Table, rect/line = artifact, group = its children are tagged individually. \"artifact\" marks the element as decoration. Header/footer elements are artifacts, except that on page 1 an element with an explicit role is tagged (e.g. the document heading in the header). Sect/Div group children; Figure on a group tags the whole group as one figure (needs alt)."
        }
      },
      "patternProperties": {
        "^(x-|_)": {
          "description": "Tool-specific metadata (for example designer state). Ignored by the renderer."
        }
      }
    },
    "element": {
      "type": "object",
      "description": "A positioned element. `type` selects the kind: rect, line, text, image, table, chart, field, group/snippet, pageBreak.",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "enum": [
            "rect",
            "line",
            "text",
            "image",
            "table",
            "chart",
            "field",
            "group",
            "pageBreak"
          ],
          "description": "Element type: rect (box), line, text (with bindings), image, table (data-driven, flows across pages), chart (data-driven vector chart, fixed box), field (interactive AcroForm form field: text, checkbox, radio, dropdown or signature), group (children or snippetPath), pageBreak."
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "rect"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/rectElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "line"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/lineElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "text"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/textElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "image"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/imageElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "table"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/tableElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "chart"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/chartElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "field"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/fieldElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "group"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/groupElement"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "pageBreak"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/pageBreakElement"
          }
        }
      ]
    },
    "rectElement": {
      "title": "rect",
      "description": "A rectangle. Uses fill, stroke, strokeWidth and radius.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "rect",
          "description": "A rectangle box."
        }
      },
      "unevaluatedProperties": false
    },
    "lineElement": {
      "title": "line",
      "description": "A straight line from (x, y) to (x + width, y + height). Use height 0 for a horizontal rule.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "line",
          "description": "A straight line."
        },
        "dash": {
          "type": "array",
          "description": "Dash pattern [on, off] in points, e.g. [3, 2]. Omit for a solid line.",
          "items": {
            "type": "number",
            "minimum": 0
          },
          "minItems": 2,
          "maxItems": 2
        }
      },
      "unevaluatedProperties": false
    },
    "textElement": {
      "title": "text",
      "description": "Text that wraps inside its box. `content` may contain {{ }} bindings with filters.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "text",
          "description": "A text box."
        },
        "content": {
          "type": "string",
          "description": "Text with bindings: {{customer.name}}, {{ total | currency:\"EUR\" }}, {{page}} / {{pages}}, {{now | date:\"2006-01-02\"}}. Missing paths render as empty (error with --strict)."
        },
        "overflow": {
          "enum": [
            "clip",
            "shrink",
            "grow"
          ],
          "default": "clip",
          "description": "What happens when text does not fit: clip (cut off at the box), shrink (reduce font size to fit), grow (box height grows; elements anchored below move down)."
        }
      },
      "unevaluatedProperties": false
    },
    "imageElement": {
      "title": "image",
      "description": "An image (PNG, JPEG, GIF or SVG) scaled into its box. SVG is drawn as vector paths and real text (see docs/svg.md).",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "required": [
        "src"
      ],
      "properties": {
        "type": {
          "const": "image",
          "description": "An image."
        },
        "src": {
          "type": "string",
          "description": "Image source: a path relative to the template file (.png, .jpg, .gif, .svg, .svgz), a data: URI (including data:image/svg+xml), inline SVG markup starting with \"<svg\", or a {{binding}} that resolves to any of these."
        },
        "fit": {
          "enum": [
            "contain",
            "cover",
            "fill"
          ],
          "default": "contain",
          "description": "How the image is scaled into the box: contain (whole image visible, aspect kept), cover (box filled, aspect kept, overflow clipped), fill (stretched to the box; for SVG it also overrides preserveAspectRatio to none)."
        }
      },
      "unevaluatedProperties": false
    },
    "aggregate": {
      "description": "Totals cell: an aggregate over the column (sum, avg, min, max, count) formatted with the column's format, or any other string, printed literally (e.g. \"Total\").",
      "anyOf": [
        {
          "enum": [
            "sum",
            "avg",
            "min",
            "max",
            "count"
          ]
        },
        {
          "type": "string"
        }
      ]
    },
    "borderLine": {
      "description": "A border line, or null for none.",
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "color": {
              "$ref": "#/$defs/color",
              "description": "Line color."
            },
            "width": {
              "type": "number",
              "minimum": 0,
              "description": "Line width in points."
            }
          },
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "column": {
      "type": "object",
      "description": "A table column. The same shape is used inline in `columns` and in the data array referenced by `columnsFrom`.",
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "description": "Key of the cell value in each row object; may be a dot path within the row (e.g. \"customer.name\"). For array rows, the column index as a string."
        },
        "header": {
          "type": "string",
          "description": "Header text. Defaults to the key."
        },
        "width": {
          "description": "Column width: points, \"20%\" of the table width, \"auto\" (measured from content) or \"*\" / \"2*\" (share of the remaining space).",
          "default": "auto",
          "anyOf": [
            {
              "type": "number",
              "exclusiveMinimum": 0
            },
            {
              "type": "string",
              "pattern": "^([0-9]+(\\.[0-9]+)?\\s*(pt|px|mm|cm|in|%)?|auto|([0-9]+(\\.[0-9]+)?)?\\*)$"
            }
          ]
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ],
          "default": "left",
          "description": "Horizontal alignment of the column's cells (and its header unless headerStyle overrides it)."
        },
        "format": {
          "$ref": "#/$defs/format",
          "description": "Formatting for the cells and totals of this column, in filter syntax without `|`: `currency:\"EUR\"`, `number:2`, `percent:1`, `date:\"02.01.2006\"`. Empty = value as is."
        },
        "headerStyle": {
          "$ref": "#/$defs/style",
          "description": "Style override for this column's header cell."
        },
        "style": {
          "$ref": "#/$defs/style",
          "description": "Style override for this column's body cells."
        }
      },
      "additionalProperties": false
    },
    "tableElement": {
      "title": "table",
      "description": "A data-driven table. Columns come from `columns` (fixed), `columnsFrom` (decided by the data) or `autoColumns` (keys of the first row). Tables taller than the remaining space flow onto new pages with the header repeated; rows are never split.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "table",
          "description": "A data table."
        },
        "repeat": {
          "enum": [
            "none",
            false
          ],
          "description": "Tables cannot repeat: they flow across pages. Use `repeatHeader` to repeat the header row; put other content to repeat in its own element."
        },
        "data": {
          "$ref": "#/$defs/dataPath",
          "description": "Data path to the rows: an array of objects, or an array of arrays whose first row is the header."
        },
        "columns": {
          "type": "array",
          "description": "Fixed column definitions. Use exactly one of columns, columnsFrom or autoColumns.",
          "items": {
            "$ref": "#/$defs/column"
          },
          "minItems": 1
        },
        "columnsFrom": {
          "$ref": "#/$defs/dataPath",
          "description": "Data path to an array of column definitions ({key, header, width, align, format}) so the data decides the columns, e.g. one column per month. Use exactly one of columns, columnsFrom or autoColumns."
        },
        "autoColumns": {
          "type": "boolean",
          "description": "Derive the columns from the keys of the first row, in the JSON key order; header = key. Handy for CSV data. Use exactly one of columns, columnsFrom or autoColumns."
        },
        "headerStyle": {
          "$ref": "#/$defs/style",
          "description": "Style of the header row, e.g. {\"bold\": true, \"fill\": \"#f0f0f0\"}."
        },
        "rowStyle": {
          "$ref": "#/$defs/style",
          "description": "Style of body rows."
        },
        "altRowStyle": {
          "$ref": "#/$defs/style",
          "description": "Style of every second body row (zebra striping), applied on top of rowStyle."
        },
        "cellPadding": {
          "$ref": "#/$defs/padding",
          "description": "Padding inside every cell, in points (number or per side)."
        },
        "borders": {
          "type": "object",
          "description": "Table borders: outer frame, horizontal lines between rows, vertical lines between columns. Each is {color, width} or null for none.",
          "properties": {
            "outer": {
              "$ref": "#/$defs/borderLine",
              "description": "Frame around the table (drawn per page fragment)."
            },
            "horizontal": {
              "$ref": "#/$defs/borderLine",
              "description": "Lines between rows."
            },
            "vertical": {
              "$ref": "#/$defs/borderLine",
              "description": "Lines between columns."
            }
          },
          "additionalProperties": false
        },
        "repeatHeader": {
          "type": "boolean",
          "default": true,
          "description": "Repeat the header row on every page the table flows onto."
        },
        "totals": {
          "type": "object",
          "description": "Totals row after the last data row, keyed by column key: \"sum\" | \"avg\" | \"min\" | \"max\" | \"count\" (formatted with the column format) or literal text such as \"Total\". Columns not listed stay empty.",
          "additionalProperties": {
            "$ref": "#/$defs/aggregate"
          }
        },
        "scalingWidth": {
          "enum": [
            "none",
            "shrink",
            "fit"
          ],
          "default": "none",
          "description": "Fit a too-wide table to its box by scaling instead of wrapping. `shrink`: when the natural width (auto columns at content width, star columns at content width, fixed columns as given) exceeds the box, column widths, fonts, line heights and padding are scaled uniformly; the table still flows across pages. `fit`: also scales up. `none` (default): auto columns wrap instead (never narrower than their longest word unless unavoidable)."
        },
        "minFontSize": {
          "type": "number",
          "exclusiveMinimum": 0,
          "description": "With scalingWidth shrink: the smallest font size (pt) the table is scaled to. If the table is still too wide at that size, its auto and star columns wrap to fit."
        }
      },
      "not": {
        "anyOf": [
          {
            "required": [
              "columns",
              "columnsFrom"
            ]
          },
          {
            "required": [
              "columns",
              "autoColumns"
            ],
            "properties": {
              "autoColumns": {
                "const": true
              }
            }
          },
          {
            "required": [
              "columnsFrom",
              "autoColumns"
            ],
            "properties": {
              "autoColumns": {
                "const": true
              }
            }
          }
        ]
      },
      "unevaluatedProperties": false
    },
    "chartElement": {
      "title": "chart",
      "description": "A data-driven vector chart (bar, line, area, pie, donut, scatter), drawn as PDF paths and text. A chart is a fixed box: it never paginates, but it can be anchored (for example under a table) and moves with its anchor target. Font style properties style all chart text; fill, stroke, strokeWidth, radius and padding style the chart's outer box. All chart settings live in the nested `chart` object.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "required": [
        "chart"
      ],
      "properties": {
        "type": {
          "const": "chart",
          "description": "A chart."
        },
        "chart": {
          "$ref": "#/$defs/chartSpec"
        }
      },
      "unevaluatedProperties": false
    },
    "chartKind": {
      "enum": [
        "bar",
        "line",
        "area",
        "pie",
        "donut",
        "scatter"
      ],
      "description": "Chart kind: bar (vertical, or horizontal with `horizontal: true`), line, area, pie, donut (pie/donut plot only the first series; extra series are ignored with a warning), scatter (numeric x from `category.key`, one point per row and series)."
    },
    "chartSpec": {
      "type": "object",
      "description": "Chart settings. Rows come from `data`; the x axis (or pie slices) from `category`; the plotted values from exactly one of `series` (fixed), `seriesFrom` (decided by the data) or `autoSeries` (every numeric key of the first row). The engine treats a chart with none of the three as autoSeries, but the schema requires one so templates say what they mean.",
      "required": [
        "kind",
        "data",
        "category"
      ],
      "properties": {
        "kind": {
          "$ref": "#/$defs/chartKind"
        },
        "data": {
          "$ref": "#/$defs/dataPath",
          "description": "Data path to the rows: an array of objects, one per category (month, region, slice...). An array of arrays also works; its first row is the header, as with tables. Missing or empty data draws `emptyText`."
        },
        "category": {
          "$ref": "#/$defs/chartCategory"
        },
        "series": {
          "type": "array",
          "description": "Fixed series definitions, drawn in this order. Use exactly one of series, seriesFrom or autoSeries.",
          "items": {
            "$ref": "#/$defs/chartSeries"
          },
          "minItems": 1
        },
        "seriesFrom": {
          "$ref": "#/$defs/dataPath",
          "description": "Data path to an array of series definitions (same shape as `series` items) so the data decides which series are drawn, e.g. one line per region. An empty array draws `emptyText`. Use exactly one of series, seriesFrom or autoSeries."
        },
        "autoSeries": {
          "type": "boolean",
          "description": "Derive the series from the first row: every numeric key except `category.key`, in JSON key order; label = key, colors from `palette`. Use exactly one of series, seriesFrom or autoSeries."
        },
        "stacked": {
          "type": "boolean",
          "default": false,
          "description": "bar/area: stack the series instead of drawing them side by side (bars) or overlapping (areas). In combo charts only series of the same kind stack with each other; lines are never stacked."
        },
        "horizontal": {
          "type": "boolean",
          "default": false,
          "description": "bar: draw horizontal bars (categories on the vertical axis, values on the horizontal axis)."
        },
        "title": {
          "type": "string",
          "description": "Title drawn at the top of the chart box. Bindings and filters allowed, e.g. \"Revenue {{report.year}}\". Omit for no title."
        },
        "legend": {
          "enum": [
            "top",
            "bottom",
            "right",
            "none"
          ],
          "description": "Legend position. Default: bottom, except \"none\" when there is a single series (pie/donut always get a legend of their slices by default)."
        },
        "axes": {
          "type": "object",
          "description": "Axis settings. Ignored for pie and donut.",
          "properties": {
            "y": {
              "$ref": "#/$defs/chartValueAxis",
              "description": "Primary value axis (left; the horizontal axis when `horizontal: true`). Range is automatic from the data (includes 0 for bar/area) with nice 1/2/5 × 10^n ticks; `min`/`max` override it."
            },
            "y2": {
              "$ref": "#/$defs/chartValueAxis",
              "description": "Secondary value axis on the right, used when any series has `axis: \"right\"`. Its range is computed from those series only."
            },
            "x": {
              "$ref": "#/$defs/chartCategoryAxis"
            }
          },
          "additionalProperties": false
        },
        "dataLabels": {
          "description": "Value labels on bars, points and slices. false = none; \"value\" = the value, formatted with the series `format`; \"percent\" = the share of the category's total (pie/donut: of all slices); \"both\" = value and percent. true means \"value\", except for pie and donut, where it means \"both\".",
          "default": false,
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "enum": [
                "value",
                "percent",
                "both"
              ]
            }
          ]
        },
        "palette": {
          "type": "array",
          "description": "Colors assigned to series (or pie/donut slices) in order, cycling when there are more series than colors. A series `color` wins. Default: [\"#2563eb\", \"#16a34a\", \"#f59e0b\", \"#dc2626\", \"#7c3aed\", \"#0891b2\"].",
          "items": {
            "$ref": "#/$defs/color"
          },
          "minItems": 1,
          "default": [
            "#2563eb",
            "#16a34a",
            "#f59e0b",
            "#dc2626",
            "#7c3aed",
            "#0891b2"
          ]
        },
        "smooth": {
          "type": "boolean",
          "default": false,
          "description": "line/area: draw monotone cubic curves through the points (no overshoot) instead of straight segments."
        },
        "markers": {
          "type": "boolean",
          "default": true,
          "description": "line/scatter: draw a marker at each data point."
        },
        "lineWidth": {
          "type": "number",
          "exclusiveMinimum": 0,
          "default": 1.5,
          "description": "Line width in points for line/area series."
        },
        "barGap": {
          "type": "number",
          "minimum": 0,
          "exclusiveMaximum": 1,
          "default": 0.2,
          "description": "Fraction of each category band left empty between groups of bars (0 = bars touch)."
        },
        "donutHole": {
          "type": "number",
          "exclusiveMinimum": 0,
          "exclusiveMaximum": 1,
          "default": 0.55,
          "description": "donut: inner radius as a fraction of the outer radius."
        },
        "emptyText": {
          "type": "string",
          "default": "No data",
          "description": "Text drawn in the middle of the chart when `data` is missing or empty."
        }
      },
      "allOf": [
        {
          "description": "Exactly one of series, seriesFrom or autoSeries: true.",
          "oneOf": [
            {
              "required": [
                "series"
              ]
            },
            {
              "required": [
                "seriesFrom"
              ]
            },
            {
              "required": [
                "autoSeries"
              ],
              "properties": {
                "autoSeries": {
                  "const": true
                }
              }
            }
          ]
        },
        {
          "description": "pie, donut and scatter cannot be combined with other kinds: their series must not set a per-series `kind`.",
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "pie",
                  "donut",
                  "scatter"
                ]
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "properties": {
              "series": {
                "items": {
                  "not": {
                    "required": [
                      "kind"
                    ]
                  }
                }
              }
            }
          }
        }
      ],
      "additionalProperties": false
    },
    "chartCategory": {
      "type": "object",
      "description": "The category of each row: the x axis for bar/line/area (the vertical axis for horizontal bars), the slice label for pie/donut, the numeric x value for scatter.",
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "description": "Key of the category value in each row (may be a dot path within the row). For array-of-arrays data, the header name."
        },
        "label": {
          "type": "string",
          "description": "Axis title for the category axis (bar/line/area/scatter). Bindings allowed. `axes.x.label` overrides it."
        },
        "format": {
          "$ref": "#/$defs/format",
          "description": "Formatting for category values in filter syntax without `|`, e.g. `date:\"Jan\"` (ISO dates to month names, localized: \"tammi\" in fi-FI) or `number:0`. Empty = value shown as is."
        }
      },
      "additionalProperties": false
    },
    "chartSeries": {
      "type": "object",
      "description": "One plotted series. The same shape is used inline in `series` and in the data array referenced by `seriesFrom`.",
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "description": "Key of the numeric value in each row (may be a dot path within the row). Null or missing values leave a gap (lines/areas) or no bar; pie/donut ignore values ≤ 0."
        },
        "label": {
          "type": "string",
          "description": "Name shown in the legend. Bindings allowed, e.g. \"{{report.previousYear}}\". Defaults to the key."
        },
        "color": {
          "$ref": "#/$defs/color",
          "description": "Series color. Defaults to the next `palette` color."
        },
        "format": {
          "$ref": "#/$defs/format",
          "description": "Formatting for this series' values in data labels, in filter syntax without `|`: `currency:\"EUR\"`, `number:0`, `percent:1`. Uses the template `locale`."
        },
        "kind": {
          "enum": [
            "bar",
            "line",
            "area"
          ],
          "description": "Per-series kind override for combo charts, e.g. bars for revenue plus a line for last year. Only bar, line and area mix; not allowed when the chart kind is pie, donut or scatter. Defaults to the chart `kind`."
        },
        "axis": {
          "enum": [
            "left",
            "right"
          ],
          "default": "left",
          "description": "Value axis: left (`axes.y`) or right (secondary axis `axes.y2`, e.g. a margin % line next to revenue bars)."
        }
      },
      "additionalProperties": false
    },
    "chartAxisProps": {
      "description": "Settings shared by all chart axes.",
      "properties": {
        "label": {
          "type": "string",
          "description": "Axis title. Bindings allowed, e.g. \"EUR ({{report.year}})\". Empty = none."
        },
        "min": {
          "type": [
            "number",
            "null"
          ],
          "default": null,
          "description": "Lower end of the axis. null = automatic from the data (bar/area always include 0)."
        },
        "max": {
          "type": [
            "number",
            "null"
          ],
          "default": null,
          "description": "Upper end of the axis. null = automatic from the data, rounded up to a nice tick."
        },
        "format": {
          "$ref": "#/$defs/format",
          "description": "Formatting for tick labels in filter syntax without `|`, e.g. `number:0`, `currency:\"EUR\"`, `percent:0`. Uses the template `locale`."
        },
        "gridlines": {
          "type": "boolean",
          "description": "Draw gridlines at the ticks. Default: true for y, false for y2 and x."
        },
        "ticks": {
          "type": "integer",
          "minimum": 2,
          "default": 5,
          "description": "Approximate number of ticks; the engine picks nice 1/2/5 × 10^n steps near it."
        }
      }
    },
    "chartValueAxis": {
      "type": "object",
      "description": "A value axis.",
      "$ref": "#/$defs/chartAxisProps",
      "unevaluatedProperties": false
    },
    "chartCategoryAxis": {
      "type": "object",
      "description": "The category axis: along the bottom, or down the left side for horizontal bars. Labels that would overlap are thinned automatically. `min`/`max`/`ticks` apply to scatter's numeric x axis only. `label` here overrides `category.label`.",
      "$ref": "#/$defs/chartAxisProps",
      "properties": {
        "labelRotation": {
          "enum": [
            0,
            45,
            90
          ],
          "default": 0,
          "description": "Rotation of the category labels in degrees: 0, 45 or 90."
        }
      },
      "unevaluatedProperties": false
    },
    "fieldElement": {
      "title": "field",
      "description": "An interactive form field (PDF AcroForm widget). The engine draws its appearance (border = stroke, default grey; background = fill; value text in the element's font style), so it looks the same in every viewer and in the PNG preview. Elements with the same field name are widgets of one field (a field in the header/footer appears on every page and shares its value; radio buttons with the same name form one group). Default size when width/height are omitted: text/dropdown 150x20, checkbox/radio 12x12, signature 180x50. Signing keys are never part of the template: a signature field only reserves the place and look of a visible signature, which `liuska render --sign-*` (or the server's signing config) fills in.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "required": [
        "field"
      ],
      "properties": {
        "type": {
          "const": "field",
          "description": "A form field."
        },
        "field": {
          "$ref": "#/$defs/fieldSpec"
        }
      },
      "unevaluatedProperties": false
    },
    "fieldSpec": {
      "type": "object",
      "description": "Form field settings.",
      "required": [
        "kind",
        "name"
      ],
      "properties": {
        "kind": {
          "enum": [
            "text",
            "checkbox",
            "radio",
            "dropdown",
            "signature"
          ],
          "description": "text (single or multi-line input), checkbox, radio (one button; buttons sharing `name` form a group), dropdown (combo box), signature (place for a digital signature)."
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[^.]+$",
          "description": "Field name (PDF /T); what form data is exported under. Must not contain '.'."
        },
        "value": {
          "type": "string",
          "description": "Default value; {{bindings}} allowed. checkbox: a truthy value (not \"\", false, 0, no, off) checks it. radio: the button whose `option` equals the value is selected. dropdown: the selected choice. Ignored for signature."
        },
        "option": {
          "type": "string",
          "minLength": 1,
          "description": "radio: the value this button stands for (required). checkbox: the export value when checked (default \"Yes\")."
        },
        "options": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "dropdown: the choices."
        },
        "optionsFrom": {
          "$ref": "#/$defs/dataPath",
          "description": "dropdown: data path to an array of extra choices (strings, or objects with label/value/name)."
        },
        "required": {
          "type": "boolean",
          "default": false,
          "description": "The viewer requires a value before the form is submitted."
        },
        "readOnly": {
          "type": "boolean",
          "default": false,
          "description": "The value cannot be changed in the viewer."
        },
        "multiline": {
          "type": "boolean",
          "default": false,
          "description": "text: multi-line input; the default value wraps."
        },
        "password": {
          "type": "boolean",
          "default": false,
          "description": "text: the viewer masks input; the default value is not stored in the file."
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0,
          "description": "text: maximum number of characters."
        },
        "editable": {
          "type": "boolean",
          "default": false,
          "description": "dropdown: the user may type a value that is not in the list."
        },
        "tooltip": {
          "type": "string",
          "description": "Tooltip / accessible name of the field (PDF /TU)."
        },
        "label": {
          "type": "string",
          "description": "signature: placeholder text drawn while the field is unsigned (default \"Signature\")."
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "radio"
              }
            }
          },
          "then": {
            "required": [
              "option"
            ]
          }
        }
      ],
      "additionalProperties": false
    },
    "groupElement": {
      "title": "group",
      "description": "A group of child elements positioned relative to the group's box, or a snippet loaded from another template file.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "group",
          "description": "A group: its children, or a snippet loaded from another template file (snippetPath)."
        },
        "children": {
          "type": "array",
          "description": "Child elements; coordinates relative to the group's top-left corner, percentages relative to the group's size.",
          "items": {
            "$ref": "#/$defs/element"
          }
        },
        "snippetPath": {
          "type": "string",
          "description": "Path (relative to this template) of another template whose elements are placed inside the group, e.g. a shared address block."
        }
      },
      "unevaluatedProperties": false
    },
    "pageBreakElement": {
      "title": "pageBreak",
      "description": "Forces the body elements after it onto a new page.",
      "type": "object",
      "$ref": "#/$defs/elementBase",
      "properties": {
        "type": {
          "const": "pageBreak",
          "description": "A forced page break."
        }
      },
      "unevaluatedProperties": false
    }
  }
}
