UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

3 lines 43 kB
var ranui_tool_card=(function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=`:host{min-width:0;color:var(--ran-tool-card-color,var(--ran-color-text));font-size:var(--ran-tool-card-font-size,var(--ran-text-copy-2));display:block}:host([hidden]){display:none}.ran-tool-card-body{gap:var(--ran-tool-card-body-gap,var(--ran-space-2));padding:var(--ran-tool-card-body-padding,var(--ran-space-2) 0 var(--ran-space-2) var(--ran-space-6));flex-direction:column;display:flex}.ran-tool-card-io{border:1px solid var(--ran-tool-card-io-border-color,var(--ran-color-border));border-radius:var(--ran-tool-card-io-radius,var(--ran-radius-md));background:var(--ran-tool-card-io-background,var(--ran-color-bg-muted));flex-direction:column;min-width:0;display:flex}.ran-tool-card-io-section{column-gap:var(--ran-tool-card-io-gutter-gap,var(--ran-space-3));padding:var(--ran-tool-card-io-padding,var(--ran-space-3));max-height:var(--ran-tool-card-io-max-height,9.5rem);overscroll-behavior:contain;grid-template-columns:max-content 1fr;align-items:baseline;display:grid;overflow:auto}.ran-tool-card-io-section+.ran-tool-card-io-section{border-top:1px solid var(--ran-tool-card-io-border-color,var(--ran-color-border))}.ran-tool-card-io-label{color:var(--ran-tool-card-io-label-color,var(--ran-color-text-disabled));font-size:var(--ran-tool-card-io-label-size,var(--ran-text-label-3));font-family:var(--ran-tool-card-output-font,var(--ran-font-mono));-webkit-user-select:none;user-select:none;position:sticky;top:0}.ran-tool-card-io-text{min-width:0;font-weight:var(--ran-tool-card-output-weight,var(--ran-text-mono-weight-regular));font-family:var(--ran-tool-card-output-font,var(--ran-font-mono));white-space:pre-wrap;overflow-wrap:anywhere}.ran-tool-card-io-text[data-error]{color:var(--ran-tool-card-io-error-color,var(--ran-color-danger))}.ran-tool-card-output{max-height:var(--ran-tool-card-output-max-height,18rem);overscroll-behavior:contain;border-radius:var(--ran-tool-card-output-radius,var(--ran-radius-sm));background:var(--ran-tool-card-output-background,var(--ran-color-bg-muted));padding:var(--ran-tool-card-output-padding,var(--ran-space-2));font-weight:var(--ran-tool-card-output-weight,var(--ran-text-mono-weight-regular));font-family:var(--ran-tool-card-output-font,var(--ran-font-mono));white-space:pre;margin:0;overflow:auto}.ran-tool-card-output-wrap{white-space:pre-wrap;overflow-wrap:anywhere}.ran-tool-card-file+.ran-tool-card-file{margin-top:var(--ran-tool-card-file-gap,var(--ran-space-3))}.ran-tool-card-path{margin-bottom:var(--ran-tool-card-path-gap,var(--ran-space-1));color:var(--ran-tool-card-path-color,var(--ran-color-text-secondary));font-family:var(--ran-tool-card-output-font,var(--ran-font-mono))}.ran-tool-card-hunk{border-radius:var(--ran-tool-card-output-radius,var(--ran-radius-sm));background:var(--ran-tool-card-output-background,var(--ran-color-bg-muted));font-family:var(--ran-tool-card-output-font,var(--ran-font-mono));white-space:pre;overflow-x:auto}.ran-tool-card-hunk+.ran-tool-card-hunk{margin-top:var(--ran-tool-card-hunk-gap,var(--ran-space-2))}.ran-tool-card-line{gap:var(--ran-tool-card-line-gap,var(--ran-space-2));padding:0 var(--ran-tool-card-line-padding,var(--ran-space-2));display:flex}.ran-tool-card-line[data-kind=added]{background:var(--ran-tool-card-added-background,var(--ran-green-200))}.ran-tool-card-line[data-kind=removed]{background:var(--ran-tool-card-removed-background,var(--ran-red-200))}.ran-tool-card-gutter{min-width:var(--ran-tool-card-gutter-width,var(--ran-size-4));color:var(--ran-tool-card-gutter-color,var(--ran-color-text-disabled));text-align:right;-webkit-user-select:none;user-select:none;flex:none}.ran-tool-card-locations{gap:var(--ran-tool-card-locations-gap,var(--ran-space-2));margin-top:var(--ran-tool-card-locations-margin,var(--ran-space-3));flex-wrap:wrap;display:flex}.ran-tool-card-location{color:var(--ran-tool-card-location-color,var(--ran-color-link));font:inherit;font-family:var(--ran-tool-card-output-font,var(--ran-font-mono));cursor:pointer;background:0 0;border:none;padding:0}`,n=typeof document>`u`,r=class{ac=null;get signal(){return this.ac??=new AbortController,this.ac.signal}on(e,t,n,r){return e.addEventListener(t,n,{...r,signal:this.signal}),this}delegate(e,t,n,r,i){return e.addEventListener(n,n=>{let i=n.target?.closest(t);i&&e.contains(i)&&r(n,i)},{...i,signal:this.signal}),this}abort(){this.ac?.abort(),this.ac=null}},i=0,a=1,o=2,s=null,c=null,l=0,u=new Set,d=!1;function f(e,t){let n=t?.equals??Object.is,r={value:e,observers:new Set};return[()=>(ne(r),r.value),e=>{let t=typeof e==`function`?e(r.value):e;if(!n(r.value,t)){r.value=t;for(let e of r.observers)g(e,o);l===0&&re()}}]}function p(e){let t=ee(e,!0);return te(t),v(t),()=>y(t)}function m(e){let t={owned:[],cleanups:[],owner:c},n=c,r=s;c=t,s=null;try{return e(()=>ae(t))}finally{c=n,s=r}}function h(e){c&&c.cleanups.push(e)}function ee(e,t,n){return{fn:e,sources:new Set,isEffect:t,running:!1,disposed:!1,state:o,observers:new Set,value:void 0,equals:n??Object.is,owned:[],cleanups:[],owner:c}}function te(e){c&&c.owned.push(e)}function ne(e){s&&(s.sources.add(e),e.observers.add(s))}function g(e,t){if(e.disposed||e.state>=t)return;let n=e.state===i;if(e.state=t,e.isEffect)u.add(e);else if(n)for(let t of e.observers)g(t,a)}function re(){if(!(l>0||d)){d=!0;try{for(;u.size>0;){let e=[...u];u.clear();for(let t of e)t.disposed||_(t)}}finally{d=!1}}}function _(e){if(!(e.disposed||e.state===i)){if(e.state===a)for(let t of e.sources)`fn`in t&&_(t);e.state===o&&v(e),e.state=i}}function v(e){if(e.running)throw Error(`ranui reactivity: cyclic dependency detected (a computation triggered itself).`);ie(e);let t=s,n=c;s=e,c=e,e.running=!0,e.state=i;try{let t=e.fn();if(e.isEffect)typeof t==`function`&&e.cleanups.push(t);else{let n=e.value;if(e.value=t,e.observers.size>0&&!e.equals(n,t))for(let t of e.observers)g(t,o)}}finally{e.running=!1,s=t,c=n}}function ie(e){for(let t of e.owned)y(t);e.owned.length=0;for(let t of e.cleanups)t();e.cleanups.length=0;for(let t of e.sources)t.observers.delete(e);e.sources.clear()}function y(e){e.disposed||(e.disposed=!0,ie(e),e.observers.clear())}function ae(e){for(let t of e.owned)y(t);e.owned.length=0;for(let t of e.cleanups)t();e.cleanups.length=0}var oe=class{_events=new Map;tap=(e,t)=>{this._events.get(e)&&e!==Symbol.for(`NEW_LISTENER`)&&this.call(Symbol.for(`NEW_LISTENER`),e);let n=this._events.get(e)||new Set;return typeof t==`function`?n.add({name:e,callback:t}):n.add(t),this._events.set(e,n),this};call=(e,...t)=>((this._events.get(e)||new Set).forEach(e=>{let{callback:n}=e;n(...t)}),this);callSync=async(e,...t)=>{let n=this._events.get(e)||new Set;for(let e of n){let{callback:n}=e;await n(...t)}return this};once=(e,t)=>{let n;if(typeof t==`function`)n={name:e,callback:(...r)=>{t(...r),this.off(e,n)},initialCallback:t};else{let{callback:r}=t;n={name:e,callback:(...t)=>{r(...t),this.off(e,n)},initialCallback:r}}return this.tap(e,n),this};off=(e,t)=>{let n=[...this._events.get(e)||new Set].filter(e=>{if(typeof t==`function`)return e.callback!==t&&e.initialCallback!==t;{let{callback:n}=t;return e.callback!==n&&e.initialCallback!==n}});return this._events.set(e,new Set(n)),this}};Math.PI/180,180/Math.PI,2*Math.PI;var b=(e=8)=>Math.random().toString(36).substring(2,e+2);Object.freeze({});function x(e){if(e===``)return[];let t=e.split(` `);return t.at(-1)===``&&t.pop(),t}function se(e,t,n={}){let r=Math.max(0,n.context??3),i=x(e),a=x(t),o=0;for(;o<i.length&&o<a.length&&i[o]===a[o];)o+=1;let s=0;for(;s<i.length-o&&s<a.length-o&&i[i.length-1-s]===a[a.length-1-s];)s+=1;let c=i.slice(o,i.length-s),l=a.slice(o,a.length-s),u=(c.length+1)*(l.length+1)>4e6?function(e,t){return[...e.map((e,t)=>({kind:`removed`,text:e,oldLine:t+1,newLine:null})),...t.map((e,t)=>({kind:`added`,text:e,oldLine:null,newLine:t+1}))]}(c,l):function(e,t){let n=e.length+1,r=t.length+1,i=new Uint32Array(n*r);for(let n=e.length-1;n>=0;--n)for(let a=t.length-1;a>=0;--a)i[n*r+a]=e[n]===t[a]?i[(n+1)*r+a+1]+1:Math.max(i[(n+1)*r+a],i[n*r+a+1]);let a=[],o=0,s=0;for(;o<e.length&&s<t.length;)e[o]===t[s]?(a.push({kind:`context`,text:e[o],oldLine:o+1,newLine:s+1}),o+=1,s+=1):i[(o+1)*r+s]>=i[o*r+s+1]?(a.push({kind:`removed`,text:e[o],oldLine:o+1,newLine:null}),o+=1):(a.push({kind:`added`,text:t[s],oldLine:null,newLine:s+1}),s+=1);for(;o<e.length;o+=1)a.push({kind:`removed`,text:e[o],oldLine:o+1,newLine:null});for(;s<t.length;s+=1)a.push({kind:`added`,text:t[s],oldLine:null,newLine:s+1});return a}(c,l);return function(e,t){let n=e.map(e=>e.kind!==`context`);if(!n.includes(!0))return[];let r=Array.from({length:e.length},()=>!1);n.forEach((n,i)=>{if(n)for(let n=Math.max(0,i-t);n<=Math.min(e.length-1,i+t);n+=1)r[n]=!0});let i=[],a=[],o=()=>{if(a.length===0)return;let e=a.map(e=>e.oldLine).filter(e=>e!==null),t=a.map(e=>e.newLine).filter(e=>e!==null);i.push({oldStart:e[0]??0,oldLines:e.length,newStart:t[0]??0,newLines:t.length,lines:a}),a=[]};return r.forEach((t,n)=>{t?a.push(e[n]):o()}),o(),i}([...i.slice(0,o).map((e,t)=>({kind:`context`,text:e,oldLine:t+1,newLine:t+1})),...u.map(e=>({...e,oldLine:e.oldLine===null?null:e.oldLine+o,newLine:e.newLine===null?null:e.newLine+o})),...i.slice(i.length-s).map((e,t)=>({kind:`context`,text:e,oldLine:i.length-s+t+1,newLine:a.length-s+t+1}))],r)}var ce=e=>typeof e==`function`,le=12e4,ue=`__ranuts_bridge__`,de=`default`,S=new class{bridges=new Set;attachedWindow=null;handleMessage=e=>{for(let t of Array.from(this.bridges))t.receive(e)};add(e){this.bridges.add(e),typeof window<`u`&&this.attachedWindow!==window&&(window.addEventListener(`message`,this.handleMessage),this.attachedWindow=window)}remove(e){this.bridges.delete(e),this.bridges.size===0&&this.attachedWindow&&(this.attachedWindow.removeEventListener(`message`,this.handleMessage),this.attachedWindow=null)}},fe=class{targetWindow;targetOrigin;messageHandlers;pendingRequests;channel;senderId;available;constructor(e,t=`*`,n=de){this.targetOrigin=t,this.channel=n,this.senderId=b(12),this.messageHandlers=new Map,this.pendingRequests=new Map,this.available=typeof window<`u`,this.available?(this.targetWindow=e??window,S.add(this)):this.targetWindow=void 0}post(e,t){let n={...t,__bridge:ue,channel:this.channel,senderId:this.senderId};e.postMessage(n,this.targetOrigin)}receive=e=>{if(!this.available||this.targetOrigin!==`*`&&e.origin!==this.targetOrigin||e.source&&e.source!==this.targetWindow)return;let t=e.data;if(!t||typeof t!=`object`||t.__bridge!==`__ranuts_bridge__`||(t.channel??`default`)!==this.channel)return;let{type:n,payload:r,id:i,isResponse:a,isError:o,senderId:s}=t;if(a&&i){let e=this.pendingRequests.get(i);e&&(o?e.reject(Error(typeof r==`string`?r:`Bridge request failed`)):e.resolve(r),this.pendingRequests.delete(i));return}if(s&&s===this.senderId||typeof n!=`string`||!this.messageHandlers.has(n))return;let c=this.messageHandlers.get(n);if(ce(c)){let t=e.source??this.targetWindow;Promise.resolve(c(r)).then(e=>{i&&this.post(t,{type:n,payload:e,id:i,isResponse:!0})}).catch(e=>{i&&this.post(t,{type:n,payload:e instanceof Error?e.message:String(e),id:i,isResponse:!0,isError:!0})})}};on=(e,t)=>{this.messageHandlers.set(e,t)};off=e=>{this.messageHandlers.delete(e)};send=async(e,t)=>{if(!this.available)return Promise.reject(Error(`PostMessageBridge is unavailable outside a browser environment`));let n=b(10);return new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingRequests.has(n)&&(this.pendingRequests.delete(n),i(Error(`Request timeout`)))},le),o=e=>{clearTimeout(a),i(e)};this.pendingRequests.set(n,{resolve:e=>{clearTimeout(a),r(e)},reject:o});try{this.post(this.targetWindow,{type:e,payload:t,id:n})}catch(e){this.pendingRequests.delete(n),o(e instanceof Error?e:Error(`Failed to post message`))}})};broadcast=e=>{if(this.available)try{this.post(this.targetWindow,{type:e.type,payload:e.payload})}catch{}};destroy=()=>{S.remove(this),this.messageHandlers.clear(),this.pendingRequests.forEach(e=>{e.reject(Error(`Bridge destroyed`))}),this.pendingRequests.clear()}};(class e{static instance;bridges=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}connectClient=({id:e,targetOrigin:t,targetWindow:n,channel:r})=>{let i=new fe(n,t,r);if(e||=b(10),this.bridges.has(e))throw Error(`Bridge ${e} already exists`);return this.bridges.set(e,i),{bridge:i,id:e}};getClient=e=>this.bridges.get(e);removeClient=e=>{let t=this.bridges.get(e);t&&(t.destroy(),this.bridges.delete(e))};removeAllClient=()=>{this.bridges.forEach(e=>{e.destroy()}),this.bridges.clear()};broadcast=e=>{this.bridges.forEach(t=>{t.broadcast(e)})};sendTo=(e,t,n)=>{let r=this.getClient(e);return r?r.send(t,n):Promise.reject(Error(`Bridge ${e} not found`))}}).getInstance(),new oe;var C=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],w=class{highOrder;lowOrder;constructor(e,t){this.highOrder=e,this.lowOrder=t}};new w(C[0],3609767458),new w(C[1],602891725),new w(C[2],3964484399),new w(C[3],2173295548),new w(C[4],4081628472),new w(C[5],3053834265),new w(C[6],2937671579),new w(C[7],3664609560),new w(C[8],2734883394),new w(C[9],1164996542),new w(C[10],1323610764),new w(C[11],3590304994),new w(C[12],4068182383),new w(C[13],991336113),new w(C[14],633803317),new w(C[15],3479774868),new w(C[16],2666613458),new w(C[17],944711139),new w(C[18],2341262773),new w(C[19],2007800933),new w(C[20],1495990901),new w(C[21],1856431235),new w(C[22],3175218132),new w(C[23],2198950837),new w(C[24],3999719339),new w(C[25],766784016),new w(C[26],2566594879),new w(C[27],3203337956),new w(C[28],1034457026),new w(C[29],2466948901),new w(C[30],3758326383),new w(C[31],168717936),new w(C[32],1188179964),new w(C[33],1546045734),new w(C[34],1522805485),new w(C[35],2643833823),new w(C[36],2343527390),new w(C[37],1014477480),new w(C[38],1206759142),new w(C[39],344077627),new w(C[40],1290863460),new w(C[41],3158454273),new w(C[42],3505952657),new w(C[43],106217008),new w(C[44],3606008344),new w(C[45],1432725776),new w(C[46],1467031594),new w(C[47],851169720),new w(C[48],3100823752),new w(C[49],1363258195),new w(C[50],3750685593),new w(C[51],3785050280),new w(C[52],3318307427),new w(C[53],3812723403),new w(C[54],2003034995),new w(C[55],3602036899),new w(C[56],1575990012),new w(C[57],1125592928),new w(C[58],2716904306),new w(C[59],442776044),new w(C[60],593698344),new w(C[61],3733110249),new w(C[62],2999351573),new w(C[63],3815920427),new w(3391569614,3928383900),new w(3515267271,566280711),new w(3940187606,3454069534),new w(4118630271,4000239992),new w(116418474,1914138554),new w(174292421,2731055270),new w(289380356,3203993006),new w(460393269,320620315),new w(685471733,587496836),new w(852142971,1086792851),new w(1017036298,365543100),new w(1126000580,2618297676),new w(1288033470,3409855158),new w(1501505948,4234509866),new w(1607167915,987167468),new w(1816402316,1246189591),new w(0,1),new w(0,32898),new w(2147483648,32906),new w(2147483648,2147516416),new w(0,32907),new w(0,2147483649),new w(2147483648,2147516545),new w(2147483648,32777),new w(0,138),new w(0,136),new w(0,2147516425),new w(0,2147483658),new w(0,2147516555),new w(2147483648,139),new w(2147483648,32905),new w(2147483648,32771),new w(2147483648,32770),new w(2147483648,128),new w(0,32778),new w(2147483648,2147483658),new w(2147483648,2147516545),new w(2147483648,32896),new w(0,2147483649),new w(2147483648,2147516424);var pe=/["'&<>]/;function T(e){let t=``+e,n=pe.exec(t);if(!n)return t;let r,i=``,a=0,o=0;for(a=n.index;a<t.length;a++){switch(t.charCodeAt(a)){case 34:r=`&quot;`;break;case 38:r=`&amp;`;break;case 39:r=`&#39;`;break;case 60:r=`&lt;`;break;case 62:r=`&gt;`;break;default:continue}o!==a&&(i+=t.substring(o,a)),o=a+1,i+=r}return o===a?i:i+t.substring(o,a)}var me=new Map,he=new Map,ge=`data-adopted-style`,_e=`data-adopted-sheet`,E=(e,t,n)=>{if(typeof CSSStyleSheet>`u`)return!1;try{if(!n.has(t)){let e=new CSSStyleSheet;e.replaceSync(t),n.set(t,e)}let r=n.get(t);return e.adoptedStyleSheets.includes(r)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,r]),!0}catch{return!1}},ve=(e,t,n=ge)=>{if(typeof document<`u`&&t&&!E(e,t,me)&&!e.querySelector(`style[${n}]`)){let r=document.createElement(`style`);r.setAttribute(n,``),r.textContent=t,e.appendChild(r)}},ye=(e,t,n=_e)=>{if(typeof document<`u`&&t&&!E(e,t,he)&&!Array.from(e.querySelectorAll(`style[${n}]`)).some(e=>e.textContent===t)){let r=document.createElement(`style`);r.setAttribute(n,``),r.textContent=t,e.appendChild(r)}};(()=>{let e=new Uint8Array(128);for(let t=0;t<78;t++)e[`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.,!?;:'"()[]{}`.charCodeAt(t)]=1;return e})();var D=new Map([[100,`Continue`],[101,`Switching Protocols`],[102,`Processing`],[103,`Early Hints`],[200,`OK`],[201,`Created`],[202,`Accepted`],[203,`Non-Authoritative Information`],[204,`No Content`],[205,`Reset Content`],[206,`Partial Content`],[207,`Multi-Status`],[208,`Already Reported`],[226,`IM Used`],[300,`Multiple Choices`],[301,`Moved Permanently`],[302,`Found`],[303,`See Other`],[304,`Not Modified`],[305,`Use Proxy`],[307,`Temporary Redirect`],[308,`Permanent Redirect`],[400,`Bad Request`],[401,`Unauthorized`],[402,`Payment Required`],[403,`Forbidden`],[404,`Not Found`],[405,`Method Not Allowed`],[406,`Not Acceptable`],[407,`Proxy Authentication Required`],[408,`Request Timeout`],[409,`Conflict`],[410,`Gone`],[411,`Length Required`],[412,`Precondition Failed`],[413,`Payload Too Large`],[414,`URI Too Long`],[415,`Unsupported Media Type`],[416,`Range Not Satisfiable`],[417,`Expectation Failed`],[418,`I'm a Teapot`],[421,`Misdirected Request`],[422,`Unprocessable Entity`],[423,`Locked`],[424,`Failed Dependency`],[425,`Too Early`],[426,`Upgrade Required`],[428,`Precondition Required`],[429,`Too Many Requests`],[431,`Request Header Fields Too Large`],[451,`Unavailable For Legal Reasons`],[500,`Internal Server Error`],[501,`Not Implemented`],[502,`Bad Gateway`],[503,`Service Unavailable`],[504,`Gateway Timeout`],[505,`HTTP Version Not Supported`],[506,`Variant Also Negotiates`],[507,`Insufficient Storage`],[508,`Loop Detected`],[509,`Bandwidth Limit Exceeded`],[510,`Not Extended`],[511,`Network Authentication Required`]]);(function(e){let t=new Map;for(let[n,r]of e)t.set(r.toLowerCase(),n);return t})(D),function(e){let t=[];for(let[n,r]of e)t.push(n);return t}(D);function O(e){return T(e)}var be=e=>typeof e!=`string`&&`tagName`in e&&`childrenList`in e,xe=`.#[`;function Se(e){let t=[],n=0,r=/^[a-zA-Z][\w-]*/.exec(e);for(r!==null&&(t.push(r[0]),n=r[0].length);n<e.length;){let r=e[n];if(r===`[`){let r=e.indexOf(`]`,n+1);if(r===-1)return null;t.push(e.slice(n,r+1)),n=r+1;continue}if(r!==`.`&&r!==`#`)return null;let i=n+1;for(;i<e.length&&!xe.includes(e[i]);)i+=1;if(i===n+1)return null;t.push(e.slice(n,i)),n=i}return t.length>0?t:null}var Ce=(e,t)=>{let n=t;if(n.startsWith(`.`))return e.classList.contains(n.slice(1));if(n.startsWith(`#`))return e.getAttribute(`id`)===n.slice(1);if(n.startsWith(`[`)&&n.endsWith(`]`)){let[t,r]=n.slice(1,-1).trim().split(`=`),i=(t||``).trim();if(!i)return!1;if(r==null)return e.hasAttribute(i);let a=r.trim().replace(/^['"]|['"]$/g,``);return e.getAttribute(i)===a}return e.tagName===n.toLowerCase()},we=(e,t)=>{let n=t.trim();if(!n)return!1;let r=Se(n);return r!==null&&r.every(t=>Ce(e,t))},k=(e,t,n)=>{for(let r of e)be(r)&&(we(r,t)&&n.push(r),k(r.childrenList,t,n))},A=class{childrenList=[];appendChild(e){return this.childrenList.push(e),e}serialize(){return this.childrenList.map(e=>typeof e==`string`?T(e):e.serialize()).join(``)}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return k(this.childrenList,e,t),t}},j=class{tagName;attributes=new Map;inlineStyles=new Map;childrenList=[];shadowRoot=null;textContent=null;content;eventListeners=new Map;style={setProperty:(e,t)=>{let n=e.startsWith(`--`)?e:e.replace(/([A-Z])/g,`-$1`).toLowerCase();this.inlineStyles.set(n,t)},removeProperty:e=>this.inlineStyles.delete(e)};classList={add:(...e)=>{let t=this.attributes.get(`class`)||``,n=new Set([...t.split(` `).filter(Boolean),...e]);this.attributes.set(`class`,Array.from(n).join(` `))},remove:(...e)=>{let t=(this.attributes.get(`class`)||``).split(` `).filter(t=>!e.includes(t));this.attributes.set(`class`,t.join(` `))},toggle:e=>{this.classList.contains(e)?this.classList.remove(e):this.classList.add(e)},contains:e=>(this.attributes.get(`class`)||``).split(` `).includes(e)};_innerHTML=``;get innerHTML(){return this._innerHTML}set innerHTML(e){this._innerHTML=e,this.tagName===`template`&&this.content&&(this.content.childrenList=[e])}constructor(e=`div`){this.tagName=e.toLowerCase(),this.tagName===`template`&&(this.content=new A)}get hidden(){return this.hasAttribute(`hidden`)}set hidden(e){e?this.setAttribute(`hidden`,``):this.removeAttribute(`hidden`)}setAttribute(e,t){this.attributes.set(e,t)}getAttribute(e){return this.attributes.get(e)||null}removeAttribute(e){this.attributes.delete(e)}hasAttribute(e){return this.attributes.has(e)}appendChild(e){return this.childrenList.push(e),e}attachShadow(e){return this.shadowRoot=new Te(this,e),this.shadowRoot}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return k(this.childrenList,e,t),t}addEventListener(e,t){let n=this.eventListeners.get(e)||new Set;n.add(t),this.eventListeners.set(e,n)}removeEventListener(e,t){let n=this.eventListeners.get(e);n&&(n.delete(t),n.size===0&&this.eventListeners.delete(e))}dispatchEvent(e){let t=this.eventListeners.get(e.type);if(!t||t.size===0)return!0;for(let n of t)typeof n==`function`?n.call(this,e):n.handleEvent(e);return!e.defaultPrevented}serialize(e){typeof this._preSerialize==`function`&&this._preSerialize();let t=e||this._ssrTag||this.tagName,n=Array.from(this.attributes.entries()).map(([e,t])=>` ${e}="${O(t)}"`).join(``),r=Array.from(this.inlineStyles.entries()).map(([e,t])=>`${e}:${t}`).join(`;`),i=r?` style="${O(r)}"`:``,a=``;return this.shadowRoot&&(a+=this.shadowRoot.serialize()),this.textContent===null?this._innerHTML?a+=this._innerHTML:a+=this.childrenList.map(e=>typeof e==`string`?T(e):(e instanceof A,e.serialize())).join(``):a+=T(this.textContent),[`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`].includes(t)&&!a?`<${t}${n}${i} />`:`<${t}${n}${i}>${a}</${t}>`}},Te=class{host;options;childrenList=[];adoptedStyleSheets=[];constructor(e,t){this.host=e,this.options=t}appendChild(e){return this.childrenList.push(e),e}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return k(this.childrenList,e,t),t}serialize(){return`<template shadowrootmode="${this.options.mode}"${this.options.delegatesFocus?` shadowrootdelegatesfocus`:``}>${this.adoptedStyleSheets.map(e=>`<style>${T(e)}</style>`).join(``)}${this.childrenList.map(e=>typeof e==`string`?T(e):(e instanceof A,e.serialize())).join(``)}</template>`}},M=()=>({current:null}),N=e=>e.reduce((e,t)=>Array.isArray(t)?e.concat(N(t)):e.concat(t),[]),P=e=>e==null?null:e instanceof L?e.build():typeof e==`string`?n?e:document.createTextNode(e):e,Ee=(e,t)=>{if(n){I(e,[t()]);return}let r=document.createComment(``),i=document.createComment(``);e.appendChild(r),e.appendChild(i);let a=null,o=()=>{a?.(),a=null;let e=r.nextSibling;for(;e&&e!==i;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}};p(()=>{let e=t();o();let n=document.createDocumentFragment();a=m(t=>(I(n,[e]),t)),i.parentNode?.insertBefore(n,i)}),h(()=>a?.())},De=`__ranFor`,Oe=e=>typeof e==`object`&&!!e&&e[De]===!0,ke=(e,t,n)=>{let[r,i]=f(t),a=null,o=m(t=>{let i=P(n(e,r));return a=typeof i==`string`?document.createTextNode(i):i,t});return{node:a,index:i,dispose:o}},F=(e,t)=>{let n=e.parentNode;if(!n)return;let r=e;for(let e of t)r.nextSibling!==e&&n.insertBefore(e,r.nextSibling),r=e},Ae=(e,t)=>{if(n){(t.each()??[]).forEach((n,r)=>{let i=P(t.render(n,()=>r));i!=null&&e.appendChild(i)});return}let r=document.createComment(``);e.appendChild(r);let i=new Map;h(()=>{for(let e of i.values())e.dispose();i.clear()}),p(()=>{let e=t.each()??[],n=new Map,a=[];e.forEach((e,r)=>{let o=t.key(e,r);if(n.has(o))return;let s=i.get(o);s?(i.delete(o),s.index(r)):s=ke(e,r,t.render),n.set(o,s),s.node&&a.push(s.node)});for(let e of i.values())e.node?.parentNode?.removeChild(e.node),e.dispose();F(r,a),i=n})},je=`__ranIndex`,Me=e=>typeof e==`object`&&!!e&&e[je]===!0,Ne=(e,t,n)=>{let[r,i]=f(e),a=null,o=m(e=>{let i=P(n(r,t));return a=typeof i==`string`?document.createTextNode(i):i,e});return{node:a,setItem:i,dispose:o}},Pe=(e,t)=>{if(n){(t.each()??[]).forEach((n,r)=>{let i=P(t.render(()=>n,r));i!=null&&e.appendChild(i)});return}let r=document.createComment(``);e.appendChild(r);let i=[];h(()=>{for(let e of i)e.dispose();i=[]}),p(()=>{let e=t.each()??[];for(let n=0;n<e.length;n++)n<i.length?i[n].setItem(e[n]):i.push(Ne(e[n],n,t.render));for(let t=i.length-1;t>=e.length;t--){let{node:e}=i[t];e?.parentNode?.removeChild(e),i[t].dispose(),i.pop()}F(r,i.map(e=>e.node).filter(e=>e!=null))})},I=(e,t)=>{N(t).forEach(t=>{if(Oe(t)){Ae(e,t);return}if(Me(t)){Pe(e,t);return}if(typeof t==`function`){Ee(e,t);return}let n=P(t);n!=null&&e.appendChild(n)})},Fe=new Set(`svg.circle.clipPath.defs.desc.ellipse.feBlend.feColorMatrix.feComposite.feDropShadow.feFlood.feGaussianBlur.feMerge.feMergeNode.feOffset.filter.foreignObject.g.image.line.linearGradient.marker.mask.path.pattern.polygon.polyline.radialGradient.rect.stop.switch.symbol.text.textPath.tspan.use`.split(`.`)),L=class{el;constructor(e,t){let r=t??(Fe.has(e)?`http://www.w3.org/2000/svg`:void 0);this.el=n?new j(e):r?document.createElementNS(r,e):document.createElement(e)}id(e){return this.el.setAttribute(`id`,e),this}bind(e,t){typeof e==`function`?p(()=>t(e())):t(e)}class(e){return this.bind(e,e=>{n?this.el.attributes.set(`class`,e):this.el.className=e}),this}addClass(...e){return e.forEach(e=>this.el.classList.add(e)),this}removeClass(...e){return e.forEach(e=>this.el.classList.remove(e)),this}attr(e,t){return this.bind(t,t=>this.el.setAttribute(e,t)),this}attrs(e){return Object.entries(e).forEach(([e,t])=>{t!=null&&this.el.setAttribute(e,String(t))}),this}boolAttr(e,t,n=``){return this.bind(t,t=>{t?this.el.setAttribute(e,n):this.el.removeAttribute(e)}),this}part(e){return this.attr(`part`,e)}data(e,t){return this.attr(`data-${e}`,t)}style(e,t){return typeof e==`string`?this.bind(t??``,t=>this.el.style.setProperty(e,t)):Object.entries(e).forEach(([e,t])=>this.el.style.setProperty(e,t)),this}cssVar(e,t){let n=e.startsWith(`--`)?e:`--${e}`;return this.style(n,t)}aria(e,t){return this.attr(`aria-${e}`,t)}role(e){return this.attr(`role`,e)}tabIndex(e){return this.attr(`tabindex`,String(e))}label(e){return this.aria(`label`,e)}labelledBy(e){return this.aria(`labelledby`,e)}describedBy(e){return this.aria(`describedby`,e)}ariaHidden(e=!0){return this.aria(`hidden`,String(e))}on(e,t,n){return this.el.addEventListener(e,t,n),this}listen(e,t,n,r){return e.on(this.el,t,n,r),this}delegate(e,t,n,r,i){return e.delegate(this.el,t,n,r,i),this}children(...e){return I(this.el,e),this}replaceChildren(...e){if(n){let e=this.el;e.childrenList=[]}else this.el.replaceChildren();return this.children(...e)}text(e){return this.bind(e,e=>{this.el.textContent=e}),this}ref(e){return e.current=this.el,this}shadow(e={mode:`closed`}){let t=this.el.attachShadow(e);return new Ie(this.el,t,e)}build(){return this.el}serialize(){if(n)return this.el.serialize();let e=document.createElement(`div`);return e.appendChild(this.el.cloneNode(!0)),e.innerHTML}},Ie=class{root;hostEl;options;constructor(e,t,n){this.hostEl=e,this.root=t,this.options=n}children(...e){return I(this.root,e),this}adoptSheet(...e){return this.root.adoptedStyleSheets=[...this.root.adoptedStyleSheets,...e],this}css(e){if(n)return this.root.adoptedStyleSheets.push(e),this;if(typeof CSSStyleSheet<`u`)try{let t=new CSSStyleSheet;return t.replaceSync(e),this.root.adoptedStyleSheets=[...this.root.adoptedStyleSheets,t],this}catch{}let t=document.createElement(`style`);return t.textContent=e,this.root.appendChild(t),this}done(){return{host:this.hostEl,shadow:this.root}}serialize(){return n?this.root.serialize():this.root.innerHTML}},R=e=>new L(e),z=()=>R(`div`),B=()=>R(`span`),V=()=>R(`slot`),H=()=>R(`button`),Le=new Map;function U(e,t){n?(Le.set(e,t),t.prototype._ssrTag=e):customElements.get(e)||customElements.define(e,t)}var W=typeof document<`u`?HTMLElement:j,Re=`data-ranui`,ze=`data-ranui-sheet`,Be=(e,t)=>ve(e,t,Re),Ve=(e,t)=>ye(e,t,ze),G=new WeakMap,K=`@media (prefers-reduced-motion: reduce){*,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important;scroll-behavior:auto !important}}`,q=new Map,He=e=>{let t=q.get(e);if(t!==void 0)return t;let n=e?`${e}\n${K}`:K;return q.set(e,n),n},J=(e,t=``,n={mode:`closed`})=>{let r=e.shadowRoot||G.get(e)||e.attachShadow(n);return G.set(e,r),Be(r,He(t)),r},Y=(e,t)=>{if(e.current===null)throw Error(`ranui: ${t} is missing its .ref() on the builder`);return e.current},X=(e,t,n=``)=>e.getAttribute(t)??n,Z=(e,t,n,r={})=>{if(r.removeEmpty&&!n){e.removeAttribute(t);return}e.setAttribute(t,n??``)},Q=(e,t,n,r,i)=>{if(n!==`sheet`||r===i)return;let a=e.getAttribute(`sheet`)||``;a&&Ve(t,a)},Ue=`:host{min-width:0;color:var(--ran-disclosure-color,var(--ran-color-text));font-size:var(--ran-disclosure-font-size,var(--ran-text-copy-2));display:block}:host([hidden]){display:none}.ran-disclosure{flex-direction:column;min-width:0;display:flex}.ran-disclosure-row{align-items:center;gap:var(--ran-disclosure-gap,var(--ran-space-2));border-radius:var(--ran-disclosure-radius,var(--ran-radius-sm));width:100%;min-width:0;height:var(--ran-disclosure-row-height,24px);color:inherit;font:inherit;text-align:left;background:0 0;border:none;padding:0;display:flex;position:relative;overflow:hidden}:host([expandable]) .ran-disclosure-row{cursor:pointer}:host([expandable]) .ran-disclosure-row:hover{background:var(--ran-disclosure-hover-background,var(--ran-color-bg-hover))}.ran-disclosure-row:focus-visible{outline:2px solid var(--ran-disclosure-focus-color,var(--ran-color-primary));outline-offset:2px}.ran-disclosure-leading{width:var(--ran-disclosure-leading-size,16px);height:var(--ran-disclosure-leading-size,16px);color:var(--ran-disclosure-leading-color,var(--ran-color-text-secondary));flex:none;place-items:center;display:inline-grid}.ran-disclosure-icon,.ran-disclosure-chevron{transition:opacity var(--ran-disclosure-transition,.1s) ease;grid-area:1/1;justify-content:center;align-items:center;display:inline-flex}.ran-disclosure-chevron,:host([expandable]) .ran-disclosure-row:hover .ran-disclosure-icon,:host([expandable][open]) .ran-disclosure-icon{opacity:0}:host([expandable]) .ran-disclosure-row:hover .ran-disclosure-chevron,:host([expandable]) .ran-disclosure-row:focus-visible .ran-disclosure-chevron,:host([expandable][open]) .ran-disclosure-chevron{opacity:1}.ran-disclosure-title{font-weight:var(--ran-disclosure-title-weight,400);flex:none}.ran-disclosure-sep{background:var(--ran-disclosure-sep-color,var(--ran-color-text-disabled));border-radius:50%;flex:none;width:2px;height:2px}.ran-disclosure-summary{min-width:0;color:var(--ran-disclosure-summary-color,var(--ran-color-text-secondary));text-overflow:ellipsis;white-space:nowrap;flex:auto;overflow:hidden}:host([tone=error]) .ran-disclosure-summary{color:var(--ran-disclosure-error-color,var(--ran-color-danger))}:host([busy]) .ran-disclosure-row:after{content:"";background:linear-gradient(90deg, transparent 0%, var(--ran-disclosure-sweep-color,color-mix(in srgb, var(--ran-color-bg) 65%, transparent)) 55%, transparent 100%);width:var(--ran-disclosure-sweep-width,12rem);animation:ran-disclosure-sweep var(--ran-disclosure-sweep-duration,2.6s) ease-out infinite;pointer-events:none;position:absolute;top:0;bottom:0;left:0}@keyframes ran-disclosure-sweep{0%{left:-12rem}90%,to{left:100%}}@media (prefers-reduced-motion:reduce){:host([busy]) .ran-disclosure-row:after{animation:none}}.ran-disclosure-body{min-width:0}:host(:not([open])) .ran-disclosure-body{display:none}@media (prefers-reduced-motion:reduce){.ran-disclosure-icon,.ran-disclosure-chevron{transition:none}}`,We=`disclosuretoggle`;U(`r-disclosure-row`,class extends W{_events=new r;_shadowDom;_row;_title;_summary;_sep;static get observedAttributes(){return[`open`,`expandable`,`heading`,`summary`,`tone`,`busy`,`sheet`]}constructor(){super(),this._shadowDom=J(this,Ue);let e=M(),t=M(),n=M(),r=M(),i=z().class(`ran-disclosure`).attr(`part`,`disclosure`).children(H().class(`ran-disclosure-row`).ref(e).attr(`part`,`row`).attr(`type`,`button`).children(B().class(`ran-disclosure-leading`).attr(`part`,`leading`).children(B().class(`ran-disclosure-icon`).children(V().attr(`name`,`leading`).build()).build(),B().class(`ran-disclosure-chevron`).attr(`aria-hidden`,`true`).text(`▸`).build()).build(),B().class(`ran-disclosure-title`).ref(t).attr(`part`,`title`).build(),B().class(`ran-disclosure-sep`).ref(r).attr(`part`,`separator`).attr(`aria-hidden`,`true`).build(),B().class(`ran-disclosure-summary`).ref(n).attr(`part`,`summary`).build()).build(),z().class(`ran-disclosure-body`).attr(`part`,`body`).children(V().build()).build()).build();this._shadowDom.appendChild(i),this._row=Y(e,`row`),this._title=Y(t,`title`),this._summary=Y(n,`summary`),this._sep=Y(r,`separator`)}get open(){return this.hasAttribute(`open`)}set open(e){e!==this.open&&(e?this.setAttribute(`open`,``):this.removeAttribute(`open`))}get expandable(){return this.hasAttribute(`expandable`)}set expandable(e){e?this.setAttribute(`expandable`,``):this.removeAttribute(`expandable`)}get heading(){return X(this,`heading`)}set heading(e){Z(this,`heading`,e)}get summary(){return X(this,`summary`)}set summary(e){Z(this,`summary`,e)}get busy(){return this.hasAttribute(`busy`)}set busy(e){e?this.setAttribute(`busy`,``):this.removeAttribute(`busy`)}get tone(){return X(this,`tone`)}set tone(e){Z(this,`tone`,e)}get sheet(){return X(this,`sheet`)}set sheet(e){Z(this,`sheet`,e)}connectedCallback(){this.handlerExternalCss(),this._events.on(this._row,`click`,this._toggle),this._sync()}disconnectedCallback(){this._events.abort()}attributeChangedCallback(e,t,n){t!==n&&(e===`sheet`?this.handlerExternalCss():this._sync())}handlerExternalCss=()=>{Q(this,this._shadowDom,`sheet`,null,this.sheet)};_toggle=()=>{this.expandable&&(this.open=!this.open,this.dispatchEvent(new CustomEvent(We,{detail:{open:this.open},bubbles:!0,composed:!0})))};_sync(){let{heading:e,summary:t,expandable:n,open:r}=this;this._title.textContent=e,this._summary.textContent=t,this._sep.hidden=t===``||e===``,this._row.setAttribute(`aria-expanded`,n?String(r):`false`),n?(this._row.removeAttribute(`disabled`),this._row.removeAttribute(`aria-disabled`)):this._row.setAttribute(`aria-disabled`,`true`)}});var Ge=`:host{width:var(--ran-state-dot-size,8px);height:var(--ran-state-dot-size,8px);flex:none;display:inline-block}:host([hidden]){display:none}.ran-state-dot{width:100%;height:100%;color:var(--ran-state-dot-color,var(--ran-color-text-disabled));position:relative}.ran-state-dot:before,.ran-state-dot:after{content:"";background:currentColor;border-radius:50%;position:absolute}.ran-state-dot:before{opacity:var(--ran-state-dot-halo-opacity,.16);inset:0}.ran-state-dot:after{inset:20%}:host([state=running]) .ran-state-dot{color:var(--ran-state-dot-running-color,var(--ran-color-primary))}:host([state=success]) .ran-state-dot{color:var(--ran-state-dot-success-color,var(--ran-color-success))}:host([state=warning]) .ran-state-dot{color:var(--ran-state-dot-warning-color,var(--ran-color-warning))}:host([state=error]) .ran-state-dot{color:var(--ran-state-dot-error-color,var(--ran-color-danger))}:host([state=running]) .ran-state-dot:after{animation:1.4s ease-in-out infinite ran-state-dot-pulse}@keyframes ran-state-dot-pulse{0%,to{opacity:1;inset:20%}50%{opacity:.6;inset:32%}}@media (prefers-reduced-motion:reduce){:host([state=running]) .ran-state-dot:after{animation:none}}`,Ke=class extends W{_shadowDom;static get observedAttributes(){return[`state`,`label`,`sheet`]}constructor(){super(),this._shadowDom=J(this,Ge),this._shadowDom.appendChild(z().class(`ran-state-dot`).attr(`part`,`dot`).build())}get state(){let e=X(this,`state`,`idle`);return qe.has(e)?e:`idle`}set state(e){Z(this,`state`,e)}get label(){return X(this,`label`)}set label(e){Z(this,`label`,e)}get sheet(){return X(this,`sheet`)}set sheet(e){Z(this,`sheet`,e)}connectedCallback(){this.handlerExternalCss(),this._syncRole()}attributeChangedCallback(e,t,n){t!==n&&(e===`sheet`&&this.handlerExternalCss(),e===`label`&&this._syncRole())}handlerExternalCss=()=>{Q(this,this._shadowDom,`sheet`,null,this.sheet)};_syncRole(){let e=this.label;if(e===``){this.setAttribute(`aria-hidden`,`true`),this.removeAttribute(`role`),this.removeAttribute(`aria-label`);return}this.removeAttribute(`aria-hidden`),this.setAttribute(`role`,`img`),this.setAttribute(`aria-label`,e)}},qe=new Set([`idle`,`running`,`success`,`warning`,`error`]);U(`r-state-dot`,Ke);var Je=new Set([`generic`,`terminal`,`diff`]);function Ye(e){let t=e?.card;return typeof t==`string`&&Je.has(t)?t:`generic`}function Xe(e){if(e===null)return``;if(typeof e.summary==`string`)return e.summary;if(e.card===`terminal`)return e.description??e.cwd??``;if(e.card===`diff`)return Array.isArray(e.diffs)?e.diffs.map(e=>e.path).join(` · `):``;let t=e.card===`generic`?e.input:void 0,n=typeof t==`object`&&t?Object.values(t)[0]:void 0;return typeof n==`string`?n:``}var Ze={running:`running`,success:`success`,error:`error`},$=class extends W{_events=new r;_shadowDom;_row;_dot;_body;_call=null;_result=null;static get observedAttributes(){return[`status`,`open`,`sheet`]}constructor(){super(),this._shadowDom=J(this,t);let e=M(),n=M(),r=R(`r-disclosure-row`).attr(`part`,`row`).children(R(`r-state-dot`).ref(e).attr(`slot`,`leading`).build(),z().class(`ran-tool-card-body`).ref(n).attr(`part`,`body`).build()).build();this._shadowDom.appendChild(r),this._row=r,this._dot=Y(e,`state dot`),this._body=Y(n,`body`)}get call(){return this._call}set call(e){this._call=e,this._render()}get result(){return this._result}set result(e){this._result=e,this._render()}get status(){let e=X(this,`status`,`running`);return e===`success`||e===`error`?e:`running`}set status(e){Z(this,`status`,e)}get open(){return this.hasAttribute(`open`)}set open(e){e?this.setAttribute(`open`,``):this.removeAttribute(`open`)}get sheet(){return X(this,`sheet`)}set sheet(e){Z(this,`sheet`,e)}connectedCallback(){this.handlerExternalCss(),this._events.on(this._row,We,e=>{this.open=e.detail.open}),this._render()}disconnectedCallback(){this._events.abort()}attributeChangedCallback(e,t,n){t!==n&&(e===`sheet`?this.handlerExternalCss():this._render())}handlerExternalCss=()=>{Q(this,this._shadowDom,`sheet`,null,this.sheet)};_render(){let e=this._call,t=this.status;this._row.heading=e!==null&&`title`in e?e.title:``,this._row.summary=Xe(e),this._row.open=this.open,this._row.tone=t===`error`?`error`:``,this._row.busy=t===`running`,this._dot.state=Ze[t],this._body.replaceChildren();let n=Ye(this._result??e);n===`terminal`?this._renderTerminal():n===`diff`?this._renderDiff():this._renderGeneric();let r=e!==null&&`locations`in e?e.locations:void 0;Array.isArray(r)&&r.length>0&&this._body.appendChild(this._renderLocations(r)),this._row.expandable=this._body.childNodes.length>0}_ioCard(e,t,n){if(e===null&&t===null)return null;let r=z().class(`ran-tool-card-io`).attr(`part`,`io`).build(),i=(e,t,n)=>{let r=z().class(`ran-tool-card-io-section`).build(),i=B().class(`ran-tool-card-io-text`).attr(`part`,`io-text`).text(t).build();return n&&(i.dataset.error=``),r.append(B().class(`ran-tool-card-io-label`).attr(`aria-hidden`,`true`).text(e).build(),i),r};return e!==null&&r.appendChild(i(`IN`,e,!1)),t!==null&&r.appendChild(i(`OUT`,t,n)),r}_renderGeneric(){let e=this._call,t=this._result,n=e!==null&&e.card===`generic`&&e.input!==void 0?Object.entries(e.input).map(([e,t])=>`${e}: ${t}`).join(` `):null,r=t!==null&&t.card===`generic`&&t.content!==void 0?t.content:null,i=this._ioCard(n,r===``?null:r,this.status===`error`);i!==null&&this._body.appendChild(i)}_renderTerminal(){let e=this._call,t=this._result,n=e!==null&&e.card===`terminal`?e.cwd===void 0?null:`cwd: ${e.cwd}`:null;if(t===null||t.card!==`terminal`){let e=this._ioCard(n,null,!1);e!==null&&this._body.appendChild(e);return}let r=this._ioCard(n,null,!1);r!==null&&this._body.appendChild(r),this._body.appendChild(this._pre(t.output,`preserve`)),t.exitCode!==void 0&&t.exitCode!==0&&this._body.appendChild(z().class(`ran-tool-card-description`).attr(`part`,`exit`).text(`exit ${t.exitCode}`).build())}_renderDiff(){let e=this._result??this._call,t=e!==null&&e.card===`diff`?e.diffs:void 0;if(Array.isArray(t))for(let e of t)this._body.appendChild(this._renderFile(e))}_renderFile(e){let t=z().class(`ran-tool-card-file`).attr(`part`,`file`).build();t.appendChild(z().class(`ran-tool-card-path`).attr(`part`,`path`).text(e.path).build());for(let n of se(e.oldText??``,e.newText))t.appendChild(this._renderHunk(n));return t}_renderHunk(e){let t=z().class(`ran-tool-card-hunk`).attr(`part`,`hunk`).build();for(let n of e.lines){let e=z().class(`ran-tool-card-line`).attr(`part`,`line`).build();e.dataset.kind=n.kind,e.append(B().class(`ran-tool-card-gutter`).text(n.oldLine===null?``:String(n.oldLine)).build(),B().class(`ran-tool-card-gutter`).text(n.newLine===null?``:String(n.newLine)).build(),B().text(`${n.kind===`added`?`+`:n.kind===`removed`?`-`:` `}${n.text}`).build()),t.appendChild(e)}return t}_renderLocations(e){let t=z().class(`ran-tool-card-locations`).attr(`part`,`locations`).build();for(let n of e){let e=n.line===void 0?n.path:`${n.path}:${n.line}`,r=H().class(`ran-tool-card-location`).attr(`part`,`location`).attr(`type`,`button`).text(e).build();this._events.on(r,`click`,()=>{this.dispatchEvent(new CustomEvent(`locationclick`,{detail:{location:n},bubbles:!0,composed:!0}))}),t.appendChild(r)}return t}_pre(e,t){let n=document.createElement(`pre`);return n.className=t===`wrap`?`ran-tool-card-output ran-tool-card-output-wrap`:`ran-tool-card-output`,n.setAttribute(`part`,`output`),n.textContent=e,n}};return U(`r-tool-card`,$),e.ToolCard=$,e.default=$,e})({});