Skip to content

Errors in "W3C" output #8

@c1rrus

Description

@c1rrus

First off, let me quickly say thank you for making this lovely tool. It's great to see new kinds of design token tools appear and, as one of the editors on the DTCG format, I'm also very excited to see tools that support the (draft) DTCG format! 😄

That being said, the output in the "W3C" tab1 does not currently conform to the current DTCG draft specification. Specifically:

  • There is no spacing type, you should output dimension tokens instead.
  • Values for the duration type must be in milliseconds, so "3s" should be converted to "3000ms". Also, the spec does not support the value paused (if you feel it should, you're welcome to propose that in a new issue).
  • There is no easing type, you should output cubicBezier tokens instead. Note that cubicBezier values need to be plain JSON arrays, so "cubic-bezier(0.12, 0, 0.39, 0)" should be converted to [0.12, 0, 0.39, 0].
    • If you want to combine cubic bezier and duration, you can use the transition type.
  • There is no radius type, you should output dimension here as well.
    • Since dimension values can only bepx or rem, the DTCG format doesn't currently have a proper way to represent % values (it probably should though!). You could fall back to using the string type for now, but be aware that type will be removed soon (another reason to add a proper type for percentage values to the spec! 😅).
  • There is no opacity type. The current draft does permit a number type, which you could use for now. Just like string above, that will be removed soon too. However, I see quite a few other tools supporting opacity tokens, so we'll need to add something to the spec to support those. Feedback and ideas welcome!
  • The values of the shadow tokens aren't valid - they need to follow the structure defined in the shadow type section.
    • Right now, the shadow type does not support multiple shadows. Hower, support for that has been proposed and I think it's likely that we'll update the spec to support that. Until then you could potentially split each shadow into a separate token and maybe append a number to the name or something like that (hacky, I know - but that's the best we can do right now).
  • There is no mediaQuery type, you should output dimension tokens there too.
  • The values for fontFamily tokens are probably not quite right. Right now you're outputting the whole font stack as a single string. Syntactically that's valid, but according to the spec tools should interpret that as a single font family name (so you're saying there is 1 font and it is called "Palatino Linotype, serif"). Since these appear to be font stacks, they should be converted into arrays like ["Palation Linotype", "serif"]. See the fontFamily type chapter for details.
  • There are no fontSize or letterSpacing types, you should output dimension tokens there too.
  • There is no lineHeight type, you should output number or dimension tokens there instead (with the caveat that the number type will be going away soon).

Finally, you probably shouldn't add the tokens groups. The current output is like this:

{
  "Color": {
    "$type": "color",
    "tokens": {
      "background-body": {
        "$value": "#233042"
      },
      // more tokens...
    }
  },
  // other groups...
}

However, the name tokens has no special meaning in the spec. So this is interpreted as: There is a group called "Color", which contains a nested group called "tokens", which contains a design token called "background-body". Since tools that convert to code would typically use the path to a token, the corresponding CSS output should be something like --color-tokens-background-body: #233043. That probably wasn't your intent. The solution is to just remove those intermediate tokens groups.

Putting it all together, the corrected "W3C" (DTCG) output should look something like this:

{
  "Color": {
    "$type": "color",
    "background-body": {
      "$value": "#233042"
    },
    "primary-body": {
      "$value": "#354156"
    }
  },
  "Spacing": {
    "$type": "dimension",
    "small": {
      "$value": "4px"
    },
    "medium": {
      "$value": "8px"
    }
  },
  "Duration": {
    "$type": "duration",
    "slow": {
      "$value": "3000ms"
    },
    "fast": {
      "$value": "500ms"
    }
  },
  "Easing": {
    "$type": "cubicBezier",
    "easeInSine": {
      "$value": [0.12, 0, 0.39, 0]
    }
  },
  "Radius": {
    "$type": "dimension",
    "circle": {
      "$type": "string",
      "$value": "50%"
    },
    "large": {
      "$value": "8px"
    },
    "small": {
      "$value": "2px"
    }
  },
  "Opacity": {
    "$type": "number",
    "opacity-25": {
      "$value": 0.25
    },
    "opacity-50": {
      "$value": 0.5
    }
  },
  "Shadow": {
    "$type": "shadow",
    "level-1_1": {
      "$value": {
       " color": "#00000024",
        "offsetX": "0px",
        "offsetY": "1px",
        "blur": "1px",
        "spread": "0px"
      }
    },
    "level-1_2": {
      "$value": {
        "color": "#0000001F",
        "offsetX": "0px",
        "offsetY": "2px",
        "blur": "1px",
        "spread": "-1px"
      }
    },
    "level-1_3": {
      "$value": {
        "color": "#00000033",
        "offsetX": "0px",
        "offsetY": "1px",
        "blur": "3px",
        "spread": "0px"
      }
    }
  },
  "Media Query": {
    "$type": "dimension",
    "max-width-mobile": {
      "$value": "600px"
    }
  },
  "Font Family": {
    "$type": "fontFamily",
    "body": {
      "$value": ["Arial", "Helvetica", "sans-serif"]
    }
  },
  "Font Size": {
    "$type": "dimension",
    "caption": {
      "$value": "12px"
    }
  },
  "Letter Spacing": {
    "$type": "dimension",
    "dense": {
      "$value": "-1px"
    }
  },
  "Line Height": {
    "$type": "number",
    "heading": {
      "$value": "1.25"
    }
  }
}

In principle, I'd be willing to submit PR(s) to fix these things. However, I'm pretty busy at the moment so probably won't have time to contribute fixes anytime soon. I therefore hope you don't mind me raising this issue to at least list out the issues in case someone else would like to try and fix them.

Footnotes

  1. Btw, we would be grateful if you could relabel that to something like "DTCG". While the DTCG is a W3C community group, we are not a W3C working group and our technical reports are not on a W3C standards track. More info here: https://www.designtokens.org/press-kit/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions