social-embeds 0.5.3 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 FRAME_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,19 +193,44 @@ 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);
64
- const inView = useNearViewport(frame, !lazy && messageHeight !== void 0);
65
- const heard = useRef(false);
233
+ const inView = useNearViewport(frame, !lazy);
66
234
  const [loaded, setLoaded] = useState(false);
67
235
  const [reportedHeight, setReportedHeight] = useState();
68
236
  const reported = useRef(false);
@@ -85,7 +253,6 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
85
253
  useEffect(() => {
86
254
  if (!near || !messageHeight) return;
87
255
  const { origin, read } = messageHeight;
88
- heard.current = false;
89
256
  const listen = (event) => {
90
257
  if (event.origin !== origin) return;
91
258
  if (!iframe.current || event.source !== iframe.current.contentWindow) return;
@@ -95,8 +262,7 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
95
262
  } catch {
96
263
  return;
97
264
  }
98
- if (typeof value !== "number" || !(value > 0 && value <= MAX_REPORTED_HEIGHT)) return;
99
- heard.current = true;
265
+ if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
100
266
  setReportedHeight(Math.ceil(value));
101
267
  report();
102
268
  };
@@ -110,12 +276,13 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
110
276
  report
111
277
  ]);
112
278
  useEffect(() => {
113
- if (!near || !inView || !messageHeight) return;
279
+ if (!near || !inView) return;
280
+ const failure = messageHeight ? "did not report its height" : "did not load";
114
281
  const timer = setTimeout(() => {
115
- if (heard.current) return;
282
+ if (reported.current) return;
116
283
  setLoaded(true);
117
- callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} did not report its height`));
118
- }, HEIGHT_TIMEOUT_MS);
284
+ callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} ${failure}`));
285
+ }, FRAME_TIMEOUT_MS);
119
286
  return () => {
120
287
  clearTimeout(timer);
121
288
  };
@@ -125,17 +292,23 @@ function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ra
125
292
  messageHeight,
126
293
  title
127
294
  ]);
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
295
  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)}` } : {
296
+ ...frameStyle({
297
+ kind: "iframe",
298
+ src,
299
+ title,
300
+ allow,
301
+ ratio,
302
+ size,
303
+ messageHeight,
304
+ startHeight,
305
+ borderRadius
306
+ }, {
307
+ width,
308
+ maxWidth,
136
309
  height,
137
310
  maxHeight
138
- },
311
+ }, reportedHeight),
139
312
  ...style
140
313
  };
141
314
  return /* @__PURE__ */ jsx("div", {
@@ -183,96 +356,7 @@ function Skeleton({ minHeight }) {
183
356
  }
184
357
  });
185
358
  }
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
- }
359
+ // src/core/params.ts
276
360
  /**
277
361
  * Security: options are not verified (docs/decisions.md D68). Keys that choose the content
278
362
  * come only from the verified url and id.
@@ -298,127 +382,115 @@ function playerParams(props, names) {
298
382
  return params;
299
383
  }
300
384
  // 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
385
  /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
307
386
  function AppleMusicEmbed(props) {
308
- const { url, embed: given, onError, height, maxWidth = 660, style, ...frame } = props;
387
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
309
388
  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=");
389
+ const plan = embed ? appleMusicPlan(embed) : void 0;
390
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
391
+ if (plan?.kind !== "iframe") return null;
314
392
  return /* @__PURE__ */ jsx(IframeEmbed, {
315
393
  ...frame,
394
+ ...planProps(plan),
316
395
  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
- }
396
+ maxWidth: maxWidth ?? plan.maxWidth,
397
+ height: height ?? plan.height
332
398
  });
333
399
  }
334
400
  /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
335
401
  function ApplePodcastsEmbed(props) {
336
- const { url, embed: given, onError, height, maxWidth = 640, style, ...frame } = props;
402
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
337
403
  const { embed, error } = resolveEmbed(url, given, "applepodcasts");
338
- useReportError(error, onError);
339
- if (!embed) return null;
340
- const path = embed.url.slice(26);
404
+ const plan = embed ? applePodcastsPlan(embed) : void 0;
405
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
406
+ if (plan?.kind !== "iframe") return null;
341
407
  return /* @__PURE__ */ jsx(IframeEmbed, {
342
408
  ...frame,
409
+ ...planProps(plan),
343
410
  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
+ maxWidth: maxWidth ?? plan.maxWidth,
412
+ height: height ?? plan.height
359
413
  });
360
414
  }
415
+ // src/core/plans/bluesky.ts
416
+ /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
417
+ const BLUESKY_HEIGHT = {
418
+ origin: "https://embed.bsky.app",
419
+ read(data) {
420
+ const height = data?.height;
421
+ return typeof height === "number" ? height : void 0;
422
+ }
423
+ };
424
+ /**
425
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
426
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
427
+ * render: a handle URL needs a lookup, and `onError` says so.
428
+ */
429
+ function blueskyPlan(embed, options) {
430
+ const mode = options.colorMode ?? embed.options.colorMode;
431
+ return {
432
+ kind: "iframe",
433
+ src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
434
+ title: "Bluesky post",
435
+ allow: "",
436
+ scrolling: "no",
437
+ ratio: {
438
+ width: 1,
439
+ height: 1
440
+ },
441
+ messageHeight: BLUESKY_HEIGHT,
442
+ startHeight: 300,
443
+ maxWidth: 600,
444
+ fallbackHtml: embed.fallbackHtml
445
+ };
446
+ }
361
447
  // src/components/bluesky-embed.tsx
362
- /** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
363
- const BLUESKY_HEIGHT = {
364
- origin: "https://embed.bsky.app",
365
- read(data) {
366
- const height = data?.height;
367
- return typeof height === "number" ? height : void 0;
368
- }
369
- };
370
- const START_HEIGHT$2 = 300;
371
448
  /**
372
449
  * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
373
450
  * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
374
451
  * render: a handle URL needs a lookup, and `onError` says so.
375
452
  */
376
453
  function BlueskyEmbed(props) {
377
- const { url, embed: given, onError, maxWidth = 600, colorMode, placeholder, ...shared } = props;
454
+ const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
378
455
  const { embed, error } = resolveEmbed(url, given, "bluesky");
379
- useReportError(error, onError);
380
- if (!embed) return null;
381
- const mode = colorMode ?? embed.options.colorMode;
456
+ const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
457
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
458
+ if (plan?.kind !== "iframe") return null;
459
+ const { fallbackHtml } = plan;
382
460
  return /* @__PURE__ */ jsx(IframeEmbed, {
383
461
  ...shared,
462
+ ...planProps(plan),
384
463
  onError,
385
- maxWidth,
386
- placeholder: placeholder ?? (embed.fallbackHtml === void 0 ? void 0 : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: embed.fallbackHtml } })),
387
- src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
388
- title: "Bluesky post",
389
- allow: "",
390
- scrolling: "no",
391
- ratio: {
392
- width: 1,
393
- height: 1
394
- },
395
- messageHeight: BLUESKY_HEIGHT,
396
- startHeight: START_HEIGHT$2
464
+ maxWidth: maxWidth ?? plan.maxWidth,
465
+ placeholder: placeholder ?? (fallbackHtml === void 0 ? void 0 : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } }))
397
466
  });
398
467
  }
399
- // src/components/dailymotion-embed.tsx
468
+ // src/core/plans/dailymotion.ts
400
469
  const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
401
470
  const ALLOW$8 = "autoplay; fullscreen; picture-in-picture; web-share";
402
471
  /**
403
472
  * 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).
473
+ * option, never another account's (docs/decisions.md D63).
405
474
  */
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 ?? {};
475
+ function dailymotionPlan(embed, options) {
476
+ const { playerId, mute, startTime, loop } = options;
477
+ const { playerId: parsedPlayer, ...parsed } = embed.options;
410
478
  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;
479
+ if (player === void 0) return {
480
+ kind: "error",
481
+ message: "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed"
482
+ };
483
+ if (typeof player !== "string" || !PLAYER_ID.test(player)) return {
484
+ kind: "error",
485
+ message: `social-embeds: not a Dailymotion Player ID: ${String(player)}`
486
+ };
415
487
  const params = [];
416
488
  if (mute !== void 0) params.push(["mute", String(mute)]);
417
489
  if (startTime !== void 0) params.push(["startTime", startTime]);
418
490
  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)}`,
