social-embeds 0.8.0 → 0.9.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 (44) hide show
  1. package/README.md +91 -48
  2. package/dist/components/hooks.js +3 -1
  3. package/dist/components/platforms.d.ts +32 -0
  4. package/dist/components/platforms.js +384 -0
  5. package/dist/components/script-embed.js +8 -7
  6. package/dist/components/social-embed.d.ts +31 -4
  7. package/dist/components/social-embed.js +48 -211
  8. package/dist/core/drivers.js +8 -1
  9. package/dist/core/plans/youtube.js +15 -3
  10. package/dist/element.d.ts +1 -1
  11. package/dist/element.js +1 -1
  12. package/dist/index.d.ts +21 -20
  13. package/dist/index.js +3 -2
  14. package/dist/loader/load-script.js +2 -0
  15. package/dist/parser/frames.js +70 -0
  16. package/dist/parser/html.d.ts +19 -0
  17. package/dist/parser/iframe.js +2 -2
  18. package/dist/parser/match-url.js +6 -2
  19. package/dist/parser/parse-embed.js +14 -10
  20. package/dist/parser/platform.d.ts +26 -0
  21. package/dist/parser/platforms/applemusic.js +3 -3
  22. package/dist/parser/platforms/applepodcasts.js +3 -3
  23. package/dist/parser/platforms/dailymotion.js +6 -8
  24. package/dist/parser/platforms/facebook.js +5 -9
  25. package/dist/parser/platforms/giphy.js +6 -6
  26. package/dist/parser/platforms/kick.js +4 -4
  27. package/dist/parser/platforms/linkedin.js +4 -4
  28. package/dist/parser/platforms/pinterest.js +3 -3
  29. package/dist/parser/platforms/reddit.js +3 -2
  30. package/dist/parser/platforms/rumble.js +3 -2
  31. package/dist/parser/platforms/soundcloud.js +3 -3
  32. package/dist/parser/platforms/spotify.js +4 -4
  33. package/dist/parser/platforms/streamable.js +3 -2
  34. package/dist/parser/platforms/tenor.js +3 -2
  35. package/dist/parser/platforms/tiktok.js +6 -6
  36. package/dist/parser/platforms/truthsocial.js +2 -1
  37. package/dist/parser/platforms/tumblr.js +4 -2
  38. package/dist/parser/platforms/twitch.js +6 -7
  39. package/dist/parser/platforms/vimeo.js +31 -12
  40. package/dist/parser/platforms/x.js +1 -1
  41. package/dist/parser/platforms/youtube.js +73 -23
  42. package/dist/parser/url.d.ts +6 -0
  43. package/dist/parser/url.js +1 -1
  44. 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` | 7 KB |
111
+ | `youtube`, `x` | 10 KB |
112
+ | `youtube`, `x`, `instagram`, `facebook`, `tiktok` | 13 KB |
113
+ | the same five and `genericIframe` | 15 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 6 KB gzipped to an app, against about 27 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 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: …`.
89
125
 
90
126
  ```tsx
91
127
  import {
@@ -311,47 +347,52 @@ A component checks an `embed` before using it: its `url` must be the exact URL `
311
347
 
