@math.gl/sun 3.6.2 → 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,102 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ getSunDirection: () => getSunDirection,
23
+ getSunPosition: () => getSunPosition
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/suncalc.ts
28
+ var DEGREES_TO_RADIANS = Math.PI / 180;
29
+ var DAY_IN_MS = 1e3 * 60 * 60 * 24;
30
+ var JD1970 = 2440588;
31
+ var JD2000 = 2451545;
32
+ var e = DEGREES_TO_RADIANS * 23.4397;
33
+ var M0 = 357.5291;
34
+ var M1 = 0.98560028;
35
+ var THETA0 = 280.147;
36
+ var THETA1 = 360.9856235;
37
+ function getSunPosition(timestamp, latitude, longitude) {
38
+ const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
39
+ const phi = DEGREES_TO_RADIANS * latitude;
40
+ const d = toDays(timestamp);
41
+ const c = getSunCoords(d);
42
+ const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
43
+ return {
44
+ azimuth: getAzimuth(H, phi, c.declination),
45
+ altitude: getAltitude(H, phi, c.declination)
46
+ };
47
+ }
48
+ function getSunDirection(timestamp, latitude, longitude) {
49
+ const { azimuth, altitude } = getSunPosition(timestamp, latitude, longitude);
50
+ return [
51
+ Math.sin(azimuth) * Math.cos(altitude),
52
+ Math.cos(azimuth) * Math.cos(altitude),
53
+ -Math.sin(altitude)
54
+ ];
55
+ }
56
+ function toJulianDay(timestamp) {
57
+ const ts = typeof timestamp === "number" ? timestamp : timestamp.getTime();
58
+ return ts / DAY_IN_MS - 0.5 + JD1970;
59
+ }
60
+ function toDays(timestamp) {
61
+ return toJulianDay(timestamp) - JD2000;
62
+ }
63
+ function getRightAscension(eclipticLongitude, b) {
64
+ const lambda = eclipticLongitude;
65
+ return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
66
+ }
67
+ function getDeclination(eclipticLongitude, b) {
68
+ const lambda = eclipticLongitude;
69
+ return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
70
+ }
71
+ function getAzimuth(hourAngle, latitudeInRadians, declination) {
72
+ const H = hourAngle;
73
+ const phi = latitudeInRadians;
74
+ const delta = declination;
75
+ return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
76
+ }
77
+ function getAltitude(hourAngle, latitudeInRadians, declination) {
78
+ const H = hourAngle;
79
+ const phi = latitudeInRadians;
80
+ const delta = declination;
81
+ return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
82
+ }
83
+ function getSiderealTime(dates, longitudeWestInRadians) {
84
+ return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
85
+ }
86
+ function getSolarMeanAnomaly(days) {
87
+ return DEGREES_TO_RADIANS * (M0 + M1 * days);
88
+ }
89
+ function getEclipticLongitude(meanAnomaly) {
90
+ const M = meanAnomaly;
91
+ const C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 3e-4 * Math.sin(3 * M));
92
+ const P = DEGREES_TO_RADIANS * 102.9372;
93
+ return M + C + P + Math.PI;
94
+ }
95
+ function getSunCoords(dates) {
96
+ const M = getSolarMeanAnomaly(dates);
97
+ const L = getEclipticLongitude(M);
98
+ return {
99
+ declination: getDeclination(L, 0),
100
+ rightAscension: getRightAscension(L, 0)
101
+ };
102
+ }
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { getSunPosition, getSunDirection } from "./suncalc.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["getSunPosition","getSunDirection"],"mappings":"SAAQA,c,EAAgBC,e","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
package/dist/suncalc.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * The azimuth is the direction along the horizon, which we measure from south to west.
5
5
  * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
6
6
  */
