@codrstudio/openclaude-chat 0.1.0

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.
Files changed (171) hide show
  1. package/dist/components/Chat.d.ts +23 -0
  2. package/dist/components/Chat.js +12 -0
  3. package/dist/components/ErrorNote.d.ts +6 -0
  4. package/dist/components/ErrorNote.js +6 -0
  5. package/dist/components/LazyRender.d.ts +8 -0
  6. package/dist/components/LazyRender.js +22 -0
  7. package/dist/components/Markdown.d.ts +5 -0
  8. package/dist/components/Markdown.js +65 -0
  9. package/dist/components/MessageBubble.d.ts +9 -0
  10. package/dist/components/MessageBubble.js +45 -0
  11. package/dist/components/MessageInput.d.ts +19 -0
  12. package/dist/components/MessageInput.js +214 -0
  13. package/dist/components/MessageList.d.ts +13 -0
  14. package/dist/components/MessageList.js +72 -0
  15. package/dist/components/StreamingIndicator.d.ts +1 -0
  16. package/dist/components/StreamingIndicator.js +9 -0
  17. package/dist/display/AlertRenderer.d.ts +2 -0
  18. package/dist/display/AlertRenderer.js +13 -0
  19. package/dist/display/CarouselRenderer.d.ts +2 -0
  20. package/dist/display/CarouselRenderer.js +41 -0
  21. package/dist/display/ChartRenderer.d.ts +2 -0
  22. package/dist/display/ChartRenderer.js +76 -0
  23. package/dist/display/ChoiceButtonsRenderer.d.ts +6 -0
  24. package/dist/display/ChoiceButtonsRenderer.js +23 -0
  25. package/dist/display/CodeBlockRenderer.d.ts +2 -0
  26. package/dist/display/CodeBlockRenderer.js +17 -0
  27. package/dist/display/ComparisonTableRenderer.d.ts +2 -0
  28. package/dist/display/ComparisonTableRenderer.js +26 -0
  29. package/dist/display/DataTableRenderer.d.ts +2 -0
  30. package/dist/display/DataTableRenderer.js +74 -0
  31. package/dist/display/DisplayReactRenderer.d.ts +26 -0
  32. package/dist/display/DisplayReactRenderer.js +192 -0
  33. package/dist/display/FileCardRenderer.d.ts +2 -0
  34. package/dist/display/FileCardRenderer.js +31 -0
  35. package/dist/display/GalleryRenderer.d.ts +2 -0
  36. package/dist/display/GalleryRenderer.js +11 -0
  37. package/dist/display/ImageViewerRenderer.d.ts +2 -0
  38. package/dist/display/ImageViewerRenderer.js +15 -0
  39. package/dist/display/LinkPreviewRenderer.d.ts +2 -0
  40. package/dist/display/LinkPreviewRenderer.js +20 -0
  41. package/dist/display/MapViewRenderer.d.ts +2 -0
  42. package/dist/display/MapViewRenderer.js +20 -0
  43. package/dist/display/MetricCardRenderer.d.ts +2 -0
  44. package/dist/display/MetricCardRenderer.js +12 -0
  45. package/dist/display/PriceHighlightRenderer.d.ts +2 -0
  46. package/dist/display/PriceHighlightRenderer.js +30 -0
  47. package/dist/display/ProductCardRenderer.d.ts +2 -0
  48. package/dist/display/ProductCardRenderer.js +23 -0
  49. package/dist/display/ProgressStepsRenderer.d.ts +2 -0
  50. package/dist/display/ProgressStepsRenderer.js +14 -0
  51. package/dist/display/SourcesListRenderer.d.ts +2 -0
  52. package/dist/display/SourcesListRenderer.js +5 -0
  53. package/dist/display/SpreadsheetRenderer.d.ts +2 -0
  54. package/dist/display/SpreadsheetRenderer.js +32 -0
  55. package/dist/display/StepTimelineRenderer.d.ts +2 -0
  56. package/dist/display/StepTimelineRenderer.js +21 -0
  57. package/dist/display/index.d.ts +21 -0
  58. package/dist/display/index.js +20 -0
  59. package/dist/display/react-sandbox/bootstrap.d.ts +1 -0
  60. package/dist/display/react-sandbox/bootstrap.js +154 -0
  61. package/dist/display/registry.d.ts +5 -0
  62. package/dist/display/registry.js +52 -0
  63. package/dist/display/sdk-types.d.ts +187 -0
  64. package/dist/display/sdk-types.js +4 -0
  65. package/dist/hooks/ChatProvider.d.ts +9 -0
  66. package/dist/hooks/ChatProvider.js +14 -0
  67. package/dist/hooks/useIsMobile.d.ts +1 -0
  68. package/dist/hooks/useIsMobile.js +12 -0
  69. package/dist/hooks/useOpenClaudeChat.d.ts +36 -0
  70. package/dist/hooks/useOpenClaudeChat.js +361 -0
  71. package/dist/index.d.ts +47 -0
  72. package/dist/index.js +42 -0
  73. package/dist/lib/utils.d.ts +2 -0
  74. package/dist/lib/utils.js +5 -0
  75. package/dist/parts/PartErrorBoundary.d.ts +21 -0
  76. package/dist/parts/PartErrorBoundary.js +27 -0
  77. package/dist/parts/PartRenderer.d.ts +8 -0
  78. package/dist/parts/PartRenderer.js +99 -0
  79. package/dist/parts/ReasoningBlock.d.ts +6 -0
  80. package/dist/parts/ReasoningBlock.js +18 -0
  81. package/dist/parts/ToolActivity.d.ts +11 -0
  82. package/dist/parts/ToolActivity.js +52 -0
  83. package/dist/parts/ToolResult.d.ts +7 -0
  84. package/dist/parts/ToolResult.js +38 -0
  85. package/dist/styles.css +2 -0
  86. package/dist/types.d.ts +40 -0
  87. package/dist/types.js +4 -0
  88. package/dist/ui/alert.d.ts +12 -0
  89. package/dist/ui/alert.js +28 -0
  90. package/dist/ui/badge.d.ts +9 -0
  91. package/dist/ui/badge.js +20 -0
  92. package/dist/ui/button.d.ts +11 -0
  93. package/dist/ui/button.js +31 -0
  94. package/dist/ui/card.d.ts +8 -0
  95. package/dist/ui/card.js +21 -0
  96. package/dist/ui/collapsible.d.ts +1 -0
  97. package/dist/ui/collapsible.js +2 -0
  98. package/dist/ui/dialog.d.ts +19 -0
  99. package/dist/ui/dialog.js +23 -0
  100. package/dist/ui/dropdown-menu.d.ts +11 -0
  101. package/dist/ui/dropdown-menu.js +15 -0
  102. package/dist/ui/input.d.ts +3 -0
  103. package/dist/ui/input.js +6 -0
  104. package/dist/ui/progress.d.ts +7 -0
  105. package/dist/ui/progress.js +9 -0
  106. package/dist/ui/scroll-area.d.ts +5 -0
  107. package/dist/ui/scroll-area.js +12 -0
  108. package/dist/ui/separator.d.ts +4 -0
  109. package/dist/ui/separator.js +8 -0
  110. package/dist/ui/skeleton.d.ts +3 -0
  111. package/dist/ui/skeleton.js +6 -0
  112. package/dist/ui/table.d.ts +10 -0
  113. package/dist/ui/table.js +27 -0
  114. package/package.json +61 -0
  115. package/src/components/Chat.tsx +107 -0
  116. package/src/components/ErrorNote.tsx +35 -0
  117. package/src/components/LazyRender.tsx +42 -0
  118. package/src/components/Markdown.tsx +114 -0
  119. package/src/components/MessageBubble.tsx +107 -0
  120. package/src/components/MessageInput.tsx +421 -0
  121. package/src/components/MessageList.tsx +153 -0
  122. package/src/components/StreamingIndicator.tsx +19 -0
  123. package/src/display/AlertRenderer.tsx +23 -0
  124. package/src/display/CarouselRenderer.tsx +141 -0
  125. package/src/display/ChartRenderer.tsx +195 -0
  126. package/src/display/ChoiceButtonsRenderer.tsx +114 -0
  127. package/src/display/CodeBlockRenderer.tsx +49 -0
  128. package/src/display/ComparisonTableRenderer.tsx +132 -0
  129. package/src/display/DataTableRenderer.tsx +144 -0
  130. package/src/display/DisplayReactRenderer.tsx +269 -0
  131. package/src/display/FileCardRenderer.tsx +55 -0
  132. package/src/display/GalleryRenderer.tsx +65 -0
  133. package/src/display/ImageViewerRenderer.tsx +114 -0
  134. package/src/display/LinkPreviewRenderer.tsx +74 -0
  135. package/src/display/MapViewRenderer.tsx +75 -0
  136. package/src/display/MetricCardRenderer.tsx +29 -0
  137. package/src/display/PriceHighlightRenderer.tsx +62 -0
  138. package/src/display/ProductCardRenderer.tsx +112 -0
  139. package/src/display/ProgressStepsRenderer.tsx +59 -0
  140. package/src/display/SourcesListRenderer.tsx +47 -0
  141. package/src/display/SpreadsheetRenderer.tsx +86 -0
  142. package/src/display/StepTimelineRenderer.tsx +75 -0
  143. package/src/display/index.ts +21 -0
  144. package/src/display/react-sandbox/bootstrap.ts +155 -0
  145. package/src/display/registry.ts +84 -0
  146. package/src/display/sdk-types.ts +217 -0
  147. package/src/hooks/ChatProvider.tsx +21 -0
  148. package/src/hooks/useIsMobile.ts +15 -0
  149. package/src/hooks/useOpenClaudeChat.ts +476 -0
  150. package/src/index.ts +76 -0
  151. package/src/lib/utils.ts +6 -0
  152. package/src/parts/PartErrorBoundary.tsx +51 -0
  153. package/src/parts/PartRenderer.tsx +145 -0
  154. package/src/parts/ReasoningBlock.tsx +41 -0
  155. package/src/parts/ToolActivity.tsx +78 -0
  156. package/src/parts/ToolResult.tsx +79 -0
  157. package/src/styles.css +2 -0
  158. package/src/types.ts +41 -0
  159. package/src/ui/alert.tsx +77 -0
  160. package/src/ui/badge.tsx +36 -0
  161. package/src/ui/button.tsx +54 -0
  162. package/src/ui/card.tsx +68 -0
  163. package/src/ui/collapsible.tsx +7 -0
  164. package/src/ui/dialog.tsx +122 -0
  165. package/src/ui/dropdown-menu.tsx +76 -0
  166. package/src/ui/input.tsx +24 -0
  167. package/src/ui/progress.tsx +36 -0
  168. package/src/ui/scroll-area.tsx +48 -0
  169. package/src/ui/separator.tsx +31 -0
  170. package/src/ui/skeleton.tsx +9 -0
  171. package/src/ui/table.tsx +114 -0
