Skip to content

Commit 2ea8f68

Browse files
authored
chore(core): the motion and gesture internals that Lab's refresh pull reads (#9807)
chore(core): the motion and gesture internals that Lab's refresh pull reads Core's internal touch entry re-exports, by name, what Lab's useRefreshControl imports: the pan recognizer, its hook and the gesture types; the motion animator; the cubic Bézier, the rubber band with its inverse and slope, and the map of a companion curve; the UIKit scroll table; and the motion-role parsers. Each one is an existing internal, and Core's behavior does not change. A bundle test checks that the public entry exports none of them.
1 parent 85b4627 commit 2ea8f68

4 files changed

Lines changed: 106 additions & 2 deletions

File tree

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+
[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.
6+
7+
@vjeux

‎packages/core/src/internal/touch.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ describe('internal/touch', () => {
3333
expect(entry).not.toHaveProperty('touchModule');
3434
});
3535

36+
it("re-exports by name what Lab's useRefreshControl reads", async () => {
37+
const entry: Record<string, unknown> = await import('./touch');
38+
const pan = await import('../gestures/PanGestureRecognizer');
39+
const hook = await import('../gestures/useGestureRecognizer');
40+
const animator = await import('../motion/animator');
41+
const bezier = await import('../motion/bezier');
42+
const progress = await import('../motion/progress');
43+
const roles = await import('../motion/roles');
44+
const band = await import('../motion/rubberBand');
45+
const scroll = await import('../motion/uikit/scroll');
46+
expect(entry.PanGestureRecognizer).toBe(pan.PanGestureRecognizer);
47+
expect(entry.useGestureRecognizer).toBe(hook.useGestureRecognizer);
48+
expect(entry.createMotionAnimator).toBe(animator.createMotionAnimator);
49+
expect(entry.cubicBezier).toBe(bezier.cubicBezier);
50+
expect(entry.mapProgress).toBe(progress.mapProgress);
51+
expect(entry.parseCssEasing).toBe(roles.parseCssEasing);
52+
expect(entry.parseMotionRoleValue).toBe(roles.parseMotionRoleValue);
53+
expect(entry.rubberBand).toBe(band.rubberBand);
54+
expect(entry.rubberBandInverse).toBe(band.rubberBandInverse);
55+
expect(entry.rubberBandSlope).toBe(band.rubberBandSlope);
56+
expect(entry.scroll).toBe(scroll.scroll);
57+
// No internal factory shares a public factory's name.
58+
expect(entry).not.toHaveProperty('createAnimator');
59+
});
60+
3661
it('attaches no window or document listeners when it loads', async () => {
3762
vi.resetModules();
3863
const onWindow = vi.spyOn(window, 'addEventListener');

‎packages/core/src/internal/touch.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/**
44
* @file touch.ts
5-
* @input The gesture core: the arena, the recognizers, and their geometry
5+
* @input The gesture core: the arena, the recognizers, and their geometry;
6+
* the pan, the motion animator and the motion math that Lab's
7+
* useRefreshControl reads
68
* @output `@astryxdesign/core/internal/touch`: the gesture core's primitives
79
* for Lab components, re-exported by name
810
* @position An internal entry reserved for Astryx's own packages:
@@ -39,3 +41,34 @@ export {
3941
export {LongPressGestureRecognizer} from '../gestures/LongPressGestureRecognizer';
4042
export {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
4143
export {DEFAULT_ENVIRONMENT} from '../gestures/types';
44+
45+
// Lab's useRefreshControl reads these: its pull's pan and the hook that
46+
// starts it. It also reads the motion animator and math, and the scroll
47+
// view's bounce spring, for its pull, settle and end. Its indicator fades
48+
// along the settle's curve, and the motion-role parsers read the theme's
49+
// tokens for its end.
50+
export {PanGestureRecognizer} from '../gestures/PanGestureRecognizer';
51+
export type {PanGestureRecognizerOptions} from '../gestures/PanGestureRecognizer';
52+
export type {
53+
GestureEventContext,
54+
GestureTouch,
55+
PointerKind,
56+
} from '../gestures/types';
57+
export {useGestureRecognizer} from '../gestures/useGestureRecognizer';
58+
// The animator's internal factory. The public one, `createAnimator`, plays
59+
// only the theme's state-change motion.
60+
export {createMotionAnimator} from '../motion/animator';
61+
export type {
62+
Animator as MotionAnimator,
63+
AnimatorOptions as MotionAnimatorOptions,
64+
MotionCurve,
65+
} from '../motion/animator';
66+
export {cubicBezier} from '../motion/bezier';
67+
export {mapProgress} from '../motion/progress';
68+
export {parseCssEasing, parseMotionRoleValue} from '../motion/roles';
69+
export {
70+
rubberBand,
71+
rubberBandInverse,
72+
rubberBandSlope,
73+
} from '../motion/rubberBand';
74+
export {scroll} from '../motion/uikit/scroll';

‎scripts/touch-support-bundle.test.mjs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* carries only the gesture code its touch components import; two components
1414
* that import the touch module share one copy per page; only the internal
1515
* `internal/touch` entry reaches it, and no consumer doc or component
16-
* `import()` does
16+
* `import()` does; the names that entry gives Lab are not in the root
17+
* entry
1718
* @position Node test over source, so it needs no build. Its build files
1819
* live under the repository's `node_modules/.cache`, never the system temp
1920
* directory, whose listing esbuild would read for every build
@@ -100,6 +101,33 @@ function outputsOf(entries) {
100101
);
101102
}
102103

104+
/** The names a build of `entry` exports, read from esbuild's metafile. */
105+
function exportsOf(entry) {
106+
const result = esbuild.buildSync({...BUILD_OPTIONS, entryPoints: [entry]});
107+
return Object.values(result.metafile.outputs).flatMap(
108+
output => output.exports ?? [],
109+
);
110+
}
111+
112+
/**
113+
* What the internal entry gives Lab's refresh pull: the pan, its hook, the
114+
* motion animator, its motion math and companion curves, the scroll view's
115+
* spring and the motion-role parsers. None is public API.
116+
*/
117+
const LAB_ONLY_NAMES = [
118+
'PanGestureRecognizer',
119+
'useGestureRecognizer',
120+
'createMotionAnimator',
121+
'cubicBezier',
122+
'mapProgress',
123+
'parseCssEasing',
124+
'parseMotionRoleValue',
125+
'rubberBand',
126+
'rubberBandInverse',
127+
'rubberBandSlope',
128+
'scroll',
129+
];
130+
103131
/** The inputs matching `pattern` that put bytes in `bytes`. */
104132
function bytesOf(bytes, pattern = PRIMITIVE_INPUT) {
105133
return Object.entries(bytes).filter(
@@ -403,6 +431,17 @@ describe('the touch module internals', () => {
403431
);
404432
});
405433

434+
it('give Lab names that the public entry does not export', () => {
435+
const internal = new Set(
436+
exportsOf(path.join(CORE_SRC, 'internal/touch.ts')),
437+
);
438+
const root = new Set(exportsOf(path.join(CORE_SRC, 'index.ts')));
439+
// The root build reads its exports: a public component is among them.
440+
expect(root.has('Button')).toBe(true);
441+
expect(LAB_ONLY_NAMES.filter(name => !internal.has(name))).toEqual([]);
442+
expect(LAB_ONLY_NAMES.filter(name => root.has(name))).toEqual([]);
443+
}, 120_000);
444+
406445
it('have no entry in the exports map beside the internal touch entry', () => {
407446
const {exports} = JSON.parse(
408447
fs.readFileSync(path.join(REPO, 'packages/core/package.json'), 'utf8'),

0 commit comments

Comments
 (0)