@sdeck/plugin-basics 1.0.0 → 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/index.js +35 -840
- package/dist/index.js.map +6 -15
- package/package.json +5 -5
- package/src/index.tsx +7 -7
package/dist/index.js
CHANGED
|
@@ -1,819 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
runtime = next;
|
|
5
|
-
}
|
|
6
|
-
// ../react/src/render.ts
|
|
7
|
-
function isReactElement(value) {
|
|
8
|
-
return typeof value === "object" && value !== null && "$$typeof" in value;
|
|
9
|
-
}
|
|
10
|
-
var defaultRenderer = {};
|
|
11
|
-
var fontRenderers = new WeakMap;
|
|
12
|
-
async function createRenderer(fonts) {
|
|
13
|
-
const { Renderer } = await import("@takumi-rs/core");
|
|
14
|
-
const renderer = new Renderer;
|
|
15
|
-
for (const font of fonts) {
|
|
16
|
-
await renderer.registerFont({
|
|
17
|
-
name: font.name,
|
|
18
|
-
data: font.data,
|
|
19
|
-
...font.weight !== undefined && { weight: font.weight },
|
|
20
|
-
...font.style !== undefined && { style: font.style }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return renderer;
|
|
24
|
-
}
|
|
25
|
-
function getRenderer(fonts) {
|
|
26
|
-
if (!fonts?.length) {
|
|
27
|
-
defaultRenderer.current ??= createRenderer([]);
|
|
28
|
-
defaultRenderer.current.catch(() => {
|
|
29
|
-
defaultRenderer.current = undefined;
|
|
30
|
-
});
|
|
31
|
-
return defaultRenderer.current;
|
|
32
|
-
}
|
|
33
|
-
let renderer = fontRenderers.get(fonts);
|
|
34
|
-
if (!renderer) {
|
|
35
|
-
renderer = createRenderer(fonts);
|
|
36
|
-
renderer.catch(() => fontRenderers.delete(fonts));
|
|
37
|
-
fontRenderers.set(fonts, renderer);
|
|
38
|
-
}
|
|
39
|
-
return renderer;
|
|
40
|
-
}
|
|
41
|
-
var number = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
42
|
-
function toNode(node, text = true) {
|
|
43
|
-
if ("text" in node) {
|
|
44
|
-
return text ? { type: "text", text: node.text } : { type: "container", children: [] };
|
|
45
|
-
}
|
|
46
|
-
const { style, tw, src, width, height } = node.props;
|
|
47
|
-
const common = {
|
|
48
|
-
...typeof tw === "string" && { tw }
|
|
49
|
-
};
|
|
50
|
-
if (node.type === "img") {
|
|
51
|
-
if (typeof src !== "string")
|
|
52
|
-
throw new Error("<img> needs a string `src` (URL or data: URI)");
|
|
53
|
-
return {
|
|
54
|
-
type: "image",
|
|
55
|
-
src,
|
|
56
|
-
...number(width) !== undefined && { width: number(width) },
|
|
57
|
-
...number(height) !== undefined && { height: number(height) },
|
|
58
|
-
...typeof style === "object" && style !== null && { style },
|
|
59
|
-
...common
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
type: "container",
|
|
64
|
-
style: { display: "flex", ...typeof style === "object" ? style : {} },
|
|
65
|
-
children: node.children.filter((child) => text || !("text" in child)).map((child) => toNode(child, text)),
|
|
66
|
-
...common
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
var reconciler;
|
|
70
|
-
var flushing = 0;
|
|
71
|
-
function flushAll(renderer) {
|
|
72
|
-
flushing++;
|
|
73
|
-
try {
|
|
74
|
-
renderer.flushSyncWork();
|
|
75
|
-
for (let i = 0;i < 20 && renderer.flushPassiveEffects(); i++)
|
|
76
|
-
renderer.flushSyncWork();
|
|
77
|
-
} finally {
|
|
78
|
-
flushing--;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function loadReconciler() {
|
|
82
|
-
reconciler ??= (async () => {
|
|
83
|
-
let factoryModule;
|
|
84
|
-
let constants;
|
|
85
|
-
let React;
|
|
86
|
-
try {
|
|
87
|
-
[factoryModule, constants, React] = await Promise.all([
|
|
88
|
-
import("react-reconciler"),
|
|
89
|
-
import("react-reconciler/constants.js"),
|
|
90
|
-
import("react")
|
|
91
|
-
]);
|
|
92
|
-
} catch (cause) {
|
|
93
|
-
throw new Error("Rendering React elements requires `react` (>=19.3) to be installed", {
|
|
94
|
-
cause
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
let priority = constants.NoEventPriority;
|
|
98
|
-
const noop = () => {};
|
|
99
|
-
const hostConfig = {
|
|
100
|
-
supportsMutation: true,
|
|
101
|
-
supportsPersistence: false,
|
|
102
|
-
supportsHydration: false,
|
|
103
|
-
isPrimaryRenderer: true,
|
|
104
|
-
warnsIfNotActing: false,
|
|
105
|
-
noTimeout: -1,
|
|
106
|
-
scheduleTimeout: setTimeout,
|
|
107
|
-
cancelTimeout: clearTimeout,
|
|
108
|
-
supportsMicrotasks: true,
|
|
109
|
-
scheduleMicrotask: queueMicrotask,
|
|
110
|
-
createInstance: (type, props) => {
|
|
111
|
-
const { children: _children, ...rest } = props;
|
|
112
|
-
return { type, props: rest, children: [] };
|
|
113
|
-
},
|
|
114
|
-
createTextInstance: (text) => ({ text }),
|
|
115
|
-
shouldSetTextContent: () => false,
|
|
116
|
-
appendInitialChild: (parent, child) => parent.children.push(child),
|
|
117
|
-
appendChild: (parent, child) => parent.children.push(child),
|
|
118
|
-
appendChildToContainer: (container, child) => container.children.push(child),
|
|
119
|
-
insertBefore: (parent, child, before) => {
|
|
120
|
-
const children = parent.children;
|
|
121
|
-
const existing = children.indexOf(child);
|
|
122
|
-
if (existing !== -1)
|
|
123
|
-
children.splice(existing, 1);
|
|
124
|
-
children.splice(children.indexOf(before), 0, child);
|
|
125
|
-
},
|
|
126
|
-
insertInContainerBefore: (container, child, before) => {
|
|
127
|
-
const children = container.children;
|
|
128
|
-
const existing = children.indexOf(child);
|
|
129
|
-
if (existing !== -1)
|
|
130
|
-
children.splice(existing, 1);
|
|
131
|
-
children.splice(children.indexOf(before), 0, child);
|
|
132
|
-
},
|
|
133
|
-
removeChild: (parent, child) => {
|
|
134
|
-
parent.children.splice(parent.children.indexOf(child), 1);
|
|
135
|
-
},
|
|
136
|
-
removeChildFromContainer: (container, child) => {
|
|
137
|
-
container.children.splice(container.children.indexOf(child), 1);
|
|
138
|
-
},
|
|
139
|
-
clearContainer: (container) => {
|
|
140
|
-
container.children = [];
|
|
141
|
-
},
|
|
142
|
-
commitUpdate: (instance, _type, _prev, next) => {
|
|
143
|
-
const { children: _children, ...rest } = next;
|
|
144
|
-
instance.props = rest;
|
|
145
|
-
},
|
|
146
|
-
commitTextUpdate: (text, _old, next) => {
|
|
147
|
-
text.text = next;
|
|
148
|
-
},
|
|
149
|
-
finalizeInitialChildren: () => false,
|
|
150
|
-
getPublicInstance: (instance) => instance,
|
|
151
|
-
getRootHostContext: () => ({}),
|
|
152
|
-
getChildHostContext: (parent) => parent,
|
|
153
|
-
prepareForCommit: () => null,
|
|
154
|
-
resetAfterCommit: (container) => container.onCommit(),
|
|
155
|
-
preparePortalMount: noop,
|
|
156
|
-
detachDeletedInstance: noop,
|
|
157
|
-
hideInstance: noop,
|
|
158
|
-
unhideInstance: noop,
|
|
159
|
-
hideTextInstance: noop,
|
|
160
|
-
unhideTextInstance: noop,
|
|
161
|
-
getInstanceFromNode: () => null,
|
|
162
|
-
beforeActiveInstanceBlur: noop,
|
|
163
|
-
afterActiveInstanceBlur: noop,
|
|
164
|
-
prepareScopeUpdate: noop,
|
|
165
|
-
getInstanceFromScope: () => null,
|
|
166
|
-
bindToConsole: (method, args) => console[method]?.bind(console, ...args) ?? noop,
|
|
167
|
-
extraDevToolsConfig: null,
|
|
168
|
-
rendererVersion: "0.0.0",
|
|
169
|
-
rendererPackageName: "sdeck",
|
|
170
|
-
getCurrentUpdatePriority: () => priority,
|
|
171
|
-
setCurrentUpdatePriority: (next) => {
|
|
172
|
-
priority = next;
|
|
173
|
-
},
|
|
174
|
-
resolveUpdatePriority: () => priority !== constants.NoEventPriority ? priority : flushing > 0 ? constants.DiscreteEventPriority : constants.DefaultEventPriority,
|
|
175
|
-
resolveEventType: () => null,
|
|
176
|
-
resolveEventTimeStamp: () => -1.1,
|
|
177
|
-
shouldAttemptEagerTransition: () => false,
|
|
178
|
-
trackSchedulerEvent: noop,
|
|
179
|
-
requestPostPaintCallback: noop,
|
|
180
|
-
maySuspendCommit: () => false,
|
|
181
|
-
preloadInstance: () => true,
|
|
182
|
-
startSuspendingCommit: noop,
|
|
183
|
-
suspendInstance: noop,
|
|
184
|
-
waitForCommitToBeReady: () => null,
|
|
185
|
-
getSuspendedCommitReason: () => null,
|
|
186
|
-
NotPendingTransition: null,
|
|
187
|
-
HostTransitionContext: React.createContext(null),
|
|
188
|
-
resetFormInstance: noop
|
|
189
|
-
};
|
|
190
|
-
const factory = factoryModule.default ?? factoryModule;
|
|
191
|
-
return factory(hostConfig);
|
|
192
|
-
})();
|
|
193
|
-
reconciler.catch(() => {
|
|
194
|
-
reconciler = undefined;
|
|
195
|
-
});
|
|
196
|
-
return reconciler;
|
|
197
|
-
}
|
|
198
|
-
function noopIndicator() {}
|
|
199
|
-
async function createReactRoot(size, onFrame, options = {}) {
|
|
200
|
-
const [takumi, renderer] = await Promise.all([getRenderer(options.fonts), loadReconciler()]);
|
|
201
|
-
let dirty = false;
|
|
202
|
-
let drawing;
|
|
203
|
-
let lastTree;
|
|
204
|
-
let unmounted = false;
|
|
205
|
-
let renderError;
|
|
206
|
-
let initial = true;
|
|
207
|
-
const fail = (error) => {
|
|
208
|
-
if (initial)
|
|
209
|
-
renderError ??= { error };
|
|
210
|
-
else
|
|
211
|
-
(options.onError ?? ((e) => console.error("sdeck: React render failed:", e)))(error);
|
|
212
|
-
};
|
|
213
|
-
async function draw() {
|
|
214
|
-
await Promise.resolve();
|
|
215
|
-
while (dirty && !unmounted) {
|
|
216
|
-
dirty = false;
|
|
217
|
-
try {
|
|
218
|
-
const [root] = container.children;
|
|
219
|
-
if (!root)
|
|
220
|
-
continue;
|
|
221
|
-
const tree = toNode(root, options.text !== false);
|
|
222
|
-
const key = JSON.stringify(tree);
|
|
223
|
-
if (key === lastTree)
|
|
224
|
-
continue;
|
|
225
|
-
lastTree = key;
|
|
226
|
-
const pixels = await takumi.render(tree, {
|
|
227
|
-
width: size.width,
|
|
228
|
-
height: size.height,
|
|
229
|
-
format: "raw",
|
|
230
|
-
...options.scale !== undefined && { devicePixelRatio: options.scale }
|
|
231
|
-
});
|
|
232
|
-
await onFrame({
|
|
233
|
-
data: new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength),
|
|
234
|
-
width: size.width,
|
|
235
|
-
height: size.height,
|
|
236
|
-
channels: 4
|
|
237
|
-
});
|
|
238
|
-
} catch (error) {
|
|
239
|
-
lastTree = undefined;
|
|
240
|
-
fail(error);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
drawing = undefined;
|
|
244
|
-
}
|
|
245
|
-
const container = {
|
|
246
|
-
children: [],
|
|
247
|
-
onCommit() {
|
|
248
|
-
dirty = true;
|
|
249
|
-
drawing ??= draw();
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
const onError = (error) => fail(error);
|
|
253
|
-
const onCaughtError = () => {};
|
|
254
|
-
const root = renderer.createContainer(container, 1, null, false, null, "", onError, onCaughtError, onError, noopIndicator, null);
|
|
255
|
-
const flush = () => flushAll(renderer);
|
|
256
|
-
const handle = {
|
|
257
|
-
render(element) {
|
|
258
|
-
if (unmounted)
|
|
259
|
-
throw new Error("This React root was unmounted");
|
|
260
|
-
renderer.updateContainerSync(element, root, null, null);
|
|
261
|
-
flush();
|
|
262
|
-
},
|
|
263
|
-
async idle() {
|
|
264
|
-
while (drawing)
|
|
265
|
-
await drawing;
|
|
266
|
-
if (initial && renderError) {
|
|
267
|
-
const { error } = renderError;
|
|
268
|
-
renderError = undefined;
|
|
269
|
-
throw error;
|
|
270
|
-
}
|
|
271
|
-
initial = false;
|
|
272
|
-
},
|
|
273
|
-
async unmount() {
|
|
274
|
-
if (unmounted)
|
|
275
|
-
return;
|
|
276
|
-
renderer.updateContainerSync(null, root, null, null);
|
|
277
|
-
flush();
|
|
278
|
-
unmounted = true;
|
|
279
|
-
await drawing;
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
return handle;
|
|
283
|
-
}
|
|
284
|
-
async function renderReact(element, size, fonts, scale) {
|
|
285
|
-
let frame;
|
|
286
|
-
const root = await createReactRoot(size, (next) => {
|
|
287
|
-
frame = next;
|
|
288
|
-
}, { ...fonts && { fonts }, ...scale !== undefined && { scale } });
|
|
289
|
-
try {
|
|
290
|
-
root.render(element);
|
|
291
|
-
await root.idle();
|
|
292
|
-
} finally {
|
|
293
|
-
await root.unmount();
|
|
294
|
-
}
|
|
295
|
-
if (!frame)
|
|
296
|
-
throw new Error("React element rendered nothing");
|
|
297
|
-
return frame;
|
|
298
|
-
}
|
|
299
|
-
registerElementRuntime({
|
|
300
|
-
matches: isReactElement,
|
|
301
|
-
render: (element, size, options) => renderReact(element, size, options?.fonts),
|
|
302
|
-
createRoot: (size, onFrame, options) => createReactRoot(size, onFrame, options)
|
|
303
|
-
});
|
|
304
|
-
// ../app/src/app.tsx
|
|
305
|
-
import { Fragment, useSyncExternalStore } from "react";
|
|
306
|
-
|
|
307
|
-
// ../app/src/context.ts
|
|
308
|
-
import { createContext, useContext } from "react";
|
|
309
|
-
var DeckContext = createContext(undefined);
|
|
310
|
-
var SlotContext = createContext(undefined);
|
|
311
|
-
var NavigatorContext = createContext(undefined);
|
|
312
|
-
function useDeck() {
|
|
313
|
-
const deck = useContext(DeckContext);
|
|
314
|
-
if (!deck)
|
|
315
|
-
throw new Error("useDeck() must be used inside a component mounted by @sdeck/app");
|
|
316
|
-
return deck;
|
|
317
|
-
}
|
|
318
|
-
function useSlot() {
|
|
319
|
-
return useContext(SlotContext);
|
|
320
|
-
}
|
|
321
|
-
// ../app/src/hooks.ts
|
|
322
|
-
import { useContext as useContext2, useEffect, useRef, useState, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
323
|
-
|
|
324
|
-
// ../app/src/swipe.ts
|
|
325
|
-
var SWIPE_WINDOW_MS = 400;
|
|
326
|
-
|
|
327
|
-
class SwipeTracker {
|
|
328
|
-
#handlers = new Set;
|
|
329
|
-
#stamps = new Map;
|
|
330
|
-
#completing = new Set;
|
|
331
|
-
#first;
|
|
332
|
-
constructor(deck) {
|
|
333
|
-
deck.on("sensorDown", (index) => this.#down(index));
|
|
334
|
-
}
|
|
335
|
-
get active() {
|
|
336
|
-
return this.#handlers.size > 0;
|
|
337
|
-
}
|
|
338
|
-
stamp(index) {
|
|
339
|
-
return this.#stamps.get(index) ?? 0;
|
|
340
|
-
}
|
|
341
|
-
completes(index) {
|
|
342
|
-
return this.#completing.has(index);
|
|
343
|
-
}
|
|
344
|
-
listen(handler) {
|
|
345
|
-
this.#handlers.add(handler);
|
|
346
|
-
return () => void this.#handlers.delete(handler);
|
|
347
|
-
}
|
|
348
|
-
#down(index) {
|
|
349
|
-
this.#completing.delete(index);
|
|
350
|
-
const now = performance.now();
|
|
351
|
-
const first = this.#first;
|
|
352
|
-
if (!this.active || !first || first.index === index || now - first.at > SWIPE_WINDOW_MS) {
|
|
353
|
-
this.#first = { index, at: now };
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
this.#first = undefined;
|
|
357
|
-
this.#completing.add(index);
|
|
358
|
-
for (const sensor of [first.index, index])
|
|
359
|
-
this.#stamps.set(sensor, this.stamp(sensor) + 1);
|
|
360
|
-
const direction = index > first.index ? "right" : "left";
|
|
361
|
-
for (const handler of [...this.#handlers])
|
|
362
|
-
handler(direction);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
var trackers = new WeakMap;
|
|
366
|
-
function swipeTracker(deck) {
|
|
367
|
-
let tracker = trackers.get(deck);
|
|
368
|
-
if (!tracker) {
|
|
369
|
-
tracker = new SwipeTracker(deck);
|
|
370
|
-
trackers.set(deck, tracker);
|
|
371
|
-
}
|
|
372
|
-
return tracker;
|
|
373
|
-
}
|
|
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";
|
|
374
4
|
|
|
375
|
-
//
|
|
376
|
-
|
|
377
|
-
const ref = useRef(value);
|
|
378
|
-
useEffect(() => {
|
|
379
|
-
ref.current = value;
|
|
380
|
-
});
|
|
381
|
-
return ref;
|
|
382
|
-
}
|
|
383
|
-
function useTarget(kind, explicit) {
|
|
384
|
-
const slot = useSlot();
|
|
385
|
-
if (explicit !== undefined)
|
|
386
|
-
return explicit;
|
|
387
|
-
return slot?.kind === kind ? slot.index : undefined;
|
|
388
|
-
}
|
|
389
|
-
function usePressed(kind, explicit) {
|
|
390
|
-
const deck = useDeck();
|
|
391
|
-
const target = useTarget(kind, explicit);
|
|
392
|
-
const [pressed, setPressed] = useState(false);
|
|
393
|
-
if (target === undefined) {
|
|
394
|
-
throw new Error(`use${kind === "key" ? "Key" : "Sensor"}Pressed() needs an index outside a ${kind} slot`);
|
|
395
|
-
}
|
|
396
|
-
useEffect(() => {
|
|
397
|
-
setPressed(false);
|
|
398
|
-
const offDown = deck.on(`${kind}Down`, (i) => i === target && setPressed(true));
|
|
399
|
-
const offUp = deck.on(`${kind}Up`, (i) => i === target && setPressed(false));
|
|
400
|
-
return () => {
|
|
401
|
-
offDown();
|
|
402
|
-
offUp();
|
|
403
|
-
};
|
|
404
|
-
}, [deck, kind, target]);
|
|
405
|
-
return pressed;
|
|
406
|
-
}
|
|
407
|
-
function useKeyPressed(key) {
|
|
408
|
-
return usePressed("key", key);
|
|
409
|
-
}
|
|
410
|
-
function usePress(kind, onPress, gestures, explicit) {
|
|
411
|
-
const deck = useDeck();
|
|
412
|
-
const target = useTarget(kind, explicit);
|
|
413
|
-
const latest = useLatest({
|
|
414
|
-
onPress,
|
|
415
|
-
onLongPress: gestures.onLongPress,
|
|
416
|
-
longPressMs: gestures.longPressMs ?? 500,
|
|
417
|
-
onDoublePress: gestures.onDoublePress ?? gestures.onDoubleTap,
|
|
418
|
-
doublePressMs: gestures.doublePressMs ?? gestures.doubleTapMs ?? 300,
|
|
419
|
-
onRelease: gestures.onRelease ?? false
|
|
420
|
-
});
|
|
421
|
-
useEffect(() => {
|
|
422
|
-
const swipes = kind === "sensor" ? swipeTracker(deck) : undefined;
|
|
423
|
-
const state = new Map;
|
|
424
|
-
const held = new Set;
|
|
425
|
-
const get = (index) => {
|
|
426
|
-
let s = state.get(index);
|
|
427
|
-
if (!s) {
|
|
428
|
-
s = { longFired: false, immediate: false, downAt: 0, stamp: 0 };
|
|
429
|
-
state.set(index, s);
|
|
430
|
-
}
|
|
431
|
-
return s;
|
|
432
|
-
};
|
|
433
|
-
const offDown = deck.on(`${kind}Down`, (index) => {
|
|
434
|
-
if (target !== undefined && index !== target)
|
|
435
|
-
return;
|
|
436
|
-
if (swipes?.completes(index))
|
|
437
|
-
return;
|
|
438
|
-
held.add(index);
|
|
439
|
-
const o = latest.current;
|
|
440
|
-
const s = get(index);
|
|
441
|
-
s.longFired = false;
|
|
442
|
-
s.downAt = performance.now();
|
|
443
|
-
s.stamp = swipes?.stamp(index) ?? 0;
|
|
444
|
-
s.immediate = !o.onLongPress && !o.onDoublePress && !o.onRelease && !swipes?.active;
|
|
445
|
-
if (s.immediate) {
|
|
446
|
-
o.onPress?.(index);
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
if (o.onLongPress) {
|
|
450
|
-
s.long = setTimeout(() => {
|
|
451
|
-
if (swipes && swipes.stamp(index) !== s.stamp)
|
|
452
|
-
return;
|
|
453
|
-
s.longFired = true;
|
|
454
|
-
clearTimeout(s.double);
|
|
455
|
-
s.double = undefined;
|
|
456
|
-
latest.current.onLongPress?.(index);
|
|
457
|
-
}, o.longPressMs);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
const offUp = deck.on(`${kind}Up`, (index) => {
|
|
461
|
-
if (!held.delete(index))
|
|
462
|
-
return;
|
|
463
|
-
const s = get(index);
|
|
464
|
-
clearTimeout(s.long);
|
|
465
|
-
if (s.immediate || s.longFired)
|
|
466
|
-
return;
|
|
467
|
-
if (!swipes?.active)
|
|
468
|
-
return released(index, s);
|
|
469
|
-
const wait = Math.max(0, SWIPE_WINDOW_MS - (performance.now() - s.downAt));
|
|
470
|
-
s.deferred = setTimeout(() => {
|
|
471
|
-
if (swipes.stamp(index) === s.stamp)
|
|
472
|
-
released(index, s);
|
|
473
|
-
}, wait);
|
|
474
|
-
});
|
|
475
|
-
function released(index, s) {
|
|
476
|
-
const o = latest.current;
|
|
477
|
-
if (!o.onDoublePress) {
|
|
478
|
-
o.onPress?.(index);
|
|
479
|
-
} else if (s.double !== undefined) {
|
|
480
|
-
clearTimeout(s.double);
|
|
481
|
-
s.double = undefined;
|
|
482
|
-
o.onDoublePress(index);
|
|
483
|
-
} else {
|
|
484
|
-
s.double = setTimeout(() => {
|
|
485
|
-
s.double = undefined;
|
|
486
|
-
latest.current.onPress?.(index);
|
|
487
|
-
}, o.doublePressMs);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return () => {
|
|
491
|
-
offDown();
|
|
492
|
-
offUp();
|
|
493
|
-
for (const s of state.values()) {
|
|
494
|
-
clearTimeout(s.long);
|
|
495
|
-
clearTimeout(s.double);
|
|
496
|
-
clearTimeout(s.deferred);
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
}, [deck, kind, target, latest]);
|
|
500
|
-
}
|
|
501
|
-
function useKeyPress(onPress, options = {}) {
|
|
502
|
-
usePress("key", onPress, options, options.key);
|
|
503
|
-
}
|
|
504
|
-
function useInterval(callback, ms) {
|
|
505
|
-
const latest = useLatest(callback);
|
|
506
|
-
useEffect(() => {
|
|
507
|
-
if (ms === null)
|
|
508
|
-
return;
|
|
509
|
-
const id = setInterval(() => latest.current(), ms);
|
|
510
|
-
return () => clearInterval(id);
|
|
511
|
-
}, [ms, latest]);
|
|
512
|
-
}
|
|
513
|
-
function useNow(ms = 1000) {
|
|
514
|
-
const [now, setNow] = useState(() => new Date);
|
|
515
|
-
useInterval(() => setNow(new Date), ms);
|
|
516
|
-
return now;
|
|
517
|
-
}
|
|
518
|
-
function useNavigation() {
|
|
519
|
-
const nav = useContext2(NavigatorContext);
|
|
520
|
-
if (!nav)
|
|
521
|
-
throw new Error("useNavigation() must be used inside a component mounted by sdeck/app");
|
|
522
|
-
const state = useSyncExternalStore2(nav.subscribe, nav.getSnapshot);
|
|
523
|
-
return {
|
|
524
|
-
...state,
|
|
525
|
-
canGoBack: state.stack.length > 1,
|
|
526
|
-
canGoForward: state.forwardStack.length > 0,
|
|
527
|
-
push: nav.push,
|
|
528
|
-
replace: nav.replace,
|
|
529
|
-
back: nav.back,
|
|
530
|
-
forward: nav.forward,
|
|
531
|
-
next: nav.next,
|
|
532
|
-
previous: nav.previous,
|
|
533
|
-
pages: nav.pages,
|
|
534
|
-
sequence: nav.sequence,
|
|
535
|
-
home: nav.home
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
function usePage() {
|
|
539
|
-
return useNavigation().page;
|
|
540
|
-
}
|
|
541
|
-
// ../schema/src/layers.ts
|
|
542
|
-
function iconLayer(id, icon, options = {}) {
|
|
543
|
-
const { color, size = 52, position = "middle", visible, row, frame } = options;
|
|
544
|
-
const src = /^[a-z0-9]+\/[A-Za-z0-9-]+$/.test(icon) ? `icon:${icon}` : icon;
|
|
545
|
-
return {
|
|
546
|
-
id,
|
|
547
|
-
type: "image",
|
|
548
|
-
src,
|
|
549
|
-
size,
|
|
550
|
-
position,
|
|
551
|
-
...color && { color },
|
|
552
|
-
...visible && { visible },
|
|
553
|
-
...row && { row },
|
|
554
|
-
...frame && { frame }
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function textLayer(id, text, options = {}) {
|
|
558
|
-
const { color = "#ffffff", size = 14, weight = 700, position = "middle" } = options;
|
|
559
|
-
const { visible, row, frame } = options;
|
|
560
|
-
return {
|
|
561
|
-
id,
|
|
562
|
-
type: "text",
|
|
563
|
-
text,
|
|
564
|
-
color,
|
|
565
|
-
size,
|
|
566
|
-
weight,
|
|
567
|
-
position,
|
|
568
|
-
...visible && { visible },
|
|
569
|
-
...row && { row },
|
|
570
|
-
...frame && { frame }
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
// ../plugin/src/settings.ts
|
|
574
|
-
function checkSchema(schema, sources = {}) {
|
|
575
|
-
const problems = [];
|
|
576
|
-
const types = new Set([
|
|
577
|
-
"text",
|
|
578
|
-
"number",
|
|
579
|
-
"boolean",
|
|
580
|
-
"color",
|
|
581
|
-
"select",
|
|
582
|
-
"page",
|
|
583
|
-
"image",
|
|
584
|
-
"secret"
|
|
585
|
-
]);
|
|
586
|
-
for (const [key, field] of Object.entries(schema)) {
|
|
587
|
-
if (!field || typeof field !== "object" || !types.has(field.type)) {
|
|
588
|
-
problems.push(`setting "${key}" has an unknown type`);
|
|
589
|
-
continue;
|
|
590
|
-
}
|
|
591
|
-
if (typeof field.label !== "string")
|
|
592
|
-
problems.push(`setting "${key}" needs a label`);
|
|
593
|
-
const source = "source" in field ? field.source : undefined;
|
|
594
|
-
if (source !== undefined && !(source in sources)) {
|
|
595
|
-
problems.push(`setting "${key}" uses unknown option source "${source}"`);
|
|
596
|
-
}
|
|
597
|
-
if (field.type === "select" && (!Array.isArray(field.options) || field.options.length === 0 && source === undefined)) {
|
|
598
|
-
problems.push(`setting "${key}" needs at least one option or a source`);
|
|
599
|
-
}
|
|
600
|
-
for (const other of "dependsOn" in field && field.dependsOn || []) {
|
|
601
|
-
if (!(other in schema))
|
|
602
|
-
problems.push(`setting "${key}" depends on unknown "${other}"`);
|
|
603
|
-
}
|
|
604
|
-
if (field.visibleIf !== undefined) {
|
|
605
|
-
for (const other of Object.keys(field.visibleIf)) {
|
|
606
|
-
if (!(other in schema))
|
|
607
|
-
problems.push(`setting "${key}" depends on unknown "${other}"`);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return problems;
|
|
612
|
-
}
|
|
5
|
+
// src/clock.tsx
|
|
6
|
+
import { defineAction, useNow } from "@sdeck/plugin";
|
|
613
7
|
|
|
614
|
-
// ../plugin/src/plugin.ts
|
|
615
|
-
var PERMISSIONS = [
|
|
616
|
-
"shell",
|
|
617
|
-
"process",
|
|
618
|
-
"filesystem",
|
|
619
|
-
"network",
|
|
620
|
-
"input",
|
|
621
|
-
"audio",
|
|
622
|
-
"clipboard"
|
|
623
|
-
];
|
|
624
|
-
var ID = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/;
|
|
625
|
-
var NAMESPACE = /^[a-z][\w-]{0,31}$/;
|
|
626
|
-
var LOCAL_ID = /^[\w.-]+$/;
|
|
627
|
-
function defineAction(def) {
|
|
628
|
-
return {
|
|
629
|
-
...def,
|
|
630
|
-
slots: def.slots ?? ["key"],
|
|
631
|
-
settings: def.settings ?? {}
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
function defineTrigger(def) {
|
|
635
|
-
return { ...def, settings: def.settings ?? {} };
|
|
636
|
-
}
|
|
637
|
-
function definePlugin(def) {
|
|
638
|
-
const problems = checkPlugin(def);
|
|
639
|
-
if (problems.length > 0) {
|
|
640
|
-
throw new TypeError(`invalid plugin "${def?.id}": ${problems.join("; ")}`);
|
|
641
|
-
}
|
|
642
|
-
return def;
|
|
643
|
-
}
|
|
644
|
-
function checkLocalIds(kind, items, problems) {
|
|
645
|
-
const seen = new Set;
|
|
646
|
-
for (const item of items) {
|
|
647
|
-
const name = typeof item?.id === "string" ? item.id : "?";
|
|
648
|
-
if (typeof item?.id !== "string" || !LOCAL_ID.test(item.id)) {
|
|
649
|
-
problems.push(`${kind} "${name}": id must be letters, digits, ".", "-" or "_"`);
|
|
650
|
-
} else if (seen.has(item.id)) {
|
|
651
|
-
problems.push(`${kind} "${name}" is defined twice`);
|
|
652
|
-
}
|
|
653
|
-
seen.add(name);
|
|
654
|
-
}
|
|
655
|
-
return seen;
|
|
656
|
-
}
|
|
657
|
-
function checkPlugin(value) {
|
|
658
|
-
if (!value || typeof value !== "object")
|
|
659
|
-
return ["not an object"];
|
|
660
|
-
const def = value;
|
|
661
|
-
const problems = [];
|
|
662
|
-
if (typeof def.id !== "string" || !ID.test(def.id)) {
|
|
663
|
-
problems.push("id must be a package-style name (lowercase, e.g. `my-plugin` or `@me/plugin`)");
|
|
664
|
-
}
|
|
665
|
-
if (typeof def.name !== "string" || def.name === "")
|
|
666
|
-
problems.push("name is required");
|
|
667
|
-
if (typeof def.version !== "string" || def.version === "")
|
|
668
|
-
problems.push("version is required");
|
|
669
|
-
if (def.namespace !== undefined && !NAMESPACE.test(def.namespace)) {
|
|
670
|
-
problems.push("namespace must be lowercase letters, digits, - or _ (starting with a letter)");
|
|
671
|
-
}
|
|
672
|
-
if (def.activate !== undefined && typeof def.activate !== "function") {
|
|
673
|
-
problems.push("activate must be a function");
|
|
674
|
-
}
|
|
675
|
-
if (def.permissions !== undefined) {
|
|
676
|
-
if (!Array.isArray(def.permissions))
|
|
677
|
-
problems.push("permissions must be an array");
|
|
678
|
-
else
|
|
679
|
-
for (const p of def.permissions)
|
|
680
|
-
if (!PERMISSIONS.includes(p))
|
|
681
|
-
problems.push(`unknown permission "${String(p)}"`);
|
|
682
|
-
}
|
|
683
|
-
if (def.settings !== undefined) {
|
|
684
|
-
for (const p of checkSchema(def.settings, def.optionSources ?? {})) {
|
|
685
|
-
problems.push(`plugin ${p}`);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
if (def.commands !== undefined) {
|
|
689
|
-
if (!Array.isArray(def.commands))
|
|
690
|
-
problems.push("commands must be an array");
|
|
691
|
-
else {
|
|
692
|
-
checkLocalIds("command", def.commands, problems);
|
|
693
|
-
for (const c of def.commands) {
|
|
694
|
-
const name = typeof c?.id === "string" ? c.id : "?";
|
|
695
|
-
if (typeof c?.name !== "string")
|
|
696
|
-
problems.push(`command "${name}": name is required`);
|
|
697
|
-
if (typeof c?.run !== "function")
|
|
698
|
-
problems.push(`command "${name}": run is required`);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
if (def.onboarding !== undefined)
|
|
703
|
-
problems.push(...checkOnboarding(def));
|
|
704
|
-
const sources = def.optionSources ?? {};
|
|
705
|
-
if (typeof sources !== "object")
|
|
706
|
-
problems.push("optionSources must be an object");
|
|
707
|
-
else
|
|
708
|
-
for (const [name, fn] of Object.entries(sources))
|
|
709
|
-
if (typeof fn !== "function")
|
|
710
|
-
problems.push(`option source "${name}" must be a function`);
|
|
711
|
-
if (!Array.isArray(def.actions))
|
|
712
|
-
return [...problems, "actions must be an array"];
|
|
713
|
-
checkLocalIds("action", def.actions, problems);
|
|
714
|
-
for (const action of def.actions) {
|
|
715
|
-
const name = typeof action?.id === "string" ? action.id : "?";
|
|
716
|
-
if (typeof action?.name !== "string")
|
|
717
|
-
problems.push(`action "${name}": name is required`);
|
|
718
|
-
const hasComponent = typeof action?.component === "function" || typeof action?.component === "object";
|
|
719
|
-
const hasRun = typeof action?.run === "function";
|
|
720
|
-
if (!hasComponent && !hasRun)
|
|
721
|
-
problems.push(`action "${name}": needs run or component`);
|
|
722
|
-
if (action?.look !== undefined && typeof action.look !== "function") {
|
|
723
|
-
problems.push(`action "${name}": look must be a function`);
|
|
724
|
-
}
|
|
725
|
-
const slots = action?.slots ?? ["key"];
|
|
726
|
-
if (!Array.isArray(slots) || slots.length === 0 || slots.some((s) => !["key", "sensor", "window"].includes(s))) {
|
|
727
|
-
problems.push(`action "${name}": slots must list "key", "sensor" and/or "window"`);
|
|
728
|
-
}
|
|
729
|
-
for (const p of checkSchema(action?.settings ?? {}, sources)) {
|
|
730
|
-
problems.push(`action "${name}": ${p}`);
|
|
731
|
-
}
|
|
732
|
-
for (const [key, field] of Object.entries(action?.settings ?? {})) {
|
|
733
|
-
if (field?.type === "secret") {
|
|
734
|
-
problems.push(`action "${name}": setting "${key}": secrets belong in the plugin settings`);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
if (def.state !== undefined) {
|
|
739
|
-
if (!Array.isArray(def.state))
|
|
740
|
-
problems.push("state must be an array");
|
|
741
|
-
else {
|
|
742
|
-
checkLocalIds("state", def.state, problems);
|
|
743
|
-
for (const s of def.state) {
|
|
744
|
-
const name = typeof s?.id === "string" ? s.id : "?";
|
|
745
|
-
if (typeof s?.name !== "string")
|
|
746
|
-
problems.push(`state "${name}": name is required`);
|
|
747
|
-
if (!["number", "string", "boolean", "json"].includes(s?.type)) {
|
|
748
|
-
problems.push(`state "${name}": type must be number, string, boolean or json`);
|
|
749
|
-
}
|
|
750
|
-
if (s?.poll && (typeof s.poll.read !== "function" || !(s.poll.everyMs > 0))) {
|
|
751
|
-
problems.push(`state "${name}": poll needs read() and everyMs > 0`);
|
|
752
|
-
}
|
|
753
|
-
if (s?.start !== undefined && typeof s.start !== "function") {
|
|
754
|
-
problems.push(`state "${name}": start must be a function`);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
if (def.triggers !== undefined) {
|
|
760
|
-
if (!Array.isArray(def.triggers))
|
|
761
|
-
problems.push("triggers must be an array");
|
|
762
|
-
else {
|
|
763
|
-
checkLocalIds("trigger", def.triggers, problems);
|
|
764
|
-
for (const t of def.triggers) {
|
|
765
|
-
const name = typeof t?.id === "string" ? t.id : "?";
|
|
766
|
-
if (typeof t?.name !== "string")
|
|
767
|
-
problems.push(`trigger "${name}": name is required`);
|
|
768
|
-
if (typeof t?.subscribe !== "function") {
|
|
769
|
-
problems.push(`trigger "${name}": subscribe is required`);
|
|
770
|
-
}
|
|
771
|
-
for (const p of checkSchema(t?.settings ?? {}, sources)) {
|
|
772
|
-
problems.push(`trigger "${name}": ${p}`);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return problems;
|
|
778
|
-
}
|
|
779
|
-
function checkOnboarding(def) {
|
|
780
|
-
const onboarding = def.onboarding;
|
|
781
|
-
if (!Array.isArray(onboarding?.steps))
|
|
782
|
-
return ["onboarding: steps must be an array"];
|
|
783
|
-
const problems = [];
|
|
784
|
-
checkLocalIds("onboarding step", onboarding.steps, problems);
|
|
785
|
-
const settings = def.settings ?? {};
|
|
786
|
-
const commands = new Set((def.commands ?? []).map((c) => c.id));
|
|
787
|
-
for (const step of onboarding.steps) {
|
|
788
|
-
const name = typeof step?.id === "string" ? step.id : "?";
|
|
789
|
-
if (typeof step?.title !== "string")
|
|
790
|
-
problems.push(`onboarding step "${name}": title is required`);
|
|
791
|
-
for (const key of step?.settings ?? []) {
|
|
792
|
-
if (!(key in settings))
|
|
793
|
-
problems.push(`onboarding step "${name}": no setting "${key}"`);
|
|
794
|
-
}
|
|
795
|
-
if (step?.command !== undefined && !commands.has(step.command)) {
|
|
796
|
-
problems.push(`onboarding step "${name}": no command "${step.command}"`);
|
|
797
|
-
}
|
|
798
|
-
if (step?.done !== undefined && typeof step.done !== "function") {
|
|
799
|
-
problems.push(`onboarding step "${name}": done must be a function`);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
const page = onboarding.starterPage;
|
|
803
|
-
if (page) {
|
|
804
|
-
const actions = new Set((def.actions ?? []).map((a) => a.id));
|
|
805
|
-
const used = [
|
|
806
|
-
...Object.values(page.keys ?? {}),
|
|
807
|
-
...Object.values(page.sensors ?? {}),
|
|
808
|
-
...page.window ? [page.window] : []
|
|
809
|
-
];
|
|
810
|
-
for (const { action } of used) {
|
|
811
|
-
if (!actions.has(action))
|
|
812
|
-
problems.push(`onboarding starter page: no action "${action}"`);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return problems;
|
|
816
|
-
}
|
|
817
8
|
// src/theme.ts
|
|
818
9
|
var THEME = {
|
|
819
10
|
background: "#16171d",
|
|
@@ -1045,7 +236,15 @@ var date = defineAction({
|
|
|
1045
236
|
});
|
|
1046
237
|
|
|
1047
238
|
// src/timers.tsx
|
|
1048
|
-
import {
|
|
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";
|
|
1049
248
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1050
249
|
var elapsed = (run, now) => run.banked + (run.startedAt === undefined ? 0 : now - run.startedAt);
|
|
1051
250
|
function toggled(run, now) {
|
|
@@ -1068,7 +267,7 @@ var timerEnded = defineTrigger({
|
|
|
1068
267
|
function Countdown(props) {
|
|
1069
268
|
const { remaining, total, running, label, accent, wide } = props;
|
|
1070
269
|
const done = remaining <= 0;
|
|
1071
|
-
const now =
|
|
270
|
+
const now = useNow2(done ? 500 : 60000);
|
|
1072
271
|
const flash = done && now.getTime() % 1000 < 500;
|
|
1073
272
|
const background = flash ? THEME.danger : props.pressed ? THEME.faint : props.background;
|
|
1074
273
|
const caption = done ? "Done" : running ? label : remaining < total ? "Paused" : label;
|
|
@@ -1148,7 +347,7 @@ function Countdown(props) {
|
|
|
1148
347
|
]
|
|
1149
348
|
});
|
|
1150
349
|
}
|
|
1151
|
-
var timer =
|
|
350
|
+
var timer = defineAction2({
|
|
1152
351
|
id: "timer",
|
|
1153
352
|
name: "Timer",
|
|
1154
353
|
description: "Counts down. Press to start or pause, hold to reset. Blinks when it ends.",
|
|
@@ -1170,10 +369,10 @@ var timer = defineAction({
|
|
|
1170
369
|
const pressed = useKeyPressed();
|
|
1171
370
|
const run = runOf(id);
|
|
1172
371
|
const running = run.startedAt !== undefined;
|
|
1173
|
-
const now =
|
|
372
|
+
const now = useNow2(running ? 250 : 60000).getTime();
|
|
1174
373
|
const remaining = Math.max(0, total - elapsed(run, now));
|
|
1175
374
|
const finished = running && remaining <= 0;
|
|
1176
|
-
|
|
375
|
+
useEffect(() => {
|
|
1177
376
|
if (!finished)
|
|
1178
377
|
return;
|
|
1179
378
|
runs.set(id, { banked: total });
|
|
@@ -1205,7 +404,7 @@ var timer = defineAction({
|
|
|
1205
404
|
});
|
|
1206
405
|
}
|
|
1207
406
|
});
|
|
1208
|
-
var stopwatch =
|
|
407
|
+
var stopwatch = defineAction2({
|
|
1209
408
|
id: "stopwatch",
|
|
1210
409
|
name: "Stopwatch",
|
|
1211
410
|
description: "Counts up. Press to start or stop, hold to reset.",
|
|
@@ -1224,7 +423,7 @@ var stopwatch = defineAction({
|
|
|
1224
423
|
const pressed = useKeyPressed();
|
|
1225
424
|
const run = runOf(id);
|
|
1226
425
|
const running = run.startedAt !== undefined;
|
|
1227
|
-
const now =
|
|
426
|
+
const now = useNow2(running ? 100 : 60000).getTime();
|
|
1228
427
|
const ms = elapsed(run, now);
|
|
1229
428
|
useKeyPress(() => {
|
|
1230
429
|
runs.set(id, toggled(runOf(id), Date.now()));
|
|
@@ -1289,7 +488,7 @@ function iconWithCaption(options) {
|
|
|
1289
488
|
]
|
|
1290
489
|
};
|
|
1291
490
|
}
|
|
1292
|
-
var label =
|
|
491
|
+
var label = defineAction3({
|
|
1293
492
|
id: "label",
|
|
1294
493
|
name: "Label",
|
|
1295
494
|
description: "Text and an icon or picture. The text can show live values: CPU {{system.cpu}}%.",
|
|
@@ -1303,9 +502,7 @@ var label = defineAction({
|
|
|
1303
502
|
color: { type: "color", label: "Text colour", default: THEME.text },
|
|
1304
503
|
fontSize: { type: "number", label: "Text size", default: 18, min: 8, max: 60 }
|
|
1305
504
|
},
|
|
1306
|
-
|
|
1307
|
-
return;
|
|
1308
|
-
},
|
|
505
|
+
display: true,
|
|
1309
506
|
look: (s) => {
|
|
1310
507
|
const layers = [];
|
|
1311
508
|
if (s.image) {
|
|
@@ -1328,7 +525,7 @@ var label = defineAction({
|
|
|
1328
525
|
return { background: s.background, layers };
|
|
1329
526
|
}
|
|
1330
527
|
});
|
|
1331
|
-
var counter =
|
|
528
|
+
var counter = defineAction3({
|
|
1332
529
|
id: "counter",
|
|
1333
530
|
name: "Counter",
|
|
1334
531
|
description: "Counts presses. Hold to reset. The count is saved.",
|
|
@@ -1342,8 +539,8 @@ var counter = defineAction({
|
|
|
1342
539
|
background: { type: "color", label: "Background", default: THEME.background }
|
|
1343
540
|
},
|
|
1344
541
|
component: ({ settings, setSettings }) => {
|
|
1345
|
-
const pressed =
|
|
1346
|
-
|
|
542
|
+
const pressed = useKeyPressed2();
|
|
543
|
+
useKeyPress2(() => setSettings({ count: settings.count + settings.step }), {
|
|
1347
544
|
onLongPress: () => setSettings({ count: 0 })
|
|
1348
545
|
});
|
|
1349
546
|
const text = String(settings.count);
|
|
@@ -1400,7 +597,7 @@ var targets = {
|
|
|
1400
597
|
home: "Home",
|
|
1401
598
|
favorite: "Favorites"
|
|
1402
599
|
};
|
|
1403
|
-
var navigate =
|
|
600
|
+
var navigate = defineAction3({
|
|
1404
601
|
id: "navigate",
|
|
1405
602
|
name: "Navigate",
|
|
1406
603
|
description: "Go to a page, back, forward, or to the next or previous page.",
|
|
@@ -1429,9 +626,9 @@ var navigate = defineAction({
|
|
|
1429
626
|
description: "After the last page comes the first.",
|
|
1430
627
|
visibleIf: { to: ["next", "previous"] }
|
|
1431
628
|
},
|
|
1432
|
-
text: { type: "text", label: "Text", placeholder: "Defaults to the target" },
|
|
1433
|
-
background: { type: "color", label: "Background", default: THEME.background },
|
|
1434
|
-
color: { type: "color", label: "Icon colour", default: THEME.accent }
|
|
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 }
|
|
1435
632
|
},
|
|
1436
633
|
run: ({ settings, deck }) => {
|
|
1437
634
|
if (settings.to === "page") {
|
|
@@ -1450,7 +647,7 @@ var navigate = defineAction({
|
|
|
1450
647
|
background: s.background
|
|
1451
648
|
})
|
|
1452
649
|
});
|
|
1453
|
-
var pageName =
|
|
650
|
+
var pageName = defineAction3({
|
|
1454
651
|
id: "page-name",
|
|
1455
652
|
name: "Page name",
|
|
1456
653
|
description: "Shows which page is open.",
|
|
@@ -1463,9 +660,7 @@ var pageName = defineAction({
|
|
|
1463
660
|
background: { type: "color", label: "Background", default: THEME.background },
|
|
1464
661
|
fontSize: { type: "number", label: "Text size", default: 20, min: 8, max: 60 }
|
|
1465
662
|
},
|
|
1466
|
-
|
|
1467
|
-
return;
|
|
1468
|
-
},
|
|
663
|
+
display: true,
|
|
1469
664
|
look: (s) => ({
|
|
1470
665
|
background: s.background,
|
|
1471
666
|
layers: [
|
|
@@ -1483,7 +678,7 @@ function nextLevel(levels, current) {
|
|
|
1483
678
|
const i = levels.indexOf(current);
|
|
1484
679
|
return levels[(i + 1) % levels.length];
|
|
1485
680
|
}
|
|
1486
|
-
var brightness =
|
|
681
|
+
var brightness = defineAction3({
|
|
1487
682
|
id: "brightness",
|
|
1488
683
|
name: "Brightness",
|
|
1489
684
|
description: "Set the deck's brightness, or cycle through levels.",
|
|
@@ -1514,7 +709,7 @@ var brightness = defineAction({
|
|
|
1514
709
|
default: "10, 40, 70, 100",
|
|
1515
710
|
visibleIf: { mode: "cycle" }
|
|
1516
711
|
},
|
|
1517
|
-
background: { type: "color", label: "Background", default: THEME.background }
|
|
712
|
+
background: { type: "color", label: "Background", default: THEME.background, appearance: true }
|
|
1518
713
|
},
|
|
1519
714
|
run: async ({ settings, deck }) => {
|
|
1520
715
|
const before = deck.brightness();
|
|
@@ -1539,7 +734,7 @@ var brightness = defineAction({
|
|
|
1539
734
|
var src_default = definePlugin({
|
|
1540
735
|
id: "@sdeck/plugin-basics",
|
|
1541
736
|
name: "Basics",
|
|
1542
|
-
version: "1.
|
|
737
|
+
version: "1.1.0",
|
|
1543
738
|
description: "Labels, a clock, the date, timers, a counter, page navigation and brightness.",
|
|
1544
739
|
author: "sdeck",
|
|
1545
740
|
actions: [label, clock, date, timer, stopwatch, counter, navigate, pageName, brightness],
|
|
@@ -1556,4 +751,4 @@ export {
|
|
|
1556
751
|
toggled
|
|
1557
752
|
};
|
|
1558
753
|
|
|
1559
|
-
//# debugId=
|
|
754
|
+
//# debugId=5D6275C202B3D4CA64756E2164756E21
|