swisseph-wasm 0.0.2 → 0.0.4

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.
@@ -45,7 +45,7 @@
45
45
  <h1 class="text-4xl font-bold text-center mb-2">🌟 SwissEph WebAssembly - Interactive Demo</h1>
46
46
  <p class="text-center text-blue-100 mb-4">Professional Swiss Ephemeris Calculator & Astrology Tools</p>
47
47
  <div class="text-center">
48
- <a href="https://github.com/prolaxu/swiss-wasm" target="_blank"
48
+ <a href="https://github.com/prolaxu/swisseph-wasm" target="_blank"
49
49
  class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-lg hover:bg-opacity-30 transition-all">
50
50
  <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
51
51
  <path fill-rule="evenodd" d="M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z" clip-rule="evenodd"></path>
@@ -59,6 +59,13 @@
59
59
  </svg>
60
60
  NPM Package
61
61
  </a>
62
+ <a href="api-explorer.html"
63
+ class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-lg hover:bg-opacity-30 transition-all ml-2">
64
+ <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
65
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
66
+ </svg>
67
+ API Explorer
68
+ </a>
62
69
  </div>
63
70
  </div>
64
71
  </header>
@@ -110,8 +117,14 @@
110
117
  <div id="tab-content-birth" class="tab-content hidden">
111
118
  <div class="bg-white rounded-lg shadow-md p-6">
112
119
  <h2 class="text-2xl font-bold mb-4 text-gray-800">🎂 Birth Chart Calculator</h2>
120
+ <div class="bg-green-50 border border-green-200 rounded-lg p-3 mb-4">
121
+ <p class="text-sm text-green-800">
122
+ <strong>💡 Tip:</strong> Birth location (latitude/longitude) is essential for accurate house calculations and local time corrections.
123
+ Default coordinates are set to Nepal (27.8667°N, 84.9167°E) with Nepal Standard Time (+5.75 UTC).
124
+ </p>
125
+ </div>
113
126
 
114
- <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
127
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-6">
115
128
  <div>
116
129
  <label class="block text-sm font-medium text-gray-700 mb-2">Birth Date</label>
117
130
  <input type="date" id="birth-date" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
@@ -122,13 +135,38 @@
122
135
  </div>
123
136
  <div>
124
137
  <label class="block text-sm font-medium text-gray-700 mb-2">Timezone Offset (hours from UTC)</label>
125
- <input type="number" id="birth-timezone" value="0" min="-12" max="12" step="0.5" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
138
+ <input type="number" id="birth-timezone" value="5.75" min="-12" max="12" step="0.25" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
139
+ </div>
140
+ <div>
141
+ <label class="block text-sm font-medium text-gray-700 mb-2">Birth Latitude</label>
142
+ <input type="number" id="birth-latitude" value="27.8667" step="0.0001" min="-90" max="90" placeholder="e.g. 27.8667 (Nepal)" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
143
+ </div>
144
+ <div>
145
+ <label class="block text-sm font-medium text-gray-700 mb-2">Birth Longitude</label>
146
+ <input type="number" id="birth-longitude" value="84.9167" step="0.0001" min="-180" max="180" placeholder="e.g. 84.9167 (Nepal)" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
126
147
  </div>
127
148
  <div>
128
149
  <label class="block text-sm font-medium text-gray-700 mb-2">Coordinate System</label>
129
- <select id="birth-system" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
150
+ <select id="birth-system" onchange="toggleAyanamsa('birth')" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
130
151
  <option value="tropical">Tropical</option>
131
- <option value="sidereal">Sidereal (Lahiri)</option>
152
+ <option value="sidereal">Sidereal</option>
153
+ </select>
154
+ </div>
155
+ <div id="birth-ayanamsa-container" class="hidden">
156
+ <label class="block text-sm font-medium text-gray-700 mb-2">Ayanamsa</label>
157
+ <select id="birth-ayanamsa" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
158
+ <option value="0">Fagan/Bradley</option>
159
+ <option value="1" selected>Lahiri</option>
160
+ <option value="2">De Luce</option>
161
+ <option value="3">Raman</option>
162
+ <option value="4">Ushashashi</option>
163
+ <option value="5">Krishnamurti</option>
164
+ <option value="6">Djwhal Khul</option>
165
+ <option value="7">Yukteshwar</option>
166
+ <option value="8">J.N. Bhasin</option>
167
+ <option value="21">Galactic Center (Gil Brand)</option>
168
+ <option value="27">True Chitra</option>
169
+ <option value="28">True Revati</option>
132
170
  </select>
