@azohra/meteo.station 0.4.2 → 0.6.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 (61) hide show
  1. package/README.md +1 -1
  2. package/dist/client/climatology.js +1 -1
  3. package/dist/client/history.d.ts +8 -14
  4. package/dist/client/history.js +8 -18
  5. package/dist/client/live.d.ts +2 -1
  6. package/dist/client/live.js +7 -4
  7. package/dist/client/stores.js +10 -2
  8. package/dist/climatology.d.ts +9 -4
  9. package/dist/climatology.js +28 -6
  10. package/dist/contract-climatology.d.ts +4 -0
  11. package/dist/contract-climatology.js +3 -1
  12. package/dist/contract.d.ts +7 -7
  13. package/dist/derive.js +5 -4
  14. package/dist/elements/elements/DailyPatternElement.js +4 -4
  15. package/dist/elements/elements/TrendChartElement.js +12 -31
  16. package/dist/elements/elements/WindHistoryChartElement.js +16 -35
  17. package/dist/elements/elements/atoms.d.ts +1 -1
  18. package/dist/elements/lib/pinned-cursor.js +48 -0
  19. package/dist/fixtures.d.ts +6 -2
  20. package/dist/fixtures.js +30 -2
  21. package/dist/format.js +7 -3
  22. package/dist/geometry.d.ts +2 -2
  23. package/dist/geometry.js +24 -17
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +2 -2
  26. package/dist/react/components/DailyPattern.js +2 -2
  27. package/dist/react/components/Dial.d.ts +1 -2
  28. package/dist/react/components/RecentSummaries.d.ts +1 -2
  29. package/dist/react/components/RecentSummaries.js +1 -2
  30. package/dist/react/components/TrendChart.js +8 -26
  31. package/dist/react/components/WindHistoryChart.js +12 -31
  32. package/dist/react/components/WindSampleStrip.js +11 -29
  33. package/dist/react/hooks/useStation.js +28 -50
  34. package/dist/react/hooks/useStationFeed.d.ts +0 -1
  35. package/dist/react/index.js +2 -2
  36. package/dist/react/lib/use-pinned-cursor.js +32 -0
  37. package/dist/samples.js +7 -43
  38. package/dist/scene/climatology-pattern.js +1 -1
  39. package/dist/scene/climatology-rose.js +1 -1
  40. package/dist/scene/daily-pattern.js +3 -3
  41. package/dist/scene/recent-summaries.js +1 -4
  42. package/dist/scene/trend.js +2 -7
  43. package/dist/scene/wind-plot.js +14 -6
  44. package/dist/server/adapters/windnerd-climatology.d.ts +5 -8
  45. package/dist/server/adapters/windnerd-climatology.js +11 -10
  46. package/dist/server/adapters/windnerd-live.d.ts +5 -8
  47. package/dist/server/adapters/windnerd-live.js +5 -8
  48. package/dist/server/adapters/windnerd.d.ts +2 -3
  49. package/dist/server/adapters/windnerd.js +4 -15
  50. package/dist/server/environment.d.ts +4 -10
  51. package/dist/server/environment.js +4 -10
  52. package/dist/server/index.d.ts +2 -2
  53. package/dist/server/index.js +2 -2
  54. package/dist/strings.d.ts +1 -1
  55. package/dist/strings.js +1 -1
  56. package/dist/windnerd.d.ts +3 -1
  57. package/dist/windnerd.js +11 -1
  58. package/package.json +3 -3
  59. package/schema/README.md +2 -2
  60. package/schema/stationclimatology.schema.json +26 -0
  61. package/styles.css +19 -21
package/README.md CHANGED
@@ -14,7 +14,7 @@ that render it natively, in your design system, with no vendor iframe.
14
14
  | `@azohra/meteo.station/client` | The framework-free client data layer: `createJsonPoller` and the station stores (`createStationFeedStore`, `createStationCurrentStore`, `createStationStore`) every binding subscribes to. Client-only at runtime, import-safe anywhere. |
15
15
  | `@azohra/meteo.station/server` | Vendor adapters plus the custom-adapter interface and `defineStationAdapter`, data-level `loadStationFeed()` / `loadStationCurrent()`, the Hologram connectivity loader (`loadHologramConnectivity`), and the mountable feed handler. Server-only, so it can never leak into a client bundle. |
