favicon-marquee
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -45,2 +45,10 @@ /** | ||
} | ||
/** | ||
* A scrolling favicon for your website. | ||
* How to use: | ||
* 1. Initialize using the constructor | ||
* const faviconMarquee = new FaviconMarquee(); | ||
* 2. Call its start method | ||
* faviconMarquee.start(); | ||
*/ | ||
export declare class FaviconMarquee { | ||
@@ -55,3 +63,2 @@ private readonly size; | ||
private pixelsScrolled; | ||
private redraws; | ||
private interval?; | ||
@@ -63,3 +70,10 @@ private favicon?; | ||
constructor({ text, font, color, step, size, marginBottom, background, }: FaviconMarqueeParameters); | ||
/** | ||
* Start the marquee at 24 FPS. The refresh interval can be configured using the interval parameter. | ||
* Higher FPS may result in performance issues on low-powered devices. | ||
*/ | ||
start(interval?: number): void; | ||
/** | ||
* Stop the marquee. It can be restarted again using {@link start} | ||
*/ | ||
stop(): void; | ||
@@ -66,0 +80,0 @@ private draw; |
@@ -0,1 +1,9 @@ | ||
/** | ||
* A scrolling favicon for your website. | ||
* How to use: | ||
* 1. Initialize using the constructor | ||
* const faviconMarquee = new FaviconMarquee(); | ||
* 2. Call its start method | ||
* faviconMarquee.start(); | ||
*/ | ||
export class FaviconMarquee { | ||
@@ -11,5 +19,7 @@ constructor({ text = "SCROLLING TEXT", font = '"Arial", sans-serif', color = "green", step = 0.5, size = 32, marginBottom = 0, background, }) { | ||
this.pixelsScrolled = 0; | ||
this.redraws = 0; // counts how many times the same canvas has been used for drawing the favicon | ||
// needed because Firefox slows down horribly when reusing the same canvas too many times | ||
} | ||
/** | ||
* Start the marquee at 24 FPS. The refresh interval can be configured using the interval parameter. | ||
* Higher FPS may result in performance issues on low-powered devices. | ||
*/ | ||
start(interval = 1000 / 24) { | ||
@@ -23,2 +33,5 @@ this.favicon = document.createElement("link"); | ||
} | ||
/** | ||
* Stop the marquee. It can be restarted again using {@link start} | ||
*/ | ||
stop() { | ||
@@ -29,9 +42,2 @@ clearInterval(this.interval); | ||
draw() { | ||
if (this.redraws === 500) { | ||
// make a new canvas every 500 redraws | ||
// this number is high enough to avoid frequent garbage collection | ||
// but low enough to avoid Firefox performance problems | ||
this.createCanvas(); | ||
this.redraws = 0; | ||
} | ||
if (this.ctx === undefined || | ||
@@ -74,5 +80,4 @@ this.textWidth === undefined || | ||
this.textWidth = Math.ceil(this.ctx.measureText(this.text).width); | ||
this.redraws++; | ||
} | ||
} | ||
export default FaviconMarquee; |
{ | ||
"name": "favicon-marquee", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "An animated scrolling favicon for your website", | ||
@@ -5,0 +5,0 @@ "author": "Sten Laane <sten@laane.xyz> (https://laane.xyz)", |
# favicon-marquee | ||
![Scrolling text example 1](https://i.imgur.com/o3f9cWL.gif) | ||
![Scrolling text example 1](./examples/scrolling-example-1.gif) | ||
![Scrolling text example 2](https://i.imgur.com/OFJRjuK.gif) | ||
![Scrolling text example 2](./examples/scrolling-example-2.gif) | ||
@@ -33,3 +33,3 @@ > A <5 kB JavaScript class with no dependencies that adds an animated scrolling | ||
<script type="module"> | ||
import FaviconMarquee from "https://cdn.jsdelivr.net/npm/favicon-marquee@1.2.0/lib/main.js"; | ||
import FaviconMarquee from "https://cdn.jsdelivr.net/npm/favicon-marquee@1.2.2/lib/main.js"; | ||
// ... | ||
@@ -84,3 +84,5 @@ </script> | ||
``` | ||
`marquee.stop()` can be used to stop the marquee at any time, after which it can be restarted again with `marquee.start()`. | ||
## Contributing and Issues | ||
@@ -87,0 +89,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10841
159
94
0