Skip to content

Commit ddf2f4a

Browse files
committed
First commit
0 parents  commit ddf2f4a

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# FrameRateHelper.js
2+
3+
**FrameRateHelper** is a lightweight, zero-dependency JavaScript utility that calculates the user's display refresh rate and provides a stable, clamped frame duration. It is ideal for synchronizing animations with screen refresh rates for smoother UI interactions.
4+
5+
## Features
6+
7+
- 🔍 Detects real screen refresh rate using `requestAnimationFrame`
8+
- 🧠 Includes fallback to `requestIdleCallback` and `setTimeout`
9+
- 🧱 Clamp logic prevents frame duration spikes on low-power or inactive tabs
10+
- 💡 Asynchronous, event-driven design
11+
- 🪶 No dependencies, pure vanilla JS
12+
13+
---
14+
15+
## Installation
16+
17+
### ✅ CDN
18+
Use directly in HTML via jsDelivr:
19+
20+
```html
21+
<script src="https://cdn.jsdelivr.net/gh/yourusername/FrameRateHelper@1.0.0/dist/FrameRateHelper.js"></script>
22+
```
23+
24+
Or via unpkg:
25+
26+
```html
27+
<script src="https://unpkg.com/framerate-helper@1.0.0/dist/FrameRateHelper.js"></script>
28+
```
29+
30+
### ✅ NPM (for modern build environments)
31+
```bash
32+
npm install framerate-helper
33+
```
34+
35+
Then in your module:
36+
```js
37+
import FrameRateHelper from 'framerate-helper';
38+
```
39+
40+
---
41+
42+
## Usage
43+
44+
### Basic Example
45+
```js
46+
const fps = new FrameRateHelper();
47+
48+
fps.onReady((hz) => {
49+
console.log('Detected refresh rate:', hz.toFixed(2), 'Hz');
50+
console.log('Adjusted duration:', fps.getDuration(300), 'ms');
51+
});
52+
```
53+
54+
---
55+
56+
## API
57+
58+
### `new FrameRateHelper()`
59+
Creates an instance and begins measuring refresh rate immediately.
60+
61+
### `onReady(callback)`
62+
Registers a callback to be called when the refresh rate is determined.
63+
64+
**Parameters:**
65+
- `callback (function)`: Function that receives the detected refresh rate in Hz.
66+
67+
### `getDuration(offset = 0)`
68+
Returns a calculated duration adjusted for the screen's refresh rate.
69+
70+
**Parameters:**
71+
- `offset (number)`: Optional additional duration in milliseconds.
72+
73+
**Returns:**
74+
- `number`: Total adjusted duration in ms
75+
76+
---
77+
78+
## Use Case
79+
80+
Perfect for developers building custom sliders, carousels, animation loops, or precision-based timing utilities where frame-perfect sync matters.
81+
82+
---
83+
84+
## License
85+
86+
MIT License
87+
88+
---
89+
90+
## Author
91+
92+
Developed by **[INFINITUM FORM®](https://infinitumform.com)**
93+
Author: [Ivijan-Stefan Stipić](https://www.linkedin.com/in/ivijanstefanstipic/)
94+
Copyright © 2025 Ivijan-Stefan Stipić. All rights reserved.

dist/FrameRateHelper.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "framerate-helper",
3+
"version": "1.0.0",
4+
"description": "A lightweight utility for estimating screen refresh rate and calculating frame-safe animation durations.",
5+
"main": "dist/FrameRateHelper.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "echo 'No build step yet'",
9+
"test": "echo 'No tests defined'"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/InfinitumForm/FrameRateHelper.git"
14+
},
15+
"keywords": [
16+
"refresh-rate",
17+
"animation",
18+
"frame-duration",
19+
"performance",
20+
"javascript",
21+
"utility",
22+
"frontend",
23+
"jquery",
24+
"react",
25+
"vue"
26+
],
27+
"author": "Ivijan-Stefan Stipić <infinitumform@gmail.com> (https://www.linkedin.com/in/ivijanstefanstipic/)",
28+
"license": "MIT",
29+
"bugs": {
30+
"url": "https://github.com/InfinitumForm/FrameRateHelper/issues"
31+
},
32+
"homepage": "https://github.com/InfinitumForm/FrameRateHelper#readme"
33+
}
34+

src/FrameRateHelper.class.js

Whitespace-only changes.

0 commit comments

Comments
 (0)