@owdproject/core 3.4.0 → 4.0.0-alpha.4
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 +112 -13
- package/dist/dom/index.d.mts +65 -0
- package/dist/dom/index.d.ts +65 -0
- package/dist/dom/index.mjs +224 -0
- package/dist/events/index.d.mts +70 -0
- package/dist/events/index.d.ts +70 -0
- package/dist/events/index.mjs +3 -0
- package/dist/index.d.mts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.mjs +115 -0
- package/dist/layout/index.d.mts +41 -0
- package/dist/layout/index.d.ts +41 -0
- package/dist/layout/index.mjs +64 -0
- package/dist/machines/index.d.mts +31 -0
- package/dist/machines/index.d.ts +31 -0
- package/dist/machines/index.mjs +2 -0
- package/dist/managers/index.d.mts +118 -0
- package/dist/managers/index.d.ts +118 -0
- package/dist/managers/index.mjs +6 -0
- package/dist/session/index.d.mts +57 -0
- package/dist/session/index.d.ts +57 -0
- package/dist/session/index.mjs +65 -0
- package/dist/shared/core.B1XxB289.mjs +239 -0
- package/dist/shared/core.B3mp7ztE.mjs +237 -0
- package/dist/shared/core.BOvFdEVQ.d.ts +114 -0
- package/dist/shared/core.CsDFgGnX.mjs +40 -0
- package/dist/shared/core.Di1eFcr_.d.mts +114 -0
- package/dist/shared/core.Pd_Ogt4g.mjs +101 -0
- package/dist/shared/core.b3Xldzyu.mjs +29 -0
- package/dist/shared/core.d_A3q1kZ.mjs +869 -0
- package/dist/types/index.d.mts +266 -0
- package/dist/types/index.d.ts +266 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +56 -112
- package/CHANGELOG.md +0 -98
- package/DESKTOP_KERNEL.md +0 -232
- package/MIGRATION_3.3.2.md +0 -23
- package/MIGRATION_3.4.md +0 -126
- package/PLAYGROUND.md +0 -91
- package/dist/module.d.mts +0 -13
- package/dist/module.json +0 -9
- package/dist/module.mjs +0 -254
- package/dist/types.d.mts +0 -7
- package/index.ts +0 -8
- package/kit/authoring.ts +0 -340
- package/kit/defineDesktopApp.ts +0 -56
- package/module.ts +0 -203
- package/runtime/components/Application/DesktopCoreApplicationRender.vue +0 -20
- package/runtime/components/Application/DesktopCoreApplicationWindowsRender.vue +0 -38
- package/runtime/components/background/DesktopCoreBackground.vue +0 -16
- package/runtime/components/core/DesktopCore.vue +0 -43
- package/runtime/components/time/DesktopCoreTime.vue +0 -56
- package/runtime/components/window/DesktopCoreWindow.vue +0 -215
- package/runtime/components/window/DesktopCoreWindowContent.vue +0 -28
- package/runtime/components/window/DesktopCoreWindowNav.vue +0 -66
- package/runtime/components/window/DesktopCoreWindowSnapHintsBase.vue +0 -74
- package/runtime/components/workspace/DesktopCoreWorkspaceEdgeHintsBase.vue +0 -84
- package/runtime/composables/useApplicationEntries.ts +0 -51
- package/runtime/composables/useApplicationManager.ts +0 -285
- package/runtime/composables/useBlockNonInputContextMenu.ts +0 -30
- package/runtime/composables/useDesktopConfig.ts +0 -8
- package/runtime/composables/useDesktopDialogs.ts +0 -16
- package/runtime/composables/useDesktopExtension.ts +0 -8
- package/runtime/composables/useDesktopManager.ts +0 -51
- package/runtime/composables/useDesktopManifest.ts +0 -17
- package/runtime/composables/useDesktopSession.ts +0 -27
- package/runtime/composables/useDesktopShellIdentity.ts +0 -99
- package/runtime/composables/useDesktopShellOptions.ts +0 -36
- package/runtime/composables/useDesktopShellReady.ts +0 -7
- package/runtime/composables/useDesktopWorkArea.ts +0 -93
- package/runtime/composables/useTerminalManager.ts +0 -159
- package/runtime/composables/useToggleWindowMaximize.ts +0 -35
- package/runtime/composables/useWindowDragHandlers.ts +0 -47
- package/runtime/composables/useWindowSnapDrop.ts +0 -112
- package/runtime/composables/useWorkspaceEdgeDrop.ts +0 -176
- package/runtime/composables/useWorkspaceManager.ts +0 -67
- package/runtime/composables/useWorkspaceOverviewCapture.ts +0 -92
- package/runtime/composables/useWorkspaceOverviewLiveScale.ts +0 -151
- package/runtime/constants/desktopShellKeys.ts +0 -12
- package/runtime/constants/shellLayout.ts +0 -5
- package/runtime/dialogs/desktopDialogProvider.ts +0 -73
- package/runtime/internal/controllers/ApplicationController.ts +0 -351
- package/runtime/internal/controllers/WindowController.ts +0 -547
- package/runtime/plugins/01.desktop-shell-init.client.ts +0 -28
- package/runtime/plugins/02.desktop-register-desktop-apps.client.ts +0 -13
- package/runtime/plugins/resize.client.ts +0 -6
- package/runtime/stores/storeApplicationMeta.ts +0 -60
- package/runtime/stores/storeApplicationWindows.ts +0 -21
- package/runtime/stores/storeDesktop.ts +0 -71
- package/runtime/stores/storeDesktopDefaultApps.ts +0 -54
- package/runtime/stores/storeDesktopVolume.ts +0 -19
- package/runtime/stores/storeDesktopWindow.ts +0 -38
- package/runtime/stores/storeDesktopWorkspace.ts +0 -105
- package/runtime/stores/storeIds.ts +0 -35
- package/runtime/types/desktopMenu.ts +0 -10
- package/runtime/utils/initDesktopShell.ts +0 -80
- package/runtime/utils/migratePersistedStoreIds.ts +0 -57
- package/runtime/utils/utilApp.ts +0 -25
- package/runtime/utils/utilCaptureElementToCanvas.ts +0 -21
- package/runtime/utils/utilCommon.ts +0 -26
- package/runtime/utils/utilDebug.ts +0 -30
- package/runtime/utils/utilDetectSnapZone.ts +0 -57
- package/runtime/utils/utilTerminal.ts +0 -6
- package/runtime/utils/utilWindowControllerAdapter.ts +0 -15
- package/runtime/utils/utilWindowLayout.ts +0 -82
- package/runtime/utils/utilWindowMaximizeLayout.ts +0 -44
- package/runtime/utils/utilWorkspaceWindows.ts +0 -33
- package/types/index.d.ts +0 -531
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate';
|
|
2
|
+
|
|
3
|
+
const windowMachine = createMachine({
|
|
4
|
+
id: "window",
|
|
5
|
+
initial: "normal",
|
|
6
|
+
context: ({ input }) => ({
|
|
7
|
+
wasMaximized: false,
|
|
8
|
+
config: input?.config
|
|
9
|
+
}),
|
|
10
|
+
states: {
|
|
11
|
+
normal: {
|
|
12
|
+
entry: assign({ wasMaximized: false }),
|
|
13
|
+
initial: "focused",
|
|
14
|
+
states: {
|
|
15
|
+
focused: {
|
|
16
|
+
initial: "idle",
|
|
17
|
+
states: {
|
|
18
|
+
idle: {
|
|
19
|
+
on: {
|
|
20
|
+
DRAG_START: "dragging",
|
|
21
|
+
RESIZE_START: "resizing"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
dragging: {
|
|
25
|
+
on: {
|
|
26
|
+
DRAG_END: "idle",
|
|
27
|
+
SNAP_DROP: "idle"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
resizing: {
|
|
31
|
+
on: {
|
|
32
|
+
RESIZE_END: "idle"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
on: {
|
|
37
|
+
BLUR: "unfocused",
|
|
38
|
+
MAXIMIZE: "#window.maximized.focused",
|
|
39
|
+
MINIMIZE: "#window.minimized"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
unfocused: {
|
|
43
|
+
on: {
|
|
44
|
+
FOCUS: "focused",
|
|
45
|
+
MAXIMIZE: "#window.maximized.unfocused",
|
|
46
|
+
MINIMIZE: "#window.minimized"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
on: {
|
|
51
|
+
DESTROY: "closed"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
maximized: {
|
|
55
|
+
entry: assign({ wasMaximized: true }),
|
|
56
|
+
initial: "focused",
|
|
57
|
+
states: {
|
|
58
|
+
focused: {
|
|
59
|
+
on: {
|
|
60
|
+
BLUR: "unfocused",
|
|
61
|
+
RESTORE: "#window.normal.focused",
|
|
62
|
+
MINIMIZE: "#window.minimized"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
unfocused: {
|
|
66
|
+
on: {
|
|
67
|
+
FOCUS: "focused",
|
|
68
|
+
RESTORE: "#window.normal.unfocused",
|
|
69
|
+
MINIMIZE: "#window.minimized"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
on: {
|
|
74
|
+
DESTROY: "closed"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
minimized: {
|
|
78
|
+
on: {
|
|
79
|
+
RESTORE: [
|
|
80
|
+
{
|
|
81
|
+
target: "maximized.focused",
|
|
82
|
+
guard: ({ context }) => context.wasMaximized
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
target: "normal.focused"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
DESTROY: "closed"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
closed: {
|
|
92
|
+
type: "final"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const applicationMachine = createMachine({
|
|
98
|
+
id: "application",
|
|
99
|
+
initial: "idle",
|
|
100
|
+
context: ({ input }) => ({
|
|
101
|
+
id: input?.id ?? "",
|
|
102
|
+
config: input?.config,
|
|
103
|
+
windowCount: 0
|
|
104
|
+
}),
|
|
105
|
+
states: {
|
|
106
|
+
idle: {
|
|
107
|
+
on: {
|
|
108
|
+
LAUNCH: "initializing",
|
|
109
|
+
RESTORE: "initializing",
|
|
110
|
+
OPEN_WINDOW: {
|
|
111
|
+
target: "running.active",
|
|
112
|
+
actions: assign({
|
|
113
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
initializing: {
|
|
119
|
+
on: {
|
|
120
|
+
INITIALIZED: [
|
|
121
|
+
{
|
|
122
|
+
target: "running.active",
|
|
123
|
+
guard: ({ context }) => context.windowCount > 0
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
target: "ready"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
OPEN_WINDOW: {
|
|
130
|
+
actions: assign({
|
|
131
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
132
|
+
})
|
|
133
|
+
},
|
|
134
|
+
INIT_FAILED: "error"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
ready: {
|
|
138
|
+
on: {
|
|
139
|
+
LAUNCH: "running.active",
|
|
140
|
+
START_PROCESS: "running.active",
|
|
141
|
+
OPEN_WINDOW: {
|
|
142
|
+
target: "running.active",
|
|
143
|
+
actions: assign({
|
|
144
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
CLOSE_APP: "terminating"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
running: {
|
|
151
|
+
initial: "active",
|
|
152
|
+
states: {
|
|
153
|
+
active: {
|
|
154
|
+
on: {
|
|
155
|
+
MINIMIZE_ALL: "suspended",
|
|
156
|
+
SUSPEND: "suspended",
|
|
157
|
+
SIGSTOP: "suspended",
|
|
158
|
+
CLOSE_WINDOW: [
|
|
159
|
+
{
|
|
160
|
+
target: "#application.terminating",
|
|
161
|
+
guard: ({ context }) => context.windowCount - 1 <= 0,
|
|
162
|
+
actions: assign({
|
|
163
|
+
windowCount: () => 0
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
actions: assign({
|
|
168
|
+
windowCount: ({ context }) => Math.max(0, context.windowCount - 1)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
OPEN_WINDOW: {
|
|
173
|
+
actions: assign({
|
|
174
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
suspended: {
|
|
180
|
+
on: {
|
|
181
|
+
RESTORE_WINDOW: "active",
|
|
182
|
+
RESUME: "active",
|
|
183
|
+
SIGCONT: "active",
|
|
184
|
+
LAUNCH: "active",
|
|
185
|
+
OPEN_WINDOW: {
|
|
186
|
+
target: "active",
|
|
187
|
+
actions: assign({
|
|
188
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
189
|
+
})
|
|
190
|
+
},
|
|
191
|
+
CLOSE_WINDOW: [
|
|
192
|
+
{
|
|
193
|
+
target: "#application.terminating",
|
|
194
|
+
guard: ({ context }) => context.windowCount - 1 <= 0,
|
|
195
|
+
actions: assign({
|
|
196
|
+
windowCount: () => 0
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
actions: assign({
|
|
201
|
+
windowCount: ({ context }) => Math.max(0, context.windowCount - 1)
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
on: {
|
|
209
|
+
CLOSE_APP: "terminating",
|
|
210
|
+
SIGTERM: "terminating",
|
|
211
|
+
SIGKILL: "terminating"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
terminating: {
|
|
215
|
+
entry: assign({
|
|
216
|
+
windowCount: () => 0
|
|
217
|
+
}),
|
|
218
|
+
on: {
|
|
219
|
+
TERMINATED: "ready"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
error: {
|
|
223
|
+
on: {
|
|
224
|
+
RESET: "ready",
|
|
225
|
+
LAUNCH: "running.active",
|
|
226
|
+
OPEN_WINDOW: {
|
|
227
|
+
target: "running.active",
|
|
228
|
+
actions: assign({
|
|
229
|
+
windowCount: ({ context }) => context.windowCount + 1
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export { applicationMachine as a, windowMachine as w };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Hookable } from 'hookable';
|
|
2
|
+
import { DesktopKernelEvent, DesktopRuntimeHooks, WindowConfig, WindowState, WindowLayout, DesktopWorkareaRect, SpatialTransform } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
type EventHandler = (event: DesktopKernelEvent) => void;
|
|
5
|
+
declare class CoreIPCBus {
|
|
6
|
+
private readonly maxEvents;
|
|
7
|
+
private events;
|
|
8
|
+
private readonly listeners;
|
|
9
|
+
private eventCounter;
|
|
10
|
+
private subscribers;
|
|
11
|
+
constructor(options?: {
|
|
12
|
+
maxEvents?: number;
|
|
13
|
+
});
|
|
14
|
+
emit(channel: string, payload?: any, options?: {
|
|
15
|
+
source?: string;
|
|
16
|
+
severity?: 'info' | 'warn' | 'error';
|
|
17
|
+
}): DesktopKernelEvent;
|
|
18
|
+
on(channel: string, handler: EventHandler): () => void;
|
|
19
|
+
off(channel: string, handler: EventHandler): void;
|
|
20
|
+
getEvents(): DesktopKernelEvent[];
|
|
21
|
+
getActiveChannels(): string[];
|
|
22
|
+
clear(): void;
|
|
23
|
+
subscribe(callback: (events: DesktopKernelEvent[]) => void): () => void;
|
|
24
|
+
}
|
|
25
|
+
declare const globalIPCBus: CoreIPCBus;
|
|
26
|
+
|
|
27
|
+
declare class WindowInstance {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly model: string;
|
|
30
|
+
readonly applicationId?: string;
|
|
31
|
+
config: WindowConfig;
|
|
32
|
+
state: WindowState;
|
|
33
|
+
meta: Record<string, any>;
|
|
34
|
+
private actor;
|
|
35
|
+
private isDisposed;
|
|
36
|
+
private subscribers;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
id: string;
|
|
39
|
+
model: string;
|
|
40
|
+
applicationId?: string;
|
|
41
|
+
config: WindowConfig;
|
|
42
|
+
initialState?: Partial<WindowState>;
|
|
43
|
+
meta?: Record<string, any>;
|
|
44
|
+
workspace?: string;
|
|
45
|
+
});
|
|
46
|
+
private updateState;
|
|
47
|
+
getSnapshot(): WindowState;
|
|
48
|
+
subscribe(callback: (snapshot: WindowState) => void): () => void;
|
|
49
|
+
private notify;
|
|
50
|
+
get stateValue(): string;
|
|
51
|
+
setPosition(data: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z?: number;
|
|
55
|
+
}): void;
|
|
56
|
+
setSize(data: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
}): void;
|
|
60
|
+
setFocus(value: boolean): void;
|
|
61
|
+
minimize(): boolean;
|
|
62
|
+
unminimize(): boolean;
|
|
63
|
+
maximize(): boolean;
|
|
64
|
+
unmaximize(): boolean;
|
|
65
|
+
toggleMaximize(): boolean;
|
|
66
|
+
startDrag(): void;
|
|
67
|
+
stopDrag(): void;
|
|
68
|
+
startResize(): void;
|
|
69
|
+
stopResize(): void;
|
|
70
|
+
setLayout(layout: WindowLayout, workarea?: DesktopWorkareaRect): boolean;
|
|
71
|
+
clearLayout(): boolean;
|
|
72
|
+
saveBoundsBeforeLayout(): void;
|
|
73
|
+
setWorkspace(workspaceId: string): void;
|
|
74
|
+
get workspace(): string;
|
|
75
|
+
setSpatialTransform(transform: SpatialTransform): void;
|
|
76
|
+
get spatial(): SpatialTransform | undefined;
|
|
77
|
+
dispose(): void;
|
|
78
|
+
}
|
|
79
|
+
declare class WindowManager {
|
|
80
|
+
private windows;
|
|
81
|
+
private snapshotCache;
|
|
82
|
+
private zIndexCounter;
|
|
83
|
+
private subscribers;
|
|
84
|
+
private hooks;
|
|
85
|
+
private ipc;
|
|
86
|
+
constructor(options?: {
|
|
87
|
+
hooks?: Hookable<DesktopRuntimeHooks>;
|
|
88
|
+
ipc?: CoreIPCBus;
|
|
89
|
+
});
|
|
90
|
+
getSnapshot(): WindowInstance[];
|
|
91
|
+
subscribe(callback: (windows: WindowInstance[]) => void): () => void;
|
|
92
|
+
private notify;
|
|
93
|
+
get(id: string): WindowInstance | undefined;
|
|
94
|
+
get focusedWindow(): WindowInstance | undefined;
|
|
95
|
+
incrementZIndex(): number;
|
|
96
|
+
addWindow(instance: WindowInstance): void;
|
|
97
|
+
createWindow(options: {
|
|
98
|
+
id: string;
|
|
99
|
+
model: string;
|
|
100
|
+
applicationId?: string;
|
|
101
|
+
config: WindowConfig;
|
|
102
|
+
initialState?: Partial<WindowState>;
|
|
103
|
+
meta?: Record<string, any>;
|
|
104
|
+
workspace?: string;
|
|
105
|
+
}): WindowInstance;
|
|
106
|
+
focusWindow(id: string): void;
|
|
107
|
+
closeWindow(id: string): boolean;
|
|
108
|
+
closeAllWindows(): void;
|
|
109
|
+
tileWindows(mode: "horizontal" | "vertical" | "grid" | undefined, workarea: DesktopWorkareaRect, workspaceId?: string, gap?: number): number;
|
|
110
|
+
setSpatialTransform(windowId: string, transform: SpatialTransform): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { CoreIPCBus as C, WindowManager as W, WindowInstance as a, globalIPCBus as g };
|
|
114
|
+
export type { EventHandler as E };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function workareaBottom(workarea) {
|
|
2
|
+
return workarea.y + workarea.height;
|
|
3
|
+
}
|
|
4
|
+
function workareaRight(workarea) {
|
|
5
|
+
return workarea.x + workarea.width;
|
|
6
|
+
}
|
|
7
|
+
function computeSnapRect(zone, workarea) {
|
|
8
|
+
const { x, y, width, height } = workarea;
|
|
9
|
+
const halfW = Math.floor(width / 2);
|
|
10
|
+
const halfH = Math.floor(height / 2);
|
|
11
|
+
switch (zone) {
|
|
12
|
+
case "maximize":
|
|
13
|
+
return { x, y, width, height };
|
|
14
|
+
case "left-half":
|
|
15
|
+
return { x, y, width: halfW, height };
|
|
16
|
+
case "right-half":
|
|
17
|
+
return { x: x + halfW, y, width: width - halfW, height };
|
|
18
|
+
case "bottom-half":
|
|
19
|
+
return { x, y: y + halfH, width, height: height - halfH };
|
|
20
|
+
case "top-left":
|
|
21
|
+
return { x, y, width: halfW, height: halfH };
|
|
22
|
+
case "top-right":
|
|
23
|
+
return { x: x + halfW, y, width: width - halfW, height: halfH };
|
|
24
|
+
case "bottom-left":
|
|
25
|
+
return { x, y: y + halfH, width: halfW, height: height - halfH };
|
|
26
|
+
case "bottom-right":
|
|
27
|
+
return {
|
|
28
|
+
x: x + halfW,
|
|
29
|
+
y: y + halfH,
|
|
30
|
+
width: width - halfW,
|
|
31
|
+
height: height - halfH
|
|
32
|
+
};
|
|
33
|
+
default: {
|
|
34
|
+
const _exhaustive = zone;
|
|
35
|
+
return _exhaustive;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { workareaRight as a, computeSnapRect as c, workareaBottom as w };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Hookable } from 'hookable';
|
|
2
|
+
import { DesktopKernelEvent, DesktopRuntimeHooks, WindowConfig, WindowState, WindowLayout, DesktopWorkareaRect, SpatialTransform } from '../types/index.mjs';
|
|
3
|
+
|
|
4
|
+
type EventHandler = (event: DesktopKernelEvent) => void;
|
|
5
|
+
declare class CoreIPCBus {
|
|
6
|
+
private readonly maxEvents;
|
|
7
|
+
private events;
|
|
8
|
+
private readonly listeners;
|
|
9
|
+
private eventCounter;
|
|
10
|
+
private subscribers;
|
|
11
|
+
constructor(options?: {
|
|
12
|
+
maxEvents?: number;
|
|
13
|
+
});
|
|
14
|
+
emit(channel: string, payload?: any, options?: {
|
|
15
|
+
source?: string;
|
|
16
|
+
severity?: 'info' | 'warn' | 'error';
|
|
17
|
+
}): DesktopKernelEvent;
|
|
18
|
+
on(channel: string, handler: EventHandler): () => void;
|
|
19
|
+
off(channel: string, handler: EventHandler): void;
|
|
20
|
+
getEvents(): DesktopKernelEvent[];
|
|
21
|
+
getActiveChannels(): string[];
|
|
22
|
+
clear(): void;
|
|
23
|
+
subscribe(callback: (events: DesktopKernelEvent[]) => void): () => void;
|
|
24
|
+
}
|
|
25
|
+
declare const globalIPCBus: CoreIPCBus;
|
|
26
|
+
|
|
27
|
+
declare class WindowInstance {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly model: string;
|
|
30
|
+
readonly applicationId?: string;
|
|
31
|
+
config: WindowConfig;
|
|
32
|
+
state: WindowState;
|
|
33
|
+
meta: Record<string, any>;
|
|
34
|
+
private actor;
|
|
35
|
+
private isDisposed;
|
|
36
|
+
private subscribers;
|
|
37
|
+
constructor(options: {
|
|
38
|
+
id: string;
|
|
39
|
+
model: string;
|
|
40
|
+
applicationId?: string;
|
|
41
|
+
config: WindowConfig;
|
|
42
|
+
initialState?: Partial<WindowState>;
|
|
43
|
+
meta?: Record<string, any>;
|
|
44
|
+
workspace?: string;
|
|
45
|
+
});
|
|
46
|
+
private updateState;
|
|
47
|
+
getSnapshot(): WindowState;
|
|
48
|
+
subscribe(callback: (snapshot: WindowState) => void): () => void;
|
|
49
|
+
private notify;
|
|
50
|
+
get stateValue(): string;
|
|
51
|
+
setPosition(data: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z?: number;
|
|
55
|
+
}): void;
|
|
56
|
+
setSize(data: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
}): void;
|
|
60
|
+
setFocus(value: boolean): void;
|
|
61
|
+
minimize(): boolean;
|
|
62
|
+
unminimize(): boolean;
|
|
63
|
+
maximize(): boolean;
|
|
64
|
+
unmaximize(): boolean;
|
|
65
|
+
toggleMaximize(): boolean;
|
|
66
|
+
startDrag(): void;
|
|
67
|
+
stopDrag(): void;
|
|
68
|
+
startResize(): void;
|
|
69
|
+
stopResize(): void;
|
|
70
|
+
setLayout(layout: WindowLayout, workarea?: DesktopWorkareaRect): boolean;
|
|
71
|
+
clearLayout(): boolean;
|
|
72
|
+
saveBoundsBeforeLayout(): void;
|
|
73
|
+
setWorkspace(workspaceId: string): void;
|
|
74
|
+
get workspace(): string;
|
|
75
|
+
setSpatialTransform(transform: SpatialTransform): void;
|
|
76
|
+
get spatial(): SpatialTransform | undefined;
|
|
77
|
+
dispose(): void;
|
|
78
|
+
}
|
|
79
|
+
declare class WindowManager {
|
|
80
|
+
private windows;
|
|
81
|
+
private snapshotCache;
|
|
82
|
+
private zIndexCounter;
|
|
83
|
+
private subscribers;
|
|
84
|
+
private hooks;
|
|
85
|
+
private ipc;
|
|
86
|
+
constructor(options?: {
|
|
87
|
+
hooks?: Hookable<DesktopRuntimeHooks>;
|
|
88
|
+
ipc?: CoreIPCBus;
|
|
89
|
+
});
|
|
90
|
+
getSnapshot(): WindowInstance[];
|
|
91
|
+
subscribe(callback: (windows: WindowInstance[]) => void): () => void;
|
|
92
|
+
private notify;
|
|
93
|
+
get(id: string): WindowInstance | undefined;
|
|
94
|
+
get focusedWindow(): WindowInstance | undefined;
|
|
95
|
+
incrementZIndex(): number;
|
|
96
|
+
addWindow(instance: WindowInstance): void;
|
|
97
|
+
createWindow(options: {
|
|
98
|
+
id: string;
|
|
99
|
+
model: string;
|
|
100
|
+
applicationId?: string;
|
|
101
|
+
config: WindowConfig;
|
|
102
|
+
initialState?: Partial<WindowState>;
|
|
103
|
+
meta?: Record<string, any>;
|
|
104
|
+
workspace?: string;
|
|
105
|
+
}): WindowInstance;
|
|
106
|
+
focusWindow(id: string): void;
|
|
107
|
+
closeWindow(id: string): boolean;
|
|
108
|
+
closeAllWindows(): void;
|
|
109
|
+
tileWindows(mode: "horizontal" | "vertical" | "grid" | undefined, workarea: DesktopWorkareaRect, workspaceId?: string, gap?: number): number;
|
|
110
|
+
setSpatialTransform(windowId: string, transform: SpatialTransform): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { CoreIPCBus as C, WindowManager as W, WindowInstance as a, globalIPCBus as g };
|
|
114
|
+
export type { EventHandler as E };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createHooks } from 'hookable';
|
|
2
|
+
|
|
3
|
+
class CoreIPCBus {
|
|
4
|
+
maxEvents;
|
|
5
|
+
events = [];
|
|
6
|
+
listeners = /* @__PURE__ */ new Map();
|
|
7
|
+
eventCounter = 0;
|
|
8
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.maxEvents = options?.maxEvents ?? 150;
|
|
11
|
+
}
|
|
12
|
+
emit(channel, payload, options) {
|
|
13
|
+
this.eventCounter++;
|
|
14
|
+
const event = {
|
|
15
|
+
id: `evt-${Date.now()}-${this.eventCounter}`,
|
|
16
|
+
timestamp: Date.now(),
|
|
17
|
+
channel,
|
|
18
|
+
source: options?.source ?? "kernel",
|
|
19
|
+
severity: options?.severity ?? "info",
|
|
20
|
+
payload
|
|
21
|
+
};
|
|
22
|
+
this.events = [event, ...this.events.slice(0, this.maxEvents - 1)];
|
|
23
|
+
const channelSet = this.listeners.get(channel);
|
|
24
|
+
if (channelSet) {
|
|
25
|
+
for (const handler of channelSet) {
|
|
26
|
+
try {
|
|
27
|
+
handler(event);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error(`[@owdproject/core][IPC] Error in listener for "${channel}":`, err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (channel !== "*") {
|
|
34
|
+
const wildcardSet = this.listeners.get("*");
|
|
35
|
+
if (wildcardSet) {
|
|
36
|
+
for (const handler of wildcardSet) {
|
|
37
|
+
try {
|
|
38
|
+
handler(event);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error(`[@owdproject/core][IPC] Error in wildcard listener:`, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const sub of this.subscribers) {
|
|
46
|
+
try {
|
|
47
|
+
sub(this.events);
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return event;
|
|
52
|
+
}
|
|
53
|
+
on(channel, handler) {
|
|
54
|
+
if (!this.listeners.has(channel)) {
|
|
55
|
+
this.listeners.set(channel, /* @__PURE__ */ new Set());
|
|
56
|
+
}
|
|
57
|
+
this.listeners.get(channel).add(handler);
|
|
58
|
+
return () => {
|
|
59
|
+
this.off(channel, handler);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
off(channel, handler) {
|
|
63
|
+
const channelSet = this.listeners.get(channel);
|
|
64
|
+
if (channelSet) {
|
|
65
|
+
channelSet.delete(handler);
|
|
66
|
+
if (channelSet.size === 0) {
|
|
67
|
+
this.listeners.delete(channel);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getEvents() {
|
|
72
|
+
return this.events;
|
|
73
|
+
}
|
|
74
|
+
getActiveChannels() {
|
|
75
|
+
return Array.from(this.listeners.keys());
|
|
76
|
+
}
|
|
77
|
+
clear() {
|
|
78
|
+
this.events = [];
|
|
79
|
+
for (const sub of this.subscribers) {
|
|
80
|
+
try {
|
|
81
|
+
sub(this.events);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
subscribe(callback) {
|
|
87
|
+
this.subscribers.add(callback);
|
|
88
|
+
callback(this.events);
|
|
89
|
+
return () => {
|
|
90
|
+
this.subscribers.delete(callback);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const globalIPCBus = new CoreIPCBus();
|
|
95
|
+
|
|
96
|
+
function createDesktopHooks() {
|
|
97
|
+
return createHooks();
|
|
98
|
+
}
|
|
99
|
+
const globalDesktopHooks = createDesktopHooks();
|
|
100
|
+
|
|
101
|
+
export { CoreIPCBus as C, globalIPCBus as a, createDesktopHooks as c, globalDesktopHooks as g };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { w as workareaBottom, a as workareaRight } from './core.CsDFgGnX.mjs';
|
|
2
|
+
|
|
3
|
+
const WINDOW_SNAP_EDGE_PX = 24;
|
|
4
|
+
const WORKSPACE_EDGE_DROP_PX = 32;
|
|
5
|
+
function detectSnapZone(clientX, clientY, workarea, options) {
|
|
6
|
+
const edge = options?.edgePx ?? WINDOW_SNAP_EDGE_PX;
|
|
7
|
+
const { x, y, width, height } = workarea;
|
|
8
|
+
if (width <= 0 || height <= 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const bottom = workareaBottom(workarea);
|
|
12
|
+
const right = workareaRight(workarea);
|
|
13
|
+
const nearTop = clientY <= y + edge;
|
|
14
|
+
const nearBottom = clientY >= bottom - edge;
|
|
15
|
+
const nearLeft = clientX <= x + edge;
|
|
16
|
+
const nearRight = clientX >= right - edge;
|
|
17
|
+
const inWorkspaceEdgeBand = options?.deferSideSnapForWorkspaceEdge === true && typeof globalThis !== "undefined" && "innerWidth" in globalThis && (clientX <= WORKSPACE_EDGE_DROP_PX || clientX >= globalThis.innerWidth - WORKSPACE_EDGE_DROP_PX);
|
|
18
|
+
if (nearTop && nearLeft) return "top-left";
|
|
19
|
+
if (nearTop && nearRight) return "top-right";
|
|
20
|
+
if (nearBottom && nearLeft) return "bottom-left";
|
|
21
|
+
if (nearBottom && nearRight) return "bottom-right";
|
|
22
|
+
if (nearTop) return "maximize";
|
|
23
|
+
if (nearBottom) return "bottom-half";
|
|
24
|
+
if (nearLeft && !inWorkspaceEdgeBand) return "left-half";
|
|
25
|
+
if (nearRight && !inWorkspaceEdgeBand) return "right-half";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { WINDOW_SNAP_EDGE_PX as W, WORKSPACE_EDGE_DROP_PX as a, detectSnapZone as d };
|