312
348
  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`.
313
349
 
350
+ Instagram's and Threads' script scans only the document, so their embeds cannot render inside another component's shadow root (Lit, Stencil): `onError` reports that at once. X, Facebook and Pinterest embeds work there.
351
+
352
+ The scripts the package adds carry the nonce of the page's first `<script nonce>`, so a nonce-based Content Security Policy needs no `'strict-dynamic'` for them.
353
+
314
354
  When a script-based embed fails for good, its placeholder goes, as an iframe's does: a URL leaves a "View this post on {Platform}" link to the post, and embed code keeps its fallback content. A platform `<script>` tag already in the page whose platform never appears, such as one written through `innerHTML` or `dangerouslySetInnerHTML` (those never run), holds an embed back for at most 3 s after the page's `load` event; the package then adds its own tag.
315
355
 
316
356
  ## Platforms
317
357
 
318
- | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
319
- | -------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
320
- | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, also with `/photo/{n}` or `/video/{n}`, `x.com/i/web/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 |
321
- | 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 |
322
- | 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 |
323
- | 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 |
324
- | TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
325
- | 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 |
326
- | 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 |
327
- | Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
328
- | 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 |
329
- | 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 |
330
- | 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 |
331
- | 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 |
332
- | 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 |
333
- | 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 |
334
- | 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 |
335
- | 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 |
336
- | 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 |
337
- | 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 |
338
- | 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 |
339
- | 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 |
340
- | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
341
- | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/stickers/…`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/{file}` (also after a `v1.…` segment), `i.giphy.com/{id}.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
342
- | 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 |
343
- | 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 |
344
- | 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 |
345
- | Streamable | iframe (`streamable.com/e/{id}`) | `streamable.com/{id}` (also with a trailing `/`), `streamable.com/e/{id}`, `streamable.com/o/{id}` | `loop`, `autoplay`, `nocontrols`, `hd`, `muted`; the ratio from the wrapper or the iframe | none |
346
- | 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) |
347
- | 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) |
348
- | Rumble | iframe (`rumble.com/embed/{id}/`) | `rumble.com/embed/{id}/` only: see [Rumble](#rumble) | `pub`, `width`, `height` | none |
358
+ | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
359
+ | -------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
360
+ | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, also with `/photo/{n}` or `/video/{n}`, `x.com/i/web/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 |
361
+ | 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 |
362
+ | 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 |
363
+ | 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 |
364
+ | TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
365
+ | YouTube | iframe | `youtube.com/watch?v={id}`, `youtu.be/{id}`, `/shorts/{id}`, `/embed/{id}`, `/live/{id}`, `youtube-nocookie.com/embed/{id}`, playlists `/playlist?list={id}`, a channel's stream `/channel/{UC…}/live`; `t`, `start` and `#t=` are kept | every player query parameter; the youtube-nocookie.com host | none |
366
+ | 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 |
367
+ | Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
368
+ | 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 |
369
+ | 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 |
370
+ | 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 |
371
+ | 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 |
372
+ | 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 |
373
+ | 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 |
374
+ | 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 |
375
+ | 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 |
376
+ | 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 |
377
+ | 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 |
378
+ | 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 |
379
+ | 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 |
380
+ | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
381
+ | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/stickers/…`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/{file}` (also after a `v1.…` segment), `i.giphy.com/{id}.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
382
+ | 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 |
383
+ | 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 |
384
+ | 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 |
385
+ | Streamable | iframe (`streamable.com/e/{id}`) | `streamable.com/{id}` (also with a trailing `/`), `streamable.com/e/{id}`, `streamable.com/o/{id}` | `loop`, `autoplay`, `nocontrols`, `hd`, `muted`; the ratio from the wrapper or the iframe | none |
386
+ | 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) |
387
+ | 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) |
388
+ | Rumble | iframe (`rumble.com/embed/{id}/`) | `rumble.com/embed/{id}/` only: see [Rumble](#rumble) | `pub`, `width`, `height` | none |
349
389
 
350
390
  URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.` and `web.`.
351
391
 
352
392
  ### X
353
393
 
354
394
  - The post that renders is the one the blockquote links to.
395
+ - Older video code (`blockquote.twitter-video`) renders like a post.
355
396
  - widgets.js loads from `platform.twitter.com`; a host page that already loaded it from `platform.x.com` or `platform.twitter.com` is reused.
356
397
 
357
398
  ### Instagram
@@ -387,14 +428,14 @@ The rules:
387
428
 
388
429
  URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `facebook.com` and `m.facebook.com`:
389
430
 
