social-embeds 0.7.1 → 0.8.0

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 (174) hide show
  1. package/README.md +13 -8
  2. package/dist/components/apple-embed.d.ts +7 -0
  3. package/dist/components/apple-embed.js +39 -0
  4. package/dist/components/bluesky-embed.d.ts +10 -0
  5. package/dist/components/bluesky-embed.js +27 -0
  6. package/dist/components/dailymotion-embed.d.ts +9 -0
  7. package/dist/components/dailymotion-embed.js +30 -0
  8. package/dist/components/facebook-embed.d.ts +6 -0
  9. package/dist/components/facebook-embed.js +40 -0
  10. package/dist/components/flickr-embed.d.ts +6 -0
  11. package/dist/components/flickr-embed.js +27 -0
  12. package/dist/components/generic-iframe-embed.d.ts +11 -0
  13. package/dist/components/generic-iframe-embed.js +26 -0
  14. package/dist/components/giphy-embed.d.ts +4 -0
  15. package/dist/components/giphy-embed.js +22 -0
  16. package/dist/components/hooks.js +36 -0
  17. package/dist/components/iframe-embed.js +169 -0
  18. package/dist/components/imgur-embed.d.ts +6 -0
  19. package/dist/components/imgur-embed.js +23 -0
  20. package/dist/components/instagram-embed.d.ts +5 -0
  21. package/dist/components/instagram-embed.js +25 -0
  22. package/dist/components/kick-embed.d.ts +6 -0
  23. package/dist/components/kick-embed.js +25 -0
  24. package/dist/components/linkedin-embed.d.ts +6 -0
  25. package/dist/components/linkedin-embed.js +23 -0
  26. package/dist/components/pinterest-embed.d.ts +5 -0
  27. package/dist/components/pinterest-embed.js +25 -0
  28. package/dist/components/reddit-embed.d.ts +6 -0
  29. package/dist/components/reddit-embed.js +29 -0
  30. package/dist/components/rumble-embed.d.ts +4 -0
  31. package/dist/components/rumble-embed.js +22 -0
  32. package/dist/components/script-embed.js +107 -0
  33. package/dist/components/shared.d.ts +29 -0
  34. package/dist/components/snapchat-embed.d.ts +4 -0
  35. package/dist/components/snapchat-embed.js +22 -0
  36. package/dist/components/social-embed.d.ts +60 -0
  37. package/dist/components/social-embed.js +221 -0
  38. package/dist/components/soundcloud-embed.d.ts +6 -0
  39. package/dist/components/soundcloud-embed.js +33 -0
  40. package/dist/components/spotify-embed.d.ts +9 -0
  41. package/dist/components/spotify-embed.js +25 -0
  42. package/dist/components/strava-embed.d.ts +6 -0
  43. package/dist/components/strava-embed.js +26 -0
  44. package/dist/components/streamable-embed.d.ts +6 -0
  45. package/dist/components/streamable-embed.js +28 -0
  46. package/dist/components/telegram-embed.d.ts +6 -0
  47. package/dist/components/telegram-embed.js +27 -0
  48. package/dist/components/tenor-embed.d.ts +4 -0
  49. package/dist/components/tenor-embed.js +22 -0
  50. package/dist/components/threads-embed.d.ts +5 -0
  51. package/dist/components/threads-embed.js +25 -0
  52. package/dist/components/tiktok-embed.d.ts +6 -0
  53. package/dist/components/tiktok-embed.js +37 -0
  54. package/dist/components/truthsocial-embed.d.ts +4 -0
  55. package/dist/components/truthsocial-embed.js +22 -0
  56. package/dist/components/tumblr-embed.d.ts +4 -0
  57. package/dist/components/tumblr-embed.js +22 -0
  58. package/dist/components/twitch-embed.d.ts +6 -0
  59. package/dist/components/twitch-embed.js +26 -0
  60. package/dist/components/vimeo-embed.d.ts +5 -0
  61. package/dist/components/vimeo-embed.js +40 -0
  62. package/dist/components/x-embed.d.ts +5 -0
  63. package/dist/components/x-embed.js +32 -0
  64. package/dist/components/youtube-embed.d.ts +5 -0
  65. package/dist/components/youtube-embed.js +43 -0
  66. package/dist/core/drivers.js +118 -0
  67. package/dist/core/layout.js +73 -0
  68. package/dist/core/markup.js +30 -0
  69. package/dist/core/params.js +26 -0
  70. package/dist/core/plans/apple.js +44 -0
  71. package/dist/core/plans/bluesky.d.ts +3 -0
  72. package/dist/core/plans/bluesky.js +34 -0
  73. package/dist/core/plans/dailymotion.d.ts +8 -0
  74. package/dist/core/plans/dailymotion.js +37 -0
  75. package/dist/core/plans/facebook.d.ts +15 -0
  76. package/dist/core/plans/facebook.js +79 -0
  77. package/dist/core/plans/flickr.d.ts +7 -0
  78. package/dist/core/plans/flickr.js +37 -0
  79. package/dist/core/plans/generic.js +44 -0
  80. package/dist/core/plans/giphy.js +16 -0
  81. package/dist/core/plans/imgur.d.ts +4 -0
  82. package/dist/core/plans/imgur.js +34 -0
  83. package/dist/core/plans/instagram.d.ts +4 -0
  84. package/dist/core/plans/instagram.js +26 -0
  85. package/dist/core/plans/kick.d.ts +5 -0
  86. package/dist/core/plans/kick.js +22 -0
  87. package/dist/core/plans/linkedin.d.ts +4 -0
  88. package/dist/core/plans/linkedin.js +23 -0
  89. package/dist/core/plans/pinterest.d.ts +4 -0
  90. package/dist/core/plans/pinterest.js +31 -0
  91. package/dist/core/plans/reddit.d.ts +11 -0
  92. package/dist/core/plans/reddit.js +46 -0
  93. package/dist/core/plans/rumble.js +21 -0
  94. package/dist/core/plans/snapchat.js +20 -0
  95. package/dist/core/plans/soundcloud.d.ts +14 -0
  96. package/dist/core/plans/soundcloud.js +37 -0
  97. package/dist/core/plans/spotify.d.ts +4 -0
  98. package/dist/core/plans/spotify.js +29 -0
  99. package/dist/core/plans/strava.d.ts +8 -0
  100. package/dist/core/plans/strava.js +38 -0
  101. package/dist/core/plans/streamable.d.ts +8 -0
  102. package/dist/core/plans/streamable.js +31 -0
  103. package/dist/core/plans/telegram.d.ts +10 -0
  104. package/dist/core/plans/telegram.js +59 -0
  105. package/dist/core/plans/tenor.js +16 -0
  106. package/dist/core/plans/threads.d.ts +4 -0
  107. package/dist/core/plans/threads.js +25 -0
  108. package/dist/core/plans/tiktok.d.ts +17 -0
  109. package/dist/core/plans/tiktok.js +36 -0
  110. package/dist/core/plans/truthsocial.js +43 -0
  111. package/dist/core/plans/tumblr.js +29 -0
  112. package/dist/core/plans/twitch.d.ts +7 -0
  113. package/dist/core/plans/twitch.js +38 -0
  114. package/dist/core/plans/vimeo.d.ts +23 -0
  115. package/dist/core/plans/vimeo.js +42 -0
  116. package/dist/core/plans/x.d.ts +12 -0
  117. package/dist/core/plans/x.js +31 -0
  118. package/dist/core/plans/youtube.d.ts +25 -0
  119. package/dist/core/plans/youtube.js +47 -0
  120. package/dist/core/post-link.js +19 -0
  121. package/dist/core/resolve.js +57 -0
  122. package/dist/core/timing.js +7 -0
  123. package/dist/element.js +1 -1
  124. package/dist/index.d.ts +53 -344
  125. package/dist/index.js +30 -2575
  126. package/dist/loader/load-script.js +114 -0
  127. package/dist/loader/platform-scripts.js +89 -0
  128. package/dist/parser/html.js +172 -0
  129. package/dist/parser/iframe.d.ts +24 -0
  130. package/dist/parser/iframe.js +151 -0
  131. package/dist/parser/lookup.js +20 -0
  132. package/dist/parser/match-url.d.ts +3 -0
  133. package/dist/parser/match-url.js +22 -0
  134. package/dist/parser/parse-embed.d.ts +7 -0
  135. package/dist/parser/parse-embed.js +69 -0
  136. package/dist/parser/platform.js +60 -0
  137. package/dist/parser/platforms/applemusic.js +45 -0
  138. package/dist/parser/platforms/applepodcasts.js +41 -0
  139. package/dist/parser/platforms/bluesky.js +64 -0
  140. package/dist/parser/platforms/dailymotion.js +59 -0
  141. package/dist/parser/platforms/facebook.js +185 -0
  142. package/dist/parser/platforms/flickr.js +134 -0
  143. package/dist/parser/platforms/giphy.js +68 -0
  144. package/dist/parser/platforms/imgur.js +107 -0
  145. package/dist/parser/platforms/index.js +62 -0
  146. package/dist/parser/platforms/instagram.js +59 -0
  147. package/dist/parser/platforms/kick.js +61 -0
  148. package/dist/parser/platforms/linkedin.js +42 -0
  149. package/dist/parser/platforms/pinterest.js +59 -0
  150. package/dist/parser/platforms/reddit.js +68 -0
  151. package/dist/parser/platforms/rumble.js +43 -0
  152. package/dist/parser/platforms/snapchat.js +87 -0
  153. package/dist/parser/platforms/soundcloud.js +128 -0
  154. package/dist/parser/platforms/spotify.js +51 -0
  155. package/dist/parser/platforms/strava.js +55 -0
  156. package/dist/parser/platforms/streamable.js +94 -0
  157. package/dist/parser/platforms/telegram.js +61 -0
  158. package/dist/parser/platforms/tenor.js +78 -0
  159. package/dist/parser/platforms/threads.js +51 -0
  160. package/dist/parser/platforms/tiktok.js +48 -0
  161. package/dist/parser/platforms/truthsocial.js +49 -0
  162. package/dist/parser/platforms/tumblr.js +70 -0
  163. package/dist/parser/platforms/twitch.js +129 -0
  164. package/dist/parser/platforms/vimeo.js +76 -0
  165. package/dist/parser/platforms/x.js +65 -0
  166. package/dist/parser/platforms/youtube.js +90 -0
  167. package/dist/parser/types.d.ts +14 -0
  168. package/dist/parser/url.js +41 -0
  169. package/dist/parser/verify.js +63 -0
  170. package/dist/parser.d.ts +4 -1
  171. package/dist/parser.js +4 -1
  172. package/package.json +1 -1
  173. package/dist/index-DrMHAkyG.d.ts +0 -46
  174. package/dist/parser-CovaPg5T.js +0 -2585
