swisseph-wasm 0.0.1 โ†’ 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.
package/README.md CHANGED
@@ -4,13 +4,36 @@ A high-precision JavaScript wrapper for the Swiss Ephemeris WebAssembly module,
4
4
 
5
5
  ## ๐ŸŒŸ Features
6
6
 
7
- - **High Precision**: Based on the renowned Swiss Ephemeris
8
- - **WebAssembly Performance**: Fast calculations in the browser and Node.js
9
- - **Comprehensive API**: Full access to Swiss Ephemeris functions
10
- - **Modern JavaScript**: ES6+ with async/await support
11
- - **Well Tested**: 106 tests with 86% coverage
12
- - **Complete Documentation**: Extensive guides and examples
13
- - **Professional Grade**: Suitable for commercial applications
7
+ - **๐ŸŽฏ High Precision**: Based on the renowned Swiss Ephemeris
8
+ - **โšก WebAssembly Performance**: Fast calculations in browser and Node.js
9
+ - **๐ŸŒ Cross-Platform**: Works in Node.js, browsers, Vue.js, React, and more
10
+ - **๐Ÿ“ฆ Zero Dependencies**: Self-contained with embedded WASM
11
+ - **๐Ÿ”ง Easy Integration**: Simple import, works with all modern bundlers
12
+ - **๐Ÿ“š Comprehensive API**: Full access to Swiss Ephemeris functions
13
+ - **๐Ÿ’ป Modern JavaScript**: ES6+ with async/await support
14
+ - **๐Ÿงช Well Tested**: 106 tests with 86% coverage
15
+ - **๐Ÿ“– Complete Documentation**: Extensive guides and examples
16
+ - **๐Ÿข Professional Grade**: Suitable for commercial applications
17
+ - **๐Ÿ”„ CDN Ready**: Available via jsdelivr CDN for quick prototyping
18
+
19
+ ---
20
+
21
+ **โ˜• Enjoying this project?** [Support development on Ko-fi](https://ko-fi.com/prolaxu) to help keep it free and actively maintained!
22
+
23
+ ---
24
+
25
+ ## ๐Ÿš€ Live Demo
26
+
27
+ **Try it now**: [Interactive SwissEph Demo](https://prolaxu.github.io/swisseph-wasm/examples/demo.html)
28
+
29
+ Experience all features including:
30
+ - ๐ŸŒ Real-time planetary positions
31
+ - ๐ŸŽ‚ Birth chart calculations
32
+ - โš–๏ธ Sidereal vs Tropical comparisons
33
+ - ๐Ÿ  House system calculations
34
+ - ๐Ÿ“ Planetary aspects analysis
35
+ - ๐Ÿ”ง Interactive API explorer
36
+ - ๐Ÿ“Š Visual astrological charts
14
37
 
15
38
  ## ๐Ÿ“ฆ Installation
16
39
 
@@ -29,6 +52,14 @@ yarn add swisseph-wasm
29
52
  pnpm add swisseph-wasm
30
53
  ```
31
54
 
55
+ ### CDN (Browser)
56
+ ```html
57
+ <script type="module">
58
+ import SwissEph from 'https://cdn.jsdelivr.net/gh/prolaxu/swisseph-wasm@main/src/swisseph.js';
59
+ // Your code here
60
+ </script>
61
+ ```
62
+
32
63
  ## ๐Ÿ“ฆ What's Included
33
64
 
34
65
  - **Core Library** (`src/swisseph.js`) - Main JavaScript wrapper
@@ -41,6 +72,8 @@ pnpm add swisseph-wasm
41
72
 
42
73
  ## ๐Ÿš€ Quick Start
43
74
 
75
+ > **๐Ÿ‘€ Want to see it in action first?** Try the [Interactive Demo](https://prolaxu.github.io/swisseph-wasm/examples/demo.html)
76
+
44
77
  ### Basic Usage
45
78
 
46
79
  ```javascript
@@ -84,6 +117,218 @@ Object.entries(chart.planets).forEach(([name, planet]) => {
84
117
  calculator.destroy();
85
118
  ```
86
119
 
120
+ ## ๐ŸŒ Cross-Platform Usage
121
+
122
+ SwissEph WebAssembly works seamlessly across different environments. Here are platform-specific setup instructions:
123
+
124
+ ### Node.js
125
+ ```javascript
126
+ import SwissEph from 'swisseph-wasm';
127
+
128
+ async function nodeExample() {
129
+ const swe = new SwissEph();
130
+ await swe.initSwissEph();
131
+
132
+ const jd = swe.julday(2023, 6, 15, 12.0);
133
+ const sunPos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
134
+
135
+ console.log(`Sun longitude: ${sunPos[0].toFixed(2)}ยฐ`);
136
+ swe.close();
137
+ }
138
+
139
+ nodeExample().catch(console.error);
140
+ ```
141
+
142
+ ### Vite (Vue.js, React, etc.)
143
+ Add this configuration to your `vite.config.js`:
144
+
145
+ ```javascript
146
+ import { defineConfig } from 'vite'
147
+ import vue from '@vitejs/plugin-vue' // or react, etc.
148
+
149
+ export default defineConfig({
150
+ plugins: [vue()],
151
+ server: {
152
+ fs: {
153
+ allow: ['..']
154
+ }
155
+ },
156
+ assetsInclude: ['**/*.wasm'],
157
+ optimizeDeps: {
158
+ exclude: ['swisseph-wasm']
159
+ }
160
+ })
161
+ ```
162
+
163
+ ### Vue.js Component
164
+ ```vue
165
+ <script setup>
166
+ import SwissEph from 'swisseph-wasm';
167
+ import { onMounted, onUnmounted, ref } from 'vue';
168
+
169
+ const swe = ref(null);
170
+ const isInitialized = ref(false);
171
+ const result = ref('');
172
+
173
+ onMounted(async () => {
174
+ try {
175
+ swe.value = new SwissEph();
176
+ await swe.value.initSwissEph();
177
+ isInitialized.value = true;
178
+ } catch (error) {
179
+ console.error('Failed to initialize SwissEph:', error);
180
+ }
181
+ });
182
+
183
+ onUnmounted(() => {
184
+ if (swe.value) {
185
+ swe.value.close();
186
+ }
187
+ });
188
+
189
+ const calculate = () => {
190
+ if (!isInitialized.value) return;
191
+
192
+ const jd = swe.value.julday(2023, 6, 15, 12.0);
193
+ const sunPos = swe.value.calc_ut(jd, swe.value.SE_SUN, swe.value.SEFLG_SWIEPH);
194
+ result.value = `Sun: ${sunPos[0].toFixed(2)}ยฐ`;
195
+ };
196
+ </script>
197
+
198
+ <template>
199
+ <div>
200
+ <button @click="calculate" :disabled="!isInitialized">
201
+ Calculate Sun Position
202
+ </button>
203
+ <p>{{ result }}</p>
204
+ </div>
205
+ </template>
206
+ ```
207
+
208
+ ### React Component
209
+ ```jsx
210
+ import React, { useState, useEffect } from 'react';
211
+ import SwissEph from 'swisseph-wasm';
212
+
213
+ function AstrologyCalculator() {
214
+ const [swe, setSwe] = useState(null);
215
+ const [isInitialized, setIsInitialized] = useState(false);
216
+ const [result, setResult] = useState('');
217
+
218
+ useEffect(() => {
219
+ const initSwissEph = async () => {
220
+ try {
221
+ const swissEph = new SwissEph();
222
+ await swissEph.initSwissEph();
223
+ setSwe(swissEph);
224
+ setIsInitialized(true);
225
+ } catch (error) {
226
+ console.error('Failed to initialize SwissEph:', error);
227
+ }
228
+ };
229
+
230
+ initSwissEph();
231
+
232
+ return () => {
233
+ if (swe) {
234
+ swe.close();
235
+ }
236
+ };
237
+ }, []);
238
+
239
+ const calculate = () => {
240
+ if (!isInitialized || !swe) return;
241
+
242
+ const jd = swe.julday(2023, 6, 15, 12.0);
243
+ const sunPos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
244
+ setResult(`Sun: ${sunPos[0].toFixed(2)}ยฐ`);
245
+ };
246
+
247
+ return (
248
+ <div>
249
+ <button onClick={calculate} disabled={!isInitialized}>
250
+ Calculate Sun Position
251
+ </button>
252
+ <p>{result}</p>
253
+ </div>
254
+ );
255
+ }
256
+
257
+ export default AstrologyCalculator;
258
+ ```
259
+
260
+ ### Vanilla HTML + JavaScript
261
+ ```html
262
+ <!DOCTYPE html>
263
+ <html>
264
+ <head>
265
+ <title>SwissEph Example</title>
266
+ </head>
267
+ <body>
268
+ <button id="calculate">Calculate Sun Position</button>
269
+ <div id="result"></div>
270
+
271
+ <script type="module">
272
+ import SwissEph from 'https://cdn.jsdelivr.net/gh/prolaxu/swisseph-wasm@main/src/swisseph.js';
273
+
274
+ let swe = null;
275
+ let isInitialized = false;
276
+
277
+ // Initialize SwissEph
278
+ (async () => {
279
+ try {
280
+ swe = new SwissEph();
281
+ await swe.initSwissEph();
282
+ isInitialized = true;
283
+ console.log('SwissEph initialized successfully');
284
+ } catch (error) {
285
+ console.error('Failed to initialize SwissEph:', error);
286
+ }
287
+ })();
288
+
289
+ // Calculate button handler
290
+ document.getElementById('calculate').addEventListener('click', () => {
291
+ if (!isInitialized || !swe) {
292
+ document.getElementById('result').textContent = 'SwissEph not initialized';
293
+ return;
294
+ }
295
+
296
+ const jd = swe.julday(2023, 6, 15, 12.0);
297
+ const sunPos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
298
+ document.getElementById('result').textContent = `Sun: ${sunPos[0].toFixed(2)}ยฐ`;
299
+ });
300
+
301
+ // Cleanup on page unload
302
+ window.addEventListener('beforeunload', () => {
303
+ if (swe) {
304
+ swe.close();
305
+ }
306
+ });
307
+ </script>
308
+ </body>
309
+ </html>
310
+ ```
311
+
312
+ ### Webpack Configuration
313
+ If using Webpack, add this to your `webpack.config.js`:
314
+
315
+ ```javascript
316
+ module.exports = {
317
+ // ... other config
318
+ experiments: {
319
+ asyncWebAssembly: true,
320
+ },
321
+ module: {
322
+ rules: [
323
+ {
324
+ test: /\.wasm$/,
325
+ type: 'webassembly/async',
326
+ },
327
+ ],
328
+ },
329
+ };
330
+ ```
331
+
87
332
  ## ๐Ÿ“š Documentation
88
333
 
89
334
  | Document | Description |
@@ -178,8 +423,91 @@ swiss-wasm/
178
423
  - ES6 modules support
179
424
  - Async/await support
180
425
 
426
+ ## ๐Ÿ”ง Troubleshooting
427
+
428
+ ### Common Issues and Solutions
429
+
430
+ #### WASM Loading Errors in Vite/Vue.js
431
+ **Error**: `WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 64 6f`
432
+
433
+ **Solution**: Add Vite configuration to your `vite.config.js`:
434
+ ```javascript
435
+ export default defineConfig({
436
+ plugins: [vue()],
437
+ server: {
438
+ fs: { allow: ['..'] }
439
+ },
440
+ assetsInclude: ['**/*.wasm'],
441
+ optimizeDeps: {
442
+ exclude: ['swisseph-wasm']
443
+ }
444
+ })
445
+ ```
446
+
447
+ #### Import Errors in Node.js
448
+ **Error**: `Cannot read properties of undefined (reading 'ccall')`
449
+
450
+ **Solution**: Always call `await swe.initSwissEph()` before using any methods:
451
+ ```javascript
452
+ const swe = new SwissEph();
453
+ await swe.initSwissEph(); // Required!
454
+ const jd = swe.julday(2023, 6, 15, 12.0);
455
+ ```
456
+
457
+ #### Browser Process Errors
458
+ **Error**: `process is not defined` in browser
459
+
460
+ **Solution**: This is fixed in the latest version. Update to the latest version:
461
+ ```bash
462
+ npm update swisseph-wasm
463
+ ```
464
+
465
+ #### Memory Issues
466
+ **Error**: Out of memory or performance issues
467
+
468
+ **Solution**: Always call `swe.close()` when done:
469
+ ```javascript
470
+ try {
471
+ const swe = new SwissEph();
472
+ await swe.initSwissEph();
473
+ // ... your calculations
474
+ } finally {
475
+ swe.close(); // Always clean up!
476
+ }
477
+ ```
478
+
479
+ #### CDN Import Issues
480
+ **Error**: Module not found when using CDN
481
+
482
+ **Solution**: Use the correct CDN URL:
483
+ ```javascript
484
+ // โœ… Correct
485
+ import SwissEph from 'https://cdn.jsdelivr.net/gh/prolaxu/swisseph-wasm@main/src/swisseph.js';
486
+
487
+ // โŒ Incorrect
488
+ import SwissEph from 'https://cdn.jsdelivr.net/npm/swisseph-wasm';
489
+ ```
490
+
491
+ #### TypeScript Errors
492
+ **Error**: Type definitions not found
493
+
494
+ **Solution**: Types are included in the package:
495
+ ```typescript
496
+ import SwissEph from 'swisseph-wasm';
497
+ // Types are automatically available
498
+ ```
499
+
500
+ ### Performance Tips
501
+
502
+ 1. **Reuse instances**: Create one SwissEph instance and reuse it for multiple calculations
503
+ 2. **Batch calculations**: Calculate multiple planets in one session rather than creating new instances
504
+ 3. **Memory management**: Always call `close()` when done
505
+ 4. **Async initialization**: Use `await swe.initSwissEph()` only once per instance
506
+
181
507
  ## ๐Ÿ’ก Examples
182
508
 
509
+ > **๐ŸŒŸ Interactive Examples**: Try all these examples and more in the [Live Demo](https://prolaxu.github.io/swisseph-wasm/examples/demo.html)
510
+
183
511
  ### Current Planetary Positions
184
512
  ```javascript
185
513
  async function getCurrentPositions() {
@@ -300,6 +628,57 @@ This library is a wrapper around the Swiss Ephemeris, which is licensed under th
300
628
  - **Test Suite**: Comprehensive validation
301
629
  - **Documentation**: Complete developer guides
302
630
 
631
+ ## ๐Ÿ“œ License & Important Legal Information
632
+
633
+ ### **๐Ÿ“‹ Project License**
634
+ This project is licensed under **GPL-3.0-or-later** - see the [LICENSE](LICENSE) file for details.
635
+
636
+ ### **โš–๏ธ Swiss Ephemeris Licensing**
637
+
638
+ **IMPORTANT**: This library incorporates the Swiss Ephemeris, which uses a **dual licensing model**:
639
+
640
+ #### **๐Ÿ†“ For Open Source Projects:**
641
+ - โœ… **Free to use** under GNU General Public License (GPL)
642
+ - โœ… Your project must also be **open source** (GPL compatible)
643
+ - โœ… No additional licensing fees required
644
+
645
+ #### **๐Ÿ’ผ For Commercial/Proprietary Projects:**
646
+ - โš ๏ธ **Commercial license required** from Astrodienst AG
647
+ - โš ๏ธ Cannot be used in closed-source applications without commercial license
648
+ - โš ๏ธ Contact Astrodienst AG for pricing and terms
649
+
650
+ ### **๐Ÿ“ž Commercial Licensing Contact**
651
+
652
+ For commercial use of Swiss Ephemeris:
653
+
654
+ **Astrodienst AG**
655
+ ๐Ÿ“ง Email: swisseph@astro.ch
656
+ ๐ŸŒ Website: https://www.astro.com/swisseph/
657
+ ๐Ÿ“ Address: Dammstrasse 23, CH-8702 Zollikon, Switzerland
658
+
659
+ ### **๐Ÿ” License Compliance Guide**
660
+
661
+ | Use Case | License Required | Action Needed |
662
+ |----------|------------------|---------------|
663
+ | ๐Ÿ†“ **Open Source Project** | GPL v3 | โœ… Use freely, keep project open source |
664
+ | ๐Ÿ’ผ **Commercial Product** | Commercial License | โš ๏ธ Contact Astrodienst AG |
665
+ | ๐ŸŽ“ **Educational/Research** | GPL v3 | โœ… Use freely for non-commercial purposes |
666
+ | ๐Ÿข **Internal Business Tools** | Commercial License | โš ๏ธ Contact Astrodienst AG |
667
+
668
+ ### **๐Ÿ“š Additional Resources**
669
+
670
+ - ๐Ÿ“– [Swiss Ephemeris Official Documentation](https://www.astro.com/swisseph/)
671
+ - โš–๏ธ [GPL v3 License Text](https://www.gnu.org/licenses/gpl-3.0.html)
672
+ - ๐Ÿข [Commercial Licensing Information](https://www.astro.com/swisseph/swephinfo_e.htm#_Toc46391649)
673
+
674
+ ### **โš ๏ธ Disclaimer**
675
+
676
+ The author of `swisseph-wasm` is not affiliated with Astrodienst AG and cannot provide commercial licenses for Swiss Ephemeris. This WebAssembly wrapper is provided "as is" under GPL v3. Users are responsible for ensuring compliance with Swiss Ephemeris licensing terms for their specific use case.
677
+
678
+ ## ๐Ÿค Contributing
679
+
680
+ We welcome contributions! Please feel free to submit a Pull Request.
681
+
303
682
  ---
304
683
 
305
684
  **Ready to calculate the cosmos? Start with the [Quick Reference](QUICK_REFERENCE.md) or dive into the [Complete Documentation](DOCUMENTATION.md)!** ๐ŸŒŸ