@nivaro/react 0.3.128 → 0.3.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,334 +1,353 @@
1
- import { jsx as l, jsxs as f } from "react/jsx-runtime";
2
- import { useMemo as k, createContext as C, useState as S, useContext as $, Suspense as W, lazy as L } from "react";
3
- import { useOptionalNivaroClient as O, useNavigation as B } from "../../context.js";
4
- import { useGlossary as I, glossarySegments as T } from "../../lib/glossary.js";
5
- import { cn as w } from "../../lib/utils.js";
6
- import { AutolinkedText as _ } from "../AutolinkedText.js";
7
- import { formatsFor as j, rowsOfBlock as M, listOf as P, chartOf as E } from "./answer-formats.js";
8
- import { useGlossaryHref as K, GlossaryMark as R } from "./GlossaryText.js";
9
- function F(t) {
1
+ import { jsx as a, jsxs as k } from "react/jsx-runtime";
2
+ import { useMemo as g, createContext as $, useState as O, useContext as S, Suspense as _, lazy as B } from "react";
3
+ import { useOptionalNivaroClient as I, useNavigation as P } from "../../context.js";
4
+ import { useGlossary as T, glossarySegments as j } from "../../lib/glossary.js";
5
+ import { cn as b } from "../../lib/utils.js";
6
+ import { AutolinkedText as E } from "../AutolinkedText.js";
7
+ import { formatsFor as K, rowsOfBlock as R, listOf as F, chartOf as H } from "./answer-formats.js";
8
+ import { useGlossaryHref as G, GlossaryMark as D } from "./GlossaryText.js";
9
+ function U(e) {
10
10
  try {
11
- const e = JSON.parse(t), r = e.type === "line" || e.type === "pie" ? e.type : "bar", i = Array.isArray(e.data) ? e.data.map((n) => ({ label: String((n == null ? void 0 : n.label) ?? ""), value: Number(n == null ? void 0 : n.value) })).filter((n) => n.label && Number.isFinite(n.value)).slice(0, 40) : [];
12
- return i.length < 2 ? null : { type: r, title: typeof e.title == "string" ? e.title : void 0, data: i };
11
+ const n = JSON.parse(e), s = n.type === "line" || n.type === "pie" ? n.type : "bar", t = Array.isArray(n.data) ? n.data.map((r) => ({ label: String((r == null ? void 0 : r.label) ?? ""), value: Number(r == null ? void 0 : r.value) })).filter((r) => r.label && Number.isFinite(r.value)).slice(0, 40) : [];
12
+ return t.length < 2 ? null : { type: s, title: typeof n.title == "string" ? n.title : void 0, data: t };
13
13
  } catch {
14
14
  return null;
15
15
  }
16
16
  }
17
- const N = /^\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;
18
- function v(t) {
19
- return t.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim());
17
+ const y = /^\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;
18
+ function A(e) {
19
+ return e.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((n) => n.trim());
20
20
  }
21
- function H(t) {
22
- return t.split(`
23
- `).flatMap((e) => {
24
- const r = e.trim();
25
- return !r.startsWith("|") || !/\|\s*\|\s*[:-]{2,}/.test(r) && !/\|\s+\|\s*\S/.test(r) ? [e] : (r.match(/\|\s+\|/g) ?? []).length < 1 ? [e] : r.split(/\|\s+(?=\|)/).map((i) => i.trim().endsWith("|") ? i.trim() : `${i.trim()} |`);
21
+ function z(e) {
22
+ return e.split(`
23
+ `).flatMap((n) => {
24
+ const s = n.trim();
25
+ return !s.startsWith("|") || !/\|\s*\|\s*[:-]{2,}/.test(s) && !/\|\s+\|\s*\S/.test(s) ? [n] : (s.match(/\|\s+\|/g) ?? []).length < 1 ? [n] : s.split(/\|\s+(?=\|)/).map((t) => t.trim().endsWith("|") ? t.trim() : `${t.trim()} |`);
26
26
  }).join(`
27
27
  `);
28
28
  }
29
- function G(t) {
30
- const e = H(t.replace(/\r\n/g, `
29
+ function C(e, n = {}) {
30
+ const s = n.charts !== !1, t = z(e.replace(/\r\n/g, `
31
31
  `)).split(`
32
32
  `), r = [];
33
- let i = [];
34
- const n = () => {
35
- i.length && r.push({ kind: "p", text: i.join(" ") }), i = [];
33
+ let l = [];
34
+ const u = () => {
35
+ l.length && r.push({ kind: "p", text: l.join(" ") }), l = [];
36
36
  };
37
- for (let s = 0; s < e.length; s++) {
38
- const a = e[s].trim();
39
- if (a.startsWith("```")) {
40
- n();
41
- const o = a.slice(3).trim().toLowerCase(), d = [];
42
- for (s++; s < e.length && !e[s].trim().startsWith("```"); ) d.push(e[s++]);
43
- const x = d.join(`
44
- `), b = o === "chart" ? F(x) : null;
45
- r.push(b ? { kind: "chart", spec: b } : { kind: "code", text: x });
37
+ for (let i = 0; i < t.length; i++) {
38
+ const o = t[i].trim();
39
+ if (o.startsWith("```")) {
40
+ u();
41
+ const p = o.slice(3).trim().toLowerCase(), m = [];
42
+ for (i++; i < t.length && !t[i].trim().startsWith("```"); ) m.push(t[i++]);
43
+ const v = m.join(`
44
+ `), N = s && p === "chart" ? U(v) : null;
45
+ r.push(N ? { kind: "chart", spec: N } : { kind: "code", text: v });
46
46
  continue;
47
47
  }
48
- if (a === "") {
49
- n();
48
+ if (o === "") {
49
+ u();
50
50
  continue;
51
51
  }
52
- const u = /^(#{1,4})\s+(.*)$/.exec(a);
53
- if (u) {
54
- n(), r.push({ kind: "h", level: u[1].length, text: u[2] });
52
+ const c = /^(#{1,4})\s+(.*)$/.exec(o);
53
+ if (c) {
54
+ u(), r.push({ kind: "h", level: c[1].length, text: c[2] });
55
55
  continue;
56
56
  }
57
- if (a.startsWith("|") && s + 1 < e.length && N.test(e[s + 1].trim())) {
58
- n();
59
- const o = v(a), d = [];
60
- for (s += 2; s < e.length && e[s].trim().startsWith("|"); )
61
- N.test(e[s].trim()) || d.push(v(e[s])), s++;
62
- s--, r.push({ kind: "table", header: o, rows: d });
57
+ if (o.startsWith("|") && i + 1 < t.length && y.test(t[i + 1].trim())) {
58
+ u();
59
+ const p = A(o), m = [];
60
+ for (i += 2; i < t.length && t[i].trim().startsWith("|"); )
61
+ y.test(t[i].trim()) || m.push(A(t[i])), i++;
62
+ i--, r.push({ kind: "table", header: p, rows: m });
63
63
  continue;
64
64
  }
65
- const h = /^[-*•]\s+(.*)$/.exec(a);
66
- if (h) {
67
- n();
68
- const o = [h[1]];
69
- for (; s + 1 < e.length; ) {
70
- const d = /^[-*•]\s+(.*)$/.exec(e[s + 1].trim());
71
- if (!d) break;
72
- o.push(d[1]), s++;
65
+ const d = /^[-*•]\s+(.*)$/.exec(o);
66
+ if (d) {
67
+ u();
68
+ const p = [d[1]];
69
+ for (; i + 1 < t.length; ) {
70
+ const m = /^[-*•]\s+(.*)$/.exec(t[i + 1].trim());
71
+ if (!m) break;
72
+ p.push(m[1]), i++;
73
73
  }
74
- r.push({ kind: "ul", items: o });
74
+ r.push({ kind: "ul", items: p });
75
75
  continue;
76
76
  }
77
- const c = /^\d+[.)]\s+(.*)$/.exec(a);
78
- if (c) {
79
- n();
80
- const o = [c[1]];
81
- for (; s + 1 < e.length; ) {
82
- const d = /^\d+[.)]\s+(.*)$/.exec(e[s + 1].trim());
83
- if (!d) break;
84
- o.push(d[1]), s++;
77
+ const x = /^\d+[.)]\s+(.*)$/.exec(o);
78
+ if (x) {
79
+ u();
80
+ const p = [x[1]];
81
+ for (; i + 1 < t.length; ) {
82
+ const m = /^\d+[.)]\s+(.*)$/.exec(t[i + 1].trim());
83
+ if (!m) break;
84
+ p.push(m[1]), i++;
85
85
  }
86
- r.push({ kind: "ol", items: o });
86
+ r.push({ kind: "ol", items: p });
87
87
  continue;
88
88
  }
89
- i.push(a);
89
+ l.push(o);
90
90
  }
91
- return n(), r;
91
+ return u(), r;
92
92
  }
93
- const D = /(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*|\[[^\]]+\]\([^)]+\))/g;
94
- function p(t, e = !1, r) {
95
- const i = [];
96
- let n = 0, s = 0;
97
- const m = (u) => e ? /* @__PURE__ */ l(_, { text: u, plain: !0 }, s++) : u, a = (u) => {
98
- if (!(r != null && r.terms.length)) return m(u);
99
- const h = T(u, r.terms, { once: r.once });
100
- return h.length === 1 && !h[0].term ? m(u) : h.map(
93
+ const J = /(\*\*[^*]+\*\*|`[^`]+`|\*[^*]+\*|\[[^\]]+\]\([^)]+\))/g;
94
+ function f(e, n = !1, s) {
95
+ const t = [];
96
+ let r = 0, l = 0;
97
+ const u = (h) => n ? /* @__PURE__ */ a(E, { text: h, plain: !0 }, l++) : h, i = (h) => {
98
+ if (!(s != null && s.terms.length)) return u(h);
99
+ const o = j(h, s.terms, { once: s.once });
100
+ return o.length === 1 && !o[0].term ? u(h) : o.map(
101
101
  (c) => {
102
- var o;
103
- return c.term ? /* @__PURE__ */ l(R, { term: c.term, href: (o = r.href) == null ? void 0 : o.call(r, c.term), children: c.text }, s++) : m(c.text);
102
+ var d;
103
+ return c.term ? /* @__PURE__ */ a(D, { term: c.term, href: (d = s.href) == null ? void 0 : d.call(s, c.term), children: c.text }, l++) : u(c.text);
104
104
  }
105
105
  );
106
106
  };
107
- for (const u of t.matchAll(D)) {
108
- const h = u.index ?? 0;
109
- h > n && i.push(a(t.slice(n, h)));
110
- const c = u[0];
111
- if (c.startsWith("**")) i.push(/* @__PURE__ */ l("strong", { children: a(c.slice(2, -2)) }, s++));
107
+ for (const h of e.matchAll(J)) {
108
+ const o = h.index ?? 0;
109
+ o > r && t.push(i(e.slice(r, o)));
110
+ const c = h[0];
111
+ if (c.startsWith("**")) t.push(/* @__PURE__ */ a("strong", { children: i(c.slice(2, -2)) }, l++));
112
112
  else if (c.startsWith("`"))
113
- i.push(
114
- /* @__PURE__ */ l(
113
+ t.push(
114
+ /* @__PURE__ */ a(
115
115
  "code",
116
116
  {
117
117
  className: "rounded bg-black/[0.06] px-1 py-px font-mono text-[0.92em] dark:bg-white/10",
118
118
  children: c.slice(1, -1)
119
119
  },
120
- s++
120
+ l++
121
121
  )
122
122
  );
123
123
  else if (c.startsWith("[")) {
124
- const o = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(c);
125
- o && z(o[2]) ? i.push(/* @__PURE__ */ l(q, { href: o[2], label: o[1] }, s++)) : o && y(o[2]) ? i.push(/* @__PURE__ */ l(U, { href: o[2], label: o[1] }, s++)) : i.push(c);
126
- } else i.push(/* @__PURE__ */ l("em", { children: c.slice(1, -1) }, s++));
127
- n = h + c.length;
124
+ const d = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(c);
125
+ d && Q(d[2]) ? t.push(/* @__PURE__ */ a(Y, { href: d[2], label: d[1] }, l++)) : d && W(d[2]) ? t.push(/* @__PURE__ */ a(q, { href: d[2], label: d[1] }, l++)) : t.push(c);
126
+ } else t.push(/* @__PURE__ */ a("em", { children: c.slice(1, -1) }, l++));
127
+ r = o + c.length;
128
128
  }
129
- return n < t.length && i.push(a(t.slice(n))), i;
129
+ return r < e.length && t.push(i(e.slice(r))), t;
130
130
  }
131
- function y(t) {
132
- if (!/^https?:\/\/\S+$/i.test(t)) return null;
131
+ function W(e) {
132
+ if (!/^https?:\/\/\S+$/i.test(e)) return null;
133
133
  try {
134
- const e = new URL(t);
135
- return e.username || e.password ? null : e.hostname || null;
134
+ const n = new URL(e);
135
+ return n.username || n.password ? null : n.hostname || null;
136
136
  } catch {
137
137
  return null;
138
138
  }
139
139
  }
140
- function U({ href: t, label: e }) {
141
- const r = y(t) ?? "", i = e.trim() === t || e.trim() === r;
142
- return /* @__PURE__ */ f(
140
+ function q({ href: e, label: n }) {
141
+ const s = W(e) ?? "", t = n.trim() === e || n.trim() === s;
142
+ return /* @__PURE__ */ k(
143
143
  "a",
144
144
  {
145
- href: t,
145
+ href: e,
146
146
  "data-ai-link": "external",
147
147
  className: "underline underline-offset-2",
148
148
  target: "_blank",
149
149
  rel: "noopener noreferrer nofollow",
150
- "data-tip": t,
150
+ "data-tip": e,
151
151
  children: [
152
- i ? r : e,
153
- !i && /* @__PURE__ */ f("span", { className: "ml-1 whitespace-nowrap text-[0.85em] opacity-70", children: [
152
+ t ? s : n,
153
+ !t && /* @__PURE__ */ k("span", { className: "ml-1 whitespace-nowrap text-[0.85em] opacity-70", children: [
154
154
  "(",
155
- r,
155
+ s,
156
156
  " ↗)"
157
157
  ] })
158
158
  ]
159
159
  }
160
160
  );
161
161
  }
162
- function z(t) {
163
- if (!/^\/(?![\\/])/.test(t)) return !1;
164
- for (let e = 0; e < t.length; e++) {
165
- const r = t.charCodeAt(e);
166
- if (r <= 32 || r === 127 || r === 92) return !1;
162
+ function Q(e) {
163
+ if (!/^\/(?![\\/])/.test(e)) return !1;
164
+ for (let n = 0; n < e.length; n++) {
165
+ const s = e.charCodeAt(n);
166
+ if (s <= 32 || s === 127 || s === 92) return !1;
167
167
  }
168
168
  return !0;
169
169
  }
170
- function J(t, e) {
171
- return e && e !== "/help-videos" && /^\/help-videos(?=[?#/]|$)/.test(t) ? `${e}${t.slice(12)}` : t;
170
+ function V(e, n) {
171
+ return n && n !== "/help-videos" && /^\/help-videos(?=[?#/]|$)/.test(e) ? `${n}${e.slice(12)}` : e;
172
+ }
173
+ const L = $(!1);
174
+ function X(e) {
175
+ return e.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (n, s, t) => `[${s.replace(/[[\]]/g, "").trim() || "image"}](${t})`);
172
176
  }
173
- function q({ href: t, label: e }) {
174
- const r = B(), i = J(t, r.helpVideosPath);
175
- return /* @__PURE__ */ l(
177
+ function Y({ href: e, label: n }) {
178
+ const s = S(L), t = P();
179
+ if (s) return /* @__PURE__ */ a("span", { "data-ai-link": "plain", children: n });
180
+ const r = V(e, t.helpVideosPath);
181
+ return /* @__PURE__ */ a(
176
182
  "a",
177
183
  {
178
- href: i,
184
+ href: r,
179
185
  "data-ai-link": "in-app",
180
186
  className: "underline underline-offset-2",
181
- onClick: (n) => {
182
- n.defaultPrevented || n.button !== 0 || n.metaKey || n.ctrlKey || n.shiftKey || n.altKey || (n.preventDefault(), r.navigate(i));
187
+ onClick: (l) => {
188
+ l.defaultPrevented || l.button !== 0 || l.metaKey || l.ctrlKey || l.shiftKey || l.altKey || (l.preventDefault(), t.navigate(r));
183
189
  },
184
- children: e
190
+ children: n
185
191
  }
186
192
  );
187
193
  }
188
- function Q({
189
- header: t,
190
- rows: e,
191
- autolink: r
194
+ function Z({
195
+ header: e,
196
+ rows: n,
197
+ autolink: s
192
198
  }) {
193
- const i = t.length;
194
- return /* @__PURE__ */ f("div", { "data-ai-table": !0, className: "my-1.5", children: [
195
- /* @__PURE__ */ l("ul", { className: "flex flex-col gap-1.5 sm:hidden", children: e.map((n, s) => (
199
+ const t = e.length;
200
+ return /* @__PURE__ */ k("div", { "data-ai-table": !0, className: "my-1.5", children: [
201
+ /* @__PURE__ */ a("ul", { className: "flex flex-col gap-1.5 sm:hidden", children: n.map((r, l) => (
196
202
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
197
- /* @__PURE__ */ f(
203
+ /* @__PURE__ */ k(
198
204
  "li",
199
205
  {
200
206
  className: "rounded-lg border border-black/10 bg-background/60 px-2.5 py-2 dark:border-white/10",
201
207
  children: [
202
- /* @__PURE__ */ l("div", { className: "font-semibold leading-snug", children: p(n[0] ?? "", r) }),
203
- n.slice(1, i).map(
204
- (m, a) => m ? (
208
+ /* @__PURE__ */ a("div", { className: "font-semibold leading-snug", children: f(r[0] ?? "", s) }),
209
+ r.slice(1, t).map(
210
+ (u, i) => u ? (
205
211
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
206
- /* @__PURE__ */ f(
212
+ /* @__PURE__ */ k(
207
213
  "div",
208
214
  {
209
215
  className: "mt-1 grid grid-cols-[minmax(0,34%)_1fr] gap-2 text-[0.94em] leading-snug",
210
216
  children: [
211
- /* @__PURE__ */ l("span", { className: "text-muted-foreground", children: t[a + 1] }),
212
- /* @__PURE__ */ l("span", { className: "min-w-0 break-words", children: p(m, r) })
217
+ /* @__PURE__ */ a("span", { className: "text-muted-foreground", children: e[i + 1] }),
218
+ /* @__PURE__ */ a("span", { className: "min-w-0 break-words", children: f(u, s) })
213
219
  ]
214
220
  },
215
- a
221
+ i
216
222
  )
217
223
  ) : null
218
224
  )
219
225
  ]
220
226
  },
221
- s
227
+ l
222
228
  )
223
229
  )) }),
224
- /* @__PURE__ */ l("div", { className: "hidden overflow-x-auto sm:block", children: /* @__PURE__ */ f("table", { className: "w-auto min-w-[50%] text-left", children: [
225
- /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { className: "border-b border-black/10 text-[0.85em] uppercase tracking-wide text-muted-foreground dark:border-white/10", children: t.map((n, s) => (
230
+ /* @__PURE__ */ a("div", { className: "hidden overflow-x-auto sm:block", children: /* @__PURE__ */ k("table", { className: "w-auto min-w-[50%] text-left", children: [
231
+ /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { className: "border-b border-black/10 text-[0.85em] uppercase tracking-wide text-muted-foreground dark:border-white/10", children: e.map((r, l) => (
226
232
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
227
- /* @__PURE__ */ l("th", { className: "py-1 pr-4 font-medium", children: p(n) }, s)
233
+ /* @__PURE__ */ a("th", { className: "py-1 pr-4 font-medium", children: f(r) }, l)
228
234
  )) }) }),
229
- /* @__PURE__ */ l("tbody", { className: "divide-y divide-black/5 dark:divide-white/10", children: e.map((n, s) => (
235
+ /* @__PURE__ */ a("tbody", { className: "divide-y divide-black/5 dark:divide-white/10", children: n.map((r, l) => (
230
236
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
231
- /* @__PURE__ */ l("tr", { className: "align-top", children: t.map((m, a) => (
237
+ /* @__PURE__ */ a("tr", { className: "align-top", children: e.map((u, i) => (
232
238
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
233
- /* @__PURE__ */ l("td", { className: "max-w-[28rem] py-1 pr-4", children: p(n[a] ?? "", r) }, a)
234
- )) }, s)
239
+ /* @__PURE__ */ a("td", { className: "max-w-[28rem] py-1 pr-4", children: f(r[i] ?? "", s) }, i)
240
+ )) }, l)
235
241
  )) })
236
242
  ] }) })
237
243
  ] });
238
244
  }
239
- const V = L(() => import("./AiChart.js").then((t) => ({ default: t.AiChart })));
240
- function X({ spec: t }) {
241
- const e = $(A);
242
- return /* @__PURE__ */ l(
243
- W,
245
+ const ee = B(() => import("./AiChart.js").then((e) => ({ default: e.AiChart })));
246
+ function te({ spec: e }) {
247
+ const n = S(M);
248
+ return /* @__PURE__ */ a(
249
+ _,
244
250
  {
245
- fallback: /* @__PURE__ */ l(
251
+ fallback: /* @__PURE__ */ a(
246
252
  "div",
247
253
  {
248
254
  "data-ai-chart-loading": !0,
249
255
  className: "my-2 w-full",
250
- style: { height: t.type === "pie" ? 220 : 200 }
256
+ style: { height: e.type === "pie" ? 220 : 200 }
251
257
  }
252
258
  ),
253
- children: /* @__PURE__ */ l(V, { spec: t, onPoint: e })
259
+ children: /* @__PURE__ */ a(ee, { spec: e, onPoint: n })
254
260
  }
255
261
  );
256
262
  }
257
- function g({ b: t, link: e, gl: r }) {
258
- switch (t.kind) {
263
+ function w({ b: e, link: n, gl: s }) {
264
+ switch (e.kind) {
259
265
  case "h":
260
- return /* @__PURE__ */ l("p", { className: w("font-semibold", t.level <= 2 ? "text-[1.05em]" : ""), children: p(t.text, e, r) });
266
+ return /* @__PURE__ */ a("p", { className: b("font-semibold", e.level <= 2 ? "text-[1.05em]" : ""), children: f(e.text, n, s) });
261
267
  case "ul":
262
- return /* @__PURE__ */ l("ul", { className: "list-disc space-y-0.5 pl-5", children: t.items.map((i, n) => (
268
+ return /* @__PURE__ */ a("ul", { className: "list-disc space-y-0.5 pl-5", children: e.items.map((t, r) => (
263
269
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
264
- /* @__PURE__ */ l("li", { children: p(i, e, r) }, n)
270
+ /* @__PURE__ */ a("li", { children: f(t, n, s) }, r)
265
271
  )) });
266
272
  case "ol":
267
- return /* @__PURE__ */ l("ol", { className: "list-decimal space-y-0.5 pl-5", children: t.items.map((i, n) => (
273
+ return /* @__PURE__ */ a("ol", { className: "list-decimal space-y-0.5 pl-5", children: e.items.map((t, r) => (
268
274
  // biome-ignore lint/suspicious/noArrayIndexKey: static content
269
- /* @__PURE__ */ l("li", { children: p(i, e, r) }, n)
275
+ /* @__PURE__ */ a("li", { children: f(t, n, s) }, r)
270
276
  )) });
271
277
  case "code":
272
- return /* @__PURE__ */ l("pre", { className: "overflow-x-auto rounded-md bg-black/[0.05] p-2 font-mono text-[0.9em] dark:bg-white/10", children: t.text });
278
+ return /* @__PURE__ */ a("pre", { className: "overflow-x-auto rounded-md bg-black/[0.05] p-2 font-mono text-[0.9em] dark:bg-white/10", children: e.text });
273
279
  case "table":
274
- return /* @__PURE__ */ l(Q, { header: t.header, rows: t.rows, autolink: e });
280
+ return /* @__PURE__ */ a(Z, { header: e.header, rows: e.rows, autolink: n });
275
281
  case "chart":
276
- return /* @__PURE__ */ l(X, { spec: t.spec });
282
+ return /* @__PURE__ */ a(te, { spec: e.spec });
277
283
  default:
278
- return /* @__PURE__ */ l("p", { children: p(t.text, e, r) });
284
+ return /* @__PURE__ */ a("p", { children: f(e.text, n, s) });
279
285
  }
280
286
  }
281
- const Y = { table: "Table", chart: "Chart", list: "List" };
282
- function Z({ b: t, link: e, gl: r }) {
283
- const i = k(() => j(t), [t]), [n, s] = S(i[0]), m = k(() => {
284
- if (n === i[0]) return t;
285
- const a = M(t);
286
- if (!a) return t;
287
- if (n === "table") return { kind: "table", header: a.header, rows: a.rows };
288
- if (n === "list") return { kind: "ul", items: P(a) };
289
- const u = E(a);
290
- return u ? { kind: "chart", spec: u } : t;
291
- }, [t, n, i]);
292
- return i.length < 2 ? /* @__PURE__ */ l(g, { b: t, link: e, gl: r }) : /* @__PURE__ */ f("div", { "data-ai-switchable": n, children: [
293
- /* @__PURE__ */ l("fieldset", { className: "mb-0.5 flex min-w-0 justify-end gap-0.5", "aria-label": "Show as", children: i.map((a) => /* @__PURE__ */ l(
287
+ const ne = { table: "Table", chart: "Chart", list: "List" };
288
+ function re({ b: e, link: n, gl: s }) {
289
+ const t = g(() => K(e), [e]), [r, l] = O(t[0]), u = g(() => {
290
+ if (r === t[0]) return e;
291
+ const i = R(e);
292
+ if (!i) return e;
293
+ if (r === "table") return { kind: "table", header: i.header, rows: i.rows };
294
+ if (r === "list") return { kind: "ul", items: F(i) };
295
+ const h = H(i);
296
+ return h ? { kind: "chart", spec: h } : e;
297
+ }, [e, r, t]);
298
+ return t.length < 2 ? /* @__PURE__ */ a(w, { b: e, link: n, gl: s }) : /* @__PURE__ */ k("div", { "data-ai-switchable": r, children: [
299
+ /* @__PURE__ */ a("fieldset", { className: "mb-0.5 flex min-w-0 justify-end gap-0.5", "aria-label": "Show as", children: t.map((i) => /* @__PURE__ */ a(
294
300
  "button",
295
301
  {
296
302
  type: "button",
297
- onClick: () => s(a),
298
- "aria-pressed": a === n,
299
- "data-ai-format": a,
300
- className: w(
303
+ onClick: () => l(i),
304
+ "aria-pressed": i === r,
305
+ "data-ai-format": i,
306
+ className: b(
301
307
  "rounded px-1.5 py-px text-[10.5px] font-medium transition-colors",
302
- a === n ? "bg-accent text-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground"
308
+ i === r ? "bg-accent text-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground"
303
309
  ),
304
- children: Y[a]
310
+ children: ne[i]
305
311
  },
306
- a
312
+ i
307
313
  )) }),
308
- /* @__PURE__ */ l(g, { b: m, link: e, gl: r })
314
+ /* @__PURE__ */ a(w, { b: u, link: n, gl: s })
309
315
  ] });
310
316
  }
311
- const A = C(void 0);
312
- function ce({
313
- content: t,
314
- className: e,
315
- autolink: r,
316
- switchable: i,
317
- onChartPoint: n
317
+ const M = $(void 0);
318
+ function me({
319
+ content: e,
320
+ className: n,
321
+ autolink: s,
322
+ switchable: t,
323
+ onChartPoint: r,
324
+ mirrored: l
318
325
  }) {
319
- const s = k(() => G(t), [t]), m = O(), a = r ?? m != null, u = I(), h = K(), c = u.length ? { terms: u, once: /* @__PURE__ */ new Set(), href: h } : void 0;
320
- return /* @__PURE__ */ l(A.Provider, { value: n, children: /* @__PURE__ */ l("div", { "data-ai-markdown": !0, className: w("space-y-1.5 [&_strong]:font-semibold", e), children: s.map((o, d) => {
321
- const x = `${o.kind}-${d}`;
322
- return i && ee.has(o.kind) ? /* @__PURE__ */ l(Z, { b: o, link: a, gl: c }, x) : /* @__PURE__ */ l(g, { b: o, link: a, gl: c }, x);
323
- }) }) });
326
+ const u = g(
327
+ () => l ? C(X(e), { charts: !1 }) : C(e),
328
+ [e, l]
329
+ ), i = I(), h = l ? !1 : s ?? i != null, o = T(), c = G(), d = o.length ? { terms: o, once: /* @__PURE__ */ new Set(), href: c } : void 0;
330
+ return /* @__PURE__ */ a(L.Provider, { value: !!l, children: /* @__PURE__ */ a(M.Provider, { value: r, children: /* @__PURE__ */ a(
331
+ "div",
332
+ {
333
+ "data-ai-markdown": !0,
334
+ "data-ai-mirrored": l ? "" : void 0,
335
+ className: b("space-y-1.5 [&_strong]:font-semibold", n),
336
+ children: u.map((x, p) => {
337
+ const m = `${x.kind}-${p}`;
338
+ return t && !l && ie.has(x.kind) ? /* @__PURE__ */ a(re, { b: x, link: h, gl: d }, m) : /* @__PURE__ */ a(w, { b: x, link: h, gl: d }, m);
339
+ })
340
+ }
341
+ ) }) });
324
342
  }
325
- const ee = /* @__PURE__ */ new Set(["table", "chart", "ul", "ol"]);
343
+ const ie = /* @__PURE__ */ new Set(["table", "chart", "ul", "ol"]);
326
344
  export {
327
- ce as AiMarkdown,
328
- y as externalHost,
329
- J as inAppHref,
330
- z as isSafeAppPath,
331
- G as parseAiMarkdown,
332
- F as parseChartSpec,
333
- p as renderInline
345
+ me as AiMarkdown,
346
+ W as externalHost,
347
+ V as inAppHref,
348
+ Q as isSafeAppPath,
349
+ X as mirroredMarkdown,
350
+ C as parseAiMarkdown,
351
+ U as parseChartSpec,
352
+ f as renderInline
334
353
  };