@@ -0,0 +1,2 @@
1
+ import type { DisplayChart } from "./sdk-types.js";
2
+ export declare function ChartRenderer({ type, title, data, format }: DisplayChart): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AreaChart, Area, BarChart, Bar, LineChart, Line, PieChart, Pie, Cell, CartesianGrid, Tooltip, ResponsiveContainer, XAxis, YAxis, } from "recharts";
3
+ import { Card } from "../ui/card";
4
+ const CHART_COLORS = [
5
+ "var(--chart-1)",
6
+ "var(--chart-2)",
7
+ "var(--chart-3)",
8
+ "var(--chart-4)",
9
+ "var(--chart-5)",
10
+ ];
11
+ const AXIS_PROPS = {
12
+ stroke: "var(--border)",
13
+ tick: { fill: "var(--muted-foreground)", fontSize: 12 },
14
+ };
15
+ const TOOLTIP_STYLE = {
16
+ contentStyle: {
17
+ background: "var(--card)",
18
+ border: "1px solid var(--border)",
19
+ color: "var(--card-foreground)",
20
+ borderRadius: "0.375rem",
21
+ fontSize: "0.75rem",
22
+ },
23
+ };
24
+ function formatValue(value, format) {
25
+ if (!format)
26
+ return String(value);
27
+ const locale = format.locale ?? "pt-BR";
28
+ const prefix = format.prefix ?? "";
29
+ const suffix = format.suffix ?? "";
30
+ if (prefix.includes("R$") || prefix.includes("$") || prefix.includes("€")) {
31
+ const currencyMap = {
32
+ "R$": "BRL",
33
+ "$": "USD",
34
+ "€": "EUR",
35
+ };
36
+ const currency = Object.keys(currencyMap).find(k => prefix.includes(k));
37
+ if (currency) {
38
+ return new Intl.NumberFormat(locale, { style: "currency", currency: currencyMap[currency] }).format(value);
39
+ }
40
+ }
41
+ if (suffix.includes("%")) {
42
+ return new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 1 }).format(value / 100);
43
+ }
44
+ const formatted = new Intl.NumberFormat(locale).format(value);
45
+ return `${prefix}${formatted}${suffix}`;
46
+ }
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ function makeTooltipFormatter(format) {
49
+ return (value) => [
50
+ typeof value === "number" ? formatValue(value, format) : String(value ?? ""),
51
+ "",
52
+ ];
53
+ }
54
+ export function ChartRenderer({ type, title, data, format }) {
55
+ const chartData = data.map((d) => ({ name: d.label, value: d.value, color: d.color }));
56
+ const tooltipFormatter = makeTooltipFormatter(format);
57
+ const sharedProps = {
58
+ data: chartData,
59
+ margin: { top: 4, right: 8, left: 8, bottom: 4 },
60
+ };
61
+ return (_jsxs(Card, { className: "p-4", children: [title && _jsx("p", { className: "text-sm font-medium text-foreground mb-4", children: title }), _jsx("div", { className: "min-h-[200px]", children: _jsx(ResponsiveContainer, { width: "100%", height: 200, children: renderChart(type, chartData, sharedProps, tooltipFormatter) }) })] }));
62
+ }
63
+ function renderChart(type, data, sharedProps, tooltipFormatter) {
64
+ switch (type) {
65
+ case "bar":
66
+ return (_jsxs(BarChart, { ...sharedProps, children: [_jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: "var(--border)" }), _jsx(XAxis, { dataKey: "name", ...AXIS_PROPS }), _jsx(YAxis, { width: 48, ...AXIS_PROPS }), _jsx(Tooltip, { formatter: tooltipFormatter, ...TOOLTIP_STYLE }), _jsx(Bar, { dataKey: "value", radius: [4, 4, 0, 0], children: data.map((entry, index) => (_jsx(Cell, { fill: entry.color ?? CHART_COLORS[index % CHART_COLORS.length] }, index))) })] }));
67
+ case "line":
68
+ return (_jsxs(LineChart, { ...sharedProps, children: [_jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: "var(--border)" }), _jsx(XAxis, { dataKey: "name", ...AXIS_PROPS }), _jsx(YAxis, { width: 48, ...AXIS_PROPS }), _jsx(Tooltip, { formatter: tooltipFormatter, ...TOOLTIP_STYLE }), _jsx(Line, { type: "monotone", dataKey: "value", stroke: CHART_COLORS[0], strokeWidth: 2, dot: { r: 4, fill: CHART_COLORS[0] } })] }));
69
+ case "area":
70
+ return (_jsxs(AreaChart, { ...sharedProps, children: [_jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: "var(--border)" }), _jsx(XAxis, { dataKey: "name", ...AXIS_PROPS }), _jsx(YAxis, { width: 48, ...AXIS_PROPS }), _jsx(Tooltip, { formatter: tooltipFormatter, ...TOOLTIP_STYLE }), _jsx(Area, { type: "monotone", dataKey: "value", stroke: CHART_COLORS[0], fill: CHART_COLORS[0], fillOpacity: 0.2, strokeWidth: 2 })] }));
71
+ case "pie":
72
+ return (_jsxs(PieChart, { children: [_jsx(Tooltip, { formatter: tooltipFormatter, ...TOOLTIP_STYLE }), _jsx(Pie, { data: data, dataKey: "value", nameKey: "name", cx: "50%", cy: "50%", outerRadius: "70%", label: ({ name }) => name, labelLine: { stroke: "var(--muted-foreground)" }, children: data.map((entry, index) => (_jsx(Cell, { fill: entry.color ?? CHART_COLORS[index % CHART_COLORS.length] }, index))) })] }));
73
+ case "donut":
74
+ return (_jsxs(PieChart, { children: [_jsx(Tooltip, { formatter: tooltipFormatter, ...TOOLTIP_STYLE }), _jsx(Pie, { data: data, dataKey: "value", nameKey: "name", cx: "50%", cy: "50%", innerRadius: "40%", outerRadius: "70%", label: ({ name }) => name, labelLine: { stroke: "var(--muted-foreground)" }, children: data.map((entry, index) => (_jsx(Cell, { fill: entry.color ?? CHART_COLORS[index % CHART_COLORS.length] }, index))) })] }));
75
+ }
76
+ }
@@ -0,0 +1,6 @@
1
+ import type { DisplayChoices } from "./sdk-types.js";
2
+ type ChoiceButtonsProps = DisplayChoices & {
3
+ onChoiceSelect?: (value: string) => void;
4
+ };
5
+ export declare function ChoiceButtonsRenderer({ question, choices, layout, onChoiceSelect, }: ChoiceButtonsProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Button } from "../ui/button.js";
4
+ import { Card } from "../ui/card.js";
5
+ import { cn } from "../lib/utils.js";
6
+ export function ChoiceButtonsRenderer({ question, choices, layout, onChoiceSelect, }) {
7
+ const [selected, setSelected] = useState(null);
8
+ function handleSelect(id) {
9
+ setSelected(id);
10
+ onChoiceSelect?.(id);
11
+ }
12
+ return (_jsxs("div", { className: "space-y-3 w-fit", children: [question && _jsx("p", { className: "text-sm font-medium text-foreground", children: question }), _jsx("div", { className: cn(layout === "buttons" && "flex flex-wrap gap-2", layout === "cards" && "grid grid-cols-1 sm:grid-cols-2 gap-2", layout === "list" && "flex flex-col gap-1"), role: "group", "aria-label": question ?? "Escolha uma opção", children: choices.map((choice) => {
13
+ const isSelected = selected === choice.id;
14
+ if (layout === "buttons") {
15
+ return (_jsxs(Button, { variant: "outline", size: "sm", onClick: () => handleSelect(choice.id), "aria-pressed": isSelected, className: cn(isSelected && "ring-2 ring-ring"), children: [choice.icon && (_jsx("span", { "aria-hidden": "true", children: choice.icon })), choice.label] }, choice.id));
16
+ }
17
+ if (layout === "cards") {
18
+ return (_jsxs(Card, { className: cn("p-3 cursor-pointer hover:bg-muted/50 transition-colors", isSelected && "ring-2 ring-ring"), onClick: () => handleSelect(choice.id), role: "button", "aria-pressed": isSelected, children: [choice.icon && (_jsx("span", { className: "text-base", "aria-hidden": "true", children: choice.icon })), _jsx("span", { className: "block font-medium text-sm text-foreground", children: choice.label }), choice.description && (_jsx("span", { className: "block text-xs text-muted-foreground mt-1", children: choice.description }))] }, choice.id));
19
+ }
20
+ // list
21
+ return (_jsxs("button", { className: cn("flex items-center gap-3 w-full rounded-md px-3 py-2 text-sm text-left hover:bg-muted transition-colors", isSelected && "bg-muted ring-1 ring-ring"), onClick: () => handleSelect(choice.id), "aria-pressed": isSelected, children: [_jsx("span", { className: cn("w-4 h-4 rounded-full border-2 border-input flex-shrink-0", isSelected && "border-primary bg-primary"), "aria-hidden": "true" }), _jsxs("span", { className: "flex items-center gap-2 flex-1 min-w-0", children: [choice.icon && (_jsx("span", { "aria-hidden": "true", children: choice.icon })), _jsx("span", { className: "font-medium text-foreground", children: choice.label }), choice.description && (_jsx("span", { className: "text-xs text-muted-foreground ml-auto", children: choice.description }))] })] }, choice.id));
22
+ }) })] }));
23
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayCode } from "./sdk-types.js";
2
+ export declare function CodeBlockRenderer({ language, code, title, lineNumbers }: DisplayCode): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Check, Copy } from "lucide-react";
3
+ import { useState } from "react";
4
+ import { Button } from "../ui/button.js";
5
+ import { cn } from "../lib/utils.js";
6
+ export function CodeBlockRenderer({ language, code, title, lineNumbers }) {
7
+ const [copied, setCopied] = useState(false);
8
+ async function handleCopy() {
9
+ await navigator.clipboard.writeText(code);
10
+ setCopied(true);
11
+ setTimeout(() => setCopied(false), 2000);
12
+ }
13
+ const displayLines = lineNumbers
14
+ ? code.split("\n").map((line, i) => (_jsxs("span", { className: "flex gap-4", children: [_jsx("span", { className: "select-none text-muted-foreground w-6 text-right shrink-0", children: i + 1 }), _jsx("span", { children: line })] }, i)))
15
+ : code;
16
+ return (_jsxs("div", { className: cn("rounded-md border border-border bg-muted/30 overflow-hidden"), children: [_jsxs("div", { className: "flex items-center justify-between px-3 py-1.5 border-b border-border", children: [_jsx("span", { className: "text-xs text-muted-foreground font-mono", children: title ?? language }), _jsxs(Button, { variant: "ghost", size: "sm", onClick: handleCopy, "aria-label": copied ? "Copiado!" : "Copiar código", className: "h-7 gap-1.5", children: [copied ? _jsx(Check, { className: "h-3 w-3" }) : _jsx(Copy, { className: "h-3 w-3" }), _jsx("span", { className: "text-xs", children: copied ? "Copiado!" : "Copiar" })] })] }), _jsx("pre", { className: "p-4 overflow-x-auto font-mono text-sm", children: lineNumbers ? (_jsx("code", { children: displayLines })) : (_jsx("code", { children: code })) })] }));
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayComparison } from "./sdk-types.js";
2
+ export declare function ComparisonTableRenderer({ title, items, attributes }: DisplayComparison): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { CheckCircle } from "lucide-react";
4
+ import { ScrollArea, ScrollBar } from "../ui/scroll-area.js";
5
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui/table.js";
6
+ import { cn } from "../lib/utils.js";
7
+ function formatMoney(value, currency = "BRL") {
8
+ return new Intl.NumberFormat("pt-BR", { style: "currency", currency }).format(value);
9
+ }
10
+ export function ComparisonTableRenderer({ title, items, attributes }) {
11
+ const [bestIdx, setBestIdx] = useState(null);
12
+ // Auto-detect best value by lowest price if no manual selection
13
+ const lowestPriceIdx = items.reduce((acc, item, i) => {
14
+ if (!item.price)
15
+ return acc;
16
+ if (acc === null)
17
+ return i;
18
+ const best = items[acc]?.price;
19
+ return best && item.price.value < best.value ? i : acc;
20
+ }, null);
21
+ const highlightIdx = bestIdx ?? lowestPriceIdx;
22
+ return (_jsxs("div", { className: "space-y-2", children: [title && _jsx("h3", { className: "text-sm font-semibold text-foreground", children: title }), _jsxs(ScrollArea, { className: "w-full", children: [_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { className: "font-semibold text-center", children: "Atributo" }), items.map((item, i) => (_jsx(TableHead, { className: cn("font-semibold text-center", i === highlightIdx && "bg-muted"), children: _jsxs("button", { className: "flex flex-col items-center gap-0.5 w-full cursor-pointer hover:opacity-80", onClick: () => setBestIdx(i === bestIdx ? null : i), title: "Marcar como melhor", children: [i === highlightIdx && (_jsx(CheckCircle, { className: "h-3.5 w-3.5 text-primary" })), _jsx("span", { className: "font-semibold", children: item.title }), item.price && (_jsx("span", { className: "text-xs text-muted-foreground font-normal", children: formatMoney(item.price.value, item.price.currency) }))] }) }, i)))] }) }), _jsx(TableBody, { children: attributes && attributes.length > 0 ? (attributes.map((attr, ri) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: attr.label }), items.map((item, ci) => {
23
+ const val = item[attr.key];
24
+ return (_jsx(TableCell, { className: cn("text-center", ci === highlightIdx && "bg-muted/50"), children: val === true ? "✓" : val === false ? "✗" : val != null ? String(val) : "—" }, ci));
25
+ })] }, ri)))) : (_jsxs(_Fragment, { children: [items.some((i) => i.rating) && (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: "Avalia\u00E7\u00E3o" }), items.map((item, ci) => (_jsx(TableCell, { className: cn("text-center", ci === highlightIdx && "bg-muted/50"), children: item.rating ? `${item.rating.score}/5 (${item.rating.count})` : "—" }, ci)))] })), items.some((i) => i.description) && (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: "Descri\u00E7\u00E3o" }), items.map((item, ci) => (_jsx(TableCell, { className: cn("text-center", ci === highlightIdx && "bg-muted/50"), children: item.description ?? "—" }, ci)))] }))] })) })] }), _jsx(ScrollBar, { orientation: "horizontal" })] })] }));
26
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayTable } from "./sdk-types.js";
2
+ export declare function DataTableRenderer({ title, columns, rows, sortable }: DisplayTable): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { ArrowUpDown, ArrowUp, ArrowDown } from "lucide-react";
4
+ import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "../ui/table.js";
5
+ import { ScrollArea, ScrollBar } from "../ui/scroll-area.js";
6
+ import { Button } from "../ui/button.js";
7
+ import { Badge } from "../ui/badge.js";
8
+ function formatMoney(value, currency = "BRL") {
9
+ return new Intl.NumberFormat("pt-BR", { style: "currency", currency }).format(value);
10
+ }
11
+ function renderCellValue(value, type) {
12
+ if (value == null)
13
+ return "—";
14
+ switch (type) {
15
+ case "money":
16
+ return typeof value === "number"
17
+ ? formatMoney(value)
18
+ : typeof value === "object" && value !== null && "value" in value
19
+ ? formatMoney(value.value, value.currency)
20
+ : String(value);
21
+ case "image":
22
+ return typeof value === "string" ? (_jsx("img", { src: value, alt: "", className: "rounded-sm max-h-12 object-cover", loading: "lazy", decoding: "async" })) : null;
23
+ case "link":
24
+ return typeof value === "string" ? (_jsx("a", { href: value, target: "_blank", rel: "noopener noreferrer", className: "text-primary underline underline-offset-2 hover:opacity-80", children: value })) : null;
25
+ case "badge":
26
+ return _jsx(Badge, { variant: "secondary", children: String(value) });
27
+ default:
28
+ return String(value);
29
+ }
30
+ }
31
+ function compareValues(a, b, type) {
32
+ if (a == null && b == null)
33
+ return 0;
34
+ if (a == null)
35
+ return 1;
36
+ if (b == null)
37
+ return -1;
38
+ if (type === "money") {
39
+ const av = typeof a === "number" ? a : typeof a === "object" && a !== null && "value" in a ? a.value : 0;
40
+ const bv = typeof b === "number" ? b : typeof b === "object" && b !== null && "value" in b ? b.value : 0;
41
+ return av - bv;
42
+ }
43
+ if (type === "number") {
44
+ return (Number(a) || 0) - (Number(b) || 0);
45
+ }
46
+ return String(a).localeCompare(String(b), "pt-BR");
47
+ }
48
+ export function DataTableRenderer({ title, columns, rows, sortable }) {
49
+ const [sortKey, setSortKey] = useState(null);
50
+ const [sortDir, setSortDir] = useState("asc");
51
+ function handleSort(key) {
52
+ if (!sortable)
53
+ return;
54
+ if (sortKey === key) {
55
+ setSortDir((d) => (d === "asc" ? "desc" : "asc"));
56
+ }
57
+ else {
58
+ setSortKey(key);
59
+ setSortDir("asc");
60
+ }
61
+ }
62
+ const sortedRows = sortKey
63
+ ? [...rows].sort((a, b) => {
64
+ const col = columns.find((c) => c.key === sortKey);
65
+ const dir = sortDir === "asc" ? 1 : -1;
66
+ return compareValues(a[sortKey], b[sortKey], col?.type ?? "text") * dir;
67
+ })
68
+ : rows;
69
+ return (_jsxs("div", { className: "space-y-2", children: [title && _jsx("h3", { className: "text-sm font-semibold text-foreground", children: title }), _jsxs(ScrollArea, { className: "w-full", children: [_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsx(TableRow, { children: columns.map((col) => (_jsx(TableHead, { className: col.align === "right" ? "text-right" : col.align === "center" ? "text-center" : "text-left", children: sortable ? (_jsxs(Button, { variant: "ghost", size: "sm", className: "-ml-3 h-8 font-semibold", onClick: () => handleSort(col.key), "aria-sort": sortKey === col.key
70
+ ? sortDir === "asc"
71
+ ? "ascending"
72
+ : "descending"
73
+ : undefined, children: [col.label, sortKey === col.key ? (sortDir === "asc" ? (_jsx(ArrowUp, { className: "ml-1 h-3 w-3" })) : (_jsx(ArrowDown, { className: "ml-1 h-3 w-3" }))) : (_jsx(ArrowUpDown, { className: "ml-1 h-3 w-3" }))] })) : (col.label) }, col.key))) }) }), _jsx(TableBody, { children: sortedRows.map((row, ri) => (_jsx(TableRow, { children: columns.map((col) => (_jsx(TableCell, { className: col.align === "right" ? "text-right" : col.align === "center" ? "text-center" : "text-left", children: renderCellValue(row[col.key], col.type) }, col.key))) }, ri))) })] }), _jsx(ScrollBar, { orientation: "horizontal" })] })] }));
74
+ }
@@ -0,0 +1,26 @@
1
+ declare const WHITELIST_MODULES: readonly ["react", "react-dom", "react-dom/client", "framer-motion", "recharts", "lucide-react"];
2
+ type WhitelistedModule = (typeof WHITELIST_MODULES)[number];
3
+ interface ImportDecl {
4
+ module: WhitelistedModule;
5
+ symbols: string[];
6
+ }
7
+ interface Layout {
8
+ height?: number | "auto";
9
+ aspectRatio?: string;
10
+ maxWidth?: number;
11
+ }
12
+ export interface DisplayReactRendererProps {
13
+ version?: "1";
14
+ title?: string;
15
+ description?: string;
16
+ code: string;
17
+ language?: "jsx" | "tsx";
18
+ entry?: "default";
19
+ imports?: ImportDecl[];
20
+ initialProps?: Record<string, unknown>;
21
+ layout?: Layout;
22
+ theme?: "light" | "dark" | "auto";
23
+ sandboxBase?: string;
24
+ }
25
+ export declare const DisplayReactRenderer: import("react").NamedExoticComponent<DisplayReactRendererProps>;
26
+ export {};
@@ -0,0 +1,192 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo, useEffect, useMemo, useRef, useState } from "react";
3
+ import { transform as sucraseTransform } from "sucrase";
4
+ import { SANDBOX_BOOTSTRAP } from "./react-sandbox/bootstrap.js";
5
+ // ─── Types ────────────────────────────────────────────────────────────────────
6
+ const WHITELIST_MODULES = [
7
+ "react",
8
+ "react-dom",
9
+ "react-dom/client",
10
+ "framer-motion",
11
+ "recharts",
12
+ "lucide-react",
13
+ ];
14
+ // ─── Size limits (mirror SDK schema) ──────────────────────────────────────────
15
+ const MAX_CODE_BYTES = 8 * 1024;
16
+ const MAX_PROPS_BYTES = 32 * 1024;
17
+ const bundleCache = new Map();
18
+ function loadBundles(base) {
19
+ const key = base;
20
+ const cached = bundleCache.get(key);
21
+ if (cached)
22
+ return cached;
23
+ const p = (async () => {
24
+ const [react, reactDom, framerMotion, recharts, lucideReact] = await Promise.all([
25
+ fetch(`${base}/react.js`).then((r) => r.text()),
26
+ fetch(`${base}/react-dom.js`).then((r) => r.text()),
27
+ fetch(`${base}/framer-motion.js`).then((r) => r.text()),
28
+ fetch(`${base}/recharts.js`).then((r) => r.text()),
29
+ fetch(`${base}/lucide-react.js`).then((r) => r.text()),
30
+ ]);
31
+ return { react, reactDom, framerMotion, recharts, lucideReact };
32
+ })();
33
+ bundleCache.set(key, p);
34
+ return p;
35
+ }
36
+ // ─── Validation helpers ──────────────────────────────────────────────────────
37
+ function byteLength(s) {
38
+ return new TextEncoder().encode(s).length;
39
+ }
40
+ function validatePayload(props) {
41
+ if (!props.code || typeof props.code !== "string")
42
+ return "missing code";
43
+ if (byteLength(props.code) > MAX_CODE_BYTES)
44
+ return `code exceeds ${MAX_CODE_BYTES} bytes`;
45
+ if (props.initialProps) {
46
+ try {
47
+ const s = JSON.stringify(props.initialProps);
48
+ if (byteLength(s) > MAX_PROPS_BYTES)
49
+ return `initialProps exceeds ${MAX_PROPS_BYTES} bytes`;
50
+ }
51
+ catch {
52
+ return "initialProps not JSON-serializable";
53
+ }
54
+ }
55
+ if (props.imports) {
56
+ for (const imp of props.imports) {
57
+ if (!WHITELIST_MODULES.includes(imp.module)) {
58
+ return `import not in whitelist: ${imp.module}`;
59
+ }
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+ // ─── Transpile user code ─────────────────────────────────────────────────────
65
+ function compile(code, language) {
66
+ try {
67
+ const transforms = ["jsx", "imports"];
68
+ if (language === "tsx")
69
+ transforms.unshift("typescript");
70
+ const out = sucraseTransform(code, {
71
+ transforms,
72
+ production: true,
73
+ jsxRuntime: "classic",
74
+ });
75
+ return { ok: true, code: out.code };
76
+ }
77
+ catch (e) {
78
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
79
+ }
80
+ }
81
+ // ─── Build srcdoc ────────────────────────────────────────────────────────────
82
+ function buildSrcDoc(bundles) {
83
+ return `<!doctype html><html><head><meta charset="utf-8"><style>
84
+ html,body{margin:0;padding:0;}
85
+ body{font:14px/1.5 system-ui,-apple-system,sans-serif;padding:12px;box-sizing:border-box;}
86
+ #root{min-height:0;}
87
+ *{box-sizing:border-box;}
88
+ </style></head><body><div id="root"></div>
89
+ <script>${bundles.react}<\/script>
90
+ <script>${bundles.reactDom}<\/script>
91
+ <script>${bundles.framerMotion}<\/script>
92
+ <script>${bundles.recharts}<\/script>
93
+ <script>${bundles.lucideReact}<\/script>
94
+ <script>${SANDBOX_BOOTSTRAP}<\/script>
95
+ </body></html>`;
96
+ }
97
+ // ─── Component ───────────────────────────────────────────────────────────────
98
+ export const DisplayReactRenderer = memo(function DisplayReactRenderer(props) {
99
+ const { code, language = "jsx", initialProps, layout, theme = "auto", title, description, sandboxBase = "/sandbox", } = props;
100
+ const iframeRef = useRef(null);
101
+ const [height, setHeight] = useState(null);
102
+ const [error, setError] = useState(null);
103
+ const [status, setStatus] = useState("loading");
104
+ // Validate + compile once per payload
105
+ const compiled = useMemo(() => {
106
+ const validationError = validatePayload(props);
107
+ if (validationError)
108
+ return { ok: false, error: validationError };
109
+ return compile(code, language);
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
111
+ }, [code, language, JSON.stringify(props.imports), JSON.stringify(initialProps)]);
112
+ // Build + inject srcdoc once bundles are available
113
+ useEffect(() => {
114
+ if (compiled.ok === false) {
115
+ setError(compiled.error);
116
+ setStatus("error");
117
+ return;
118
+ }
119
+ let cancelled = false;
120
+ loadBundles(sandboxBase)
121
+ .then((bundles) => {
122
+ if (cancelled)
123
+ return;
124
+ const iframe = iframeRef.current;
125
+ if (!iframe)
126
+ return;
127
+ iframe.srcdoc = buildSrcDoc(bundles);
128
+ })
129
+ .catch((e) => {
130
+ if (cancelled)
131
+ return;
132
+ setError(`failed to load sandbox bundles: ${e instanceof Error ? e.message : String(e)}`);
133
+ setStatus("error");
134
+ });
135
+ return () => {
136
+ cancelled = true;
137
+ };
138
+ }, [compiled, sandboxBase]);
139
+ // postMessage pump: wait for sandbox-boot → send compiled code. Also capture height + ready.
140
+ useEffect(() => {
141
+ const handler = (ev) => {
142
+ const iframe = iframeRef.current;
143
+ if (!iframe || ev.source !== iframe.contentWindow)
144
+ return;
145
+ const data = ev.data;
146
+ if (!data || typeof data !== "object" || !data.type)
147
+ return;
148
+ if (data.type === "sandbox-boot") {
149
+ if (!compiled.ok)
150
+ return;
151
+ iframe.contentWindow?.postMessage({
152
+ type: "sandbox-render",
153
+ compiledCode: compiled.code,
154
+ payload: {
155
+ initialProps: initialProps ?? {},
156
+ theme,
157
+ },
158
+ }, "*");
159
+ }
160
+ else if (data.type === "sandbox-ready") {
161
+ setStatus("ready");
162
+ }
163
+ else if (data.type === "sandbox-height" && typeof data.height === "number") {
164
+ if (layout?.height !== "auto" && typeof layout?.height === "number")
165
+ return;
166
+ setHeight(data.height + 24); // padding from body
167
+ }
168
+ };
169
+ window.addEventListener("message", handler);
170
+ return () => window.removeEventListener("message", handler);
171
+ }, [compiled, initialProps, theme, layout?.height]);
172
+ // Compute iframe style
173
+ const iframeStyle = {
174
+ width: "100%",
175
+ maxWidth: layout?.maxWidth ? `${layout.maxWidth}px` : undefined,
176
+ aspectRatio: layout?.aspectRatio,
177
+ height: typeof layout?.height === "number"
178
+ ? `${layout.height}px`
179
+ : height !== null
180
+ ? `${height}px`
181
+ : "120px",
182
+ border: "1px solid var(--border, #e5e5e5)",
183
+ borderRadius: "8px",
184
+ display: "block",
185
+ background: "var(--bg, #fff)",
186
+ };
187
+ if (error || (compiled.ok === false)) {
188
+ const msg = error ?? (compiled.ok === false ? compiled.error : "unknown");
189
+ return (_jsxs("div", { className: "rounded-lg border border-red-300 bg-red-50 text-red-900 p-3 text-xs", children: [_jsx("div", { className: "font-semibold mb-1", children: "React sandbox error" }), _jsx("pre", { className: "whitespace-pre-wrap break-words font-mono text-[11px]", children: msg })] }));
190
+ }
191
+ return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [(title || description) && (_jsxs("div", { className: "flex flex-col gap-0.5 px-0.5", children: [title && _jsx("div", { className: "text-sm font-semibold text-foreground", children: title }), description && _jsx("div", { className: "text-xs text-muted-foreground", children: description })] })), _jsx("iframe", { ref: iframeRef, sandbox: "allow-scripts", title: title ?? "react sandbox", style: iframeStyle, "aria-busy": status === "loading" })] }));
192
+ });
@@ -0,0 +1,2 @@
1
+ import type { DisplayFile } from "./sdk-types.js";
2
+ export declare function FileCardRenderer({ name, type, size, url }: DisplayFile): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Download, File, FileCode, FileImage, FileMinus, FileText, FileVideo, Music, } from "lucide-react";
3
+ import { Button } from "../ui/button.js";
4
+ import { Card } from "../ui/card.js";
5
+ function getFileIcon(type) {
6
+ const mime = type.toLowerCase();
7
+ if (mime.startsWith("image/"))
8
+ return FileImage;
9
+ if (mime.startsWith("video/"))
10
+ return FileVideo;
11
+ if (mime.startsWith("audio/"))
12
+ return Music;
13
+ if (mime === "application/pdf" || mime === "text/plain" || mime.includes("document"))
14
+ return FileText;
15
+ if (mime.includes("spreadsheet") || mime.includes("csv"))
16
+ return FileMinus;
17
+ if (mime.includes("javascript") || mime.includes("typescript") || mime.includes("json") || mime.includes("html") || mime.includes("css") || mime.includes("xml"))
18
+ return FileCode;
19
+ return File;
20
+ }
21
+ function formatSize(bytes) {
22
+ if (bytes < 1024)
23
+ return `${bytes} B`;
24
+ if (bytes < 1024 * 1024)
25
+ return `${(bytes / 1024).toFixed(1)} KB`;
26
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
27
+ }
28
+ export function FileCardRenderer({ name, type, size, url }) {
29
+ const Icon = getFileIcon(type);
30
+ return (_jsxs(Card, { className: "flex items-center gap-3 p-3", children: [_jsx("div", { className: "shrink-0 text-primary", children: _jsx(Icon, { className: "h-8 w-8" }) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("p", { className: "font-medium text-sm truncate", children: name }), _jsxs("p", { className: "text-xs text-muted-foreground", children: [type, size !== undefined && ` · ${formatSize(size)}`] })] }), url && (_jsx(Button, { variant: "ghost", size: "icon", asChild: true, children: _jsx("a", { href: url, download: name, "aria-label": `Baixar ${name}`, children: _jsx(Download, { className: "h-4 w-4" }) }) }))] }));
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayGallery } from "./sdk-types.js";
2
+ export declare function GalleryRenderer({ title, images }: DisplayGallery): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { ZoomIn } from "lucide-react";
4
+ import { cn } from "../lib/utils.js";
5
+ import { Dialog, DialogContent, DialogTitle } from "../ui/dialog.js";
6
+ export function GalleryRenderer({ title, images }) {
7
+ const [lightboxIdx, setLightboxIdx] = useState(null);
8
+ const activeImage = lightboxIdx !== null ? images[lightboxIdx] : null;
9
+ return (_jsxs("div", { className: "space-y-2", children: [title && _jsx("h3", { className: "text-sm font-medium text-foreground", children: title }), _jsx("div", { className: "grid grid-cols-2 md:grid-cols-3 gap-2", children: images.map((img, i) => (_jsxs("button", { className: "relative group cursor-pointer rounded-md overflow-hidden", onClick: () => setLightboxIdx(i), "aria-label": img.alt ?? `Imagem ${i + 1}`, children: [_jsx("img", { src: img.url, alt: img.alt ?? "", className: "w-full h-full object-cover aspect-square", loading: "lazy" }), _jsx("div", { className: "absolute inset-0 bg-background/50 opacity-0 group-hover:opacity-100 flex items-center justify-center transition-opacity", children: _jsx(ZoomIn, { className: "h-5 w-5 text-foreground" }) }), img.caption && (_jsx("p", { className: "absolute bottom-0 left-0 right-0 text-sm text-muted-foreground bg-background/80 px-2 py-1 truncate", children: img.caption }))] }, i))) }), _jsx(Dialog, { open: lightboxIdx !== null, onOpenChange: (open) => { if (!open)
10
+ setLightboxIdx(null); }, children: _jsxs(DialogContent, { className: cn("max-w-4xl p-0 bg-background/95"), children: [_jsx(DialogTitle, { className: "sr-only", children: activeImage?.alt ?? "Visualizador de imagem" }), activeImage && (_jsxs("div", { className: "flex flex-col", children: [_jsx("img", { src: activeImage.url, alt: activeImage.alt ?? "", className: "w-full max-h-[80vh] object-contain" }), activeImage.caption && (_jsx("p", { className: "text-sm text-muted-foreground px-4 py-3", children: activeImage.caption }))] }))] }) })] }));
11
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayImage } from "./sdk-types.js";
2
+ export declare function ImageViewerRenderer({ url, alt, caption, width, height }: DisplayImage): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { ZoomIn, ZoomOut, RotateCcw, X } from "lucide-react";
4
+ import { Dialog, DialogContent, DialogTitle } from "../ui/dialog.js";
5
+ import { Button } from "../ui/button.js";
6
+ import { cn } from "../lib/utils.js";
7
+ export function ImageViewerRenderer({ url, alt, caption, width, height }) {
8
+ const [dialogOpen, setDialogOpen] = useState(false);
9
+ const [zoom, setZoom] = useState(1);
10
+ function handleOpen() {
11
+ setZoom(1);
12
+ setDialogOpen(true);
13
+ }
14
+ return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("button", { className: "relative group cursor-pointer rounded-md overflow-hidden inline-block", onClick: handleOpen, "aria-label": `Ampliar imagem${alt ? `: ${alt}` : ""}`, children: [_jsx("img", { src: url, alt: alt ?? "", className: "block max-w-full rounded-md", loading: "lazy", decoding: "async", width: width, height: height }), _jsx("div", { className: "absolute inset-0 bg-background/50 opacity-0 group-hover:opacity-100 flex items-center justify-center transition-opacity", children: _jsx(ZoomIn, { className: "h-5 w-5 text-foreground" }) })] }), caption && (_jsx("p", { className: "text-xs text-muted-foreground", children: caption })), _jsx(Dialog, { open: dialogOpen, onOpenChange: setDialogOpen, children: _jsxs(DialogContent, { className: "max-w-4xl p-0 bg-background/95 overflow-hidden", children: [_jsx(DialogTitle, { className: "sr-only", children: alt ?? "Visualizador de imagem" }), _jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "flex items-center gap-1 p-2 border-b border-border", children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: () => setZoom((z) => Math.max(0.25, z - 0.25)), "aria-label": "Reduzir zoom", disabled: zoom <= 0.25, children: _jsx(ZoomOut, { className: "h-4 w-4" }) }), _jsxs("span", { className: cn("text-xs text-muted-foreground w-12 text-center tabular-nums"), children: [Math.round(zoom * 100), "%"] }), _jsx(Button, { variant: "ghost", size: "icon", onClick: () => setZoom((z) => Math.min(4, z + 0.25)), "aria-label": "Aumentar zoom", disabled: zoom >= 4, children: _jsx(ZoomIn, { className: "h-4 w-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", onClick: () => setZoom(1), "aria-label": "Resetar zoom", children: _jsx(RotateCcw, { className: "h-4 w-4" }) }), _jsx("div", { className: "flex-1" }), _jsx(Button, { variant: "ghost", size: "icon", onClick: () => setDialogOpen(false), "aria-label": "Fechar", children: _jsx(X, { className: "h-4 w-4" }) })] }), _jsx("div", { className: "overflow-auto max-h-[80vh] flex items-center justify-center p-4", children: _jsx("img", { src: url, alt: alt ?? "", style: { transform: `scale(${zoom})`, transformOrigin: "center" }, className: "max-w-full transition-transform", width: width, height: height }) }), caption && (_jsx("p", { className: "text-xs text-muted-foreground text-center p-2 border-t border-border", children: caption }))] })] }) })] }));
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayLink } from "./sdk-types.js";
2
+ export declare function LinkPreviewRenderer({ url, title, description, image, favicon, domain, }: DisplayLink): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Globe } from "lucide-react";
4
+ import { Card } from "../ui/card";
5
+ function getDomain(url, domainProp) {
6
+ if (domainProp)
7
+ return domainProp;
8
+ try {
9
+ return new URL(url).hostname.replace(/^www\./, "");
10
+ }
11
+ catch {
12
+ return url;
13
+ }
14
+ }
15
+ export function LinkPreviewRenderer({ url, title, description, image, favicon, domain, }) {
16
+ const [imgError, setImgError] = useState(false);
17
+ const [faviconError, setFaviconError] = useState(false);
18
+ const displayDomain = getDomain(url, domain);
19
+ return (_jsx("a", { href: url, target: "_blank", rel: "noopener noreferrer", "aria-label": `Link: ${title}`, children: _jsxs(Card, { className: "overflow-hidden hover:bg-muted/50 transition-colors", children: [image && !imgError && (_jsx("div", { className: "aspect-video overflow-hidden", children: _jsx("img", { src: image, alt: title, className: "w-full h-full object-cover", loading: "lazy", decoding: "async", onError: () => setImgError(true) }) })), _jsxs("div", { className: "p-3 space-y-1", children: [_jsxs("div", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [favicon && !faviconError ? (_jsx("img", { src: favicon, alt: "", className: "w-3 h-3 rounded-sm", onError: () => setFaviconError(true), "aria-hidden": "true" })) : (_jsx(Globe, { size: 12, "aria-hidden": "true", className: "shrink-0" })), _jsx("span", { children: displayDomain })] }), _jsx("p", { className: "font-medium text-foreground text-sm", children: title }), description && (_jsx("p", { className: "text-xs text-muted-foreground line-clamp-2", children: description }))] })] }) }));
20
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayMap } from "./sdk-types.js";
2
+ export declare function MapViewRenderer({ title, pins, zoom }: DisplayMap): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { MapPin } from "lucide-react";
3
+ import { Card } from "../ui/card.js";
4
+ import { Separator } from "../ui/separator.js";
5
+ function buildOsmUrl(pins, zoom) {
6
+ if (pins.length === 0) {
7
+ return `https://www.openstreetmap.org/export/embed.html?bbox=-180,-90,180,90&layer=mapnik`;
8
+ }
9
+ const lat = pins.reduce((acc, p) => acc + p.lat, 0) / pins.length;
10
+ const lng = pins.reduce((acc, p) => acc + p.lng, 0) / pins.length;
11
+ const firstPin = pins[0];
12
+ const markerParam = pins.length === 1
13
+ ? `&mlat=${firstPin.lat}&mlon=${firstPin.lng}`
14
+ : "";
15
+ return `https://www.openstreetmap.org/export/embed.html?bbox=${lng - 0.05},${lat - 0.05},${lng + 0.05},${lat + 0.05}&layer=mapnik&zoom=${zoom}${markerParam}`;
16
+ }
17
+ export function MapViewRenderer({ title, pins, zoom }) {
18
+ const osmUrl = buildOsmUrl(pins, zoom);
19
+ return (_jsxs(Card, { className: "overflow-hidden", children: [title && (_jsx("div", { className: "px-4 py-3", children: _jsx("h3", { className: "font-medium text-sm text-foreground", children: title }) })), _jsxs("div", { className: "relative aspect-video bg-muted text-muted-foreground overflow-hidden", children: [_jsx("iframe", { src: osmUrl, className: "w-full h-full border-0", title: title ?? "Mapa OpenStreetMap", loading: "lazy", referrerPolicy: "no-referrer", sandbox: "allow-scripts allow-same-origin" }), _jsx("div", { className: "absolute inset-0 pointer-events-none flex items-center justify-center opacity-10", children: _jsx(MapPin, { className: "h-10 w-10" }) })] }), pins.length > 0 && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsx("ul", { className: "p-3 space-y-2", "aria-label": "Locais no mapa", children: pins.map((pin, i) => (_jsxs("li", { className: "flex items-start gap-2", children: [_jsx(MapPin, { className: "h-4 w-4 shrink-0 text-primary mt-0.5", "aria-hidden": "true" }), _jsxs("span", { className: "flex flex-col min-w-0", children: [pin.label && (_jsx("span", { className: "font-medium text-sm text-foreground", children: pin.label })), pin.address && (_jsx("span", { className: "text-xs text-muted-foreground", children: pin.address })), !pin.label && !pin.address && (_jsxs("span", { className: "text-xs text-muted-foreground font-mono", children: [pin.lat.toFixed(4), ", ", pin.lng.toFixed(4)] }))] })] }, i))) })] }))] }));
20
+ }
@@ -0,0 +1,2 @@
1
+ import type { DisplayMetric } from "./sdk-types.js";
2
+ export declare function MetricCardRenderer({ label, value, unit, trend }: DisplayMetric): import("react/jsx-runtime").JSX.Element;