@qy_better_lib/hooks 0.1.9 → 0.2.0

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.
Files changed (82) hide show
  1. package/DOCUMENTATION.md +704 -0
  2. package/USAGE.md +444 -0
  3. package/__tests__/use-chart/index.test.ts +287 -0
  4. package/__tests__/use-emit/index.test.ts +248 -0
  5. package/__tests__/use-fullscreen/index.test.ts +162 -0
  6. package/__tests__/use-image/index.test.ts +230 -0
  7. package/__tests__/use-layout-flow/index.test.ts +382 -0
  8. package/__tests__/use-mqtt/index.test.ts +392 -0
  9. package/__tests__/use-print/index.test.ts +378 -0
  10. package/__tests__/use-watermark/index.test.ts +277 -0
  11. package/__tests__/use-websocket/index.test.ts +402 -0
  12. package/dist/hooks.min.js +76 -0
  13. package/lib/_virtual/dayjs.min.js +2 -0
  14. package/lib/_virtual/dayjs.min2.js +4 -0
  15. package/lib/index.d.ts +5 -2
  16. package/lib/index.js +20 -31
  17. package/lib/node_modules/dayjs/dayjs.min.js +286 -0
  18. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/directives/click_outside.js +19 -0
  19. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/dom.js +25 -0
  20. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/echarts.js +166 -0
  21. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/file.js +55 -0
  22. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/is.js +8 -0
  23. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/object.js +83 -0
  24. package/lib/packages/hooks/node_modules/@qy_better_lib/core/lib/utils/random.js +11 -0
  25. package/lib/use-chart/config.d.ts +2 -3
  26. package/lib/use-chart/config.js +80 -0
  27. package/lib/use-chart/index.d.ts +5 -13
  28. package/lib/use-chart/index.js +199 -0
  29. package/lib/use-chart/type.d.ts +92 -4
  30. package/lib/use-emit/extend.d.ts +2 -1
  31. package/lib/use-emit/extend.js +34 -15
  32. package/lib/use-emit/index.d.ts +2 -13
  33. package/lib/use-emit/index.js +22 -17
  34. package/lib/use-emit/type.d.ts +16 -0
  35. package/lib/use-fullscreen/index.d.ts +23 -0
  36. package/lib/use-fullscreen/index.js +53 -0
  37. package/lib/use-image/index.d.ts +18 -52
  38. package/lib/use-image/index.js +189 -67
  39. package/lib/use-image/type.d.ts +8 -10
  40. package/lib/use-image/type.js +7 -6
  41. package/lib/use-layout-flow/index.d.ts +14 -40
  42. package/lib/use-layout-flow/index.js +286 -0
  43. package/lib/use-layout-flow/type.d.ts +46 -0
  44. package/lib/use-mqtt/index.d.ts +9 -18
  45. package/lib/use-mqtt/index.js +179 -0
  46. package/lib/use-mqtt/type.d.ts +78 -0
  47. package/lib/use-print/index.d.ts +5 -9
  48. package/lib/use-print/index.js +274 -40
  49. package/lib/use-print/type.d.ts +58 -0
  50. package/lib/use-watermark/index.d.ts +7 -0
  51. package/lib/use-watermark/index.js +134 -0
  52. package/lib/use-watermark/type.d.ts +55 -0
  53. package/lib/use-websocket/index.d.ts +6 -13
  54. package/lib/use-websocket/index.js +192 -39
  55. package/lib/use-websocket/type.d.ts +54 -0
  56. package/package.json +9 -3
  57. package/dist/@qy_better_lib/hooks.min.js +0 -15
  58. package/lib/use-chart/utils.d.ts +0 -7
  59. package/lib/use-file/index.d.ts +0 -14
  60. package/lib/use-file/index.js +0 -26
  61. package/lib/use-image/canvastoDataURL.d.ts +0 -11
  62. package/lib/use-image/canvastoDataURL.js +0 -7
  63. package/lib/use-image/canvastoFile.d.ts +0 -11
  64. package/lib/use-image/canvastoFile.js +0 -9
  65. package/lib/use-image/dataURLtoFile.d.ts +0 -10
  66. package/lib/use-image/dataURLtoFile.js +0 -16
  67. package/lib/use-image/dataURLtoImage.d.ts +0 -7
  68. package/lib/use-image/dataURLtoImage.js +0 -9
  69. package/lib/use-image/downloadFile.d.ts +0 -7
  70. package/lib/use-image/downloadFile.js +0 -9
  71. package/lib/use-image/filetoDataURL.d.ts +0 -7
  72. package/lib/use-image/filetoDataURL.js +0 -9
  73. package/lib/use-image/imagetoCanvas.d.ts +0 -26
  74. package/lib/use-image/imagetoCanvas.js +0 -41
  75. package/lib/use-image/urltoBlob.d.ts +0 -8
  76. package/lib/use-image/urltoBlob.js +0 -6
  77. package/lib/use-image/urltoImage.d.ts +0 -7
  78. package/lib/use-image/urltoImage.js +0 -13
  79. package/lib/use-utils/index.d.ts +0 -1
  80. package/lib/use-utils/use-fullscreen.d.ts +0 -9
  81. package/lib/use-waterMark/index.d.ts +0 -17
  82. package/lib/use-waterMark/index.js +0 -29
