@astryxdesign/core 0.7.2-canary.d150f78 → 0.7.2-canary.d3ec0b2

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.
@@ -7,7 +7,6 @@
7
7
  * SYNC: When modified, update these files to stay in sync:
8
8
  * - /packages/core/src/AspectRatio/AspectRatio.doc.mjs
9
9
  * - /packages/core/src/AspectRatio/AspectRatio.test.tsx
10
- * - /packages/core/src/reset.css (AspectRatio fit baseline rules)
11
10
  * - /apps/storybook/stories/AspectRatio.stories.tsx
12
11
  * - /packages/cli/assets/templates/blocks/components/AspectRatio/ (showcase blocks)
13
12
  */
@@ -80,13 +79,12 @@ export interface AspectRatioProps extends BaseProps<HTMLDivElement> {
80
79
  * (`object-fit: contain`).
81
80
  * - `center`: child keeps its natural size, centered in the box.
82
81
  *
83
- * `cover`/`contain` child sizing ships as zero-specificity baseline rules
84
- * in `reset.css`, keyed on the `data-astryx-aspect-ratio-override`
85
- * attribute the component sets on the child's direct parent. Any styles
86
- * the child sets itself still win, so children that already size
87
- * themselves keep their behavior. When omitted, the child is left
88
- * unstyled (the pre-existing contract). `fit` is structural, not visual,
89
- * so it is not exposed on the theming surface.
82
+ * `cover`/`contain` size the child from the component's own styles, in
83
+ * the `astryx-base` cascade layer. Styles in a later layer (Tailwind
84
+ * utilities, `astryx-theme`), unlayered CSS, and inline styles on the
85
+ * child still win. When omitted, the child is left unstyled (the
86
+ * pre-existing contract). `fit` is structural, not visual, so it is not
87
+ * exposed on the theming surface.
90
88
  *
91
89
  * @example
92
90
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"AspectRatio.d.ts","sourceRoot":"","sources":["../../src/AspectRatio/AspectRatio.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAI5C;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACjE,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IAErB;;;;;;;OAOG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB;AAgDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAmB,EACnB,GAAG,EACH,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,KAAK,EACT,EAAE,gBAAgB,+BA4BlB;yBAtCe,WAAW"}
1
+ {"version":3,"file":"AspectRatio.d.ts","sourceRoot":"","sources":["../../src/AspectRatio/AspectRatio.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAI5C;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACjE,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IAErB;;;;;;;OAOG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB;AAkED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAmB,EACnB,GAAG,EACH,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,KAAK,EACT,EAAE,gBAAgB,+BAgClB;yBA1Ce,WAAW"}
@@ -9,7 +9,6 @@
9
9
  * SYNC: When modified, update these files to stay in sync:
10
10
  * - /packages/core/src/AspectRatio/AspectRatio.doc.mjs
11
11
  * - /packages/core/src/AspectRatio/AspectRatio.test.tsx
12
- * - /packages/core/src/reset.css (AspectRatio fit baseline rules)
13
12
  * - /apps/storybook/stories/AspectRatio.stories.tsx
14
13
  * - /packages/cli/assets/templates/blocks/components/AspectRatio/ (showcase blocks)
15
14
  */
@@ -132,10 +131,52 @@ export function AspectRatio({
132
131
  0: {
133
132
  className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d"
134
133
  },
135
- 1: {
134
+ 8: {
136
135
  className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k"
136
+ },
137
+ 4: {
138
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq"
139
+ },
140
+ 12: {
141
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq"
142
+ },
143
+ 2: {
144
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x492jj3"
145
+ },
146
+ 10: {
147
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x492jj3"
148
+ },
149
+ 6: {
150
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x492jj3"
151
+ },
152
+ 14: {
153
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x492jj3"
154
+ },
155
+ 1: {
156
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x16lv2iq"
157
+ },
158
+ 9: {
159
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x16lv2iq"
160
+ },
161
+ 5: {
162
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x16lv2iq"
163
+ },
164
+ 13: {
165
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x16lv2iq"
166
+ },
167
+ 3: {
168
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x16lv2iq"
169
+ },
170
+ 11: {
171
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x16lv2iq"
172
+ },
173
+ 7: {
174
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x16lv2iq"
175
+ },
176
+ 15: {
177
+ className: "x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x16lv2iq"
137
178
  }
138
- }[!!(fit === 'center') << 0],
179
+ }[!!(fit === 'center') << 3 | !!(fit === 'cover' || fit === 'contain') << 2 | !!(fit === 'cover') << 1 | !!(fit === 'contain') << 0],
139
180
  children: children
140
181
  })
141
182
  });