@@ -0,0 +1,25 @@
1
+ import { instagramPlan } from "../core/plans/instagram.js";
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";
7
+ // src/components/instagram-embed.tsx
8
+ 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);
24
+ }
25
+ export { InstagramEmbed };
@@ -0,0 +1,6 @@
1
+ import { KickOptions } from "../core/plans/kick.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type KickEmbedProps = EmbedSource & Omit<FrameProps, keyof KickOptions> & KickOptions;
4
+ /** A live channel at 16:9. */
5
+ export declare function KickEmbed(props: KickEmbedProps): import("react").JSX.Element | null;
6
+ export type { KickOptions };
@@ -0,0 +1,25 @@
1
+ import { kickPlan } from "../core/plans/kick.js";
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";
7
+ // src/components/kick-embed.tsx
8
+ /** A live channel at 16:9. */
9
+ 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
+ });
24
+ }
25
+ export { KickEmbed };
@@ -0,0 +1,6 @@
1
+ import { LinkedInOptions } from "../core/plans/linkedin.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type LinkedInEmbedProps = EmbedSource & Omit<FrameProps, keyof LinkedInOptions> & LinkedInOptions;
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;
6
+ export type { LinkedInOptions };
@@ -0,0 +1,23 @@
1
+ import { linkedinPlan } from "../core/plans/linkedin.js";
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";
7
+ // src/components/linkedin-embed.tsx
8
+ /** A fixed height: the `height` prop, else the embed code's, else 670px. */
9
+ 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
+ });
22
+ }
23
+ export { LinkedInEmbed };
@@ -0,0 +1,5 @@
1
+ import { PinterestOptions } from "../core/plans/pinterest.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type PinterestEmbedProps = EmbedSource & Omit<SharedProps, keyof PinterestOptions> & PinterestOptions;
4
+ export declare function PinterestEmbed(props: PinterestEmbedProps): import("react").JSX.Element | null;
5
+ export type { PinterestOptions };
@@ -0,0 +1,25 @@
1
+ import { pinterestPlan } from "../core/plans/pinterest.js";
2
+ import { pinterest } from "../parser/platforms/pinterest.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";
7
+ // src/components/pinterest-embed.tsx
8
+ function PinterestEmbed(props) {
9
+ const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
10
+ const { embed, error } = resolveEmbed(url, given, pinterest);
11
+ const plan = embed ? pinterestPlan(embed, { pinWidth }) : 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);
24
+ }
25
+ export { PinterestEmbed };
@@ -0,0 +1,6 @@
1
+ import { RedditOptions } from "../core/plans/reddit.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type RedditEmbedProps = EmbedSource & Omit<SharedProps, keyof RedditOptions> & RedditOptions;
4
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
5
+ export declare function RedditEmbed(props: RedditEmbedProps): import("react").JSX.Element | null;
6
+ export type { RedditOptions };
@@ -0,0 +1,29 @@
1
+ import { redditPlan } from "../core/plans/reddit.js";
2
+ import { reddit } from "../parser/platforms/reddit.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";
7
+ // src/components/reddit-embed.tsx
8
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
9
+ function RedditEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
11
+ const { embed, error } = resolveEmbed(url, given, reddit);
12
+ const plan = embed ? redditPlan(embed, {
13
+ theme,
14
+ showMedia,
15
+ showTitle,
16
+ showUsername,
17
+ locale,
18
+ depth
19
+ }) : void 0;
20
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
21
+ if (plan?.kind !== "iframe") return null;
22
+ return /* @__PURE__ */ jsx(IframeEmbed, {
23
+ ...shared,
24
+ ...planProps(plan),
25
+ onError,
26
+ maxWidth: maxWidth ?? plan.maxWidth
27
+ });
28
+ }
29
+ export { RedditEmbed };
@@ -0,0 +1,4 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type RumbleEmbedProps = EmbedSource & FrameProps;
3
+ /** Embed code only: a page URL holds another id than the player (docs/decisions.md D99). */
4
+ export declare function RumbleEmbed(props: RumbleEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ import { rumblePlan } from "../core/plans/rumble.js";
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";
7
+ // src/components/rumble-embed.tsx
8
+ /** Embed code only: a page URL holds another id than the player (docs/decisions.md D99). */
9
+ 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
+ });
21
+ }
22
+ export { RumbleEmbed };
@@ -0,0 +1,107 @@
1
+ import { postLinkText, postUrl } from "../core/post-link.js";
2
+ import { RENDER_TIMEOUT_MS, RETRY_DELAY_MS } from "../core/timing.js";
3
+ import { useNearViewport } from "./hooks.js";
4
+ import { Skeleton } from "./iframe-embed.js";
5
+ import { useEffect, useRef, useState } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // src/components/script-embed.tsx
8
+ const LAYER = { width: "100%" };
9
+ function toError(error) {
10
+ return error instanceof Error ? error : new Error(String(error));
11
+ }
12
+ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "100%", maxWidth, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
13
+ const container = useRef(null);
14
+ const near = useNearViewport(container, lazy);
15
+ const [rendered, setRendered] = useState(false);
16
+ const [failure, setFailure] = useState();
17
+ const callbacks = useRef({
18
+ onLoad,
19
+ onError
20
+ });
21
+ useEffect(() => {
22
+ callbacks.current = {
23
+ onLoad,
24
+ onError
25
+ };
26
+ });
27
+ useEffect(() => {
28
+ const element = container.current;
29
+ if (!near || !element) return;
30
+ let cancelled = false;
31
+ let done = false;
32
+ let timer;
33
+ let stop = () => {};
34
+ const href = postUrl(element);
35
+ const finish = () => {
36
+ if (cancelled || done) return;
37
+ done = true;
38
+ clearTimeout(timer);
39
+ stop();
40
+ setRendered(true);
41
+ callbacks.current.onLoad?.();
42
+ };
43
+ const fail = (error) => {
44
+ setFailure({ href });
45
+ callbacks.current.onError?.(error);
46
+ };
47
+ const retryOrFail = (number, error) => {
48
+ if (cancelled || done) return;
49
+ stop();
50
+ stop = () => {};
51
+ if (number >= 3) {
52
+ fail(error);
53
+ return;
54
+ }
55
+ timer = setTimeout(() => {
56
+ attempt(number + 1);
57
+ }, RETRY_DELAY_MS * 2 ** (number - 1));
58
+ };
59
+ const attempt = (number) => {
60
+ if (cancelled || done) return;
61
+ try {
62
+ stop = driver.render(element, finish);
63
+ } catch (error) {
64
+ retryOrFail(number, toError(error));
65
+ return;
66
+ }
67
+ timer = setTimeout(() => {
68
+ retryOrFail(number, /* @__PURE__ */ new Error(`social-embeds: the ${label} embed did not render`));
69
+ }, RENDER_TIMEOUT_MS);
70
+ };
71
+ driver.load().then(() => {
72
+ attempt(1);
73
+ }, (error) => {
74
+ if (!cancelled) fail(toError(error));
75
+ });
76
+ return () => {
77
+ cancelled = true;
78
+ clearTimeout(timer);
79
+ stop();
80
+ };
81
+ }, [
82
+ near,
83
+ driver,
84
+ label
85
+ ]);
86
+ const wrapper = {
87
+ width,
88
+ maxWidth,
89
+ ...style
90
+ };
91
+ return /* @__PURE__ */ jsx("div", {
92
+ ...rest,
93
+ style: wrapper,
94
+ children: /* @__PURE__ */ jsxs("div", {
95
+ style: LAYER,
96
+ children: [/* @__PURE__ */ jsx("div", {
97
+ ref: container,
98
+ suppressHydrationWarning: true,
99
+ dangerouslySetInnerHTML: { __html: markup }
100
+ }), !hasFallback && !rendered && (failure ? failure.href !== void 0 && /* @__PURE__ */ jsx("a", {
101
+ href: failure.href,
102
+ children: postLinkText(label)
103
+ }) : placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
104
+ })
105
+ });
106
+ }
107
+ export { ScriptEmbed };
@@ -0,0 +1,29 @@
1
+ import { ParsedEmbed } from "../parser/types.js";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ export type EmbedSource = {
4
+ url: string;
5
+ embed?: never;
6
+ } | {
7
+ embed: ParsedEmbed;
8
+ url?: never;
9
+ };
10
+ export type SharedProps = Omit<ComponentProps<'div'>, 'children' | 'onLoad' | 'onError'> & {
11
+ /** Wrapper width. Default `'100%'`. */
12
+ width?: number | string;
13
+ /** The embed fills its container up to this width, in pixels. */
14
+ maxWidth?: number;
15
+ /** Rendered until the embed has loaded. Default: a neutral skeleton. */
16
+ placeholder?: ReactNode;
17
+ /** Load the embed only when it comes near the viewport. Default `true`. */
18
+ lazy?: boolean;
19
+ /** Fires once the platform has rendered the post. */
20
+ onLoad?: () => void;
21
+ /** Fires on invalid input, script load failure or init timeout. */
22
+ onError?: (error: Error) => void;
23
+ };
24
+ export type FrameProps = SharedProps & {
25
+ /** A fixed height in pixels, instead of the embed's aspect ratio. */
26
+ height?: number;
27
+ /** The embed is at most this tall, in pixels: it narrows to keep its aspect ratio. */
28
+ maxHeight?: number;
29
+ };
@@ -0,0 +1,4 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type SnapchatEmbedProps = EmbedSource & FrameProps;
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;
@@ -0,0 +1,22 @@
1
+ import { snapchatPlan } from "../core/plans/snapchat.js";
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";
7
+ // src/components/snapchat-embed.tsx
8
+ /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
9
+ 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
+ });
21
+ }
22
+ export { SnapchatEmbed };
@@ -0,0 +1,60 @@
1
+ import "./bluesky-embed.js";
2
+ import { BlueskyOptions } from "../core/plans/bluesky.js";
3
+ import "./dailymotion-embed.js";
4
+ import { DailymotionOptions } from "../core/plans/dailymotion.js";
5
+ import "./facebook-embed.js";
6
+ import { FacebookOptions } from "../core/plans/facebook.js";
7
+ import "./flickr-embed.js";
8
+ import { FlickrOptions } from "../core/plans/flickr.js";
9
+ import "./imgur-embed.js";
10
+ import { ImgurOptions } from "../core/plans/imgur.js";
11
+ import "./instagram-embed.js";
12
+ import { InstagramOptions } from "../core/plans/instagram.js";
13
+ import "./kick-embed.js";
14
+ import { KickOptions } from "../core/plans/kick.js";
15
+ import "./linkedin-embed.js";
16
+ import { LinkedInOptions } from "../core/plans/linkedin.js";
17
+ import "./pinterest-embed.js";
18
+ import { PinterestOptions } from "../core/plans/pinterest.js";
19
+ import "./reddit-embed.js";
20
+ import { RedditOptions } from "../core/plans/reddit.js";
21
+ import { FrameProps } from "./shared.js";
22
+ import { SoundCloudOptions } from "../core/plans/soundcloud.js";
23
+ import "./soundcloud-embed.js";
24
+ import { StravaOptions } from "../core/plans/strava.js";
25
+ import "./strava-embed.js";
26
+ import { StreamableOptions } from "../core/plans/streamable.js";
27
+ import "./streamable-embed.js";
28
+ import { TelegramOptions } from "../core/plans/telegram.js";
29
+ import "./telegram-embed.js";
30
+ import { ThreadsOptions } from "../core/plans/threads.js";
31
+ import "./threads-embed.js";
32
+ import { TikTokOptions } from "../core/plans/tiktok.js";
33
+ import "./tiktok-embed.js";
34
+ import { TwitchOptions } from "../core/plans/twitch.js";
35
+ import "./twitch-embed.js";
36
+ import { VimeoOptions } from "../core/plans/vimeo.js";
37
+ import "./vimeo-embed.js";
38
+ import { XOptions } from "../core/plans/x.js";
39
+ import "./x-embed.js";
40
+ import { YouTubeOptions } from "../core/plans/youtube.js";
41
+ import "./youtube-embed.js";
42
+ import { ReactNode } from "react";
43
+ export type SocialEmbedSource = {
44
+ html: string;
45
+ url?: never;
46
+ } | {
47
+ url: string;
48
+ html?: never;
49
+ };
50
+ type PlatformOption = keyof XOptions | keyof InstagramOptions | keyof ThreadsOptions | keyof FacebookOptions | keyof TikTokOptions | keyof YouTubeOptions | keyof TelegramOptions | keyof RedditOptions | keyof LinkedInOptions | keyof PinterestOptions | keyof VimeoOptions | keyof TwitchOptions | keyof DailymotionOptions | keyof BlueskyOptions | keyof SoundCloudOptions | keyof KickOptions | keyof StreamableOptions | keyof ImgurOptions | keyof StravaOptions | keyof FlickrOptions;
51
+ export type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOption> & {
52
+ /**
53
+ * Called with the original string when `html` is neither a platform's embed code nor a
54
+ * safe iframe. Without it, nothing is rendered and `onError` is called.
55
+ */
56
+ fallback?: (html: string) => ReactNode;
57
+ };
58
+ /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
59
+ export declare function SocialEmbed(props: SocialEmbedProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
60
+ export {};
@@ -0,0 +1,221 @@
1
+ import { matchUrl } from "../parser/match-url.js";
2
+ import { parseEmbed } from "../parser/parse-embed.js";
3
+ import { parseIframe } from "../parser/iframe.js";
4
+ import { sourceError } from "../core/resolve.js";
5
+ import { AppleMusicEmbed, ApplePodcastsEmbed } from "./apple-embed.js";
6
+ import { BlueskyEmbed } from "./bluesky-embed.js";
7
+ import { DailymotionEmbed } from "./dailymotion-embed.js";
8
+ import { FacebookEmbed } from "./facebook-embed.js";
9
+ import { FlickrEmbed } from "./flickr-embed.js";
10
+ import { GenericIframeEmbed } from "./generic-iframe-embed.js";
11
+ import { GiphyEmbed } from "./giphy-embed.js";
12
+ import { useReportError } from "./hooks.js";
13
+ import { ImgurEmbed } from "./imgur-embed.js";
14
+ import { InstagramEmbed } from "./instagram-embed.js";
15
+ import { KickEmbed } from "./kick-embed.js";
16
+ import { LinkedInEmbed } from "./linkedin-embed.js";
17
+ import { PinterestEmbed } from "./pinterest-embed.js";
18
+ import { RedditEmbed } from "./reddit-embed.js";
19
+ import { SnapchatEmbed } from "./snapchat-embed.js";
20
+ import { SoundCloudEmbed } from "./soundcloud-embed.js";
21
+ import { SpotifyEmbed } from "./spotify-embed.js";
22
+ import { StravaEmbed } from "./strava-embed.js";
23
+ import { StreamableEmbed } from "./streamable-embed.js";
24
+ import { RumbleEmbed } from "./rumble-embed.js";
25
+ import { TenorEmbed } from "./tenor-embed.js";
26
+ import { TelegramEmbed } from "./telegram-embed.js";
27
+ import { ThreadsEmbed } from "./threads-embed.js";
28
+ import { TikTokEmbed } from "./tiktok-embed.js";
29
+ import { TruthSocialEmbed } from "./truthsocial-embed.js";
30
+ import { TumblrEmbed } from "./tumblr-embed.js";
31
+ import { TwitchEmbed } from "./twitch-embed.js";
32
+ import { VimeoEmbed } from "./vimeo-embed.js";
33
+ import { XEmbed } from "./x-embed.js";
34
+ import { YouTubeEmbed } from "./youtube-embed.js";
35
+ import { useMemo } from "react";
36
+ import { jsx } from "react/jsx-runtime";
37
+ // src/components/social-embed.tsx
38
+ /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
39
+ function SocialEmbed(props) {
40
+ const { html, url, fallback, height, maxHeight, onError, ...shared } = props;
41
+ const frame = {
42
+ height,
43
+ maxHeight
44
+ };
45
+ const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
46
+ const iframe = useMemo(() => embed === null && html !== void 0 ? parseIframe(html) : null, [embed, html]);
47
+ useReportError(embed === null && iframe === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
48
+ if (iframe) return /* @__PURE__ */ jsx(GenericIframeEmbed, {
49
+ ...shared,
50
+ ...frame,
51
+ onError,
52
+ embed: iframe
53
+ });
54
+ if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
55
+ switch (embed.platform) {
56
+ case "x": return /* @__PURE__ */ jsx(XEmbed, {
57
+ ...shared,
58
+ onError,
59
+ embed
60
+ });
61
+ case "instagram": return /* @__PURE__ */ jsx(InstagramEmbed, {
62
+ ...shared,
63
+ onError,
64
+ embed
65
+ });
66
+ case "threads": return /* @__PURE__ */ jsx(ThreadsEmbed, {
67
+ ...shared,
68
+ onError,
69
+ embed
70
+ });
71
+ case "facebook": return /* @__PURE__ */ jsx(FacebookEmbed, {
72
+ ...shared,
73
+ ...frame,
74
+ onError,
75
+ embed
76
+ });
77
+ case "tiktok": return /* @__PURE__ */ jsx(TikTokEmbed, {
78
+ ...shared,
79
+ ...frame,
80
+ onError,
81
+ embed
82
+ });
83
+ case "youtube": return /* @__PURE__ */ jsx(YouTubeEmbed, {
84
+ ...shared,
85
+ ...frame,
86
+ onError,
87
+ embed
88
+ });
89
+ case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
90
+ ...shared,
91
+ onError,
92
+ embed
93
+ });
94
+ case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
95
+ ...shared,
96
+ ...frame,
97
+ onError,
98
+ embed
99
+ });
100
+ case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
101
+ ...shared,
102
+ ...frame,
103
+ onError,
104
+ embed
105
+ });
106
+ case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
107
+ ...shared,
108
+ onError,
109
+ embed
110
+ });
111
+ case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
112
+ ...shared,
113
+ onError,
114
+ embed
115
+ });
116
+ case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
117
+ ...shared,
118
+ ...frame,
119
+ onError,
120
+ embed
121
+ });
122
+ case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
123
+ ...shared,
124
+ ...frame,
125
+ onError,
126
+ embed
127
+ });
128
+ case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
129
+ ...shared,
130
+ ...frame,
131
+ onError,
132
+ embed
133
+ });
134
+ case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
135
+ ...shared,
136
+ ...frame,
137
+ onError,
138
+ embed
139
+ });
140
+ case "bluesky": return /* @__PURE__ */ jsx(BlueskyEmbed, {
141
+ ...shared,
142
+ onError,
143
+ embed
144
+ });
145
+ case "soundcloud": return /* @__PURE__ */ jsx(SoundCloudEmbed, {
146
+ ...shared,
147
+ ...frame,
148
+ onError,
149
+ embed
150
+ });
151
+ case "applemusic": return /* @__PURE__ */ jsx(AppleMusicEmbed, {
152
+ ...shared,
153
+ ...frame,
154
+ onError,
155
+ embed
156
+ });
157
+ case "applepodcasts": return /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
158
+ ...shared,
159
+ ...frame,
160
+ onError,
161
+ embed
162
+ });
163
+ case "tumblr": return /* @__PURE__ */ jsx(TumblrEmbed, {
164
+ ...shared,
165
+ onError,
166
+ embed
167
+ });
168
+ case "kick": return /* @__PURE__ */ jsx(KickEmbed, {
169
+ ...shared,
170
+ ...frame,
171
+ onError,
172
+ embed
173
+ });
174
+ case "giphy": return /* @__PURE__ */ jsx(GiphyEmbed, {
175
+ ...shared,
176
+ ...frame,
177
+ onError,
178
+ embed
179
+ });
180
+ case "tenor": return /* @__PURE__ */ jsx(TenorEmbed, {
181
+ ...shared,
182
+ ...frame,
183
+ onError,
184
+ embed
185
+ });
186
+ case "streamable": return /* @__PURE__ */ jsx(StreamableEmbed, {
187
+ ...shared,
188
+ ...frame,
189
+ onError,
190
+ embed
191
+ });
192
+ case "rumble": return /* @__PURE__ */ jsx(RumbleEmbed, {
193
+ ...shared,
194
+ ...frame,
195
+ onError,
196
+ embed
197
+ });
198
+ case "truthsocial": return /* @__PURE__ */ jsx(TruthSocialEmbed, {
199
+ ...shared,
200
+ onError,
201
+ embed
202
+ });
203
+ case "imgur": return /* @__PURE__ */ jsx(ImgurEmbed, {
204
+ ...shared,
205
+ onError,
206
+ embed
207
+ });
208
+ case "strava": return /* @__PURE__ */ jsx(StravaEmbed, {
209
+ ...shared,
210
+ onError,
211
+ embed
212
+ });
213
+ case "flickr": return /* @__PURE__ */ jsx(FlickrEmbed, {
214
+ ...shared,
215
+ ...frame,
216
+ onError,
217
+ embed
218
+ });
219
+ }
220
+ }
221
+ export { SocialEmbed };
@@ -0,0 +1,6 @@
1
+ import { SoundCloudOptions } from "../core/plans/soundcloud.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type SoundCloudEmbedProps = EmbedSource & Omit<FrameProps, keyof SoundCloudOptions> & SoundCloudOptions;
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;
6
+ export type { SoundCloudOptions };