social-embeds 0.8.1 → 0.9.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 (62) hide show
  1. package/README.md +37 -1
  2. package/dist/components/iframe-embed.js +15 -31
  3. package/dist/components/platforms.d.ts +32 -0
  4. package/dist/components/platforms.js +384 -0
  5. package/dist/components/social-embed.d.ts +31 -4
  6. package/dist/components/social-embed.js +48 -211
  7. package/dist/core/drivers.js +6 -6
  8. package/dist/core/layout.js +1 -45
  9. package/dist/core/message-height.js +24 -0
  10. package/dist/core/plans/bluesky.js +3 -1
  11. package/dist/core/plans/flickr.js +16 -6
  12. package/dist/core/plans/imgur.js +3 -1
  13. package/dist/core/plans/reddit.js +3 -1
  14. package/dist/core/plans/strava.js +3 -1
  15. package/dist/core/plans/telegram.js +3 -1
  16. package/dist/core/plans/truthsocial.js +5 -2
  17. package/dist/core/plans/tumblr.js +3 -1
  18. package/dist/core/plans/twitch.js +5 -2
  19. package/dist/core/resolve.js +15 -37
  20. package/dist/core/size-in-src.js +47 -0
  21. package/dist/element.js +1 -1
  22. package/dist/index.d.ts +21 -20
  23. package/dist/index.js +3 -2
  24. package/dist/loader/platform-scripts.js +23 -22
  25. package/dist/parser/html.d.ts +14 -0
  26. package/dist/parser/html.js +6 -1
  27. package/dist/parser/lookup.js +11 -5
  28. package/dist/parser/match-url.js +6 -2
  29. package/dist/parser/parse-embed.js +12 -8
  30. package/dist/parser/platform.d.ts +32 -0
  31. package/dist/parser/platforms/applemusic.js +2 -0
  32. package/dist/parser/platforms/applepodcasts.js +2 -0
  33. package/dist/parser/platforms/bluesky.js +6 -2
  34. package/dist/parser/platforms/dailymotion.js +2 -0
  35. package/dist/parser/platforms/facebook.js +8 -2
  36. package/dist/parser/platforms/flickr.js +4 -2
  37. package/dist/parser/platforms/giphy.js +2 -0
  38. package/dist/parser/platforms/imgur.js +4 -2
  39. package/dist/parser/platforms/instagram.js +4 -2
  40. package/dist/parser/platforms/kick.js +2 -0
  41. package/dist/parser/platforms/linkedin.js +2 -0
  42. package/dist/parser/platforms/pinterest.js +2 -0
  43. package/dist/parser/platforms/reddit.js +2 -0
  44. package/dist/parser/platforms/rumble.js +4 -0
  45. package/dist/parser/platforms/snapchat.js +2 -0
  46. package/dist/parser/platforms/soundcloud.js +2 -0
  47. package/dist/parser/platforms/spotify.js +2 -0
  48. package/dist/parser/platforms/strava.js +2 -0
  49. package/dist/parser/platforms/streamable.js +2 -0
  50. package/dist/parser/platforms/telegram.js +2 -0
  51. package/dist/parser/platforms/tenor.js +4 -2
  52. package/dist/parser/platforms/threads.js +4 -2
  53. package/dist/parser/platforms/tiktok.js +2 -0
  54. package/dist/parser/platforms/truthsocial.js +2 -0
  55. package/dist/parser/platforms/tumblr.js +2 -0
  56. package/dist/parser/platforms/twitch.js +2 -0
  57. package/dist/parser/platforms/vimeo.js +2 -0
  58. package/dist/parser/platforms/x.js +8 -2
  59. package/dist/parser/platforms/youtube.js +2 -0
  60. package/dist/parser/url.d.ts +6 -0
  61. package/dist/parser/verify.js +2 -46
  62. package/package.json +1 -1
package/README.md CHANGED
@@ -81,11 +81,47 @@ An unsupported URL never reaches `fallback`: nothing is rendered and `onError` n
81
81
 
82
82
  Before 0.7.0, iframe code that no platform claimed reached `fallback`. It now renders as a generic iframe. Non-iframe code, and iframes that are rejected, still reach `fallback`.
83
83
 
