UNPKG

@kitn.ai/ui

Version:

Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.

2 lines (1 loc) 2.54 kB
import{s as p,g as O,h as C,c as u,i as h,a as f,b as m,k as w,m as y,S,t as v,v as $,w as z,p as M,u as R,e as B}from"./define-CNSKFZCd.js";import{c as g}from"./cn-CU7UAWzk.js";import{M as E}from"./markdown-n3Xbj3PR.js";import{c as P}from"./chevron-down-DcRg1aRU.js";const q=1;function A(i,s){let e=-1;const o=new ResizeObserver(n=>{var r;const t=((r=n[n.length-1])==null?void 0:r.contentRect.height)??i.getBoundingClientRect().height;(e<0||Math.abs(t-e)>q)&&(e=t,s(t))});return o.observe(i),()=>o.disconnect()}var D=v("<div>"),F=v("<button><span class=text-primary></span><div>"),G=v("<div style=max-height:0px><div>");const k=$();function H(){const i=z(k);if(!i)throw new Error("useReasoningContext must be used within a Reasoning provider");return i}function I(i){var s;const[e]=p(i,["children","class","open","defaultOpen","onOpenChange","isStreaming","disabled","controllerRef"]),[o,n]=O(e.defaultOpen??!1),[r,t]=O(!1),a=()=>e.open!==void 0,c=()=>a()?e.open:o(),d=()=>!!e.disabled,x=l=>{var b;c()!==l&&(a()||n(l),(b=e.onOpenChange)==null||b.call(e,l))};return C(()=>{const l=e.isStreaming;l&&!r()&&(a()||n(!0),t(!0)),!l&&r()&&(a()||n(!1),t(!1))}),(s=e.controllerRef)==null||s.call(e,{open:c,setOpen:x}),u(k.Provider,{value:{isOpen:c,onOpenChange:x,disabled:d},get children(){var l=D();return h(l,()=>e.children),f(()=>m(l,e.class)),l}})}function T(i){const[s,e]=p(i,["children","class"]),{isOpen:o,onOpenChange:n,disabled:r}=H();return(()=>{var t=F(),a=t.firstChild,c=a.nextSibling;return t.$$click=()=>{r()||n(!o())},w(t,y({get class(){return g("flex cursor-pointer items-center gap-2 text-meta",s.class)},get disabled(){return r()||void 0}},e),!1,!0),h(a,()=>s.children),h(c,u(P,{class:"size-4"})),f(()=>m(c,g("transform transition-transform",o()?"rotate-180":""))),t})()}function _(i){const[s,e]=p(i,["children","class","contentClass","markdown"]),{isOpen:o}=H();let n,r;return C(()=>{if(!n||!r)return;const t=A(r,()=>{n&&r&&o()&&(n.style.maxHeight=`${r.scrollHeight}px`)});o()?n.style.maxHeight=`${r.scrollHeight}px`:n.style.maxHeight="0px",M(t)}),(()=>{var t=G(),a=t.firstChild,c=n;typeof c=="function"?R(c,t):n=t,w(t,y({get class(){return g("overflow-hidden transition-[max-height] duration-150 ease-out",s.class)}},e),!1,!0);var d=r;return typeof d=="function"?R(d,a):r=a,h(a,u(S,{get when(){return s.markdown},get fallback(){return s.children},get children(){return u(E,{get content(){return s.children}})}})),f(()=>m(a,g("text-muted-foreground text-body",s.contentClass))),t})()}B(["click"]);export{I as R,T as a,_ as b};