social-embeds 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Pasting a platform's embed code into `dangerouslySetInnerHTML` does not work in
6
6
 
7
7
  **[Live demo](https://amitrev.github.io/social-embeds/)**: every platform from embed code and post URLs, and a box for your own, running the released version.
8
8
 
9
- - X, Instagram, Threads, Facebook, TikTok, YouTube, Telegram, Snapchat, LinkedIn, Reddit, Pinterest, Spotify, Vimeo, Twitch, Dailymotion, Bluesky, SoundCloud, Apple Music, Apple Podcasts, Tumblr, Kick and Giphy
9
+ - X, Instagram, Threads, Facebook, TikTok, YouTube, Telegram, Snapchat, LinkedIn, Reddit, Pinterest, Spotify, Vimeo, Twitch, Dailymotion, Bluesky, SoundCloud, Apple Music, Apple Podcasts, Tumblr, Kick, Giphy, Truth Social, Imgur, Tenor, Streamable, Strava, Flickr and Rumble, plus any other site's iframe embed code (see [Generic iframe embeds](#generic-iframe-embeds))
10
10
  - React 19, Next.js App Router (Server Components, client navigation), or plain React
11
11
  - Zero runtime dependencies, ESM only, typed
12
12
  - No styling and no defaults beyond what the embed code or your props ask for
@@ -38,7 +38,7 @@ There are two inputs, and they lead to the same component:
38
38
  - **`html`**: the embed code from the platform's Embed dialog, stored as-is (for example in your CMS). It carries the post's options (theme, caption, start time, and so on), and for X, Instagram, Threads and some Facebook code it also carries **fallback content**: the post text, author and link inside the `<blockquote>`. That content is rendered on the server, so crawlers and visitors without JavaScript see it, and the platform script upgrades it in place.
39
39
  - **`url`**: the post's address. A URL has no fallback content, so until the post has loaded the component shows a placeholder. This is a property of the input, not a limitation of the package. A URL carries no options either, except a YouTube start time (`t` or `start`), the privacy-enhanced host, Telegram's `single` and `comment`, a Vimeo start time (`#t=`) and a Twitch video's `t`.
40
40
 
41
- Embed code is matched strictly: it must be one platform's own snippet, as the platform produced it. Extra wrappers, other markup or unknown scripts make it unrecognised (see [`fallback`](#unrecognised-embed-code)). The exceptions are Vimeo's and Dailymotion's own responsive wrappers, which hold the video's aspect ratio.
41
+ Embed code is matched strictly: it must be one platform's own snippet, as the platform produced it. Extra wrappers, other markup or unknown scripts make it unrecognised (see [`fallback`](#unrecognised-embed-code)). The exceptions are Vimeo's, Dailymotion's and Streamable's own responsive wrappers, which hold the video's aspect ratio, and the script tag that Truth Social, Imgur, Tenor, Strava and Flickr put next to their markup. Embed code that no platform claims, but that holds one iframe, renders as a [generic iframe](#generic-iframe-embeds).
42
42
 
43
43
  ## Usage
44
44
 
@@ -65,7 +65,7 @@ It accepts the [shared props](#shared-props); `height` reaches only the iframe-b
65
65
 
66
66
  #### Unrecognised embed code
67
67
 
68
- When `html` is not a recognised embed code, `<SocialEmbed>` calls `fallback` with the original string and renders what it returns. Without `fallback`, it renders nothing and calls `onError`.
68
+ When `html` is neither a platform's embed code nor a [generic iframe](#generic-iframe-embeds), `<SocialEmbed>` calls `fallback` with the original string and renders what it returns. Without `fallback`, it renders nothing and calls `onError`.
69
69
 
70
70
  ```tsx
71
71
  <SocialEmbed
@@ -79,6 +79,8 @@ When `html` is not a recognised embed code, `<SocialEmbed>` calls `fallback` wit
79
79
 
80
80
  An unsupported URL never reaches `fallback`: nothing is rendered and `onError` names the URL.
81
81
 
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
+
82
84
  ### Platform components
83
85
 
84
86
  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.
@@ -90,18 +92,26 @@ import {
90
92
  BlueskyEmbed,
91
93
  DailymotionEmbed,
92
94
  FacebookEmbed,
95
+ FlickrEmbed,
96
+ GenericIframeEmbed,
93
97
  GiphyEmbed,
98
+ ImgurEmbed,
94
99
  InstagramEmbed,
95
100
  KickEmbed,
96
101
  LinkedInEmbed,
97
102
  PinterestEmbed,
98
103
  RedditEmbed,
104
+ RumbleEmbed,
99
105
  SnapchatEmbed,
100
106
  SoundCloudEmbed,
101
107
  SpotifyEmbed,
108
+ StravaEmbed,
109
+ StreamableEmbed,
102
110
  TelegramEmbed,
111
+ TenorEmbed,
103
112
  ThreadsEmbed,
104
113
  TikTokEmbed,
114
+ TruthSocialEmbed,
105
115
  TumblrEmbed,
106
116
  TwitchEmbed,
107
117
  VimeoEmbed,
@@ -175,6 +185,22 @@ import {
175
185
  <KickEmbed url="https://kick.com/kick" muted />
176
186
 
177
187
  <GiphyEmbed url="https://giphy.com/gifs/originals-animation-kitten-logo-l41YlHs99JsSptZf2" maxWidth={480} />
188
+
189
+ <TruthSocialEmbed url="https://truthsocial.com/@truthsocial/posts/117529982042129746" />
190
+
191
+ <ImgurEmbed url="https://imgur.com/a/04b1CmA" context={false} />
192
+
193
+ <TenorEmbed url="https://tenor.com/view/happy-cat-day-gif-12328062661350661133" maxWidth={360} />
194
+
195
+ <StreamableEmbed url="https://streamable.com/lttg48" muted loop />
196
+
197
+ <StravaEmbed url="https://www.strava.com/routes/3247927232574435836" embedStyle="minimal" />
198
+
199
+ <FlickrEmbed url="https://www.flickr.com/photos/flickr/55618331478/" maxHeight={480} />
200
+
201
+ <RumbleEmbed html={code} />
202
+
203
+ <GenericIframeEmbed html={code} />
178
204
  ```
179
205
 
180
206
  | Component | Option props |
@@ -197,13 +223,19 @@ import {
197
223
  | `BlueskyEmbed` | `colorMode` (`'light'` \| `'dark'` \| `'system'`) |
198
224
  | `SoundCloudEmbed` | SoundCloud's player parameters, in camelCase: `visual`, `color` (with `#`), `autoPlay`, `hideRelated`, `showComments`, `showUser`, `showReposts`, `showTeaser`, `showArtwork` |
199
225
  | `AppleMusicEmbed`, `ApplePodcastsEmbed`, `TumblrEmbed`, `GiphyEmbed` | none |
226
+ | `TruthSocialEmbed`, `TenorEmbed`, `RumbleEmbed` | none |
227
+ | `ImgurEmbed` | `context` (`false` hides the title and description) |
228
+ | `StreamableEmbed` | `autoplay`, `hd`, `loop`, `muted`, `nocontrols` |
229
+ | `StravaEmbed` | `embedStyle` (`'standard'` \| `'minimal'`; not `style`, which stays the CSS prop), `fullWidth` (routes), `mapHash` |
230
+ | `FlickrEmbed` | `header`, `footer`, `context` |
231
+ | `GenericIframeEmbed` | none: it takes `html` or a `ParsedIframe` as `embed`, no `url` |
200
232
  | `KickEmbed` | `autoplay`, `muted` |
201
233
 
202
- Boolean player parameters are written as `1`/`0`; Telegram's, Reddit's, Twitch's, Dailymotion's, SoundCloud's and Kick's options are written the way their own embed code writes them.
234
+ Boolean player parameters are written as `1`/`0`; Streamable's as the player writes them; Telegram's, Reddit's, Twitch's, Dailymotion's, SoundCloud's and Kick's options are written the way their own embed code writes them.
203
235
 
204
236
  ### Parser
205
237
 
206
- `social-embeds/parser` exports `parseEmbed(html)` and `matchUrl(url)`. They are pure functions with no React and no DOM, so they run the same in a Server Component, in Node (for example when your CMS saves a post) and in the browser. Both return a plain, serialisable `ParsedEmbed`, or `null` for input they do not recognise. They never throw.
238
+ `social-embeds/parser` exports `parseEmbed(html)`, `matchUrl(url)` and `parseIframe(html)`. They are pure functions with no React and no DOM, so they run the same in a Server Component, in Node (for example when your CMS saves a post) and in the browser. `parseEmbed` and `matchUrl` return a plain, serialisable `ParsedEmbed`, and `parseIframe` a plain, serialisable `ParsedIframe`, or `null` for input they do not recognise. They never throw.
207
239
 
208
240
  ```ts
209
241
  import { matchUrl, parseEmbed, type ParsedEmbed } from 'social-embeds/parser';
@@ -254,53 +286,62 @@ import { YouTubeEmbed } from 'social-embeds';
254
286
  }
255
287
  ```
256
288
 
289
+ `parseIframe(html)` reads a [generic iframe](#generic-iframe-embeds): it returns a checked `ParsedIframe` (`src`, `title`, `allow`, `allowFullscreen`, `referrerPolicy`, `sandbox`, `scrolling`, `size` and `ratio`), or `null` when the code is not one. It also returns `null` for an iframe that a named platform owns, so run `parseEmbed` first, as `<SocialEmbed>` does. Pass the result to `GenericIframeEmbed` as `embed`.
290
+
257
291
  A component checks an `embed` before using it: its `url` must be the exact URL `matchUrl` returns for it, with the same platform and id, and `fallbackHtml` must be exactly what the parser would produce. Otherwise it calls `onError`, or drops the fallback content.
258
292
 
259
293
  ## Shared props
260
294
 
261
- | Prop | Type | Default | Notes |
262
- | ------------- | ------------------------ | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
263
- | `url` | `string` | | Post URL. Platform components take `url` or `embed`; `<SocialEmbed>` takes `url` or `html`. |
264
- | `embed` | `ParsedEmbed` | | Platform components only. |
265
- | `html` | `string` | | `<SocialEmbed>` only. |
266
- | `width` | `number \| string` | `'100%'` | Wrapper width. |
267
- | `maxWidth` | `number` | per platform | The embed fills its container up to this width, in pixels. See [Platforms](#platforms). |
268
- | `height` | `number` | | Fixed-size iframe embeds only (YouTube, TikTok, Facebook video embed code, Snapchat, LinkedIn, Spotify, Vimeo, Twitch, Dailymotion, SoundCloud, Apple Music, Apple Podcasts, Kick, Giphy): a fixed height instead of the aspect ratio, or instead of a fixed-height player's default. The others size themselves. |
269
- | `maxHeight` | `number` | | Fixed-size iframe embeds only: the embed is at most this tall, in pixels. It narrows to keep its aspect ratio, so a vertical video does not fill the column. |
270
- | `placeholder` | `ReactNode` | a skeleton | Shown until the post has loaded. The default skeleton has a per-platform minimum height to limit layout shift. |
271
- | `lazy` | `boolean` | `true` | Load the embed only when it comes within 200 px of the viewport. |
272
- | `onLoad` | `() => void` | | Called once the platform has rendered the post (iframe embeds: when the iframe has loaded; Telegram, Reddit, Bluesky and Tumblr: when the frame first reports its height). |
273
- | `onError` | `(error: Error) => void` | | Called on invalid input, a script that fails to load, or a post that does not render. Components never throw. |
274
- | `...rest` | `ComponentProps<'div'>` | | Passed to the wrapper `div` (`className`, `style`, `data-*`, …). |
275
-
276
- Script-based embeds try to render three times, waiting 15 s each time, 1 s and then 2 s apart, before `onError` reports the failure. Iframe embeds get 15 s, counted from when the embed comes near the viewport, also with `lazy={false}`. Telegram, Reddit, Bluesky and Tumblr frames that report no height by then show at their starting height; other frames that have not loaded by then show as they are, such as a frame the browser blocked. `onError` reports both, and a frame that loads or reports its height later still calls `onLoad`.
295
+ | Prop | Type | Default | Notes |
296
+ | ------------- | ------------------------ | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
297
+ | `url` | `string` | | Post URL. Platform components take `url` or `embed`; `<SocialEmbed>` takes `url` or `html`. |
298
+ | `embed` | `ParsedEmbed` | | Platform components only. |
299
+ | `html` | `string` | | `<SocialEmbed>` only. |
300
+ | `width` | `number \| string` | `'100%'` | Wrapper width. |
301
+ | `maxWidth` | `number` | per platform | The embed fills its container up to this width, in pixels. See [Platforms](#platforms). |
302
+ | `height` | `number` | | Fixed-size iframe embeds only (YouTube, TikTok, Facebook video embed code, Snapchat, LinkedIn, Spotify, Vimeo, Twitch, Dailymotion, SoundCloud, Apple Music, Apple Podcasts, Kick, Giphy, Tenor, Streamable, Rumble, Flickr, generic iframes): a fixed height instead of the aspect ratio, or instead of a fixed-height player's default. The others size themselves. |
303
+ | `maxHeight` | `number` | | Fixed-size iframe embeds only: the embed is at most this tall, in pixels. It narrows to keep its aspect ratio, so a vertical video does not fill the column. |
304
+ | `placeholder` | `ReactNode` | a skeleton | Shown until the post has loaded. The default skeleton has a per-platform minimum height to limit layout shift. |
305
+ | `lazy` | `boolean` | `true` | Load the embed only when it comes within 200 px of the viewport. |
306
+ | `onLoad` | `() => void` | | Called once the platform has rendered the post (iframe embeds: when the iframe has loaded; Telegram, Reddit, Bluesky, Tumblr, Truth Social, Imgur and Strava: when the frame first reports its height). |
307
+ | `onError` | `(error: Error) => void` | | Called on invalid input, a script that fails to load, or a post that does not render. Components never throw. |
308
+ | `...rest` | `ComponentProps<'div'>` | | Passed to the wrapper `div` (`className`, `style`, `data-*`, …). |
309
+
310
+ Script-based embeds try to render three times, waiting 15 s each time, 1 s and then 2 s apart, before `onError` reports the failure. Iframe embeds get 15 s, counted from when the embed comes near the viewport, also with `lazy={false}`. Telegram, Reddit, Bluesky, Tumblr, Truth Social, Imgur and Strava frames that report no height by then show at their starting height; other frames that have not loaded by then show as they are, such as a frame the browser blocked. `onError` reports both, and a frame that loads or reports its height later still calls `onLoad`.
277
311
 
278
312
  ## Platforms
279
313
 
280
- | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
281
- | -------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
282
- | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, `twitter.com/…` (also `www.` and `mobile.`) | `data-theme`, `data-conversation`, `data-cards`, `data-align` or `align`, `data-lang`, `data-dnt`, `data-width` | 550 |
283
- | Instagram | script (`embed.js`), `instgrm.Embeds.process` | `instagram.com/p/{code}/`, `/reel/`, `/reels/`, `/tv/`, `/{user}/p/{code}/`, `/{user}/reel/{code}/` | `data-instgrm-captioned`, `data-instgrm-version` | 540 |
284
- | Threads | script (`embed.js`), `instgrm.Embeds.process` | `threads.com/@{user}/post/{code}`, `threads.com/t/{code}` (and `threads.net`) | `data-theme`, `data-text-post-version` | 658 |
285
- | Facebook | posts and video URLs: SDK (`sdk.js`), `FB.XFBML.parse`; video embed code: iframe | see [Facebook](#facebook) | `data-width`, `data-show-text`, `data-lazy`, `data-allowfullscreen`, `data-autoplay`, `data-show-captions`; iframe query (`show_text`, `width`, …); SDK locale | posts 750, videos none |
286
- | TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
287
- | YouTube | iframe | `youtube.com/watch?v={id}`, `youtu.be/{id}`, `/shorts/{id}`, `/embed/{id}`, `/live/{id}`, `youtube-nocookie.com/embed/{id}`; `t` and `start` are kept | every player query parameter; the youtube-nocookie.com host | none |
288
- | Telegram | iframe (`t.me/{post}?embed=1`), height from the frame | `t.me/{channel}/{id}`, `t.me/s/{channel}/{id}`, `telegram.me/…`; `single` and `comment` are kept | `data-width`, `data-userpic`, `data-color`, `data-dark`, `data-dark-color`, `data-comment`, `data-mode`, `data-single` | 500 |
289
- | Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
290
- | LinkedIn | iframe, fixed height | `linkedin.com/feed/update/urn:li:{activity\|share\|ugcPost}:{id}`, `linkedin.com/posts/{slug}-activity-{id}-…` (also country hosts such as `bg.`) | iframe query (`collapsed`), `width`, `height` | embed code width, else 504 |
291
- | Reddit | iframe (`embed.reddit.com`), height from the frame | `reddit.com/r/{sub}/comments/{id}/…`, comments `…/comments/{id}/comment/{commentId}/` (also `old.` and `new.`) | `data-embed-height`, `data-embed-theme`, `data-embed-showmedia`, `data-embed-showtitle`, `data-embed-locale`, `data-embed-depth` and the other `data-embed-*` | 640 |
292
- | Pinterest | script (`pinit_main.js`), `PinUtils.build` | `pinterest.com/pin/{id}/`, `/pin/{slug}--{id}/`, country hosts (`bg.pinterest.com`, `pinterest.co.uk`, …) | `data-pin-width`, `data-pin-lang`, `data-pin-terse` | the pin's width: 236, 345 or 600 |
293
- | Spotify | iframe (`open.spotify.com/embed/…`), fixed height | `open.spotify.com/{track\|album\|playlist\|artist\|episode\|show\|audiobook\|chapter}/{id}`, also with an `intl-{lang}/` prefix | iframe query (`theme`, …; `utm_source` and `si` dropped), `height`; `/video` for a video show | none |
294
- | Vimeo | iframe (`player.vimeo.com/video/{id}`) | `vimeo.com/{id}`, `vimeo.com/{id}/{hash}` (unlisted), `/channels/{name}/{id}`, `/groups/{name}/videos/{id}`, `/showcase/{id}/video/{id}`, `player.vimeo.com/video/{id}`; `#t=` is kept | every player query parameter (`app_id` and `player_id` dropped); `width` and `height`, or the responsive wrapper's ratio | none |
295
- | Twitch | iframe (`player.twitch.tv`, `clips.twitch.tv/embed`), `parent` set in the browser | `twitch.tv/{channel}`, `/videos/{id}` (`t` is kept), `/collections/{id}`, `/{channel}/clip/{slug}`, `clips.twitch.tv/{slug}` (also `www.` and `m.`) | `autoplay`, `muted`, `time`, `width`, `height`; `parent` is dropped | none |
296
- | Dailymotion | iframe (`geo.dailymotion.com/player/{playerId}.html`), Player ID required | `dailymotion.com/video/{id}`, `dailymotion.com/embed/video/{id}`, `dai.ly/{id}` | the Player ID, every player query parameter; `width` and `height`, or the responsive wrapper's ratio | none |
297
- | Bluesky | iframe (`embed.bsky.app/embed/…`), height from the frame; `embed.js` is not loaded | `bsky.app/profile/{did}/post/{rkey}` only: see [Bluesky](#bluesky) | `data-bluesky-uri`, `data-bluesky-cid`, `data-bluesky-embed-color-mode` | 600 |
298
- | SoundCloud | iframe (`w.soundcloud.com/player`), fixed height | `soundcloud.com/{user}/{track}`, `/{user}/sets/{playlist}`, `/{user}`, a private track's `/s-{token}`, `api.soundcloud.com/{tracks\|playlists\|users}/{id}` (also `www.` and `m.`) | every player query parameter, `height`; the `url` parameter is the content | none |
299
- | Apple Music | iframe (`embed.music.apple.com`), fixed height | `music.apple.com/{country}/{album\|song\|playlist}/{slug}/{id}`, a song on its album with `?i={id}` | `height` | 660 |
300
- | Apple Podcasts | iframe (`embed.podcasts.apple.com`), fixed height | `podcasts.apple.com/{country}/podcast/{slug}/id{id}`, an episode with `?i={id}` | `width`, `height` | 640 |
301
- | Tumblr | iframe (`embed.tumblr.com/embed/post/…`), height from the frame; `post.js` is not loaded | `www.tumblr.com/{blog}/{id}`, `{blog}.tumblr.com/post/{id}`, with or without the slug | none | 540 |
302
- | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
303
- | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/gifs/{id}`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/giphy.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
314
+ | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
315
+ | -------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
316
+ | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, `twitter.com/…` (also `www.` and `mobile.`) | `data-theme`, `data-conversation`, `data-cards`, `data-align` or `align`, `data-lang`, `data-dnt`, `data-width` | 550 |
317
+ | Instagram | script (`embed.js`), `instgrm.Embeds.process` | `instagram.com/p/{code}/`, `/reel/`, `/reels/`, `/tv/`, `/{user}/p/{code}/`, `/{user}/reel/{code}/` | `data-instgrm-captioned`, `data-instgrm-version` | 540 |
318
+ | Threads | script (`embed.js`), `instgrm.Embeds.process` | `threads.com/@{user}/post/{code}`, `threads.com/t/{code}` (and `threads.net`) | `data-theme`, `data-text-post-version` | 658 |
319
+ | Facebook | posts and video URLs: SDK (`sdk.js`), `FB.XFBML.parse`; video embed code: iframe | see [Facebook](#facebook) | `data-width`, `data-show-text`, `data-lazy`, `data-allowfullscreen`, `data-autoplay`, `data-show-captions`; iframe query (`show_text`, `width`, …); SDK locale | posts 750, videos none |
320
+ | TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
321
+ | YouTube | iframe | `youtube.com/watch?v={id}`, `youtu.be/{id}`, `/shorts/{id}`, `/embed/{id}`, `/live/{id}`, `youtube-nocookie.com/embed/{id}`; `t` and `start` are kept | every player query parameter; the youtube-nocookie.com host | none |
322
+ | Telegram | iframe (`t.me/{post}?embed=1`), height from the frame | `t.me/{channel}/{id}`, `t.me/s/{channel}/{id}`, `telegram.me/…`; `single` and `comment` are kept | `data-width`, `data-userpic`, `data-color`, `data-dark`, `data-dark-color`, `data-comment`, `data-mode`, `data-single` | 500 |
323
+ | Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
324
+ | LinkedIn | iframe, fixed height | `linkedin.com/feed/update/urn:li:{activity\|share\|ugcPost}:{id}`, `linkedin.com/posts/{slug}-activity-{id}-…` (also country hosts such as `bg.`) | iframe query (`collapsed`), `width`, `height` | embed code width, else 504 |
325
+ | Reddit | iframe (`embed.reddit.com`), height from the frame | `reddit.com/r/{sub}/comments/{id}/…`, comments `…/comments/{id}/comment/{commentId}/` (also `old.` and `new.`) | `data-embed-height`, `data-embed-theme`, `data-embed-showmedia`, `data-embed-showtitle`, `data-embed-locale`, `data-embed-depth` and the other `data-embed-*` | 640 |
326
+ | Pinterest | script (`pinit_main.js`), `PinUtils.build` | `pinterest.com/pin/{id}/`, `/pin/{slug}--{id}/`, country hosts (`bg.pinterest.com`, `pinterest.co.uk`, …) | `data-pin-width`, `data-pin-lang`, `data-pin-terse` | the pin's width: 236, 345 or 600 |
327
+ | Spotify | iframe (`open.spotify.com/embed/…`), fixed height | `open.spotify.com/{track\|album\|playlist\|artist\|episode\|show\|audiobook\|chapter}/{id}`, also with an `intl-{lang}/` prefix | iframe query (`theme`, …; `utm_source` and `si` dropped), `height`; `/video` for a video show | none |
328
+ | Vimeo | iframe (`player.vimeo.com/video/{id}`) | `vimeo.com/{id}`, `vimeo.com/{id}/{hash}` (unlisted), `/channels/{name}/{id}`, `/groups/{name}/videos/{id}`, `/showcase/{id}/video/{id}`, `player.vimeo.com/video/{id}`; `#t=` is kept | every player query parameter (`app_id` and `player_id` dropped); `width` and `height`, or the responsive wrapper's ratio | none |
329
+ | Twitch | iframe (`player.twitch.tv`, `clips.twitch.tv/embed`), `parent` set in the browser | `twitch.tv/{channel}`, `/videos/{id}` (`t` is kept), `/collections/{id}`, `/{channel}/clip/{slug}`, `clips.twitch.tv/{slug}` (also `www.` and `m.`) | `autoplay`, `muted`, `time`, `width`, `height`; `parent` is dropped | none |
330
+ | Dailymotion | iframe (`geo.dailymotion.com/player/{playerId}.html`), Player ID required | `dailymotion.com/video/{id}`, `dailymotion.com/embed/video/{id}`, `dai.ly/{id}` | the Player ID, every player query parameter; `width` and `height`, or the responsive wrapper's ratio | none |
331
+ | Bluesky | iframe (`embed.bsky.app/embed/…`), height from the frame; `embed.js` is not loaded | `bsky.app/profile/{did}/post/{rkey}` only: see [Bluesky](#bluesky) | `data-bluesky-uri`, `data-bluesky-cid`, `data-bluesky-embed-color-mode` | 600 |
332
+ | SoundCloud | iframe (`w.soundcloud.com/player`), fixed height | `soundcloud.com/{user}/{track}`, `/{user}/sets/{playlist}`, `/{user}`, a private track's `/s-{token}`, `api.soundcloud.com/{tracks\|playlists\|users}/{id}` (also `www.` and `m.`) | every player query parameter, `height`; the `url` parameter is the content | none |
333
+ | Apple Music | iframe (`embed.music.apple.com`), fixed height | `music.apple.com/{country}/{album\|song\|playlist}/{slug}/{id}`, a song on its album with `?i={id}` | `height` | 660 |
334
+ | Apple Podcasts | iframe (`embed.podcasts.apple.com`), fixed height | `podcasts.apple.com/{country}/podcast/{slug}/id{id}`, an episode with `?i={id}` | `width`, `height` | 640 |
335
+ | Tumblr | iframe (`embed.tumblr.com/embed/post/…`), height from the frame; `post.js` is not loaded | `www.tumblr.com/{blog}/{id}`, `{blog}.tumblr.com/post/{id}`, with or without the slug | none | 540 |
336
+ | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
337
+ | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/gifs/{id}`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/giphy.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
338
+ | Truth Social | iframe (`truthsocial.com/@{user}/{id}/embed`), height from the frame; `embed.js` is not loaded | `truthsocial.com/@{user}/posts/{id}`, `truthsocial.com/@{user}/{id}` | `video`, set from the iframe's `truthsocial-video` class, not a prop | 600 |
339
+ | Imgur | iframe (`imgur.com/{id}/embed?pub=true`), height from the frame; `embed.js` is not loaded | `imgur.com/{id}`, `imgur.com/a/{id}`, `imgur.com/gallery/{id}` and `…/gallery/{slug}-{id}`, `i.imgur.com/{id}.{ext}` | `data-context`, `data-analytics` | 540 |
340
+ | Tenor | iframe (`tenor.com/embed/{id}`); `embed.js` is not loaded | `tenor.com/view/{slug}-gif-{id}`, with an optional locale (`tenor.com/en-GB/view/…`) | none; the ratio from `data-aspect-ratio`, or the iframe's `width` and `height` | none |
341
+ | Streamable | iframe (`streamable.com/e/{id}`) | `streamable.com/{id}`, `streamable.com/e/{id}`, `streamable.com/o/{id}` | `loop`, `autoplay`, `nocontrols`, `hd`, `muted`; the ratio from the wrapper or the iframe | none |
342
+ | Strava | iframe (`strava-embeds.com/{type}/{id}`), height from the frame; `embed.js` is not loaded | `www.strava.com/activities/{id}`, `www.strava.com/routes/{id}` | `data-style`, `data-full-width` (routes), `data-map-hash` | 554 (none for a full-width route) |
343
+ | Flickr | iframe (`embedr.flickr.com/photos/{id}`), built on the client at the box's width; `client-code.js` is not loaded | `flickr.com/photos/{user}/{id}` (with or without `/in/…`), `…/photos/{user}/albums/{id}`, `flic.kr/p/{code}` | `data-header`, `data-footer`, `data-context`; the image's `width` and `height` | the image's width (none for a URL) |
344
+ | Rumble | iframe (`rumble.com/embed/{id}/`) | `rumble.com/embed/{id}/` only: see [Rumble](#rumble) | `pub`, `width`, `height` | none |
304
345
 
305
346
  URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
306
347
 
@@ -448,6 +489,61 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
448
489
  - Kick has no embed dialog: use a channel URL or Kick's player URL in an iframe. Videos and clips are not supported.
449
490
  - Giphy's "via GIPHY" credit is accepted and not rendered. A URL carries no size and renders square; `maxWidth` keeps it small.
450
491
 
492
+ ### Truth Social, Imgur and Strava
493
+
494
+ - These frames report their own height without being asked, so the height follows the post. Until the first report, the frame is 150 px (Truth Social), 500 px (Imgur) or 650 px (Strava) high.
495
+ - Truth Social video posts get 165 px extra, as Truth Social's own script adds. Embed code marks a video post; a URL cannot, so a URL takes the height the frame reports. A vertical video stays cut off, as in Truth Social's own embed.
496
+ - Imgur's gallery posts and albums share ids, and both render as an album. `i.imgur.com` file URLs render the image's post.
497
+ - Strava renders activities and routes. The style option is the prop `embedStyle`, because `style` stays the CSS prop; in embed code it is `data-style`. `strava.app.link` short links are not supported.
498
+
499
+ ### Tenor and Streamable
500
+
501
+ - A Tenor URL has no size, so it renders at 1.33:1, the default ratio of Tenor's own script; Tenor's Embed dialog code carries its ratio, and oEmbed code carries its own `width` and `height`. A sticker embeds like a GIF.
502
+ - Streamable's player has a "Copy embed code" menu. Its code ends with a stray `</div>`; the package accepts exactly that one. The code Streamable's API and oEmbed give is accepted too.
503
+
504
+ ### Flickr
505
+
506
+ - Plain photo and album links work, and so do `flic.kr/p/…` short links: the code is decoded without a network request. Embed code is accepted too. Flickr's own script is never loaded, because it runs Flickr's code in your page.
507
+ - The frame is rebuilt at the box's width: the first width builds at once, and later widths wait until the box has held its width for 200 ms. The package builds a new frame instead of navigating the old one, so the browser gets no extra history entries. The frame is blank until it has reloaded.
508
+ - A fixed `height` may crop the photo or letterbox it. Prefer `maxHeight`. A URL renders at 4:3.
509
+
510
+ ### Rumble
511
+
512
+ - Rumble's page URL (`rumble.com/v…-title.html`) carries a different id from the embed code's, so a URL cannot be turned into a frame without a lookup, and the package makes none. A page URL renders nothing, and `onError` reports `social-embeds: a Rumble URL needs a lookup: use the embed code`. `matchUrl` returns `null` for it.
513
+ - Use the iframe code from the video's Embed dialog. `pub` is kept when the code has it. The "JavaScript" option writes a script player with no iframe; it is not supported.
514
+
515
+ ### Generic iframe embeds
516
+
517
+ Embed code that no platform claims, but that holds one iframe, renders as a responsive iframe. This covers Google Maps, Datawrapper, Deezer, Mixcloud, Loom, TED, CodePen, Bandcamp and any other site that gives iframe code.
518
+
519
+ - **Embed code only.** A plain URL to an unknown site renders nothing: the package cannot know the site's embed URL.
520
+ - **Exactly one `<iframe>`.** Markup around it (wrappers, links, captions, `<script>` tags) is dropped, and no script runs. Two or more iframes are not a generic embed.
521
+ - **Named platforms win.** `<SocialEmbed>` and `<social-embed>` try the platforms first. An iframe whose host a named platform owns (YouTube, Vimeo, Spotify, `facebook.com/plugins`, and so on) never goes generic, even if that platform rejects it. Frames a platform's own script creates (`platform.twitter.com/embed/…`) and a platform's other hosts (`podcasters.spotify.com`) are not guarded and render generically.
522
+ - **Kept attributes:** `src`, `width`, `height`, `title`, `allow`, `allowfullscreen`, `referrerpolicy`, `sandbox`, `scrolling="no"`. Everything else is dropped: `srcdoc`, every `on*` handler, `style`, `class`, `id`, `name` and `loading`.
523
+ - **Rejected `src`:** `http:`, `javascript:`, `data:`, `blob:`, a relative URL, and a URL with a user name or password. Also rejected: a backslash, a percent-encoded or non-ASCII host, a dot segment (`/./` or `/../`, also escaped), `//` in the path, a percent-escaped unreserved character in the path (`%7E`), and a malformed `%` escape in the query. The code is then not a generic embed. A `//host/…` URL becomes `https:`.
524
+ - **`allow`** keeps only `autoplay`, `fullscreen`, `encrypted-media`, `picture-in-picture`, `clipboard-write` and `web-share`. Camera, microphone, geolocation, payment and every other feature are dropped, because a delegated permission is granted in your site's name. A feature keeps its origin list only when every origin is `*`, `'self'`, `'src'`, `'none'` or an `https:` origin.
525
+ - **`referrerpolicy`** keeps only `no-referrer`, `origin`, `same-origin`, `strict-origin` and `strict-origin-when-cross-origin`. Other policies would send the page's URL to the frame, so the browser default applies instead.
526
+ - **`sandbox`** keeps only the spec's keywords.
527
+ - **Size**, from the first source that has one: the iframe's `width` and `height` attributes; then `px` values in its inline `style`, as Bandcamp's code has them; then the padding-bottom ratio of one wrapper, as Loom's code has it. A numeric `width` and `height` give a box of that ratio, at most that wide. A numeric `height` with a percentage or no `width` gives full width at that height. A numeric `width` alone gives 16:9, at most that wide. No size gives 16:9.
528
+ - **Title:** the code's `title`, else `Embedded content`.
529
+ - **Loading** is as for other iframe embeds: created near the viewport, a placeholder until `load`, and after 15 s without a `load`, `onError` reports `social-embeds: {title} did not load`.
530
+ - **No height messages.** Chart embeds that resize themselves (Datawrapper, Flourish, Infogram) keep the height in their code.
531
+
532
+ ```tsx
533
+ import { GenericIframeEmbed } from 'social-embeds';
534
+ import { parseIframe } from 'social-embeds/parser';
535
+
536
+ <GenericIframeEmbed html={code} maxWidth={640} />;
537
+
538
+ // Or parse once, on the server or in your CMS
539
+ const embed = parseIframe(code);
540
+ embed && <GenericIframeEmbed embed={embed} />;
541
+ ```
542
+
543
+ `GenericIframeEmbed` takes the [shared props](#shared-props) and no `url`.
544
+
545
+ **Behaviour change in 0.7.0:** iframe code that `<SocialEmbed>` used to hand to `fallback`, and that `<social-embed>` answered with an `error` event, now renders. Non-iframe code and rejected iframes still reach `fallback` or `error`.
546
+
451
547
  ### Not supported
452
548
 
453
549
  - Redirecting short links: `fb.watch/…`, Facebook share links (`/share/p/…`, `/share/v/…`), `vm.tiktok.com/…`, `vt.tiktok.com/…`, `redd.it/…`, Reddit share links (`/r/{sub}/s/…`), `pin.it/…`, `lnkd.in/…`, `t.snapchat.com/…`, `spotify.link/…`, `spotify.app.link/…`, `on.soundcloud.com/…` and `gph.is/…`. A redirect cannot be followed without a network request, and the package makes none. `matchUrl` returns `null`.
@@ -456,7 +552,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
456
552
 
457
553
  ## Without React
458
554
 
459
- `social-embeds/element` defines `<social-embed>`, a custom element for plain HTML, CMS templates, Vue, Svelte and Angular. It is one self-contained file with no React in it, about 20 KB gzipped.
555
+ `social-embeds/element` defines `<social-embed>`, a custom element for plain HTML, CMS templates, Vue, Svelte and Angular. It is one self-contained file with no React in it, about 25 KB gzipped.
460
556
 
461
557
  ```html
462
558
  <script
@@ -561,7 +657,7 @@ Client navigation needs nothing extra: each platform script loads once per page,
561
657
 
562
658
  - **Embed code with fallback content** (X, Instagram, Threads, Facebook SDK code with a blockquote): the server HTML contains the platform's blockquote with its whitelisted content, such as the post text, author and link. No placeholder is shown. On the client, the platform script turns it into the post.
563
659
  - **URLs and embed code without fallback content**: the server HTML contains the sized wrapper and the placeholder.
564
- - **Iframe embeds** (YouTube, TikTok, Facebook video embed code, Telegram, Snapchat, LinkedIn, Reddit, Spotify, Vimeo, Twitch, Dailymotion): the iframe is added on the client, so `onLoad` can never be missed. Without JavaScript only the placeholder shows.
660
+ - **Iframe embeds** (YouTube, TikTok, Facebook video embed code, Telegram, Snapchat, LinkedIn, Reddit, Spotify, Vimeo, Twitch, Dailymotion, Tenor, Streamable, Rumble, Flickr, Truth Social, Imgur, Strava and generic iframes): the iframe is added on the client, so `onLoad` can never be missed. Without JavaScript only the placeholder shows.
565
661
  - **Pinterest**: the server HTML contains the pin's empty link and the placeholder.
566
662
  - The server HTML never contains a platform `<script>`.
567
663