@qy_better_lib/hooks 0.0.7 → 0.0.8
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,4 +1,4 @@
|
|
|
1
|
-
(function(u,
|
|
1
|
+
(function(u,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("mitt"),require("vue")):typeof define=="function"&&define.amd?define(["exports","mitt","vue"],g):(u=typeof globalThis<"u"?globalThis:u||self,g(u["@qy_better_lib/hooks"]={},u.mitt,u.Vue))})(this,function(u,g,R){"use strict";const b=g();b.emit=(t,n)=>{const a=b.all.get(t),e=a==null?void 0:a.slice()[0];return e==null?void 0:e(t,n)};function U(t){return R.onMounted(()=>{if(t&&t.length>0)for(let n=0;n<t.length;n++)b.on(t[n].key,t[n].value)}),R.onUnmounted(()=>{if(t&&t.length>0)for(let n=0;n<t.length;n++)b.off(t[n].key,t[n].value),b.all.delete(t[n].key)}),{emitter:b}}function M(){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
2
|
display: none;
|
|
3
3
|
}
|
|
4
4
|
@media print {
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
#print-container {
|
|
13
13
|
display: block;
|
|
14
14
|
}
|
|
15
|
-
}`,c=document.createElement("style");return c.innerHTML=i,c}function
|
|
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 v(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 v(d,n.quality,o),i=await E(r,e);return i.size>t.size?t:i}async function q(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 v(r,c,s);const k=m.length*i;if(y===7){(a.max<k||a.min>k)&&(m=[m,...h].filter(C=>C).sort((C,N)=>Math.abs(C.length*i-a.accurate)-Math.abs(N.length*i-a.accurate))[0]);break}if(a.max<k)h[1]=m,c-=.5**(y+1);else if(a.min>k)h[0]=m,c+=.5**(y+1);else break}const l=await E(m,o);return l.size>t.size?t:l}u.canvastoDataURL=v,u.canvastoFile=z,u.compress=T,u.compressAccurately=q,u.dataURLtoFile=E,u.dataURLtoImage=L,u.downloadFile=B,u.filetoDataURL=I,u.imagetoCanvas=P,u.urltoBlob=D,u.urltoImage=A,u.useEmits=U,u.useFile=M,u.usePrintHtml=F,u.useWaterMark=S,u.useWebSocket=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/lib/use-emit/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { onMounted as
|
|
3
|
-
const f =
|
|
1
|
+
import c from "mitt";
|
|
2
|
+
import { onMounted as g, onUnmounted as n } from "vue";
|
|
3
|
+
const f = c();
|
|
4
|
+
f.emit = (o, r) => {
|
|
5
|
+
const m = f.all.get(o), u = m == null ? void 0 : m.slice()[0];
|
|
6
|
+
return u == null ? void 0 : u(o, r);
|
|
7
|
+
};
|
|
4
8
|
function a(o) {
|
|
5
|
-
return
|
|
9
|
+
return g(() => {
|
|
6
10
|
if (o && o.length > 0)
|
|
7
11
|
for (let r = 0; r < o.length; r++)
|
|
8
12
|
f.on(o[r].key, o[r].value);
|
|
9
|
-
}),
|
|
13
|
+
}), n(() => {
|
|
10
14
|
if (o && o.length > 0)
|
|
11
15
|
for (let r = 0; r < o.length; r++)
|
|
12
16
|
f.off(o[r].key, o[r].value), f.all.delete(o[r].key);
|
package/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@qy_better_lib/hooks",
|
|
3
|
-
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "qy better lib hooks",
|
|
6
|
-
"author": "luhuiming",
|
|
7
|
-
"license": "ISC",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:lib": "vite build --config vite.lib.config.ts",
|
|
10
|
-
"build:dist-min": "vite build --config vite.dist.min.config.ts",
|
|
11
|
-
"build": "yarn build:lib && yarn build:dist-min"
|
|
12
|
-
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"module": "lib/index.js",
|
|
15
|
-
"types": "lib/index.d.ts",
|
|
16
|
-
"typesVersions": {
|
|
17
|
-
"*": {
|
|
18
|
-
"lib/index.js": [
|
|
19
|
-
"lib/index.d.ts"
|
|
20
|
-
],
|
|
21
|
-
"@qy-better-lib/hooks": [
|
|
22
|
-
"lib/index.d.ts"
|
|
23
|
-
],
|
|
24
|
-
"*": [
|
|
25
|
-
"*",
|
|
26
|
-
"dist/*",
|
|
27
|
-
"lib/*",
|
|
28
|
-
"lib/*.d.ts",
|
|
29
|
-
"lib/*/index.d.ts"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"exports": {
|
|
34
|
-
".": {
|
|
35
|
-
"import": "./lib/index.js"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"publishConfig": {
|
|
39
|
-
"access": "public",
|
|
40
|
-
"registry": "https://registry.npmjs.org/"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@types/node": "^20.14.9",
|
|
44
|
-
"@vitejs/plugin-vue": "^5.0.5",
|
|
45
|
-
"mitt": "^3.0.1",
|
|
46
|
-
"vite": "^5.3.2",
|
|
47
|
-
"vite-plugin-dts": "^3.9.1",
|
|
48
|
-
"vue": "^3.4.31"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@qy_better_lib/hooks",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.8",
|
|
5
|
+
"description": "qy better lib hooks",
|
|
6
|
+
"author": "luhuiming",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:lib": "vite build --config vite.lib.config.ts",
|
|
10
|
+
"build:dist-min": "vite build --config vite.dist.min.config.ts",
|
|
11
|
+
"build": "yarn build:lib && yarn build:dist-min"
|
|
12
|
+
},
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"module": "lib/index.js",
|
|
15
|
+
"types": "lib/index.d.ts",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"lib/index.js": [
|
|
19
|
+
"lib/index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"@qy-better-lib/hooks": [
|
|
22
|
+
"lib/index.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"*": [
|
|
25
|
+
"*",
|
|
26
|
+
"dist/*",
|
|
27
|
+
"lib/*",
|
|
28
|
+
"lib/*.d.ts",
|
|
29
|
+
"lib/*/index.d.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": "./lib/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.14.9",
|
|
44
|
+
"@vitejs/plugin-vue": "^5.0.5",
|
|
45
|
+
"mitt": "^3.0.1",
|
|
46
|
+
"vite": "^5.3.2",
|
|
47
|
+
"vite-plugin-dts": "^3.9.1",
|
|
48
|
+
"vue": "^3.4.31"
|
|
49
|
+
}
|
|
50
|
+
}
|