import{o as e,t}from"./payload-DyKkZIOX.mjs";function n(e){let t=e.createElement(`style`);return t.textContent=`
.bk-flame {
  display: grid;
  gap: var(--dt-space-2);
}

.bk-flame-bar {
  min-height: 2rem;
  padding: 0 var(--dt-space-3);
  border: 0;
  border-radius: var(--dt-radius-md);
  color: white;
  display: flex;
  align-items: center;
  overflow: hidden;
  cursor: zoom-in;
  box-shadow: var(--dt-shadow-sm);
}

.bk-flame-bar[data-root='true'] {
  cursor: zoom-out;
}

.bk-flame-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--dt-font-size-sm);
  font-weight: 600;
}
`,t}function r(t){if(!e(t)||typeof t.name!=`string`)return null;let n=typeof t.total==`number`?t.total:typeof t.value==`number`?t.value:0,i=Array.isArray(t.children)?t.children.flatMap(e=>{let t=r(e);return t?[t]:[]}):[];return{name:t.name,total:n,self:typeof t.self==`number`?t.self:void 0,children:i}}function i(e){return`hsl(${16+e*9%30} 82% ${Math.max(38,62-e*4)}%)`}function a(a,o={}){let s=t(a.ownerDocument),c=e(s)?r(s.profile):null;if(!c)return()=>{};let l=a.ownerDocument,u=n(l),d=a.innerHTML,f=[c],p=()=>{let e=f[f.length-1]??c;a.innerHTML=``;let t=l.createElement(`div`);t.className=`bk-flame`;let n=(r,a,o)=>{let s=l.createElement(`div`);s.style.paddingLeft=`${a*12}px`;let c=l.createElement(`div`);c.className=`bk-flame-bar`,c.dataset.root=String(o[o.length-1]===f[f.length-1]),c.style.background=i(a),c.style.width=`${Math.max(8,r.total/Math.max(e.total,1)*100)}%`,c.title=r.self===void 0?`${r.name}: ${r.total}`:`${r.name}: ${r.total} (self: ${r.self})`;let u=l.createElement(`span`);u.className=`bk-flame-label`,u.textContent=`${r.name} (${r.total})`,c.appendChild(u),c.addEventListener(`click`,()=>{f=o[o.length-1]===f[f.length-1]&&f.length>1?f.slice(0,-1):o,p()}),s.appendChild(c),t.appendChild(s);for(let e of r.children)n(e,a+1,[...o,e])};n(e,0,[...f]),a.appendChild(t)};return l.head?.appendChild(u),p(),()=>{u.remove(),a.innerHTML=d}}export{a as hydrateFlameGraph};