7
- export declare type CelestialPosition = {
7
+ export type CelestialPosition = {
8
8
  azimuth: number;
9
9
  altitude: number;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"suncalc.d.ts","sourceRoot":"","sources":["../src/suncalc.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAanB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CASV"}
1
+ {"version":3,"file":"suncalc.d.ts","sourceRoot":"","sources":["../src/suncalc.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAanB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CASV"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":"AAAA,MAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,MAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,OAAf;AAGA,MAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,MAAMO,EAAE,GAAG,QAAX;AACA,MAAMC,EAAE,GAAG,UAAX;AAEA,MAAMC,MAAM,GAAG,O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B0B,KAAtB,EAGE;AACA,QAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,QAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLzB,IAAAA,WAAW,EAAEe,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL/B,IAAAA,cAAc,EAAEY,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["const DEGREES_TO_RADIANS = Math.PI / 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n\n // solar position to light direction\n return [\n Math.sin(azimuth) * Math.cos(altitude),\n Math.cos(azimuth) * Math.cos(altitude),\n -Math.sin(altitude)\n ];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates: number): {\n declination: number;\n rightAscension: number;\n} {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}
package/package.json CHANGED
@@ -2,10 +2,11 @@
2
2
  "name": "@math.gl/sun",
3
3
  "description": "Sun classes",
4
4
  "license": "MIT",
5
+ "type": "module",
5
6
  "publishConfig": {
6
7
  "access": "public"
7
8
  },
8
- "version": "3.6.2",
9
+ "version": "4.0.0-alpha.1",
9
10
  "keywords": [
10
11
  "javascript",
11
12
  "math",
@@ -19,8 +20,8 @@
19
20
  "url": "https://github.com/uber-web/math.gl.git"
20
21
  },
21
22
  "types": "dist/index.d.ts",
22
- "main": "dist/es5/index.js",
23
- "module": "dist/esm/index.js",
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.js",
24
25
  "files": [
25
26
  "dist",
26
27
  "src"
@@ -28,5 +29,5 @@
28
29
  "dependencies": {
29
30
  "@babel/runtime": "^7.12.0"
30
31
  },
31
- "gitHead": "517015873bbd7143bfc4bb761e70071c7a86771b"
32
+ "gitHead": "66f872ea615a3ef81431595727cdf58dcadf3670"
32
33
  }
package/dist/es5/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "getSunPosition", {
7
- enumerable: true,
8
- get: function get() {
9
- return _suncalc.getSunPosition;
10
- }
11
- });
12
- Object.defineProperty(exports, "getSunDirection", {
13
- enumerable: true,
14
- get: function get() {
15
- return _suncalc.getSunDirection;
16
- }
17
- });
18
-
19
- var _suncalc = require("./suncalc");
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSunPosition = getSunPosition;
7
- exports.getSunDirection = getSunDirection;
8
- var DEGREES_TO_RADIANS = Math.PI / 180;
9
- var DAY_IN_MS = 1000 * 60 * 60 * 24;
10
- var JD1970 = 2440588;
11
- var JD2000 = 2451545;
12
- var e = DEGREES_TO_RADIANS * 23.4397;
13
- var M0 = 357.5291;
14
- var M1 = 0.98560028;
15
- var THETA0 = 280.147;
16
- var THETA1 = 360.9856235;
17
-
18
- function getSunPosition(timestamp, latitude, longitude) {
19
- var longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
20
- var phi = DEGREES_TO_RADIANS * latitude;
21
- var d = toDays(timestamp);
22
- var c = getSunCoords(d);
23
- var H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
24
- return {
25
- azimuth: getAzimuth(H, phi, c.declination),
26
- altitude: getAltitude(H, phi, c.declination)
27
- };
28
- }
29
-
30
- function getSunDirection(timestamp, latitude, longitude) {
31
- var _getSunPosition = getSunPosition(timestamp, latitude, longitude),
32
- azimuth = _getSunPosition.azimuth,
33
- altitude = _getSunPosition.altitude;
34
-
35
- return [Math.sin(azimuth) * Math.cos(altitude), Math.cos(azimuth) * Math.cos(altitude), -Math.sin(altitude)];
36
- }
37
-
38
- function toJulianDay(timestamp) {
39
- var ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
40
- return ts / DAY_IN_MS - 0.5 + JD1970;
41
- }
42
-
43
- function toDays(timestamp) {
44
- return toJulianDay(timestamp) - JD2000;
45
- }
46
-
47
- function getRightAscension(eclipticLongitude, b) {
48
- var lambda = eclipticLongitude;
49
- return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
50
- }
51
-
52
- function getDeclination(eclipticLongitude, b) {
53
- var lambda = eclipticLongitude;
54
- return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
55
- }
56
-
57
- function getAzimuth(hourAngle, latitudeInRadians, declination) {
58
- var H = hourAngle;
59
- var phi = latitudeInRadians;
60
- var delta = declination;
61
- return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
62
- }
63
-
64
- function getAltitude(hourAngle, latitudeInRadians, declination) {
65
- var H = hourAngle;
66
- var phi = latitudeInRadians;
67
- var delta = declination;
68
- return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
69
- }
70
-
71
- function getSiderealTime(dates, longitudeWestInRadians) {
72
- return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
73
- }
74
-
75
- function getSolarMeanAnomaly(days) {
76
- return DEGREES_TO_RADIANS * (M0 + M1 * days);
77
- }
78
-
79
- function getEclipticLongitude(meanAnomaly) {
80
- var M = meanAnomaly;
81
- var C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
82
- var P = DEGREES_TO_RADIANS * 102.9372;
83
- return M + C + P + Math.PI;
84
- }
85
-
86
- function getSunCoords(dates) {
87
- var M = getSolarMeanAnomaly(dates);
88
- var L = getEclipticLongitude(M);
89
- return {
90
- declination: getDeclination(L, 0),
91
- rightAscension: getRightAscension(L, 0)
92
- };
93
- }
94
- //# sourceMappingURL=suncalc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":";;;;;;;AAAA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,IAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,OAAf;AAGA,IAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,IAAMO,EAAE,GAAG,QAAX;AACA,IAAMC,EAAE,GAAG,UAAX;AAEA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,WAAf;;AAkBO,SAASC,cAAT,CACLC,SADK,EAELC,QAFK,EAGLC,SAHK,EAIc;AACnB,MAAMC,sBAAsB,GAAGf,kBAAkB,GAAG,CAACc,SAArD;AACA,MAAME,GAAG,GAAGhB,kBAAkB,GAAGa,QAAjC;AACA,MAAMI,CAAC,GAAGC,MAAM,CAACN,SAAD,CAAhB;AAEA,MAAMO,CAAC,GAAGC,YAAY,CAACH,CAAD,CAAtB;AAEA,MAAMI,CAAC,GAAGC,eAAe,CAACL,CAAD,EAAIF,sBAAJ,CAAf,GAA6CI,CAAC,CAACI,cAAzD;AAEA,SAAO;AACLC,IAAAA,OAAO,EAAEC,UAAU,CAACJ,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX,CADd;AAELC,IAAAA,QAAQ,EAAEC,WAAW,CAACP,CAAD,EAAI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T,CAAyBwB,KAAzB,EAAwC/B,sBAAxC,EAAgF;AAC9E,SAAOf,kBAAkB,IAAIS,MAAM,GAAGC,MAAM,GAAGoC,KAAtB,CAAlB,GAAiD/B,sBAAxD;AACD;;AAED,SAASgC,mBAAT,CAA6BC,IAA7B,EAAmD;AACjD,SAAOhD,kBAAkB,IAAIO,EAAE,GAAGC,EAAE,GAAGwC,IAAd,CAAzB;AACD;;AAED,SAASC,oBAAT,CAA8BC,WAA9B,EAA2D;AACzD,MAAMC,CAAC,GAAGD,WAAV;AAEA,MAAME,CAAC,GACLpD,kBAAkB,IAAI,SAASC,IAAI,CAAC6B,GAAL,CAASqB,CAAT,CAAT,GAAuB,OAAOlD,IAAI,CAAC6B,GAAL,CAAS,IAAIqB,CAAb,CAA9B,GAAgD,SAASlD,IAAI,CAAC6B,GAAL,CAAS,IAAIqB,CAAb,CAA7D,CADpB;AAGA,MAAME,CAAC,GAAGrD,kBAAkB,GAAG,QAA/B;AAEA,SAAOmD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYpD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsB0B,KAAtB,EAGE;AACA,MAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,MAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLzB,IAAAA,WAAW,EAAEe,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL/B,IAAAA,cAAc,EAAEY,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["const DEGREES_TO_RADIANS = Math.PI / 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n\n // solar position to light direction\n return [\n Math.sin(azimuth) * Math.cos(altitude),\n Math.cos(azimuth) * Math.cos(altitude),\n -Math.sin(altitude)\n ];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates: number): {\n declination: number;\n rightAscension: number;\n} {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}
package/dist/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { getSunPosition, getSunDirection } from './suncalc';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":["getSunPosition","getSunDirection"],"mappings":"AAAA,SAAQA,cAAR,EAAwBC,eAAxB,QAA8C,WAA9C","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":"AAAA,MAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,MAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,OAAf;AAGA,MAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,MAAMO,EAAE,GAAG,QAAX;AACA,MAAMC,EAAE,GAAG,UAAX;AAEA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,WAAf;AAkBA,OAAO,SAASC,cAAT,CACLC,SADK,EAELC,QAFK,EAGLC,SAHK,EAIc;AACnB,QAAMC,sBAAsB,GAAGf,kBAAkB,GAAG,CAACc,SAArD;AACA,QAAME,GAAG,GAAGhB,kBAAkB,GAAGa,QAAjC;AACA,QAAMI,CAAC,GAAGC,MAAM,CAACN,SAAD,CAAhB;AAEA,QAAMO,CAAC,GAAGC,YAAY,CAACH,CAAD,CAAtB;AAEA,QAAMI,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 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n\n // solar position to light direction\n return [\n Math.sin(azimuth) * Math.cos(altitude),\n Math.cos(azimuth) * Math.cos(altitude),\n -Math.sin(altitude)\n ];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates: number): {\n declination: number;\n rightAscension: number;\n} {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}