@pollinations/ui 0.0.2 → 0.1.0-alpha.1

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 (59) hide show
  1. package/README.md +38 -71
  2. package/dist/{Chip-SM52sUbZ.d.cts → Chip-CQCq34kS.d.cts} +1 -1
  3. package/dist/{Chip-C5impfYd.d.ts → Chip-Cj4xG7Te.d.ts} +1 -1
  4. package/dist/app-user-menu/sdk.cjs +497 -0
  5. package/dist/app-user-menu/sdk.cjs.map +1 -0
  6. package/dist/app-user-menu/sdk.d.cts +18 -0
  7. package/dist/app-user-menu/sdk.d.ts +18 -0
  8. package/dist/app-user-menu/sdk.js +469 -0
  9. package/dist/app-user-menu/sdk.js.map +1 -0
  10. package/dist/app.css +94 -3
  11. package/dist/auth/index.cjs +77 -62
  12. package/dist/auth/index.cjs.map +1 -1
  13. package/dist/auth/index.js +77 -62
  14. package/dist/auth/index.js.map +1 -1
  15. package/dist/gen/index.cjs +477 -0
  16. package/dist/gen/index.cjs.map +1 -0
  17. package/dist/gen/index.d.cts +35 -0
  18. package/dist/gen/index.d.ts +35 -0
  19. package/dist/gen/index.js +451 -0
  20. package/dist/gen/index.js.map +1 -0
  21. package/dist/index.cjs +1875 -761
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +294 -109
  24. package/dist/index.d.ts +294 -109
  25. package/dist/index.js +1889 -798
  26. package/dist/index.js.map +1 -1
  27. package/dist/styles.css +1 -1
  28. package/dist/theme-jRPPBmld.d.cts +20 -0
  29. package/dist/theme-jRPPBmld.d.ts +20 -0
  30. package/dist/wallet/index.cjs +17 -8
  31. package/dist/wallet/index.cjs.map +1 -1
  32. package/dist/wallet/index.d.cts +2 -2
  33. package/dist/wallet/index.d.ts +2 -2
  34. package/dist/wallet/index.js +17 -8
  35. package/dist/wallet/index.js.map +1 -1
  36. package/package.json +15 -18
  37. package/dist/Button-Bn8pGg6N.d.ts +0 -26
  38. package/dist/Button-CWUBCiIc.d.cts +0 -26
  39. package/dist/auth/sdk.cjs +0 -220
  40. package/dist/auth/sdk.cjs.map +0 -1
  41. package/dist/auth/sdk.d.cts +0 -53
  42. package/dist/auth/sdk.d.ts +0 -53
  43. package/dist/auth/sdk.js +0 -187
  44. package/dist/auth/sdk.js.map +0 -1
  45. package/dist/modality/index.cjs +0 -83
  46. package/dist/modality/index.cjs.map +0 -1
  47. package/dist/modality/index.d.cts +0 -25
  48. package/dist/modality/index.d.ts +0 -25
  49. package/dist/modality/index.js +0 -56
  50. package/dist/modality/index.js.map +0 -1
  51. package/dist/theme-VMRlhqST.d.cts +0 -9
  52. package/dist/theme-VMRlhqST.d.ts +0 -9
  53. package/dist/wallet/sdk.cjs +0 -206
  54. package/dist/wallet/sdk.cjs.map +0 -1
  55. package/dist/wallet/sdk.d.cts +0 -33
  56. package/dist/wallet/sdk.d.ts +0 -33
  57. package/dist/wallet/sdk.js +0 -175
  58. package/dist/wallet/sdk.js.map +0 -1
  59. package/dist/wallet.css +0 -73
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/modules/modality/index.ts","../../src/modules/modality/colors.ts"],"sourcesContent":["export {\n getModalityColors,\n type Modality,\n type ModalityColorSet,\n} from \"./colors.ts\";\n","/**\n * Single source of truth for modality colors.\n *\n * Each modality (text/image/video/audio/realtime/embedding) gets one\n * page-theme hue, applied at the soft `-200/-900/-400` chip recipe.\n * Used by apps to compose model-selection buttons and static modality chips.\n * This module only owns modality color data; primitives own shape and behavior.\n */\nimport type { ThemeName } from \"../../theme.ts\";\n\nexport type Modality =\n | \"text\"\n | \"image\"\n | \"video\"\n | \"audio\"\n | \"realtime\"\n | \"embedding\";\n\nexport type ModalityColorSet = {\n /** Matching package theme for surfaces/chips that should inherit this hue. */\n theme: ThemeName;\n /** Selected/filled state: `bg + text + border` classes. */\n filled: string;\n /** Hover hint shown on the unselected button (subtle tint). */\n hover: string;\n /** Heading text colour for the category label. */\n text: string;\n};\n\n// No borders — chips and buttons in this system are borderless.\nexport const MODALITY_COLORS: Record<Modality, ModalityColorSet> = {\n text: {\n theme: \"blue\",\n filled: \"polli:bg-blue-200 polli:text-blue-900\",\n hover: \"polli:hover:bg-blue-100 polli:hover:text-blue-900\",\n text: \"polli:text-blue-800\",\n },\n image: {\n theme: \"pink\",\n filled: \"polli:bg-pink-200 polli:text-pink-900\",\n hover: \"polli:hover:bg-pink-100 polli:hover:text-pink-900\",\n text: \"polli:text-pink-800\",\n },\n video: {\n theme: \"teal\",\n filled: \"polli:bg-teal-200 polli:text-teal-900\",\n hover: \"polli:hover:bg-teal-100 polli:hover:text-teal-900\",\n text: \"polli:text-teal-800\",\n },\n audio: {\n theme: \"violet\",\n filled: \"polli:bg-violet-200 polli:text-violet-900\",\n hover: \"polli:hover:bg-violet-100 polli:hover:text-violet-900\",\n text: \"polli:text-violet-800\",\n },\n realtime: {\n theme: \"green\",\n filled: \"polli:bg-green-200 polli:text-green-900\",\n hover: \"polli:hover:bg-green-100 polli:hover:text-green-900\",\n text: \"polli:text-green-800\",\n },\n embedding: {\n theme: \"amber\",\n filled: \"polli:bg-amber-200 polli:text-amber-900\",\n hover: \"polli:hover:bg-amber-100 polli:hover:text-amber-900\",\n text: \"polli:text-amber-800\",\n },\n};\n\n/** Map any human-typed category string to the canonical `Modality` key. */\nfunction normalize(category: string): Modality | null {\n const lower = category.toLowerCase();\n if (lower === \"images\") return \"image\";\n if (lower === \"embeddings\") return \"embedding\";\n if (\n lower === \"text\" ||\n lower === \"image\" ||\n lower === \"video\" ||\n lower === \"audio\" ||\n lower === \"realtime\" ||\n lower === \"embedding\"\n ) {\n return lower;\n }\n return null;\n}\n\nexport function getModalityColors(category: string): ModalityColorSet | null {\n const key = normalize(category);\n return key ? MODALITY_COLORS[key] : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC8BO,IAAM,kBAAsD;AAAA,EAC/D,MAAM;AAAA,IACF,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,UAAU;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,WAAW;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AACJ;AAGA,SAAS,UAAU,UAAmC;AAClD,QAAM,QAAQ,SAAS,YAAY;AACnC,MAAI,UAAU,SAAU,QAAO;AAC/B,MAAI,UAAU,aAAc,QAAO;AACnC,MACI,UAAU,UACV,UAAU,WACV,UAAU,WACV,UAAU,WACV,UAAU,cACV,UAAU,aACZ;AACE,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,kBAAkB,UAA2C;AACzE,QAAM,MAAM,UAAU,QAAQ;AAC9B,SAAO,MAAM,gBAAgB,GAAG,IAAI;AACxC;","names":[]}
@@ -1,25 +0,0 @@
1
- import { T as ThemeName } from '../theme-VMRlhqST.cjs';
2
-
3
- /**
4
- * Single source of truth for modality colors.
5
- *
6
- * Each modality (text/image/video/audio/realtime/embedding) gets one
7
- * page-theme hue, applied at the soft `-200/-900/-400` chip recipe.
8
- * Used by apps to compose model-selection buttons and static modality chips.
9
- * This module only owns modality color data; primitives own shape and behavior.
10
- */
11
-
12
- type Modality = "text" | "image" | "video" | "audio" | "realtime" | "embedding";
13
- type ModalityColorSet = {
14
- /** Matching package theme for surfaces/chips that should inherit this hue. */
15
- theme: ThemeName;
16
- /** Selected/filled state: `bg + text + border` classes. */
17
- filled: string;
18
- /** Hover hint shown on the unselected button (subtle tint). */
19
- hover: string;
20
- /** Heading text colour for the category label. */
21
- text: string;
22
- };
23
- declare function getModalityColors(category: string): ModalityColorSet | null;
24
-
25
- export { type Modality, type ModalityColorSet, getModalityColors };
@@ -1,25 +0,0 @@
1
- import { T as ThemeName } from '../theme-VMRlhqST.js';
2
-
3
- /**
4
- * Single source of truth for modality colors.
5
- *
6
- * Each modality (text/image/video/audio/realtime/embedding) gets one
7
- * page-theme hue, applied at the soft `-200/-900/-400` chip recipe.
8
- * Used by apps to compose model-selection buttons and static modality chips.
9
- * This module only owns modality color data; primitives own shape and behavior.
10
- */
11
-
12
- type Modality = "text" | "image" | "video" | "audio" | "realtime" | "embedding";
13
- type ModalityColorSet = {
14
- /** Matching package theme for surfaces/chips that should inherit this hue. */
15
- theme: ThemeName;
16
- /** Selected/filled state: `bg + text + border` classes. */
17
- filled: string;
18
- /** Hover hint shown on the unselected button (subtle tint). */
19
- hover: string;
20
- /** Heading text colour for the category label. */
21
- text: string;
22
- };
23
- declare function getModalityColors(category: string): ModalityColorSet | null;
24
-
25
- export { type Modality, type ModalityColorSet, getModalityColors };
@@ -1,56 +0,0 @@
1
- // src/modules/modality/colors.ts
2
- var MODALITY_COLORS = {
3
- text: {
4
- theme: "blue",
5
- filled: "polli:bg-blue-200 polli:text-blue-900",
6
- hover: "polli:hover:bg-blue-100 polli:hover:text-blue-900",
7
- text: "polli:text-blue-800"
8
- },
9
- image: {
10
- theme: "pink",
11
- filled: "polli:bg-pink-200 polli:text-pink-900",
12
- hover: "polli:hover:bg-pink-100 polli:hover:text-pink-900",
13
- text: "polli:text-pink-800"
14
- },
15
- video: {
16
- theme: "teal",
17
- filled: "polli:bg-teal-200 polli:text-teal-900",
18
- hover: "polli:hover:bg-teal-100 polli:hover:text-teal-900",
19
- text: "polli:text-teal-800"
20
- },
21
- audio: {
22
- theme: "violet",
23
- filled: "polli:bg-violet-200 polli:text-violet-900",
24
- hover: "polli:hover:bg-violet-100 polli:hover:text-violet-900",
25
- text: "polli:text-violet-800"
26
- },
27
- realtime: {
28
- theme: "green",
29
- filled: "polli:bg-green-200 polli:text-green-900",
30
- hover: "polli:hover:bg-green-100 polli:hover:text-green-900",
31
- text: "polli:text-green-800"
32
- },
33
- embedding: {
34
- theme: "amber",
35
- filled: "polli:bg-amber-200 polli:text-amber-900",
36
- hover: "polli:hover:bg-amber-100 polli:hover:text-amber-900",
37
- text: "polli:text-amber-800"
38
- }
39
- };
40
- function normalize(category) {
41
- const lower = category.toLowerCase();
42
- if (lower === "images") return "image";
43
- if (lower === "embeddings") return "embedding";
44
- if (lower === "text" || lower === "image" || lower === "video" || lower === "audio" || lower === "realtime" || lower === "embedding") {
45
- return lower;
46
- }
47
- return null;
48
- }
49
- function getModalityColors(category) {
50
- const key = normalize(category);
51
- return key ? MODALITY_COLORS[key] : null;
52
- }
53
- export {
54
- getModalityColors
55
- };
56
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/modules/modality/colors.ts"],"sourcesContent":["/**\n * Single source of truth for modality colors.\n *\n * Each modality (text/image/video/audio/realtime/embedding) gets one\n * page-theme hue, applied at the soft `-200/-900/-400` chip recipe.\n * Used by apps to compose model-selection buttons and static modality chips.\n * This module only owns modality color data; primitives own shape and behavior.\n */\nimport type { ThemeName } from \"../../theme.ts\";\n\nexport type Modality =\n | \"text\"\n | \"image\"\n | \"video\"\n | \"audio\"\n | \"realtime\"\n | \"embedding\";\n\nexport type ModalityColorSet = {\n /** Matching package theme for surfaces/chips that should inherit this hue. */\n theme: ThemeName;\n /** Selected/filled state: `bg + text + border` classes. */\n filled: string;\n /** Hover hint shown on the unselected button (subtle tint). */\n hover: string;\n /** Heading text colour for the category label. */\n text: string;\n};\n\n// No borders — chips and buttons in this system are borderless.\nexport const MODALITY_COLORS: Record<Modality, ModalityColorSet> = {\n text: {\n theme: \"blue\",\n filled: \"polli:bg-blue-200 polli:text-blue-900\",\n hover: \"polli:hover:bg-blue-100 polli:hover:text-blue-900\",\n text: \"polli:text-blue-800\",\n },\n image: {\n theme: \"pink\",\n filled: \"polli:bg-pink-200 polli:text-pink-900\",\n hover: \"polli:hover:bg-pink-100 polli:hover:text-pink-900\",\n text: \"polli:text-pink-800\",\n },\n video: {\n theme: \"teal\",\n filled: \"polli:bg-teal-200 polli:text-teal-900\",\n hover: \"polli:hover:bg-teal-100 polli:hover:text-teal-900\",\n text: \"polli:text-teal-800\",\n },\n audio: {\n theme: \"violet\",\n filled: \"polli:bg-violet-200 polli:text-violet-900\",\n hover: \"polli:hover:bg-violet-100 polli:hover:text-violet-900\",\n text: \"polli:text-violet-800\",\n },\n realtime: {\n theme: \"green\",\n filled: \"polli:bg-green-200 polli:text-green-900\",\n hover: \"polli:hover:bg-green-100 polli:hover:text-green-900\",\n text: \"polli:text-green-800\",\n },\n embedding: {\n theme: \"amber\",\n filled: \"polli:bg-amber-200 polli:text-amber-900\",\n hover: \"polli:hover:bg-amber-100 polli:hover:text-amber-900\",\n text: \"polli:text-amber-800\",\n },\n};\n\n/** Map any human-typed category string to the canonical `Modality` key. */\nfunction normalize(category: string): Modality | null {\n const lower = category.toLowerCase();\n if (lower === \"images\") return \"image\";\n if (lower === \"embeddings\") return \"embedding\";\n if (\n lower === \"text\" ||\n lower === \"image\" ||\n lower === \"video\" ||\n lower === \"audio\" ||\n lower === \"realtime\" ||\n lower === \"embedding\"\n ) {\n return lower;\n }\n return null;\n}\n\nexport function getModalityColors(category: string): ModalityColorSet | null {\n const key = normalize(category);\n return key ? MODALITY_COLORS[key] : null;\n}\n"],"mappings":";AA8BO,IAAM,kBAAsD;AAAA,EAC/D,MAAM;AAAA,IACF,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,OAAO;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,UAAU;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AAAA,EACA,WAAW;AAAA,IACP,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,EACV;AACJ;AAGA,SAAS,UAAU,UAAmC;AAClD,QAAM,QAAQ,SAAS,YAAY;AACnC,MAAI,UAAU,SAAU,QAAO;AAC/B,MAAI,UAAU,aAAc,QAAO;AACnC,MACI,UAAU,UACV,UAAU,WACV,UAAU,WACV,UAAU,WACV,UAAU,cACV,UAAU,aACZ;AACE,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,kBAAkB,UAA2C;AACzE,QAAM,MAAM,UAAU,QAAQ;AAC9B,SAAO,MAAM,gBAAgB,GAAG,IAAI;AACxC;","names":[]}
@@ -1,9 +0,0 @@
1
- /**
2
- * The six chrome themes exposed by the CSS-var cascade. Apply via
3
- * `data-theme="<name>"` on any ancestor — primitives and `--polli-*`
4
- * tokens in that subtree restyle accordingly.
5
- */
6
- declare const themes: readonly ["amber", "blue", "pink", "teal", "violet", "green"];
7
- type ThemeName = (typeof themes)[number];
8
-
9
- export { type ThemeName as T, themes as t };
@@ -1,9 +0,0 @@
1
- /**
2
- * The six chrome themes exposed by the CSS-var cascade. Apply via
3
- * `data-theme="<name>"` on any ancestor — primitives and `--polli-*`
4
- * tokens in that subtree restyle accordingly.
5
- */
6
- declare const themes: readonly ["amber", "blue", "pink", "teal", "violet", "green"];
7
- type ThemeName = (typeof themes)[number];
8
-
9
- export { type ThemeName as T, themes as t };
@@ -1,206 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/modules/wallet/sdk.ts
21
- var sdk_exports = {};
22
- __export(sdk_exports, {
23
- Balance: () => Balance,
24
- KeyBudget: () => KeyBudget,
25
- KeyExpiry: () => KeyExpiry,
26
- KeyModels: () => KeyModels,
27
- KeyPrefix: () => KeyPrefix
28
- });
29
- module.exports = __toCommonJS(sdk_exports);
30
-
31
- // src/modules/wallet/Balance.tsx
32
- var import_react = require("@pollinations/sdk/react");
33
-
34
- // src/lib/cn.ts
35
- var import_clsx = require("clsx");
36
- var import_tailwind_merge = require("tailwind-merge");
37
- var twMerge = (0, import_tailwind_merge.extendTailwindMerge)({ prefix: "polli" });
38
- function cn(...inputs) {
39
- return twMerge((0, import_clsx.clsx)(...inputs));
40
- }
41
-
42
- // src/primitives/Chip.tsx
43
- var import_jsx_runtime = require("react/jsx-runtime");
44
- var chipSizes = {
45
- sm: "polli:px-2 polli:py-0.5 polli:text-xs",
46
- md: "polli:px-2.5 polli:py-0.5 polli:text-sm",
47
- lg: "polli:px-3 polli:py-1 polli:text-sm"
48
- };
49
- var intentClasses = {
50
- news: "polli:bg-[oklch(0.935_0.06_158)] polli:text-[oklch(0.46_0.13_158)]",
51
- alpha: "polli:bg-[oklch(0.93_0.06_300)] polli:text-[oklch(0.42_0.18_300)]",
52
- neutral: "polli:border polli:border-gray-400/70 polli:bg-gray-100/80 polli:text-gray-900",
53
- success: "polli:border polli:border-intent-success-border polli:bg-intent-success-bg-light polli:text-intent-success-text",
54
- warning: "polli:border polli:border-intent-warning-border polli:bg-intent-warning-bg-light polli:text-intent-warning-text",
55
- danger: "polli:border polli:border-intent-danger-border polli:bg-intent-danger-bg-light polli:text-intent-danger-text"
56
- };
57
- var Chip = ({
58
- theme,
59
- intent,
60
- size = "md",
61
- className,
62
- children,
63
- ...rest
64
- }) => {
65
- const intentClass = intent ? intentClasses[intent] : "polli:bg-theme-bg-active polli:text-theme-text-strong";
66
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
- "span",
68
- {
69
- ...rest,
70
- "data-theme": theme,
71
- className: cn(
72
- "polli:inline-flex polli:shrink-0 polli:items-center polli:gap-1 polli:rounded-lg polli:font-medium polli:leading-normal",
73
- chipSizes[size],
74
- intentClass,
75
- className
76
- ),
77
- children
78
- }
79
- );
80
- };
81
-
82
- // src/modules/wallet/format-pollen.ts
83
- var BUDGET = 5;
84
- var MAX_DECIMALS = 4;
85
- var COMPACT_THRESHOLD = 1e5;
86
- function floorTo(value, decimals) {
87
- const factor = 10 ** decimals;
88
- return Math.floor(value * factor) / factor;
89
- }
90
- function formatCompact(value) {
91
- const abs = Math.abs(value);
92
- const sign = value < 0 ? "-" : "";
93
- const [unit, scale] = abs >= 1e9 ? ["B", 1e9] : abs >= 1e6 ? ["M", 1e6] : ["K", 1e3];
94
- const ratio = abs / scale;
95
- const intDigits = Math.max(1, Math.floor(Math.log10(ratio)) + 1);
96
- const decimals = Math.max(0, 3 - intDigits);
97
- const floored = floorTo(ratio, decimals);
98
- return `${sign}${Number(floored.toFixed(decimals)).toString()}${unit}`;
99
- }
100
- function formatPollen(value) {
101
- if (!Number.isFinite(value) || value === 0) return "0";
102
- const abs = Math.abs(value);
103
- if (abs >= COMPACT_THRESHOLD) return formatCompact(value);
104
- const intDigits = abs >= 1 ? Math.floor(Math.log10(abs)) + 1 : 1;
105
- const decimals = Math.min(MAX_DECIMALS, Math.max(0, BUDGET - intDigits));
106
- const floored = floorTo(value, decimals);
107
- if (floored === 0) return "0";
108
- return Number(floored.toFixed(decimals)).toString();
109
- }
110
-
111
- // src/modules/wallet/Balance.tsx
112
- var import_jsx_runtime2 = require("react/jsx-runtime");
113
- function Balance({ className } = {}) {
114
- const { isLoggedIn } = (0, import_react.useAuthState)();
115
- const { data: balance } = (0, import_react.useAccountBalance)({ enabled: isLoggedIn });
116
- if (!isLoggedIn || balance == null) return null;
117
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
118
- Chip,
119
- {
120
- "data-polli": "balance",
121
- className: cn("polli:tabular-nums", className),
122
- children: [
123
- formatPollen(balance.balance),
124
- " pollen"
125
- ]
126
- }
127
- );
128
- }
129
-
130
- // src/modules/wallet/KeyBudget.tsx
131
- var import_react2 = require("@pollinations/sdk/react");
132
- var import_jsx_runtime3 = require("react/jsx-runtime");
133
- function KeyBudget({ className } = {}) {
134
- const { isLoggedIn } = (0, import_react2.useAuthState)();
135
- const { data: key } = (0, import_react2.useAccountKey)({ enabled: isLoggedIn });
136
- const budget = key?.pollenBudget;
137
- if (!isLoggedIn || budget == null) return null;
138
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
139
- Chip,
140
- {
141
- "data-polli": "key-budget",
142
- className: cn("polli:tabular-nums", className),
143
- children: [
144
- formatPollen(budget),
145
- " pollen"
146
- ]
147
- }
148
- );
149
- }
150
-
151
- // src/modules/wallet/KeyExpiry.tsx
152
- var import_react3 = require("@pollinations/sdk/react");
153
- var import_jsx_runtime4 = require("react/jsx-runtime");
154
- function KeyExpiry({ className } = {}) {
155
- const { isLoggedIn } = (0, import_react3.useAuthState)();
156
- const { data: key } = (0, import_react3.useAccountKey)({ enabled: isLoggedIn });
157
- if (!isLoggedIn || !key?.expiresAt) return null;
158
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
159
- Chip,
160
- {
161
- "data-polli": "key-expiry",
162
- className: cn("polli:tabular-nums", className),
163
- children: key.expiresAt.slice(0, 10)
164
- }
165
- );
166
- }
167
-
168
- // src/modules/wallet/KeyModels.tsx
169
- var import_react4 = require("@pollinations/sdk/react");
170
- var import_jsx_runtime5 = require("react/jsx-runtime");
171
- function KeyModels({ className } = {}) {
172
- const { isLoggedIn } = (0, import_react4.useAuthState)();
173
- const { data: key } = (0, import_react4.useAccountKey)({ enabled: isLoggedIn });
174
- if (!isLoggedIn || !key) return null;
175
- const models = key.permissions?.models ?? null;
176
- const text = models === null ? "All models" : `${models.length} model${models.length === 1 ? "" : "s"}`;
177
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Chip, { "data-polli": "key-models", className, children: text });
178
- }
179
-
180
- // src/modules/wallet/KeyPrefix.tsx
181
- var import_react5 = require("@pollinations/sdk/react");
182
- var import_jsx_runtime6 = require("react/jsx-runtime");
183
- function KeyPrefix({ className } = {}) {
184
- const { apiKey } = (0, import_react5.useAuthState)();
185
- if (!apiKey) return null;
186
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
187
- Chip,
188
- {
189
- "data-polli": "key-prefix",
190
- className: cn("polli:font-mono polli:select-none", className),
191
- children: [
192
- apiKey.slice(0, 7),
193
- "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
194
- ]
195
- }
196
- );
197
- }
198
- // Annotate the CommonJS export names for ESM import in node:
199
- 0 && (module.exports = {
200
- Balance,
201
- KeyBudget,
202
- KeyExpiry,
203
- KeyModels,
204
- KeyPrefix
205
- });
206
- //# sourceMappingURL=sdk.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/modules/wallet/sdk.ts","../../src/modules/wallet/Balance.tsx","../../src/lib/cn.ts","../../src/primitives/Chip.tsx","../../src/modules/wallet/format-pollen.ts","../../src/modules/wallet/KeyBudget.tsx","../../src/modules/wallet/KeyExpiry.tsx","../../src/modules/wallet/KeyModels.tsx","../../src/modules/wallet/KeyPrefix.tsx"],"sourcesContent":["export { Balance, type BalanceProps } from \"./Balance.tsx\";\nexport { KeyBudget, type KeyBudgetProps } from \"./KeyBudget.tsx\";\nexport { KeyExpiry, type KeyExpiryProps } from \"./KeyExpiry.tsx\";\nexport { KeyModels, type KeyModelsProps } from \"./KeyModels.tsx\";\nexport { KeyPrefix, type KeyPrefixProps } from \"./KeyPrefix.tsx\";\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 { 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 { 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-[oklch(0.935_0.06_158)] polli:text-[oklch(0.46_0.13_158)]\",\n alpha: \"polli:bg-[oklch(0.93_0.06_300)] polli:text-[oklch(0.42_0.18_300)]\",\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 { useAccountKey, 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 KeyBudgetProps = { className?: string };\n\n/** Renders the current delegated key's remaining budget. `null` until loaded. */\nexport function KeyBudget({ className }: KeyBudgetProps = {}) {\n const { isLoggedIn } = useAuthState();\n const { data: key } = useAccountKey({ enabled: isLoggedIn });\n const budget = key?.pollenBudget;\n if (!isLoggedIn || budget == null) return null;\n return (\n <Chip\n data-polli=\"key-budget\"\n className={cn(\"polli:tabular-nums\", className)}\n >\n {formatPollen(budget)} pollen\n </Chip>\n );\n}\n","import { useAccountKey, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyExpiryProps = { className?: string };\n\n/** Renders the current delegated key's expiry date (YYYY-MM-DD) or `null`. */\nexport function KeyExpiry({ className }: KeyExpiryProps = {}) {\n const { isLoggedIn } = useAuthState();\n const { data: key } = useAccountKey({ enabled: isLoggedIn });\n if (!isLoggedIn || !key?.expiresAt) return null;\n return (\n <Chip\n data-polli=\"key-expiry\"\n className={cn(\"polli:tabular-nums\", className)}\n >\n {key.expiresAt.slice(0, 10)}\n </Chip>\n );\n}\n","import { useAccountKey, useAuthState } from \"@pollinations/sdk/react\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyModelsProps = { className?: string };\n\n/** Renders \"All models\" or \"N models\" for the current key. `null` until loaded. */\nexport function KeyModels({ className }: KeyModelsProps = {}) {\n const { isLoggedIn } = useAuthState();\n const { data: key } = useAccountKey({ enabled: isLoggedIn });\n if (!isLoggedIn || !key) return null;\n const models = key.permissions?.models ?? null;\n const text =\n models === null\n ? \"All models\"\n : `${models.length} model${models.length === 1 ? \"\" : \"s\"}`;\n return (\n <Chip data-polli=\"key-models\" className={className}>\n {text}\n </Chip>\n );\n}\n","import { useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyPrefixProps = { className?: string };\n\n/** Renders the first 7 chars of the API key followed by bullets. `null` when logged out. */\nexport function KeyPrefix({ className }: KeyPrefixProps = {}) {\n const { apiKey } = useAuthState();\n if (!apiKey) return null;\n return (\n <Chip\n data-polli=\"key-prefix\"\n className={cn(\"polli:font-mono polli:select-none\", className)}\n >\n {apiKey.slice(0, 7)}\n {\"••••••••\"}\n </Chip>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgD;;;ACAhD,kBAAqB;AACrB,4BAAoC;AAEpC,IAAM,cAAU,2CAAoB,EAAE,QAAQ,QAAQ,CAAC;AAGhD,SAAS,MAAM,QAA+C;AACjE,SAAO,YAAQ,kBAAK,GAAG,MAAM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time","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime"]}
@@ -1,33 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
-
3
- type BalanceProps = {
4
- className?: string;
5
- };
6
- /** Renders the logged-in user's pollen balance. `null` until loaded. */
7
- declare function Balance({ className }?: BalanceProps): react_jsx_runtime.JSX.Element | null;
8
-
9
- type KeyBudgetProps = {
10
- className?: string;
11
- };
12
- /** Renders the current delegated key's remaining budget. `null` until loaded. */
13
- declare function KeyBudget({ className }?: KeyBudgetProps): react_jsx_runtime.JSX.Element | null;
14
-
15
- type KeyExpiryProps = {
16
- className?: string;
17
- };
18
- /** Renders the current delegated key's expiry date (YYYY-MM-DD) or `null`. */
19
- declare function KeyExpiry({ className }?: KeyExpiryProps): react_jsx_runtime.JSX.Element | null;
20
-
21
- type KeyModelsProps = {
22
- className?: string;
23
- };
24
- /** Renders "All models" or "N models" for the current key. `null` until loaded. */
25
- declare function KeyModels({ className }?: KeyModelsProps): react_jsx_runtime.JSX.Element | null;
26
-
27
- type KeyPrefixProps = {
28
- className?: string;
29
- };
30
- /** Renders the first 7 chars of the API key followed by bullets. `null` when logged out. */
31
- declare function KeyPrefix({ className }?: KeyPrefixProps): react_jsx_runtime.JSX.Element | null;
32
-
33
- export { Balance, type BalanceProps, KeyBudget, type KeyBudgetProps, KeyExpiry, type KeyExpiryProps, KeyModels, type KeyModelsProps, KeyPrefix, type KeyPrefixProps };
@@ -1,33 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
-
3
- type BalanceProps = {
4
- className?: string;
5
- };
6
- /** Renders the logged-in user's pollen balance. `null` until loaded. */
7
- declare function Balance({ className }?: BalanceProps): react_jsx_runtime.JSX.Element | null;
8
-
9
- type KeyBudgetProps = {
10
- className?: string;
11
- };
12
- /** Renders the current delegated key's remaining budget. `null` until loaded. */
13
- declare function KeyBudget({ className }?: KeyBudgetProps): react_jsx_runtime.JSX.Element | null;
14
-
15
- type KeyExpiryProps = {
16
- className?: string;
17
- };
18
- /** Renders the current delegated key's expiry date (YYYY-MM-DD) or `null`. */
19
- declare function KeyExpiry({ className }?: KeyExpiryProps): react_jsx_runtime.JSX.Element | null;
20
-
21
- type KeyModelsProps = {
22
- className?: string;
23
- };
24
- /** Renders "All models" or "N models" for the current key. `null` until loaded. */
25
- declare function KeyModels({ className }?: KeyModelsProps): react_jsx_runtime.JSX.Element | null;
26
-
27
- type KeyPrefixProps = {
28
- className?: string;
29
- };
30
- /** Renders the first 7 chars of the API key followed by bullets. `null` when logged out. */
31
- declare function KeyPrefix({ className }?: KeyPrefixProps): react_jsx_runtime.JSX.Element | null;
32
-
33
- export { Balance, type BalanceProps, KeyBudget, type KeyBudgetProps, KeyExpiry, type KeyExpiryProps, KeyModels, type KeyModelsProps, KeyPrefix, type KeyPrefixProps };
@@ -1,175 +0,0 @@
1
- // src/modules/wallet/Balance.tsx
2
- import { useAccountBalance, useAuthState } from "@pollinations/sdk/react";
3
-
4
- // src/lib/cn.ts
5
- import { clsx } from "clsx";
6
- import { extendTailwindMerge } from "tailwind-merge";
7
- var twMerge = extendTailwindMerge({ prefix: "polli" });
8
- function cn(...inputs) {
9
- return twMerge(clsx(...inputs));
10
- }
11
-
12
- // src/primitives/Chip.tsx
13
- import { jsx } from "react/jsx-runtime";
14
- var chipSizes = {
15
- sm: "polli:px-2 polli:py-0.5 polli:text-xs",
16
- md: "polli:px-2.5 polli:py-0.5 polli:text-sm",
17
- lg: "polli:px-3 polli:py-1 polli:text-sm"
18
- };
19
- var intentClasses = {
20
- news: "polli:bg-[oklch(0.935_0.06_158)] polli:text-[oklch(0.46_0.13_158)]",
21
- alpha: "polli:bg-[oklch(0.93_0.06_300)] polli:text-[oklch(0.42_0.18_300)]",
22
- neutral: "polli:border polli:border-gray-400/70 polli:bg-gray-100/80 polli:text-gray-900",
23
- success: "polli:border polli:border-intent-success-border polli:bg-intent-success-bg-light polli:text-intent-success-text",
24
- warning: "polli:border polli:border-intent-warning-border polli:bg-intent-warning-bg-light polli:text-intent-warning-text",
25
- danger: "polli:border polli:border-intent-danger-border polli:bg-intent-danger-bg-light polli:text-intent-danger-text"
26
- };
27
- var Chip = ({
28
- theme,
29
- intent,
30
- size = "md",
31
- className,
32
- children,
33
- ...rest
34
- }) => {
35
- const intentClass = intent ? intentClasses[intent] : "polli:bg-theme-bg-active polli:text-theme-text-strong";
36
- return /* @__PURE__ */ jsx(
37
- "span",
38
- {
39
- ...rest,
40
- "data-theme": theme,
41
- className: cn(
42
- "polli:inline-flex polli:shrink-0 polli:items-center polli:gap-1 polli:rounded-lg polli:font-medium polli:leading-normal",
43
- chipSizes[size],
44
- intentClass,
45
- className
46
- ),
47
- children
48
- }
49
- );
50
- };
51
-
52
- // src/modules/wallet/format-pollen.ts
53
- var BUDGET = 5;
54
- var MAX_DECIMALS = 4;
55
- var COMPACT_THRESHOLD = 1e5;
56
- function floorTo(value, decimals) {
57
- const factor = 10 ** decimals;
58
- return Math.floor(value * factor) / factor;
59
- }
60
- function formatCompact(value) {
61
- const abs = Math.abs(value);
62
- const sign = value < 0 ? "-" : "";
63
- const [unit, scale] = abs >= 1e9 ? ["B", 1e9] : abs >= 1e6 ? ["M", 1e6] : ["K", 1e3];
64
- const ratio = abs / scale;
65
- const intDigits = Math.max(1, Math.floor(Math.log10(ratio)) + 1);
66
- const decimals = Math.max(0, 3 - intDigits);
67
- const floored = floorTo(ratio, decimals);
68
- return `${sign}${Number(floored.toFixed(decimals)).toString()}${unit}`;
69
- }
70
- function formatPollen(value) {
71
- if (!Number.isFinite(value) || value === 0) return "0";
72
- const abs = Math.abs(value);
73
- if (abs >= COMPACT_THRESHOLD) return formatCompact(value);
74
- const intDigits = abs >= 1 ? Math.floor(Math.log10(abs)) + 1 : 1;
75
- const decimals = Math.min(MAX_DECIMALS, Math.max(0, BUDGET - intDigits));
76
- const floored = floorTo(value, decimals);
77
- if (floored === 0) return "0";
78
- return Number(floored.toFixed(decimals)).toString();
79
- }
80
-
81
- // src/modules/wallet/Balance.tsx
82
- import { jsxs } from "react/jsx-runtime";
83
- function Balance({ className } = {}) {
84
- const { isLoggedIn } = useAuthState();
85
- const { data: balance } = useAccountBalance({ enabled: isLoggedIn });
86
- if (!isLoggedIn || balance == null) return null;
87
- return /* @__PURE__ */ jsxs(
88
- Chip,
89
- {
90
- "data-polli": "balance",
91
- className: cn("polli:tabular-nums", className),
92
- children: [
93
- formatPollen(balance.balance),
94
- " pollen"
95
- ]
96
- }
97
- );
98
- }
99
-
100
- // src/modules/wallet/KeyBudget.tsx
101
- import { useAccountKey, useAuthState as useAuthState2 } from "@pollinations/sdk/react";
102
- import { jsxs as jsxs2 } from "react/jsx-runtime";
103
- function KeyBudget({ className } = {}) {
104
- const { isLoggedIn } = useAuthState2();
105
- const { data: key } = useAccountKey({ enabled: isLoggedIn });
106
- const budget = key?.pollenBudget;
107
- if (!isLoggedIn || budget == null) return null;
108
- return /* @__PURE__ */ jsxs2(
109
- Chip,
110
- {
111
- "data-polli": "key-budget",
112
- className: cn("polli:tabular-nums", className),
113
- children: [
114
- formatPollen(budget),
115
- " pollen"
116
- ]
117
- }
118
- );
119
- }
120
-
121
- // src/modules/wallet/KeyExpiry.tsx
122
- import { useAccountKey as useAccountKey2, useAuthState as useAuthState3 } from "@pollinations/sdk/react";
123
- import { jsx as jsx2 } from "react/jsx-runtime";
124
- function KeyExpiry({ className } = {}) {
125
- const { isLoggedIn } = useAuthState3();
126
- const { data: key } = useAccountKey2({ enabled: isLoggedIn });
127
- if (!isLoggedIn || !key?.expiresAt) return null;
128
- return /* @__PURE__ */ jsx2(
129
- Chip,
130
- {
131
- "data-polli": "key-expiry",
132
- className: cn("polli:tabular-nums", className),
133
- children: key.expiresAt.slice(0, 10)
134
- }
135
- );
136
- }
137
-
138
- // src/modules/wallet/KeyModels.tsx
139
- import { useAccountKey as useAccountKey3, useAuthState as useAuthState4 } from "@pollinations/sdk/react";
140
- import { jsx as jsx3 } from "react/jsx-runtime";
141
- function KeyModels({ className } = {}) {
142
- const { isLoggedIn } = useAuthState4();
143
- const { data: key } = useAccountKey3({ enabled: isLoggedIn });
144
- if (!isLoggedIn || !key) return null;
145
- const models = key.permissions?.models ?? null;
146
- const text = models === null ? "All models" : `${models.length} model${models.length === 1 ? "" : "s"}`;
147
- return /* @__PURE__ */ jsx3(Chip, { "data-polli": "key-models", className, children: text });
148
- }
149
-
150
- // src/modules/wallet/KeyPrefix.tsx
151
- import { useAuthState as useAuthState5 } from "@pollinations/sdk/react";
152
- import { jsxs as jsxs3 } from "react/jsx-runtime";
153
- function KeyPrefix({ className } = {}) {
154
- const { apiKey } = useAuthState5();
155
- if (!apiKey) return null;
156
- return /* @__PURE__ */ jsxs3(
157
- Chip,
158
- {
159
- "data-polli": "key-prefix",
160
- className: cn("polli:font-mono polli:select-none", className),
161
- children: [
162
- apiKey.slice(0, 7),
163
- "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
164
- ]
165
- }
166
- );
167
- }
168
- export {
169
- Balance,
170
- KeyBudget,
171
- KeyExpiry,
172
- KeyModels,
173
- KeyPrefix
174
- };
175
- //# sourceMappingURL=sdk.js.map