491
+ return {
492
+ kind: "iframe",
493
+ src: `https://geo.dailymotion.com/player/${player}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
422
494
  title: "Dailymotion video player",
423
495
  allow: ALLOW$8,
424
496
  ratio: {
@@ -426,11 +498,33 @@ function DailymotionEmbed(props) {
426
498
  height: 9
427
499
  },
428
500
  size: embed.size
501
+ };
502
+ }
503
+ // src/components/dailymotion-embed.tsx
504
+ /**
505
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
506
+ * prop, never another account's (docs/decisions.md D63).
507
+ */
508
+ function DailymotionEmbed(props) {
509
+ const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
510
+ const { embed, error } = resolveEmbed(url, given, "dailymotion");
511
+ const plan = embed ? dailymotionPlan(embed, {
512
+ playerId,
513
+ mute,
514
+ startTime,
515
+ loop
516
+ }) : void 0;
517
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
518
+ if (plan?.kind !== "iframe") return null;
519
+ return /* @__PURE__ */ jsx(IframeEmbed, {
520
+ ...frame,
521
+ ...planProps(plan),
522
+ maxWidth: maxWidth ?? plan.maxWidth
429
523
  });
430
524
  }
431
525
  // src/loader/load-script.ts
432
- const ATTEMPTS$1 = 3;
433
- const RETRY_DELAY_MS$1 = 1e3;
526
+ const ATTEMPTS = 3;
527
+ const RETRY_DELAY_MS = 1e3;
434
528
  const TIMEOUT_MS = 15e3;
435
529
  const POLL_MS = 50;
436
530
  const loading = /* @__PURE__ */ new Map();
@@ -456,11 +550,11 @@ async function add(script) {
456
550
  const ready = script.readyCallback?.();
457
551
  for (let attempt = 1;; attempt++) try {
458
552
  const element = await insert(script);
459
- if (attempt >= ATTEMPTS$1 || !script.skipped?.()) break;
553
+ if (attempt >= ATTEMPTS || !script.skipped?.()) break;
460
554
  element.remove();
461
555
  } catch (error) {
462
- if (!(error instanceof LoadError) || attempt >= ATTEMPTS$1) throw error;
463
- await delay(RETRY_DELAY_MS$1 * 2 ** (attempt - 1));
556
+ if (!(error instanceof LoadError) || attempt >= ATTEMPTS) throw error;
557
+ await delay(RETRY_DELAY_MS * 2 ** (attempt - 1));
464
558
  }
465
559
  await (ready ? timeout(ready, `${script.url} did not report ready`) : poll(script));
466
560
  }
@@ -602,7 +696,7 @@ function loadPlatformScript(platform, { locale = "en_US" } = {}) {
602
696
  case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
603
697
  }
604
698
  }
605
- // src/components/drivers.ts
699
+ // src/core/drivers.ts
606
700
  const globals = () => window;
607
701
  function watch(container, rendered, done) {
608
702
  if (rendered(container)) {
@@ -718,24 +812,7 @@ const pinterestDriver = {
718
812
  return stop;
719
813
  }
720
814
  };
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
815
+ // src/core/markup.ts
739
816
  /** `true` becomes a valueless attribute. */
740
817
  function attributes(entries) {
741
818
  let html = "";
@@ -763,10 +840,82 @@ function withProps(options, props) {
763
840
  function hasFallback(fallbackHtml) {
764
841
  return fallbackHtml !== void 0 && fallbackHtml.trim() !== "";
765
842
  }
843
+ // src/core/plans/facebook.ts
844
+ const ATTRIBUTES$2 = {
845
+ width: "data-width",
846
+ showText: "data-show-text",
847
+ lazy: "data-lazy",
848
+ allowfullscreen: "data-allowfullscreen",
849
+ autoplay: "data-autoplay",
850
+ showCaptions: "data-show-captions"
851
+ };
852
+ const PLAYER_PARAMETERS = {
853
+ showText: "show_text",
854
+ allowfullscreen: "allowfullscreen",
855
+ autoplay: "autoplay",
856
+ showCaptions: "show_captions"
857
+ };
858
+ /** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
859
+ const POST_MAX_WIDTH = 750;
860
+ /** docs/decisions.md D34. */
861
+ const MIN_HEIGHT$4 = {
862
+ post: 300,
863
+ video: 200
864
+ };
865
+ const ALLOW$7 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
866
+ /** Its content fills the iframe at any width, whatever `width` says (docs/decisions.md D29). */
867
+ function facebookVideoPlan(embed) {
868
+ const params = Object.entries(embed.options).filter(([key]) => key !== "href");
869
+ return {
870
+ kind: "iframe",
871
+ src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
872
+ title: "Facebook video player",
873
+ allow: ALLOW$7,
874
+ scrolling: "no",
875
+ ratio: {
876
+ width: 16,
877
+ height: 9
878
+ },
879
+ size: embed.size
880
+ };
881
+ }
882
+ function facebookPlan(embed, options) {
883
+ if (embed.variant === "iframe") return facebookVideoPlan(embed);
884
+ const merged = withProps(embed.options, {
885
+ showText: options.showText,
886
+ allowfullscreen: options.allowfullscreen,
887
+ autoplay: options.autoplay,
888
+ showCaptions: options.showCaptions
889
+ });
890
+ const { size } = embed;
891
+ if (embed.kind === "video" && merged.showText === false && size?.width !== void 0 && size.height !== void 0) {
892
+ const parameters = {};
893
+ for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
894
+ const value = merged[option];
895
+ if (value !== void 0) parameters[name] = value;
896
+ }
897
+ parameters.width = size.width;
898
+ parameters.height = size.height;
899
+ return facebookVideoPlan({
900
+ ...embed,
901
+ options: parameters
902
+ });
903
+ }
904
+ const sdkLocale = options.locale ?? (typeof merged.locale === "string" ? merged.locale : "en_US");
905
+ const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, merged)}>${embed.fallbackHtml ?? ""}</div>`;
906
+ return {
907
+ kind: "script",
908
+ key: `${sdkLocale} ${markup}`,
909
+ markup,
910
+ driver: facebookDriver(sdkLocale),
911
+ minHeight: MIN_HEIGHT$4[embed.kind],
912
+ label: "Facebook",
913
+ hasFallback: hasFallback(embed.fallbackHtml),
914
+ maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0
915
+ };
916
+ }
766
917
  // src/components/script-embed.tsx
