Repository navigation
feat(native): Swift theme generator warns on lossy values and falls back for impossible ones - #8422
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
7c2eba2 to
d9985b4
Compare
a4ea306 to
213bcf2
Compare
d9985b4 to
3aea90f
Compare
213bcf2 to
6d600d4
Compare
3aea90f to
c661973
Compare
6d600d4 to
44de317
Compare
c661973 to
6938475
Compare
44de317 to
0472804
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Separately, renderSwiftTheme(theme) and renderAll(load) called without a warnings list, as the drift test calls it, now return core's value with no signal at all (swift-ios-theme.mjs:311, :729); please print those warnings or keep the old error when no list is passed, and deduplicate the repeated warning that a value with two em operands produces.
[Automated review]
| */ | ||
| export async function resolveTheme( | ||
| theme, | ||
| {warnings = [], strict = false} = {}, |
There was a problem hiding this comment.
With warnings defaulting to a throwaway array here (and in renderAll), renderSwiftTheme(theme) and renderAll(load), the drift test's call, now replace an unconvertible value with core's default and report nothing; before this change they threw. Printing the warnings when no list is passed, as the web compiler's warnings?: string[] collector does, or keeping the throw, would keep that substitution visible.
| notes.push(`${error.message}; core's default ${fallback} used instead`); | ||
| } | ||
| const emitted = swiftValue(memberType(group, token), typed); | ||
| for (const note of notes) warnings.push(`${where} → ${emitted}: ${note}`); |
There was a problem hiding this comment.
A value with two em operands, such as calc(1em + 1em), adds two identical notes, so this prints the same warning twice per mode and --strict counts it twice, while G15 says one warning per lossy conversion. Deduplicating the token's notes (new Set(notes)) would fix it.
6938475 to
d4a0696
Compare
0472804 to
f07c4a6
Compare
d4a0696 to
3abc514
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Alongside that decision, three fixes are needed:
renderSwiftTheme(theme)andrenderAll(load)called without awarningslist, as the published-theme and drift tests call them, return core's value with no signal at all (swift-ios-theme.mjs:311,:739); print those warnings or keep the error when no list is passed.- When a theme's own value fails partway, its earlier notes stay on the substituted value, so
calc(1em + 2vw)warns that anemwas read for what is core's default; clear the notes before the fallback (swift-ios-theme.mjs:288). - Deduplicate a token's notes so
calc(1em + 1em)warns once per mode, as G15 says (swift-ios-theme.mjs:291).
[Automated review]
| `${where}: ${error.message}; Swift has no static value`, | ||
| ); | ||
| } | ||
| notes.push(`${error.message}; core's default ${fallback} used instead`); |
There was a problem hiding this comment.
When the theme's own conversion throws partway, notes still holds what css-values.mjs pushed before the failure (an em operand, a drop layer's spread), so calc(1em + 2vw) emits core's 16 with an extra … → 16: em read against the 16px root font size warning per mode, and --strict counts it. Clearing the notes before this push (notes.length = 0) leaves only the substitution warning.
f07c4a6 to
04f28f2
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Alongside that decision, three fixes are still needed:
renderSwiftTheme(theme)andrenderAll(load)called without awarningslist, as the published-theme and drift tests call them, return core's value with no signal at all (swift-ios-theme.mjs:311,:739); print those warnings or keep the error when no list is passed.- When a theme's own value fails partway, its earlier notes stay on the substituted value, so
calc(1em + 2vw)warns that anemwas read for what is core's default; clear the notes before the fallback (swift-ios-theme.mjs:288). - Deduplicate a token's notes so
calc(1em + 1em)warns once per mode, as G15 says (swift-ios-theme.mjs:291).
[Automated review]
04f28f2 to
483cb9d
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning, so that behaviour stays a spec gap until G15 is decided. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. The three fixes requested earlier (printing warnings when no list is passed, dropping a failed read's notes, and one warning per token and mode) are in, each with a test, and no other change is needed.
[Automated review]
3abc514 to
b87f12a
Compare
483cb9d to
6d99f67
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a typo such as rbg(0 100 224)) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. No other change is needed: the generator matches G15 as written, and every published theme still generates unchanged with no warning.
[Automated review]
b87f12a to
f59810d
Compare
…ack for impossible ones A lossy conversion (a color outside Display P3, clipped as Chromium draws it; an em read against the root; bolder or lighter; a normal line height; a drop-shadow spread) prints a warning after the run, naming the theme, mode, token, value, and the Swift value written. The outside-Display-P3 warning keeps its text, "outside Display P3; clipped to match the web", and now goes through the same warnings list. A value with no static form (currentColor, %, vh, an unresolved var()) takes core's default for that token with a warning; only a token core has no default for stops the run, ending "Swift has no static value". A form the reader does not read still fails, saying so. --strict turns every warning into an error and writes no file. Product themes (--theme) get the same treatment, and renderSwiftTheme takes `warnings` and `strict` in place of the `warn` callback. The spec gains G15.
ccbf760 to
f5a83b9
Compare
6d99f67 to
ca5fbe2
Compare
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a mistyped var() reference) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. Separately, the G7 row of the acceptance checks (line 251) still says currentColor, an inherit font family and a colorless shadow fail with "Swift has no static value"; please reword it to match G15, since those shared tokens now take core's default with a warning.
[Automated review]
| | G12 | A test reads `packages/themes/*/package.json` and finds one generated file per non-private package plus `default`. A fixture product theme renders through `renderSwiftTheme`. | | ||
| | G13 | Editing one generated value or member name by hand fails the drift test with the regenerate command in the message. | | ||
| | G14 | The README's generated-Swift note lists the generated theme files. | | ||
| | G15 | `oklch(0.7 0.4 150)` emits `Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1)`, clipped as Chromium draws it, and warns in light and dark with theme, mode, token, value, and that Swift value, ending "outside Display P3; clipped to match the web"; `--spacing-4: 2vw` emits core's default and warns; `currentColor` in a token core has no default for fails with theme, mode, token, value, and reason; with `--strict`, a theme that warns fails and no file is written. Without a list, `renderSwiftTheme` prints each warning to standard error; `calc(1em + 2vw)` falls back with one warning that does not mention the `em`; `calc(1em + 1em)` warns once per mode. | |
There was a problem hiding this comment.
This row says currentColor fails only in a token core has no default for, but G7's row above (line 251, unchanged) still requires currentColor, --font-family-body: inherit, and a colorless shadow layer to fail ending "Swift has no static value", and "Each G7 form with no static form fails with its reason". All three are shared tokens, so at this head they take core's default with a warning (the tests were rewritten to falls back from %s). Rewording the G7 row to point at G15's fallback would keep the record consistent.
currentColor, an inherit font family, and a colorless shadow layer are reported as having no static form and handled as G15 says: core's default with a warning, or a failed run when core has none.
There was a problem hiding this comment.
Approval waits on an engineering owner deciding G15 in the draft packages/native/specs/swift/library/theme-generator.md: no current spec settles whether a value Swift cannot express (2vw, currentColor, or a mistyped var() reference) should stop the run or take core's default with a warning. An engineering owner records approval of G15 as written by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or replies with what G15 should say instead. The G7 acceptance row now matches G15 and the code, and no other change is needed.
[Automated review]
|
/approve-spec af1aa90 |
There was a problem hiding this comment.
This is ready to merge: G15's warnings, core-default fallback and --strict are approved by an engineering owner on this head, and the generator, its record, the README and the tests agree. Every published theme still regenerates unchanged with no warning, and no further change is needed.
[Automated review]
Follows #8420 (CSS reader, merged). Rebased onto
mainwith only its own commit.User need
With #8420, the Swift theme generator reads every CSS color and length, but two gaps stay:
emis read against the root size, a drop shadow's spread is dropped), it happens silently. A product team never learns that its Swift theme differs from the web.currentColor,50%,2vw) stops the whole run, even when core already has a perfectly good default for that token. The team gets no Swift theme at all.After this change:
--strictturns every warning into an error and writes no file.Problem and solution fit
swift-ios-theme.mjs: collects the reader's loss notes as warnings; on a value with no static form, converts core's default for that token and mode instead and warns, or fails when there is none;--strict;warning:/error:output; the same for--themeproduct themes.renderSwiftTheme(theme, {warnings, strict})andrenderAll(load, {warnings}): optional diagnostics options for programmatic callers, replacing feat(native): Swift theme generator reads the CSS colors and lengths its spec lists #8420'swarncallback; without a list, warnings print to standard error. feat(native): Swift theme generator reads the CSS colors and lengths its spec lists #8420's outside-Display-P3 warning keeps its text and now goes through this list.--strict.No generated Swift changes; every published theme generates with zero warnings.
Current specification
packages/native/specs/swift/library/theme-generator.md(draft) owns the generator; this PR adds G15 there. G7 (values, from #8420) decides what each value converts to; G15 decides what the run does about it.Public delta and caller burden
Rules (G15):
em,bolder/lighter,normalline height, drop-shadow spread): value emitted, one warning.resolveThemeTokens(null, {mode})), which covers every shared token. A token core has no default for, and every token of core's own defaults, are required.--strictfails before writing.A product theme run (
--theme ./acme.mjs#acmeTheme --out ./out):The same run with
--strictwrites nothing and exits 1:No static form and no core default:
Callers that pass no options behave as before except that an impossible value in a token core has a default for now generates (with a warning) instead of failing.
Review fixes
Three findings from automated review, each with a test:
renderSwiftTheme(theme)andrenderAll(load)called without awarningslist now print each warning to standard error instead of dropping it. This matches G15's rule that warnings print and that a value with no static form falls back with a warning; keeping the error when no list is passed would contradict the fallback. A caller that wants them silently passes its own list.calc(1em + 2vw)), the notes from that failed read are dropped before the fallback, so the warning names only the failure and core's default.calc(1em + 1em)warns once per mode.Design and alternatives
--strictfails before writing so CI never leaves half-generated output.Existing authority searched
swift theme generator,--strict,warning,diagnostics,optional token,theme-generator.md,swift-ios-theme.packages/native/specs/swift/library/theme-generator.md(owner; G15 added here). No other record covers generator diagnostics.Writing rubric results
Evidence
--spacing-4: 2vw, required-token error for a token core has no default for,--strictthrowing with every warning listed, andfinishRunwriting nothing under--strict.generate:swift-iosregenerates every published theme byte-identically with zero warnings.Scope
Testing