@geolith/globe 0.1.0 → 0.2.1

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
@@ -77,5 +77,5 @@ pnpm format
77
77
  pnpm typecheck
78
78
  ```
79
79
 
80
- The local gates are the gate (Actions billing is off for the org); paste their
81
- exit codes in a PR.
80
+ CI (`.github/workflows/ci.yml`) is the gate; run the same commands locally
81
+ before a PR.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { Component, ComputedRef, Ref } from "vue";
2
- import { Map, StyleSpecification } from "maplibre-gl";
3
1
  import { Grid } from "@geoql/maplibre-gl-weather";
2
+ import { Map, StyleSpecification } from "maplibre-gl";
3
+ import { ComputedRef, Ref } from "vue";
4
4
  /**
5
5
  * The forecast models the catalogue can publish a field for. The strings are the
6
6
  * dataset's own model keys, so a URL is never assembled from a display name.
7
7
  */
8
- type GlobeModel = "gfs" | "ecmwf-ifs";
8
+ type GlobeModel = 'gfs' | 'ecmwf-ifs';
9
9
  /** A quantised field the weather layers know how to draw. */
10
- type GlobeField = "rain" | "tmax" | "tmin" | "wind-u" | "wind-v";
10
+ type GlobeField = 'rain' | 'tmax' | 'tmin' | 'wind-u' | 'wind-v';
11
11
  /** One catalogue layer, as the caller's catalogue defines it. */
12
12
  interface GlobeLayer {
13
13
  /** Catalogue id: `'forecast-rain'`, `'wind'`, `'flood-risk'`. */
@@ -15,7 +15,7 @@ interface GlobeLayer {
15
15
  /** The catalogue's own label; never typed by the app. */
16
16
  readonly label: string;
17
17
  /** A global field, or a district dataset drawn when zoomed in. */
18
- readonly kind: "field" | "district";
18
+ readonly kind: 'field' | 'district';
19
19
  /** Models that publish this layer; empty for a district layer. */
20
20
  readonly models: readonly GlobeModel[];
21
21
  /** Fields this layer draws; empty for a district layer. */
@@ -73,98 +73,22 @@ interface GlobeSelect {
73
73
  interface GlobeLockedClick {
74
74
  readonly country: string;
75
75
  }
76
- /** What the field layer is doing, as the page reports it. */
77
- type GlobeStatus = "idle" | "loading" | "ready" | "empty" | "error";
78
- /** Everything `useGlobeFields` reads. */
79
- interface GlobeFieldsInput {
80
- readonly source: GlobeDataSource;
81
- readonly selection: Ref<GlobeSelection>;
82
- /** The catalogue layer's fields; the first one is drawn and blended. */
83
- readonly fields?: readonly GlobeField[];
84
- readonly fetchJson: (url: string) => Promise<unknown>;
85
- /** The grid's decoded bytes: the transport un-gzips, never the shader. */
86
- readonly fetchBytes: (url: string) => Promise<Uint8Array>;
87
- }
88
- /** The field frames and their state. */
89
- interface GlobeFields {
90
- readonly index: Ref<FieldIndexDto | null>;
91
- readonly frames: Ref<readonly Grid[]>;
92
- /** `0` shows `frames[0]`, `1` shows `frames[1]`. */
93
- readonly mix: Ref<number>;
94
- readonly status: Ref<GlobeStatus>;
95
- /** The index's own day labels, in order. */
96
- readonly labels: Ref<readonly string[]>;
97
- load(): Promise<void>;
98
- }
99
- /**
100
- * Loads one field's index, then the selected day and the day after it, so the
101
- * shader can blend. The composable never invents a zero field: no data is
102
- * `'empty'` and a failed grid after a good index keeps the frames it had.
103
- */
104
- export declare function useGlobeFields(input: GlobeFieldsInput): GlobeFields;
105
76
  /** The wind pair the particle layer advects through. */
106
77
  interface WindPair {
107
78
  readonly u: Grid;
108
79
  readonly v: Grid;
109
80
  }
110
- /** Everything `useGlobeParticles` reads. */
111
- interface GlobeParticlesInput {
112
- readonly source: GlobeDataSource;
113
- readonly selection: Ref<GlobeSelection>;
114
- readonly fetchJson: (url: string) => Promise<unknown>;
115
- readonly fetchBytes: (url: string) => Promise<Uint8Array>;
116
- }
117
- /** The wind grids and their state. */
118
- interface GlobeParticles {
119
- readonly wind: Ref<WindPair | null>;
120
- readonly status: Ref<GlobeStatus>;
121
- load(): Promise<void>;
122
- }
123
- /**
124
- * Loads the 10 m wind pair (`u` east, `v` north) for the selected day. A layer
125
- * with no wind fields, or a run that published none, is `'empty'` — the globe
126
- * then draws the field alone, never particles advected by zero wind.
127
- */
128
- export declare function useGlobeParticles(input: GlobeParticlesInput): GlobeParticles;
129
81
  /** A district source the map may draw. */
130
82
  interface DistrictSource {
131
83
  readonly country: string;
132
84
  readonly url: string;
133
85
  }
134
- /** Everything the map needs from the component. */
135
- interface UseGlobeMapInput {
136
- readonly host: Ref<HTMLElement | null>;
137
- readonly style: StyleSpecification;
138
- readonly centroid: readonly [number, number] | null;
139
- readonly reducedMotion: boolean;
140
- readonly source: GlobeDataSource;
141
- readonly frames: Ref<readonly Grid[]>;
142
- readonly mix: Ref<number>;
143
- readonly palette: readonly string[] | null;
144
- readonly wind: Ref<WindPair | null>;
145
- readonly district: Ref<DistrictSource | null>;
146
- /** True once the caller's data is ready; the map mounts then. */
147
- readonly mountWhen: Ref<boolean>;
148
- readonly onIdle: () => void;
149
- }
150
- /** The map handle and its lifecycle. */
151
- interface GlobeMap {
152
- readonly map: Ref<Map | null>;
153
- mount(): Promise<void>;
154
- dispose(): void;
155
- }
156
- /**
157
- * The map's lifecycle and its layers. Mounts only when its host measures non
158
- * zero in both axes, so a hidden page (or a test with no layout) mounts
159
- * nothing and logs nothing.
160
- */
161
- export declare function useGlobeMap(input: UseGlobeMapInput): GlobeMap;
162
86
  /** Everything the globe draws; the page supplies all of it. */
163
87
  interface GlobeCanvasProps {
164
88
  readonly layers: readonly GlobeLayer[];
165
89
  readonly dataSource: GlobeDataSource;
166
90
  readonly style: StyleSpecification;
167
- readonly status: "loading" | "ready" | "empty" | "error";
91
+ readonly status: 'loading' | 'ready' | 'empty' | 'error';
168
92
  readonly centroid?: readonly [number, number] | null;
169
93
  readonly reducedMotion?: boolean;
170
94
  readonly frames?: readonly Grid[];
@@ -173,27 +97,64 @@ interface GlobeCanvasProps {
173
97
  readonly wind?: WindPair | null;
174
98
  readonly district?: DistrictSource | null;
175
99
  }
176
- export declare const GlobeCanvas: Component;
177
- /** The locked country and the hook a page uses to open its own ask. */
178
- interface GlobeLockProps {
179
- readonly country: string;
180
- }
181
- export declare const GlobeLock: Component;
182
- /** The pointer readout: a value and its unit, or nothing at all. */
183
- interface GlobeReadoutProps {
184
- readonly value: number | null;
185
- readonly unit: string;
186
- }
187
- export declare const GlobeReadout: Component;
188
- export declare const GlobeSkeleton: Component;
189
100
  /** The 7-day slider: the run's own day labels, a play toggle, and a thumb. */
190
101
  interface GlobeTimeSliderProps {
191
102
  /** Day labels from the field index, in the run's order. */
192
103
  readonly labels: readonly string[];
193
104
  readonly modelValue: number;
194
- readonly playing: boolean;
105
+ readonly playing?: boolean;
106
+ }
107
+ /** The pointer readout: a value and its unit, or nothing at all. */
108
+ interface GlobeReadoutProps {
109
+ readonly value?: number | null;
110
+ readonly unit: string;
111
+ }
112
+ /** The locked country and the hook a page uses to open its own ask. */
113
+ interface GlobeLockProps {
114
+ readonly country: string;
195
115
  }
196
- export declare const GlobeTimeSlider: Component;
116
+ declare const __VLS_export$4: import("vue").DefineComponent<GlobeCanvasProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
117
+ idle: () => any;
118
+ select: (areaId: string) => any;
119
+ }, string, import("vue").PublicProps, Readonly<GlobeCanvasProps> & Readonly<{
120
+ onIdle?: (() => any) | undefined;
121
+ onSelect?: ((areaId: string) => any) | undefined;
122
+ }>, {
123
+ centroid: readonly [number, number] | null;
124
+ reducedMotion: boolean;
125
+ frames: readonly Grid[];
126
+ mix: number;
127
+ palette: readonly string[] | null;
128
+ wind: WindPair | null;
129
+ district: DistrictSource | null;
130
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
131
+ declare const _default: typeof __VLS_export$4;
132
+ declare const __VLS_export$3: import("vue").DefineComponent<GlobeLockProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
133
+ unlockRequest: (args_0: {
134
+ country: string;
135
+ }) => any;
136
+ }, string, import("vue").PublicProps, Readonly<GlobeLockProps> & Readonly<{
137
+ onUnlockRequest?: ((args_0: {
138
+ country: string;
139
+ }) => any) | undefined;
140
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
141
+ declare const _default$1: typeof __VLS_export$3;
142
+ declare const __VLS_export$2: import("vue").DefineComponent<GlobeReadoutProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<GlobeReadoutProps> & Readonly<{}>, {
143
+ value: number | null;
144
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
145
+ declare const _default$2: typeof __VLS_export$2;
146
+ declare const __VLS_export$1: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
147
+ declare const _default$3: typeof __VLS_export$1;
148
+ declare const __VLS_export: import("vue").DefineComponent<GlobeTimeSliderProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
149
+ "update:modelValue": (value: number) => any;
150
+ toggle: () => any;
151
+ }, string, import("vue").PublicProps, Readonly<GlobeTimeSliderProps> & Readonly<{
152
+ "onUpdate:modelValue"?: ((value: number) => any) | undefined;
153
+ onToggle?: (() => any) | undefined;
154
+ }>, {
155
+ playing: boolean;
156
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
157
+ declare const _default$4: typeof __VLS_export;
197
158
  /** What the visitor has explored: which layers, and since when (epoch ms). */
198
159
  interface Explored {
199
160
  readonly layers: ReadonlySet<string>;
@@ -230,6 +191,54 @@ export declare function useGlobeState(initial: {
230
191
  readonly unlockedCountries: readonly string[];
231
192
  readonly now?: () => number;
232
193
  }): GlobeState;
194
+ /** What the field layer is doing, as the page reports it. */
195
+ type GlobeStatus = 'idle' | 'loading' | 'ready' | 'empty' | 'error';
196
+ /** Everything `useGlobeFields` reads. */
197
+ interface GlobeFieldsInput {
198
+ readonly source: GlobeDataSource;
199
+ readonly selection: Ref<GlobeSelection>;
200
+ /** The catalogue layer's fields; the first one is drawn and blended. */
201
+ readonly fields?: readonly GlobeField[];
202
+ readonly fetchJson: (url: string) => Promise<unknown>;
203
+ /** The grid's decoded bytes: the transport un-gzips, never the shader. */
204
+ readonly fetchBytes: (url: string) => Promise<Uint8Array>;
205
+ }
206
+ /** The field frames and their state. */
207
+ interface GlobeFields {
208
+ readonly index: Ref<FieldIndexDto | null>;
209
+ readonly frames: Ref<readonly Grid[]>;
210
+ /** `0` shows `frames[0]`, `1` shows `frames[1]`. */
211
+ readonly mix: Ref<number>;
212
+ readonly status: Ref<GlobeStatus>;
213
+ /** The index's own day labels, in order. */
214
+ readonly labels: Ref<readonly string[]>;
215
+ load(): Promise<void>;
216
+ }
217
+ /**
218
+ * Loads one field's index, then the selected day and the day after it, so the
219
+ * shader can blend. The composable never invents a zero field: no data is
220
+ * `'empty'` and a failed grid after a good index keeps the frames it had.
221
+ */
222
+ export declare function useGlobeFields(input: GlobeFieldsInput): GlobeFields;
223
+ /** Everything `useGlobeParticles` reads. */
224
+ interface GlobeParticlesInput {
225
+ readonly source: GlobeDataSource;
226
+ readonly selection: Ref<GlobeSelection>;
227
+ readonly fetchJson: (url: string) => Promise<unknown>;
228
+ readonly fetchBytes: (url: string) => Promise<Uint8Array>;
229
+ }
230
+ /** The wind grids and their state. */
231
+ interface GlobeParticles {
232
+ readonly wind: Ref<WindPair | null>;
233
+ readonly status: Ref<GlobeStatus>;
234
+ load(): Promise<void>;
235
+ }
236
+ /**
237
+ * Loads the 10 m wind pair (`u` east, `v` north) for the selected day. A layer
238
+ * with no wind fields, or a run that published none, is `'empty'` — the globe
239
+ * then draws the field alone, never particles advected by zero wind.
240
+ */
241
+ export declare function useGlobeParticles(input: GlobeParticlesInput): GlobeParticles;
233
242
  /** A district source the globe may draw, or nothing for a locked country. */
234
243
  interface DistrictLayer {
235
244
  readonly id: string;
@@ -255,6 +264,40 @@ interface GlobeDistricts {
255
264
  * district geometry reaches a browser that may not read it.
256
265
  */
257
266
  export declare function useGlobeDistricts(input: GlobeDistrictsInput): GlobeDistricts;
267
+ /** Everything the map needs from the component. */
268
+ interface UseGlobeMapInput {
269
+ readonly host: Ref<HTMLElement | null>;
270
+ readonly style: StyleSpecification;
271
+ readonly centroid: readonly [number, number] | null;
272
+ readonly reducedMotion: boolean;
273
+ readonly source: GlobeDataSource;
274
+ readonly frames: Ref<readonly Grid[]>;
275
+ readonly mix: Ref<number>;
276
+ readonly palette: readonly string[] | null;
277
+ readonly wind: Ref<WindPair | null>;
278
+ readonly district: Ref<DistrictSource | null>;
279
+ /** True once the caller's data is ready; the map mounts then. */
280
+ readonly mountWhen: Ref<boolean>;
281
+ readonly onIdle: () => void;
282
+ /** A district click, by the area's own UUID. */
283
+ readonly onSelect?: (areaId: string) => void;
284
+ }
285
+ /** The map handle and its lifecycle. */
286
+ interface GlobeMap {
287
+ readonly map: Ref<Map | null>;
288
+ mount(): Promise<void>;
289
+ dispose(): void;
290
+ }
291
+ /**
292
+ * The map's lifecycle and its layers.
293
+ *
294
+ * MapLibre 6 refuses `setProjection` until a style is loaded, so the globe is
295
+ * converted on `load` and again on `style.load` (a new style drops both the
296
+ * projection and every custom layer). A mount can never run twice, and every
297
+ * add is guarded by the layer's existence, so N mounts and any number of prop
298
+ * changes leave exactly one map and one canvas.
299
+ */
300
+ export declare function useGlobeMap(input: UseGlobeMapInput): GlobeMap;
258
301
  /**
259
302
  * The globe opens at a fixed zoom and pitch, over one place: the visitor's
260
303
  * country when the caller resolved it, the world otherwise.
@@ -296,7 +339,7 @@ export declare const FIELD_FADE: readonly [number, number];
296
339
  /** The districts' half of the same handover. */
297
340
  export declare const DISTRICT_FADE: readonly [number, number];
298
341
  /** The desktop particle count the spike measured as free on a desktop GPU. */
299
- export declare const PARTICLE_CAP = 42e3;
342
+ export declare const PARTICLE_CAP = 42000;
300
343
  /**
301
344
  * Opacity of the global field at a zoom: 1 below the ramp, 0 above it, linear
302
345
  * between.
@@ -312,6 +355,57 @@ export declare function districtOpacity(zoom: number): number;
312
355
  * @param dpr - The device pixel ratio the map draws at.
313
356
  */
314
357
  export declare function particleCount(width: number, dpr: number, reducedMotion: boolean): number;
358
+ /** The source layer the area tiles carry. */
359
+ export declare const AREA_SOURCE_LAYER = "areas";
360
+ /**
361
+ * A district feature's own id.
362
+ *
363
+ * The MVT feature id is a tile-local integer; the area's UUID is the `id`
364
+ * property. Reading the integer asks the API for "area=192", which is not an
365
+ * area at all.
366
+ */
367
+ export declare function areaIdOf(properties: Readonly<Record<string, unknown>> | null | undefined): string | null;
368
+ /** The two layers a district source needs: a fill that fades in, and its line. */
369
+ interface DistrictLayerIds {
370
+ readonly sourceId: string;
371
+ readonly fill: string;
372
+ readonly line: string;
373
+ }
374
+ /**
375
+ * Adds a country's area source and its two layers, once per style. The fill
376
+ * fades in on the same ramp the field fades out on; the line keeps a coastline
377
+ * readable over the weather.
378
+ */
379
+ export declare function addDistrictLayers(map: Map, country: string, url: string): DistrictLayerIds;
380
+ /** Reports a district click by the area's own UUID, and the pointer shape. */
381
+ export declare function bindDistrictClicks(map: Map, fill: string, onSelect: (areaId: string) => void): void;
382
+ /**
383
+ * Rain as a field is mostly dry: the ramp's lowest stop is near-white, so a dry
384
+ * cell would paint the planet white. Cells under `minValue` (millimetres) are
385
+ * set to the no-data byte, so rain shows where rain is and nothing elsewhere.
386
+ *
387
+ * Only a rain grid is masked: a temperature cell is never "dry", and a wind
388
+ * component of zero is calm air, not an absence.
389
+ */
390
+ export declare function maskDryRain(frames: readonly Grid[], minValue: number): readonly Grid[];
391
+ /**
392
+ * How much of the particle budget the field may carry.
393
+ *
394
+ * Measured on this Mac (Chromium, SwiftShader, 1440×900, globe at z1.5, the
395
+ * field hidden so only the wind shows): the share of canvas pixels carrying a
396
+ * stroke is 1.1 % at 200 particles, 8.2 % at 4 200, 8.9 % at 8 000, 9.3 % at
397
+ * 14 700 and 9.9 % at 42 000. The curve is flat above ~4 000: 42 000 buys
398
+ * 1.7 points of coverage for ten times the work. `0.15` spends 6 300 at a
399
+ * desktop width and ~1 100 on a phone, just above the knee; the console's own
400
+ * report (a full budget became a white sheet on a phone) is the same finding
401
+ * from the other side. A host that wants more can pass its own count.
402
+ */
403
+ export declare const PARTICLE_DENSITY = 0.15;
404
+ /**
405
+ * Particles for a viewport: the handover budget scaled by the measured density,
406
+ * and none at all for a visitor who prefers reduced motion.
407
+ */
408
+ export declare function particleDensity(width: number, dpr: number, reducedMotion: boolean): number;
315
409
  /**
316
410
  * The field ramps. They are data ramps, not brand colours: a shader needs plain
317
411
  * RGB stops, and these are perceptually spaced so a 1 mm cell never looks like a
@@ -323,11 +417,10 @@ export declare const TEMPERATURE_RAMP: readonly string[];
323
417
  /** Calm to strong, the magma ramp. */
324
418
  export declare const WIND_RAMP: readonly string[];
325
419
  /** Every ramp the globe ships, keyed by the field family it draws. */
326
- export declare const FIELD_PALETTES: Readonly<Record<"rain" | "temperature" | "wind", readonly string[]>>;
420
+ export declare const FIELD_PALETTES: Readonly<Record<'rain' | 'temperature' | 'wind', readonly string[]>>;
327
421
  /**
328
422
  * The ramp for a field name: rain grids take the rain ramp, both temperature
329
423
  * fields the temperature ramp, both wind components the wind ramp.
330
424
  */
331
425
  export declare function paletteFor(field: string): readonly string[];
332
- export type { DistrictLayer, DistrictSource, Explored, FieldIndexDto, GlobeCanvasProps, GlobeDataSource, GlobeDistricts, GlobeDistrictsInput, GlobeField, GlobeFields, GlobeFieldsInput, GlobeHover, GlobeLayer, GlobeLockProps, GlobeLockedClick, GlobeMap, GlobeModel, GlobeParticles, GlobeParticlesInput, GlobeReadoutProps, GlobeSelect, GlobeSelection, GlobeState, GlobeStatus, GlobeTimeSliderProps, OpeningCamera, UseGlobeMapInput, WindPair };
333
- //# sourceMappingURL=index.d.ts.map
426
+ export { type DistrictLayer, type DistrictLayerIds, type DistrictSource, type Explored, type FieldIndexDto, _default as GlobeCanvas, type GlobeCanvasProps, type GlobeDataSource, type GlobeDistricts, type GlobeDistrictsInput, type GlobeField, type GlobeFields, type GlobeFieldsInput, type GlobeHover, type GlobeLayer, _default$1 as GlobeLock, type GlobeLockProps, type GlobeLockedClick, type GlobeMap, type GlobeModel, type GlobeParticles, type GlobeParticlesInput, _default$2 as GlobeReadout, type GlobeReadoutProps, type GlobeSelect, type GlobeSelection, _default$3 as GlobeSkeleton, type GlobeState, type GlobeStatus, _default$4 as GlobeTimeSlider, type GlobeTimeSliderProps, type OpeningCamera, type UseGlobeMapInput, type WindPair };