dsh-offwork 1.0.0 → 1.0.1
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/CHANGELOG.md +17 -0
- package/README.md +58 -39
- package/client.js +1001 -299
- package/client.source.js +896 -252
- package/clock.js +81 -34
- package/index.js +142 -66
- package/locale/en.json +6 -1
- package/locale/zh.json +6 -1
- package/package.json +18 -5
- package/tests/clock.test.mjs +76 -33
- package/tests/host.test.mjs +76 -27
- package/tests/ui.test.mjs +77 -20
- package/tools/build.mjs +22 -7
- package/tools/check-package.mjs +96 -0
- package/ui-utils.js +21 -10
package/ui-utils.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
export function formatDuration(seconds) {
|
|
3
3
|
if (!Number.isFinite(seconds) || seconds < 0) return '--:--:--';
|
|
4
4
|
const n = Math.ceil(seconds);
|
|
5
|
-
return [Math.floor(n / 3600), Math.floor(n % 3600 / 60), n % 60]
|
|
6
|
-
.map(part => String(part).padStart(2, '0'))
|
|
5
|
+
return [Math.floor(n / 3600), Math.floor((n % 3600) / 60), n % 60]
|
|
6
|
+
.map((part) => String(part).padStart(2, '0'))
|
|
7
|
+
.join(':');
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function clampPosition(position, viewport, size) {
|
|
10
|
-
const width = Math.max(0, viewport.width),
|
|
11
|
+
const width = Math.max(0, viewport.width),
|
|
12
|
+
height = Math.max(0, viewport.height);
|
|
11
13
|
const edge = Math.min(12, width / 2, height / 2);
|
|
12
14
|
const maxX = Math.max(edge, width - size.width - edge);
|
|
13
15
|
const maxY = Math.max(edge, height - size.height - edge);
|
|
@@ -28,8 +30,10 @@ export function normalizeView(value) {
|
|
|
28
30
|
mini: value?.mini !== false,
|
|
29
31
|
masked: value?.masked !== false,
|
|
30
32
|
opacity: clampOpacity(value?.opacity),
|
|
31
|
-
position:
|
|
32
|
-
|
|
33
|
+
position:
|
|
34
|
+
Number.isFinite(value?.position?.x) && Number.isFinite(value?.position?.y)
|
|
35
|
+
? { x: value.position.x, y: value.position.y }
|
|
36
|
+
: null,
|
|
33
37
|
};
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -38,14 +42,21 @@ export function decodeCommand(rpc) {
|
|
|
38
42
|
const result = rpc.value?.result;
|
|
39
43
|
if (!result || typeof result.text !== 'string') throw new Error('Command unavailable');
|
|
40
44
|
let data;
|
|
41
|
-
try {
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
try {
|
|
46
|
+
data = JSON.parse(result.text);
|
|
47
|
+
} catch {
|
|
48
|
+
throw new Error('Invalid command response');
|
|
49
|
+
}
|
|
50
|
+
if (result.kind !== 'success' || data?.ok !== true)
|
|
51
|
+
throw new Error(data?.error || 'Request failed');
|
|
44
52
|
if (!data.settings || typeof data.settings !== 'object') throw new Error('Missing settings');
|
|
45
53
|
return data;
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
export function changedSettings(original, draft) {
|
|
49
|
-
return Object.fromEntries(
|
|
50
|
-
.
|
|
57
|
+
return Object.fromEntries(
|
|
58
|
+
Object.entries(draft).filter(
|
|
59
|
+
([key, value]) => JSON.stringify(value) !== JSON.stringify(original[key]),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
51
62
|
}
|