@deep-eye/core 0.1.0
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/README.md +49 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/visualization/D3MindMap.vue.d.ts +75 -0
- package/dist/components/visualization/D3MindMap.vue.d.ts.map +1 -0
- package/dist/components/visualization/index.d.ts +5 -0
- package/dist/components/visualization/index.d.ts.map +1 -0
- package/dist/components/visualization/themes.d.ts +40 -0
- package/dist/components/visualization/themes.d.ts.map +1 -0
- package/dist/components/visualization/types.d.ts +291 -0
- package/dist/components/visualization/types.d.ts.map +1 -0
- package/dist/components/visualization/utils.d.ts +48 -0
- package/dist/components/visualization/utils.d.ts.map +1 -0
- package/dist/composables/index.d.ts +3 -0
- package/dist/composables/index.d.ts.map +1 -0
- package/dist/composables/useMindMapLayout.d.ts +16 -0
- package/dist/composables/useMindMapLayout.d.ts.map +1 -0
- package/dist/composables/useMindMapTheme.d.ts +43 -0
- package/dist/composables/useMindMapTheme.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1351 -0
- package/dist/style.css +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +53 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),yt=require("d3"),mt=require("gsap"),gt=require("@vueuse/core");function pt(i){const h=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const c in i)if(c!=="default"){const s=Object.getOwnPropertyDescriptor(i,c);Object.defineProperty(h,c,s.get?s:{enumerable:!0,get:()=>i[c]})}}return h.default=i,Object.freeze(h)}const g=pt(yt),oe={name:"default",nodeStyle:{colors:["rgb(195, 202, 255)","rgb(186, 211, 238)","rgb(162, 220, 208)","rgb(157, 236, 187)","rgb(205, 254, 165)"],textColor:"rgb(0, 0, 0)",fontSize:20,fontFamily:'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:500,borderRadius:8,padding:[18,27.5],minWidth:100,minHeight:55,borderWidth:0,borderStyle:"none"},linkStyle:{color:(i,h)=>{const c=h;return c===1?"rgb(195, 202, 255)":c===2?"rgb(186, 211, 238)":c===3?"rgb(162, 220, 208)":c===4?"rgb(157, 236, 187)":"rgb(195, 202, 255)"},width:2.5,style:"solid",curve:"bezier"},background:"#f8f9fa",grid:{show:!0,color:"#e0e0e0",size:20}},Ae={name:"dark",nodeStyle:{colors:["rgb(88, 86, 214)","rgb(52, 168, 83)","rgb(251, 188, 4)","rgb(234, 67, 53)","rgb(66, 133, 244)"],textColor:"rgb(255, 255, 255)",fontSize:20,fontFamily:'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:500,borderRadius:8,padding:[18,27.5],minWidth:100,minHeight:55,borderWidth:0,borderStyle:"none"},linkStyle:{color:(i,h)=>{const c=h;return c===1?"rgb(88, 86, 214)":c===2?"rgb(52, 168, 83)":c===3?"rgb(251, 188, 4)":c===4?"rgb(234, 67, 53)":"rgb(66, 133, 244)"},width:2.5,style:"solid",curve:"bezier"},background:"#2b2d30",grid:{show:!0,color:"#3c3f41",size:20}},Re={name:"colorful",nodeStyle:{colors:["rgb(255, 107, 107)","rgb(255, 184, 77)","rgb(72, 219, 251)","rgb(129, 236, 236)","rgb(255, 159, 243)"],textColor:"rgb(255, 255, 255)",fontSize:20,fontFamily:'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:500,borderRadius:10,padding:[18,27.5],minWidth:100,minHeight:55,borderWidth:0,borderStyle:"none"},linkStyle:{color:(i,h)=>{const c=h;return c===1?"rgb(255, 107, 107)":c===2?"rgb(255, 184, 77)":c===3?"rgb(72, 219, 251)":c===4?"rgb(129, 236, 236)":"rgb(255, 159, 243)"},width:2.5,style:"solid",curve:"bezier"},background:"#fafafa",grid:{show:!0,color:"#eeeeee",size:20}},Oe={name:"minimal",nodeStyle:{colors:["rgb(255, 255, 255)","rgb(255, 255, 255)","rgb(255, 255, 255)","rgb(255, 255, 255)","rgb(255, 255, 255)"],textColor:"rgb(51, 51, 51)",fontSize:20,fontFamily:'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:400,borderRadius:6,padding:[18,27.5],minWidth:100,minHeight:55,borderWidth:2,borderColor:"rgb(189, 189, 189)",borderStyle:"solid"},linkStyle:{color:"rgb(189, 189, 189)",width:2,style:"solid",curve:"bezier"},background:"#ffffff",grid:{show:!1}},Ge={name:"professional",nodeStyle:{colors:["rgb(79, 129, 189)","rgb(155, 187, 89)","rgb(192, 80, 77)","rgb(128, 100, 162)","rgb(75, 172, 198)"],textColor:"rgb(255, 255, 255)",fontSize:20,fontFamily:'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:500,borderRadius:6,padding:[18,27.5],minWidth:100,minHeight:55,borderWidth:0,borderStyle:"none"},linkStyle:{color:(i,h)=>{const c=h;return c===1?"rgb(79, 129, 189)":c===2?"rgb(155, 187, 89)":c===3?"rgb(192, 80, 77)":c===4?"rgb(128, 100, 162)":"rgb(75, 172, 198)"},width:2.5,style:"solid",curve:"bezier"},background:"#f5f5f5",grid:{show:!0,color:"#e0e0e0",size:20}},Ue={default:oe,dark:Ae,colorful:Re,minimal:Oe,professional:Ge};function xt(i){return Ue[i]||oe}function _e(i,h){return{...i,...h,nodeStyle:{...i.nodeStyle,...h.nodeStyle},linkStyle:{...i.linkStyle,...h.linkStyle},layoutConfig:{...i.layoutConfig,...h.layoutConfig},grid:{...i.grid,...h.grid}}}function Ze(i,h,c){const s=r.computed(()=>{let x;return typeof i=="function"?x=i()||oe:x=r.unref(i)||oe,(h||c)&&(x=_e(x,{nodeStyle:h,linkStyle:c})),x}),b=(x,T)=>{var te;const f=s.value.nodeStyle;if(f!=null&&f.backgroundColor)return typeof f.backgroundColor=="function"?f.backgroundColor(x,T):f.backgroundColor;if(f!=null&&f.colors)return typeof f.colors=="function"?f.colors(x,T):Array.isArray(f.colors)?f.colors[Math.min(T,f.colors.length-1)]:String(f.colors);const I=(te=oe.nodeStyle)==null?void 0:te.colors;return Array.isArray(I)&&I[Math.min(T,4)]||"rgb(195, 202, 255)"},v=(x,T)=>{var te;const f=s.value.nodeStyle;if(f!=null&&f.textColor)return typeof f.textColor=="function"?f.textColor(x,T):f.textColor;const I=(te=oe.nodeStyle)==null?void 0:te.textColor;return typeof I=="string"?I:"rgb(0, 0, 0)"},N=(x,T)=>{const f=s.value.nodeStyle;if(f!=null&&f.borderColor)return typeof f.borderColor=="function"?f.borderColor(x,T):f.borderColor};return{finalTheme:s,getNodeColor:b,getNodeTextColor:v,getNodeBorderColor:N,getLinkColor:(x,T)=>{const f=s.value.linkStyle;if(f!=null&&f.color)return typeof f.color=="function"?f.color(x,T):f.color;const I=T;return I===1?"rgb(195, 202, 255)":I===2?"rgb(186, 211, 238)":I===3?"rgb(162, 220, 208)":I===4?"rgb(157, 236, 187)":"rgb(195, 202, 255)"},getNodeStyle:(x,T)=>{const f=s.value.nodeStyle||{};return{backgroundColor:b(x,T),color:v(x,T),fontSize:f.fontSize?typeof f.fontSize=="number"?`${f.fontSize}px`:f.fontSize:"20px",fontFamily:f.fontFamily||'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif',fontWeight:f.fontWeight||500,borderRadius:f.borderRadius!==void 0?`${f.borderRadius}px`:"8px",borderWidth:f.borderWidth!==void 0?`${f.borderWidth}px`:"0",borderColor:N(x,T),borderStyle:f.borderStyle||"none"}},getNodePadding:()=>{const x=s.value.nodeStyle,T=x==null?void 0:x.padding;return Array.isArray(T)?T:typeof T=="number"?[T,T]:[18,27.5]},getNodeMinSize:()=>{const x=s.value.nodeStyle;return{minWidth:(x==null?void 0:x.minWidth)||100,minHeight:(x==null?void 0:x.minHeight)||55}},getLinkWidth:()=>{var x;return((x=s.value.linkStyle)==null?void 0:x.width)||2.5},getLinkStyle:()=>{var x;return((x=s.value.linkStyle)==null?void 0:x.style)||"solid"},getBackgroundStyle:()=>{const x=s.value.background||"#f8f9fa",T=s.value.grid;if((T==null?void 0:T.show)===!1)return{backgroundColor:x};const f=(T==null?void 0:T.color)||"#e0e0e0",I=(T==null?void 0:T.size)||20;return{backgroundColor:x,backgroundImage:`radial-gradient(circle, ${f} 1px, transparent 1px)`,backgroundSize:`${I}px ${I}px`}}}}function qe(i){const h=r.computed(()=>(i==null?void 0:i.direction)||"horizontal"),c=r.computed(()=>i==null?void 0:i.nodeSpacing),s=r.computed(()=>i==null?void 0:i.levelSpacing),b=r.computed(()=>(i==null?void 0:i.align)||"center"),v=r.computed(()=>h.value==="horizontal"),N=r.computed(()=>h.value==="vertical");return{direction:h,nodeSpacing:c,levelSpacing:s,align:b,isHorizontal:v,isVertical:N,getNodeSpacing:()=>c.value,getLevelSpacing:()=>s.value,getAlign:()=>b.value}}function vt(){return Math.random().toString(36).substring(2,15)}function we(i,h){const s=document.createElement("canvas").getContext("2d");return s?(s.font=h,s.measureText(i).width):100}function Ve(i){if(i===null||typeof i!="object")return i;if(i instanceof Date)return new Date(i.getTime());if(i instanceof Array)return i.map(h=>Ve(h));if(i instanceof Object){const h={};for(const c in i)i.hasOwnProperty(c)&&(h[c]=Ve(i[c]));return h}return i}function bt(i,h){let c=null;return function(...s){const b=this;c&&clearTimeout(c),c=setTimeout(()=>{i.apply(b,s),c=null},h)}}function kt(i,h){let c=null,s=0;return function(...b){const v=this,N=Date.now();s||(s=N);const D=h-(N-s);D<=0||D>h?(c&&(clearTimeout(c),c=null),s=N,i.apply(v,b)):c||(c=setTimeout(()=>{s=Date.now(),c=null,i.apply(v,b)},D))}}function je(i,h){return new Promise((c,s)=>{try{let v=new XMLSerializer().serializeToString(i);h&&(v=v.replace("<svg",`<svg style="background-color: ${h}"`));const N=new Blob([v],{type:"image/svg+xml;charset=utf-8"});c(N)}catch(b){s(b)}})}function Qe(i,h={}){return new Promise((c,s)=>{try{const{scale:b=2,backgroundColor:v="#ffffff",quality:N=1}=h;let K=new XMLSerializer().serializeToString(i);v&&(K=K.replace("<svg",`<svg style="background-color: ${v}"`));const R=document.createElement("canvas"),ee=R.getContext("2d");if(!ee){s(new Error("Failed to get canvas context"));return}const O=new Image,ce=new Blob([K],{type:"image/svg+xml;charset=utf-8"}),A=URL.createObjectURL(ce);O.onload=()=>{R.width=O.width*b,R.height=O.height*b,ee.scale(b,b),ee.drawImage(O,0,0),URL.revokeObjectURL(A),R.toBlob(x=>{x?c(x):s(new Error("Failed to convert canvas to blob"))},"image/png",N)},O.onerror=()=>{URL.revokeObjectURL(A),s(new Error("Failed to load SVG image"))},O.src=A}catch(b){s(b)}})}function wt(i,h){const c=URL.createObjectURL(i),s=document.createElement("a");s.href=c,s.download=h,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(c)}function St(i){return i.includes("gradient")}function Mt(i){const h=i.match(/#[0-9a-fA-F]{6}|rgb\([^)]+\)/);return h?h[0]:"#000000"}const Tt={key:0,class:"toolbar-scale"},Et=["title"],Ct={key:0,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},Nt={key:1,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},Dt={key:1,class:"toolbar-divider"},zt={key:3,class:"toolbar-count",title:"节点总数"},Wt={class:"count-value"},Le=18,Xe=.3,Bt=r.defineComponent({__name:"D3MindMap",props:{data:{default:()=>({nodeData:{id:"root",topic:"思维导图",root:!0,children:[]}})},readonly:{type:Boolean,default:!0},height:{default:"100%"},width:{default:"100%"},showToolbar:{type:Boolean,default:!1},showDownload:{type:Boolean,default:!0},showCounts:{type:Boolean,default:!1},showScale:{type:Boolean,default:!0},toolbarPosition:{default:"bottom"},theme:{},nodeStyle:{},linkStyle:{},layoutConfig:{}},emits:["change","node-click","node-dblclick","node-contextmenu","node-mouseenter","node-mouseleave","node-expand","node-collapse","zoom","pan","download","ready"],setup(i,{expose:h,emit:c}){const s=i,b=c,v=r.ref(null),N=r.ref(null),D=r.ref(null),K=r.ref(800),{getNodeColor:R,getNodeTextColor:ee,getNodeBorderColor:O,getLinkColor:ce,getNodeStyle:A,getNodePadding:x,getNodeMinSize:T,getLinkWidth:f,getLinkStyle:I,getBackgroundStyle:te}=Ze(()=>s.theme,s.nodeStyle,s.linkStyle),{isHorizontal:$t,getNodeSpacing:Ft,getLevelSpacing:It}=qe(s.layoutConfig),Je=r.computed(()=>`toolbar-${s.toolbarPosition}`);let Y=null,H=g.zoomIdentity,ue=!1,de=null,ae=!1,ne=null,le={vx:0,vy:0},Se="",j=!1,re=!1,fe=null,L=null;const ie=new Set,he=new Map,ge=new Map,Pe=t=>{const n=a=>{a&&(a._prevX=a.x,a._prevY=a.y,a.children&&a.children.forEach(n))};n(t)},_=r.ref(null),W=r.ref(null),$=r.ref(1),Ke=r.computed(()=>Math.round($.value*100)),$e=r.computed(()=>{if(!W.value)return 0;let t=0;const n=(a,l=!0)=>{l&&(a.parent&&a.parent.data&&a.parent.data.expanded===!1||(t++,a.children&&a.data.expanded!==!1&&a.children.forEach(y=>n(y,!0))))};return n(W.value,!0),t}),Me=r.computed(()=>{if(!_.value)return!0;const t=n=>n.children&&n.children.length>0?n.expanded===!1?!1:n.children.every(a=>t(a)):!0;return t(_.value)}),pe=r.ref(!0),et=r.computed(()=>({height:typeof s.height=="number"?`${s.height}px`:s.height,width:typeof s.width=="number"?`${s.width}px`:s.width})),w={expandDuration:420,collapseDuration:320,expandEase:g.easeCubicOut,collapseEase:g.easeQuadOut,expandStartDelay:10,transformDuration:.28,centerDuration:1.05,transformEase:"power1.out",centerEase:"power2.out",nodeScaleFrom:.8,nodeScaleTo:1,linkFadeDuration:150},Fe=t=>{if(t.parent){const n=t.x0===void 0||t.y0===void 0,a=t.x0!==void 0&&t.y0!==void 0&&Math.abs(t.x0-t.parent.x)<2&&Math.abs(t.y0-t.parent.y)<2;if(n||a)return j?w.expandStartDelay:0}return 0},xe=t=>{N.value&&g.select(N.value).attr("transform",`translate(${t.x},${t.y}) scale(${t.k})`)},Q=(t,n={})=>{if(n.duration===0){H=t,$.value=t.k,xe(t),n.syncZoom&&Y&&v.value&&(ae=!0,g.select(v.value).call(Y.transform,t),setTimeout(()=>{ae=!1},0)),n.onComplete&&n.onComplete();return}const{duration:a=.55,ease:l="power2.out",syncZoom:y=!1,onComplete:p}=n;de==null||de.kill();const S={x:H.x,y:H.y,k:H.k};return de=mt.gsap.to(S,{x:t.x,y:t.y,k:t.k,duration:a,ease:l,overwrite:"auto",onUpdate:()=>{const m=g.zoomIdentity.translate(S.x,S.y).scale(S.k);H=m,$.value=m.k,xe(m)},onComplete:()=>{const m=g.zoomIdentity.translate(t.x,t.y).scale(t.k);H=m,$.value=m.k,xe(m),y&&Y&&v.value&&(ae=!0,g.select(v.value).call(Y.transform,m),setTimeout(()=>{ae=!1},0)),p&&p()}}),de},Te=()=>Math.random().toString(36).substring(2,15),Ie=t=>{var a;if((a=t==null?void 0:t.nodeData)!=null&&a.topic)return t.nodeData;const n=(l,y=!1,p=0)=>{var m,C;if(!l)return{topic:"思维导图",id:Te(),expanded:!0};const S={topic:((m=l.data)==null?void 0:m.text)||"未命名",id:Te(),expanded:!0};return y&&(S.root=!0),((C=l.children)==null?void 0:C.length)>0&&(S.children=l.children.map(k=>n(k,!1,p+1))),S};return n(t,!0)},Ee=(t,n=0,a=1)=>{t.expanded=n<=a,t.children&&t.children.length>0&&t.children.forEach(l=>Ee(l,n+1,a))},Ye=t=>{const n=g.hierarchy(t,a=>a.children);return n.each(a=>{a.data&&(a.data._original=a.data)}),n},Ce=t=>{var l,y;if((l=t.data)!=null&&l._nodeWidth)return t.data._nodeWidth;const n=we(((y=t.data)==null?void 0:y.topic)||"",'20px "Google Sans"'),a=Math.max(n+36,100);return t.data&&(t.data._nodeWidth=a),a},tt=()=>52,ve=t=>{const n=g.hierarchy(t.data,u=>u.expanded===!1?null:u.children),a=tt();let l=1;n.each(u=>{u.children&&u.children.length>0&&(l=Math.max(l,u.children.length))});const y=Math.min(140,Math.max(80,90+(l-1)*6)),p={};n.each(u=>{const z=u.depth||0,e=Ce(u);p[z]=Math.max(p[z]||0,e)});const S=Math.max(...Object.values(p),100),m=Math.max(S+50,200);g.tree().nodeSize([y,m]).separation((u,z)=>{const o=(a+16)/y;return u.parent===z.parent?Math.max(1,o):1.2})(n);const k={0:0},V=Math.max(...Array.from(Object.keys(p)).map(Number));for(let u=1;u<=V;u++){const z=p[u-1]||100;k[u]=k[u-1]+z+80}n.each(u=>{const z=u.depth||0;u.y=k[z]});const F=new Map;n.each(u=>{F.set(u.data.id,{x:u.x,y:u.y})});const q=u=>{if(!u.parent)return{x:0,y:0};const z=F.get(u.parent.data.id);return z||q(u.parent)};t.each(u=>{const z=F.get(u.data.id);if(z)u.x=z.x,u.y=z.y;else{const e=q(u);u.x=e.x,u.y=e.y}});let P=1/0;t.each(u=>{u.y!==void 0&&u.y<P&&(P=u.y)}),P!==1/0&&P!==0&&t.each(u=>{u.y=(u.y||0)-P});const se=t.x||0;t.each(u=>{u.x=(u.x||0)-se});let B=1/0;if(t.each(u=>{u.x!==void 0&&u.x<B&&(B=u.x)}),B<0){const u=-B+8;t.each(z=>{z.x=(z.x||0)+u})}},nt=()=>{if(!v.value||!N.value)return;const t=Ie(s.data);Ee(t,0,0),_.value=t;const n=Ye(t);ve(n);let a=n.y||0;n.each(l=>{l.y<a&&(a=l.y)}),a!==0&&n.each(l=>{l.y=l.y-a}),n.y!==0&&(n.y=0),W.value=n,ye(),be(),ot(),r.nextTick(()=>{Z()})},be=()=>{if(!v.value||!N.value||!W.value)return;g.select(v.value);const t=g.select(N.value),n=t.select(".links"),a=t.select(".nodes"),l=[],y=[],p=(e,o=!0)=>{o&&(e.parent&&e.parent.data&&e.parent.data.expanded===!1||(l.push(e),e.children&&e.data.expanded!==!1&&e.children.forEach(d=>{y.push({source:e,target:d}),p(d,!0)})))};p(W.value,!0);const S=n.selectAll(".link").data(y,e=>`${e.source.data.id}-${e.target.data.id}`);S.exit().style("will-change","opacity, stroke-width").style("opacity",1).transition().duration(w.linkFadeDuration).ease(w.collapseEase).style("stroke-width","1px").style("opacity",0).on("end",function(){g.select(this).style("will-change","auto"),g.select(this).remove()});const C=e=>{const o=e.target.depth||0;return ce(e,o)};l.forEach(e=>{e.parent?(e.x0===void 0||e.y0===void 0||ie.has(e.data.id))&&(e.x0=e.parent.x,e.y0=e.parent.y):(e.x0===void 0&&(e.x0=e.x),e.y0===void 0&&(e.y0=e.y))});const k=(e,o)=>{var X;const d=((X=e.data)==null?void 0:X._nodeWidth)||Ce(e),E=e.x||0,M=e.y||0;return o==="source"?{x:E,y:M+(d-18+Le)}:{x:E,y:M-18}},V=(e,o)=>{const d=(e.y+o.y)/2,E=d,M=e.x,X=d,G=o.x;return`M ${e.y} ${e.x} C ${E} ${M}, ${X} ${G}, ${o.y} ${o.x}`},F=S.enter().append("path").attr("class","link").style("opacity",0).attr("d",e=>{const o=k({...e.source,x:e.source.x0??e.source.x,y:e.source.y0??e.source.y},"source"),d=k({...e.target,x:e.target.x0??e.target.x,y:e.target.y0??e.target.y},"target");return V(o,d)}).style("fill","none").style("stroke",e=>C(e)).style("stroke-width","1px");F.style("opacity",0).style("will-change","opacity, d, stroke-width"),S.style("will-change","opacity, d, stroke-width"),F.merge(S).transition().duration(w.expandDuration).ease(w.expandEase).delay(e=>Fe(e.target)).style("opacity",function(e){const o=parseFloat(g.select(this).style("opacity")||"1");return o===0?1:o}).style("stroke-width",`${f()}px`).attrTween("d",function(e){const o=k({...e.source,x:e.source.x0??e.source.x,y:e.source.y0??e.source.y},"source"),d=k({...e.target,x:e.target.x0??e.target.x,y:e.target.y0??e.target.y},"target"),E=k(e.source,"source"),M=k(e.target,"target");if(Math.abs(o.y-E.y)<.1&&Math.abs(o.x-E.x)<.1&&Math.abs(d.y-M.y)<.1&&Math.abs(d.x-M.x)<.1)return()=>V(E,M);const X=g.interpolateNumber(o.y,E.y),G=g.interpolateNumber(o.x,E.x),me=g.interpolateNumber(d.y,M.y),U=g.interpolateNumber(d.x,M.x);return J=>{const ft={y:X(J),x:G(J)},ht={y:me(J),x:U(J)};return V(ft,ht)}}).style("stroke",e=>C(e)).on("end",function(e){var o,d,E,M;e.source.x0=e.source.x,e.source.y0=e.source.y,e.target.x0=e.target.x,e.target.y0=e.target.y,(d=(o=e.source)==null?void 0:o.data)!=null&&d.id&&he.set(e.source.data.id,{x:e.source.x,y:e.source.y}),(M=(E=e.target)==null?void 0:E.data)!=null&&M.id&&he.set(e.target.data.id,{x:e.target.x,y:e.target.y}),g.select(this).style("will-change","auto")});const P=a.selectAll(".node").data(l,e=>e.data.id);P.exit().style("will-change","transform, opacity").style("opacity",1).transition().duration(w.collapseDuration).ease(w.collapseEase).style("opacity",0).attrTween("transform",function(e){const o=e.y??e.y0??0,d=e.x??e.x0??0;let E=o,M=d;if(e.parent){const U=k(e.parent,"target");E=U.y,M=U.x}const X=g.interpolateNumber(o,E),G=g.interpolateNumber(d,M),me=g.interpolateNumber(w.nodeScaleTo,.9);return U=>`translate(${X(U)},${G(U)}) scale(${me(U)})`}).on("end",function(){g.select(this).style("will-change","auto"),g.select(this).remove()});const B=P.enter().append("g").attr("class","node").attr("role","treeitem").attr("aria-level",e=>e.depth+1).attr("aria-expanded",e=>{const o=e.children&&e.children.length>0,d=e.data.expanded!==!1;return o?String(d):null}).attr("aria-label",e=>{const d=e.children&&e.children.length>0?e.children.length:0;return`${e.data.topic}, ${d} 个子项`}).attr("tabindex",(e,o)=>o===0?0:-1).attr("transform",e=>{const o=e.y0!==void 0?e.y0:e.parent?e.parent.y:e.y,d=e.x0!==void 0?e.x0:e.parent?e.parent.x:e.x;return`translate(${o},${d}) scale(${w.nodeScaleFrom})`}).style("opacity",0).style("cursor","pointer").style("outline","none").style("will-change","transform, opacity"),u=e=>R(e.data,e.depth);B.append("rect").attr("rx",e=>{const o=A(e.data,e.depth);return parseInt(o.borderRadius||"8")}).attr("ry",e=>{const o=A(e.data,e.depth);return parseInt(o.borderRadius||"8")}).attr("x",-18).attr("y",-27.5).attr("width",e=>{const o=A(e.data,e.depth),d=`${o.fontSize} ${o.fontFamily}`,E=we(e.data.topic,d),M=Math.max(E+36,100);return e.data._nodeWidth=M,M}).attr("height",55).style("fill",e=>u(e)).style("stroke",e=>O(e.data,e.depth)||"none").style("stroke-width",e=>A(e.data,e.depth).borderWidth||"0").style("cursor","pointer"),B.append("text").attr("class","node-name").attr("text-anchor","start").attr("x",0).attr("y",0).style("font-size",e=>A(e.data,e.depth).fontSize).style("font-family",e=>A(e.data,e.depth).fontFamily).style("font-weight",e=>A(e.data,e.depth).fontWeight).style("dominant-baseline","middle").style("fill",e=>ee(e.data,e.depth)).style("pointer-events","none").style("user-select","none").text(e=>e.data.topic),B.each(function(e){if(e.children&&e.children.length>0){const o=g.select(this),E=(e.data._nodeWidth||Math.max(we(e.data.topic,'20px "Google Sans"')+36,100))-18+Le;o.append("circle").attr("class","expand-button").attr("r",12).attr("cx",E).attr("cy",0).attr("fill-opacity",1).style("fill",M=>u(M)).style("cursor","pointer").style("pointer-events","all").on("click",function(M){M.stopPropagation(),M.preventDefault(),rt(e)}),o.append("text").attr("class","expand-symbol").attr("x",E).attr("y",0).attr("text-anchor","middle").style("font-size","20px").style("font-family",'"Google Sans", "PingFang SC", "Microsoft YaHei", sans-serif').style("fill","rgb(0, 0, 0)").style("pointer-events","none").style("dominant-baseline","middle").style("user-select","none").text(M=>M.data.expanded!==!1?"<":">")}}),B.on("click",(e,o)=>{const d=e.target;d.tagName==="circle"||d.classList.contains("expand-symbol")||b("node-click",o.data._original||o.data,e)}),B.on("dblclick",(e,o)=>{b("node-dblclick",o.data._original||o.data,e)}),B.on("contextmenu",(e,o)=>{e.preventDefault(),b("node-contextmenu",o.data._original||o.data,e)}),B.on("mouseenter",(e,o)=>{b("node-mouseenter",o.data._original||o.data,e)}),B.on("mouseleave",(e,o)=>{b("node-mouseleave",o.data._original||o.data,e)}),B.style("opacity",0).style("will-change","transform, opacity"),P.style("will-change","transform, opacity");const z=B.merge(P);z.transition().duration(w.expandDuration).ease(w.expandEase).delay(e=>Fe(e)).style("opacity",function(e){const o=parseFloat(g.select(this).style("opacity")||"1");return o===0?1:o}).attrTween("transform",function(e){const o=e.y0??(e.parent?e.parent.y:e.y),d=e.x0??(e.parent?e.parent.x:e.x),E=e.y,M=e.x;if(Math.abs(o-E)<.1&&Math.abs(d-M)<.1)return()=>`translate(${E},${M}) scale(1)`;const X=e.parent&&(e.y0===void 0||e.x0===void 0||Math.abs(o-e.parent.y)<2&&Math.abs(d-e.parent.x)<2),G=g.interpolateNumber(o,E),me=g.interpolateNumber(d,M),U=g.interpolateNumber(X?w.nodeScaleFrom:w.nodeScaleTo,w.nodeScaleTo);return J=>`translate(${G(J)},${me(J)}) scale(${U(J)})`}).on("end",function(e){var o,d;e.x0=e.x,e.y0=e.y,(o=e.data)!=null&&o.id&&he.set(e.data.id,{x:e.x,y:e.y}),(d=e.data)!=null&&d.id&&ie.delete(e.data.id),g.select(this).style("will-change","auto")}),z.selectAll(".expand-symbol").text(e=>e.data.expanded!==!1?"<":">")},rt=t=>{t.data&&(re||(j&&L&&(L.kill(),L=null,j=!1),fe&&(clearTimeout(fe),fe=null),ie.clear(),fe=setTimeout(()=>{if(re)return;re=!0,ue=!0;const n=t.data.expanded!==!1;t.data.expanded=!n,b(n?"node-collapse":"node-expand",t.data._original||t.data),W.value&&Pe(W.value);let a=0;const l=m=>{m.children&&(a+=m.children.length,m.children.forEach(C=>{l(C)}))},p=(m=>{let C=0,k=m;for(;k.parent;)C++,k=k.parent;return C})(t);if(ge.clear(),he.forEach((m,C)=>ge.set(C,{...m})),n){const m=C=>{C.children&&C.children.forEach(k=>{k.x0=void 0,k.y0=void 0,m(k)})};m(t),l(t)}else{const m=k=>{k.children&&k.children.forEach(V=>{V.x0=void 0,V.y0=void 0,m(V)})};m(t);const C=k=>{k.children&&k.children.forEach(V=>{var F;(F=V.data)!=null&&F.id&&ie.add(V.data.id),C(V)})};C(t),l(t)}j=!0,W.value&&ve(W.value),be(),b("change",Ne()),r.nextTick(()=>{setTimeout(()=>{const m=.7-p*.08,C=Math.min(Math.sqrt(a)*.03,.18),k=.35,V=.8,F=m+C,q=Math.max(Math.min(F,V),k);at(t,q)},50)});const S=Math.max(w.expandDuration,w.collapseDuration);setTimeout(()=>{re=!1,ue=!1},S+100),fe=null},50)))},ot=()=>{!v.value||!N.value||(Y=g.zoom().scaleExtent([.25,5]).on("start",()=>{pe.value=!1,ne=null,le={vx:0,vy:0},Se=""}).on("zoom",t=>{const n=t==null?void 0:t.sourceEvent;Se=(n==null?void 0:n.type)||"";const a=(n==null?void 0:n.timeStamp)??performance.now();if(n&&n.type!=="wheel")if(!ne)ne={x:t.transform.x,y:t.transform.y,t:a};else{const l=Math.max(1,a-ne.t);le={vx:(t.transform.x-ne.x)/l,vy:(t.transform.y-ne.y)/l},ne={x:t.transform.x,y:t.transform.y,t:a}}if(ae){H=t.transform,$.value=t.transform.k,xe(t.transform),b("zoom",t.transform.k),b("pan",{x:t.transform.x,y:t.transform.y,k:t.transform.k});return}Q(t.transform,{duration:w.transformDuration,ease:w.transformEase,syncZoom:!1}),b("zoom",t.transform.k),b("pan",{x:t.transform.x,y:t.transform.y,k:t.transform.k})}).on("end",()=>{if(setTimeout(()=>{pe.value=!0},2e3),ae||Se==="wheel"||Math.hypot(le.vx,le.vy)<.08)return;const n=120;let a=le.vx*n,l=le.vy*n;const y=260,p=Math.hypot(a,l);if(p>y){const m=y/p;a*=m,l*=m}const S=g.zoomIdentity.translate(H.x+a,H.y+l).scale(H.k);Q(S,{duration:w.transformDuration*1.4,ease:w.transformEase,syncZoom:!0})}),g.select(v.value).call(Y))},Ne=()=>{if(!_.value)return null;const t=n=>{const a={id:n.id||Te(),topic:n.topic||"未命名",expanded:n.expanded!==!1};return n.root&&(a.root=!0),n.children&&n.children.length>0&&(a.children=n.children.map(l=>t(l))),a};return{nodeData:t(_.value)}},He=t=>{const n=Ie(t);Ee(n,0,0),_.value=n;const a=Ye(n);ve(a),W.value=a,be()},ye=()=>{if(!v.value||!D.value)return;const t=D.value.clientWidth||800,n=D.value.clientHeight||600;g.select(v.value).attr("width",t).attr("height",n)},at=(t,n)=>{if(!t||!W.value||!v.value||!N.value||!D.value){Z();return}ye();const a=D.value.clientWidth||800,l=D.value.clientHeight||600,y=[],p=d=>{y.push(d),d.children&&d.data.expanded!==!1&&d.children.forEach(E=>p(E))};if(p(t),y.length===0){Z();return}let S=1/0,m=-1/0,C=1/0,k=-1/0;y.forEach(d=>{const E=d.x||0,M=d.y||0,X=Ce(d),G=55;S=Math.min(S,E-G/2),m=Math.max(m,E+G/2),C=Math.min(C,M-X/2),k=Math.max(k,M+X/2)});const V=100,F=k-C+V*2,q=m-S+V*2,P=a/F,se=l/q,B=Math.min(P,se,1.2),u=t.x||0,z=t.y||0,e=a/2-z*B,o=l/2-u*B;if(Y&&N.value){const d=g.zoomIdentity.translate(e,o).scale(B),E=n!==void 0?n:w.centerDuration;L&&(L.kill(),L=null),L=Q(d,{duration:E,ease:w.centerEase,syncZoom:!0,onComplete:()=>{j=!1,L=null}})}},Z=()=>{if(!W.value||!v.value||!N.value||!D.value)return;ye();const t=D.value.clientWidth||800,n=D.value.clientHeight||600,a=[],l=(e,o=!0)=>{o&&(e.parent&&e.parent.data&&e.parent.data.expanded===!1||(a.push(e),e.children&&e.data.expanded!==!1&&e.children.forEach(d=>l(d,!0))))};if(l(W.value,!0),a.length===0)return;let y=1/0,p=-1/0,S=1/0,m=-1/0;a.forEach(e=>{const o=e.x||0,d=e.y||0;y=Math.min(y,o),p=Math.max(p,o),S=Math.min(S,d),m=Math.max(m,d)});const C=80,k=m-S+C*2,V=p-y+C*2,F=t/k,q=n/V,P=Math.min(F,q,1.2),se=(y+p)/2,B=(S+m)/2,u=t/2-B*P,z=n/2-se*P;if(Y&&N.value){const e=g.zoomIdentity.translate(u,z).scale(P);L&&(L.kill(),L=null),L=Q(e,{duration:w.centerDuration,ease:w.centerEase,syncZoom:!0,onComplete:()=>{j=!1,L=null}})}},De=()=>{if(!W.value||!v.value||!N.value||!D.value)return;const t=W.value,n=t.x||0,a=t.y||0,l=D.value.clientWidth||800,y=D.value.clientHeight||600,p=l/2-a*$.value,S=y/2-n*$.value;if(Y&&v.value){const m=g.zoomIdentity.translate(p,S).scale($.value);Q(m,{duration:w.centerDuration,ease:w.centerEase,syncZoom:!0})}},ke=t=>{if(!_.value||!W.value||re)return;if(re=!0,ue=!0,ie.clear(),Pe(W.value),ge.clear(),he.forEach((l,y)=>ge.set(y,{...l})),t){const l=y=>{y.children&&y.children.forEach(p=>{var S;p.x0=void 0,p.y0=void 0,(S=p.data)!=null&&S.id&&ie.add(p.data.id),l(p)})};l(W.value)}else{const l=y=>{y.children&&y.children.forEach(p=>{p.x0=p.x,p.y0=p.y,l(p)})};l(W.value)}const n=l=>{l.expanded=t,l.children&&l.children.length>0&&l.children.forEach(y=>n(y))};n(_.value),j=!0,ve(W.value),be(),b("change",Ne()),r.nextTick(()=>{setTimeout(()=>{Z();const l=w.centerDuration*1e3;setTimeout(()=>{j=!1,L=null},l+80)},50)});const a=Math.max(w.expandDuration,w.collapseDuration)+120;setTimeout(()=>{re=!1,ue=!1},a)},ze=(t,n)=>{if(!D.value)return g.zoomIdentity.scale(t);const a=D.value.clientWidth||800,l=D.value.clientHeight||600,y=a/2,p=l/2,S=(y-H.x)/H.k,m=(p-H.y)/H.k,C=y-S*t,k=p-m*t;return g.zoomIdentity.translate(C,k).scale(t)},We=()=>{if(!v.value||!Y)return;const t=Math.min($.value*(1+Xe),5);if(Math.abs(t-$.value)<.001)return;const n=ze(t);Q(n,{duration:w.transformDuration,ease:w.transformEase,syncZoom:!0})},Be=()=>{if(!v.value||!Y)return;const t=Math.max($.value*(1-Xe),.25);if(Math.abs(t-$.value)<.001)return;const n=ze(t);Q(n,{duration:w.transformDuration,ease:w.transformEase,syncZoom:!0})},lt=t=>{if(!v.value||!Y)return;const n=Math.max(.25,Math.min(5,t));if(Math.abs(n-$.value)<.001)return;const a=ze(n);Q(a,{duration:w.transformDuration,ease:w.transformEase,syncZoom:!0})},it=()=>$.value,st=()=>({treeData:W.value,nodeData:_.value}),ct=()=>{ke(!Me.value)},ut=()=>{b("download")},dt=async(t="png",n)=>{if(!v.value)throw new Error("SVG element not found");return t==="svg"?je(v.value,n==null?void 0:n.backgroundColor):Qe(v.value,{scale:(n==null?void 0:n.scale)||2,backgroundColor:(n==null?void 0:n.backgroundColor)||"#ffffff",quality:(n==null?void 0:n.quality)||1})};return r.watch(()=>s.data,(t,n)=>{ue||t&&(He(t),pe.value&&r.nextTick(()=>{Z()}))},{deep:!0}),r.watch(()=>s.theme,(t,n)=>{t!==n&&r.nextTick(()=>{if(!N.value)return;const a=g.select(N.value);a.selectAll(".node").each(function(l){const y=g.select(this);y.select("rect").style("fill",R(l.data,l.depth)).style("stroke",O(l.data,l.depth)||"none"),y.select(".node-name").style("fill",ee(l.data,l.depth)),y.select(".expand-button").style("fill",R(l.data,l.depth))}),a.selectAll(".link").each(function(l){const y=l.target.depth||0;g.select(this).style("stroke",ce(l,y))})})},{deep:!0}),r.onMounted(()=>{r.nextTick(()=>{nt(),D.value&>.useResizeObserver(D,()=>{var t;K.value=((t=D.value)==null?void 0:t.clientWidth)||800,pe.value?(ye(),r.nextTick(()=>{Z()})):ye()})})}),r.onBeforeUnmount(()=>{Y&&v.value&&g.select(v.value).on(".zoom",null),Y=null}),h({getData:Ne,setData:He,toCenter:De,expandAll:ke,zoomIn:We,zoomOut:Be,setZoom:lt,getZoom:it,getInstance:st,fit:()=>{Z()},fitToWindow:Z}),(t,n)=>(r.openBlock(),r.createElementBlock("div",{ref_key:"wrapperRef",ref:D,class:"d3-mindmap-wrapper",style:r.normalizeStyle(r.unref(te)())},[(r.openBlock(),r.createElementBlock("svg",{ref_key:"svgRef",ref:v,class:"d3-mindmap-svg",style:r.normalizeStyle(et.value),role:"tree"},[r.createElementVNode("g",{ref_key:"svgGroupRef",ref:N,class:"mindmap-group"},[...n[0]||(n[0]=[r.createElementVNode("g",{class:"links"},null,-1),r.createElementVNode("g",{class:"nodes"},null,-1)])],512)],4)),i.showToolbar?(r.openBlock(),r.createElementBlock("div",{key:0,class:r.normalizeClass(["d3-mindmap-toolbar",Je.value])},[t.$slots.toolbar?r.renderSlot(t.$slots,"toolbar",{key:0,zoomIn:We,zoomOut:Be,fit:Z,toCenter:De,expandAll:()=>ke(!0),collapseAll:()=>ke(!1),exportImage:dt,scale:$.value,visibleNodeCount:$e.value},void 0,!0):(r.openBlock(),r.createElementBlock(r.Fragment,{key:1},[r.createElementVNode("button",{class:"toolbar-btn",onClick:Be,title:"缩小"},[...n[1]||(n[1]=[r.createElementVNode("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r.createElementVNode("circle",{cx:"11",cy:"11",r:"8"}),r.createElementVNode("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),r.createElementVNode("line",{x1:"8",y1:"11",x2:"14",y2:"11"})],-1)])]),i.showScale?(r.openBlock(),r.createElementBlock("div",Tt,r.toDisplayString(Ke.value)+"%",1)):r.createCommentVNode("",!0),r.createElementVNode("button",{class:"toolbar-btn",onClick:We,title:"放大"},[...n[2]||(n[2]=[r.createStaticVNode('<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" data-v-64e7aa82><circle cx="11" cy="11" r="8" data-v-64e7aa82></circle><line x1="21" y1="21" x2="16.65" y2="16.65" data-v-64e7aa82></line><line x1="11" y1="8" x2="11" y2="14" data-v-64e7aa82></line><line x1="8" y1="11" x2="14" y2="11" data-v-64e7aa82></line></svg>',1)])]),n[8]||(n[8]=r.createElementVNode("div",{class:"toolbar-divider"},null,-1)),r.createElementVNode("button",{class:"toolbar-btn",onClick:De,title:"适应画布"},[...n[3]||(n[3]=[r.createElementVNode("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r.createElementVNode("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})],-1)])]),n[9]||(n[9]=r.createElementVNode("div",{class:"toolbar-divider"},null,-1)),r.createElementVNode("button",{class:"toolbar-btn",onClick:ct,title:Me.value?"全部收起":"全部展开"},[Me.value?(r.openBlock(),r.createElementBlock("svg",Nt,[...n[5]||(n[5]=[r.createElementVNode("polyline",{points:"4 14 10 14 10 20"},null,-1),r.createElementVNode("polyline",{points:"20 10 14 10 14 4"},null,-1),r.createElementVNode("line",{x1:"14",y1:"10",x2:"21",y2:"3"},null,-1),r.createElementVNode("line",{x1:"3",y1:"21",x2:"10",y2:"14"},null,-1)])])):(r.openBlock(),r.createElementBlock("svg",Ct,[...n[4]||(n[4]=[r.createElementVNode("polyline",{points:"15 3 21 3 21 9"},null,-1),r.createElementVNode("polyline",{points:"9 21 3 21 3 15"},null,-1),r.createElementVNode("line",{x1:"21",y1:"3",x2:"14",y2:"10"},null,-1),r.createElementVNode("line",{x1:"3",y1:"21",x2:"10",y2:"14"},null,-1)])]))],8,Et),i.showDownload||i.showCounts?(r.openBlock(),r.createElementBlock("div",Dt)):r.createCommentVNode("",!0),i.showDownload?(r.openBlock(),r.createElementBlock("button",{key:2,class:"toolbar-btn",onClick:ut,title:"导出图片"},[...n[6]||(n[6]=[r.createElementVNode("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r.createElementVNode("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),r.createElementVNode("polyline",{points:"7 10 12 15 17 10"}),r.createElementVNode("line",{x1:"12",y1:"15",x2:"12",y2:"3"})],-1)])])):r.createCommentVNode("",!0),i.showCounts?(r.openBlock(),r.createElementBlock("div",zt,[n[7]||(n[7]=r.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r.createElementVNode("circle",{cx:"12",cy:"12",r:"3"}),r.createElementVNode("path",{d:"M12 1v6m0 6v6M5.64 5.64l4.24 4.24m4.24 4.24l4.24 4.24M1 12h6m6 0h6M5.64 18.36l4.24-4.24m4.24-4.24l4.24-4.24"})],-1)),r.createElementVNode("span",Wt,r.toDisplayString($e.value),1)])):r.createCommentVNode("",!0)],64))],2)):r.createCommentVNode("",!0)],4))}}),Vt=(i,h)=>{const c=i.__vccOpts||i;for(const[s,b]of h)c[s]=b;return c},Pt=Vt(Bt,[["__scopeId","data-v-64e7aa82"]]);exports.D3MindMap=Pt;exports.colorfulTheme=Re;exports.darkTheme=Ae;exports.debounce=bt;exports.deepClone=Ve;exports.defaultTheme=oe;exports.downloadBlob=wt;exports.generateId=vt;exports.getTextWidth=we;exports.getTheme=xt;exports.isGradient=St;exports.mergeTheme=_e;exports.minimalTheme=Oe;exports.parseGradientColor=Mt;exports.professionalTheme=Ge;exports.svgToBlob=je;exports.svgToPng=Qe;exports.themes=Ue;exports.throttle=kt;exports.useMindMapLayout=qe;exports.useMindMapTheme=Ze;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|