@pollinations/ui 0.1.0-alpha.1 → 0.1.0-alpha.4

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 (88) hide show
  1. package/README.md +148 -36
  2. package/dist/Button-ByKwRtdw.d.cts +29 -0
  3. package/dist/Button-ByKwRtdw.d.ts +29 -0
  4. package/dist/Chip-v-ADv6cz.d.cts +18 -0
  5. package/dist/Chip-v-ADv6cz.d.ts +18 -0
  6. package/dist/Dialog-D3Nqt8cE.d.cts +66 -0
  7. package/dist/Dialog-D3Nqt8cE.d.ts +66 -0
  8. package/dist/app-user-menu/sdk.cjs +698 -242
  9. package/dist/app-user-menu/sdk.cjs.map +1 -1
  10. package/dist/app-user-menu/sdk.d.cts +22 -7
  11. package/dist/app-user-menu/sdk.d.ts +22 -7
  12. package/dist/app-user-menu/sdk.js +703 -240
  13. package/dist/app-user-menu/sdk.js.map +1 -1
  14. package/dist/app.css +12 -122
  15. package/dist/auth/index.cjs +1365 -85
  16. package/dist/auth/index.cjs.map +1 -1
  17. package/dist/auth/index.d.cts +91 -6
  18. package/dist/auth/index.d.ts +91 -6
  19. package/dist/auth/index.js +1362 -84
  20. package/dist/auth/index.js.map +1 -1
  21. package/dist/auth/sdk.cjs +244 -0
  22. package/dist/auth/sdk.cjs.map +1 -0
  23. package/dist/auth/sdk.d.cts +40 -0
  24. package/dist/auth/sdk.d.ts +40 -0
  25. package/dist/auth/sdk.js +213 -0
  26. package/dist/auth/sdk.js.map +1 -0
  27. package/dist/brand/lockup-horizontal-black.png +0 -0
  28. package/dist/brand/lockup-horizontal-black.svg +4 -0
  29. package/dist/brand/lockup-horizontal-white.png +0 -0
  30. package/dist/brand/lockup-horizontal-white.svg +4 -0
  31. package/dist/brand/lockup-horizontal.svg +4 -0
  32. package/dist/brand/lockup-stacked-black.png +0 -0
  33. package/dist/brand/lockup-stacked-black.svg +4 -0
  34. package/dist/brand/lockup-stacked-white.png +0 -0
  35. package/dist/brand/lockup-stacked-white.svg +4 -0
  36. package/dist/brand/lockup-stacked.svg +4 -0
  37. package/dist/brand/mark-black.png +0 -0
  38. package/dist/brand/mark-black.svg +1 -0
  39. package/dist/brand/mark-white.png +0 -0
  40. package/dist/brand/mark-white.svg +1 -0
  41. package/dist/brand/mark.svg +1 -0
  42. package/dist/brand/polli/polli-lockup-horizontal-black.png +0 -0
  43. package/dist/brand/polli/polli-lockup-horizontal-white.png +0 -0
  44. package/dist/brand/polli/polli-lockup-stacked-black.png +0 -0
  45. package/dist/brand/polli/polli-lockup-stacked-white.png +0 -0
  46. package/dist/brand/polli/polli.png +0 -0
  47. package/dist/brand/wordmark-black.png +0 -0
  48. package/dist/brand/wordmark-black.svg +1 -0
  49. package/dist/brand/wordmark-white.png +0 -0
  50. package/dist/brand/wordmark-white.svg +1 -0
  51. package/dist/brand/wordmark.svg +1 -0
  52. package/dist/fonts/geist-pixel-square.woff2 +0 -0
  53. package/dist/gen/index.cjs +427 -217
  54. package/dist/gen/index.cjs.map +1 -1
  55. package/dist/gen/index.d.cts +68 -19
  56. package/dist/gen/index.d.ts +68 -19
  57. package/dist/gen/index.js +421 -215
  58. package/dist/gen/index.js.map +1 -1
  59. package/dist/index.browser.min.js +2 -0
  60. package/dist/index.browser.min.js.map +1 -0
  61. package/dist/index.cjs +3711 -1590
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +548 -178
  64. package/dist/index.d.ts +548 -178
  65. package/dist/index.js +3713 -1655
  66. package/dist/index.js.map +1 -1
  67. package/dist/licenses/Geist-OFL.txt +93 -0
  68. package/dist/markdown.cjs +826 -0
  69. package/dist/markdown.cjs.map +1 -0
  70. package/dist/markdown.d.cts +16 -0
  71. package/dist/markdown.d.ts +16 -0
  72. package/dist/markdown.js +797 -0
  73. package/dist/markdown.js.map +1 -0
  74. package/dist/styles.css +1 -1
  75. package/dist/theme.css +87 -0
  76. package/dist/wallet/index.cjs +291 -64
  77. package/dist/wallet/index.cjs.map +1 -1
  78. package/dist/wallet/index.d.cts +30 -7
  79. package/dist/wallet/index.d.ts +30 -7
  80. package/dist/wallet/index.js +290 -64
  81. package/dist/wallet/index.js.map +1 -1
  82. package/package.json +106 -89
  83. package/dist/Chip-CQCq34kS.d.cts +0 -20
  84. package/dist/Chip-Cj4xG7Te.d.ts +0 -20
  85. package/dist/assets/logo-wordmark.svg +0 -1
  86. package/dist/assets/logo.svg +0 -4
  87. package/dist/theme-jRPPBmld.d.cts +0 -20
  88. package/dist/theme-jRPPBmld.d.ts +0 -20
