@sdeck/plugin-basics 1.2.0 → 1.3.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.
- package/dist/clock.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +116 -145
- package/dist/index.js.map +8 -7
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/theme.d.ts +1 -3
- package/dist/theme.d.ts.map +1 -1
- package/dist/timers.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/clock.tsx +18 -24
- package/src/index.tsx +66 -103
- package/src/plugin.ts +9 -0
- package/src/theme.ts +2 -2
- package/src/timers.tsx +25 -23
package/src/index.tsx
CHANGED
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
* Basics: what most decks want. Labels, time (clock, date, timer, stopwatch), a counter, page
|
|
3
3
|
* navigation and the deck's brightness.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { setting, useKeyPress, useKeyPressed } from "@sdeck/plugin";
|
|
6
|
+
import {
|
|
7
|
+
iconLayer,
|
|
8
|
+
iconLook,
|
|
9
|
+
type Layer,
|
|
10
|
+
type Look,
|
|
11
|
+
surface,
|
|
12
|
+
surfaceStyle,
|
|
13
|
+
textLayer,
|
|
14
|
+
} from "@sdeck/schema";
|
|
7
15
|
import { clock, date } from "./clock.tsx";
|
|
16
|
+
import { plugin } from "./plugin.ts";
|
|
8
17
|
import { column, THEME } from "./theme.ts";
|
|
9
18
|
import { stopwatch, timer, timerEnded } from "./timers.tsx";
|
|
10
19
|
|
|
@@ -12,33 +21,9 @@ export { analogFace, timeParts } from "./clock.tsx";
|
|
|
12
21
|
export { formatDuration } from "./theme.ts";
|
|
13
22
|
export { elapsed, type Run, toggled } from "./timers.tsx";
|
|
14
23
|
|
|
15
|
-
/** An icon with a caption under it, or the icon alone. */
|
|
16
|
-
function iconWithCaption(options: {
|
|
17
|
-
icon: string;
|
|
18
|
-
iconColor: string;
|
|
19
|
-
caption: string;
|
|
20
|
-
captionColor: string;
|
|
21
|
-
background: string;
|
|
22
|
-
}): Look {
|
|
23
|
-
const { icon, iconColor, caption, captionColor, background } = options;
|
|
24
|
-
return {
|
|
25
|
-
background,
|
|
26
|
-
layers: [
|
|
27
|
-
iconLayer("icon", icon, {
|
|
28
|
-
color: iconColor,
|
|
29
|
-
size: caption ? 44 : 54,
|
|
30
|
-
position: caption ? "top" : "middle",
|
|
31
|
-
}),
|
|
32
|
-
...(caption
|
|
33
|
-
? [textLayer("label", caption, { color: captionColor, size: 13, position: "bottom" })]
|
|
34
|
-
: []),
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
24
|
// -- Label --------------------------------------------------------------------
|
|
40
25
|
|
|
41
|
-
const label =
|
|
26
|
+
const label = plugin.action({
|
|
42
27
|
id: "label",
|
|
43
28
|
name: "Label",
|
|
44
29
|
description: "Text and an icon or picture. The text can show live values: CPU {{system.cpu}}%.",
|
|
@@ -46,11 +31,11 @@ const label = defineAction({
|
|
|
46
31
|
icon: "type",
|
|
47
32
|
slots: ["key", "sensor", "window"],
|
|
48
33
|
settings: {
|
|
49
|
-
text:
|
|
50
|
-
image:
|
|
51
|
-
background:
|
|
52
|
-
color:
|
|
53
|
-
fontSize:
|
|
34
|
+
text: setting.text("Text", { default: "Hello" }),
|
|
35
|
+
image: setting.image("Icon or picture"),
|
|
36
|
+
background: setting.color("Background", { default: THEME.background }),
|
|
37
|
+
color: setting.color("Text colour", { default: THEME.text }),
|
|
38
|
+
fontSize: setting.number("Text size", { default: 18, min: 8, max: 60 }),
|
|
54
39
|
},
|
|
55
40
|
// Pressing a label does nothing, but it can still start a button's own steps.
|
|
56
41
|
display: true,
|
|
@@ -61,8 +46,8 @@ const label = defineAction({
|
|
|
61
46
|
id: "icon",
|
|
62
47
|
type: "image",
|
|
63
48
|
src: s.image,
|
|
64
|
-
size: s.text ?
|
|
65
|
-
position:
|
|
49
|
+
size: s.text ? 48 : 68,
|
|
50
|
+
position: "middle",
|
|
66
51
|
// Icons take the text's colour; pictures keep their own.
|
|
67
52
|
color: s.color,
|
|
68
53
|
});
|
|
@@ -72,28 +57,27 @@ const label = defineAction({
|
|
|
72
57
|
textLayer("label", s.text, {
|
|
73
58
|
color: s.color,
|
|
74
59
|
size: s.image ? Math.min(s.fontSize, 14) : s.fontSize,
|
|
75
|
-
position: s.image ? "bottom" : "middle",
|
|
76
60
|
}),
|
|
77
61
|
);
|
|
78
62
|
}
|
|
79
|
-
return { background: s.background, layers };
|
|
63
|
+
return { background: surface(s.background), layers };
|
|
80
64
|
},
|
|
81
65
|
});
|
|
82
66
|
|
|
83
67
|
// -- Counter ------------------------------------------------------------------
|
|
84
68
|
|
|
85
|
-
const counter =
|
|
69
|
+
const counter = plugin.action({
|
|
86
70
|
id: "counter",
|
|
87
71
|
name: "Counter",
|
|
88
72
|
description: "Counts presses. Hold to reset. The count is saved.",
|
|
89
73
|
category: "Display",
|
|
90
74
|
icon: "hash",
|
|
91
75
|
settings: {
|
|
92
|
-
title:
|
|
93
|
-
count:
|
|
94
|
-
step:
|
|
95
|
-
accent:
|
|
96
|
-
background:
|
|
76
|
+
title: setting.text("Title", { default: "" }),
|
|
77
|
+
count: setting.number("Count", { default: 0 }),
|
|
78
|
+
step: setting.number("Step", { default: 1 }),
|
|
79
|
+
accent: setting.color("Colour", { default: THEME.accent }),
|
|
80
|
+
background: setting.color("Background", { default: THEME.background }),
|
|
97
81
|
},
|
|
98
82
|
component: ({ settings, setSettings }) => {
|
|
99
83
|
const pressed = useKeyPressed();
|
|
@@ -106,7 +90,7 @@ const counter = defineAction({
|
|
|
106
90
|
<div
|
|
107
91
|
style={{
|
|
108
92
|
...column,
|
|
109
|
-
|
|
93
|
+
...surfaceStyle(pressed ? settings.accent : settings.background),
|
|
110
94
|
fontWeight: 700,
|
|
111
95
|
gap: 2,
|
|
112
96
|
}}
|
|
@@ -162,7 +146,7 @@ const targets = {
|
|
|
162
146
|
favorite: "Favorites",
|
|
163
147
|
} as const;
|
|
164
148
|
|
|
165
|
-
const navigate =
|
|
149
|
+
const navigate = plugin.action({
|
|
166
150
|
id: "navigate",
|
|
167
151
|
name: "Navigate",
|
|
168
152
|
description: "Go to a page, back, forward, or to the next or previous page.",
|
|
@@ -170,30 +154,23 @@ const navigate = defineAction({
|
|
|
170
154
|
icon: "move-right",
|
|
171
155
|
slots: ["key", "sensor"],
|
|
172
156
|
settings: {
|
|
173
|
-
to: {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
{ value: "favorite", label: "Next favorite page" },
|
|
185
|
-
],
|
|
186
|
-
},
|
|
187
|
-
page: { type: "page", label: "Page", visibleIf: { to: "page" } },
|
|
188
|
-
wrap: {
|
|
189
|
-
type: "boolean",
|
|
190
|
-
label: "Wrap around",
|
|
157
|
+
to: setting.select("Go to", {
|
|
158
|
+
page: "A page",
|
|
159
|
+
back: "Back (history)",
|
|
160
|
+
forward: "Forward (history)",
|
|
161
|
+
next: "Next page",
|
|
162
|
+
previous: "Previous page",
|
|
163
|
+
home: "First page",
|
|
164
|
+
favorite: "Next favorite page",
|
|
165
|
+
}),
|
|
166
|
+
page: setting.page("Page", { required: true, visibleIf: { to: "page" } }),
|
|
167
|
+
wrap: setting.boolean("Wrap around", {
|
|
191
168
|
description: "After the last page comes the first.",
|
|
192
169
|
visibleIf: { to: ["next", "previous"] },
|
|
193
|
-
},
|
|
194
|
-
text:
|
|
195
|
-
background:
|
|
196
|
-
color:
|
|
170
|
+
}),
|
|
171
|
+
text: setting.text("Text", { placeholder: "Defaults to the target", appearance: true }),
|
|
172
|
+
background: setting.color("Background", { default: THEME.background, appearance: true }),
|
|
173
|
+
color: setting.color("Icon colour", { default: THEME.accent, appearance: true }),
|
|
197
174
|
},
|
|
198
175
|
run: ({ settings, deck }) => {
|
|
199
176
|
if (settings.to === "page") {
|
|
@@ -203,19 +180,18 @@ const navigate = defineAction({
|
|
|
203
180
|
return { label: settings.to === "page" ? `Go to ${settings.page}` : targets[settings.to] };
|
|
204
181
|
},
|
|
205
182
|
look: (s) =>
|
|
206
|
-
|
|
183
|
+
iconLook({
|
|
207
184
|
icon: NAVIGATE_ICONS[s.to],
|
|
208
|
-
|
|
185
|
+
color: s.to === "favorite" ? THEME.warm : s.color,
|
|
209
186
|
// A page key names its page, so keys to different pages can be told apart.
|
|
210
187
|
caption: s.text || (s.to === "page" ? s.page : ""),
|
|
211
|
-
captionColor: THEME.text,
|
|
212
188
|
background: s.background,
|
|
213
189
|
}),
|
|
214
190
|
});
|
|
215
191
|
|
|
216
192
|
// -- Page name ----------------------------------------------------------------
|
|
217
193
|
|
|
218
|
-
const pageName =
|
|
194
|
+
const pageName = plugin.action({
|
|
219
195
|
id: "page-name",
|
|
220
196
|
name: "Page name",
|
|
221
197
|
description: "Shows which page is open.",
|
|
@@ -223,14 +199,14 @@ const pageName = defineAction({
|
|
|
223
199
|
icon: "file-text",
|
|
224
200
|
slots: ["key", "sensor", "window"],
|
|
225
201
|
settings: {
|
|
226
|
-
color:
|
|
227
|
-
accent:
|
|
228
|
-
background:
|
|
229
|
-
fontSize:
|
|
202
|
+
color: setting.color("Text colour", { default: THEME.text }),
|
|
203
|
+
accent: setting.color("Icon colour", { default: THEME.accent }),
|
|
204
|
+
background: setting.color("Background", { default: THEME.background }),
|
|
205
|
+
fontSize: setting.number("Text size", { default: 20, min: 8, max: 60 }),
|
|
230
206
|
},
|
|
231
207
|
display: true,
|
|
232
208
|
look: (s) => ({
|
|
233
|
-
background: s.background,
|
|
209
|
+
background: surface(s.background),
|
|
234
210
|
layers: [
|
|
235
211
|
iconLayer("icon", "lucide/layers", { color: s.accent, size: 30, row: "name" }),
|
|
236
212
|
textLayer("label", "{{page.name}}", { color: s.color, size: s.fontSize, row: "name" }),
|
|
@@ -257,7 +233,7 @@ export function nextLevel(levels: readonly number[], current: number): number |
|
|
|
257
233
|
return levels[(i + 1) % levels.length];
|
|
258
234
|
}
|
|
259
235
|
|
|
260
|
-
const brightness =
|
|
236
|
+
const brightness = plugin.action({
|
|
261
237
|
id: "brightness",
|
|
262
238
|
name: "Brightness",
|
|
263
239
|
description: "Set the deck's brightness, or cycle through levels.",
|
|
@@ -265,30 +241,23 @@ const brightness = defineAction({
|
|
|
265
241
|
icon: "sun",
|
|
266
242
|
slots: ["key", "sensor"],
|
|
267
243
|
settings: {
|
|
268
|
-
mode: {
|
|
269
|
-
|
|
270
|
-
label: "Mode",
|
|
271
|
-
default: "cycle",
|
|
272
|
-
options: [
|
|
273
|
-
{ value: "cycle", label: "Cycle through levels" },
|
|
274
|
-
{ value: "set", label: "Set a level" },
|
|
275
|
-
],
|
|
276
|
-
},
|
|
277
|
-
level: {
|
|
278
|
-
type: "number",
|
|
279
|
-
label: "Level (%)",
|
|
244
|
+
mode: setting.select("Mode", { cycle: "Cycle through levels", set: "Set a level" }),
|
|
245
|
+
level: setting.number("Level (%)", {
|
|
280
246
|
default: 100,
|
|
281
247
|
min: 0,
|
|
282
248
|
max: 100,
|
|
283
249
|
visibleIf: { mode: "set" },
|
|
284
|
-
},
|
|
285
|
-
levels: {
|
|
286
|
-
type: "text",
|
|
287
|
-
label: "Levels to cycle",
|
|
250
|
+
}),
|
|
251
|
+
levels: setting.text("Levels to cycle", {
|
|
288
252
|
default: "10, 40, 70, 100",
|
|
253
|
+
required: true,
|
|
254
|
+
validate: (list) =>
|
|
255
|
+
parseLevels(list).length > 0
|
|
256
|
+
? undefined
|
|
257
|
+
: "should be numbers from 0 to 100, like 10, 50, 100",
|
|
289
258
|
visibleIf: { mode: "cycle" },
|
|
290
|
-
},
|
|
291
|
-
background:
|
|
259
|
+
}),
|
|
260
|
+
background: setting.color("Background", { default: THEME.background, appearance: true }),
|
|
292
261
|
},
|
|
293
262
|
run: async ({ settings, deck }) => {
|
|
294
263
|
const before = deck.brightness();
|
|
@@ -303,23 +272,17 @@ const brightness = defineAction({
|
|
|
303
272
|
};
|
|
304
273
|
},
|
|
305
274
|
look: (s) =>
|
|
306
|
-
|
|
275
|
+
iconLook({
|
|
307
276
|
icon:
|
|
308
277
|
s.mode === "cycle" ? "lucide/sun-medium" : s.level < 50 ? "lucide/sun-dim" : "lucide/sun",
|
|
309
|
-
|
|
278
|
+
color: THEME.warm,
|
|
310
279
|
caption: s.mode === "cycle" ? "" : `${s.level}%`,
|
|
311
|
-
captionColor: THEME.text,
|
|
312
280
|
background: s.background,
|
|
313
281
|
}),
|
|
314
282
|
});
|
|
315
283
|
|
|
316
284
|
/** Can be used directly by hosts and apps: `import basics from "@sdeck/plugin-basics"`. */
|
|
317
|
-
export default
|
|
318
|
-
id: "@sdeck/plugin-basics",
|
|
319
|
-
name: "Basics",
|
|
320
|
-
version: "1.2.0",
|
|
321
|
-
description: "Labels, a clock, the date, timers, a counter, page navigation and brightness.",
|
|
322
|
-
author: "sdeck",
|
|
285
|
+
export default plugin.define({
|
|
323
286
|
actions: [label, clock, date, timer, stopwatch, counter, navigate, pageName, brightness],
|
|
324
287
|
triggers: [timerEnded],
|
|
325
288
|
});
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPlugin } from "@sdeck/plugin";
|
|
2
|
+
|
|
3
|
+
export const plugin = createPlugin({
|
|
4
|
+
id: "@sdeck/plugin-basics",
|
|
5
|
+
name: "Basics",
|
|
6
|
+
version: "1.3.0",
|
|
7
|
+
description: "Labels, a clock, the date, timers, a counter, page navigation and brightness.",
|
|
8
|
+
author: "sdeck",
|
|
9
|
+
});
|
package/src/theme.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** The colours and shapes Basics draws with, so its keys look like one set. */
|
|
2
|
+
import { KEY } from "@sdeck/schema";
|
|
2
3
|
import type { CSSProperties } from "react";
|
|
3
4
|
|
|
4
5
|
export const THEME = {
|
|
5
|
-
|
|
6
|
-
background: "#16171d",
|
|
6
|
+
background: KEY,
|
|
7
7
|
/** Main text and icons. */
|
|
8
8
|
text: "#f4f4f5",
|
|
9
9
|
/** Secondary text: dates, units, hints. */
|
package/src/timers.tsx
CHANGED
|
@@ -2,16 +2,10 @@
|
|
|
2
2
|
* A countdown timer and a stopwatch. Their state lives here, by page and slot, so they keep
|
|
3
3
|
* running while another page is shown.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
defineTrigger,
|
|
8
|
-
type SlotInfo,
|
|
9
|
-
useKeyPress,
|
|
10
|
-
useKeyPressed,
|
|
11
|
-
useNow,
|
|
12
|
-
usePage,
|
|
13
|
-
} from "@sdeck/plugin";
|
|
5
|
+
import { type SlotInfo, setting, useKeyPress, useKeyPressed, useNow, usePage } from "@sdeck/plugin";
|
|
6
|
+
import { surfaceStyle } from "@sdeck/schema";
|
|
14
7
|
import { useEffect, useReducer } from "react";
|
|
8
|
+
import { plugin } from "./plugin.ts";
|
|
15
9
|
import { column, fill, formatDuration, ring, THEME } from "./theme.ts";
|
|
16
10
|
|
|
17
11
|
/** A running or paused clock: `startedAt` while running, `banked` ms from earlier runs. */
|
|
@@ -38,7 +32,7 @@ const slotId = (page: string, slot: SlotInfo, kind: string) =>
|
|
|
38
32
|
/** Listeners of the "timer ends" trigger. */
|
|
39
33
|
const ended = new Set<(event: { label: string; seconds: number }) => void>();
|
|
40
34
|
|
|
41
|
-
export const timerEnded =
|
|
35
|
+
export const timerEnded = plugin.trigger({
|
|
42
36
|
id: "timer-ended",
|
|
43
37
|
name: "When a timer ends",
|
|
44
38
|
description: "Fires when any Basics timer reaches zero.",
|
|
@@ -71,7 +65,15 @@ function Countdown(props: {
|
|
|
71
65
|
const color = done ? "#ffffff" : running ? THEME.text : THEME.muted;
|
|
72
66
|
if (wide) {
|
|
73
67
|
return (
|
|
74
|
-
<div
|
|
68
|
+
<div
|
|
69
|
+
style={{
|
|
70
|
+
...column,
|
|
71
|
+
...surfaceStyle(background),
|
|
72
|
+
padding: "0 16px",
|
|
73
|
+
gap: 6,
|
|
74
|
+
fontWeight: 700,
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
75
77
|
<div
|
|
76
78
|
style={{
|
|
77
79
|
display: "flex",
|
|
@@ -108,7 +110,7 @@ function Countdown(props: {
|
|
|
108
110
|
);
|
|
109
111
|
}
|
|
110
112
|
return (
|
|
111
|
-
<div style={{ ...fill, background, position: "relative" }}>
|
|
113
|
+
<div style={{ ...fill, ...surfaceStyle(background), position: "relative" }}>
|
|
112
114
|
<img
|
|
113
115
|
src={ring(1 - remaining / total, done ? "#ffffff" : accent, THEME.faint)}
|
|
114
116
|
width={86}
|
|
@@ -135,7 +137,7 @@ function Countdown(props: {
|
|
|
135
137
|
);
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
export const timer =
|
|
140
|
+
export const timer = plugin.action({
|
|
139
141
|
id: "timer",
|
|
140
142
|
name: "Timer",
|
|
141
143
|
description: "Counts down. Press to start or pause, hold to reset. Blinks when it ends.",
|
|
@@ -143,11 +145,11 @@ export const timer = defineAction({
|
|
|
143
145
|
icon: "timer",
|
|
144
146
|
slots: ["key", "window"],
|
|
145
147
|
settings: {
|
|
146
|
-
minutes:
|
|
147
|
-
seconds:
|
|
148
|
-
label:
|
|
149
|
-
accent:
|
|
150
|
-
background:
|
|
148
|
+
minutes: setting.number("Minutes", { default: 5, min: 0, max: 600 }),
|
|
149
|
+
seconds: setting.number("Seconds", { default: 0, min: 0, max: 59 }),
|
|
150
|
+
label: setting.text("Label", { placeholder: "Tea, Focus…" }),
|
|
151
|
+
accent: setting.color("Ring colour", { default: THEME.warm }),
|
|
152
|
+
background: setting.color("Background", { default: THEME.background }),
|
|
151
153
|
},
|
|
152
154
|
component: ({ settings, slot, plugin }) => {
|
|
153
155
|
const page = usePage();
|
|
@@ -203,7 +205,7 @@ export const timer = defineAction({
|
|
|
203
205
|
},
|
|
204
206
|
});
|
|
205
207
|
|
|
206
|
-
export const stopwatch =
|
|
208
|
+
export const stopwatch = plugin.action({
|
|
207
209
|
id: "stopwatch",
|
|
208
210
|
name: "Stopwatch",
|
|
209
211
|
description: "Counts up. Press to start or stop, hold to reset.",
|
|
@@ -211,9 +213,9 @@ export const stopwatch = defineAction({
|
|
|
211
213
|
icon: "watch",
|
|
212
214
|
slots: ["key", "window"],
|
|
213
215
|
settings: {
|
|
214
|
-
label:
|
|
215
|
-
accent:
|
|
216
|
-
background:
|
|
216
|
+
label: setting.text("Label", { placeholder: "Shown under the time" }),
|
|
217
|
+
accent: setting.color("Colour while running", { default: THEME.success }),
|
|
218
|
+
background: setting.color("Background", { default: THEME.background }),
|
|
217
219
|
},
|
|
218
220
|
component: ({ settings, slot }) => {
|
|
219
221
|
const page = usePage();
|
|
@@ -246,7 +248,7 @@ export const stopwatch = defineAction({
|
|
|
246
248
|
style={{
|
|
247
249
|
...column,
|
|
248
250
|
...(wide && { flexDirection: "row", gap: 14 }),
|
|
249
|
-
|
|
251
|
+
...surfaceStyle(pressed ? THEME.faint : settings.background),
|
|
250
252
|
fontWeight: 700,
|
|
251
253
|
}}
|
|
252
254
|
>
|