social-embeds 0.9.1 → 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 (61) hide show
  1. package/README.md +3 -3
  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 +15 -1
  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/package.json +1 -1
@@ -1,22 +1,11 @@
1
1
  import { rumblePlan } from "../core/plans/rumble.js";
2
2
  import { rumble } from "../parser/platforms/rumble.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/rumble-embed.tsx
8
6
  /** Embed code only: a page URL holds another id than the player (docs/decisions.md D99). */
9
7
  function RumbleEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, rumble);
12
- const plan = embed ? rumblePlan(embed) : void 0;
13
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
- if (plan?.kind !== "iframe") return null;
15
- return /* @__PURE__ */ jsx(IframeEmbed, {
16
- ...frame,
17
- ...planProps(plan),
18
- onError,
19
- maxWidth: maxWidth ?? plan.maxWidth
20
- });
8
+ const [plan, frame] = usePlan(props, rumble, [], rumblePlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { RumbleEmbed };
@@ -7,6 +7,19 @@ import { useEffect, useRef, useState } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  // src/components/script-embed.tsx
9
9
  const LAYER = { width: "100%" };
10
+ /** A platform component's script embed: it sizes itself, so `height` and `maxHeight` are dropped. */
11
+ function scriptOf(plan, props) {
12
+ const { maxWidth, height, maxHeight, ...rest } = props;
13
+ return /* @__PURE__ */ jsx(ScriptEmbed, {
14
+ ...rest,
15
+ maxWidth: maxWidth ?? plan.maxWidth,
16
+ driver: plan.driver,
17
+ markup: plan.markup,
18
+ hasFallback: plan.hasFallback,
19
+ minHeight: plan.minHeight,
20
+ label: plan.label
21
+ }, plan.key);
22
+ }
10
23
  function toError(error) {
11
24
  return error instanceof Error ? error : new Error(String(error));
12
25
  }
@@ -105,4 +118,4 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
105
118
  })
106
119
  });
107
120
  }
108
- export { ScriptEmbed };
121
+ export { ScriptEmbed, scriptOf };
@@ -1,4 +1,4 @@
1
1
  import { EmbedSource, FrameProps } from "./shared.js";
2
2
  export type SnapchatEmbedProps = EmbedSource & FrameProps;
3
3
  /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
4
- export declare function SnapchatEmbed(props: SnapchatEmbedProps): import("react").JSX.Element | null;
4
+ export declare function SnapchatEmbed(props: SnapchatEmbedProps): import("react").ReactNode;
@@ -1,22 +1,11 @@
1
1
  import { snapchatPlan } from "../core/plans/snapchat.js";
2
2
  import { snapchat } from "../parser/platforms/snapchat.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/snapchat-embed.tsx
8
6
  /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
9
7
  function SnapchatEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, snapchat);
12
- const plan = embed ? snapchatPlan(embed) : void 0;
13
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
- if (plan?.kind !== "iframe") return null;
15
- return /* @__PURE__ */ jsx(IframeEmbed, {
16
- ...frame,
17
- ...planProps(plan),
18
- onError,
19
- maxWidth: maxWidth ?? plan.maxWidth
20
- });
8
+ const [plan, frame] = usePlan(props, snapchat, [], snapchatPlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { SnapchatEmbed };
@@ -2,5 +2,5 @@ import { SoundCloudOptions } from "../core/plans/soundcloud.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type SoundCloudEmbedProps = EmbedSource & Omit<FrameProps, keyof SoundCloudOptions> & SoundCloudOptions;
4
4
  /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
5
- export declare function SoundCloudEmbed(props: SoundCloudEmbedProps): import("react").JSX.Element | null;
5
+ export declare function SoundCloudEmbed(props: SoundCloudEmbedProps): import("react").ReactNode;
6
6
  export type { SoundCloudOptions };
@@ -1,33 +1,22 @@
1
1
  import { soundcloud } from "../parser/platforms/soundcloud.js";
2
2
  import { soundcloudPlan } from "../core/plans/soundcloud.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/soundcloud-embed.tsx
6
+ const SOUNDCLOUD_OPTIONS = [
7
+ "visual",
8
+ "color",
9
+ "autoPlay",
10
+ "hideRelated",
11
+ "showComments",
12
+ "showUser",
13
+ "showReposts",
14
+ "showTeaser",
15
+ "showArtwork"
16
+ ];
8
17
  /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
9
18
  function SoundCloudEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, soundcloud);
