Skip to content

feat(native): Swift theme generator reads the CSS colors and lengths its spec lists - #8420

Merged
cixzhang merged 1 commit into
mainfrom
native/swift-theme-css-values
Nov 1, 2026
Merged

cixzhang merged 1 commit into
mainfrom
native/swift-theme-css-values

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Stack: main → this PR (CSS reader) → #8422 (diagnostics: the remaining warnings, core-default fallback, --strict). Based on main.

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:

  • Product teams whose themes use modern CSS colors and lengths get a Swift theme instead of a failed run.
  • Wide-gamut brand colors stay wide on iPhone and Mac (Display P3), instead of being clipped duller than the web shows them on the same device.
  • A value with no fixed Swift form still stops the run, now with the reason: theme, mode, token, value, and why; a form the reader does not read says so instead.
  • A color outside Display P3 clips per channel, as Chromium draws it, and warns (theme, mode, token, value: "outside Display P3; clipped to match the web"). The other approximation warnings, falling back to core's default, and --strict come in feat(native): Swift theme generator warns on lossy values and falls back for impossible ones #8422.

Problem and solution fit

  • New 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 --theme product themes.
  • No new Swift API: a color outside sRGB is written as SwiftUI's own Color(.displayP3, red:green:blue:opacity:) with the same helper main uses for Color(.sRGB, …): each 8-bit channel 0, 1, or the exact decimal of its step over 255.
  • Spec: G1 (light-dark at any depth, tuples), G7 rewritten to list every accepted syntax and its exact conversion and rounding, D5 (Display P3), the G7 acceptance row, current state.

Not in this PR (in #8422): the other approximation warnings, core-default fallback, --strict. This PR prints only the outside-Display-P3 warning; renderSwiftTheme takes an optional warn callback.

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 0xRRGGBBAA for brevity; the generator writes them as Color(.sRGB, …):

CSS in Swift out
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) 0x7D2329FF
lch(52.2345% 72.2 56.2) (CSS Color 4 example) 0xC65D06FF
rgb(10% 20% 30% / 50%), hwb(194 0% 0% / .5), hsl(0.5turn 50% 50%) 0x1A334D80, 0x00C4FF80, 0x40BFBFFF
color(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, P3 0x44A4A3FF
color-mix(in srgb, red 20%, blue 20%) 0x80008066 (sum under 100% scales alpha)
color-mix(in oklch longer hue, red, blue) P3 0x009000FF (outside P3: clipped per channel, as Chromium draws it, with a warning)
oklch(0.9 0.4 300) P3 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) 0x1C3456FF
rebeccapurple, rgb(none 0 0) 0x663399FF, 0x000000FF
[ 'oklch(40.101% 0.12332 21.555)', 'color-mix(in srgb, light-dark(red, blue) 50%, white)' ] (tuple) light 0x7D2329FF, dark 0x8080FFFF
rgb(from color(display-p3 1 0 0) r g b / 50%) P3 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 (a none alpha 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°)
line height 1.5em on a 14px style 1.5
medium as a font size; as --border-width fails; 3
calc((1rem - 2px) * 2), 12pt, clamp(2px, 1rem, 12px) 28, 16, 12
bold, bolder 700, 700 (read against 400)
line height 20px with a 16px size; 150% 1.25; 1.5

A value with no static form fails the run with its reason:

acme-brand light: --color-accent = currentColor: currentColor depends on where the token is used; Swift has no static value

API: toColor, toWeight, toLeading are new exports; toHexColor is replaced by toColor, and toShadow no longer takes a mode (light-dark is resolved before conversion). renderSwiftTheme and renderAll keep their signatures.

Review fixes

Four conversion findings from automated review, each with a test:

  1. A relative rgb()/hwb()/hsl()/Lab color no longer clamps its channels, so rgb(from var(--color-accent) r g b / 50%) over a Display P3 accent stays Display P3 instead of becoming a clipped sRGB red.
  2. An em line height counts against the style's own size: 1.5em is 1.5, not 1.714.
  3. thin, medium, and thick are lengths only for --border-width; anywhere else (such as a font size, where medium means something else) they fail with a reason.
  4. color-mix() follows CSS Color 4 for a none alpha (it takes the other color's alpha before premultiplying), for analogous components (Lab b is not blue; X, Y, Z group with red, green, blue), and for hues outside 0–360° (taken modulo 360° first).

Design and alternatives

  • Display P3, not sRGB clipping (D5). iPhone and Mac displays are P3, and a browser on them draws an out-of-sRGB color in P3. SwiftUI's own 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 as Color(.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.
  • Line heights stay multipliers. A length line height divides by the same style's size in the same mode, so the Swift type does not change.
  • One reader module, no dependency. The color math follows CSS Color 4 sample matrices; verified during development against an independent CSS Color 4 implementation (all 148 named colors, every syntax row above, agree byte for byte); clipped out-of-P3 values and rec2020 values match headless Chromium 154). Adding a dependency would change the root lockfile, outside this package.

Existing authority searched

Writing rubric results

