social-embeds 0.8.0 → 0.9.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.
Files changed (44) hide show
  1. package/README.md +91 -48
  2. package/dist/components/hooks.js +3 -1
  3. package/dist/components/platforms.d.ts +32 -0
  4. package/dist/components/platforms.js +384 -0
  5. package/dist/components/script-embed.js +8 -7
  6. package/dist/components/social-embed.d.ts +31 -4
  7. package/dist/components/social-embed.js +48 -211
  8. package/dist/core/drivers.js +8 -1
  9. package/dist/core/plans/youtube.js +15 -3
  10. package/dist/element.d.ts +1 -1
  11. package/dist/element.js +1 -1
  12. package/dist/index.d.ts +21 -20
  13. package/dist/index.js +3 -2
  14. package/dist/loader/load-script.js +2 -0
  15. package/dist/parser/frames.js +70 -0
  16. package/dist/parser/html.d.ts +19 -0
  17. package/dist/parser/iframe.js +2 -2
  18. package/dist/parser/match-url.js +6 -2
  19. package/dist/parser/parse-embed.js +14 -10
  20. package/dist/parser/platform.d.ts +26 -0
  21. package/dist/parser/platforms/applemusic.js +3 -3
  22. package/dist/parser/platforms/applepodcasts.js +3 -3
  23. package/dist/parser/platforms/dailymotion.js +6 -8
  24. package/dist/parser/platforms/facebook.js +5 -9
  25. package/dist/parser/platforms/giphy.js +6 -6
  26. package/dist/parser/platforms/kick.js +4 -4
  27. package/dist/parser/platforms/linkedin.js +4 -4
  28. package/dist/parser/platforms/pinterest.js +3 -3
  29. package/dist/parser/platforms/reddit.js +3 -2
  30. package/dist/parser/platforms/rumble.js +3 -2
  31. package/dist/parser/platforms/soundcloud.js +3 -3
  32. package/dist/parser/platforms/spotify.js +4 -4
  33. package/dist/parser/platforms/streamable.js +3 -2
  34. package/dist/parser/platforms/tenor.js +3 -2
  35. package/dist/parser/platforms/tiktok.js +6 -6
  36. package/dist/parser/platforms/truthsocial.js +2 -1
  37. package/dist/parser/platforms/tumblr.js +4 -2
  38. package/dist/parser/platforms/twitch.js +6 -7
  39. package/dist/parser/platforms/vimeo.js +31 -12
  40. package/dist/parser/platforms/x.js +1 -1
  41. package/dist/parser/platforms/youtube.js +73 -23
  42. package/dist/parser/url.d.ts +6 -0
  43. package/dist/parser/url.js +1 -1
  44. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ import { underPath } from "./platform.js";