133
171
  </div>
134
172
  </div>
@@ -151,7 +189,7 @@
151
189
  <div class="bg-white rounded-lg shadow-md p-6">
152
190
  <h2 class="text-2xl font-bold mb-4 text-gray-800">⚖️ Sidereal vs Tropical Comparison</h2>
153
191
 
154
- <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
192
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
155
193
  <div>
156
194
  <label class="block text-sm font-medium text-gray-700 mb-2">Date</label>
157
195
  <input type="date" id="compare-date" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
@@ -170,6 +208,26 @@
170
208
  <option value="4">Mars ♂</option>
171
209
  <option value="5">Jupiter ♃</option>
172
210
  <option value="6">Saturn ♄</option>
211
+ <option value="7">Uranus ♅</option>
212
+ <option value="8">Neptune ♆</option>
213
+ <option value="9">Pluto ♇</option>
214
+ </select>
215
+ </div>
216
+ <div>
217
+ <label class="block text-sm font-medium text-gray-700 mb-2">Ayanamsa</label>
218
+ <select id="compare-ayanamsa" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
219
+ <option value="0">Fagan/Bradley</option>
220
+ <option value="1" selected>Lahiri</option>
221
+ <option value="2">De Luce</option>
222
+ <option value="3">Raman</option>
223
+ <option value="4">Ushashashi</option>
224
+ <option value="5">Krishnamurti</option>
225
+ <option value="6">Djwhal Khul</option>
226
+ <option value="7">Yukteshwar</option>
227
+ <option value="8">J.N. Bhasin</option>
228
+ <option value="21">Galactic Center (Gil Brand)</option>
229
+ <option value="27">True Chitra</option>
230
+ <option value="28">True Revati</option>
173
231
  </select>
174
232
  </div>
175
233
  </div>
@@ -295,11 +353,11 @@
295
353
  </div>
296
354
  <div>
297
355
  <label class="block text-sm font-medium text-gray-700 mb-2">Latitude</label>
298
- <input type="number" id="houses-lat" value="51.5074" step="0.0001" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
356
+ <input type="number" id="houses-lat" value="27.7172" step="0.0001" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
299
357
  </div>
300
358
  <div>
301
359
  <label class="block text-sm font-medium text-gray-700 mb-2">Longitude</label>
302
- <input type="number" id="houses-lon" value="-0.1278" step="0.0001" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
360
+ <input type="number" id="houses-lon" value="85.3240" step="0.0001" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
303
361
  </div>
304
362
  </div>
305
363
 
@@ -365,16 +423,22 @@
365
423
 
366
424
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
367
425
  <div>
426
+ <label class="block text-sm font-medium text-gray-700 mb-2">Function Category</label>
427
+ <select id="api-category" onchange="updateFunctionList()" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent mb-2">
428
+ <option value="basic">🌟 Basic Calculations</option>
429
+ <option value="time">⏰ Time Functions</option>
430
+ <option value="houses">🏠 Houses & Angles</option>
431
+ <option value="ayanamsa">🔮 Ayanamsa & Sidereal</option>
432
+ <option value="eclipse">🌑 Eclipses & Occultations</option>
433
+ <option value="stars">⭐ Fixed Stars</option>
434
+ <option value="phenomena">🌙 Phenomena & Visibility</option>
435
+ <option value="coordinates">📐 Coordinate Transformations</option>
436
+ <option value="utility">🔧 Utility Functions</option>
437
+ <option value="advanced">🚀 Advanced Features</option>
438
+ </select>
368
439
  <label class="block text-sm font-medium text-gray-700 mb-2">Function</label>
