@johnmorrisdotca/chikyu-earth 0.29.0 → 0.31.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.
@@ -0,0 +1,182 @@
1
+ import { parseManifest, tileColumns, tileRows } from "../realistic/tiles.js";
2
+ import { OWN_BY_ID, madeHere } from "./own.js";
3
+ const RAD = Math.PI / 180;
4
+ const TAU = Math.PI * 2;
5
+ /** A tile's own edge is not the next tile: places are measured to a billionth of a tile. */
6
+ const EDGE = 1e-9;
7
+ /**
8
+ * The levels a source has when it does not say: levels 3 and 4 (8192 and 16384 pixels across), the two the package's cutter makes beyond its own 4096 pixel picture.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { DEFAULT_LEVELS } from "@johnmorrisdotca/chikyu-earth/door";
13
+ *
14
+ * console.log(DEFAULT_LEVELS.levels.map((level) => level.width));
15
+ * ```
16
+ */
17
+ export const DEFAULT_LEVELS = Object.freeze({ tileSize: 512, levels: Object.freeze([3, 4].map((level) => ({ level, width: 1024 * 2 ** level }))) });
18
+ const KEY_END = /(\d+)\/(\d+)\/(\d+)$/;
19
+ /**
20
+ * The level, column and row a tile key ends in, or `undefined` for a key that does not end in three numbers.
21
+ *
22
+ * @param key - The tile's key.
23
+ * @returns Where the tile is in the pyramid, or `undefined` for a key that does not end in three numbers.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { tileKeyParts } from "@johnmorrisdotca/chikyu-earth/door";
28
+ *
29
+ * console.log(tileKeyParts("day/3/12/5"));
30
+ * ```
31
+ */
32
+ export function tileKeyParts(key) {
33
+ const found = KEY_END.exec(key);
34
+ return found === null ? undefined : { level: Number(found[1]), col: Number(found[2]), row: Number(found[3]) };
35
+ }
36
+ /**
37
+ * The place a tile covers, in degrees: what a view asks a source about to get that tile's key.
38
+ *
39
+ * @param tile - A tile of the pyramid.
40
+ * @returns The tile's longitude and latitude bounds.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { tilePlace } from "@johnmorrisdotca/chikyu-earth/door";
45
+ *
46
+ * console.log(tilePlace({ level: 3, col: 0, row: 0 }));
47
+ * ```
48
+ */
49
+ export function tilePlace(tile) {
50
+ const columns = tileColumns(tile.level);
51
+ const rows = tileRows(tile.level);
52
+ return { lonMin: -180 + (360 * tile.col) / columns, lonMax: -180 + (360 * (tile.col + 1)) / columns, latMax: 90 - (180 * tile.row) / rows, latMin: 90 - (180 * (tile.row + 1)) / rows };
53
+ }
54
+ /**
55
+ * The keys of the tiles that cover a place at a detail, on the package's pyramid: the level is the lowest whose width is at least `detail` pixels round (or the finest there is), and the tiles are every one the place touches.
56
+ * Pure. A source of your own can build its `need` on it.
57
+ *
58
+ * @param place - The part of the map, in degrees.
59
+ * @param detail - The pixels across the whole circumference wanted.
60
+ * @param layer - The levels the source has; `DEFAULT_LEVELS` where left out.
61
+ * @param prefix - Put before each key (`"day/"`), for a folder of several layers.
62
+ * @returns The keys, `[<prefix>]level/column/row`, row by row; none for a place with no area.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { mapKeys } from "@johnmorrisdotca/chikyu-earth/door";
67
+ *
68
+ * console.log(mapKeys({ lonMin: -10, lonMax: 10, latMin: -5, latMax: 5 }, 8192));
69
+ * ```
70
+ */
71
+ export function mapKeys(place, detail, layer = DEFAULT_LEVELS, prefix = "") {
72
+ if (layer.levels.length === 0 || !(place.lonMax > place.lonMin) || !(place.latMax >= place.latMin))
73
+ return [];
74
+ const level = layer.levels.find((one) => one.width >= detail) ?? layer.levels[layer.levels.length - 1];
75
+ const columns = tileColumns(level.level);
76
+ const rows = tileRows(level.level);
77
+ const span = Math.min(TAU, (place.lonMax - place.lonMin) * RAD);
78
+ const first = Math.floor(((place.lonMin * RAD) / TAU + 0.5) * columns + EDGE);
79
+ const count = span >= TAU - 1e-9 ? columns : Math.min(columns, Math.ceil(((place.lonMin * RAD + span) / TAU + 0.5) * columns - EDGE) - first);
80
+ const row0 = Math.max(0, Math.floor((0.5 - (place.latMax * RAD) / Math.PI) * rows + EDGE));
81
+ const row1 = Math.min(rows, Math.max(row0 + 1, Math.ceil((0.5 - (place.latMin * RAD) / Math.PI) * rows - EDGE)));
82
+ const keys = [];
83
+ for (let row = row0; row < row1; row += 1)
84
+ for (let i = 0; i < count; i += 1)
85
+ keys.push(`${prefix}${level.level}/${(((first + i) % columns) + columns) % columns}/${row}`);
86
+ return keys;
87
+ }
88
+ const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
89
+ /**
90
+ * What a decoded picture holds in memory, with its mipmaps (4/3 of its bytes): the `bytes` of a map source.
91
+ *
92
+ * @param tile - The tile.
93
+ * @returns Bytes.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { imageBytes } from "@johnmorrisdotca/chikyu-earth/door";
98
+ *
99
+ * console.log(imageBytes({ width: 512, height: 512, image: { width: 512, height: 512 } }));
100
+ * ```
101
+ */
102
+ export function imageBytes(tile) {
103
+ return Math.ceil(tile.width * tile.height * 4 * (4 / 3));
104
+ }
105
+ const folders = new Map();
106
+ /**
107
+ * The package's own finer map tiles as a source: a folder with a `manifest.json` and a tile for each layer, level and place at `<layer>/<level>/<column>/<row>.webp` (made by `scripts/make-earth-tiles.py`). This is what the `tiles`
108
+ * attribute of `<chikyu-earth-realistic>` means, and what the Earth is drawn from where no source of yours covers a layer. It is for every layer in the folder (`layer: "*"`); the manifest says which levels each has, and it is read once
109
+ * for the source, only when a view first wants more than the 4096 pixel picture. Its `id` is `chikyu-tiles`, and a view counts it as the package's own data.
110
+ *
111
+ * @param base - The folder's address, with or without the closing slash.
112
+ * @param options - The `fetch` and the decoder to use.
113
+ * @returns The source.
114
+ *
115
+ * @example
116
+ * ```ts no-run
117
+ * import { earthTiles } from "@johnmorrisdotca/chikyu-earth/door";
118
+ *
119
+ * const mine = earthTiles("/tiles/");
120
+ * console.log(mine.need({ lonMin: 0, lonMax: 20, latMin: 0, latMax: 10, layer: "day" }, 8192));
121
+ * ```
122
+ */
123
+ export function earthTiles(base, options = {}) {
124
+ const folder = slash(base);
125
+ const get = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
126
+ const decode = options.decode ?? ((blob) => createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }));
127
+ let manifest;
128
+ const source = {
129
+ kind: "tiles",
130
+ layer: "*",
131
+ info: OWN_BY_ID.get("chikyu-tiles"),
132
+ need(place, detail) {
133
+ const layer = place.layer;
134
+ if (typeof layer !== "string" || layer === "")
135
+ throw new RangeError("a folder of tiles is asked for a place with its layer");
136
+ return mapKeys(place, detail, DEFAULT_LEVELS, `${layer}/`);
137
+ },
138
+ async levels(layer) {
139
+ // read once: a folder that cannot be read is not asked again by this source, so a view at rest sends nothing
140
+ const asked = (manifest ??= get(`${folder}manifest.json`, { mode: "cors" }).then(async (response) => (response.ok ? parseManifest(await response.json().catch(() => undefined))?.layers : undefined), () => undefined));
141
+ const layers = await asked;
142
+ // an answer that was no folder is not kept: the next view of it (a changed source, a new element) asks again, and a view at rest never does
143
+ if (layers === undefined && manifest === asked)
144
+ manifest = undefined;
145
+ return layers?.[layer];
146
+ },
147
+ async load(key, signal) {
148
+ if (tileKeyParts(key) === undefined)
149
+ throw new RangeError(`"${key}" is not the key of a tile`);
150
+ const response = await get(`${folder}${key}.webp`, { mode: "cors", signal });
151
+ if (!response.ok)
152
+ throw new Error(`The tile ${key} could not be fetched (${response.status})`);
153
+ const image = await decode(await response.blob());
154
+ return { width: image.width > 0 ? image.width : 512, height: image.height > 0 ? image.height : 512, image };
155
+ },
156
+ bytes: (tile) => imageBytes(tile),
157
+ };
158
+ madeHere(source);
159
+ return source;
160
+ }
161
+ /**
162
+ * The folder source of an address, the same object each time: what an element makes of its `tiles` attribute, so that two elements on a page with the same folder share one source and its pictures.
163
+ *
164
+ * @param base - The folder's address.
165
+ * @returns The source `earthTiles` makes for it.
166
+ *
167
+ * @example
168
+ * ```ts no-run
169
+ * import { folderSource } from "@johnmorrisdotca/chikyu-earth/door";
170
+ *
171
+ * console.log(folderSource("/tiles/") === folderSource("/tiles/"));
172
+ * ```
173
+ */
174
+ export function folderSource(base) {
175
+ const folder = slash(base);
176
+ let held = folders.get(folder);
177
+ if (held === undefined) {
178
+ held = earthTiles(folder);
179
+ folders.set(folder, held);
180
+ }
181
+ return held;
182
+ }
@@ -0,0 +1,36 @@
1
+ import type { Credit, SourceInfo } from "../data-door.ts";
2
+ /**
3
+ * The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
4
+ * A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
9
+ *
10
+ * console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
11
+ * ```
12
+ */
13
+ export declare const OWN_SOURCES: readonly SourceInfo[];
14
+ /** The rows of `OWN_SOURCES` by id. */
15
+ export declare const OWN_BY_ID: ReadonlyMap<string, SourceInfo>;
16
+ /** Marks a source object as made by this package. */
17
+ export declare function madeHere<T extends object>(source: T): T;
18
+ /** True for a source object this package made (`earthTiles`), false for any other. */
19
+ export declare const isOwnSource: (source: object) => boolean;
20
+ /**
21
+ * The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
22
+ * puts `ownCredit("chikyu-pictures", 1)` in its credit line.
23
+ *
24
+ * @param id - `chikyu-pictures` or `chikyu-tiles`.
25
+ * @param used - How many marks were drawn from it.
26
+ * @returns The credit, marked as the package's own.
27
+ * @throws RangeError for an id that is not one of `OWN_SOURCES`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
32
+ *
33
+ * console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
34
+ * ```
35
+ */
36
+ export declare function ownCredit(id: string, used: number): Credit;
@@ -0,0 +1,75 @@
1
+ const NOTICE = "https://github.com/johnmorrisdotca/chikyu-earth/blob/main/NOTICE.md";
2
+ function freeze(value) {
3
+ if (typeof value === "object" && value !== null)
4
+ for (const inner of Object.values(value))
5
+ freeze(inner);
6
+ return Object.freeze(value);
7
+ }
8
+ /**
9
+ * The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
10
+ * A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
15
+ *
16
+ * console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
17
+ * ```
18
+ */
19
+ export const OWN_SOURCES = freeze([
20
+ {
21
+ id: "chikyu-pictures",
22
+ name: { en: "Earth pictures", ja: "地球の画像" },
23
+ credit: {
24
+ en: "Earth pictures: NASA Earth Observatory (Blue Marble, Reto Stöckli; Black Marble, Suomi NPP VIIRS data)",
25
+ ja: "地球の画像:NASA Earth Observatory(ブルーマーブル、Reto Stöckli/ブラックマーブル、Suomi NPP VIIRSデータ)",
26
+ },
27
+ licence: { name: "Public domain", url: `${NOTICE}#the-realistic-earths-pictures` },
28
+ url: "https://github.com/johnmorrisdotca/chikyu-earth/tree/main/textures",
29
+ retrieved: "2026-11-02",
30
+ },
31
+ {
32
+ id: "chikyu-tiles",
33
+ name: { en: "Finer map tiles", ja: "細かい地図のタイル" },
34
+ credit: {
35
+ en: "Finer map tiles: NASA Earth Observatory (Blue Marble: Next Generation; Black Marble, Suomi NPP VIIRS data), cut by Chikyu Earth",
36
+ ja: "細かい地図のタイル:NASA Earth Observatory(ブルーマーブル・ネクストジェネレーション/ブラックマーブル、Suomi NPP VIIRSデータ)、Chikyu Earthで切り出したもの",
37
+ },
38
+ licence: { name: "Public domain", url: `${NOTICE}#the-earth-tiles` },
39
+ url: "https://johnmorrisdotca.github.io/chikyu-earth/tiles/",
40
+ retrieved: "2026-11-08",
41
+ },
42
+ ]);
43
+ /** The rows of `OWN_SOURCES` by id. */
44
+ export const OWN_BY_ID = new Map(OWN_SOURCES.map((source) => [source.id, source]));
45
+ /** The source objects this package made itself: only these are its own, whatever id a caller's source gives itself. */
46
+ const MADE_HERE = new WeakSet();
47
+ /** Marks a source object as made by this package. */
48
+ export function madeHere(source) {
49
+ MADE_HERE.add(source);
50
+ return source;
51
+ }
52
+ /** True for a source object this package made (`earthTiles`), false for any other. */
53
+ export const isOwnSource = (source) => MADE_HERE.has(source);
54
+ /**
55
+ * The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
56
+ * puts `ownCredit("chikyu-pictures", 1)` in its credit line.
57
+ *
58
+ * @param id - `chikyu-pictures` or `chikyu-tiles`.
59
+ * @param used - How many marks were drawn from it.
60
+ * @returns The credit, marked as the package's own.
61
+ * @throws RangeError for an id that is not one of `OWN_SOURCES`.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
66
+ *
67
+ * console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
68
+ * ```
69
+ */
70
+ export function ownCredit(id, used) {
71
+ const source = OWN_BY_ID.get(id);
72
+ if (source === undefined)
73
+ throw new RangeError(`"${id}" is not one of the package's own sources`);
74
+ return { source, own: true, used };
75
+ }
@@ -1,3 +1,4 @@
1
1
  export { METEOR_SHOWERS, type MeteorShower } from "../data/meteor-showers.ts";
