@jsb188/gfx 1.1.2 → 1.1.11

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.
Files changed (56) hide show
  1. package/README.md +54 -248
  2. package/libs/dotGrid.ts +77 -480
  3. package/libs/effects/effectQuad.ts +2 -8
  4. package/libs/pointer.ts +0 -6
  5. package/libs/runtime.ts +4 -6
  6. package/libs/types.ts +1 -8
  7. package/main.ts +0 -2
  8. package/modules/Carousel.helpers.ts +0 -234
  9. package/modules/Carousel.tsx +29 -135
  10. package/modules/DotsArea.tsx +120 -0
  11. package/modules/GfxCanvas.tsx +2 -10
  12. package/modules/ScrollSteps.tsx +52 -7
  13. package/modules/VisionBoard.helpers.ts +561 -0
  14. package/modules/VisionBoard.tsx +358 -0
  15. package/modules/VisionBoard.types.ts +88 -0
  16. package/package.json +5 -15
  17. package/scenes/Carousel.ts +18 -99
  18. package/scenes/DotsArea.ts +208 -0
  19. package/tsconfig.json +1 -1
  20. package/utils/color.ts +2 -64
  21. package/utils/dotGridSpecs.ts +46 -304
  22. package/elements/Shapes.helpers.ts +0 -204
  23. package/elements/Shapes.hooks.ts +0 -171
  24. package/elements/Shapes.tsx +0 -505
  25. package/elements/Shapes.types.ts +0 -81
  26. package/elements/Stack.helpers.ts +0 -42
  27. package/elements/Stack.tsx +0 -143
  28. package/elements/Text.helpers.ts +0 -45
  29. package/elements/Text.hooks.ts +0 -197
  30. package/elements/Text.tsx +0 -98
  31. package/libs/dotGrid.helpers.ts +0 -53
  32. package/libs/effects/dotEffects.ts +0 -136
  33. package/modules/Carousel.hooks.ts +0 -520
  34. package/modules/Dots.tsx +0 -269
  35. package/modules/DotsBoard.helpers.ts +0 -388
  36. package/modules/DotsBoard.hooks.ts +0 -144
  37. package/modules/DotsBoard.strings.ts +0 -649
  38. package/modules/DotsBoard.types.ts +0 -240
  39. package/modules/DotsBoardCanvas.hooks.ts +0 -49
  40. package/modules/DotsBoardCanvas.tsx +0 -190
  41. package/modules/DotsBoardElements.tsx +0 -330
  42. package/modules/Gallery.helpers.ts +0 -32
  43. package/modules/Gallery.hooks.ts +0 -149
  44. package/modules/Gallery.tsx +0 -194
  45. package/modules/KineticHeader.helpers.ts +0 -44
  46. package/modules/KineticHeader.hooks.ts +0 -206
  47. package/modules/KineticHeader.tsx +0 -305
  48. package/modules/KineticHeader.types.ts +0 -56
  49. package/modules/ScrollSteps.hooks.ts +0 -138
  50. package/scenes/DotsBoard.helpers.ts +0 -12
  51. package/scenes/DotsBoard.ts +0 -245
  52. package/utils/align.ts +0 -18
  53. package/utils/dotEffectSpecs.ts +0 -79
  54. package/utils/motion.ts +0 -88
  55. package/utils/random.ts +0 -22
  56. package/utils/strings.ts +0 -116