@@ -1,67 +1,301 @@
1
- function y() {
2
- function o(t) {
3
- let e = c(), n = u(t);
4
- document.body.appendChild(e), document.body.appendChild(n), m(n).then(() => {
5
- window.print(), document.body.removeChild(e), document.body.removeChild(n);
6
- });
7
- }
8
- function c(t) {
9
- let e = `#print-container {
1
+ function use_print() {
2
+ let preview_container = null;
3
+ let print_in_progress = false;
4
+ function get_style(custom_style, options) {
5
+ const page_size = options?.page_size || "A4";
6
+ const page_orientation = options?.page_orientation || "portrait";
7
+ const margin = options?.margin || "1cm";
8
+ const print_background = options?.print_background ? "true" : "false";
9
+ const default_style = `#print-container {
10
10
  display: none;
11
11
  }
12
+ #preview-container {
13
+ position: fixed;
14
+ top: 0;
15
+ left: 0;
16
+ width: 100%;
17
+ height: 100%;
18
+ background: rgba(0, 0, 0, 0.8);
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ z-index: 9999;
23
+ overflow: auto;
24
+ }
25
+ #preview-content {
26
+ background: white;
27
+ width: 80%;
28
+ max-width: 800px;
29
+ padding: 20px;
30
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
31
+ position: relative;
32
+ }
33
+ #preview-close {
34
+ position: absolute;
35
+ top: 10px;
36
+ right: 10px;
37
+ background: #333;
38
+ color: white;
39
+ border: none;
40
+ border-radius: 50%;
41
+ width: 30px;
42
+ height: 30px;
43
+ cursor: pointer;
44
+ font-size: 16px;
45
+ display: flex;
46
+ justify-content: center;
47
+ align-items: center;
48
+ }
49
+ #preview-print {
50
+ margin-top: 20px;
51
+ padding: 10px 20px;
52
+ background: #007bff;
53
+ color: white;
54
+ border: none;
55
+ border-radius: 4px;
56
+ cursor: pointer;
57
+ font-size: 16px;
58
+ }
12
59
  @media print {
13
- body > :not(.print-container) {
60
+ body > :not(#print-container) {
14
61
  display: none;
15
62
  }
16
63
  html,
17
64
  body {
18
65
  display: block !important;
66
+ margin: 0;
67
+ padding: 0;
68
+ width: 100%;
69
+ height: 100%;
70
+ -webkit-print-color-adjust: ${print_background};
71
+ print-color-adjust: ${print_background};
19
72
  }
20
73
  #print-container {
21
74
  display: block;
75
+ padding: 20px;
76
+ width: 100%;
77
+ height: 100%;
78
+ box-sizing: border-box;
22
79
  }
23
- }`, n = document.createElement("style");
24
- return n.innerHTML = e, n;
80
+ }
81
+ @page {
82
+ size: ${page_size} ${page_orientation};
83
+ margin: ${margin};
84
+ }`;
85
+ const style = document.createElement("style");
86
+ style.innerHTML = custom_style || default_style;
87
+ return style;
88
+ }
89
+ function clean_print() {
90
+ const existing_container = document.getElementById("print-container");
91
+ if (existing_container) {
92
+ try {
93
+ document.body.removeChild(existing_container);
94
+ } catch (error) {
95
+ console.error("清理打印容器失败:", error);
96
+ }
97
+ }
25
98
  }
