social-embeds 0.5.2 → 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,17 +193,45 @@ 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);
233
+ const inView = useNearViewport(frame, !lazy && messageHeight !== void 0);
234
+ const heard = useRef(false);
64
235
  const [loaded, setLoaded] = useState(false);
65
236
  const [reportedHeight, setReportedHeight] = useState();
66
237
  const reported = useRef(false);
@@ -83,7 +254,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
83
254
  useEffect(() => {
84
255
  if (!near || !messageHeight) return;
85
256
  const { origin, read } = messageHeight;
86
- let heard = false;
257
+ heard.current = false;
87
258
  const listen = (event) => {
88
259
  if (event.origin !== origin) return;
89
260
  if (!iframe.current || event.source !== iframe.current.contentWindow) return;
@@ -93,38 +264,53 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
93
264
  } catch {
94
265
  return;
95
266
  }
96
- if (typeof value !== "number" || !(value > 0 && value <= MAX_REPORTED_HEIGHT)) return;
97
- heard = true;
267
+ if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
268
+ heard.current = true;
98
269
  setReportedHeight(Math.ceil(value));
99
270
  report();
100
271
  };
101
272
  window.addEventListener("message", listen);
273
+ return () => {
274
+ window.removeEventListener("message", listen);
275
+ };
276
+ }, [
277
+ near,
278
+ messageHeight,
279
+ report
280
+ ]);
281
+ useEffect(() => {
282
+ if (!near || !inView || !messageHeight) return;
102
283
  const timer = setTimeout(() => {
103
- if (heard) return;
284
+ if (heard.current) return;
104
285
  setLoaded(true);
105
286
  callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} did not report its height`));
106
287
  }, HEIGHT_TIMEOUT_MS);
107
288
  return () => {
108
- window.removeEventListener("message", listen);
109
289
  clearTimeout(timer);
110
290
  };
111
291
  }, [
112
292
  near,
293
+ inView,
113
294
  messageHeight,
114
- title,
115
- report
295
+ title
116
296
  ]);
117
- const aspectWidth = size?.width ?? ratio.width;
118
- const aspectHeight = size?.height ?? ratio.height;
119
- const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
120
297
  const wrapper = {
121
- position: "relative",
122
- width,
123
- maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
124
- ...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,
125
311
  height,
126
312
  maxHeight
127
- },
313
+ }, reportedHeight),
128
314
  ...style
129
315
  };
130
316
  return /* @__PURE__ */ jsx("div", {
@@ -172,96 +358,7 @@ function Skeleton({ minHeight }) {
172
358
  }
173
359
  });
174
360
  }
175
- // src/parser/verify.ts
176
- const SHAPES = {
177
- x: ["post sdk"],
178
- instagram: ["post sdk"],
179
- threads: ["post sdk"],
180
- facebook: [
181
- "post sdk",
182
- "video sdk",
183
- "video iframe"
184
- ],
185
- tiktok: ["video iframe"],
186
- youtube: ["video iframe"],
187
- telegram: ["post iframe"],
188
- snapchat: ["post iframe", "video iframe"],
189
- linkedin: ["post iframe"],
190
- reddit: ["post iframe"],
191
- pinterest: ["post sdk"],
192
- spotify: ["post iframe", "video iframe"],
193
- vimeo: ["video iframe"],
194
- twitch: ["video iframe"],
195
- dailymotion: ["video iframe"],
196
- bluesky: ["post iframe"],
197
- soundcloud: ["post iframe"],
198
- applemusic: ["post iframe"],
199
- applepodcasts: ["post iframe"],
200
- tumblr: ["post iframe"],
201
- kick: ["video iframe"],
202
- giphy: ["video iframe"]
203
- };
204
- /**
205
- * Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
206
- * into the page: only what this parser itself produces passes (docs/decisions.md D35).
207
- */
208
- function verifyEmbed(embed) {
209
- const matched = matchUrl(embed.url);
210
- if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
211
- if (matched.url !== embed.url) return null;
212
- if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
213
- if (embed.fallbackHtml === void 0) return embed;
214
- if (trustedFallback(embed, embed.fallbackHtml)) return embed;
215
- const withoutFallback = { ...embed };
216
- delete withoutFallback.fallbackHtml;
217
- return withoutFallback;
218
- }
219
- function trustedFallback(embed, fallbackHtml) {
220
- const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
221
- const nodes = parseHtml(fallbackHtml);
222
- if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
223
- if (embed.platform !== "x") return true;
224
- const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
225
- return root?.type === "element" && x$1.parse(root)?.id === embed.id;
226
- }
227
- // src/components/shared.ts
228
- const NAMES = {
229
- x: "X",
230
- instagram: "Instagram",
231
- facebook: "Facebook",
232
- threads: "Threads",
233
- tiktok: "TikTok",
234
- youtube: "YouTube",
235
- telegram: "Telegram",
236
- snapchat: "Snapchat",
237
- linkedin: "LinkedIn",
238
- reddit: "Reddit",
239
- pinterest: "Pinterest",
240
- spotify: "Spotify",
241
- vimeo: "Vimeo",
242
- twitch: "Twitch",
243
- dailymotion: "Dailymotion",
244
- bluesky: "Bluesky",
245
- soundcloud: "SoundCloud",
246
- applemusic: "Apple Music",
247
- applepodcasts: "Apple Podcasts",
248
- tumblr: "Tumblr",
249
- kick: "Kick",
250
- giphy: "Giphy"
251
- };
252
- /** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
253
- function lookupMessage(platform) {
254
- return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
255
- }
256
- function resolveEmbed(url, given, platform) {
257
- const embed = given ?? (url === void 0 ? null : matchUrl(url));
258
- if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
259
- if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
260
- if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
261
- const verified = verifyEmbed(embed);
262
- if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
263
- return { embed: verified };
264
- }
361
+ // src/core/params.ts
265
362
  /**
266
363
  * Security: options are not verified (docs/decisions.md D68). Keys that choose the content
267
364
  * come only from the verified url and id.
@@ -287,67 +384,37 @@ function playerParams(props, names) {
287
384
  return params;
288
385
  }
289
386
  // src/components/apple-embed.tsx
290
- const ALLOW$9 = "autoplay *; encrypted-media *; fullscreen *; clipboard-write";
291
- const SANDBOX$1 = "allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation";
292
- const SINGLE_HEIGHT = 175;
293
- const EPISODE_HEIGHT = 160;
294
- const FULL_HEIGHT$1 = 450;
295
387
  /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
296
388
  function AppleMusicEmbed(props) {
297
- const { url, embed: given, onError, height, maxWidth = 660, style, ...frame } = props;
389
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
298
390
  const { embed, error } = resolveEmbed(url, given, "applemusic");
299
- useReportError(error, onError);
300
- if (!embed) return null;
301
- const path = embed.url.slice(23);
302
- 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;
303
394
  return /* @__PURE__ */ jsx(IframeEmbed, {
304
395
  ...frame,
396
+ ...planProps(plan),
305
397
  onError,
306
- maxWidth,
307
- style: {
308
- borderRadius: 10,
309
- overflow: "hidden",
310
- ...style
311
- },
312
- height: height ?? embed.size?.height ?? (single ? SINGLE_HEIGHT : FULL_HEIGHT$1),
313
- src: `https://embed.music.apple.com${path}`,
314
- title: "Apple Music player",
315
- allow: ALLOW$9,
316
- sandbox: SANDBOX$1,
317
- ratio: {
318
- width: 16,
319
- height: 9
320
- }
398
+ maxWidth: maxWidth ?? plan.maxWidth,
399
+ height: height ?? plan.height
321
400
  });
322
401
  }
