ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
106 lines (105 loc) • 3.82 kB
JavaScript
import { T as a, _ as o, i as h, m as l, p as d } from "./factory-WDxu11V0.js";
import { t as u } from "./events-Cqz3ramM.js";
import "./builder-EH76YCFS.js";
import { a as c, i as n, n as i, o as p, t as g } from "./utils-U-9uH7EX.js";
import { a as b, n as w } from "./ssr-BzykYefm.js";
import { t as _ } from "./disclosure-row-B6EePiK9.js";
var f = ":host{display:block;min-width:0;color:var(--ran-reasoning-color, var(--ran-color-text-secondary));font-size:var(--ran-reasoning-font-size, var(--ran-text-copy-2))}:host([hidden]){display:none}.ran-reasoning-body{border-left:2px solid var(--ran-reasoning-border-color, var(--ran-color-border));padding:var(--ran-reasoning-body-padding, var(--ran-space-1) 0 var(--ran-space-2) var(--ran-space-3));margin-left:var(--ran-reasoning-body-indent, var(--ran-space-2));overflow-wrap:anywhere;white-space:pre-wrap}";
function m(t, e) {
const r = t.trimEnd();
if (r === "") return "";
if (!e) return r.split(`
`, 1)[0] ?? "";
const s = r.lastIndexOf(`
`);
return s === -1 ? r : r.slice(s + 1);
}
var v = class extends w {
_events = new u();
_shadowDom;
_row;
_text;
_readerOwns = !1;
_writingOpen = !1;
_content = "";
static get observedAttributes() {
return [
"open",
"streaming",
"label",
"duration",
"sheet"
];
}
constructor() {
super(), this._shadowDom = g(this, f);
const t = a(), e = o("r-disclosure-row").attr("part", "row").attr("expandable", "").children(h().class("ran-reasoning-body").attr("part", "body").children(l().class("ran-reasoning-text").ref(t).attr("part", "text").build(), d().build()).build()).build();
this._shadowDom.appendChild(e), this._row = e, this._text = c(t, "text");
}
get content() {
return this._content;
}
set content(t) {
this._content = t, this._text.textContent = t, this._syncRow();
}
get streaming() {
return this.hasAttribute("streaming");
}
set streaming(t) {
t ? this.setAttribute("streaming", "") : this.removeAttribute("streaming");
}
get open() {
return this.hasAttribute("open");
}
set open(t) {
t !== this.open && (t ? this.setAttribute("open", "") : this.removeAttribute("open"));
}
get label() {
return i(this, "label", "Reasoning");
}
set label(t) {
n(this, "label", t);
}
get duration() {
const t = this.getAttribute("duration");
if (t === null) return null;
const e = Number(t);
return Number.isFinite(e) && e >= 0 ? e : null;
}
set duration(t) {
n(this, "duration", t === null ? null : String(t));
}
get sheet() {
return i(this, "sheet");
}
set sheet(t) {
n(this, "sheet", t);
}
connectedCallback() {
this.handlerExternalCss(), this._events.on(this._row, _, (t) => {
this._readerOwns = !0, this._writingOpen = !0, this.open = t.detail.open, this._writingOpen = !1;
}), this._syncRow();
}
disconnectedCallback() {
this._events.abort();
}
attributeChangedCallback(t, e, r) {
e !== r && (t === "sheet" && this.handlerExternalCss(), (t === "label" || t === "duration") && this._syncRow(), t === "streaming" && this._followStreaming(r !== null), t === "open" && (this._writingOpen || (this._readerOwns = !0), this._syncRow()));
}
handlerExternalCss = () => {
p(this, this._shadowDom, "sheet", null, this.sheet);
};
_followStreaming(t) {
this._syncRow(), !this._readerOwns && (this._writingOpen = !0, this.open = t, this._writingOpen = !1);
}
_syncRow() {
const t = this.streaming, e = this.duration;
this._row.open = this.open, this._row.busy = t;
const r = e === null || e < 1e3 ? "" : `${(e / 1e3).toFixed(1)}s`;
this._row.heading = r === "" ? this.label : `${this.label} · ${r}`, this._row.summary = m(this._content, t);
}
};
b("r-reasoning", v);
export {
v as t
};