social-embeds 0.5.3 → 0.6.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
@@ -16,8 +16,151 @@ function needsLookup(url) {
16
16
  const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
17
17
  return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
18
18
  }
19
- // src/components/hooks.ts
19
+ // src/parser/verify.ts
20
+ const SHAPES = {
21
+ x: ["post sdk"],
22
+ instagram: ["post sdk"],
23
+ threads: ["post sdk"],
24
+ facebook: [
25
+ "post sdk",
26
+ "video sdk",
27
+ "video iframe"
28
+ ],
29
+ tiktok: ["video iframe"],
30
+ youtube: ["video iframe"],
31
+ telegram: ["post iframe"],
32
+ snapchat: ["post iframe", "video iframe"],
33
+ linkedin: ["post iframe"],
34
+ reddit: ["post iframe"],
35
+ pinterest: ["post sdk"],
36
+ spotify: ["post iframe", "video iframe"],
37
+ vimeo: ["video iframe"],
38
+ twitch: ["video iframe"],
39
+ dailymotion: ["video iframe"],
40
+ bluesky: ["post iframe"],
41
+ soundcloud: ["post iframe"],
42
+ applemusic: ["post iframe"],
43
+ applepodcasts: ["post iframe"],
44
+ tumblr: ["post iframe"],
45
+ kick: ["video iframe"],
46
+ giphy: ["video iframe"]
47
+ };
48
+ /**
49
+ * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
50
+ * into the page: only what this parser itself produces passes (docs/decisions.md D35).
51
+ */
52
+ function verifyEmbed(embed) {
53
+ const matched = matchUrl(embed.url);
54
+ if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
55
+ if (matched.url !== embed.url) return null;
56
+ if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
57
+ if (embed.fallbackHtml === void 0) return embed;
58
+ if (trustedFallback(embed, embed.fallbackHtml)) return embed;
59
+ const withoutFallback = { ...embed };
60
+ delete withoutFallback.fallbackHtml;
61
+ return withoutFallback;
62
+ }
63
+ function trustedFallback(embed, fallbackHtml) {
64
+ const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
65
+ const nodes = parseHtml(fallbackHtml);
66
+ if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
67
+ if (embed.platform !== "x") return true;
68
+ const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
69
+ return root?.type === "element" && x$1.parse(root)?.id === embed.id;
70
+ }
71
+ // src/core/resolve.ts
72
+ const NAMES = {
73
+ x: "X",
74
+ instagram: "Instagram",
75
+ facebook: "Facebook",
76
+ threads: "Threads",
77
+ tiktok: "TikTok",
78
+ youtube: "YouTube",
79
+ telegram: "Telegram",
80
+ snapchat: "Snapchat",
81
+ linkedin: "LinkedIn",
82
+ reddit: "Reddit",
83
+ pinterest: "Pinterest",
84
+ spotify: "Spotify",
85
+ vimeo: "Vimeo",
86
+ twitch: "Twitch",
87
+ dailymotion: "Dailymotion",
88
+ bluesky: "Bluesky",
89
+ soundcloud: "SoundCloud",
90
+ applemusic: "Apple Music",
91
+ applepodcasts: "Apple Podcasts",
92
+ tumblr: "Tumblr",
93
+ kick: "Kick",
94
+ giphy: "Giphy"
95
+ };
96
+ /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
97
+ function lookupMessage(platform) {
98
+ return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
99
+ }
100
+ function resolveEmbed(url, given, platform) {
101
+ const embed = given ?? (url === void 0 ? null : matchUrl(url));
102
+ if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
103
+ if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
104
+ if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
105
+ const verified = verifyEmbed(embed);
106
+ if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
107
+ return { embed: verified };
108
+ }
109
+ /** The message `<SocialEmbed>` reports when its input matches no platform. */
110
+ function sourceError(source) {
111
+ if ("html" in source) return "social-embeds: unrecognised embed code";
112
+ const lookup = needsLookup(source.url);
113
+ return lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${source.url}`;
114
+ }
115
+ // src/core/plans/apple.ts
116
+ const ALLOW$9 = "autoplay *; encrypted-media *; fullscreen *; clipboard-write";
117
+ const SANDBOX$1 = "allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation";
118
+ const SINGLE_HEIGHT = 175;
119
+ const EPISODE_HEIGHT = 160;
120
+ const FULL_HEIGHT$1 = 450;
121
+ /** A fixed height: the embed code's, else 175px for a song and 450px for the rest. */
122
+ function appleMusicPlan(embed) {
123
+ const path = embed.url.slice(23);
124
+ const single = path.includes("/song/") || path.includes("?i=");
125
+ return {
126
+ kind: "iframe",
127
+ src: `https://embed.music.apple.com${path}`,
128
+ title: "Apple Music player",
129
+ allow: ALLOW$9,
130
+ sandbox: SANDBOX$1,
131
+ ratio: {
132
+ width: 16,
133
+ height: 9
134
+ },
135
+ height: embed.size?.height ?? (single ? SINGLE_HEIGHT : FULL_HEIGHT$1),
136
+ maxWidth: 660,
137
+ borderRadius: 10
138
+ };
139
+ }
140
+ /** A fixed height: the embed code's, else 160px for an episode and 450px for a show. */
141
+ function applePodcastsPlan(embed) {
142
+ const path = embed.url.slice(26);
143
+ return {
144
+ kind: "iframe",
145
+ src: `https://embed.podcasts.apple.com${path}`,
146
+ title: "Apple Podcasts player",
147
+ allow: ALLOW$9,
148
+ sandbox: SANDBOX$1,
149
+ ratio: {
150
+ width: 16,
151
+ height: 9
152
+ },
153
+ height: embed.size?.height ?? (path.includes("?i=") ? EPISODE_HEIGHT : FULL_HEIGHT$1),
154
+ maxWidth: 640,
155
+ borderRadius: 12
156
+ };
157
+ }
158
+ // src/core/timing.ts
20
159
  const ROOT_MARGIN = "200px 0px";
160
+ const HEIGHT_TIMEOUT_MS = 15e3;
161
+ const RENDER_TIMEOUT_MS = 15e3;
162
+ const RETRY_DELAY_MS$1 = 1e3;
163
+ // src/components/hooks.ts
21
164
  /** False on the server and in the first client render, so the markup matches on hydration. */
22
165
  function useNearViewport(ref, lazy) {
23
166
  const [near, setNear] = useState(false);
@@ -50,14 +193,40 @@ function useReportError(message, onError) {
50
193
  if (message !== void 0) latest.current?.(new Error(message));
51
194
  }, [message]);
52
195
  }
196
+ // src/core/layout.ts
197
+ /** The iframe wrapper's style, without the host's `style`. Numbers are pixels. */
198
+ function frameStyle(plan, layout, reportedHeight) {
199
+ const { width = "100%", maxHeight } = layout;
200
+ const height = layout.height ?? plan.height;
201
+ const maxWidth = layout.maxWidth ?? plan.maxWidth;
202
+ const aspectWidth = plan.size?.width ?? plan.ratio.width;
203
+ const aspectHeight = plan.size?.height ?? plan.ratio.height;
204
+ const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
205
+ return {
206
+ position: "relative",
207
+ width,
208
+ maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
209
+ ...plan.messageHeight ? { height: reportedHeight ?? plan.startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
210
+ height,
211
+ maxHeight
212
+ },
213
+ ...plan.borderRadius === void 0 ? {} : {
214
+ borderRadius: plan.borderRadius,
215
+ overflow: "hidden"
216
+ }
217
+ };
218
+ }
53
219
  // src/components/iframe-embed.tsx
220
+ /** The plan's fields as `IframeEmbed` props. */
221
+ function planProps(plan) {
222
+ const { kind, fallbackHtml, ...props } = plan;
223
+ return props;
224
+ }
54
225
  const FILL = {
55
226
  position: "absolute",
56
227
  inset: 0
57
228
  };
58
- const HEIGHT_TIMEOUT_MS = 15e3;
59
- const MAX_REPORTED_HEIGHT = 5e4;
60
- function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, width = "100%", maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
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 }) {
61
230
  const frame = useRef(null);
62
231
  const iframe = useRef(null);
63
232
  const near = useNearViewport(frame, lazy);
@@ -95,7 +264,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
95
264
  } catch {
96
265
  return;
97
266
  }
98
- if (typeof value !== "number" || !(value > 0 && value <= MAX_REPORTED_HEIGHT)) return;
267
+ if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
99
268
  heard.current = true;
100
269
  setReportedHeight(Math.ceil(value));
101
270
  report();
@@ -125,17 +294,23 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
125
294
  messageHeight,
126
295
  title
127
296
  ]);
128
- const aspectWidth = size?.width ?? ratio.width;
129
- const aspectHeight = size?.height ?? ratio.height;
130
- const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
131
297
  const wrapper = {
132
- position: "relative",
133
- width,
134
- maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
135
- ...messageHeight ? { height: reportedHeight ?? startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
298
+ ...frameStyle({
299
+ kind: "iframe",
300
+ src,
301
+ title,
302
+ allow,
303
+ ratio,
304
+ size,
305
+ messageHeight,
306
+ startHeight,
307
+ borderRadius
308
+ }, {
309
+ width,
310
+ maxWidth,
136
311
  height,
137
312
  maxHeight
138
- },
313
+ }, reportedHeight),
139
314
  ...style
140
315
  };
141
316
  return /* @__PURE__ */ jsx("div", {
@@ -183,96 +358,7 @@ function Skeleton({ minHeight }) {
183
358
  }
184
359
  });
