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

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