R1 narration: G7 opened as a rewrite of the old list; written as present-tense rules. Current state's new bullets state facts, not changes.
R2 research: none in the record; the cross-check against an independent CSS Color 4 implementation is described only in this PR.
R3 evidence: the G7 acceptance row cites CSS Color 4 examples and concrete outputs, no PRs.
R4 rejected alternatives: one, D5, one line (mapping every color into sRGB).
R5 change references: none (searched for #digits, /pull/, /issues/).
R6 open questions: none.

Evidence

  • Unit tests: 48-row color table (each with the loss note the reader records, if any), lengths/weights/line heights, 11 no-static-form errors with reasons, shadows (spread note, none, color first), light-dark at any depth, tuple end to end through defineTheme, length line height, and a theme whose value has no static form failing with theme, mode, token, value, and reason.
  • Drift: generate:swift-ios regenerates every published theme byte-identically.
  • Swift: a generated product theme with four Display P3 colors typechecks against the Astryx module; an immediate-mode run shows Color(.displayP3, red: 1, green: 0, blue: 0, opacity: 1) resolves to extended-sRGB red 1.093, outside sRGB.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run --project node packages/native         # 9 files, 107 tests pass
# run with --testTimeout=120000: contracts.test.ts's type-resolution test (untouched here)
# needs more than 30 s while the machine is busy
pnpm -F @astryxdesign/native generate:swift-ios          # no generated file changes
pnpm -F @astryxdesign/native typecheck                   # pass
pnpm check:knowledge                                     # Knowledge templates and records are aligned.
swiftc -typecheck (package, tests, templates)            # pass

No visual change: generated Swift is unchanged for every published theme, so no screenshots apply.

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 1, 2026 8:42am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 1, 2026, 9:42 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · f5a83b9

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

API changes: core +8 · ~20 · −0 (report stale: run pnpm api:report); richtext +0 · ~1 · −0 (report stale: run pnpm api:report)

29 API changes (advisory)
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

@cixzhang
cixzhang force-pushed the native/swift-card-props branch from dcdbaf9 to 35d4efe Compare October 25, 2026 16:15
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from a63734c to f239feb Compare October 25, 2026 16:18
@cixzhang cixzhang changed the title feat(native): Swift theme generator converts every CSS color and length, and warns or fails on the rest feat(native): Swift theme generator reads every CSS color and length Oct 25, 2026
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from f239feb to 7c2eba2 Compare October 25, 2026 16:29
@cixzhang
cixzhang force-pushed the native/swift-card-props branch from 35d4efe to adce2d0 Compare October 25, 2026 16:30
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from 7c2eba2 to d9985b4 Compare October 25, 2026 16:38
@cixzhang
cixzhang force-pushed the native/swift-card-props branch from 413f374 to e56c79d Compare October 25, 2026 16:55
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from d9985b4 to 3aea90f Compare October 25, 2026 17:01
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from 3aea90f to c661973 Compare October 25, 2026 17:12
@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from c661973 to 6938475 Compare October 25, 2026 17:44
@cixzhang
cixzhang changed the base branch from native/swift-card-props to main October 25, 2026 17:44

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, so rgb(from var(--color-accent) r g b / 50%) over an oklch() accent comes out as sRGB #F10000 while the accent itself stays Display P3 (css-values.mjs, colorFunction).
  • toLeading reads em against the 16 pt root, so 1.5em on a 14px style becomes 1.714 instead of 1.5.
  • toPoints reads medium as a 3 pt border width for every length, including font sizes, where it means 16px.
  • Three color-mix() edge readings (a none alpha, Lab b treated as blue, hues above 360°) differ from CSS Color 4.

[Automated review]

Comment thread packages/native/scripts/css-values.mjs Outdated
Comment on lines +833 to +844
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),
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +368 to +371
if (q.k === 'length') {
if (!fontSize) fail("a length line height needs its style's font size");
return Number((q.v / fontSize).toPrecision(12));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/native/scripts/css-values.mjs Outdated
Comment on lines +908 to +919
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

@cixzhang
cixzhang force-pushed the native/swift-theme-css-values branch from 6938475 to d4a0696 Compare October 25, 2026 19:39
@cixzhang
cixzhang changed the base branch from main to native/swift-color-sdk-initializers October 25, 2026 19:39

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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), so color-mix(in lab, hsl(0 50% none), lab(50 20 30)) generates #4F3525 where 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) and contrast-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 draws rgb(0, 204, 0).

CI's one failing test, a CLI file-watch test outside this change, passes locally and needs a rerun.

[Automated review]

Comment thread packages/native/scripts/css-values.mjs Outdated
Comment on lines +649 to +651
// Reds, greens, and blues include X, Y, and Z; HSL lightness has no analog.
const ANALOGOUS = {
hsl: ['hue', 'colorfulness', null],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +850 to +855
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),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/native/apple/README.md Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cixzhang cixzhang changed the title feat(native): Swift theme generator reads every CSS color and length feat(native): Swift theme generator reads the CSS colors and lengths its spec lists Nov 1, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, so hsl(120 200% 40%) generates a near-white Display P3 #E2FFD7 where Chromium and Firefox draw rgb(0, 204, 0) (the capped rule in css-values.mjs and G7's clamping sentence).
  • calc(4px+2px), calc(1rem-2px) and "Figtree", inherit are invalid CSS that both browsers reject, but they generate 6, 14 and a family named inherit instead of failing as G7 says.

[Automated review]

Comment thread packages/native/scripts/css-values.mjs Outdated
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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, also css-values.mjs:527), but CSS Color 4 now defines rec2020 with 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]

Comment on lines +119 to +120
with Bradford adaptation for D50 spaces; `rec2020` uses CSS Color 4's
rec2020 transfer function (the BT.2020 piecewise curve).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec f5a83b9

@cixzhang
cixzhang merged commit 1ffa166 into main Nov 1, 2026
53 checks passed
@cixzhang
cixzhang deleted the native/swift-theme-css-values branch November 1, 2026 09:51

This branch was successfully deployed

1 active deployment
Preview — f5a83b9d Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant