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
package/README.md CHANGED
@@ -83,7 +83,7 @@ Before 0.7.0, iframe code that no platform claimed reached `fallback`. It now re
83
83
 
84
84
  #### Only the platforms you use
85
85
 
86
- `<SocialEmbed>` recognises every platform, so it adds about 28 KB gzipped to an app. `createSocialEmbed` makes one that recognises only the platforms you list, and a bundler leaves the others out:
86
+ `<SocialEmbed>` recognises every platform, so it adds about 27 KB gzipped to an app. `createSocialEmbed` makes one that recognises only the platforms you list, and a bundler leaves the others out:
87
87
 
88
88
  ```tsx
89
89
  // app/social-embed.tsx
@@ -107,11 +107,11 @@ export const SocialEmbed = createSocialEmbed([
107
107
 
108
108
  | Platforms | Gzipped |
109
109
  | ------------------------------------------------- | ------- |
110
- | `youtube` | 7 KB |
111
- | `youtube`, `x` | 10 KB |
112
- | `youtube`, `x`, `instagram`, `facebook`, `tiktok` | 13 KB |
113
- | the same five and `genericIframe` | 15 KB |
114
- | every platform (`<SocialEmbed>`) | 28 KB |
110
+ | `youtube` | 6 KB |
111
+ | `youtube`, `x` | 9 KB |
112
+ | `youtube`, `x`, `instagram`, `facebook`, `tiktok` | 12 KB |
113
+ | the same five and `genericIframe` | 14 KB |
114
+ | every platform (`<SocialEmbed>`) | 27 KB |
115
115
 
116
116
  - **Names:** each platform is exported under its id, as in `embed.platform`: `x`, `instagram`, `threads`, `facebook`, `tiktok`, `youtube`, `telegram`, `snapchat`, `linkedin`, `reddit`, `pinterest`, `spotify`, `vimeo`, `twitch`, `dailymotion`, `bluesky`, `soundcloud`, `applemusic`, `applepodcasts`, `tumblr`, `kick`, `giphy`, `truthsocial`, `imgur`, `tenor`, `streamable`, `strava`, `flickr` and `rumble`. `genericIframe` adds [generic iframe embeds](#generic-iframe-embeds). The order of the list does not matter.
117
117
  - **The same component:** it takes the same props and renders exactly what `<SocialEmbed>` renders for the platforms it knows. Embed code of another platform goes to `fallback`, or to `onError` as `social-embeds: unrecognised embed code`; a URL of another platform is reported as `social-embeds: not a supported post URL: …`. A frame that a named platform serves never renders as a generic iframe, even when that platform is not in the list.
@@ -121,7 +121,7 @@ export const SocialEmbed = createSocialEmbed([
121
121
 
122
122
  Each platform component takes a `url`, or an `embed` already parsed by [`social-embeds/parser`](#parser), plus the shared props and its own option props. Option props override options from the embed code.
123
123
 
124
- A platform component bundles only its own platform's parser: one component adds about 5 to 6 KB gzipped to an app (`FacebookEmbed` about 9 KB, `GenericIframeEmbed` about 5 KB), against about 28 KB for `<SocialEmbed>`, which recognises every platform. A URL of another platform is reported as `social-embeds: not a {Platform} post URL: …`.
124
+ A platform component bundles only its own platform's parser: one component adds about 3.5 to 5.5 KB gzipped to an app (`FacebookEmbed` about 7.4 KB), against about 27 KB for `<SocialEmbed>`, which recognises every platform. A URL of another platform is reported as `social-embeds: not a {Platform} post URL: …`, and an `embed` of another platform as `social-embeds: expected a {Platform} embed, got {id}`.
125
125
 
126
126
  ```tsx
127
127
  import {
@@ -2,6 +2,6 @@ import { EmbedSource, FrameProps } from "./shared.js";
2
2
  export type AppleMusicEmbedProps = EmbedSource & FrameProps;
3
3
  export type ApplePodcastsEmbedProps = EmbedSource & FrameProps;
4
4
  /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
5
- export declare function AppleMusicEmbed(props: AppleMusicEmbedProps): import("react").JSX.Element | null;
5
+ export declare function AppleMusicEmbed(props: AppleMusicEmbedProps): import("react").ReactNode;
6
6
  /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
7
- export declare function ApplePodcastsEmbed(props: ApplePodcastsEmbedProps): import("react").JSX.Element | null;
7
+ export declare function ApplePodcastsEmbed(props: ApplePodcastsEmbedProps): import("react").ReactNode;
@@ -1,39 +1,17 @@
1
1
  import { appleMusicPlan, applePodcastsPlan } from "../core/plans/apple.js";
2
2
  import { applemusic } from "../parser/platforms/applemusic.js";
3
3
  import { applepodcasts } from "../parser/platforms/applepodcasts.js";
4
- import { useReportError } from "./hooks.js";
5
- import { IframeEmbed, planProps } from "./iframe-embed.js";
6
- import { resolveEmbed } from "../core/resolve.js";
7
- import { jsx } from "react/jsx-runtime";
4
+ import { usePlan } from "./use-plan.js";
5
+ import { frameOf } from "./iframe-embed.js";
8
6
  // src/components/apple-embed.tsx
9
7
  /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
10
8
  function AppleMusicEmbed(props) {
11
- const { url, embed: given, onError, height, maxWidth, ...frame } = props;
12
- const { embed, error } = resolveEmbed(url, given, applemusic);
13
- const plan = embed ? appleMusicPlan(embed) : void 0;
14
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
15
- if (plan?.kind !== "iframe") return null;
16
- return /* @__PURE__ */ jsx(IframeEmbed, {
17
- ...frame,
18
- ...planProps(plan),
19
- onError,
20
- maxWidth: maxWidth ?? plan.maxWidth,
21
- height: height ?? plan.height
22
- });
9
+ const [plan, frame] = usePlan(props, applemusic, [], appleMusicPlan);
10
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
23
11
  }
24
12
  /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
25
13
  function ApplePodcastsEmbed(props) {
26
- const { url, embed: given, onError, height, maxWidth, ...frame } = props;
27
- const { embed, error } = resolveEmbed(url, given, applepodcasts);
28
- const plan = embed ? applePodcastsPlan(embed) : void 0;
29
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
30
- if (plan?.kind !== "iframe") return null;
31
- return /* @__PURE__ */ jsx(IframeEmbed, {
32
- ...frame,
33
- ...planProps(plan),
34
- onError,
35
- maxWidth: maxWidth ?? plan.maxWidth,
36
- height: height ?? plan.height
37
- });
14
+ const [plan, frame] = usePlan(props, applepodcasts, [], applePodcastsPlan);
15
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
38
16
  }
39
17
  export { AppleMusicEmbed, ApplePodcastsEmbed };
@@ -6,5 +6,5 @@ export type BlueskyEmbedProps = EmbedSource & Omit<SharedProps, keyof BlueskyOpt
6
6
  * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
7
7
  * render: a handle URL needs a lookup, and `onError` says so.
8
8
  */
9
- export declare function BlueskyEmbed(props: BlueskyEmbedProps): import("react").JSX.Element | null;
9
+ export declare function BlueskyEmbed(props: BlueskyEmbedProps): import("react").ReactNode;
10
10
  export type { BlueskyOptions };
@@ -1,27 +1,16 @@
1
1
  import { blueskyPlan } from "../core/plans/bluesky.js";
2
2
  import { bluesky } from "../parser/platforms/bluesky.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, fallbackPlaceholder, 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 { fallbackPlaceholder, frameOf } from "./iframe-embed.js";
7
5
  // src/components/bluesky-embed.tsx
6
+ const BLUESKY_OPTIONS = ["colorMode"];
8
7
  /**
9
8
  * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
10
9
  * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
11
10
  * render: a handle URL needs a lookup, and `onError` says so.
12
11
  */
13
12
  function BlueskyEmbed(props) {
14
- const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
15
- const { embed, error } = resolveEmbed(url, given, bluesky);
16
- const plan = embed ? blueskyPlan(embed, { colorMode }) : 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
- placeholder: placeholder ?? fallbackPlaceholder(plan)
25
- });
13
+ const [plan, frame] = usePlan(props, bluesky, BLUESKY_OPTIONS, blueskyPlan);
14
+ return plan?.kind === "iframe" ? frameOf(plan, frame, fallbackPlaceholder) : null;
26
15
  }
27
16
  export { BlueskyEmbed };
@@ -5,5 +5,5 @@ export type DailymotionEmbedProps = EmbedSource & Omit<FrameProps, keyof Dailymo
5
5
  * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
6
6
  * prop, never another account's (docs/decisions.md D63).
7
7
  */
8
- export declare function DailymotionEmbed(props: DailymotionEmbedProps): import("react").JSX.Element | null;
8
+ export declare function DailymotionEmbed(props: DailymotionEmbedProps): import("react").ReactNode;
9
9
  export type { DailymotionOptions };
@@ -1,30 +1,20 @@
1
1
  import { dailymotion } from "../parser/platforms/dailymotion.js";
2
2
  import { dailymotionPlan } from "../core/plans/dailymotion.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/dailymotion-embed.tsx
6
+ const DAILYMOTION_OPTIONS = [
7
+ "playerId",
8
+ "mute",
9
+ "startTime",
10
+ "loop"
11
+ ];
8
12
  /**
9
13
  * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
10
14
  * prop, never another account's (docs/decisions.md D63).
11
15
  */
12
16
  function DailymotionEmbed(props) {
13
- const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
14
- const { embed, error } = resolveEmbed(url, given, dailymotion);
15
- const plan = embed ? dailymotionPlan(embed, {
16
- playerId,
17
- mute,
18
- startTime,
19
- loop
20
- }) : void 0;
21
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
22
- if (plan?.kind !== "iframe") return null;
23
- return /* @__PURE__ */ jsx(IframeEmbed, {
24
- ...frame,
25
- ...planProps(plan),
26
- onError,
27
- maxWidth: maxWidth ?? plan.maxWidth
28
- });
17
+ const [plan, frame] = usePlan(props, dailymotion, DAILYMOTION_OPTIONS, dailymotionPlan);
18
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
29
19
  }
30
20
  export { DailymotionEmbed };
@@ -2,5 +2,5 @@ import { FacebookOptions } from "../core/plans/facebook.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  /** `height` and `maxHeight` apply only to a video that renders as an iframe. */
4
4
  export type FacebookEmbedProps = EmbedSource & Omit<FrameProps, keyof FacebookOptions> & FacebookOptions;
5
- export declare function FacebookEmbed(props: FacebookEmbedProps): import("react").JSX.Element | null;
5
+ export declare function FacebookEmbed(props: FacebookEmbedProps): import("react").ReactNode;
6
6
  export type { FacebookOptions };
@@ -1,40 +1,19 @@
1
1
  import { facebookPlan } from "../core/plans/facebook.js";
2
2
  import { facebook } from "../parser/platforms/facebook.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, planProps } from "./iframe-embed.js";
5
- import { ScriptEmbed } from "./script-embed.js";
6
- import { resolveEmbed } from "../core/resolve.js";
7
- import { jsx } from "react/jsx-runtime";
3
+ import { frameOf } from "./iframe-embed.js";
4
+ import { scriptOf } from "./script-embed.js";
5
+ import { usePlan } from "./use-plan.js";
8
6
  // src/components/facebook-embed.tsx
7
+ const FACEBOOK_OPTIONS = [
8
+ "locale",
9
+ "showText",
10
+ "allowfullscreen",
11
+ "autoplay",
12
+ "showCaptions"
13
+ ];
9
14
  function FacebookEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, facebook);
12
- const plan = embed ? facebookPlan(embed, {
13
- locale,
14
- showText,
15
- allowfullscreen,
16
- autoplay,
17
- showCaptions
18
- }) : void 0;
19
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
20
- if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
21
- ...shared,
22
- ...planProps(plan),
23
- onError,
24
- maxWidth: maxWidth ?? plan.maxWidth,
25
- height,
26
- maxHeight
27
- });
28
- if (plan?.kind !== "script") return null;
29
- return /* @__PURE__ */ jsx(ScriptEmbed, {
30
- ...shared,
31
- onError,
32
- maxWidth: maxWidth ?? plan.maxWidth,
33
- driver: plan.driver,
34
- markup: plan.markup,
35
- hasFallback: plan.hasFallback,
36
- minHeight: plan.minHeight,
37
- label: plan.label
38
- }, plan.key);
15
+ const [plan, frame] = usePlan(props, facebook, FACEBOOK_OPTIONS, facebookPlan);
16
+ if (plan?.kind === "iframe") return frameOf(plan, frame);
17
+ return plan?.kind === "script" ? scriptOf(plan, frame) : null;
39
18
  }
40
19
  export { FacebookEmbed };
