-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax is too complex #1
Description
Hey @ddamato,
thank you for taking a test-drive here. I've pioneered operations/transforms (as style-dictionary is calling them) with Theemo. As I'm currently reworking theemo to support variables I also need to touch this. Of course I looked at your post, but also I wrote mine at the same time. We aren't that far off. So I'm aiming to suggest a combination of the both formats to make it a bit more readable on the syntax.
Problem: Using the array for two sort of types (primtive as value + array as function) is overloading. Then it becomes looking like a regex with $0 and $1.
Solution: Function programming, more exactly: piping + currying (= parameters), see the great video from Scott Wlaschin.
The syntax would change to:
{
"token-name": {
"$type": "color",
"$value": "blue",
"$operations": [
["opacity", 25], // function name "opacity" with parameter "25"
["hue", -25], // function name "hue" rotate by -25 degree
]
}
}The input to the opacity function is $value the result of that function is put into the hue function, the result of that is the final value.
Going a bit more complex with references and other tokens as input:
{
"opacity": {
"$type": "number", // huh? Is that a type?
"$value": 25
},
"token-name": {
"$type": "color",
"$value": "blue",
"$operations": [
["opacity", "{opacity}"], // function name "opacity" with parameter being a reference token
]
}
}Let's say I do have a opacity25 function (that always add 25% of opacity):
{
"token-name": {
"$type": "color",
"$value": "blue",
"$operations": [
"opacity25"
]
}
}That is the operations is an array of a string value (referring to a function) or a tuple with [functionName, parameters]. Paramters can be a complex object:
{
"token-name": {
"$type": "color",
"$value": "blue",
"$operations": [
["leonardo", { ... }]
]
}
}
Referring to operations as function names, gives them readability, as I know what hue or opacity means, but I've almost never seen an algorithmic representation in json that was readable.
About function names:
At the moment, I consider them need to be registered from the tools processing the tokens, such that style dictionary does that. We cannot even assume that the tooling is always using javascript (and therefore the node ecosystem).
Possibly: These function names are actually forward translatable into CSS functions: Which when you do a dev export of tokens (ie. even color palettes), then you can create this fluent theme generator (in a sandbox, not for production).