Skip to content

Commit b8b228e

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 4a34b4c + 6b4ecb5 commit b8b228e

99 files changed

Lines changed: 4470 additions & 597 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[chore] Internal: a comment in the theme build names the module that now holds the default width points. No command changes.
6+
7+
@vjeux

‎.changeset/keyed-relations.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/build': patch
3+
---
4+
5+
[perf] Astryx's stylesheets restyle less when a hover, a focus or a press changes. Each StyleX relation that ends in a bare `*`, such as the one `stylex.when.ancestor(':hover')` prints, now names its rule's own class: `:where(.marker:hover :where(.c))` instead of `:where(.marker:hover *)`. Chromium keeps one invalidation set for each pseudo-class for the whole document. One such relation makes it restyle the whole subtree of every element whose state changes. The prebuilt stylesheets, the source builds, and the app rules that the PostCSS and Vite integrations compile print the keyed form. Each rule matches the same elements with the same specificity. A relation that ends in a bare `*` in any other stylesheet on the page still restyles whole subtrees. No API changes.
6+
7+
@vjeux
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[docs] The `ListReorderHandle` file header keeps only its tags, and the measured iOS reorder timing sits once, in the comment beside its `touch-action` style. No behavior change.
6+
7+
@Geervan
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] DropdownMenu, ContextMenu: in the touch sheet, a sub-menu row's chevron and the Back chevron now flip by the menu's own direction (its nearest `dir`), as the popover's already do. In a left-to-right menu inside a right-to-left page, the row chevron used to point left and the Back chevron right, against the sheet's own layout.
6+
7+
@cixzhang
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[perf] `useScrollableArea` and `useScrollOverflow` take their first measurement at the browser's first resize notification after layout, so a `Table` without plugins, a `TabList` and a `SegmentedControl` read no layout or computed style in the commit that mounts them. A `Table` with column resizing, sticky columns or windowing still measures as it mounts. `useScrollableArea` (Table, ScrollableArea, CodeBlock, Tokenizer and BottomSheet) also no longer reads `document.fonts.ready`, which updates style and layout in Chromium. TabList reveals its selected tab at that notification, before the frame paints. SegmentedControl attaches its selection animators at the first selection change or press. `useScrollOverflow` (TabList and Carousel) commits that first measurement before the frame paints, so the edge fades and scroll arrows show from the first frame, at the offset TabList's reveal leaves. Carousel's scroll buttons take that first state without their fade. With `useScrollableArea`, the scroll state, tab stop and edge fade of an area that overflows as it mounts arrive one frame later. A test that stubs `ResizeObserver` delivers that notification, and awaits a microtask for `useScrollOverflow`, before it checks them; where no `ResizeObserver` exists, the first measurement happens at once, as before.
6+
7+
@Sufiyan-MSA
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Popover: a press no longer shrinks a Button, Selector, MultiSelector or ComplexSelector while an open `usePopover` popover points at it through `anchorRef`. Chrome and Safari place the popover from the control's box after the press shrinks it, so the popover moved by up to 1% of the control's width or height while the press was held. The control still shows its pressed overlay, and it shrinks on a press again when the popover closes.
6+
7+
@nynexman4464
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] DropdownMenu, ContextMenu: in a bottom sheet, a checkbox in a row's `endContent` now toggles when it is tapped or clicked, and a switch when it is clicked. A tapped switch now toggles at the release instead of about 300 ms later. The sheet leaves a press that starts on a control in a row's content to that control.
6+
7+
@bstcoc
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[perf] The breakpoint names and the compact definition now live in their own module, which imports nothing. Button, Link, IconButton, Popover, AppShell and every other component entry except Toast no longer import the theme adaptation writer. Toast still does, because its viewport applies the caller's theme. A page that renders them can leave that code out of its first load, also when the app's bundler keeps whole modules. `@astryxdesign/core/theme` exports the same names as before.
6+
7+
@vjeux
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Banner's dismiss button, a field's clear button and Timestamp's copy button no longer have their short tooltip read as a description when their accessible name already contains it, as in English ("Dismiss Project A was archived", "Clear Assignee", "Copy 3:42 PM"). A screen reader read that word twice. The visible "Dismiss", "Clear" and "Copy" tooltips are unchanged.
6+
7+
Reported by:
8+
9+
@duytbp
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file font-loading.spec.ts
5+
* @input Production docsite: the home page at a desktop size and at a phone
6+
* size, the community page, and the playground's preview frame
7+
* @output Proof that the hero reel loads ahead of time each font weight that
8+
* the cards of a slide ask for, and no other; that the themes card draws
9+
* its "Aa" with no text, so that no text of the home page asks for the
10+
* display font of a theme; and that the home page asks for Playwrite US
11+
* Trad at weight 400 only, and the preview frame for the range after it
12+
* @position Docsite browser tests. hero-theme-content.test.ts pins the list
13+
* of fonts; only a browser computes the font that card text asks for.
14+
* Each check reads what a page asks the browser for, and not which font
15+
* files arrive, so no check needs the font host.
16+
*/
17+
18+
import {expect, test, type Page} from '@playwright/test';
19+
import {expectTooltipsLive} from './liveTooltips';
20+
21+
const SLIDE_COUNT = 5;
22+
23+
const FONT_STYLESHEETS =
24+
'link[rel="stylesheet"][href^="https://fonts.googleapis.com/"]';
25+
26+
/** The weights that each font stylesheet of the page asks Playwrite for. */
27+
function playwriteWeights(page: Page) {
28+
return page
29+
.locator(FONT_STYLESHEETS)
30+
.evaluateAll((links: HTMLLinkElement[]) =>
31+
links.map(link =>
32+
new URL(link.href).searchParams
33+
.getAll('family')
34+
.filter(family => family.startsWith('Playwrite US Trad'))
35+
.join(),
36+
),
37+
);
38+
}
39+
40+
// The display fonts of the reel's themes. The site's font stylesheet has
41+
// them for other pages. The home page draws no text in them.
42+
const DISPLAY_FONTS = ['Sarina', 'Manufacturing Consent', 'Crimson Text'];
43+
44+
/**
45+
* Records each `document.fonts.load()` call of the page. Returns a function
46+
* that reads the specifiers of the calls so far.
47+
*/
48+
async function recordFontLoads(page: Page) {
49+
await page.addInitScript(() => {
50+
const loads: string[] = [];
51+
Object.assign(window, {recordedFontLoads: loads});
52+
const load = document.fonts.load.bind(document.fonts);
53+
document.fonts.load = (font: string, text?: string) => {
54+
loads.push(font);
55+
return load(font, text);
56+
};
57+
});
58+
return () =>
59+
page.evaluate(
60+
() =>
61+
(window as unknown as {recordedFontLoads: string[]}).recordedFontLoads,
62+
);
63+
}
64+
65+
/**
66+
* The fonts that drawn text asks for, as `document.fonts.load()` specifiers:
67+
* the first family and the weight of each piece of text that has a box.
68+
* With `inHeroCards`, only the text of the hero cards layer that shows.
69+
*/
70+
function fontsOfText(page: Page, {inHeroCards}: {inHeroCards: boolean}) {
71+
return page.evaluate(heroOnly => {
72+
const reelPhoto = Array.from(document.images).find(
73+
img =>
74+
img.getClientRects().length > 0 &&
75+
/\/landing\/hero\/(?!avatar-)/u.test(
76+
decodeURIComponent(img.currentSrc),
77+
),
78+
);
79+
const root = heroOnly ? reelPhoto?.closest('[inert]') : document.body;
80+
if (root == null) {
81+
return [];
82+
}
83+
const fonts = new Set<string>();
84+
const add = (element: Element) => {
85+
const style = getComputedStyle(element);
86+
const family = style.fontFamily
87+
.split(',')[0]
88+
.trim()
89+
.replace(/^["']|["']$/gu, '');
90+
fonts.add(`${style.fontWeight} 1rem "${family}"`);
91+
};
92+
const range = document.createRange();
93+
const texts = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
94+
for (let text = texts.nextNode(); text != null; text = texts.nextNode()) {
95+
range.selectNodeContents(text);
96+
if (
97+
text.nodeValue?.trim() !== '' &&
98+
text.parentElement != null &&
99+
range.getClientRects().length > 0
100+
) {
101+
add(text.parentElement);
102+
}
103+
}
104+
// A field draws its placeholder in its own font.
105+
for (const field of root.querySelectorAll('input, textarea')) {
106+
if (field.getClientRects().length > 0) {
107+
add(field);
108+
}
109+
}
110+
return Array.from(fonts).sort();
111+
}, inHeroCards);
112+
}
113+
114+
/** The reel's dot for the slide at `position`, from 1. */
115+
function dot(page: Page, position: number) {
116+
return page
117+
.getByRole('navigation', {name: 'Preview Astryx themes'})
118+
.getByRole('radio', {name: `Page ${position}`});
119+
}
120+
121+
/**
122+
* Moves keyboard focus to the reel's dot at `position`, which shows its
123+
* slide. The reel can become live after the shell, so the focus repeats.
124+
*/
125+
async function showSlide(page: Page, position: number) {
126+
await expect(async () => {
127+
await dot(page, position).focus();
128+
await expect(dot(page, position)).toBeChecked({timeout: 1000});
129+
}).toPass();
130+
}
131+
132+
/** Waits until the page's shell is live, and the page has been idle. */
133+
async function settle(page: Page) {
134+
await expectTooltipsLive(
135+
page,
136+
page
137+
.getByRole('navigation', {name: 'Astryx navigation'})
138+
.getByRole('button', {name: 'Search'})
139+
.filter({visible: true})
140+
.first(),
141+
);
142+
await page.waitForLoadState('networkidle');
143+
await page.evaluate(
144+
() =>
145+
new Promise(resolve => {
146+
requestIdleCallback(() => resolve(null), {timeout: 5000});
147+
}),
148+
);
149+
}
150+
151+
test.describe('at a desktop size', () => {
152+
// With reduced motion the reel does not advance by itself while a test
153+
// goes through the slides. It loads the same fonts ahead of time.
154+
test.use({
155+
viewport: {width: 1440, height: 900},
156+
contextOptions: {reducedMotion: 'reduce'},
157+
});
158+
159+
test('the reel loads ahead of time each font weight that a hero card asks for, once, and no other', async ({
160+
page,
161+
}) => {
162+
const fontLoads = await recordFontLoads(page);
163+
await page.goto('/');
164+
await settle(page);
165+
166+
const asked = new Set<string>();
167+
for (let position = 1; position <= SLIDE_COUNT; position++) {
168+
await showSlide(page, position);
169+
const fonts = await fontsOfText(page, {inHeroCards: true});
170+
expect(fonts.length, `slide ${position}`).toBeGreaterThan(0);
171+
fonts.forEach(font => asked.add(font));
172+
}
173+
await expect
174+
.poll(async () => (await fontLoads()).sort())
175+
.toEqual(Array.from(asked).sort());
176+
});
177+
178+
test('no text of the page asks for the display font of a theme', async ({
179+
page,
180+
}) => {
181+
await page.goto('/');
182+
await settle(page);
183+
for (let position = 1; position <= SLIDE_COUNT; position++) {
184+
await showSlide(page, position);
185+
const fonts = await fontsOfText(page, {inHeroCards: false});
186+
expect(
187+
fonts.filter(font =>
188+
DISPLAY_FONTS.some(family => font.includes(`"${family}"`)),
189+
),
190+
`slide ${position}`,
191+
).toEqual([]);
192+
}
193+
});
194+
195+
test('the font stylesheet of the home page asks for Playwrite US Trad at weight 400 only', async ({
196+
page,
197+
}) => {
198+
await page.goto('/');
199+
expect(await playwriteWeights(page)).toEqual([
200+
'Playwrite US Trad:wght@400',
201+
]);
202+
});
203+
204+
test("the playground's preview frame asks for the weight range of Playwrite US Trad, after weight 400", async ({
205+
page,
206+
}) => {
207+
// The frame's document. A browser gives each weight to the later of two
208+
// faces that have it.
209+
await page.goto('/playground/preview');
210+
expect(await playwriteWeights(page)).toEqual([
211+
'Playwrite US Trad:wght@400',
212+
'Playwrite US Trad:wght@100..400',
213+
]);
214+
});
215+
216+
for (const path of ['/', '/community']) {
217+
for (const colorScheme of ['light', 'dark'] as const) {
218+
test(`on ${path} in ${colorScheme} mode, the themes card draws its "Aa" in the place of the text, in the color of the first swatch`, async ({
219+
page,
220+
}) => {
221+
await page.emulateMedia({colorScheme});
222+
await page.goto(path);
223+
await settle(page);
224+
225+
// Two ems of a 2048-unit font wide, one em high.
226+
const drawing = page.locator('svg[viewBox$=" 4096 2048"]');
227+
await expect(drawing).toHaveCount(1);
228+
await expect(drawing).toHaveAttribute('aria-hidden', 'true');
229+
await drawing.scrollIntoViewIfNeeded();
230+
expect(await drawing.boundingBox()).toMatchObject({
231+
width: 48,
232+
height: 24,
233+
});
234+
235+
const {ink, color, swatch, text} = await drawing.evaluate(
236+
(svg: SVGSVGElement) => {
237+
const box = svg.getBoundingClientRect();
238+
const letters = svg.querySelector('path')?.getBoundingClientRect();
239+
const firstSwatch = svg.parentElement?.firstElementChild;
240+
return {
241+
// In px from the left and from the top of the drawing's box.
242+
ink:
243+
letters == null
244+
? []
245+
: [
246+
letters.left - box.left,
247+
letters.top - box.top,
248+
letters.right - box.left,
249+
letters.bottom - box.top,
250+
],
251+
color: getComputedStyle(svg).color,
252+
swatch:
253+
firstSwatch == null
254+
? null
255+
: getComputedStyle(firstSwatch).backgroundColor,
256+
text: svg.parentElement?.textContent,
257+
};
258+
},
259+
);
260+
// The extent of the glyphs "A" and "a" of Sarina at 24px, with the
261+
// "a" 30px after the start of the "A" and the baseline 19px below
262+
// the top of the box.
263+
const extent = [-0.129, 2.957, 50.73, 19.785];
264+
expect(ink).toHaveLength(extent.length);
265+
ink.forEach((edge, index) =>
266+
expect(edge).toBeCloseTo(extent[index], 1),
267+
);
268+
expect(color).toBe(swatch);
269+
expect(text).toBe('');
270+
});
271+
}
272+
}
273+
});
274+
275+
test.describe('at a phone size', () => {
276+
test.use({
277+
viewport: {width: 390, height: 844},
278+
hasTouch: true,
279+
isMobile: true,
280+
});
281+
282+
test('the reel loads for each slide that it does not show first the font weights that the cards of that slide ask for', async ({
283+
page,
284+
}) => {
285+
const fontLoads = await recordFontLoads(page);
286+
await page.goto('/');
287+
await settle(page);
288+
expect(await fontLoads()).toEqual([]);
289+
290+
// The last link of the hero text, which is before the dots. Keyboard
291+
// focus on the dots loads the slides next to the first one.
292+
await page.getByRole('link', {name: 'StyleX', exact: true}).focus();
293+
await page.keyboard.press('Tab');
294+
await expect(dot(page, 1)).toBeFocused();
295+
296+
const asked = new Set<string>();
297+
for (let position = 2; position <= SLIDE_COUNT; position++) {
298+
await page.keyboard.press('ArrowRight');
299+
await expect(dot(page, position)).toBeChecked();
300+
const fonts = await fontsOfText(page, {inHeroCards: true});
301+
expect(fonts.length, `slide ${position}`).toBeGreaterThan(0);
302+
fonts.forEach(font => asked.add(font));
303+
}
304+
expect((await fontLoads()).sort()).toEqual(Array.from(asked).sort());
305+
});
306+
});

0 commit comments

Comments
 (0)