@@ -2,5 +2,5 @@ import { FlickrOptions } from "../core/plans/flickr.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type FlickrEmbedProps = EmbedSource & Omit<FrameProps, keyof FlickrOptions> & FlickrOptions;
4
4
  /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
5
- export declare function FlickrEmbed(props: FlickrEmbedProps): import("react").JSX.Element | null;
5
+ export declare function FlickrEmbed(props: FlickrEmbedProps): import("react").ReactNode;
6
6
  export type { FlickrOptions };
@@ -1,27 +1,16 @@
1
1
  import { flickrPlan } from "../core/plans/flickr.js";
2
2
  import { flickr } from "../parser/platforms/flickr.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, fallbackPlaceholder, 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 { fallbackPlaceholder, frameOf } from "./iframe-embed.js";
7
5
  // src/components/flickr-embed.tsx
6
+ const FLICKR_OPTIONS = [
7
+ "header",
8
+ "footer",
9
+ "context"
10
+ ];
8
11
  /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
9
12
  function FlickrEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, header, footer, context, placeholder, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, flickr);
12
- const plan = embed ? flickrPlan(embed, {
13
- header,
14
- footer,
15
- context
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
- placeholder: placeholder ?? fallbackPlaceholder(plan)
25
- });
13
+ const [plan, frame] = usePlan(props, flickr, FLICKR_OPTIONS, flickrPlan);
14
+ return plan?.kind === "iframe" ? frameOf(plan, frame, fallbackPlaceholder) : null;
26
15
  }
27
16
  export { FlickrEmbed };
@@ -1,4 +1,4 @@
1
1
  import { EmbedSource, FrameProps } from "./shared.js";
2
2
  export type GiphyEmbedProps = EmbedSource & FrameProps;
3
3
  /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
4
- export declare function GiphyEmbed(props: GiphyEmbedProps): import("react").JSX.Element | null;
4
+ export declare function GiphyEmbed(props: GiphyEmbedProps): import("react").ReactNode;
@@ -1,22 +1,11 @@
1
1
  import { giphyPlan } from "../core/plans/giphy.js";
2
2
  import { giphy } from "../parser/platforms/giphy.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/giphy-embed.tsx
8
6
  /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
9
7
  function GiphyEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, giphy);
12
- const plan = embed ? giphyPlan(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, giphy, [], giphyPlan);
9
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
21
10
  }
22
11
  export { GiphyEmbed };
@@ -1,5 +1,5 @@
1
1
  import { FRAME_TIMEOUT_MS } from "../core/timing.js";
2
- import { frameStyle, srcWithSize, watchWidth } from "../core/layout.js";
2
+ import { frameStyle } from "../core/layout.js";
3
3
  import { useNearViewport } from "./hooks.js";
4
4
  import { useCallback, useEffect, useRef, useState } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -18,6 +18,20 @@ function fallbackPlaceholder(plan) {
18
18
  dangerouslySetInnerHTML: { __html: fallbackHtml }
19
19
  }) : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } });
20
20
  }
21
+ /**
22
+ * A platform component's frame: the host's `maxWidth` and `height` win over the plan's.
23
+ * Platforms with fallback content pass `fallbackPlaceholder`, which the others never bundle.
24
+ */
25
+ function frameOf(plan, props, fallback) {
26
+ const { maxWidth, height, placeholder, ...rest } = props;
27
+ return /* @__PURE__ */ jsx(IframeEmbed, {
28
+ ...rest,
29
+ ...planProps(plan),
30
+ maxWidth: maxWidth ?? plan.maxWidth,
31
+ height: height ?? plan.height,
32
+ placeholder: placeholder ?? fallback?.(plan)
33
+ });
34
+ }
21
35
  const FILL = {
22
36
  position: "absolute",
23
37
  inset: 0
@@ -25,7 +39,7 @@ const FILL = {
25
39
  function IframeEmbed(props) {
26
40
  return /* @__PURE__ */ jsx(Frame, { ...props }, props.src);
27
41
  }
28
- function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, borderRadius, sizeInSrc, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
42
+ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, clientSrc, borderRadius, sizeInSrc, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
29
43
  const frame = useRef(null);
30
44
  const iframe = useRef(null);
31
45
  const near = useNearViewport(frame, lazy);
@@ -52,34 +66,25 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
52
66
  }, []);