12
- const plan = embed ? soundcloudPlan(embed, {
13
- visual,
14
- color,
15
- autoPlay,
16
- hideRelated,
17
- showComments,
18
- showUser,
19
- showReposts,
20
- showTeaser,
21
- showArtwork
22
- }) : void 0;
23
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
24
- if (plan?.kind !== "iframe") return null;
25
- return /* @__PURE__ */ jsx(IframeEmbed, {
26
- ...frame,
27
- ...planProps(plan),
28
- onError,
29
- maxWidth: maxWidth ?? plan.maxWidth,
30
- height: height ?? plan.height
31
- });
19
+ const [plan, frame] = usePlan(props, soundcloud, SOUNDCLOUD_OPTIONS, soundcloudPlan);
20
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
32
21
  }
33
22
  export { SoundCloudEmbed };
@@ -5,5 +5,5 @@ export type SpotifyEmbedProps = EmbedSource & Omit<FrameProps, keyof SpotifyOpti
5
5
  * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
6
6
  * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
7
7
  */
8
- export declare function SpotifyEmbed(props: SpotifyEmbedProps): import("react").JSX.Element | null;
8
+ export declare function SpotifyEmbed(props: SpotifyEmbedProps): import("react").ReactNode;
9
9
  export type { SpotifyOptions };
@@ -1,25 +1,15 @@
1
1
  import { spotifyPlan } from "../core/plans/spotify.js";
2
2
  import { spotify } from "../parser/platforms/spotify.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/spotify-embed.tsx
6
+ const SPOTIFY_OPTIONS = ["theme"];
8
7
  /**
9
8
  * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
10
9
  * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
11
10
  */
12
11
  function SpotifyEmbed(props) {
13
- const { url, embed: given, onError, height, theme, ...frame } = props;
14
- const { embed, error } = resolveEmbed(url, given, spotify);
15
- const plan = embed ? spotifyPlan(embed, { theme }) : void 0;
16
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
17
- if (plan?.kind !== "iframe") return null;
18
- return /* @__PURE__ */ jsx(IframeEmbed, {
19
- ...frame,
20
- ...planProps(plan),
21
- onError,
22
- height: height ?? plan.height
23
- });
12
+ const [plan, frame] = usePlan(props, spotify, SPOTIFY_OPTIONS, spotifyPlan);
13
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
24
14
  }
25
15
  export { SpotifyEmbed };
@@ -2,5 +2,5 @@ import { StravaOptions } from "../core/plans/strava.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type StravaEmbedProps = EmbedSource & Omit<SharedProps, keyof StravaOptions> & StravaOptions;
4
4
  /** At most 554px wide by default, as `embed.js` makes the frame; a full-width route has no maximum (docs/decisions.md D97). */
5
- export declare function StravaEmbed(props: StravaEmbedProps): import("react").JSX.Element | null;
5
+ export declare function StravaEmbed(props: StravaEmbedProps): import("react").ReactNode;
6
6
  export type { StravaOptions };
@@ -1,26 +1,16 @@
1
1
  import { stravaPlan } from "../core/plans/strava.js";
2
2
  import { strava } from "../parser/platforms/strava.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/strava-embed.tsx
6
+ const STRAVA_OPTIONS = [
7
+ "embedStyle",
8
+ "fullWidth",
9
+ "mapHash"
10
+ ];
8
11
  /** At most 554px wide by default, as `embed.js` makes the frame; a full-width route has no maximum (docs/decisions.md D97). */
