@bun-native/core 0.0.0-bootstrap.0 → 0.33.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bunly contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @bun-native/core
2
+
3
+ The public TypeScript API of the Bun Native desktop framework.
4
+
5
+ Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.0 was built from [fa8bef754122](https://github.com/0xPlayerOne/bun-native/tree/fa8bef754122621d4235eb06e30bb1085b4f7b1e) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/fa8bef754122621d4235eb06e30bb1085b4f7b1e/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
@@ -0,0 +1,107 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "commit": "fa8bef754122621d4235eb06e30bb1085b4f7b1e",
4
+ "tree": "f805e2eb19a4e10fc29d1dc827cf5bc617b5773b",
5
+ "files": {
6
+ "package.json": {
7
+ "bytes": 2164,
8
+ "sha256": "db50b6f81f25c113a46f8c9b038bc548a92effaeb4ad9562e5e95044baa7b66f"
9
+ },
10
+ "packages/core/package.json": {
11
+ "bytes": 234,
12
+ "sha256": "e3e6aabd2e22d892540bf5dc64630334307fcfebb9b9f05ef3034f51fa1d63fc"
13
+ },
14
+ "packages/core/src/app-menu.ts": {
15
+ "bytes": 7879,
16
+ "sha256": "be41f76ea03059acb892700a172a8df3f07821af79f16332173399aaf6db7731"
17
+ },
18
+ "packages/core/src/application.ts": {
19
+ "bytes": 75969,
20
+ "sha256": "4dea1f51d55025dd0427815d200537a8e295dd4245a99ebc1f1e82587c54556a"
21
+ },
22
+ "packages/core/src/commit-plan.ts": {
23
+ "bytes": 8861,
24
+ "sha256": "04b4cd48ca0e6bf9eda03dce2fd3e0bf96eddea4e94bcf33ba7e4f597508a40d"
25
+ },
26
+ "packages/core/src/context-menus.ts": {
27
+ "bytes": 2555,
28
+ "sha256": "19c59698130066d5a09c977a77a03f54450a51c89523aba4d797044270f90ec8"
29
+ },
30
+ "packages/core/src/dialogs.ts": {
31
+ "bytes": 5546,
32
+ "sha256": "e0bfb065e5c63b835a4bf6b69c9d31d7608c5ddeaa5b5962c5cfff77ff5622cb"
33
+ },
34
+ "packages/core/src/display.ts": {
35
+ "bytes": 787,
36
+ "sha256": "e1fabce2f0640b4764c357834e6f600242941534ded6238b15c5e568dd66638e"
37
+ },
38
+ "packages/core/src/drops.ts": {
39
+ "bytes": 3231,
40
+ "sha256": "57e9d4c563652156f48c95b88dd340643917dc8cdbaf2e1ad0824a9a883bc8fb"
41
+ },
42
+ "packages/core/src/events.ts": {
43
+ "bytes": 10830,
44
+ "sha256": "3a4f8d97ccb50522e59db76f173cc88035b0c82e7a0b1df3c602498008243486"
45
+ },
46
+ "packages/core/src/files.ts": {
47
+ "bytes": 9190,
48
+ "sha256": "a65dad7045a37592e4672c9237fe85d6b02cf1aca616fb34a71689625a4de293"
49
+ },
50
+ "packages/core/src/index.ts": {
51
+ "bytes": 2509,
52
+ "sha256": "1ab9096fb92e6e0e06f73c07130f5c22e69e088896c59b8f6b3f7e803f425099"
53
+ },
54
+ "packages/core/src/message-dialogs.ts": {
55
+ "bytes": 19180,
56
+ "sha256": "907e6eaa550eddded30a4447d18674a676dc6f1edaaf9961c2ee71b6ac812128"
57
+ },
58
+ "packages/core/src/notifications.ts": {
59
+ "bytes": 4465,
60
+ "sha256": "7d2ead1b814304af936ff4ef990401a2728fd2847e6dd9d5f8041697310f016c"
61
+ },
62
+ "packages/core/src/overlays.ts": {
63
+ "bytes": 2095,
64
+ "sha256": "1634d00f9585e355b633c461c64b702e19ab9b0277028357d75cf239e8f7c5de"
65
+ },
66
+ "packages/core/src/processes.ts": {
67
+ "bytes": 7770,
68
+ "sha256": "079df5516eedc817b81068893cd0293fe7a9a12beeaaf681e9b00a71d3fea596"
69
+ },
70
+ "packages/core/src/services.ts": {
71
+ "bytes": 16678,
72
+ "sha256": "d8f4af83a0c6e1c99bf93ab8fc628c2b62edef3ef804d46ebdd69ab5ae5d53a8"
73
+ },
74
+ "packages/core/src/shortcuts.ts": {
75
+ "bytes": 4326,
76
+ "sha256": "51f3ffb2db76aeec1db8db63b18dedae2772c5ad33be41504e1a8070eaa2e3e0"
77
+ },
78
+ "packages/core/src/splits.ts": {
79
+ "bytes": 1232,
80
+ "sha256": "1274f9e5b695e32959059e6fad95517369d05e260129c068064c3e10317d1fba"
81
+ },
82
+ "packages/core/src/theme.ts": {
83
+ "bytes": 3670,
84
+ "sha256": "c460c4e1a2e9d337e79294bce333e53896381529af8f7e35b23e207c6e132b85"
85
+ },
86
+ "packages/core/src/tree.ts": {
87
+ "bytes": 24844,
88
+ "sha256": "dcaf0b12360b8e7274a981ef1c2bde87b79fc46b0b5ce311a6c9a50f960c564b"
89
+ },
90
+ "packages/core/src/types.ts": {
91
+ "bytes": 14319,
92
+ "sha256": "25400d57bebe1a449ec2c877b0d2cecd58ff172ddc3192eb93bc2532c5ccbf43"
93
+ },
94
+ "LICENSE": {
95
+ "bytes": 1075,
96
+ "sha256": "86673fb485f12fa9aaa3941dfccc9f69a7f8322f8141d0d5c73db4323de10ac5"
97
+ }
98
+ },
99
+ "toolchain": {
100
+ "bytes": 3012,
101
+ "sha256": "00c3f707aae8abe9ca75cd2e162f5e1c7c34362a03675da39afead60d856066a"
102
+ },
103
+ "dependencyLock": {
104
+ "bytes": 28357,
105
+ "sha256": "65e3dbd01be4a1889367690faf1a9c3f08fb31d22dbd273d9bb9f39dd6baa6fb"
106
+ }
107
+ }
package/package.json CHANGED
@@ -1 +1,32 @@
1
- {"name":"@bun-native/core","version":"0.0.0-bootstrap.0","description":"Placeholder. Releases publish from GitHub Actions.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/0xPlayerOne/bun-native.git"}}
1
+ {
2
+ "name": "@bun-native/core",
3
+ "version": "0.33.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "files": [
7
+ "src",
8
+ "LICENSE",
9
+ "README.md",
10
+ "bun-native-source.json"
11
+ ],
12
+ "engines": {
13
+ "bun": "1.4.4-canary.1"
14
+ },
15
+ "exports": "./src/index.ts",
16
+ "description": "The public TypeScript API of the Bun Native desktop framework.",
17
+ "dependencies": {
18
+ "@bun-native/protocol": "0.33.0",
19
+ "@bun-native/runtime": "0.33.0"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/0xPlayerOne/bun-native.git",
24
+ "directory": "packages/core"
25
+ },
26
+ "homepage": "https://github.com/0xPlayerOne/bun-native#readme",
27
+ "bugs": "https://github.com/0xPlayerOne/bun-native/issues",
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "provenance": true
31
+ }
32
+ }
@@ -0,0 +1,271 @@
1
+ import {
2
+ APP_MENU_KEYS,
3
+ MAX_APP_MENU_DEPTH,
4
+ MAX_APP_MENU_ENTRIES,
5
+ parseAppMenus,
6
+ ProtocolError,
7
+ type AppMenu,
8
+ type AppMenuEntry,
9
+ } from '@bun-native/protocol'
10
+ import type { Listener } from './types.ts'
11
+
12
+ type Letter =
13
+ | 'a'
14
+ | 'b'
15
+ | 'c'
16
+ | 'd'
17
+ | 'e'
18
+ | 'f'
19
+ | 'g'
20
+ | 'h'
21
+ | 'i'
22
+ | 'j'
23
+ | 'k'
24
+ | 'l'
25
+ | 'm'
26
+ | 'n'
27
+ | 'o'
28
+ | 'p'
29
+ | 'q'
30
+ | 'r'
31
+ | 's'
32
+ | 't'
33
+ | 'u'
34
+ | 'v'
35
+ | 'w'
36
+ | 'x'
37
+ | 'y'
38
+ | 'z'
39
+ type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
40
+ type FunctionKey = `f${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}`
41
+ type Punctuation = ',' | '.' | '/' | ';' | "'" | '[' | ']' | '-' | '=' | '`' | '\\'
42
+ type NamedKey =
43
+ | 'enter'
44
+ | 'escape'
45
+ | 'tab'
46
+ | 'space'
47
+ | 'backspace'
48
+ | 'delete'
49
+ | 'up'
50
+ | 'down'
51
+ | 'left'
52
+ | 'right'
53
+ | 'home'
54
+ | 'end'
55
+ | 'pageup'
56
+ | 'pagedown'
57
+
58
+ /** The closed key set of a menu shortcut. */
59
+ export type MenuShortcutKey = Letter | Digit | FunctionKey | Punctuation | NamedKey
60
+
61
+ export interface MenuShortcutOptions {
62
+ readonly key: MenuShortcutKey
63
+ readonly control?: boolean
64
+ readonly alt?: boolean
65
+ readonly shift?: boolean
66
+ /** Command on macOS. Every key except f1-f12 needs control, alt or platform. */
67
+ readonly platform?: boolean
68
+ }
69
+
70
+ export type MenuEntryOptions =
71
+ | Readonly<{
72
+ kind: 'item'
73
+ /** Reported back on selection: 1-64 of `A-Z a-z 0-9 . _ : -`, unique in the bar. */
74
+ id: string
75
+ label: string
76
+ /** Shown beside the item and bound while the bar is installed; unique in the bar. */
77
+ shortcut?: MenuShortcutOptions
78
+ /** Default true. */
79
+ enabled?: boolean
80
+ /** Default false. */
81
+ checked?: boolean
82
+ }>
83
+ | Readonly<{ kind: 'separator' }>
84
+ | Readonly<{
85
+ kind: 'submenu'
86
+ label: string
87
+ /** Default true. */
88
+ enabled?: boolean
89
+ items: readonly MenuEntryOptions[]
90
+ }>
91
+
92
+ export interface MenuOptions {
93
+ /** On macOS the first menu is the application menu, shown under the process name. */
94
+ readonly title: string
95
+ readonly items: readonly MenuEntryOptions[]
96
+ }
97
+
98
+ export interface AppMenuItemEvent {
99
+ readonly type: 'app_menu_item'
100
+ readonly sequence: number
101
+ /** The application's `id` of the selected item. */
102
+ readonly itemId: string
103
+ readonly menuBar: NativeMenuBar
104
+ /** Aborted when the bar is replaced, cleared, or the app stops. */
105
+ readonly signal: AbortSignal
106
+ }
107
+
108
+ export interface NativeMenuBar {
109
+ /** False once replaced, cleared or revoked; no later selection is delivered. */
110
+ readonly active: boolean
111
+ /** Removes this bar if it is still installed. Idempotent; a replaced bar is left alone. */
112
+ clear(): Promise<void>
113
+ }
114
+
115
+ function options(value: unknown, field: string, allowed: readonly string[]) {
116
+ if (!value || typeof value !== 'object' || Array.isArray(value))
117
+ throw new TypeError(field + ' must be an object')
118
+ if (Object.keys(value).some((key) => !allowed.includes(key)))
119
+ throw new TypeError('Unknown ' + field + ' option')
120
+ return value as Record<string, unknown>
121
+ }
122
+
123
+ function flag(data: Record<string, unknown>, key: string, fallback: boolean): boolean {
124
+ const value = Object.hasOwn(data, key) ? data[key] : fallback
125
+ if (typeof value !== 'boolean') throw new TypeError('Menu ' + key + ' must be a boolean')
126
+ return value
127
+ }
128
+
129
+ function list(value: unknown, field: string): readonly unknown[] {
130
+ if (!Array.isArray(value)) throw new TypeError(field + ' must be an array')
131
+ return value
132
+ }
133
+
134
+ interface Budget {
135
+ entries: number
136
+ }
137
+
138
+ function shortcut(
139
+ value: unknown
140
+ ): NonNullable<Extract<AppMenuEntry, { kind: 'item' }>['shortcut']> {
141
+ const data = options(value, 'Menu shortcut', ['key', 'control', 'alt', 'shift', 'platform'])
142
+ const key = data['key']
143
+ if (typeof key !== 'string' || !APP_MENU_KEYS.includes(key))
144
+ throw new TypeError('Menu shortcut key is not in the closed key set')
145
+ return {
146
+ key,
147
+ modifiers: {
148
+ control: flag(data, 'control', false),
149
+ alt: flag(data, 'alt', false),
150
+ shift: flag(data, 'shift', false),
151
+ platform: flag(data, 'platform', false),
152
+ },
153
+ }
154
+ }
155
+
156
+ function entries(value: unknown, depth: number, budget: Budget): AppMenuEntry[] {
157
+ // Bounded before recursion, so a cyclic or huge consumer object is rejected.
158
+ return list(value, 'Menu items').map((raw): AppMenuEntry => {
159
+ if (++budget.entries > MAX_APP_MENU_ENTRIES)
160
+ throw new TypeError('A menu bar holds at most 128 entries')
161
+ const kind =
162
+ raw && typeof raw === 'object' ? (raw as Record<string, unknown>)['kind'] : undefined
163
+ switch (kind) {
164
+ case 'item': {
165
+ const data = options(raw, 'Menu item', [
166
+ 'kind',
167
+ 'id',
168
+ 'label',
169
+ 'shortcut',
170
+ 'enabled',
171
+ 'checked',
172
+ ])
173
+ return {
174
+ kind: 'item',
175
+ id: data['id'] as string,
176
+ label: data['label'] as string,
177
+ ...(Object.hasOwn(data, 'shortcut') ? { shortcut: shortcut(data['shortcut']) } : {}),
178
+ enabled: flag(data, 'enabled', true),
179
+ checked: flag(data, 'checked', false),
180
+ }
181
+ }
182
+ case 'separator':
183
+ options(raw, 'Menu separator', ['kind'])
184
+ return { kind: 'separator' }
185
+ case 'submenu': {
186
+ const data = options(raw, 'Submenu', ['kind', 'label', 'enabled', 'items'])
187
+ if (depth >= MAX_APP_MENU_DEPTH)
188
+ throw new TypeError('Submenus nest at most two levels below a top-level menu')
189
+ return {
190
+ kind: 'submenu',
191
+ label: data['label'] as string,
192
+ enabled: flag(data, 'enabled', true),
193
+ items: entries(data['items'], depth + 1, budget),
194
+ }
195
+ }
196
+ default:
197
+ throw new TypeError("Menu entry kind must be 'item', 'separator' or 'submenu'")
198
+ }
199
+ })
200
+ }
201
+
202
+ /** The entries of one menu in wire shape, not yet validated as a whole. */
203
+ export function menuEntriesRequest(items: readonly MenuEntryOptions[]): AppMenuEntry[] {
204
+ return entries(items, 1, { entries: 0 })
205
+ }
206
+
207
+ /** Copies consumer options into the closed wire shape and validates it with the shared parser. */
208
+ export function menuBarRequest(menus: readonly MenuOptions[]): AppMenu[] {
209
+ const budget: Budget = { entries: 0 }
210
+ const wire = list(menus, 'Menu bar').map((raw) => {
211
+ const data = options(raw, 'Menu', ['title', 'items'])
212
+ return {
213
+ title: data['title'] as string,
214
+ items: entries(data['items'], 1, budget),
215
+ }
216
+ })
217
+ try {
218
+ return parseAppMenus(wire)
219
+ } catch (error) {
220
+ if (error instanceof ProtocolError) throw new TypeError(error.message)
221
+ throw error
222
+ }
223
+ }
224
+
225
+ /** Internal registry entry. Consumers only receive its frozen handle. */
226
+ export class MenuBarRegistration {
227
+ readonly handle: NativeMenuBar
228
+ readonly controller = new AbortController()
229
+ listener: Listener<AppMenuItemEvent> | undefined
230
+ private revoked = false
231
+ private clearing: Promise<void> | undefined
232
+
233
+ constructor(
234
+ readonly id: number,
235
+ listener: Listener<AppMenuItemEvent>,
236
+ clear: (registration: MenuBarRegistration) => Promise<void>
237
+ ) {
238
+ this.listener = listener
239
+ this.handle = publicHandle(this, clear)
240
+ }
241
+
242
+ /** Shared by the public handle; one clear per registration. */
243
+ clear(clear: (registration: MenuBarRegistration) => Promise<void>): Promise<void> {
244
+ this.clearing ??= this.revoked ? Promise.resolve() : clear(this)
245
+ return this.clearing
246
+ }
247
+
248
+ get live(): boolean {
249
+ return !this.revoked
250
+ }
251
+
252
+ /** Synchronous local revocation; the native bar is replaced separately. */
253
+ revoke(): void {
254
+ if (this.revoked) return
255
+ this.revoked = true
256
+ this.listener = undefined
257
+ this.controller.abort()
258
+ }
259
+ }
260
+
261
+ function publicHandle(
262
+ registration: MenuBarRegistration,
263
+ clear: (registration: MenuBarRegistration) => Promise<void>
264
+ ): NativeMenuBar {
265
+ return Object.freeze({
266
+ get active() {
267
+ return registration.live
268
+ },
269
+ clear: () => registration.clear(clear),
270
+ })
271
+ }