185
360
  }
186
- // src/parser/verify.ts
187
- const SHAPES = {
188
- x: ["post sdk"],
189
- instagram: ["post sdk"],
190
- threads: ["post sdk"],
191
- facebook: [
192
- "post sdk",
193
- "video sdk",
194
- "video iframe"
195
- ],
196
- tiktok: ["video iframe"],
197
- youtube: ["video iframe"],
198
- telegram: ["post iframe"],
199
- snapchat: ["post iframe", "video iframe"],
200
- linkedin: ["post iframe"],
201
- reddit: ["post iframe"],
202
- pinterest: ["post sdk"],
203
- spotify: ["post iframe", "video iframe"],
204
- vimeo: ["video iframe"],
205
- twitch: ["video iframe"],
206
- dailymotion: ["video iframe"],
207
- bluesky: ["post iframe"],
208
- soundcloud: ["post iframe"],
209
- applemusic: ["post iframe"],
210
- applepodcasts: ["post iframe"],
211
- tumblr: ["post iframe"],
212
- kick: ["video iframe"],
213
- giphy: ["video iframe"]
214
- };
215
- /**
216
- * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
217
- * into the page: only what this parser itself produces passes (docs/decisions.md D35).
218
- */
219
- function verifyEmbed(embed) {
220
- const matched = matchUrl(embed.url);
221
- if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
222
- if (matched.url !== embed.url) return null;
223
- if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
224
- if (embed.fallbackHtml === void 0) return embed;
225
- if (trustedFallback(embed, embed.fallbackHtml)) return embed;
226
- const withoutFallback = { ...embed };
227
- delete withoutFallback.fallbackHtml;
228
- return withoutFallback;
229
- }
230
- function trustedFallback(embed, fallbackHtml) {
231
- const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
232
- const nodes = parseHtml(fallbackHtml);
233
- if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
234
- if (embed.platform !== "x") return true;
235
- const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
236
- return root?.type === "element" && x$1.parse(root)?.id === embed.id;
237
- }
238
- // src/components/shared.ts
239
- const NAMES = {
240
- x: "X",
241
- instagram: "Instagram",
242
- facebook: "Facebook",
243
- threads: "Threads",
244
- tiktok: "TikTok",
245
- youtube: "YouTube",
246
- telegram: "Telegram",
247
- snapchat: "Snapchat",
248
- linkedin: "LinkedIn",
249
- reddit: "Reddit",
250
- pinterest: "Pinterest",
251
- spotify: "Spotify",
252
- vimeo: "Vimeo",
253
- twitch: "Twitch",
254
- dailymotion: "Dailymotion",
255
- bluesky: "Bluesky",
256
- soundcloud: "SoundCloud",
257
- applemusic: "Apple Music",
258
- applepodcasts: "Apple Podcasts",
259
- tumblr: "Tumblr",
260
- kick: "Kick",
261
- giphy: "Giphy"
262
- };
263
- /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
264
- function lookupMessage(platform) {
265
- return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
266
- }
267
- function resolveEmbed(url, given, platform) {
268
- const embed = given ?? (url === void 0 ? null : matchUrl(url));
269
- if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
270
- if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
271
- if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
272
- const verified = verifyEmbed(embed);
273
- if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
274
- return { embed: verified };
275
- }
361
+ // src/core/params.ts
276
362
  /**
277
363
  * Security: options are not verified (docs/decisions.md D68). Keys that choose the content
278
364
  * come only from the verified url and id.
@@ -298,67 +384,37 @@ function playerParams(props, names) {
298
384
  return params;
299
385
  }
300
386
  // src/components/apple-embed.tsx
301
- const ALLOW$9 = "autoplay *; encrypted-media *; fullscreen *; clipboard-write";
302
- const SANDBOX$1 = "allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation";
303
- const SINGLE_HEIGHT = 175;
304
- const EPISODE_HEIGHT = 160;
305
- const FULL_HEIGHT$1 = 450;
306
387
  /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
307
388
  function AppleMusicEmbed(props) {
308
- const { url, embed: given, onError, height, maxWidth = 660, style, ...frame } = props;
389
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
309
390
  const { embed, error } = resolveEmbed(url, given, "applemusic");
310
- useReportError(error, onError);
311
- if (!embed) return null;
312
- const path = embed.url.slice(23);
313
- const single = path.includes("/song/") || path.includes("?i=");
391
+ const plan = embed ? appleMusicPlan(embed) : void 0;
392
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
393
+ if (plan?.kind !== "iframe") return null;
314
394
  return /* @__PURE__ */ jsx(IframeEmbed, {
315
395
  ...frame,
396
+ ...planProps(plan),
316
397
  onError,
317
- maxWidth,
318
- style: {
319
- borderRadius: 10,
320
- overflow: "hidden",
321
- ...style
322
- },
323
- height: height ?? embed.size?.height ?? (single ? SINGLE_HEIGHT : FULL_HEIGHT$1),
324
- src: `https://embed.music.apple.com${path}`,
325
- title: "Apple Music player",
326
- allow: ALLOW$9,
327
- sandbox: SANDBOX$1,
328
- ratio: {
329
- width: 16,
330
- height: 9
331
- }
398
+ maxWidth: maxWidth ?? plan.maxWidth,
399
+ height: height ?? plan.height
332
400
  });
333
401
  }
334
402
  /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
335
403
  function ApplePodcastsEmbed(props) {
336
- const { url, embed: given, onError, height, maxWidth = 640, style, ...frame } = props;
404
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
337
405
  const { embed, error } = resolveEmbed(url, given, "applepodcasts");
338
- useReportError(error, onError);
339
- if (!embed) return null;
340
- const path = embed.url.slice(26);
406
+ const plan = embed ? applePodcastsPlan(embed) : void 0;
407
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
408
+ if (plan?.kind !== "iframe") return null;
341
409
  return /* @__PURE__ */ jsx(IframeEmbed, {
342
410
  ...frame,
343
- onError,
344
- maxWidth,
345
- style: {
346
- borderRadius: 12,
347
- overflow: "hidden",
348
- ...style
349
- },
350
- height: height ?? embed.size?.height ?? (path.includes("?i=") ? EPISODE_HEIGHT : FULL_HEIGHT$1),
351
- src: `https://embed.podcasts.apple.com${path}`,
352
- title: "Apple Podcasts player",
353
- allow: ALLOW$9,
354
- sandbox: SANDBOX$1,
355
- ratio: {
356
- width: 16,
357
- height: 9
358
- }
411
+ ...planProps(plan),
412
+ onError,
413
+ maxWidth: maxWidth ?? plan.maxWidth,
414
+ height: height ?? plan.height
359
415
  });
360
416
  }
361
- // src/components/bluesky-embed.tsx
417
+ // src/core/plans/bluesky.ts
362
418
  /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
363
419
  const BLUESKY_HEIGHT = {
364
420
  origin: "https://embed.bsky.app",
@@ -367,23 +423,15 @@ const BLUESKY_HEIGHT = {
367
423
  return typeof height === "number" ? height : void 0;
368
424
  }
369
425
  };
370
- const START_HEIGHT$2 = 300;
371
426
  /**
372
427
  * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
373
428
  * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
374
429
  * render: a handle URL needs a lookup, and `onError` says so.
375
430
  */
376
- function BlueskyEmbed(props) {
377
- const { url, embed: given, onError, maxWidth = 600, colorMode, placeholder, ...shared } = props;
378
- const { embed, error } = resolveEmbed(url, given, "bluesky");
379
- useReportError(error, onError);
380
- if (!embed) return null;
381
- const mode = colorMode ?? embed.options.colorMode;
382
- return /* @__PURE__ */ jsx(IframeEmbed, {
383
- ...shared,
384
- onError,
385
- maxWidth,
386
- placeholder: placeholder ?? (embed.fallbackHtml === void 0 ? void 0 : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: embed.fallbackHtml } })),
431
+ function blueskyPlan(embed, options) {
432
+ const mode = options.colorMode ?? embed.options.colorMode;
433
+ return {
434
+ kind: "iframe",
387
435
  src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
388
436
  title: "Bluesky post",
389
437
  allow: "",
@@ -393,32 +441,58 @@ function BlueskyEmbed(props) {
393
441
  height: 1
394
442
  },
395
443
  messageHeight: BLUESKY_HEIGHT,
396
- startHeight: START_HEIGHT$2
444
+ startHeight: 300,
445
+ maxWidth: 600,
446
+ fallbackHtml: embed.fallbackHtml
447
+ };
448
+ }
449
+ // src/components/bluesky-embed.tsx
450
+ /**
451
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
452
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
453
+ * render: a handle URL needs a lookup, and `onError` says so.
454
+ */
455
+ function BlueskyEmbed(props) {
456
+ const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
457
+ const { embed, error } = resolveEmbed(url, given, "bluesky");
458
+ const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
459
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
460
+ if (plan?.kind !== "iframe") return null;
461
+ const { fallbackHtml } = plan;
462
+ return /* @__PURE__ */ jsx(IframeEmbed, {
463
+ ...shared,
464
+ ...planProps(plan),
465
+ onError,
466
+ maxWidth: maxWidth ?? plan.maxWidth,
467
+ placeholder: placeholder ?? (fallbackHtml === void 0 ? void 0 : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } }))
397
468
  });
398
469
  }
399
- // src/components/dailymotion-embed.tsx
470
+ // src/core/plans/dailymotion.ts
400
471
  const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
