social-embeds 0.2.1 → 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 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 YouTube
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`) and 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, 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: 'x' | 'instagram' | 'facebook' | 'threads' | 'tiktok' | 'youtube';
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 one `matchUrl` recognises 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.
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` | | Iframe-based embeds only (YouTube, TikTok, Facebook video embed code): a fixed height instead of the aspect ratio. The others size themselves. |
180
- | `maxHeight` | `number` | | Iframe-based 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. |
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 `vt.tiktok.com/…`. A redirect cannot be followed without a network request, and the package makes none. `matchUrl` returns `null`.
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 class 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.
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';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as ParsedEmbed } from "./index-DCF8EEVz.js";
1
+ import { r as ParsedEmbed } from "./index-7CfJ3zQZ.js";
2
2
  import { ComponentProps, ReactNode } from "react";
3
3
  type EmbedSource = {
4
4
  url: string;
@@ -51,6 +51,46 @@ type InstagramOptions = {
51
51
  };
52
52
  type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
53
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;
54
94
  type ThreadsOptions = {
55
95
  /** `data-theme`; embed.js also reads `dark` and `auto` (docs/decisions.md D32). */
56
96
  theme?: 'light' | 'dark' | 'auto';
@@ -125,7 +165,7 @@ type SocialEmbedSource = {
125
165
  url: string;
126
166
  html?: never;
127
167
  };
128
- 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;
129
169
  type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
130
170
  /**
131
171
  * Called with the original string when `html` is not a recognised embed code. Without
@@ -135,4 +175,7 @@ type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
135
175
  };
136
176
  /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
137
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;
138
- export type { EmbedSource, FacebookEmbedProps, FacebookOptions, FrameProps, InstagramEmbedProps, InstagramOptions, SharedProps, SocialEmbedProps, SocialEmbedSource, ThreadsEmbedProps, ThreadsOptions, TikTokEmbedProps, TikTokOptions, XEmbedProps, XOptions, YouTubeEmbedProps, YouTubeOptions };
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 };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { a as escapeAttribute, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-BrlUKvvo.js";
3
- import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { a as escapeAttribute, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-HhmrfoYj.js";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/loader/load-script.ts
6
6
  const ATTEMPTS$1 = 3;
@@ -161,11 +161,18 @@ function facebook(locale) {
161
161
  })
162
162
  };
163
163
  }
164
+ const pinterest = {
165
+ key: "pinterest",
166
+ url: "https://assets.pinterest.com/js/pinit_main.js",
167
+ isOwn: (src) => /^https?:\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js(?:[?#]|$)/.test(src),
168
+ isPresent: () => typeof globals$1().PinUtils?.build === "function"
169
+ };
164
170
  function loadPlatformScript(platform, { locale = "en_US" } = {}) {
165
171
  switch (platform) {
166
172
  case "x": return loadScript(x);
167
173
  case "instagram": return loadScript(instagram);
168
174
  case "threads": return loadScript(threads);
175
+ case "pinterest": return loadScript(pinterest);
169
176
  case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
170
177
  }
171
178
  }
@@ -273,6 +280,18 @@ function facebookDriver(locale) {
273
280
  }
274
281
  return driver;
275
282
  }
283
+ const pinterestDriver = {
284
+ load: () => loadPlatformScript("pinterest"),
285
+ render(container, done) {
286
+ const build = globals().PinUtils?.build;
287
+ if (!build) throw new Error("social-embeds: PinUtils.build is missing");
288
+ const stop = watch(container, (element) => element.querySelector("span[data-pin-id]") !== null, done);
289
+ const link = container.querySelector("a");
290
+ if (link && !link.hasAttribute("data-pin-do")) link.setAttribute("data-pin-do", "embedPin");
291
+ build(container);
292
+ return stop;
293
+ }
294
+ };
276
295
  // src/components/hooks.ts
277
296
  const ROOT_MARGIN = "200px 0px";
278
297
  /** False on the server and in the first client render, so the markup matches on hydration. */
@@ -312,11 +331,65 @@ const FILL = {
312
331
  position: "absolute",
313
332
  inset: 0
314
333
  };
315
- function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, ratio, size, width = "100%", maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, style, ...rest }) {
334
+ const HEIGHT_TIMEOUT_MS = 15e3;
335
+ const MAX_REPORTED_HEIGHT = 5e4;
336
+ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, width = "100%", maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
316
337
  const frame = useRef(null);
338
+ const iframe = useRef(null);
317
339
  const near = useNearViewport(frame, lazy);
318
340
  const [loaded, setLoaded] = useState(false);
341
+ const [reportedHeight, setReportedHeight] = useState();
319
342
  const reported = useRef(false);
343
+ const callbacks = useRef({
344
+ onLoad,
345
+ onError
346
+ });
347
+ useEffect(() => {
348
+ callbacks.current = {
349
+ onLoad,
350
+ onError
351
+ };
352
+ });
353
+ const report = useCallback(() => {
354
+ setLoaded(true);
355
+ if (reported.current) return;
356
+ reported.current = true;
357
+ callbacks.current.onLoad?.();
358
+ }, []);
359
+ useEffect(() => {
360
+ if (!near || !messageHeight) return;
361
+ const { origin, read } = messageHeight;
362
+ let heard = false;
363
+ const listen = (event) => {
364
+ if (event.origin !== origin) return;
365
+ if (!iframe.current || event.source !== iframe.current.contentWindow) return;
366
+ let value;
367
+ try {
368
+ value = read(event.data);
369
+ } catch {
370
+ return;
371
+ }
372
+ if (typeof value !== "number" || !(value > 0 && value <= MAX_REPORTED_HEIGHT)) return;
373
+ heard = true;
374
+ setReportedHeight(Math.ceil(value));
375
+ report();
376
+ };
377
+ window.addEventListener("message", listen);
378
+ const timer = setTimeout(() => {
379
+ if (heard) return;
380
+ setLoaded(true);
381
+ callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} did not report its height`));
382
+ }, HEIGHT_TIMEOUT_MS);
383
+ return () => {
384
+ window.removeEventListener("message", listen);
385
+ clearTimeout(timer);
386
+ };
387
+ }, [
388
+ near,
389
+ messageHeight,
390
+ title,
391
+ report
392
+ ]);
320
393
  const aspectWidth = size?.width ?? ratio.width;
321
394
  const aspectHeight = size?.height ?? ratio.height;
322
395
  const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
@@ -324,7 +397,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, ratio, size
324
397
  position: "relative",
325
398
  width,
326
399
  maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
327
- ...height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
400
+ ...messageHeight ? { height: reportedHeight ?? startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
328
401
  height,
329
402
  maxHeight
330
403
  },
@@ -337,12 +410,14 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, ratio, size
337
410
  ref: frame,
338
411
  style: FILL,
339
412
  children: [near && /* @__PURE__ */ jsx("iframe", {
413
+ ref: iframe,
340
414
  src,
341
415
  title,
342
416
  allow,
343
417
  allowFullScreen: true,
344
418
  referrerPolicy,
345
419
  scrolling,
420
+ sandbox,
346
421
  style: {
347
422
  display: "block",
348
423
  width: "100%",
@@ -350,10 +425,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, ratio, size
350
425
  border: 0
351
426
  },
352
427
  onLoad: () => {
353
- setLoaded(true);
354
- if (reported.current) return;
355
- reported.current = true;
356
- onLoad?.();
428
+ if (!messageHeight) report();
357
429
  }
358
430
  }), !loaded && /* @__PURE__ */ jsx("div", {
359
431
  style: FILL,
@@ -384,7 +456,12 @@ const SHAPES = {
384
456
  "video iframe"
385
457
  ],
386
458
  tiktok: ["video iframe"],
387
- youtube: ["video iframe"]
459
+ youtube: ["video iframe"],
460
+ telegram: ["post iframe"],
461
+ snapchat: ["post iframe", "video iframe"],
462
+ linkedin: ["post iframe"],
463
+ reddit: ["post iframe"],
464
+ pinterest: ["post sdk"]
388
465
  };
389
466
  /**
390
467
  * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
@@ -393,6 +470,7 @@ const SHAPES = {
393
470
  function verifyEmbed(embed) {
394
471
  const matched = matchUrl(embed.url);
395
472
  if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
473
+ if (matched.url !== embed.url) return null;
396
474
  if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
397
475
  if (embed.fallbackHtml === void 0) return embed;
398
476
  if (trustedFallback(embed, embed.fallbackHtml)) return embed;
@@ -415,7 +493,12 @@ const NAMES = {
415
493
  facebook: "Facebook",
416
494
  threads: "Threads",
417
495
  tiktok: "TikTok",
418
- youtube: "YouTube"
496
+ youtube: "YouTube",
497
+ telegram: "Telegram",
498
+ snapchat: "Snapchat",
499
+ linkedin: "LinkedIn",
500
+ reddit: "Reddit",
501
+ pinterest: "Pinterest"
419
502
  };
420
503
  function resolveEmbed(url, given, platform) {
421
504
  const embed = given ?? (url === void 0 ? null : matchUrl(url));
@@ -443,14 +526,14 @@ function playerParams(props, names) {
443
526
  return params;
444
527
  }
445
528
  // src/components/facebook-video-iframe.tsx
446
- const ALLOW$2 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
529
+ const ALLOW$4 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
447
530
  function FacebookVideoIframe({ embed, ...frame }) {
448
531
  const params = Object.entries(embed.options).filter(([key]) => key !== "href");
449
532
  return /* @__PURE__ */ jsx(IframeEmbed, {
450
533
  ...frame,
451
534
  src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
452
535
  title: "Facebook video player",
453
- allow: ALLOW$2,
536
+ allow: ALLOW$4,
454
537
  scrolling: "no",
455
538
  ratio: {
456
539
  width: 16,
@@ -578,7 +661,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
578
661
  });
579
662
  }
580
663
  // src/components/facebook-embed.tsx
581
- const ATTRIBUTES$1 = {
664
+ const ATTRIBUTES$2 = {
582
665
  width: "data-width",
583
666
  showText: "data-show-text",
584
667
  lazy: "data-lazy",
@@ -595,7 +678,7 @@ const PLAYER_PARAMETERS = {
595
678
  /** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
596
679
  const POST_MAX_WIDTH = 750;
597
680
  /** docs/decisions.md D34. */
598
- const MIN_HEIGHT$3 = {
681
+ const MIN_HEIGHT$4 = {
599
682
  post: 300,
600
683
  video: 200
601
684
  };
@@ -638,7 +721,7 @@ function FacebookEmbed(props) {
638
721
  });
639
722
  }
640
723
  const sdkLocale = locale ?? (typeof options.locale === "string" ? options.locale : "en_US");
641
- const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, options)}>${embed.fallbackHtml ?? ""}</div>`;
724
+ const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, options)}>${embed.fallbackHtml ?? ""}</div>`;
642
725
  return /* @__PURE__ */ jsx(ScriptEmbed, {
643
726
  maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0,
644
727
  ...shared,
@@ -646,13 +729,13 @@ function FacebookEmbed(props) {
646
729
  driver: facebookDriver(sdkLocale),
647
730
  markup,
648
731
  hasFallback: hasFallback(embed.fallbackHtml),
649
- minHeight: MIN_HEIGHT$3[embed.kind],
732
+ minHeight: MIN_HEIGHT$4[embed.kind],
650
733
  label: "Facebook"
651
734
  }, `${sdkLocale} ${markup}`);
652
735
  }
653
736
  // src/components/instagram-embed.tsx
654
737
  /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
655
- const MIN_HEIGHT$2 = 680;
738
+ const MIN_HEIGHT$3 = 680;
656
739
  const FLUID_WIDTH = "width:calc(100% - 2px)";
657
740
  function InstagramEmbed(props) {
658
741
  const { url, embed: given, onError, maxWidth = 540, captioned, ...shared } = props;
@@ -673,10 +756,209 @@ function InstagramEmbed(props) {
673
756
  driver: instagramDriver,
674
757
  markup,
675
758
  hasFallback: hasFallback(embed.fallbackHtml),
676
- minHeight: MIN_HEIGHT$2,
759
+ minHeight: MIN_HEIGHT$3,
677
760
  label: "Instagram"
678
761
  }, markup);
679
762
  }
763
+ // src/components/linkedin-embed.tsx
764
+ const DEFAULT_HEIGHT = 670;
765
+ const DEFAULT_WIDTH = 504;
766
+ /** A fixed height: the `height` prop, else the embed code's, else 670px. */
767
+ function LinkedInEmbed(props) {
768
+ const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
769
+ const { embed, error } = resolveEmbed(url, given, "linkedin");
770
+ useReportError(error, onError);
771
+ if (!embed) return null;
772
+ const params = new Map(Object.entries(embed.options));
773
+ if (collapsed === true) params.set("collapsed", 1);
774
+ if (collapsed === false) params.delete("collapsed");
775
+ return /* @__PURE__ */ jsx(IframeEmbed, {
776
+ ...frame,
777
+ maxWidth: maxWidth ?? embed.size?.width ?? DEFAULT_WIDTH,
778
+ height: height ?? embed.size?.height ?? DEFAULT_HEIGHT,
779
+ src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
780
+ title: "LinkedIn post",
781
+ allow: "",
782
+ ratio: {
783
+ width: DEFAULT_WIDTH,
784
+ height: DEFAULT_HEIGHT
785
+ }
786
+ });
787
+ }
788
+ // src/components/pinterest-embed.tsx
789
+ const ATTRIBUTES$1 = {
790
+ width: "data-pin-width",
791
+ lang: "data-pin-lang",
792
+ terse: "data-pin-terse"
793
+ };
794
+ const PIN_WIDTHS = {
795
+ small: 236,
796
+ medium: 345,
797
+ large: 600
798
+ };
799
+ const DEFAULT_PIN_WIDTH = 236;
800
+ const MIN_HEIGHT$2 = 270;
801
+ function PinterestEmbed(props) {
802
+ const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
803
+ const { embed, error } = resolveEmbed(url, given, "pinterest");
804
+ useReportError(error, onError);
805
+ if (!embed) return null;
806
+ const options = withProps(embed.options, { width: pinWidth });
807
+ const pinWidthPx = PIN_WIDTHS[String(options.width)] ?? DEFAULT_PIN_WIDTH;
808
+ const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, options)}></a>`;
809
+ return /* @__PURE__ */ jsx(ScriptEmbed, {
810
+ ...shared,
811
+ onError,
812
+ maxWidth: maxWidth ?? pinWidthPx,
813
+ driver: pinterestDriver,
814
+ markup,
815
+ hasFallback: false,
816
+ minHeight: MIN_HEIGHT$2,
817
+ label: "Pinterest"
818
+ }, markup);
819
+ }
820
+ // src/components/reddit-embed.tsx
821
+ const PARAMS$3 = {
822
+ theme: "theme",
823
+ showMedia: "showmedia",
824
+ showTitle: "showtitle",
825
+ showUsername: "showusername",
826
+ locale: "locale",
827
+ depth: "depth"
828
+ };
829
+ const SANDBOX = "allow-scripts allow-same-origin allow-popups";
830
+ const ALLOW$3 = "clipboard-read; clipboard-write";
831
+ const START_HEIGHT = 316;
832
+ /** docs/decisions.md D52. */
833
+ const REDDIT_HEIGHT = {
834
+ origin: "https://embed.reddit.com",
835
+ read(data) {
836
+ if (typeof data !== "string") return void 0;
837
+ const message = JSON.parse(data);
838
+ return message.type === "resize.embed" && typeof message.data === "number" ? message.data : void 0;
839
+ }
840
+ };
841
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
842
+ function RedditEmbed(props) {
843
+ const { url, embed: given, onError, maxWidth = 640, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
844
+ const { embed, error } = resolveEmbed(url, given, "reddit");
845
+ useReportError(error, onError);
846
+ if (!embed) return null;
847
+ const fromProps = [];
848
+ const values = {
849
+ theme,
850
+ showMedia,
851
+ showTitle,
852
+ showUsername,
853
+ locale,
854
+ depth
855
+ };
856
+ for (const [prop, name] of Object.entries(PARAMS$3)) {
857
+ const value = values[prop];
858
+ if (value !== void 0) fromProps.push([name, value]);
859
+ }
860
+ const path = embed.url.slice(22);
861
+ return /* @__PURE__ */ jsx(IframeEmbed, {
862
+ ...shared,
863
+ onError,
864
+ maxWidth,
865
+ src: `https://embed.reddit.com${path}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
866
+ title: "Reddit post",
867
+ allow: ALLOW$3,
868
+ sandbox: SANDBOX,
869
+ scrolling: "no",
870
+ ratio: {
871
+ width: 1,
872
+ height: 1
873
+ },
874
+ messageHeight: REDDIT_HEIGHT,
875
+ startHeight: embed.size?.height ?? START_HEIGHT
876
+ });
877
+ }
878
+ // src/components/snapchat-embed.tsx
879
+ const ALLOW$2 = "autoplay; camera; microphone; clipboard-write;";
880
+ /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
881
+ function SnapchatEmbed(props) {
882
+ const { url, embed: given, onError, maxWidth = 416, ...frame } = props;
883
+ const { embed, error } = resolveEmbed(url, given, "snapchat");
884
+ useReportError(error, onError);
885
+ if (!embed) return null;
886
+ const title = embed.options.title;
887
+ return /* @__PURE__ */ jsx(IframeEmbed, {
888
+ ...frame,
889
+ maxWidth,
890
+ src: `${embed.url}/embed`,
891
+ title: typeof title === "string" && title !== "" ? title : "Snapchat",
892
+ allow: ALLOW$2,
893
+ scrolling: "no",
894
+ ratio: {
895
+ width: 416,
896
+ height: 692
897
+ },
898
+ size: embed.size
899
+ });
900
+ }
901
+ // src/components/telegram-embed.tsx
902
+ const PARAMS$2 = [
903
+ ["comment", "comment"],
904
+ ["userpic", "userpic"],
905
+ ["mode", "mode"],
906
+ ["single", "single"],
907
+ ["color", "color"],
908
+ ["dark", "dark"],
909
+ ["darkColor", "dark_color"]
910
+ ];
911
+ function param(name, value) {
912
+ if (typeof value === "boolean") {
913
+ if (name === "userpic") return String(value);
914
+ if (name === "single") return value ? 1 : void 0;
915
+ return value ? 1 : 0;
916
+ }
917
+ return typeof value === "string" || typeof value === "number" ? value : void 0;
918
+ }
919
+ /** docs/decisions.md D49. */
920
+ const TELEGRAM_HEIGHT = {
921
+ origin: "https://t.me",
922
+ read(data) {
923
+ if (typeof data !== "string") return void 0;
924
+ const message = JSON.parse(data);
925
+ return message.event === "resize" && typeof message.height === "number" ? message.height : void 0;
926
+ }
927
+ };
928
+ /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
929
+ function TelegramEmbed(props) {
930
+ const { url, embed: given, onError, maxWidth = 500, userpic, color, dark, darkColor, ...shared } = props;
931
+ const { embed, error } = resolveEmbed(url, given, "telegram");
932
+ useReportError(error, onError);
933
+ if (!embed) return null;
934
+ const values = {
935
+ ...embed.options,
936
+ ...userpic === void 0 ? {} : { userpic },
937
+ ...color === void 0 ? {} : { color },
938
+ ...dark === void 0 ? {} : { dark },
939
+ ...darkColor === void 0 ? {} : { darkColor }
940
+ };
941
+ const params = [["embed", 1]];
942
+ for (const [option, name] of PARAMS$2) {
943
+ const value = param(name, values[option]);
944
+ if (value !== void 0) params.push([name, value]);
945
+ }
946
+ return /* @__PURE__ */ jsx(IframeEmbed, {
947
+ ...shared,
948
+ onError,
949
+ maxWidth,
950
+ src: `${embed.url}${query(params)}`,
951
+ title: "Telegram post",
952
+ allow: "",
953
+ scrolling: "no",
954
+ ratio: {
955
+ width: 1,
956
+ height: 1
957
+ },
958
+ messageHeight: TELEGRAM_HEIGHT,
959
+ startHeight: 300
960
+ });
961
+ }
680
962
  // src/components/threads-embed.tsx
681
963
  /** A text-only post (docs/decisions.md D34). */
682
964
  const MIN_HEIGHT$1 = 240;
@@ -908,6 +1190,33 @@ function SocialEmbed(props) {
908
1190
  onError,
909
1191
  embed
910
1192
  });
1193
+ case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
1194
+ ...shared,
1195
+ onError,
1196
+ embed
1197
+ });
1198
+ case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
1199
+ ...shared,
1200
+ ...frame,
1201
+ onError,
1202
+ embed
1203
+ });
1204
+ case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
1205
+ ...shared,
1206
+ ...frame,
1207
+ onError,
1208
+ embed
1209
+ });
1210
+ case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
1211
+ ...shared,
1212
+ onError,
1213
+ embed
1214
+ });
1215
+ case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
1216
+ ...shared,
1217
+ onError,
1218
+ embed
1219
+ });
911
1220
  }
912
1221
  }
913
- export { FacebookEmbed, InstagramEmbed, SocialEmbed, ThreadsEmbed, TikTokEmbed, XEmbed, YouTubeEmbed };
1222
+ export { FacebookEmbed, InstagramEmbed, LinkedInEmbed, PinterestEmbed, RedditEmbed, SnapchatEmbed, SocialEmbed, TelegramEmbed, ThreadsEmbed, TikTokEmbed, XEmbed, YouTubeEmbed };
@@ -231,7 +231,7 @@ function withSize(embed, size) {
231
231
  } : embed;
232
232
  }
233
233
  // src/parser/platforms/facebook.ts
234
- const HOSTS$4 = /* @__PURE__ */ new Set([
234
+ const HOSTS$7 = /* @__PURE__ */ new Set([
235
235
  "facebook.com",
236
236
  "www.facebook.com",
237
237
  "m.facebook.com"
@@ -240,7 +240,7 @@ const PLUGIN_HOSTS = /* @__PURE__ */ new Set(["facebook.com", "www.facebook.com"
240
240
  const BASE = "https://www.facebook.com";
241
241
  const NAME = "[A-Za-z0-9.\\-]{1,80}";
242
242
  const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
243
- const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
243
+ const POSTS_PATH$1 = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
244
244
  const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
245
245
  const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
246
246
  const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
@@ -252,8 +252,8 @@ const PHOTO_PATHS = /* @__PURE__ */ new Set([
252
252
  ]);
253
253
  const STORY_ID = new RegExp(`^${POST_ID}$`);
254
254
  const NUMERIC_ID = /^\d{1,25}$/;
255
- const SCRIPT$4 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
256
- const OPTION_ATTRIBUTES$2 = [
255
+ const SCRIPT$8 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
256
+ const OPTION_ATTRIBUTES$5 = [
257
257
  ["data-width", "width"],
258
258
  ["data-show-text", "showText"],
259
259
  ["data-lazy", "lazy"],
@@ -278,9 +278,9 @@ const FALLBACK$3 = /* @__PURE__ */ new Map([
278
278
  ["p", []]
279
279
  ]);
280
280
  function target(url) {
281
- if (!url || !HOSTS$4.has(url.host)) return null;
281
+ if (!url || !HOSTS$7.has(url.host)) return null;
282
282
  const { path, query } = url;
283
- const [, name, postId] = POSTS_PATH.exec(path) ?? [];
283
+ const [, name, postId] = POSTS_PATH$1.exec(path) ?? [];
284
284
  if (name !== void 0 && postId !== void 0) return {
285
285
  kind: "post",
286
286
  id: postId,
@@ -354,7 +354,7 @@ const facebook = {
354
354
  const found = target(parseUrl(root.attrs.get("data-href") ?? ""));
355
355
  if (!kind || !found) return null;
356
356
  return {
357
- ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$2, coerce)),
357
+ ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$5, coerce)),
358
358
  fallbackHtml: rebuild(root.children, FALLBACK$3)
359
359
  };
360
360
  }
@@ -393,9 +393,9 @@ const facebook = {
393
393
  }
394
394
  return null;
395
395
  },
396
- isOwnScript: (src) => SCRIPT$4.test(src),
396
+ isOwnScript: (src) => SCRIPT$8.test(src),
397
397
  scriptOptions(src) {
398
- const [, locale] = SCRIPT$4.exec(src) ?? [];
398
+ const [, locale] = SCRIPT$8.exec(src) ?? [];
399
399
  return locale === void 0 ? {} : { locale };
400
400
  },
401
401
  allowsFbRoot: true,
@@ -405,8 +405,8 @@ const facebook = {
405
405
  }
406
406
  };
407
407
  // src/parser/platforms/instagram.ts
408
- const HOSTS$3 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
409
- const POST_PATH$1 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
408
+ const HOSTS$6 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
409
+ const POST_PATH$3 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
410
410
  const TYPES = /* @__PURE__ */ new Set([
411
411
  "p",
412
412
  "reel",
@@ -414,15 +414,15 @@ const TYPES = /* @__PURE__ */ new Set([
414
414
  "tv"
415
415
  ]);
416
416
  const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
417
- const SCRIPT$3 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
417
+ const SCRIPT$7 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
418
418
  const FALLBACK$2 = /* @__PURE__ */ new Map([
419
419
  ["div", []],
420
420
  ["a", ["href"]],
421
421
  ["p", []]
422
422
  ]);
423
- function post$2(url) {
424
- if (!url || !HOSTS$3.has(url.host)) return null;
425
- const [, user, type, code] = POST_PATH$1.exec(url.path) ?? [];
423
+ function post$5(url) {
424
+ if (!url || !HOSTS$6.has(url.host)) return null;
425
+ const [, user, type, code] = POST_PATH$3.exec(url.path) ?? [];
426
426
  if (type === void 0 || code === void 0) return null;
427
427
  if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
428
428
  return {
@@ -439,7 +439,7 @@ const instagram = {
439
439
  parse(root) {
440
440
  if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
441
441
  const permalink = root.attrs.get("data-instgrm-permalink");
442
- const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$2(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$2(parseUrl(permalink));
442
+ const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$5(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$5(parseUrl(permalink));
443
443
  if (!found) return null;
444
444
  const options = {};
445
445
  if (root.attrs.has("data-instgrm-captioned")) options.captioned = true;
@@ -451,15 +451,310 @@ const instagram = {
451
451
  fallbackHtml: rebuild(root.children, FALLBACK$2)
452
452
  };
453
453
  },
454
- isOwnScript: (src) => SCRIPT$3.test(src),
454
+ isOwnScript: (src) => SCRIPT$7.test(src),
455
455
  match(url) {
456
- const found = post$2(url);
456
+ const found = post$5(url);
457
457
  return found && {
458
458
  ...found,
459
459
  options: {}
460
460
  };
461
461
  }
462
462
  };
463
+ // src/parser/platforms/linkedin.ts
464
+ const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
465
+ const URN = "(activity|share|ugcPost):(\\d{19})";
466
+ const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
467
+ const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
468
+ const EMBED_PATH$1 = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
469
+ function post$4(type, id, options = {}) {
470
+ const urn = `urn:li:${type}:${id}`;
471
+ return {
472
+ platform: "linkedin",
473
+ kind: "post",
474
+ url: `https://www.linkedin.com/feed/update/${urn}/`,
475
+ id: urn,
476
+ variant: "iframe",
477
+ options
478
+ };
479
+ }
480
+ const decodeColons = (path) => path.replace(/%3A/gi, ":");
481
+ const linkedin = {
482
+ platform: "linkedin",
483
+ parse(root) {
484
+ if (root.tag !== "iframe") return null;
485
+ const src = parseUrl(root.attrs.get("src") ?? "");
486
+ if (src?.host !== "www.linkedin.com") return null;
487
+ const [, type, id] = EMBED_PATH$1.exec(src.path) ?? [];
488
+ if (type === void 0 || id === void 0) return null;
489
+ return withSize(post$4(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
490
+ },
491
+ isOwnScript: () => false,
492
+ match(url) {
493
+ if (!HOST$1.test(url.host)) return null;
494
+ const path = decodeColons(url.path);
495
+ const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
496
+ return type === void 0 || id === void 0 ? null : post$4(type, id);
497
+ }
498
+ };
499
+ // src/parser/platforms/pinterest.ts
500
+ const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
501
+ const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
502
+ const PIN_ID = /^\d{1,25}$/;
503
+ const SCRIPT$6 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
504
+ const OPTION_ATTRIBUTES$4 = [
505
+ ["data-pin-width", "width"],
506
+ ["data-pin-lang", "lang"],
507
+ ["data-pin-terse", "terse"]
508
+ ];
509
+ function pin(id) {
510
+ return {
511
+ platform: "pinterest",
512
+ kind: "post",
513
+ url: `https://www.pinterest.com/pin/${id}/`,
514
+ id,
515
+ variant: "sdk"
516
+ };
517
+ }
518
+ function pinOf(url) {
519
+ if (!url || !HOST.test(url.host)) return null;
520
+ const [, id] = PIN_PATH.exec(url.path) ?? [];
521
+ return id === void 0 ? null : pin(id);
522
+ }
523
+ const pinterest = {
524
+ platform: "pinterest",
525
+ parse(root) {
526
+ if (root.tag === "a") {
527
+ if (root.attrs.get("data-pin-do") !== "embedPin") return null;
528
+ if (root.children.some((child) => child.type === "element")) return null;
529
+ const found = pinOf(parseUrl(root.attrs.get("href") ?? ""));
530
+ return found && {
531
+ ...found,
532
+ options: attributeOptions(root, OPTION_ATTRIBUTES$4, coerce)
533
+ };
534
+ }
535
+ if (root.tag !== "iframe") return null;
536
+ const src = parseUrl(root.attrs.get("src") ?? "");
537
+ if (src?.host !== "assets.pinterest.com" || src.path !== "/ext/embed.html") return null;
538
+ const id = src.query.get("id");
539
+ return id !== void 0 && PIN_ID.test(id) ? {
540
+ ...pin(id),
541
+ options: {}
542
+ } : null;
543
+ },
544
+ isOwnScript: (src) => SCRIPT$6.test(src),
545
+ match(url) {
546
+ const found = pinOf(url);
547
+ return found && {
548
+ ...found,
549
+ options: {}
550
+ };
551
+ }
552
+ };
553
+ // src/parser/platforms/reddit.ts
554
+ const HOSTS$5 = /* @__PURE__ */ new Set([
555
+ "reddit.com",
556
+ "www.reddit.com",
557
+ "old.reddit.com",
558
+ "new.reddit.com"
559
+ ]);
560
+ const POST_PATH$2 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
561
+ const SCRIPT$5 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
562
+ const OPTION_ATTRIBUTES$3 = [
563
+ "depth",
564
+ "style",
565
+ "theme",
566
+ "showmedia",
567
+ "showtitle",
568
+ "showedits",
569
+ "created",
570
+ "locale",
571
+ "showusername",
572
+ "snippet"
573
+ ].map((name) => [`data-embed-${name}`, name]);
574
+ function post$3(url) {
575
+ if (!url || !HOSTS$5.has(url.host)) return null;
576
+ const [, sub, postId, slug, commentId] = POST_PATH$2.exec(url.path) ?? [];
577
+ if (sub === void 0 || postId === void 0) return null;
578
+ const base = {
579
+ platform: "reddit",
580
+ kind: "post",
581
+ variant: "iframe"
582
+ };
583
+ const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
584
+ if (commentId === void 0) return {
585
+ ...base,
586
+ url: postUrl,
587
+ id: postId
588
+ };
589
+ if (slug === void 0) return null;
590
+ return {
591
+ ...base,
592
+ url: `${postUrl}comment/${commentId}/`,
593
+ id: commentId
594
+ };
595
+ }
596
+ const reddit = {
597
+ platform: "reddit",
598
+ parse(root) {
599
+ if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
600
+ const found = descendants(root.children).map((element) => element.tag === "a" ? post$3(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
601
+ if (!found) return null;
602
+ const height = pixels(root.attrs.get("data-embed-height"));
603
+ return withSize({
604
+ ...found,
605
+ options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
606
+ }, height === void 0 ? void 0 : { height });
607
+ },
608
+ isOwnScript: (src) => SCRIPT$5.test(src),
609
+ match(url) {
610
+ const found = post$3(url);
611
+ return found && {
612
+ ...found,
613
+ options: {}
614
+ };
615
+ }
616
+ };
617
+ // src/parser/platforms/snapchat.ts
618
+ const HOSTS$4 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
619
+ const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
620
+ const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
621
+ const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
622
+ const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
623
+ const HIGHLIGHT = new RegExp(`^/@${USER}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
624
+ const SCRIPT$4 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
625
+ function content(url) {
626
+ if (!url || !HOSTS$4.has(url.host)) return null;
627
+ const path = url.path.replace(/\/$/, "");
628
+ const base = {
629
+ platform: "snapchat",
630
+ variant: "iframe"
631
+ };
632
+ const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
633
+ if (spotlightId !== void 0) {
634
+ const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
635
+ return {
636
+ ...base,
637
+ kind: "video",
638
+ url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
639
+ id: spotlightId
640
+ };
641
+ }
642
+ const [, user] = PROFILE.exec(path) ?? [];
643
+ if (user !== void 0) return {
644
+ ...base,
645
+ kind: "post",
646
+ url: `https://www.snapchat.com/@${user}`,
647
+ id: user
648
+ };
649
+ const [, lens] = LENS.exec(path) ?? [];
650
+ if (lens !== void 0) return {
651
+ ...base,
652
+ kind: "post",
653
+ url: `https://www.snapchat.com/lens/${lens}`,
654
+ id: lens
655
+ };
656
+ const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
657
+ if (owner !== void 0 && highlight !== void 0) return {
658
+ ...base,
659
+ kind: "post",
660
+ url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
661
+ id: highlight
662
+ };
663
+ return null;
664
+ }
665
+ const snapchat = {
666
+ platform: "snapchat",
667
+ parse(root) {
668
+ if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
669
+ const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
670
+ if (!embedUrl?.path.endsWith("/embed")) return null;
671
+ const found = content({
672
+ ...embedUrl,
673
+ path: embedUrl.path.slice(0, -6)
674
+ });
675
+ if (!found) return null;
676
+ if (!descendants(root.children).filter((el) => el.tag === "a").every((link) => {
677
+ const linked = content(parseUrl(link.attrs.get("href") ?? ""));
678
+ return linked?.kind === found.kind && linked.id === found.id;
679
+ })) return null;
680
+ const title = root.attrs.get("data-snapchat-embed-title");
681
+ const width = pixels(root.attrs.get("data-snapchat-embed-width"));
682
+ const height = pixels(root.attrs.get("data-snapchat-embed-height"));
683
+ return withSize({
684
+ ...found,
685
+ options: title === void 0 ? {} : { title }
686
+ }, width === void 0 || height === void 0 ? void 0 : {
687
+ width,
688
+ height
689
+ });
690
+ },
691
+ isOwnScript: (src) => SCRIPT$4.test(src),
692
+ match(url) {
693
+ const found = content(url);
694
+ return found && {
695
+ ...found,
696
+ options: {}
697
+ };
698
+ }
699
+ };
700
+ // src/parser/platforms/telegram.ts
701
+ const HOSTS$3 = /* @__PURE__ */ new Set([
702
+ "t.me",
703
+ "telegram.me",
704
+ "www.telegram.me"
705
+ ]);
706
+ const CHANNEL = "[A-Za-z][A-Za-z0-9_]{2,31}";
707
+ const POST = new RegExp(`^(${CHANNEL})/(\\d{1,10})$`);
708
+ const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL})/(\\d{1,10})/?$`);
709
+ const SCRIPT$3 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
710
+ const OTHER_WIDGETS = [
711
+ "data-telegram-login",
712
+ "data-telegram-discussion",
713
+ "data-telegram-share-url"
714
+ ];
715
+ const OPTION_ATTRIBUTES$2 = [
716
+ ["data-width", "width"],
717
+ ["data-comment", "comment"],
718
+ ["data-userpic", "userpic"],
719
+ ["data-mode", "mode"],
720
+ ["data-color", "color"],
721
+ ["data-dark", "dark"],
722
+ ["data-dark-color", "darkColor"]
723
+ ];
724
+ function post$2(channel, id, options) {
725
+ return {
726
+ platform: "telegram",
727
+ kind: "post",
728
+ url: `https://t.me/${channel}/${id}`,
729
+ id: `${channel}/${id}`,
730
+ variant: "iframe",
731
+ options
732
+ };
733
+ }
734
+ const telegram = {
735
+ platform: "telegram",
736
+ parse: () => null,
737
+ parseScript(script) {
738
+ if (!SCRIPT$3.test(script.attrs.get("src") ?? "")) return null;
739
+ if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
740
+ const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
741
+ if (channel === void 0 || id === void 0) return null;
742
+ const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
743
+ if (script.attrs.has("data-single")) options.single = true;
744
+ return post$2(channel, id, options);
745
+ },
746
+ isOwnScript: (src) => SCRIPT$3.test(src),
747
+ match(url) {
748
+ if (!HOSTS$3.has(url.host)) return null;
749
+ const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
750
+ if (channel === void 0 || id === void 0) return null;
751
+ const options = {};
752
+ if (url.query.has("single")) options.single = true;
753
+ const comment = url.query.get("comment");
754
+ if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
755
+ return post$2(channel, id, options);
756
+ }
757
+ };
463
758
  // src/parser/platforms/threads.ts
464
759
  const HOSTS$2 = /* @__PURE__ */ new Set([
465
760
  "threads.com",
@@ -701,7 +996,12 @@ const platforms = [
701
996
  options: urlOptions(url, nocookie)
702
997
  };
703
998
  }
704
- }
999
+ },
1000
+ telegram,
1001
+ snapchat,
1002
+ linkedin,
1003
+ reddit,
1004
+ pinterest
705
1005
  ];
