@motioncomplex/cosmos-lib 1.0.9

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 (47) hide show
  1. package/README.md +125 -0
  2. package/dist/api.d.ts +246 -0
  3. package/dist/cache.d.ts +11 -0
  4. package/dist/clock.d.ts +181 -0
  5. package/dist/constants.d.ts +43 -0
  6. package/dist/data/constellations.d.ts +58 -0
  7. package/dist/data/cutouts.d.ts +70 -0
  8. package/dist/data/deep-sky.d.ts +27 -0
  9. package/dist/data/images.d.ts +147 -0
  10. package/dist/data/index.d.ts +422 -0
  11. package/dist/data/messier.d.ts +61 -0
  12. package/dist/data/ps1-files.d.ts +11 -0
  13. package/dist/data/showers.d.ts +62 -0
  14. package/dist/data/solar-system.d.ts +34 -0
  15. package/dist/data/stars.d.ts +57 -0
  16. package/dist/data/textures.d.ts +67 -0
  17. package/dist/eclipse.d.ts +176 -0
  18. package/dist/index.cjs +1 -0
  19. package/dist/index.d.ts +237 -0
  20. package/dist/index.js +713 -0
  21. package/dist/math.d.ts +532 -0
  22. package/dist/media-DVOcIMa1.js +252 -0
  23. package/dist/media-DlE7RKBL.cjs +1 -0
  24. package/dist/media.d.ts +217 -0
  25. package/dist/moon.d.ts +170 -0
  26. package/dist/planner.d.ts +224 -0
  27. package/dist/react/index.cjs +1 -0
  28. package/dist/react/index.d.ts +167 -0
  29. package/dist/react/index.js +163 -0
  30. package/dist/skymap-hittest.d.ts +69 -0
  31. package/dist/skymap-interactive-CLg6FA0X.js +6377 -0
  32. package/dist/skymap-interactive-D2OZFwJ7.cjs +1 -0
  33. package/dist/skymap-interactive.d.ts +153 -0
  34. package/dist/skymap.d.ts +172 -0
  35. package/dist/sun.d.ts +119 -0
  36. package/dist/three/factories.d.ts +160 -0
  37. package/dist/three/flight.d.ts +116 -0
  38. package/dist/three/index.cjs +20 -0
  39. package/dist/three/index.d.ts +21 -0
  40. package/dist/three/index.js +404 -0
  41. package/dist/three/lod.d.ts +100 -0
  42. package/dist/three/shaders.d.ts +22 -0
  43. package/dist/three/types.d.ts +169 -0
  44. package/dist/transitions.d.ts +246 -0
  45. package/dist/types.d.ts +730 -0
  46. package/dist/units.d.ts +132 -0
  47. package/package.json +93 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Built-in GLSL shader sources used by the Three.js integration layer.
