@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.
- package/dist/@qy_better_lib/hooks.min.js +2 -2
- package/lib/index.d.ts +2 -1
- package/lib/node_modules/mitt/dist/mitt.js +19 -0
- package/lib/use-emit/extend.d.ts +1 -2
- package/lib/use-emit/index.d.ts +0 -1
- package/lib/use-file/index.d.ts +1 -1
- package/lib/use-image/canvastoDataURL.d.ts +0 -1
- package/lib/use-image/canvastoFile.d.ts +0 -1
- package/lib/use-image/dataURLtoFile.d.ts +0 -1
- package/lib/use-image/imagetoCanvas.d.ts +0 -1
- package/lib/use-image/index.d.ts +0 -1
- package/lib/use-utils/index.d.ts +1 -0
- package/lib/use-utils/use-fullscreen.d.ts +9 -0
- package/package.json +6 -6
- package/lib/index.js +0 -33
- package/lib/use-emit/extend.js +0 -22
- package/lib/use-emit/index.js +0 -19
- package/lib/use-file/index.js +0 -29
- package/lib/use-image/canvastoDataURL.js +0 -7
- package/lib/use-image/canvastoFile.js +0 -9
- package/lib/use-image/dataURLtoFile.js +0 -17
- package/lib/use-image/dataURLtoImage.js +0 -9
- package/lib/use-image/downloadFile.js +0 -9
- package/lib/use-image/filetoDataURL.js +0 -12
- package/lib/use-image/imagetoCanvas.js +0 -41
- package/lib/use-image/index.js +0 -74
- package/lib/use-image/type.js +0 -8
- package/lib/use-image/urltoBlob.js +0 -6
- package/lib/use-image/urltoImage.js +0 -13
- package/lib/use-print/index.js +0 -68
- package/lib/use-waterMark/index.js +0 -30
- package/lib/use-websocket/index.js +0 -54
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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
|
-
}`,
|
|
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
|
@@ -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/use-emit/extend.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function createAsyncEmitter(): Emitter<Record< EventType, unknown>>;
|
|
1
|
+
export declare function createAsyncEmitter(): any;
|
package/lib/use-emit/index.d.ts
CHANGED
package/lib/use-file/index.d.ts
CHANGED
package/lib/use-image/index.d.ts
CHANGED
|
@@ -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';
|
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.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": "^
|
|
40
|
-
"@vitejs/plugin-vue": "^
|
|
39
|
+
"@types/node": "^24.5.2",
|
|
40
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
41
41
|
"mitt": "^3.0.1",
|
|
42
|
-
"vite": "^
|
|
43
|
-
"vite-plugin-dts": "^
|
|
44
|
-
"vue": "^3.
|
|
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
|
-
};
|
package/lib/use-emit/extend.js
DELETED
|
@@ -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
|
-
};
|
package/lib/use-emit/index.js
DELETED
|
@@ -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
|
-
};
|
package/lib/use-file/index.js
DELETED
|
@@ -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,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 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,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
|
-
};
|
package/lib/use-image/index.js
DELETED
|
@@ -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
|
-
};
|
package/lib/use-image/type.js
DELETED
|
@@ -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
|
-
};
|
package/lib/use-print/index.js
DELETED
|
@@ -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
|
-
};
|