plusui-native-core 0.1.65 → 0.1.68

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.
@@ -1,156 +1,207 @@
1
- import { connect } from '../Connection/connect';
2
-
3
- export interface WindowSize {
4
- width: number;
5
- height: number;
6
- }
7
-
8
- export interface WindowPosition {
9
- x: number;
10
- y: number;
11
- }
12
-
13
- export interface WindowRect {
14
- x: number;
15
- y: number;
16
- width: number;
17
- height: number;
18
- }
19
-
20
- export interface WindowState {
21
- isMinimized: boolean;
22
- isMaximized: boolean;
23
- isVisible: boolean;
24
- isFullscreen: boolean;
25
- }
26
-
27
- export type WindowId = string;
28
-
29
- let _invoke: ((method: string, args?: unknown[]) => Promise<unknown>) | null = null;
30
-
31
- export function setInvokeFn(fn: (method: string, args?: unknown[]) => Promise<unknown>) {
32
- _invoke = fn;
33
- }
34
-
35
- async function invoke(method: string, args?: unknown[]): Promise<unknown> {
36
- if (!_invoke) {
37
- if (typeof window !== 'undefined' && (window as any).__invoke__) {
38
- _invoke = (window as any).__invoke__;
39
- } else {
40
- throw new Error('Window API not initialized');
41
- }
42
- }
43
- return _invoke(method, args);
44
- }
45
-
46
- const windowFeatureEvents = connect.feature('window');
47
-
48
- export const window = {
49
- connect: windowFeatureEvents,
50
-
51
- on: <TData = unknown>(name: string, callback: (payload: TData) => void): (() => void) => {
52
- return windowFeatureEvents.on<TData>(name, callback);
53
- },
54
-
55
- emit: <TIn = Record<string, unknown>>(name: string, payload: TIn): void => {
56
- windowFeatureEvents.emit<TIn>(name, payload);
57
- },
58
-
59
- async minimize(id?: WindowId): Promise<void> {
60
- await invoke('window.minimize', id ? [id] : []);
61
- },
62
-
63
- async maximize(id?: WindowId): Promise<void> {
64
- await invoke('window.maximize', id ? [id] : []);
65
- },
66
-
67
- async restore(id?: WindowId): Promise<void> {
68
- await invoke('window.restore', id ? [id] : []);
69
- },
70
-
71
- async close(id?: WindowId): Promise<void> {
72
- await invoke('window.close', id ? [id] : []);
73
- },
74
-
75
- async show(id?: WindowId): Promise<void> {
76
- await invoke('window.show', id ? [id] : []);
77
- },
78
-
79
- async hide(id?: WindowId): Promise<void> {
80
- await invoke('window.hide', id ? [id] : []);
81
- },
82
-
83
- async center(id?: WindowId): Promise<void> {
84
- await invoke('window.center', id ? [id] : []);
85
- },
86
-
87
- async setSize(width: number, height: number, id?: WindowId): Promise<void> {
88
- const args = id ? [width, height, id] : [width, height];
89
- await invoke('window.setSize', args);
90
- },
91
-
92
- async setPosition(x: number, y: number, id?: WindowId): Promise<void> {
93
- const args = id ? [x, y, id] : [x, y];
94
- await invoke('window.setPosition', args);
95
- },
96
-
97
- async setTitle(title: string, id?: WindowId): Promise<void> {
98
- const args = id ? [title, id] : [title];
99
- await invoke('window.setTitle', args);
100
- },
101
-
102
- async setFullscreen(enabled: boolean, id?: WindowId): Promise<void> {
103
- const args = id ? [enabled, id] : [enabled];
104
- await invoke('window.setFullscreen', args);
105
- },
106
-
107
- async setAlwaysOnTop(enabled: boolean, id?: WindowId): Promise<void> {
108
- const args = id ? [enabled, id] : [enabled];
109
- await invoke('window.setAlwaysOnTop', args);
110
- },
111
-
112
- async setResizable(enabled: boolean, id?: WindowId): Promise<void> {
113
- const args = id ? [enabled, id] : [enabled];
114
- await invoke('window.setResizable', args);
115
- },
116
-
117
- async setDecorations(enabled: boolean, id?: WindowId): Promise<void> {
118
- const args = id ? [enabled, id] : [enabled];
119
- await invoke('window.setDecorations', args);
120
- },
121
-
122
- async setTransparency(alpha: number, id?: WindowId): Promise<void> {
123
- const args = id ? [alpha, id] : [alpha];
124
- await invoke('window.setTransparency', args);
125
- },
126
-
127
- async getSize(id?: WindowId): Promise<WindowSize> {
128
- return await invoke('window.getSize', id ? [id] : []) as Promise<WindowSize>;
129
- },
130
-
131
- async getPosition(id?: WindowId): Promise<WindowPosition> {
132
- return await invoke('window.getPosition', id ? [id] : []) as Promise<WindowPosition>;
133
- },
134
-
135
- async getRect(id?: WindowId): Promise<WindowRect> {
136
- return await invoke('window.getRect', id ? [id] : []) as Promise<WindowRect>;
137
- },
138
-
139
- async getState(id?: WindowId): Promise<WindowState> {
140
- return await invoke('window.getState', id ? [id] : []) as Promise<WindowState>;
141
- },
142
-
143
- async isMaximized(id?: WindowId): Promise<boolean> {
144
- return await invoke('window.isMaximized', id ? [id] : []) as Promise<boolean>;
145
- },
146
-
147
- async isMinimized(id?: WindowId): Promise<boolean> {
148
- return await invoke('window.isMinimized', id ? [id] : []) as Promise<boolean>;
149
- },
150
-
151
- async isVisible(id?: WindowId): Promise<boolean> {
152
- return await invoke('window.isVisible', id ? [id] : []) as Promise<boolean>;
153
- }
154
- };
155
-
156
- export default window;
1
+ import { connect } from '../Connection/connect';
2
+
3
+ export interface WindowSize {
4
+ width: number;
5
+ height: number;
6
+ }
7
+
8
+ export interface WindowPosition {
9
+ x: number;
10
+ y: number;
11
+ }
12
+
13
+ export interface WindowRect {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ }
19
+
20
+ export interface WindowState {
21
+ isMinimized: boolean;
22
+ isMaximized: boolean;
23
+ isVisible: boolean;
24
+ isFullscreen: boolean;
25
+ }
26
+
27
+ export type WindowId = string;
28
+
29
+ let _invoke: ((method: string, args?: unknown[]) => Promise<unknown>) | null = null;
30
+ let _event: ((event: string, callback: (...args: unknown[]) => void) => () => void) | null = null;
31
+
32
+ export function setInvokeFn(fn: (method: string, args?: unknown[]) => Promise<unknown>) {
33
+ _invoke = fn;
34
+ }
35
+
36
+ export function setEventFn(fn: (event: string, callback: (...args: unknown[]) => void) => () => void) {
37
+ _event = fn;
38
+ }
39
+
40
+ async function invoke<T = unknown>(method: string, args?: unknown[]): Promise<T> {
41
+ if (!_invoke) {
42
+ if (typeof window !== 'undefined' && (window as any).__invoke__) {
43
+ _invoke = (window as any).__invoke__;
44
+ } else {
45
+ throw new Error('Window API not initialized');
46
+ }
47
+ }
48
+ return _invoke!(method, args) as Promise<T>;
49
+ }
50
+
51
+ function eventHandler(event: string, callback: (...args: unknown[]) => void): () => void {
52
+ if (!_event) {
53
+ if (typeof window !== 'undefined' && (window as any).__on__) {
54
+ _event = (window as any).__on__;
55
+ } else {
56
+ return () => {};
57
+ }
58
+ }
59
+ return _event!(event, callback);
60
+ }
61
+
62
+ export const window = {
63
+ // Direct methods
64
+ async minimize(id?: WindowId): Promise<void> {
65
+ await invoke('window.minimize', id ? [id] : []);
66
+ },
67
+
68
+ async maximize(id?: WindowId): Promise<void> {
69
+ await invoke('window.maximize', id ? [id] : []);
70
+ },
71
+
72
+ async restore(id?: WindowId): Promise<void> {
73
+ await invoke('window.restore', id ? [id] : []);
74
+ },
75
+
76
+ async close(id?: WindowId): Promise<void> {
77
+ await invoke('window.close', id ? [id] : []);
78
+ },
79
+
80
+ async show(id?: WindowId): Promise<void> {
81
+ await invoke('window.show', id ? [id] : []);
82
+ },
83
+
84
+ async hide(id?: WindowId): Promise<void> {
85
+ await invoke('window.hide', id ? [id] : []);
86
+ },
87
+
88
+ async center(id?: WindowId): Promise<void> {
89
+ await invoke('window.center', id ? [id] : []);
90
+ },
91
+
92
+ async setTitle(title: string, id?: WindowId): Promise<void> {
93
+ const args = id ? [title, id] : [title];
94
+ await invoke('window.setTitle', args);
95
+ },
96
+
97
+ async setSize(width: number, height: number, id?: WindowId): Promise<void> {
98
+ const args = id ? [width, height, id] : [width, height];
99
+ await invoke('window.setSize', args);
100
+ },
101
+
102
+ async setPosition(x: number, y: number, id?: WindowId): Promise<void> {
103
+ const args = id ? [x, y, id] : [x, y];
104
+ await invoke('window.setPosition', args);
105
+ },
106
+
107
+ async setFullscreen(enabled: boolean, id?: WindowId): Promise<void> {
108
+ const args = id ? [enabled, id] : [enabled];
109
+ await invoke('window.setFullscreen', args);
110
+ },
111
+
112
+ async setAlwaysOnTop(enabled: boolean, id?: WindowId): Promise<void> {
113
+ const args = id ? [enabled, id] : [enabled];
114
+ await invoke('window.setAlwaysOnTop', args);
115
+ },
116
+
117
+ async setResizable(enabled: boolean, id?: WindowId): Promise<void> {
118
+ const args = id ? [enabled, id] : [enabled];
119
+ await invoke('window.setResizable', args);
120
+ },
121
+
122
+ async setDecorations(enabled: boolean, id?: WindowId): Promise<void> {
123
+ const args = id ? [enabled, id] : [enabled];
124
+ await invoke('window.setDecorations', args);
125
+ },
126
+
127
+ async setTransparency(alpha: number, id?: WindowId): Promise<void> {
128
+ const args = id ? [alpha, id] : [alpha];
129
+ await invoke('window.setTransparency', args);
130
+ },
131
+
132
+ async getSize(id?: WindowId): Promise<WindowSize> {
133
+ return invoke<WindowSize>('window.getSize', id ? [id] : []);
134
+ },
135
+
136
+ async getPosition(id?: WindowId): Promise<WindowPosition> {
137
+ return invoke<WindowPosition>('window.getPosition', id ? [id] : []);
138
+ },
139
+
140
+ async getRect(id?: WindowId): Promise<WindowRect> {
141
+ return invoke<WindowRect>('window.getRect', id ? [id] : []);
142
+ },
143
+
144
+ async getState(id?: WindowId): Promise<WindowState> {
145
+ return invoke<WindowState>('window.getState', id ? [id] : []);
146
+ },
147
+
148
+ async isMaximized(id?: WindowId): Promise<boolean> {
149
+ return invoke<boolean>('window.isMaximized', id ? [id] : []);
150
+ },
151
+
152
+ async isMinimized(id?: WindowId): Promise<boolean> {
153
+ return invoke<boolean>('window.isMinimized', id ? [id] : []);
154
+ },
155
+
156
+ async isVisible(id?: WindowId): Promise<boolean> {
157
+ return invoke<boolean>('window.isVisible', id ? [id] : []);
158
+ },
159
+
160
+ async focus(id?: WindowId): Promise<void> {
161
+ await invoke('window.focus', id ? [id] : []);
162
+ },
163
+
164
+ async setIcon(iconPath: string, id?: WindowId): Promise<void> {
165
+ const args = id ? [iconPath, id] : [iconPath];
166
+ await invoke('window.setIcon', args);
167
+ },
168
+
169
+ // Direct event registration
170
+ onResize(callback: (size: WindowSize) => void): () => void {
171
+ return eventHandler('window:resize', callback as (...args: unknown[]) => void);
172
+ },
173
+
174
+ onMove(callback: (pos: WindowPosition) => void): () => void {
175
+ return eventHandler('window:move', callback as (...args: unknown[]) => void);
176
+ },
177
+
178
+ onClose(callback: () => void): () => void {
179
+ return eventHandler('window:close', callback as (...args: unknown[]) => void);
180
+ },
181
+
182
+ onFocus(callback: (focused: boolean) => void): () => void {
183
+ return eventHandler('window:focus', callback as (...args: unknown[]) => void);
184
+ },
185
+
186
+ onStateChange(callback: (state: WindowState) => void): () => void {
187
+ return eventHandler('window:stateChange', callback as (...args: unknown[]) => void);
188
+ },
189
+
190
+ onMinimize(callback: () => void): () => void {
191
+ return eventHandler('window:minimize', callback as (...args: unknown[]) => void);
192
+ },
193
+
194
+ onMaximize(callback: () => void): () => void {
195
+ return eventHandler('window:maximize', callback as (...args: unknown[]) => void);
196
+ },
197
+
198
+ onRestore(callback: () => void): () => void {
199
+ return eventHandler('window:restore', callback as (...args: unknown[]) => void);
200
+ },
201
+
202
+ onFileDrop(callback: (files: { path: string; name: string; type: string; size: number }[]) => void): () => void {
203
+ return eventHandler('window:fileDrop', callback as (...args: unknown[]) => void);
204
+ },
205
+ };
206
+
207
+ export default window;
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.65",
3
+ "version": "0.1.68",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
+ "exports": {
7
+ ".": "./Core/API/index.ts"
8
+ },
9
+ "types": "./Core/API/index.ts",
6
10
  "files": [
7
11
  "Core",
8
12
  "README.md"