@impro.social/impro-plugin 0.0.20 → 0.0.22

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 (3) hide show
  1. package/main.d.ts +1420 -0
  2. package/main.js +1107 -125
  3. package/package.json +13 -5
package/main.d.ts ADDED
@@ -0,0 +1,1420 @@
1
+ /**
2
+ * Proxied fetch through the host. Requires the `"networkRequest"` permission
3
+ * scope and the target URL must be covered by the plugin's manifest allowlist.
4
+ * `init` accepts `method`, `headers` (plain object, `Headers`, `Map`, or
5
+ * `[name, value]` iterable), and a string `body`. Resolves to a
6
+ * {@link PluginResponse}.
7
+ * @param {string} url
8
+ * @param {PluginFetchInit} [init]
9
+ * @returns {Promise<PluginResponse>}
10
+ */
11
+ export function fetch(url: string, init?: PluginFetchInit): Promise<PluginResponse>;
12
+ /**
13
+ * Convenience wrapper that returns a new {@link FlattenedTokens} for `tokens`.
14
+ * @param {RichTextToken[]} tokens
15
+ * @returns {FlattenedTokens}
16
+ */
17
+ export function flattenForScan(tokens: RichTextToken[]): FlattenedTokens;
18
+ /**
19
+ * @typedef {Record<string, unknown>} PostView
20
+ * Hydrated `app.bsky.feed.defs#postView` shape.
21
+ * @typedef {Record<string, unknown>} ProfileView
22
+ * Basic `app.bsky.actor.defs#profileView` shape.
23
+ * @typedef {Record<string, unknown>} DetailedProfileView
24
+ * Detailed profile view with viewer relationship fields.
25
+ * @typedef {Record<string, unknown>} KnownFollowersResponse
26
+ * Paginated response from `getKnownFollowers`: `{ followers, cursor }`.
27
+ * @typedef {Record<string, unknown>} RepoRecord
28
+ * A raw repo record: `{ uri, cid, value }`.
29
+ * @typedef {Record<string, unknown>} FeedItem
30
+ * A `app.bsky.feed.defs#feedViewPost` (post + reply/repost context).
31
+ * @typedef {{ $type: string } & Record<string, unknown>} RichTextFacetFeature
32
+ * One feature of a facet; fields beyond `$type` vary by service.
33
+ * @typedef {{ index: { byteStart: number, byteEnd: number }, features?: RichTextFacetFeature[] }} RichTextFacet
34
+ * An `app.bsky.richtext.facet` — a byte range plus the features applying to it.
35
+ * @typedef {{ type: "text", value: string }} RichTextTextToken
36
+ * A run of plain text.
37
+ * @typedef {{ type: "facet", facet: RichTextFacet, text: string }} RichTextFacetToken
38
+ * The text covered by one facet; the host restores the original facet payload.
39
+ * @typedef {{ type: "inline" | "block", node: VirtualEl | Record<string, unknown>, pluginId?: string }} RichTextNodeToken
40
+ * Custom content the plugin renders itself — `block` on its own line, `inline` in the text flow.
41
+ * @typedef {RichTextTextToken | RichTextFacetToken | RichTextNodeToken} RichTextToken
42
+ * One token in a rich-text stream — `text`, `facet`, `inline`, or `block`.
43
+ * @typedef {Record<string, string> | Headers | Map<string, string> | Iterable<[string, string], void, undefined>} PluginFetchHeaders
44
+ * Any header collection {@link fetch} accepts — read structurally, not by class.
45
+ * @typedef {{ method?: string, headers?: PluginFetchHeaders, body?: string }} PluginFetchInit
46
+ * Options for {@link fetch} — a subset of `RequestInit` the host proxy supports.
47
+ * @typedef {{ feedGenerator: Record<string, unknown> | null, feedContext: string | null, feedProxyUrl: string | null }} PostContextMenuMeta
48
+ * Where a post was seen, passed to `post-context-menu` listeners.
49
+ * @typedef {{ kind: "post" | "reply" | "quote", replyTo: PostView | null, replyRoot: PostView | null, quotedPost: PostView | null }} PostComposerContext
50
+ * What the composer is being opened for, passed to `post-composer-open` listeners.
51
+ * @typedef {{
52
+ * "post-context-menu": (menu: Menu, post: PostView, meta?: PostContextMenuMeta) => void,
53
+ * "profile-context-menu": (menu: Menu, profile: ProfileView) => void,
54
+ * "post-composer-open": (composer: Composer, context: PostComposerContext) => void,
55
+ * }} PluginEventMap
56
+ * The events {@link Plugin.on} accepts, and the listener each one takes.
57
+ * @typedef {VirtualEl | null | undefined} RenderResult
58
+ * What a render callback may return: a tree to render, or nothing.
59
+ */
60
+ export class SimpleUUID {
61
+ create(): number;
62
+ #private;
63
+ }
64
+ /**
65
+ * A single item in a {@link Menu}. Configure with the chained setters and
66
+ * an `onClick` handler. Not constructed directly — obtained via
67
+ * `Menu.addItem(builder)`.
68
+ */
69
+ export class MenuItem {
70
+ title: string;
71
+ icon: string | VirtualEl | null;
72
+ /** @internal */
73
+ _callback: () => void;
74
+ /**
75
+ * Set the menu item's label.
76
+ * @param {string} title
77
+ * @returns {this}
78
+ */
79
+ setTitle(title: string): this;
80
+ /**
81
+ * Set the leading icon. Either a named icon (string) or a {@link VirtualEl}
82
+ * to render as the icon.
83
+ * @param {string | VirtualEl} icon
84
+ * @returns {this}
85
+ */
86
+ setIcon(icon: string | VirtualEl): this;
87
+ /**
88
+ * Called when the user activates the item.
89
+ * @param {() => void} callback
90
+ * @returns {this}
91
+ */
92
+ onClick(callback: () => void): this;
93
+ }
94
+ /**
95
+ * A context-menu builder passed as the first argument to
96
+ * `post-context-menu` and `profile-context-menu` event listeners. Call
97
+ * `addItem` to append menu entries.
98
+ */
99
+ export class Menu {
100
+ /** @type {MenuItem[]} */
101
+ items: MenuItem[];
102
+ /**
103
+ * Append a menu item. The builder receives a {@link MenuItem} to configure.
104
+ * @param {(item: MenuItem) => void} builder
105
+ * @returns {this}
106
+ */
107
+ addItem(builder: (item: MenuItem) => void): this;
108
+ /** @internal */
109
+ _serialize(): {
110
+ title: string;
111
+ icon: string | SerializedElement | null;
112
+ handlerId: number;
113
+ }[];
114
+ }
115
+ /**
116
+ * Builder passed as the first argument to `post-composer-open` event
117
+ * listeners. Queues text operations that the host applies to the composer once
118
+ * all listeners have run. operations from multiple plugins are applied in order.
119
+ */
120
+ export class Composer {
121
+ /**
122
+ * Replace the composer's current text.
123
+ * @param {string} text
124
+ * @returns {this}
125
+ */
126
+ setText(text: string): this;
127
+ /**
128
+ * Append text to the end of the composer.
129
+ * @param {string} text
130
+ * @returns {this}
131
+ */
132
+ appendText(text: string): this;
133
+ /**
134
+ * Prepend text to the start of the composer.
135
+ * @param {string} text
136
+ * @returns {this}
137
+ */
138
+ prependText(text: string): this;
139
+ /**
140
+ * Move the caret to the given character index in the final text.
141
+ * @param {number} index
142
+ * @returns {this}
143
+ */
144
+ setCursor(index: number): this;
145
+ /** @internal */
146
+ _serialize(): {
147
+ ops: {
148
+ op: string;
149
+ text: string;
150
+ }[];
151
+ cursor: number | null;
152
+ };
153
+ #private;
154
+ }
155
+ /**
156
+ * Read-only accessors for appview data with the current user as the viewer.
157
+ * Reached via {@link App.data} on the plugin's {@link App} instance.
158
+ */
159
+ export class PluginData {
160
+ /**
161
+ * Fetch a hydrated post view by AT-URI, as seen by the current user.
162
+ * @param {string} uri
163
+ * @returns {Promise<PostView>}
164
+ */
165
+ getPost(uri: string): Promise<PostView>;
166
+ /**
167
+ * Fetch the basic profile view for a DID.
168
+ * @param {string} did
169
+ * @returns {Promise<ProfileView>}
170
+ */
171
+ getProfile(did: string): Promise<ProfileView>;
172
+ /**
173
+ * Like {@link PluginData.getProfile}, but includes viewer relationship
174
+ * details not present on the basic profile view: `viewer.following`,
175
+ * `viewer.followedBy`, and `viewer.knownFollowers` (a summary of mutual
176
+ * followers).
177
+ * @param {string} did
178
+ * @returns {Promise<DetailedProfileView>}
179
+ */
180
+ getDetailedProfile(did: string): Promise<DetailedProfileView>;
181
+ /**
182
+ * The full known-followers list for `did`. The summary on
183
+ * {@link PluginData.getDetailedProfile}'s `viewer.knownFollowers` is
184
+ * capped to a handful; use this to paginate the complete list.
185
+ * @param {string} did
186
+ * @returns {Promise<KnownFollowersResponse>}
187
+ */
188
+ getKnownFollowers(did: string): Promise<KnownFollowersResponse>;
189
+ /**
190
+ * Fetch a raw repo record by `(repo, collection, rkey)`.
191
+ * @param {string} repo
192
+ * @param {string} collection
193
+ * @param {string} rkey
194
+ * @returns {Promise<RepoRecord>}
195
+ */
196
+ getRecord(repo: string, collection: string, rkey: string): Promise<RepoRecord>;
197
+ }
198
+ /**
199
+ * The plugin's handle to the running impro app. Exposed as `this.app` on a
200
+ * {@link Plugin} instance. Owns event subscriptions, data accessors
201
+ * ({@link App.data}), and user-scoped actions.
202
+ */
203
+ export class App {
204
+ /**
205
+ * The signed-in user's basic profile, populated before `onload()` runs.
206
+ * Null when no session is active.
207
+ * @type {ProfileView | null}
208
+ */
209
+ currentUser: ProfileView | null;
210
+ /** Read-only appview accessors — see {@link PluginData}. */
211
+ data: PluginData;
212
+ /**
213
+ * Register an event listener. Supported events:
214
+ *
215
+ * - `"post-context-menu"` — `(menu: Menu, post) => void`, called when the
216
+ * user opens a post's context menu.
217
+ * - `"profile-context-menu"` — `(menu: Menu, profile) => void`, called
218
+ * when the user opens a profile's context menu.
219
+ * - `"post-composer-open"` — `(composer: Composer, context: { kind, replyTo, replyRoot, quotedPost }) => void`,
220
+ * called when the post composer opens; use `composer` to seed text.
221
+ *
222
+ * The `listener` signature varies per event — see {@link PluginEventMap}.
223
+ * @template {keyof PluginEventMap} K
224
+ * @param {K} event
225
+ * @param {PluginEventMap[K]} listener
226
+ * @returns {void}
227
+ */
228
+ on<K extends keyof PluginEventMap>(event: K, listener: PluginEventMap[K]): void;
229
+ /**
230
+ * Re-run registered feed filters. Pass a `feedURI` to limit the refresh
231
+ * to one feed, or omit/pass `null` to refresh every feed.
232
+ * @param {string | null} [feedURI]
233
+ * @returns {Promise<void>}
234
+ */
235
+ refreshFeedFilters(feedURI?: string | null): Promise<void>;
236
+ /**
237
+ * Mute an actor on behalf of the signed-in user. Requires the `"mute"`
238
+ * scope in the plugin manifest's `permissions.actions`.
239
+ * @param {string} did
240
+ * @returns {Promise<void>}
241
+ */
242
+ muteActor(did: string): Promise<void>;
243
+ /**
244
+ * Unmute an actor. Requires the `"mute"` scope.
245
+ * @param {string} did
246
+ * @returns {Promise<void>}
247
+ */
248
+ unmuteActor(did: string): Promise<void>;
249
+ /**
250
+ * Block an actor on behalf of the signed-in user. Requires the `"block"`
251
+ * scope in the plugin manifest's `permissions.actions`.
252
+ * @param {string} did
253
+ * @returns {Promise<void>}
254
+ */
255
+ blockActor(did: string): Promise<void>;
256
+ /**
257
+ * Unblock an actor. Requires the `"block"` scope.
258
+ * @param {string} did
259
+ * @returns {Promise<void>}
260
+ */
261
+ unblockActor(did: string): Promise<void>;
262
+ /**
263
+ * Acts like the user clicking "Show less like this": sends the
264
+ * `requestLess` feedback signal to `feedUri` and collapses the post
265
+ * behind a feedback message in feeds. Requires the `"feedFeedback"`
266
+ * scope.
267
+ * @param {string} postUri
268
+ * @param {string} feedUri
269
+ * @returns {Promise<void>}
270
+ */
271
+ showLessLikeThis(postUri: string, feedUri: string): Promise<void>;
272
+ /**
273
+ * Sends the `requestMore` feedback signal to `feedUri` for `postUri`.
274
+ * Requires the `"feedFeedback"` scope.
275
+ * @param {string} postUri
276
+ * @param {string} feedUri
277
+ * @returns {Promise<void>}
278
+ */
279
+ showMoreLikeThis(postUri: string, feedUri: string): Promise<void>;
280
+ }
281
+ /**
282
+ * Response returned from {@link fetch}. Body is buffered by the host and
283
+ * exposed as text or parsed JSON. `status`, `ok`, and `headers` (a `Map`)
284
+ * mirror the underlying HTTP response.
285
+ */
286
+ export class PluginResponse {
287
+ /**
288
+ * @internal
289
+ * @param {SerializedFetchResponse} response
290
+ */
291
+ constructor({ status, ok, headers, body }: SerializedFetchResponse);
292
+ /** @type {number} */
293
+ status: number;
294
+ /** @type {boolean} */
295
+ ok: boolean;
296
+ /** @type {Map<string, string>} */
297
+ headers: Map<string, string>;
298
+ /**
299
+ * Resolves with the response body as a string.
300
+ * @returns {Promise<string>}
301
+ */
302
+ text(): Promise<string>;
303
+ /**
304
+ * Resolves with the response body parsed as JSON.
305
+ * @returns {Promise<unknown>}
306
+ */
307
+ json(): Promise<unknown>;
308
+ #private;
309
+ }
310
+ /**
311
+ * Shows a toast notification. `noticeEl` is a {@link VirtualEl} that can be
312
+ * mutated (e.g. `addClass`, appending children) synchronously after
313
+ * construction — the host serializes and renders the toast on a microtask, so
314
+ * any mutations made in the same task apply to the initial render. Mutations
315
+ * or `setMessage` calls made after that point do NOT propagate to the mounted
316
+ * toast; call {@link Notice.hide} and create a new `Notice` to change it.
317
+ */
318
+ export class Notice {
319
+ /**
320
+ * `timeout` is in milliseconds; `0` (the default) keeps the toast up until
321
+ * {@link Notice.hide} is called.
322
+ * @param {string} message
323
+ * @param {number} [timeout=0]
324
+ */
325
+ constructor(message: string, timeout?: number);
326
+ /** @type {VirtualEl} */
327
+ noticeEl: VirtualEl;
328
+ /**
329
+ * Updates `noticeEl`'s text. Only takes effect if called synchronously
330
+ * before the microtask that snapshots the toast for the initial render.
331
+ * @param {string} message
332
+ * @returns {this}
333
+ */
334
+ setMessage(message: string): this;
335
+ /**
336
+ * Dismisses the toast. No-op if already hidden.
337
+ * @returns {void}
338
+ */
339
+ hide(): void;
340
+ #private;
341
+ }
342
+ /**
343
+ * Injects a CSS block scoped to the plugin. The stylesheet is mounted by the
344
+ * host on the next microtask; snippets are automatically removed when the
345
+ * plugin unloads.
346
+ */
347
+ export class StyleSnippet {
348
+ /**
349
+ * @param {string} cssText
350
+ */
351
+ constructor(cssText: string);
352
+ /**
353
+ * Resolves once the snippet has been applied by the host.
354
+ * @type {Promise<void>}
355
+ */
356
+ ready: Promise<void>;
357
+ /**
358
+ * Removes the snippet from the document. No-op if already removed.
359
+ * @returns {void}
360
+ */
361
+ remove(): void;
362
+ #private;
363
+ }
364
+ /**
365
+ * Base class for impro plugins. Subclass this and override {@link Plugin.onload}
366
+ * (and optionally {@link Plugin.onunload}) to wire up your plugin's extension
367
+ * points. `this.app` is the shared {@link App} instance for host actions and
368
+ * data. Call `MyPlugin.register()` at the top of your plugin's main.js to boot.
369
+ */
370
+ export class Plugin {
371
+ /**
372
+ * Boots the plugin. Call as `MyPlugin.register()` at the top of your plugin's
373
+ * main.js — instantiates the subclass, resolves the current user onto
374
+ * `app.currentUser`, then invokes {@link Plugin.onload}. Idempotent.
375
+ * @returns {void}
376
+ */
377
+ static register(): void;
378
+ /** @type {App} */
379
+ app: App;
380
+ /**
381
+ * Adds an item to the impro sidebar. `icon` is a {@link VirtualEl} (typically
382
+ * an SVG) or a string; `callback` runs when the item is clicked.
383
+ * @param {string | VirtualEl} icon
384
+ * @param {string} title
385
+ * @param {() => void} [callback]
386
+ * @returns {void}
387
+ */
388
+ addSidebarItem(icon: string | VirtualEl, title: string, callback?: () => void): void;
389
+ /**
390
+ * Loads this plugin's account-synced JSON blob. Follows the user across
391
+ * devices via account preferences. Returns whatever was last saved, or null.
392
+ * @returns {Promise<unknown>}
393
+ */
394
+ loadData(): Promise<unknown>;
395
+ /**
396
+ * Persists `data` as this plugin's account-synced JSON blob.
397
+ * @param {Cloneable} data
398
+ * @returns {Promise<void>}
399
+ */
400
+ saveData(data: Cloneable): Promise<void>;
401
+ /**
402
+ * Device-local counterpart to {@link Plugin.loadData}: never synced through
403
+ * the user's account preferences, so it's the right place for anything that
404
+ * shouldn't silently follow the plugin to another device (e.g. a locally
405
+ * held secret key). Cleared on uninstall, same as loadData/saveData.
406
+ * @returns {Promise<unknown>}
407
+ */
408
+ loadLocalData(): Promise<unknown>;
409
+ /**
410
+ * Device-local counterpart to {@link Plugin.saveData}.
411
+ * @param {Cloneable} data
412
+ * @returns {Promise<void>}
413
+ */
414
+ saveLocalData(data: Cloneable): Promise<void>;
415
+ /**
416
+ * Registers a {@link PluginSettingTab} shown under this plugin's entry in
417
+ * the app's settings.
418
+ * @param {PluginSettingTab} tab
419
+ * @returns {void}
420
+ */
421
+ addSettingTab(tab: PluginSettingTab): void;
422
+ /**
423
+ * Registers a feed filter. `callback(feedUri, feedItems)` returns an object
424
+ * `{ [postUri]: false }` for posts to hide from the feed. Only `false` hides;
425
+ * any other value is ignored, so one plugin can't un-hide what another hid.
426
+ * @param {(feedUri: string, feedItems: FeedItem[]) => Record<string, boolean> | Promise<Record<string, boolean>>} callback
427
+ * @returns {void}
428
+ */
429
+ addFeedFilter(callback?: (feedUri: string, feedItems: FeedItem[]) => Record<string, boolean> | Promise<Record<string, boolean>>): void;
430
+ /**
431
+ * Registers a rich-text transform. `callback(tokens, context)` receives the
432
+ * token stream for one post and returns a new token array (or the input
433
+ * unchanged). Tokens are one of: `text` (plain string run), `facet` (linked
434
+ * text with an atproto facet feature), `inline` (a plugin-produced inline
435
+ * {@link VirtualEl}), or `block` (a plugin-produced block VirtualEl). See
436
+ * {@link FlattenedTokens} for pattern-matching across token boundaries.
437
+ *
438
+ * A node token's `node` is a {@link VirtualEl} when this transform creates it,
439
+ * but arrives in serialized form when an earlier transform produced it.
440
+ *
441
+ * `options.handlesFacetTypes` is an array of facet feature `$type` strings
442
+ * this transform owns, so the host can suppress fallback rendering flash
443
+ * while the transform runs.
444
+ * @param {(tokens: RichTextToken[], context: { uri: string, surface: string, source: { text: string } }) => RichTextToken[] | Promise<RichTextToken[]>} callback
445
+ * @param {{ handlesFacetTypes?: string[] }} [options]
446
+ * @returns {void}
447
+ */
448
+ registerRichTextTransform(callback?: (tokens: RichTextToken[], context: {
449
+ uri: string;
450
+ surface: string;
451
+ source: {
452
+ text: string;
453
+ };
454
+ }) => RichTextToken[] | Promise<RichTextToken[]>, options?: {
455
+ handlesFacetTypes?: string[];
456
+ }): void;
457
+ /**
458
+ * Registers a slot renderer. `<plugin-slot name="...">` elements in the host
459
+ * UI (or other plugins' output) invoke `callback(context)`, where `context`
460
+ * is a flat string map of the slot element's attributes. The callback should
461
+ * return a {@link VirtualEl} or `null`.
462
+ *
463
+ * `options.cacheKey` is an array of context field names. If provided, the
464
+ * host treats the slot content as a pure function of these fields — omitting
465
+ * other fields from the callback's context and caching return values until
466
+ * invalidated by {@link Plugin.refreshSlot}. An empty array declares that
467
+ * the content depends on no context at all, so one cached result serves
468
+ * every instance.
469
+ *
470
+ * The host batches all pending contexts of a render into one call.
471
+ * @param {string} name
472
+ * @param {(context: Record<string, string>) => RenderResult | Promise<RenderResult>} callback
473
+ * @param {{ cacheKey?: string[] }} [options]
474
+ * @returns {void}
475
+ */
476
+ registerSlot(name: string, callback?: (context: Record<string, string>) => RenderResult | Promise<RenderResult>, options?: {
477
+ cacheKey?: string[];
478
+ }): void;
479
+ /**
480
+ * Registers a full-page view reachable via {@link Plugin.openPage}. `display()`
481
+ * is called on navigation and must return a {@link VirtualEl}, or nothing to
482
+ * render an empty page.
483
+ * @param {{ id: string, title?: string | null, display?: () => RenderResult | Promise<RenderResult> }} options
484
+ * @returns {void}
485
+ */
486
+ registerPage({ id, title, display }: {
487
+ id: string;
488
+ title?: string | null;
489
+ display?: () => RenderResult | Promise<RenderResult>;
490
+ }): void;
491
+ /**
492
+ * Navigates the user to one of this plugin's registered pages.
493
+ * @param {string} pageId
494
+ * @returns {Promise<void>}
495
+ */
496
+ openPage(pageId: string): Promise<void>;
497
+ /**
498
+ * Re-invokes a registered page's display callback if the page is open.
499
+ * `options.reset` also discards the rendered tree instead of patching it.
500
+ * @param {string} pageId
501
+ * @param {{ reset?: boolean }} [options]
502
+ * @returns {Promise<void>}
503
+ */
504
+ refreshPage(pageId: string, { reset }?: {
505
+ reset?: boolean;
506
+ }): Promise<void>;
507
+ /**
508
+ * Makes mounted `<plugin-slot name=...>` instances re-invoke this plugin's
509
+ * registered callback for that slot, and drops any cached results. Useful
510
+ * when a slot's content depends on plugin state that changed after render.
511
+ *
512
+ * `options.keys` is an array of matcher objects OR'd together,
513
+ * e.g. `[{ did: "..." }]` — any matching slots are invalidated and refreshed.
514
+ * Omit to refresh every instance. A slot registered with a `cacheKey` can
515
+ * only be matched on those declared fields, since its output depends on
516
+ * nothing else.
517
+ * @param {string} name
518
+ * @param {{ keys?: Record<string, string>[] }} [options]
519
+ * @returns {Promise<void>}
520
+ */
521
+ refreshSlot(name: string, options?: {
522
+ keys?: Record<string, string>[];
523
+ }): Promise<void>;
524
+ /**
525
+ * Override in your subclass. Runs after the plugin is loaded and the current user is resolved.
526
+ * @returns {void | Promise<void>}
527
+ */
528
+ onload(): void | Promise<void>;
529
+ /**
530
+ * Override in your subclass. Runs when the plugin is being torn down (uninstall/reload).
531
+ * @returns {void | Promise<void>}
532
+ */
533
+ onunload(): void | Promise<void>;
534
+ }
535
+ /**
536
+ * Flattens a rich-text token stream into a plain string with a position map,
537
+ * so a {@link Plugin.registerRichTextTransform | rich-text transform} can
538
+ * pattern-match (e.g. with a regex) across token boundaries and map matches
539
+ * back to the original tokens.
540
+ */
541
+ export class FlattenedTokens {
542
+ /**
543
+ * @param {RichTextToken[]} tokens
544
+ */
545
+ constructor(tokens: RichTextToken[]);
546
+ /** @type {string} */
547
+ text: string;
548
+ /**
549
+ * Return the plain-text slice for `[start, end)` — inert, with no facets.
550
+ * @param {number} start
551
+ * @param {number} end
552
+ * @returns {string}
553
+ */
554
+ textFor(start: number, end: number): string;
555
+ /**
556
+ * Return the tokens covering `[start, end)`. Facet tokens partially
557
+ * overlapping the range are demoted to plain text tokens so the emitted
558
+ * slice never carries a truncated facet.
559
+ * @param {number} start
560
+ * @param {number} end
561
+ * @returns {RichTextToken[]}
562
+ */
563
+ tokensFor(start: number, end: number): RichTextToken[];
564
+ #private;
565
+ }
566
+ /**
567
+ * A dismissable modal dialog. Subclass and populate `contentEl` and
568
+ * `titleEl` (both {@link VirtualEl}), typically inside {@link Modal.onOpen}.
569
+ * Call `open()` to show and `close()` to hide.
570
+ */
571
+ export class Modal {
572
+ /** @type {VirtualEl} */
573
+ contentEl: VirtualEl;
574
+ /** @type {VirtualEl} */
575
+ titleEl: VirtualEl;
576
+ /**
577
+ * Show the modal. Runs {@link Modal.onOpen} first, then mounts the current el state.
578
+ * @returns {void}
579
+ */
580
+ open(): void;
581
+ /**
582
+ * Re-render the open modal from the current `titleEl` / `contentEl` state. No-op if closed.
583
+ * @returns {void}
584
+ */
585
+ update(): void;
586
+ /**
587
+ * Hide the modal and fire {@link Modal.onClose}.
588
+ * @returns {void}
589
+ */
590
+ close(): void;
591
+ /**
592
+ * Lifecycle hook — override to populate `titleEl` / `contentEl` before the modal mounts.
593
+ * @returns {void}
594
+ */
595
+ onOpen(): void;
596
+ /**
597
+ * Lifecycle hook — override to react to the modal being dismissed (by `close()` or the user).
598
+ * @returns {void}
599
+ */
600
+ onClose(): void;
601
+ #private;
602
+ }
603
+ /**
604
+ * A tab in the plugin's settings UI. Subclass and override {@link PluginSettingTab.display}
605
+ * to render into `this.containerEl`. Pass the owning plugin to `super(plugin)`
606
+ * and register with `plugin.addSettingTab(tab)`.
607
+ */
608
+ export class PluginSettingTab {
609
+ /**
610
+ * @param {Plugin} plugin The owning plugin, available as `this.plugin`.
611
+ */
612
+ constructor(plugin: Plugin);
613
+ /** @type {Plugin} */
614
+ plugin: Plugin;
615
+ /** @type {VirtualEl} */
616
+ containerEl: VirtualEl;
617
+ /** @type {string | null} */
618
+ name: string | null;
619
+ /**
620
+ * Set the tab's label.
621
+ * @param {string} name
622
+ * @returns {this}
623
+ */
624
+ setName(name: string): this;
625
+ /**
626
+ * Override to render the tab's contents into `this.containerEl`.
627
+ * @returns {void}
628
+ */
629
+ display(): void;
630
+ /**
631
+ * Re-invoke {@link PluginSettingTab.display}. `reset: true` also discards the rendered tree.
632
+ * @param {{ reset?: boolean }} [options]
633
+ * @returns {Promise<void>}
634
+ */
635
+ refresh({ reset }?: {
636
+ reset?: boolean;
637
+ }): Promise<void>;
638
+ }
639
+ /**
640
+ * Fluent builder for a single labeled settings row. `new Setting(containerEl)`
641
+ * appends a row (name + description + control area) to `containerEl` and
642
+ * returns a builder for populating it.
643
+ */
644
+ export class Setting {
645
+ /**
646
+ * @param {VirtualEl} containerEl
647
+ */
648
+ constructor(containerEl: VirtualEl);
649
+ /** @type {VirtualEl} */
650
+ settingEl: VirtualEl;
651
+ /** @type {VirtualEl} */
652
+ infoEl: VirtualEl;
653
+ /** @type {VirtualEl} */
654
+ nameEl: VirtualEl;
655
+ /** @type {VirtualEl} */
656
+ descEl: VirtualEl;
657
+ /** @type {VirtualEl} */
658
+ controlEl: VirtualEl;
659
+ /**
660
+ * Set the row's name/label.
661
+ * @param {string} text
662
+ * @returns {this}
663
+ */
664
+ setName(text: string): this;
665
+ /**
666
+ * Set the row's description text below the name.
667
+ * @param {string} text
668
+ * @returns {this}
669
+ */
670
+ setDesc(text: string): this;
671
+ /**
672
+ * Add a text input; the callback receives a {@link TextComponent}.
673
+ * @param {(component: TextComponent) => void} callback
674
+ * @returns {this}
675
+ */
676
+ addText(callback: (component: TextComponent) => void): this;
677
+ /**
678
+ * Add a multi-line text input; the callback receives a {@link TextAreaComponent}.
679
+ * @param {(component: TextAreaComponent) => void} callback
680
+ * @returns {this}
681
+ */
682
+ addTextArea(callback: (component: TextAreaComponent) => void): this;
683
+ /**
684
+ * Add a toggle switch; the callback receives a {@link ToggleComponent}.
685
+ * @param {(component: ToggleComponent) => void} callback
686
+ * @returns {this}
687
+ */
688
+ addToggle(callback: (component: ToggleComponent) => void): this;
689
+ /**
690
+ * Add a dropdown; the callback receives a {@link DropdownComponent}.
691
+ * @param {(component: DropdownComponent) => void} callback
692
+ * @returns {this}
693
+ */
694
+ addDropdown(callback: (component: DropdownComponent) => void): this;
695
+ /**
696
+ * Add a button; the callback receives a {@link ButtonComponent}.
697
+ * @param {(component: ButtonComponent) => void} callback
698
+ * @returns {this}
699
+ */
700
+ addButton(callback: (component: ButtonComponent) => void): this;
701
+ }
702
+ /** Single-line text input, built via {@link Setting.addText}. */
703
+ export class TextComponent {
704
+ /**
705
+ * @internal
706
+ * @param {VirtualEl} containerEl
707
+ */
708
+ constructor(containerEl: VirtualEl);
709
+ /** @type {VirtualEl} */
710
+ el: VirtualEl;
711
+ /**
712
+ * Set the current value.
713
+ * @param {string | null} value
714
+ * @returns {this}
715
+ */
716
+ setValue(value: string | null): this;
717
+ /**
718
+ * Set the placeholder text shown when the input is empty.
719
+ * @param {string} value
720
+ * @returns {this}
721
+ */
722
+ setPlaceholder(value: string): this;
723
+ /**
724
+ * Fires with the new string value on every change.
725
+ * @param {(value: string) => void} callback
726
+ * @returns {this}
727
+ */
728
+ onChange(callback: (value: string) => void): this;
729
+ }
730
+ /** Multi-line text input, built via {@link Setting.addTextArea}. */
731
+ export class TextAreaComponent {
732
+ /**
733
+ * @internal
734
+ * @param {VirtualEl} containerEl
735
+ */
736
+ constructor(containerEl: VirtualEl);
737
+ /** @type {VirtualEl} */
738
+ el: VirtualEl;
739
+ /**
740
+ * Set the current value.
741
+ * @param {string | null} value
742
+ * @returns {this}
743
+ */
744
+ setValue(value: string | null): this;
745
+ /**
746
+ * Set the placeholder text shown when the input is empty.
747
+ * @param {string} value
748
+ * @returns {this}
749
+ */
750
+ setPlaceholder(value: string): this;
751
+ /**
752
+ * Fires with the new string value on every change.
753
+ * @param {(value: string) => void} callback
754
+ * @returns {this}
755
+ */
756
+ onChange(callback: (value: string) => void): this;
757
+ }
758
+ /** On/off toggle switch, built via {@link Setting.addToggle}. */
759
+ export class ToggleComponent {
760
+ /**
761
+ * @internal
762
+ * @param {VirtualEl} containerEl
763
+ */
764
+ constructor(containerEl: VirtualEl);
765
+ /** @type {VirtualEl} */
766
+ el: VirtualEl;
767
+ /**
768
+ * Set the checked state.
769
+ * @param {boolean} value
770
+ * @returns {this}
771
+ */
772
+ setValue(value: boolean): this;
773
+ /**
774
+ * Fires with the new boolean value on every change.
775
+ * @param {(checked: boolean) => void} callback
776
+ * @returns {this}
777
+ */
778
+ onChange(callback: (checked: boolean) => void): this;
779
+ }
780
+ /** Single-select dropdown, built via {@link Setting.addDropdown}. */
781
+ export class DropdownComponent {
782
+ /**
783
+ * @internal
784
+ * @param {VirtualEl} containerEl
785
+ */
786
+ constructor(containerEl: VirtualEl);
787
+ /** @type {VirtualEl} */
788
+ el: VirtualEl;
789
+ /**
790
+ * Append one option.
791
+ * @param {string} value
792
+ * @param {string} label
793
+ * @returns {this}
794
+ */
795
+ addOption(value: string, label: string): this;
796
+ /**
797
+ * Append every `{ value: label }` entry as an option.
798
+ * @param {Record<string, string>} map
799
+ * @returns {this}
800
+ */
801
+ addOptions(map: Record<string, string>): this;
802
+ /**
803
+ * Select the option whose value matches.
804
+ * @param {string} value
805
+ * @returns {this}
806
+ */
807
+ setValue(value: string): this;
808
+ /**
809
+ * Fires with the newly selected value on every change.
810
+ * @param {(value: string) => void} callback
811
+ * @returns {this}
812
+ */
813
+ onChange(callback: (value: string) => void): this;
814
+ }
815
+ /** Clickable button, built via {@link Setting.addButton}. */
816
+ export class ButtonComponent {
817
+ /**
818
+ * @internal
819
+ * @param {VirtualEl} containerEl
820
+ */
821
+ constructor(containerEl: VirtualEl);
822
+ /** @type {VirtualEl} */
823
+ el: VirtualEl;
824
+ /**
825
+ * Set the button's label.
826
+ * @param {string} text
827
+ * @returns {this}
828
+ */
829
+ setButtonText(text: string): this;
830
+ /**
831
+ * Style the button as the row's primary call-to-action.
832
+ * @returns {this}
833
+ */
834
+ setCta(): this;
835
+ /**
836
+ * Register a click handler.
837
+ * @param {() => void} callback
838
+ * @returns {this}
839
+ */
840
+ onClick(callback: () => void): this;
841
+ }
842
+ /** Renders a host-provided icon by name. Built via {@link VirtualEl.createIcon}. */
843
+ export class IconComponent {
844
+ /**
845
+ * @internal
846
+ * @param {VirtualEl} containerEl
847
+ */
848
+ constructor(containerEl: VirtualEl);
849
+ /** @type {VirtualEl} */
850
+ el: VirtualEl;
851
+ /**
852
+ * Set the icon name.
853
+ * @param {string} name
854
+ * @returns {this}
855
+ */
856
+ setIcon(name: string): this;
857
+ }
858
+ /**
859
+ * Renders a repo blob (by owning DID + blob CID) as an image. Built via
860
+ * {@link VirtualEl.createBlobImage}.
861
+ */
862
+ export class BlobImageComponent {
863
+ /**
864
+ * @internal
865
+ * @param {VirtualEl} containerEl
866
+ */
867
+ constructor(containerEl: VirtualEl);
868
+ /** @type {VirtualEl} */
869
+ el: VirtualEl;
870
+ /**
871
+ * DID of the repo the blob belongs to.
872
+ * @param {string} did
873
+ * @returns {this}
874
+ */
875
+ setDid(did: string): this;
876
+ /**
877
+ * CID of the blob to render.
878
+ * @param {string} cid
879
+ * @returns {this}
880
+ */
881
+ setCid(cid: string): this;
882
+ /**
883
+ * Set the image's alt text.
884
+ * @param {string} alt
885
+ * @returns {this}
886
+ */
887
+ setAlt(alt: string): this;
888
+ /**
889
+ * Override the CDN URL prefix used to fetch the blob.
890
+ * @param {string} prefix
891
+ * @returns {this}
892
+ */
893
+ setCdnPrefix(prefix: string): this;
894
+ }
895
+ /**
896
+ * Renders a list of profiles from an array of DIDs, hydrated by the host.
897
+ * Built via {@link VirtualEl.createProfilesList}.
898
+ */
899
+ export class ProfilesListComponent {
900
+ /**
901
+ * @internal
902
+ * @param {VirtualEl} containerEl
903
+ */
904
+ constructor(containerEl: VirtualEl);
905
+ /** @type {VirtualEl} */
906
+ el: VirtualEl;
907
+ /**
908
+ * Set the DIDs to render (array or comma-separated string).
909
+ * @param {string[] | string} dids
910
+ * @returns {this}
911
+ */
912
+ setDids(dids: string[] | string): this;
913
+ /**
914
+ * Message shown when the list is empty.
915
+ * @param {string} message
916
+ * @returns {this}
917
+ */
918
+ setEmptyMessage(message: string): this;
919
+ }
920
+ /**
921
+ * Renders a feed of posts from an array of post URIs, hydrated by the host.
922
+ * Built via {@link VirtualEl.createPostsFeed}.
923
+ */
924
+ export class PostsFeedComponent {
925
+ /**
926
+ * @internal
927
+ * @param {VirtualEl} containerEl
928
+ */
929
+ constructor(containerEl: VirtualEl);
930
+ /** @type {VirtualEl} */
931
+ el: VirtualEl;
932
+ /**
933
+ * Set the post URIs to render (array or comma-separated string).
934
+ * @param {string[] | string} uris
935
+ * @returns {this}
936
+ */
937
+ setUris(uris: string[] | string): this;
938
+ /**
939
+ * Message shown when the feed is empty.
940
+ * @param {string} message
941
+ * @returns {this}
942
+ */
943
+ setEmptyMessage(message: string): this;
944
+ }
945
+ /**
946
+ * A text node in a {@link VirtualEl} tree. Null/undefined coerce to `""`.
947
+ */
948
+ export class VirtualText {
949
+ /**
950
+ * @param {string | null | undefined} value
951
+ */
952
+ constructor(value: string | null | undefined);
953
+ /** @type {string} */
954
+ value: string;
955
+ /**
956
+ * @internal
957
+ * @returns {SerializedText}
958
+ */
959
+ _serialize(): SerializedText;
960
+ }
961
+ /**
962
+ * Minimal DOM-builder node. Plugins run in a sandbox and cannot touch the real
963
+ * DOM directly; instead they build a serializable {@link VirtualEl} tree that
964
+ * the host renders and reconciles.
965
+ */
966
+ export class VirtualEl {
967
+ /**
968
+ * @param {string} tag
969
+ */
970
+ constructor(tag: string);
971
+ /** @type {string} */
972
+ tag: string;
973
+ /** @type {Record<string, string>} */
974
+ attrs: Record<string, string>;
975
+ /** @type {Record<string, string>} */
976
+ styles: Record<string, string>;
977
+ /** @type {(VirtualEl | VirtualText)[]} */
978
+ children: (VirtualEl | VirtualText)[];
979
+ /** @type {Record<string, number>} */
980
+ events: Record<string, number>;
981
+ /**
982
+ * Set an inline style.
983
+ * @param {string} name
984
+ * @param {string | null} value
985
+ * @returns {this}
986
+ */
987
+ setStyle(name: string, value: string | null): this;
988
+ /**
989
+ * Register a click handler.
990
+ * @param {(event?: object) => void} fn
991
+ * @returns {this}
992
+ */
993
+ onClick(fn: (event?: object) => void): this;
994
+ /**
995
+ * Register a change handler (form controls).
996
+ * @param {(event: { target: { value?: string, checked?: boolean } }) => void} fn
997
+ * @returns {this}
998
+ */
999
+ onChange(fn: (event: {
1000
+ target: {
1001
+ value?: string;
1002
+ checked?: boolean;
1003
+ };
1004
+ }) => void): this;
1005
+ /**
1006
+ * Register an input handler (text inputs).
1007
+ * @param {(event: { target: { value?: string } }) => void} fn
1008
+ * @returns {this}
1009
+ */
1010
+ onInput(fn: (event: {
1011
+ target: {
1012
+ value?: string;
1013
+ };
1014
+ }) => void): this;
1015
+ /**
1016
+ * Replace all children with a single {@link VirtualText} node.
1017
+ * @param {string | null} text
1018
+ * @returns {this}
1019
+ */
1020
+ setText(text: string | null): this;
1021
+ /**
1022
+ * Remove all children.
1023
+ * @returns {this}
1024
+ */
1025
+ empty(): this;
1026
+ /**
1027
+ * Append a {@link VirtualEl} or {@link VirtualText}; throws on anything else.
1028
+ * @param {VirtualEl | VirtualText} child
1029
+ * @returns {this}
1030
+ */
1031
+ appendChild(child: VirtualEl | VirtualText): this;
1032
+ /**
1033
+ * Append a {@link VirtualText} child.
1034
+ * @param {string} value
1035
+ * @returns {this}
1036
+ */
1037
+ appendText(value: string): this;
1038
+ /**
1039
+ * Append and return a {@link VirtualText} child.
1040
+ * @param {string} value
1041
+ * @returns {VirtualText}
1042
+ */
1043
+ createText(value: string): VirtualText;
1044
+ /**
1045
+ * Add a CSS class, whitespace-joined with any existing classes.
1046
+ * @param {string} cls
1047
+ * @returns {this}
1048
+ */
1049
+ addClass(cls: string): this;
1050
+ /**
1051
+ * Set an attribute; `undefined` coerces to `""`.
1052
+ * @param {string} name
1053
+ * @param {string | undefined} value
1054
+ * @returns {this}
1055
+ */
1056
+ setAttr(name: string, value: string | undefined): this;
1057
+ /**
1058
+ * Append a child element and return it. `options` accepts `text`,
1059
+ * `cls` (string or string[]), and `attr` (object). The optional callback
1060
+ * receives the new child for further building.
1061
+ * @param {string} tag
1062
+ * @param {{ text?: string, cls?: string | string[], attr?: Record<string, string> }} [options]
1063
+ * @param {(child: VirtualEl) => void} [callback]
1064
+ * @returns {VirtualEl}
1065
+ */
1066
+ createEl(tag: string, options?: {
1067
+ text?: string;
1068
+ cls?: string | string[];
1069
+ attr?: Record<string, string>;
1070
+ }, callback?: (child: VirtualEl) => void): VirtualEl;
1071
+ /**
1072
+ * Shorthand for `createEl("div", ...)`.
1073
+ * @param {{ text?: string, cls?: string | string[], attr?: Record<string, string> }} [options]
1074
+ * @param {(child: VirtualEl) => void} [callback]
1075
+ * @returns {VirtualEl}
1076
+ */
1077
+ createDiv(options?: {
1078
+ text?: string;
1079
+ cls?: string | string[];
1080
+ attr?: Record<string, string>;
1081
+ }, callback?: (child: VirtualEl) => void): VirtualEl;
1082
+ /**
1083
+ * Shorthand for `createEl("span", ...)`.
1084
+ * @param {{ text?: string, cls?: string | string[], attr?: Record<string, string> }} [options]
1085
+ * @param {(child: VirtualEl) => void} [callback]
1086
+ * @returns {VirtualEl}
1087
+ */
1088
+ createSpan(options?: {
1089
+ text?: string;
1090
+ cls?: string | string[];
1091
+ attr?: Record<string, string>;
1092
+ }, callback?: (child: VirtualEl) => void): VirtualEl;
1093
+ /**
1094
+ * Append a profiles-list custom component and return its builder.
1095
+ * @param {(c: ProfilesListComponent) => void} [callback]
1096
+ * @returns {ProfilesListComponent}
1097
+ */
1098
+ createProfilesList(callback?: (c: ProfilesListComponent) => void): ProfilesListComponent;
1099
+ /**
1100
+ * Append a posts-feed custom component and return its builder.
1101
+ * @param {(c: PostsFeedComponent) => void} [callback]
1102
+ * @returns {PostsFeedComponent}
1103
+ */
1104
+ createPostsFeed(callback?: (c: PostsFeedComponent) => void): PostsFeedComponent;
1105
+ /**
1106
+ * Append an icon custom component and return its builder.
1107
+ * @param {(c: IconComponent) => void} [callback]
1108
+ * @returns {IconComponent}
1109
+ */
1110
+ createIcon(callback?: (c: IconComponent) => void): IconComponent;
1111
+ /**
1112
+ * Append a blob-image custom component and return its builder.
1113
+ * @param {(c: BlobImageComponent) => void} [callback]
1114
+ * @returns {BlobImageComponent}
1115
+ */
1116
+ createBlobImage(callback?: (c: BlobImageComponent) => void): BlobImageComponent;
1117
+ /**
1118
+ * @internal
1119
+ * @returns {SerializedElement}
1120
+ */
1121
+ _serialize(): SerializedElement;
1122
+ }
1123
+ /**
1124
+ * Hydrated `app.bsky.feed.defs#postView` shape.
1125
+ */
1126
+ export type PostView = Record<string, unknown>;
1127
+ /**
1128
+ * Basic `app.bsky.actor.defs#profileView` shape.
1129
+ */
1130
+ export type ProfileView = Record<string, unknown>;
1131
+ /**
1132
+ * Detailed profile view with viewer relationship fields.
1133
+ */
1134
+ export type DetailedProfileView = Record<string, unknown>;
1135
+ /**
1136
+ * Paginated response from `getKnownFollowers`: `{ followers, cursor }`.
1137
+ */
1138
+ export type KnownFollowersResponse = Record<string, unknown>;
1139
+ /**
1140
+ * A raw repo record: `{ uri, cid, value }`.
1141
+ */
1142
+ export type RepoRecord = Record<string, unknown>;
1143
+ /**
1144
+ * A `app.bsky.feed.defs#feedViewPost` (post + reply/repost context).
1145
+ */
1146
+ export type FeedItem = Record<string, unknown>;
1147
+ /**
1148
+ * One feature of a facet; fields beyond `$type` vary by service.
1149
+ */
1150
+ export type RichTextFacetFeature = {
1151
+ $type: string;
1152
+ } & Record<string, unknown>;
1153
+ /**
1154
+ * An `app.bsky.richtext.facet` — a byte range plus the features applying to it.
1155
+ */
1156
+ export type RichTextFacet = {
1157
+ index: {
1158
+ byteStart: number;
1159
+ byteEnd: number;
1160
+ };
1161
+ features?: RichTextFacetFeature[];
1162
+ };
1163
+ /**
1164
+ * A run of plain text.
1165
+ */
1166
+ export type RichTextTextToken = {
1167
+ type: "text";
1168
+ value: string;
1169
+ };
1170
+ /**
1171
+ * The text covered by one facet; the host restores the original facet payload.
1172
+ */
1173
+ export type RichTextFacetToken = {
1174
+ type: "facet";
1175
+ facet: RichTextFacet;
1176
+ text: string;
1177
+ };
1178
+ /**
1179
+ * Custom content the plugin renders itself — `block` on its own line, `inline` in the text flow.
1180
+ */
1181
+ export type RichTextNodeToken = {
1182
+ type: "inline" | "block";
1183
+ node: VirtualEl | Record<string, unknown>;
1184
+ pluginId?: string;
1185
+ };
1186
+ /**
1187
+ * One token in a rich-text stream — `text`, `facet`, `inline`, or `block`.
1188
+ */
1189
+ export type RichTextToken = RichTextTextToken | RichTextFacetToken | RichTextNodeToken;
1190
+ /**
1191
+ * Any header collection {@link fetch} accepts — read structurally, not by class.
1192
+ */
1193
+ export type PluginFetchHeaders = Record<string, string> | Headers | Map<string, string> | Iterable<[string, string], void, undefined>;
1194
+ /**
1195
+ * Options for {@link fetch} — a subset of `RequestInit` the host proxy supports.
1196
+ */
1197
+ export type PluginFetchInit = {
1198
+ method?: string;
1199
+ headers?: PluginFetchHeaders;
1200
+ body?: string;
1201
+ };
1202
+ /**
1203
+ * Where a post was seen, passed to `post-context-menu` listeners.
1204
+ */
1205
+ export type PostContextMenuMeta = {
1206
+ feedGenerator: Record<string, unknown> | null;
1207
+ feedContext: string | null;
1208
+ feedProxyUrl: string | null;
1209
+ };
1210
+ /**
1211
+ * What the composer is being opened for, passed to `post-composer-open` listeners.
1212
+ */
1213
+ export type PostComposerContext = {
1214
+ kind: "post" | "reply" | "quote";
1215
+ replyTo: PostView | null;
1216
+ replyRoot: PostView | null;
1217
+ quotedPost: PostView | null;
1218
+ };
1219
+ /**
1220
+ * The events {@link Plugin.on} accepts, and the listener each one takes.
1221
+ */
1222
+ export type PluginEventMap = {
1223
+ "post-context-menu": (menu: Menu, post: PostView, meta?: PostContextMenuMeta) => void;
1224
+ "profile-context-menu": (menu: Menu, profile: ProfileView) => void;
1225
+ "post-composer-open": (composer: Composer, context: PostComposerContext) => void;
1226
+ };
1227
+ /**
1228
+ * What a render callback may return: a tree to render, or nothing.
1229
+ */
1230
+ export type RenderResult = VirtualEl | null | undefined;
1231
+ /**
1232
+ * {@internal} The wire format of a {@link VirtualText} node.
1233
+ */
1234
+ export type SerializedText = {
1235
+ type: "text";
1236
+ value: string;
1237
+ };
1238
+ /**
1239
+ * {@internal} The wire format of a {@link VirtualEl} node.
1240
+ */
1241
+ export type SerializedElement = {
1242
+ type: "element";
1243
+ tag: string;
1244
+ attrs: Record<string, string>;
1245
+ events: Record<string, number>;
1246
+ children: SerializedNode[];
1247
+ styles?: Record<string, string>;
1248
+ };
1249
+ /**
1250
+ * {@internal} One node of the serialized tree the host renders and reconciles.
1251
+ */
1252
+ export type SerializedNode = SerializedText | SerializedElement;
1253
+ /**
1254
+ * An object whose values are all {@link Cloneable}.
1255
+ */
1256
+ export type CloneableObject = {
1257
+ [key: string]: Cloneable;
1258
+ };
1259
+ /**
1260
+ * An array of {@link Cloneable} values.
1261
+ */
1262
+ export type CloneableArray = Cloneable[];
1263
+ /**
1264
+ * JSON-shaped data — the only thing that can cross between a plugin and the
1265
+ * host. Functions, class instances, `Date`, `Map` and friends cannot.
1266
+ */
1267
+ export type Cloneable = null | undefined | boolean | number | string | CloneableArray | CloneableObject;
1268
+ /**
1269
+ * {@internal}
1270
+ */
1271
+ export type RegisterEventListenerMessage = {
1272
+ type: "register";
1273
+ target: "eventListener";
1274
+ event: string;
1275
+ handlerId: number;
1276
+ };
1277
+ /**
1278
+ * {@internal}
1279
+ */
1280
+ export type RegisterSidebarItemMessage = {
1281
+ type: "register";
1282
+ target: "sidebarItem";
1283
+ icon: string | SerializedElement;
1284
+ title: string;
1285
+ handlerId: number;
1286
+ };
1287
+ /**
1288
+ * {@internal}
1289
+ */
1290
+ export type RegisterSettingTabMessage = {
1291
+ type: "register";
1292
+ target: "settingTab";
1293
+ name: string | null;
1294
+ displayHandlerId: number;
1295
+ };
1296
+ /**
1297
+ * {@internal}
1298
+ */
1299
+ export type RegisterFeedFilterMessage = {
1300
+ type: "register";
1301
+ target: "feedFilter";
1302
+ handlerId: number;
1303
+ };
1304
+ /**
1305
+ * {@internal}
1306
+ */
1307
+ export type RegisterRichTextTransformMessage = {
1308
+ type: "register";
1309
+ target: "richTextTransform";
1310
+ handlerId: number;
1311
+ handlesFacetTypes: string[];
1312
+ };
1313
+ /**
1314
+ * {@internal}
1315
+ */
1316
+ export type RegisterSlotMessage = {
1317
+ type: "register";
1318
+ target: "slot";
1319
+ name: string;
1320
+ handlerId: number;
1321
+ cacheKey: string[] | null;
1322
+ batch: true;
1323
+ };
1324
+ /**
1325
+ * {@internal}
1326
+ */
1327
+ export type RegisterPageMessage = {
1328
+ type: "register";
1329
+ target: "page";
1330
+ id: string;
1331
+ title: string | null;
1332
+ displayHandlerId: number;
1333
+ };
1334
+ /**
1335
+ * {@internal} Announces an extension point this plugin provides.
1336
+ */
1337
+ export type RegisterMessage = RegisterEventListenerMessage | RegisterSidebarItemMessage | RegisterSettingTabMessage | RegisterFeedFilterMessage | RegisterRichTextTransformMessage | RegisterSlotMessage | RegisterPageMessage;
1338
+ /**
1339
+ * {@internal} Calls a host method. Without a `hostCallId` it is fire-and-forget.
1340
+ */
1341
+ export type HostCallRequestMessage = {
1342
+ type: "hostCall";
1343
+ method: string;
1344
+ hostCallId?: number;
1345
+ args: Cloneable[];
1346
+ };
1347
+ /**
1348
+ * {@internal} Answers a {@link HostCallMessage}.
1349
+ */
1350
+ export type CallResultMessage = {
1351
+ type: "result";
1352
+ callId: number;
1353
+ value?: unknown;
1354
+ error?: string;
1355
+ };
1356
+ /**
1357
+ * {@internal} Reports the outcome of plugin load.
1358
+ */
1359
+ export type ReadyMessage = {
1360
+ type: "ready";
1361
+ error?: string;
1362
+ };
1363
+ /**
1364
+ * {@internal} Anything this worker may post to the host.
1365
+ */
1366
+ export type WorkerMessage = RegisterMessage | HostCallRequestMessage | CallResultMessage | ReadyMessage;
1367
+ /**
1368
+ * {@internal} The host invoking a handler this worker registered.
1369
+ */
1370
+ export type HostCallMessage = {
1371
+ type: "call";
1372
+ callId: number;
1373
+ handlerId: number;
1374
+ args: Cloneable[];
1375
+ };
1376
+ /**
1377
+ * {@internal} The host answering a {@link hostCall}.
1378
+ */
1379
+ export type HostResultMessage = {
1380
+ type: "hostResult";
1381
+ hostCallId: number;
1382
+ value?: Cloneable;
1383
+ error?: string;
1384
+ };
1385
+ /**
1386
+ * {@internal} An out-of-band notification from the host.
1387
+ */
1388
+ export type HostEventMessage = {
1389
+ type: "event";
1390
+ event: "modalDismissed";
1391
+ data: {
1392
+ modalId: number;
1393
+ };
1394
+ };
1395
+ /**
1396
+ * {@internal} Anything the host may post to this worker.
1397
+ */
1398
+ export type HostMessage = HostCallMessage | HostResultMessage | HostEventMessage;
1399
+ /**
1400
+ * {@internal} The host's reply to a proxied {@link fetch}.
1401
+ */
1402
+ export type SerializedFetchResponse = {
1403
+ status: number;
1404
+ ok: boolean;
1405
+ headers: Record<string, string>;
1406
+ body: string;
1407
+ };
1408
+ /**
1409
+ * {@internal} A {@link PluginFetchInit} with its headers flattened for transfer.
1410
+ */
1411
+ export type SerializedFetchInit = {
1412
+ method?: string;
1413
+ headers?: Record<string, string>;
1414
+ body?: string;
1415
+ };
1416
+ /**
1417
+ * {@internal} A {@link RichTextToken} whose `inline`/`block` node, if any, has
1418
+ * been replaced by its serialized form.
1419
+ */
1420
+ export type SerializedRichTextToken = Record<string, unknown>;