767
- const ATTEMPTS = 3;
768
- const RENDER_TIMEOUT_MS = 15e3;
769
- const RETRY_DELAY_MS = 1e3;
918
+ const LAYER = { width: "100%" };
770
919
  function toError(error) {
771
920
  return error instanceof Error ? error : new Error(String(error));
772
921
  }
@@ -803,13 +952,13 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
803
952
  if (cancelled || done) return;
804
953
  stop();
805
954
  stop = () => {};
806
- if (number >= ATTEMPTS) {
955
+ if (number >= 3) {
807
956
  callbacks.current.onError?.(error);
808
957
  return;
809
958
  }
810
959
  timer = setTimeout(() => {
811
960
  attempt(number + 1);
812
- }, RETRY_DELAY_MS * 2 ** (number - 1));
961
+ }, RETRY_DELAY_MS$1 * 2 ** (number - 1));
813
962
  };
814
963
  const attempt = (number) => {
815
964
  if (cancelled || done) return;
@@ -843,99 +992,55 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
843
992
  maxWidth,
844
993
  ...style
845
994
  };
846
- return /* @__PURE__ */ jsxs("div", {
995
+ return /* @__PURE__ */ jsx("div", {
847
996
  ...rest,
848
997
  style: wrapper,
849
- children: [/* @__PURE__ */ jsx("div", {
850
- ref: container,
851
- suppressHydrationWarning: true,
852
- dangerouslySetInnerHTML: { __html: markup }
853
- }), !hasFallback && !rendered && (placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
998
+ children: /* @__PURE__ */ jsxs("div", {
999
+ style: LAYER,
1000
+ children: [/* @__PURE__ */ jsx("div", {
1001
+ ref: container,
1002
+ suppressHydrationWarning: true,
1003
+ dangerouslySetInnerHTML: { __html: markup }
1004
+ }), !hasFallback && !rendered && (placeholder ?? /* @__PURE__ */ jsx(Skeleton, { minHeight }))]
1005
+ })
854
1006
  });
855
1007
  }
856
1008
  // 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
1009
  function FacebookEmbed(props) {
879
- const { url, embed: given, onError, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
1010
+ const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
880
1011
  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, {
1012
+ const plan = embed ? facebookPlan(embed, {
1013
+ locale,
893
1014
  showText,
894
1015
  allowfullscreen,
895
1016
  autoplay,
896
1017
  showCaptions
1018
+ }) : void 0;
1019
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1020
+ if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
1021
+ ...shared,
1022
+ ...planProps(plan),
1023
+ maxWidth: maxWidth ?? plan.maxWidth,
1024
+ height,
1025
+ maxHeight
897
1026
  });
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>`;
1027
+ if (plan?.kind !== "script") return null;
918
1028
  return /* @__PURE__ */ jsx(ScriptEmbed, {
919
- maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0,
920
1029
  ...shared,
921
1030
  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}`);
1031
+ maxWidth: maxWidth ?? plan.maxWidth,
1032
+ driver: plan.driver,
1033
+ markup: plan.markup,
1034
+ hasFallback: plan.hasFallback,
1035
+ minHeight: plan.minHeight,
1036
+ label: plan.label
1037
+ }, plan.key);
928
1038
  }
929
- // src/components/giphy-embed.tsx
1039
+ // src/core/plans/giphy.ts
930
1040
  /** 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,
1041
+ function giphyPlan(embed) {
1042
+ return {
1043
+ kind: "iframe",
939
1044
  src: `https://giphy.com/embed/${embed.id}`,
940
1045
  title: "Giphy GIF",
941
1046
  allow: "fullscreen",
@@ -944,50 +1049,74 @@ function GiphyEmbed(props) {
944
1049
  height: 1
945
1050
  },
946
1051
  size: embed.size
1052
+ };
1053
+ }
1054
+ // src/components/giphy-embed.tsx
1055
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
1056
+ function GiphyEmbed(props) {
1057
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
1058
+ const { embed, error } = resolveEmbed(url, given, "giphy");
1059
+ const plan = embed ? giphyPlan(embed) : void 0;
1060
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1061
+ if (plan?.kind !== "iframe") return null;
1062
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1063
+ ...frame,
1064
+ ...planProps(plan),
1065
+ onError,
1066
+ maxWidth: maxWidth ?? plan.maxWidth
947
1067
  });
948
1068
  }
949
- // src/components/instagram-embed.tsx
1069
+ // src/core/plans/instagram.ts
950
1070
  /** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
951
1071
  const MIN_HEIGHT$3 = 680;
952
1072
  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 });
1073
+ function instagramPlan(embed, options) {
1074
+ const merged = withProps(embed.options, { captioned: options.captioned });
959
1075
  const markup = `<blockquote${attributes({
960
1076
  "data-instgrm-permalink": embed.url,
961
- "data-instgrm-version": options.version,
962
- "data-instgrm-captioned": options.captioned === true ? true : void 0,
1077
+ "data-instgrm-version": merged.version,
1078
+ "data-instgrm-captioned": merged.captioned === true ? true : void 0,
963
1079
  style: FLUID_WIDTH
964
1080
  })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1081
+ return {
1082
+ kind: "script",
1083
+ key: markup,
1084
+ markup,
1085
+ driver: instagramDriver,
1086
+ minHeight: MIN_HEIGHT$3,
1087
+ label: "Instagram",
1088
+ hasFallback: hasFallback(embed.fallbackHtml),
1089
+ maxWidth: 540
1090
+ };
1091
+ }
1092
+ // src/components/instagram-embed.tsx
1093
+ function InstagramEmbed(props) {
1094
+ const { url, embed: given, onError, maxWidth, captioned, ...shared } = props;
1095
+ const { embed, error } = resolveEmbed(url, given, "instagram");
1096
+ const plan = embed ? instagramPlan(embed, { captioned }) : void 0;
1097
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1098
+ if (plan?.kind !== "script") return null;
965
1099
  return /* @__PURE__ */ jsx(ScriptEmbed, {
966
1100
  ...shared,
967
1101
  onError,
968
- maxWidth,
969
- driver: instagramDriver,
970
- markup,
971
- hasFallback: hasFallback(embed.fallbackHtml),
972
- minHeight: MIN_HEIGHT$3,
973
- label: "Instagram"
974
- }, markup);
1102
+ maxWidth: maxWidth ?? plan.maxWidth,
1103
+ driver: plan.driver,
1104
+ markup: plan.markup,
1105
+ hasFallback: plan.hasFallback,
1106
+ minHeight: plan.minHeight,
1107
+ label: plan.label
1108
+ }, plan.key);
975
1109
  }
