-
Notifications
You must be signed in to change notification settings - Fork 63
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
Types for CSS Keywords #177
Comments
The CSS part is maybe a bit misleading. |
@chris-dura said :
|
I think you misunderstood :) Keyword: .foo {
text-align: center;
} String: .foo {
content: "string content";
} But in JSON both need to be stored as strings : {
"$value": "center"
} {
"$value": "string content"
} But all languages/platforms have keywords: {
"$value": "infinity"
} const foo = Infinity; |
This issue is partly resolved by these recent resolutions :
These removed a lot of ambiguity. For some platforms the @font-face {
font-family: "serif";
src: ...
}
.foo {
font-family: "serif";
} or .foo {
font-family: serif;
} iOS seems to have the same concepts : class func monospacedSystemFont(
ofSize fontSize: CGFloat,
weight: UIFont.Weight
) -> UIFont |
I think the underlying issue is this :
User defined values :
Typically strings, numbers, ... Platform defined values : Typically keywords, enums, functions, ... Some platform defined values have equivalents in all or most platforms. |
Yes, sorry, I was using "string" to mean "a piece of text". I think many use cases can be covered by defining escape sequences (#171). That will help an author in cases like: {
"keyword-like-font-name": {
"$value": "Helvetica",
"$type": "string"
},
"string-like-font-name": {
"$value": "\"Helvetica\"",
"$type": "string"
}
} (maybe Which, when translated into css variables, would result in the following. :root {
--keyword-like-font-name: Helvetica;
--string-like-font-name: "Helvetica";
} If you'll forgive the pedantry, in this example, {
"$value": "infinity"
} const foo = Infinity;
The cases that are not covered by the Your font example is the most salient one. In CSS, the keyword for "the default system font" is Which leads to the question: should translators be required to maintain the mapping these one-to-many keyword values in tokens to the correct platform-specific versions? Or should the spec allow for the author to provide the mapping? Or both? |
That is incorrect. To address the underlying numeric value you need to use a platform specific API. Escaping quotes will not work. What if one of the target platforms uses parentheses as string start and end tokens.
|
Generally, I think "the Tokens spec" should be as agnostic as possible... obviously it's very "CSS-leaning" (as evidenced by the title of this issue)... but "how to represent platform-specific syntax" seems fully the responsibility of the translators/transformers/tools, in my opinion. {
"keyword-like-font-name": {
"$value": "Helvetica",
"$type": "string"
"$extensions": {
"isCssKeyword": true,
},
},
} ... then in the transform layer, I'd hook into |
This is partly true. But this specification does need to define the supported/adopted concepts.
This specification does not define Translation tools might also provide a public API so that users of those tools can provide fallback/custom values for concepts that do not have a platform specific equivalent.
Do you have concrete examples? Maybe best to open specific issues here for each. |
Fair, but I'm not sure platform-specific things qualify as "basic"... at least not across the board. It kind of smells to me that an arbitrary update to iOS/Swift that Apple decides to make would/could require an update to the Tokens spec to support some new type or syntax in iOS 17? But, as you somewhat said, the "concept" of a keyword (or even more agnostic... the concept of an "unquoted string" type) may be universal enough to warrant placement in the spec?
Tbf, I'm mostly using $extensions: {
deprecated: {
renamed: "new-token-name",
message: "@deprecated: Replace with 'new-token-name' token",
},
swift: {
available: {
platform: "iOS 13",
introduced: "4.0.0",
deprecated: "4.1.0",
obsoleted: "5.0.0",
unavailable: true,
},
optional: true,
type: "UInt",
},
tier: "option" | "intent" | "component" | "decision"
}, Most of the above values are used in some custom output formats I've created. For example, I have a custom Swift format that outputs some However, the |
Hehe, no, it has to be the other way around. {
"$type": "unquoted-string", // or "keyword", "raw", ...
"$value": "system-ui"
} This token can only work in CSS. {
"$type": "fontFamilyKeyword",
"$value": "systemUI"
} This is different from the regular Instead of generating a string value (
This works because there are two bits of information :
There are multiple ways to have the same outcome : {
"$type": "fontFamily",
"$keyword": true,
"$value": "systemUI"
} ... abusing/overloading the word "keyword" a bit, but it is closest to what is intended |
Do we need types for CSS Keywords that aren't strings: like
text-align
values:left
,right
,center
etc.The text was updated successfully, but these errors were encountered: