From 40a30523207d203510ffa09c6e3e07a21dd52098 Mon Sep 17 00:00:00 2001 From: Sergio Cinos Date: Tue, 5 Nov 2024 23:08:04 +0100 Subject: [PATCH] Use yarn patch to patch suncalc3 instead of having a hard copy (#155) --- .../suncalc3-npm-2.0.5-9cdae05f76.patch | 63 + package.json | 2 +- suncalc3/LICENSE | 22 - suncalc3/README-HORIZON-CARD.md | 25 - suncalc3/README.md | 621 -------- suncalc3/package.json | 234 --- suncalc3/suncalc.js | 1251 ----------------- yarn.lock | 11 +- 8 files changed, 70 insertions(+), 2159 deletions(-) create mode 100644 .yarn/patches/suncalc3-npm-2.0.5-9cdae05f76.patch delete mode 100644 suncalc3/LICENSE delete mode 100644 suncalc3/README-HORIZON-CARD.md delete mode 100644 suncalc3/README.md delete mode 100644 suncalc3/package.json delete mode 100644 suncalc3/suncalc.js diff --git a/.yarn/patches/suncalc3-npm-2.0.5-9cdae05f76.patch b/.yarn/patches/suncalc3-npm-2.0.5-9cdae05f76.patch new file mode 100644 index 0000000..fcdc3af --- /dev/null +++ b/.yarn/patches/suncalc3-npm-2.0.5-9cdae05f76.patch @@ -0,0 +1,63 @@ +diff --git a/suncalc.js b/suncalc.js +index bcd8a159e55c63e21dfd93f262ecca46b04b3733..d0a9d3b16fc993cc2d063011019498050935c1bc 100644 +--- a/suncalc.js ++++ b/suncalc.js +@@ -543,7 +543,7 @@ + * @param {boolean} [inUTC=false] defines if the calculation should be in utc or local time (default is local) + * @return {ISunTimeList} result object of sunTime + */ +- SunCalc.getSunTimes = function (dateValue, lat, lng, height, addDeprecated, inUTC) { ++ SunCalc.getSunTimes = function (dateValue, lat, lng, height, addDeprecated, inUTC, dateAsIs) { + // console.log(`getSunTimes dateValue=${dateValue} lat=${lat}, lng=${lng}, height={height}, noDeprecated=${noDeprecated}`); + if (isNaN(lat)) { + throw new Error('latitude missing'); +@@ -552,11 +552,16 @@ + throw new Error('longitude missing'); + } + // @ts-ignore +- const t = new Date(dateValue); +- if (inUTC) { +- t.setUTCHours(12, 0, 0, 0); ++ let t ++ if (dateAsIs) { ++ t = dateValue + } else { +- t.setHours(12, 0, 0, 0); ++ t = new Date(dateValue); ++ if (inUTC) { ++ t.setUTCHours(12, 0, 0, 0); ++ } else { ++ t.setHours(12, 0, 0, 0); ++ } + } + + const lw = rad * -lng; +@@ -1064,18 +1069,23 @@ + * @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is local) + * @return {IMoonTimes} result object of sunTime + */ +- SunCalc.getMoonTimes = function (dateValue, lat, lng, inUTC) { ++ SunCalc.getMoonTimes = function (dateValue, lat, lng, inUTC, dateAsIs) { + if (isNaN(lat)) { + throw new Error('latitude missing'); + } + if (isNaN(lng)) { + throw new Error('longitude missing'); + } +- const t = new Date(dateValue); +- if (inUTC) { +- t.setUTCHours(0, 0, 0, 0); ++ let t ++ if (dateAsIs) { ++ t = dateValue + } else { +- t.setHours(0, 0, 0, 0); ++ t = new Date(dateValue); ++ if (inUTC) { ++ t.setUTCHours(0, 0, 0, 0); ++ } else { ++ t.setHours(0, 0, 0, 0); ++ } + } + dateValue = t.valueOf(); + // console.log(`getMoonTimes lat=${lat} lng=${lng} dateValue=${dateValue} t=${t}`); diff --git a/package.json b/package.json index 45202df..6f41ce0 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "dependencies": { "custom-card-helpers": "^1.8.0", "lit": "^2.7.2", - "suncalc3": "link:suncalc3" + "suncalc3": "patch:suncalc3@npm%3A2.0.5#~/.yarn/patches/suncalc3-npm-2.0.5-9cdae05f76.patch" }, "resolutions": { "@formatjs/intl-utils": "npm:empty-npm-package@1.0.0" diff --git a/suncalc3/LICENSE b/suncalc3/LICENSE deleted file mode 100644 index 91a7b5e..0000000 --- a/suncalc3/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2014, Vladimir Agafonkin -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are -permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/suncalc3/README-HORIZON-CARD.md b/suncalc3/README-HORIZON-CARD.md deleted file mode 100644 index 0ece3d7..0000000 --- a/suncalc3/README-HORIZON-CARD.md +++ /dev/null @@ -1,25 +0,0 @@ -# Local copy of suncalc3 - -This is a copy of module suncalc3 v2.0.5 with some minor modifications to improve its time zone handling. - -Be careful if you feel you need to make adjustments in it. - -## Modifications - -`SunCalc.getSunTimes` and `SunCalc.getMoonTimes` - added additional argument `dateAsIs`, that makes the function use the provided `dateValue` as is, instead of using non-TZ friendly logic to set the time part of the value to noon. - -```js -SunCalc.getSunTimes = function (dateValue, lat, lng, height, addDeprecated, inUTC, dateAsIs) = { - ... -} - -SunCalc.getMoonTimes = function (dateValue, lat, lng, inUTC, dateAsIs) = { - ... -} -``` - -## References - -- https://github.com/hypnos3/suncalc3 -- https://yarn.pm/suncalc3 -- https://www.npmjs.com/package/suncalc3 diff --git a/suncalc3/README.md b/suncalc3/README.md deleted file mode 100644 index b7584a9..0000000 --- a/suncalc3/README.md +++ /dev/null @@ -1,621 +0,0 @@ - -SunCalc -======= -[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/hypnos3/suncalc3/graphs/commit-activity) -[![npm version](https://badge.fury.io/js/suncalc3.svg)](https://badge.fury.io/js/suncalc3) -[![Issues](https://img.shields.io/github/issues/hypnos3/suncalc3.svg?style=flat-square)](https://github.com/hypnos3/suncalc3/issues) -[![code style](https://img.shields.io/badge/Code%20Style-eslint-green.svg)](https://eslint.org/) -[![NPM](https://nodei.co/npm/suncalc3.png)](https://nodei.co/npm/suncalc3/) - - -SunCalc is a tiny BSD-licensed JavaScript library for calculating sun position, -sunlight phases (times for sunrise, sunset, dusk, etc.), -moon position and lunar phase for the given location and time, -created by [Vladimir Agafonkin](http://agafonkin.com/en) ([@mourner](https://github.com/mourner)) -as a part of the [SunCalc.net project](http://suncalc.net). -This version is reworked and enhanced by [@hypnos3](https://github.com/hypnos3). The output of the function is changed in the most times to objects with enhanced properies. - -Most calculations are based on the formulas given in the excellent Astronomy Answers articles -about [position of the sun](http://aa.quae.nl/en/reken/zonpositie.html) -and [the planets](http://aa.quae.nl/en/reken/hemelpositie.html). -You can read about different twilight phases calculated by SunCalc -in the [Twilight article on Wikipedia](http://en.wikipedia.org/wiki/Twilight). - -## table of contents - -- [SunCalc](#suncalc) - - [table of contents](#table-of-contents) - - [changed in this library](#changed-in-this-library) - - [Usage example](#usage-example) - - [Reference](#reference) - - [Sunlight times](#sunlight-times) - - [adding / getting own Sunlight times](#adding--getting-own-sunlight-times) - - [get specific Sunlight time](#get-specific-sunlight-time) - - [get Sunlight time for a given azimuth angle for a given date](#get-sunlight-time-for-a-given-azimuth-angle-for-a-given-date) - - [getting solar time](#getting-solar-time) - - [Sun position](#sun-position) - - [Moon position](#moon-position) - - [Moon illumination](#moon-illumination) - - [Moon illumination, position and zenith angle](#moon-illumination-position-and-zenith-angle) - - [Moon rise and set times](#moon-rise-and-set-times) - - [Moon transit](#moon-transit) - - [Changelog](#changelog) - - [2.0.5 — April 04, 2022](#205--april-04-2022) - - [2.0.4 — April 04, 2022](#204--april-04-2022) - - [2.0.2 — March 29, 2022](#202--march-29-2022) - - [2.0.1 — March 13, 2022](#201--march-13-2022) - - [2.0.0 — March 13, 2022](#200--march-13-2022) - - [1.8.0 — Dec 22, 2016](#180--dec-22-2016) - - [1.7.0 — Nov 11, 2015](#170--nov-11-2015) - - [1.6.0 — Oct 27, 2014](#160--oct-27-2014) - - [1.5.1 — May 16, 2014](#151--may-16-2014) - - [1.4.0 — Apr 10, 2014](#140--apr-10-2014) - - [1.3.0 — Feb 21, 2014](#130--feb-21-2014) - - [1.2.0 — Mar 07, 2013](#120--mar-07-2013) - - [1.1.0 — Mar 06, 2013](#110--mar-06-2013) - - [1.0.0 — Dec 07, 2011](#100--dec-07-2011) - - [0.0.0 — Aug 25, 2011](#000--aug-25-2011) - -## changed in this library - -| function names of original SunCalc | changes in this library | -|-------------------------------------|---------------------------| -| SunCalc.getTimes | SunCalc.getSunTimes | - -| name of the manes of original SunCalc | changes in this library | -|----------------------------------------|---------------------------| -| sunrise | sunriseEnd | -| sunset | sunsetStart | -| dawn | civilDawn | -| dusk | civilDusk | -| night | astronomicalDusk | -| nightEnd | astronomicalDawn | -| goldenHour | goldenHourDuskStart | -| goldenHourEnd | goldenHourDawnEnd | - -Additional are the output of the function is changed in the most times to objects with more properies. Also JSDOC is added ans type script definitions. - -## Usage example - -```javascript -// get today's sunlight times for London -let times = SunCalc.getSunTimes(new Date(), 51.5, -0.1); - -// format sunrise time from the Date object -let sunriseStr = times.sunriseStart.getHours() + ':' + times.sunrise.getMinutes(); - -// get position of the sun (azimuth and altitude) at today's sunrise -let sunrisePos = SunCalc.getPosition(times.sunrise, 51.5, -0.1); - -// get sunrise azimuth in degrees -let sunriseAzimuth = sunrisePos.azimuth * 180 / Math.PI; -``` - -SunCalc is also available as an NPM package: - -```bash -$ npm install suncalc3 -``` - -```js -let SunCalc = require('suncalc3'); -``` - -## Reference - -### Sunlight times - -```javascript -/** - * calculates sun times for a given date and latitude/longitude - * @param {number|Date} dateValue Date object or timestamp for calculating sun-times - * @param {number} lat latitude for calculating sun-times - * @param {number} lng longitude for calculating sun-times - * @param {number} [height=0] the observer height (in meters) relative to the horizon - * @param {boolean} [addDeprecated=false] if true to times from timesDeprecated array will be added to the object - * @param {boolean} [inUTC=false] defines if the calculation should be in utc or local time (default is local) - * @return {ISunTimeList} result object of sunTime - */ -SunCalc.getSunTimes(dateValue, lat, lng, height, addDeprecated, inUTC) -``` - -Returns an object with the following properties: - -```javascript -/** -* @typedef {Object} ISunTimeList -* @property {ISunTimeDef} solarNoon - The sun-time for the solar noon (sun is in the highest position) -* @property {ISunTimeDef} nadir - The sun-time for nadir (darkest moment of the night, sun is in the lowest position) -* @property {ISunTimeDef} goldenHourDawnStart - The sun-time for morning golden hour (soft light, best time for photography) -* @property {ISunTimeDef} goldenHourDawnEnd - The sun-time for morning golden hour (soft light, best time for photography) -* @property {ISunTimeDef} goldenHourDuskStart - The sun-time for evening golden hour starts -* @property {ISunTimeDef} goldenHourDuskEnd - The sun-time for evening golden hour starts -* @property {ISunTimeDef} sunriseStart - The sun-time for sunrise starts (top edge of the sun appears on the horizon) -* @property {ISunTimeDef} sunriseEnd - The sun-time for sunrise ends (bottom edge of the sun touches the horizon) -* @property {ISunTimeDef} sunsetStart - The sun-time for sunset starts (bottom edge of the sun touches the horizon) -* @property {ISunTimeDef} sunsetEnd - The sun-time for sunset ends (sun disappears below the horizon, evening civil twilight starts) -* @property {ISunTimeDef} blueHourDawnStart - The sun-time for blue Hour start (time for special photography photos starts) -* @property {ISunTimeDef} blueHourDawnEnd - The sun-time for blue Hour end (time for special photography photos end) -* @property {ISunTimeDef} blueHourDuskStart - The sun-time for blue Hour start (time for special photography photos starts) -* @property {ISunTimeDef} blueHourDuskEnd - The sun-time for blue Hour end (time for special photography photos end) -* @property {ISunTimeDef} civilDawn - The sun-time for dawn (morning nautical twilight ends, morning civil twilight starts) -* @property {ISunTimeDef} civilDusk - The sun-time for dusk (evening nautical twilight starts) -* @property {ISunTimeDef} nauticalDawn - The sun-time for nautical dawn (morning nautical twilight starts) -* @property {ISunTimeDef} nauticalDusk - The sun-time for nautical dusk end (evening astronomical twilight starts) -* @property {ISunTimeDef} amateurDawn - The sun-time for amateur astronomical dawn (sun at 12° before sunrise) -* @property {ISunTimeDef} amateurDusk - The sun-time for amateur astronomical dusk (sun at 12° after sunrise) -* @property {ISunTimeDef} astronomicalDawn - The sun-time for night ends (morning astronomical twilight starts) -* @property {ISunTimeDef} astronomicalDusk - The sun-time for night starts (dark enough for astronomical observations) -* @property {ISunTimeDef} [dawn] - Deprecated: alternate for civilDawn -* @property {ISunTimeDef} [dusk] - Deprecated: alternate for civilDusk -* @property {ISunTimeDef} [nightEnd] - Deprecated: alternate for astronomicalDawn -* @property {ISunTimeDef} [night] - Deprecated: alternate for astronomicalDusk -* @property {ISunTimeDef} [nightStart] - Deprecated: alternate for astronomicalDusk -* @property {ISunTimeDef} [goldenHour] - Deprecated: alternate for goldenHourDuskStart -* @property {ISunTimeDef} [sunset] - Deprecated: alternate for sunsetEnd -* @property {ISunTimeDef} [sunrise] - Deprecated: alternate for sunriseStart -* @property {ISunTimeDef} [goldenHourEnd] - Deprecated: alternate for goldenHourDawnEnd -* @property {ISunTimeDef} [goldenHourStart] - Deprecated: alternate for goldenHourDuskStart -*/ -``` - -These properties contains the sun times for these given times: - -| Property | Description | SunBH | -| ------------------- | ------------------------------------------------------------------------ | ----- | -| `astronomicalDawn` | night ends (morning astronomical twilight starts) | 18 | -| `amateurDawn` | amateur astronomical dawn (sun at 12° before sunrise) | 15 | -| `nauticalDawn` | nautical dawn (morning nautical twilight starts) | 12 | -| `blueHourDawnStart` | blue Hour start (time for special photography photos starts) | 8 | -| `civilDawn` | dawn (morning nautical twilight ends, morning civil twilight starts) | 6 | -| `blueHourDawnEnd` | blue Hour end (time for special photography photos end) | 4 | -| `goldenHourDawnStart` | morning golden hour (soft light, best time for photography) starts | -1 | -| `sunriseStart` | sunrise (top edge of the sun appears on the horizon) | 0.833 | -| `sunriseEnd` | sunrise ends (bottom edge of the sun touches the horizon) | 0.3 | -| `goldenHourDawnEnd` | morning golden hour (soft light, best time for photography) ends | -6 | -| `solarNoon` | solar noon (sun is in the highest position) | | -| `goldenHourDuskStart` | evening golden hour (soft light, best time for photography) starts | -6 | -| `sunsetStart` | sunset starts (bottom edge of the sun touches the horizon) | 0.3 | -| `sunsetEnd` | sunset (sun disappears below the horizon, evening civil twilight starts) | 0.833 | -| `goldenHourDuskEnd` | evening golden hour (soft light, best time for photography) ends | 1 | -| `blueHourDuskStart` | blue Hour start (time for special photography photos starts) | 4 | -| `civilDusk` | dusk (evening nautical twilight starts) | 6 | -| `blueHourDuskEnd` | blue Hour end (time for special photography photos end) | 8 | -| `nauticalDusk` | nautical dusk end (evening astronomical twilight starts) | 12 | -| `amateurDusk` | amateur astronomical dusk (sun at 12° after sunrise) | 15 | -| `astronomicalDusk` | night starts (dark enough for astronomical observations) | 18 | -| `nadir` | nadir (darkest moment of the night, sun is in the lowest position) | | - -SunBH is the angle of the sun below the horizon - -If `addDeprecated` is `true`, the object will have additional objects, with the same properties as other properties. This is to have backwards compatibility to original suncalc library. - -| Property | will equal to | -| ------------------- | ------------------------------------------------------------------------ | -| `dawn` | `civilDawn` | -| `dusk` | `civilDusk` | -| `nightEnd` | `astronomicalDawn` | -| `night` | `astronomicalDusk` | -| `nightStart` | `astronomicalDusk` | -| `sunrise` | `sunriseStart` | -| `sunset` | `sunsetEnd` | -| `goldenHour` | `goldenHourDuskStart` | -| `goldenHourEnd` | `goldenHourDawnEnd` | -| `goldenHourStart` | `goldenHourDuskStart` | - - -Each of the properties will be an object with the following properties: - -```javascript -/** -* @typedef {Object} ISunTimeDef -* @property {string} name - The Name of the time -* @property {Date} value - Date object with the calculated sun-time -* @property {number} ts - The time as Unix timestamp -* @property {number} pos - The position of the sun on the time -* @property {number} [elevation] - Angle of the sun on the time (except for solarNoon / nadir) -* @property {number} julian - The time as Julian calendar -* @property {boolean} valid - indicates if the time is valid or not -* @property {boolean} [deprecated] - indicates if the time is a deprecated time name -* @property {string} [nameOrg] - if it is a deprecated name, the original property name -* @property {number} [posOrg] - if it is a deprecated name, the original position -*/ -``` - -#### adding / getting own Sunlight times - -```javascript -/** adds a custom time to the times config - * @param {number} angleAltitude - angle of Altitude/elevation above the horizont of the sun in degrees - * @param {string} riseName - name of sun rise (morning name) - * @param {string} setName - name of sun set (evening name) - * @param {number} [risePos] - (optional) position at rise (morning) - * @param {number} [setPos] - (optional) position at set (evening) - * @param {boolean} [degree=true] defines if the elevationAngle is in degree not in radians - * @return {Boolean} true if new time could be added, false if not (parameter missing; riseName or setName already existing) - */ -SunCalc.addTime(angleInDegrees, riseName, setName, risePos, setPos) -``` - -Adds a custom time when the sun reaches the given angle to results returned by `SunCalc.getSunTimes`. - -- the function tests for validity of the given parameters - - `riseName` and `setName` must be a non empty `string` and match the regex `/^(?![0-9])[a-zA-Z0-9$_]+$/` - - `angleInDegrees` must be a number - - `originalName` must be in the array `SunCalc.times` as `riseName` or `setName` - - `riseName` and `setName` must not correspond to a `riseName` or `setName` already in the array `SunCalc.times` - -Additional this function removes all items from `SunCalc.timesDeprecated` array where the `riseName` or `setName` matches the `alternameName` to prevent errors. - -```javascript -/** - * @typedef ISunTimeNames - * @type {Object} - * @property {number} angle - angle of the sun position in degrees - * @property {string} riseName - name of sun rise (morning name) - * @property {string} setName - name of sun set (evening name) - * @property {number} [risePos] - (optional) position at rise - * @property {number} [setPos] - (optional) position at set - */ -``` - -`SunCalc.times` property contains all currently defined times of type `Array.`. - -```javascript -/** - * add an alternate name for a sun time - * @param {string} alternameName - alternate or deprecated time name - * @param {string} originalName - original time name from SunCalc.times array - * @return {Boolean} true if could be added, false if not (parameter missing; originalName does not exists; alternameName already existis) - */ -SunCalc.addDeprecatedTimeName(alternameName, originalName) -``` - -Add a deprecated name - -- the function tests for validity of the given parameters - - `alternameName` must be a non empty `string` and match the regex `/^(?![0-9])[a-zA-Z0-9$_]+$/` - - `originalName` must be in the array `SunCalc.times` as `riseName` or `setName` - - `alternameName` must not correspond to a `riseName` or `setName` in the array `SunCalc.times` - -`SunCalc.timesDeprecated` property contains all deprecated time names as an `Array.<[string, string]>` - `Array.`. - -#### get specific Sunlight time - -```javascript -/** - * calculates sun times for a given date and latitude/longitude - * calculates the time at which the sun will have a given elevation angle when rising and when setting for a given date and latitude/longitude. - * @param {number|Date} dateValue Date object or timestamp for calculating sun-times - * @param {number} lat latitude for calculating sun-times - * @param {number} lng longitude for calculating sun-times - * @param {number} elevationAngle sun angle for calculating sun-time - * @param {number} [height=0] the observer height (in meters) relative to the horizon - * @param {boolean} [degree] defines if the elevationAngle is in degree not in radians - * @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is local) - * @return {ISunTimeSingle} result object of single sunTime - */ -SunCalc.getSunTime(dateValue, lat, lng, elevationAngle, height, degree, inUTC) -``` - -Returns an object with the following properties: - -```javascript -/** -* @typedef {Object} ISunTimeSingle -* @property {ISunTimeDef} rise - sun-time for sun rise -* @property {ISunTimeDef} set - sun-time for sun set -* @property {string} [error] - string of an error message if an error occurs -*/ -``` - -`rise` and `set` will be an object equal to the times objects given by `SunCalc.getSunTimes`. - -#### get Sunlight time for a given azimuth angle for a given date - -```javascript -/** - * calculates time for a given azimuth angle for a given date and latitude/longitude - * @param {Date} date start date for calculating sun-position - * @param {number} nazimuth azimuth for calculating sun-position - * @param {number} lat latitude for calculating sun-position - * @param {number} lng longitude for calculating sun-position - * @param {boolean} [degree] true if the angle is in degree and not in rad - * @return {Date} result time of sun-position -*/ -SunCalc.getSunTimeByAzimuth(date, lat, lng, nazimuth, degree) -``` - -Returns an Date object - -#### getting solar time - - -```javascript -/** - * Calculaes the solar time of the given date in the given latitude and UTC offset. - * @param {number|Date} dateValue Date object or timestamp for calculating solar time - * @param {number} utcOffset - * @param {number} lng - * @returns Returns the solar time of the given date in the given latitude and UTC offset. - */ -SunCalc.getSolarTime(dateValue, utcOffset, lng) -``` - -Returns an Date object - -### Sun position - -```javascript -/** - * calculates sun position for a given date and latitude/longitude - * @param {number|Date} dateValue Date object or timestamp for calculating sun-position - * @param {number} lat latitude for calculating sun-position - * @param {number} lng longitude for calculating sun-position - * @return {ISunPosition} result object of sun-position -*/ -SunCalc.getPosition(dateValue, lat, lng) -``` - -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} ISunPosition - * @property {number} azimuth - The azimuth of the sun in radians - * @property {number} altitude - The altitude above the horizon of the sun in radians - * @property {number} zenith - The zenith of the sun in radians - * @property {number} azimuthDegrees - The azimuth of the sun in decimal degree - * @property {number} altitudeDegrees - The altitude of the sun in decimal degree - * @property {number} zenithDegrees - The zenith of the sun in decimal degree - * @property {number} declination - The declination of the sun - */ -``` - - * `altitude`: sun altitude above the horizon in radians, - e.g. `0` at the horizon and `PI/2` at the zenith (straight over your head) - * `azimuth`: sun azimuth in radians (direction along the horizon, measured from south to west), - e.g. `0` is south and `Math.PI * 3/4` is northwest - - -### Moon position - -```javascript -/** - * calculates moon position for a given date and latitude/longitude - * @param {number|Date} dateValue Date object or timestamp for calculating moon-position - * @param {number} lat latitude for calculating moon-position - * @param {number} lng longitude for calculating moon-position - * @return {IMoonPosition} result object of moon-position - */ -SunCalc.getMoonPosition(dateValue, lat, lng) -``` - -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} IMoonPosition - * @property {number} azimuth - The moon azimuth in radians - * @property {number} altitude - The moon altitude above the horizon in radians - * @property {number} azimuthDegrees - The moon azimuth in degree - * @property {number} altitudeDegrees - The moon altitude above the horizon in degree - * @property {number} distance - The distance of the moon to the earth in kilometers - * @property {number} parallacticAngle - The parallactic angle of the moon - * @property {number} parallacticAngleDegrees - The parallactic angle of the moon in degree - */ -``` - -### Moon illumination - -```javascript -/** - * calculations for illumination parameters of the moon, - * based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and - * Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - * @param {number|Date} dateValue Date object or timestamp for calculating moon-illumination - * @return {IMoonIllumination} result object of moon-illumination - */ -SunCalc.getMoonIllumination(dateValue) -``` - -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} IMoonIllumination - * @property {number} fraction - illuminated fraction of the moon; varies from `0.0` (new moon) to `1.0` (full moon) - * @property {IPhaseObj} phase - moon phase as object - * @property {number} phaseValue - The phase of the moon in the current cycle; varies from `0.0` to `1.0` - * @property {number} angle - The midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; - * @property {IMoonIlluminationNext} next - object containing information about the next phases of the moon - * @remarks the moon is waxing if the angle is negative, and waning if positive - */ - -/** - * @typedef {Object} IPhaseObj - * @property {number} from - The phase start - * @property {number} to - The phase end - * @property {('newMoon'|'waxingCrescentMoon'|'firstQuarterMoon'|'waxingGibbousMoon'|'fullMoon'|'waningGibbousMoon'|'thirdQuarterMoon'|'waningCrescentMoon')} id - id of the phase - * @property {string} emoji - unicode symbol of the phase - * @property {string} name - name of the phase - * @property {string} id - phase name - * @property {number} weight - weight of the phase - * @property {string} css - a css value of the phase - * @property {string} [nameAlt] - an alernate name (not used by this library) - * @property {string} [tag] - additional tag (not used by this library) - */ - -/** - * @typedef {Object} IMoonIlluminationNext - * @property {string} date - The Date as a ISO String YYYY-MM-TTTHH:MM:SS.mmmmZ of the next phase - * @property {number} value - The Date as the milliseconds since 1.1.1970 0:00 UTC of the next phase - * @property {string} type - The name of the next phase [newMoon, fullMoon, firstQuarter, thirdQuarter] - * @property {IDateObj} newMoon - Date of the next new moon - * @property {IDateObj} fullMoon - Date of the next full moon - * @property {IDateObj} firstQuarter - Date of the next first quater of the moon - * @property {IDateObj} thirdQuarter - Date of the next third/last quater of the moon - */ -``` - - -Moon phase value should be interpreted like this: - -By subtracting the `parallacticAngle` from the `angle` one can get the zenith angle of the moons bright limb (anticlockwise). -The zenith angle can be used do draw the moon shape from the observers perspective (e.g. moon lying on its back). The `SunCalc.getMoonData` function will return the zenith angle. - -`SunCalc.moonCycles` contains an array with objects of type `IPhaseObj` for every phase. - -## Moon illumination, position and zenith angle - -```javascript -/** - * calculations moon position and illumination for a given date and latitude/longitude of the moon, - * @param {number|Date} dateValue Date object or timestamp for calculating moon-illumination - * @param {number} lat latitude for calculating moon-position - * @param {number} lng longitude for calculating moon-position - * @return {IMoonData} result object of moon-illumination - */ -SunCalc.getMoonData(dateValue, lat, lng) -``` - -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} IMoonData - * @property {number} azimuth - The moon azimuth in radians - * @property {number} altitude - The moon altitude above the horizon in radians - * @property {number} azimuthDegrees - The moon azimuth in degree - * @property {number} altitudeDegrees - The moon altitude above the horizon in degree - * @property {number} distance - The distance of the moon to the earth in kilometers - * @property {number} parallacticAngle - The parallactic angle of the moon - * @property {number} parallacticAngleDegrees - The parallactic angle of the moon in degree - * @property {number} zenithAngle - The zenith angle of the moon - * @property {IMoonIllumination} illumination - object containing information about the next phases of the moon - */ -``` - -The `IMoonIllumination` object is the same as the `SunCalc.getMoonIllumination` functions returns. - -### Moon rise and set times - -```javascript -/** - * calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article - * @param {number|Date} dateValue Date object or timestamp for calculating moon-times - * @param {number} lat latitude for calculating moon-times - * @param {number} lng longitude for calculating moon-times - * @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is local) - * @return {IMoonTimes} result object of sunTime - */ -SunCalc.getMoonTimes(dateValue, lat, lng, inUTC) -``` - -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} IMoonTimes - * @property {Date|NaN} rise - a Date object if the moon is rising on the given Date, otherwise NaN - * @property {Date|NaN} set - a Date object if the moon is setting on the given Date, otherwise NaN - * @property {boolean} alwaysUp - is true if the moon never rises/sets and is always _above_ the horizon during the day - * @property {boolean} alwaysDown - is true if the moon is always _below_ the horizon - */ -``` - -By default, it will search for moon rise and set during local user's day (frou 0 to 24 hours). -If `inUTC` is set to true, it will instead search the specified date from 0 to 24 UTC hours. - -### Moon transit -```javascript -/** - * calculated the moon transit - * @param {number|Date} rise rise time as Date object or timestamp for calculating moon-transit - * @param {number|Date} set set time as Date object or timestamp for calculating moon-transit - * @param {number} lat latitude for calculating moon-times - * @param {number} lng longitude for calculating moon-times - * @returns {IMoonTransit} - */ -SunCalc.moonTransit(rise, set, lat, lng) -``` -Returns an object with the following properties: - -```javascript -/** - * @typedef {Object} IMoonTransit - * @property {Date|NaN} main - the moon transit date - * @property {Date|NaN} invert - the inverted moon transit date - */ -``` - -## Changelog - -#### 2.0.5 — April 04, 2022 -- function `SunCalc.addTime(...)` removes all items from `SunCalc.timesDeprecated` array where the new rise or set name matches the `alternameName`. - -#### 2.0.4 — April 04, 2022 -- added `SunCalc.addDeprecatedTimeName(...)` function -- renamed `SunCalc.timesAlternate` array to `SunCalc.timesDeprecated` -- added validation to function `addTime` - -#### 2.0.2 — March 29, 2022 -- type definitions update - -#### 2.0.1 — March 13, 2022 - -- added type definitions - -#### 2.0.0 — March 13, 2022 - -- published as suncalc3 after this library was used by my own with various changes to the original one -- added getSolarTime and moonTransit - -#### 1.8.0 — Dec 22, 2016 - -- Improved precision of moonrise/moonset calculations. -- Added `parallacticAngle` calculation to `getMoonPosition`. -- Default to today's date in `getMoonIllumination`. -- Fixed incompatibility when using Browserify/Webpack together with a global AMD loader. - -#### 1.7.0 — Nov 11, 2015 - -- Added `inUTC` argument to `getMoonTimes`. - -#### 1.6.0 — Oct 27, 2014 - -- Added `SunCalc.getMoonTimes` for calculating moon rise and set times. - -#### 1.5.1 — May 16, 2014 - -- Exposed `SunCalc.times` property with defined daylight times. -- Slightly improved `SunCalc.getTimes` performance. - -#### 1.4.0 — Apr 10, 2014 - -- Added `phase` to `SunCalc.getMoonIllumination` results (moon phase). -- Switched from mocha to tape for tests. - -#### 1.3.0 — Feb 21, 2014 - -- Added `SunCalc.getMoonIllumination` (in place of `getMoonFraction`) that returns an object with `fraction` and `angle` -(angle of illuminated limb of the moon). - -#### 1.2.0 — Mar 07, 2013 - -- Added `SunCalc.getMoonFraction` function that returns illuminated fraction of the moon. - -#### 1.1.0 — Mar 06, 2013 - -- Added `SunCalc.getMoonPosition` function. -- Added nadir (darkest time of the day, middle of the night). -- Added tests. - -#### 1.0.0 — Dec 07, 2011 - -- Published to NPM. -- Added `SunCalc.addTime` function. - -#### 0.0.0 — Aug 25, 2011 - -- First commit. diff --git a/suncalc3/package.json b/suncalc3/package.json deleted file mode 100644 index 6b5ca69..0000000 --- a/suncalc3/package.json +++ /dev/null @@ -1,234 +0,0 @@ -{ - "name": "suncalc3", - "version": "2.0.5", - "description": "A tiny JavaScript library for calculating sun/moon positions and phases.", - "homepage": "https://github.com/hypnos3/suncalc3", - "keywords": [ - "sun", - "astronomy", - "math", - "calculation", - "sunrise", - "sunset", - "twilight", - "moon", - "illumination", - "solar" - ], - "author": { - "name": "Hypnos3", - "email": "hypnos3@online.de", - "url": "https://github.com/hypnos3" - }, - "contributors": [ - { - "name": "Hypnos3", - "url": "https://github.com/hypnos3" - }, - { - "name": "Vladimir Agafonkin", - "url": "https://github.com/mourner" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/hypnos3/suncalc3.git" - }, - "main": "suncalc.js", - "types": "suncalc.d.ts", - "devDependencies": { - "eslint": ">=8.12.0", - "eslint-plugin-json": ">=3.1.0", - "eslint-plugin-node": ">=11.1.0", - "tape": "^5.5.2", - "typescript":"^4.6.3" - }, - "files": [ - "suncalc.js" - ], - "scripts": { - "pretest": "eslint suncalc.js test.js", - "test": "node test.js", - "prepublishOnly": "tsc && eslint suncalc.js test.js && npm test", - "build": "tsc --build", - "clean": "tsc --build --clean" - }, - "jshintConfig": { - "quotmark": "single", - "trailing": true, - "unused": true - }, - "eslintConfig": { - "env": { - "es6": true, - "node": true, - "browser": true, - "commonjs": true, - "jquery": true, - "amd": true - }, - "extends": "eslint:recommended", - "settings": { - "html/html-extensions": [ - ".html", - ".htm", - ".we" - ], - "html/indent": "+4", - "html/report-bad-indent": "error", - "import/resolver": { - "node": { - "extensions": [ - ".js", - ".jsx" - ] - } - } - }, - "globals": { - "RED": true - }, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" - }, - "rules": { - "indent": [ - "error", - 4, - { - "SwitchCase": 1 - } - ], - "max-len": [ - "error", - { - "code": 250, - "ignoreComments": true, - "ignoreTrailingComments": true, - "ignoreUrls": true, - "ignoreRegExpLiterals": true, - "ignoreTemplateLiterals": true - } - ], - "no-eq-null": "error", - "eqeqeq": "error", - "no-else-return": "error", - "prefer-arrow-callback": "error", - "no-confusing-arrow": [ - "error", - { - "allowParens": true - } - ], - "arrow-parens": [ - "error", - "as-needed" - ], - "no-console": "warn", - "no-unused-vars": [ - "error", - { - "args": "after-used", - "argsIgnorePattern": "^_" - } - ], - "no-unused-expressions": "warn", - "no-useless-escape": "warn", - "no-constant-condition": "off", - "no-multiple-empty-lines": [ - "error", - { - "max": 2, - "maxEOF": 1 - } - ], - "no-var": "error", - "object-shorthand": [ - "error", - "always" - ], - "prefer-const": "error", - "prefer-rest-params": "error", - "no-useless-concat": "error", - "no-template-curly-in-string": "error", - "require-jsdoc": "warn", - "rest-spread-spacing": [ - "error", - "never" - ], - "symbol-description": "error", - "array-callback-return": "error", - "consistent-return": "error", - "no-lone-blocks": "error", - "linebreak-style": [ - "warn", - "unix" - ], - "brace-style": [ - 2, - "1tbs", - { - "allowSingleLine": true - } - ], - "quotes": [ - "warn", - "single", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } - ], - "semi": [ - "error", - "always" - ], - "comma-dangle": [ - "error", - { - "arrays": "never", - "objects": "never", - "imports": "never", - "exports": "never", - "functions": "ignore" - } - ], - "no-trailing-spaces": "error", - "spaced-comment": [ - "warn", - "always", - { - "line": { - "markers": [ - "/", - "*" - ], - "exceptions": [ - "-", - "+", - "*", - "#" - ] - }, - "block": { - "markers": [ - "!" - ], - "exceptions": [ - "-", - "+", - "*", - "#" - ], - "balanced": true - } - } - ], - "eol-last": [ - "error", - "never" - ] - } - } -} diff --git a/suncalc3/suncalc.js b/suncalc3/suncalc.js deleted file mode 100644 index d0a9d3b..0000000 --- a/suncalc3/suncalc.js +++ /dev/null @@ -1,1251 +0,0 @@ -// @ts-check -/* - (c) 2011-2015, Vladimir Agafonkin - SunCalc is a JavaScript library for calculating sun/moon position and light phases. - https://github.com/mourner/suncalc - - Reworked and enhanced by Robert Gester - Additional Copyright (c) 2022 Robert Gester - https://github.com/hypnos3/suncalc3 -*/ - -/** -* @typedef {Object} ISunTimeDef -* @property {string} name - The Name of the time -* @property {Date} value - Date object with the calculated sun-time -* @property {number} ts - The time as timestamp -* @property {number} pos - The position of the sun on the time -* @property {number} [elevation] - Angle of the sun on the time (except for solarNoon / nadir) -* @property {number} julian - The time as Julian calendar -* @property {boolean} valid - indicates if the time is valid or not -* @property {boolean} [deprecated] - indicates if the time is a deprecated time name -* @property {string} [nameOrg] - if it is a deprecated name, the original property name -* @property {number} [posOrg] - if it is a deprecated name, the original position -*/ - -/** -* @typedef {Object} ISunTimeSingle -* @property {ISunTimeDef} rise - sun-time for sun rise -* @property {ISunTimeDef} set - sun-time for sun set -* @property {string} [error] - string of an error message if an error occurs -*/ - -/** -* @typedef {Object} ISunTimeList -* @property {ISunTimeDef} solarNoon - The sun-time for the solar noon (sun is in the highest position) -* @property {ISunTimeDef} nadir - The sun-time for nadir (darkest moment of the night, sun is in the lowest position) -* @property {ISunTimeDef} goldenHourDawnStart - The sun-time for morning golden hour (soft light, best time for photography) -* @property {ISunTimeDef} goldenHourDawnEnd - The sun-time for morning golden hour (soft light, best time for photography) -* @property {ISunTimeDef} goldenHourDuskStart - The sun-time for evening golden hour starts -* @property {ISunTimeDef} goldenHourDuskEnd - The sun-time for evening golden hour starts -* @property {ISunTimeDef} sunriseStart - The sun-time for sunrise starts (top edge of the sun appears on the horizon) -* @property {ISunTimeDef} sunriseEnd - The sun-time for sunrise ends (bottom edge of the sun touches the horizon) -* @property {ISunTimeDef} sunsetStart - The sun-time for sunset starts (bottom edge of the sun touches the horizon) -* @property {ISunTimeDef} sunsetEnd - The sun-time for sunset ends (sun disappears below the horizon, evening civil twilight starts) -* @property {ISunTimeDef} blueHourDawnStart - The sun-time for blue Hour start (time for special photography photos starts) -* @property {ISunTimeDef} blueHourDawnEnd - The sun-time for blue Hour end (time for special photography photos end) -* @property {ISunTimeDef} blueHourDuskStart - The sun-time for blue Hour start (time for special photography photos starts) -* @property {ISunTimeDef} blueHourDuskEnd - The sun-time for blue Hour end (time for special photography photos end) -* @property {ISunTimeDef} civilDawn - The sun-time for dawn (morning nautical twilight ends, morning civil twilight starts) -* @property {ISunTimeDef} civilDusk - The sun-time for dusk (evening nautical twilight starts) -* @property {ISunTimeDef} nauticalDawn - The sun-time for nautical dawn (morning nautical twilight starts) -* @property {ISunTimeDef} nauticalDusk - The sun-time for nautical dusk end (evening astronomical twilight starts) -* @property {ISunTimeDef} amateurDawn - The sun-time for amateur astronomical dawn (sun at 12° before sunrise) -* @property {ISunTimeDef} amateurDusk - The sun-time for amateur astronomical dusk (sun at 12° after sunrise) -* @property {ISunTimeDef} astronomicalDawn - The sun-time for night ends (morning astronomical twilight starts) -* @property {ISunTimeDef} astronomicalDusk - The sun-time for night starts (dark enough for astronomical observations) -* @property {ISunTimeDef} [dawn] - Deprecated: alternate for civilDawn -* @property {ISunTimeDef} [dusk] - Deprecated: alternate for civilDusk -* @property {ISunTimeDef} [nightEnd] - Deprecated: alternate for astronomicalDawn -* @property {ISunTimeDef} [night] - Deprecated: alternate for astronomicalDusk -* @property {ISunTimeDef} [nightStart] - Deprecated: alternate for astronomicalDusk -* @property {ISunTimeDef} [goldenHour] - Deprecated: alternate for goldenHourDuskStart -* @property {ISunTimeDef} [sunset] - Deprecated: alternate for sunsetEnd -* @property {ISunTimeDef} [sunrise] - Deprecated: alternate for sunriseStart -* @property {ISunTimeDef} [goldenHourEnd] - Deprecated: alternate for goldenHourDawnEnd -* @property {ISunTimeDef} [goldenHourStart] - Deprecated: alternate for goldenHourDuskStart -*/ - -/** - * @typedef ISunTimeNames - * @type {Object} - * @property {number} angle - angle of the sun position in degrees - * @property {string} riseName - name of sun rise (morning name) - * @property {string} setName - name of sun set (evening name) - * @property {number} [risePos] - (optional) position at rise - * @property {number} [setPos] - (optional) position at set - */ - - -/** - * @typedef {Object} ISunCoordinates - * @property {number} dec - The declination of the sun - * @property {number} ra - The right ascension of the sun - */ - -/** - * @typedef {Object} ISunPosition - * @property {number} azimuth - The azimuth above the horizon of the sun in radians - * @property {number} altitude - The altitude of the sun in radians - * @property {number} zenith - The zenith of the sun in radians - * @property {number} azimuthDegrees - The azimuth of the sun in decimal degree - * @property {number} altitudeDegrees - The altitude of the sun in decimal degree - * @property {number} zenithDegrees - The zenith of the sun in decimal degree - * @property {number} declination - The declination of the sun - */ - -/** - * @typedef {Object} IMoonPosition - * @property {number} azimuth - The moon azimuth in radians - * @property {number} altitude - The moon altitude above the horizon in radians - * @property {number} azimuthDegrees - The moon azimuth in degree - * @property {number} altitudeDegrees - The moon altitude above the horizon in degree - * @property {number} distance - The distance of the moon to the earth in kilometers - * @property {number} parallacticAngle - The parallactic angle of the moon - * @property {number} parallacticAngleDegrees - The parallactic angle of the moon in degree - */ - - -/** - * @typedef {Object} IDateObj - * @property {string} date - The Date as a ISO String YYYY-MM-TTTHH:MM:SS.mmmmZ - * @property {number} value - The Date as the milliseconds since 1.1.1970 0:00 UTC - */ - -/** - * @typedef {Object} IPhaseObj - * @property {number} from - The phase start - * @property {number} to - The phase end - * @property {('newMoon'|'waxingCrescentMoon'|'firstQuarterMoon'|'waxingGibbousMoon'|'fullMoon'|'waningGibbousMoon'|'thirdQuarterMoon'|'waningCrescentMoon')} id - id of the phase - * @property {string} emoji - unicode symbol of the phase - * @property {string} name - name of the phase - * @property {string} id - phase name - * @property {number} weight - weight of the phase - * @property {string} css - a css value of the phase - * @property {string} [nameAlt] - an alernate name (not used by this library) - * @property {string} [tag] - additional tag (not used by this library) - */ - -/** - * @typedef {Object} IMoonIlluminationNext - * @property {string} date - The Date as a ISO String YYYY-MM-TTTHH:MM:SS.mmmmZ of the next phase - * @property {number} value - The Date as the milliseconds since 1.1.1970 0:00 UTC of the next phase - * @property {string} type - The name of the next phase [newMoon, fullMoon, firstQuarter, thirdQuarter] - * @property {IDateObj} newMoon - Date of the next new moon - * @property {IDateObj} fullMoon - Date of the next full moon - * @property {IDateObj} firstQuarter - Date of the next first quater of the moon - * @property {IDateObj} thirdQuarter - Date of the next third/last quater of the moon - */ - -/** - * @typedef {Object} IMoonIllumination - * @property {number} fraction - illuminated fraction of the moon; varies from `0.0` (new moon) to `1.0` (full moon) - * @property {IPhaseObj} phase - moon phase as object - * @property {number} phaseValue - The phase of the moon in the current cycle; varies from `0.0` to `1.0` - * @property {number} angle - The midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; - * @property {IMoonIlluminationNext} next - object containing information about the next phases of the moon - * @remarks the moon is waxing if the angle is negative, and waning if positive - */ - -/** - * @typedef {Object} IMoonDataInst - * @property {number} zenithAngle - The zenith angle of the moon - * @property {IMoonIllumination} illumination - object containing information about the next phases of the moon - * - * @typedef {IMoonPosition & IMoonDataInst} IMoonData - */ - -/** - * @typedef {Object} IMoonTimes - * @property {Date|NaN} rise - a Date object if the moon is rising on the given Date, otherwise NaN - * @property {Date|NaN} set - a Date object if the moon is setting on the given Date, otherwise NaN - * @property {boolean} alwaysUp - is true if the moon never rises/sets and is always _above_ the horizon during the day - * @property {boolean} alwaysDown - is true if the moon is always _below_ the horizon - * @property {Date} [highest] - Date of the highest position, only avalílable if set and rise is not NaN - */ - -(function () { - 'use strict'; - // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas - - // shortcuts for easier to read formulas - const sin = Math.sin; - const cos = Math.cos; - const tan = Math.tan; - const asin = Math.asin; - const atan = Math.atan2; - const acos = Math.acos; - const rad = Math.PI / 180; - const degr = 180 / Math.PI; - - // date/time constants and conversions - const dayMs = 86400000; // 1000 * 60 * 60 * 24; - const J1970 = 2440587.5; - const J2000 = 2451545; - - const lunarDaysMs = 2551442778; // The duration in days of a lunar cycle is 29.53058770576 - const firstNewMoon2000 = 947178840000; // first newMoon in the year 2000 2000-01-06 18:14 - - /** - * convert date from Julian calendar - * @param {number} j - day number in Julian calendar to convert - * @return {number} result date as timestamp - */ - function fromJulianDay(j) { - return (j - J1970) * dayMs; - } - - /** - * get number of days for a dateValue since 2000 - * @param {number} dateValue date as timestamp to get days - * @return {number} count of days - */ - function toDays(dateValue) { - return ((dateValue / dayMs) + J1970) - J2000; - } - - // general calculations for position - - const e = rad * 23.4397; // obliquity of the Earth - - /** - * get right ascension - * @param {number} l - * @param {number} b - * @returns {number} - */ - function rightAscension(l, b) { - return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); - } - - /** - * get declination - * @param {number} l - * @param {number} b - * @returns {number} - */ - function declination(l, b) { - return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); - } - - /** - * get azimuth - * @param {number} H - siderealTime - * @param {number} phi - PI constant - * @param {number} dec - The declination of the sun - * @returns {number} azimuth in rad - */ - function azimuthCalc(H, phi, dec) { - return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)) + Math.PI; - } - - /** - * get altitude - * @param {number} H - siderealTime - * @param {number} phi - PI constant - * @param {number} dec - The declination of the sun - * @returns {number} - */ - function altitudeCalc(H, phi, dec) { - return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); - } - - /** - * side real time - * @param {number} d - * @param {number} lw - * @returns {number} - */ - function siderealTime(d, lw) { - return rad * (280.16 + 360.9856235 * d) - lw; - } - - /** - * get astro refraction - * @param {number} h - * @returns {number} - */ - function astroRefraction(h) { - if (h < 0) { // the following formula works for positive altitudes only. - h = 0; - } // if h = -0.08901179 a div/0 would occur. - - // formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - // 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad: - return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179)); - } - // general sun calculations - /** - * get solar mean anomaly - * @param {number} d - * @returns {number} - */ - function solarMeanAnomaly(d) { - return rad * (357.5291 + 0.98560028 * d); - } - - /** - * ecliptic longitude - * @param {number} M - * @returns {number} - */ - function eclipticLongitude(M) { - const C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)); - // equation of center - const P = rad * 102.9372; // perihelion of the Earth - return M + C + P + Math.PI; - } - - /** - * sun coordinates - * @param {number} d days in Julian calendar - * @returns {ISunCoordinates} - */ - function sunCoords(d) { - const M = solarMeanAnomaly(d); - const L = eclipticLongitude(M); - - return { - dec: declination(L, 0), - ra: rightAscension(L, 0) - }; - } - - const SunCalc = {}; - - /** - * calculates sun position for a given date and latitude/longitude - * @param {number|Date} dateValue Date object or timestamp for calculating sun-position - * @param {number} lat latitude for calculating sun-position - * @param {number} lng longitude for calculating sun-position - * @return {ISunPosition} result object of sun-position - */ - SunCalc.getPosition = function (dateValue, lat, lng) { - // console.log(`getPosition dateValue=${dateValue} lat=${lat}, lng=${lng}`); - if (isNaN(lat)) { - throw new Error('latitude missing'); - } - if (isNaN(lng)) { - throw new Error('longitude missing'); - } - if (dateValue instanceof Date) { - dateValue = dateValue.valueOf(); - } - const lw = rad * -lng; - const phi = rad * lat; - const d = toDays(dateValue); - const c = sunCoords(d); - const H = siderealTime(d, lw) - c.ra; - const azimuth = azimuthCalc(H, phi, c.dec); - const altitude = altitudeCalc(H, phi, c.dec); - // console.log(`getPosition date=${date}, M=${H}, L=${H}, c=${JSON.stringify(c)}, d=${d}, lw=${lw}, phi=${phi}`); - - return { - azimuth, - altitude, - zenith: (90*Math.PI/180) - altitude, - azimuthDegrees: degr * azimuth, - altitudeDegrees: degr * altitude, - zenithDegrees: 90 - (degr * altitude), - declination: c.dec - }; - }; - - /** sun times configuration - * @type {Array.} - */ - const sunTimes = SunCalc.times = [ - { angle: 6, riseName: 'goldenHourDawnEnd', setName: 'goldenHourDuskStart'}, // GOLDEN_HOUR_2 - { angle: -0.3, riseName: 'sunriseEnd', setName: 'sunsetStart'}, // SUNRISE_END - { angle: -0.833, riseName: 'sunriseStart', setName: 'sunsetEnd'}, // SUNRISE - { angle: -1, riseName: 'goldenHourDawnStart', setName: 'goldenHourDuskEnd'}, // GOLDEN_HOUR_1 - { angle: -4, riseName: 'blueHourDawnEnd', setName: 'blueHourDuskStart'}, // BLUE_HOUR - { angle: -6, riseName: 'civilDawn', setName: 'civilDusk'}, // DAWN - { angle: -8, riseName: 'blueHourDawnStart', setName: 'blueHourDuskEnd'}, // BLUE_HOUR - { angle: -12, riseName: 'nauticalDawn', setName: 'nauticalDusk'}, // NAUTIC_DAWN - { angle: -15, riseName: 'amateurDawn', setName: 'amateurDusk'}, - { angle: -18, riseName: 'astronomicalDawn', setName: 'astronomicalDusk'} // ASTRO_DAWN - ]; - - /** alternate time names for backward compatibility - * @type {Array.<[string, string]>} - */ - const suntimesDeprecated = SunCalc.timesDeprecated = [ - ['dawn', 'civilDawn'], - ['dusk', 'civilDusk'], - ['nightEnd', 'astronomicalDawn'], - ['night', 'astronomicalDusk'], - ['nightStart', 'astronomicalDusk'], - ['goldenHour', 'goldenHourDuskStart'], - ['sunrise', 'sunriseStart'], - ['sunset', 'sunsetEnd'], - ['goldenHourEnd', 'goldenHourDawnEnd'], - ['goldenHourStart', 'goldenHourDuskStart'] - ]; - - /** adds a custom time to the times config - * @param {number} angleAltitude - angle of Altitude/elevation above the horizont of the sun in degrees - * @param {string} riseName - name of sun rise (morning name) - * @param {string} setName - name of sun set (evening name) - * @param {number} [risePos] - (optional) position at rise (morning) - * @param {number} [setPos] - (optional) position at set (evening) - * @param {boolean} [degree=true] defines if the elevationAngle is in degree not in radians - * @return {Boolean} true if new time could be added, false if not (parameter missing; riseName or setName already existing) - */ - SunCalc.addTime = function (angleAltitude, riseName, setName, risePos, setPos, degree) { - let isValid = (typeof riseName === 'string') && (riseName.length > 0) && - (typeof setName === 'string') && (setName.length > 0) && - (typeof angleAltitude === 'number'); - if (isValid) { - const EXP = /^(?![0-9])[a-zA-Z0-9$_]+$/; - // check for invalid names - for (let i=0; i= 0; i--) { - if (suntimesDeprecated[i][0] === riseName || suntimesDeprecated[i][0] === setName) { - suntimesDeprecated.splice(i, 1); - } - } - return true; - } - } - return false; - }; - - /** - * add an alternate name for a sun time - * @param {string} alternameName - alternate or deprecated time name - * @param {string} originalName - original time name from SunCalc.times array - * @return {Boolean} true if could be added, false if not (parameter missing; originalName does not exists; alternameName already existis) - */ - SunCalc.addDeprecatedTimeName = function (alternameName, originalName) { - let isValid = (typeof alternameName === 'string') && (alternameName.length > 0) && - (typeof originalName === 'string') && (originalName.length > 0); - if (isValid) { - let hasOrg = false; - const EXP = /^(?![0-9])[a-zA-Z0-9$_]+$/; - // check for invalid names - for (let i=0; i 200) { - // let nazi = this.getPosition(dateVal, lat, lng).azimuth; - const d = toDays(dateVal); - const c = sunCoords(d); - const H = siderealTime(d, lw) - c.ra; - const nazim = azimuthCalc(H, phi, c.dec); - - addval /= 2; - if (nazim < nazimuth) { - dateVal += addval; - } else { - dateVal -= addval; - } - } - return new Date(Math.floor(dateVal)); - }; - - // calculation for solar time based on https://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time - - /** - * Calculaes the solar time of the given date in the given latitude and UTC offset. - * @param {number|Date} dateValue Date object or timestamp for calculating solar time - * @param {number} lng longitude for calculating sun-time - * @param {number} utcOffset offset to the utc time - * @returns {Date} Returns the solar time of the given date in the given latitude and UTC offset. - */ - SunCalc.getSolarTime = function (dateValue, lng, utcOffset) { - // @ts-ignore - const date = new Date(dateValue); - // calculate the day of year - const start = new Date(date.getFullYear(), 0, 0); - const diff = (date.getTime() - start.getTime()) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000); - const dayOfYear = Math.floor(diff / dayMs); - - const b = 360 / 365 * (dayOfYear - 81) * rad; - const equationOfTime = 9.87 * sin(2 * b) - 7.53 * cos(b) - 1.5 * sin(b); - const localSolarTimeMeridian = 15 * utcOffset; - const timeCorrection = equationOfTime + 4 * (lng - localSolarTimeMeridian); - const localSolarTime = date.getHours() + timeCorrection / 60 + date.getMinutes() / 60; - - const solarDate = new Date(0, 0); - solarDate.setMinutes(+localSolarTime * 60); - return solarDate; - }; - - // moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas - - /** - * calculate the geocentric ecliptic coordinates of the moon - * @param {number} d number of days - */ - function moonCoords(d) { - const L = rad * (218.316 + 13.176396 * d); // ecliptic longitude - const M = rad * (134.963 + 13.064993 * d); // mean anomaly - const F = rad * (93.272 + 13.229350 * d); // mean distance - const l = L + rad * 6.289 * sin(M); // longitude - const b = rad * 5.128 * sin(F); // latitude - const dt = 385001 - 20905 * cos(M); // distance to the moon in km - - return { - ra: rightAscension(l, b), - dec: declination(l, b), - dist: dt - }; - } - - /** - * calculates moon position for a given date and latitude/longitude - * @param {number|Date} dateValue Date object or timestamp for calculating moon-position - * @param {number} lat latitude for calculating moon-position - * @param {number} lng longitude for calculating moon-position - * @return {IMoonPosition} result object of moon-position - */ - SunCalc.getMoonPosition = function (dateValue, lat, lng) { - // console.log(`getMoonPosition dateValue=${dateValue} lat=${lat}, lng=${lng}`); - if (isNaN(lat)) { - throw new Error('latitude missing'); - } - if (isNaN(lng)) { - throw new Error('longitude missing'); - } - if (dateValue instanceof Date) { - dateValue = dateValue.valueOf(); - } - const lw = rad * -lng; - const phi = rad * lat; - const d = toDays(dateValue); - const c = moonCoords(d); - const H = siderealTime(d, lw) - c.ra; - let altitude = altitudeCalc(H, phi, c.dec); - altitude += astroRefraction(altitude); // altitude correction for refraction - - // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - const pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); - - const azimuth = azimuthCalc(H, phi, c.dec); - - return { - azimuth, - altitude, - azimuthDegrees: degr * azimuth, - altitudeDegrees: degr * altitude, - distance: c.dist, - parallacticAngle: pa, - parallacticAngleDegrees: degr * pa - }; - }; - - const fractionOfTheMoonCycle = SunCalc.moonCycles = [{ - from: 0, - to: 0.033863193308711, - id: 'newMoon', - emoji: '🌚', - code: ':new_moon_with_face:', - name: 'New Moon', - weight: 1, - css: 'wi-moon-new' - }, - { - from: 0.033863193308711, - to: 0.216136806691289, - id: 'waxingCrescentMoon', - emoji: '🌒', - code: ':waxing_crescent_moon:', - name: 'Waxing Crescent', - weight: 6.3825, - css: 'wi-moon-wax-cres' - }, - { - from: 0.216136806691289, - to: 0.283863193308711, - id: 'firstQuarterMoon', - emoji: '🌓', - code: ':first_quarter_moon:', - name: 'First Quarter', - weight: 1, - css: 'wi-moon-first-quart' - }, - { - from: 0.283863193308711, - to: 0.466136806691289, - id: 'waxingGibbousMoon', - emoji: '🌔', - code: ':waxing_gibbous_moon:', - name: 'Waxing Gibbous', - weight: 6.3825, - css: 'wi-moon-wax-gibb' - }, - { - from: 0.466136806691289, - to: 0.533863193308711, - id: 'fullMoon', - emoji: '🌝', - code: ':full_moon_with_face:', - name: 'Full Moon', - weight: 1, - css: 'wi-moon-full' - }, - { - from: 0.533863193308711, - to: 0.716136806691289, - id: 'waningGibbousMoon', - emoji: '🌖', - code: ':waning_gibbous_moon:', - name: 'Waning Gibbous', - weight: 6.3825, - css: 'wi-moon-wan-gibb' - }, - { - from: 0.716136806691289, - to: 0.783863193308711, - id: 'thirdQuarterMoon', - emoji: '🌗', - code: ':last_quarter_moon:', - name: 'third Quarter', - weight: 1, - css: 'wi-moon-third-quart' - }, - { - from: 0.783863193308711, - to: 0.966136806691289, - id: 'waningCrescentMoon', - emoji: '🌘', - code: ':waning_crescent_moon:', - name: 'Waning Crescent', - weight: 6.3825, - css: 'wi-moon-wan-cres' - }, - { - from: 0.966136806691289, - to: 1, - id: 'newMoon', - emoji: '🌚', - code: ':new_moon_with_face:', - name: 'New Moon', - weight: 1, - css: 'wi-moon-new' - }]; - - /** - * calculations for illumination parameters of the moon, - * based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and - * Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - * @param {number|Date} dateValue Date object or timestamp for calculating moon-illumination - * @return {IMoonIllumination} result object of moon-illumination - */ - SunCalc.getMoonIllumination = function (dateValue) { - // console.log(`getMoonIllumination dateValue=${dateValue}`); - if (dateValue instanceof Date) { - dateValue = dateValue.valueOf(); - } - const d = toDays(dateValue); - const s = sunCoords(d); - const m = moonCoords(d); - const sdist = 149598000; // distance from Earth to Sun in km - const phi = acos(sin(s.dec) * sin(m.dec) + cos(s.dec) * cos(m.dec) * cos(s.ra - m.ra)); - const inc = atan(sdist * sin(phi), m.dist - sdist * cos(phi)); - const angle = atan(cos(s.dec) * sin(s.ra - m.ra), sin(s.dec) * cos(m.dec) - - cos(s.dec) * sin(m.dec) * cos(s.ra - m.ra)); - const phaseValue = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI; - - // calculates the difference in ms between the sirst fullMoon 2000 and given Date - const diffBase = dateValue - firstNewMoon2000; - // Calculate modulus to drop completed cycles - let cycleModMs = diffBase % lunarDaysMs; - // If negative number (date before new moon 2000) add lunarDaysMs - if ( cycleModMs < 0 ) { cycleModMs += lunarDaysMs; } - const nextNewMoon = (lunarDaysMs - cycleModMs) + dateValue; - let nextFullMoon = ((lunarDaysMs/2) - cycleModMs) + dateValue; - if (nextFullMoon < dateValue) { nextFullMoon += lunarDaysMs; } - const quater = (lunarDaysMs/4); - let nextFirstQuarter = (quater - cycleModMs) + dateValue; - if (nextFirstQuarter < dateValue) { nextFirstQuarter += lunarDaysMs; } - let nextThirdQuarter = (lunarDaysMs - quater - cycleModMs) + dateValue; - if (nextThirdQuarter < dateValue) { nextThirdQuarter += lunarDaysMs; } - // Calculate the fraction of the moon cycle - // const currentfrac = cycleModMs / lunarDaysMs; - const next = Math.min(nextNewMoon, nextFirstQuarter, nextFullMoon, nextThirdQuarter); - let phase; - - for (let index = 0; index < fractionOfTheMoonCycle.length; index++) { - const element = fractionOfTheMoonCycle[index]; - if ( (phaseValue >= element.from) && (phaseValue <= element.to) ) { - phase = element; - break; - } - } - - return { - fraction: (1 + cos(inc)) / 2, - // fraction2: cycleModMs / lunarDaysMs, - // @ts-ignore - phase, - phaseValue, - angle, - next : { - value: next, - date: (new Date(next)).toISOString(), - type: (next === nextNewMoon) ? 'newMoon' : ((next === nextFirstQuarter) ? 'firstQuarter' : ((next === nextFullMoon) ? 'fullMoon' : 'thirdQuarter')), - newMoon: { - value: nextNewMoon, - date: (new Date(nextNewMoon)).toISOString() - }, - fullMoon: { - value: nextFullMoon, - date: (new Date(nextFullMoon)).toISOString() - }, - firstQuarter: { - value: nextFirstQuarter, - date: (new Date(nextFirstQuarter)).toISOString() - }, - thirdQuarter: { - value: nextThirdQuarter, - date: (new Date(nextThirdQuarter)).toISOString() - } - } - }; - }; - - /** - * calculations moon position and illumination for a given date and latitude/longitude of the moon, - * @param {number|Date} dateValue Date object or timestamp for calculating moon-illumination - * @param {number} lat latitude for calculating moon-position - * @param {number} lng longitude for calculating moon-position - * @return {IMoonData} result object of moon-illumination - */ - SunCalc.getMoonData = function (dateValue, lat, lng) { - const pos = SunCalc.getMoonPosition(dateValue, lat, lng); - const illum = SunCalc.getMoonIllumination(dateValue); - return Object.assign({ - illumination : illum, - zenithAngle : illum.angle - pos.parallacticAngle - }, pos); - }; - - /** - * add hours to a date - * @param {number} dateValue timestamp to add hours - * @param {number} h - hours to add - * @returns {number} new timestamp with added hours - */ - function hoursLater(dateValue, h) { - return dateValue + h * dayMs / 24; - } - - /** - * calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article - * @param {number|Date} dateValue Date object or timestamp for calculating moon-times - * @param {number} lat latitude for calculating moon-times - * @param {number} lng longitude for calculating moon-times - * @param {boolean} [inUTC] defines if the calculation should be in utc or local time (default is local) - * @return {IMoonTimes} result object of sunTime - */ - SunCalc.getMoonTimes = function (dateValue, lat, lng, inUTC, dateAsIs) { - if (isNaN(lat)) { - throw new Error('latitude missing'); - } - if (isNaN(lng)) { - throw new Error('longitude missing'); - } - let t - if (dateAsIs) { - t = dateValue - } else { - t = new Date(dateValue); - if (inUTC) { - t.setUTCHours(0, 0, 0, 0); - } else { - t.setHours(0, 0, 0, 0); - } - } - dateValue = t.valueOf(); - // console.log(`getMoonTimes lat=${lat} lng=${lng} dateValue=${dateValue} t=${t}`); - - const hc = 0.133 * rad; - let h0 = SunCalc.getMoonPosition(dateValue, lat, lng).altitude - hc; - let rise; let set; let ye; let d; let roots; let x1; let x2; let dx; - - // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set) - for (let i = 1; i <= 26; i += 2) { - const h1 = SunCalc.getMoonPosition(hoursLater(dateValue, i), lat, lng).altitude - hc; - const h2 = SunCalc.getMoonPosition(hoursLater(dateValue, i + 1), lat, lng).altitude - hc; - - const a = (h0 + h2) / 2 - h1; - const b = (h2 - h0) / 2; - const xe = -b / (2 * a); - ye = (a * xe + b) * xe + h1; - d = b * b - 4 * a * h1; - roots = 0; - - if (d >= 0) { - dx = Math.sqrt(d) / (Math.abs(a) * 2); - x1 = xe - dx; - x2 = xe + dx; - if (Math.abs(x1) <= 1) { - roots++; - } - - if (Math.abs(x2) <= 1) { - roots++; - } - - if (x1 < -1) { - x1 = x2; - } - } - - if (roots === 1) { - if (h0 < 0) { - rise = i + x1; - } else { - set = i + x1; - } - } else if (roots === 2) { - rise = i + (ye < 0 ? x2 : x1); - set = i + (ye < 0 ? x1 : x2); - } - - if (rise && set) { - break; - } - - h0 = h2; - } - - const result = {}; - if (rise) { - result.rise = new Date(hoursLater(dateValue, rise)); - } else { - result.rise = NaN; - } - - if (set) { - result.set = new Date(hoursLater(dateValue, set)); - } else { - result.set = NaN; - } - - if (!rise && !set) { - if (ye > 0) { - result.alwaysUp = true; - result.alwaysDown = false; - } else { - result.alwaysUp = false; - result.alwaysDown = true; - } - } else if (rise && set) { - result.alwaysUp = false; - result.alwaysDown = false; - result.highest = new Date(hoursLater(dateValue, Math.min(rise, set) + (Math.abs(set - rise) / 2))); - } else { - result.alwaysUp = false; - result.alwaysDown = false; - } - return result; - }; - - /** - * calc moon transit - * @param {number} rize timestamp for rise - * @param {number} set timestamp for set time - * @returns {Date} new moon transit - */ - function calcMoonTransit(rize, set) { - if (rize > set) { - return new Date(set + (rize - set) / 2); - } - return new Date(rize + (set - rize) / 2); - } - - /** - * calculated the moon transit - * @param {number|Date} rise rise time as Date object or timestamp for calculating moon-transit - * @param {number|Date} set set time as Date object or timestamp for calculating moon-transit - * @param {number} lat latitude for calculating moon-times - * @param {number} lng longitude for calculating moon-times - * @returns {{main: (Date|null), invert: (Date|null)}} - */ - SunCalc.moonTransit = function (rise, set, lat, lng) { - /** @type {Date|null} */ let main = null; - /** @type {Date|null} */ let invert = null; - const riseDate = new Date(rise); - const setDate = new Date(set); - const riseValue = riseDate.getTime(); - const setValue = setDate.getTime(); - const day = setDate.getDate(); - let tempTransitBefore; - let tempTransitAfter; - - if (rise && set) { - if (rise < set) { - main = calcMoonTransit(riseValue, setValue); - } else { - invert = calcMoonTransit(riseValue, setValue); - } - } - - if (rise) { - tempTransitAfter = calcMoonTransit(riseValue, SunCalc.getMoonTimes(new Date(riseDate).setDate(day + 1), lat, lng).set.valueOf()); - if (tempTransitAfter.getDate() === day) { - if (main) { - invert = tempTransitAfter; - } else { - main = tempTransitAfter; - } - } - } - - if (set) { - tempTransitBefore = calcMoonTransit(setValue, SunCalc.getMoonTimes(new Date(setDate).setDate(day - 1), lat, lng).rise.valueOf()); - if (tempTransitBefore.getDate() === day) { - main = tempTransitBefore; - } - } - return { - main, - invert - }; - }; - - // export as Node module / AMD module / browser variable - if (typeof exports === 'object' && typeof module !== 'undefined') { - module.exports = SunCalc; - // @ts-ignore - } else if (typeof define === 'function' && define.amd) { - // @ts-ignore - define(SunCalc); - } else { - // @ts-ignore - window.SunCalc = SunCalc; - } - -})(); diff --git a/yarn.lock b/yarn.lock index 1a40207..b232468 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5392,7 +5392,7 @@ __metadata: rollup: "npm:^3.19.1" rollup-plugin-serve: "npm:^2.0.2" rollup-plugin-typescript2: "npm:^0.34.1" - suncalc3: "link:suncalc3" + suncalc3: "npm:^2.0.5" ts-jest: "npm:29.1.0" typescript: "npm:^5.0.4" languageName: unknown @@ -6656,11 +6656,12 @@ __metadata: languageName: node linkType: hard -"suncalc3@link:suncalc3::locator=lovelace-horizon-card%40workspace%3A.": - version: 0.0.0-use.local - resolution: "suncalc3@link:suncalc3::locator=lovelace-horizon-card%40workspace%3A." +"suncalc3@npm:^2.0.5": + version: 2.0.5 + resolution: "suncalc3@npm:2.0.5" + checksum: 10c0/2c9ed89481657ddb395b01c01149ac1b908c2344ec993da4ef4d74bdbb49f85bba70401fd2265b0a754b606e5a7faca1852c47d0e3a52b2aab3008058adfddc5 languageName: node - linkType: soft + linkType: hard "superstruct@npm:^0.15.3": version: 0.15.5