social-embeds 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +63 -51
  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 +38 -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 +108 -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 +125 -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 +59 -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.d.ts +1 -1
  124. package/dist/element.js +1 -1
  125. package/dist/index.d.ts +53 -344
  126. package/dist/index.js +30 -2575
  127. package/dist/loader/load-script.js +116 -0
  128. package/dist/loader/platform-scripts.js +89 -0
  129. package/dist/parser/frames.js +70 -0
  130. package/dist/parser/html.js +172 -0
  131. package/dist/parser/iframe.d.ts +24 -0
  132. package/dist/parser/iframe.js +151 -0
  133. package/dist/parser/lookup.js +20 -0
  134. package/dist/parser/match-url.d.ts +3 -0
  135. package/dist/parser/match-url.js +22 -0
  136. package/dist/parser/parse-embed.d.ts +7 -0
  137. package/dist/parser/parse-embed.js +69 -0
  138. package/dist/parser/platform.js +60 -0
  139. package/dist/parser/platforms/applemusic.js +45 -0
  140. package/dist/parser/platforms/applepodcasts.js +41 -0
  141. package/dist/parser/platforms/bluesky.js +64 -0
  142. package/dist/parser/platforms/dailymotion.js +57 -0
  143. package/dist/parser/platforms/facebook.js +181 -0
  144. package/dist/parser/platforms/flickr.js +134 -0
  145. package/dist/parser/platforms/giphy.js +68 -0
  146. package/dist/parser/platforms/imgur.js +107 -0
  147. package/dist/parser/platforms/index.js +62 -0
  148. package/dist/parser/platforms/instagram.js +59 -0
  149. package/dist/parser/platforms/kick.js +61 -0
  150. package/dist/parser/platforms/linkedin.js +42 -0
  151. package/dist/parser/platforms/pinterest.js +59 -0
  152. package/dist/parser/platforms/reddit.js +69 -0
  153. package/dist/parser/platforms/rumble.js +44 -0
  154. package/dist/parser/platforms/snapchat.js +87 -0
  155. package/dist/parser/platforms/soundcloud.js +128 -0
  156. package/dist/parser/platforms/spotify.js +51 -0
  157. package/dist/parser/platforms/strava.js +55 -0
  158. package/dist/parser/platforms/streamable.js +95 -0
  159. package/dist/parser/platforms/telegram.js +61 -0
  160. package/dist/parser/platforms/tenor.js +79 -0
  161. package/dist/parser/platforms/threads.js +51 -0
  162. package/dist/parser/platforms/tiktok.js +48 -0
  163. package/dist/parser/platforms/truthsocial.js +50 -0
  164. package/dist/parser/platforms/tumblr.js +72 -0
  165. package/dist/parser/platforms/twitch.js +128 -0
  166. package/dist/parser/platforms/vimeo.js +95 -0
  167. package/dist/parser/platforms/x.js +65 -0
  168. package/dist/parser/platforms/youtube.js +140 -0
  169. package/dist/parser/types.d.ts +14 -0
  170. package/dist/parser/url.js +41 -0
  171. package/dist/parser/verify.js +63 -0
  172. package/dist/parser.d.ts +4 -1
  173. package/dist/parser.js +4 -1
  174. package/package.json +1 -1
  175. package/dist/index-DrMHAkyG.d.ts +0 -46
  176. package/dist/parser-CovaPg5T.js +0 -2585