369
440
  <select id="api-function" onchange="updateApiParams()" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
370
- <option value="calc_ut">calc_ut - Calculate planet position</option>
371
- <option value="julday">julday - Convert to Julian Day</option>
372
- <option value="revjul">revjul - Convert from Julian Day</option>
373
- <option value="sidtime">sidtime - Sidereal time</option>
374
- <option value="deltat">deltat - Delta T</option>
375
- <option value="get_ayanamsa">get_ayanamsa - Ayanamsa value</option>
376
- <option value="houses">houses - Calculate houses</option>
377
- <option value="version">version - Get version</option>
441
+ <!-- Functions will be populated by JavaScript -->
378
442
  </select>
379
443
  </div>
380
444
  <div>
@@ -446,10 +510,32 @@
446
510
  </div>
447
511
 
448
512
  <!-- Footer -->
449
- <footer class="mt-12 text-center text-gray-500">
450
- <p>Powered by Swiss Ephemeris WebAssembly |
451
- <a href="https://github.com/prolaxu/swiss-wasm" class="text-blue-500 hover:underline">View on GitHub</a>
452
- </p>
513
+ <footer class="mt-12 text-center">
514
+ <!-- Main Footer -->
515
+ <div class="text-gray-500 mb-3">
516
+ <p class="text-xs mb-1">⚡ Powered by Swiss Ephemeris WebAssembly |
517
+ <a href="https://github.com/prolaxu/swisseph-wasm" class="text-blue-500 hover:underline">Open Source</a>
518
+ </p>
519
+ <p class="text-xs">🇳🇵 Built with ❤️ by Laxman Adhikari from Nepal</p>
520
+ </div>
521
+
522
+ <!-- Support Section -->
523
+ <div class="mb-3">
524
+ <p class="text-xs text-gray-600 mb-2">
525
+ ☕ Enjoying this free tool?
526
+ <a href="https://ko-fi.com/prolaxu" target="_blank"
527
+ class="text-blue-500 hover:text-blue-600 font-medium">Support on Ko-fi</a>
528
+ </p>
529
+ </div>
530
+
531
+ <!-- Bottom Links -->
532
+ <div class="text-xs text-gray-400 border-t border-gray-200 pt-3">
533
+ <p>
534
+ <a href="https://github.com/prolaxu/swisseph-wasm" class="hover:text-blue-500">Documentation</a> •
535
+ <a href="https://github.com/prolaxu/swisseph-wasm/issues" class="hover:text-blue-500">Report Issues</a> •
536
+ <a href="https://www.astro.com/swisseph/" class="hover:text-blue-500">Swiss Ephemeris</a>
537
+ </p>
538
+ </div>
453
539
  </footer>
454
540
  </div>
455
541
 
@@ -546,6 +632,18 @@
546
632
  return `${degree.toFixed(2)}° ${zodiacSigns[sign]}`;
547
633
  }
548
634
 
635
+ // Toggle ayanamsa visibility
636
+ window.toggleAyanamsa = function(prefix) {
637
+ const systemSelect = document.getElementById(`${prefix}-system`);
638
+ const ayanamsaContainer = document.getElementById(`${prefix}-ayanamsa-container`);
639
+
640
+ if (systemSelect.value === 'sidereal') {
641
+ ayanamsaContainer.classList.remove('hidden');
642
+ } else {
643
+ ayanamsaContainer.classList.add('hidden');
644
+ }
645
+ };
646
+
549
647
  // Calculate current positions
