码桶
发现社区成员的开源项目
Heatmap-B9MhSEGm.js5.9 KB
import{u as _,a as F,c as G,r as l,q as z,b as A,j as t,B as V,T as O,C as q,f as b}from"./index-GWuvg2UH.js";import{B as U}from"./index-DihvOmSo.js";import{E as N}from"./index-VbOLTMR0.js";import{R as K,a as B}from"./index-DIHsQVbu.js";import{S as H}from"./index-BZDftoba.js";import{T as J}from"./index-mZVFvfKe.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./slice-B6jKCnyX.js";import"./object-DkPZvw8u.js";import"./index-BMbdBPA2.js";const Q=[1,7,30],X=[{key:"",labelKey:"heatAllDevices"},{key:"desktop",labelKey:"heatDesktop"},{key:"mobile",labelKey:"heatMobile"},{key:"tablet",labelKey:"heatTablet"}],Y={"":1280,desktop:1280,mobile:390,tablet:820},Z=2e3;function ee(){const a=[[26,168,118],[245,158,11],[239,68,68]],f=new Array(256);for(let o=0;o<256;o++){const h=o/255*(a.length-1),p=Math.min(a.length-2,Math.floor(h)),r=h-p,u=a[p],m=a[p+1];f[o]=[Math.round(u[0]+(m[0]-u[0])*r),Math.round(u[1]+(m[1]-u[1])*r),Math.round(u[2]+(m[2]-u[2])*r)]}return f}const te=ee();function ae(a,f,o){const h=a.getContext("2d"),p=a.width,r=a.height;if(h.clearRect(0,0,p,r),!f.length||o<=0)return;const u=Math.max(20,p*.05),m=p/100,w=r/100,d=document.createElement("canvas");d.width=p,d.height=r;const n=d.getContext("2d"),s=n.createRadialGradient(0,0,0,0,0,u);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),n.fillStyle=s;for(const c of f)n.save(),n.globalAlpha=Math.max(.12,Math.min(1,c.c/o)),n.translate((c.x+.5)*m,(c.y+.5)*w),n.beginPath(),n.arc(0,0,u,0,Math.PI*2),n.fill(),n.restore();const v=n.getImageData(0,0,p,r),g=v.data;for(let c=0;c<g.length;c+=4){const x=g[c+3];if(x===0)continue;const y=te[x];g[c]=y[0],g[c+1]=y[1],g[c+2]=y[2],g[c+3]=Math.min(210,x*.95)}h.putImageData(v,0,0)}function me(){const{t:a}=_(),f=F(),{site:o}=G(),[h,p]=l.useState(7),[r,u]=l.useState(""),[m,w]=l.useState(null),[d,n]=l.useState(""),[s,v]=l.useState(null),[g,c]=l.useState(!1),[x,y]=l.useState(""),S=l.useRef(null),T=l.useRef(null),[k,I]=l.useState(0),W=l.useCallback(async()=>{if(o){c(!0);try{const{start:e,end:i}=z(h),j=await A.heatPages(o.id,e,i);w(j.pages||[]),n(M=>{var D,$;return M||((($=(D=j.pages)==null?void 0:D[0])==null?void 0:$.path)??"")}),y("")}catch(e){y(e.message)}finally{c(!1)}}},[o,h]);if(l.useEffect(()=>{let e=!1;return(async()=>{if(!o||!d){v(null);return}try{const{start:i,end:j}=z(h),M=await A.heatPoints(o.id,i,j,d,r);e||v(M)}catch(i){e||y(i.message)}})(),()=>{e=!0}},[o,d,h,r]),l.useEffect(()=>{W()},[W]),l.useEffect(()=>{const e=S.current;if(!e)return;const i=new ResizeObserver(()=>I(e.clientWidth));return i.observe(e),I(e.clientWidth),()=>i.disconnect()},[m]),l.useEffect(()=>{const e=T.current;!e||!k||ae(e,(s==null?void 0:s.cells)||[],(s==null?void 0:s.max_cell)||0)},[s,k,r]),!o)return t.jsx("div",{className:"page",children:t.jsx(N,{style:{marginTop:60},title:a("noSiteHint"),children:t.jsx(V,{theme:"solid",onClick:()=>f("/sites"),children:a("goSites")})})});const C=Y[r]||1280,E=k>0?Math.min(3,k/C):1,P=(s==null?void 0:s.avg_dh)||Z,R=Math.round(P*E),L=d?`${window.location.protocol}//${String(o.domain||"").replace(/^https?:\/\//,"")}${d}`:"";return t.jsxs("div",{className:"page",children:[t.jsxs("div",{className:"toolbar",children:[t.jsx(O.Title,{heading:5,style:{margin:0},children:a("heat")}),t.jsx(K,{type:"button",buttonSize:"small",value:h,onChange:e=>p(Number(e.target.value)),children:Q.map(e=>t.jsxs(B,{value:e,children:[e,"D"]},e))})]}),x&&t.jsx(U,{type:"danger",description:x,style:{marginBottom:12},closeIcon:null}),t.jsxs("div",{className:"card",style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap"},children:[t.jsx(q,{style:{minWidth:320},placeholder:a("heatPickPage"),value:d||void 0,onChange:e=>n(e),optionList:(m||[]).map(e=>({value:e.path,label:`${e.path}(${b(e.clicks)} ${a("heatColClicks")})`})),showClear:!1}),t.jsx(K,{type:"button",buttonSize:"small",value:r,onChange:e=>u(e.target.value),children:X.map(e=>t.jsx(B,{value:e.key,children:a(e.labelKey)},e.key))}),s&&t.jsxs("span",{style:{color:"#86909c",fontSize:13},children:[b(s.clicks)," ",a("heatColClicks")," · doc≈",P,"px"]})]}),t.jsxs("div",{className:"card",style:{marginTop:14},children:[t.jsxs("div",{className:"card-title",children:[a("heatPreview")," — ",d||"-",s&&` · ${b(s.clicks)} ${a("heatColClicks")}`]}),s&&s.clicks===0&&t.jsx(N,{description:a("heatNoPages"),style:{padding:"32px 0"}}),!s&&g&&t.jsx(H,{active:!0,placeholder:t.jsx(H.Image,{style:{height:320}}),loading:!0}),S&&t.jsx("div",{ref:S,style:{position:"relative",overflow:"hidden",borderRadius:6,background:"#fff",border:"1px solid var(--semi-color-border)"},children:t.jsxs("div",{style:{position:"relative",height:R,pointerEvents:"none"},children:[t.jsx("iframe",{title:"preview",src:L,sandbox:"",style:{width:C,height:P,border:"none",transform:`scale(${E})`,transformOrigin:"top left",pointerEvents:"none",background:"#fff"}}),t.jsx("canvas",{ref:T,width:Math.round(C*E),height:R,style:{position:"absolute",left:0,top:0,width:"100%",height:R}})]})}),t.jsx("div",{style:{color:"#86909c",fontSize:12,marginTop:8},children:a("heatPreviewFail")})]}),t.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden",marginTop:14},children:[t.jsx("div",{className:"card-title",style:{padding:"14px 16px 0"},children:a("heatPages")}),t.jsx(J,{style:{marginTop:8},columns:[{title:a("jPath"),dataIndex:"path",render:e=>t.jsx("a",{style:{fontFamily:"monospace",fontSize:12},onClick:()=>n(e),children:e})},{title:a("heatColClicks"),dataIndex:"clicks",width:120,sorter:(e,i)=>e.clicks-i.clicks,render:e=>b(e)},{title:a("heatColVisits"),dataIndex:"visits",width:120,sorter:(e,i)=>e.visits-i.visits,render:e=>b(e)},{title:a("heatColClicks")+"/SV",width:100,render:(e,i)=>i.visits>0?(i.clicks/i.visits).toFixed(1):"-"}],dataSource:m||[],rowKey:"path",pagination:!1,size:"small",loading:g&&!m,empty:t.jsx(N,{description:a("heatNoPages")}),onRow:e=>({style:e.path===d?{background:"var(--semi-color-primary-light-default)",cursor:"pointer"}:{cursor:"pointer"},onClick:()=>n(e.path)})})]})]})}export{me as default};