@@ -0,0 +1,169 @@
1
+ import { FRAME_TIMEOUT_MS } from "../core/timing.js";
2
+ import { frameStyle, srcWithSize, watchWidth } from "../core/layout.js";
3
+ import { useNearViewport } from "./hooks.js";
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ // src/components/iframe-embed.tsx
7
+ /** The plan's fields as `IframeEmbed` props. */
8
+ function planProps(plan) {
9
+ const { kind, fallbackHtml, fallbackImage, ...props } = plan;
10
+ return props;
11
+ }
12
+ /** The plan's verified fallback content as the placeholder, if it has any. */
13
+ function fallbackPlaceholder(plan) {
14
+ const { fallbackHtml, fallbackImage } = plan;
15
+ if (fallbackHtml === void 0) return void 0;
16
+ return fallbackImage ? /* @__PURE__ */ jsx("div", {
17
+ style: { height: "100%" },
18
+ dangerouslySetInnerHTML: { __html: fallbackHtml }
19
+ }) : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } });
20
+ }
21
+ const FILL = {
22
+ position: "absolute",
23
+ inset: 0
24
+ };
25
+ function IframeEmbed(props) {
26
+ return /* @__PURE__ */ jsx(Frame, { ...props }, props.src);
27
+ }
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 }) {
29
+ const frame = useRef(null);
30
+ const iframe = useRef(null);
31
+ const near = useNearViewport(frame, lazy);
32
+ const inView = useNearViewport(frame, !lazy);
33
+ const [loaded, setLoaded] = useState(false);
34
+ const [reportedHeight, setReportedHeight] = useState();
35
+ const [boxWidth, setBoxWidth] = useState();
36
+ const reported = useRef(false);
37
+ const callbacks = useRef({
38
+ onLoad,
39
+ onError
40
+ });
41
+ useEffect(() => {
42
+ callbacks.current = {
43
+ onLoad,
44
+ onError
45
+ };
46
+ });
47
+ const report = useCallback(() => {
48
+ setLoaded(true);
49
+ if (reported.current) return;
50
+ reported.current = true;
51
+ callbacks.current.onLoad?.();
52
+ }, []);
53
+ useEffect(() => {
54
+ 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));
67
+ report();
68
+ };
69
+ window.addEventListener("message", listen);
70
+ return () => {
71
+ window.removeEventListener("message", listen);
72
+ };
73
+ }, [
74
+ near,
75
+ messageHeight,
76
+ report
77
+ ]);
78
+ useEffect(() => {
79
+ const element = frame.current;
80
+ if (!near || !sizeInSrc || !element) return;
81
+ return watchWidth(element, setBoxWidth);
82
+ }, [near, sizeInSrc]);
83
+ useEffect(() => {
84
+ if (!near || !inView) return;
85
+ const failure = messageHeight ? "did not report its height" : "did not load";
86
+ const timer = setTimeout(() => {
87
+ if (reported.current) return;
88
+ setLoaded(true);
89
+ callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} ${failure}`));
90
+ }, FRAME_TIMEOUT_MS);
91
+ return () => {
92
+ clearTimeout(timer);
93
+ };
94
+ }, [
95
+ near,
96
+ inView,
97
+ messageHeight,
98
+ title
99
+ ]);
100
+ const wrapper = {
101
+ ...frameStyle({
102
+ kind: "iframe",
103
+ src,
104
+ title,
105
+ allow,
106
+ ratio,
107
+ size,
108
+ messageHeight,
109
+ startHeight,
110
+ borderRadius
111
+ }, {
112
+ width,
113
+ maxWidth,
114
+ height,
115
+ maxHeight
116
+ }, reportedHeight),
117
+ ...style
118
+ };
119
+ const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
120
+ src,
121
+ ratio,
122
+ size
123
+ }, boxWidth);
124
+ return /* @__PURE__ */ jsx("div", {
125
+ ...rest,
126
+ style: wrapper,
127
+ children: /* @__PURE__ */ jsxs("div", {
128
+ ref: frame,
129
+ style: FILL,
130
+ children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
131
+ ref: iframe,
132
+ src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
133
+ title,
134
+ allow,
135
+ allowFullScreen: allowFullscreen,
136
+ referrerPolicy,
137
+ scrolling,
138
+ sandbox,
139
+ style: {
140
+ display: "block",
141
+ width: "100%",
142
+ height: "100%",
143
+ border: 0
144
+ },
145
+ onLoad: () => {
146
+ if (!messageHeight) report();
147
+ }
148
+ }, sizeInSrc ? frameSrc : void 0), !loaded && /* @__PURE__ */ jsx("div", {
149
+ style: FILL,
150
+ children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
151
+ })]
152
+ })
153
+ });
154
+ }
155
+ function withHost(src, name) {
156
+ return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
157
+ }
158
+ function Skeleton({ minHeight }) {
159
+ return /* @__PURE__ */ jsx("div", {
160
+ "aria-hidden": "true",
161
+ style: {
162
+ width: "100%",
163
+ height: "100%",
164
+ minHeight,
165
+ background: "rgba(128, 128, 128, 0.12)"
166
+ }
167
+ });
168
+ }
169
+ export { IframeEmbed, Skeleton, fallbackPlaceholder, planProps };
@@ -0,0 +1,6 @@
1
+ import { ImgurOptions } from "../core/plans/imgur.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type ImgurEmbedProps = EmbedSource & Omit<SharedProps, keyof ImgurOptions> & ImgurOptions;
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;
6
+ export type { ImgurOptions };
@@ -0,0 +1,23 @@
1
+ import { imgurPlan } from "../core/plans/imgur.js";
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";
7
+ // src/components/imgur-embed.tsx
8
+ /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
9
+ 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
+ });
22
+ }
23
+ export { ImgurEmbed };
@@ -0,0 +1,5 @@
1
+ import { InstagramOptions } from "../core/plans/instagram.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
4
+ export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").JSX.Element | null;
5
+ export type { InstagramOptions };
@@ -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,108 @@
1
+ import { FinalError } from "../core/drivers.js";
2
+ import { postLinkText, postUrl } from "../core/post-link.js";
3
+ import { RENDER_TIMEOUT_MS, RETRY_DELAY_MS } from "../core/timing.js";
4
+ import { useNearViewport } from "./hooks.js";
5
+ import { Skeleton } from "./iframe-embed.js";
6
+ import { useEffect, useRef, useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ // src/components/script-embed.tsx
9
+ const LAYER = { width: "100%" };
10
+ function toError(error) {
11
+ return error instanceof Error ? error : new Error(String(error));
12
+ }
13
+ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "100%", maxWidth, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
14
+ const container = useRef(null);
15
+ const near = useNearViewport(container, lazy);
16
+ const [rendered, setRendered] = useState(false);
17
+ const [failure, setFailure] = useState();
18
+ const done = useRef(false);
19
+ const callbacks = useRef({
20
+ onLoad,
21
+ onError
22
+ });
23
+ useEffect(() => {
24
+ callbacks.current = {
25
+ onLoad,
26
+ onError
27
+ };
28
+ });
29
+ useEffect(() => {
30
+ const element = container.current;
31
+ if (!near || !element || done.current) return;
32
+ let cancelled = false;
33
+ let timer;
34
+ let stop = () => {};
35
+ const href = postUrl(element);
36
+ const finish = () => {
37
+ if (cancelled || done.current) return;
38
+ done.current = true;
39
+ clearTimeout(timer);
40
+ stop();
41
+ setRendered(true);
42
+ callbacks.current.onLoad?.();
43
+ };
44
+ const fail = (error) => {
45
+ setFailure({ href });
46
+ callbacks.current.onError?.(error);
47
+ };
48
+ const retryOrFail = (number, error) => {
49
+ if (cancelled || done.current) return;
50
+ stop();
51
+ stop = () => {};
52
+ if (number >= 3 || error instanceof FinalError) {
53
+ fail(error);
54
+ return;
55
+ }
56
+ timer = setTimeout(() => {
57
+ attempt(number + 1);
58
+ }, RETRY_DELAY_MS * 2 ** (number - 1));
59
+ };
60
+ const attempt = (number) => {
61
+ if (cancelled || done.current) return;
62
+ try {
63
+ stop = driver.render(element, finish);
64
+ } catch (error) {
65
+ retryOrFail(number, toError(error));
66
+ return;
67
+ }
68
+ timer = setTimeout(() => {
69
+ retryOrFail(number, /* @__PURE__ */ new Error(`social-embeds: the ${label} embed did not render`));
70
+ }, RENDER_TIMEOUT_MS);
71
+ };
72
+ driver.load().then(() => {
73
+ attempt(1);
74
+ }, (error) => {
75
+ if (!cancelled) fail(toError(error));
76
+ });
77
+ return () => {
78
+ cancelled = true;
79
+ clearTimeout(timer);
80
+ stop();
81
+ };
82
+ }, [
83
+ near,
84
+ driver,
85
+ label
86
+ ]);
87
+ const wrapper = {
88
+ width,
89
+ maxWidth,
90
+ ...style
91
+ };
92
+ return /* @__PURE__ */ jsx("div", {
93
+ ...rest,
94
+ style: wrapper,
95
+ children: /* @__PURE__ */ jsxs("div", {
96
+ style: LAYER,
97
+ children: [/* @__PURE__ */ jsx("div", {
98
+ ref: container,
99
+ suppressHydrationWarning: true,
100
+ dangerouslySetInnerHTML: { __html: markup }
101
+ }), !hasFallback && !rendered && (failure ? failure.href !== void 0 && /* @__PURE__ */ jsx("a", {
102
+ href: failure.href,
103
+ children: postLinkText(label)
104
+ }) : placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
105
+ })
106
+ });
107
+ }
108
+ 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 {};