550
648
  window.calculateCurrentPositions = async function() {
551
649
  if (!initialized) return;
@@ -591,11 +689,13 @@
591
689
  // Calculate birth chart
592
690
  window.calculateBirthChart = async function() {
593
691
  if (!initialized) return;
594
-
692
+
595
693
  try {
596
694
  const date = document.getElementById('birth-date').value;
597
695
  const time = document.getElementById('birth-time').value;
598
696
  const timezone = parseFloat(document.getElementById('birth-timezone').value);
697
+ const latitude = parseFloat(document.getElementById('birth-latitude').value);
698
+ const longitude = parseFloat(document.getElementById('birth-longitude').value);
599
699
  const system = document.getElementById('birth-system').value;
600
700
 
601
701
  if (!date || !time) {
@@ -603,15 +703,21 @@
603
703
  return;
604
704
  }
605
705
 
706
+ if (isNaN(latitude) || isNaN(longitude)) {
707
+ showError('Please enter valid latitude and longitude');
708
+ return;
709
+ }
710
+
606
711
  const [year, month, day] = date.split('-').map(Number);
607
712
  const [hour, minute] = time.split(':').map(Number);
608
-
713
+
609
714
  const utcHour = hour + minute / 60 - timezone;
610
715
  const jd = swe.julday(year, month, day, utcHour);
611
716
 
612
717
  // Set sidereal mode if needed
613
718
  if (system === 'sidereal') {
614
- swe.set_sid_mode(swe.SE_SIDM_LAHIRI, 0, 0);
719
+ const ayanamsa = parseInt(document.getElementById('birth-ayanamsa').value);
720
+ swe.set_sid_mode(ayanamsa, 0, 0);
615
721
  }
616
722
 
617
723
  const flags = system === 'sidereal' ?
@@ -638,8 +744,8 @@
638
744
  planetsContainer.appendChild(planetCard);
639
745
  }
640
746
 
641
- document.getElementById('birth-info').textContent =
642
- `Birth Chart (${system}): ${date} ${time} UTC${timezone >= 0 ? '+' : ''}${timezone} (JD: ${jd.toFixed(6)})`;
747
+ document.getElementById('birth-info').textContent =
748
+ `Birth Chart (${system}): ${date} ${time} UTC${timezone >= 0 ? '+' : ''}${timezone} | Location: ${latitude.toFixed(4)}°N, ${longitude.toFixed(4)}°E (JD: ${jd.toFixed(6)})`;
643
749
  document.getElementById('birth-results').classList.remove('hidden');
644
750
 
645
751
  } catch (error) {
@@ -670,9 +776,10 @@
670
776
  const tropical = swe.calc_ut(jd, planetId, swe.SEFLG_SWIEPH);
671
777
 
672
778
  // Sidereal position
673
- swe.set_sid_mode(swe.SE_SIDM_LAHIRI, 0, 0);
779
+ const ayanamsa = parseInt(document.getElementById('compare-ayanamsa').value);
780
+ swe.set_sid_mode(ayanamsa, 0, 0);
674
781
  const sidereal = swe.calc_ut(jd, planetId, swe.SEFLG_SWIEPH | swe.SEFLG_SIDEREAL);
675
- const ayanamsa = swe.get_ayanamsa(jd);
782
+ const ayanamsaValue = swe.get_ayanamsa(jd);
676
783
 
677
784
  document.getElementById('tropical-result').innerHTML = `
678
785
  <p class="font-bold">${formatPosition(tropical[0])}</p>
@@ -684,7 +791,7 @@
684
791
  <p class="text-sm text-gray-600">${sidereal[0].toFixed(6)}°</p>
685
792
  `;
686
793
 
687
- document.getElementById('ayanamsa-value').textContent = `${ayanamsa.toFixed(6)}°`;
794
+ document.getElementById('ayanamsa-value').textContent = `${ayanamsaValue.toFixed(6)}°`;
688
795
  document.getElementById('difference-value').textContent = `${(tropical[0] - sidereal[0]).toFixed(6)}°`;
689
796
  document.getElementById('julian-day-value').textContent = jd.toFixed(6);
690
797
 
@@ -905,23 +1012,146 @@
905
1012
  }
906
1013
  };
907
1014
 