2
+ // src/parser/frames.ts
3
+ const YOUTUBE_HOSTS = /* @__PURE__ */ new Set([
4
+ "youtube.com",
5
+ "www.youtube.com",
6
+ "m.youtube.com"
7
+ ]);
8
+ const YOUTUBE_NOCOOKIE_HOSTS = /* @__PURE__ */ new Set(["youtube-nocookie.com", "www.youtube-nocookie.com"]);
9
+ const DAILYMOTION_HOSTS = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
10
+ const DAILYMOTION_PLAYER_HOST = "geo.dailymotion.com";
11
+ const DAILYMOTION_SHORT_HOST = "dai.ly";
12
+ const TIKTOK_HOSTS = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
13
+ const TWITCH_PLAYER_HOST = "player.twitch.tv";
14
+ const TWITCH_CLIPS_HOST = "clips.twitch.tv";
15
+ const VIMEO_PLAYER_HOST = "player.vimeo.com";
16
+ const FACEBOOK_PLUGIN_HOSTS = /* @__PURE__ */ new Set([
17
+ "facebook.com",
18
+ "www.facebook.com",
19
+ "web.facebook.com"
20
+ ]);
21
+ const GIPHY_PAGE_HOSTS = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
22
+ const KICK_PLAYER_HOSTS = /* @__PURE__ */ new Set(["player.kick.com"]);
23
+ const LINKEDIN_FRAME_HOST = "www.linkedin.com";
24
+ const PINTEREST_FRAME_HOST = "assets.pinterest.com";
25
+ const APPLE_MUSIC_FRAME_HOST = "embed.music.apple.com";
26
+ const APPLE_PODCASTS_FRAME_HOST = "embed.podcasts.apple.com";
27
+ const SOUNDCLOUD_WIDGET_HOST = "w.soundcloud.com";
28
+ const SPOTIFY_HOST = "open.spotify.com";
29
+ const youtubeFrame = (src) => YOUTUBE_NOCOOKIE_HOSTS.has(src.host) || YOUTUBE_HOSTS.has(src.host) && underPath(src.path, "/embed");
30
+ const dailymotionFrame = (src) => src.host === "geo.dailymotion.com" || src.host === "dai.ly" || DAILYMOTION_HOSTS.has(src.host) && (underPath(src.path, "/embed") || underPath(src.path, "/video"));
31
+ const tiktokFrame = (src) => TIKTOK_HOSTS.has(src.host) && underPath(src.path, "/player");
32
+ const twitchFrame = (src) => src.host === "player.twitch.tv" || src.host === "clips.twitch.tv" && underPath(src.path, "/embed");
33
+ const vimeoFrame = (src) => src.host === VIMEO_PLAYER_HOST;
34
+ const facebookFrame = (src) => FACEBOOK_PLUGIN_HOSTS.has(src.host) && underPath(src.path, "/plugins");
35
+ const giphyFrame = (src) => GIPHY_PAGE_HOSTS.has(src.host) && underPath(src.path, "/embed");
36
+ const kickFrame = (src) => KICK_PLAYER_HOSTS.has(src.host);
37
+ const linkedinFrame = (src) => src.host === "www.linkedin.com" && underPath(src.path, "/embed");
38
+ const pinterestFrame = (src) => src.host === PINTEREST_FRAME_HOST;
39
+ const appleMusicFrame = (src) => src.host === APPLE_MUSIC_FRAME_HOST;
40
+ const applePodcastsFrame = (src) => src.host === APPLE_PODCASTS_FRAME_HOST;
41
+ const soundcloudFrame = (src) => src.host === SOUNDCLOUD_WIDGET_HOST;
42
+ const spotifyFrame = (src) => src.host === "open.spotify.com" && underPath(src.path, "/embed");
43
+ const rumbleFrame = (src) => src.host === "rumble.com" && underPath(src.path, "/embed");
44
+ const streamableFrame = (src) => src.host === "streamable.com" && (underPath(src.path, "/e") || underPath(src.path, "/o"));
45
+ const tenorFrame = (src) => src.host === "tenor.com" && underPath(src.path, "/embed");
46
+ const truthsocialFrame = (src) => src.host === "truthsocial.com" && src.path.startsWith("/@");
47
+ /** True for a frame a named platform serves, which the generic iframe path must refuse. */
48
+ function ownedFrame(src) {
49
+ return [
50
+ youtubeFrame,
51
+ dailymotionFrame,
52
+ tiktokFrame,
53
+ twitchFrame,
54
+ vimeoFrame,
55
+ facebookFrame,
56
+ giphyFrame,
57
+ kickFrame,
58
+ linkedinFrame,
59
+ pinterestFrame,
60
+ appleMusicFrame,
61
+ applePodcastsFrame,
62
+ soundcloudFrame,
63
+ spotifyFrame,
64
+ rumbleFrame,
65
+ streamableFrame,
66
+ tenorFrame,
67
+ truthsocialFrame
68
+ ].some((owns) => owns(src));
69
+ }
70
+ export { APPLE_MUSIC_FRAME_HOST, APPLE_PODCASTS_FRAME_HOST, DAILYMOTION_HOSTS, DAILYMOTION_PLAYER_HOST, DAILYMOTION_SHORT_HOST, FACEBOOK_PLUGIN_HOSTS, GIPHY_PAGE_HOSTS, KICK_PLAYER_HOSTS, LINKEDIN_FRAME_HOST, PINTEREST_FRAME_HOST, SOUNDCLOUD_WIDGET_HOST, SPOTIFY_HOST, TIKTOK_HOSTS, TWITCH_CLIPS_HOST, TWITCH_PLAYER_HOST, VIMEO_PLAYER_HOST, YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS, appleMusicFrame, applePodcastsFrame, dailymotionFrame, facebookFrame, giphyFrame, kickFrame, linkedinFrame, ownedFrame, pinterestFrame, rumbleFrame, soundcloudFrame, spotifyFrame, streamableFrame, tenorFrame, tiktokFrame, truthsocialFrame, twitchFrame, vimeoFrame, youtubeFrame };
@@ -0,0 +1,19 @@
1
+ export type HtmlElement = {
2
+ type: 'element';
3
+ tag: string;
4
+ attrs: ReadonlyMap<string, string>;
5
+ children: HtmlNode[];
6
+ };
7
+ export type HtmlText = {
8
+ type: 'text';
9
+ raw: string;
10
+ };
11
+ export type HtmlComment = {
12
+ type: 'comment';
13
+ };
14
+ export type HtmlNode = HtmlElement | HtmlText | HtmlComment;
15
+ export type AttributeRule = string | {
16
+ name: string;
17
+ value: RegExp;
18
+ };
19
+ export type Whitelist = ReadonlyMap<string, readonly AttributeRule[]>;
@@ -1,6 +1,6 @@
1
1
  import { descendants, parseHtml } from "./html.js";
