glimpse-custom-applet-sdk 0.1.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.
@@ -0,0 +1,626 @@
1
+ function applyCommonProps(payload, props) {
2
+ if (props.id !== undefined)
3
+ payload.id = props.id;
4
+ if (props.visible !== undefined)
5
+ payload.visible = props.visible;
6
+ if (props.hexpand !== undefined)
7
+ payload.hexpand = props.hexpand;
8
+ if (props.vexpand !== undefined)
9
+ payload.vexpand = props.vexpand;
10
+ if (props.halign !== undefined)
11
+ payload.halign = props.halign;
12
+ if (props.valign !== undefined)
13
+ payload.valign = props.valign;
14
+ if (props.tooltip !== undefined)
15
+ payload.tooltip = props.tooltip;
16
+ if (props.variant !== undefined)
17
+ payload.variant = props.variant;
18
+ return payload;
19
+ }
20
+ class WidgetBase {
21
+ common;
22
+ constructor(common = {}) {
23
+ this.common = common;
24
+ }
25
+ withCommon(payload) {
26
+ return applyCommonProps(payload, this.common);
27
+ }
28
+ }
29
+ export class Label extends WidgetBase {
30
+ text;
31
+ options;
32
+ constructor(text, options = {}) {
33
+ super(options);
34
+ this.text = text;
35
+ this.options = options;
36
+ }
37
+ toProtocol() {
38
+ const payload = this.withCommon({ text: this.text });
39
+ if (this.options.wrap !== undefined)
40
+ payload.wrap = this.options.wrap;
41
+ if (this.options.xalign !== undefined)
42
+ payload.xalign = this.options.xalign;
43
+ if (this.options.selectable !== undefined)
44
+ payload.selectable = this.options.selectable;
45
+ return { type: "label", data: payload };
46
+ }
47
+ }
48
+ export class Image extends WidgetBase {
49
+ icon;
50
+ options;
51
+ constructor(icon, options = {}) {
52
+ super(options);
53
+ this.icon = icon;
54
+ this.options = options;
55
+ }
56
+ toProtocol() {
57
+ const payload = this.withCommon({ icon: this.icon.toProtocol() });
58
+ if (this.options.pixel_size !== undefined)
59
+ payload.pixel_size = this.options.pixel_size;
60
+ return { type: "image", data: payload };
61
+ }
62
+ }
63
+ export class IconWidget extends WidgetBase {
64
+ icon;
65
+ options;
66
+ constructor(icon, options = {}) {
67
+ super(options);
68
+ this.icon = icon;
69
+ this.options = options;
70
+ }
71
+ toProtocol() {
72
+ const payload = this.withCommon({ icon: this.icon.toProtocol() });
73
+ if (this.options.pixel_size !== undefined)
74
+ payload.pixel_size = this.options.pixel_size;
75
+ return { type: "icon", data: payload };
76
+ }
77
+ }
78
+ export class Progress extends WidgetBase {
79
+ options;
80
+ constructor(options) {
81
+ super(options);
82
+ this.options = options;
83
+ }
84
+ toProtocol() {
85
+ const payload = this.withCommon({
86
+ value: this.options.value,
87
+ max: this.options.max ?? 1,
88
+ });
89
+ if (this.options.show_text !== undefined)
90
+ payload.show_text = this.options.show_text;
91
+ if (this.options.text !== undefined)
92
+ payload.text = this.options.text;
93
+ return { type: "progress", data: payload };
94
+ }
95
+ }
96
+ export class Button extends WidgetBase {
97
+ options;
98
+ constructor(options = {}) {
99
+ super(options);
100
+ this.options = options;
101
+ }
102
+ toProtocol() {
103
+ const payload = this.withCommon({});
104
+ if (this.options.label !== undefined)
105
+ payload.label = this.options.label;
106
+ if (this.options.icon !== undefined)
107
+ payload.icon = this.options.icon.toProtocol();
108
+ if (this.options.child !== undefined)
109
+ payload.child = this.options.child.toProtocol();
110
+ return { type: "button", data: payload };
111
+ }
112
+ }
113
+ export class Switch extends WidgetBase {
114
+ options;
115
+ constructor(options = {}) {
116
+ super(options);
117
+ this.options = options;
118
+ }
119
+ toProtocol() {
120
+ const payload = this.withCommon({ active: this.options.active ?? false });
121
+ if (this.options.label !== undefined)
122
+ payload.label = this.options.label;
123
+ return { type: "switch", data: payload };
124
+ }
125
+ }
126
+ export class Scale extends WidgetBase {
127
+ options;
128
+ constructor(options = {}) {
129
+ super(options);
130
+ this.options = options;
131
+ }
132
+ toProtocol() {
133
+ const payload = this.withCommon({
134
+ min: this.options.min ?? 0,
135
+ max: this.options.max ?? 1,
136
+ step: this.options.step ?? 0.1,
137
+ value: this.options.value ?? 0,
138
+ });
139
+ if (this.options.orientation !== undefined)
140
+ payload.orientation = this.options.orientation;
141
+ if (this.options.draw_value !== undefined)
142
+ payload.draw_value = this.options.draw_value;
143
+ return { type: "scale", data: payload };
144
+ }
145
+ }
146
+ export class Checkbox extends WidgetBase {
147
+ options;
148
+ constructor(options = {}) {
149
+ super(options);
150
+ this.options = options;
151
+ }
152
+ toProtocol() {
153
+ const payload = this.withCommon({ active: this.options.active ?? false });
154
+ if (this.options.label !== undefined)
155
+ payload.label = this.options.label;
156
+ return { type: "checkbox", data: payload };
157
+ }
158
+ }
159
+ export class DropdownItem {
160
+ id;
161
+ label;
162
+ constructor(id, label) {
163
+ this.id = id;
164
+ this.label = label;
165
+ }
166
+ toProtocol() {
167
+ return { id: this.id, label: this.label };
168
+ }
169
+ }
170
+ export class Dropdown extends WidgetBase {
171
+ options;
172
+ constructor(options = {}) {
173
+ super(options);
174
+ this.options = options;
175
+ }
176
+ toProtocol() {
177
+ const payload = this.withCommon({
178
+ items: (this.options.items ?? []).map((item) => item.toProtocol()),
179
+ });
180
+ if (this.options.selected !== undefined)
181
+ payload.selected = this.options.selected;
182
+ return { type: "dropdown", data: payload };
183
+ }
184
+ }
185
+ export class Separator extends WidgetBase {
186
+ options;
187
+ constructor(options = {}) {
188
+ super(options);
189
+ this.options = options;
190
+ }
191
+ toProtocol() {
192
+ const payload = this.withCommon({});
193
+ if (this.options.orientation !== undefined)
194
+ payload.orientation = this.options.orientation;
195
+ return { type: "separator", data: payload };
196
+ }
197
+ }
198
+ export class Scroll extends WidgetBase {
199
+ child;
200
+ constructor(child, options = {}) {
201
+ super(options);
202
+ this.child = child;
203
+ }
204
+ toProtocol() {
205
+ return { type: "scroll", data: this.withCommon({ child: this.child.toProtocol() }) };
206
+ }
207
+ }
208
+ export class GridChild {
209
+ row;
210
+ column;
211
+ child;
212
+ width;
213
+ height;
214
+ constructor(row, column, child, width = 1, height = 1) {
215
+ this.row = row;
216
+ this.column = column;
217
+ this.child = child;
218
+ this.width = width;
219
+ this.height = height;
220
+ }
221
+ toProtocol() {
222
+ return {
223
+ row: this.row,
224
+ column: this.column,
225
+ width: this.width,
226
+ height: this.height,
227
+ child: this.child.toProtocol(),
228
+ };
229
+ }
230
+ }
231
+ export class Grid extends WidgetBase {
232
+ options;
233
+ constructor(options = {}) {
234
+ super(options);
235
+ this.options = options;
236
+ }
237
+ toProtocol() {
238
+ return {
239
+ type: "grid",
240
+ data: this.withCommon({
241
+ row_spacing: this.options.row_spacing ?? 0,
242
+ column_spacing: this.options.column_spacing ?? 0,
243
+ children: (this.options.children ?? []).map((child) => child.toProtocol()),
244
+ }),
245
+ };
246
+ }
247
+ }
248
+ export class Hero extends WidgetBase {
249
+ options;
250
+ constructor(options) {
251
+ super(options);
252
+ this.options = options;
253
+ }
254
+ toProtocol() {
255
+ const payload = this.withCommon({
256
+ title: this.options.title,
257
+ subtitle: this.options.subtitle,
258
+ });
259
+ if (this.options.icon !== undefined)
260
+ payload.icon = this.options.icon.toProtocol();
261
+ return { type: "hero", data: payload };
262
+ }
263
+ }
264
+ export class Card extends WidgetBase {
265
+ options;
266
+ constructor(options = {}) {
267
+ super(options);
268
+ this.options = options;
269
+ }
270
+ toProtocol() {
271
+ return {
272
+ type: "card",
273
+ data: this.withCommon({
274
+ children: (this.options.children ?? []).map((child) => child.toProtocol()),
275
+ }),
276
+ };
277
+ }
278
+ }
279
+ export class Header {
280
+ title;
281
+ subtitle;
282
+ constructor(title, subtitle = "") {
283
+ this.title = title;
284
+ this.subtitle = subtitle;
285
+ }
286
+ toProtocol() {
287
+ const payload = { title: this.title };
288
+ if (this.subtitle !== "")
289
+ payload.subtitle = this.subtitle;
290
+ return payload;
291
+ }
292
+ }
293
+ export class Section extends WidgetBase {
294
+ options;
295
+ constructor(options) {
296
+ super(options);
297
+ this.options = options;
298
+ }
299
+ toProtocol() {
300
+ const header = this.options.header ??
301
+ (this.options.title === undefined
302
+ ? undefined
303
+ : new Header(this.options.title, this.options.subtitle ?? ""));
304
+ const body = this.options.body ?? this.options.children ?? [];
305
+ return {
306
+ type: "section",
307
+ data: this.withCommon({
308
+ ...(header === undefined ? {} : { header: header.toProtocol() }),
309
+ body: body.map((child) => child.toProtocol()),
310
+ }),
311
+ };
312
+ }
313
+ }
314
+ export class Collapsible extends WidgetBase {
315
+ options;
316
+ constructor(options) {
317
+ super(options);
318
+ this.options = options;
319
+ }
320
+ toProtocol() {
321
+ const header = this.options.header ??
322
+ (this.options.title === undefined
323
+ ? undefined
324
+ : new Header(this.options.title, this.options.subtitle ?? ""));
325
+ const body = this.options.body ?? this.options.children ?? [];
326
+ return {
327
+ type: "collapsible",
328
+ data: this.withCommon({
329
+ ...(header === undefined ? {} : { header: header.toProtocol() }),
330
+ expanded: this.options.expanded ?? false,
331
+ body: body.map((child) => child.toProtocol()),
332
+ }),
333
+ };
334
+ }
335
+ }
336
+ export class Item extends WidgetBase {
337
+ options;
338
+ constructor(options = {}) {
339
+ super(options);
340
+ this.options = options;
341
+ }
342
+ toProtocol() {
343
+ const payload = this.withCommon({
344
+ label: this.options.label ?? "",
345
+ clickable: this.options.clickable ?? false,
346
+ menu: (this.options.menu ?? []).map((item) => item.toProtocol()),
347
+ });
348
+ if (this.options.left !== undefined)
349
+ payload.left = this.options.left.toProtocol();
350
+ if (this.options.right !== undefined)
351
+ payload.right = this.options.right.toProtocol();
352
+ return { type: "item", data: payload };
353
+ }
354
+ }
355
+ export class CollapsibleItem extends WidgetBase {
356
+ options;
357
+ constructor(options = {}) {
358
+ super(options);
359
+ this.options = options;
360
+ }
361
+ toProtocol() {
362
+ const payload = this.withCommon({
363
+ label: this.options.label ?? "",
364
+ expanded: this.options.expanded ?? false,
365
+ body: (this.options.body ?? this.options.children ?? []).map((child) => child.toProtocol()),
366
+ });
367
+ if (this.options.left !== undefined)
368
+ payload.left = this.options.left.toProtocol();
369
+ if (this.options.right !== undefined)
370
+ payload.right = this.options.right.toProtocol();
371
+ return { type: "collapsible_item", data: payload };
372
+ }
373
+ }
374
+ export class Meter extends WidgetBase {
375
+ options;
376
+ constructor(options) {
377
+ super(options);
378
+ this.options = options;
379
+ }
380
+ toProtocol() {
381
+ const payload = this.withCommon({
382
+ label: this.options.label ?? "",
383
+ value: this.options.value,
384
+ min: this.options.min ?? 0,
385
+ max: this.options.max ?? 1,
386
+ step: this.options.step ?? 0.01,
387
+ interactive: this.options.interactive ?? false,
388
+ });
389
+ if (this.options.icon !== undefined)
390
+ payload.icon = this.options.icon.toProtocol();
391
+ if (this.options.text !== undefined)
392
+ payload.text = this.options.text;
393
+ return { type: "meter", data: payload };
394
+ }
395
+ }
396
+ export class Copyable extends WidgetBase {
397
+ options;
398
+ constructor(options) {
399
+ super(options);
400
+ this.options = options;
401
+ }
402
+ toProtocol() {
403
+ return {
404
+ type: "copyable",
405
+ data: this.withCommon({
406
+ label: this.options.label ?? "",
407
+ value: this.options.value,
408
+ }),
409
+ };
410
+ }
411
+ }
412
+ export class ToastAction {
413
+ id;
414
+ label;
415
+ constructor(id, label) {
416
+ this.id = id;
417
+ this.label = label;
418
+ }
419
+ toProtocol() {
420
+ return { id: this.id, label: this.label };
421
+ }
422
+ }
423
+ export class Toast extends WidgetBase {
424
+ options;
425
+ constructor(options) {
426
+ super(options);
427
+ this.options = options;
428
+ }
429
+ toProtocol() {
430
+ const payload = this.withCommon({
431
+ title: this.options.title,
432
+ message: this.options.message ?? "",
433
+ });
434
+ if (this.options.icon !== undefined)
435
+ payload.icon = this.options.icon.toProtocol();
436
+ if (this.options.action !== undefined)
437
+ payload.action = this.options.action.toProtocol();
438
+ return { type: "toast", data: payload };
439
+ }
440
+ }
441
+ export class ActionRow extends WidgetBase {
442
+ options;
443
+ constructor(options) {
444
+ super(options);
445
+ this.options = options;
446
+ }
447
+ toProtocol() {
448
+ const payload = this.withCommon({
449
+ title: this.options.title,
450
+ subtitle: this.options.subtitle ?? "",
451
+ meta: this.options.meta ?? "",
452
+ });
453
+ if (this.options.icon !== undefined)
454
+ payload.icon = this.options.icon.toProtocol();
455
+ return { type: "action_row", data: payload };
456
+ }
457
+ }
458
+ export class Row extends WidgetBase {
459
+ options;
460
+ constructor(options = {}) {
461
+ super(options);
462
+ this.options = options;
463
+ }
464
+ toProtocol() {
465
+ return {
466
+ type: "row",
467
+ data: this.withCommon({
468
+ spacing: this.options.spacing ?? 0,
469
+ children: (this.options.children ?? []).map((child) => child.toProtocol()),
470
+ }),
471
+ };
472
+ }
473
+ }
474
+ export class Column extends WidgetBase {
475
+ options;
476
+ constructor(options = {}) {
477
+ super(options);
478
+ this.options = options;
479
+ }
480
+ toProtocol() {
481
+ return {
482
+ type: "column",
483
+ data: this.withCommon({
484
+ spacing: this.options.spacing ?? 0,
485
+ children: (this.options.children ?? []).map((child) => child.toProtocol()),
486
+ }),
487
+ };
488
+ }
489
+ }
490
+ export class ActionMenuItem {
491
+ options;
492
+ constructor(options) {
493
+ this.options = options;
494
+ }
495
+ toProtocol() {
496
+ const payload = {
497
+ id: this.options.id,
498
+ label: this.options.label,
499
+ };
500
+ if (this.options.icon !== undefined)
501
+ payload.icon = this.options.icon.toProtocol();
502
+ if (this.options.visible !== undefined)
503
+ payload.visible = this.options.visible;
504
+ if (this.options.checked !== undefined)
505
+ payload.checked = this.options.checked;
506
+ if (this.options.selectable !== undefined)
507
+ payload.selectable = this.options.selectable;
508
+ return payload;
509
+ }
510
+ }
511
+ export class ActionMenu extends WidgetBase {
512
+ options;
513
+ constructor(options = {}) {
514
+ super(options);
515
+ this.options = options;
516
+ }
517
+ toProtocol() {
518
+ const payload = this.withCommon({
519
+ items: (this.options.items ?? []).map((item) => item.toProtocol()),
520
+ });
521
+ if (this.options.header !== undefined)
522
+ payload.header = this.options.header;
523
+ return { type: "action_menu", data: payload };
524
+ }
525
+ }
526
+ export class Spinner extends WidgetBase {
527
+ options;
528
+ constructor(options = {}) {
529
+ super(options);
530
+ this.options = options;
531
+ }
532
+ toProtocol() {
533
+ return {
534
+ type: "spinner",
535
+ data: this.withCommon({ spinning: this.options.spinning ?? true }),
536
+ };
537
+ }
538
+ }
539
+ export class DetailGridItem {
540
+ key;
541
+ value;
542
+ constructor(key, value) {
543
+ this.key = key;
544
+ this.value = value;
545
+ }
546
+ toProtocol() {
547
+ return { key: this.key, value: this.value };
548
+ }
549
+ }
550
+ export class DetailGrid extends WidgetBase {
551
+ options;
552
+ constructor(options = {}) {
553
+ super(options);
554
+ this.options = options;
555
+ }
556
+ toProtocol() {
557
+ return {
558
+ type: "detail_grid",
559
+ data: this.withCommon({
560
+ rows: (this.options.rows ?? []).map((row) => row.toProtocol()),
561
+ }),
562
+ };
563
+ }
564
+ }
565
+ export class EmptyState extends WidgetBase {
566
+ options;
567
+ constructor(options) {
568
+ super(options);
569
+ this.options = options;
570
+ }
571
+ toProtocol() {
572
+ return {
573
+ type: "empty_state",
574
+ data: this.withCommon({
575
+ title: this.options.title,
576
+ subtitle: this.options.subtitle ?? "",
577
+ }),
578
+ };
579
+ }
580
+ }
581
+ export class Badge extends WidgetBase {
582
+ options;
583
+ constructor(options) {
584
+ super(options);
585
+ this.options = options;
586
+ }
587
+ toProtocol() {
588
+ return {
589
+ type: "badge",
590
+ data: this.withCommon({
591
+ label: this.options.label,
592
+ }),
593
+ };
594
+ }
595
+ }
596
+ export class StatusDot extends WidgetBase {
597
+ constructor(options = {}) {
598
+ super(options);
599
+ }
600
+ toProtocol() {
601
+ return { type: "status", data: this.withCommon({}) };
602
+ }
603
+ }
604
+ export class Box extends WidgetBase {
605
+ options;
606
+ constructor(options = {}) {
607
+ super(options);
608
+ this.options = options;
609
+ }
610
+ static vertical(children, spacing = 0, options = {}) {
611
+ return new Box({ ...options, orientation: "vertical", spacing, children });
612
+ }
613
+ static horizontal(children, spacing = 0, options = {}) {
614
+ return new Box({ ...options, orientation: "horizontal", spacing, children });
615
+ }
616
+ toProtocol() {
617
+ return {
618
+ type: "box",
619
+ data: this.withCommon({
620
+ orientation: this.options.orientation ?? "vertical",
621
+ spacing: this.options.spacing ?? 0,
622
+ children: (this.options.children ?? []).map((child) => child.toProtocol()),
623
+ }),
624
+ };
625
+ }
626
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "glimpse-custom-applet-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Typed async framework for building Glimpse exec applets",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "import": "./dist/src/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/src",
16
+ "src",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json",
22
+ "test": "npm run build && node --test dist/tests/*.test.js",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "keywords": [
26
+ "glimpse",
27
+ "applet",
28
+ "panel",
29
+ "desktop",
30
+ "sdk"
31
+ ],
32
+ "license": "MIT",
33
+ "author": "Alex Oleshkevich <alex.oleshkevich@gmail.com>",
34
+ "homepage": "https://alex-oleshkevich.github.io/glimpse/",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/alex-oleshkevich/glimpse.git",
38
+ "directory": "sdk/sdk-ts"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/alex-oleshkevich/glimpse/issues"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^20.14.0",
51
+ "typescript": "^5.6.0"
52
+ }
53
+ }