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,221 +1,58 @@
1
- import { matchUrl } from "../parser/match-url.js";
2
- import { parseEmbed } from "../parser/parse-embed.js";
3
- import { parseIframe } from "../parser/iframe.js";
4
1
  import { sourceError } from "../core/resolve.js";
5
- import { AppleMusicEmbed, ApplePodcastsEmbed } from "./apple-embed.js";
6
- import { BlueskyEmbed } from "./bluesky-embed.js";
7
- import { DailymotionEmbed } from "./dailymotion-embed.js";
8
- import { FacebookEmbed } from "./facebook-embed.js";
9
- import { FlickrEmbed } from "./flickr-embed.js";
10
- import { GenericIframeEmbed } from "./generic-iframe-embed.js";
11
- import { GiphyEmbed } from "./giphy-embed.js";
2
+ import { matchUrlWith } from "../parser/match-url.js";
3
+ import { parseEmbedWith } from "../parser/parse-embed.js";
12
4
  import { useReportError } from "./hooks.js";
13
- import { ImgurEmbed } from "./imgur-embed.js";
14
- import { InstagramEmbed } from "./instagram-embed.js";
15
- import { KickEmbed } from "./kick-embed.js";
16
- import { LinkedInEmbed } from "./linkedin-embed.js";
17
- import { PinterestEmbed } from "./pinterest-embed.js";
18
- import { RedditEmbed } from "./reddit-embed.js";
19
- import { SnapchatEmbed } from "./snapchat-embed.js";
20
- import { SoundCloudEmbed } from "./soundcloud-embed.js";
21
- import { SpotifyEmbed } from "./spotify-embed.js";
22
- import { StravaEmbed } from "./strava-embed.js";
23
- import { StreamableEmbed } from "./streamable-embed.js";
24
- import { RumbleEmbed } from "./rumble-embed.js";
25
- import { TenorEmbed } from "./tenor-embed.js";
26
- import { TelegramEmbed } from "./telegram-embed.js";
27
- import { ThreadsEmbed } from "./threads-embed.js";
28
- import { TikTokEmbed } from "./tiktok-embed.js";
29
- import { TruthSocialEmbed } from "./truthsocial-embed.js";
30
- import { TumblrEmbed } from "./tumblr-embed.js";
31
- import { TwitchEmbed } from "./twitch-embed.js";
32
- import { VimeoEmbed } from "./vimeo-embed.js";
33
- import { XEmbed } from "./x-embed.js";
34
- import { YouTubeEmbed } from "./youtube-embed.js";
5
+ import { EVERY_PLATFORM } from "./platforms.js";
35
6
  import { useMemo } from "react";
36
- import { jsx } from "react/jsx-runtime";
37
7
  // src/components/social-embed.tsx
