@sdeck/plugin-basics 0.0.0-stage → 1.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.
- package/dist/clock.d.ts +16 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +754 -0
- package/dist/index.js.map +13 -0
- package/dist/theme.d.ts +25 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/timers.d.ts +13 -0
- package/dist/timers.d.ts.map +1 -0
- package/package.json +60 -4
- package/src/clock.tsx +197 -0
- package/src/index.tsx +325 -0
- package/src/theme.ts +56 -0
- package/src/timers.tsx +269 -0
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
// src/index.tsx
|
|
2
|
+
import { defineAction as defineAction3, definePlugin, useKeyPress as useKeyPress2, useKeyPressed as useKeyPressed2 } from "@sdeck/plugin";
|
|
3
|
+
import { iconLayer, textLayer } from "@sdeck/schema";
|
|
4
|
+
|
|
5
|
+
// src/clock.tsx
|
|
6
|
+
import { defineAction, useNow } from "@sdeck/plugin";
|
|
7
|
+
|
|
8
|
+
// src/theme.ts
|
|
9
|
+
var THEME = {
|
|
10
|
+
background: "#16171d",
|
|
11
|
+
text: "#f4f4f5",
|
|
12
|
+
muted: "#8b8d98",
|
|
13
|
+
faint: "#2b2d36",
|
|
14
|
+
accent: "#5b8cff",
|
|
15
|
+
warm: "#ffb547",
|
|
16
|
+
danger: "#ff5d5d",
|
|
17
|
+
success: "#3ddc84"
|
|
18
|
+
};
|
|
19
|
+
var fill = {
|
|
20
|
+
display: "flex",
|
|
21
|
+
width: "100%",
|
|
22
|
+
height: "100%",
|
|
23
|
+
alignItems: "center",
|
|
24
|
+
justifyContent: "center"
|
|
25
|
+
};
|
|
26
|
+
var column = { ...fill, flexDirection: "column" };
|
|
27
|
+
function formatDuration(ms, roundUp = true) {
|
|
28
|
+
const total = Math.max(0, roundUp ? Math.ceil(ms / 1000) : Math.floor(ms / 1000));
|
|
29
|
+
const hours = Math.floor(total / 3600);
|
|
30
|
+
const minutes = Math.floor(total % 3600 / 60);
|
|
31
|
+
const seconds = total % 60;
|
|
32
|
+
const ss = String(seconds).padStart(2, "0");
|
|
33
|
+
return hours > 0 ? `${hours}:${String(minutes).padStart(2, "0")}:${ss}` : `${minutes}:${ss}`;
|
|
34
|
+
}
|
|
35
|
+
var svg = (body, size = 100) => `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}">${body}</svg>`)}`;
|
|
36
|
+
function ring(part, color, track, width = 7) {
|
|
37
|
+
const r = 50 - width / 2 - 1;
|
|
38
|
+
const length = 2 * Math.PI * r;
|
|
39
|
+
const shown = Math.min(1, Math.max(0, part)) * length;
|
|
40
|
+
return svg(`<circle cx="50" cy="50" r="${r}" fill="none" stroke="${track}" stroke-width="${width}"/>` + (shown > 0 ? `<circle cx="50" cy="50" r="${r}" fill="none" stroke="${color}" stroke-width="${width}" stroke-linecap="round" stroke-dasharray="${shown} ${length}" transform="rotate(-90 50 50)"/>` : ""));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/clock.tsx
|
|
44
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
45
|
+
function analogFace(date, colors, seconds) {
|
|
46
|
+
const h = date.getHours() % 12;
|
|
47
|
+
const m = date.getMinutes();
|
|
48
|
+
const s = date.getSeconds();
|
|
49
|
+
const hand = (angle, length, width, color, tail = 0) => `<line x1="50" y1="${50 + tail}" x2="50" y2="${50 - length}" stroke="${color}" stroke-width="${width}" stroke-linecap="round" transform="rotate(${angle} 50 50)"/>`;
|
|
50
|
+
const ticks = Array.from({ length: 12 }, (_, i) => {
|
|
51
|
+
const major = i % 3 === 0;
|
|
52
|
+
return `<line x1="50" y1="${major ? 6 : 7}" x2="50" y2="${major ? 13 : 11}" stroke="${colors.ticks}" stroke-width="${major ? 3 : 2}" stroke-linecap="round" transform="rotate(${i * 30} 50 50)"/>`;
|
|
53
|
+
}).join("");
|
|
54
|
+
return svg(`<circle cx="50" cy="50" r="47" fill="${colors.face}"/>${ticks}` + hand((h + m / 60) * 30, 24, 6, colors.hands) + hand((m + s / 60) * 6, 35, 4, colors.hands) + (seconds ? hand(s * 6, 38, 1.8, colors.accent, 8) : "") + `<circle cx="50" cy="50" r="3.5" fill="${seconds ? colors.accent : colors.hands}"/>`);
|
|
55
|
+
}
|
|
56
|
+
function timeParts(date, hour12) {
|
|
57
|
+
const hours = date.getHours();
|
|
58
|
+
const shown = hour12 ? hours % 12 || 12 : hours;
|
|
59
|
+
return {
|
|
60
|
+
main: `${hour12 ? shown : String(shown).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`,
|
|
61
|
+
seconds: String(date.getSeconds()).padStart(2, "0"),
|
|
62
|
+
period: hour12 ? hours < 12 ? "AM" : "PM" : ""
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
var clock = defineAction({
|
|
66
|
+
id: "clock",
|
|
67
|
+
name: "Clock",
|
|
68
|
+
description: "The time, as digits or hands, and optionally the date.",
|
|
69
|
+
category: "Time",
|
|
70
|
+
icon: "clock",
|
|
71
|
+
slots: ["key", "window"],
|
|
72
|
+
settings: {
|
|
73
|
+
style: {
|
|
74
|
+
type: "select",
|
|
75
|
+
label: "Style",
|
|
76
|
+
default: "digital",
|
|
77
|
+
options: [
|
|
78
|
+
{ value: "digital", label: "Digits" },
|
|
79
|
+
{ value: "analog", label: "Hands" }
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
hour12: { type: "boolean", label: "12-hour clock", visibleIf: { style: "digital" } },
|
|
83
|
+
seconds: { type: "boolean", label: "Show seconds", default: true },
|
|
84
|
+
date: { type: "boolean", label: "Show the date" },
|
|
85
|
+
color: { type: "color", label: "Colour", default: THEME.text },
|
|
86
|
+
accent: { type: "color", label: "Accent", default: THEME.accent },
|
|
87
|
+
background: { type: "color", label: "Background", default: THEME.background }
|
|
88
|
+
},
|
|
89
|
+
component: ({ settings, slot }) => {
|
|
90
|
+
const now = useNow(settings.seconds ? 1000 : 1e4);
|
|
91
|
+
const wide = slot.kind === "window";
|
|
92
|
+
const day = now.toLocaleDateString(undefined, {
|
|
93
|
+
weekday: "short",
|
|
94
|
+
day: "numeric",
|
|
95
|
+
month: "short"
|
|
96
|
+
});
|
|
97
|
+
if (settings.style === "analog") {
|
|
98
|
+
const face = analogFace(now, { face: THEME.faint, hands: settings.color, accent: settings.accent, ticks: THEME.muted }, settings.seconds);
|
|
99
|
+
const size = wide ? 50 : settings.date ? 66 : 82;
|
|
100
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
101
|
+
style: {
|
|
102
|
+
...fill,
|
|
103
|
+
flexDirection: wide ? "row" : "column",
|
|
104
|
+
gap: wide ? 12 : 4,
|
|
105
|
+
background: settings.background
|
|
106
|
+
},
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsx("img", {
|
|
109
|
+
src: face,
|
|
110
|
+
width: size,
|
|
111
|
+
height: size,
|
|
112
|
+
alt: ""
|
|
113
|
+
}),
|
|
114
|
+
settings.date || wide ? /* @__PURE__ */ jsx("div", {
|
|
115
|
+
style: {
|
|
116
|
+
display: "flex",
|
|
117
|
+
color: THEME.muted,
|
|
118
|
+
fontSize: wide ? 18 : 12,
|
|
119
|
+
fontWeight: 700
|
|
120
|
+
},
|
|
121
|
+
children: day
|
|
122
|
+
}) : null
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const { main, seconds, period } = timeParts(now, settings.hour12);
|
|
127
|
+
const small = [settings.seconds ? `:${seconds}` : "", period].filter(Boolean).join(" ");
|
|
128
|
+
const big = wide ? 34 : main.length > 4 ? 27 : 31;
|
|
129
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
130
|
+
style: {
|
|
131
|
+
...column,
|
|
132
|
+
background: settings.background,
|
|
133
|
+
color: settings.color,
|
|
134
|
+
fontWeight: 700,
|
|
135
|
+
gap: wide ? 0 : 2,
|
|
136
|
+
...wide && { flexDirection: "row", gap: 14 }
|
|
137
|
+
},
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsxs("div", {
|
|
140
|
+
style: { display: "flex", alignItems: "baseline", gap: 3 },
|
|
141
|
+
children: [
|
|
142
|
+
/* @__PURE__ */ jsx("div", {
|
|
143
|
+
style: { display: "flex", fontSize: big, letterSpacing: -0.5 },
|
|
144
|
+
children: main
|
|
145
|
+
}),
|
|
146
|
+
wide && small ? /* @__PURE__ */ jsx("div", {
|
|
147
|
+
style: { display: "flex", fontSize: 16, color: settings.accent },
|
|
148
|
+
children: small
|
|
149
|
+
}) : null
|
|
150
|
+
]
|
|
151
|
+
}),
|
|
152
|
+
!wide && small ? /* @__PURE__ */ jsx("div", {
|
|
153
|
+
style: { display: "flex", fontSize: 13, color: settings.accent },
|
|
154
|
+
children: small
|
|
155
|
+
}) : null,
|
|
156
|
+
settings.date ? /* @__PURE__ */ jsx("div", {
|
|
157
|
+
style: { display: "flex", fontSize: wide ? 16 : 12, color: THEME.muted },
|
|
158
|
+
children: day
|
|
159
|
+
}) : null
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
var date = defineAction({
|
|
165
|
+
id: "date",
|
|
166
|
+
name: "Date",
|
|
167
|
+
description: "Today's date, like a page torn off a calendar.",
|
|
168
|
+
category: "Time",
|
|
169
|
+
icon: "calendar",
|
|
170
|
+
slots: ["key", "window"],
|
|
171
|
+
settings: {
|
|
172
|
+
accent: { type: "color", label: "Accent", default: THEME.danger },
|
|
173
|
+
background: { type: "color", label: "Background", default: THEME.background }
|
|
174
|
+
},
|
|
175
|
+
component: ({ settings, slot }) => {
|
|
176
|
+
const now = useNow(60000);
|
|
177
|
+
const weekday = now.toLocaleDateString(undefined, { weekday: "short" });
|
|
178
|
+
const month = now.toLocaleDateString(undefined, { month: "short" });
|
|
179
|
+
if (slot.kind === "window") {
|
|
180
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
181
|
+
style: { ...fill, gap: 14, background: settings.background, fontWeight: 700 },
|
|
182
|
+
children: [
|
|
183
|
+
/* @__PURE__ */ jsx("div", {
|
|
184
|
+
style: { display: "flex", fontSize: 36, color: THEME.text },
|
|
185
|
+
children: now.getDate()
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsxs("div", {
|
|
188
|
+
style: { display: "flex", flexDirection: "column" },
|
|
189
|
+
children: [
|
|
190
|
+
/* @__PURE__ */ jsx("div", {
|
|
191
|
+
style: { display: "flex", fontSize: 15, color: settings.accent },
|
|
192
|
+
children: now.toLocaleDateString(undefined, { weekday: "long" })
|
|
193
|
+
}),
|
|
194
|
+
/* @__PURE__ */ jsx("div", {
|
|
195
|
+
style: { display: "flex", fontSize: 14, color: THEME.muted },
|
|
196
|
+
children: now.toLocaleDateString(undefined, { month: "long", year: "numeric" })
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
})
|
|
200
|
+
]
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
204
|
+
style: {
|
|
205
|
+
...column,
|
|
206
|
+
justifyContent: "flex-start",
|
|
207
|
+
background: settings.background,
|
|
208
|
+
fontWeight: 700
|
|
209
|
+
},
|
|
210
|
+
children: [
|
|
211
|
+
/* @__PURE__ */ jsx("div", {
|
|
212
|
+
style: {
|
|
213
|
+
display: "flex",
|
|
214
|
+
width: "100%",
|
|
215
|
+
height: 26,
|
|
216
|
+
alignItems: "center",
|
|
217
|
+
justifyContent: "center",
|
|
218
|
+
background: settings.accent,
|
|
219
|
+
color: "#ffffff",
|
|
220
|
+
fontSize: 13,
|
|
221
|
+
letterSpacing: 1
|
|
222
|
+
},
|
|
223
|
+
children: weekday.toUpperCase()
|
|
224
|
+
}),
|
|
225
|
+
/* @__PURE__ */ jsx("div", {
|
|
226
|
+
style: { display: "flex", fontSize: 40, color: THEME.text, marginTop: 4 },
|
|
227
|
+
children: now.getDate()
|
|
228
|
+
}),
|
|
229
|
+
/* @__PURE__ */ jsx("div", {
|
|
230
|
+
style: { display: "flex", fontSize: 12, color: THEME.muted },
|
|
231
|
+
children: month
|
|
232
|
+
})
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// src/timers.tsx
|
|
239
|
+
import {
|
|
240
|
+
defineAction as defineAction2,
|
|
241
|
+
defineTrigger,
|
|
242
|
+
useKeyPress,
|
|
243
|
+
useKeyPressed,
|
|
244
|
+
useNow as useNow2,
|
|
245
|
+
usePage
|
|
246
|
+
} from "@sdeck/plugin";
|
|
247
|
+
import { useEffect, useReducer } from "react";
|
|
248
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
249
|
+
var elapsed = (run, now) => run.banked + (run.startedAt === undefined ? 0 : now - run.startedAt);
|
|
250
|
+
function toggled(run, now) {
|
|
251
|
+
return run.startedAt === undefined ? { ...run, startedAt: now } : { banked: elapsed(run, now) };
|
|
252
|
+
}
|
|
253
|
+
var runs = new Map;
|
|
254
|
+
var runOf = (id) => runs.get(id) ?? { banked: 0 };
|
|
255
|
+
var slotId = (page, slot, kind) => `${kind}|${page}|${slot.kind}|${"index" in slot ? slot.index : 0}`;
|
|
256
|
+
var ended = new Set;
|
|
257
|
+
var timerEnded = defineTrigger({
|
|
258
|
+
id: "timer-ended",
|
|
259
|
+
name: "When a timer ends",
|
|
260
|
+
description: "Fires when any Basics timer reaches zero.",
|
|
261
|
+
subscribe: ({ fire }) => {
|
|
262
|
+
const listener = (event) => fire(event);
|
|
263
|
+
ended.add(listener);
|
|
264
|
+
return () => ended.delete(listener);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
function Countdown(props) {
|
|
268
|
+
const { remaining, total, running, label, accent, wide } = props;
|
|
269
|
+
const done = remaining <= 0;
|
|
270
|
+
const now = useNow2(done ? 500 : 60000);
|
|
271
|
+
const flash = done && now.getTime() % 1000 < 500;
|
|
272
|
+
const background = flash ? THEME.danger : props.pressed ? THEME.faint : props.background;
|
|
273
|
+
const caption = done ? "Done" : running ? label : remaining < total ? "Paused" : label;
|
|
274
|
+
const time = formatDuration(remaining);
|
|
275
|
+
const color = done ? "#ffffff" : running ? THEME.text : THEME.muted;
|
|
276
|
+
if (wide) {
|
|
277
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
278
|
+
style: { ...column, background, padding: "0 16px", gap: 6, fontWeight: 700 },
|
|
279
|
+
children: [
|
|
280
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
281
|
+
style: {
|
|
282
|
+
display: "flex",
|
|
283
|
+
width: "100%",
|
|
284
|
+
justifyContent: "space-between",
|
|
285
|
+
alignItems: "baseline"
|
|
286
|
+
},
|
|
287
|
+
children: [
|
|
288
|
+
/* @__PURE__ */ jsx2("div", {
|
|
289
|
+
style: { display: "flex", fontSize: 14, color: done ? "#ffffff" : THEME.muted },
|
|
290
|
+
children: caption || "Timer"
|
|
291
|
+
}),
|
|
292
|
+
/* @__PURE__ */ jsx2("div", {
|
|
293
|
+
style: { display: "flex", fontSize: 26, color },
|
|
294
|
+
children: time
|
|
295
|
+
})
|
|
296
|
+
]
|
|
297
|
+
}),
|
|
298
|
+
/* @__PURE__ */ jsx2("div", {
|
|
299
|
+
style: {
|
|
300
|
+
display: "flex",
|
|
301
|
+
width: "100%",
|
|
302
|
+
height: 4,
|
|
303
|
+
background: THEME.faint,
|
|
304
|
+
borderRadius: 2
|
|
305
|
+
},
|
|
306
|
+
children: /* @__PURE__ */ jsx2("div", {
|
|
307
|
+
style: {
|
|
308
|
+
display: "flex",
|
|
309
|
+
width: `${Math.round((1 - remaining / total) * 100)}%`,
|
|
310
|
+
height: 4,
|
|
311
|
+
background: accent,
|
|
312
|
+
borderRadius: 2
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
]
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
320
|
+
style: { ...fill, background, position: "relative" },
|
|
321
|
+
children: [
|
|
322
|
+
/* @__PURE__ */ jsx2("img", {
|
|
323
|
+
src: ring(1 - remaining / total, done ? "#ffffff" : accent, THEME.faint),
|
|
324
|
+
width: 86,
|
|
325
|
+
height: 86,
|
|
326
|
+
alt: "",
|
|
327
|
+
style: { position: "absolute", left: 5, top: 5 }
|
|
328
|
+
}),
|
|
329
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
330
|
+
style: { ...column, fontWeight: 700 },
|
|
331
|
+
children: [
|
|
332
|
+
/* @__PURE__ */ jsx2("div", {
|
|
333
|
+
style: { display: "flex", fontSize: time.length > 5 ? 17 : 22, color },
|
|
334
|
+
children: time
|
|
335
|
+
}),
|
|
336
|
+
caption ? /* @__PURE__ */ jsx2("div", {
|
|
337
|
+
style: {
|
|
338
|
+
display: "flex",
|
|
339
|
+
fontSize: 10,
|
|
340
|
+
color: done ? "#ffffff" : THEME.muted,
|
|
341
|
+
maxWidth: 60
|
|
342
|
+
},
|
|
343
|
+
children: caption
|
|
344
|
+
}) : null
|
|
345
|
+
]
|
|
346
|
+
})
|
|
347
|
+
]
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
var timer = defineAction2({
|
|
351
|
+
id: "timer",
|
|
352
|
+
name: "Timer",
|
|
353
|
+
description: "Counts down. Press to start or pause, hold to reset. Blinks when it ends.",
|
|
354
|
+
category: "Time",
|
|
355
|
+
icon: "timer",
|
|
356
|
+
slots: ["key", "window"],
|
|
357
|
+
settings: {
|
|
358
|
+
minutes: { type: "number", label: "Minutes", default: 5, min: 0, max: 600 },
|
|
359
|
+
seconds: { type: "number", label: "Seconds", default: 0, min: 0, max: 59 },
|
|
360
|
+
label: { type: "text", label: "Label", placeholder: "Tea, Focus…" },
|
|
361
|
+
accent: { type: "color", label: "Ring colour", default: THEME.warm },
|
|
362
|
+
background: { type: "color", label: "Background", default: THEME.background }
|
|
363
|
+
},
|
|
364
|
+
component: ({ settings, slot, plugin }) => {
|
|
365
|
+
const page = usePage();
|
|
366
|
+
const id = slotId(page, slot, "timer");
|
|
367
|
+
const total = Math.max(1, (settings.minutes * 60 + settings.seconds) * 1000);
|
|
368
|
+
const [, redraw] = useReducer((n) => n + 1, 0);
|
|
369
|
+
const pressed = useKeyPressed();
|
|
370
|
+
const run = runOf(id);
|
|
371
|
+
const running = run.startedAt !== undefined;
|
|
372
|
+
const now = useNow2(running ? 250 : 60000).getTime();
|
|
373
|
+
const remaining = Math.max(0, total - elapsed(run, now));
|
|
374
|
+
const finished = running && remaining <= 0;
|
|
375
|
+
useEffect(() => {
|
|
376
|
+
if (!finished)
|
|
377
|
+
return;
|
|
378
|
+
runs.set(id, { banked: total });
|
|
379
|
+
const event = { label: settings.label, seconds: total / 1000 };
|
|
380
|
+
for (const listener of [...ended])
|
|
381
|
+
listener(event);
|
|
382
|
+
plugin.emit("timer-ended", event);
|
|
383
|
+
redraw();
|
|
384
|
+
}, [finished, id, total, settings.label, plugin]);
|
|
385
|
+
useKeyPress(() => {
|
|
386
|
+
const current = runOf(id);
|
|
387
|
+
runs.set(id, elapsed(current, Date.now()) >= total ? { banked: 0, startedAt: Date.now() } : toggled(current, Date.now()));
|
|
388
|
+
redraw();
|
|
389
|
+
}, {
|
|
390
|
+
onLongPress: () => {
|
|
391
|
+
runs.delete(id);
|
|
392
|
+
redraw();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return /* @__PURE__ */ jsx2(Countdown, {
|
|
396
|
+
remaining,
|
|
397
|
+
total,
|
|
398
|
+
running,
|
|
399
|
+
label: settings.label,
|
|
400
|
+
accent: settings.accent,
|
|
401
|
+
background: settings.background,
|
|
402
|
+
wide: slot.kind === "window",
|
|
403
|
+
pressed
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
var stopwatch = defineAction2({
|
|
408
|
+
id: "stopwatch",
|
|
409
|
+
name: "Stopwatch",
|
|
410
|
+
description: "Counts up. Press to start or stop, hold to reset.",
|
|
411
|
+
category: "Time",
|
|
412
|
+
icon: "watch",
|
|
413
|
+
slots: ["key", "window"],
|
|
414
|
+
settings: {
|
|
415
|
+
label: { type: "text", label: "Label", placeholder: "Shown under the time" },
|
|
416
|
+
accent: { type: "color", label: "Colour while running", default: THEME.success },
|
|
417
|
+
background: { type: "color", label: "Background", default: THEME.background }
|
|
418
|
+
},
|
|
419
|
+
component: ({ settings, slot }) => {
|
|
420
|
+
const page = usePage();
|
|
421
|
+
const id = slotId(page, slot, "stopwatch");
|
|
422
|
+
const [, redraw] = useReducer((n) => n + 1, 0);
|
|
423
|
+
const pressed = useKeyPressed();
|
|
424
|
+
const run = runOf(id);
|
|
425
|
+
const running = run.startedAt !== undefined;
|
|
426
|
+
const now = useNow2(running ? 100 : 60000).getTime();
|
|
427
|
+
const ms = elapsed(run, now);
|
|
428
|
+
useKeyPress(() => {
|
|
429
|
+
runs.set(id, toggled(runOf(id), Date.now()));
|
|
430
|
+
redraw();
|
|
431
|
+
}, {
|
|
432
|
+
onLongPress: () => {
|
|
433
|
+
runs.delete(id);
|
|
434
|
+
redraw();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
const time = formatDuration(ms, false);
|
|
438
|
+
const tenths = Math.floor(ms % 1000 / 100);
|
|
439
|
+
const color = running ? settings.accent : ms > 0 ? THEME.text : THEME.muted;
|
|
440
|
+
const caption = settings.label || (running ? "" : ms > 0 ? "Stopped" : "Stopwatch");
|
|
441
|
+
const wide = slot.kind === "window";
|
|
442
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
443
|
+
style: {
|
|
444
|
+
...column,
|
|
445
|
+
...wide && { flexDirection: "row", gap: 14 },
|
|
446
|
+
background: pressed ? THEME.faint : settings.background,
|
|
447
|
+
fontWeight: 700
|
|
448
|
+
},
|
|
449
|
+
children: [
|
|
450
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
451
|
+
style: { display: "flex", alignItems: "baseline" },
|
|
452
|
+
children: [
|
|
453
|
+
/* @__PURE__ */ jsx2("div", {
|
|
454
|
+
style: { display: "flex", fontSize: wide ? 32 : time.length > 5 ? 20 : 26, color },
|
|
455
|
+
children: time
|
|
456
|
+
}),
|
|
457
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
458
|
+
style: { display: "flex", fontSize: wide ? 20 : 15, color: THEME.muted },
|
|
459
|
+
children: [
|
|
460
|
+
".",
|
|
461
|
+
tenths
|
|
462
|
+
]
|
|
463
|
+
})
|
|
464
|
+
]
|
|
465
|
+
}),
|
|
466
|
+
caption ? /* @__PURE__ */ jsx2("div", {
|
|
467
|
+
style: { display: "flex", fontSize: wide ? 14 : 11, color: THEME.muted },
|
|
468
|
+
children: caption
|
|
469
|
+
}) : null
|
|
470
|
+
]
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
// src/index.tsx
|
|
476
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
477
|
+
function iconWithCaption(options) {
|
|
478
|
+
const { icon, iconColor, caption, captionColor, background } = options;
|
|
479
|
+
return {
|
|
480
|
+
background,
|
|
481
|
+
layers: [
|
|
482
|
+
iconLayer("icon", icon, {
|
|
483
|
+
color: iconColor,
|
|
484
|
+
size: caption ? 44 : 54,
|
|
485
|
+
position: caption ? "top" : "middle"
|
|
486
|
+
}),
|
|
487
|
+
...caption ? [textLayer("label", caption, { color: captionColor, size: 13, position: "bottom" })] : []
|
|
488
|
+
]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
var label = defineAction3({
|
|
492
|
+
id: "label",
|
|
493
|
+
name: "Label",
|
|
494
|
+
description: "Text and an icon or picture. The text can show live values: CPU {{system.cpu}}%.",
|
|
495
|
+
category: "Display",
|
|
496
|
+
icon: "type",
|
|
497
|
+
slots: ["key", "sensor", "window"],
|
|
498
|
+
settings: {
|
|
499
|
+
text: { type: "text", label: "Text", default: "Hello" },
|
|
500
|
+
image: { type: "image", label: "Icon or picture" },
|
|
501
|
+
background: { type: "color", label: "Background", default: THEME.background },
|
|
502
|
+
color: { type: "color", label: "Text colour", default: THEME.text },
|
|
503
|
+
fontSize: { type: "number", label: "Text size", default: 18, min: 8, max: 60 }
|
|
504
|
+
},
|
|
505
|
+
display: true,
|
|
506
|
+
look: (s) => {
|
|
507
|
+
const layers = [];
|
|
508
|
+
if (s.image) {
|
|
509
|
+
layers.push({
|
|
510
|
+
id: "icon",
|
|
511
|
+
type: "image",
|
|
512
|
+
src: s.image,
|
|
513
|
+
size: s.text ? 50 : 68,
|
|
514
|
+
position: s.text ? "top" : "middle",
|
|
515
|
+
color: s.color
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
if (s.text) {
|
|
519
|
+
layers.push(textLayer("label", s.text, {
|
|
520
|
+
color: s.color,
|
|
521
|
+
size: s.image ? Math.min(s.fontSize, 14) : s.fontSize,
|
|
522
|
+
position: s.image ? "bottom" : "middle"
|
|
523
|
+
}));
|
|
524
|
+
}
|
|
525
|
+
return { background: s.background, layers };
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
var counter = defineAction3({
|
|
529
|
+
id: "counter",
|
|
530
|
+
name: "Counter",
|
|
531
|
+
description: "Counts presses. Hold to reset. The count is saved.",
|
|
532
|
+
category: "Display",
|
|
533
|
+
icon: "hash",
|
|
534
|
+
settings: {
|
|
535
|
+
title: { type: "text", label: "Title", default: "" },
|
|
536
|
+
count: { type: "number", label: "Count", default: 0 },
|
|
537
|
+
step: { type: "number", label: "Step", default: 1 },
|
|
538
|
+
accent: { type: "color", label: "Colour", default: THEME.accent },
|
|
539
|
+
background: { type: "color", label: "Background", default: THEME.background }
|
|
540
|
+
},
|
|
541
|
+
component: ({ settings, setSettings }) => {
|
|
542
|
+
const pressed = useKeyPressed2();
|
|
543
|
+
useKeyPress2(() => setSettings({ count: settings.count + settings.step }), {
|
|
544
|
+
onLongPress: () => setSettings({ count: 0 })
|
|
545
|
+
});
|
|
546
|
+
const text = String(settings.count);
|
|
547
|
+
const size = text.length <= 2 ? 44 : text.length <= 4 ? 32 : 22;
|
|
548
|
+
return /* @__PURE__ */ jsxs3("div", {
|
|
549
|
+
style: {
|
|
550
|
+
...column,
|
|
551
|
+
background: pressed ? settings.accent : settings.background,
|
|
552
|
+
fontWeight: 700,
|
|
553
|
+
gap: 2
|
|
554
|
+
},
|
|
555
|
+
children: [
|
|
556
|
+
settings.title ? /* @__PURE__ */ jsx3("div", {
|
|
557
|
+
style: {
|
|
558
|
+
display: "flex",
|
|
559
|
+
fontSize: 12,
|
|
560
|
+
color: pressed ? "#ffffff" : THEME.muted,
|
|
561
|
+
maxWidth: 86
|
|
562
|
+
},
|
|
563
|
+
children: settings.title
|
|
564
|
+
}) : null,
|
|
565
|
+
/* @__PURE__ */ jsx3("div", {
|
|
566
|
+
style: { display: "flex", fontSize: size, color: pressed ? "#ffffff" : THEME.text },
|
|
567
|
+
children: text
|
|
568
|
+
}),
|
|
569
|
+
/* @__PURE__ */ jsx3("div", {
|
|
570
|
+
style: {
|
|
571
|
+
display: "flex",
|
|
572
|
+
width: 26,
|
|
573
|
+
height: 3,
|
|
574
|
+
borderRadius: 2,
|
|
575
|
+
background: pressed ? "#ffffff" : settings.accent,
|
|
576
|
+
marginTop: 2
|
|
577
|
+
}
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
var NAVIGATE_ICONS = {
|
|
584
|
+
page: "lucide/folder-open",
|
|
585
|
+
back: "lucide/arrow-left",
|
|
586
|
+
forward: "lucide/arrow-right",
|
|
587
|
+
next: "lucide/chevron-right",
|
|
588
|
+
previous: "lucide/chevron-left",
|
|
589
|
+
home: "lucide/house",
|
|
590
|
+
favorite: "lucide/star"
|
|
591
|
+
};
|
|
592
|
+
var targets = {
|
|
593
|
+
back: "Back",
|
|
594
|
+
forward: "Forward",
|
|
595
|
+
next: "Next",
|
|
596
|
+
previous: "Prev",
|
|
597
|
+
home: "Home",
|
|
598
|
+
favorite: "Favorites"
|
|
599
|
+
};
|
|
600
|
+
var navigate = defineAction3({
|
|
601
|
+
id: "navigate",
|
|
602
|
+
name: "Navigate",
|
|
603
|
+
description: "Go to a page, back, forward, or to the next or previous page.",
|
|
604
|
+
category: "Navigation",
|
|
605
|
+
icon: "move-right",
|
|
606
|
+
slots: ["key", "sensor"],
|
|
607
|
+
settings: {
|
|
608
|
+
to: {
|
|
609
|
+
type: "select",
|
|
610
|
+
label: "Go to",
|
|
611
|
+
default: "page",
|
|
612
|
+
options: [
|
|
613
|
+
{ value: "page", label: "A page" },
|
|
614
|
+
{ value: "back", label: "Back (history)" },
|
|
615
|
+
{ value: "forward", label: "Forward (history)" },
|
|
616
|
+
{ value: "next", label: "Next page" },
|
|
617
|
+
{ value: "previous", label: "Previous page" },
|
|
618
|
+
{ value: "home", label: "First page" },
|
|
619
|
+
{ value: "favorite", label: "Next favorite page" }
|
|
620
|
+
]
|
|
621
|
+
},
|
|
622
|
+
page: { type: "page", label: "Page", visibleIf: { to: "page" } },
|
|
623
|
+
wrap: {
|
|
624
|
+
type: "boolean",
|
|
625
|
+
label: "Wrap around",
|
|
626
|
+
description: "After the last page comes the first.",
|
|
627
|
+
visibleIf: { to: ["next", "previous"] }
|
|
628
|
+
},
|
|
629
|
+
text: { type: "text", label: "Text", placeholder: "Defaults to the target", appearance: true },
|
|
630
|
+
background: { type: "color", label: "Background", default: THEME.background, appearance: true },
|
|
631
|
+
color: { type: "color", label: "Icon colour", default: THEME.accent, appearance: true }
|
|
632
|
+
},
|
|
633
|
+
run: ({ settings, deck }) => {
|
|
634
|
+
if (settings.to === "page") {
|
|
635
|
+
if (!settings.page)
|
|
636
|
+
throw new Error("no page chosen");
|
|
637
|
+
deck.navigate("page", settings.page);
|
|
638
|
+
} else
|
|
639
|
+
deck.navigate(settings.to, undefined, { wrap: settings.wrap });
|
|
640
|
+
return { label: settings.to === "page" ? `Go to ${settings.page}` : targets[settings.to] };
|
|
641
|
+
},
|
|
642
|
+
look: (s) => iconWithCaption({
|
|
643
|
+
icon: NAVIGATE_ICONS[s.to],
|
|
644
|
+
iconColor: s.to === "favorite" ? THEME.warm : s.color,
|
|
645
|
+
caption: s.text || (s.to === "page" ? s.page : ""),
|
|
646
|
+
captionColor: THEME.text,
|
|
647
|
+
background: s.background
|
|
648
|
+
})
|
|
649
|
+
});
|
|
650
|
+
var pageName = defineAction3({
|
|
651
|
+
id: "page-name",
|
|
652
|
+
name: "Page name",
|
|
653
|
+
description: "Shows which page is open.",
|
|
654
|
+
category: "Navigation",
|
|
655
|
+
icon: "file-text",
|
|
656
|
+
slots: ["key", "sensor", "window"],
|
|
657
|
+
settings: {
|
|
658
|
+
color: { type: "color", label: "Text colour", default: THEME.text },
|
|
659
|
+
accent: { type: "color", label: "Icon colour", default: THEME.accent },
|
|
660
|
+
background: { type: "color", label: "Background", default: THEME.background },
|
|
661
|
+
fontSize: { type: "number", label: "Text size", default: 20, min: 8, max: 60 }
|
|
662
|
+
},
|
|
663
|
+
display: true,
|
|
664
|
+
look: (s) => ({
|
|
665
|
+
background: s.background,
|
|
666
|
+
layers: [
|
|
667
|
+
iconLayer("icon", "lucide/layers", { color: s.accent, size: 30, row: "name" }),
|
|
668
|
+
textLayer("label", "{{page.name}}", { color: s.color, size: s.fontSize, row: "name" })
|
|
669
|
+
]
|
|
670
|
+
})
|
|
671
|
+
});
|
|
672
|
+
function parseLevels(list) {
|
|
673
|
+
return list.split(",").map((s) => s.trim()).filter((s) => s !== "").map(Number).filter((n) => Number.isFinite(n) && n >= 0 && n <= 100);
|
|
674
|
+
}
|
|
675
|
+
function nextLevel(levels, current) {
|
|
676
|
+
if (levels.length === 0)
|
|
677
|
+
return;
|
|
678
|
+
const i = levels.indexOf(current);
|
|
679
|
+
return levels[(i + 1) % levels.length];
|
|
680
|
+
}
|
|
681
|
+
var brightness = defineAction3({
|
|
682
|
+
id: "brightness",
|
|
683
|
+
name: "Brightness",
|
|
684
|
+
description: "Set the deck's brightness, or cycle through levels.",
|
|
685
|
+
category: "Deck",
|
|
686
|
+
icon: "sun",
|
|
687
|
+
slots: ["key", "sensor"],
|
|
688
|
+
settings: {
|
|
689
|
+
mode: {
|
|
690
|
+
type: "select",
|
|
691
|
+
label: "Mode",
|
|
692
|
+
default: "cycle",
|
|
693
|
+
options: [
|
|
694
|
+
{ value: "cycle", label: "Cycle through levels" },
|
|
695
|
+
{ value: "set", label: "Set a level" }
|
|
696
|
+
]
|
|
697
|
+
},
|
|
698
|
+
level: {
|
|
699
|
+
type: "number",
|
|
700
|
+
label: "Level (%)",
|
|
701
|
+
default: 100,
|
|
702
|
+
min: 0,
|
|
703
|
+
max: 100,
|
|
704
|
+
visibleIf: { mode: "set" }
|
|
705
|
+
},
|
|
706
|
+
levels: {
|
|
707
|
+
type: "text",
|
|
708
|
+
label: "Levels to cycle",
|
|
709
|
+
default: "10, 40, 70, 100",
|
|
710
|
+
visibleIf: { mode: "cycle" }
|
|
711
|
+
},
|
|
712
|
+
background: { type: "color", label: "Background", default: THEME.background, appearance: true }
|
|
713
|
+
},
|
|
714
|
+
run: async ({ settings, deck }) => {
|
|
715
|
+
const before = deck.brightness();
|
|
716
|
+
const next = settings.mode === "cycle" ? nextLevel(parseLevels(settings.levels), before) : settings.level;
|
|
717
|
+
if (next === undefined)
|
|
718
|
+
throw new Error("no valid levels to cycle through");
|
|
719
|
+
await deck.setBrightness(next);
|
|
720
|
+
return {
|
|
721
|
+
result: next,
|
|
722
|
+
label: `Brightness ${next}%`,
|
|
723
|
+
undo: () => deck.setBrightness(before)
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
look: (s) => iconWithCaption({
|
|
727
|
+
icon: s.mode === "cycle" ? "lucide/sun-medium" : s.level < 50 ? "lucide/sun-dim" : "lucide/sun",
|
|
728
|
+
iconColor: THEME.warm,
|
|
729
|
+
caption: s.mode === "cycle" ? "" : `${s.level}%`,
|
|
730
|
+
captionColor: THEME.text,
|
|
731
|
+
background: s.background
|
|
732
|
+
})
|
|
733
|
+
});
|
|
734
|
+
var src_default = definePlugin({
|
|
735
|
+
id: "@sdeck/plugin-basics",
|
|
736
|
+
name: "Basics",
|
|
737
|
+
version: "1.1.0",
|
|
738
|
+
description: "Labels, a clock, the date, timers, a counter, page navigation and brightness.",
|
|
739
|
+
author: "sdeck",
|
|
740
|
+
actions: [label, clock, date, timer, stopwatch, counter, navigate, pageName, brightness],
|
|
741
|
+
triggers: [timerEnded]
|
|
742
|
+
});
|
|
743
|
+
export {
|
|
744
|
+
analogFace,
|
|
745
|
+
src_default as default,
|
|
746
|
+
elapsed,
|
|
747
|
+
formatDuration,
|
|
748
|
+
nextLevel,
|
|
749
|
+
parseLevels,
|
|
750
|
+
timeParts,
|
|
751
|
+
toggled
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
//# debugId=5D6275C202B3D4CA64756E2164756E21
|