social-embeds 0.7.1 → 0.8.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 (176) hide show
  1. package/README.md +63 -51
  2. package/dist/components/apple-embed.d.ts +7 -0
  3. package/dist/components/apple-embed.js +39 -0
  4. package/dist/components/bluesky-embed.d.ts +10 -0
  5. package/dist/components/bluesky-embed.js +27 -0
  6. package/dist/components/dailymotion-embed.d.ts +9 -0
  7. package/dist/components/dailymotion-embed.js +30 -0
  8. package/dist/components/facebook-embed.d.ts +6 -0
  9. package/dist/components/facebook-embed.js +40 -0
  10. package/dist/components/flickr-embed.d.ts +6 -0
  11. package/dist/components/flickr-embed.js +27 -0
  12. package/dist/components/generic-iframe-embed.d.ts +11 -0
  13. package/dist/components/generic-iframe-embed.js +26 -0
  14. package/dist/components/giphy-embed.d.ts +4 -0
  15. package/dist/components/giphy-embed.js +22 -0
  16. package/dist/components/hooks.js +38 -0
  17. package/dist/components/iframe-embed.js +169 -0
  18. package/dist/components/imgur-embed.d.ts +6 -0
  19. package/dist/components/imgur-embed.js +23 -0
  20. package/dist/components/instagram-embed.d.ts +5 -0
  21. package/dist/components/instagram-embed.js +25 -0
  22. package/dist/components/kick-embed.d.ts +6 -0
  23. package/dist/components/kick-embed.js +25 -0
  24. package/dist/components/linkedin-embed.d.ts +6 -0
  25. package/dist/components/linkedin-embed.js +23 -0
  26. package/dist/components/pinterest-embed.d.ts +5 -0
  27. package/dist/components/pinterest-embed.js +25 -0
  28. package/dist/components/reddit-embed.d.ts +6 -0
  29. package/dist/components/reddit-embed.js +29 -0
  30. package/dist/components/rumble-embed.d.ts +4 -0
  31. package/dist/components/rumble-embed.js +22 -0
  32. package/dist/components/script-embed.js +108 -0
  33. package/dist/components/shared.d.ts +29 -0
  34. package/dist/components/snapchat-embed.d.ts +4 -0
  35. package/dist/components/snapchat-embed.js +22 -0
  36. package/dist/components/social-embed.d.ts +60 -0
  37. package/dist/components/social-embed.js +221 -0
  38. package/dist/components/soundcloud-embed.d.ts +6 -0
  39. package/dist/components/soundcloud-embed.js +33 -0
  40. package/dist/components/spotify-embed.d.ts +9 -0
  41. package/dist/components/spotify-embed.js +25 -0
  42. package/dist/components/strava-embed.d.ts +6 -0
  43. package/dist/components/strava-embed.js +26 -0
  44. package/dist/components/streamable-embed.d.ts +6 -0
  45. package/dist/components/streamable-embed.js +28 -0
  46. package/dist/components/telegram-embed.d.ts +6 -0
  47. package/dist/components/telegram-embed.js +27 -0
  48. package/dist/components/tenor-embed.d.ts +4 -0
  49. package/dist/components/tenor-embed.js +22 -0
  50. package/dist/components/threads-embed.d.ts +5 -0
  51. package/dist/components/threads-embed.js +25 -0
  52. package/dist/components/tiktok-embed.d.ts +6 -0
  53. package/dist/components/tiktok-embed.js +37 -0
  54. package/dist/components/truthsocial-embed.d.ts +4 -0
  55. package/dist/components/truthsocial-embed.js +22 -0
  56. package/dist/components/tumblr-embed.d.ts +4 -0
  57. package/dist/components/tumblr-embed.js +22 -0
  58. package/dist/components/twitch-embed.d.ts +6 -0
  59. package/dist/components/twitch-embed.js +26 -0
  60. package/dist/components/vimeo-embed.d.ts +5 -0
  61. package/dist/components/vimeo-embed.js +40 -0
  62. package/dist/components/x-embed.d.ts +5 -0
  63. package/dist/components/x-embed.js +32 -0
  64. package/dist/components/youtube-embed.d.ts +5 -0
  65. package/dist/components/youtube-embed.js +43 -0
  66. package/dist/core/drivers.js +125 -0
  67. package/dist/core/layout.js +73 -0
  68. package/dist/core/markup.js +30 -0
  69. package/dist/core/params.js +26 -0
  70. package/dist/core/plans/apple.js +44 -0
  71. package/dist/core/plans/bluesky.d.ts +3 -0
  72. package/dist/core/plans/bluesky.js +34 -0
  73. package/dist/core/plans/dailymotion.d.ts +8 -0
  74. package/dist/core/plans/dailymotion.js +37 -0
  75. package/dist/core/plans/facebook.d.ts +15 -0
  76. package/dist/core/plans/facebook.js +79 -0
  77. package/dist/core/plans/flickr.d.ts +7 -0
  78. package/dist/core/plans/flickr.js +37 -0
  79. package/dist/core/plans/generic.js +44 -0
  80. package/dist/core/plans/giphy.js +16 -0
  81. package/dist/core/plans/imgur.d.ts +4 -0
  82. package/dist/core/plans/imgur.js +34 -0
  83. package/dist/core/plans/instagram.d.ts +4 -0
  84. package/dist/core/plans/instagram.js +26 -0
  85. package/dist/core/plans/kick.d.ts +5 -0
  86. package/dist/core/plans/kick.js +22 -0
  87. package/dist/core/plans/linkedin.d.ts +4 -0
  88. package/dist/core/plans/linkedin.js +23 -0
  89. package/dist/core/plans/pinterest.d.ts +4 -0
  90. package/dist/core/plans/pinterest.js +31 -0
  91. package/dist/core/plans/reddit.d.ts +11 -0
  92. package/dist/core/plans/reddit.js +46 -0
  93. package/dist/core/plans/rumble.js +21 -0
  94. package/dist/core/plans/snapchat.js +20 -0
  95. package/dist/core/plans/soundcloud.d.ts +14 -0
  96. package/dist/core/plans/soundcloud.js +37 -0
  97. package/dist/core/plans/spotify.d.ts +4 -0
  98. package/dist/core/plans/spotify.js +29 -0
  99. package/dist/core/plans/strava.d.ts +8 -0
  100. package/dist/core/plans/strava.js +38 -0
  101. package/dist/core/plans/streamable.d.ts +8 -0
  102. package/dist/core/plans/streamable.js +31 -0
  103. package/dist/core/plans/telegram.d.ts +10 -0
  104. package/dist/core/plans/telegram.js +59 -0
  105. package/dist/core/plans/tenor.js +16 -0
  106. package/dist/core/plans/threads.d.ts +4 -0
  107. package/dist/core/plans/threads.js +25 -0
  108. package/dist/core/plans/tiktok.d.ts +17 -0
  109. package/dist/core/plans/tiktok.js +36 -0
  110. package/dist/core/plans/truthsocial.js +43 -0
  111. package/dist/core/plans/tumblr.js +29 -0
  112. package/dist/core/plans/twitch.d.ts +7 -0
  113. package/dist/core/plans/twitch.js +38 -0
  114. package/dist/core/plans/vimeo.d.ts +23 -0
  115. package/dist/core/plans/vimeo.js +42 -0
  116. package/dist/core/plans/x.d.ts +12 -0
  117. package/dist/core/plans/x.js +31 -0
  118. package/dist/core/plans/youtube.d.ts +25 -0
  119. package/dist/core/plans/youtube.js +59 -0
  120. package/dist/core/post-link.js +19 -0
  121. package/dist/core/resolve.js +57 -0
  122. package/dist/core/timing.js +7 -0
  123. package/dist/element.d.ts +1 -1
  124. package/dist/element.js +1 -1
  125. package/dist/index.d.ts +53 -344
  126. package/dist/index.js +30 -2575
  127. package/dist/loader/load-script.js +116 -0
  128. package/dist/loader/platform-scripts.js +89 -0
  129. package/dist/parser/frames.js +70 -0
  130. package/dist/parser/html.js +172 -0
  131. package/dist/parser/iframe.d.ts +24 -0
  132. package/dist/parser/iframe.js +151 -0
  133. package/dist/parser/lookup.js +20 -0
  134. package/dist/parser/match-url.d.ts +3 -0
  135. package/dist/parser/match-url.js +22 -0
  136. package/dist/parser/parse-embed.d.ts +7 -0
  137. package/dist/parser/parse-embed.js +69 -0
  138. package/dist/parser/platform.js +60 -0
  139. package/dist/parser/platforms/applemusic.js +45 -0
  140. package/dist/parser/platforms/applepodcasts.js +41 -0
  141. package/dist/parser/platforms/bluesky.js +64 -0
  142. package/dist/parser/platforms/dailymotion.js +57 -0
  143. package/dist/parser/platforms/facebook.js +181 -0
  144. package/dist/parser/platforms/flickr.js +134 -0
  145. package/dist/parser/platforms/giphy.js +68 -0
  146. package/dist/parser/platforms/imgur.js +107 -0
  147. package/dist/parser/platforms/index.js +62 -0
  148. package/dist/parser/platforms/instagram.js +59 -0
  149. package/dist/parser/platforms/kick.js +61 -0
  150. package/dist/parser/platforms/linkedin.js +42 -0
  151. package/dist/parser/platforms/pinterest.js +59 -0
  152. package/dist/parser/platforms/reddit.js +69 -0
  153. package/dist/parser/platforms/rumble.js +44 -0
  154. package/dist/parser/platforms/snapchat.js +87 -0
  155. package/dist/parser/platforms/soundcloud.js +128 -0
  156. package/dist/parser/platforms/spotify.js +51 -0
  157. package/dist/parser/platforms/strava.js +55 -0
  158. package/dist/parser/platforms/streamable.js +95 -0
  159. package/dist/parser/platforms/telegram.js +61 -0
  160. package/dist/parser/platforms/tenor.js +79 -0
  161. package/dist/parser/platforms/threads.js +51 -0
  162. package/dist/parser/platforms/tiktok.js +48 -0
  163. package/dist/parser/platforms/truthsocial.js +50 -0
  164. package/dist/parser/platforms/tumblr.js +72 -0
  165. package/dist/parser/platforms/twitch.js +128 -0
  166. package/dist/parser/platforms/vimeo.js +95 -0
  167. package/dist/parser/platforms/x.js +65 -0
  168. package/dist/parser/platforms/youtube.js +140 -0
  169. package/dist/parser/types.d.ts +14 -0
  170. package/dist/parser/url.js +41 -0
  171. package/dist/parser/verify.js +63 -0
  172. package/dist/parser.d.ts +4 -1
  173. package/dist/parser.js +4 -1
  174. package/package.json +1 -1
  175. package/dist/index-DrMHAkyG.d.ts +0 -46
  176. package/dist/parser-CovaPg5T.js +0 -2585