706
1006
  // src/parser/match-url.ts
707
1007
  /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
@@ -738,7 +1038,16 @@ function parseEmbed(html) {
738
1038
  else if (root) return null;
739
1039
  else root = node;
740
1040
  }
741
- if (!root) return null;
1041
+ if (!root) {
1042
+ const [script] = scripts;
1043
+ if (fbRoot || scripts.length !== 1 || !script) return null;
1044
+ if (script.children.length !== 0) return null;
1045
+ for (const platform of platforms) {
1046
+ const embed = platform.parseScript?.(script);
1047
+ if (embed) return embed;
1048
+ }
1049
+ return null;
1050
+ }
742
1051
  for (const platform of platforms) {
743
1052
  const embed = platform.parse(root);
744
1053
  if (!embed) continue;
package/dist/parser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as Platform, n as matchUrl, r as ParsedEmbed, t as parseEmbed } from "./index-DCF8EEVz.js";
1
+ import { i as Platform, n as matchUrl, r as ParsedEmbed, t as parseEmbed } from "./index-7CfJ3zQZ.js";
2
2
  export { type ParsedEmbed, type Platform, matchUrl, parseEmbed };
package/dist/parser.js CHANGED
@@ -1 +1 @@
1
- export { n as matchUrl, t as parseEmbed } from "./parser-BrlUKvvo.js";
1
+ export { n as matchUrl, t as parseEmbed } from "./parser-HhmrfoYj.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "social-embeds",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "license": "MIT",
6
6
  "author": "Atanas Mitrev",
@@ -40,17 +40,17 @@
40
40
  "@testing-library/react": "16.3.3",
41
41
  "@types/react": "19.3.0",
42
42
  "@types/react-dom": "19.3.0",
43
- "eslint": "10.14.0",
43
+ "eslint": "10.15.0",
44
44
  "eslint-plugin-react-hooks": "7.1.1",
45
45
  "happy-dom": "21.0.4",
46
- "prettier": "3.9.10",
46
+ "prettier": "3.10.1",
47
47
  "publint": "0.3.25",
48
48
  "react": "19.3.1",
49
49
  "react-dom": "19.3.1",
50
50
  "tsdown": "0.23.7",
51
51
  "typescript": "6.0.3",
52
- "typescript-eslint": "8.72.1",
53
- "vite": "8.3.7",
52
+ "typescript-eslint": "8.72.2",
53
+ "vite": "8.3.8",
54
54
  "vitest": "5.1.0"
55
55
  },
56
56
  "scripts": {