@astryxdesign/core 0.7.16-canary.gfef050d → 0.7.16

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.
@@ -42,4 +42,20 @@ export interface SpringMove {
42
42
  * ```
43
43
  */
44
44
  export declare function resolveSettleMs(element: Element | null | undefined, spring: SpringDescription, move?: SpringMove): number;
45
+ /**
46
+ * How `move` on `spring` plays at the tempo of the theme `element` is in: how
47
+ * long it takes, as `resolveSettleMs` gives it, and its progress over that
48
+ * time as CSS `linear()` easing. A CSS part that takes both follows the
49
+ * spring frame by frame, so the two start and land together. A sheet's scrim
50
+ * fades this way under the sheet's close.
51
+ *
52
+ * With `doneAt`, a position between `from` and `to`, the progress is measured
53
+ * toward `doneAt` instead. It reaches 1 the first time the move gets there
54
+ * and stays at 1. A sheet leaves view before its close ends, because its
55
+ * surface reaches below the screen, and its scrim is clear by then.
56
+ */
57
+ export declare function resolveMoveTiming(element: Element | null | undefined, spring: SpringDescription, move: SpringMove, doneAt?: number): {
58
+ durationMs: number;
59
+ easing: string;
60
+ };
45
61
  //# sourceMappingURL=resolveMotion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMotion.d.ts","sourceRoot":"","sources":["../../src/motion/resolveMotion.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAC/C,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAC;AAmDlB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,iBAAiB,EACvD,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,iBAAiB,CAAC;AACzB,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,KAAK,EAAE,iBAAiB,GACvB,iBAAiB,CAAC;AACrB,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EACxE,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,CAAC,GACL,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAClB,MAAM,GACN,CAAC,CAAC,CAAC,CAAC,SAAS,iBAAiB,GAC5B,iBAAiB,GACjB,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;AA2B/B,yDAAyD;AACzD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,UAAU,GAChB,MAAM,CAKR"}
1
+ {"version":3,"file":"resolveMotion.d.ts","sourceRoot":"","sources":["../../src/motion/resolveMotion.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAC/C,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAC;AAoDlB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,iBAAiB,EACvD,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,iBAAiB,CAAC;AACzB,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,KAAK,EAAE,iBAAiB,GACvB,iBAAiB,CAAC;AACrB,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EACxE,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,CAAC,GACL,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAClB,MAAM,GACN,CAAC,CAAC,CAAC,CAAC,SAAS,iBAAiB,GAC5B,iBAAiB,GACjB,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;AA2B/B,yDAAyD;AACzD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,UAAU,GAChB,MAAM,CAKR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACnC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,MAAgB,GACvB;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAoBtC"}
@@ -7,7 +7,8 @@
7
7
  * plays on, for its theme's tempo (themeTempo.ts)
8
8
  * @output resolveMotion: the role's value at the theme's tempo.
9
9
  * resolveSettleMs: how long a spring role, or one move on it, takes to
10
- * settle there, for a CSS part that plays with it
10
+ * settle there, for a CSS part that plays with it. resolveMoveTiming: that
11
+ * move's duration and its progress as CSS easing
11
12
  * @position Motion foundation; the animator resolves every spring and curve
12
13
  * it is handed with it, and components resolve the durations they time
13
14
  * with it
@@ -31,6 +32,7 @@
31
32
  import { motionRoleIn, motionRoleOf } from "./roles.js";
32
33
  import { isSpring } from "./roleValue.js";
33
34
  import { settlingDuration, solveSpring, toSpring } from "./spring.js";
35
+ import { linearEasing } from "./linearEasing.js";
34
36
  import { themeTempo } from "./themeTempo.js";
35
37
 
36
38
  /**
@@ -130,4 +132,41 @@ export function resolveMotion(element, leafOrGroup, key) {
130
132
  export function resolveSettleMs(element, spring, move) {
131
133
  const resolved = toSpring(resolveMotion(element, spring));
132
134
  return move == null ? settlingDuration(resolved) * 1000 : solveSpring(resolved, move).settleTime(move.epsilon) * 1000;
135
+ }
136
+
137
+ /**
138
+ * How `move` on `spring` plays at the tempo of the theme `element` is in: how
139
+ * long it takes, as `resolveSettleMs` gives it, and its progress over that
140
+ * time as CSS `linear()` easing. A CSS part that takes both follows the
141
+ * spring frame by frame, so the two start and land together. A sheet's scrim
142
+ * fades this way under the sheet's close.
143
+ *
144
+ * With `doneAt`, a position between `from` and `to`, the progress is measured
145
+ * toward `doneAt` instead. It reaches 1 the first time the move gets there
146
+ * and stays at 1. A sheet leaves view before its close ends, because its
147
+ * surface reaches below the screen, and its scrim is clear by then.
148
+ */
149
+ export function resolveMoveTiming(element, spring, move, doneAt = move.to) {
150
+ const curve = solveSpring(toSpring(resolveMotion(element, spring)), move);
151
+ const durationMs = curve.settleTime(move.epsilon) * 1000;
152
+ const span = doneAt - move.from;
153
+ if (span === 0 || durationMs === 0) {
154
+ return {
155
+ durationMs,
156
+ easing: linearEasing(durationMs, () => 1)
157
+ };
158
+ }
159
+ const progressAt = t => (curve.value(t / 1000) - move.from) / span;
160
+ // The first millisecond at which the move reaches `doneAt`, if it does.
161
+ let reachedAt = Infinity;
162
+ for (let t = 0; t <= durationMs; t++) {
163
+ if (progressAt(t) >= 1) {
164
+ reachedAt = t;
165
+ break;
166
+ }
167
+ }
168
+ return {
169
+ durationMs,
170
+ easing: linearEasing(durationMs, t => t >= reachedAt ? 1 : progressAt(t))
171
+ };
133
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.7.16-canary.gfef050d",
3
+ "version": "0.7.16",
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",
@@ -893,6 +893,11 @@
893
893
  "source": "./src/internal/committed-ref.ts",
894
894
  "types": "./dist/internal/committed-ref.d.ts",
895
895
  "default": "./dist/internal/committed-ref.js"
896
+ },
897
+ "./internal/shared-context": {
898
+ "source": "./src/internal/shared-context.ts",
899
+ "types": "./dist/internal/shared-context.d.ts",
900
+ "default": "./dist/internal/shared-context.js"
896
901
  }
897
902
  },
898
903
  "files": [
@@ -925,9 +930,6 @@
925
930
  "react-dom": ">=19.0.0"
926
931
  },
927
932
  "devDependencies": {
928
- "@astryxdesign/a11y-spec": "0.7.16-canary.gfef050d",
929
- "@astryxdesign/cli": "0.7.16-canary.gfef050d",
930
- "@astryxdesign/interaction-harness": "0.7.16-canary.gfef050d",
931
933
  "@babel/cli": "^7.29.7",
932
934
  "@babel/core": "^7.29.7",
933
935
  "@babel/preset-react": "^7.29.7",
@@ -939,7 +941,10 @@
939
941
  "@testing-library/react": "^16.3.3",
940
942
  "@types/babel__core": "^7.20.5",
941
943
  "tailwindcss": "^4.3.2",
942
- "temporal-polyfill": "^1.0.6"
944
+ "temporal-polyfill": "^1.0.6",
945
+ "@astryxdesign/a11y-spec": "0.0.0",
946
+ "@astryxdesign/cli": "0.7.16",
947
+ "@astryxdesign/interaction-harness": "0.0.0"
943
948
  },
944
949
  "dependencies": {
945
950
  "intl-messageformat": "^11.2.9"
@@ -93,6 +93,7 @@ import {
93
93
  BottomSheetPanel,
94
94
  type BottomSheetPanelMotion,
95
95
  type BottomSheetPanelState,
96
+ type ScrimFade,
96
97
  } from './BottomSheetPanel';
97
98
  import {BottomSheetEdgeTint} from './BottomSheetEdgeTint';
98
99
  import {
@@ -212,11 +213,12 @@ const styles = stylex.create({
212
213
  * The dim leaves with the sheet, on a matching curve. A fade covers no
213
214
  * distance, so `--ease-standard` would end it early: 90% faded after 163ms
214
215
  * of a 410ms close, under a sheet that is still sliding. `linear` uses the
215
- * whole duration.
216
+ * whole duration. A touch drag's close writes its spring's progress as the
217
+ * easing instead, so the dim clears as the sheet slides out.
216
218
  */
217
219
  scrimClosing: {
218
220
  '::backdrop': {
219
- transitionTimingFunction: 'linear',
221
+ transitionTimingFunction: 'var(--_sheet-scrim-easing, linear)',
220
222
  },
221
223
  },
222
224
  positioner: {
@@ -287,23 +289,24 @@ function scrimOpacityForView(view: BottomSheetStackView): '0' | '1' {
287
289
 
288
290
  /**
289
291
  * Writes the fade a touch drag's close paces on `dialog`'s scrim, or clears
290
- * it when `ms` is null. `written` keeps the value the host wrote, so a clear
291
- * removes only that value.
292
+ * it when `fade` is null. `written` keeps the duration the host wrote, so a
293
+ * clear removes only that fade.
292
294
  */
293
- function writeScrimFadeDuration(
295
+ function writeScrimFade(
294
296
  dialog: HTMLDialogElement | null,
295
- ms: number | null,
297
+ fade: ScrimFade | null,
296
298
  written: {current: string | null},
297
299
  ): void {
298
300
  if (dialog == null) {
299
301
  return;
300
302
  }
301
303
  const current = dialog.style.getPropertyValue('--_sheet-scrim-duration');
302
- if (ms == null) {
303
- // Remove only the value this host wrote. A stack's 0s pin written since
304
+ if (fade == null) {
305
+ // Remove only the fade this host wrote. A stack's 0s pin written since
304
306
  // then stays.
305
307
  if (written.current != null && current === written.current) {
306
308
  dialog.style.removeProperty('--_sheet-scrim-duration');
309
+ dialog.style.removeProperty('--_sheet-scrim-easing');
307
310
  }
308
311
  written.current = null;
309
312
  return;
@@ -312,8 +315,9 @@ function writeScrimFadeDuration(
312
315
  if (current === '0s') {
313
316
  return;
314
317
  }
315
- written.current = `${ms}ms`;
318
+ written.current = `${fade.durationMs}ms`;
316
319
  dialog.style.setProperty('--_sheet-scrim-duration', written.current);
320
+ dialog.style.setProperty('--_sheet-scrim-easing', fade.easing);
317
321
  }
318
322
 
319
323
  interface BottomSheetSharedProps extends BaseProps<HTMLDivElement> {
@@ -563,13 +567,13 @@ function StandaloneBottomSheet({
563
567
  }, []);
564
568
  // The fade duration a touch drag's close wrote, until that close ends.
565
569
  const scrimFadeRef = useRef<string | null>(null);
566
- const handleScrimFadeDuration = useCallback(
567
- (panel: HTMLElement, ms: number | null) => {
570
+ const handleScrimFade = useCallback(
571
+ (panel: HTMLElement, fade: ScrimFade | null) => {
568
572
  const view = stackViewRef.current;
569
573
  if (view.isStacked && !view.ownsScrim) {
570
574
  return;
571
575
  }
572
- writeScrimFadeDuration(panel.closest('dialog'), ms, scrimFadeRef);
576
+ writeScrimFade(panel.closest('dialog'), fade, scrimFadeRef);
573
577
  },
574
578
  [],
575
579
  );
@@ -940,7 +944,7 @@ function StandaloneBottomSheet({
940
944
  xstyle={xstyle}
941
945
  onDismiss={dismissOnLightInteraction}
942
946
  onScrimOpacity={handleScrimOpacity}
943
- onScrimFadeDuration={handleScrimFadeDuration}
947
+ onScrimFade={handleScrimFade}
944
948
  onElementChange={handlePanelElementChange}
945
949
  handleRef={outletRef}
946
950
  onMotionStart={handleMotionStart}
@@ -1095,9 +1099,9 @@ function SwitcherBottomSheetItem({
1095
1099
  // close ends. The step a drag closes becomes the flow's retained step, so
1096
1100
  // its backdrop is the flow's scrim.
1097
1101
  const scrimFadeRef = useRef<string | null>(null);
1098
- const handleScrimFadeDuration = useCallback(
1099
- (panel: HTMLElement, ms: number | null) => {
1100
- writeScrimFadeDuration(panel.closest('dialog'), ms, scrimFadeRef);
1102
+ const handleScrimFade = useCallback(
1103
+ (panel: HTMLElement, fade: ScrimFade | null) => {
1104
+ writeScrimFade(panel.closest('dialog'), fade, scrimFadeRef);
1101
1105
  },
1102
1106
  [],
1103
1107
  );
@@ -1303,7 +1307,7 @@ function SwitcherBottomSheetItem({
1303
1307
  xstyle={xstyle}
1304
1308
  onDismiss={dismissOnSwipe}
1305
1309
  onScrimOpacity={handleScrimOpacity}
1306
- onScrimFadeDuration={handleScrimFadeDuration}
1310
+ onScrimFade={handleScrimFade}
1307
1311
  onElementChange={handlePanelElementChange}
1308
1312
  onMotionStart={handleMotionStart}
1309
1313
  onMotionComplete={handleMotionComplete}>
@@ -71,7 +71,7 @@ import {
71
71
  type BottomSheetSnapPoint,
72
72
  } from './snapOffsets';
73
73
  import {animatorFor, SETTLE_THRESHOLD} from '../motion/animator';
74
- import {resolveSettleMs} from '../motion/resolveMotion';
74
+ import {resolveMoveTiming} from '../motion/resolveMotion';
75
75
  import {springs} from '../motion/uikit/springs';
76
76
  import {useMobileKeyboard} from '../keyboard/useMobileKeyboard';
77
77
  import {
@@ -130,6 +130,15 @@ function hasStyles(xstyle: unknown): boolean {
130
130
  : xstyle != null && typeof xstyle === 'object';
131
131
  }
132
132
 
133
+ /**
134
+ * The scrim's fade under a touch drag's close: the close's duration in ms,
135
+ * and its progress as CSS easing, so the fade follows the sheet.
136
+ */
137
+ export interface ScrimFade {
138
+ readonly durationMs: number;
139
+ readonly easing: string;
140
+ }
141
+
133
142
  function supportsWebAnimations(): boolean {
134
143
  return (
135
144
  typeof Element !== 'undefined' &&
@@ -138,16 +147,29 @@ function supportsWebAnimations(): boolean {
138
147
  }
139
148
 
140
149
  /**
141
- * How long a drag's close plays, in ms. It is the close spring's move from
142
- * where the finger left the sheet, timed as the shared animator times it.
150
+ * How a drag's close plays: the close spring's move from where the finger
151
+ * left the sheet, timed as the shared animator times it, and its progress
152
+ * toward the point where the sheet leaves view. The sheet's surface reaches
153
+ * below the screen (the reserve), so it leaves view before the close ends,
154
+ * and the scrim is clear when it does.
143
155
  */
144
- function dragExitMs(element: Element, exit: SheetDragExit): number {
145
- return resolveSettleMs(element, springs.sheetDismissSwipe, {
146
- from: 0,
147
- to: exit.distance,
148
- velocity: exit.velocity,
149
- epsilon: SETTLE_THRESHOLD.y,
150
- });
156
+ function dragExitFade(element: Element, exit: SheetDragExit): ScrimFade {
157
+ const viewportHeight = element.ownerDocument.defaultView?.innerHeight ?? 0;
158
+ const shown = Math.max(
159
+ 0,
160
+ viewportHeight - element.getBoundingClientRect().top,
161
+ );
162
+ return resolveMoveTiming(
163
+ element,
164
+ springs.sheetDismissSwipe,
165
+ {
166
+ from: 0,
167
+ to: exit.distance,
168
+ velocity: exit.velocity,
169
+ epsilon: SETTLE_THRESHOLD.y,
170
+ },
171
+ Math.min(exit.distance, shown),
172
+ );
151
173
  }
152
174
 
153
175
  /** The running fade that clears the scrim behind `panel`, if any. */
@@ -372,6 +394,7 @@ const styles = stylex.create({
372
394
  // inheritance, so the restyle stops here.
373
395
  '--_sheet-scrim-opacity': 'initial',
374
396
  '--_sheet-scrim-duration': 'initial',
397
+ '--_sheet-scrim-easing': 'initial',
375
398
  },
376
399
  // A sheet present on page load opens where it rests (spec:AST-013 FR13):
377
400
  // the collapse reduced motion uses, so the transition still ends.
@@ -586,12 +609,12 @@ interface BottomSheetPanelProps extends BaseProps<HTMLDivElement> {
586
609
  onDismiss: () => void;
587
610
  onScrimOpacity: (opacity: number) => void;
588
611
  /**
589
- * The scrim's fade under a touch drag's close, in milliseconds, or null
590
- * once that close ends or a reopen takes the sheet back. `panel` is the
591
- * sheet's element: the commit that starts the close can detach the host's
592
- * dialog ref while this runs.
612
+ * The scrim's fade under a touch drag's close, or null once that close
613
+ * ends or a reopen takes the sheet back. `panel` is the sheet's element:
614
+ * the commit that starts the close can detach the host's dialog ref while
615
+ * this runs.
593
616
  */
594
- onScrimFadeDuration?: (panel: HTMLElement, ms: number | null) => void;
617
+ onScrimFade?: (panel: HTMLElement, fade: ScrimFade | null) => void;
595
618
  onElementChange?: (element: HTMLDivElement | null) => void;
596
619
  /**
597
620
  * A ref for the grab handle's element. The handle stays mounted with the
@@ -774,7 +797,7 @@ export function BottomSheetPanel({
774
797
  isPageScrollLocked = false,
775
798
  onDismiss,
776
799
  onScrimOpacity,
777
- onScrimFadeDuration,
800
+ onScrimFade,
778
801
  onElementChange,
779
802
  handleRef,
780
803
  onMotionStart,
@@ -787,7 +810,7 @@ export function BottomSheetPanel({
787
810
  >(null);
788
811
  const onMotionStartRef = useCommittedRef(onMotionStart);
789
812
  const onMotionCompleteRef = useCommittedRef(onMotionComplete);
790
- const onScrimFadeDurationRef = useCommittedRef(onScrimFadeDuration);
813
+ const onScrimFadeRef = useCommittedRef(onScrimFade);
791
814
  const startedMotionRef = useRef<BottomSheetPanelMotion | null>(null);
792
815
  const pendingMotionCompleteRef = useRef<BottomSheetPanelMotion | null>(null);
793
816
 
@@ -991,14 +1014,14 @@ export function BottomSheetPanel({
991
1014
  return;
992
1015
  }
993
1016
  // The host's current callback hears the fade end, as it heard its start.
994
- const reportFade = (durationMs: number | null) => {
995
- onScrimFadeDurationRef.current?.(element, durationMs);
1017
+ const reportFade = (fade: ScrimFade | null) => {
1018
+ onScrimFadeRef.current?.(element, fade);
996
1019
  };
997
- reportFade(dragExitMs(element, playedDragExit));
1020
+ reportFade(dragExitFade(element, playedDragExit));
998
1021
  return () => {
999
1022
  reportFade(null);
1000
1023
  };
1001
- }, [onScrimFadeDurationRef, playedDragExit]);
1024
+ }, [onScrimFadeRef, playedDragExit]);
1002
1025
  // Syncs the motion with the panel's CSS transition, or a drag's exit with
1003
1026
  // the shared animator. The motion completes when that one ends.
1004
1027
  useLayoutEffect(() => {
@@ -1057,7 +1080,7 @@ export function BottomSheetPanel({
1057
1080
  });
1058
1081
  void exit.finished.then(() => {
1059
1082
  isFinished = true;
1060
- onScrimFadeDurationRef.current?.(element, null);
1083
+ onScrimFadeRef.current?.(element, null);
1061
1084
  if (isCurrent) {
1062
1085
  complete();
1063
1086
  }
@@ -1090,7 +1113,7 @@ export function BottomSheetPanel({
1090
1113
  playedDragExit,
1091
1114
  isReactivatedEntrance,
1092
1115
  onMotionCompleteRef,
1093
- onScrimFadeDurationRef,
1116
+ onScrimFadeRef,
1094
1117
  ]);
1095
1118
  // The snap is transform-only; the layout height reconciles when it lands.
1096
1119
  // waitForTransition — the same helper the motion states use — resolves that
@@ -67,6 +67,16 @@ export const docs = {
67
67
  type: 'StyleXStyles',
68
68
  description: 'StyleX styles for layout customization. Must be a stylex.create() value.',
69
69
  },
70
+ {
71
+ name: 'className',
72
+ type: 'string',
73
+ description: 'CSS class name for the root element. Prefer xstyle for styling; className is provided for integration with non-StyleX systems.',
74
+ },
75
+ {
76
+ name: 'style',
77
+ type: 'CSSProperties',
78
+ description: 'Inline styles for the root element. Prefer xstyle for styling; inline styles bypass StyleX optimization.',
79
+ },
70
80
  ],
71
81
  components: [
72
82
  {name: 'MetadataListItem'},
@@ -77,6 +87,8 @@ export const docs = {
77
87
  bestPractices: [
78
88
  { guidance: true, description: 'Choose label position based on content: "start" for short values, "top" for long or complex values.' },
79
89
  { guidance: true, description: 'Collapse long lists with `maxNumOfItems` to keep the page scannable.' },
90
+ { guidance: true, description: 'Give each MetadataListItem a short label that names its value. Assistive technology reads each label with its value as a term and its definition.' },
91
+ { guidance: true, description: 'The title does not name the list or add a heading. Pass a heading element as the title when the list needs a place in the page outline.' },
80
92
  { guidance: false, description: 'Use for extensive form input; use a form layout instead.' },
81
93
  { guidance: false, description: "Use for data that doesn't have a clear key-value structure." },
82
94
  ],
@@ -97,6 +109,8 @@ export const docsZh = {
97
109
  bestPractices: [
98
110
  { guidance: true, description: 'Choose label position based on content: "start" for short values, "top" for long or complex values.' },
99
111
  { guidance: true, description: 'Collapse long lists with `maxNumOfItems` to keep the page scannable.' },
112
+ { guidance: true, description: 'Give each MetadataListItem a short label that names its value. Assistive technology reads each label with its value as a term and its definition.' },
113
+ { guidance: true, description: 'The title does not name the list or add a heading. Pass a heading element as the title when the list needs a place in the page outline.' },
100
114
  { guidance: false, description: 'Use for extensive form input; use a form layout instead.' },
101
115
  { guidance: false, description: "Use for data that doesn't have a clear key-value structure." },
102
116
  ],
@@ -118,6 +132,8 @@ export const docsDense = {
118
132
  bestPractices: [
119
133
  { guidance: true, description: 'Choose label position based on content: "start" for short values, "top" for long or complex values.' },
120
134
  { guidance: true, description: 'Collapse long lists with `maxNumOfItems` to keep the page scannable.' },
135
+ { guidance: true, description: 'Give each MetadataListItem a short label that names its value. Assistive technology reads each label with its value as a term and its definition.' },
136
+ { guidance: true, description: 'The title does not name the list or add a heading. Pass a heading element as the title when the list needs a place in the page outline.' },
121
137
  { guidance: false, description: 'Use for extensive form input; use a form layout instead.' },
122
138
  { guidance: false, description: "Use for data that doesn't have a clear key-value structure." },
123
139
  ],
@@ -66,7 +66,8 @@ export interface MetadataListProps extends Omit<
66
66
  columns?: MetadataListColumns;
67
67
  /**
68
68
  * Label display configuration.
69
- * - position: 'start' places labels to the left, 'top' stacks labels above content
69
+ * - position: 'start' places each label at the inline start of its value,
70
+ * 'top' stacks labels above content
70
71
  * - width: Custom label width (number in px or CSS string)
71
72
  *
72
73
  * Defaults to `{ position: 'top' }` for multi-column layouts and
@@ -260,7 +261,7 @@ export function MetadataList({
260
261
  ? styles.gridStackedSingle
261
262
  : styles.gridStackedMulti;
262
263
  }
263
- // Labels on the left
264
+ // Labels at the inline start
264
265
  if (columns === 'single' || columns === 1) {
265
266
  return styles.gridSingle;
266
267
  }
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ /**
3
+ * @file shared-context.ts
4
+ * @input Core's shared React context helper
5
+ * @output `@astryxdesign/core/internal/shared-context`: createSharedContext,
6
+ * re-exported by name for Lab components
7
+ * @position An internal entry reserved for Astryx's own packages:
8
+ * undocumented, outside the public API and its compatibility promise,
9
+ * versioned in lockstep with Core, and allowed only in Core and Lab by the
10
+ * `@astryx/no-core-internal-import` lint rule. Core components import the
11
+ * same module by relative path. Named re-exports only.
12
+ *
13
+ * SYNC: When modified, update scripts/sync-exports.js.
14
+ */
15
+ export {createSharedContext} from '../utils/sharedContext';
@@ -35,6 +35,7 @@ roles through `resolveMotion`.
35
35
  | `roles.ts` | The internal motion roles: the springs, durations and curves `spec:AST-094` FR4 names, registered by the shared tables, and a role's CSS form read back. |
36
36
  | `roleValue.ts` | A role's CSS form, written: a spring's duration and bounce, a duration in ms, a curve's `cubic-bezier()`. |
37
37
  | `resolveMotion.ts` | A role's value: its table value, as the per-role tables stay internal (`spec:AST-094` DEC-15). |
38
+ | `linearEasing.ts` | A curve sampled once per frame as CSS `linear()` easing text. |
38
39
  | `MEASUREMENTS.md` | The UIKit reference captures each unconfirmed value still needs. |
39
40
  | `spring.ts` | Closed-form damped spring, every Apple parameterization, settling duration, a spring chasing a moving target. |
40
41
  | `decay.ts` | UIScrollView's momentum coast. |
@@ -82,6 +82,7 @@
82
82
  */
83
83
 
84
84
  import {LATE_START_MS} from './frameBlock';
85
+ import {linearEasing, sampleCount} from './linearEasing';
85
86
  import {
86
87
  sharedKey,
87
88
  sharedMap,
@@ -117,8 +118,6 @@ import {
117
118
  const MIN_SHIFT_PX = 0.5;
118
119
  /** The touch cross-fade's cap (`design:reduced-motion` DR2). */
119
120
  const CROSS_FADE_CAP_MS = 200;
120
- /** Keyframes per second the motion is sampled at. */
121
- const SAMPLES_PER_SECOND = 60;
122
121
 
123
122
  // ---------------------------------------------------------------------------
124
123
  // Motion
@@ -206,21 +205,11 @@ export function springGlide(
206
205
  settlingDuration(physics, {initialVelocity: velocity}) * 1000;
207
206
  const remaining = (t: number) =>
208
207
  t >= durationMs ? 0 : 1 - curve.value(t / 1000);
209
- return {durationMs, easing: linearEasing(durationMs, remaining), remaining};
210
- }
211
-
212
- /** A move's remaining fraction over time as CSS `linear()` easing text. */
213
- function linearEasing(
214
- durationMs: number,
215
- remaining: (t: number) => number,
216
- ): string {
217
- const count = sampleCount(durationMs);
218
- const stops: string[] = [];
219
- for (let i = 0; i < count; i++) {
220
- const done = 1 - remaining((i / (count - 1)) * durationMs);
221
- stops.push(String(Math.round(done * 10000) / 10000));
222
- }
223
- return `linear(${stops.join(', ')})`;
208
+ return {
209
+ durationMs,
210
+ easing: linearEasing(durationMs, t => 1 - remaining(t)),
211
+ remaining,
212
+ };
224
213
  }
225
214
 
226
215
  function releaseGlideFor(area: Element): GlideProgress | undefined {
@@ -256,10 +245,6 @@ function layoutMotion(area: Element): LayoutMotion {
256
245
  return progress == null ? {kind: 'instant'} : {kind: 'glide', progress};
257
246
  }
258
247
 
259
- function sampleCount(durationMs: number): number {
260
- return Math.max(2, Math.ceil((durationMs / 1000) * SAMPLES_PER_SECOND) + 1);
261
- }
262
-
263
248
  /** Linear keyframes over `durationMs`, one per frame, from `frame(t ms)`. */
264
249
  function sampleOver(
265
250
  durationMs: number,
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file linearEasing.ts
5
+ * @input A duration and the fraction of a move done at each time
6
+ * @output Exports `linearEasing`, that curve as CSS `linear()` easing text,
7
+ * and `sampleCount`, how many samples cover a duration at 60 per second
8
+ * @position Pure math under the motion helpers; no DOM, no React
9
+ */
10
+
11
+ /** Samples per second of a sampled curve: one per frame at 60 Hz. */
12
+ const SAMPLES_PER_SECOND = 60;
13
+
14
+ /** How many samples cover `durationMs`, both ends included: at least 2. */
15
+ export function sampleCount(durationMs: number): number {
16
+ return Math.max(2, Math.ceil((durationMs / 1000) * SAMPLES_PER_SECOND) + 1);
17
+ }
18
+
19
+ /**
20
+ * The curve `done` traces over `durationMs` as CSS `linear()` easing text,
21
+ * one stop per frame. `done(t)` is the fraction of the move done `t` ms in.
22
+ * A CSS transition with this easing and duration follows the curve.
23
+ */
24
+ export function linearEasing(
25
+ durationMs: number,
26
+ done: (t: number) => number,
27
+ ): string {
28
+ const count = sampleCount(durationMs);
29
+ const stops: string[] = [];
30
+ for (let i = 0; i < count; i++) {
31
+ const value = done((i / (count - 1)) * durationMs);
32
+ stops.push(String(Math.round(value * 10000) / 10000));
33
+ }
34
+ return `linear(${stops.join(', ')})`;
35
+ }
@@ -7,7 +7,8 @@
7
7
  * plays on, for its theme's tempo (themeTempo.ts)
8
8
  * @output resolveMotion: the role's value at the theme's tempo.
9
9
  * resolveSettleMs: how long a spring role, or one move on it, takes to
10
- * settle there, for a CSS part that plays with it
10
+ * settle there, for a CSS part that plays with it. resolveMoveTiming: that
11
+ * move's duration and its progress as CSS easing
11
12
  * @position Motion foundation; the animator resolves every spring and curve
12
13
  * it is handed with it, and components resolve the durations they time
13
14
  * with it
@@ -37,6 +38,7 @@ import {
37
38
  toSpring,
38
39
  type SpringDescription,
39
40
  } from './spring';
41
+ import {linearEasing} from './linearEasing';
40
42
  import {themeTempo} from './themeTempo';
41
43
 
42
44
  /**
@@ -179,3 +181,42 @@ export function resolveSettleMs(
179
181
  ? settlingDuration(resolved) * 1000
180
182
  : solveSpring(resolved, move).settleTime(move.epsilon) * 1000;
181
183
  }
184
+
185
+ /**
186
+ * How `move` on `spring` plays at the tempo of the theme `element` is in: how
187
+ * long it takes, as `resolveSettleMs` gives it, and its progress over that
188
+ * time as CSS `linear()` easing. A CSS part that takes both follows the
189
+ * spring frame by frame, so the two start and land together. A sheet's scrim
190
+ * fades this way under the sheet's close.
191
+ *
192
+ * With `doneAt`, a position between `from` and `to`, the progress is measured
193
+ * toward `doneAt` instead. It reaches 1 the first time the move gets there
194
+ * and stays at 1. A sheet leaves view before its close ends, because its
195
+ * surface reaches below the screen, and its scrim is clear by then.
196
+ */
197
+ export function resolveMoveTiming(
198
+ element: Element | null | undefined,
199
+ spring: SpringDescription,
200
+ move: SpringMove,
201
+ doneAt: number = move.to,
202
+ ): {durationMs: number; easing: string} {
203
+ const curve = solveSpring(toSpring(resolveMotion(element, spring)), move);
204
+ const durationMs = curve.settleTime(move.epsilon) * 1000;
205
+ const span = doneAt - move.from;
206
+ if (span === 0 || durationMs === 0) {
207
+ return {durationMs, easing: linearEasing(durationMs, () => 1)};
208
+ }
209
+ const progressAt = (t: number) => (curve.value(t / 1000) - move.from) / span;
210
+ // The first millisecond at which the move reaches `doneAt`, if it does.
211
+ let reachedAt = Infinity;
212
+ for (let t = 0; t <= durationMs; t++) {
213
+ if (progressAt(t) >= 1) {
214
+ reachedAt = t;
215
+ break;
216
+ }
217
+ }
218
+ return {
219
+ durationMs,
220
+ easing: linearEasing(durationMs, t => (t >= reachedAt ? 1 : progressAt(t))),
221
+ };
222
+ }