976
- // src/components/kick-embed.tsx
1110
+ // src/core/plans/kick.ts
977
1111
  const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
978
1112
  /** 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)}`,
1113
+ function kickPlan(embed, options) {
1114
+ const fromOptions = [];
1115
+ if (options.autoplay !== void 0) fromOptions.push(["autoplay", options.autoplay]);
1116
+ if (options.muted !== void 0) fromOptions.push(["muted", options.muted]);
1117
+ return {
1118
+ kind: "iframe",
1119
+ src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT.has(key)), fromOptions)}`,
991
1120
  title: "Kick player",
992
1121
  allow: "autoplay; fullscreen",
993
1122
  scrolling: "no",
@@ -996,34 +1125,63 @@ function KickEmbed(props) {
996
1125
  height: 9
997
1126
  },
998
1127
  size: embed.size
1128
+ };
1129
+ }
1130
+ // src/components/kick-embed.tsx
1131
+ /** A live channel at 16:9. */
1132
+ function KickEmbed(props) {
1133
+ const { url, embed: given, onError, maxWidth, autoplay, muted, ...frame } = props;
1134
+ const { embed, error } = resolveEmbed(url, given, "kick");
1135
+ const plan = embed ? kickPlan(embed, {
1136
+ autoplay,
1137
+ muted
1138
+ }) : void 0;
1139
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1140
+ if (plan?.kind !== "iframe") return null;
1141
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1142
+ ...frame,
1143
+ ...planProps(plan),
1144
+ onError,
1145
+ maxWidth: maxWidth ?? plan.maxWidth
999
1146
  });
1000
1147
  }
1001
- // src/components/linkedin-embed.tsx
1148
+ // src/core/plans/linkedin.ts
1002
1149
  const DEFAULT_HEIGHT = 670;
1003
1150
  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;
1151
+ /** A fixed height: the embed code's, else 670px. */
1152
+ function linkedinPlan(embed, options) {
1010
1153
  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,
1154
+ if (options.collapsed === true) params.set("collapsed", 1);
1155
+ if (options.collapsed === false) params.delete("collapsed");
1156
+ return {
1157
+ kind: "iframe",
1017
1158
  src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
1018
1159
  title: "LinkedIn post",
1019
1160
  allow: "",
1020
1161
  ratio: {
1021
1162
  width: DEFAULT_WIDTH,
1022
1163
  height: DEFAULT_HEIGHT
1023
- }
1164
+ },
1165
+ height: embed.size?.height ?? DEFAULT_HEIGHT,
1166
+ maxWidth: embed.size?.width ?? DEFAULT_WIDTH
1167
+ };
1168
+ }
1169
+ // src/components/linkedin-embed.tsx
1170
+ /** A fixed height: the `height` prop, else the embed code's, else 670px. */
1171
+ function LinkedInEmbed(props) {
1172
+ const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
1173
+ const { embed, error } = resolveEmbed(url, given, "linkedin");
1174
+ const plan = embed ? linkedinPlan(embed, { collapsed }) : void 0;
1175
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1176
+ if (plan?.kind !== "iframe") return null;
1177
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1178
+ ...frame,
1179
+ ...planProps(plan),
1180
+ maxWidth: maxWidth ?? plan.maxWidth,
1181
+ height: height ?? plan.height
1024
1182
  });
1025
1183
  }
1026
- // src/components/pinterest-embed.tsx
1184
+ // src/core/plans/pinterest.ts
1027
1185
  const ATTRIBUTES$1 = {
1028
1186
  width: "data-pin-width",
1029
1187
  lang: "data-pin-lang",
@@ -1036,26 +1194,39 @@ const PIN_WIDTHS = {
1036
1194
  };
1037
1195
  const DEFAULT_PIN_WIDTH = 236;
1038
1196
  const MIN_HEIGHT$2 = 270;
1197
+ function pinterestPlan(embed, options) {
1198
+ const merged = withProps(embed.options, { width: options.pinWidth });
1199
+ const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, merged)}></a>`;
1200
+ return {
1201
+ kind: "script",
1202
+ key: markup,
1203
+ markup,
1204
+ driver: pinterestDriver,
1205
+ minHeight: MIN_HEIGHT$2,
1206
+ label: "Pinterest",
1207
+ hasFallback: false,
1208
+ maxWidth: PIN_WIDTHS[String(merged.width)] ?? DEFAULT_PIN_WIDTH
1209
+ };
1210
+ }
1211
+ // src/components/pinterest-embed.tsx
1039
1212
  function PinterestEmbed(props) {
1040
1213
  const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
1041
1214
  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>`;
1215
+ const plan = embed ? pinterestPlan(embed, { pinWidth }) : void 0;
1216
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1217
+ if (plan?.kind !== "script") return null;
1047
1218
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1048
1219
  ...shared,
1049
1220
  onError,
1050
- maxWidth: maxWidth ?? pinWidthPx,
1051
- driver: pinterestDriver,
1052
- markup,
1053
- hasFallback: false,
1054
- minHeight: MIN_HEIGHT$2,
1055
- label: "Pinterest"
1056
- }, markup);
1221
+ maxWidth: maxWidth ?? plan.maxWidth,
1222
+ driver: plan.driver,
1223
+ markup: plan.markup,
1224
+ hasFallback: plan.hasFallback,
1225
+ minHeight: plan.minHeight,
1226
+ label: plan.label
1227
+ }, plan.key);
1057
1228
  }