9
12
  function StravaEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, embedStyle, fullWidth, mapHash, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, strava);
12
- const plan = embed ? stravaPlan(embed, {
13
- embedStyle,
14
- fullWidth,
15
- mapHash
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
- ...shared,
21
- ...planProps(plan),
22
- onError,
23
- maxWidth: maxWidth ?? plan.maxWidth
24
- });
13
+ const [plan, frame] = usePlan(props, strava, STRAVA_OPTIONS, stravaPlan);
14
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
25
15
  }
26
16
  export { StravaEmbed };
@@ -2,5 +2,5 @@ import { StreamableOptions } from "../core/plans/streamable.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type StreamableEmbedProps = EmbedSource & Omit<FrameProps, keyof StreamableOptions> & StreamableOptions;
4
4
  /** The embed code's aspect ratio, else 16:9. */
5
- export declare function StreamableEmbed(props: StreamableEmbedProps): import("react").JSX.Element | null;
5
+ export declare function StreamableEmbed(props: StreamableEmbedProps): import("react").ReactNode;
6
6
  export type { StreamableOptions };
@@ -1,28 +1,18 @@
1
1
  import { streamable } from "../parser/platforms/streamable.js";
2
2
  import { streamablePlan } from "../core/plans/streamable.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/streamable-embed.tsx
6
+ const STREAMABLE_OPTIONS = [
7
+ "autoplay",
8
+ "hd",
9
+ "loop",
10
+ "muted",
11
+ "nocontrols"
12
+ ];
8
13
  /** The embed code's aspect ratio, else 16:9. */
9
14
  function StreamableEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, autoplay, hd, loop, muted, nocontrols, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, streamable);
12
- const plan = embed ? streamablePlan(embed, {
13
- autoplay,
14
- hd,
15
- loop,
16
- muted,
17
- nocontrols
18
- }) : void 0;
19
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
20
- if (plan?.kind !== "iframe") return null;
21
- return /* @__PURE__ */ jsx(IframeEmbed, {
22
- ...frame,
23
- ...planProps(plan),
24
- onError,
25
- maxWidth: maxWidth ?? plan.maxWidth
26
- });
15
+ const [plan, frame] = usePlan(props, streamable, STREAMABLE_OPTIONS, streamablePlan);
16
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
27
17
  }
28
18
  export { StreamableEmbed };
@@ -2,5 +2,5 @@ import { TelegramOptions } from "../core/plans/telegram.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type TelegramEmbedProps = EmbedSource & Omit<SharedProps, keyof TelegramOptions> & TelegramOptions;
4
4
  /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
5
- export declare function TelegramEmbed(props: TelegramEmbedProps): import("react").JSX.Element | null;
5
+ export declare function TelegramEmbed(props: TelegramEmbedProps): import("react").ReactNode;
6
6
  export type { TelegramOptions };
@@ -1,27 +1,17 @@
1
1
  import { telegramPlan } from "../core/plans/telegram.js";
2
2
  import { telegram } from "../parser/platforms/telegram.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/telegram-embed.tsx
6
+ const TELEGRAM_OPTIONS = [
7
+ "userpic",
8
+ "color",
9
+ "dark",
10
+ "darkColor"
11
+ ];
8
12
  /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
9
13
  function TelegramEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, userpic, color, dark, darkColor, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, telegram);
12
- const plan = embed ? telegramPlan(embed, {
13
- userpic,
14
- color,
15
- dark,
16
- darkColor
17
- }) : void 0;
18
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
19
- if (plan?.kind !== "iframe") return null;
20
- return /* @__PURE__ */ jsx(IframeEmbed, {
21
- ...shared,
22
- ...planProps(plan),
23
- onError,
24
- maxWidth: maxWidth ?? plan.maxWidth
25
- });
14
+ const [plan, frame] = usePlan(props, telegram, TELEGRAM_OPTIONS, telegramPlan);
15
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
26
16
  }
