@impro.social/impro-plugin 0.0.21 → 0.0.23

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