@atmo-dev/kit 0.18.1 → 0.19.1
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/dist/articles/ArticleCard.svelte +97 -0
- package/dist/articles/ArticleCard.svelte.d.ts +20 -0
- package/dist/articles/ArticleCodeBlock.svelte +121 -0
- package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
- package/dist/articles/ArticleEditor.svelte +340 -0
- package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
- package/dist/articles/ArticleLinkEmbed.svelte +50 -0
- package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
- package/dist/articles/ArticleView.svelte +128 -0
- package/dist/articles/ArticleView.svelte.d.ts +46 -0
- package/dist/articles/PublicationIcon.svelte +37 -0
- package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
- package/dist/articles/article-link-embed.d.ts +36 -0
- package/dist/articles/article-link-embed.js +29 -0
- package/dist/articles/dates.d.ts +2 -0
- package/dist/articles/dates.js +12 -0
- package/dist/articles/images.d.ts +5 -0
- package/dist/articles/images.js +44 -0
- package/dist/articles/markdown.d.ts +15 -0
- package/dist/articles/markdown.js +52 -0
- package/dist/articles/paste.d.ts +11 -0
- package/dist/articles/paste.js +27 -0
- package/dist/articles/records.d.ts +166 -0
- package/dist/articles/records.js +423 -0
- package/dist/articles/styles.d.ts +4 -0
- package/dist/articles/styles.js +14 -0
- package/dist/articles-data.d.ts +8 -0
- package/dist/articles-data.js +8 -0
- package/dist/articles.d.ts +10 -0
- package/dist/articles.js +8 -0
- package/dist/components/ExternalEmbed.svelte +16 -2
- package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
- package/dist/components/IconMaker.svelte +119 -0
- package/dist/components/IconMaker.svelte.d.ts +9 -0
- package/dist/components/IconRail.svelte +9 -6
- package/dist/components/IconRail.svelte.d.ts +2 -0
- package/dist/components/LinkEmbed.svelte +24 -21
- package/dist/components/LinkEmbed.svelte.d.ts +3 -2
- package/dist/components/PaletteApply.svelte +62 -0
- package/dist/components/PaletteApply.svelte.d.ts +9 -0
- package/dist/components/PalettePicker.svelte +92 -0
- package/dist/components/PalettePicker.svelte.d.ts +13 -0
- package/dist/components/PostComments.svelte +129 -0
- package/dist/components/PostComments.svelte.d.ts +15 -0
- package/dist/components/RichText.svelte +199 -9
- package/dist/components/RichText.svelte.d.ts +17 -0
- package/dist/components/RichTextEditor.svelte +164 -13
- package/dist/components/RichTextEditor.svelte.d.ts +26 -3
- package/dist/components/composer/ComposerPost.svelte +10 -0
- package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
- package/dist/components/composer/PostComposer.svelte +28 -2
- package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
- package/dist/editor/EditorMenus.svelte +438 -0
- package/dist/editor/EditorMenus.svelte.d.ts +9 -0
- package/dist/editor/SlashOptions.svelte +45 -0
- package/dist/editor/SlashOptions.svelte.d.ts +12 -0
- package/dist/editor/article-commands.d.ts +44 -0
- package/dist/editor/article-commands.js +289 -0
- package/dist/editor/article-extensions.d.ts +8 -0
- package/dist/editor/article-extensions.js +315 -0
- package/dist/editor/article-menus.d.ts +2 -0
- package/dist/editor/article-menus.js +3 -0
- package/dist/editor/document.d.ts +5 -0
- package/dist/editor/document.js +163 -12
- package/dist/editor/image-node.d.ts +8 -0
- package/dist/editor/image-node.js +75 -0
- package/dist/editor/markdown-extensions.d.ts +1 -5
- package/dist/editor/markdown-extensions.js +37 -2
- package/dist/editor/slash-menu.svelte.d.ts +9 -0
- package/dist/editor/slash-menu.svelte.js +134 -0
- package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
- package/dist/embeds/PostLinkEmbed.svelte +12 -29
- package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
- package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/defaults.d.ts +4 -2
- package/dist/embeds/defaults.js +7 -3
- package/dist/embeds/load.d.ts +44 -0
- package/dist/embeds/load.js +139 -0
- package/dist/embeds/types.d.ts +18 -3
- package/dist/events/EventComments.svelte +4 -101
- package/dist/events/EventComments.svelte.d.ts +1 -1
- package/dist/events/EventView.svelte +5 -0
- package/dist/events/EventView.svelte.d.ts +3 -0
- package/dist/events/event-link-embed.d.ts +4 -1
- package/dist/events/event-link-embed.js +9 -1
- package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
- package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
- package/dist/icon-maker/artwork.d.ts +11 -0
- package/dist/icon-maker/artwork.js +25 -0
- package/dist/icon-maker/index.d.ts +12 -0
- package/dist/icon-maker/index.js +73 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +7 -1
- package/dist/palettes.d.ts +20 -0
- package/dist/palettes.js +37 -0
- package/dist/richtext/article-styles.d.ts +10 -0
- package/dist/richtext/article-styles.js +28 -0
- package/dist/richtext/document.d.ts +63 -1
- package/dist/richtext/document.js +54 -0
- package/dist/richtext/markdown.d.ts +19 -4
- package/dist/richtext/markdown.js +223 -18
- package/dist/richtext/serialize.d.ts +5 -1
- package/dist/richtext/serialize.js +163 -31
- package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
- package/dist/richtext/vendor/markdown-tree.js +2584 -26
- package/dist/richtext.d.ts +7 -5
- package/dist/richtext.js +1 -1
- package/dist/social/external-embeds.d.ts +5 -0
- package/dist/social/external-embeds.js +6 -1
- package/dist/social/mention-suggestions.svelte.js +18 -7
- package/dist/social/posts.d.ts +2 -0
- package/dist/social/posts.js +43 -2
- package/dist/social/profile.js +2 -1
- package/package.json +28 -2
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import Avatar from '../components/Avatar.svelte';
|
|
4
|
+
import RichText from '../components/RichText.svelte';
|
|
5
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
6
|
+
import type { RichTextDocument } from '../richtext/document.js';
|
|
7
|
+
import { safeLinkHref } from '../urls.js';
|
|
8
|
+
import { cn } from '../utils.js';
|
|
9
|
+
import ArticleCodeBlock from './ArticleCodeBlock.svelte';
|
|
10
|
+
import { formatArticleDate } from './dates.js';
|
|
11
|
+
import { articleCodeKey, articleMathKey } from './markdown.js';
|
|
12
|
+
import type { ArticleSummary } from './records.js';
|
|
13
|
+
import { articleClass } from './styles.js';
|
|
14
|
+
|
|
15
|
+
// An article as it is read: cover, title, byline and the text.
|
|
16
|
+
let {
|
|
17
|
+
article,
|
|
18
|
+
content,
|
|
19
|
+
subtitle,
|
|
20
|
+
cover,
|
|
21
|
+
author,
|
|
22
|
+
imageSrc,
|
|
23
|
+
code = {},
|
|
24
|
+
math: formulas = {},
|
|
25
|
+
embeds = true,
|
|
26
|
+
embedData,
|
|
27
|
+
header,
|
|
28
|
+
byline,
|
|
29
|
+
actions,
|
|
30
|
+
children,
|
|
31
|
+
class: className
|
|
32
|
+
}: {
|
|
33
|
+
article: Pick<ArticleSummary, 'title' | 'publishedAt'>;
|
|
34
|
+
/** The text, parsed with `parseArticleText`. */
|
|
35
|
+
content?: RichTextDocument;
|
|
36
|
+
/** Shown under the title: a description the author wrote. */
|
|
37
|
+
subtitle?: string;
|
|
38
|
+
/** Address of the cover image. */
|
|
39
|
+
cover?: string;
|
|
40
|
+
author?: { name: string; avatar?: string; href?: string };
|
|
41
|
+
/** The address to load an uploaded image (`cid:` destination) from. */
|
|
42
|
+
imageSrc?: (url: string) => string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Highlighted markup of code blocks by `articleCodeKey`, inserted as is: only pass a
|
|
45
|
+
* highlighter's output. Blocks without an entry are shown plain.
|
|
46
|
+
*/
|
|
47
|
+
code?: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* Rendered formulas by `articleMathKey`, inserted as is: only pass a renderer's output,
|
|
50
|
+
* such as KaTeX's. Formulas without an entry are shown as their source.
|
|
51
|
+
*/
|
|
52
|
+
math?: Record<string, string>;
|
|
53
|
+
/** Bare links on their own line as embeds: the app's, a list, or none. */
|
|
54
|
+
embeds?: boolean | readonly LinkEmbed[];
|
|
55
|
+
/** What `loadLinkEmbedData` loaded for the embeds, so that they are shown with the text. */
|
|
56
|
+
embedData?: Record<string, unknown>;
|
|
57
|
+
/** Above the title, e.g. a link to the publication. */
|
|
58
|
+
header?: Snippet;
|
|
59
|
+
/** In place of the author, e.g. the publication. */
|
|
60
|
+
byline?: Snippet;
|
|
61
|
+
/** At the end of the byline, e.g. Edit and Delete for the author. */
|
|
62
|
+
actions?: Snippet;
|
|
63
|
+
/** The text when it is not Markdown: shown when there is no `content`, and styled by the app. */
|
|
64
|
+
children?: Snippet;
|
|
65
|
+
class?: string;
|
|
66
|
+
} = $props();
|
|
67
|
+
|
|
68
|
+
let authorHref = $derived(safeLinkHref(author?.href));
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<article class={cn('w-full', className)}>
|
|
72
|
+
{#if cover}<img
|
|
73
|
+
src={cover}
|
|
74
|
+
alt=""
|
|
75
|
+
class="mb-8 max-h-[90dvh] w-full rounded-xl object-cover"
|
|
76
|
+
/>{/if}
|
|
77
|
+
{#if header}{@render header()}{/if}
|
|
78
|
+
<h1
|
|
79
|
+
class={[
|
|
80
|
+
'text-4xl leading-tight font-semibold tracking-tight text-balance sm:text-5xl',
|
|
81
|
+
header && 'mt-5'
|
|
82
|
+
]}
|
|
83
|
+
>
|
|
84
|
+
{article.title}
|
|
85
|
+
</h1>
|
|
86
|
+
{#if subtitle}
|
|
87
|
+
<p class="mt-4 text-xl text-pretty text-base-600 dark:text-base-400">{subtitle}</p>
|
|
88
|
+
{/if}
|
|
89
|
+
<div class="mt-6 flex flex-wrap items-center gap-3 text-sm">
|
|
90
|
+
{#if byline}
|
|
91
|
+
{@render byline()}
|
|
92
|
+
{:else if author}
|
|
93
|
+
<Avatar name={author.name} src={author.avatar} size={32} />
|
|
94
|
+
{#if authorHref}
|
|
95
|
+
<a href={authorHref} class="rounded-sm font-medium hover:underline">{author.name}</a>
|
|
96
|
+
{:else}
|
|
97
|
+
<span class="font-medium">{author.name}</span>
|
|
98
|
+
{/if}
|
|
99
|
+
{/if}
|
|
100
|
+
<time datetime={article.publishedAt} class="whitespace-nowrap text-base-500"
|
|
101
|
+
>{formatArticleDate(article.publishedAt)}</time
|
|
102
|
+
>
|
|
103
|
+
{#if actions}<span class="ml-auto flex items-center gap-1">{@render actions()}</span>{/if}
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<!-- `content` first: markup between the tags is a `children` snippet even when it is empty. -->
|
|
107
|
+
{#if content}
|
|
108
|
+
<RichText
|
|
109
|
+
{content}
|
|
110
|
+
{embeds}
|
|
111
|
+
{embedData}
|
|
112
|
+
{imageSrc}
|
|
113
|
+
headingOffset={1}
|
|
114
|
+
class="mt-10 {articleClass}"
|
|
115
|
+
>
|
|
116
|
+
{#snippet codeBlock(value, lang)}
|
|
117
|
+
<ArticleCodeBlock {value} html={code[articleCodeKey(value, lang)]} />
|
|
118
|
+
{/snippet}
|
|
119
|
+
{#snippet math(value, display)}
|
|
120
|
+
{@const html = formulas[articleMathKey(value, display)]}
|
|
121
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- app-rendered formula markup -->
|
|
122
|
+
{#if html}{@html html}{:else}<code>{value}</code>{/if}
|
|
123
|
+
{/snippet}
|
|
124
|
+
</RichText>
|
|
125
|
+
{:else if children}
|
|
126
|
+
<div class="mt-10">{@render children()}</div>
|
|
127
|
+
{/if}
|
|
128
|
+
</article>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
3
|
+
import type { RichTextDocument } from '../richtext/document.js';
|
|
4
|
+
import type { ArticleSummary } from './records.js';
|
|
5
|
+
type $$ComponentProps = {
|
|
6
|
+
article: Pick<ArticleSummary, 'title' | 'publishedAt'>;
|
|
7
|
+
/** The text, parsed with `parseArticleText`. */
|
|
8
|
+
content?: RichTextDocument;
|
|
9
|
+
/** Shown under the title: a description the author wrote. */
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
/** Address of the cover image. */
|
|
12
|
+
cover?: string;
|
|
13
|
+
author?: {
|
|
14
|
+
name: string;
|
|
15
|
+
avatar?: string;
|
|
16
|
+
href?: string;
|
|
17
|
+
};
|
|
18
|
+
/** The address to load an uploaded image (`cid:` destination) from. */
|
|
19
|
+
imageSrc?: (url: string) => string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Highlighted markup of code blocks by `articleCodeKey`, inserted as is: only pass a
|
|
22
|
+
* highlighter's output. Blocks without an entry are shown plain.
|
|
23
|
+
*/
|
|
24
|
+
code?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Rendered formulas by `articleMathKey`, inserted as is: only pass a renderer's output,
|
|
27
|
+
* such as KaTeX's. Formulas without an entry are shown as their source.
|
|
28
|
+
*/
|
|
29
|
+
math?: Record<string, string>;
|
|
30
|
+
/** Bare links on their own line as embeds: the app's, a list, or none. */
|
|
31
|
+
embeds?: boolean | readonly LinkEmbed[];
|
|
32
|
+
/** What `loadLinkEmbedData` loaded for the embeds, so that they are shown with the text. */
|
|
33
|
+
embedData?: Record<string, unknown>;
|
|
34
|
+
/** Above the title, e.g. a link to the publication. */
|
|
35
|
+
header?: Snippet;
|
|
36
|
+
/** In place of the author, e.g. the publication. */
|
|
37
|
+
byline?: Snippet;
|
|
38
|
+
/** At the end of the byline, e.g. Edit and Delete for the author. */
|
|
39
|
+
actions?: Snippet;
|
|
40
|
+
/** The text when it is not Markdown: shown when there is no `content`, and styled by the app. */
|
|
41
|
+
children?: Snippet;
|
|
42
|
+
class?: string;
|
|
43
|
+
};
|
|
44
|
+
declare const ArticleView: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
45
|
+
type ArticleView = ReturnType<typeof ArticleView>;
|
|
46
|
+
export default ArticleView;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
// A publication's icon, or its initial on a neutral square when it has none.
|
|
5
|
+
let {
|
|
6
|
+
name,
|
|
7
|
+
src,
|
|
8
|
+
size = 40,
|
|
9
|
+
class: className
|
|
10
|
+
}: {
|
|
11
|
+
name: string;
|
|
12
|
+
/** Address of the icon image. */
|
|
13
|
+
src?: string;
|
|
14
|
+
size?: number;
|
|
15
|
+
class?: string;
|
|
16
|
+
} = $props();
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#if src}
|
|
20
|
+
<img
|
|
21
|
+
{src}
|
|
22
|
+
alt=""
|
|
23
|
+
width={size}
|
|
24
|
+
height={size}
|
|
25
|
+
style="width:{size}px;height:{size}px"
|
|
26
|
+
class={cn('shrink-0 rounded-[22%] object-cover', className)}
|
|
27
|
+
/>
|
|
28
|
+
{:else}
|
|
29
|
+
<span
|
|
30
|
+
aria-hidden="true"
|
|
31
|
+
style="width:{size}px;height:{size}px;font-size:{size * 0.45}px"
|
|
32
|
+
class={cn(
|
|
33
|
+
'grid shrink-0 place-items-center rounded-[22%] bg-base-200 font-semibold text-base-600 dark:bg-base-800 dark:text-base-300',
|
|
34
|
+
className
|
|
35
|
+
)}>{Array.from(name.trim())[0]?.toUpperCase() ?? ''}</span
|
|
36
|
+
>
|
|
37
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
name: string;
|
|
3
|
+
/** Address of the icon image. */
|
|
4
|
+
src?: string;
|
|
5
|
+
size?: number;
|
|
6
|
+
class?: string;
|
|
7
|
+
};
|
|
8
|
+
declare const PublicationIcon: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type PublicationIcon = ReturnType<typeof PublicationIcon>;
|
|
10
|
+
export default PublicationIcon;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
2
|
+
import { type ArticleSummary } from './records.js';
|
|
3
|
+
/** What an app knows about a linked article. */
|
|
4
|
+
export type LinkedArticle = {
|
|
5
|
+
/** Its author. */
|
|
6
|
+
did: string;
|
|
7
|
+
article: ArticleSummary;
|
|
8
|
+
/** Shown after the date. */
|
|
9
|
+
author?: string;
|
|
10
|
+
publication?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ArticleLinkEmbedRef = {
|
|
13
|
+
actor: string;
|
|
14
|
+
rkey: string;
|
|
15
|
+
path: string;
|
|
16
|
+
local: boolean;
|
|
17
|
+
loadArticle: (actor: string, rkey: string) => Promise<LinkedArticle | null | undefined>;
|
|
18
|
+
cover?: (did: string, cid: string) => string | undefined;
|
|
19
|
+
};
|
|
20
|
+
/** The article a link points to; null when there is none to show. */
|
|
21
|
+
export declare function loadLinkedArticle(ref: ArticleLinkEmbedRef): Promise<LinkedArticle | null>;
|
|
22
|
+
/** Links to article pages on the given origins, shown as article cards. */
|
|
23
|
+
export declare function articleLinkEmbed(options: {
|
|
24
|
+
loadArticle: ArticleLinkEmbedRef['loadArticle'];
|
|
25
|
+
/** Defaults to atmo.blog. */
|
|
26
|
+
origins?: readonly string[];
|
|
27
|
+
/** Whether this app serves article pages itself; otherwise the card opens the linked URL. */
|
|
28
|
+
local?: boolean;
|
|
29
|
+
/** Where a cover image loads from. Defaults to Bluesky's image CDN. */
|
|
30
|
+
cover?: ArticleLinkEmbedRef['cover'];
|
|
31
|
+
/** Leave some article links as ordinary links, e.g. the article being shown. */
|
|
32
|
+
skip?: (link: {
|
|
33
|
+
actor: string;
|
|
34
|
+
rkey: string;
|
|
35
|
+
}) => boolean;
|
|
36
|
+
}): LinkEmbed<ArticleLinkEmbedRef, LinkedArticle>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ATMO_BLOG_ORIGIN, parseArticleLink } from './records.js';
|
|
2
|
+
/** The article a link points to; null when there is none to show. */
|
|
3
|
+
export async function loadLinkedArticle(ref) {
|
|
4
|
+
const result = await ref.loadArticle(ref.actor, ref.rkey);
|
|
5
|
+
return result?.article.rkey === ref.rkey && result.article.title ? result : null;
|
|
6
|
+
}
|
|
7
|
+
// One function for every such embed, so that its component is loaded once.
|
|
8
|
+
const load = () => import('./ArticleLinkEmbed.svelte');
|
|
9
|
+
/** Links to article pages on the given origins, shown as article cards. */
|
|
10
|
+
export function articleLinkEmbed(options) {
|
|
11
|
+
const origins = options.origins ?? [ATMO_BLOG_ORIGIN];
|
|
12
|
+
return {
|
|
13
|
+
id: 'article',
|
|
14
|
+
label: 'article',
|
|
15
|
+
match(url) {
|
|
16
|
+
const link = parseArticleLink(url.href, origins);
|
|
17
|
+
return link && !options.skip?.(link)
|
|
18
|
+
? {
|
|
19
|
+
...link,
|
|
20
|
+
local: !!options.local,
|
|
21
|
+
loadArticle: options.loadArticle,
|
|
22
|
+
cover: options.cover
|
|
23
|
+
}
|
|
24
|
+
: null;
|
|
25
|
+
},
|
|
26
|
+
load,
|
|
27
|
+
data: loadLinkedArticle
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const format = new Intl.DateTimeFormat('en', {
|
|
2
|
+
year: 'numeric',
|
|
3
|
+
month: 'long',
|
|
4
|
+
day: 'numeric',
|
|
5
|
+
// The same on the server and in every browser.
|
|
6
|
+
timeZone: 'UTC'
|
|
7
|
+
});
|
|
8
|
+
/** "November 15, 2026", or nothing for an unreadable date. */
|
|
9
|
+
export function formatArticleDate(value) {
|
|
10
|
+
const date = new Date(value);
|
|
11
|
+
return Number.isNaN(date.getTime()) ? '' : format.format(date);
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ARTICLE_IMAGE_TYPES, ARTICLE_LIMITS } from './records.js';
|
|
2
|
+
const MAX_SIDE = 2400;
|
|
3
|
+
function encode(canvas, type, quality) {
|
|
4
|
+
return new Promise((resolve) => canvas.toBlob(resolve, type, quality));
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An image as it will be uploaded: a supported type, small enough, re-encoded only if
|
|
8
|
+
* needed. Browser only. Throws an `Error` whose message can be shown.
|
|
9
|
+
*/
|
|
10
|
+
export async function prepareArticleImage(file, maxBytes = ARTICLE_LIMITS.imageBytes) {
|
|
11
|
+
// Said rather than made a still of: the author expects it to move.
|
|
12
|
+
if (file.type === 'image/gif')
|
|
13
|
+
throw new Error('GIFs are not supported yet.');
|
|
14
|
+
if (ARTICLE_IMAGE_TYPES.includes(file.type) && file.size <= maxBytes)
|
|
15
|
+
return file;
|
|
16
|
+
let bitmap;
|
|
17
|
+
try {
|
|
18
|
+
bitmap = await createImageBitmap(file);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new Error('This image type is not supported.');
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
let scale = Math.min(1, MAX_SIDE / Math.max(bitmap.width, bitmap.height));
|
|
25
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
26
|
+
const canvas = document.createElement('canvas');
|
|
27
|
+
canvas.width = Math.max(1, Math.round(bitmap.width * scale));
|
|
28
|
+
canvas.height = Math.max(1, Math.round(bitmap.height * scale));
|
|
29
|
+
canvas.getContext('2d').drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
30
|
+
for (const quality of [0.86, 0.72]) {
|
|
31
|
+
const blob = (await encode(canvas, 'image/webp', quality)) ??
|
|
32
|
+
(await encode(canvas, 'image/jpeg', quality));
|
|
33
|
+
// Browsers without WebP encoding answer with PNG.
|
|
34
|
+
if (blob && ARTICLE_IMAGE_TYPES.includes(blob.type) && blob.size <= maxBytes)
|
|
35
|
+
return blob;
|
|
36
|
+
}
|
|
37
|
+
scale *= 0.75;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
bitmap.close();
|
|
42
|
+
}
|
|
43
|
+
throw new Error('This image is too large.');
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RichTextDocument } from '../richtext/document.js';
|
|
2
|
+
/** Article Markdown as stored in a document. Uploaded images are `cid:` destinations. */
|
|
3
|
+
export declare function parseArticleText(text: string, allowImage?: (url: string) => boolean): RichTextDocument;
|
|
4
|
+
/** Destinations of the images in a document, in order, wherever a block can be. */
|
|
5
|
+
export declare function imageUrls(document: RichTextDocument): string[];
|
|
6
|
+
export declare function plainText(document: RichTextDocument): string;
|
|
7
|
+
/** The text of the opening paragraphs, up to the first heading, list or other block. */
|
|
8
|
+
export declare function lead(document: RichTextDocument): string;
|
|
9
|
+
/** The description an article gets when its author writes none. */
|
|
10
|
+
export declare function autoDescription(document: RichTextDocument, length?: number): string;
|
|
11
|
+
/** The start of the text, cut at a word. */
|
|
12
|
+
export declare function excerpt(plain: string, length: number): string;
|
|
13
|
+
/** Keys of the app-rendered code and formulas `ArticleView` looks up. */
|
|
14
|
+
export declare const articleCodeKey: (value: string, lang?: string | null) => string;
|
|
15
|
+
export declare const articleMathKey: (value: string, display: boolean) => string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { parseRichText, richTextToPlainText } from '../richtext.js';
|
|
2
|
+
const uploaded = (url) => /^cid:[a-z2-7]{20,200}$/.test(url);
|
|
3
|
+
/** Article Markdown as stored in a document. Uploaded images are `cid:` destinations. */
|
|
4
|
+
export function parseArticleText(text, allowImage = uploaded) {
|
|
5
|
+
return parseRichText(text, { markdown: true, article: true, detectLinks: true, allowImage });
|
|
6
|
+
}
|
|
7
|
+
/** Destinations of the images in a document, in order, wherever a block can be. */
|
|
8
|
+
export function imageUrls(document) {
|
|
9
|
+
const urls = [];
|
|
10
|
+
const walk = (blocks) => {
|
|
11
|
+
for (const block of blocks) {
|
|
12
|
+
if (block.type === 'image')
|
|
13
|
+
urls.push(block.url);
|
|
14
|
+
else if (block.type === 'blockquote' || block.type === 'footnoteDefinition')
|
|
15
|
+
walk(block.children);
|
|
16
|
+
else if (block.type === 'list')
|
|
17
|
+
block.items.forEach(walk);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
walk(document.children);
|
|
21
|
+
return urls;
|
|
22
|
+
}
|
|
23
|
+
export function plainText(document) {
|
|
24
|
+
return richTextToPlainText(document).trim();
|
|
25
|
+
}
|
|
26
|
+
/** The text of the opening paragraphs, up to the first heading, list or other block. */
|
|
27
|
+
export function lead(document) {
|
|
28
|
+
const paragraphs = [];
|
|
29
|
+
for (const block of document.children) {
|
|
30
|
+
if (block.type === 'image')
|
|
31
|
+
continue;
|
|
32
|
+
if (block.type !== 'paragraph')
|
|
33
|
+
break;
|
|
34
|
+
paragraphs.push(block);
|
|
35
|
+
}
|
|
36
|
+
return plainText({ ...document, children: paragraphs });
|
|
37
|
+
}
|
|
38
|
+
/** The description an article gets when its author writes none. */
|
|
39
|
+
export function autoDescription(document, length = 300) {
|
|
40
|
+
return excerpt(lead(document) || plainText(document), length);
|
|
41
|
+
}
|
|
42
|
+
/** The start of the text, cut at a word. */
|
|
43
|
+
export function excerpt(plain, length) {
|
|
44
|
+
const line = plain.replace(/\s+/g, ' ').trim();
|
|
45
|
+
if (line.length <= length)
|
|
46
|
+
return line;
|
|
47
|
+
const cut = line.slice(0, length - 1);
|
|
48
|
+
return `${cut.slice(0, Math.max(cut.lastIndexOf(' '), length / 2)).trimEnd()}…`;
|
|
49
|
+
}
|
|
50
|
+
/** Keys of the app-rendered code and formulas `ArticleView` looks up. */
|
|
51
|
+
export const articleCodeKey = (value, lang) => `${lang ?? ''}\n${value}`;
|
|
52
|
+
export const articleMathKey = (value, display) => `${display ? 'd' : 'i'}\n${value}`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** What a pasted Markdown file says about itself, apart from its text. */
|
|
2
|
+
export type PastedArticle = {
|
|
3
|
+
title?: string;
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Whole articles are often pasted as their file: front matter first, then a top heading
|
|
8
|
+
* repeating the title. Both become the title instead of text. Only for an article that has
|
|
9
|
+
* no title yet, and only when text follows.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readPastedArticle(source: string, hasTitle: boolean): PastedArticle;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function unquote(value) {
|
|
2
|
+
const trimmed = value.trim();
|
|
3
|
+
const quoted = /^(["'])(.*)\1$/.exec(trimmed);
|
|
4
|
+
return quoted ? quoted[2] : trimmed;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whole articles are often pasted as their file: front matter first, then a top heading
|
|
8
|
+
* repeating the title. Both become the title instead of text. Only for an article that has
|
|
9
|
+
* no title yet, and only when text follows.
|
|
10
|
+
*/
|
|
11
|
+
export function readPastedArticle(source, hasTitle) {
|
|
12
|
+
let text = source.replace(/\r\n?/g, '\n');
|
|
13
|
+
let title;
|
|
14
|
+
const frontMatter = /^---\n([\s\S]*?)\n(?:---|\.\.\.)[ \t]*(?:\n|$)/.exec(text);
|
|
15
|
+
if (frontMatter && /^[A-Za-z_][\w-]*:/m.test(frontMatter[1])) {
|
|
16
|
+
text = text.slice(frontMatter[0].length);
|
|
17
|
+
const line = /^title:[ \t]*(.+)$/m.exec(frontMatter[1]);
|
|
18
|
+
if (line)
|
|
19
|
+
title = unquote(line[1]);
|
|
20
|
+
}
|
|
21
|
+
const heading = /^\s*#[ \t]+(.+?)[ \t]*#*[ \t]*\n+(?=[\s\S]*\S)/.exec(text);
|
|
22
|
+
if (heading && !hasTitle && (!title || heading[1].trim() === title)) {
|
|
23
|
+
title = heading[1].trim();
|
|
24
|
+
text = text.slice(heading[0].length);
|
|
25
|
+
}
|
|
26
|
+
return { text: text.trimStart(), ...(title && !hasTitle ? { title } : {}) };
|
|
27
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* standard.site publications and documents, with Markdown as the document content. Pure
|
|
3
|
+
* helpers: reading records defensively, and building the records an app writes.
|
|
4
|
+
*/
|
|
5
|
+
import { type Palette } from '../palettes.js';
|
|
6
|
+
export declare const PUBLICATION_COLLECTION = "site.standard.publication";
|
|
7
|
+
export declare const DOCUMENT_COLLECTION = "site.standard.document";
|
|
8
|
+
/** The `$type` of a document's Markdown content. */
|
|
9
|
+
export declare const MARKDOWN_CONTENT = "blog.atmo.content.markdown";
|
|
10
|
+
/** Where publications written with these helpers are registered, unless an app says otherwise. */
|
|
11
|
+
export declare const ATMO_BLOG_ORIGIN = "https://atmo.blog";
|
|
12
|
+
/**
|
|
13
|
+
* No GIFs for now: image CDNs, Bluesky's among them, serve an animated one as its first frame,
|
|
14
|
+
* so it could not be shown as it was uploaded.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ARTICLE_IMAGE_TYPES: readonly string[];
|
|
17
|
+
export declare const ARTICLE_LIMITS: {
|
|
18
|
+
readonly title: 300;
|
|
19
|
+
readonly description: 300;
|
|
20
|
+
/** A publication's name. */
|
|
21
|
+
readonly name: 100;
|
|
22
|
+
/** The most Markdown the parser reads as an article. */
|
|
23
|
+
readonly text: 200000;
|
|
24
|
+
readonly images: 200;
|
|
25
|
+
readonly imageBytes: 2000000;
|
|
26
|
+
/**
|
|
27
|
+
* The most a document record may take as JSON. Account servers refuse larger writes (the
|
|
28
|
+
* reference server at 150 KB for the whole request), whatever the lexicons allow.
|
|
29
|
+
*/
|
|
30
|
+
readonly recordBytes: 140000;
|
|
31
|
+
/** standard.site's limit for cover images and publication icons. */
|
|
32
|
+
readonly coverBytes: 1000000;
|
|
33
|
+
};
|
|
34
|
+
export type ArticleBlobRef = {
|
|
35
|
+
$type: 'blob';
|
|
36
|
+
ref: {
|
|
37
|
+
$link: string;
|
|
38
|
+
};
|
|
39
|
+
mimeType: string;
|
|
40
|
+
size: number;
|
|
41
|
+
};
|
|
42
|
+
export type Publication = {
|
|
43
|
+
rkey: string;
|
|
44
|
+
name: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
/** CID of its icon. */
|
|
47
|
+
icon?: string;
|
|
48
|
+
/** Its own site, when it was made elsewhere. Such a publication is shown but not edited. */
|
|
49
|
+
url?: string;
|
|
50
|
+
/** The colors it chose, as two of the kit's palettes. */
|
|
51
|
+
theme?: Palette;
|
|
52
|
+
};
|
|
53
|
+
export type ArticleSummary = {
|
|
54
|
+
rkey: string;
|
|
55
|
+
/** rkey of its publication. */
|
|
56
|
+
publication: string;
|
|
57
|
+
title: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
publishedAt: string;
|
|
60
|
+
updatedAt?: string;
|
|
61
|
+
/** CID of its cover image. */
|
|
62
|
+
cover?: string;
|
|
63
|
+
/** Where to read it, for a post in a publication made elsewhere. */
|
|
64
|
+
url?: string;
|
|
65
|
+
/** The Bluesky post announcing it; its replies are the comments. */
|
|
66
|
+
bskyPost?: string;
|
|
67
|
+
/** Its CID, which a reply has to name. */
|
|
68
|
+
bskyPostCid?: string;
|
|
69
|
+
};
|
|
70
|
+
export type Article = ArticleSummary & {
|
|
71
|
+
text: string;
|
|
72
|
+
images: ArticleBlobRef[];
|
|
73
|
+
};
|
|
74
|
+
export declare const BLUESKY_POST_URI: RegExp;
|
|
75
|
+
export declare const isCid: (value: unknown) => value is string;
|
|
76
|
+
export declare const isRecordKey: (value: unknown) => value is string;
|
|
77
|
+
export declare const publicationPath: (actor: string, rkey: string) => string;
|
|
78
|
+
export declare const articlePath: (actor: string, rkey: string) => string;
|
|
79
|
+
/** A document's path below its publication's address. */
|
|
80
|
+
export declare const documentPath: (rkey: string) => string;
|
|
81
|
+
/** The address a publication is registered under. */
|
|
82
|
+
export declare const publicationUrl: (did: string, rkey: string, origin?: string) => string;
|
|
83
|
+
export declare const articleUrl: (actor: string, rkey: string, origin?: string) => string;
|
|
84
|
+
export declare const publicationUri: (did: string, rkey: string) => string;
|
|
85
|
+
export declare const documentUri: (did: string, rkey: string) => string;
|
|
86
|
+
export declare function rkeyOf(uri: unknown): string;
|
|
87
|
+
/** `cid:<CID>` in an image destination refers to an uploaded image. */
|
|
88
|
+
export declare function imageCid(url: string): string | undefined;
|
|
89
|
+
export declare function isBlobRef(value: unknown): value is ArticleBlobRef;
|
|
90
|
+
/** A cover image or icon small enough, and of a type, to be served. */
|
|
91
|
+
export declare function isImageBlob(value: unknown): value is ArticleBlobRef;
|
|
92
|
+
/**
|
|
93
|
+
* A link to an article page: `/profile/{actor}/article/{rkey}`, or the same below its
|
|
94
|
+
* publication, which is the address a document has on record.
|
|
95
|
+
*/
|
|
96
|
+
export declare function parseArticleLink(url: string, origins?: readonly string[]): {
|
|
97
|
+
actor: string;
|
|
98
|
+
rkey: string;
|
|
99
|
+
path: string;
|
|
100
|
+
} | null;
|
|
101
|
+
/** A publication made on `origin`: one registered under its own address there. */
|
|
102
|
+
export declare function parsePublication(did: string, rkey: string, value: unknown, origin?: string): Publication | null;
|
|
103
|
+
/**
|
|
104
|
+
* A palette as standard.site's basic theme, for sites and readers that do not know the kit's
|
|
105
|
+
* palettes: the page and text of the base, links and buttons in the accent, white on those.
|
|
106
|
+
*/
|
|
107
|
+
export declare function basicTheme(palette: Palette): Record<string, unknown>;
|
|
108
|
+
/** Any of the account's publications: one made on `origin`, or one with a site of its own. */
|
|
109
|
+
export declare function parseAnyPublication(did: string, rkey: string, value: unknown, origin?: string): Publication | null;
|
|
110
|
+
/** rkey of the account's own publication a document names as its site. */
|
|
111
|
+
export declare function documentPublication(did: string, value: unknown): string | undefined;
|
|
112
|
+
/** A post in a publication made elsewhere, whatever its content: it is read on that site. */
|
|
113
|
+
export declare function parseExternalDocument(rkey: string, value: unknown, publication: Publication): ArticleSummary | null;
|
|
114
|
+
/** A document with Markdown content in one of the author's own publications. */
|
|
115
|
+
export declare function parseArticle(did: string, rkey: string, value: unknown): Article | null;
|
|
116
|
+
export declare function articleSummary(article: Article): ArticleSummary;
|
|
117
|
+
/** Why a record could not be built. The message can be shown to the author. */
|
|
118
|
+
export declare class ArticleError extends Error {
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The publication record to write. Fields of `existing` this does not know are kept.
|
|
122
|
+
* `icon`: a newly uploaded one, `null` to remove it; otherwise it stays.
|
|
123
|
+
* `theme`: the colors, written as their names in `preferences` (`accentColor`, `baseColor`) and
|
|
124
|
+
* as `basicTheme` for everyone else; `null` to remove them; otherwise they stay.
|
|
125
|
+
*/
|
|
126
|
+
export declare function publicationRecord(input: {
|
|
127
|
+
did: string;
|
|
128
|
+
rkey: string;
|
|
129
|
+
name: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
icon?: ArticleBlobRef | null;
|
|
132
|
+
theme?: Palette | null;
|
|
133
|
+
/** The record being edited. */
|
|
134
|
+
existing?: unknown;
|
|
135
|
+
origin?: string;
|
|
136
|
+
}): Record<string, unknown>;
|
|
137
|
+
/**
|
|
138
|
+
* The document record to write for an article. Fields of `existing` this does not know are
|
|
139
|
+
* kept (tags, the Bluesky announcement, …), as is its publication date.
|
|
140
|
+
*
|
|
141
|
+
* Every uploaded image the text shows (`cid:` destinations) must be among `blobs` or the
|
|
142
|
+
* images of `existing`: the record keeps them alive. Each must be of one of
|
|
143
|
+
* `ARTICLE_IMAGE_TYPES` and at most `ARTICLE_LIMITS.imageBytes`.
|
|
144
|
+
*
|
|
145
|
+
* The record stays within `ARTICLE_LIMITS.recordBytes`: its plain-text copy (`textContent`) is
|
|
146
|
+
* cut short when the text leaves no room for all of it, and a text too long by itself is
|
|
147
|
+
* refused.
|
|
148
|
+
*/
|
|
149
|
+
export declare function articleRecord(input: {
|
|
150
|
+
did: string;
|
|
151
|
+
rkey: string;
|
|
152
|
+
/** rkey of the author's publication it goes into. */
|
|
153
|
+
publication: string;
|
|
154
|
+
title: string;
|
|
155
|
+
/** Left out for the opening of the text. */
|
|
156
|
+
description?: string;
|
|
157
|
+
/** A newly uploaded cover, `null` to remove it; otherwise it stays. */
|
|
158
|
+
cover?: ArticleBlobRef | null;
|
|
159
|
+
/** Article Markdown. */
|
|
160
|
+
text: string;
|
|
161
|
+
/** Images uploaded for this version. */
|
|
162
|
+
blobs?: readonly ArticleBlobRef[];
|
|
163
|
+
/** The record being edited. */
|
|
164
|
+
existing?: unknown;
|
|
165
|
+
now?: Date;
|
|
166
|
+
}): Record<string, unknown>;
|