53
67
  useEffect(() => {
54
68
  if (!near || !messageHeight) return;
55
- const { origin, read } = messageHeight;
56
- const listen = (event) => {
57
- if (event.origin !== origin) return;
58
- if (!iframe.current || event.source !== iframe.current.contentWindow) return;
59
- let value;
60
- try {
61
- value = read(event.data);
62
- } catch {
63
- return;
64
- }
65
- if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
66
- setReportedHeight(Math.ceil(value));
69
+ return messageHeight.listen(() => iframe.current, (value) => {
70
+ setReportedHeight(value);
67
71
  report();
68
- };
69
- window.addEventListener("message", listen);
70
- return () => {
71
- window.removeEventListener("message", listen);
72
- };
72
+ });
73
73
  }, [
74
74
  near,
75
75
  messageHeight,
76
76
  report
77
77
  ]);
78
+ const sizing = useRef(sizeInSrc);
79
+ useEffect(() => {
80
+ sizing.current = sizeInSrc;
81
+ });
82
+ const sized = sizeInSrc !== void 0;
78
83
  useEffect(() => {
79
84
  const element = frame.current;
80
- if (!near || !sizeInSrc || !element) return;
81
- return watchWidth(element, setBoxWidth);
82
- }, [near, sizeInSrc]);
85
+ if (!near || !sized || !element) return;
86
+ return sizing.current?.watch(element, setBoxWidth);
87
+ }, [near, sized]);
83
88
  useEffect(() => {
84
89
  if (!near || !inView) return;
85
90
  const failure = messageHeight ? "did not report its height" : "did not load";
@@ -116,11 +121,7 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
116
121
  }, reportedHeight),
117
122
  ...style
118
123
  };
119
- const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
120
- src,
121
- ratio,
122
- size
123
- }, boxWidth);
124
+ const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : sizeInSrc.src(boxWidth);
124
125
  return /* @__PURE__ */ jsx("div", {
125
126
  ...rest,
126
127
  style: wrapper,
@@ -129,7 +130,7 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
129
130
  style: FILL,
130
131
  children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
131
132
  ref: iframe,
132
- src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
133
+ src: clientSrc ? clientSrc(frameSrc) : frameSrc,
133
134
  title,
134
135
  allow,
135
136
  allowFullScreen: allowFullscreen,
@@ -152,9 +153,6 @@ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scro
152
153
  })
153
154
  });
154
155
  }
155
- function withHost(src, name) {
156
- return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
157
- }
158
156
  function Skeleton({ minHeight }) {
159
157
  return /* @__PURE__ */ jsx("div", {
160
158
  "aria-hidden": "true",
@@ -166,4 +164,4 @@ function Skeleton({ minHeight }) {
166
164
  }
167
165
  });
168
166
  }
169
- export { IframeEmbed, Skeleton, fallbackPlaceholder, planProps };
167
+ export { IframeEmbed, Skeleton, fallbackPlaceholder, frameOf, planProps };
@@ -2,5 +2,5 @@ import { ImgurOptions } from "../core/plans/imgur.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type ImgurEmbedProps = EmbedSource & Omit<SharedProps, keyof ImgurOptions> & ImgurOptions;
4
4
  /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
5
- export declare function ImgurEmbed(props: ImgurEmbedProps): import("react").JSX.Element | null;
5
+ export declare function ImgurEmbed(props: ImgurEmbedProps): import("react").ReactNode;
6
6
  export type { ImgurOptions };
@@ -1,23 +1,12 @@
1
1
  import { imgurPlan } from "../core/plans/imgur.js";
2
2
  import { imgur } from "../parser/platforms/imgur.js";
3
- import { useReportError } from "./hooks.js";
4
- import { IframeEmbed, fallbackPlaceholder, 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 { fallbackPlaceholder, frameOf } from "./iframe-embed.js";
7
5
  // src/components/imgur-embed.tsx
6
+ const IMGUR_OPTIONS = ["context"];
8
7
  /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
9
8
  function ImgurEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, context, placeholder, ...shared } = props;
11
- const { embed, error } = resolveEmbed(url, given, imgur);
12
- const plan = embed ? imgurPlan(embed, { context }) : 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
- placeholder: placeholder ?? fallbackPlaceholder(plan)
21
- });
9
+ const [plan, frame] = usePlan(props, imgur, IMGUR_OPTIONS, imgurPlan);
10
+ return plan?.kind === "iframe" ? frameOf(plan, frame, fallbackPlaceholder) : null;
22
11
  }
23
12
  export { ImgurEmbed };