908
- // API Explorer functions
1015
+ // API Explorer functions - Complete function database
1016
+ const swissEphFunctions = {
1017
+ basic: {
1018
+ 'calc_ut': { params: '[2460218.5, 0, 2]', desc: 'Calculate planet position (UT)' },
1019
+ 'calc': { params: '[2460218.5, 0, 2]', desc: 'Calculate planet position (ET)' },
1020
+ 'get_planet_name': { params: '[0]', desc: 'Get planet name by ID' },
1021
+ 'pheno': { params: '[2460218.5, 0, 2]', desc: 'Planetary phenomena (ET)' },
1022
+ 'pheno_ut': { params: '[2460218.5, 0, 2]', desc: 'Planetary phenomena (UT)' },
1023
+ 'version': { params: '[]', desc: 'Get Swiss Ephemeris version' }
1024
+ },
1025
+ time: {
1026
+ 'julday': { params: '[2023, 6, 15, 12.0]', desc: 'Convert to Julian Day' },
1027
+ 'revjul': { params: '[2460218.5, 1]', desc: 'Convert from Julian Day' },
1028
+ 'sidtime': { params: '[2460218.5]', desc: 'Sidereal time' },
1029
+ 'sidtime0': { params: '[2460218.5, 23.4, 0]', desc: 'Sidereal time with obliquity' },
1030
+ 'deltat': { params: '[2460218.5]', desc: 'Delta T (ET-UT)' },
1031
+ 'time_equ': { params: '[2460218.5]', desc: 'Equation of time' },
1032
+ 'day_of_week': { params: '[2460218.5]', desc: 'Day of week (0=Monday)' },
1033
+ 'date_conversion': { params: '[2023, 6, 15, 12, 1]', desc: 'Date conversion' },
1034
+ 'utc_to_jd': { params: '[2023, 6, 15, 12, 0, 0, 1]', desc: 'UTC to Julian Day' },
1035
+ 'jdet_to_utc': { params: '[2460218.5, 1]', desc: 'JD (ET) to UTC' },
1036
+ 'jdut1_to_utc': { params: '[2460218.5, 1]', desc: 'JD (UT1) to UTC' },
1037
+ 'utc_time_zone': { params: '[2023, 6, 15, 12, 0, 0, 5.5]', desc: 'UTC with timezone' }
1038
+ },
1039
+ houses: {
1040
+ 'houses': { params: '[2460218.5, 51.5074, -0.1278, "P"]', desc: 'Calculate houses' },
1041
+ 'houses_ex': { params: '[2460218.5, 2, 51.5074, -0.1278, "P"]', desc: 'Houses with flags' },
1042
+ 'houses_ex2': { params: '[2460218.5, 2, 51.5074, -0.1278, "P"]', desc: 'Houses extended' },
1043
+ 'houses_armc': { params: '[180, 51.5074, 23.4, "P"]', desc: 'Houses from ARMC' },
1044
+ 'houses_armc_ex2': { params: '[180, 51.5074, 23.4, "P"]', desc: 'Houses ARMC extended' },
1045
+ 'house_pos': { params: '[180, 51.5074, 23.4, "P", 120, 0]', desc: 'House position of point' }
1046
+ },
1047
+ ayanamsa: {
1048
+ 'get_ayanamsa': { params: '[2460218.5]', desc: 'Get ayanamsa value' },
1049
+ 'get_ayanamsa_ut': { params: '[2460218.5]', desc: 'Get ayanamsa (UT)' },
1050
+ 'get_ayanamsa_ex': { params: '[2460218.5, 2]', desc: 'Get ayanamsa extended' },
1051
+ 'get_ayanamsa_ex_ut': { params: '[2460218.5, 2]', desc: 'Get ayanamsa extended (UT)' },
1052
+ 'get_ayanamsa_name': { params: '[1]', desc: 'Get ayanamsa name' },
1053
+ 'set_sid_mode': { params: '[1, 0, 0]', desc: 'Set sidereal mode' }
1054
+ },
1055
+ eclipse: {
1056
+ 'sol_eclipse_when_glob': { params: '[2460218.5, 2, 0, 0]', desc: 'Next solar eclipse globally' },
1057
+ 'sol_eclipse_when_loc': { params: '[2460218.5, 2, -0.1278, 51.5074, 0, 0]', desc: 'Solar eclipse at location' },
1058
+ 'sol_eclipse_where': { params: '[2460218.5, 2]', desc: 'Solar eclipse visibility' },
1059
+ 'sol_eclipse_how': { params: '[2460218.5, 2, -0.1278, 51.5074, 0]', desc: 'Solar eclipse magnitude' },
1060
+ 'lun_eclipse_when': { params: '[2460218.5, 2, 0, 0]', desc: 'Next lunar eclipse' },
1061
+ 'lun_eclipse_when_loc': { params: '[2460218.5, 2, -0.1278, 51.5074, 0, 0]', desc: 'Lunar eclipse at location' },
1062
+ 'lun_eclipse_how': { params: '[2460218.5, 2, -0.1278, 51.5074, 0]', desc: 'Lunar eclipse magnitude' },
1063
+ 'lun_occult_when_glob': { params: '[2460218.5, 1, "", 2, 0, 0]', desc: 'Lunar occultation globally' },
1064
+ 'lun_occult_when_loc': { params: '[2460218.5, 1, "", 2, -0.1278, 51.5074, 0, 0]', desc: 'Lunar occultation locally' },
1065
+ 'lun_occult_where': { params: '[2460218.5, 1, "", 2]', desc: 'Lunar occultation visibility' }
1066
+ },
1067
+ stars: {
1068
+ 'fixstar': { params: '["Sirius", 2460218.5, 2]', desc: 'Fixed star position' },
1069
+ 'fixstar2': { params: '["Sirius", 2460218.5, 2]', desc: 'Fixed star position v2' },
1070
+ 'fixstar2_ut': { params: '["Sirius", 2460218.5, 2]', desc: 'Fixed star position v2 (UT)' },
1071
+ 'fixstar_mag': { params: '["Sirius"]', desc: 'Fixed star magnitude' },
1072
+ 'fixstar2_mag': { params: '["Sirius"]', desc: 'Fixed star magnitude v2' }
1073
+ },
1074
+ phenomena: {
1075
+ 'rise_trans': { params: '[2460218.5, 0, -0.1278, 51.5074, 0, 1]', desc: 'Rise/transit/set times' },
1076
+ 'rise_trans_true_hor': { params: '[2460218.5, 0, -0.1278, 51.5074, 0, 1]', desc: 'Rise/set true horizon' },
1077
+ 'azal': { params: '[2460218.5, 51.5074, -0.1278, 0, 0]', desc: 'Azimuth/altitude' },
1078
+ 'azal_rev': { params: '[2460218.5, 51.5074, -0.1278, 0, 0]', desc: 'Reverse azimuth/altitude' },
1079
+ 'heliacal_ut': { params: '[2460218.5, [51.5074, -0.1278, 0], [1013, 15, 40, 0.25], [1.8, 25, 1, 1, 1, 1], "Venus", 1, 0]', desc: 'Heliacal phenomena' },
1080
+ 'heliacal_pheno_ut': { params: '[2460218.5, [51.5074, -0.1278, 0], [1013, 15, 40, 0.25], [1.8, 25, 1, 1, 1, 1], "Venus", 1, 0]', desc: 'Heliacal phenomena details' },
1081
+ 'vis_limit_mag': { params: '[2460218.5, [51.5074, -0.1278, 0], [1013, 15, 40, 0.25], [1.8, 25, 1, 1, 1, 1], "Venus", 0]', desc: 'Visibility limit magnitude' }
1082
+ },
1083
+ coordinates: {
1084
+ 'cotrans': { params: '[[120, 30, 1], 23.4]', desc: 'Coordinate transformation' },
1085
+ 'cotrans_sp': { params: '[[120, 30, 1], 23.4]', desc: 'Coordinate transformation with speed' },
1086
+ 'refrac': { params: '[2460218.5, 51.5074, -0.1278, 0, 1013, 15]', desc: 'Atmospheric refraction' },
1087
+ 'refrac_extended': { params: '[2460218.5, 51.5074, -0.1278, 0, 1013, 15, 1]', desc: 'Extended refraction' }
1088
+ },
1089
+ utility: {
1090
+ 'degnorm': { params: '[390]', desc: 'Normalize degrees (0-360)' },
1091
+ 'radnorm': { params: '[7]', desc: 'Normalize radians (0-2π)' },
1092
+ 'deg_midp': { params: '[10, 350]', desc: 'Midpoint in degrees' },
1093
+ 'rad_midp': { params: '[0.1, 6.1]', desc: 'Midpoint in radians' },
1094
+ 'difdegn': { params: '[10, 350]', desc: 'Degree difference normalized' },
1095
+ 'difdeg2n': { params: '[10, 350]', desc: 'Degree difference 2π normalized' },
1096
+ 'difrad2n': { params: '[0.1, 6.1]', desc: 'Radian difference 2π normalized' },
1097
+ 'difcsn': { params: '[10, 350]', desc: 'Centisecond difference normalized' },
1098
+ 'difcs2n': { params: '[10, 350]', desc: 'Centisecond difference 2π normalized' },
1099
+ 'csnorm': { params: '[390000]', desc: 'Normalize centiseconds' },
1100
+ 'csroundsec': { params: '[123456]', desc: 'Round centiseconds to seconds' },
1101
+ 'd2l': { params: '[123.456]', desc: 'Double to long conversion' },
1102
+ 'split_deg': { params: '[123.456789, 0]', desc: 'Split degrees to D°M\'S"' },
1103
+ 'cs2timestr': { params: '[123456, 58, 0]', desc: 'Centiseconds to time string' },
1104
+ 'cs2lonlatstr': { params: '[123456, "E", "W"]', desc: 'Centiseconds to lon/lat string' },
1105
+ 'cs2degstr': { params: '[123456]', desc: 'Centiseconds to degree string' }
1106
+ },
1107
+ advanced: {
1108
+ 'nod_aps': { params: '[2460218.5, 0, 2, 0]', desc: 'Nodes and apsides' },
1109
+ 'nod_aps_ut': { params: '[2460218.5, 0, 2, 0]', desc: 'Nodes and apsides (UT)' },
1110
+ 'get_orbital_elements': { params: '[2460218.5, 0, 2]', desc: 'Orbital elements' },
1111
+ 'orbit_max_min_true_distance': { params: '[2460218.5, 0, 2]', desc: 'Orbital distances' },
1112
+ 'set_ephe_path': { params: '["/path/to/ephemeris"]', desc: 'Set ephemeris path' },
1113
+ 'set_jpl_file': { params: '["de431.eph"]', desc: 'Set JPL ephemeris file' },
1114
+ 'set_topo': { params: '[-0.1278, 51.5074, 0]', desc: 'Set topocentric location' },
1115
+ 'set_tid_acc': { params: '[23.8946]', desc: 'Set tidal acceleration' },
1116
+ 'get_tid_acc': { params: '[]', desc: 'Get tidal acceleration' },
1117
+ 'set_lapse_rate': { params: '[0.0065]', desc: 'Set atmospheric lapse rate' },
1118
+ 'close': { params: '[]', desc: 'Close Swiss Ephemeris' }
1119
+ }
1120
+ };
1121
+
1122
+ window.updateFunctionList = function() {
1123
+ const category = document.getElementById('api-category').value;
1124
+ const functionSelect = document.getElementById('api-function');
1125
+
1126
+ functionSelect.innerHTML = '';
1127
+
1128
+ const functions = swissEphFunctions[category] || {};
1129
+ for (const [funcName, funcData] of Object.entries(functions)) {
1130
+ const option = document.createElement('option');
1131
+ option.value = funcName;
1132
+ option.textContent = `${funcName} - ${funcData.desc}`;
1133
+ functionSelect.appendChild(option);
1134
+ }
1135
+
1136
+ // Update parameters for first function
1137
+ if (Object.keys(functions).length > 0) {
1138
+ updateApiParams();
1139
+ }
1140
+ };
1141
+
909
1142
  window.updateApiParams = function() {
1143
+ const category = document.getElementById('api-category').value;
910
1144
  const func = document.getElementById('api-function').value;
911
1145
  const paramsField = document.getElementById('api-params');
912
1146
 
913
- const examples = {
914
- 'calc_ut': '[2460218.5, 0, 2]',
915
- 'julday': '[2023, 6, 15, 12.0]',
916
- 'revjul': '[2460218.5, 1]',
917
- 'sidtime': '[2460218.5]',
918
- 'deltat': '[2460218.5]',
919
- 'get_ayanamsa': '[2460218.5]',
920
- 'houses': '[2460218.5, 51.5074, -0.1278, "P"]',
921
- 'version': '[]'
922
- };
923
-
924
- paramsField.value = examples[func] || '[]';
1147
+ const functions = swissEphFunctions[category] || {};
1148
+ const funcData = functions[func];
1149
+
1150
+ if (funcData) {
1151
+ paramsField.value = funcData.params;
1152
+ } else {
1153
+ paramsField.value = '[]';
1154
+ }
925
1155
  };
