social-embeds 0.5.0 → 0.5.2

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,6 +4,8 @@ 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
+ **[Live demo](https://amitrev.github.io/social-embeds/)**: every platform from embed code and post URLs, and a box for your own, running the released version.
8
+
7
9
  - X, Instagram, Threads, Facebook, TikTok, YouTube, Telegram, Snapchat, LinkedIn, Reddit, Pinterest, Spotify, Vimeo, Twitch, Dailymotion, Bluesky, SoundCloud, Apple Music, Apple Podcasts, Tumblr, Kick and Giphy
8
10
  - React 19, Next.js App Router (Server Components, client navigation), or plain React
9
11
  - Zero runtime dependencies, ESM only, typed
@@ -109,47 +111,47 @@ import {
109
111
 
110
112
  <XEmbed url="https://x.com/jack/status/20" theme="dark" cards="hidden" />
111
113
 
112
- <InstagramEmbed url="https://www.instagram.com/p/DfPQchkG1tg/" captioned />
114
+ <InstagramEmbed url="https://www.instagram.com/p/Df75lxnmIrF/" captioned />
113
115
 
114
- <ThreadsEmbed url="https://www.threads.com/@instagram/post/DfQSavwEs5C" theme="auto" />
116
+ <ThreadsEmbed url="https://www.threads.com/@instagram/post/Df5MmLBm0O7" theme="auto" />
115
117
 
116
118
  <FacebookEmbed
117
119
  url="https://www.facebook.com/facebook/videos/10153231379946729/"
118
- locale="bg_BG"
120
+ locale="en_GB"
119
121
  showCaptions
120
122
  />
121
123
 
122
124
  <TikTokEmbed
123
- url="https://www.tiktok.com/@scout2015/video/6718335390845095173"
125
+ url="https://www.tiktok.com/@tiktok/video/7704834703446117662"
124
126
  musicInfo={false}
125
127
  description={false}
126
128
  />
127
129
 
128
- <YouTubeEmbed url="https://youtu.be/jNQXAC9IVRw?t=90" nocookie controls={false} />
130
+ <YouTubeEmbed url="https://youtu.be/jNQXAC9IVRw?t=11" nocookie controls={false} />
129
131
 
130
132
  <TelegramEmbed url="https://t.me/telegram/83" dark userpic={false} />
131
133
 
132
134
  <SnapchatEmbed url="https://www.snapchat.com/@teamsnapchat" />
133
135
 
134
136
  <LinkedInEmbed
135
- url="https://www.linkedin.com/feed/update/urn:li:activity:7527261038006697984/"
137
+ url="https://www.linkedin.com/feed/update/urn:li:ugcPost:7528828146767409153/"
136
138
  collapsed
137
139
  height={560}
138
140
  />
139
141
 
140
142
  <RedditEmbed
141
- url="https://www.reddit.com/r/bulgaria/comments/1xz8iq4/"
143
+ url="https://www.reddit.com/r/reddit/comments/11zso11/"
142
144
  theme="dark"
143
- locale="bg-BG"
145
+ locale="en-GB"
144
146
  />
145
147
 
146
- <PinterestEmbed url="https://www.pinterest.com/pin/99360735500167749/" pinWidth="large" />
148
+ <PinterestEmbed url="https://www.pinterest.com/pin/424605071145752542/" pinWidth="large" />
147
149
 
148
- <SpotifyEmbed url="https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC" theme={0} />
150
+ <SpotifyEmbed url="https://open.spotify.com/track/0LrHzQHk5gYGbMsoVbKDuS" theme={0} />
149
151
 
150
152
  <VimeoEmbed url="https://vimeo.com/76979871" muted title={false} t="1m2s" />
151
153
 
152
- <TwitchEmbed url="https://www.twitch.tv/videos/40464143" autoplay={false} time="1h2m3s" />
154
+ <TwitchEmbed url="https://www.twitch.tv/videos/1816688726" autoplay={false} time="30s" />
153
155
 
154
156
  <DailymotionEmbed
155
157
  url="https://www.dailymotion.com/video/x84sh87"
@@ -158,21 +160,21 @@ import {
158
160
  />
159
161
 
160
162
  <BlueskyEmbed
161
- url="https://bsky.app/profile/did:plc:z72i7hdynmk6r22z27h6tvur/post/3n2mkgfb4tk2d"
163
+ url="https://bsky.app/profile/did:plc:z72i7hdynmk6r22z27h6tvur/post/3mxu3hsnebc2v"
162
164
  colorMode="dark"
163
165
  />
164
166
 
165
167
  <SoundCloudEmbed url="https://soundcloud.com/forss/flickermood" visual={false} height={166} />
166
168
 
167
- <AppleMusicEmbed url="https://music.apple.com/us/album/better-together/1440857781?i=1440857786" />
169
+ <AppleMusicEmbed url="https://music.apple.com/us/album/birds-of-oaks-bottom-piano-solos/1357820591?i=1357820597" />
168
170
 
169
- <ApplePodcastsEmbed url="https://podcasts.apple.com/us/podcast/the-daily/id1200361736" />
171
+ <ApplePodcastsEmbed url="https://podcasts.apple.com/us/podcast/monument-valley-meet-the-developer/id947965068" />
170
172
 
171
- <TumblrEmbed url="https://staff.tumblr.com/post/832577330595643392" />
173
+ <TumblrEmbed url="https://staff.tumblr.com/post/828009069026721792" />
172
174
 
173
- <KickEmbed url="https://kick.com/xqc" muted />
175
+ <KickEmbed url="https://kick.com/kick" muted />
174
176
 
175
- <GiphyEmbed url="https://giphy.com/gifs/cat-funny-JIX9t2j0ZTN9S" maxWidth={480} />
177
+ <GiphyEmbed url="https://giphy.com/gifs/originals-animation-kitten-logo-l41YlHs99JsSptZf2" maxWidth={480} />
176
178
  ```
177
179
 
178
180
  | Component | Option props |
@@ -416,6 +418,7 @@ URL shapes, each tested against Facebook's plugins on `www.facebook.com`, `faceb
416
418
  - Embed code from Dailymotion Studio carries the Player ID (`geo.dailymotion.com/player/{playerId}.html?video={id}`) and renders as given, also inside Dailymotion's responsive wrapper `div`.
417
419
  - URLs, and code without a Player ID, render only through `DailymotionEmbed` with your `playerId`. A `playerId` prop also replaces the one in the embed code. `<SocialEmbed>` takes none: for that input it renders nothing and calls `onError`.
418
420
  - The package never uses a Player ID you did not give it.
421
+ - Playback with a publisher's own Player ID is not yet tested. The sample Player ID from Dailymotion's docs loads the player and plays, but its stream is refused after a few plays (`docs/decisions.md` D69), so the demo's Dailymotion page may show "Playback error".
419
422
  - Playlists are not supported.
420
423
 
421
424
  ### Bluesky
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use client";
2
- import { a as DID, c as rebuild, i as x$1, l as parseUrl, n as matchUrl, o as escapeAttribute, r as platforms, s as parseHtml, t as parseEmbed } from "./parser-CJccut4h.js";
2
+ import { a as escapeAttribute, c as parseUrl, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-BSz1rCrV.js";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/parser/lookup.ts
6
6
  const BLUESKY_HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
7
7
  const HANDLE_POST = /^\/profile\/([^/]{1,253})\/post\/[A-Za-z0-9._~:-]{1,512}\/?$/;
8
- const IS_DID = new RegExp(`^${DID}$`);
8
+ const HANDLE = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
9
9
  /**
10
10
  * The platform of a post URL that only a network lookup could turn into an embed: a Bluesky
11
11
  * URL with a handle instead of a DID. Internal; the parser entry does not export it.
@@ -14,7 +14,7 @@ function needsLookup(url) {
14
14
  const parsed = typeof url === "string" ? parseUrl(url) : null;
15
15
  if (!parsed || !BLUESKY_HOSTS.has(parsed.host)) return null;
16
16
  const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
17
- return profile !== void 0 && !IS_DID.test(profile) ? "bluesky" : null;
17
+ return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
18
18
  }
19
19
  // src/components/hooks.ts
20
20
  const ROOT_MARGIN = "200px 0px";
@@ -249,9 +249,13 @@ const NAMES = {
249
249
  kick: "Kick",
250
250
  giphy: "Giphy"
251
251
  };
252
+ /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
253
+ function lookupMessage(platform) {
254
+ return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
255
+ }
252
256
  function resolveEmbed(url, given, platform) {
253
257
  const embed = given ?? (url === void 0 ? null : matchUrl(url));
254
- if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code` };
258
+ if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
255
259
  if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
256
260
  if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
257
261
  const verified = verifyEmbed(embed);
@@ -263,7 +267,7 @@ function resolveEmbed(url, given, platform) {
263
267
  * come only from the verified url and id.
264
268
  */
265
269
  function optionsWithout(options, reserved) {
266
- return Object.entries(options).filter(([key]) => !reserved.includes(key));
270
+ return Object.entries(options).filter(([key]) => !reserved.includes(key.toLowerCase()));
267
271
  }
268
272
  /** Later entries replace earlier ones with the same name. */
269
273
  function query(...sources) {
@@ -1598,7 +1602,9 @@ function SocialEmbed(props) {
1598
1602
  maxHeight
1599
1603
  };
1600
1604
  const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
1601
- useReportError(embed === null && !(html !== void 0 && fallback) ? html !== void 0 ? "social-embeds: unrecognised embed code" : needsLookup(url) === "bluesky" ? "social-embeds: a Bluesky URL needs a lookup: use the embed code" : `social-embeds: not a supported post URL: ${url}` : void 0, onError);
1605
+ const unrecognised = embed === null && !(html !== void 0 && fallback);
1606
+ const lookup = html === void 0 ? needsLookup(url) : null;
1607
+ useReportError(unrecognised ? html !== void 0 ? "social-embeds: unrecognised embed code" : lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${url}` : void 0, onError);
1602
1608
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
1603
1609
  switch (embed.platform) {
1604
1610
  case "x": return /* @__PURE__ */ jsx(XEmbed, {
@@ -747,6 +747,9 @@ const NOT_CHANNELS = /* @__PURE__ */ new Set([
747
747
  "browse",
748
748
  "categories",
749
749
  "category",
750
+ "clips",
751
+ "video",
752
+ "videos",
750
753
  "following",
751
754
  "search",
752
755
  "settings",
@@ -1127,8 +1130,16 @@ const soundcloud = {
1127
1130
  if (root.tag !== "iframe") return null;
1128
1131
  const src = parseUrl(root.attrs.get("src") ?? "");
1129
1132
  if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
1130
- const found = fromApi(parseUrl(src.query.get("url") ?? ""));
1133
+ let found = fromApi(parseUrl(src.query.get("url") ?? ""));
1131
1134
  if (!found) return null;
1135
+ const outer = src.query.get("secret_token");
1136
+ if (outer !== void 0) {
1137
+ if (!SECRET_TOKEN.test(outer)) return null;
1138
+ if (!found.url.includes("?")) found = {
1139
+ ...found,
1140
+ url: `${found.url}?secret_token=${outer}`
1141
+ };
1142
+ }
1132
1143
  const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
1133
1144
  const { height } = sizeOf(root) ?? {};
1134
1145
  return withSize({
@@ -1385,12 +1396,13 @@ const tumblr = {
1385
1396
  if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
1386
1397
  const frame = parseUrl(root.attrs.get("data-href") ?? "");
1387
1398
  if (frame?.host !== "embed.tumblr.com") return null;
1388
- const [, , framePost] = FRAME_PATH.exec(frame.path) ?? [];
1399
+ const [, frameBlog, framePost] = FRAME_PATH.exec(frame.path) ?? [];
1389
1400
  if (framePost === void 0) return null;
1390
1401
  const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
1391
1402
  if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
1392
1403
  const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
1393
1404
  if (found?.id !== framePost) return null;
1405
+ if (frameBlog !== void 0 && found.url !== `https://www.tumblr.com/${frameBlog}/${framePost}`) return null;
1394
1406
  return {
1395
1407
  ...found,
1396
1408
  options: {}
@@ -1810,7 +1822,7 @@ function parseEmbed(html) {
1810
1822
  }
1811
1823
  if (!root) {
1812
1824
  const [script] = scripts;
1813
- if (fbRoot || extra || scripts.length !== 1 || !script) return null;
1825
+ if (fbRoot || scripts.length !== 1 || !script) return null;
1814
1826
  if (script.children.length !== 0) return null;
1815
1827
  for (const platform of platforms) {
1816
1828
  const embed = platform.parseScript?.(script);
@@ -1836,4 +1848,4 @@ function parseEmbed(html) {
1836
1848
  function isFbRoot(element) {
1837
1849
  return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
1838
1850
  }
1839
- export { DID as a, rebuild as c, x as i, parseUrl as l, matchUrl as n, escapeAttribute as o, platforms as r, parseHtml as s, parseEmbed as t };
1851
+ export { escapeAttribute as a, parseUrl as c, x as i, matchUrl as n, parseHtml as o, platforms as r, rebuild as s, parseEmbed as t };
package/dist/parser.js CHANGED
@@ -1 +1 @@
1
- export { n as matchUrl, t as parseEmbed } from "./parser-CJccut4h.js";
1
+ export { n as matchUrl, t as parseEmbed } from "./parser-BSz1rCrV.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "social-embeds",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "keywords": [
6
6
  "react",