@iftc/yete 0.0.1-alpha.1 → 0.0.1-alpha.2
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 +21 -0
- package/README.md +39 -0
- package/index.js +132 -3
- package/libs/yete-ui/yete.json +12 -0
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) IFTC 2020-2026
|
|
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,39 @@
|
|
|
1
|
+
# Yete
|
|
2
|
+
|
|
3
|
+
Yete 是一个轻量级、可扩展的 Web 框架。使用 Dexie 库操作 IndexedDB,将资源文件缓存到浏览器中,并支持离线访问。
|
|
4
|
+
开发文档:https://iftc.koyeb.app/docs/yete
|
|
5
|
+
|
|
6
|
+
## 快速开始
|
|
7
|
+
|
|
8
|
+
1. 下载 Yete CLI:
|
|
9
|
+
- [Windows x64](https://dbmp-xbgmorqeur6oh81z.database.nocode.cn/storage/v1/object/public/files/yete.exe "yete.exe")
|
|
10
|
+
- [Linux arm64](https://dbmp-xbgmorqeur6oh81z.database.nocode.cn/storage/v1/object/public/files/yete "yete")
|
|
11
|
+
- [CLI源文件(其他操作系统请自行编译或直接使用 Txiki.js 运行)](https://dbmp-xbgmorqeur6oh81z.database.nocode.cn/storage/v1/object/public/files/yete.zip "yete.zip")
|
|
12
|
+
|
|
13
|
+
2. 创建并构建项目:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yete init <project-name>
|
|
17
|
+
cd <project-name>
|
|
18
|
+
npm i
|
|
19
|
+
yete build && yete serve
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
3. 访问项目:
|
|
23
|
+
浏览器访问 http://localhost:12345
|
|
24
|
+
|
|
25
|
+
## 贡献
|
|
26
|
+
|
|
27
|
+
欢迎任何形式的贡献,如提交 PR、提交 Issue、提交文档、提交翻译、提交代码片段。
|
|
28
|
+
|
|
29
|
+
## 许可证
|
|
30
|
+
|
|
31
|
+
[MIT](https://github.com/IFTC-XLKJ/Yete/blob/main/LICENSE)
|
|
32
|
+
|
|
33
|
+
## 联系作者
|
|
34
|
+
|
|
35
|
+
- 邮箱:iftcceo@139.com 或 iftcceo@gmail.com
|
|
36
|
+
- 社区:https://discord.gg/dWWaUjVWv6
|
|
37
|
+
- 官网:https://iftc.koyeb.app/
|
|
38
|
+
- 仓库:https://github.com/IFTC-XLKJ/yete
|
|
39
|
+
- 官方文档:https://iftc.koyeb.app/docs/yete
|
package/index.js
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
|
+
const { add } = require("dexie");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 自定义错误类
|
|
5
|
+
*/
|
|
1
6
|
class YeteError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* 构造函数
|
|
9
|
+
* @param {String} message 错误信息
|
|
10
|
+
*/
|
|
2
11
|
constructor(message) {
|
|
3
12
|
super(message);
|
|
4
13
|
this.name = 'YeteError';
|
|
5
14
|
}
|
|
6
15
|
}
|
|
7
|
-
|
|
16
|
+
/**
|
|
17
|
+
* 页面基类
|
|
18
|
+
*/
|
|
8
19
|
class Page {
|
|
20
|
+
/**
|
|
21
|
+
* 构造函数
|
|
22
|
+
* @param {String} name
|
|
23
|
+
*/
|
|
9
24
|
constructor(name) {
|
|
10
25
|
this.name = name;
|
|
11
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* 渲染页面
|
|
29
|
+
* @returns {HTMLElement}
|
|
30
|
+
*/
|
|
12
31
|
render() {
|
|
13
32
|
return document.createElement('div', { className: 'page' }, this.name);
|
|
14
33
|
}
|
|
@@ -16,6 +35,7 @@ class Page {
|
|
|
16
35
|
|
|
17
36
|
const pages = [];
|
|
18
37
|
const routes = [];
|
|
38
|
+
const events = [];
|
|
19
39
|
|
|
20
40
|
const obj = {
|
|
21
41
|
/**
|
|
@@ -96,6 +116,21 @@ const obj = {
|
|
|
96
116
|
document.head.appendChild(link);
|
|
97
117
|
});
|
|
98
118
|
},
|
|
119
|
+
/**
|
|
120
|
+
* 加载 JS 文件
|
|
121
|
+
* @param {String} scriptPath
|
|
122
|
+
*/
|
|
123
|
+
loadScript: async function (scriptPath) {
|
|
124
|
+
return new Promise(async (resolve, reject) => {
|
|
125
|
+
const script = document.createElement('script');
|
|
126
|
+
script.type = 'text/javascript';
|
|
127
|
+
const scriptFile = await YeteDB.files.get({ name: scriptPath });
|
|
128
|
+
script.src = URL.createObjectURL(scriptFile.blob);
|
|
129
|
+
script.onload = resolve;
|
|
130
|
+
script.onerror = reject;
|
|
131
|
+
document.body.appendChild(script);
|
|
132
|
+
});
|
|
133
|
+
},
|
|
99
134
|
/**
|
|
100
135
|
* 跳转到指定页面
|
|
101
136
|
* @param {String} path
|
|
@@ -107,20 +142,114 @@ const obj = {
|
|
|
107
142
|
if (page) {
|
|
108
143
|
document.body.innerHTML = "";
|
|
109
144
|
document.body.appendChild(page.page);
|
|
145
|
+
obj.emit('page-change', new obj.YeteEvent("page-change", { path, isNotFound: false }));
|
|
110
146
|
} else {
|
|
111
147
|
document.body.innerHTML = "<center><h1>404 Not Found</h1><p>Power By Yete</p></center>";
|
|
148
|
+
obj.emit('page-change', new obj.YeteEvent("page-change", { path, isNotFound: true }));
|
|
112
149
|
throw new YeteError("The page not found.");
|
|
113
150
|
}
|
|
114
|
-
}
|
|
151
|
+
},
|
|
152
|
+
/**
|
|
153
|
+
* 创建 UI 元素
|
|
154
|
+
* @param {String} tag
|
|
155
|
+
* @param {Object} options
|
|
156
|
+
* @returns {HTMLElement}
|
|
157
|
+
*/
|
|
158
|
+
newElement: function (tag, options = {}) {
|
|
159
|
+
if (!UIElements[tag]) {
|
|
160
|
+
throw new YeteError(`The element ${tag} not found.`);
|
|
161
|
+
}
|
|
162
|
+
const element = document.createElement(UIElements[tag].html);
|
|
163
|
+
const style = UIElements[tag].style;
|
|
164
|
+
if (style) {
|
|
165
|
+
for (const key in style) {
|
|
166
|
+
element.style[key] = style[key];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const key in options) {
|
|
170
|
+
element[key] = options[key];
|
|
171
|
+
}
|
|
172
|
+
return element;
|
|
173
|
+
},
|
|
174
|
+
/**
|
|
175
|
+
* 添加事件监听器
|
|
176
|
+
* @param {String} type
|
|
177
|
+
* @param {Function} listener
|
|
178
|
+
*/
|
|
179
|
+
addEventListener: function (type, listener) {
|
|
180
|
+
events.push({ type, listener });
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* 移除事件监听器
|
|
184
|
+
* @param {String} type
|
|
185
|
+
* @param {Function} listener
|
|
186
|
+
*/
|
|
187
|
+
removeEventListener: function (type, listener) {
|
|
188
|
+
const index = events.findIndex(e => e.type === type && e.listener === listener);
|
|
189
|
+
if (index !== -1) {
|
|
190
|
+
events.splice(index, 1);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* 派发事件
|
|
195
|
+
* @param {String} type
|
|
196
|
+
* @param {Object} event
|
|
197
|
+
*/
|
|
198
|
+
dispatchEvent: function (type, event) {
|
|
199
|
+
events.forEach(e => {
|
|
200
|
+
if (e.type === type) {
|
|
201
|
+
e.listener(event);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* 创建事件
|
|
207
|
+
*/
|
|
208
|
+
YeteEvent: class extends Event {
|
|
209
|
+
/**
|
|
210
|
+
* 构造函数
|
|
211
|
+
* @param {String} type
|
|
212
|
+
* @param {Object} options
|
|
213
|
+
*/
|
|
214
|
+
constructor(type, options) {
|
|
215
|
+
super(type, { bubbles: true, cancelable: true });
|
|
216
|
+
for (const key in options) {
|
|
217
|
+
this[key] = options[key];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
115
221
|
};
|
|
116
222
|
|
|
223
|
+
/**
|
|
224
|
+
* 添加事件监听器
|
|
225
|
+
* @param {String} type
|
|
226
|
+
* @param {Function} listener
|
|
227
|
+
*/
|
|
228
|
+
obj.on = obj.addEventListener;
|
|
229
|
+
/**
|
|
230
|
+
* 移除事件监听器
|
|
231
|
+
* @param {String} type
|
|
232
|
+
* @param {Function} listener
|
|
233
|
+
*/
|
|
234
|
+
obj.off = obj.removeEventListener;
|
|
235
|
+
/**
|
|
236
|
+
* 派发事件
|
|
237
|
+
* @param {String} type
|
|
238
|
+
* @param {Object} event
|
|
239
|
+
*/
|
|
240
|
+
obj.emit = obj.dispatchEvent;
|
|
241
|
+
|
|
117
242
|
// 监听 hashchange 事件,实现页面跳转
|
|
118
243
|
window.addEventListener('hashchange', () => {
|
|
119
244
|
const path = location.hash.slice(1) || '/';
|
|
120
245
|
obj.toPage(path);
|
|
121
246
|
});
|
|
122
247
|
|
|
123
|
-
|
|
248
|
+
/**
|
|
249
|
+
* 获取文件类型
|
|
250
|
+
* @param {String} filePath
|
|
251
|
+
* @returns {String}
|
|
252
|
+
*/
|
|
124
253
|
function getFileType(filePath) {
|
|
125
254
|
const ext = path.extname(filePath).toLowerCase();
|
|
126
255
|
switch (ext) {
|