2
2
  export { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, activeShowers, apexPoint, darkness, hourlyRateAt, meteorSky, placeVector, pointBeneath, showerRate, solarLongitude, type MeteorSky } from "./rate.ts";
3
3
  export { METEORS_PER_SECOND_MAX, METEOR_SLOTS, streakPath, streaksPerSecond } from "./layer.ts";
4
+ export { METEOR_STRENGTH_DEFAULT, readMeteorStrength } from "./strength.ts";
@@ -4,3 +4,4 @@
4
4
  export { METEOR_SHOWERS } from "../data/meteor-showers.js";
5
5
  export { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, activeShowers, apexPoint, darkness, hourlyRateAt, meteorSky, placeVector, pointBeneath, showerRate, solarLongitude } from "./rate.js";
6
6
  export { METEORS_PER_SECOND_MAX, METEOR_SLOTS, streakPath, streaksPerSecond } from "./layer.js";
7
+ export { METEOR_STRENGTH_DEFAULT, readMeteorStrength } from "./strength.js";
@@ -32,6 +32,8 @@ export interface MeteorState {
32
32
  running: () => boolean;
33
33
  /** Told when the strongest active shower changes, with `null` when none is active. */
34
34
  onShower?: (shower: MeteorShower | null, zhr: number) => void;
35
+ /** How strongly the streaks are drawn, 0 to 1 (`meteors-strength`): it scales how many start and how bright they are, and nothing that is real. 0 draws none. */
36
+ strength: number;
35
37
  random: () => number;
36
38
  drawn: {
37
39
  alive: number;
@@ -66,18 +68,20 @@ export interface MeteorLayer {
66
68
  * How many streaks a second are drawn for a mean hourly rate over the dark part of the view: 2.5 a second where the whole view is dark on a
67
69
  * night with no shower, more with a shower but squeezed (the 0.6th power) and never over nine, none where nothing in view is dark.
68
70
  * A streak stands for a great many meteors: the count follows the real rate, it does not equal it.
71
+ * `strength` (0 to 1, the page's `meteors-strength`) then scales the count: half the streaks at 0.5, none at 0.
69
72
  *
70
73
  * @param meanHourlyRate - The mean over the view of each place's hourly rate times how dark it is there (`hourlyRateAt`, `darkness`).
74
+ * @param strength - How strongly the streaks are drawn, from 0 to 1 (1 when left out); a number outside the range is brought to its nearest end.
71
75
  * @returns Streaks a second.
72
76
  *
73
77
  * @example
74
78
  * ```ts
75
79
  * import { streaksPerSecond } from "@johnmorrisdotca/chikyu-earth/meteors";
76
80
  *
77
- * console.log(streaksPerSecond(8), streaksPerSecond(0), streaksPerSecond(100000)); // 2.5 0 9
81
+ * console.log(streaksPerSecond(8), streaksPerSecond(0), streaksPerSecond(100000), streaksPerSecond(8, 0.5)); // 2.5 0 9 1.25
78
82
  * ```
79
83
  */
80
- export declare function streaksPerSecond(meanHourlyRate: number): number;
84
+ export declare function streaksPerSecond(meanHourlyRate: number, strength?: number): number;
81
85
  /**
82
86
  * Where one streak runs: from `start` to `end`, in Earth radii from the centre, in the Earth's own axes.
83
87
  * It ends `METEOR_HEIGHT_KM.bottom + 5` km up and comes down the line from the radiant; its true length is the drop in height
@@ -1,4 +1,5 @@
1
1
  import { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, darkness, hourlyRateAt, meteorSky } from "./rate.js";
2
+ import { METEOR_STRENGTH_DEFAULT } from "./strength.js";
2
3
  const EARTH_KM = 6371;
3
4
  /**
4
5
  * The most streaks alive at once: the size of the one mesh they are drawn as.
@@ -37,32 +38,35 @@ const SAMPLES = 160;
37
38
  /** The Earth's radius on the screen, in CSS pixels, below which no streak is drawn. */
38
39
  const MIN_EARTH_PX = 40;
39
40
  const FRAME_MS = 33;
40
- export const newMeteorState = () => ({ on: false, running: () => false, random: Math.random, drawn: { alive: 0, spawned: 0, perSecond: 0, shower: null, zhr: 0 } });
41
+ export const newMeteorState = () => ({ on: false, running: () => false, strength: METEOR_STRENGTH_DEFAULT, random: Math.random, drawn: { alive: 0, spawned: 0, perSecond: 0, shower: null, zhr: 0 } });
41
42
  /**
42
43
  * How many streaks a second are drawn for a mean hourly rate over the dark part of the view: 2.5 a second where the whole view is dark on a
43
44
  * night with no shower, more with a shower but squeezed (the 0.6th power) and never over nine, none where nothing in view is dark.
44
45
  * A streak stands for a great many meteors: the count follows the real rate, it does not equal it.
46
+ * `strength` (0 to 1, the page's `meteors-strength`) then scales the count: half the streaks at 0.5, none at 0.
45
47
  *
46
48
  * @param meanHourlyRate - The mean over the view of each place's hourly rate times how dark it is there (`hourlyRateAt`, `darkness`).
49
+ * @param strength - How strongly the streaks are drawn, from 0 to 1 (1 when left out); a number outside the range is brought to its nearest end.
47
50
  * @returns Streaks a second.
48
51
  *
49
52
  * @example
50
53
  * ```ts
51
54
  * import { streaksPerSecond } from "@johnmorrisdotca/chikyu-earth/meteors";
52
55
  *
53
- * console.log(streaksPerSecond(8), streaksPerSecond(0), streaksPerSecond(100000)); // 2.5 0 9
56
+ * console.log(streaksPerSecond(8), streaksPerSecond(0), streaksPerSecond(100000), streaksPerSecond(8, 0.5)); // 2.5 0 9 1.25
54
57
  * ```
55
58
  */
56
- export function streaksPerSecond(meanHourlyRate) {
57
- if (!(meanHourlyRate > 0))
59
+ export function streaksPerSecond(meanHourlyRate, strength = METEOR_STRENGTH_DEFAULT) {
60
+ if (!(meanHourlyRate > 0) || !(strength > 0))
58
61
  return 0;
59
- return Math.min(METEORS_PER_SECOND_MAX, BASE_PER_SECOND * Math.pow(meanHourlyRate / SPORADIC_HOURLY_RATE, 0.6));
62
+ return Math.min(METEORS_PER_SECOND_MAX, BASE_PER_SECOND * Math.pow(meanHourlyRate / SPORADIC_HOURLY_RATE, 0.6)) * Math.min(1, strength);
60
63
  }
61
64
  const VERT = /* glsl */ `
62
65
  uniform float now;
63
66
  uniform float vw;
64
67
  uniform float vh;
65
68
  uniform float thick;
69
+ uniform float strength;
66
70
  attribute vec3 aStart;
67
71
  attribute vec3 aEnd;
68
72
  attribute vec2 aTime;
@@ -88,7 +92,7 @@ void main() {
88
92
  at.xy += push / halfSize * at.w;
89
93
  // a streak is there from its start to a short afterglow, and nowhere before or after
90
94
  float alive = step(0.0, age) * (1.0 - smoothstep(1.0, 1.35, age));
91
- vFade = alive * aGlow * smoothstep(0.0, 0.12, age);
95
+ vFade = alive * aGlow * strength * smoothstep(0.0, 0.12, age);
92
96
  vAlong = aCorner.x;
93
97
  vSide = aCorner.y;
94
98
  gl_Position = alive > 0.0 ? at : vec4(2.0, 2.0, 2.0, 1.0);
@@ -173,7 +177,7 @@ export function createMeteorLayer(three, parent, state) {
173
177
  geometry.setAttribute("aCorner", new three.BufferAttribute(cornerOf, 2));
174
178
  geometry.setAttribute("aGlow", glowAttr);
175
179
  geometry.setIndex(index);
176
- const uniforms = { now: { value: 0 }, vw: { value: 1 }, vh: { value: 1 }, thick: { value: 1.8 }, tint: { value: new three.Vector3(1, 0.96, 0.86) } };
180
+ const uniforms = { now: { value: 0 }, vw: { value: 1 }, vh: { value: 1 }, thick: { value: 1.8 }, strength: { value: 1 }, tint: { value: new three.Vector3(1, 0.96, 0.86) } };
177
181
  const material = new three.ShaderMaterial({ vertexShader: VERT, fragmentShader: FRAG, uniforms, transparent: true, depthWrite: false, side: three.DoubleSide });
178
182
  const mesh = new three.Mesh(geometry, material);
179
183
  mesh.frustumCulled = false;
@@ -185,6 +189,8 @@ export function createMeteorLayer(three, parent, state) {
185
189
  const over = new Float64Array(METEOR_SLOTS);
186
190
  let sky = null;
187
191
  let skyAt = -Infinity;
192
+ /** The strength the sky was last surveyed at: a new one makes the survey again, so the count follows it at once. */
193
+ let surveyedAt = METEOR_STRENGTH_DEFAULT;
188
194
  let peak = 0;
189
195
  let perSecond = 0;
190
196
  let nextAt = 0;
@@ -210,7 +216,8 @@ export function createMeteorLayer(three, parent, state) {
210
216
  if (weight > peak)
211
217
  peak = weight;
212
218
  }
213
- perSecond = streaksPerSecond(sum / SAMPLES);
219
+ surveyedAt = state.strength;
220
+ perSecond = streaksPerSecond(sum / SAMPLES, surveyedAt);
214
221
  const top = sky.showers[0];
215
222
  state.drawn.perSecond = perSecond;
216
223
  state.drawn.shower = top?.shower.code ?? null;
@@ -296,8 +303,18 @@ export function createMeteorLayer(three, parent, state) {
296
303
  mesh.visible = false;
297
304
  return Infinity;
298
305
  }
299
- if (!sky || Math.abs(input.time - sky.ms) > SKY_GAME_MS || input.now - skyAt > SKY_WALL_MS)
306
+ if (!sky || Math.abs(input.time - sky.ms) > SKY_GAME_MS || input.now - skyAt > SKY_WALL_MS || state.strength !== surveyedAt)
300
307
  survey(input);
308
+ uniforms.strength.value = Math.min(1, Math.max(0, state.strength));
309
+ if (!(state.strength > 0)) {
310
+ // strength 0: the sky is still surveyed (the shower is still told) but no streak starts, and nothing more is asked for
311
+ over.fill(0);
312
+ nextAt = 0;
313
+ last = input.now;
314
+ state.drawn.alive = 0;
315
+ mesh.visible = false;
316
+ return Infinity;
317
+ }
301
318
  if (perSecond > 0) {
302
319
  // after a rest the clock starts again from now, so a pause is not made up for with a burst
303
320
  if (input.now - last > 1000 || nextAt === 0)
@@ -0,0 +1,26 @@
1
+ /**
2
+ * How strongly the meteors are drawn when a page says nothing: 1, the look they have always had. The page's `meteors-strength` attribute chooses.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { METEOR_STRENGTH_DEFAULT } from "@johnmorrisdotca/chikyu-earth/meteors";
7
+ *
8
+ * console.log(METEOR_STRENGTH_DEFAULT); // 1
9
+ * ```
10
+ */
11
+ export declare const METEOR_STRENGTH_DEFAULT = 1;
12
+ /**
13
+ * What a page's `meteors-strength` attribute means: a number from 0 (no streaks are drawn) to 1 (the full look), given as it is written; with none, or something that
14
+ * is not a number, `METEOR_STRENGTH_DEFAULT`. A number outside the range is brought to its nearest end.
15
+ *
16
+ * @param given - The attribute's value, or `null` when the page has none.
17
+ * @returns How strongly the streaks are drawn, between 0 and 1.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { readMeteorStrength } from "@johnmorrisdotca/chikyu-earth/meteors";
22
+ *
23
+ * console.log(readMeteorStrength(null), readMeteorStrength("0.3"), readMeteorStrength("7"), readMeteorStrength("-1"), readMeteorStrength("soft")); // 1 0.3 1 0 1
24
+ * ```
25
+ */
26
+ export declare function readMeteorStrength(given: string | null): number;
@@ -0,0 +1,35 @@
1
+ // How strongly the meteors are drawn: one number from 0 to 1 that a page sets with `meteors-strength`. It scales how bright a streak is and how many are drawn.
2
+ // It changes nothing that is real: the hourly rates, the showers and the `chikyu-meteors` event are the same at every strength.
3
+ /**
4
+ * How strongly the meteors are drawn when a page says nothing: 1, the look they have always had. The page's `meteors-strength` attribute chooses.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { METEOR_STRENGTH_DEFAULT } from "@johnmorrisdotca/chikyu-earth/meteors";
9
+ *
10
+ * console.log(METEOR_STRENGTH_DEFAULT); // 1
11
+ * ```
12
+ */
13
+ export const METEOR_STRENGTH_DEFAULT = 1;
14
+ /**
15
+ * What a page's `meteors-strength` attribute means: a number from 0 (no streaks are drawn) to 1 (the full look), given as it is written; with none, or something that
16
+ * is not a number, `METEOR_STRENGTH_DEFAULT`. A number outside the range is brought to its nearest end.
17
+ *
18
+ * @param given - The attribute's value, or `null` when the page has none.
19
+ * @returns How strongly the streaks are drawn, between 0 and 1.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { readMeteorStrength } from "@johnmorrisdotca/chikyu-earth/meteors";
24
+ *
25
+ * console.log(readMeteorStrength(null), readMeteorStrength("0.3"), readMeteorStrength("7"), readMeteorStrength("-1"), readMeteorStrength("soft")); // 1 0.3 1 0 1
26
+ * ```
27
+ */
28
+ export function readMeteorStrength(given) {
29
+ if (given === null || given.trim() === "")
30
+ return METEOR_STRENGTH_DEFAULT;
31
+ const value = Number(given);
32
+ if (!Number.isFinite(value))
33
+ return METEOR_STRENGTH_DEFAULT;
34
+ return Math.min(1, Math.max(0, value));
35
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ElementSet } from "../satellites/types.ts";
2
+ import { type Credit, type DataSource } from "../data-door.ts";
2
3
  import { type SatellitePass } from "./passes.ts";
3
4
  type Lang = "en" | "ja";
4
5
  /**
@@ -26,6 +27,23 @@ export declare class ChikyuPasses extends HTMLElement {
26
27
  /** The orbit data the passes are worked out from. Setting it works the passes out again. */
27
28
  get elements(): readonly ElementSet[];
28
29
  set elements(sets: readonly ElementSet[]);
30
+ /**
31
+ * The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
32
+ * Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
33
+ */
34
+ get sources(): readonly DataSource[];
35
+ set sources(list: readonly unknown[]);
36
+ /** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
37
+ addSource(source: unknown): () => void;
38
+ /** Takes a source away by its id. Returns whether there was one. */
39
+ removeSource(id: string): boolean;
40
+ /** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
41
+ enableSource(id: string, on: boolean): void;
42
+ /**
43
+ * Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
44
+ * as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
45
+ */
46
+ credits(): Credit[];
29
47
  /** The passes listed now, earliest first. */
30
48
  get passes(): readonly SatellitePass[];
31
49
  /** The pass pressed, or undefined. */