@atmo-dev/kit 0.13.2 → 0.15.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 (102) hide show
  1. package/dist/components/ExternalEmbed.svelte +30 -29
  2. package/dist/components/ExternalEmbed.svelte.d.ts +8 -0
  3. package/dist/components/InlineEditor.svelte +15 -95
  4. package/dist/components/InlineEditor.svelte.d.ts +1 -1
  5. package/dist/components/LinkCard.svelte +54 -25
  6. package/dist/components/LinkCard.svelte.d.ts +2 -0
  7. package/dist/components/LinkEmbed.svelte +75 -0
  8. package/dist/components/LinkEmbed.svelte.d.ts +13 -0
  9. package/dist/components/NestedComments.svelte +205 -52
  10. package/dist/components/NestedComments.svelte.d.ts +49 -6
  11. package/dist/components/PostContent.svelte +26 -25
  12. package/dist/components/PostContent.svelte.d.ts +3 -0
  13. package/dist/components/PostImages.svelte +85 -0
  14. package/dist/components/PostImages.svelte.d.ts +9 -0
  15. package/dist/components/PostVideo.svelte +16 -2
  16. package/dist/components/PostVideo.svelte.d.ts +4 -0
  17. package/dist/components/RichText.svelte +47 -5
  18. package/dist/components/RichText.svelte.d.ts +5 -2
  19. package/dist/components/RichTextEditor.svelte +271 -0
  20. package/dist/components/RichTextEditor.svelte.d.ts +44 -0
  21. package/dist/components/composer/AltText.svelte +63 -0
  22. package/dist/components/composer/AltText.svelte.d.ts +11 -0
  23. package/dist/components/composer/CharRing.svelte +39 -0
  24. package/dist/components/composer/CharRing.svelte.d.ts +7 -0
  25. package/dist/components/composer/ComposerPost.svelte +321 -0
  26. package/dist/components/composer/ComposerPost.svelte.d.ts +29 -0
  27. package/dist/components/composer/Drafts.svelte +82 -0
  28. package/dist/components/composer/Drafts.svelte.d.ts +9 -0
  29. package/dist/components/composer/EmojiPicker.svelte +55 -0
  30. package/dist/components/composer/EmojiPicker.svelte.d.ts +7 -0
  31. package/dist/components/composer/GifPicker.svelte +118 -0
  32. package/dist/components/composer/GifPicker.svelte.d.ts +11 -0
  33. package/dist/components/composer/PostComposer.svelte +599 -0
  34. package/dist/components/composer/PostComposer.svelte.d.ts +71 -0
  35. package/dist/components/composer/PostComposerDialog.svelte +75 -0
  36. package/dist/components/composer/PostComposerDialog.svelte.d.ts +10 -0
  37. package/dist/components/composer/ReplySettings.svelte +150 -0
  38. package/dist/components/composer/ReplySettings.svelte.d.ts +18 -0
  39. package/dist/components/login/search.d.ts +29 -1
  40. package/dist/components/login/search.js +31 -3
  41. package/dist/editor/EditorLinkEmbed.svelte +35 -0
  42. package/dist/editor/EditorLinkEmbed.svelte.d.ts +12 -0
  43. package/dist/editor/detect-plugin.d.ts +5 -0
  44. package/dist/editor/detect-plugin.js +51 -0
  45. package/dist/editor/document.d.ts +17 -0
  46. package/dist/editor/document.js +269 -0
  47. package/dist/editor/link-embed-node.d.ts +17 -0
  48. package/dist/editor/link-embed-node.js +96 -0
  49. package/dist/editor/markdown-extensions.d.ts +6 -0
  50. package/dist/editor/markdown-extensions.js +42 -0
  51. package/dist/editor/markdown.d.ts +3 -0
  52. package/dist/editor/markdown.js +4 -0
  53. package/dist/embeds/PlayerLinkEmbed.svelte +9 -0
  54. package/dist/embeds/PlayerLinkEmbed.svelte.d.ts +7 -0
  55. package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte +7 -7
  56. package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte.d.ts +1 -1
  57. package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte +7 -7
  58. package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte.d.ts +1 -1
  59. package/dist/embeds/context.d.ts +10 -0
  60. package/dist/embeds/context.js +20 -0
  61. package/dist/embeds/defaults.d.ts +27 -0
  62. package/dist/embeds/defaults.js +38 -0
  63. package/dist/embeds/resolve.d.ts +9 -0
  64. package/dist/embeds/resolve.js +27 -0
  65. package/dist/embeds/types.d.ts +39 -0
  66. package/dist/embeds/types.js +1 -0
  67. package/dist/events/EventComments.svelte +5 -5
  68. package/dist/events/EventEditor.svelte +7 -6
  69. package/dist/events/EventView.svelte +21 -38
  70. package/dist/events/PostToBlueskyModal.svelte +12 -4
  71. package/dist/events/event-link-embed.d.ts +22 -0
  72. package/dist/events/event-link-embed.js +15 -0
  73. package/dist/events/event-view/EventLinkEmbed.svelte +12 -30
  74. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -12
  75. package/dist/events.d.ts +2 -0
  76. package/dist/events.js +1 -0
  77. package/dist/index.d.ts +16 -2
  78. package/dist/index.js +10 -2
  79. package/dist/richtext/detect.js +1 -1
  80. package/dist/richtext/document.d.ts +10 -0
  81. package/dist/richtext/document.js +44 -4
  82. package/dist/richtext/markdown.js +5 -1
  83. package/dist/richtext/serialize.d.ts +11 -0
  84. package/dist/richtext/serialize.js +462 -0
  85. package/dist/richtext.d.ts +1 -0
  86. package/dist/richtext.js +1 -0
  87. package/dist/social/MentionOptions.svelte +30 -0
  88. package/dist/social/MentionOptions.svelte.d.ts +12 -0
  89. package/dist/social/composer.d.ts +143 -0
  90. package/dist/social/composer.js +141 -0
  91. package/dist/social/{mention-suggestions.d.ts → mention-suggestions.svelte.d.ts} +1 -1
  92. package/dist/social/{mention-suggestions.js → mention-suggestions.svelte.js} +36 -46
  93. package/dist/social/posts.d.ts +10 -0
  94. package/dist/social/posts.js +5 -1
  95. package/dist/social/richtext.js +2 -0
  96. package/dist/social.d.ts +2 -0
  97. package/dist/social.js +1 -0
  98. package/dist/styles.d.ts +5 -0
  99. package/dist/styles.js +5 -0
  100. package/package.json +4 -1
  101. package/dist/components/PostComposer.svelte +0 -41
  102. package/dist/components/PostComposer.svelte.d.ts +0 -16