323
402
  /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
324
403
  function ApplePodcastsEmbed(props) {
325
- const { url, embed: given, onError, height, maxWidth = 640, style, ...frame } = props;
404
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
326
405
  const { embed, error } = resolveEmbed(url, given, "applepodcasts");
327
- useReportError(error, onError);
328
- if (!embed) return null;
329
- 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;
330
409
  return /* @__PURE__ */ jsx(IframeEmbed, {
331
410
  ...frame,
332
- onError,
333
- maxWidth,
334
- style: {
335
- borderRadius: 12,
336
- overflow: "hidden",
337
- ...style
338
- },
339
- height: height ?? embed.size?.height ?? (path.includes("?i=") ? EPISODE_HEIGHT : FULL_HEIGHT$1),
340
- src: `https://embed.podcasts.apple.com${path}`,
341
- title: "Apple Podcasts player",
342
- allow: ALLOW$9,
343
- sandbox: SANDBOX$1,
344
- ratio: {
345
- width: 16,
346
- height: 9
347
- }
411
+ ...planProps(plan),
412
+ onError,
413
+ maxWidth: maxWidth ?? plan.maxWidth,
414
+ height: height ?? plan.height
348
415
  });
349
416
  }
350
- // src/components/bluesky-embed.tsx
417
+ // src/core/plans/bluesky.ts
351
418
  /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
352
419
  const BLUESKY_HEIGHT = {
353
420
  origin: "https://embed.bsky.app",
@@ -356,23 +423,15 @@ const BLUESKY_HEIGHT = {
356
423
  return typeof height === "number" ? height : void 0;
357
424
  }
358
425
  };
359
- const START_HEIGHT$2 = 300;
360
426
  /**
361
427
  * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
362
428
  * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
363
429
  * render: a handle URL needs a lookup, and `onError` says so.
364
430
  */
365
- function BlueskyEmbed(props) {
366
- const { url, embed: given, onError, maxWidth = 600, colorMode, placeholder, ...shared } = props;
367
- const { embed, error } = resolveEmbed(url, given, "bluesky");
368
- useReportError(error, onError);
369
- if (!embed) return null;
370
- const mode = colorMode ?? embed.options.colorMode;
371
- return /* @__PURE__ */ jsx(IframeEmbed, {
372
- ...shared,
373
- onError,
374
- maxWidth,
375
- 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",
376
435
  src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
377
436
  title: "Bluesky post",
378
437
  allow: "",
@@ -382,32 +441,58 @@ function BlueskyEmbed(props) {
382
441
  height: 1
383
442
  },
384
443
  messageHeight: BLUESKY_HEIGHT,
385
- 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 } }))
386
468
  });
387
469
  }
388
- // src/components/dailymotion-embed.tsx
470
+ // src/core/plans/dailymotion.ts
389
471
  const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
390
472
  const ALLOW$8 = "autoplay; fullscreen; picture-in-picture; web-share";
391
473
  /**
392
474
  * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
393
- * prop, never another account's (docs/decisions.md D63).
475
+ * option, never another account's (docs/decisions.md D63).
394
476
  */