@@ -1,5 +1,5 @@
1
1
  import { InstagramOptions } from "../core/plans/instagram.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
4
- export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").JSX.Element | null;
4
+ export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").ReactNode;
5
5
  export type { InstagramOptions };
@@ -1,25 +1,11 @@
1
1
  import { instagramPlan } from "../core/plans/instagram.js";
2
2
  import { instagram } from "../parser/platforms/instagram.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/instagram-embed.tsx
6
+ const INSTAGRAM_OPTIONS = ["captioned"];
8
7
  function InstagramEmbed(props) {
9
- const { url, embed: given, onError, maxWidth, captioned, ...shared } = props;
10
- const { embed, error } = resolveEmbed(url, given, instagram);
11
- const plan = embed ? instagramPlan(embed, { captioned }) : 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, instagram, INSTAGRAM_OPTIONS, instagramPlan);
9
+ return plan?.kind === "script" ? scriptOf(plan, frame) : null;
24
10
  }
25
11
  export { InstagramEmbed };
@@ -2,5 +2,5 @@ import { KickOptions } from "../core/plans/kick.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type KickEmbedProps = EmbedSource & Omit<FrameProps, keyof KickOptions> & KickOptions;
4
4
  /** A live channel at 16:9. */
5
- export declare function KickEmbed(props: KickEmbedProps): import("react").JSX.Element | null;
5
+ export declare function KickEmbed(props: KickEmbedProps): import("react").ReactNode;
6
6
  export type { KickOptions };
@@ -1,25 +1,12 @@
1
1
  import { kickPlan } from "../core/plans/kick.js";
2
2
  import { kick } from "../parser/platforms/kick.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/kick-embed.tsx
6
+ const KICK_OPTIONS = ["autoplay", "muted"];
8
7
  /** A live channel at 16:9. */
9
8
  function KickEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, autoplay, muted, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, kick);
12
- const plan = embed ? kickPlan(embed, {
13
- autoplay,
14
- muted
15
- }) : 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
- maxWidth: maxWidth ?? plan.maxWidth
23
- });
9
+ const [plan, frame] = usePlan(props, kick, KICK_OPTIONS, kickPlan);
10
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
24
11
  }
25
12
  export { KickEmbed };
@@ -2,5 +2,5 @@ import { LinkedInOptions } from "../core/plans/linkedin.js";
2
2
  import { EmbedSource, FrameProps } from "./shared.js";
3
3
  export type LinkedInEmbedProps = EmbedSource & Omit<FrameProps, keyof LinkedInOptions> & LinkedInOptions;
4
4
  /** A fixed height: the `height` prop, else the embed code's, else 670px. */
5
- export declare function LinkedInEmbed(props: LinkedInEmbedProps): import("react").JSX.Element | null;
5
+ export declare function LinkedInEmbed(props: LinkedInEmbedProps): import("react").ReactNode;
6
6
  export type { LinkedInOptions };
@@ -1,23 +1,12 @@
1
1
  import { linkedinPlan } from "../core/plans/linkedin.js";
2
2
  import { linkedin } from "../parser/platforms/linkedin.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/linkedin-embed.tsx
6
+ const LINKEDIN_OPTIONS = ["collapsed"];
8
7
  /** A fixed height: the `height` prop, else the embed code's, else 670px. */
9
8
  function LinkedInEmbed(props) {
10
- const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
11
- const { embed, error } = resolveEmbed(url, given, linkedin);
12
- const plan = embed ? linkedinPlan(embed, { collapsed }) : 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
- height: height ?? plan.height
21
- });
9
+ const [plan, frame] = usePlan(props, linkedin, LINKEDIN_OPTIONS, linkedinPlan);
10
+ return plan?.kind === "iframe" ? frameOf(plan, frame) : null;
22
11
  }
23
12
  export { LinkedInEmbed };
@@ -1,5 +1,5 @@
1
1
  import { PinterestOptions } from "../core/plans/pinterest.js";
2
2
  import { EmbedSource, SharedProps } from "./shared.js";
3
3
  export type PinterestEmbedProps = EmbedSource & Omit<SharedProps, keyof PinterestOptions> & PinterestOptions;
4
- export declare function PinterestEmbed(props: PinterestEmbedProps): import("react").JSX.Element | null;
4
+ export declare function PinterestEmbed(props: PinterestEmbedProps): import("react").ReactNode;
5
5
  export type { PinterestOptions };