1058
- // src/components/reddit-embed.tsx
1229
+ // src/core/plans/reddit.ts
1059
1230
  const PARAMS$5 = {
1060
1231
  theme: "theme",
1061
1232
  showMedia: "showmedia",
@@ -1066,7 +1237,7 @@ const PARAMS$5 = {
1066
1237
  };
1067
1238
  const SANDBOX = "allow-scripts allow-same-origin allow-popups";
1068
1239
  const ALLOW$6 = "clipboard-read; clipboard-write";
1069
- const START_HEIGHT$1 = 316;
1240
+ const START_HEIGHT = 316;
1070
1241
  /** docs/decisions.md D52. */
1071
1242
  const REDDIT_HEIGHT = {
1072
1243
  origin: "https://embed.reddit.com",
@@ -1077,30 +1248,15 @@ const REDDIT_HEIGHT = {
1077
1248
  }
1078
1249
  };
1079
1250
  /** 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;
1251
+ function redditPlan(embed, options) {
1085
1252
  const fromProps = [];
1086
- const values = {
1087
- theme,
1088
- showMedia,
1089
- showTitle,
1090
- showUsername,
1091
- locale,
1092
- depth
1093
- };
1094
1253
  for (const [prop, name] of Object.entries(PARAMS$5)) {
1095
- const value = values[prop];
1254
+ const value = options[prop];
1096
1255
  if (value !== void 0) fromProps.push([name, value]);
1097
1256
  }
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)}`,
1257
+ return {
1258
+ kind: "iframe",
1259
+ src: `https://embed.reddit.com${embed.url.slice(22)}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
1104
1260
  title: "Reddit post",
1105
1261
  allow: ALLOW$6,
1106
1262
  sandbox: SANDBOX,
@@ -1110,21 +1266,39 @@ function RedditEmbed(props) {
1110
1266
  height: 1
1111
1267
  },
1112
1268
  messageHeight: REDDIT_HEIGHT,
1113
- startHeight: embed.size?.height ?? START_HEIGHT$1
1269
+ startHeight: embed.size?.height ?? START_HEIGHT,
1270
+ maxWidth: 640
1271
+ };
1272
+ }
1273
+ // src/components/reddit-embed.tsx
1274
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
1275
+ function RedditEmbed(props) {
1276
+ const { url, embed: given, onError, maxWidth, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
1277
+ const { embed, error } = resolveEmbed(url, given, "reddit");
1278
+ const plan = embed ? redditPlan(embed, {
1279
+ theme,
1280
+ showMedia,
1281
+ showTitle,
1282
+ showUsername,
1283
+ locale,
1284
+ depth
1285
+ }) : void 0;
1286
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1287
+ if (plan?.kind !== "iframe") return null;
1288
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1289
+ ...shared,
1290
+ ...planProps(plan),
1291
+ onError,
1292
+ maxWidth: maxWidth ?? plan.maxWidth
1114
1293
  });
1115
1294
  }
1116
- // src/components/snapchat-embed.tsx
1295
+ // src/core/plans/snapchat.ts
1117
1296
  const ALLOW$5 = "autoplay; camera; microphone; clipboard-write;";
1118
1297
  /** 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;
1298
+ function snapchatPlan(embed) {
1124
1299
  const title = embed.options.title;
1125
- return /* @__PURE__ */ jsx(IframeEmbed, {
1126
- ...frame,
1127
- maxWidth,
1300
+ return {
1301
+ kind: "iframe",
1128
1302
  src: `${embed.url}/embed`,
1129
1303
  title: typeof title === "string" && title !== "" ? title : "Snapchat",
1130
1304
  allow: ALLOW$5,
@@ -1133,10 +1307,25 @@ function SnapchatEmbed(props) {
1133
1307
  width: 416,
1134
1308
  height: 692
1135
1309
  },
1136
- size: embed.size
1310
+ size: embed.size,
1311
+ maxWidth: 416
1312
+ };
1313
+ }
1314
+ // src/components/snapchat-embed.tsx
1315
+ /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
1316
+ function SnapchatEmbed(props) {
1317
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
1318
+ const { embed, error } = resolveEmbed(url, given, "snapchat");
1319
+ const plan = embed ? snapchatPlan(embed) : void 0;
1320
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1321
+ if (plan?.kind !== "iframe") return null;
1322
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1323
+ ...frame,
1324
+ ...planProps(plan),
1325
+ maxWidth: maxWidth ?? plan.maxWidth
1137
1326
  });
1138
1327
  }
