@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.
Files changed (115) hide show
  1. package/dist/articles/ArticleCard.svelte +97 -0
  2. package/dist/articles/ArticleCard.svelte.d.ts +20 -0
  3. package/dist/articles/ArticleCodeBlock.svelte +121 -0
  4. package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
  5. package/dist/articles/ArticleEditor.svelte +340 -0
  6. package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
  7. package/dist/articles/ArticleLinkEmbed.svelte +50 -0
  8. package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
  9. package/dist/articles/ArticleView.svelte +128 -0
  10. package/dist/articles/ArticleView.svelte.d.ts +46 -0
  11. package/dist/articles/PublicationIcon.svelte +37 -0
  12. package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
  13. package/dist/articles/article-link-embed.d.ts +36 -0
  14. package/dist/articles/article-link-embed.js +29 -0
  15. package/dist/articles/dates.d.ts +2 -0
  16. package/dist/articles/dates.js +12 -0
  17. package/dist/articles/images.d.ts +5 -0
  18. package/dist/articles/images.js +44 -0
  19. package/dist/articles/markdown.d.ts +15 -0
  20. package/dist/articles/markdown.js +52 -0
  21. package/dist/articles/paste.d.ts +11 -0
  22. package/dist/articles/paste.js +27 -0
  23. package/dist/articles/records.d.ts +166 -0
  24. package/dist/articles/records.js +423 -0
  25. package/dist/articles/styles.d.ts +4 -0
  26. package/dist/articles/styles.js +14 -0
  27. package/dist/articles-data.d.ts +8 -0
  28. package/dist/articles-data.js +8 -0
  29. package/dist/articles.d.ts +10 -0
  30. package/dist/articles.js +8 -0
  31. package/dist/components/ExternalEmbed.svelte +16 -2
  32. package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
  33. package/dist/components/IconMaker.svelte +119 -0
  34. package/dist/components/IconMaker.svelte.d.ts +9 -0
  35. package/dist/components/IconRail.svelte +9 -6
  36. package/dist/components/IconRail.svelte.d.ts +2 -0
  37. package/dist/components/LinkEmbed.svelte +24 -21
  38. package/dist/components/LinkEmbed.svelte.d.ts +3 -2
  39. package/dist/components/PaletteApply.svelte +62 -0
  40. package/dist/components/PaletteApply.svelte.d.ts +9 -0
  41. package/dist/components/PalettePicker.svelte +92 -0
  42. package/dist/components/PalettePicker.svelte.d.ts +13 -0
  43. package/dist/components/PostComments.svelte +129 -0
  44. package/dist/components/PostComments.svelte.d.ts +15 -0
  45. package/dist/components/RichText.svelte +199 -9
  46. package/dist/components/RichText.svelte.d.ts +17 -0
  47. package/dist/components/RichTextEditor.svelte +164 -13
  48. package/dist/components/RichTextEditor.svelte.d.ts +26 -3
  49. package/dist/components/composer/ComposerPost.svelte +10 -0
  50. package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
  51. package/dist/components/composer/PostComposer.svelte +28 -2
  52. package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
  53. package/dist/editor/EditorMenus.svelte +438 -0
  54. package/dist/editor/EditorMenus.svelte.d.ts +9 -0
  55. package/dist/editor/SlashOptions.svelte +45 -0
  56. package/dist/editor/SlashOptions.svelte.d.ts +12 -0
  57. package/dist/editor/article-commands.d.ts +44 -0
  58. package/dist/editor/article-commands.js +289 -0
  59. package/dist/editor/article-extensions.d.ts +8 -0
  60. package/dist/editor/article-extensions.js +315 -0
  61. package/dist/editor/article-menus.d.ts +2 -0
  62. package/dist/editor/article-menus.js +3 -0
  63. package/dist/editor/document.d.ts +5 -0
  64. package/dist/editor/document.js +163 -12
  65. package/dist/editor/image-node.d.ts +8 -0
  66. package/dist/editor/image-node.js +75 -0
  67. package/dist/editor/markdown-extensions.d.ts +1 -5
  68. package/dist/editor/markdown-extensions.js +37 -2
  69. package/dist/editor/slash-menu.svelte.d.ts +9 -0
  70. package/dist/editor/slash-menu.svelte.js +134 -0
  71. package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
  72. package/dist/embeds/PostLinkEmbed.svelte +12 -29
  73. package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
  74. package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
  75. package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
  76. package/dist/embeds/defaults.d.ts +4 -2
  77. package/dist/embeds/defaults.js +7 -3
  78. package/dist/embeds/load.d.ts +44 -0
  79. package/dist/embeds/load.js +139 -0
  80. package/dist/embeds/types.d.ts +18 -3
  81. package/dist/events/EventComments.svelte +4 -101
  82. package/dist/events/EventComments.svelte.d.ts +1 -1
  83. package/dist/events/EventView.svelte +5 -0
  84. package/dist/events/EventView.svelte.d.ts +3 -0
  85. package/dist/events/event-link-embed.d.ts +4 -1
  86. package/dist/events/event-link-embed.js +9 -1
  87. package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
  88. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
  89. package/dist/icon-maker/artwork.d.ts +11 -0
  90. package/dist/icon-maker/artwork.js +25 -0
  91. package/dist/icon-maker/index.d.ts +12 -0
  92. package/dist/icon-maker/index.js +73 -0
  93. package/dist/index.d.ts +10 -3
  94. package/dist/index.js +7 -1
  95. package/dist/palettes.d.ts +20 -0
  96. package/dist/palettes.js +37 -0
  97. package/dist/richtext/article-styles.d.ts +10 -0
  98. package/dist/richtext/article-styles.js +28 -0
  99. package/dist/richtext/document.d.ts +63 -1
  100. package/dist/richtext/document.js +54 -0
  101. package/dist/richtext/markdown.d.ts +19 -4
  102. package/dist/richtext/markdown.js +223 -18
  103. package/dist/richtext/serialize.d.ts +5 -1
  104. package/dist/richtext/serialize.js +163 -31
  105. package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
  106. package/dist/richtext/vendor/markdown-tree.js +2584 -26
  107. package/dist/richtext.d.ts +7 -5
  108. package/dist/richtext.js +1 -1
  109. package/dist/social/external-embeds.d.ts +5 -0
  110. package/dist/social/external-embeds.js +6 -1
  111. package/dist/social/mention-suggestions.svelte.js +18 -7
  112. package/dist/social/posts.d.ts +2 -0
  113. package/dist/social/posts.js +43 -2
  114. package/dist/social/profile.js +2 -1
  115. package/package.json +28 -2
