@atmo-dev/kit 0.11.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/components/RichText.svelte +17 -1
  2. package/dist/components/RichText.svelte.d.ts +8 -0
  3. package/dist/components/SembleCollectionPicker.svelte +221 -0
  4. package/dist/components/SembleCollectionPicker.svelte.d.ts +14 -0
  5. package/dist/components/SembleCollectionView.svelte +153 -0
  6. package/dist/components/SembleCollectionView.svelte.d.ts +10 -0
  7. package/dist/events/EventComments.svelte +15 -2
  8. package/dist/events/EventView.svelte +100 -28
  9. package/dist/events/VodPlayer.svelte +14 -73
  10. package/dist/events/VodPlayer.svelte.d.ts +0 -1
  11. package/dist/events/editor/LinkedRecordsPicker.svelte +44 -3
  12. package/dist/events/editor/LinksSection.svelte +29 -9
  13. package/dist/events/editor/adapter.d.ts +3 -0
  14. package/dist/events/event-view/EventLinkEmbed.svelte +49 -0
  15. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +14 -0
  16. package/dist/events/event-view/Player.svelte +431 -0
  17. package/dist/events/event-view/Player.svelte.d.ts +24 -0
  18. package/dist/events/event-view/PostLinkEmbed.svelte +71 -0
  19. package/dist/events/event-view/PostLinkEmbed.svelte.d.ts +11 -0
  20. package/dist/events/event-view/ProfileLinkEmbed.svelte +67 -0
  21. package/dist/events/event-view/ProfileLinkEmbed.svelte.d.ts +11 -0
  22. package/dist/events/event-view/StreamPlacePlayer.svelte +13 -46
  23. package/dist/events/event-view/StreamPlacePlayer.svelte.d.ts +0 -1
  24. package/dist/events/linked-records.d.ts +20 -0
  25. package/dist/events/linked-records.js +32 -2
  26. package/dist/events/schedule/ScheduleEventCell.svelte +2 -1
  27. package/dist/events/urls.d.ts +17 -0
  28. package/dist/events/urls.js +11 -0
  29. package/dist/events-data.d.ts +1 -0
  30. package/dist/events-data.js +1 -0
  31. package/dist/index.d.ts +7 -1
  32. package/dist/index.js +5 -1
  33. package/dist/richtext/document.d.ts +9 -0
  34. package/dist/richtext/document.js +35 -0
  35. package/dist/richtext.d.ts +1 -1
  36. package/dist/richtext.js +1 -1
  37. package/dist/semble/types.d.ts +46 -0
  38. package/dist/semble/types.js +1 -0
  39. package/dist/semble/urls.d.ts +2 -0
  40. package/dist/semble/urls.js +43 -0
  41. package/dist/semble/xrpc.d.ts +3 -0
  42. package/dist/semble/xrpc.js +131 -0
  43. package/dist/semble.d.ts +3 -0
  44. package/dist/semble.js +2 -0
  45. package/dist/social/posts.d.ts +7 -0
  46. package/dist/social/posts.js +21 -0
  47. package/dist/social/urls.d.ts +10 -0
  48. package/dist/social/urls.js +43 -1
  49. package/dist/social.d.ts +3 -1
  50. package/dist/social.js +2 -1
  51. package/package.json +5 -6
  52. package/dist/events/event-view/plyr-icons.d.ts +0 -3
  53. package/dist/events/event-view/plyr-icons.js +0 -46
@@ -2,9 +2,7 @@
2
2
  import { onMount } from 'svelte';
3
3
  import { Icon } from '../../index.js';
4
4
  import { ExternalLink } from '@sketchyicons/svelte';
5
- import 'plyr/dist/plyr.css';
6
- import type PlyrType from 'plyr';
7
- import { sketchyPlyrIcons } from './plyr-icons.js';
5
+ import Player from './Player.svelte';
8
6
 
9
7
  let {
10
8
  handle,
@@ -15,12 +13,11 @@
15
13
  } = $props();
16
14
 
17
15
  let videoEl: HTMLVideoElement | undefined = $state();
18
- let overlayEl: HTMLAnchorElement | undefined = $state();
16
+ let player: Player | undefined = $state();
19
17
  let error = $state(false);
20
18
  let controlsVisible = $state(true);
21
19
 
22
20
  let pc: RTCPeerConnection | null = null;
23
- let plyr: PlyrType | null = null;
24
21
 
