@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,15 @@
1
+ import { StationFeed } from "../../contract.js";
2
+ import { SpeedThresholds, SpeedUnit } from "../../derive.js";
3
+ import { FormatTime, StationStringOverrides } from "../../strings.js";
4
+ import "../../index.js";
5
+ //#region src/elements/lib/ambient.d.ts
6
+ type AmbientStationFeed = {
7
+ feed: StationFeed | null;
8
+ receivedAtMs: number | null;
9
+ strings: StationStringOverrides | undefined;
10
+ unit: SpeedUnit | undefined;
11
+ formatTime: FormatTime | undefined;
12
+ thresholds: SpeedThresholds | undefined;
13
+ };
14
+ //#endregion
15
+ export { AmbientStationFeed };
@@ -0,0 +1,5 @@
1
+ //#region src/elements/lib/ambient.ts
2
+ const STATION_FEED_CONTEXT_KEY = "station-feed";
3
+ const ELEMENTS_AMBIENT_HINT = "render inside <meteo-station-feed> with a feed";
4
+ //#endregion
5
+ export { ELEMENTS_AMBIENT_HINT, STATION_FEED_CONTEXT_KEY };
@@ -0,0 +1,21 @@
1
+ import { SPEED_UNITS } from "../../derive.js";
2
+ //#region src/elements/lib/attributes.ts
3
+ function numberAttribute(value) {
4
+ if (value == null || value.trim() === "") return void 0;
5
+ const parsed = Number(value);
6
+ return Number.isFinite(parsed) ? parsed : void 0;
7
+ }
8
+ function unitAttribute(value) {
9
+ return value != null && SPEED_UNITS.includes(value) ? value : void 0;
10
+ }
11
+ function parseThresholdsAttribute(value) {
12
+ if (value == null) return void 0;
13
+ if (value.trim() === "none") return null;
14
+ try {
15
+ const parsed = JSON.parse(value);
16
+ if (typeof parsed === "object" && parsed != null && SPEED_UNITS.includes(parsed.unit) && Array.isArray(parsed.values) && parsed.values.every((bound) => typeof bound === "number" && Number.isFinite(bound))) return parsed;
17
+ } catch {}
18
+ console.warn(`meteo: invalid thresholds attribute ${JSON.stringify(value)} — expected '{"unit":"kmh","values":[12,20,28]}' or "none"; treating as absent.`);
19
+ }
20
+ //#endregion
21
+ export { numberAttribute, parseThresholdsAttribute, unitAttribute };
@@ -0,0 +1,45 @@
1
+ import { Station } from "../../contract.js";
2
+ import { FreshnessStatus, SpeedThresholds } from "../../derive.js";
3
+ import { FormatTime, StationStringOverrides } from "../../strings.js";
4
+ import { ResolvedDisplay } from "../../display.js";
5
+ import "../../index.js";
6
+ import { AmbientStationFeed } from "./ambient.js";
7
+ //#region src/elements/lib/base.d.ts
8
+ declare abstract class MeteoElement extends HTMLElement {
9
+ #private;
10
+ connectedCallback(): void;
11
+ disconnectedCallback(): void;
12
+ attributeChangedCallback(_name: string, _oldValue: string | null, _newValue: string | null): void;
13
+ requestRender(): void;
14
+ protected ambient(): AmbientStationFeed | null;
15
+ protected addCleanup(cleanup: () => void): void;
16
+ protected upgradeProperty(name: string): void;
17
+ protected resolveRequiredStation(component: string, stationProp: Station | undefined): Station;
18
+ protected connected(): void;
19
+ protected disconnected(): void;
20
+ protected abstract render(): void;
21
+ }
22
+ declare abstract class MeteoStationElement extends MeteoElement {
23
+ #private;
24
+ constructor();
25
+ get station(): Station | undefined;
26
+ set station(value: Station | undefined);
27
+ get strings(): StationStringOverrides | undefined;
28
+ set strings(value: StationStringOverrides | undefined);
29
+ get formatTime(): FormatTime | undefined;
30
+ set formatTime(value: FormatTime | undefined);
31
+ get thresholds(): SpeedThresholds | null | undefined;
32
+ set thresholds(value: SpeedThresholds | null | undefined);
33
+ protected display(): ResolvedDisplay;
34
+ protected requiredStation(component: string): Station;
35
+ get servedAt(): string | null | undefined;
36
+ set servedAt(value: string | null | undefined);
37
+ get receivedAtMs(): number | null | undefined;
38
+ set receivedAtMs(value: number | null | undefined);
39
+ protected servedAtValue(): string | null;
40
+ protected receivedAtMsValue(): number | null;
41
+ protected watchFreshness(): void;
42
+ protected freshnessOf(station: Station): FreshnessStatus | null;
43
+ }
44
+ //#endregion
45
+ export { MeteoElement, MeteoStationElement };
@@ -0,0 +1,152 @@
1
+ import { freshness, stationFreshnessThresholds } from "../../derive.js";
2
+ import { requireResolved, resolveDisplay, resolveStation } from "../../display.js";
3
+ import { subscribeTicker } from "../../client/ticker.js";
4
+ import { ELEMENTS_AMBIENT_HINT, STATION_FEED_CONTEXT_KEY } from "./ambient.js";
5
+ import { numberAttribute, parseThresholdsAttribute, unitAttribute } from "./attributes.js";
6
+ import { requestContext } from "./context.js";
7
+ //#region src/elements/lib/base.ts
8
+ var MeteoElement = class extends HTMLElement {
9
+ #cleanups = [];
10
+ #ambient = null;
11
+ #wired = false;
12
+ connectedCallback() {
13
+ if (!this.isConnected) return;
14
+ this.style.display = "contents";
15
+ this.#ambient = requestContext(this, STATION_FEED_CONTEXT_KEY);
16
+ if (this.#ambient != null) this.addCleanup(this.#ambient.subscribe(() => this.requestRender()));
17
+ this.#wired = true;
18
+ this.connected();
19
+ this.requestRender();
20
+ }
21
+ disconnectedCallback() {
22
+ for (const cleanup of this.#cleanups.splice(0)) cleanup();
23
+ this.#ambient = null;
24
+ this.#wired = false;
25
+ this.disconnected();
26
+ }
27
+ attributeChangedCallback(_name, _oldValue, _newValue) {
28
+ this.requestRender();
29
+ }
30
+ requestRender() {
31
+ if (!this.isConnected || !this.#wired) return;
32
+ this.render();
33
+ }
34
+ ambient() {
35
+ return this.#ambient?.getValue() ?? null;
36
+ }
37
+ addCleanup(cleanup) {
38
+ this.#cleanups.push(cleanup);
39
+ }
40
+ upgradeProperty(name) {
41
+ if (Object.prototype.hasOwnProperty.call(this, name)) {
42
+ const value = this[name];
43
+ delete this[name];
44
+ this[name] = value;
45
+ }
46
+ }
47
+ resolveRequiredStation(component, stationProp) {
48
+ return requireResolved(component, "station", stationProp ?? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0), ELEMENTS_AMBIENT_HINT);
49
+ }
50
+ connected() {}
51
+ disconnected() {}
52
+ };
53
+ var MeteoStationElement = class extends MeteoElement {
54
+ #station;
55
+ #strings;
56
+ #formatTime;
57
+ #thresholds = void 0;
58
+ #thresholdsSet = false;
59
+ #servedAt = void 0;
60
+ #receivedAtMs = void 0;
61
+ constructor() {
62
+ super();
63
+ for (const name of [
64
+ "station",
65
+ "strings",
66
+ "formatTime",
67
+ "thresholds",
68
+ "servedAt",
69
+ "receivedAtMs"
70
+ ]) this.upgradeProperty(name);
71
+ }
72
+ get station() {
73
+ return this.#station;
74
+ }
75
+ set station(value) {
76
+ this.#station = value;
77
+ this.requestRender();
78
+ }
79
+ get strings() {
80
+ return this.#strings;
81
+ }
82
+ set strings(value) {
83
+ this.#strings = value;
84
+ this.requestRender();
85
+ }
86
+ get formatTime() {
87
+ return this.#formatTime;
88
+ }
89
+ set formatTime(value) {
90
+ this.#formatTime = value;
91
+ this.requestRender();
92
+ }
93
+ get thresholds() {
94
+ return this.#thresholds;
95
+ }
96
+ set thresholds(value) {
97
+ this.#thresholds = value;
98
+ this.#thresholdsSet = value !== void 0;
99
+ this.requestRender();
100
+ }
101
+ display() {
102
+ return resolveDisplay(this.ambient(), {
103
+ strings: this.#strings,
104
+ unit: unitAttribute(this.getAttribute("unit")),
105
+ formatTime: this.#formatTime,
106
+ thresholds: this.#thresholdsSet ? this.#thresholds : parseThresholdsAttribute(this.getAttribute("thresholds"))
107
+ });
108
+ }
109
+ requiredStation(component) {
110
+ return this.resolveRequiredStation(component, this.#station);
111
+ }
112
+ get servedAt() {
113
+ return this.#servedAt;
114
+ }
115
+ set servedAt(value) {
116
+ this.#servedAt = value;
117
+ this.requestRender();
118
+ }
119
+ get receivedAtMs() {
120
+ return this.#receivedAtMs;
121
+ }
122
+ set receivedAtMs(value) {
123
+ this.#receivedAtMs = value;
124
+ this.requestRender();
125
+ }
126
+ servedAtValue() {
127
+ if (this.#servedAt !== void 0) return this.#servedAt;
128
+ return this.getAttribute("served-at") ?? this.ambient()?.feed?.servedAt ?? null;
129
+ }
130
+ receivedAtMsValue() {
131
+ if (this.#receivedAtMs !== void 0) return this.#receivedAtMs;
132
+ const attr = numberAttribute(this.getAttribute("received-at-ms"));
133
+ return attr !== void 0 ? attr : this.ambient()?.receivedAtMs ?? null;
134
+ }
135
+ watchFreshness() {
136
+ this.addCleanup(subscribeTicker(() => this.requestRender()));
137
+ }
138
+ freshnessOf(station) {
139
+ const observedAt = station.reading?.observedAt ?? null;
140
+ const servedAt = this.servedAtValue();
141
+ const receivedAtMs = this.receivedAtMsValue();
142
+ if (observedAt == null || servedAt == null || receivedAtMs == null) return null;
143
+ return freshness({
144
+ observedAt,
145
+ servedAt,
146
+ receivedAtMs,
147
+ nowMs: Date.now()
148
+ }, stationFreshnessThresholds(station));
149
+ }
150
+ };
151
+ //#endregion
152
+ export { MeteoElement, MeteoStationElement };
@@ -0,0 +1,28 @@
1
+ //#region src/elements/lib/context.ts
2
+ const CONTEXT_REQUEST_EVENT = "meteo-context-request";
3
+ function requestContext(from, key) {
4
+ let provision = null;
5
+ from.dispatchEvent(new CustomEvent(CONTEXT_REQUEST_EVENT, {
6
+ bubbles: true,
7
+ composed: false,
8
+ detail: {
9
+ key,
10
+ callback: (answered) => {
11
+ provision = answered;
12
+ }
13
+ }
14
+ }));
15
+ return provision;
16
+ }
17
+ function provideContext(host, key, provision) {
18
+ const handler = (event) => {
19
+ const request = event;
20
+ if (request.detail?.key !== key || event.target === host) return;
21
+ event.stopPropagation();
22
+ request.detail.callback(provision);
23
+ };
24
+ host.addEventListener(CONTEXT_REQUEST_EVENT, handler);
25
+ return () => host.removeEventListener(CONTEXT_REQUEST_EVENT, handler);
26
+ }
27
+ //#endregion
28
+ export { CONTEXT_REQUEST_EVENT, provideContext, requestContext };
@@ -0,0 +1,45 @@
1
+ import { directionCell } from "../../format.js";
2
+ import { freshnessBadgeSpec, windArrowSpec } from "../../scene/glyphs.js";
3
+ import { h, hs } from "./h.js";
4
+ //#region src/elements/lib/fragments.ts
5
+ function windArrowSvg(deg, size = 12) {
6
+ const spec = windArrowSpec(deg, size);
7
+ const svg = hs("svg", {
8
+ "aria-hidden": "true",
9
+ class: spec.className,
10
+ height: spec.height,
11
+ viewBox: spec.viewBox,
12
+ width: spec.width
13
+ }, hs("path", {
14
+ d: spec.path.d,
15
+ fill: spec.path.fill
16
+ }));
17
+ svg.style.transform = spec.transform;
18
+ return svg;
19
+ }
20
+ function directionCellNodes(windAvgMps, windDirectionDeg, words) {
21
+ const cell = directionCell(windAvgMps, windDirectionDeg);
22
+ if (cell.kind === "calm") return [words.calm];
23
+ if (cell.kind === "dash") return ["—"];
24
+ return [windArrowSvg(cell.deg), ` ${cell.compass} ${cell.rounded}°`];
25
+ }
26
+ function stationNameNode(station) {
27
+ if (station.pageUrl == null) return station.name;
28
+ return h("a", {
29
+ href: station.pageUrl,
30
+ rel: "noreferrer",
31
+ target: "_blank"
32
+ }, station.name);
33
+ }
34
+ function freshnessBadgeSpan(status, words) {
35
+ const spec = freshnessBadgeSpec(status, words);
36
+ return h("span", {
37
+ class: spec.className,
38
+ "data-freshness": spec.status
39
+ }, h("span", {
40
+ "aria-hidden": "true",
41
+ class: spec.dot.className
42
+ }), spec.text);
43
+ }
44
+ //#endregion
45
+ export { directionCellNodes, freshnessBadgeSpan, stationNameNode, windArrowSvg };
@@ -0,0 +1,35 @@
1
+ //#region src/elements/lib/h.ts
2
+ const SVG_NS = "http://www.w3.org/2000/svg";
3
+ function apply(element, attrs, children) {
4
+ if (attrs != null) for (const [name, value] of Object.entries(attrs)) {
5
+ if (value == null || value === false) continue;
6
+ if (typeof value === "function") {
7
+ element.addEventListener(name.slice(2), value);
8
+ continue;
9
+ }
10
+ element.setAttribute(name, value === true ? "" : String(value));
11
+ }
12
+ appendChildren(element, children);
13
+ }
14
+ function appendChildren(element, children) {
15
+ for (const child of children) {
16
+ if (child == null || child === false) continue;
17
+ if (Array.isArray(child)) {
18
+ appendChildren(element, child);
19
+ continue;
20
+ }
21
+ element.append(typeof child === "number" ? String(child) : child);
22
+ }
23
+ }
24
+ function h(tag, attrs = null, ...children) {
25
+ const element = document.createElement(tag);
26
+ apply(element, attrs, children);
27
+ return element;
28
+ }
29
+ function hs(tag, attrs = null, ...children) {
30
+ const element = document.createElementNS(SVG_NS, tag);
31
+ apply(element, attrs, children);
32
+ return element;
33
+ }
34
+ //#endregion
35
+ export { h, hs };
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,5 @@
1
+ import { defineMeteoElements } from "./index.js";
2
+ //#region src/elements/register.ts
3
+ defineMeteoElements();
4
+ //#endregion
5
+ export {};
@@ -0,0 +1,5 @@
1
+ //#region src/endpoints.d.ts
2
+ declare function feedEndpoint(base: string): string;
3
+ declare function currentEndpoint(base: string, stationId: string): string;
4
+ //#endregion
5
+ export { currentEndpoint, feedEndpoint };
@@ -0,0 +1,10 @@
1
+ //#region src/endpoints.ts
2
+ const trimBase = (base) => base.replace(/\/+$/, "");
3
+ function feedEndpoint(base) {
4
+ return `${trimBase(base)}/feed`;
5
+ }
6
+ function currentEndpoint(base, stationId) {
7
+ return `${trimBase(base)}/current?station=${encodeURIComponent(stationId)}`;
8
+ }
9
+ //#endregion
10
+ export { currentEndpoint, feedEndpoint };
@@ -0,0 +1,23 @@
1
+ import { HistoryPoint } from "./contract.js";
2
+ //#region src/fixtures.d.ts
3
+ /** Deterministic PRNG (mulberry32). */
4
+ declare function mulberry32(seed: number): () => number;
5
+ /** Smoothstep clamped to [0, 1]. */
6
+ declare const smooth: (value: number) => number;
7
+ /** Deterministic wobble in roughly [-1, 1]. */
8
+ declare const wobble: (seed: number) => number;
9
+ interface LongHistoryOptions {
10
+ /** The series ends here. */
11
+ nowMs: number;
12
+ /** How many days of history to build. */
13
+ days?: number;
14
+ /** Sample cadence. */
15
+ periodMinutes?: number;
16
+ seed?: number;
17
+ /** Punch a few multi-hour dropouts in. */
18
+ withGaps?: boolean;
19
+ }
20
+ /** A long-range deterministic synthetic history: seasonal, diurnal, with occasional dropouts. */
21
+ declare function buildLongHistory({ nowMs, days, periodMinutes, seed, withGaps }: LongHistoryOptions): HistoryPoint[];
22
+ //#endregion
23
+ export { LongHistoryOptions, buildLongHistory, mulberry32, smooth, wobble };
@@ -0,0 +1,67 @@
1
+ //#region src/fixtures.ts
2
+ const MINUTE_MS = 6e4;
3
+ const DAY_MS = 1440 * MINUTE_MS;
4
+ /** Deterministic PRNG (mulberry32). */
5
+ function mulberry32(seed) {
6
+ let a = seed >>> 0;
7
+ return () => {
8
+ a = a + 1831565813 | 0;
9
+ let t = Math.imul(a ^ a >>> 15, 1 | a);
10
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
11
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
12
+ };
13
+ }
14
+ /** Smoothstep clamped to [0, 1]. */
15
+ const smooth = (value) => {
16
+ const u = Math.min(1, Math.max(0, value));
17
+ return u * u * (3 - 2 * u);
18
+ };
19
+ /** Deterministic wobble in roughly [-1, 1]. */
20
+ const wobble = (seed) => (Math.sin(seed * 12.9898) + Math.sin(seed * 4.1414 + 1.3)) / 2;
21
+ const round1 = (value) => Math.round(value * 10) / 10;
22
+ const round2 = (value) => Math.round(value * 100) / 100;
23
+ const mps = (kmh) => round2(kmh / 3.6);
24
+ const normalizeDeg = (deg) => (deg % 360 + 360) % 360;
25
+ function seasonPhase(dateUtc) {
26
+ const solsticeMs = Date.UTC(dateUtc.getUTCFullYear(), 11, 21);
27
+ const anchored = dateUtc.getTime() >= solsticeMs ? solsticeMs : Date.UTC(dateUtc.getUTCFullYear() - 1, 11, 21);
28
+ return (dateUtc.getTime() - anchored) / (365.25 * DAY_MS) % 1;
29
+ }
30
+ /** A long-range deterministic synthetic history: seasonal, diurnal, with occasional dropouts. */
31
+ function buildLongHistory({ nowMs, days = 420, periodMinutes = 15, seed = 99537381, withGaps = true }) {
32
+ const rand = mulberry32(seed);
33
+ const totalSamples = Math.round(days * DAY_MS / (periodMinutes * MINUTE_MS));
34
+ const anchorMs = Math.floor(nowMs / (periodMinutes * MINUTE_MS)) * periodMinutes * MINUTE_MS;
35
+ const gapStartIndexes = withGaps ? Array.from({ length: 6 }, () => Math.floor(rand() * (totalSamples - 40)) + 20) : [];
36
+ const gapLengthSamples = Math.max(2, Math.round(180 / periodMinutes));
37
+ const points = [];
38
+ for (let index = 0; index < totalSamples; index += 1) {
39
+ const sampleMs = anchorMs - (totalSamples - 1 - index) * periodMinutes * MINUTE_MS;
40
+ if (gapStartIndexes.some((start) => index >= start && index < start + gapLengthSamples)) continue;
41
+ const date = new Date(sampleMs);
42
+ const dayFraction = (date.getUTCHours() * 60 + date.getUTCMinutes()) / 1440;
43
+ const diurnal = smooth((dayFraction - .32) / .24) * (1 - smooth((dayFraction - .72) / .22));
44
+ const season = seasonPhase(date);
45
+ const summerWeight = smooth(1 - Math.abs(season - .5) * 2.4);
46
+ const strength = .35 + .9 * summerWeight;
47
+ const scatter = 60 - 34 * summerWeight;
48
+ const noise = wobble(index * .7) * .5 + wobble(index * 3.1 + 11) * .5;
49
+ const average = Math.max(0, round1(diurnal * strength * (16 + noise * 6)));
50
+ const calm = average < .5;
51
+ const gust = calm ? 0 : mps(average * 1.3 + 2 + Math.abs(noise) * 4);
52
+ const lull = calm ? 0 : mps(Math.max(0, average * .6 - 1));
53
+ const bearing = calm ? null : round1(normalizeDeg(225 + noise * scatter));
54
+ const temperature = round1(8 + 14 * summerWeight + 6 * smooth((dayFraction - .3) / .4) + wobble(index * 5) * 1.5);
55
+ points.push({
56
+ observedAt: new Date(sampleMs).toISOString(),
57
+ windAvgMps: mps(average),
58
+ windGustMps: gust,
59
+ windLullMps: lull,
60
+ windDirectionDeg: bearing,
61
+ temperatureC: temperature
62
+ });
63
+ }
64
+ return points;
65
+ }
66
+ //#endregion
67
+ export { buildLongHistory, mulberry32, smooth, wobble };
@@ -0,0 +1,31 @@
1
+ import { Station } from "./contract.js";
2
+ import { CompassPoint, SpeedUnit } from "./derive.js";
3
+ import { FormatTime, StationStrings } from "./strings.js";
4
+ //#region src/format.d.ts
5
+ declare function roundSpeed(mps: number, unit: SpeedUnit): number;
6
+ declare function optionalSpeed(mps: number | null, unit: SpeedUnit): string;
7
+ declare function temperatureValue(temperatureC: number): string;
8
+ declare function temperatureText(temperatureC: number | null, words: StationStrings): string;
9
+ type SpeedKind = "average" | "gust" | "lull";
10
+ type DirectionCellData = {
11
+ kind: "calm";
12
+ } | {
13
+ kind: "dash";
14
+ } | {
15
+ kind: "bearing";
16
+ deg: number;
17
+ compass: CompassPoint;
18
+ rounded: number;
19
+ };
20
+ declare function directionCell(windAvgMps: number, windDirectionDeg: number | null): DirectionCellData;
21
+ declare function updatedAtText(ageMs: number, observedAt: string, words: StationStrings, formatTime: FormatTime): string;
22
+ type SummaryEntry = {
23
+ label: string;
24
+ value: string;
25
+ };
26
+ declare function summaryEntries(station: Station, unit: SpeedUnit, words: StationStrings, formatTime: FormatTime): {
27
+ entries: SummaryEntry[];
28
+ periodEndedAt: string;
29
+ } | null;
30
+ //#endregion
31
+ export { DirectionCellData, SpeedKind, SummaryEntry, directionCell, optionalSpeed, roundSpeed, summaryEntries, temperatureText, temperatureValue, updatedAtText };
package/dist/format.js ADDED
@@ -0,0 +1,82 @@
1
+ import { compassDirection, isCalm, periodSummary, speedFromMps } from "./derive.js";
2
+ //#region src/format.ts
3
+ function roundSpeed(mps, unit) {
4
+ return Math.round(speedFromMps(mps, unit));
5
+ }
6
+ function optionalSpeed(mps, unit) {
7
+ return mps == null ? "—" : String(roundSpeed(mps, unit));
8
+ }
9
+ function temperatureValue(temperatureC) {
10
+ return temperatureC.toFixed(1);
11
+ }
12
+ function temperatureText(temperatureC, words) {
13
+ return temperatureC == null ? "—" : `${temperatureValue(temperatureC)} ${words.degC}`;
14
+ }
15
+ function speedMpsOf(station, kind) {
16
+ if (station.status !== "ok") return null;
17
+ switch (kind) {
18
+ case "average": return station.reading.windAvgMps;
19
+ case "gust": return station.capabilities.gustLull ? station.reading.windGustMps : null;
20
+ case "lull": return station.capabilities.gustLull ? station.reading.windLullMps : null;
21
+ }
22
+ }
23
+ function directionCell(windAvgMps, windDirectionDeg) {
24
+ if (isCalm(windAvgMps)) return { kind: "calm" };
25
+ if (windDirectionDeg == null) return { kind: "dash" };
26
+ return {
27
+ kind: "bearing",
28
+ deg: windDirectionDeg,
29
+ compass: compassDirection(windDirectionDeg),
30
+ rounded: Math.round(windDirectionDeg)
31
+ };
32
+ }
33
+ const MINUTE_MS = 6e4;
34
+ const HOUR_MS = 36e5;
35
+ const UPDATED_ABSOLUTE_AFTER_MS = 6 * HOUR_MS;
36
+ function relativeWords(ageMs, words) {
37
+ if (ageMs < MINUTE_MS) return words.updated.justNow;
38
+ const minutes = Math.floor(ageMs / MINUTE_MS);
39
+ if (minutes < 60) return words.updated.minutesAgo(minutes);
40
+ return words.updated.hoursAgo(Math.floor(ageMs / HOUR_MS));
41
+ }
42
+ function readingAgeMs(args) {
43
+ const observedMs = Date.parse(args.observedAt);
44
+ return args.servedAt != null && args.receivedAtMs != null ? Math.max(0, Date.parse(args.servedAt) - observedMs) + Math.max(0, args.nowMs - args.receivedAtMs) : Math.max(0, args.nowMs - observedMs);
45
+ }
46
+ function updatedAtText(ageMs, observedAt, words, formatTime) {
47
+ return ageMs >= 216e5 ? formatTime(new Date(Date.parse(observedAt))) : relativeWords(ageMs, words);
48
+ }
49
+ function summaryEntries(station, unit, words, formatTime) {
50
+ const history = station.status === "ok" ? station.history : null;
51
+ const summary = history == null || history.points.length === 0 ? null : periodSummary(history);
52
+ if (summary == null) return null;
53
+ const capabilities = station.capabilities;
54
+ const shown = (windAvgMps) => roundSpeed(windAvgMps, unit);
55
+ const unitLabel = words.speedUnits[unit];
56
+ return {
57
+ entries: [
58
+ {
59
+ label: words.averageLabel,
60
+ value: `${shown(summary.windAvgMps)} ${unitLabel}`
61
+ },
62
+ ...capabilities.gustLull ? [{
63
+ label: words.peakLabel,
64
+ value: summary.peakGustMps == null ? "—" : `${shown(summary.peakGustMps)} ${unitLabel}${summary.peakGustAt == null ? "" : ` · ${formatTime(new Date(summary.peakGustAt))}`}`
65
+ }, {
66
+ label: words.minLabel,
67
+ value: summary.lowestLullMps == null ? "—" : `${shown(summary.lowestLullMps)} ${unitLabel}`
68
+ }] : [],
69
+ {
70
+ label: words.windRunLabel,
71
+ value: `${Math.round(summary.windRunKm)} ${words.km}`
72
+ },
73
+ ...capabilities.temperature ? [{
74
+ label: words.tempRangeLabel,
75
+ value: summary.temperatureLowC == null || summary.temperatureHighC == null ? "—" : `${summary.temperatureLowC.toFixed(1)}–${summary.temperatureHighC.toFixed(1)} ${words.degC}`
76
+ }] : []
77
+ ],
78
+ periodEndedAt: summary.periodEndedAt
79
+ };
80
+ }
81
+ //#endregion
82
+ export { UPDATED_ABSOLUTE_AFTER_MS, directionCell, optionalSpeed, readingAgeMs, relativeWords, roundSpeed, speedMpsOf, summaryEntries, temperatureText, temperatureValue, updatedAtText };
@@ -0,0 +1,84 @@
1
+ import { History, HistoryPoint } from "./contract.js";
2
+ //#region src/geometry.d.ts
3
+ type ChartFrame = {
4
+ height: number;
5
+ labelRow: number;
6
+ left: number;
7
+ plotBottom: number;
8
+ plotTop: number;
9
+ right: number;
10
+ vaneLabelRow: number;
11
+ vaneRow: number;
12
+ valueRow: number;
13
+ width: number;
14
+ };
15
+ declare function chartFrame(width: number): ChartFrame;
16
+ type ChartScales = {
17
+ startMs: number;
18
+ endMs: number;
19
+ durationMs: number;
20
+ scaleMax: number;
21
+ xAtMs: (ms: number) => number;
22
+ xAt: (observedAt: string) => number;
23
+ yAt: (speedMps: number) => number;
24
+ };
25
+ type ChartScaleOptions = {
26
+ niceStepMps?: number;
27
+ floorMps?: number;
28
+ };
29
+ declare function chartScales(points: ReadonlyArray<HistoryPoint>, frame: ChartFrame, options?: ChartScaleOptions): ChartScales;
30
+ declare function bandPoints(points: ReadonlyArray<HistoryPoint>, scales: ChartScales): string | null;
31
+ declare function averagePoints(points: ReadonlyArray<HistoryPoint>, scales: ChartScales): string;
32
+ type Vane = {
33
+ windAvgMps: number;
34
+ windDirectionDeg: number | null;
35
+ endIndex: number;
36
+ midMs: number;
37
+ startIndex: number;
38
+ };
39
+ declare function thinVanes(points: ReadonlyArray<HistoryPoint>, target?: number): Vane[];
40
+ declare function vanePath(cx: number, cy: number, fromBearingDeg: number, { reach, spread }?: {
41
+ reach?: number;
42
+ spread?: number;
43
+ }): string;
44
+ type ChartTick = {
45
+ index: number;
46
+ timeMs: number;
47
+ x: number;
48
+ };
49
+ declare function vaneTicks(vanes: ReadonlyArray<Vane>, scales: ChartScales): ChartTick[];
50
+ declare function speedBand(speedMps: number, thresholdsMps: ReadonlyArray<number>): number;
51
+ type RoseSector = {
52
+ bearingDeg: number;
53
+ frequency: number;
54
+ meanSpeedMps: number | null;
55
+ maxGustMps: number | null;
56
+ count: number;
57
+ };
58
+ type WindRoseSummary = {
59
+ sectors: RoseSector[];
60
+ calmFraction: number;
61
+ sampleCount: number;
62
+ };
63
+ declare function windRose(points: ReadonlyArray<HistoryPoint>, sectorCount?: number): WindRoseSummary;
64
+ declare const DAILY_PATTERN_DEFAULT_SLOT_MINUTES = 180;
65
+ type DailyPatternSlot = {
66
+ startMinuteOfDay: number;
67
+ sampleCount: number;
68
+ windDirectionDeg: number | null;
69
+ speedMps: number;
70
+ };
71
+ declare function dailyPattern(points: ReadonlyArray<HistoryPoint>, options?: {
72
+ slotMinutes?: number;
73
+ utcOffsetMinutes?: number;
74
+ }): DailyPatternSlot[];
75
+ declare const METEOROLOGICAL_SEASON_MONTHS: Record<"fall" | "spring" | "summer" | "winter", number[]>;
76
+ declare function filterByMonth(points: ReadonlyArray<HistoryPoint>, months: ReadonlyArray<number>, utcOffsetMinutes?: number): HistoryPoint[];
77
+ declare function filterByTimeOfDay(points: ReadonlyArray<HistoryPoint>, fromMinute: number, toMinute: number, utcOffsetMinutes?: number): HistoryPoint[];
78
+ declare function historyGaps(history: History, toleranceFactor?: number): Array<[number, number]>;
79
+ type TrendSeries = "temperature" | "pressure";
80
+ declare function windowPoints(points: ReadonlyArray<HistoryPoint>, hours?: number): ReadonlyArray<HistoryPoint>;
81
+ declare function compareWindow(points: ReadonlyArray<HistoryPoint>, offsetDays: number, windowHours?: number): HistoryPoint[] | null;
82
+ declare function compareTracePoints(comparePoints: ReadonlyArray<HistoryPoint>, scales: ChartScales, offsetDays: number): string;
83
+ //#endregion
84
+ export { ChartFrame, ChartScaleOptions, ChartScales, ChartTick, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DailyPatternSlot, METEOROLOGICAL_SEASON_MONTHS, RoseSector, TrendSeries, Vane, WindRoseSummary, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints };