@zendir/ui 0.2.9 → 0.2.10

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.
@@ -78,47 +78,15 @@ function hexToRgb(hex) {
78
78
  }
79
79
  return [255, 238, 221];
80
80
  }
81
- function calculateSubSolarPoint(date) {
82
- const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 864e5);
83
- const declination = -23.44 * Math.cos(2 * Math.PI / 365 * (dayOfYear + 10));
84
- const B = 2 * Math.PI / 365 * (dayOfYear - 81);
85
- const eotMinutes = 9.87 * Math.sin(2 * B) - 7.53 * Math.cos(B) - 1.5 * Math.sin(B);
86
- const utcHours = date.getUTCHours() + date.getUTCMinutes() / 60 + date.getUTCSeconds() / 3600;
87
- const solarHours = utcHours + eotMinutes / 60;
88
- const lon = -(solarHours - 12) * 15;
89
- return [declination, (lon + 540) % 360 - 180];
90
- }
91
- function calculateSubLunarPoint(date) {
92
- const J2000 = Date.UTC(2e3, 0, 1, 12, 0, 0);
93
- const d = (date.getTime() - J2000) / 864e5;
94
- const DEG = Math.PI / 180;
95
- const L = (218.316 + 13.176396 * d) % 360;
96
- const M = (134.963 + 13.064993 * d) % 360;
97
- const F = (93.272 + 13.22935 * d) % 360;
98
- const lon_ecl = L + 6.289 * Math.sin(M * DEG);
99
- const lat_ecl = 5.128 * Math.sin(F * DEG);
100
- const obliquity = 23.439 - 36e-8 * d;
101
- const sinRA = Math.sin(lon_ecl * DEG) * Math.cos(obliquity * DEG) - Math.tan(lat_ecl * DEG) * Math.sin(obliquity * DEG);
102
- const cosRA = Math.cos(lon_ecl * DEG);
103
- let RA = Math.atan2(sinRA, cosRA) / DEG;
104
- if (RA < 0) RA += 360;
105
- const dec = Math.asin(
106
- Math.sin(lat_ecl * DEG) * Math.cos(obliquity * DEG) + Math.cos(lat_ecl * DEG) * Math.sin(obliquity * DEG) * Math.sin(lon_ecl * DEG)
107
- ) / DEG;
108
- const GMST = (280.46061837 + 360.98564736629 * d) % 360;
109
- let geoLon = RA - GMST;
110
- geoLon = (geoLon + 540) % 360 - 180;
111
- return [dec, geoLon];
112
- }
113
81
  function calculateTerminatorContinuous(date, depressionDeg = 0, numPoints = 360) {
114
- const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 864e5);
82
+ const dayOfYear = Math.floor((date.getTime() - Date.UTC(date.getUTCFullYear(), 0, 0)) / 864e5);
115
83
  const declination = -23.44 * Math.cos(2 * Math.PI / 365 * (dayOfYear + 10));
116
84
  const decRad = declination * Math.PI / 180;
117
85
  const B = 2 * Math.PI / 365 * (dayOfYear - 81);
118
86
  const eotMinutes = 9.87 * Math.sin(2 * B) - 7.53 * Math.cos(B) - 1.5 * Math.sin(B);
119
87
  const utcHours = date.getUTCHours() + date.getUTCMinutes() / 60 + date.getUTCSeconds() / 3600;
120
88
  const solarHours = utcHours + eotMinutes / 60;
121
- const hourAngle = solarHours / 24 * 360 - 180;
89
+ const subSolarLon = -(solarHours - 12) * 15;
122
90
  const depRad = depressionDeg * Math.PI / 180;
123
91
  const sunset = [];
124
92
  const sunrise = [];
@@ -128,12 +96,12 @@ function calculateTerminatorContinuous(date, depressionDeg = 0, numPoints = 360)
128
96
  const cosH = -(Math.sin(depRad) + Math.sin(latRad) * Math.sin(decRad)) / (Math.cos(latRad) * Math.cos(decRad));
129
97
  if (cosH < -1) ;