1139
- // src/components/soundcloud-embed.tsx
1328
+ // src/core/plans/soundcloud.ts
1140
1329
  const PARAMS$4 = {
1141
1330
  visual: "visual",
1142
1331
  color: "color",
@@ -1150,13 +1339,33 @@ const PARAMS$4 = {
1150
1339
  };
1151
1340
  const ALLOW$4 = "autoplay; encrypted-media";
1152
1341
  const URL_HEIGHT = 400;
1342
+ /** A fixed height: the embed code's, else 400px for the visual player. */
1343
+ function soundcloudPlan(embed, options) {
1344
+ const fromOptions = [];
1345
+ for (const [option, name] of Object.entries(PARAMS$4)) {
1346
+ const value = options[option];
1347
+ if (value !== void 0) fromOptions.push([name, value]);
1348
+ }
1349
+ const fromUrl = embed.size === void 0;
1350
+ return {
1351
+ kind: "iframe",
1352
+ src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromOptions)}`,
1353
+ title: "SoundCloud player",
1354
+ allow: ALLOW$4,
1355
+ scrolling: "no",
1356
+ ratio: {
1357
+ width: 16,
1358
+ height: 9
1359
+ },
1360
+ height: embed.size?.height ?? URL_HEIGHT
1361
+ };
1362
+ }
1363
+ // src/components/soundcloud-embed.tsx
1153
1364
  /** A fixed height: the `height` prop, else the embed code's, else 400px for the visual player. */
1154
1365
  function SoundCloudEmbed(props) {
1155
- const { url, embed: given, onError, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
1366
+ const { url, embed: given, onError, maxWidth, height, visual, color, autoPlay, hideRelated, showComments, showUser, showReposts, showTeaser, showArtwork, ...frame } = props;
1156
1367
  const { embed, error } = resolveEmbed(url, given, "soundcloud");
1157
- useReportError(error, onError);
1158
- if (!embed) return null;
1159
- const values = {
1368
+ const plan = embed ? soundcloudPlan(embed, {
1160
1369
  visual,
1161
1370
  color,
1162
1371
  autoPlay,
@@ -1166,52 +1375,32 @@ function SoundCloudEmbed(props) {
1166
1375
  showReposts,
1167
1376
  showTeaser,
1168
1377
  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;
1378
+ }) : void 0;
1379
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1380
+ if (plan?.kind !== "iframe") return null;
1176
1381
  return /* @__PURE__ */ jsx(IframeEmbed, {
1177
1382
  ...frame,
1383
+ ...planProps(plan),
1178
1384
  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
- }
1385
+ maxWidth: maxWidth ?? plan.maxWidth,
1386
+ height: height ?? plan.height
1188
1387
  });
1189
1388
  }
1190
- // src/components/spotify-embed.tsx
1389
+ // src/core/plans/spotify.ts
1191
1390
  const ALLOW$3 = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
1192
1391
  const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
1193
1392
  const COMPACT_HEIGHT = 152;
1194
1393
  const FULL_HEIGHT = 352;
1195
1394
  /**
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.
1395
+ * A fixed height: the embed code's, else 152px for a track or episode and 352px for the rest.
1396
+ * A video show keeps its 16:9 aspect ratio instead.
1198
1397
  */
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;
1398
+ function spotifyPlan(embed, options) {
1204
1399
  const type = new URL(embed.url).pathname.split("/")[1] ?? "";
1205
1400
  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),
1401
+ const params = query(Object.entries(embed.options), options.theme === void 0 ? void 0 : [["theme", options.theme]]);
1402
+ return {
1403
+ kind: "iframe",
1215
1404
  src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
1216
1405
  title: "Spotify Embed",
1217
1406
  allow: ALLOW$3,
@@ -1219,10 +1408,29 @@ function SpotifyEmbed(props) {
1219
1408
  width: 16,
1220
1409
  height: 9
1221
1410
  },
1222
- size: video ? embed.size : void 0
1411
+ size: video ? embed.size : void 0,
1412
+ borderRadius: 12,
1413
+ height: video ? void 0 : embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT)
1414
+ };
1415
+ }
1416
+ // src/components/spotify-embed.tsx
1417
+ /**
1418
+ * A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
1419
+ * and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
1420
+ */
1421
+ function SpotifyEmbed(props) {
1422
+ const { url, embed: given, onError, height, theme, ...frame } = props;
1423
+ const { embed, error } = resolveEmbed(url, given, "spotify");
1424
+ const plan = embed ? spotifyPlan(embed, { theme }) : void 0;
1425
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1426
+ if (plan?.kind !== "iframe") return null;
1427
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1428
+ ...frame,
1429
+ ...planProps(plan),
1430
+ height: height ?? plan.height
1223
1431
  });
1224
1432
  }
1225
- // src/components/telegram-embed.tsx
1433
+ // src/core/plans/telegram.ts
1226
1434
  const PARAMS$3 = [
1227
1435
  ["comment", "comment"],
1228
1436
  ["userpic", "userpic"],
@@ -1250,11 +1458,8 @@ const TELEGRAM_HEIGHT = {
1250
1458
  }
1251
1459
  };
1252
1460
  /** 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;
1461
+ function telegramPlan(embed, options) {
1462
+ const { userpic, color, dark, darkColor } = options;
1258
1463
  const values = {
1259
1464
  ...embed.options,
1260
1465
  ...userpic === void 0 ? {} : { userpic },
@@ -1267,10 +1472,8 @@ function TelegramEmbed(props) {
1267
1472
  const value = param(name, values[option]);
1268
1473
  if (value !== void 0) params.push([name, value]);
1269
1474
  }
1270
- return /* @__PURE__ */ jsx(IframeEmbed, {
1271
- ...shared,
1272
- onError,
1273
- maxWidth,
1475
+ return {
1476
+ kind: "iframe",
1274
1477
  src: `${embed.url}${query(params)}`,
1275
1478
  title: "Telegram post",
1276
1479
  allow: "",
@@ -1280,36 +1483,71 @@ function TelegramEmbed(props) {
1280
1483
  height: 1
1281
1484
  },
1282
1485
  messageHeight: TELEGRAM_HEIGHT,
1283
- startHeight: 300
1486
+ startHeight: 300,
1487
+ maxWidth: 500
1488
+ };
1489
+ }
1490
+ // src/components/telegram-embed.tsx
1491
+ /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
1492
+ function TelegramEmbed(props) {
1493
+ const { url, embed: given, onError, maxWidth, userpic, color, dark, darkColor, ...shared } = props;
1494
+ const { embed, error } = resolveEmbed(url, given, "telegram");
1495
+ const plan = embed ? telegramPlan(embed, {
1496
+ userpic,
1497
+ color,
1498
+ dark,
1499
+ darkColor
1500
+ }) : void 0;
1501
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1502
+ if (plan?.kind !== "iframe") return null;
1503
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1504
+ ...shared,
1505
+ ...planProps(plan),
1506
+ onError,
1507
+ maxWidth: maxWidth ?? plan.maxWidth
1284
1508
  });
1285
1509
  }
1286
- // src/components/threads-embed.tsx
1510
+ // src/core/plans/threads.ts
1287
1511
  /** A text-only post (docs/decisions.md D34). */
1288
1512
  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 });
1513
+ function threadsPlan(embed, options) {
1514
+ const merged = withProps(embed.options, { theme: options.theme });
1295
1515
  const markup = `<blockquote${attributes({
1296
1516
  "data-text-post-permalink": embed.url,
1297
- "data-text-post-version": options.version ?? 0,
1517
+ "data-text-post-version": merged.version ?? 0,
1298
1518
  id: `ig-tp-${embed.id}`,
1299
- "data-theme": options.theme
1519
+ "data-theme": merged.theme
1300
1520
  })}>${embed.fallbackHtml ?? ""}</blockquote>`;
1521
+ return {
1522
+ kind: "script",
1523
+ key: markup,
1524
+ markup,
1525
+ driver: threadsDriver,
1526
+ minHeight: MIN_HEIGHT$1,
1527
+ label: "Threads",
1528
+ hasFallback: hasFallback(embed.fallbackHtml),
1529
+ maxWidth: 658
1530
+ };
1531
+ }
1532
+ // src/components/threads-embed.tsx
1533
+ function ThreadsEmbed(props) {
1534
+ const { url, embed: given, onError, maxWidth, theme, ...shared } = props;
1535
+ const { embed, error } = resolveEmbed(url, given, "threads");
1536
+ const plan = embed ? threadsPlan(embed, { theme }) : void 0;
1537
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1538
+ if (plan?.kind !== "script") return null;
1301
1539
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1302
1540
  ...shared,
1303
1541
  onError,
1304
- maxWidth,
1305
- driver: threadsDriver,
1306
- markup,
1307
- hasFallback: hasFallback(embed.fallbackHtml),
1308
- minHeight: MIN_HEIGHT$1,
1309
- label: "Threads"
1310
- }, markup);
1542
+ maxWidth: maxWidth ?? plan.maxWidth,
1543
+ driver: plan.driver,
1544
+ markup: plan.markup,
1545
+ hasFallback: plan.hasFallback,
1546
+ minHeight: plan.minHeight,
1547
+ label: plan.label
1548
+ }, plan.key);
1311
1549
  }
1312
- // src/components/tiktok-embed.tsx
1550
+ // src/core/plans/tiktok.ts
1313
1551
  const PARAMS$2 = {
1314
1552
  controls: "controls",
1315
1553
  progressBar: "progress_bar",
@@ -1328,12 +1566,27 @@ const PARAMS$2 = {
1328
1566
  };
1329
1567
  const ALLOW$2 = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
1330
1568
  /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
1569
+ function tiktokPlan(embed, options) {
1570
+ const params = playerParams(options, PARAMS$2);
1571
+ return {
1572
+ kind: "iframe",
1573
+ src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
1574
+ title: "TikTok video player",
1575
+ allow: ALLOW$2,
1576
+ ratio: {
1577
+ width: 9,
1578
+ height: 16
1579
+ },
1580
+ size: embed.size,
1581
+ maxWidth: 325
1582
+ };
1583
+ }
1584
+ // src/components/tiktok-embed.tsx
1585
+ /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
1331
1586
  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;
1587
+ const { url, embed: given, onError, maxWidth, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
1333
1588
  const { embed, error } = resolveEmbed(url, given, "tiktok");
1334
- useReportError(error, onError);
1335
- if (!embed) return null;
1336
- const params = playerParams({
1589
+ const plan = embed ? tiktokPlan(embed, {
1337
1590
  controls,
1338
1591
  progressBar,
1339
1592
  playButton,
@@ -1348,21 +1601,16 @@ function TikTokEmbed(props) {
1348
1601
  nativeContextMenu,
1349
1602
  closedCaption,
1350
1603
  forceMuted
1351
- }, PARAMS$2);
1604
+ }) : void 0;
1605
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1606
+ if (plan?.kind !== "iframe") return null;
1352
1607
  return /* @__PURE__ */ jsx(IframeEmbed, {
1353
1608
  ...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
1609
+ ...planProps(plan),
1610
+ maxWidth: maxWidth ?? plan.maxWidth
1363
1611
  });
1364
1612
  }
1365
- // src/components/tumblr-embed.tsx
1613
+ // src/core/plans/tumblr.ts
1366
1614
  /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
1367
1615
  const TUMBLR_HEIGHT = {
1368
1616
  origin: "https://embed.tumblr.com",
@@ -1373,19 +1621,11 @@ const TUMBLR_HEIGHT = {
1373
1621
  return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
1374
1622
  }
1375
1623
  };
1376
- const START_HEIGHT = 400;
1377
1624
  /** 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`,
1625
+ function tumblrPlan(embed) {
1626
+ return {
1627
+ kind: "iframe",
1628
+ src: `https://embed.tumblr.com/embed/post/${embed.url.slice(23).split("/")[0] ?? ""}/${embed.id}/v2`,
1389
1629
  title: "Tumblr post",
1390
1630
  allow: "",
1391
1631
  scrolling: "no",
@@ -1394,10 +1634,26 @@ function TumblrEmbed(props) {
1394
1634
  height: 1
1395
1635
  },
1396
1636
  messageHeight: TUMBLR_HEIGHT,
1397
- startHeight: START_HEIGHT
1637
+ startHeight: 400,
1638
+ maxWidth: 540
1639
+ };
1640
+ }
1641
+ // src/components/tumblr-embed.tsx
1642
+ /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
1643
+ function TumblrEmbed(props) {
1644
+ const { url, embed: given, onError, maxWidth, ...shared } = props;
1645
+ const { embed, error } = resolveEmbed(url, given, "tumblr");
1646
+ const plan = embed ? tumblrPlan(embed) : void 0;
1647
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1648
+ if (plan?.kind !== "iframe") return null;
1649
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1650
+ ...shared,
1651
+ ...planProps(plan),
1652
+ onError,
1653
+ maxWidth: maxWidth ?? plan.maxWidth
1398
1654
  });