26
- function d() {
27
- let t = document.getElementById("print-container");
28
- t && document?.querySelector("body")?.removeChild(t);
99
+ function clean_preview() {
100
+ const existing_preview = document.getElementById("preview-container");
101
+ if (existing_preview) {
102
+ try {
103
+ document.body.removeChild(existing_preview);
104
+ preview_container = null;
105
+ } catch (error) {
106
+ console.error("清理预览容器失败:", error);
107
+ }
108
+ }
29
109
  }
30
- function u(t) {
31
- d();
32
- let e = document.createElement("div");
33
- return e.setAttribute("id", "print-container"), e.innerHTML = t, e;
110
+ function get_container(html_content) {
111
+ clean_print();
112
+ const container = document.createElement("div");
113
+ container.setAttribute("id", "print-container");
114
+ container.innerHTML = html_content;
115
+ return container;
34
116
  }
35
- function m(t) {
36
- let e = t.querySelectorAll("img");
37
- const n = [].slice.call(e);
38
- if (n.length === 0)
117
+ function get_load_promise(container) {
118
+ if (!container || typeof container.querySelectorAll !== "function") {
39
119
  return Promise.resolve();
40
- let i = 0;
41
- return new Promise((p) => {
42
- function r() {
43
- i++, i === n.length && p();
120
+ }
121
+ const img_elements = container.querySelectorAll("img");
122
+ const imgs = Array.from(img_elements);
123
+ if (imgs.length === 0) {
124
+ return Promise.resolve();
125
+ }
126
+ let finished_count = 0;
127
+ return new Promise((resolve, reject) => {
128
+ function check() {
129
+ finished_count++;
130
+ if (finished_count === imgs.length) {
131
+ resolve();
132
+ }
44
133
  }
45
- n.forEach((l) => {
46
- l.addEventListener("load", r), l.addEventListener("error", r);
134
+ imgs.forEach((img) => {
135
+ if (img.complete) {
136
+ check();
137
+ } else {
138
+ img.addEventListener("load", check);
139
+ img.addEventListener("error", check);
140
+ }
47
141
  });
142
+ setTimeout(() => {
143
+ reject(new Error("图片加载超时"));
144
+ }, 1e4);
48
145
  });
49
146
  }
50
- function a(t) {
51
- const e = document.querySelector(t);
52
- e && o(e.innerHTML);
147
+ async function print(html_content, options) {
148
+ if (print_in_progress) {
149
+ console.warn("打印已在进行中");
150
+ return;
151
+ }
152
+ try {
153
+ print_in_progress = true;
154
+ const style = get_style(options?.custom_style, options);
155
+ const container = get_container(html_content);
156
+ document.body.appendChild(style);
157
+ document.body.appendChild(container);
158
+ await get_load_promise(container);
159
+ window.print();
160
+ setTimeout(() => {
161
+ try {
162
+ if (style.parentNode) {
163
+ style.parentNode.removeChild(style);
164
+ }
165
+ if (container.parentNode) {
166
+ container.parentNode.removeChild(container);
167
+ }
168
+ print_in_progress = false;
169
+ options?.on_complete?.();
170
+ } catch (error) {
171
+ console.error("清理打印元素失败:", error);
172
+ options?.on_error?.(error);
173
+ }
174
+ }, 100);
175
+ } catch (error) {
176
+ console.error("打印失败:", error);
177
+ print_in_progress = false;
178
+ options?.on_error?.(error);
179
+ }
180
+ }
181
+ async function preview(html_content, options) {
182
+ try {
183
+ clean_preview();
184
+ const style = get_style(options?.custom_style, options);
185
+ const content = document.createElement("div");
186
+ content.innerHTML = html_content;
187
+ await get_load_promise(content);
188
+ const preview_wrapper = document.createElement("div");
189
+ preview_wrapper.setAttribute("id", "preview-container");
190
+ const preview_content = document.createElement("div");
191
+ preview_content.setAttribute("id", "preview-content");
192
+ preview_content.appendChild(content);
193
+ const close_button = document.createElement("button");
194
+ close_button.setAttribute("id", "preview-close");
195
+ close_button.textContent = "×";
196
+ close_button.addEventListener("click", () => {
197
+ clean_preview();
198
+ options?.on_cancel?.();
199
+ });
200
+ const print_button = document.createElement("button");
201
+ print_button.setAttribute("id", "preview-print");
202
+ print_button.textContent = "打印";
203
+ print_button.addEventListener("click", () => {
204
+ clean_preview();
205
+ print(html_content, options);
206
+ });
207
+ preview_content.appendChild(close_button);
208
+ preview_content.appendChild(print_button);
209
+ preview_wrapper.appendChild(preview_content);
210
+ document.body.appendChild(style);
211
+ document.body.appendChild(preview_wrapper);
212
+ preview_container = preview_wrapper;
213
+ } catch (error) {
214
+ console.error("预览失败:", error);
215
+ options?.on_error?.(error);
216
+ }
217
+ }
218
+ async function print_html(dom_selector, options) {
219
+ try {
220
+ const target_element = document.querySelector(dom_selector);
221
+ if (target_element) {
222
+ if (options?.preview) {
223
+ await preview(target_element.innerHTML, options);
224
+ } else {
225
+ await print(target_element.innerHTML, options);
226
+ }
227
+ } else {
228
+ throw new Error(`未找到DOM节点: ${dom_selector}`);
229
+ }
230
+ } catch (error) {
231
+ console.error("打印DOM元素失败:", error);
232
+ options?.on_error?.(error);
233
+ }
234
+ }
235
+ async function print_html_element(element_array, options) {
236
+ try {
237
+ if (!element_array || element_array.length === 0) {
238
+ throw new Error("元素数组为空");
239
+ }
240
+ let html_content = "";
241
+ for (const element of element_array) {
242
+ html_content += element.outerHTML;
243
+ }
244
+ if (!html_content) {
245
+ throw new Error("元素内容为空");
246
+ }
247
+ if (options?.preview) {
248
+ await preview(html_content, options);
249
+ } else {
250
+ await print(html_content, options);
251
+ }
252
+ } catch (error) {
253
+ console.error("打印元素数组失败:", error);
254
+ options?.on_error?.(error);
255
+ }
256
+ }
257
+ function preview_html(dom_selector, options) {
258
+ try {
259
+ const target_element = document.querySelector(dom_selector);
260
+ if (target_element) {
261
+ preview(target_element.innerHTML, options);
262
+ } else {
263
+ throw new Error(`未找到DOM节点: ${dom_selector}`);
264
+ }
265
+ } catch (error) {
266
+ console.error("预览DOM元素失败:", error);
267
+ options?.on_error?.(error);
268
+ }
269
+ }
270
+ function preview_html_element(element_array, options) {
271
+ try {
272
+ if (!element_array || element_array.length === 0) {
273
+ throw new Error("元素数组为空");
274
+ }
275
+ let html_content = "";
276
+ for (const element of element_array) {
277
+ html_content += element.outerHTML;
278
+ }
279
+ if (!html_content) {
280
+ throw new Error("元素内容为空");
281
+ }
282
+ preview(html_content, options);
283
+ } catch (error) {
284
+ console.error("预览元素数组失败:", error);
285
+ options?.on_error?.(error);
286
+ }
53
287
  }
54
- function s(t) {
55
- let e = "";
56
- for (let n = 0; n < t.length; n++)
57
- e += t[n].outerHTML;
58
- e && o(e);
288
+ function close_preview() {
289
+ clean_preview();
59
290
  }
60
291
  return {
61
- printHtml: a,
62
- printHtmlElement: s
292
+ print_html,
293
+ print_html_element,
294
+ preview_html,
295
+ preview_html_element,
296
+ close_preview
63
297
  };
64
298
  }
65
299
  export {
66
- y as usePrintHtml
300
+ use_print
67
301
  };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * 打印选项
3
+ */
4
+ export interface PrintOptions {
5
+ /** 自定义打印样式 */
6
+ custom_style?: string;
7
+ /** 打印完成后的回调 */
8
+ on_complete?: () => void;
9
+ /** 打印失败的回调 */
10
+ on_error?: (error: Error) => void;
11
+ /** 打印取消的回调 */
12
+ on_cancel?: () => void;
13
+ /** 页面大小 */
14
+ page_size?: 'A4' | 'A3' | 'Letter' | 'Legal' | string;
15
+ /** 页面方向 */
16
+ page_orientation?: 'portrait' | 'landscape';
17
+ /** 页面边距 */
18
+ margin?: string;
19
+ /** 是否打印背景色 */
20
+ print_background?: boolean;
21
+ /** 预览模式 */
22
+ preview?: boolean;
23
+ /** 预览容器选择器 */
24
+ preview_container?: string;
25
+ }
26
+ /**
27
+ * 打印钩子返回类型
28
+ */
29
+ export interface UsePrintReturn {
30
+ /**
31
+ * 打印指定DOM选择器的内容
32
+ * @param dom_node DOM节点选择器
33
+ * @param options 打印选项
34
+ */
35
+ print_html: (dom_node: string, options?: PrintOptions) => void;
36
+ /**
37
+ * 打印多个DOM元素
38
+ * @param element_array DOM元素数组
39
+ * @param options 打印选项
40
+ */
41
+ print_html_element: (element_array: Element[], options?: PrintOptions) => void;
42
+ /**
43
+ * 预览指定DOM选择器的内容
44
+ * @param dom_node DOM节点选择器
45
+ * @param options 打印选项
46
+ */
47
+ preview_html: (dom_node: string, options?: PrintOptions) => void;
48
+ /**
49
+ * 预览多个DOM元素
50
+ * @param element_array DOM元素数组
51
+ * @param options 打印选项
52
+ */
53
+ preview_html_element: (element_array: Element[], options?: PrintOptions) => void;
54
+ /**
55
+ * 关闭预览
56
+ */
57
+ close_preview: () => void;
58
+ }
@@ -0,0 +1,7 @@
1
+ import { UseWaterMark } from './type';
2
+ /**
3
+ * 水印功能钩子
4
+ * @returns 水印操作方法
5
+ * @description 适用于需要在前端添加水印的场景,支持创建、移除、更新水印
6
+ */
7
+ export declare function use_water_mark(): UseWaterMark;
@@ -0,0 +1,134 @@
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";
5
+ function use_water_mark() {
6
+ const id = generate_guid();
7
+ let current_options = null;
8
+ let resize_handler = null;
9
+ function get_wrapper(wrapper) {
10
+ return wrapper ? get_element(wrapper) || document.body : document.body;
11
+ }
12
+ function create_watermark_canvas(options) {
13
+ const { text1, text2, font_size = 16, font_family = "Avenir,Helvetica,Arial,sans-serif", rotate = -15, text_color = "#999", opacity = 0.1, size = { width: 250, height: 150 } } = options;
14
+ try {
15
+ const canvas = document.createElement("canvas");
16
+ canvas.width = size.width;
17
+ canvas.height = size.height;
18
+ const ctx = canvas.getContext("2d");
19
+ if (ctx) {
20
+ ctx.font = `${font_size}px ${font_family}`;
21
+ ctx.fillStyle = text_color.replace(/\,\s(1|(0\.\d+)\))/, `, ${opacity}`);
22
+ ctx.textAlign = "left";
23
+ ctx.textBaseline = "middle";
24
+ ctx.rotate(rotate * Math.PI / 180);
25
+ ctx.fillText(text1, 0, canvas.height / 2);
26
+ if (text2) {
27
+ const text1_width = ctx.measureText(text1).width;
28
+ ctx.fillText(text2, text1_width + 16, canvas.height / 2);
29
+ }
30
+ }
31
+ return canvas;
32
+ } catch (error) {
33
+ console.error("创建水印画布失败:", error);
34
+ const canvas = document.createElement("canvas");
35
+ canvas.width = 0;
36
+ canvas.height = 0;
37
+ return canvas;
38
+ }
39
+ }
40
+ function create_watermark_element(options) {
41
+ const {
42
+ wrapper,
43
+ z_index = 1e5,
44
+ position = "fixed",
45
+ spacing = 0,
46
+ size = { width: 250, height: 150 }
47
+ } = options;
48
+ const wrapper_element = get_wrapper(wrapper);
49
+ const existing_element = document.getElementById(id);
50
+ if (existing_element) {
51
+ try {
52
+ wrapper_element.removeChild(existing_element);
53
+ } catch (error) {
54
+ console.error("移除旧水印失败:", error);
55
+ }
56
+ }
57
+ const canvas = create_watermark_canvas(options);
58
+ const div = document.createElement("div");
59
+ div.id = id;
60
+ div.style.pointerEvents = "none";
61
+ div.style.top = "0px";
62
+ div.style.left = "0px";
63
+ div.style.position = position;
64
+ div.style.zIndex = z_index.toString();
65
+ const window_size = get_window_size();
66
+ div.style.width = window_size.width + "px";
67
+ div.style.height = window_size.height + "px";
68
+ div.style.background = `url(${canvas.toDataURL("image/png")}) left top repeat`;
69
+ if (spacing > 0) {
70
+ div.style.backgroundSize = `${size.width + spacing}px ${size.height + spacing}px`;
71
+ }
72
+ try {
73
+ wrapper_element.appendChild(div);
74
+ } catch (error) {
75
+ console.error("添加水印失败:", error);
76
+ }
77
+ }
78
+ function handle_resize() {
79
+ if (current_options) {
80
+ create_watermark_element(current_options);
81
+ }
82
+ }
83
+ function create_water_mark(options) {
84
+ current_options = options;
85
+ create_watermark_element(options);
86
+ if (options.responsive) {
87
+ if (!resize_handler) {
88
+ resize_handler = handle_resize;
89
+ on(window, "resize", resize_handler);
90
+ }
91
+ } else if (resize_handler) {
92
+ off(window, "resize", resize_handler);
93
+ resize_handler = null;
94
+ }
95
+ }
96
+ function remove_water_mark() {
97
+ const existing_element = document.getElementById(id);
98
+ if (existing_element) {
99
+ try {
100
+ const parent = existing_element.parentElement;
101
+ if (parent) {
102
+ parent.removeChild(existing_element);
103
+ }
104
+ } catch (error) {
105
+ console.error("移除水印失败:", error);
106
+ }
107
+ }
108
+ if (resize_handler) {
109
+ off(window, "resize", resize_handler);
110
+ resize_handler = null;
111
+ }
112
+ current_options = null;
113
+ }
114
+ function update_water_mark(options) {
115
+ if (current_options) {
116
+ const new_options = { ...current_options, ...options };
117
+ create_water_mark(new_options);
118
+ } else {
119
+ console.warn("水印未初始化,请先调用 create_water_mark");
120
+ }
121
+ }
122
+ function has_water_mark() {
123
+ return document.getElementById(id) !== null;
124
+ }
125
+ return {
126
+ create_water_mark,
127
+ remove_water_mark,
128
+ update_water_mark,
129
+ has_water_mark
130
+ };
131
+ }
132
+ export {
133
+ use_water_mark
134
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 水印配置选项
3
+ */
4
+ export interface WaterMarkOptions {
5
+ /** 水印容器选择器 */
6
+ wrapper?: string | null;
7
+ /** 主标题 */
8
+ text1: string;
9
+ /** 副标题 */
10
+ text2?: string;
11
+ /** 文字颜色 */
12
+ text_color?: string;
13
+ /** 文字大小 */
14
+ font_size?: number;
15
+ /** 文字字体 */
16
+ font_family?: string;
17
+ /** 旋转角度 */
18
+ rotate?: number;
19
+ /** 透明度 */
20
+ opacity?: number;
21
+ /** 水印间距 */
22
+ spacing?: number;
23
+ /** 水印大小 */
24
+ size?: {
25
+ width: number;
26
+ height: number;
27
+ };
28
+ /** 层级 */
29
+ z_index?: number;
30
+ /** 定位方式 */
31
+ position?: 'fixed' | 'absolute' | 'relative';
32
+ /** 是否响应式 */
33
+ responsive?: boolean;
34
+ }
35
+ /**
36
+ * 水印钩子返回类型
37
+ */
38
+ export interface UseWaterMark {
39
+ /**
40
+ * 创建水印
41
+ */
42
+ create_water_mark: (options: WaterMarkOptions) => void;
43
+ /**
44
+ * 移除水印
45
+ */
46
+ remove_water_mark: () => void;
47
+ /**
48
+ * 更新水印
49
+ */
50
+ update_water_mark: (options: Partial<WaterMarkOptions>) => void;
51
+ /**
52
+ * 检查水印是否存在
53
+ */
54
+ has_water_mark: () => boolean;
55
+ }
@@ -1,15 +1,8 @@
1
- export type WebSocketOption = {
2
- /**服务端地址 */
3
- server: string;
4
- /**消息接收处理方法 */
5
- receive: (res: any) => void;
6
- };
1
+ import { WebSocketOptions, UseWebSocketReturn } from './type';
7
2
  /**
8
- * WebSocket
3
+ * WebSocket钩子
4
+ * @param options WebSocket配置选项
5
+ * @returns WebSocket操作方法和状态
6
+ * @description 适用于需要在前端实现WebSocket通信的场景,支持自动重连、心跳检测、消息队列等功能
9
7
  */
10
- export declare function useWebSocket(option: WebSocketOption): {
11
- ws: undefined;
12
- create: () => void;
13
- socketClose: () => void;
14
- sendMessage: (msg: any) => void;
15
- };
8
+ export declare function use_web_socket(options: WebSocketOptions): UseWebSocketReturn;