401
472
  const ALLOW$8 = "autoplay; fullscreen; picture-in-picture; web-share";
402
473
  /**
403
474
  * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
404
- * prop, never another account's (docs/decisions.md D63).
475
+ * option, never another account's (docs/decisions.md D63).
405
476
  */
406
- function DailymotionEmbed(props) {
407
- const { url, embed: given, onError, playerId, mute, startTime, loop, ...frame } = props;
408
- const resolved = resolveEmbed(url, given, "dailymotion");
409
- const { playerId: parsedPlayer, ...parsed } = resolved.embed?.options ?? {};
477
+ function dailymotionPlan(embed, options) {
478
+ const { playerId, mute, startTime, loop } = options;
479
+ const { playerId: parsedPlayer, ...parsed } = embed.options;
410
480
  const player = playerId ?? parsedPlayer;
411
- const error = resolved.error ?? (player === void 0 ? "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed" : typeof player !== "string" || !PLAYER_ID.test(player) ? `social-embeds: not a Dailymotion Player ID: ${String(player)}` : void 0);
412
- useReportError(error, onError);
413
- const { embed } = resolved;
414
- if (!embed || error) return null;
481
+ if (player === void 0) return {
482
+ kind: "error",
483
+ message: "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed"
484
+ };
485
+ if (typeof player !== "string" || !PLAYER_ID.test(player)) return {
486
+ kind: "error",
487
+ message: `social-embeds: not a Dailymotion Player ID: ${String(player)}`
488
+ };
415
489
  const params = [];
416
490
  if (mute !== void 0) params.push(["mute", String(mute)]);
417
491
  if (startTime !== void 0) params.push(["startTime", startTime]);
418
492
  if (loop !== void 0) params.push(["loop", String(loop)]);
419
- return /* @__PURE__ */ jsx(IframeEmbed, {
420
- ...frame,
421
- src: `https://geo.dailymotion.com/player/${String(player)}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
493
+ return {
494
+ kind: "iframe",
495
+ src: `https://geo.dailymotion.com/player/${player}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
422
496
  title: "Dailymotion video player",
423
497
  allow: ALLOW$8,
424
498
  ratio: {
@@ -426,11 +500,33 @@ function DailymotionEmbed(props) {
426
500
  height: 9
427
501
  },
428
502
  size: embed.size
503
+ };
504
+ }
505
+ // src/components/dailymotion-embed.tsx
506
+ /**
507
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
508
+ * prop, never another account's (docs/decisions.md D63).
509
+ */
510
+ function DailymotionEmbed(props) {
511
+ const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
512
+ const { embed, error } = resolveEmbed(url, given, "dailymotion");
513
+ const plan = embed ? dailymotionPlan(embed, {
514
+ playerId,
515
+ mute,
516
+ startTime,
517
+ loop
518
+ }) : void 0;
519
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
520
+ if (plan?.kind !== "iframe") return null;
521
+ return /* @__PURE__ */ jsx(IframeEmbed, {
522
+ ...frame,
523
+ ...planProps(plan),
524
+ maxWidth: maxWidth ?? plan.maxWidth
429
525
  });
430
526
  }
431
527
  // src/loader/load-script.ts
432
- const ATTEMPTS$1 = 3;
433
- const RETRY_DELAY_MS$1 = 1e3;
528
+ const ATTEMPTS = 3;
529
+ const RETRY_DELAY_MS = 1e3;
434
530
  const TIMEOUT_MS = 15e3;
435
531
  const POLL_MS = 50;
436
532
  const loading = /* @__PURE__ */ new Map();
@@ -456,11 +552,11 @@ async function add(script) {
456
552
  const ready = script.readyCallback?.();
457
553
  for (let attempt = 1;; attempt++) try {
458
554
  const element = await insert(script);
459
- if (attempt >= ATTEMPTS$1 || !script.skipped?.()) break;
555
+ if (attempt >= ATTEMPTS || !script.skipped?.()) break;
460
556
  element.remove();
461
557
  } catch (error) {
462
- if (!(error instanceof LoadError) || attempt >= ATTEMPTS$1) throw error;
463
- await delay(RETRY_DELAY_MS$1 * 2 ** (attempt - 1));
558
+ if (!(error instanceof LoadError) || attempt >= ATTEMPTS) throw error;
559
+ await delay(RETRY_DELAY_MS * 2 ** (attempt - 1));
464
560
  }
465
561
  await (ready ? timeout(ready, `${script.url} did not report ready`) : poll(script));
466
562
  }
@@ -602,7 +698,7 @@ function loadPlatformScript(platform, { locale = "en_US" } = {}) {
602
698
  case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
603
699
  }
604
700
  }
605
- // src/components/drivers.ts
701
+ // src/core/drivers.ts
606
702
  const globals = () => window;
607
703
  function watch(container, rendered, done) {
608
704
  if (rendered(container)) {
@@ -718,24 +814,7 @@ const pinterestDriver = {
718
814
  return stop;
719
815
  }
720
816
  };
721
- // src/components/facebook-video-iframe.tsx
722
- const ALLOW$7 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
723
- function FacebookVideoIframe({ embed, ...frame }) {
724
- const params = Object.entries(embed.options).filter(([key]) => key !== "href");
725
- return /* @__PURE__ */ jsx(IframeEmbed, {
726
- ...frame,
727
- src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
728
- title: "Facebook video player",
729
- allow: ALLOW$7,
730
- scrolling: "no",
731
- ratio: {
732
- width: 16,
733
- height: 9
734
- },
735
- size: embed.size
736
- });
737
- }
738
- // src/components/markup.ts
817
+ // src/core/markup.ts
739
818
  /** `true` becomes a valueless attribute. */
740
819
  function attributes(entries) {
741
820
  let html = "";
@@ -763,10 +842,81 @@ function withProps(options, props) {
763
842
  function hasFallback(fallbackHtml) {
764
843
  return fallbackHtml !== void 0 && fallbackHtml.trim() !== "";
765
844
  }
845
+ // src/core/plans/facebook.ts
846
+ const ATTRIBUTES$2 = {
847
+ width: "data-width",
848
+ showText: "data-show-text",
849
+ lazy: "data-lazy",
850
+ allowfullscreen: "data-allowfullscreen",
851
+ autoplay: "data-autoplay",
852
+ showCaptions: "data-show-captions"
853
+ };
854
+ const PLAYER_PARAMETERS = {
855
+ showText: "show_text",
856
+ allowfullscreen: "allowfullscreen",
857
+ autoplay: "autoplay",
858
+ showCaptions: "show_captions"
859
+ };
860
+ /** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
861
+ const POST_MAX_WIDTH = 750;
862
+ /** docs/decisions.md D34. */
863
+ const MIN_HEIGHT$4 = {
864
+ post: 300,
865
+ video: 200
866
+ };
867
+ const ALLOW$7 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
868
+ /** Its content fills the iframe at any width, whatever `width` says (docs/decisions.md D29). */
869
+ function facebookVideoPlan(embed) {
870
+ const params = Object.entries(embed.options).filter(([key]) => key !== "href");
871
+ return {
872
+ kind: "iframe",
873
+ src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
874
+ title: "Facebook video player",
875
+ allow: ALLOW$7,
876
+ scrolling: "no",
877
+ ratio: {
878
+ width: 16,
879
+ height: 9
880
+ },
881
+ size: embed.size
882
+ };
883
+ }
884
+ function facebookPlan(embed, options) {
885
+ if (embed.variant === "iframe") return facebookVideoPlan(embed);
886
+ const merged = withProps(embed.options, {
887
+ showText: options.showText,
888
+ allowfullscreen: options.allowfullscreen,
889
+ autoplay: options.autoplay,
890
+ showCaptions: options.showCaptions
891
+ });
892
+ const { size } = embed;
893
+ if (embed.kind === "video" && merged.showText === false && size?.width !== void 0 && size.height !== void 0) {
894
+ const parameters = {};
895
+ for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
896
+ const value = merged[option];
897
+ if (value !== void 0) parameters[name] = value;
898
+ }
899
+ parameters.width = size.width;
900
+ parameters.height = size.height;
901
+ return facebookVideoPlan({
902
+ ...embed,
903
+ options: parameters
904
+ });
905
+ }
906
+ const sdkLocale = options.locale ?? (typeof merged.locale === "string" ? merged.locale : "en_US");
907
+ const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, merged)}>${embed.fallbackHtml ?? ""}</div>`;
908
+ return {
909
+ kind: "script",
910
+ key: `${sdkLocale} ${markup}`,
911
+ markup,
912
+ driver: facebookDriver(sdkLocale),
913
+ minHeight: MIN_HEIGHT$4[embed.kind],
914
+ label: "Facebook",
915
+ hasFallback: hasFallback(embed.fallbackHtml),
916
+ maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0
917
+ };
918
+ }
766
919
  // src/components/script-embed.tsx
767
- const ATTEMPTS = 3;
768
- const RENDER_TIMEOUT_MS = 15e3;
769
- const RETRY_DELAY_MS = 1e3;
770
920
  function toError(error) {
771
921
  return error instanceof Error ? error : new Error(String(error));
772
922
  }
@@ -803,13 +953,13 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
803
953
  if (cancelled || done) return;
804
954
  stop();
805
955
  stop = () => {};
806
- if (number >= ATTEMPTS) {
956
+ if (number >= 3) {
807
957
  callbacks.current.onError?.(error);
808
958
  return;
809
959
  }
810
960
  timer = setTimeout(() => {
811
961
  attempt(number + 1);
812
- }, RETRY_DELAY_MS * 2 ** (number - 1));
962
+ }, RETRY_DELAY_MS$1 * 2 ** (number - 1));
813
963
  };
814
964
  const attempt = (number) => {
815
965
  if (cancelled || done) return;
@@ -854,88 +1004,41 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
854
1004
  });
855
1005
  }
856
1006
  // src/components/facebook-embed.tsx
857
- const ATTRIBUTES$2 = {
858
- width: "data-width",
859
- showText: "data-show-text",
860
- lazy: "data-lazy",
861
- allowfullscreen: "data-allowfullscreen",
862
- autoplay: "data-autoplay",
863
- showCaptions: "data-show-captions"
864
- };
865
- const PLAYER_PARAMETERS = {
866
- showText: "show_text",
867
- allowfullscreen: "allowfullscreen",
868
- autoplay: "autoplay",
869
- showCaptions: "show_captions"
870
- };
871
- /** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
872
- const POST_MAX_WIDTH = 750;
873
- /** docs/decisions.md D34. */
874
- const MIN_HEIGHT$4 = {
875
- post: 300,
876
- video: 200
877
- };
878
1007
  function FacebookEmbed(props) {
879
- const { url, embed: given, onError, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
1008
+ const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
880
1009
  const { embed, error } = resolveEmbed(url, given, "facebook");
881
- useReportError(error, onError);
882
- if (!embed) return null;
883
- const frame = {
884
- height,
885
- maxHeight
886
- };
887
- if (embed.variant === "iframe") return /* @__PURE__ */ jsx(FacebookVideoIframe, {
888
- ...shared,
889
- ...frame,
890
- embed
891
- });
892
- const options = withProps(embed.options, {
1010
+ const plan = embed ? facebookPlan(embed, {
1011
+ locale,
893
1012
  showText,
894
1013
  allowfullscreen,
895
1014
  autoplay,
896
1015
  showCaptions
1016
+ }) : void 0;
1017
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1018
+ if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
1019
+ ...shared,
1020
+ ...planProps(plan),
1021
+ maxWidth: maxWidth ?? plan.maxWidth,
1022
+ height,
1023
+ maxHeight
897
1024
  });
898
- const { size } = embed;
899
- if (embed.kind === "video" && options.showText === false && size?.width !== void 0 && size.height !== void 0) {
900
- const parameters = {};
901
- for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
902
- const value = options[option];
903
- if (value !== void 0) parameters[name] = value;
904
- }
905
- parameters.width = size.width;
906
- parameters.height = size.height;
907
- return /* @__PURE__ */ jsx(FacebookVideoIframe, {
908
- ...shared,
909
- ...frame,
910
- embed: {
911
- ...embed,
912
- options: parameters
913
- }
914
- });
915
- }
916
- const sdkLocale = locale ?? (typeof options.locale === "string" ? options.locale : "en_US");
917
- const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, options)}>${embed.fallbackHtml ?? ""}</div>`;
1025
+ if (plan?.kind !== "script") return null;
918
1026
  return /* @__PURE__ */ jsx(ScriptEmbed, {
919
- maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0,
920
1027
  ...shared,
921
1028
  onError,
922
- driver: facebookDriver(sdkLocale),
923
- markup,
924
- hasFallback: hasFallback(embed.fallbackHtml),
925
- minHeight: MIN_HEIGHT$4[embed.kind],
926
- label: "Facebook"
927
- }, `${sdkLocale} ${markup}`);
1029
+ maxWidth: maxWidth ?? plan.maxWidth,
1030
+ driver: plan.driver,
1031
+ markup: plan.markup,
1032
+ hasFallback: plan.hasFallback,
1033
+ minHeight: plan.minHeight,
1034
+ label: plan.label
1035
+ }, plan.key);
928
1036
  }