@@ -0,0 +1,423 @@
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 { accentColorRgb, baseColorRgb, isAccentColor, isBaseColor } from '../palettes.js';
6
+ import { autoDescription, imageUrls, parseArticleText, plainText } from './markdown.js';
7
+ export const PUBLICATION_COLLECTION = 'site.standard.publication';
8
+ export const DOCUMENT_COLLECTION = 'site.standard.document';
9
+ /** The `$type` of a document's Markdown content. */
10
+ export const MARKDOWN_CONTENT = 'blog.atmo.content.markdown';
11
+ /** Where publications written with these helpers are registered, unless an app says otherwise. */
12
+ export const ATMO_BLOG_ORIGIN = 'https://atmo.blog';
13
+ /**
14
+ * No GIFs for now: image CDNs, Bluesky's among them, serve an animated one as its first frame,
15
+ * so it could not be shown as it was uploaded.
16
+ */
17
+ export const ARTICLE_IMAGE_TYPES = [
18
+ 'image/png',
19
+ 'image/jpeg',
20
+ 'image/webp',
21
+ 'image/avif'
22
+ ];
23
+ export const ARTICLE_LIMITS = {
24
+ title: 300,
25
+ description: 300,
26
+ /** A publication's name. */
27
+ name: 100,
28
+ /** The most Markdown the parser reads as an article. */
29
+ text: 200_000,
30
+ images: 200,
31
+ imageBytes: 2_000_000,
32
+ /**
33
+ * The most a document record may take as JSON. Account servers refuse larger writes (the
34
+ * reference server at 150 KB for the whole request), whatever the lexicons allow.
35
+ */
36
+ recordBytes: 140_000,
37
+ /** standard.site's limit for cover images and publication icons. */
38
+ coverBytes: 1_000_000
39
+ };
40
+ const CID = /^[a-z2-7]{20,200}$/;
41
+ const RKEY = /^[a-zA-Z0-9._~-]{1,512}$/;
42
+ export const BLUESKY_POST_URI = /^at:\/\/did:[a-z]+:[A-Za-z0-9._:%-]+\/app\.bsky\.feed\.post\/[A-Za-z0-9._~-]+$/;
43
+ export const isCid = (value) => typeof value === 'string' && CID.test(value);
44
+ export const isRecordKey = (value) => typeof value === 'string' && RKEY.test(value);
45
+ const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
46
+ const text = (value) => typeof value === 'string' && value.trim() ? value : undefined;
47
+ const date = (value) => typeof value === 'string' && !Number.isNaN(Date.parse(value)) ? value : undefined;
48
+ export const publicationPath = (actor, rkey) => `/profile/${actor}/publication/${rkey}`;
49
+ export const articlePath = (actor, rkey) => `/profile/${actor}/article/${rkey}`;
50
+ /** A document's path below its publication's address. */
51
+ export const documentPath = (rkey) => `/article/${rkey}`;
52
+ /** The address a publication is registered under. */
53
+ export const publicationUrl = (did, rkey, origin = ATMO_BLOG_ORIGIN) => `${origin}${publicationPath(did, rkey)}`;
54
+ export const articleUrl = (actor, rkey, origin = ATMO_BLOG_ORIGIN) => `${origin}${articlePath(actor, rkey)}`;
55
+ export const publicationUri = (did, rkey) => `at://${did}/${PUBLICATION_COLLECTION}/${rkey}`;
56
+ export const documentUri = (did, rkey) => `at://${did}/${DOCUMENT_COLLECTION}/${rkey}`;
57
+ export function rkeyOf(uri) {
58
+ return typeof uri === 'string' ? (uri.split('/').pop() ?? '') : '';
59
+ }
60
+ /** `cid:<CID>` in an image destination refers to an uploaded image. */
61
+ export function imageCid(url) {
62
+ const cid = url.startsWith('cid:') ? url.slice(4) : '';
63
+ return CID.test(cid) ? cid : undefined;
64
+ }
65
+ export function isBlobRef(value) {
66
+ const blob = object(value);
67
+ return (blob?.$type === 'blob' &&
68
+ isCid(object(blob.ref)?.$link) &&
69
+ typeof blob.mimeType === 'string' &&
70
+ typeof blob.size === 'number');
71
+ }
72
+ /** A cover image or icon small enough, and of a type, to be served. */
73
+ export function isImageBlob(value) {
74
+ return (isBlobRef(value) &&
75
+ ARTICLE_IMAGE_TYPES.includes(value.mimeType) &&
76
+ value.size <= ARTICLE_LIMITS.coverBytes);
77
+ }
78
+ /**
79
+ * A link to an article page: `/profile/{actor}/article/{rkey}`, or the same below its
80
+ * publication, which is the address a document has on record.
81
+ */
82
+ export function parseArticleLink(url, origins = [ATMO_BLOG_ORIGIN]) {
83
+ let parsed;
84
+ try {
85
+ parsed = new URL(url);
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ if (!origins.includes(parsed.origin))
91
+ return null;
92
+ const match = /^\/profile\/([^/]+)(?:\/publication\/[^/]+)?\/article\/([^/]+)\/?$/.exec(parsed.pathname);
93
+ if (!match)
94
+ return null;
95
+ let actor;
96
+ try {
97
+ actor = decodeURIComponent(match[1]);
98
+ }
99
+ catch {
100
+ return null;
101
+ }
102
+ if (!/^(did:[a-z]+:[A-Za-z0-9._:%-]+|[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+)$/.test(actor))
103
+ return null;
104
+ if (!RKEY.test(match[2]))
105
+ return null;
106
+ return { actor, rkey: match[2], path: articlePath(actor, match[2]) };
107
+ }
108
+ /** A publication made on `origin`: one registered under its own address there. */
109
+ export function parsePublication(did, rkey, value, origin = ATMO_BLOG_ORIGIN) {
110
+ const record = object(value);
111
+ const name = text(record?.name);
112
+ if (!record || !name || !RKEY.test(rkey) || record.url !== publicationUrl(did, rkey, origin))
113
+ return null;
114
+ const description = text(record.description);
115
+ const theme = paletteOf(record.preferences);
116
+ return {
117
+ rkey,
118
+ name,
119
+ ...(description ? { description } : {}),
120
+ ...(isImageBlob(record.icon) ? { icon: record.icon.ref.$link } : {}),
121
+ ...(theme ? { theme } : {})
122
+ };
123
+ }
124
+ /** The palettes a publication names in its preferences, when both are the kit's. */
125
+ function paletteOf(preferences) {
126
+ const { accentColor: accent, baseColor: base } = object(preferences) ?? {};
127
+ return isAccentColor(accent) && isBaseColor(base) ? { accent, base } : undefined;
128
+ }
129
+ const rgb = ([r, g, b]) => ({
130
+ $type: 'site.standard.theme.color#rgb',
131
+ r,
132
+ g,
133
+ b
134
+ });
135
+ /**
136
+ * A palette as standard.site's basic theme, for sites and readers that do not know the kit's
137
+ * palettes: the page and text of the base, links and buttons in the accent, white on those.
138
+ */
139
+ export function basicTheme(palette) {
140
+ return {
141
+ $type: 'site.standard.theme.basic',
142
+ background: rgb(baseColorRgb[palette.base].background),
143
+ foreground: rgb(baseColorRgb[palette.base].foreground),
144
+ accent: rgb(accentColorRgb[palette.accent]),
145
+ accentForeground: rgb([255, 255, 255])
146
+ };
147
+ }
148
+ function webUrl(value) {
149
+ if (typeof value !== 'string')
150
+ return undefined;
151
+ try {
152
+ const url = new URL(value);
153
+ return (url.protocol === 'https:' || url.protocol === 'http:') && !url.username && !url.password
154
+ ? url.href
155
+ : undefined;
156
+ }
157
+ catch {
158
+ return undefined;
159
+ }
160
+ }
161
+ /** Any of the account's publications: one made on `origin`, or one with a site of its own. */
162
+ export function parseAnyPublication(did, rkey, value, origin = ATMO_BLOG_ORIGIN) {
163
+ const own = parsePublication(did, rkey, value, origin);
164
+ if (own)
165
+ return own;
166
+ const record = object(value);
167
+ const name = text(record?.name);
168
+ const url = webUrl(record?.url);
169
+ // Blento keeps a publication per page for its own use; those are not blogs.
170
+ if (!record || !name || !url || !RKEY.test(rkey) || rkey.startsWith('blento.'))
171
+ return null;
172
+ const description = text(record.description);
173
+ return {
174
+ rkey,
175
+ name,
176
+ url,
177
+ ...(description ? { description } : {}),
178
+ ...(isImageBlob(record.icon) ? { icon: record.icon.ref.$link } : {})
179
+ };
180
+ }
181
+ /** rkey of the account's own publication a document names as its site. */
182
+ export function documentPublication(did, value) {
183
+ const site = object(value)?.site;
184
+ const prefix = `at://${did}/${PUBLICATION_COLLECTION}/`;
185
+ return typeof site === 'string' && site.startsWith(prefix)
186
+ ? site.slice(prefix.length)
187
+ : undefined;
188
+ }
189
+ /** The Bluesky post a document names as its announcement. */
190
+ function bskyRef(record) {
191
+ const ref = object(record.bskyPostRef);
192
+ if (typeof ref?.uri !== 'string' || !BLUESKY_POST_URI.test(ref.uri))
193
+ return {};
194
+ return {
195
+ bskyPost: ref.uri,
196
+ ...(typeof ref.cid === 'string' && /^[a-z0-9]{20,200}$/.test(ref.cid)
197
+ ? { bskyPostCid: ref.cid }
198
+ : {})
199
+ };
200
+ }
201
+ /** A post in a publication made elsewhere, whatever its content: it is read on that site. */
202
+ export function parseExternalDocument(rkey, value, publication) {
203
+ const record = object(value);
204
+ const title = text(record?.title);
205
+ const publishedAt = date(record?.publishedAt);
206
+ if (!record || !title || !publishedAt || !publication.url || !RKEY.test(rkey))
207
+ return null;
208
+ const path = typeof record.path === 'string' && record.path.startsWith('/') ? record.path : '';
209
+ const url = webUrl(publication.url.replace(/\/+$/, '') + path);
210
+ if (!url)
211
+ return null;
212
+ const description = text(record.description);
213
+ return {
214
+ rkey,
215
+ publication: publication.rkey,
216
+ title,
217
+ publishedAt,
218
+ url,
219
+ ...(description ? { description } : {}),
220
+ ...(isImageBlob(record.coverImage) ? { cover: record.coverImage.ref.$link } : {}),
221
+ ...bskyRef(record)
222
+ };
223
+ }
224
+ /** A document with Markdown content in one of the author's own publications. */
225
+ export function parseArticle(did, rkey, value) {
226
+ const record = object(value);
227
+ const content = object(record?.content);
228
+ const title = text(record?.title);
229
+ const publishedAt = date(record?.publishedAt);
230
+ const prefix = `at://${did}/${PUBLICATION_COLLECTION}/`;
231
+ const site = typeof record?.site === 'string' ? record.site : '';
232
+ if (!record ||
233
+ !content ||
234
+ !title ||
235
+ !publishedAt ||
236
+ !RKEY.test(rkey) ||
237
+ content.$type !== MARKDOWN_CONTENT ||
238
+ typeof content.text !== 'string' ||
239
+ !site.startsWith(prefix) ||
240
+ !RKEY.test(site.slice(prefix.length)))
241
+ return null;
242
+ const description = text(record.description);
243
+ const updatedAt = date(record.updatedAt);
244
+ return {
245
+ rkey,
246
+ publication: site.slice(prefix.length),
247
+ title,
248
+ publishedAt,
249
+ text: content.text,
250
+ images: Array.isArray(content.images) ? content.images.filter(isBlobRef) : [],
251
+ ...(description ? { description } : {}),
252
+ ...(updatedAt ? { updatedAt } : {}),
253
+ ...(isImageBlob(record.coverImage) ? { cover: record.coverImage.ref.$link } : {}),
254
+ ...bskyRef(record)
255
+ };
256
+ }
257
+ export function articleSummary(article) {
258
+ const summary = { ...article };
259
+ delete summary.text;
260
+ delete summary.images;
261
+ return summary;
262
+ }
263
+ /** Why a record could not be built. The message can be shown to the author. */
264
+ export class ArticleError extends Error {
265
+ }
266
+ const line = (value) => value.replace(/\s+/g, ' ').trim();
267
+ /**
268
+ * The publication record to write. Fields of `existing` this does not know are kept.
269
+ * `icon`: a newly uploaded one, `null` to remove it; otherwise it stays.
270
+ * `theme`: the colors, written as their names in `preferences` (`accentColor`, `baseColor`) and
271
+ * as `basicTheme` for everyone else; `null` to remove them; otherwise they stay.
272
+ */
273
+ export function publicationRecord(input) {
274
+ const name = line(input.name);
275
+ if (!name)
276
+ throw new ArticleError('Add a name first.');
277
+ if (name.length > ARTICLE_LIMITS.name)
278
+ throw new ArticleError('This name is too long.');
279
+ const description = line(input.description ?? '');
280
+ if (description.length > ARTICLE_LIMITS.description)
281
+ throw new ArticleError('This description is too long.');
282
+ if (input.icon && !isImageBlob(input.icon))
283
+ throw new ArticleError('This icon cannot be used.');
284
+ const theme = input.theme;
285
+ if (theme && !(isAccentColor(theme.accent) && isBaseColor(theme.base)))
286
+ throw new ArticleError('These colors cannot be used.');
287
+ const { icon, ...rest } = object(input.existing) ?? {};
288
+ delete rest.description;
289
+ const nextIcon = input.icon === undefined ? icon : input.icon;
290
+ if (theme !== undefined) {
291
+ // Other preferences are the publication's, or another app's, to keep.
292
+ const preferences = { ...object(rest.preferences) };
293
+ delete preferences.accentColor;
294
+ delete preferences.baseColor;
295
+ if (theme)
296
+ Object.assign(preferences, { accentColor: theme.accent, baseColor: theme.base });
297
+ if (Object.keys(preferences).length)
298
+ rest.preferences = preferences;
299
+ else
300
+ delete rest.preferences;
301
+ if (theme)
302
+ rest.basicTheme = basicTheme(theme);
303
+ else
304
+ delete rest.basicTheme;
305
+ }
306
+ return {
307
+ ...rest,
308
+ ...(nextIcon ? { icon: nextIcon } : {}),
309
+ $type: PUBLICATION_COLLECTION,
310
+ url: publicationUrl(input.did, input.rkey, input.origin),
311
+ name,
312
+ ...(description ? { description } : {})
313
+ };
314
+ }
315
+ /**
316
+ * The document record to write for an article. Fields of `existing` this does not know are
317
+ * kept (tags, the Bluesky announcement, …), as is its publication date.
318
+ *
319
+ * Every uploaded image the text shows (`cid:` destinations) must be among `blobs` or the
320
+ * images of `existing`: the record keeps them alive. Each must be of one of
321
+ * `ARTICLE_IMAGE_TYPES` and at most `ARTICLE_LIMITS.imageBytes`.
322
+ *
323
+ * The record stays within `ARTICLE_LIMITS.recordBytes`: its plain-text copy (`textContent`) is
324
+ * cut short when the text leaves no room for all of it, and a text too long by itself is
325
+ * refused.
326
+ */
327
+ export function articleRecord(input) {
328
+ const title = line(input.title);
329
+ if (!title)
330
+ throw new ArticleError('Add a title first.');
331
+ if (title.length > ARTICLE_LIMITS.title)
332
+ throw new ArticleError('This title is too long.');
333
+ const written = line(input.description ?? '');
334
+ if (written.length > ARTICLE_LIMITS.description)
335
+ throw new ArticleError('This description is too long.');
336
+ if (input.cover && !isImageBlob(input.cover))
337
+ throw new ArticleError('This cover cannot be used.');
338
+ const body = input.text.trim();
339
+ if (body.length > ARTICLE_LIMITS.text)
340
+ throw new ArticleError('This post is too long to publish.');
341
+ const document = parseArticleText(body);
342
+ if (!document.markdown)
343
+ throw new ArticleError('This text is too long or too complex to publish.');
344
+ const existing = object(input.existing) ?? {};
345
+ const previous = object(existing.content)?.images;
346
+ const known = new Map([...(Array.isArray(previous) ? previous : []), ...(input.blobs ?? [])]
347
+ .filter(isBlobRef)
348
+ .map((image) => [image.ref.$link, image]));
349
+ const images = new Map();
350
+ for (const url of imageUrls(document)) {
351
+ const cid = imageCid(url);
352
+ if (!cid)
353
+ continue;
354
+ const image = known.get(cid);
355
+ if (!image)
356
+ throw new ArticleError('An image is missing. Add it again and retry.');
357
+ if (!ARTICLE_IMAGE_TYPES.includes(image.mimeType))
358
+ throw new ArticleError('An image is of a type that cannot be used.');
359
+ if (image.size > ARTICLE_LIMITS.imageBytes)
360
+ throw new ArticleError('An image is too large.');
361
+ images.set(cid, image);
362
+ }
363
+ if (images.size > ARTICLE_LIMITS.images)
364
+ throw new ArticleError('Too many images.');
365
+ const plain = plainText(document);
366
+ const now = (input.now ?? new Date()).toISOString();
367
+ const { coverImage, ...rest } = existing;
368
+ delete rest.description;
369
+ delete rest.textContent;
370
+ const description = written || autoDescription(document, ARTICLE_LIMITS.description);
371
+ const cover = input.cover === undefined ? coverImage : input.cover;
372
+ const edited = input.existing !== undefined && input.existing !== null;
373
+ const record = (textContent) => ({
374
+ ...rest,
375
+ $type: DOCUMENT_COLLECTION,
376
+ site: publicationUri(input.did, input.publication),
377
+ path: documentPath(input.rkey),
378
+ title,
379
+ ...(description ? { description } : {}),
380
+ ...(cover ? { coverImage: cover } : {}),
381
+ publishedAt: date(existing.publishedAt) ?? now,
382
+ ...(edited ? { updatedAt: now } : {}),
383
+ ...(textContent ? { textContent } : {}),
384
+ content: {
385
+ $type: MARKDOWN_CONTENT,
386
+ text: body,
387
+ ...(images.size ? { images: [...images.values()] } : {})
388
+ }
389
+ });
390
+ // The plain text is a copy for search and previews. When both do not fit, the copy is cut:
391
+ // the text itself is never shortened.
392
+ const full = record(plain);
393
+ const over = jsonBytes(full) - ARTICLE_LIMITS.recordBytes;
394
+ if (over <= 0)
395
+ return full;
396
+ const without = record('');
397
+ const room = ARTICLE_LIMITS.recordBytes - jsonBytes(without);
398
+ if (room < 0)
399
+ throw new ArticleError('This post is too long to publish.');
400
+ return record(fitBytes(plain, room - 20));
401
+ }
402
+ const jsonBytes = (value) => new TextEncoder().encode(JSON.stringify(value)).length;
403
+ /** The start of `text` that takes at most `bytes` as a JSON string, cut at a word. */
404
+ function fitBytes(text, bytes) {
405
+ if (bytes <= 0)
406
+ return '';
407
+ let low = 0;
408
+ let high = text.length;
409
+ while (low < high) {
410
+ const middle = Math.ceil((low + high) / 2);
411
+ if (jsonBytes(text.slice(0, middle)) <= bytes)
412
+ low = middle;
413
+ else
414
+ high = middle - 1;
415
+ }
416
+ if (low === text.length)
417
+ return text;
418
+ // Not in the middle of a character made of two code units.
419
+ const code = text.charCodeAt(low - 1);
420
+ const cut = text.slice(0, code >= 0xd800 && code <= 0xdbff ? low - 1 : low);
421
+ const space = cut.lastIndexOf(' ');
422
+ return (space > cut.length / 2 ? cut.slice(0, space) : cut).trimEnd();
423
+ }
@@ -0,0 +1,4 @@
1
+ /** For `RichTextEditor markdown="article"`, where `#` is an h1. */
2
+ export declare const articleEditorClass: string;
3
+ /** For `RichText` with `headingOffset={1}`: the title is the page's h1, so `#` is an h2. */
4
+ export declare const articleClass: string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Long-form typography, shared by the editor and the published article so that what is
3
+ * written is what will be shown. `!` because the components bring their own compact sizes.
4
+ * An image is never taller than the window, so that it can be seen whole.
5
+ * Nothing here reaches into an embed (`[data-link-embed]`), which brings its own headings
6
+ * and images. The classes are written out in full so that Tailwind finds them.
7
+ */
8
+ const base = 'text-[1.0625rem] leading-[1.75]! space-y-5! [&_.ProseMirror]:space-y-5! [&_.ProseMirror]:leading-[1.75]! [&_:is(h1,h2,h3,h4,h5,h6):not([data-link-embed]_*)]:tracking-tight [&_img:not([data-link-embed]_*)]:mx-auto [&_img:not([data-link-embed]_*)]:max-h-[90dvh] [&_pre:not([data-link-embed]_*)]:text-sm! [&_pre:not([data-link-embed]_*)]:leading-relaxed [&_table:not([data-link-embed]_*)]:text-[0.9375rem]';
9
+ /** For `RichTextEditor markdown="article"`, where `#` is an h1. */
10
+ export const articleEditorClass = base +
11
+ ' [&_h1:not([data-link-embed]_*)]:mt-10 [&_h1:not([data-link-embed]_*)]:text-3xl! [&_h2:not([data-link-embed]_*)]:mt-10 [&_h2:not([data-link-embed]_*)]:text-2xl! [&_h3:not([data-link-embed]_*)]:mt-8 [&_h3:not([data-link-embed]_*)]:text-xl! [&_h4:not([data-link-embed]_*)]:mt-6 [&_h4:not([data-link-embed]_*)]:text-lg!';
12
+ /** For `RichText` with `headingOffset={1}`: the title is the page's h1, so `#` is an h2. */
13
+ export const articleClass = base +
14
+ ' [&_h2:not([data-link-embed]_*)]:mt-10 [&_h2:not([data-link-embed]_*)]:text-3xl! [&_h3:not([data-link-embed]_*)]:mt-10 [&_h3:not([data-link-embed]_*)]:text-2xl! [&_h4:not([data-link-embed]_*)]:mt-8 [&_h4:not([data-link-embed]_*)]:text-xl! [&_h5:not([data-link-embed]_*)]:mt-6 [&_h5:not([data-link-embed]_*)]:text-lg!';
@@ -0,0 +1,8 @@
1
+ /** Article and publication records and pure helpers. Safe to import without Svelte or a DOM. */
2
+ export * from './articles/records.js';
3
+ export { parseArticleText, imageUrls, plainText, lead, autoDescription, excerpt, articleCodeKey, articleMathKey } from './articles/markdown.js';
4
+ export { readPastedArticle, type PastedArticle } from './articles/paste.js';
5
+ export { prepareArticleImage } from './articles/images.js';
6
+ export { formatArticleDate } from './articles/dates.js';
7
+ export { articleClass, articleEditorClass } from './articles/styles.js';
8
+ export { accentColors, baseColors, isAccentColor, isBaseColor, type AccentColor, type BaseColor, type Palette } from './palettes.js';
@@ -0,0 +1,8 @@
1
+ /** Article and publication records and pure helpers. Safe to import without Svelte or a DOM. */
2
+ export * from './articles/records.js';
3
+ export { parseArticleText, imageUrls, plainText, lead, autoDescription, excerpt, articleCodeKey, articleMathKey } from './articles/markdown.js';
4
+ export { readPastedArticle } from './articles/paste.js';
5
+ export { prepareArticleImage } from './articles/images.js';
6
+ export { formatArticleDate } from './articles/dates.js';
7
+ export { articleClass, articleEditorClass } from './articles/styles.js';
8
+ export { accentColors, baseColors, isAccentColor, isBaseColor } from './palettes.js';
@@ -0,0 +1,10 @@
1
+ /** Long-form writing: standard.site publications and Markdown articles. Apps own the writes. */
2
+ export * from './articles-data.js';
3
+ export { default as ArticleView } from './articles/ArticleView.svelte';
4
+ export { default as ArticleEditor } from './articles/ArticleEditor.svelte';
5
+ export type { ArticleEditorProps, ArticleEditorImages } from './articles/ArticleEditor.svelte';
6
+ export { default as ArticleCard } from './articles/ArticleCard.svelte';
7
+ export { default as ArticleCodeBlock } from './articles/ArticleCodeBlock.svelte';
8
+ export { default as PublicationIcon } from './articles/PublicationIcon.svelte';
9
+ export { articleLinkEmbed } from './articles/article-link-embed.js';
10
+ export type { ArticleLinkEmbedRef, LinkedArticle } from './articles/article-link-embed.js';
@@ -0,0 +1,8 @@
1
+ /** Long-form writing: standard.site publications and Markdown articles. Apps own the writes. */
2
+ export * from './articles-data.js';
3
+ export { default as ArticleView } from './articles/ArticleView.svelte';
4
+ export { default as ArticleEditor } from './articles/ArticleEditor.svelte';
5
+ export { default as ArticleCard } from './articles/ArticleCard.svelte';
6
+ export { default as ArticleCodeBlock } from './articles/ArticleCodeBlock.svelte';
7
+ export { default as PublicationIcon } from './articles/PublicationIcon.svelte';
8
+ export { articleLinkEmbed } from './articles/article-link-embed.js';
@@ -19,6 +19,7 @@
19
19
  embed,
20
20
  providers,
21
21
  embeds = false,
22
+ providerPoster = false,
22
23
  socialClient
23
24
  }: {
24
25
  embed: ExternalPostEmbed;
@@ -28,11 +29,23 @@
28
29
  * `setLinkEmbeds`), or a list. Off by default, so links stay cards.
29
30
  */
30
31
  embeds?: boolean | readonly LinkEmbedDefinition[];
32
+ /**
33
+ * Without `embed.image`, show the preview image the provider names for a player that waits
34
+ * for its play button (a YouTube thumbnail). That image comes from the provider's host, so
35
+ * it is off unless asked for.
36
+ */
37
+ providerPoster?: boolean;
31
38
  socialClient?: PreferredSocialClient | null;
32
39
  } = $props();
