social-embeds 0.8.1 → 0.9.1

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 (62) hide show
  1. package/README.md +37 -1
  2. package/dist/components/iframe-embed.js +15 -31
  3. package/dist/components/platforms.d.ts +32 -0
  4. package/dist/components/platforms.js +384 -0
  5. package/dist/components/social-embed.d.ts +31 -4
  6. package/dist/components/social-embed.js +48 -211
  7. package/dist/core/drivers.js +6 -6
  8. package/dist/core/layout.js +1 -45
  9. package/dist/core/message-height.js +24 -0
  10. package/dist/core/plans/bluesky.js +3 -1
  11. package/dist/core/plans/flickr.js +16 -6
  12. package/dist/core/plans/imgur.js +3 -1
  13. package/dist/core/plans/reddit.js +3 -1
  14. package/dist/core/plans/strava.js +3 -1
  15. package/dist/core/plans/telegram.js +3 -1
  16. package/dist/core/plans/truthsocial.js +5 -2
  17. package/dist/core/plans/tumblr.js +3 -1
  18. package/dist/core/plans/twitch.js +5 -2
  19. package/dist/core/resolve.js +15 -37
  20. package/dist/core/size-in-src.js +47 -0
  21. package/dist/element.js +1 -1
  22. package/dist/index.d.ts +21 -20
  23. package/dist/index.js +3 -2
  24. package/dist/loader/platform-scripts.js +23 -22
  25. package/dist/parser/html.d.ts +14 -0
  26. package/dist/parser/html.js +6 -1
  27. package/dist/parser/lookup.js +11 -5
  28. package/dist/parser/match-url.js +6 -2
  29. package/dist/parser/parse-embed.js +12 -8
  30. package/dist/parser/platform.d.ts +32 -0
  31. package/dist/parser/platforms/applemusic.js +2 -0
  32. package/dist/parser/platforms/applepodcasts.js +2 -0
  33. package/dist/parser/platforms/bluesky.js +6 -2
  34. package/dist/parser/platforms/dailymotion.js +2 -0
  35. package/dist/parser/platforms/facebook.js +8 -2
  36. package/dist/parser/platforms/flickr.js +4 -2
  37. package/dist/parser/platforms/giphy.js +2 -0
  38. package/dist/parser/platforms/imgur.js +4 -2
  39. package/dist/parser/platforms/instagram.js +4 -2
  40. package/dist/parser/platforms/kick.js +2 -0
  41. package/dist/parser/platforms/linkedin.js +2 -0
  42. package/dist/parser/platforms/pinterest.js +2 -0
  43. package/dist/parser/platforms/reddit.js +2 -0
  44. package/dist/parser/platforms/rumble.js +4 -0
  45. package/dist/parser/platforms/snapchat.js +2 -0
  46. package/dist/parser/platforms/soundcloud.js +2 -0
  47. package/dist/parser/platforms/spotify.js +2 -0
  48. package/dist/parser/platforms/strava.js +2 -0
  49. package/dist/parser/platforms/streamable.js +2 -0
  50. package/dist/parser/platforms/telegram.js +2 -0
  51. package/dist/parser/platforms/tenor.js +4 -2
  52. package/dist/parser/platforms/threads.js +4 -2
  53. package/dist/parser/platforms/tiktok.js +2 -0
  54. package/dist/parser/platforms/truthsocial.js +2 -0
  55. package/dist/parser/platforms/tumblr.js +2 -0
  56. package/dist/parser/platforms/twitch.js +2 -0
  57. package/dist/parser/platforms/vimeo.js +2 -0
  58. package/dist/parser/platforms/x.js +8 -2
  59. package/dist/parser/platforms/youtube.js +2 -0
  60. package/dist/parser/url.d.ts +6 -0
  61. package/dist/parser/verify.js +2 -46
  62. package/package.json +1 -1
@@ -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.8.1",
3
+ "version": "0.9.1",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "keywords": [
6
6
  "react",