siderust-js 0.1.0

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.
Files changed (272) hide show
  1. package/.github/workflows/ci.yml +166 -0
  2. package/.gitmodules +9 -0
  3. package/CHANGELOG.md +26 -0
  4. package/LICENSE +661 -0
  5. package/README.md +138 -0
  6. package/package.json +12 -0
  7. package/qtty-js/.github/workflows/ci.yml +151 -0
  8. package/qtty-js/.gitmodules +3 -0
  9. package/qtty-js/CHANGELOG.md +31 -0
  10. package/qtty-js/LICENSE +661 -0
  11. package/qtty-js/README.md +132 -0
  12. package/qtty-js/package.json +20 -0
  13. package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
  14. package/qtty-js/qtty/CHANGELOG.md +120 -0
  15. package/qtty-js/qtty/Cargo.lock +1462 -0
  16. package/qtty-js/qtty/Cargo.toml +12 -0
  17. package/qtty-js/qtty/LICENSE +661 -0
  18. package/qtty-js/qtty/README.md +9 -0
  19. package/qtty-js/qtty/qtty/Cargo.toml +41 -0
  20. package/qtty-js/qtty/qtty/README.md +8 -0
  21. package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
  22. package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
  23. package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
  24. package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
  25. package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
  26. package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
  27. package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
  28. package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
  29. package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
  30. package/qtty-js/qtty/qtty/src/f32.rs +108 -0
  31. package/qtty-js/qtty/qtty/src/f64.rs +30 -0
  32. package/qtty-js/qtty/qtty/src/i128.rs +111 -0
  33. package/qtty-js/qtty/qtty/src/i16.rs +111 -0
  34. package/qtty-js/qtty/qtty/src/i32.rs +111 -0
  35. package/qtty-js/qtty/qtty/src/i64.rs +111 -0
  36. package/qtty-js/qtty/qtty/src/i8.rs +111 -0
  37. package/qtty-js/qtty/qtty/src/lib.rs +238 -0
  38. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
  39. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
  40. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
  41. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
  42. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
  43. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
  44. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
  45. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
  46. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
  47. package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
  48. package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
  49. package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
  50. package/qtty-js/qtty/qtty-core/README.md +8 -0
  51. package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
  52. package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
  53. package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
  54. package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
  55. package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
  56. package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
  57. package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
  58. package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
  59. package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
  60. package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
  61. package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
  62. package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
  63. package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
  64. package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
  65. package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
  66. package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
  67. package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
  68. package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
  69. package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
  70. package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
  71. package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
  72. package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
  73. package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
  74. package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
  75. package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
  76. package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
  77. package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
  78. package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
  79. package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
  80. package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
  81. package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
  82. package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
  83. package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
  84. package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
  85. package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
  86. package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
  87. package/qtty-js/qtty/qtty-derive/README.md +8 -0
  88. package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
  89. package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
  90. package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
  91. package/qtty-js/qtty/qtty-ffi/README.md +9 -0
  92. package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
  93. package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
  94. package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
  95. package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
  96. package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
  97. package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
  98. package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
  99. package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
  100. package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
  101. package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
  102. package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
  103. package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
  104. package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
  105. package/qtty-js/qtty-node/.prettierignore +6 -0
  106. package/qtty-js/qtty-node/.prettierrc.json +6 -0
  107. package/qtty-js/qtty-node/README.md +250 -0
  108. package/qtty-js/qtty-node/c8.config.json +11 -0
  109. package/qtty-js/qtty-node/eslint.config.js +31 -0
  110. package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
  111. package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
  112. package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
  113. package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
  114. package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
  115. package/qtty-js/qtty-node/index.d.ts +219 -0
  116. package/qtty-js/qtty-node/index.js +323 -0
  117. package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
  118. package/qtty-js/qtty-node/lib/Quantity.js +151 -0
  119. package/qtty-js/qtty-node/lib/backend.js +25 -0
  120. package/qtty-js/qtty-node/native.cjs +306 -0
  121. package/qtty-js/qtty-node/package-lock.json +3223 -0
  122. package/qtty-js/qtty-node/package.json +70 -0
  123. package/qtty-js/qtty-node/units.d.ts +299 -0
  124. package/qtty-js/qtty-node/units.js +210 -0
  125. package/qtty-js/qtty-web/Cargo.lock +767 -0
  126. package/qtty-js/qtty-web/Cargo.toml +21 -0
  127. package/qtty-js/qtty-web/index.d.ts +140 -0
  128. package/qtty-js/qtty-web/index.js +20 -0
  129. package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
  130. package/qtty-js/qtty-web/lib/Quantity.js +75 -0
  131. package/qtty-js/qtty-web/lib/backend.js +80 -0
  132. package/qtty-js/qtty-web/package.json +45 -0
  133. package/qtty-js/qtty-web/src/lib.rs +111 -0
  134. package/qtty-js/scripts/ci.sh +73 -0
  135. package/scripts/ci.sh +123 -0
  136. package/siderust-core/Cargo.lock +787 -0
  137. package/siderust-core/Cargo.toml +18 -0
  138. package/siderust-core/DEDUPLICATION.md +124 -0
  139. package/siderust-core/src/body.rs +120 -0
  140. package/siderust-core/src/events.rs +184 -0
  141. package/siderust-core/src/lib.rs +20 -0
  142. package/siderust-core/src/observer.rs +55 -0
  143. package/siderust-core/src/position.rs +213 -0
  144. package/siderust-node/.prettierignore +7 -0
  145. package/siderust-node/.prettierrc.json +6 -0
  146. package/siderust-node/Cargo.lock +906 -0
  147. package/siderust-node/Cargo.toml +29 -0
  148. package/siderust-node/README.md +109 -0
  149. package/siderust-node/__test__/index.test.mjs +248 -0
  150. package/siderust-node/build.rs +5 -0
  151. package/siderust-node/c8.config.json +3 -0
  152. package/siderust-node/eslint.config.js +31 -0
  153. package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
  154. package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
  155. package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
  156. package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
  157. package/siderust-node/examples/05_target_tracking.mjs +22 -0
  158. package/siderust-node/examples/06_night_events.mjs +18 -0
  159. package/siderust-node/examples/07_moon_properties.mjs +21 -0
  160. package/siderust-node/examples/08_solar_system.mjs +19 -0
  161. package/siderust-node/examples/09_star_observability.mjs +22 -0
  162. package/siderust-node/examples/10_time_periods.mjs +9 -0
  163. package/siderust-node/examples/11_serialization.mjs +31 -0
  164. package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
  165. package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
  166. package/siderust-node/index.d.ts +623 -0
  167. package/siderust-node/index.js +79 -0
  168. package/siderust-node/lib/Observer.js +112 -0
  169. package/siderust-node/lib/Star.js +118 -0
  170. package/siderust-node/lib/backend.js +63 -0
  171. package/siderust-node/lib/wrappers.js +566 -0
  172. package/siderust-node/main.js +20 -0
  173. package/siderust-node/native.cjs +360 -0
  174. package/siderust-node/package-lock.json +3261 -0
  175. package/siderust-node/package.json +71 -0
  176. package/siderust-node/src/body.rs +74 -0
  177. package/siderust-node/src/coordinates.rs +372 -0
  178. package/siderust-node/src/ephemeris.rs +462 -0
  179. package/siderust-node/src/events.rs +577 -0
  180. package/siderust-node/src/lib.rs +43 -0
  181. package/siderust-node/src/observer.rs +132 -0
  182. package/siderust-node/src/phase.rs +218 -0
  183. package/siderust-node/src/position.rs +292 -0
  184. package/siderust-node/src/star.rs +200 -0
  185. package/siderust-web/Cargo.lock +855 -0
  186. package/siderust-web/Cargo.toml +34 -0
  187. package/siderust-web/README.md +100 -0
  188. package/siderust-web/__test__/index.test.mjs +118 -0
  189. package/siderust-web/examples/github-pages/README.md +31 -0
  190. package/siderust-web/examples/github-pages/index.html +135 -0
  191. package/siderust-web/index.d.ts +311 -0
  192. package/siderust-web/index.js +66 -0
  193. package/siderust-web/lib/Observer.js +103 -0
  194. package/siderust-web/lib/Star.js +116 -0
  195. package/siderust-web/lib/backend.js +400 -0
  196. package/siderust-web/lib/wrappers.js +512 -0
  197. package/siderust-web/package.json +55 -0
  198. package/siderust-web/src/body.rs +69 -0
  199. package/siderust-web/src/coordinates.rs +302 -0
  200. package/siderust-web/src/ephemeris.rs +456 -0
  201. package/siderust-web/src/events.rs +520 -0
  202. package/siderust-web/src/lib.rs +51 -0
  203. package/siderust-web/src/observer.rs +117 -0
  204. package/siderust-web/src/phase.rs +190 -0
  205. package/siderust-web/src/position.rs +291 -0
  206. package/siderust-web/src/star.rs +178 -0
  207. package/tempoch-js/.github/workflows/ci.yml +142 -0
  208. package/tempoch-js/.gitmodules +3 -0
  209. package/tempoch-js/CHANGELOG.md +25 -0
  210. package/tempoch-js/LICENSE +661 -0
  211. package/tempoch-js/README.md +126 -0
  212. package/tempoch-js/package.json +20 -0
  213. package/tempoch-js/scripts/ci.sh +73 -0
  214. package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
  215. package/tempoch-js/tempoch/CHANGELOG.md +82 -0
  216. package/tempoch-js/tempoch/Cargo.lock +947 -0
  217. package/tempoch-js/tempoch/Cargo.toml +3 -0
  218. package/tempoch-js/tempoch/LICENSE +661 -0
  219. package/tempoch-js/tempoch/README.md +76 -0
  220. package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
  221. package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
  222. package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
  223. package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
  224. package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
  225. package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
  226. package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
  227. package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
  228. package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
  229. package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
  230. package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
  231. package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
  232. package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
  233. package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
  234. package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
  235. package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
  236. package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
  237. package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
  238. package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
  239. package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
  240. package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
  241. package/tempoch-js/tempoch-node/.prettierignore +6 -0
  242. package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
  243. package/tempoch-js/tempoch-node/Cargo.lock +496 -0
  244. package/tempoch-js/tempoch-node/Cargo.toml +29 -0
  245. package/tempoch-js/tempoch-node/README.md +265 -0
  246. package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
  247. package/tempoch-js/tempoch-node/build.rs +5 -0
  248. package/tempoch-js/tempoch-node/c8.config.json +3 -0
  249. package/tempoch-js/tempoch-node/eslint.config.js +31 -0
  250. package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
  251. package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
  252. package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
  253. package/tempoch-js/tempoch-node/index.d.ts +280 -0
  254. package/tempoch-js/tempoch-node/index.js +32 -0
  255. package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
  256. package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
  257. package/tempoch-js/tempoch-node/lib/Period.js +133 -0
  258. package/tempoch-js/tempoch-node/lib/backend.js +38 -0
  259. package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
  260. package/tempoch-js/tempoch-node/native.cjs +317 -0
  261. package/tempoch-js/tempoch-node/package-lock.json +3223 -0
  262. package/tempoch-js/tempoch-node/package.json +56 -0
  263. package/tempoch-js/tempoch-node/src/lib.rs +573 -0
  264. package/tempoch-js/tempoch-web/Cargo.toml +23 -0
  265. package/tempoch-js/tempoch-web/index.d.ts +95 -0
  266. package/tempoch-js/tempoch-web/index.js +27 -0
  267. package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
  268. package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
  269. package/tempoch-js/tempoch-web/lib/Period.js +121 -0
  270. package/tempoch-js/tempoch-web/lib/backend.js +118 -0
  271. package/tempoch-js/tempoch-web/package.json +46 -0
  272. package/tempoch-js/tempoch-web/src/lib.rs +184 -0
