@glasshome/widget-sdk 1.31.1 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6443,5 +6443,154 @@
6443
6443
  "useWidgetViewer",
6444
6444
  "widgetFields",
6445
6445
  "z"
6446
+ ],
6447
+ "1.32.0": [
6448
+ "Badge",
6449
+ "Button",
6450
+ "ButtonGroup",
6451
+ "CameraSourceContext",
6452
+ "CameraStream",
6453
+ "Carousel",
6454
+ "CarouselContent",
6455
+ "CarouselDots",
6456
+ "CarouselItem",
6457
+ "CarouselNext",
6458
+ "CarouselPrevious",
6459
+ "ColorDisc",
6460
+ "ColorSlider",
6461
+ "ColorWheel",
6462
+ "CountPill",
6463
+ "Icon",
6464
+ "Input",
6465
+ "Label",
6466
+ "PanelEntityRow",
6467
+ "PanelFacts",
6468
+ "PanelRow",
6469
+ "PanelRows",
6470
+ "PanelSection",
6471
+ "Progress",
6472
+ "ResponsiveDialog",
6473
+ "ResponsiveDialogBody",
6474
+ "ResponsiveDialogClose",
6475
+ "ResponsiveDialogContent",
6476
+ "ResponsiveDialogDescription",
6477
+ "ResponsiveDialogFooter",
6478
+ "ResponsiveDialogHeader",
6479
+ "ResponsiveDialogTitle",
6480
+ "SDK_VERSION",
6481
+ "SchemaForm",
6482
+ "SectionIcon",
6483
+ "SectionTitle",
6484
+ "Select",
6485
+ "SelectContent",
6486
+ "SelectItem",
6487
+ "SelectTrigger",
6488
+ "SelectValue",
6489
+ "Slider",
6490
+ "SwatchPicker",
6491
+ "Switch",
6492
+ "Tabs",
6493
+ "TabsContent",
6494
+ "TabsList",
6495
+ "TabsTrigger",
6496
+ "TemperatureBar",
6497
+ "Toggle",
6498
+ "ToggleGroup",
6499
+ "ToggleGroupItem",
6500
+ "ToneSchema",
6501
+ "Widget",
6502
+ "WidgetAction",
6503
+ "WidgetBackdrop",
6504
+ "WidgetChip",
6505
+ "WidgetChoice",
6506
+ "WidgetContent",
6507
+ "WidgetControls",
6508
+ "WidgetCtx",
6509
+ "WidgetDebugTab",
6510
+ "WidgetDebugView",
6511
+ "WidgetDialog",
6512
+ "WidgetGlyph",
6513
+ "WidgetHead",
6514
+ "WidgetHero",
6515
+ "WidgetIcon",
6516
+ "WidgetLayer",
6517
+ "WidgetManifestSchema",
6518
+ "WidgetSizeCtx",
6519
+ "WidgetSliderFill",
6520
+ "WidgetStatus",
6521
+ "WidgetStepper",
6522
+ "WidgetTitle",
6523
+ "WidgetValue",
6524
+ "buildDebugData",
6525
+ "byDomain",
6526
+ "calculateLightGroup",
6527
+ "calculateSensorGroup",
6528
+ "copyText",
6529
+ "countActiveEntities",
6530
+ "defineConfig",
6531
+ "defineWidget",
6532
+ "deprecations",
6533
+ "field",
6534
+ "formatDeprecation",
6535
+ "formatSchemaError",
6536
+ "getEntityAttribute",
6537
+ "getForecasts",
6538
+ "getStream",
6539
+ "getWebRtcClientConfig",
6540
+ "hassMediaUrl",
6541
+ "imagePreset",
6542
+ "imageSrc",
6543
+ "imageUrl",
6544
+ "injectTokens",
6545
+ "isDark",
6546
+ "isEntityActive",
6547
+ "isPanelControllable",
6548
+ "mediaUrl",
6549
+ "monotoneCubicPath",
6550
+ "parseColor",
6551
+ "presetValue",
6552
+ "provideCameraSource",
6553
+ "sendWebRtcCandidate",
6554
+ "startWebRtcSession",
6555
+ "state",
6556
+ "svgColors",
6557
+ "trackEntityHistory",
6558
+ "untrackEntityHistory",
6559
+ "useArea",
6560
+ "useCalendarEvents",
6561
+ "useCamera",
6562
+ "useCameraSource",
6563
+ "useConfirm",
6564
+ "useConnection",
6565
+ "useCopyText",
6566
+ "useCurrency",
6567
+ "useDaylight",
6568
+ "useEntities",
6569
+ "useEntity",
6570
+ "useEntityHistory",
6571
+ "useEntityStatistics",
6572
+ "useForecast",
6573
+ "useHassConfig",
6574
+ "useIntersectionPause",
6575
+ "useLocale",
6576
+ "useMaterial",
6577
+ "useReducedMotion",
6578
+ "useService",
6579
+ "useStore",
6580
+ "useTemperatureUnit",
6581
+ "useToggle",
6582
+ "useTurnOff",
6583
+ "useTurnOn",
6584
+ "useUnitSystem",
6585
+ "useWidgetContext",
6586
+ "useWidgetDashboard",
6587
+ "useWidgetDialog",
6588
+ "useWidgetDimensions",
6589
+ "useWidgetEntityGroup",
6590
+ "useWidgetGestures",
6591
+ "useWidgetState",
6592
+ "useWidgetViewer",
6593
+ "widgetFields",
6594
+ "z"
6446
6595
  ]
