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
@@ -2,5 +2,5 @@ import { TwitchOptions } from "../core/plans/twitch.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type TwitchEmbedProps = EmbedSource & Omit<FrameProps, keyof TwitchOptions> & TwitchOptions;
4
4
  /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
5
- export declare function TwitchEmbed(props: TwitchEmbedProps): import("react").JSX.Element | null;
5
+ export declare function TwitchEmbed(props: TwitchEmbedProps): import("react").ReactNode;
6
6
  export type { TwitchOptions };
@@ -1,26 +1,16 @@
1
1
  import { twitchPlan } from "../core/plans/twitch.js";
2
2
  import { twitch } from "../parser/platforms/twitch.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, planProps } from "./iframe-embed.js";
5
- import { resolveEmbed } from "../core/resolve.js";
6
- import { jsx } from "react/jsx-runtime";
3
+ import { usePlan } from "./use-plan.js";
4
+ import { frameOf } from "./iframe-embed.js";
7
5
  // src/components/twitch-embed.tsx
6
+ const TWITCH_OPTIONS = [
7
+ "autoplay",
8
+ "muted",
9
+ "time"
10
+ ];
8
11
  /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
9
12
  function TwitchEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, autoplay, muted, time, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, twitch);
12
- const plan = embed ? twitchPlan(embed, {
13
- autoplay,
14
- muted,
15
- time
16
- }) : void 0;
17
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
18
- if (plan?.kind !== "iframe") return null;
19
- return /* @__PURE__ */ jsx(IframeEmbed, {
20
- ...frame,
21
- ...planProps(plan),
22
- onError,
23
- maxWidth: maxWidth ?? plan.maxWidth
24
- });
13
+ const [plan, frame] = usePlan(props, twitch, TWITCH_OPTIONS, twitchPlan);
14
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
25
15
  }
26
16
  export { TwitchEmbed };
@@ -0,0 +1,20 @@
1
+ import { resolveEmbed } from "../core/resolve.js";
2
+ import { useReportError } from "./hooks.js";
3
+ // src/components/use-plan.ts
4
+ /**
5
+ * One body for every platform component: resolves the input, plans it with the option props
6
+ * named in `names`, reports invalid input, and returns the plan with the remaining props.
7
+ */
8
+ function usePlan(props, parser, names, plan) {
9
+ const { url, embed: given, ...others } = props;
10
+ const options = {};
11
+ for (const name of names) if (name in others) {
12
+ options[name] = others[name];
13
+ delete others[name];
14
+ }
15
+ const { embed, error } = resolveEmbed(url, given, parser);
16
+ const planned = embed ? plan(embed, options) : void 0;
17
+ useReportError(error ?? (planned?.kind === "error" ? planned.message : void 0), props.onError);
18
+ return [planned?.kind === "error" ? void 0 : planned, others];
19
+ }
20
+ export { usePlan };
@@ -1,5 +1,5 @@
1
1
  import { VimeoOptions } from "../core/plans/vimeo.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type VimeoEmbedProps = EmbedSource & Omit<FrameProps, keyof VimeoOptions> & VimeoOptions;
4
- export declare function VimeoEmbed(props: VimeoEmbedProps): import("react").JSX.Element | null;
4
+ export declare function VimeoEmbed(props: VimeoEmbedProps): import("react").ReactNode;
5
5
  export type { VimeoOptions };
@@ -1,40 +1,30 @@
1
1
  import { vimeoPlan } from "../core/plans/vimeo.js";
2
2
  import { vimeo } from "../parser/platforms/vimeo.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, planProps } from "./iframe-embed.js";
5
- import { resolveEmbed } from "../core/resolve.js";
6
- import { jsx } from "react/jsx-runtime";
3
+ import { usePlan } from "./use-plan.js";
4
+ import { frameOf } from "./iframe-embed.js";
7
5
  // src/components/vimeo-embed.tsx
6
+ const VIMEO_OPTIONS = [
7
+ "autopause",
8
+ "autoplay",
9
+ "background",
10
+ "byline",
11
+ "color",
12
+ "controls",
13
+ "dnt",
14
+ "keyboard",
15
+ "loop",
16
+ "muted",
17
+ "pip",
18
+ "playsinline",
19
+ "portrait",
20
+ "quality",
21
+ "speed",
22
+ "title",
23
+ "transparent",
24
+ "t"
25
+ ];
8
26
  function VimeoEmbed(props) {
9
- const { url, embed: given, onError, maxWidth, autopause, autoplay, background, byline, color, controls, dnt, keyboard, loop, muted, pip, playsinline, portrait, quality, speed, title, transparent, t, ...frame } = props;
10
- const { embed, error } = resolveEmbed(url, given, vimeo);
11
- const plan = embed ? vimeoPlan(embed, {
12
- autopause,
13
- autoplay,
14
- background,
15
- byline,
16
- color,
17
- controls,
18
- dnt,
19
- keyboard,
20
- loop,
21
- muted,
22
- pip,
23
- playsinline,
24
- portrait,
25
- quality,
26
- speed,
27
- title,
28
- transparent,
29
- t
30
- }) : void 0;
31
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
32
- if (plan?.kind !== "iframe") return null;
33
- return /* @__PURE__ */ jsx(IframeEmbed, {
34
- ...frame,
35
- ...planProps(plan),
36
- onError,
37
- maxWidth: maxWidth ?? plan.maxWidth
38
- });
27
+ const [plan, frame] = usePlan(props, vimeo, VIMEO_OPTIONS, vimeoPlan);
28
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
39
29
  }
