social-embeds 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,22 @@
1
1
  "use client";
2
- import { a as escapeAttribute, c as parseUrl, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-BSz1rCrV.js";
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
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/parser/lookup.ts
6
6
  const BLUESKY_HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
7
7
  const HANDLE_POST = /^\/profile\/([^/]{1,253})\/post\/[A-Za-z0-9._~:-]{1,512}\/?$/;
8
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$/;
9
11
  /**
10
12
  * The platform of a post URL that only a network lookup could turn into an embed: a Bluesky
11
- * URL with a handle instead of a DID. Internal; the parser entry does not export it.
13
+ * URL with a handle instead of a DID, or a Rumble page URL. Internal; the parser entry does not export it.
12
14
  */
13
15
  function needsLookup(url) {
14
16
  const parsed = typeof url === "string" ? parseUrl(url) : null;
15
- if (!parsed || !BLUESKY_HOSTS.has(parsed.host)) return 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;
16
20
  const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
17
21
  return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
18
22
  }
@@ -43,7 +47,14 @@ const SHAPES = {
43
47
  applepodcasts: ["post iframe"],
44
48
  tumblr: ["post iframe"],
45
49
  kick: ["video iframe"],
46
- giphy: ["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"]
47
58
  };
48
59
  /**
49
60
  * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
@@ -91,7 +102,14 @@ const NAMES = {
91
102
  applepodcasts: "Apple Podcasts",
92
103
  tumblr: "Tumblr",
93
104
  kick: "Kick",
94
- giphy: "Giphy"
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"
95
113
  };
96
114
  /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
97
115
  function lookupMessage(platform) {
@@ -157,7 +175,7 @@ function applePodcastsPlan(embed) {
157
175
  }
158
176
  // src/core/timing.ts
159
177
  const ROOT_MARGIN = "200px 0px";
160
- const HEIGHT_TIMEOUT_MS = 15e3;
178
+ const FRAME_TIMEOUT_MS = 15e3;
161
179
  const RENDER_TIMEOUT_MS = 15e3;
162
180
  const RETRY_DELAY_MS$1 = 1e3;
163
181
  // src/components/hooks.ts
@@ -194,13 +212,18 @@ function useReportError(message, onError) {
194
212
  }, [message]);
195
213
  }
196
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
+ }
197
221
  /** The iframe wrapper's style, without the host's `style`. Numbers are pixels. */
198
222
  function frameStyle(plan, layout, reportedHeight) {
199
223
  const { width = "100%", maxHeight } = layout;
200
224
  const height = layout.height ?? plan.height;
201
225
  const maxWidth = layout.maxWidth ?? plan.maxWidth;
202
- const aspectWidth = plan.size?.width ?? plan.ratio.width;
203
- const aspectHeight = plan.size?.height ?? plan.ratio.height;
226
+ const { width: aspectWidth, height: aspectHeight } = aspectOf(plan);
204
227
  const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
205
228
  return {
206
229
  position: "relative",
@@ -216,24 +239,77 @@ function frameStyle(plan, layout, reportedHeight) {
216
239
  }
217
240
  };
218
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
+ }
219
286
  // src/components/iframe-embed.tsx
220
287
  /** The plan's fields as `IframeEmbed` props. */
221
288
  function planProps(plan) {
222
- const { kind, fallbackHtml, ...props } = plan;
289
+ const { kind, fallbackHtml, fallbackImage, ...props } = plan;
223
290
  return props;
224
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
+ }
225
301
  const FILL = {
226
302
  position: "absolute",
227
303
  inset: 0
228
304
  };
229
- function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, borderRadius, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
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 }) {
230
306
  const frame = useRef(null);
231
307
  const iframe = useRef(null);
232
308
  const near = useNearViewport(frame, lazy);
233
- const inView = useNearViewport(frame, !lazy && messageHeight !== void 0);
234
- const heard = useRef(false);
309
+ const inView = useNearViewport(frame, !lazy);
235
310
  const [loaded, setLoaded] = useState(false);
236
311
  const [reportedHeight, setReportedHeight] = useState();
312
+ const [boxWidth, setBoxWidth] = useState();
237
313
  const reported = useRef(false);
238
314
  const callbacks = useRef({
239
315
  onLoad,
@@ -254,7 +330,6 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
254
330
  useEffect(() => {
255
331
  if (!near || !messageHeight) return;
256
332
  const { origin, read } = messageHeight;
257
- heard.current = false;
258
333
  const listen = (event) => {
259
334
  if (event.origin !== origin) return;
260
335
  if (!iframe.current || event.source !== iframe.current.contentWindow) return;
@@ -265,7 +340,6 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
265
340
  return;
266
341
  }
267
342
  if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
268
- heard.current = true;
269
343
  setReportedHeight(Math.ceil(value));
270
344
  report();
271
345
  };
@@ -279,12 +353,18 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
279
353
  report
280
354
  ]);
281
355
  useEffect(() => {
282
- if (!near || !inView || !messageHeight) return;
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";
283
363
  const timer = setTimeout(() => {
284
- if (heard.current) return;
364
+ if (reported.current) return;
285
365
  setLoaded(true);
286
- callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} did not report its height`));
287
- }, HEIGHT_TIMEOUT_MS);
366
+ callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} ${failure}`));
367
+ }, FRAME_TIMEOUT_MS);
288
368
  return () => {
289
369
  clearTimeout(timer);
290
370
  };
@@ -313,18 +393,23 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
313
393
  }, reportedHeight),
