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
package/dist/index.js CHANGED
@@ -1,2577 +1,32 @@
1
1
  "use client";
2
- import { a as platforms, c as escapeAttribute, i as parseIframe, l as parseHtml, n as matchUrl, o as x$1, r as checkIframe, s as parseUrl, t as parseEmbed, u as rebuild } from "./parser-CovaPg5T.js";
3
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- // src/parser/lookup.ts
6
- const BLUESKY_HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
7
- const HANDLE_POST = /^\/profile\/([^/]{1,253})\/post\/[A-Za-z0-9._~:-]{1,512}\/?$/;
8
- const HANDLE = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
9
- const RUMBLE_HOSTS = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
10
- const RUMBLE_PAGE = /^\/v[a-z0-9]{1,12}-[^/]{1,300}\.html$/;
11
- /**
12
- * The platform of a post URL that only a network lookup could turn into an embed: a Bluesky
13
- * URL with a handle instead of a DID, or a Rumble page URL. Internal; the parser entry does not export it.
14
- */
15
- function needsLookup(url) {
16
- const parsed = typeof url === "string" ? parseUrl(url) : null;
17
- if (!parsed) return null;
18
- if (RUMBLE_HOSTS.has(parsed.host)) return RUMBLE_PAGE.test(parsed.path) ? "rumble" : null;
19
- if (!BLUESKY_HOSTS.has(parsed.host)) return null;
20
- const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
21
- return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
22
- }
23
- // src/parser/verify.ts
24
- const SHAPES = {
25
- x: ["post sdk"],
26
- instagram: ["post sdk"],
27
- threads: ["post sdk"],
28
- facebook: [
29
- "post sdk",
30
- "video sdk",
31
- "video iframe"
32
- ],
33
- tiktok: ["video iframe"],
34
- youtube: ["video iframe"],
35
- telegram: ["post iframe"],
36
- snapchat: ["post iframe", "video iframe"],
37
- linkedin: ["post iframe"],
38
- reddit: ["post iframe"],
39
- pinterest: ["post sdk"],
40
- spotify: ["post iframe", "video iframe"],
41
- vimeo: ["video iframe"],
42
- twitch: ["video iframe"],
43
- dailymotion: ["video iframe"],
44
- bluesky: ["post iframe"],
45
- soundcloud: ["post iframe"],
46
- applemusic: ["post iframe"],
47
- applepodcasts: ["post iframe"],
48
- tumblr: ["post iframe"],
49
- kick: ["video iframe"],
50
- giphy: ["video iframe"],
51
- truthsocial: ["post iframe"],
52
- imgur: ["post iframe"],
53
- tenor: ["video iframe"],
54
- streamable: ["video iframe"],
55
- strava: ["post iframe"],
56
- flickr: ["post iframe"],
57
- rumble: ["video iframe"]
58
- };
59
- /**
60
- * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
61
- * into the page: only what this parser itself produces passes (docs/decisions.md D35).
62
- */
63
- function verifyEmbed(embed) {
64
- const matched = matchUrl(embed.url);
65
- if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
66
- if (matched.url !== embed.url) return null;
67
- if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
68
- if (embed.fallbackHtml === void 0) return embed;
69
- if (trustedFallback(embed, embed.fallbackHtml)) return embed;
70
- const withoutFallback = { ...embed };
71
- delete withoutFallback.fallbackHtml;
72
- return withoutFallback;
73
- }
74
- function trustedFallback(embed, fallbackHtml) {
75
- const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
76
- const nodes = parseHtml(fallbackHtml);
77
- if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
78
- if (embed.platform !== "x") return true;
79
- const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
80
- return root?.type === "element" && x$1.parse(root)?.id === embed.id;
81
- }
82
- // src/core/resolve.ts
83
- const NAMES = {
84
- x: "X",
85
- instagram: "Instagram",
86
- facebook: "Facebook",
87
- threads: "Threads",
88
- tiktok: "TikTok",
89
- youtube: "YouTube",
90
- telegram: "Telegram",
91
- snapchat: "Snapchat",
92
- linkedin: "LinkedIn",
93
- reddit: "Reddit",
94
- pinterest: "Pinterest",
95
- spotify: "Spotify",
96
- vimeo: "Vimeo",
97
- twitch: "Twitch",
98
- dailymotion: "Dailymotion",
99
- bluesky: "Bluesky",
100
- soundcloud: "SoundCloud",
101
- applemusic: "Apple Music",
102
- applepodcasts: "Apple Podcasts",
103
- tumblr: "Tumblr",
104
- kick: "Kick",
105
- giphy: "Giphy",
106
- truthsocial: "Truth Social",
107
- imgur: "Imgur",
108
- tenor: "Tenor",
109
- streamable: "Streamable",
110
- strava: "Strava",
111
- flickr: "Flickr",
112
- rumble: "Rumble"
113
- };
114
- /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
115
- function lookupMessage(platform) {
116
- return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
117
- }
118
- function resolveEmbed(url, given, platform) {
119
- const embed = given ?? (url === void 0 ? null : matchUrl(url));
120
- if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
121
- if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
122
- if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
123
- const verified = verifyEmbed(embed);
124
- if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
125
- return { embed: verified };
126
- }
127
- /** The message `<SocialEmbed>` reports when its input matches no platform. */
128
- function sourceError(source) {
129
- if ("html" in source) return "social-embeds: unrecognised embed code";
130
- const lookup = needsLookup(source.url);
131
- return lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${source.url}`;
132
- }
133
- // src/core/plans/apple.ts
134
- const ALLOW$9 = "autoplay *; encrypted-media *; fullscreen *; clipboard-write";
135
- const SANDBOX$1 = "allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation";
136
- const SINGLE_HEIGHT = 175;
137
- const EPISODE_HEIGHT = 160;
138
- const FULL_HEIGHT$1 = 450;
139
- /** A fixed height: the embed code's, else 175px for a song and 450px for the rest. */
140
- function appleMusicPlan(embed) {
141
- const path = embed.url.slice(23);
142
- const single = path.includes("/song/") || path.includes("?i=");
143
- return {
144
- kind: "iframe",
145
- src: `https://embed.music.apple.com${path}`,
146
- title: "Apple Music player",
147
- allow: ALLOW$9,
148
- sandbox: SANDBOX$1,
149
- ratio: {
150
- width: 16,
151
- height: 9
152
- },
153
- height: embed.size?.height ?? (single ? SINGLE_HEIGHT : FULL_HEIGHT$1),
154
- maxWidth: 660,
155
- borderRadius: 10
156
- };
157
- }
158
- /** A fixed height: the embed code's, else 160px for an episode and 450px for a show. */
159
- function applePodcastsPlan(embed) {
160
- const path = embed.url.slice(26);
161
- return {
162
- kind: "iframe",
163
- src: `https://embed.podcasts.apple.com${path}`,
164
- title: "Apple Podcasts player",
165
- allow: ALLOW$9,
166
- sandbox: SANDBOX$1,
167
- ratio: {
168
- width: 16,
169
- height: 9
170
- },
171
- height: embed.size?.height ?? (path.includes("?i=") ? EPISODE_HEIGHT : FULL_HEIGHT$1),
172
- maxWidth: 640,
173
- borderRadius: 12
174
- };
175
- }
176
- // src/core/timing.ts
177
- const ROOT_MARGIN = "200px 0px";
178
- const FRAME_TIMEOUT_MS = 15e3;
179
- const RENDER_TIMEOUT_MS = 15e3;
180
- const RETRY_DELAY_MS$1 = 1e3;
181
- // src/components/hooks.ts
182
- /** False on the server and in the first client render, so the markup matches on hydration. */
183
- function useNearViewport(ref, lazy) {
184
- const [near, setNear] = useState(false);
185
- useEffect(() => {
186
- const element = ref.current;
187
- if (!lazy || !element || typeof IntersectionObserver === "undefined") {
188
- setNear(true);
189
- return;
190
- }
191
- const observer = new IntersectionObserver((entries) => {
192
- if (entries.some((entry) => entry.isIntersecting)) {
193
- setNear(true);
194
- observer.disconnect();
195
- }
196
- }, { rootMargin: ROOT_MARGIN });
197
- observer.observe(element);
198
- return () => {
199
- observer.disconnect();
200
- };
201
- }, [ref, lazy]);
202
- return near;
203
- }
204
- /** Calls `onError` from an effect, once per distinct message. */
205
- function useReportError(message, onError) {
206
- const latest = useRef(onError);
207
- useEffect(() => {
208
- latest.current = onError;
209
- });
210
- useEffect(() => {
211
- if (message !== void 0) latest.current?.(new Error(message));
212
- }, [message]);
213
- }
214
- // src/core/layout.ts
215
- function aspectOf(plan) {
216
- return {
217
- width: plan.size?.width ?? plan.ratio.width,
218
- height: plan.size?.height ?? plan.ratio.height
219
- };
220
- }
221
- /** The iframe wrapper's style, without the host's `style`. Numbers are pixels. */
222
- function frameStyle(plan, layout, reportedHeight) {
223
- const { width = "100%", maxHeight } = layout;
224
- const height = layout.height ?? plan.height;
225
- const maxWidth = layout.maxWidth ?? plan.maxWidth;
226
- const { width: aspectWidth, height: aspectHeight } = aspectOf(plan);
227
- const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
228
- return {
229
- position: "relative",
230
- width,
231
- maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
232
- ...plan.messageHeight ? { height: reportedHeight ?? plan.startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
233
- height,
234
- maxHeight
235
- },
236
- ...plan.borderRadius === void 0 ? {} : {
237
- borderRadius: plan.borderRadius,
238
- overflow: "hidden"
239
- }
240
- };
241
- }
242
- /** `src` for a plan with `sizeInSrc`, in a box `width` pixels wide. */
243
- function srcWithSize(plan, width) {
244
- const aspect = aspectOf(plan);
245
- const height = Math.round(width * aspect.height / aspect.width);
246
- const query = plan.src.indexOf("?");
247
- const path = query === -1 ? plan.src : plan.src.slice(0, query);
248
- const rest = query === -1 ? "" : `&${plan.src.slice(query + 1)}`;
249
- return `${path}?width=${String(width)}&height=${String(height)}${rest}`;
250
- }
251
- /**
252
- * Calls `onWidth` with the element's rounded width once it has one, then with each new width
253
- * that has held for WIDTH_SETTLE_MS, so a resize rebuilds the frame once.
254
- */
255
- function watchWidth(element, onWidth) {
256
- let last;
257
- let timer;
258
- const take = (width) => {
259
- const rounded = Math.round(width);
260
- if (rounded <= 0) return;
261
- clearTimeout(timer);
262
- if (rounded === last) return;
263
- if (last === void 0) {
264
- last = rounded;
265
- onWidth(rounded);
266
- return;
267
- }
268
- timer = setTimeout(() => {
269
- last = rounded;
270
- onWidth(rounded);
271
- }, 200);
272
- };
273
- if (typeof ResizeObserver === "undefined") {
274
- take(element.getBoundingClientRect().width);
275
- return () => {};
276
- }
277
- const observer = new ResizeObserver((entries) => {
278
- for (const entry of entries) take(entry.contentRect.width);
279
- });
280
- observer.observe(element);
281
- return () => {
282
- observer.disconnect();
283
- clearTimeout(timer);
284
- };
285
- }
286
- // src/components/iframe-embed.tsx
287
- /** The plan's fields as `IframeEmbed` props. */
288
- function planProps(plan) {
289
- const { kind, fallbackHtml, fallbackImage, ...props } = plan;
290
- return props;
291
- }
292
- /** The plan's verified fallback content as the placeholder, if it has any. */
293
- function fallbackPlaceholder(plan) {
294
- const { fallbackHtml, fallbackImage } = plan;
295
- if (fallbackHtml === void 0) return void 0;
296
- return fallbackImage ? /* @__PURE__ */ jsx("div", {
297
- style: { height: "100%" },
298
- dangerouslySetInnerHTML: { __html: fallbackHtml }
299
- }) : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } });
300
- }
301
- const FILL = {
302
- position: "absolute",
303
- inset: 0
304
- };
305
- function IframeEmbed({ 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 }) {
306
- const frame = useRef(null);
307
- const iframe = useRef(null);
308
- const near = useNearViewport(frame, lazy);
309
- const inView = useNearViewport(frame, !lazy);
310
- const [loaded, setLoaded] = useState(false);
311
- const [reportedHeight, setReportedHeight] = useState();
312
- const [boxWidth, setBoxWidth] = useState();
313
- const reported = useRef(false);
314
- const callbacks = useRef({
315
- onLoad,
316
- onError
317
- });
318
- useEffect(() => {
319
- callbacks.current = {
320
- onLoad,
321
- onError
322
- };
323
- });
324
- const report = useCallback(() => {
325
- setLoaded(true);
326
- if (reported.current) return;
327
- reported.current = true;
328
- callbacks.current.onLoad?.();
329
- }, []);
330
- useEffect(() => {
331
- if (!near || !messageHeight) return;
332
- const { origin, read } = messageHeight;
333
- const listen = (event) => {
334
- if (event.origin !== origin) return;
335
- if (!iframe.current || event.source !== iframe.current.contentWindow) return;
336
- let value;
337
- try {
338
- value = read(event.data);
339
- } catch {
340
- return;
341
- }
342
- if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
343
- setReportedHeight(Math.ceil(value));
344
- report();
345
- };
346
- window.addEventListener("message", listen);
347
- return () => {
348
- window.removeEventListener("message", listen);
349
- };
350
- }, [
351
- near,
352
- messageHeight,
353
- report
354
- ]);
355
- useEffect(() => {
356
- const element = frame.current;
357
- if (!near || !sizeInSrc || !element) return;
358
- return watchWidth(element, setBoxWidth);
359
- }, [near, sizeInSrc]);
360
- useEffect(() => {
361
- if (!near || !inView) return;
362
- const failure = messageHeight ? "did not report its height" : "did not load";
363
- const timer = setTimeout(() => {
364
- if (reported.current) return;
365
- setLoaded(true);
366
- callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} ${failure}`));
367
- }, FRAME_TIMEOUT_MS);
368
- return () => {
369
- clearTimeout(timer);
370
- };
371
- }, [
372
- near,
373
- inView,
374
- messageHeight,
375
- title
376
- ]);
377
- const wrapper = {
378
- ...frameStyle({
379
- kind: "iframe",
380
- src,
381
- title,
382
- allow,
383
- ratio,
384
- size,
385
- messageHeight,
386
- startHeight,
387
- borderRadius
388
- }, {
389
- width,
390
- maxWidth,
391
- height,
392
- maxHeight
393
- }, reportedHeight),
394
- ...style
395
- };
396
- const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
397
- src,
398
- ratio,
399
- size
400
- }, boxWidth);
401
- return /* @__PURE__ */ jsx("div", {
402
- ...rest,
403
- style: wrapper,
404
- children: /* @__PURE__ */ jsxs("div", {
405
- ref: frame,
406
- style: FILL,
407
- children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
408
- ref: iframe,
409
- src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
410
- title,
411
- allow,
412
- allowFullScreen: allowFullscreen,
413
- referrerPolicy,
414
- scrolling,
415
- sandbox,
416
- style: {
417
- display: "block",
418
- width: "100%",
419
- height: "100%",
420
- border: 0
421
- },
422
- onLoad: () => {
423
- if (!messageHeight) report();
424
- }
425
- }, sizeInSrc ? frameSrc : void 0), !loaded && /* @__PURE__ */ jsx("div", {
426
- style: FILL,
427
- children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
428
- })]
429
- })
430
- });
431
- }
432
- function withHost(src, name) {
433
- return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
434
- }
435
- function Skeleton({ minHeight }) {
436
- return /* @__PURE__ */ jsx("div", {
437
- "aria-hidden": "true",
438
- style: {
439
- width: "100%",
440
- height: "100%",
441
- minHeight,
442
- background: "rgba(128, 128, 128, 0.12)"
443
- }
444
- });
445
- }
446
- // src/core/params.ts
447
- /**
448
- * Security: options are not verified (docs/decisions.md D68). Keys that choose the content
449
- * come only from the verified url and id.
450
- */
451
- function optionsWithout(options, reserved) {
452
- return Object.entries(options).filter(([key]) => !reserved.includes(key.toLowerCase()));
453
- }
454
- /** Later entries replace earlier ones with the same name. */
455
- function query(...sources) {
456
- const params = /* @__PURE__ */ new Map();
457
- for (const source of sources) for (const [key, value] of source ?? []) params.set(key, String(value));
458
- const pairs = [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
459
- return pairs.length > 0 ? `?${pairs.join("&")}` : "";
460
- }
461
- /** Player parameters take 0 and 1, so booleans become numbers. */
462
- function playerParams(props, names) {
463
- const params = [];
464
- for (const [prop, name] of Object.entries(names)) {
465
- const value = props[prop];
466
- if (typeof value === "boolean") params.push([name, value ? 1 : 0]);
467
- else if (typeof value === "string" || typeof value === "number") params.push([name, value]);
468
- }
469
- return params;
470
- }
471
- // src/components/apple-embed.tsx
472
- /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
473
- function AppleMusicEmbed(props) {
474
- const { url, embed: given, onError, height, maxWidth, ...frame } = props;
475
- const { embed, error } = resolveEmbed(url, given, "applemusic");
476
- const plan = embed ? appleMusicPlan(embed) : void 0;
477
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
478
- if (plan?.kind !== "iframe") return null;
479
- return /* @__PURE__ */ jsx(IframeEmbed, {
480
- ...frame,
481
- ...planProps(plan),
482
- onError,
483
- maxWidth: maxWidth ?? plan.maxWidth,
484
- height: height ?? plan.height
485
- });
486
- }
487
- /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
488
- function ApplePodcastsEmbed(props) {
489
- const { url, embed: given, onError, height, maxWidth, ...frame } = props;
490
- const { embed, error } = resolveEmbed(url, given, "applepodcasts");
491
- const plan = embed ? applePodcastsPlan(embed) : void 0;
492
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
493
- if (plan?.kind !== "iframe") return null;
494
- return /* @__PURE__ */ jsx(IframeEmbed, {
495
- ...frame,
496
- ...planProps(plan),
497
- onError,
498
- maxWidth: maxWidth ?? plan.maxWidth,
499
- height: height ?? plan.height
500
- });
501
- }
502
- // src/core/plans/bluesky.ts
503
- /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
504
- const BLUESKY_HEIGHT = {
505
- origin: "https://embed.bsky.app",
506
- read(data) {
507
- const height = data?.height;
508
- return typeof height === "number" ? height : void 0;
509
- }
510
- };
511
- /**
512
- * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
513
- * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
514
- * render: a handle URL needs a lookup, and `onError` says so.
515
- */
516
- function blueskyPlan(embed, options) {
517
- const mode = options.colorMode ?? embed.options.colorMode;
518
- return {
519
- kind: "iframe",
520
- src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
521
- title: "Bluesky post",
522
- allow: "",
523
- scrolling: "no",
524
- ratio: {
525
- width: 1,
526
- height: 1
527
- },
528
- messageHeight: BLUESKY_HEIGHT,
529
- startHeight: 300,
530
- maxWidth: 600,
531
- fallbackHtml: embed.fallbackHtml
532
- };
533
- }
534
- // src/components/bluesky-embed.tsx
535
- /**
536
- * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
537
- * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
538
- * render: a handle URL needs a lookup, and `onError` says so.
539
- */
540
- function BlueskyEmbed(props) {
541
- const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
542
- const { embed, error } = resolveEmbed(url, given, "bluesky");
543
- const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
544
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
545
- if (plan?.kind !== "iframe") return null;
546
- return /* @__PURE__ */ jsx(IframeEmbed, {
547
- ...shared,
548
- ...planProps(plan),
549
- onError,
550
- maxWidth: maxWidth ?? plan.maxWidth,
551
- placeholder: placeholder ?? fallbackPlaceholder(plan)
552
- });
553
- }
554
- // src/core/plans/dailymotion.ts
555
- const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
556
- const ALLOW$8 = "autoplay; fullscreen; picture-in-picture; web-share";
557
- /**
558
- * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
559
- * option, never another account's (docs/decisions.md D63).
560
- */
561
- function dailymotionPlan(embed, options) {
562
- const { playerId, mute, startTime, loop } = options;
563
- const { playerId: parsedPlayer, ...parsed } = embed.options;
564
- const player = playerId ?? parsedPlayer;
565
- if (player === void 0) return {
566
- kind: "error",
567
- message: "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed"
568
- };
569
- if (typeof player !== "string" || !PLAYER_ID.test(player)) return {
570
- kind: "error",
571
- message: `social-embeds: not a Dailymotion Player ID: ${String(player)}`
572
- };
573
- const params = [];
574
- if (mute !== void 0) params.push(["mute", String(mute)]);
575
- if (startTime !== void 0) params.push(["startTime", startTime]);
576
- if (loop !== void 0) params.push(["loop", String(loop)]);
577
- return {
578
- kind: "iframe",
579
- src: `https://geo.dailymotion.com/player/${player}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
580
- title: "Dailymotion video player",
581
- allow: ALLOW$8,
582
- ratio: {
583
- width: 16,
584
- height: 9
585
- },
586
- size: embed.size
587
- };
588
- }
589
- // src/components/dailymotion-embed.tsx
590
- /**
591
- * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
592
- * prop, never another account's (docs/decisions.md D63).
593
- */
594
- function DailymotionEmbed(props) {
595
- const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
596
- const { embed, error } = resolveEmbed(url, given, "dailymotion");
597
- const plan = embed ? dailymotionPlan(embed, {
598
- playerId,
599
- mute,
600
- startTime,
601
- loop
602
- }) : void 0;
603
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
604
- if (plan?.kind !== "iframe") return null;
605
- return /* @__PURE__ */ jsx(IframeEmbed, {
606
- ...frame,
607
- ...planProps(plan),
608
- maxWidth: maxWidth ?? plan.maxWidth
609
- });
610
- }
611
- // src/loader/load-script.ts
612
- const ATTEMPTS = 3;
613
- const RETRY_DELAY_MS = 1e3;
614
- const TIMEOUT_MS = 15e3;
615
- const POLL_MS = 50;
616
- const loading = /* @__PURE__ */ new Map();
617
- function loadScript(script) {
618
- if (typeof document === "undefined") return Promise.reject(/* @__PURE__ */ new Error("social-embeds: platform scripts load only in the browser"));
619
- let promise = loading.get(script.key);
620
- if (!promise) {
621
- promise = load(script).catch((error) => {
622
- loading.delete(script.key);
623
- throw error;
624
- });
625
- loading.set(script.key, promise);
626
- }
627
- return promise;
628
- }
629
- async function load(script) {
630
- if (!script.isPresent()) await ([...document.querySelectorAll("script[src]")].some((element) => script.isOwn(element.src)) ? poll(script) : add(script));
631
- await script.whenPresent?.();
632
- }
633
- /** The browser reported the script as failed; its tag has been removed. */
634
- var LoadError = class extends Error {};
635
- async function add(script) {
636
- const ready = script.readyCallback?.();
637
- for (let attempt = 1;; attempt++) try {
638
- const element = await insert(script);
639
- if (attempt >= ATTEMPTS || !script.skipped?.()) break;
640
- element.remove();
641
- } catch (error) {
642
- if (!(error instanceof LoadError) || attempt >= ATTEMPTS) throw error;
643
- await delay(RETRY_DELAY_MS * 2 ** (attempt - 1));
644
- }
645
- await (ready ? timeout(ready, `${script.url} did not report ready`) : poll(script));
646
- }
647
- async function insert(script) {
648
- const restore = script.prepare?.();
649
- const element = document.createElement("script");
650
- const loaded = new Promise((resolve, reject) => {
651
- element.src = script.url;
652
- element.async = true;
653
- if (script.crossOrigin) element.crossOrigin = script.crossOrigin;
654
- element.addEventListener("load", () => {
655
- resolve();
656
- });
657
- element.addEventListener("error", () => {
658
- element.remove();
659
- reject(new LoadError(`social-embeds: could not load ${script.url}`));
660
- });
661
- document.head.appendChild(element);
662
- });
663
- try {
664
- await timeout(loaded, `${script.url} did not load`);
665
- } finally {
666
- restore?.();
667
- }
668
- return element;
669
- }
670
- function poll(script) {
671
- return new Promise((resolve, reject) => {
672
- const deadline = Date.now() + TIMEOUT_MS;
673
- const check = () => {
674
- if (script.isPresent()) resolve();
675
- else if (Date.now() >= deadline) reject(/* @__PURE__ */ new Error(`social-embeds: ${script.url} did not initialise`));
676
- else setTimeout(check, POLL_MS);
677
- };
678
- check();
679
- });
680
- }
681
- function timeout(promise, message) {
682
- return new Promise((resolve, reject) => {
683
- const timer = setTimeout(() => {
684
- reject(/* @__PURE__ */ new Error(`social-embeds: ${message}`));
685
- }, TIMEOUT_MS);
686
- promise.then(() => {
687
- clearTimeout(timer);
688
- resolve();
689
- }, (error) => {
690
- clearTimeout(timer);
691
- reject(error instanceof Error ? error : new Error(String(error)));
692
- });
693
- });
694
- }
695
- function delay(ms) {
696
- return new Promise((resolve) => setTimeout(resolve, ms));
697
- }
698
- // src/loader/platform-scripts.ts
699
- const globals$1 = () => window;
700
- /** The SDK refuses to parse without a Graph API version (docs/decisions.md D26). */
701
- const FACEBOOK_SDK_VERSION = "v26.0";
702
- const LOCALE = /^[a-z]{2,3}_[A-Z]{2}$/;
703
- /** Instagram and Threads share `instgrm.Embeds`; each registers its name when loaded. */
704
- function embedSdkRegistered(name) {
705
- return () => {
706
- const embeds = globals$1().instgrm?.Embeds;
707
- return embeds?.registeredEmbedSDKs?.[name] === true && typeof embeds.process === "function";
708
- };
709
- }
710
- const x = {
711
- key: "x",
712
- url: "https://platform.twitter.com/widgets.js",
713
- isOwn: (src) => /^https?:\/\/platform\.(?:twitter|x)\.com\/widgets\.js(?:[?#]|$)/.test(src),
714
- isPresent: () => typeof globals$1().twttr?.widgets?.load === "function",
715
- whenPresent: () => new Promise((resolve) => {
716
- const ready = globals$1().twttr?.ready;
717
- if (ready) ready(() => {
718
- resolve();
719
- });
720
- else resolve();
721
- })
722
- };
723
- function besideFacebookSdk() {
724
- const fb = globals$1().FB;
725
- if (!fb || fb.__buffer) return () => {};
726
- fb.__buffer = true;
727
- return () => {
728
- delete fb.__buffer;
729
- };
730
- }
731
- function skippedBesideFacebookSdk(name) {
732
- const registered = embedSdkRegistered(name);
733
- return () => {
734
- const fb = globals$1().FB;
735
- return !registered() && fb !== void 0 && !fb.__buffer;
736
- };
737
- }
738
- const instagram = {
739
- key: "instagram",
740
- url: "https://www.instagram.com/embed.js",
741
- isOwn: (src) => /^https?:\/\/www\.instagram\.com\/embed\.js(?:[?#]|$)/.test(src),
742
- isPresent: embedSdkRegistered("instagram"),
743
- prepare: besideFacebookSdk,
744
- skipped: skippedBesideFacebookSdk("instagram")
745
- };
746
- const threads = {
747
- key: "threads",
748
- url: "https://www.threads.com/embed.js",
749
- isOwn: (src) => /^https?:\/\/www\.threads\.(?:com|net)\/embed\.js(?:[?#]|$)/.test(src),
750
- isPresent: embedSdkRegistered("threads"),
751
- prepare: besideFacebookSdk,
752
- skipped: skippedBesideFacebookSdk("threads")
753
- };
754
- function facebook(locale) {
755
- return {
756
- key: "facebook",
757
- url: `https://connect.facebook.net/${locale}/sdk.js#xfbml=0&version=${FACEBOOK_SDK_VERSION}`,
758
- crossOrigin: "anonymous",
759
- isOwn: (src) => /^https?:\/\/connect\.facebook\.net\/[a-z]{2,3}_[A-Z]{2}\/(?:sdk(?:\/debug)?|all)\.js(?:[?#]|$)/.test(src),
760
- isPresent: () => typeof globals$1().FB?.XFBML?.parse === "function",
761
- readyCallback: () => new Promise((resolve) => {
762
- const previous = globals$1().fbAsyncInit;
763
- globals$1().fbAsyncInit = () => {
764
- previous?.();
765
- resolve();
766
- };
767
- })
768
- };
769
- }
770
- const pinterest = {
771
- key: "pinterest",
772
- url: "https://assets.pinterest.com/js/pinit_main.js",
773
- isOwn: (src) => /^https?:\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js(?:[?#]|$)/.test(src),
774
- isPresent: () => typeof globals$1().PinUtils?.build === "function"
775
- };
776
- function loadPlatformScript(platform, { locale = "en_US" } = {}) {
777
- switch (platform) {
778
- case "x": return loadScript(x);
779
- case "instagram": return loadScript(instagram);
780
- case "threads": return loadScript(threads);
781
- case "pinterest": return loadScript(pinterest);
782
- case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
783
- }
784
- }
785
- // src/core/drivers.ts
786
- const globals = () => window;
787
- function watch(container, rendered, done) {
788
- if (rendered(container)) {
789
- done();
790
- return () => {};
791
- }
792
- const observer = new MutationObserver(() => {
793
- if (!rendered(container)) return;
794
- observer.disconnect();
795
- done();
796
- });
797
- observer.observe(container, {
798
- subtree: true,
799
- childList: true,
800
- attributes: true,
801
- attributeFilter: [
802
- "class",
803
- "style",
804
- "height"
805
- ]
806
- });
807
- return () => {
808
- observer.disconnect();
809
- };
810
- }
811
- function reveal(container, className) {
812
- const blockquote = container.querySelector("blockquote");
813
- if (blockquote && !blockquote.hasAttribute("class")) blockquote.classList.add(className);
814
- }
815
- function hasSizedIframe(container) {
816
- return [...container.querySelectorAll("iframe")].some((iframe) => Number.parseFloat(iframe.style.height) > 0);
817
- }
818
- const xDriver = {
819
- load: () => loadPlatformScript("x"),
820
- render(container, done) {
821
- const twttr = globals().twttr;
822
- const onRendered = (event) => {
823
- if (event.target instanceof Node && container.contains(event.target)) done();
824
- };
825
- twttr?.events?.bind?.("rendered", onRendered);
826
- const stop = watch(container, hasSizedIframe, done);
827
- reveal(container, "twitter-tweet");
828
- twttr?.widgets?.load?.(container);
829
- return () => {
830
- twttr?.events?.unbind?.("rendered", onRendered);
831
- stop();
832
- };
833
- }
834
- };
835
- /** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
836
- function processEmbeds() {
837
- const process = globals().instgrm?.Embeds?.process;
838
- if (!process) throw new Error("social-embeds: instgrm.Embeds.process is missing");
839
- process();
840
- }
841
- const instagramDriver = {
842
- load: () => loadPlatformScript("instagram"),
843
- render(container, done) {
844
- const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
845
- reveal(container, "instagram-media");
846
- processEmbeds();
847
- return stop;
848
- }
849
- };
850
- const threadsDriver = {
851
- load: () => loadPlatformScript("threads"),
852
- render(container, done) {
853
- const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
854
- reveal(container, "text-post-media");
855
- processEmbeds();
856
- return stop;
857
- }
858
- };
859
- const facebookDrivers = /* @__PURE__ */ new Map();
860
- function facebookDriver(locale) {
861
- let driver = facebookDrivers.get(locale);
862
- if (!driver) {
863
- driver = {
864
- load: () => loadPlatformScript("facebook", { locale }),
865
- render(container, done) {
866
- const fb = globals().FB;
867
- const parse = fb?.XFBML?.parse;
868
- if (!fb || !parse) throw new Error("social-embeds: FB.XFBML.parse is missing");
869
- const run = () => {
870
- parse(container, done);
871
- };
872
- try {
873
- run();
874
- } catch (error) {
875
- if (!(error instanceof Error) || !/init not called/.test(error.message)) throw error;
876
- fb.init?.({
877
- xfbml: false,
878
- version: FACEBOOK_SDK_VERSION
879
- });
880
- run();
881
- }
882
- return () => {};
883
- }
884
- };
885
- facebookDrivers.set(locale, driver);
886
- }
887
- return driver;
888
- }
889
- const pinterestDriver = {
890
- load: () => loadPlatformScript("pinterest"),
891
- render(container, done) {
892
- const build = globals().PinUtils?.build;
893
- if (!build) throw new Error("social-embeds: PinUtils.build is missing");
894
- const stop = watch(container, (element) => element.querySelector("span[data-pin-id]") !== null, done);
895
- const link = container.querySelector("a");
896
- if (link && !link.hasAttribute("data-pin-do")) link.setAttribute("data-pin-do", "embedPin");
897
- build(container);
898
- return stop;
899
- }
900
- };
901
- // src/core/markup.ts
902
- /** `true` becomes a valueless attribute. */
903
- function attributes(entries) {
904
- let html = "";
905
- for (const [name, value] of Object.entries(entries)) {
906
- if (value === void 0) continue;
907
- html += value === true ? ` ${name}` : ` ${name}="${escapeAttribute(String(value))}"`;
908
- }
909
- return html;
910
- }
911
- /** Booleans are written as `"true"` and `"false"`, the way the platforms document them. */
912
- function dataAttributes(names, options) {
913
- const entries = {};
914
- for (const [key, name] of Object.entries(names)) {
915
- const value = options[key];
916
- if (value !== void 0) entries[name] = String(value);
917
- }
918
- return attributes(entries);
919
- }
920
- /** Embed code options first; props the host passed replace them. */
921
- function withProps(options, props) {
922
- const merged = { ...options };
923
- for (const [key, value] of Object.entries(props)) if (value !== void 0) merged[key] = value;
924
- return merged;
925
- }
926
- function hasFallback(fallbackHtml) {
927
- return fallbackHtml !== void 0 && fallbackHtml.trim() !== "";
928
- }
929
- // src/core/plans/facebook.ts
930
- const ATTRIBUTES$2 = {
931
- width: "data-width",
932
- showText: "data-show-text",
933
- lazy: "data-lazy",
934
- allowfullscreen: "data-allowfullscreen",
935
- autoplay: "data-autoplay",
936
- showCaptions: "data-show-captions"
937
- };
938
- const PLAYER_PARAMETERS = {
939
- showText: "show_text",
940
- allowfullscreen: "allowfullscreen",
941
- autoplay: "autoplay",
942
- showCaptions: "show_captions"
943
- };
944
- /** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
945
- const POST_MAX_WIDTH = 750;
946
- /** docs/decisions.md D34. */
947
- const MIN_HEIGHT$4 = {
948
- post: 300,
949
- video: 200
950
- };
951
- const ALLOW$7 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
952
- /** Its content fills the iframe at any width, whatever `width` says (docs/decisions.md D29). */
953
- function facebookVideoPlan(embed) {
954
- const params = Object.entries(embed.options).filter(([key]) => key !== "href");
955
- return {
956
- kind: "iframe",
957
- src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
958
- title: "Facebook video player",
959
- allow: ALLOW$7,
960
- scrolling: "no",
961
- ratio: {
962
- width: 16,
963
- height: 9
964
- },
965
- size: embed.size
966
- };
967
- }
968
- function facebookPlan(embed, options) {
969
- if (embed.variant === "iframe") return facebookVideoPlan(embed);
970
- const merged = withProps(embed.options, {
971
- showText: options.showText,
972
- allowfullscreen: options.allowfullscreen,
973
- autoplay: options.autoplay,
974
- showCaptions: options.showCaptions
975
- });
976
- const { size } = embed;
977
- if (embed.kind === "video" && merged.showText === false && size?.width !== void 0 && size.height !== void 0) {
978
- const parameters = {};
979
- for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
980
- const value = merged[option];
981
- if (value !== void 0) parameters[name] = value;
982
- }
983
- parameters.width = size.width;
984
- parameters.height = size.height;
985
- return facebookVideoPlan({
986
- ...embed,
987
- options: parameters
988
- });
989
- }
990
- const sdkLocale = options.locale ?? (typeof merged.locale === "string" ? merged.locale : "en_US");
991
- const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, merged)}>${embed.fallbackHtml ?? ""}</div>`;
992
- return {
993
- kind: "script",
994
- key: `${sdkLocale} ${markup}`,
995
- markup,
996
- driver: facebookDriver(sdkLocale),
997
- minHeight: MIN_HEIGHT$4[embed.kind],
998
- label: "Facebook",
999
- hasFallback: hasFallback(embed.fallbackHtml),
1000
- maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0
1001
- };
1002
- }
1003
- // src/components/script-embed.tsx
1004
- const LAYER = { width: "100%" };
1005
- function toError(error) {
1006
- return error instanceof Error ? error : new Error(String(error));
1007
- }
1008
- function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "100%", maxWidth, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
1009
- const container = useRef(null);
1010
- const near = useNearViewport(container, lazy);
1011
- const [rendered, setRendered] = useState(false);
1012
- const callbacks = useRef({
1013
- onLoad,
1014
- onError
1015
- });
1016
- useEffect(() => {
1017
- callbacks.current = {
1018
- onLoad,
1019
- onError
1020
- };
1021
- });
1022
- useEffect(() => {
1023
- const element = container.current;
1024
- if (!near || !element) return;
1025
- let cancelled = false;
1026
- let done = false;
1027
- let timer;
1028
- let stop = () => {};
1029
- const finish = () => {
1030
- if (cancelled || done) return;
1031
- done = true;
1032
- clearTimeout(timer);
1033
- stop();
1034
- setRendered(true);
1035
- callbacks.current.onLoad?.();
1036
- };
1037
- const retryOrFail = (number, error) => {
1038
- if (cancelled || done) return;
1039
- stop();
1040
- stop = () => {};
1041
- if (number >= 3) {
1042
- callbacks.current.onError?.(error);
1043
- return;
1044
- }
1045
- timer = setTimeout(() => {
1046
- attempt(number + 1);
1047
- }, RETRY_DELAY_MS$1 * 2 ** (number - 1));
1048
- };
1049
- const attempt = (number) => {
1050
- if (cancelled || done) return;
1051
- try {
1052
- stop = driver.render(element, finish);
1053
- } catch (error) {
1054
- retryOrFail(number, toError(error));
1055
- return;
1056
- }
1057
- timer = setTimeout(() => {
1058
- retryOrFail(number, /* @__PURE__ */ new Error(`social-embeds: the ${label} embed did not render`));
1059
- }, RENDER_TIMEOUT_MS);
1060
- };
1061
- driver.load().then(() => {
1062
- attempt(1);
1063
- }, (error) => {
1064
- if (!cancelled) callbacks.current.onError?.(toError(error));
1065
- });
1066
- return () => {
1067
- cancelled = true;
1068
- clearTimeout(timer);
1069
- stop();
1070
- };
1071
- }, [
1072
- near,
1073
- driver,
1074
- label
1075
- ]);
1076
- const wrapper = {
1077
- width,
1078
- maxWidth,
1079
- ...style
1080
- };
1081
- return /* @__PURE__ */ jsx("div", {
1082
- ...rest,
1083
- style: wrapper,
1084
- children: /* @__PURE__ */ jsxs("div", {
1085
- style: LAYER,
1086
- children: [/* @__PURE__ */ jsx("div", {
1087
- ref: container,
1088
- suppressHydrationWarning: true,
1089
- dangerouslySetInnerHTML: { __html: markup }
1090
- }), !hasFallback && !rendered && (placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
1091
- })
1092
- });
1093
- }
1094
- // src/components/facebook-embed.tsx
1095
- function FacebookEmbed(props) {
1096
- const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
1097
- const { embed, error } = resolveEmbed(url, given, "facebook");
1098
- const plan = embed ? facebookPlan(embed, {
1099
- locale,
1100
- showText,
1101
- allowfullscreen,
1102
- autoplay,
1103
- showCaptions
1104
- }) : void 0;
1105
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1106
- if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
1107
- ...shared,
1108
- ...planProps(plan),
1109
- maxWidth: maxWidth ?? plan.maxWidth,
1110
- height,
1111
- maxHeight
1112
- });
1113
- if (plan?.kind !== "script") return null;
1114
- return /* @__PURE__ */ jsx(ScriptEmbed, {
1115
- ...shared,
1116
- onError,
1117
- maxWidth: maxWidth ?? plan.maxWidth,
1118
- driver: plan.driver,
1119
- markup: plan.markup,
1120
- hasFallback: plan.hasFallback,
1121
- minHeight: plan.minHeight,
1122
- label: plan.label
1123
- }, plan.key);
1124
- }
1125
- // src/core/plans/flickr.ts
1126
- const OPTIONS = [
1127
- "header",
1128
- "footer",
1129
- "context"
1130
- ];
1131
- const ALBUM = /\/albums\/\d+$/;
1132
- const IMAGE_STYLE = "display:block;width:100%;height:100%;object-fit:cover";
1133
- /** 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). */
1134
- function flickrPlan(embed, options) {
1135
- const album = ALBUM.test(embed.url);
1136
- const kept = OPTIONS.filter((name) => options[name] ?? embed.options[name] === true);
1137
- const { width, height } = embed.size ?? {};
1138
- const size = width !== void 0 && height !== void 0 ? {
1139
- width,
1140
- height
1141
- } : void 0;
1142
- return {
1143
- kind: "iframe",
1144
- src: `https://embedr.flickr.com/${album ? "photosets" : "photos"}/${embed.id}${kept.length > 0 ? `?${kept.map((name) => `${name}=true`).join("&")}` : ""}`,
1145
- title: album ? "Flickr album" : "Flickr photo",
1146
- allow: "",
1147
- scrolling: "no",
1148
- ratio: {
1149
- width: 4,
1150
- height: 3
1151
- },
1152
- ...size ? {
1153
- size,
1154
- maxWidth: size.width
1155
- } : {},
1156
- sizeInSrc: true,
1157
- ...embed.fallbackHtml === void 0 ? {} : { fallbackHtml: embed.fallbackHtml.replace(/<img(?=[\s>])/g, `<img style="${IMAGE_STYLE}"`) },
1158
- fallbackImage: true
1159
- };
1160
- }
1161
- // src/components/flickr-embed.tsx
1162
- /** 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). */
1163
- function FlickrEmbed(props) {
1164
- const { url, embed: given, onError, maxWidth, header, footer, context, placeholder, ...frame } = props;
1165
- const { embed, error } = resolveEmbed(url, given, "flickr");
1166
- const plan = embed ? flickrPlan(embed, {
1167
- header,
1168
- footer,
1169
- context
1170
- }) : void 0;
1171
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1172
- if (plan?.kind !== "iframe") return null;
1173
- return /* @__PURE__ */ jsx(IframeEmbed, {
1174
- ...frame,
1175
- ...planProps(plan),
1176
- onError,
1177
- maxWidth: maxWidth ?? plan.maxWidth,
1178
- placeholder: placeholder ?? fallbackPlaceholder(plan)
1179
- });
1180
- }
1181
- // src/core/plans/generic.ts
1182
- const DEFAULT_RATIO = {
1183
- width: 16,
1184
- height: 9
1185
- };
1186
- /** Re-checks the embed, so a host-built value renders only what `parseIframe` would keep. */
1187
- function genericPlan(embed) {
1188
- const checked = checkIframe(embed);
1189
- if (!checked) return {
1190
- kind: "error",
1191
- message: "social-embeds: not a generic iframe embed"
1192
- };
1193
- return {
1194
- kind: "iframe",
1195
- src: checked.src,
1196
- title: checked.title ?? "Embedded content",
1197
- allow: checked.allow,
1198
- allowFullscreen: checked.allowFullscreen,
1199
- ...checked.referrerPolicy ? { referrerPolicy: checked.referrerPolicy } : {},
1200
- ...checked.sandbox === void 0 ? {} : { sandbox: checked.sandbox },
1201
- ...checked.scrolling ? { scrolling: checked.scrolling } : {},
1202
- ...layout(checked)
1203
- };
1204
- }
1205
- function layout({ size, ratio }) {
1206
- const { width, height } = size;
1207
- if (width !== void 0 && height !== void 0) return {
1208
- ratio: {
1209
- width,
1210
- height
1211
- },
1212
- maxWidth: width
1213
- };
1214
- if (height !== void 0) return {
1215
- ratio: DEFAULT_RATIO,
1216
- height
1217
- };
1218
- return {
1219
- ratio: ratio ?? DEFAULT_RATIO,
1220
- ...width === void 0 ? {} : { maxWidth: width }
1221
- };
1222
- }
1223
- // src/components/generic-iframe-embed.tsx
1224
- /** One iframe rebuilt from its checked attributes; nothing else in the code renders. */
1225
- function GenericIframeEmbed(props) {
1226
- const { html, embed: given, onError, maxWidth, height, ...frame } = props;
1227
- const embed = useMemo(() => given ?? parseIframe(html), [given, html]);
1228
- const plan = embed ? genericPlan(embed) : {
1229
- kind: "error",
1230
- message: "social-embeds: not an iframe embed code"
1231
- };
1232
- useReportError(plan.kind === "error" ? plan.message : void 0, onError);
1233
- if (plan.kind !== "iframe") return null;
1234
- return /* @__PURE__ */ jsx(IframeEmbed, {
1235
- ...frame,
1236
- ...planProps(plan),
1237
- onError,
1238
- maxWidth: maxWidth ?? plan.maxWidth,
1239
- height: height ?? plan.height
1240
- });
1241
- }
1242
- // src/core/plans/giphy.ts
1243
- /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
1244
- function giphyPlan(embed) {
1245
- return {
1246
- kind: "iframe",
1247
- src: `https://giphy.com/embed/${embed.id}`,
1248
- title: "Giphy GIF",
1249
- allow: "fullscreen",
1250
- ratio: {
1251
- width: 1,
1252
- height: 1
1253
- },
1254
- size: embed.size
1255
- };
1256
- }
1257
- // src/components/giphy-embed.tsx
1258
- /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
1259
- function GiphyEmbed(props) {
1260
- const { url, embed: given, onError, maxWidth, ...frame } = props;
1261
- const { embed, error } = resolveEmbed(url, given, "giphy");
1262
- const plan = embed ? giphyPlan(embed) : void 0;
1263
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1264
- if (plan?.kind !== "iframe") return null;
1265
- return /* @__PURE__ */ jsx(IframeEmbed, {
1266
- ...frame,
1267
- ...planProps(plan),
1268
- onError,
1269
- maxWidth: maxWidth ?? plan.maxWidth
1270
- });
1271
- }
1272
- // src/core/plans/imgur.ts
1273
- /** The frame posts one JSON string at `load`, unasked (docs/decisions.md D94). */
1274
- const IMGUR_HEIGHT = {
1275
- origin: "https://imgur.com",
1276
- read(data) {
1277
- if (typeof data !== "string") return void 0;
1278
- const message = JSON.parse(data);
1279
- return message.message === "resize_imgur" && typeof message.height === "number" ? message.height : void 0;
1280
- }
1281
- };
1282
- /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
1283
- function imgurPlan(embed, options) {
1284
- const params = [
1285
- "pub=true",
1286
- ...options.context ?? embed.options.context !== false ? [] : ["context=false"],
1287
- ...embed.options.analytics === false ? ["analytics=false"] : []
1288
- ];
1289
- return {
1290
- kind: "iframe",
1291
- src: `https://imgur.com/${embed.id}/embed?${params.join("&")}`,
1292
- title: "Imgur post",
1293
- allow: "",
1294
- scrolling: "no",
1295
- ratio: {
1296
- width: 1,
1297
- height: 1
1298
- },
1299
- messageHeight: IMGUR_HEIGHT,
1300
- startHeight: 500,
1301
- maxWidth: 540,
1302
- fallbackHtml: embed.fallbackHtml
1303
- };
1304
- }
1305
- // src/components/imgur-embed.tsx
1306
- /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
1307
- function ImgurEmbed(props) {
1308
- const { url, embed: given, onError, maxWidth, context, placeholder, ...shared } = props;
1309
- const { embed, error } = resolveEmbed(url, given, "imgur");
1310
- const plan = embed ? imgurPlan(embed, { context }) : void 0;
1311
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1312
- if (plan?.kind !== "iframe") return null;
1313
- return /* @__PURE__ */ jsx(IframeEmbed, {
1314
- ...shared,
1315
- ...planProps(plan),
1316
- onError,
1317
- maxWidth: maxWidth ?? plan.maxWidth,
1318
- placeholder: placeholder ?? fallbackPlaceholder(plan)
1319
- });
1320
- }
1321
- // src/core/plans/instagram.ts
1322
- /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
1323
- const MIN_HEIGHT$3 = 680;
1324
- const FLUID_WIDTH = "width:calc(100% - 2px)";
1325
- function instagramPlan(embed, options) {
1326
- const merged = withProps(embed.options, { captioned: options.captioned });
1327
- const markup = `<blockquote${attributes({
1328
- "data-instgrm-permalink": embed.url,
1329
- "data-instgrm-version": merged.version,
1330
- "data-instgrm-captioned": merged.captioned === true ? true : void 0,
1331
- style: FLUID_WIDTH
1332
- })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1333
- return {
1334
- kind: "script",
1335
- key: markup,
1336
- markup,
1337
- driver: instagramDriver,
1338
- minHeight: MIN_HEIGHT$3,
1339
- label: "Instagram",
1340
- hasFallback: hasFallback(embed.fallbackHtml),
1341
- maxWidth: 540
1342
- };
1343
- }
1344
- // src/components/instagram-embed.tsx
1345
- function InstagramEmbed(props) {
1346
- const { url, embed: given, onError, maxWidth, captioned, ...shared } = props;
1347
- const { embed, error } = resolveEmbed(url, given, "instagram");
1348
- const plan = embed ? instagramPlan(embed, { captioned }) : void 0;
1349
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1350
- if (plan?.kind !== "script") return null;
1351
- return /* @__PURE__ */ jsx(ScriptEmbed, {
1352
- ...shared,
1353
- onError,
1354
- maxWidth: maxWidth ?? plan.maxWidth,
1355
- driver: plan.driver,
1356
- markup: plan.markup,
1357
- hasFallback: plan.hasFallback,
1358
- minHeight: plan.minHeight,
1359
- label: plan.label
1360
- }, plan.key);
1361
- }
1362
- // src/core/plans/kick.ts
1363
- const KEPT$1 = /* @__PURE__ */ new Set(["autoplay", "muted"]);
1364
- /** A live channel at 16:9. */
1365
- function kickPlan(embed, options) {
1366
- const fromOptions = [];
1367
- if (options.autoplay !== void 0) fromOptions.push(["autoplay", options.autoplay]);
1368
- if (options.muted !== void 0) fromOptions.push(["muted", options.muted]);
1369
- return {
1370
- kind: "iframe",
1371
- src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT$1.has(key)), fromOptions)}`,
1372
- title: "Kick player",
1373
- allow: "autoplay; fullscreen",
1374
- scrolling: "no",
1375
- ratio: {
1376
- width: 16,
1377
- height: 9
1378
- },
1379
- size: embed.size
1380
- };
1381
- }
1382
- // src/components/kick-embed.tsx
1383
- /** A live channel at 16:9. */
1384
- function KickEmbed(props) {
1385
- const { url, embed: given, onError, maxWidth, autoplay, muted, ...frame } = props;
1386
- const { embed, error } = resolveEmbed(url, given, "kick");
1387
- const plan = embed ? kickPlan(embed, {
1388
- autoplay,
1389
- muted
1390
- }) : void 0;
1391
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1392
- if (plan?.kind !== "iframe") return null;
1393
- return /* @__PURE__ */ jsx(IframeEmbed, {
1394
- ...frame,
1395
- ...planProps(plan),
1396
- onError,
1397
- maxWidth: maxWidth ?? plan.maxWidth
1398
- });
1399
- }
1400
- // src/core/plans/linkedin.ts
1401
- const DEFAULT_HEIGHT = 670;
1402
- const DEFAULT_WIDTH = 504;
1403
- /** A fixed height: the embed code's, else 670px. */
1404
- function linkedinPlan(embed, options) {
1405
- const params = new Map(Object.entries(embed.options));
1406
- if (options.collapsed === true) params.set("collapsed", 1);
1407
- if (options.collapsed === false) params.delete("collapsed");
1408
- return {
1409
- kind: "iframe",
1410
- src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
1411
- title: "LinkedIn post",
1412
- allow: "",
1413
- ratio: {
1414
- width: DEFAULT_WIDTH,
1415
- height: DEFAULT_HEIGHT
1416
- },
1417
- height: embed.size?.height ?? DEFAULT_HEIGHT,
1418
- maxWidth: embed.size?.width ?? DEFAULT_WIDTH
1419
- };
1420
- }
1421
- // src/components/linkedin-embed.tsx
1422
- /** A fixed height: the `height` prop, else the embed code's, else 670px. */
1423
- function LinkedInEmbed(props) {
1424
- const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
1425
- const { embed, error } = resolveEmbed(url, given, "linkedin");
1426
- const plan = embed ? linkedinPlan(embed, { collapsed }) : void 0;
1427
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1428
- if (plan?.kind !== "iframe") return null;
1429
- return /* @__PURE__ */ jsx(IframeEmbed, {
1430
- ...frame,
1431
- ...planProps(plan),
1432
- maxWidth: maxWidth ?? plan.maxWidth,
1433
- height: height ?? plan.height
1434
- });
1435
- }
1436
- // src/core/plans/pinterest.ts
1437
- const ATTRIBUTES$1 = {
1438
- width: "data-pin-width",
1439
- lang: "data-pin-lang",
1440
- terse: "data-pin-terse"
1441
- };
1442
- const PIN_WIDTHS = {
1443
- small: 236,
1444
- medium: 345,
1445
- large: 600
1446
- };
1447
- const DEFAULT_PIN_WIDTH = 236;
1448
- const MIN_HEIGHT$2 = 270;
1449
- function pinterestPlan(embed, options) {
1450
- const merged = withProps(embed.options, { width: options.pinWidth });
1451
- const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, merged)}></a>`;
1452
- return {
1453
- kind: "script",
1454
- key: markup,
1455
- markup,
1456
- driver: pinterestDriver,
1457
- minHeight: MIN_HEIGHT$2,
1458
- label: "Pinterest",
1459
- hasFallback: false,
1460
- maxWidth: PIN_WIDTHS[String(merged.width)] ?? DEFAULT_PIN_WIDTH
1461
- };
1462
- }
1463
- // src/components/pinterest-embed.tsx
1464
- function PinterestEmbed(props) {
1465
- const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
1466
- const { embed, error } = resolveEmbed(url, given, "pinterest");
1467
- const plan = embed ? pinterestPlan(embed, { pinWidth }) : void 0;
1468
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1469
- if (plan?.kind !== "script") return null;
1470
- return /* @__PURE__ */ jsx(ScriptEmbed, {
1471
- ...shared,
1472
- onError,
1473
- maxWidth: maxWidth ?? plan.maxWidth,
1474
- driver: plan.driver,
1475
- markup: plan.markup,
1476
- hasFallback: plan.hasFallback,
1477
- minHeight: plan.minHeight,
1478
- label: plan.label
1479
- }, plan.key);
1480
- }
1481
- // src/core/plans/reddit.ts
1482
- const PARAMS$6 = {
1483
- theme: "theme",
1484
- showMedia: "showmedia",
1485
- showTitle: "showtitle",
1486
- showUsername: "showusername",
1487
- locale: "locale",
1488
- depth: "depth"
1489
- };
1490
- const SANDBOX = "allow-scripts allow-same-origin allow-popups";
1491
- const ALLOW$6 = "clipboard-read; clipboard-write";
1492
- const START_HEIGHT = 316;
1493
- /** docs/decisions.md D52. */
1494
- const REDDIT_HEIGHT = {
1495
- origin: "https://embed.reddit.com",
1496
- read(data) {
1497
- if (typeof data !== "string") return void 0;
1498
- const message = JSON.parse(data);
1499
- return message.type === "resize.embed" && typeof message.data === "number" ? message.data : void 0;
1500
- }
1501
- };
1502
- /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1503
- function redditPlan(embed, options) {
1504
- const fromProps = [];
1505
- for (const [prop, name] of Object.entries(PARAMS$6)) {
1506
- const value = options[prop];
1507
- if (value !== void 0) fromProps.push([name, value]);
1508
- }
1509
- return {
1510
- kind: "iframe",
1511
- src: `https://embed.reddit.com${embed.url.slice(22)}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
1512
- title: "Reddit post",
1513
- allow: ALLOW$6,
1514
- sandbox: SANDBOX,
1515
- scrolling: "no",
1516
- ratio: {
1517
- width: 1,
1518
- height: 1
1519
- },
1520
- messageHeight: REDDIT_HEIGHT,
1521
- startHeight: embed.size?.height ?? START_HEIGHT,
1522
- maxWidth: 640
1523
- };
1524
- }
1525
- // src/components/reddit-embed.tsx
1526
- /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1527
- function RedditEmbed(props) {
1528
- const { url, embed: given, onError, maxWidth, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
1529
- const { embed, error } = resolveEmbed(url, given, "reddit");
1530
- const plan = embed ? redditPlan(embed, {
1531
- theme,
1532
- showMedia,
1533
- showTitle,
1534
- showUsername,
1535
- locale,
1536
- depth
1537
- }) : void 0;
1538
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1539
- if (plan?.kind !== "iframe") return null;
1540
- return /* @__PURE__ */ jsx(IframeEmbed, {
1541
- ...shared,
1542
- ...planProps(plan),
1543
- onError,
1544
- maxWidth: maxWidth ?? plan.maxWidth
1545
- });
1546
- }
1547
- // src/core/plans/snapchat.ts
1548
- const ALLOW$5 = "autoplay; camera; microphone; clipboard-write;";
1549
- /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1550
- function snapchatPlan(embed) {
1551
- const title = embed.options.title;
1552
- return {
1553
- kind: "iframe",
1554
- src: `${embed.url}/embed`,
1555
- title: typeof title === "string" && title !== "" ? title : "Snapchat",
1556
- allow: ALLOW$5,
1557
- scrolling: "no",
1558
- ratio: {
1559
- width: 416,
1560
- height: 692
1561
- },
1562
- size: embed.size,
1563
- maxWidth: 416
1564
- };
1565
- }
1566
- // src/components/snapchat-embed.tsx
1567
- /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1568
- function SnapchatEmbed(props) {
1569
- const { url, embed: given, onError, maxWidth, ...frame } = props;
1570
- const { embed, error } = resolveEmbed(url, given, "snapchat");
1571
- const plan = embed ? snapchatPlan(embed) : void 0;
1572
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1573
- if (plan?.kind !== "iframe") return null;
1574
- return /* @__PURE__ */ jsx(IframeEmbed, {
1575
- ...frame,
1576
- ...planProps(plan),
1577
- maxWidth: maxWidth ?? plan.maxWidth
1578
- });
1579
- }
1580
- // src/core/plans/soundcloud.ts
1581
- const PARAMS$5 = {
1582
- visual: "visual",
1583
- color: "color",
1584
- autoPlay: "auto_play",
1585
- hideRelated: "hide_related",
1586
- showComments: "show_comments",
1587
- showUser: "show_user",
1588
- showReposts: "show_reposts",
1589
- showTeaser: "show_teaser",
1590
- showArtwork: "show_artwork"
1591
- };
1592
- const ALLOW$4 = "autoplay; encrypted-media";
1593
- const URL_HEIGHT = 400;
1594
- /** A fixed height: the embed code's, else 400px for the visual player. */
1595
- function soundcloudPlan(embed, options) {
1596
- const fromOptions = [];
1597
- for (const [option, name] of Object.entries(PARAMS$5)) {
1598
- const value = options[option];
1599
- if (value !== void 0) fromOptions.push([name, value]);
1600
- }
1601
- const fromUrl = embed.size === void 0;
1602
- return {
1603
- kind: "iframe",
1604
- src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromOptions)}`,
1605
- title: "SoundCloud player",
1606
- allow: ALLOW$4,
1607
- scrolling: "no",
1608
- ratio: {
1609
- width: 16,
1610
- height: 9
1611
- },
1612
- height: embed.size?.height ?? URL_HEIGHT
1613
- };
1614
- }
1615
- // src/components/soundcloud-embed.tsx
1616
- /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
1617
- function SoundCloudEmbed(props) {
1618
- const { url, embed: given, onError, maxWidth, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
1619
- const { embed, error } = resolveEmbed(url, given, "soundcloud");
1620
- const plan = embed ? soundcloudPlan(embed, {
1621
- visual,
1622
- color,
1623
- autoPlay,
1624
- hideRelated,
1625
- showComments,
1626
- showUser,
1627
- showReposts,
1628
- showTeaser,
1629
- showArtwork
1630
- }) : void 0;
1631
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1632
- if (plan?.kind !== "iframe") return null;
1633
- return /* @__PURE__ */ jsx(IframeEmbed, {
1634
- ...frame,
1635
- ...planProps(plan),
1636
- onError,
1637
- maxWidth: maxWidth ?? plan.maxWidth,
1638
- height: height ?? plan.height
1639
- });
1640
- }
1641
- // src/core/plans/spotify.ts
1642
- const ALLOW$3 = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
1643
- const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
1644
- const COMPACT_HEIGHT = 152;
1645
- const FULL_HEIGHT = 352;
1646
- /**
1647
- * A fixed height: the embed code's, else 152px for a track or episode and 352px for the rest.
1648
- * A video show keeps its 16:9 aspect ratio instead.
1649
- */
1650
- function spotifyPlan(embed, options) {
1651
- const type = new URL(embed.url).pathname.split("/")[1] ?? "";
1652
- const video = embed.kind === "video";
1653
- const params = query(Object.entries(embed.options), options.theme === void 0 ? void 0 : [["theme", options.theme]]);
1654
- return {
1655
- kind: "iframe",
1656
- src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
1657
- title: "Spotify Embed",
1658
- allow: ALLOW$3,
1659
- ratio: {
1660
- width: 16,
1661
- height: 9
1662
- },
1663
- size: video ? embed.size : void 0,
1664
- borderRadius: 12,
1665
- height: video ? void 0 : embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT)
1666
- };
1667
- }
1668
- // src/components/spotify-embed.tsx
1669
- /**
1670
- * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
1671
- * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
1672
- */
1673
- function SpotifyEmbed(props) {
1674
- const { url, embed: given, onError, height, theme, ...frame } = props;
1675
- const { embed, error } = resolveEmbed(url, given, "spotify");
1676
- const plan = embed ? spotifyPlan(embed, { theme }) : void 0;
1677
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1678
- if (plan?.kind !== "iframe") return null;
1679
- return /* @__PURE__ */ jsx(IframeEmbed, {
1680
- ...frame,
1681
- ...planProps(plan),
1682
- height: height ?? plan.height
1683
- });
1684
- }
1685
- // src/core/plans/strava.ts
1686
- const NS = "social-embeds";
1687
- /** The frame posts `[ns, 'BROADCAST_IFRAME_HEIGHT', height]` once, unasked (docs/decisions.md D97). */
1688
- const STRAVA_HEIGHT = {
1689
- origin: "https://strava-embeds.com",
1690
- read(data) {
1691
- if (!Array.isArray(data)) return void 0;
1692
- const [, type, height] = data;
1693
- return type === "BROADCAST_IFRAME_HEIGHT" && typeof height === "number" ? height : void 0;
1694
- }
1695
- };
1696
- function styleOf(value) {
1697
- return value === "minimal" ? "minimal" : "standard";
1698
- }
1699
- /** At most 554px wide by default, as `embed.js` makes the frame; a full-width route has no maximum (docs/decisions.md D97). */
1700
- function stravaPlan(embed, options) {
1701
- const route = embed.id.startsWith("route/");
1702
- const style = styleOf(options.embedStyle ?? embed.options.style);
1703
- const fullWidth = route && (options.fullWidth ?? embed.options.fullWidth === true);
1704
- const mapHash = options.mapHash ?? embed.options.mapHash;
1705
- const query = `?style=${style}${fullWidth ? "&fullWidth=true" : ""}`;
1706
- const fragment = `#ns=${NS}${typeof mapHash === "string" && mapHash !== "" ? `&mapHash=${encodeURIComponent(mapHash)}` : ""}`;
1707
- return {
1708
- kind: "iframe",
1709
- src: `https://strava-embeds.com/${embed.id}${query}${fragment}`,
1710
- title: route ? "Strava route" : "Strava activity",
1711
- allow: "",
1712
- scrolling: "no",
1713
- ratio: {
1714
- width: 1,
1715
- height: 1
1716
- },
1717
- messageHeight: STRAVA_HEIGHT,
1718
- startHeight: 650,
1719
- ...fullWidth ? {} : { maxWidth: 554 }
1720
- };
1721
- }
1722
- // src/components/strava-embed.tsx
1723
- /** At most 554px wide by default, as `embed.js` makes the frame; a full-width route has no maximum (docs/decisions.md D97). */
1724
- function StravaEmbed(props) {
1725
- const { url, embed: given, onError, maxWidth, embedStyle, fullWidth, mapHash, ...shared } = props;
1726
- const { embed, error } = resolveEmbed(url, given, "strava");
1727
- const plan = embed ? stravaPlan(embed, {
1728
- embedStyle,
1729
- fullWidth,
1730
- mapHash
1731
- }) : void 0;
1732
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1733
- if (plan?.kind !== "iframe") return null;
1734
- return /* @__PURE__ */ jsx(IframeEmbed, {
1735
- ...shared,
1736
- ...planProps(plan),
1737
- onError,
1738
- maxWidth: maxWidth ?? plan.maxWidth
1739
- });
1740
- }
1741
- // src/core/plans/streamable.ts
1742
- const KEPT = /* @__PURE__ */ new Set([
1743
- "autoplay",
1744
- "hd",
1745
- "loop",
1746
- "muted",
1747
- "nocontrols"
1748
- ]);
1749
- const PARAMS$4 = {
1750
- autoplay: "autoplay",
1751
- hd: "hd",
1752
- loop: "loop",
1753
- muted: "muted",
1754
- nocontrols: "nocontrols"
1755
- };
1756
- function streamablePlan(embed, options) {
1757
- const parsed = Object.entries(embed.options).filter(([key]) => KEPT.has(key));
1758
- return {
1759
- kind: "iframe",
1760
- src: `https://streamable.com/e/${embed.id}${query(parsed, playerParams(options, PARAMS$4))}`,
1761
- title: "Streamable video",
1762
- allow: "autoplay; fullscreen",
1763
- ratio: {
1764
- width: 16,
1765
- height: 9
1766
- },
1767
- size: embed.size
1768
- };
1769
- }
1770
- // src/components/streamable-embed.tsx
1771
- /** The embed code's aspect ratio, else 16:9. */
1772
- function StreamableEmbed(props) {
1773
- const { url, embed: given, onError, maxWidth, autoplay, hd, loop, muted, nocontrols, ...frame } = props;
1774
- const { embed, error } = resolveEmbed(url, given, "streamable");
1775
- const plan = embed ? streamablePlan(embed, {
1776
- autoplay,
1777
- hd,
1778
- loop,
1779
- muted,
1780
- nocontrols
1781
- }) : void 0;
1782
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1783
- if (plan?.kind !== "iframe") return null;
1784
- return /* @__PURE__ */ jsx(IframeEmbed, {
1785
- ...frame,
1786
- ...planProps(plan),
1787
- onError,
1788
- maxWidth: maxWidth ?? plan.maxWidth
1789
- });
1790
- }
1791
- // src/core/plans/rumble.ts
1792
- /**
1793
- * Rumble documents no player parameters (docs/decisions.md D99), so there are no options.
1794
- * The embed code's `pub` is kept as given and never added.
1795
- */
1796
- function rumblePlan(embed) {
1797
- const pub = optionsWithout(embed.options, []).filter(([key]) => key === "pub");
1798
- return {
1799
- kind: "iframe",
1800
- src: `https://rumble.com/embed/${embed.id}/${query(pub)}`,
1801
- title: "Rumble video",
1802
- allow: "fullscreen",
1803
- ratio: {
1804
- width: 16,
1805
- height: 9
1806
- },
1807
- size: embed.size
1808
- };
1809
- }
1810
- // src/components/rumble-embed.tsx
1811
- /** Embed code only: a page URL holds another id than the player (docs/decisions.md D99). */
1812
- function RumbleEmbed(props) {
1813
- const { url, embed: given, onError, maxWidth, ...frame } = props;
1814
- const { embed, error } = resolveEmbed(url, given, "rumble");
1815
- const plan = embed ? rumblePlan(embed) : void 0;
1816
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1817
- if (plan?.kind !== "iframe") return null;
1818
- return /* @__PURE__ */ jsx(IframeEmbed, {
1819
- ...frame,
1820
- ...planProps(plan),
1821
- onError,
1822
- maxWidth: maxWidth ?? plan.maxWidth
1823
- });
1824
- }
1825
- // src/core/plans/tenor.ts
1826
- /** The embed code's aspect ratio; a URL carries no size and renders at 1.33:1, as `embed.js` does (docs/decisions.md D95). */
1827
- function tenorPlan(embed) {
1828
- return {
1829
- kind: "iframe",
1830
- src: `https://tenor.com/embed/${embed.id}`,
1831
- title: "Tenor GIF",
1832
- allow: "fullscreen",
1833
- ratio: {
1834
- width: 133,
1835
- height: 100
1836
- },
1837
- size: embed.size
1838
- };
1839
- }
1840
- // src/components/tenor-embed.tsx
1841
- /** The embed code's aspect ratio; a URL carries no size and renders at 1.33:1 (docs/decisions.md D95). */
1842
- function TenorEmbed(props) {
1843
- const { url, embed: given, onError, maxWidth, ...frame } = props;
1844
- const { embed, error } = resolveEmbed(url, given, "tenor");
1845
- const plan = embed ? tenorPlan(embed) : void 0;
1846
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1847
- if (plan?.kind !== "iframe") return null;
1848
- return /* @__PURE__ */ jsx(IframeEmbed, {
1849
- ...frame,
1850
- ...planProps(plan),
1851
- onError,
1852
- maxWidth: maxWidth ?? plan.maxWidth
1853
- });
1854
- }
1855
- // src/core/plans/telegram.ts
1856
- const PARAMS$3 = [
1857
- ["comment", "comment"],
1858
- ["userpic", "userpic"],
1859
- ["mode", "mode"],
1860
- ["single", "single"],
1861
- ["color", "color"],
1862
- ["dark", "dark"],
1863
- ["darkColor", "dark_color"]
1864
- ];
1865
- function param(name, value) {
1866
- if (typeof value === "boolean") {
1867
- if (name === "userpic") return String(value);
1868
- if (name === "single") return value ? 1 : void 0;
1869
- return value ? 1 : 0;
1870
- }
1871
- return typeof value === "string" || typeof value === "number" ? value : void 0;
1872
- }
1873
- /** docs/decisions.md D49. */
1874
- const TELEGRAM_HEIGHT = {
1875
- origin: "https://t.me",
1876
- read(data) {
1877
- if (typeof data !== "string") return void 0;
1878
- const message = JSON.parse(data);
1879
- return message.event === "resize" && typeof message.height === "number" ? message.height : void 0;
1880
- }
1881
- };
1882
- /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1883
- function telegramPlan(embed, options) {
1884
- const { userpic, color, dark, darkColor } = options;
1885
- const values = {
1886
- ...embed.options,
1887
- ...userpic === void 0 ? {} : { userpic },
1888
- ...color === void 0 ? {} : { color },
1889
- ...dark === void 0 ? {} : { dark },
1890
- ...darkColor === void 0 ? {} : { darkColor }
1891
- };
1892
- const params = [["embed", 1]];
1893
- for (const [option, name] of PARAMS$3) {
1894
- const value = param(name, values[option]);
1895
- if (value !== void 0) params.push([name, value]);
1896
- }
1897
- return {
1898
- kind: "iframe",
1899
- src: `${embed.url}${query(params)}`,
1900
- title: "Telegram post",
1901
- allow: "",
1902
- scrolling: "no",
1903
- ratio: {
1904
- width: 1,
1905
- height: 1
1906
- },
1907
- messageHeight: TELEGRAM_HEIGHT,
1908
- startHeight: 300,
1909
- maxWidth: 500
1910
- };
1911
- }
1912
- // src/components/telegram-embed.tsx
1913
- /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1914
- function TelegramEmbed(props) {
1915
- const { url, embed: given, onError, maxWidth, userpic, color, dark, darkColor, ...shared } = props;
1916
- const { embed, error } = resolveEmbed(url, given, "telegram");
1917
- const plan = embed ? telegramPlan(embed, {
1918
- userpic,
1919
- color,
1920
- dark,
1921
- darkColor
1922
- }) : void 0;
1923
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1924
- if (plan?.kind !== "iframe") return null;
1925
- return /* @__PURE__ */ jsx(IframeEmbed, {
1926
- ...shared,
1927
- ...planProps(plan),
1928
- onError,
1929
- maxWidth: maxWidth ?? plan.maxWidth
1930
- });
1931
- }
1932
- // src/core/plans/threads.ts
1933
- /** A text-only post (docs/decisions.md D34). */
1934
- const MIN_HEIGHT$1 = 240;
1935
- function threadsPlan(embed, options) {
1936
- const merged = withProps(embed.options, { theme: options.theme });
1937
- const markup = `<blockquote${attributes({
1938
- "data-text-post-permalink": embed.url,
1939
- "data-text-post-version": merged.version ?? 0,
1940
- id: `ig-tp-${embed.id}`,
1941
- "data-theme": merged.theme
1942
- })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1943
- return {
1944
- kind: "script",
1945
- key: markup,
1946
- markup,
1947
- driver: threadsDriver,
1948
- minHeight: MIN_HEIGHT$1,
1949
- label: "Threads",
1950
- hasFallback: hasFallback(embed.fallbackHtml),
1951
- maxWidth: 658
1952
- };
1953
- }
1954
- // src/components/threads-embed.tsx
1955
- function ThreadsEmbed(props) {
1956
- const { url, embed: given, onError, maxWidth, theme, ...shared } = props;
1957
- const { embed, error } = resolveEmbed(url, given, "threads");
1958
- const plan = embed ? threadsPlan(embed, { theme }) : void 0;
1959
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1960
- if (plan?.kind !== "script") return null;
1961
- return /* @__PURE__ */ jsx(ScriptEmbed, {
1962
- ...shared,
1963
- onError,
1964
- maxWidth: maxWidth ?? plan.maxWidth,
1965
- driver: plan.driver,
1966
- markup: plan.markup,
1967
- hasFallback: plan.hasFallback,
1968
- minHeight: plan.minHeight,
1969
- label: plan.label
1970
- }, plan.key);
1971
- }
1972
- // src/core/plans/tiktok.ts
1973
- const PARAMS$2 = {
1974
- controls: "controls",
1975
- progressBar: "progress_bar",
1976
- playButton: "play_button",
1977
- volumeControl: "volume_control",
1978
- fullscreenButton: "fullscreen_button",
1979
- timestamp: "timestamp",
1980
- loop: "loop",
1981
- autoplay: "autoplay",
1982
- musicInfo: "music_info",
1983
- description: "description",
1984
- rel: "rel",
1985
- nativeContextMenu: "native_context_menu",
1986
- closedCaption: "closed_caption",
1987
- forceMuted: "force_muted"
1988
- };
1989
- const ALLOW$2 = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
1990
- /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
1991
- function tiktokPlan(embed, options) {
1992
- const params = playerParams(options, PARAMS$2);
1993
- return {
1994
- kind: "iframe",
1995
- src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
1996
- title: "TikTok video player",
1997
- allow: ALLOW$2,
1998
- ratio: {
1999
- width: 9,
2000
- height: 16
2001
- },
2002
- size: embed.size,
2003
- maxWidth: 325
2004
- };
2005
- }
2006
- // src/components/tiktok-embed.tsx
2007
- /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
2008
- function TikTokEmbed(props) {
2009
- const { url, embed: given, onError, maxWidth, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
2010
- const { embed, error } = resolveEmbed(url, given, "tiktok");
2011
- const plan = embed ? tiktokPlan(embed, {
2012
- controls,
2013
- progressBar,
2014
- playButton,
2015
- volumeControl,
2016
- fullscreenButton,
2017
- timestamp,
2018
- loop,
2019
- autoplay,
2020
- musicInfo,
2021
- description,
2022
- rel,
2023
- nativeContextMenu,
2024
- closedCaption,
2025
- forceMuted
2026
- }) : void 0;
2027
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2028
- if (plan?.kind !== "iframe") return null;
2029
- return /* @__PURE__ */ jsx(IframeEmbed, {
2030
- ...frame,
2031
- ...planProps(plan),
2032
- maxWidth: maxWidth ?? plan.maxWidth
2033
- });
2034
- }
2035
- // src/core/plans/truthsocial.ts
2036
- const VIDEO_EXTRA = 165;
2037
- function setHeight(data) {
2038
- const message = data;
2039
- return message?.type === "setHeight" && typeof message.height === "number" ? message.height : void 0;
2040
- }
2041
- /** The frame posts `{ type: 'setHeight', id, height }` without being asked (docs/decisions.md D93). */
2042
- const TRUTH_SOCIAL_HEIGHT = {
2043
- origin: "https://truthsocial.com",
2044
- read: setHeight
2045
- };
2046
- /** A video post reports its height before the video is sized (docs/decisions.md D100). */
2047
- const TRUTH_SOCIAL_VIDEO_HEIGHT = {
2048
- origin: "https://truthsocial.com",
2049
- read(data) {
2050
- const height = setHeight(data);
2051
- return height === void 0 || height <= 0 ? void 0 : height + VIDEO_EXTRA;
2052
- }
2053
- };
2054
- const CANONICAL = /^https:\/\/truthsocial\.com\/(@[^/]+)\/posts\/\d+$/;
2055
- /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
2056
- function truthSocialPlan(embed) {
2057
- const user = CANONICAL.exec(embed.url)?.[1];
2058
- if (user === void 0) return {
2059
- kind: "error",
2060
- message: `social-embeds: not a Truth Social post URL: ${embed.url}`
2061
- };
2062
- return {
2063
- kind: "iframe",
2064
- src: `https://truthsocial.com/${user}/${embed.id}/embed`,
2065
- title: "Truth Social post",
2066
- allow: "",
2067
- scrolling: "no",
2068
- ratio: {
2069
- width: 1,
2070
- height: 1
2071
- },
2072
- messageHeight: embed.options.video === true ? TRUTH_SOCIAL_VIDEO_HEIGHT : TRUTH_SOCIAL_HEIGHT,
2073
- startHeight: 150,
2074
- maxWidth: embed.size?.width ?? 600
2075
- };
2076
- }
2077
- // src/components/truthsocial-embed.tsx
2078
- /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
2079
- function TruthSocialEmbed(props) {
2080
- const { url, embed: given, onError, maxWidth, ...shared } = props;
2081
- const { embed, error } = resolveEmbed(url, given, "truthsocial");
2082
- const plan = embed ? truthSocialPlan(embed) : void 0;
2083
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2084
- if (plan?.kind !== "iframe") return null;
2085
- return /* @__PURE__ */ jsx(IframeEmbed, {
2086
- ...shared,
2087
- ...planProps(plan),
2088
- onError,
2089
- maxWidth: maxWidth ?? plan.maxWidth
2090
- });
2091
- }
2092
- // src/core/plans/tumblr.ts
2093
- /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
2094
- const TUMBLR_HEIGHT = {
2095
- origin: "https://embed.tumblr.com",
2096
- read(data) {
2097
- if (typeof data !== "string") return void 0;
2098
- const message = JSON.parse(data);
2099
- const [height] = Array.isArray(message.args) ? message.args : [];
2100
- return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
2101
- }
2102
- };
2103
- /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
2104
- function tumblrPlan(embed) {
2105
- return {
2106
- kind: "iframe",
2107
- src: `https://embed.tumblr.com/embed/post/${embed.url.slice(23).split("/")[0] ?? ""}/${embed.id}/v2`,
2108
- title: "Tumblr post",
2109
- allow: "",
2110
- scrolling: "no",
2111
- ratio: {
2112
- width: 1,
2113
- height: 1
2114
- },
2115
- messageHeight: TUMBLR_HEIGHT,
2116
- startHeight: 400,
2117
- maxWidth: 540
2118
- };
2119
- }
2120
- // src/components/tumblr-embed.tsx
2121
- /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
2122
- function TumblrEmbed(props) {
2123
- const { url, embed: given, onError, maxWidth, ...shared } = props;
2124
- const { embed, error } = resolveEmbed(url, given, "tumblr");
2125
- const plan = embed ? tumblrPlan(embed) : void 0;
2126
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2127
- if (plan?.kind !== "iframe") return null;
2128
- return /* @__PURE__ */ jsx(IframeEmbed, {
2129
- ...shared,
2130
- ...planProps(plan),
2131
- onError,
2132
- maxWidth: maxWidth ?? plan.maxWidth
2133
- });
2134
- }
2135
- // src/core/plans/twitch.ts
2136
- const RESERVED = [
2137
- "channel",
2138
- "video",
2139
- "collection",
2140
- "clip",
2141
- "parent"
2142
- ];
2143
- /** The player and its content parameter for the embed's canonical URL (docs/decisions.md D64). */
2144
- function player(url, id) {
2145
- const { hostname, pathname } = new URL(url);
2146
- if (hostname === "clips.twitch.tv") return ["https://clips.twitch.tv/embed", ["clip", id]];
2147
- const section = pathname.split("/")[1];
2148
- return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
2149
- }
2150
- /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
2151
- function twitchPlan(embed, options) {
2152
- const { autoplay, muted, time } = options;
2153
- const params = [];
2154
- if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
2155
- if (muted !== void 0) params.push(["muted", String(muted)]);
2156
- if (time !== void 0) params.push(["time", time]);
2157
- const [base, content] = player(embed.url, embed.id);
2158
- return {
2159
- kind: "iframe",
2160
- src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
2161
- title: "Twitch player",
2162
- allow: "",
2163
- ratio: {
2164
- width: 16,
2165
- height: 9
2166
- },
2167
- size: embed.size,
2168
- hostParam: "parent"
2169
- };
2170
- }
2171
- // src/components/twitch-embed.tsx
2172
- /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
2173
- function TwitchEmbed(props) {
2174
- const { url, embed: given, onError, maxWidth, autoplay, muted, time, ...frame } = props;
2175
- const { embed, error } = resolveEmbed(url, given, "twitch");
2176
- const plan = embed ? twitchPlan(embed, {
2177
- autoplay,
2178
- muted,
2179
- time
2180
- }) : void 0;
2181
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2182
- if (plan?.kind !== "iframe") return null;
2183
- return /* @__PURE__ */ jsx(IframeEmbed, {
2184
- ...frame,
2185
- ...planProps(plan),
2186
- maxWidth: maxWidth ?? plan.maxWidth
2187
- });
2188
- }
2189
- // src/core/plans/vimeo.ts
2190
- const PARAMS$1 = {
2191
- autopause: "autopause",
2192
- autoplay: "autoplay",
2193
- background: "background",
2194
- byline: "byline",
2195
- color: "color",
2196
- controls: "controls",
2197
- dnt: "dnt",
2198
- keyboard: "keyboard",
2199
- loop: "loop",
2200
- muted: "muted",
2201
- pip: "pip",
2202
- playsinline: "playsinline",
2203
- portrait: "portrait",
2204
- quality: "quality",
2205
- speed: "speed",
2206
- title: "title",
2207
- transparent: "transparent"
2208
- };
2209
- const ALLOW$1 = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
2210
- function vimeoPlan(embed, options) {
2211
- const { t, ...rest } = options;
2212
- const { t: parsedStart, ...parsed } = embed.options;
2213
- const hash = new URL(embed.url).pathname.split("/")[2];
2214
- const params = playerParams(rest, PARAMS$1);
2215
- const start = t ?? parsedStart;
2216
- return {
2217
- kind: "iframe",
2218
- src: `https://player.vimeo.com/video/${embed.id}${query(hash ? [["h", hash]] : void 0, optionsWithout(parsed, ["h"]), params)}${start === void 0 ? "" : `#t=${encodeURIComponent(String(start))}`}`,
2219
- title: "Vimeo video player",
2220
- allow: ALLOW$1,
2221
- referrerPolicy: "strict-origin-when-cross-origin",
2222
- ratio: {
2223
- width: 16,
2224
- height: 9
2225
- },
2226
- size: embed.size
2227
- };
2228
- }
2229
- // src/components/vimeo-embed.tsx
2230
- function VimeoEmbed(props) {
2231
- const { url, embed: given, onError, maxWidth, autopause, autoplay, background, byline, color, controls, dnt, keyboard, loop, muted, pip, playsinline, portrait, quality, speed, title, transparent, t, ...frame } = props;
2232
- const { embed, error } = resolveEmbed(url, given, "vimeo");
2233
- const plan = embed ? vimeoPlan(embed, {
2234
- autopause,
2235
- autoplay,
2236
- background,
2237
- byline,
2238
- color,
2239
- controls,
2240
- dnt,
2241
- keyboard,
2242
- loop,
2243
- muted,
2244
- pip,
2245
- playsinline,
2246
- portrait,
2247
- quality,
2248
- speed,
2249
- title,
2250
- transparent,
2251
- t
2252
- }) : void 0;
2253
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2254
- if (plan?.kind !== "iframe") return null;
2255
- return /* @__PURE__ */ jsx(IframeEmbed, {
2256
- ...frame,
2257
- ...planProps(plan),
2258
- maxWidth: maxWidth ?? plan.maxWidth
2259
- });
2260
- }
2261
- // src/core/plans/x.ts
2262
- const ATTRIBUTES = {
2263
- theme: "data-theme",
2264
- conversation: "data-conversation",
2265
- cards: "data-cards",
2266
- align: "data-align",
2267
- lang: "data-lang",
2268
- dnt: "data-dnt",
2269
- width: "data-width"
2270
- };
2271
- /** A plain text post, the smallest X renders (docs/decisions.md D34). */
2272
- const MIN_HEIGHT = 250;
2273
- function xPlan(embed, options) {
2274
- const merged = withProps(embed.options, { ...options });
2275
- const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
2276
- const markup = `<blockquote${dataAttributes(ATTRIBUTES, merged)}>${content}</blockquote>`;
2277
- return {
2278
- kind: "script",
2279
- key: markup,
2280
- markup,
2281
- driver: xDriver,
2282
- minHeight: MIN_HEIGHT,
2283
- label: "X",
2284
- hasFallback: hasFallback(embed.fallbackHtml),
2285
- maxWidth: 550
2286
- };
2287
- }
2288
- // src/components/x-embed.tsx
2289
- function XEmbed(props) {
2290
- const { url, embed: given, onError, maxWidth, theme, conversation, cards, align, lang, dnt, ...shared } = props;
2291
- const { embed, error } = resolveEmbed(url, given, "x");
2292
- const plan = embed ? xPlan(embed, {
2293
- theme,
2294
- conversation,
2295
- cards,
2296
- align,
2297
- lang,
2298
- dnt
2299
- }) : void 0;
2300
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2301
- if (plan?.kind !== "script") return null;
2302
- return /* @__PURE__ */ jsx(ScriptEmbed, {
2303
- ...shared,
2304
- onError,
2305
- maxWidth: maxWidth ?? plan.maxWidth,
2306
- driver: plan.driver,
2307
- markup: plan.markup,
2308
- hasFallback: plan.hasFallback,
2309
- minHeight: plan.minHeight,
2310
- label: plan.label
2311
- }, plan.key);
2312
- }
2313
- // src/core/plans/youtube.ts
2314
- const PARAMS = {
2315
- autoplay: "autoplay",
2316
- ccLangPref: "cc_lang_pref",
2317
- ccLoadPolicy: "cc_load_policy",
2318
- color: "color",
2319
- controls: "controls",
2320
- disablekb: "disablekb",
2321
- enablejsapi: "enablejsapi",
2322
- end: "end",
2323
- fs: "fs",
2324
- hl: "hl",
2325
- ivLoadPolicy: "iv_load_policy",
2326
- list: "list",
2327
- listType: "listType",
2328
- loop: "loop",
2329
- origin: "origin",
2330
- playlist: "playlist",
2331
- playsinline: "playsinline",
2332
- rel: "rel",
2333
- start: "start",
2334
- widgetReferrer: "widget_referrer"
2335
- };
2336
- const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
2337
- function youtubePlan(embed, options) {
2338
- const { nocookie, ...rest } = options;
2339
- const { nocookie: parsedNocookie, ...parsed } = embed.options;
2340
- const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
2341
- const params = playerParams(rest, PARAMS);
2342
- return {
2343
- kind: "iframe",
2344
- src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
2345
- title: "YouTube video player",
2346
- allow: ALLOW,
2347
- referrerPolicy: "strict-origin-when-cross-origin",
2348
- ratio: embed.url.includes("/shorts/") ? {
2349
- width: 9,
2350
- height: 16
2351
- } : {
2352
- width: 16,
2353
- height: 9
2354
- },
2355
- size: embed.size
2356
- };
2357
- }
2358
- // src/components/youtube-embed.tsx
2359
- function YouTubeEmbed(props) {
2360
- const { url, embed: given, onError, maxWidth, autoplay, ccLangPref, ccLoadPolicy, color, controls, disablekb, enablejsapi, end, fs, hl, ivLoadPolicy, list, listType, loop, origin, playlist, playsinline, rel, start, widgetReferrer, nocookie, ...frame } = props;
2361
- const { embed, error } = resolveEmbed(url, given, "youtube");
2362
- const plan = embed ? youtubePlan(embed, {
2363
- autoplay,
2364
- ccLangPref,
2365
- ccLoadPolicy,
2366
- color,
2367
- controls,
2368
- disablekb,
2369
- enablejsapi,
2370
- end,
2371
- fs,
2372
- hl,
2373
- ivLoadPolicy,
2374
- list,
2375
- listType,
2376
- loop,
2377
- origin,
2378
- playlist,
2379
- playsinline,
2380
- rel,
2381
- start,
2382
- widgetReferrer,
2383
- nocookie
2384
- }) : void 0;
2385
- useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
2386
- if (plan?.kind !== "iframe") return null;
2387
- return /* @__PURE__ */ jsx(IframeEmbed, {
2388
- ...frame,
2389
- ...planProps(plan),
2390
- maxWidth: maxWidth ?? plan.maxWidth
2391
- });
2392
- }
2393
- // src/components/social-embed.tsx
2394
- /** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
2395
- function SocialEmbed(props) {
2396
- const { html, url, fallback, height, maxHeight, onError, ...shared } = props;
2397
- const frame = {
2398
- height,
2399
- maxHeight
2400
- };
2401
- const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
2402
- const iframe = useMemo(() => embed === null && html !== void 0 ? parseIframe(html) : null, [embed, html]);
2403
- useReportError(embed === null && iframe === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
2404
- if (iframe) return /* @__PURE__ */ jsx(GenericIframeEmbed, {
2405
- ...shared,
2406
- ...frame,
2407
- onError,
2408
- embed: iframe
2409
- });
2410
- if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
2411
- switch (embed.platform) {
2412
- case "x": return /* @__PURE__ */ jsx(XEmbed, {
2413
- ...shared,
2414
- onError,
2415
- embed
2416
- });
2417
- case "instagram": return /* @__PURE__ */ jsx(InstagramEmbed, {
2418
- ...shared,
2419
- onError,
2420
- embed
2421
- });
2422
- case "threads": return /* @__PURE__ */ jsx(ThreadsEmbed, {
2423
- ...shared,
2424
- onError,
2425
- embed
2426
- });
2427
- case "facebook": return /* @__PURE__ */ jsx(FacebookEmbed, {
2428
- ...shared,
2429
- ...frame,
2430
- onError,
2431
- embed
2432
- });
2433
- case "tiktok": return /* @__PURE__ */ jsx(TikTokEmbed, {
2434
- ...shared,
2435
- ...frame,
2436
- onError,
2437
- embed
2438
- });
2439
- case "youtube": return /* @__PURE__ */ jsx(YouTubeEmbed, {
2440
- ...shared,
2441
- ...frame,
2442
- onError,
2443
- embed
2444
- });
2445
- case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
2446
- ...shared,
2447
- onError,
2448
- embed
2449
- });
2450
- case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
2451
- ...shared,
2452
- ...frame,
2453
- onError,
2454
- embed
2455
- });
2456
- case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
2457
- ...shared,
2458
- ...frame,
2459
- onError,
2460
- embed
2461
- });
2462
- case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
2463
- ...shared,
2464
- onError,
2465
- embed
2466
- });
2467
- case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
2468
- ...shared,
2469
- onError,
2470
- embed
2471
- });
2472
- case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
2473
- ...shared,
2474
- ...frame,
2475
- onError,
2476
- embed
2477
- });
2478
- case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
2479
- ...shared,
2480
- ...frame,
2481
- onError,
2482
- embed
2483
- });
2484
- case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
2485
- ...shared,
2486
- ...frame,
2487
- onError,
2488
- embed
2489
- });
2490
- case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
2491
- ...shared,
2492
- ...frame,
2493
- onError,
2494
- embed
2495
- });
2496
- case "bluesky": return /* @__PURE__ */ jsx(BlueskyEmbed, {
2497
- ...shared,
2498
- onError,
2499
- embed
2500
- });
2501
- case "soundcloud": return /* @__PURE__ */ jsx(SoundCloudEmbed, {
2502
- ...shared,
2503
- ...frame,
2504
- onError,
2505
- embed
2506
- });
2507
- case "applemusic": return /* @__PURE__ */ jsx(AppleMusicEmbed, {
2508
- ...shared,
2509
- ...frame,
2510
- onError,
2511
- embed
2512
- });
2513
- case "applepodcasts": return /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
2514
- ...shared,
2515
- ...frame,
2516
- onError,
2517
- embed
2518
- });
2519
- case "tumblr": return /* @__PURE__ */ jsx(TumblrEmbed, {
2520
- ...shared,
2521
- onError,
2522
- embed
2523
- });
2524
- case "kick": return /* @__PURE__ */ jsx(KickEmbed, {
2525
- ...shared,
2526
- ...frame,
2527
- onError,
2528
- embed
2529
- });
2530
- case "giphy": return /* @__PURE__ */ jsx(GiphyEmbed, {
2531
- ...shared,
2532
- ...frame,
2533
- onError,
2534
- embed
2535
- });
2536
- case "tenor": return /* @__PURE__ */ jsx(TenorEmbed, {
2537
- ...shared,
2538
- ...frame,
2539
- onError,
2540
- embed
2541
- });
2542
- case "streamable": return /* @__PURE__ */ jsx(StreamableEmbed, {
2543
- ...shared,
2544
- ...frame,
2545
- onError,
2546
- embed
2547
- });
2548
- case "rumble": return /* @__PURE__ */ jsx(RumbleEmbed, {
2549
- ...shared,
2550
- ...frame,
2551
- onError,
2552
- embed
2553
- });
2554
- case "truthsocial": return /* @__PURE__ */ jsx(TruthSocialEmbed, {
2555
- ...shared,
2556
- onError,
2557
- embed
2558
- });
2559
- case "imgur": return /* @__PURE__ */ jsx(ImgurEmbed, {
2560
- ...shared,
2561
- onError,
2562
- embed
2563
- });
2564
- case "strava": return /* @__PURE__ */ jsx(StravaEmbed, {
2565
- ...shared,
2566
- onError,
2567
- embed
2568
- });
2569
- case "flickr": return /* @__PURE__ */ jsx(FlickrEmbed, {
2570
- ...shared,
2571
- ...frame,
2572
- onError,
2573
- embed
2574
- });
2575
- }
2576
- }
2
+ import { SocialEmbed } from "./components/social-embed.js";
3
+ import { DailymotionEmbed } from "./components/dailymotion-embed.js";
4
+ import { FacebookEmbed } from "./components/facebook-embed.js";
5
+ import { InstagramEmbed } from "./components/instagram-embed.js";
6
+ import { LinkedInEmbed } from "./components/linkedin-embed.js";
7
+ import { PinterestEmbed } from "./components/pinterest-embed.js";
8
+ import { RedditEmbed } from "./components/reddit-embed.js";
9
+ import { SnapchatEmbed } from "./components/snapchat-embed.js";
10
+ import { SpotifyEmbed } from "./components/spotify-embed.js";
11
+ import { TelegramEmbed } from "./components/telegram-embed.js";
12
+ import { ThreadsEmbed } from "./components/threads-embed.js";
13
+ import { TwitchEmbed } from "./components/twitch-embed.js";
14
+ import { TikTokEmbed } from "./components/tiktok-embed.js";
15
+ import { VimeoEmbed } from "./components/vimeo-embed.js";
16
+ import { XEmbed } from "./components/x-embed.js";
17
+ import { YouTubeEmbed } from "./components/youtube-embed.js";
18
+ import { SoundCloudEmbed } from "./components/soundcloud-embed.js";
19
+ import { AppleMusicEmbed, ApplePodcastsEmbed } from "./components/apple-embed.js";
20
+ import { KickEmbed } from "./components/kick-embed.js";
21
+ import { GiphyEmbed } from "./components/giphy-embed.js";
22
+ import { TenorEmbed } from "./components/tenor-embed.js";
23
+ import { StreamableEmbed } from "./components/streamable-embed.js";
24
+ import { RumbleEmbed } from "./components/rumble-embed.js";
25
+ import { TruthSocialEmbed } from "./components/truthsocial-embed.js";
26
+ import { ImgurEmbed } from "./components/imgur-embed.js";
27
+ import { StravaEmbed } from "./components/strava-embed.js";
28
+ import { FlickrEmbed } from "./components/flickr-embed.js";
29
+ import { GenericIframeEmbed } from "./components/generic-iframe-embed.js";
30
+ import { BlueskyEmbed } from "./components/bluesky-embed.js";
31
+ import { TumblrEmbed } from "./components/tumblr-embed.js";
2577
32
  export { AppleMusicEmbed, ApplePodcastsEmbed, BlueskyEmbed, DailymotionEmbed, FacebookEmbed, FlickrEmbed, GenericIframeEmbed, GiphyEmbed, ImgurEmbed, InstagramEmbed, KickEmbed, LinkedInEmbed, PinterestEmbed, RedditEmbed, RumbleEmbed, SnapchatEmbed, SocialEmbed, SoundCloudEmbed, SpotifyEmbed, StravaEmbed, StreamableEmbed, TelegramEmbed, TenorEmbed, ThreadsEmbed, TikTokEmbed, TruthSocialEmbed, TumblrEmbed, TwitchEmbed, VimeoEmbed, XEmbed, YouTubeEmbed };