926
1156
 
927
1157
  window.executeApiCall = function() {
@@ -933,41 +1163,45 @@
933
1163
  const params = JSON.parse(paramsStr);
934
1164
 
935
1165
  let result;
936
- switch (func) {
937
- case 'calc_ut':
938
- result = swe.calc_ut(...params);
939
- break;
940
- case 'julday':
941
- result = swe.julday(...params);
942
- break;
943
- case 'revjul':
944
- result = swe.revjul(...params);
945
- break;
946
- case 'sidtime':
947
- result = swe.sidtime(...params);
948
- break;
949
- case 'deltat':
950
- result = swe.deltat(...params);
951
- break;
952
- case 'get_ayanamsa':
953
- result = swe.get_ayanamsa(...params);
954
- break;
955
- case 'houses':
956
- result = swe.houses(...params);
957
- break;
958
- case 'version':
959
- result = swe.version();
960
- break;
961
- default:
962
- throw new Error('Unknown function');
1166
+
1167
+ // Check if the function exists on the swe object
1168
+ if (typeof swe[func] === 'function') {
1169
+ result = swe[func](...params);
1170
+ } else {
1171
+ throw new Error(`Function '${func}' not found in Swiss Ephemeris`);
1172
+ }
1173
+
1174
+ // Format result for display
1175
+ let displayResult;
1176
+ if (Array.isArray(result)) {
1177
+ displayResult = result;
1178
+ } else if (typeof result === 'object' && result !== null) {
1179
+ displayResult = result;
1180
+ } else {
1181
+ displayResult = result;
963
1182
  }
964
1183
 
965
- document.getElementById('api-output').textContent = JSON.stringify(result, null, 2);
966
- document.getElementById('api-code').textContent = `const result = swe.${func}(${paramsStr.slice(1, -1)});`;
1184
+ document.getElementById('api-output').textContent = JSON.stringify(displayResult, null, 2);
1185
+
1186
+ // Generate code example
1187
+ let codeExample;
1188
+ if (params.length === 0) {
1189
+ codeExample = `const result = swe.${func}();`;
1190
+ } else {
1191
+ const paramStr = params.map(p => {
1192
+ if (typeof p === 'string') return `"${p}"`;
1193
+ if (Array.isArray(p)) return JSON.stringify(p);
1194
+ return p;
1195
+ }).join(', ');
1196
+ codeExample = `const result = swe.${func}(${paramStr});`;
1197
+ }
1198
+
1199
+ document.getElementById('api-code').textContent = codeExample;
967
1200
  document.getElementById('api-results').classList.remove('hidden');
968
1201
 
969
1202
  } catch (error) {
970
1203
  showError('API call failed: ' + error.message);
1204
+ console.error('API Error:', error);
971
1205
  }
972
1206
  };
973
1207
 
@@ -1184,6 +1418,9 @@
1184
1418
 
1185
1419
  // Initialize when page loads
1186
1420
  initSwissEph();
1421
+
1422
+ // Initialize API Explorer
1423
+ updateFunctionList();
1187
1424
  </script>
1188
1425
 
1189
1426
  <style>