@qy_better_lib/hooks 0.0.2 → 0.0.4
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/dist/@qy_better_lib/hooks.min.js +15 -1
- package/lib/node_modules/mitt/dist/mitt.js +19 -0
- package/lib/src/index.js +33 -0
- package/lib/src/use-emit/index.js +19 -0
- package/lib/src/use-file/index.js +18 -0
- package/lib/src/use-print/index.js +68 -0
- package/lib/src/use-waterMark/index.js +30 -0
- package/lib/src/use-websocket/index.js +54 -0
- package/lib/use-emit/index.d.ts +1 -1
- package/lib/use-file/index.d.ts +1 -1
- package/lib/use-print/index.d.ts +1 -1
- package/lib/use-waterMark/index.d.ts +1 -1
- package/lib/use-websocket/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/use-emit/index.ts +1 -10
- package/src/use-file/index.ts +1 -1
- package/src/use-print/index.ts +1 -1
- package/src/use-waterMark/index.ts +1 -1
- package/src/use-websocket/index.ts +1 -1
- package/lib/index.js +0 -24
- /package/lib/{use-image → src/use-image}/canvastoDataURL.js +0 -0
- /package/lib/{use-image → src/use-image}/canvastoFile.js +0 -0
- /package/lib/{use-image → src/use-image}/dataURLtoFile.js +0 -0
- /package/lib/{use-image → src/use-image}/dataURLtoImage.js +0 -0
- /package/lib/{use-image → src/use-image}/downloadFile.js +0 -0
- /package/lib/{use-image → src/use-image}/filetoDataURL.js +0 -0
- /package/lib/{use-image → src/use-image}/imagetoCanvas.js +0 -0
- /package/lib/{use-image → src/use-image}/index.js +0 -0
- /package/lib/{use-image → src/use-image}/type.js +0 -0
- /package/lib/{use-image → src/use-image}/urltoBlob.js +0 -0
- /package/lib/{use-image → src/use-image}/urltoImage.js +0 -0
|
@@ -1 +1,15 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],b):(u=typeof globalThis<"u"?globalThis:u||self,b(u["@qy_better_lib/hooks"]={},u.Vue))})(this,function(u,b){"use strict";function M(t){return{all:t=t||new Map,on:function(n,a){var e=t.get(n);e?e.push(a):t.set(n,[a])},off:function(n,a){var e=t.get(n);e&&(a?e.splice(e.indexOf(a)>>>0,1):t.set(n,[]))},emit:function(n,a){var e=t.get(n);e&&e.slice().map(function(o){o(a)}),(e=t.get("*"))&&e.slice().map(function(o){o(n,a)})}}}const g=M();function R(t){return b.onMounted(()=>{if(t&&t.length>0)for(let n=0;n<t.length;n++)g.on(t[n].key,t[n].value)}),b.onUnmounted(()=>{if(t&&t.length>0)for(let n=0;n<t.length;n++)g.off(t[n].key,t[n].value),g.all.delete(t[n].key)}),{emitter:g}}function U(){function t(a){window.open(a)}function n(a){a.forEach(e=>{const o=document.createElement("a");o.href=e.url,o.target="_blank",o.setAttribute("download",e.name),document.body.appendChild(o),o.click(),document.body.removeChild(o)})}return{downLoadFile:t,downLoadFiles:n}}function F(){function t(r){let i=n(),c=e(r);document.body.appendChild(i),document.body.appendChild(c),o(c).then(()=>{window.print(),document.body.removeChild(i),document.body.removeChild(c)})}function n(r){let i=`#print-container {
|
|
2
|
+
display: none;
|
|
3
|
+
}
|
|
4
|
+
@media print {
|
|
5
|
+
body > :not(.print-container) {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
html,
|
|
9
|
+
body {
|
|
10
|
+
display: block !important;
|
|
11
|
+
}
|
|
12
|
+
#print-container {
|
|
13
|
+
display: block;
|
|
14
|
+
}
|
|
15
|
+
}`,c=document.createElement("style");return c.innerHTML=i,c}function a(){var i;let r=document.getElementById("print-container");r&&((i=document==null?void 0:document.querySelector("body"))==null||i.removeChild(r))}function e(r){a();let i=document.createElement("div");return i.setAttribute("id","print-container"),i.innerHTML=r,i}function o(r){let i=r.querySelectorAll("img");const c=[].slice.call(i);if(c.length===0)return Promise.resolve();let m=0;return new Promise(h=>{function l(){m++,m===c.length&&h()}c.forEach(f=>{f.addEventListener("load",l),f.addEventListener("error",l)})})}function s(r){const i=document.querySelector(r);i&&t(i.innerHTML)}function d(r){let i="";for(let c=0;c<r.length;c++)i+=r[c].outerHTML;i&&t(i)}return{printHtml:s,printHtmlElement:d}}function S(){const t="A77B030B-E33D-C656-7642-56D6FEA46059";function n(o=null,s,d,r){let i=e(o,s,d,r);document.getElementById(i)===null&&(i=e(o,s,d))}function a(){const o=document.getElementById(t);o==null||o.remove()}function e(o=null,s,d,r="#999"){const i=o!=null?document.querySelector(o):document.body,c=document.getElementById(t);c!==null&&(i==null||i.removeChild(c));let m=document.createElement("canvas");m.width=250,m.height=150;let h=m.getContext("2d");h&&(h.font="16px Avenir,Helvetica,Arial,sans-serif",h.fillStyle=r.replace(/\,\s(1|(0.\d+)\))/,", 0.1"),h.textAlign="left",h.textBaseline="middle",h.rotate(-15*Math.PI/180),h==null||h.fillText(s,0,m.height),d&&(h==null||h.fillText(d,h.measureText(s).width+16,m.height)));let l=document.createElement("div");l.id=t,l.style.pointerEvents="none",l.style.top="0px",l.style.left="0px",l.style.position="fixed",l.style.zIndex="100000";const{clientWidth:f,clientHeight:y}=document.documentElement;return l.style.width=f+"px",l.style.height=y+"px",l.style.background="url("+m.toDataURL("image/png")+") left top repeat",i==null||i.appendChild(l),t}return{createWaterMark:n,removeWatermark:a}}function j(t){let n=0,a=!1,e,o;const{server:s,receive:d}=t;window.onbeforeunload=()=>{e==null||e.close()};function r(){try{e=new WebSocket(s),c()}catch(l){console.log("连接建立异常",l)}}function i(){if(n>=5){e==null||e.close();return}if(a)return!1;a=!0,o=setTimeout(function(){r(),a=!1,n++,o&&clearTimeout(o)},5e3)}function c(){e&&(e.onerror=l=>{console.log("连接错误",l),i()},e.onclose=()=>{console.log("连接关闭 - "+new Date().toLocaleTimeString()),i()},e.onopen=()=>{n=0,console.log("连接成功")},e.onmessage=l=>{try{d(l)}catch{console.log("message:"+l.data)}})}function m(l){(e==null?void 0:e.readyState)===WebSocket.OPEN&&(e==null||e.send(l))}function h(){e==null||e.close()}return{ws:e,create:r,socketClose:h,sendMessage:m}}var w=(t=>(t.PNG="image/png",t.JPEG="image/jpeg",t.GIF="image/gif",t))(w||{});function p(t){return["image/png","image/jpeg","image/gif"].some(n=>n===t)}async function k(t,n=.92,a=w.JPEG){return p(a)||(a=w.JPEG),t.toDataURL(a,n)}function z(t,n=.92,a=w.JPEG){return new Promise(e=>t.toBlob(o=>e(o),a,n))}async function E(t,n){var r;const a=t.split(",");let e=(r=a[0].match(/:(.*?);/))==null?void 0:r[1];const o=atob(a[1]);let s=o.length;const d=new Uint8Array(s);for(;s--;)d[s]=o.charCodeAt(s);return p(n)&&(e=n),new Blob([d],{type:e})}function L(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>n(e),e.onerror=()=>a(new Error("dataURLtoImage(): dataURL is illegal")),e.src=t})}function B(t,n){const a=document.createElement("a");a.href=window.URL.createObjectURL(t),a.download=n||Date.now().toString(36),document.body.appendChild(a);const e=document.createEvent("MouseEvents");e.initEvent("click",!1,!1),a.dispatchEvent(e),document.body.removeChild(a)}function I(t){return new Promise(n=>{const a=new FileReader;a.onloadend=e=>{var o;return n((o=e.target)==null?void 0:o.result)},a.readAsDataURL(t)})}async function P(t,n={}){const a={...n},e=document.createElement("canvas"),o=e.getContext("2d");let s,d;for(const r in a)Object.prototype.hasOwnProperty.call(a,r)&&(a[r]=Number(a[r]));if(!a.scale)d=a.width||(a.height||0)*t.width/t.height||t.width,s=a.height||(a.width||0)*t.height/t.width||t.height;else{const r=a.scale>0&&a.scale<10?a.scale:1;d=t.width*r,s=t.height*r}switch([5,6,7,8].some(r=>r===a.orientation)?(e.height=d,e.width=s):(e.height=s,e.width=d),a.orientation){case 3:o.rotate(180*Math.PI/180),o.drawImage(t,-e.width,-e.height,e.width,e.height);break;case 6:o.rotate(90*Math.PI/180),o.drawImage(t,0,-e.width,e.height,e.width);break;case 8:o.rotate(270*Math.PI/180),o.drawImage(t,-e.height,0,e.height,e.width);break;case 2:o.translate(e.width,0),o.scale(-1,1),o.drawImage(t,0,0,e.width,e.height);break;case 4:o.translate(e.width,0),o.scale(-1,1),o.rotate(180*Math.PI/180),o.drawImage(t,-e.width,-e.height,e.width,e.height);break;case 5:o.translate(e.width,0),o.scale(-1,1),o.rotate(90*Math.PI/180),o.drawImage(t,0,-e.width,e.height,e.width);break;case 7:o.translate(e.width,0),o.scale(-1,1),o.rotate(270*Math.PI/180),o.drawImage(t,-e.height,0,e.height,e.width);break;default:o.drawImage(t,0,0,e.width,e.height)}return e}function D(t){return fetch(t).then(n=>n.blob())}function A(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>n(e),e.onerror=()=>a(new Error("urltoImage(): Image failed to load, please check the image URL")),e.src=t})}async function T(t,n={}){var c;if(!(t instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if(typeof n!="object"&&(n=Object.assign({quality:n})),n.quality=Number(n.quality),Number.isNaN(n.quality))return t;const a=await I(t);let e=(c=a.split(",")[0].match(/:(.*?);/))==null?void 0:c[1],o=w.JPEG;p(n.type)&&(o=n.type,e=n.type);const s=await L(a),d=await P(s,Object.assign({},n)),r=await k(d,n.quality,o),i=await E(r,e);return i.size>t.size?t:i}async function N(t,n={}){var f;if(!(t instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if(typeof n!="object"&&(n=Object.assign({size:n})),n.size=Number(n.size),Number.isNaN(n.size)||n.size*1024>t.size)return t;n.accuracy=Number(n.accuracy),(!n.accuracy||n.accuracy<.8||n.accuracy>.99)&&(n.accuracy=.95);const a={max:n.size*(2-n.accuracy)*1024,accurate:n.size*1024,min:n.size*n.accuracy*1024},e=await I(t);let o=(f=e.split(",")[0].match(/:(.*?);/))==null?void 0:f[1],s=w.JPEG;p(n.type)&&(s=n.type,o=n.type);const d=await L(e),r=await P(d,Object.assign({},n)),i=.75;let c=1,m;const h=new Array(2);for(let y=1;y<=7;y++){m=await k(r,c,s);const v=m.length*i;if(y===7){(a.max<v||a.min>v)&&(m=[m,...h].filter(C=>C).sort((C,q)=>Math.abs(C.length*i-a.accurate)-Math.abs(q.length*i-a.accurate))[0]);break}if(a.max<v)h[1]=m,c-=.5**(y+1);else if(a.min>v)h[0]=m,c+=.5**(y+1);else break}const l=await E(m,o);return l.size>t.size?t:l}u.canvastoDataURL=k,u.canvastoFile=z,u.compress=T,u.compressAccurately=N,u.dataURLtoFile=E,u.dataURLtoImage=L,u.downloadFile=B,u.filetoDataURL=I,u.imagetoCanvas=P,u.urltoBlob=D,u.urltoImage=A,u.useEitter=R,u.useFile=U,u.usePrintHtml=F,u.useWaterMark=S,u.useWebSocket=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function c(t) {
|
|
2
|
+
return { all: t = t || /* @__PURE__ */ new Map(), on: function(e, f) {
|
|
3
|
+
var i = t.get(e);
|
|
4
|
+
i ? i.push(f) : t.set(e, [f]);
|
|
5
|
+
}, off: function(e, f) {
|
|
6
|
+
var i = t.get(e);
|
|
7
|
+
i && (f ? i.splice(i.indexOf(f) >>> 0, 1) : t.set(e, []));
|
|
8
|
+
}, emit: function(e, f) {
|
|
9
|
+
var i = t.get(e);
|
|
10
|
+
i && i.slice().map(function(a) {
|
|
11
|
+
a(f);
|
|
12
|
+
}), (i = t.get("*")) && i.slice().map(function(a) {
|
|
13
|
+
a(e, f);
|
|
14
|
+
});
|
|
15
|
+
} };
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
c as default
|
|
19
|
+
};
|
package/lib/src/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEitter as t } from "./use-emit/index.js";
|
|
2
|
+
import { useFile as r } from "./use-file/index.js";
|
|
3
|
+
import { usePrintHtml as m } from "./use-print/index.js";
|
|
4
|
+
import { useWaterMark as l } from "./use-waterMark/index.js";
|
|
5
|
+
import { useWebSocket as u } from "./use-websocket/index.js";
|
|
6
|
+
import { compress as d, compressAccurately as i } from "./use-image/index.js";
|
|
7
|
+
import { default as n } from "./use-image/canvastoDataURL.js";
|
|
8
|
+
import { default as L } from "./use-image/canvastoFile.js";
|
|
9
|
+
import { default as U } from "./use-image/dataURLtoFile.js";
|
|
10
|
+
import { default as v } from "./use-image/dataURLtoImage.js";
|
|
11
|
+
import { default as k } from "./use-image/downloadFile.js";
|
|
12
|
+
import { default as I } from "./use-image/filetoDataURL.js";
|
|
13
|
+
import { default as w } from "./use-image/imagetoCanvas.js";
|
|
14
|
+
import { default as A } from "./use-image/urltoBlob.js";
|
|
15
|
+
import { default as C } from "./use-image/urltoImage.js";
|
|
16
|
+
export {
|
|
17
|
+
n as canvastoDataURL,
|
|
18
|
+
L as canvastoFile,
|
|
19
|
+
d as compress,
|
|
20
|
+
i as compressAccurately,
|
|
21
|
+
U as dataURLtoFile,
|
|
22
|
+
v as dataURLtoImage,
|
|
23
|
+
k as downloadFile,
|
|
24
|
+
I as filetoDataURL,
|
|
25
|
+
w as imagetoCanvas,
|
|
26
|
+
A as urltoBlob,
|
|
27
|
+
C as urltoImage,
|
|
28
|
+
t as useEitter,
|
|
29
|
+
r as useFile,
|
|
30
|
+
m as usePrintHtml,
|
|
31
|
+
l as useWaterMark,
|
|
32
|
+
u as useWebSocket
|
|
33
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import m from "../../node_modules/mitt/dist/mitt.js";
|
|
2
|
+
import { onMounted as u, onUnmounted as g } from "vue";
|
|
3
|
+
const f = m();
|
|
4
|
+
function a(o) {
|
|
5
|
+
return u(() => {
|
|
6
|
+
if (o && o.length > 0)
|
|
7
|
+
for (let r = 0; r < o.length; r++)
|
|
8
|
+
f.on(o[r].key, o[r].value);
|
|
9
|
+
}), g(() => {
|
|
10
|
+
if (o && o.length > 0)
|
|
11
|
+
for (let r = 0; r < o.length; r++)
|
|
12
|
+
f.off(o[r].key, o[r].value), f.all.delete(o[r].key);
|
|
13
|
+
}), {
|
|
14
|
+
emitter: f
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
a as useEitter
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function c() {
|
|
2
|
+
function t(n) {
|
|
3
|
+
window.open(n);
|
|
4
|
+
}
|
|
5
|
+
function d(n) {
|
|
6
|
+
n.forEach((o) => {
|
|
7
|
+
const e = document.createElement("a");
|
|
8
|
+
e.href = o.url, e.target = "_blank", e.setAttribute("download", o.name), document.body.appendChild(e), e.click(), document.body.removeChild(e);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
downLoadFile: t,
|
|
13
|
+
downLoadFiles: d
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
c as useFile
|
|
18
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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 {
|
|
10
|
+
display: none;
|
|
11
|
+
}
|
|
12
|
+
@media print {
|
|
13
|
+
body > :not(.print-container) {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
html,
|
|
17
|
+
body {
|
|
18
|
+
display: block !important;
|
|
19
|
+
}
|
|
20
|
+
#print-container {
|
|
21
|
+
display: block;
|
|
22
|
+
}
|
|
23
|
+
}`, n = document.createElement("style");
|
|
24
|
+
return n.innerHTML = e, n;
|
|
25
|
+
}
|
|
26
|
+
function d() {
|
|
27
|
+
var e;
|
|
28
|
+
let t = document.getElementById("print-container");
|
|
29
|
+
t && ((e = document == null ? void 0 : document.querySelector("body")) == null || e.removeChild(t));
|
|
30
|
+
}
|
|
31
|
+
function u(t) {
|
|
32
|
+
d();
|
|
33
|
+
let e = document.createElement("div");
|
|
34
|
+
return e.setAttribute("id", "print-container"), e.innerHTML = t, e;
|
|
35
|
+
}
|
|
36
|
+
function m(t) {
|
|
37
|
+
let e = t.querySelectorAll("img");
|
|
38
|
+
const n = [].slice.call(e);
|
|
39
|
+
if (n.length === 0)
|
|
40
|
+
return Promise.resolve();
|
|
41
|
+
let i = 0;
|
|
42
|
+
return new Promise((p) => {
|
|
43
|
+
function r() {
|
|
44
|
+
i++, i === n.length && p();
|
|
45
|
+
}
|
|
46
|
+
n.forEach((l) => {
|
|
47
|
+
l.addEventListener("load", r), l.addEventListener("error", r);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function a(t) {
|
|
52
|
+
const e = document.querySelector(t);
|
|
53
|
+
e && o(e.innerHTML);
|
|
54
|
+
}
|
|
55
|
+
function s(t) {
|
|
56
|
+
let e = "";
|
|
57
|
+
for (let n = 0; n < t.length; n++)
|
|
58
|
+
e += t[n].outerHTML;
|
|
59
|
+
e && o(e);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
printHtml: a,
|
|
63
|
+
printHtmlElement: s
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
y as usePrintHtml
|
|
68
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function x() {
|
|
2
|
+
const c = "A77B030B-E33D-C656-7642-56D6FEA46059";
|
|
3
|
+
function s(n = null, o, d, u) {
|
|
4
|
+
let l = a(n, o, d, u);
|
|
5
|
+
document.getElementById(l) === null && (l = a(n, o, d));
|
|
6
|
+
}
|
|
7
|
+
function r() {
|
|
8
|
+
const n = document.getElementById(c);
|
|
9
|
+
n == null || n.remove();
|
|
10
|
+
}
|
|
11
|
+
function a(n = null, o, d, u = "#999") {
|
|
12
|
+
const l = n != null ? document.querySelector(n) : document.body, m = document.getElementById(c);
|
|
13
|
+
m !== null && (l == null || l.removeChild(m));
|
|
14
|
+
let i = document.createElement("canvas");
|
|
15
|
+
i.width = 250, i.height = 150;
|
|
16
|
+
let e = i.getContext("2d");
|
|
17
|
+
e && (e.font = "16px Avenir,Helvetica,Arial,sans-serif", e.fillStyle = u.replace(/\,\s(1|(0.\d+)\))/, ", 0.1"), e.textAlign = "left", e.textBaseline = "middle", e.rotate(-15 * Math.PI / 180), e == null || e.fillText(o, 0, i.height), d && (e == null || e.fillText(d, e.measureText(o).width + 16, i.height)));
|
|
18
|
+
let t = document.createElement("div");
|
|
19
|
+
t.id = c, t.style.pointerEvents = "none", t.style.top = "0px", t.style.left = "0px", t.style.position = "fixed", t.style.zIndex = "100000";
|
|
20
|
+
const { clientWidth: f, clientHeight: h } = document.documentElement;
|
|
21
|
+
return t.style.width = f + "px", t.style.height = h + "px", t.style.background = "url(" + i.toDataURL("image/png") + ") left top repeat", l == null || l.appendChild(t), c;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
createWaterMark: s,
|
|
25
|
+
removeWatermark: r
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
x as useWaterMark
|
|
30
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function d(i) {
|
|
2
|
+
let n = 0, t = !1, e, c;
|
|
3
|
+
const { server: a, receive: s } = i;
|
|
4
|
+
window.onbeforeunload = () => {
|
|
5
|
+
e == null || e.close();
|
|
6
|
+
};
|
|
7
|
+
function l() {
|
|
8
|
+
try {
|
|
9
|
+
e = new WebSocket(a), u();
|
|
10
|
+
} catch (o) {
|
|
11
|
+
console.log("连接建立异常", o);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function r() {
|
|
15
|
+
if (n >= 5) {
|
|
16
|
+
e == null || e.close();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (t) return !1;
|
|
20
|
+
t = !0, c = setTimeout(function() {
|
|
21
|
+
l(), t = !1, n++, c && clearTimeout(c);
|
|
22
|
+
}, 5e3);
|
|
23
|
+
}
|
|
24
|
+
function u() {
|
|
25
|
+
e && (e.onerror = (o) => {
|
|
26
|
+
console.log("连接错误", o), r();
|
|
27
|
+
}, e.onclose = () => {
|
|
28
|
+
console.log("连接关闭 - " + (/* @__PURE__ */ new Date()).toLocaleTimeString()), r();
|
|
29
|
+
}, e.onopen = () => {
|
|
30
|
+
n = 0, console.log("连接成功");
|
|
31
|
+
}, e.onmessage = (o) => {
|
|
32
|
+
try {
|
|
33
|
+
s(o);
|
|
34
|
+
} catch {
|
|
35
|
+
console.log("message:" + o.data);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function f(o) {
|
|
40
|
+
(e == null ? void 0 : e.readyState) === WebSocket.OPEN && (e == null || e.send(o));
|
|
41
|
+
}
|
|
42
|
+
function g() {
|
|
43
|
+
e == null || e.close();
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
ws: e,
|
|
47
|
+
create: l,
|
|
48
|
+
socketClose: g,
|
|
49
|
+
sendMessage: f
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
d as useWebSocket
|
|
54
|
+
};
|
package/lib/use-emit/index.d.ts
CHANGED
package/lib/use-file/index.d.ts
CHANGED
package/lib/use-print/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qy_better_lib/hooks",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "qy better lib hooks",
|
|
6
6
|
"author": "luhuiming",
|
|
7
7
|
"license": "ISC",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lib/index.js": [
|
|
19
19
|
"lib/index.d.ts"
|
|
20
20
|
],
|
|
21
|
-
"@qy-better-lib/
|
|
21
|
+
"@qy-better-lib/hooks": [
|
|
22
22
|
"lib/index.d.ts"
|
|
23
23
|
],
|
|
24
24
|
"*": [
|
package/src/use-emit/index.ts
CHANGED
|
@@ -12,16 +12,7 @@ type event = { key: string; value: (obj?: any) => void };
|
|
|
12
12
|
|
|
13
13
|
const emitter: Emitter<Record<EventType, unknown>> = mitt();
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
emitter.emit = (type: string, evt?: any): any => {
|
|
17
|
-
let handlers = emitter.all!.get(type);
|
|
18
|
-
if (handlers) {
|
|
19
|
-
return handlers[0]?.(evt!, undefined) as any;
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default function useEitter(eventlist?: Array<event>): UseEitter {
|
|
15
|
+
export function useEitter(eventlist?: Array<event>): UseEitter {
|
|
25
16
|
onMounted((): void => {
|
|
26
17
|
if (eventlist && eventlist.length > 0) {
|
|
27
18
|
for (let i = 0; i < eventlist.length; i++) {
|
package/src/use-file/index.ts
CHANGED
package/src/use-print/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ type UseWaterMark = {
|
|
|
18
18
|
* 水印功能
|
|
19
19
|
* ==============================================
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export function useWaterMark(): UseWaterMark {
|
|
22
22
|
const id: string = "A77B030B-E33D-C656-7642-56D6FEA46059";
|
|
23
23
|
|
|
24
24
|
/**
|
package/lib/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import "vue";
|
|
2
|
-
import { compress as e, compressAccurately as r } from "./use-image/index.js";
|
|
3
|
-
import { default as l } from "./use-image/canvastoDataURL.js";
|
|
4
|
-
import { default as s } from "./use-image/canvastoFile.js";
|
|
5
|
-
import { default as p } from "./use-image/dataURLtoFile.js";
|
|
6
|
-
import { default as x } from "./use-image/dataURLtoImage.js";
|
|
7
|
-
import { default as i } from "./use-image/downloadFile.js";
|
|
8
|
-
import { default as L } from "./use-image/filetoDataURL.js";
|
|
9
|
-
import { default as U } from "./use-image/imagetoCanvas.js";
|
|
10
|
-
import { default as v } from "./use-image/urltoBlob.js";
|
|
11
|
-
import { default as D } from "./use-image/urltoImage.js";
|
|
12
|
-
export {
|
|
13
|
-
l as canvastoDataURL,
|
|
14
|
-
s as canvastoFile,
|
|
15
|
-
e as compress,
|
|
16
|
-
r as compressAccurately,
|
|
17
|
-
p as dataURLtoFile,
|
|
18
|
-
x as dataURLtoImage,
|
|
19
|
-
i as downloadFile,
|
|
20
|
-
L as filetoDataURL,
|
|
21
|
-
U as imagetoCanvas,
|
|
22
|
-
v as urltoBlob,
|
|
23
|
-
D as urltoImage
|
|
24
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|