Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensible Types #221

Open
matthewsimo opened this issue Jun 21, 2023 · 2 comments
Open

Extensible Types #221

matthewsimo opened this issue Jun 21, 2023 · 2 comments

Comments

@matthewsimo
Copy link

I think for the specification to be applicable by platforms other than the web the specification should include a way to define custom types.

In otherwords, I think it will be useful for the specification to allow a way to define schema in the top level of the document that can be used later in that same document. An example that could act as a model is how the openapi spec does this to allow for composable advanced types for APIs. Nothing as complication should be necessary but something in that direction could provide the necessary extensibility.

24bit RGB or 24+8bit RGBA color in the sRGB color space is entirely reasonable for the web but becomes limiting especially as more and more displays are commonly supporting larger color gamuts.

For example, something like this.

{
  "$schemas": [{
    "$name": "hex-color"
    "$ref": "https://www.w3.org/TR/css-color-4/#hex-notation",
    "$version": "1.0.0"
  }],
  "Majestic magenta": {
    "$value": "#ff00ff",
    "$type": "$schemas.hex-color"
  },
  "Translucent shadow": {
    "$value": "#00000080",
    "$type": "$schemas.hex-color"
  }
}

Likewise, the supported values for the dimension type seems limiting too. For a web client, px and rem is a reasonable baseline even if they are only a fraction of the supported length units. Personally, I'd want at least the absolute and font based relative CSS length units. Though there's also a strong argument for both viewport and container relative length units too. Many of these don't make sense for many platforms that tokens are consumed, but providing a way to define types helps avoid the issue.

If schemas support external references they would keep their footprint within the .tokens or .tokens.json file minimal. This would also allow platforms and tools to maintain their own declarations the community could benefit from and provide an easy path forward on providing Enums for the CSS Keywords I've seen discussed in other tickets.

Thanks for taking the time to read and consider.

@nesquarx
Copy link

nesquarx commented Jun 21, 2023 via email

@matthewsimo
Copy link
Author

Ideally, I'd think the spec should define a comprehensive list of useful types, including oklab & oklch.

However, with the extensible types idea I'm proposing it could look something like this:

{
  "$schemas": {
    "oklch-color": {
      "$properties": {
        "l": {
          "$name": "lightness",
          "$types": ["percentage", "number"],
        },
        "c": {
          "$name": "chroma",
          "$types": ["percentage", "number"],
        },
        "h": {
          "$name": "hue",
          "$types": ["number", "angle"],
        }
      },
    },
  },
  "Majestic magenta": {
    "$value": {
      l: "70.17%",
      c: 0.322, 
      h: 328.36,
    },
    "$type": "$schemas.oklch-color"
  },
}

Note: This is inspired by the openapi spec and I'm not necessarily promoting this format or structure - it's just for illustrative purposes. Also, it assumes some generic types that the spec provides like "percentage", "number", "angle", which I'm taking from https://www.w3.org/TR/css-values-4/#numeric-types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants