social-embeds 0.8.0 → 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.
package/README.md CHANGED
@@ -85,7 +85,7 @@ 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 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: …`.
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
89
 
90
90
  ```tsx
91
91
  import {
@@ -311,47 +311,52 @@ A component checks an `embed` before using it: its `url` must be the exact URL `
311
311
 
312
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`.
313
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
+
314
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.
315
319
 
316
320
  ## Platforms
317
321
 
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 |
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 |
349
353
 
350
354
  URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.` and `web.`.
351
355
 
352
356
  ### X
353
357
 
354
358
  - The post that renders is the one the blockquote links to.
359
+ - Older video code (`blockquote.twitter-video`) renders like a post.
355
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.
356
361
 
357
362
  ### Instagram
@@ -387,14 +392,14 @@ The rules:
387
392
 
388
393
  URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `facebook.com` and `m.facebook.com`:
389
394
 
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}` |
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}` |
394
399
 
395
400
  - One SDK serves the whole page, so the first `locale` requested wins.
396
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.
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.
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.
398
403
  - A removed post shows Facebook's "no longer available" notice.
399
404
 
400
405
  ### TikTok
@@ -431,6 +436,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
431
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).
432
437
  - Reddit may machine-translate the post into the visitor's language; `locale` sets the language.
433
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.
434
440
 
435
441
  ### Pinterest
436
442
 
@@ -449,6 +455,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
449
455
 
450
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.
451
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.
452
459
 
453
460
  ### Twitch
454
461
 
@@ -486,7 +493,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
486
493
 
487
494
  ### Tumblr
488
495
 
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.
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.
490
497
 
491
498
  ### Kick and Giphy
492
499
 
@@ -581,21 +588,21 @@ Embed code goes in a `<template>`, which keeps the platform's own `<script>` fro
581
588
  </social-embed>
582
589
  ```
583
590
 
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`). |
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. |
593
600
 
594
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.
595
602
 
596
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`.
597
604
 
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.
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.
599
606
 
600
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.
601
608
 
@@ -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 };
@@ -1,3 +1,4 @@
1
+ import { FinalError } from "../core/drivers.js";
1
2
  import { postLinkText, postUrl } from "../core/post-link.js";
2
3
  import { RENDER_TIMEOUT_MS, RETRY_DELAY_MS } from "../core/timing.js";
3
4
  import { useNearViewport } from "./hooks.js";
@@ -14,6 +15,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
14
15
  const near = useNearViewport(container, lazy);
15
16
  const [rendered, setRendered] = useState(false);
16
17
  const [failure, setFailure] = useState();
18
+ const done = useRef(false);
17
19
  const callbacks = useRef({
18
20
  onLoad,
19
21
  onError
@@ -26,15 +28,14 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
26
28
  });
