mdn-data

repository·main·Indexed 21 days ago

https://github.com/mdn/data

Structured JSON data representing Web technologies, including Web API inheritance hierarchies and comprehensive CSS specifications. It provides data on CSS at-rules, functions, properties, selectors, syntaxes, types, and units, used by MDN Web Docs and external tools like the CSSTree CSS parser. Note: this package is being deprecated in favor of w3c/webref.

Tokens
6.5K
Snippets
15
Records
26
Agent score
73%

What's inside mdn-data

  1. Overview of MDN CSS data structure

    main

    The css/ directory contains structured JSON data representing various features of the CSS language. This data is organized into specific categories, each accompanied by a JSON schema for validation and documentation files. Developers can use these JSON files to build tools, documentation sites, or validators that require authoritative CSS specifications.

    The data is categorized into the following types:

    • at-rules: Data regarding CSS @ rules.
    • functions: Data regarding CSS functions.
    • properties: Data regarding CSS properties.
    • selectors: Data regarding CSS selectors.
    • syntaxes: Data regarding CSS syntax patterns.
    • types: Data regarding CSS data types.
    • units: Data regarding CSS units.
  2. Overview of MDN data repository contents

    main

    This repository provides structured JSON data used by MDN Web Docs for information boxes and sidebar navigation, and by external tools like the CSSTree CSS parser. The data is organized into several top-level directories:

    • api: Contains Web API data, specifically focusing on API inheritance (interface inheritance and mixin implementations).
    • css: Contains comprehensive CSS data, including at-rules, functions, properties, selectors, syntaxes, types, and units.
    • l10n: Contains localization strings used across the various JSON data files in the repository.
  3. Understand the structure of Web API inheritance data

    main

    The inheritance data in mdn/mdn/data describes how Web API interfaces relate to one another through inheritance and mixins. The data is structured as a top-level object where each key is an interface name. Each interface entry must contain two properties:

    • inherits (string | null): The name of the parent interface from which the current interface inherits properties and methods. If the value is null, the interface does not inherit from any other interface.
    • implements (array of strings): A list of mixins that the interface implements. This can be an empty array [] if no mixins are implemented.
    "DocumentFragment": {
      "inherits": "Node",
      "implements": [
        "ParentNode",
        "LegacyQueryInterface"
      ]
    }
  4. Understand the syntax of CSS value functions

    main

    CSS value functions are statements that invoke special data processing or calculations to return a CSS value for a CSS property. They allow for complex data types and can take input arguments to calculate a return value.

    Syntax Structure

    A function's value syntax follows this pattern:

    1. The name of the function.
    2. An opening parenthesis (.
    3. One or more arguments.
    4. A closing parenthesis ).

    Argument Formatting

    Functions can take multiple arguments. The separator used between arguments depends on the specific function's notation:

    • Comma-separated: Some functions require arguments to be separated by commas.
    • Space-separated: Other functions use spaces to separate arguments.

    Whitespace is allowed inside the parentheses but is optional.

    General Syntax Template

    selector {
      property: function([argument]? [, argument]!);
    }
  5. Understand the structure of CSS selector data objects

    main

    In the mdn/mdn/data repository, CSS selectors are represented as JSON objects. Each selector object contains information about its syntax, the CSS modules it belongs to, and its standardization status. This data is useful for building tools that need to programmatically understand or list CSS selector capabilities.

    Each selector object must include the following properties:

    • syntax (string): The literal syntax of the selector (e.g., A ~ B, ::after, or :hover).
    • groups (array of strings): The names of the CSS modules where the selector is defined.
    • status (enum string): The standardization status. Valid values are standard, nonstandard, experimental, or obsolete.

    An optional property is:

    • mdn_url (string): A direct link to the selector's MDN documentation page. Note that this URL must omit localization segments (e.g., use /docs/Web/CSS/... instead of /en-US/docs/Web/CSS/...).
    "General sibling selectors": {
      "syntax": "A ~ B",
      "groups": [
        "Selectors"
      ],
      "status": "standard"
    }
  6. Understand the structure of CSS Property objects

    main

    The mdn-data CSS properties are represented as JSON objects. The structure of these objects differs depending on whether the property is a long-hand property or a short-hand property.

    Long-hand properties

    Long-hand properties typically use single values (strings or enums) for fields like animationType, percentages, initial, and computed.

    Short-hand properties

    Short-hand properties use arrays for fields like animationType, percentages, initial, and computed to list the constituent long-hand properties that the short-hand property controls or derives from.

    // Example Long-hand property
    "background-color": {
      "syntax": "<color>",
      "media": "visual",
      "inherited": false,
      "animationType": "color",
      "percentages": "no",
      "groups": ["CSS Background and Borders"],
      "initial": "transparent",
      "appliesto": "allElements",
      "computed": "computedColor",
      "order": "uniqueOrder",
      "alsoAppliesTo": ["::first-letter", "::first-line", "::placeholder"],
      "status": "standard"
    }
    
    // Example Short-hand property
    "background": {
      "syntax": "[ <bg-layer> , ]* <final-bg-layer>",
      "media": "visual",
      "inherited": false,
      "animationType": [
        "background-color",
        "background-image",
        "background-clip",
        "background-position",
        "background-size",
        "background-repeat",
        "background-attachment"
      ],
      "percentages": [
        "background-position",
        "background-size"
      ],
      "groups": ["CSS Background and Borders"],
      "initial": [
        "background-image",
        "background-position",
        "background-size",
        "background-repeat",
        "background-origin",
        "background-clip",
        "background-attachment",
        "background-color"
      ],
      "appliesto": "allElements",
      "computed": [
        "background-image",
        "background-position",
        "background-size",
        "background-repeat",
        "background-origin",
        "background-clip",
        "background-attachment",
        "background-color"
      ],
      "order": "orderOfAppearance",
      "alsoAppliesTo": ["::first-letter", "::first-line", "::placeholder"],
      "status": "standard"
    }
  7. Understand the structure of CSS unit data objects

    main

    In the mdn-data repository, CSS units (such as em or px) are represented as JSON objects. Each unit object must contain two required properties: groups and status.

    • groups (array of strings): An array containing the name(s) of the CSS module(s) where the unit is defined (e.g., "CSS Values and Units").
    • status (enum string): The standardization status of the unit. Valid values are standard, nonstandard, experimental, or obsolete.
    "ch": {
      "groups": [
        "CSS Values and Units"
      ],
      "status": "standard"
    }
  8. Handle CSS Custom Properties

    main
    Custom properties (CSS variables) are treated as a special case in the data. They use variable keys that must be prefixed with two dashes (e.g., --brand-color). These keys are validated against a regular expression defined in the patternProperties section of the schema.
  9. Understand CSS value definition syntax in mdn-data

    main

    The syntaxes.json file defines the formal syntax for CSS properties. In the MDN data structure, CSS properties (found in properties.json) use a syntax key to reference these definitions.

    Syntaxes can be simple keyword lists, combinations of CSS types (defined in types.md), or references to other syntaxes within syntaxes.json.

    Common syntax patterns include:

    • Keywords: Separated by a pipe (|), e.g., scroll | fixed | local.
    • Type references: Referencing CSS types like <number> or <percentage>.
    • Syntax nesting: Referencing other defined syntaxes, e.g., <length> | <percentage>.
    • Repetition: Using the # symbol to indicate that the preceding syntax can be repeated (e.g., <attachment>#).
    /* Example: background-attachment property definition */
    // In properties.json:
    "background-attachment": {
      "syntax": "<attachment>#"
    }
    
    /* Example: attachment syntax definition */
    // In syntaxes.json:
    "attachment": {
      "syntax": "scroll | fixed | local"
    }
  10. Publish a new version of mdn-data

    main

    Releases for mdn-data are published to both GitHub and the npm registry. The publishing process is automated using release-please and GitHub Actions. To trigger a new release, you must follow these requirements:

    1. Commit Convention: All commits must adhere to conventional commits. Only commits prefixed with fix: or feat: are recognized by the release automation.
    2. Release Pull Request: The release-please tool monitors the main branch. If it detects relevant fix: or feat: commits since the last release, it automatically opens a release pull request.
    3. Merging and Deployment: Once the release pull request is merged, the publish-release.yml workflow triggers. This workflow creates a GitHub release and publishes the updated package to npm.

    After the process completes, verify the release by checking the mdn-data package on npm.