1399
1655
  }
1400
- // src/components/twitch-embed.tsx
1656
+ // src/core/plans/twitch.ts
1401
1657
  const RESERVED = [
1402
1658
  "channel",
1403
1659
  "video",
@@ -1413,18 +1669,15 @@ function player(url, id) {
1413
1669
  return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
1414
1670
  }
1415
1671
  /** `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;
1672
+ function twitchPlan(embed, options) {
1673
+ const { autoplay, muted, time } = options;
1421
1674
  const params = [];
1422
1675
  if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
1423
1676
  if (muted !== void 0) params.push(["muted", String(muted)]);
1424
1677
  if (time !== void 0) params.push(["time", time]);
1425
1678
  const [base, content] = player(embed.url, embed.id);
1426
- return /* @__PURE__ */ jsx(IframeEmbed, {
1427
- ...frame,
1679
+ return {
1680
+ kind: "iframe",
1428
1681
  src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
1429
1682
  title: "Twitch player",
1430
1683
  allow: "",
@@ -1434,9 +1687,27 @@ function TwitchEmbed(props) {
1434
1687
  },
1435
1688
  size: embed.size,
1436
1689
  hostParam: "parent"
1690
+ };
1691
+ }
1692
+ // src/components/twitch-embed.tsx
1693
+ /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
1694
+ function TwitchEmbed(props) {
1695
+ const { url, embed: given, onError, maxWidth, autoplay, muted, time, ...frame } = props;
1696
+ const { embed, error } = resolveEmbed(url, given, "twitch");
1697
+ const plan = embed ? twitchPlan(embed, {
1698
+ autoplay,
1699
+ muted,
1700
+ time
1701
+ }) : void 0;
1702
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1703
+ if (plan?.kind !== "iframe") return null;
1704
+ return /* @__PURE__ */ jsx(IframeEmbed, {
1705
+ ...frame,
1706
+ ...planProps(plan),
1707
+ maxWidth: maxWidth ?? plan.maxWidth
1437
1708
  });
1438
1709
  }
1439
- // src/components/vimeo-embed.tsx
1710
+ // src/core/plans/vimeo.ts
1440
1711
  const PARAMS$1 = {
1441
1712
  autopause: "autopause",
1442
1713
  autoplay: "autoplay",
@@ -1457,14 +1728,30 @@ const PARAMS$1 = {
1457
1728
  transparent: "transparent"
1458
1729
  };
1459
1730
  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;
1731
+ function vimeoPlan(embed, options) {
1732
+ const { t, ...rest } = options;
1465
1733
  const { t: parsedStart, ...parsed } = embed.options;
1466
1734
  const hash = new URL(embed.url).pathname.split("/")[2];
1467
- const params = playerParams({
1735
+ const params = playerParams(rest, PARAMS$1);
1736
+ const start = t ?? parsedStart;
1737
+ return {
1738
+ kind: "iframe",
1739
+ 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))}`}`,
1740
+ title: "Vimeo video player",
1741
+ allow: ALLOW$1,
1742
+ referrerPolicy: "strict-origin-when-cross-origin",
1743
+ ratio: {
1744
+ width: 16,
1745
+ height: 9
1746
+ },
1747
+ size: embed.size
1748
+ };
1749
+ }
1750
+ // src/components/vimeo-embed.tsx
1751
+ function VimeoEmbed(props) {
1752
+ 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;
1753
+ const { embed, error } = resolveEmbed(url, given, "vimeo");
1754
+ const plan = embed ? vimeoPlan(embed, {
1468
1755
  autopause,
1469
1756
  autoplay,
1470
1757
  background,
@@ -1481,23 +1768,18 @@ function VimeoEmbed(props) {
1481
1768
  quality,
1482
1769
  speed,
1483
1770
  title,
1484
- transparent
1485
- }, PARAMS$1);
1486
- const start = t ?? parsedStart;
1771
+ transparent,
1772
+ t
1773
+ }) : void 0;
1774
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1775
+ if (plan?.kind !== "iframe") return null;
1487
1776
  return /* @__PURE__ */ jsx(IframeEmbed, {
1488
1777
  ...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
1778
+ ...planProps(plan),
1779
+ maxWidth: maxWidth ?? plan.maxWidth
1498
1780
  });
1499
1781
  }
1500
- // src/components/x-embed.tsx
1782
+ // src/core/plans/x.ts
1501
1783
  const ATTRIBUTES = {
1502
1784
  theme: "data-theme",
1503
1785
  conversation: "data-conversation",
@@ -1509,33 +1791,47 @@ const ATTRIBUTES = {
1509
1791
  };
1510
1792
  /** A plain text post, the smallest X renders (docs/decisions.md D34). */
1511
1793
  const MIN_HEIGHT = 250;
1794
+ function xPlan(embed, options) {
1795
+ const merged = withProps(embed.options, { ...options });
1796
+ const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
1797
+ const markup = `<blockquote${dataAttributes(ATTRIBUTES, merged)}>${content}</blockquote>`;
1798
+ return {
1799
+ kind: "script",
1800
+ key: markup,
1801
+ markup,
1802
+ driver: xDriver,
1803
+ minHeight: MIN_HEIGHT,
1804
+ label: "X",
1805
+ hasFallback: hasFallback(embed.fallbackHtml),
1806
+ maxWidth: 550
1807
+ };
1808
+ }
1809
+ // src/components/x-embed.tsx
1512
1810
  function XEmbed(props) {
1513
- const { url, embed: given, onError, maxWidth = 550, theme, conversation, cards, align, lang, dnt, ...shared } = props;
1811
+ const { url, embed: given, onError, maxWidth, theme, conversation, cards, align, lang, dnt, ...shared } = props;
1514
1812
  const { embed, error } = resolveEmbed(url, given, "x");
1515
- useReportError(error, onError);
1516
- if (!embed) return null;
1517
- const options = withProps(embed.options, {
1813
+ const plan = embed ? xPlan(embed, {
1518
1814
  theme,
1519
1815
  conversation,
1520
1816
  cards,
1521
1817
  align,
1522
1818
  lang,
1523
1819
  dnt
1524
- });
1525
- const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
1526
- const markup = `<blockquote${dataAttributes(ATTRIBUTES, options)}>${content}</blockquote>`;
1820
+ }) : void 0;
1821
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1822
+ if (plan?.kind !== "script") return null;
1527
1823
  return /* @__PURE__ */ jsx(ScriptEmbed, {
1528
1824
  ...shared,
1529
1825
  onError,
1530
- maxWidth,
1531
- driver: xDriver,
1532
- markup,
1533
- hasFallback: hasFallback(embed.fallbackHtml),
1534
- minHeight: MIN_HEIGHT,
1535
- label: "X"
1536
- }, markup);
1826
+ maxWidth: maxWidth ?? plan.maxWidth,
1827
+ driver: plan.driver,
1828
+ markup: plan.markup,
1829
+ hasFallback: plan.hasFallback,
1830
+ minHeight: plan.minHeight,
1831
+ label: plan.label
1832
+ }, plan.key);
1537
1833
  }
