social-embeds 0.9.2 → 0.9.3

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.
Files changed (90) hide show
  1. package/README.md +1 -1
  2. package/dist/components/apple-embed.js +4 -4
  3. package/dist/components/bluesky-embed.js +2 -2
  4. package/dist/components/dailymotion-embed.js +2 -2
  5. package/dist/components/facebook-embed.js +2 -2
  6. package/dist/components/flickr-embed.js +2 -2
  7. package/dist/components/giphy-embed.js +2 -2
  8. package/dist/components/imgur-embed.js +2 -2
  9. package/dist/components/instagram-embed.js +2 -2
  10. package/dist/components/kick-embed.js +2 -2
  11. package/dist/components/linkedin-embed.js +2 -2
  12. package/dist/components/pinterest-embed.js +2 -2
  13. package/dist/components/reddit-embed.js +2 -2
  14. package/dist/components/rumble-embed.js +2 -2
  15. package/dist/components/snapchat-embed.js +2 -2
  16. package/dist/components/soundcloud-embed.js +2 -2
  17. package/dist/components/spotify-embed.js +2 -2
  18. package/dist/components/strava-embed.js +2 -2
  19. package/dist/components/streamable-embed.js +2 -2
  20. package/dist/components/telegram-embed.js +2 -2
  21. package/dist/components/tenor-embed.js +2 -2
  22. package/dist/components/threads-embed.js +2 -2
  23. package/dist/components/tiktok-embed.js +2 -2
  24. package/dist/components/truthsocial-embed.js +2 -2
  25. package/dist/components/tumblr-embed.js +2 -2
  26. package/dist/components/twitch-embed.js +2 -2
  27. package/dist/components/vimeo-embed.js +2 -2
  28. package/dist/components/x-embed.js +2 -2
  29. package/dist/components/youtube-embed.js +2 -2
  30. package/dist/element.js +1 -1
  31. package/dist/parser/matchers/applemusic.js +33 -0
  32. package/dist/parser/matchers/applepodcasts.js +32 -0
  33. package/dist/parser/matchers/bluesky.js +41 -0
  34. package/dist/parser/matchers/dailymotion.js +47 -0
  35. package/dist/parser/matchers/facebook.js +118 -0
  36. package/dist/parser/matchers/flickr.js +100 -0
  37. package/dist/parser/matchers/giphy.js +38 -0
  38. package/dist/parser/matchers/imgur.js +76 -0
  39. package/dist/parser/matchers/instagram.js +43 -0
  40. package/dist/parser/matchers/kick.js +48 -0
  41. package/dist/parser/matchers/linkedin.js +31 -0
  42. package/dist/parser/matchers/pinterest.js +32 -0
  43. package/dist/parser/matchers/reddit.js +43 -0
  44. package/dist/parser/matchers/rumble.js +32 -0
  45. package/dist/parser/matchers/snapchat.js +60 -0
  46. package/dist/parser/matchers/soundcloud.js +87 -0
  47. package/dist/parser/matchers/spotify.js +39 -0
  48. package/dist/parser/matchers/strava.js +31 -0
  49. package/dist/parser/matchers/streamable.js +59 -0
  50. package/dist/parser/matchers/telegram.js +34 -0
  51. package/dist/parser/matchers/tenor.js +34 -0
  52. package/dist/parser/matchers/threads.js +36 -0
  53. package/dist/parser/matchers/tiktok.js +25 -0
  54. package/dist/parser/matchers/truthsocial.js +34 -0
  55. package/dist/parser/matchers/tumblr.js +51 -0
  56. package/dist/parser/matchers/twitch.js +90 -0
  57. package/dist/parser/matchers/vimeo.js +71 -0
  58. package/dist/parser/matchers/x.js +50 -0
  59. package/dist/parser/matchers/youtube.js +123 -0
  60. package/dist/parser/platform.d.ts +10 -4
  61. package/dist/parser/platforms/applemusic.js +4 -30
  62. package/dist/parser/platforms/applepodcasts.js +4 -29
  63. package/dist/parser/platforms/bluesky.js +4 -38
  64. package/dist/parser/platforms/dailymotion.js +4 -44
  65. package/dist/parser/platforms/facebook.js +5 -115
  66. package/dist/parser/platforms/flickr.js +5 -98
  67. package/dist/parser/platforms/giphy.js +4 -35
  68. package/dist/parser/platforms/imgur.js +4 -73
  69. package/dist/parser/platforms/instagram.js +4 -40
  70. package/dist/parser/platforms/kick.js +4 -45
  71. package/dist/parser/platforms/linkedin.js +4 -28
  72. package/dist/parser/platforms/pinterest.js +4 -29
  73. package/dist/parser/platforms/reddit.js +3 -40
  74. package/dist/parser/platforms/rumble.js +3 -29
  75. package/dist/parser/platforms/snapchat.js +3 -57
  76. package/dist/parser/platforms/soundcloud.js +4 -84
  77. package/dist/parser/platforms/spotify.js +4 -36
  78. package/dist/parser/platforms/strava.js +3 -28
  79. package/dist/parser/platforms/streamable.js +3 -56
  80. package/dist/parser/platforms/telegram.js +3 -31
  81. package/dist/parser/platforms/tenor.js +5 -32
  82. package/dist/parser/platforms/threads.js +4 -33
  83. package/dist/parser/platforms/tiktok.js +4 -22
  84. package/dist/parser/platforms/truthsocial.js +3 -31
  85. package/dist/parser/platforms/tumblr.js +3 -48
  86. package/dist/parser/platforms/twitch.js +4 -87
  87. package/dist/parser/platforms/vimeo.js +4 -68
  88. package/dist/parser/platforms/x.js +6 -46
  89. package/dist/parser/platforms/youtube.js +5 -120
  90. package/package.json +1 -1
