@astryxdesign/native 0.7.6-canary.e428366 → 0.7.6-canary.eae4b9e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,8 +27,6 @@ let package = Package(
27
27
  name: "Astryx",
28
28
  dependencies: ["AstryxNative"],
29
29
  path: "Sources/Astryx",
30
- // Each component's spec lives beside its view (AST-093 FR1).
31
- exclude: ["Avatar/Avatar.spec.md", "Avatar/AvatarStatusDot.spec.md", "Button/Button.spec.md", "Icon/Icon.spec.md", "TextInput/TextInput.spec.md", "Thumbnail/Thumbnail.spec.md"],
32
30
  resources: [.process("Resources")]
33
31
  ),
34
32
  .testTarget(name: "AstryxNativeTests", dependencies: ["AstryxNative"], path: "Tests/AstryxNativeTests"),
package/apple/README.md CHANGED
@@ -26,13 +26,13 @@ apple/
26
26
  │ │ │ └── Generated/ # typed tokens and every published theme, generated; do not edit
27
27
  │ │ ├── Resources/ # core's messages per locale, generated; do not edit
28
28
  │ │ ├── Localization/
29
- │ │ ├── Icon/ # Icon, Icon.spec.md
30
- │ │ ├── Avatar/ # Avatar, Avatar.spec.md
29
+ │ │ ├── Icon/ # Icon
30
+ │ │ ├── Avatar/ # Avatar
31
31
  │ │ ├── Text/ # Text
32
32
  │ │ ├── Heading/ # Heading
33
33
  │ │ ├── Button/ # Button
34
34
  │ │ ├── TextInput/ # TextInput
35
- │ │ ├── Thumbnail/ # Thumbnail, Thumbnail.spec.md
35
+ │ │ ├── Thumbnail/ # Thumbnail
36
36
  │ │ ├── Card/ # Card
37
37
  │ │ └── Banner/ # Banner
38
38
  │ └── AstryxNative/ # contracts, wire, logic host (module AstryxNative)
@@ -46,6 +46,9 @@ apple/
46
46
  └── Tests/
47
47
  ```
48
48
 
49
+ Each component's Swift spec sits beside its core spec, at
50
+ `docs/specs/components/<ComponentRoot>/<Name>.swift.spec.md`.
51
+
49
52
  - **`Sources/Astryx/<Name>/`** holds one folder per component, named as in
50
53
  `packages/core/src/<Name>/`. Each view has core's component name in the
51
54
  `Astryx` module (`Button`, `Text`), which re-exports SwiftUI and the
@@ -143,6 +146,15 @@ export:
143
146
  node packages/native/scripts/swift-ios-theme.mjs --theme ./src/acmeTheme.ts#acmeTheme --out ./Sources/Theme
144
147
  ```
145
148
 
149
+ The generator reads the CSS forms its spec lists
150
+ (`specs/swift/library/theme-generator.md`, G7): hex and named colors, `rgb()`,
151
+ `hsl()`, `hwb()`, Lab, LCH, OKLab, OKLCH, `color()` in the listed spaces,
152
+ `color-mix()`, and relative colors (wide-gamut colors kept as Display P3;
153
+ a color outside Display P3 clips, as browsers draw it, with a warning),
154
+ lengths with `calc()`, and `[light, dark]` tuples. A value with no static form,
155
+ such as `currentColor` or `50%`, stops the run naming the theme, mode, token,
156
+ and value; so does a form the generator does not read yet, saying so.
157
+
146
158
  A theme's local tokens are not generated yet; the generator names each one it
147
159
  leaves out.
148
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/native",
3
- "version": "0.7.6-canary.e428366",
3
+ "version": "0.7.6-canary.eae4b9e",
4
4
  "description": "Experimental native platforms for Astryx (iOS, Android, macOS, Windows) — published to npm only under the @canary dist-tag; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "peerDependencies": {