40
30
  export { VimeoEmbed };
@@ -1,5 +1,5 @@
1
1
  import { XOptions } from "../core/plans/x.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type XEmbedProps = EmbedSource & Omit<SharedProps, keyof XOptions> & XOptions;
4
- export declare function XEmbed(props: XEmbedProps): import("react").JSX.Element | null;
4
+ export declare function XEmbed(props: XEmbedProps): import("react").ReactNode;
5
5
  export type { XOptions };
@@ -1,32 +1,18 @@
1
1
  import { xPlan } from "../core/plans/x.js";
2
2
  import { x } from "../parser/platforms/x.js";
3
- import { useReportError } from "./hooks.js";
4
- import { ScriptEmbed } from "./script-embed.js";
5
- import { resolveEmbed } from "../core/resolve.js";
6
- import { jsx } from "react/jsx-runtime";
3
+ import { usePlan } from "./use-plan.js";
4
+ import { scriptOf } from "./script-embed.js";
7
5
  // src/components/x-embed.tsx
6
+ const X_OPTIONS = [
7
+ "theme",
8
+ "conversation",
9
+ "cards",
10
+ "align",
11
+ "lang",
12
+ "dnt"
13
+ ];
8
14
  function XEmbed(props) {
9
- const { url, embed: given, onError, maxWidth, theme, conversation, cards, align, lang, dnt, ...shared } = props;
10
- const { embed, error } = resolveEmbed(url, given, x);
11
- const plan = embed ? xPlan(embed, {
12
- theme,
13
- conversation,
14
- cards,
15
- align,
16
- lang,
17
- dnt
18
- }) : void 0;
19
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
20
- if (plan?.kind !== "script") return null;
21
- return /* @__PURE__ */ jsx(ScriptEmbed, {
22
- ...shared,
23
- onError,
24
- maxWidth: maxWidth ?? plan.maxWidth,
25
- driver: plan.driver,
26
- markup: plan.markup,
27
- hasFallback: plan.hasFallback,
28
- minHeight: plan.minHeight,
29
- label: plan.label
30
- }, plan.key);
15
+ const [plan, frame] = usePlan(props, x, X_OPTIONS, xPlan);
16
+ return plan?.kind === "script" ? scriptOf(plan, frame) : null;
31
17
  }
32
18
  export { XEmbed };
@@ -1,5 +1,5 @@
1
1
  import { YouTubeOptions } from "../core/plans/youtube.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type YouTubeEmbedProps = EmbedSource & Omit<FrameProps, keyof YouTubeOptions> & YouTubeOptions;
4
- export declare function YouTubeEmbed(props: YouTubeEmbedProps): import("react").JSX.Element | null;
4
+ export declare function YouTubeEmbed(props: YouTubeEmbedProps): import("react").ReactNode;
5
5
  export type { YouTubeOptions };
@@ -1,43 +1,33 @@
1
1
  import { youtubePlan } from "../core/plans/youtube.js";
2
2
  import { youtube } from "../parser/platforms/youtube.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, planProps } from "./iframe-embed.js";
5
- import { resolveEmbed } from "../core/resolve.js";
6
- import { jsx } from "react/jsx-runtime";
3
+ import { usePlan } from "./use-plan.js";
4
+ import { frameOf } from "./iframe-embed.js";
7
5
  // src/components/youtube-embed.tsx
6
+ const YOUTUBE_OPTIONS = [
7
+ "autoplay",
8
+ "ccLangPref",
9
+ "ccLoadPolicy",
10
+ "color",
11
+ "controls",
12
+ "disablekb",
13
+ "enablejsapi",
14
+ "end",
15
+ "fs",
16
+ "hl",
17
+ "ivLoadPolicy",
18
+ "list",
19
+ "listType",
20
+ "loop",
21
+ "origin",
22
+ "playlist",
23
+ "playsinline",
24
+ "rel",
25
+ "start",
26
+ "widgetReferrer",
27
+ "nocookie"
28
+ ];
8
29
  function YouTubeEmbed(props) {
9
- const { url, embed: given, onError, maxWidth, autoplay, ccLangPref, ccLoadPolicy, color, controls, disablekb, enablejsapi, end, fs, hl, ivLoadPolicy, list, listType, loop, origin, playlist, playsinline, rel, start, widgetReferrer, nocookie, ...frame } = props;
10
- const { embed, error } = resolveEmbed(url, given, youtube);
11
- const plan = embed ? youtubePlan(embed, {
12
- autoplay,
13
- ccLangPref,
14
- ccLoadPolicy,
15
- color,
16
- controls,
17
- disablekb,
18
- enablejsapi,
19
- end,
20
- fs,
21
- hl,
22
- ivLoadPolicy,
23
- list,
24
- listType,
25
- loop,
26
- origin,
27
- playlist,
28
- playsinline,
29
- rel,
30
- start,
31
- widgetReferrer,
32
- nocookie
33
- }) : void 0;
34
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
35
- if (plan?.kind !== "iframe") return null;
36
- return /* @__PURE__ */ jsx(IframeEmbed, {
37
- ...frame,
38
- ...planProps(plan),
39
- onError,
40
- maxWidth: maxWidth ?? plan.maxWidth
41
- });
30
+ const [plan, frame] = usePlan(props, youtube, YOUTUBE_OPTIONS, youtubePlan);
31
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
42
32
  }
43
33
  export { YouTubeEmbed };
@@ -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 };