27
29
  useEffect(() => {
28
30
  const element = container.current;
29
- if (!near || !element) return;
31
+ if (!near || !element || done.current) return;
30
32
  let cancelled = false;
31
- let done = false;
32
33
  let timer;
33
34
  let stop = () => {};
34
35
  const href = postUrl(element);
35
36
  const finish = () => {
36
- if (cancelled || done) return;
37
- done = true;
37
+ if (cancelled || done.current) return;
38
+ done.current = true;
38
39
  clearTimeout(timer);
39
40
  stop();
40
41
  setRendered(true);
@@ -45,10 +46,10 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
45
46
  callbacks.current.onError?.(error);
46
47
  };
47
48
  const retryOrFail = (number, error) => {
48
- if (cancelled || done) return;
49
+ if (cancelled || done.current) return;
49
50
  stop();
50
51
  stop = () => {};
51
- if (number >= 3) {
52
+ if (number >= 3 || error instanceof FinalError) {
52
53
  fail(error);
53
54
  return;
54
55
  }
@@ -57,7 +58,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
57
58
  }, RETRY_DELAY_MS * 2 ** (number - 1));
58
59
  };
59
60
  const attempt = (number) => {
60
- if (cancelled || done) return;
61
+ if (cancelled || done.current) return;
61
62
  try {
62
63
  stop = driver.render(element, finish);
63
64
  } catch (error) {
@@ -1,6 +1,8 @@
1
1
  import { FACEBOOK_SDK_VERSION, loadPlatformScript } from "../loader/platform-scripts.js";
2
2
  // src/core/drivers.ts
3
3
  const globals = () => window;
4
+ /** Thrown by `render` when another attempt cannot succeed. */
5
+ var FinalError = class extends Error {};
4
6
  function watch(container, rendered, done) {
5
7
  if (rendered(container)) {
6
8
  done();
@@ -49,6 +51,9 @@ const xDriver = {
49
51
  };
50
52
  }
51
53
  };
54
+ function inDocument(container, label) {
55
+ if (container.getRootNode() !== document) throw new FinalError(`social-embeds: the ${label} embed cannot render inside a shadow root`);
56
+ }
52
57
  /** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
53
58
  function processEmbeds() {
54
59
  const process = globals().instgrm?.Embeds?.process;
@@ -58,6 +63,7 @@ function processEmbeds() {
58
63
  const instagramDriver = {
59
64
  load: () => loadPlatformScript("instagram"),
60
65
  render(container, done) {
66
+ inDocument(container, "Instagram");
61
67
  const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
62
68
  reveal(container, "instagram-media");
63
69
  processEmbeds();
@@ -67,6 +73,7 @@ const instagramDriver = {
67
73
  const threadsDriver = {
68
74
  load: () => loadPlatformScript("threads"),
69
75
  render(container, done) {
76
+ inDocument(container, "Threads");
70
77
  const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
71
78
  reveal(container, "text-post-media");
72
79
  processEmbeds();
@@ -115,4 +122,4 @@ const pinterestDriver = {
115
122
  return stop;
116
123
  }
117
124
  };
118
- export { facebookDriver, instagramDriver, pinterestDriver, threadsDriver, xDriver };
125
+ export { FinalError, facebookDriver, instagramDriver, pinterestDriver, threadsDriver, xDriver };
@@ -1,4 +1,4 @@
1
- import { playerParams, query } from "../params.js";
1
+ import { optionsWithout, playerParams, query } from "../params.js";
2
2
  // src/core/plans/youtube.ts
3
3
  const PARAMS = {
4
4
  autoplay: "autoplay",
@@ -23,14 +23,26 @@ const PARAMS = {
23
23
  widgetReferrer: "widget_referrer"
24
24
  };
25
25
  const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
26
+ function player(embed) {
27
+ if (embed.url.startsWith("https://www.youtube.com/playlist?")) return {
28
+ path: "videoseries",
29
+ key: "list"
30
+ };
31
+ if (embed.url.startsWith("https://www.youtube.com/channel/")) return {
32
+ path: "live_stream",
33
+ key: "channel"
34
+ };
35
+ return { path: embed.id };
36
+ }
26
37
  function youtubePlan(embed, options) {
27
38
  const { nocookie, ...rest } = options;
28
39
  const { nocookie: parsedNocookie, ...parsed } = embed.options;
29
40
  const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
30
- const params = playerParams(rest, PARAMS);
41
+ const { path, key } = player(embed);
42
+ const params = playerParams(rest, PARAMS).filter(([name]) => name !== key);
31
43
  return {
32
44
  kind: "iframe",
33
- src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
45
+ src: `${host}/embed/${path}${query(key === void 0 ? void 0 : [[key, embed.id]], optionsWithout(parsed, key === void 0 ? [] : [key]), params)}`,
34
46
  title: "YouTube video player",
35
47
  allow: ALLOW,
36
48
  referrerPolicy: "strict-origin-when-cross-origin",
package/dist/element.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare class SocialEmbedElement extends Base {
19
19
  get maxHeight(): string | null;
20
20
  set maxHeight(value: string | null);
21
21
  get eager(): boolean;
22
- set eager(value: boolean | null | undefined);
22
+ set eager(value: boolean | string | null | undefined);
23
23
  connectedCallback(): void;
24
24
  disconnectedCallback(): void;
25
25
  attributeChangedCallback(): void;