314
394
  ...style
315
395
  };
396
+ const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
397
+ src,
398
+ ratio,
399
+ size
400
+ }, boxWidth);
316
401
  return /* @__PURE__ */ jsx("div", {
317
402
  ...rest,
318
403
  style: wrapper,
319
404
  children: /* @__PURE__ */ jsxs("div", {
320
405
  ref: frame,
321
406
  style: FILL,
322
- children: [near && /* @__PURE__ */ jsx("iframe", {
407
+ children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
323
408
  ref: iframe,
324
- src: hostParam ? withHost(src, hostParam) : src,
409
+ src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
325
410
  title,
326
411
  allow,
327
- allowFullScreen: true,
412
+ allowFullScreen: allowFullscreen,
328
413
  referrerPolicy,
329
414
  scrolling,
330
415
  sandbox,
@@ -337,7 +422,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
337
422
  onLoad: () => {
338
423
  if (!messageHeight) report();
339
424
  }
340
- }), !loaded && /* @__PURE__ */ jsx("div", {
425
+ }, sizeInSrc ? frameSrc : void 0), !loaded && /* @__PURE__ */ jsx("div", {
341
426
  style: FILL,
342
427
  children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
343
428
  })]
@@ -458,13 +543,12 @@ function BlueskyEmbed(props) {
458
543
  const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
459
544
  useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
460
545
  if (plan?.kind !== "iframe") return null;
461
- const { fallbackHtml } = plan;
462
546
  return /* @__PURE__ */ jsx(IframeEmbed, {
463
547
  ...shared,
464
548
  ...planProps(plan),
465
549
  onError,
466
550
  maxWidth: maxWidth ?? plan.maxWidth,
467
- placeholder: placeholder ?? (fallbackHtml === void 0 ? void 0 : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } }))
551
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
468
552
  });
469
553
  }
470
554
  // src/core/plans/dailymotion.ts
@@ -917,6 +1001,7 @@ function facebookPlan(embed, options) {
917
1001
  };
918
1002
  }
919
1003
  // src/components/script-embed.tsx
1004
+ const LAYER = { width: "100%" };
920
1005
  function toError(error) {
921
1006
  return error instanceof Error ? error : new Error(String(error));
922
1007
  }
@@ -993,14 +1078,17 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
993
1078
  maxWidth,
994
1079
  ...style
995
1080
  };
996
- return /* @__PURE__ */ jsxs("div", {
1081
+ return /* @__PURE__ */ jsx("div", {
997
1082
  ...rest,
998
1083
  style: wrapper,
999
- children: [/* @__PURE__ */ jsx("div", {
1000
- ref: container,
1001
- suppressHydrationWarning: true,
1002
- dangerouslySetInnerHTML: { __html: markup }
1003
- }), !hasFallback && !rendered && (placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
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
+ })
1004
1092
  });
1005
1093
  }
1006
1094
  // src/components/facebook-embed.tsx
@@ -1034,6 +1122,123 @@ function FacebookEmbed(props) {
1034
1122
  label: plan.label
1035
1123
  }, plan.key);
1036
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
+ }
1037
1242
  // src/core/plans/giphy.ts
1038
1243
  /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
1039
1244
  function giphyPlan(embed) {
@@ -1064,6 +1269,55 @@ function GiphyEmbed(props) {
1064
1269
  maxWidth: maxWidth ?? plan.maxWidth
1065
1270
  });
1066
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
+ }
1067
1321
  // src/core/plans/instagram.ts
1068
1322
  /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
1069
1323
  const MIN_HEIGHT$3 = 680;
@@ -1106,7 +1360,7 @@ function InstagramEmbed(props) {
1106
1360
  }, plan.key);