38
- /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
39
- function SocialEmbed(props) {
8
+ function tableOf(list) {
9
+ const named = list.flatMap((entry) => entry.kind === "platform" ? [entry] : []);
10
+ return {
11
+ parsers: named.map((entry) => entry.parser),
12
+ renders: new Map(named.map((entry) => [entry.parser.platform, entry.render])),
13
+ iframe: list.find((entry) => entry.kind === "iframe")
14
+ };
15
+ }
16
+ function useSocialEmbed(props, table) {
40
17
  const { html, url, fallback, height, maxHeight, onError, ...shared } = props;
41
- const frame = {
42
- height,
43
- maxHeight
18
+ const route = {
19
+ shared,
20
+ frame: {
21
+ height,
22
+ maxHeight
23
+ },
24
+ onError
44
25
  };
45
- const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
46
- const iframe = useMemo(() => embed === null && html !== void 0 ? parseIframe(html) : null, [embed, html]);
26
+ const embed = useMemo(() => html !== void 0 ? parseEmbedWith(table.parsers, html) : matchUrlWith(table.parsers, url), [
27
+ html,
28
+ url,
29
+ table
30
+ ]);
31
+ const iframe = useMemo(() => embed === null && html !== void 0 ? table.iframe?.parse(html) ?? null : null, [
32
+ embed,
33
+ html,
34
+ table
35
+ ]);
47
36
  useReportError(embed === null && iframe === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
48
- if (iframe) return /* @__PURE__ */ jsx(GenericIframeEmbed, {
49
- ...shared,
50
- ...frame,
51
- onError,
52
- embed: iframe
53
- });
37
+ if (iframe && table.iframe) return table.iframe.render(iframe, route);
54
38
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
55
- switch (embed.platform) {
56
- case "x": return /* @__PURE__ */ jsx(XEmbed, {
57
- ...shared,
58
- onError,
59
- embed
60
- });
61
- case "instagram": return /* @__PURE__ */ jsx(InstagramEmbed, {
62
- ...shared,
63
- onError,
64
- embed
65
- });
66
- case "threads": return /* @__PURE__ */ jsx(ThreadsEmbed, {
67
- ...shared,
68
- onError,
69
- embed
70
- });
71
- case "facebook": return /* @__PURE__ */ jsx(FacebookEmbed, {
72
- ...shared,
73
- ...frame,
74
- onError,
75
- embed
76
- });
77
- case "tiktok": return /* @__PURE__ */ jsx(TikTokEmbed, {
78
- ...shared,
79
- ...frame,
80
- onError,
81
- embed
82
- });
83
- case "youtube": return /* @__PURE__ */ jsx(YouTubeEmbed, {
84
- ...shared,
85
- ...frame,
86
- onError,
87
- embed
88
- });
89
- case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
90
- ...shared,
91
- onError,
92
- embed
93
- });
94
- case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
95
- ...shared,
96
- ...frame,
97
- onError,
98
- embed
99
- });
100
- case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
101
- ...shared,
102
- ...frame,
103
- onError,
104
- embed
105
- });
106
- case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
107
- ...shared,
108
- onError,
109
- embed
110
- });
111
- case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
112
- ...shared,
113
- onError,
114
- embed
115
- });
116
- case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
117
- ...shared,
118
- ...frame,
119
- onError,
120
- embed
121
- });
122
- case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
123
- ...shared,
124
- ...frame,
125
- onError,
126
- embed
127
- });
128
- case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
129
- ...shared,
130
- ...frame,
131
- onError,
132
- embed
133
- });
134
- case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
135
- ...shared,
136
- ...frame,
137
- onError,
138
- embed
139
- });
140
- case "bluesky": return /* @__PURE__ */ jsx(BlueskyEmbed, {
141
- ...shared,
142
- onError,
143
- embed
144
- });
145
- case "soundcloud": return /* @__PURE__ */ jsx(SoundCloudEmbed, {
146
- ...shared,
147
- ...frame,
148
- onError,
149
- embed
150
- });
151
- case "applemusic": return /* @__PURE__ */ jsx(AppleMusicEmbed, {
152
- ...shared,
153
- ...frame,
154
- onError,
155
- embed
156
- });
157
- case "applepodcasts": return /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
158
- ...shared,
159
- ...frame,
160
- onError,
161
- embed
162
- });
163
- case "tumblr": return /* @__PURE__ */ jsx(TumblrEmbed, {
164
- ...shared,
165
- onError,
166
- embed
167
- });
168
- case "kick": return /* @__PURE__ */ jsx(KickEmbed, {
169
- ...shared,
170
- ...frame,
171
- onError,
172
- embed
173
- });
174
- case "giphy": return /* @__PURE__ */ jsx(GiphyEmbed, {
175
- ...shared,
176
- ...frame,
177
- onError,
178
- embed
179
- });
180
- case "tenor": return /* @__PURE__ */ jsx(TenorEmbed, {
181
- ...shared,
182
- ...frame,
183
- onError,
184
- embed
185
- });
186
- case "streamable": return /* @__PURE__ */ jsx(StreamableEmbed, {
187
- ...shared,
188
- ...frame,
189
- onError,
190
- embed
191
- });
192
- case "rumble": return /* @__PURE__ */ jsx(RumbleEmbed, {
193
- ...shared,
194
- ...frame,
195
- onError,
196
- embed
197
- });
198
- case "truthsocial": return /* @__PURE__ */ jsx(TruthSocialEmbed, {
199
- ...shared,
200
- onError,
201
- embed
202
- });
203
- case "imgur": return /* @__PURE__ */ jsx(ImgurEmbed, {
204
- ...shared,
205
- onError,
206
- embed
207
- });
208
- case "strava": return /* @__PURE__ */ jsx(StravaEmbed, {
209
- ...shared,
210
- onError,
211
- embed
212
- });
213
- case "flickr": return /* @__PURE__ */ jsx(FlickrEmbed, {
214
- ...shared,
215
- ...frame,
216
- onError,
217
- embed
218
- });
39
+ return table.renders.get(embed.platform)?.(embed, route) ?? null;
40
+ }
41
+ /**
42
+ * A `<SocialEmbed>` that recognises only the listed platforms, so a bundler leaves the others
43
+ * out. Call it in a client module: `createSocialEmbed([youtube, x, genericIframe])`.
44
+ */
45
+ function createSocialEmbed(list) {
46
+ const table = tableOf(list);
47
+ function SocialEmbed(props) {
48
+ return useSocialEmbed(props, table);
219
49
  }
50
+ return SocialEmbed;
51
+ }
52
+ let every;
53
+ /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
54
+ function SocialEmbed(props) {
55
+ every ??= tableOf(EVERY_PLATFORM);
56
+ return useSocialEmbed(props, every);
220
57
  }