@@ -0,0 +1,512 @@
1
+ /**
2
+ * @siderust/siderust-web — Typed wrapper functions.
3
+ *
4
+ * These wrappers enforce the public JS domain types and map the raw wasm
5
+ * transport values back into `Quantity`, `JulianDate`, `ModifiedJulianDate`,
6
+ * and `Period` objects.
7
+ *
8
+ * @module @siderust/siderust-web/lib/wrappers
9
+ * @private
10
+ */
11
+
12
+ import { Quantity } from '@siderust/qtty-web';
13
+ import { JulianDate, ModifiedJulianDate, Period } from '@siderust/tempoch-web';
14
+ import * as backend from './backend.js';
15
+ import { Observer } from './Observer.js';
16
+ import { Star } from './Star.js';
17
+
18
+ function toNativeObserver(obs) {
19
+ if (!(obs instanceof Observer)) {
20
+ throw new Error('Expected an Observer');
21
+ }
22
+ return backend.NativeObserver(obs._lonDeg, obs._latDeg, obs._heightM);
23
+ }
24
+
25
+ function toNativeStar(star) {
26
+ if (!(star instanceof Star)) {
27
+ throw new Error('Expected a Star');
28
+ }
29
+ return backend.NativeStar(
30
+ star._name,
31
+ star._distanceLy,
32
+ star._massSolar,
33
+ star._radiusSolar,
34
+ star._luminositySolar,
35
+ star._raDeg,
36
+ star._decDeg,
37
+ );
38
+ }
39
+
40
+ function toJdValue(jd) {
41
+ if (!(jd instanceof JulianDate)) {
42
+ throw new Error('Expected a JulianDate');
43
+ }
44
+ return jd.value;
45
+ }
46
+
47
+ function toMjdValue(mjd) {
48
+ if (!(mjd instanceof ModifiedJulianDate)) {
49
+ throw new Error('Expected a ModifiedJulianDate');
50
+ }
51
+ return mjd.value;
52
+ }
53
+
54
+ function toWindow(window) {
55
+ if (!(window instanceof Period)) {
56
+ throw new Error('Expected a Period');
57
+ }
58
+ return {
59
+ start: window.start.value,
60
+ end: window.end.value,
61
+ };
62
+ }
63
+
64
+ function toQuantity(value, unit, label) {
65
+ if (!(value instanceof Quantity)) {
66
+ throw new Error(`${label}: expected a Quantity`);
67
+ }
68
+ return value.to(unit);
69
+ }
70
+
71
+ function toScalar(value, unit, label) {
72
+ return toQuantity(value, unit, label).value;
73
+ }
74
+
75
+ function toAngleValue(value, label) {
76
+ return toScalar(value, 'Degree', label);
77
+ }
78
+
79
+ function toLengthTriple(x, y, z, label) {
80
+ const xQuantity = toQuantity(x, x && x.unit ? x.unit : 'Meter', `${label}.x`);
81
+ return {
82
+ unit: xQuantity.unit,
83
+ x: xQuantity.value,
84
+ y: toQuantity(y, xQuantity.unit, `${label}.y`).value,
85
+ z: toQuantity(z, xQuantity.unit, `${label}.z`).value,
86
+ };
87
+ }
88
+
89
+ function mapPlanetInfo(raw) {
90
+ return {
91
+ name: raw.name,
92
+ mass: new Quantity(raw.massKg, 'Kilogram'),
93
+ radius: new Quantity(raw.radiusKm, 'Kilometer'),
94
+ semiMajorAxis: new Quantity(raw.semiMajorAxisAu, 'AstronomicalUnit'),
95
+ eccentricity: raw.eccentricity,
96
+ inclination: new Quantity(raw.inclinationDeg, 'Degree'),
97
+ };
98
+ }
99
+
100
+ function mapDirection(raw) {
101
+ return {
102
+ polar: new Quantity(raw.polarDeg, 'Degree'),
103
+ azimuth: new Quantity(raw.azimuthDeg, 'Degree'),
104
+ frame: raw.frame,
105
+ };
106
+ }
107
+
108
+ function mapCartesianEcef(raw) {
109
+ return {
110
+ x: new Quantity(raw.x, 'Meter'),
111
+ y: new Quantity(raw.y, 'Meter'),
112
+ z: new Quantity(raw.z, 'Meter'),
113
+ };
114
+ }
115
+
116
+ function mapCartesianPosition(raw, unit) {
117
+ return {
118
+ x: new Quantity(raw.x, unit),
119
+ y: new Quantity(raw.y, unit),
120
+ z: new Quantity(raw.z, unit),
121
+ frame: raw.frame,
122
+ center: raw.center,
123
+ };
124
+ }
125
+
126
+ function mapCrossingEvent(raw) {
127
+ return {
128
+ mjd: new ModifiedJulianDate(raw.mjd),
129
+ direction: raw.direction,
130
+ };
131
+ }
132
+
133
+ function mapCulminationEvent(raw) {
134
+ return {
135
+ mjd: new ModifiedJulianDate(raw.mjd),
136
+ altitude: new Quantity(raw.altitudeDeg, 'Degree'),
137
+ kind: raw.kind,
138
+ };
139
+ }
140
+
141
+ function mapAzimuthExtremum(raw) {
142
+ return {
143
+ mjd: new ModifiedJulianDate(raw.mjd),
144
+ azimuth: new Quantity(raw.azimuthDeg, 'Degree'),
145
+ kind: raw.kind,
146
+ };
147
+ }
148
+
149
+ function mapPeriod(raw) {
150
+ return new Period(
151
+ new ModifiedJulianDate(raw.startMjd),
152
+ new ModifiedJulianDate(raw.endMjd),
153
+ );
154
+ }
155
+
156
+ function mapPhase(raw) {
157
+ return {
158
+ phaseAngle: new Quantity(raw.phaseAngleDeg, 'Degree'),
159
+ illuminatedFraction: raw.illuminatedFraction,
160
+ elongation: new Quantity(raw.elongationDeg, 'Degree'),
161
+ waxing: raw.waxing,
162
+ label: raw.label,
163
+ };
164
+ }
165
+
166
+ function mapPhaseEvent(raw) {
167
+ return {
168
+ mjd: new ModifiedJulianDate(raw.mjd),
169
+ kind: raw.kind,
170
+ };
171
+ }
172
+
173
+ function mapPeriods(periods) {
174
+ return periods.map(mapPeriod);
175
+ }
176
+
177
+ function mapCrossings(events) {
178
+ return events.map(mapCrossingEvent);
179
+ }
180
+
181
+ function mapCulminations(events) {
182
+ return events.map(mapCulminationEvent);
183
+ }
184
+
185
+ function mapAzimuthExtrema(events) {
186
+ return events.map(mapAzimuthExtremum);
187
+ }
188
+
189
+ export function transformDirection(polar, azimuth, srcFrame, dstFrame, jd) {
190
+ return mapDirection(
191
+ backend.transformDirection(
192
+ toAngleValue(polar, 'polar'),
193
+ toAngleValue(azimuth, 'azimuth'),
194
+ srcFrame,
195
+ dstFrame,
196
+ toJdValue(jd),
197
+ ),
198
+ );
199
+ }
200
+
201
+ export function directionToHorizontal(polar, azimuth, srcFrame, jd, observer) {
202
+ return mapDirection(
203
+ backend.directionToHorizontal(
204
+ toAngleValue(polar, 'polar'),
205
+ toAngleValue(azimuth, 'azimuth'),
206
+ srcFrame,
207
+ toJdValue(jd),
208
+ toNativeObserver(observer),
209
+ ),
210
+ );
211
+ }
212
+
213
+ export function geodeticToEcef(observer) {
214
+ return mapCartesianEcef(backend.geodeticToEcef(toNativeObserver(observer)));
215
+ }
216
+
217
+ export function angularSeparation(polar1, azimuth1, polar2, azimuth2, frame) {
218
+ return new Quantity(
219
+ backend.angularSeparation(
220
+ toAngleValue(polar1, 'polar1'),
221
+ toAngleValue(azimuth1, 'azimuth1'),
222
+ toAngleValue(polar2, 'polar2'),
223
+ toAngleValue(azimuth2, 'azimuth2'),
224
+ frame,
225
+ ),
226
+ 'Degree',
227
+ );
228
+ }
229
+
230
+ export function cartesianDistance(x1, y1, z1, x2, y2, z2) {
231
+ const lhs = toLengthTriple(x1, y1, z1, 'point1');
232
+ const rhs = {
233
+ x: toQuantity(x2, lhs.unit, 'point2.x').value,
234
+ y: toQuantity(y2, lhs.unit, 'point2.y').value,
235
+ z: toQuantity(z2, lhs.unit, 'point2.z').value,
236
+ };
237
+ return new Quantity(
238
+ backend.cartesianDistance(lhs.x, lhs.y, lhs.z, rhs.x, rhs.y, rhs.z),
239
+ lhs.unit,
240
+ );
241
+ }
242
+
243
+ export function cartesianMagnitude(x, y, z) {
244
+ const vector = toLengthTriple(x, y, z, 'vector');
245
+ return new Quantity(
246
+ backend.cartesianMagnitude(vector.x, vector.y, vector.z),
247
+ vector.unit,
248
+ );
249
+ }
250
+
251
+ export function dotProduct(x1, y1, z1, x2, y2, z2) {
252
+ return backend.dotProduct(x1, y1, z1, x2, y2, z2);
253
+ }
254
+
255
+ export function directionToCartesian(polar, azimuth) {
256
+ return backend.directionToCartesian(
257
+ toAngleValue(polar, 'polar'),
258
+ toAngleValue(azimuth, 'azimuth'),
259
+ );
260
+ }
261
+
262
+ export function vsop87Heliocentric(body, jd) {
263
+ return mapCartesianPosition(backend.vsop87Heliocentric(body, toJdValue(jd)), 'AstronomicalUnit');
264
+ }
265
+
266
+ export function vsop87Barycentric(body, jd) {
267
+ return mapCartesianPosition(backend.vsop87Barycentric(body, toJdValue(jd)), 'AstronomicalUnit');
268
+ }
269
+
270
+ export function vsop87SunBarycentric(jd) {
271
+ return mapCartesianPosition(backend.vsop87SunBarycentric(toJdValue(jd)), 'AstronomicalUnit');
272
+ }
273
+
274
+ export function vsop87EarthBarycentric(jd) {
275
+ return mapCartesianPosition(backend.vsop87EarthBarycentric(toJdValue(jd)), 'AstronomicalUnit');
276
+ }
277
+
278
+ export function vsop87EarthHeliocentric(jd) {
279
+ return mapCartesianPosition(backend.vsop87EarthHeliocentric(toJdValue(jd)), 'AstronomicalUnit');
280
+ }
281
+
282
+ export function vsop87MoonGeocentric(jd) {
283
+ return mapCartesianPosition(backend.vsop87MoonGeocentric(toJdValue(jd)), 'Kilometer');
284
+ }
285
+
286
+ export function transformPositionCenter(x, y, z, srcCenter, dstCenter, jd) {
287
+ const coords = toLengthTriple(x, y, z, 'position');
288
+ return mapCartesianPosition(
289
+ backend.transformPositionCenter(coords.x, coords.y, coords.z, srcCenter, dstCenter, toJdValue(jd)),
290
+ coords.unit,
291
+ );
292
+ }
293
+
294
+ export function transformPositionFrame(x, y, z, srcFrame, dstFrame, jd) {
295
+ const coords = toLengthTriple(x, y, z, 'position');
296
+ return mapCartesianPosition(
297
+ backend.transformPositionFrame(coords.x, coords.y, coords.z, srcFrame, dstFrame, toJdValue(jd)),
298
+ coords.unit,
299
+ );
300
+ }
301
+
302
+ export function orbitalPeriod(name) {
303
+ return new Quantity(backend.orbitalPeriodDays(name), 'Day');
304
+ }
305
+
306
+ export function bodyAltitudeAt(body, observer, mjd) {
307
+ return new Quantity(
308
+ backend.bodyAltitudeAt(body, toNativeObserver(observer), toMjdValue(mjd)),
309
+ 'Degree',
310
+ );
311
+ }
312
+
313
+ export function bodyAzimuthAt(body, observer, mjd) {
314
+ return new Quantity(
315
+ backend.bodyAzimuthAt(body, toNativeObserver(observer), toMjdValue(mjd)),
316
+ 'Degree',
317
+ );
318
+ }
319
+
320
+ export function bodyCrossings(body, observer, window, threshold) {
321
+ const range = toWindow(window);
322
+ return mapCrossings(
323
+ backend.bodyCrossings(
324
+ body,
325
+ toNativeObserver(observer),
326
+ range.start,
327
+ range.end,
328
+ toAngleValue(threshold, 'threshold'),
329
+ ),
330
+ );
331
+ }
332
+
333
+ export function bodyCulminations(body, observer, window) {
334
+ const range = toWindow(window);
335
+ return mapCulminations(
336
+ backend.bodyCulminations(body, toNativeObserver(observer), range.start, range.end),
337
+ );
338
+ }
339
+
340
+ export function bodyAboveThreshold(body, observer, window, threshold) {
341
+ const range = toWindow(window);
342
+ return mapPeriods(
343
+ backend.bodyAboveThreshold(
344
+ body,
345
+ toNativeObserver(observer),
346
+ range.start,
347
+ range.end,
348
+ toAngleValue(threshold, 'threshold'),
349
+ ),
350
+ );
351
+ }
352
+
353
+ export function bodyBelowThreshold(body, observer, window, threshold) {
354
+ const range = toWindow(window);
355
+ return mapPeriods(
356
+ backend.bodyBelowThreshold(
357
+ body,
358
+ toNativeObserver(observer),
359
+ range.start,
360
+ range.end,
361
+ toAngleValue(threshold, 'threshold'),
362
+ ),
363
+ );
364
+ }
365
+
366
+ export function bodyAzimuthCrossings(body, observer, window, bearing) {
367
+ const range = toWindow(window);
368
+ return mapCrossings(
369
+ backend.bodyAzimuthCrossings(
370
+ body,
371
+ toNativeObserver(observer),
372
+ range.start,
373
+ range.end,
374
+ toAngleValue(bearing, 'bearing'),
375
+ ),
376
+ );
377
+ }
378
+
379
+ export function bodyAzimuthExtrema(body, observer, window) {
380
+ const range = toWindow(window);
381
+ return mapAzimuthExtrema(
382
+ backend.bodyAzimuthExtrema(body, toNativeObserver(observer), range.start, range.end),
383
+ );
384
+ }
385
+
386
+ export function starAltitudeAt(star, observer, mjd) {
387
+ return new Quantity(
388
+ backend.starAltitudeAt(toNativeStar(star), toNativeObserver(observer), toMjdValue(mjd)),
389
+ 'Degree',
390
+ );
391
+ }
392
+
393
+ export function starAzimuthAt(star, observer, mjd) {
394
+ return new Quantity(
395
+ backend.starAzimuthAt(toNativeStar(star), toNativeObserver(observer), toMjdValue(mjd)),
396
+ 'Degree',
397
+ );
398
+ }
399
+
400
+ export function starCrossings(star, observer, window, threshold) {
401
+ const range = toWindow(window);
402
+ return mapCrossings(
403
+ backend.starCrossings(
404
+ toNativeStar(star),
405
+ toNativeObserver(observer),
406
+ range.start,
407
+ range.end,
408
+ toAngleValue(threshold, 'threshold'),
409
+ ),
410
+ );
411
+ }
412
+
413
+ export function starCulminations(star, observer, window) {
414
+ const range = toWindow(window);
415
+ return mapCulminations(
416
+ backend.starCulminations(toNativeStar(star), toNativeObserver(observer), range.start, range.end),
417
+ );
418
+ }
419
+
420
+ export function starAboveThreshold(star, observer, window, threshold) {
421
+ const range = toWindow(window);
422
+ return mapPeriods(
423
+ backend.starAboveThreshold(
424
+ toNativeStar(star),
425
+ toNativeObserver(observer),
426
+ range.start,
427
+ range.end,
428
+ toAngleValue(threshold, 'threshold'),
429
+ ),
430
+ );
431
+ }
432
+
433
+ export function starBelowThreshold(star, observer, window, threshold) {
434
+ const range = toWindow(window);
435
+ return mapPeriods(
436
+ backend.starBelowThreshold(
437
+ toNativeStar(star),
438
+ toNativeObserver(observer),
439
+ range.start,
440
+ range.end,
441
+ toAngleValue(threshold, 'threshold'),
442
+ ),
443
+ );
444
+ }
445
+
446
+ export function starAzimuthCrossings(star, observer, window, bearing) {
447
+ const range = toWindow(window);
448
+ return mapCrossings(
449
+ backend.starAzimuthCrossings(
450
+ toNativeStar(star),
451
+ toNativeObserver(observer),
452
+ range.start,
453
+ range.end,
454
+ toAngleValue(bearing, 'bearing'),
455
+ ),
456
+ );
457
+ }
458
+
459
+ export function starAzimuthExtrema(star, observer, window) {
460
+ const range = toWindow(window);
461
+ return mapAzimuthExtrema(
462
+ backend.starAzimuthExtrema(toNativeStar(star), toNativeObserver(observer), range.start, range.end),
463
+ );
464
+ }
465
+
466
+ export function intersectPeriods(periods1, periods2) {
467
+ const rawPeriods1 = periods1.map((period) => {
468
+ const range = toWindow(period);
469
+ return { startMjd: range.start, endMjd: range.end };
470
+ });
471
+ const rawPeriods2 = periods2.map((period) => {
472
+ const range = toWindow(period);
473
+ return { startMjd: range.start, endMjd: range.end };
474
+ });
475
+ return mapPeriods(backend.intersectPeriods(rawPeriods1, rawPeriods2));
476
+ }
477
+
478
+ export function moonPhase(jd) {
479
+ return mapPhase(backend.moonPhase(toJdValue(jd)));
480
+ }
481
+
482
+ export function moonPhaseTopocentric(jd, observer) {
483
+ return mapPhase(backend.moonPhaseTopocentric(toJdValue(jd), toNativeObserver(observer)));
484
+ }
485
+
486
+ export function findPhaseEvents(window) {
487
+ const range = toWindow(window);
488
+ return backend.findPhaseEvents(range.start, range.end).map(mapPhaseEvent);
489
+ }
490
+
491
+ export function moonIlluminationAbove(window, kMin) {
492
+ const range = toWindow(window);
493
+ return mapPeriods(backend.moonIlluminationAbove(range.start, range.end, kMin));
494
+ }
495
+
496
+ export function moonIlluminationBelow(window, kMax) {
497
+ const range = toWindow(window);
498
+ return mapPeriods(backend.moonIlluminationBelow(range.start, range.end, kMax));
499
+ }
500
+
501
+ export function moonIlluminationRange(window, kMin, kMax) {
502
+ const range = toWindow(window);
503
+ return mapPeriods(backend.moonIlluminationRange(range.start, range.end, kMin, kMax));
504
+ }
505
+
506
+ export function getPlanet(name) {
507
+ return mapPlanetInfo(backend.getPlanet(name));
508
+ }
509
+
510
+ export const listBodies = backend.listBodies;
511
+ export const listCatalogStars = backend.listCatalogStars;
512
+ export const version = backend.version;
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@siderust/siderust-web",
3
+ "version": "1.0.0",
4
+ "description": "High-precision astronomy for the browser — observer setup, celestial body tracking, altitude/azimuth events, coordinate transforms, ephemerides, and lunar phases. Powered by Rust + WebAssembly.",
5
+ "type": "module",
6
+ "module": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "wasm-pack build --target web --out-dir pkg --release --scope siderust",
16
+ "build:dev": "wasm-pack build --target web --out-dir pkg --dev --scope siderust",
17
+ "build:bundler": "wasm-pack build --target bundler --out-dir pkg --release --scope siderust",
18
+ "test": "node --test __test__/*.test.mjs",
19
+ "clean": "rm -rf pkg/"
20
+ },
21
+ "files": [
22
+ "index.js",
23
+ "index.d.ts",
24
+ "lib/",
25
+ "pkg/siderust_web_bg.wasm",
26
+ "pkg/siderust_web.js",
27
+ "pkg/siderust_web.d.ts",
28
+ "README.md",
29
+ "examples/"
30
+ ],
31
+ "keywords": [
32
+ "astronomy",
33
+ "astrometry",
34
+ "ephemeris",
35
+ "coordinates",
36
+ "altitude",
37
+ "azimuth",
38
+ "solar-system",
39
+ "moon-phase",
40
+ "vsop87",
41
+ "wasm",
42
+ "webassembly",
43
+ "browser",
44
+ "rust"
45
+ ],
46
+ "dependencies": {
47
+ "@siderust/qtty-web": "^0.1.0",
48
+ "@siderust/tempoch-web": "^0.1.0"
49
+ },
50
+ "license": "AGPL-3.0",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/Siderust/siderust"
54
+ }
55
+ }
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (C) 2026 Vallés Puig, Ramon
3
+
4
+ //! Solar-system body identifiers and planet data.
5
+
6
+ use serde::Serialize;
7
+ use wasm_bindgen::prelude::*;
8
+
9
+ // Re-export shared types from the binding core.
10
+ pub(crate) use siderust_binding_core::body::BodyKind;
11
+ pub(crate) use siderust_binding_core::dispatch_body;
12
+
13
+ /// Convert a body name string to BodyKind, mapping errors to JsError.
14
+ pub(crate) fn parse_body(s: &str) -> Result<BodyKind, JsError> {
15
+ BodyKind::from_str(s).map_err(|e| JsError::new(&e))
16
+ }
17
+
18
+ // ─────────────────────────────────────────────────────────────────────────────
19
+ // Planet info
20
+ // ─────────────────────────────────────────────────────────────────────────────
21
+
22
+ #[derive(Serialize)]
23
+ #[serde(rename_all = "camelCase")]
24
+ pub struct PlanetInfo {
25
+ pub name: String,
26
+ pub mass_kg: f64,
27
+ pub radius_km: f64,
28
+ pub semi_major_axis_au: f64,
29
+ pub eccentricity: f64,
30
+ pub inclination_deg: f64,
31
+ }
32
+
33
+ impl From<siderust_binding_core::body::PlanetInfo> for PlanetInfo {
34
+ fn from(p: siderust_binding_core::body::PlanetInfo) -> Self {
35
+ Self {
36
+ name: p.name,
37
+ mass_kg: p.mass_kg,
38
+ radius_km: p.radius_km,
39
+ semi_major_axis_au: p.semi_major_axis_au,
40
+ eccentricity: p.eccentricity,
41
+ inclination_deg: p.inclination_deg,
42
+ }
43
+ }
44
+ }
45
+
46
+ /// Get physical parameters for a named planet.
47
+ #[wasm_bindgen(js_name = "getPlanet")]
48
+ pub fn get_planet(name: &str) -> Result<JsValue, JsError> {
49
+ let info: PlanetInfo = siderust_binding_core::body::get_planet_info(name)
50
+ .map(PlanetInfo::from)
51
+ .ok_or_else(|| JsError::new(&format!(
52
+ "Unknown planet: \"{name}\". Valid: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune."
53
+ )))?;
54
+ to_js(&info)
55
+ }
56
+
57
+ /// List the names of all available solar-system bodies.
58
+ #[wasm_bindgen(js_name = "listBodies")]
59
+ pub fn list_bodies() -> JsValue {
60
+ serde_wasm_bindgen::to_value(BodyKind::all_names()).unwrap()
61
+ }
62
+
63
+ // ─────────────────────────────────────────────────────────────────────────────
64
+ // Helpers
65
+ // ─────────────────────────────────────────────────────────────────────────────
66
+
67
+ pub(crate) fn to_js<T: Serialize>(val: &T) -> Result<JsValue, JsError> {
68
+ serde_wasm_bindgen::to_value(val).map_err(|e| JsError::new(&e.to_string()))
69
+ }