1538
- // src/components/youtube-embed.tsx
1834
+ // src/core/plans/youtube.ts
1539
1835
  const PARAMS = {
1540
1836
  autoplay: "autoplay",
1541
1837
  ccLangPref: "cc_lang_pref",
@@ -1559,14 +1855,32 @@ const PARAMS = {
1559
1855
  widgetReferrer: "widget_referrer"
1560
1856
  };
1561
1857
  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;
1858
+ function youtubePlan(embed, options) {
1859
+ const { nocookie, ...rest } = options;
1567
1860
  const { nocookie: parsedNocookie, ...parsed } = embed.options;
1568
1861
  const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
1569
- const params = playerParams({
1862
+ const params = playerParams(rest, PARAMS);
1863
+ return {
1864
+ kind: "iframe",
1865
+ src: `${host}/embed/${embed.id}${query(Object.entries(parsed), params)}`,
1866
+ title: "YouTube video player",
1867
+ allow: ALLOW,
1868
+ referrerPolicy: "strict-origin-when-cross-origin",
1869
+ ratio: embed.url.includes("/shorts/") ? {
1870
+ width: 9,
1871
+ height: 16
1872
+ } : {
1873
+ width: 16,
1874
+ height: 9
1875
+ },
1876
+ size: embed.size
1877
+ };
1878
+ }
1879
+ // src/components/youtube-embed.tsx
1880
+ function YouTubeEmbed(props) {
1881
+ 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;
1882
+ const { embed, error } = resolveEmbed(url, given, "youtube");
1883
+ const plan = embed ? youtubePlan(embed, {
1570
1884
  autoplay,
1571
1885
  ccLangPref,
1572
1886
  ccLoadPolicy,
@@ -1586,22 +1900,15 @@ function YouTubeEmbed(props) {
1586
1900
  playsinline,
1587
1901
  rel,
1588
1902
  start,
1589
- widgetReferrer
1590
- }, PARAMS);
1903
+ widgetReferrer,
1904
+ nocookie
1905
+ }) : void 0;
1906
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
1907
+ if (plan?.kind !== "iframe") return null;
1591
1908
  return /* @__PURE__ */ jsx(IframeEmbed, {
1592
1909
  ...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
1910
+ ...planProps(plan),
1911
+ maxWidth: maxWidth ?? plan.maxWidth
1605
1912
  });
1606
1913
  }
1607
1914
  // src/components/social-embed.tsx
@@ -1613,9 +1920,7 @@ function SocialEmbed(props) {
1613
1920
  maxHeight
1614
1921
  };
1615
1922
  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);
1923
+ useReportError(embed === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
1619
1924
  if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
1620
1925
  switch (embed.platform) {
1621
1926
  case "x": return /* @__PURE__ */ jsx(XEmbed, {