glimpse-sdk 0.7.0 → 0.9.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.
@@ -1,602 +0,0 @@
1
- export class InlineHandlerRegistry {
2
- handlers = new Map();
3
- add(event, id, handler) {
4
- this.handlers.set(`${event}:${id}`, handler);
5
- }
6
- }
7
- export class WidgetBase {
8
- common;
9
- constructor(common = {}) {
10
- this.common = common;
11
- }
12
- bindHandlers(_registry, _path) { }
13
- toProtocol() {
14
- return { type: this.type, data: this.data() };
15
- }
16
- commonData() {
17
- const out = {};
18
- if (this.common.visible !== undefined)
19
- out.visible = this.common.visible;
20
- if (this.common.tooltip !== undefined)
21
- out.tooltip = this.common.tooltip;
22
- if (this.common.css_classes?.length)
23
- out.css_classes = this.common.css_classes;
24
- if (this.common.styles && Object.keys(this.common.styles).length > 0)
25
- out.styles = this.common.styles;
26
- return out;
27
- }
28
- }
29
- const child = (node) => node?.toProtocol();
30
- const children = (nodes) => nodes.map((node) => node.toProtocol());
31
- export class Label extends WidgetBase {
32
- type = "label";
33
- options;
34
- constructor(options) {
35
- const normalized = typeof options === "string" ? { label: options } : options;
36
- super(normalized);
37
- this.options = normalized;
38
- }
39
- data() {
40
- const out = { ...this.commonData(), label: this.options.label };
41
- if (this.options.xalign !== undefined)
42
- out.xalign = this.options.xalign;
43
- if (this.options.wrap !== undefined)
44
- out.wrap = this.options.wrap;
45
- return out;
46
- }
47
- }
48
- export class Header extends WidgetBase {
49
- options;
50
- type = "header";
51
- constructor(options) {
52
- super(options);
53
- this.options = options;
54
- }
55
- data() { return { ...this.commonData(), label: this.options.label }; }
56
- }
57
- export class Hero extends WidgetBase {
58
- options;
59
- type = "hero";
60
- constructor(options) {
61
- super(options);
62
- this.options = options;
63
- }
64
- data() {
65
- const out = { ...this.commonData(), title: this.options.title, subtitle: this.options.subtitle ?? "" };
66
- for (const key of ["id", "icon", "icon_size", "toggle", "toggle_sensitive", "separator"]) {
67
- if (this.options[key] !== undefined)
68
- out[key] = this.options[key];
69
- }
70
- const trailing = child(this.options.trailing);
71
- if (trailing)
72
- out.trailing = trailing;
73
- return out;
74
- }
75
- bindHandlers(registry, path) {
76
- if (this.options.id && this.options.on_toggle)
77
- registry.add("toggle", this.options.id, this.options.on_toggle);
78
- this.options.trailing?.bindHandlers(registry, [...path, 0]);
79
- }
80
- }
81
- export class Badge extends WidgetBase {
82
- options;
83
- type = "badge";
84
- constructor(options) {
85
- super(options);
86
- this.options = options;
87
- }
88
- data() { return { ...this.commonData(), label: this.options.label, kind: this.options.kind ?? "default" }; }
89
- }
90
- export class StatusDot extends WidgetBase {
91
- options;
92
- type = "status_dot";
93
- constructor(options = {}) {
94
- super(options);
95
- this.options = options;
96
- }
97
- data() { return { ...this.commonData(), status: this.options.status ?? "neutral" }; }
98
- }
99
- export class PanelIndicator extends WidgetBase {
100
- options;
101
- type = "panel_indicator";
102
- constructor(options) {
103
- super(options);
104
- this.options = options;
105
- }
106
- data() {
107
- const out = { ...this.commonData(), active: this.options.active ?? false, checked: this.options.checked ?? false, needs_attention: this.options.needs_attention ?? false };
108
- for (const key of ["id", "icon", "label"])
109
- if (this.options[key] !== undefined)
110
- out[key] = this.options[key];
111
- const extra = child(this.options.extra);
112
- if (extra)
113
- out.extra = extra;
114
- return out;
115
- }
116
- bindHandlers(registry, path) {
117
- if (this.options.id && this.options.on_click)
118
- registry.add("click", this.options.id, this.options.on_click);
119
- this.options.extra?.bindHandlers(registry, [...path, 0]);
120
- }
121
- }
122
- export class EmptyState extends WidgetBase {
123
- options;
124
- type = "empty_state";
125
- constructor(options) {
126
- super(options);
127
- this.options = options;
128
- }
129
- data() {
130
- const out = { ...this.commonData(), title: this.options.title };
131
- if (this.options.subtitle !== undefined)
132
- out.subtitle = this.options.subtitle;
133
- return out;
134
- }
135
- }
136
- export class Spinner extends WidgetBase {
137
- options;
138
- type = "spinner";
139
- constructor(options = {}) {
140
- super(options);
141
- this.options = options;
142
- }
143
- data() { return { ...this.commonData(), spinning: this.options.spinning ?? true }; }
144
- }
145
- export class Meter extends WidgetBase {
146
- options;
147
- type = "meter";
148
- constructor(options = {}) {
149
- super(options);
150
- this.options = options;
151
- }
152
- data() {
153
- const out = {
154
- ...this.commonData(),
155
- label: this.options.label ?? "",
156
- value: this.options.value ?? 0,
157
- min: this.options.min ?? 0,
158
- max: this.options.max ?? 1,
159
- step: this.options.step ?? 0.01,
160
- interactive: this.options.interactive ?? this.options.on_change !== undefined,
161
- };
162
- for (const key of ["id", "icon", "text"])
163
- if (this.options[key] !== undefined)
164
- out[key] = this.options[key];
165
- return out;
166
- }
167
- bindHandlers(registry, _path) {
168
- if (this.options.id && this.options.on_change)
169
- registry.add("change", this.options.id, this.options.on_change);
170
- }
171
- }
172
- export class Separator extends WidgetBase {
173
- type = "separator";
174
- constructor(common = {}) { super(common); }
175
- data() { return this.commonData(); }
176
- }
177
- export class Scroll extends WidgetBase {
178
- options;
179
- type = "scroll";
180
- constructor(options) {
181
- super(options);
182
- this.options = options;
183
- }
184
- data() { return { ...this.commonData(), child: this.options.child.toProtocol() }; }
185
- bindHandlers(registry, path) {
186
- this.options.child.bindHandlers(registry, [...path, 0]);
187
- }
188
- }
189
- class ChildrenWidget extends WidgetBase {
190
- constructor(common = {}) { super(common); this.kids = common.children ?? []; }
191
- kids;
192
- data() { return { ...this.commonData(), children: children(this.kids) }; }
193
- bindHandlers(registry, path) {
194
- this.kids.forEach((kid, index) => kid.bindHandlers(registry, [...path, index]));
195
- }
196
- }
197
- export class Row extends ChildrenWidget {
198
- type = "row";
199
- }
200
- export class Column extends ChildrenWidget {
201
- type = "column";
202
- }
203
- export class BoxedList extends ChildrenWidget {
204
- type = "boxed_list";
205
- }
206
- export class ButtonRow extends ChildrenWidget {
207
- type = "button_row";
208
- }
209
- export class CircleBox extends WidgetBase {
210
- options;
211
- type = "circle_box";
212
- constructor(options) {
213
- super(options);
214
- this.options = options;
215
- }
216
- data() {
217
- const out = this.commonData();
218
- out.color = this.options.color;
219
- return out;
220
- }
221
- }
222
- export class Container extends ChildrenWidget {
223
- type = "container";
224
- }
225
- export class PopoverShell extends ChildrenWidget {
226
- options;
227
- type = "popover_shell";
228
- constructor(options = {}) {
229
- super(options);
230
- this.options = options;
231
- }
232
- data() {
233
- const out = { ...super.data(), size: this.options.size ?? "medium" };
234
- if ((this.options.footer ?? []).length > 0)
235
- out.footer = children(this.options.footer ?? []);
236
- if (this.options.footer_visible)
237
- out.footer_visible = this.options.footer_visible;
238
- return out;
239
- }
240
- bindHandlers(registry, path) {
241
- super.bindHandlers(registry, path);
242
- (this.options.footer ?? []).forEach((kid, index) => kid.bindHandlers(registry, [...path, this.kids.length + index]));
243
- }
244
- }
245
- export class Tile extends WidgetBase {
246
- options;
247
- type = "tile";
248
- constructor(options) {
249
- super(options);
250
- this.options = options;
251
- }
252
- data() {
253
- const out = { ...this.commonData(), primary: this.options.primary, activatable: this.options.activatable ?? false };
254
- for (const key of ["id", "secondary", "left_icon"])
255
- if (this.options[key] !== undefined)
256
- out[key] = this.options[key];
257
- const left = child(this.options.left);
258
- const right = child(this.options.right);
259
- if (left)
260
- out.left = left;
261
- if (right)
262
- out.right = right;
263
- return out;
264
- }
265
- bindHandlers(registry, path) {
266
- if (this.options.id && this.options.on_click)
267
- registry.add("click", this.options.id, this.options.on_click);
268
- this.options.left?.bindHandlers(registry, [...path, 0]);
269
- this.options.right?.bindHandlers(registry, [...path, 1]);
270
- }
271
- }
272
- export class SegmentedTile extends Tile {
273
- options;
274
- type = "segmented_tile";
275
- constructor(options) {
276
- super(options);
277
- this.options = options;
278
- }
279
- data() {
280
- const out = super.data();
281
- const nested = child(this.options.child);
282
- if (nested)
283
- out.child = nested;
284
- out.expanded = this.options.expanded ?? false;
285
- return out;
286
- }
287
- bindHandlers(registry, path) {
288
- super.bindHandlers(registry, path);
289
- if (this.options.id && this.options.on_toggle)
290
- registry.add("toggle", this.options.id, this.options.on_toggle);
291
- this.options.child?.bindHandlers(registry, [...path, 2]);
292
- }
293
- }
294
- export class SwitchTile extends WidgetBase {
295
- options;
296
- type = "switch_tile";
297
- constructor(options) {
298
- super(options);
299
- this.options = options;
300
- }
301
- data() {
302
- const out = { ...this.commonData(), id: this.options.id, primary: this.options.primary, active: this.options.active ?? false };
303
- for (const key of ["secondary", "left_icon"])
304
- if (this.options[key] !== undefined)
305
- out[key] = this.options[key];
306
- const left = child(this.options.left);
307
- if (left)
308
- out.left = left;
309
- return out;
310
- }
311
- bindHandlers(registry, path) {
312
- if (this.options.on_toggle)
313
- registry.add("toggle", this.options.id, this.options.on_toggle);
314
- this.options.left?.bindHandlers(registry, [...path, 0]);
315
- }
316
- }
317
- export class ExpanderTile extends WidgetBase {
318
- options;
319
- type = "expander_tile";
320
- constructor(options) {
321
- super(options);
322
- this.options = options;
323
- }
324
- data() {
325
- const out = { ...this.commonData(), primary: this.options.primary, expanded: this.options.expanded ?? false };
326
- for (const key of ["id", "secondary", "left_icon"])
327
- if (this.options[key] !== undefined)
328
- out[key] = this.options[key];
329
- const left = child(this.options.left);
330
- const nested = child(this.options.child);
331
- if (left)
332
- out.left = left;
333
- if (nested)
334
- out.child = nested;
335
- return out;
336
- }
337
- bindHandlers(registry, path) {
338
- if (this.options.id && this.options.on_toggle)
339
- registry.add("toggle", this.options.id, this.options.on_toggle);
340
- this.options.left?.bindHandlers(registry, [...path, 0]);
341
- this.options.child?.bindHandlers(registry, [...path, 1]);
342
- }
343
- }
344
- export class SliderTile extends WidgetBase {
345
- options;
346
- type = "slider_tile";
347
- constructor(options) {
348
- super(options);
349
- this.options = options;
350
- }
351
- data() {
352
- const out = { ...this.commonData(), id: this.options.id, value: this.options.value ?? 0, min: this.options.min ?? 0, max: this.options.max ?? 1, step: this.options.step ?? 0.01, page: this.options.page ?? 0.1, digits: this.options.digits ?? 0 };
353
- for (const key of ["label", "left_icon", "snap_step"])
354
- if (this.options[key] !== undefined)
355
- out[key] = this.options[key];
356
- const left = child(this.options.left);
357
- if (left)
358
- out.left = left;
359
- return out;
360
- }
361
- bindHandlers(registry, path) {
362
- if (this.options.on_change)
363
- registry.add("change", this.options.id, this.options.on_change);
364
- this.options.left?.bindHandlers(registry, [...path, 0]);
365
- }
366
- }
367
- export class ChoiceTile extends WidgetBase {
368
- options;
369
- type = "choice_tile";
370
- constructor(options) {
371
- super(options);
372
- this.options = options;
373
- }
374
- data() {
375
- const out = { ...this.commonData(), primary: this.options.primary, selected: this.options.selected ?? false };
376
- for (const key of ["id", "secondary", "left_icon"])
377
- if (this.options[key] !== undefined)
378
- out[key] = this.options[key];
379
- const left = child(this.options.left);
380
- if (left)
381
- out.left = left;
382
- return out;
383
- }
384
- bindHandlers(registry, path) {
385
- if (this.options.id && this.options.on_click)
386
- registry.add("click", this.options.id, this.options.on_click);
387
- this.options.left?.bindHandlers(registry, [...path, 0]);
388
- }
389
- }
390
- export class Choice {
391
- options;
392
- constructor(options) {
393
- this.options = options;
394
- }
395
- toProtocol() {
396
- const out = { id: this.options.id, primary: this.options.primary };
397
- if (this.options.secondary !== undefined)
398
- out.secondary = this.options.secondary;
399
- if (this.options.icon !== undefined)
400
- out.icon = this.options.icon;
401
- return out;
402
- }
403
- }
404
- export class ChoiceList extends WidgetBase {
405
- options;
406
- type = "choice_list";
407
- constructor(options) {
408
- super(options);
409
- this.options = options;
410
- }
411
- data() {
412
- const out = { ...this.commonData(), id: this.options.id, choices: (this.options.choices ?? []).map((choice) => choice.toProtocol()) };
413
- if (this.options.active !== undefined)
414
- out.active = this.options.active;
415
- return out;
416
- }
417
- bindHandlers(registry, _path) {
418
- if (this.options.on_change)
419
- registry.add("change", this.options.id, this.options.on_change);
420
- }
421
- }
422
- export class KeyValueGrid extends WidgetBase {
423
- options;
424
- type = "key_value_grid";
425
- constructor(options = {}) {
426
- super(options);
427
- this.options = options;
428
- }
429
- data() { return { ...this.commonData(), rows: this.options.rows ?? [] }; }
430
- }
431
- export class PagerItem extends WidgetBase {
432
- options;
433
- type = "pager_item";
434
- constructor(options) {
435
- super(options);
436
- this.options = options;
437
- }
438
- data() { return { ...this.commonData(), id: this.options.id, label: this.options.label ?? "", appearance: this.options.appearance ?? "dots", active: this.options.active ?? false, inactive: this.options.inactive ?? false, occupied: this.options.occupied ?? false, urgent: this.options.urgent ?? false }; }
439
- bindHandlers(registry, _path) { if (this.options.on_click)
440
- registry.add("click", String(this.options.id), this.options.on_click); }
441
- }
442
- export class PagerStrip extends WidgetBase {
443
- options;
444
- type = "pager_strip";
445
- constructor(options = {}) {
446
- super(options);
447
- this.options = options;
448
- }
449
- data() {
450
- const out = { ...this.commonData(), placeholder: this.options.placeholder ?? false, items: (this.options.items ?? []).map((item) => item.data()) };
451
- if (this.options.id !== undefined)
452
- out.id = this.options.id;
453
- return out;
454
- }
455
- bindHandlers(registry, path) {
456
- if (this.options.id && this.options.on_change)
457
- registry.add("change", this.options.id, this.options.on_change);
458
- (this.options.items ?? []).forEach((item, index) => item.bindHandlers(registry, [...path, index]));
459
- }
460
- }
461
- class ActiveIndicator extends WidgetBase {
462
- options;
463
- constructor(options = {}) {
464
- super(options);
465
- this.options = options;
466
- }
467
- data() { return { ...this.commonData(), active: this.options.active ?? false }; }
468
- }
469
- export class CameraIndicator extends ActiveIndicator {
470
- type = "camera_indicator";
471
- }
472
- export class MicIndicator extends ActiveIndicator {
473
- type = "mic_indicator";
474
- }
475
- export class MutedIndicator extends ActiveIndicator {
476
- type = "muted_indicator";
477
- }
478
- export class LocationIndicator extends ActiveIndicator {
479
- type = "location_indicator";
480
- }
481
- export class ScreenCastIndicator extends ActiveIndicator {
482
- options;
483
- type = "screencast_indicator";
484
- constructor(options = {}) {
485
- super(options);
486
- this.options = options;
487
- }
488
- data() {
489
- const out = super.data();
490
- if (this.options.timer_text !== undefined)
491
- out.timer_text = this.options.timer_text;
492
- return out;
493
- }
494
- }
495
- export class Calendar extends WidgetBase {
496
- options;
497
- type = "calendar";
498
- constructor(options) {
499
- super(options);
500
- this.options = options;
501
- }
502
- data() {
503
- const out = { ...this.commonData(), selected_date: this.options.selected_date, event_days: this.options.event_days ?? [] };
504
- if (this.options.id !== undefined)
505
- out.id = this.options.id;
506
- return out;
507
- }
508
- bindHandlers(registry, _path) { if (this.options.id && this.options.on_change)
509
- registry.add("change", this.options.id, this.options.on_change); }
510
- }
511
- export class BatteryHero extends WidgetBase {
512
- options;
513
- type = "battery_hero";
514
- constructor(options) {
515
- super(options);
516
- this.options = options;
517
- }
518
- data() { return { ...this.commonData(), icon: this.options.icon, percentage: this.options.percentage, fraction: this.options.fraction, state: this.options.state }; }
519
- }
520
- export class DateHero extends WidgetBase {
521
- options;
522
- type = "date_hero";
523
- constructor(options) {
524
- super(options);
525
- this.options = options;
526
- }
527
- data() { return { ...this.commonData(), weekday: this.options.weekday, date: this.options.date }; }
528
- }
529
- export class EventItem {
530
- options;
531
- constructor(options) {
532
- this.options = options;
533
- }
534
- toProtocol() {
535
- const out = { id: this.options.id, title: this.options.title, start: this.options.start, end: this.options.end ?? "", all_day: this.options.all_day ?? false };
536
- if (this.options.location !== undefined)
537
- out.location = this.options.location;
538
- return out;
539
- }
540
- }
541
- export class Events extends WidgetBase {
542
- options;
543
- type = "events";
544
- constructor(options) {
545
- super(options);
546
- this.options = options;
547
- }
548
- data() { return { ...this.commonData(), date: this.options.date, loading: this.options.loading ?? false, events: (this.options.events ?? []).map((event) => event.toProtocol()) }; }
549
- }
550
- export class WeatherForecastItem {
551
- options;
552
- constructor(options) {
553
- this.options = options;
554
- }
555
- toProtocol() { return { day_name: this.options.day_name, icon: this.options.icon, condition: this.options.condition, temperatures: this.options.temperatures, is_today: this.options.is_today ?? false }; }
556
- }
557
- export class WeatherForecastList extends WidgetBase {
558
- options;
559
- type = "weather_forecast_list";
560
- constructor(options = {}) {
561
- super(options);
562
- this.options = options;
563
- }
564
- data() { return { ...this.commonData(), items: (this.options.items ?? []).map((item) => item.toProtocol()) }; }
565
- }
566
- export class WeatherHourlyItem {
567
- options;
568
- constructor(options) {
569
- this.options = options;
570
- }
571
- toProtocol() { return { time: this.options.time, icon: this.options.icon, temperature: this.options.temperature }; }
572
- }
573
- export class WeatherHourlyStrip extends WidgetBase {
574
- options;
575
- type = "weather_hourly_strip";
576
- constructor(options = {}) {
577
- super(options);
578
- this.options = options;
579
- }
580
- data() { return { ...this.commonData(), items: (this.options.items ?? []).map((item) => item.toProtocol()) }; }
581
- }
582
- export class WorldClockRow {
583
- options;
584
- constructor(options) {
585
- this.options = options;
586
- }
587
- toProtocol() {
588
- const out = { name: this.options.name, timezone: this.options.timezone, time: this.options.time, offset: this.options.offset };
589
- if (this.options.day_label !== undefined)
590
- out.day_label = this.options.day_label;
591
- return out;
592
- }
593
- }
594
- export class WorldClock extends WidgetBase {
595
- options;
596
- type = "world_clock";
597
- constructor(options = {}) {
598
- super(options);
599
- this.options = options;
600
- }
601
- data() { return { ...this.commonData(), rows: (this.options.rows ?? []).map((row) => row.toProtocol()) }; }
602
- }