@@ -1,46 +1,9 @@
1
1
  import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
- import { coerce, parseUrl } from "../url.js";
3
- import { vimeoFrame } from "../frames.js";
2
+ import { parseUrl } from "../url.js";
3
+ import { HOSTS, fromPage, fromPlayer, vimeoMatcher } from "../matchers/vimeo.js";
4
4
  // src/parser/platforms/vimeo.ts
5
- const HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
6
- const VIDEO = "(\\d{1,12})";
7
- const HASH = "([0-9a-f]{6,20})";
8
- const PAGE_PATHS = [
9
- new RegExp(`^/${VIDEO}(?:/${HASH})?/?$`),
10
- new RegExp(`^/channels/[A-Za-z0-9_-]{1,64}/${VIDEO}/?$`),
11
- new RegExp(`^/groups/[A-Za-z0-9_-]{1,64}/videos/${VIDEO}/?$`),
12
- new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
13
- ];
14
- const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
15
5
  const WRAPPER = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
16
6
  const SCRIPT = /^(?:https?:)?\/\/player\.vimeo\.com\/api\/player\.js$/;
17
- const DROPPED = /* @__PURE__ */ new Set([
18
- "h",
19
- "app_id",
20
- "player_id"
21
- ]);
22
- const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
23
- function video(id, hash) {
24
- return {
25
- platform: "vimeo",
26
- kind: "video",
27
- url: `https://vimeo.com/${id}${hash ? `/${hash}` : ""}`,
28
- id,
29
- variant: "iframe"
30
- };
31
- }
32
- function start(url) {
33
- const [, time] = START.exec(url.fragment ?? "") ?? [];
34
- return time ? { t: time } : {};
35
- }
36
- function fromPage(url) {
37
- if (!url || !HOSTS.has(url.host)) return null;
38
- for (const path of PAGE_PATHS) {
39
- const [, id, hash] = path.exec(url.path) ?? [];
40
- if (id !== void 0) return video(id, hash);
41
- }
42
- return null;
43
- }
44
7
  function isLink(node, test) {
45
8
  if (node?.type !== "element" || node.tag !== "a" || node.attrs.size !== 1) return false;
46
9
  const href = parseUrl(node.attrs.get("href") ?? "");
@@ -55,25 +18,8 @@ function isCredit(element, embed) {
55
18
  const [title, from, author, on, home, stop, ...rest] = element.children;
56
19
  return rest.length === 0 && isLink(title, (url) => fromPage(url)?.id === embed.id) && isText(from, "from") && isLink(author, () => true) && isText(on, "on") && isLink(home, (url) => url.path === "" || url.path === "/") && isText(stop, ".");
57
20
  }
58
- function fromPlayer(url) {
59
- if (url?.host !== "player.vimeo.com") return null;
60
- const [, id] = PLAYER_PATH.exec(url.path) ?? [];
61
- if (id === void 0) return null;
62
- const hash = url.query.get("h");
63
- if (hash !== void 0 && !new RegExp(`^${HASH}$`).test(hash)) return null;
64
- const options = Object.fromEntries([...url.query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
65
- return {
66
- ...video(id, hash),
67
- options: {
68
- ...options,
69
- ...start(url)
70
- }
71
- };
72
- }
73
21
  const vimeo = {
74
- platform: "vimeo",
75
- name: "Vimeo",
76
- shapes: ["video iframe"],
22
+ ...vimeoMatcher,
77
23
  parse(root) {
78
24
  const wrapped = unwrapRatio(root, WRAPPER);
79
25
  const iframe = wrapped?.iframe ?? root;
@@ -82,16 +28,6 @@ const vimeo = {
82
28
  return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
83
29
  },
84
30
  isOwnScript: (src) => SCRIPT.test(src),
85
- isOwnExtra: isCredit,
86
- match(url) {
87
- const player = fromPlayer(url);
88
- if (player) return player;
89
- const page = fromPage(url);
90
- return page && {
91
- ...page,
92
- options: start(url)
93
- };
94
- },
95
- ownsFrame: vimeoFrame
31
+ isOwnExtra: isCredit
96
32
  };
97
33
  export { vimeo };
@@ -1,17 +1,8 @@
1
- import { descendants, hasClass, parseHtml, rebuild, rebuildsAs } from "../html.js";
1
+ import { hasClass, rebuild } from "../html.js";
2
2
  import { attributeOptions } from "../platform.js";
3
- import { coerce, parseUrl } from "../url.js";
3
+ import { coerce } from "../url.js";
4
+ import { FALLBACK, lastStatus, xMatcher } from "../matchers/x.js";
4
5
  // src/parser/platforms/x.ts
5
- const HOSTS = /* @__PURE__ */ new Set([
6
- "x.com",
7
- "www.x.com",
8
- "mobile.x.com",
9
- "twitter.com",
10
- "www.twitter.com",
11
- "mobile.twitter.com"
12
- ]);
13
- const STATUS_PATH = /^\/([A-Za-z0-9_]{1,15})\/status\/(\d{1,20})\/?$/;
14
- const LINK_PATH = /^\/(?:([A-Za-z0-9_]{1,15})|i\/web)\/status\/(\d{1,20})(?:\/(?:photo|video)\/[1-4])?\/?$/;
15
6
  const SCRIPT = /^(?:https?:)?\/\/platform\.(?:x|twitter)\.com\/widgets\.js$/;
16
7
  const OPTION_ATTRIBUTES = [
17
8
  ["data-theme", "theme"],
@@ -23,35 +14,11 @@ const OPTION_ATTRIBUTES = [
23
14
  ["data-dnt", "dnt"],
24
15
  ["data-width", "width"]
25
16
  ];
26
- const FALLBACK = /* @__PURE__ */ new Map([
27
- ["p", ["lang", "dir"]],
28
- ["a", ["href"]],
29
- ["br", []]
30
- ]);
31
- function post(url, path = STATUS_PATH) {
32
- if (!url || !HOSTS.has(url.host)) return null;
33
- const [, user = "i", id] = path.exec(url.path) ?? [];
34
- if (id === void 0) return null;
35
- return {
36
- platform: "x",
37
- kind: "post",
38
- url: `https://x.com/${user}/status/${id}`,
39
- id,
40
- variant: "sdk"
41
- };
42
- }
43
- function fallbackNamesPost(html, id) {
44
- const [root] = parseHtml(`<blockquote class="twitter-tweet">${html}</blockquote>`) ?? [];
45
- return root?.type === "element" && x.parse(root)?.id === id;
46
- }
47
17
  const x = {
48
- platform: "x",
49
- name: "X",
50
- shapes: ["post sdk"],
51
- trustsFallback: (html, embed) => rebuildsAs(html, FALLBACK) && fallbackNamesPost(html, embed.id),
18
+ ...xMatcher,
52
19
  parse(root) {
53
20
  if (root.tag !== "blockquote" || !(hasClass(root, "twitter-tweet") || hasClass(root, "twitter-video"))) return null;
54
- const status = descendants(root.children).reverse().map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((found) => found !== null);
21
+ const status = lastStatus(root.children);
55
22
  if (!status) return null;
56
23
  return {
57
24
  ...status,
@@ -59,13 +26,6 @@ const x = {
59
26
  fallbackHtml: rebuild(root.children, FALLBACK)
60
27
  };
61
28
  },
62
- isOwnScript: (src) => SCRIPT.test(src),
63
- match(url) {
64
- const status = post(url, LINK_PATH);
65
- return status && {
66
- ...status,
67
- options: {}
68
- };
69
- }
29
+ isOwnScript: (src) => SCRIPT.test(src)
70
30
  };
71
31
  export { x };
@@ -1,78 +1,10 @@
1
- import { sizeOf, underPath, withSize } from "../platform.js";
1
+ import { sizeOf, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
- import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS, youtubeFrame } from "../frames.js";
3
+ import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS } from "../frames.js";
4
+ import { fromEmbed, startOf, youtubeMatcher } from "../matchers/youtube.js";
4
5
  // src/parser/platforms/youtube.ts
5
- const BASE = "https://www.youtube.com";
6
- const VIDEO_ID = /^(?!videoseries|live_stream)[A-Za-z0-9_-]{11}$/;
7
- const EMBED_PATH = /^\/embed\/(?:(videoseries|live_stream)|([A-Za-z0-9_-]{11}))\/?$/;
8
- const URL_PATHS = /^\/(shorts|live)\/((?!videoseries|live_stream)[A-Za-z0-9_-]{11})\/?$/;
9
- const SHORT_LINK_PATH = /^\/([A-Za-z0-9_-]{11})\/?$/;
10
- const PLAYLIST_ID = /^[A-Za-z0-9_-]{10,64}$/;
11
- const CHANNEL_ID = /^UC[A-Za-z0-9_-]{22}$/;
12
- const CHANNEL_LIVE_PATH = /^\/channel\/(UC[A-Za-z0-9_-]{22})\/live\/?$/;
13
- const DURATION = /^(?:(\d{1,5})h)?(?:(\d{1,6})m)?(?:(\d{1,7})s?)?$/;
14
- const FRAGMENT_START = /^t=(.+)$/;
15
- /** `90`, `90s`, `1m30s`, `1h2m3s` → seconds. */
16
- function seconds(value) {
17
- if (value === void 0 || value === "") return void 0;
18
- const match = DURATION.exec(value);
19
- if (!match) return void 0;
20
- const [, hours = "0", minutes = "0", secs = "0"] = match;
21
- return Number(hours) * 3600 + Number(minutes) * 60 + Number(secs);
22
- }
23
- /** `start` wins over `t`; `t` is converted, because the embed player only reads `start`. */
24
- function startOf(query) {
25
- return seconds(query.get("start")) ?? seconds(query.get("t"));
26
- }
27
- function found(id, url) {
28
- return {
29
- platform: "youtube",
30
- kind: "video",
31
- url,
32
- id,
33
- variant: "iframe"
34
- };
35
- }
36
- function video(id, shorts = false) {
37
- return found(id, shorts ? `${BASE}/shorts/${id}` : `${BASE}/watch?v=${id}`);
38
- }
39
- function playlist(id) {
40
- return id !== void 0 && PLAYLIST_ID.test(id) ? found(id, `${BASE}/playlist?list=${id}`) : null;
41
- }
42
- function live(id) {
43
- return id !== void 0 && CHANNEL_ID.test(id) ? found(id, `${BASE}/channel/${id}/live`) : null;
44
- }
45
- /** `key` is the query parameter that names the content, for a playlist or a channel's stream. */
46
- function fromEmbed(url) {
47
- const [, series, id] = EMBED_PATH.exec(url.path) ?? [];
48
- if (id !== void 0) return { found: video(id) };
49
- if (series === "videoseries") {
50
- const list = playlist(url.query.get("list"));
51
- return list && {
52
- found: list,
53
- key: "list"
54
- };
55
- }
56
- if (series === "live_stream") {
57
- const stream = live(url.query.get("channel"));
58
- return stream && {
59
- found: stream,
60
- key: "channel"
61
- };
62
- }
63
- return null;
64
- }
65
- function urlOptions(url, nocookie) {
66
- const start = startOf(url.query) ?? seconds(FRAGMENT_START.exec(url.fragment ?? "")?.[1]);
67
- return {
68
- ...start === void 0 ? {} : { start },
69
- ...nocookie ? { nocookie: true } : {}
70
- };
71
- }
72
6
  const youtube = {
73
- platform: "youtube",
74
- name: "YouTube",
75
- shapes: ["video iframe"],
7
+ ...youtubeMatcher,
76
8
  parse(root) {
77
9
  if (root.tag !== "iframe") return null;
78
10
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -90,53 +22,6 @@ const youtube = {
90
22
  options
91
23
  }, sizeOf(root));
92
24
  },
93
- isOwnScript: () => false,
94
- match(url) {
95
- if (url.host === "youtu.be") {
96
- const [, id] = SHORT_LINK_PATH.exec(url.path) ?? [];
97
- return id === void 0 ? null : {
98
- ...video(id),
99
- options: urlOptions(url, false)
100
- };
101
- }
102
- const nocookie = YOUTUBE_NOCOOKIE_HOSTS.has(url.host);
103
- if (!nocookie && !YOUTUBE_HOSTS.has(url.host)) return null;
104
- const options = urlOptions(url, nocookie);
105
- if (underPath(url.path, "/embed")) {
106
- const player = fromEmbed(url);
107
- return player && {
108
- ...player.found,
109
- options
110
- };
111
- }
112
- if (nocookie) return null;
113
- if (/^\/watch\/?$/.test(url.path)) {
114
- const id = url.query.get("v");
115
- return id !== void 0 && VIDEO_ID.test(id) ? {
116
- ...video(id),
117
- options
118
- } : null;
119
- }
120
- if (/^\/playlist\/?$/.test(url.path)) {
121
- const list = playlist(url.query.get("list"));
122
- return list && {
123
- ...list,
124
- options
125
- };
126
- }
127
- const [, channel] = CHANNEL_LIVE_PATH.exec(url.path) ?? [];
128
- const stream = live(channel);
129
- if (stream) return {
130
- ...stream,
131
- options
132
- };
133
- const [, kind, id] = URL_PATHS.exec(url.path) ?? [];
134
- if (kind === void 0 || id === void 0) return null;
135
- return {
136
- ...video(id, kind === "shorts"),
137
- options
138
- };
139
- },
140
- ownsFrame: youtubeFrame
25
+ isOwnScript: () => false
141
26
  };
142
27
  export { youtube };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "social-embeds",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "keywords": [
6
6
  "react",