favicon-marquee
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,33 +0,1 @@ | ||
type Renderer = import("./types").Renderer; | ||
type DataMessage = import("./types").DataMessage; | ||
type FaviconMarqueeParameters = import("./types").FaviconMarqueeParameters; | ||
type State = import("./types").State; | ||
type Message = import("./types").Message; | ||
declare const CANVAS_SIZE = 256; | ||
declare class CanvasPainter { | ||
private readonly text; | ||
private readonly color; | ||
private readonly stepSize; | ||
private readonly font; | ||
private readonly marginBottom; | ||
private readonly background?; | ||
private readonly textWidth; | ||
private pixelsScrolled; | ||
private renderingContext; | ||
constructor({ text, font, color, step, marginBottom, background, }: FaviconMarqueeParameters, renderingContext: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D); | ||
step(): void; | ||
} | ||
declare class OffscreenCanvasRenderer implements Renderer { | ||
private readonly canvas; | ||
private readonly canvasDrawer; | ||
private state; | ||
constructor(parameters: FaviconMarqueeParameters); | ||
start(): void; | ||
/** | ||
* Stop the marquee. It can be restarted again using {@link start} | ||
*/ | ||
stop(): void; | ||
private getDataUrl; | ||
private handleDataUrl; | ||
} | ||
declare let renderer: OffscreenCanvasRenderer | undefined; | ||
export {}; |
@@ -1,47 +0,4 @@ | ||
"use strict"; | ||
// Currently, when any values are imported using normal 'import { x } from "y"' code, TypeScript generates ESM code for this file. | ||
// Since Firefox does not support ESM workers, nothing can be imported like normal. | ||
// TODO when Firefox starts supporting ESM workers (https://stackoverflow.com/a/45578811, expected March 2023): | ||
// 1. Import the types like normal | ||
// 2. Create a "module" type worker in main.ts | ||
// 3. Stop duplicating the CanvasDrawer class code, instead import it and CANVAS_SIZE from canvasPainter.ts | ||
// 4. Use enum values for OffscreenCanvasRenderer's state | ||
import { CanvasPainter } from "./canvasPainter.js"; | ||
import { State } from "./types.js"; | ||
const CANVAS_SIZE = 256; | ||
class CanvasPainter { | ||
text; | ||
color; | ||
stepSize; | ||
font; | ||
marginBottom; | ||
background; | ||
textWidth; | ||
pixelsScrolled; | ||
renderingContext; | ||
constructor({ text = "SCROLLING TEXT", font = '"Arial", sans-serif', color = "green", step = 0.75, marginBottom = 0, background, }, renderingContext) { | ||
this.text = text; | ||
this.color = color; | ||
this.stepSize = step; | ||
this.font = font; | ||
this.marginBottom = marginBottom; | ||
this.background = background; | ||
this.pixelsScrolled = 0; | ||
this.renderingContext = renderingContext; | ||
this.renderingContext.font = CANVAS_SIZE + "px " + this.font; | ||
this.textWidth = Math.ceil(this.renderingContext.measureText(this.text).width); | ||
} | ||
step() { | ||
if (this.background) { | ||
this.renderingContext.fillStyle = this.background; | ||
this.renderingContext.fillRect(0, 0, CANVAS_SIZE, CANVAS_SIZE); | ||
} | ||
else { | ||
this.renderingContext.clearRect(0, 0, CANVAS_SIZE, CANVAS_SIZE); | ||
} | ||
this.pixelsScrolled = (this.pixelsScrolled + this.stepSize) % (this.textWidth + 2 * CANVAS_SIZE); | ||
this.renderingContext.fillStyle = this.color; | ||
const widthOffset = -1 * this.pixelsScrolled + CANVAS_SIZE; // negation of pixelsScrolled because canvas scrolls left-to-right | ||
// then add CANVAS_SIZE to begin rendering with blank canvas | ||
this.renderingContext.fillText(this.text, widthOffset, CANVAS_SIZE - this.marginBottom); | ||
} | ||
} | ||
class OffscreenCanvasRenderer { | ||
@@ -58,9 +15,9 @@ canvas; | ||
this.canvasDrawer = new CanvasPainter(parameters, renderingContext); | ||
this.state = 0; | ||
this.state = State.Stopped; | ||
} | ||
start() { | ||
if (this.state == 1) { | ||
if (this.state == State.Running) { | ||
return; | ||
} | ||
this.state = 1; | ||
this.state = State.Running; | ||
const render = async () => { | ||
@@ -80,3 +37,3 @@ if (this.state === 1) { | ||
stop() { | ||
this.state = 0; | ||
this.state = State.Stopped; | ||
} | ||
@@ -83,0 +40,0 @@ async getDataUrl() { |
@@ -6,3 +6,3 @@ export class WorkerRenderer { | ||
constructor(parameters, favicon) { | ||
this.worker = new Worker(new URL("./worker.js", import.meta.url)); | ||
this.worker = new Worker(new URL("./worker.js", import.meta.url), { type: "module" }); | ||
this.parameters = parameters; | ||
@@ -9,0 +9,0 @@ this.favicon = favicon; |
{ | ||
"name": "favicon-marquee", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "An animated scrolling favicon for your website", | ||
@@ -8,4 +8,6 @@ "author": "Sten Laane <sten@laane.xyz> (https://laane.xyz)", | ||
"types": "lib/main.d.ts", | ||
"type": "module", | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"!lib/**/__tests__/**/*" | ||
], | ||
@@ -16,9 +18,11 @@ "scripts": { | ||
"format:fix": "prettier --write src/**/*", | ||
"prepublishOnly": "npm run compile" | ||
"prepublishOnly": "npm run compile", | ||
"test": "tsc && docker compose -f src/__tests__/docker-compose.yml up --abort-on-container-exit" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@typescript/lib-dom": "npm:@types/web@^0.0.90", | ||
"@types/selenium-webdriver": "^4.1.15", | ||
"prettier": "^2.8.3", | ||
"typescript": "^4.9.4" | ||
"selenium-webdriver": "^4.10.0", | ||
"typescript": "~5.1.3" | ||
}, | ||
@@ -25,0 +29,0 @@ "repository": "https://github.com/StenAL/favicon-marquee", |
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
0
Yes
18109
4
15
387