From 12d326edd94438705ddf24ca90ca7096ec76b6de Mon Sep 17 00:00:00 2001
From: Claude
");
+ if (joined.startsWith("${joined}
${escapeHtml(codeLines.join("\n"))}`
- );
+ output.push(`${escapeHtml(codeLines.join("\n"))}`);
inCodeBlock = false;
codeLines = [];
codeLang = "";
@@ -428,9 +255,7 @@ function renderMarkdown(text) {
}
if (inCodeBlock) {
const langAttr = codeLang ? ` data-lang="${escapeHtml(codeLang)}"` : "";
- output.push(
- `${escapeHtml(codeLines.join("\n"))}`
- );
+ output.push(`${escapeHtml(codeLines.join("\n"))}`);
}
const paragraphs = [];
let current = [];
@@ -449,11 +274,6 @@ function renderMarkdown(text) {
}
return paragraphs.join("");
}
-function wrapParagraph(lines) {
- const joined = lines.join("${joined}`;
-}
// src/lem-message.ts
var LemMessage = class extends HTMLElement {
@@ -462,7 +282,7 @@ var LemMessage = class extends HTMLElement {
thinkContent;
thinkLabel;
contentEl;
- cursorEl;
+ cursorEl = null;
_text = "";
_streaming = false;
_thinkCollapsed = false;
@@ -504,7 +324,7 @@ var LemMessage = class extends HTMLElement {
this.shadow.appendChild(style);
this.shadow.appendChild(bubble);
if (this._text) {
- this.render();
+ this.updateContent();
}
}
get text() {
@@ -512,18 +332,18 @@ var LemMessage = class extends HTMLElement {
}
set text(value) {
this._text = value;
- this.render();
+ this.updateContent();
}
get streaming() {
return this._streaming;
}
set streaming(value) {
this._streaming = value;
- this.render();
+ this.updateContent();
}
appendToken(token) {
this._text += token;
- this.render();
+ this.updateContent();
}
/**
* Splits text into think/response portions and renders each.
@@ -532,7 +352,7 @@ var LemMessage = class extends HTMLElement {
* inline formatting is applied. The source is the local MLX model output,
* not arbitrary user HTML. Shadow DOM provides additional isolation.
*/
- render() {
+ updateContent() {
if (!this.contentEl) return;
const { think, response } = this.splitThink(this._text);
if (think !== null && this.thinkPanel) {
@@ -554,10 +374,6 @@ var LemMessage = class extends HTMLElement {
}
}
}
- /**
- * Split raw text into think content and response content.
- * Returns { think: string | null, response: string }
- */
splitThink(text) {
const thinkStart = text.indexOf("");
if (thinkStart === -1) {
@@ -580,99 +396,6 @@ var LemMessage = class extends HTMLElement {
};
customElements.define("lem-message", LemMessage);
-// src/lem-input.ts
-var LemInput = class extends HTMLElement {
- shadow;
- textarea;
- sendBtn;
- _disabled = false;
- constructor() {
- super();
- this.shadow = this.attachShadow({ mode: "open" });
- }
- connectedCallback() {
- const style = document.createElement("style");
- style.textContent = inputStyles;
- const wrapper = document.createElement("div");
- wrapper.className = "input-wrapper";
- this.textarea = document.createElement("textarea");
- this.textarea.rows = 1;
- this.textarea.placeholder = "Message LEM...";
- this.sendBtn = document.createElement("button");
- this.sendBtn.className = "send-btn";
- this.sendBtn.type = "button";
- this.sendBtn.disabled = true;
- this.sendBtn.appendChild(this.createSendIcon());
- wrapper.appendChild(this.textarea);
- wrapper.appendChild(this.sendBtn);
- this.shadow.appendChild(style);
- this.shadow.appendChild(wrapper);
- this.textarea.addEventListener("input", () => {
- this.textarea.style.height = "auto";
- this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
- this.sendBtn.disabled = this._disabled || this.textarea.value.trim() === "";
- });
- this.textarea.addEventListener("keydown", (e) => {
- if (e.key === "Enter" && !e.shiftKey) {
- e.preventDefault();
- this.submit();
- }
- });
- this.sendBtn.addEventListener("click", () => this.submit());
- }
- /** Build the send arrow SVG using DOM API (no innerHTML) */
- createSendIcon() {
- const ns = "http://www.w3.org/2000/svg";
- const svg = document.createElementNS(ns, "svg");
- svg.setAttribute("viewBox", "0 0 24 24");
- svg.setAttribute("fill", "none");
- svg.setAttribute("stroke", "currentColor");
- svg.setAttribute("stroke-width", "2");
- svg.setAttribute("stroke-linecap", "round");
- svg.setAttribute("stroke-linejoin", "round");
- svg.setAttribute("width", "16");
- svg.setAttribute("height", "16");
- const line = document.createElementNS(ns, "line");
- line.setAttribute("x1", "22");
- line.setAttribute("y1", "2");
- line.setAttribute("x2", "11");
- line.setAttribute("y2", "13");
- const polygon = document.createElementNS(ns, "polygon");
- polygon.setAttribute("points", "22 2 15 22 11 13 2 9 22 2");
- svg.appendChild(line);
- svg.appendChild(polygon);
- return svg;
- }
- submit() {
- const text = this.textarea.value.trim();
- if (!text || this._disabled) return;
- this.dispatchEvent(
- new CustomEvent("lem-send", {
- bubbles: true,
- composed: true,
- detail: { text }
- })
- );
- this.textarea.value = "";
- this.textarea.style.height = "auto";
- this.sendBtn.disabled = true;
- this.textarea.focus();
- }
- get disabled() {
- return this._disabled;
- }
- set disabled(value) {
- this._disabled = value;
- this.textarea.disabled = value;
- this.sendBtn.disabled = value || this.textarea.value.trim() === "";
- this.textarea.placeholder = value ? "LEM is thinking..." : "Message LEM...";
- }
- focus() {
- this.textarea?.focus();
- }
-};
-customElements.define("lem-input", LemInput);
-
// src/lem-chat.ts
var LemChat = class extends HTMLElement {
shadow;
@@ -715,7 +438,8 @@ var LemChat = class extends HTMLElement {
this.shadow.appendChild(this.messages);
this.shadow.appendChild(this.input);
this.addEventListener("lem-send", ((e) => {
- this.handleSend(e.detail.text);
+ const detail = e.detail;
+ this.handleSend(detail.text);
}));
const systemPrompt = this.getAttribute("system-prompt");
if (systemPrompt) {