package/dist/astryx.css CHANGED
@@ -1483,6 +1483,8 @@
1483
1483
  .x1nwey30:is([dir="rtl"] *):not(#\#):not(#\#):not(#\#){mask-image:linear-gradient(to left,transparent var(--_tab-strip-bleed),black calc(var(--_tab-strip-bleed) + var(--spacing-8)))}
1484
1484
  .x8ulde1:is([dir="rtl"] *):not(#\#):not(#\#):not(#\#){mask-image:linear-gradient(to right,transparent 0%,rgba(0,0,0,.3) 2px,black var(--spacing-1))}
1485
1485
  .x1rxa4r8:is([dir="rtl"] *):not(#\#):not(#\#):not(#\#){mask-image:linear-gradient(to right,transparent var(--_tab-strip-bleed),black calc(var(--_tab-strip-bleed) + var(--spacing-8)))}
1486
+ .x16lv2iq:not([stylex-hack]) > :is(img, video):not(#\#):not(#\#):not(#\#){object-fit:contain}
1487
+ .x492jj3:not([stylex-hack]) > :is(img, video):not(#\#):not(#\#):not(#\#){object-fit:cover}
1486
1488
  .x1euntei:focus-within:not(#\#):not(#\#):not(#\#){opacity:1}
1487
1489
  .x25t5g8:focus-visible:not(#\#):not(#\#):not(#\#){opacity:1}
1488
1490
  .xof6bs:is(th:hover *):not(#\#):not(#\#):not(#\#){opacity:1}
@@ -2017,11 +2019,13 @@
2017
2019
  .x1uyokj7:not(#\#):not(#\#):not(#\#):not(#\#){width:var(--x-inlineSize)}
2018
2020
  .x5lhr3w:not(#\#):not(#\#):not(#\#):not(#\#){width:var(--x-width)}
2019
2021
  .x1wp2rvj.x1wp2rvj:where(.x139im0d:last-child *):not(#\#):not(#\#):not(#\#):not(#\#){border-bottom-width:0}
2022
+ .x1m6kvgq:not([stylex-hack]) > *:not(#\#):not(#\#):not(#\#):not(#\#){height:100%}
2020
2023
  .x1vonza8.x1vonza8:where(.astryx-input-group > *):not(#\#):not(#\#):not(#\#):not(#\#){height:100%}
2021
2024
  .x132qfvm:focus-within:not(#\#):not(#\#):not(#\#):not(#\#){height:auto}
2022
2025
  .xsg11nj.xsg11nj:where(.x-default-marker:has(> .astryx-layout-footer:not([data-divider])) *):not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:0}
2023
2026
  .x1ioh5az.x1ioh5az:where(.x-default-marker:has(> .astryx-layout-header:not([data-divider])) *):not(#\#):not(#\#):not(#\#):not(#\#){padding-top:0}
2024
2027
  .x1kw28su:focus-within:not(#\#):not(#\#):not(#\#):not(#\#){padding-top:var(--spacing-1)}
2028
+ .xyz6fim:not([stylex-hack]) > *:not(#\#):not(#\#):not(#\#):not(#\#){width:100%}
2025
2029
  .x10okhzq:focus-within:not(#\#):not(#\#):not(#\#):not(#\#){width:auto}
2026
2030
  .x5du68j:has(~ * [data-chat-name]):not(#\#):not(#\#):not(#\#):not(#\#){margin-top:var(--spacing-5)}
2027
2031
  .xzzx6db:has([role="radio"]:not([aria-label])):not(#\#):not(#\#):not(#\#):not(#\#){max-width:100%}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.7.2-canary.d150f78",
3
+ "version": "0.7.2-canary.d3ec0b2",
4
4
  "displayName": "Astryx Core",
5
5
  "description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
6
6
  "author": "Meta Open Source",
@@ -792,8 +792,8 @@
792
792
  "react-dom": ">=19.0.0"
793
793
  },
794
794
  "devDependencies": {
795
- "@astryxdesign/a11y-spec": "0.7.2-canary.d150f78",
796
- "@astryxdesign/cli": "0.7.2-canary.d150f78",
795
+ "@astryxdesign/a11y-spec": "0.7.2-canary.d3ec0b2",
796
+ "@astryxdesign/cli": "0.7.2-canary.d3ec0b2",
797
797
  "@babel/cli": "^7.29.7",
798
798
  "@babel/core": "^7.29.7",
799
799
  "@babel/preset-react": "^7.29.7",
@@ -9,7 +9,7 @@
9
9
  * SYNC: When AspectRatio.tsx changes, update tests to match new behavior
10
10
  */
11
11
 
12
- import {describe, it, expect, vi, beforeAll} from 'vitest';
12
+ import {describe, it, expect, vi} from 'vitest';
13
13
  import {render, screen} from '@testing-library/react';
14
14
  import {AspectRatio} from './AspectRatio';
15
15
 
@@ -230,9 +230,8 @@ describe('AspectRatio', () => {
230
230
  <img src="test.jpg" alt="Test" data-testid="image" />
231
231
  </AspectRatio>,
232
232
  );
233
- // The marker sits on the child's actual parent, so the reset.css
234
- // sizing rules are direct-child selectors with no dependence on
235
- // AspectRatio's internal structure.
233
+ // Earlier releases documented the marker, so it stays on the child's
234
+ // direct parent for product CSS that targets it.
236
235
  const wrapper = screen.getByTestId('image').parentElement;
237
236
  expect(wrapper).toHaveAttribute(
238
237
  'data-astryx-aspect-ratio-override',
@@ -274,8 +273,11 @@ describe('AspectRatio', () => {
274
273
  );
275
274
  const wrapper = screen.getByTestId('image').parentElement;
276
275
  expect(wrapper).not.toHaveAttribute('data-astryx-aspect-ratio-override');
277
- // Without the marker, none of the reset.css fit rules can match, so
278
- // existing self-styled children render exactly as before.
276
+ // Without fit the wrapper carries no child-sizing styles, so existing
277
+ // self-styled children render exactly as before.
278
+ expect(wrapper?.className).not.toContain('childFill');
279
+ expect(wrapper?.className).not.toContain('childCover');
280
+ expect(wrapper?.className).not.toContain('childContain');
279
281
  expect(screen.getByTestId('image')).not.toHaveAttribute('class');
280
282
  });
281
283
 
@@ -292,13 +294,37 @@ describe('AspectRatio', () => {
292
294
  </AspectRatio>,
293
295
  );
294
296
  const image = screen.getByTestId('image');
295
- // Fit styling is pure CSS (zero-specificity reset rules); the child's
296
- // own className/style pass through untouched and always win, so
297
- // children that already size themselves keep their behavior.
297
+ // Fit styling is a direct-child rule on the wrapper; the child's own
298
+ // className/style pass through untouched, and an inline style still
299
+ // wins over it.
298
300
  expect(image.className).toBe('consumer-class');
299
301
  expect(image.style.objectFit).toBe('contain');
300
302
  });
301
303
 
304
+ it('sizes the child from the wrapper with fit="cover"', () => {
305
+ render(
306
+ <AspectRatio ratio={16 / 9} fit="cover">
307
+ <img src="test.jpg" alt="Test" data-testid="image" />
308
+ </AspectRatio>,
309
+ );
310
+ const wrapper = screen.getByTestId('image').parentElement;
311
+ expect(wrapper?.className).toContain('childFill');
312
+ expect(wrapper?.className).toContain('childCover');
313
+ expect(wrapper?.className).not.toContain('childContain');
314
+ });
315
+
316
+ it('sizes the child from the wrapper with fit="contain"', () => {
317
+ render(
318
+ <AspectRatio ratio={16 / 9} fit="contain">
319
+ <img src="test.jpg" alt="Test" data-testid="image" />
320
+ </AspectRatio>,
321
+ );
322
+ const wrapper = screen.getByTestId('image').parentElement;
323
+ expect(wrapper?.className).toContain('childFill');
324
+ expect(wrapper?.className).toContain('childContain');
325
+ expect(wrapper?.className).not.toContain('childCover');
326
+ });
327
+
302
328
  it('centers the child via the wrapper with fit="center"', () => {
303
329
  render(
304
330
  <AspectRatio ratio={16 / 9} fit="center">
@@ -309,6 +335,7 @@ describe('AspectRatio', () => {
309
335
  expect(image).not.toHaveAttribute('class');
310
336
  const wrapper = image.parentElement;
311
337
  expect(wrapper?.className).toContain('childCenter');
338
+ expect(wrapper?.className).not.toContain('childFill');
312
339
  });
313
340
 
314
341
  it('does not center the wrapper for other fit values', () => {
@@ -353,45 +380,19 @@ describe('AspectRatio', () => {
353
380
  });
354
381
  });
355
382
 
356
- describe('reset.css fit baseline rules', () => {
357
- // The cover/contain child sizing ships as zero-specificity baseline
358
- // rules in reset.css keyed on the data-astryx-aspect-ratio-override
359
- // marker the component sets on the child's direct parent. These
360
- // assertions keep the stylesheet in sync with the component contract.
361
- let resetCSS: string;
362
-
363
- beforeAll(async () => {
383
+ describe('reset.css', () => {
384
+ it('carries no AspectRatio rules', async () => {
385
+ // fit ships with the component's StyleX styles in `astryx-base`. A
386
+ // rule in reset.css sits below the layer the documented Tailwind
387
+ // setups give preflight, whose `img, video { height: auto }` would
388
+ // undo the fill.
364
389
  const fs = await import('fs');
365
390
  const path = await import('path');
366
- resetCSS = fs.readFileSync(
391
+ const resetCSS = fs.readFileSync(
367
392
  path.resolve(__dirname, '../reset.css'),
368
393
  'utf-8',
369
394
  );
370
- });
371
-
372
- it('sizes the child to fill the box for cover and contain', () => {
373
- const fillMatch = resetCSS.match(
374
- /:where\(\[data-astryx-aspect-ratio-override="cover"\], \[data-astryx-aspect-ratio-override="contain"\]\)\s*>\s*:where\(\*\)\s*\{([^}]+)\}/,
375
- );
376
- expect(fillMatch).not.toBeNull();
377
- expect(fillMatch![1]).toContain('width: 100%');
378
- expect(fillMatch![1]).toContain('height: 100%');
379
- });
380
-
381
- it('crops media with object-fit: cover for fit="cover"', () => {
382
- const coverMatch = resetCSS.match(
383
- /:where\(\[data-astryx-aspect-ratio-override="cover"\]\)\s*>\s*:where\(img, video\)\s*\{([^}]+)\}/,
384
- );
385
- expect(coverMatch).not.toBeNull();
386
- expect(coverMatch![1]).toContain('object-fit: cover');
387
- });
388
-
389
- it('letterboxes media with object-fit: contain for fit="contain"', () => {
390
- const containMatch = resetCSS.match(
391
- /:where\(\[data-astryx-aspect-ratio-override="contain"\]\)\s*>\s*:where\(img, video\)\s*\{([^}]+)\}/,
392
- );
393
- expect(containMatch).not.toBeNull();
394
- expect(containMatch![1]).toContain('object-fit: contain');
395
+ expect(resetCSS).not.toContain('aspect-ratio-override');
395
396
  });
396
397
  });
397
398
  });
@@ -9,7 +9,6 @@
9
9
  * SYNC: When modified, update these files to stay in sync:
10
10
  * - /packages/core/src/AspectRatio/AspectRatio.doc.mjs
11
11
  * - /packages/core/src/AspectRatio/AspectRatio.test.tsx
12
- * - /packages/core/src/reset.css (AspectRatio fit baseline rules)
13
12
  * - /apps/storybook/stories/AspectRatio.stories.tsx
14
13
  * - /packages/cli/assets/templates/blocks/components/AspectRatio/ (showcase blocks)
15
14
  */
@@ -91,13 +90,12 @@ export interface AspectRatioProps extends BaseProps<HTMLDivElement> {
91
90
  * (`object-fit: contain`).
92
91
  * - `center`: child keeps its natural size, centered in the box.
93
92
  *
94
- * `cover`/`contain` child sizing ships as zero-specificity baseline rules
95
- * in `reset.css`, keyed on the `data-astryx-aspect-ratio-override`
96
- * attribute the component sets on the child's direct parent. Any styles
97
- * the child sets itself still win, so children that already size
98
- * themselves keep their behavior. When omitted, the child is left
99
- * unstyled (the pre-existing contract). `fit` is structural, not visual,
100
- * so it is not exposed on the theming surface.
93
+ * `cover`/`contain` size the child from the component's own styles, in
94
+ * the `astryx-base` cascade layer. Styles in a later layer (Tailwind
95
+ * utilities, `astryx-theme`), unlayered CSS, and inline styles on the
96
+ * child still win. When omitted, the child is left unstyled (the
97
+ * pre-existing contract). `fit` is structural, not visual, so it is not
98
+ * exposed on the theming surface.
101
99
  *
102
100
  * @example
103
101
  * ```
@@ -140,15 +138,33 @@ const styles = stylex.create({
140
138
  height: '100%',
141
139
  },
142
140
  // fit="center" centers the child at its natural size from the wrapper —
143
- // no styles on the child itself. The `cover`/`contain` child sizing can't
144
- // live here (StyleX has no descendant selectors); it ships as baseline
145
- // rules in reset.css keyed on the `data-astryx-aspect-ratio-override`
146
- // attribute the wrapper carries (see below).
141
+ // no styles on the child itself.
147
142
  childCenter: {
148
143
  display: 'flex',
149
144
  alignItems: 'center',
150
145
  justifyContent: 'center',
151
146
  },
147
+ // `cover`/`contain` must style the child itself (`object-fit` only applies
148
+ // on the replaced element), and StyleX has no child selector. The
149
+ // `:not([stylex-hack])` pseudo-class always matches, so StyleX accepts the
150
+ // key and emits `.x:not([stylex-hack]) > *`, a direct-child rule in the
151
+ // `astryx-base` layer like every other component style.
152
+ childFill: {
153
+ ':not([stylex-hack]) > *': {
154
+ width: '100%',
155
+ height: '100%',
156
+ },
157
+ },
158
+ childCover: {
159
+ ':not([stylex-hack]) > :is(img, video)': {
160
+ objectFit: 'cover',
161
+ },
162
+ },
163
+ childContain: {
164
+ ':not([stylex-hack]) > :is(img, video)': {
165
+ objectFit: 'contain',
166
+ },
167
+ },
152
168
  });
153
169
 
154
170
  // The ratio compiles to a CSS variable + a class-level declaration
@@ -234,14 +250,18 @@ export function AspectRatio({
234
250
  style,
235
251
  )}
236
252
  {...props}>
237
- {/* The marker attribute carries the fit value so the reset.css child
238
- sizing can use direct-child selectors on this wrapper — the child's
239
- actual parent — without depending on AspectRatio's internal
240
- structure or on the theming surface (fit is structural, not
241
- themeable). The name is namespaced to avoid collisions. */}
253
+ {/* The marker attribute carries the fit value. No Astryx style keys on
254
+ it any more, but earlier releases documented it, so product CSS may
255
+ still target it. */}
242
256
  <div
243
257
  data-astryx-aspect-ratio-override={fit}
244
- {...stylex.props(styles.child, fit === 'center' && styles.childCenter)}>
258
+ {...stylex.props(
259
+ styles.child,
260
+ fit === 'center' && styles.childCenter,
261
+ (fit === 'cover' || fit === 'contain') && styles.childFill,
262
+ fit === 'cover' && styles.childCover,
263
+ fit === 'contain' && styles.childContain,
264
+ )}>
245
265
  {children}
246
266
  </div>
247
267
  </div>
@@ -0,0 +1,157 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file AspectRatioFitLayers.a11y.browser.spec.ts
5
+ * @input The built FitModes story (its rendered markup and compiled CSS) and
6
+ * Tailwind's preflight.css
7
+ * @output Browser evidence that `fit` fills the box on the documented setups
8
+ * @position AspectRatio integration proof. Which rule sizes the child is a
9
+ * cascade-layer question, and only a shipping engine resolves the cascade.
10
+ */
11
+
12
+ import * as fs from 'node:fs';
13
+ import {fileURLToPath} from 'node:url';
14
+ import {expect, test, type Page} from '@playwright/test';
15
+ import {
16
+ DEFAULT_STORYBOOK_DIR,
17
+ serveStorybook,
18
+ type StaticServer,
19
+ } from '@astryxdesign/a11y-spec/storybook';
20
+
21
+ const PREFLIGHT_CSS = fs.readFileSync(
22
+ fileURLToPath(import.meta.resolve('tailwindcss/preflight.css')),
23
+ 'utf8',
24
+ );
25
+
26
+ // The layer order each setup guide declares, and the layer preflight goes in.
27
+ const TAILWIND_SETUPS = [
28
+ {
29
+ name: 'Tailwind v4',
30
+ order:
31
+ '@layer reset, theme, base, astryx-base, astryx-theme, components, utilities;',
32
+ preflightLayer: 'base',
33
+ },
34
+ {
35
+ name: 'Tailwind v3',
36
+ order: '@layer reset, tw-preflight, astryx-base, astryx-theme;',
37
+ preflightLayer: 'tw-preflight',
38
+ },
39
+ ];
40
+
41
+ // A 100×100 image in a 320px-wide 16:9 box: filling the box makes it 320×180.
42
+ const IMAGE =
43
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'/%3E";
44
+
45
+ type Fit = 'cover' | 'contain';
46
+
47
+ let storybook: StaticServer;
48
+ test.beforeAll(async () => {
49
+ storybook = await serveStorybook(
50
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
51
+ );
52
+ });
53
+ test.afterAll(async () => {
54
+ await storybook?.close();
55
+ });
56
+
57
+ /**
58
+ * The markup AspectRatio renders for `fit`, and every CSS rule the story
59
+ * page loaded, taken from the built story so the classes and rules are the
60
+ * component's real compiled output. The child image gets a fixed id, a
61
+ * local source and any extra class.
62
+ */
63
+ async function captureStory(page: Page, fit: Fit, mediaClass: string) {
64
+ await page.goto(
65
+ `${storybook.origin}/iframe.html?id=core-aspectratio--fit-modes&viewMode=story`,
66
+ );
67
+ const wrapper = page.locator(`[data-astryx-aspect-ratio-override="${fit}"]`);
68
+ await expect(wrapper).toHaveCount(1);
69
+ return wrapper.evaluate(
70
+ (element, {image, extraClass}) => {
71
+ const root = element.parentElement?.cloneNode(true);
72
+ const media =
73
+ root instanceof HTMLElement ? root.querySelector('img') : null;
74
+ if (!(root instanceof HTMLElement) || media == null) {
75
+ throw new Error('FitModes no longer renders an img inside AspectRatio');
76
+ }
77
+ media.id = 'media';
78
+ media.src = image;
79
+ if (extraClass) {
80
+ media.classList.add(extraClass);
81
+ }
82
+ const css = [...document.styleSheets]
83
+ .flatMap(sheet => [...sheet.cssRules].map(rule => rule.cssText))
84
+ .join('\n');
85
+ return {html: root.outerHTML, css};
86
+ },
87
+ {image: IMAGE, extraClass: mediaClass},
88
+ );
89
+ }
90
+
91
+ /** Re-host the captured story with `before` CSS ahead of it and `after` CSS behind it. */
92
+ async function measureMedia(
93
+ page: Page,
94
+ fit: Fit,
95
+ {
96
+ before = [],
97
+ after = [],
98
+ mediaClass = '',
99
+ }: {
100
+ before?: string[];
101
+ after?: string[];
102
+ mediaClass?: string;
103
+ },
104
+ ) {
105
+ const {html, css} = await captureStory(page, fit, mediaClass);
106
+ await page.setContent(
107
+ `<!doctype html><div style="width: 320px">${html}</div>`,
108
+ );
109
+ for (const content of [...before, css, ...after]) {
110
+ await page.addStyleTag({content});
111
+ }
112
+ await page.waitForFunction(
113
+ () => (document.getElementById('media') as HTMLImageElement).complete,
114
+ );
115
+ return page.evaluate(() => {
116
+ const media = document.getElementById('media');
117
+ if (!media) {
118
+ throw new Error('missing media');
119
+ }
120
+ const box = media.getBoundingClientRect();
121
+ return {
122
+ width: box.width,
123
+ height: box.height,
124
+ objectFit: getComputedStyle(media).objectFit,
125
+ };
126
+ });
127
+ }
128
+
129
+ for (const setup of TAILWIND_SETUPS) {
130
+ for (const fit of ['cover', 'contain'] as const) {
131
+ test(`fit="${fit}" fills the box on the ${setup.name} setup`, async ({
132
+ page,
133
+ }) => {
134
+ const media = await measureMedia(page, fit, {
135
+ before: [
136
+ setup.order,
137
+ `@layer ${setup.preflightLayer} { ${PREFLIGHT_CSS} }`,
138
+ ],
139
+ });
140
+ expect(media).toEqual({width: 320, height: 180, objectFit: fit});
141
+ });
142
+ }
143
+ }
144
+
145
+ test('fit fills the box with only Astryx CSS loaded', async ({page}) => {
146
+ const media = await measureMedia(page, 'cover', {});
147
+ expect(media).toEqual({width: 320, height: 180, objectFit: 'cover'});
148
+ });
149
+
150
+ test('a utility class on the child still wins over fit', async ({page}) => {
151
+ const media = await measureMedia(page, 'cover', {
152
+ before: [TAILWIND_SETUPS[0].order, `@layer base { ${PREFLIGHT_CSS} }`],
153
+ after: ['@layer utilities { .h-10 { height: 40px; } }'],
154
+ mediaClass: 'h-10',
155
+ });
156
+ expect(media).toEqual({width: 320, height: 40, objectFit: 'cover'});
157
+ });
package/src/reset.css CHANGED
@@ -203,35 +203,6 @@
203
203
  height: auto;
204
204
  }
205
205
 
206
- /* ===========================================================================
207
- AspectRatio Fit Baseline
208
- =========================================================================== */
209
-
210
- /*
211
- * Child sizing for AspectRatio's `fit` prop — the component marks the
212
- * child's direct parent with `data-astryx-aspect-ratio-override` (carrying
213
- * the fit value), and these direct-child rules size the child, so
214
- * consumers don't hand-write width/height/object-fit on every media child.
215
- * The marker sits on the parent itself, so the rules don't depend on
216
- * AspectRatio's internal element structure or its theming surface. As with
217
- * the [data-astryx-media] baseline below, the rules are zero-specificity
218
- * and any styling the child sets itself still wins. `fit="center"` needs
219
- * no rules here — the component centers the child from its own wrapper.
220
- */
221
- :where([data-astryx-aspect-ratio-override="cover"], [data-astryx-aspect-ratio-override="contain"])
222
- > :where(*) {
223
- width: 100%;
224
- height: 100%;
225
- }
226
-
227
- :where([data-astryx-aspect-ratio-override="cover"]) > :where(img, video) {
228
- object-fit: cover;
229
- }
230
-
231
- :where([data-astryx-aspect-ratio-override="contain"]) > :where(img, video) {
232
- object-fit: contain;
233
- }
234
-
235
206
  /* ===========================================================================
236
207
  Forms
237
208
  =========================================================================== */