@atmo-dev/kit 0.21.0 → 0.22.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/components/RichText.svelte +17 -9
- 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 +13 -1
- package/dist/index.js +7 -1
- package/dist/legal.d.ts +3 -0
- package/dist/legal.js +2 -0
- 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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Avatar from '../../components/Avatar.svelte';
|
|
3
|
+
import Button from '../../components/Button.svelte';
|
|
4
|
+
import { appviewUrl } from '../../events/atproto-helpers.js';
|
|
5
|
+
import { handleOf } from '../api.js';
|
|
6
|
+
import type { ChatMessage } from '../types.js';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
message,
|
|
10
|
+
canModerate,
|
|
11
|
+
channelHref,
|
|
12
|
+
onmention,
|
|
13
|
+
onban
|
|
14
|
+
}: {
|
|
15
|
+
message: ChatMessage;
|
|
16
|
+
canModerate: boolean;
|
|
17
|
+
/** Where "Channel" leads. */
|
|
18
|
+
channelHref: string;
|
|
19
|
+
onmention?: () => void;
|
|
20
|
+
onban: () => void;
|
|
21
|
+
} = $props();
|
|
22
|
+
|
|
23
|
+
type Profile = { displayName?: string; avatar?: string; description?: string };
|
|
24
|
+
let profile = $state.raw<Profile>({});
|
|
25
|
+
const author = $derived(message.author);
|
|
26
|
+
const handle = $derived(handleOf(author));
|
|
27
|
+
const local = $derived(/^\/(?!\/)/.test(channelHref));
|
|
28
|
+
|
|
29
|
+
$effect(() => {
|
|
30
|
+
const did = author.did;
|
|
31
|
+
profile = {};
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const timer = setTimeout(() => controller.abort(), 4000);
|
|
34
|
+
fetch(`${appviewUrl()}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(did)}`, {
|
|
35
|
+
signal: controller.signal
|
|
36
|
+
})
|
|
37
|
+
.then((response) => (response.ok ? (response.json() as Promise<Profile>) : {}))
|
|
38
|
+
.then((data) => !controller.signal.aborted && (profile = data))
|
|
39
|
+
.catch(() => {})
|
|
40
|
+
.finally(() => clearTimeout(timer));
|
|
41
|
+
return () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
controller.abort();
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div class="w-64">
|
|
49
|
+
<div class="flex items-center gap-3">
|
|
50
|
+
<Avatar name={handle} src={profile.avatar ?? author.avatar} size={44} />
|
|
51
|
+
<div class="min-w-0">
|
|
52
|
+
<p class="truncate text-sm font-semibold">
|
|
53
|
+
{profile.displayName || author.displayName || handle}
|
|
54
|
+
</p>
|
|
55
|
+
<p class="truncate text-xs text-base-600 dark:text-base-400">@{handle}</p>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
{#if profile.description}
|
|
59
|
+
<p class="mt-3 line-clamp-3 text-[13px] whitespace-pre-line">{profile.description}</p>
|
|
60
|
+
{/if}
|
|
61
|
+
<div class="mt-3 flex flex-wrap gap-2">
|
|
62
|
+
<Button
|
|
63
|
+
size="sm"
|
|
64
|
+
variant="secondary"
|
|
65
|
+
href={channelHref}
|
|
66
|
+
target={local ? undefined : '_blank'}
|
|
67
|
+
rel={local ? undefined : 'noopener noreferrer'}>Channel</Button
|
|
68
|
+
>
|
|
69
|
+
{#if onmention}
|
|
70
|
+
<Button size="sm" variant="secondary" onclick={onmention}>Mention</Button>
|
|
71
|
+
{/if}
|
|
72
|
+
{#if canModerate}
|
|
73
|
+
<Button size="sm" variant="ghost" onclick={onban}>Ban from chat</Button>
|
|
74
|
+
{/if}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChatMessage } from '../types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
message: ChatMessage;
|
|
4
|
+
canModerate: boolean;
|
|
5
|
+
/** Where "Channel" leads. */
|
|
6
|
+
channelHref: string;
|
|
7
|
+
onmention?: () => void;
|
|
8
|
+
onban: () => void;
|
|
9
|
+
};
|
|
10
|
+
declare const UserCard: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
11
|
+
type UserCard = ReturnType<typeof UserCard>;
|
|
12
|
+
export default UserCard;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChatColor } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A name colour that stays readable on both themes: the chosen hue is kept, and lightness
|
|
4
|
+
* and strength are fixed per theme. Accounts without a colour get a hue from their DID.
|
|
5
|
+
*/
|
|
6
|
+
export declare function nameColor(did: string, color?: ChatColor, on?: 'dark'): string;
|
|
7
|
+
export declare const shortHandle: (handle: string) => string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function hueOf(seed) {
|
|
2
|
+
let hash = 0;
|
|
3
|
+
for (let i = 0; i < seed.length; i++)
|
|
4
|
+
hash = (hash * 31 + seed.charCodeAt(i)) | 0;
|
|
5
|
+
return Math.abs(hash) % 360;
|
|
6
|
+
}
|
|
7
|
+
/** Chroma and hue of an sRGB colour in OKLCH, where equal lightness reads as equally bright. */
|
|
8
|
+
function toOklch({ red, green, blue }) {
|
|
9
|
+
const linear = (value) => {
|
|
10
|
+
const v = Math.min(255, Math.max(0, value)) / 255;
|
|
11
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
12
|
+
};
|
|
13
|
+
const [r, g, b] = [linear(red), linear(green), linear(blue)];
|
|
14
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
15
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
16
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
17
|
+
const a = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
18
|
+
const bb = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
19
|
+
return { c: Math.hypot(a, bb), h: ((Math.atan2(bb, a) * 180) / Math.PI + 360) % 360 };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A name colour that stays readable on both themes: the chosen hue is kept, and lightness
|
|
23
|
+
* and strength are fixed per theme. Accounts without a colour get a hue from their DID.
|
|
24
|
+
*/
|
|
25
|
+
export function nameColor(did, color, on) {
|
|
26
|
+
const { c, h } = color ? toOklch(color) : { c: 0.1, h: hueOf(did) };
|
|
27
|
+
const tone = `${Math.min(c, 0.1).toFixed(3)} ${Math.round(h)}`;
|
|
28
|
+
// Over video the backing is always dark.
|
|
29
|
+
if (on === 'dark')
|
|
30
|
+
return `oklch(0.8 ${tone})`;
|
|
31
|
+
return `light-dark(oklch(0.48 ${tone}), oklch(0.8 ${tone}))`;
|
|
32
|
+
}
|
|
33
|
+
export const shortHandle = (handle) => handle.replace(/\.bsky\.social$/, '');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComposerLinkPreview } from '../../social/composer.js';
|
|
2
|
+
/** Images are shown from their own host, so only after a click. */
|
|
3
|
+
export declare const isImageUrl: (url: string) => boolean;
|
|
4
|
+
export type LinkPreview = {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
image?: string;
|
|
8
|
+
};
|
|
9
|
+
/** One lookup per link for the page's lifetime: busy chats repeat the same links. */
|
|
10
|
+
export declare function cachedPreview(load: ComposerLinkPreview, url: string): Promise<LinkPreview | undefined>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Images are shown from their own host, so only after a click. */
|
|
2
|
+
export const isImageUrl = (url) => {
|
|
3
|
+
try {
|
|
4
|
+
return /\.(png|jpe?g|gif|webp|avif)$/i.test(new URL(url).pathname);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const caches = new WeakMap();
|
|
11
|
+
/** One lookup per link for the page's lifetime: busy chats repeat the same links. */
|
|
12
|
+
export function cachedPreview(load, url) {
|
|
13
|
+
let cache = caches.get(load);
|
|
14
|
+
if (!cache)
|
|
15
|
+
caches.set(load, (cache = new Map()));
|
|
16
|
+
let pending = cache.get(url);
|
|
17
|
+
if (!pending) {
|
|
18
|
+
pending = Promise.resolve()
|
|
19
|
+
.then(() => load(url, AbortSignal.timeout(6000)))
|
|
20
|
+
.then((link) => link?.title
|
|
21
|
+
? { title: link.title, description: link.description || undefined, image: link.image }
|
|
22
|
+
: undefined)
|
|
23
|
+
.catch(() => undefined);
|
|
24
|
+
cache.set(url, pending);
|
|
25
|
+
if (cache.size > 300)
|
|
26
|
+
cache.delete(cache.keys().next().value);
|
|
27
|
+
}
|
|
28
|
+
return pending;
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Facet } from './types.js';
|
|
2
|
+
export type ResolveHandle = (handle: string) => Promise<string | undefined>;
|
|
3
|
+
/** Links and mentions in a chat message, as byte ranges. Unresolved mentions stay plain text. */
|
|
4
|
+
export declare function detectFacets(text: string, resolve: ResolveHandle): Promise<Facet[]>;
|
|
5
|
+
/** Links in a message: its facets, or plain `https://` URLs when it has none. */
|
|
6
|
+
export declare function linksOf(facets?: Facet[], text?: string): string[];
|
|
7
|
+
/**
|
|
8
|
+
* The message without a link that ends it (or is all of it), for when that link is shown as
|
|
9
|
+
* an embed instead. A link with words after it is part of the sentence and stays, as does the
|
|
10
|
+
* whole text when the link is not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function withoutLink(text: string, facets: Facet[] | undefined, uri: string): {
|
|
13
|
+
text: string;
|
|
14
|
+
facets: Facet[] | undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { safeHttpUrl } from '../urls.js';
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const bytes = (text) => encoder.encode(text).length;
|
|
4
|
+
const linkPattern = /(^|[\s(])((?:https?:\/\/)?(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}(?::\d+)?(?:\/[^\s]*)?)/gi;
|
|
5
|
+
const mentionPattern = /(^|[\s(])@((?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,})/gi;
|
|
6
|
+
// Typed without a scheme, these are far more often a file than a site ("README.md", "app.ts").
|
|
7
|
+
const fileEndings = new Set('md ts tsx js jsx mjs cjs json css html htm svelte vue py rs go rb sh zip pdf txt png jpg gif mov mp4 yml yaml toml lock log sql'.split(' '));
|
|
8
|
+
const looksLikeFile = (raw) => !/^https?:\/\//i.test(raw) &&
|
|
9
|
+
!/[/:]/.test(raw) &&
|
|
10
|
+
!/^www\./i.test(raw) &&
|
|
11
|
+
fileEndings.has(raw.slice(raw.lastIndexOf('.') + 1).toLowerCase());
|
|
12
|
+
/** Links and mentions in a chat message, as byte ranges. Unresolved mentions stay plain text. */
|
|
13
|
+
export async function detectFacets(text, resolve) {
|
|
14
|
+
const facets = [];
|
|
15
|
+
const taken = [];
|
|
16
|
+
// Looked up together: one slow handle must not hold up the others.
|
|
17
|
+
const mentions = [...text.matchAll(mentionPattern)];
|
|
18
|
+
const dids = await Promise.all(mentions.map((match) => resolve(match[2].toLowerCase()).catch(() => undefined)));
|
|
19
|
+
for (const [index, match] of mentions.entries()) {
|
|
20
|
+
const start = match.index + match[1].length;
|
|
21
|
+
const did = dids[index];
|
|
22
|
+
if (!did)
|
|
23
|
+
continue;
|
|
24
|
+
taken.push([start, start + match[2].length + 1]);
|
|
25
|
+
facets.push({
|
|
26
|
+
index: {
|
|
27
|
+
byteStart: bytes(text.slice(0, start)),
|
|
28
|
+
byteEnd: bytes(text.slice(0, start + match[2].length + 1))
|
|
29
|
+
},
|
|
30
|
+
features: [{ $type: 'app.bsky.richtext.facet#mention', did }]
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
for (const match of text.matchAll(linkPattern)) {
|
|
34
|
+
const start = match.index + match[1].length;
|
|
35
|
+
// Trailing punctuation belongs to the sentence, not the link.
|
|
36
|
+
const raw = match[2]
|
|
37
|
+
.replace(/[.,;:!?'"]+$/, '')
|
|
38
|
+
.replace(/\)$/, (m) => (match[2].includes('(') ? m : ''));
|
|
39
|
+
const end = start + raw.length;
|
|
40
|
+
if (taken.some(([from, to]) => start < to && end > from))
|
|
41
|
+
continue;
|
|
42
|
+
if (start > 0 && text[start - 1] === '@')
|
|
43
|
+
continue;
|
|
44
|
+
if (looksLikeFile(raw))
|
|
45
|
+
continue;
|
|
46
|
+
const uri = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
|
|
47
|
+
if (!URL.canParse(uri))
|
|
48
|
+
continue;
|
|
49
|
+
facets.push({
|
|
50
|
+
index: { byteStart: bytes(text.slice(0, start)), byteEnd: bytes(text.slice(0, end)) },
|
|
51
|
+
features: [{ $type: 'app.bsky.richtext.facet#link', uri }]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return facets.sort((a, b) => a.index.byteStart - b.index.byteStart);
|
|
55
|
+
}
|
|
56
|
+
/** Links in a message: its facets, or plain `https://` URLs when it has none. */
|
|
57
|
+
export function linksOf(facets, text = '') {
|
|
58
|
+
const links = [];
|
|
59
|
+
const validHttps = (value) => typeof value === 'string' && !!safeHttpUrl(value)?.startsWith('https://');
|
|
60
|
+
if (!facets?.length) {
|
|
61
|
+
for (const match of text.matchAll(/https:\/\/[^\s<>"']+/g)) {
|
|
62
|
+
const url = match[0].replace(/[.,;:!?)]+$/, '');
|
|
63
|
+
if (validHttps(url))
|
|
64
|
+
links.push(url);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const facet of facets ?? []) {
|
|
68
|
+
for (const feature of facet?.features ?? []) {
|
|
69
|
+
if (validHttps(feature?.uri))
|
|
70
|
+
links.push(feature.uri);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return links;
|
|
74
|
+
}
|
|
75
|
+
const decoder = new TextDecoder();
|
|
76
|
+
const isSpace = (byte) => byte === 0x20 || byte === 0x0a || byte === 0x0d || byte === 0x09;
|
|
77
|
+
/**
|
|
78
|
+
* The message without a link that ends it (or is all of it), for when that link is shown as
|
|
79
|
+
* an embed instead. A link with words after it is part of the sentence and stays, as does the
|
|
80
|
+
* whole text when the link is not found.
|
|
81
|
+
*/
|
|
82
|
+
export function withoutLink(text, facets, uri) {
|
|
83
|
+
const data = encoder.encode(text);
|
|
84
|
+
let start = -1;
|
|
85
|
+
let end = -1;
|
|
86
|
+
const facet = facets?.find((item) => item?.features?.some((feature) => feature?.uri === uri));
|
|
87
|
+
if (facet) {
|
|
88
|
+
start = facet.index?.byteStart;
|
|
89
|
+
end = facet.index?.byteEnd;
|
|
90
|
+
}
|
|
91
|
+
else if (!facets?.length) {
|
|
92
|
+
const at = text.indexOf(uri);
|
|
93
|
+
if (at >= 0) {
|
|
94
|
+
start = bytes(text.slice(0, at));
|
|
95
|
+
end = start + bytes(uri);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!Number.isInteger(start) ||
|
|
99
|
+
!Number.isInteger(end) ||
|
|
100
|
+
start < 0 ||
|
|
101
|
+
end <= start ||
|
|
102
|
+
end > data.length)
|
|
103
|
+
return { text, facets };
|
|
104
|
+
if (!data.subarray(end).every(isSpace))
|
|
105
|
+
return { text, facets };
|
|
106
|
+
while (start > 0 && isSpace(data[start - 1]))
|
|
107
|
+
start -= 1;
|
|
108
|
+
return {
|
|
109
|
+
text: decoder.decode(data.subarray(0, start)),
|
|
110
|
+
facets: (facets ?? []).filter((item) => Number.isInteger(item?.index?.byteEnd) && item.index.byteEnd <= start)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
2
|
+
export type StreamLinkEmbedRef = {
|
|
3
|
+
actor: string;
|
|
4
|
+
href: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Links to a channel on stream.place, shown as a small card with the stream's title and,
|
|
8
|
+
* while live, its picture. Pass `href` when the app has its own page for a channel.
|
|
9
|
+
*/
|
|
10
|
+
export declare function streamLinkEmbed(options?: {
|
|
11
|
+
/** Where the card leads: a path in this app, or stream.place by default. */
|
|
12
|
+
href?: (actor: string) => string;
|
|
13
|
+
}): LinkEmbed<StreamLinkEmbedRef>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parseStreamplaceLink } from './links.js';
|
|
2
|
+
/**
|
|
3
|
+
* Links to a channel on stream.place, shown as a small card with the stream's title and,
|
|
4
|
+
* while live, its picture. Pass `href` when the app has its own page for a channel.
|
|
5
|
+
*/
|
|
6
|
+
export function streamLinkEmbed(options = {}) {
|
|
7
|
+
return {
|
|
8
|
+
id: 'stream',
|
|
9
|
+
label: 'stream',
|
|
10
|
+
match: (url) => {
|
|
11
|
+
const link = parseStreamplaceLink(url.href);
|
|
12
|
+
return link ? { actor: link.actor, href: options.href?.(link.actor) ?? link.url } : null;
|
|
13
|
+
},
|
|
14
|
+
load: () => import('./StreamLinkEmbed.svelte')
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseStreamplaceLink } from '../grain/urls.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChatMessage } from './types.js';
|
|
2
|
+
export type Reaction = {
|
|
3
|
+
emoji: string;
|
|
4
|
+
/** Everyone who reacted with it, with the message that carries their reaction. */
|
|
5
|
+
by: {
|
|
6
|
+
did: string;
|
|
7
|
+
handle: string;
|
|
8
|
+
uri: string;
|
|
9
|
+
pending?: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export declare const quickReactions: string[];
|
|
13
|
+
/** A single emoji and nothing else. */
|
|
14
|
+
export declare function isEmoji(text: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* A reaction is an ordinary chat message: a reply whose whole text is one emoji.
|
|
17
|
+
* Returns the message it reacts to.
|
|
18
|
+
*/
|
|
19
|
+
export declare function reactionTarget(message: ChatMessage): string | undefined;
|
|
20
|
+
/** Reactions per message, in the order each emoji first appeared. One per person and emoji. */
|
|
21
|
+
export declare function groupReactions(messages: ChatMessage[]): Map<string, Reaction[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { graphemeLength } from '../social/richtext.js';
|
|
2
|
+
export const quickReactions = ['👍', '❤️', '😂', '😮', '😢', '🔥'];
|
|
3
|
+
const emojiPattern = /\p{Extended_Pictographic}|\p{Regional_Indicator}|\u20e3/u;
|
|
4
|
+
/** A single emoji and nothing else. */
|
|
5
|
+
export function isEmoji(text) {
|
|
6
|
+
const value = text.trim();
|
|
7
|
+
return (value.length > 0 &&
|
|
8
|
+
value.length <= 32 &&
|
|
9
|
+
graphemeLength(value) === 1 &&
|
|
10
|
+
emojiPattern.test(value));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A reaction is an ordinary chat message: a reply whose whole text is one emoji.
|
|
14
|
+
* Returns the message it reacts to.
|
|
15
|
+
*/
|
|
16
|
+
export function reactionTarget(message) {
|
|
17
|
+
if (message.system)
|
|
18
|
+
return undefined;
|
|
19
|
+
const parent = message.record.reply?.parent?.uri;
|
|
20
|
+
return parent && isEmoji(message.record.text) ? parent : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Reactions per message, in the order each emoji first appeared. One per person and emoji. */
|
|
23
|
+
export function groupReactions(messages) {
|
|
24
|
+
const grouped = new Map();
|
|
25
|
+
for (const message of messages) {
|
|
26
|
+
const target = reactionTarget(message);
|
|
27
|
+
if (!target)
|
|
28
|
+
continue;
|
|
29
|
+
const emoji = message.record.text.trim();
|
|
30
|
+
let list = grouped.get(target);
|
|
31
|
+
if (!list)
|
|
32
|
+
grouped.set(target, (list = []));
|
|
33
|
+
let reaction = list.find((item) => item.emoji === emoji);
|
|
34
|
+
if (!reaction)
|
|
35
|
+
list.push((reaction = { emoji, by: [] }));
|
|
36
|
+
if (reaction.by.some((person) => person.did === message.author.did))
|
|
37
|
+
continue;
|
|
38
|
+
reaction.by.push({
|
|
39
|
+
did: message.author.did,
|
|
40
|
+
handle: message.author.handle,
|
|
41
|
+
uri: message.uri,
|
|
42
|
+
pending: message.pending
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return grouped;
|
|
46
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { Facet } from '../social/richtext.js';
|
|
2
|
+
export type { Facet };
|
|
3
|
+
export type StrongRef = {
|
|
4
|
+
uri: string;
|
|
5
|
+
cid: string;
|
|
6
|
+
};
|
|
7
|
+
export type BlobRef = {
|
|
8
|
+
$type: 'blob';
|
|
9
|
+
ref: {
|
|
10
|
+
$link: string;
|
|
11
|
+
};
|
|
12
|
+
mimeType: string;
|
|
13
|
+
size: number;
|
|
14
|
+
};
|
|
15
|
+
export type ProfileBasic = {
|
|
16
|
+
did: string;
|
|
17
|
+
handle: string;
|
|
18
|
+
displayName?: string;
|
|
19
|
+
avatar?: string;
|
|
20
|
+
pronouns?: string;
|
|
21
|
+
};
|
|
22
|
+
export type Activity = {
|
|
23
|
+
$type: 'place.stream.defs#activityGame';
|
|
24
|
+
uri: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
} | {
|
|
27
|
+
$type: 'place.stream.defs#activityLabel';
|
|
28
|
+
label: string;
|
|
29
|
+
};
|
|
30
|
+
export type LivestreamRecord = {
|
|
31
|
+
$type: 'place.stream.livestream';
|
|
32
|
+
title: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
lastSeenAt?: string;
|
|
36
|
+
endedAt?: string;
|
|
37
|
+
idleTimeoutSeconds?: number;
|
|
38
|
+
post?: StrongRef;
|
|
39
|
+
agent?: string;
|
|
40
|
+
canonicalUrl?: string;
|
|
41
|
+
thumb?: BlobRef;
|
|
42
|
+
notificationSettings?: {
|
|
43
|
+
pushNotification?: boolean;
|
|
44
|
+
};
|
|
45
|
+
activity?: Activity;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
};
|
|
48
|
+
export type LivestreamView = {
|
|
49
|
+
uri: string;
|
|
50
|
+
cid: string;
|
|
51
|
+
author: ProfileBasic;
|
|
52
|
+
record: LivestreamRecord;
|
|
53
|
+
indexedAt: string;
|
|
54
|
+
viewerCount?: {
|
|
55
|
+
count: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export type ChatColor = {
|
|
59
|
+
red: number;
|
|
60
|
+
green: number;
|
|
61
|
+
blue: number;
|
|
62
|
+
};
|
|
63
|
+
export type ChatProfile = {
|
|
64
|
+
color?: ChatColor;
|
|
65
|
+
selfLabels?: string[];
|
|
66
|
+
};
|
|
67
|
+
export type ChatMessageRecord = {
|
|
68
|
+
$type: 'place.stream.chat.message';
|
|
69
|
+
text: string;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
streamer: string;
|
|
72
|
+
facets?: Facet[];
|
|
73
|
+
reply?: {
|
|
74
|
+
root: StrongRef;
|
|
75
|
+
parent: StrongRef;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export type Badge = {
|
|
79
|
+
badgeType: string;
|
|
80
|
+
issuer?: string;
|
|
81
|
+
recipient?: string;
|
|
82
|
+
};
|
|
83
|
+
export type ChatMessage = {
|
|
84
|
+
uri: string;
|
|
85
|
+
cid: string;
|
|
86
|
+
author: ProfileBasic;
|
|
87
|
+
record: ChatMessageRecord;
|
|
88
|
+
indexedAt: string;
|
|
89
|
+
chatProfile?: ChatProfile;
|
|
90
|
+
replyTo?: ChatMessage;
|
|
91
|
+
deleted?: boolean;
|
|
92
|
+
badges?: Badge[];
|
|
93
|
+
/** Not from the network: sent from this tab and not yet confirmed. */
|
|
94
|
+
pending?: boolean;
|
|
95
|
+
/** Not from the network: stream started, teleport arrived. */
|
|
96
|
+
system?: 'start' | 'teleport';
|
|
97
|
+
};
|
|
98
|
+
export type PinnedRecordView = {
|
|
99
|
+
uri: string;
|
|
100
|
+
cid: string;
|
|
101
|
+
record: {
|
|
102
|
+
pinnedMessage: string;
|
|
103
|
+
pinnedBy?: string;
|
|
104
|
+
createdAt: string;
|
|
105
|
+
expiresAt?: string;
|
|
106
|
+
};
|
|
107
|
+
message?: ChatMessage;
|
|
108
|
+
};
|
|
109
|
+
export type Segment = {
|
|
110
|
+
$type: 'place.stream.segment';
|
|
111
|
+
startTime: string;
|
|
112
|
+
duration?: number;
|
|
113
|
+
video?: {
|
|
114
|
+
codec: string;
|
|
115
|
+
width: number;
|
|
116
|
+
height: number;
|
|
117
|
+
framerate?: {
|
|
118
|
+
num: number;
|
|
119
|
+
den: number;
|
|
120
|
+
};
|
|
121
|
+
}[];
|
|
122
|
+
audio?: {
|
|
123
|
+
codec: string;
|
|
124
|
+
rate: number;
|
|
125
|
+
channels: number;
|
|
126
|
+
}[];
|
|
127
|
+
contentWarnings?: {
|
|
128
|
+
warnings?: string[];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export type Problem = {
|
|
132
|
+
code: string;
|
|
133
|
+
message: string;
|
|
134
|
+
severity: string;
|
|
135
|
+
link?: string;
|
|
136
|
+
};
|
|
137
|
+
export type VideoRecord = {
|
|
138
|
+
$type: 'place.stream.video';
|
|
139
|
+
title: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
descriptionFacets?: Facet[];
|
|
142
|
+
createdAt: string;
|
|
143
|
+
durationMs?: number;
|
|
144
|
+
thumb?: BlobRef;
|
|
145
|
+
tags?: string[];
|
|
146
|
+
activity?: Activity;
|
|
147
|
+
/** Records this video relates to, e.g. the livestream it was recorded from. */
|
|
148
|
+
connections?: {
|
|
149
|
+
ref?: StrongRef;
|
|
150
|
+
}[];
|
|
151
|
+
};
|
|
152
|
+
export type VideoView = {
|
|
153
|
+
uri: string;
|
|
154
|
+
cid: string;
|
|
155
|
+
author: ProfileBasic;
|
|
156
|
+
record: VideoRecord;
|
|
157
|
+
likeCount?: number;
|
|
158
|
+
viewCounts?: {
|
|
159
|
+
count: number;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/** The signed-in account, as far as display goes. Never evidence of a session. */
|
|
163
|
+
export type Viewer = {
|
|
164
|
+
did: string;
|
|
165
|
+
handle: string;
|
|
166
|
+
displayName?: string;
|
|
167
|
+
avatar?: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* How the app writes to the signed-in account's repository. Kit holds no session: a server
|
|
171
|
+
* app posts to its own endpoint, a browser app uses its OAuth client. Both reject when
|
|
172
|
+
* nobody is signed in or a permission is missing.
|
|
173
|
+
*/
|
|
174
|
+
export type RecordWriter = {
|
|
175
|
+
/** Resolves with the new record's AT URI, which is how its copy from the network is recognised. */
|
|
176
|
+
create: (collection: string, record: object) => Promise<{
|
|
177
|
+
uri: string;
|
|
178
|
+
cid?: string;
|
|
179
|
+
}>;
|
|
180
|
+
/** By the record's AT URI. */
|
|
181
|
+
delete: (uri: string) => Promise<unknown>;
|
|
182
|
+
};
|
|
183
|
+
export type CommentView = {
|
|
184
|
+
uri: string;
|
|
185
|
+
cid: string;
|
|
186
|
+
author: ProfileBasic;
|
|
187
|
+
record: {
|
|
188
|
+
text: string;
|
|
189
|
+
createdAt: string;
|
|
190
|
+
video: string;
|
|
191
|
+
facets?: Facet[];
|
|
192
|
+
reply?: {
|
|
193
|
+
root: StrongRef;
|
|
194
|
+
parent: StrongRef;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
indexedAt: string;
|
|
198
|
+
replyTo?: Omit<CommentView, 'replyTo'>;
|
|
199
|
+
likeCount: number;
|
|
200
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamplace types, API reads and chat helpers. No Svelte, CSS or players, so it is safe on
|
|
3
|
+
* the server. Reads go to stream.place; apps own sessions and writing.
|
|
4
|
+
*/
|
|
5
|
+
export { configureAtproto } from './events/atproto-helpers.js';
|
|
6
|
+
export * from './streamplace/links.js';
|
|
7
|
+
export type * from './streamplace/types.js';
|
|
8
|
+
export { ApiError, activityName, activityOptions, blobImage, displayName, fetchProfiles, followedAmong, formatCount, getLiveStreams, getLiveStreamsCached, getLivestream, getVideo, getVideos, handleOf, livePlaylist, liveThumbnail, rkeyOf, timeAgo, videoPlaylist, visibleTags, whepUrl, withProfiles, xrpc } from './streamplace/api.js';
|
|
9
|
+
export { detectFacets, linksOf, withoutLink, type ResolveHandle } from './streamplace/facets.js';
|
|
10
|
+
export { groupReactions, isEmoji, quickReactions, reactionTarget, type Reaction } from './streamplace/reactions.js';
|
|
11
|
+
export { startBroadcast, type BroadcastState } from './streamplace/broadcast.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamplace types, API reads and chat helpers. No Svelte, CSS or players, so it is safe on
|
|
3
|
+
* the server. Reads go to stream.place; apps own sessions and writing.
|
|
4
|
+
*/
|
|
5
|
+
export { configureAtproto } from './events/atproto-helpers.js';
|
|
6
|
+
export * from './streamplace/links.js';
|
|
7
|
+
export { ApiError, activityName, activityOptions, blobImage, displayName, fetchProfiles, followedAmong, formatCount, getLiveStreams, getLiveStreamsCached, getLivestream, getVideo, getVideos, handleOf, livePlaylist, liveThumbnail, rkeyOf, timeAgo, videoPlaylist, visibleTags, whepUrl, withProfiles, xrpc } from './streamplace/api.js';
|
|
8
|
+
export { detectFacets, linksOf, withoutLink } from './streamplace/facets.js';
|
|
9
|
+
export { groupReactions, isEmoji, quickReactions, reactionTarget } from './streamplace/reactions.js';
|
|
10
|
+
export { startBroadcast } from './streamplace/broadcast.js';
|
package/dist/streamplace.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export
|
|
1
|
+
/** Streamplace: live channels, chat and playback. Apps own sessions, routes and persistence. */
|
|
2
|
+
export * from './streamplace-data.js';
|
|
3
|
+
export { Channel, type Teleport } from './streamplace/channel.svelte.js';
|
|
4
|
+
export { default as StreamPlayer } from './streamplace/StreamPlayer.svelte';
|
|
5
|
+
export type { StreamPlayerProps } from './streamplace/StreamPlayer.svelte';
|
|
6
|
+
export { default as StreamChat } from './streamplace/chat/StreamChat.svelte';
|
|
7
|
+
export type { StreamChatProps } from './streamplace/chat/StreamChat.svelte';
|
|
8
|
+
export { default as StreamChatPopups } from './streamplace/chat/StreamChatPopups.svelte';
|
|
9
|
+
export { streamLinkEmbed, type StreamLinkEmbedRef } from './streamplace/link-embed.js';
|
|
10
|
+
export { default as StreamCard } from './streamplace/StreamCard.svelte';
|
|
11
|
+
export type { StreamCardProps } from './streamplace/StreamCard.svelte';
|
|
12
|
+
export { default as VideoCard } from './streamplace/VideoCard.svelte';
|
|
13
|
+
export type { VideoCardProps } from './streamplace/VideoCard.svelte';
|
|
14
|
+
export { prefetchHls, startHls, startWebRTC, warmWebRTC, type Engine, type EngineEvents } from './video/engines.js';
|