analog-clock-lib
v2.0.1
Published
Lightweight TypeScript library to render an analog clock using HTML Canvas
Maintainers
Readme
analog-clock-lib
A small TypeScript library to render a customizable analog clock using an HTML Canvas element.
Features
- Lightweight and dependency-free
- Configurable size, themes and display options
- Simple API: create, start, stop, update options
- Written in TypeScript (types included)
Quick install
npm install analog-clock-libQuick usage
<div id="clock"></div>
<script type="module">
import { AnalogClock } from "analog-clock-lib";
const container = document.getElementById('clock');
const clock = new AnalogClock(container!, {
size: 220,
showNumbers: true,
theme: {
face: '#ffffff',
border: '#333333',
hourHand: '#333333',
minuteHand: '#333333',
secondHand: '#d23f3f'
}
});
clock.start();
</script>API
new AnalogClock(container: HTMLElement, options?: AnalogClockOptions)— create a clock instancestart()— begin the animation loopstop()— stop the animationsetTime(date: Date)— manually set displayed time (optional)updateOptions(opts: Partial<AnalogClockOptions>)— update configuration
