@qy_better_lib/hooks 0.0.11 → 0.0.13

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(d,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("vue"),require("mitt")):typeof define=="function"&&define.amd?define(["exports","vue","mitt"],b):(d=typeof globalThis<"u"?globalThis:d||self,b(d["@qy_better_lib/hooks"]={},d.Vue,d.mitt))})(this,function(d,b,C){"use strict";function U(){const t=C();return t.emitAsync=async function(n,...o){var c;const e=(c=this.all)==null?void 0:c.get(n);if(!e||e.length===0)return[];const a=e.map(s=>{try{const r=s(...o);return r instanceof Promise?r:Promise.resolve(r)}catch(r){return Promise.reject(r)}});return Promise.all(a)},t}const g=U();function M(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 F(){function t(e,a){const c=document.createElement("a");c.href=e,c.target="_blank",a&&c.setAttribute("download",a),document.body.appendChild(c),c.click(),document.body.removeChild(c)}function n(e){e.forEach(a=>{t(a.url,a.name)})}async function o(e){if(!e)return;const a=new FileReader;return a.readAsDataURL(e),new Promise((c,s)=>{a.onload=r=>{var i;return c((i=r.target)==null?void 0:i.result)},a.onerror=r=>s(void 0)})}return{downLoadFile:t,downLoadFiles:n,toBase64:o}}function j(){function t(r){let i=n(),l=e(r);document.body.appendChild(i),document.body.appendChild(l),a(l).then(()=>{window.print(),document.body.removeChild(i),document.body.removeChild(l)})}function n(r){let i=`#print-container {
1
+ (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u["@qy_better_lib/hooks"]={},u.Vue))})(this,(function(u,f){"use strict";function F(n){return{all:n=n||new Map,on:function(t,a){var e=n.get(t);e?e.push(a):n.set(t,[a])},off:function(t,a){var e=n.get(t);e&&(a?e.splice(e.indexOf(a)>>>0,1):n.set(t,[]))},emit:function(t,a){var e=n.get(t);e&&e.slice().map(function(r){r(a)}),(e=n.get("*"))&&e.slice().map(function(r){r(t,a)})}}}function R(){const n=F();return n.emitAsync=async function(t,...a){const e=this.all?.get(t);if(!e||e.length===0)return[];const r=e.map(i=>{try{const l=i(...a);return l instanceof Promise?l:Promise.resolve(l)}catch(l){return Promise.reject(l)}});return Promise.all(r)},n}const b=R();function U(n){return f.onMounted(()=>{if(n&&n.length>0)for(let t=0;t<n.length;t++){debugger;b.on(n[t].key,n[t].value)}}),f.onUnmounted(()=>{if(n&&n.length>0)for(let t=0;t<n.length;t++)b.off(n[t].key,n[t].value),b.all.delete(n[t].key)}),{emitter:b}}function C(){function n(e,r){const i=document.createElement("a");i.href=e,i.target="_blank",r&&i.setAttribute("download",r),document.body.appendChild(i),i.click(),document.body.removeChild(i)}function t(e){e.forEach(r=>{n(r.url,r.name)})}async function a(e){if(!e)return;const r=new FileReader;return r.readAsDataURL(e),new Promise((i,l)=>{r.onload=o=>i(o.target?.result),r.onerror=o=>l(void 0)})}return{downLoadFile:n,downLoadFiles:t,toBase64:a}}function M(){function n(o){let c=t(),d=e(o);document.body.appendChild(c),document.body.appendChild(d),r(d).then(()=>{window.print(),document.body.removeChild(c),document.body.removeChild(d)})}function t(o){let c=`#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
- }`,l=document.createElement("style");return l.innerHTML=i,l}function o(){var i;let r=document.getElementById("print-container");r&&((i=document==null?void 0:document.querySelector("body"))==null||i.removeChild(r))}function e(r){o();let i=document.createElement("div");return i.setAttribute("id","print-container"),i.innerHTML=r,i}function a(r){let i=r.querySelectorAll("img");const l=[].slice.call(i);if(l.length===0)return Promise.resolve();let h=0;return new Promise(m=>{function u(){h++,h===l.length&&m()}l.forEach(y=>{y.addEventListener("load",u),y.addEventListener("error",u)})})}function c(r){const i=document.querySelector(r);i&&t(i.innerHTML)}function s(r){let i="";for(let l=0;l<r.length;l++)i+=r[l].outerHTML;i&&t(i)}return{printHtml:c,printHtmlElement:s}}function A(){const t="A77B030B-E33D-C656-7642-56D6FEA46059";function n(a=null,c,s,r){let i=e(a,c,s,r);document.getElementById(i)===null&&(i=e(a,c,s))}function o(){const a=document.getElementById(t);a==null||a.remove()}function e(a=null,c,s,r="#999"){const i=a!=null?document.querySelector(a):document.body,l=document.getElementById(t);l!==null&&(i==null||i.removeChild(l));let h=document.createElement("canvas");h.width=250,h.height=150;let m=h.getContext("2d");m&&(m.font="16px Avenir,Helvetica,Arial,sans-serif",m.fillStyle=r.replace(/\,\s(1|(0.\d+)\))/,", 0.1"),m.textAlign="left",m.textBaseline="middle",m.rotate(-15*Math.PI/180),m==null||m.fillText(c,0,h.height),s&&(m==null||m.fillText(s,m.measureText(c).width+16,h.height)));let u=document.createElement("div");u.id=t,u.style.pointerEvents="none",u.style.top="0px",u.style.left="0px",u.style.position="fixed",u.style.zIndex="100000";const{clientWidth:y,clientHeight:f}=document.documentElement;return u.style.width=y+"px",u.style.height=f+"px",u.style.background="url("+h.toDataURL("image/png")+") left top repeat",i==null||i.appendChild(u),t}return{createWaterMark:n,removeWatermark:o}}function S(t){let n=0,o=!1,e,a;const{server:c,receive:s}=t;window.onbeforeunload=()=>{e==null||e.close()};function r(){try{e=new WebSocket(c),l()}catch(u){console.log("连接建立异常",u)}}function i(){if(n>=5){e==null||e.close();return}if(o)return!1;o=!0,a=setTimeout(function(){r(),o=!1,n++,a&&clearTimeout(a)},5e3)}function l(){e&&(e.onerror=u=>{console.log("连接错误",u),i()},e.onclose=()=>{console.log("连接关闭 - "+new Date().toLocaleTimeString()),i()},e.onopen=()=>{n=0,console.log("连接成功")},e.onmessage=u=>{try{s(u)}catch{console.log("message:"+u.data)}})}function h(u){(e==null?void 0:e.readyState)===WebSocket.OPEN&&(e==null||e.send(u))}function m(){e==null||e.close()}return{ws:e,create:r,socketClose:m,sendMessage:h}}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,o=w.JPEG){return p(o)||(o=w.JPEG),t.toDataURL(o,n)}function z(t,n=.92,o=w.JPEG){return new Promise(e=>t.toBlob(a=>e(a),o,n))}async function E(t,n){var r;const o=t.split(",");let e=(r=o[0].match(/:(.*?);/))==null?void 0:r[1];const a=atob(o[1]);let c=a.length;const s=new Uint8Array(c);for(;c--;)s[c]=a.charCodeAt(c);return p(n)&&(e=n),new Blob([s],{type:e})}function L(t){return new Promise((n,o)=>{const e=new Image;e.onload=()=>n(e),e.onerror=()=>o(new Error("dataURLtoImage(): dataURL is illegal")),e.src=t})}function B(t,n){const o=document.createElement("a");o.href=window.URL.createObjectURL(t),o.download=n||Date.now().toString(36),document.body.appendChild(o);const e=document.createEvent("MouseEvents");e.initEvent("click",!1,!1),o.dispatchEvent(e),document.body.removeChild(o)}function P(t){return new Promise(n=>{const o=new FileReader;o.onloadend=e=>{var a;return n((a=e.target)==null?void 0:a.result)},o.readAsDataURL(t)})}async function I(t,n={}){const o={...n},e=document.createElement("canvas"),a=e.getContext("2d");let c,s;for(const r in o)Object.prototype.hasOwnProperty.call(o,r)&&(o[r]=Number(o[r]));if(!o.scale)s=o.width||(o.height||0)*t.width/t.height||t.width,c=o.height||(o.width||0)*t.height/t.width||t.height;else{const r=o.scale>0&&o.scale<10?o.scale:1;s=t.width*r,c=t.height*r}switch([5,6,7,8].some(r=>r===o.orientation)?(e.height=s,e.width=c):(e.height=c,e.width=s),o.orientation){case 3:a.rotate(180*Math.PI/180),a.drawImage(t,-e.width,-e.height,e.width,e.height);break;case 6:a.rotate(90*Math.PI/180),a.drawImage(t,0,-e.width,e.height,e.width);break;case 8:a.rotate(270*Math.PI/180),a.drawImage(t,-e.height,0,e.height,e.width);break;case 2:a.translate(e.width,0),a.scale(-1,1),a.drawImage(t,0,0,e.width,e.height);break;case 4:a.translate(e.width,0),a.scale(-1,1),a.rotate(180*Math.PI/180),a.drawImage(t,-e.width,-e.height,e.width,e.height);break;case 5:a.translate(e.width,0),a.scale(-1,1),a.rotate(90*Math.PI/180),a.drawImage(t,0,-e.width,e.height,e.width);break;case 7:a.translate(e.width,0),a.scale(-1,1),a.rotate(270*Math.PI/180),a.drawImage(t,-e.height,0,e.height,e.width);break;default:a.drawImage(t,0,0,e.width,e.height)}return e}function D(t){return fetch(t).then(n=>n.blob())}function T(t){return new Promise((n,o)=>{const e=new Image;e.onload=()=>n(e),e.onerror=()=>o(new Error("urltoImage(): Image failed to load, please check the image URL")),e.src=t})}async function q(t,n={}){var l;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 o=await P(t);let e=(l=o.split(",")[0].match(/:(.*?);/))==null?void 0:l[1],a=w.JPEG;p(n.type)&&(a=n.type,e=n.type);const c=await L(o),s=await I(c,Object.assign({},n)),r=await k(s,n.quality,a),i=await E(r,e);return i.size>t.size?t:i}async function H(t,n={}){var y;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 o={max:n.size*(2-n.accuracy)*1024,accurate:n.size*1024,min:n.size*n.accuracy*1024},e=await P(t);let a=(y=e.split(",")[0].match(/:(.*?);/))==null?void 0:y[1],c=w.JPEG;p(n.type)&&(c=n.type,a=n.type);const s=await L(e),r=await I(s,Object.assign({},n)),i=.75;let l=1,h;const m=new Array(2);for(let f=1;f<=7;f++){h=await k(r,l,c);const v=h.length*i;if(f===7){(o.max<v||o.min>v)&&(h=[h,...m].filter(R=>R).sort((R,N)=>Math.abs(R.length*i-o.accurate)-Math.abs(N.length*i-o.accurate))[0]);break}if(o.max<v)m[1]=h,l-=.5**(f+1);else if(o.min>v)m[0]=h,l+=.5**(f+1);else break}const u=await E(h,a);return u.size>t.size?t:u}d.canvastoDataURL=k,d.canvastoFile=z,d.compress=q,d.compressAccurately=H,d.dataURLtoFile=E,d.dataURLtoImage=L,d.downloadFile=B,d.filetoDataURL=P,d.imagetoCanvas=I,d.urltoBlob=D,d.urltoImage=T,d.useEmits=M,d.useFile=F,d.usePrintHtml=j,d.useWaterMark=A,d.useWebSocket=S,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
15
+ }`,d=document.createElement("style");return d.innerHTML=c,d}function a(){let o=document.getElementById("print-container");o&&document?.querySelector("body")?.removeChild(o)}function e(o){a();let c=document.createElement("div");return c.setAttribute("id","print-container"),c.innerHTML=o,c}function r(o){let c=o.querySelectorAll("img");const d=[].slice.call(c);if(d.length===0)return Promise.resolve();let m=0;return new Promise(h=>{function s(){m++,m===d.length&&h()}d.forEach(y=>{y.addEventListener("load",s),y.addEventListener("error",s)})})}function i(o){const c=document.querySelector(o);c&&n(c.innerHTML)}function l(o){let c="";for(let d=0;d<o.length;d++)c+=o[d].outerHTML;c&&n(c)}return{printHtml:i,printHtmlElement:l}}function S(){const n="A77B030B-E33D-C656-7642-56D6FEA46059";function t(r=null,i,l,o){let c=e(r,i,l,o);document.getElementById(c)===null&&(c=e(r,i,l))}function a(){document.getElementById(n)?.remove()}function e(r=null,i,l,o="#999"){const c=r!=null?document.querySelector(r):document.body,d=document.getElementById(n);d!==null&&c?.removeChild(d);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=o.replace(/\,\s(1|(0.\d+)\))/,", 0.1"),h.textAlign="left",h.textBaseline="middle",h.rotate(-15*Math.PI/180),h?.fillText(i,0,m.height),l&&h?.fillText(l,h.measureText(i).width+16,m.height));let s=document.createElement("div");s.id=n,s.style.pointerEvents="none",s.style.top="0px",s.style.left="0px",s.style.position="fixed",s.style.zIndex="100000";const{clientWidth:y,clientHeight:g}=document.documentElement;return s.style.width=y+"px",s.style.height=g+"px",s.style.background="url("+m.toDataURL("image/png")+") left top repeat",c?.appendChild(s),n}return{createWaterMark:t,removeWatermark:a}}function j(n){let t=0,a=!1,e,r;const{server:i,receive:l}=n;window.onbeforeunload=()=>{e?.close()};function o(){try{e=new WebSocket(i),d()}catch(s){console.log("连接建立异常",s)}}function c(){if(t>=5){e?.close();return}if(a)return!1;a=!0,r=setTimeout(function(){o(),a=!1,t++,r&&clearTimeout(r)},5e3)}function d(){e&&(e.onerror=s=>{console.log("连接错误",s),c()},e.onclose=()=>{console.log("连接关闭 - "+new Date().toLocaleTimeString()),c()},e.onopen=()=>{t=0,console.log("连接成功")},e.onmessage=s=>{try{l(s)}catch{console.log("message:"+s.data)}})}function m(s){e?.readyState===WebSocket.OPEN&&e?.send(s)}function h(){e?.close()}return{ws:e,create:o,socketClose:h,sendMessage:m}}var w=(n=>(n.PNG="image/png",n.JPEG="image/jpeg",n.GIF="image/gif",n))(w||{});function p(n){return["image/png","image/jpeg","image/gif"].some(t=>t===n)}async function v(n,t=.92,a=w.JPEG){return p(a)||(a=w.JPEG),n.toDataURL(a,t)}function A(n,t=.92,a=w.JPEG){return new Promise(e=>n.toBlob(r=>e(r),a,t))}async function E(n,t){const a=n.split(",");let e=a[0].match(/:(.*?);/)?.[1];const r=atob(a[1]);let i=r.length;const l=new Uint8Array(i);for(;i--;)l[i]=r.charCodeAt(i);return p(t)&&(e=t),new Blob([l],{type:e})}function k(n){return new Promise((t,a)=>{const e=new Image;e.onload=()=>t(e),e.onerror=()=>a(new Error("dataURLtoImage(): dataURL is illegal")),e.src=n})}function z(n,t){const a=document.createElement("a");a.href=window.URL.createObjectURL(n),a.download=t||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 L(n){return new Promise(t=>{const a=new FileReader;a.onloadend=e=>t(e.target?.result),a.readAsDataURL(n)})}async function P(n,t={}){const a={...t},e=document.createElement("canvas"),r=e.getContext("2d");let i,l;for(const o in a)Object.prototype.hasOwnProperty.call(a,o)&&(a[o]=Number(a[o]));if(!a.scale)l=a.width||(a.height||0)*n.width/n.height||n.width,i=a.height||(a.width||0)*n.height/n.width||n.height;else{const o=a.scale>0&&a.scale<10?a.scale:1;l=n.width*o,i=n.height*o}switch([5,6,7,8].some(o=>o===a.orientation)?(e.height=l,e.width=i):(e.height=i,e.width=l),a.orientation){case 3:r.rotate(180*Math.PI/180),r.drawImage(n,-e.width,-e.height,e.width,e.height);break;case 6:r.rotate(90*Math.PI/180),r.drawImage(n,0,-e.width,e.height,e.width);break;case 8:r.rotate(270*Math.PI/180),r.drawImage(n,-e.height,0,e.height,e.width);break;case 2:r.translate(e.width,0),r.scale(-1,1),r.drawImage(n,0,0,e.width,e.height);break;case 4:r.translate(e.width,0),r.scale(-1,1),r.rotate(180*Math.PI/180),r.drawImage(n,-e.width,-e.height,e.width,e.height);break;case 5:r.translate(e.width,0),r.scale(-1,1),r.rotate(90*Math.PI/180),r.drawImage(n,0,-e.width,e.height,e.width);break;case 7:r.translate(e.width,0),r.scale(-1,1),r.rotate(270*Math.PI/180),r.drawImage(n,-e.height,0,e.height,e.width);break;default:r.drawImage(n,0,0,e.width,e.height)}return e}function B(n){return fetch(n).then(t=>t.blob())}function D(n){return new Promise((t,a)=>{const e=new Image;e.onload=()=>t(e),e.onerror=()=>a(new Error("urltoImage(): Image failed to load, please check the image URL")),e.src=n})}async function q(n,t={}){if(!(n instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if(typeof t!="object"&&(t=Object.assign({quality:t})),t.quality=Number(t.quality),Number.isNaN(t.quality))return n;const a=await L(n);let e=a.split(",")[0].match(/:(.*?);/)?.[1],r=w.JPEG;p(t.type)&&(r=t.type,e=t.type);const i=await k(a),l=await P(i,Object.assign({},t)),o=await v(l,t.quality,r),c=await E(o,e);return c.size>n.size?n:c}async function T(n,t={}){if(!(n instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if(typeof t!="object"&&(t=Object.assign({size:t})),t.size=Number(t.size),Number.isNaN(t.size)||t.size*1024>n.size)return n;t.accuracy=Number(t.accuracy),(!t.accuracy||t.accuracy<.8||t.accuracy>.99)&&(t.accuracy=.95);const a={max:t.size*(2-t.accuracy)*1024,accurate:t.size*1024,min:t.size*t.accuracy*1024},e=await L(n);let r=e.split(",")[0].match(/:(.*?);/)?.[1],i=w.JPEG;p(t.type)&&(i=t.type,r=t.type);const l=await k(e),o=await P(l,Object.assign({},t)),c=.75;let d=1,m;const h=new Array(2);for(let y=1;y<=7;y++){m=await v(o,d,i);const g=m.length*c;if(y===7){(a.max<g||a.min>g)&&(m=[m,...h].filter(I=>I).sort((I,N)=>Math.abs(I.length*c-a.accurate)-Math.abs(N.length*c-a.accurate))[0]);break}if(a.max<g)h[1]=m,d-=.5**(y+1);else if(a.min>g)h[0]=m,d+=.5**(y+1);else break}const s=await E(m,r);return s.size>n.size?n:s}function H(n){const t=f.ref(!1);let a=f.shallowRef(null);f.onMounted(()=>{a.value=document.querySelector(n),a.value?.addEventListener("fullscreenchange",r)}),f.onUnmounted(()=>{a.value?.removeEventListener("fullscreenchange",r)});function e(){t.value?document.exitFullscreen&&document.exitFullscreen():a.value?.requestFullscreen&&a.value?.requestFullscreen(),t.value=!t.value}function r(){t.value=document.fullscreenElement===a.value}return{container:a,full:t,on_change:e}}u.canvastoDataURL=v,u.canvastoFile=A,u.compress=q,u.compressAccurately=T,u.dataURLtoFile=E,u.dataURLtoImage=k,u.downloadFile=z,u.filetoDataURL=L,u.imagetoCanvas=P,u.urltoBlob=B,u.urltoImage=D,u.useEmits=U,u.useFile=C,u.useFullScreen=H,u.usePrintHtml=M,u.useWaterMark=S,u.useWebSocket=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/lib/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from './use-emit';
2
2
  export * from './use-file';
3
3
  export * from './use-print';
4
4
  export * from './use-waterMark';
5
- export * from './use-websocket/index';
5
+ export * from './use-websocket';
6
6
  export * from './use-image';
7
+ export * from './use-utils';
@@ -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
+ };
@@ -1,2 +1 @@
1
- import { Emitter, EventType } from 'mitt';
2
- export declare function createAsyncEmitter(): Emitter<Record< EventType, unknown>>;
1
+ export declare function createAsyncEmitter(): any;
@@ -1,5 +1,4 @@
1
1
  import { Emitter, EventType } from 'mitt';
2
-
3
2
  interface useEmits {
4
3
  /**
5
4
  * 全局事件对象
@@ -4,7 +4,7 @@ interface UseFile {
4
4
  /**批量下载文件 */
5
5
  downLoadFiles: (list: Array<any>) => void;
6
6
  /**将二进制文件转换成base64 */
7
- toBase64: (file: Blob) => Promise<string>;
7
+ toBase64: (file: Blob) => Promise<string | undefined>;
8
8
  }
9
9
  /**
10
10
  * 文件处理
@@ -1,5 +1,4 @@
1
1
  import { EImageType } from './type';
2
-
3
2
  /**
4
3
  * 将一个Canvas对象转变为一个dataURL字符串
5
4
  * 该方法可以做压缩处理
@@ -1,5 +1,4 @@
1
1
  import { EImageType } from './type';
2
-
3
2
  /**
4
3
  * 将一个canvas对象转变为一个File(Blob)对象
5
4
  * 该方法可以做压缩处理
@@ -1,5 +1,4 @@
1
1
  import { EImageType } from './type';
2
-
3
2
  /**
4
3
  * 将一个dataURL字符串转变为一个File(Blob)对象
5
4
  * 转变时可以确定File对象的类型
@@ -1,5 +1,4 @@
1
1
  import { Image2CanvasConfig } from './type';
2
-
3
2
  /**
4
3
  * 将一个image对象转变为一个canvas对象
5
4
  *
@@ -8,7 +8,6 @@ import { default as imagetoCanvas } from './imagetoCanvas';
8
8
  import { default as urltoBlob } from './urltoBlob';
9
9
  import { default as urltoImage } from './urltoImage';
10
10
  import { ICompressConfig, compressAccuratelyConfig } from './type';
11
-
12
11
  /**
13
12
  * 压缩File(Blob)对象
14
13
  * @param {Blob} file - 一个File(Blob)对象
@@ -0,0 +1 @@
1
+ export * from './use-fullscreen';
@@ -0,0 +1,9 @@
1
+ import { Ref, ShallowRef } from 'vue';
2
+ interface UseFullScreen {
3
+ full: Ref<boolean>;
4
+ container: ShallowRef<Element | null>;
5
+ on_change: () => void;
6
+ }
7
+ /**DOM全屏展示 */
8
+ export declare function useFullScreen(selector: string): UseFullScreen;
9
+ export {};
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.11",
4
+ "version": "0.0.13",
5
5
  "description": "qy better lib hooks",
6
6
  "author": "luhuiming",
7
7
  "license": "ISC",
@@ -36,11 +36,11 @@
36
36
  }
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^20.14.9",
40
- "@vitejs/plugin-vue": "^5.0.5",
39
+ "@types/node": "^24.5.2",
40
+ "@vitejs/plugin-vue": "^6.0.1",
41
41
  "mitt": "^3.0.1",
42
- "vite": "^5.3.2",
43
- "vite-plugin-dts": "^3.9.1",
44
- "vue": "^3.4.31"
42
+ "vite": "^7.1.7",
43
+ "vite-plugin-dts": "^4.5.4",
44
+ "vue": "^3.5.22"
45
45
  }
46
46
  }
package/lib/index.js DELETED
@@ -1,33 +0,0 @@
1
- import { useEmits 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 useEmits,
29
- r as useFile,
30
- m as usePrintHtml,
31
- l as useWaterMark,
32
- u as useWebSocket
33
- };
@@ -1,22 +0,0 @@
1
- import m from "mitt";
2
- function l() {
3
- const e = m();
4
- return e.emitAsync = async function(s, ...o) {
5
- var n;
6
- const t = (n = this.all) == null ? void 0 : n.get(s);
7
- if (!t || t.length === 0)
8
- return [];
9
- const i = t.map((c) => {
10
- try {
11
- const r = c(...o);
12
- return r instanceof Promise ? r : Promise.resolve(r);
13
- } catch (r) {
14
- return Promise.reject(r);
15
- }
16
- });
17
- return Promise.all(i);
18
- }, e;
19
- }
20
- export {
21
- l as createAsyncEmitter
22
- };
@@ -1,19 +0,0 @@
1
- import { onMounted as m, onUnmounted as u } from "vue";
2
- import { createAsyncEmitter as n } from "./extend.js";
3
- const f = n();
4
- function e(o) {
5
- return m(() => {
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
- }), u(() => {
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
- e as useEmits
19
- };
@@ -1,29 +0,0 @@
1
- function i() {
2
- function o(r, e) {
3
- const n = document.createElement("a");
4
- n.href = r, n.target = "_blank", e && n.setAttribute("download", e), document.body.appendChild(n), n.click(), document.body.removeChild(n);
5
- }
6
- function a(r) {
7
- r.forEach((e) => {
8
- o(e.url, e.name);
9
- });
10
- }
11
- async function u(r) {
12
- if (!r) return;
13
- const e = new FileReader();
14
- return e.readAsDataURL(r), new Promise((n, c) => {
15
- e.onload = (t) => {
16
- var d;
17
- return n((d = t.target) == null ? void 0 : d.result);
18
- }, e.onerror = (t) => c(void 0);
19
- });
20
- }
21
- return {
22
- downLoadFile: o,
23
- downLoadFiles: a,
24
- toBase64: u
25
- };
26
- }
27
- export {
28
- i as useFile
29
- };
@@ -1,7 +0,0 @@
1
- import { checkImageType as c, EImageType as t } from "./type.js";
2
- async function r(e, o = 0.92, a = t.JPEG) {
3
- return c(a) || (a = t.JPEG), e.toDataURL(a, o);
4
- }
5
- export {
6
- r as default
7
- };
@@ -1,9 +0,0 @@
1
- import { EImageType as n } from "./type.js";
2
- function m(e, o = 0.92, t = n.JPEG) {
3
- return new Promise(
4
- (r) => e.toBlob((a) => r(a), t, o)
5
- );
6
- }
7
- export {
8
- m as default
9
- };
@@ -1,17 +0,0 @@
1
- import { checkImageType as l } from "./type.js";
2
- async function m(i, e) {
3
- var c;
4
- const r = i.split(",");
5
- let a = (c = r[0].match(/:(.*?);/)) == null ? void 0 : c[1];
6
- const n = atob(r[1]);
7
- let t = n.length;
8
- const o = new Uint8Array(t);
9
- for (; t--; )
10
- o[t] = n.charCodeAt(t);
11
- return l(e) && (a = e), new Blob([o], {
12
- type: a
13
- });
14
- }
15
- export {
16
- m as default
17
- };
@@ -1,9 +0,0 @@
1
- function t(e) {
2
- return new Promise((o, r) => {
3
- const a = new Image();
4
- a.onload = () => o(a), a.onerror = () => r(new Error("dataURLtoImage(): dataURL is illegal")), a.src = e;
5
- });
6
- }
7
- export {
8
- t as default
9
- };
@@ -1,9 +0,0 @@
1
- function d(n, o) {
2
- const e = document.createElement("a");
3
- e.href = window.URL.createObjectURL(n), e.download = o || Date.now().toString(36), document.body.appendChild(e);
4
- const t = document.createEvent("MouseEvents");
5
- t.initEvent("click", !1, !1), e.dispatchEvent(t), document.body.removeChild(e);
6
- }
7
- export {
8
- d as default
9
- };
@@ -1,12 +0,0 @@
1
- function o(t) {
2
- return new Promise((r) => {
3
- const e = new FileReader();
4
- e.onloadend = (n) => {
5
- var a;
6
- return r((a = n.target) == null ? void 0 : a.result);
7
- }, e.readAsDataURL(t);
8
- });
9
- }
10
- export {
11
- o as default
12
- };
@@ -1,41 +0,0 @@
1
- async function w(e, s = {}) {
2
- const a = { ...s }, t = document.createElement("canvas"), h = t.getContext("2d");
3
- let d, r;
4
- for (const i in a)
5
- Object.prototype.hasOwnProperty.call(a, i) && (a[i] = Number(a[i]));
6
- if (!a.scale)
7
- r = a.width || (a.height || 0) * e.width / e.height || e.width, d = a.height || (a.width || 0) * e.height / e.width || e.height;
8
- else {
9
- const i = a.scale > 0 && a.scale < 10 ? a.scale : 1;
10
- r = e.width * i, d = e.height * i;
11
- }
12
- switch ([5, 6, 7, 8].some((i) => i === a.orientation) ? (t.height = r, t.width = d) : (t.height = d, t.width = r), a.orientation) {
13
- case 3:
14
- h.rotate(180 * Math.PI / 180), h.drawImage(e, -t.width, -t.height, t.width, t.height);
15
- break;
16
- case 6:
17
- h.rotate(90 * Math.PI / 180), h.drawImage(e, 0, -t.width, t.height, t.width);
18
- break;
19
- case 8:
20
- h.rotate(270 * Math.PI / 180), h.drawImage(e, -t.height, 0, t.height, t.width);
21
- break;
22
- case 2:
23
- h.translate(t.width, 0), h.scale(-1, 1), h.drawImage(e, 0, 0, t.width, t.height);
24
- break;
25
- case 4:
26
- h.translate(t.width, 0), h.scale(-1, 1), h.rotate(180 * Math.PI / 180), h.drawImage(e, -t.width, -t.height, t.width, t.height);
27
- break;
28
- case 5:
29
- h.translate(t.width, 0), h.scale(-1, 1), h.rotate(90 * Math.PI / 180), h.drawImage(e, 0, -t.width, t.height, t.width);
30
- break;
31
- case 7:
32
- h.translate(t.width, 0), h.scale(-1, 1), h.rotate(270 * Math.PI / 180), h.drawImage(e, -t.height, 0, t.height, t.width);
33
- break;
34
- default:
35
- h.drawImage(e, 0, 0, t.width, t.height);
36
- }
37
- return t;
38
- }
39
- export {
40
- w as default
41
- };
@@ -1,74 +0,0 @@
1
- import h from "./canvastoDataURL.js";
2
- import { EImageType as j, checkImageType as L } from "./type.js";
3
- import N from "./dataURLtoFile.js";
4
- import R from "./dataURLtoImage.js";
5
- import U from "./filetoDataURL.js";
6
- import F from "./imagetoCanvas.js";
7
- async function M(t, a = {}) {
8
- var i;
9
- if (!(t instanceof Blob))
10
- throw new Error(
11
- "compress(): First arg must be a Blob object or a File object."
12
- );
13
- if (typeof a != "object" && (a = Object.assign({
14
- quality: a
15
- })), a.quality = Number(a.quality), Number.isNaN(a.quality))
16
- return t;
17
- const e = await U(t);
18
- let m = (i = e.split(",")[0].match(/:(.*?);/)) == null ? void 0 : i[1], c = j.JPEG;
19
- L(a.type) && (c = a.type, m = a.type);
20
- const u = await R(e), y = await F(u, Object.assign({}, a)), l = await h(y, a.quality, c), s = await N(l, m);
21
- return s.size > t.size ? t : s;
22
- }
23
- async function O(t, a = {}) {
24
- var z;
25
- if (!(t instanceof Blob))
26
- throw new Error(
27
- "compressAccurately(): First arg must be a Blob object or a File object."
28
- );
29
- if (typeof a != "object" && (a = Object.assign({
30
- size: a
31
- })), a.size = Number(a.size), Number.isNaN(a.size) || a.size * 1024 > t.size)
32
- return t;
33
- a.accuracy = Number(a.accuracy), (!a.accuracy || a.accuracy < 0.8 || a.accuracy > 0.99) && (a.accuracy = 0.95);
34
- const e = {
35
- max: a.size * (2 - a.accuracy) * 1024,
36
- accurate: a.size * 1024,
37
- min: a.size * a.accuracy * 1024
38
- }, m = await U(t);
39
- let c = (z = m.split(",")[0].match(/:(.*?);/)) == null ? void 0 : z[1], u = j.JPEG;
40
- L(a.type) && (u = a.type, c = a.type);
41
- const y = await R(m), l = await F(y, Object.assign({}, a)), s = 0.75;
42
- let i = 1, r;
43
- const b = new Array(2);
44
- for (let o = 1; o <= 7; o++) {
45
- r = await h(l, i, u);
46
- const p = r.length * s;
47
- if (o === 7) {
48
- (e.max < p || e.min > p) && (r = [r, ...b].filter((n) => n).sort(
49
- (n, q) => Math.abs(n.length * s - e.accurate) - Math.abs(q.length * s - e.accurate)
50
- )[0]);
51
- break;
52
- }
53
- if (e.max < p)
54
- b[1] = r, i -= 0.5 ** (o + 1);
55
- else if (e.min > p)
56
- b[0] = r, i += 0.5 ** (o + 1);
57
- else
58
- break;
59
- }
60
- const w = await N(
61
- r,
62
- c
63
- );
64
- return w.size > t.size ? t : w;
65
- }
66
- export {
67
- h as canvastoDataURL,
68
- M as compress,
69
- O as compressAccurately,
70
- N as dataURLtoFile,
71
- R as dataURLtoImage,
72
- U as filetoDataURL,
73
- F as imagetoCanvas
74
- };
@@ -1,8 +0,0 @@
1
- var i = /* @__PURE__ */ ((e) => (e.PNG = "image/png", e.JPEG = "image/jpeg", e.GIF = "image/gif", e))(i || {});
2
- function a(e) {
3
- return ["image/png", "image/jpeg", "image/gif"].some((g) => g === e);
4
- }
5
- export {
6
- i as EImageType,
7
- a as checkImageType
8
- };
@@ -1,6 +0,0 @@
1
- function o(t) {
2
- return fetch(t).then((e) => e.blob());
3
- }
4
- export {
5
- o as default
6
- };
@@ -1,13 +0,0 @@
1
- function n(o) {
2
- return new Promise((r, a) => {
3
- const e = new Image();
4
- e.onload = () => r(e), e.onerror = () => a(
5
- new Error(
6
- "urltoImage(): Image failed to load, please check the image URL"
7
- )
8
- ), e.src = o;
9
- });
10
- }
11
- export {
12
- n as default
13
- };
@@ -1,68 +0,0 @@
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
- };
@@ -1,30 +0,0 @@
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
- };
@@ -1,54 +0,0 @@
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
- };