@@ -0,0 +1,797 @@
1
+ // src/compositions/Markdown.tsx
2
+ import { isValidElement } from "react";
3
+ import ReactMarkdown from "react-markdown";
4
+ import remarkGfm from "remark-gfm";
5
+
6
+ // src/lib/cn.ts
7
+ import { clsx } from "clsx";
8
+ import { extendTailwindMerge } from "tailwind-merge";
9
+ var twMerge = extendTailwindMerge({ prefix: "polli" });
10
+ function cn(...inputs) {
11
+ return twMerge(clsx(...inputs));
12
+ }
13
+
14
+ // src/lib/link.ts
15
+ function isExternalHref(href, origin = globalThis.location?.origin) {
16
+ if (typeof href !== "string" || !/^(https?:)?\/\//i.test(href))
17
+ return false;
18
+ if (!origin) return true;
19
+ try {
20
+ return new URL(href, origin).origin !== origin;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+
26
+ // src/primitives/icons/index.tsx
27
+ import { jsx, jsxs } from "react/jsx-runtime";
28
+ var strokeProps = {
29
+ fill: "none",
30
+ stroke: "currentColor",
31
+ strokeWidth: 2,
32
+ strokeLinecap: "round",
33
+ strokeLinejoin: "round"
34
+ };
35
+ function CheckIcon(props) {
36
+ return /* @__PURE__ */ jsx(
37
+ "svg",
38
+ {
39
+ "aria-hidden": "true",
40
+ viewBox: "0 0 24 24",
41
+ ...strokeProps,
42
+ strokeWidth: 2.5,
43
+ ...props,
44
+ children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" })
45
+ }
46
+ );
47
+ }
48
+ function ClipboardIcon(props) {
49
+ return /* @__PURE__ */ jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", ...strokeProps, ...props, children: [
50
+ /* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2" }),
51
+ /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
52
+ ] });
53
+ }
54
+ function ExternalLinkIcon(props) {
55
+ return /* @__PURE__ */ jsx("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", ...strokeProps, ...props, children: /* @__PURE__ */ jsx("path", { d: "M7 17 17 7M9 7h8v8" }) });
56
+ }
57
+
58
+ // src/primitives/InlineLink.tsx
59
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
60
+ function InlineLink({
61
+ as,
62
+ external,
63
+ showIcon = true,
64
+ size = "inherit",
65
+ tone = "accent",
66
+ className,
67
+ children,
68
+ ...linkProps
69
+ }) {
70
+ const Component = as || "a";
71
+ const isExternal = external ?? isExternalHref(linkProps.href);
72
+ return /* @__PURE__ */ jsxs2(
73
+ Component,
74
+ {
75
+ target: isExternal && as !== "button" ? "_blank" : void 0,
76
+ rel: isExternal && as !== "button" ? "noopener noreferrer" : void 0,
77
+ className: ["polli-link", className].filter(Boolean).join(" "),
78
+ "data-size": size,
79
+ "data-tone": tone,
80
+ ...linkProps,
81
+ children: [
82
+ children,
83
+ showIcon && isExternal && /* @__PURE__ */ jsx2(
84
+ ExternalLinkIcon,
85
+ {
86
+ "aria-hidden": "true",
87
+ className: "polli-link-external-icon"
88
+ }
89
+ )
90
+ ]
91
+ }
92
+ );
93
+ }
94
+
95
+ // src/compositions/CopyButton.tsx
96
+ import {
97
+ useEffect as useEffect2,
98
+ useRef as useRef2,
99
+ useState as useState2
100
+ } from "react";
101
+
102
+ // src/primitives/Button.tsx
103
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
104
+ var pillSizes = {
105
+ icon: "polli:h-12 polli:w-12 polli:p-0",
106
+ xs: "polli:h-5 polli:px-1.5 polli:py-0 polli:text-[11px] polli:leading-none",
107
+ sm: "polli:min-h-7 polli:px-2 polli:pt-0.5 polli:pb-1",
108
+ md: "polli:min-h-9 polli:px-4 polli:pt-1.5 polli:pb-2",
109
+ lg: "polli:min-h-12 polli:px-6 polli:py-3 polli:text-base"
110
+ };
111
+ var raisedSizes = {
112
+ icon: "polli:h-12 polli:w-12 polli:p-0",
113
+ xs: "polli:px-2 polli:py-1 polli:text-xs",
114
+ sm: "polli:px-4 polli:py-2 polli:text-sm",
115
+ md: "polli:px-7 polli:py-3.5 polli:text-base",
116
+ lg: "polli:px-8 polli:py-4 polli:text-lg"
117
+ };
118
+ var appearanceClasses = {
119
+ pill: "polli:rounded-full",
120
+ raised: "polli:rounded-xl polli:border-r-[3px] polli:border-b-[3px] polli:border-solid polli:border-theme-text-strong/20 polli:hover:border-theme-text-strong/45"
121
+ };
122
+ var themeClasses = "polli:bg-theme-bg-active polli:text-theme-text-strong polli:hover:bg-theme-bg-hover polli:hover:text-theme-text-hover polli:transition-colors";
123
+ var outlined = "polli:border polli:border-theme-text-soft polli:bg-theme-bg-active/30 polli:text-theme-text-strong polli:transition-colors polli:[.dark_&]:bg-transparent";
124
+ var intentClasses = {
125
+ brand: `${outlined} polli:hover:bg-theme-bg-active/50 polli:[.dark_&]:hover:bg-theme-text-soft/10`,
126
+ commit: `${outlined} polli:hover:border-theme-bg-active polli:hover:bg-theme-bg-active polli:focus-visible:border-theme-bg-active polli:focus-visible:bg-theme-bg-active polli:[.dark_&]:hover:bg-theme-bg-active polli:[.dark_&]:focus-visible:bg-theme-bg-active`,
127
+ danger: "polli:border polli:border-intent-danger-text polli:bg-intent-danger-bg-light polli:text-intent-danger-text polli:hover:bg-intent-danger-bg-hover polli:focus-visible:bg-intent-danger-bg-hover polli:transition-colors polli:[.dark_&]:bg-transparent polli:[.dark_&]:hover:bg-intent-danger-bg-hover polli:[.dark_&]:focus-visible:bg-intent-danger-bg-hover",
128
+ info: "polli:bg-intent-info-bg-light polli:text-intent-info-text polli:hover:bg-intent-info-bg-hover polli:transition-colors",
129
+ // Secondary actions never take the accent: one step stronger grey on hover.
130
+ neutral: "polli:bg-theme-bg-subtle polli:text-theme-text-base polli:hover:bg-theme-text-muted/25 polli:hover:text-theme-text-strong polli:transition-colors"
131
+ };
132
+ var buttonClasses = ({
133
+ intent,
134
+ appearance = "pill",
135
+ size,
136
+ className,
137
+ disabled,
138
+ busy
139
+ }) => {
140
+ const colorClasses = intent ? intentClasses[intent] : themeClasses;
141
+ const sizeClasses = appearance === "raised" ? raisedSizes : pillSizes;
142
+ return cn(
143
+ "polli-control polli:inline-flex polli:items-center polli:justify-center polli:self-center polli:font-body polli:text-sm polli:font-medium polli:leading-normal polli:box-border polli:border polli:border-transparent",
144
+ // A busy button is working, not unavailable: it keeps its strength.
145
+ busy ? "polli:cursor-progress" : disabled ? "polli:opacity-50 polli:cursor-not-allowed" : "polli:hover:filter polli:hover:brightness-105 polli:cursor-pointer",
146
+ colorClasses,
147
+ appearanceClasses[appearance],
148
+ sizeClasses[size || "md"],
149
+ className
150
+ );
151
+ };
152
+ function Button({
153
+ as,
154
+ children,
155
+ icon,
156
+ intent,
157
+ appearance,
158
+ size,
159
+ className,
160
+ disabled,
161
+ ...buttonProps
162
+ }) {
163
+ const Component = as || "button";
164
+ const isButton = Component === "button";
165
+ const isAnchor = Component === "a";
166
+ const buttonType = buttonProps.type;
167
+ const onClick = buttonProps.onClick;
168
+ const ariaBusy = buttonProps["aria-busy"];
169
+ const busy = ariaBusy === true || ariaBusy === "true";
170
+ const handleClick = disabled ? (event) => {
171
+ event.preventDefault();
172
+ event.stopPropagation();
173
+ } : onClick;
174
+ return /* @__PURE__ */ jsxs3(
175
+ Component,
176
+ {
177
+ ...buttonProps,
178
+ "data-intent": intent,
179
+ ...isButton ? { type: buttonType ?? "button", disabled } : {},
180
+ ...!isButton && disabled ? { "aria-disabled": true, tabIndex: -1 } : {},
181
+ ...isAnchor && disabled ? { href: void 0 } : {},
182
+ onClick: handleClick,
183
+ className: buttonClasses({
184
+ intent,
185
+ appearance,
186
+ size,
187
+ className,
188
+ disabled,
189
+ busy
190
+ }),
191
+ children: [
192
+ icon && /* @__PURE__ */ jsx3(
193
+ "span",
194
+ {
195
+ "aria-hidden": "true",
196
+ className: "polli:mr-2 polli:flex polli:size-4 polli:shrink-0 polli:[&>svg]:size-full",
197
+ children: busy ? /* @__PURE__ */ jsx3("span", { className: "polli:block polli:size-full polli:animate-spin polli:rounded-full polli:border-2 polli:border-current polli:border-r-transparent polli:motion-reduce:animate-none" }) : icon
198
+ }
199
+ ),
200
+ children
201
+ ]
202
+ }
203
+ );
204
+ }
205
+
206
+ // src/primitives/Tooltip.tsx
207
+ import {
208
+ useEffect,
209
+ useId,
210
+ useRef,
211
+ useState
212
+ } from "react";
213
+ import { createPortal } from "react-dom";
214
+ import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
215
+ var TOOLTIP_MAX_WIDTH = 288;
216
+ var TOOLTIP_VIEWPORT_MARGIN = 12;
217
+ var Tooltip = ({
218
+ children,
219
+ content,
220
+ align = "start",
221
+ ariaLabel,
222
+ clampToViewport = true,
223
+ className,
224
+ maxWidth = TOOLTIP_MAX_WIDTH,
225
+ onClick,
226
+ stopClickPropagation = true,
227
+ style,
228
+ tapEnabled = false,
229
+ triggerAs = "button",
230
+ displayContents = false
231
+ }) => {
232
+ const [showTooltip, setShowTooltip] = useState(false);
233
+ const [tooltipPosition, setTooltipPosition] = useState({
234
+ top: 0,
235
+ left: 0,
236
+ maxWidth
237
+ });
238
+ const triggerRef = useRef(null);
239
+ const tapPinnedRef = useRef(false);
240
+ const tooltipId = useId();
241
+ const closeTooltip = () => {
242
+ tapPinnedRef.current = false;
243
+ setShowTooltip(false);
244
+ };
245
+ useEffect(() => {
246
+ if (!showTooltip) return;
247
+ const dismissOnOutsideTap = (event) => {
248
+ if (triggerRef.current?.contains(event.target)) return;
249
+ tapPinnedRef.current = false;
250
+ setShowTooltip(false);
251
+ };
252
+ const dismissOnEscape = (event) => {
253
+ if (event.key !== "Escape") return;
254
+ tapPinnedRef.current = false;
255
+ setShowTooltip(false);
256
+ };
257
+ const dismissOnViewportChange = () => {
258
+ tapPinnedRef.current = false;
259
+ setShowTooltip(false);
260
+ };
261
+ document.addEventListener("pointerdown", dismissOnOutsideTap);
262
+ document.addEventListener("keydown", dismissOnEscape);
263
+ window.addEventListener("scroll", dismissOnViewportChange, {
264
+ capture: true,
265
+ passive: true
266
+ });
267
+ window.addEventListener("resize", dismissOnViewportChange);
268
+ return () => {
269
+ document.removeEventListener("pointerdown", dismissOnOutsideTap);
270
+ document.removeEventListener("keydown", dismissOnEscape);
271
+ window.removeEventListener("scroll", dismissOnViewportChange, true);
272
+ window.removeEventListener("resize", dismissOnViewportChange);
273
+ };
274
+ }, [showTooltip]);
275
+ const updateTooltipPosition = () => {
276
+ if (triggerRef.current) {
277
+ const rect = triggerRef.current.getBoundingClientRect();
278
+ const availableMaxWidth = Math.min(
279
+ maxWidth,
280
+ window.innerWidth - TOOLTIP_VIEWPORT_MARGIN * 2
281
+ );
282
+ let left = align === "center" ? rect.left + rect.width / 2 : rect.left;
283
+ let transform = align === "center" ? "translateX(-50%)" : void 0;
284
+ if (clampToViewport) {
285
+ left = Math.min(
286
+ Math.max(rect.left, TOOLTIP_VIEWPORT_MARGIN),
287
+ Math.max(
288
+ TOOLTIP_VIEWPORT_MARGIN,
289
+ window.innerWidth - availableMaxWidth - TOOLTIP_VIEWPORT_MARGIN
290
+ )
291
+ );
292
+ transform = void 0;
293
+ }
294
+ setTooltipPosition({
295
+ top: rect.bottom + 4,
296
+ left,
297
+ maxWidth: availableMaxWidth,
298
+ transform
299
+ });
300
+ }
301
+ };
302
+ const triggerClassName = cn(
303
+ "polli-control polli:relative polli:cursor-help polli:text-left polli:inline-flex polli:items-center",
304
+ className
305
+ );
306
+ const cursorClass = displayContents ? "polli:contents" : "polli:cursor-inherit";
307
+ const popupClasses = "polli:fixed polli:w-max polli:px-2 polli:py-1 polli:bg-surface-menu polli:text-theme-text-base polli:font-normal polli:leading-snug polli:tracking-normal polli:normal-case polli:not-italic polli:text-xs polli:rounded-md polli:shadow-md polli:z-[130] polli:pointer-events-none polli:transition-opacity polli:whitespace-pre-line polli:break-words";
308
+ const popupNode = content ? /* @__PURE__ */ jsx4(
309
+ "span",
310
+ {
311
+ id: tooltipId,
312
+ role: "tooltip",
313
+ "aria-hidden": !showTooltip,
314
+ style: {
315
+ top: tooltipPosition.top,
316
+ left: tooltipPosition.left,
317
+ maxWidth: tooltipPosition.maxWidth,
318
+ transform: tooltipPosition.transform
319
+ },
320
+ className: `${showTooltip ? "polli:visible polli:opacity-100" : "polli:invisible polli:opacity-0"} ${popupClasses}`,
321
+ children: content
322
+ }
323
+ ) : null;
324
+ const tooltipPopup = popupNode && typeof document !== "undefined" ? createPortal(
325
+ popupNode,
326
+ triggerRef.current?.closest('[role="dialog"]') ?? document.body
327
+ ) : popupNode;
328
+ const contentNode = /* @__PURE__ */ jsxs4(Fragment, { children: [
329
+ /* @__PURE__ */ jsx4("span", { className: cursorClass, children }),
330
+ tooltipPopup
331
+ ] });
332
+ const sharedProps = {
333
+ "aria-label": ariaLabel,
334
+ "aria-describedby": content && showTooltip ? tooltipId : void 0,
335
+ className: triggerClassName,
336
+ onMouseEnter: () => {
337
+ updateTooltipPosition();
338
+ setShowTooltip(true);
339
+ },
340
+ onMouseLeave: () => {
341
+ if (!tapPinnedRef.current) setShowTooltip(false);
342
+ },
343
+ onClick: (e) => {
344
+ if (stopClickPropagation) e.stopPropagation();
345
+ if (onClick) {
346
+ onClick();
347
+ }
348
+ if (!tapEnabled || !content) return;
349
+ updateTooltipPosition();
350
+ if (tapPinnedRef.current) {
351
+ closeTooltip();
352
+ return;
353
+ }
354
+ tapPinnedRef.current = true;
355
+ setShowTooltip(true);
356
+ },
357
+ onFocus: () => {
358
+ updateTooltipPosition();
359
+ setShowTooltip(true);
360
+ },
361
+ onBlur: closeTooltip,
362
+ style
363
+ };
364
+ if (triggerAs === "span") {
365
+ const handleKeyDown = (event) => {
366
+ if (!tapEnabled || !content) return;
367
+ if (event.key !== "Enter" && event.key !== " ") return;
368
+ event.preventDefault();
369
+ updateTooltipPosition();
370
+ if (tapPinnedRef.current) {
371
+ closeTooltip();
372
+ return;
373
+ }
374
+ tapPinnedRef.current = true;
375
+ setShowTooltip(true);
376
+ };
377
+ const spanInteractionProps = {
378
+ ...sharedProps,
379
+ role: tapEnabled && content ? "button" : void 0,
380
+ tabIndex: tapEnabled && content ? 0 : void 0,
381
+ onKeyDown: tapEnabled && content ? handleKeyDown : void 0
382
+ };
383
+ return /* @__PURE__ */ jsx4(
384
+ "span",
385
+ {
386
+ ref: (node) => {
387
+ triggerRef.current = node;
388
+ },
389
+ ...spanInteractionProps,
390
+ children: contentNode
391
+ }
392
+ );
393
+ }
394
+ return /* @__PURE__ */ jsx4(
395
+ "button",
396
+ {
397
+ ref: (node) => {
398
+ triggerRef.current = node;
399
+ },
400
+ type: "button",
401
+ "aria-label": ariaLabel,
402
+ "aria-describedby": content && showTooltip ? tooltipId : void 0,
403
+ className: triggerClassName,
404
+ onMouseEnter: sharedProps.onMouseEnter,
405
+ onMouseLeave: sharedProps.onMouseLeave,
406
+ onClick: sharedProps.onClick,
407
+ onFocus: sharedProps.onFocus,
408
+ onBlur: sharedProps.onBlur,
409
+ style,
410
+ children: contentNode
411
+ }
412
+ );
413
+ };
414
+
415
+ // src/compositions/CopyButton.tsx
416
+ import { jsx as jsx5 } from "react/jsx-runtime";
417
+ function CopyButton({
418
+ value,
419
+ children,
420
+ copiedTimeoutMs = 2e3,
421
+ tooltip = "\u{1F4CB} Click to copy",
422
+ tooltipAlign,
423
+ tooltipClampToViewport,
424
+ tooltipMaxWidth,
425
+ copiedTooltip = "\u2705 Copied!",
426
+ tooltipClassName,
427
+ className,
428
+ variant = "plain",
429
+ intent,
430
+ onCopied,
431
+ onCopyError,
432
+ ...buttonProps
433
+ }) {
434
+ const [copied, setCopied] = useState2(false);
435
+ const timeoutRef = useRef2(null);
436
+ useEffect2(
437
+ () => () => {
438
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
439
+ },
440
+ []
441
+ );
442
+ async function handleCopy(event) {
443
+ event.stopPropagation();
444
+ try {
445
+ const text = typeof value === "function" ? await value() : value;
446
+ await navigator.clipboard.writeText(text);
447
+ setCopied(true);
448
+ onCopied?.();
449
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
450
+ timeoutRef.current = setTimeout(
451
+ () => setCopied(false),
452
+ copiedTimeoutMs
453
+ );
454
+ } catch (error) {
455
+ onCopyError?.(error);
456
+ }
457
+ }
458
+ const Control = variant === "button" ? Button : "button";
459
+ const button = /* @__PURE__ */ jsx5(
460
+ Control,
461
+ {
462
+ ...buttonProps,
463
+ ...variant === "button" && intent ? { intent } : {},
464
+ type: "button",
465
+ onClick: handleCopy,
466
+ className: cn(
467
+ "polli-control",
468
+ buttonProps.disabled ? "polli:cursor-not-allowed" : "polli:cursor-pointer",
469
+ typeof className === "function" ? className(copied) : className
470
+ ),
471
+ children: typeof children === "function" ? children(copied) : children
472
+ }
473
+ );
474
+ if (tooltip === null) {
475
+ return button;
476
+ }
477
+ return /* @__PURE__ */ jsx5(
478
+ Tooltip,
479
+ {
480
+ triggerAs: "span",
481
+ content: copied ? copiedTooltip : tooltip,
482
+ align: tooltipAlign,
483
+ clampToViewport: tooltipClampToViewport,
484
+ maxWidth: tooltipMaxWidth,
485
+ displayContents: true,
486
+ tapEnabled: false,
487
+ className: cn(
488
+ buttonProps.disabled ? "polli:cursor-not-allowed" : "polli:cursor-pointer",
489
+ tooltipClassName
490
+ ),
491
+ children: button
492
+ }
493
+ );
494
+ }
495
+
496
+ // src/compositions/CodeBlock.tsx
497
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
498
+ var CodeBlock = ({
499
+ code,
500
+ codeClassName,
501
+ language,
502
+ className,
503
+ ...rest
504
+ }) => {
505
+ const label = language || "Code";
506
+ return /* @__PURE__ */ jsxs5(
507
+ "div",
508
+ {
509
+ ...rest,
510
+ className: cn(
511
+ "polli:min-w-0 polli:max-w-full polli:overflow-hidden polli:rounded-lg polli:border polli:border-theme-border polli:bg-theme-bg-pale",
512
+ className
513
+ ),
514
+ children: [
515
+ /* @__PURE__ */ jsxs5("div", { className: "polli:flex polli:min-h-9 polli:items-center polli:justify-between polli:gap-3 polli:bg-theme-bg-subtle polli:px-3 polli:py-1.5", children: [
516
+ /* @__PURE__ */ jsx6("span", { className: "polli:truncate polli:font-mono polli:text-[11px] polli:font-medium polli:uppercase polli:tracking-wide polli:text-theme-text-muted", children: label }),
517
+ /* @__PURE__ */ jsx6(
518
+ CopyButton,
519
+ {
520
+ value: code,
521
+ tooltip: null,
522
+ "aria-label": "Copy code",
523
+ className: "polli:flex polli:items-center polli:gap-1.5 polli:rounded-md polli:px-2 polli:py-1 polli:text-xs polli:font-medium polli:text-theme-text-base polli:transition-colors polli:hover:bg-theme-bg-hover polli:hover:text-theme-text-hover",
524
+ children: (copied) => /* @__PURE__ */ jsxs5(Fragment2, { children: [
525
+ copied ? /* @__PURE__ */ jsx6(CheckIcon, { className: "polli:size-3.5" }) : /* @__PURE__ */ jsx6(ClipboardIcon, { className: "polli:size-3.5" }),
526
+ /* @__PURE__ */ jsx6("span", { children: copied ? "Copied" : "Copy" })
527
+ ] })
528
+ }
529
+ )
530
+ ] }),
531
+ /* @__PURE__ */ jsx6(
532
+ "pre",
533
+ {
534
+ className: cn(
535
+ "polli:m-0 polli:min-w-0 polli:whitespace-pre-wrap polli:break-words polli:[overflow-wrap:anywhere] polli:[tab-size:4] polli:p-3 polli:font-mono polli:text-xs polli:leading-6 polli:text-theme-text-strong",
536
+ codeClassName
537
+ ),
538
+ children: /* @__PURE__ */ jsx6("code", { children: code })
539
+ }
540
+ )
541
+ ]
542
+ }
543
+ );
544
+ };
545
+
546
+ // src/compositions/Markdown.tsx
547
+ import { jsx as jsx7 } from "react/jsx-runtime";
548
+ function textContent(value) {
549
+ if (typeof value === "string" || typeof value === "number") {
550
+ return String(value);
551
+ }
552
+ if (Array.isArray(value)) return value.map(textContent).join("");
553
+ if (isValidElement(value)) {
554
+ return textContent(value.props.children);
555
+ }
556
+ return "";
557
+ }
558
+ var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set(["m4v", "mov", "mp4", "webm"]);
559
+ var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set([
560
+ "aac",
561
+ "flac",
562
+ "m4a",
563
+ "mp3",
564
+ "ogg",
565
+ "opus",
566
+ "wav"
567
+ ]);
568
+ function urlExtension(src) {
569
+ const path = src.split(/[?#]/, 1)[0];
570
+ return path.split(".").pop()?.toLowerCase() ?? "";
571
+ }
572
+ function inlineMedia(src, label) {
573
+ if (!src) return null;
574
+ const extension = urlExtension(src);
575
+ const video = VIDEO_EXTENSIONS.has(extension) || label === "Generated video";
576
+ const audio = AUDIO_EXTENSIONS.has(extension) || label === "Generated audio";
577
+ if (!video && !audio) return null;
578
+ const Element = video ? "video" : "audio";
579
+ return /* @__PURE__ */ jsx7(
580
+ Element,
581
+ {
582
+ src,
583
+ "aria-label": label,
584
+ controls: true,
585
+ playsInline: video || void 0,
586
+ preload: "metadata",
587
+ className: "polli:max-w-full polli:rounded-lg"
588
+ }
589
+ );
590
+ }
591
+ function MarkdownCodeBlock({ children }) {
592
+ const child = isValidElement(children) ? children : null;
593
+ const language = child?.props.className?.match(/language-([^\s]+)/)?.[1];
594
+ const code = textContent(child?.props.children ?? children).replace(
595
+ /\n$/,
596
+ ""
597
+ );
598
+ return /* @__PURE__ */ jsx7(CodeBlock, { code, language, className: "polli:my-3" });
599
+ }
600
+ var components = {
601
+ ul: ({ node, ...props }) => /* @__PURE__ */ jsx7(
602
+ "ul",
603
+ {
604
+ className: "polli:flex polli:min-w-0 polli:list-disc polli:flex-col polli:gap-1 polli:pl-5 polli:marker:text-theme-text-muted",
605
+ ...props
606
+ }
607
+ ),
608
+ ol: ({ node, ...props }) => /* @__PURE__ */ jsx7(
609
+ "ol",
610
+ {
611
+ className: "polli:flex polli:min-w-0 polli:list-decimal polli:flex-col polli:gap-1 polli:pl-5 polli:marker:text-theme-text-muted",
612
+ ...props
613
+ }
614
+ ),
615
+ p: ({ node, ...props }) => /* @__PURE__ */ jsx7("p", { className: "polli:mb-2 polli:last:mb-0", ...props }),
616
+ strong: ({ node, ...props }) => /* @__PURE__ */ jsx7(
617
+ "strong",
618
+ {
619
+ className: "polli:font-semibold polli:text-theme-text-strong",
620
+ ...props
621
+ }
622
+ ),
623
+ code: ({ node, ...props }) => /* @__PURE__ */ jsx7(
624
+ "code",
625
+ {
626
+ className: "polli:break-words polli:rounded polli:bg-theme-bg-subtle polli:px-1 polli:py-0.5 polli:font-mono polli:text-xs",
627
+ ...props
628
+ }
629
+ ),
630
+ pre: ({ children }) => /* @__PURE__ */ jsx7(MarkdownCodeBlock, { children }),
631
+ img: ({ node, src, alt, ...props }) => {
632
+ const media = inlineMedia(
633
+ typeof src === "string" ? src : void 0,
634
+ alt
635
+ );
636
+ if (media) return media;
637
+ return /* @__PURE__ */ jsx7(
638
+ "img",
639
+ {
640
+ src,
641
+ alt,
642
+ loading: "lazy",
643
+ className: "polli:max-w-full polli:rounded-lg",
644
+ ...props
645
+ }
646
+ );
647
+ },
648
+ a: ({ node, href, ...props }) => {
649
+ const media = inlineMedia(href, textContent(props.children));
650
+ if (media) return media;
651
+ return /* @__PURE__ */ jsx7(InlineLink, { href, ...props });
652
+ }
653
+ };
654
+ function Markdown({ children, className }) {
655
+ return /* @__PURE__ */ jsx7(
656
+ "div",
657
+ {
658
+ className: cn(
659
+ "polli:min-w-0 polli:font-body polli:leading-relaxed",
660
+ className
661
+ ),
662
+ children: /* @__PURE__ */ jsx7(ReactMarkdown, { remarkPlugins: [remarkGfm], components, children })
663
+ }
664
+ );
665
+ }
666
+
667
+ // src/compositions/Prose.tsx
668
+ import Markdown2 from "react-markdown";
669
+ import rehypeSlug from "rehype-slug";
670
+ import remarkGfm2 from "remark-gfm";
671
+
672
+ // src/primitives/Typography.tsx
673
+ import { jsx as jsx8 } from "react/jsx-runtime";
674
+ var headingSizeClasses = {
675
+ display: "polli:font-heading polli:text-5xl polli:leading-none",
676
+ title: "polli:font-heading polli:text-4xl polli:leading-none",
677
+ section: "polli:font-subheading polli:text-2xl polli:leading-tight",
678
+ subsection: "polli:font-subheading polli:text-xl polli:leading-tight",
679
+ card: "polli:font-subheading polli:text-lg polli:leading-tight"
680
+ };
681
+ function headingClassName(size, className) {
682
+ return cn(
683
+ "polli:break-words polli:text-theme-text-strong",
684
+ headingSizeClasses[size],
685
+ className
686
+ );
687
+ }
688
+
689
+ // src/compositions/Prose.tsx
690
+ import { jsx as jsx9 } from "react/jsx-runtime";
691
+ var components2 = {
692
+ h1: ({ node, ...props }) => /* @__PURE__ */ jsx9(
693
+ "h1",
694
+ {
695
+ className: headingClassName("title", "polli:mt-0 polli:mb-5"),
696
+ ...props
697
+ }
698
+ ),
699
+ h2: ({ node, ...props }) => /* @__PURE__ */ jsx9(
700
+ "h2",
701
+ {
702
+ className: headingClassName("section", "polli:mt-8 polli:mb-3"),
703
+ ...props
704
+ }
705
+ ),
706
+ h3: ({ node, ...props }) => /* @__PURE__ */ jsx9(
707
+ "h3",
708
+ {
709
+ className: headingClassName("subsection", "polli:mt-6 polli:mb-2"),
710
+ ...props
711
+ }
712
+ ),
713
+ p: ({ node, ...props }) => /* @__PURE__ */ jsx9("p", { className: "polli:my-4 polli:leading-relaxed", ...props }),
714
+ a: ({ node, ...props }) => /* @__PURE__ */ jsx9(InlineLink, { ...props }),
715
+ ul: ({ node, ...props }) => /* @__PURE__ */ jsx9(
716
+ "ul",
717
+ {
718
+ className: "polli:my-4 polli:list-disc polli:pl-6 polli:leading-relaxed",
719
+ ...props
720
+ }
721
+ ),
722
+ ol: ({ node, ...props }) => /* @__PURE__ */ jsx9(
723
+ "ol",
724
+ {
725
+ className: "polli:my-4 polli:list-decimal polli:pl-6 polli:leading-relaxed",
726
+ ...props
727
+ }
728
+ ),
729
+ blockquote: ({ node, ...props }) => /* @__PURE__ */ jsx9(
730
+ "blockquote",
731
+ {
732
+ className: "polli:my-4 polli:border-l-4 polli:border-theme-border polli:pl-4 polli:text-theme-text-soft",
733
+ ...props
734
+ }
735
+ ),
736
+ code: ({ node, ...props }) => /* @__PURE__ */ jsx9(
737
+ "code",
738
+ {
739
+ className: "polli:rounded polli:bg-theme-bg-active polli:px-1 polli:py-0.5 polli:font-pixel polli:text-sm",
740
+ ...props
741
+ }
742
+ ),
743
+ pre: ({ node, ...props }) => /* @__PURE__ */ jsx9(
744
+ "pre",
745
+ {
746
+ className: "polli:my-4 polli:overflow-x-auto polli:rounded-lg polli:bg-theme-bg-active polli:p-4",
747
+ ...props
748
+ }
749
+ ),
750
+ table: ({ node, ...props }) => /* @__PURE__ */ jsx9(
751
+ "table",
752
+ {
753
+ className: "polli:my-4 polli:w-full polli:border-collapse polli:text-sm",
754
+ ...props
755
+ }
756
+ ),
757
+ th: ({ node, ...props }) => /* @__PURE__ */ jsx9(
758
+ "th",
759
+ {
760
+ className: "polli:border polli:border-theme-border polli:px-3 polli:py-2 polli:text-left polli:font-semibold",
761
+ ...props
762
+ }
763
+ ),
764
+ td: ({ node, ...props }) => /* @__PURE__ */ jsx9(
765
+ "td",
766
+ {
767
+ className: "polli:border polli:border-theme-border polli:px-3 polli:py-2",
768
+ ...props
769
+ }
770
+ ),
771
+ hr: ({ node, ...props }) => /* @__PURE__ */ jsx9("hr", { className: "polli:my-6 polli:border-theme-border", ...props })
772
+ };
773
+ function Prose({ children, className }) {
774
+ return /* @__PURE__ */ jsx9(
775
+ "div",
776
+ {
777
+ className: cn(
778
+ "polli:font-body polli:text-theme-text-base polli:leading-relaxed",
779
+ className
780
+ ),
781
+ children: /* @__PURE__ */ jsx9(
782
+ Markdown2,
783
+ {
784
+ remarkPlugins: [remarkGfm2],
785
+ rehypePlugins: [rehypeSlug],
786
+ components: components2,
787
+ children
788
+ }
789
+ )
790
+ }
791
+ );
792
+ }
793
+ export {
794
+ Markdown,
795
+ Prose
796
+ };
797
+ //# sourceMappingURL=markdown.js.map