{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://noodles.gl/schema/noodles-project.schema.json",
  "title": "Noodles.gl project document (version 1)",
  "description": "A noodles.json document. Covers file shape only; check operators, parameters and ports with noodles-validate.",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "version": {
      "type": "number",
      "const": 1,
      "description": "Document version"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "description": "Opaque and stable; edges and parent name nodes by id"
          },
          "op": {
            "type": "string",
            "minLength": 1,
            "description": "Operator type, e.g. file, scatter, deck"
          },
          "name": {
            "description": "Unique within its network; paths use it. Defaults to the id",
            "type": "string",
            "pattern": "^[^/\\s]+$"
          },
          "parent": {
            "description": "Id of the subnet it is inside; absent at the root",
            "type": "string"
          },
          "x": {
            "type": "number"
          },
          "y": {
            "type": "number"
          },
          "params": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "$ref": "#/$defs/ParamValue"
            },
            "description": "Parameters that differ from the defaults, by name"
          },
          "flags": {
            "type": "object",
            "properties": {
              "bypass": {
                "description": "Pass the first table input through",
                "type": "boolean"
              },
              "display": {
                "description": "Preview the node's rows",
                "type": "boolean"
              }
            },
            "additionalProperties": false
          },
          "promoted": {
            "description": "A subnet's parameters, each driving a child's parameter",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "node": {
                  "type": "string",
                  "description": "The child's id"
                },
                "param": {
                  "type": "string"
                }
              },
              "required": [
                "name",
                "node",
                "param"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "id",
          "op",
          "x",
          "y",
          "params"
        ],
        "additionalProperties": false
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "type": "string",
            "minLength": 1,
            "description": "Node id"
          },
          "sourcePort": {
            "type": "string",
            "minLength": 1,
            "description": "An output port, e.g. out"
          },
          "target": {
            "type": "string",
            "minLength": 1,
            "description": "Node id"
          },
          "targetPort": {
            "type": "string",
            "minLength": 1,
            "description": "An input port, e.g. in, or par:<name> to drive a parameter"
          },
          "index": {
            "description": "Order among edges into a multi-input port, such as the deck's layers",
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "id",
          "source",
          "sourcePort",
          "target",
          "targetPort"
        ],
        "additionalProperties": false
      }
    },
    "timeline": {
      "type": "object",
      "properties": {
        "length": {
          "type": "number",
          "exclusiveMinimum": 0,
          "description": "Seconds"
        },
        "fps": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "tracks": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "target": {
                "type": "string",
                "pattern": "^[^.]+\\..+$",
                "description": "The parameter it drives: <node id>.<param>, e.g. deck.bearing"
              },
              "keyframes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "time": {
                      "type": "number",
                      "minimum": 0,
                      "description": "Seconds"
                    },
                    "value": {
                      "anyOf": [
                        {
                          "type": "number"
                        },
                        {
                          "type": "string"
                        }
                      ],
                      "description": "A number eases; text holds"
                    },
                    "interpolation": {
                      "type": "string",
                      "enum": [
                        "bezier",
                        "linear",
                        "hold"
                      ],
                      "description": "How the segment leaving this keyframe interpolates"
                    },
                    "handles": {
                      "description": "Bezier control points, as CSS cubic-bezier(left, right)",
                      "type": "object",
                      "properties": {
                        "left": {
                          "type": "array",
                          "prefixItems": [
                            {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            },
                            {
                              "type": "number"
                            }
                          ],
                          "minItems": 2,
                          "maxItems": 2
                        },
                        "right": {
                          "type": "array",
                          "prefixItems": [
                            {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            },
                            {
                              "type": "number"
                            }
                          ],
                          "minItems": 2,
                          "maxItems": 2
                        }
                      },
                      "required": [
                        "left",
                        "right"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "id",
                    "time",
                    "value",
                    "interpolation"
                  ],
                  "additionalProperties": false
                },
                "description": "Sorted by time"
              }
            },
            "required": [
              "target",
              "keyframes"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "length",
        "fps",
        "tracks"
      ],
      "additionalProperties": false
    },
    "credits": {
      "description": "Attribution for the data it uses",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "meta": {
      "description": "Editor state saved with it, such as the viewport",
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {}
    }
  },
  "required": [
    "version",
    "name",
    "nodes",
    "edges"
  ],
  "additionalProperties": false,
  "$defs": {
    "ParamValue": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "string"
        },
        {
          "type": "object",
          "properties": {
            "expr": {
              "type": "string"
            }
          },
          "required": [
            "expr"
          ],
          "additionalProperties": false,
          "description": "An expression: T seconds, F frame, ch('node/param'), math"
        },
        {
          "type": "object",
          "properties": {
            "ref": {
              "type": "string"
            }
          },
          "required": [
            "ref"
          ],
          "additionalProperties": false,
          "description": "Another node's parameter, e.g. points/radius"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "JsonValue": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "string"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    }
  }
}
