social-embeds 0.9.0 → 0.9.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.
Files changed (111) hide show
  1. package/README.md +7 -7
  2. package/dist/components/apple-embed.d.ts +2 -2
  3. package/dist/components/apple-embed.js +6 -28
  4. package/dist/components/bluesky-embed.d.ts +1 -1
  5. package/dist/components/bluesky-embed.js +5 -16
  6. package/dist/components/dailymotion-embed.d.ts +1 -1
  7. package/dist/components/dailymotion-embed.js +10 -20
  8. package/dist/components/facebook-embed.d.ts +1 -1
  9. package/dist/components/facebook-embed.js +13 -34
  10. package/dist/components/flickr-embed.d.ts +1 -1
  11. package/dist/components/flickr-embed.js +9 -20
  12. package/dist/components/giphy-embed.d.ts +1 -1
  13. package/dist/components/giphy-embed.js +4 -15
  14. package/dist/components/iframe-embed.js +30 -32
  15. package/dist/components/imgur-embed.d.ts +1 -1
  16. package/dist/components/imgur-embed.js +5 -16
  17. package/dist/components/instagram-embed.d.ts +1 -1
  18. package/dist/components/instagram-embed.js +5 -19
  19. package/dist/components/kick-embed.d.ts +1 -1
  20. package/dist/components/kick-embed.js +5 -18
  21. package/dist/components/linkedin-embed.d.ts +1 -1
  22. package/dist/components/linkedin-embed.js +5 -16
  23. package/dist/components/pinterest-embed.d.ts +1 -1
  24. package/dist/components/pinterest-embed.js +5 -19
  25. package/dist/components/reddit-embed.d.ts +1 -1
  26. package/dist/components/reddit-embed.js +12 -22
  27. package/dist/components/rumble-embed.d.ts +1 -1
  28. package/dist/components/rumble-embed.js +4 -15
  29. package/dist/components/script-embed.js +14 -1
  30. package/dist/components/snapchat-embed.d.ts +1 -1
  31. package/dist/components/snapchat-embed.js +4 -15
  32. package/dist/components/soundcloud-embed.d.ts +1 -1
  33. package/dist/components/soundcloud-embed.js +15 -26
  34. package/dist/components/spotify-embed.d.ts +1 -1
  35. package/dist/components/spotify-embed.js +5 -15
  36. package/dist/components/strava-embed.d.ts +1 -1
  37. package/dist/components/strava-embed.js +9 -19
  38. package/dist/components/streamable-embed.d.ts +1 -1
  39. package/dist/components/streamable-embed.js +11 -21
  40. package/dist/components/telegram-embed.d.ts +1 -1
  41. package/dist/components/telegram-embed.js +10 -20
  42. package/dist/components/tenor-embed.d.ts +1 -1
  43. package/dist/components/tenor-embed.js +4 -15
  44. package/dist/components/threads-embed.d.ts +1 -1
  45. package/dist/components/threads-embed.js +5 -19
  46. package/dist/components/tiktok-embed.d.ts +1 -1
  47. package/dist/components/tiktok-embed.js +20 -30
  48. package/dist/components/truthsocial-embed.d.ts +1 -1
  49. package/dist/components/truthsocial-embed.js +4 -15
  50. package/dist/components/tumblr-embed.d.ts +1 -1
  51. package/dist/components/tumblr-embed.js +4 -15
  52. package/dist/components/twitch-embed.d.ts +1 -1
  53. package/dist/components/twitch-embed.js +9 -19
  54. package/dist/components/use-plan.js +20 -0
  55. package/dist/components/vimeo-embed.d.ts +1 -1
  56. package/dist/components/vimeo-embed.js +24 -34
  57. package/dist/components/x-embed.d.ts +1 -1
  58. package/dist/components/x-embed.js +12 -26
  59. package/dist/components/youtube-embed.d.ts +1 -1
  60. package/dist/components/youtube-embed.js +27 -37
  61. package/dist/core/drivers.js +6 -6
  62. package/dist/core/layout.js +1 -45
  63. package/dist/core/message-height.js +24 -0
  64. package/dist/core/plans/bluesky.js +3 -1
  65. package/dist/core/plans/flickr.js +16 -6
  66. package/dist/core/plans/imgur.js +3 -1
  67. package/dist/core/plans/reddit.js +3 -1
  68. package/dist/core/plans/strava.js +3 -1
  69. package/dist/core/plans/telegram.js +3 -1
  70. package/dist/core/plans/truthsocial.js +5 -2
  71. package/dist/core/plans/tumblr.js +3 -1
  72. package/dist/core/plans/twitch.js +5 -2
  73. package/dist/core/resolve.js +15 -37
  74. package/dist/core/size-in-src.js +47 -0
  75. package/dist/element.js +1 -1
  76. package/dist/loader/platform-scripts.js +23 -22
  77. package/dist/parser/html.d.ts +1 -6
  78. package/dist/parser/html.js +6 -1
  79. package/dist/parser/lookup.js +11 -5
  80. package/dist/parser/platform.d.ts +9 -3
  81. package/dist/parser/platforms/applemusic.js +2 -0
  82. package/dist/parser/platforms/applepodcasts.js +2 -0
  83. package/dist/parser/platforms/bluesky.js +6 -2
  84. package/dist/parser/platforms/dailymotion.js +2 -0
  85. package/dist/parser/platforms/facebook.js +8 -2
  86. package/dist/parser/platforms/flickr.js +4 -2
  87. package/dist/parser/platforms/giphy.js +2 -0
  88. package/dist/parser/platforms/imgur.js +4 -2
  89. package/dist/parser/platforms/instagram.js +4 -2
  90. package/dist/parser/platforms/kick.js +2 -0
  91. package/dist/parser/platforms/linkedin.js +2 -0
  92. package/dist/parser/platforms/pinterest.js +2 -0
  93. package/dist/parser/platforms/reddit.js +2 -0
  94. package/dist/parser/platforms/rumble.js +4 -0
  95. package/dist/parser/platforms/snapchat.js +2 -0
  96. package/dist/parser/platforms/soundcloud.js +2 -0
  97. package/dist/parser/platforms/spotify.js +2 -0
  98. package/dist/parser/platforms/strava.js +2 -0
  99. package/dist/parser/platforms/streamable.js +2 -0
  100. package/dist/parser/platforms/telegram.js +2 -0
  101. package/dist/parser/platforms/tenor.js +4 -2
  102. package/dist/parser/platforms/threads.js +4 -2
  103. package/dist/parser/platforms/tiktok.js +2 -0
  104. package/dist/parser/platforms/truthsocial.js +2 -0
  105. package/dist/parser/platforms/tumblr.js +2 -0
  106. package/dist/parser/platforms/twitch.js +2 -0
  107. package/dist/parser/platforms/vimeo.js +2 -0
  108. package/dist/parser/platforms/x.js +8 -2
  109. package/dist/parser/platforms/youtube.js +2 -0
  110. package/dist/parser/verify.js +2 -46
  111. package/package.json +1 -1