130
98
  else if (cosH > 1) {
131
- sunset.push([lat, hourAngle]);
132
- sunrise.push([lat, hourAngle + 360]);
99
+ sunset.push([lat, subSolarLon]);
100
+ sunrise.push([lat, subSolarLon + 360]);
133
101
  } else {
134
102
  const H = Math.acos(cosH) * 180 / Math.PI;
135
- sunset.push([lat, hourAngle + H]);
136
- sunrise.push([lat, hourAngle + 360 - H]);
103
+ sunset.push([lat, subSolarLon + H]);
104
+ sunrise.push([lat, subSolarLon + 360 - H]);
137
105
  }
138
106
  }
139
107
  return { sunset, sunrise };
@@ -266,13 +234,13 @@ function GroundTrackMap({
266
234
  ctx.fillRect(0, 0, W, H);
267
235
  if (showTerminator) {
268
236
  const now = terminatorTime ?? /* @__PURE__ */ new Date();
269
- const BAND_STEP = 2;
270
- const MAX_DEP = 24;
271
- const NIGHT_ALPHA = 0.55;
237
+ const BAND_STEP = 1.5;
238
+ const MAX_DEP = 30;
239
+ const NIGHT_ALPHA = 0.38;
272
240
  const bandSteps = [];
273
241
  for (let d = 0; d <= MAX_DEP; d += BAND_STEP) {
274
242
  const t = Math.min(d / 18, 1);
275
- const alpha = t * t * (NIGHT_ALPHA * 0.82) + (d > 18 ? (d - 18) / 6 * (NIGHT_ALPHA * 0.18) : 0);
243
+ const alpha = Math.pow(t, 1.6) * (NIGHT_ALPHA * 0.85) + (d > 18 ? (d - 18) / 12 * (NIGHT_ALPHA * 0.15) : 0);
276
244
  bandSteps.push({ depression: d, alpha: Math.min(alpha, NIGHT_ALPHA) });
277
245
  }
278
246
  bandSteps.push({ depression: 90, alpha: NIGHT_ALPHA });
@@ -294,7 +262,7 @@ function GroundTrackMap({
294
262
  prevAlpha = zone.alpha;
295
263
  continue;
296
264
  }
297
- ctx.fillStyle = `rgba(0, 6, 24, ${bandAlpha.toFixed(4)})`;
265
+ ctx.fillStyle = `rgba(42, 58, 82, ${bandAlpha.toFixed(4)})`;
298
266
  for (const offset of [-360, 0, 360]) {
299
267
  ctx.beginPath();
300
268
  for (let i = 0; i < poly.length; i++) {
@@ -316,8 +284,8 @@ function GroundTrackMap({
316
284
  const terminatorEdge = calculateTerminatorContinuous(now, 0);
317
285
  if (terminatorEdge.sunset.length > 2) {
318
286
  ctx.save();
319
- ctx.strokeStyle = "rgba(90, 142, 200, 0.12)";
320
- ctx.lineWidth = 4;
287
+ ctx.strokeStyle = "rgba(143, 174, 200, 0.08)";
288
+ ctx.lineWidth = 3;
321
289
  for (const curve of [terminatorEdge.sunset, terminatorEdge.sunrise]) {
322
290
  for (const offset of [-360, 0, 360]) {
323
291
  ctx.beginPath();
@@ -330,7 +298,7 @@ function GroundTrackMap({
330
298
  ctx.stroke();
331
299
  }
332
300
  }
333
- ctx.strokeStyle = "rgba(122, 164, 212, 0.5)";
301
+ ctx.strokeStyle = "rgba(154, 184, 216, 0.35)";
334
302
  ctx.lineWidth = 1;
335
303
  for (const curve of [terminatorEdge.sunset, terminatorEdge.sunrise]) {
336
304
  for (const offset of [-360, 0, 360]) {
@@ -346,54 +314,6 @@ function GroundTrackMap({
346
314
  }
347
315
  ctx.restore();
348
316
  }
349
- const celestialEnabled = showCelestialMarkers !== void 0 ? showCelestialMarkers : true;
350
- if (celestialEnabled) {
351
- const [sunLat, sunLon] = calculateSubSolarPoint(now);
352
- const sx = lonToX(sunLon, W), sy = latToY(sunLat, H);
353
- ctx.save();
354
- ctx.shadowColor = "rgba(255, 179, 0, 0.5)";
355
- ctx.shadowBlur = 8;
356
- ctx.fillStyle = "#FFB300";
357
- ctx.strokeStyle = "#FF8F00";
358
- ctx.lineWidth = 1.2;
359
- ctx.beginPath();
360
- ctx.arc(sx, sy, 6, 0, Math.PI * 2);
361
- ctx.fill();
362
- ctx.stroke();
363
- ctx.shadowBlur = 0;
364
- ctx.strokeStyle = "rgba(255, 179, 0, 0.85)";
365
- ctx.lineWidth = 1.4;
366
- for (let a = 0; a < 360; a += 45) {
367
- const rad = a * Math.PI / 180;
368
- ctx.beginPath();
369
- ctx.moveTo(sx + 8 * Math.cos(rad), sy + 8 * Math.sin(rad));
370
- ctx.lineTo(sx + 12 * Math.cos(rad), sy + 12 * Math.sin(rad));
371
- ctx.stroke();
372
- }
373
- ctx.restore();
374
- const [moonLat, moonLon] = calculateSubLunarPoint(now);
375
- const mx = lonToX(moonLon, W), my = latToY(moonLat, H);
376
- ctx.save();
377
- ctx.shadowColor = "rgba(224, 224, 224, 0.4)";
378
- ctx.shadowBlur = 6;
379
- ctx.fillStyle = "#e0e0e0";
380
- ctx.strokeStyle = "#9e9e9e";
381
- ctx.lineWidth = 0.8;
382
- ctx.beginPath();
383
- ctx.arc(mx, my, 5.5, 0, Math.PI * 2);
384
- ctx.fill();
385
- ctx.stroke();
386
- ctx.shadowBlur = 0;
387
- ctx.fillStyle = "rgba(189, 189, 189, 0.5)";
388
- ctx.beginPath();
389
- ctx.arc(mx - 1.5, my - 1, 1.4, 0, Math.PI * 2);
390
- ctx.fill();
391
- ctx.fillStyle = "rgba(189, 189, 189, 0.4)";
392
- ctx.beginPath();
393
- ctx.arc(mx + 2, my + 1.5, 0.9, 0, Math.PI * 2);
394
- ctx.fill();
395
- ctx.restore();
396
- }
397
317
  }
398
318
  ctx.fillStyle = COLORS.land;
399
319
  ctx.strokeStyle = "rgba(100, 120, 160, 0.25)";
@@ -624,12 +544,12 @@ function GroundTrackMap({
624
544
  const r = light.radius ?? 4;
625
545
  const intensity = light.intensity ?? 0.8;
626
546
  const color = light.color ?? "#ffeedd";
627
- const dayOfYear = Math.floor((now.getTime() - new Date(now.getFullYear(), 0, 0).getTime()) / 864e5);
547
+ const dayOfYear = Math.floor((now.getTime() - Date.UTC(now.getUTCFullYear(), 0, 0)) / 864e5);
628
548
  const declination = -23.44 * Math.cos(2 * Math.PI / 365 * (dayOfYear + 10));
629
549
  const decRad = declination * Math.PI / 180;
630
- const hourAngle = (now.getUTCHours() + now.getUTCMinutes() / 60) / 24 * 360 - 180;
550
+ const lsSubSolarLon = -(now.getUTCHours() + now.getUTCMinutes() / 60 - 12) * 15;
631
551
  const latRad = light.latitude * Math.PI / 180;
632
- const sinAlt = Math.sin(latRad) * Math.sin(decRad) + Math.cos(latRad) * Math.cos(decRad) * Math.cos((light.longitude - hourAngle) * Math.PI / 180);
552
+ const sinAlt = Math.sin(latRad) * Math.sin(decRad) + Math.cos(latRad) * Math.cos(decRad) * Math.cos((light.longitude - lsSubSolarLon) * Math.PI / 180);
633
553
  const solarAltDeg = Math.asin(sinAlt) * 180 / Math.PI;
634
554
  let nightFactor;
635
555
  if (solarAltDeg >= 0) nightFactor = 0;