fauna-api 0.0.0-stage → 1.0.679

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/brands.d.ts +2 -0
  2. package/dist/brands.js +2 -0
  3. package/dist/index.d.ts +64 -0
  4. package/dist/index.js +121 -0
  5. package/dist/src/ant/chat.d.ts +130 -0
  6. package/dist/src/ant/chat.js +467 -0
  7. package/dist/src/ant/format.d.ts +40 -0
  8. package/dist/src/ant/format.js +143 -0
  9. package/dist/src/ant/graph.d.ts +130 -0
  10. package/dist/src/ant/graph.js +449 -0
  11. package/dist/src/ant/index.d.ts +16 -0
  12. package/dist/src/ant/index.js +61 -0
  13. package/dist/src/ant/persona.d.ts +151 -0
  14. package/dist/src/ant/persona.js +136 -0
  15. package/dist/src/ant/timeline.d.ts +283 -0
  16. package/dist/src/ant/timeline.js +1025 -0
  17. package/dist/src/authentification.d.ts +45 -0
  18. package/dist/src/authentification.js +194 -0
  19. package/dist/src/billing.d.ts +135 -0
  20. package/dist/src/billing.js +128 -0
  21. package/dist/src/calendar.d.ts +83 -0
  22. package/dist/src/calendar.js +133 -0
  23. package/dist/src/chats.d.ts +113 -0
  24. package/dist/src/chats.js +100 -0
  25. package/dist/src/cicada/contacts.d.ts +31 -0
  26. package/dist/src/cicada/contacts.js +28 -0
  27. package/dist/src/cicada/conversations.d.ts +73 -0
  28. package/dist/src/cicada/conversations.js +236 -0
  29. package/dist/src/cicada/inboxes.d.ts +48 -0
  30. package/dist/src/cicada/inboxes.js +82 -0
  31. package/dist/src/cicada/index.d.ts +16 -0
  32. package/dist/src/cicada/index.js +61 -0
  33. package/dist/src/cicada/phone.d.ts +48 -0
  34. package/dist/src/cicada/phone.js +306 -0
  35. package/dist/src/drive.d.ts +80 -0
  36. package/dist/src/drive.js +472 -0
  37. package/dist/src/extensions/index.d.ts +4 -0
  38. package/dist/src/extensions/index.js +5 -0
  39. package/dist/src/extensions/web/index.d.ts +6 -0
  40. package/dist/src/extensions/web/index.js +7 -0
  41. package/dist/src/extensions/web/session.d.ts +108 -0
  42. package/dist/src/extensions/web/session.js +470 -0
  43. package/dist/src/extensions/web/tools.d.ts +13 -0
  44. package/dist/src/extensions/web/tools.js +72 -0
  45. package/dist/src/friends.d.ts +39 -0
  46. package/dist/src/friends.js +119 -0
  47. package/dist/src/groups.d.ts +82 -0
  48. package/dist/src/groups.js +269 -0
  49. package/dist/src/inbox.d.ts +11 -0
  50. package/dist/src/inbox.js +35 -0
  51. package/dist/src/integrations.d.ts +52 -0
  52. package/dist/src/integrations.js +205 -0
  53. package/dist/src/magpie/explorer.d.ts +14 -0
  54. package/dist/src/magpie/explorer.js +36 -0
  55. package/dist/src/magpie/index.d.ts +16 -0
  56. package/dist/src/magpie/index.js +61 -0
  57. package/dist/src/magpie/portfolio.d.ts +52 -0
  58. package/dist/src/magpie/portfolio.js +179 -0
  59. package/dist/src/magpie/quotes.d.ts +35 -0
  60. package/dist/src/magpie/quotes.js +47 -0
  61. package/dist/src/magpie/room.d.ts +61 -0
  62. package/dist/src/magpie/room.js +238 -0
  63. package/dist/src/maps.d.ts +159 -0
  64. package/dist/src/maps.js +171 -0
  65. package/dist/src/marmot/browser.d.ts +139 -0
  66. package/dist/src/marmot/browser.js +389 -0
  67. package/dist/src/marmot/index.d.ts +20 -0
  68. package/dist/src/marmot/index.js +65 -0
  69. package/dist/src/marmot/media.d.ts +56 -0
  70. package/dist/src/marmot/media.js +265 -0
  71. package/dist/src/marmot/research.d.ts +337 -0
  72. package/dist/src/marmot/research.js +1138 -0
  73. package/dist/src/marmot/scraper.d.ts +59 -0
  74. package/dist/src/marmot/scraper.js +94 -0
  75. package/dist/src/marmot/web.d.ts +402 -0
  76. package/dist/src/marmot/web.js +2586 -0
  77. package/dist/src/marmot/workspace.d.ts +81 -0
  78. package/dist/src/marmot/workspace.js +263 -0
  79. package/dist/src/parrot/agent.d.ts +53 -0
  80. package/dist/src/parrot/agent.js +93 -0
  81. package/dist/src/parrot/chat.d.ts +84 -0
  82. package/dist/src/parrot/chat.js +237 -0
  83. package/dist/src/parrot/format.d.ts +128 -0
  84. package/dist/src/parrot/format.js +639 -0
  85. package/dist/src/parrot/generative.d.ts +261 -0
  86. package/dist/src/parrot/generative.js +185 -0
  87. package/dist/src/parrot/index.d.ts +22 -0
  88. package/dist/src/parrot/index.js +67 -0
  89. package/dist/src/parrot/room.d.ts +225 -0
  90. package/dist/src/parrot/room.js +466 -0
  91. package/dist/src/parrot/routing.d.ts +90 -0
  92. package/dist/src/parrot/routing.js +78 -0
  93. package/dist/src/parrot/share.d.ts +126 -0
  94. package/dist/src/parrot/share.js +261 -0
  95. package/dist/src/parrot/socket.d.ts +41 -0
  96. package/dist/src/parrot/socket.js +478 -0
  97. package/dist/src/payments.d.ts +73 -0
  98. package/dist/src/payments.js +107 -0
  99. package/dist/src/private/cards.css +75 -0
  100. package/dist/src/rooms.d.ts +76 -0
  101. package/dist/src/rooms.js +168 -0
  102. package/dist/src/shared/schema.d.ts +24 -0
  103. package/dist/src/shared/schema.js +1 -0
  104. package/dist/src/shared/server.d.ts +65 -0
  105. package/dist/src/shared/server.js +302 -0
  106. package/dist/src/termite/environment.d.ts +110 -0
  107. package/dist/src/termite/environment.js +263 -0
  108. package/dist/src/termite/index.d.ts +14 -0
  109. package/dist/src/termite/index.js +59 -0
  110. package/dist/src/termite/os.d.ts +326 -0
  111. package/dist/src/termite/os.js +572 -0
  112. package/dist/src/termite/versioning.d.ts +94 -0
  113. package/dist/src/termite/versioning.js +217 -0
  114. package/dist/src/tickets.d.ts +43 -0
  115. package/dist/src/tickets.js +138 -0
  116. package/dist/src/travel.d.ts +85 -0
  117. package/dist/src/travel.js +44 -0
  118. package/dist/src/ui/authentification.d.ts +24 -0
  119. package/dist/src/ui/authentification.js +177 -0
  120. package/dist/src/ui/brands.css +11 -0
  121. package/dist/src/ui/brands.d.ts +7 -0
  122. package/dist/src/ui/brands.js +14 -0
  123. package/dist/src/ui/browser.d.ts +74 -0
  124. package/dist/src/ui/browser.js +470 -0
  125. package/dist/src/ui/chat.d.ts +183 -0
  126. package/dist/src/ui/chat.js +2379 -0
  127. package/dist/src/ui/chatPanel.d.ts +109 -0
  128. package/dist/src/ui/chatPanel.js +768 -0
  129. package/dist/src/ui/chatSequence.d.ts +36 -0
  130. package/dist/src/ui/chatSequence.js +42 -0
  131. package/dist/src/ui/crown.d.ts +19 -0
  132. package/dist/src/ui/crown.js +199 -0
  133. package/dist/src/ui/cursor.d.ts +73 -0
  134. package/dist/src/ui/cursor.js +175 -0
  135. package/dist/src/ui/device.d.ts +33 -0
  136. package/dist/src/ui/device.js +49 -0
  137. package/dist/src/ui/drive.d.ts +69 -0
  138. package/dist/src/ui/drive.js +1243 -0
  139. package/dist/src/ui/generative.d.ts +39 -0
  140. package/dist/src/ui/generative.js +313 -0
  141. package/dist/src/ui/hover.d.ts +6 -0
  142. package/dist/src/ui/hover.js +210 -0
  143. package/dist/src/ui/index.d.ts +42 -0
  144. package/dist/src/ui/index.js +87 -0
  145. package/dist/src/ui/integrations.d.ts +13 -0
  146. package/dist/src/ui/integrations.js +175 -0
  147. package/dist/src/ui/maps.d.ts +87 -0
  148. package/dist/src/ui/maps.js +547 -0
  149. package/dist/src/ui/roster.d.ts +32 -0
  150. package/dist/src/ui/roster.js +163 -0
  151. package/dist/src/ui/talk.d.ts +12 -0
  152. package/dist/src/ui/talk.js +560 -0
  153. package/dist/src/ui/tickets.d.ts +13 -0
  154. package/dist/src/ui/tickets.js +966 -0
  155. package/dist/src/ui/toast.d.ts +7 -0
  156. package/dist/src/ui/toast.js +258 -0
  157. package/dist/src/ui/tokenText.d.ts +18 -0
  158. package/dist/src/ui/tokenText.js +96 -0
  159. package/dist/src/ui/tokenized.d.ts +42 -0
  160. package/dist/src/ui/tokenized.js +622 -0
  161. package/dist/src/ui/ui.css +4763 -0
  162. package/dist/src/ui/view.d.ts +23 -0
  163. package/dist/src/ui/view.js +584 -0
  164. package/dist/src/view.d.ts +113 -0
  165. package/dist/src/view.js +386 -0
  166. package/dist/src/webhooks.d.ts +66 -0
  167. package/dist/src/webhooks.js +78 -0
  168. package/dist/ui.d.ts +1 -0
  169. package/dist/ui.js +1 -0
  170. package/package.json +87 -4
  171. package/README.md +0 -3