27
17
  export { TelegramEmbed };
@@ -1,4 +1,4 @@
1
1
  import { EmbedSource, FrameProps } from "./shared.js";
2
2
  export type TenorEmbedProps = EmbedSource & FrameProps;
3
3
  /** The embed code's aspect ratio; a URL carries no size and renders at 1.33:1 (docs/decisions.md D95). */
4
- export declare function TenorEmbed(props: TenorEmbedProps): import("react").JSX.Element | null;
4
+ export declare function TenorEmbed(props: TenorEmbedProps): import("react").ReactNode;
@@ -1,22 +1,11 @@
1
1
  import { tenorPlan } from "../core/plans/tenor.js";
2
2
  import { tenor } from "../parser/platforms/tenor.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/tenor-embed.tsx
8
6
  /** The embed code's aspect ratio; a URL carries no size and renders at 1.33:1 (docs/decisions.md D95). */
9
7
  function TenorEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, tenor);
12
- const plan = embed ? tenorPlan(embed) : void 0;
13
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
- if (plan?.kind !== "iframe") return null;
15
- return /* @__PURE__ */ jsx(IframeEmbed, {
16
- ...frame,
17
- ...planProps(plan),
18
- onError,
19
- maxWidth: maxWidth ?? plan.maxWidth
20
- });
8
+ const [plan, frame] = usePlan(props, tenor, [], tenorPlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { TenorEmbed };
@@ -1,5 +1,5 @@
1
1
  import { ThreadsOptions } from "../core/plans/threads.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type ThreadsEmbedProps = EmbedSource & Omit<SharedProps, keyof ThreadsOptions> & ThreadsOptions;
4
- export declare function ThreadsEmbed(props: ThreadsEmbedProps): import("react").JSX.Element | null;
4
+ export declare function ThreadsEmbed(props: ThreadsEmbedProps): import("react").ReactNode;
5
5
  export type { ThreadsOptions };
@@ -1,25 +1,11 @@
1
1
  import { threadsPlan } from "../core/plans/threads.js";
2
2
  import { threads } from "../parser/platforms/threads.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/threads-embed.tsx
6
+ const THREADS_OPTIONS = ["theme"];
8
7
  function ThreadsEmbed(props) {
9
- const { url, embed: given, onError, maxWidth, theme, ...shared } = props;
10
- const { embed, error } = resolveEmbed(url, given, threads);
11
- const plan = embed ? threadsPlan(embed, { theme }) : void 0;
12
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
13
- if (plan?.kind !== "script") return null;
14
- return /* @__PURE__ */ jsx(ScriptEmbed, {
15
- ...shared,
16
- onError,
17
- maxWidth: maxWidth ?? plan.maxWidth,
18
- driver: plan.driver,
19
- markup: plan.markup,
20
- hasFallback: plan.hasFallback,
21
- minHeight: plan.minHeight,
22
- label: plan.label
23
- }, plan.key);
8
+ const [plan, frame] = usePlan(props, threads, THREADS_OPTIONS, threadsPlan);
9
+ return plan?.kind === "script" ? scriptOf(plan, frame) : null;
24
10
  }
25
11
  export { ThreadsEmbed };
@@ -2,5 +2,5 @@ import { TikTokOptions } from "../core/plans/tiktok.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type TikTokEmbedProps = EmbedSource & Omit<FrameProps, keyof TikTokOptions> & TikTokOptions;
4
4
  /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
5
- export declare function TikTokEmbed(props: TikTokEmbedProps): import("react").JSX.Element | null;
5
+ export declare function TikTokEmbed(props: TikTokEmbedProps): import("react").ReactNode;
6
6
  export type { TikTokOptions };
@@ -1,37 +1,27 @@
1
1
  import { tiktokPlan } from "../core/plans/tiktok.js";
2
2
  import { tiktok } from "../parser/platforms/tiktok.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/tiktok-embed.tsx
6
+ const TIKTOK_OPTIONS = [
7
+ "controls",
8
+ "progressBar",
9
+ "playButton",
10
+ "volumeControl",
11
+ "fullscreenButton",
12
+ "timestamp",
13
+ "loop",
14
+ "autoplay",
15
+ "musicInfo",
16
+ "description",
17
+ "rel",
18
+ "nativeContextMenu",
19
+ "closedCaption",
20
+ "forceMuted"
21
+ ];
8
22
  /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
9
23
  function TikTokEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, tiktok);