@@ -12,9 +12,15 @@ const RUMBLE_PAGE = /^\/v[a-z0-9]{1,12}-[^/]{1,300}\.html$/;
12
12
  function needsLookup(url) {
13
13
  const parsed = typeof url === "string" ? parseUrl(url) : null;
14
14
  if (!parsed) return null;
15
- if (RUMBLE_HOSTS.has(parsed.host)) return RUMBLE_PAGE.test(parsed.path) ? "rumble" : null;
16
- if (!BLUESKY_HOSTS.has(parsed.host)) return null;
17
- const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
18
- return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
15
+ if (rumbleNeedsLookup(parsed)) return "rumble";
16
+ return blueskyNeedsLookup(parsed) ? "bluesky" : null;
19
17
  }
20
- export { needsLookup };
18
+ function rumbleNeedsLookup(url) {
19
+ return RUMBLE_HOSTS.has(url.host) && RUMBLE_PAGE.test(url.path);
20
+ }
21
+ function blueskyNeedsLookup(url) {
22
+ if (!BLUESKY_HOSTS.has(url.host)) return false;
23
+ const [, profile] = HANDLE_POST.exec(url.path) ?? [];
24
+ return profile !== void 0 && HANDLE.test(profile);
25
+ }
26
+ export { blueskyNeedsLookup, needsLookup, rumbleNeedsLookup };
@@ -1,11 +1,17 @@
1
- import { HtmlElement, Whitelist } from "./html.js";
1
+ import { HtmlElement } from "./html.js";
2
2
  import { ParsedEmbed, Platform } from "./types.js";