390
- | Kind | Shapes |
391
- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
392
- | Post | `/{user}/posts/{id}`, `/{user}/posts/pfbid…`, `/permalink.php?story_fbid={id}&id={owner}`, `/story.php?story_fbid={id}&id={owner}`, `/photo.php?fbid={id}`, `/photo/?fbid={id}`, `/{user}/photos/{album}/{fbid}/` |
393
- | Video | `/{page}/videos/{id}`, `/{page}/videos/{slug}/{id}/`, `/watch/?v={id}`, `/video.php?v={id}`, `/reel/{id}` |
431
+ | Kind | Shapes |
432
+ | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
433
+ | Post | `/{user}/posts/{id}`, `/{user}/posts/pfbid…`, `/permalink.php?story_fbid={id}&id={owner}`, `/story.php?story_fbid={id}&id={owner}`, `/photo.php?fbid={id}`, `/photo/?fbid={id}`, `/{user}/photos/{album}/{fbid}/`, also photostream albums (`pb.{id}.-2207520000`) |
434
+ | Video | `/{page}/videos/{id}`, `/{page}/videos/{slug}/{id}/`, `/watch/?v={id}`, `/video.php?v={id}`, `/reel/{id}` |
394
435
 
395
436
  - One SDK serves the whole page, so the first `locale` requested wins.
396
437
  - The SDK loads with `xfbml=0` and parses only the embed's own element, so it never scans the rest of the page. An SDK the host page already loaded is reused.
397
- - Instagram's and Threads' scripts do nothing on a page where the Facebook SDK has already loaded; the loader works around that. If your page loads both the SDK and Instagram's script itself, load Instagram's first.
438
+ - Instagram's and Threads' scripts do nothing on a page where the Facebook SDK has already loaded; the loader works around that, also when your page loads both scripts itself.
398
439
  - A removed post shows Facebook's "no longer available" notice.
399
440
 
400
441
  ### TikTok