395
- function DailymotionEmbed(props) {
396
- const { url, embed: given, onError, playerId, mute, startTime, loop, ...frame } = props;
397
- const resolved = resolveEmbed(url, given, "dailymotion");
398
- 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;
399
480
  const player = playerId ?? parsedPlayer;
400
- 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);
401
- useReportError(error, onError);
402
- const { embed } = resolved;
403
- 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
+ };
404
489
  const params = [];
405
490
  if (mute !== void 0) params.push(["mute", String(mute)]);
406
491
  if (startTime !== void 0) params.push(["startTime", startTime]);
407
492
  if (loop !== void 0) params.push(["loop", String(loop)]);
408
- return /* @__PURE__ */ jsx(IframeEmbed, {
409
- ...frame,
410
- 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)}`,
411
496
  title: "Dailymotion video player",
412
497
  allow: ALLOW$8,
413
498
  ratio: {
@@ -415,11 +500,33 @@ function DailymotionEmbed(props) {
415
500
  height: 9
416
501
  },
417
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
418
525
  });
419
526
  }
420
527
  // src/loader/load-script.ts
421
- const ATTEMPTS$1 = 3;
422
- const RETRY_DELAY_MS$1 = 1e3;
528
+ const ATTEMPTS = 3;
529
+ const RETRY_DELAY_MS = 1e3;
423
530
  const TIMEOUT_MS = 15e3;
424
531
  const POLL_MS = 50;
425
532
  const loading = /* @__PURE__ */ new Map();
@@ -445,11 +552,11 @@ async function add(script) {
445
552
  const ready = script.readyCallback?.();
446
553
  for (let attempt = 1;; attempt++) try {
447
554
  const element = await insert(script);
448
- if (attempt >= ATTEMPTS$1 || !script.skipped?.()) break;
555
+ if (attempt >= ATTEMPTS || !script.skipped?.()) break;
449
556
  element.remove();
450
557
  } catch (error) {
451
- if (!(error instanceof LoadError) || attempt >= ATTEMPTS$1) throw error;
452
- 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));
453
560
  }
454
561
  await (ready ? timeout(ready, `${script.url} did not report ready`) : poll(script));
455
562
  }
@@ -591,7 +698,7 @@ function loadPlatformScript(platform, { locale = "en_US" } = {}) {
591
698
  case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
592
699
  }
593
700
  }
594
- // src/components/drivers.ts
701
+ // src/core/drivers.ts
595
702
  const globals = () => window;
596
703
  function watch(container, rendered, done) {
597
704
  if (rendered(container)) {
@@ -707,24 +814,7 @@ const pinterestDriver = {
707
814
  return stop;
708
815
  }
709
816
  };
710
- // src/components/facebook-video-iframe.tsx
711
- const ALLOW$7 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
712
- function FacebookVideoIframe({ embed, ...frame }) {
713
- const params = Object.entries(embed.options).filter(([key]) => key !== "href");
714
- return /* @__PURE__ */ jsx(IframeEmbed, {
715
- ...frame,
716
- src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
717
- title: "Facebook video player",
718
- allow: ALLOW$7,
719
- scrolling: "no",
720
- ratio: {
721
- width: 16,
722
- height: 9
723
- },
724
- size: embed.size
725
- });
726
- }
727
- // src/components/markup.ts
817
+ // src/core/markup.ts
728
818
  /** `true` becomes a valueless attribute. */
729
819
  function attributes(entries) {
730
820
  let html = "";
@@ -752,10 +842,81 @@ function withProps(options, props) {
752
842
  function hasFallback(fallbackHtml) {
753
843
  return fallbackHtml !== void 0 && fallbackHtml.trim() !== "";
754
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
+ }
755
919
  // src/components/script-embed.tsx
756
- const ATTEMPTS = 3;
757
- const RENDER_TIMEOUT_MS = 15e3;
758
- const RETRY_DELAY_MS = 1e3;
759
920
  function toError(error) {
760
921
  return error instanceof Error ? error : new Error(String(error));
761
922
  }
@@ -792,13 +953,13 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
792
953
  if (cancelled || done) return;
793
954
  stop();
794
955
  stop = () => {};
795
- if (number >= ATTEMPTS) {
956
+ if (number >= 3) {
796
957
  callbacks.current.onError?.(error);
797
958
  return;
798
959
  }
799
960
  timer = setTimeout(() => {
800
961
  attempt(number + 1);
801
- }, RETRY_DELAY_MS * 2 ** (number - 1));
962
+ }, RETRY_DELAY_MS$1 * 2 ** (number - 1));
802
963
  };
803
964
  const attempt = (number) => {
804
965
  if (cancelled || done) return;
@@ -843,88 +1004,41 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
843
1004
  });
844
1005
  }
845
1006
  // src/components/facebook-embed.tsx
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
1007
  function FacebookEmbed(props) {
868
- 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;
869
1009
  const { embed, error } = resolveEmbed(url, given, "facebook");
870
- useReportError(error, onError);
871
- if (!embed) return null;
872
- const frame = {
873
- height,
874
- maxHeight
875
- };
876
- if (embed.variant === "iframe") return /* @__PURE__ */ jsx(FacebookVideoIframe, {
877
- ...shared,
878
- ...frame,
879
- embed
880
- });
881
- const options = withProps(embed.options, {
1010
+ const plan = embed ? facebookPlan(embed, {
1011
+ locale,
882
1012
  showText,
883
1013
  allowfullscreen,
884
1014
  autoplay,
885
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
886
1024
  });
887
- const { size } = embed;
888
- if (embed.kind === "video" && options.showText === false && size?.width !== void 0 && size.height !== void 0) {
889
- const parameters = {};
890
- for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
891
- const value = options[option];
892
- if (value !== void 0) parameters[name] = value;
893
- }
894
- parameters.width = size.width;
895
- parameters.height = size.height;
896
- return /* @__PURE__ */ jsx(FacebookVideoIframe, {
897
- ...shared,
898
- ...frame,
899
- embed: {
900
- ...embed,
901
- options: parameters
902
- }
903
- });
904
- }
905
- const sdkLocale = locale ?? (typeof options.locale === "string" ? options.locale : "en_US");
906
- 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;
907
1026
  return /* @__PURE__ */ jsx(ScriptEmbed, {
908
- maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0,
909
1027
  ...shared,
910
1028
  onError,
911
- driver: facebookDriver(sdkLocale),
912
- markup,
913
- hasFallback: hasFallback(embed.fallbackHtml),
914
- minHeight: MIN_HEIGHT$4[embed.kind],
915
- label: "Facebook"
916
- }, `${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);
917
1036
  }
