nexfep 0.0.1 → 0.0.3
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-CN.md +240 -0
- package/README.md +100 -98
- package/package.json +2 -1
package/README-CN.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Nexfep
|
|
2
|
+
|
|
3
|
+
语言: [English](https://github.com/zhuxiaojt/Nexfep/blob/master/README.md) | 简体中文(当前)
|
|
4
|
+
|
|
5
|
+
基于 @webviewjs/webview 的桌面应用框架
|
|
6
|
+
|
|
7
|
+
## 项目状态
|
|
8
|
+
|
|
9
|
+
**🚧 早期阶段**
|
|
10
|
+
|
|
11
|
+
本项目目前处于早期开发阶段,仍缺失大量桌面应用开发所需的核心能力。框架正在持续迭代中。
|
|
12
|
+
|
|
13
|
+
## 简介
|
|
14
|
+
|
|
15
|
+
Nexfep 是一个基于 [@webviewjs/webview](https://github.com/webview/webview) 构建的桌面应用框架,使用 TypeScript 编写。它旨在为开发者提供一套简洁、高效的工具链,用于构建跨平台桌面应用。
|
|
16
|
+
|
|
17
|
+
框架采用窗口池管理机制,支持多窗口应用场景,如代码编辑器、聊天工具、仪表盘等。
|
|
18
|
+
|
|
19
|
+
## 特性
|
|
20
|
+
|
|
21
|
+
- **窗口池管理** — 内置窗口池机制,自动复用和回收窗口资源,避免频繁创建销毁的开销
|
|
22
|
+
- **IPC 通信** — 支持主进程与 WebView 之间的双向消息通信,通过注入的函数进行调用
|
|
23
|
+
- **窗口控制** — 提供最大化、最小化、关闭、标题设置、开发者工具等完整窗口操作 API
|
|
24
|
+
- **拖拽区域** — 内置 HTML 属性支持,方便定义窗口拖拽区域(`nexfep-area-drag` 等)
|
|
25
|
+
- **TypeScript 支持** — 完整的类型定义,开发体验优秀
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add nexfep
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 快速开始
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { WindowPool } from 'nexfep';
|
|
37
|
+
|
|
38
|
+
const pool = new WindowPool();
|
|
39
|
+
|
|
40
|
+
const window = await pool.createWindow(true, false);
|
|
41
|
+
|
|
42
|
+
await window.loadHTML('<h1 nexfep-area-drag>Hello Nexfep!</h1>');
|
|
43
|
+
|
|
44
|
+
pool.mainloop();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 使用指南
|
|
48
|
+
|
|
49
|
+
### 窗口池
|
|
50
|
+
|
|
51
|
+
`WindowPool` 是框架的核心管理类,负责窗口的创建和回收。
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const pool = new WindowPool();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**构造函数参数**
|
|
58
|
+
|
|
59
|
+
- `WindowsWebview2UserDataFolder`(可选)— WebView2 用户数据目录,默认为 `%LOCALAPPDATA%\NexfepDevelopment.webview2-data`
|
|
60
|
+
|
|
61
|
+
### 窗口创建
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const win = await pool.createWindow(true, false);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**参数说明**
|
|
68
|
+
|
|
69
|
+
- `isShow`(布尔值,默认 `true`)— 是否立即显示窗口
|
|
70
|
+
- `isDecorated`(布尔值,默认 `true`)— 是否使用系统窗口装饰。设为 `false` 时,窗口无边框,需要自定义标题栏
|
|
71
|
+
|
|
72
|
+
### 窗口操作
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
window.show();
|
|
76
|
+
window.hide();
|
|
77
|
+
window.maximize();
|
|
78
|
+
window.minimize();
|
|
79
|
+
window.close();
|
|
80
|
+
window.setTitle('新标题');
|
|
81
|
+
window.openDevTools();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### IPC 通信
|
|
85
|
+
|
|
86
|
+
框架在 WebView 页面加载完成后会自动注入一系列控制函数,建议使用这些注入的函数进行 IPC 通信,而非直接使用 `@webviewjs/webview` 原生包装的 IPC。
|
|
87
|
+
|
|
88
|
+
#### 发送自定义消息
|
|
89
|
+
|
|
90
|
+
在页面中通过 `window.postMessage` 发送消息:
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
window.postMessage({ hello: 'world' });
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**参数说明**
|
|
97
|
+
|
|
98
|
+
- `data` — 任意类型的可序列化数据,会被序列化为 JSON 字符串后发送
|
|
99
|
+
|
|
100
|
+
#### 监听消息
|
|
101
|
+
|
|
102
|
+
在主进程中通过 `onCustomMessage` 回调接收消息:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
pool.onCustomMessage = (window, data) => {
|
|
106
|
+
console.log(`来自窗口 ${window.id} 的消息:`, data);
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**回调参数**
|
|
111
|
+
|
|
112
|
+
- `window` — 发送消息的窗口对象
|
|
113
|
+
- `data` — 消息内容,为对象类型(JSON 序列化后会自动通过 `JSON.parse` 转换为对象)
|
|
114
|
+
|
|
115
|
+
#### 窗口控制函数
|
|
116
|
+
|
|
117
|
+
页面中可直接调用以下注入函数进行窗口控制:
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
window.close(); // 关闭窗口
|
|
121
|
+
window.minimize(); // 最小化窗口
|
|
122
|
+
window.unminimize(); // 还原最小化的窗口
|
|
123
|
+
window.maximize(); // 最大化窗口
|
|
124
|
+
window.unmaximize(); // 还原最大化的窗口
|
|
125
|
+
window.setTitle('标题'); // 设置窗口标题
|
|
126
|
+
window.openDevTools(); // 打开开发者工具
|
|
127
|
+
window.closeDevTools(); // 关闭开发者工具
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 拖拽区域
|
|
131
|
+
|
|
132
|
+
通过 HTML 属性即可定义窗口拖拽区域,无需编写额外 JavaScript 代码。这些属性会自动应用 `-webkit-app-region` 和 `app-region` CSS 属性。
|
|
133
|
+
|
|
134
|
+
#### `nexfep-area-drag`
|
|
135
|
+
|
|
136
|
+
使整个区域及其所有子元素均可拖拽。适用于自定义标题栏等需要整块区域可拖拽的场景。
|
|
137
|
+
|
|
138
|
+
```html
|
|
139
|
+
<div nexfep-area-drag>
|
|
140
|
+
<h1>标题栏</h1>
|
|
141
|
+
<span>副标题</span>
|
|
142
|
+
</div>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### `nexfep-element-drag`
|
|
146
|
+
|
|
147
|
+
仅使指定元素本身可拖拽,子元素不受影响。适用于需要精确控制拖拽区域的场景。
|
|
148
|
+
|
|
149
|
+
```html
|
|
150
|
+
<div>
|
|
151
|
+
<div nexfep-element-drag>拖拽手柄</div>
|
|
152
|
+
<p>这部分不可拖拽</p>
|
|
153
|
+
</div>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `nexfep-no-drag`
|
|
157
|
+
|
|
158
|
+
使指定区域及其所有子元素不可拖拽,优先级最高,可覆盖父元素的拖拽属性。适用于按钮、输入框等交互元素。
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<div nexfep-area-drag>
|
|
162
|
+
<h1>标题栏</h1>
|
|
163
|
+
<button nexfep-no-drag>点击按钮</button>
|
|
164
|
+
</div>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### `nexfep-auto-drag`
|
|
168
|
+
|
|
169
|
+
自动判断拖拽区域:整个区域可拖拽,但常见交互元素(`button`、`input`、`select`、`textarea`、`a`)自动设为不可拖拽。适用于包含多种交互元素的复杂区域。
|
|
170
|
+
|
|
171
|
+
```html
|
|
172
|
+
<div nexfep-auto-drag>
|
|
173
|
+
<h1>标题栏</h1>
|
|
174
|
+
<button>自动不可拖拽</button>
|
|
175
|
+
<input placeholder="自动不可拖拽" />
|
|
176
|
+
<a href="#">自动不可拖拽</a>
|
|
177
|
+
</div>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 加载完成事件
|
|
181
|
+
|
|
182
|
+
WebView 窗口加载完成后会触发 `nexfep-load-done` 事件:
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
window.addEventListener('nexfep-load-done', () => {
|
|
186
|
+
console.log('Nexfep 窗口加载完成');
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
也可通过 `window.isNexfepLoadDone` 属性判断:
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
if (window.isNexfepLoadDone) {
|
|
194
|
+
// 窗口已就绪
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## API
|
|
199
|
+
|
|
200
|
+
### WindowPool
|
|
201
|
+
|
|
202
|
+
| 方法/属性 | 参数 | 返回值 | 说明 |
|
|
203
|
+
| ------------------------------------- | ----------------------------------------------------------- | ---------------- | -------------------------- |
|
|
204
|
+
| `constructor(userDataFolder?)` | `userDataFolder`: string(可选) | WindowPool | 创建窗口池,可选指定 WebView2 用户数据目录 |
|
|
205
|
+
| `createWindow(isShow?, isDecorated?)` | `isShow`: boolean(默认 true), `isDecorated`: boolean(默认 true) | Promise\<Window> | 创建并获取一个窗口 |
|
|
206
|
+
| `closeWindow(window)` | `window`: Window | Promise\<void> | 关闭指定窗口并回收至池中 |
|
|
207
|
+
| `closePool()` | 无 | Promise\<void> | 关闭窗口池,退出应用 |
|
|
208
|
+
| `mainloop()` | 无 | void | 启动应用主循环,阻塞直到应用退出 |
|
|
209
|
+
| `onCustomMessage` | `(window: Window, data: string) => void` | 无 | 自定义消息回调函数,当收到页面发来的自定义消息时触发 |
|
|
210
|
+
|
|
211
|
+
### Window
|
|
212
|
+
|
|
213
|
+
| 方法/属性 | 参数 | 返回值 | 说明 |
|
|
214
|
+
| --------------------------- | --------------------------------- | -------------- | ------------- |
|
|
215
|
+
| `loadURL(url)` | `url`: string — 要加载的网页地址 | Promise\<void> | 加载指定 URL |
|
|
216
|
+
| `loadHTML(html)` | `html`: string — HTML 字符串 | Promise\<void> | 加载指定 HTML 内容 |
|
|
217
|
+
| `show()` | 无 | void | 显示窗口 |
|
|
218
|
+
| `hide()` | 无 | void | 隐藏窗口 |
|
|
219
|
+
| `maximize()` | 无 | void | 最大化窗口 |
|
|
220
|
+
| `unMaximize()` | 无 | void | 还原窗口(取消最大化) |
|
|
221
|
+
| `minimize()` | 无 | void | 最小化窗口 |
|
|
222
|
+
| `unMinimize()` | 无 | void | 还原窗口(取消最小化) |
|
|
223
|
+
| `close()` | 无 | void | 关闭窗口并回收至池中 |
|
|
224
|
+
| `setTitle(title)` | `title`: string — 窗口标题 | void | 设置窗口标题 |
|
|
225
|
+
| `setDecorated(isDecorated)` | `isDecorated`: boolean — 是否使用系统装饰 | void | 设置窗口是否带边框和标题栏 |
|
|
226
|
+
| `resizable(resizable)` | `resizable`: boolean — 是否可调整大小 | void | 设置窗口是否可调整大小 |
|
|
227
|
+
| `openDevTools()` | 无 | void | 打开开发者工具 |
|
|
228
|
+
| `closeDevTools()` | 无 | void | 关闭开发者工具 |
|
|
229
|
+
| `id` | 无 | number | 窗口唯一标识,自增编号 |
|
|
230
|
+
|
|
231
|
+
## 开发
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
pnpm install
|
|
235
|
+
pnpm run compile
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 许可证
|
|
239
|
+
|
|
240
|
+
MIT License
|
package/README.md
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
# Nexfep
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Language: English(now) | [简体中文](https://github.com/zhuxiaojt/Nexfep/blob/master/README-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A desktop application framework based on @webviewjs/webview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Project Status
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**🚧 Early Stage**
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
This project is currently in early development, with many core capabilities for desktop application development still missing. The framework is being continuously iterated.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Introduction
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Nexfep is a desktop application framework built on [@webviewjs/webview](https://github.com/webview/webview), written in TypeScript. It aims to provide developers with a concise and efficient toolchain for building cross-platform desktop applications.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The framework uses a window pool management mechanism, supporting multi-window application scenarios such as code editors, chat tools, dashboards, etc.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- **IPC 通信** — 支持主进程与 WebView 之间的双向消息通信,通过注入的函数进行调用
|
|
21
|
-
- **窗口控制** — 提供最大化、最小化、关闭、标题设置、开发者工具等完整窗口操作 API
|
|
22
|
-
- **拖拽区域** — 内置 HTML 属性支持,方便定义窗口拖拽区域(`nexfep-area-drag` 等)
|
|
23
|
-
- **TypeScript 支持** — 完整的类型定义,开发体验优秀
|
|
19
|
+
## Features
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
- **Window Pool Management** — Built-in window pool mechanism for automatic reuse and recycling of window resources, avoiding the overhead of frequent creation and destruction
|
|
22
|
+
- **IPC Communication** — Supports bidirectional message communication between the main process and WebView, via injected functions
|
|
23
|
+
- **Window Control** — Provides complete window operation APIs including maximize, minimize, close, title setting, and developer tools
|
|
24
|
+
- **Drag Regions** — Built-in HTML attribute support for defining window drag regions (`nexfep-area-drag`, etc.)
|
|
25
|
+
- **TypeScript Support** — Complete type definitions for excellent development experience
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
26
28
|
|
|
27
29
|
```bash
|
|
28
30
|
pnpm add nexfep
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
##
|
|
33
|
+
## Quick Start
|
|
32
34
|
|
|
33
35
|
```typescript
|
|
34
36
|
import { WindowPool } from 'nexfep';
|
|
@@ -42,32 +44,32 @@ await window.loadHTML('<h1 nexfep-area-drag>Hello Nexfep!</h1>');
|
|
|
42
44
|
pool.mainloop();
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
##
|
|
47
|
+
## Usage Guide
|
|
46
48
|
|
|
47
|
-
###
|
|
49
|
+
### Window Pool
|
|
48
50
|
|
|
49
|
-
`WindowPool`
|
|
51
|
+
`WindowPool` is the core management class of the framework, responsible for window creation and recycling.
|
|
50
52
|
|
|
51
53
|
```typescript
|
|
52
54
|
const pool = new WindowPool();
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
**Constructor Parameters**
|
|
56
58
|
|
|
57
|
-
- `WindowsWebview2UserDataFolder
|
|
59
|
+
- `WindowsWebview2UserDataFolder` (optional) — WebView2 user data directory, defaults to `%LOCALAPPDATA%\NexfepDevelopment.webview2-data`
|
|
58
60
|
|
|
59
|
-
###
|
|
61
|
+
### Window Creation
|
|
60
62
|
|
|
61
63
|
```typescript
|
|
62
64
|
const win = await pool.createWindow(true, false);
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
**Parameters**
|
|
66
68
|
|
|
67
|
-
- `isShow
|
|
68
|
-
- `isDecorated
|
|
69
|
+
- `isShow` (boolean, default `true`) — Whether to immediately show the window
|
|
70
|
+
- `isDecorated` (boolean, default `true`) — Whether to use system window decorations. When set to `false`, the window has no border and requires a custom title bar
|
|
69
71
|
|
|
70
|
-
###
|
|
72
|
+
### Window Operations
|
|
71
73
|
|
|
72
74
|
```typescript
|
|
73
75
|
window.show();
|
|
@@ -75,121 +77,121 @@ window.hide();
|
|
|
75
77
|
window.maximize();
|
|
76
78
|
window.minimize();
|
|
77
79
|
window.close();
|
|
78
|
-
window.setTitle('
|
|
80
|
+
window.setTitle('New Title');
|
|
79
81
|
window.openDevTools();
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
### IPC
|
|
84
|
+
### IPC Communication
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
The framework automatically injects a series of control functions after WebView page loading is complete. It is recommended to use these injected functions for IPC communication, rather than the native IPC wrapped by `@webviewjs/webview`.
|
|
85
87
|
|
|
86
|
-
####
|
|
88
|
+
#### Send Custom Messages
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
Send messages via `window.postMessage` in the page:
|
|
89
91
|
|
|
90
92
|
```javascript
|
|
91
93
|
window.postMessage({ hello: 'world' });
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
**Parameters**
|
|
95
97
|
|
|
96
|
-
- `data` —
|
|
98
|
+
- `data` — Any serializable data, will be serialized to JSON string before sending
|
|
97
99
|
|
|
98
|
-
####
|
|
100
|
+
#### Listen for Messages
|
|
99
101
|
|
|
100
|
-
|
|
102
|
+
Receive messages via `onCustomMessage` callback in the main process:
|
|
101
103
|
|
|
102
104
|
```typescript
|
|
103
105
|
pool.onCustomMessage = (window, data) => {
|
|
104
|
-
console.log(
|
|
106
|
+
console.log(`Message from window ${window.id}:`, data);
|
|
105
107
|
};
|
|
106
108
|
```
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
**Callback Parameters**
|
|
109
111
|
|
|
110
|
-
- `window` —
|
|
111
|
-
- `data` —
|
|
112
|
+
- `window` — The window object that sent the message
|
|
113
|
+
- `data` — Message content, an object type (automatically converted from JSON string via `JSON.parse`)
|
|
112
114
|
|
|
113
|
-
####
|
|
115
|
+
#### Window Control Functions
|
|
114
116
|
|
|
115
|
-
|
|
117
|
+
The following injected functions can be directly called in the page for window control:
|
|
116
118
|
|
|
117
119
|
```javascript
|
|
118
|
-
window.close(); //
|
|
119
|
-
window.minimize(); //
|
|
120
|
-
window.unminimize(); //
|
|
121
|
-
window.maximize(); //
|
|
122
|
-
window.unmaximize(); //
|
|
123
|
-
window.setTitle('
|
|
124
|
-
window.openDevTools(); //
|
|
125
|
-
window.closeDevTools(); //
|
|
120
|
+
window.close(); // Close window
|
|
121
|
+
window.minimize(); // Minimize window
|
|
122
|
+
window.unminimize(); // Restore minimized window
|
|
123
|
+
window.maximize(); // Maximize window
|
|
124
|
+
window.unmaximize(); // Restore maximized window
|
|
125
|
+
window.setTitle('Title'); // Set window title
|
|
126
|
+
window.openDevTools(); // Open developer tools
|
|
127
|
+
window.closeDevTools(); // Close developer tools
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
###
|
|
130
|
+
### Drag Regions
|
|
129
131
|
|
|
130
|
-
|
|
132
|
+
Define window drag regions via HTML attributes without writing additional JavaScript code. These attributes automatically apply `-webkit-app-region` and `app-region` CSS properties.
|
|
131
133
|
|
|
132
134
|
#### `nexfep-area-drag`
|
|
133
135
|
|
|
134
|
-
|
|
136
|
+
Makes the entire region and all its child elements draggable. Suitable for scenarios like custom title bars where the entire region needs to be draggable.
|
|
135
137
|
|
|
136
138
|
```html
|
|
137
139
|
<div nexfep-area-drag>
|
|
138
|
-
<h1
|
|
139
|
-
<span
|
|
140
|
+
<h1>Title Bar</h1>
|
|
141
|
+
<span>Subtitle</span>
|
|
140
142
|
</div>
|
|
141
143
|
```
|
|
142
144
|
|
|
143
145
|
#### `nexfep-element-drag`
|
|
144
146
|
|
|
145
|
-
|
|
147
|
+
Makes only the specified element itself draggable; child elements are not affected. Suitable for scenarios requiring precise control over the drag region.
|
|
146
148
|
|
|
147
149
|
```html
|
|
148
150
|
<div>
|
|
149
|
-
<div nexfep-element-drag
|
|
150
|
-
<p
|
|
151
|
+
<div nexfep-element-drag>Drag Handle</div>
|
|
152
|
+
<p>This part is not draggable</p>
|
|
151
153
|
</div>
|
|
152
154
|
```
|
|
153
155
|
|
|
154
156
|
#### `nexfep-no-drag`
|
|
155
157
|
|
|
156
|
-
|
|
158
|
+
Makes the specified region and all its child elements non-draggable. Highest priority, can override parent element's drag attributes. Suitable for interactive elements like buttons and input fields.
|
|
157
159
|
|
|
158
160
|
```html
|
|
159
161
|
<div nexfep-area-drag>
|
|
160
|
-
<h1
|
|
161
|
-
<button nexfep-no-drag
|
|
162
|
+
<h1>Title Bar</h1>
|
|
163
|
+
<button nexfep-no-drag>Click Button</button>
|
|
162
164
|
</div>
|
|
163
165
|
```
|
|
164
166
|
|
|
165
167
|
#### `nexfep-auto-drag`
|
|
166
168
|
|
|
167
|
-
|
|
169
|
+
Automatically determines drag regions: the entire region is draggable, but common interactive elements (`button`, `input`, `select`, `textarea`, `a`) are automatically set to non-draggable. Suitable for complex regions containing multiple interactive elements.
|
|
168
170
|
|
|
169
171
|
```html
|
|
170
172
|
<div nexfep-auto-drag>
|
|
171
|
-
<h1
|
|
172
|
-
<button
|
|
173
|
-
<input placeholder="
|
|
174
|
-
<a href="#"
|
|
173
|
+
<h1>Title Bar</h1>
|
|
174
|
+
<button>Automatically non-draggable</button>
|
|
175
|
+
<input placeholder="Automatically non-draggable" />
|
|
176
|
+
<a href="#">Automatically non-draggable</a>
|
|
175
177
|
</div>
|
|
176
178
|
```
|
|
177
179
|
|
|
178
|
-
###
|
|
180
|
+
### Load Complete Event
|
|
179
181
|
|
|
180
|
-
|
|
182
|
+
The `nexfep-load-done` event is triggered after the WebView window finishes loading:
|
|
181
183
|
|
|
182
184
|
```javascript
|
|
183
185
|
window.addEventListener('nexfep-load-done', () => {
|
|
184
|
-
console.log('Nexfep
|
|
186
|
+
console.log('Nexfep window loaded');
|
|
185
187
|
});
|
|
186
188
|
```
|
|
187
189
|
|
|
188
|
-
|
|
190
|
+
It can also be checked via the `window.isNexfepLoadDone` property:
|
|
189
191
|
|
|
190
192
|
```javascript
|
|
191
193
|
if (window.isNexfepLoadDone) {
|
|
192
|
-
//
|
|
194
|
+
// Window is ready
|
|
193
195
|
}
|
|
194
196
|
```
|
|
195
197
|
|
|
@@ -197,42 +199,42 @@ if (window.isNexfepLoadDone) {
|
|
|
197
199
|
|
|
198
200
|
### WindowPool
|
|
199
201
|
|
|
200
|
-
|
|
|
201
|
-
| ------------------------------------- |
|
|
202
|
-
| `constructor(userDataFolder?)` | `userDataFolder`: string
|
|
203
|
-
| `createWindow(isShow?, isDecorated?)` | `isShow`: boolean
|
|
204
|
-
| `closeWindow(window)` | `window`: Window
|
|
205
|
-
| `closePool()` |
|
|
206
|
-
| `mainloop()` |
|
|
207
|
-
| `onCustomMessage` | `(window: Window, data: string) => void`
|
|
202
|
+
| Method/Property | Parameters | Return Value | Description |
|
|
203
|
+
| ------------------------------------- | -------------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------ |
|
|
204
|
+
| `constructor(userDataFolder?)` | `userDataFolder`: string (optional) | WindowPool | Creates a window pool, optionally specifying the WebView2 user data directory |
|
|
205
|
+
| `createWindow(isShow?, isDecorated?)` | `isShow`: boolean (default true), `isDecorated`: boolean (default true) | Promise\<Window> | Creates and returns a window |
|
|
206
|
+
| `closeWindow(window)` | `window`: Window | Promise\<void> | Closes the specified window and returns it to the pool |
|
|
207
|
+
| `closePool()` | None | Promise\<void> | Closes the window pool and exits the application |
|
|
208
|
+
| `mainloop()` | None | void | Starts the application main loop, blocking until the application exits |
|
|
209
|
+
| `onCustomMessage` | `(window: Window, data: string) => void` | None | Custom message callback, triggered when receiving custom messages from pages |
|
|
208
210
|
|
|
209
211
|
### Window
|
|
210
212
|
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
| `loadURL(url)`
|
|
214
|
-
| `loadHTML(html)`
|
|
215
|
-
| `show()`
|
|
216
|
-
| `hide()`
|
|
217
|
-
| `maximize()`
|
|
218
|
-
| `unMaximize()`
|
|
219
|
-
| `minimize()`
|
|
220
|
-
| `unMinimize()`
|
|
221
|
-
| `close()`
|
|
222
|
-
| `setTitle(title)`
|
|
223
|
-
| `setDecorated(isDecorated)`
|
|
224
|
-
| `resizable(resizable)`
|
|
225
|
-
| `openDevTools()`
|
|
226
|
-
| `closeDevTools()`
|
|
227
|
-
| `id`
|
|
228
|
-
|
|
229
|
-
##
|
|
213
|
+
| Method/Property | Parameters | Return Value | Description |
|
|
214
|
+
| ------------------------------------- | ------------------------------------------- | ---------------- | ---------------------------------------- |
|
|
215
|
+
| `loadURL(url)` | `url`: string — URL to load | Promise\<void> | Loads the specified URL |
|
|
216
|
+
| `loadHTML(html)` | `html`: string — HTML string | Promise\<void> | Loads the specified HTML content |
|
|
217
|
+
| `show()` | None | void | Shows the window |
|
|
218
|
+
| `hide()` | None | void | Hides the window |
|
|
219
|
+
| `maximize()` | None | void | Maximizes the window |
|
|
220
|
+
| `unMaximize()` | None | void | Restores the window (cancels maximize) |
|
|
221
|
+
| `minimize()` | None | void | Minimizes the window |
|
|
222
|
+
| `unMinimize()` | None | void | Restores the window (cancels minimize) |
|
|
223
|
+
| `close()` | None | void | Closes the window and returns to pool |
|
|
224
|
+
| `setTitle(title)` | `title`: string — Window title | void | Sets the window title |
|
|
225
|
+
| `setDecorated(isDecorated)` | `isDecorated`: boolean — Use system decorations | void | Sets whether the window has borders and title bar |
|
|
226
|
+
| `resizable(resizable)` | `resizable`: boolean — Resizable | void | Sets whether the window is resizable |
|
|
227
|
+
| `openDevTools()` | None | void | Opens developer tools |
|
|
228
|
+
| `closeDevTools()` | None | void | Closes developer tools |
|
|
229
|
+
| `id` | None | number | Unique window identifier, auto-incrementing |
|
|
230
|
+
|
|
231
|
+
## Development
|
|
230
232
|
|
|
231
233
|
```bash
|
|
232
234
|
pnpm install
|
|
233
235
|
pnpm run compile
|
|
234
236
|
```
|
|
235
237
|
|
|
236
|
-
##
|
|
238
|
+
## License
|
|
237
239
|
|
|
238
|
-
MIT License
|
|
240
|
+
MIT License
|