929
- // src/components/giphy-embed.tsx
1037
+ // src/core/plans/giphy.ts
930
1038
  /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
931
- function GiphyEmbed(props) {
932
- const { url, embed: given, onError, ...frame } = props;
933
- const { embed, error } = resolveEmbed(url, given, "giphy");
934
- useReportError(error, onError);
935
- if (!embed) return null;
936
- return /* @__PURE__ */ jsx(IframeEmbed, {
937
- ...frame,
938
- onError,
1039
+ function giphyPlan(embed) {
1040
+ return {
1041
+ kind: "iframe",
939
1042
  src: `https://giphy.com/embed/${embed.id}`,
940
1043
  title: "Giphy GIF",
941
1044
  allow: "fullscreen",
@@ -944,50 +1047,74 @@ function GiphyEmbed(props) {
944
1047
  height: 1
945
1048
  },
946
1049
  size: embed.size
1050
+ };
1051
+ }
1052
+ // src/components/giphy-embed.tsx
1053
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
1054
+ function GiphyEmbed(props) {
1055
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
1056
+ const { embed, error } = resolveEmbed(url, given, "giphy");
1057
+ const plan = embed ? giphyPlan(embed) : void 0;
1058
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1059
+ if (plan?.kind !== "iframe") return null;
1060
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1061
+ ...frame,
1062
+ ...planProps(plan),
1063
+ onError,
1064
+ maxWidth: maxWidth ?? plan.maxWidth
947
1065
  });
948
1066
  }
949
- // src/components/instagram-embed.tsx
1067
+ // src/core/plans/instagram.ts
950
1068
  /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
951
1069
  const MIN_HEIGHT$3 = 680;
952
1070
  const FLUID_WIDTH = "width:calc(100% - 2px)";
953
- function InstagramEmbed(props) {
954
- const { url, embed: given, onError, maxWidth = 540, captioned, ...shared } = props;
955
- const { embed, error } = resolveEmbed(url, given, "instagram");
956
- useReportError(error, onError);
957
- if (!embed) return null;
958
- const options = withProps(embed.options, { captioned });
1071
+ function instagramPlan(embed, options) {
1072
+ const merged = withProps(embed.options, { captioned: options.captioned });
959
1073
  const markup = `<blockquote${attributes({
960
1074
  "data-instgrm-permalink": embed.url,
961
- "data-instgrm-version": options.version,
962
- "data-instgrm-captioned": options.captioned === true ? true : void 0,
1075
+ "data-instgrm-version": merged.version,
1076
+ "data-instgrm-captioned": merged.captioned === true ? true : void 0,
963
1077
  style: FLUID_WIDTH
964
1078
  })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1079
+ return {
1080
+ kind: "script",
1081
+ key: markup,
1082
+ markup,
1083
+ driver: instagramDriver,
1084
+ minHeight: MIN_HEIGHT$3,
1085
+ label: "Instagram",
1086
+ hasFallback: hasFallback(embed.fallbackHtml),
1087
+ maxWidth: 540
1088
+ };
1089
+ }
1090
+ // src/components/instagram-embed.tsx
1091
+ function InstagramEmbed(props) {
1092
+ const { url, embed: given, onError, maxWidth, captioned, ...shared } = props;
1093
+ const { embed, error } = resolveEmbed(url, given, "instagram");
1094
+ const plan = embed ? instagramPlan(embed, { captioned }) : void 0;
1095
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1096
+ if (plan?.kind !== "script") return null;
965
1097
  return /* @__PURE__ */ jsx(ScriptEmbed, {
966
1098
  ...shared,
967
1099
  onError,
968
- maxWidth,
969
- driver: instagramDriver,
970
- markup,
971
- hasFallback: hasFallback(embed.fallbackHtml),
972
- minHeight: MIN_HEIGHT$3,
973
- label: "Instagram"
974
- }, markup);
1100
+ maxWidth: maxWidth ?? plan.maxWidth,
1101
+ driver: plan.driver,
1102
+ markup: plan.markup,
1103
+ hasFallback: plan.hasFallback,
1104
+ minHeight: plan.minHeight,
1105
+ label: plan.label
1106
+ }, plan.key);
975
1107
  }
976
- // src/components/kick-embed.tsx
1108
+ // src/core/plans/kick.ts
977
1109
  const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
978
1110
  /** A live channel at 16:9. */
979
- function KickEmbed(props) {
980
- const { url, embed: given, onError, autoplay, muted, ...frame } = props;
981
- const { embed, error } = resolveEmbed(url, given, "kick");
982
- useReportError(error, onError);
983
- if (!embed) return null;
984
- const fromProps = [];
985
- if (autoplay !== void 0) fromProps.push(["autoplay", autoplay]);
986
- if (muted !== void 0) fromProps.push(["muted", muted]);
987
- return /* @__PURE__ */ jsx(IframeEmbed, {
988
- ...frame,
989
- onError,
990
- src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT.has(key)), fromProps)}`,
1111
+ function kickPlan(embed, options) {
1112
+ const fromOptions = [];
1113
+ if (options.autoplay !== void 0) fromOptions.push(["autoplay", options.autoplay]);
1114
+ if (options.muted !== void 0) fromOptions.push(["muted", options.muted]);
1115
+ return {
1116
+ kind: "iframe",
1117
+ src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT.has(key)), fromOptions)}`,
991
1118
  title: "Kick player",
992
1119
  allow: "autoplay; fullscreen",
993
1120
  scrolling: "no",
@@ -996,34 +1123,63 @@ function KickEmbed(props) {
996
1123
  height: 9
997
1124
  },
998
1125
  size: embed.size
1126
+ };
1127
+ }
1128
+ // src/components/kick-embed.tsx
1129
+ /** A live channel at 16:9. */
1130
+ function KickEmbed(props) {
1131
+ const { url, embed: given, onError, maxWidth, autoplay, muted, ...frame } = props;
1132
+ const { embed, error } = resolveEmbed(url, given, "kick");
1133
+ const plan = embed ? kickPlan(embed, {
1134
+ autoplay,
1135
+ muted
1136
+ }) : void 0;
1137
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1138
+ if (plan?.kind !== "iframe") return null;
1139
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1140
+ ...frame,
1141
+ ...planProps(plan),
1142
+ onError,
1143
+ maxWidth: maxWidth ?? plan.maxWidth
999
1144
  });
1000
1145
  }
1001
- // src/components/linkedin-embed.tsx
1146
+ // src/core/plans/linkedin.ts
1002
1147
  const DEFAULT_HEIGHT = 670;
1003
1148
  const DEFAULT_WIDTH = 504;
1004
- /** A fixed height: the `height` prop, else the embed code's, else 670px. */
1005
- function LinkedInEmbed(props) {
1006
- const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
1007
- const { embed, error } = resolveEmbed(url, given, "linkedin");
1008
- useReportError(error, onError);
1009
- if (!embed) return null;
1149
+ /** A fixed height: the embed code's, else 670px. */
1150
+ function linkedinPlan(embed, options) {
1010
1151
  const params = new Map(Object.entries(embed.options));
1011
- if (collapsed === true) params.set("collapsed", 1);
1012
- if (collapsed === false) params.delete("collapsed");
1013
- return /* @__PURE__ */ jsx(IframeEmbed, {
1014
- ...frame,
1015
- maxWidth: maxWidth ?? embed.size?.width ?? DEFAULT_WIDTH,
1016
- height: height ?? embed.size?.height ?? DEFAULT_HEIGHT,
1152
+ if (options.collapsed === true) params.set("collapsed", 1);
1153
+ if (options.collapsed === false) params.delete("collapsed");
1154
+ return {
1155
+ kind: "iframe",
1017
1156
  src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
1018
1157
  title: "LinkedIn post",
1019
1158
  allow: "",
1020
1159
  ratio: {
1021
1160
  width: DEFAULT_WIDTH,
1022
1161
  height: DEFAULT_HEIGHT
1023
- }
1162
+ },
1163
+ height: embed.size?.height ?? DEFAULT_HEIGHT,
1164
+ maxWidth: embed.size?.width ?? DEFAULT_WIDTH
1165
+ };
1166
+ }
1167
+ // src/components/linkedin-embed.tsx
1168
+ /** A fixed height: the `height` prop, else the embed code's, else 670px. */
1169
+ function LinkedInEmbed(props) {
1170
+ const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
1171
+ const { embed, error } = resolveEmbed(url, given, "linkedin");
1172
+ const plan = embed ? linkedinPlan(embed, { collapsed }) : void 0;
1173
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1174
+ if (plan?.kind !== "iframe") return null;
1175
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1176
+ ...frame,
1177
+ ...planProps(plan),
1178
+ maxWidth: maxWidth ?? plan.maxWidth,
1179
+ height: height ?? plan.height
1024
1180
  });
1025
1181
  }
1026
- // src/components/pinterest-embed.tsx
1182
+ // src/core/plans/pinterest.ts
1027
1183
  const ATTRIBUTES$1 = {
1028
1184
  width: "data-pin-width",
1029
1185
  lang: "data-pin-lang",
@@ -1036,26 +1192,39 @@ const PIN_WIDTHS = {
1036
1192
  };
1037
1193
  const DEFAULT_PIN_WIDTH = 236;
1038
1194
  const MIN_HEIGHT$2 = 270;
1195
+ function pinterestPlan(embed, options) {
1196
+ const merged = withProps(embed.options, { width: options.pinWidth });
1197
+ const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, merged)}></a>`;
1198
+ return {
1199
+ kind: "script",
1200
+ key: markup,
1201
+ markup,
1202
+ driver: pinterestDriver,
1203
+ minHeight: MIN_HEIGHT$2,
1204
+ label: "Pinterest",
1205
+ hasFallback: false,
1206
+ maxWidth: PIN_WIDTHS[String(merged.width)] ?? DEFAULT_PIN_WIDTH
1207
+ };
1208
+ }
1209
+ // src/components/pinterest-embed.tsx
1039
1210
  function PinterestEmbed(props) {
1040
1211
  const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
1041
1212
  const { embed, error } = resolveEmbed(url, given, "pinterest");
1042
- useReportError(error, onError);
1043
- if (!embed) return null;
1044
- const options = withProps(embed.options, { width: pinWidth });
1045
- const pinWidthPx = PIN_WIDTHS[String(options.width)] ?? DEFAULT_PIN_WIDTH;
1046
- const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, options)}></a>`;
1213
+ const plan = embed ? pinterestPlan(embed, { pinWidth }) : void 0;
1214
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1215
+ if (plan?.kind !== "script") return null;
1047
1216
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1048
1217
  ...shared,
1049
1218
  onError,
1050
- maxWidth: maxWidth ?? pinWidthPx,
1051
- driver: pinterestDriver,
1052
- markup,
1053
- hasFallback: false,
1054
- minHeight: MIN_HEIGHT$2,
1055
- label: "Pinterest"
1056
- }, markup);
1219
+ maxWidth: maxWidth ?? plan.maxWidth,
1220
+ driver: plan.driver,
1221
+ markup: plan.markup,
1222
+ hasFallback: plan.hasFallback,
1223
+ minHeight: plan.minHeight,
1224
+ label: plan.label
1225
+ }, plan.key);
1057
1226
  }
1058
- // src/components/reddit-embed.tsx
1227
+ // src/core/plans/reddit.ts
1059
1228
  const PARAMS$5 = {
1060
1229
  theme: "theme",
1061
1230
  showMedia: "showmedia",
@@ -1066,7 +1235,7 @@ const PARAMS$5 = {
1066
1235
  };
1067
1236
  const SANDBOX = "allow-scripts allow-same-origin allow-popups";
1068
1237
  const ALLOW$6 = "clipboard-read; clipboard-write";
1069
- const START_HEIGHT$1 = 316;
1238
+ const START_HEIGHT = 316;
1070
1239
  /** docs/decisions.md D52. */
1071
1240
  const REDDIT_HEIGHT = {
1072
1241
  origin: "https://embed.reddit.com",
@@ -1077,30 +1246,15 @@ const REDDIT_HEIGHT = {
1077
1246
  }
1078
1247
  };
1079
1248
  /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1080
- function RedditEmbed(props) {
1081
- const { url, embed: given, onError, maxWidth = 640, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
1082
- const { embed, error } = resolveEmbed(url, given, "reddit");
1083
- useReportError(error, onError);
1084
- if (!embed) return null;
1249
+ function redditPlan(embed, options) {
1085
1250
  const fromProps = [];
1086
- const values = {
1087
- theme,
1088
- showMedia,
1089
- showTitle,
1090
- showUsername,
1091
- locale,
1092
- depth
1093
- };
1094
1251
  for (const [prop, name] of Object.entries(PARAMS$5)) {
1095
- const value = values[prop];
1252
+ const value = options[prop];
1096
1253
  if (value !== void 0) fromProps.push([name, value]);
1097
1254
  }
1098
- const path = embed.url.slice(22);
1099
- return /* @__PURE__ */ jsx(IframeEmbed, {
1100
- ...shared,
1101
- onError,
1102
- maxWidth,
1103
- src: `https://embed.reddit.com${path}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
1255
+ return {
1256
+ kind: "iframe",
1257
+ src: `https://embed.reddit.com${embed.url.slice(22)}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
1104
1258
  title: "Reddit post",
1105
1259
  allow: ALLOW$6,
1106
1260
  sandbox: SANDBOX,
@@ -1110,21 +1264,39 @@ function RedditEmbed(props) {
1110
1264
  height: 1
1111
1265
  },
1112
1266
  messageHeight: REDDIT_HEIGHT,
1113
- startHeight: embed.size?.height ?? START_HEIGHT$1
1267
+ startHeight: embed.size?.height ?? START_HEIGHT,
1268
+ maxWidth: 640
1269
+ };
1270
+ }
1271
+ // src/components/reddit-embed.tsx
1272
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1273
+ function RedditEmbed(props) {
1274
+ const { url, embed: given, onError, maxWidth, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
1275
+ const { embed, error } = resolveEmbed(url, given, "reddit");
1276
+ const plan = embed ? redditPlan(embed, {
1277
+ theme,
1278
+ showMedia,
1279
+ showTitle,
1280
+ showUsername,
1281
+ locale,
1282
+ depth
1283
+ }) : void 0;
1284
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1285
+ if (plan?.kind !== "iframe") return null;
1286
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1287
+ ...shared,
1288
+ ...planProps(plan),
1289
+ onError,
1290
+ maxWidth: maxWidth ?? plan.maxWidth
1114
1291
  });
1115
1292
  }
1116
- // src/components/snapchat-embed.tsx
1293
+ // src/core/plans/snapchat.ts
1117
1294
  const ALLOW$5 = "autoplay; camera; microphone; clipboard-write;";
1118
1295
  /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1119
- function SnapchatEmbed(props) {
1120
- const { url, embed: given, onError, maxWidth = 416, ...frame } = props;
1121
- const { embed, error } = resolveEmbed(url, given, "snapchat");
1122
- useReportError(error, onError);
1123
- if (!embed) return null;
1296
+ function snapchatPlan(embed) {
1124
1297
  const title = embed.options.title;
1125
- return /* @__PURE__ */ jsx(IframeEmbed, {
1126
- ...frame,
1127
- maxWidth,
1298
+ return {
1299
+ kind: "iframe",
1128
1300
  src: `${embed.url}/embed`,
1129
1301
  title: typeof title === "string" && title !== "" ? title : "Snapchat",
1130
1302
  allow: ALLOW$5,
@@ -1133,10 +1305,25 @@ function SnapchatEmbed(props) {
1133
1305
  width: 416,
1134
1306
  height: 692
1135
1307
  },
1136
- size: embed.size
1308
+ size: embed.size,
1309
+ maxWidth: 416
1310
+ };
1311
+ }
1312
+ // src/components/snapchat-embed.tsx
1313
+ /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1314
+ function SnapchatEmbed(props) {
1315
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
1316
+ const { embed, error } = resolveEmbed(url, given, "snapchat");
1317
+ const plan = embed ? snapchatPlan(embed) : void 0;
1318
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1319
+ if (plan?.kind !== "iframe") return null;
1320
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1321
+ ...frame,
1322
+ ...planProps(plan),
1323
+ maxWidth: maxWidth ?? plan.maxWidth
1137
1324
  });
1138
1325
  }
1139
- // src/components/soundcloud-embed.tsx
1326
+ // src/core/plans/soundcloud.ts
1140
1327
  const PARAMS$4 = {
1141
1328
  visual: "visual",
1142
1329
  color: "color",
@@ -1150,13 +1337,33 @@ const PARAMS$4 = {
1150
1337
  };
1151
1338
  const ALLOW$4 = "autoplay; encrypted-media";
1152
1339
  const URL_HEIGHT = 400;
1340
+ /** A fixed height: the embed code's, else 400px for the visual player. */
1341
+ function soundcloudPlan(embed, options) {
1342
+ const fromOptions = [];
1343
+ for (const [option, name] of Object.entries(PARAMS$4)) {
1344
+ const value = options[option];
1345
+ if (value !== void 0) fromOptions.push([name, value]);
1346
+ }
1347
+ const fromUrl = embed.size === void 0;
1348
+ return {
1349
+ kind: "iframe",
1350
+ src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromOptions)}`,
1351
+ title: "SoundCloud player",
1352
+ allow: ALLOW$4,
1353
+ scrolling: "no",
1354
+ ratio: {
1355
+ width: 16,
1356
+ height: 9
1357
+ },
1358
+ height: embed.size?.height ?? URL_HEIGHT
1359
+ };
1360
+ }
1361
+ // src/components/soundcloud-embed.tsx
1153
1362
  /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
