UNPKG

git-contri-merged

Version:

A React component to display merged GitHub contribution graphs from multiple contributors

35 lines (34 loc) 25 kB
(function(S,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(S=typeof globalThis<"u"?globalThis:S||self,c(S.MergedGitHubCalendar={},S.jsxRuntime,S.React))})(this,function(S,c,E){"use strict";function mt(t,e){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const r=document.implementation.createHTMLDocument(),n=r.createElement("base"),s=r.createElement("a");return r.head.appendChild(n),r.body.appendChild(s),e&&(n.href=e),s.href=t,s.href}const pt=(()=>{let t=0;const e=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(t+=1,`u${e()}${t}`)})();function $(t){const e=[];for(let r=0,n=t.length;r<n;r++)e.push(t[r]);return e}let k=null;function q(t={}){return k||(t.includeStyleProperties?(k=t.includeStyleProperties,k):(k=$(window.getComputedStyle(document.documentElement)),k))}function M(t,e){const n=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(e);return n?parseFloat(n.replace("px","")):0}function yt(t){const e=M(t,"border-left-width"),r=M(t,"border-right-width");return t.clientWidth+e+r}function wt(t){const e=M(t,"border-top-width"),r=M(t,"border-bottom-width");return t.clientHeight+e+r}function Y(t,e={}){const r=e.width||yt(t),n=e.height||wt(t);return{width:r,height:n}}function bt(){let t,e;try{e=process}catch{}const r=e&&e.env?e.env.devicePixelRatio:null;return r&&(t=parseInt(r,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}const b=16384;function xt(t){(t.width>b||t.height>b)&&(t.width>b&&t.height>b?t.width>t.height?(t.height*=b/t.width,t.width=b):(t.width*=b/t.height,t.height=b):t.width>b?(t.height*=b/t.width,t.width=b):(t.width*=b/t.height,t.height=b))}function A(t){return new Promise((e,r)=>{const n=new Image;n.onload=()=>{n.decode().then(()=>{requestAnimationFrame(()=>e(n))})},n.onerror=r,n.crossOrigin="anonymous",n.decoding="async",n.src=t})}async function Ct(t){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(t)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)}async function St(t,e,r){const n="http://www.w3.org/2000/svg",s=document.createElementNS(n,"svg"),o=document.createElementNS(n,"foreignObject");return s.setAttribute("width",`${e}`),s.setAttribute("height",`${r}`),s.setAttribute("viewBox",`0 0 ${e} ${r}`),o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("x","0"),o.setAttribute("y","0"),o.setAttribute("externalResourcesRequired","true"),s.appendChild(o),o.appendChild(t),Ct(s)}const w=(t,e)=>{if(t instanceof e)return!0;const r=Object.getPrototypeOf(t);return r===null?!1:r.constructor.name===e.name||w(r,e)};function vt(t){const e=t.getPropertyValue("content");return`${t.cssText} content: '${e.replace(/'|"/g,"")}';`}function Et(t,e){return q(e).map(r=>{const n=t.getPropertyValue(r),s=t.getPropertyPriority(r);return`${r}: ${n}${s?" !important":""};`}).join(" ")}function $t(t,e,r,n){const s=`.${t}:${e}`,o=r.cssText?vt(r):Et(r,n);return document.createTextNode(`${s}{${o}}`)}function z(t,e,r,n){const s=window.getComputedStyle(t,r),o=s.getPropertyValue("content");if(o===""||o==="none")return;const i=pt();try{e.className=`${e.className} ${i}`}catch{return}const a=document.createElement("style");a.appendChild($t(i,r,s,n)),e.appendChild(a)}function Tt(t,e,r){z(t,e,":before",r),z(t,e,":after",r)}const J="application/font-woff",X="image/jpeg",Dt={woff:J,woff2:J,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:X,jpeg:X,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function kt(t){const e=/\.([^./]*?)$/g.exec(t);return e?e[1]:""}function W(t){const e=kt(t).toLowerCase();return Dt[e]||""}function Ft(t){return t.split(/,/)[1]}function j(t){return t.search(/^(data:)/)!==-1}function Lt(t,e){return`data:${e};base64,${t}`}async function K(t,e,r){const n=await fetch(t,e);if(n.status===404)throw new Error(`Resource "${n.url}" not found`);const s=await n.blob();return new Promise((o,i)=>{const a=new FileReader;a.onerror=i,a.onloadend=()=>{try{o(r({res:n,result:a.result}))}catch(l){i(l)}},a.readAsDataURL(s)})}const B={};function Pt(t,e,r){let n=t.replace(/\?.*/,"");return r&&(n=t),/ttf|otf|eot|woff2?/i.test(n)&&(n=n.replace(/.*\//,"")),e?`[${e}]${n}`:n}async function V(t,e,r){const n=Pt(t,e,r.includeQueryParams);if(B[n]!=null)return B[n];r.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+new Date().getTime());let s;try{const o=await K(t,r.fetchRequestInit,({res:i,result:a})=>(e||(e=i.headers.get("Content-Type")||""),Ft(a)));s=Lt(o,e)}catch(o){s=r.imagePlaceholder||"";let i=`Failed to fetch resource: ${t}`;o&&(i=typeof o=="string"?o:o.message),i&&console.warn(i)}return B[n]=s,s}async function It(t){const e=t.toDataURL();return e==="data:,"?t.cloneNode(!1):A(e)}async function Mt(t,e){if(t.currentSrc){const o=document.createElement("canvas"),i=o.getContext("2d");o.width=t.clientWidth,o.height=t.clientHeight,i==null||i.drawImage(t,0,0,o.width,o.height);const a=o.toDataURL();return A(a)}const r=t.poster,n=W(r),s=await V(r,n,e);return A(s)}async function At(t,e){var r;try{if(!((r=t==null?void 0:t.contentDocument)===null||r===void 0)&&r.body)return await R(t.contentDocument.body,e,!0)}catch{}return t.cloneNode(!1)}async function Rt(t,e){return w(t,HTMLCanvasElement)?It(t):w(t,HTMLVideoElement)?Mt(t,e):w(t,HTMLIFrameElement)?At(t,e):t.cloneNode(Q(t))}const Ut=t=>t.tagName!=null&&t.tagName.toUpperCase()==="SLOT",Q=t=>t.tagName!=null&&t.tagName.toUpperCase()==="SVG";async function Ot(t,e,r){var n,s;if(Q(e))return e;let o=[];return Ut(t)&&t.assignedNodes?o=$(t.assignedNodes()):w(t,HTMLIFrameElement)&&(!((n=t.contentDocument)===null||n===void 0)&&n.body)?o=$(t.contentDocument.body.childNodes):o=$(((s=t.shadowRoot)!==null&&s!==void 0?s:t).childNodes),o.length===0||w(t,HTMLVideoElement)||await o.reduce((i,a)=>i.then(()=>R(a,r)).then(l=>{l&&e.appendChild(l)}),Promise.resolve()),e}function Ht(t,e,r){const n=e.style;if(!n)return;const s=window.getComputedStyle(t);s.cssText?(n.cssText=s.cssText,n.transformOrigin=s.transformOrigin):q(r).forEach(o=>{let i=s.getPropertyValue(o);o==="font-size"&&i.endsWith("px")&&(i=`${Math.floor(parseFloat(i.substring(0,i.length-2)))-.1}px`),w(t,HTMLIFrameElement)&&o==="display"&&i==="inline"&&(i="block"),o==="d"&&e.getAttribute("d")&&(i=`path(${e.getAttribute("d")})`),n.setProperty(o,i,s.getPropertyPriority(o))})}function Wt(t,e){w(t,HTMLTextAreaElement)&&(e.innerHTML=t.value),w(t,HTMLInputElement)&&e.setAttribute("value",t.value)}function jt(t,e){if(w(t,HTMLSelectElement)){const r=e,n=Array.from(r.children).find(s=>t.value===s.getAttribute("value"));n&&n.setAttribute("selected","")}}function Bt(t,e,r){return w(e,Element)&&(Ht(t,e,r),Tt(t,e,r),Wt(t,e),jt(t,e)),e}async function Vt(t,e){const r=t.querySelectorAll?t.querySelectorAll("use"):[];if(r.length===0)return t;const n={};for(let o=0;o<r.length;o++){const a=r[o].getAttribute("xlink:href");if(a){const l=t.querySelector(a),d=document.querySelector(a);!l&&d&&!n[a]&&(n[a]=await R(d,e,!0))}}const s=Object.values(n);if(s.length){const o="http://www.w3.org/1999/xhtml",i=document.createElementNS(o,"svg");i.setAttribute("xmlns",o),i.style.position="absolute",i.style.width="0",i.style.height="0",i.style.overflow="hidden",i.style.display="none";const a=document.createElementNS(o,"defs");i.appendChild(a);for(let l=0;l<s.length;l++)a.appendChild(s[l]);t.appendChild(i)}return t}async function R(t,e,r){return!r&&e.filter&&!e.filter(t)?null:Promise.resolve(t).then(n=>Rt(n,e)).then(n=>Ot(t,n,e)).then(n=>Bt(t,n,e)).then(n=>Vt(n,e))}const Z=/url\((['"]?)([^'"]+?)\1\)/g,_t=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Gt=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function qt(t){const e=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${e})(['"]?\\))`,"g")}function Yt(t){const e=[];return t.replace(Z,(r,n,s)=>(e.push(s),r)),e.filter(r=>!j(r))}async function zt(t,e,r,n,s){try{const o=r?mt(e,r):e,i=W(e);let a;return s||(a=await V(o,i,n)),t.replace(qt(e),`$1${a}$3`)}catch{}return t}function Jt(t,{preferredFontFormat:e}){return e?t.replace(Gt,r=>{for(;;){const[n,,s]=_t.exec(r)||[];if(!s)return"";if(s===e)return`src: ${n};`}}):t}function N(t){return t.search(Z)!==-1}async function tt(t,e,r){if(!N(t))return t;const n=Jt(t,r);return Yt(n).reduce((o,i)=>o.then(a=>zt(a,i,e,r)),Promise.resolve(n))}async function F(t,e,r){var n;const s=(n=e.style)===null||n===void 0?void 0:n.getPropertyValue(t);if(s){const o=await tt(s,null,r);return e.style.setProperty(t,o,e.style.getPropertyPriority(t)),!0}return!1}async function Xt(t,e){await F("background",t,e)||await F("background-image",t,e),await F("mask",t,e)||await F("-webkit-mask",t,e)||await F("mask-image",t,e)||await F("-webkit-mask-image",t,e)}async function Kt(t,e){const r=w(t,HTMLImageElement);if(!(r&&!j(t.src))&&!(w(t,SVGImageElement)&&!j(t.href.baseVal)))return;const n=r?t.src:t.href.baseVal,s=await V(n,W(n),e);await new Promise((o,i)=>{t.onload=o,t.onerror=e.onImageErrorHandler?(...l)=>{try{o(e.onImageErrorHandler(...l))}catch(d){i(d)}}:i;const a=t;a.decode&&(a.decode=o),a.loading==="lazy"&&(a.loading="eager"),r?(t.srcset="",t.src=s):t.href.baseVal=s})}async function Qt(t,e){const n=$(t.childNodes).map(s=>et(s,e));await Promise.all(n).then(()=>t)}async function et(t,e){w(t,Element)&&(await Xt(t,e),await Kt(t,e),await Qt(t,e))}function Zt(t,e){const{style:r}=t;e.backgroundColor&&(r.backgroundColor=e.backgroundColor),e.width&&(r.width=`${e.width}px`),e.height&&(r.height=`${e.height}px`);const n=e.style;return n!=null&&Object.keys(n).forEach(s=>{r[s]=n[s]}),t}const rt={};async function nt(t){let e=rt[t];if(e!=null)return e;const n=await(await fetch(t)).text();return e={url:t,cssText:n},rt[t]=e,e}async function ot(t,e){let r=t.cssText;const n=/url\(["']?([^"')]+)["']?\)/g,o=(r.match(/url\([^)]+\)/g)||[]).map(async i=>{let a=i.replace(n,"$1");return a.startsWith("https://")||(a=new URL(a,t.url).href),K(a,e.fetchRequestInit,({result:l})=>(r=r.replace(i,`url(${l})`),[i,l]))});return Promise.all(o).then(()=>r)}function st(t){if(t==null)return[];const e=[],r=/(\/\*[\s\S]*?\*\/)/gi;let n=t.replace(r,"");const s=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const l=s.exec(n);if(l===null)break;e.push(l[0])}n=n.replace(s,"");const o=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,i="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",a=new RegExp(i,"gi");for(;;){let l=o.exec(n);if(l===null){if(l=a.exec(n),l===null)break;o.lastIndex=a.lastIndex}else a.lastIndex=o.lastIndex;e.push(l[0])}return e}async function Nt(t,e){const r=[],n=[];return t.forEach(s=>{if("cssRules"in s)try{$(s.cssRules||[]).forEach((o,i)=>{if(o.type===CSSRule.IMPORT_RULE){let a=i+1;const l=o.href,d=nt(l).then(h=>ot(h,e)).then(h=>st(h).forEach(u=>{try{s.insertRule(u,u.startsWith("@import")?a+=1:s.cssRules.length)}catch(g){console.error("Error inserting rule from remote css",{rule:u,error:g})}})).catch(h=>{console.error("Error loading remote css",h.toString())});n.push(d)}})}catch(o){const i=t.find(a=>a.href==null)||document.styleSheets[0];s.href!=null&&n.push(nt(s.href).then(a=>ot(a,e)).then(a=>st(a).forEach(l=>{i.insertRule(l,i.cssRules.length)})).catch(a=>{console.error("Error loading remote stylesheet",a)})),console.error("Error inlining remote css file",o)}}),Promise.all(n).then(()=>(t.forEach(s=>{if("cssRules"in s)try{$(s.cssRules||[]).forEach(o=>{r.push(o)})}catch(o){console.error(`Error while reading CSS rules from ${s.href}`,o)}}),r))}function te(t){return t.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>N(e.style.getPropertyValue("src")))}async function ee(t,e){if(t.ownerDocument==null)throw new Error("Provided element is not within a Document");const r=$(t.ownerDocument.styleSheets),n=await Nt(r,e);return te(n)}function it(t){return t.trim().replace(/["']/g,"")}function re(t){const e=new Set;function r(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach(o=>{e.add(it(o))}),Array.from(n.children).forEach(o=>{o instanceof HTMLElement&&r(o)})}return r(t),e}async function ne(t,e){const r=await ee(t,e),n=re(t);return(await Promise.all(r.filter(o=>n.has(it(o.style.fontFamily))).map(o=>{const i=o.parentStyleSheet?o.parentStyleSheet.href:null;return tt(o.cssText,i,e)}))).join(` `)}async function oe(t,e){const r=e.fontEmbedCSS!=null?e.fontEmbedCSS:e.skipFonts?null:await ne(t,e);if(r){const n=document.createElement("style"),s=document.createTextNode(r);n.appendChild(s),t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n)}}async function se(t,e={}){const{width:r,height:n}=Y(t,e),s=await R(t,e,!0);return await oe(s,e),await et(s,e),Zt(s,e),await St(s,r,n)}async function ie(t,e={}){const{width:r,height:n}=Y(t,e),s=await se(t,e),o=await A(s),i=document.createElement("canvas"),a=i.getContext("2d"),l=e.pixelRatio||bt(),d=e.canvasWidth||r,h=e.canvasHeight||n;return i.width=d*l,i.height=h*l,e.skipAutoScale||xt(i),i.style.width=`${d}`,i.style.height=`${h}`,e.backgroundColor&&(a.fillStyle=e.backgroundColor,a.fillRect(0,0,i.width,i.height)),a.drawImage(o,0,0,i.width,i.height),i}async function ae(t,e={}){return(await ie(t,e)).toDataURL()}async function ce(t,e,r){var l,d,h;const n=new Date().getFullYear(),s=e||n,o=`${s}-01-01T00:00:00Z`,i=`${s}-12-31T23:59:59Z`,a=` query($username: String!, $from: DateTime!, $to: DateTime!) { user(login: $username) { contributionsCollection(from: $from, to: $to) { contributionCalendar { totalContributions weeks { contributionDays { date contributionCount color } } } } } viewer { login contributionsCollection(from: $from, to: $to) { contributionCalendar { totalContributions weeks { contributionDays { date contributionCount color } } } } } } `;try{const u={"Content-Type":"application/json"};r&&(u.Authorization=`Bearer ${r}`);const g=await fetch("https://api.github.com/graphql",{method:"POST",headers:u,body:JSON.stringify({query:a,variables:{username:t,from:o,to:i}})});if(!g.ok)throw new Error(`GitHub API error: ${g.statusText}`);const f=await g.json();if(f.errors&&(!f.errors.find(v=>v.message.includes("Could not resolve to a User"))||!((l=f.data)!=null&&l.viewer)))throw new Error(`GraphQL errors: ${JSON.stringify(f.errors)}`);let m;if((d=f.data)!=null&&d.viewer&&f.data.viewer.login.toLowerCase()===t.toLowerCase())m=f.data.viewer.contributionsCollection.contributionCalendar;else if((h=f.data)!=null&&h.user)m=f.data.user.contributionsCollection.contributionCalendar;else throw new Error(`User ${t} not found`);const x=[],D=m.weeks;for(const L of D)for(const v of L.contributionDays)x.push({date:v.date,count:v.contributionCount,level:fe(v.contributionCount)});return x}catch(u){throw console.error(`Error fetching contributions for ${t}:`,u),u}}async function le(t,e,r){const n=new Map,s=new Date().getFullYear(),o=e||[s];for(const i of t)try{const a=[];for(const l of o){const d=await ce(i,l,r);a.push(...d)}n.set(i,a)}catch(a){console.error(`Failed to fetch contributions for ${i}:`,a)}return n}async function ue(t,e){try{const[r,n]=t.split("/");if(!r||!n)throw new Error('Invalid repository name. Format should be "owner/repo"');const s=[];let o=1;const i=100;for(;;){const a={Accept:"application/vnd.github.v3+json"};e&&(a.Authorization=`Bearer ${e}`);const l=await fetch(`https://api.github.com/repos/${r}/${n}/contributors?per_page=${i}&page=${o}`,{headers:a});if(!l.ok)throw new Error(`GitHub API error: ${l.statusText}`);const d=await l.json();if(d.length===0)break;for(const h of d)h.login&&h.type==="User"&&s.push(h.login);if(d.length<i)break;o++}return s}catch(r){throw console.error(`Error fetching contributors for ${t}:`,r),r}}function fe(t){return t===0?0:t<=3?1:t<=6?2:t<=9?3:4}function de(t){const e=new Map,r={};for(const[s,o]of t.entries())for(const i of o){const l=(e.get(i.date)||0)+i.count;e.set(i.date,l);const d=new Date(i.date).getFullYear();r[d]=(r[d]||0)+i.count}const n=Array.from(e.entries()).map(([s,o])=>({date:s,count:o,level:he(o)})).sort((s,o)=>new Date(s.date).getTime()-new Date(o.date).getTime());return{total:r,contributions:n}}function he(t){return t===0?0:t<=5?1:t<=10?2:t<=15?3:4}function at(t,e,r){const n=[],s=new Map(t.map(i=>[i.date,i])),o=new Date(e);for(;o<=r;){const i=o.toISOString().split("T")[0],a=s.get(i);a?n.push(a):n.push({date:i,count:0,level:0}),o.setDate(o.getDate()+1)}return n}function ge(t){if(t.length===0){const r=new Date,n=new Date;return n.setFullYear(n.getFullYear()-1),{start:n,end:r}}const e=t.map(r=>new Date(r.date));return{start:new Date(Math.min(...e.map(r=>r.getTime()))),end:new Date(Math.max(...e.map(r=>r.getTime())))}}function me(t){if(t.length===0)return[];const e=[];let r=[];const n=new Date(t[0].date),s=n.getDay();for(let o=0;o<s;o++){const i=new Date(n);i.setDate(i.getDate()-(s-o)),r.push({date:i.toISOString().split("T")[0],count:0,level:0})}for(const o of t)r.push(o),r.length===7&&(e.push(r),r=[]);if(r.length>0){const o=new Date(r[r.length-1].date);for(;r.length<7;)o.setDate(o.getDate()+1),r.push({date:o.toISOString().split("T")[0],count:0,level:0});e.push(r)}return e}const ct={level0:"#ebedf0",level1:"#9be9a8",level2:"#40c463",level3:"#30a14e",level4:"#216e39",text:"#24292f",background:"#ffffff"},lt={level0:"#161b22",level1:"#0e4429",level2:"#006d32",level3:"#26a641",level4:"#39d353",text:"#c9d1d9",background:"#0d1117"};function _(t){return t==="light"?ct:lt}const pe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],ut=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ft=({contributions:t,theme:e,blockSize:r=12,blockMargin:n=3,showWeekdayLabels:s=!0,showMonthLabels:o=!0})=>{const i=me(t),a=u=>e[`level${u}`],l=u=>{if(!o||u>=i.length)return null;const g=i[u][0],m=new Date(g.date).getMonth();if(u===0)return ut[m];const x=i[u-1][0],L=new Date(x.date).getMonth();return m!==L?ut[m]:null},h=s?30:0;return c.jsxs("svg",{width:h+i.length*(r+n)+n,height:o?7*(r+n)+30:7*(r+n)+10,style:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[o&&c.jsx("g",{transform:`translate(${h}, 0)`,children:(()=>{const u=[];if(i.forEach((g,f)=>{const m=l(f);m&&u.push({x:f*(r+n),label:m})}),u.length>1){const g=u[0],f=u[1],m=2*(r+n);f.x-g.x<m&&u.shift()}return u.map((g,f)=>c.jsx("text",{x:g.x,y:10,fontSize:"10",fill:e.text,children:g.label},`month-${f}-${g.label}`))})()}),s&&c.jsx("g",{transform:`translate(0, ${o?20:0})`,children:[1,3,5].map(u=>c.jsx("text",{x:0,y:u*(r+n)+r,fontSize:"9",fill:e.text,textAnchor:"start",children:pe[u]},`weekday-${u}`))}),c.jsx("g",{transform:`translate(${h}, ${o?20:0})`,children:i.map((u,g)=>u.map((f,m)=>{const x=g*(r+n),D=m*(r+n);return c.jsx("rect",{x,y:D,width:r,height:r,rx:2,ry:2,fill:a(f.level),"data-date":f.date,"data-count":f.count,children:c.jsx("title",{children:`${f.date}: ${f.count} contribution${f.count!==1?"s":""}`})},`${f.date}`)}))})]})},ye=t=>{const{years:e,colorScheme:r="light",blockSize:n=12,blockMargin:s=3,fontSize:o=14,showWeekdayLabels:i=!0,showMonthLabels:a=!0,loading:l,error:d,githubToken:h,onDataLoad:u,onContributorsLoad:g}=t,[f,m]=E.useState(null),[x,D]=E.useState([]),[L,v]=E.useState(!0),[dt,ht]=E.useState(null),U=E.useRef(null),p=_(r),I="usernames"in t?t.usernames:void 0,T="repoName"in t?t.repoName:void 0,be=E.useCallback(async()=>{if(U.current!==null)try{const y=await ae(U.current,{cacheBust:!0,filter:P=>{var H;return!((H=P.classList)!=null&&H.contains("download-btn"))},backgroundColor:p.background,style:{display:"inline-block",height:"auto"}}),C=document.createElement("a");C.download=`${T||"merged-contributions"}.png`,C.href=y,C.click()}catch(y){console.error("Failed to download image",y)}},[U,T,p.background]);if(E.useEffect(()=>{(I||T)&&(async()=>{try{v(!0),ht(null);let C=[];if(T){const G=await ue(T,h);C=G,D(G),g==null||g(G)}else I&&(C=I,D(I));if(C.length===0){v(!1);return}const P=await le(C,e,h),O=de(P),{start:H,end:Ce}=ge(O.contributions),Se=at(O.contributions,H,Ce),gt={...O,contributions:Se};m(gt),u==null||u(gt)}catch(C){const P=C instanceof Error?C:new Error("Failed to load contributions");ht(P),console.error("Error loading contributions:",P)}finally{v(!1)}})()},[I,T,e,u,g,h]),L)return l?c.jsx(c.Fragment,{children:l}):c.jsx("div",{style:{padding:"20px",color:p.text},children:"Loading contributions..."});if(dt)return c.jsx("div",{style:{padding:"20px",color:p.text},children:d||`Error: ${dt.message}`});if(!f||f.contributions.length===0)return c.jsx("div",{style:{padding:"20px",color:p.text},children:"No contributions found"});const xe=Object.values(f.total).reduce((y,C)=>y+C,0);return c.jsxs("div",{ref:U,style:{padding:"20px",backgroundColor:p.background,borderRadius:"6px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[c.jsxs("div",{style:{marginBottom:"16px",display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[c.jsxs("div",{children:[c.jsx("h3",{style:{margin:"0 0 8px 0",color:p.text,fontSize:o},children:T?`${T} - Merged Contributions`:"Merged Contributions"}),c.jsxs("div",{style:{color:p.text,fontSize:o-2,opacity:.8},children:[x.length," contributor",x.length!==1?"s":""," • ",xe," total contributions"]}),c.jsx("div",{style:{color:p.text,fontSize:o-3,opacity:.6,marginTop:"4px"},children:x.length<=10?x.join(", "):`${x.slice(0,10).join(", ")} and ${x.length-10} more`})]}),c.jsxs("button",{className:"download-btn",onClick:be,style:{background:"transparent",border:`1px solid ${p.text}`,borderRadius:"4px",cursor:"pointer",padding:"6px 10px",color:p.text,opacity:.7,display:"flex",alignItems:"center",gap:"6px",fontSize:o-2,transition:"all 0.2s ease"},onMouseEnter:y=>{y.currentTarget.style.opacity="1",y.currentTarget.style.backgroundColor=p.text+"10"},onMouseLeave:y=>{y.currentTarget.style.opacity="0.7",y.currentTarget.style.backgroundColor="transparent"},title:"Download as Image",children:[c.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c.jsx("polyline",{points:"7 10 12 15 17 10"}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Download"]})]}),c.jsx(ft,{contributions:f.contributions,theme:p,blockSize:n,blockMargin:s,showWeekdayLabels:i,showMonthLabels:a}),c.jsxs("div",{style:{marginTop:"12px",display:"flex",alignItems:"center",gap:"8px",fontSize:o-3},children:[c.jsx("span",{style:{color:p.text,opacity:.6},children:"Less"}),[0,1,2,3,4].map(y=>c.jsx("div",{style:{width:n,height:n,backgroundColor:p[`level${y}`],borderRadius:"2px"},title:`Level ${y}`},y)),c.jsx("span",{style:{color:p.text,opacity:.6},children:"More"})]})]})},we=({colorScheme:t,blockSize:e=12,blockMargin:r=3})=>{const n=_(t),s=E.useMemo(()=>{const o=new Date().getFullYear(),i=new Date(o,0,1),a=new Date(o,11,31);return at([],i,a)},[]);return c.jsxs("div",{style:{padding:"20px",backgroundColor:n.background,borderRadius:"6px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[c.jsxs("div",{style:{marginBottom:"16px",display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[c.jsxs("div",{children:[c.jsx("div",{style:{height:"20px",width:"250px",backgroundColor:n.level0,borderRadius:"4px",marginBottom:"8px"}}),c.jsx("div",{style:{height:"14px",width:"180px",backgroundColor:n.level0,borderRadius:"4px",marginBottom:"4px"}}),c.jsx("div",{style:{height:"12px",width:"300px",backgroundColor:n.level0,borderRadius:"4px",marginTop:"4px"}})]}),c.jsx("div",{style:{height:"28px",width:"80px",backgroundColor:n.level0,borderRadius:"4px",opacity:.5}})]}),c.jsx("div",{className:"skeleton-shimmer",style:{display:"inline-block",borderRadius:"4px"},children:c.jsx(ft,{contributions:s,theme:n,blockSize:e,blockMargin:r,showWeekdayLabels:!0,showMonthLabels:!0})}),c.jsxs("div",{style:{marginTop:"12px",display:"flex",gap:"8px",alignItems:"center"},children:[c.jsx("div",{style:{height:"10px",width:"30px",backgroundColor:n.level0,borderRadius:"2px"}}),c.jsx("div",{style:{display:"flex",gap:"3px"},children:[0,1,2,3,4].map(o=>c.jsx("div",{style:{width:e,height:e,backgroundColor:n.level0,borderRadius:"2px"}},o))}),c.jsx("div",{style:{height:"10px",width:"30px",backgroundColor:n.level0,borderRadius:"2px"}})]})]})};S.MergedGitHubCalendar=ye,S.SkeletonCalendar=we,S.darkTheme=lt,S.getTheme=_,S.lightTheme=ct,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});