{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tryscormcraft.com/schemas/theme-pack/1.json",
  "title": "SCORMCraft theme pack (theme.json)",
  "description": "The manifest of a .scormcrafttheme file. It covers the pack's own fields exactly; the theme and each template slide are SCORMCraft course JSON, which SCORMCraft checks in full on import (this schema describes their outline and the colour rule).",
  "type": "object",
  "additionalProperties": false,
  "required": ["scormcraftThemePack", "id", "name", "version", "theme"],
  "properties": {
    "$schema": { "type": "string", "maxLength": 2048, "description": "This schema's URL, so an editor checks the file as it is written. SCORMCraft ignores it." },
    "scormcraftThemePack": { "const": 1, "description": "The format version." },
    "id": { "$ref": "#/$defs/packId", "description": "Importing the same id again replaces the pack when the version is newer." },
    "name": { "type": "string", "minLength": 1, "maxLength": 200 },
    "version": { "type": "string", "pattern": "^[0-9]{1,9}\\.[0-9]{1,9}\\.[0-9]{1,9}$", "examples": ["1.0.0"] },
    "description": { "type": "string", "maxLength": 100000 },
    "theme": { "$ref": "#/$defs/theme" },
    "colorways": { "type": "array", "maxItems": 24, "items": { "$ref": "#/$defs/colorway" } },
    "fonts": { "type": "array", "maxItems": 16, "items": { "$ref": "#/$defs/font" } },
    "templates": { "type": "array", "maxItems": 100, "items": { "$ref": "#/$defs/template" } }
  },
  "$defs": {
    "packId": { "type": "string", "pattern": "^[a-z0-9-]{1,64}$" },
    "colorKey": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,31}$" },
    "uuid": { "type": "string", "pattern": "^([a-z]+-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" },
    "color": {
      "description": "#rgb, #rrggbb, #rrggbbaa, rgb()/rgba(), hsl()/hsla(), transparent, currentColor, or var(--pd-<name>) naming a theme colour. Nothing else, and no fallback inside var().",
      "type": "string",
      "maxLength": 42,
      "pattern": "^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgba?\\(.+\\)|hsla?\\(.+\\)|transparent|currentColor|var\\(--pd-[a-z][a-z0-9-]{0,31}\\))$"
    },
    "colorRoles": {
      "type": "object",
      "properties": {
        "primary": { "$ref": "#/$defs/color" },
        "secondary": { "$ref": "#/$defs/color" },
        "accent": { "$ref": "#/$defs/color" },
        "background": { "$ref": "#/$defs/color" },
        "surface": { "$ref": "#/$defs/color" },
        "text": { "$ref": "#/$defs/color" },
        "textLight": { "$ref": "#/$defs/color" },
        "success": { "$ref": "#/$defs/color" },
        "error": { "$ref": "#/$defs/color" },
        "warning": { "$ref": "#/$defs/color" },
        "palette": {
          "description": "Extra named colours, each usable as var(--pd-<name>).",
          "type": "object",
          "maxProperties": 64,
          "propertyNames": { "$ref": "#/$defs/colorKey" },
          "additionalProperties": { "$ref": "#/$defs/color" }
        }
      }
    },
    "theme": {
      "description": "SCORMCraft's Theme (crates/core/src/schema/course.rs). Leave out theme.pack: the studio sets it.",
      "type": "object",
      "required": ["id", "name"],
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string", "minLength": 1 },
        "colors": { "$ref": "#/$defs/colorRoles" },
        "fonts": {
          "type": "object",
          "properties": {
            "heading": { "type": "string", "description": "A font family: a name in fonts[].family, or a system font." },
            "body": { "type": "string" }
          }
        },
        "logo": { "type": "string" },
        "playerChrome": { "type": "object", "description": "Colours here are outside the stage: use literal colours, not var()." },
        "backgroundStack": { "type": "object" },
        "textStyles": { "type": "array" },
        "buttonStyles": { "type": "array" },
        "questionChrome": { "type": "object" }
      },
      "not": { "required": ["pack"] }
    },
    "colorway": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "palette"],
      "properties": {
        "id": { "$ref": "#/$defs/packId" },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "palette": {
          "description": "Merged over the theme's palette. A name that is one of the fixed colours (primary, secondary, accent, background, surface, text, text-light, success, error, warning) replaces that colour too.",
          "type": "object",
          "minProperties": 1,
          "maxProperties": 64,
          "propertyNames": { "$ref": "#/$defs/colorKey" },
          "additionalProperties": { "$ref": "#/$defs/color" }
        }
      }
    },
    "font": {
      "description": "SCORMCraft's FontEntry (crates/core/src/schema/media.rs). The file is in the zip.",
      "type": "object",
      "required": ["id", "family", "source", "url"],
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "family": { "type": "string", "minLength": 1, "maxLength": 200 },
        "source": { "const": "uploaded" },
        "weights": {
          "description": "One weight for a static file; two or more for a variable font, which covers the lowest to the highest.",
          "type": "array",
          "maxItems": 9,
          "items": { "enum": ["100", "200", "300", "400", "500", "600", "700", "800", "900"] }
        },
        "italic": { "type": "boolean" },
        "url": { "type": "string", "pattern": "^fonts/[^/]+\\.(woff2|woff|ttf|otf)$" },
        "fallback": { "type": "string", "description": "serif, sans-serif, monospace, cursive or system-ui. Anything else is read as sans-serif." }
      },
      "not": { "required": ["assetId"] }
    },
    "template": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "category", "slide"],
      "properties": {
        "id": { "$ref": "#/$defs/packId" },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "category": { "enum": ["series", "cover", "divider", "concept", "steps", "checklist", "quiz", "summary", "other"] },
        "description": { "type": "string" },
        "slide": {
          "description": "A SCORMCraft Slide: type content, quiz or results (not quiz-pool). Every id is a UUID, optionally prefixed (text-<uuid>). Positions are absolute stage pixels, 1280x720 by default.",
          "type": "object",
          "required": ["id", "name", "type"],
          "properties": {
            "id": { "$ref": "#/$defs/uuid" },
            "name": { "type": "string", "minLength": 1 },
            "type": { "enum": ["content", "quiz", "results"] },
            "blocks": { "type": "array", "items": { "type": "object", "required": ["id", "type", "position", "size"] } }
          }
        }
      }
    }
  }
}