84
+ #### Only the platforms you use
85
+
86
+ `<SocialEmbed>` recognises every platform, so it adds about 28 KB gzipped to an app. `createSocialEmbed` makes one that recognises only the platforms you list, and a bundler leaves the others out:
87
+
88
+ ```tsx
89
+ // app/social-embed.tsx
90
+ 'use client';
91
+
92
+ import {
93
+ createSocialEmbed,
94
+ genericIframe,
95
+ instagram,
96
+ x,
97
+ youtube,
98
+ } from 'social-embeds';
99
+
100
+ export const SocialEmbed = createSocialEmbed([
101
+ youtube,
102
+ x,
103
+ instagram,
104
+ genericIframe,
105
+ ]);
106
+ ```
107
+
108
+ | Platforms | Gzipped |
109
+ | ------------------------------------------------- | ------- |
110
+ | `youtube` | 6 KB |
111
+ | `youtube`, `x` | 9 KB |
112
+ | `youtube`, `x`, `instagram`, `facebook`, `tiktok` | 12 KB |
113
+ | the same five and `genericIframe` | 14 KB |
114
+ | every platform (`<SocialEmbed>`) | 28 KB |
115
+
116
+ - **Names:** each platform is exported under its id, as in `embed.platform`: `x`, `instagram`, `threads`, `facebook`, `tiktok`, `youtube`, `telegram`, `snapchat`, `linkedin`, `reddit`, `pinterest`, `spotify`, `vimeo`, `twitch`, `dailymotion`, `bluesky`, `soundcloud`, `applemusic`, `applepodcasts`, `tumblr`, `kick`, `giphy`, `truthsocial`, `imgur`, `tenor`, `streamable`, `strava`, `flickr` and `rumble`. `genericIframe` adds [generic iframe embeds](#generic-iframe-embeds). The order of the list does not matter.
117
+ - **The same component:** it takes the same props and renders exactly what `<SocialEmbed>` renders for the platforms it knows. Embed code of another platform goes to `fallback`, or to `onError` as `social-embeds: unrecognised embed code`; a URL of another platform is reported as `social-embeds: not a supported post URL: …`. A frame that a named platform serves never renders as a generic iframe, even when that platform is not in the list.
118
+ - **A client module:** call `createSocialEmbed` once, at the top of a module with `'use client'`, and import the component from there. In the Next.js App Router a Server Component cannot call it, because it comes from a client module; it can render the component it returns.
119
+
84
120
  ### Platform components
85
121
 
86
122
  Each platform component takes a `url`, or an `embed` already parsed by [`social-embeds/parser`](#parser), plus the shared props and its own option props. Option props override options from the embed code.
87
123
 
88
- A platform component bundles only its own platform's parser: one component adds about 5 to 6 KB gzipped to an app (`FacebookEmbed` about 9 KB, `GenericIframeEmbed` about 5 KB), against about 28 KB for `<SocialEmbed>`, which recognises every platform. A URL of another platform is reported as `social-embeds: not a {Platform} post URL: …`.
124
+ A platform component bundles only its own platform's parser: one component adds about 3.5 to 5.5 KB gzipped to an app (`FacebookEmbed` about 7.4 KB), against about 28 KB for `<SocialEmbed>`, which recognises every platform. A URL of another platform is reported as `social-embeds: not a {Platform} post URL: …`, and an `embed` of another platform as `social-embeds: expected a {Platform} embed, got {id}`.
89
125
 
90
126
  ```tsx
91
127
  import {
@@ -1,5 +1,5 @@
1
1
  import { FRAME_TIMEOUT_MS } from "../core/timing.js";
2
- import { frameStyle, srcWithSize, watchWidth } from "../core/layout.js";
2
+ import { frameStyle } from "../core/layout.js";
3
3
  import { useNearViewport } from "./hooks.js";
4
4
  import { useCallback, useEffect, useRef, useState } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -25,7 +25,7 @@ const FILL = {
25
25
  function IframeEmbed(props) {
26
26
  return /* @__PURE__ */ jsx(Frame, { ...props }, props.src);
27
27
  }
28
- function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, borderRadius, sizeInSrc, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
28
+ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, clientSrc, borderRadius, sizeInSrc, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
29
29
  const frame = useRef(null);
30
30
  const iframe = useRef(null);
31
31
  const near = useNearViewport(frame, lazy);
@@ -52,34 +52,25 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
52
52
  }, []);
53
53
  useEffect(() => {
54
54
  if (!near || !messageHeight) return;
55
- const { origin, read } = messageHeight;
56
- const listen = (event) => {
57
- if (event.origin !== origin) return;
58
- if (!iframe.current || event.source !== iframe.current.contentWindow) return;
59
- let value;
60
- try {
61
- value = read(event.data);
62
- } catch {
63
- return;
64
- }
65
- if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
66
- setReportedHeight(Math.ceil(value));
55
+ return messageHeight.listen(() => iframe.current, (value) => {
56
+ setReportedHeight(value);
67
57
  report();
68
- };
69
- window.addEventListener("message", listen);
70
- return () => {
71
- window.removeEventListener("message", listen);
72
- };
58
+ });
73
59
  }, [
74
60
  near,
75
61
  messageHeight,
76
62
  report
77
63
  ]);
64
+ const sizing = useRef(sizeInSrc);
65
+ useEffect(() => {
66
+ sizing.current = sizeInSrc;
67
+ });
68
+ const sized = sizeInSrc !== void 0;
78
69
  useEffect(() => {
79
70
  const element = frame.current;
80
- if (!near || !sizeInSrc || !element) return;
81
- return watchWidth(element, setBoxWidth);
82
- }, [near, sizeInSrc]);
71
+ if (!near || !sized || !element) return;
72
+ return sizing.current?.watch(element, setBoxWidth);
73
+ }, [near, sized]);
83
74
  useEffect(() => {
84
75
  if (!near || !inView) return;
85
76
  const failure = messageHeight ? "did not report its height" : "did not load";
@@ -116,11 +107,7 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
116
107
  }, reportedHeight),
117
108
  ...style
118
109
  };
119
- const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
120
- src,
121
- ratio,
122
- size
123
- }, boxWidth);
110
+ const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : sizeInSrc.src(boxWidth);
124
111
  return /* @__PURE__ */ jsx("div", {
125
112
  ...rest,
126
113
  style: wrapper,
@@ -129,7 +116,7 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
129
116
  style: FILL,
130
117
  children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
131
118
  ref: iframe,
132
- src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
119
+ src: clientSrc ? clientSrc(frameSrc) : frameSrc,
133
120
  title,
134
121
  allow,
135
122
  allowFullScreen: allowFullscreen,
@@ -152,9 +139,6 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
152
139
  })
153
140
  });
154
141
  }
155
- function withHost(src, name) {
156
- return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
157
- }
158
142
  function Skeleton({ minHeight }) {
159
143
  return /* @__PURE__ */ jsx("div", {
160
144
  "aria-hidden": "true",
@@ -0,0 +1,32 @@
1
+ import { EmbedPlatform } from "./social-embed.js";
2
+ export declare const x: EmbedPlatform;
3
+ export declare const instagram: EmbedPlatform;
4
+ export declare const facebook: EmbedPlatform;
5
+ export declare const threads: EmbedPlatform;
6
+ export declare const tiktok: EmbedPlatform;
7
+ export declare const youtube: EmbedPlatform;
8
+ export declare const telegram: EmbedPlatform;
9
+ export declare const snapchat: EmbedPlatform;
10
+ export declare const linkedin: EmbedPlatform;
11
+ export declare const reddit: EmbedPlatform;
12
+ export declare const pinterest: EmbedPlatform;
13
+ export declare const spotify: EmbedPlatform;
14
+ export declare const vimeo: EmbedPlatform;
15
+ export declare const twitch: EmbedPlatform;
16
+ export declare const dailymotion: EmbedPlatform;
17
+ export declare const soundcloud: EmbedPlatform;
18
+ export declare const applemusic: EmbedPlatform;
19
+ export declare const applepodcasts: EmbedPlatform;
20
+ export declare const kick: EmbedPlatform;
21
+ export declare const giphy: EmbedPlatform;
22
+ export declare const tenor: EmbedPlatform;
23
+ export declare const streamable: EmbedPlatform;
24
+ export declare const rumble: EmbedPlatform;
25
+ export declare const truthsocial: EmbedPlatform;
26
+ export declare const imgur: EmbedPlatform;
27
+ export declare const strava: EmbedPlatform;
28
+ export declare const flickr: EmbedPlatform;
29
+ export declare const bluesky: EmbedPlatform;
30
+ export declare const tumblr: EmbedPlatform;
31
+ /** Iframe embed code that no listed platform recognises, checked as `GenericIframeEmbed` does. */
32
+ export declare const genericIframe: EmbedPlatform;
@@ -0,0 +1,384 @@
1
+ import { parseIframe } from "../parser/iframe.js";
2
+ import { applemusic as applemusic$1 } from "../parser/platforms/applemusic.js";
3
+ import { applepodcasts as applepodcasts$1 } from "../parser/platforms/applepodcasts.js";
4
+ import { bluesky as bluesky$1 } from "../parser/platforms/bluesky.js";
5
+ import { dailymotion as dailymotion$1 } from "../parser/platforms/dailymotion.js";
6
+ import { facebook as facebook$1 } from "../parser/platforms/facebook.js";
7
+ import { flickr as flickr$1 } from "../parser/platforms/flickr.js";
8
+ import { giphy as giphy$1 } from "../parser/platforms/giphy.js";
9
+ import { imgur as imgur$1 } from "../parser/platforms/imgur.js";
10
+ import { instagram as instagram$1 } from "../parser/platforms/instagram.js";
11
+ import { kick as kick$1 } from "../parser/platforms/kick.js";
12
+ import { linkedin as linkedin$1 } from "../parser/platforms/linkedin.js";
13
+ import { pinterest as pinterest$1 } from "../parser/platforms/pinterest.js";
14
+ import { reddit as reddit$1 } from "../parser/platforms/reddit.js";
15
+ import { rumble as rumble$1 } from "../parser/platforms/rumble.js";
16
+ import { snapchat as snapchat$1 } from "../parser/platforms/snapchat.js";
17
+ import { soundcloud as soundcloud$1 } from "../parser/platforms/soundcloud.js";
18
+ import { spotify as spotify$1 } from "../parser/platforms/spotify.js";
19
+ import { strava as strava$1 } from "../parser/platforms/strava.js";
20
+ import { streamable as streamable$1 } from "../parser/platforms/streamable.js";
21
+ import { telegram as telegram$1 } from "../parser/platforms/telegram.js";
22
+ import { tenor as tenor$1 } from "../parser/platforms/tenor.js";
23
+ import { threads as threads$1 } from "../parser/platforms/threads.js";
24
+ import { tiktok as tiktok$1 } from "../parser/platforms/tiktok.js";
25
+ import { truthsocial as truthsocial$1 } from "../parser/platforms/truthsocial.js";
26
+ import { tumblr as tumblr$1 } from "../parser/platforms/tumblr.js";
27
+ import { twitch as twitch$1 } from "../parser/platforms/twitch.js";
28
+ import { vimeo as vimeo$1 } from "../parser/platforms/vimeo.js";
29
+ import { x as x$1 } from "../parser/platforms/x.js";
30
+ import { youtube as youtube$1 } from "../parser/platforms/youtube.js";
31
+ import { AppleMusicEmbed, ApplePodcastsEmbed } from "./apple-embed.js";
32
+ import { BlueskyEmbed } from "./bluesky-embed.js";
33
+ import { DailymotionEmbed } from "./dailymotion-embed.js";
34
+ import { FacebookEmbed } from "./facebook-embed.js";
35
+ import { FlickrEmbed } from "./flickr-embed.js";
36
+ import { GiphyEmbed } from "./giphy-embed.js";
37
+ import { ImgurEmbed } from "./imgur-embed.js";
38
+ import { InstagramEmbed } from "./instagram-embed.js";
39
+ import { KickEmbed } from "./kick-embed.js";
40
+ import { LinkedInEmbed } from "./linkedin-embed.js";
41
+ import { PinterestEmbed } from "./pinterest-embed.js";
42
+ import { RedditEmbed } from "./reddit-embed.js";
43
+ import { RumbleEmbed } from "./rumble-embed.js";
44
+ import { SnapchatEmbed } from "./snapchat-embed.js";
45
+ import { SoundCloudEmbed } from "./soundcloud-embed.js";
46
+ import { SpotifyEmbed } from "./spotify-embed.js";
47
+ import { StravaEmbed } from "./strava-embed.js";
48
+ import { StreamableEmbed } from "./streamable-embed.js";
49
+ import { TelegramEmbed } from "./telegram-embed.js";
50
+ import { TenorEmbed } from "./tenor-embed.js";
51
+ import { ThreadsEmbed } from "./threads-embed.js";
52
+ import { TikTokEmbed } from "./tiktok-embed.js";
53
+ import { TruthSocialEmbed } from "./truthsocial-embed.js";
54
+ import { TumblrEmbed } from "./tumblr-embed.js";
55
+ import { TwitchEmbed } from "./twitch-embed.js";
56
+ import { VimeoEmbed } from "./vimeo-embed.js";
57
+ import { XEmbed } from "./x-embed.js";
58
+ import { YouTubeEmbed } from "./youtube-embed.js";
59
+ import { GenericIframeEmbed } from "./generic-iframe-embed.js";
60
+ import { jsx } from "react/jsx-runtime";
61
+ // src/components/platforms.tsx
62
+ const x = {
63
+ kind: "platform",
64
+ parser: x$1,
65
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(XEmbed, {
66
+ ...shared,
67
+ onError,
68
+ embed
69
+ })
70
+ };
71
+ const instagram = {
72
+ kind: "platform",
73
+ parser: instagram$1,
74
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(InstagramEmbed, {
75
+ ...shared,
76
+ onError,
77
+ embed
78
+ })
79
+ };
80
+ const facebook = {
81
+ kind: "platform",
82
+ parser: facebook$1,
83
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(FacebookEmbed, {
84
+ ...shared,
85
+ ...frame,
86
+ onError,
87
+ embed
88
+ })
89
+ };
90
+ const threads = {
91
+ kind: "platform",
92
+ parser: threads$1,
93
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(ThreadsEmbed, {
94
+ ...shared,
95
+ onError,
96
+ embed
97
+ })
98
+ };
99
+ const tiktok = {
100
+ kind: "platform",
101
+ parser: tiktok$1,
102
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TikTokEmbed, {
103
+ ...shared,
104
+ ...frame,
105
+ onError,
106
+ embed
107
+ })
108
+ };
109
+ const youtube = {
110
+ kind: "platform",
111
+ parser: youtube$1,
112
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(YouTubeEmbed, {
113
+ ...shared,
114
+ ...frame,
115
+ onError,
116
+ embed
117
+ })
118
+ };
119
+ const telegram = {
120
+ kind: "platform",
121
+ parser: telegram$1,
122
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TelegramEmbed, {
123
+ ...shared,
124
+ onError,
125
+ embed
126
+ })
127
+ };
128
+ const snapchat = {
129
+ kind: "platform",
130
+ parser: snapchat$1,
131
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SnapchatEmbed, {
132
+ ...shared,
133
+ ...frame,
134
+ onError,
135
+ embed
136
+ })
137
+ };
138
+ const linkedin = {
139
+ kind: "platform",
140
+ parser: linkedin$1,
141
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(LinkedInEmbed, {
142
+ ...shared,
143
+ ...frame,
144
+ onError,
145
+ embed
146
+ })
147
+ };
148
+ const reddit = {
149
+ kind: "platform",
150
+ parser: reddit$1,
151
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(RedditEmbed, {
152
+ ...shared,
153
+ onError,
154
+ embed
155
+ })
156
+ };
157
+ const pinterest = {
158
+ kind: "platform",
159
+ parser: pinterest$1,
160
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(PinterestEmbed, {
161
+ ...shared,
162
+ onError,
163
+ embed
164
+ })
165
+ };
166
+ const spotify = {
167
+ kind: "platform",
168
+ parser: spotify$1,
169
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SpotifyEmbed, {
170
+ ...shared,
171
+ ...frame,
172
+ onError,
173
+ embed
174
+ })
175
+ };
176
+ const vimeo = {
177
+ kind: "platform",
178
+ parser: vimeo$1,
179
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(VimeoEmbed, {
180
+ ...shared,
181
+ ...frame,
182
+ onError,
183
+ embed
184
+ })
185
+ };
186
+ const twitch = {
187
+ kind: "platform",
188
+ parser: twitch$1,
189
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TwitchEmbed, {
190
+ ...shared,
191
+ ...frame,
192
+ onError,
193
+ embed
194
+ })
195
+ };
196
+ const dailymotion = {
197
+ kind: "platform",
198
+ parser: dailymotion$1,
199
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(DailymotionEmbed, {
200
+ ...shared,
201
+ ...frame,
202
+ onError,
203
+ embed
204
+ })
205
+ };
206
+ const soundcloud = {
207
+ kind: "platform",
208
+ parser: soundcloud$1,
209
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SoundCloudEmbed, {
210
+ ...shared,
211
+ ...frame,
212
+ onError,
213
+ embed
214
+ })
215
+ };
216
+ const applemusic = {
217
+ kind: "platform",
218
+ parser: applemusic$1,
219
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(AppleMusicEmbed, {
220
+ ...shared,
221
+ ...frame,
222
+ onError,
223
+ embed
224
+ })
225
+ };
226
+ const applepodcasts = {
227
+ kind: "platform",
228
+ parser: applepodcasts$1,
229
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
230
+ ...shared,
231
+ ...frame,
232
+ onError,
233
+ embed
234
+ })
235
+ };
236
+ const kick = {
237
+ kind: "platform",
238
+ parser: kick$1,
239
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(KickEmbed, {
240
+ ...shared,
241
+ ...frame,
242
+ onError,
243
+ embed
244
+ })
245
+ };
246
+ const giphy = {
247
+ kind: "platform",
248
+ parser: giphy$1,
249
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(GiphyEmbed, {
250
+ ...shared,
251
+ ...frame,
252
+ onError,
253
+ embed
254
+ })
255
+ };
256
+ const tenor = {
257
+ kind: "platform",
258
+ parser: tenor$1,
259
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TenorEmbed, {
260
+ ...shared,
261
+ ...frame,
262
+ onError,
263
+ embed
264
+ })
265
+ };
266
+ const streamable = {
267
+ kind: "platform",
268
+ parser: streamable$1,
269
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(StreamableEmbed, {
270
+ ...shared,
271
+ ...frame,
272
+ onError,
273
+ embed
274
+ })
275
+ };
276
+ const rumble = {
277
+ kind: "platform",
278
+ parser: rumble$1,
279
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(RumbleEmbed, {
280
+ ...shared,
281
+ ...frame,
282
+ onError,
283
+ embed
284
+ })
285
+ };
286
+ const truthsocial = {
287
+ kind: "platform",
288
+ parser: truthsocial$1,
289
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TruthSocialEmbed, {
290
+ ...shared,
291
+ onError,
292
+ embed
293
+ })
294
+ };
295
+ const imgur = {
296
+ kind: "platform",
297
+ parser: imgur$1,
298
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(ImgurEmbed, {
299
+ ...shared,
300
+ onError,
301
+ embed
302
+ })
303
+ };
304
+ const strava = {
305
+ kind: "platform",
306
+ parser: strava$1,
307
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(StravaEmbed, {
308
+ ...shared,
309
+ onError,
310
+ embed
311
+ })
312
+ };
313
+ const flickr = {
314
+ kind: "platform",
315
+ parser: flickr$1,
316
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(FlickrEmbed, {
317
+ ...shared,
318
+ ...frame,
319
+ onError,
320
+ embed
321
+ })
322
+ };
323
+ const bluesky = {
324
+ kind: "platform",
325
+ parser: bluesky$1,
326
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(BlueskyEmbed, {
327
+ ...shared,
328
+ onError,
329
+ embed
330
+ })
331
+ };
332
+ const tumblr = {
333
+ kind: "platform",
334
+ parser: tumblr$1,
335
+ render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TumblrEmbed, {
336
+ ...shared,
337
+ onError,
338
+ embed
339
+ })
340
+ };
341
+ /** Iframe embed code that no listed platform recognises, checked as `GenericIframeEmbed` does. */
342
+ const genericIframe = {
343
+ kind: "iframe",
344
+ parse: parseIframe,
345
+ render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(GenericIframeEmbed, {
346
+ ...shared,
347
+ ...frame,
348
+ onError,
349
+ embed
350
+ })
351
+ };
352
+ const EVERY_PLATFORM = [
353
+ genericIframe,
354
+ x,
355
+ instagram,
356
+ facebook,
357
+ threads,
358
+ tiktok,
359
+ youtube,
360
+ telegram,
361
+ snapchat,
362
+ linkedin,
363
+ reddit,
364
+ pinterest,
365
+ spotify,
366
+ vimeo,
367
+ twitch,
368
+ dailymotion,
369
+ soundcloud,
370
+ applemusic,
371
+ applepodcasts,
372
+ kick,
373
+ giphy,
374
+ tenor,
375
+ streamable,
376
+ rumble,
377
+ truthsocial,
378
+ imgur,
379
+ strava,
380
+ flickr,
381
+ bluesky,
382
+ tumblr
383
+ ];
384
+ export { EVERY_PLATFORM, applemusic, applepodcasts, bluesky, dailymotion, facebook, flickr, genericIframe, giphy, imgur, instagram, kick, linkedin, pinterest, reddit, rumble, snapchat, soundcloud, spotify, strava, streamable, telegram, tenor, threads, tiktok, truthsocial, tumblr, twitch, vimeo, x, youtube };
@@ -1,10 +1,13 @@
1
+ import { PlatformParser } from "../parser/platform.js";
2
+ import { ParsedEmbed } from "../parser/types.js";
1
3
  import "./bluesky-embed.js";
2
- import { BlueskyOptions } from "../core/plans/bluesky.js";
3
4
  import "./dailymotion-embed.js";
4
- import { DailymotionOptions } from "../core/plans/dailymotion.js";
5
+ import { BlueskyOptions } from "../core/plans/bluesky.js";
5
6
  import "./facebook-embed.js";
6
- import { FacebookOptions } from "../core/plans/facebook.js";
7
+ import { DailymotionOptions } from "../core/plans/dailymotion.js";
7
8
  import "./flickr-embed.js";
9
+ import { FacebookOptions } from "../core/plans/facebook.js";
10
+ import { ParsedIframe } from "../parser/iframe.js";
8
11
  import { FlickrOptions } from "../core/plans/flickr.js";
9
12
  import "./imgur-embed.js";
10
13
  import { ImgurOptions } from "../core/plans/imgur.js";
@@ -55,6 +58,30 @@ export type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOpti
55
58
  */
56
59
  fallback?: (html: string) => ReactNode;
57
60
  };
61
+ /** What `<SocialEmbed>` passes on to the platform it renders. */
62
+ export type RouteProps = {
63
+ shared: Omit<SocialEmbedProps, 'html' | 'url' | 'fallback' | 'height' | 'maxHeight' | 'onError'>;
64
+ frame: Pick<FrameProps, 'height' | 'maxHeight'>;
65
+ onError: FrameProps['onError'];
66
+ };
67
+ /**
68
+ * A platform for `createSocialEmbed`, such as `youtube` or `genericIframe`. Opaque: import the
69
+ * ones a page needs and pass them on.
70
+ */
71
+ export type EmbedPlatform = {
72
+ readonly kind: 'platform';
73
+ readonly parser: PlatformParser;
74
+ readonly render: (embed: ParsedEmbed, props: RouteProps) => ReactNode;
75
+ } | {
76
+ readonly kind: 'iframe';
77
+ readonly parse: (html: string) => ParsedIframe | null;
78
+ readonly render: (embed: ParsedIframe, props: RouteProps) => ReactNode;
79
+ };
80
+ /**
81
+ * A `<SocialEmbed>` that recognises only the listed platforms, so a bundler leaves the others
82
+ * out. Call it in a client module: `createSocialEmbed([youtube, x, genericIframe])`.
83
+ */
84
+ export declare function createSocialEmbed(list: readonly EmbedPlatform[]): (props: SocialEmbedProps) => ReactNode;
58
85
  /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
59
- export declare function SocialEmbed(props: SocialEmbedProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
86
+ export declare function SocialEmbed(props: SocialEmbedProps): ReactNode;
60
87
  export {};