1154
1363
  function SoundCloudEmbed(props) {
1155
- const { url, embed: given, onError, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
1364
+ const { url, embed: given, onError, maxWidth, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
1156
1365
  const { embed, error } = resolveEmbed(url, given, "soundcloud");
1157
- useReportError(error, onError);
1158
- if (!embed) return null;
1159
- const values = {
1366
+ const plan = embed ? soundcloudPlan(embed, {
1160
1367
  visual,
1161
1368
  color,
1162
1369
  autoPlay,
@@ -1166,52 +1373,32 @@ function SoundCloudEmbed(props) {
1166
1373
  showReposts,
1167
1374
  showTeaser,
1168
1375
  showArtwork
1169
- };
1170
- const fromProps = [];
1171
- for (const [prop, name] of Object.entries(PARAMS$4)) {
1172
- const value = values[prop];
1173
- if (value !== void 0) fromProps.push([name, value]);
1174
- }
1175
- const fromUrl = embed.size === void 0;
1376
+ }) : void 0;
1377
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1378
+ if (plan?.kind !== "iframe") return null;
1176
1379
  return /* @__PURE__ */ jsx(IframeEmbed, {
1177
1380
  ...frame,
1381
+ ...planProps(plan),
1178
1382
  onError,
1179
- height: height ?? embed.size?.height ?? URL_HEIGHT,
1180
- src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromProps)}`,
1181
- title: "SoundCloud player",
1182
- allow: ALLOW$4,
1183
- scrolling: "no",
1184
- ratio: {
1185
- width: 16,
1186
- height: 9
1187
- }
1383
+ maxWidth: maxWidth ?? plan.maxWidth,
1384
+ height: height ?? plan.height
1188
1385
  });
1189
1386
  }
1190
- // src/components/spotify-embed.tsx
1387
+ // src/core/plans/spotify.ts
1191
1388
  const ALLOW$3 = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
1192
1389
  const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
1193
1390
  const COMPACT_HEIGHT = 152;
1194
1391
  const FULL_HEIGHT = 352;
1195
1392
  /**
1196
- * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
1197
- * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
1393
+ * A fixed height: the embed code's, else 152px for a track or episode and 352px for the rest.
1394
+ * A video show keeps its 16:9 aspect ratio instead.
1198
1395
  */
1199
- function SpotifyEmbed(props) {
1200
- const { url, embed: given, onError, height, theme, style, ...frame } = props;
1201
- const { embed, error } = resolveEmbed(url, given, "spotify");
1202
- useReportError(error, onError);
1203
- if (!embed) return null;
1396
+ function spotifyPlan(embed, options) {
1204
1397
  const type = new URL(embed.url).pathname.split("/")[1] ?? "";
1205
1398
  const video = embed.kind === "video";
1206
- const params = query(Object.entries(embed.options), theme === void 0 ? void 0 : [["theme", theme]]);
1207
- return /* @__PURE__ */ jsx(IframeEmbed, {
1208
- ...frame,
1209
- style: {
1210
- borderRadius: 12,
1211
- overflow: "hidden",
1212
- ...style
1213
- },
1214
- height: video ? height : height ?? embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT),
1399
+ const params = query(Object.entries(embed.options), options.theme === void 0 ? void 0 : [["theme", options.theme]]);
1400
+ return {
1401
+ kind: "iframe",
1215
1402
  src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
1216
1403
  title: "Spotify Embed",
1217
1404
  allow: ALLOW$3,
@@ -1219,10 +1406,29 @@ function SpotifyEmbed(props) {
1219
1406
  width: 16,
1220
1407
  height: 9
1221
1408
  },
1222
- size: video ? embed.size : void 0
1409
+ size: video ? embed.size : void 0,
1410
+ borderRadius: 12,
1411
+ height: video ? void 0 : embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT)
1412
+ };
1413
+ }
1414
+ // src/components/spotify-embed.tsx
1415
+ /**
1416
+ * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
1417
+ * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
1418
+ */
1419
+ function SpotifyEmbed(props) {
1420
+ const { url, embed: given, onError, height, theme, ...frame } = props;
1421
+ const { embed, error } = resolveEmbed(url, given, "spotify");
1422
+ const plan = embed ? spotifyPlan(embed, { theme }) : void 0;
1423
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1424
+ if (plan?.kind !== "iframe") return null;
1425
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1426
+ ...frame,
1427
+ ...planProps(plan),
1428
+ height: height ?? plan.height
1223
1429
  });
1224
1430
  }
1225
- // src/components/telegram-embed.tsx
1431
+ // src/core/plans/telegram.ts
1226
1432
  const PARAMS$3 = [
1227
1433
  ["comment", "comment"],
1228
1434
  ["userpic", "userpic"],
@@ -1250,11 +1456,8 @@ const TELEGRAM_HEIGHT = {
1250
1456
  }
1251
1457
  };
1252
1458
  /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1253
- function TelegramEmbed(props) {
1254
- const { url, embed: given, onError, maxWidth = 500, userpic, color, dark, darkColor, ...shared } = props;
1255
- const { embed, error } = resolveEmbed(url, given, "telegram");
1256
- useReportError(error, onError);
1257
- if (!embed) return null;
1459
+ function telegramPlan(embed, options) {
1460
+ const { userpic, color, dark, darkColor } = options;
1258
1461
  const values = {
1259
1462
  ...embed.options,
1260
1463
  ...userpic === void 0 ? {} : { userpic },
@@ -1267,10 +1470,8 @@ function TelegramEmbed(props) {
1267
1470
  const value = param(name, values[option]);
1268
1471
  if (value !== void 0) params.push([name, value]);
1269
1472
  }
1270
- return /* @__PURE__ */ jsx(IframeEmbed, {
1271
- ...shared,
1272
- onError,
1273
- maxWidth,
1473
+ return {
1474
+ kind: "iframe",
1274
1475
  src: `${embed.url}${query(params)}`,
1275
1476
  title: "Telegram post",
1276
1477
  allow: "",
@@ -1280,36 +1481,71 @@ function TelegramEmbed(props) {
1280
1481
  height: 1
1281
1482
  },
1282
1483
  messageHeight: TELEGRAM_HEIGHT,
1283
- startHeight: 300
1484
+ startHeight: 300,
1485
+ maxWidth: 500
1486
+ };
1487
+ }
1488
+ // src/components/telegram-embed.tsx
1489
+ /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1490
+ function TelegramEmbed(props) {
1491
+ const { url, embed: given, onError, maxWidth, userpic, color, dark, darkColor, ...shared } = props;
1492
+ const { embed, error } = resolveEmbed(url, given, "telegram");
1493
+ const plan = embed ? telegramPlan(embed, {
1494
+ userpic,
1495
+ color,
1496
+ dark,
1497
+ darkColor
1498
+ }) : void 0;
1499
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1500
+ if (plan?.kind !== "iframe") return null;
1501
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1502
+ ...shared,
1503
+ ...planProps(plan),
1504
+ onError,
1505
+ maxWidth: maxWidth ?? plan.maxWidth
1284
1506
  });
1285
1507
  }
1286
- // src/components/threads-embed.tsx
1508
+ // src/core/plans/threads.ts
1287
1509
  /** A text-only post (docs/decisions.md D34). */
1288
1510
  const MIN_HEIGHT$1 = 240;
1289
- function ThreadsEmbed(props) {
1290
- const { url, embed: given, onError, maxWidth = 658, theme, ...shared } = props;
1291
- const { embed, error } = resolveEmbed(url, given, "threads");
1292
- useReportError(error, onError);
1293
- if (!embed) return null;
1294
- const options = withProps(embed.options, { theme });
1511
+ function threadsPlan(embed, options) {
1512
+ const merged = withProps(embed.options, { theme: options.theme });
1295
1513
  const markup = `<blockquote${attributes({
1296
1514
  "data-text-post-permalink": embed.url,
1297
- "data-text-post-version": options.version ?? 0,
1515
+ "data-text-post-version": merged.version ?? 0,
1298
1516
  id: `ig-tp-${embed.id}`,
1299
- "data-theme": options.theme
1517
+ "data-theme": merged.theme
1300
1518
  })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1519
+ return {
1520
+ kind: "script",
1521
+ key: markup,
1522
+ markup,
1523
+ driver: threadsDriver,
1524
+ minHeight: MIN_HEIGHT$1,
1525
+ label: "Threads",
1526
+ hasFallback: hasFallback(embed.fallbackHtml),
1527
+ maxWidth: 658
1528
+ };
1529
+ }
1530
+ // src/components/threads-embed.tsx
1531
+ function ThreadsEmbed(props) {
1532
+ const { url, embed: given, onError, maxWidth, theme, ...shared } = props;
1533
+ const { embed, error } = resolveEmbed(url, given, "threads");
1534
+ const plan = embed ? threadsPlan(embed, { theme }) : void 0;
1535
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1536
+ if (plan?.kind !== "script") return null;
1301
1537
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1302
1538
  ...shared,
1303
1539
  onError,
1304
- maxWidth,
1305
- driver: threadsDriver,
1306
- markup,
1307
- hasFallback: hasFallback(embed.fallbackHtml),
1308
- minHeight: MIN_HEIGHT$1,
1309
- label: "Threads"
1310
- }, markup);
1540
+ maxWidth: maxWidth ?? plan.maxWidth,
1541
+ driver: plan.driver,
1542
+ markup: plan.markup,
1543
+ hasFallback: plan.hasFallback,
1544
+ minHeight: plan.minHeight,
1545
+ label: plan.label
1546
+ }, plan.key);
1311
1547
  }
