stick-n-roll 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 devashtar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.MD ADDED
@@ -0,0 +1,94 @@
1
+ **`stick-n-roll`** is a lightweight and user-friendly npm package that enables HTML elements to have functionality similar to position: sticky, with the added ability to scroll the block.
2
+
3
+ **Key Features**:
4
+ - **Easy Integration**: Simply install the package and add a few lines of code to activate the functionality.
5
+ - **Block Scrolling**: Unlike standard position: sticky, sticky-scroll allows the block to scroll while maintaining its "stickiness" as the user scrolls the page.
6
+ - **Customizable Options**: Easily configure the block's behavior with parameters such as `spaceBottom`, `spaceTop` to add margins and default `position` for `target` element.
7
+ - **Cross-Browser Support**: The package works seamlessly across all modern browsers, ensuring consistent behavior on different platforms.
8
+ - **Simplicity of Use**: Minimal code required for setup, providing maximum flexibility in usage.
9
+
10
+
11
+ ## Table of contents
12
+
13
+ - [Installing](#installing)
14
+ - [Using](#using)
15
+ - [Links](#links)
16
+ - [Copyright and license](#copyright-and-license)
17
+
18
+ ## Installing
19
+ ```sh
20
+ npm install --save-dev stick-n-roll
21
+ ```
22
+
23
+ ## Using
24
+
25
+ ### HTML example
26
+ ```html
27
+ <body>
28
+ <h1>Example</h1>
29
+ <main>
30
+ <aside id="container">
31
+ <div id="target-element">Sidebar content...</div>
32
+ </aside>
33
+ <section>
34
+ ...
35
+ </section>
36
+ </main>
37
+ <script>
38
+ const StickNRoll = require('stick-n-roll');
39
+ const container = document.getElementById('container');
40
+ const targetElement = document.getElementById('target-element');
41
+ const stickNRoll = new StickNRoll(container, targetElement, { spaceBottom: 8, spaceTop: 64 });
42
+ stickNRoll.enable();
43
+ </script>
44
+ </body>
45
+ ```
46
+
47
+ ### Native javascript
48
+
49
+ ```js
50
+ const StickNRoll = require('stick-n-roll');
51
+ const container = document.getElementById('container');
52
+ const targetElement = document.getElementById('target-element');
53
+ const stickNRoll = new StickNRoll(container, targetElement, { spaceBottom: 8, spaceTop: 64, position: 'relative' });
54
+ stickNRoll.enable(); // start
55
+ // stickNRoll.updateSpaces({ spaceTop: 96, spaceBottom: 16, }); // Change spaces dynamically
56
+ // stickNRoll.disable(); // disable listeners and stop running. You can start it again with help "enable()".
57
+ ```
58
+
59
+ ### React ts
60
+
61
+ ```ts
62
+ import StickNRoll from 'stick-n-roll';
63
+
64
+ // ...
65
+ const ref = React.useRef<StickNRoll>(new StickNRoll(containerRef, targetElementRef, { spaceBottom: 8, spaceTop: 64 }));
66
+
67
+ React.useEffect(() => {
68
+ if (ref.current) {
69
+ ref.current.enable(); // add listeners
70
+ return () => {
71
+ ref.current.disable(); // delete listeners
72
+ };
73
+ }
74
+ }, []);
75
+ // ...
76
+ ```
77
+
78
+ ## Links
79
+
80
+ - [DOM](https://developer.mozilla.org/en-US/docs/Glossary/DOM)
81
+ - [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement)
82
+ - [dimensions of elements](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements)
83
+ - [coordinate systems](https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems)
84
+ - [viewport](https://developer.mozilla.org/en-US/docs/Glossary/Viewport)
85
+ - [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position)
86
+ - [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
87
+ - [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame)
88
+ - [resizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
89
+ - [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
90
+ - [removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener)
91
+
92
+ ## Copyright and license
93
+
94
+ Code copyright 2025 the [author](https://github.com/devashtar). Code released under the [MIT License](./README.MD).
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Options type.
3
+ */
4
+ type OptionsType = {
5
+ /**
6
+ * The space between bottom of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and bottom of the `visible area`.
7
+ * @default 0
8
+ */
9
+ spaceBottom?: number;
10
+ /**
11
+ * The space between top of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and top of the `visible area`.
12
+ * @default 0
13
+ */
14
+ spaceTop?: number;
15
+ /**
16
+ * Default {@link https://developer.mozilla.org/en-US/docs/Web/CSS/position|position} for the target `element`.
17
+ * @default ''
18
+ */
19
+ position?: CSSStyleDeclaration['position'];
20
+ };
21
+ /**
22
+ * Helps to give an element sticky scrolling capability.
23
+ */
24
+ declare class StickNRoll {
25
+ /**
26
+ * Parent element of target {@link element}.
27
+ */
28
+ private container;
29
+ /**
30
+ * Target element with sticky and scroll abilities.
31
+ */
32
+ private element;
33
+ /**
34
+ * Triggered Event.
35
+ */
36
+ private events;
37
+ /**
38
+ * Indicates that a render request has already been initiated.
39
+ * @default false
40
+ */
41
+ private isRunningRequest;
42
+ /**
43
+ * The Current Y-axis coordinates relative to the {@link container}.
44
+ */
45
+ private translateY;
46
+ /**
47
+ * The maximum allowed Y-axis coordinates relative to the {@link container}.
48
+ */
49
+ private maxTranslateY;
50
+ /**
51
+ * Previous element height.
52
+ */
53
+ private prevElementHeight;
54
+ /**
55
+ * Height of the {@link container}.
56
+ */
57
+ private containerHeight;
58
+ /**
59
+ * Width of the {@link container}.
60
+ */
61
+ private containerWidth;
62
+ /**
63
+ * Coordinate by X-axis of the {@link container}.
64
+ */
65
+ private containerLeft;
66
+ /**
67
+ * Coordinate by Y-axis of the {@link container}.
68
+ */
69
+ private containerTop;
70
+ /**
71
+ * Previous width of the {@link container}.
72
+ */
73
+ private prevContainerWidth;
74
+ /**
75
+ * Previous coordinate by X-axis of the {@link container}.
76
+ */
77
+ private prevContainerLeft;
78
+ /**
79
+ * Previous coordinate by Y-axis of the {@link container}.
80
+ */
81
+ private prevContainerTop;
82
+ /**
83
+ * Height of the {@link collider}.
84
+ */
85
+ private colliderHeight;
86
+ /**
87
+ * Top coordinate of the {@link collider}.
88
+ */
89
+ private colliderTop;
90
+ /**
91
+ * Previous coordinate by X-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.
92
+ */
93
+ private prevViewportScrollX;
94
+ /**
95
+ * Previous coordinate by Y-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.
96
+ */
97
+ private prevViewportScrollY;
98
+ /**
99
+ * Space top.
100
+ * @default 0
101
+ */
102
+ private spaceTop;
103
+ /**
104
+ * Space bottom.
105
+ * @default 0
106
+ */
107
+ private spaceBottom;
108
+ /**
109
+ * Resize observer.
110
+ */
111
+ private resizeObserver;
112
+ /**
113
+ * Current strategy. Helps to detect element behaviour.
114
+ * @default Strategy.None
115
+ */
116
+ private strategy;
117
+ /**
118
+ * Previous strategy.
119
+ * @default Strategy.None
120
+ */
121
+ private prevStrategy;
122
+ /**
123
+ * Previous state.
124
+ * @default Variant.None
125
+ */
126
+ private prevState;
127
+ /**
128
+ * List of available CSS properties.
129
+ */
130
+ private listOfRules;
131
+ /**
132
+ * List of css properties to be updated.
133
+ */
134
+ private rules;
135
+ /**
136
+ * @param {HTMLElement} container - The parent element ({@link container}) of {@link element}.
137
+ * @param {HTMLElement} element - The target {@link element} which will be endowed with stickiness and scrolling abilities relative to its parent element ({@link container}).
138
+ */
139
+ constructor(container: HTMLElement, element: HTMLElement, options?: OptionsType);
140
+ /**
141
+ * Enable sticky scrolling capability. Use {@link disable} method to deactivate sticky scrolling capability.
142
+ */
143
+ enable(): void;
144
+ /**
145
+ * Disable sticky scrolling capability. Use {@link enable} method to activate sticky scrolling capability again.
146
+ */
147
+ disable(): void;
148
+ /**
149
+ * Update {@link spaceBottom} and {@link spaceTop}. It fires the render after changes of spaces.
150
+ */
151
+ updateSpaces(spaces: Pick<OptionsType, 'spaceBottom' | 'spaceTop'>): void;
152
+ /**
153
+ * Resize listener.
154
+ */
155
+ private _resizeListener;
156
+ /**
157
+ * Scroll listener.
158
+ */
159
+ private _scrollListener;
160
+ /**
161
+ * Get coordinates for passed element.
162
+ */
163
+ private _getCoords;
164
+ /**
165
+ * Update styles in target {@link element} and {@link container}.
166
+ */
167
+ private _render;
168
+ /**
169
+ * Get the scroll direction. `None` for horizontal scrolling or no scrolling.
170
+ */
171
+ private _getDirection;
172
+ /**
173
+ * Get state of target element.
174
+ */
175
+ private _getState;
176
+ /**
177
+ * Get a {@link strategy} that determines the further behavior of the target {@link element}.
178
+ */
179
+ private _getStrategy;
180
+ /**
181
+ * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements|dimensions}.
182
+ */
183
+ private _calcDims;
184
+ /**
185
+ * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems|coordinates}.
186
+ */
187
+ private _calcScroll;
188
+ /**
189
+ * Helps apply DOM manipulation and synchronize processing with rendering. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame|requestAnimationFrame}.
190
+ */
191
+ private _request;
192
+ /**
193
+ * Observe {@link https://developer.mozilla.org/en-US/docs/Web/API/Node|nodes} from target {@link element} to {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body|document body} with help the {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
194
+ */
195
+ private _observeTreeNodesFromCurrentToBody;
196
+ /**
197
+ * Add required event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener|addEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
198
+ */
199
+ private _addListeners;
200
+ /**
201
+ * Remove all event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener|removeEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
202
+ */
203
+ private _removeListeners;
204
+ }
205
+
206
+ export { StickNRoll, StickNRoll as default };
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Options type.
3
+ */
4
+ type OptionsType = {
5
+ /**
6
+ * The space between bottom of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and bottom of the `visible area`.
7
+ * @default 0
8
+ */
9
+ spaceBottom?: number;
10
+ /**
11
+ * The space between top of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and top of the `visible area`.
12
+ * @default 0
13
+ */
14
+ spaceTop?: number;
15
+ /**
16
+ * Default {@link https://developer.mozilla.org/en-US/docs/Web/CSS/position|position} for the target `element`.
17
+ * @default ''
18
+ */
19
+ position?: CSSStyleDeclaration['position'];
20
+ };
21
+ /**
22
+ * Helps to give an element sticky scrolling capability.
23
+ */
24
+ declare class StickNRoll {
25
+ /**
26
+ * Parent element of target {@link element}.
27
+ */
28
+ private container;
29
+ /**
30
+ * Target element with sticky and scroll abilities.
31
+ */
32
+ private element;
33
+ /**
34
+ * Triggered Event.
35
+ */
36
+ private events;
37
+ /**
38
+ * Indicates that a render request has already been initiated.
39
+ * @default false
40
+ */
41
+ private isRunningRequest;
42
+ /**
43
+ * The Current Y-axis coordinates relative to the {@link container}.
44
+ */
45
+ private translateY;
46
+ /**
47
+ * The maximum allowed Y-axis coordinates relative to the {@link container}.
48
+ */
49
+ private maxTranslateY;
50
+ /**
51
+ * Previous element height.
52
+ */
53
+ private prevElementHeight;
54
+ /**
55
+ * Height of the {@link container}.
56
+ */
57
+ private containerHeight;
58
+ /**
59
+ * Width of the {@link container}.
60
+ */
61
+ private containerWidth;
62
+ /**
63
+ * Coordinate by X-axis of the {@link container}.
64
+ */
65
+ private containerLeft;
66
+ /**
67
+ * Coordinate by Y-axis of the {@link container}.
68
+ */
69
+ private containerTop;
70
+ /**
71
+ * Previous width of the {@link container}.
72
+ */
73
+ private prevContainerWidth;
74
+ /**
75
+ * Previous coordinate by X-axis of the {@link container}.
76
+ */
77
+ private prevContainerLeft;
78
+ /**
79
+ * Previous coordinate by Y-axis of the {@link container}.
80
+ */
81
+ private prevContainerTop;
82
+ /**
83
+ * Height of the {@link collider}.
84
+ */
85
+ private colliderHeight;
86
+ /**
87
+ * Top coordinate of the {@link collider}.
88
+ */
89
+ private colliderTop;
90
+ /**
91
+ * Previous coordinate by X-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.
92
+ */
93
+ private prevViewportScrollX;
94
+ /**
95
+ * Previous coordinate by Y-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.
96
+ */
97
+ private prevViewportScrollY;
98
+ /**
99
+ * Space top.
100
+ * @default 0
101
+ */
102
+ private spaceTop;
103
+ /**
104
+ * Space bottom.
105
+ * @default 0
106
+ */
107
+ private spaceBottom;
108
+ /**
109
+ * Resize observer.
110
+ */
111
+ private resizeObserver;
112
+ /**
113
+ * Current strategy. Helps to detect element behaviour.
114
+ * @default Strategy.None
115
+ */
116
+ private strategy;
117
+ /**
118
+ * Previous strategy.
119
+ * @default Strategy.None
120
+ */
121
+ private prevStrategy;
122
+ /**
123
+ * Previous state.
124
+ * @default Variant.None
125
+ */
126
+ private prevState;
127
+ /**
128
+ * List of available CSS properties.
129
+ */
130
+ private listOfRules;
131
+ /**
132
+ * List of css properties to be updated.
133
+ */
134
+ private rules;
135
+ /**
136
+ * @param {HTMLElement} container - The parent element ({@link container}) of {@link element}.
137
+ * @param {HTMLElement} element - The target {@link element} which will be endowed with stickiness and scrolling abilities relative to its parent element ({@link container}).
138
+ */
139
+ constructor(container: HTMLElement, element: HTMLElement, options?: OptionsType);
140
+ /**
141
+ * Enable sticky scrolling capability. Use {@link disable} method to deactivate sticky scrolling capability.
142
+ */
143
+ enable(): void;
144
+ /**
145
+ * Disable sticky scrolling capability. Use {@link enable} method to activate sticky scrolling capability again.
146
+ */
147
+ disable(): void;
148
+ /**
149
+ * Update {@link spaceBottom} and {@link spaceTop}. It fires the render after changes of spaces.
150
+ */
151
+ updateSpaces(spaces: Pick<OptionsType, 'spaceBottom' | 'spaceTop'>): void;
152
+ /**
153
+ * Resize listener.
154
+ */
155
+ private _resizeListener;
156
+ /**
157
+ * Scroll listener.
158
+ */
159
+ private _scrollListener;
160
+ /**
161
+ * Get coordinates for passed element.
162
+ */
163
+ private _getCoords;
164
+ /**
165
+ * Update styles in target {@link element} and {@link container}.
166
+ */
167
+ private _render;
168
+ /**
169
+ * Get the scroll direction. `None` for horizontal scrolling or no scrolling.
170
+ */
171
+ private _getDirection;
172
+ /**
173
+ * Get state of target element.
174
+ */
175
+ private _getState;
176
+ /**
177
+ * Get a {@link strategy} that determines the further behavior of the target {@link element}.
178
+ */
179
+ private _getStrategy;
180
+ /**
181
+ * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements|dimensions}.
182
+ */
183
+ private _calcDims;
184
+ /**
185
+ * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems|coordinates}.
186
+ */
187
+ private _calcScroll;
188
+ /**
189
+ * Helps apply DOM manipulation and synchronize processing with rendering. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame|requestAnimationFrame}.
190
+ */
191
+ private _request;
192
+ /**
193
+ * Observe {@link https://developer.mozilla.org/en-US/docs/Web/API/Node|nodes} from target {@link element} to {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body|document body} with help the {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
194
+ */
195
+ private _observeTreeNodesFromCurrentToBody;
196
+ /**
197
+ * Add required event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener|addEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
198
+ */
199
+ private _addListeners;
200
+ /**
201
+ * Remove all event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener|removeEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.
202
+ */
203
+ private _removeListeners;
204
+ }
205
+
206
+ export { StickNRoll, StickNRoll as default };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(i,t)=>{for(var e in t)n(i,e,{get:t[e],enumerable:!0})},c=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of h(t))!l.call(i,s)&&s!==e&&n(i,s,{get:()=>t[s],enumerable:!(r=a(t,s))||r.enumerable});return i};var v=i=>c(n({},"__esModule",{value:!0}),i);var d={};p(d,{StickNRoll:()=>o,default:()=>f});module.exports=v(d);var o=class{container;element;events;isRunningRequest;translateY;maxTranslateY;prevElementHeight;containerHeight;containerWidth;containerLeft;containerTop;prevContainerWidth;prevContainerLeft;prevContainerTop;colliderHeight;colliderTop;prevViewportScrollX;prevViewportScrollY;spaceTop;spaceBottom;resizeObserver;strategy;prevStrategy;prevState;listOfRules;rules;constructor(t,e,r){this.container=t,this.element=e,this.isRunningRequest=!1,this.colliderHeight=0,this.colliderTop=0,this.containerHeight=0,this.containerWidth=0,this.containerLeft=0,this.containerTop=0,this.prevContainerWidth=0,this.prevContainerLeft=0,this.prevContainerTop=0,this.prevElementHeight=0,this.maxTranslateY=0,this.translateY=0,this.prevViewportScrollX=0,this.prevViewportScrollY=0,this.events=[0,0],this.strategy=1,this.prevStrategy=1,this.prevState=3,this.listOfRules={width:"",left:"",top:"",position:r?.position??"",transform:""},this.rules={},this.spaceBottom=r?.spaceBottom??0,this.spaceTop=r?.spaceTop??0,this._calcDims=this._calcDims.bind(this),this._calcScroll=this._calcScroll.bind(this),this._resizeListener=this._resizeListener.bind(this),this._scrollListener=this._scrollListener.bind(this),this.resizeObserver=new ResizeObserver(this._resizeListener)}enable(){this._addListeners()}disable(){this._removeListeners(),this.isRunningRequest=!1,this.events.fill(0)}updateSpaces(t){this.spaceBottom=t.spaceBottom??0,this.spaceTop=t.spaceTop??0,this._resizeListener()}_resizeListener(){this.events[0]===0&&(this.events[0]=1),this._request()}_scrollListener(){this.events[1]===0&&(this.events[1]=2),this._request()}_getCoords(t){let e={left:t.offsetLeft,top:t.offsetTop};for(;t=t.tagName==="BODY"?t.parentElement:t.offsetParent;)e.top+=t.offsetTop,e.left+=t.offsetLeft;return e}_render(t){t===0?(this.translateY=this.maxTranslateY,this.rules={top:this.spaceTop+"px",left:"0px",position:"sticky",width:this.container.clientWidth+"px"}):t===2?(this.translateY=0,this.rules={top:this.colliderHeight+this.spaceTop-this.element.offsetHeight+"px",left:this.containerLeft-window.scrollX+"px",position:"fixed",width:this.container.clientWidth+"px"}):t===1?(this.translateY=0,this.rules={top:this.spaceTop+"px",left:this.containerLeft-window.scrollX+"px",position:"fixed",width:this.container.clientWidth+"px"}):t===3?(this.translateY=0,this.rules={}):t===4&&(this.prevState===1?this.translateY=this.colliderTop-this.containerTop:this.prevState===2?this.translateY=this.colliderTop+this.colliderHeight-this.containerTop-this.prevElementHeight:this.prevState===0&&(this.translateY=this.containerHeight-this.element.offsetHeight),this.rules={position:"relative",transform:`translate3d(0px, ${this.translateY}px, 0px)`}),this.container.style.position=t===0?"relative":"";for(let e in this.listOfRules)this.element.style[e]=this.rules[e]??this.listOfRules[e]}_getDirection(){return this.prevViewportScrollY===window.scrollY?1:this.prevViewportScrollY<window.scrollY?0:2}_getState(t){if(this.prevState===1){if(this.colliderTop<=this.containerTop)return 3;if(this.colliderTop+this.element.offsetHeight>=this.containerTop+this.containerHeight)return 0;if(this.prevStrategy===2&&this.element.offsetHeight>this.colliderHeight)return this.prevStrategy=this.strategy,4;if(this.strategy===0&&t===0)return 4;if(this.prevViewportScrollX!==window.scrollX||this.prevContainerLeft!==this.containerLeft||this.prevContainerWidth!==this.containerWidth||this.prevContainerTop!==this.containerTop)return 1}else if(this.prevState===2){if(this.colliderTop<=this.containerTop)return 3;if(this.colliderTop+this.colliderHeight>=this.containerTop+this.containerHeight)return 0;if(this.element.offsetHeight<=this.colliderHeight)return 1;if(t===2||this.prevElementHeight!==this.element.offsetHeight)return 4;if(this.prevViewportScrollX!==window.scrollX||this.prevContainerLeft!==this.containerLeft||this.prevContainerWidth!==this.containerWidth||this.prevContainerTop!==this.containerTop)return 2}else if(this.prevState===0){if(this.colliderTop<=this.containerTop)return 3;if(t===2&&this.colliderTop<=this.containerTop+this.maxTranslateY||this.element.offsetHeight<this.containerTop+this.containerHeight-this.colliderTop)return 1;if(this.prevContainerWidth!==this.containerWidth)return 0}else if(this.prevState===3){if(this.colliderTop+this.element.offsetHeight>=this.containerTop+this.containerHeight)return 0;if(this.element.offsetHeight<this.colliderHeight&&this.colliderTop>=this.containerTop)return 1;if(this.strategy===0&&this.colliderTop+this.colliderHeight>=this.containerTop+this.element.offsetHeight)return 2}else if(this.prevState===4){if(this.containerHeight-this.translateY<this.element.offsetHeight)return 0;if(this.element.offsetHeight<this.colliderHeight||this.colliderTop<=this.containerTop+this.translateY)return 1;if(this.translateY<this.maxTranslateY&&this.colliderTop+this.colliderHeight>this.containerTop+this.translateY+this.element.offsetHeight)return 2}return 5}_getStrategy(){return this.containerHeight<=this.element.offsetHeight?1:this.colliderHeight<this.element.offsetHeight?0:2}_calcDims(){let t=this._getCoords(this.container);this.containerLeft=t.left,this.containerTop=t.top,this.containerHeight=this.container.clientHeight,this.containerWidth=this.container.clientWidth,this.colliderHeight=window.innerHeight-this.spaceTop-this.spaceBottom,this.maxTranslateY=this.container.clientHeight-this.element.offsetHeight,this.strategy=this._getStrategy(),this.strategy===1?this.prevStrategy!==this.strategy&&this._render(3):this._calcScroll(),this.prevContainerWidth=this.containerWidth,this.prevContainerLeft=this.containerLeft,this.prevContainerTop=this.containerTop,this.prevElementHeight=this.element.offsetHeight,this.prevStrategy=this.strategy}_calcScroll(){this.colliderTop=window.scrollY+this.spaceTop;let t=this._getState(this._getDirection());t!==5&&(this._render(t),this.prevState=t),this.prevViewportScrollX=window.scrollX,this.prevViewportScrollY=window.scrollY}_request(){this.isRunningRequest||(this.isRunningRequest=!0,window.requestAnimationFrame(()=>{this.events[0]===1?(this.events[0]=0,this._calcDims()):this.events[1]===2&&(this.events[1]=0,this._calcScroll()),this.isRunningRequest=!1}))}_observeTreeNodesFromCurrentToBody(t){for(;t&&(this.resizeObserver.observe(t),t.tagName!=="BODY");)t=t.parentElement}_addListeners(){window.addEventListener("scroll",this._scrollListener,{capture:!1,passive:!0}),this._observeTreeNodesFromCurrentToBody(this.element)}_removeListeners(){window.removeEventListener("scroll",this._scrollListener,{capture:!1}),this.resizeObserver.disconnect()}},f=o;0&&(module.exports={StickNRoll});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Options type.\n */\ntype OptionsType = {\n /**\n * The space between bottom of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and bottom of the `visible area`.\n * @default 0\n */\n spaceBottom?: number;\n /**\n * The space between top of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and top of the `visible area`.\n * @default 0\n */\n spaceTop?: number;\n /**\n * Default {@link https://developer.mozilla.org/en-US/docs/Web/CSS/position|position} for the target `element`.\n * @default ''\n */\n position?: CSSStyleDeclaration['position'];\n};\n\n/**\n * The element coordinates.\n */\ntype TypeElementCoords = {\n left: number;\n top: number;\n};\n\n/**\n * Indexes of events in the events array.\n */\nenum Item {\n Resize = 0,\n Scroll = 1,\n}\n\nenum Event {\n None,\n Resize,\n Scroll,\n}\n\n/**\n * Defines `viewport` direction.\n */\nenum Direction {\n Down,\n None,\n Up,\n}\n\n/**\n * Strategy.\n */\nenum Strategy {\n /**\n * Sticky both sides by Y-axis.\n */\n Both,\n /**\n * Nothing do.\n */\n None,\n /**\n * Sticky only top side.\n */\n Top,\n}\n\n/**\n * @enum {number} Position variant of target `element`.\n */\nenum State {\n /**\n * Element affixed at the bottom of the container.\n */\n ContainerBottom,\n /**\n * Element fixed at the top of the window viewport area (including top padding).\n */\n ColliderTop,\n /**\n * Element fixed at the bottom of the window viewport area (including bottom padding).\n */\n ColliderBottom,\n /**\n * Default element behavior. Case without specific rules.\n */\n None,\n /**\n * The element is offset along the Y axis relative to the container.\n */\n TranslateY,\n /**\n * Indicates that rendering should be skipped until the state changes.\n */\n Rest,\n}\n\ntype Rules = Pick<CSSStyleDeclaration, 'width' | 'left' | 'top' | 'position' | 'transform'>;\n\n/**\n * Helps to give an element sticky scrolling capability.\n */\nexport class StickNRoll {\n /**\n * Parent element of target {@link element}.\n */\n private container: HTMLElement;\n\n /**\n * Target element with sticky and scroll abilities.\n */\n private element: HTMLElement;\n\n /**\n * Triggered Event.\n */\n private events: [Event.Resize | Event.None, Event.Scroll | Event.None];\n\n /**\n * Indicates that a render request has already been initiated.\n * @default false\n */\n private isRunningRequest: boolean;\n\n /**\n * The Current Y-axis coordinates relative to the {@link container}.\n */\n private translateY: number;\n\n /**\n * The maximum allowed Y-axis coordinates relative to the {@link container}.\n */\n private maxTranslateY: number;\n\n /**\n * Previous element height.\n */\n private prevElementHeight: number;\n\n /**\n * Height of the {@link container}.\n */\n private containerHeight: number;\n\n /**\n * Width of the {@link container}.\n */\n private containerWidth: number;\n\n /**\n * Coordinate by X-axis of the {@link container}.\n */\n private containerLeft: number;\n\n /**\n * Coordinate by Y-axis of the {@link container}.\n */\n private containerTop: number;\n\n /**\n * Previous width of the {@link container}.\n */\n private prevContainerWidth: number;\n\n /**\n * Previous coordinate by X-axis of the {@link container}.\n */\n private prevContainerLeft: number;\n\n /**\n * Previous coordinate by Y-axis of the {@link container}.\n */\n private prevContainerTop: number;\n\n /**\n * Height of the {@link collider}.\n */\n private colliderHeight: number;\n\n /**\n * Top coordinate of the {@link collider}.\n */\n private colliderTop: number;\n\n /**\n * Previous coordinate by X-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.\n */\n private prevViewportScrollX: number;\n\n /**\n * Previous coordinate by Y-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.\n */\n private prevViewportScrollY: number;\n\n /**\n * Space top.\n * @default 0\n */\n private spaceTop: number;\n\n /**\n * Space bottom.\n * @default 0\n */\n private spaceBottom: number;\n\n /**\n * Resize observer.\n */\n private resizeObserver: ResizeObserver;\n\n /**\n * Current strategy. Helps to detect element behaviour.\n * @default Strategy.None\n */\n private strategy: Strategy;\n\n /**\n * Previous strategy.\n * @default Strategy.None\n */\n private prevStrategy: Strategy;\n\n /**\n * Previous state.\n * @default Variant.None\n */\n private prevState: State;\n\n /**\n * List of available CSS properties.\n */\n private listOfRules: Rules;\n\n /**\n * List of css properties to be updated.\n */\n private rules: Partial<Rules>;\n\n /**\n * @param {HTMLElement} container - The parent element ({@link container}) of {@link element}.\n * @param {HTMLElement} element - The target {@link element} which will be endowed with stickiness and scrolling abilities relative to its parent element ({@link container}).\n */\n constructor(container: HTMLElement, element: HTMLElement, options?: OptionsType) {\n this.container = container;\n this.element = element;\n\n this.isRunningRequest = false;\n\n this.colliderHeight = 0;\n this.colliderTop = 0;\n\n this.containerHeight = 0;\n this.containerWidth = 0;\n this.containerLeft = 0;\n this.containerTop = 0;\n this.prevContainerWidth = 0;\n this.prevContainerLeft = 0;\n this.prevContainerTop = 0;\n\n this.prevElementHeight = 0;\n\n this.maxTranslateY = 0;\n this.translateY = 0;\n\n this.prevViewportScrollX = 0;\n this.prevViewportScrollY = 0;\n\n this.events = [Event.None, Event.None];\n\n this.strategy = Strategy.None;\n this.prevStrategy = Strategy.None;\n\n this.prevState = State.None;\n\n this.listOfRules = { width: '', left: '', top: '', position: options?.position ?? '', transform: '' };\n this.rules = {};\n\n this.spaceBottom = options?.spaceBottom ?? 0;\n this.spaceTop = options?.spaceTop ?? 0;\n\n // Binds \"this\" context to the following class methods.\n this._calcDims = this._calcDims.bind(this);\n this._calcScroll = this._calcScroll.bind(this);\n this._resizeListener = this._resizeListener.bind(this);\n this._scrollListener = this._scrollListener.bind(this);\n\n // Create resize observer.\n this.resizeObserver = new ResizeObserver(this._resizeListener);\n }\n\n /**\n * Enable sticky scrolling capability. Use {@link disable} method to deactivate sticky scrolling capability.\n */\n public enable(): void {\n this._addListeners(); // calls _calcDims method by default, cause is used ResizeObserver\n }\n\n /**\n * Disable sticky scrolling capability. Use {@link enable} method to activate sticky scrolling capability again.\n */\n public disable(): void {\n this._removeListeners();\n this.isRunningRequest = false;\n this.events.fill(Event.None);\n }\n\n /**\n * Update {@link spaceBottom} and {@link spaceTop}. It fires the render after changes of spaces.\n */\n public updateSpaces(spaces: Pick<OptionsType, 'spaceBottom' | 'spaceTop'>): void {\n this.spaceBottom = spaces.spaceBottom ?? 0;\n this.spaceTop = spaces.spaceTop ?? 0;\n this._resizeListener();\n }\n\n /**\n * Resize listener.\n */\n private _resizeListener(): void {\n if (this.events[Item.Resize] === Event.None) this.events[Item.Resize] = Event.Resize;\n this._request();\n }\n\n /**\n * Scroll listener.\n */\n private _scrollListener(): void {\n if (this.events[Item.Scroll] === Event.None) this.events[Item.Scroll] = Event.Scroll;\n this._request();\n }\n\n /**\n * Get coordinates for passed element.\n */\n private _getCoords(element: HTMLElement): TypeElementCoords {\n const coords = { left: element.offsetLeft, top: element.offsetTop };\n while (((element as unknown) = 'BODY' === element.tagName ? element.parentElement : element.offsetParent)) {\n coords.top += element.offsetTop;\n coords.left += element.offsetLeft;\n }\n return coords;\n }\n\n /**\n * Update styles in target {@link element} and {@link container}.\n */\n private _render(state: State): void {\n if (state === State.ContainerBottom) {\n this.translateY = this.maxTranslateY;\n this.rules = {\n top: this.spaceTop + 'px',\n left: '0px',\n position: 'sticky',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.ColliderBottom) {\n this.translateY = 0;\n this.rules = {\n top: this.colliderHeight + this.spaceTop - this.element.offsetHeight + 'px',\n left: this.containerLeft - window.scrollX + 'px',\n position: 'fixed',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.ColliderTop) {\n this.translateY = 0;\n this.rules = {\n top: this.spaceTop + 'px',\n left: this.containerLeft - window.scrollX + 'px',\n position: 'fixed',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.None) {\n this.translateY = 0;\n this.rules = {};\n } else if (state === State.TranslateY) {\n if (this.prevState === State.ColliderTop) {\n this.translateY = this.colliderTop - this.containerTop;\n } else if (this.prevState === State.ColliderBottom) {\n this.translateY = this.colliderTop + this.colliderHeight - this.containerTop - this.prevElementHeight;\n } else if (this.prevState === State.ContainerBottom) {\n this.translateY = this.containerHeight - this.element.offsetHeight;\n }\n this.rules = { position: 'relative', transform: `translate3d(0px, ${this.translateY}px, 0px)` };\n }\n\n this.container.style.position = state === State.ContainerBottom ? 'relative' : '';\n\n for (const key in this.listOfRules) {\n this.element.style[key as keyof Rules] =\n this.rules[key as unknown as keyof Rules] ?? this.listOfRules[key as unknown as keyof Rules];\n }\n }\n\n /**\n * Get the scroll direction. `None` for horizontal scrolling or no scrolling.\n */\n private _getDirection(): Direction {\n if (this.prevViewportScrollY === window.scrollY) return Direction.None;\n return this.prevViewportScrollY < window.scrollY ? Direction.Down : Direction.Up;\n }\n\n /**\n * Get state of target element.\n */\n private _getState(direction: Direction): State {\n if (this.prevState === State.ColliderTop) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (this.colliderTop + this.element.offsetHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.prevStrategy === Strategy.Top && this.element.offsetHeight > this.colliderHeight) {\n this.prevStrategy = this.strategy;\n return State.TranslateY;\n }\n if (this.strategy === Strategy.Both && direction === Direction.Down) {\n return State.TranslateY;\n }\n if (\n this.prevViewportScrollX !== window.scrollX ||\n this.prevContainerLeft !== this.containerLeft ||\n this.prevContainerWidth !== this.containerWidth ||\n this.prevContainerTop !== this.containerTop\n ) {\n return State.ColliderTop;\n }\n } else if (this.prevState === State.ColliderBottom) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (this.colliderTop + this.colliderHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight <= this.colliderHeight) {\n return State.ColliderTop;\n }\n if (direction === Direction.Up || this.prevElementHeight !== this.element.offsetHeight) {\n return State.TranslateY;\n }\n if (\n this.prevViewportScrollX !== window.scrollX ||\n this.prevContainerLeft !== this.containerLeft ||\n this.prevContainerWidth !== this.containerWidth ||\n this.prevContainerTop !== this.containerTop\n ) {\n return State.ColliderBottom;\n }\n } else if (this.prevState === State.ContainerBottom) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (direction === Direction.Up && this.colliderTop <= this.containerTop + this.maxTranslateY) {\n return State.ColliderTop;\n }\n if (this.element.offsetHeight < this.containerTop + this.containerHeight - this.colliderTop) {\n return State.ColliderTop;\n }\n if (this.prevContainerWidth !== this.containerWidth) {\n return State.ContainerBottom;\n }\n } else if (this.prevState === State.None) {\n if (this.colliderTop + this.element.offsetHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight < this.colliderHeight && this.colliderTop >= this.containerTop) {\n return State.ColliderTop;\n }\n if (\n this.strategy === Strategy.Both &&\n this.colliderTop + this.colliderHeight >= this.containerTop + this.element.offsetHeight\n ) {\n return State.ColliderBottom;\n }\n } else if (this.prevState === State.TranslateY) {\n if (this.containerHeight - this.translateY < this.element.offsetHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight < this.colliderHeight || this.colliderTop <= this.containerTop + this.translateY) {\n return State.ColliderTop;\n }\n if (\n this.translateY < this.maxTranslateY &&\n this.colliderTop + this.colliderHeight > this.containerTop + this.translateY + this.element.offsetHeight\n ) {\n return State.ColliderBottom;\n }\n }\n\n return State.Rest;\n }\n\n /**\n * Get a {@link strategy} that determines the further behavior of the target {@link element}.\n */\n private _getStrategy(): Strategy {\n if (this.containerHeight <= this.element.offsetHeight) return Strategy.None;\n if (this.colliderHeight < this.element.offsetHeight) return Strategy.Both;\n return Strategy.Top;\n }\n\n /**\n * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements|dimensions}.\n */\n private _calcDims(): void {\n const containerCoords = this._getCoords(this.container);\n this.containerLeft = containerCoords.left;\n this.containerTop = containerCoords.top;\n this.containerHeight = this.container.clientHeight;\n this.containerWidth = this.container.clientWidth;\n this.colliderHeight = window.innerHeight - this.spaceTop - this.spaceBottom;\n this.maxTranslateY = this.container.clientHeight - this.element.offsetHeight;\n\n this.strategy = this._getStrategy();\n\n if (this.strategy === Strategy.None) {\n if (this.prevStrategy !== this.strategy) this._render(State.None);\n } else {\n this._calcScroll();\n }\n\n this.prevContainerWidth = this.containerWidth;\n this.prevContainerLeft = this.containerLeft;\n this.prevContainerTop = this.containerTop;\n this.prevElementHeight = this.element.offsetHeight;\n this.prevStrategy = this.strategy;\n }\n\n /**\n * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems|coordinates}.\n */\n private _calcScroll(): void {\n this.colliderTop = window.scrollY + this.spaceTop;\n\n const state = this._getState(this._getDirection());\n\n if (state !== State.Rest) {\n this._render(state);\n this.prevState = state;\n }\n\n this.prevViewportScrollX = window.scrollX;\n this.prevViewportScrollY = window.scrollY;\n }\n\n /**\n * Helps apply DOM manipulation and synchronize processing with rendering. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame|requestAnimationFrame}.\n */\n private _request(): void {\n if (this.isRunningRequest) return;\n this.isRunningRequest = true;\n window.requestAnimationFrame(() => {\n if (this.events[Item.Resize] === Event.Resize) {\n this.events[Item.Resize] = Event.None;\n this._calcDims();\n } else if (this.events[Item.Scroll] === Event.Scroll) {\n this.events[Item.Scroll] = Event.None;\n this._calcScroll();\n }\n this.isRunningRequest = false;\n });\n }\n\n /**\n * Observe {@link https://developer.mozilla.org/en-US/docs/Web/API/Node|nodes} from target {@link element} to {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body|document body} with help the {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _observeTreeNodesFromCurrentToBody(element: HTMLElement): void {\n while (element) {\n this.resizeObserver.observe(element);\n if (element.tagName === 'BODY') break;\n (element as unknown) = element.parentElement;\n }\n }\n\n /**\n * Add required event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener|addEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _addListeners(): void {\n window.addEventListener('scroll', this._scrollListener, { capture: false, passive: true });\n this._observeTreeNodesFromCurrentToBody(this.element);\n }\n\n /**\n * Remove all event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener|removeEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _removeListeners(): void {\n window.removeEventListener('scroll', this._scrollListener, { capture: false }); // window\n this.resizeObserver.disconnect();\n }\n}\n\nexport default StickNRoll;"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAyGO,IAAMK,EAAN,KAAiB,CAIZ,UAKA,QAKA,OAMA,iBAKA,WAKA,cAKA,kBAKA,gBAKA,eAKA,cAKA,aAKA,mBAKA,kBAKA,iBAKA,eAKA,YAKA,oBAKA,oBAMA,SAMA,YAKA,eAMA,SAMA,aAMA,UAKA,YAKA,MAMR,YAAYC,EAAwBC,EAAsBC,EAAuB,CAC7E,KAAK,UAAYF,EACjB,KAAK,QAAUC,EAEf,KAAK,iBAAmB,GAExB,KAAK,eAAiB,EACtB,KAAK,YAAc,EAEnB,KAAK,gBAAkB,EACvB,KAAK,eAAiB,EACtB,KAAK,cAAgB,EACrB,KAAK,aAAe,EACpB,KAAK,mBAAqB,EAC1B,KAAK,kBAAoB,EACzB,KAAK,iBAAmB,EAExB,KAAK,kBAAoB,EAEzB,KAAK,cAAgB,EACrB,KAAK,WAAa,EAElB,KAAK,oBAAsB,EAC3B,KAAK,oBAAsB,EAE3B,KAAK,OAAS,CAAC,EAAY,CAAU,EAErC,KAAK,SAAW,EAChB,KAAK,aAAe,EAEpB,KAAK,UAAY,EAEjB,KAAK,YAAc,CAAE,MAAO,GAAI,KAAM,GAAI,IAAK,GAAI,SAAUC,GAAS,UAAY,GAAI,UAAW,EAAG,EACpG,KAAK,MAAQ,CAAC,EAEd,KAAK,YAAcA,GAAS,aAAe,EAC3C,KAAK,SAAWA,GAAS,UAAY,EAGrC,KAAK,UAAY,KAAK,UAAU,KAAK,IAAI,EACzC,KAAK,YAAc,KAAK,YAAY,KAAK,IAAI,EAC7C,KAAK,gBAAkB,KAAK,gBAAgB,KAAK,IAAI,EACrD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K,OAAO,CACxD,CAKQ,kBAAyB,CAC7B,OAAO,oBAAoB,SAAU,KAAK,gBAAiB,CAAE,QAAS,EAAM,CAAC,EAC7E,KAAK,eAAe,WAAW,CACnC,CACJ,EAEOQ,EAAQV","names":["index_exports","__export","StickNRoll","index_default","__toCommonJS","StickNRoll","container","element","options","spaces","coords","state","key","direction","containerCoords","index_default"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ var r=class{container;element;events;isRunningRequest;translateY;maxTranslateY;prevElementHeight;containerHeight;containerWidth;containerLeft;containerTop;prevContainerWidth;prevContainerLeft;prevContainerTop;colliderHeight;colliderTop;prevViewportScrollX;prevViewportScrollY;spaceTop;spaceBottom;resizeObserver;strategy;prevStrategy;prevState;listOfRules;rules;constructor(t,e,i){this.container=t,this.element=e,this.isRunningRequest=!1,this.colliderHeight=0,this.colliderTop=0,this.containerHeight=0,this.containerWidth=0,this.containerLeft=0,this.containerTop=0,this.prevContainerWidth=0,this.prevContainerLeft=0,this.prevContainerTop=0,this.prevElementHeight=0,this.maxTranslateY=0,this.translateY=0,this.prevViewportScrollX=0,this.prevViewportScrollY=0,this.events=[0,0],this.strategy=1,this.prevStrategy=1,this.prevState=3,this.listOfRules={width:"",left:"",top:"",position:i?.position??"",transform:""},this.rules={},this.spaceBottom=i?.spaceBottom??0,this.spaceTop=i?.spaceTop??0,this._calcDims=this._calcDims.bind(this),this._calcScroll=this._calcScroll.bind(this),this._resizeListener=this._resizeListener.bind(this),this._scrollListener=this._scrollListener.bind(this),this.resizeObserver=new ResizeObserver(this._resizeListener)}enable(){this._addListeners()}disable(){this._removeListeners(),this.isRunningRequest=!1,this.events.fill(0)}updateSpaces(t){this.spaceBottom=t.spaceBottom??0,this.spaceTop=t.spaceTop??0,this._resizeListener()}_resizeListener(){this.events[0]===0&&(this.events[0]=1),this._request()}_scrollListener(){this.events[1]===0&&(this.events[1]=2),this._request()}_getCoords(t){let e={left:t.offsetLeft,top:t.offsetTop};for(;t=t.tagName==="BODY"?t.parentElement:t.offsetParent;)e.top+=t.offsetTop,e.left+=t.offsetLeft;return e}_render(t){t===0?(this.translateY=this.maxTranslateY,this.rules={top:this.spaceTop+"px",left:"0px",position:"sticky",width:this.container.clientWidth+"px"}):t===2?(this.translateY=0,this.rules={top:this.colliderHeight+this.spaceTop-this.element.offsetHeight+"px",left:this.containerLeft-window.scrollX+"px",position:"fixed",width:this.container.clientWidth+"px"}):t===1?(this.translateY=0,this.rules={top:this.spaceTop+"px",left:this.containerLeft-window.scrollX+"px",position:"fixed",width:this.container.clientWidth+"px"}):t===3?(this.translateY=0,this.rules={}):t===4&&(this.prevState===1?this.translateY=this.colliderTop-this.containerTop:this.prevState===2?this.translateY=this.colliderTop+this.colliderHeight-this.containerTop-this.prevElementHeight:this.prevState===0&&(this.translateY=this.containerHeight-this.element.offsetHeight),this.rules={position:"relative",transform:`translate3d(0px, ${this.translateY}px, 0px)`}),this.container.style.position=t===0?"relative":"";for(let e in this.listOfRules)this.element.style[e]=this.rules[e]??this.listOfRules[e]}_getDirection(){return this.prevViewportScrollY===window.scrollY?1:this.prevViewportScrollY<window.scrollY?0:2}_getState(t){if(this.prevState===1){if(this.colliderTop<=this.containerTop)return 3;if(this.colliderTop+this.element.offsetHeight>=this.containerTop+this.containerHeight)return 0;if(this.prevStrategy===2&&this.element.offsetHeight>this.colliderHeight)return this.prevStrategy=this.strategy,4;if(this.strategy===0&&t===0)return 4;if(this.prevViewportScrollX!==window.scrollX||this.prevContainerLeft!==this.containerLeft||this.prevContainerWidth!==this.containerWidth||this.prevContainerTop!==this.containerTop)return 1}else if(this.prevState===2){if(this.colliderTop<=this.containerTop)return 3;if(this.colliderTop+this.colliderHeight>=this.containerTop+this.containerHeight)return 0;if(this.element.offsetHeight<=this.colliderHeight)return 1;if(t===2||this.prevElementHeight!==this.element.offsetHeight)return 4;if(this.prevViewportScrollX!==window.scrollX||this.prevContainerLeft!==this.containerLeft||this.prevContainerWidth!==this.containerWidth||this.prevContainerTop!==this.containerTop)return 2}else if(this.prevState===0){if(this.colliderTop<=this.containerTop)return 3;if(t===2&&this.colliderTop<=this.containerTop+this.maxTranslateY||this.element.offsetHeight<this.containerTop+this.containerHeight-this.colliderTop)return 1;if(this.prevContainerWidth!==this.containerWidth)return 0}else if(this.prevState===3){if(this.colliderTop+this.element.offsetHeight>=this.containerTop+this.containerHeight)return 0;if(this.element.offsetHeight<this.colliderHeight&&this.colliderTop>=this.containerTop)return 1;if(this.strategy===0&&this.colliderTop+this.colliderHeight>=this.containerTop+this.element.offsetHeight)return 2}else if(this.prevState===4){if(this.containerHeight-this.translateY<this.element.offsetHeight)return 0;if(this.element.offsetHeight<this.colliderHeight||this.colliderTop<=this.containerTop+this.translateY)return 1;if(this.translateY<this.maxTranslateY&&this.colliderTop+this.colliderHeight>this.containerTop+this.translateY+this.element.offsetHeight)return 2}return 5}_getStrategy(){return this.containerHeight<=this.element.offsetHeight?1:this.colliderHeight<this.element.offsetHeight?0:2}_calcDims(){let t=this._getCoords(this.container);this.containerLeft=t.left,this.containerTop=t.top,this.containerHeight=this.container.clientHeight,this.containerWidth=this.container.clientWidth,this.colliderHeight=window.innerHeight-this.spaceTop-this.spaceBottom,this.maxTranslateY=this.container.clientHeight-this.element.offsetHeight,this.strategy=this._getStrategy(),this.strategy===1?this.prevStrategy!==this.strategy&&this._render(3):this._calcScroll(),this.prevContainerWidth=this.containerWidth,this.prevContainerLeft=this.containerLeft,this.prevContainerTop=this.containerTop,this.prevElementHeight=this.element.offsetHeight,this.prevStrategy=this.strategy}_calcScroll(){this.colliderTop=window.scrollY+this.spaceTop;let t=this._getState(this._getDirection());t!==5&&(this._render(t),this.prevState=t),this.prevViewportScrollX=window.scrollX,this.prevViewportScrollY=window.scrollY}_request(){this.isRunningRequest||(this.isRunningRequest=!0,window.requestAnimationFrame(()=>{this.events[0]===1?(this.events[0]=0,this._calcDims()):this.events[1]===2&&(this.events[1]=0,this._calcScroll()),this.isRunningRequest=!1}))}_observeTreeNodesFromCurrentToBody(t){for(;t&&(this.resizeObserver.observe(t),t.tagName!=="BODY");)t=t.parentElement}_addListeners(){window.addEventListener("scroll",this._scrollListener,{capture:!1,passive:!0}),this._observeTreeNodesFromCurrentToBody(this.element)}_removeListeners(){window.removeEventListener("scroll",this._scrollListener,{capture:!1}),this.resizeObserver.disconnect()}},o=r;export{r as StickNRoll,o as default};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Options type.\n */\ntype OptionsType = {\n /**\n * The space between bottom of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and bottom of the `visible area`.\n * @default 0\n */\n spaceBottom?: number;\n /**\n * The space between top of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport} and top of the `visible area`.\n * @default 0\n */\n spaceTop?: number;\n /**\n * Default {@link https://developer.mozilla.org/en-US/docs/Web/CSS/position|position} for the target `element`.\n * @default ''\n */\n position?: CSSStyleDeclaration['position'];\n};\n\n/**\n * The element coordinates.\n */\ntype TypeElementCoords = {\n left: number;\n top: number;\n};\n\n/**\n * Indexes of events in the events array.\n */\nenum Item {\n Resize = 0,\n Scroll = 1,\n}\n\nenum Event {\n None,\n Resize,\n Scroll,\n}\n\n/**\n * Defines `viewport` direction.\n */\nenum Direction {\n Down,\n None,\n Up,\n}\n\n/**\n * Strategy.\n */\nenum Strategy {\n /**\n * Sticky both sides by Y-axis.\n */\n Both,\n /**\n * Nothing do.\n */\n None,\n /**\n * Sticky only top side.\n */\n Top,\n}\n\n/**\n * @enum {number} Position variant of target `element`.\n */\nenum State {\n /**\n * Element affixed at the bottom of the container.\n */\n ContainerBottom,\n /**\n * Element fixed at the top of the window viewport area (including top padding).\n */\n ColliderTop,\n /**\n * Element fixed at the bottom of the window viewport area (including bottom padding).\n */\n ColliderBottom,\n /**\n * Default element behavior. Case without specific rules.\n */\n None,\n /**\n * The element is offset along the Y axis relative to the container.\n */\n TranslateY,\n /**\n * Indicates that rendering should be skipped until the state changes.\n */\n Rest,\n}\n\ntype Rules = Pick<CSSStyleDeclaration, 'width' | 'left' | 'top' | 'position' | 'transform'>;\n\n/**\n * Helps to give an element sticky scrolling capability.\n */\nexport class StickNRoll {\n /**\n * Parent element of target {@link element}.\n */\n private container: HTMLElement;\n\n /**\n * Target element with sticky and scroll abilities.\n */\n private element: HTMLElement;\n\n /**\n * Triggered Event.\n */\n private events: [Event.Resize | Event.None, Event.Scroll | Event.None];\n\n /**\n * Indicates that a render request has already been initiated.\n * @default false\n */\n private isRunningRequest: boolean;\n\n /**\n * The Current Y-axis coordinates relative to the {@link container}.\n */\n private translateY: number;\n\n /**\n * The maximum allowed Y-axis coordinates relative to the {@link container}.\n */\n private maxTranslateY: number;\n\n /**\n * Previous element height.\n */\n private prevElementHeight: number;\n\n /**\n * Height of the {@link container}.\n */\n private containerHeight: number;\n\n /**\n * Width of the {@link container}.\n */\n private containerWidth: number;\n\n /**\n * Coordinate by X-axis of the {@link container}.\n */\n private containerLeft: number;\n\n /**\n * Coordinate by Y-axis of the {@link container}.\n */\n private containerTop: number;\n\n /**\n * Previous width of the {@link container}.\n */\n private prevContainerWidth: number;\n\n /**\n * Previous coordinate by X-axis of the {@link container}.\n */\n private prevContainerLeft: number;\n\n /**\n * Previous coordinate by Y-axis of the {@link container}.\n */\n private prevContainerTop: number;\n\n /**\n * Height of the {@link collider}.\n */\n private colliderHeight: number;\n\n /**\n * Top coordinate of the {@link collider}.\n */\n private colliderTop: number;\n\n /**\n * Previous coordinate by X-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.\n */\n private prevViewportScrollX: number;\n\n /**\n * Previous coordinate by Y-axis of the {@link https://developer.mozilla.org/en-US/docs/Glossary/Viewport|viewport}.\n */\n private prevViewportScrollY: number;\n\n /**\n * Space top.\n * @default 0\n */\n private spaceTop: number;\n\n /**\n * Space bottom.\n * @default 0\n */\n private spaceBottom: number;\n\n /**\n * Resize observer.\n */\n private resizeObserver: ResizeObserver;\n\n /**\n * Current strategy. Helps to detect element behaviour.\n * @default Strategy.None\n */\n private strategy: Strategy;\n\n /**\n * Previous strategy.\n * @default Strategy.None\n */\n private prevStrategy: Strategy;\n\n /**\n * Previous state.\n * @default Variant.None\n */\n private prevState: State;\n\n /**\n * List of available CSS properties.\n */\n private listOfRules: Rules;\n\n /**\n * List of css properties to be updated.\n */\n private rules: Partial<Rules>;\n\n /**\n * @param {HTMLElement} container - The parent element ({@link container}) of {@link element}.\n * @param {HTMLElement} element - The target {@link element} which will be endowed with stickiness and scrolling abilities relative to its parent element ({@link container}).\n */\n constructor(container: HTMLElement, element: HTMLElement, options?: OptionsType) {\n this.container = container;\n this.element = element;\n\n this.isRunningRequest = false;\n\n this.colliderHeight = 0;\n this.colliderTop = 0;\n\n this.containerHeight = 0;\n this.containerWidth = 0;\n this.containerLeft = 0;\n this.containerTop = 0;\n this.prevContainerWidth = 0;\n this.prevContainerLeft = 0;\n this.prevContainerTop = 0;\n\n this.prevElementHeight = 0;\n\n this.maxTranslateY = 0;\n this.translateY = 0;\n\n this.prevViewportScrollX = 0;\n this.prevViewportScrollY = 0;\n\n this.events = [Event.None, Event.None];\n\n this.strategy = Strategy.None;\n this.prevStrategy = Strategy.None;\n\n this.prevState = State.None;\n\n this.listOfRules = { width: '', left: '', top: '', position: options?.position ?? '', transform: '' };\n this.rules = {};\n\n this.spaceBottom = options?.spaceBottom ?? 0;\n this.spaceTop = options?.spaceTop ?? 0;\n\n // Binds \"this\" context to the following class methods.\n this._calcDims = this._calcDims.bind(this);\n this._calcScroll = this._calcScroll.bind(this);\n this._resizeListener = this._resizeListener.bind(this);\n this._scrollListener = this._scrollListener.bind(this);\n\n // Create resize observer.\n this.resizeObserver = new ResizeObserver(this._resizeListener);\n }\n\n /**\n * Enable sticky scrolling capability. Use {@link disable} method to deactivate sticky scrolling capability.\n */\n public enable(): void {\n this._addListeners(); // calls _calcDims method by default, cause is used ResizeObserver\n }\n\n /**\n * Disable sticky scrolling capability. Use {@link enable} method to activate sticky scrolling capability again.\n */\n public disable(): void {\n this._removeListeners();\n this.isRunningRequest = false;\n this.events.fill(Event.None);\n }\n\n /**\n * Update {@link spaceBottom} and {@link spaceTop}. It fires the render after changes of spaces.\n */\n public updateSpaces(spaces: Pick<OptionsType, 'spaceBottom' | 'spaceTop'>): void {\n this.spaceBottom = spaces.spaceBottom ?? 0;\n this.spaceTop = spaces.spaceTop ?? 0;\n this._resizeListener();\n }\n\n /**\n * Resize listener.\n */\n private _resizeListener(): void {\n if (this.events[Item.Resize] === Event.None) this.events[Item.Resize] = Event.Resize;\n this._request();\n }\n\n /**\n * Scroll listener.\n */\n private _scrollListener(): void {\n if (this.events[Item.Scroll] === Event.None) this.events[Item.Scroll] = Event.Scroll;\n this._request();\n }\n\n /**\n * Get coordinates for passed element.\n */\n private _getCoords(element: HTMLElement): TypeElementCoords {\n const coords = { left: element.offsetLeft, top: element.offsetTop };\n while (((element as unknown) = 'BODY' === element.tagName ? element.parentElement : element.offsetParent)) {\n coords.top += element.offsetTop;\n coords.left += element.offsetLeft;\n }\n return coords;\n }\n\n /**\n * Update styles in target {@link element} and {@link container}.\n */\n private _render(state: State): void {\n if (state === State.ContainerBottom) {\n this.translateY = this.maxTranslateY;\n this.rules = {\n top: this.spaceTop + 'px',\n left: '0px',\n position: 'sticky',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.ColliderBottom) {\n this.translateY = 0;\n this.rules = {\n top: this.colliderHeight + this.spaceTop - this.element.offsetHeight + 'px',\n left: this.containerLeft - window.scrollX + 'px',\n position: 'fixed',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.ColliderTop) {\n this.translateY = 0;\n this.rules = {\n top: this.spaceTop + 'px',\n left: this.containerLeft - window.scrollX + 'px',\n position: 'fixed',\n width: this.container.clientWidth + 'px',\n };\n } else if (state === State.None) {\n this.translateY = 0;\n this.rules = {};\n } else if (state === State.TranslateY) {\n if (this.prevState === State.ColliderTop) {\n this.translateY = this.colliderTop - this.containerTop;\n } else if (this.prevState === State.ColliderBottom) {\n this.translateY = this.colliderTop + this.colliderHeight - this.containerTop - this.prevElementHeight;\n } else if (this.prevState === State.ContainerBottom) {\n this.translateY = this.containerHeight - this.element.offsetHeight;\n }\n this.rules = { position: 'relative', transform: `translate3d(0px, ${this.translateY}px, 0px)` };\n }\n\n this.container.style.position = state === State.ContainerBottom ? 'relative' : '';\n\n for (const key in this.listOfRules) {\n this.element.style[key as keyof Rules] =\n this.rules[key as unknown as keyof Rules] ?? this.listOfRules[key as unknown as keyof Rules];\n }\n }\n\n /**\n * Get the scroll direction. `None` for horizontal scrolling or no scrolling.\n */\n private _getDirection(): Direction {\n if (this.prevViewportScrollY === window.scrollY) return Direction.None;\n return this.prevViewportScrollY < window.scrollY ? Direction.Down : Direction.Up;\n }\n\n /**\n * Get state of target element.\n */\n private _getState(direction: Direction): State {\n if (this.prevState === State.ColliderTop) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (this.colliderTop + this.element.offsetHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.prevStrategy === Strategy.Top && this.element.offsetHeight > this.colliderHeight) {\n this.prevStrategy = this.strategy;\n return State.TranslateY;\n }\n if (this.strategy === Strategy.Both && direction === Direction.Down) {\n return State.TranslateY;\n }\n if (\n this.prevViewportScrollX !== window.scrollX ||\n this.prevContainerLeft !== this.containerLeft ||\n this.prevContainerWidth !== this.containerWidth ||\n this.prevContainerTop !== this.containerTop\n ) {\n return State.ColliderTop;\n }\n } else if (this.prevState === State.ColliderBottom) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (this.colliderTop + this.colliderHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight <= this.colliderHeight) {\n return State.ColliderTop;\n }\n if (direction === Direction.Up || this.prevElementHeight !== this.element.offsetHeight) {\n return State.TranslateY;\n }\n if (\n this.prevViewportScrollX !== window.scrollX ||\n this.prevContainerLeft !== this.containerLeft ||\n this.prevContainerWidth !== this.containerWidth ||\n this.prevContainerTop !== this.containerTop\n ) {\n return State.ColliderBottom;\n }\n } else if (this.prevState === State.ContainerBottom) {\n if (this.colliderTop <= this.containerTop) {\n return State.None;\n }\n if (direction === Direction.Up && this.colliderTop <= this.containerTop + this.maxTranslateY) {\n return State.ColliderTop;\n }\n if (this.element.offsetHeight < this.containerTop + this.containerHeight - this.colliderTop) {\n return State.ColliderTop;\n }\n if (this.prevContainerWidth !== this.containerWidth) {\n return State.ContainerBottom;\n }\n } else if (this.prevState === State.None) {\n if (this.colliderTop + this.element.offsetHeight >= this.containerTop + this.containerHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight < this.colliderHeight && this.colliderTop >= this.containerTop) {\n return State.ColliderTop;\n }\n if (\n this.strategy === Strategy.Both &&\n this.colliderTop + this.colliderHeight >= this.containerTop + this.element.offsetHeight\n ) {\n return State.ColliderBottom;\n }\n } else if (this.prevState === State.TranslateY) {\n if (this.containerHeight - this.translateY < this.element.offsetHeight) {\n return State.ContainerBottom;\n }\n if (this.element.offsetHeight < this.colliderHeight || this.colliderTop <= this.containerTop + this.translateY) {\n return State.ColliderTop;\n }\n if (\n this.translateY < this.maxTranslateY &&\n this.colliderTop + this.colliderHeight > this.containerTop + this.translateY + this.element.offsetHeight\n ) {\n return State.ColliderBottom;\n }\n }\n\n return State.Rest;\n }\n\n /**\n * Get a {@link strategy} that determines the further behavior of the target {@link element}.\n */\n private _getStrategy(): Strategy {\n if (this.containerHeight <= this.element.offsetHeight) return Strategy.None;\n if (this.colliderHeight < this.element.offsetHeight) return Strategy.Both;\n return Strategy.Top;\n }\n\n /**\n * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements|dimensions}.\n */\n private _calcDims(): void {\n const containerCoords = this._getCoords(this.container);\n this.containerLeft = containerCoords.left;\n this.containerTop = containerCoords.top;\n this.containerHeight = this.container.clientHeight;\n this.containerWidth = this.container.clientWidth;\n this.colliderHeight = window.innerHeight - this.spaceTop - this.spaceBottom;\n this.maxTranslateY = this.container.clientHeight - this.element.offsetHeight;\n\n this.strategy = this._getStrategy();\n\n if (this.strategy === Strategy.None) {\n if (this.prevStrategy !== this.strategy) this._render(State.None);\n } else {\n this._calcScroll();\n }\n\n this.prevContainerWidth = this.containerWidth;\n this.prevContainerLeft = this.containerLeft;\n this.prevContainerTop = this.containerTop;\n this.prevElementHeight = this.element.offsetHeight;\n this.prevStrategy = this.strategy;\n }\n\n /**\n * Calculate {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_view/Coordinate_systems|coordinates}.\n */\n private _calcScroll(): void {\n this.colliderTop = window.scrollY + this.spaceTop;\n\n const state = this._getState(this._getDirection());\n\n if (state !== State.Rest) {\n this._render(state);\n this.prevState = state;\n }\n\n this.prevViewportScrollX = window.scrollX;\n this.prevViewportScrollY = window.scrollY;\n }\n\n /**\n * Helps apply DOM manipulation and synchronize processing with rendering. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame|requestAnimationFrame}.\n */\n private _request(): void {\n if (this.isRunningRequest) return;\n this.isRunningRequest = true;\n window.requestAnimationFrame(() => {\n if (this.events[Item.Resize] === Event.Resize) {\n this.events[Item.Resize] = Event.None;\n this._calcDims();\n } else if (this.events[Item.Scroll] === Event.Scroll) {\n this.events[Item.Scroll] = Event.None;\n this._calcScroll();\n }\n this.isRunningRequest = false;\n });\n }\n\n /**\n * Observe {@link https://developer.mozilla.org/en-US/docs/Web/API/Node|nodes} from target {@link element} to {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body|document body} with help the {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _observeTreeNodesFromCurrentToBody(element: HTMLElement): void {\n while (element) {\n this.resizeObserver.observe(element);\n if (element.tagName === 'BODY') break;\n (element as unknown) = element.parentElement;\n }\n }\n\n /**\n * Add required event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener|addEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _addListeners(): void {\n window.addEventListener('scroll', this._scrollListener, { capture: false, passive: true });\n this._observeTreeNodesFromCurrentToBody(this.element);\n }\n\n /**\n * Remove all event listeners. See {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener|removeEventListener} and {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver|ResizeObserver}.\n */\n private _removeListeners(): void {\n window.removeEventListener('scroll', this._scrollListener, { capture: false }); // window\n this.resizeObserver.disconnect();\n }\n}\n\nexport default StickNRoll;"],"mappings":"AAyGO,IAAMA,EAAN,KAAiB,CAIZ,UAKA,QAKA,OAMA,iBAKA,WAKA,cAKA,kBAKA,gBAKA,eAKA,cAKA,aAKA,mBAKA,kBAKA,iBAKA,eAKA,YAKA,oBAKA,oBAMA,SAMA,YAKA,eAMA,SAMA,aAMA,UAKA,YAKA,MAMR,YAAYC,EAAwBC,EAAsBC,EAAuB,CAC7E,KAAK,UAAYF,EACjB,KAAK,QAAUC,EAEf,KAAK,iBAAmB,GAExB,KAAK,eAAiB,EACtB,KAAK,YAAc,EAEnB,KAAK,gBAAkB,EACvB,KAAK,eAAiB,EACtB,KAAK,cAAgB,EACrB,KAAK,aAAe,EACpB,KAAK,mBAAqB,EAC1B,KAAK,kBAAoB,EACzB,KAAK,iBAAmB,EAExB,KAAK,kBAAoB,EAEzB,KAAK,cAAgB,EACrB,KAAK,WAAa,EAElB,KAAK,oBAAsB,EAC3B,KAAK,oBAAsB,EAE3B,KAAK,OAAS,CAAC,EAAY,CAAU,EAErC,KAAK,SAAW,EAChB,KAAK,aAAe,EAEpB,KAAK,UAAY,EAEjB,KAAK,YAAc,CAAE,MAAO,GAAI,KAAM,GAAI,IAAK,GAAI,SAAUC,GAAS,UAAY,GAAI,UAAW,EAAG,EACpG,KAAK,MAAQ,CAAC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AOA,IACH,KAAK,eAAe,QAAQA,CAAO,EAC/BA,EAAQ,UAAY,SACvBA,EAAsBA,EAAQ,aAEvC,CAKQ,eAAsB,CAC1B,OAAO,iBAAiB,SAAU,KAAK,gBAAiB,CAAE,QAAS,GAAO,QAAS,EAAK,CAAC,EACzF,KAAK,mCAAmC,KAAK,OAAO,CACxD,CAKQ,kBAAyB,CAC7B,OAAO,oBAAoB,SAAU,KAAK,gBAAiB,CAAE,QAAS,EAAM,CAAC,EAC7E,KAAK,eAAe,WAAW,CACnC,CACJ,EAEOQ,EAAQV","names":["StickNRoll","container","element","options","spaces","coords","state","key","direction","containerCoords","index_default"]}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "stick-n-roll",
3
+ "version": "1.0.1",
4
+ "description": "stick-n-roll is a lightweight and user-friendly npm package that enables HTML elements to have functionality similar to position: sticky, with the added ability to scroll the block.",
5
+ "homepage": "https://devashtar.github.io/stick-n-roll/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/devashtar/stick-n-roll.git"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "package.json"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "require": "./dist/index.js",
17
+ "import": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.mjs",
23
+ "types": "./dist/index.d.ts",
24
+ "scripts": {
25
+ "build": "tsup ./src",
26
+ "deploy": "gh-pages -d example"
27
+ },
28
+ "keywords": [
29
+ "sticky",
30
+ "fixed",
31
+ "scroll",
32
+ "ui",
33
+ "sidebar",
34
+ "aside",
35
+ "position",
36
+ "sticky",
37
+ "element",
38
+ "frontend",
39
+ "smart block",
40
+ "web development",
41
+ "user experience"
42
+ ],
43
+ "author": "devashtar",
44
+ "license": "MIT",
45
+ "devDependencies": {
46
+ "gh-pages": "^6.3.0",
47
+ "tsup": "^8.3.6",
48
+ "typescript": "^5.7.3"
49
+ }
50
+ }