{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://app.unidoc.top/schemas/udoc-json/v1.json",
  "title": "UDOC JSON Authoring v1",
  "description": "AI/human authoring exchange format. Native saves MUST be encoded as UDOC3PKG.",
  "type": "object",
  "required": ["format", "version", "unidoc_type", "blocks"],
  "additionalProperties": false,
  "properties": {
    "$schema": { "const": "https://app.unidoc.top/schemas/udoc-json/v1.json" },
    "format": { "const": "udoc" },
    "version": { "const": 3 },
    "unidoc_type": { "const": "docs" },
    "basename": { "type": "string", "maxLength": 255 },
    "title": { "type": "string", "maxLength": 4096 },
    "page": { "type": "object" },
    "header": { "type": ["string", "object", "array", "null"] },
    "footer": { "type": ["string", "object", "array", "null"] },
    "pageNum": { "type": ["string", "object", "array", "null"] },
    "furniture": { "type": ["object", "array", "null"] },
    "comments": {
      "type": "array", "maxItems": 10000,
      "items": { "type": "object", "required": ["id", "text"],
        "properties": {
          "id": { "type": "string", "pattern": "^(0|[1-9][0-9]{0,14})$" },
          "text": { "type": "string" }, "author": { "type": "string" },
          "initials": { "type": "string" }, "date": { "type": "string" },
          "parentId": { "type": "string", "pattern": "^(0|[1-9][0-9]{0,14})$", "description": "Reply to another comment; replies reuse the parent's document anchor." },
          "resolved": { "type": "boolean" },
          "sourceXml": { "type": "string", "description": "Optional original self-contained comment XML, base64 encoded." }
        }
      }
    },
    "blocks": {
      "type": "array",
      "maxItems": 100000,
      "items": {
        "type": "object",
        "required": ["para_id", "html"],
        "properties": {
          "para_id": { "type": "integer", "minimum": 1 },
          "html": { "type": "string", "contentMediaType": "text/html" }
        },
        "additionalProperties": true
      }
    },
    "textboxes": {
      "type": "array",
      "maxItems": 2048,
      "items": {
        "type": "object",
        "required": ["id"],
        "properties": {
          "id": { "type": "string", "minLength": 1, "maxLength": 128 },
          "kind": { "type": "string" },
          "config": { "type": "object" }
        },
        "additionalProperties": true
      }
    },
    "music": { "type": "array", "maxItems": 256 },
    "pageBackgrounds": { "type": ["array", "object", "null"] },
    "penStrokes": { "type": ["array", "object", "null"] },
    "fonts": { "type": ["array", "object", "null"] },
    "embedFonts": { "type": ["array", "object", "boolean", "null"] },
    "resources": {
      "description": "Content-addressed package path to self-contained data URL. Decoded resources are limited to 64 MiB in aggregate by the normative validator.",
      "type": "object",
      "propertyNames": {
        "pattern": "^(media|attachments|embeds|resources)/[0-9a-f]{64}\\.[a-z0-9]{1,12}$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^data:[^;,\\s]+(?:;charset=[^;,\\s]+)?(?:;base64)?,"
      }
    }
  }
}
