A lightweight, zero-dependency analog clock widget built with TypeScript and CSS. Supports two themes (light and dark), optional digit display, smooth second-hand animation, and a simple API for attaching, resizing, pausing, and resuming.
pnpm add simple-watch
# or
npm install simple-watch
# or
yarn add simple-watch<link rel="stylesheet" href="node_modules/simple-watch/css/watch.css" />Or, with a bundler that supports CSS imports:
import 'simple-watch/css';<div class="watch"></div>import { Watch } from 'simple-watch';
const watchEl = document.querySelector('.watch') as HTMLElement;
const watch = new Watch({
size: 300,
theme: 'dark',
showDigits: true,
smooth: true,
});
watch.attach(watchEl);After running pnpm build, reference the bundled output directly:
<link rel="stylesheet" href="css/watch.css" />
<script src="dist/index.global.js"></script>
<script>
const watch = new SimpleWatch.Watch({ theme: 'dark', size: 300 });
watch.attach(document.querySelector('.watch'));
</script>See the example/ folder for a working demo.
Creates a new Watch instance. All configuration options are optional.
| Option | Type | Default | Description |
|---|---|---|---|
smooth |
boolean |
false |
Enables smooth second hand via millisecond interpolation |
size |
number |
300 |
Size of the watch face in pixels |
theme |
'light' | 'dark' |
'light' |
Visual color theme |
showDigits |
boolean |
false |
Show numeric hour labels (1–12) on the watch face |
Renders the watch DOM into el and starts the animation loop. If no element is provided, a new <div> is created and appended to document.body.
Dynamically resizes the watch face to size pixels. Digit font sizes are updated automatically.
Pauses the animation loop. The watch face stays visible but frozen at the last rendered time.
Resumes the animation loop after suspend() has been called.
pnpm install
pnpm build # compile TypeScript → dist/
pnpm lint # run ESLint
pnpm lint:fix # auto-fix ESLint issues
pnpm format # format with Prettier
pnpm format:check # check formatting without writing
pnpm release # run semantic-release locally (CI does this on main)Open example/index.html in a browser after running pnpm build.
This project uses Semantic Release and GitHub Actions to publish GitHub Releases automatically.
- Trigger: every push to
main(including merged PRs) - Output: a new Git tag + GitHub Release with autogenerated notes
- Changelog:
CHANGELOG.mdis updated and committed by the release workflow
Semantic Release determines version bumps from commit messages. Conventional-style commits are recommended (feat:, fix:, etc.).
For this repository, release rules are configured so non-breaking commits also produce at least a patch release on main.
👤 Hajanirina Ridjvan Randrianandraina
Give a ⭐️ if this project helped you!
MIT

