@domicile-desktop/component-library 0.0.0-alpha-7e37a30d1bac → 0.0.0-alpha-617f1cc7ddbb
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/README.md +1 -0
- package/package.json +4 -3
- package/src/app-host-frames.ts +55 -0
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Each export is `@domicile-desktop/component-library/<name>`.
|
|
|
16
16
|
|
|
17
17
|
| Name | What it is |
|
|
18
18
|
|---|---|
|
|
19
|
+
| `app-host-frames` | `encodeFrame` and `frameDecoder`: the length-prefixed JSON an app module and `domicile-app-host` speak over stdio. |
|
|
19
20
|
| `Accordion` | Stack of sections that open and close. |
|
|
20
21
|
| `Autocomplete` | Text field with a suggestion list the caller supplies and ranks. |
|
|
21
22
|
| `Avatar` | Avatar with an initials or gradient fallback. |
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"dependencies": {
|
|
3
3
|
"@base-ui/react": "^1.8.0",
|
|
4
4
|
"@cprussin/option-result": "^2.0.1",
|
|
5
|
-
"@domicile-desktop/sdk": "0.0.0-alpha-
|
|
6
|
-
"@domicile-desktop/system-apps": "0.0.0-alpha-
|
|
5
|
+
"@domicile-desktop/sdk": "0.0.0-alpha-617f1cc7ddbb",
|
|
6
|
+
"@domicile-desktop/system-apps": "0.0.0-alpha-617f1cc7ddbb",
|
|
7
7
|
"@pandacss/dev": "^1.12.1",
|
|
8
8
|
"@phosphor-icons/react": "^2.1.10"
|
|
9
9
|
},
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"./AppChooser": "./src/AppChooser/AppChooser.tsx",
|
|
34
34
|
"./Autocomplete": "./src/Autocomplete/Autocomplete.tsx",
|
|
35
35
|
"./Avatar": "./src/Avatar/Avatar.tsx",
|
|
36
|
+
"./app-host-frames": "./src/app-host-frames.ts",
|
|
36
37
|
"./appearance": "./src/ThemeSwitch/appearance.ts",
|
|
37
38
|
"./Button": "./src/Button/Button.tsx",
|
|
38
39
|
"./Card": "./src/Card/Card.tsx",
|
|
@@ -108,5 +109,5 @@
|
|
|
108
109
|
"test:unit": "bun test"
|
|
109
110
|
},
|
|
110
111
|
"type": "module",
|
|
111
|
-
"version": "0.0.0-alpha-
|
|
112
|
+
"version": "0.0.0-alpha-617f1cc7ddbb"
|
|
112
113
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The framing of `domicile-app-host`, the process app modules spawn, on its
|
|
2
|
+
// stdin and stdout: each message is a 4-byte little-endian length, then that
|
|
3
|
+
// many bytes of UTF-8 JSON.
|
|
4
|
+
|
|
5
|
+
/** The bytes of the length before each message. */
|
|
6
|
+
const LENGTH_BYTES = 4;
|
|
7
|
+
|
|
8
|
+
/** `message` as one frame. */
|
|
9
|
+
export const encodeFrame = (message: unknown): Uint8Array => {
|
|
10
|
+
const body = new TextEncoder().encode(JSON.stringify(message));
|
|
11
|
+
const frame = new Uint8Array(LENGTH_BYTES + body.length);
|
|
12
|
+
new DataView(frame.buffer).setUint32(0, body.length, true);
|
|
13
|
+
frame.set(body, LENGTH_BYTES);
|
|
14
|
+
return frame;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A decoder for a stream of frames that arrive in chunks of any size. Each
|
|
19
|
+
* call takes the next chunk and returns the messages it completed, parsed
|
|
20
|
+
* from JSON.
|
|
21
|
+
*/
|
|
22
|
+
export const frameDecoder = () => {
|
|
23
|
+
let buffered: Uint8Array = new Uint8Array();
|
|
24
|
+
return (chunk: Uint8Array): unknown[] => {
|
|
25
|
+
buffered = joined(buffered, chunk);
|
|
26
|
+
const messages: unknown[] = [];
|
|
27
|
+
for (
|
|
28
|
+
let length = lengthOf(buffered);
|
|
29
|
+
length !== undefined && buffered.length >= LENGTH_BYTES + length;
|
|
30
|
+
length = lengthOf(buffered)
|
|
31
|
+
) {
|
|
32
|
+
const body = buffered.subarray(LENGTH_BYTES, LENGTH_BYTES + length);
|
|
33
|
+
messages.push(JSON.parse(new TextDecoder().decode(body)));
|
|
34
|
+
buffered = buffered.slice(LENGTH_BYTES + length);
|
|
35
|
+
}
|
|
36
|
+
return messages;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** The length `buffered` starts with, or `undefined` before all of it came. */
|
|
41
|
+
const lengthOf = (buffered: Uint8Array): number | undefined =>
|
|
42
|
+
buffered.length < LENGTH_BYTES
|
|
43
|
+
? undefined
|
|
44
|
+
: new DataView(
|
|
45
|
+
buffered.buffer,
|
|
46
|
+
buffered.byteOffset,
|
|
47
|
+
LENGTH_BYTES,
|
|
48
|
+
).getUint32(0, true);
|
|
49
|
+
|
|
50
|
+
const joined = (first: Uint8Array, second: Uint8Array): Uint8Array => {
|
|
51
|
+
const both = new Uint8Array(first.length + second.length);
|
|
52
|
+
both.set(first);
|
|
53
|
+
both.set(second, first.length);
|
|
54
|
+
return both;
|
|
55
|
+
};
|