Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(core): the motion and gesture internals that Lab's refresh pull reads (#9807)

Christopher Chedeau2ea8f682159d
diff --git a/.changeset/core-internal-touch-refresh-pull.md b/.changeset/core-internal-touch-refresh-pull.md
new file mode 100644
index 0000000000..d254751990
--- /dev/null
+++ b/.changeset/core-internal-touch-refresh-pull.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Internal: Core's internal touch entry re-exports what Lab's useRefreshControl reads. That is the pan recognizer, its hook and the gesture types, and the motion animator. It is also the motion math, the map of a companion curve, the UIKit scroll table of its pull, and the motion-role parsers. None is in the public entry. Apps import nothing new.
+
+@vjeux
diff --git a/packages/core/src/internal/touch.test.ts b/packages/core/src/internal/touch.test.ts
index 2f175885db..0300e71f38 100644
--- a/packages/core/src/internal/touch.test.ts
+++ b/packages/core/src/internal/touch.test.ts
@@ -33,6 +33,31 @@ describe('internal/touch', () => {
expect(entry).not.toHaveProperty('touchModule');
});
+ it("re-exports by name what Lab's useRefreshControl reads", async () => {
+ const entry: Record<string, unknown> = await import('./touch');
+ const pan = await import('../gestures/PanGestureRecognizer');
+ const hook = await import('../gestures/useGestureRecognizer');
+ const animator = await import('../motion/animator');
+ const bezier = await import('../motion/bezier');
+ const progress = await import('../motion/progress');
+ const roles = await import('../motion/roles');
+ const band = await import('../motion/rubberBand');
+ const scroll = await import('../motion/uikit/scroll');
+ expect(entry.PanGestureRecognizer).toBe(pan.PanGestureRecognizer);
+ expect(entry.useGestureRecognizer).toBe(hook.useGestureRecognizer);
+ expect(entry.createMotionAnimator).toBe(animator.createMotionAnimator);
+ expect(entry.cubicBezier).toBe(bezier.cubicBezier);
+ expect(entry.mapProgress).toBe(progress.mapProgress);
+ expect(entry.parseCssEasing).toBe(roles.parseCssEasing);
+ expect(entry.parseMotionRoleValue).toBe(roles.parseMotionRoleValue);
+ expect(entry.rubberBand).toBe(band.rubberBand);
+ expect(entry.rubberBandInverse).toBe(band.rubberBandInverse);
+ expect(entry.rubberBandSlope).toBe(band.rubberBandSlope);
+ expect(entry.scroll).toBe(scroll.scroll);
+ // No internal factory shares a public factory's name.
+ expect(entry).not.toHaveProperty('createAnimator');
+ });
+
it('attaches no window or document listeners when it loads', async () => {
vi.resetModules();
const onWindow = vi.spyOn(window, 'addEventListener');
diff --git a/packages/core/src/internal/touch.ts b/packages/core/src/internal/touch.ts
index b1ff8a168b..560cc95f3e 100644
--- a/packages/core/src/internal/touch.ts
+++ b/packages/core/src/internal/touch.ts
@@ -2,7 +2,9 @@
/**
* @file touch.ts
- * @input The gesture core: the arena, the recognizers, and their geometry
+ * @input The gesture core: the arena, the recognizers, and their geometry;
+ * the pan, the motion animator and the motion math that Lab's
+ * useRefreshControl reads
* @output `@astryxdesign/core/internal/touch`: the gesture core's primitives
* for Lab components, re-exported by name
* @position An internal entry reserved for Astryx's own packages:
@@ -39,3 +41,34 @@ export {
export {LongPressGestureRecognizer} from '../gestures/LongPressGestureRecognizer';
export {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
export {DEFAULT_ENVIRONMENT} from '../gestures/types';
+
+// Lab's useRefreshControl reads these: its pull's pan and the hook that
+// starts it. It also reads the motion animator and math, and the scroll
+// view's bounce spring, for its pull, settle and end. Its indicator fades
+// along the settle's curve, and the motion-role parsers read the theme's
+// tokens for its end.
+export {PanGestureRecognizer} from '../gestures/PanGestureRecognizer';
+export type {PanGestureRecognizerOptions} from '../gestures/PanGestureRecognizer';
+export type {
+ GestureEventContext,
+ GestureTouch,
+ PointerKind,
+} from '../gestures/types';
+export {useGestureRecognizer} from '../gestures/useGestureRecognizer';
+// The animator's internal factory. The public one, `createAnimator`, plays
+// only the theme's state-change motion.
+export {createMotionAnimator} from '../motion/animator';
+export type {
+ Animator as MotionAnimator,
+ AnimatorOptions as MotionAnimatorOptions,
+ MotionCurve,
+} from '../motion/animator';
+export {cubicBezier} from '../motion/bezier';
+export {mapProgress} from '../motion/progress';
+export {parseCssEasing, parseMotionRoleValue} from '../motion/roles';
+export {
+ rubberBand,
+ rubberBandInverse,
+ rubberBandSlope,
+} from '../motion/rubberBand';
+export {scroll} from '../motion/uikit/scroll';
diff --git a/scripts/touch-support-bundle.test.mjs b/scripts/touch-support-bundle.test.mjs
index 2b7504521c..76ebf5bc5b 100644
--- a/scripts/touch-support-bundle.test.mjs
+++ b/scripts/touch-support-bundle.test.mjs
@@ -13,7 +13,8 @@
* carries only the gesture code its touch components import; two components
* that import the touch module share one copy per page; only the internal
* `internal/touch` entry reaches it, and no consumer doc or component
- * `import()` does
+ * `import()` does; the names that entry gives Lab are not in the root
+ * entry
* @position Node test over source, so it needs no build. Its build files
* live under the repository's `node_modules/.cache`, never the system temp
* directory, whose listing esbuild would read for every build
@@ -100,6 +101,33 @@ function outputsOf(entries) {
);
}
+/** The names a build of `entry` exports, read from esbuild's metafile. */
+function exportsOf(entry) {
+ const result = esbuild.buildSync({...BUILD_OPTIONS, entryPoints: [entry]});
+ return Object.values(result.metafile.outputs).flatMap(
+ output => output.exports ?? [],
+ );
+}
+
+/**
+ * What the internal entry gives Lab's refresh pull: the pan, its hook, the
+ * motion animator, its motion math and companion curves, the scroll view's
+ * spring and the motion-role parsers. None is public API.
+ */
+const LAB_ONLY_NAMES = [
+ 'PanGestureRecognizer',
+ 'useGestureRecognizer',
+ 'createMotionAnimator',
+ 'cubicBezier',
+ 'mapProgress',
+ 'parseCssEasing',
+ 'parseMotionRoleValue',
+ 'rubberBand',
+ 'rubberBandInverse',
+ 'rubberBandSlope',
+ 'scroll',
+];
+
/** The inputs matching `pattern` that put bytes in `bytes`. */
function bytesOf(bytes, pattern = PRIMITIVE_INPUT) {
return Object.entries(bytes).filter(
@@ -403,6 +431,17 @@ describe('the touch module internals', () => {
);
});
+ it('give Lab names that the public entry does not export', () => {
+ const internal = new Set(
+ exportsOf(path.join(CORE_SRC, 'internal/touch.ts')),
+ );
+ const root = new Set(exportsOf(path.join(CORE_SRC, 'index.ts')));
+ // The root build reads its exports: a public component is among them.
+ expect(root.has('Button')).toBe(true);
+ expect(LAB_ONLY_NAMES.filter(name => !internal.has(name))).toEqual([]);
+ expect(LAB_ONLY_NAMES.filter(name => root.has(name))).toEqual([]);
+ }, 120_000);
+
it('have no entry in the exports map beside the internal touch entry', () => {
const {exports} = JSON.parse(
fs.readFileSync(path.join(REPO, 'packages/core/package.json'), 'utf8'),