@qy_better_lib/hooks 0.2.0 → 0.2.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.
@@ -1,6 +1,4 @@
1
- import "../_virtual/dayjs.min.js";
2
- import { auto_size } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/echarts.js";
3
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
1
+ import { auto_size } from "@qy_better_lib/core";
4
2
  const options = {
5
3
  textStyle: {
6
4
  fontSize: auto_size(12),
@@ -1,8 +1,5 @@
1
1
  import { onUnmounted } from "vue";
2
- import { deep_assign, deep_clone } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/object.js";
3
- import "../_virtual/dayjs.min.js";
4
- import { destroy_chart, auto_size, get_chart_gradient_color, generate_chart_colors, remove_chart_listener, add_chart_listener, export_chart_image, resize_chart, merge_chart_options, update_chart, init_chart, make_chart_responsive } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/echarts.js";
5
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
2
+ import { destroy_chart, auto_size, get_chart_gradient_color, generate_chart_colors, remove_chart_listener, add_chart_listener, export_chart_image, resize_chart, merge_chart_options, update_chart, deep_assign, deep_clone, init_chart, make_chart_responsive } from "@qy_better_lib/core";
6
3
  import options from "./config.js";
7
4
  function get_chart_theme(theme) {
8
5
  {
@@ -1,7 +1,5 @@
1
1
  import { ref, shallowRef, onMounted, onUnmounted } from "vue";
2
- import { get_element, on, off } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/dom.js";
3
- import "../_virtual/dayjs.min.js";
4
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
2
+ import { get_element, on, off } from "@qy_better_lib/core";
5
3
  function use_fullscreen(selector) {
6
4
  const full = ref(false);
7
5
  const container = shallowRef(null);
@@ -1,6 +1,4 @@
1
- import { download_file, to_base64, compress_image } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/file.js";
2
- import "../_virtual/dayjs.min.js";
3
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
1
+ import { download_file, to_base64, compress_image } from "@qy_better_lib/core";
4
2
  import { EImageType } from "./type.js";
5
3
  function use_image() {
6
4
  function check_image_type(type) {
@@ -1,6 +1,4 @@
1
- import { deep_assign } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/object.js";
2
- import "../_virtual/dayjs.min.js";
3
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
1
+ import { deep_assign } from "@qy_better_lib/core";
4
2
  function use_layout_flow(options) {
5
3
  let graph = void 0;
6
4
  let Graph;
@@ -1,7 +1,4 @@
1
- import { generate_guid } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/random.js";
2
- import { on, off, get_window_size, get_element } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/dom.js";
3
- import "../_virtual/dayjs.min.js";
4
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
1
+ import { generate_guid, on, off, get_window_size, get_element } from "@qy_better_lib/core";
5
2
  function use_water_mark() {
6
3
  const id = generate_guid();
7
4
  let current_options = null;
@@ -1,6 +1,4 @@
1
- import { is_object } from "../packages/hooks/node_modules/@qy_better_lib/core/lib/utils/is.js";
2
- import "../_virtual/dayjs.min.js";
3
- import "../packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js";
1
+ import { is_object } from "@qy_better_lib/core";
4
2
  function use_web_socket(options) {
5
3
  const {
6
4
  server,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qy_better_lib/hooks",
3
3
  "private": false,
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "description": "qy better lib hooks",
6
6
  "author": "luhuiming",
7
7
  "license": "ISC",
@@ -34,7 +34,12 @@
34
34
  },
35
35
  "exports": {
36
36
  ".": {
37
- "import": "./lib/index.js"
37
+ "import": "./lib/index.js",
38
+ "types": "./lib/index.d.ts"
39
+ },
40
+ "./*": {
41
+ "import": "./lib/*/index.js",
42
+ "types": "./lib/*/index.d.ts"
38
43
  }
39
44
  },
40
45
  "devDependencies": {
@@ -76,6 +81,6 @@
76
81
  }
77
82
  },
78
83
  "dependencies": {
79
- "@qy_better_lib/core": "^0.1.5"
84
+ "@qy_better_lib/core": "^0.2.0"
80
85
  }
81
86
  }
package/USAGE.md DELETED
@@ -1,444 +0,0 @@
1
- # QY Better Lib Hooks - 使用文档
2
-
3
- 本文档详细介绍了 QY Better Lib Hooks 包中的各种钩子函数,包括功能描述、参数说明、返回类型和使用示例。
4
-
5
- ## Hooks 分类
6
-
7
- ### 1. 事件管理钩子 (use-emit)
8
-
9
- #### use_emit
10
- - **功能**: 创建全局事件发射器,支持事件的注册和监听
11
- - **参数**: `event_list?: Array<EventItem>` - 事件监听器数组
12
- - **返回类型**: `UseEmits` - 包含事件发射器的对象
13
- - **示例**:
14
- ```typescript
15
- import { use_emit } from '@qy_better_lib/hooks';
16
-
17
- const { emitter } = use_emit([
18
- {
19
- key: 'test-event',
20
- value: (data) => {
21
- console.log('收到事件:', data);
22
- }
23
- }
24
- ]);
25
-
26
- // 发送事件
27
- emitter.emit('test-event', { message: 'Hello' });
28
-
29
- // 异步发送事件
30
- await emitter.emitAsync('test-event', { message: 'Async Hello' });
31
- ```
32
-
33
- ### 2. 打印功能钩子 (use-print)
34
-
35
- #### use_print
36
- - **功能**: 提供打印页面元素的功能,支持打印HTML内容和DOM元素
37
- - **参数**: 无
38
- - **返回类型**: `UsePrintReturn` - 包含打印操作方法的对象
39
- - **示例**:
40
- ```typescript
41
- import { use_print } from '@qy_better_lib/hooks';
42
-
43
- const { print_html, preview_html } = use_print();
44
-
45
- // 打印指定DOM元素
46
- print_html('#content', {
47
- page_size: 'A4',
48
- page_orientation: 'portrait',
49
- print_background: true,
50
- on_complete: () => {
51
- console.log('打印完成');
52
- }
53
- });
54
-
55
- // 预览打印内容
56
- preview_html('#content', {
57
- preview: true
58
- });
59
- ```
60
-
61
- ### 3. 水印功能钩子 (use-watermark)
62
-
63
- #### use_water_mark
64
- - **功能**: 在页面上添加水印,支持自定义水印内容、样式和位置
65
- - **参数**: 无
66
- - **返回类型**: `UseWaterMark` - 包含水印操作方法的对象
67
- - **示例**:
68
- ```typescript
69
- import { use_water_mark } from '@qy_better_lib/hooks';
70
-
71
- const { create_water_mark, remove_water_mark, update_water_mark } = use_water_mark();
72
-
73
- // 创建水印
74
- create_water_mark({
75
- text1: '测试水印',
76
- text2: '2024-01-01',
77
- font_size: 16,
78
- font_family: 'Arial',
79
- rotate: -15,
80
- text_color: '#999',
81
- opacity: 0.1,
82
- z_index: 100000,
83
- responsive: true
84
- });
85
-
86
- // 更新水印
87
- update_water_mark({
88
- text1: '更新后的水印'
89
- });
90
-
91
- // 移除水印
92
- remove_water_mark();
93
- ```
94
-
95
- ### 4. WebSocket 钩子 (use-websocket)
96
-
97
- #### use_web_socket
98
- - **功能**: 提供 WebSocket 通信功能,支持自动重连、心跳检测和消息队列
99
- - **参数**: `options: WebSocketOptions` - WebSocket 配置选项
100
- - **返回类型**: `UseWebSocketReturn` - 包含 WebSocket 操作方法和状态的对象
101
- - **示例**:
102
- ```typescript
103
- import { use_web_socket } from '@qy_better_lib/hooks';
104
-
105
- const { ws, send_message, get_status, close } = use_web_socket({
106
- server: 'ws://localhost:8080',
107
- receive: (event) => {
108
- console.log('收到消息:', event.data);
109
- },
110
- max_reconnect_attempts: 5,
111
- reconnect_interval: 5000,
112
- heartbeat_interval: 30000,
113
- heartbeat_message: 'ping',
114
- on_open: () => {
115
- console.log('WebSocket连接成功');
116
- },
117
- on_error: (error) => {
118
- console.error('WebSocket错误:', error);
119
- },
120
- on_close: () => {
121
- console.log('WebSocket连接关闭');
122
- }
123
- });
124
-
125
- // 发送消息
126
- send_message({ type: 'chat', content: 'Hello WebSocket' });
127
-
128
- // 获取连接状态
129
- console.log('连接状态:', get_status());
130
-
131
- // 关闭连接
132
- close();
133
- ```
134
-
135
- ### 5. 图片处理钩子 (use-image)
136
-
137
- #### use_image
138
- - **功能**: 提供图片处理功能,包括压缩、转换和下载
139
- - **参数**: 无
140
- - **返回类型**: 包含图片处理方法的对象
141
- - **示例**:
142
- ```typescript
143
- import { use_image, EImageType } from '@qy_better_lib/hooks';
144
-
145
- const { compress, compress_accurately, download_file } = use_image();
146
-
147
- // 压缩图片
148
- async function handleImageCompress(file) {
149
- const compressedFile = await compress(file, {
150
- quality: 0.8,
151
- type: EImageType.JPEG
152
- });
153
- console.log('压缩后的文件大小:', compressedFile.size);
154
- return compressedFile;
155
- }
156
-
157
- // 精确压缩图片到指定大小
158
- async function handleImageCompressAccurately(file) {
159
- const compressedFile = await compress_accurately(file, {
160
- size: 100, // 100KB
161
- accuracy: 0.95,
162
- type: EImageType.JPEG
163
- });
164
- console.log('精确压缩后的文件大小:', compressedFile.size);
165
- return compressedFile;
166
- }
167
-
168
- // 下载图片
169
- function handleDownloadImage(blob) {
170
- download_file(blob, 'compressed-image.jpg');
171
- }
172
- ```
173
-
174
- ### 6. 全屏功能钩子 (use-fullscreen)
175
-
176
- #### use_fullscreen
177
- - **功能**: 提供全屏功能,支持切换、进入和退出全屏
178
- - **参数**: `selector: string` - 目标元素选择器
179
- - **返回类型**: `UseFullScreenReturn` - 包含全屏操作方法和状态的对象
180
- - **示例**:
181
- ```typescript
182
- import { use_fullscreen } from '@qy_better_lib/hooks';
183
-
184
- const { full, toggle_fullscreen, enter_fullscreen, exit_fullscreen } = use_fullscreen('#app');
185
-
186
- // 切换全屏状态
187
- toggle_fullscreen();
188
-
189
- // 进入全屏
190
- enter_fullscreen();
191
-
192
- // 退出全屏
193
- exit_fullscreen();
194
-
195
- // 监听全屏状态变化
196
- console.log('当前全屏状态:', full.value);
197
- ```
198
-
199
- ### 7. 图表管理钩子 (use-chart)
200
-
201
- #### use_chart
202
- - **功能**: 提供 ECharts 图表管理功能,支持渲染、更新和销毁图表
203
- - **参数**: `options: UseChartOptions` - 图表配置选项
204
- - **返回类型**: `UseChartReturn` - 包含图表管理方法的对象
205
- - **示例**:
206
- ```typescript
207
- import { use_chart } from '@qy_better_lib/hooks';
208
-
209
- const { render_chart, update_chart, remove_chart } = use_chart({
210
- default_theme: 'light',
211
- default_renderer: 'canvas',
212
- auto_responsive: true
213
- });
214
-
215
- // 渲染图表
216
- async function renderMyChart() {
217
- const chartOption = {
218
- title: {
219
- text: '示例图表'
220
- },
221
- tooltip: {},
222
- xAxis: {
223
- data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
224
- },
225
- yAxis: {},
226
- series: [{
227
- name: '销量',
228
- type: 'bar',
229
- data: [120, 200, 150, 80, 70, 110, 130]
230
- }]
231
- };
232
-
233
- const chart = await render_chart(chartOption, '#chart-container');
234
- console.log('图表渲染成功:', chart);
235
- }
236
-
237
- // 更新图表
238
- function updateMyChart() {
239
- const newOption = {
240
- series: [{
241
- name: '销量',
242
- type: 'bar',
243
- data: [150, 250, 200, 100, 90, 130, 160]
244
- }]
245
- };
246
-
247
- update_chart('#chart-container', newOption);
248
- }
249
-
250
- // 移除图表
251
- function removeMyChart() {
252
- remove_chart('#chart-container');
253
- }
254
- ```
255
-
256
- ### 8. 流程图布局钩子 (use-layout-flow)
257
-
258
- #### use_layout_flow
259
- - **功能**: 提供流程图自动布局功能,支持多种布局方向和自定义元素
260
- - **参数**: `options: LayoutFlow` - 布局配置选项
261
- - **返回类型**: 包含流程图布局方法的对象
262
- - **示例**:
263
- ```typescript
264
- import { use_layout_flow } from '@qy_better_lib/hooks';
265
-
266
- const { init, add_graph_elements, layout, center_content } = use_layout_flow({
267
- option: {
268
- panning: true,
269
- interacting: false,
270
- mousewheel: {
271
- enabled: true
272
- },
273
- scaling: { min: 0.1, max: 10 }
274
- }
275
- });
276
-
277
- // 初始化画布
278
- async function initFlowChart() {
279
- const container = document.getElementById('flow-container');
280
- const success = await init(container);
281
-
282
- if (success) {
283
- // 添加节点和边
284
- const elements = [
285
- {
286
- id: 'node1',
287
- shape: 'rect',
288
- x: 100,
289
- y: 100,
290
- width: 80,
291
- height: 40,
292
- label: '节点1'
293
- },
294
- {
295
- id: 'node2',
296
- shape: 'rect',
297
- x: 300,
298
- y: 100,
299
- width: 80,
300
- height: 40,
301
- label: '节点2'
302
- },
303
- {
304
- id: 'edge1',
305
- shape: 'edge',
306
- source: 'node1',
307
- target: 'node2'
308
- }
309
- ];
310
-
311
- add_graph_elements(elements);
312
-
313
- // 自动布局
314
- await layout({
315
- node_w: 100,
316
- node_h: 50,
317
- nodesep: 50,
318
- ranksep: 80
319
- }, 'LR');
320
-
321
- // 内容居中
322
- center_content(50);
323
- }
324
- }
325
- ```
326
-
327
- ### 9. MQTT 通信钩子 (use-mqtt)
328
-
329
- #### use_mqtt
330
- - **功能**: 提供 MQTT 通信功能,支持连接管理、消息订阅和发布
331
- - **参数**:
332
- - `url: string` - MQTT broker 地址
333
- - `options: any` - MQTT 连接选项
334
- - **返回类型**: `UseMqttReturn` - 包含 MQTT 操作方法和状态的对象
335
- - **示例**:
336
- ```typescript
337
- import { use_mqtt } from '@qy_better_lib/hooks';
338
-
339
- const { connect, subscribe, publish, close, status } = use_mqtt('mqtt://localhost:1883', {
340
- clientId: 'test-client',
341
- clean: true,
342
- reconnectPeriod: 5000
343
- });
344
-
345
- // 连接 MQTT
346
- async function connectMqtt() {
347
- connect({
348
- success: () => {
349
- console.log('MQTT 连接成功');
350
- // 订阅主题
351
- subscribe('test/topic', {}, (err, granted) => {
352
- if (!err) {
353
- console.log('订阅成功:', granted);
354
- }
355
- });
356
- },
357
- error: (err) => {
358
- console.error('MQTT 连接错误:', err);
359
- },
360
- receive: (topic, message) => {
361
- console.log('收到消息:', topic, message.toString());
362
- }
363
- });
364
- }
365
-
366
- // 发布消息
367
- function publishMessage() {
368
- publish('test/topic', 'Hello MQTT', {}, (error) => {
369
- if (!error) {
370
- console.log('消息发布成功');
371
- }
372
- });
373
- }
374
-
375
- // 关闭连接
376
- function closeMqtt() {
377
- close(() => {
378
- console.log('MQTT 连接已关闭');
379
- });
380
- }
381
-
382
- // 监听连接状态
383
- console.log('当前连接状态:', status);
384
- ```
385
-
386
- ## 安装和使用
387
-
388
- ### 安装
389
-
390
- ```bash
391
- # 使用 npm
392
- npm install @qy_better_lib/hooks
393
-
394
- # 使用 yarn
395
- yarn add @qy_better_lib/hooks
396
- ```
397
-
398
- ### 全局引入
399
-
400
- ```typescript
401
- import { createApp } from 'vue';
402
- import App from './App.vue';
403
- import * as QyHooks from '@qy_better_lib/hooks';
404
-
405
- const app = createApp(App);
406
-
407
- // 全局注册所有钩子
408
- app.config.globalProperties.$hooks = QyHooks;
409
-
410
- app.mount('#app');
411
- ```
412
-
413
- ### 按需引入
414
-
415
- ```typescript
416
- // 按需引入所需的钩子
417
- import { use_print, use_water_mark } from '@qy_better_lib/hooks';
418
- ```
419
-
420
- ## 版本历史
421
-
422
- - **v1.0.0** - 初始版本,包含所有钩子函数
423
-
424
- ## 贡献指南
425
-
426
- 1. Fork 仓库
427
- 2. 创建功能分支
428
- 3. 提交代码
429
- 4. 发起 Pull Request
430
-
431
- ## 许可证
432
-
433
- MIT License
434
-
435
- ## 注意事项
436
-
437
- - 使用 `use-chart` 钩子时,需要确保已安装 `echarts` 依赖
438
- - 使用 `use-layout-flow` 钩子时,需要确保已安装 `@antv/x6` 和 `dagre` 依赖
439
- - 使用 `use-mqtt` 钩子时,需要确保已安装 `mqtt` 依赖
440
- - 所有钩子函数都使用 TypeScript 编写,提供了完整的类型定义
441
-
442
- ## 总结
443
-
444
- QY Better Lib Hooks 提供了一系列实用的 Vue 3 Composition API 钩子函数,涵盖了事件管理、打印功能、水印功能、WebSocket 通信、图片处理、全屏功能、图表管理、流程图布局和 MQTT 通信等多种场景。这些钩子函数设计简洁,使用方便,可以帮助开发者更高效地构建 Vue 应用。
@@ -1,2 +0,0 @@
1
- import { __require as requireDayjs_min } from "../node_modules/dayjs/dayjs.min.js";
2
- requireDayjs_min();
@@ -1,4 +0,0 @@
1
- var dayjs_min = { exports: {} };
2
- export {
3
- dayjs_min as __module
4
- };
@@ -1,286 +0,0 @@
1
- import { __module as dayjs_min$1 } from "../../_virtual/dayjs.min2.js";
2
- var dayjs_min = dayjs_min$1.exports;
3
- var hasRequiredDayjs_min;
4
- function requireDayjs_min() {
5
- if (hasRequiredDayjs_min) return dayjs_min$1.exports;
6
- hasRequiredDayjs_min = 1;
7
- (function(module, exports) {
8
- !(function(t, e) {
9
- module.exports = e();
10
- })(dayjs_min, (function() {
11
- var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
12
- var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
13
- return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
14
- } }, m = function(t2, e2, n2) {
15
- var r2 = String(t2);
16
- return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
17
- }, v = { s: m, z: function(t2) {
18
- var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
19
- return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
20
- }, m: function t2(e2, n2) {
21
- if (e2.date() < n2.date()) return -t2(n2, e2);
22
- var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
23
- return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
24
- }, a: function(t2) {
25
- return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
26
- }, p: function(t2) {
27
- return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
28
- }, u: function(t2) {
29
- return void 0 === t2;
30
- } }, g = "en", D = {};
31
- D[g] = M;
32
- var p = "$isDayjsObject", S = function(t2) {
33
- return t2 instanceof _ || !(!t2 || !t2[p]);
34
- }, w = function t2(e2, n2, r2) {
35
- var i2;
36
- if (!e2) return g;
37
- if ("string" == typeof e2) {
38
- var s2 = e2.toLowerCase();
39
- D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
40
- var u2 = e2.split("-");
41
- if (!i2 && u2.length > 1) return t2(u2[0]);
42
- } else {
43
- var a2 = e2.name;
44
- D[a2] = e2, i2 = a2;
45
- }
46
- return !r2 && i2 && (g = i2), i2 || !r2 && g;
47
- }, O = function(t2, e2) {
48
- if (S(t2)) return t2.clone();
49
- var n2 = "object" == typeof e2 ? e2 : {};
50
- return n2.date = t2, n2.args = arguments, new _(n2);
51
- }, b = v;
52
- b.l = w, b.i = S, b.w = function(t2, e2) {
53
- return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
54
- };
55
- var _ = (function() {
56
- function M2(t2) {
57
- this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
58
- }
59
- var m2 = M2.prototype;
60
- return m2.parse = function(t2) {
61
- this.$d = (function(t3) {
62
- var e2 = t3.date, n2 = t3.utc;
63
- if (null === e2) return /* @__PURE__ */ new Date(NaN);
64
- if (b.u(e2)) return /* @__PURE__ */ new Date();
65
- if (e2 instanceof Date) return new Date(e2);
66
- if ("string" == typeof e2 && !/Z$/i.test(e2)) {
67
- var r2 = e2.match($);
68
- if (r2) {
69
- var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
70
- return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
71
- }
72
- }
73
- return new Date(e2);
74
- })(t2), this.init();
75
- }, m2.init = function() {
76
- var t2 = this.$d;
77
- this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
78
- }, m2.$utils = function() {
79
- return b;
80
- }, m2.isValid = function() {
81
- return !(this.$d.toString() === l);
82
- }, m2.isSame = function(t2, e2) {
83
- var n2 = O(t2);
84
- return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
85
- }, m2.isAfter = function(t2, e2) {
86
- return O(t2) < this.startOf(e2);
87
- }, m2.isBefore = function(t2, e2) {
88
- return this.endOf(e2) < O(t2);
89
- }, m2.$g = function(t2, e2, n2) {
90
- return b.u(t2) ? this[e2] : this.set(n2, t2);
91
- }, m2.unix = function() {
92
- return Math.floor(this.valueOf() / 1e3);
93
- }, m2.valueOf = function() {
94
- return this.$d.getTime();
95
- }, m2.startOf = function(t2, e2) {
96
- var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
97
- var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
98
- return r2 ? i2 : i2.endOf(a);
99
- }, $2 = function(t3, e3) {
100
- return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
101
- }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
102
- switch (f2) {
103
- case h:
104
- return r2 ? l2(1, 0) : l2(31, 11);
105
- case c:
106
- return r2 ? l2(1, M3) : l2(0, M3 + 1);
107
- case o:
108
- var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
109
- return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
110
- case a:
111
- case d:
112
- return $2(v2 + "Hours", 0);
113
- case u:
114
- return $2(v2 + "Minutes", 1);
115
- case s:
116
- return $2(v2 + "Seconds", 2);
117
- case i:
118
- return $2(v2 + "Milliseconds", 3);
119
- default:
120
- return this.clone();
121
- }
122
- }, m2.endOf = function(t2) {
123
- return this.startOf(t2, false);
124
- }, m2.$set = function(t2, e2) {
125
- var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
126
- if (o2 === c || o2 === h) {
127
- var y2 = this.clone().set(d, 1);
128
- y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
129
- } else l2 && this.$d[l2]($2);
130
- return this.init(), this;
131
- }, m2.set = function(t2, e2) {
132
- return this.clone().$set(t2, e2);
133
- }, m2.get = function(t2) {
134
- return this[b.p(t2)]();
135
- }, m2.add = function(r2, f2) {
136
- var d2, l2 = this;
137
- r2 = Number(r2);
138
- var $2 = b.p(f2), y2 = function(t2) {
139
- var e2 = O(l2);
140
- return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
141
- };
142
- if ($2 === c) return this.set(c, this.$M + r2);
143
- if ($2 === h) return this.set(h, this.$y + r2);
144
- if ($2 === a) return y2(1);
145
- if ($2 === o) return y2(7);
146
- var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
147
- return b.w(m3, this);
148
- }, m2.subtract = function(t2, e2) {
149
- return this.add(-1 * t2, e2);
150
- }, m2.format = function(t2) {
151
- var e2 = this, n2 = this.$locale();
152
- if (!this.isValid()) return n2.invalidDate || l;
153
- var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
154
- return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
155
- }, d2 = function(t3) {
156
- return b.s(s2 % 12 || 12, t3, "0");
157
- }, $2 = f2 || function(t3, e3, n3) {
158
- var r3 = t3 < 12 ? "AM" : "PM";
159
- return n3 ? r3.toLowerCase() : r3;
160
- };
161
- return r2.replace(y, (function(t3, r3) {
162
- return r3 || (function(t4) {
163
- switch (t4) {
164
- case "YY":
165
- return String(e2.$y).slice(-2);
166
- case "YYYY":
167
- return b.s(e2.$y, 4, "0");
168
- case "M":
169
- return a2 + 1;
170
- case "MM":
171
- return b.s(a2 + 1, 2, "0");
172
- case "MMM":
173
- return h2(n2.monthsShort, a2, c2, 3);
174
- case "MMMM":
175
- return h2(c2, a2);
176
- case "D":
177
- return e2.$D;
178
- case "DD":
179
- return b.s(e2.$D, 2, "0");
180
- case "d":
181
- return String(e2.$W);
182
- case "dd":
183
- return h2(n2.weekdaysMin, e2.$W, o2, 2);
184
- case "ddd":
185
- return h2(n2.weekdaysShort, e2.$W, o2, 3);
186
- case "dddd":
187
- return o2[e2.$W];
188
- case "H":
189
- return String(s2);
190
- case "HH":
191
- return b.s(s2, 2, "0");
192
- case "h":
193
- return d2(1);
194
- case "hh":
195
- return d2(2);
196
- case "a":
197
- return $2(s2, u2, true);
198
- case "A":
199
- return $2(s2, u2, false);
200
- case "m":
201
- return String(u2);
202
- case "mm":
203
- return b.s(u2, 2, "0");
204
- case "s":
205
- return String(e2.$s);
206
- case "ss":
207
- return b.s(e2.$s, 2, "0");
208
- case "SSS":
209
- return b.s(e2.$ms, 3, "0");
210
- case "Z":
211
- return i2;
212
- }
213
- return null;
214
- })(t3) || i2.replace(":", "");
215
- }));
216
- }, m2.utcOffset = function() {
217
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
218
- }, m2.diff = function(r2, d2, l2) {
219
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
220
- return b.m(y2, m3);
221
- };
222
- switch (M3) {
223
- case h:
224
- $2 = D2() / 12;
225
- break;
226
- case c:
227
- $2 = D2();
228
- break;
229
- case f:
230
- $2 = D2() / 3;
231
- break;
232
- case o:
233
- $2 = (g2 - v2) / 6048e5;
234
- break;
235
- case a:
236
- $2 = (g2 - v2) / 864e5;
237
- break;
238
- case u:
239
- $2 = g2 / n;
240
- break;
241
- case s:
242
- $2 = g2 / e;
243
- break;
244
- case i:
245
- $2 = g2 / t;
246
- break;
247
- default:
248
- $2 = g2;
249
- }
250
- return l2 ? $2 : b.a($2);
251
- }, m2.daysInMonth = function() {
252
- return this.endOf(c).$D;
253
- }, m2.$locale = function() {
254
- return D[this.$L];
255
- }, m2.locale = function(t2, e2) {
256
- if (!t2) return this.$L;
257
- var n2 = this.clone(), r2 = w(t2, e2, true);
258
- return r2 && (n2.$L = r2), n2;
259
- }, m2.clone = function() {
260
- return b.w(this.$d, this);
261
- }, m2.toDate = function() {
262
- return new Date(this.valueOf());
263
- }, m2.toJSON = function() {
264
- return this.isValid() ? this.toISOString() : null;
265
- }, m2.toISOString = function() {
266
- return this.$d.toISOString();
267
- }, m2.toString = function() {
268
- return this.$d.toUTCString();
269
- }, M2;
270
- })(), k = _.prototype;
271
- return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach((function(t2) {
272
- k[t2[1]] = function(e2) {
273
- return this.$g(e2, t2[0], t2[1]);
274
- };
275
- })), O.extend = function(t2, e2) {
276
- return t2.$i || (t2(e2, _, O), t2.$i = true), O;
277
- }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
278
- return O(1e3 * t2);
279
- }, O.en = D[g], O.Ls = D, O.p = {}, O;
280
- }));
281
- })(dayjs_min$1);
282
- return dayjs_min$1.exports;
283
- }
284
- export {
285
- requireDayjs_min as __require
286
- };
@@ -1,19 +0,0 @@
1
- import { is_client } from "../utils/is.js";
2
- import "../../../../../../../_virtual/dayjs.min.js";
3
- const node_list = /* @__PURE__ */ new Map();
4
- let start_click = null;
5
- if (is_client) {
6
- document.addEventListener("mousedown", (e) => {
7
- start_click = e;
8
- });
9
- document.addEventListener("mouseup", (e) => {
10
- for (const handlers of node_list.values()) {
11
- for (const { document_handler } of handlers) {
12
- if (start_click) {
13
- document_handler(e, start_click);
14
- }
15
- }
16
- }
17
- start_click = null;
18
- });
19
- }
@@ -1,25 +0,0 @@
1
- function get_element(selector, context = document) {
2
- return context.querySelector(selector);
3
- }
4
- function on(element, event, handler, options) {
5
- if (element) {
6
- element.addEventListener(event, handler, options);
7
- }
8
- }
9
- function off(element, event, handler, options) {
10
- if (element) {
11
- element.removeEventListener(event, handler, options);
12
- }
13
- }
14
- function get_window_size() {
15
- return {
16
- width: window.innerWidth || document.documentElement.clientWidth,
17
- height: window.innerHeight || document.documentElement.clientHeight
18
- };
19
- }
20
- export {
21
- get_element,
22
- get_window_size,
23
- off,
24
- on
25
- };
@@ -1,166 +0,0 @@
1
- function auto_size(size, deflate_width = 1920) {
2
- let client_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
3
- if (!client_width) return size;
4
- let scale = client_width / deflate_width;
5
- return Number((size * scale).toFixed(3));
6
- }
7
- function get_chart_gradient_color(type, start_color, end_color) {
8
- return {
9
- type: "linear",
10
- x: 0,
11
- y: 0,
12
- x2: type === "v" ? 0 : 1,
13
- y2: type === "v" ? 1 : 0,
14
- colorStops: [
15
- {
16
- offset: 0,
17
- color: start_color
18
- // 0% 处的颜色
19
- },
20
- {
21
- offset: 1,
22
- color: end_color
23
- // 100% 处的颜色
24
- }
25
- ]
26
- };
27
- }
28
- function init_chart(container, options, renderer = "canvas", theme) {
29
- const load_echarts = async () => {
30
- try {
31
- let echarts;
32
- if (typeof window !== "undefined" && window.echarts) {
33
- echarts = window.echarts;
34
- } else {
35
- const imported = await import("echarts");
36
- echarts = imported.default || imported;
37
- }
38
- const chart_dom = typeof container === "string" ? document.getElementById(container) : container;
39
- if (!chart_dom) {
40
- console.error("ECharts DOM容器未找到");
41
- return null;
42
- }
43
- const chart = echarts.init(chart_dom, theme, {
44
- renderer
45
- });
46
- if (options) {
47
- chart.setOption(options);
48
- }
49
- return chart;
50
- } catch (error) {
51
- console.error("加载 ECharts 失败:", error);
52
- return null;
53
- }
54
- };
55
- return load_echarts();
56
- }
57
- function destroy_chart(chart) {
58
- if (chart && typeof chart.dispose === "function") {
59
- chart.dispose();
60
- }
61
- }
62
- function update_chart(chart, options) {
63
- if (chart && typeof chart.setOption === "function") {
64
- chart.setOption(options);
65
- }
66
- }
67
- function resize_chart(chart) {
68
- if (chart && typeof chart.resize === "function") {
69
- chart.resize();
70
- }
71
- }
72
- function make_chart_responsive(chart, debounce_time = 200) {
73
- if (!chart) return;
74
- let resize_timer;
75
- const resize_handler = () => {
76
- clearTimeout(resize_timer);
77
- resize_timer = setTimeout(() => {
78
- resize_chart(chart);
79
- }, debounce_time);
80
- };
81
- window.addEventListener("resize", resize_handler);
82
- return () => {
83
- window.removeEventListener("resize", resize_handler);
84
- clearTimeout(resize_timer);
85
- };
86
- }
87
- function generate_chart_colors(count, base_colors) {
88
- const default_colors = [
89
- "#5470c6",
90
- "#91cc75",
91
- "#fac858",
92
- "#ee6666",
93
- "#73c0de",
94
- "#3ba272",
95
- "#fc8452",
96
- "#9a60b4",
97
- "#ea7ccc",
98
- "#67c23a"
99
- ];
100
- const colors = base_colors || default_colors;
101
- const result = [];
102
- for (let i = 0; i < count; i++) {
103
- result.push(colors[i % colors.length]);
104
- }
105
- return result;
106
- }
107
- function merge_chart_options(defaultOption, customOption) {
108
- return {
109
- ...defaultOption,
110
- ...customOption,
111
- // 特殊处理数组类型的配置
112
- series: customOption.series || defaultOption.series,
113
- xAxis: customOption.xAxis || defaultOption.xAxis,
114
- yAxis: customOption.yAxis || defaultOption.yAxis,
115
- legend: customOption.legend || defaultOption.legend,
116
- tooltip: customOption.tooltip || defaultOption.tooltip,
117
- title: customOption.title || defaultOption.title
118
- };
119
- }
120
- function add_chart_listener(chart, eventName, handler) {
121
- if (chart && typeof chart.on === "function") {
122
- chart.on(eventName, handler);
123
- }
124
- }
125
- function remove_chart_listener(chart, eventName, handler) {
126
- if (chart && typeof chart.off === "function") {
127
- chart.off(eventName, handler);
128
- }
129
- }
130
- function export_chart_image(chart, options = {}) {
131
- if (!chart || typeof chart.getDataURL !== "function") {
132
- return null;
133
- }
134
- const {
135
- type = "png",
136
- pixel_ratio = 2,
137
- background_color = "#fff",
138
- exclude_components = [],
139
- file_name = "echarts-image"
140
- } = options;
141
- const data_url = chart.getDataURL({
142
- type,
143
- pixelRatio: pixel_ratio,
144
- backgroundColor: background_color,
145
- excludeComponents: exclude_components
146
- });
147
- const link = document.createElement("a");
148
- link.download = `${file_name}.${type}`;
149
- link.href = data_url;
150
- link.click();
151
- return data_url;
152
- }
153
- export {
154
- add_chart_listener,
155
- auto_size,
156
- destroy_chart,
157
- export_chart_image,
158
- generate_chart_colors,
159
- get_chart_gradient_color,
160
- init_chart,
161
- make_chart_responsive,
162
- merge_chart_options,
163
- remove_chart_listener,
164
- resize_chart,
165
- update_chart
166
- };
@@ -1,55 +0,0 @@
1
- function download_file({ path, name }) {
2
- const link = document.createElement("a");
3
- link.href = path;
4
- link.target = "_blank";
5
- name && link.setAttribute("download", name);
6
- document.body.appendChild(link);
7
- link.click();
8
- document.body.removeChild(link);
9
- }
10
- async function to_base64(file) {
11
- if (!file) return void 0;
12
- const reader = new FileReader();
13
- reader.readAsDataURL(file);
14
- return new Promise((resolve, reject) => {
15
- reader.onload = (event) => {
16
- return resolve(event.target?.result);
17
- };
18
- reader.onerror = (error) => {
19
- return reject(void 0);
20
- };
21
- });
22
- }
23
- async function compress_image(file, max_width = 800, max_height = 800, quality = 0.8) {
24
- if (!file.type.startsWith("image/")) return void 0;
25
- return new Promise((resolve) => {
26
- const canvas = document.createElement("canvas");
27
- const ctx = canvas.getContext("2d");
28
- const img = new Image();
29
- img.onload = () => {
30
- let { width, height } = img;
31
- if (width > max_width || height > max_height) {
32
- const ratio = Math.min(max_width / width, max_height / height);
33
- width *= ratio;
34
- height *= ratio;
35
- }
36
- canvas.width = width;
37
- canvas.height = height;
38
- ctx?.drawImage(img, 0, 0, width, height);
39
- canvas.toBlob((blob) => {
40
- if (blob) {
41
- const compressed_file = new File([blob], file.name, { type: file.type });
42
- resolve(compressed_file);
43
- } else {
44
- resolve(void 0);
45
- }
46
- }, file.type, quality);
47
- };
48
- img.src = URL.createObjectURL(file);
49
- });
50
- }
51
- export {
52
- compress_image,
53
- download_file,
54
- to_base64
55
- };
@@ -1,8 +0,0 @@
1
- function is_object(val) {
2
- return typeof val === "object" && val !== null && Object.prototype.toString.call(val) === "[object Object]";
3
- }
4
- const is_client = typeof window !== "undefined";
5
- export {
6
- is_client,
7
- is_object
8
- };
@@ -1,83 +0,0 @@
1
- import { is_object } from "./is.js";
2
- function deep_clone(obj) {
3
- const _toString = Object.prototype.toString;
4
- if (!obj || typeof obj !== "object") {
5
- return obj;
6
- }
7
- if (obj.nodeType && "cloneNode" in obj) {
8
- return obj.cloneNode(true);
9
- }
10
- if (_toString.call(obj) === "[object Date]") {
11
- return new Date(obj.getTime());
12
- }
13
- if (_toString.call(obj) === "[object RegExp]") {
14
- const flags = [];
15
- if (obj.global) {
16
- flags.push("g");
17
- }
18
- if (obj.multiline) {
19
- flags.push("m");
20
- }
21
- if (obj.ignoreCase) {
22
- flags.push("i");
23
- }
24
- return new RegExp(obj.source, flags.join(""));
25
- }
26
- if (_toString.call(obj) === "[object FormData]") {
27
- const form_data = new FormData();
28
- for (const [key, value] of obj.entries()) {
29
- form_data.append(key, value);
30
- }
31
- return form_data;
32
- }
33
- if (_toString.call(obj) === "[object Map]") {
34
- const map = /* @__PURE__ */ new Map();
35
- for (const [key, value] of obj.entries()) {
36
- map.set(key, deep_clone(value));
37
- }
38
- return map;
39
- }
40
- if (_toString.call(obj) === "[object Set]") {
41
- const set = /* @__PURE__ */ new Set();
42
- for (const value of obj.values()) {
43
- set.add(deep_clone(value));
44
- }
45
- return set;
46
- }
47
- const result = Array.isArray(obj) ? [] : obj.constructor ? new obj.constructor() : {};
48
- for (const key in obj) {
49
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
50
- result[key] = deep_clone(obj[key]);
51
- }
52
- }
53
- return result;
54
- }
55
- function deep_assign(...args) {
56
- let len = args.length, target = args[0];
57
- if (!is_object(target)) {
58
- target = {};
59
- }
60
- for (let i = 1; i < len; i++) {
61
- let source = args[i];
62
- if (is_object(source)) {
63
- for (let s in source) {
64
- if (s === "__proto__" || target === source[s]) {
65
- continue;
66
- }
67
- if (is_object(source[s])) {
68
- if (!is_object(target[s])) {
69
- target[s] = Array.isArray(source[s]) ? [] : {};
70
- }
71
- target[s] = deep_assign(target[s], source[s]);
72
- } else {
73
- target[s] = source[s];
74
- }
75
- }
76
- }
77
- }
78
- return target;
79
- }
80
- export {
81
- deep_assign,
82
- deep_clone
83
- };
@@ -1,11 +0,0 @@
1
- function generate_guid() {
2
- const gs = generate_string;
3
- return `${gs()}${gs()}-${gs()}-${gs()}-${gs()}-${gs()}${gs()}${gs()}`;
4
- }
5
- function generate_string() {
6
- return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
7
- }
8
- export {
9
- generate_guid,
10
- generate_string
11
- };