@qy_better_lib/hooks 0.1.7 → 0.1.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.
- package/dist/@qy_better_lib/hooks.min.js +2 -2
- package/lib/index.d.ts +4 -0
- package/lib/index.js +39 -31
- package/lib/node_modules/@qy_better_lib/core/lib/directives/click-outside.js +8 -0
- package/lib/node_modules/@qy_better_lib/core/lib/utils/is.js +8 -0
- package/lib/node_modules/@qy_better_lib/core/lib/utils/object.js +15 -0
- package/lib/use-chart/default.d.ts +1 -1
- package/lib/use-chart/default.js +11 -0
- package/lib/use-chart/index.d.ts +4 -0
- package/lib/use-emit/extend.js +16 -14
- package/lib/use-emit/index.js +8 -7
- package/lib/use-layout-flow/index.js +120 -0
- package/lib/use-mqtt/index.d.ts +7 -1
- package/lib/use-utils/use-fullscreen.js +24 -0
- package/package.json +26 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("mitt"),require("vue"),require("@antv/x6"),require("dagre"),require("mqtt")):typeof define=="function"&&define.amd?define(["exports","mitt","vue","@antv/x6","dagre","mqtt"],L):(d=typeof globalThis<"u"?globalThis:d||self,L(d["@qy_better_lib/hooks"]={},d.mitt,d.vue,d["@antv/x6"],d.dagre))})(this,(function(d,L,S,U,O){"use strict";function J(){if(typeof L>"u")return{};const t=L();return t.emitAsync=async function(e,...o){const n=this.all?.get(e);if(!n||n.length===0)return[];const r=n.map(a=>{try{const u=a(...o);return u instanceof Promise?u:Promise.resolve(u)}catch(u){return Promise.reject(u)}});return Promise.all(r)},t}const R=J();function V(t){return typeof L>"u"?{emitter:R}:(S.onMounted(()=>{if(t&&t.length>0)for(let e=0;e<t.length;e++){debugger;R.on(t[e].key,t[e].value)}}),S.onUnmounted(()=>{if(t&&t.length>0)for(let e=0;e<t.length;e++)R.off(t[e].key,t[e].value),R.all.delete(t[e].key)}),{emitter:R})}function Q(){function t(n,r){const a=document.createElement("a");a.href=n,a.target="_blank",r&&a.setAttribute("download",r),document.body.appendChild(a),a.click(),document.body.removeChild(a)}function e(n){n.forEach(r=>{t(r.url,r.name)})}async function o(n){if(!n)return;const r=new FileReader;return r.readAsDataURL(n),new Promise((a,u)=>{r.onload=c=>a(c.target?.result),r.onerror=c=>u(void 0)})}return{downLoadFile:t,downLoadFiles:e,toBase64:o}}function $(){function t(c){let i=e(),m=n(c);document.body.appendChild(i),document.body.appendChild(m),r(m).then(()=>{window.print(),document.body.removeChild(i),document.body.removeChild(m)})}function e(c){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
|
-
}`,
|
|
15
|
+
}`,m=document.createElement("style");return m.innerHTML=i,m}function o(){let c=document.getElementById("print-container");c&&document?.querySelector("body")?.removeChild(c)}function n(c){o();let i=document.createElement("div");return i.setAttribute("id","print-container"),i.innerHTML=c,i}function r(c){let i=c.querySelectorAll("img");const m=[].slice.call(i);if(m.length===0)return Promise.resolve();let g=0;return new Promise(y=>{function h(){g++,g===m.length&&y()}m.forEach(s=>{s.addEventListener("load",h),s.addEventListener("error",h)})})}function a(c){const i=document.querySelector(c);i&&t(i.innerHTML)}function u(c){let i="";for(let m=0;m<c.length;m++)i+=c[m].outerHTML;i&&t(i)}return{printHtml:a,printHtmlElement:u}}function K(){const t="A77B030B-E33D-C656-7642-56D6FEA46059";function e(r=null,a,u,c){let i=n(r,a,u,c);document.getElementById(i)===null&&(i=n(r,a,u))}function o(){document.getElementById(t)?.remove()}function n(r=null,a,u,c="#999"){const i=r!=null?document.querySelector(r):document.body,m=document.getElementById(t);m!==null&&i?.removeChild(m);let g=document.createElement("canvas");g.width=250,g.height=150;let y=g.getContext("2d");y&&(y.font="16px Avenir,Helvetica,Arial,sans-serif",y.fillStyle=c.replace(/\,\s(1|(0.\d+)\))/,", 0.1"),y.textAlign="left",y.textBaseline="middle",y.rotate(-15*Math.PI/180),y?.fillText(a,0,g.height),u&&y?.fillText(u,y.measureText(a).width+16,g.height));let h=document.createElement("div");h.id=t,h.style.pointerEvents="none",h.style.top="0px",h.style.left="0px",h.style.position="fixed",h.style.zIndex="100000";const{clientWidth:s,clientHeight:l}=document.documentElement;return h.style.width=s+"px",h.style.height=l+"px",h.style.background="url("+g.toDataURL("image/png")+") left top repeat",i?.appendChild(h),t}return{createWaterMark:e,removeWatermark:o}}function X(t){let e=0,o=!1,n,r;const{server:a,receive:u}=t;window.onbeforeunload=()=>{n?.close()};function c(){try{n=new WebSocket(a),m()}catch(h){console.log("连接建立异常",h)}}function i(){if(e>=5){n?.close();return}if(o)return!1;o=!0,r=setTimeout(function(){c(),o=!1,e++,r&&clearTimeout(r)},5e3)}function m(){n&&(n.onerror=h=>{console.log("连接错误",h),i()},n.onclose=()=>{console.log("连接关闭 - "+new Date().toLocaleTimeString()),i()},n.onopen=()=>{e=0,console.log("连接成功")},n.onmessage=h=>{try{u(h)}catch{console.log("message:"+h.data)}})}function g(h){n?.readyState===WebSocket.OPEN&&n?.send(h)}function y(){n?.close()}return{ws:n,create:c,socketClose:y,sendMessage:g}}var k=(t=>(t.PNG="image/png",t.JPEG="image/jpeg",t.GIF="image/gif",t))(k||{});function B(t){return["image/png","image/jpeg","image/gif"].some(e=>e===t)}async function j(t,e=.92,o=k.JPEG){return B(o)||(o=k.JPEG),t.toDataURL(o,e)}function Y(t,e=.92,o=k.JPEG){return new Promise(n=>t.toBlob(r=>n(r),o,e))}async function M(t,e){const o=t.split(",");let n=o[0].match(/:(.*?);/)?.[1];const r=atob(o[1]);let a=r.length;const u=new Uint8Array(a);for(;a--;)u[a]=r.charCodeAt(a);return B(e)&&(n=e),new Blob([u],{type:n})}function z(t){return new Promise((e,o)=>{const n=new Image;n.onload=()=>e(n),n.onerror=()=>o(new Error("dataURLtoImage(): dataURL is illegal")),n.src=t})}function Z(t,e){const o=document.createElement("a");o.href=window.URL.createObjectURL(t),o.download=e||Date.now().toString(36),document.body.appendChild(o);const n=document.createEvent("MouseEvents");n.initEvent("click",!1,!1),o.dispatchEvent(n),document.body.removeChild(o)}function T(t){return new Promise(e=>{const o=new FileReader;o.onloadend=n=>e(n.target?.result),o.readAsDataURL(t)})}async function q(t,e={}){const o={...e},n=document.createElement("canvas"),r=n.getContext("2d");let a,u;for(const c in o)Object.prototype.hasOwnProperty.call(o,c)&&(o[c]=Number(o[c]));if(!o.scale)u=o.width||(o.height||0)*t.width/t.height||t.width,a=o.height||(o.width||0)*t.height/t.width||t.height;else{const c=o.scale>0&&o.scale<10?o.scale:1;u=t.width*c,a=t.height*c}switch([5,6,7,8].some(c=>c===o.orientation)?(n.height=u,n.width=a):(n.height=a,n.width=u),o.orientation){case 3:r.rotate(180*Math.PI/180),r.drawImage(t,-n.width,-n.height,n.width,n.height);break;case 6:r.rotate(90*Math.PI/180),r.drawImage(t,0,-n.width,n.height,n.width);break;case 8:r.rotate(270*Math.PI/180),r.drawImage(t,-n.height,0,n.height,n.width);break;case 2:r.translate(n.width,0),r.scale(-1,1),r.drawImage(t,0,0,n.width,n.height);break;case 4:r.translate(n.width,0),r.scale(-1,1),r.rotate(180*Math.PI/180),r.drawImage(t,-n.width,-n.height,n.width,n.height);break;case 5:r.translate(n.width,0),r.scale(-1,1),r.rotate(90*Math.PI/180),r.drawImage(t,0,-n.width,n.height,n.width);break;case 7:r.translate(n.width,0),r.scale(-1,1),r.rotate(270*Math.PI/180),r.drawImage(t,-n.height,0,n.height,n.width);break;default:r.drawImage(t,0,0,n.width,n.height)}return n}function ee(t){return fetch(t).then(e=>e.blob())}function te(t){return new Promise((e,o)=>{const n=new Image;n.onload=()=>e(n),n.onerror=()=>o(new Error("urltoImage(): Image failed to load, please check the image URL")),n.src=t})}async function ne(t,e={}){if(!(t instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if(typeof e!="object"&&(e=Object.assign({quality:e})),e.quality=Number(e.quality),Number.isNaN(e.quality))return t;const o=await T(t);let n=o.split(",")[0].match(/:(.*?);/)?.[1],r=k.JPEG;B(e.type)&&(r=e.type,n=e.type);const a=await z(o),u=await q(a,Object.assign({},e)),c=await j(u,e.quality,r),i=await M(c,n);return i.size>t.size?t:i}async function oe(t,e={}){if(!(t instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if(typeof e!="object"&&(e=Object.assign({size:e})),e.size=Number(e.size),Number.isNaN(e.size)||e.size*1024>t.size)return t;e.accuracy=Number(e.accuracy),(!e.accuracy||e.accuracy<.8||e.accuracy>.99)&&(e.accuracy=.95);const o={max:e.size*(2-e.accuracy)*1024,accurate:e.size*1024,min:e.size*e.accuracy*1024},n=await T(t);let r=n.split(",")[0].match(/:(.*?);/)?.[1],a=k.JPEG;B(e.type)&&(a=e.type,r=e.type);const u=await z(n),c=await q(u,Object.assign({},e)),i=.75;let m=1,g;const y=new Array(2);for(let s=1;s<=7;s++){g=await j(c,m,a);const l=g.length*i;if(s===7){(o.max<l||o.min>l)&&(g=[g,...y].filter(f=>f).sort((f,b)=>Math.abs(f.length*i-o.accurate)-Math.abs(b.length*i-o.accurate))[0]);break}if(o.max<l)y[1]=g,m-=.5**(s+1);else if(o.min>l)y[0]=g,m+=.5**(s+1);else break}const h=await M(g,r);return h.size>t.size?t:h}function N(t){return typeof t=="object"&&Object.prototype.toString.call(t)==="[object Object]"}const re=typeof window<"u";function W(...t){let e=t.length,o=t[0];N(o)||(o={});for(let n=1;n<e;n++){let r=t[n];if(N(r))for(let a in r)a==="__proto__"||o===r[a]||(N(r[a])?o[a]=W(o[a],r[a]):o[a]=r[a])}return o}const ae=new Map;let G;re&&(document.addEventListener("mousedown",t=>G=t),document.addEventListener("mouseup",t=>{for(const e of ae.values())for(const{documentHandler:o}of e)o(t,G)})),v(12),v(14),v(12),v(8),v(16),v(12),v(12),v(12),v(12);function v(t,e=1920){if(!t)return 0;let o=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;if(!o)return t;let n=o/e;return Number((t*n).toFixed(3))}function ce(t){let e;const o={panning:!0,interacting:!1,mousewheel:{enabled:!0},scaling:{min:.1,max:10}};function n(s){const l=W(o,t);e=new U.Graph({container:s,...l})}function r(s){e.resetCells(s)}function a(s,l="LR"){const{node_w:f,node_h:b,nodesep:A,ranksep:C}=s,se=e.getNodes(),H=e.getEdges(),x=new O.graphlib.Graph;x.setGraph({rankdir:l,nodesep:A,ranksep:C}),x.setDefaultEdgeLabel(()=>({}));const le=f,ue=b;se.forEach(p=>{x.setNode(p.id,{width:le,height:ue})}),H.forEach(p=>{const P=p.getSource(),F=p.getTarget();x.setEdge(P.cell,F.cell)}),O.layout(x),x.nodes().forEach(p=>{const P=e.getCellById(p);if(P){const F=x.node(p);P.position(F.x,F.y)}}),H.forEach(p=>{const P=p.getSourceNode(),F=p.getTargetNode(),w=P.getBBox(),E=F.getBBox();if((l==="LR"||l==="RL")&&w.y!==E.y){const _=l==="LR"?E.x-w.x-w.width:-w.x+E.x+E.width,D=l==="LR"?w.width:0,I=w.x+D+_/2;p.setVertices([{x:I,y:w.center.y},{x:I,y:E.center.y}])}else if((l==="TB"||l==="BT")&&w.x!==E.x){const _=l==="TB"?E.y-w.y-w.height:-w.y+E.y+E.height,D=l==="TB"?w.height:0,I=w.y+D+_/2;p.setVertices([{x:w.center.x,y:I},{x:E.center.x,y:I}])}else p.setVertices([])})}function u(s){e.zoomToFit({padding:s,maxScale:1.2}),e.centerContent()}function c(s){const l=[];return s.forEach(f=>{const b=e.createNode(f);l.push(b)}),l}function i(s){const l=[];return s.forEach(f=>{const b=e.createEdge({shape:f.shape,source:{cell:f.source_id},target:{cell:f.target_id}});l.push(b)}),l}function m(s){Object.keys(s).forEach(f=>{const b=s[f];s[f]=l(b,"g",e),e.on(f,s[f])});function l(f,b,A){return function(...C){return C[0][b]=A,f.apply(this,C)}}}function g(s){Object.keys(s.nodes).forEach(l=>{const f=s.nodes[l];U.Graph.registerNode(l,f,!0)}),Object.keys(s.edges).forEach(l=>{const f=s.edges[l];U.Graph.registerEdge(l,f,!0)})}function y(){return e.getNodes()}function h(){e?.clearCells()}return{init:n,add_graph_elements:r,layout:a,center_content:u,createNodes:c,createEdges:i,register_event:m,register_custom_elements:g,get_nodes:y,clear:h}}function ie(t){const e=S.ref(!1);let o=S.shallowRef(null);S.onMounted(()=>{o.value=document.querySelector(t),o.value?.addEventListener("fullscreenchange",r)}),S.onUnmounted(()=>{o.value?.removeEventListener("fullscreenchange",r)});function n(){e.value?document.exitFullscreen&&document.exitFullscreen():o.value?.requestFullscreen&&o.value?.requestFullscreen(),e.value=!e.value}function r(){e.value=document.fullscreenElement===o.value}return{container:o,full:e,on_change:n}}d.canvastoDataURL=j,d.canvastoFile=Y,d.compress=ne,d.compressAccurately=oe,d.dataURLtoFile=M,d.dataURLtoImage=z,d.downloadFile=Z,d.filetoDataURL=T,d.imagetoCanvas=q,d.urltoBlob=ee,d.urltoImage=te,d.useEmits=V,d.useFile=Q,d.useFullScreen=ie,d.useLayoutFlow=ce,d.usePrintHtml=$,d.useWaterMark=K,d.useWebSocket=X,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import { useEmits as
|
|
2
|
-
import { useFile as
|
|
3
|
-
import { usePrintHtml as
|
|
4
|
-
import { useWaterMark as
|
|
5
|
-
import { useWebSocket as
|
|
6
|
-
import { compress as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
1
|
+
import { useEmits as f } from "./use-emit/index.js";
|
|
2
|
+
import { useFile as l } from "./use-file/index.js";
|
|
3
|
+
import { usePrintHtml as u } from "./use-print/index.js";
|
|
4
|
+
import { useWaterMark as d } from "./use-waterMark/index.js";
|
|
5
|
+
import { useWebSocket as c } from "./use-websocket/index.js";
|
|
6
|
+
import { compress as F, compressAccurately as L } from "./use-image/index.js";
|
|
7
|
+
import "./node_modules/@qy_better_lib/core/lib/directives/click-outside.js";
|
|
8
|
+
import "./use-chart/default.js";
|
|
9
|
+
import "vue";
|
|
10
|
+
import { useLayoutFlow as U } from "./use-layout-flow/index.js";
|
|
11
|
+
import "mqtt";
|
|
12
|
+
import { useFullScreen as v } from "./use-utils/use-fullscreen.js";
|
|
13
|
+
import { default as k } from "./use-image/canvastoDataURL.js";
|
|
14
|
+
import { default as y } from "./use-image/canvastoFile.js";
|
|
15
|
+
import { default as I } from "./use-image/dataURLtoFile.js";
|
|
16
|
+
import { default as W } from "./use-image/dataURLtoImage.js";
|
|
17
|
+
import { default as B } from "./use-image/downloadFile.js";
|
|
18
|
+
import { default as E } from "./use-image/filetoDataURL.js";
|
|
19
|
+
import { default as M } from "./use-image/imagetoCanvas.js";
|
|
20
|
+
import { default as h } from "./use-image/urltoBlob.js";
|
|
21
|
+
import { default as q } from "./use-image/urltoImage.js";
|
|
16
22
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
u as
|
|
23
|
+
k as canvastoDataURL,
|
|
24
|
+
y as canvastoFile,
|
|
25
|
+
F as compress,
|
|
26
|
+
L as compressAccurately,
|
|
27
|
+
I as dataURLtoFile,
|
|
28
|
+
W as dataURLtoImage,
|
|
29
|
+
B as downloadFile,
|
|
30
|
+
E as filetoDataURL,
|
|
31
|
+
M as imagetoCanvas,
|
|
32
|
+
h as urltoBlob,
|
|
33
|
+
q as urltoImage,
|
|
34
|
+
f as useEmits,
|
|
35
|
+
l as useFile,
|
|
36
|
+
v as useFullScreen,
|
|
37
|
+
U as useLayoutFlow,
|
|
38
|
+
u as usePrintHtml,
|
|
39
|
+
d as useWaterMark,
|
|
40
|
+
c as useWebSocket
|
|
33
41
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isClient as s } from "../utils/is.js";
|
|
2
|
+
const d = /* @__PURE__ */ new Map();
|
|
3
|
+
let n;
|
|
4
|
+
s && (document.addEventListener("mousedown", (e) => n = e), document.addEventListener("mouseup", (e) => {
|
|
5
|
+
for (const o of d.values())
|
|
6
|
+
for (const { documentHandler: t } of o)
|
|
7
|
+
t(e, n);
|
|
8
|
+
}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isObject as i } from "./is.js";
|
|
2
|
+
function f(...e) {
|
|
3
|
+
let l = e.length, o = e[0];
|
|
4
|
+
i(o) || (o = {});
|
|
5
|
+
for (let n = 1; n < l; n++) {
|
|
6
|
+
let r = e[n];
|
|
7
|
+
if (i(r))
|
|
8
|
+
for (let t in r)
|
|
9
|
+
t === "__proto__" || o === r[t] || (i(r[t]) ? o[t] = f(o[t], r[t]) : o[t] = r[t]);
|
|
10
|
+
}
|
|
11
|
+
return o;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
f as deepAssign
|
|
15
|
+
};
|
|
@@ -6,5 +6,5 @@ declare const options: ECOption;
|
|
|
6
6
|
* @param defalteWidth
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
export declare function auto_chart_size(size: number, defalteWidth?: number): number
|
|
9
|
+
export declare function auto_chart_size(size: number, defalteWidth?: number): number;
|
|
10
10
|
export default options;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
t(12), t(14), t(12), t(8), t(16), t(12), t(12), t(12), t(12);
|
|
2
|
+
function t(e, n = 1920) {
|
|
3
|
+
if (!e) return 0;
|
|
4
|
+
let i = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
5
|
+
if (!i) return e;
|
|
6
|
+
let o = i / n;
|
|
7
|
+
return Number((e * o).toFixed(3));
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
t as auto_chart_size
|
|
11
|
+
};
|
package/lib/use-chart/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ import * as echarts from 'echarts/core';
|
|
|
5
5
|
* @returns echartsType
|
|
6
6
|
*/
|
|
7
7
|
export default function useEcharts(): {
|
|
8
|
+
renderChart?: undefined;
|
|
9
|
+
removeChart?: undefined;
|
|
10
|
+
getChart?: undefined;
|
|
11
|
+
} | {
|
|
8
12
|
renderChart: (option: ECOption, domId: string, isdark?: boolean, renderer?: "canvas" | "svg") => echarts.ECharts | undefined;
|
|
9
13
|
removeChart: (domId: string) => void;
|
|
10
14
|
getChart: (domId: string) => echarts.ECharts | undefined;
|
package/lib/use-emit/extend.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import n from "mitt";
|
|
2
|
+
function u() {
|
|
3
|
+
if (typeof n > "u")
|
|
4
|
+
return {};
|
|
5
|
+
const t = n();
|
|
6
|
+
return t.emitAsync = async function(o, ...s) {
|
|
7
|
+
const r = this.all?.get(o);
|
|
8
|
+
if (!r || r.length === 0)
|
|
7
9
|
return [];
|
|
8
|
-
const
|
|
10
|
+
const i = r.map((c) => {
|
|
9
11
|
try {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
} catch (
|
|
13
|
-
return Promise.reject(
|
|
12
|
+
const e = c(...s);
|
|
13
|
+
return e instanceof Promise ? e : Promise.resolve(e);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return Promise.reject(e);
|
|
14
16
|
}
|
|
15
17
|
});
|
|
16
|
-
return Promise.all(
|
|
17
|
-
},
|
|
18
|
+
return Promise.all(i);
|
|
19
|
+
}, t;
|
|
18
20
|
}
|
|
19
21
|
export {
|
|
20
|
-
|
|
22
|
+
u as createAsyncEmitter
|
|
21
23
|
};
|
package/lib/use-emit/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import m from "mitt";
|
|
2
|
+
import { onMounted as e, onUnmounted as u } from "vue";
|
|
3
|
+
import { createAsyncEmitter as n } from "./extend.js";
|
|
4
|
+
const f = n();
|
|
5
|
+
function p(o) {
|
|
6
|
+
return typeof m > "u" ? { emitter: f } : (e(() => {
|
|
6
7
|
if (o && o.length > 0)
|
|
7
8
|
for (let r = 0; r < o.length; r++) {
|
|
8
9
|
debugger;
|
|
@@ -14,8 +15,8 @@ function a(o) {
|
|
|
14
15
|
f.off(o[r].key, o[r].value), f.all.delete(o[r].key);
|
|
15
16
|
}), {
|
|
16
17
|
emitter: f
|
|
17
|
-
};
|
|
18
|
+
});
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
20
|
-
|
|
21
|
+
p as useEmits
|
|
21
22
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Graph as x } from "@antv/x6";
|
|
2
|
+
import { deepAssign as F } from "../node_modules/@qy_better_lib/core/lib/utils/object.js";
|
|
3
|
+
import "../node_modules/@qy_better_lib/core/lib/directives/click-outside.js";
|
|
4
|
+
import y from "dagre";
|
|
5
|
+
function k(E) {
|
|
6
|
+
let c;
|
|
7
|
+
const B = {
|
|
8
|
+
panning: !0,
|
|
9
|
+
// 画布可拖动
|
|
10
|
+
interacting: !1,
|
|
11
|
+
// 边、节点是否可以拖动大小调整等
|
|
12
|
+
mousewheel: {
|
|
13
|
+
enabled: !0
|
|
14
|
+
// 开启滚轮交互
|
|
15
|
+
},
|
|
16
|
+
scaling: { min: 0.1, max: 10 }
|
|
17
|
+
};
|
|
18
|
+
function w(t) {
|
|
19
|
+
const e = F(B, E);
|
|
20
|
+
c = new x({ container: t, ...e });
|
|
21
|
+
}
|
|
22
|
+
function _(t) {
|
|
23
|
+
c.resetCells(t);
|
|
24
|
+
}
|
|
25
|
+
function N(t, e = "LR") {
|
|
26
|
+
const { node_w: o, node_h: a, nodesep: h, ranksep: f } = t, O = c.getNodes(), m = c.getEdges(), g = new y.graphlib.Graph();
|
|
27
|
+
g.setGraph({ rankdir: e, nodesep: h, ranksep: f }), g.setDefaultEdgeLabel(() => ({}));
|
|
28
|
+
const S = o, V = a;
|
|
29
|
+
O.forEach((s) => {
|
|
30
|
+
g.setNode(s.id, { width: S, height: V });
|
|
31
|
+
}), m.forEach((s) => {
|
|
32
|
+
const i = s.getSource(), u = s.getTarget();
|
|
33
|
+
g.setEdge(i.cell, u.cell);
|
|
34
|
+
}), y.layout(g), g.nodes().forEach((s) => {
|
|
35
|
+
const i = c.getCellById(s);
|
|
36
|
+
if (i) {
|
|
37
|
+
const u = g.node(s);
|
|
38
|
+
i.position(u.x, u.y);
|
|
39
|
+
}
|
|
40
|
+
}), m.forEach((s) => {
|
|
41
|
+
const i = s.getSourceNode(), u = s.getTargetNode(), n = i.getBBox(), r = u.getBBox();
|
|
42
|
+
if ((e === "LR" || e === "RL") && n.y !== r.y) {
|
|
43
|
+
const l = e === "LR" ? r.x - n.x - n.width : -n.x + r.x + r.width, p = e === "LR" ? n.width : 0, d = n.x + p + l / 2;
|
|
44
|
+
s.setVertices([
|
|
45
|
+
{ x: d, y: n.center.y },
|
|
46
|
+
{ x: d, y: r.center.y }
|
|
47
|
+
]);
|
|
48
|
+
} else if ((e === "TB" || e === "BT") && n.x !== r.x) {
|
|
49
|
+
const l = e === "TB" ? r.y - n.y - n.height : -n.y + r.y + r.height, p = e === "TB" ? n.height : 0, d = n.y + p + l / 2;
|
|
50
|
+
s.setVertices([
|
|
51
|
+
{ x: n.center.x, y: d },
|
|
52
|
+
{ x: r.center.x, y: d }
|
|
53
|
+
]);
|
|
54
|
+
} else
|
|
55
|
+
s.setVertices([]);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function L(t) {
|
|
59
|
+
c.zoomToFit({ padding: t, maxScale: 1.2 }), c.centerContent();
|
|
60
|
+
}
|
|
61
|
+
function T(t) {
|
|
62
|
+
const e = [];
|
|
63
|
+
return t.forEach((o) => {
|
|
64
|
+
const a = c.createNode(o);
|
|
65
|
+
e.push(a);
|
|
66
|
+
}), e;
|
|
67
|
+
}
|
|
68
|
+
function b(t) {
|
|
69
|
+
const e = [];
|
|
70
|
+
return t.forEach((o) => {
|
|
71
|
+
const a = c.createEdge({
|
|
72
|
+
shape: o.shape,
|
|
73
|
+
source: { cell: o.source_id },
|
|
74
|
+
target: { cell: o.target_id }
|
|
75
|
+
});
|
|
76
|
+
e.push(a);
|
|
77
|
+
}), e;
|
|
78
|
+
}
|
|
79
|
+
function R(t) {
|
|
80
|
+
Object.keys(t).forEach((o) => {
|
|
81
|
+
const a = t[o];
|
|
82
|
+
t[o] = e(a, "g", c), c.on(o, t[o]);
|
|
83
|
+
});
|
|
84
|
+
function e(o, a, h) {
|
|
85
|
+
return function(...f) {
|
|
86
|
+
return f[0][a] = h, o.apply(this, f);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function C(t) {
|
|
91
|
+
Object.keys(t.nodes).forEach((e) => {
|
|
92
|
+
const o = t.nodes[e];
|
|
93
|
+
x.registerNode(e, o, !0);
|
|
94
|
+
}), Object.keys(t.edges).forEach((e) => {
|
|
95
|
+
const o = t.edges[e];
|
|
96
|
+
x.registerEdge(e, o, !0);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function j() {
|
|
100
|
+
return c.getNodes();
|
|
101
|
+
}
|
|
102
|
+
function G() {
|
|
103
|
+
c?.clearCells();
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
init: w,
|
|
107
|
+
add_graph_elements: _,
|
|
108
|
+
layout: N,
|
|
109
|
+
center_content: L,
|
|
110
|
+
createNodes: T,
|
|
111
|
+
createEdges: b,
|
|
112
|
+
register_event: R,
|
|
113
|
+
register_custom_elements: C,
|
|
114
|
+
get_nodes: j,
|
|
115
|
+
clear: G
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
k as useLayoutFlow
|
|
120
|
+
};
|
package/lib/use-mqtt/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { default as mqtt } from 'mqtt';
|
|
2
2
|
export default function useMQTT(url: string, options?: mqtt.IClientOptions): {
|
|
3
|
+
connect?: undefined;
|
|
4
|
+
close?: undefined;
|
|
5
|
+
subscribe?: undefined;
|
|
6
|
+
unsubscribe?: undefined;
|
|
7
|
+
publish?: undefined;
|
|
8
|
+
} | {
|
|
3
9
|
connect: ({ success, err, receive }: {
|
|
4
10
|
success: () => void;
|
|
5
11
|
err: (e: any) => void;
|
|
6
|
-
receive: (...args: any) => void;
|
|
12
|
+
receive: (...args: any[]) => void;
|
|
7
13
|
}) => void;
|
|
8
14
|
close: () => void;
|
|
9
15
|
subscribe: (topic: any) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ref as c, shallowRef as r, onMounted as o, onUnmounted as a } from "vue";
|
|
2
|
+
function f(u) {
|
|
3
|
+
const l = c(!1);
|
|
4
|
+
let e = r(null);
|
|
5
|
+
o(() => {
|
|
6
|
+
e.value = document.querySelector(u), e.value?.addEventListener("fullscreenchange", n);
|
|
7
|
+
}), a(() => {
|
|
8
|
+
e.value?.removeEventListener("fullscreenchange", n);
|
|
9
|
+
});
|
|
10
|
+
function t() {
|
|
11
|
+
l.value ? document.exitFullscreen && document.exitFullscreen() : e.value?.requestFullscreen && e.value?.requestFullscreen(), l.value = !l.value;
|
|
12
|
+
}
|
|
13
|
+
function n() {
|
|
14
|
+
l.value = document.fullscreenElement === e.value;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
container: e,
|
|
18
|
+
full: l,
|
|
19
|
+
on_change: t
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
f as useFullScreen
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qy_better_lib/hooks",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.8",
|
|
5
5
|
"description": "qy better lib hooks",
|
|
6
6
|
"author": "luhuiming",
|
|
7
7
|
"license": "ISC",
|
|
@@ -33,11 +33,7 @@
|
|
|
33
33
|
"exports": {
|
|
34
34
|
".": {
|
|
35
35
|
"import": "./lib/index.js"
|
|
36
|
-
}
|
|
37
|
-
"./use-chart": "./lib/use-chart/index.js",
|
|
38
|
-
"./use-chart/*": "./lib/use-chart/*/*.js",
|
|
39
|
-
"./use-utils": "./lib/use-utils/index.js",
|
|
40
|
-
"./use-utils/*": "./lib/use-utils/*/*.js"
|
|
36
|
+
}
|
|
41
37
|
},
|
|
42
38
|
"devDependencies": {
|
|
43
39
|
"@antv/x6": "^2.18.1",
|
|
@@ -52,5 +48,28 @@
|
|
|
52
48
|
"vite-plugin-dts": "^4.5.4",
|
|
53
49
|
"vue": "^3.5.22"
|
|
54
50
|
},
|
|
55
|
-
"
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@antv/x6": "^2.18.1",
|
|
53
|
+
"dagre": "^0.8.5",
|
|
54
|
+
"echarts": "5.6.0",
|
|
55
|
+
"mitt": "^3.0.1",
|
|
56
|
+
"mqtt": "^5.14.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@antv/x6": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"dagre": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"echarts": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"mitt": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"mqtt": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
56
75
|
}
|