@atmo-dev/kit 0.21.0 → 0.23.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.
- package/README.md +1 -1
- package/dist/articles/ArticleView.svelte +21 -7
- package/dist/articles/ArticleView.svelte.d.ts +8 -4
- package/dist/articles/styles.js +3 -2
- package/dist/articles-data.d.ts +1 -0
- package/dist/components/RichText.svelte +34 -17
- package/dist/components/RichText.svelte.d.ts +4 -1
- package/dist/components/RichTextEditor.svelte +67 -11
- package/dist/components/RichTextEditor.svelte.d.ts +0 -2
- package/dist/components/StreamplacePicker.svelte +2 -2
- package/dist/components/StreamplacePicker.svelte.d.ts +1 -1
- package/dist/components/composer/EmojiPanel.svelte +55 -0
- package/dist/components/composer/EmojiPanel.svelte.d.ts +6 -0
- package/dist/components/composer/EmojiPicker.svelte +2 -38
- package/dist/components/data/DataLabel.svelte +120 -0
- package/dist/components/data/DataLabel.svelte.d.ts +10 -0
- package/dist/components/data/issues.d.ts +5 -0
- package/dist/components/data/issues.js +52 -0
- package/dist/components/data/types.d.ts +28 -0
- package/dist/components/data/types.js +1 -0
- package/dist/components/data/visibility.d.ts +7 -0
- package/dist/components/data/visibility.js +15 -0
- package/dist/components/legal/links.js +1 -0
- package/dist/components/legal/types.d.ts +1 -1
- package/dist/components/notifications/NotificationList.svelte +137 -0
- package/dist/components/notifications/NotificationList.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationPushToggle.svelte +76 -0
- package/dist/components/notifications/NotificationPushToggle.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationSettings.svelte +125 -0
- package/dist/components/notifications/NotificationSettings.svelte.d.ts +16 -0
- package/dist/components/notifications/types.d.ts +37 -0
- package/dist/components/notifications/types.js +1 -0
- package/dist/editor/ImageDialog.svelte +87 -0
- package/dist/editor/ImageDialog.svelte.d.ts +16 -0
- package/dist/editor/image-node.d.ts +6 -2
- package/dist/editor/image-node.js +36 -37
- package/dist/events/EventCard.svelte +6 -1
- package/dist/events/VodPlayer.svelte +1 -1
- package/dist/events/atmo-rsvp.d.ts +6 -0
- package/dist/events/atmo-rsvp.js +34 -0
- package/dist/events/atproto-helpers.d.ts +1 -0
- package/dist/events/atproto-helpers.js +3 -0
- package/dist/events/event-link-embed.d.ts +7 -3
- package/dist/events/event-link-embed.js +11 -5
- package/dist/events/event-view/StreamPlacePlayer.svelte +14 -108
- package/dist/events/linked-records.d.ts +1 -1
- package/dist/events/linked-records.js +2 -2
- package/dist/events-card.d.ts +9 -0
- package/dist/events-card.js +7 -0
- package/dist/events-data.d.ts +1 -0
- package/dist/events-data.js +1 -0
- package/dist/grain/xrpc.js +11 -4
- package/dist/index.d.ts +14 -2
- package/dist/index.js +7 -1
- package/dist/legal.d.ts +3 -0
- package/dist/legal.js +2 -0
- package/dist/media.d.ts +33 -0
- package/dist/media.js +74 -1
- package/dist/richtext/serialize.js +13 -8
- package/dist/streamplace/StreamCard.svelte +184 -0
- package/dist/streamplace/StreamCard.svelte.d.ts +24 -0
- package/dist/streamplace/StreamLinkEmbed.svelte +59 -0
- package/dist/streamplace/StreamLinkEmbed.svelte.d.ts +5 -0
- package/dist/streamplace/StreamPlayer.svelte +539 -0
- package/dist/streamplace/StreamPlayer.svelte.d.ts +42 -0
- package/dist/streamplace/VideoCard.svelte +159 -0
- package/dist/streamplace/VideoCard.svelte.d.ts +17 -0
- package/dist/streamplace/api.d.ts +74 -0
- package/dist/streamplace/api.js +182 -0
- package/dist/streamplace/broadcast.d.ts +3 -0
- package/dist/streamplace/broadcast.js +110 -0
- package/dist/streamplace/channel.svelte.d.ts +74 -0
- package/dist/streamplace/channel.svelte.js +515 -0
- package/dist/streamplace/chat/Composer.svelte +232 -0
- package/dist/streamplace/chat/Composer.svelte.d.ts +15 -0
- package/dist/streamplace/chat/Embeds.svelte +135 -0
- package/dist/streamplace/chat/Embeds.svelte.d.ts +13 -0
- package/dist/streamplace/chat/Message.svelte +303 -0
- package/dist/streamplace/chat/Message.svelte.d.ts +25 -0
- package/dist/streamplace/chat/StreamChat.svelte +463 -0
- package/dist/streamplace/chat/StreamChat.svelte.d.ts +33 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte +151 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte.d.ts +15 -0
- package/dist/streamplace/chat/UserCard.svelte +76 -0
- package/dist/streamplace/chat/UserCard.svelte.d.ts +12 -0
- package/dist/streamplace/chat/color.d.ts +7 -0
- package/dist/streamplace/chat/color.js +33 -0
- package/dist/streamplace/chat/links.d.ts +10 -0
- package/dist/streamplace/chat/links.js +29 -0
- package/dist/streamplace/facets.d.ts +15 -0
- package/dist/streamplace/facets.js +112 -0
- package/dist/streamplace/link-embed.d.ts +13 -0
- package/dist/streamplace/link-embed.js +16 -0
- package/dist/streamplace/links.d.ts +6 -0
- package/dist/streamplace/links.js +1 -0
- package/dist/streamplace/reactions.d.ts +21 -0
- package/dist/streamplace/reactions.js +46 -0
- package/dist/streamplace/types.d.ts +200 -0
- package/dist/streamplace/types.js +1 -0
- package/dist/streamplace-data.d.ts +11 -0
- package/dist/streamplace-data.js +10 -0
- package/dist/streamplace.d.ts +14 -6
- package/dist/streamplace.js +11 -1
- package/dist/{events/event-view → video}/Player.svelte +69 -21
- package/dist/video/Player.svelte.d.ts +38 -0
- package/dist/video/engines.d.ts +59 -0
- package/dist/video/engines.js +647 -0
- package/package.json +11 -1
- package/dist/events/event-view/Player.svelte.d.ts +0 -24
package/dist/media.js
CHANGED
|
@@ -1 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
import { safeHttpUrl } from './urls.js';
|
|
2
|
+
/**
|
|
3
|
+
* An image address that is safe to load: HTTP(S), a path on the app's own origin, or a
|
|
4
|
+
* `blob:` address. Never a script, and never a path a browser would read as another host.
|
|
5
|
+
*/
|
|
6
|
+
export function safeImageSrc(value) {
|
|
7
|
+
if (typeof value !== 'string' || !value)
|
|
8
|
+
return undefined;
|
|
9
|
+
const local = (value.startsWith('/') && !value.startsWith('//')) || value.startsWith('blob:');
|
|
10
|
+
if (!local)
|
|
11
|
+
return safeHttpUrl(value);
|
|
12
|
+
// `/\host` is `//host` to a browser.
|
|
13
|
+
for (const char of value) {
|
|
14
|
+
const code = char.charCodeAt(0);
|
|
15
|
+
if (char === '\\' || code <= 0x20 || code === 0x7f)
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/** A positive whole number of pixels, rounded. */
|
|
21
|
+
const pixels = (value) => typeof value === 'number' && Number.isFinite(value) && Math.round(value) > 0
|
|
22
|
+
? Math.round(value)
|
|
23
|
+
: undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The safe candidates of a `srcset`, each an address and a width descriptor (`1000w`). An
|
|
26
|
+
* address may itself contain commas, as image-resizing URLs often do.
|
|
27
|
+
*/
|
|
28
|
+
export function safeSrcset(value) {
|
|
29
|
+
if (typeof value !== 'string')
|
|
30
|
+
return undefined;
|
|
31
|
+
const candidates = [];
|
|
32
|
+
// A candidate is an address, whitespace, then descriptors up to a comma.
|
|
33
|
+
for (const match of value.matchAll(/\s*([^\s]+)((?:\s+[^\s,]+)*)\s*(?:,|$)/g)) {
|
|
34
|
+
if (!match[0].trim())
|
|
35
|
+
continue;
|
|
36
|
+
const address = safeImageSrc(match[1].replace(/,+$/, ''));
|
|
37
|
+
const descriptors = match[2].trim().split(/\s+/).filter(Boolean);
|
|
38
|
+
if (address && descriptors.length === 1 && /^[1-9]\d*w$/.test(descriptors[0]))
|
|
39
|
+
candidates.push(`${address} ${descriptors[0]}`);
|
|
40
|
+
}
|
|
41
|
+
return candidates.length ? candidates.join(', ') : undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An image as an `<img>` can take it: a safe address, valid candidates, both dimensions or
|
|
45
|
+
* neither, and how it loads. A plain address is an image without the rest.
|
|
46
|
+
*/
|
|
47
|
+
export function sizedImage(value, defaults = {}) {
|
|
48
|
+
const input = typeof value === 'string' ? { src: value } : value;
|
|
49
|
+
const src = safeImageSrc(input?.src);
|
|
50
|
+
if (!input || !src)
|
|
51
|
+
return undefined;
|
|
52
|
+
const width = pixels(input.width);
|
|
53
|
+
const height = pixels(input.height);
|
|
54
|
+
const srcset = safeSrcset(input.srcset);
|
|
55
|
+
const fetchpriority = input.fetchpriority === 'high' ||
|
|
56
|
+
input.fetchpriority === 'low' ||
|
|
57
|
+
input.fetchpriority === 'auto'
|
|
58
|
+
? input.fetchpriority
|
|
59
|
+
: undefined;
|
|
60
|
+
const loading = input.loading === 'lazy' || input.loading === 'eager'
|
|
61
|
+
? input.loading
|
|
62
|
+
: fetchpriority === 'high'
|
|
63
|
+
? undefined
|
|
64
|
+
: defaults.loading;
|
|
65
|
+
return {
|
|
66
|
+
src,
|
|
67
|
+
...(srcset
|
|
68
|
+
? { srcset, sizes: (typeof input.sizes === 'string' && input.sizes.trim()) || '100vw' }
|
|
69
|
+
: {}),
|
|
70
|
+
...(width && height ? { width, height } : {}),
|
|
71
|
+
...(loading ? { loading } : {}),
|
|
72
|
+
...(fetchpriority ? { fetchpriority } : {})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -205,8 +205,8 @@ function shapeOf(blocks, depth = 0) {
|
|
|
205
205
|
return [
|
|
206
206
|
{
|
|
207
207
|
img: safeWebUrl(block.url) ?? block.url,
|
|
208
|
-
alt: block.alt ?? '',
|
|
209
|
-
title: block.title ?? ''
|
|
208
|
+
alt: (block.alt ?? '').replace(/[\r\n]+/g, ' '),
|
|
209
|
+
title: (block.title ?? '').replace(/[\r\n]+/g, ' ')
|
|
210
210
|
}
|
|
211
211
|
];
|
|
212
212
|
case 'table':
|
|
@@ -470,11 +470,16 @@ function tableMarkdown(block, aggressive, article) {
|
|
|
470
470
|
...body.map(row)
|
|
471
471
|
].join('\n');
|
|
472
472
|
}
|
|
473
|
-
function
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
473
|
+
function escapeTitle(value) {
|
|
474
|
+
return value
|
|
475
|
+
.replace(/[\r\n]+/g, ' ')
|
|
476
|
+
.replace(/["\\]/g, '\\$&')
|
|
477
|
+
.replace(/&(?=(?:[A-Za-z][A-Za-z0-9]{0,31}|#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6});)/g, '\\&');
|
|
478
|
+
}
|
|
479
|
+
function imageMarkdown(block, aggressive, article) {
|
|
480
|
+
const title = block.title ? ` "${escapeTitle(block.title)}"` : '';
|
|
481
|
+
const altText = (block.alt ?? '').replace(/[\r\n]+/g, ' ');
|
|
482
|
+
const alt = aggressive ? escapeAll(altText) : escapeText(altText, true, article);
|
|
478
483
|
return `}${title})`;
|
|
479
484
|
}
|
|
480
485
|
function blocksMarkdown(blocks, aggressive, depth, inList = false, article = false) {
|
|
@@ -541,7 +546,7 @@ function blocksMarkdown(blocks, aggressive, depth, inList = false, article = fal
|
|
|
541
546
|
result.push(inList ? '***' : '---');
|
|
542
547
|
break;
|
|
543
548
|
case 'image':
|
|
544
|
-
result.push(imageMarkdown(block));
|
|
549
|
+
result.push(imageMarkdown(block, aggressive, article));
|
|
545
550
|
break;
|
|
546
551
|
case 'math':
|
|
547
552
|
result.push(`$$\n${block.value}\n$$`);
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { LivestreamView } from './types.js';
|
|
3
|
+
|
|
4
|
+
export type StreamCardProps = {
|
|
5
|
+
stream: LivestreamView;
|
|
6
|
+
/** Where the card leads: a path in this app, or stream.place by default. */
|
|
7
|
+
href?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The picture. By default the node's current frame of the stream, shown over the
|
|
10
|
+
* stream's own thumbnail once it has loaded (the node is slow to send it).
|
|
11
|
+
*/
|
|
12
|
+
thumbnail?: string;
|
|
13
|
+
/** Load the picture at once, for cards at the top of a page. */
|
|
14
|
+
eager?: boolean;
|
|
15
|
+
/** Play the stream in place, silently, while the mouse is on the card. */
|
|
16
|
+
preview?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Start connecting to the stream as soon as the card is pointed at, focused or pressed,
|
|
19
|
+
* so the stream page that opens next plays at once. On for links within the app.
|
|
20
|
+
*/
|
|
21
|
+
prefetch?: boolean;
|
|
22
|
+
class?: string;
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import Avatar from '../components/Avatar.svelte';
|
|
28
|
+
import { muted, recess } from '../styles.js';
|
|
29
|
+
import { cn } from '../utils.js';
|
|
30
|
+
import { startWebRTC, warmWebRTC } from '../video/engines.js';
|
|
31
|
+
import {
|
|
32
|
+
activityName,
|
|
33
|
+
blobImage,
|
|
34
|
+
displayName,
|
|
35
|
+
formatCount,
|
|
36
|
+
handleOf,
|
|
37
|
+
liveThumbnail,
|
|
38
|
+
whepUrl
|
|
39
|
+
} from './api.js';
|
|
40
|
+
|
|
41
|
+
let {
|
|
42
|
+
stream,
|
|
43
|
+
href,
|
|
44
|
+
thumbnail,
|
|
45
|
+
eager = false,
|
|
46
|
+
preview = true,
|
|
47
|
+
prefetch,
|
|
48
|
+
class: className
|
|
49
|
+
}: StreamCardProps = $props();
|
|
50
|
+
|
|
51
|
+
const handle = $derived(handleOf(stream.author));
|
|
52
|
+
const link = $derived(href ?? `https://stream.place/${encodeURIComponent(handle)}`);
|
|
53
|
+
const local = $derived(/^\/(?!\/)/.test(link));
|
|
54
|
+
const viewers = $derived(stream.viewerCount?.count ?? 0);
|
|
55
|
+
const byline = $derived(
|
|
56
|
+
[displayName(stream.author), activityName(stream.record.activity)].filter(Boolean).join(' · ')
|
|
57
|
+
);
|
|
58
|
+
// One picture per minute, so revisits reuse the cached frame.
|
|
59
|
+
const picture = $derived(
|
|
60
|
+
thumbnail ?? liveThumbnail(stream.author.did, Math.floor(Date.now() / 60_000))
|
|
61
|
+
);
|
|
62
|
+
// The stream's own thumbnail comes from a fast CDN, but is only as recent as the stream.
|
|
63
|
+
const stored = $derived(
|
|
64
|
+
thumbnail ? undefined : blobImage(stream.author.did, stream.record.thumb)
|
|
65
|
+
);
|
|
66
|
+
let loadedPicture = $state<string>();
|
|
67
|
+
const pictureLoaded = $derived(loadedPicture === picture);
|
|
68
|
+
/** A picture that finished loading before the page was interactive fires no `load`. */
|
|
69
|
+
function loaded(node: HTMLImageElement) {
|
|
70
|
+
const current = picture;
|
|
71
|
+
if (node.complete && node.naturalWidth) loadedPicture = current;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let video = $state<HTMLVideoElement>();
|
|
75
|
+
let previewing = $state(false);
|
|
76
|
+
let playing = $state(false);
|
|
77
|
+
/** The stream page plays the same session; it stays open this long after the card lets go. */
|
|
78
|
+
const KEEP = 15_000;
|
|
79
|
+
const prefetchEnabled = $derived(prefetch ?? local);
|
|
80
|
+
|
|
81
|
+
function warm() {
|
|
82
|
+
if (prefetchEnabled) warmWebRTC(whepUrl(stream.author.did), KEEP);
|
|
83
|
+
}
|
|
84
|
+
function enter(event: PointerEvent) {
|
|
85
|
+
warm();
|
|
86
|
+
// Not for touch, where there is no resting pointer, and not against reduced motion.
|
|
87
|
+
if (!preview || event.pointerType !== 'mouse') return;
|
|
88
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
89
|
+
// No delay: the session is being opened anyway, and the picture only fades in once
|
|
90
|
+
// frames arrive, so passing over a card shows nothing.
|
|
91
|
+
previewing = true;
|
|
92
|
+
}
|
|
93
|
+
function leave() {
|
|
94
|
+
previewing = false;
|
|
95
|
+
}
|
|
96
|
+
$effect(() => {
|
|
97
|
+
if (!previewing || !video) return;
|
|
98
|
+
const element = video;
|
|
99
|
+
// One attempt: a preview that does not start is simply not shown.
|
|
100
|
+
// Only keep the session open for handoff when prefetching is enabled.
|
|
101
|
+
const engine = startWebRTC(
|
|
102
|
+
element,
|
|
103
|
+
whepUrl(stream.author.did),
|
|
104
|
+
{ onready: () => void element.play().catch(() => {}), onfail: leave },
|
|
105
|
+
{ attempts: 1, keep: prefetchEnabled ? KEEP : 0 }
|
|
106
|
+
);
|
|
107
|
+
return () => {
|
|
108
|
+
engine.destroy();
|
|
109
|
+
playing = false;
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<a
|
|
115
|
+
href={link}
|
|
116
|
+
target={local ? undefined : '_blank'}
|
|
117
|
+
rel={local ? undefined : 'noopener noreferrer'}
|
|
118
|
+
class={cn(
|
|
119
|
+
'group block min-w-0 text-base-950 no-underline outline-none dark:text-base-50',
|
|
120
|
+
className
|
|
121
|
+
)}
|
|
122
|
+
onpointerenter={enter}
|
|
123
|
+
onpointerleave={leave}
|
|
124
|
+
onpointerdown={warm}
|
|
125
|
+
onfocus={warm}
|
|
126
|
+
>
|
|
127
|
+
<div
|
|
128
|
+
class={cn(
|
|
129
|
+
'relative aspect-video overflow-hidden rounded-ui group-focus-visible:outline-2 group-focus-visible:outline-offset-3 group-focus-visible:outline-accent-700 dark:group-focus-visible:outline-accent-300',
|
|
130
|
+
recess
|
|
131
|
+
)}
|
|
132
|
+
>
|
|
133
|
+
{#if stored}
|
|
134
|
+
<img
|
|
135
|
+
src={stored}
|
|
136
|
+
alt=""
|
|
137
|
+
loading={eager ? 'eager' : 'lazy'}
|
|
138
|
+
decoding="async"
|
|
139
|
+
class="absolute inset-0 size-full object-cover transition-transform duration-300 group-hover:scale-[1.02] motion-reduce:transition-none"
|
|
140
|
+
/>
|
|
141
|
+
{/if}
|
|
142
|
+
<img
|
|
143
|
+
src={picture}
|
|
144
|
+
alt=""
|
|
145
|
+
loading={eager ? 'eager' : 'lazy'}
|
|
146
|
+
decoding="async"
|
|
147
|
+
{@attach loaded}
|
|
148
|
+
onload={() => (loadedPicture = picture)}
|
|
149
|
+
class={[
|
|
150
|
+
'absolute inset-0 size-full object-cover transition-[opacity,transform] duration-300 group-hover:scale-[1.02] motion-reduce:transition-none',
|
|
151
|
+
stored && !pictureLoaded && 'opacity-0'
|
|
152
|
+
]}
|
|
153
|
+
/>
|
|
154
|
+
{#if previewing}
|
|
155
|
+
<video
|
|
156
|
+
bind:this={video}
|
|
157
|
+
muted
|
|
158
|
+
playsinline
|
|
159
|
+
disablepictureinpicture
|
|
160
|
+
aria-hidden="true"
|
|
161
|
+
tabindex="-1"
|
|
162
|
+
class={[
|
|
163
|
+
'pointer-events-none absolute inset-0 size-full bg-black object-contain transition-opacity duration-200',
|
|
164
|
+
playing ? 'opacity-100' : 'opacity-0'
|
|
165
|
+
]}
|
|
166
|
+
onplaying={() => (playing = true)}
|
|
167
|
+
></video>
|
|
168
|
+
{/if}
|
|
169
|
+
<span
|
|
170
|
+
class="absolute bottom-2 left-2 flex items-center gap-1.5 rounded-md bg-black/70 px-1.5 py-0.5 text-[11px] font-medium text-white"
|
|
171
|
+
>
|
|
172
|
+
<span class="size-1.5 rounded-full bg-accent-500"></span>
|
|
173
|
+
{formatCount(viewers)}
|
|
174
|
+
<span class="sr-only">{viewers === 1 ? 'viewer' : 'viewers'}</span>
|
|
175
|
+
</span>
|
|
176
|
+
</div>
|
|
177
|
+
<div class="mt-2.5 flex gap-2.5">
|
|
178
|
+
<Avatar name={handle} src={stream.author.avatar} size={36} class="shrink-0" />
|
|
179
|
+
<div class="min-w-0">
|
|
180
|
+
<h3 class="line-clamp-2 text-sm leading-snug font-medium">{stream.record.title}</h3>
|
|
181
|
+
<p class={cn('mt-0.5 truncate text-[13px]', muted)}>{byline}</p>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</a>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LivestreamView } from './types.js';
|
|
2
|
+
export type StreamCardProps = {
|
|
3
|
+
stream: LivestreamView;
|
|
4
|
+
/** Where the card leads: a path in this app, or stream.place by default. */
|
|
5
|
+
href?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The picture. By default the node's current frame of the stream, shown over the
|
|
8
|
+
* stream's own thumbnail once it has loaded (the node is slow to send it).
|
|
9
|
+
*/
|
|
10
|
+
thumbnail?: string;
|
|
11
|
+
/** Load the picture at once, for cards at the top of a page. */
|
|
12
|
+
eager?: boolean;
|
|
13
|
+
/** Play the stream in place, silently, while the mouse is on the card. */
|
|
14
|
+
preview?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Start connecting to the stream as soon as the card is pointed at, focused or pressed,
|
|
17
|
+
* so the stream page that opens next plays at once. On for links within the app.
|
|
18
|
+
*/
|
|
19
|
+
prefetch?: boolean;
|
|
20
|
+
class?: string;
|
|
21
|
+
};
|
|
22
|
+
declare const StreamCard: import("svelte").Component<StreamCardProps, {}, "">;
|
|
23
|
+
type StreamCard = ReturnType<typeof StreamCard>;
|
|
24
|
+
export default StreamCard;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { LinkEmbedProps } from '../embeds/types.js';
|
|
3
|
+
import { getLivestream, getLiveStreamsCached, handleOf, liveThumbnail } from './api.js';
|
|
4
|
+
import type { StreamLinkEmbedRef } from './link-embed.js';
|
|
5
|
+
import type { LivestreamView } from './types.js';
|
|
6
|
+
|
|
7
|
+
let { ref, fallback }: LinkEmbedProps<StreamLinkEmbedRef> = $props();
|
|
8
|
+
const local = $derived(/^\/(?!\/)/.test(ref.href));
|
|
9
|
+
|
|
10
|
+
let stream = $state.raw<LivestreamView | null>();
|
|
11
|
+
$effect(() => {
|
|
12
|
+
let current = true;
|
|
13
|
+
stream = undefined;
|
|
14
|
+
getLivestream(ref.actor)
|
|
15
|
+
.then((result) => current && (stream = result))
|
|
16
|
+
.catch(() => current && (stream = null));
|
|
17
|
+
return () => (current = false);
|
|
18
|
+
});
|
|
19
|
+
let live = $state(false);
|
|
20
|
+
$effect(() => {
|
|
21
|
+
const did = stream?.author.did;
|
|
22
|
+
live = false;
|
|
23
|
+
if (!did) return;
|
|
24
|
+
let current = true;
|
|
25
|
+
void getLiveStreamsCached()
|
|
26
|
+
.then((streams) => {
|
|
27
|
+
if (current) live = streams.some((other) => other.author.did === did);
|
|
28
|
+
})
|
|
29
|
+
.catch(() => {});
|
|
30
|
+
return () => (current = false);
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
{#if stream}
|
|
35
|
+
<a
|
|
36
|
+
href={ref.href}
|
|
37
|
+
target={local ? undefined : '_blank'}
|
|
38
|
+
rel={local ? undefined : 'noopener noreferrer'}
|
|
39
|
+
class="flex items-center gap-3 rounded-lg border border-base-300 p-2 hover:bg-base-200/60 dark:border-base-800 dark:hover:bg-base-800/50"
|
|
40
|
+
>
|
|
41
|
+
{#if live}
|
|
42
|
+
<img
|
|
43
|
+
src={liveThumbnail(stream.author.did)}
|
|
44
|
+
alt=""
|
|
45
|
+
loading="lazy"
|
|
46
|
+
class="aspect-video w-24 shrink-0 rounded-md bg-black object-cover"
|
|
47
|
+
/>
|
|
48
|
+
{/if}
|
|
49
|
+
<span class="min-w-0">
|
|
50
|
+
<span class="line-clamp-2 text-[13px] leading-snug font-medium">{stream.record.title}</span>
|
|
51
|
+
<span class="mt-0.5 flex items-center gap-1.5 text-xs text-base-600 dark:text-base-400">
|
|
52
|
+
{#if live}<span class="size-1.5 rounded-full bg-accent-500"></span>Live ·{/if}
|
|
53
|
+
<span class="truncate">@{handleOf(stream.author)}</span>
|
|
54
|
+
</span>
|
|
55
|
+
</span>
|
|
56
|
+
</a>
|
|
57
|
+
{:else}
|
|
58
|
+
{@render fallback()}
|
|
59
|
+
{/if}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LinkEmbedProps } from '../embeds/types.js';
|
|
2
|
+
import type { StreamLinkEmbedRef } from './link-embed.js';
|
|
3
|
+
declare const StreamLinkEmbed: import("svelte").Component<LinkEmbedProps<StreamLinkEmbedRef>, {}, "">;
|
|
4
|
+
type StreamLinkEmbed = ReturnType<typeof StreamLinkEmbed>;
|
|
5
|
+
export default StreamLinkEmbed;
|