Skip to content

Commit

Permalink
Add: options schema
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKoerner committed Jan 26, 2025
1 parent 01d5824 commit f56a5b7
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/schema/definition.json → src/schema/v1/definition.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$id": "https://static.dicebear.com/schema/definition.json#",
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://static.dicebear.com/schema/v1/definition.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "DiceBear definition schema",
"type": "object",
"properties": {
Expand Down
179 changes: 179 additions & 0 deletions src/schema/v1/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"$id": "https://static.dicebear.com/schema/v1/options.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "DiceBear options schema",
"type": "object",
"$defs": {
"flipDirection": {
"type": "string",
"enum": ["horizontal", "vertical", "both"]
},
"rotation": {
"type": "number",
"minimum": -360,
"maximum": 360
},
"scaleFactor": {
"type": "number",
"minimum": 0
},
"offset": {
"type": "number"
},
"cornerRadius": {
"type": "number",
"minimum": 0,
"maximum": 50
},
"color": {
"type": "string",
"pattern": "^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$"
}
},
"properties": {
"seed": {
"type": "string",
"description": "The starting value for the pseudorandom number generator (PRNG) used in the avatar generation process. This option is essential for creating unique and consistent avatars. By setting a specific seed, you ensure that the same sequence of random characteristics is applied, allowing identical avatars to be reproduced. This is especially valuable for maintaining consistency across sessions and allowing users to share or recreate their personalized avatars."
},
"size": {
"type": "integer",
"description": "Specifies the dimensions of the avatar in pixels. If no size is specified, the avatar defaults to a responsive design or scales to 100% of its container. This flexibility allows the avatar to seamlessly adapt to different screen sizes and layouts, ensuring optimal display across devices and environments.",
"minimum": 1
},
"idRandomization": {
"type": "boolean",
"description": "Generates random values for all IDs present in the SVG. This process ensures that while the avatar appears visually identical, the underlying code remains unique. This is particularly useful for embedding the same avatar multiple times in a document without running into duplicate ID conflicts that can interfere with styles and scripts."
},
"flipDirection": {
"description": "Specifies how the avatar will be flipped. Options include `horizontal` for a left-to-right flip, `vertical` for an upside-down flip, and `both' for a complete flip. This allows for flexible orientation customization of the avatar's appearance.",
"oneOf": [
{
"$ref": "#/$defs/flipDirection"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/flipDirection"
}
}
]
},
"scaleFactor": {
"description": "Sets the scaling of the avatar. The value can be a float or an integer, but will be interpreted as a percentage. A value of 100 corresponds to the original size of the avatar. This setting affects the size of the avatar itself, but not the size of the avatar container; any excess content will be clipped. If specified as an array, the PRNG will define a value between the two given values, including the values themselves.",
"oneOf": [
{
"$ref": "#/$defs/scaleFactor"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/scaleFactor"
},
"minItems": 2,
"maxItems": 2
}
]
},
"cornerRadius": {
"description": "This is the radius of the corners of the avatar. This value can be a float or an integer. A value of 0 means that the avatar has sharp corners, while larger values result in more rounded corners. The maximum value is 50, which turns the avatar into a complete circle. If specified as an array, the PRNG will define a value between the two given values, including the values themselves.",
"oneOf": [
{
"$ref": "#/$defs/cornerRadius"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/cornerRadius"
},
"minItems": 2,
"maxItems": 2
}
]
}
},
"patternProperties": {
"Probability$": {
"type": "number",
"description": "Represents the probability that a component of the avatar will be displayed. The value can be either a float or an integer, but is interpreted as a percentage. For example, a value of 0 means the part will never be displayed, while a value of 100 means it will always be displayed.",
"minimum": 0,
"maximum": 100
},
"Variant$": {
"description": "Specifies which variants of the avatar part can be selected by the PRNG. If specified as a string or as an array with only one value, the value is fixed. However, if specified as an array with multiple values, the PRNG will choose from the available options.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"Color$": {
"description": "Specifies which colors for the avatar component can be selected by the PRNG. If specified as a string or array with only one value, the value is fixed. However, if specified as an array with multiple values, the PRNG will choose from the available options. The color must be specified as a hex value.",
"oneOf": [
{
"$ref": "#/$defs/color"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/color"
}
}
]
},
"(^r|R)otation": {
"description": "This is the rotation angle for the avatar or its parts. This value can be an integer or a float. A value of 0 results in no rotation, while values between -360 and 360 define the degree of rotation in both directions. If specified as an array, the PRNG will select a value within the specified range, including the values themselves. If not preceded by an avatar part, the option applies to the entire avatar.",
"oneOf": [
{
"$ref": "#/$defs/rotation"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/rotation"
},
"minItems": 2,
"maxItems": 2
}
]
},
"(^v|V)erticalOffset$": {
"description": "This is the vertical offset of the avatar or its parts. This value can be an integer or a float. A value of 0 results in no offset, while positive values move the part down as a percentage and negative values move it up as a percentage. If specified as an array, the PRNG will select a value within the specified range, including the values themselves. If no avatar part is specified, the option applies to the entire avatar.",
"oneOf": [
{
"$ref": "#/$defs/offset"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/offset"
},
"minItems": 2,
"maxItems": 2
}
]
},
"(^h|H)orizontalOffset$": {
"description": "This is the horizontal offset of the avatar or its parts. This value can be an integer or a float. A value of 0 results in no offset, while positive values move the part to the right as a percentage and negative values move it to the left as a percentage. If specified as an array, the PRNG will select a value within the specified range, including the values themselves. If no avatar part is specified, the option applies to the entire avatar.",
"oneOf": [
{
"$ref": "#/$defs/offset"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/offset"
},
"minItems": 2,
"maxItems": 2
}
]
}
},
"additionalProperties": false
}

0 comments on commit f56a5b7

Please sign in to comment.