16
16
  | `@azohra/meteo.station/react` | `StationFeedProvider`, polling hooks (`useStation`, `useStationFeed`, `useStationCurrent`), the component set (`StationCard`, `CurrentConditions`, `WindHistoryChart`, `WindSampleStrip`, `TrendChart`, `WindRose`, `DailyPattern`, `StationTable`, `StationStrip`, `AirMatrix`, `FreshnessBadge`), and an atoms layer of inline primitives (`Speed`, `Gust`, `Lull`, `Temperature`, `Pressure`, `Direction`, `UpdatedAt`, `BandChip`, `Dial`, `Sparkline`, `Readout`) for composing your own layouts. |
17
- | `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), a full peer of the react binding, framework-free, held byte-identical by a parity suite. `/register` is the auto-defining one-liner. |
17
+ | `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), a full peer of the React binding, framework-free, held byte-identical by a parity suite. `/register` is the auto-defining one-liner. |
18
18
  | `@azohra/meteo.station/styles.css` | The default skin (an intentional side effect), shared by both bindings. |
19
19
 
20
20
  ## Taste
@@ -1,6 +1,6 @@
1
1
  import { parseStationClimatologyJson } from "../contract-climatology.js";
2
+ import { REQUEST_TIMEOUT_MS } from "./poll.js";
2
3
  //#region src/client/climatology.ts
3
- const REQUEST_TIMEOUT_MS = 15e3;
4
4
  /**
5
5
  * Fetch-once store for the climatology document: near-immutable history
6
6
  * needs no poller. Every filter interaction re-aggregates the held cube
@@ -6,13 +6,9 @@ type StationHistoryQuery = {
6
6
  toMs: number;
7
7
  periodMinutes: number;
8
8
  };
9
- /**
10
- * The archive fetch contract: one requested window in, one
11
- * parsed document (or null on failure) out. A host that mounts the feed
12
- * handler uses `stationHistoryFetcher`; one that serves history its own way
13
- * — an authenticated server function, a proxy — supplies any function of
14
- * this shape and never touches the handler.
15
- */
9
+ /** One requested window in, one parsed document (or null on failure) out.
10
+ * A host that mounts the feed handler uses `stationHistoryFetcher`; a host
11
+ * serving history its own way supplies any function of this shape. */
16
12
  type StationHistoryFetcher = (query: StationHistoryQuery) => Promise<StationHistory | null>;
17
13
  /** The default fetcher, against the mounted handler's /history route. */
18
14
  declare function stationHistoryFetcher(base: string, stationId: string, fetchInit?: RequestInit): StationHistoryFetcher;