1107
1361
  }
1108
1362
  // src/core/plans/kick.ts
1109
- const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
1363
+ const KEPT$1 = /* @__PURE__ */ new Set(["autoplay", "muted"]);
1110
1364
  /** A live channel at 16:9. */
1111
1365
  function kickPlan(embed, options) {
1112
1366
  const fromOptions = [];
@@ -1114,7 +1368,7 @@ function kickPlan(embed, options) {
1114
1368
  if (options.muted !== void 0) fromOptions.push(["muted", options.muted]);
1115
1369
  return {
1116
1370
  kind: "iframe",
1117
- src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT.has(key)), fromOptions)}`,
1371
+ src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT$1.has(key)), fromOptions)}`,
1118
1372
  title: "Kick player",
1119
1373
  allow: "autoplay; fullscreen",
1120
1374
  scrolling: "no",
@@ -1225,7 +1479,7 @@ function PinterestEmbed(props) {
1225
1479
  }, plan.key);
1226
1480
  }
1227
1481
  // src/core/plans/reddit.ts
1228
- const PARAMS$5 = {
1482
+ const PARAMS$6 = {
1229
1483
  theme: "theme",
1230
1484
  showMedia: "showmedia",
1231
1485
  showTitle: "showtitle",
@@ -1248,7 +1502,7 @@ const REDDIT_HEIGHT = {
1248
1502
  /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1249
1503
  function redditPlan(embed, options) {
1250
1504
  const fromProps = [];
1251
- for (const [prop, name] of Object.entries(PARAMS$5)) {
1505
+ for (const [prop, name] of Object.entries(PARAMS$6)) {
1252
1506
  const value = options[prop];
1253
1507
  if (value !== void 0) fromProps.push([name, value]);
1254
1508
  }
@@ -1324,7 +1578,7 @@ function SnapchatEmbed(props) {
1324
1578
  });
1325
1579
  }
1326
1580
  // src/core/plans/soundcloud.ts
1327
- const PARAMS$4 = {
1581
+ const PARAMS$5 = {
1328
1582
  visual: "visual",
1329
1583
  color: "color",
1330
1584
  autoPlay: "auto_play",
@@ -1340,7 +1594,7 @@ const URL_HEIGHT = 400;
1340
1594
  /** A fixed height: the embed code's, else 400px for the visual player. */
1341
1595
  function soundcloudPlan(embed, options) {
1342
1596
  const fromOptions = [];
1343
- for (const [option, name] of Object.entries(PARAMS$4)) {
1597
+ for (const [option, name] of Object.entries(PARAMS$5)) {
1344
1598
  const value = options[option];
1345
1599
  if (value !== void 0) fromOptions.push([name, value]);
1346
1600
  }
@@ -1428,6 +1682,176 @@ function SpotifyEmbed(props) {
1428
1682
  height: height ?? plan.height
1429
1683
  });
1430
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
+ }
1431
1855
  // src/core/plans/telegram.ts
1432
1856
  const PARAMS$3 = [
1433
1857
  ["comment", "comment"],
@@ -1608,6 +2032,63 @@ function TikTokEmbed(props) {
1608
2032
  maxWidth: maxWidth ?? plan.maxWidth
1609
2033
  });
1610
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: 300,
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
+ }
1611
2092
  // src/core/plans/tumblr.ts
1612
2093
  /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
1613
2094
  const TUMBLR_HEIGHT = {
@@ -1918,7 +2399,14 @@ function SocialEmbed(props) {
1918
2399
  maxHeight
1919
2400
  };
1920
2401
  const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
1921
- useReportError(embed === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
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
+ });
1922
2410
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
1923
2411
  switch (embed.platform) {
1924
2412
  case "x": return /* @__PURE__ */ jsx(XEmbed, {
@@ -2045,6 +2533,45 @@ function SocialEmbed(props) {
2045
2533
  onError,
2046
2534
  embed
2047
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
+ });
2048
2575
  }
2049
2576
  }
2050
- export { AppleMusicEmbed, ApplePodcastsEmbed, BlueskyEmbed, DailymotionEmbed, FacebookEmbed, GiphyEmbed, InstagramEmbed, KickEmbed, LinkedInEmbed, PinterestEmbed, RedditEmbed, SnapchatEmbed, SocialEmbed, SoundCloudEmbed, SpotifyEmbed, TelegramEmbed, ThreadsEmbed, TikTokEmbed, TumblrEmbed, TwitchEmbed, VimeoEmbed, XEmbed, YouTubeEmbed };
2577
+ 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 };