25
22
  const posterUrl = $derived(
26
23
  `https://stream.place/api/playback/${encodeURIComponent(handle)}/stream.jpg`
@@ -36,7 +33,6 @@
36
33
  if (videoEl) {
37
34
  videoEl.srcObject = null;
38
35
  }
39
- plyr?.destroy();
40
36
  };
41
37
  });
42
38
 
@@ -123,29 +119,6 @@
123
119
 
124
120
  const answerSdp = await response.text();
125
121
  await pc.setRemoteDescription({ type: 'answer', sdp: answerSdp });
126
-
127
- const { default: Plyr } = await import('plyr');
128
-
129
- plyr = new Plyr(videoEl, {
130
- ...sketchyPlyrIcons(),
131
- controls: ['play', 'mute', 'volume', 'fullscreen'],
132
- settings: [],
133
- ratio: '16:9'
134
- });
135
-
136
- plyr.on('controlshidden', () => {
137
- controlsVisible = false;
138
- });
139
- plyr.on('controlsshown', () => {
140
- controlsVisible = true;
141
- });
142
-
143
- // Move the overlay link inside Plyr's container so mousemove over the
144
- // button bubbles into Plyr's activity tracker — otherwise hovering it
145
- // hides the controls, which hides the button, which reactivates Plyr
146
- // (a flicker loop).
147
- const plyrEl = videoEl.closest('.plyr');
148
- if (plyrEl && overlayEl) plyrEl.appendChild(overlayEl);
149
122
  } catch {
150
123
  error = true;
151
124
  if (pc) {
@@ -158,11 +131,10 @@
158
131
 
159
132
  {#snippet watchOnStreamPlace(hidden = false)}
160
133
  <a
161
- bind:this={overlayEl}
162
134
  href="https://stream.place/{handle}"
163
135
  target="_blank"
164
136
  rel="noopener noreferrer"
165
- onclick={() => plyr?.pause()}
137
+ onclick={() => player?.pause()}
166
138
  class="absolute top-3 right-3 z-10 inline-flex items-center gap-1.5 rounded-full bg-black/55 px-2.5 py-1 text-xs font-medium text-white backdrop-blur-sm transition-opacity duration-200 hover:bg-black/75 {hidden
167
139
  ? 'pointer-events-none opacity-0'
168
140
  : 'opacity-100'}"
@@ -188,22 +160,17 @@
188
160
  <div
189
161
  class="relative aspect-video w-full max-w-full overflow-hidden rounded-xl border border-base-300 dark:border-base-400/40"
190
162
  >
191
- {@render watchOnStreamPlace(!controlsVisible)}
192
- <video
193
- bind:this={videoEl}
194
- class="h-full w-full"
195
- aria-label={title}
163
+ <Player
164
+ bind:this={player}
165
+ bind:video={videoEl}
166
+ bind:controlsVisible
167
+ {title}
196
168
  poster={posterUrl}
169
+ live
197
170
  autoplay
198
- playsinline
199
- muted
200
- crossorigin="anonymous"
201
- ></video>
171
+ >
172
+ <!-- Inside the player, so pointing at the link keeps the controls up. -->
173
+ {@render watchOnStreamPlace(!controlsVisible)}
174
+ </Player>
202
175
  </div>
203
176
  {/if}
204
-
205
- <style>
206
- * {
207
- --plyr-color-main: var(--color-accent-500);
208
- }
209
- </style>
@@ -1,4 +1,3 @@
1
- import 'plyr/dist/plyr.css';
2
1
  type $$ComponentProps = {
3
2
  handle: string;
4
3
  title: string;
@@ -1,7 +1,11 @@
1
1
  import { type GrainClient } from '../grain.js';
2
+ import type { FlatEventRecord } from './contrail.js';
3
+ import { type SembleClient } from '../semble.js';
2
4
  export { parseGrainLink, isLinkedActor } from '../grain.js';
5
+ export { parseSembleLink } from '../semble.js';
3
6
  export { parseStreamplaceLink } from '../streamplace.js';
4
7
  export type { GrainReference, GrainAlbum, GrainPhoto, GrainGallery, GrainAlbumPage } from '../grain.js';
8
+ export type { SembleReference, SembleCard, SembleCollection, SembleCollectionPage, SembleCollectionList } from '../semble.js';
5
9
  export type EventLink = {
6
10
  uri: string;
7
11
  name?: string;
@@ -9,10 +13,26 @@ export type EventLink = {
9
13
  export type LinkedRecordsClient = {
10
14
  getGrainGallery: GrainClient['getGallery'];
11
15
  listGrainAlbums: GrainClient['listAlbums'];
16
+ /** Optional: without these, Semble collections stay links and can only be pasted. */
17
+ getSembleCollection?: SembleClient['getCollection'];
18
+ listSembleCollections?: SembleClient['listCollections'];
19
+ /** Optional: a public event by handle or DID and record key, for event links in descriptions. */
20
+ getEvent?: (actor: string, rkey: string) => Promise<FlatEventRecord>;
12
21
  };
22
+ /**
23
+ * Recognize a link to an event page, `/p/<handle or DID>/e/<rkey>`, on one of the given origins.
24
+ * Syntax only; the event may not exist.
25
+ */
26
+ export declare function parseEventLink(value: string, origins?: readonly string[]): {
27
+ actor: string;
28
+ rkey: string;
29
+ path: string;
30
+ } | null;
13
31
  /** Recognize event stream URLs, not arbitrary bare handles in `uris`. */
14
32
  export declare function eventStreamLink(uri: string): {
15
33
  actor: string;
16
34
  url: string;
17
35
  } | null;
36
+ /** Links shown in the event's own tabs rather than its link list. */
37
+ export declare function eventTabLink(uri: string): 'photos' | 'collections' | null;
18
38
  export declare function isLinkedRecord(link: EventLink): boolean;
@@ -1,11 +1,41 @@
1
- import { parseGrainLink } from '../grain.js';
1
+ import { isLinkedActor, parseGrainLink } from '../grain.js';
2
+ import { parseSembleLink } from '../semble.js';
2
3
  import { parseStreamplaceLink } from '../streamplace.js';
3
4
  export { parseGrainLink, isLinkedActor } from '../grain.js';
5
+ export { parseSembleLink } from '../semble.js';
4
6
  export { parseStreamplaceLink } from '../streamplace.js';
7
+ /**
8
+ * Recognize a link to an event page, `/p/<handle or DID>/e/<rkey>`, on one of the given origins.
9
+ * Syntax only; the event may not exist.
10
+ */
11
+ export function parseEventLink(value, origins = ['https://atmo.rsvp']) {
12
+ try {
13
+ const url = new URL(value);
14
+ if (!origins.includes(url.origin) || url.username || url.password)
15
+ return null;
16
+ const match = /^\/p\/([^/]+)\/e\/([^/]+)\/?$/.exec(url.pathname);
17
+ if (!match)
18
+ return null;
19
+ let actor = decodeURIComponent(match[1]);
20
+ const rkey = decodeURIComponent(match[2]);
21
+ if (!isLinkedActor(actor) || !/^[A-Za-z0-9._~:-]{1,512}$/.test(rkey) || rkey.startsWith('.'))
22
+ return null;
23
+ if (!actor.startsWith('did:'))
24
+ actor = actor.toLowerCase();
25
+ return { actor, rkey, path: `/p/${actor.replaceAll('%', '%25')}/e/${rkey}` };
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
5
31
  /** Recognize event stream URLs, not arbitrary bare handles in `uris`. */
6
32
  export function eventStreamLink(uri) {
7
33
  return /^https?:\/\//i.test(uri) ? parseStreamplaceLink(uri) : null;
8
34
  }
35
+ /** Links shown in the event's own tabs rather than its link list. */
36
+ export function eventTabLink(uri) {
37
+ return parseGrainLink(uri) ? 'photos' : parseSembleLink(uri) ? 'collections' : null;
38
+ }
9
39
  export function isLinkedRecord(link) {
10
- return !!parseGrainLink(link.uri) || !!eventStreamLink(link.uri);
40
+ return !!eventTabLink(link.uri) || !!eventStreamLink(link.uri);
11
41
  }
@@ -10,6 +10,7 @@
10
10
  import { Modal, Button, Icon } from '../../index.js';
11
11
  import EventRsvp from '../EventRsvp.svelte';
12
12
  import VodPlayer from '../VodPlayer.svelte';
13
+ import { resolveEventUrls } from '../urls.js';
13
14
  import type { EditorAdapter, EditorViewer } from '../editor/adapter.js';
14
15
  import type { Snippet } from 'svelte';
15
16
 
@@ -52,7 +53,7 @@
52
53
  );
53
54
  let initialRsvpRkey = $derived(rsvpRkeys[event.uri] ?? null);
54
55
  let isPast = $derived(event.end ? new Date(event.end) < new Date() : false);
55
- let eventHref = $derived(`/p/${eventActor}/e/${event.rkey}`);
56
+ let eventHref = $derived(resolveEventUrls(adapter.urls).event(eventActor, event.rkey));
56
57
  </script>
57
58
 
58
59
  {#if linkableTypes.has(event.type) && event.rkey}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Where the event components link to inside the host app. Every entry is optional; the
3
+ * defaults are the RSVP app's routes.
4
+ */
5
+ export type EventUrls = {
6
+ /** A person's page: the host, an attendee, a mention. Default `/p/{actor}`. */
7
+ profile?: (actor: string) => string;
8
+ /** An event's page. Default `/p/{actor}/e/{rkey}`. */
9
+ event?: (actor: string, rkey: string) => string;
10
+ /** The event's editor, or null for an app without one. Default: the event's page plus `/edit`. */
11
+ edit?: (actor: string, rkey: string) => string | null;
12
+ /** Where a conference's talks are managed, or null. Default: the event's page plus `/talks`. */
13
+ talks?: (actor: string, rkey: string) => string | null;
14
+ };
15
+ export type ResolvedEventUrls = Required<EventUrls>;
16
+ /** The host's routes with the defaults filled in. */
17
+ export declare function resolveEventUrls(urls?: EventUrls): ResolvedEventUrls;
@@ -0,0 +1,11 @@
1
+ /** The host's routes with the defaults filled in. */
2
+ export function resolveEventUrls(urls = {}) {
3
+ const profile = urls.profile ?? ((actor) => `/p/${encodeURIComponent(actor)}`);
4
+ const event = urls.event ?? ((actor, rkey) => `/p/${actor}/e/${rkey}`);
5
+ return {
6
+ profile,
7
+ event,
8
+ edit: urls.edit ?? ((actor, rkey) => `${event(actor, rkey)}/edit`),
9
+ talks: urls.talks ?? ((actor, rkey) => `${event(actor, rkey)}/talks`)
10
+ };
11
+ }
@@ -12,4 +12,5 @@ export * from './events/theme.js';
12
12
  export { getEventThumbnail, getEventExternalImage, type ExternalEventImage } from './events/event-media.js';
13
13
  export { getCDNImageBlobUrl, compressImage, configureAtproto } from './events/atproto-helpers.js';
14
14
  export { getProfileUrl, getLocalProfileUrl } from './events/profile-url.js';
15
+ export { resolveEventUrls, type EventUrls, type ResolvedEventUrls } from './events/urls.js';
15
16
  export { normalizeCountryCode, normalizeEventLocations, LocationValidationError } from './events/editor/location.js';
@@ -6,4 +6,5 @@ export * from './events/theme.js';
6
6
  export { getEventThumbnail, getEventExternalImage } from './events/event-media.js';
7
7
  export { getCDNImageBlobUrl, compressImage, configureAtproto } from './events/atproto-helpers.js';
8
8
  export { getProfileUrl, getLocalProfileUrl } from './events/profile-url.js';
9
+ export { resolveEventUrls } from './events/urls.js';
9
10
  export { normalizeCountryCode, normalizeEventLocations, LocationValidationError } from './events/editor/location.js';
package/dist/index.d.ts CHANGED
@@ -38,7 +38,12 @@ export { default as GrainAlbumView } from './components/GrainAlbumView.svelte';
38
38
  export type { GrainAlbumViewProps } from './components/GrainAlbumView.svelte';
39
39
  export { default as StreamplacePicker } from './components/StreamplacePicker.svelte';
40
40
  export type { StreamplacePickerProps } from './components/StreamplacePicker.svelte';
41
+ export { default as SembleCollectionPicker } from './components/SembleCollectionPicker.svelte';
42
+ export type { SembleCollectionPickerProps } from './components/SembleCollectionPicker.svelte';
43
+ export { default as SembleCollectionView } from './components/SembleCollectionView.svelte';
44
+ export type { SembleCollectionViewProps } from './components/SembleCollectionView.svelte';
41
45
  export * from './grain.js';
46
+ export * from './semble.js';
42
47
  export * from './streamplace.js';
43
48
  export { default as InsetImage } from './components/InsetImage.svelte';
44
49
  export { default as Badge } from './components/Badge.svelte';
@@ -89,7 +94,8 @@ export type { RichTextDocument, RichTextLinkOptions } from './richtext/document.
89
94
  export { default as ExternalEmbed } from './components/ExternalEmbed.svelte';
90
95
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
91
96
  export type { ExternalPostEmbed, ExternalEmbedProvider, ExternalEmbedPlayer } from './social/external-embeds.js';
92
- export { blueskyPostToPostData } from './social/posts.js';
97
+ export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
98
+ export { parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
93
99
  export type { PostData, PostEmbed, BlueskyPostView } from './social/posts.js';
94
100
  export { editorJsonToBlueskyPost, textToDoc, graphemeLength } from './social/richtext.js';
95
101
  export type { Facet, RichTextOptions, RichTextSegment } from './social/richtext.js';
package/dist/index.js CHANGED
@@ -26,7 +26,10 @@ export { default as PhotoGrid } from './components/PhotoGrid.svelte';
26
26
  export { default as GrainAlbumPicker } from './components/GrainAlbumPicker.svelte';
27
27
  export { default as GrainAlbumView } from './components/GrainAlbumView.svelte';
28
28
  export { default as StreamplacePicker } from './components/StreamplacePicker.svelte';
29
+ export { default as SembleCollectionPicker } from './components/SembleCollectionPicker.svelte';
30
+ export { default as SembleCollectionView } from './components/SembleCollectionView.svelte';
29
31
  export * from './grain.js';
32
+ export * from './semble.js';
30
33
  export * from './streamplace.js';
31
34
  export { default as InsetImage } from './components/InsetImage.svelte';
32
35
  export { default as Badge } from './components/Badge.svelte';
@@ -61,7 +64,8 @@ export { safeHttpUrl, safeLinkHref } from './urls.js';
61
64
  export { default as RichText } from './components/RichText.svelte';
62
65
  export { default as ExternalEmbed } from './components/ExternalEmbed.svelte';
63
66
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
64
- export { blueskyPostToPostData } from './social/posts.js';
67
+ export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
68
+ export { parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
65
69
  export { editorJsonToBlueskyPost, textToDoc, graphemeLength } from './social/richtext.js';
66
70
  export { launchConfetti } from './confetti.js';
67
71
  export { cn } from './utils.js';
@@ -68,6 +68,15 @@ export declare function mentionHref(actor: unknown, options: RichTextLinkOptions
68
68
  export declare function tagHref(tag: unknown, options: RichTextLinkOptions): string | undefined;
69
69
  /** Validated destination of a link, mention or tag node; undefined for anything else. */
70
70
  export declare function inlineHref(node: unknown, options: RichTextLinkOptions): string | undefined;
71
+ export type ParagraphPart = {
72
+ children: Record<string, unknown>[];
73
+ embed?: string;
74
+ };
75
+ /**
76
+ * Split a paragraph into runs of lines, so that a bare link alone on its line can be shown as
77
+ * an embed. Labeled links and links inside a sentence stay ordinary links.
78
+ */
79
+ export declare function paragraphParts(children: unknown, isEmbed?: (url: string) => boolean): ParagraphPart[];
71
80
  /** Documents from the parser nest far less; deeper (tampered) nodes are cut off. */
72
81
  export declare const MAX_RENDER_DEPTH = 32;
73
82
  /** Text content of any node, including unknown ones. */
@@ -46,6 +46,41 @@ function nodes(value) {
46
46
  function string(value) {
47
47
  return typeof value === 'string' ? value : '';
48
48
  }
49
+ /**
50
+ * Split a paragraph into runs of lines, so that a bare link alone on its line can be shown as
51
+ * an embed. Labeled links and links inside a sentence stay ordinary links.
52
+ */
53
+ export function paragraphParts(children, isEmbed) {
54
+ const all = nodes(children);
55
+ if (!isEmbed)
56
+ return [{ children: all }];
57
+ const parts = [];
58
+ let text;
59
+ for (let start = 0; start <= all.length; start++) {
60
+ let end = start;
61
+ while (end < all.length && all[end].type !== 'break')
62
+ end++;
63
+ const line = all.slice(start, end);
64
+ const content = line.filter((node) => node.type !== 'text' || string(node.value).trim());
65
+ const link = content.length === 1 && content[0].type === 'link' ? content[0] : undefined;
66
+ const label = link && nodes(link.children);
67
+ const url = link && label?.length === 1 && label[0].type === 'text' && label[0].value === link.url
68
+ ? safeWebUrl(link.url)
69
+ : undefined;
70
+ if (url && isEmbed(url)) {
71
+ parts.push({ children: line, embed: url });
72
+ text = undefined;
73
+ }
74
+ else if (text) {
75
+ text.children.push({ type: 'break' }, ...line);
76
+ }
77
+ else if (line.length || end < all.length) {
78
+ parts.push((text = { children: line }));
79
+ }
80
+ start = end;
81
+ }
82
+ return parts;
83
+ }
49
84
  /** Documents from the parser nest far less; deeper (tampered) nodes are cut off. */
50
85
  export const MAX_RENDER_DEPTH = 32;
51
86
  /** Text content of any node, including unknown ones. */
@@ -11,7 +11,7 @@ export type RichTextParseOptions = PlainTextOptions & {
11
11
  };
12
12
  export declare function parseRichText(text: string, options?: RichTextParseOptions): RichTextDocument;
13
13
  export { parseMarkdown, parsePlainText };
14
- export { richTextToPlainText, safeWebUrl } from './richtext/document.js';
14
+ export { richTextToPlainText, safeWebUrl, paragraphParts } from './richtext/document.js';
15
15
  export type { RichTextDocument, RichTextBlock, RichTextInline, RichTextLinkOptions } from './richtext/document.js';
16
16
  export type { PlainTextOptions };
17
17
  export { detectTokens, type DetectedToken } from './richtext/detect.js';
package/dist/richtext.js CHANGED
@@ -8,5 +8,5 @@ export function parseRichText(text, options = {}) {
8
8
  return options.markdown ? parseMarkdown(text, options) : parsePlainText(text, options);
9
9
  }
10
10
  export { parseMarkdown, parsePlainText };
11
- export { richTextToPlainText, safeWebUrl } from './richtext/document.js';
11
+ export { richTextToPlainText, safeWebUrl, paragraphParts } from './richtext/document.js';
12
12
  export { detectTokens } from './richtext/detect.js';
@@ -0,0 +1,46 @@
1
+ export type SembleReference = {
2
+ actor: string;
3
+ rkey: string;
4
+ atUri: string;
5
+ url: string;
6
+ };
7
+ export type SembleActor = {
8
+ did: string;
9
+ handle: string;
10
+ displayName?: string;
11
+ };
12
+ export type SembleCollection = {
13
+ uri: string;
14
+ url: string;
15
+ name: string;
16
+ description?: string;
17
+ creator: SembleActor;
18
+ cardCount: number;
19
+ };
20
+ export type SembleCard = {
21
+ id: string;
22
+ url: string;
23
+ title: string;
24
+ /** Host name of `url`, or the page's own site name. */
25
+ site: string;
26
+ description?: string;
27
+ /** The page's own preview image, on any HTTPS host. */
28
+ image?: string;
29
+ note?: string;
30
+ /** Set when someone other than the collection's creator added the card. */
31
+ addedBy?: SembleActor;
32
+ };
33
+ /** A collection with its most recently updated cards; `cardCount` can exceed `cards.length`. */
34
+ export type SembleCollectionPage = SembleCollection & {
35
+ cards: SembleCard[];
36
+ };
37
+ export type SembleCollectionList = {
38
+ collections: SembleCollection[];
39
+ cursor?: string;
40
+ };
41
+ /** Normalized public reads. Implement with Semble's API, or another index of the same records. */
42
+ export type SembleClient = {
43
+ getCollection(reference: string): Promise<SembleCollectionPage>;
44
+ listCollections(actor: string, cursor?: string): Promise<SembleCollectionList>;
45
+ };
46
+ export type SembleSelection = (collection: SembleCollection) => void | string | Promise<void | string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SembleReference } from './types.js';
2
+ export declare function parseSembleLink(input: string): SembleReference | null;
@@ -0,0 +1,43 @@
1
+ import { isLinkedActor } from '../grain/urls.js';
2
+ export function parseSembleLink(input) {
3
+ try {
4
+ const raw = input.trim();
5
+ let actor;
6
+ let rkey;
7
+ if (raw.startsWith('at://')) {
8
+ const match = /^at:\/\/([^/]+)\/network\.cosmik\.collection\/([^/?#]+)$/.exec(raw);
9
+ if (!match)
10
+ return null;
11
+ [, actor, rkey] = match;
12
+ }
13
+ else {
14
+ const url = new URL(/^semble\.so\//i.test(raw) ? `https://${raw}` : raw);
15
+ if (!['https:', 'http:'].includes(url.protocol) ||
16
+ url.hostname !== 'semble.so' ||
17
+ url.username ||
18
+ url.password ||
19
+ url.port)
20
+ return null;
21
+ const match = /^\/profile\/([^/]+)\/collections\/([^/]+)\/?$/.exec(url.pathname);
22
+ if (!match)
23
+ return null;
24
+ actor = decodeURIComponent(match[1]);
25
+ rkey = decodeURIComponent(match[2]);
26
+ }
27
+ if (!isLinkedActor(actor) ||
28
+ !/^[A-Za-z0-9._~:-]{1,512}$/.test(rkey) ||
29
+ ['.', '..'].includes(rkey))
30
+ return null;
31
+ if (!actor.startsWith('did:'))
32
+ actor = actor.toLowerCase();
33
+ return {
34
+ actor,
35
+ rkey,
36
+ atUri: `at://${actor}/network.cosmik.collection/${rkey}`,
37
+ url: `https://semble.so/profile/${actor.replaceAll('%', '%25')}/collections/${rkey}`
38
+ };
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ import type { SembleClient } from './types.js';
2
+ /** Current Semble API implementation; not a configurable proxy or an app session. */
3
+ export declare function createSembleXrpcClient(fetchImpl?: typeof fetch): SembleClient;
@@ -0,0 +1,131 @@
1
+ import { isLinkedActor } from '../grain/urls.js';
2
+ import { safeHttpUrl } from '../urls.js';
3
+ import { parseSembleLink } from './urls.js';
4
+ // Semble's API is deliberately isolated here; never proxy a user-supplied host.
5
+ const ORIGIN = 'https://api.semble.so';
6
+ const CARD_LIMIT = 50;
7
+ const LIST_LIMIT = 24;
8
+ function object(value) {
9
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
10
+ }
11
+ /** Page metadata is third-party text of any length. */
12
+ function text(value, max = 300) {
13
+ return typeof value === 'string' ? value.trim().slice(0, max) : '';
14
+ }
15
+ function image(value) {
16
+ const url = safeHttpUrl(text(value, 2048));
17
+ return url?.startsWith('https://') ? url : undefined;
18
+ }
19
+ function actor(value) {
20
+ const user = object(value);
21
+ const did = text(user.id);
22
+ if (!did.startsWith('did:') || !isLinkedActor(did))
23
+ return null;
24
+ return { did, handle: text(user.handle) || did, displayName: text(user.name, 100) || undefined };
25
+ }
26
+ function collection(value) {
27
+ const c = object(value);
28
+ const ref = parseSembleLink(text(c.uri, 1024));
29
+ const creator = actor(c.author);
30
+ if (!ref || !creator || ref.actor !== creator.did)
31
+ throw new Error('Invalid Semble collection');
32
+ return {
33
+ uri: ref.atUri,
34
+ url: ref.url,
35
+ name: text(c.name, 100) || 'Untitled collection',
36
+ description: text(c.description, 500) || undefined,
37
+ creator,
38
+ cardCount: typeof c.cardCount === 'number' && c.cardCount > 0 ? Math.floor(c.cardCount) : 0
39
+ };
40
+ }
41
+ function card(value, creator) {
42
+ const c = object(value), content = object(c.cardContent);
43
+ const url = safeHttpUrl(text(c.url, 2048));
44
+ const id = text(c.uri, 1024) || text(c.id);
45
+ if (!url || !id)
46
+ return null;
47
+ const host = new URL(url).hostname.replace(/^www\./, '');
48
+ const addedBy = actor(c.author);
49
+ const title = text(content.title) || host;
50
+ const description = text(content.description, 500);
51
+ const preview = image(content.imageUrl);
52
+ return {
53
+ id,
54
+ url,
55
+ title,
56
+ site: text(content.siteName, 100) || host,
57
+ // Posts and similar pages repeat their text as both title and description.
58
+ description: description && !description.startsWith(title) ? description : undefined,
59
+ ...(preview ? { image: preview } : {}),
60
+ note: text(object(c.note).text, 1000) || undefined,
61
+ ...(addedBy && addedBy.did !== creator.did ? { addedBy } : {})
62
+ };
63
+ }
64
+ /** Current Semble API implementation; not a configurable proxy or an app session. */
65
+ export function createSembleXrpcClient(fetchImpl = fetch) {
66
+ async function request(method, params) {
67
+ const url = new URL(`/xrpc/${method}`, ORIGIN);
68
+ url.search = new URLSearchParams(params).toString();
69
+ const response = await fetchImpl(url, {
70
+ headers: { accept: 'application/json' },
71
+ signal: AbortSignal.timeout(5000),
72
+ redirect: 'error'
73
+ });
74
+ if (!response.ok)
75
+ throw new Error(`Semble unavailable (${response.status})`);
76
+ return object(await response.json());
77
+ }
78
+ return {
79
+ async getCollection(reference) {
80
+ const ref = parseSembleLink(reference);
81
+ if (!ref)
82
+ throw new Error('Invalid Semble reference');
83
+ const data = await request('network.cosmik.collection.getByAtUri', {
84
+ handle: ref.actor,
85
+ recordKey: ref.rkey,
86
+ limit: String(CARD_LIMIT)
87
+ });
88
+ const result = collection(data);
89
+ const canonical = parseSembleLink(result.uri);
90
+ if (canonical.rkey !== ref.rkey ||
91
+ (ref.actor.startsWith('did:') && canonical.actor !== ref.actor))
92
+ throw new Error('Mismatched Semble collection');
93
+ // The API can list a card twice; ids must be unique for keyed rendering.
94
+ const cards = new Map();
95
+ for (const value of (Array.isArray(data.urlCards) ? data.urlCards : []).slice(0, CARD_LIMIT)) {
96
+ const item = card(value, result.creator);
97
+ if (item && !cards.has(item.id))
98
+ cards.set(item.id, item);
99
+ }
100
+ return { ...result, cards: [...cards.values()] };
101
+ },
102
+ async listCollections(identifier, cursor) {
103
+ if (!isLinkedActor(identifier))
104
+ throw new Error('Invalid actor');
105
+ if (cursor !== undefined && !/^[1-9]\d{0,3}$/.test(cursor))
106
+ throw new Error('Invalid cursor');
107
+ const data = await request('network.cosmik.collection.listByUser', {
108
+ identifier,
109
+ limit: String(LIST_LIMIT),
110
+ page: cursor ?? '1'
111
+ });
112
+ if (!Array.isArray(data.collections))
113
+ throw new Error('Invalid Semble collections');
114
+ // One malformed entry must not hide the rest of the list.
115
+ const collections = data.collections.flatMap((value) => {
116
+ try {
117
+ const item = collection(value);
118
+ return !identifier.startsWith('did:') || item.creator.did === identifier ? [item] : [];
119
+ }
120
+ catch {
121
+ return [];
122
+ }
123
+ });
124
+ const pagination = object(data.pagination);
125
+ const next = pagination.hasMore === true && typeof pagination.currentPage === 'number'
126
+ ? String(pagination.currentPage + 1)
127
+ : undefined;
128
+ return { collections, ...(next && next !== cursor ? { cursor: next } : {}) };
129
+ }
130
+ };
131
+ }
@@ -0,0 +1,3 @@
1
+ export type { SembleClient, SembleCard, SembleCollection, SembleCollectionPage, SembleCollectionList, SembleReference, SembleSelection } from './semble/types.js';
2
+ export { parseSembleLink } from './semble/urls.js';
3
+ export { createSembleXrpcClient } from './semble/xrpc.js';
package/dist/semble.js ADDED
@@ -0,0 +1,2 @@
1
+ export { parseSembleLink } from './semble/urls.js';
2
+ export { createSembleXrpcClient } from './semble/xrpc.js';
@@ -133,5 +133,12 @@ type BlueskyEmbedView = {
133
133
  record?: RecordView;
134
134
  media?: BlueskyEmbedView;
135
135
  };
136
+ /**
137
+ * Whether an AppView view carries a moderation label anywhere: for a post, on the post, its
138
+ * author, or anything it embeds (a quoted post and its author, at any depth). Apps without the
139
+ * viewer's moderation preferences can use it to leave such content out. Pass a single post
140
+ * view, not a thread: a thread's replies would count too.
141
+ */
142
+ export declare function hasModerationLabel(value: unknown, depth?: number): boolean;
136
143
  export declare function blueskyPostToPostData(post: BlueskyPostView, depth?: number): PostData;
137
144
  export {};