Repository navigation
feat(native): Swift theme generator reads the CSS colors and lengths its spec lists - #8420
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Package | Where | Signature | Usage | |
|---|---|---|---|---|
| + | core |
. · Types · interface FieldStatusProps |
message: string |
import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {message: …} |
| + | core |
. · Types · interface FieldStatusProps |
ref?: React.Ref<HTMLDivElement> |
import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {ref: …} |
| + | core |
. · Types · interface FieldStatusProps |
type: InputStatusType |
import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {type: …} |
| + | core |
. · Types · interface FieldStatusProps |
variant?: FieldStatusVariant = 'attached' |
import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {variant: …} |
| + | core |
. · Types · interface FieldStatusProps |
xstyle?: StyleXStyles |
import type {FieldStatusProps} from '@astryxdesign/core'; const x: FieldStatusProps = {xstyle: …} |
| + | core |
. · Types · interface FieldStatusProps |
inherits AriaAttributes, DOMAttributes, HTMLAttributes |
import type {FieldStatusProps} from '@astryxdesign/core' |
| + | core |
. · Types · interface SearchContext |
interface SearchContext<T extends SearchableItem = SearchableItem> |
import type {SearchContext} from '@astryxdesign/core' |
| + | core |
./Typeahead · Also exported from an earlier entry point · SearchContext |
SearchContext (.) |
import {SearchContext} from '@astryxdesign/core/Typeahead' |
| ~ | core |
. · Components · component ComplexSelector |
prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors |
<ComplexSelector statusVariant="attached" /> |
| ~ | core |
. · Components · component DateInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<DateInput statusVariant="attached" /> |
| ~ | core |
. · Components · component DateRangeInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<DateRangeInput statusVariant="attached" /> |
| ~ | core |
. · Components · component Field |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<Field statusVariant="attached" /> |
| ~ | core |
. · Components · component FieldStatus |
component FieldStatus(props: FieldStatusProps) → component FieldStatus @deprecated |
<FieldStatus /> |
| ~ | core |
. · Components · component FieldStatus |
prop variant?: FieldStatusVariant = 'attached' → prop variant: FieldStatusVariant = 'attached' |
<FieldStatus variant="attached" /> |
| ~ | core |
. · Components · component FileInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<FileInput statusVariant="attached" /> |
| ~ | core |
. · Components · component MultiSelector |
prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary and ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary and ghost selectors |
<MultiSelector statusVariant="attached" /> |
| ~ | core |
. · Components · component NumberInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<NumberInput statusVariant="attached" /> |
| ~ | core |
. · Components · component PowerSearch |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<PowerSearch statusVariant="attached" /> |
| ~ | core |
. · Components · component Selector |
prop statusVariant?: FieldStatusVariant = 'attached' for input selectors; 'detached' for secondary/ghost selectors → prop statusVariant?: FieldStatusPlacement = 'attached' for input selectors; 'detached' for secondary/ghost selectors |
<Selector statusVariant="attached" /> |
| ~ | core |
. · Components · component TextArea |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<TextArea statusVariant="attached" /> |
| ~ | core |
. · Components · component TextInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<TextInput statusVariant="attached" /> |
| ~ | core |
. · Components · component TimeInput |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<TimeInput statusVariant="attached" /> |
| ~ | core |
. · Components · component Tokenizer |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<Tokenizer statusVariant="attached" /> |
| ~ | core |
. · Components · component Typeahead |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusPlacement = 'attached' |
<Typeahead statusVariant="attached" /> |
| ~ | core |
. · Types · interface FieldStatusProps |
interface FieldStatusProps extends BaseProps<HTMLDivElement> (props of FieldStatus) → interface FieldStatusProps extends BaseProps<HTMLDivElement> |
import type {FieldStatusProps} from '@astryxdesign/core' |
| ~ | core |
. · Types · interface FieldStatusVariantMap |
tooltip: true → tooltip: true @deprecated |
import type {FieldStatusVariantMap} from '@astryxdesign/core'; const x: FieldStatusVariantMap = {tooltip: …} |
| ~ | core |
. · Types · interface SearchSource |
search: (query: string) => Promise<T[]> | T[] → search: (query: string, context?: SearchContext<T>) => Promise<T[]> | T[] |
import type {SearchSource} from '@astryxdesign/core'; const x: SearchSource = {search: …} |
| ~ | core |
. · Types · interface UseInputStatusIconOptions |
statusVariant?: FieldStatusVariant → statusVariant?: FieldStatusPlacement |
import type {UseInputStatusIconOptions} from '@astryxdesign/core'; const x: UseInputStatusIconOptions = {statusVariant: …} |
| ~ | richtext |
. · Components · component RichTextEditor |
prop statusVariant?: FieldStatusVariant = 'attached' → prop statusVariant?: FieldStatusVariant | 'tooltip' = 'attached' |
<RichTextEditor statusVariant="tooltip" /> |
Wide change (shared styles: packages/native/src/theme/swiftIOSTheme.test.ts): add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
dcdbaf9 to
35d4efe
Compare
a63734c to
f239feb
Compare
f239feb to
7c2eba2
Compare
35d4efe to
adce2d0
Compare
7c2eba2 to
d9985b4
Compare
413f374 to
e56c79d
Compare
d9985b4 to
3aea90f
Compare
3aea90f to
c661973
Compare
c661973 to
6938475
Compare
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements, and an engineering owner records approval by commenting /approve-spec 693847573076ac7fa639e6675df2d6bd0c6bdbe5 on this pull request (the author may do so as an engineering owner). Separately, a few conversions give Swift a different value than the web draws for the same token and need fixing whatever that decision is:
- Relative
rgb()/hwb()reuse the literal-value clamps, sorgb(from var(--color-accent) r g b / 50%)over anoklch()accent comes out as sRGB#F10000while the accent itself stays Display P3 (css-values.mjs,colorFunction). toLeadingreadsemagainst the 16 pt root, so1.5emon a 14px style becomes 1.714 instead of 1.5.toPointsreadsmediumas a 3 pt border width for every length, including font sizes, where it means 16px.- Three
color-mix()edge readings (anonealpha, Labbtreated as blue, hues above 360°) differ from CSS Color 4.
[Automated review]
| if (fn.clamp) | ||
| coords = coords.map(v => | ||
| Number.isNaN(v) ? v : Math.min(fn.clamp[1], Math.max(fn.clamp[0], v)), | ||
| ); | ||
| if (fn.scale) coords = coords.map(v => v * fn.scale); | ||
| if (fn.space === 'hsl' || fn.space === 'hwb') { | ||
| coords = coords.map((v, i) => | ||
| i === 0 | ||
| ? v | ||
| : Math.max(0, i === 2 && fn.space === 'hsl' ? Math.min(100, v) : v), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Relative colors reuse the literal-value clamps here, so a wide-gamut origin is clipped: with --color-accent: oklch(0.6 0.25 30), rgb(from var(--color-accent) r g b / 50%) generates Color(astryxRGBA: 0xF1000080) (sRGB #F10000) next to an accent generated as Display P3 221 / 255, 45 / 255, 25 / 255, while CSS keeps the origin's channels. Skipping these clamps when the function has a from origin fixes it, and a table row such as rgb(from color(display-p3 1 0 0) r g b) → display-p3 #FF0000FF would pin it.
| if (q.k === 'length') { | ||
| if (!fontSize) fail("a length line height needs its style's font size"); | ||
| return Number((q.v / fontSize).toPrecision(12)); | ||
| } |
There was a problem hiding this comment.
By this point quantity has turned em into 16 px, so 1.5em on a 14px style becomes 1.71428571429 (a 24 pt line). In a line height em is the element's own font size, and the theme sets font-size and line-height on the same element, so the web draws 1.5. Reading em against fontSize in this branch gives the exact multiplier.
| return quantity(tokens[0], null, notes); | ||
| } | ||
|
|
||
| const BORDER_KEYWORDS = {thin: 1, medium: 3, thick: 5}; |
There was a problem hiding this comment.
These are border-width keywords, but toPoints applies them to every length token: --text-large-size: medium generates size: 3, while font-size: medium is 16px on the web, and in spacing or radius tokens the keywords are not valid CSS. Limiting them to --border-width, and reading a font-size medium as 16 or failing, keeps Swift and the web in step.
| if (i === hueAt) { | ||
| let [h1, h2] = [x, y]; | ||
| const d = h2 - h1; | ||
| if (hue === 'shorter') d > 180 ? (h1 += 360) : d < -180 && (h2 += 360); | ||
| else if (hue === 'longer') | ||
| d > 0 && d < 180 ? (h1 += 360) : d > -180 && d <= 0 && (h2 += 360); | ||
| else if (hue === 'increasing') h2 < h1 && (h2 += 360); | ||
| else h1 < h2 && (h1 += 360); | ||
| return (h1 * (1 - w) + h2 * w) % 360; | ||
| } | ||
| const aa = Number.isNaN(a.alpha) ? 1 : a.alpha; | ||
| const ba = Number.isNaN(b.alpha) ? 1 : b.alpha; |
There was a problem hiding this comment.
Three readings here differ from CSS Color 4: hues are not normalized to 0–360 before the hue method (color-mix(in hsl, hsl(730 50% 50%), hsl(20 50% 50%)) gives cyan #409FBF instead of orange rgb(191, 96, 64)), a none alpha premultiplies as 1 instead of taking the other color's alpha (#FF008080 instead of rgba(128, 0, 128, 0.5)), and analog() matches Lab's opponent b with RGB blue (color-mix(in srgb, lab(50 20 none), red) gives #CB3500 instead of rgb(203, 53, 60)).
6938475 to
d4a0696
Compare
b87f12a to
f59810d
Compare
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec f59810d3cfbadf3c044851f2c1b92a04697a6518 on this pull request (the author may do so as an engineering owner). Separately, three fixes are needed whatever that decision is:
color-mix()gives HSL lightness no analog (css-values.mjs,ANALOGOUS), socolor-mix(in lab, hsl(0 50% none), lab(50 20 30))generates#4F3525where Chromium draws#8E705E.- The title, the README's “reads any CSS color syntax” and the “Swift has no static value” failure suffix overstate the reader: valid colors such as
color(display-p3-linear 1 0 0)andcontrast-color(red)stop the run as if they had no static form. - A legacy
hsl(120, 200%, 40%)keeps its saturation above 100%, so Swift gets a near-white where Chromium drawsrgb(0, 204, 0).
CI's one failing test, a CLI file-watch test outside this change, passes locally and needs a rerun.
[Automated review]
| // Reds, greens, and blues include X, Y, and Z; HSL lightness has no analog. | ||
| const ANALOGOUS = { | ||
| hsl: ['hue', 'colorfulness', null], |
There was a problem hiding this comment.
HSL lightness is analogous to Lab, LCH, OKLab and OKLCH lightness, as G7's own list says, and Chromium 149 carries it: color-mix(in lab, hsl(0 50% none), lab(50 20 30)) computes lab(50 10 15) (#8E705E), while this table turns the missing lightness into 0 and the generator writes #4F3525. hsl: ['hue', 'colorfulness', 'lightness'] (and the comment above it) fixes it; a table row pinning that mix to #8E705EFF would keep it.
| if (!origin && (fn.space === 'hsl' || fn.space === 'hwb')) { | ||
| coords = coords.map((v, i) => | ||
| i === 0 | ||
| ? v | ||
| : Math.max(0, i === 2 && fn.space === 'hsl' ? Math.min(100, v) : v), | ||
| ); |
There was a problem hiding this comment.
Chromium 149 clamps a comma-syntax hsl() saturation to 100%: hsl(120, 200%, 40%) computes and draws rgb(0, 204, 0), while this keeps 200% and the gamut mapping turns it into Display P3 #E2FFD7, a near-white. Clamping saturation at 100 when legacy is set (and saying so in G7) would match.
| node packages/native/scripts/swift-ios-theme.mjs --theme ./src/acmeTheme.ts#acmeTheme --out ./Sources/Theme | ||
| ``` | ||
|
|
||
| The generator reads any CSS color syntax (including `color-mix()`, relative |
There was a problem hiding this comment.
color(display-p3-linear 1 0 0), contrast-color(red) and color-mix(in oklab, red calc(30%), blue) are valid CSS colors (Chromium 149 accepts them) that stop the run, so “any CSS color syntax” overstates what the generator reads; naming the syntaxes the theme generator spec lists would keep this accurate.
| if (!(error instanceof CssValueError)) throw error; | ||
| throw new Error( | ||
| `${theme.name} ${mode}: ${token} is not a ${kind} Swift can read: ${value}`, | ||
| `${theme.name} ${mode}: ${token} = ${value}: ${error.message}; Swift has no static value`, |
There was a problem hiding this comment.
This suffix goes on every reader error, so a static color the reader does not parse yet, such as color(display-p3-linear 1 0 0), is reported as “color(display-p3-linear) is not a color space Swift can read; Swift has no static value”. Keeping “Swift has no static value” for the true no-static-form reasons (currentColor, viewport units, …) and saying the generator does not read the rest would point product teams at the right fix.
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec 2abe79e82cc8bb3953563c4394b724cd96a673df on this pull request (the author may do so as an engineering owner). The earlier HSL-lightness, legacy hsl() saturation and failure-wording findings are fixed. One fix is still needed whatever that decision is: font-family and shadow tokens skip G7's no-static-form rule, so --font-family-body: inherit generates a family named inherit, while env() or attr() in a family and inherit, initial or a colorless layer in a shadow end “the Swift theme generator does not read this form” instead of “Swift has no static value” (toFamilies and convertToken in swift-ios-theme.mjs, toShadow in css-values.mjs).
[Automated review]
| if (group === 'shadow') return toShadow(value, notes); | ||
| if (isFamily(token)) { | ||
| const families = toFamilies(value); | ||
| if (!families) throw new CssValueError('a font family is a list of names'); |
There was a problem hiding this comment.
G7 lists CSS-wide keywords, env() and attr() as having no static form, ending “Swift has no static value”, but family tokens skip that: --font-family-body: inherit generates ["inherit"] (a family named inherit), and env(foo) or attr(data-font) lands here and ends “the Swift theme generator does not read this form”. toShadow has the same gap for inherit/initial and a colorless layer (CSS draws it in currentColor). Failing through noStaticForm for an unquoted whole-value keyword or a var()/env()/attr() before the family and shadow converters, with rows in the no-static-form test, would close it.
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec 956ebc879368de603fa87e321e1e685238b9bbe0 on this pull request (the author may do so as an engineering owner). The earlier font-family and shadow finding is fixed. Two fixes are still needed whatever that decision is:
- A space-syntax
hsl()saturation above 100% is not clamped, sohsl(120 200% 40%)generates a near-white Display P3#E2FFD7where Chromium and Firefox drawrgb(0, 204, 0)(thecappedrule incss-values.mjsand G7's clamping sentence). calc(4px+2px),calc(1rem-2px)and"Figtree", inheritare invalid CSS that both browsers reject, but they generate6,14and a family namedinheritinstead of failing as G7 says.
[Automated review]
| if (!origin && (fn.space === 'hsl' || fn.space === 'hwb')) { | ||
| // Lightness clamps at 100%; so does a comma-syntax hsl() saturation, | ||
| // as browsers read the legacy form. | ||
| const capped = i => fn.space === 'hsl' && (i === 2 || (i === 1 && legacy)); |
There was a problem hiding this comment.
Chromium 149 and Firefox 151 clamp a literal hsl() saturation at 100% in space syntax too: hsl(120 200% 40%) computes rgb(0, 204, 0) in both, while this keeps 200% and the gamut mapping writes a near-white Display P3 #E2FFD7. Clamping saturation for both syntaxes (relative colors still unclamped) and updating G7's sentence would match the web.
| i++; | ||
| } else if ( | ||
| (m = NUMBER.exec(rest)) && | ||
| // A sign right after a value is a calc() operator, not part of a number. |
There was a problem hiding this comment.
This reads calc(4px+2px) as 6 and calc(1rem-2px) as 14, but CSS needs whitespace around + and - in calc(), and Chromium and Firefox reject both, so the web falls back while Swift gets a value. Dropping this special case lets sum report the missing operator, as G7's "valid CSS or not, fails" says.
| .replace(/"[^"]*"|'[^']*'/g, '""') | ||
| .trim() | ||
| .toLowerCase(); | ||
| if (/^(inherit|initial|unset|revert|revert-layer)$/.test(bare)) |
There was a problem hiding this comment.
Only a whole-value keyword is caught: "Figtree", inherit (invalid CSS, rejected by both browsers) generates ["Figtree", "inherit"]. Testing each comma-separated family against the CSS-wide keywords would make it fail as G7 says.
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec 7abf68be5a6f6bb2df61534bc900acbf7cb69e8e on this pull request (the author may do so as an engineering owner). The earlier hsl() saturation and invalid calc() and font-family findings are fixed. One small fix is still needed whatever that decision is: a comma-syntax color with a none alpha, such as rgba(255, 0, 0, none), generates a fully transparent color because the new comma check skips the alpha (css-values.mjs, colorFunction and checkCommaSyntax), although G7 now says commas hold no none, the base failed the run, and Chromium and Firefox reject the value.
[Automated review]
| : fail(`${tok.name}() has an empty or doubled value`), | ||
| ); | ||
| if (parts.length === 4) alphaTok = parts.pop(); | ||
| checkCommaSyntax(tok.name, parts); |
There was a problem hiding this comment.
The alpha popped on the line above never reaches this check, so rgba(255, 0, 0, none) generates red at opacity 0, while Chromium and Firefox reject it, the base failed the run, and G7 now says commas hold no none. Running the none check over alphaTok too would make it fail.
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec fb3bc2f67d4aa69bcd8f7878ac844862cd05aac7 on this pull request (the author may do so as an engineering owner). The comma-syntax none alpha fix is in, with a test, and no other code change is needed; every published theme regenerates byte-identically. When deciding, note that G7 gamut-maps colors outside Display P3 and decodes rec2020 with a 2.4 gamma, so values such as oklch(0.9 0.4 300) and color(rec2020 0.4 0.6 0.2) draw differently in Swift than Chromium draws them.
[Automated review]
There was a problem hiding this comment.
Approval here waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records approval by commenting /approve-spec 92767489d6ede2304b4b523cd1482f0ef139b2e8 on this pull request (the author may do so as an engineering owner). Three fixes are needed whatever that decision is:
- The pull request is now 2,012 authored lines, over the 2,000-line limit; moving the new gamut-mapping warning into the stacked #8422, which already owns warnings, brings it under.
- G7 credits the BT.2020 piecewise curve to CSS Color 4 (
theme-generator.md:119-120, alsocss-values.mjs:527), but CSS Color 4 now definesrec2020with a 2.4 gamma (w3c/csswg-drafts#12574); describe the curve as matching Chromium, or switch curves. - “option 1's warning” (
theme-generator.md:142,swift-ios-theme.mjs:280) refers to an option no record defines; dropping “option 1's” fixes it.
[Automated review]
| with Bradford adaptation for D50 spaces; `rec2020` uses CSS Color 4's | ||
| rec2020 transfer function (the BT.2020 piecewise curve). |
There was a problem hiding this comment.
CSS Color 4 now defines rec2020 with a 2.4 gamma (w3c/csswg-drafts#12574, resolved August 2025), so this sentence names two different curves: following “CSS Color 4's” gives #787878 for color(rec2020 0.5 0.5 0.5) where the acceptance row requires #8B8B8B. Saying “the BT.2020 piecewise curve, as Chromium draws it” here and in the css-values.mjs:527 and test comments would keep it accurate.
| color outside Display P3 is a value Swift cannot express exactly: it is | ||
| gamut-mapped into Display P3 by CSS Color 4's algorithm (OKLCH chroma | ||
| lowered until clipping moves the color less than ΔEOK 0.02), and the run | ||
| prints option 1's warning naming the theme, mode, token, and value, |
There was a problem hiding this comment.
“option 1's warning” refers to an option no record, README or description lists (the same phrase is in swift-ios-theme.mjs:280); dropping “option 1's” keeps the sentence complete, since it already gives the warning's content and ending.
There was a problem hiding this comment.
Approval waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records the decision by commenting /approve-spec dad58e305d8ef5b55f2ef89011b0de565cacc623 on this pull request (the author may do so as an engineering owner). The earlier size and wording findings are fixed, and published themes still regenerate byte-identically. One small fix is needed whatever the decision: G7 now cites w3c/csswg-drafts#12574 (line 121), and records state the fact rather than an issue (architecture:knowledge-contracts INV10), so keep "CSS Color 4 specifies a 2.4 gamma" without the reference and update the R5 rubric line.
[Automated review]
| - Conversion uses CSS Color 4's equations and matrices through CIE XYZ D65, | ||
| with Bradford adaptation for D50 spaces; `rec2020` uses the BT.2020 | ||
| piecewise transfer curve, as Chromium draws it (CSS Color 4's draft now | ||
| gives `rec2020` a 2.4 gamma, w3c/csswg-drafts#12574). |
There was a problem hiding this comment.
This cites an issue as standing content, which architecture:knowledge-contracts INV10 rules out for records (“Pull requests and issues are not standing content”), and the description's R5 rubric line reports none. Stating the fact alone, for example “(CSS Color 4 specifies a 2.4 gamma)”, keeps the sentence complete.
There was a problem hiding this comment.
Approval waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements that no current spec states, and an engineering owner records the decision by commenting /approve-spec b14dfa33e171b060a76cca543a4fc4f951e3f085 on this pull request (the author may do so as an engineering owner). The G7 issue reference is gone, published themes still regenerate byte-identically, and no other change is needed. Two points for that decision: G7 decodes rec2020 as Chromium does rather than with CSS Color 4's 2.4 gamma, and it gamut-maps colors outside Display P3 where plain clipping keeps more chroma.
[Automated review]
…its spec lists A CSS value reader (scripts/css-values.mjs) converts every G7 form per token and mode: CSS Color 4/5 colors (Display P3 outside sRGB; outside Display P3 clipped per channel, as Chromium draws it, with a warning), calc() lengths, weights, line heights, families, and shadows. A value with no static form fails naming theme, mode, token, value, and reason; a form the reader does not read says so. G1, G7, D5, and the G7 acceptance row are updated; every published theme regenerates byte-identically.
There was a problem hiding this comment.
Approval waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements no current spec states, and an engineering owner records the decision by commenting /approve-spec ccbf760242d0ea01242018736dbeb68144bb0525 on this pull request (the author may do so as an engineering owner). Whatever that decision, please update the description, which still says colors outside Display P3 are gamut-mapped (its color-mix(in oklch longer hue, red, blue) row shows 0x008D00FF; this head writes Display P3 #009000 with a warning) and that warnings ship only in #8422. The failing “Touched components” check runs a script that main added after this branch's base, so a rebase onto main should clear it.
[Automated review]
ccbf760 to
f5a83b9
Compare
There was a problem hiding this comment.
Approval waits on a spec decision: the rewritten G1, G7, D5 and G7 acceptance row in packages/native/specs/swift/library/theme-generator.md are draft requirements no current spec states, including the choices to decode rec2020 with the BT.2020 curve and to clip colors outside Display P3 per channel, as Chromium draws them, where CSS Color 4 specifies a 2.4 gamma and chroma-reducing gamut mapping. An engineering owner records the decision by commenting /approve-spec f5a83b9dba1a871a6060635949aabb2a578f649c on this pull request; the author may do so as an engineering owner. The code, tests and description otherwise hold up, and every published theme regenerates byte-identically. One wording leftover in the description: “In-sRGB colors keep Color(astryxRGBA:)” should read Color(.sRGB, …), which the generator writes.
[Automated review]
|
/approve-spec f5a83b9 |
Stack:
main→ this PR (CSS reader) → #8422 (diagnostics: the remaining warnings, core-default fallback,--strict). Based onmain.User need
A product team writes its Astryx theme in modern CSS:
oklch()brand colors,color-mix()borders,calc()spacing,[light, dark]tuples. Today the Swift theme generator reads only hex,rgb(),hsl(),oklch(), and px/rem, and stops with an error on anything else, so that team gets no Swift theme at all. When a value truly cannot become a fixed Swift value (currentColor,50%,2vw), the team gets a one-line crash with no hint of what to do.After this change:
--strictcome in feat(native): Swift theme generator warns on lossy values and falls back for impossible ones #8422.Problem and solution fit
scripts/css-values.mjs: one small CSS value reader (tokenizer,calc()evaluator, CSS Color 4/5 color math) that the generator calls per token and mode. It reads CSS only; it never resolves a token reference (core's resolver still does that, G1).swift-ios-theme.mjs: picks the converter by token kind (color, shadow, family, weight, line height, length); a value the reader cannot convert fails the run naming theme, mode, token, value, and reason. Same path for published themes and--themeproduct themes.Color(.displayP3, red:green:blue:opacity:)with the same helper main uses forColor(.sRGB, …): each 8-bit channel0,1, or the exact decimal of its step over 255.Not in this PR (in #8422): the other approximation warnings, core-default fallback,
--strict. This PR prints only the outside-Display-P3 warning;renderSwiftThemetakes an optionalwarncallback.No generated Swift changes: every published theme converts byte-identically.
Current specification
packages/native/specs/swift/library/theme-generator.md(draft) owns the generator. This PR amends G1 and G7 and adds D5 there; no other record owns Swift value conversion.Public delta and caller burden
Input → Swift output (each row is a test; exact to the 8-bit channel, tolerance 0 of 255). sRGB results are shown as
0xRRGGBBAAfor brevity; the generator writes them asColor(.sRGB, …):lab(29.2345% 39.3825 20.0664),oklab(40.101% 0.1147 0.0453),oklch(40.101% 0.12332 21.555)(CSS Color 4 examples)0x7D2329FFlch(52.2345% 72.2 56.2)(CSS Color 4 example)0xC65D06FFrgb(10% 20% 30% / 50%),hwb(194 0% 0% / .5),hsl(0.5turn 50% 50%)0x1A334D80,0x00C4FF80,0x40BFBFFFcolor(display-p3 1 0 0 / 50%)Color(.displayP3, red: 1, green: 0, blue: 0, opacity: 0.5019607843137255)color(prophoto-rgb 0.4 0.6 0.2),color(xyz-d65 0.2 0.3 0.4)0x52B204FF, P30x44A4A3FFcolor-mix(in srgb, red 20%, blue 20%)0x80008066(sum under 100% scales alpha)color-mix(in oklch longer hue, red, blue)0x009000FF(outside P3: clipped per channel, as Chromium draws it, with a warning)oklch(0.9 0.4 300)0xFB7CFFFF(clipped, as Chromium draws it, with a warning)color(rec2020 0.4 0.6 0.2)0x4AA829FF(BT.2020 curve, as Chromium draws it)rgb(from #123456 calc(r + 10) g b)0x1C3456FFrebeccapurple,rgb(none 0 0)0x663399FF,0x000000FF[ 'oklch(40.101% 0.12332 21.555)', 'color-mix(in srgb, light-dark(red, blue) 50%, white)' ](tuple)0x7D2329FF, dark0x8080FFFFrgb(from color(display-p3 1 0 0) r g b / 50%)0xFF000080(a relative color keeps its origin's gamut)color-mix(in srgb, rgb(255 0 0 / none), rgb(0 0 255 / 0.5))0x80008080(anonealpha takes the other's)color-mix(in lab, rgb(0 0 none), lab(50 20 30))0x4F3525FF(a missing blue is not Lab's b)color-mix(in oklch, oklch(0.6 0.1 400), oklch(0.6 0.1 20))0xB4685CFF(400° is 40°)1.5emon a 14px style1.5mediumas a font size; as--border-width3calc((1rem - 2px) * 2),12pt,clamp(2px, 1rem, 12px)28,16,12bold,bolder700,700(read against 400)20pxwith a16pxsize;150%1.25;1.5A value with no static form fails the run with its reason:
API:
toColor,toWeight,toLeadingare new exports;toHexColoris replaced bytoColor, andtoShadowno longer takes a mode (light-dark is resolved before conversion).renderSwiftThemeandrenderAllkeep their signatures.Review fixes
Four conversion findings from automated review, each with a test:
rgb()/hwb()/hsl()/Lab color no longer clamps its channels, sorgb(from var(--color-accent) r g b / 50%)over a Display P3 accent stays Display P3 instead of becoming a clipped sRGB red.emline height counts against the style's own size:1.5emis 1.5, not 1.714.thin,medium, andthickare lengths only for--border-width; anywhere else (such as a font size, wheremediummeans something else) they fail with a reason.color-mix()follows CSS Color 4 for anonealpha (it takes the other color's alpha before premultiplying), for analogous components (Labbis not blue; X, Y, Z group with red, green, blue), and for hues outside 0–360° (taken modulo 360° first).Design and alternatives
Color(.displayP3, …)represents it exactly (checked:Color(.displayP3, red: 1, green: 0, blue: 0, opacity: 1)resolves to extended-sRGB red 1.093), so the generator writes that and Astryx adds no color initializer. In-sRGB colors are written asColor(.sRGB, …), as main writes them, so no published theme output changes. Only colors outside P3 are approximated: each channel clips, as Chromium draws them, so a designer sees the same color on both, and the run warns. Rejected: mapping everything into sRGB, which makes brand colors duller than the web on the same device.Existing authority searched
swift theme generator,color-mix,native theme,css values,light-dark,theme-generator.md,swift-ios-theme.packages/native/specs/swift/library/theme-generator.md(owner, amended here);theme-environment.md(environment, not values; untouched).Theme.swift; this PR no longer touches it.Writing rubric results
Evidence
none, color first), light-dark at any depth, tuple end to end throughdefineTheme, length line height, and a theme whose value has no static form failing with theme, mode, token, value, and reason.generate:swift-iosregenerates every published theme byte-identically.Astryxmodule; an immediate-mode run showsColor(.displayP3, red: 1, green: 0, blue: 0, opacity: 1)resolves to extended-sRGB red 1.093, outside sRGB.Scope
Testing
No visual change: generated Swift is unchanged for every published theme, so no screenshots apply.