1312
- // src/components/tiktok-embed.tsx
1548
+ // src/core/plans/tiktok.ts
1313
1549
  const PARAMS$2 = {
1314
1550
  controls: "controls",
1315
1551
  progressBar: "progress_bar",
@@ -1328,12 +1564,27 @@ const PARAMS$2 = {
1328
1564
  };
1329
1565
  const ALLOW$2 = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
1330
1566
  /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
1567
+ function tiktokPlan(embed, options) {
1568
+ const params = playerParams(options, PARAMS$2);
1569
+ return {
1570
+ kind: "iframe",
1571
+ src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
1572
+ title: "TikTok video player",
1573
+ allow: ALLOW$2,
1574
+ ratio: {
1575
+ width: 9,
1576
+ height: 16
1577
+ },
1578
+ size: embed.size,
1579
+ maxWidth: 325
1580
+ };
1581
+ }
1582
+ // src/components/tiktok-embed.tsx
1583
+ /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
1331
1584
  function TikTokEmbed(props) {
1332
- const { url, embed: given, onError, maxWidth = 325, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
1585
+ const { url, embed: given, onError, maxWidth, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
1333
1586
  const { embed, error } = resolveEmbed(url, given, "tiktok");
1334
- useReportError(error, onError);
1335
- if (!embed) return null;
1336
- const params = playerParams({
1587
+ const plan = embed ? tiktokPlan(embed, {
1337
1588
  controls,
1338
1589
  progressBar,
1339
1590
  playButton,
@@ -1348,21 +1599,16 @@ function TikTokEmbed(props) {
1348
1599
  nativeContextMenu,
1349
1600
  closedCaption,
1350
1601
  forceMuted
1351
- }, PARAMS$2);
1602
+ }) : void 0;
1603
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1604
+ if (plan?.kind !== "iframe") return null;
1352
1605
  return /* @__PURE__ */ jsx(IframeEmbed, {
1353
1606
  ...frame,
1354
- maxWidth,
1355
- src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
1356
- title: "TikTok video player",
1357
- allow: ALLOW$2,
1358
- ratio: {
1359
- width: 9,
1360
- height: 16
1361
- },
1362
- size: embed.size
1607
+ ...planProps(plan),
1608
+ maxWidth: maxWidth ?? plan.maxWidth
1363
1609
  });
1364
1610
  }
1365
- // src/components/tumblr-embed.tsx
1611
+ // src/core/plans/tumblr.ts
1366
1612
  /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
1367
1613
  const TUMBLR_HEIGHT = {
1368
1614
  origin: "https://embed.tumblr.com",
@@ -1373,19 +1619,11 @@ const TUMBLR_HEIGHT = {
1373
1619
  return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
1374
1620
  }
1375
1621
  };
1376
- const START_HEIGHT = 400;
1377
1622
  /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
1378
- function TumblrEmbed(props) {
1379
- const { url, embed: given, onError, maxWidth = 540, ...shared } = props;
1380
- const { embed, error } = resolveEmbed(url, given, "tumblr");
1381
- useReportError(error, onError);
1382
- if (!embed) return null;
1383
- const blog = embed.url.slice(23).split("/")[0] ?? "";
1384
- return /* @__PURE__ */ jsx(IframeEmbed, {
1385
- ...shared,
1386
- onError,
1387
- maxWidth,
1388
- src: `https://embed.tumblr.com/embed/post/${blog}/${embed.id}/v2`,
1623
+ function tumblrPlan(embed) {
1624
+ return {
1625
+ kind: "iframe",
1626
+ src: `https://embed.tumblr.com/embed/post/${embed.url.slice(23).split("/")[0] ?? ""}/${embed.id}/v2`,
1389
1627
  title: "Tumblr post",
1390
1628
  allow: "",
1391
1629
  scrolling: "no",
@@ -1394,10 +1632,26 @@ function TumblrEmbed(props) {
1394
1632
  height: 1
1395
1633
  },
1396
1634
  messageHeight: TUMBLR_HEIGHT,
1397
- startHeight: START_HEIGHT
1635
+ startHeight: 400,
1636
+ maxWidth: 540
1637
+ };
1638
+ }
1639
+ // src/components/tumblr-embed.tsx
1640
+ /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
1641
+ function TumblrEmbed(props) {
1642
+ const { url, embed: given, onError, maxWidth, ...shared } = props;
1643
+ const { embed, error } = resolveEmbed(url, given, "tumblr");
1644
+ const plan = embed ? tumblrPlan(embed) : void 0;
1645
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1646
+ if (plan?.kind !== "iframe") return null;
1647
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1648
+ ...shared,
1649
+ ...planProps(plan),
1650
+ onError,
1651
+ maxWidth: maxWidth ?? plan.maxWidth
1398
1652
  });
1399
1653
  }
1400
- // src/components/twitch-embed.tsx
1654
+ // src/core/plans/twitch.ts
1401
1655
  const RESERVED = [
1402
1656
  "channel",
1403
1657
  "video",
@@ -1413,18 +1667,15 @@ function player(url, id) {
1413
1667
  return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
1414
1668
  }
1415
1669
  /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
1416
- function TwitchEmbed(props) {
1417
- const { url, embed: given, onError, autoplay, muted, time, ...frame } = props;
1418
- const { embed, error } = resolveEmbed(url, given, "twitch");
1419
- useReportError(error, onError);
1420
- if (!embed) return null;
1670
+ function twitchPlan(embed, options) {
1671
+ const { autoplay, muted, time } = options;
1421
1672
  const params = [];
1422
1673
  if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
1423
1674
  if (muted !== void 0) params.push(["muted", String(muted)]);
1424
1675
  if (time !== void 0) params.push(["time", time]);
1425
1676
  const [base, content] = player(embed.url, embed.id);
1426
- return /* @__PURE__ */ jsx(IframeEmbed, {
1427
- ...frame,
1677
+ return {
1678
+ kind: "iframe",
1428
1679
  src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
1429
1680
  title: "Twitch player",
1430
1681
  allow: "",
@@ -1434,9 +1685,27 @@ function TwitchEmbed(props) {
1434
1685
  },
1435
1686
  size: embed.size,
1436
1687
  hostParam: "parent"
1688
+ };
1689
+ }
1690
+ // src/components/twitch-embed.tsx
1691
+ /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
1692
+ function TwitchEmbed(props) {
1693
+ const { url, embed: given, onError, maxWidth, autoplay, muted, time, ...frame } = props;
1694
+ const { embed, error } = resolveEmbed(url, given, "twitch");
1695
+ const plan = embed ? twitchPlan(embed, {
1696
+ autoplay,
1697
+ muted,
1698
+ time
1699
+ }) : void 0;
1700
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1701
+ if (plan?.kind !== "iframe") return null;
1702
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1703
+ ...frame,
1704
+ ...planProps(plan),
1705
+ maxWidth: maxWidth ?? plan.maxWidth
1437
1706
  });
1438
1707
  }
1439
- // src/components/vimeo-embed.tsx
1708
+ // src/core/plans/vimeo.ts
1440
1709
  const PARAMS$1 = {
1441
1710
  autopause: "autopause",
1442
1711
  autoplay: "autoplay",
@@ -1457,14 +1726,30 @@ const PARAMS$1 = {
1457
1726
  transparent: "transparent"
1458
1727
  };
1459
1728
  const ALLOW$1 = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
1460
- function VimeoEmbed(props) {
1461
- const { url, embed: given, onError, autopause, autoplay, background, byline, color, controls, dnt, keyboard, loop, muted, pip, playsinline, portrait, quality, speed, title, transparent, t, ...frame } = props;
1462
- const { embed, error } = resolveEmbed(url, given, "vimeo");
1463
- useReportError(error, onError);
1464
- if (!embed) return null;
1729
+ function vimeoPlan(embed, options) {
1730
+ const { t, ...rest } = options;
1465
1731
  const { t: parsedStart, ...parsed } = embed.options;
1466
1732
  const hash = new URL(embed.url).pathname.split("/")[2];
1467
- const params = playerParams({
1733
+ const params = playerParams(rest, PARAMS$1);
1734
+ const start = t ?? parsedStart;
1735
+ return {
1736
+ kind: "iframe",
1737
+ 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))}`}`,
1738
+ title: "Vimeo video player",
1739
+ allow: ALLOW$1,
1740
+ referrerPolicy: "strict-origin-when-cross-origin",
1741
+ ratio: {
1742
+ width: 16,
1743
+ height: 9
1744
+ },
1745
+ size: embed.size
1746
+ };
1747
+ }
1748
+ // src/components/vimeo-embed.tsx
1749
+ function VimeoEmbed(props) {
1750
+ 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;
1751
+ const { embed, error } = resolveEmbed(url, given, "vimeo");
1752
+ const plan = embed ? vimeoPlan(embed, {
1468
1753
  autopause,
1469
1754
  autoplay,
1470
1755
  background,
@@ -1481,23 +1766,18 @@ function VimeoEmbed(props) {
1481
1766
  quality,
1482
1767
  speed,
1483
1768
  title,
1484
- transparent
1485
- }, PARAMS$1);
1486
- const start = t ?? parsedStart;
1769
+ transparent,
1770
+ t
1771
+ }) : void 0;
1772
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1773
+ if (plan?.kind !== "iframe") return null;
1487
1774
  return /* @__PURE__ */ jsx(IframeEmbed, {
1488
1775
  ...frame,
1489
- 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))}`}`,
1490
- title: "Vimeo video player",
1491
- allow: ALLOW$1,
1492
- referrerPolicy: "strict-origin-when-cross-origin",
1493
- ratio: {
1494
- width: 16,
1495
- height: 9
1496
- },
1497
- size: embed.size
1776
+ ...planProps(plan),
1777
+ maxWidth: maxWidth ?? plan.maxWidth
1498
1778
  });
1499
1779
  }
1500
- // src/components/x-embed.tsx
1780
+ // src/core/plans/x.ts
1501
1781
  const ATTRIBUTES = {
1502
1782
  theme: "data-theme",
1503
1783
  conversation: "data-conversation",
@@ -1509,33 +1789,47 @@ const ATTRIBUTES = {
1509
1789
  };
1510
1790
  /** A plain text post, the smallest X renders (docs/decisions.md D34). */
1511
1791
  const MIN_HEIGHT = 250;
1792
+ function xPlan(embed, options) {
1793
+ const merged = withProps(embed.options, { ...options });
1794
+ const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
1795
+ const markup = `<blockquote${dataAttributes(ATTRIBUTES, merged)}>${content}</blockquote>`;
1796
+ return {
1797
+ kind: "script",
1798
+ key: markup,
1799
+ markup,
1800
+ driver: xDriver,
1801
+ minHeight: MIN_HEIGHT,
1802
+ label: "X",
1803
+ hasFallback: hasFallback(embed.fallbackHtml),
1804
+ maxWidth: 550
1805
+ };
1806
+ }
1807
+ // src/components/x-embed.tsx
1512
1808
  function XEmbed(props) {
1513
- const { url, embed: given, onError, maxWidth = 550, theme, conversation, cards, align, lang, dnt, ...shared } = props;
1809
+ const { url, embed: given, onError, maxWidth, theme, conversation, cards, align, lang, dnt, ...shared } = props;
1514
1810
  const { embed, error } = resolveEmbed(url, given, "x");
1515
- useReportError(error, onError);
1516
- if (!embed) return null;
1517
- const options = withProps(embed.options, {
1811
+ const plan = embed ? xPlan(embed, {
1518
1812
  theme,
1519
1813
  conversation,
1520
1814
  cards,
1521
1815
  align,
1522
1816
  lang,
1523
1817
  dnt
1524
- });
1525
- const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
1526
- const markup = `<blockquote${dataAttributes(ATTRIBUTES, options)}>${content}</blockquote>`;
1818
+ }) : void 0;
1819
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1820
+ if (plan?.kind !== "script") return null;
1527
1821
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1528
1822
  ...shared,
1529
1823
  onError,
1530
- maxWidth,
1531
- driver: xDriver,
1532
- markup,
1533
- hasFallback: hasFallback(embed.fallbackHtml),
1534
- minHeight: MIN_HEIGHT,
1535
- label: "X"
1536
- }, markup);
1824
+ maxWidth: maxWidth ?? plan.maxWidth,
1825
+ driver: plan.driver,
1826
+ markup: plan.markup,
1827
+ hasFallback: plan.hasFallback,
1828
+ minHeight: plan.minHeight,
1829
+ label: plan.label
1830
+ }, plan.key);
1537
1831
  }
1538
- // src/components/youtube-embed.tsx
1832
+ // src/core/plans/youtube.ts
1539
1833
  const PARAMS = {
1540
1834
  autoplay: "autoplay",
1541
1835
  ccLangPref: "cc_lang_pref",
@@ -1559,14 +1853,32 @@ const PARAMS = {
1559
1853
  widgetReferrer: "widget_referrer"
1560
1854
  };
1561
1855
  const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
1562
- function YouTubeEmbed(props) {
1563
- const { url, embed: given, onError, autoplay, ccLangPref, ccLoadPolicy, color, controls, disablekb, enablejsapi, end, fs, hl, ivLoadPolicy, list, listType, loop, origin, playlist, playsinline, rel, start, widgetReferrer, nocookie, ...frame } = props;
1564
- const { embed, error } = resolveEmbed(url, given, "youtube");
1565
- useReportError(error, onError);
1566
- if (!embed) return null;
1856
+ function youtubePlan(embed, options) {
1857
+ const { nocookie, ...rest } = options;
1567
1858
  const { nocookie: parsedNocookie, ...parsed } = embed.options;
1568
1859
  const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
1569
- const params = playerParams({
1860
+ const params = playerParams(rest, PARAMS);
1861
+ return {
1862
+ kind: "iframe",
1863
+ src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
1864
+ title: "YouTube video player",
1865
+ allow: ALLOW,
1866
+ referrerPolicy: "strict-origin-when-cross-origin",
1867
+ ratio: embed.url.includes("/shorts/") ? {
1868
+ width: 9,
1869
+ height: 16
1870
+ } : {
1871
+ width: 16,
1872
+ height: 9
1873
+ },
1874
+ size: embed.size
1875
+ };
1876
+ }
1877
+ // src/components/youtube-embed.tsx
1878
+ function YouTubeEmbed(props) {
1879
+ 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;
1880
+ const { embed, error } = resolveEmbed(url, given, "youtube");
1881
+ const plan = embed ? youtubePlan(embed, {
1570
1882
  autoplay,
1571
1883
  ccLangPref,
1572
1884
  ccLoadPolicy,
@@ -1586,22 +1898,15 @@ function YouTubeEmbed(props) {
1586
1898
  playsinline,
1587
1899
  rel,
1588
1900
  start,
1589
- widgetReferrer
1590
- }, PARAMS);
1901
+ widgetReferrer,
1902
+ nocookie
1903
+ }) : void 0;
1904
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1905
+ if (plan?.kind !== "iframe") return null;
1591
1906
  return /* @__PURE__ */ jsx(IframeEmbed, {
1592
1907
  ...frame,
1593
- src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
1594
- title: "YouTube video player",
1595
- allow: ALLOW,
1596
- referrerPolicy: "strict-origin-when-cross-origin",
1597
- ratio: embed.url.includes("/shorts/") ? {
1598
- width: 9,
1599
- height: 16
1600
- } : {
1601
- width: 16,
1602
- height: 9
1603
- },
1604
- size: embed.size
1908
+ ...planProps(plan),
1909
+ maxWidth: maxWidth ?? plan.maxWidth
1605
1910
  });
1606
1911
  }
1607
1912
  // src/components/social-embed.tsx
@@ -1613,9 +1918,7 @@ function SocialEmbed(props) {
1613
1918
  maxHeight
1614
1919
  };
1615
1920
  const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
1616
- const unrecognised = embed === null && !(html !== void 0 && fallback);
1617
- const lookup = html === void 0 ? needsLookup(url) : null;
1618
- useReportError(unrecognised ? html !== void 0 ? "social-embeds: unrecognised embed code" : lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${url}` : void 0, onError);
1921
+ useReportError(embed === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
1619
1922
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
1620
1923
  switch (embed.platform) {
1621
1924
  case "x": return /* @__PURE__ */ jsx(XEmbed, {