@astryxdesign/native 0.7.6-canary.6bc8efa → 0.7.6-canary.6dded46
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.
- package/apple/README.md +7 -5
- package/package.json +3 -3
- package/src/theme/swiftIOSTheme.test.ts +142 -41
package/apple/README.md
CHANGED
|
@@ -149,11 +149,13 @@ node packages/native/scripts/swift-ios-theme.mjs --theme ./src/acmeTheme.ts#acme
|
|
|
149
149
|
The generator reads the CSS forms its spec lists
|
|
150
150
|
(`specs/swift/library/theme-generator.md`, G7): hex and named colors, `rgb()`,
|
|
151
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
`color-mix()`, and relative colors (wide-gamut colors kept as Display P3),
|
|
153
|
+
lengths with `calc()`, and `[light, dark]` tuples. A value it can only
|
|
154
|
+
approximate, such as a color outside Display P3 (clipped, as browsers draw it),
|
|
155
|
+
prints a warning after the run; a value with no static form, such as
|
|
156
|
+
`currentColor` or `50%`, takes core's default for that token with a warning, or
|
|
157
|
+
stops the run when core has none. A form the generator does not read yet stops
|
|
158
|
+
the run, saying so. Add `--strict` to fail on any warning.
|
|
157
159
|
|
|
158
160
|
A theme's local tokens are not generated yet; the generator names each one it
|
|
159
161
|
leaves out.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/native",
|
|
3
|
-
"version": "0.7.6-canary.
|
|
3
|
+
"version": "0.7.6-canary.6dded46",
|
|
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.
|
|
73
|
+
"@astryxdesign/core": "0.7.6-canary.6dded46"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@astryxdesign/core": "0.7.6-canary.
|
|
76
|
+
"@astryxdesign/core": "0.7.6-canary.6dded46"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import {describe, expect, it} from 'vitest';
|
|
5
|
+
import {describe, expect, it, vi} from 'vitest';
|
|
6
6
|
import {
|
|
7
7
|
CORE_DEFAULTS,
|
|
8
8
|
SWIFT_THEME_DIR,
|
|
9
9
|
SWIFT_TOKENS_FILE,
|
|
10
10
|
defineTheme,
|
|
11
|
+
finishRun,
|
|
11
12
|
localTokensLeftOut,
|
|
12
13
|
publishedThemePackages,
|
|
13
14
|
renderAll,
|
|
@@ -319,34 +320,41 @@ describe('swift theme generator: values (G7)', () => {
|
|
|
319
320
|
expect(dark).toContain('s4: 12,');
|
|
320
321
|
});
|
|
321
322
|
|
|
322
|
-
|
|
323
|
-
const theme = await defineTheme({
|
|
324
|
-
name: 'acme-brand',
|
|
325
|
-
tokens: {'--color-accent': 'currentColor'},
|
|
326
|
-
});
|
|
327
|
-
await expect(renderSwiftTheme(theme)).rejects.toThrow(
|
|
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';
|
|
323
|
+
// A value with no static form takes core's default and warns (G15).
|
|
336
324
|
it.each([
|
|
337
|
-
['--font-family-body', 'inherit', 'inherit depends on'
|
|
338
|
-
['--font-family-body', '"Figtree", env(x)', 'env() is known'
|
|
339
|
-
['--
|
|
340
|
-
['--shadow-low', '
|
|
341
|
-
|
|
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) => {
|
|
325
|
+
['--font-family-body', 'inherit', 'inherit depends on'],
|
|
326
|
+
['--font-family-body', '"Figtree", env(x)', 'env() is known'],
|
|
327
|
+
['--shadow-low', 'inherit', 'inherit depends on'],
|
|
328
|
+
['--shadow-low', '0 1px 2px', 'draws in currentColor'],
|
|
329
|
+
])('falls back from %s: %s, warning why', async (token, value, reason) => {
|
|
344
330
|
const theme = await defineTheme({name: 'acme', tokens: {[token]: value}});
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
expect(
|
|
331
|
+
const warnings: string[] = [];
|
|
332
|
+
await renderSwiftTheme(theme, {warnings});
|
|
333
|
+
expect(warnings).toHaveLength(2);
|
|
334
|
+
for (const warning of warnings) {
|
|
335
|
+
expect(warning).toContain(reason);
|
|
336
|
+
expect(warning).toContain("core's default");
|
|
337
|
+
}
|
|
348
338
|
});
|
|
349
339
|
|
|
340
|
+
// A form the reader does not read fails, saying so (G7).
|
|
341
|
+
it.each([
|
|
342
|
+
['--font-family-body', '"Figtree", inherit', 'cannot be one name'],
|
|
343
|
+
['--color-accent', 'color(display-p3-linear 1 0 0)', 'not a color'],
|
|
344
|
+
])(
|
|
345
|
+
'fails %s: %s as a form it does not read',
|
|
346
|
+
async (token, value, reason) => {
|
|
347
|
+
const theme = await defineTheme({name: 'acme', tokens: {[token]: value}});
|
|
348
|
+
const {message} = await renderSwiftTheme(theme, {warnings: []}).catch(
|
|
349
|
+
error => error,
|
|
350
|
+
);
|
|
351
|
+
expect(message).toContain(reason);
|
|
352
|
+
expect(
|
|
353
|
+
message.endsWith('; the Swift theme generator does not read this form'),
|
|
354
|
+
).toBe(true);
|
|
355
|
+
},
|
|
356
|
+
);
|
|
357
|
+
|
|
350
358
|
it('reads + and - in calc() only with a space on each side, as CSS does', () => {
|
|
351
359
|
expect(toPoints('calc(1rem - 2px)')).toBe(14);
|
|
352
360
|
expect(() => toPoints('calc(4px+2px)')).toThrow(/space on each side of \+/);
|
|
@@ -363,22 +371,6 @@ describe('swift theme generator: values (G7)', () => {
|
|
|
363
371
|
expect(() => toColor(css)).toThrow(reason);
|
|
364
372
|
});
|
|
365
373
|
|
|
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
374
|
it("writes a color outside sRGB as SwiftUI's Display P3 color", async () => {
|
|
383
375
|
const theme = await defineTheme({
|
|
384
376
|
name: 'acme-brand',
|
|
@@ -413,6 +405,115 @@ describe('swift theme generator: values (G7)', () => {
|
|
|
413
405
|
});
|
|
414
406
|
});
|
|
415
407
|
|
|
408
|
+
describe('swift theme generator: diagnostics (G15)', () => {
|
|
409
|
+
it('warns on a lossy value with theme, mode, token, value, and output', async () => {
|
|
410
|
+
const theme = await defineTheme({
|
|
411
|
+
name: 'acme-brand',
|
|
412
|
+
tokens: {'--color-accent': 'oklch(0.7 0.4 150)'},
|
|
413
|
+
});
|
|
414
|
+
const warnings: string[] = [];
|
|
415
|
+
const swift = await renderSwiftTheme(theme, {warnings});
|
|
416
|
+
expect(swift).toContain(
|
|
417
|
+
'accent: Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1)',
|
|
418
|
+
);
|
|
419
|
+
expect(warnings).toEqual([
|
|
420
|
+
`acme-brand light: --color-accent = oklch(0.7 0.4 150) → Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1): ${P3_CLIPPED}`,
|
|
421
|
+
`acme-brand dark: --color-accent = oklch(0.7 0.4 150) → Color(.displayP3, red: 0, green: 0.8196078431372549, blue: 0, opacity: 1): ${P3_CLIPPED}`,
|
|
422
|
+
]);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("takes core's default for a value with no static form, with a warning", async () => {
|
|
426
|
+
const theme = await defineTheme({
|
|
427
|
+
name: 'acme-brand',
|
|
428
|
+
tokens: {'--spacing-4': '2vw'},
|
|
429
|
+
});
|
|
430
|
+
const warnings: string[] = [];
|
|
431
|
+
const swift = await renderSwiftTheme(theme, {warnings});
|
|
432
|
+
const core = await renderSwiftTheme(CORE_DEFAULTS);
|
|
433
|
+
const s4 = (text: string) => /s4: [\d.]+/.exec(text)?.[0];
|
|
434
|
+
expect(s4(swift)).toBe(s4(core));
|
|
435
|
+
expect(warnings[0]).toMatch(
|
|
436
|
+
/^acme-brand light: --spacing-4 = 2vw → \d+: viewport units depend on the screen; core's default \S+ used instead$/,
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('fails when a value has no static form and core has no default', async () => {
|
|
441
|
+
const theme = await defineTheme({
|
|
442
|
+
name: 'acme-brand',
|
|
443
|
+
tokens: {'--color-acme-only': 'currentColor'},
|
|
444
|
+
});
|
|
445
|
+
await expect(renderSwiftTheme(theme)).rejects.toThrow(
|
|
446
|
+
'acme-brand light: --color-acme-only = currentColor: currentColor depends on where the token is used; Swift has no static value',
|
|
447
|
+
);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it('prints warnings to standard error when no list is passed', async () => {
|
|
451
|
+
const theme = await defineTheme({
|
|
452
|
+
name: 'acme-brand',
|
|
453
|
+
tokens: {'--color-accent': 'oklch(0.7 0.4 150)'},
|
|
454
|
+
});
|
|
455
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
456
|
+
try {
|
|
457
|
+
await renderSwiftTheme(theme);
|
|
458
|
+
expect(warn).toHaveBeenCalledTimes(2);
|
|
459
|
+
expect(warn.mock.calls[0][0]).toMatch(
|
|
460
|
+
/^warning: acme-brand light: --color-accent = oklch\(0\.7 0\.4 150\) → /,
|
|
461
|
+
);
|
|
462
|
+
} finally {
|
|
463
|
+
warn.mockRestore();
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("drops a failed value's notes before falling back to core's default", async () => {
|
|
468
|
+
const theme = await defineTheme({
|
|
469
|
+
name: 'acme-brand',
|
|
470
|
+
tokens: {'--spacing-4': 'calc(1em + 2vw)'},
|
|
471
|
+
});
|
|
472
|
+
const warnings: string[] = [];
|
|
473
|
+
await renderSwiftTheme(theme, {warnings});
|
|
474
|
+
expect(warnings).toHaveLength(2);
|
|
475
|
+
for (const warning of warnings) {
|
|
476
|
+
expect(warning).toMatch(
|
|
477
|
+
/viewport units depend on the screen; core's default/,
|
|
478
|
+
);
|
|
479
|
+
expect(warning).not.toMatch(/em read/);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("prints a token's note once per mode", async () => {
|
|
484
|
+
const theme = await defineTheme({
|
|
485
|
+
name: 'acme-brand',
|
|
486
|
+
tokens: {'--spacing-4': 'calc(1em + 1em)'},
|
|
487
|
+
});
|
|
488
|
+
const warnings: string[] = [];
|
|
489
|
+
await renderSwiftTheme(theme, {warnings});
|
|
490
|
+
expect(warnings).toEqual([
|
|
491
|
+
'acme-brand light: --spacing-4 = calc(1em + 1em) → 32: em read against the 16px root font size',
|
|
492
|
+
'acme-brand dark: --spacing-4 = calc(1em + 1em) → 32: em read against the 16px root font size',
|
|
493
|
+
]);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('turns warnings into errors with --strict, before anything is written', async () => {
|
|
497
|
+
const theme = await defineTheme({
|
|
498
|
+
name: 'acme-brand',
|
|
499
|
+
tokens: {'--color-accent': 'oklch(0.7 0.4 150)'},
|
|
500
|
+
});
|
|
501
|
+
await expect(renderSwiftTheme(theme, {strict: true})).rejects.toThrow(
|
|
502
|
+
/2 warning\(s\), which --strict treats as errors:\nerror: acme-brand light: --color-accent/,
|
|
503
|
+
);
|
|
504
|
+
let wrote = false;
|
|
505
|
+
const write = () => {
|
|
506
|
+
wrote = true;
|
|
507
|
+
};
|
|
508
|
+
expect(() => finishRun(['a warning'], true, write)).toThrow(
|
|
509
|
+
/error: a warning/,
|
|
510
|
+
);
|
|
511
|
+
expect(wrote).toBe(false);
|
|
512
|
+
finishRun([], true, write);
|
|
513
|
+
expect(wrote).toBe(true);
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
416
517
|
describe('swift theme generator: local tokens (G8)', () => {
|
|
417
518
|
it('generates no local token and reports each one it leaves out', async () => {
|
|
418
519
|
const theme = await defineTheme({
|