(function(){function e(e){return e.replace(/\\/g,`/`)}function t(t,n){let r=e(n).replace(/\/$/,``),i=e(t);return i===r?`.`:i.startsWith(`${r}/`)?`./${i.slice(r.length+1)}`:t}function n(r,i){if(typeof r!=`string`)return r.displayFile??(r.file?n(r.file,i):``);let a=r,o=e(a),s=o.lastIndexOf(`/node_modules/`);return s===-1?i?t(a,i).replace(/^\.\//,``):a:`…/${o.slice(s+14)}`}function r(e,t){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,t)??String(e)}catch{return String(e)}}function i(e,t={}){return a(e,t,2).join(` `)}function a(e,t,n){let i=`#`.repeat(Math.min(n,6)),c=[],l=e.kind===`warning`?`Warning`:e.kind===`compile`?`Compile error`:`Error`;c.push(`${i} ${l}: ${e.name}${e.code&&e.code!==e.name?` [${e.code}]`:``}`,``),c.push("```",e.message,"```",``),e.hint&&c.push(`> ${e.hint}`,``),e.docsUrl&&c.push(`Docs: ${e.docsUrl}`,``),e.trace?.length&&c.push(`Component trace: ${e.trace.map(e=>`\`${e.label}\``).join(` › `)}`,``);let u=e.frames.find(e=>e.type===`app`&&e.snippet);if(u?.snippet&&u.file)c.push(`\`${s(u,t)}\``,``),c.push(...o(u.snippet,u.line));else{let n=e.frames.find(e=>e.type===`app`&&e.compiled?.snippet)?.compiled;n?.snippet&&(c.push(`Generated code \`${s(n,t)}\``,``),c.push(...o(n.snippet,n.line)))}if(e.frames.length){c.push("```");let n=0;for(let r of e.frames){if(r.type!==`app`&&!t.allFrames){n++;continue}n&&=(c.push(` ... ${n} more`),0),c.push(` at ${[r.isAsync&&`async`,r.isConstructor&&`new`,r.function??``].filter(Boolean).join(` `)} (${s(r,t)})`)}n&&c.push(` ... ${n} more`),c.push("```",``)}for(let t of e.sections)if(t.id!==`headers`){if(c.push(`**${t.title}**`,``),typeof t.content==`string`)c.push("```",t.content,"```",``);else{for(let[e,n]of Object.entries(t.content))c.push(`- ${e}: \`${r(n)}\``);c.push(``)}}for(let r of e.causes)c.push(...a({...r,name:`Caused by ${r.name}`},t,n+1));for(let r of e.errors??[])c.push(...a(r,t,n+1));return c}function o(e,t){let n=[`\`\`\`${e.lang??``}`];for(let[r,i]of e.lines.entries()){let a=e.start+r;n.push(`${a===t?`>`:` `} ${String(a).padStart(String(e.start+e.lines.length).length)} | ${i}`)}return n.push("```",``),n}function s(e,n){return`${e.file?n.cwd?t(e.file,n.cwd):e.file:e.raw?.trim()??``}${e.line===void 0?``:`:${e.line}`}${e.column===void 0?``:`:${e.column}`}`}let c={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},l=/[&<>"']/,u=/[&<>"']/g;function d(e){let t=String(e);return l.test(t)?t.replace(u,e=>c[e]):t}function ee(e){if(!e)return;let t=e.replace(/[\u0000-\u0020\u007F]/g,``),n=/^([a-z][a-z0-9+.-]*):/i.exec(t)?.[1]?.toLowerCase();return!n||n===`http`||n===`https`||n===`mailto`?e:void 0}function f(e,t){return t==null||t===!1?``:` ${e}="${d(t)}"`}function te(e,t=1e3){return e.length<=t?{head:e,rest:``}:{head:e.slice(0,t),rest:e.slice(t)}}function ne(e){let t=[],n=[];for(let[r,i]of e.entries())i.type===`app`?(n.length&&(t.push({group:n}),n=[]),t.push({app:i,index:r})):n.push({frame:i,index:r});return n.length&&t.push({group:n}),t}let re=new Set(`abstract as async await break case catch class const continue debugger default delete do else enum export extends false finally for from function if implements import in instanceof interface let new null of package private protected public return satisfies static super switch this throw true try type typeof undefined var void while with yield`.split(` `)),p=/(\/\/[^\n\r\u2028\u2029]*|\/\*(?:(?!\*\/)[^\n\r\u2028\u2029])*(?:\*\/)?|`)||e.endsWith(`--!>`))?void 0:`html-comment`;if(e.startsWith("`"))return e.length>=2&&e.endsWith("`")&&!se(e,e.length-1)?void 0:`template`}function m(e,t,n){if(!t||t===`md`)return{tokens:[{type:`text`,text:e}],state:void 0};let r=[],i=0;if(n){let t=oe(e,n),a=n===`template`?`string`:`comment`;if(t<0)return{tokens:e?[{type:a,text:e}]:[],state:n};r.push({type:a,text:e.slice(0,t)}),i=t}let a=!1,o;p.lastIndex=i;for(let n=p.exec(e);n;n=p.exec(e)){n.index>i&&r.push({type:`text`,text:e.slice(i,n.index)});let s=n[0],c=1;for(;n[c]===void 0;)c++;let l=ie[c-1];o=void 0,c<=2?(o=ce(s),o===`template`?s=e.slice(n.index):o&&n.index+s.length`):l===`variable`&&(l=a||t===`css`&&e[n.index+s.length]===`:`?`attribute`:re.has(s)?`keyword`:ue(s.charCodeAt(0))?`type`:e[n.index+s.length]===`(`?`function`:`text`),r.push({type:l,text:s}),i=n.index+s.length,p.lastIndex=i}return im(e,t,void 0).tokens;function ue(e){return e>=65&&e<=90}let h=/* @__PURE__ */ new WeakMap;function de(e,t){let n=e.lines[t]??``;if(e.offset!==void 0)return le(n,e.lang)??[{type:`text`,text:n}];let r=h.get(e);for(r||(r={lines:[],state:e.continues},h.set(e,r));r.lines.length<=t&&r.lines.length${d(r.text)}`;return n}let g={file:``,down:``,context:``,history:``,warning:``,copy:``,check:``,info:``,theme:``,logs:``,open:``,chevron:``,prev:``,next:``,close:``,minimize:``},_={error:`Error`,warning:`Warning`,compile:`Compile error`};function me(e){if(e.kind!==`error`)return _[e.kind];let t=b(e).filter(e=>e.related).length+1;return`${t} error${t===1?``:`s`}`}function v(e,t=`r`){let{report:n}=e,r=!!e.channel,i=d(e.theme?.name??`my-bad`),a=`${e.theme?.logo??``}${i}`,o=ee(e.theme?.url);return`
${o?`${a} (opens in a new tab)`:`

${a}

`}${me(n)}
${r?``:``}
${ve(b(n).find(e=>e.path===t)?.report??n,e,t)} ${_e(e,t)}
${n.sections.length?``:``}${r?``:``}${e.history?.length?`
${g.history}History
    ${e.history.map((t,r)=>`
  1. `).join(``)}
`:``}
${r?De():``} ${n.sections.length?Oe(n.sections):``}
`}function y(e,t){return Math.max(0,t.findIndex(t=>t.id===e.id))}function he(e,t){if(!t||t.length<2)return``;let n=y(e,t);return`
  • ${n+1} of ${t.length}
  • `}function b(e,t=`r`,n=!1){return[{report:e,path:t,related:n,label:t===`r`?`Reported error`:n?`Related error`:e.causes.length?`Wrapped error`:`Root cause`},...e.causes.flatMap((e,r)=>b(e,`${t}c${r}`,n)),...(e.errors??[]).flatMap((e,n)=>b(e,`${t}e${n}`,!0))]}function ge(e,t){let n=b(e.report);if(n.length<2)return``;let r=n.some(e=>e.related),i=r?n:n.reverse(),a=i.findIndex(e=>e.path===t),o=(e,t=i[e].label)=>``;return i.length===2&&!r?``:``}function _e(e,t){let n=b(e.report),r=n.filter(e=>e.path!==t);if(!r.length)return``;let i=n.reduce((e,t)=>e+(t.report.omittedErrors??0),0),a=i?`

    and ${i} more related ${i===1?`error`:`errors`} not shown

    `:``;return`
    ${g.chevron}${r.length===1?`Cause`:`Causes and related errors`} ${r.length}${r.map(t=>`

    ${d(t.label)}

    ${ve(t.report,e,t.path,!1)}
    `).join(``)}${a}
    `}function ve(e,t,n,r=!0){let i=d(`mb-${n}-${e.id}`),a=r?`h1`:`h2`,o=ee(e.docsUrl),s=e.name===e.code,c=e.code?`${o?`${d(e.code)}${g.open} documentation (opens in a new tab)`:d(e.code)}`:``;return`

    ${e.kind===`error`?``:``}${d(s?_[e.kind]:e.name)}${s?``:`${e.kind===`error`?``:``}${_[e.kind]}`}${t.environment?`·${d(t.environment)}`:``}${c}${e.status?`HTTP ${d(e.status)}`:``}

    ${r?`
    `:``}
    ${ye(e,t,a,`${i}-message`)} ${e.hint?`

    ${d(e.hint)}${o?` Learn more`:``}

    `:``} ${r?ge(t,n):``} ${xe(e.frames,t,i)} ${e.trace?.length?`
    ${g.chevron}Component trace ${e.trace.length}${be(e,t)}
    `:``}
    `}function ye(e,t,n,r){let{head:i,rest:a}=te(e.message||e.name,t.maxMessageLength),o=a?``:``;return`<${n} class="mb-message" id="${r}" data-message>${d(i)}${o}`}function be(e,t){return`
      ${e.trace.map(e=>{let n=`${d(e.label)}`;return e.file?`
    1. `:`
    2. ${n}
    3. `}).join(``)}
    `}function xe(e,t,n){if(!e.length)return`

    No stack trace was provided. The error message and request context are still available to copy.

    `;let r=Math.max(0,e.findIndex(e=>e.type===`app`&&(e.snippet||e.compiled?.snippet))),i=e.filter(e=>e.type!==`app`).length,a=(e,n)=>n===r?n===0?``:`
  • ${d(e.function??``)} · Shown above
  • `:`
  • ${Se(e,t,!0)}
  • `,o=ne(e).map(e=>{if(`app`in e)return a(e.app,e.index);let t=e.group.filter(({index:e})=>e!==r);if(!t.length)return``;let n=t[0].index+1,i=t.at(-1).index+1,o=t.every(({frame:e})=>!e.snippet&&!e.compiled?.snippet);return`
  • ${n===i?n:`${n} – ${i}`}${t.length} framework frame${t.length===1?``:`s`} hidden${o?`Code not captured`:``}
      ${t.map(({frame:e,index:t})=>a(e,t)).join(``)}
  • `}).join(``);return`
    ${Se(e[r],t)}${o?`
    ${i?``:``}
    `:``}
    `}function Se(e,t,n=!1){let r=!!e.snippet&&e.line!==void 0,i=!!e.compiled?.snippet&&e.compiled.line!==void 0,a=n=>{if(!n.file)return`${d(e.raw??`Source location unavailable`)}`;let r=e.file?e:n;return``},o=n=>{let r=n?e.compiled:e;return r.snippet&&r.line!==void 0?Te(r.snippet,r.line,r.column,S(r,t)):`

    Source is unavailable at this stack location.

    `},s=Ce(e,i);return n&&!r&&!i?`
    ${d(e.function??``)}${a(e)}${s}
    `:`
    ${e.function?`${d(e.function)}`:``}${a(e)}${i?`${a(e.compiled)}`:``}
    ${r&&i?``:``}${s}${e.file?``:``}
    ${i?`

    Compiled JavaScript${e.compiled.file===e.file?` (in memory)`:``} · Editor opens the original source location.

    `:``}
    ${o(!1)}
    ${i?`
    ${o(!0)}
    `:``}
    `}function x(e,t){return t?.file?`${f(`${e}file`,t.file)}${f(`${e}line`,t.line)}${f(`${e}column`,t.column)}`:``}function Ce(e,t){return!e.file&&!(t&&e.compiled?.file)?``:``}function we(e,t,n,r){return`${d(S(e,r))}${t===void 0?``:`:${d(t)}${n===void 0?``:`:${d(n)}`}`}`}function S(e,t){return n(e,t.cwd)}function Te(e,t,n,r){let i=t>=e.start&&tt+3),a=String(e.start+e.lines.length-1).length,o=``;for(let[r,s]of e.lines.entries()){let c=e.start+r,l=c===t;o+=`3?` data-context="true"`:``}>${pe(e,r)||` `}${l?Ee(s,n===void 0?void 0:n-(e.offset??0)):``}`}let s=`Source${r?` of ${r}`:``}, line ${t} highlighted`;return`
    ${o}
    `}function Ee(e,t){if(t===void 0||!Number.isInteger(t))return``;let n=e.search(/\S/);return t>(n<0?e.length:n)&&t<=e.length+1?``:``}function De(){return``}function Oe(e){return`

    Info

    ${e.map(ke).join(``)}
    `}function ke(e){let t=typeof e.content==`string`?`
    ${d(e.content)}
    `:`
    ${Object.entries(e.content).map(([e,t])=>`
    ${d(e)}
    ${d(r(t,2))}
    `).join(``)}
    `;return`
    ${g.chevron}${d(e.title)}${t}
    `}function Ae(e){return`
    ${g.warning}
    `}let C={theme:`my-bad:theme`,dock:`my-bad:overlay:dock`,minimized:`my-bad:overlay:minimized`},w=!1,T=/* @__PURE__ */ new Set;function je(){let e=document.currentScript?.previousElementSibling;if(e instanceof HTMLScriptElement&&e.type===`application/json`)try{return JSON.parse(e.textContent||``)}catch{}return window.__MY_BAD__}function E(e,t){return k(()=>localStorage,e,t)}function D(e){return`my-bad:overlay:hidden${e?`:${e}`:``}`}function O(e,t){return k(()=>sessionStorage,e,t)}function k(e,t,n){try{let r=e();if(n===void 0)return r.getItem(t);n===null?r.removeItem(t):r.setItem(t,n)}catch{}return null}function A(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`mb-pip-button ${t}`,i.title=n,i.setAttribute(`aria-label`,n),i.dataset.action=e,i.innerHTML=r,i}function Me(){let e=je();if(!e)return;if(e.mode===`overlay`){let t=document.currentScript?.previousElementSibling?.previousElementSibling??document.querySelector(e.tag??`my-bad-overlay`);return t?j(e,t):void 0}let t=document.querySelector(`[data-my-bad-root]`);if(t)return{state:e,themeTarget:document.documentElement,root:t}}function j(e,t){let n=t.attachShadow({mode:`open`}),r=[];if(e.stylesUrl){let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e.stylesUrl,r.push(t)}let i=document.createElement(`style`);i.textContent=e.styles??``,r.push(i);let a=document.createElement(`div`);a.className=`mb-overlay`,a.dataset.overlay=``,a.setAttribute(`role`,`dialog`),a.setAttribute(`aria-modal`,`true`),a.setAttribute(`aria-label`,`Error details`),a.setAttribute(`lang`,`en`);let o=document.createElement(`div`);o.className=`mb-root`,o.dataset.myBadRoot=``,o.innerHTML=v(e);let s=A(`hide`,`mb-overlay-close`,`Hide error overlay`,g.close),c=A(`expand`,`mb-overlay-expand`,`Show error details`,``),l=document.createElement(`button`);l.type=`button`,l.className=`mb-restore`,l.dataset.action=`restore`,l.hidden=!0,l.textContent=`Show error overlay`;let u=document.createElement(`div`);return u.className=`mb-preview`,u.dataset.preview=``,u.hidden=!0,u.innerHTML=``,a.append(c,s,o,u),n.append(...r,a,l),{state:e,themeTarget:t,root:o,overlay:a,restore:l,preview:u}}function Ne(e){let t=e.state.theme?.scheme,n=E(C.theme),r=t??(n===`light`||n===`dark`?n:void 0)??(matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`);e.themeTarget.setAttribute(`data-theme`,r)}function Pe(e){let t=e.themeTarget.getAttribute(`data-theme`)===`dark`?`light`:`dark`;e.themeTarget.setAttribute(`data-theme`,t),E(C.theme,t)}function M(e,t){let n=e.root.querySelector(`[data-announce]`);n&&(n.textContent=``,setTimeout(()=>n.textContent=t,50))}function N(e){e.root.querySelector(`main`)?.focus({preventScroll:!0})}function P(e,t){w=t;let n=e.root.querySelector(`[data-live]`);n?.toggleAttribute(`data-connected`,t);let r=n?.querySelector(`[data-live-text]`);r&&(r.textContent=`Dev server: ${t?`connected`:`disconnected`}`)}function F(e){return e?[...e.childNodes]:[]}let I;function Fe(e){if(e.state.mode!==`overlay`||(clearTimeout(I),I=void 0,e.overlay?.isConnected))return;let t=document.createElement(e.themeTarget.localName);document.body.append(t),Object.assign(e,j(e.state,t)),st(e)}function L(e,t,n){Fe(e),e.selected=void 0,e.state.report=t,n&&(e.state.history=n);let r=F(e.root.querySelector(`[data-log-list]`)),i=e.root.querySelector(`[data-log-filter]`)?.value??``,a=!e.root.querySelector(`[data-logs]`)?.hasAttribute(`hidden`),o=F(e.root.querySelector(`[data-toasts]`));e.root.innerHTML=v(e.state),e.root.querySelector(`[data-fallback]`)?.remove(),r.length&&e.root.querySelector(`[data-log-list]`)?.replaceChildren(...r);let s=e.root.querySelector(`[data-log-filter]`);s&&(s.value=i),a&&(e.root.querySelector(`[data-logs]`)?.removeAttribute(`hidden`),e.root.querySelector(`[data-action="logs"]`)?.setAttribute(`aria-pressed`,`true`)),X(e),o.length&&e.root.querySelector(`[data-toasts]`)?.replaceChildren(...o),W(e),P(e,w),Z(e),e.root.scrollTop=0,M(e,`${t.kind===`warning`?`Warning`:`Error`}: ${t.name}: ${t.message}`),N(e)}let R=/* @__PURE__ */ new WeakMap;function z(e,t,n,r=!1){R.get(e)?.();let i=e.innerHTML,a=e.getAttribute(`aria-label`),o=e.getAttribute(`title`);r?(e.innerHTML=n===`copied`?g.check:g.copy,e.setAttribute(`aria-label`,t),e.title=t):e.textContent=t,e.dataset[n]=``;let s=()=>{R.get(e)===s&&(R.delete(e),e.innerHTML=i,r&&(Ie(e,`aria-label`,a),Ie(e,`title`,o)),delete e.dataset.copied,delete e.dataset.copyFailed)};return R.set(e,s),s}function Ie(e,t,n){n===null?e.removeAttribute(t):e.setAttribute(t,n)}function Le(e,t,n=!1){setTimeout(z(e,t,`copied`,n),1200)}function Re(e){let t=document.createElement(`textarea`);return t.value=e,t.readOnly=!0,t.setAttribute(`data-my-bad`,``),t.setAttribute(`aria-hidden`,`true`),t.style.cssText=`position:fixed;top:0;left:0;width:1px;height:1px;padding:0;border:0;opacity:0;z-index:2147483647`,document.body.append(t),t.focus({preventScroll:!0}),t.select(),t}function ze(e){let t=document.getSelection(),n=t?.rangeCount?t.getRangeAt(0):void 0,r=Re(e),i=!1;try{i=document.execCommand(`copy`)}catch{}return r.remove(),n&&t&&(t.removeAllRanges(),t.addRange(n)),i}function Be(e){return new Promise(t=>{let n=Re(e),r=new AbortController,i=r.signal,a=()=>{i.aborted||(r.abort(),n.remove(),t())};setTimeout(a,15e3),addEventListener(`keyup`,e=>{(e.key===`Escape`||(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`c`)&&a()},{capture:!0,signal:i}),n.addEventListener(`blur`,a,{signal:i})})}let Ve=()=>/mac|iphone|ipad/i.test(navigator.userAgent)?`⌘C`:`Ctrl+C`;async function He(e,t,n){let r=b(e.state.report).find(t=>t.path===e.selected)?.report??e.state.report;return We(e,t===`json`?JSON.stringify(r,null,2):`${t===`prompt`?`Help diagnose this error. Trace the root cause in the source, explain the failure, and propose the smallest appropriate fix. Verify the fix against the relevant behaviour. `:``}${i(r,{cwd:e.state.cwd})}`,n)}function Ue(e,t){let{dataset:n}=t,r=(e,t,n)=>e&&`${e}${t?`:${t}${n?`:${n}`:``}`:``}`,i=r(n.file,n.line,n.column),a=r(n.compiledFile,n.compiledLine,n.compiledColumn),o=(t.closest(`[data-frame]`)?.hasAttribute(`data-compiled`)?a:void 0)||i||a;return o?We(e,o,t,`location`):void 0}async function We(e,t,n,r){let i=r!==void 0,a=()=>{Le(n,i?`Copied ${r}`:`Copied`,i),i&&M(e,`Copied ${r}: ${t}`)};try{return await navigator.clipboard.writeText(t),a()}catch{}if(ze(t))return n.focus({preventScroll:!0}),a();let o=`Press ${Ve()}`,s=z(n,i?`${o} to copy the ${r}`:o,`copyFailed`,i);i&&M(e,`${o} to copy the ${r}`),await Be(t),s()}async function Ge(e,t,n,r){if(e.state.channel&&T.has(`open`))try{if((await fetch(`${e.state.channel}/open`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t,line:n?Number(n):void 0,column:r?Number(r):void 0})})).ok)return}catch{}let i=e.state.editor??`vscode`,a=document.createElement(`a`);a.href=`${i}://file/${t.replace(/^\//,``)}${n?`:${n}`:``}${r?`:${r}`:``}`,a.hidden=!0,e.root.append(a),a.click(),a.remove()}async function Ke(e,t){let n=e.state.history??[],r=n[y(e.state.report,n)+t];if(r&&e.state.channel)try{let t=await fetch(`${e.state.channel}/history/${encodeURIComponent(r.id)}?${Ze(e)}`);t.ok&&L(e,await t.json())}catch{}}let B=0;function qe(e,t){let n=e.root.querySelector(`[data-log-list]`);if(!n)return;let r=e.root.querySelector(`[data-log-filter]`)?.value??``,i=document.createElement(`li`);for(i.className=`mb-log`,i.dataset.log=``,i.dataset.level=t.level,i.hidden=!Je(t.level,r),i.innerHTML=`${d(t.level)}${d(t.text)}`,n.append(i);n.children.length>500;)n.firstElementChild?.remove();let a=n.parentElement??n;if(a.scrollTop=a.scrollHeight,X(e),e.root.querySelector(`[data-logs]`)?.hasAttribute(`hidden`)){B++;let t=e.root.querySelector(`[data-log-count]`);t&&(t.textContent=String(B),t.hidden=!1)}}function Je(e,t){return t?t===`error`?e===`error`||e===`fatal`:e===`warn`||e===`error`||e===`fatal`:!0}function Ye(e,t){let n=e.root.querySelector(`[data-logs]`),r=e.root.querySelector(`[data-action="logs"]`);if(!n)return;let i=t??n.hidden;if(n.hidden=!i,r?.setAttribute(`aria-pressed`,String(i)),X(e),i){B=0;let t=e.root.querySelector(`[data-log-count]`);t&&(t.hidden=!0)}}let V=!1,H=/* @__PURE__ */ new Map,U=0;function Xe(e,t){for(H.has(t.id)||U++,H.delete(t.id),H.set(t.id,t);H.size>50;)H.delete(H.keys().next().value);let n=e.root.querySelector(`[data-toasts]`);if(n)for(n.querySelector(`[data-toast-id="${CSS.escape(t.id)}"]`)?.remove(),n.insertAdjacentHTML(`beforeend`,Ae(t));n.children.length>4;)n.firstElementChild?.remove();W(e)}function W(e){let t=e.root.querySelector(`[data-warning-count]`);t&&(t.textContent=`${U} warning${U===1?``:`s`}`,t.hidden=U===0);let n=e.root.querySelector(`[data-log-count]`);n&&(n.textContent=String(B),n.hidden=B===0)}function Ze(e){let t=new URLSearchParams({path:`${location.pathname}${location.search}`});return e.state.requestId&&t.set(`requestId`,e.state.requestId),t}function Qe(e){return`${e.state.channel}/events?${Ze(e)}`}function $e(e){let t=e.root.querySelector(`[data-pager]`);t&&(t.outerHTML=he(e.state.report,e.state.history))}function et(e){if(!e.state.channel||typeof EventSource>`u`)return;window.__MY_BAD_CLIENT__=!0;let t=new EventSource(Qe(e));t.addEventListener(`open`,()=>P(e,!0)),t.addEventListener(`error`,()=>P(e,!1));let n=(e,n)=>{t.addEventListener(e,e=>{try{n(JSON.parse(e.data))}catch{}})};n(`hello`,t=>{T.clear();for(let e of t.actions)T.add(e);t.current&&t.current.id!==e.state.report.id?L(e,t.current,t.history):t.history&&(e.state.history=t.history)}),n(`history`,t=>{e.state.history=t.history,$e(e)}),n(`error:set`,t=>{V=!1,L(e,t.report,t.history);let n=e.root.querySelector(`[data-progress]`);n&&(n.hidden=!0),e.overlay&&Y(e,!1)}),n(`error:clear`,()=>{if(e.overlay){let t=e.overlay.getRootNode()?.host;e.overlay.setAttribute(`data-hidden`,``),K(e,!1),e.restore?.remove(),clearTimeout(I),I=setTimeout(()=>t?.remove(),250)}else t.close(),location.reload()}),n(`build`,t=>{let n=e.root.querySelector(`[data-progress]`);if(!n)return;n.hidden=t.percent!==void 0&&t.percent>=100,n.toggleAttribute(`data-indeterminate`,t.percent===void 0),t.percent===void 0?n.removeAttribute(`aria-valuenow`):(n.style.setProperty(`--mb-progress`,`${Math.max(0,Math.min(100,t.percent))}%`),n.setAttribute(`aria-valuenow`,String(Math.round(t.percent))));let r=n.querySelector(`[data-progress-label]`);r&&(r.textContent=t.message??t.phase)}),n(`warning`,t=>{e.state.history=t.history,Xe(e,t.report)}),n(`log`,t=>qe(e,t))}function G(e,t,n={}){let{persist:r=!0}=n;if(e.overlay){if(e.overlay.hasAttribute(`data-minimized`)===t)return J(e);e.overlay.toggleAttribute(`data-minimized`,t),t?e.overlay.querySelector(`[data-action="expand"]`)?.focus({preventScroll:!0}):N(e),e.overlay.setAttribute(`aria-modal`,String(!t)),r&&E(C.minimized,t?`1`:`0`),document.documentElement.style.overflow=t?``:`hidden`,K(e,!t&&!e.overlay.hasAttribute(`data-hidden`)),J(e)}}function K(e,t){let n=e.overlay?.getRootNode()?.host;if(n)for(let e of document.body.children)e!==n&&!e.hasAttribute(`data-my-bad`)&&e.tagName!==`SCRIPT`&&e.toggleAttribute(`inert`,t)}function q(e){let t=e.preview?.querySelector(`iframe`);if(!e.preview||!t)return;let n=Math.min(240/innerWidth,.28);e.preview.style.width=`${Math.round(innerWidth*n)}px`,e.preview.style.height=`${Math.round(innerHeight*n)}px`,t.style.width=`${innerWidth}px`,t.style.height=`${innerHeight}px`,t.style.transform=`scale(${n})`}function J(e){if(!e.preview||!e.overlay)return;let t=!e.overlay.hasAttribute(`data-minimized`)&&!e.overlay.hasAttribute(`data-hidden`)&&!V;if(e.preview.hidden=!t,e.overlay.toggleAttribute(`data-has-preview`,t),!t)return;q(e);let n=e.preview.querySelector(`iframe`),r=e.overlay.getRootNode().host,i=document.documentElement.cloneNode(!0);for(let e of i.querySelectorAll(`script, ${r.tagName.toLowerCase()}, [data-my-bad]`))e.remove();let a=document.createElement(`base`);a.href=location.href,i.querySelector(`head`)?.prepend(a);let o=`${document.doctype?``:``}${i.outerHTML}`;n&&n.dataset.snapshot!==String(o.length)&&(n.srcdoc=o,n.dataset.snapshot=String(o.length))}function Y(e,t){e.overlay&&e.restore&&(e.overlay.toggleAttribute(`data-hidden`,t),e.overlay.toggleAttribute(`inert`,t),e.restore.hidden=!t,O(D(e.state.cwd),t?`1`:`0`),K(e,!t&&!e.overlay.hasAttribute(`data-minimized`)),J(e))}function tt(e,t){e.overlay?.setAttribute(`data-dock`,t),e.preview?.setAttribute(`data-dock`,t),E(C.dock,t)}function nt(e,t,n,r){let i,a=!1;t.addEventListener(`pointerdown`,e=>{n()&&!e.target.closest(`[data-action="hide"], [data-action="hide-preview"]`)&&(i={x:e.clientX,y:e.clientY,moved:!1},t.setPointerCapture(e.pointerId))}),t.addEventListener(`pointermove`,e=>{i&&(!i.moved&&Math.hypot(e.clientX-i.x,e.clientY-i.y)<4||(i.moved=!0,t.setAttribute(`data-dragging`,``),t.style.translate=`${e.clientX-i.x}px ${e.clientY-i.y}px`))});let o=n=>{if(i){if(a=i.moved,i=void 0,t.removeAttribute(`data-dragging`),t.style.translate=``,a){let t=n.clientX{a&&(a=!1,e.stopPropagation(),e.preventDefault())},!0)}function rt(e){let t=e.overlay,n=E(C.dock)??`bottom-right`;t.setAttribute(`data-dock`,n),e.preview?.setAttribute(`data-dock`,n);let r=E(C.minimized);G(e,!!e.state.startMinimized||r===`1`,{persist:!1}),Y(e,O(D(e.state.cwd))===`1`),nt(e,t,()=>t.hasAttribute(`data-minimized`),()=>G(e,!1)),e.preview&&nt(e,e.preview,()=>!0,()=>G(e,!0)),t.addEventListener(`keydown`,n=>{let r=e.root.querySelector(`dialog[open], [data-menu-list]:not([hidden])`)||n.target.closest(`[data-toast]`);n.key===`Escape`&&!t.hasAttribute(`data-minimized`)&&!r&&G(e,!0);let i={ArrowLeft:e=>e.replace(`right`,`left`),ArrowRight:e=>e.replace(`left`,`right`),ArrowUp:e=>e.replace(`bottom`,`top`),ArrowDown:e=>e.replace(`top`,`bottom`)};t.hasAttribute(`data-minimized`)&&i[n.key]&&(n.preventDefault(),tt(e,i[n.key](it(e))))})}function it(e){return e.overlay?.getAttribute(`data-dock`)??`bottom-right`}function X(e){let t=e.root.querySelector(`[data-log-list]`),n=e.root.querySelector(`[data-log-empty]`);n&&(n.hidden=!!t?.querySelector(`[data-log]:not([hidden])`),n.textContent=t?.childElementCount?`No logs match this level.`:`No logs received yet.`);let r=t?.parentElement;r&&(r.scrollHeight>r.clientHeight+1?r.setAttribute(`tabindex`,`0`):r.removeAttribute(`tabindex`))}function Z(e){for(let t of e.root.querySelectorAll(`pre[data-snippet], pre.mb-snippet`))t.scrollWidth>t.clientWidth+1?t.setAttribute(`tabindex`,`0`):t.removeAttribute(`tabindex`)}function Q(e,t={}){for(let n of e.root.querySelectorAll(`.mb-cause-picker[open], .mb-history[open]`))t.except&&n.contains(t.except)||(n.open=!1,t.focusFrom&&n.contains(t.focusFrom)&&n.querySelector(`summary`)?.focus());for(let n of e.root.querySelectorAll(`[data-menu-list]`)){if(n===t.except||n.hidden)continue;n.hidden=!0;let e=n.previousElementSibling;e?.setAttribute(`aria-expanded`,`false`),t.focusFrom&&n.contains(t.focusFrom)&&e?.focus()}}function at(e){let t=e.root.querySelector(`[data-info]`);t&&!t.open&&t.showModal()}function ot(e){let t=e.overlay?.parentNode??e.root;t.addEventListener(`click`,n=>{if(n.target.matches?.(`dialog[open]`)){n.target.close();return}let r=n.target.closest(`[data-action]`);if(r&&t.contains(r))switch(r.dataset.action){case`theme`:return Pe(e);case`copy-menu`:{let t=r.nextElementSibling;if(!(t instanceof HTMLElement))return;let n=t.hidden;Q(e,{except:t}),t.hidden=!n,r.setAttribute(`aria-expanded`,String(n));return}case`copy`:He(e,r.dataset.copy??`markdown`,r),setTimeout(Q,1200,e);return;case`copy-location`:Ue(e,r);return;case`open`:Ge(e,r.dataset.file,r.dataset.line,r.dataset.column);return;case`cause`:{let t=b(e.state.report).find(e=>e.path===r.dataset.path);if(!t)return;e.selected=t.path;let n=document.createElement(`div`);n.innerHTML=v(e.state,e.selected);let i=n.querySelector(`.mb-report`);if(!i)return;e.root.querySelector(`.mb-report`)?.replaceWith(i),Z(e),M(e,`${t.label}: ${t.report.name}: ${t.report.message}`),N(e);return}case`expand-message`:(r.closest(`[data-message]`)?.querySelector(`[data-message-rest]`))?.removeAttribute(`hidden`),r.remove();return;case`context`:{let t=r.closest(`[data-frame]`);if(!t)return;let n=t.toggleAttribute(`data-expanded`);r.setAttribute(`aria-expanded`,String(n));let i=n?`Less context`:`More context`;r.setAttribute(`aria-label`,i),r.title=i,Z(e);return}case`stack`:{let t=r.closest(`[data-stack]`)?.querySelector(`.mb-frames`);if(!t)return;t.hidden=!t.hidden,r.setAttribute(`aria-expanded`,String(!t.hidden)),Z(e);return}case`framework`:{let t=r.closest(`[data-stack]`);if(!t)return;r.setAttribute(`aria-checked`,String(t.toggleAttribute(`data-framework`))),Z(e);return}case`toggle-compiled`:{let t=r.closest(`[data-frame]`),n=t?.querySelector(`[data-snippet-source]`),i=t?.querySelector(`[data-snippet-compiled]`);if(!t||!n||!i)return;let a=r.dataset.switch===`compiled`;t.toggleAttribute(`data-compiled`,a),n.hidden=a,i.hidden=!a;for(let e of t.querySelectorAll(`[data-switch]`))e.setAttribute(`aria-pressed`,String(e.dataset.switch===`compiled`===a));Z(e);return}case`info`:return at(e);case`close-info`:return e.root.querySelector(`[data-info]`)?.close();case`logs`:return Ye(e);case`clear-logs`:{let t=e.root.querySelector(`[data-log-list]`);t&&(t.innerHTML=``),B=0,W(e),X(e);return}case`history`:Ke(e,Number(r.dataset.dir));return;case`dismiss-toast`:{n.stopPropagation();let e=r.closest(`[data-toast]`);return e?.dataset.toastId&&H.delete(e.dataset.toastId),e?.remove()}case`show-toast`:{let t=r.closest(`[data-toast]`),n=t&&H.get(t.dataset.toastId);n&&(t.remove(),H.delete(n.id),L(e,n));return}case`minimize`:return G(e,!0);case`hide`:return n.stopPropagation(),Y(e,!0);case`restore`:return Y(e,!1);case`expand`:return n.stopPropagation(),G(e,!1);case`hide-preview`:return n.stopPropagation(),V=!0,J(e)}}),t.addEventListener(`click`,t=>{t.target.closest(`[data-menu], .mb-cause-picker, .mb-history`)||Q(e)}),t.addEventListener(`toggle`,()=>Z(e),!0),t.addEventListener(`change`,t=>{let n=t.target;if(n.matches(`[data-log-filter]`)){for(let t of e.root.querySelectorAll(`[data-log]`))t.hidden=!Je(t.dataset.level??``,n.value);X(e)}}),t.addEventListener(`keydown`,t=>{let n=t,r=n.target;if(n.key===`Escape`){Q(e,{focusFrom:r});let t=r.closest(`[data-toast]`);t&&(t.dataset.toastId&&H.delete(t.dataset.toastId),t.remove(),e.root.querySelector(`main`)?.focus())}})}function st(e){e.root.querySelector(`[data-fallback]`)?.remove(),Ne(e),ot(e),e.overlay&&rt(e),Z(e),e.overlay?.hasAttribute(`data-minimized`)||N(e)}let $=Me();$ &&(st($),addEventListener(`resize`,()=>{Z($),q($)}),et($))})();