npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@blcklab/helios

v1.1.2

Published

Astronomy engine for sunrise, sunset, golden hour, and solar calculations

Readme

Helios

A lightweight JavaScript library for deterministic solar modeling in real-time graphics and simulation.

Helios calculates precise sun positions, solar events, and derived lighting conditions from geographic coordinates and time. Built as a zero-dependency computation layer for Three.js, Babylon.js, WebGL, and modern edge runtimes.

Pure, stateless, and framework-agnostic.


System Overview

Input:

  • geographic coordinates (lat, lng)
  • temporal state (Date)

Output:

  • solar event timeline
  • directional sun vector
  • empirical light model

Mapping:

(lat, lng, t)
    ↓
solar ephemeris model
    ↓
scene-relevant state vector

Installation

npm install @blcklab/helios

Using Yarn:

yarn add @blcklab/helios

Using pnpm:

pnpm add @blcklab/helios

Integration Example (Three.js)

import { getTimes } from "@blcklab/helios";

const sun = getTimes({
  lat: 14.4297,
  lng: 120.9367,
  date: new Date(),
});

// Directional light orientation
directionalLight.position.set(
  sun.direction.x,
  sun.direction.y,
  sun.direction.z
);

directionalLight.intensity = sun.light.intensity;

Integration Example (Babylon.js)

import { getTimes } from "@blcklab/helios";

const sun = getTimes({
  lat: 14.4297,
  lng: 120.9367
});

light.direction = new BABYLON.Vector3(
  sun.direction.x,
  sun.direction.y,
  sun.direction.z
);

light.intensity = sun.light.intensity;

Core API

getTimes(options)

Evaluates the full solar and lighting state for a given spatiotemporal input.

type GetTimesOptions = {
  lat: number;
  lng: number;
  date?: Date;
};

Returns a flat SunTimes schema containing ephemeris metrics alongside derived lighting values.


helios(lat, lng)

Stateful factory wrapper bound to a fixed spatial coordinate, ideal for repeated evaluations.

import { helios } from "@blcklab/helios";

const solarCalculator = helios(14.4297, 120.9367);

Methods:

  • .now() → Evaluates the current solar state.
  • .at(date) → Evaluates the state at a specific time.
  • .getTimes(date?) → Synonym method returning full state evaluation.
  • .position(date?) → Directly yields the raw spherical SunPosition ({ altitude, azimuth }).

Solar State Model Reference

When running getTimes(), the returned evaluation follows this strict structure:

{
  dawn: Date,           // Civil dawn (Sun reaches -6° altitude)
  sunrise: Date,        // Sunrise marker
  solarNoon: Date,      // Sun reaches its highest zenith point
  sunset: Date,         // Sunset marker
  dusk: Date,           // Civil dusk (Sun reaches -6° altitude)

  dayLength: number,    // Daylight duration in milliseconds
  sunProgress: number,  // Day progression index normalized 0 (sunrise) to 1 (sunset)

  phase: 'night' | 'dawn' | 'morning' | 'day' | 'sunset',

  position: {
    altitude: number,   // Height above horizon in degrees (0° = horizon, 90° = overhead)
    azimuth: number     // Compass bearing in degrees clockwise from North (0° = N, 90° = E)
  },

  direction: {
    x: number,          // Right-Handed Cartesian Unit Vectors
    y: number,          // Orientation is Y-Up oriented by default
    z: number           // Represents normalized direction of incident solar vector
  },

  light: {
    intensity: number,        // Derived illumination scalar mapping ∈ [0, 1]
    colorTemperature: number, // Estimated Kelvin rating (2000K = orange sunset, 6500K = white daylight)
    rgb: { r: number, g: number, b: number } // Normalized linear RGB approximation [0, 1]
  },

  civilTwilight: {
    morning: { start: Date, end: Date },
    evening: { start: Date, end: Date }
  },

  isDay: boolean,       // Flag verifying if sun is above horizon
  isNight: boolean      // Flag verifying if sun is below horizon
}

Frame Update Pattern

Helios is highly optimized for per-frame animation and simulation cycles. Instantiating the context once outside the loop ensures there are zero runtime object mutations or garbage collection spikes:

// Instantiate once outside your animation loop
const solarCalculator = helios(lat, lng);

function update() {
  requestAnimationFrame(update);

  // O(1) stateless evaluation using the pre-bound target coordinate
  const sun = solarCalculator.now();

  directionalLight.position.set(
    sun.direction.x,
    sun.direction.y,
    sun.direction.z
  );

  directionalLight.intensity = sun.light.intensity;
}

Computational Properties

  • Complexity: O(1) uniform footprint per evaluation.
  • Side-Effect Free: Pure mathematical transformations with no hidden runtime states.
  • No Network IO: Zero external runtime dependencies or API requests.
  • Deterministic: Replicable, uniform output values matching specific target inputs.

Coordinate Conventions

  • Right-handed Cartesian coordinate layout.
  • Default Y-up spatial orientation (engine-dependent transformations allowed).
  • Azimuth measured clockwise from geographic true North.

System Applications

  • Game Engines & Real-time Visuals: Real-time day/night loops, physically-inspired atmospheric lighting models, and procedural environment configurations.
  • Simulations & Virtual Twins: GIS visual analytics, virtual reality worlds, and location-synchronized architecture previews.
  • Smart Ecosystem Automation: Coordinating dynamic hardware lighting rules or sunrise/sunset behaviors alongside native environmental cycles.

Module Support

Helios provides cross-environment support across modern environments and runtimes:

ESM

import { getTimes } from "@blcklab/helios";

CommonJS

const { getTimes } = require("@blcklab/helios");

Design Constraints

  • No rendering or layout responsibilities.
  • No environment I/O, storage access, or network calls.
  • No internal state mutation flags inside standard math calculators.

License

MIT © Black Lab