use-scroll-animate 3.1.0 → 3.2.0
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.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -0
- package/README_ja.md +1 -0
- package/README_zh.md +1 -0
- package/dist/chunks/{index-tags-Gw1G06Pb.cjs → index-tags-DCTX4F9b.cjs} +2 -1
- package/dist/chunks/{index-tags-Gw1G06Pb.cjs.map → index-tags-DCTX4F9b.cjs.map} +1 -1
- package/dist/chunks/{index-tags-D7NynL4r.js → index-tags-DZ-gjMZc.js} +2 -1
- package/dist/chunks/{index-tags-D7NynL4r.js.map → index-tags-DZ-gjMZc.js.map} +1 -1
- package/dist/components/gesture.cjs +387 -0
- package/dist/components/gesture.cjs.map +1 -0
- package/dist/components/gesture.css +3 -0
- package/dist/components/gesture.d.cts +169 -0
- package/dist/components/gesture.d.ts +169 -0
- package/dist/components/gesture.js +379 -0
- package/dist/components/gesture.js.map +1 -0
- package/dist/components/jsx.d.cts +1 -0
- package/dist/components/jsx.d.ts +1 -0
- package/dist/components/lazy.cjs +2 -1
- package/dist/components/lazy.cjs.map +1 -1
- package/dist/components/lazy.d.cts +1 -0
- package/dist/components/lazy.d.ts +1 -0
- package/dist/components/lazy.js +2 -1
- package/dist/components/lazy.js.map +1 -1
- package/dist/components/react.cjs +1 -1
- package/dist/components/react.js +1 -1
- package/dist/components/vue.cjs +2 -1
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.d.cts +48 -0
- package/dist/components/vue.d.ts +48 -0
- package/dist/components/vue.js +2 -1
- package/dist/components/vue.js.map +1 -1
- package/dist/components.cjs +9 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +1 -0
- package/dist/components.d.cts +125 -2
- package/dist/components.d.ts +125 -2
- package/dist/components.js +5 -2
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/components.md +8 -0
- package/package.json +13 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use-scroll-animate/components — shared base for the `<usa-*>` custom elements.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is lazy: nothing touches `window`, `document`,
|
|
5
|
+
* `HTMLElement` or `matchMedia` at import time, so the components can be
|
|
6
|
+
* imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
|
|
7
|
+
* scripts. Classes are created the first time a `define*()` function runs.
|
|
8
|
+
*/
|
|
9
|
+
interface ComponentsConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Inject each component's CSS when it is defined (default `true`). Uses a
|
|
12
|
+
* constructable stylesheet (`document.adoptedStyleSheets`, which a strict
|
|
13
|
+
* `style-src` CSP does not block) and falls back to a `<style>` tag. Set
|
|
14
|
+
* to `false` when you load `use-scroll-animate/components.css` yourself.
|
|
15
|
+
*/
|
|
16
|
+
injectStyles?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always
|
|
19
|
+
* uses the reduced variants (e.g. a kiosk / battery-saver mode);
|
|
20
|
+
* `'no-preference'` ignores the OS setting (only for demos — respect your users).
|
|
21
|
+
*/
|
|
22
|
+
reducedMotion?: 'user' | 'reduce' | 'no-preference';
|
|
23
|
+
/**
|
|
24
|
+
* Global motion intensity (v2.7): `'off'` (same as reduced motion),
|
|
25
|
+
* `'low'` (shorter, calmer), `'normal'` (default) or `'high'`. Scales every
|
|
26
|
+
* component animation's duration and sets `--usa-motion` (0 / 0.6 / 1 /
|
|
27
|
+
* 1.25) on `<html>` for your own CSS. See `setMotionIntensity()`.
|
|
28
|
+
*/
|
|
29
|
+
motionIntensity?: MotionIntensity;
|
|
30
|
+
}
|
|
31
|
+
type MotionIntensity = 'off' | 'low' | 'normal' | 'high';
|
|
32
|
+
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
33
|
+
declare function configureComponents(options: ComponentsConfig): void;
|
|
34
|
+
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
35
|
+
declare function prefersReducedMotion(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
|
|
38
|
+
* bag that is emptied on disconnect, and motion helpers that degrade to the
|
|
39
|
+
* final state without WAAPI or under reduced motion.
|
|
40
|
+
*/
|
|
41
|
+
interface UsaElement extends HTMLElement {
|
|
42
|
+
/** `true` while reduced motion applies to this element. */
|
|
43
|
+
readonly reduced: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PanState {
|
|
47
|
+
/** Offset from the gesture start (px). */
|
|
48
|
+
dx: number;
|
|
49
|
+
dy: number;
|
|
50
|
+
/** Velocity (px/s). */
|
|
51
|
+
vx: number;
|
|
52
|
+
vy: number;
|
|
53
|
+
first: boolean;
|
|
54
|
+
last: boolean;
|
|
55
|
+
event: Event;
|
|
56
|
+
}
|
|
57
|
+
type SwipeDirection = 'left' | 'right' | 'up' | 'down';
|
|
58
|
+
interface SwipeState {
|
|
59
|
+
direction: SwipeDirection;
|
|
60
|
+
velocity: number;
|
|
61
|
+
dx: number;
|
|
62
|
+
dy: number;
|
|
63
|
+
}
|
|
64
|
+
interface PinchState {
|
|
65
|
+
scale: number; /** Midpoint of the two pointers (client px). */
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
first: boolean;
|
|
69
|
+
last: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface PressState {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}
|
|
75
|
+
interface GestureHandlers {
|
|
76
|
+
onPan?: (s: PanState) => void;
|
|
77
|
+
onSwipe?: (s: SwipeState) => void;
|
|
78
|
+
onPinch?: (s: PinchState) => void;
|
|
79
|
+
onLongPress?: (s: PressState) => void;
|
|
80
|
+
onTap?: (s: PressState) => void;
|
|
81
|
+
onDoubleTap?: (s: PressState) => void;
|
|
82
|
+
}
|
|
83
|
+
interface GestureOptions {
|
|
84
|
+
/** Restrict panning to an axis. */
|
|
85
|
+
axis?: 'x' | 'y';
|
|
86
|
+
/** Movement (px) before a pan starts (default 4). */
|
|
87
|
+
threshold?: number;
|
|
88
|
+
/** Minimum distance (px, default 40) and speed (px/s, default 300) for a swipe. */
|
|
89
|
+
swipeDistance?: number;
|
|
90
|
+
swipeVelocity?: number;
|
|
91
|
+
/** Long-press delay (ms, default 500). */
|
|
92
|
+
longPress?: number;
|
|
93
|
+
/** Ctrl/⌘ + wheel (trackpad pinch) counts as pinch (default true). */
|
|
94
|
+
wheelPinch?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/** The swipe a pointer release represents, or `null` (pure). */
|
|
97
|
+
declare function swipeDirection(dx: number, dy: number, vx: number, vy: number, o?: {
|
|
98
|
+
distance?: number;
|
|
99
|
+
velocity?: number;
|
|
100
|
+
axis?: 'x' | 'y';
|
|
101
|
+
}): SwipeState | null;
|
|
102
|
+
/** Scale between two pointer distances, clamped to [min, max] (pure). */
|
|
103
|
+
declare function pinchScale(startDistance: number, distance: number, base?: number, min?: number, max?: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* One recognizer for pan, swipe, pinch (two pointers or Ctrl + wheel),
|
|
106
|
+
* long-press, tap and double-tap, with velocities ready to hand to a spring
|
|
107
|
+
* (`createSpring().set(target, velocity)`). Works with mouse, touch and pen
|
|
108
|
+
* through Pointer Events. Returns a cleanup function.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const x = createSpring({ onUpdate: (v) => (card.style.translate = `${v}px`) });
|
|
112
|
+
* gesture(card, {
|
|
113
|
+
* onPan: ({ dx, last, vx }) => (last ? x.set(0, vx) : x.jump(dx)),
|
|
114
|
+
* onSwipe: ({ direction }) => dismiss(direction),
|
|
115
|
+
* }, { axis: 'x' });
|
|
116
|
+
*/
|
|
117
|
+
declare function gesture(el: HTMLElement, h: GestureHandlers, o?: GestureOptions): () => void;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `<usa-swipeable>` — swipe-to-dismiss / swipe actions. The content follows
|
|
121
|
+
* the finger (rubber-banded past `distance`), flies out on a swipe or a drag
|
|
122
|
+
* past `distance`, otherwise springs home with the release velocity.
|
|
123
|
+
*
|
|
124
|
+
* Attributes: `axis` (`x` default · `y`), `distance` (px, 120), `preset`
|
|
125
|
+
* (spring), `dismiss` (remove the element after flying out), `disabled`.
|
|
126
|
+
* Keyboard: Delete/Backspace dismisses, ←/→ swipe. Events `usa:swipe`
|
|
127
|
+
* (`{ direction }`, cancelable), `usa:dismiss`. Methods `swipe(dir)`, `reset()`.
|
|
128
|
+
* Reduced motion: no follow / fly-out animation, events still fire.
|
|
129
|
+
*/
|
|
130
|
+
interface UsaSwipeableElement extends UsaElement {
|
|
131
|
+
swipe(direction: SwipeDirection): void;
|
|
132
|
+
reset(): void;
|
|
133
|
+
readonly offset: number;
|
|
134
|
+
}
|
|
135
|
+
declare function defineSwipeable(tag?: string): CustomElementConstructor | undefined;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `<usa-pinch-zoom>` — pinch (two fingers or Ctrl/⌘ + wheel / trackpad
|
|
139
|
+
* pinch) to zoom its content, pan while zoomed, double-tap to toggle zoom;
|
|
140
|
+
* scale and position spring back inside the bounds on release.
|
|
141
|
+
*
|
|
142
|
+
* Attributes: `min` (1), `max` (4), `double-tap` (zoom level, 2), `preset`.
|
|
143
|
+
* Keyboard: `+` / `-` / `0`. Property `scale`, method `zoomTo(scale)`.
|
|
144
|
+
* Event `usa:zoom` (`{ scale }`). Reduced motion: zoom changes instantly.
|
|
145
|
+
*/
|
|
146
|
+
interface UsaPinchZoomElement extends UsaElement {
|
|
147
|
+
readonly scale: number;
|
|
148
|
+
zoomTo(scale: number): void;
|
|
149
|
+
}
|
|
150
|
+
declare function definePinchZoom(tag?: string): CustomElementConstructor | undefined;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* use-scroll-animate/components/gesture — unified gestures (v3.2).
|
|
154
|
+
* `gesture()` recognises pan, swipe, pinch, long-press, tap and double-tap
|
|
155
|
+
* with release velocities for springs; `<usa-swipeable>` (swipe-to-dismiss)
|
|
156
|
+
* and `<usa-pinch-zoom>` are built on it.
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
/** Register every component of this category under its default tag. */
|
|
160
|
+
declare function defineGestureComponents(): void;
|
|
161
|
+
declare global {
|
|
162
|
+
interface HTMLElementTagNameMap {
|
|
163
|
+
'usa-swipeable': UsaSwipeableElement;
|
|
164
|
+
'usa-pinch-zoom': UsaPinchZoomElement;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { configureComponents, defineGestureComponents, definePinchZoom, defineSwipeable, gesture, pinchScale, prefersReducedMotion, swipeDirection };
|
|
169
|
+
export type { ComponentsConfig, GestureHandlers, GestureOptions, PanState, PinchState, PressState, SwipeDirection, SwipeState, UsaElement, UsaPinchZoomElement, UsaSwipeableElement };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use-scroll-animate/components — shared base for the `<usa-*>` custom elements.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is lazy: nothing touches `window`, `document`,
|
|
5
|
+
* `HTMLElement` or `matchMedia` at import time, so the components can be
|
|
6
|
+
* imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
|
|
7
|
+
* scripts. Classes are created the first time a `define*()` function runs.
|
|
8
|
+
*/
|
|
9
|
+
interface ComponentsConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Inject each component's CSS when it is defined (default `true`). Uses a
|
|
12
|
+
* constructable stylesheet (`document.adoptedStyleSheets`, which a strict
|
|
13
|
+
* `style-src` CSP does not block) and falls back to a `<style>` tag. Set
|
|
14
|
+
* to `false` when you load `use-scroll-animate/components.css` yourself.
|
|
15
|
+
*/
|
|
16
|
+
injectStyles?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always
|
|
19
|
+
* uses the reduced variants (e.g. a kiosk / battery-saver mode);
|
|
20
|
+
* `'no-preference'` ignores the OS setting (only for demos — respect your users).
|
|
21
|
+
*/
|
|
22
|
+
reducedMotion?: 'user' | 'reduce' | 'no-preference';
|
|
23
|
+
/**
|
|
24
|
+
* Global motion intensity (v2.7): `'off'` (same as reduced motion),
|
|
25
|
+
* `'low'` (shorter, calmer), `'normal'` (default) or `'high'`. Scales every
|
|
26
|
+
* component animation's duration and sets `--usa-motion` (0 / 0.6 / 1 /
|
|
27
|
+
* 1.25) on `<html>` for your own CSS. See `setMotionIntensity()`.
|
|
28
|
+
*/
|
|
29
|
+
motionIntensity?: MotionIntensity;
|
|
30
|
+
}
|
|
31
|
+
type MotionIntensity = 'off' | 'low' | 'normal' | 'high';
|
|
32
|
+
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
33
|
+
declare function configureComponents(options: ComponentsConfig): void;
|
|
34
|
+
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
35
|
+
declare function prefersReducedMotion(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
|
|
38
|
+
* bag that is emptied on disconnect, and motion helpers that degrade to the
|
|
39
|
+
* final state without WAAPI or under reduced motion.
|
|
40
|
+
*/
|
|
41
|
+
interface UsaElement extends HTMLElement {
|
|
42
|
+
/** `true` while reduced motion applies to this element. */
|
|
43
|
+
readonly reduced: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PanState {
|
|
47
|
+
/** Offset from the gesture start (px). */
|
|
48
|
+
dx: number;
|
|
49
|
+
dy: number;
|
|
50
|
+
/** Velocity (px/s). */
|
|
51
|
+
vx: number;
|
|
52
|
+
vy: number;
|
|
53
|
+
first: boolean;
|
|
54
|
+
last: boolean;
|
|
55
|
+
event: Event;
|
|
56
|
+
}
|
|
57
|
+
type SwipeDirection = 'left' | 'right' | 'up' | 'down';
|
|
58
|
+
interface SwipeState {
|
|
59
|
+
direction: SwipeDirection;
|
|
60
|
+
velocity: number;
|
|
61
|
+
dx: number;
|
|
62
|
+
dy: number;
|
|
63
|
+
}
|
|
64
|
+
interface PinchState {
|
|
65
|
+
scale: number; /** Midpoint of the two pointers (client px). */
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
first: boolean;
|
|
69
|
+
last: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface PressState {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}
|
|
75
|
+
interface GestureHandlers {
|
|
76
|
+
onPan?: (s: PanState) => void;
|
|
77
|
+
onSwipe?: (s: SwipeState) => void;
|
|
78
|
+
onPinch?: (s: PinchState) => void;
|
|
79
|
+
onLongPress?: (s: PressState) => void;
|
|
80
|
+
onTap?: (s: PressState) => void;
|
|
81
|
+
onDoubleTap?: (s: PressState) => void;
|
|
82
|
+
}
|
|
83
|
+
interface GestureOptions {
|
|
84
|
+
/** Restrict panning to an axis. */
|
|
85
|
+
axis?: 'x' | 'y';
|
|
86
|
+
/** Movement (px) before a pan starts (default 4). */
|
|
87
|
+
threshold?: number;
|
|
88
|
+
/** Minimum distance (px, default 40) and speed (px/s, default 300) for a swipe. */
|
|
89
|
+
swipeDistance?: number;
|
|
90
|
+
swipeVelocity?: number;
|
|
91
|
+
/** Long-press delay (ms, default 500). */
|
|
92
|
+
longPress?: number;
|
|
93
|
+
/** Ctrl/⌘ + wheel (trackpad pinch) counts as pinch (default true). */
|
|
94
|
+
wheelPinch?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/** The swipe a pointer release represents, or `null` (pure). */
|
|
97
|
+
declare function swipeDirection(dx: number, dy: number, vx: number, vy: number, o?: {
|
|
98
|
+
distance?: number;
|
|
99
|
+
velocity?: number;
|
|
100
|
+
axis?: 'x' | 'y';
|
|
101
|
+
}): SwipeState | null;
|
|
102
|
+
/** Scale between two pointer distances, clamped to [min, max] (pure). */
|
|
103
|
+
declare function pinchScale(startDistance: number, distance: number, base?: number, min?: number, max?: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* One recognizer for pan, swipe, pinch (two pointers or Ctrl + wheel),
|
|
106
|
+
* long-press, tap and double-tap, with velocities ready to hand to a spring
|
|
107
|
+
* (`createSpring().set(target, velocity)`). Works with mouse, touch and pen
|
|
108
|
+
* through Pointer Events. Returns a cleanup function.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const x = createSpring({ onUpdate: (v) => (card.style.translate = `${v}px`) });
|
|
112
|
+
* gesture(card, {
|
|
113
|
+
* onPan: ({ dx, last, vx }) => (last ? x.set(0, vx) : x.jump(dx)),
|
|
114
|
+
* onSwipe: ({ direction }) => dismiss(direction),
|
|
115
|
+
* }, { axis: 'x' });
|
|
116
|
+
*/
|
|
117
|
+
declare function gesture(el: HTMLElement, h: GestureHandlers, o?: GestureOptions): () => void;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `<usa-swipeable>` — swipe-to-dismiss / swipe actions. The content follows
|
|
121
|
+
* the finger (rubber-banded past `distance`), flies out on a swipe or a drag
|
|
122
|
+
* past `distance`, otherwise springs home with the release velocity.
|
|
123
|
+
*
|
|
124
|
+
* Attributes: `axis` (`x` default · `y`), `distance` (px, 120), `preset`
|
|
125
|
+
* (spring), `dismiss` (remove the element after flying out), `disabled`.
|
|
126
|
+
* Keyboard: Delete/Backspace dismisses, ←/→ swipe. Events `usa:swipe`
|
|
127
|
+
* (`{ direction }`, cancelable), `usa:dismiss`. Methods `swipe(dir)`, `reset()`.
|
|
128
|
+
* Reduced motion: no follow / fly-out animation, events still fire.
|
|
129
|
+
*/
|
|
130
|
+
interface UsaSwipeableElement extends UsaElement {
|
|
131
|
+
swipe(direction: SwipeDirection): void;
|
|
132
|
+
reset(): void;
|
|
133
|
+
readonly offset: number;
|
|
134
|
+
}
|
|
135
|
+
declare function defineSwipeable(tag?: string): CustomElementConstructor | undefined;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `<usa-pinch-zoom>` — pinch (two fingers or Ctrl/⌘ + wheel / trackpad
|
|
139
|
+
* pinch) to zoom its content, pan while zoomed, double-tap to toggle zoom;
|
|
140
|
+
* scale and position spring back inside the bounds on release.
|
|
141
|
+
*
|
|
142
|
+
* Attributes: `min` (1), `max` (4), `double-tap` (zoom level, 2), `preset`.
|
|
143
|
+
* Keyboard: `+` / `-` / `0`. Property `scale`, method `zoomTo(scale)`.
|
|
144
|
+
* Event `usa:zoom` (`{ scale }`). Reduced motion: zoom changes instantly.
|
|
145
|
+
*/
|
|
146
|
+
interface UsaPinchZoomElement extends UsaElement {
|
|
147
|
+
readonly scale: number;
|
|
148
|
+
zoomTo(scale: number): void;
|
|
149
|
+
}
|
|
150
|
+
declare function definePinchZoom(tag?: string): CustomElementConstructor | undefined;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* use-scroll-animate/components/gesture — unified gestures (v3.2).
|
|
154
|
+
* `gesture()` recognises pan, swipe, pinch, long-press, tap and double-tap
|
|
155
|
+
* with release velocities for springs; `<usa-swipeable>` (swipe-to-dismiss)
|
|
156
|
+
* and `<usa-pinch-zoom>` are built on it.
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
/** Register every component of this category under its default tag. */
|
|
160
|
+
declare function defineGestureComponents(): void;
|
|
161
|
+
declare global {
|
|
162
|
+
interface HTMLElementTagNameMap {
|
|
163
|
+
'usa-swipeable': UsaSwipeableElement;
|
|
164
|
+
'usa-pinch-zoom': UsaPinchZoomElement;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { configureComponents, defineGestureComponents, definePinchZoom, defineSwipeable, gesture, pinchScale, prefersReducedMotion, swipeDirection };
|
|
169
|
+
export type { ComponentsConfig, GestureHandlers, GestureOptions, PanState, PinchState, PressState, SwipeDirection, SwipeState, UsaElement, UsaPinchZoomElement, UsaSwipeableElement };
|