@@ -431,6 +472,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
431
472
  - The address of the host page is not sent to Reddit (Reddit's script sends it as `embed_host_url`; the embed works without it).
432
473
  - Reddit may machine-translate the post into the visitor's language; `locale` sets the language.
433
474
  - No fallback content: Reddit's embed code holds only the title, author and subreddit links.
475
+ - Reddit's older card code (`blockquote.reddit-card` with `embed.redditmedia.com/widgets/platform.js`) renders the same post.
434
476
 
435
477
  ### Pinterest
436
478
 
@@ -449,6 +491,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
449
491
 
450
492
  - Vimeo's responsive embed code (a `div` with `padding:56.25% 0 0 0;position:relative;` around the iframe, then `player.js`) is recognised, and the padding is read as the video's aspect ratio. `player.js` is not loaded: the package sizes the frame itself.
451
493
  - An unlisted video keeps its hash, from the URL or from the iframe's `h`.
494
+ - Older embed code that ends with a credit paragraph ("{title} from {user} on Vimeo.") is accepted; the credit is not rendered.
452
495
 
453
496
  ### Twitch
454
497
 
@@ -486,7 +529,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
486
529
 
487
530
  ### Tumblr
488
531
 
489
- - Tumblr's embed code names the post by a token; the package renders it by blog name, which the post link in the same code gives, so URLs work too.
532
+ - Tumblr's embed code names the post by a token; the package renders it by blog name, which the post link in the same code gives, so URLs work too. Older code, without `/v2` in `data-href` or loading `secure.assets.tumblr.com/post.js`, is accepted.
490
533
 
491
534
  ### Kick and Giphy
492
535
 
@@ -581,21 +624,21 @@ Embed code goes in a `<template>`, which keeps the platform's own `<script>` fro
581
624
  </social-embed>
582
625
  ```
583
626
 
584
- | Attribute / property | Meaning |
585
- | -------------------------- | ------------------------------------------------------------------------------- |
586
- | `html` | Embed code. Usually set as a property (below). |
587
- | `url` | A post URL. |
588
- | `width` | A number means pixels; otherwise any CSS length. |
589
- | `max-width` / `maxWidth` | Pixels: `400` or `400px`. |
590
- | `height` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
591
- | `max-height` / `maxHeight` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
592
- | `eager` | Load at once instead of when near the viewport (the inverse of React's `lazy`). |
627
+ | Attribute / property | Meaning |
628
+ | -------------------------- | ------------------------------------------------------------------------------------------------------- |
629
+ | `html` | Embed code. Usually set as a property (below). |
630
+ | `url` | A post URL. |
631
+ | `width` | A number means pixels; otherwise any CSS length. |
632
+ | `max-width` / `maxWidth` | Pixels: `400` or `400px`. |
633
+ | `height` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
634
+ | `max-height` / `maxHeight` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
635
+ | `eager` | Load at once instead of when near the viewport (the inverse of React's `lazy`); `eager="false"` is off. |
593
636
 
594
637
  Each property reflects its attribute, so framework property bindings such as Angular's `[url]` work. `url` and the size properties take a string, and `null` removes the attribute; `eager` takes a boolean.
595
638
 
596
639
  The `html` property takes embed code from script. From a framework, pass embed code this way: a `<template>` the framework renders keeps its children in `childNodes`, not in `content`, where the element reads them. Before the tag is defined, React 19, Vue and Svelte write `html` as an attribute, and server HTML can carry it that way too; the element reads that attribute. When several inputs are set, the `html` property wins over the `html` attribute, which wins over the `<template>`, which wins over `url`. Options come only from the embed code, as with `<SocialEmbed>`, and the element renders into the light DOM. The element has no `playerId`, so Dailymotion needs embed code that names a Player ID; a Dailymotion URL alone fires `error`.
597
640
 
598
- The element's own children other than `<template>` are never rendered and never moved, so a framework that renders children into it keeps owning them. Copies of them, taken each time the embed starts, are the placeholder until it loads; without any, a neutral skeleton shows. The embed renders into a `<div slot="embed">` in the light DOM, which a shadow root holding only that slot shows; the `embed` slot name is the element's own. If other code removes that `<div>`, for example a framework setting a text child or a DOM morph, the embed starts again. If the element connects while the document is still loading, it waits for `DOMContentLoaded` before reading its children.
641
+ The element's own children other than `<template>` are never rendered and never moved, so a framework that renders children into it keeps owning them. Copies of them, taken each time the embed starts and without their `id`s, are the placeholder until it loads; without any, a neutral skeleton shows. Embed code written straight inside the element, without a `<template>` (as a CMS that strips `<template>` leaves it), is used as `html` when there is no other input. Changing `width`, `max-width`, `height` or `max-height` restyles the embed in place; only a new `url` or `html` starts it again. The embed renders into a `<div slot="embed">` in the light DOM, which a shadow root holding only that slot shows; the `embed` slot name is the element's own. If other code removes that `<div>`, for example a framework setting a text child or a DOM morph, the embed starts again. If the element connects while the document is still loading, it waits for `DOMContentLoaded` before reading its children.
599
642
 
600
643
  It dispatches `load` (an `Event`) when the platform has rendered, and `error` (an `ErrorEvent`) when it cannot. `error.error` is an `Error` with the same message as React's `onError`. Neither event bubbles, both fire in a microtask, and only while the element is connected.
601
644
 
@@ -26,11 +26,13 @@ function useNearViewport(ref, lazy) {
26
26
  /** Calls `onError` from an effect, once per distinct message. */
27
27
  function useReportError(message, onError) {
28
28
  const latest = useRef(onError);
29
+ const reported = useRef(void 0);
29
30
  useEffect(() => {
30
31
  latest.current = onError;
31
32
  });
32
33
  useEffect(() => {
33
- if (message !== void 0) latest.current?.(new Error(message));
34
+ if (message !== void 0 && message !== reported.current) latest.current?.(new Error(message));
35
+ reported.current = message;
34
36
  }, [message]);
35
37
  }
36
38
  export { useNearViewport, useReportError };
@@ -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;