social-embeds 0.2.0 → 0.3.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 +113 -33
- package/dist/{index-CGSxjvGN.d.ts → index-7CfJ3zQZ.d.ts} +4 -9
- package/dist/index.d.ts +53 -31
- package/dist/index.js +354 -109
- package/dist/{parser-B-_erpaf.js → parser-HhmrfoYj.js} +337 -41
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +6 -6
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 and Pinterest
|
|
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,7 +34,7 @@ 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, and Telegram's `single` and `comment`.
|
|
38
38
|
|
|
39
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)).
|
|
40
40
|
|
|
@@ -85,6 +85,11 @@ Each platform component takes a `url`, or an `embed` already parsed by [`social-
|
|
|
85
85
|
import {
|
|
86
86
|
FacebookEmbed,
|
|
87
87
|
InstagramEmbed,
|
|
88
|
+
LinkedInEmbed,
|
|
89
|
+
PinterestEmbed,
|
|
90
|
+
RedditEmbed,
|
|
91
|
+
SnapchatEmbed,
|
|
92
|
+
TelegramEmbed,
|
|
88
93
|
ThreadsEmbed,
|
|
89
94
|
TikTokEmbed,
|
|
90
95
|
XEmbed,
|
|
@@ -110,6 +115,24 @@ import {
|
|
|
110
115
|
/>
|
|
111
116
|
|
|
112
117
|
<YouTubeEmbed url="https://youtu.be/jNQXAC9IVRw?t=90" nocookie controls={false} />
|
|
118
|
+
|
|
119
|
+
<TelegramEmbed url="https://t.me/telegram/83" dark userpic={false} />
|
|
120
|
+
|
|
121
|
+
<SnapchatEmbed url="https://www.snapchat.com/@teamsnapchat" />
|
|
122
|
+
|
|
123
|
+
<LinkedInEmbed
|
|
124
|
+
url="https://www.linkedin.com/feed/update/urn:li:activity:7527261038006697984/"
|
|
125
|
+
collapsed
|
|
126
|
+
height={560}
|
|
127
|
+
/>
|
|
128
|
+
|
|
129
|
+
<RedditEmbed
|
|
130
|
+
url="https://www.reddit.com/r/bulgaria/comments/1xz8iq4/"
|
|
131
|
+
theme="dark"
|
|
132
|
+
locale="bg-BG"
|
|
133
|
+
/>
|
|
134
|
+
|
|
135
|
+
<PinterestEmbed url="https://www.pinterest.com/pin/99360735500167749/" pinWidth="large" />
|
|
113
136
|
```
|
|
114
137
|
|
|
115
138
|
| Component | Option props |
|
|
@@ -120,8 +143,13 @@ import {
|
|
|
120
143
|
| `FacebookEmbed` | `locale` (SDK locale, default `'en_US'`), `showText`; videos also `allowfullscreen`, `autoplay`, `showCaptions` |
|
|
121
144
|
| `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` |
|
|
122
145
|
| `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) |
|
|
146
|
+
| `TelegramEmbed` | the widget configurator's options: `userpic`, `color` (hex, no `#`), `dark`, `darkColor` |
|
|
147
|
+
| `SnapchatEmbed` | none |
|
|
148
|
+
| `LinkedInEmbed` | `collapsed` (the Embed dialog's "less text") |
|
|
149
|
+
| `RedditEmbed` | `theme` (`'light'` \| `'dark'`), `showMedia`, `showTitle`, `showUsername`, `locale`, `depth` (replies under a comment) |
|
|
150
|
+
| `PinterestEmbed` | `pinWidth` (`'small'` \| `'medium'` \| `'large'`): `data-pin-width`, since `width` is the wrapper's |
|
|
123
151
|
|
|
124
|
-
Boolean player parameters are written as `1`/`0
|
|
152
|
+
Boolean player parameters are written as `1`/`0`; Telegram's and Reddit's options are written the way their own scripts write them.
|
|
125
153
|
|
|
126
154
|
### Parser
|
|
127
155
|
|
|
@@ -144,7 +172,18 @@ const embed = parseEmbed(code);
|
|
|
144
172
|
|
|
145
173
|
```ts
|
|
146
174
|
type ParsedEmbed = {
|
|
147
|
-
platform:
|
|
175
|
+
platform:
|
|
176
|
+
| 'x'
|
|
177
|
+
| 'instagram'
|
|
178
|
+
| 'facebook'
|
|
179
|
+
| 'threads'
|
|
180
|
+
| 'tiktok'
|
|
181
|
+
| 'youtube'
|
|
182
|
+
| 'telegram'
|
|
183
|
+
| 'snapchat'
|
|
184
|
+
| 'linkedin'
|
|
185
|
+
| 'reddit'
|
|
186
|
+
| 'pinterest';
|
|
148
187
|
kind: 'post' | 'video';
|
|
149
188
|
url: string; // canonical post URL
|
|
150
189
|
id: string;
|
|
@@ -165,37 +204,42 @@ import { YouTubeEmbed } from 'social-embeds';
|
|
|
165
204
|
}
|
|
166
205
|
```
|
|
167
206
|
|
|
168
|
-
A component checks an `embed` before using it: its `url` must be
|
|
207
|
+
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
208
|
|
|
170
209
|
## Shared props
|
|
171
210
|
|
|
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.
|
|
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-*`, …). |
|
|
225
|
+
|
|
226
|
+
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
227
|
|
|
189
228
|
## Platforms
|
|
190
229
|
|
|
191
|
-
| Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth`
|
|
192
|
-
| --------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
193
|
-
| 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
|
|
194
|
-
| 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
|
|
195
|
-
| 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
|
|
196
|
-
| 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
|
|
197
|
-
| TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325
|
|
198
|
-
| 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
|
|
230
|
+
| Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
|
|
231
|
+
| --------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
|
232
|
+
| 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 |
|
|
233
|
+
| 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 |
|
|
234
|
+
| 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 |
|
|
235
|
+
| 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 |
|
|
236
|
+
| TikTok | iframe ([Embed Player](https://developers.tiktok.com/doc/embed-player)) | `tiktok.com/@{user}/video/{id}` | every player query parameter | 325 |
|
|
237
|
+
| 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 |
|
|
238
|
+
| 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 |
|
|
239
|
+
| Snapchat | iframe (`{url}/embed`) | see [Snapchat](#snapchat) | `data-snapchat-embed-width`, `data-snapchat-embed-height`, `data-snapchat-embed-title` | 416 |
|
|
240
|
+
| 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 |
|
|
241
|
+
| 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 |
|
|
242
|
+
| 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 |
|
|
199
243
|
|
|
200
244
|
URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
|
|
201
245
|
|
|
@@ -257,9 +301,41 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
|
|
|
257
301
|
- Videos are 16:9 and Shorts URLs 9:16, unless embed code gives a `width` and `height`.
|
|
258
302
|
- Privacy-enhanced embed code (youtube-nocookie.com) stays on that host; `nocookie` sets it for other input.
|
|
259
303
|
|
|
304
|
+
### Telegram
|
|
305
|
+
|
|
306
|
+
- 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.
|
|
307
|
+
- Public channels and groups only: private links (`t.me/c/…`) are not recognised.
|
|
308
|
+
|
|
309
|
+
### Snapchat
|
|
310
|
+
|
|
311
|
+
- Every input renders Snapchat's `/embed` page for the content, in a 416:692 box unless the embed code gives another size.
|
|
312
|
+
- 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.
|
|
313
|
+
- A single public story (`/@{user}/{story id}`) and publisher stories (`/p/{id}`) have no embed page and are not recognised.
|
|
314
|
+
- On snapchat.com, the Embed button of a Spotlight video currently opens an app prompt instead of the code. The URL works.
|
|
315
|
+
- `data-snapchat-embed-style` is free-form CSS and is not applied.
|
|
316
|
+
|
|
317
|
+
### LinkedIn
|
|
318
|
+
|
|
319
|
+
- 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.
|
|
320
|
+
- In the EU, LinkedIn shows its own cookie banner inside the frame, over the top of the post, until the visitor answers it.
|
|
321
|
+
|
|
322
|
+
### Reddit
|
|
323
|
+
|
|
324
|
+
- Posts and single comments. The package builds the `embed.reddit.com` frame itself, without Reddit's script, and follows the height the frame reports.
|
|
325
|
+
- 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).
|
|
326
|
+
- Reddit may machine-translate the post into the visitor's language; `locale` sets the language.
|
|
327
|
+
- No fallback content: Reddit's embed code holds only the title, author and subreddit links.
|
|
328
|
+
|
|
329
|
+
### Pinterest
|
|
330
|
+
|
|
331
|
+
- 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.
|
|
332
|
+
- 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.
|
|
333
|
+
- A host page that already loaded `pinit.js` or `pinit_main.js` is reused.
|
|
334
|
+
- Boards and profiles are not supported.
|
|
335
|
+
|
|
260
336
|
### Not supported
|
|
261
337
|
|
|
262
|
-
- Redirecting short links: `fb.watch/…`, Facebook share links (`/share/p/…`, `/share/v/…`), `vm.tiktok.com/…` and `
|
|
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 `t.snapchat.com/…`. A redirect cannot be followed without a network request, and the package makes none. `matchUrl` returns `null`.
|
|
263
339
|
- Facebook group posts.
|
|
264
340
|
- Fetching embed code from oEmbed endpoints, consent gating and HTML sanitising: these stay with the host.
|
|
265
341
|
|
|
@@ -302,17 +378,21 @@ Client navigation needs nothing extra: each platform script loads once per page,
|
|
|
302
378
|
|
|
303
379
|
- **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
380
|
- **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.
|
|
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.
|
|
382
|
+
- **Pinterest**: the server HTML contains the pin's empty link and the placeholder.
|
|
306
383
|
- The server HTML never contains a platform `<script>`.
|
|
307
384
|
|
|
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
|
|
385
|
+
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
386
|
|
|
310
387
|
## Responsiveness
|
|
311
388
|
|
|
312
389
|
The host does nothing to make embeds responsive:
|
|
313
390
|
|
|
314
391
|
- **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.
|
|
392
|
+
- **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
|
+
- **Telegram and Reddit** get a wrapper of `width: 100%` and `max-width: {maxWidth}px` whose height follows the height the frame reports.
|
|
394
|
+
- **LinkedIn** has a fixed height (see [LinkedIn](#linkedin)).
|
|
395
|
+
- **Pinterest** pins have a fixed width; the wrapper's `max-width` defaults to it.
|
|
316
396
|
|
|
317
397
|
## License
|
|
318
398
|
|
|
@@ -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';
|
|
2
2
|
type ParsedEmbed = {
|
|
3
3
|
platform: Platform;
|
|
4
4
|
kind: 'post' | 'video';
|
|
@@ -12,16 +12,11 @@ type ParsedEmbed = {
|
|
|
12
12
|
};
|
|
13
13
|
fallbackHtml?: string;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Recognises a post URL. The result has no fallback content, and options only for data the
|
|
17
|
-
* URL itself carries (docs/decisions.md D13). Never throws.
|
|
18
|
-
*/
|
|
15
|
+
/** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
|
|
19
16
|
declare function matchUrl(url: string): ParsedEmbed | null;
|
|
20
17
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `<div id="fb-root">`, whitespace and comments. Anything else returns `null`
|
|
24
|
-
* (docs/decisions.md D14). Never throws.
|
|
18
|
+
* Never throws. `null` unless the input is one embed element plus, at most, the platform's
|
|
19
|
+
* own scripts, `<div id="fb-root">`, whitespace and comments (docs/decisions.md D14).
|
|
25
20
|
*/
|
|
26
21
|
declare function parseEmbed(html: string): ParsedEmbed | null;
|
|
27
22
|
export { Platform as i, matchUrl as n, ParsedEmbed as r, parseEmbed as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as ParsedEmbed } from "./index-
|
|
1
|
+
import { r as ParsedEmbed } from "./index-7CfJ3zQZ.js";
|
|
2
2
|
import { ComponentProps, ReactNode } from "react";
|
|
3
|
-
/** A platform component takes a post URL or an already-parsed embed (brief §5.2). */
|
|
4
3
|
type EmbedSource = {
|
|
5
4
|
url: string;
|
|
6
5
|
embed?: never;
|
|
@@ -8,7 +7,6 @@ type EmbedSource = {
|
|
|
8
7
|
embed: ParsedEmbed;
|
|
9
8
|
url?: never;
|
|
10
9
|
};
|
|
11
|
-
/** Props every embed component shares (brief §6). */
|
|
12
10
|
type SharedProps = Omit<ComponentProps<'div'>, 'children' | 'onLoad' | 'onError'> & {
|
|
13
11
|
/** Wrapper width. Default `'100%'`. */
|
|
14
12
|
width?: number | string;
|
|
@@ -23,7 +21,6 @@ type SharedProps = Omit<ComponentProps<'div'>, 'children' | 'onLoad' | 'onError'
|
|
|
23
21
|
/** Fires on invalid input, script load failure or init timeout. */
|
|
24
22
|
onError?: (error: Error) => void;
|
|
25
23
|
};
|
|
26
|
-
/** Iframe-based embeds (Group B) may also be given a fixed or a maximum height. */
|
|
27
24
|
type FrameProps = SharedProps & {
|
|
28
25
|
/** A fixed height in pixels, instead of the embed's aspect ratio. */
|
|
29
26
|
height?: number;
|
|
@@ -31,8 +28,7 @@ type FrameProps = SharedProps & {
|
|
|
31
28
|
maxHeight?: number;
|
|
32
29
|
};
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
* `data-lazy` have no props, because `width` and `lazy` are the wrapper's
|
|
31
|
+
* `data-width` and `data-lazy` have no props, because `width` and `lazy` are the wrapper's
|
|
36
32
|
* (docs/decisions.md D33).
|
|
37
33
|
*/
|
|
38
34
|
type FacebookOptions = {
|
|
@@ -48,12 +44,6 @@ type FacebookOptions = {
|
|
|
48
44
|
};
|
|
49
45
|
/** `height` and `maxHeight` apply only to a video that renders as an iframe. */
|
|
50
46
|
type FacebookEmbedProps = EmbedSource & Omit<FrameProps, keyof FacebookOptions> & FacebookOptions;
|
|
51
|
-
/**
|
|
52
|
-
* Facebook rendering rules (brief §5.4): posts always through the SDK; video embed code as
|
|
53
|
-
* the iframe that came in; video URLs through the SDK. The parser has set `variant`.
|
|
54
|
-
* Video embed code that shows the post text also goes through the SDK (D44), unless
|
|
55
|
-
* `showText` turns the text off: then it is the plain iframe (D45).
|
|
56
|
-
*/
|
|
57
47
|
export declare function FacebookEmbed(props: FacebookEmbedProps): import("react").JSX.Element | null;
|
|
58
48
|
type InstagramOptions = {
|
|
59
49
|
/** Show the caption (`data-instgrm-captioned`). */
|
|
@@ -61,6 +51,46 @@ type InstagramOptions = {
|
|
|
61
51
|
};
|
|
62
52
|
type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
|
|
63
53
|
export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").JSX.Element | null;
|
|
54
|
+
type LinkedInOptions = {
|
|
55
|
+
/** The Embed dialog's "less text" option. */
|
|
56
|
+
collapsed?: boolean;
|
|
57
|
+
};
|
|
58
|
+
type LinkedInEmbedProps = EmbedSource & Omit<FrameProps, keyof LinkedInOptions> & LinkedInOptions;
|
|
59
|
+
/** A fixed height: the `height` prop, else the embed code's, else 670px. */
|
|
60
|
+
export declare function LinkedInEmbed(props: LinkedInEmbedProps): import("react").JSX.Element | null;
|
|
61
|
+
/** `pinWidth` is `data-pin-width`; `width` stays the wrapper's. */
|
|
62
|
+
type PinterestOptions = {
|
|
63
|
+
pinWidth?: 'small' | 'medium' | 'large';
|
|
64
|
+
};
|
|
65
|
+
type PinterestEmbedProps = EmbedSource & Omit<SharedProps, keyof PinterestOptions> & PinterestOptions;
|
|
66
|
+
export declare function PinterestEmbed(props: PinterestEmbedProps): import("react").JSX.Element | null;
|
|
67
|
+
/** The `data-embed-*` options of Reddit's embed code that hosts set most. */
|
|
68
|
+
type RedditOptions = {
|
|
69
|
+
theme?: 'light' | 'dark';
|
|
70
|
+
showMedia?: boolean;
|
|
71
|
+
showTitle?: boolean;
|
|
72
|
+
showUsername?: boolean;
|
|
73
|
+
/** Language of the post, which Reddit machine-translates (docs/decisions.md D52). */
|
|
74
|
+
locale?: string;
|
|
75
|
+
/** Replies shown under an embedded comment. */
|
|
76
|
+
depth?: number;
|
|
77
|
+
};
|
|
78
|
+
type RedditEmbedProps = EmbedSource & Omit<SharedProps, keyof RedditOptions> & RedditOptions;
|
|
79
|
+
/** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
|
|
80
|
+
export declare function RedditEmbed(props: RedditEmbedProps): import("react").JSX.Element | null;
|
|
81
|
+
/** The options of Telegram's post widget configurator (core.telegram.org/widgets/post). */
|
|
82
|
+
type TelegramOptions = {
|
|
83
|
+
/** Show the author's photo. */
|
|
84
|
+
userpic?: boolean;
|
|
85
|
+
/** Accent colour as hex, without `#`. */
|
|
86
|
+
color?: string;
|
|
87
|
+
dark?: boolean;
|
|
88
|
+
/** Accent colour in the dark theme, as hex without `#`. */
|
|
89
|
+
darkColor?: string;
|
|
90
|
+
};
|
|
91
|
+
type TelegramEmbedProps = EmbedSource & Omit<SharedProps, keyof TelegramOptions> & TelegramOptions;
|
|
92
|
+
/** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
|
|
93
|
+
export declare function TelegramEmbed(props: TelegramEmbedProps): import("react").JSX.Element | null;
|
|
64
94
|
type ThreadsOptions = {
|
|
65
95
|
/** `data-theme`; embed.js also reads `dark` and `auto` (docs/decisions.md D32). */
|
|
66
96
|
theme?: 'light' | 'dark' | 'auto';
|
|
@@ -85,14 +115,11 @@ type TikTokOptions = {
|
|
|
85
115
|
forceMuted?: boolean;
|
|
86
116
|
};
|
|
87
117
|
type TikTokEmbedProps = EmbedSource & Omit<FrameProps, keyof TikTokOptions> & TikTokOptions;
|
|
88
|
-
/**
|
|
89
|
-
* Every TikTok input renders the Embed Player iframe (docs/decisions.md D11). It is at
|
|
90
|
-
* most 325px wide, the size of TikTok's own embed code (D40).
|
|
91
|
-
*/
|
|
118
|
+
/** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
|
|
92
119
|
export declare function TikTokEmbed(props: TikTokEmbedProps): import("react").JSX.Element | null;
|
|
93
120
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
121
|
+
* `data-width` has no prop, because `width` is the wrapper's: the post fills the wrapper up
|
|
122
|
+
* to `maxWidth` (docs/decisions.md D33).
|
|
96
123
|
*/
|
|
97
124
|
type XOptions = {
|
|
98
125
|
theme?: 'light' | 'dark';
|
|
@@ -131,7 +158,6 @@ type YouTubeOptions = {
|
|
|
131
158
|
};
|
|
132
159
|
type YouTubeEmbedProps = EmbedSource & Omit<FrameProps, keyof YouTubeOptions> & YouTubeOptions;
|
|
133
160
|
export declare function YouTubeEmbed(props: YouTubeEmbedProps): import("react").JSX.Element | null;
|
|
134
|
-
/** Embed code or a post URL; never both (brief §5.2). */
|
|
135
161
|
type SocialEmbedSource = {
|
|
136
162
|
html: string;
|
|
137
163
|
url?: never;
|
|
@@ -139,21 +165,17 @@ type SocialEmbedSource = {
|
|
|
139
165
|
url: string;
|
|
140
166
|
html?: never;
|
|
141
167
|
};
|
|
142
|
-
|
|
143
|
-
* Platform options come from the embed code. Div attributes that share a name with one
|
|
144
|
-
* (`lang`, `color`, `rel`) are left out, because each platform reads that name its own way.
|
|
145
|
-
*/
|
|
146
|
-
type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions;
|
|
168
|
+
type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions | keyof TelegramOptions | keyof RedditOptions | keyof LinkedInOptions | keyof PinterestOptions;
|
|
147
169
|
type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
|
|
148
170
|
/**
|
|
149
|
-
* Called with the original string when `html` is not a recognised embed code
|
|
150
|
-
*
|
|
171
|
+
* Called with the original string when `html` is not a recognised embed code. Without
|
|
172
|
+
* it, nothing is rendered and `onError` is called.
|
|
151
173
|
*/
|
|
152
174
|
fallback?: (html: string) => ReactNode;
|
|
153
175
|
};
|
|
154
|
-
/**
|
|
155
|
-
* Recognises embed code or a post URL and renders the platform's component. `height` and
|
|
156
|
-
* `maxHeight` reach only the iframe-based embeds; the others size themselves (brief §6.1).
|
|
157
|
-
*/
|
|
176
|
+
/** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
|
|
158
177
|
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;
|
|
159
|
-
|
|
178
|
+
type SnapchatEmbedProps = EmbedSource & FrameProps;
|
|
179
|
+
/** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
|
|
180
|
+
export declare function SnapchatEmbed(props: SnapchatEmbedProps): import("react").JSX.Element | null;
|
|
181
|
+
export type { EmbedSource, FacebookEmbedProps, FacebookOptions, FrameProps, InstagramEmbedProps, InstagramOptions, LinkedInEmbedProps, LinkedInOptions, PinterestEmbedProps, PinterestOptions, RedditEmbedProps, RedditOptions, SharedProps, SnapchatEmbedProps, SocialEmbedProps, SocialEmbedSource, TelegramEmbedProps, TelegramOptions, ThreadsEmbedProps, ThreadsOptions, TikTokEmbedProps, TikTokOptions, XEmbedProps, XOptions, YouTubeEmbedProps, YouTubeOptions };
|