3
3
  import { ParsedUrl } from "./url.js";
4
4
  export type Options = ParsedEmbed['options'];
5
5
  export type PlatformParser = {
6
6
  platform: Platform;
7
- /** Elements and attributes allowed in `fallbackHtml`. */
8
- fallback?: Whitelist;
7
+ /** For messages: `YouTube`, `Apple Music`. */
8
+ name: string;
9
+ /** The `kind variant` pairs this platform's embeds may have, such as `post sdk`. */
10
+ shapes: readonly string[];
11
+ /** True when `fallbackHtml` is exactly what this parser writes for the embed (docs/decisions.md D35). */
12
+ trustsFallback?: (html: string, embed: ParsedEmbed) => boolean;
13
+ /** A post URL that only a network lookup could turn into an embed (docs/decisions.md D70). */
14
+ needsLookup?: (url: ParsedUrl) => boolean;
9
15
  /** The embed element (blockquote, div or iframe) of the platform's own embed code. */
10
16
  parse: (root: HtmlElement) => ParsedEmbed | null;
11
17
  /** Embed code that is a single `<script>` tag, as Telegram's is. */
@@ -20,6 +20,8 @@ function appleContent(url, host) {
20
20
  }
21
21
  const applemusic = {
22
22
  platform: "applemusic",
23
+ name: "Apple Music",
24
+ shapes: ["post iframe"],
23
25
  parse(root) {
24
26
  if (root.tag !== "iframe") return null;
25
27
  const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), APPLE_MUSIC_FRAME_HOST);
@@ -20,6 +20,8 @@ function content(url, host) {
20
20
  }
21
21
  const applepodcasts = {
22
22
  platform: "applepodcasts",
23
+ name: "Apple Podcasts",
24
+ shapes: ["post iframe"],
23
25
  parse(root) {
24
26
  if (root.tag !== "iframe") return null;
25
27
  const found = content(parseUrl(root.attrs.get("src") ?? ""), APPLE_PODCASTS_FRAME_HOST);
@@ -1,4 +1,5 @@
1
- import { descendants, hasClass, rebuild } from "../html.js";
1
+ import { blueskyNeedsLookup } from "../lookup.js";
2
+ import { descendants, hasClass, rebuild, rebuildsAs } from "../html.js";
2
3
  import { parseUrl } from "../url.js";
3
4
  // src/parser/platforms/bluesky.ts
4
5
  const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
@@ -34,7 +35,10 @@ function fromUrl(url) {
34
35
  }
35
36
  const bluesky = {
36
37
  platform: "bluesky",
37
- fallback: FALLBACK,
38
+ name: "Bluesky",
39
+ shapes: ["post iframe"],
40
+ needsLookup: blueskyNeedsLookup,
41
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
38
42
  parse(root) {
39
43
  if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
40
44
  const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
@@ -39,6 +39,8 @@ function fromPage(url) {
39
39
  }
40
40
  const dailymotion = {
41
41
  platform: "dailymotion",
42
+ name: "Dailymotion",
43
+ shapes: ["video iframe"],
42
44
  parse(root) {
43
45
  const wrapped = unwrapRatio(root, WRAPPER);
44
46
  const iframe = wrapped?.iframe ?? root;
@@ -1,4 +1,4 @@
1
- import { hasClass, rebuild } from "../html.js";
1
+ import { hasClass, rebuild, rebuildsAs } from "../html.js";
2
2
  import { attributeOptions, sizeOf, withSize } from "../platform.js";
3
3
  import { coerce, parseUrl, pixels } from "../url.js";
4
4
  import { FACEBOOK_PLUGIN_HOSTS, facebookFrame } from "../frames.js";
@@ -119,7 +119,13 @@ function embed(found, kind, variant, options) {
119
119
  }
120
120
  const facebook = {
121
121
  platform: "facebook",
122
- fallback: FALLBACK,
122
+ name: "Facebook",
123
+ shapes: [
124
+ "post sdk",
125
+ "video sdk",
126
+ "video iframe"
127
+ ],
128
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
123
129
  parse(root) {
124
130
  if (root.tag === "div") {
125
131
  const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
@@ -1,4 +1,4 @@
1
- import { rebuild } from "../html.js";
1
+ import { rebuild, rebuildsAs } from "../html.js";
2
2
  import { sizeOf, withSize } from "../platform.js";
3
3
  import { parseUrl } from "../url.js";
4
4
  // src/parser/platforms/flickr.ts
@@ -103,7 +103,9 @@ function onlyImage(root) {
103
103
  }
104
104
  const flickr = {
105
105
  platform: "flickr",
106
- fallback: FALLBACK,
106
+ name: "Flickr",
107
+ shapes: ["post iframe"],
108
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
107
109
  parse(root) {
108
110
  if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
109
111
  const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
@@ -44,6 +44,8 @@ function isCredit(element, embed) {
44
44
  }
45
45
  const giphy = {
46
46
  platform: "giphy",
47
+ name: "Giphy",
48
+ shapes: ["video iframe"],
47
49
  parse(root) {
48
50
  const wrapped = unwrapRatio(root, WRAPPER);
49
51
  const iframe = wrapped?.iframe ?? root;
@@ -1,4 +1,4 @@
1
- import { hasClass, rebuild } from "../html.js";
1
+ import { hasClass, rebuild, rebuildsAs } from "../html.js";
2
2
  // src/parser/platforms/imgur.ts
3
3
  const HOSTS = /* @__PURE__ */ new Set([
4
4
  "imgur.com",
@@ -80,7 +80,9 @@ function falseOption(root, attribute) {
80
80
  }
81
81
  const imgur = {
82
82
  platform: "imgur",
83
- fallback: FALLBACK,
83
+ name: "Imgur",
84
+ shapes: ["post iframe"],
85
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
84
86
  parse(root) {
85
87
  if (root.tag !== "blockquote" || !hasClass(root, "imgur-embed-pub")) return null;
86
88
  const id = root.attrs.get("data-id") ?? "";
@@ -1,4 +1,4 @@
1
- import { descendants, hasClass, rebuild } from "../html.js";
1
+ import { descendants, hasClass, rebuild, rebuildsAs } from "../html.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
3
  // src/parser/platforms/instagram.ts
4
4
  const HOSTS = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
@@ -31,7 +31,9 @@ function post(url) {
31
31
  }
32
32
  const instagram = {
33
33
  platform: "instagram",
34
- fallback: FALLBACK,
34
+ name: "Instagram",
35
+ shapes: ["post sdk"],
36
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
35
37
  parse(root) {
36
38
  if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
37
39
  const permalink = root.attrs.get("data-instgrm-permalink");
@@ -37,6 +37,8 @@ function channel(url, hosts) {
37
37
  }
38
38
  const kick = {
39
39
  platform: "kick",
40
+ name: "Kick",
41
+ shapes: ["video iframe"],
40
42
  parse(root) {
41
43
  if (root.tag !== "iframe") return null;
42
44
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -21,6 +21,8 @@ function post(type, id, options = {}) {
21
21
  const decodeColons = (path) => path.replace(/%3A/gi, ":");
22
22
  const linkedin = {
23
23
  platform: "linkedin",
24
+ name: "LinkedIn",
25
+ shapes: ["post iframe"],
24
26
  parse(root) {
25
27
  if (root.tag !== "iframe") return null;
26
28
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -27,6 +27,8 @@ function pinOf(url) {
27
27
  }
28
28
  const pinterest = {
29
29
  platform: "pinterest",
30
+ name: "Pinterest",
31
+ shapes: ["post sdk"],
30
32
  parse(root) {
31
33
  if (root.tag === "a") {
32
34
  if (root.attrs.get("data-pin-do") !== "embedPin") return null;
@@ -47,6 +47,8 @@ function post(url) {
47
47
  }
48
48
  const reddit = {
49
49
  platform: "reddit",
50
+ name: "Reddit",
51
+ shapes: ["post iframe"],
50
52
  parse(root) {
51
53
  if (root.tag !== "blockquote" || !(hasClass(root, "reddit-embed-bq") || hasClass(root, "reddit-card"))) return null;
52
54
  const found = descendants(root.children).map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
@@ -1,3 +1,4 @@
1
+ import { rumbleNeedsLookup } from "../lookup.js";
1
2
  import { sizeOf, withSize } from "../platform.js";
2
3
  import { coerce, parseUrl } from "../url.js";
3
4
  import { rumbleFrame } from "../frames.js";
@@ -18,6 +19,9 @@ function idOf(url, hosts) {
18
19
  }
19
20
  const rumble = {
20
21
  platform: "rumble",
22
+ name: "Rumble",
23
+ shapes: ["video iframe"],
24
+ needsLookup: rumbleNeedsLookup,
21
25
  parse(root) {
22
26
  if (root.tag !== "iframe") return null;
23
27
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -51,6 +51,8 @@ function content(url) {
51
51
  }
52
52
  const snapchat = {
53
53
  platform: "snapchat",
54
+ name: "Snapchat",
55
+ shapes: ["post iframe", "video iframe"],
54
56
  parse(root) {
55
57
  if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
56
58
  const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
@@ -93,6 +93,8 @@ function isCredit(element) {
93
93
  }
94
94
  const soundcloud = {
95
95
  platform: "soundcloud",
96
+ name: "SoundCloud",
97
+ shapes: ["post iframe"],
96
98
  parse(root) {
97
99
  if (root.tag !== "iframe") return null;
98
100
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -22,6 +22,8 @@ function options(query) {
22
22
  }
23
23
  const spotify = {
24
24
  platform: "spotify",
25
+ name: "Spotify",
26
+ shapes: ["post iframe", "video iframe"],
25
27
  parse(root) {
26
28
  if (root.tag !== "iframe") return null;
27
29
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -24,6 +24,8 @@ function isType(value) {
24
24
  }
25
25
  const strava = {
26
26
  platform: "strava",
27
+ name: "Strava",
28
+ shapes: ["post iframe"],
27
29
  parse(root) {
28
30
  if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
29
31
  if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
@@ -68,6 +68,8 @@ function idOf(url) {
68
68
  }
69
69
  const streamable = {
70
70
  platform: "streamable",
71
+ name: "Streamable",
72
+ shapes: ["video iframe"],
71
73
  parse(root) {
72
74
  const wrapped = unwrapRatio(root, WRAPPER);
73
75
  const iframe = wrapped?.iframe ?? root;
@@ -36,6 +36,8 @@ function post(channel, id, options) {
36
36
  }
37
37
  const telegram = {
38
38
  platform: "telegram",
39
+ name: "Telegram",
40
+ shapes: ["post iframe"],
39
41
  parse: () => null,
40
42
  parseScript(script) {
41
43
  if (!SCRIPT.test(script.attrs.get("src") ?? "")) return null;
@@ -1,4 +1,4 @@
1
- import { hasClass, rebuild } from "../html.js";
1
+ import { hasClass, rebuild, rebuildsAs } from "../html.js";
2
2
  import { sizeOf, withSize } from "../platform.js";
3
3
  import { parseUrl } from "../url.js";
4
4
  import { tenorFrame } from "../frames.js";
@@ -61,7 +61,9 @@ function fromIframe(root) {
61
61
  }
62
62
  const tenor = {
63
63
  platform: "tenor",
64
- fallback: FALLBACK,
64
+ name: "Tenor",
65
+ shapes: ["video iframe"],
66
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
65
67
  parse(root) {
66
68
  if (root.tag === "div") return fromDiv(root);
67
69
  return root.tag === "iframe" ? fromIframe(root) : null;
@@ -1,4 +1,4 @@
1
- import { hasClass, rebuild } from "../html.js";
1
+ import { hasClass, rebuild, rebuildsAs } from "../html.js";
2
2
  import { attributeOptions } from "../platform.js";
3
3
  import { coerce, parseUrl } from "../url.js";
4
4
  // src/parser/platforms/threads.ts
@@ -26,7 +26,9 @@ function post(url) {
26
26
  }
27
27
  const threads = {
28
28
  platform: "threads",
29
- fallback: FALLBACK,
29
+ name: "Threads",
30
+ shapes: ["post sdk"],
31
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
30
32
  parse(root) {
31
33
  if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
32
34
  const found = post(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
@@ -19,6 +19,8 @@ function video(id, user = "", options = {}) {
19
19
  }
20
20
  const tiktok = {
21
21
  platform: "tiktok",
22
+ name: "TikTok",
23
+ shapes: ["video iframe"],
22
24
  parse(root) {
23
25
  if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
24
26
  const cite = parseUrl(root.attrs.get("cite") ?? "");
@@ -25,6 +25,8 @@ function fromUrl(url) {
25
25
  }
26
26
  const truthsocial = {
27
27
  platform: "truthsocial",
28
+ name: "Truth Social",
29
+ shapes: ["post iframe"],
28
30
  parse(root) {
29
31
  if (root.tag !== "iframe") return null;
30
32
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -43,6 +43,8 @@ function fromUrl(url) {
43
43
  }
44
44
  const tumblr = {
45
45
  platform: "tumblr",
46
+ name: "Tumblr",
47
+ shapes: ["post iframe"],
46
48
  parse(root) {
47
49
  if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
48
50
  const frame = parseUrl(root.attrs.get("data-href") ?? "");
@@ -100,6 +100,8 @@ function fromPage(url) {
100
100
  }
101
101
  const twitch = {
102
102
  platform: "twitch",
103
+ name: "Twitch",
104
+ shapes: ["video iframe"],
103
105
  parse(root) {
104
106
  if (root.tag !== "iframe") return null;
105
107
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -72,6 +72,8 @@ function fromPlayer(url) {
72
72
  }
73
73
  const vimeo = {
74
74
  platform: "vimeo",
75
+ name: "Vimeo",
76
+ shapes: ["video iframe"],
75
77
  parse(root) {
76
78
  const wrapped = unwrapRatio(root, WRAPPER);
77
79
  const iframe = wrapped?.iframe ?? root;
@@ -1,4 +1,4 @@
1
- import { descendants, hasClass, rebuild } from "../html.js";
1
+ import { descendants, hasClass, parseHtml, rebuild, rebuildsAs } from "../html.js";
2
2
  import { attributeOptions } from "../platform.js";
3
3
  import { coerce, parseUrl } from "../url.js";
4
4
  // src/parser/platforms/x.ts
@@ -40,9 +40,15 @@ function post(url, path = STATUS_PATH) {
40
40
  variant: "sdk"
41
41
  };
42
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
+ }
43
47
  const x = {
44
48
  platform: "x",
45
- fallback: FALLBACK,
49
+ name: "X",
50
+ shapes: ["post sdk"],
51
+ trustsFallback: (html, embed) => rebuildsAs(html, FALLBACK) && fallbackNamesPost(html, embed.id),
46
52
  parse(root) {
47
53
  if (root.tag !== "blockquote" || !(hasClass(root, "twitter-tweet") || hasClass(root, "twitter-video"))) return null;
48
54
  const status = descendants(root.children).reverse().map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((found) => found !== null);
@@ -71,6 +71,8 @@ function urlOptions(url, nocookie) {
71
71
  }
72
72
  const youtube = {
73
73
  platform: "youtube",
74
+ name: "YouTube",
75
+ shapes: ["video iframe"],
74
76
  parse(root) {
75
77
  if (root.tag !== "iframe") return null;
76
78
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -1,41 +1,5 @@
1
- import { parseHtml, rebuild } from "./html.js";
2
1
  import { matchWith } from "./match-url.js";
3
2
  // src/parser/verify.ts
4
- const SHAPES = {
5
- x: ["post sdk"],
6
- instagram: ["post sdk"],
7
- threads: ["post sdk"],
8
- facebook: [
9
- "post sdk",
10
- "video sdk",
11
- "video iframe"
12
- ],
13
- tiktok: ["video iframe"],
14
- youtube: ["video iframe"],
15
- telegram: ["post iframe"],
16
- snapchat: ["post iframe", "video iframe"],
17
- linkedin: ["post iframe"],
18
- reddit: ["post iframe"],
19
- pinterest: ["post sdk"],
20
- spotify: ["post iframe", "video iframe"],
21
- vimeo: ["video iframe"],
22
- twitch: ["video iframe"],
23
- dailymotion: ["video iframe"],
24
- bluesky: ["post iframe"],
25
- soundcloud: ["post iframe"],
26
- applemusic: ["post iframe"],
27
- applepodcasts: ["post iframe"],
28
- tumblr: ["post iframe"],
29
- kick: ["video iframe"],
30
- giphy: ["video iframe"],
31
- truthsocial: ["post iframe"],
32
- imgur: ["post iframe"],
33
- tenor: ["video iframe"],
34
- streamable: ["video iframe"],
35
- strava: ["post iframe"],
36
- flickr: ["post iframe"],
37
- rumble: ["video iframe"]
38
- };
39
3
  /**
40
4
  * `verifyEmbed` with only the embed's own parser, so a per-platform component does not
41
5
  * bundle the other platforms' (docs/decisions.md D103).
@@ -45,19 +9,11 @@ function verifyWith(parser, embed) {
45
9
  const matched = matchWith(parser, embed.url);
46
10
  if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
47
11
  if (matched.url !== embed.url) return null;
48
- if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
12
+ if (!parser.shapes.includes(`${embed.kind} ${embed.variant}`)) return null;
49
13
  if (embed.fallbackHtml === void 0) return embed;
50
- if (trustedFallback(parser, embed, embed.fallbackHtml)) return embed;
14
+ if (parser.trustsFallback?.(embed.fallbackHtml, embed)) return embed;
51
15
  const withoutFallback = { ...embed };
52
16
  delete withoutFallback.fallbackHtml;
53
17
  return withoutFallback;
54
18
  }
55
- function trustedFallback(parser, embed, fallbackHtml) {
56
- const whitelist = parser.fallback;
57
- const nodes = parseHtml(fallbackHtml);
58
- if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
59
- if (embed.platform !== "x") return true;
60
- const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
61
- return root?.type === "element" && parser.parse(root)?.id === embed.id;
62
- }
63
19
  export { verifyWith };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "social-embeds",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "keywords": [
6
6
  "react",