3
+ *
4
+ * Currently contains the atmosphere glow shaders consumed by
5
+ * {@link createAtmosphere}. The shaders implement a Fresnel-based rim-lighting
6
+ * effect rendered on the back face of a slightly oversized sphere with additive
7
+ * blending.
8
+ *
9
+ * **`atmosphereVert`** -- Vertex shader that computes per-vertex view direction
10
+ * and normal vectors in world space.
11
+ *
12
+ * **`atmosphereFrag`** -- Fragment shader with the following uniforms:
13
+ * - `uAtmColor` (`vec3`) -- atmosphere RGB colour.
14
+ * - `uIntensity` (`float`) -- glow intensity multiplier.
15
+ *
16
+ * The fragment alpha is derived from `pow(rim, 3.0) * uIntensity`, where `rim`
17
+ * is `1.0 - abs(dot(normal, viewDir))`.
18
+ */
19
+ export declare const SHADERS: {
20
+ readonly atmosphereVert: "\n varying vec3 vNormal;\n varying vec3 vViewDir;\n void main() {\n vec4 worldPos = modelMatrix * vec4(position, 1.0);\n vViewDir = normalize(cameraPosition - worldPos.xyz);\n vNormal = normalize(normalMatrix * normal);\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ";
21
+ readonly atmosphereFrag: "\n uniform vec3 uAtmColor;\n uniform float uIntensity;\n varying vec3 vNormal;\n varying vec3 vViewDir;\n void main() {\n float rim = 1.0 - abs(dot(vNormal, vViewDir));\n float alpha = pow(rim, 3.0) * uIntensity;\n gl_FragColor = vec4(uAtmColor * alpha, alpha);\n }\n ";
22
+ };
@@ -0,0 +1,169 @@
1
+ import type * as THREE from 'three';
2
+ /**
3
+ * Configuration for {@link createPlanet}.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const opts: PlanetOptions = {
8
+ * radius: 6.5,
9
+ * textureUrl: 'earth-bluemarble-4k.jpg',
10
+ * atmosphere: { color: 0x4488ff, intensity: 1.3 },
11
+ * }
12
+ * ```
13
+ */
14
+ export interface PlanetOptions {
15
+ /** Sphere radius in scene units. */
16
+ radius: number;
17
+ /** Single texture URL for the planet surface. */
18
+ textureUrl?: string;
19
+ /** Fallback chain of texture URLs — takes priority over `textureUrl` if provided. */
20
+ textureUrls?: string[];
21
+ /** URL for a bump/displacement map to add surface relief. */
22
+ bumpUrl?: string;
23
+ /** Base colour as a hex number (e.g. `0x3366aa`). Used when no texture is loaded. */
24
+ color?: number;
25
+ /** Emissive colour (self-illumination), e.g. for a star. */
26
+ emissive?: number;
27
+ /** Emissive intensity multiplier. @defaultValue `1` */
28
+ emissiveIntensity?: number;
29
+ /** Optional atmospheric glow shell rendered around the planet. */
30
+ atmosphere?: {
31
+ /** Atmosphere colour as a hex number. */
32
+ color: number;
33
+ /** Glow intensity. @defaultValue `1` */
34
+ intensity?: number;
35
+ };
36
+ /** Optional planetary ring system (e.g. Saturn). */
37
+ rings?: {
38
+ /** Inner ring radius in scene units. */
39
+ inner: number;
40
+ /** Outer ring radius in scene units. */
41
+ outer: number;
42
+ /** Ring colour as a hex number. */
43
+ color: number;
44
+ /** Ring opacity (0–1). */
45
+ opacity: number;
46
+ /** Axial tilt of the ring plane in degrees. @defaultValue `0` */
47
+ tilt?: number;
48
+ };
49
+ /** When `true`, renders a black-hole accretion-disk effect instead of a standard sphere. */
50
+ isBlackHole?: boolean;
51
+ }
52
+ /**
53
+ * Return value of {@link createPlanet}.
54
+ */
55
+ export interface PlanetResult {
56
+ /** Top-level group containing the planet mesh, atmosphere, and rings. */
57
+ group: THREE.Group;
58
+ /** The planet's surface mesh. */
59
+ mesh: THREE.Mesh;
60
+ /** Dispose all GPU resources (geometries, materials, textures). */
61
+ dispose: () => void;
62
+ }
63
+ /**
64
+ * Configuration for {@link createNebula}.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const opts: NebulaOptions = {
69
+ * radius: 3000,
70
+ * textureUrls: ['orion-nebula-hubble.jpg'],
71
+ * opacity: 0.9,
72
+ * }
73
+ * ```
74
+ */
75
+ export interface NebulaOptions {
76
+ /** Visual radius of the nebula sprite in scene units. */
77
+ radius: number;
78
+ /** Aspect ratio (width / height) of the sprite. @defaultValue `1` */
79
+ aspect?: number;
80
+ /** Fallback chain of texture URLs for the nebula image. */
81
+ textureUrls: string[];
82
+ /** Sprite opacity (0–1). @defaultValue `1` */
83
+ opacity?: number;
84
+ }
85
+ /**
86
+ * Return value of {@link createNebula}.
87
+ */
88
+ export interface NebulaResult {
89
+ /** Top-level group containing the sprite and hit mesh. */
90
+ group: THREE.Group;
91
+ /** The billboard sprite displaying the nebula texture. */
92
+ sprite: THREE.Sprite;
93
+ /** Invisible mesh used for raycasting / click detection. */
94
+ hitMesh: THREE.Mesh;
95
+ /** Dispose all GPU resources (geometries, materials, textures). */
96
+ dispose: () => void;
97
+ }
98
+ /**
99
+ * Configuration for {@link createStarField}.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const stars = createStarField({ count: 5000, maxRadius: 10000 }, THREE)
104
+ * scene.add(stars)
105
+ * ```
106
+ */
107
+ export interface StarFieldOptions {
108
+ /** Number of stars to generate. @defaultValue `2000` */
109
+ count?: number;
110
+ /** Minimum distance from the origin. @defaultValue `500` */
111
+ minRadius?: number;
112
+ /** Maximum distance from the origin. @defaultValue `5000` */
113
+ maxRadius?: number;
114
+ /** Minimum star point size. @defaultValue `0.5` */
115
+ sizeMin?: number;
116
+ /** Maximum star point size. @defaultValue `2` */
117
+ sizeMax?: number;
118
+ /** Point opacity (0–1). @defaultValue `1` */
119
+ opacity?: number;
120
+ }
121
+ /**
122
+ * Configuration for {@link createOrbit}.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const ring = createOrbit({ color: 0x888888, opacity: 0.4 }, THREE)
127
+ * scene.add(ring)
128
+ * ```
129
+ */
130
+ export interface OrbitOptions {
131
+ /** Line colour as a hex number. @defaultValue `0xffffff` */
132
+ color?: number;
133
+ /** Line opacity (0–1). @defaultValue `0.3` */
134
+ opacity?: number;
135
+ /** Number of line segments forming the circle. @defaultValue `128` */
136
+ segments?: number;
137
+ }
138
+ /**
139
+ * Options for {@link CameraFlight.flyTo}.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * flight.flyTo(target, lookAt, { duration: 2000, easing: 'inOut' })
144
+ * ```
145
+ */
146
+ export interface FlightOptions {
147
+ /** Animation duration in milliseconds. @defaultValue `1500` */
148
+ duration?: number;
149
+ /** Easing curve. @defaultValue `'inOut'` */
150
+ easing?: 'in' | 'out' | 'inOut';
151
+ /** Callback invoked when the flight completes. */
152
+ onDone?: () => void;
153
+ }
154
+ /**
155
+ * Options for {@link CameraFlight.orbitAround}.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * flight.orbitAround(planet.group.position, { radius: 20, speed: 0.5 })
160
+ * ```
161
+ */
162
+ export interface OrbitAroundOptions {
163
+ /** Orbit radius in scene units. @defaultValue `10` */
164
+ radius?: number;
165
+ /** Angular speed in radians per second. @defaultValue `0.3` */
166
+ speed?: number;
167
+ /** Camera elevation above the orbit plane in scene units. @defaultValue `0` */
168
+ elevation?: number;
169
+ }
@@ -0,0 +1,246 @@
1
+ import type { MorphOptions, StaggerOptions, HeroExpandOptions } from './types.js';
2
+ /**
3
+ * Wrap a DOM mutation in the View Transitions API.
4
+ *
5
+ * When the browser supports `document.startViewTransition`, the provided
6
+ * callback is executed inside a view transition so the browser can
7
+ * automatically cross-fade old and new DOM states. On unsupported browsers
8
+ * the callback is invoked directly as a no-op fallback.
9
+ *
10
+ * Custom CSS variables `--cosmos-vt-duration` and `--cosmos-vt-easing` are
11
+ * set on the document element so companion stylesheets can pick them up.
12
+ *
13
+ * @param updateFn - A synchronous or asynchronous function that mutates the DOM
14
+ * (e.g. swapping panel content, re-rendering a component).
15
+ * @param opts - Transition options. See {@link MorphOptions} for defaults.
16
+ * @returns A promise that resolves when the view transition finishes (or
17
+ * immediately after `updateFn` on unsupported browsers).
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { morph } from '@motioncomplex/cosmos-lib'
22
+ *
23
+ * // Morph a detail panel from one star to another
24
+ * const controller = new AbortController()
25
+ * await morph(() => {
26
+ * panel.innerHTML = renderStarDetail(nextStar)
27
+ * }, { duration: 350, easing: 'ease-out', signal: controller.signal })
28
+ * ```
29
+ */
30
+ export declare function morph(updateFn: () => void | Promise<void>, opts?: MorphOptions): Promise<void>;
31
+ /**
32
+ * Stagger-reveal all direct children of a container element.
33
+ *
34
+ * Each child fades in and slides from the specified direction with a
35
+ * configurable inter-child delay, producing a cascading entrance effect.
36
+ * Animation is driven by `requestAnimationFrame` for frame-accurate timing
37
+ * and can be cancelled at any time via an `AbortSignal`.
38
+ *
39
+ * @param container - The parent element whose direct children will be animated.
40
+ * @param opts - Stagger options controlling delay, timing, direction, and
41
+ * cancellation. See {@link StaggerOptions} for defaults.
42
+ * @returns A promise that resolves when the last child finishes its entrance
43
+ * animation, or immediately if the container has no children or the
44
+ * signal is already aborted.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { staggerIn } from '@motioncomplex/cosmos-lib'
49
+ *
50
+ * // Stagger-reveal a grid of star cards from the bottom
51
+ * const grid = document.querySelector<HTMLElement>('.star-card-grid')!
52
+ * await staggerIn(grid, {
53
+ * delay: 100,
54
+ * stagger: 60,
55
+ * duration: 500,
56
+ * from: 'bottom',
57
+ * distance: '24px',
58
+ * })
59
+ * ```
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * // Cancel mid-animation with an AbortController
64
+ * const controller = new AbortController()
65
+ * staggerIn(grid, { signal: controller.signal })
66
+ * // later...
67
+ * controller.abort()
68
+ * ```
69
+ */
70
+ export declare function staggerIn(container: HTMLElement, opts?: StaggerOptions): Promise<void>;
71
+ /**
72
+ * Stagger-hide all direct children of a container element.
73
+ *
74
+ * The inverse of {@link staggerIn}: children fade out and slide in the
75
+ * specified direction, animated in **reverse DOM order** (last child first)
76
+ * to create a natural cascading exit. Driven by `requestAnimationFrame`
77
+ * and cancellable via `AbortSignal`.
78
+ *
79
+ * @param container - The parent element whose direct children will be animated out.
80
+ * @param opts - Stagger options controlling timing, direction, and
81
+ * cancellation. See {@link StaggerOptions} for defaults.
82
+ * Note: `delay` is ignored for stagger-out; animation
83
+ * begins immediately.
84
+ * @returns A promise that resolves when the last child finishes its exit
85
+ * animation, or immediately if the container is empty or the signal
86
+ * is already aborted.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { staggerOut } from '@motioncomplex/cosmos-lib'
91
+ *
92
+ * // Stagger-hide a grid of star cards before removing them
93
+ * const grid = document.querySelector<HTMLElement>('.star-card-grid')!
94
+ * await staggerOut(grid, {
95
+ * stagger: 40,
96
+ * duration: 300,
97
+ * from: 'bottom',
98
+ * distance: '12px',
99
+ * })
100
+ * grid.innerHTML = ''
101
+ * ```
102
+ */
103
+ export declare function staggerOut(container: HTMLElement, opts?: StaggerOptions): Promise<void>;
104
+ /**
105
+ * Fade an element in or out.
106
+ *
107
+ * Applies a CSS opacity transition and toggles `pointer-events` accordingly
108
+ * (`'auto'` when fading in, `'none'` when fading out). Resolves when the
109
+ * `transitionend` event fires, with a safety timeout in case the event is
110
+ * swallowed.
111
+ *
112
+ * @param el - The DOM element to fade.
113
+ * @param direction - `'in'` to fade the element to full opacity, `'out'` to
114
+ * fade it to transparent.
115
+ * @param duration - Transition duration in milliseconds. Defaults to `300`.
116
+ * @returns A promise that resolves when the fade completes.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { fade } from '@motioncomplex/cosmos-lib'
121
+ *
122
+ * const tooltip = document.getElementById('star-tooltip')!
123
+ * // Show the tooltip
124
+ * await fade(tooltip, 'in', 200)
125
+ * // Later, hide it
126
+ * await fade(tooltip, 'out', 200)
127
+ * ```
128
+ */
129
+ export declare function fade(el: HTMLElement, direction: 'in' | 'out', duration?: number): Promise<void>;
130
+ /**
131
+ * Crossfade two elements: fades `from` out while fading `to` in simultaneously.
132
+ *
133
+ * Both fade animations run in parallel via {@link fade}. After both complete,
134
+ * the outgoing element is hidden with `display: none` so it no longer occupies
135
+ * layout space.
136
+ *
137
+ * @param from - The currently visible element to fade out.
138
+ * @param to - The incoming element to fade in. Its `display` style is
139
+ * cleared before the fade begins.
140
+ * @param duration - Transition duration in milliseconds for each fade.
141
+ * Defaults to `400`.
142
+ * @returns A promise that resolves when both fades are complete and `from` has
143
+ * been hidden.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { crossfade } from '@motioncomplex/cosmos-lib'
148
+ *
149
+ * const listView = document.getElementById('star-list')!
150
+ * const detailView = document.getElementById('star-detail')!
151
+ *
152
+ * // Swap from list view to detail view
153
+ * await crossfade(listView, detailView, 350)
154
+ * ```
155
+ */
156
+ export declare function crossfade(from: HTMLElement, to: HTMLElement, duration?: number): Promise<void>;
157
+ /**
158
+ * Hero expand -- animates an element from its current bounding rect to fill
159
+ * the viewport using the FLIP (First-Last-Invert-Play) technique.
160
+ *
161
+ * Reads the element's current position, computes the translate/scale needed
162
+ * to cover the full viewport, and animates using a CSS `transform` transition.
163
+ * No GSAP or other animation library is required. Styles are cleaned up
164
+ * automatically when the transition ends (or after a safety timeout).
165
+ *
166
+ * Cancellable via `opts.signal`; if aborted the element stays in its
167
+ * current state.
168
+ *
169
+ * @param element - The DOM element to expand (e.g. a star card thumbnail).
170
+ * @param opts - Animation options. See {@link HeroExpandOptions} for defaults.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * import { heroExpand } from '@motioncomplex/cosmos-lib'
175
+ *
176
+ * const card = document.querySelector<HTMLElement>('.star-card')!
177
+ * heroExpand(card, {
178
+ * duration: 500,
179
+ * easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
180
+ * onDone: () => showFullScreenOverlay(card.dataset.starId!),
181
+ * })
182
+ * ```
183
+ */
184
+ export declare function heroExpand(element: HTMLElement, opts?: HeroExpandOptions): void;
185
+ /**
186
+ * Hero collapse -- animates an overlay element from full-viewport size down
187
+ * into the bounding rect of a target element, producing the reverse of
188
+ * {@link heroExpand}.
189
+ *
190
+ * If no `overlayEl` is supplied, a temporary full-screen `<div>` is created,
191
+ * appended to `document.body`, and automatically removed after the animation
192
+ * completes. When a pre-existing overlay is passed it is **not** removed --
193
+ * only its transform and opacity are animated.
194
+ *
195
+ * Cancellable via `opts.signal`; if aborted, cleanup runs immediately.
196
+ *
197
+ * @param targetElement - The element to collapse into (e.g. the original
198
+ * thumbnail card).
199
+ * @param opts - Animation options. See {@link HeroExpandOptions} for
200
+ * defaults.
201
+ * @param overlayEl - Optional pre-existing overlay element. When omitted a
202
+ * temporary overlay `<div>` is created and removed
203
+ * automatically after animation.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { heroCollapse } from '@motioncomplex/cosmos-lib'
208
+ *
209
+ * const card = document.querySelector<HTMLElement>('.star-card')!
210
+ * const overlay = document.getElementById('fullscreen-overlay')!
211
+ *
212
+ * heroCollapse(card, {
213
+ * duration: 400,
214
+ * onDone: () => overlay.remove(),
215
+ * }, overlay)
216
+ * ```
217
+ */
218
+ export declare function heroCollapse(targetElement: HTMLElement, opts?: HeroExpandOptions, overlayEl?: HTMLElement): void;
219
+ /**
220
+ * Legacy namespace re-exporting all transition functions.
221
+ *
222
+ * @deprecated Use the named exports `morph`, `staggerIn`, `staggerOut`,
223
+ * `fade`, `crossfade`, `heroExpand`, and `heroCollapse` directly instead.
224
+ * This object is retained solely for backwards compatibility and will be
225
+ * removed in a future major release.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * // Before (deprecated)
230
+ * import { Transitions } from '@motioncomplex/cosmos-lib'
231
+ * Transitions.staggerIn(grid)
232
+ *
233
+ * // After (preferred)
234
+ * import { staggerIn } from '@motioncomplex/cosmos-lib'
235
+ * staggerIn(grid)
236
+ * ```
237
+ */
238
+ export declare const Transitions: {
239
+ morph: typeof morph;
240
+ staggerIn: typeof staggerIn;
241
+ staggerOut: typeof staggerOut;
242
+ fade: typeof fade;
243
+ crossfade: typeof crossfade;
244
+ heroExpand: typeof heroExpand;
245
+ heroCollapse: typeof heroCollapse;
246
+ };