@@ -0,0 +1,7 @@
1
+ type ToastType = 'success' | 'error' | 'warning' | 'info';
2
+ export declare function sendInformaticToast(html: string, type: ToastType, duration?: number): Promise<boolean>;
3
+ export declare function sendProgressToast(html: string): {
4
+ show: Promise<boolean>;
5
+ setProgress: (progress: number) => void;
6
+ };
7
+ export {};
@@ -0,0 +1,258 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import gsap from "gsap";
5
+ // Per-type palette (baked in — not sourced from host CSS). Each entry is a soft
6
+ // tinted surface with a saturated accent bar + icon so the toast reads clearly
7
+ // on any background.
8
+ const PALETTE = {
9
+ success: { bg: '#f7fbf8', border: '#d7e8dc', accent: '#2f7d50', icon: 'M20 6 9 17l-5-5' },
10
+ error: { bg: '#fff8f7', border: '#efd9d6', accent: '#b94b43', icon: 'M18 6 6 18M6 6l12 12' },
11
+ warning: { bg: '#fffaf0', border: '#ebdfc4', accent: '#9c721e', icon: 'M12 9v4m0 4h.01M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z' },
12
+ info: { bg: '#f7f9fc', border: '#dce2ea', accent: '#4d6f94', icon: 'M12 16v-4m0-4h.01M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0z' },
13
+ };
14
+ const QUEUE = [];
15
+ let ACTIVE = null;
16
+ let PROCESSING = false;
17
+ let listener = null;
18
+ function notify() {
19
+ listener?.(ACTIVE ? ACTIVE.state : null);
20
+ }
21
+ async function drain() {
22
+ if (PROCESSING)
23
+ return;
24
+ PROCESSING = true;
25
+ ensureMounted();
26
+ await MOUNT_READY;
27
+ while (QUEUE.length > 0) {
28
+ const build = QUEUE.shift();
29
+ const toast = build();
30
+ if (!toast)
31
+ continue;
32
+ ACTIVE = toast;
33
+ notify();
34
+ try {
35
+ await toast.done;
36
+ }
37
+ catch { /* dismissed */ }
38
+ ACTIVE = null;
39
+ notify();
40
+ }
41
+ PROCESSING = false;
42
+ }
43
+ // ─── Public API (imperative, unchanged signatures) ────────────────────────────
44
+ export async function sendInformaticToast(html, type, duration = 5000) {
45
+ return new Promise((resolveShow) => {
46
+ QUEUE.push(() => {
47
+ let resolveDone;
48
+ const done = new Promise((res) => { resolveDone = res; });
49
+ const toast = {
50
+ state: { html, type, progress: null },
51
+ done,
52
+ resolveDone,
53
+ resolveShow,
54
+ dismissed: false,
55
+ };
56
+ // Auto-dismiss after `duration` once shown; the component reports the
57
+ // shown flag and starts the timer via onShown below.
58
+ toast.autoDismissMs = duration;
59
+ return toast;
60
+ });
61
+ void drain();
62
+ });
63
+ }
64
+ export function sendProgressToast(html) {
65
+ let setter = () => { };
66
+ let current = 0;
67
+ const show = new Promise((resolveShow) => {
68
+ QUEUE.push(() => {
69
+ if (current >= 1) {
70
+ resolveShow(false);
71
+ return null;
72
+ }
73
+ let resolveDone;
74
+ const done = new Promise((res) => { resolveDone = res; });
75
+ const toast = {
76
+ state: { html, type: 'info', progress: current },
77
+ done,
78
+ resolveDone,
79
+ resolveShow,
80
+ dismissed: false,
81
+ };
82
+ setter = (p) => {
83
+ const clamped = Math.min(Math.max(p, 0), 1);
84
+ toast.state = { ...toast.state, progress: clamped };
85
+ if (ACTIVE === toast)
86
+ notify();
87
+ if (clamped >= 1) {
88
+ // Let the filled bar render a beat, then dismiss.
89
+ setTimeout(() => { if (ACTIVE === toast)
90
+ requestDismiss(toast); }, 250);
91
+ }
92
+ };
93
+ return toast;
94
+ });
95
+ void drain();
96
+ });
97
+ return {
98
+ show,
99
+ setProgress: (p) => { current = p; setter(p); },
100
+ };
101
+ }
102
+ // ─── Dismiss plumbing ──────────────────────────────────────────────────────────
103
+ function requestDismiss(toast) {
104
+ if (toast.dismissed)
105
+ return;
106
+ toast.dismissed = true;
107
+ // The component watches for dismiss requests to animate out, then finalizes.
108
+ DISMISS_LISTENERS.forEach((fn) => fn(toast));
109
+ }
110
+ const DISMISS_LISTENERS = new Set();
111
+ // ─── React component + self-mount ──────────────────────────────────────────────
112
+ const PORTAL_ID = 'fauna-toast-portal';
113
+ let mounted = false;
114
+ let resolveMount = () => { };
115
+ const MOUNT_READY = new Promise((resolve) => { resolveMount = resolve; });
116
+ function ensureMounted() {
117
+ if (mounted || typeof document === 'undefined')
118
+ return;
119
+ mounted = true;
120
+ const host = document.createElement('div');
121
+ host.id = PORTAL_ID;
122
+ Object.assign(host.style, {
123
+ position: 'fixed',
124
+ top: 'clamp(14px, 2vw, 22px)',
125
+ left: '50%',
126
+ transform: 'translateX(-50%)',
127
+ zIndex: '2147483647',
128
+ width: 'min(380px, calc(100vw - 28px))',
129
+ pointerEvents: 'none',
130
+ });
131
+ document.body.appendChild(host);
132
+ createRoot(host).render(_jsx(ToastRoot, {}));
133
+ }
134
+ function ToastRoot() {
135
+ const [state, setState] = useState(null);
136
+ const activeRef = useRef(null);
137
+ const cardRef = useRef(null);
138
+ const dismissTimer = useRef(null);
139
+ // Subscribe the module store to this component instance.
140
+ useEffect(() => {
141
+ listener = (s) => {
142
+ activeRef.current = ACTIVE;
143
+ setState(s);
144
+ };
145
+ if (ACTIVE) {
146
+ activeRef.current = ACTIVE;
147
+ setState(ACTIVE.state);
148
+ }
149
+ resolveMount();
150
+ return () => { listener = null; };
151
+ }, []);
152
+ const animateOut = (toast) => {
153
+ const el = cardRef.current;
154
+ const finish = () => {
155
+ toast.resolveDone();
156
+ };
157
+ if (!el) {
158
+ finish();
159
+ return;
160
+ }
161
+ gsap.killTweensOf(el);
162
+ gsap.to(el, {
163
+ duration: 0.28,
164
+ x: 18,
165
+ y: -6,
166
+ opacity: 0,
167
+ scale: 0.98,
168
+ ease: 'power2.in',
169
+ onComplete: finish,
170
+ });
171
+ };
172
+ // React to external dismiss requests (progress-complete / setProgress).
173
+ useEffect(() => {
174
+ const onDismiss = (t) => { if (t === activeRef.current)
175
+ animateOut(t); };
176
+ DISMISS_LISTENERS.add(onDismiss);
177
+ return () => { DISMISS_LISTENERS.delete(onDismiss); };
178
+ }, []);
179
+ // Animate in whenever a new active toast appears; arm auto-dismiss.
180
+ useEffect(() => {
181
+ if (dismissTimer.current) {
182
+ clearTimeout(dismissTimer.current);
183
+ dismissTimer.current = null;
184
+ }
185
+ const toast = activeRef.current;
186
+ const el = cardRef.current;
187
+ if (!state || !toast || !el)
188
+ return;
189
+ gsap.killTweensOf(el);
190
+ gsap.fromTo(el, { x: 18, y: -6, opacity: 0, scale: 0.98 }, {
191
+ x: 0,
192
+ y: 0,
193
+ opacity: 1,
194
+ scale: 1,
195
+ duration: 0.36,
196
+ ease: 'power3.out',
197
+ onComplete: () => {
198
+ toast.resolveShow(true);
199
+ if (toast.autoDismissMs && toast.state.progress === null) {
200
+ dismissTimer.current = setTimeout(() => animateOut(toast), toast.autoDismissMs);
201
+ }
202
+ },
203
+ });
204
+ return () => { if (dismissTimer.current)
205
+ clearTimeout(dismissTimer.current); };
206
+ // eslint-disable-next-line react-hooks/exhaustive-deps
207
+ }, [state]);
208
+ if (!state)
209
+ return null;
210
+ const p = PALETTE[state.type];
211
+ const onClick = () => {
212
+ const toast = activeRef.current;
213
+ if (toast)
214
+ animateOut(toast);
215
+ };
216
+ return (_jsxs("div", { ref: cardRef, onClick: onClick, role: "status", "aria-live": "polite", style: {
217
+ position: 'relative',
218
+ display: 'flex',
219
+ alignItems: 'center',
220
+ gap: 10,
221
+ width: '100%',
222
+ boxSizing: 'border-box',
223
+ padding: '11px 12px',
224
+ borderRadius: 12,
225
+ background: p.bg,
226
+ border: `1px solid ${p.border}`,
227
+ boxShadow: '0 12px 32px rgba(39, 35, 29, 0.14), 0 2px 8px rgba(39, 35, 29, 0.08)',
228
+ color: '#292722',
229
+ fontFamily: 'inherit',
230
+ fontSize: 13,
231
+ fontWeight: 500,
232
+ lineHeight: 1.45,
233
+ letterSpacing: '0.01em',
234
+ cursor: 'pointer',
235
+ pointerEvents: 'auto',
236
+ opacity: 0,
237
+ overflow: 'hidden',
238
+ backdropFilter: 'blur(14px)',
239
+ WebkitBackdropFilter: 'blur(14px)',
240
+ }, children: [_jsx("span", { style: {
241
+ flex: '0 0 auto',
242
+ display: 'grid',
243
+ placeItems: 'center',
244
+ width: 24,
245
+ height: 24,
246
+ borderRadius: 999,
247
+ background: `${p.accent}18`,
248
+ color: p.accent,
249
+ }, children: _jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2.4, strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: p.icon }) }) }), _jsx("span", { style: { flex: 1, minWidth: 0, overflowWrap: 'anywhere' }, dangerouslySetInnerHTML: { __html: state.html } }), _jsx("span", { "aria-hidden": "true", style: { flex: '0 0 auto', color: '#8d8981', fontSize: 16, lineHeight: 1 }, children: "\u00D7" }), state.progress !== null && (_jsx("span", { style: {
250
+ position: 'absolute',
251
+ left: 0,
252
+ bottom: 0,
253
+ height: 3,
254
+ width: `${Math.round(state.progress * 100)}%`,
255
+ background: p.accent,
256
+ transition: 'width 0.12s linear',
257
+ } }))] }));
258
+ }
@@ -0,0 +1,18 @@
1
+ export type Token = {
2
+ type: string;
3
+ value: string;
4
+ label: string;
5
+ icon?: string;
6
+ };
7
+ export type Part = {
8
+ kind: 'text';
9
+ text: string;
10
+ } | {
11
+ kind: 'token';
12
+ token: Token;
13
+ };
14
+ export declare function encodeToken(token: Token): string;
15
+ export declare function serializeParts(parts: Part[]): string;
16
+ export declare function parseRichText(text: string): Part[];
17
+ export declare function hasTokens(text: string): boolean;
18
+ export declare function toPlainText(text: string): string;
@@ -0,0 +1,96 @@
1
+ // Lossless token serialization (DOM-free).
2
+ //
3
+ // A composed message is flattened to a single string (for persistence and for
4
+ // feeding back into the chat log). Tokens emit a self-describing marker carrying
5
+ // the whole Token as base64-encoded JSON: `[[ft:<b64>]]`, fenced by zero-width
6
+ // spaces so it survives round-trips and never trips markdown. `parseRichText`
7
+ // turns the string back into Parts so any consumer hydrates the same chips, and
8
+ // `toPlainText` strips markers down to `@label` (plus `ids` when present) for
9
+ // the LLM / clipboard.
10
+ const TOKEN_MARKER = /\[\[ft:([A-Za-z0-9+/=]+)\]\]/g;
11
+ function encodeUtf8Base64(str) {
12
+ const bytes = new TextEncoder().encode(str);
13
+ let binary = '';
14
+ for (const b of bytes)
15
+ binary += String.fromCharCode(b);
16
+ return btoa(binary);
17
+ }
18
+ function decodeUtf8Base64(b64) {
19
+ const binary = atob(b64);
20
+ const bytes = new Uint8Array(binary.length);
21
+ for (let i = 0; i < binary.length; i++)
22
+ bytes[i] = binary.charCodeAt(i);
23
+ return new TextDecoder().decode(bytes);
24
+ }
25
+ export function encodeToken(token) {
26
+ return `\u200B[[ft:${encodeUtf8Base64(JSON.stringify(token))}]]\u200B`;
27
+ }
28
+ export function serializeParts(parts) {
29
+ return parts.map(p => p.kind === 'text' ? p.text : encodeToken(p.token)).join('');
30
+ }
31
+ export function parseRichText(text) {
32
+ const parts = [];
33
+ let lastIndex = 0;
34
+ const pushText = (raw) => {
35
+ const clean = raw.replace(/\u200B/g, '');
36
+ if (clean.length === 0)
37
+ return;
38
+ const last = parts[parts.length - 1];
39
+ if (last && last.kind === 'text')
40
+ last.text += clean;
41
+ else
42
+ parts.push({ kind: 'text', text: clean });
43
+ };
44
+ TOKEN_MARKER.lastIndex = 0;
45
+ let match;
46
+ while ((match = TOKEN_MARKER.exec(text)) !== null) {
47
+ pushText(text.slice(lastIndex, match.index));
48
+ try {
49
+ parts.push({ kind: 'token', token: JSON.parse(decodeUtf8Base64(match[1])) });
50
+ }
51
+ catch {
52
+ pushText(match[0]);
53
+ }
54
+ lastIndex = match.index + match[0].length;
55
+ }
56
+ pushText(text.slice(lastIndex));
57
+ return parts;
58
+ }
59
+ export function hasTokens(text) {
60
+ TOKEN_MARKER.lastIndex = 0;
61
+ return TOKEN_MARKER.test(text);
62
+ }
63
+ function expandToken(token) {
64
+ if (token.type === 'pin') {
65
+ try {
66
+ const data = JSON.parse(token.value);
67
+ const note = typeof data?.note === 'string' && data.note.trim() ? data.note.trim() : token.label;
68
+ return note ? `@Pin ${note}` : '@Pin';
69
+ }
70
+ catch {
71
+ return token.label ? `@Pin ${token.label}` : '@Pin';
72
+ }
73
+ }
74
+ const label = token.label || token.value;
75
+ try {
76
+ const data = JSON.parse(token.value);
77
+ if (data && Array.isArray(data.ids)) {
78
+ const ids = data.ids.map(String).filter(Boolean);
79
+ return ids.length ? `@${label} [${ids.join(', ')}]` : `@${label} (none)`;
80
+ }
81
+ }
82
+ catch { /* not JSON, or no ids */ }
83
+ return `@${label}`;
84
+ }
85
+ export function toPlainText(text) {
86
+ return text
87
+ .replace(TOKEN_MARKER, (_, b64) => {
88
+ try {
89
+ return expandToken(JSON.parse(decodeUtf8Base64(b64)));
90
+ }
91
+ catch {
92
+ return '';
93
+ }
94
+ })
95
+ .replace(/\u200B/g, '');
96
+ }
@@ -0,0 +1,42 @@
1
+ import { Fauna } from "fauna-api";
2
+ import { type Token, type Part } from "./tokenText.js";
3
+ export type { Token, Part };
4
+ export { encodeToken, serializeParts, parseRichText, hasTokens, toPlainText } from "./tokenText.js";
5
+ export type Suggestion = {
6
+ label: string;
7
+ subtitle?: string;
8
+ icon?: string;
9
+ image?: string;
10
+ data?: any;
11
+ };
12
+ export type Trigger = {
13
+ char: string;
14
+ type: string;
15
+ suggest: (query: string) => Promise<Suggestion[]> | Suggestion[];
16
+ onPick: (s: Suggestion) => Token;
17
+ };
18
+ export declare function createTokenizedInput(container: HTMLElement, options?: Partial<{
19
+ placeholder: string;
20
+ triggers: Trigger[];
21
+ multiline: boolean;
22
+ onSubmit: (parts: Part[]) => void;
23
+ onInput: (parts: Part[]) => void;
24
+ }>): {
25
+ getParts: () => Part[];
26
+ getText: () => string;
27
+ setParts: (parts: Part[]) => void;
28
+ insertToken: (token: Token) => void;
29
+ clear: () => void;
30
+ focus: () => void;
31
+ getElement: () => HTMLElement;
32
+ setPlaceholder: (text: string) => void;
33
+ };
34
+ /**
35
+ * `@` mentions. By default it searches every Fauna user; pass `people` (a
36
+ * group's members, say) to pick only from that list, shown in full as soon as
37
+ * `@` is typed.
38
+ */
39
+ export declare function createUserTrigger(credentials: Fauna.Authentification.Credentials, options?: {
40
+ people?: Fauna.Authentification.Profile[];
41
+ }): Trigger;
42
+ export declare function createDriveTrigger(credentials: Fauna.Authentification.Credentials): Trigger;