@azohra/meteo.station 0.1.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.
Files changed (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/air.d.ts +13 -0
  4. package/dist/air.js +76 -0
  5. package/dist/client/index.d.ts +4 -0
  6. package/dist/client/index.js +4 -0
  7. package/dist/client/poll.d.ts +42 -0
  8. package/dist/client/poll.js +121 -0
  9. package/dist/client/stores.d.ts +46 -0
  10. package/dist/client/stores.js +128 -0
  11. package/dist/client/ticker.d.ts +4 -0
  12. package/dist/client/ticker.js +19 -0
  13. package/dist/contract.d.ts +381 -0
  14. package/dist/contract.js +143 -0
  15. package/dist/derive.d.ts +54 -0
  16. package/dist/derive.js +134 -0
  17. package/dist/display.d.ts +28 -0
  18. package/dist/display.js +27 -0
  19. package/dist/elements/elements/AirMatrixElement.d.ts +14 -0
  20. package/dist/elements/elements/AirMatrixElement.js +83 -0
  21. package/dist/elements/elements/CurrentConditionsElement.d.ts +9 -0
  22. package/dist/elements/elements/CurrentConditionsElement.js +52 -0
  23. package/dist/elements/elements/DailyPatternElement.d.ts +15 -0
  24. package/dist/elements/elements/DailyPatternElement.js +200 -0
  25. package/dist/elements/elements/DialElement.d.ts +9 -0
  26. package/dist/elements/elements/DialElement.js +128 -0
  27. package/dist/elements/elements/FreshnessBadgeElement.d.ts +8 -0
  28. package/dist/elements/elements/FreshnessBadgeElement.js +22 -0
  29. package/dist/elements/elements/SparklineElement.d.ts +9 -0
  30. package/dist/elements/elements/SparklineElement.js +74 -0
  31. package/dist/elements/elements/StationCardElement.d.ts +53 -0
  32. package/dist/elements/elements/StationCardElement.js +211 -0
  33. package/dist/elements/elements/StationFeedElement.d.ts +32 -0
  34. package/dist/elements/elements/StationFeedElement.js +215 -0
  35. package/dist/elements/elements/StationStripElement.d.ts +9 -0
  36. package/dist/elements/elements/StationStripElement.js +43 -0
  37. package/dist/elements/elements/StationTableElement.d.ts +18 -0
  38. package/dist/elements/elements/StationTableElement.js +102 -0
  39. package/dist/elements/elements/TrendChartElement.d.ts +10 -0
  40. package/dist/elements/elements/TrendChartElement.js +174 -0
  41. package/dist/elements/elements/WindArrowElement.d.ts +8 -0
  42. package/dist/elements/elements/WindArrowElement.js +14 -0
  43. package/dist/elements/elements/WindHistoryChartElement.d.ts +10 -0
  44. package/dist/elements/elements/WindHistoryChartElement.js +277 -0
  45. package/dist/elements/elements/WindRoseElement.d.ts +17 -0
  46. package/dist/elements/elements/WindRoseElement.js +106 -0
  47. package/dist/elements/elements/atoms.d.ts +48 -0
  48. package/dist/elements/elements/atoms.js +131 -0
  49. package/dist/elements/index.d.ts +48 -0
  50. package/dist/elements/index.js +57 -0
  51. package/dist/elements/lib/ambient.d.ts +15 -0
  52. package/dist/elements/lib/ambient.js +5 -0
  53. package/dist/elements/lib/attributes.js +21 -0
  54. package/dist/elements/lib/base.d.ts +45 -0
  55. package/dist/elements/lib/base.js +152 -0
  56. package/dist/elements/lib/context.js +28 -0
  57. package/dist/elements/lib/fragments.js +45 -0
  58. package/dist/elements/lib/h.js +35 -0
  59. package/dist/elements/register.d.ts +1 -0
  60. package/dist/elements/register.js +5 -0
  61. package/dist/endpoints.d.ts +5 -0
  62. package/dist/endpoints.js +10 -0
  63. package/dist/fixtures.d.ts +23 -0
  64. package/dist/fixtures.js +67 -0
  65. package/dist/format.d.ts +31 -0
  66. package/dist/format.js +82 -0
  67. package/dist/geometry.d.ts +84 -0
  68. package/dist/geometry.js +333 -0
  69. package/dist/index.d.ts +12 -0
  70. package/dist/index.js +12 -0
  71. package/dist/instruments.d.ts +75 -0
  72. package/dist/instruments.js +173 -0
  73. package/dist/merge-current.d.ts +13 -0
  74. package/dist/merge-current.js +54 -0
  75. package/dist/react/components/AirMatrix.d.ts +11 -0
  76. package/dist/react/components/AirMatrix.js +82 -0
  77. package/dist/react/components/CurrentConditions.d.ts +17 -0
  78. package/dist/react/components/CurrentConditions.js +98 -0
  79. package/dist/react/components/DailyPattern.d.ts +19 -0
  80. package/dist/react/components/DailyPattern.js +212 -0
  81. package/dist/react/components/Dial.d.ts +17 -0
  82. package/dist/react/components/Dial.js +133 -0
  83. package/dist/react/components/FreshnessBadge.d.ts +10 -0
  84. package/dist/react/components/FreshnessBadge.js +20 -0
  85. package/dist/react/components/Sparkline.d.ts +17 -0
  86. package/dist/react/components/Sparkline.js +60 -0
  87. package/dist/react/components/StationCard.d.ts +46 -0
  88. package/dist/react/components/StationCard.js +140 -0
  89. package/dist/react/components/StationFeedProvider.d.ts +27 -0
  90. package/dist/react/components/StationFeedProvider.js +40 -0
  91. package/dist/react/components/StationStrip.d.ts +16 -0
  92. package/dist/react/components/StationStrip.js +84 -0
  93. package/dist/react/components/StationTable.d.ts +18 -0
  94. package/dist/react/components/StationTable.js +115 -0
  95. package/dist/react/components/TrendChart.d.ts +14 -0
  96. package/dist/react/components/TrendChart.js +150 -0
  97. package/dist/react/components/WindArrow.d.ts +7 -0
  98. package/dist/react/components/WindArrow.js +21 -0
  99. package/dist/react/components/WindHistoryChart.d.ts +18 -0
  100. package/dist/react/components/WindHistoryChart.js +278 -0
  101. package/dist/react/components/WindRose.d.ts +17 -0
  102. package/dist/react/components/WindRose.js +99 -0
  103. package/dist/react/components/atoms.d.ts +33 -0
  104. package/dist/react/components/atoms.js +136 -0
  105. package/dist/react/hooks/useFreshness.d.ts +6 -0
  106. package/dist/react/hooks/useFreshness.js +21 -0
  107. package/dist/react/hooks/usePolledJson.js +17 -0
  108. package/dist/react/hooks/useStation.d.ts +23 -0
  109. package/dist/react/hooks/useStation.js +42 -0
  110. package/dist/react/hooks/useStationCurrent.d.ts +23 -0
  111. package/dist/react/hooks/useStationCurrent.js +32 -0
  112. package/dist/react/hooks/useStationFeed.d.ts +22 -0
  113. package/dist/react/hooks/useStationFeed.js +28 -0
  114. package/dist/react/index.d.ts +20 -0
  115. package/dist/react/index.js +21 -0
  116. package/dist/react/lib/cells.js +29 -0
  117. package/dist/scene/air-matrix.js +71 -0
  118. package/dist/scene/atoms.js +102 -0
  119. package/dist/scene/card.js +54 -0
  120. package/dist/scene/chart.js +28 -0
  121. package/dist/scene/current.js +66 -0
  122. package/dist/scene/daily-pattern.js +81 -0
  123. package/dist/scene/dial.js +141 -0
  124. package/dist/scene/glyphs.js +24 -0
  125. package/dist/scene/rose.js +120 -0
  126. package/dist/scene/sparkline.js +73 -0
  127. package/dist/scene/strip.js +63 -0
  128. package/dist/scene/table.js +76 -0
  129. package/dist/scene/trend.js +160 -0
  130. package/dist/scene/wind-history.js +148 -0
  131. package/dist/scene/wind-plot.js +214 -0
  132. package/dist/server/adapter.d.ts +28 -0
  133. package/dist/server/adapter.js +32 -0
  134. package/dist/server/adapters/campbell.d.ts +112 -0
  135. package/dist/server/adapters/campbell.js +414 -0
  136. package/dist/server/adapters/tempest.d.ts +27 -0
  137. package/dist/server/adapters/tempest.js +137 -0
  138. package/dist/server/adapters/windnerd.d.ts +39 -0
  139. package/dist/server/adapters/windnerd.js +159 -0
  140. package/dist/server/config.d.ts +135 -0
  141. package/dist/server/config.js +57 -0
  142. package/dist/server/environment.d.ts +48 -0
  143. package/dist/server/environment.js +128 -0
  144. package/dist/server/feed.d.ts +31 -0
  145. package/dist/server/feed.js +216 -0
  146. package/dist/server/handler.d.ts +17 -0
  147. package/dist/server/handler.js +133 -0
  148. package/dist/server/index.d.ts +10 -0
  149. package/dist/server/index.js +10 -0
  150. package/dist/strings.d.ts +118 -0
  151. package/dist/strings.js +237 -0
  152. package/dist/windnerd.d.ts +5 -0
  153. package/dist/windnerd.js +25 -0
  154. package/package.json +97 -0
  155. package/schema/README.md +14 -0
  156. package/schema/example-current.json +48 -0
  157. package/schema/example-feed.json +147 -0
  158. package/schema/stationcurrent.schema.json +641 -0
  159. package/schema/stationfeed.schema.json +656 -0
  160. package/styles.css +1141 -0
@@ -0,0 +1,136 @@
1
+ "use client";
2
+ import { resolveDisplay } from "../../display.js";
3
+ import { subscribeTicker } from "../../client/ticker.js";
4
+ import { bandChipScene, directionAtomScene, pressureAtomScene, speedAtomScene, temperatureAtomScene, updatedAtScene } from "../../scene/atoms.js";
5
+ import { requireResolved, resolveStation, useStationFeedContext } from "./StationFeedProvider.js";
6
+ import { DirectionCell } from "../lib/cells.js";
7
+ import { useEffect, useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ //#region src/react/components/atoms.tsx
10
+ function useResolvedStation(component, stationProp, stationId) {
11
+ const context = useStationFeedContext();
12
+ return {
13
+ context,
14
+ station: requireResolved(component, "station", stationProp ?? resolveStation(context, stationId))
15
+ };
16
+ }
17
+ function ValueAtom({ scene }) {
18
+ return /* @__PURE__ */ jsx("data", {
19
+ className: scene.className,
20
+ value: scene.value,
21
+ children: scene.content.kind === "dash" ? scene.content.text : /* @__PURE__ */ jsxs(Fragment, { children: [scene.content.text, /* @__PURE__ */ jsx("span", {
22
+ className: scene.content.unit.className,
23
+ children: scene.content.unit.text
24
+ })] })
25
+ });
26
+ }
27
+ function SpeedValue({ component, kind, station: stationProp, stationId, unit: unitProp, strings: stringsProp }) {
28
+ const { context, station } = useResolvedStation(component, stationProp, stationId);
29
+ const { unit, words } = resolveDisplay(context, {
30
+ strings: stringsProp,
31
+ unit: unitProp
32
+ });
33
+ return /* @__PURE__ */ jsx(ValueAtom, { scene: speedAtomScene(station, kind, unit, words) });
34
+ }
35
+ function Speed(props) {
36
+ return /* @__PURE__ */ jsx(SpeedValue, {
37
+ component: "Speed",
38
+ kind: "average",
39
+ ...props
40
+ });
41
+ }
42
+ function Gust(props) {
43
+ return /* @__PURE__ */ jsx(SpeedValue, {
44
+ component: "Gust",
45
+ kind: "gust",
46
+ ...props
47
+ });
48
+ }
49
+ function Lull(props) {
50
+ return /* @__PURE__ */ jsx(SpeedValue, {
51
+ component: "Lull",
52
+ kind: "lull",
53
+ ...props
54
+ });
55
+ }
56
+ function Temperature({ station: stationProp, stationId, strings: stringsProp }) {
57
+ const { context, station } = useResolvedStation("Temperature", stationProp, stationId);
58
+ const { words } = resolveDisplay(context, { strings: stringsProp });
59
+ return /* @__PURE__ */ jsx(ValueAtom, { scene: temperatureAtomScene(station, words) });
60
+ }
61
+ function Pressure({ station: stationProp, stationId, strings: stringsProp }) {
62
+ const { context, station } = useResolvedStation("Pressure", stationProp, stationId);
63
+ const { words } = resolveDisplay(context, { strings: stringsProp });
64
+ return /* @__PURE__ */ jsx(ValueAtom, { scene: pressureAtomScene(station, words) });
65
+ }
66
+ function Direction({ station: stationProp, stationId, strings: stringsProp }) {
67
+ const { context, station } = useResolvedStation("Direction", stationProp, stationId);
68
+ const { words } = resolveDisplay(context, { strings: stringsProp });
69
+ const scene = directionAtomScene(station, words);
70
+ if (scene.cell == null) return /* @__PURE__ */ jsx("span", {
71
+ className: scene.className,
72
+ children: scene.dashText
73
+ });
74
+ return /* @__PURE__ */ jsx("span", {
75
+ "aria-label": scene.ariaLabel,
76
+ className: scene.className,
77
+ children: /* @__PURE__ */ jsx(DirectionCell, {
78
+ windAvgMps: scene.cell.windAvgMps,
79
+ windDirectionDeg: scene.cell.windDirectionDeg,
80
+ words
81
+ })
82
+ });
83
+ }
84
+ function UpdatedAt({ station: stationProp, stationId, servedAt: servedAtProp, receivedAtMs: receivedAtMsProp, strings: stringsProp, formatTime: formatTimeProp }) {
85
+ const { context, station } = useResolvedStation("UpdatedAt", stationProp, stationId);
86
+ const servedAt = servedAtProp ?? context?.feed?.servedAt ?? null;
87
+ const receivedAtMs = receivedAtMsProp !== void 0 ? receivedAtMsProp : context?.receivedAtMs ?? null;
88
+ const { formatTime, words } = resolveDisplay(context, {
89
+ formatTime: formatTimeProp,
90
+ strings: stringsProp
91
+ });
92
+ const [nowMs, setNowMs] = useState(() => receivedAtMs ?? Date.now());
93
+ useEffect(() => {
94
+ setNowMs(Date.now());
95
+ return subscribeTicker(() => setNowMs(Date.now()));
96
+ }, []);
97
+ const scene = updatedAtScene({
98
+ formatTime,
99
+ nowMs,
100
+ receivedAtMs,
101
+ servedAt,
102
+ station,
103
+ words
104
+ });
105
+ if (scene.kind === "dash") return /* @__PURE__ */ jsx("span", {
106
+ className: scene.className,
107
+ children: scene.text
108
+ });
109
+ return /* @__PURE__ */ jsx("time", {
110
+ className: scene.className,
111
+ dateTime: scene.dateTime,
112
+ children: scene.text
113
+ });
114
+ }
115
+ function BandChip({ station: stationProp, stationId, thresholds: thresholdsProp, labels, unit: unitProp, strings: stringsProp }) {
116
+ const { context, station } = useResolvedStation("BandChip", stationProp, stationId);
117
+ const { thresholds, unit, words } = resolveDisplay(context, {
118
+ strings: stringsProp,
119
+ thresholds: thresholdsProp,
120
+ unit: unitProp
121
+ });
122
+ const scene = bandChipScene({
123
+ labels,
124
+ station,
125
+ thresholds,
126
+ unit,
127
+ words
128
+ });
129
+ return /* @__PURE__ */ jsx("span", {
130
+ className: scene.className,
131
+ "data-band": scene.band,
132
+ children: scene.text
133
+ });
134
+ }
135
+ //#endregion
136
+ export { BandChip, Direction, Gust, Lull, Pressure, Speed, Temperature, UpdatedAt };
@@ -0,0 +1,6 @@
1
+ import { FreshnessStatus, FreshnessThresholds } from "../../derive.js";
2
+ import "../../index.js";
3
+ //#region src/react/hooks/useFreshness.d.ts
4
+ declare function useFreshness(observedAt: string | null | undefined, servedAt: string | null | undefined, receivedAtMs: number | null | undefined, thresholds?: FreshnessThresholds): FreshnessStatus | null;
5
+ //#endregion
6
+ export { useFreshness };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { freshness } from "../../derive.js";
3
+ import { subscribeTicker } from "../../client/ticker.js";
4
+ import { useEffect, useState } from "react";
5
+ //#region src/react/hooks/useFreshness.ts
6
+ function useFreshness(observedAt, servedAt, receivedAtMs, thresholds) {
7
+ const [nowMs, setNowMs] = useState(() => receivedAtMs ?? Date.now());
8
+ useEffect(() => {
9
+ setNowMs(Date.now());
10
+ return subscribeTicker(() => setNowMs(Date.now()));
11
+ }, []);
12
+ if (observedAt == null || servedAt == null || receivedAtMs == null) return null;
13
+ return freshness({
14
+ observedAt,
15
+ servedAt,
16
+ receivedAtMs,
17
+ nowMs
18
+ }, thresholds);
19
+ }
20
+ //#endregion
21
+ export { useFreshness };
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useSyncExternalStore } from "react";
3
+ //#region src/react/hooks/usePolledJson.ts
4
+ function usePoller(poller, enabled) {
5
+ const snapshot = useSyncExternalStore(poller.subscribe, poller.getSnapshot, poller.getSnapshot);
6
+ useEffect(() => {
7
+ if (!enabled) return;
8
+ poller.start();
9
+ return () => poller.stop();
10
+ }, [poller, enabled]);
11
+ return {
12
+ snapshot,
13
+ refresh: useCallback(() => poller.refresh(), [poller])
14
+ };
15
+ }
16
+ //#endregion
17
+ export { usePoller };
@@ -0,0 +1,23 @@
1
+ import { PollError } from "../../client/poll.js";
2
+ import { Station, StationFeed } from "../../contract.js";
3
+ import "../../client/index.js";
4
+ import "../../index.js";
5
+ //#region src/react/hooks/useStation.d.ts
6
+ declare function useStation(url: string, stationId: string, options?: {
7
+ pollSeconds?: number;
8
+ currentPollSeconds?: number;
9
+ enabled?: boolean;
10
+ fetchInit?: RequestInit;
11
+ initialData?: {
12
+ feed: StationFeed;
13
+ receivedAtMs: number;
14
+ };
15
+ }): {
16
+ feed: StationFeed | null;
17
+ station: Station | null;
18
+ receivedAtMs: number | null;
19
+ error: PollError | null;
20
+ refresh: () => void;
21
+ };
22
+ //#endregion
23
+ export { useStation };
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { foldCurrent } from "../../merge-current.js";
3
+ import { useStationCurrent } from "./useStationCurrent.js";
4
+ import { useStationFeed } from "./useStationFeed.js";
5
+ import { useCallback, useMemo } from "react";
6
+ //#region src/react/hooks/useStation.ts
7
+ function useStation(url, stationId, options = {}) {
8
+ const { pollSeconds, currentPollSeconds, enabled = true, fetchInit, initialData } = options;
9
+ const feedResult = useStationFeed(url, {
10
+ ...pollSeconds != null ? { pollSeconds } : {},
11
+ enabled,
12
+ ...fetchInit != null ? { fetchInit } : {},
13
+ ...initialData != null ? { initialData } : {}
14
+ });
15
+ const currentResult = useStationCurrent(url, stationId, {
16
+ ...currentPollSeconds != null ? { pollSeconds: currentPollSeconds } : {},
17
+ enabled,
18
+ ...fetchInit != null ? { fetchInit } : {}
19
+ });
20
+ const merged = useMemo(() => foldCurrent(feedResult.feed, feedResult.receivedAtMs, currentResult.current, currentResult.receivedAtMs), [
21
+ feedResult.feed,
22
+ feedResult.receivedAtMs,
23
+ currentResult.current,
24
+ currentResult.receivedAtMs
25
+ ]);
26
+ const station = merged.feed?.stations.find((entry) => entry.id === stationId) ?? null;
27
+ const feedRefresh = feedResult.refresh;
28
+ const currentRefresh = currentResult.refresh;
29
+ const refresh = useCallback(() => {
30
+ feedRefresh();
31
+ currentRefresh();
32
+ }, [feedRefresh, currentRefresh]);
33
+ return {
34
+ feed: merged.feed,
35
+ station,
36
+ receivedAtMs: merged.receivedAtMs,
37
+ error: feedResult.error ?? currentResult.error,
38
+ refresh
39
+ };
40
+ }
41
+ //#endregion
42
+ export { useStation };
@@ -0,0 +1,23 @@
1
+ import { PollError } from "../../client/poll.js";
2
+ import { Station, StationCurrent } from "../../contract.js";
3
+ import "../../client/index.js";
4
+ import "../../index.js";
5
+ //#region src/react/hooks/useStationCurrent.d.ts
6
+ declare function useStationCurrent(url: string, stationId: string, options?: {
7
+ pollSeconds?: number;
8
+ enabled?: boolean;
9
+ fetchInit?: RequestInit;
10
+ initialData?: {
11
+ current: StationCurrent;
12
+ receivedAtMs: number;
13
+ };
14
+ }): {
15
+ current: StationCurrent | null;
16
+ station: Station | null;
17
+ servedAt: string | null;
18
+ error: PollError | null;
19
+ receivedAtMs: number | null;
20
+ refresh: () => void;
21
+ };
22
+ //#endregion
23
+ export { useStationCurrent };
@@ -0,0 +1,32 @@
1
+ "use client";
2
+ import { createStationCurrentStore } from "../../client/stores.js";
3
+ import { usePoller } from "./usePolledJson.js";
4
+ import { useMemo, useRef } from "react";
5
+ //#region src/react/hooks/useStationCurrent.ts
6
+ function useStationCurrent(url, stationId, options = {}) {
7
+ const { pollSeconds, enabled = true, fetchInit, initialData } = options;
8
+ const fetchInitRef = useRef(fetchInit);
9
+ fetchInitRef.current = fetchInit;
10
+ const initialRef = useRef(initialData);
11
+ const mountUrlRef = useRef(url);
12
+ const mountStationRef = useRef(stationId);
13
+ const { snapshot, refresh } = usePoller(useMemo(() => createStationCurrentStore(url, stationId, {
14
+ ...pollSeconds != null ? { pollSeconds } : {},
15
+ fetchInit: () => fetchInitRef.current,
16
+ ...url === mountUrlRef.current && stationId === mountStationRef.current && initialRef.current != null ? { initial: initialRef.current } : {}
17
+ }), [
18
+ url,
19
+ stationId,
20
+ pollSeconds
21
+ ]), enabled);
22
+ return {
23
+ current: snapshot.data,
24
+ station: snapshot.data?.station ?? null,
25
+ servedAt: snapshot.data?.servedAt ?? null,
26
+ error: snapshot.error,
27
+ receivedAtMs: snapshot.receivedAtMs,
28
+ refresh
29
+ };
30
+ }
31
+ //#endregion
32
+ export { useStationCurrent };
@@ -0,0 +1,22 @@
1
+ import { PollError } from "../../client/poll.js";
2
+ import { StationFeed } from "../../contract.js";
3
+ import "../../client/index.js";
4
+ import "../../index.js";
5
+ //#region src/react/hooks/useStationFeed.d.ts
6
+ declare function useStationFeed(url: string, options?: {
7
+ pollSeconds?: number;
8
+ enabled?: boolean;
9
+ fetchInit?: RequestInit;
10
+ initialData?: {
11
+ feed: StationFeed;
12
+ servedAt?: string;
13
+ receivedAtMs: number;
14
+ };
15
+ }): {
16
+ feed: StationFeed | null;
17
+ error: PollError | null;
18
+ receivedAtMs: number | null;
19
+ refresh: () => void;
20
+ };
21
+ //#endregion
22
+ export { useStationFeed };
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { createStationFeedStore } from "../../client/stores.js";
3
+ import { usePoller } from "./usePolledJson.js";
4
+ import { useMemo, useRef } from "react";
5
+ //#region src/react/hooks/useStationFeed.ts
6
+ function useStationFeed(url, options = {}) {
7
+ const { pollSeconds, enabled = true, fetchInit, initialData } = options;
8
+ const fetchInitRef = useRef(fetchInit);
9
+ fetchInitRef.current = fetchInit;
10
+ const initialRef = useRef(initialData);
11
+ const mountUrlRef = useRef(url);
12
+ const { snapshot, refresh } = usePoller(useMemo(() => createStationFeedStore(url, {
13
+ ...pollSeconds != null ? { pollSeconds } : {},
14
+ fetchInit: () => fetchInitRef.current,
15
+ ...url === mountUrlRef.current && initialRef.current != null ? { initial: {
16
+ feed: initialRef.current.feed,
17
+ receivedAtMs: initialRef.current.receivedAtMs
18
+ } } : {}
19
+ }), [url, pollSeconds]), enabled);
20
+ return {
21
+ feed: snapshot.data,
22
+ error: snapshot.error,
23
+ receivedAtMs: snapshot.receivedAtMs,
24
+ refresh
25
+ };
26
+ }
27
+ //#endregion
28
+ export { useStationFeed };
@@ -0,0 +1,20 @@
1
+ import { AirMatrix } from "./components/AirMatrix.js";
2
+ import { BandChip, Direction, Gust, Lull, Pressure, Speed, Temperature, UpdatedAt } from "./components/atoms.js";
3
+ import { CurrentConditions } from "./components/CurrentConditions.js";
4
+ import { Dial } from "./components/Dial.js";
5
+ import { FreshnessBadge } from "./components/FreshnessBadge.js";
6
+ import { Sparkline } from "./components/Sparkline.js";
7
+ import { StationMetaRenderer, StationTable } from "./components/StationTable.js";
8
+ import { StationFeedContextValue, StationFeedProvider, useStationFeedContext } from "./components/StationFeedProvider.js";
9
+ import { StationStrip } from "./components/StationStrip.js";
10
+ import { TrendChart } from "./components/TrendChart.js";
11
+ import { WindArrow } from "./components/WindArrow.js";
12
+ import { DailyPattern } from "./components/DailyPattern.js";
13
+ import { WindHistoryChart } from "./components/WindHistoryChart.js";
14
+ import { WindRose } from "./components/WindRose.js";
15
+ import { StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary } from "./components/StationCard.js";
16
+ import { useFreshness } from "./hooks/useFreshness.js";
17
+ import { useStation } from "./hooks/useStation.js";
18
+ import { useStationCurrent } from "./hooks/useStationCurrent.js";
19
+ import { useStationFeed } from "./hooks/useStationFeed.js";
20
+ export { AirMatrix, BandChip, CurrentConditions, DailyPattern, Dial, Direction, FreshnessBadge, Gust, Lull, Pressure, Sparkline, Speed, StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary, type StationFeedContextValue, StationFeedProvider, type StationMetaRenderer, StationStrip, StationTable, Temperature, TrendChart, UpdatedAt, WindArrow, WindHistoryChart, WindRose, useFreshness, useStation, useStationCurrent, useStationFeed, useStationFeedContext };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { StationFeedProvider, useStationFeedContext } from "./components/StationFeedProvider.js";
3
+ import { AirMatrix } from "./components/AirMatrix.js";
4
+ import { WindArrow } from "./components/WindArrow.js";
5
+ import { BandChip, Direction, Gust, Lull, Pressure, Speed, Temperature, UpdatedAt } from "./components/atoms.js";
6
+ import { useFreshness } from "./hooks/useFreshness.js";
7
+ import { Dial } from "./components/Dial.js";
8
+ import { FreshnessBadge } from "./components/FreshnessBadge.js";
9
+ import { CurrentConditions } from "./components/CurrentConditions.js";
10
+ import { Sparkline } from "./components/Sparkline.js";
11
+ import { StationTable } from "./components/StationTable.js";
12
+ import { StationStrip } from "./components/StationStrip.js";
13
+ import { TrendChart } from "./components/TrendChart.js";
14
+ import { DailyPattern } from "./components/DailyPattern.js";
15
+ import { WindHistoryChart } from "./components/WindHistoryChart.js";
16
+ import { WindRose } from "./components/WindRose.js";
17
+ import { StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary } from "./components/StationCard.js";
18
+ import { useStationCurrent } from "./hooks/useStationCurrent.js";
19
+ import { useStationFeed } from "./hooks/useStationFeed.js";
20
+ import { useStation } from "./hooks/useStation.js";
21
+ export { AirMatrix, BandChip, CurrentConditions, DailyPattern, Dial, Direction, FreshnessBadge, Gust, Lull, Pressure, Sparkline, Speed, StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary, StationFeedProvider, StationStrip, StationTable, Temperature, TrendChart, UpdatedAt, WindArrow, WindHistoryChart, WindRose, useFreshness, useStation, useStationCurrent, useStationFeed, useStationFeedContext };
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { directionCell } from "../../format.js";
3
+ import { WindArrow } from "../components/WindArrow.js";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/react/lib/cells.tsx
6
+ function DirectionCell({ windAvgMps, windDirectionDeg, words }) {
7
+ const cell = directionCell(windAvgMps, windDirectionDeg);
8
+ if (cell.kind === "calm") return /* @__PURE__ */ jsx(Fragment, { children: words.calm });
9
+ if (cell.kind === "dash") return /* @__PURE__ */ jsx(Fragment, { children: "—" });
10
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
11
+ /* @__PURE__ */ jsx(WindArrow, { deg: cell.deg }),
12
+ " ",
13
+ cell.compass,
14
+ " ",
15
+ cell.rounded,
16
+ "°"
17
+ ] });
18
+ }
19
+ function StationNameLink({ station }) {
20
+ if (station.pageUrl == null) return /* @__PURE__ */ jsx(Fragment, { children: station.name });
21
+ return /* @__PURE__ */ jsx("a", {
22
+ href: station.pageUrl,
23
+ rel: "noreferrer",
24
+ target: "_blank",
25
+ children: station.name
26
+ });
27
+ }
28
+ //#endregion
29
+ export { DirectionCell, StationNameLink };
@@ -0,0 +1,71 @@
1
+ import { airRows, airSummary, lastStrikeWords } from "../air.js";
2
+ //#region src/scene/air-matrix.ts
3
+ function airMatrixScene(input) {
4
+ const { formatTime, stations, words } = input;
5
+ const capable = stations.filter((station) => station.capabilities.conditions);
6
+ if (capable.length === 0) return null;
7
+ const firstConditions = capable.map((station) => station.reading?.conditions ?? null).find((conditions) => conditions != null) ?? null;
8
+ const cellsOf = (value) => capable.map((station) => ({
9
+ key: station.id,
10
+ className: "meteo-air-cell",
11
+ text: value(station) ?? "—"
12
+ }));
13
+ const feelsLikeRows = capable.some((station) => station.reading?.windChillC != null) ? [{
14
+ key: words.air.feelsLike,
15
+ className: "meteo-air-row",
16
+ labelClassName: "meteo-air-label",
17
+ label: words.air.feelsLike,
18
+ unit: words.degC,
19
+ cells: cellsOf((station) => station.reading?.windChillC?.toFixed(1) ?? null)
20
+ }] : [];
21
+ const conditionRows = airRows(words).filter((row) => capable.some((station) => {
22
+ const conditions = station.reading?.conditions;
23
+ return conditions != null && row.value(conditions) != null;
24
+ })).map((row) => ({
25
+ key: row.label,
26
+ className: "meteo-air-row",
27
+ labelClassName: "meteo-air-label",
28
+ label: row.label,
29
+ unit: row.unit,
30
+ cells: cellsOf((station) => {
31
+ const conditions = station.reading?.conditions;
32
+ return conditions == null ? null : row.value(conditions);
33
+ })
34
+ }));
35
+ return {
36
+ className: "meteo-air",
37
+ trigger: {
38
+ className: "meteo-air-trigger",
39
+ title: {
40
+ className: "meteo-air-title",
41
+ text: words.air.title
42
+ },
43
+ summary: {
44
+ className: "meteo-air-summary",
45
+ text: firstConditions == null ? words.air.summaryFallback : airSummary(firstConditions, words)
46
+ }
47
+ },
48
+ panelClassName: "meteo-air-panel",
49
+ matrix: {
50
+ ariaLabel: words.aria.air(capable.length),
51
+ className: "meteo-air-matrix",
52
+ gridTemplateColumns: `minmax(7.5rem, 1.4fr) repeat(${capable.length}, minmax(4.5rem, 1fr))`,
53
+ head: {
54
+ className: "meteo-air-row meteo-air-head",
55
+ corner: { className: "meteo-air-corner" },
56
+ columnClassName: "meteo-microlabel",
57
+ columns: capable.map((station) => ({
58
+ key: station.id,
59
+ text: station.name
60
+ }))
61
+ },
62
+ rows: [...feelsLikeRows, ...conditionRows]
63
+ },
64
+ note: {
65
+ className: "meteo-air-note",
66
+ text: firstConditions == null ? words.air.noStrike : lastStrikeWords(firstConditions, formatTime, words)
67
+ }
68
+ };
69
+ }
70
+ //#endregion
71
+ export { airMatrixScene };
@@ -0,0 +1,102 @@
1
+ import { compassDirection, isCalm, thresholdsToMps } from "../derive.js";
2
+ import { readingAgeMs, roundSpeed, speedMpsOf, temperatureValue, updatedAtText } from "../format.js";
3
+ import { speedBand } from "../geometry.js";
4
+ //#region src/scene/atoms.ts
5
+ const valueContent = (value, shown, unitWord) => value == null ? {
6
+ kind: "dash",
7
+ text: "—"
8
+ } : {
9
+ kind: "value",
10
+ text: `${shown(value)} `,
11
+ unit: {
12
+ className: "meteo-unit",
13
+ text: unitWord
14
+ }
15
+ };
16
+ function speedAtomScene(station, kind, unit, words) {
17
+ const mps = speedMpsOf(station, kind);
18
+ return {
19
+ className: "meteo-value meteo-speed",
20
+ value: mps ?? void 0,
21
+ content: valueContent(mps, (value) => String(roundSpeed(value, unit)), words.speedUnits[unit])
22
+ };
23
+ }
24
+ function temperatureAtomScene(station, words) {
25
+ const celsius = station.status === "ok" && station.capabilities.temperature ? station.reading.temperatureC : null;
26
+ return {
27
+ className: "meteo-value meteo-temperature",
28
+ value: celsius ?? void 0,
29
+ content: valueContent(celsius, temperatureValue, words.degC)
30
+ };
31
+ }
32
+ function pressureAtomScene(station, words) {
33
+ const hpa = station.status === "ok" && station.capabilities.conditions ? station.reading.conditions?.seaLevelPressureHpa ?? null : null;
34
+ return {
35
+ className: "meteo-value meteo-pressure",
36
+ value: hpa ?? void 0,
37
+ content: valueContent(hpa, (value) => value.toFixed(1), words.air.unitHpa)
38
+ };
39
+ }
40
+ function directionAtomScene(station, words) {
41
+ const reading = station.status === "ok" ? station.reading : null;
42
+ if (reading == null) return {
43
+ className: "meteo-direction",
44
+ ariaLabel: void 0,
45
+ cell: null,
46
+ dashText: "—"
47
+ };
48
+ const bearingDeg = isCalm(reading.windAvgMps) ? null : reading.windDirectionDeg;
49
+ const point = bearingDeg == null ? null : compassDirection(bearingDeg);
50
+ return {
51
+ className: "meteo-direction",
52
+ ariaLabel: point == null || bearingDeg == null ? void 0 : words.aria.direction(words.compassSpoken[point], Math.round(bearingDeg)),
53
+ cell: {
54
+ windAvgMps: reading.windAvgMps,
55
+ windDirectionDeg: reading.windDirectionDeg
56
+ },
57
+ dashText: "—"
58
+ };
59
+ }
60
+ function updatedAtScene(input) {
61
+ const { formatTime, nowMs, receivedAtMs, servedAt, station, words } = input;
62
+ const reading = station.status === "ok" ? station.reading : null;
63
+ if (reading == null) return {
64
+ kind: "dash",
65
+ className: "meteo-updated",
66
+ text: "—"
67
+ };
68
+ const ageMs = readingAgeMs({
69
+ observedAt: reading.observedAt,
70
+ servedAt,
71
+ receivedAtMs,
72
+ nowMs
73
+ });
74
+ return {
75
+ kind: "time",
76
+ className: "meteo-updated",
77
+ dateTime: reading.observedAt,
78
+ text: updatedAtText(ageMs, reading.observedAt, words, formatTime)
79
+ };
80
+ }
81
+ function bandChipScene(input) {
82
+ const { labels, station, thresholds, unit, words } = input;
83
+ const reading = station.status === "ok" ? station.reading : null;
84
+ if (reading != null && isCalm(reading.windAvgMps)) return {
85
+ className: "meteo-band-chip",
86
+ band: void 0,
87
+ text: words.calm
88
+ };
89
+ if (reading == null || thresholds == null) return {
90
+ className: "meteo-band-chip",
91
+ band: void 0,
92
+ text: "—"
93
+ };
94
+ const band = speedBand(reading.windAvgMps, thresholdsToMps(thresholds));
95
+ return {
96
+ className: "meteo-band-chip",
97
+ band,
98
+ text: labels?.[band] ?? `${roundSpeed(reading.windAvgMps, unit)} ${words.speedUnits[unit]}`
99
+ };
100
+ }
101
+ //#endregion
102
+ export { bandChipScene, directionAtomScene, pressureAtomScene, speedAtomScene, temperatureAtomScene, updatedAtScene };
@@ -0,0 +1,54 @@
1
+ import { summaryEntries } from "../format.js";
2
+ //#region src/scene/card.ts
3
+ const STATION_CARD_CLASS = "meteo-station-card";
4
+ function cardPartThresholds(own, card) {
5
+ return (own === void 0 ? card : own ?? void 0) ?? null;
6
+ }
7
+ function cardPartWiringError(part, provider) {
8
+ return `${part} must render inside ${provider} — the provider carries the station, clocks, and display settings.`;
9
+ }
10
+ function cardHeaderScene(station, words) {
11
+ return {
12
+ className: "meteo-station-card-header",
13
+ identity: {
14
+ className: "meteo-station-card-identity",
15
+ name: {
16
+ className: "meteo-station-card-name",
17
+ link: station.pageUrl == null ? null : {
18
+ href: station.pageUrl,
19
+ rel: "noreferrer",
20
+ target: "_blank",
21
+ text: `${station.name} ↗`
22
+ },
23
+ text: station.name
24
+ },
25
+ meta: {
26
+ className: "meteo-station-card-meta",
27
+ source: {
28
+ className: "meteo-station-card-source",
29
+ text: station.sourceLabel
30
+ },
31
+ elevation: station.elevationM == null ? null : {
32
+ className: "meteo-station-card-elevation",
33
+ text: ` · ${words.elevation(Math.round(station.elevationM))}`
34
+ }
35
+ }
36
+ }
37
+ };
38
+ }
39
+ function summaryScene(station, unit, words, formatTime) {
40
+ const summary = summaryEntries(station, unit, words, formatTime);
41
+ if (summary == null) return null;
42
+ return {
43
+ ariaLabel: words.aria.summary(formatTime(new Date(summary.periodEndedAt))),
44
+ className: "meteo-summary",
45
+ itemClassName: "meteo-summary-item",
46
+ labelClassName: "meteo-microlabel",
47
+ items: summary.entries.map((entry) => ({
48
+ label: entry.label,
49
+ value: entry.value
50
+ }))
51
+ };
52
+ }
53
+ //#endregion
54
+ export { STATION_CARD_CLASS, cardHeaderScene, cardPartThresholds, cardPartWiringError, summaryScene };