world-clock-strip
v0.2.2
Published
Reusable world clock strip extracted from the Dashboard web app.
Maintainers
Readme
World Clock Strip
Reusable world-clock-strip web component extracted from the Dashboard web app. It ships with animated weather art, moving day-cycle background, editable locations, sharing tools, presets, and a bottom config drawer.
Features
- Shadow DOM custom element:
world-clock-strip - Default cities: Las Vegas, Israel, New Delhi, Macau, Sydney
- Built-in client-side weather via Open-Meteo
- Optional backend weather endpoint override
- Shareable URL state
- JSON import/export
- Saved presets in local storage
- Optional persistent local config
- Optional read-only mode
- Visual presets:
default,minimal,cinematic,wallboard configchangeevent for host apps
Install
Install from npm:
npm install world-clock-stripIf you want to install directly from GitHub instead:
npm install git+ssh://[email protected]/steve777/World-Clock.gitFor local development in this repo:
npm installRun
npm run devOpen http://127.0.0.1:4173.
Build
npm run buildnpm run build:demonpm run testnpm run test:packageBasic Usage
import { defineWorldClockStrip } from "world-clock-strip";
defineWorldClockStrip();<world-clock-strip></world-clock-strip>Imperative Usage
import { createWorldClockStrip } from "world-clock-strip";
const clock = createWorldClockStrip({
locations: [
{ label: "Las Vegas", timeZone: "America/Los_Angeles", weatherQuery: "Las Vegas, Nevada" },
{ label: "London", timeZone: "Europe/London", weatherQuery: "London, United Kingdom" }
],
weatherEnabled: true,
visualPreset: "cinematic",
persistKey: "executive-clock",
enableUrlState: true,
});
document.body.append(clock);Public API
Exports:
defineWorldClockStrip()createWorldClockStrip()normalizeClockLocations()serializeWorldClockConfig()deserializeWorldClockConfig()defaultClockLocations
Types:
ClockLocationClockWeatherSnapshotCommonClockCityVisualPresetWorldClockConfigWorldClockStripOptions
Config Options
WorldClockStripOptions supports:
locationsweatherEnabledweatherEndpointweatherAssetBaseUrlweatherOverridesvisualPresetreadOnlypersistKeyenableUrlStateshareQueryParamcityCatalog
Temperature units are automatic:
- U.S. system time zones show
F - all other system time zones show
C
Sharing
The drawer supports:
Share: copies a URL with encoded clock configJSON: copy current config JSON or import oneSaved presets: save, load, and delete local presets
You can also use the helpers directly:
import {
serializeWorldClockConfig,
deserializeWorldClockConfig,
} from "world-clock-strip";Events
The component dispatches configchange:
clock.addEventListener("configchange", (event) => {
const detail = (event as CustomEvent).detail;
console.log(detail.config, detail.source);
});detail.source is one of:
apidrawerurlstoragepresetattribute
Read-Only Mode
Hide the config drawer entirely:
<world-clock-strip read-only></world-clock-strip>Or:
clock.readOnly = true;Weather Source
Most apps do not need a backend endpoint. If weatherEnabled is on and weatherEndpoint is blank, the component fetches weather itself.
If your app already has a backend route:
clock.weatherEndpoint = "/api/weather/clocks";By default, the published package loads weather art from the package CDN so installed consumers render correctly without extra asset copying.
If you want to self-host the weather art instead:
clock.weatherAssetBaseUrl = "/vendor/world-clock/weather/";Docker
docker build -t world-clock-strip .
docker run --rm -p 4173:4173 world-clock-stripNotes
- The drawer stores presets in local storage.
persistKeystores the current config in local storage.- If both persisted state and shared URL state exist, the shared URL wins.
- The weather art bundle is much smaller than before, but the package still benefits from continued asset optimization.
npm run test:packagevalidates the packed tarball in a clean temporary install.