2
2
  import { sizeOf, unwrapRatio } from "./platform.js";
3
- import { platforms } from "./platforms/index.js";
3
+ import { ownedFrame } from "./frames.js";
4
4
  import { parseUrl, pixels } from "./url.js";
5
5
  // src/parser/iframe.ts
6
6
  const REFERRER_POLICIES = [
@@ -102,7 +102,7 @@ function checkSrc(value) {
102
102
  host: url.host.replace(/:\d+$/, ""),
103
103
  path: (url.path.toLowerCase().split(";")[0] ?? "").replaceAll("%2f", "/")
104
104
  };
105
- if (platforms.some((platform) => platform.ownsFrame?.(frame))) return null;
105
+ if (ownedFrame(frame)) return null;
106
106
  return src.startsWith("//") ? `https:${src}` : src;
107
107
  }
108
108
  /** A feature keeps its origin list as written, or is dropped whole when one origin is not safe. */
@@ -3,9 +3,13 @@ import { parseUrl } from "./url.js";
3
3
  // src/parser/match-url.ts
4
4
  /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
5
5
  function matchUrl(url) {
6
+ return matchUrlWith(platforms, url);
7
+ }
8
+ /** `matchUrl` for these platforms only. */
9
+ function matchUrlWith(parsers, url) {
6
10
  const parsed = parse(url);
7
11
  if (!parsed) return null;
8
- for (const platform of platforms) {
12
+ for (const platform of parsers) {
9
13
  const embed = platform.match(parsed);
10
14
  if (embed) return embed;
11
15
  }
@@ -19,4 +23,4 @@ function matchWith(parser, url) {
19
23
  function parse(url) {
20
24
  return typeof url === "string" ? parseUrl(url) : null;
21
25
  }
22
- export { matchUrl, matchWith };
26
+ export { matchUrl, matchUrlWith, matchWith };
@@ -1,4 +1,4 @@
1
- import { parseHtml } from "./html.js";
1
+ import { decodeEntities, parseHtml } from "./html.js";
2
2
  import { platforms } from "./platforms/index.js";
3
3
  // src/parser/parse-embed.ts
4
4
  /**
@@ -7,20 +7,24 @@ import { platforms } from "./platforms/index.js";
7
7
  * comments (docs/decisions.md D14).
8
8
  */
9
9
  function parseEmbed(html) {
10
+ return parseEmbedWith(platforms, html);
11
+ }
12
+ /** `parseEmbed` for these platforms only. */
13
+ function parseEmbedWith(parsers, html) {
10
14
  if (typeof html !== "string") return null;
11
15
  const nodes = parseHtml(html);
12
- return nodes ? parseNodes(nodes) : parseRepaired(html);
16
+ return nodes ? parseNodes(parsers, nodes) : parseRepaired(parsers, html);
13
17
  }
14
- function parseRepaired(html) {
15
- for (const platform of platforms) {
18
+ function parseRepaired(parsers, html) {
19
+ for (const platform of parsers) {
16
20
  const repaired = platform.repair?.(html);
17
21
  const nodes = repaired === void 0 || repaired === null ? null : parseHtml(repaired);
18
- const embed = nodes && parseNodes(nodes);
22
+ const embed = nodes && parseNodes(parsers, nodes);
19
23
  if (embed?.platform === platform.platform) return embed;
20
24
  }
21
25
  return null;
22
26
  }
23
- function parseNodes(nodes) {
27
+ function parseNodes(parsers, nodes) {
24
28
  let root;
25
29
  let extra;
26
30
  const scripts = [];
@@ -28,7 +32,7 @@ function parseNodes(nodes) {
28
32
  for (const node of nodes) {
29
33
  if (node.type === "comment") continue;
30
34
  if (node.type === "text") {
31
- if (/^\s*$/.test(node.raw)) continue;
35
+ if (/^\s*$/.test(decodeEntities(node.raw))) continue;
32
36
  return null;
33
37
  }
34
38
  if (node.tag === "script") scripts.push(node);
@@ -42,13 +46,13 @@ function parseNodes(nodes) {
42
46
  const [script] = scripts;
43
47
  if (fbRoot || scripts.length !== 1 || !script) return null;
44
48
  if (script.children.length !== 0) return null;
45
- for (const platform of platforms) {
49
+ for (const platform of parsers) {
46
50
  const embed = platform.parseScript?.(script);
47
51
  if (embed) return embed;
48
52
  }
49
53
  return null;
50
54
  }
51
- for (const platform of platforms) {
55
+ for (const platform of parsers) {
52
56
  const embed = platform.parse(root);
53
57
  if (!embed) continue;
54
58
  if (fbRoot && !platform.allowsFbRoot) return null;
@@ -66,4 +70,4 @@ function parseNodes(nodes) {
66
70
  function isFbRoot(element) {
67
71
  return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
68
72
  }
69
- export { parseEmbed };
73
+ export { parseEmbed, parseEmbedWith };
@@ -0,0 +1,26 @@
1
+ import { HtmlElement, Whitelist } from "./html.js";
2
+ import { ParsedEmbed, Platform } from "./types.js";
3
+ import { ParsedUrl } from "./url.js";
4
+ export type Options = ParsedEmbed['options'];
5
+ export type PlatformParser = {
6
+ platform: Platform;
7
+ /** Elements and attributes allowed in `fallbackHtml`. */
8
+ fallback?: Whitelist;
9
+ /** The embed element (blockquote, div or iframe) of the platform's own embed code. */
10
+ parse: (root: HtmlElement) => ParsedEmbed | null;
11
+ /** Embed code that is a single `<script>` tag, as Telegram's is. */
12
+ parseScript?: (script: HtmlElement) => ParsedEmbed | null;
13
+ /**
14
+ * For code the HTML parser rejects: the same code without the stray markup this platform's own
15
+ * tool writes, or `null`. The result must still parse as this platform's embed.
16
+ */
17
+ repair?: (html: string) => string | null;
18
+ isOwnScript: (src: string) => boolean;
19
+ scriptOptions?: (src: string) => Options;
20
+ allowsFbRoot?: boolean;
21
+ /** A sibling element after the embed that is the platform's own markup, such as a credit; it is dropped. */
22
+ isOwnExtra?: (element: HtmlElement, embed: ParsedEmbed) => boolean;
23
+ match: (url: ParsedUrl) => ParsedEmbed | null;
24
+ /** True also for frames `parse` rejects, so generic iframe code never bypasses the platform's checks. */
25
+ ownsFrame?: (src: ParsedUrl) => boolean;
26
+ };
@@ -1,9 +1,9 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
2
  import { parseUrl } from "../url.js";
3
+ import { APPLE_MUSIC_FRAME_HOST, appleMusicFrame } from "../frames.js";
3
4
  // src/parser/platforms/applemusic.ts
4
5
  const PATH = /^\/([a-z]{2})\/(album|song|playlist)\/(?:[^/]{1,200}\/)?(\d{1,15}|pl\.[A-Za-z0-9-]{1,64})\/?$/;
5
6
  const SONG = /^\d{1,15}$/;
6
- const FRAME_HOST = "embed.music.apple.com";
7
7
  function appleContent(url, host) {
8
8
  if (url?.host !== host) return null;
9
9
  const [, country, type, id] = PATH.exec(url.path) ?? [];
@@ -22,7 +22,7 @@ const applemusic = {
22
22
  platform: "applemusic",
23
23
  parse(root) {
24
24
  if (root.tag !== "iframe") return null;
25
- const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST);
25
+ const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), APPLE_MUSIC_FRAME_HOST);
26
26
  if (!found) return null;
27
27
  const { height } = sizeOf(root) ?? {};
28
28
  return withSize({
@@ -40,6 +40,6 @@ const applemusic = {
40
40
  options: {}
41
41
  };
42
42
  },
43
- ownsFrame: (src) => src.host === FRAME_HOST
43
+ ownsFrame: appleMusicFrame
44
44
  };
45
45
  export { applemusic };
@@ -1,9 +1,9 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
2
  import { parseUrl } from "../url.js";
3
+ import { APPLE_PODCASTS_FRAME_HOST, applePodcastsFrame } from "../frames.js";
3
4
  // src/parser/platforms/applepodcasts.ts
4
5
  const PATH = /^\/([a-z]{2})\/podcast\/(?:[^/]{1,200}\/)?(?:id)?(\d{1,15})\/?$/;
5
6
  const EPISODE = /^\d{1,15}$/;
6
- const FRAME_HOST = "embed.podcasts.apple.com";
7
7
  function content(url, host) {
8
8
  if (url?.host !== host) return null;
9
9
  const [, country, show] = PATH.exec(url.path) ?? [];
@@ -22,7 +22,7 @@ const applepodcasts = {
22
22
  platform: "applepodcasts",
23
23
  parse(root) {
24
24
  if (root.tag !== "iframe") return null;
25
- const found = content(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST);
25
+ const found = content(parseUrl(root.attrs.get("src") ?? ""), APPLE_PODCASTS_FRAME_HOST);
26
26
  return found && withSize({
27
27
  ...found,
28
28
  options: {}
@@ -36,6 +36,6 @@ const applepodcasts = {
36
36
  options: {}
37
37
  };
38
38
  },
39
- ownsFrame: (src) => src.host === FRAME_HOST
39
+ ownsFrame: applePodcastsFrame
40
40
  };
41
41
  export { applepodcasts };
@@ -1,12 +1,10 @@
1
- import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
1
+ import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
+ import { DAILYMOTION_HOSTS, dailymotionFrame } from "../frames.js";
3
4
  // src/parser/platforms/dailymotion.ts
4
5
  const VIDEO_ID = /^x[a-z0-9]{4,12}$/;
5
6
  const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
6
7
  const WRAPPER = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
7
- const HOSTS = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
8
- const PLAYER_HOST = "geo.dailymotion.com";
9
- const SHORT_HOST = "dai.ly";
10
8
  function video(id, options) {
11
9
  return {
12
10
  platform: "dailymotion",
@@ -19,7 +17,7 @@ function video(id, options) {
19
17
  }
20
18
  /** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
21
19
  function fromPlayer(url) {
22
- if (url.host !== PLAYER_HOST || url.query.has("playlist")) return null;
20
+ if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
23
21
  const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
24
22
  if (!match) return null;
25
23
  const [, playerId] = match;
@@ -31,11 +29,11 @@ function fromPlayer(url) {
31
29
  return video(id, options);
32
30
  }
33
31
  function fromPage(url) {
34
- if (url.host === SHORT_HOST) {
32
+ if (url.host === "dai.ly") {
35
33
  const id = url.path.replace(/^\/|\/$/g, "");
36
34
  return VIDEO_ID.test(id) ? video(id, {}) : null;
37
35
  }
38
- if (!HOSTS.has(url.host)) return null;
36
+ if (!DAILYMOTION_HOSTS.has(url.host)) return null;
39
37
  const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
40
38
  return id !== void 0 && VIDEO_ID.test(id) ? video(id, {}) : null;
41
39
  }
@@ -54,6 +52,6 @@ const dailymotion = {
54
52
  match(url) {
55
53
  return fromPlayer(url) ?? fromPage(url);
56
54
  },
57
- ownsFrame: (src) => src.host === PLAYER_HOST || src.host === SHORT_HOST || HOSTS.has(src.host) && (underPath(src.path, "/embed") || underPath(src.path, "/video"))
55
+ ownsFrame: dailymotionFrame
58
56
  };
59
57
  export { dailymotion };
@@ -1,6 +1,7 @@
1
1
  import { hasClass, rebuild } from "../html.js";
2
- import { attributeOptions, sizeOf, underPath, withSize } from "../platform.js";
2
+ import { attributeOptions, sizeOf, withSize } from "../platform.js";
3
3
  import { coerce, parseUrl, pixels } from "../url.js";
4
+ import { FACEBOOK_PLUGIN_HOSTS, facebookFrame } from "../frames.js";
4
5
  // src/parser/platforms/facebook.ts
5
6
  const HOSTS = /* @__PURE__ */ new Set([
6
7
  "facebook.com",
@@ -8,16 +9,11 @@ const HOSTS = /* @__PURE__ */ new Set([
8
9
  "web.facebook.com",
9
10
  "m.facebook.com"
10
11
  ]);
11
- const PLUGIN_HOSTS = /* @__PURE__ */ new Set([
12
- "facebook.com",
13
- "www.facebook.com",
14
- "web.facebook.com"
15
- ]);
16
12
  const BASE = "https://www.facebook.com";
17
13
  const NAME = "[A-Za-z0-9.\\-]{1,80}";
18
14
  const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
19
15
  const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
20
- const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
16
+ const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.\\-]{1,80})/(\\d{1,25})/?$`);
21
17
  const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
22
18
  const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
23
19
  const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
@@ -136,7 +132,7 @@ const facebook = {
136
132
  }
137
133
  if (root.tag !== "iframe") return null;
138
134
  const src = parseUrl(root.attrs.get("src") ?? "");
139
- if (!src || !PLUGIN_HOSTS.has(src.host)) return null;
135
+ if (!src || !FACEBOOK_PLUGIN_HOSTS.has(src.host)) return null;
140
136
  const found = target(parseUrl(src.query.get("href") ?? ""));
141
137
  if (!found) return null;
142
138
  if (src.path === "/plugins/post.php") {
@@ -180,6 +176,6 @@ const facebook = {
180
176
  const found = target(url);
181
177
  return found && embed(found, found.kind, "sdk", {});
182
178
  },
183
- ownsFrame: (src) => PLUGIN_HOSTS.has(src.host) && underPath(src.path, "/plugins")
179
+ ownsFrame: facebookFrame
184
180
  };
185
181
  export { facebook };
@@ -1,8 +1,8 @@
1
- import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
1
+ import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
2
  import { parseUrl } from "../url.js";
3
+ import { GIPHY_PAGE_HOSTS, giphyFrame } from "../frames.js";
3
4
  // src/parser/platforms/giphy.ts
4
5
  const ID = "([A-Za-z0-9]{6,40})";
5
- const PAGE_HOSTS = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
6
6
  const PAGE_PATH = new RegExp(`^/(?:gifs|stickers)/(?:[A-Za-z0-9-]{0,200}-)?${ID}/?$`);
7
7
  const EMBED_PATH = new RegExp(`^/embed/${ID}/?$`);
8
8
  const MEDIA_HOST = /^(?:media\d?|i)\.giphy\.com$/;
@@ -21,14 +21,14 @@ function gif(id) {
21
21
  }
22
22
  function idOf(url) {
23
23
  if (!url) return void 0;
24
- if (PAGE_HOSTS.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH.exec(url.path))?.[1];
24
+ if (GIPHY_PAGE_HOSTS.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH.exec(url.path))?.[1];
25
25
  if (!MEDIA_HOST.test(url.host)) return void 0;
26
26
  return (MEDIA_PATH.exec(url.path) ?? (url.host === "i.giphy.com" ? SHORT_MEDIA_PATH.exec(url.path) : null))?.[1];
27
27
  }
28
28
  function fromIframe(iframe) {
29
29
  if (iframe.tag !== "iframe") return null;
30
30
  const src = parseUrl(iframe.attrs.get("src") ?? "");
31
- if (!src || !PAGE_HOSTS.has(src.host)) return null;
31
+ if (!src || !GIPHY_PAGE_HOSTS.has(src.host)) return null;
32
32
  const [, id] = EMBED_PATH.exec(src.path) ?? [];
33
33
  return id === void 0 ? null : gif(id);
34
34
  }
@@ -38,7 +38,7 @@ function isCredit(element, embed) {
38
38
  if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return false;
39
39
  if (link.attrs.size !== 1) return false;
40
40
  const href = parseUrl(link.attrs.get("href") ?? "");
41
- if (!href || !PAGE_HOSTS.has(href.host) || PAGE_PATH.exec(href.path)?.[1] !== embed.id) return false;
41
+ if (!href || !GIPHY_PAGE_HOSTS.has(href.host) || PAGE_PATH.exec(href.path)?.[1] !== embed.id) return false;
42
42
  const [text, ...more] = link.children;
43
43
  return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
44
44
  }
@@ -63,6 +63,6 @@ const giphy = {
63
63
  options: {}
64
64
  };
65
65
  },
66
- ownsFrame: (src) => PAGE_HOSTS.has(src.host) && underPath(src.path, "/embed")
66
+ ownsFrame: giphyFrame
67
67
  };
68
68
  export { giphy };
@@ -1,5 +1,6 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
+ import { KICK_PLAYER_HOSTS, kickFrame } from "../frames.js";
3
4
  // src/parser/platforms/kick.ts
4
5
  const PAGE_HOSTS = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
5
6
  const CHANNEL = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
@@ -34,13 +35,12 @@ function channel(url, hosts) {
34
35
  variant: "iframe"
35
36
  };
36
37
  }
37
- const PLAYER = /* @__PURE__ */ new Set(["player.kick.com"]);
38
38
  const kick = {
39
39
  platform: "kick",
40
40
  parse(root) {
41
41
  if (root.tag !== "iframe") return null;
42
42
  const src = parseUrl(root.attrs.get("src") ?? "");
43
- const found = channel(src, PLAYER);
43
+ const found = channel(src, KICK_PLAYER_HOSTS);
44
44
  if (!found || !src) return null;
45
45
  const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
46
46
  return withSize({
@@ -50,12 +50,12 @@ const kick = {
50
50
  },
51
51
  isOwnScript: () => false,
52
52
  match(url) {
53
- const found = channel(url, PAGE_HOSTS) ?? channel(url, PLAYER);
53
+ const found = channel(url, PAGE_HOSTS) ?? channel(url, KICK_PLAYER_HOSTS);
54
54
  return found && {
55
55
  ...found,
56
56
  options: {}
57
57
  };
58
58
  },
59
- ownsFrame: (src) => PLAYER.has(src.host)
59
+ ownsFrame: kickFrame
60
60
  };
61
61
  export { kick };
@@ -1,8 +1,8 @@
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 { linkedinFrame } from "../frames.js";
3
4
  // src/parser/platforms/linkedin.ts
4
5
  const HOST = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
5
- const FRAME_HOST = "www.linkedin.com";
6
6
  const URN = "(activity|share|ugcPost):(\\d{19})";
7
7
  const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
8
8
  const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
@@ -24,7 +24,7 @@ const linkedin = {
24
24
  parse(root) {
25
25
  if (root.tag !== "iframe") return null;
26
26
  const src = parseUrl(root.attrs.get("src") ?? "");
27
- if (src?.host !== FRAME_HOST) return null;
27
+ if (src?.host !== "www.linkedin.com") return null;
28
28
  const [, type, id] = EMBED_PATH.exec(src.path) ?? [];
29
29
  if (type === void 0 || id === void 0) return null;
30
30
  const options = Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]));
@@ -37,6 +37,6 @@ const linkedin = {
37
37
  const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
38
38
  return type === void 0 || id === void 0 ? null : post(type, id);
39
39
  },
40
- ownsFrame: (src) => src.host === FRAME_HOST && underPath(src.path, "/embed")
40
+ ownsFrame: linkedinFrame
41
41
  };
42
42
  export { linkedin };
@@ -1,10 +1,10 @@
1
1
  import { attributeOptions } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
+ import { pinterestFrame } from "../frames.js";
3
4
  // src/parser/platforms/pinterest.ts
4
5
  const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
5
6
  const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
6
7
  const PIN_ID = /^\d{1,25}$/;
7
- const FRAME_HOST = "assets.pinterest.com";
8
8
  const SCRIPT = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
9
9
  const OPTION_ATTRIBUTES = [
10
10
  ["data-pin-width", "width"],
@@ -39,7 +39,7 @@ const pinterest = {
39
39
  }
40
40
  if (root.tag !== "iframe") return null;
41
41
  const src = parseUrl(root.attrs.get("src") ?? "");
42
- if (src?.host !== FRAME_HOST || src.path !== "/ext/embed.html") return null;
42
+ if (src?.host !== "assets.pinterest.com" || src.path !== "/ext/embed.html") return null;
43
43
  const id = src.query.get("id");
44
44
  return id !== void 0 && PIN_ID.test(id) ? {
45
45
  ...pin(id),
@@ -54,6 +54,6 @@ const pinterest = {
54
54
  options: {}
55
55
  };
56
56
  },
57
- ownsFrame: (src) => src.host === FRAME_HOST
57
+ ownsFrame: pinterestFrame
58
58
  };
59
59
  export { pinterest };
@@ -10,6 +10,7 @@ const HOSTS = /* @__PURE__ */ new Set([
10
10
  ]);
11
11
  const POST_PATH = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
12
12
  const SCRIPT = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
13
+ const CARD_SCRIPT = /^(?:https?:)?\/\/embed\.redditmedia\.com\/widgets\/platform\.js$/;
13
14
  const OPTION_ATTRIBUTES = [
14
15
  "depth",
15
16
  "style",
@@ -47,7 +48,7 @@ function post(url) {
47
48
  const reddit = {
48
49
  platform: "reddit",
49
50
  parse(root) {
50
- if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
51
+ if (root.tag !== "blockquote" || !(hasClass(root, "reddit-embed-bq") || hasClass(root, "reddit-card"))) return null;
51
52
  const found = descendants(root.children).map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
52
53
  if (!found) return null;
53
54
  const height = pixels(root.attrs.get("data-embed-height"));
@@ -56,7 +57,7 @@ const reddit = {
56
57
  options: attributeOptions(root, OPTION_ATTRIBUTES, coerce)
57
58
  }, height === void 0 ? void 0 : { height });
58
59
  },
59
- isOwnScript: (src) => SCRIPT.test(src),
60
+ isOwnScript: (src) => SCRIPT.test(src) || CARD_SCRIPT.test(src),
60
61
  match(url) {
61
62
  const found = post(url);
62
63
  return found && {
@@ -1,5 +1,6 @@
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 { rumbleFrame } from "../frames.js";
3
4
  // src/parser/platforms/rumble.ts
4
5
  const PATH = /^\/embed\/(v[a-z0-9]{1,12})\/?$/;
5
6
  const HOSTS = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
@@ -38,6 +39,6 @@ const rumble = {
38
39
  options: {}
39
40
  };
40
41
  },
41
- ownsFrame: (src) => src.host === "rumble.com" && underPath(src.path, "/embed")
42
+ ownsFrame: rumbleFrame
42
43
  };
43
44
  export { rumble };
@@ -1,5 +1,6 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
+ import { soundcloudFrame } from "../frames.js";
3
4
  // src/parser/platforms/soundcloud.ts
4
5
  const PAGE_HOSTS = /* @__PURE__ */ new Set([
5
6
  "soundcloud.com",
@@ -42,7 +43,6 @@ const NOT_SOUNDS = /* @__PURE__ */ new Set([
42
43
  "toptracks"
43
44
  ]);
44
45
  const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
45
- const WIDGET_HOST = "w.soundcloud.com";
46
46
  function sound(url, id) {
47
47
  return {
48
48
  platform: "soundcloud",
@@ -96,7 +96,7 @@ const soundcloud = {
96
96
  parse(root) {
97
97
  if (root.tag !== "iframe") return null;
98
98
  const src = parseUrl(root.attrs.get("src") ?? "");
99
- if (src?.host !== WIDGET_HOST || !/^\/player\/?$/.test(src.path)) return null;
99
+ if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
100
100
  let found = fromApi(parseUrl(src.query.get("url") ?? ""));
101
101
  if (!found) return null;
102
102
  const outer = src.query.get("secret_token");
@@ -123,6 +123,6 @@ const soundcloud = {
123
123
  options: {}
124
124
  };
125
125
  },
126
- ownsFrame: (src) => src.host === WIDGET_HOST
126
+ ownsFrame: soundcloudFrame
127
127
  };
128
128
  export { soundcloud };
@@ -1,11 +1,11 @@
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 { spotifyFrame } from "../frames.js";
3
4
  // src/parser/platforms/spotify.ts
4
5
  const CONTENT_PATH = new RegExp(`^(?:/intl-[a-z]{2}(?:-[A-Za-z]{2})?)?(?:/embed)?/(track|album|playlist|artist|episode|show|audiobook|chapter)/([A-Za-z0-9]{22})(/video)?/?$`);
5
6
  const DROPPED = /* @__PURE__ */ new Set(["utm_source", "si"]);
6
- const HOST = "open.spotify.com";
7
7
  function content(url) {
8
- if (url?.host !== HOST) return null;
8
+ if (url?.host !== "open.spotify.com") return null;
9
9
  const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
10
10
  if (type === void 0 || id === void 0) return null;
11
11
  return {
@@ -46,6 +46,6 @@ const spotify = {
46
46
  options: {}
47
47
  };
48
48
  },
49
- ownsFrame: (src) => src.host === HOST && underPath(src.path, "/embed")
49
+ ownsFrame: spotifyFrame
50
50
  };
51
51
  export { spotify };
@@ -1,5 +1,6 @@
1
- import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
1
+ import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
+ import { streamableFrame } from "../frames.js";
3
4
  // src/parser/platforms/streamable.ts
4
5
  const ID = "([a-z0-9]{4,8})";
5
6
  const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
@@ -89,6 +90,6 @@ const streamable = {
89
90
  options: {}
90
91
  };
91
92
  },
92
- ownsFrame: (src) => src.host === "streamable.com" && (underPath(src.path, "/e") || underPath(src.path, "/o"))
93
+ ownsFrame: streamableFrame
93
94
  };
94
95
  export { streamable };
@@ -1,6 +1,7 @@
1
1
  import { hasClass, rebuild } from "../html.js";
2
- import { sizeOf, underPath, withSize } from "../platform.js";
2
+ import { sizeOf, withSize } from "../platform.js";
3
3
  import { parseUrl } from "../url.js";
4
+ import { tenorFrame } from "../frames.js";
4
5
  // src/parser/platforms/tenor.ts
5
6
  const HOSTS = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
6
7
  const ID = "(\\d{1,20})";
@@ -73,6 +74,6 @@ const tenor = {
73
74
  options: {}
74
75
  };
75
76
  },
76
- ownsFrame: (src) => src.host === "tenor.com" && underPath(src.path, "/embed")
77
+ ownsFrame: tenorFrame
77
78
  };
78
79
  export { tenor };