@@ -37,17 +33,15 @@ type ArchiveWindow = {
37
33
  /** The finest ladder period that keeps the span at or under the point
38
34
  * target; a span too wide for every rung takes the coarsest. */
39
35
  declare function archivePeriodFor(spanMs: number, periods?: ReadonlyArray<number>, targetPoints?: number): number;
40
- /** One whole LOCAL day from a YYYY-MM-DD date-input value — the day the
41
- * person picking it means, not the UTC day; null when the value is not a
42
- * real date. */
36
+ /** One whole LOCAL day from a YYYY-MM-DD date-input value (not the UTC
37
+ * day); null when the value is not a real date. */
43
38
  declare function archiveDayWindow(dateValue: string): ArchiveWindow | null;
44
39
  /** The YYYY-MM-DD value naming an instant's local day. */
45
40
  declare function archiveDayValue(atMs: number): string;
46
- /** The day value a number of days away — how a pager steps. Stepping
47
- * through noon of the target day keeps a DST-shifted midnight from landing
48
- * the step on the wrong side. Null when the value is not a real date. */
41
+ /** The day value deltaDays away. Steps through noon so a DST-shifted
42
+ * midnight cannot skip a day; null for an invalid value. */
49
43
  declare function archiveDayStep(dateValue: string, deltaDays: number): string | null;
50
- /** The trailing window ending now — a pager's "today". */
44
+ /** The trailing 24 h ending at nowMs. */
51
45
  declare function archiveTrailingWindow(nowMs: number, spanMs?: number): ArchiveWindow;
52
46
  //#endregion
53
47
  export { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, ArchiveWindow, HISTORY_STORE_DEFAULT_MAX_WINDOWS, StationHistoryFetcher, StationHistoryQuery, StationHistoryStore, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createStationHistoryStore, stationHistoryFetcher };
@@ -1,7 +1,8 @@
1
1
  import { parseStationHistoryJson } from "../contract.js";
2
2
  import { historyEndpoint } from "../endpoints.js";
3
+ import { WINDNERD_RECORD_PERIODS_MINUTES } from "../windnerd.js";
4
+ import { REQUEST_TIMEOUT_MS } from "./poll.js";
3
5
  //#region src/client/history.ts
4
- const REQUEST_TIMEOUT_MS = 15e3;
5
6
  const HISTORY_STORE_DEFAULT_MAX_WINDOWS = 32;
6
7
  /** The default fetcher, against the mounted handler's /history route. */
7
8
  function stationHistoryFetcher(base, stationId, fetchInit) {
@@ -52,16 +53,7 @@ function createStationHistoryStore(fetcher, options = {}) {
52
53
  size: () => held.size
53
54
  };
54
55
  }
55
- const ARCHIVE_DEFAULT_PERIODS_MINUTES = [
56
- 1,
57
- 5,
58
- 10,
59
- 15,
60
- 30,
61
- 60,
62
- 180,
63
- 360
64
- ];
56
+ const ARCHIVE_DEFAULT_PERIODS_MINUTES = WINDNERD_RECORD_PERIODS_MINUTES;
65
57
  const ARCHIVE_TARGET_POINTS = 500;
66
58
  const DAY_MS = 864e5;
67
59
  /** The finest ladder period that keeps the span at or under the point
@@ -71,9 +63,8 @@ function archivePeriodFor(spanMs, periods = ARCHIVE_DEFAULT_PERIODS_MINUTES, tar
71
63
  for (const period of ascending) if (spanMs / (period * 6e4) <= targetPoints) return period;
72
64
  return ascending[ascending.length - 1];
73
65
  }
74
- /** One whole LOCAL day from a YYYY-MM-DD date-input value — the day the
75
- * person picking it means, not the UTC day; null when the value is not a
76
- * real date. */
66
+ /** One whole LOCAL day from a YYYY-MM-DD date-input value (not the UTC
67
+ * day); null when the value is not a real date. */
77
68
  function archiveDayWindow(dateValue) {
78
69
  const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateValue);
79
70
  if (!match) return null;
@@ -95,15 +86,14 @@ function archiveDayValue(atMs) {
95
86
  const pad = (value) => String(value).padStart(2, "0");
96
87
  return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}`;
97
88
  }
98
- /** The day value a number of days away — how a pager steps. Stepping
99
- * through noon of the target day keeps a DST-shifted midnight from landing
100
- * the step on the wrong side. Null when the value is not a real date. */
89
+ /** The day value deltaDays away. Steps through noon so a DST-shifted
90
+ * midnight cannot skip a day; null for an invalid value. */
101
91
  function archiveDayStep(dateValue, deltaDays) {
102
92
  const window = archiveDayWindow(dateValue);
103
93
  if (window == null) return null;
104
94
  return archiveDayValue(window.fromMs + deltaDays * DAY_MS + DAY_MS / 2);
105
95
  }
106
- /** The trailing window ending now — a pager's "today". */
96
+ /** The trailing 24 h ending at nowMs. */
107
97
  function archiveTrailingWindow(nowMs, spanMs = DAY_MS) {
108
98
  return {
109
99
  fromMs: nowMs - spanMs,
@@ -9,6 +9,7 @@ type StationLiveSnapshot = {
9
9
  status: LiveStatus;
10
10
  station: Station | null;
11
11
  samples: LiveSample[];
12
+ sampleIntervalSeconds: number | null;
12
13
  servedAt: string | null;
13
14
  receivedAtMs: number | null;
14
15
  error: PollError | null;
@@ -32,6 +33,6 @@ declare function createStationLiveStore(base: string, stationId: string, options
32
33
  fetchInit?: FetchInitOption;
33
34
  windowSeconds?: number;
34
35
  }): StationLiveStore;
35
- declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples">): StationCurrent | null;
36
+ declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples" | "sampleIntervalSeconds">): StationCurrent | null;
36
37
  //#endregion
37
38
  export { LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, LiveStatus, StationLiveSnapshot, StationLiveStore, createStationLiveStore, liveSnapshotToCurrent };
@@ -21,6 +21,7 @@ function createStationLiveStore(base, stationId, options = {}) {
21
21
  status: "stopped",
22
22
  station: null,
23
23
  samples: [],
24
+ sampleIntervalSeconds: null,
24
25
  servedAt: null,
25
26
  receivedAtMs: null,
26
27
  error: null
@@ -36,11 +37,12 @@ function createStationLiveStore(base, stationId, options = {}) {
36
37
  switch (frame.type) {
37
38
  case "init": {
38
39
  current.attempt = 0;
39
- const points = frame.station.status === "ok" ? frame.station.samples?.points ?? [] : [];
40
+ const ring = frame.station.status === "ok" ? frame.station.samples ?? null : null;
40
41
  setSnapshot({
41
42
  status: "open",
42
43
  station: frame.station,
43
- samples: mergeSamples(snapshot.samples, points, windowSeconds),
44
+ samples: mergeSamples(snapshot.samples, ring?.points ?? [], windowSeconds),
45
+ sampleIntervalSeconds: ring?.intervalSeconds ?? snapshot.sampleIntervalSeconds,
44
46
  servedAt: frame.servedAt,
45
47
  receivedAtMs: Date.now(),
46
48
  error: null
@@ -52,6 +54,7 @@ function createStationLiveStore(base, stationId, options = {}) {
52
54
  ...snapshot,
53
55
  status: "open",
54
56
  samples: mergeSamples(snapshot.samples, frame.samples.points, windowSeconds),
57
+ sampleIntervalSeconds: frame.samples.intervalSeconds,
55
58
  receivedAtMs: Date.now(),
56
59
  error: null
57
60
  });
@@ -225,10 +228,10 @@ function createStationLiveStore(base, stationId, options = {}) {
225
228
  }
226
229
  function liveSnapshotToCurrent(live) {
227
230
  if (live.station == null || live.servedAt == null) return null;
228
- const station = live.station.status === "ok" && live.samples.length > 0 ? {
231
+ const station = live.station.status === "ok" && live.samples.length > 0 && live.sampleIntervalSeconds != null ? {
229
232
  ...live.station,
230
233
  samples: {
231
- intervalSeconds: live.station.samples?.intervalSeconds ?? 3,
234
+ intervalSeconds: live.sampleIntervalSeconds,
232
235
  points: live.samples
233
236
  }
234
237
  } : live.station;
@@ -80,6 +80,7 @@ function liveCurrentLeg(base, stationId, fetchInit) {
80
80
  error: null,
81
81
  receivedAtMs: null
82
82
  };
83
+ let running = false;
83
84
  const toCurrent = (live) => {
84
85
  const data = liveSnapshotToCurrent(live);
85
86
  return {
@@ -98,9 +99,16 @@ function liveCurrentLeg(base, stationId, fetchInit) {
98
99
  return mapped;
99
100
  },
100
101
  subscribe: (listener) => liveStore.subscribe(listener),
101
- start: () => liveStore.start(),
102
- stop: () => liveStore.stop(),
102
+ start: () => {
103
+ running = true;
104
+ liveStore.start();
105
+ },
106
+ stop: () => {
107
+ running = false;
108
+ liveStore.stop();
109
+ },
103
110
  refresh: () => {
111
+ if (!running) return;
104
112
  liveStore.stop();
105
113
  liveStore.start();
106
114
  }
@@ -27,6 +27,8 @@ type MutableCell = {
27
27
  type ClimatologyAccumulator = {
28
28
  readonly params: ClimatologyFoldParams;
29
29
  readonly cells: Map<string, MutableCell>;
30
+ /** Distinct (month, day, slot) buckets holding a record, per year. */
31
+ readonly coveredSlots: Map<number, Set<string>>;
30
32
  };
31
33
  declare function createClimatologyAccumulator(params: ClimatologyFoldParams): ClimatologyAccumulator;
32
34
  declare function foldClimatologyPoints(accumulator: ClimatologyAccumulator, points: ReadonlyArray<HistoryPoint>): void;
@@ -49,13 +51,16 @@ declare function climatologyPattern(document: StationClimatology, filters?: Pick
49
51
  type ClimatologyCoverage = {
50
52
  sampleCount: number;
51
53
  expectedCount: number;
52
- ratio: number;
54
+ ratio: number | null;
53
55
  };
54
- /** The whole record's honesty figure, summed over the year ledger. */
56
+ /** Per-year covered-slot counts, for producers writing the ledger. */
57
+ declare function coveredSlotCountByYear(accumulator: ClimatologyAccumulator): Map<number, number>;
58
+ /** Summed over the ledger. The ratio comes only from the slot pair and is
59
+ * null when any year lacks it — no percent beats a wrong-unit percent. */
55
60
  declare function climatologyCoverage(document: StationClimatology): ClimatologyCoverage;
56
61
  /** The share of the filtered non-calm record blowing from inside the
57
62
  * consumer's arcs, judged at each sector's centre bearing; null when
58
- * nothing non-calm was recorded — absence over a fabricated zero. */
63
+ * nothing non-calm was recorded. */
59
64
  declare function climatologyFavorableShare(document: StationClimatology, arcs: ReadonlyArray<DirectionArc>, filters?: ClimatologyFilters): number | null;
60
65
  //#endregion
61
- export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, createClimatologyAccumulator, foldClimatologyPoints };
66
+ export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };
@@ -7,7 +7,8 @@ function createClimatologyAccumulator(params) {
7
7
  if (params.sectorCount < 4) throw new Error(`climatology: sectorCount must be at least 4, got ${params.sectorCount}`);
8
8
  return {
9
9
  params,
10
- cells: /* @__PURE__ */ new Map()
10
+ cells: /* @__PURE__ */ new Map(),
11
+ coveredSlots: /* @__PURE__ */ new Map()
11
12
  };
12
13
  }
13
14
  function foldClimatologyPoints(accumulator, points) {
@@ -18,7 +19,15 @@ function foldClimatologyPoints(accumulator, points) {
18
19
  const local = new Date(localMs);
19
20
  const month = local.getUTCMonth() + 1;
20
21
  const minuteOfDay = local.getUTCHours() * 60 + local.getUTCMinutes();
21
- const key = `${month}/${Math.floor(minuteOfDay / slotMinutes)}`;
22
+ const slot = Math.floor(minuteOfDay / slotMinutes);
23
+ const year = local.getUTCFullYear();
24
+ let covered = accumulator.coveredSlots.get(year);
25
+ if (covered == null) {
26
+ covered = /* @__PURE__ */ new Set();
27
+ accumulator.coveredSlots.set(year, covered);
28
+ }
29
+ covered.add(`${month}/${local.getUTCDate()}/${slot}`);
30
+ const key = `${month}/${slot}`;
22
31
  let cell = accumulator.cells.get(key);
23
32
  if (cell == null) {
24
33
  cell = {
@@ -176,23 +185,36 @@ function climatologyPattern(document, filters) {
176
185
  };
177
186
  });
178
187
  }
179
- /** The whole record's honesty figure, summed over the year ledger. */
188
+ /** Per-year covered-slot counts, for producers writing the ledger. */
189
+ function coveredSlotCountByYear(accumulator) {
190
+ return new Map([...accumulator.coveredSlots.entries()].map(([year, slots]) => [year, slots.size]));
191
+ }
192
+ /** Summed over the ledger. The ratio comes only from the slot pair and is
193
+ * null when any year lacks it — no percent beats a wrong-unit percent. */
180
194
  function climatologyCoverage(document) {
181
195
  let sampleCount = 0;
182
196
  let expectedCount = 0;
197
+ let coveredSlots = 0;
198
+ let expectedSlots = 0;
199
+ let slotsKnown = true;
183
200
  for (const year of document.years) {
184
201
  sampleCount += year.sampleCount;
185
202
  expectedCount += year.expectedCount;
203
+ if (year.coveredSlotCount == null || year.expectedSlotCount == null) slotsKnown = false;
204
+ else {
205
+ coveredSlots += year.coveredSlotCount;
206
+ expectedSlots += year.expectedSlotCount;
207
+ }
186
208
  }
187
209
  return {
188
210
  sampleCount,
189
211
  expectedCount,
190
- ratio: expectedCount === 0 ? 0 : sampleCount / expectedCount
212
+ ratio: slotsKnown && expectedSlots > 0 ? coveredSlots / expectedSlots : null
191
213
  };
192
214
  }
193
215
  /** The share of the filtered non-calm record blowing from inside the
194
216
  * consumer's arcs, judged at each sector's centre bearing; null when
195
- * nothing non-calm was recorded — absence over a fabricated zero. */
217
+ * nothing non-calm was recorded. */
196
218
  function climatologyFavorableShare(document, arcs, filters) {
197
219
  if (arcs.length === 0) return null;
198
220
  const sectorWidth = 360 / document.sectorCount;
@@ -205,4 +227,4 @@ function climatologyFavorableShare(document, arcs, filters) {
205
227
  return blowing === 0 ? null : favorable / blowing;
206
228
  }
207
229
  //#endregion
208
- export { accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, createClimatologyAccumulator, foldClimatologyPoints };
230
+ export { accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };
@@ -31,6 +31,8 @@ declare const climatologyYearSchema: z.ZodObject<{
31
31
  year: z.ZodNumber;
32
32
  sampleCount: z.ZodNumber;
33
33
  expectedCount: z.ZodNumber;
34
+ coveredSlotCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
35
+ expectedSlotCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
36
  }, z.core.$strip>;
35
37
  type ClimatologyYear = z.infer<typeof climatologyYearSchema>;
36
38
  declare const stationClimatologySchema: z.ZodObject<{
@@ -45,6 +47,8 @@ declare const stationClimatologySchema: z.ZodObject<{
45
47
  year: z.ZodNumber;
46
48
  sampleCount: z.ZodNumber;
47
49
  expectedCount: z.ZodNumber;
50
+ coveredSlotCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
51
+ expectedSlotCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
48
52
  }, z.core.$strip>>;
49
53
  cells: z.ZodArray<z.ZodObject<{
50
54
  month: z.ZodNumber;
@@ -21,7 +21,9 @@ const climatologyCellSchema = z.object({
21
21
  const climatologyYearSchema = z.object({
22
22
  year: z.number().int(),
23
23
  sampleCount: count,
24
- expectedCount: count.describe("Records a gapless station would have produced over the requested window — the honesty denominator; a leading dropout lowers the ratio instead of hiding.")
24
+ expectedCount: count.describe("Records a gapless station would have produced over the requested window — the honesty denominator; a leading dropout lowers the ratio instead of hiding."),
25
+ coveredSlotCount: count.nullish().describe("Distinct (day, slot) buckets holding at least one record."),
26
+ expectedSlotCount: count.nullish().describe("Slots a gapless station would have covered over the window.")
25
27
  }).meta({ id: "ClimatologyYear" });
26
28
  const isoTime = z.string().refine((value) => Number.isFinite(Date.parse(value)), { message: "not an ISO timestamp" }).meta({ format: "date-time" });
27
29
  const stationClimatologySchema = z.object({
@@ -13,10 +13,10 @@ declare const airConditionsSchema: z.ZodObject<{
13
13
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
14
14
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
15
15
  pressureTrend: z.ZodNullable<z.ZodEnum<{
16
+ unknown: "unknown";
16
17
  falling: "falling";
17
18
  rising: "rising";
18
19
  steady: "steady";
19
- unknown: "unknown";
20
20
  }>>;
21
21
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
22
22
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -45,10 +45,10 @@ declare const readingSchema: z.ZodObject<{
45
45
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
46
46
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
47
47
  pressureTrend: z.ZodNullable<z.ZodEnum<{
48
+ unknown: "unknown";
48
49
  falling: "falling";
49
50
  rising: "rising";
50
51
  steady: "steady";
51
- unknown: "unknown";
52
52
  }>>;
53
53
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
54
54
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -184,10 +184,10 @@ declare const stationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
184
184
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
185
185
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
186
186
  pressureTrend: z.ZodNullable<z.ZodEnum<{
187
+ unknown: "unknown";
187
188
  falling: "falling";
188
189
  rising: "rising";
189
190
  steady: "steady";
190
- unknown: "unknown";
191
191
  }>>;
192
192
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
193
193
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -325,10 +325,10 @@ declare const stationFeedSchema: z.ZodObject<{
325
325
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
326
326
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
327
327
  pressureTrend: z.ZodNullable<z.ZodEnum<{
328
+ unknown: "unknown";
328
329
  falling: "falling";
329
330
  rising: "rising";
330
331
  steady: "steady";
331
- unknown: "unknown";
332
332
  }>>;
333
333
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
334
334
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -466,10 +466,10 @@ declare const stationCurrentSchema: z.ZodObject<{
466
466
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
467
467
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
468
468
  pressureTrend: z.ZodNullable<z.ZodEnum<{
469
+ unknown: "unknown";
469
470
  falling: "falling";
470
471
  rising: "rising";
471
472
  steady: "steady";
472
- unknown: "unknown";
473
473
  }>>;
474
474
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
475
475
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -633,10 +633,10 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
633
633
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
634
634
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
635
635
  pressureTrend: z.ZodNullable<z.ZodEnum<{
636
+ unknown: "unknown";
636
637
  falling: "falling";
637
638
  rising: "rising";
638
639
  steady: "steady";
639
- unknown: "unknown";
640
640
  }>>;
641
641
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
642
642
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
@@ -782,10 +782,10 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
782
782
  precipitationRateMmPerHour: z.ZodNullable<z.ZodNumber>;
783
783
  precipitationTodayMm: z.ZodNullable<z.ZodNumber>;
784
784
  pressureTrend: z.ZodNullable<z.ZodEnum<{
785
+ unknown: "unknown";
785
786
  falling: "falling";
786
787
  rising: "rising";
787
788
  steady: "steady";
788
- unknown: "unknown";
789
789
  }>>;
790
790
  relativeHumidityPercent: z.ZodNullable<z.ZodNumber>;
791
791
  seaLevelPressureHpa: z.ZodNullable<z.ZodNumber>;
package/dist/derive.js CHANGED
@@ -161,13 +161,14 @@ function stationFreshnessThresholds(meta) {
161
161
  staleAfterMs: clampMs(currentForMs * 6, 10 * 6e4, 45 * 6e4)
162
162
  };
163
163
  }
164
+ function anchoredAgeMs(input) {
165
+ return Math.max(0, Date.parse(input.servedAt) - Date.parse(input.observedAt)) + Math.max(0, input.nowMs - input.receivedAtMs);
166
+ }
164
167
  function freshness(input, thresholds = DEFAULT_FRESHNESS_THRESHOLDS) {
165
- const ageAtServeMs = Date.parse(input.servedAt) - Date.parse(input.observedAt);
166
- const sinceReceivedMs = Math.max(0, input.nowMs - input.receivedAtMs);
167
- const ageMs = Math.max(0, ageAtServeMs) + sinceReceivedMs;
168
+ const ageMs = anchoredAgeMs(input);
168
169
  if (ageMs <= thresholds.currentForMs) return "live";
169
170
  if (ageMs <= thresholds.staleAfterMs) return "aging";
170
171
  return "stale";
171
172
  }
172
173
  //#endregion
173
- export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
174
+ export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, anchoredAgeMs, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
@@ -180,22 +180,22 @@ function dailyPatternSceneDom(scene) {
180
180
  }, vane.mark.text.text) : hs("path", {
181
181
  class: vane.mark.className,
182
182
  d: vane.mark.d
183
- })), scene.vanes.map((vane) => hs("text", {
183
+ })), scene.vanes.flatMap((vane) => vane.label == null ? [] : [hs("text", {
184
184
  class: vane.label.className,
185
185
  "text-anchor": vane.label.anchor,
186
186
  x: vane.label.x,
187
187
  y: vane.label.y
188
- }, vane.label.text)), hs("text", {
188
+ }, vane.label.text)]), hs("text", {
189
189
  class: scene.rowLabels.avg.className,
190
190
  "text-anchor": scene.rowLabels.avg.anchor,
191
191
  x: scene.rowLabels.avg.x,
192
192
  y: scene.rowLabels.avg.y
193
- }, scene.rowLabels.avg.text), scene.vanes.map((vane) => hs("text", {
193
+ }, scene.rowLabels.avg.text), scene.vanes.flatMap((vane) => vane.value == null ? [] : [hs("text", {
194
194
  class: vane.value.className,
195
195
  "text-anchor": vane.value.anchor,
196
196
  x: vane.value.x,
197
197
  y: vane.value.y
198
- }, vane.value.text)), scene.ticks.map((tick) => hs("text", {
198
+ }, vane.value.text)]), scene.ticks.map((tick) => hs("text", {
199
199
  class: tick.className,
200
200
  "text-anchor": tick.anchor,
201
201
  x: tick.x,
@@ -1,21 +1,25 @@
1
1
  import { requireResolved } from "../../display.js";
2
2
  import { measuredChartWidth } from "../../geometry.js";
3
- import { activeChartIndex, chartIndexAtClient, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
3
+ import { readoutAriaLive } from "../../scene/chart.js";
4
4
  import { TREND_CLASS, trendGate, trendScene } from "../../scene/trend.js";
5
5
  import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
6
6
  import { MeteoStationElement } from "../lib/base.js";
7
7
  import { h, hs } from "../lib/h.js";
8
+ import { PinnedCursor } from "../lib/pinned-cursor.js";
8
9
  //#region src/elements/elements/TrendChartElement.ts
9
10
  var TrendChartElement = class extends MeteoStationElement {
10
11
  static observedAttributes = ["series", "station-id"];
11
12
  #width = null;
12
13
  #observer = null;
13
- #pinnedAt = null;
14
- #previewIndex = null;
15
14
  #scene = null;
16
15
  #readout = null;
17
16
  #svg = null;
18
17
  #hit = null;
18
+ #cursor = new PinnedCursor({
19
+ scene: () => this.#scene,
20
+ svg: () => this.#svg,
21
+ onChange: () => this.#updateCursor()
22
+ });
19
23
  disconnected() {
20
24
  this.#observer?.disconnect();
21
25
  this.#observer = null;
@@ -76,12 +80,9 @@ var TrendChartElement = class extends MeteoStationElement {
76
80
  class: scene.hit.className,
77
81
  fill: scene.hit.fill,
78
82
  height: scene.hit.height,
79
- onclick: (event) => this.#handleClick(event),
80
- onpointerleave: () => {
81
- this.#previewIndex = null;
82
- this.#updateCursor();
83
- },
84
- onpointermove: (event) => this.#handlePointerMove(event),
83
+ onclick: (event) => this.#cursor.handleClick(event),
84
+ onpointerleave: () => this.#cursor.handlePointerLeave(),
85
+ onpointermove: (event) => this.#cursor.handlePointerMove(event),
85
86
  width: scene.hit.width,
86
87
  x: scene.hit.x,
87
88
  y: scene.hit.y
@@ -123,34 +124,14 @@ var TrendChartElement = class extends MeteoStationElement {
123
124
  wrap.replaceChildren(readout, svg);
124
125
  this.#updateCursor();
125
126
  }
126
- #indexAtPoint(clientX) {
127
- const scene = this.#scene;
128
- const svg = this.#svg;
129
- if (scene == null || svg == null) return null;
130
- return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
131
- }
132
- #handlePointerMove(event) {
133
- if (event.pointerType === "touch") return;
134
- this.#previewIndex = this.#indexAtPoint(event.clientX);
135
- this.#updateCursor();
136
- }
137
- #handleClick(event) {
138
- const index = this.#indexAtPoint(event.clientX);
139
- if (index == null) return;
140
- const observedAt = this.#scene?.points[index]?.observedAt;
141
- if (observedAt == null) return;
142
- this.#pinnedAt = togglePinnedAt(this.#pinnedAt, observedAt);
143
- this.#previewIndex = null;
144
- this.#updateCursor();
145
- }
146
127
  #updateCursor() {
147
128
  const scene = this.#scene;
148
129
  const readout = this.#readout;
149
130
  const svg = this.#svg;
150
131
  const hit = this.#hit;
151
132
  if (scene == null || readout == null || svg == null || hit == null) return;
152
- const inspection = scene.inspect(activeChartIndex(scene.points, this.#pinnedAt, this.#previewIndex));
153
- readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
133
+ const inspection = scene.inspect(this.#cursor.activeIndex());
134
+ readout.setAttribute("aria-live", readoutAriaLive(this.#cursor.previewIndex));
154
135
  readout.replaceChildren(h("strong", null, inspection.readout.strong), h("span", null, inspection.readout.span));
155
136
  for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
156
137
  const cursor = inspection.cursor;