@@ -1,44 +0,0 @@
1
- import type { CSSProperties } from 'react';
2
- import type { KineticHeaderImage } from './KineticHeader.types.ts';
3
-
4
- /*
5
- * Anchor captions outside the image with 8px top/bottom gaps and 10px left/right gaps.
6
- */
7
- export function getKineticImageAltStyle({ altPosition = 'top', altWidth }: KineticHeaderImage): CSSProperties {
8
- const width = altWidth ?? '100%';
9
- switch (altPosition) {
10
- case 'left':
11
- return { width, top: 0, right: 'calc(100% + 10px)' };
12
- case 'right':
13
- return { width, top: 0, left: 'calc(100% + 10px)' };
14
- case 'bottom':
15
- return { width, left: 0, top: 'calc(100% + 8px)' };
16
- default:
17
- return { width, left: 0, bottom: 'calc(100% + 8px)' };
18
- }
19
- }
20
-
21
- /*
22
- * Animate entrance and exit around the full display duration. The first slide skips entrance.
23
- */
24
- export function createKineticImageAnimation(
25
- element: HTMLElement | null,
26
- { duration, enterDuration, exitDuration }: { duration: number; enterDuration: number; exitDuration: number },
27
- ) {
28
- if (!element?.animate || (enterDuration <= 0 && exitDuration <= 0)) return;
29
- const totalDuration = enterDuration + duration + exitDuration;
30
- return element.animate(
31
- [
32
- {
33
- opacity: enterDuration > 0 ? 0 : 1,
34
- transform: enterDuration > 0 ? 'translateY(32px)' : 'translateY(0)',
35
- offset: 0,
36
- easing: 'ease-in-out',
37
- },
38
- { opacity: 1, transform: 'translateY(0)', offset: enterDuration / totalDuration },
39
- { opacity: 1, transform: 'translateY(0)', offset: (enterDuration + duration) / totalDuration, easing: 'ease-in-out' },
40
- { opacity: 0, transform: 'translateY(32px)', offset: 1 },
41
- ],
42
- { duration: totalDuration, fill: 'both' },
43
- );
44
- }
@@ -1,206 +0,0 @@
1
- import { useLayoutEffect, useRef, useState } from 'react';
2
- import { createKineticImageAnimation } from './KineticHeader.helpers.ts';
3
- import type { KineticHeaderProps } from './KineticHeader.types.ts';
4
-
5
- /*
6
- * Schedule entrance, display, and exit boundaries while native animations draw images and progress.
7
- * Hover pauses display time or uses its configured duration; keyboard focus pauses display time.
8
- * Offscreen slides, hidden tabs, and reduced motion pause all phases.
9
- * The enclosing component remounts this sequence when the slide contents or fixed selection change.
10
- * Fixed slides stay fully visible without starting timers or animations.
11
- */
12
- export function useKineticHeader({
13
- slides,
14
- fixedSlide,
15
- slideDuration = 5000,
16
- mouseOverSlideDuration,
17
- slideTransitionMs = 350,
18
- }: KineticHeaderProps) {
19
- const [index, setIndex] = useState(fixedSlide ?? 0);
20
- const [isPaused, setIsPaused] = useState(fixedSlide !== undefined);
21
- const [reducedMotion, setReducedMotion] = useState(false);
22
- const [showControls, setShowControls] = useState(false);
23
- const imageAreaRef = useRef<HTMLDivElement>(null);
24
- const hoverAreaRef = useRef<HTMLDivElement>(null);
25
- const progressRef = useRef<HTMLDivElement>(null);
26
- const previousIndex = useRef(index);
27
- const hovered = useRef<boolean | null>(null);
28
- const navigateRef = useRef<((direction: -1 | 1) => void) | null>(null);
29
-
30
- /*
31
- * Request navigation through the active timeline, which ignores input during transitions or fixed slides.
32
- */
33
- const navigate = (direction: -1 | 1) => {
34
- navigateRef.current?.(direction);
35
- };
36
-
37
- useLayoutEffect(() => {
38
- const changed = previousIndex.current !== index;
39
- previousIndex.current = index;
40
- if (fixedSlide !== undefined || slides.length < 2) return;
41
-
42
- const duration = Number.isFinite(slideDuration) ? Math.max(1, slideDuration) : 5000;
43
- const hoverDuration =
44
- typeof mouseOverSlideDuration === 'number' && Number.isInteger(mouseOverSlideDuration) && mouseOverSlideDuration > 0
45
- ? mouseOverSlideDuration
46
- : undefined;
47
- const transition = Number.isFinite(slideTransitionMs) ? Math.max(0, slideTransitionMs) : 350;
48
- const enterDuration = changed ? transition : 0;
49
- const exitDuration = transition > 0 ? 350 : 0;
50
- const exitStart = enterDuration + duration;
51
- const totalDuration = exitStart + exitDuration;
52
- const hoverArea = hoverAreaRef.current;
53
- const progress = progressRef.current;
54
- const motion = window.matchMedia?.('(prefers-reduced-motion: reduce)');
55
- const imageAnimation = createKineticImageAnimation(imageAreaRef.current, { duration, enterDuration, exitDuration });
56
- const progressAnimation = progress?.animate?.([{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], {
57
- duration,
58
- fill: 'both',
59
- });
60
- let elapsed = 0;
61
- let startedAt: number | null = null;
62
- let playbackRate = 1;
63
- let timer: number | undefined;
64
- let nextIndex = (index + 1) % slides.length;
65
- // Keep pointer presence across slide effects, including entry during the outgoing fade.
66
- hovered.current ??= hoverArea?.matches(':hover') ?? false;
67
- let focused = !!hoverArea?.contains(document.activeElement);
68
- let visible = true;
69
-
70
- /*
71
- * Preserve elapsed progress at the previous speed before applying hover speed or pause changes.
72
- */
73
- const syncPlayback = () => {
74
- const now = performance.now();
75
- if (startedAt !== null) {
76
- // Stop at each boundary so a delayed timer cannot consume display time before checking hover.
77
- const phaseEnd = elapsed < enterDuration ? enterDuration : elapsed < exitStart ? exitStart : totalDuration;
78
- elapsed = Math.min(phaseEnd, elapsed + (now - startedAt) * playbackRate);
79
- }
80
- startedAt = null;
81
- window.clearTimeout(timer);
82
- timer = undefined;
83
-
84
- const reduced = motion?.matches ?? false;
85
- const displaying = elapsed >= enterDuration && elapsed < exitStart;
86
- const displayElapsed = Math.max(0, Math.min(duration, elapsed - enterDuration));
87
- const interacting = !!hovered.current || focused;
88
- const paused =
89
- ((focused || (hovered.current && hoverDuration === undefined)) && displaying) || !visible || document.hidden || reduced;
90
- playbackRate = displaying && hovered.current && hoverDuration !== undefined ? duration / hoverDuration : 1;
91
- setIsPaused(paused);
92
- setReducedMotion(reduced);
93
- setShowControls(interacting && (displaying || reduced) && visible && !document.hidden);
94
-
95
- if (imageAnimation) {
96
- // Cancelling restores the complete image if reduced motion interrupts an entrance or exit.
97
- if (reduced) imageAnimation.cancel();
98
- else {
99
- imageAnimation.pause();
100
- imageAnimation.playbackRate = playbackRate;
101
- imageAnimation.currentTime = elapsed;
102
- }
103
- }
104
- if (progressAnimation) {
105
- progressAnimation.pause();
106
- progressAnimation.playbackRate = playbackRate;
107
- progressAnimation.currentTime = displayElapsed;
108
- }
109
- if (progress && !progressAnimation) {
110
- progress.style.transition = 'none';
111
- progress.style.transform = `scaleX(${displayElapsed / duration})`;
112
- if (!paused && displaying) {
113
- // Browsers without Web Animations can still interpolate progress natively.
114
- progress.getBoundingClientRect();
115
- progress.style.transition = `transform ${(duration - displayElapsed) / playbackRate}ms linear`;
116
- progress.style.transform = 'scaleX(1)';
117
- }
118
- }
119
- if (paused) return;
120
- if (elapsed >= totalDuration) {
121
- setIndex(nextIndex);
122
- return;
123
- }
124
-
125
- startedAt = now;
126
- imageAnimation?.play();
127
- if (displaying) progressAnimation?.play();
128
- const nextBoundary = elapsed < enterDuration ? enterDuration : displaying ? exitStart : totalDuration;
129
- timer = window.setTimeout(syncPlayback, (nextBoundary - elapsed) / playbackRate);
130
- };
131
-
132
- /*
133
- * Exit the current slide before entering its neighbor; reduced motion switches immediately.
134
- */
135
- navigateRef.current = (direction) => {
136
- const reduced = motion?.matches ?? false;
137
- if (!reduced && (elapsed < enterDuration || elapsed >= exitStart)) return;
138
- nextIndex = (index + direction + slides.length) % slides.length;
139
- if (reduced) {
140
- setIndex(nextIndex);
141
- return;
142
- }
143
- elapsed = exitStart;
144
- startedAt = null;
145
- syncPlayback();
146
- };
147
-
148
- /*
149
- * Remember pointer entry; only display time uses the hover duration or pauses.
150
- */
151
- const onMouseEnter = () => {
152
- hovered.current = true;
153
- syncPlayback();
154
- };
155
-
156
- /*
157
- * Restore the normal display speed after pointer exit unless another pause reason remains active.
158
- */
159
- const onMouseLeave = () => {
160
- hovered.current = false;
161
- syncPlayback();
162
- };
163
-
164
- /*
165
- * Track focus across descendants using the destination, before activeElement updates.
166
- */
167
- const syncFocus = (event: FocusEvent) => {
168
- focused = event.type === 'focusin' || (event.relatedTarget instanceof Node && !!hoverArea?.contains(event.relatedTarget));
169
- syncPlayback();
170
- };
171
-
172
- /*
173
- * Stop advancing and fetching subsequent slide images while the image area is offscreen.
174
- */
175
- const syncVisibility = (entries: IntersectionObserverEntry[]) => {
176
- visible = entries.at(-1)?.isIntersecting ?? visible;
177
- syncPlayback();
178
- };
179
-
180
- const observer = hoverArea && typeof IntersectionObserver !== 'undefined' ? new IntersectionObserver(syncVisibility) : null;
181
- if (hoverArea) observer?.observe(hoverArea);
182
- syncPlayback();
183
- hoverArea?.addEventListener('mouseenter', onMouseEnter);
184
- hoverArea?.addEventListener('mouseleave', onMouseLeave);
185
- hoverArea?.addEventListener('focusin', syncFocus);
186
- hoverArea?.addEventListener('focusout', syncFocus);
187
- document.addEventListener('visibilitychange', syncPlayback);
188
- motion?.addEventListener('change', syncPlayback);
189
- return () => {
190
- navigateRef.current = null;
191
- observer?.disconnect();
192
- window.clearTimeout(timer);
193
- imageAnimation?.cancel();
194
- progressAnimation?.cancel();
195
- if (progress && !progressAnimation) progress.style.transition = 'none';
196
- hoverArea?.removeEventListener('mouseenter', onMouseEnter);
197
- hoverArea?.removeEventListener('mouseleave', onMouseLeave);
198
- hoverArea?.removeEventListener('focusin', syncFocus);
199
- hoverArea?.removeEventListener('focusout', syncFocus);
200
- document.removeEventListener('visibilitychange', syncPlayback);
201
- motion?.removeEventListener('change', syncPlayback);
202
- };
203
- }, [index, slides.length, slideDuration, mouseOverSlideDuration, slideTransitionMs, fixedSlide]);
204
-
205
- return { index, isPaused, reducedMotion, showControls, navigate, imageAreaRef, hoverAreaRef, progressRef };
206
- }
@@ -1,305 +0,0 @@
1
- import i18n from '@jsb188/app/i18n/index.ts';
2
- import { cn } from '@jsb188/app/utils/string.ts';
3
- import { Icon } from '@jsb188/react-web/svgs/Icon';
4
- import type { CSSProperties, RefObject } from 'react';
5
- import { memo, useMemo } from 'react';
6
- import { useTypedText } from '../elements/Text.hooks.ts';
7
- import { getKineticImageAltStyle } from './KineticHeader.helpers.ts';
8
- import { useKineticHeader } from './KineticHeader.hooks.ts';
9
- import type { KineticHeaderImage, KineticHeaderProps } from './KineticHeader.types.ts';
10
-
11
- export type { KineticHeaderImage, KineticHeaderProps, KineticHeaderSlide } from './KineticHeader.types.ts';
12
-
13
- /*
14
- * Position an image and its caption by the image center.
15
- */
16
- const KineticImage = memo((p: { image: KineticHeaderImage; style?: CSSProperties }) => {
17
- const { image, style } = p;
18
- const hasFixedSize = image.width !== undefined && image.height !== undefined;
19
- const heightOnly = image.width === undefined && image.height !== undefined;
20
- return (
21
- <div
22
- className='abs'
23
- style={{
24
- left: `calc(50% + ${image.offset?.x ?? 0}px)`,
25
- top: `calc(50% + ${image.offset?.y ?? 0}px)`,
26
- width: image.width ?? (heightOnly ? 'max-content' : 650),
27
- height: image.height,
28
- transform: 'translate(-50%, -50%)',
29
- }}
30
- >
31
- {image.alt && (
32
- <div
33
- className={cn('abs ft_xs cl_md lh_2 a_l ofw bg_lighter_6', image.altClassName)}
34
- style={getKineticImageAltStyle(image)}
35
- aria-hidden
36
- >
37
- {image.alt}
38
- </div>
39
- )}
40
- <img
41
- src={image.src}
42
- alt={image.alt}
43
- width={image.width}
44
- height={image.height}
45
- decoding='async'
46
- draggable={false}
47
- className={cn('bl unsel', heightOnly ? 'no_shrink' : 'w_f', hasFixedSize && 'img_cover')}
48
- style={{ height: image.height !== undefined ? '100%' : 'auto', ...style }}
49
- />
50
- </div>
51
- );
52
- });
53
-
54
- /*
55
- * Position images in exact pixels around the image area's center, allowing overflow.
56
- */
57
- const KineticImageArea = (p: {
58
- images: readonly KineticHeaderImage[];
59
- index: number;
60
- imageAreaRef: RefObject<HTMLDivElement | null>;
61
- hoverAreaRef: RefObject<HTMLDivElement | null>;
62
- progressRef: RefObject<HTMLDivElement | null>;
63
- showProgress: boolean;
64
- isFixed: boolean;
65
- isPaused: boolean;
66
- showControls: boolean;
67
- onNavigate: (direction: -1 | 1) => void;
68
- reducedMotion: boolean;
69
- pausedLabelText?: KineticHeaderProps['pausedLabelText'];
70
- areaWidth: number;
71
- areaHeight: number;
72
- imageStyle?: CSSProperties;
73
- }) => {
74
- return (
75
- <div
76
- ref={p.hoverAreaRef}
77
- className='rel z1 w_f mx_auto'
78
- style={{ maxWidth: Math.max(1, p.areaWidth), height: Math.max(1, p.areaHeight), marginTop: 32 }}
79
- >
80
- <div
81
- ref={p.imageAreaRef}
82
- className='rel w_f h_f'
83
- >
84
- {p.images.map((image, itemIndex) => (
85
- <KineticImage
86
- key={`${p.index}-${itemIndex}`}
87
- image={image}
88
- style={p.imageStyle}
89
- />
90
- ))}
91
- </div>
92
- {p.showProgress && (
93
- <div
94
- className='abs z2 w_f h_f'
95
- style={{
96
- top: 0,
97
- left: 0,
98
- display: 'flex',
99
- flexDirection: 'column',
100
- justifyContent: 'flex-end',
101
- pointerEvents: 'none',
102
- }}
103
- >
104
- <div className='sticky_bottom w_f pb_5'>
105
- {!p.isFixed && (
106
- <div
107
- className='w_f h_spread gap_xs ft_xs cl_darker_5'
108
- style={{ opacity: p.showControls ? 1 : 0, pointerEvents: p.showControls ? 'auto' : 'none' }}
109
- >
110
- <button
111
- type='button'
112
- className='link h_center w_32 h_24 bg_lighter_5 bg_primary_hv no_shrink'
113
- aria-label={i18n.t('c.prev')}
114
- aria-disabled={!p.showControls}
115
- onMouseDown={(event) => event.preventDefault()}
116
- onClick={() => p.onNavigate(-1)}
117
- >
118
- <Icon name='arrow-narrow-left' />
119
- </button>
120
- {p.pausedLabelText && p.isPaused && (
121
- <span
122
- className='bg h_24 v_center px_6'
123
- aria-hidden={!p.showControls}
124
- >
125
- {p.pausedLabelText}
126
- </span>
127
- )}
128
- <button
129
- type='button'
130
- className='link h_center w_32 h_24 bg_lighter_5 bg_primary_hv no_shrink'
131
- aria-label={i18n.t('c.next')}
132
- aria-disabled={!p.showControls}
133
- onMouseDown={(event) => event.preventDefault()}
134
- onClick={() => p.onNavigate(1)}
135
- >
136
- <Icon name='arrow-narrow-right' />
137
- </button>
138
- </div>
139
- )}
140
- <div
141
- className='w_f h_4 bg shadow_line_alt r of'
142
- aria-hidden
143
- hidden={p.reducedMotion}
144
- >
145
- <div
146
- ref={p.progressRef}
147
- className='w_f h_f bg_primary r'
148
- style={{ transform: p.isFixed ? 'scaleX(1)' : 'scaleX(0)', transformOrigin: 'left' }}
149
- />
150
- </div>
151
- </div>
152
- </div>
153
- )}
154
- </div>
155
- );
156
- };
157
-
158
- /*
159
- * Confine each typing update to the visible title; image and layout trees stay untouched.
160
- */
161
- const KineticTitleText = (
162
- p: Pick<KineticHeaderProps, 'wordClassName' | 'typeMs' | 'deleteMs' | 'pauseMs' | 'jitter'> & {
163
- before: string;
164
- after: string;
165
- text: string;
166
- index: number;
167
- reducedMotion: boolean;
168
- },
169
- ) => {
170
- const { before, after, text, index, reducedMotion, wordClassName, typeMs, deleteMs = 35, pauseMs, jitter } = p;
171
- const { shown, typing } = useTypedText(text, { typeMs, deleteMs, pauseMs, jitter }, { replayKey: index, interruptOnChange: true });
172
- return (
173
- <span
174
- aria-hidden
175
- style={{ gridArea: '1 / 1' }}
176
- >
177
- {before}
178
- <span className={cn('rel', wordClassName)}>
179
- {reducedMotion ? text : shown}
180
- {typing && !reducedMotion && (
181
- <span
182
- className='abs'
183
- style={{ left: '100%', fontWeight: 200 }}
184
- >
185
- |
186
- </span>
187
- )}
188
- </span>
189
- {after}
190
- </span>
191
- );
192
- };
193
-
194
- /*
195
- * Render a centered title and its synchronized images; invisible complete titles reserve
196
- * enough space for every slide, keeping the image and following content still while typing.
197
- */
198
- const KineticHeaderSequence = (p: KineticHeaderProps) => {
199
- const {
200
- title,
201
- children,
202
- slides,
203
- fixedSlide,
204
- className,
205
- titleClassName,
206
- wordClassName,
207
- pausedLabelText,
208
- typeMs,
209
- deleteMs,
210
- pauseMs,
211
- jitter,
212
- style,
213
- titleStyle,
214
- imageStyle,
215
- imageAreaAspectRatio,
216
- imageAreaWidth = 1000,
217
- imageAreaHeight = imageAreaAspectRatio ? imageAreaWidth / imageAreaAspectRatio : 750,
218
- } = p;
219
- const { index, isPaused, reducedMotion, showControls, navigate, imageAreaRef, hoverAreaRef, progressRef } = useKineticHeader(p);
220
- const images = slides[index]?.images ?? [];
221
- const placeholder = title.indexOf('{word}');
222
- const before = placeholder < 0 ? title : title.slice(0, placeholder);
223
- const after = placeholder < 0 ? '' : title.slice(placeholder + 6);
224
-
225
- return (
226
- <div
227
- className={cn('w_f a_c', className)}
228
- style={style}
229
- >
230
- <h1
231
- className={cn('rel z2 grid gap_n mx_n my_n ofw', titleClassName)}
232
- aria-label={title.replace('{word}', slides[index]?.text ?? '')}
233
- style={{
234
- whiteSpace: 'pre-line',
235
- ...titleStyle,
236
- }}
237
- >
238
- {slides.map((item, itemIndex) => (
239
- <span
240
- key={itemIndex}
241
- aria-hidden
242
- className='invis'
243
- style={{ gridArea: '1 / 1' }}
244
- >
245
- {before}
246
- <span className={wordClassName}>{placeholder < 0 ? '' : item.text}</span>
247
- {after}
248
- </span>
249
- ))}
250
- <KineticTitleText
251
- before={before}
252
- after={after}
253
- text={placeholder < 0 ? '' : (slides[index]?.text ?? '')}
254
- index={index}
255
- reducedMotion={reducedMotion}
256
- wordClassName={wordClassName}
257
- typeMs={typeMs}
258
- deleteMs={deleteMs}
259
- pauseMs={pauseMs}
260
- jitter={jitter}
261
- />
262
- </h1>
263
- {children}
264
- {(slides.some((item) => item.images.length > 0) || (fixedSlide !== undefined && slides.length > 0)) && (
265
- <KineticImageArea
266
- images={images}
267
- index={index}
268
- imageAreaRef={imageAreaRef}
269
- hoverAreaRef={hoverAreaRef}
270
- progressRef={progressRef}
271
- showProgress={slides.length > 1 || fixedSlide !== undefined}
272
- isFixed={fixedSlide !== undefined}
273
- isPaused={isPaused}
274
- showControls={showControls}
275
- onNavigate={navigate}
276
- reducedMotion={reducedMotion}
277
- pausedLabelText={pausedLabelText}
278
- areaWidth={imageAreaWidth}
279
- areaHeight={imageAreaHeight}
280
- imageStyle={imageStyle}
281
- />
282
- )}
283
- </div>
284
- );
285
- };
286
-
287
- /*
288
- * Loop through a slide list, restarting only when its contents change rather than when
289
- * a parent recreates the array. Fixed selections remount fully typed and disable playback.
290
- * Reduced motion keeps the current complete slide still during autoplay.
291
- */
292
- export const KineticHeader = memo((p: KineticHeaderProps) => {
293
- const sequenceKey = useMemo(() => JSON.stringify(p.slides), [p.slides]);
294
- const fixedSlide =
295
- typeof p.fixedSlide === 'number' && Number.isInteger(p.fixedSlide)
296
- ? Math.max(0, Math.min(p.fixedSlide, p.slides.length - 1))
297
- : undefined;
298
- return (
299
- <KineticHeaderSequence
300
- key={`${sequenceKey}:${fixedSlide ?? 'auto'}`}
301
- {...p}
302
- fixedSlide={fixedSlide}
303
- />
304
- );
305
- });
@@ -1,56 +0,0 @@
1
- import type { CSSProperties, ReactNode } from 'react';
2
- import type { TypedTextTiming } from '../elements/Text.hooks.ts';
3
-
4
- export interface KineticHeaderImage {
5
- src: string;
6
- alt: string;
7
- /** Caption side; defaults to top. Side captions align with the image's top edge. */
8
- altPosition?: 'top' | 'left' | 'right' | 'bottom';
9
- /** Caption width in pixels; defaults to the image width. Does not affect image placement. */
10
- altWidth?: number;
11
- /** Additional classes for the caption container, such as a_r for right-aligned text. */
12
- altClassName?: string;
13
- /** Pixel offset of the image's center from the image area's center. Defaults to { x: 0, y: 0 }. */
14
- offset?: { x: number; y: number };
15
- /** Width in pixels. Alone, preserves aspect ratio. Defaults to 650 only when neither dimension is set. */
16
- width?: number;
17
- /** Height in pixels. Alone, derives width from aspect ratio; with width, crops to fill the box. */
18
- height?: number;
19
- }
20
-
21
- export interface KineticHeaderSlide {
22
- text: string;
23
- /** Positioned images shown when this slide starts; later entries appear on top. */
24
- images: readonly KineticHeaderImage[];
25
- }
26
-
27
- export interface KineticHeaderProps extends TypedTextTiming {
28
- /** Content rendered directly below the title and above the image area. */
29
- children?: ReactNode;
30
- /** A complete title containing one `{word}` placeholder; newlines are preserved. */
31
- title: string;
32
- /** Loops in order, starting with the first slide fully typed. Changing the list restarts it. */
33
- slides: readonly KineticHeaderSlide[];
34
- /** Zero-based slide index to hold without playback. Integers are clamped to the slide range; other values enable autoplay. Keeps a full, static progress bar visible. */
35
- fixedSlide?: number;
36
- /** Fully visible display time in milliseconds, excluding image entrance and exit; defaults to 5000. Short durations can interrupt typing. Hover pauses unless mouseOverSlideDuration is set; focus pauses display time. Neither affects entrance or exit. Offscreen slides, hidden tabs, and reduced motion pause all phases. */
37
- slideDuration?: number;
38
- /** Positive integer display duration in milliseconds while hovered, excluding entrance and exit. Changes speed without resetting progress; leaving restores slideDuration. Omitted or invalid values retain hover-to-pause. Keyboard focus still pauses. */
39
- mouseOverSlideDuration?: number;
40
- /** Image entrance duration; defaults to 350ms. Exit takes 350ms. Both run in addition to slideDuration. Use 0 to disable both. */
41
- slideTransitionMs?: number;
42
- /** Optional width / height ratio, used only when imageAreaHeight is omitted. */
43
- imageAreaAspectRatio?: number;
44
- /** Maximum image area width in pixels; defaults to 1000. Images retain their pixel sizes in narrower containers. */
45
- imageAreaWidth?: number;
46
- /** Image area height in pixels; defaults to 750 unless an aspect ratio is supplied. Does not scale. */
47
- imageAreaHeight?: number;
48
- /** Optional localized caption shown between navigation buttons while playback is paused and controls are visible. */
49
- pausedLabelText?: string;
50
- className?: string;
51
- titleClassName?: string;
52
- wordClassName?: string;
53
- style?: CSSProperties;
54
- titleStyle?: CSSProperties;
55
- imageStyle?: CSSProperties;
56
- }