package/README.md CHANGED
@@ -85,6 +85,8 @@ Before 0.7.0, iframe code that no platform claimed reached `fallback`. It now re
85
85
 
86
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.
87
87
 
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: …`.
89
+
88
90
  ```tsx
89
91
  import {
90
92
  AppleMusicEmbed,
@@ -309,45 +311,52 @@ A component checks an `embed` before using it: its `url` must be the exact URL `
309
311
 
310
312
  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`.
311
313
 
314
+ 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.
315
+
316
+ 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.
317
+
318
+ 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.
319
+
312
320
  ## Platforms
313
321
 
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 |
345
-
346
- URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
322
+ | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
323
+ | -------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
324
+ | 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 |
325
+ | 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 |
326
+ | 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 |
327
+ | 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 |
328
+ | TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
329
+ | 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 |
330
+ | 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 |
331
+ | Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
332
+ | 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 |
333
+ | 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 |
334
+ | 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 |
335
+ | 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 |
336
+ | 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 |
337
+ | 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 |
338
+ | 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 |
339
+ | 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 |
340
+ | 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 |
341
+ | 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 |
342
+ | 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 |
343
+ | 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 |
344
+ | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
345
+ | 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 |
346
+ | 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 |
347
+ | 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 |
348
+ | 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 |
349
+ | 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 |
350
+ | 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) |
351
+ | 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) |
352
+ | Rumble | iframe (`rumble.com/embed/{id}/`) | `rumble.com/embed/{id}/` only: see [Rumble](#rumble) | `pub`, `width`, `height` | none |
353
+
354
+ URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.` and `web.`.
347
355
 
348
356
  ### X
349
357
 
350
358
  - The post that renders is the one the blockquote links to.
359
+ - Older video code (`blockquote.twitter-video`) renders like a post.
351
360
  - widgets.js loads from `platform.twitter.com`; a host page that already loaded it from `platform.x.com` or `platform.twitter.com` is reused.
352
361
 
353
362
  ### Instagram
@@ -383,14 +392,14 @@ The rules:
383
392
 
384
393
  URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `facebook.com` and `m.facebook.com`:
385
394
 
386
- | Kind | Shapes |
387
- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
388
- | 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}/` |
389
- | Video | `/{page}/videos/{id}`, `/{page}/videos/{slug}/{id}/`, `/watch/?v={id}`, `/video.php?v={id}`, `/reel/{id}` |
395
+ | Kind | Shapes |
396
+ | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
397
+ | 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`) |
398
+ | Video | `/{page}/videos/{id}`, `/{page}/videos/{slug}/{id}/`, `/watch/?v={id}`, `/video.php?v={id}`, `/reel/{id}` |
390
399
 
391
400
  - One SDK serves the whole page, so the first `locale` requested wins.
392
401
  - 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.
393
- - 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.
402
+ - 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.
394
403
  - A removed post shows Facebook's "no longer available" notice.
395
404
 
396
405
  ### TikTok
@@ -427,6 +436,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
427
436
  - 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).
428
437
  - Reddit may machine-translate the post into the visitor's language; `locale` sets the language.
429
438
  - No fallback content: Reddit's embed code holds only the title, author and subreddit links.
439
+ - Reddit's older card code (`blockquote.reddit-card` with `embed.redditmedia.com/widgets/platform.js`) renders the same post.
430
440
 
431
441
  ### Pinterest
432
442
 
@@ -445,6 +455,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
445
455
 
446
456
  - 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.
447
457
  - An unlisted video keeps its hash, from the URL or from the iframe's `h`.
458
+ - Older embed code that ends with a credit paragraph ("{title} from {user} on Vimeo.") is accepted; the credit is not rendered.
448
459
 
449
460
  ### Twitch
450
461
 
@@ -482,7 +493,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
482
493
 
483
494
  ### Tumblr
484
495
 
485
- - 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.
496
+ - 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.
486
497
 
487
498
  ### Kick and Giphy
488
499
 
@@ -552,12 +563,12 @@ embed && <GenericIframeEmbed embed={embed} />;
552
563
 
553
564
  ## Without React
554
565
 
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.
566
+ `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 26 KB gzipped.
556
567
 
557
568
  ```html
558
569
  <script
559
570
  type="module"
560
- src="https://cdn.jsdelivr.net/npm/social-embeds@0.6.0/dist/element.js"
571
+ src="https://cdn.jsdelivr.net/npm/social-embeds@0.8.0/dist/element.js"
561
572
  integrity="sha384-…"
562
573
  crossorigin="anonymous"
563
574
  ></script>
@@ -577,20 +588,21 @@ Embed code goes in a `<template>`, which keeps the platform's own `<script>` fro
577
588
  </social-embed>
578
589
  ```
579
590
 
580
- | Attribute / property | Meaning |
581
- | -------------------------- | ------------------------------------------------------------------------------- |
582
- | `url` | A post URL. |
583
- | `width` | A number means pixels; otherwise any CSS length. |
584
- | `max-width` / `maxWidth` | Pixels: `400` or `400px`. |
585
- | `height` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
586
- | `max-height` / `maxHeight` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
587
- | `eager` | Load at once instead of when near the viewport (the inverse of React's `lazy`). |
591
+ | Attribute / property | Meaning |
592
+ | -------------------------- | ------------------------------------------------------------------------------------------------------- |
593
+ | `html` | Embed code. Usually set as a property (below). |
594
+ | `url` | A post URL. |
595
+ | `width` | A number means pixels; otherwise any CSS length. |
596
+ | `max-width` / `maxWidth` | Pixels: `400` or `400px`. |
597
+ | `height` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
598
+ | `max-height` / `maxHeight` | Pixels: `400` or `400px`. Reaches only iframe-based platforms, as in React. |
599
+ | `eager` | Load at once instead of when near the viewport (the inverse of React's `lazy`); `eager="false"` is off. |
588
600
 
589
601
  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.
590
602
 
591
- 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. When several inputs are set, `html` wins over the `<template>`, and the `<template>` 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`.
603
+ 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`.
592
604
 
593
- Child elements other than `<template>` are the placeholder until the embed loads; without any, a neutral skeleton shows. They are read once, when the element first connects; children added later are not a placeholder. If the element connects while the document is still loading, it waits for `DOMContentLoaded` before reading its children.
605
+ 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.
594
606
 
595
607
  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.
596
608
 
@@ -0,0 +1,7 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type AppleMusicEmbedProps = EmbedSource & FrameProps;
3
+ export type ApplePodcastsEmbedProps = EmbedSource & FrameProps;
4
+ /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
5
+ export declare function AppleMusicEmbed(props: AppleMusicEmbedProps): import("react").JSX.Element | null;
6
+ /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
7
+ export declare function ApplePodcastsEmbed(props: ApplePodcastsEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,39 @@
1
+ import { appleMusicPlan, applePodcastsPlan } from "../core/plans/apple.js";
2
+ import { applemusic } from "../parser/platforms/applemusic.js";
3
+ import { applepodcasts } from "../parser/platforms/applepodcasts.js";
4
+ import { useReportError } from "./hooks.js";
5
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
6
+ import { resolveEmbed } from "../core/resolve.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // src/components/apple-embed.tsx
9
+ /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
10
+ function AppleMusicEmbed(props) {
11
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
12
+ const { embed, error } = resolveEmbed(url, given, applemusic);
13
+ const plan = embed ? appleMusicPlan(embed) : void 0;
14
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
15
+ if (plan?.kind !== "iframe") return null;
16
+ return /* @__PURE__ */ jsx(IframeEmbed, {
17
+ ...frame,
18
+ ...planProps(plan),
19
+ onError,
20
+ maxWidth: maxWidth ?? plan.maxWidth,
21
+ height: height ?? plan.height
22
+ });
23
+ }
24
+ /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
25
+ function ApplePodcastsEmbed(props) {
26
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
27
+ const { embed, error } = resolveEmbed(url, given, applepodcasts);
28
+ const plan = embed ? applePodcastsPlan(embed) : void 0;
29
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
30
+ if (plan?.kind !== "iframe") return null;
31
+ return /* @__PURE__ */ jsx(IframeEmbed, {
32
+ ...frame,
33
+ ...planProps(plan),
34
+ onError,
35
+ maxWidth: maxWidth ?? plan.maxWidth,
36
+ height: height ?? plan.height
37
+ });
38
+ }
39
+ export { AppleMusicEmbed, ApplePodcastsEmbed };
@@ -0,0 +1,10 @@
1
+ import { BlueskyOptions } from "../core/plans/bluesky.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type BlueskyEmbedProps = EmbedSource & Omit<SharedProps, keyof BlueskyOptions> & BlueskyOptions;
4
+ /**
5
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
6
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
7
+ * render: a handle URL needs a lookup, and `onError` says so.
8
+ */
9
+ export declare function BlueskyEmbed(props: BlueskyEmbedProps): import("react").JSX.Element | null;
10
+ export type { BlueskyOptions };
@@ -0,0 +1,27 @@
1
+ import { blueskyPlan } from "../core/plans/bluesky.js";
2
+ import { bluesky } from "../parser/platforms/bluesky.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, fallbackPlaceholder, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/bluesky-embed.tsx
8
+ /**
9
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
10
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
11
+ * render: a handle URL needs a lookup, and `onError` says so.
12
+ */
13
+ function BlueskyEmbed(props) {
14
+ const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
15
+ const { embed, error } = resolveEmbed(url, given, bluesky);
16
+ const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
17
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
18
+ if (plan?.kind !== "iframe") return null;
19
+ return /* @__PURE__ */ jsx(IframeEmbed, {
20
+ ...shared,
21
+ ...planProps(plan),
22
+ onError,
23
+ maxWidth: maxWidth ?? plan.maxWidth,
24
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
25
+ });
26
+ }
27
+ export { BlueskyEmbed };
@@ -0,0 +1,9 @@
1
+ import { DailymotionOptions } from "../core/plans/dailymotion.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type DailymotionEmbedProps = EmbedSource & Omit<FrameProps, keyof DailymotionOptions> & DailymotionOptions;
4
+ /**
5
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
6
+ * prop, never another account's (docs/decisions.md D63).
7
+ */
8
+ export declare function DailymotionEmbed(props: DailymotionEmbedProps): import("react").JSX.Element | null;
9
+ export type { DailymotionOptions };
@@ -0,0 +1,30 @@
1
+ import { dailymotion } from "../parser/platforms/dailymotion.js";
2
+ import { dailymotionPlan } from "../core/plans/dailymotion.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/dailymotion-embed.tsx
8
+ /**
9
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
10
+ * prop, never another account's (docs/decisions.md D63).
11
+ */
12
+ function DailymotionEmbed(props) {
13
+ const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
14
+ const { embed, error } = resolveEmbed(url, given, dailymotion);
15
+ const plan = embed ? dailymotionPlan(embed, {
16
+ playerId,
17
+ mute,
18
+ startTime,
19
+ loop
20
+ }) : void 0;
21
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
22
+ if (plan?.kind !== "iframe") return null;
23
+ return /* @__PURE__ */ jsx(IframeEmbed, {
24
+ ...frame,
25
+ ...planProps(plan),
26
+ onError,
27
+ maxWidth: maxWidth ?? plan.maxWidth
28
+ });
29
+ }
30
+ export { DailymotionEmbed };
@@ -0,0 +1,6 @@
1
+ import { FacebookOptions } from "../core/plans/facebook.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ /** `height` and `maxHeight` apply only to a video that renders as an iframe. */
4
+ export type FacebookEmbedProps = EmbedSource & Omit<FrameProps, keyof FacebookOptions> & FacebookOptions;
5
+ export declare function FacebookEmbed(props: FacebookEmbedProps): import("react").JSX.Element | null;
6
+ export type { FacebookOptions };
@@ -0,0 +1,40 @@
1
+ import { facebookPlan } from "../core/plans/facebook.js";
2
+ import { facebook } from "../parser/platforms/facebook.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { ScriptEmbed } from "./script-embed.js";
6
+ import { resolveEmbed } from "../core/resolve.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // src/components/facebook-embed.tsx
9
+ function FacebookEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
11
+ const { embed, error } = resolveEmbed(url, given, facebook);
12
+ const plan = embed ? facebookPlan(embed, {
13
+ locale,
14
+ showText,
15
+ allowfullscreen,
16
+ autoplay,
17
+ showCaptions
18
+ }) : void 0;
19
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
20
+ if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
21
+ ...shared,
22
+ ...planProps(plan),
23
+ onError,
24
+ maxWidth: maxWidth ?? plan.maxWidth,
25
+ height,
26
+ maxHeight
27
+ });
28
+ if (plan?.kind !== "script") return null;
29
+ return /* @__PURE__ */ jsx(ScriptEmbed, {
30
+ ...shared,
31
+ onError,
32
+ maxWidth: maxWidth ?? plan.maxWidth,
33
+ driver: plan.driver,
34
+ markup: plan.markup,
35
+ hasFallback: plan.hasFallback,
36
+ minHeight: plan.minHeight,
37
+ label: plan.label
38
+ }, plan.key);
39
+ }
40
+ export { FacebookEmbed };
@@ -0,0 +1,6 @@
1
+ import { FlickrOptions } from "../core/plans/flickr.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type FlickrEmbedProps = EmbedSource & Omit<FrameProps, keyof FlickrOptions> & FlickrOptions;
4
+ /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
5
+ export declare function FlickrEmbed(props: FlickrEmbedProps): import("react").JSX.Element | null;
6
+ export type { FlickrOptions };
@@ -0,0 +1,27 @@
1
+ import { flickrPlan } from "../core/plans/flickr.js";
2
+ import { flickr } from "../parser/platforms/flickr.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, fallbackPlaceholder, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/flickr-embed.tsx
8
+ /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
9
+ function FlickrEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, header, footer, context, placeholder, ...frame } = props;
11
+ const { embed, error } = resolveEmbed(url, given, flickr);
12
+ const plan = embed ? flickrPlan(embed, {
13
+ header,
14
+ footer,
15
+ context
16
+ }) : void 0;
17
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
18
+ if (plan?.kind !== "iframe") return null;
19
+ return /* @__PURE__ */ jsx(IframeEmbed, {
20
+ ...frame,
21
+ ...planProps(plan),
22
+ onError,
23
+ maxWidth: maxWidth ?? plan.maxWidth,
24
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
25
+ });
26
+ }
27
+ export { FlickrEmbed };
@@ -0,0 +1,11 @@
1
+ import { ParsedIframe } from "../parser/iframe.js";
2
+ import { FrameProps } from "./shared.js";
3
+ export type GenericIframeEmbedProps = ({
4
+ html: string;
5
+ embed?: never;
6
+ } | {
7
+ embed: ParsedIframe;
8
+ html?: never;
9
+ }) & FrameProps;
10
+ /** One iframe rebuilt from its checked attributes; nothing else in the code renders. */
11
+ export declare function GenericIframeEmbed(props: GenericIframeEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,26 @@
1
+ import { genericPlan } from "../core/plans/generic.js";
2
+ import { parseIframe } from "../parser/iframe.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { useMemo } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/generic-iframe-embed.tsx
8
+ /** One iframe rebuilt from its checked attributes; nothing else in the code renders. */
9
+ function GenericIframeEmbed(props) {
10
+ const { html, embed: given, onError, maxWidth, height, ...frame } = props;
11
+ const embed = useMemo(() => given ?? parseIframe(html), [given, html]);
12
+ const plan = embed ? genericPlan(embed) : {
13
+ kind: "error",
14
+ message: "social-embeds: not an iframe embed code"
15
+ };
16
+ useReportError(plan.kind === "error" ? plan.message : void 0, onError);
17
+ if (plan.kind !== "iframe") return null;
18
+ return /* @__PURE__ */ jsx(IframeEmbed, {
19
+ ...frame,
20
+ ...planProps(plan),
21
+ onError,
22
+ maxWidth: maxWidth ?? plan.maxWidth,
23
+ height: height ?? plan.height
24
+ });
25
+ }
26
+ export { GenericIframeEmbed };
@@ -0,0 +1,4 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type GiphyEmbedProps = EmbedSource & FrameProps;
3
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
4
+ export declare function GiphyEmbed(props: GiphyEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ import { giphyPlan } from "../core/plans/giphy.js";
2
+ import { giphy } from "../parser/platforms/giphy.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/giphy-embed.tsx
8
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
9
+ function GiphyEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
11
+ const { embed, error } = resolveEmbed(url, given, giphy);
12
+ const plan = embed ? giphyPlan(embed) : void 0;
13
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
+ if (plan?.kind !== "iframe") return null;
15
+ return /* @__PURE__ */ jsx(IframeEmbed, {
16
+ ...frame,
17
+ ...planProps(plan),
18
+ onError,
19
+ maxWidth: maxWidth ?? plan.maxWidth
20
+ });
21
+ }
22
+ export { GiphyEmbed };
@@ -0,0 +1,38 @@
1
+ import { ROOT_MARGIN } from "../core/timing.js";
2
+ import { useEffect, useRef, useState } from "react";
3
+ // src/components/hooks.ts
4
+ /** False on the server and in the first client render, so the markup matches on hydration. */
5
+ function useNearViewport(ref, lazy) {
6
+ const [near, setNear] = useState(false);
7
+ useEffect(() => {
8
+ const element = ref.current;
9
+ if (!lazy || !element || typeof IntersectionObserver === "undefined") {
10
+ setNear(true);
11
+ return;
12
+ }
13
+ const observer = new IntersectionObserver((entries) => {
14
+ if (entries.some((entry) => entry.isIntersecting)) {
15
+ setNear(true);
16
+ observer.disconnect();
17
+ }
18
+ }, { rootMargin: ROOT_MARGIN });
19
+ observer.observe(element);
20
+ return () => {
21
+ observer.disconnect();
22
+ };
23
+ }, [ref, lazy]);
24
+ return near;
25
+ }
26
+ /** Calls `onError` from an effect, once per distinct message. */
27
+ function useReportError(message, onError) {
28
+ const latest = useRef(onError);
29
+ const reported = useRef(void 0);
30
+ useEffect(() => {
31
+ latest.current = onError;
32
+ });
33
+ useEffect(() => {
34
+ if (message !== void 0 && message !== reported.current) latest.current?.(new Error(message));
35
+ reported.current = message;
36
+ }, [message]);
37
+ }
38
+ export { useNearViewport, useReportError };