@andrew_l/dom 0.3.22 → 0.4.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/dist/index.d.cts DELETED
@@ -1,219 +0,0 @@
1
- interface AnimationInstance {
2
- isCancelled: boolean;
3
- }
4
- /**
5
- * Animates a single tick of an animation, running repeatedly until cancelled or the tick function returns `false`.
6
- *
7
- * If an `instance` is provided, it will control the cancellation state of the animation. Otherwise, a new animation
8
- * instance is created and assigned as the current instance. This function uses `fastRaf` to run the animation in the
9
- * next available frame.
10
- *
11
- * @param tick A function to be called on each frame, returning `true` to continue animating or `false` to stop.
12
- * @param instance An optional animation instance to control cancellation state.
13
- *
14
- * @example
15
- * animateSingle(() => {
16
- * // Your tick logic here (e.g., move an element)
17
- * return true; // Return `true` to keep animating, `false` to stop.
18
- * });
19
- *
20
- * @group Animation
21
- */
22
- declare function animateSingle(tick: Function, instance?: AnimationInstance): void;
23
- /**
24
- * Continuously animates by repeatedly calling the `tick` function until it returns `false`.
25
- *
26
- * The function uses `fastRaf` to run the animation and continues until the `tick` function no longer returns `true`.
27
- *
28
- * @param tick The tick function to be executed on each frame. If it returns `false`, the animation stops.
29
- *
30
- * @example
31
- * animate(() => {
32
- * // Your animation logic here
33
- * return true; // Return `true` to continue animating, `false` to stop.
34
- * });
35
- *
36
- * @group Animation
37
- */
38
- declare function animate(tick: Function): void;
39
- /**
40
- * Instantly animates by calling the `tick` function in rapid succession until it returns `false`.
41
- *
42
- * This is intended for scenarios where the animation should run as quickly as possible, without any delay.
43
- *
44
- * @param tick The tick function to be executed on each frame. If it returns `false`, the animation stops.
45
- *
46
- * @example
47
- * animateInstantly(() => {
48
- * // Your instant animation logic here
49
- * return true; // Return `true` to continue animating, `false` to stop.
50
- * });
51
- *
52
- * @group Animation
53
- */
54
- declare function animateInstantly(tick: Function): void;
55
- type TimingFn = (t: number) => number;
56
- type AnimateNumberProps = {
57
- to: number | number[];
58
- from: number | number[];
59
- duration: number;
60
- onUpdate: (value: any) => void;
61
- timing?: TimingFn;
62
- onEnd?: () => void;
63
- };
64
- declare const timingFunctions: {
65
- linear: (t: number) => number;
66
- easeIn: (t: number) => number;
67
- easeOut: (t: number) => number;
68
- easeInOut: (t: number) => number;
69
- easeInQuad: (t: number) => number;
70
- easeOutQuad: (t: number) => number;
71
- easeInOutQuad: (t: number) => number;
72
- easeInCubic: (t: number) => number;
73
- easeOutCubic: (t: number) => number;
74
- easeInOutCubic: (t: number) => number;
75
- easeInQuart: (t: number) => number;
76
- easeOutQuart: (t: number) => number;
77
- easeInOutQuart: (t: number) => number;
78
- easeInQuint: (t: number) => number;
79
- easeOutQuint: (t: number) => number;
80
- easeInOutQuint: (t: number) => number;
81
- };
82
- /**
83
- * Animates a numeric value from `from` to `to` over a specified duration, applying an optional timing function.
84
- *
85
- * The animation will continuously update the value using the `onUpdate` callback until the animation is complete.
86
- * Once the animation ends, the `onEnd` callback will be called, if provided.
87
- *
88
- * @param timing The timing function that controls the progression of the animation. Defaults to `linear`.
89
- * @param onUpdate A callback that receives the updated value (or values) on each animation frame.
90
- * @param duration The duration of the animation in milliseconds.
91
- * @param onEnd An optional callback to be called when the animation completes.
92
- * @param from The starting value(s) of the animation.
93
- * @param to The target value(s) of the animation.
94
- *
95
- * @returns A function that can be called to cancel the animation.
96
- *
97
- * @example
98
- * animateNumber({
99
- * from: 0,
100
- * to: 100,
101
- * duration: 1000,
102
- * onUpdate: (value) => {
103
- * console.log(value); // Updated value on each frame
104
- * },
105
- * onEnd: () => {
106
- * console.log('Animation complete!');
107
- * },
108
- * });
109
- *
110
- * @group Animation
111
- */
112
- declare function animateNumber({ timing, onUpdate, duration, onEnd, from, to, }: AnimateNumberProps): () => void;
113
-
114
- /**
115
- * Copies the provided text to the system clipboard.
116
- *
117
- * The function attempts to use the `navigator.clipboard` API if available. If not,
118
- * it falls back to using a fake element approach to copy the text.
119
- *
120
- * @param text The text to be copied to the clipboard.
121
- * @returns A promise that resolves to `true` if the text was successfully copied,
122
- * or `false` if the operation failed.
123
- *
124
- * @example
125
- * copyTextToClipboard('Hello, World!')
126
- * .then(success => {
127
- * if (success) {
128
- * console.log('Text copied to clipboard!');
129
- * } else {
130
- * console.log('Failed to copy text.');
131
- * }
132
- * });
133
- *
134
- * @group Clipboard
135
- */
136
- declare function copyTextToClipboard(text: string): Promise<boolean>;
137
-
138
- declare const FAST_SMOOTH_MAX_DISTANCE = 1500;
139
- declare const FAST_SMOOTH_MIN_DURATION = 250;
140
- declare const FAST_SMOOTH_MAX_DURATION = 600;
141
- declare const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500;
142
- type ScrollCompleteCallback = (target: HTMLElement) => void;
143
- declare enum FocusDirection {
144
- Up = 0,
145
- Down = 1,
146
- Static = 2
147
- }
148
- /**
149
- * Smoothly scrolls the specified container to bring the given element into view,
150
- * with optional customization for scroll behavior, direction, and duration.
151
- *
152
- * This function calculates the optimal scroll position based on the given parameters
153
- * and smoothly scrolls the container to that position. It can adjust the scroll
154
- * behavior for accessibility, animation duration, and other constraints.
155
- *
156
- * @param container The container element that will be scrolled.
157
- * @param element The element inside the container that needs to be brought into view.
158
- * @param position The scroll position logic (`'centerOrTop'`, `ScrollLogicalPosition`).
159
- * @param margin A margin in pixels to be applied around the element when scrolling into view (default is `0`).
160
- * @param maxDistance The maximum distance for smooth scrolling (default is `FAST_SMOOTH_MAX_DISTANCE`).
161
- * @param forceDirection Optional, the direction to force the scroll (`FocusDirection`). If not provided, the default scroll direction is calculated.
162
- * @param forceDuration Optional, a custom duration (in milliseconds) for the smooth scroll. If not provided, a default duration is used.
163
- * @param forceNormalContainerHeight Optional, a flag indicating whether to force the container height calculation for normal behavior.
164
- * @param onComplete Optional callback function that is triggered when the scroll operation completes.
165
- *
166
- * @example
167
- * fastSmoothScroll(container, element, 'centerOrTop', 10, 500, FocusDirection.Up, 300);
168
- *
169
- * @group Scrolling
170
- */
171
- declare function fastSmoothScroll(container: HTMLElement, element: HTMLElement, position: ScrollLogicalPosition | 'centerOrTop', margin?: number, maxDistance?: number, forceDirection?: FocusDirection, forceDuration?: number, forceNormalContainerHeight?: boolean, onComplete?: ScrollCompleteCallback): void;
172
-
173
- /**
174
- * Determines if the specified element or the document/window is scrolled near the bottom.
175
- *
176
- * This function checks if the scroll position has reached the bottom of the target element or window
177
- * within a specified threshold. It is commonly used for implementing "infinite scroll" or detecting
178
- * when a user has scrolled to the bottom of a page or container.
179
- *
180
- * @param target The target element, document, or window to check the scroll position.
181
- * Can be an `HTMLElement`, `Document`, or `Window`.
182
- * @param threshold The threshold (in pixels) below which the target is considered "scrolled to the bottom."
183
- * Default is `10`, meaning the target is considered scrolled to the bottom if it is within 10px of the bottom.
184
- *
185
- * @returns `true` if the target is scrolled near the bottom within the given threshold, otherwise `false`.
186
- *
187
- * @example
188
- * // Check if the window is scrolled near the bottom
189
- * isScrolledToDown(window, 20); // Returns true if within 20px of the bottom of the window.
190
- *
191
- * @example
192
- * // Check if a specific container is scrolled near the bottom
193
- * const container = document.getElementById('myContainer');
194
- * isScrolledToDown(container, 50); // Returns true if within 50px of the bottom of the container.
195
- *
196
- * @group Scrolling
197
- */
198
- declare function isScrolledToDown(target: HTMLElement | Document | Window, threshold?: number): boolean;
199
-
200
- /**
201
- * Resets the scroll position of the specified container element.
202
- *
203
- * If a `scrollTop` value is provided, the container's scroll position is set
204
- * to that value. Otherwise, the function will leave the scroll position unchanged.
205
- * This function is useful for resetting the scroll state in a container, such as
206
- * when the content changes or after an animation.
207
- *
208
- * @param container The container element whose scroll position needs to be reset.
209
- * @param scrollTop Optional value to set the container's `scrollTop`. If not provided, the scroll position remains unchanged.
210
- *
211
- * @example
212
- * resetScroll(container, 0); // Resets scroll to top of the container.
213
- * resetScroll(container); // Resets scroll position without changing it.
214
- *
215
- * @group Scrolling
216
- */
217
- declare function resetScroll(container: HTMLDivElement, scrollTop?: number): void;
218
-
219
- export { type AnimateNumberProps, FAST_SMOOTH_MAX_DISTANCE, FAST_SMOOTH_MAX_DURATION, FAST_SMOOTH_MIN_DURATION, FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE, FocusDirection, type ScrollCompleteCallback, type TimingFn, animate, animateInstantly, animateNumber, animateSingle, copyTextToClipboard, fastSmoothScroll, isScrolledToDown, resetScroll, timingFunctions };
package/dist/index.d.ts DELETED
@@ -1,219 +0,0 @@
1
- interface AnimationInstance {
2
- isCancelled: boolean;
3
- }
4
- /**
5
- * Animates a single tick of an animation, running repeatedly until cancelled or the tick function returns `false`.
6
- *
7
- * If an `instance` is provided, it will control the cancellation state of the animation. Otherwise, a new animation
8
- * instance is created and assigned as the current instance. This function uses `fastRaf` to run the animation in the
9
- * next available frame.
10
- *
11
- * @param tick A function to be called on each frame, returning `true` to continue animating or `false` to stop.
12
- * @param instance An optional animation instance to control cancellation state.
13
- *
14
- * @example
15
- * animateSingle(() => {
16
- * // Your tick logic here (e.g., move an element)
17
- * return true; // Return `true` to keep animating, `false` to stop.
18
- * });
19
- *
20
- * @group Animation
21
- */
22
- declare function animateSingle(tick: Function, instance?: AnimationInstance): void;
23
- /**
24
- * Continuously animates by repeatedly calling the `tick` function until it returns `false`.
25
- *
26
- * The function uses `fastRaf` to run the animation and continues until the `tick` function no longer returns `true`.
27
- *
28
- * @param tick The tick function to be executed on each frame. If it returns `false`, the animation stops.
29
- *
30
- * @example
31
- * animate(() => {
32
- * // Your animation logic here
33
- * return true; // Return `true` to continue animating, `false` to stop.
34
- * });
35
- *
36
- * @group Animation
37
- */
38
- declare function animate(tick: Function): void;
39
- /**
40
- * Instantly animates by calling the `tick` function in rapid succession until it returns `false`.
41
- *
42
- * This is intended for scenarios where the animation should run as quickly as possible, without any delay.
43
- *
44
- * @param tick The tick function to be executed on each frame. If it returns `false`, the animation stops.
45
- *
46
- * @example
47
- * animateInstantly(() => {
48
- * // Your instant animation logic here
49
- * return true; // Return `true` to continue animating, `false` to stop.
50
- * });
51
- *
52
- * @group Animation
53
- */
54
- declare function animateInstantly(tick: Function): void;
55
- type TimingFn = (t: number) => number;
56
- type AnimateNumberProps = {
57
- to: number | number[];
58
- from: number | number[];
59
- duration: number;
60
- onUpdate: (value: any) => void;
61
- timing?: TimingFn;
62
- onEnd?: () => void;
63
- };
64
- declare const timingFunctions: {
65
- linear: (t: number) => number;
66
- easeIn: (t: number) => number;
67
- easeOut: (t: number) => number;
68
- easeInOut: (t: number) => number;
69
- easeInQuad: (t: number) => number;
70
- easeOutQuad: (t: number) => number;
71
- easeInOutQuad: (t: number) => number;
72
- easeInCubic: (t: number) => number;
73
- easeOutCubic: (t: number) => number;
74
- easeInOutCubic: (t: number) => number;
75
- easeInQuart: (t: number) => number;
76
- easeOutQuart: (t: number) => number;
77
- easeInOutQuart: (t: number) => number;
78
- easeInQuint: (t: number) => number;
79
- easeOutQuint: (t: number) => number;
80
- easeInOutQuint: (t: number) => number;
81
- };
82
- /**
83
- * Animates a numeric value from `from` to `to` over a specified duration, applying an optional timing function.
84
- *
85
- * The animation will continuously update the value using the `onUpdate` callback until the animation is complete.
86
- * Once the animation ends, the `onEnd` callback will be called, if provided.
87
- *
88
- * @param timing The timing function that controls the progression of the animation. Defaults to `linear`.
89
- * @param onUpdate A callback that receives the updated value (or values) on each animation frame.
90
- * @param duration The duration of the animation in milliseconds.
91
- * @param onEnd An optional callback to be called when the animation completes.
92
- * @param from The starting value(s) of the animation.
93
- * @param to The target value(s) of the animation.
94
- *
95
- * @returns A function that can be called to cancel the animation.
96
- *
97
- * @example
98
- * animateNumber({
99
- * from: 0,
100
- * to: 100,
101
- * duration: 1000,
102
- * onUpdate: (value) => {
103
- * console.log(value); // Updated value on each frame
104
- * },
105
- * onEnd: () => {
106
- * console.log('Animation complete!');
107
- * },
108
- * });
109
- *
110
- * @group Animation
111
- */
112
- declare function animateNumber({ timing, onUpdate, duration, onEnd, from, to, }: AnimateNumberProps): () => void;
113
-
114
- /**
115
- * Copies the provided text to the system clipboard.
116
- *
117
- * The function attempts to use the `navigator.clipboard` API if available. If not,
118
- * it falls back to using a fake element approach to copy the text.
119
- *
120
- * @param text The text to be copied to the clipboard.
121
- * @returns A promise that resolves to `true` if the text was successfully copied,
122
- * or `false` if the operation failed.
123
- *
124
- * @example
125
- * copyTextToClipboard('Hello, World!')
126
- * .then(success => {
127
- * if (success) {
128
- * console.log('Text copied to clipboard!');
129
- * } else {
130
- * console.log('Failed to copy text.');
131
- * }
132
- * });
133
- *
134
- * @group Clipboard
135
- */
136
- declare function copyTextToClipboard(text: string): Promise<boolean>;
137
-
138
- declare const FAST_SMOOTH_MAX_DISTANCE = 1500;
139
- declare const FAST_SMOOTH_MIN_DURATION = 250;
140
- declare const FAST_SMOOTH_MAX_DURATION = 600;
141
- declare const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500;
142
- type ScrollCompleteCallback = (target: HTMLElement) => void;
143
- declare enum FocusDirection {
144
- Up = 0,
145
- Down = 1,
146
- Static = 2
147
- }
148
- /**
149
- * Smoothly scrolls the specified container to bring the given element into view,
150
- * with optional customization for scroll behavior, direction, and duration.
151
- *
152
- * This function calculates the optimal scroll position based on the given parameters
153
- * and smoothly scrolls the container to that position. It can adjust the scroll
154
- * behavior for accessibility, animation duration, and other constraints.
155
- *
156
- * @param container The container element that will be scrolled.
157
- * @param element The element inside the container that needs to be brought into view.
158
- * @param position The scroll position logic (`'centerOrTop'`, `ScrollLogicalPosition`).
159
- * @param margin A margin in pixels to be applied around the element when scrolling into view (default is `0`).
160
- * @param maxDistance The maximum distance for smooth scrolling (default is `FAST_SMOOTH_MAX_DISTANCE`).
161
- * @param forceDirection Optional, the direction to force the scroll (`FocusDirection`). If not provided, the default scroll direction is calculated.
162
- * @param forceDuration Optional, a custom duration (in milliseconds) for the smooth scroll. If not provided, a default duration is used.
163
- * @param forceNormalContainerHeight Optional, a flag indicating whether to force the container height calculation for normal behavior.
164
- * @param onComplete Optional callback function that is triggered when the scroll operation completes.
165
- *
166
- * @example
167
- * fastSmoothScroll(container, element, 'centerOrTop', 10, 500, FocusDirection.Up, 300);
168
- *
169
- * @group Scrolling
170
- */
171
- declare function fastSmoothScroll(container: HTMLElement, element: HTMLElement, position: ScrollLogicalPosition | 'centerOrTop', margin?: number, maxDistance?: number, forceDirection?: FocusDirection, forceDuration?: number, forceNormalContainerHeight?: boolean, onComplete?: ScrollCompleteCallback): void;
172
-
173
- /**
174
- * Determines if the specified element or the document/window is scrolled near the bottom.
175
- *
176
- * This function checks if the scroll position has reached the bottom of the target element or window
177
- * within a specified threshold. It is commonly used for implementing "infinite scroll" or detecting
178
- * when a user has scrolled to the bottom of a page or container.
179
- *
180
- * @param target The target element, document, or window to check the scroll position.
181
- * Can be an `HTMLElement`, `Document`, or `Window`.
182
- * @param threshold The threshold (in pixels) below which the target is considered "scrolled to the bottom."
183
- * Default is `10`, meaning the target is considered scrolled to the bottom if it is within 10px of the bottom.
184
- *
185
- * @returns `true` if the target is scrolled near the bottom within the given threshold, otherwise `false`.
186
- *
187
- * @example
188
- * // Check if the window is scrolled near the bottom
189
- * isScrolledToDown(window, 20); // Returns true if within 20px of the bottom of the window.
190
- *
191
- * @example
192
- * // Check if a specific container is scrolled near the bottom
193
- * const container = document.getElementById('myContainer');
194
- * isScrolledToDown(container, 50); // Returns true if within 50px of the bottom of the container.
195
- *
196
- * @group Scrolling
197
- */
198
- declare function isScrolledToDown(target: HTMLElement | Document | Window, threshold?: number): boolean;
199
-
200
- /**
201
- * Resets the scroll position of the specified container element.
202
- *
203
- * If a `scrollTop` value is provided, the container's scroll position is set
204
- * to that value. Otherwise, the function will leave the scroll position unchanged.
205
- * This function is useful for resetting the scroll state in a container, such as
206
- * when the content changes or after an animation.
207
- *
208
- * @param container The container element whose scroll position needs to be reset.
209
- * @param scrollTop Optional value to set the container's `scrollTop`. If not provided, the scroll position remains unchanged.
210
- *
211
- * @example
212
- * resetScroll(container, 0); // Resets scroll to top of the container.
213
- * resetScroll(container); // Resets scroll position without changing it.
214
- *
215
- * @group Scrolling
216
- */
217
- declare function resetScroll(container: HTMLDivElement, scrollTop?: number): void;
218
-
219
- export { type AnimateNumberProps, FAST_SMOOTH_MAX_DISTANCE, FAST_SMOOTH_MAX_DURATION, FAST_SMOOTH_MIN_DURATION, FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE, FocusDirection, type ScrollCompleteCallback, type TimingFn, animate, animateInstantly, animateNumber, animateSingle, copyTextToClipboard, fastSmoothScroll, isScrolledToDown, resetScroll, timingFunctions };