@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,128 @@
1
+ import "../../instruments.js";
2
+ import { dialScene } from "../../scene/dial.js";
3
+ import { numberAttribute } from "../lib/attributes.js";
4
+ import { MeteoStationElement } from "../lib/base.js";
5
+ import { hs } from "../lib/h.js";
6
+ //#region src/elements/elements/DialElement.ts
7
+ let bezelCounter = 0;
8
+ function dialSvg(options) {
9
+ const { station, thresholds, unit, words, size = 160, calmWord = true } = options;
10
+ const scene = dialScene({
11
+ bezelId: `meteo-bezel-e${++bezelCounter}`,
12
+ calmWord,
13
+ size,
14
+ station,
15
+ thresholds,
16
+ unit,
17
+ words
18
+ });
19
+ const { gradient, centre } = scene;
20
+ return hs("svg", {
21
+ "aria-label": scene.svg.ariaLabel,
22
+ class: scene.svg.className,
23
+ height: scene.svg.height,
24
+ role: "img",
25
+ viewBox: scene.svg.viewBox,
26
+ width: scene.svg.width
27
+ }, hs("defs", null, hs("radialGradient", {
28
+ cx: gradient.cx,
29
+ cy: gradient.cy,
30
+ id: gradient.id,
31
+ r: gradient.r
32
+ }, gradient.stops.map((stop) => hs("stop", {
33
+ class: stop.className,
34
+ offset: stop.offset
35
+ })))), hs("circle", {
36
+ class: scene.face.className,
37
+ cx: scene.face.cx,
38
+ cy: scene.face.cy,
39
+ r: scene.face.r
40
+ }), hs("circle", {
41
+ class: scene.bezel.className,
42
+ cx: scene.bezel.cx,
43
+ cy: scene.bezel.cy,
44
+ fill: scene.bezel.fill,
45
+ r: scene.bezel.r
46
+ }), hs("circle", {
47
+ class: scene.ring.className,
48
+ cx: scene.ring.cx,
49
+ cy: scene.ring.cy,
50
+ r: scene.ring.r
51
+ }), scene.arc != null && hs("path", {
52
+ class: scene.arc.className,
53
+ d: scene.arc.d
54
+ }), scene.ticks.map((tick) => hs("line", {
55
+ class: tick.className,
56
+ x1: tick.x1,
57
+ x2: tick.x2,
58
+ y1: tick.y1,
59
+ y2: tick.y2
60
+ })), scene.letters.map((letter) => hs("text", {
61
+ class: letter.className,
62
+ "text-anchor": letter.anchor,
63
+ x: letter.x,
64
+ y: letter.y
65
+ }, letter.text)), scene.needle != null && hs("g", { class: scene.needle.className }, hs("polygon", {
66
+ class: scene.needle.blade.className,
67
+ points: scene.needle.blade.points
68
+ }), hs("circle", {
69
+ class: scene.needle.counterweight.className,
70
+ cx: scene.needle.counterweight.cx,
71
+ cy: scene.needle.counterweight.cy,
72
+ r: scene.needle.counterweight.r
73
+ })), hs("circle", {
74
+ class: scene.hub.className,
75
+ cx: scene.hub.cx,
76
+ cy: scene.hub.cy,
77
+ r: scene.hub.r
78
+ }), centre.kind === "reason" ? hs("text", {
79
+ class: centre.text.className,
80
+ "text-anchor": centre.text.anchor,
81
+ x: centre.text.x,
82
+ y: centre.text.y
83
+ }, centre.text.text) : [
84
+ centre.calmWord != null ? hs("text", {
85
+ class: centre.calmWord.className,
86
+ "text-anchor": centre.calmWord.anchor,
87
+ x: centre.calmWord.x,
88
+ y: centre.calmWord.y
89
+ }, centre.calmWord.text) : null,
90
+ hs("text", {
91
+ class: centre.speed.className,
92
+ "text-anchor": centre.speed.anchor,
93
+ x: centre.speed.x,
94
+ y: centre.speed.y
95
+ }, centre.speed.text),
96
+ hs("text", {
97
+ class: centre.unit.className,
98
+ "text-anchor": centre.unit.anchor,
99
+ x: centre.unit.x,
100
+ y: centre.unit.y
101
+ }, centre.unit.text)
102
+ ]);
103
+ }
104
+ var DialElement = class extends MeteoStationElement {
105
+ static observedAttributes = [
106
+ "no-calm-word",
107
+ "received-at-ms",
108
+ "served-at",
109
+ "size",
110
+ "station-id",
111
+ "thresholds",
112
+ "unit"
113
+ ];
114
+ render() {
115
+ const station = this.requiredStation("meteo-dial");
116
+ const { thresholds, unit, words } = this.display();
117
+ this.replaceChildren(dialSvg({
118
+ station,
119
+ thresholds,
120
+ unit,
121
+ words,
122
+ size: numberAttribute(this.getAttribute("size")) ?? 160,
123
+ calmWord: !this.hasAttribute("no-calm-word")
124
+ }));
125
+ }
126
+ };
127
+ //#endregion
128
+ export { DialElement, dialSvg };
@@ -0,0 +1,8 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ //#region src/elements/elements/FreshnessBadgeElement.d.ts
3
+ declare class FreshnessBadgeElement extends MeteoStationElement {
4
+ static readonly observedAttributes: string[];
5
+ protected render(): void;
6
+ }
7
+ //#endregion
8
+ export { FreshnessBadgeElement };
@@ -0,0 +1,22 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ import { freshnessBadgeSpan } from "../lib/fragments.js";
3
+ //#region src/elements/elements/FreshnessBadgeElement.ts
4
+ const STATUSES = [
5
+ "live",
6
+ "aging",
7
+ "stale"
8
+ ];
9
+ var FreshnessBadgeElement = class extends MeteoStationElement {
10
+ static observedAttributes = ["status"];
11
+ render() {
12
+ const status = this.getAttribute("status");
13
+ if (status == null || !STATUSES.includes(status)) {
14
+ this.replaceChildren();
15
+ return;
16
+ }
17
+ const { words } = this.display();
18
+ this.replaceChildren(freshnessBadgeSpan(status, words));
19
+ }
20
+ };
21
+ //#endregion
22
+ export { FreshnessBadgeElement };
@@ -0,0 +1,9 @@
1
+ import "../../index.js";
2
+ import { MeteoStationElement } from "../lib/base.js";
3
+ //#region src/elements/elements/SparklineElement.d.ts
4
+ declare class SparklineElement extends MeteoStationElement {
5
+ static readonly observedAttributes: string[];
6
+ protected render(): void;
7
+ }
8
+ //#endregion
9
+ export { SparklineElement };
@@ -0,0 +1,74 @@
1
+ import { sparklineScene } from "../../scene/sparkline.js";
2
+ import { numberAttribute } from "../lib/attributes.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ import { h, hs } from "../lib/h.js";
5
+ //#region src/elements/elements/SparklineElement.ts
6
+ function sparklineNode(options) {
7
+ const { station, thresholds, words, width = 120, height = 32, showBand = true } = options;
8
+ const scene = sparklineScene({
9
+ height,
10
+ showBand,
11
+ station,
12
+ thresholds,
13
+ width,
14
+ words
15
+ });
16
+ if (scene.kind === "placeholder") {
17
+ const placeholder = h("span", {
18
+ "aria-label": scene.ariaLabel,
19
+ class: scene.className,
20
+ role: "img"
21
+ }, scene.text);
22
+ placeholder.style.height = `${scene.height}px`;
23
+ placeholder.style.width = `${scene.width}px`;
24
+ return placeholder;
25
+ }
26
+ return hs("svg", {
27
+ "aria-label": scene.svg.ariaLabel,
28
+ class: scene.svg.className,
29
+ height: scene.svg.height,
30
+ role: "img",
31
+ viewBox: scene.svg.viewBox,
32
+ width: scene.svg.width
33
+ }, scene.bands.map((band) => hs("polygon", {
34
+ class: band.className,
35
+ points: band.points
36
+ })), scene.trace.map((part) => part.kind === "dot" ? hs("circle", {
37
+ class: part.className,
38
+ cx: part.cx,
39
+ cy: part.cy,
40
+ r: part.r
41
+ }) : part.kind === "polyline" ? hs("polyline", {
42
+ class: part.className,
43
+ points: part.points
44
+ }) : hs("line", {
45
+ class: part.className,
46
+ x1: part.x1,
47
+ x2: part.x2,
48
+ y1: part.y1,
49
+ y2: part.y2
50
+ })));
51
+ }
52
+ var SparklineElement = class extends MeteoStationElement {
53
+ static observedAttributes = [
54
+ "height",
55
+ "no-band",
56
+ "station-id",
57
+ "thresholds",
58
+ "width"
59
+ ];
60
+ render() {
61
+ const station = this.requiredStation("meteo-sparkline");
62
+ const { thresholds, words } = this.display();
63
+ this.replaceChildren(sparklineNode({
64
+ station,
65
+ thresholds,
66
+ words,
67
+ width: numberAttribute(this.getAttribute("width")) ?? 120,
68
+ height: numberAttribute(this.getAttribute("height")) ?? 32,
69
+ showBand: !this.hasAttribute("no-band")
70
+ }));
71
+ }
72
+ };
73
+ //#endregion
74
+ export { SparklineElement, sparklineNode };
@@ -0,0 +1,53 @@
1
+ import { Station } from "../../contract.js";
2
+ import { SpeedThresholds, SpeedUnit } from "../../derive.js";
3
+ import { FormatTime, StationStringOverrides } from "../../strings.js";
4
+ import "../../index.js";
5
+ import { MeteoElement, MeteoStationElement } from "../lib/base.js";
6
+ //#region src/elements/elements/StationCardElement.d.ts
7
+ type StationCardContextValue = {
8
+ station: Station;
9
+ servedAt: string | null;
10
+ receivedAtMs: number | null;
11
+ thresholds: SpeedThresholds | undefined;
12
+ unit: SpeedUnit;
13
+ strings: StationStringOverrides | undefined;
14
+ formatTime: FormatTime;
15
+ };
16
+ declare class StationCardElement extends MeteoStationElement {
17
+ #private;
18
+ static readonly observedAttributes: string[];
19
+ protected connected(): void;
20
+ protected render(): void;
21
+ }
22
+ declare abstract class StationCardPartElement extends MeteoElement {
23
+ #private;
24
+ protected abstract readonly partName: string;
25
+ constructor();
26
+ get strings(): StationStringOverrides | undefined;
27
+ set strings(value: StationStringOverrides | undefined);
28
+ get formatTime(): FormatTime | undefined;
29
+ set formatTime(value: FormatTime | undefined);
30
+ protected connected(): void;
31
+ protected card(): StationCardContextValue;
32
+ }
33
+ declare class StationCardHeaderElement extends StationCardPartElement {
34
+ protected readonly partName = "header";
35
+ protected connected(): void;
36
+ protected render(): void;
37
+ }
38
+ declare class StationCardInstrumentElement extends StationCardPartElement {
39
+ static readonly observedAttributes: string[];
40
+ protected readonly partName = "instrument";
41
+ protected render(): void;
42
+ }
43
+ declare class StationCardChartElement extends StationCardPartElement {
44
+ static readonly observedAttributes: string[];
45
+ protected readonly partName = "chart";
46
+ protected render(): void;
47
+ }
48
+ declare class StationCardSummaryElement extends StationCardPartElement {
49
+ protected readonly partName = "summary";
50
+ protected render(): void;
51
+ }
52
+ //#endregion
53
+ export { StationCardChartElement, StationCardElement, StationCardHeaderElement, StationCardInstrumentElement, StationCardSummaryElement };
@@ -0,0 +1,211 @@
1
+ import { freshness, stationFreshnessThresholds } from "../../derive.js";
2
+ import { mergeStringOverrides, resolveStrings } from "../../strings.js";
3
+ import { resolveDisplay } from "../../display.js";
4
+ import { subscribeTicker } from "../../client/ticker.js";
5
+ import { STATION_CARD_CLASS, cardHeaderScene, cardPartThresholds, cardPartWiringError, summaryScene } from "../../scene/card.js";
6
+ import { numberAttribute } from "../lib/attributes.js";
7
+ import { provideContext, requestContext } from "../lib/context.js";
8
+ import { MeteoElement, MeteoStationElement } from "../lib/base.js";
9
+ import { h } from "../lib/h.js";
10
+ import { freshnessBadgeSpan } from "../lib/fragments.js";
11
+ //#region src/elements/elements/StationCardElement.ts
12
+ const STATION_CARD_CONTEXT_KEY = "meteo-station-card";
13
+ var StationCardElement = class extends MeteoStationElement {
14
+ static observedAttributes = [
15
+ "compose",
16
+ "received-at-ms",
17
+ "served-at",
18
+ "station-id",
19
+ "thresholds",
20
+ "unit"
21
+ ];
22
+ #listeners = /* @__PURE__ */ new Set();
23
+ #article = null;
24
+ connected() {
25
+ this.addCleanup(provideContext(this, STATION_CARD_CONTEXT_KEY, {
26
+ getValue: () => this.#value(),
27
+ subscribe: (listener) => {
28
+ this.#listeners.add(listener);
29
+ return () => this.#listeners.delete(listener);
30
+ }
31
+ }));
32
+ }
33
+ #value() {
34
+ const station = this.requiredStation("meteo-station-card");
35
+ const { formatTime, strings, thresholds, unit } = resolveDisplay(this.ambient(), {
36
+ strings: this.strings,
37
+ thresholds: this.thresholds !== void 0 ? this.thresholds : this.#thresholdsAttribute(),
38
+ unit: this.#unitAttribute(),
39
+ formatTime: this.formatTime
40
+ });
41
+ return {
42
+ station,
43
+ servedAt: this.servedAtValue(),
44
+ receivedAtMs: this.receivedAtMsValue(),
45
+ thresholds,
46
+ unit,
47
+ strings,
48
+ formatTime
49
+ };
50
+ }
51
+ #unitAttribute() {
52
+ const value = this.getAttribute("unit");
53
+ return value === "kmh" || value === "knots" || value === "mph" || value === "mps" ? value : void 0;
54
+ }
55
+ #thresholdsAttribute() {
56
+ const raw = this.getAttribute("thresholds");
57
+ if (raw == null) return void 0;
58
+ if (raw.trim() === "none") return null;
59
+ try {
60
+ return JSON.parse(raw);
61
+ } catch {
62
+ return;
63
+ }
64
+ }
65
+ render() {
66
+ const value = this.#value();
67
+ if (this.#article == null) {
68
+ const authoredText = [...this.childNodes].some((node) => node.nodeType === Node.TEXT_NODE && (node.textContent ?? "").trim() !== "");
69
+ const composing = this.hasAttribute("compose") || this.children.length > 0 || authoredText;
70
+ const article = h("article", {
71
+ class: STATION_CARD_CLASS,
72
+ "data-status": value.station.status
73
+ });
74
+ if (composing) article.append(...this.childNodes);
75
+ else article.append(document.createElement("meteo-station-card-header"), document.createElement("meteo-station-card-instrument"), document.createElement("meteo-station-card-chart"), document.createElement("meteo-station-card-summary"));
76
+ this.#article = article;
77
+ this.replaceChildren(article);
78
+ } else this.#article.setAttribute("data-status", value.station.status);
79
+ for (const listener of [...this.#listeners]) listener();
80
+ }
81
+ };
82
+ var StationCardPartElement = class extends MeteoElement {
83
+ #context = null;
84
+ #strings;
85
+ #formatTime;
86
+ constructor() {
87
+ super();
88
+ for (const name of ["strings", "formatTime"]) this.upgradeProperty(name);
89
+ }
90
+ get strings() {
91
+ return this.#strings;
92
+ }
93
+ set strings(value) {
94
+ this.#strings = value;
95
+ this.requestRender();
96
+ }
97
+ get formatTime() {
98
+ return this.#formatTime;
99
+ }
100
+ set formatTime(value) {
101
+ this.#formatTime = value;
102
+ this.requestRender();
103
+ }
104
+ connected() {
105
+ this.#context = requestContext(this, STATION_CARD_CONTEXT_KEY);
106
+ if (this.#context == null) throw new Error(cardPartWiringError(`<meteo-station-card-${this.partName}>`, "<meteo-station-card>"));
107
+ this.addCleanup(this.#context.subscribe(() => this.requestRender()));
108
+ this.addCleanup(() => {
109
+ this.#context = null;
110
+ });
111
+ }
112
+ card() {
113
+ const context = this.#context;
114
+ if (context == null) throw new Error(`<meteo-station-card-${this.partName}> must render inside <meteo-station-card> — the provider carries the station, clocks, and display settings.`);
115
+ const value = context.getValue();
116
+ return {
117
+ ...value,
118
+ strings: mergeStringOverrides(value.strings, this.#strings),
119
+ formatTime: this.#formatTime ?? value.formatTime
120
+ };
121
+ }
122
+ };
123
+ var StationCardHeaderElement = class extends StationCardPartElement {
124
+ partName = "header";
125
+ connected() {
126
+ super.connected();
127
+ this.addCleanup(subscribeTicker(() => this.requestRender()));
128
+ }
129
+ render() {
130
+ const { station, servedAt, receivedAtMs, strings } = this.card();
131
+ const words = resolveStrings(strings);
132
+ const observedAt = station.reading?.observedAt ?? null;
133
+ const status = observedAt == null || servedAt == null || receivedAtMs == null ? null : freshness({
134
+ observedAt,
135
+ servedAt,
136
+ receivedAtMs,
137
+ nowMs: Date.now()
138
+ }, stationFreshnessThresholds(station));
139
+ const scene = cardHeaderScene(station, words);
140
+ const { name, meta } = scene.identity;
141
+ this.replaceChildren(h("header", { class: scene.className }, h("div", { class: scene.identity.className }, h("h3", { class: name.className }, name.link ? h("a", {
142
+ href: name.link.href,
143
+ rel: name.link.rel,
144
+ target: name.link.target
145
+ }, name.link.text) : name.text), h("p", { class: meta.className }, h("span", { class: meta.source.className }, meta.source.text), meta.elevation != null && h("span", { class: meta.elevation.className }, meta.elevation.text))), status != null && freshnessBadgeSpan(status, words)));
146
+ }
147
+ };
148
+ var StationCardInstrumentElement = class extends StationCardPartElement {
149
+ static observedAttributes = ["thresholds", "unit"];
150
+ partName = "instrument";
151
+ render() {
152
+ const context = this.card();
153
+ const child = document.createElement("meteo-current-conditions");
154
+ child.station = context.station;
155
+ child.strings = context.strings;
156
+ child.thresholds = cardPartThresholds(partThresholds(this), context.thresholds);
157
+ child.formatTime = context.formatTime;
158
+ child.servedAt = context.servedAt;
159
+ child.receivedAtMs = context.receivedAtMs;
160
+ child.setAttribute("unit", this.getAttribute("unit") ?? context.unit);
161
+ this.replaceChildren(child);
162
+ }
163
+ };
164
+ function partThresholds(part) {
165
+ const raw = part.getAttribute("thresholds");
166
+ if (raw == null) return void 0;
167
+ if (raw.trim() === "none") return null;
168
+ try {
169
+ return JSON.parse(raw);
170
+ } catch {
171
+ return;
172
+ }
173
+ }
174
+ var StationCardChartElement = class extends StationCardPartElement {
175
+ static observedAttributes = [
176
+ "plot-height",
177
+ "thresholds",
178
+ "unit"
179
+ ];
180
+ partName = "chart";
181
+ render() {
182
+ const context = this.card();
183
+ const child = document.createElement("meteo-wind-history-chart");
184
+ child.station = context.station;
185
+ child.strings = context.strings;
186
+ child.thresholds = cardPartThresholds(partThresholds(this), context.thresholds);
187
+ child.formatTime = context.formatTime;
188
+ child.setAttribute("unit", this.getAttribute("unit") ?? context.unit);
189
+ const plotHeight = numberAttribute(this.getAttribute("plot-height"));
190
+ if (plotHeight != null) child.setAttribute("plot-height", String(plotHeight));
191
+ this.replaceChildren(child);
192
+ }
193
+ };
194
+ var StationCardSummaryElement = class extends StationCardPartElement {
195
+ partName = "summary";
196
+ render() {
197
+ const context = this.card();
198
+ const words = resolveStrings(context.strings);
199
+ const summary = summaryScene(context.station, context.unit, words, context.formatTime);
200
+ if (summary == null) {
201
+ this.replaceChildren();
202
+ return;
203
+ }
204
+ this.replaceChildren(h("dl", {
205
+ "aria-label": summary.ariaLabel,
206
+ class: summary.className
207
+ }, summary.items.map((item) => h("div", { class: summary.itemClassName }, h("dt", { class: summary.labelClassName }, item.label), h("dd", null, item.value)))));
208
+ }
209
+ };
210
+ //#endregion
211
+ export { StationCardChartElement, StationCardElement, StationCardHeaderElement, StationCardInstrumentElement, StationCardSummaryElement };
@@ -0,0 +1,32 @@
1
+ import { PollError } from "../../client/poll.js";
2
+ import { StationFeed } from "../../contract.js";
3
+ import "../../client/index.js";
4
+ import { SpeedThresholds } from "../../derive.js";
5
+ import { FormatTime, StationStringOverrides } from "../../strings.js";
6
+ import "../../index.js";
7
+ import { MeteoElement } from "../lib/base.js";
8
+ //#region src/elements/elements/StationFeedElement.d.ts
9
+ declare class StationFeedElement extends MeteoElement {
10
+ #private;
11
+ static readonly observedAttributes: string[];
12
+ constructor();
13
+ get feed(): StationFeed | null;
14
+ set feed(value: StationFeed | null);
15
+ get receivedAtMs(): number | null;
16
+ set receivedAtMs(value: number | null);
17
+ get strings(): StationStringOverrides | undefined;
18
+ set strings(value: StationStringOverrides | undefined);
19
+ get formatTime(): FormatTime | undefined;
20
+ set formatTime(value: FormatTime | undefined);
21
+ get thresholds(): SpeedThresholds | undefined;
22
+ set thresholds(value: SpeedThresholds | undefined);
23
+ get fetchInit(): RequestInit | undefined;
24
+ set fetchInit(value: RequestInit | undefined);
25
+ get error(): PollError | null;
26
+ refresh(): void;
27
+ protected connected(): void;
28
+ attributeChangedCallback(name: string): void;
29
+ protected render(): void;
30
+ }
31
+ //#endregion
32
+ export { StationFeedElement };