{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jsoncut.com/schemas/v2/project-source.schema.json",
  "title": "JsonCut V2 project source",
  "description": "Public jsoncut-html source envelope. Layer attributes inside html are additionally validated by JsonCut.",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "version", "id", "name", "width", "height", "fps", "duration", "html", "css", "variables", "values"],
  "properties": {
    "format": { "const": "jsoncut-html" },
    "version": { "const": 1 },
    "id": { "type": "string", "minLength": 1 },
    "name": { "type": "string", "minLength": 1 },
    "compositionKind": { "enum": ["image", "video"], "default": "video" },
    "width": { "type": "integer", "minimum": 1, "maximum": 3840 },
    "height": { "type": "integer", "minimum": 1, "maximum": 2160 },
    "fps": { "type": "integer", "minimum": 1, "maximum": 60 },
    "duration": { "type": "number", "exclusiveMinimum": 0, "maximum": 1200 },
    "canvasBackground": { "type": "string", "default": "#000000" },
    "safeArea": { "$ref": "#/$defs/safeArea" },
    "aspectVariants": {
      "type": "array",
      "maxItems": 12,
      "items": { "$ref": "#/$defs/aspectVariant" },
      "default": []
    },
    "html": { "type": "string", "maxLength": 5242880 },
    "css": { "type": "string", "maxLength": 5242880 },
    "customBlocks": {
      "type": "array",
      "items": { "$ref": "#/$defs/customBlock" },
      "default": []
    },
    "variables": {
      "type": "array",
      "maxItems": 250,
      "items": { "$ref": "#/$defs/variable" }
    },
    "values": { "type": "object" }
  },
  "allOf": [
    {
      "if": { "properties": { "compositionKind": { "const": "image" } }, "required": ["compositionKind"] },
      "then": { "properties": { "fps": { "const": 1 }, "duration": { "const": 1 } } }
    }
  ],
  "$defs": {
    "safeArea": {
      "type": "object",
      "additionalProperties": false,
      "required": ["top", "right", "bottom", "left"],
      "properties": {
        "top": { "type": "number", "minimum": 0 },
        "right": { "type": "number", "minimum": 0 },
        "bottom": { "type": "number", "minimum": 0 },
        "left": { "type": "number", "minimum": 0 }
      }
    },
    "aspectVariant": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "width", "height"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
        "label": { "type": "string", "minLength": 1 },
        "width": { "type": "integer", "minimum": 64, "maximum": 8192 },
        "height": { "type": "integer", "minimum": 64, "maximum": 8192 },
        "safeArea": { "$ref": "#/$defs/safeArea" }
      }
    },
    "variable": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "type", "default"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,127}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 120 },
        "type": { "enum": ["string", "number", "color", "boolean", "image", "video", "audio", "html", "array"] },
        "default": { "oneOf": [{ "type": "string" }, { "type": "number" }, { "type": "boolean" }, { "type": "array", "maxItems": 100, "items": { "type": "string", "maxLength": 1000 } }] },
        "min": { "type": "number" },
        "max": { "type": "number" },
        "step": { "type": "number", "exclusiveMinimum": 0 },
        "unit": { "type": "string", "maxLength": 40 }
      }
    },
    "customBlockValue": {
      "oneOf": [
        { "type": ["string", "number", "boolean", "null"] },
        { "type": "array", "items": { "$ref": "#/$defs/customBlockValue" } },
        { "type": "object", "additionalProperties": { "$ref": "#/$defs/customBlockValue" } }
      ]
    },
    "customBlock": {
      "type": "object",
      "additionalProperties": false,
      "required": ["layerId", "adapter", "inputs"],
      "anyOf": [{ "required": ["javascript"] }, { "required": ["source"] }],
      "properties": {
        "layerId": { "type": "string", "minLength": 1 },
        "adapter": { "enum": ["canvas-2d", "svg", "dom", "webgl"] },
        "html": { "type": "string" },
        "css": { "type": "string" },
        "javascript": { "type": "string" },
        "source": { "type": "string", "deprecated": true },
        "inputs": { "type": "object", "additionalProperties": { "$ref": "#/$defs/customBlockValue" } }
      }
    }
  }
}