6447
6596
  }
package/dist/index.js CHANGED
@@ -3405,7 +3405,7 @@ function fs(e) {
3405
3405
  //#region src/version.ts
3406
3406
  var ps = {
3407
3407
  name: "@glasshome/widget-sdk",
3408
- version: "1.31.1",
3408
+ version: "1.32.0",
3409
3409
  description: "SDK for building GlassHome dashboard widgets with SolidJS",
3410
3410
  keywords: [
3411
3411
  "dashboard",
@@ -1,18 +1,28 @@
1
1
  import { type JSX } from "solid-js";
2
2
  export interface CameraStreamProps {
3
3
  entityId: string;
4
- kind: "webrtc" | "hls";
4
+ /** `image` shows `src`, an MJPEG stream or a snapshot, in the same box and full screen. */
5
+ kind: "webrtc" | "hls" | "image";
6
+ /** The picture an `image` stream shows; a new value replaces it in place. */
7
+ src?: string;
8
+ /** A new value restarts the stream in place, so full screen stays. */
9
+ session?: number;
5
10
  muted: boolean;
6
11
  poster?: string;
7
12
  /** How the video fills the stream's box; `cover` by default. */
8
13
  fit?: "cover" | "contain";
9
14
  /** Shows a full screen control, which fills the screen with the stream from the homeowner's press. */
10
15
  fullscreen?: boolean;
16
+ /** Shows a sound control in full screen, which reports through `onMutedChange`. */
17
+ sound?: boolean;
11
18
  class?: string;
12
19
  onLive?: () => void;
13
20
  onAudio?: (has: boolean) => void;
14
21
  onError?: (reason: string) => void;
15
22
  onStale?: (reason: string) => void;
23
+ /** Where a stream that has not played yet stands, each time that changes. */
24
+ onStage?: (stage: string) => void;
25
+ onMutedChange?: (muted: boolean) => void;
16
26
  }
17
- /** A camera's live video, over WebRTC or HLS, from the camera source the host provides. */
27
+ /** A camera's live picture, over WebRTC, HLS or an image, from the camera source the host provides. */
18
28
  export declare function CameraStream(props: CameraStreamProps): JSX.Element;
@@ -1,12 +1,12 @@
1
1
  import { useCameraSource as e } from "./camera-source.js";
2
2
  import { Show as t, createEffect as n, createSignal as r, on as i, onCleanup as a, onMount as o } from "solid-js";
3
- import { className as s, createComponent as c, effect as l, insert as u, setAttribute as d, style as f, template as p, use as m } from "solid-js/web";
4
- import { Button as h, Icon as g } from "@glasshome/ui/solid";
3
+ import { className as s, createComponent as c, effect as l, insert as u, memo as d, setAttribute as f, setStyleProperty as p, style as m, template as h, use as g } from "solid-js/web";
4
+ import { Button as _, Icon as v } from "@glasshome/ui/solid";
5
5
  //#region src/media/drivers/hls.ts
6
- var _ = 2, v = 2e3, y = (e) => e.audioTracks?.length ?? 0;
7
- function b(e, t, n) {
6
+ var y = 2, b = 2e3, x = (e) => e.audioTracks?.length ?? 0;
7
+ function S(e, t, n) {
8
8
  let r = !1, i = null, a, o = () => {
9
- y(e) > 0 && n.onAudio(!0), n.onLive();
9
+ x(e) > 0 && n.onAudio(!0), n.onLive();
10
10
  }, s = () => n.onError(`native hls error: media error code ${e.error?.code ?? "unknown"}`);
11
11
  return e.addEventListener("playing", o), import("hls.js").then(({ default: o }) => {
12
12
  if (r) return;
@@ -25,7 +25,7 @@ function b(e, t, n) {
25
25
  }), c.on(o.Events.ERROR, (e, t) => {
26
26
  if (!t.fatal) return;
27
27
  let r = t.response?.code, s = r ? `${t.details} (http ${r})` : t.details;
28
- clearTimeout(a), t.type === o.ErrorTypes.MEDIA_ERROR && l++ < _ ? c.recoverMediaError() : t.type === o.ErrorTypes.NETWORK_ERROR && u++ < _ ? a = setTimeout(() => c.startLoad(), v) : (c.destroy(), i = null, n.onError(`hls ${t.type}: ${s}`));
28
+ clearTimeout(a), t.type === o.ErrorTypes.MEDIA_ERROR && l++ < y ? c.recoverMediaError() : t.type === o.ErrorTypes.NETWORK_ERROR && u++ < y ? a = setTimeout(() => c.startLoad(), b) : (c.destroy(), i = null, n.onError(`hls ${t.type}: ${s}`));
29
29
  }), c.loadSource(t), c.attachMedia(e);
30
30
  }).catch(() => {
31
31
  r || n.onError("hls player failed to load");
@@ -35,7 +35,7 @@ function b(e, t, n) {
35
35
  }
36
36
  //#endregion
37
37
  //#region src/media/drivers/types.ts
38
- function x(e) {
38
+ function C(e) {
39
39
  if (e instanceof Error) return e.message;
40
40
  if (typeof e == "object" && e) {
41
41
  let { message: t, code: n } = e;
@@ -46,131 +46,194 @@ function x(e) {
46
46
  }
47
47
  //#endregion
48
48
  //#region src/media/drivers/webrtc.ts
49
- function S(e, t, n) {
49
+ function w(e, t, n) {
50
50
  let r = null, i = null, a = !1, o = !1, s = "config", c = () => {
51
+ a || n.onStage(`stage ${s}, connection ${r?.connectionState ?? "none"}`);
52
+ }, l = (e) => {
53
+ s = e, c();
54
+ };
55
+ c();
56
+ let u = () => {
51
57
  o = !0, n.onLive();
52
58
  };
53
- return e.addEventListener("playing", c), (async () => {
59
+ return e.addEventListener("playing", u), (async () => {
54
60
  try {
55
- let c = await t.config();
61
+ let s = await t.config();
56
62
  if (a) return;
57
- let l = new RTCPeerConnection(c);
58
- r = l, l.ontrack = (t) => {
63
+ let u = new RTCPeerConnection(s);
64
+ r = u, u.ontrack = (t) => {
59
65
  t.track.kind === "audio" && n.onAudio(!0), t.streams[0] && !a && (e.srcObject = t.streams[0]);
60
- }, l.onconnectionstatechange = () => {
61
- l.connectionState === "failed" && (o ? n.onStale("ice connection failed") : n.onError("ice connection failed"));
62
- }, l.addTransceiver("audio", { direction: "recvonly" }), l.addTransceiver("video", { direction: "recvonly" }), s = "local offer";
63
- let u = await l.createOffer();
64
- if (await l.setLocalDescription(u), a) return;
65
- let d = null, f = [], p = (e) => {
66
- d ? t.candidate(d, e).catch(() => {}) : f.push(e);
66
+ }, u.onconnectionstatechange = () => {
67
+ o || c(), u.connectionState === "failed" && (o ? n.onStale("ice connection failed") : n.onError("ice connection failed"));
68
+ }, u.addTransceiver("audio", { direction: "recvonly" }), u.addTransceiver("video", { direction: "recvonly" }), l("local offer");
69
+ let d = await u.createOffer();
70
+ if (await u.setLocalDescription(d), a) return;
71
+ let f = null, p = [], m = (e) => {
72
+ f ? t.candidate(f, e).catch(() => {}) : p.push(e);
67
73
  };
68
- if (l.onicecandidate = (e) => {
69
- e.candidate && p(e.candidate.toJSON());
70
- }, !u.sdp) throw Error("offer has no sdp");
71
- s = "home assistant answer";
72
- let m = await t.start(u.sdp, (e) => {
74
+ if (u.onicecandidate = (e) => {
75
+ e.candidate && m(e.candidate.toJSON());
76
+ }, !d.sdp) throw Error("offer has no sdp");
77
+ l("home assistant answer");
78
+ let h = await t.start(d.sdp, (e) => {
73
79
  let t = { ...e };
74
- !t.sdpMid && t.sdpMLineIndex == null && (t.sdpMid = "0"), l.addIceCandidate(new RTCIceCandidate(t)).catch(() => {});
80
+ !t.sdpMid && t.sdpMLineIndex == null && (t.sdpMid = "0"), u.addIceCandidate(new RTCIceCandidate(t)).catch(() => {});
75
81
  });
76
- if (i = m.stop, a) {
77
- m.stop().catch(() => {});
82
+ if (i = h.stop, a) {
83
+ h.stop().catch(() => {});
78
84
  return;
79
85
  }
80
- d = m.sessionId;
81
- for (let e of f.splice(0)) p(e);
82
- s = "remote description", await l.setRemoteDescription({
86
+ f = h.sessionId;
87
+ for (let e of p.splice(0)) m(e);
88
+ l("remote description"), await u.setRemoteDescription({
83
89
  type: "answer",
84
- sdp: m.answer
90
+ sdp: h.answer
85
91
  });
86
92
  } catch (e) {
87
- a || n.onError(`${s}: ${x(e)}`);
93
+ a || n.onError(`${s}: ${C(e)}`);
88
94
  }
89
- })(), {
90
- stop: () => {
91
- a = !0, e.removeEventListener("playing", c), e.srcObject = null, i?.().catch(() => {}), i = null, r?.close(), r = null;
92
- },
93
- describe: () => `stage ${s}, connection ${r?.connectionState ?? "none"}`
94
- };
95
+ })(), { stop: () => {
96
+ a = !0, e.removeEventListener("playing", u), e.srcObject = null, i?.().catch(() => {}), i = null, r?.close(), r = null;
97
+ } };
95
98
  }
96
99
  //#endregion
97
100
  //#region src/media/camera-stream.tsx
98
- var C = /*#__PURE__*/ p("<div style=position:absolute;left:0.75rem;bottom:0.75rem>"), w = /*#__PURE__*/ p("<div style=position:relative;overflow:hidden><video autoplay playsinline>"), T = {
101
+ var T = /*#__PURE__*/ h("<div style=position:absolute;left:0.75rem;bottom:0.75rem;display:flex;gap:0.5rem>"), E = /*#__PURE__*/ h("<div style=position:relative;overflow:hidden><video autoplay playsinline>"), D = /*#__PURE__*/ h("<img alt>"), O = {
99
102
  position: "absolute",
100
103
  inset: "0",
101
104
  width: "100%",
102
105
  height: "100%"
103
106
  };
104
- function E(p) {
105
- let _ = e(), v, y, [E, D] = r(!1), O = typeof document < "u" && document.fullscreenEnabled;
107
+ function k(h) {
108
+ let y = e(), b, x, [k, A] = r(!1), j = typeof document < "u" && document.fullscreenEnabled, M = () => h.kind === "image";
106
109
  o(() => {
107
- n(i([() => p.entityId, () => p.kind], ([e, t]) => {
110
+ n(i([
111
+ () => h.entityId,
112
+ () => h.kind,
113
+ () => h.session
114
+ ], ([e, t]) => {
115
+ if (t === "image") return;
108
116
  let n = !0, r, i = {
109
- onLive: () => n && p.onLive?.(),
110
- onAudio: (e) => n && p.onAudio?.(e),
111
- onError: (e) => n && p.onError?.(e),
112
- onStale: (e) => n && p.onStale?.(e)
117
+ onLive: () => n && h.onLive?.(),
118
+ onAudio: (e) => n && h.onAudio?.(e),
119
+ onError: (e) => n && h.onError?.(e),
120
+ onStale: (e) => n && h.onStale?.(e),
121
+ onStage: (e) => n && h.onStage?.(e)
113
122
  };
114
123
  if (t === "webrtc") try {
115
- r = S(y, _.webrtc(e), i);
124
+ r = w(x, y.webrtc(e), i);
116
125
  } catch (e) {
117
- i.onError(`webrtc: ${x(e)}`);
126
+ i.onError(`webrtc: ${C(e)}`);
118
127
  }
119
- else Promise.resolve().then(() => _.stream(e, "hls")).then((e) => {
120
- n && (e ? r = b(y, e, i) : i.onError("home assistant returned no hls url"));
121
- }).catch((e) => i.onError(`hls stream request: ${x(e)}`));
128
+ else i.onStage("hls stream request"), Promise.resolve().then(() => y.stream(e, "hls")).then((e) => {
129
+ if (n) {
130
+ if (!e) return i.onError("home assistant returned no hls url");
131
+ i.onStage("hls playlist"), r = S(x, e, i);
132
+ }
133
+ }).catch((e) => i.onError(`hls stream request: ${C(e)}`));
122
134
  a(() => {
123
- n = !1, r?.stop(), y.removeAttribute("src"), y.load();
135
+ n = !1, r?.stop(), x.removeAttribute("src"), x.load();
124
136
  });
125
137
  }));
126
- let e = () => D(document.fullscreenElement === v);
138
+ let e = () => A(document.fullscreenElement === b);
127
139
  document.addEventListener("fullscreenchange", e), a(() => {
128
- document.removeEventListener("fullscreenchange", e), document.fullscreenElement === v && document.exitFullscreen();
140
+ document.removeEventListener("fullscreenchange", e), document.fullscreenElement === b && document.exitFullscreen();
129
141
  });
130
142
  });
131
- let k = () => {
132
- E() ? document.exitFullscreen() : v.requestFullscreen();
143
+ let N = () => {
144
+ k() ? document.exitFullscreen() : b.requestFullscreen();
133
145
  };
134
146
  return (() => {
135
- var e = w(), n = e.firstChild, r = v;
136
- typeof r == "function" ? m(r, e) : v = e;
137
- var i = y;
138
- return typeof i == "function" ? m(i, n) : y = n, u(e, c(t, {
147
+ var e = E(), n = e.firstChild, r = b;
148
+ typeof r == "function" ? g(r, e) : b = e;
149
+ var i = x;
150
+ return typeof i == "function" ? g(i, n) : x = n, u(e, c(t, {
151
+ get when() {
152
+ return d(() => !!M())() && { session: h.session };
153
+ },
154
+ keyed: !0,
155
+ children: (e) => {
156
+ let t = !0, n;
157
+ return a(() => {
158
+ t = !1, n.removeAttribute("src");
159
+ }), (() => {
160
+ var e = D();
161
+ e.addEventListener("error", () => t && h.onError?.("image error")), e.addEventListener("load", () => t && h.onLive?.());
162
+ var r = n;
163
+ return typeof r == "function" ? g(r, e) : n = e, l((t) => {
164
+ var n = h.src, r = {
165
+ ...O,
166
+ "object-fit": k() ? "contain" : h.fit ?? "cover"
167
+ };
168
+ return n !== t.e && f(e, "src", t.e = n), t.t = m(e, r, t.t), t;
169
+ }, {
170
+ e: void 0,
171
+ t: void 0
172
+ }), e;
173
+ })();
174
+ }
175
+ }), null), u(e, c(t, {
139
176
  get when() {
140
- return p.fullscreen && O;
177
+ return h.fullscreen && j;
141
178
  },
142
179
  get children() {
143
- var e = C();
144
- return u(e, c(h, {
180
+ var e = T();
181
+ return u(e, c(_, {
145
182
  variant: "outline",
146
183
  size: "icon",
147
184
  get "aria-label"() {
148
- return E() ? "Exit full screen" : "Full screen";
185
+ return k() ? "Exit full screen" : "Full screen";
149
186
  },
150
- onClick: k,
187
+ onClick: N,
151
188
  get children() {
152
- return c(g, {
189
+ return c(v, {
153
190
  get icon() {
154
- return E() ? "mdi:fullscreen-exit" : "mdi:fullscreen";
191
+ return k() ? "mdi:fullscreen-exit" : "mdi:fullscreen";
155
192
  },
156
193
  width: 18
157
194
  });
158
195
  }
159
- })), e;
196
+ }), null), u(e, c(t, {
197
+ get when() {
198
+ return d(() => !!k())() && h.sound;
199
+ },
200
+ get children() {
201
+ return c(_, {
202
+ get variant() {
203
+ return h.muted ? "outline" : "default";
204
+ },
205
+ size: "icon",
206
+ get "aria-label"() {
207
+ return h.muted ? "Turn sound on" : "Turn sound off";
208
+ },
209
+ onClick: () => h.onMutedChange?.(!h.muted),
210
+ get children() {
211
+ return c(v, {
212
+ get icon() {
213
+ return h.muted ? "mdi:volume-off" : "mdi:volume-high";
214
+ },
215
+ width: 18
216
+ });
217
+ }
218
+ });
219
+ }
220
+ }), null), e;
160
221
  }
161
222
  }), null), l((t) => {
162
- var r = p.class, i = p.muted, a = p.poster, o = {
163
- ...T,
164
- "object-fit": p.fit ?? "cover"
223
+ var r = h.class, i = k() ? "black" : void 0, a = h.muted, o = M() ? void 0 : h.poster, c = {
224
+ ...O,
225
+ "object-fit": h.fit ?? "cover",
226
+ display: M() ? "none" : void 0
165
227
  };
166
- return r !== t.e && s(e, t.e = r), i !== t.t && (n.muted = t.t = i), a !== t.a && d(n, "poster", t.a = a), t.o = f(n, o, t.o), t;
228
+ return r !== t.e && s(e, t.e = r), i !== t.t && p(e, "background", t.t = i), a !== t.a && (n.muted = t.a = a), o !== t.o && f(n, "poster", t.o = o), t.i = m(n, c, t.i), t;
167
229
  }, {
168
230
  e: void 0,
169
231
  t: void 0,
170
232
  a: void 0,
171
- o: void 0
233
+ o: void 0,
234
+ i: void 0
172
235
  }), e;
173
236
  })();
174
237
  }
175
238
  //#endregion
176
- export { E as CameraStream };
239
+ export { k as CameraStream };
@@ -3,9 +3,9 @@ export interface StreamCallbacks {
3
3
  onAudio: (has: boolean) => void;
4
4
  onError: (reason: string) => void;
5
5
  onStale: (reason: string) => void;
6
+ onStage: (stage: string) => void;
6
7
  }
7
8
  export interface StreamDriver {
8
9
  stop: () => void;
9
- describe?: () => string;
10
10
  }
11
11
  export declare function reasonOf(err: unknown): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/widget-sdk",
3
- "version": "1.31.1",
3
+ "version": "1.32.0",
4
4
  "description": "SDK for building GlassHome dashboard widgets with SolidJS",
5
5
  "keywords": [
6
6
  "dashboard",