@atmo-dev/kit 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) 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 +155 -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/posts.d.ts +2 -0
  112. package/dist/social/posts.js +43 -2
  113. package/dist/social/profile.js +2 -1
  114. package/package.json +28 -2
@@ -0,0 +1,73 @@
1
+ let pending;
2
+ /** Every icon, loaded once on first use. */
3
+ export function loadMakerIcons() {
4
+ return (pending ??= import('./artwork.js')
5
+ .then((module) => module.icons)
6
+ .catch((error) => {
7
+ pending = undefined;
8
+ throw error;
9
+ }));
10
+ }
11
+ export function matchingIcons(icons, query, limit) {
12
+ const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
13
+ const result = [];
14
+ for (const icon of icons) {
15
+ if (words.every((word) => icon.terms.includes(word)))
16
+ result.push(icon);
17
+ if (result.length === limit)
18
+ break;
19
+ }
20
+ return result;
21
+ }
22
+ /** Tailwind's 500 shades, as plain colors: the icon is an image, shown outside the app too. */
23
+ export const iconColors = [
24
+ ['Red', '#fb2c36'],
25
+ ['Orange', '#ff6900'],
26
+ ['Amber', '#fe9a00'],
27
+ ['Yellow', '#f0b100'],
28
+ ['Lime', '#7ccf00'],
29
+ ['Green', '#00c950'],
30
+ ['Emerald', '#00bc7d'],
31
+ ['Teal', '#00bba7'],
32
+ ['Cyan', '#00b8db'],
33
+ ['Sky', '#00a6f4'],
34
+ ['Blue', '#2b7fff'],
35
+ ['Indigo', '#615fff'],
36
+ ['Violet', '#8e51ff'],
37
+ ['Purple', '#ad46ff'],
38
+ ['Fuchsia', '#e12afb'],
39
+ ['Pink', '#f6339a'],
40
+ ['Rose', '#ff2056']
41
+ ];
42
+ const escape = (value) => String(value).replace(/[&<>"]/g, (char) => `&#${char.charCodeAt(0)};`);
43
+ /** A square of the color with the icon drawn on it in white, as SVG. */
44
+ export function iconSvg(color, icon) {
45
+ const shapes = (icon ?? [])
46
+ .filter(([tag]) => /^[a-z]+$/.test(tag))
47
+ .map(([tag, attributes]) => `<${tag} ${Object.entries(attributes)
48
+ .filter(([name]) => /^[a-zA-Z-]+$/.test(name))
49
+ .map(([name, value]) => `${name}="${escape(value)}"`)
50
+ .join(' ')}/>`)
51
+ .join('');
52
+ // The 24-unit artwork fills the middle half of the square.
53
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 48 48"><rect width="48" height="48" fill="${escape(color)}"/><g transform="translate(12 12)" fill="none" stroke="#fff" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">${shapes}</g></svg>`;
54
+ }
55
+ /** The same as a 512×512 PNG. Browser only. */
56
+ export async function iconPng(color, icon) {
57
+ const url = URL.createObjectURL(new Blob([iconSvg(color, icon)], { type: 'image/svg+xml' }));
58
+ try {
59
+ const image = new Image();
60
+ image.src = url;
61
+ await image.decode();
62
+ const canvas = document.createElement('canvas');
63
+ canvas.width = canvas.height = 512;
64
+ canvas.getContext('2d').drawImage(image, 0, 0, 512, 512);
65
+ const blob = await new Promise((resolve) => canvas.toBlob(resolve, 'image/png'));
66
+ if (!blob)
67
+ throw new Error('Could not make the icon.');
68
+ return blob;
69
+ }
70
+ finally {
71
+ URL.revokeObjectURL(url);
72
+ }
73
+ }
package/dist/index.d.ts CHANGED
@@ -48,6 +48,8 @@ export * from './streamplace.js';
48
48
  export { default as InsetImage } from './components/InsetImage.svelte';
49
49
  export { default as Badge } from './components/Badge.svelte';
50
50
  export { default as Modal } from './components/Modal.svelte';
51
+ export { default as IconMaker } from './components/IconMaker.svelte';
52
+ export { iconColors, iconSvg, iconPng } from './icon-maker/index.js';
51
53
  export { default as LegalDocument } from './components/legal/LegalDocument.svelte';
52
54
  export type { LegalDocumentProps } from './components/legal/LegalDocument.svelte';
53
55
  export { default as LegalFooter } from './components/legal/LegalFooter.svelte';
@@ -87,7 +89,7 @@ export { default as Popover } from './components/Popover.svelte';
87
89
  export { default as LinkCard } from './components/LinkCard.svelte';
88
90
  export { default as InlineEditor } from './components/InlineEditor.svelte';
89
91
  export { default as RichTextEditor } from './components/RichTextEditor.svelte';
90
- export type { RichTextEditorProps, RichTextEditorContent } from './components/RichTextEditor.svelte';
92
+ export type { RichTextEditorProps, RichTextEditorContent, RichTextEditorImages } from './components/RichTextEditor.svelte';
91
93
  export { default as PostComposer } from './components/composer/PostComposer.svelte';
92
94
  export type { PostComposerProps } from './components/composer/PostComposer.svelte';
93
95
  export { default as PostComposerDialog } from './components/composer/PostComposerDialog.svelte';
@@ -95,6 +97,7 @@ export { default as CharRing } from './components/composer/CharRing.svelte';
95
97
  export { blueskyGifSearch, blueskyLinkPreview, defaultComposerLimits, defaultComposerLanguages, defaultContentWarnings } from './social/composer.js';
96
98
  export type { ComposerContent, ComposerPost, ComposerImage, ComposerVideo, ComposerGif, ComposerLink, ComposerReplyRule, ComposerLimits, ComposerFeatures, ComposerLabels, ComposerGifSearch, ComposerGifResult, ComposerLinkPreview, ComposerDrafts, ComposerDraftSummary, ComposerContentWarning } from './social/composer.js';
97
99
  export { default as NestedComments } from './components/NestedComments.svelte';
100
+ export { default as PostComments } from './components/PostComments.svelte';
98
101
  export { default as PostContent } from './components/PostContent.svelte';
99
102
  export { safeHttpUrl, safeLinkHref } from './urls.js';
100
103
  export { default as RichText } from './components/RichText.svelte';
@@ -105,8 +108,9 @@ export { default as LinkEmbed } from './components/LinkEmbed.svelte';
105
108
  export type { LinkEmbedComponentProps } from './components/LinkEmbed.svelte';
106
109
  export { defaultLinkEmbeds, postLinkEmbed, profileLinkEmbed, youtubeLinkEmbed, klipyLinkEmbed, playerLinkEmbed } from './embeds/defaults.js';
107
110
  export { resolveLinkEmbed } from './embeds/resolve.js';
111
+ export { linkEmbedUrls, loadLinkEmbedData, preloadLinkEmbeds, type LinkEmbedData } from './embeds/load.js';
108
112
  export { setLinkEmbeds } from './embeds/context.js';
109
- export type { LinkEmbed as LinkEmbedDefinition, LinkEmbedProps, LinkEmbedOptions } from './embeds/types.js';
113
+ export type { LinkEmbed as LinkEmbedDefinition, LinkEmbedProps, LinkEmbedOptions, LinkEmbedLoadOptions } from './embeds/types.js';
110
114
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
111
115
  export type { ExternalPostEmbed, ExternalEmbedProvider, ExternalEmbedPlayer } from './social/external-embeds.js';
112
116
  export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
@@ -117,4 +121,7 @@ export type { Facet, RichTextOptions, RichTextSegment } from './social/richtext.
117
121
  export type { Editor, JSONContent } from '@tiptap/core';
118
122
  export { launchConfetti } from './confetti.js';
119
123
  export { cn } from './utils.js';
120
- export { baseColors, accentColors } from './palettes.js';
124
+ export { baseColors, accentColors, baseColorRgb, accentColorRgb, isBaseColor, isAccentColor } from './palettes.js';
125
+ export type { BaseColor, AccentColor, Palette } from './palettes.js';
126
+ export { default as PalettePicker } from './components/PalettePicker.svelte';
127
+ export { default as PaletteApply } from './components/PaletteApply.svelte';
package/dist/index.js CHANGED
@@ -34,6 +34,8 @@ export * from './streamplace.js';
34
34
  export { default as InsetImage } from './components/InsetImage.svelte';
35
35
  export { default as Badge } from './components/Badge.svelte';
36
36
  export { default as Modal } from './components/Modal.svelte';
37
+ export { default as IconMaker } from './components/IconMaker.svelte';
38
+ export { iconColors, iconSvg, iconPng } from './icon-maker/index.js';
37
39
  export { default as LegalDocument } from './components/legal/LegalDocument.svelte';
38
40
  export { default as LegalFooter } from './components/legal/LegalFooter.svelte';
39
41
  export { createLegalDrafts, getLegalDraftIssues, getLegalDocumentIssues } from './components/legal/drafts.js';
@@ -63,6 +65,7 @@ export { default as PostComposerDialog } from './components/composer/PostCompose
63
65
  export { default as CharRing } from './components/composer/CharRing.svelte';
64
66
  export { blueskyGifSearch, blueskyLinkPreview, defaultComposerLimits, defaultComposerLanguages, defaultContentWarnings } from './social/composer.js';
65
67
  export { default as NestedComments } from './components/NestedComments.svelte';
68
+ export { default as PostComments } from './components/PostComments.svelte';
66
69
  export { default as PostContent } from './components/PostContent.svelte';
67
70
  export { safeHttpUrl, safeLinkHref } from './urls.js';
68
71
  export { default as RichText } from './components/RichText.svelte';
@@ -70,6 +73,7 @@ export { default as ExternalEmbed } from './components/ExternalEmbed.svelte';
70
73
  export { default as LinkEmbed } from './components/LinkEmbed.svelte';
71
74
  export { defaultLinkEmbeds, postLinkEmbed, profileLinkEmbed, youtubeLinkEmbed, klipyLinkEmbed, playerLinkEmbed } from './embeds/defaults.js';
72
75
  export { resolveLinkEmbed } from './embeds/resolve.js';
76
+ export { linkEmbedUrls, loadLinkEmbedData, preloadLinkEmbeds } from './embeds/load.js';
73
77
  export { setLinkEmbeds } from './embeds/context.js';
74
78
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
75
79
  export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
@@ -77,4 +81,6 @@ export { parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
77
81
  export { editorJsonToBlueskyPost, textToDoc, graphemeLength } from './social/richtext.js';
78
82
  export { launchConfetti } from './confetti.js';
79
83
  export { cn } from './utils.js';
80
- export { baseColors, accentColors } from './palettes.js';
84
+ export { baseColors, accentColors, baseColorRgb, accentColorRgb, isBaseColor, isAccentColor } from './palettes.js';
85
+ export { default as PalettePicker } from './components/PalettePicker.svelte';
86
+ export { default as PaletteApply } from './components/PaletteApply.svelte';
@@ -1,2 +1,22 @@
1
1
  export declare const baseColors: readonly ["gray", "zinc", "neutral", "stone", "slate", "mist", "mauve", "olive", "taupe"];
2
2
  export declare const accentColors: readonly ["red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose"];
3
+ export type BaseColor = (typeof baseColors)[number];
4
+ export type AccentColor = (typeof accentColors)[number];
5
+ export type Palette = {
6
+ accent: AccentColor;
7
+ base: BaseColor;
8
+ };
9
+ export declare const isBaseColor: (value: unknown) => value is BaseColor;
10
+ export declare const isAccentColor: (value: unknown) => value is AccentColor;
11
+ type Rgb = readonly [r: number, g: number, b: number];
12
+ /**
13
+ * The palettes as sRGB, for records and other places that cannot name a palette: the page and
14
+ * text colors of a base (its 50 and 950), and the 700 of an accent, which the kit uses for links
15
+ * on a light page and which white text is readable on.
16
+ */
17
+ export declare const baseColorRgb: Record<BaseColor, {
18
+ background: Rgb;
19
+ foreground: Rgb;
20
+ }>;
21
+ export declare const accentColorRgb: Record<AccentColor, Rgb>;
22
+ export {};
package/dist/palettes.js CHANGED
@@ -28,3 +28,40 @@ export const accentColors = [
28
28
  'pink',
29
29
  'rose'
30
30
  ];
31
+ export const isBaseColor = (value) => baseColors.includes(value);
32
+ export const isAccentColor = (value) => accentColors.includes(value);
33
+ /**
34
+ * The palettes as sRGB, for records and other places that cannot name a palette: the page and
35
+ * text colors of a base (its 50 and 950), and the 700 of an accent, which the kit uses for links
36
+ * on a light page and which white text is readable on.
37
+ */
38
+ export const baseColorRgb = {
39
+ gray: { background: [249, 250, 251], foreground: [3, 7, 18] },
40
+ zinc: { background: [250, 250, 250], foreground: [9, 9, 11] },
41
+ neutral: { background: [250, 250, 250], foreground: [10, 10, 10] },
42
+ stone: { background: [250, 250, 249], foreground: [12, 10, 9] },
43
+ slate: { background: [248, 250, 252], foreground: [2, 6, 24] },
44
+ mist: { background: [249, 251, 251], foreground: [9, 11, 12] },
45
+ mauve: { background: [250, 250, 250], foreground: [12, 9, 12] },
46
+ olive: { background: [251, 251, 249], foreground: [12, 12, 9] },
47
+ taupe: { background: [251, 250, 249], foreground: [12, 10, 9] }
48
+ };
49
+ export const accentColorRgb = {
50
+ red: [193, 0, 7],
51
+ orange: [202, 53, 0],
52
+ amber: [187, 77, 0],
53
+ yellow: [166, 95, 0],
54
+ lime: [73, 125, 0],
55
+ green: [0, 130, 54],
56
+ emerald: [0, 122, 85],
57
+ teal: [0, 120, 111],
58
+ cyan: [0, 117, 149],
59
+ sky: [0, 105, 168],
60
+ blue: [20, 71, 230],
61
+ indigo: [67, 45, 215],
62
+ violet: [112, 8, 231],
63
+ purple: [130, 0, 219],
64
+ fuchsia: [168, 0, 183],
65
+ pink: [198, 0, 92],
66
+ rose: [199, 0, 54]
67
+ };
@@ -0,0 +1,10 @@
1
+ import { type IconNode } from '@sketchyicons/svelte';
2
+ import type { RichTextCallout } from './document.js';
3
+ /** `==marked==` text, the same where it is written and where it is read. */
4
+ export declare const highlightClass = "rounded-sm bg-accent-200 px-0.5 text-inherit dark:bg-[color-mix(in_srgb,var(--accent-500)_35%,transparent)]";
5
+ export declare const CALLOUT_LABELS: Record<RichTextCallout, string>;
6
+ export declare const CALLOUT_ICONS: Record<RichTextCallout, IconNode>;
7
+ /** The box of a callout. */
8
+ export declare function calloutClass(kind: RichTextCallout): string;
9
+ /** The line naming the kind of callout. */
10
+ export declare function calloutLabelClass(kind: RichTextCallout): string;
@@ -0,0 +1,28 @@
1
+ import { Info, Lightbulb, MessageSquareWarning, OctagonAlert, TriangleAlert } from '@sketchyicons/svelte';
2
+ /** `==marked==` text, the same where it is written and where it is read. */
3
+ export const highlightClass = 'rounded-sm bg-accent-200 px-0.5 text-inherit dark:bg-[color-mix(in_srgb,var(--accent-500)_35%,transparent)]';
4
+ export const CALLOUT_LABELS = {
5
+ note: 'Note',
6
+ tip: 'Tip',
7
+ important: 'Important',
8
+ warning: 'Warning',
9
+ caution: 'Caution'
10
+ };
11
+ export const CALLOUT_ICONS = {
12
+ note: Info,
13
+ tip: Lightbulb,
14
+ important: MessageSquareWarning,
15
+ warning: TriangleAlert,
16
+ caution: OctagonAlert
17
+ };
18
+ const alarming = (kind) => kind === 'warning' || kind === 'caution';
19
+ /** The box of a callout. */
20
+ export function calloutClass(kind) {
21
+ return `space-y-3 rounded-ui px-4 py-3 ${alarming(kind)
22
+ ? 'bg-[color-mix(in_srgb,var(--color-red-500)_9%,transparent)]'
23
+ : 'bg-[color-mix(in_srgb,var(--accent-500)_9%,transparent)]'}`;
24
+ }
25
+ /** The line naming the kind of callout. */
26
+ export function calloutLabelClass(kind) {
27
+ return `flex items-center gap-1.5 font-sans text-sm leading-normal font-semibold ${alarming(kind) ? 'text-red-700 dark:text-red-400' : 'text-accent-700 dark:text-accent-300'}`;
28
+ }
@@ -18,21 +18,55 @@ export type RichTextBlock = {
18
18
  type: 'heading';
19
19
  depth: 1 | 2 | 3 | 4 | 5 | 6;
20
20
  children: RichTextInline[];
21
- } | {
21
+ }
22
+ /** Article Markdown only: with `callout`, a quote that began with `[!NOTE]` or the like. */
23
+ | {
22
24
  type: 'blockquote';
23
25
  children: RichTextBlock[];
26
+ callout?: RichTextCallout;
24
27
  } | {
25
28
  type: 'list';
26
29
  ordered: boolean;
27
30
  start?: number;
28
31
  items: RichTextBlock[][];
32
+ /** Article Markdown only: per item, whether a task is done; `null` for an ordinary item. */
33
+ checked?: (boolean | null)[];
29
34
  } | {
30
35
  type: 'codeBlock';
31
36
  value: string;
32
37
  lang?: string;
33
38
  } | {
34
39
  type: 'thematicBreak';
40
+ }
41
+ /** Article Markdown only. `url` is HTTP(S) or a destination the app allowed. */
42
+ | {
43
+ type: 'image';
44
+ url: string;
45
+ alt?: string;
46
+ title?: string;
47
+ }
48
+ /** Article Markdown only. The first row is the header; every row has a cell per column. */
49
+ | {
50
+ type: 'table';
51
+ align: RichTextAlign[];
52
+ rows: RichTextInline[][][];
53
+ }
54
+ /** Article Markdown only. TeX source of a displayed formula. */
55
+ | {
56
+ type: 'math';
57
+ value: string;
58
+ }
59
+ /** Article Markdown only. Shown at the end of the text, not where it was written. */
60
+ | {
61
+ type: 'footnoteDefinition';
62
+ id: string;
63
+ children: RichTextBlock[];
35
64
  };
65
+ export type RichTextAlign = 'left' | 'center' | 'right' | null;
66
+ /** The kinds of callout, as GitHub has them: `> [!NOTE]` and so on. */
67
+ export declare const CALLOUTS: readonly ["note", "tip", "important", "warning", "caution"];
68
+ export type RichTextCallout = (typeof CALLOUTS)[number];
69
+ export declare function isCallout(value: unknown): value is RichTextCallout;
36
70
  export type RichTextInline = {
37
71
  type: 'text';
38
72
  value: string;
@@ -41,9 +75,24 @@ export type RichTextInline = {
41
75
  } | {
42
76
  type: 'strong' | 'emphasis' | 'delete';
43
77
  children: RichTextInline[];
78
+ }
79
+ /** Article Markdown only: `==marked==` text. */
80
+ | {
81
+ type: 'highlight';
82
+ children: RichTextInline[];
44
83
  } | {
45
84
  type: 'code';
46
85
  value: string;
86
+ }
87
+ /** Article Markdown only. TeX source of a formula in the line. */
88
+ | {
89
+ type: 'math';
90
+ value: string;
91
+ }
92
+ /** Article Markdown only. Refers to the `footnoteDefinition` with the same id. */
93
+ | {
94
+ type: 'footnoteReference';
95
+ id: string;
47
96
  } | {
48
97
  type: 'link';
49
98
  url: string;
@@ -85,11 +134,24 @@ export declare function lineBreaks(children: unknown): Record<string, unknown>[]
85
134
  * an embed. Labeled links and links inside a sentence stay ordinary links.
86
135
  */
87
136
  export declare function paragraphParts(children: unknown, isEmbed?: (url: string) => boolean): ParagraphPart[];
137
+ /** The parts of a plain-text document: its lines, with those shown as embeds on their own. */
138
+ export declare function plainTextParts(document: {
139
+ children?: unknown;
140
+ } | null | undefined, isEmbed?: (url: string) => boolean): ParagraphPart[];
88
141
  /** Blank lines next to an embed are already expressed by the space around it. */
89
142
  export declare function trimBreaks(children: Record<string, unknown>[]): Record<string, unknown>[];
90
143
  /** Documents from the parser nest far less; deeper (tampered) nodes are cut off. */
91
144
  export declare const MAX_RENDER_DEPTH = 32;
92
145
  /** Text content of any node, including unknown ones. */
93
146
  export declare function inlineText(node: Record<string, unknown>, depth?: number): string;
147
+ export type Footnotes = {
148
+ /** Ids in the order their notes are shown: by first reference, then the unreferenced. */
149
+ order: string[];
150
+ definitions: Map<string, Record<string, unknown>>;
151
+ /** The first reference to each note, where its way back leads. */
152
+ references: Map<string, Record<string, unknown>>;
153
+ };
154
+ /** The footnotes of a document, for renderers: definitions are shown together at the end. */
155
+ export declare function collectFootnotes(content: unknown): Footnotes;
94
156
  /** Readable text without Markdown syntax, for meta descriptions, previews and search. */
95
157
  export declare function richTextToPlainText(content: RichTextDocument): string;
@@ -3,6 +3,11 @@ import { socialHashtagUrl, socialProfileUrl } from '../social/urls.js';
3
3
  import { safeHttpUrl as safeWebUrl } from '../urls.js';
4
4
  // Backwards-compatible export for existing richtext and social consumers.
5
5
  export { safeWebUrl };
6
+ /** The kinds of callout, as GitHub has them: `> [!NOTE]` and so on. */
7
+ export const CALLOUTS = ['note', 'tip', 'important', 'warning', 'caution'];
8
+ export function isCallout(value) {
9
+ return CALLOUTS.includes(value);
10
+ }
6
11
  /** Only app-relative paths or HTTP(S), including for app-owned mention callbacks. */
7
12
  export function mentionHref(actor, options) {
8
13
  if (typeof actor !== 'string' || !isActorIdentifier(actor))
@@ -111,6 +116,10 @@ export function paragraphParts(children, isEmbed) {
111
116
  }
112
117
  return parts;
113
118
  }
119
+ /** The parts of a plain-text document: its lines, with those shown as embeds on their own. */
120
+ export function plainTextParts(document, isEmbed) {
121
+ return nodes(document?.children).flatMap((block) => paragraphParts(lineBreaks(block.children), isEmbed));
122
+ }
114
123
  /** Blank lines next to an embed are already expressed by the space around it. */
115
124
  export function trimBreaks(children) {
116
125
  let start = 0;
@@ -153,7 +162,20 @@ function blockText(node, depth) {
153
162
  case 'thematicBreak':
154
163
  return '';
155
164
  case 'codeBlock':
165
+ case 'math':
156
166
  return string(node.value);
167
+ case 'footnoteDefinition':
168
+ return blocksText(node.children, '\n\n', depth + 1);
169
+ case 'image':
170
+ return string(node.alt);
171
+ case 'table':
172
+ return (Array.isArray(node.rows) ? node.rows : [])
173
+ .map((row) => (Array.isArray(row) ? row : [])
174
+ .map((cell) => nodes(cell)
175
+ .map((child) => inlineText(child, depth + 1))
176
+ .join(''))
177
+ .join('\t'))
178
+ .join('\n');
157
179
  default:
158
180
  return inlineText(node, depth);
159
181
  }
@@ -164,6 +186,38 @@ function blocksText(value, separator = '\n\n', depth = 0) {
164
186
  .filter(Boolean)
165
187
  .join(separator);
166
188
  }
189
+ /** The footnotes of a document, for renderers: definitions are shown together at the end. */
190
+ export function collectFootnotes(content) {
191
+ const definitions = new Map();
192
+ const referenced = [];
193
+ const references = new Map();
194
+ const walk = (value, depth) => {
195
+ if (depth > MAX_RENDER_DEPTH + 4 || value === null || typeof value !== 'object')
196
+ return;
197
+ if (Array.isArray(value))
198
+ return value.forEach((item) => walk(item, depth + 1));
199
+ const node = value;
200
+ const id = string(node.id);
201
+ if (node.type === 'footnoteDefinition' && id && !definitions.has(id))
202
+ definitions.set(id, node);
203
+ if (node.type === 'footnoteReference' && id && !referenced.includes(id)) {
204
+ referenced.push(id);
205
+ references.set(id, node);
206
+ }
207
+ walk(node.children, depth + 1);
208
+ walk(node.items, depth + 1);
209
+ walk(node.rows, depth + 1);
210
+ };
211
+ walk(content?.children, 0);
212
+ const order = referenced.filter((id) => definitions.has(id));
213
+ for (const id of definitions.keys())
214
+ if (!order.includes(id))
215
+ order.push(id);
216
+ for (const id of references.keys())
217
+ if (!definitions.has(id))
218
+ references.delete(id);
219
+ return { order, definitions, references };
220
+ }
167
221
  /** Readable text without Markdown syntax, for meta descriptions, previews and search. */
168
222
  export function richTextToPlainText(content) {
169
223
  return blocksText(content?.children);
@@ -1,10 +1,25 @@
1
1
  import { type RichTextDocument } from './document.js';
2
2
  import { type PlainTextOptions } from './plain.js';
3
+ export type MarkdownOptions = PlainTextOptions & {
4
+ /**
5
+ * Standard Markdown for long-form writing: a single newline wraps instead of breaking the
6
+ * line, images and tables are kept, and far longer text is parsed.
7
+ */
8
+ article?: boolean;
9
+ /**
10
+ * With `article`, image destinations to keep besides HTTP(S), e.g. an app's own scheme for
11
+ * uploaded files. Such a destination is kept as written; rendering it is up to the app.
12
+ */
13
+ allowImage?: (url: string) => boolean;
14
+ };
3
15
  /** Whether Markdown parsing could be slow; checked in linear time. */
4
- export declare function exceedsMarkdownLimits(text: string): boolean;
16
+ export declare function exceedsMarkdownLimits(text: string, article?: boolean): boolean;
17
+ export declare const FOOTNOTE_ID: RegExp;
5
18
  /**
6
19
  * CommonMark plus ~~strikethrough~~, with facets applied to the parsed text. Raw HTML is shown
7
- * literally, images become links and only HTTP(S) destinations are kept. Text that exceeds
8
- * the parser's limits is returned as a plain-text document.
20
+ * literally, images become links and only HTTP(S) destinations are kept. With `article`,
21
+ * images, tables, footnotes, task lists, `$math$`, `==highlights==` and callouts (`> [!NOTE]`)
22
+ * are kept and newlines inside a paragraph wrap. Text that exceeds the parser's limits is
23
+ * returned as a plain-text document.
9
24
  */
10
- export declare function parseMarkdown(text: string, options?: PlainTextOptions): RichTextDocument;
25
+ export declare function parseMarkdown(text: string, options?: MarkdownOptions): RichTextDocument;