social-embeds 0.3.0 → 0.4.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 +99 -49
- package/dist/{index-7CfJ3zQZ.d.ts → index-CSSlJIJU.d.ts} +1 -1
- package/dist/index.d.ts +62 -3
- package/dist/index.js +557 -348
- package/dist/{parser-HhmrfoYj.js → parser-D7a5KPhN.js} +442 -116
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +25 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Turn social media embed code or post URLs into working React components.
|
|
|
4
4
|
|
|
5
5
|
Pasting a platform's embed code into `dangerouslySetInnerHTML` does not work in React: the `<script>` tag never runs, every embed adds the same script again, and nothing initialises after client-side navigation. `social-embeds` recognises the platform, reads the post and its options from the embed code, drops the `<script>` tag, loads each platform script once per page and asks the platform to render the post. Iframe-based platforms get a responsive `<iframe>` instead.
|
|
6
6
|
|
|
7
|
-
- X, Instagram, Threads, Facebook, TikTok, YouTube, Telegram, Snapchat, LinkedIn, Reddit and
|
|
7
|
+
- X, Instagram, Threads, Facebook, TikTok, YouTube, Telegram, Snapchat, LinkedIn, Reddit, Pinterest, Spotify, Vimeo, Twitch and Dailymotion
|
|
8
8
|
- React 19, Next.js App Router (Server Components, client navigation), or plain React
|
|
9
9
|
- Zero runtime dependencies, ESM only, typed
|
|
10
10
|
- No styling and no defaults beyond what the embed code or your props ask for
|
|
@@ -34,9 +34,9 @@ import { SocialEmbed } from 'social-embeds';
|
|
|
34
34
|
There are two inputs, and they lead to the same component:
|
|
35
35
|
|
|
36
36
|
- **`html`**: the embed code from the platform's Embed dialog, stored as-is (for example in your CMS). It carries the post's options (theme, caption, start time, and so on), and for X, Instagram, Threads and some Facebook code it also carries **fallback content**: the post text, author and link inside the `<blockquote>`. That content is rendered on the server, so crawlers and visitors without JavaScript see it, and the platform script upgrades it in place.
|
|
37
|
-
- **`url`**: the post's address. A URL has no fallback content, so until the post has loaded the component shows a placeholder. This is a property of the input, not a limitation of the package. A URL carries no options either, except a YouTube start time (`t` or `start`), the privacy-enhanced host,
|
|
37
|
+
- **`url`**: the post's address. A URL has no fallback content, so until the post has loaded the component shows a placeholder. This is a property of the input, not a limitation of the package. A URL carries no options either, except a YouTube start time (`t` or `start`), the privacy-enhanced host, Telegram's `single` and `comment`, a Vimeo start time (`#t=`) and a Twitch video's `t`.
|
|
38
38
|
|
|
39
|
-
Embed code is matched strictly: it must be one platform's own snippet, as the platform produced it. Extra wrappers, other markup or unknown scripts make it unrecognised (see [`fallback`](#unrecognised-embed-code)).
|
|
39
|
+
Embed code is matched strictly: it must be one platform's own snippet, as the platform produced it. Extra wrappers, other markup or unknown scripts make it unrecognised (see [`fallback`](#unrecognised-embed-code)). The exceptions are Vimeo's and Dailymotion's own responsive wrappers, which hold the video's aspect ratio.
|
|
40
40
|
|
|
41
41
|
## Usage
|
|
42
42
|
|
|
@@ -59,7 +59,7 @@ export function Embed({ code }: { code: string }) {
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
It accepts the [shared props](#shared-props); `height` reaches only the iframe-based platforms. Platform options come from the embed code. To set them with props, use a platform component.
|
|
62
|
+
It accepts the [shared props](#shared-props); `height` reaches only the iframe-based platforms. Platform options come from the embed code. To set them with props, use a platform component. `<SocialEmbed>` takes no Dailymotion Player ID, so it renders Dailymotion only from embed code that carries one (see [Dailymotion](#dailymotion)).
|
|
63
63
|
|
|
64
64
|
#### Unrecognised embed code
|
|
65
65
|
|
|
@@ -83,15 +83,19 @@ Each platform component takes a `url`, or an `embed` already parsed by [`social-
|
|
|
83
83
|
|
|
84
84
|
```tsx
|
|
85
85
|
import {
|
|
86
|
+
DailymotionEmbed,
|
|
86
87
|
FacebookEmbed,
|
|
87
88
|
InstagramEmbed,
|
|
88
89
|
LinkedInEmbed,
|
|
89
90
|
PinterestEmbed,
|
|
90
91
|
RedditEmbed,
|
|
91
92
|
SnapchatEmbed,
|
|
93
|
+
SpotifyEmbed,
|
|
92
94
|
TelegramEmbed,
|
|
93
95
|
ThreadsEmbed,
|
|
94
96
|
TikTokEmbed,
|
|
97
|
+
TwitchEmbed,
|
|
98
|
+
VimeoEmbed,
|
|
95
99
|
XEmbed,
|
|
96
100
|
YouTubeEmbed,
|
|
97
101
|
} from 'social-embeds';
|
|
@@ -133,23 +137,39 @@ import {
|
|
|
133
137
|
/>
|
|
134
138
|
|
|
135
139
|
<PinterestEmbed url="https://www.pinterest.com/pin/99360735500167749/" pinWidth="large" />
|
|
140
|
+
|
|
141
|
+
<SpotifyEmbed url="https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC" theme={0} />
|
|
142
|
+
|
|
143
|
+
<VimeoEmbed url="https://vimeo.com/76979871" muted title={false} t="1m2s" />
|
|
144
|
+
|
|
145
|
+
<TwitchEmbed url="https://www.twitch.tv/videos/40464143" autoplay={false} time="1h2m3s" />
|
|
146
|
+
|
|
147
|
+
<DailymotionEmbed
|
|
148
|
+
url="https://www.dailymotion.com/video/x84sh87"
|
|
149
|
+
playerId={process.env.NEXT_PUBLIC_DAILYMOTION_PLAYER_ID}
|
|
150
|
+
mute
|
|
151
|
+
/>
|
|
136
152
|
```
|
|
137
153
|
|
|
138
|
-
| Component
|
|
139
|
-
|
|
|
140
|
-
| `XEmbed`
|
|
141
|
-
| `InstagramEmbed`
|
|
142
|
-
| `ThreadsEmbed`
|
|
143
|
-
| `FacebookEmbed`
|
|
144
|
-
| `TikTokEmbed`
|
|
145
|
-
| `YouTubeEmbed`
|
|
146
|
-
| `TelegramEmbed`
|
|
147
|
-
| `SnapchatEmbed`
|
|
148
|
-
| `LinkedInEmbed`
|
|
149
|
-
| `RedditEmbed`
|
|
150
|
-
| `PinterestEmbed`
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
| Component | Option props |
|
|
155
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
156
|
+
| `XEmbed` | `theme` (`'light'` \| `'dark'`), `conversation` (`'none'`), `cards` (`'hidden'`), `align` (`'left'` \| `'center'` \| `'right'`), `lang`, `dnt` |
|
|
157
|
+
| `InstagramEmbed` | `captioned` |
|
|
158
|
+
| `ThreadsEmbed` | `theme` (`'light'` \| `'dark'` \| `'auto'`) |
|
|
159
|
+
| `FacebookEmbed` | `locale` (SDK locale, default `'en_US'`), `showText`; videos also `allowfullscreen`, `autoplay`, `showCaptions` |
|
|
160
|
+
| `TikTokEmbed` | the [Embed Player](https://developers.tiktok.com/doc/embed-player) parameters: `controls`, `progressBar`, `playButton`, `volumeControl`, `fullscreenButton`, `timestamp`, `loop`, `autoplay`, `musicInfo`, `description`, `rel`, `nativeContextMenu`, `closedCaption`, `forceMuted` |
|
|
161
|
+
| `YouTubeEmbed` | the [player parameters](https://developers.google.com/youtube/player_parameters): `autoplay`, `ccLangPref`, `ccLoadPolicy`, `color`, `controls`, `disablekb`, `enablejsapi`, `end`, `fs`, `hl`, `ivLoadPolicy`, `list`, `listType`, `loop`, `origin`, `playlist`, `playsinline`, `rel`, `start`, `widgetReferrer`; plus `nocookie` (play from youtube-nocookie.com) |
|
|
162
|
+
| `TelegramEmbed` | the widget configurator's options: `userpic`, `color` (hex, no `#`), `dark`, `darkColor` |
|
|
163
|
+
| `SnapchatEmbed` | none |
|
|
164
|
+
| `LinkedInEmbed` | `collapsed` (the Embed dialog's "less text") |
|
|
165
|
+
| `RedditEmbed` | `theme` (`'light'` \| `'dark'`), `showMedia`, `showTitle`, `showUsername`, `locale`, `depth` (replies under a comment) |
|
|
166
|
+
| `PinterestEmbed` | `pinWidth` (`'small'` \| `'medium'` \| `'large'`): `data-pin-width`, since `width` is the wrapper's |
|
|
167
|
+
| `SpotifyEmbed` | `theme` (`0`, the dark player) |
|
|
168
|
+
| `VimeoEmbed` | Vimeo's player parameters: `autopause`, `autoplay`, `background`, `byline`, `color` (hex, no `#`), `controls`, `dnt`, `keyboard`, `loop`, `muted`, `pip`, `playsinline`, `portrait`, `quality`, `speed`, `title`, `transparent`; plus `t` (start time, seconds or `1m2s`) |
|
|
169
|
+
| `TwitchEmbed` | `autoplay`, `muted`, `time` (a video's start, `1h2m3s`) |
|
|
170
|
+
| `DailymotionEmbed` | `playerId` (your Player ID; required unless the embed code has one), `mute`, `startTime` (seconds), `loop` |
|
|
171
|
+
|
|
172
|
+
Boolean player parameters are written as `1`/`0`; Telegram's, Reddit's, Twitch's and Dailymotion's options are written the way their own embed code writes them.
|
|
153
173
|
|
|
154
174
|
### Parser
|
|
155
175
|
|
|
@@ -208,38 +228,42 @@ A component checks an `embed` before using it: its `url` must be the exact URL `
|
|
|
208
228
|
|
|
209
229
|
## Shared props
|
|
210
230
|
|
|
211
|
-
| Prop | Type | Default | Notes
|
|
212
|
-
| ------------- | ------------------------ | ------------ |
|
|
213
|
-
| `url` | `string` | | Post URL. Platform components take `url` or `embed`; `<SocialEmbed>` takes `url` or `html`.
|
|
214
|
-
| `embed` | `ParsedEmbed` | | Platform components only.
|
|
215
|
-
| `html` | `string` | | `<SocialEmbed>` only.
|
|
216
|
-
| `width` | `number \| string` | `'100%'` | Wrapper width.
|
|
217
|
-
| `maxWidth` | `number` | per platform | The embed fills its container up to this width, in pixels. See [Platforms](#platforms).
|
|
218
|
-
| `height` | `number` | | Fixed-size iframe embeds only (YouTube, TikTok, Facebook video embed code, Snapchat, LinkedIn): a fixed height instead of the aspect ratio, or instead of LinkedIn's default 670 px. The others size themselves. |
|
|
219
|
-
| `maxHeight` | `number` | | Fixed-size iframe embeds only: the embed is at most this tall, in pixels. It narrows to keep its aspect ratio, so a vertical video does not fill the column.
|
|
220
|
-
| `placeholder` | `ReactNode` | a skeleton | Shown until the post has loaded. The default skeleton has a per-platform minimum height to limit layout shift.
|
|
221
|
-
| `lazy` | `boolean` | `true` | Load the embed only when it comes within 200 px of the viewport.
|
|
222
|
-
| `onLoad` | `() => void` | | Called once the platform has rendered the post (iframe embeds: when the iframe has loaded; Telegram and Reddit: when the frame first reports its height).
|
|
223
|
-
| `onError` | `(error: Error) => void` | | Called on invalid input, a script that fails to load, or a post that does not render. Components never throw.
|
|
224
|
-
| `...rest` | `ComponentProps<'div'>` | | Passed to the wrapper `div` (`className`, `style`, `data-*`, …).
|
|
231
|
+
| Prop | Type | Default | Notes |
|
|
232
|
+
| ------------- | ------------------------ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
233
|
+
| `url` | `string` | | Post URL. Platform components take `url` or `embed`; `<SocialEmbed>` takes `url` or `html`. |
|
|
234
|
+
| `embed` | `ParsedEmbed` | | Platform components only. |
|
|
235
|
+
| `html` | `string` | | `<SocialEmbed>` only. |
|
|
236
|
+
| `width` | `number \| string` | `'100%'` | Wrapper width. |
|
|
237
|
+
| `maxWidth` | `number` | per platform | The embed fills its container up to this width, in pixels. See [Platforms](#platforms). |
|
|
238
|
+
| `height` | `number` | | Fixed-size iframe embeds only (YouTube, TikTok, Facebook video embed code, Snapchat, LinkedIn, Spotify, Vimeo, Twitch, Dailymotion): a fixed height instead of the aspect ratio, or instead of LinkedIn's default 670 px or Spotify's 152 or 352 px. The others size themselves. |
|
|
239
|
+
| `maxHeight` | `number` | | Fixed-size iframe embeds only: the embed is at most this tall, in pixels. It narrows to keep its aspect ratio, so a vertical video does not fill the column. |
|
|
240
|
+
| `placeholder` | `ReactNode` | a skeleton | Shown until the post has loaded. The default skeleton has a per-platform minimum height to limit layout shift. |
|
|
241
|
+
| `lazy` | `boolean` | `true` | Load the embed only when it comes within 200 px of the viewport. |
|
|
242
|
+
| `onLoad` | `() => void` | | Called once the platform has rendered the post (iframe embeds: when the iframe has loaded; Telegram and Reddit: when the frame first reports its height). |
|
|
243
|
+
| `onError` | `(error: Error) => void` | | Called on invalid input, a script that fails to load, or a post that does not render. Components never throw. |
|
|
244
|
+
| `...rest` | `ComponentProps<'div'>` | | Passed to the wrapper `div` (`className`, `style`, `data-*`, …). |
|
|
225
245
|
|
|
226
246
|
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. Telegram and Reddit frames that report no height within 15 s show at their starting height, and `onError` reports it.
|
|
227
247
|
|
|
228
248
|
## Platforms
|
|
229
249
|
|
|
230
|
-
| Platform
|
|
231
|
-
|
|
|
232
|
-
| X
|
|
233
|
-
| Instagram
|
|
234
|
-
| Threads
|
|
235
|
-
| Facebook
|
|
236
|
-
| TikTok
|
|
237
|
-
| YouTube
|
|
238
|
-
| Telegram
|
|
239
|
-
| Snapchat
|
|
240
|
-
| LinkedIn
|
|
241
|
-
| Reddit
|
|
242
|
-
| Pinterest
|
|
250
|
+
| Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
|
|
251
|
+
| ----------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
|
252
|
+
| 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 |
|
|
253
|
+
| 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 |
|
|
254
|
+
| 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 |
|
|
255
|
+
| 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 |
|
|
256
|
+
| TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
|
|
257
|
+
| 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 |
|
|
258
|
+
| 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 |
|
|
259
|
+
| Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
|
|
260
|
+
| 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 |
|
|
261
|
+
| 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 |
|
|
262
|
+
| 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 |
|
|
263
|
+
| 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 |
|
|
264
|
+
| 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 |
|
|
265
|
+
| 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 |
|
|
266
|
+
| 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 |
|
|
243
267
|
|
|
244
268
|
URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
|
|
245
269
|
|
|
@@ -333,9 +357,35 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
|
|
|
333
357
|
- A host page that already loaded `pinit.js` or `pinit_main.js` is reused.
|
|
334
358
|
- Boards and profiles are not supported.
|
|
335
359
|
|
|
360
|
+
### Spotify
|
|
361
|
+
|
|
362
|
+
- Every input renders Spotify's player across the column at a fixed height: the embed code's, else 152 px for a track or episode (the compact player) and 352 px for the rest. `height` replaces it.
|
|
363
|
+
- Embed code for a video podcast (its iframe address ends in `/video`) renders the video player at its aspect ratio. A URL cannot tell a video show from an audio one, so it renders the audio player.
|
|
364
|
+
- The wrapper has Spotify's rounded corners (`border-radius: 12px`); `style` replaces them.
|
|
365
|
+
|
|
366
|
+
### Vimeo
|
|
367
|
+
|
|
368
|
+
- 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.
|
|
369
|
+
- An unlisted video keeps its hash, from the URL or from the iframe's `h`.
|
|
370
|
+
|
|
371
|
+
### Twitch
|
|
372
|
+
|
|
373
|
+
- Twitch plays only when its `parent` parameter names the domain of the embedding page. The package drops every `parent` from the embed code and adds `parent={location.hostname}` when it creates the iframe in the browser, so the same code works on every domain and environment. Twitch's docs require HTTPS for the embedding page; `localhost` works.
|
|
374
|
+
- A page that is itself shown in another site's frame also needs that site as a `parent`, which the package cannot know. Render Twitch's iframe yourself there.
|
|
375
|
+
- Autoplay is Twitch's default (channels and videos play, clips do not) unless the embed code or `autoplay` says otherwise.
|
|
376
|
+
- Twitch's interactive JavaScript embed (`Twitch.Player`) is not supported.
|
|
377
|
+
|
|
378
|
+
### Dailymotion
|
|
379
|
+
|
|
380
|
+
- Dailymotion serves embeds only through a publisher's player, identified by a Player ID made in Dailymotion Studio. Its oEmbed code (`geo.dailymotion.com/player.html?video=…`) and the old `www.dailymotion.com/embed/video/{id}` have none, and Dailymotion answers them with 403.
|
|
381
|
+
- Embed code from Dailymotion Studio carries the Player ID (`geo.dailymotion.com/player/{playerId}.html?video={id}`) and renders as given, also inside Dailymotion's responsive wrapper `div`.
|
|
382
|
+
- URLs, and code without a Player ID, render only through `DailymotionEmbed` with your `playerId`. A `playerId` prop also replaces the one in the embed code. `<SocialEmbed>` takes none: for that input it renders nothing and calls `onError`.
|
|
383
|
+
- The package never uses a Player ID you did not give it.
|
|
384
|
+
- Playlists are not supported.
|
|
385
|
+
|
|
336
386
|
### Not supported
|
|
337
387
|
|
|
338
|
-
- Redirecting short links: `fb.watch/…`, Facebook share links (`/share/p/…`, `/share/v/…`), `vm.tiktok.com/…`, `vt.tiktok.com/…`, `redd.it/…`, Reddit share links (`/r/{sub}/s/…`), `pin.it/…`, `lnkd.in/…` and `
|
|
388
|
+
- Redirecting short links: `fb.watch/…`, Facebook share links (`/share/p/…`, `/share/v/…`), `vm.tiktok.com/…`, `vt.tiktok.com/…`, `redd.it/…`, Reddit share links (`/r/{sub}/s/…`), `pin.it/…`, `lnkd.in/…`, `t.snapchat.com/…`, `spotify.link/…` and `spotify.app.link/…`. A redirect cannot be followed without a network request, and the package makes none. `matchUrl` returns `null`.
|
|
339
389
|
- Facebook group posts.
|
|
340
390
|
- Fetching embed code from oEmbed endpoints, consent gating and HTML sanitising: these stay with the host.
|
|
341
391
|
|
|
@@ -378,7 +428,7 @@ Client navigation needs nothing extra: each platform script loads once per page,
|
|
|
378
428
|
|
|
379
429
|
- **Embed code with fallback content** (X, Instagram, Threads, Facebook SDK code with a blockquote): the server HTML contains the platform's blockquote with its whitelisted content, such as the post text, author and link. No placeholder is shown. On the client, the platform script turns it into the post.
|
|
380
430
|
- **URLs and embed code without fallback content**: the server HTML contains the sized wrapper and the placeholder.
|
|
381
|
-
- **Iframe embeds** (YouTube, TikTok, Facebook video embed code, Telegram, Snapchat, LinkedIn, Reddit): the iframe is added on the client, so `onLoad` can never be missed. Without JavaScript only the placeholder shows.
|
|
431
|
+
- **Iframe embeds** (YouTube, TikTok, Facebook video embed code, Telegram, Snapchat, LinkedIn, Reddit, Spotify, Vimeo, Twitch, Dailymotion): the iframe is added on the client, so `onLoad` can never be missed. Without JavaScript only the placeholder shows.
|
|
382
432
|
- **Pinterest**: the server HTML contains the pin's empty link and the placeholder.
|
|
383
433
|
- The server HTML never contains a platform `<script>`.
|
|
384
434
|
|
|
@@ -391,7 +441,7 @@ The host does nothing to make embeds responsive:
|
|
|
391
441
|
- **Script-based embeds** (X, Instagram, Threads, Facebook SDK) get a wrapper of `width: 100%` (or `width`) and `max-width: {maxWidth}px`, and the platform widget fills it. Their height is the platform's own.
|
|
392
442
|
- **Iframe embeds** get a wrapper with `aspect-ratio` taken from the embed code's `width` and `height` (16:9 without them; 9:16 for TikTok and YouTube Shorts URLs; 416:692 for Snapchat), and the iframe fills it. `height` replaces the aspect ratio with a fixed height. `maxHeight` keeps the aspect ratio and lowers the wrapper's `max-width` to the widest box that is at most that tall.
|
|
393
443
|
- **Telegram and Reddit** get a wrapper of `width: 100%` and `max-width: {maxWidth}px` whose height follows the height the frame reports.
|
|
394
|
-
- **LinkedIn**
|
|
444
|
+
- **LinkedIn** and **Spotify** have a fixed height (see [LinkedIn](#linkedin) and [Spotify](#spotify)).
|
|
395
445
|
- **Pinterest** pins have a fixed width; the wrapper's `max-width` defaults to it.
|
|
396
446
|
|
|
397
447
|
## License
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Platform = 'x' | 'instagram' | 'facebook' | 'threads' | 'tiktok' | 'youtube' | 'telegram' | 'snapchat' | 'linkedin' | 'reddit' | 'pinterest';
|
|
1
|
+
type Platform = 'x' | 'instagram' | 'facebook' | 'threads' | 'tiktok' | 'youtube' | 'telegram' | 'snapchat' | 'linkedin' | 'reddit' | 'pinterest' | 'spotify' | 'vimeo' | 'twitch' | 'dailymotion';
|
|
2
2
|
type ParsedEmbed = {
|
|
3
3
|
platform: Platform;
|
|
4
4
|
kind: 'post' | 'video';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as ParsedEmbed } from "./index-
|
|
1
|
+
import { r as ParsedEmbed } from "./index-CSSlJIJU.js";
|
|
2
2
|
import { ComponentProps, ReactNode } from "react";
|
|
3
3
|
type EmbedSource = {
|
|
4
4
|
url: string;
|
|
@@ -27,6 +27,20 @@ type FrameProps = SharedProps & {
|
|
|
27
27
|
/** The embed is at most this tall, in pixels: it narrows to keep its aspect ratio. */
|
|
28
28
|
maxHeight?: number;
|
|
29
29
|
};
|
|
30
|
+
type DailymotionOptions = {
|
|
31
|
+
/** The publisher's Player ID from Dailymotion Studio. Replaces the embed code's own. */
|
|
32
|
+
playerId?: string;
|
|
33
|
+
mute?: boolean;
|
|
34
|
+
/** Start time in seconds. */
|
|
35
|
+
startTime?: number;
|
|
36
|
+
loop?: boolean;
|
|
37
|
+
};
|
|
38
|
+
type DailymotionEmbedProps = EmbedSource & Omit<FrameProps, keyof DailymotionOptions> & DailymotionOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
|
|
41
|
+
* prop, never another account's (docs/decisions.md D63).
|
|
42
|
+
*/
|
|
43
|
+
export declare function DailymotionEmbed(props: DailymotionEmbedProps): import("react").JSX.Element | null;
|
|
30
44
|
/**
|
|
31
45
|
* `data-width` and `data-lazy` have no props, because `width` and `lazy` are the wrapper's
|
|
32
46
|
* (docs/decisions.md D33).
|
|
@@ -117,6 +131,41 @@ type TikTokOptions = {
|
|
|
117
131
|
type TikTokEmbedProps = EmbedSource & Omit<FrameProps, keyof TikTokOptions> & TikTokOptions;
|
|
118
132
|
/** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
|
|
119
133
|
export declare function TikTokEmbed(props: TikTokEmbedProps): import("react").JSX.Element | null;
|
|
134
|
+
type TwitchOptions = {
|
|
135
|
+
/** Twitch's default: `true` for channels and videos, `false` for clips. */
|
|
136
|
+
autoplay?: boolean;
|
|
137
|
+
muted?: boolean;
|
|
138
|
+
/** A video's start time, as `1h2m3s`. */
|
|
139
|
+
time?: string;
|
|
140
|
+
};
|
|
141
|
+
type TwitchEmbedProps = EmbedSource & Omit<FrameProps, keyof TwitchOptions> & TwitchOptions;
|
|
142
|
+
/** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
|
|
143
|
+
export declare function TwitchEmbed(props: TwitchEmbedProps): import("react").JSX.Element | null;
|
|
144
|
+
/** The player parameters Vimeo documents (help.vimeo.com, "Using player parameters"). */
|
|
145
|
+
type VimeoOptions = {
|
|
146
|
+
autopause?: boolean;
|
|
147
|
+
autoplay?: boolean;
|
|
148
|
+
background?: boolean;
|
|
149
|
+
byline?: boolean;
|
|
150
|
+
/** Hex colour without `#`. */
|
|
151
|
+
color?: string;
|
|
152
|
+
controls?: boolean;
|
|
153
|
+
dnt?: boolean;
|
|
154
|
+
keyboard?: boolean;
|
|
155
|
+
loop?: boolean;
|
|
156
|
+
muted?: boolean;
|
|
157
|
+
pip?: boolean;
|
|
158
|
+
playsinline?: boolean;
|
|
159
|
+
portrait?: boolean;
|
|
160
|
+
quality?: string;
|
|
161
|
+
speed?: boolean;
|
|
162
|
+
title?: boolean;
|
|
163
|
+
transparent?: boolean;
|
|
164
|
+
/** Start time: seconds, or `1m2s`. */
|
|
165
|
+
t?: number | string;
|
|
166
|
+
};
|
|
167
|
+
type VimeoEmbedProps = EmbedSource & Omit<FrameProps, keyof VimeoOptions> & VimeoOptions;
|
|
168
|
+
export declare function VimeoEmbed(props: VimeoEmbedProps): import("react").JSX.Element | null;
|
|
120
169
|
/**
|
|
121
170
|
* `data-width` has no prop, because `width` is the wrapper's: the post fills the wrapper up
|
|
122
171
|
* to `maxWidth` (docs/decisions.md D33).
|
|
@@ -165,7 +214,7 @@ type SocialEmbedSource = {
|
|
|
165
214
|
url: string;
|
|
166
215
|
html?: never;
|
|
167
216
|
};
|
|
168
|
-
type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions | keyof TelegramOptions | keyof RedditOptions | keyof LinkedInOptions | keyof PinterestOptions;
|
|
217
|
+
type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions | keyof TelegramOptions | keyof RedditOptions | keyof LinkedInOptions | keyof PinterestOptions | keyof VimeoOptions | keyof TwitchOptions | keyof DailymotionOptions;
|
|
169
218
|
type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
|
|
170
219
|
/**
|
|
171
220
|
* Called with the original string when `html` is not a recognised embed code. Without
|
|
@@ -178,4 +227,14 @@ export declare function SocialEmbed(props: SocialEmbedProps): string | number |
|
|
|
178
227
|
type SnapchatEmbedProps = EmbedSource & FrameProps;
|
|
179
228
|
/** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
|
|
180
229
|
export declare function SnapchatEmbed(props: SnapchatEmbedProps): import("react").JSX.Element | null;
|
|
181
|
-
|
|
230
|
+
type SpotifyOptions = {
|
|
231
|
+
/** `0` for the dark player. */
|
|
232
|
+
theme?: 0;
|
|
233
|
+
};
|
|
234
|
+
type SpotifyEmbedProps = EmbedSource & Omit<FrameProps, keyof SpotifyOptions> & SpotifyOptions;
|
|
235
|
+
/**
|
|
236
|
+
* A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
|
|
237
|
+
* and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
|
|
238
|
+
*/
|
|
239
|
+
export declare function SpotifyEmbed(props: SpotifyEmbedProps): import("react").JSX.Element | null;
|
|
240
|
+
export type { DailymotionEmbedProps, DailymotionOptions, EmbedSource, FacebookEmbedProps, FacebookOptions, FrameProps, InstagramEmbedProps, InstagramOptions, LinkedInEmbedProps, LinkedInOptions, PinterestEmbedProps, PinterestOptions, RedditEmbedProps, RedditOptions, SharedProps, SnapchatEmbedProps, SocialEmbedProps, SocialEmbedSource, SpotifyEmbedProps, SpotifyOptions, TelegramEmbedProps, TelegramOptions, ThreadsEmbedProps, ThreadsOptions, TikTokEmbedProps, TikTokOptions, TwitchEmbedProps, TwitchOptions, VimeoEmbedProps, VimeoOptions, XEmbedProps, XOptions, YouTubeEmbedProps, YouTubeOptions };
|