221
- export { SocialEmbed };
58
+ export { SocialEmbed, createSocialEmbed };
@@ -1,4 +1,4 @@
1
- import { FACEBOOK_SDK_VERSION, loadPlatformScript } from "../loader/platform-scripts.js";
1
+ import { FACEBOOK_SDK_VERSION, loadFacebook, loadInstagram, loadPinterest, loadThreads, loadX } from "../loader/platform-scripts.js";
2
2
  // src/core/drivers.ts
3
3
  const globals = () => window;
4
4
  /** Thrown by `render` when another attempt cannot succeed. */
@@ -35,7 +35,7 @@ function hasSizedIframe(container) {
35
35
  return [...container.querySelectorAll("iframe")].some((iframe) => Number.parseFloat(iframe.style.height) > 0);
36
36
  }
37
37
  const xDriver = {
38
- load: () => loadPlatformScript("x"),
38
+ load: () => loadX(),
39
39
  render(container, done) {
40
40
  const twttr = globals().twttr;
41
41
  const onRendered = (event) => {
@@ -61,7 +61,7 @@ function processEmbeds() {
61
61
  process();
62
62
  }
63
63
  const instagramDriver = {
64
- load: () => loadPlatformScript("instagram"),
64
+ load: () => loadInstagram(),
65
65
  render(container, done) {
66
66
  inDocument(container, "Instagram");
67
67
  const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
@@ -71,7 +71,7 @@ const instagramDriver = {
71
71
  }
72
72
  };
73
73
  const threadsDriver = {
74
- load: () => loadPlatformScript("threads"),
74
+ load: () => loadThreads(),
75
75
  render(container, done) {
76
76
  inDocument(container, "Threads");
77
77
  const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
@@ -85,7 +85,7 @@ function facebookDriver(locale) {
85
85
  let driver = facebookDrivers.get(locale);
86
86
  if (!driver) {
87
87
  driver = {
88
- load: () => loadPlatformScript("facebook", { locale }),
88
+ load: () => loadFacebook(locale),
89
89
  render(container, done) {
90
90
  const fb = globals().FB;
91
91
  const parse = fb?.XFBML?.parse;
@@ -111,7 +111,7 @@ function facebookDriver(locale) {
111
111
  return driver;
112
112
  }
113
113
  const pinterestDriver = {
114
- load: () => loadPlatformScript("pinterest"),
114
+ load: () => loadPinterest(),
115
115
  render(container, done) {
116
116
  const build = globals().PinUtils?.build;
117
117
  if (!build) throw new Error("social-embeds: PinUtils.build is missing");
@@ -26,48 +26,4 @@ function frameStyle(plan, layout, reportedHeight) {
26
26
  }
27
27
  };
28
28
  }
29
- /** `src` for a plan with `sizeInSrc`, in a box `width` pixels wide. */
30
- function srcWithSize(plan, width) {
31
- const aspect = aspectOf(plan);
32
- const height = Math.round(width * aspect.height / aspect.width);
33
- const query = plan.src.indexOf("?");
34
- const path = query === -1 ? plan.src : plan.src.slice(0, query);
35
- const rest = query === -1 ? "" : `&${plan.src.slice(query + 1)}`;
36
- return `${path}?width=${String(width)}&height=${String(height)}${rest}`;
37
- }
38
- /**
39
- * Calls `onWidth` with the element's rounded width once it has one, then with each new width
40
- * that has held for WIDTH_SETTLE_MS, so a resize rebuilds the frame once.
41
- */
42
- function watchWidth(element, onWidth) {
43
- let last;
44
- let timer;
45
- const take = (width) => {
46
- const rounded = Math.round(width);
47
- if (rounded <= 0) return;
48
- clearTimeout(timer);
49
- if (rounded === last) return;
50
- if (last === void 0) {
51
- last = rounded;
52
- onWidth(rounded);
53
- return;
54
- }
55
- timer = setTimeout(() => {
56
- last = rounded;
57
- onWidth(rounded);
58
- }, 200);
59
- };
60
- if (typeof ResizeObserver === "undefined") {
61
- take(element.getBoundingClientRect().width);
62
- return () => {};
63
- }
64
- const observer = new ResizeObserver((entries) => {
65
- for (const entry of entries) take(entry.contentRect.width);
66
- });
67
- observer.observe(element);
68
- return () => {
69
- observer.disconnect();
70
- clearTimeout(timer);
71
- };
72
- }
73
- export { frameStyle, srcWithSize, watchWidth };
29
+ export { aspectOf, frameStyle };
@@ -0,0 +1,24 @@
1
+ import "./timing.js";
2
+ // src/core/message-height.ts
3
+ /** `MessageHeight.listen`: the heights the frame itself posts, from the platform's origin only. */
4
+ function listenForHeight(frame, onHeight) {
5
+ const { origin, read } = this;
6
+ const listen = (event) => {
7
+ if (event.origin !== origin) return;
8
+ const element = frame();
9
+ if (!element || event.source !== element.contentWindow) return;
10
+ let value;
11
+ try {
12
+ value = read(event.data);
13
+ } catch {
14
+ return;
15
+ }
16
+ if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
17
+ onHeight(Math.ceil(value));
18
+ };
19
+ window.addEventListener("message", listen);
20
+ return () => {
21
+ window.removeEventListener("message", listen);
22
+ };
23
+ }
24
+ export { listenForHeight };
@@ -1,4 +1,5 @@
1
1
  import { query } from "../params.js";
2
+ import { listenForHeight } from "../message-height.js";
2
3
  // src/core/plans/bluesky.ts
3
4
  /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
4
5
  const BLUESKY_HEIGHT = {
@@ -6,7 +7,8 @@ const BLUESKY_HEIGHT = {
6
7
  read(data) {
7
8
  const height = data?.height;
8
9
  return typeof height === "number" ? height : void 0;
9
- }
10
+ },
11
+ listen: listenForHeight
10
12
  };
11
13
  /**
12
14
  * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
@@ -1,3 +1,4 @@
1
+ import { srcWithSize, watchWidth } from "../size-in-src.js";
1
2
  // src/core/plans/flickr.ts
2
3
  const OPTIONS = [
3
4
  "header",
@@ -15,21 +16,30 @@ function flickrPlan(embed, options) {
15
16
  width,
16
17
  height
17
18
  } : void 0;
19
+ const src = `https://embedr.flickr.com/${album ? "photosets" : "photos"}/${embed.id}${kept.length > 0 ? `?${kept.map((name) => `${name}=true`).join("&")}` : ""}`;
20
+ const ratio = {
21
+ width: 4,
22
+ height: 3
23
+ };
18
24
  return {
19
25
  kind: "iframe",
20
- src: `https://embedr.flickr.com/${album ? "photosets" : "photos"}/${embed.id}${kept.length > 0 ? `?${kept.map((name) => `${name}=true`).join("&")}` : ""}`,
26
+ src,
21
27
  title: album ? "Flickr album" : "Flickr photo",
22
28
  allow: "",
23
29
  scrolling: "no",
24
- ratio: {
25
- width: 4,
26
- height: 3
27
- },
30
+ ratio,
28
31
  ...size ? {
29
32
  size,
30
33
  maxWidth: size.width
31
34
  } : {},
32
- sizeInSrc: true,
35
+ sizeInSrc: {
36
+ watch: watchWidth,
37
+ src: (width) => srcWithSize({
38
+ src,
39
+ ratio,
40
+ size
41
+ }, width)
42
+ },
33
43
  ...embed.fallbackHtml === void 0 ? {} : { fallbackHtml: embed.fallbackHtml.replace(/<img(?=[\s>])/g, `<img style="${IMAGE_STYLE}"`) },
34
44
  fallbackImage: true
35
45
  };
@@ -1,3 +1,4 @@
1
+ import { listenForHeight } from "../message-height.js";
1
2
  // src/core/plans/imgur.ts
2
3
  /** The frame posts one JSON string at `load`, unasked (docs/decisions.md D94). */
3
4
  const IMGUR_HEIGHT = {
@@ -6,7 +7,8 @@ const IMGUR_HEIGHT = {
6
7
  if (typeof data !== "string") return void 0;
7
8
  const message = JSON.parse(data);
8
9
  return message.message === "resize_imgur" && typeof message.height === "number" ? message.height : void 0;
9
- }
10
+ },
11
+ listen: listenForHeight
10
12
  };
11
13
  /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
12
14
  function imgurPlan(embed, options) {
@@ -1,4 +1,5 @@
1
1
  import { query } from "../params.js";
2
+ import { listenForHeight } from "../message-height.js";
2
3
  // src/core/plans/reddit.ts
3
4
  const PARAMS = {
4
5
  theme: "theme",
@@ -18,7 +19,8 @@ const REDDIT_HEIGHT = {
18
19
  if (typeof data !== "string") return void 0;
19
20
  const message = JSON.parse(data);
20
21
  return message.type === "resize.embed" && typeof message.data === "number" ? message.data : void 0;
21
- }
22
+ },
23
+ listen: listenForHeight
22
24
  };
23
25
  /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
24
26
  function redditPlan(embed, options) {
@@ -1,3 +1,4 @@
1
+ import { listenForHeight } from "../message-height.js";
1
2
  // src/core/plans/strava.ts
2
3
  const NS = "social-embeds";
3
4
  /** The frame posts `[ns, 'BROADCAST_IFRAME_HEIGHT', height]` once, unasked (docs/decisions.md D97). */
@@ -7,7 +8,8 @@ const STRAVA_HEIGHT = {
7
8
  if (!Array.isArray(data)) return void 0;
8
9
  const [, type, height] = data;
9
10
  return type === "BROADCAST_IFRAME_HEIGHT" && typeof height === "number" ? height : void 0;
10
- }
11
+ },
12
+ listen: listenForHeight
11
13
  };
12
14
  function styleOf(value) {
13
15
  return value === "minimal" ? "minimal" : "standard";
@@ -1,4 +1,5 @@
1
1
  import { query } from "../params.js";
2
+ import { listenForHeight } from "../message-height.js";
2
3
  // src/core/plans/telegram.ts
3
4
  const PARAMS = [
4
5
  ["comment", "comment"],
@@ -24,7 +25,8 @@ const TELEGRAM_HEIGHT = {
24
25
  if (typeof data !== "string") return void 0;
25
26
  const message = JSON.parse(data);
26
27
  return message.event === "resize" && typeof message.height === "number" ? message.height : void 0;
27
- }
28
+ },
29
+ listen: listenForHeight
28
30
  };
29
31
  /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
30
32
  function telegramPlan(embed, options) {
@@ -1,3 +1,4 @@
1
+ import { listenForHeight } from "../message-height.js";
1
2
  // src/core/plans/truthsocial.ts
2
3
  const VIDEO_EXTRA = 165;
3
4
  function setHeight(data) {
@@ -7,7 +8,8 @@ function setHeight(data) {
7
8
  /** The frame posts `{ type: 'setHeight', id, height }` without being asked (docs/decisions.md D93). */
8
9
  const TRUTH_SOCIAL_HEIGHT = {
9
10
  origin: "https://truthsocial.com",
10
- read: setHeight
11
+ read: setHeight,
12
+ listen: listenForHeight
11
13
  };
12
14
  /** A video post reports its height before the video is sized (docs/decisions.md D100). */
13
15
  const TRUTH_SOCIAL_VIDEO_HEIGHT = {
@@ -15,7 +17,8 @@ const TRUTH_SOCIAL_VIDEO_HEIGHT = {
15
17
  read(data) {
16
18
  const height = setHeight(data);
17
19
  return height === void 0 || height <= 0 ? void 0 : height + VIDEO_EXTRA;
18
- }
20
+ },
21
+ listen: listenForHeight
19
22
  };
20
23
  const CANONICAL = /^https:\/\/truthsocial\.com\/(@[^/]+)\/posts\/\d+$/;
21
24
  /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
@@ -1,3 +1,4 @@
1
+ import { listenForHeight } from "../message-height.js";
1
2
  // src/core/plans/tumblr.ts
2
3
  /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
3
4
  const TUMBLR_HEIGHT = {
@@ -7,7 +8,8 @@ const TUMBLR_HEIGHT = {
7
8
  const message = JSON.parse(data);
8
9
  const [height] = Array.isArray(message.args) ? message.args : [];
9
10
  return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
10
- }
11
+ },
12
+ listen: listenForHeight
11
13
  };
12
14
  /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
13
15
  function tumblrPlan(embed) {
@@ -32,7 +32,10 @@ function twitchPlan(embed, options) {
32
32
  height: 9
33
33
  },
34
34
  size: embed.size,
35
- hostParam: "parent"
35
+ clientSrc: withParent
36
36
  };
37
37
  }
38
- export { twitchPlan };
38
+ function withParent(src) {
39
+ return `${src}${src.includes("?") ? "&" : "?"}parent=${encodeURIComponent(window.location.hostname)}`;
40
+ }
41
+ export { twitchPlan, withParent };
@@ -1,57 +1,35 @@
1
1
  import { needsLookup } from "../parser/lookup.js";
2
2
  import { matchWith } from "../parser/match-url.js";
3
+ import { parseUrl } from "../parser/url.js";
3
4
  import { verifyWith } from "../parser/verify.js";
4
5
  // src/core/resolve.ts
5
- const NAMES = {
6
- x: "X",
7
- instagram: "Instagram",
8
- facebook: "Facebook",
9
- threads: "Threads",
10
- tiktok: "TikTok",
11
- youtube: "YouTube",
12
- telegram: "Telegram",
13
- snapchat: "Snapchat",
14
- linkedin: "LinkedIn",
15
- reddit: "Reddit",
16
- pinterest: "Pinterest",
17
- spotify: "Spotify",
18
- vimeo: "Vimeo",
19
- twitch: "Twitch",
20
- dailymotion: "Dailymotion",
6
+ const LOOKUP_NAMES = {
21
7
  bluesky: "Bluesky",
22
- soundcloud: "SoundCloud",
23
- applemusic: "Apple Music",
24
- applepodcasts: "Apple Podcasts",
25
- tumblr: "Tumblr",
26
- kick: "Kick",
27
- giphy: "Giphy",
28
- truthsocial: "Truth Social",
29
- imgur: "Imgur",
30
- tenor: "Tenor",
31
- streamable: "Streamable",
32
- strava: "Strava",
33
- flickr: "Flickr",
34
8
  rumble: "Rumble"
35
9
  };
36
10
  /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
37
- function lookupMessage(platform) {
38
- return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
11
+ function lookupMessage(name) {
12
+ return `social-embeds: a ${name} URL needs a lookup: use the embed code`;
39
13
  }
40
14
  /** Takes the platform's own parser, so a per-platform component bundles no other (docs/decisions.md D103). */
41
15
  function resolveEmbed(url, given, parser) {
42
- const { platform } = parser;
16
+ const { platform, name } = parser;
43
17
  const embed = given ?? (url === void 0 ? null : matchWith(parser, url));
44
- if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
45
- if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
46
- if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
18
+ if (!embed && url !== void 0 && lookupNeeded(parser, url)) return { error: lookupMessage(name) };
19
+ if (!embed) return { error: `social-embeds: not a ${name} post URL: ${String(url)}` };
20
+ if (embed.platform !== platform) return { error: `social-embeds: expected a ${name} embed, got ${embed.platform}` };
47
21
  const verified = verifyWith(parser, embed);
48
- if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
22
+ if (!verified) return { error: `social-embeds: the ${name} embed's url and id do not match` };
49
23
  return { embed: verified };
50
24
  }
51
25
  /** The message `<SocialEmbed>` reports when its input matches no platform. */
52
26
  function sourceError(source) {
53
27
  if ("html" in source) return "social-embeds: unrecognised embed code";
54
28
  const lookup = needsLookup(source.url);
55
- return lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${source.url}`;
29
+ return lookup ? lookupMessage(LOOKUP_NAMES[lookup] ?? lookup) : `social-embeds: not a supported post URL: ${source.url}`;
56
30
  }
57
- export { NAMES, lookupMessage, resolveEmbed, sourceError };
31
+ function lookupNeeded(parser, url) {
32
+ const parsed = typeof url === "string" ? parseUrl(url) : null;
33
+ return parsed !== null && parser.needsLookup?.(parsed) === true;
34
+ }
35
+ export { lookupMessage, resolveEmbed, sourceError };