@qy_better_lib/hooks 0.0.13 → 0.0.14
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(
|
|
1
|
+
(function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d["@qy_better_lib/hooks"]={},d.Vue))})(this,(function(d,y){"use strict";function R(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)})}}}function C(){const t=R();return t.emitAsync=async function(n,...a){const e=this.all?.get(n);if(!e||e.length===0)return[];const o=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(o)},t}const b=C();function U(t){return y.onMounted(()=>{if(t&&t.length>0)for(let n=0;n<t.length;n++){debugger;b.on(t[n].key,t[n].value)}}),y.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(e,o){const i=document.createElement("a");i.href=e,i.target="_blank",o&&i.setAttribute("download",o),document.body.appendChild(i),i.click(),document.body.removeChild(i)}function n(e){e.forEach(o=>{t(o.url,o.name)})}async function a(e){if(!e)return;const o=new FileReader;return o.readAsDataURL(e),new Promise((i,l)=>{o.onload=r=>i(r.target?.result),o.onerror=r=>l(void 0)})}return{downLoadFile:t,downLoadFiles:n,toBase64:a}}function F(){function t(r){let c=n(),u=e(r);document.body.appendChild(c),document.body.appendChild(u),o(u).then(()=>{window.print(),document.body.removeChild(c),document.body.removeChild(u)})}function n(r){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
|
-
}`,
|
|
15
|
+
}`,u=document.createElement("style");return u.innerHTML=c,u}function a(){let r=document.getElementById("print-container");r&&document?.querySelector("body")?.removeChild(r)}function e(r){a();let c=document.createElement("div");return c.setAttribute("id","print-container"),c.innerHTML=r,c}function o(r){let c=r.querySelectorAll("img");const u=[].slice.call(c);if(u.length===0)return Promise.resolve();let m=0;return new Promise(h=>{function s(){m++,m===u.length&&h()}u.forEach(f=>{f.addEventListener("load",s),f.addEventListener("error",s)})})}function i(r){const c=document.querySelector(r);c&&t(c.innerHTML)}function l(r){let c="";for(let u=0;u<r.length;u++)c+=r[u].outerHTML;c&&t(c)}return{printHtml:i,printHtmlElement:l}}function j(){const t="A77B030B-E33D-C656-7642-56D6FEA46059";function n(o=null,i,l,r){let c=e(o,i,l,r);document.getElementById(c)===null&&(c=e(o,i,l))}function a(){document.getElementById(t)?.remove()}function e(o=null,i,l,r="#999"){const c=o!=null?document.querySelector(o):document.body,u=document.getElementById(t);u!==null&&c?.removeChild(u);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?.fillText(i,0,m.height),l&&h?.fillText(l,h.measureText(i).width+16,m.height));let s=document.createElement("div");s.id=t,s.style.pointerEvents="none",s.style.top="0px",s.style.left="0px",s.style.position="fixed",s.style.zIndex="100000";const{clientWidth:f,clientHeight:g}=document.documentElement;return s.style.width=f+"px",s.style.height=g+"px",s.style.background="url("+m.toDataURL("image/png")+") left top repeat",c?.appendChild(s),t}return{createWaterMark:n,removeWatermark:a}}function A(t){let n=0,a=!1,e,o;const{server:i,receive:l}=t;window.onbeforeunload=()=>{e?.close()};function r(){try{e=new WebSocket(i),u()}catch(s){console.log("连接建立异常",s)}}function c(){if(n>=5){e?.close();return}if(a)return!1;a=!0,o=setTimeout(function(){r(),a=!1,n++,o&&clearTimeout(o)},5e3)}function u(){e&&(e.onerror=s=>{console.log("连接错误",s),c()},e.onclose=()=>{console.log("连接关闭 - "+new Date().toLocaleTimeString()),c()},e.onopen=()=>{n=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: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 S(t,n=.92,a=w.JPEG){return new Promise(e=>t.toBlob(o=>e(o),a,n))}async function E(t,n){const a=t.split(",");let e=a[0].match(/:(.*?);/)?.[1];const o=atob(a[1]);let i=o.length;const l=new Uint8Array(i);for(;i--;)l[i]=o.charCodeAt(i);return p(n)&&(e=n),new Blob([l],{type:e})}function k(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 z(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 L(t){return new Promise(n=>{const a=new FileReader;a.onloadend=e=>n(e.target?.result),a.readAsDataURL(t)})}async function P(t,n={}){const a={...n},e=document.createElement("canvas"),o=e.getContext("2d");let i,l;for(const r in a)Object.prototype.hasOwnProperty.call(a,r)&&(a[r]=Number(a[r]));if(!a.scale)l=a.width||(a.height||0)*t.width/t.height||t.width,i=a.height||(a.width||0)*t.height/t.width||t.height;else{const r=a.scale>0&&a.scale<10?a.scale:1;l=t.width*r,i=t.height*r}switch([5,6,7,8].some(r=>r===a.orientation)?(e.height=l,e.width=i):(e.height=i,e.width=l),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 B(t){return fetch(t).then(n=>n.blob())}function D(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={}){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 L(t);let e=a.split(",")[0].match(/:(.*?);/)?.[1],o=w.JPEG;p(n.type)&&(o=n.type,e=n.type);const i=await k(a),l=await P(i,Object.assign({},n)),r=await v(l,n.quality,o),c=await E(r,e);return c.size>t.size?t:c}async function q(t,n={}){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 L(t);let o=e.split(",")[0].match(/:(.*?);/)?.[1],i=w.JPEG;p(n.type)&&(i=n.type,o=n.type);const l=await k(e),r=await P(l,Object.assign({},n)),c=.75;let u=1,m;const h=new Array(2);for(let f=1;f<=7;f++){m=await v(r,u,i);const g=m.length*c;if(f===7){(a.max<g||a.min>g)&&(m=[m,...h].filter(I=>I).sort((I,H)=>Math.abs(I.length*c-a.accurate)-Math.abs(H.length*c-a.accurate))[0]);break}if(a.max<g)h[1]=m,u-=.5**(f+1);else if(a.min>g)h[0]=m,u+=.5**(f+1);else break}const s=await E(m,o);return s.size>t.size?t:s}d.canvastoDataURL=v,d.canvastoFile=S,d.compress=T,d.compressAccurately=q,d.dataURLtoFile=E,d.dataURLtoImage=k,d.downloadFile=z,d.filetoDataURL=L,d.imagetoCanvas=P,d.urltoBlob=B,d.urltoImage=D,d.useEmits=U,d.useFile=M,d.usePrintHtml=F,d.useWaterMark=j,d.useWebSocket=A,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
package/lib/index.d.ts
CHANGED
package/package.json
CHANGED
package/lib/use-utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-fullscreen';
|