social-embeds 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -44
- package/dist/{index-DCF8EEVz.d.ts → index-CSSlJIJU.d.ts} +1 -1
- package/dist/index.d.ts +105 -3
- package/dist/index.js +773 -255
- package/dist/{parser-BrlUKvvo.js → parser-D7a5KPhN.js} +739 -104
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +5 -5
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 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`)
|
|
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,10 +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,
|
|
89
|
+
LinkedInEmbed,
|
|
90
|
+
PinterestEmbed,
|
|
91
|
+
RedditEmbed,
|
|
92
|
+
SnapchatEmbed,
|
|
93
|
+
SpotifyEmbed,
|
|
94
|
+
TelegramEmbed,
|
|
88
95
|
ThreadsEmbed,
|
|
89
96
|
TikTokEmbed,
|
|
97
|
+
TwitchEmbed,
|
|
98
|
+
VimeoEmbed,
|
|
90
99
|
XEmbed,
|
|
91
100
|
YouTubeEmbed,
|
|
92
101
|
} from 'social-embeds';
|
|
@@ -110,18 +119,57 @@ import {
|
|
|
110
119
|
/>
|
|
111
120
|
|
|
112
121
|
<YouTubeEmbed url="https://youtu.be/jNQXAC9IVRw?t=90" nocookie controls={false} />
|
|
113
|
-
```
|
|
114
122
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
<TelegramEmbed url="https://t.me/telegram/83" dark userpic={false} />
|
|
124
|
+
|
|
125
|
+
<SnapchatEmbed url="https://www.snapchat.com/@teamsnapchat" />
|
|
126
|
+
|
|
127
|
+
<LinkedInEmbed
|
|
128
|
+
url="https://www.linkedin.com/feed/update/urn:li:activity:7527261038006697984/"
|
|
129
|
+
collapsed
|
|
130
|
+
height={560}
|
|
131
|
+
/>
|
|
132
|
+
|
|
133
|
+
<RedditEmbed
|
|
134
|
+
url="https://www.reddit.com/r/bulgaria/comments/1xz8iq4/"
|
|
135
|
+
theme="dark"
|
|
136
|
+
locale="bg-BG"
|
|
137
|
+
/>
|
|
138
|
+
|
|
139
|
+
<PinterestEmbed url="https://www.pinterest.com/pin/99360735500167749/" pinWidth="large" />
|
|
140
|
+
|
|
141
|
+
<SpotifyEmbed url="https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC" theme={0} />
|
|
123
142
|
|
|
124
|
-
|
|
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
|
+
/>
|
|
152
|
+
```
|
|
153
|
+
|
|
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.
|
|
125
173
|
|
|
126
174
|
### Parser
|
|
127
175
|
|
|
@@ -144,7 +192,18 @@ const embed = parseEmbed(code);
|
|
|
144
192
|
|
|
145
193
|
```ts
|
|
146
194
|
type ParsedEmbed = {
|
|
147
|
-
platform:
|
|
195
|
+
platform:
|
|
196
|
+
| 'x'
|
|
197
|
+
| 'instagram'
|
|
198
|
+
| 'facebook'
|
|
199
|
+
| 'threads'
|
|
200
|
+
| 'tiktok'
|
|
201
|
+
| 'youtube'
|
|
202
|
+
| 'telegram'
|
|
203
|
+
| 'snapchat'
|
|
204
|
+
| 'linkedin'
|
|
205
|
+
| 'reddit'
|
|
206
|
+
| 'pinterest';
|
|
148
207
|
kind: 'post' | 'video';
|
|
149
208
|
url: string; // canonical post URL
|
|
150
209
|
id: string;
|
|
@@ -165,37 +224,46 @@ import { YouTubeEmbed } from 'social-embeds';
|
|
|
165
224
|
}
|
|
166
225
|
```
|
|
167
226
|
|
|
168
|
-
A component checks an `embed` before using it: its `url` must be
|
|
227
|
+
A component checks an `embed` before using it: its `url` must be the exact URL `matchUrl` returns for it, with the same platform and id, and `fallbackHtml` must be exactly what the parser would produce. Otherwise it calls `onError`, or drops the fallback content.
|
|
169
228
|
|
|
170
229
|
## Shared props
|
|
171
230
|
|
|
172
|
-
| Prop | Type | Default | Notes
|
|
173
|
-
| ------------- | ------------------------ | ------------ |
|
|
174
|
-
| `url` | `string` | | Post URL. Platform components take `url` or `embed`; `<SocialEmbed>` takes `url` or `html`.
|
|
175
|
-
| `embed` | `ParsedEmbed` | | Platform components only.
|
|
176
|
-
| `html` | `string` | | `<SocialEmbed>` only.
|
|
177
|
-
| `width` | `number \| string` | `'100%'` | Wrapper width.
|
|
178
|
-
| `maxWidth` | `number` | per platform | The embed fills its container up to this width, in pixels. See [Platforms](#platforms).
|
|
179
|
-
| `height` | `number` | |
|
|
180
|
-
| `maxHeight` | `number` | |
|
|
181
|
-
| `placeholder` | `ReactNode` | a skeleton | Shown until the post has loaded. The default skeleton has a per-platform minimum height to limit layout shift.
|
|
182
|
-
| `lazy` | `boolean` | `true` | Load the embed only when it comes within 200 px of the viewport.
|
|
183
|
-
| `onLoad` | `() => void` | | Called once the platform has rendered the post (iframe embeds: when the iframe has loaded).
|
|
184
|
-
| `onError` | `(error: Error) => void` | | Called on invalid input, a script that fails to load, or a post that does not render. Components never throw.
|
|
185
|
-
| `...rest` | `ComponentProps<'div'>` | | Passed to the wrapper `div` (`className`, `style`, `data-*`, …).
|
|
186
|
-
|
|
187
|
-
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.
|
|
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-*`, …). |
|
|
245
|
+
|
|
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.
|
|
188
247
|
|
|
189
248
|
## Platforms
|
|
190
249
|
|
|
191
|
-
| Platform
|
|
192
|
-
|
|
|
193
|
-
| X
|
|
194
|
-
| Instagram
|
|
195
|
-
| Threads
|
|
196
|
-
| Facebook
|
|
197
|
-
| TikTok
|
|
198
|
-
| YouTube
|
|
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 |
|
|
199
267
|
|
|
200
268
|
URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
|
|
201
269
|
|
|
@@ -257,9 +325,67 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
|
|
|
257
325
|
- Videos are 16:9 and Shorts URLs 9:16, unless embed code gives a `width` and `height`.
|
|
258
326
|
- Privacy-enhanced embed code (youtube-nocookie.com) stays on that host; `nocookie` sets it for other input.
|
|
259
327
|
|
|
328
|
+
### Telegram
|
|
329
|
+
|
|
330
|
+
- The embed code is Telegram's widget `<script>` tag itself. It renders as the post's iframe, without the script: the frame reports its own height, and the embed follows it.
|
|
331
|
+
- Public channels and groups only: private links (`t.me/c/…`) are not recognised.
|
|
332
|
+
|
|
333
|
+
### Snapchat
|
|
334
|
+
|
|
335
|
+
- Every input renders Snapchat's `/embed` page for the content, in a 416:692 box unless the embed code gives another size.
|
|
336
|
+
- Recognised: Spotlight videos (`/spotlight/{id}`, `/@{user}/spotlight/{id}`), public profiles (`/@{user}`, `/add/{user}`), Lenses (`/lens/{id}`) and saved stories (`/@{user}/highlight/{id}`). A profile embed shows the account's public stories.
|
|
337
|
+
- A single public story (`/@{user}/{story id}`) and publisher stories (`/p/{id}`) have no embed page and are not recognised.
|
|
338
|
+
- On snapchat.com, the Embed button of a Spotlight video currently opens an app prompt instead of the code. The URL works.
|
|
339
|
+
- `data-snapchat-embed-style` is free-form CSS and is not applied.
|
|
340
|
+
|
|
341
|
+
### LinkedIn
|
|
342
|
+
|
|
343
|
+
- LinkedIn's frame neither scales nor reports its height. It keeps the embed code's height; a URL gets 670 px. A shorter post leaves space below it, and a longer one scrolls inside the frame. Pass `height` when you know better.
|
|
344
|
+
- In the EU, LinkedIn shows its own cookie banner inside the frame, over the top of the post, until the visitor answers it.
|
|
345
|
+
|
|
346
|
+
### Reddit
|
|
347
|
+
|
|
348
|
+
- Posts and single comments. The package builds the `embed.reddit.com` frame itself, without Reddit's script, and follows the height the frame reports.
|
|
349
|
+
- 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).
|
|
350
|
+
- Reddit may machine-translate the post into the visitor's language; `locale` sets the language.
|
|
351
|
+
- No fallback content: Reddit's embed code holds only the title, author and subreddit links.
|
|
352
|
+
|
|
353
|
+
### Pinterest
|
|
354
|
+
|
|
355
|
+
- Pins render through Pinterest's widget. The oEmbed iframe code (`assets.pinterest.com/ext/embed.html`) renders through the widget too, because its fixed size fits only one width.
|
|
356
|
+
- The pin is drawn into the page, not an iframe, at a fixed width per `pinWidth`. Its classes start with `PIN_`, so host CSS can reach it.
|
|
357
|
+
- A host page that already loaded `pinit.js` or `pinit_main.js` is reused.
|
|
358
|
+
- Boards and profiles are not supported.
|
|
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
|
+
|
|
260
386
|
### Not supported
|
|
261
387
|
|
|
262
|
-
- Redirecting short links: `fb.watch/…`, Facebook share links (`/share/p/…`, `/share/v/…`), `vm.tiktok.com/…` 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`.
|
|
263
389
|
- Facebook group posts.
|
|
264
390
|
- Fetching embed code from oEmbed endpoints, consent gating and HTML sanitising: these stay with the host.
|
|
265
391
|
|
|
@@ -302,17 +428,21 @@ Client navigation needs nothing extra: each platform script loads once per page,
|
|
|
302
428
|
|
|
303
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.
|
|
304
430
|
- **URLs and embed code without fallback content**: the server HTML contains the sized wrapper and the placeholder.
|
|
305
|
-
- **Iframe embeds** (YouTube, TikTok, Facebook video embed code): 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.
|
|
432
|
+
- **Pinterest**: the server HTML contains the pin's empty link and the placeholder.
|
|
306
433
|
- The server HTML never contains a platform `<script>`.
|
|
307
434
|
|
|
308
|
-
The platform's class (`twitter-tweet`, `instagram-media`, `text-post-media`) is added only when the embed renders, so the platform scripts, which render every element with that
|
|
435
|
+
The platform's class (`twitter-tweet`, `instagram-media`, `text-post-media`) or Pinterest's `data-pin-do` is added only when the embed renders, so the platform scripts, which render every element with that marker on the page, cannot render embeds that have not come near the viewport yet. CSS that targets those classes does not apply to the fallback content before then.
|
|
309
436
|
|
|
310
437
|
## Responsiveness
|
|
311
438
|
|
|
312
439
|
The host does nothing to make embeds responsive:
|
|
313
440
|
|
|
314
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.
|
|
315
|
-
- **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), 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.
|
|
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.
|
|
443
|
+
- **Telegram and Reddit** get a wrapper of `width: 100%` and `max-width: {maxWidth}px` whose height follows the height the frame reports.
|
|
444
|
+
- **LinkedIn** and **Spotify** have a fixed height (see [LinkedIn](#linkedin) and [Spotify](#spotify)).
|
|
445
|
+
- **Pinterest** pins have a fixed width; the wrapper's `max-width` defaults to it.
|
|
316
446
|
|
|
317
447
|
## License
|
|
318
448
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Platform = 'x' | 'instagram' | 'facebook' | 'threads' | 'tiktok' | 'youtube';
|
|
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).
|
|
@@ -51,6 +65,46 @@ type InstagramOptions = {
|
|
|
51
65
|
};
|
|
52
66
|
type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
|
|
53
67
|
export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").JSX.Element | null;
|
|
68
|
+
type LinkedInOptions = {
|
|
69
|
+
/** The Embed dialog's "less text" option. */
|
|
70
|
+
collapsed?: boolean;
|
|
71
|
+
};
|
|
72
|
+
type LinkedInEmbedProps = EmbedSource & Omit<FrameProps, keyof LinkedInOptions> & LinkedInOptions;
|
|
73
|
+
/** A fixed height: the `height` prop, else the embed code's, else 670px. */
|
|
74
|
+
export declare function LinkedInEmbed(props: LinkedInEmbedProps): import("react").JSX.Element | null;
|
|
75
|
+
/** `pinWidth` is `data-pin-width`; `width` stays the wrapper's. */
|
|
76
|
+
type PinterestOptions = {
|
|
77
|
+
pinWidth?: 'small' | 'medium' | 'large';
|
|
78
|
+
};
|
|
79
|
+
type PinterestEmbedProps = EmbedSource & Omit<SharedProps, keyof PinterestOptions> & PinterestOptions;
|
|
80
|
+
export declare function PinterestEmbed(props: PinterestEmbedProps): import("react").JSX.Element | null;
|
|
81
|
+
/** The `data-embed-*` options of Reddit's embed code that hosts set most. */
|
|
82
|
+
type RedditOptions = {
|
|
83
|
+
theme?: 'light' | 'dark';
|
|
84
|
+
showMedia?: boolean;
|
|
85
|
+
showTitle?: boolean;
|
|
86
|
+
showUsername?: boolean;
|
|
87
|
+
/** Language of the post, which Reddit machine-translates (docs/decisions.md D52). */
|
|
88
|
+
locale?: string;
|
|
89
|
+
/** Replies shown under an embedded comment. */
|
|
90
|
+
depth?: number;
|
|
91
|
+
};
|
|
92
|
+
type RedditEmbedProps = EmbedSource & Omit<SharedProps, keyof RedditOptions> & RedditOptions;
|
|
93
|
+
/** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
|
|
94
|
+
export declare function RedditEmbed(props: RedditEmbedProps): import("react").JSX.Element | null;
|
|
95
|
+
/** The options of Telegram's post widget configurator (core.telegram.org/widgets/post). */
|
|
96
|
+
type TelegramOptions = {
|
|
97
|
+
/** Show the author's photo. */
|
|
98
|
+
userpic?: boolean;
|
|
99
|
+
/** Accent colour as hex, without `#`. */
|
|
100
|
+
color?: string;
|
|
101
|
+
dark?: boolean;
|
|
102
|
+
/** Accent colour in the dark theme, as hex without `#`. */
|
|
103
|
+
darkColor?: string;
|
|
104
|
+
};
|
|
105
|
+
type TelegramEmbedProps = EmbedSource & Omit<SharedProps, keyof TelegramOptions> & TelegramOptions;
|
|
106
|
+
/** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
|
|
107
|
+
export declare function TelegramEmbed(props: TelegramEmbedProps): import("react").JSX.Element | null;
|
|
54
108
|
type ThreadsOptions = {
|
|
55
109
|
/** `data-theme`; embed.js also reads `dark` and `auto` (docs/decisions.md D32). */
|
|
56
110
|
theme?: 'light' | 'dark' | 'auto';
|
|
@@ -77,6 +131,41 @@ type TikTokOptions = {
|
|
|
77
131
|
type TikTokEmbedProps = EmbedSource & Omit<FrameProps, keyof TikTokOptions> & TikTokOptions;
|
|
78
132
|
/** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
|
|
79
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;
|
|
80
169
|
/**
|
|
81
170
|
* `data-width` has no prop, because `width` is the wrapper's: the post fills the wrapper up
|
|
82
171
|
* to `maxWidth` (docs/decisions.md D33).
|
|
@@ -125,7 +214,7 @@ type SocialEmbedSource = {
|
|
|
125
214
|
url: string;
|
|
126
215
|
html?: never;
|
|
127
216
|
};
|
|
128
|
-
type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions;
|
|
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;
|
|
129
218
|
type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
|
|
130
219
|
/**
|
|
131
220
|
* Called with the original string when `html` is not a recognised embed code. Without
|
|
@@ -135,4 +224,17 @@ type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
|
|
|
135
224
|
};
|
|
136
225
|
/** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
|
|
137
226
|
export declare function SocialEmbed(props: SocialEmbedProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
138
|
-
|
|
227
|
+
type SnapchatEmbedProps = EmbedSource & FrameProps;
|
|
228
|
+
/** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
|
|
229
|
+
export declare function SnapchatEmbed(props: SnapchatEmbedProps): import("react").JSX.Element | null;
|
|
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 };
|