918
- // src/components/giphy-embed.tsx
1037
+ // src/core/plans/giphy.ts
919
1038
  /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
920
- function GiphyEmbed(props) {
921
- const { url, embed: given, onError, ...frame } = props;
922
- const { embed, error } = resolveEmbed(url, given, "giphy");
923
- useReportError(error, onError);
924
- if (!embed) return null;
925
- return /* @__PURE__ */ jsx(IframeEmbed, {
926
- ...frame,
927
- onError,
1039
+ function giphyPlan(embed) {
1040
+ return {
1041
+ kind: "iframe",
928
1042
  src: `https://giphy.com/embed/${embed.id}`,
929
1043
  title: "Giphy GIF",
930
1044
  allow: "fullscreen",
@@ -933,50 +1047,74 @@ function GiphyEmbed(props) {
933
1047
  height: 1
934
1048
  },
935
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
936
1065
  });
937
1066
  }
938
- // src/components/instagram-embed.tsx
1067
+ // src/core/plans/instagram.ts
939
1068
  /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
940
1069
  const MIN_HEIGHT$3 = 680;
941
1070
  const FLUID_WIDTH = "width:calc(100% - 2px)";
942
- function InstagramEmbed(props) {
943
- const { url, embed: given, onError, maxWidth = 540, captioned, ...shared } = props;
944
- const { embed, error } = resolveEmbed(url, given, "instagram");
945
- useReportError(error, onError);
946
- if (!embed) return null;
947
- const options = withProps(embed.options, { captioned });
1071
+ function instagramPlan(embed, options) {
1072
+ const merged = withProps(embed.options, { captioned: options.captioned });
948
1073
  const markup = `<blockquote${attributes({
949
1074
  "data-instgrm-permalink": embed.url,
950
- "data-instgrm-version": options.version,
951
- "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,
952
1077
  style: FLUID_WIDTH
953
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;
954
1097
  return /* @__PURE__ */ jsx(ScriptEmbed, {
955
1098
  ...shared,
956
1099
  onError,
957
- maxWidth,
958
- driver: instagramDriver,
959
- markup,
960
- hasFallback: hasFallback(embed.fallbackHtml),
961
- minHeight: MIN_HEIGHT$3,
962
- label: "Instagram"
963
- }, 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);
964
1107
  }
965
- // src/components/kick-embed.tsx
1108
+ // src/core/plans/kick.ts
966
1109
  const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
967
1110
  /** A live channel at 16:9. */
968
- function KickEmbed(props) {
969
- const { url, embed: given, onError, autoplay, muted, ...frame } = props;
970
- const { embed, error } = resolveEmbed(url, given, "kick");
971
- useReportError(error, onError);
972
- if (!embed) return null;
973
- const fromProps = [];
974
- if (autoplay !== void 0) fromProps.push(["autoplay", autoplay]);
975
- if (muted !== void 0) fromProps.push(["muted", muted]);
976
- return /* @__PURE__ */ jsx(IframeEmbed, {
977
- ...frame,
978
- onError,
979
- 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)}`,
980
1118
  title: "Kick player",
981
1119
  allow: "autoplay; fullscreen",
982
1120
  scrolling: "no",
@@ -985,34 +1123,63 @@ function KickEmbed(props) {
985
1123
  height: 9
986
1124
  },
987
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
988
1144
  });
989
1145
  }
990
- // src/components/linkedin-embed.tsx
1146
+ // src/core/plans/linkedin.ts
991
1147
  const DEFAULT_HEIGHT = 670;
992
1148
  const DEFAULT_WIDTH = 504;
993
- /** A fixed height: the `height` prop, else the embed code's, else 670px. */
994
- function LinkedInEmbed(props) {
995
- const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
996
- const { embed, error } = resolveEmbed(url, given, "linkedin");
997
- useReportError(error, onError);
998
- if (!embed) return null;
1149
+ /** A fixed height: the embed code's, else 670px. */
1150
+ function linkedinPlan(embed, options) {
999
1151
  const params = new Map(Object.entries(embed.options));
1000
- if (collapsed === true) params.set("collapsed", 1);
1001
- if (collapsed === false) params.delete("collapsed");
1002
- return /* @__PURE__ */ jsx(IframeEmbed, {
1003
- ...frame,
1004
- maxWidth: maxWidth ?? embed.size?.width ?? DEFAULT_WIDTH,
1005
- 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",
1006
1156
  src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
1007
1157
  title: "LinkedIn post",
1008
1158
  allow: "",
1009
1159
  ratio: {
1010
1160
  width: DEFAULT_WIDTH,
1011
1161
  height: DEFAULT_HEIGHT
1012
- }
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
1013
1180
  });
1014
1181
  }
1015
- // src/components/pinterest-embed.tsx
1182
+ // src/core/plans/pinterest.ts
1016
1183
  const ATTRIBUTES$1 = {
1017
1184
  width: "data-pin-width",
1018
1185
  lang: "data-pin-lang",
@@ -1025,26 +1192,39 @@ const PIN_WIDTHS = {
1025
1192
  };
1026
1193
  const DEFAULT_PIN_WIDTH = 236;
1027
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
1028
1210
  function PinterestEmbed(props) {
1029
1211
  const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
1030
1212
  const { embed, error } = resolveEmbed(url, given, "pinterest");
1031
- useReportError(error, onError);
1032
- if (!embed) return null;
1033
- const options = withProps(embed.options, { width: pinWidth });
1034
- const pinWidthPx = PIN_WIDTHS[String(options.width)] ?? DEFAULT_PIN_WIDTH;
1035
- 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;
1036
1216
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1037
1217
  ...shared,
1038
1218
  onError,
1039
- maxWidth: maxWidth ?? pinWidthPx,
1040
- driver: pinterestDriver,
1041
- markup,
1042
- hasFallback: false,
1043
- minHeight: MIN_HEIGHT$2,
1044
- label: "Pinterest"
1045
- }, 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);
1046
1226
  }
1047
- // src/components/reddit-embed.tsx
1227
+ // src/core/plans/reddit.ts
1048
1228
  const PARAMS$5 = {
1049
1229
  theme: "theme",
1050
1230
  showMedia: "showmedia",
@@ -1055,7 +1235,7 @@ const PARAMS$5 = {
1055
1235
  };
1056
1236
  const SANDBOX = "allow-scripts allow-same-origin allow-popups";
1057
1237
  const ALLOW$6 = "clipboard-read; clipboard-write";
1058
- const START_HEIGHT$1 = 316;
1238
+ const START_HEIGHT = 316;
1059
1239
  /** docs/decisions.md D52. */
1060
1240
  const REDDIT_HEIGHT = {
1061
1241
  origin: "https://embed.reddit.com",
@@ -1066,30 +1246,15 @@ const REDDIT_HEIGHT = {
1066
1246
  }
1067
1247
  };
1068
1248
  /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1069
- function RedditEmbed(props) {
1070
- const { url, embed: given, onError, maxWidth = 640, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
1071
- const { embed, error } = resolveEmbed(url, given, "reddit");
1072
- useReportError(error, onError);
1073
- if (!embed) return null;
1249
+ function redditPlan(embed, options) {
1074
1250
  const fromProps = [];
1075
- const values = {
1076
- theme,
1077
- showMedia,
1078
- showTitle,
1079
- showUsername,
1080
- locale,
1081
- depth
1082
- };
1083
1251
  for (const [prop, name] of Object.entries(PARAMS$5)) {
1084
- const value = values[prop];
1252
+ const value = options[prop];
1085
1253
  if (value !== void 0) fromProps.push([name, value]);
1086
1254
  }
1087
- const path = embed.url.slice(22);
1088
- return /* @__PURE__ */ jsx(IframeEmbed, {
1089
- ...shared,
1090
- onError,
1091
- maxWidth,
1092
- 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)}`,
1093
1258
  title: "Reddit post",
1094
1259
  allow: ALLOW$6,
1095
1260
  sandbox: SANDBOX,
@@ -1099,21 +1264,39 @@ function RedditEmbed(props) {
1099
1264
  height: 1
1100
1265
  },
1101
1266
  messageHeight: REDDIT_HEIGHT,
1102
- 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
1103
1291
  });
1104
1292
  }
1105
- // src/components/snapchat-embed.tsx
1293
+ // src/core/plans/snapchat.ts
1106
1294
  const ALLOW$5 = "autoplay; camera; microphone; clipboard-write;";
1107
1295
  /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1108
- function SnapchatEmbed(props) {
1109
- const { url, embed: given, onError, maxWidth = 416, ...frame } = props;
1110
- const { embed, error } = resolveEmbed(url, given, "snapchat");
1111
- useReportError(error, onError);
1112
- if (!embed) return null;
1296
+ function snapchatPlan(embed) {
1113
1297
  const title = embed.options.title;
1114
- return /* @__PURE__ */ jsx(IframeEmbed, {
1115
- ...frame,
1116
- maxWidth,
1298
+ return {
1299
+ kind: "iframe",
1117
1300
  src: `${embed.url}/embed`,
1118
1301
  title: typeof title === "string" && title !== "" ? title : "Snapchat",
1119
1302
  allow: ALLOW$5,
@@ -1122,10 +1305,25 @@ function SnapchatEmbed(props) {
1122
1305
  width: 416,
1123
1306
  height: 692
1124
1307
  },
1125
- 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
1126
1324
  });
1127
1325
  }
1128
- // src/components/soundcloud-embed.tsx
1326
+ // src/core/plans/soundcloud.ts
1129
1327
  const PARAMS$4 = {
1130
1328
  visual: "visual",
1131
1329
  color: "color",
@@ -1139,13 +1337,33 @@ const PARAMS$4 = {
1139
1337
  };
1140
1338
  const ALLOW$4 = "autoplay; encrypted-media";
1141
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
1142
1362
  /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
1143
1363
  function SoundCloudEmbed(props) {
1144
- 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;
1145
1365
  const { embed, error } = resolveEmbed(url, given, "soundcloud");
1146
- useReportError(error, onError);
1147
- if (!embed) return null;
1148
- const values = {
1366
+ const plan = embed ? soundcloudPlan(embed, {
1149
1367
  visual,
1150
1368
  color,
1151
1369
  autoPlay,
@@ -1155,52 +1373,32 @@ function SoundCloudEmbed(props) {
1155
1373
  showReposts,
1156
1374
  showTeaser,
1157
1375
  showArtwork
1158
- };
1159
- const fromProps = [];
1160
- for (const [prop, name] of Object.entries(PARAMS$4)) {
1161
- const value = values[prop];
1162
- if (value !== void 0) fromProps.push([name, value]);
1163
- }
1164
- 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;
1165
1379
  return /* @__PURE__ */ jsx(IframeEmbed, {
1166
1380
  ...frame,
1381
+ ...planProps(plan),
1167
1382
  onError,
1168
- height: height ?? embed.size?.height ?? URL_HEIGHT,
1169
- src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromProps)}`,
1170
- title: "SoundCloud player",
1171
- allow: ALLOW$4,
1172
- scrolling: "no",
1173
- ratio: {
1174
- width: 16,
1175
- height: 9
1176
- }
1383
+ maxWidth: maxWidth ?? plan.maxWidth,
1384
+ height: height ?? plan.height
1177
1385
  });
1178
1386
  }
1179
- // src/components/spotify-embed.tsx
1387
+ // src/core/plans/spotify.ts
1180
1388
  const ALLOW$3 = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
1181
1389
  const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
1182
1390
  const COMPACT_HEIGHT = 152;
1183
1391
  const FULL_HEIGHT = 352;
1184
1392
  /**
1185
- * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
1186
- * 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.
1187
1395
  */
1188
- function SpotifyEmbed(props) {
1189
- const { url, embed: given, onError, height, theme, style, ...frame } = props;
1190
- const { embed, error } = resolveEmbed(url, given, "spotify");
1191
- useReportError(error, onError);
1192
- if (!embed) return null;
1396
+ function spotifyPlan(embed, options) {
1193
1397
  const type = new URL(embed.url).pathname.split("/")[1] ?? "";
1194
1398
  const video = embed.kind === "video";
1195
- const params = query(Object.entries(embed.options), theme === void 0 ? void 0 : [["theme", theme]]);
1196
- return /* @__PURE__ */ jsx(IframeEmbed, {
1197
- ...frame,
1198
- style: {
1199
- borderRadius: 12,
1200
- overflow: "hidden",
1201
- ...style
1202
- },
1203
- 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",
1204
1402
  src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
1205
1403
  title: "Spotify Embed",
1206
1404
  allow: ALLOW$3,
@@ -1208,10 +1406,29 @@ function SpotifyEmbed(props) {
1208
1406
  width: 16,
1209
1407
  height: 9
1210
1408
  },
1211
- 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
1212
1429
  });
1213
1430
  }
1214
- // src/components/telegram-embed.tsx
1431
+ // src/core/plans/telegram.ts
1215
1432
  const PARAMS$3 = [
1216
1433
  ["comment", "comment"],
1217
1434
  ["userpic", "userpic"],
@@ -1239,11 +1456,8 @@ const TELEGRAM_HEIGHT = {
1239
1456
  }
1240
1457
  };
1241
1458
  /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1242
- function TelegramEmbed(props) {
1243
- const { url, embed: given, onError, maxWidth = 500, userpic, color, dark, darkColor, ...shared } = props;
1244
- const { embed, error } = resolveEmbed(url, given, "telegram");
1245
- useReportError(error, onError);
1246
- if (!embed) return null;
1459
+ function telegramPlan(embed, options) {
1460
+ const { userpic, color, dark, darkColor } = options;
1247
1461
  const values = {
1248
1462
  ...embed.options,
1249
1463
  ...userpic === void 0 ? {} : { userpic },
@@ -1256,10 +1470,8 @@ function TelegramEmbed(props) {
1256
1470
  const value = param(name, values[option]);
1257
1471
  if (value !== void 0) params.push([name, value]);
1258
1472
  }
1259
- return /* @__PURE__ */ jsx(IframeEmbed, {
1260
- ...shared,
1261
- onError,
1262
- maxWidth,
1473
+ return {
1474
+ kind: "iframe",
1263
1475
  src: `${embed.url}${query(params)}`,
1264
1476
  title: "Telegram post",
1265
1477
  allow: "",
@@ -1269,36 +1481,71 @@ function TelegramEmbed(props) {
1269
1481
  height: 1
1270
1482
  },
1271
1483
  messageHeight: TELEGRAM_HEIGHT,
1272
- 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
1273
1506
  });
1274
1507
  }
1275
- // src/components/threads-embed.tsx
1508
+ // src/core/plans/threads.ts
1276
1509
  /** A text-only post (docs/decisions.md D34). */
1277
1510
  const MIN_HEIGHT$1 = 240;
1278
- function ThreadsEmbed(props) {
1279
- const { url, embed: given, onError, maxWidth = 658, theme, ...shared } = props;
1280
- const { embed, error } = resolveEmbed(url, given, "threads");
1281
- useReportError(error, onError);
1282
- if (!embed) return null;
1283
- const options = withProps(embed.options, { theme });
1511
+ function threadsPlan(embed, options) {
1512
+ const merged = withProps(embed.options, { theme: options.theme });
1284
1513
  const markup = `<blockquote${attributes({
1285
1514
  "data-text-post-permalink": embed.url,
1286
- "data-text-post-version": options.version ?? 0,
1515
+ "data-text-post-version": merged.version ?? 0,
1287
1516
  id: `ig-tp-${embed.id}`,
1288
- "data-theme": options.theme
1517
+ "data-theme": merged.theme
1289
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;
1290
1537
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1291
1538
  ...shared,
1292
1539
  onError,
1293
- maxWidth,
1294
- driver: threadsDriver,
1295
- markup,
1296
- hasFallback: hasFallback(embed.fallbackHtml),
1297
- minHeight: MIN_HEIGHT$1,
1298
- label: "Threads"
1299
- }, 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);
1300
1547
  }
1301
- // src/components/tiktok-embed.tsx
1548
+ // src/core/plans/tiktok.ts
1302
1549
  const PARAMS$2 = {
1303
1550
  controls: "controls",
1304
1551
  progressBar: "progress_bar",
@@ -1317,12 +1564,27 @@ const PARAMS$2 = {
1317
1564
  };
1318
1565
  const ALLOW$2 = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
1319
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). */
1320
1584
  function TikTokEmbed(props) {
1321
- 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;
1322
1586
  const { embed, error } = resolveEmbed(url, given, "tiktok");
1323
- useReportError(error, onError);
1324
- if (!embed) return null;
1325
- const params = playerParams({
1587
+ const plan = embed ? tiktokPlan(embed, {
1326
1588
  controls,
1327
1589
  progressBar,
1328
1590
  playButton,
@@ -1337,21 +1599,16 @@ function TikTokEmbed(props) {
1337
1599
  nativeContextMenu,
1338
1600
  closedCaption,
1339
1601
  forceMuted
1340
- }, PARAMS$2);
1602
+ }) : void 0;
1603
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1604
+ if (plan?.kind !== "iframe") return null;
1341
1605
  return /* @__PURE__ */ jsx(IframeEmbed, {
1342
1606
  ...frame,
1343
- maxWidth,
1344
- src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
1345
- title: "TikTok video player",
1346
- allow: ALLOW$2,
1347
- ratio: {
1348
- width: 9,
1349
- height: 16
1350
- },
1351
- size: embed.size
1607
+ ...planProps(plan),
1608
+ maxWidth: maxWidth ?? plan.maxWidth
1352
1609
  });
1353
1610
  }
1354
- // src/components/tumblr-embed.tsx
1611
+ // src/core/plans/tumblr.ts
1355
1612
  /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
1356
1613
  const TUMBLR_HEIGHT = {
1357
1614
  origin: "https://embed.tumblr.com",
@@ -1362,19 +1619,11 @@ const TUMBLR_HEIGHT = {
1362
1619
  return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
1363
1620
  }
1364
1621
  };
1365
- const START_HEIGHT = 400;
1366
1622
  /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
1367
- function TumblrEmbed(props) {
1368
- const { url, embed: given, onError, maxWidth = 540, ...shared } = props;
1369
- const { embed, error } = resolveEmbed(url, given, "tumblr");
1370
- useReportError(error, onError);
1371
- if (!embed) return null;
1372
- const blog = embed.url.slice(23).split("/")[0] ?? "";
1373
- return /* @__PURE__ */ jsx(IframeEmbed, {
1374
- ...shared,
1375
- onError,
1376
- maxWidth,
1377
- 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`,
1378
1627
  title: "Tumblr post",
1379
1628
  allow: "",
1380
1629
  scrolling: "no",
@@ -1383,10 +1632,26 @@ function TumblrEmbed(props) {
1383
1632
  height: 1
1384
1633
  },
1385
1634
  messageHeight: TUMBLR_HEIGHT,
1386
- 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
1387
1652
  });
1388
1653
  }
1389
- // src/components/twitch-embed.tsx
1654
+ // src/core/plans/twitch.ts
1390
1655
  const RESERVED = [
1391
1656
  "channel",
1392
1657
  "video",
@@ -1402,18 +1667,15 @@ function player(url, id) {
1402
1667
  return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
1403
1668
  }
1404
1669
  /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
1405
- function TwitchEmbed(props) {
1406
- const { url, embed: given, onError, autoplay, muted, time, ...frame } = props;
1407
- const { embed, error } = resolveEmbed(url, given, "twitch");
1408
- useReportError(error, onError);
1409
- if (!embed) return null;
1670
+ function twitchPlan(embed, options) {
1671
+ const { autoplay, muted, time } = options;
1410
1672
  const params = [];
1411
1673
  if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
1412
1674
  if (muted !== void 0) params.push(["muted", String(muted)]);
1413
1675
  if (time !== void 0) params.push(["time", time]);
1414
1676
  const [base, content] = player(embed.url, embed.id);
1415
- return /* @__PURE__ */ jsx(IframeEmbed, {
1416
- ...frame,
1677
+ return {
1678
+ kind: "iframe",
1417
1679
  src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
1418
1680
  title: "Twitch player",
1419
1681
  allow: "",
@@ -1423,9 +1685,27 @@ function TwitchEmbed(props) {
1423
1685
  },
1424
1686
  size: embed.size,
1425
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
1426
1706
  });
1427
1707
  }
1428
- // src/components/vimeo-embed.tsx
1708
+ // src/core/plans/vimeo.ts
1429
1709
  const PARAMS$1 = {
1430
1710
  autopause: "autopause",
1431
1711
  autoplay: "autoplay",
@@ -1446,14 +1726,30 @@ const PARAMS$1 = {
1446
1726
  transparent: "transparent"
1447
1727
  };
1448
1728
  const ALLOW$1 = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
1449
- function VimeoEmbed(props) {
1450
- 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;
1451
- const { embed, error } = resolveEmbed(url, given, "vimeo");
1452
- useReportError(error, onError);
1453
- if (!embed) return null;
1729
+ function vimeoPlan(embed, options) {
1730
+ const { t, ...rest } = options;
1454
1731
  const { t: parsedStart, ...parsed } = embed.options;
1455
1732
  const hash = new URL(embed.url).pathname.split("/")[2];
1456
- 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, {
1457
1753
  autopause,
1458
1754
  autoplay,
1459
1755
  background,
@@ -1470,23 +1766,18 @@ function VimeoEmbed(props) {
1470
1766
  quality,
1471
1767
  speed,
1472
1768
  title,
1473
- transparent
1474
- }, PARAMS$1);
1475
- 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;
1476
1774
  return /* @__PURE__ */ jsx(IframeEmbed, {
1477
1775
  ...frame,
1478
- 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))}`}`,
1479
- title: "Vimeo video player",
1480
- allow: ALLOW$1,
1481
- referrerPolicy: "strict-origin-when-cross-origin",
1482
- ratio: {
1483
- width: 16,
1484
- height: 9
1485
- },
1486
- size: embed.size
1776
+ ...planProps(plan),
1777
+ maxWidth: maxWidth ?? plan.maxWidth
1487
1778
  });
1488
1779
  }
1489
- // src/components/x-embed.tsx
1780
+ // src/core/plans/x.ts
1490
1781
  const ATTRIBUTES = {
1491
1782
  theme: "data-theme",
1492
1783
  conversation: "data-conversation",
@@ -1498,33 +1789,47 @@ const ATTRIBUTES = {
1498
1789
  };
1499
1790
  /** A plain text post, the smallest X renders (docs/decisions.md D34). */
1500
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
1501
1808
  function XEmbed(props) {
1502
- 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;
1503
1810
  const { embed, error } = resolveEmbed(url, given, "x");
1504
- useReportError(error, onError);
1505
- if (!embed) return null;
1506
- const options = withProps(embed.options, {
1811
+ const plan = embed ? xPlan(embed, {
1507
1812
  theme,
1508
1813
  conversation,
1509
1814
  cards,
1510
1815
  align,
1511
1816
  lang,
1512
1817
  dnt
1513
- });
1514
- const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
1515
- 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;
1516
1821
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1517
1822
  ...shared,
1518
1823
  onError,
1519
- maxWidth,
1520
- driver: xDriver,
1521
- markup,
1522
- hasFallback: hasFallback(embed.fallbackHtml),
1523
- minHeight: MIN_HEIGHT,
1524
- label: "X"
1525
- }, 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);
1526
1831
  }
1527
- // src/components/youtube-embed.tsx
1832
+ // src/core/plans/youtube.ts
1528
1833
  const PARAMS = {
1529
1834
  autoplay: "autoplay",
1530
1835
  ccLangPref: "cc_lang_pref",
@@ -1548,14 +1853,32 @@ const PARAMS = {
1548
1853
  widgetReferrer: "widget_referrer"
1549
1854
  };
1550
1855
  const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
1551
- function YouTubeEmbed(props) {
1552
- 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;
1553
- const { embed, error } = resolveEmbed(url, given, "youtube");
1554
- useReportError(error, onError);
1555
- if (!embed) return null;
1856
+ function youtubePlan(embed, options) {
1857
+ const { nocookie, ...rest } = options;
1556
1858
  const { nocookie: parsedNocookie, ...parsed } = embed.options;
1557
1859
  const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
1558
- 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, {
1559
1882
  autoplay,
1560
1883
  ccLangPref,
1561
1884
  ccLoadPolicy,
@@ -1575,22 +1898,15 @@ function YouTubeEmbed(props) {
1575
1898
  playsinline,
1576
1899
  rel,
1577
1900
  start,
1578
- widgetReferrer
1579
- }, 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;
1580
1906
  return /* @__PURE__ */ jsx(IframeEmbed, {
1581
1907
  ...frame,
1582
- src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
1583
- title: "YouTube video player",
1584
- allow: ALLOW,
1585
- referrerPolicy: "strict-origin-when-cross-origin",
1586
- ratio: embed.url.includes("/shorts/") ? {
1587
- width: 9,
1588
- height: 16
1589
- } : {
1590
- width: 16,
1591
- height: 9
1592
- },
1593
- size: embed.size
1908
+ ...planProps(plan),
1909
+ maxWidth: maxWidth ?? plan.maxWidth
1594
1910
  });
1595
1911
  }
1596
1912
  // src/components/social-embed.tsx
@@ -1602,9 +1918,7 @@ function SocialEmbed(props) {
1602
1918
  maxHeight
1603
1919
  };
1604
1920
  const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
1605
- const unrecognised = embed === null && !(html !== void 0 && fallback);
1606
- const lookup = html === void 0 ? needsLookup(url) : null;
1607
- 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);
1608
1922
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
1609
1923
  switch (embed.platform) {
1610
1924
  case "x": return /* @__PURE__ */ jsx(XEmbed, {