@@ -10,14 +10,28 @@
10
10
  import { focus } from '../styles.js';
11
11
  import Icon from './Icon.svelte';
12
12
  import LinkCard from './LinkCard.svelte';
13
+ import LinkEmbed from './LinkEmbed.svelte';
14
+ import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
15
+ import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
16
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
13
17
 
14
18
  let {
15
19
  embed,
16
- providers
20
+ providers,
21
+ embeds = false,
22
+ socialClient
17
23
  }: {
18
24
  embed: ExternalPostEmbed;
19
25
  providers?: readonly ExternalEmbedProvider[];
26
+ /**
27
+ * Show links that are not media as link embeds: `true` for the app's embeds (see
28
+ * `setLinkEmbeds`), or a list. Off by default, so links stay cards.
29
+ */
30
+ embeds?: boolean | readonly LinkEmbedDefinition[];
31
+ socialClient?: PreferredSocialClient | null;
20
32
  } = $props();
33
+ const context = linkEmbedOptions();
34
+ let linkEmbeds = $derived(selectLinkEmbeds(embeds, context()));
21
35
  let match = $derived(resolveExternalEmbed(embed, providers));
22
36
  // Consent belongs to this resolved player, not to its position in the feed.
23
37
  // A changed URL/provider/source never inherits an earlier click, even for one render.
@@ -38,8 +52,7 @@
38
52
  match !== null && (activated === match || (autoplay && !reducedMotion && paused !== match))
39
53
  );
40
54
  let label = $derived(embed.title || `${match?.provider.label ?? 'External'} media`);
