@johnmorrisdotca/wakusei-planets 0.22.0 → 0.24.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.
@@ -1,3 +1,4 @@
1
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import { BODIES, MOONS_OF } from "../facts.js";
2
3
  import { createGate, frameCap } from "../gate.js";
3
4
  import { createPainter } from "../scene/painter.js";
@@ -28,6 +29,11 @@ const readBody = (value) => {
28
29
  const id = value.toLowerCase();
29
30
  return SPACE_BODIES.includes(id) ? id : undefined;
30
31
  };
32
+ /**
33
+ * The zoom range of the space view when it carries its own controls. The floor, a millionth, takes the camera out past Neptune in the true scale. The ceiling is where the camera reaches the body: it is held at
34
+ * 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.2 nothing moves; 3 shows the surface as sharp as the painted maps (2048 pixels round) and the shader allow.
35
+ */
36
+ const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3, tiltMax: 90 };
31
37
  const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}</style><div id="stage"></div><div id="labels"></div>`;
32
38
  /**
33
39
  * The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
@@ -35,6 +41,9 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
35
41
  * `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base` and `max-texture`. Positions come from this package's own models. It draws
36
42
  * only when something changes, and nothing while it is out of sight.
37
43
  *
44
+ * It carries the shared view controls itself: a drag turns the camera round the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page), and the arrow keys, + and - and 0 work once it is
45
+ * focused. `controls="none"` turns them off; `zoom-min` and `zoom-max` set the range (a millionth to 3 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
46
+ *
38
47
  * @example
39
48
  * ```ts no-run
40
49
  * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
@@ -65,6 +74,11 @@ export class WakuseiSpace extends HTMLElement {
65
74
  #painter;
66
75
  #focusBeforeRide = "earth";
67
76
  #lostTold = false;
77
+ #hands;
78
+ /** The shared controller behind the element's own hands: for a page that moves the view itself, such as `controller.set({ zoom: space.zoomFor("moon") })`. It is there while the element is connected, whether `controls` is `none` or not. */
79
+ get controller() {
80
+ return this.#hands?.controller;
81
+ }
68
82
  connectedCallback() {
69
83
  this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
70
84
  this.#mode = readTime(this.getAttribute("time"));
@@ -116,10 +130,13 @@ export class WakuseiSpace extends HTMLElement {
116
130
  this.#last = performance.now();
117
131
  this.#schedule();
118
132
  this.addEventListener("pointerdown", this.#down);
133
+ this.#hands = carryControls(this, { limits: CARRIED_LIMITS, initial: { drag: "turn" }, onChange: (view, info) => this.setView(view, info.final) });
119
134
  this.#labelBox.addEventListener("click", this.#labelClick);
120
135
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
121
136
  }
122
137
  disconnectedCallback() {
138
+ this.#hands?.unbind();
139
+ this.#hands = undefined;
123
140
  this.removeEventListener("pointerdown", this.#down);
124
141
  window.removeEventListener("pointerup", this.#up, true);
125
142
  clearTimeout(this.#timer);
@@ -235,6 +252,7 @@ export class WakuseiSpace extends HTMLElement {
235
252
  if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom)
236
253
  return;
237
254
  this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom };
255
+ this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom } }));
238
256
  const drawn = this.#model.drawnView;
239
257
  if (drawn && !final && view.zoom === drawn.zoom) {
240
258
  const turned = Math.max(Math.abs(view.yaw - drawn.yaw), Math.abs(view.tilt - drawn.tilt)) * RAD;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.22.0";
1
+ export declare const VERSION = "0.24.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.22.0";
1
+ export const VERSION = "0.24.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -46,6 +46,7 @@
46
46
  "leap-seconds",
47
47
  "sidereal-time",
48
48
  "spaceprogramx",
49
+ "space-program-x",
49
50
  "spx",
50
51
  "suncalc",
51
52
  "sunrise",
@@ -69,7 +70,10 @@
69
70
  "coordinates",
70
71
  "spacecraft",
71
72
  "voyager",
72
- "trajectory"
73
+ "trajectory",
74
+ "conjunction",
75
+ "close-approach",
76
+ "nearest"
73
77
  ],
74
78
  "homepage": "https://johnmorrisdotca.github.io/wakusei-planets/",
75
79
  "repository": {
@@ -135,6 +139,11 @@
135
139
  "import": "./dist/stars.js",
136
140
  "default": "./dist/stars.js"
137
141
  },
142
+ "./nearest": {
143
+ "types": "./dist/nearest.d.ts",
144
+ "import": "./dist/nearest.js",
145
+ "default": "./dist/nearest.js"
146
+ },
138
147
  "./spacecraft": {
139
148
  "types": "./dist/spacecraft.d.ts",
140
149
  "import": "./dist/spacecraft.js",
@@ -370,7 +379,7 @@
370
379
  },
371
380
  "packageManager": "pnpm@10.28.0",
372
381
  "dependencies": {
373
- "@johnmorrisdotca/kazoku-ui": "^0.20.0"
382
+ "@johnmorrisdotca/kazoku-ui": "^0.21.1"
374
383
  },
375
384
  "peerDependencies": {
376
385
  "@johnmorrisdotca/chikyu-earth": ">=0.10.0",