@substrate-system/raf-scroll 0.0.2

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,99 @@
1
+ # Big Time Public License
2
+
3
+ Version 2.0.2
4
+
5
+ <https://bigtimelicense.com/versions/2.0.2>
6
+
7
+ ## Purpose
8
+
9
+ These terms let you use and share this software for noncommercial purposes and in small business for free, while also guaranteeing that paid licenses for big businesses will be available on fair, reasonable, and nondiscriminatory terms.
10
+
11
+ ## Acceptance
12
+
13
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
14
+
15
+ ## Noncommercial Purposes
16
+
17
+ You may use the software for any noncommercial purpose.
18
+
19
+ ## Personal Uses
20
+
21
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, count as use for noncommercial purposes.
22
+
23
+ ## Noncommercial Organizations
24
+
25
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution counts as use for noncommercial purposes, regardless of the source of funding or obligations resulting from the funding.
26
+
27
+ ## Small Business
28
+
29
+ You may use the software for the benefit of your company if it meets all these criteria:
30
+
31
+ 1. had fewer than 20 total individuals working as employees and independent contractors at all times during the last tax year
32
+
33
+ 2. earned less than $1,000,000 total revenue in the last tax year
34
+
35
+ 3. received less than $1,000,000 total debt, equity, and other investment in the last five tax years, counting investment in predecessor companies that reorganized into, merged with, or spun out your company
36
+
37
+ All dollar figures are United States dollars as of 2019. Adjust for them inflation according to the United States Bureau of Labor Statistics' consumer price index for all urban consumers, United States city average, for all items, not seasonally adjusted, with 1982–1984=100 reference base.
38
+
39
+ ## Big Business
40
+
41
+ You may use the software for the benefit of your company:
42
+
43
+ 1. for 128 days after your company stops qualifying under [Small Business](#small-business)
44
+
45
+ 2. indefinitely, if the licensor or their legal successor does not offer fair, reasonable, and nondiscriminatory terms for a commercial license for the software within 32 days of [written request](#how-to-request) and negotiate in good faith to conclude a deal
46
+
47
+ ## How to Request
48
+
49
+ If this software includes an address for the licensor or an agent of the licensor in a standard place, such as in documentation, software package metadata, or an "about" page or screen, try to request a fair commercial license at that address. If this package includes both online and offline addresses, try online before offline. If you can't deliver a request that way, or this software doesn't include any addressees, spend one hour online researching an address, recording all your searches and inquiries as you go, and try any addresses that you find. If you can't find any addresses, or if those addresses also fail, that counts as failure to offer a fair commercial license by the licensor under [Big Business](#big-business).
50
+
51
+ ## Fair, Reasonable, and Nondiscriminatory Terms
52
+
53
+ Fair, reasonable, and nondiscriminatory terms may license the software perpetually or for a term, and may or may not cover new versions of the software. If the licensor advertises license terms and a pricing structure for generally available commercial licenses, the licensor proposes license terms and a price as advertised, and a customer not affiliated with the licensor has bought a commercial license for the software on substantially equivalent terms in the past year, the proposal is fair, reasonable, and nondiscriminatory.
54
+
55
+ ## Copyright License
56
+
57
+ The licensor grants you a copyright license to do everything with the software that would otherwise infringe the licensor's copyright in it for any purpose allowed by these terms.
58
+
59
+ ## Notices
60
+
61
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
62
+
63
+ > Required Notice: Copyright Nick Thomas (https://nichoth.com).
64
+
65
+ ## Patent License
66
+
67
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
68
+
69
+ ## Fair Use
70
+
71
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
72
+
73
+ ## No Other Rights
74
+
75
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
76
+
77
+ ## Patent Defense
78
+
79
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
80
+
81
+ ## Violations
82
+
83
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
84
+
85
+ ## No Liability
86
+
87
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
88
+
89
+ ## Definitions
90
+
91
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
92
+
93
+ **You** refers to the individual or entity agreeing to these terms.
94
+
95
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
96
+
97
+ **Your licenses** are all the licenses granted to you for the software under these terms.
98
+
99
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # raf scroll
2
+ [![tests](https://img.shields.io/github/actions/workflow/status/substrate-system/raf-scroll/nodejs.yml?style=flat-square)](https://github.com/substrate-system/raf-scroll/actions/workflows/nodejs.yml)
3
+ [![dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg?style=flat-square)](package.json)
4
+ [![types](https://img.shields.io/npm/types/@substrate-system/raf-scroll?style=flat-square)](README.md)
5
+ [![module](https://img.shields.io/badge/module-ESM%2FCJS-blue?style=flat-square)](README.md)
6
+ [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/raf-scroll?cache-control=no-cache)](https://packagephobia.com/result?p=@substrate-system/raf-scroll)
7
+ [![gzip size](https://img.shields.io/bundlephobia/minzip/@substrate-system/raf-scroll?style=flat-square)](https://bundlephobia.com/package/@substrate-system/raf-scroll)
8
+ [![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)
9
+
10
+ Scroll events, debounced with `requestAnimationFrame`.
11
+
12
+ <details><summary><h2>Contents</h2></summary>
13
+ <!-- toc -->
14
+ </details>
15
+
16
+ ## Install
17
+ ```sh
18
+ npm i -S @substrate-system/raf-scroll
19
+ ```
20
+
21
+ ## Example
22
+
23
+ ```js
24
+ import { rafScroll } from '@substrate-system/raf-scroll'
25
+
26
+ rafScroll(ev => {
27
+ // this is called at most once per animation frame
28
+ console.log('scroll event', ev)
29
+ })
30
+ ```
31
+
32
+ ## Modules
33
+
34
+ This exposes ESM and common JS via [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
35
+
36
+ ### Bundler
37
+
38
+ Import like normal.
39
+
40
+ ```js
41
+ import { rafScroll } from '@substrate-system/raf-scroll'
42
+ ```
43
+
44
+ ### Minified
45
+
46
+ This package exposes minified JS too. Copy to a location that is
47
+ accessible to your web server, then link to it in HTML.
48
+
49
+ #### copy
50
+ ```sh
51
+ cp ./node_modules/@substrate-system/raf-scroll/dist/index.min.js ./public/raf-scroll.min.js
52
+ ```
53
+
54
+ #### HTML
55
+ ```html
56
+ <script type="module" src="./raf-scroll.min.js"></script>
57
+ ```
58
+
package/dist/index.cjs ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ rafScroll: () => rafScroll
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+ let lastKnownScrollPosition = 0;
26
+ let ticking = false;
27
+ const rafScroll = /* @__PURE__ */ __name(function rafScroll2(cb) {
28
+ document.addEventListener("scroll", onScroll);
29
+ function onScroll() {
30
+ lastKnownScrollPosition = window.scrollY;
31
+ if (!ticking) {
32
+ window.requestAnimationFrame(() => {
33
+ cb(lastKnownScrollPosition);
34
+ ticking = false;
35
+ });
36
+ ticking = true;
37
+ }
38
+ }
39
+ __name(onScroll, "onScroll");
40
+ return /* @__PURE__ */ __name(function Unsubscribe() {
41
+ document.removeEventListener("scroll", onScroll);
42
+ }, "Unsubscribe");
43
+ }, "rafScroll");
44
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJsZXQgbGFzdEtub3duU2Nyb2xsUG9zaXRpb24gPSAwXG5sZXQgdGlja2luZyA9IGZhbHNlXG5cbmludGVyZmFjZSBVbnN1YnNjcmliZSB7XG4gICAgKCk6dm9pZFxufVxuXG5leHBvcnQgY29uc3QgcmFmU2Nyb2xsID0gZnVuY3Rpb24gcmFmU2Nyb2xsIChcbiAgICBjYjooc2Nyb2xsWTpudW1iZXIpPT5hbnlcbik6VW5zdWJzY3JpYmUge1xuICAgIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoJ3Njcm9sbCcsIG9uU2Nyb2xsKVxuXG4gICAgZnVuY3Rpb24gb25TY3JvbGwgKCkge1xuICAgICAgICBsYXN0S25vd25TY3JvbGxQb3NpdGlvbiA9IHdpbmRvdy5zY3JvbGxZXG5cbiAgICAgICAgaWYgKCF0aWNraW5nKSB7XG4gICAgICAgICAgICB3aW5kb3cucmVxdWVzdEFuaW1hdGlvbkZyYW1lKCgpID0+IHtcbiAgICAgICAgICAgICAgICBjYihsYXN0S25vd25TY3JvbGxQb3NpdGlvbilcbiAgICAgICAgICAgICAgICB0aWNraW5nID0gZmFsc2VcbiAgICAgICAgICAgIH0pXG5cbiAgICAgICAgICAgIHRpY2tpbmcgPSB0cnVlXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gZnVuY3Rpb24gVW5zdWJzY3JpYmUgKCkge1xuICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCdzY3JvbGwnLCBvblNjcm9sbClcbiAgICB9XG59XG4iXSwKICAibWFwcGluZ3MiOiAiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBLElBQUksMEJBQTBCO0FBQzlCLElBQUksVUFBVTtBQU1QLE1BQU0sWUFBWSxnQ0FBU0EsV0FDOUIsSUFDVTtBQUNWLFdBQVMsaUJBQWlCLFVBQVUsUUFBUTtBQUU1QyxXQUFTLFdBQVk7QUFDakIsOEJBQTBCLE9BQU87QUFFakMsUUFBSSxDQUFDLFNBQVM7QUFDVixhQUFPLHNCQUFzQixNQUFNO0FBQy9CLFdBQUcsdUJBQXVCO0FBQzFCLGtCQUFVO0FBQUEsTUFDZCxDQUFDO0FBRUQsZ0JBQVU7QUFBQSxJQUNkO0FBQUEsRUFDSjtBQVhTO0FBYVQsU0FBTyxnQ0FBUyxjQUFlO0FBQzNCLGFBQVMsb0JBQW9CLFVBQVUsUUFBUTtBQUFBLEVBQ25ELEdBRk87QUFHWCxHQXJCeUI7IiwKICAibmFtZXMiOiBbInJhZlNjcm9sbCJdCn0K
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ let lastKnownScrollPosition = 0;
4
+ let ticking = false;
5
+ const rafScroll = /* @__PURE__ */ __name(function rafScroll2(cb) {
6
+ document.addEventListener("scroll", onScroll);
7
+ function onScroll() {
8
+ lastKnownScrollPosition = window.scrollY;
9
+ if (!ticking) {
10
+ window.requestAnimationFrame(() => {
11
+ cb(lastKnownScrollPosition);
12
+ ticking = false;
13
+ });
14
+ ticking = true;
15
+ }
16
+ }
17
+ __name(onScroll, "onScroll");
18
+ return /* @__PURE__ */ __name(function Unsubscribe() {
19
+ document.removeEventListener("scroll", onScroll);
20
+ }, "Unsubscribe");
21
+ }, "rafScroll");
22
+ export {
23
+ rafScroll
24
+ };
25
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJsZXQgbGFzdEtub3duU2Nyb2xsUG9zaXRpb24gPSAwXG5sZXQgdGlja2luZyA9IGZhbHNlXG5cbmludGVyZmFjZSBVbnN1YnNjcmliZSB7XG4gICAgKCk6dm9pZFxufVxuXG5leHBvcnQgY29uc3QgcmFmU2Nyb2xsID0gZnVuY3Rpb24gcmFmU2Nyb2xsIChcbiAgICBjYjooc2Nyb2xsWTpudW1iZXIpPT5hbnlcbik6VW5zdWJzY3JpYmUge1xuICAgIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoJ3Njcm9sbCcsIG9uU2Nyb2xsKVxuXG4gICAgZnVuY3Rpb24gb25TY3JvbGwgKCkge1xuICAgICAgICBsYXN0S25vd25TY3JvbGxQb3NpdGlvbiA9IHdpbmRvdy5zY3JvbGxZXG5cbiAgICAgICAgaWYgKCF0aWNraW5nKSB7XG4gICAgICAgICAgICB3aW5kb3cucmVxdWVzdEFuaW1hdGlvbkZyYW1lKCgpID0+IHtcbiAgICAgICAgICAgICAgICBjYihsYXN0S25vd25TY3JvbGxQb3NpdGlvbilcbiAgICAgICAgICAgICAgICB0aWNraW5nID0gZmFsc2VcbiAgICAgICAgICAgIH0pXG5cbiAgICAgICAgICAgIHRpY2tpbmcgPSB0cnVlXG4gICAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gZnVuY3Rpb24gVW5zdWJzY3JpYmUgKCkge1xuICAgICAgICBkb2N1bWVudC5yZW1vdmVFdmVudExpc3RlbmVyKCdzY3JvbGwnLCBvblNjcm9sbClcbiAgICB9XG59XG4iXSwKICAibWFwcGluZ3MiOiAiOztBQUFBLElBQUksMEJBQTBCO0FBQzlCLElBQUksVUFBVTtBQU1QLE1BQU0sWUFBWSxnQ0FBU0EsV0FDOUIsSUFDVTtBQUNWLFdBQVMsaUJBQWlCLFVBQVUsUUFBUTtBQUU1QyxXQUFTLFdBQVk7QUFDakIsOEJBQTBCLE9BQU87QUFFakMsUUFBSSxDQUFDLFNBQVM7QUFDVixhQUFPLHNCQUFzQixNQUFNO0FBQy9CLFdBQUcsdUJBQXVCO0FBQzFCLGtCQUFVO0FBQUEsTUFDZCxDQUFDO0FBRUQsZ0JBQVU7QUFBQSxJQUNkO0FBQUEsRUFDSjtBQVhTO0FBYVQsU0FBTyxnQ0FBUyxjQUFlO0FBQzNCLGFBQVMsb0JBQW9CLFVBQVUsUUFBUTtBQUFBLEVBQ25ELEdBRk87QUFHWCxHQXJCeUI7IiwKICAibmFtZXMiOiBbInJhZlNjcm9sbCJdCn0K
@@ -0,0 +1 @@
1
+ "use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var t=(e,n)=>l(e,"name",{value:n,configurable:!0});var b=(e,n)=>{for(var o in n)l(e,o,{get:n[o],enumerable:!0})},d=(e,n,o,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!f.call(e,r)&&r!==o&&l(e,r,{get:()=>n[r],enumerable:!(c=u(n,r))||c.enumerable});return e};var m=e=>d(l({},"__esModule",{value:!0}),e);var v={};b(v,{rafScroll:()=>w});module.exports=m(v);let s=0,i=!1;const w=t(function(n){document.addEventListener("scroll",o);function o(){s=window.scrollY,i||(window.requestAnimationFrame(()=>{n(s),i=!1}),i=!0)}return t(o,"onScroll"),t(function(){document.removeEventListener("scroll",o)},"Unsubscribe")},"rafScroll");
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var n=(r,e)=>c(r,"name",{value:e,configurable:!0});let t=0,o=!1;const u=n(function(e){document.addEventListener("scroll",l);function l(){t=window.scrollY,o||(window.requestAnimationFrame(()=>{e(t),o=!1}),o=!0)}return n(l,"onScroll"),n(function(){document.removeEventListener("scroll",l)},"Unsubscribe")},"rafScroll");export{u as rafScroll};
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@substrate-system/raf-scroll",
3
+ "description": "Scroll events, debounced with `requestAnimationFrame`",
4
+ "directories": {
5
+ "example": "example",
6
+ "test": "test"
7
+ },
8
+ "type": "module",
9
+ "version": "0.0.2",
10
+ "main": "dist/index.js",
11
+ "files": [
12
+ "./dist/*"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "./min": {
20
+ "import": [
21
+ "./dist/index.min.js"
22
+ ],
23
+ "require": [
24
+ "./dist/index.min.cjs"
25
+ ]
26
+ },
27
+ "./*": {
28
+ "import": [
29
+ "./dist/*.js",
30
+ "./dist/*"
31
+ ],
32
+ "require": [
33
+ "./dist/*.cjs",
34
+ "./dist/*"
35
+ ]
36
+ }
37
+ },
38
+ "scripts": {
39
+ "lint": "eslint \"./**/*.{ts,js}\"",
40
+ "build-tests": "esbuild test/index.ts --target=es2020 --bundle --keep-names > test/test-bundle.js",
41
+ "test": "npm run lint && npm run build",
42
+ "build-cjs": "esbuild src/*.ts --format=cjs --tsconfig=tsconfig.build.json --keep-names --outdir=./dist --out-extension:.js=.cjs --sourcemap=inline",
43
+ "build-esm": "esbuild src/*.ts --format=esm --tsconfig=tsconfig.build.json --keep-names --outdir=./dist --sourcemap=inline",
44
+ "build": "mkdir -p ./dist && rm -rf ./dist/* && npm run build-cjs && npm run build-esm && npm run build:min",
45
+ "build-cjs:min": "esbuild src/*.ts --minify --format=cjs --tsconfig=tsconfig.build.json --keep-names --outdir=./dist --out-extension:.js=.min.cjs",
46
+ "build-esm:min": "esbuild src/*.ts --minify --format=esm --tsconfig=tsconfig.build.json --keep-names --outdir=./dist --out-extension:.js=.min.js",
47
+ "build:min": "npm run build-cjs:min && npm run build-esm:min",
48
+ "start": "vite",
49
+ "toc": "markdown-toc --maxdepth 3 -i README.md",
50
+ "preversion": "npm run lint",
51
+ "version": "npm run toc && auto-changelog -p --template keepachangelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md README.md",
52
+ "postversion": "git push --follow-tags && npm publish",
53
+ "prepublishOnly": "npm run build"
54
+ },
55
+ "devDependencies": {
56
+ "@bicycle-codes/tapzero": "^0.10.0",
57
+ "@nichoth/debug": "^0.6.5",
58
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
59
+ "@typescript-eslint/parser": "^8.0.0",
60
+ "auto-changelog": "^2.4.0",
61
+ "esbuild": "^0.25.0",
62
+ "eslint": "^8.57.0",
63
+ "eslint-config-standard": "^17.1.0",
64
+ "markdown-toc": "^1.2.0",
65
+ "postcss-nesting": "^13.0.0",
66
+ "tap-arc": "^1.2.2",
67
+ "tape-run": "^11.0.0",
68
+ "typescript": "^5.3.3",
69
+ "vite": "^6.0.0"
70
+ },
71
+ "author": "nichoth <nichoth@gmail.com> (https://nichoth.com)",
72
+ "license": "SEE LICENSE IN LICENSE",
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/bicycle-codes/raf-scroll.git"
76
+ },
77
+ "keywords": [
78
+ "request",
79
+ "animation",
80
+ "from",
81
+ "scroll",
82
+ "raf"
83
+ ],
84
+ "bugs": {
85
+ "url": "https://github.com/bicycle-codes/raf-scroll/issues"
86
+ },
87
+ "homepage": "https://github.com/bicycle-codes/raf-scroll#readme"
88
+ }