12
- const plan = embed ? tiktokPlan(embed, {
13
- controls,
14
- progressBar,
15
- playButton,
16
- volumeControl,
17
- fullscreenButton,
18
- timestamp,
19
- loop,
20
- autoplay,
21
- musicInfo,
22
- description,
23
- rel,
24
- nativeContextMenu,
25
- closedCaption,
26
- forceMuted
27
- }) : void 0;
28
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
29
- if (plan?.kind !== "iframe") return null;
30
- return /* @__PURE__ */ jsx(IframeEmbed, {
31
- ...frame,
32
- ...planProps(plan),
33
- onError,
34
- maxWidth: maxWidth ?? plan.maxWidth
35
- });
24
+ const [plan, frame] = usePlan(props, tiktok, TIKTOK_OPTIONS, tiktokPlan);
25
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
36
26
  }
37
27
  export { TikTokEmbed };
@@ -1,4 +1,4 @@
1
1
  import { EmbedSource, SharedProps } from "./shared.js";
2
2
  export type TruthSocialEmbedProps = EmbedSource & SharedProps;
3
3
  /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
4
- export declare function TruthSocialEmbed(props: TruthSocialEmbedProps): import("react").JSX.Element | null;
4
+ export declare function TruthSocialEmbed(props: TruthSocialEmbedProps): import("react").ReactNode;
@@ -1,22 +1,11 @@
1
1
  import { truthSocialPlan } from "../core/plans/truthsocial.js";
2
2
  import { truthsocial } from "../parser/platforms/truthsocial.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/truthsocial-embed.tsx
8
6
  /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
9
7
  function TruthSocialEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, truthsocial);
12
- const plan = embed ? truthSocialPlan(embed) : void 0;
13
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
- if (plan?.kind !== "iframe") return null;
15
- return /* @__PURE__ */ jsx(IframeEmbed, {
16
- ...shared,
17
- ...planProps(plan),
18
- onError,
19
- maxWidth: maxWidth ?? plan.maxWidth
20
- });
8
+ const [plan, frame] = usePlan(props, truthsocial, [], truthSocialPlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { TruthSocialEmbed };
@@ -1,4 +1,4 @@
1
1
  import { EmbedSource, SharedProps } from "./shared.js";
2
2
  export type TumblrEmbedProps = EmbedSource & SharedProps;
3
3
  /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
4
- export declare function TumblrEmbed(props: TumblrEmbedProps): import("react").JSX.Element | null;
4
+ export declare function TumblrEmbed(props: TumblrEmbedProps): import("react").ReactNode;
@@ -1,22 +1,11 @@
1
1
  import { tumblrPlan } from "../core/plans/tumblr.js";
2
2
  import { tumblr } from "../parser/platforms/tumblr.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/tumblr-embed.tsx
8
6
  /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
9
7
  function TumblrEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, tumblr);
12
- const plan = embed ? tumblrPlan(embed) : void 0;
13
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
- if (plan?.kind !== "iframe") return null;
15
- return /* @__PURE__ */ jsx(IframeEmbed, {
16
- ...shared,
17
- ...planProps(plan),
18
- onError,
19
- maxWidth: maxWidth ?? plan.maxWidth
20
- });
8
+ const [plan, frame] = usePlan(props, tumblr, [], tumblrPlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { TumblrEmbed };
@@ -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 };