41
- let previewButton = $state<HTMLButtonElement | null>(null);
42
- let stopButton = $state<HTMLButtonElement | null>(null);
55
+ let frame = $state<HTMLIFrameElement | null>(null);
43
56
  let animationButton = $state<HTMLButtonElement | null>(null);
44
57
  let video = $state<HTMLVideoElement | null>(null);
45
58
  $effect(() => {
@@ -51,13 +64,14 @@
51
64
  paused = null;
52
65
  activated = match;
53
66
  await tick();
54
- (autoplay ? animationButton : stopButton)?.focus({ preventScroll: true });
67
+ // The play button is gone; keyboard users continue in the player.
68
+ (autoplay ? animationButton : frame)?.focus({ preventScroll: true });
55
69
  }
56
70
  async function stop() {
57
71
  paused = match;
58
72
  activated = null;
59
73
  await tick();
60
- (autoplay ? animationButton : previewButton)?.focus({ preventScroll: true });
74
+ animationButton?.focus({ preventScroll: true });
61
75
  }
62
76
  </script>
63
77
 
@@ -68,6 +82,7 @@
68
82
  {#if active || (autoplay && match.player.type === 'video' && paused === match)}
69
83
  {#if match.player.type === 'iframe'}
70
84
  <iframe
85
+ bind:this={frame}
71
86
  src={safeWebUrl(match.player.src)}
72
87
  title={label}
73
88
  allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
@@ -119,11 +134,10 @@
119
134
  </div>
120
135
  {:else}
121
136
  <button
122
- bind:this={previewButton}
123
137
  type="button"
124
138
  aria-label={`Play ${label} on ${match.provider.label}`}
125
139
  onclick={play}
126
- class={`relative flex max-h-[32rem] w-full items-center justify-center overflow-hidden bg-base-50 text-base-950 dark:bg-base-900 dark:text-base-50 ${focus}`}
140
+ class={`group/play relative flex max-h-[32rem] w-full cursor-pointer items-center justify-center overflow-hidden bg-black ${focus}`}
127
141
  style:aspect-ratio={match.player.aspectRatio ?? 16 / 9}
128
142
  >
129
143
  {#if safeWebUrl(embed.image)}<img
@@ -133,9 +147,9 @@
133
147
  class="absolute inset-0 size-full object-cover"
134
148
  />{/if}
135
149
  <span
136
- class="relative inline-flex items-center gap-2 rounded-full border border-base-300 bg-base-50 px-4 py-2 text-sm font-medium dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-900"
150
+ class="relative grid size-14 place-items-center rounded-full bg-black/60 text-white transition-transform duration-150 group-hover/play:scale-105 motion-reduce:transition-none"
137
151
  >
138
- <Icon img={Play} size={18} />Play · {match.provider.label}
152
+ <Icon img={Play} size={24} />
139
153
  </span>
140
154
  </button>
141
155
  {/if}
@@ -150,28 +164,15 @@
150
164
  class={`absolute right-2 bottom-2 inline-flex size-8 items-center justify-center rounded-full bg-black/60 text-white transition-colors hover:bg-black/80 ${focus}`}
151
165
  ><Icon img={active ? Pause : Play} size={16} /></button
152
166
  >
153
- {:else}
154
- <div class="flex items-center justify-between gap-3 p-3 text-xs">
155
- <a
156
- href={safeWebUrl(embed.uri)}
157
- target="_blank"
158
- rel="noopener noreferrer"
159
- class={`min-w-0 truncate rounded-ui text-base-600 hover:text-accent-700 dark:text-base-400 dark:hover:text-accent-300 ${focus}`}
160
- >{embed.title || `Open on ${match.provider.label}`}</a
161
- >
162
- {#if active}<button
163
- type="button"
164
- bind:this={stopButton}
165
- onclick={stop}
166
- aria-label={`Stop ${match.provider.label} embed`}
167
- class={`shrink-0 rounded-ui text-base-600 hover:text-accent-700 dark:text-base-400 dark:hover:text-accent-300 ${focus}`}
168
- >Stop</button
169
- >{/if}
170
- </div>{/if}
167
+ {/if}
171
168
  </div>
172
- {:else}
169
+ {:else if linkEmbeds.length}
170
+ <LinkEmbed url={embed.uri} embeds={linkEmbeds} fallback={card} {socialClient} />
171
+ {:else}{@render card()}{/if}
172
+
173
+ {#snippet card()}
173
174
  <LinkCard
174
175
  href={embed.uri}
175
176
  meta={{ title: embed.title, description: embed.description, image: embed.image }}
176
177
  />
177
- {/if}
178
+ {/snippet}
@@ -1,7 +1,15 @@
1
1
  import { type ExternalEmbedProvider, type ExternalPostEmbed } from '../social/external-embeds.js';
2
+ import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
3
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
2
4
  type $$ComponentProps = {
3
5
  embed: ExternalPostEmbed;
4
6
  providers?: readonly ExternalEmbedProvider[];
7
+ /**
8
+ * Show links that are not media as link embeds: `true` for the app's embeds (see
9
+ * `setLinkEmbeds`), or a list. Off by default, so links stay cards.
10
+ */
11
+ embeds?: boolean | readonly LinkEmbedDefinition[];
12
+ socialClient?: PreferredSocialClient | null;
5
13
  };
6
14
  declare const ExternalEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
7
15
  type ExternalEmbed = ReturnType<typeof ExternalEmbed>;
@@ -1,17 +1,9 @@
1
1
  <script lang="ts">
2
- import { onMount, untrack } from 'svelte';
3
- import { Editor, type JSONContent } from '@tiptap/core';
4
- import Document from '@tiptap/extension-document';
5
- import Paragraph from '@tiptap/extension-paragraph';
6
- import Text from '@tiptap/extension-text';
7
- import HardBreak from '@tiptap/extension-hard-break';
8
- import History from '@tiptap/extension-history';
9
- import Placeholder from '@tiptap/extension-placeholder';
10
- import Mention from '@tiptap/extension-mention';
2
+ import type { Editor, JSONContent } from '@tiptap/core';
11
3
  import type { ActorSearch } from './login/types.js';
12
- import { mentionSuggestions } from '../social/mention-suggestions.js';
13
- import { editorJsonToBlueskyPost, textToDoc } from '../social/richtext.js';
14
- import { cn } from '../utils.js';
4
+ import RichTextEditor from './RichTextEditor.svelte';
5
+
6
+ // The plain-text editor for titles and posts; `RichTextEditor` adds Markdown and embeds.
15
7
  let {
16
8
  value = $bindable(''),
17
9
  editor = $bindable<Editor | null>(null),
@@ -33,88 +25,16 @@
33
25
  onupdate?: (content: { text: string; json: JSONContent }) => void;
34
26
  class?: string;
35
27
  } = $props();
36
- const id = $props.id();
37
- let host: HTMLDivElement;
38
- let element: HTMLDivElement;
39
- onMount(() => {
40
- const instance = new Editor({
41
- element,
42
- extensions: [
43
- Document,
44
- Paragraph,
45
- Text,
46
- HardBreak,
47
- History,
48
- Placeholder.configure({ placeholder }),
49
- ...(searchActors
50
- ? [
51
- Mention.configure({
52
- HTMLAttributes: { class: 'text-accent-700 dark:text-accent-300' },
53
- suggestion: mentionSuggestions(searchActors, () => host)
54
- })
55
- ]
56
- : [])
57
- ],
58
- content: textToDoc(untrack(() => value)),
59
- editable: !disabled,
60
- editorProps: {
61
- attributes: {
62
- id,
63
- role: searchActors ? 'combobox' : 'textbox',
64
- 'aria-label': label,
65
- ...(searchActors
66
- ? { 'aria-autocomplete': 'list', 'aria-expanded': 'false', 'aria-haspopup': 'listbox' }
67
- : { 'aria-multiline': String(!singleLine) }),
68
- class:
69
- 'min-h-[1.5em] outline-none whitespace-pre-wrap break-words [&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)] [&_p.is-editor-empty:first-child]:before:text-base-600 dark:[&_p.is-editor-empty:first-child]:before:text-base-400 [&_p.is-editor-empty:first-child]:before:float-left [&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:h-0'
70
- },
71
- handleKeyDown: (view, event) =>
72
- singleLine &&
73
- event.key === 'Enter' &&
74
- !event.isComposing &&
75
- !view.dom.getAttribute('aria-activedescendant'),
76
- transformPastedText: (text) => (singleLine ? text.replace(/[\r\n]+/g, ' ') : text),
77
- // Accept plain text only, preserving the editor's deliberately small schema.
78
- handlePaste: (_view, event) => {
79
- const text = event.clipboardData?.getData('text/plain');
80
- if (text === undefined) return false;
81
- event.preventDefault();
82
- if (singleLine) {
83
- const cleaned = text.replace(/[\r\n]+/g, ' ');
84
- if (cleaned) instance.commands.insertContent({ type: 'text', text: cleaned });
85
- } else instance.commands.insertContent(textToDoc(text).content ?? []);
86
- return true;
87
- }
88
- },
89
- onUpdate: ({ editor: current }) => {
90
- const json = current.getJSON();
91
- value = editorJsonToBlueskyPost(json).text;
92
- onupdate?.({ text: value, json });
93
- }
94
- });
95
- editor = instance;
96
- return () => {
97
- instance.destroy();
98
- editor = null;
99
- };
100
- });
101
- $effect(() => {
102
- if (editor && editorJsonToBlueskyPost(editor.getJSON()).text !== value)
103
- editor.commands.setContent(textToDoc(value), { emitUpdate: false });
104
- });
105
- $effect(() => {
106
- editor?.setEditable(!disabled, false);
107
- editor?.view.dom.setAttribute('aria-disabled', String(disabled));
108
- });
109
28
  </script>
110
29
 
111
- <div
112
- bind:this={host}
113
- class={cn(
114
- 'relative min-w-0 rounded-sm focus-within:outline-2 focus-within:outline-offset-4 focus-within:outline-accent-700 dark:focus-within:outline-accent-300',
115
- className
116
- )}
117
- data-slot="inline-editor"
118
- >
119
- <div bind:this={element}></div>
120
- </div>
30
+ <RichTextEditor
31
+ bind:value
32
+ bind:editor
33
+ {label}
34
+ {placeholder}
35
+ {singleLine}
36
+ {disabled}
37
+ {searchActors}
38
+ {onupdate}
39
+ class={className}
40
+ />
@@ -1,4 +1,4 @@
1
- import { Editor, type JSONContent } from '@tiptap/core';
1
+ import type { Editor, JSONContent } from '@tiptap/core';
2
2
  import type { ActorSearch } from './login/types.js';
3
3
  type $$ComponentProps = {
4
4
  value?: string;
@@ -1,49 +1,78 @@
1
1
  <script lang="ts">
2
2
  import type { HTMLAnchorAttributes } from 'svelte/elements';
3
3
  import { cn } from '../utils.js';
4
- import { focus } from '../styles.js';
4
+ import { action, focus, line, muted, recess } from '../styles.js';
5
5
  import { safeHttpUrl as safeWebUrl } from '../urls.js';
6
6
  let {
7
7
  href,
8
+ localHref,
8
9
  meta,
9
10
  class: className,
10
11
  ...rest
11
12
  }: Omit<HTMLAnchorAttributes, 'href' | 'children'> & {
12
13
  href: string;
14
+ /** A path in this app to open in the same tab instead; `href` still names the site. */
15
+ localHref?: string;
13
16
  meta: { title?: string; description?: string; image?: string };
14
17
  } = $props();
18
+ let host = $derived.by(() => {
19
+ try {
20
+ return new URL(href).hostname.replace(/^www\./, '');
21
+ } catch {
22
+ return '';
23
+ }
24
+ });
25
+ // Only paths: anything else could leave the app or run script.
26
+ let local = $derived(localHref && /^\/(?!\/)/.test(localHref) ? localHref : undefined);
27
+ // A broken image leaves the text card, not an empty black frame.
28
+ let failed = $state<string>();
29
+ let image = $derived(meta.image === failed ? undefined : safeWebUrl(meta.image));
15
30
  </script>
16
31
 
17
32
  <a
33
+ target={local ? undefined : '_blank'}
34
+ rel={local ? undefined : 'noopener noreferrer'}
18
35
  {...rest}
19
- href={safeWebUrl(href)}
20
- target="_blank"
21
- rel="noopener noreferrer"
36
+ href={local ?? safeWebUrl(href)}
22
37
  class={cn(
23
- 'block overflow-hidden rounded-ui border border-base-300 bg-base-50 text-base-950 no-underline hover:border-base-300 dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-900 dark:text-base-50 dark:hover:border-base-800',
38
+ 'relative block overflow-hidden rounded-ui border text-base-950 no-underline dark:text-base-50',
39
+ line,
40
+ image ? 'aspect-[1.91/1] bg-black' : recess,
24
41
  focus,
25
42
  className
26
43
  )}
27
44
  >
28
- {#if meta.image && safeWebUrl(meta.image)}<div class="relative">
29
- <img
30
- src={meta.image}
31
- alt=""
32
- class="aspect-[1.91/1] w-full object-cover"
33
- loading="lazy"
34
- /><span
35
- class="pointer-events-none absolute inset-0 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--base-950)_8%,transparent),inset_0_2px_5px_color-mix(in_srgb,var(--base-950)_8%,transparent)] dark:shadow-[inset_0_0_0_1px_#0006,inset_0_2px_5px_#0006]"
36
- ></span>
37
- </div>{/if}
38
- <div class="p-3">
39
- <strong class="block text-sm font-medium">{meta.title || href}</strong>
40
- {#if meta.description}<p
41
- class="mt-1 line-clamp-2 text-xs leading-relaxed text-base-600 dark:text-base-400"
42
- >
43
- {meta.description}
44
- </p>{/if}
45
- <span class="mt-1 block truncate text-[.6875rem] text-base-600 dark:text-base-400"
46
- >{href.replace(/^https?:\/\//, '')}</span
45
+ {#if image}
46
+ <img
47
+ src={image}
48
+ alt=""
49
+ loading="lazy"
50
+ decoding="async"
51
+ class="absolute inset-0 size-full object-cover"
52
+ onerror={() => (failed = meta.image)}
53
+ />
54
+ <span
55
+ class="absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-linear-to-t from-black/85 via-black/55 to-transparent px-4 pt-14 pb-3.5"
47
56
  >
48
- </div>
57
+ {#if host}<span class="truncate text-xs font-semibold text-accent-300">{host}</span>{/if}
58
+ <span class="line-clamp-2 text-[15px] leading-snug font-semibold text-white"
59
+ >{meta.title || host || href}</span
60
+ >
61
+ </span>
62
+ {:else}
63
+ <span class="flex flex-col gap-1 px-4 py-3.5">
64
+ {#if host}<span class={cn('truncate text-xs font-semibold', action)}>{host}</span>{/if}
65
+ <span class="line-clamp-2 text-[15px] leading-snug font-semibold wrap-anywhere"
66
+ >{meta.title || href}</span
67
+ >
68
+ {#if meta.description}<span class={cn('line-clamp-2 text-sm leading-snug', muted)}
69
+ >{meta.description}</span
70
+ >{/if}
71
+ </span>
72
+ {/if}
73
+ <!-- Recessed edge, drawn above the image. -->
74
+ <span
75
+ class="pointer-events-none absolute inset-0 rounded-[inherit] shadow-[inset_0_2px_5px_rgb(0_0_0/0.22),inset_0_0_0_1px_rgb(0_0_0/0.08)] dark:shadow-[inset_0_2px_6px_rgb(0_0_0/0.5),inset_0_0_0_1px_rgb(0_0_0/0.25)]"
76
+ aria-hidden="true"
77
+ ></span>
49
78
  </a>
@@ -1,6 +1,8 @@
1
1
  import type { HTMLAnchorAttributes } from 'svelte/elements';
2
2
  type $$ComponentProps = Omit<HTMLAnchorAttributes, 'href' | 'children'> & {
3
3
  href: string;
4
+ /** A path in this app to open in the same tab instead; `href` still names the site. */
5
+ localHref?: string;
4
6
  meta: {
5
7
  title?: string;
6
8
  description?: string;
@@ -0,0 +1,75 @@
1
+ <script lang="ts" module>
2
+ import type { Component } from 'svelte';
3
+ // Not imported as `LinkEmbed`: the generated types would give that name to the import
4
+ // instead of this component, leaving consumers with a type-only export.
5
+ import type { LinkEmbed as Definition, LinkEmbedProps } from '../embeds/types.js';
6
+
7
+ // Loaded components are kept, so later embeds of the same kind render without a flash.
8
+ const loaded = new WeakMap<Definition, Component<LinkEmbedProps>>();
9
+ </script>
10
+
11
+ <script lang="ts">
12
+ import type { Snippet } from 'svelte';
13
+ import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
14
+ import { isClickToLoad, resolveLinkEmbed } from '../embeds/resolve.js';
15
+ import type { LinkEmbedOptions } from '../embeds/types.js';
16
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
17
+ import { safeHttpUrl } from '../urls.js';
18
+ import Button from './Button.svelte';
19
+
20
+ export type LinkEmbedComponentProps = LinkEmbedOptions & {
21
+ url: string;
22
+ /** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
23
+ fallback?: Snippet;
24
+ socialClient?: PreferredSocialClient | null;
25
+ };
26
+
27
+ let { url, embeds, clickToLoad, fallback, socialClient }: LinkEmbedComponentProps = $props();
28
+
29
+ const context = linkEmbedOptions();
30
+ let match = $derived(resolveLinkEmbed(url, embeds ?? selectLinkEmbeds(true, context())));
31
+ let gated = $derived(!!match && isClickToLoad(match.embed, clickToLoad ?? context().clickToLoad));
32
+ // Consent belongs to this link, not to its position on the page.
33
+ let accepted = $state<string>();
34
+ let component = $state.raw<Component<LinkEmbedProps>>();
35
+ $effect(() => {
36
+ const embed = match?.embed;
37
+ component = embed && loaded.get(embed);
38
+ if (!embed || component || (gated && accepted !== match?.url)) return;
39
+ let current = true;
40
+ embed
41
+ .load()
42
+ .then((module) => {
43
+ loaded.set(embed, module.default);
44
+ if (current) component = module.default;
45
+ })
46
+ .catch(() => {});
47
+ return () => {
48
+ current = false;
49
+ };
50
+ });
51
+ let href = $derived(safeHttpUrl(url));
52
+ </script>
53
+
54
+ {#snippet link()}
55
+ {#if fallback}{@render fallback()}
56
+ {:else if href}<p class="wrap-anywhere">
57
+ <a
58
+ {href}
59
+ target="_blank"
60
+ rel="noopener noreferrer nofollow ugc"
61
+ class="text-accent-700 underline decoration-accent-700/40 underline-offset-2 hover:decoration-accent-700 dark:text-accent-300 dark:decoration-accent-300/40 dark:hover:decoration-accent-300"
62
+ >{url}</a
63
+ >
64
+ </p>{/if}
65
+ {/snippet}
66
+
67
+ {#if match && gated && accepted !== match.url}
68
+ {@render link()}
69
+ <Button variant="secondary" size="sm" onclick={() => (accepted = match?.url)}
70
+ >Load {match.embed.label}</Button
71
+ >
72
+ {:else if match && component}
73
+ {@const Embed = component}
74
+ <Embed url={match.url} ref={match.ref} fallback={link} {socialClient} />
75
+ {:else}{@render link()}{/if}
@@ -0,0 +1,13 @@
1
+ import type { Component } from 'svelte';
2
+ import type { Snippet } from 'svelte';
3
+ import type { LinkEmbedOptions } from '../embeds/types.js';
4
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
5
+ export type LinkEmbedComponentProps = LinkEmbedOptions & {
6
+ url: string;
7
+ /** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
8
+ fallback?: Snippet;
9
+ socialClient?: PreferredSocialClient | null;
10
+ };
11
+ declare const LinkEmbed: Component<LinkEmbedComponentProps, {}, "">;
12
+ type LinkEmbed = ReturnType<typeof LinkEmbed>;
13
+ export default LinkEmbed;