73
- "@astryxdesign/core": "0.7.6-canary.e428366"
73
+ "@astryxdesign/core": "0.7.6-canary.eae4b9e"
74
74
  },
75
75
  "devDependencies": {
76
- "@astryxdesign/core": "0.7.6-canary.e428366"
76
+ "@astryxdesign/core": "0.7.6-canary.eae4b9e"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
@@ -14,11 +14,13 @@ import {
14
14
  renderSwiftTheme,
15
15
  swiftMember,
16
16
  swiftThemeName,
17
+ toColor,
17
18
  toFamilies,
18
- toHexColor,
19
+ toLeading,
19
20
  toPoints,
20
21
  renderTokenTypes,
21
22
  toShadow,
23
+ toWeight,
22
24
  tokenSurface,
23
25
  valueForMode,
24
26
  } from '../../scripts/swift-ios-theme.mjs';
@@ -105,25 +107,128 @@ describe('swift theme generator: names (G6)', () => {
105
107
  });
106
108
  });
107
109
 
110
+ // Every row is exact to the 8-bit channel (tolerance 0 of 255). The lab(),
111
+ // lch(), oklab(), and oklch() rows are CSS Color 4's own examples of #7D2329
112
+ // and #C65D06; the rest agree with an independent CSS Color 4 implementation.
113
+ // Outside Display P3, each channel clips, as Chromium 154 draws it.
114
+ const P3_CLIPPED = 'outside Display P3; clipped to match the web';
115
+ const COLORS: [css: string, swift: string, note?: string][] = [
116
+ ['#0064E0', '#0064E0FF'],
117
+ ['#abc8', '#AABBCC88'],
118
+ ['rebeccapurple', '#663399FF'],
119
+ ['transparent', '#00000000'],
120
+ ['rgba(5, 54, 89, 0.1)', '#0536591A'],
121
+ ['rgb(10% 20% 30% / 50%)', '#1A334D80'],
122
+ ['rgb(none 0 0)', '#000000FF'],
123
+ ['rgb(calc(255 / 2) 0 0)', '#800000FF'],
124
+ ['hsl(210 100% 50%)', '#0080FFFF'],
125
+ ['hsla(120, 100%, 25%, 0.5)', '#00800080'],
126
+ ['hsl(0.5turn 50% 50%)', '#40BFBFFF'],
127
+ ['hsl(200grad 50% 50%)', '#40BFBFFF'],
128
+ ['hsl(3.14159rad 50% 50%)', '#40BFBFFF'],
129
+ ['hwb(194 0% 0% / .5)', '#00C4FF80'],
130
+ ['hwb(0 60% 60%)', '#808080FF'],
131
+ ['lab(29.2345% 39.3825 20.0664)', '#7D2329FF'],
132
+ ['lch(52.2345% 72.2 56.2)', '#C65D06FF'],
133
+ ['oklab(40.101% 0.1147 0.0453)', '#7D2329FF'],
134
+ ['oklch(40.101% 0.12332 21.555)', '#7D2329FF'],
135
+ ['oklch(0 0 0 / 5%)', '#0000000D'],
136
+ ['oklch(50% 0 0)', '#636363FF'],
137
+ ['color(srgb 0.5 0.2 0.1)', '#80331AFF'],
138
+ ['color(srgb-linear 0.5 0.2 0.1)', '#BC7C59FF'],
139
+ ['color(display-p3 0.4 0.6 0.2)', '#559B17FF'],
140
+ ['color(a98-rgb 0.4 0.6 0.2)', '#439A22FF'],
141
+ ['color(prophoto-rgb 0.4 0.6 0.2)', '#52B204FF'],
142
+ // rec2020 decodes with the BT.2020 curve, as Chromium 154 draws it.
143
+ ['color(rec2020 0.4 0.6 0.2)', '#4AA829FF'],
144
+ ['color(rec2020 0.5 0.5 0.5)', '#8B8B8BFF'],
145
+ ['color(xyz-d65 0.2 0.3 0.4)', 'display-p3 #44A4A3FF'],
146
+ ['color(xyz-d50 0.2 0.3 0.4)', 'display-p3 #2CA5BAFF'],
147
+ ['color(display-p3 1 0 0)', 'display-p3 #FF0000FF'],
148
+ ['color-mix(in srgb, red, blue)', '#800080FF'],
149
+ ['color-mix(in srgb, red 30%, blue)', '#4D00B3FF'],
150
+ ['color-mix(in srgb, red 20%, blue 20%)', '#80008066'],
151
+ ['color-mix(in srgb, rgb(255 0 0 / .5), blue)', '#5500AABF'],
152
+ ['color-mix(in srgb, rgb(none 50 0), rgb(10 200 0))', '#0A7D00FF'],
153
+ ['color-mix(in srgb-linear, red, blue)', '#BC00BCFF'],
154
+ ['color-mix(in xyz, red, blue)', '#BC00BCFF'],
155
+ ['color-mix(in display-p3, red, blue)', '#800A91FF'],
156
+ ['color-mix(in oklab, red, blue)', '#8C53A2FF'],
157
+ ['color-mix(red, blue)', '#8C53A2FF'],
158
+ ['color-mix(in lab, red, blue)', 'display-p3 #B01185FF'],
159
+ ['color-mix(in hsl, red, blue)', '#FF00FFFF'],
160
+ ['color-mix(in oklch, red, blue)', 'display-p3 #AA00BBFF', P3_CLIPPED],
161
+ [
162
+ 'color-mix(in oklch longer hue, red, blue)',
163
+ 'display-p3 #009000FF',
164
+ P3_CLIPPED,
165
+ ],
166
+ ['rgb(from #123456 calc(r + 10) g b)', '#1C3456FF'],
167
+ ['rgb(from red r g b / 50%)', '#FF000080'],
168
+ ['hsl(from blue calc(h + 180) s l)', '#FFFF00FF'],
169
+ ['oklch(0.7 0.4 150)', 'display-p3 #00D100FF', P3_CLIPPED],
170
+ ['oklch(0.9 0.4 300)', 'display-p3 #FB7CFFFF', P3_CLIPPED],
171
+ // A relative color keeps its origin's gamut instead of clamping to sRGB.
172
+ ['rgb(from color(display-p3 1 0 0) r g b / 50%)', 'display-p3 #FF000080'],
173
+ ['hwb(from color(display-p3 1 0 0) h w b)', 'display-p3 #FF0000FF'],
174
+ // A missing alpha takes the other color's before premultiplying.
175
+ ['color-mix(in srgb, rgb(255 0 0 / none), rgb(0 0 255 / 0.5))', '#80008080'],
176
+ ['color-mix(in srgb, rgb(255 0 0 / none), rgb(0 0 255 / none))', '#80008000'],
177
+ // A missing blue is not Lab's b: only analogous channels carry over.
178
+ ['color-mix(in lab, rgb(0 0 none), lab(50 20 30))', '#4F3525FF'],
179
+ // HSL lightness is analogous to Lab's, so a missing one carries over.
180
+ ['color-mix(in lab, hsl(0 50% none), lab(50 20 30))', '#8E705EFF'],
181
+ // hsl() saturation clamps at 100% in both syntaxes, as browsers read it.
182
+ ['hsl(120, 200%, 40%)', '#00CC00FF'],
183
+ ['hsl(120 200% 40%)', '#00CC00FF'],
184
+ // Hues are taken modulo 360° before interpolating (400° is 40°).
185
+ ['color-mix(in oklch, oklch(0.6 0.1 400), oklch(0.6 0.1 20))', '#B4685CFF'],
186
+ ];
187
+
108
188
  describe('swift theme generator: values (G7)', () => {
109
- it('reads CSS colors, lengths, and font stacks as Swift values', () => {
110
- expect(toHexColor('#0064E0')).toBe('#0064E0FF');
111
- expect(toHexColor('#fff')).toBe('#FFFFFFFF');
112
- expect(toHexColor('rgba(5, 54, 89, 0.1)')).toBe('#0536591A');
113
- expect(toHexColor('transparent')).toBe('#00000000');
114
- expect(toHexColor('oklch(0 0 0 / 5%)')).toBe('#0000000D');
115
- expect(toHexColor('oklch(1 0 0 / 8%)')).toBe('#FFFFFF14');
116
- expect(toHexColor('oklch(0.5 0 0)')).toBe('#636363FF');
117
- expect(toHexColor('oklch(50% 0 0)')).toBe('#636363FF');
118
- expect(toHexColor('color-mix(in srgb, red, blue)')).toBeNull();
119
- expect(toHexColor('light-dark(#000, #fff)')).toBeNull();
120
- expect(toHexColor('hsl(0 100% 50%)')).toBe('#FF0000FF');
121
- expect(toHexColor('hsl(210 100% 50%)')).toBe('#0080FFFF');
122
- expect(toHexColor('hsla(120, 100%, 25%, 0.5)')).toBe('#00800080');
123
- expect(toPoints('0.875rem')).toBe(14);
124
- expect(toPoints('32px')).toBe(32);
125
- expect(toPoints('600')).toBe(600);
126
- expect(toPoints('calc(1px + 1rem)')).toBeNull();
189
+ it.each(COLORS)('reads the color %s as %s', (css, swift, note) => {
190
+ const notes: string[] = [];
191
+ expect(toColor(css, notes)).toBe(swift);
192
+ expect(notes).toEqual(note ? [note] : []);
193
+ });
194
+
195
+ it('reads lengths, weights, and line heights', () => {
196
+ const lengths: [string, number][] = [
197
+ ['0.875rem', 14],
198
+ ['32px', 32],
199
+ ['12pt', 16],
200
+ ['1in', 96],
201
+ ['0', 0],
202
+ ['calc(1rem + 2px)', 18],
203
+ ['calc((1rem - 2px) * 2)', 28],
204
+ ['max(4px, 0.5rem)', 8],
205
+ ['clamp(2px, 1rem, 12px)', 12],
206
+ ];
207
+ for (const [css, points] of lengths) {
208
+ expect(toPoints(css), css).toBe(points);
209
+ }
210
+ // thin, medium, and thick are lengths only for a border width.
211
+ expect(toPoints('thin', [], {borderWidth: true})).toBe(1);
212
+ expect(toPoints('medium', [], {borderWidth: true})).toBe(3);
213
+ expect(() => toPoints('medium')).toThrow(/names a border width/);
214
+ const notes: string[] = [];
215
+ expect(toPoints('1.5em', notes)).toBe(24);
216
+ expect(notes).toEqual(['em read against the 16px root font size']);
217
+ expect(toWeight('bold')).toBe(700);
218
+ expect(toWeight('normal')).toBe(400);
219
+ expect(toWeight('650')).toBe(650);
220
+ expect(toWeight('bolder', notes)).toBe(700);
221
+ expect(toLeading('1.5', 14)).toBe(1.5);
222
+ expect(toLeading('150%', 14)).toBe(1.5);
223
+ expect(toLeading('21px', 14)).toBe(1.5);
224
+ // An em counts against the style's own size, not the 16-point root.
225
+ expect(toLeading('1.5em', 14)).toBe(1.5);
226
+ expect(toLeading('calc(1em + 7px)', 14)).toBe(1.5);
227
+ expect(toLeading('normal', 14, notes)).toBe(1.2);
228
+ expect(notes.slice(1)).toEqual([
229
+ "bolder read against normal (400), the root's inherited weight",
230
+ 'normal depends on the font; read as 1.2',
231
+ ]);
127
232
  expect(toFamilies('"Figtree", -apple-system, sans-serif')).toEqual([
128
233
  'Figtree',
129
234
  '-apple-system',
@@ -132,50 +237,178 @@ describe('swift theme generator: values (G7)', () => {
132
237
  expect(toFamilies('var(--font-family-body)')).toBeNull();
133
238
  });
134
239
 
135
- it('reads box-shadow lists as drop layers and inset rings (G7)', () => {
240
+ it('fails on a value with no static form, saying why', () => {
241
+ const cases: [() => unknown, RegExp][] = [
242
+ [() => toColor('currentColor'), /currentColor depends on where/],
243
+ [() => toColor('Canvas'), /system color/],
244
+ [() => toColor('var(--brand)'), /var\(--brand\) is not a token/],
245
+ [() => toColor('color(--custom 1 0 0)'), /not a color space/],
246
+ [() => toPoints('50%'), /percentage depends on the box/],
247
+ [() => toPoints('10vh'), /viewport units/],
248
+ [() => toPoints('2ch'), /font-relative units/],
249
+ [() => toPoints('calc(1px + 50%)'), /adds length and percent/],
250
+ [() => toPoints('env(safe-area-inset-top)'), /env\(\) is known only/],
251
+ [() => toWeight('1001'), /from 1 to 1000/],
252
+ [
253
+ () => toShadow('inset 0 1px 2px #000'),
254
+ /SwiftUI draws only inset rings/,
255
+ ],
256
+ ];
257
+ for (const [run, message] of cases) {
258
+ expect(run).toThrow(message);
259
+ }
260
+ });
261
+
262
+ it('reads box-shadow lists as drop layers and inset rings', () => {
136
263
  const neutralLow =
137
264
  '0 2px 4px light-dark(oklch(0 0 0 / 5%), oklch(0 0 0 / 25%)), 0 4px 8px light-dark(oklch(0 0 0 / 10%), oklch(0 0 0 / 40%)), inset 0 0 0 1px light-dark(transparent, oklch(1 0 0 / 8%))';
138
- expect(toShadow(neutralLow, 'light')).toEqual([
265
+ expect(toShadow(valueForMode(neutralLow, 'light'))).toEqual([
139
266
  {x: 0, y: 2, blur: 4, spread: 0, isInset: false, color: '#0000000D'},
140
267
  {x: 0, y: 4, blur: 8, spread: 0, isInset: false, color: '#0000001A'},
141
268
  {x: 0, y: 0, blur: 0, spread: 1, isInset: true, color: '#00000000'},
142
269
  ]);
143
- expect(toShadow(neutralLow, 'dark')?.[2]?.color).toBe('#FFFFFF14');
144
- expect(toShadow('0 2px 4px #4a35200D', 'light')).toEqual([
145
- {x: 0, y: 2, blur: 4, spread: 0, isInset: false, color: '#4A35200D'},
270
+ expect(toShadow(valueForMode(neutralLow, 'dark'))[2]?.color).toBe(
271
+ '#FFFFFF14',
272
+ );
273
+ expect(toShadow('none')).toEqual([]);
274
+ const notes: string[] = [];
275
+ expect(toShadow('#000 0 calc(1px + 1px) 0.25rem 1px', notes)).toEqual([
276
+ {x: 0, y: 2, blur: 4, spread: 0, isInset: false, color: '#000000FF'},
277
+ ]);
278
+ expect(notes).toEqual([
279
+ 'drop layer "#000 0 calc(1px + 1px) 0.25rem 1px" drawn without its spread',
146
280
  ]);
147
- // No exact SwiftUI form: a drop spread, or a blurred or offset inset.
148
- expect(toShadow('0 2px 4px 1px #000', 'light')).toBeNull();
149
- expect(toShadow('inset 0 1px 2px #000', 'light')).toBeNull();
150
281
  });
151
282
 
152
- it('takes light-dark() per mode (G1)', async () => {
283
+ it('takes light-dark() per mode at any depth (G1)', () => {
153
284
  expect(valueForMode('light-dark(#000, #fff)', 'light')).toBe('#000');
154
285
  expect(valueForMode('light-dark(#000, #fff)', 'dark')).toBe('#fff');
155
- expect(
156
- valueForMode('light-dark(rgb(0, 0, 0), rgb(255, 255, 255))', 'dark'),
157
- ).toBe('rgb(255, 255, 255)');
286
+ const mixed = 'color-mix(in srgb, light-dark(red, blue), white)';
287
+ expect(toColor(valueForMode(mixed, 'light'))).toBe('#FF8080FF');
288
+ expect(toColor(valueForMode(mixed, 'dark'))).toBe('#8080FFFF');
158
289
  expect(valueForMode('#123', 'dark')).toBe('#123');
290
+ });
291
+
292
+ it('generates a [light, dark] tuple and a light-dark() value per mode', async () => {
159
293
  const theme = await defineTheme({
160
294
  name: 'acme-brand',
161
- tokens: {'--color-accent': 'light-dark(#000, #fff)'},
295
+ tokens: {
296
+ '--color-accent': 'light-dark(#000, #fff)',
297
+ '--color-border': [
298
+ 'oklch(40.101% 0.12332 21.555)',
299
+ 'color-mix(in srgb, light-dark(red, blue) 50%, white)',
300
+ ],
301
+ '--spacing-4': ['4px', '0.75rem'],
302
+ },
162
303
  });
163
304
  const swift = await renderSwiftTheme(theme);
164
- expect(swift).toContain(
305
+ const [light, dark] = swift.split('dark: Tokens(');
306
+ expect(light).toContain(
165
307
  'accent: Color(.sRGB, red: 0, green: 0, blue: 0, opacity: 1)',
166
308
  );
167
- expect(swift).toContain(
309
+ expect(dark).toContain(
168
310
  'accent: Color(.sRGB, red: 1, green: 1, blue: 1, opacity: 1)',
169
311
  );
312
+ expect(light).toContain(
313
+ 'border: Color(.sRGB, red: 0.49019607843137253, green: 0.13725490196078433, blue: 0.1607843137254902, opacity: 1)',
314
+ );
315
+ expect(dark).toContain(
316
+ 'border: Color(.sRGB, red: 0.5019607843137255, green: 0.5019607843137255, blue: 1, opacity: 1)',
317
+ );
318
+ expect(light).toContain('s4: 4,');
319
+ expect(dark).toContain('s4: 12,');
170
320
  });
171
321
 
172
- it('fails on a value Swift cannot read, naming theme, mode, token, and value', async () => {
322
+ it('fails on a value with no static form, naming theme, mode, token, value, and reason', async () => {
173
323
  const theme = await defineTheme({
174
324
  name: 'acme-brand',
175
- tokens: {'--color-accent': 'color-mix(in srgb, red, blue)'},
325
+ tokens: {'--color-accent': 'currentColor'},
176
326
  });
177
327
  await expect(renderSwiftTheme(theme)).rejects.toThrow(
178
- 'acme-brand light: --color-accent is not a color Swift can read: color-mix(in srgb, red, blue)',
328
+ 'acme-brand light: --color-accent = currentColor: currentColor depends on where the token is used; Swift has no static value',
329
+ );
330
+ });
331
+
332
+ // A value with no static form, and a form the reader does not read, each
333
+ // fail with their own ending (G7).
334
+ const NONE = 'Swift has no static value';
335
+ const READ = 'the Swift theme generator does not read this form';
336
+ it.each([
337
+ ['--font-family-body', 'inherit', 'inherit depends on', NONE],
338
+ ['--font-family-body', '"Figtree", env(x)', 'env() is known', NONE],
339
+ ['--font-family-body', '"Figtree", inherit', 'cannot be one name', READ],
340
+ ['--shadow-low', 'inherit', 'inherit depends on', NONE],
341
+ ['--shadow-low', '0 1px 2px', 'draws in currentColor', NONE],
342
+ ['--color-accent', 'color(display-p3-linear 1 0 0)', 'not a color', READ],
343
+ ])('fails %s: %s, saying why', async (token, value, reason, ending) => {
344
+ const theme = await defineTheme({name: 'acme', tokens: {[token]: value}});
345
+ const {message} = await renderSwiftTheme(theme).catch(error => error);
346
+ expect(message).toContain(reason);
347
+ expect(message.endsWith(`; ${ending}`)).toBe(true);
348
+ });
349
+
350
+ it('reads + and - in calc() only with a space on each side, as CSS does', () => {
351
+ expect(toPoints('calc(1rem - 2px)')).toBe(14);
352
+ expect(() => toPoints('calc(4px+2px)')).toThrow(/space on each side of \+/);
353
+ expect(() => toPoints('calc(1rem-2px)')).toThrow(/space on each side of -/);
354
+ });
355
+
356
+ it.each([
357
+ ['hwb(0, 0%, 0%)', /no comma syntax/],
358
+ ['rgb(255, none, 0)', /cannot hold none/],
359
+ ['rgba(255, 0, 0, none)', /cannot hold none/],
360
+ ['rgb(255, 50%, 0)', /all numbers or all percentages/],
361
+ ['hsl(120, 50, 40)', /saturation and lightness as percentages/],
362
+ ])('fails the comma syntax CSS does not allow: %s', (css, reason) => {
363
+ expect(() => toColor(css)).toThrow(reason);
364
+ });
365
+
366
+ it('warns, naming theme, mode, token, and value, when it clips a color outside Display P3', async () => {
367
+ const theme = await defineTheme({
368
+ name: 'acme-brand',
369
+ tokens: {'--color-accent': 'oklch(0.9 0.4 300)'},
370
+ });
371
+ const warnings: string[] = [];
372
+ const swift = await renderSwiftTheme(theme, {
373
+ warn: message => warnings.push(message),
374
+ });
375
+ expect(swift).toContain('accent: Color(.displayP3,');
376
+ expect(warnings).toEqual([
377
+ 'acme-brand light: --color-accent = oklch(0.9 0.4 300): outside Display P3; clipped to match the web',
378
+ 'acme-brand dark: --color-accent = oklch(0.9 0.4 300): outside Display P3; clipped to match the web',
379
+ ]);
380
+ });
381
+
382
+ it("writes a color outside sRGB as SwiftUI's Display P3 color", async () => {
383
+ const theme = await defineTheme({
384
+ name: 'acme-brand',
385
+ tokens: {'--color-accent': 'color(display-p3 1 0 0 / 50%)'},
386
+ });
387
+ expect(await renderSwiftTheme(theme)).toContain(
388
+ 'accent: Color(.displayP3, red: 1, green: 0, blue: 0, opacity: 0.5019607843137255)',
389
+ );
390
+ });
391
+
392
+ it("keeps a relative color in its origin's gamut through core's var()", async () => {
393
+ const theme = await defineTheme({
394
+ name: 'acme-brand',
395
+ tokens: {
396
+ '--color-accent': 'color(display-p3 1 0 0)',
397
+ '--color-border': 'rgb(from var(--color-accent) r g b / 50%)',
398
+ },
399
+ });
400
+ expect(await renderSwiftTheme(theme)).toContain(
401
+ 'border: Color(.displayP3, red: 1, green: 0, blue: 0, opacity: 0.5019607843137255)',
402
+ );
403
+ });
404
+
405
+ it('turns a length line height into a multiplier of its style size', async () => {
406
+ const theme = await defineTheme({
407
+ name: 'acme-brand',
408
+ tokens: {'--text-body-size': '16px', '--text-body-leading': '20px'},
409
+ });
410
+ expect(await renderSwiftTheme(theme)).toMatch(
411
+ /body: TypeStyleTokens\(size: 16, weight: \d+, leading: 1\.25\)/,
179
412
  );
180
413
  });
181
414
  });