33
40
  const context = linkEmbedOptions();
34
41
  let linkEmbeds = $derived(selectLinkEmbeds(embeds, context()));
35
42
  let match = $derived(resolveExternalEmbed(embed, providers));
43
+ let poster = $derived(
44
+ safeWebUrl(embed.image) ??
45
+ (providerPoster && match?.player.type === 'iframe'
46
+ ? safeWebUrl(match.player.poster)
47
+ : undefined)
48
+ );
36
49
  // Consent belongs to this resolved player, not to its position in the feed.
37
50
  // A changed URL/provider/source never inherits an earlier click, even for one render.
38
51
  let activated = $state.raw<typeof match>(null);
@@ -140,10 +153,11 @@
140
153
  class={`group/play relative flex max-h-[32rem] w-full cursor-pointer items-center justify-center overflow-hidden bg-black ${focus}`}
141
154
  style:aspect-ratio={match.player.aspectRatio ?? 16 / 9}
142
155
  >
143
- {#if safeWebUrl(embed.image)}<img
144
- src={safeWebUrl(embed.image)}
156
+ {#if poster}<img
157
+ src={poster}
145
158
  alt=""
146
159
  loading="lazy"
160
+ referrerpolicy="no-referrer"
147
161
  class="absolute inset-0 size-full object-cover"
148
162
  />{/if}
149
163
  <span
@@ -9,6 +9,12 @@ type $$ComponentProps = {
9
9
  * `setLinkEmbeds`), or a list. Off by default, so links stay cards.
10
10
  */
11
11
  embeds?: boolean | readonly LinkEmbedDefinition[];
12
+ /**
13
+ * Without `embed.image`, show the preview image the provider names for a player that waits
14
+ * for its play button (a YouTube thumbnail). That image comes from the provider's host, so
15
+ * it is off unless asked for.
16
+ */
17
+ providerPoster?: boolean;
12
18
  socialClient?: PreferredSocialClient | null;
13
19
  };
14
20
  declare const ExternalEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
@@ -0,0 +1,119 @@
1
+ <script lang="ts">
2
+ import {
3
+ iconColors,
4
+ iconPng,
5
+ loadMakerIcons,
6
+ matchingIcons,
7
+ type MakerIcon
8
+ } from '../icon-maker/index.js';
9
+ import Button from './Button.svelte';
10
+ import Icon from './Icon.svelte';
11
+ import Input from './Input.svelte';
12
+ import Modal from './Modal.svelte';
13
+
14
+ // A dialog that makes a square icon: a color, and optionally a drawing on it.
15
+ let {
16
+ open = $bindable(false),
17
+ title = 'Make an icon',
18
+ onmade
19
+ }: {
20
+ open?: boolean;
21
+ title?: string;
22
+ /** Receives the icon as a 512×512 PNG. */
23
+ onmade: (icon: Blob) => void;
24
+ } = $props();
25
+
26
+ const SHOWN = 96;
27
+ let color = $state<string>(iconColors[7][1]);
28
+ let picked = $state.raw<MakerIcon>();
29
+ let search = $state('');
30
+ let all = $state.raw<MakerIcon[]>();
31
+ let failed = $state(false);
32
+ let making = $state(false);
33
+ let shown = $derived(all ? matchingIcons(all, search, SHOWN) : []);
34
+
35
+ $effect(() => {
36
+ if (!open || all) return;
37
+ failed = false;
38
+ loadMakerIcons()
39
+ .then((loaded) => (all = loaded))
40
+ .catch(() => (failed = true));
41
+ });
42
+
43
+ async function use() {
44
+ if (making) return;
45
+ making = true;
46
+ try {
47
+ onmade(await iconPng(color, picked?.node));
48
+ open = false;
49
+ } finally {
50
+ making = false;
51
+ }
52
+ }
53
+ </script>
54
+
55
+ <Modal bind:open {title}>
56
+ <div class="flex items-center gap-4">
57
+ <span
58
+ class="grid size-18 shrink-0 place-items-center rounded-[22%] text-white"
59
+ style="background:{color}"
60
+ aria-hidden="true"
61
+ >
62
+ {#if picked}<Icon img={picked.node} size={36} />{/if}
63
+ </span>
64
+ <div role="radiogroup" aria-label="Color" class="flex flex-wrap gap-1.5">
65
+ {#each iconColors as [label, value] (value)}
66
+ <button
67
+ type="button"
68
+ role="radio"
69
+ aria-checked={color === value}
70
+ aria-label={label}
71
+ title={label}
72
+ onclick={() => (color = value)}
73
+ style="background:{value}"
74
+ class="size-7 cursor-pointer rounded-full outline-offset-2 outline-base-950 focus-visible:outline-2 aria-checked:outline-2 dark:outline-base-50"
75
+ ></button>
76
+ {/each}
77
+ </div>
78
+ </div>
79
+
80
+ <Input
81
+ type="search"
82
+ bind:value={search}
83
+ aria-label="Search icons"
84
+ placeholder="Search icons…"
85
+ class="mt-5"
86
+ />
87
+ <div class="mt-3 h-52 overflow-y-auto">
88
+ {#if failed}
89
+ <p class="text-sm text-base-500">Icons could not be loaded.</p>
90
+ {:else if !all}
91
+ <p class="text-sm text-base-500">Loading icons…</p>
92
+ {:else if !shown.length}
93
+ <p class="text-sm text-base-500">No icons found.</p>
94
+ {:else}
95
+ <div class="grid grid-cols-8 gap-1">
96
+ {#each shown as icon (icon.name)}
97
+ <button
98
+ type="button"
99
+ aria-label={icon.label}
100
+ aria-pressed={picked === icon}
101
+ title={icon.label}
102
+ onclick={() => (picked = picked === icon ? undefined : icon)}
103
+ class="grid aspect-square cursor-pointer place-items-center rounded-md text-base-700 outline-accent-600 hover:bg-base-100 focus-visible:outline-2 aria-pressed:bg-base-200 aria-pressed:text-base-950 dark:text-base-300 dark:hover:bg-base-900 dark:aria-pressed:bg-base-800 dark:aria-pressed:text-base-50"
104
+ >
105
+ <Icon img={icon.node} size={22} />
106
+ </button>
107
+ {/each}
108
+ </div>
109
+ {#if shown.length === SHOWN}
110
+ <p class="mt-3 text-sm text-base-500">Search to find more.</p>
111
+ {/if}
112
+ {/if}
113
+ </div>
114
+
115
+ <div class="mt-5 flex justify-end gap-2">
116
+ <Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
117
+ <Button loading={making} onclick={use}>Use icon</Button>
118
+ </div>
119
+ </Modal>
@@ -0,0 +1,9 @@
1
+ type $$ComponentProps = {
2
+ open?: boolean;
3
+ title?: string;
4
+ /** Receives the icon as a 512×512 PNG. */
5
+ onmade: (icon: Blob) => void;
6
+ };
7
+ declare const IconMaker: import("svelte").Component<$$ComponentProps, {}, "open">;
8
+ type IconMaker = ReturnType<typeof IconMaker>;
9
+ export default IconMaker;