@pollinations/ui 0.0.1 → 0.1.0-alpha.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.
- package/README.md +25 -16
- package/dist/{Button-DMJ2K6Gr.d.ts → Button-BvLF_Km2.d.cts} +4 -4
- package/dist/{Button-CNzpisJf.d.cts → Button-DQAZzvyQ.d.ts} +4 -4
- package/dist/{Chip-BS8ronOu.d.ts → Chip-C5impfYd.d.ts} +2 -2
- package/dist/{Chip-DyqWrq0r.d.cts → Chip-SM52sUbZ.d.cts} +2 -2
- package/dist/app.css +1 -1
- package/dist/auth/index.cjs +78 -71
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +1 -2
- package/dist/auth/index.d.ts +1 -2
- package/dist/auth/index.js +78 -71
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/sdk.cjs +7 -6
- package/dist/auth/sdk.cjs.map +1 -1
- package/dist/auth/sdk.d.cts +2 -2
- package/dist/auth/sdk.d.ts +2 -2
- package/dist/auth/sdk.js +7 -6
- package/dist/auth/sdk.js.map +1 -1
- package/dist/compositions/app-user.cjs +497 -0
- package/dist/compositions/app-user.cjs.map +1 -0
- package/dist/compositions/app-user.d.cts +18 -0
- package/dist/compositions/app-user.d.ts +18 -0
- package/dist/compositions/app-user.js +469 -0
- package/dist/compositions/app-user.js.map +1 -0
- package/dist/index.cjs +1151 -312
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -13
- package/dist/index.d.ts +146 -13
- package/dist/index.js +1109 -295
- package/dist/index.js.map +1 -1
- package/dist/modality/index.cjs +27 -56
- package/dist/modality/index.cjs.map +1 -1
- package/dist/modality/index.d.cts +13 -32
- package/dist/modality/index.d.ts +13 -32
- package/dist/modality/index.js +27 -55
- package/dist/modality/index.js.map +1 -1
- package/dist/models/index.cjs +508 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +22 -0
- package/dist/models/index.d.ts +22 -0
- package/dist/models/index.js +486 -0
- package/dist/models/index.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/theme-VMRlhqST.d.cts +9 -0
- package/dist/theme-VMRlhqST.d.ts +9 -0
- package/dist/wallet/index.cjs +17 -5
- package/dist/wallet/index.cjs.map +1 -1
- package/dist/wallet/index.d.cts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +17 -5
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/sdk.cjs +6 -3
- package/dist/wallet/sdk.cjs.map +1 -1
- package/dist/wallet/sdk.js +6 -3
- package/dist/wallet/sdk.js.map +1 -1
- package/package.json +17 -10
- package/dist/showcase/index.cjs +0 -2851
- package/dist/showcase/index.cjs.map +0 -1
- package/dist/showcase/index.d.cts +0 -19
- package/dist/showcase/index.d.ts +0 -19
- package/dist/showcase/index.js +0 -2839
- package/dist/showcase/index.js.map +0 -1
- package/dist/theme-DfHMjWB7.d.cts +0 -16
- package/dist/theme-DfHMjWB7.d.ts +0 -16
- package/dist/wallet.css +0 -73
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
// src/compositions/app-user/AppUserMenu.tsx
|
|
2
|
+
import { useAuthActions as useAuthActions2 } from "@pollinations/sdk/react";
|
|
3
|
+
|
|
4
|
+
// src/modules/auth/LoginButton.tsx
|
|
5
|
+
import { useAuthActions, useAuthState } from "@pollinations/sdk/react";
|
|
6
|
+
|
|
7
|
+
// src/lib/cn.ts
|
|
8
|
+
import { clsx } from "clsx";
|
|
9
|
+
import { extendTailwindMerge } from "tailwind-merge";
|
|
10
|
+
var twMerge = extendTailwindMerge({ prefix: "polli" });
|
|
11
|
+
function cn(...inputs) {
|
|
12
|
+
return twMerge(clsx(...inputs));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/primitives/Button.tsx
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
var sizes = {
|
|
18
|
+
sm: "polli:px-2 polli:pt-0.5 polli:pb-1",
|
|
19
|
+
md: "polli:px-4 polli:pt-1.5 polli:pb-2",
|
|
20
|
+
lg: "polli:px-6 polli:py-3"
|
|
21
|
+
};
|
|
22
|
+
var themeClasses = "polli:bg-theme-bg-active polli:text-theme-text-base polli:hover:bg-theme-bg-hover polli:transition-colors";
|
|
23
|
+
var intentClasses = {
|
|
24
|
+
danger: "polli:bg-intent-danger-bg-light polli:text-intent-danger-text polli:hover:bg-intent-danger-bg-hover polli:transition-colors"
|
|
25
|
+
};
|
|
26
|
+
var buttonClasses = ({
|
|
27
|
+
theme: _theme,
|
|
28
|
+
intent,
|
|
29
|
+
size,
|
|
30
|
+
className,
|
|
31
|
+
disabled
|
|
32
|
+
}) => {
|
|
33
|
+
const colorClasses = intent ? intentClasses[intent] : themeClasses;
|
|
34
|
+
return cn(
|
|
35
|
+
"polli-control polli:inline-flex polli:items-center polli:justify-center polli:rounded-full polli:self-center polli:font-medium polli:leading-normal polli:box-border",
|
|
36
|
+
disabled ? "polli:opacity-50 polli:cursor-not-allowed" : "polli:hover:filter polli:hover:brightness-105 polli:cursor-pointer",
|
|
37
|
+
colorClasses,
|
|
38
|
+
sizes[size || "md"],
|
|
39
|
+
className
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
function Button({
|
|
43
|
+
as,
|
|
44
|
+
children,
|
|
45
|
+
theme,
|
|
46
|
+
intent,
|
|
47
|
+
size,
|
|
48
|
+
className,
|
|
49
|
+
disabled,
|
|
50
|
+
...buttonProps
|
|
51
|
+
}) {
|
|
52
|
+
const Component = as || "button";
|
|
53
|
+
return /* @__PURE__ */ jsx(
|
|
54
|
+
Component,
|
|
55
|
+
{
|
|
56
|
+
"data-theme": intent ? void 0 : theme,
|
|
57
|
+
"data-intent": intent,
|
|
58
|
+
className: buttonClasses({
|
|
59
|
+
theme,
|
|
60
|
+
intent,
|
|
61
|
+
size,
|
|
62
|
+
className,
|
|
63
|
+
disabled
|
|
64
|
+
}),
|
|
65
|
+
disabled,
|
|
66
|
+
...buttonProps,
|
|
67
|
+
children
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/modules/auth/LoginButton.tsx
|
|
73
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
74
|
+
function LoginButton({ children, ...buttonProps }) {
|
|
75
|
+
const { isLoggedIn } = useAuthState();
|
|
76
|
+
const { login } = useAuthActions();
|
|
77
|
+
if (isLoggedIn) return null;
|
|
78
|
+
return /* @__PURE__ */ jsx2(Button, { ...buttonProps, onClick: () => login(), children });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/modules/auth/UserAvatar.tsx
|
|
82
|
+
import { useAccountProfile, useAuthState as useAuthState2 } from "@pollinations/sdk/react";
|
|
83
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
84
|
+
var sizeClass = {
|
|
85
|
+
sm: "polli:w-6 polli:h-6 polli:text-xs",
|
|
86
|
+
md: "polli:w-9 polli:h-9 polli:text-sm",
|
|
87
|
+
lg: "polli:w-12 polli:h-12 polli:text-base"
|
|
88
|
+
};
|
|
89
|
+
function initials(name) {
|
|
90
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
91
|
+
if (parts.length === 0) return null;
|
|
92
|
+
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase() || null;
|
|
93
|
+
const first = parts[0][0] ?? "";
|
|
94
|
+
const last = parts[parts.length - 1][0] ?? "";
|
|
95
|
+
return (first + last).toUpperCase() || null;
|
|
96
|
+
}
|
|
97
|
+
function UserAvatar({ size = "md", className }) {
|
|
98
|
+
const { isLoggedIn } = useAuthState2();
|
|
99
|
+
const { data: profile } = useAccountProfile({ enabled: isLoggedIn });
|
|
100
|
+
if (!isLoggedIn) return null;
|
|
101
|
+
const base = cn(
|
|
102
|
+
"polli:inline-flex polli:items-center polli:justify-center polli:rounded-full polli:overflow-hidden polli:bg-theme-bg-pale polli:text-theme-text-strong polli:font-semibold polli:select-none",
|
|
103
|
+
sizeClass[size],
|
|
104
|
+
className
|
|
105
|
+
);
|
|
106
|
+
if (profile?.image) {
|
|
107
|
+
return /* @__PURE__ */ jsx3(
|
|
108
|
+
"img",
|
|
109
|
+
{
|
|
110
|
+
"data-polli": "user-avatar",
|
|
111
|
+
src: profile.image,
|
|
112
|
+
alt: profile.name ?? "",
|
|
113
|
+
className: base
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const label = profile?.name ? initials(profile.name) : null;
|
|
118
|
+
if (!label) return null;
|
|
119
|
+
return /* @__PURE__ */ jsx3(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
"data-polli": "user-avatar",
|
|
123
|
+
role: "img",
|
|
124
|
+
"aria-label": profile?.name ?? void 0,
|
|
125
|
+
className: base,
|
|
126
|
+
children: label
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/modules/auth/UserName.tsx
|
|
132
|
+
import { useAccountProfile as useAccountProfile2, useAuthState as useAuthState3 } from "@pollinations/sdk/react";
|
|
133
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
134
|
+
function UserName({ className }) {
|
|
135
|
+
const { isLoggedIn } = useAuthState3();
|
|
136
|
+
const { data: profile } = useAccountProfile2({ enabled: isLoggedIn });
|
|
137
|
+
if (!isLoggedIn || !profile) return null;
|
|
138
|
+
const display = profile.name || profile.githubUsername;
|
|
139
|
+
if (!display) return null;
|
|
140
|
+
return /* @__PURE__ */ jsx4("span", { "data-polli": "user-name", className, children: display });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/modules/auth/WhenLoggedIn.tsx
|
|
144
|
+
import { useAuthState as useAuthState4 } from "@pollinations/sdk/react";
|
|
145
|
+
import { Fragment } from "react";
|
|
146
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
147
|
+
function WhenLoggedIn({ children }) {
|
|
148
|
+
const { isLoggedIn } = useAuthState4();
|
|
149
|
+
if (!isLoggedIn) return null;
|
|
150
|
+
return /* @__PURE__ */ jsx5(Fragment, { children });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/modules/auth/WhenLoggedOut.tsx
|
|
154
|
+
import { useAuthState as useAuthState5 } from "@pollinations/sdk/react";
|
|
155
|
+
import { Fragment as Fragment2 } from "react";
|
|
156
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
157
|
+
function WhenLoggedOut({ children }) {
|
|
158
|
+
const { isLoggedIn } = useAuthState5();
|
|
159
|
+
if (isLoggedIn) return null;
|
|
160
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/modules/wallet/Balance.tsx
|
|
164
|
+
import { useAccountBalance, useAuthState as useAuthState6 } from "@pollinations/sdk/react";
|
|
165
|
+
|
|
166
|
+
// src/primitives/Chip.tsx
|
|
167
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
168
|
+
var chipSizes = {
|
|
169
|
+
sm: "polli:px-2 polli:py-0.5 polli:text-xs",
|
|
170
|
+
md: "polli:px-2.5 polli:py-0.5 polli:text-sm",
|
|
171
|
+
lg: "polli:px-3 polli:py-1 polli:text-sm"
|
|
172
|
+
};
|
|
173
|
+
var intentClasses2 = {
|
|
174
|
+
news: "polli:bg-intent-news-bg-light polli:text-intent-news-text",
|
|
175
|
+
alpha: "polli:bg-intent-alpha-bg-light polli:text-intent-alpha-text",
|
|
176
|
+
neutral: "polli:border polli:border-gray-400/70 polli:bg-gray-100/80 polli:text-gray-900",
|
|
177
|
+
success: "polli:border polli:border-intent-success-border polli:bg-intent-success-bg-light polli:text-intent-success-text",
|
|
178
|
+
warning: "polli:border polli:border-intent-warning-border polli:bg-intent-warning-bg-light polli:text-intent-warning-text",
|
|
179
|
+
danger: "polli:border polli:border-intent-danger-border polli:bg-intent-danger-bg-light polli:text-intent-danger-text"
|
|
180
|
+
};
|
|
181
|
+
var Chip = ({
|
|
182
|
+
theme,
|
|
183
|
+
intent,
|
|
184
|
+
size = "md",
|
|
185
|
+
className,
|
|
186
|
+
children,
|
|
187
|
+
...rest
|
|
188
|
+
}) => {
|
|
189
|
+
const intentClass = intent ? intentClasses2[intent] : "polli:bg-theme-bg-active polli:text-theme-text-strong";
|
|
190
|
+
return /* @__PURE__ */ jsx7(
|
|
191
|
+
"span",
|
|
192
|
+
{
|
|
193
|
+
...rest,
|
|
194
|
+
"data-theme": theme,
|
|
195
|
+
className: cn(
|
|
196
|
+
"polli:inline-flex polli:shrink-0 polli:items-center polli:gap-1 polli:rounded-lg polli:font-medium polli:leading-normal",
|
|
197
|
+
chipSizes[size],
|
|
198
|
+
intentClass,
|
|
199
|
+
className
|
|
200
|
+
),
|
|
201
|
+
children
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/modules/wallet/format-pollen.ts
|
|
207
|
+
var BUDGET = 5;
|
|
208
|
+
var MAX_DECIMALS = 4;
|
|
209
|
+
var COMPACT_THRESHOLD = 1e5;
|
|
210
|
+
function floorTo(value, decimals) {
|
|
211
|
+
const factor = 10 ** decimals;
|
|
212
|
+
return Math.floor(value * factor) / factor;
|
|
213
|
+
}
|
|
214
|
+
function formatCompact(value) {
|
|
215
|
+
const abs = Math.abs(value);
|
|
216
|
+
const sign = value < 0 ? "-" : "";
|
|
217
|
+
const [unit, scale] = abs >= 1e9 ? ["B", 1e9] : abs >= 1e6 ? ["M", 1e6] : ["K", 1e3];
|
|
218
|
+
const ratio = abs / scale;
|
|
219
|
+
const intDigits = Math.max(1, Math.floor(Math.log10(ratio)) + 1);
|
|
220
|
+
const decimals = Math.max(0, 3 - intDigits);
|
|
221
|
+
const floored = floorTo(ratio, decimals);
|
|
222
|
+
return `${sign}${Number(floored.toFixed(decimals)).toString()}${unit}`;
|
|
223
|
+
}
|
|
224
|
+
function formatPollen(value) {
|
|
225
|
+
if (!Number.isFinite(value) || value === 0) return "0";
|
|
226
|
+
const abs = Math.abs(value);
|
|
227
|
+
if (abs >= COMPACT_THRESHOLD) return formatCompact(value);
|
|
228
|
+
const intDigits = abs >= 1 ? Math.floor(Math.log10(abs)) + 1 : 1;
|
|
229
|
+
const decimals = Math.min(MAX_DECIMALS, Math.max(0, BUDGET - intDigits));
|
|
230
|
+
const floored = floorTo(value, decimals);
|
|
231
|
+
if (floored === 0) return "0";
|
|
232
|
+
return Number(floored.toFixed(decimals)).toString();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/modules/wallet/Balance.tsx
|
|
236
|
+
import { jsxs } from "react/jsx-runtime";
|
|
237
|
+
function Balance({ className } = {}) {
|
|
238
|
+
const { isLoggedIn } = useAuthState6();
|
|
239
|
+
const { data: balance } = useAccountBalance({ enabled: isLoggedIn });
|
|
240
|
+
if (!isLoggedIn || balance == null) return null;
|
|
241
|
+
return /* @__PURE__ */ jsxs(
|
|
242
|
+
Chip,
|
|
243
|
+
{
|
|
244
|
+
"data-polli": "balance",
|
|
245
|
+
className: cn("polli:tabular-nums", className),
|
|
246
|
+
children: [
|
|
247
|
+
formatPollen(balance.balance),
|
|
248
|
+
" pollen"
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/primitives/ChevronIcon.tsx
|
|
255
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
256
|
+
var ChevronIcon = ({ expanded, className }) => /* @__PURE__ */ jsx8(
|
|
257
|
+
"svg",
|
|
258
|
+
{
|
|
259
|
+
"aria-hidden": "true",
|
|
260
|
+
width: "12",
|
|
261
|
+
height: "12",
|
|
262
|
+
viewBox: "0 0 12 12",
|
|
263
|
+
className: cn(
|
|
264
|
+
"polli:shrink-0 polli:transition-transform polli:duration-200 polli:ease-out",
|
|
265
|
+
expanded && "polli:rotate-180",
|
|
266
|
+
className
|
|
267
|
+
),
|
|
268
|
+
children: /* @__PURE__ */ jsx8(
|
|
269
|
+
"path",
|
|
270
|
+
{
|
|
271
|
+
d: "M3 4.5 6 7.5l3-3",
|
|
272
|
+
fill: "none",
|
|
273
|
+
stroke: "currentColor",
|
|
274
|
+
strokeLinecap: "round",
|
|
275
|
+
strokeLinejoin: "round",
|
|
276
|
+
strokeWidth: "1.5"
|
|
277
|
+
}
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
// src/primitives/Dropdown.tsx
|
|
283
|
+
import { Popover } from "@ark-ui/react/popover";
|
|
284
|
+
import { Portal } from "@ark-ui/react/portal";
|
|
285
|
+
import { useState } from "react";
|
|
286
|
+
import { jsx as jsx9, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
287
|
+
var DEFAULT_PANEL = "polli:rounded-lg polli:border polli:border-theme-border polli:bg-theme-bg-pale polli:shadow-lg";
|
|
288
|
+
var Dropdown = ({
|
|
289
|
+
theme,
|
|
290
|
+
trigger,
|
|
291
|
+
children,
|
|
292
|
+
align = "start",
|
|
293
|
+
open: openProp,
|
|
294
|
+
onOpenChange,
|
|
295
|
+
className
|
|
296
|
+
}) => {
|
|
297
|
+
const [internalOpen, setInternalOpen] = useState(false);
|
|
298
|
+
const isControlled = openProp !== void 0;
|
|
299
|
+
const open = isControlled ? openProp : internalOpen;
|
|
300
|
+
const setOpen = (next) => {
|
|
301
|
+
if (!isControlled) setInternalOpen(next);
|
|
302
|
+
onOpenChange?.(next);
|
|
303
|
+
};
|
|
304
|
+
return /* @__PURE__ */ jsxs2(
|
|
305
|
+
Popover.Root,
|
|
306
|
+
{
|
|
307
|
+
open,
|
|
308
|
+
onOpenChange: (details) => setOpen(details.open),
|
|
309
|
+
positioning: {
|
|
310
|
+
placement: align === "end" ? "bottom-end" : "bottom-start"
|
|
311
|
+
},
|
|
312
|
+
children: [
|
|
313
|
+
/* @__PURE__ */ jsx9(Popover.Trigger, { asChild: true, children: trigger(open) }),
|
|
314
|
+
/* @__PURE__ */ jsx9(Portal, { children: /* @__PURE__ */ jsx9(Popover.Positioner, { children: /* @__PURE__ */ jsx9(
|
|
315
|
+
Popover.Content,
|
|
316
|
+
{
|
|
317
|
+
"data-theme": theme,
|
|
318
|
+
className: cn(
|
|
319
|
+
"polli:z-50 polli:overflow-hidden polli:focus:outline-none",
|
|
320
|
+
DEFAULT_PANEL,
|
|
321
|
+
className
|
|
322
|
+
),
|
|
323
|
+
children: typeof children === "function" ? children(() => setOpen(false)) : children
|
|
324
|
+
}
|
|
325
|
+
) }) })
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/primitives/DropdownItem.tsx
|
|
332
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
333
|
+
function DropdownItem({
|
|
334
|
+
as,
|
|
335
|
+
className,
|
|
336
|
+
children,
|
|
337
|
+
...rest
|
|
338
|
+
}) {
|
|
339
|
+
const Component = as || "button";
|
|
340
|
+
return /* @__PURE__ */ jsx10(
|
|
341
|
+
Component,
|
|
342
|
+
{
|
|
343
|
+
...Component === "button" ? { type: "button" } : void 0,
|
|
344
|
+
...rest,
|
|
345
|
+
className: cn(
|
|
346
|
+
"polli-control polli:flex polli:w-full polli:cursor-pointer polli:items-center polli:gap-2 polli:rounded-lg polli:bg-transparent polli:px-3 polli:py-2 polli:text-left polli:text-sm polli:font-medium polli:text-theme-text-base polli:no-underline polli:transition-colors polli:hover:bg-theme-bg-hover polli:focus-visible:bg-theme-bg-hover",
|
|
347
|
+
className
|
|
348
|
+
),
|
|
349
|
+
children
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/compositions/app-user/AppUserMenu.tsx
|
|
355
|
+
import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
356
|
+
var defaultLabels = {
|
|
357
|
+
authorize: "Authorize app",
|
|
358
|
+
appUserMenu: "App user menu",
|
|
359
|
+
topUpAccount: "Top up account",
|
|
360
|
+
logout: "Log out from this app"
|
|
361
|
+
};
|
|
362
|
+
function isEmbeddedContext(embedQueryParam = "embed") {
|
|
363
|
+
if (typeof window === "undefined") return false;
|
|
364
|
+
const search = new URLSearchParams(window.location.search);
|
|
365
|
+
if (search.get(embedQueryParam) === "1") return true;
|
|
366
|
+
try {
|
|
367
|
+
return window.self !== window.top;
|
|
368
|
+
} catch {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function AppUserMenu({
|
|
373
|
+
dashboardHref,
|
|
374
|
+
labels: labelOverrides,
|
|
375
|
+
hiddenWhenEmbedded = false,
|
|
376
|
+
embedQueryParam = "embed"
|
|
377
|
+
}) {
|
|
378
|
+
if (hiddenWhenEmbedded && isEmbeddedContext(embedQueryParam)) return null;
|
|
379
|
+
return /* @__PURE__ */ jsx11(
|
|
380
|
+
AppUserMenuContent,
|
|
381
|
+
{
|
|
382
|
+
dashboardHref,
|
|
383
|
+
labels: labelOverrides
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
function AppUserMenuContent({
|
|
388
|
+
dashboardHref,
|
|
389
|
+
labels: labelOverrides
|
|
390
|
+
}) {
|
|
391
|
+
const labels = { ...defaultLabels, ...labelOverrides };
|
|
392
|
+
const { logout } = useAuthActions2();
|
|
393
|
+
return /* @__PURE__ */ jsxs3("div", { "data-theme": "amber", className: "polli:flex polli:justify-end", children: [
|
|
394
|
+
/* @__PURE__ */ jsx11(WhenLoggedOut, { children: /* @__PURE__ */ jsx11(LoginButton, { theme: "amber", children: labels.authorize }) }),
|
|
395
|
+
/* @__PURE__ */ jsx11(WhenLoggedIn, { children: /* @__PURE__ */ jsx11(
|
|
396
|
+
Dropdown,
|
|
397
|
+
{
|
|
398
|
+
theme: "amber",
|
|
399
|
+
align: "end",
|
|
400
|
+
className: "polli:w-64 polli:p-1",
|
|
401
|
+
trigger: (open) => /* @__PURE__ */ jsxs3(
|
|
402
|
+
"button",
|
|
403
|
+
{
|
|
404
|
+
type: "button",
|
|
405
|
+
"data-theme": "amber",
|
|
406
|
+
"aria-label": labels.appUserMenu,
|
|
407
|
+
className: "polli-control polli:flex polli:min-w-0 polli:items-center polli:gap-2 polli:rounded-full polli:bg-theme-bg-active polli:py-1 polli:pl-1 polli:pr-3 polli:text-theme-text-base polli:shadow-sm polli:transition-colors polli:hover:bg-theme-bg-hover",
|
|
408
|
+
children: [
|
|
409
|
+
/* @__PURE__ */ jsx11(
|
|
410
|
+
UserAvatar,
|
|
411
|
+
{
|
|
412
|
+
size: "md",
|
|
413
|
+
className: "polli:h-8 polli:w-8"
|
|
414
|
+
}
|
|
415
|
+
),
|
|
416
|
+
/* @__PURE__ */ jsxs3("span", { className: "polli:flex polli:min-w-0 polli:flex-col polli:items-start polli:leading-tight", children: [
|
|
417
|
+
/* @__PURE__ */ jsx11(UserName, { className: "polli:max-w-32 polli:truncate polli:text-sm polli:font-semibold" }),
|
|
418
|
+
/* @__PURE__ */ jsx11(Balance, { className: "polli:bg-transparent polli:px-0 polli:py-0 polli:text-xs polli:text-theme-text-base" })
|
|
419
|
+
] }),
|
|
420
|
+
/* @__PURE__ */ jsx11(
|
|
421
|
+
ChevronIcon,
|
|
422
|
+
{
|
|
423
|
+
expanded: open,
|
|
424
|
+
className: "polli:h-4 polli:w-4 polli:text-theme-text-base"
|
|
425
|
+
}
|
|
426
|
+
)
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
),
|
|
430
|
+
children: (close) => /* @__PURE__ */ jsxs3(
|
|
431
|
+
"div",
|
|
432
|
+
{
|
|
433
|
+
"data-theme": "amber",
|
|
434
|
+
className: "polli:flex polli:flex-col",
|
|
435
|
+
children: [
|
|
436
|
+
/* @__PURE__ */ jsx11(
|
|
437
|
+
DropdownItem,
|
|
438
|
+
{
|
|
439
|
+
as: "a",
|
|
440
|
+
href: dashboardHref,
|
|
441
|
+
target: "_blank",
|
|
442
|
+
rel: "noopener noreferrer",
|
|
443
|
+
onClick: close,
|
|
444
|
+
children: labels.topUpAccount
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
/* @__PURE__ */ jsx11(
|
|
448
|
+
DropdownItem,
|
|
449
|
+
{
|
|
450
|
+
type: "button",
|
|
451
|
+
onClick: () => {
|
|
452
|
+
close();
|
|
453
|
+
logout();
|
|
454
|
+
},
|
|
455
|
+
children: labels.logout
|
|
456
|
+
}
|
|
457
|
+
)
|
|
458
|
+
]
|
|
459
|
+
}
|
|
460
|
+
)
|
|
461
|
+
}
|
|
462
|
+
) })
|
|
463
|
+
] });
|
|
464
|
+
}
|
|
465
|
+
export {
|
|
466
|
+
AppUserMenu,
|
|
467
|
+
isEmbeddedContext
|
|
468
|
+
};
|
|
469
|
+
//# sourceMappingURL=app-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/compositions/app-user/AppUserMenu.tsx","../../src/modules/auth/LoginButton.tsx","../../src/lib/cn.ts","../../src/primitives/Button.tsx","../../src/modules/auth/UserAvatar.tsx","../../src/modules/auth/UserName.tsx","../../src/modules/auth/WhenLoggedIn.tsx","../../src/modules/auth/WhenLoggedOut.tsx","../../src/modules/wallet/Balance.tsx","../../src/primitives/Chip.tsx","../../src/modules/wallet/format-pollen.ts","../../src/primitives/ChevronIcon.tsx","../../src/primitives/Dropdown.tsx","../../src/primitives/DropdownItem.tsx"],"sourcesContent":["import { useAuthActions } from \"@pollinations/sdk/react\";\nimport {\n LoginButton,\n UserAvatar,\n UserName,\n WhenLoggedIn,\n WhenLoggedOut,\n} from \"../../modules/auth/sdk.ts\";\nimport { Balance } from \"../../modules/wallet/sdk.ts\";\nimport { ChevronIcon } from \"../../primitives/ChevronIcon.tsx\";\nimport { Dropdown } from \"../../primitives/Dropdown.tsx\";\nimport { DropdownItem } from \"../../primitives/DropdownItem.tsx\";\n\nexport type AppUserMenuLabels = {\n authorize: string;\n appUserMenu: string;\n topUpAccount: string;\n logout: string;\n};\n\nexport type AppUserMenuProps = {\n dashboardHref: string;\n labels?: Partial<AppUserMenuLabels>;\n hiddenWhenEmbedded?: boolean;\n embedQueryParam?: string;\n};\n\nconst defaultLabels: AppUserMenuLabels = {\n authorize: \"Authorize app\",\n appUserMenu: \"App user menu\",\n topUpAccount: \"Top up account\",\n logout: \"Log out from this app\",\n};\n\nexport function isEmbeddedContext(embedQueryParam = \"embed\"): boolean {\n if (typeof window === \"undefined\") return false;\n const search = new URLSearchParams(window.location.search);\n if (search.get(embedQueryParam) === \"1\") return true;\n try {\n return window.self !== window.top;\n } catch {\n return true;\n }\n}\n\nexport function AppUserMenu({\n dashboardHref,\n labels: labelOverrides,\n hiddenWhenEmbedded = false,\n embedQueryParam = \"embed\",\n}: AppUserMenuProps) {\n if (hiddenWhenEmbedded && isEmbeddedContext(embedQueryParam)) return null;\n\n return (\n <AppUserMenuContent\n dashboardHref={dashboardHref}\n labels={labelOverrides}\n />\n );\n}\n\nfunction AppUserMenuContent({\n dashboardHref,\n labels: labelOverrides,\n}: Pick<AppUserMenuProps, \"dashboardHref\" | \"labels\">) {\n const labels = { ...defaultLabels, ...labelOverrides };\n const { logout } = useAuthActions();\n\n return (\n <div data-theme=\"amber\" className=\"polli:flex polli:justify-end\">\n <WhenLoggedOut>\n <LoginButton theme=\"amber\">{labels.authorize}</LoginButton>\n </WhenLoggedOut>\n\n <WhenLoggedIn>\n <Dropdown\n theme=\"amber\"\n align=\"end\"\n className=\"polli:w-64 polli:p-1\"\n trigger={(open) => (\n <button\n type=\"button\"\n data-theme=\"amber\"\n aria-label={labels.appUserMenu}\n className=\"polli-control polli:flex polli:min-w-0 polli:items-center polli:gap-2 polli:rounded-full polli:bg-theme-bg-active polli:py-1 polli:pl-1 polli:pr-3 polli:text-theme-text-base polli:shadow-sm polli:transition-colors polli:hover:bg-theme-bg-hover\"\n >\n <UserAvatar\n size=\"md\"\n className=\"polli:h-8 polli:w-8\"\n />\n <span className=\"polli:flex polli:min-w-0 polli:flex-col polli:items-start polli:leading-tight\">\n <UserName className=\"polli:max-w-32 polli:truncate polli:text-sm polli:font-semibold\" />\n <Balance className=\"polli:bg-transparent polli:px-0 polli:py-0 polli:text-xs polli:text-theme-text-base\" />\n </span>\n <ChevronIcon\n expanded={open}\n className=\"polli:h-4 polli:w-4 polli:text-theme-text-base\"\n />\n </button>\n )}\n >\n {(close) => (\n <div\n data-theme=\"amber\"\n className=\"polli:flex polli:flex-col\"\n >\n <DropdownItem\n as=\"a\"\n href={dashboardHref}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={close}\n >\n {labels.topUpAccount}\n </DropdownItem>\n <DropdownItem\n type=\"button\"\n onClick={() => {\n close();\n logout();\n }}\n >\n {labels.logout}\n </DropdownItem>\n </div>\n )}\n </Dropdown>\n </WhenLoggedIn>\n </div>\n );\n}\n","import { useAuthActions, useAuthState } from \"@pollinations/sdk/react\";\nimport type { ReactNode } from \"react\";\nimport { Button, type ButtonProps } from \"../../primitives/Button.tsx\";\n\nexport type LoginButtonProps = Omit<\n ButtonProps<\"button\">,\n \"as\" | \"onClick\" | \"children\"\n> & {\n children: ReactNode;\n};\n\n/** Button that kicks off the auth redirect. `null` when already logged in. */\nexport function LoginButton({ children, ...buttonProps }: LoginButtonProps) {\n const { isLoggedIn } = useAuthState();\n const { login } = useAuthActions();\n if (isLoggedIn) return null;\n return (\n <Button {...buttonProps} onClick={() => login()}>\n {children}\n </Button>\n );\n}\n","import { clsx } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({ prefix: \"polli\" });\n\n/** Internal class merge for polli:-prefixed package primitive classes. */\nexport function cn(...inputs: (string | undefined | null | false)[]) {\n return twMerge(clsx(...inputs));\n}\n","import type { PropsWithChildren } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\nimport type { ThemeName } from \"../theme.ts\";\n\n/** Button only supports `danger`. Label/status color recipes live on Chip. */\ntype ButtonIntent = \"danger\";\n\nconst sizes = {\n sm: \"polli:px-2 polli:pt-0.5 polli:pb-1\",\n md: \"polli:px-4 polli:pt-1.5 polli:pb-2\",\n lg: \"polli:px-6 polli:py-3\",\n} as const;\n\n// Cascade-driven base — reads [data-theme] vars.\nconst themeClasses =\n \"polli:bg-theme-bg-active polli:text-theme-text-base \" +\n \"polli:hover:bg-theme-bg-hover polli:transition-colors\";\n\n// Single intent: danger. Soft recipe — light tile + deep text, slightly\n// deeper bg on hover. No filled CTAs anywhere.\nconst intentClasses: Record<ButtonIntent, string> = {\n danger:\n \"polli:bg-intent-danger-bg-light polli:text-intent-danger-text \" +\n \"polli:hover:bg-intent-danger-bg-hover polli:transition-colors\",\n};\n\ntype BaseButtonProps = {\n /** Override the cascade theme for this button's subtree. Ignored when `intent` is set. */\n theme?: ThemeName;\n /** Only `\"danger\"` for now. */\n intent?: ButtonIntent;\n size?: keyof typeof sizes;\n className?: string;\n disabled?: boolean;\n};\n\nconst buttonClasses = ({\n theme: _theme,\n intent,\n size,\n className,\n disabled,\n}: BaseButtonProps & { disabled?: boolean }) => {\n const colorClasses = intent ? intentClasses[intent] : themeClasses;\n return cn(\n \"polli-control polli:inline-flex polli:items-center polli:justify-center polli:rounded-full polli:self-center polli:font-medium polli:leading-normal polli:box-border\",\n disabled\n ? \"polli:opacity-50 polli:cursor-not-allowed\"\n : \"polli:hover:filter polli:hover:brightness-105 polli:cursor-pointer\",\n colorClasses,\n sizes[size || \"md\"],\n className,\n );\n};\n\nexport type ButtonProps<T extends React.ElementType = \"button\"> =\n PropsWithChildren<BaseButtonProps> & {\n as?: T;\n } & Omit<React.ComponentPropsWithoutRef<T>, keyof BaseButtonProps | \"as\">;\n\nexport function Button<T extends React.ElementType = \"button\">({\n as,\n children,\n theme,\n intent,\n size,\n className,\n disabled,\n ...buttonProps\n}: ButtonProps<T>) {\n const Component: React.ElementType = as || \"button\";\n\n return (\n <Component\n // Cascade override only applies when `intent` is unset.\n data-theme={intent ? undefined : theme}\n data-intent={intent}\n className={buttonClasses({\n theme,\n intent,\n size,\n className,\n disabled,\n })}\n disabled={disabled}\n {...buttonProps}\n >\n {children}\n </Component>\n );\n}\n","import { useAccountProfile, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\n\nexport type UserAvatarProps = {\n size?: \"sm\" | \"md\" | \"lg\";\n className?: string;\n};\n\nconst sizeClass = {\n sm: \"polli:w-6 polli:h-6 polli:text-xs\",\n md: \"polli:w-9 polli:h-9 polli:text-sm\",\n lg: \"polli:w-12 polli:h-12 polli:text-base\",\n} as const;\n\nfunction initials(name: string): string | null {\n const parts = name.trim().split(/\\s+/).filter(Boolean);\n if (parts.length === 0) return null;\n if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase() || null;\n const first = parts[0][0] ?? \"\";\n const last = parts[parts.length - 1][0] ?? \"\";\n return (first + last).toUpperCase() || null;\n}\n\n/** Avatar from `profile.image`, or initials from `profile.name`. `null` otherwise. */\nexport function UserAvatar({ size = \"md\", className }: UserAvatarProps) {\n const { isLoggedIn } = useAuthState();\n const { data: profile } = useAccountProfile({ enabled: isLoggedIn });\n if (!isLoggedIn) return null;\n\n const base = cn(\n \"polli:inline-flex polli:items-center polli:justify-center polli:rounded-full polli:overflow-hidden polli:bg-theme-bg-pale polli:text-theme-text-strong polli:font-semibold polli:select-none\",\n sizeClass[size],\n className,\n );\n\n if (profile?.image) {\n return (\n <img\n data-polli=\"user-avatar\"\n src={profile.image}\n alt={profile.name ?? \"\"}\n className={base}\n />\n );\n }\n const label = profile?.name ? initials(profile.name) : null;\n if (!label) return null;\n return (\n <div\n data-polli=\"user-avatar\"\n role=\"img\"\n aria-label={profile?.name ?? undefined}\n className={base}\n >\n {label}\n </div>\n );\n}\n","import { useAccountProfile, useAuthState } from \"@pollinations/sdk/react\";\n\nexport type UserNameProps = { className?: string };\n\n/**\n * Renders the user's display name. Falls back to GitHub username when the\n * `profile` scope was not granted (or `name` is empty). `null` when logged\n * out, or when neither name nor GitHub username is available.\n */\nexport function UserName({ className }: UserNameProps) {\n const { isLoggedIn } = useAuthState();\n const { data: profile } = useAccountProfile({ enabled: isLoggedIn });\n if (!isLoggedIn || !profile) return null;\n const display = profile.name || profile.githubUsername;\n if (!display) return null;\n return (\n <span data-polli=\"user-name\" className={className}>\n {display}\n </span>\n );\n}\n","import { useAuthState } from \"@pollinations/sdk/react\";\nimport { Fragment, type ReactNode } from \"react\";\n\nexport type WhenLoggedInProps = { children: ReactNode };\n\n/** Renders `children` only when a user is signed in. */\nexport function WhenLoggedIn({ children }: WhenLoggedInProps) {\n const { isLoggedIn } = useAuthState();\n if (!isLoggedIn) return null;\n return <Fragment>{children}</Fragment>;\n}\n","import { useAuthState } from \"@pollinations/sdk/react\";\nimport { Fragment, type ReactNode } from \"react\";\n\nexport type WhenLoggedOutProps = { children: ReactNode };\n\n/** Renders `children` only when no user is signed in. */\nexport function WhenLoggedOut({ children }: WhenLoggedOutProps) {\n const { isLoggedIn } = useAuthState();\n if (isLoggedIn) return null;\n return <Fragment>{children}</Fragment>;\n}\n","import { useAccountBalance, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\nimport { formatPollen } from \"./format-pollen.ts\";\n\nexport type BalanceProps = { className?: string };\n\n/** Renders the logged-in user's pollen balance. `null` until loaded. */\nexport function Balance({ className }: BalanceProps = {}) {\n const { isLoggedIn } = useAuthState();\n const { data: balance } = useAccountBalance({ enabled: isLoggedIn });\n if (!isLoggedIn || balance == null) return null;\n return (\n <Chip\n data-polli=\"balance\"\n className={cn(\"polli:tabular-nums\", className)}\n >\n {formatPollen(balance.balance)} pollen\n </Chip>\n );\n}\n","import type { ComponentPropsWithoutRef, FC } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\nimport type { ThemeName } from \"../theme.ts\";\n\n/** Semantic chip labels for status and metadata badges. */\ntype ChipIntent =\n | \"news\"\n | \"alpha\"\n | \"neutral\"\n | \"success\"\n | \"warning\"\n | \"danger\";\n\nconst chipSizes = {\n sm: \"polli:px-2 polli:py-0.5 polli:text-xs\",\n md: \"polli:px-2.5 polli:py-0.5 polli:text-sm\",\n lg: \"polli:px-3 polli:py-1 polli:text-sm\",\n} as const;\n\nconst intentClasses: Record<ChipIntent, string> = {\n news: \"polli:bg-intent-news-bg-light polli:text-intent-news-text\",\n alpha: \"polli:bg-intent-alpha-bg-light polli:text-intent-alpha-text\",\n neutral:\n \"polli:border polli:border-gray-400/70 polli:bg-gray-100/80 polli:text-gray-900\",\n success:\n \"polli:border polli:border-intent-success-border polli:bg-intent-success-bg-light polli:text-intent-success-text\",\n warning:\n \"polli:border polli:border-intent-warning-border polli:bg-intent-warning-bg-light polli:text-intent-warning-text\",\n danger: \"polli:border polli:border-intent-danger-border polli:bg-intent-danger-bg-light polli:text-intent-danger-text\",\n};\n\nexport type ChipProps = ComponentPropsWithoutRef<\"span\"> & {\n /** Override the cascade theme for this chip's subtree. */\n theme?: ThemeName;\n /** Semantic intent. Wins over `theme` when set. */\n intent?: ChipIntent;\n size?: keyof typeof chipSizes;\n};\n\n// Static, rectangular colored container. Round shapes are reserved for buttons.\n// Reads `bg-theme-bg-active` / `text-theme-text-strong` from the cascade unless\n// `intent` is set (semantic, theme-independent).\nexport const Chip: FC<ChipProps> = ({\n theme,\n intent,\n size = \"md\",\n className,\n children,\n ...rest\n}) => {\n const intentClass = intent\n ? intentClasses[intent]\n : \"polli:bg-theme-bg-active polli:text-theme-text-strong\";\n return (\n <span\n {...rest}\n data-theme={theme}\n className={cn(\n \"polli:inline-flex polli:shrink-0 polli:items-center polli:gap-1 polli:rounded-lg polli:font-medium polli:leading-normal\",\n chipSizes[size],\n intentClass,\n className,\n )}\n >\n {children}\n </span>\n );\n};\n","// 5-digit budget for pollen display. Integer takes its space, decimals fill\n// the remainder (capped at 4), floor toward -infinity, trailing zeros stripped.\n// Integers needing >=6 digits switch to compact (K/M/B, 3 sig figs).\n// Decimal point and minus sign do not count toward the budget.\n\nconst BUDGET = 5;\nconst MAX_DECIMALS = 4;\nconst COMPACT_THRESHOLD = 100_000;\n\nfunction floorTo(value: number, decimals: number): number {\n const factor = 10 ** decimals;\n return Math.floor(value * factor) / factor;\n}\n\nfunction formatCompact(value: number): string {\n const abs = Math.abs(value);\n const sign = value < 0 ? \"-\" : \"\";\n const [unit, scale] =\n abs >= 1e9\n ? ([\"B\", 1e9] as const)\n : abs >= 1e6\n ? ([\"M\", 1e6] as const)\n : ([\"K\", 1e3] as const);\n const ratio = abs / scale;\n const intDigits = Math.max(1, Math.floor(Math.log10(ratio)) + 1);\n const decimals = Math.max(0, 3 - intDigits);\n const floored = floorTo(ratio, decimals);\n return `${sign}${Number(floored.toFixed(decimals)).toString()}${unit}`;\n}\n\nexport function formatPollen(value: number): string {\n if (!Number.isFinite(value) || value === 0) return \"0\";\n\n const abs = Math.abs(value);\n\n if (abs >= COMPACT_THRESHOLD) return formatCompact(value);\n\n const intDigits = abs >= 1 ? Math.floor(Math.log10(abs)) + 1 : 1;\n const decimals = Math.min(MAX_DECIMALS, Math.max(0, BUDGET - intDigits));\n const floored = floorTo(value, decimals);\n if (floored === 0) return \"0\";\n return Number(floored.toFixed(decimals)).toString();\n}\n","import type { FC } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\n\ntype ChevronIconProps = {\n /** Rotate 180° when expanded/open. */\n expanded?: boolean;\n className?: string;\n};\n\n/**\n * Canonical chevron used for collapsibles, dropdown triggers, and select pills\n * across the app. One icon everywhere.\n */\nexport const ChevronIcon: FC<ChevronIconProps> = ({ expanded, className }) => (\n <svg\n aria-hidden=\"true\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 12 12\"\n className={cn(\n \"polli:shrink-0 polli:transition-transform polli:duration-200 polli:ease-out\",\n expanded && \"polli:rotate-180\",\n className,\n )}\n >\n <path\n d=\"M3 4.5 6 7.5l3-3\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"1.5\"\n />\n </svg>\n);\n","import { Popover } from \"@ark-ui/react/popover\";\nimport { Portal } from \"@ark-ui/react/portal\";\nimport type { FC, ReactNode } from \"react\";\nimport { useState } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\nimport type { ThemeName } from \"../theme.ts\";\n\nconst DEFAULT_PANEL =\n \"polli:rounded-lg polli:border polli:border-theme-border polli:bg-theme-bg-pale polli:shadow-lg\";\n\nexport type DropdownProps = {\n theme: ThemeName;\n /** Trigger element; receives the current open state (e.g. to rotate a chevron). */\n trigger: (open: boolean) => ReactNode;\n /** Panel content. As a function, receives `close` to dismiss after a selection. */\n children: ReactNode | ((close: () => void) => ReactNode);\n /** Panel placement relative to the trigger. */\n align?: \"start\" | \"end\";\n /** Controlled open state. Omit to let the Dropdown manage its own. */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** Appended after the surface (widths, padding, max-height…). */\n className?: string;\n};\n\nexport const Dropdown: FC<DropdownProps> = ({\n theme,\n trigger,\n children,\n align = \"start\",\n open: openProp,\n onOpenChange,\n className,\n}) => {\n const [internalOpen, setInternalOpen] = useState(false);\n const isControlled = openProp !== undefined;\n const open = isControlled ? openProp : internalOpen;\n\n const setOpen = (next: boolean) => {\n if (!isControlled) setInternalOpen(next);\n onOpenChange?.(next);\n };\n\n return (\n <Popover.Root\n open={open}\n onOpenChange={(details) => setOpen(details.open)}\n positioning={{\n placement: align === \"end\" ? \"bottom-end\" : \"bottom-start\",\n }}\n >\n <Popover.Trigger asChild>{trigger(open)}</Popover.Trigger>\n <Portal>\n <Popover.Positioner>\n <Popover.Content\n data-theme={theme}\n className={cn(\n \"polli:z-50 polli:overflow-hidden polli:focus:outline-none\",\n DEFAULT_PANEL,\n className,\n )}\n >\n {typeof children === \"function\"\n ? children(() => setOpen(false))\n : children}\n </Popover.Content>\n </Popover.Positioner>\n </Portal>\n </Popover.Root>\n );\n};\n","import type { PropsWithChildren } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\n\ntype BaseDropdownItemProps = {\n className?: string;\n};\n\nexport type DropdownItemProps<T extends React.ElementType = \"button\"> =\n PropsWithChildren<BaseDropdownItemProps> & {\n as?: T;\n } & Omit<\n React.ComponentPropsWithoutRef<T>,\n keyof BaseDropdownItemProps | \"as\"\n >;\n\nexport function DropdownItem<T extends React.ElementType = \"button\">({\n as,\n className,\n children,\n ...rest\n}: DropdownItemProps<T>) {\n const Component: React.ElementType = as || \"button\";\n return (\n <Component\n {...(Component === \"button\" ? { type: \"button\" } : undefined)}\n {...rest}\n className={cn(\n \"polli-control polli:flex polli:w-full polli:cursor-pointer polli:items-center polli:gap-2 polli:rounded-lg polli:bg-transparent polli:px-3 polli:py-2 polli:text-left polli:text-sm polli:font-medium polli:text-theme-text-base polli:no-underline polli:transition-colors polli:hover:bg-theme-bg-hover polli:focus-visible:bg-theme-bg-hover\",\n className,\n )}\n >\n {children}\n </Component>\n );\n}\n"],"mappings":";AAAA,SAAS,kBAAAA,uBAAsB;;;ACA/B,SAAS,gBAAgB,oBAAoB;;;ACA7C,SAAS,YAAY;AACrB,SAAS,2BAA2B;AAEpC,IAAM,UAAU,oBAAoB,EAAE,QAAQ,QAAQ,CAAC;AAGhD,SAAS,MAAM,QAA+C;AACjE,SAAO,QAAQ,KAAK,GAAG,MAAM,CAAC;AAClC;;;ACiEQ;AAlER,IAAM,QAAQ;AAAA,EACV,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACR;AAGA,IAAM,eACF;AAKJ,IAAM,gBAA8C;AAAA,EAChD,QACI;AAER;AAYA,IAAM,gBAAgB,CAAC;AAAA,EACnB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,MAAgD;AAC5C,QAAM,eAAe,SAAS,cAAc,MAAM,IAAI;AACtD,SAAO;AAAA,IACH;AAAA,IACA,WACM,8CACA;AAAA,IACN;AAAA,IACA,MAAM,QAAQ,IAAI;AAAA,IAClB;AAAA,EACJ;AACJ;AAOO,SAAS,OAA+C;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EAC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ACG,0BAAAA,MAAC,eAAY,OAAM,SAAS,iBAAO,WAAU,GACjD;AAAA,IAEA,gBAAAA,MAAC,gBACG,0BAAAA;AAAA,MAAC;AAAA;AAAA,QACG,OAAM;AAAA,QACN,OAAM;AAAA,QACN,WAAU;AAAA,QACV,SAAS,CAAC,SACN,gBAAAC;AAAA,UAAC;AAAA;AAAA,YACG,MAAK;AAAA,YACL,cAAW;AAAA,YACX,cAAY,OAAO;AAAA,YACnB,WAAU;AAAA,YAEV;AAAA,8BAAAD;AAAA,gBAAC;AAAA;AAAA,kBACG,MAAK;AAAA,kBACL,WAAU;AAAA;AAAA,cACd;AAAA,cACA,gBAAAC,MAAC,UAAK,WAAU,iFACZ;AAAA,gCAAAD,MAAC,YAAS,WAAU,mEAAkE;AAAA,gBACtF,gBAAAA,MAAC,WAAQ,WAAU,uFAAsF;AAAA,iBAC7G;AAAA,cACA,gBAAAA;AAAA,gBAAC;AAAA;AAAA,kBACG,UAAU;AAAA,kBACV,WAAU;AAAA;AAAA,cACd;AAAA;AAAA;AAAA,QACJ;AAAA,QAGH,WAAC,UACE,gBAAAC;AAAA,UAAC;AAAA;AAAA,YACG,cAAW;AAAA,YACX,WAAU;AAAA,YAEV;AAAA,8BAAAD;AAAA,gBAAC;AAAA;AAAA,kBACG,IAAG;AAAA,kBACH,MAAM;AAAA,kBACN,QAAO;AAAA,kBACP,KAAI;AAAA,kBACJ,SAAS;AAAA,kBAER,iBAAO;AAAA;AAAA,cACZ;AAAA,cACA,gBAAAA;AAAA,gBAAC;AAAA;AAAA,kBACG,MAAK;AAAA,kBACL,SAAS,MAAM;AACX,0BAAM;AACN,2BAAO;AAAA,kBACX;AAAA,kBAEC,iBAAO;AAAA;AAAA,cACZ;AAAA;AAAA;AAAA,QACJ;AAAA;AAAA,IAER,GACJ;AAAA,KACJ;AAER;","names":["useAuthActions","jsx","useAuthState","jsx","useAuthState","useAccountProfile","useAuthState","jsx","useAuthState","jsx","useAuthState","Fragment","jsx","useAuthState","jsx","intentClasses","useAuthState","jsx","jsx","jsxs","jsx","jsx","jsxs","useAuthActions"]}
|