Repository navigation
spec(native): Swift theme generator turns any Astryx theme into an AstryxTheme - #8031
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…ot, and contrast decided
|
/approve-spec 688c263 |
PR Analysis Report
|
There was a problem hiding this comment.
Changes requested: the theme-generator record is owner-approved, but it conflicts with two current specs it leaves unchanged and specifies a step core cannot supply yet. Please amend spec:AST-082 FR16 (or drop the interim import exception in G2 and D1), and rework G8 so theme-local tokens get a per-mode value source and are typed without reading the astryx-theme-<theme>- prefix that spec:AST-006 DEC-2 rules out. Then rebase onto the Swift package from #7981 (or rewrite Current state for what is on main), and close the macOS gap in G10 and the missing rule D4 points to.
resolveThemeTokensnever returnslocalTokens, and neutral's local colors are stored aslight-dark(…)strings that G7 rejects, so G8 cannot be met for neutral as written.
[Automated review]
| - **G2 — Core is read only at build time.** The generator runs at build time; | ||
| generated Swift imports only SwiftUI and carries nothing from core at run | ||
| time (AST-082 FR16). Once core's portable entry ships, the generator imports | ||
| core only through it. Until then it imports `@astryxdesign/core/theme` and | ||
| `@astryxdesign/core/theme/tokens`, a named interim exception to FR16 (D1). |
There was a problem hiding this comment.
This names an exception to spec:AST-082 FR16 ("native never imports core outside the portable entry"), whose verification row fails an import of the web theme entry from native. A library spec cannot carve that out: amend FR16 in AST-082 to list the interim build-time reads (including scripts/core-docs.mjs, which already imports core's doc modules), or drop the exception here and in D1.
| - **G8 — Theme-local tokens are typed in the theme's own namespace.** A | ||
| theme-local token (`astryx-theme-<theme>-<rest>`) whose `<rest>` is in a G5 | ||
| group becomes a typed member, by the G6 rule applied to `<rest>`, of a | ||
| namespace generated only in that theme's file: `AstryxTheme.Neutral.local`, | ||
| with light and dark values (`AstryxTheme.Neutral.local.dark.color.statusFillAccent`). | ||
| Only code written for that theme reads them; shared components never do. |
There was a problem hiding this comment.
G1 allows values only from resolveThemeTokens, which never returns localTokens, and core stores local [light, dark] pairs as light-dark(…) strings that G7 rejects, so neutral's ten local colors have no permitted source. Parsing astryx-theme-<theme>-<rest> also conflicts with spec:AST-006 DEC-2 (no prefix is interpreted). Name a per-mode source for local values and type them from their exact names and owner metadata.
| and no component uses it. | ||
| - **G10 — Font names map to SwiftUI fonts, with a system fallback.** The reader | ||
| walks a family list in order and uses the first family the app has | ||
| available (`UIFont(name:size:)` is not nil) as |
There was a problem hiding this comment.
UIFont(name:size:) is UIKit-only, but both Swift packages declare macOS 14 and CI tests them on macOS. Name the AppKit counterpart (NSFont(name:size:)) or a platform-neutral check, and scope the Large-to-AX5 scaling check to iOS.
| until it exists, components follow the Swift theme-environment rule of | ||
| drawing borders and separators with the emphasized border token when | ||
| Increase Contrast is on. |
There was a problem hiding this comment.
No "Swift theme-environment rule" exists in the repository yet. State the interim emphasized-border rule here as a requirement with an acceptance check, or drop this clause.
| - `scripts/swift-ios-theme.mjs` generates core's default theme only, as | ||
| string-keyed `AstryxTokens.defaultLight` and `.defaultDark` dictionaries, | ||
| with every G5 group except `font-family-*` and theme-local tokens, and with | ||
| the G7 color and length conversions; `AstryxTheme.default` is written by | ||
| hand. | ||
| - The Swift components and the Login template read tokens by string name | ||
| (`astryx.color("color-text-primary")`); a missing name draws clear. | ||
| - `src/theme/swiftIOSTheme.test.ts` checks the default theme only. |
There was a problem hiding this comment.
None of these files (scripts/swift-ios-theme.mjs, src/theme/swiftIOSTheme.test.ts, swift-ios-1/, the Login template) is on main yet; they come from #7981. Land this after it, or describe the package as it is now (apple/, generated contracts only).
…light-dark per mode, FR16 interim reads, macOS fonts, contrast rule, unprefixed names, no version
|
/approve-spec 597dea4 |
There was a problem hiding this comment.
Changes requested: the theme-generator record is owner-approved for this commit, but two of its requirements still contradict current specs that this pull request leaves unchanged. G2 and D1 keep the interim imports of @astryxdesign/core/theme and @astryxdesign/core/theme/tokens that spec:AST-082 FR16 forbids, so please amend FR16 (OQ1's own recommendation) in this pull request or one that lands first, or drop the exception until core's portable entry ships. G8 builds each local-token member by camel-casing its custom-property name, a second identifier spec:AST-006 FR3 rules out, so amend FR3 for native identifiers, key local values by their exact names, or drop the naming clause for now.
- Smaller fixes for the same revision: the Summary's “any Astryx theme” fails on
hsl()colors under G7, G3's examples should use the real theme names (neutral,y2k), and the R6 rubric result should mention OQ1.
[Automated review]
| impact). Until it ships, the generator reads core through | ||
| `@astryxdesign/core/theme` and `@astryxdesign/core/theme/tokens` at build | ||
| time, the same kind of build-time read the contract generator makes of | ||
| core's documentation; once the portable entry ships, it reads core only | ||
| through that entry. Whether AST-082 FR16 lists these interim build-time | ||
| reads is OQ1. |
There was a problem hiding this comment.
This keeps native importing core's web theme entry until the portable entry ships, which current spec:AST-082 FR16 forbids (“native never imports core outside the portable entry”; its verification row lists “an import of a core component or the web theme entry from native”). OQ1 records the amendment but leaves it out, so the record requires what a current spec forbids. Please amend FR16 to list both interim build-time reads (these two entries and the contract generator's scripts/core-docs.mjs) and when they end, here or in a pull request that lands first, or drop the interim reads here, in D1 and in the G2 acceptance row.
| reports each local token it leaves out. When generated, each keeps its exact | ||
| name (AST-006 DEC-2): its Swift member is the whole custom-property name in | ||
| lower camel case (`--neutral-status-fill` → `neutralStatusFill`), with no |
There was a problem hiding this comment.
Camel-casing the custom-property name creates a second identifier, which current spec:AST-006 FR3 rules out for “generated theme-specific types or metadata” (“No transform may create a second identifier”), and DEC-2 rejects generated names and hidden normalization, so “keeps its exact name” does not hold. A Swift identifier cannot hold -, so this needs a decision: amend AST-006 FR3 to allow a deterministic native projection with a collision rule, key local values by their exact name, or drop this naming clause until that is decided.
| An iOS app built with Astryx shows its own brand, not only core's default: any | ||
| Astryx theme, from a published theme package such as neutral or from the | ||
| product itself, becomes a Swift `AstryxTheme` that `.astryxTheme(.neutral)` | ||
| applies, with the same light and dark values and typeface the web uses. Every |
There was a problem hiding this comment.
G7 fails any kept-group value outside its listed forms, and core passes hsl() through: the private probe theme resolves 16 color-syntax-* tokens to hsl() values in both modes, so a product theme written that way would not generate. Consider an exact hsl() conversion in G7, or narrow “any Astryx theme” here.
| - `<swiftName>` is the theme's `name` with a leading `astryx-` removed, in | ||
| lower camel case (`astryx-neutral` → `neutral`, `astryx-y2k` → `y2k`, a | ||
| product's `acme-brand` → `acmeBrand`). Core's default theme (`astryx`) is |
There was a problem hiding this comment.
The published themes are named neutral and y2k (neutralTheme.ts:71, y2kTheme.ts:107); astryx-neutral and astryx-y2k name their syntax themes, and core resolves its defaults with no theme name. The rule's output is unchanged, but the examples should use the real inputs.
…y exact name, converts hsl()
There was a problem hiding this comment.
This needs an owner decision before it can be approved: no engineering owner has approved the latest commit, so the theme-generator record's requirements (G1–G14, D1–D4) and the new swift/library/ spec area are still unsettled. Any engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. G2, D1 and the G2 acceptance check also depend on the AST-082 FR16 amendment in #8048, which has to land on main before they match current spec.
- The G2 acceptance check allows only the two theme entries in
packages/native/scripts/, but the existingcore-docs.mjsalready reads core's component documentation at build time, a read the FR16 amendment allows, so please widen the check and D1 to the reads FR16 lists. - Smaller fixes: the
hsl(210 100% 50%)example equals#0080FFonly after 8-bit rounding that G7 doesn't state, G8's string-keyed local maps conflict with D2, and G3 names a core default theme (astryx) that doesn't exist.
[Automated review]
| generated Swift imports only SwiftUI and carries nothing from core at run | ||
| time (AST-082 FR16). Until core's portable entry ships, the generator reads | ||
| core at build time through `@astryxdesign/core/theme` and | ||
| `@astryxdesign/core/theme/tokens`, the build-time reads AST-082 FR16 allows |
There was a problem hiding this comment.
Current spec:AST-082 FR16 on main still says "native never imports core outside the portable entry"; this allowance exists only in open #8048. G2 and D1 match current spec once that amendment lands.
| light and one for dark. | ||
| - `<swiftName>` is the theme's `name` with a leading `astryx-` removed, in | ||
| lower camel case (`neutral` → `neutral`, `y2k` → `y2k`, a product's | ||
| `acme-brand` → `acmeBrand`). Core's default theme (`astryx`) is |
There was a problem hiding this comment.
Core has no theme named astryx; its defaults resolve with no theme (resolveThemeTokens(null, …)). Saying that core's defaults render from no theme as default would also give G1 an input for the default file G12 requires.
| by its exact custom-property name (AST-006 FR3, DEC-2), with no second | ||
| identifier and no prefix read or removed, in a map of its value's type (G7) | ||
| for light and for dark, carried only by that theme | ||
| (`AstryxTheme.neutral.local.dark.colors["--neutral-status-fill"]`). Only code written for that theme reads them; shared components never |
There was a problem hiding this comment.
These string-keyed maps are what D2 rejects ("not string-keyed dictionaries"), so a misspelled local key compiles and returns nil. Scoping D2 to the shared surface and saying what a missing key does would resolve it; --neutral-status-fill is also not one of neutral's local tokens, which are named --astryx-theme-neutral-color-*.
| | Requirement | Check | | ||
| | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | G1 | A theme whose resolved token differs from its raw `theme.tokens` entry (a reference) shows the resolved value in Swift. A `DefinedTheme` with web component overrides generates the same file as the same theme without them. | | ||
| | G2 | A source check finds no import of core in `packages/native/scripts/` outside the two named theme entries (later, outside the portable entry). Generated Swift imports only SwiftUI. | |
There was a problem hiding this comment.
packages/native/scripts/core-docs.mjs already imports core's .doc.mjs files at build time, a read #8048's FR16 text allows, so this check would flag the existing contract generator. Consider checking for core imports "outside the build-time reads AST-082 FR16 lists", and naming that read in D1 too.
| | G4 | Generating twice, and on two CI machines, gives byte-identical output. | | ||
| | G5 | Every theme's light and dark values fill every member of `AstryxTokens`, equal to core's resolved names filtered by the G5 groups. | | ||
| | G6 | Unit tests map every row of the G6 table; two tokens that collide fail with both names. A Swift fixture referencing `theme.color.textPrimray` fails to compile. | | ||
| | G7 | A token written as `light-dark(#000, #fff)` generates black in light and white in dark. `hsl(210 100% 50%)` generates the same color as `#0080FF`. Unit tests convert every listed form; `oklch(0 0 0 / 5%)` in a kept group fails with theme, mode, token, and value in the message; `"Figtree", -apple-system, sans-serif` becomes `["Figtree", "-apple-system", "sans-serif"]`. | |
There was a problem hiding this comment.
The exact sRGB value of hsl(210 100% 50%) is (0, 0.5, 1), while #0080FF is (0, 128/255, 1), so an exact converter (G4, G7) fails this check. Either say hsl() rounds to 8-bit channels, or use an example that is exact both ways, such as hsl(0 100% 50%) and #FF0000.
…aps vs D2, core defaults
|
/approve-spec 639f694 |
|
/approve-spec ca81828 |
There was a problem hiding this comment.
Changes requested: the theme-generator record is owner-approved for this commit, but G2, D1 and the G2 acceptance check say AST-082 FR16 allows build-time reads of @astryxdesign/core/theme, @astryxdesign/core/theme/tokens, core's component documentation and its icon names, while FR16 on main still says native never imports core outside the portable entry. Please land the FR16 amendment in #8048 first, after which this commit matches as written, or drop the interim reads here until FR16 allows them.
- Smaller fixes: the Summary's "Every token is a typed Swift member" should say shared tokens because G8 keys local values by name, Current state's
color-mix()sentence misses--color-syntax-addedand--color-syntax-removed(keptcolor-*tokens that core resolves fromcolor-mix()), and the description's G3, G8 and D1 lines no longer match the record.
[Automated review]
| time (AST-082 FR16). Until core's portable entry ships, the generator reads | ||
| core at build time through `@astryxdesign/core/theme` and | ||
| `@astryxdesign/core/theme/tokens`, the build-time reads AST-082 FR16 allows | ||
| a native build script, each listed in the boundary check; once the portable | ||
| entry ships, it reads core only through that entry. |
There was a problem hiding this comment.
spec:AST-082 FR16 on main still says native never imports core outside the portable entry and lists no build-time reads; this allowance, D1's list (line 161) and the G2 check (line 142) cite text that is only in open #8048. Landing #8048 first makes this match as written; otherwise drop the interim reads until FR16 allows them.
| applies, with the same light and dark values and typeface the web uses. Every | ||
| token is a typed Swift member, so a misspelled token fails to compile instead | ||
| of drawing nothing. The generator runs core's own resolver, so Swift never |
There was a problem hiding this comment.
G8 keys theme-local values by exact name, so a misspelled local name compiles and returns nil; “Every shared token” would match G8 and D2.
| - Published theme packages: butter, chocolate, gothic, matcha, neutral, stone, | ||
| y2k (probe is private). Their raw values use `oklch()` and `color-mix()` only | ||
| outside the G5 groups (shadows, component styles). |
There was a problem hiding this comment.
The defined butter, chocolate, matcha and neutral themes carry --color-syntax-added and --color-syntax-removed as color-mix(in srgb, …) (core's syntax defaults), inside the kept color-* group. Core evaluates them to rgba() (neutral light: rgba(188, 224, 187, 0.25)), so generation still works; saying the resolved kept values use only G7's forms would be accurate.
…ax colors that use color-mix
|
/approve-spec 3c93d14 |
There was a problem hiding this comment.
Changes requested: the theme-generator record is owner-approved for this commit, and the AST-082 FR16 amendment it relies on is now on main, but D1 and the G2 acceptance check list FR16's allowed build-time reads without core's locale catalogs, which FR16 now includes. A boundary check built from D1 as written would refuse a read FR16 allows, such as the locale-catalog read in the strings generator in #7981, so please add locale catalogs to both lists or have them point at FR16's list.
- Smaller fix:
mainalready hasswift/library/accessibility.md, so the newlibrary/README.mdindex should list it.
[Automated review]
| import anywhere in the package is checked against AST-082 FR16, with every | ||
| build-time read FR16 allows listed by name: the generator's two theme entries | ||
| (G2) and the contract generator's reads of core's component documentation | ||
| and built-in icon names. |
There was a problem hiding this comment.
FR16 on main also allows core's locale catalogs (“read core's component documentation, its built-in icon names, and its locale catalogs as data”), so this list of “every build-time read FR16 allows” leaves one out, and a check built from it would refuse the strings generator's read of @astryxdesign/core/locales/*.json in #7981. Add the locale catalogs here, or refer to FR16's list instead of restating it.
| | Requirement | Check | | ||
| | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | G1 | A theme whose resolved token differs from its raw `theme.tokens` entry (a reference) shows the resolved value in Swift. A `DefinedTheme` with web component overrides generates the same file as the same theme without them. | | ||
| | G2 | A source check finds no import of core in `packages/native/` outside the build-time reads AST-082 FR16 lists (the two theme entries, core's component documentation, and core's built-in icon names; later only the portable entry). Generated Swift imports only SwiftUI. | |
There was a problem hiding this comment.
This parenthetical should match FR16's list, which now includes core's locale catalogs; as written, the check would flag a locale-catalog read that FR16 allows.
|
|
||
| | File | Concern | | ||
| | -------------------- | -------------------------------------------------- | | ||
| | `theme-generator.md` | How any Astryx theme becomes a Swift `AstryxTheme` | |
There was a problem hiding this comment.
main already has accessibility.md in this directory (the Swift accessibility contract); add its row when you merge main so the index lists every file.
… lists accessibility.md
|
/approve-spec 02a7bb9 |
There was a problem hiding this comment.
Approved: the theme-generator record is owner-approved at this commit, G2, D1 and the G2 acceptance check now list every build-time read the amended AST-082 FR16 allows, including core's locale catalogs, and the library index lists accessibility.md. No changes are required. Two optional follow-ups are noted inline: the Summary's "every shared token" and "typeface the web uses" read broader than G5 and G10, and naming the package version in G3's header means each release-version change on main must also regenerate the theme files or the drift test fails.
[Automated review]
| applies, with the same light and dark values and typeface the web uses. Every shared | ||
| token is a typed Swift member, so a misspelled token fails to compile instead |
There was a problem hiding this comment.
Optional: two Summary claims read broader than the requirements. G5 keeps 229 of core's 263 shared tokens, so --shadow-*, --duration-*, --ease-standard, --focus-outline-*, --text-code-* and --text-display-* get no member, and the web's typeface reaches Swift only when the app bundles and registers the font (G10). Saying "every token in the G5 groups" and "the typeface the web uses, once the app registers it" would match.
| - Each file starts with a header naming the source package, its version, and | ||
| the theme name, says "Do not edit", and names the regenerate command. |
There was a problem hiding this comment.
Optional: with the source package's version in this header, G13's drift test fails whenever the fixed release group's version changes on main (.changeset/config.json keeps core and all seven published theme packages on one version), unless that pull request also regenerates every theme file. An earlier revision of this record said "The header never names a version, so a release that only bumps versions changes no generated file"; restoring that, or naming the regeneration step, avoids the churn.
Exact decision needed
How any Astryx theme becomes a Swift
AstryxTheme: the input, the output file, the token set, value conversion, which themes are generated, and the drift check. Draft until the owner approves this spec; nothing is built from it before then.Existing authority searched
spec:AST-082(current) owns native theming: one theme definition as the token authority (FR10), the portable theme (FR18), and the one-way, build-time read of core with nothing from core at run time (FR16). It does not say how a theme's resolved values reach Swift.spec:AST-093(current) requires brand values to come from the theme (FR4). It defines one spec per component and no place for rules shared by every Swift component, so this PR addspackages/native/specs/swift/library/beside the component specs.packages/native/scripts/swift-ios-theme.mjs, and its drift test generate core's default theme only. This spec describes the general form that script grows into.Decision
PortableTheme(aDefinedThemepasses unchanged); values come only from core'sresolveThemeTokensfor light and dark.AstryxTokens.swift(typed members per group) and one file per theme declaringAstryxTheme.<name>(neutral→.neutral,y2k→.y2k; core's defaults, resolved with no theme, →.default).font-family-*; adding a group is one PR with its first reader.color-text-primary→color.textPrimary,spacing-0-5→space.s0_5,text-body-size→font.bodySize); collisions and keywords fail with both names.Color,CGFloat,[String]) or the run fails with theme, mode, token, and value.AstryxTheme.neutral.local.dark.colors["--astryx-theme-neutral-color-status-fill-accent"]); an undeclared name returnsnil.Font.custom(_:size:relativeTo:)when the app has the font, otherwise the system font; the library never bundles fonts.AstryxTheme.nativeis reserved and empty.packages/native/, listing by name every build-time read AST-082 FR16 allows: the generator's two theme entries, the contract generator's reads of core's component documentation and built-in icon names, and the strings generator's read of core's locale catalogs.defineNativeThemeinto the reserved slot; composing intent insidedefineThemeis outside this spec.Rejected alternatives
Claim scope and non-goals
Moving the existing SwiftUI views to typed members, filling the native slot, and a core Increase Contrast mode are outside this PR. Extending the package-boundary check (D1) lands as its own pull request.
Evidence and implementation relationship
Files only:
packages/native/specs/swift/library/theme-generator.md,packages/native/specs/swift/library/README.md, and one line inpackages/native/specs/README.md. Published theme packages checked: butter, chocolate, gothic, matcha, neutral, stone, y2k (probe is private); theiroklch()andcolor-mix()values sit outside the kept groups.Writing rubric results
Scope
packages/native/.Validation
check:knowledgeandcheck:package-boundaries) pass.