@monokonet/scroll 1.0.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/LICENSE ADDED
@@ -0,0 +1,209 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License.
67
+
68
+ Subject to the terms and conditions of this License, each Contributor
69
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
70
+ royalty-free, irrevocable copyright license to reproduce, prepare
71
+ Derivative Works of, publicly display, publicly perform, sublicense,
72
+ and distribute the Work and such Derivative Works in Source or Object
73
+ form.
74
+
75
+ 3. Grant of Patent License.
76
+
77
+ Subject to the terms and conditions of this License, each Contributor
78
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
79
+ royalty-free, irrevocable (except as stated in this section) patent
80
+ license to make, have made, use, offer to sell, sell, import, and
81
+ otherwise transfer the Work, where such license applies only to those
82
+ patent claims licensable by such Contributor that are necessarily
83
+ infringed by their Contribution(s) alone or by combination of their
84
+ Contribution(s) with the Work to which such Contribution(s) was
85
+ submitted. If You institute patent litigation against any entity
86
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
87
+ the Work or a Contribution incorporated within the Work constitutes
88
+ direct or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate as of
90
+ the date such litigation is filed.
91
+
92
+ 4. Redistribution.
93
+
94
+ You may reproduce and distribute copies of the Work or Derivative
95
+ Works thereof in any medium, with or without modifications, and in
96
+ Source or Object form, provided that You meet the following conditions:
97
+
98
+ (a) You must give any other recipients of the Work or Derivative Works
99
+ a copy of this License; and
100
+
101
+ (b) You must cause any modified files to carry prominent notices
102
+ stating that You changed the files; and
103
+
104
+ (c) You must retain, in the Source form of any Derivative Works that
105
+ You distribute, all copyright, patent, trademark, and attribution
106
+ notices from the Source form of the Work, excluding those notices
107
+ that do not pertain to any part of the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained within
112
+ such NOTICE file, excluding those notices that do not pertain to
113
+ any part of the Derivative Works, in at least one of the following
114
+ places: within a NOTICE text file distributed as part of the
115
+ Derivative Works; within the Source form or documentation, if
116
+ provided along with the Derivative Works; or, within a display
117
+ generated by the Derivative Works, if and wherever such third-party
118
+ notices normally appear. The contents of the NOTICE file are for
119
+ informational purposes only and do not modify the License.
120
+ You may add Your own attribution notices within Derivative Works
121
+ that You distribute, alongside or as an addendum to the NOTICE text
122
+ from the Work, provided that such additional attribution notices
123
+ cannot be construed as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and may
126
+ provide additional or different license terms and conditions for use,
127
+ reproduction, or distribution of Your modifications, or for any such
128
+ Derivative Works as a whole, provided Your use, reproduction, and
129
+ distribution of the Work otherwise complies with the conditions stated
130
+ in this License.
131
+
132
+ 5. Submission of Contributions.
133
+
134
+ Unless You explicitly state otherwise, any Contribution intentionally
135
+ submitted for inclusion in the Work by You to the Licensor shall be
136
+ under the terms and conditions of this License, without any additional
137
+ terms or conditions. Notwithstanding the above, nothing herein shall
138
+ supersede or modify the terms of any separate license agreement you may
139
+ have executed with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks.
142
+
143
+ This License does not grant permission to use the trade names,
144
+ trademarks, service marks, or product names of the Licensor, except as
145
+ required for reasonable and customary use in describing the origin of
146
+ the Work and reproducing the content of the NOTICE file.
147
+
148
+ 7. Disclaimer of Warranty.
149
+
150
+ Unless required by applicable law or agreed to in writing, Licensor
151
+ provides the Work (and each Contributor provides its Contributions) on
152
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
153
+ express or implied, including, without limitation, any warranties or
154
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
155
+ A PARTICULAR PURPOSE. You are solely responsible for determining the
156
+ appropriateness of using or redistributing the Work and assume any risks
157
+ associated with Your exercise of permissions under this License.
158
+
159
+ 8. Limitation of Liability.
160
+
161
+ In no event and under no legal theory, whether in tort (including
162
+ negligence), contract, or otherwise, unless required by applicable law
163
+ (such as deliberate and grossly negligent acts) or agreed to in writing,
164
+ shall any Contributor be liable to You for damages, including any
165
+ direct, indirect, special, incidental, or consequential damages of any
166
+ character arising as a result of this License or out of the use or
167
+ inability to use the Work (including but not limited to damages for loss
168
+ of goodwill, work stoppage, computer failure or malfunction, or any and
169
+ all other commercial damages or losses), even if such Contributor has
170
+ been advised of the possibility of such damages.
171
+
172
+ 9. Accepting Warranty or Additional Liability.
173
+
174
+ While redistributing the Work or Derivative Works thereof, You may
175
+ choose to offer, and charge a fee for, acceptance of support, warranty,
176
+ indemnity, or other liability obligations and/or rights consistent with
177
+ this License. However, in accepting such obligations, You may act only
178
+ on Your own behalf and on Your sole responsibility, not on behalf of
179
+ any other Contributor, and only if You agree to indemnify, defend, and
180
+ hold each Contributor harmless for any liability incurred by, or claims
181
+ asserted against, such Contributor by reason of your accepting any such
182
+ warranty or additional liability.
183
+
184
+ END OF TERMS AND CONDITIONS
185
+
186
+ APPENDIX: How to apply the Apache License to your work.
187
+
188
+ To apply the Apache License to your work, attach the following
189
+ boilerplate notice, with the fields enclosed by brackets "[]"
190
+ replaced with your own identifying information. (Don't include
191
+ the brackets!) The text should be enclosed in the appropriate
192
+ comment syntax for the file format. We also recommend that a
193
+ file or class name and description of purpose be included on the
194
+ same "printed page" as the copyright notice for easier
195
+ identification within third-party archives.
196
+
197
+ Copyright 2026 MONOKO
198
+
199
+ Licensed under the Apache License, Version 2.0 (the "License");
200
+ you may not use this file except in compliance with the License.
201
+ You may obtain a copy of the License at
202
+
203
+ http://www.apache.org/licenses/LICENSE-2.0
204
+
205
+ Unless required by applicable law or agreed to in writing, software
206
+ distributed under the License is distributed on an "AS IS" BASIS,
207
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
+ See the License for the specific language governing permissions and
209
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @monokonet/scroll
2
+
3
+ A lightweight runtime for interpolated scrolling.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @monokonet/scroll
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createScroll } from '@monokonet/scroll';
15
+
16
+ const scroll = createScroll({
17
+ multiplier: 1.0,
18
+ duration: 0.77,
19
+ limit: 120.0,
20
+ });
21
+
22
+ scroll.watch(({ position, progress, distance, direction }) => {
23
+ console.log(position, progress, distance, direction);
24
+ });
25
+ ```
26
+
27
+ ## License
28
+
29
+ Apache-2.0
@@ -0,0 +1,67 @@
1
+ type ScrollOptions = {
2
+ multiplier?: number;
3
+ duration?: number;
4
+ limit?: number;
5
+ ease?: (t: number) => number;
6
+ axis?: 'y' | 'x';
7
+ };
8
+ type ScrollState = {
9
+ position: number;
10
+ progress: number;
11
+ distance: number;
12
+ direction: number;
13
+ };
14
+ type ScrollTask = (state: ScrollState) => void;
15
+
16
+ /** ------------------------------------------------------------------------- */
17
+ declare class Scroll {
18
+ private readonly _multiplier;
19
+ private readonly _duration;
20
+ private readonly _limit;
21
+ private readonly _ease;
22
+ private _tasks;
23
+ private _running;
24
+ private _time;
25
+ private _position;
26
+ private _progress;
27
+ private _velocity;
28
+ private _from;
29
+ private _to;
30
+ private _max;
31
+ /** ----------------------------------------------------------------------- */
32
+ constructor({ multiplier, duration, limit, ease, axis, }?: ScrollOptions);
33
+ destroy(): void;
34
+ /** ----------------------------------------------------------------------- */
35
+ watch(task: ScrollTask, priority?: number): () => void;
36
+ unwatch(task: ScrollTask): void;
37
+ /** ----------------------------------------------------------------------- */
38
+ by(distance: number): void;
39
+ to(position: number): void;
40
+ set(position: number): void;
41
+ update(delta: number): void;
42
+ /** ----------------------------------------------------------------------- */
43
+ get position(): number;
44
+ get progress(): number;
45
+ get velocity(): number;
46
+ get running(): boolean;
47
+ /** ----------------------------------------------------------------------- */
48
+ private _start;
49
+ private _stop;
50
+ private _move;
51
+ /** ----------------------------------------------------------------------- */
52
+ private _reset;
53
+ private _reset_x;
54
+ private _write;
55
+ private _write_x;
56
+ /** ----------------------------------------------------------------------- */
57
+ private _wheel;
58
+ private _wheel_x;
59
+ private _scroll;
60
+ private _scroll_x;
61
+ }
62
+
63
+ /** ------------------------------------------------------------------------- */
64
+ declare function createScroll(options?: ScrollOptions): Scroll;
65
+ declare function getScroll(): Scroll;
66
+
67
+ export { Scroll, type ScrollOptions, type ScrollState, type ScrollTask, createScroll, getScroll };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var o=class{_multiplier;_duration;_limit;_ease;_tasks=[];_running=!1;_time=0;_position=0;_progress=0;_velocity=0;_from=0;_to=0;_max=0;constructor({multiplier:t=1,duration:i=.82,limit:e=120,ease:s=_=>1-2**(-_*10),axis:r="y"}={}){this._multiplier=t,this._duration=i,this._limit=e,this._ease=s,r==="x"&&(this._reset=this._reset_x,this._write=this._write_x,this._wheel=this._wheel_x,this._scroll=this._scroll_x),window.addEventListener("resize",this._reset),window.addEventListener("orientationchange",this._reset),window.addEventListener("wheel",this._wheel,{passive:!1}),window.addEventListener("scroll",this._scroll),this._reset()}destroy(){window.removeEventListener("resize",this._reset),window.removeEventListener("orientationchange",this._reset),window.removeEventListener("wheel",this._wheel),window.removeEventListener("scroll",this._scroll)}watch(t,i=0){return this._tasks.push([t,i]),this._tasks.sort((e,s)=>e[1]-s[1]),()=>{this.unwatch(t)}}unwatch(t){this._tasks=this._tasks.filter(([i])=>i!==t)}by(t){this.to(this._to+t)}to(t){t=Math.min(Math.max(t,0),this._max),t===this._position||this._start(t)}set(t){this._move(Math.min(Math.max(t,0),this._max)),this._stop(),this._write()}update(t){this._running&&((this._time+=t)<this._duration?this._velocity=this._move(this._from+this._ease(this._time/this._duration)*(this._to-this._from))/t:(this._move(this._to),this._stop()),this._write())}get position(){return this._position}get progress(){return this._progress}get velocity(){return this._velocity}get running(){return this._running}_start(t){this._running=!0,this._time=0,this._from=this._position,this._to=t}_stop(){this._running=!1,this._time=0,this._from=this._position,this._to=this._position,this._velocity=0}_move(t){let i=t-this._position,e=i<0?-1:1;this._position=t,this._progress=this._max>0?t/this._max:0;let s={position:this._position,progress:this._progress,distance:i,direction:e};for(let r=0;r<this._tasks.length;r++)this._tasks[r][0](s);return i}_reset=()=>{this._max=Math.max(0,document.body.scrollHeight-window.innerHeight),this._move(window.scrollY),this._stop()};_reset_x=()=>{this._max=Math.max(0,document.body.scrollWidth-window.innerWidth),this._move(window.scrollX),this._stop()};_write(){window.scrollTo(0,this._position)}_write_x(){window.scrollTo(this._position,0)}_wheel=t=>{t.preventDefault();let i=this._multiplier*t.deltaY;this.by(Math.min(Math.max(i,-this._limit),this._limit))};_wheel_x=t=>{t.preventDefault();let i=this._multiplier*(Math.abs(t.deltaY)>Math.abs(t.deltaX)?t.deltaY:t.deltaX);this.by(Math.min(Math.max(i,-this._limit),this._limit))};_scroll=()=>{this._running||(this._move(window.scrollY),this._stop())};_scroll_x=()=>{this._running||(this._move(window.scrollX),this._stop())}};var n;function l(h){return n?.destroy(),n=new o(h),n}function p(){return n??l()}export{o as Scroll,l as createScroll,p as getScroll};
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@monokonet/scroll",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/monokonet/scroll.git"
9
+ },
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "devDependencies": {
25
+ "tsup": "^8.5.1",
26
+ "typescript": "5.9.2"
27
+ },
28
+ "scripts": {
29
+ "dev": "tsup src/index.ts --format esm --dts --watch",
30
+ "build": "tsup src/index.ts --format esm --dts --minify"
31
+ }
32
+ }