social-embeds 0.7.1 → 0.8.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.
Files changed (174) hide show
  1. package/README.md +13 -8
  2. package/dist/components/apple-embed.d.ts +7 -0
  3. package/dist/components/apple-embed.js +39 -0
  4. package/dist/components/bluesky-embed.d.ts +10 -0
  5. package/dist/components/bluesky-embed.js +27 -0
  6. package/dist/components/dailymotion-embed.d.ts +9 -0
  7. package/dist/components/dailymotion-embed.js +30 -0
  8. package/dist/components/facebook-embed.d.ts +6 -0
  9. package/dist/components/facebook-embed.js +40 -0
  10. package/dist/components/flickr-embed.d.ts +6 -0
  11. package/dist/components/flickr-embed.js +27 -0
  12. package/dist/components/generic-iframe-embed.d.ts +11 -0
  13. package/dist/components/generic-iframe-embed.js +26 -0
  14. package/dist/components/giphy-embed.d.ts +4 -0
  15. package/dist/components/giphy-embed.js +22 -0
  16. package/dist/components/hooks.js +36 -0
  17. package/dist/components/iframe-embed.js +169 -0
  18. package/dist/components/imgur-embed.d.ts +6 -0
  19. package/dist/components/imgur-embed.js +23 -0
  20. package/dist/components/instagram-embed.d.ts +5 -0
  21. package/dist/components/instagram-embed.js +25 -0
  22. package/dist/components/kick-embed.d.ts +6 -0
  23. package/dist/components/kick-embed.js +25 -0
  24. package/dist/components/linkedin-embed.d.ts +6 -0
  25. package/dist/components/linkedin-embed.js +23 -0
  26. package/dist/components/pinterest-embed.d.ts +5 -0
  27. package/dist/components/pinterest-embed.js +25 -0
  28. package/dist/components/reddit-embed.d.ts +6 -0
  29. package/dist/components/reddit-embed.js +29 -0
  30. package/dist/components/rumble-embed.d.ts +4 -0
  31. package/dist/components/rumble-embed.js +22 -0
  32. package/dist/components/script-embed.js +107 -0
  33. package/dist/components/shared.d.ts +29 -0
  34. package/dist/components/snapchat-embed.d.ts +4 -0
  35. package/dist/components/snapchat-embed.js +22 -0
  36. package/dist/components/social-embed.d.ts +60 -0
  37. package/dist/components/social-embed.js +221 -0
  38. package/dist/components/soundcloud-embed.d.ts +6 -0
  39. package/dist/components/soundcloud-embed.js +33 -0
  40. package/dist/components/spotify-embed.d.ts +9 -0
  41. package/dist/components/spotify-embed.js +25 -0
  42. package/dist/components/strava-embed.d.ts +6 -0
  43. package/dist/components/strava-embed.js +26 -0
  44. package/dist/components/streamable-embed.d.ts +6 -0
  45. package/dist/components/streamable-embed.js +28 -0
  46. package/dist/components/telegram-embed.d.ts +6 -0
  47. package/dist/components/telegram-embed.js +27 -0
  48. package/dist/components/tenor-embed.d.ts +4 -0
  49. package/dist/components/tenor-embed.js +22 -0
  50. package/dist/components/threads-embed.d.ts +5 -0
  51. package/dist/components/threads-embed.js +25 -0
  52. package/dist/components/tiktok-embed.d.ts +6 -0
  53. package/dist/components/tiktok-embed.js +37 -0
  54. package/dist/components/truthsocial-embed.d.ts +4 -0
  55. package/dist/components/truthsocial-embed.js +22 -0
  56. package/dist/components/tumblr-embed.d.ts +4 -0
  57. package/dist/components/tumblr-embed.js +22 -0
  58. package/dist/components/twitch-embed.d.ts +6 -0
  59. package/dist/components/twitch-embed.js +26 -0
  60. package/dist/components/vimeo-embed.d.ts +5 -0
  61. package/dist/components/vimeo-embed.js +40 -0
  62. package/dist/components/x-embed.d.ts +5 -0
  63. package/dist/components/x-embed.js +32 -0
  64. package/dist/components/youtube-embed.d.ts +5 -0
  65. package/dist/components/youtube-embed.js +43 -0
  66. package/dist/core/drivers.js +118 -0
  67. package/dist/core/layout.js +73 -0
  68. package/dist/core/markup.js +30 -0
  69. package/dist/core/params.js +26 -0
  70. package/dist/core/plans/apple.js +44 -0
  71. package/dist/core/plans/bluesky.d.ts +3 -0
  72. package/dist/core/plans/bluesky.js +34 -0
  73. package/dist/core/plans/dailymotion.d.ts +8 -0
  74. package/dist/core/plans/dailymotion.js +37 -0
  75. package/dist/core/plans/facebook.d.ts +15 -0
  76. package/dist/core/plans/facebook.js +79 -0
  77. package/dist/core/plans/flickr.d.ts +7 -0
  78. package/dist/core/plans/flickr.js +37 -0
  79. package/dist/core/plans/generic.js +44 -0
  80. package/dist/core/plans/giphy.js +16 -0
  81. package/dist/core/plans/imgur.d.ts +4 -0
  82. package/dist/core/plans/imgur.js +34 -0
  83. package/dist/core/plans/instagram.d.ts +4 -0
  84. package/dist/core/plans/instagram.js +26 -0
  85. package/dist/core/plans/kick.d.ts +5 -0
  86. package/dist/core/plans/kick.js +22 -0
  87. package/dist/core/plans/linkedin.d.ts +4 -0
  88. package/dist/core/plans/linkedin.js +23 -0
  89. package/dist/core/plans/pinterest.d.ts +4 -0
  90. package/dist/core/plans/pinterest.js +31 -0
  91. package/dist/core/plans/reddit.d.ts +11 -0
  92. package/dist/core/plans/reddit.js +46 -0
  93. package/dist/core/plans/rumble.js +21 -0
  94. package/dist/core/plans/snapchat.js +20 -0
  95. package/dist/core/plans/soundcloud.d.ts +14 -0
  96. package/dist/core/plans/soundcloud.js +37 -0
  97. package/dist/core/plans/spotify.d.ts +4 -0
  98. package/dist/core/plans/spotify.js +29 -0
  99. package/dist/core/plans/strava.d.ts +8 -0
  100. package/dist/core/plans/strava.js +38 -0
  101. package/dist/core/plans/streamable.d.ts +8 -0
  102. package/dist/core/plans/streamable.js +31 -0
  103. package/dist/core/plans/telegram.d.ts +10 -0
  104. package/dist/core/plans/telegram.js +59 -0
  105. package/dist/core/plans/tenor.js +16 -0
  106. package/dist/core/plans/threads.d.ts +4 -0
  107. package/dist/core/plans/threads.js +25 -0
  108. package/dist/core/plans/tiktok.d.ts +17 -0
  109. package/dist/core/plans/tiktok.js +36 -0
  110. package/dist/core/plans/truthsocial.js +43 -0
  111. package/dist/core/plans/tumblr.js +29 -0
  112. package/dist/core/plans/twitch.d.ts +7 -0
  113. package/dist/core/plans/twitch.js +38 -0
  114. package/dist/core/plans/vimeo.d.ts +23 -0
  115. package/dist/core/plans/vimeo.js +42 -0
  116. package/dist/core/plans/x.d.ts +12 -0
  117. package/dist/core/plans/x.js +31 -0
  118. package/dist/core/plans/youtube.d.ts +25 -0
  119. package/dist/core/plans/youtube.js +47 -0
  120. package/dist/core/post-link.js +19 -0
  121. package/dist/core/resolve.js +57 -0
  122. package/dist/core/timing.js +7 -0
  123. package/dist/element.js +1 -1
  124. package/dist/index.d.ts +53 -344
  125. package/dist/index.js +30 -2575
  126. package/dist/loader/load-script.js +114 -0
  127. package/dist/loader/platform-scripts.js +89 -0
  128. package/dist/parser/html.js +172 -0
  129. package/dist/parser/iframe.d.ts +24 -0
  130. package/dist/parser/iframe.js +151 -0
  131. package/dist/parser/lookup.js +20 -0
  132. package/dist/parser/match-url.d.ts +3 -0
  133. package/dist/parser/match-url.js +22 -0
  134. package/dist/parser/parse-embed.d.ts +7 -0
  135. package/dist/parser/parse-embed.js +69 -0
  136. package/dist/parser/platform.js +60 -0
  137. package/dist/parser/platforms/applemusic.js +45 -0
  138. package/dist/parser/platforms/applepodcasts.js +41 -0
  139. package/dist/parser/platforms/bluesky.js +64 -0
  140. package/dist/parser/platforms/dailymotion.js +59 -0
  141. package/dist/parser/platforms/facebook.js +185 -0
  142. package/dist/parser/platforms/flickr.js +134 -0
  143. package/dist/parser/platforms/giphy.js +68 -0
  144. package/dist/parser/platforms/imgur.js +107 -0
  145. package/dist/parser/platforms/index.js +62 -0
  146. package/dist/parser/platforms/instagram.js +59 -0
  147. package/dist/parser/platforms/kick.js +61 -0
  148. package/dist/parser/platforms/linkedin.js +42 -0
  149. package/dist/parser/platforms/pinterest.js +59 -0
  150. package/dist/parser/platforms/reddit.js +68 -0
  151. package/dist/parser/platforms/rumble.js +43 -0
  152. package/dist/parser/platforms/snapchat.js +87 -0
  153. package/dist/parser/platforms/soundcloud.js +128 -0
  154. package/dist/parser/platforms/spotify.js +51 -0
  155. package/dist/parser/platforms/strava.js +55 -0
  156. package/dist/parser/platforms/streamable.js +94 -0
  157. package/dist/parser/platforms/telegram.js +61 -0
  158. package/dist/parser/platforms/tenor.js +78 -0
  159. package/dist/parser/platforms/threads.js +51 -0
  160. package/dist/parser/platforms/tiktok.js +48 -0
  161. package/dist/parser/platforms/truthsocial.js +49 -0
  162. package/dist/parser/platforms/tumblr.js +70 -0
  163. package/dist/parser/platforms/twitch.js +129 -0
  164. package/dist/parser/platforms/vimeo.js +76 -0
  165. package/dist/parser/platforms/x.js +65 -0
  166. package/dist/parser/platforms/youtube.js +90 -0
  167. package/dist/parser/types.d.ts +14 -0
  168. package/dist/parser/url.js +41 -0
  169. package/dist/parser/verify.js +63 -0
  170. package/dist/parser.d.ts +4 -1
  171. package/dist/parser.js +4 -1
  172. package/package.json +1 -1
  173. package/dist/index-DrMHAkyG.d.ts +0 -46
  174. package/dist/parser-CovaPg5T.js +0 -2585
package/README.md CHANGED
@@ -85,6 +85,8 @@ Before 0.7.0, iframe code that no platform claimed reached `fallback`. It now re
85
85
 
86
86
  Each platform component takes a `url`, or an `embed` already parsed by [`social-embeds/parser`](#parser), plus the shared props and its own option props. Option props override options from the embed code.
87
87
 
88
+ A platform component bundles only its own platform's parser: one component adds about 6 KB gzipped to an app, against about 27 KB for `<SocialEmbed>`, which recognises every platform. A URL of another platform is reported as `social-embeds: not a {Platform} post URL: …`.
89
+
88
90
  ```tsx
89
91
  import {
90
92
  AppleMusicEmbed,
@@ -309,11 +311,13 @@ A component checks an `embed` before using it: its `url` must be the exact URL `
309
311
 
310
312
  Script-based embeds try to render three times, waiting 15 s each time, 1 s and then 2 s apart, before `onError` reports the failure. Iframe embeds get 15 s, counted from when the embed comes near the viewport, also with `lazy={false}`. Telegram, Reddit, Bluesky, Tumblr, Truth Social, Imgur and Strava frames that report no height by then show at their starting height; other frames that have not loaded by then show as they are, such as a frame the browser blocked. `onError` reports both, and a frame that loads or reports its height later still calls `onLoad`.
311
313
 
314
+ When a script-based embed fails for good, its placeholder goes, as an iframe's does: a URL leaves a "View this post on {Platform}" link to the post, and embed code keeps its fallback content. A platform `<script>` tag already in the page whose platform never appears, such as one written through `innerHTML` or `dangerouslySetInnerHTML` (those never run), holds an embed back for at most 3 s after the page's `load` event; the package then adds its own tag.
315
+
312
316
  ## Platforms
313
317
 
314
318
  | Platform | Mechanism | URL formats | Options read from embed code | Default `maxWidth` |
315
319
  | -------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
316
- | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, `twitter.com/…` (also `www.` and `mobile.`) | `data-theme`, `data-conversation`, `data-cards`, `data-align` or `align`, `data-lang`, `data-dnt`, `data-width` | 550 |
320
+ | X | script (`widgets.js`), `twttr.widgets.load` | `x.com/{user}/status/{id}`, also with `/photo/{n}` or `/video/{n}`, `x.com/i/web/status/{id}`, `twitter.com/…` (also `www.` and `mobile.`) | `data-theme`, `data-conversation`, `data-cards`, `data-align` or `align`, `data-lang`, `data-dnt`, `data-width` | 550 |
317
321
  | Instagram | script (`embed.js`), `instgrm.Embeds.process` | `instagram.com/p/{code}/`, `/reel/`, `/reels/`, `/tv/`, `/{user}/p/{code}/`, `/{user}/reel/{code}/` | `data-instgrm-captioned`, `data-instgrm-version` | 540 |
318
322
  | Threads | script (`embed.js`), `instgrm.Embeds.process` | `threads.com/@{user}/post/{code}`, `threads.com/t/{code}` (and `threads.net`) | `data-theme`, `data-text-post-version` | 658 |
319
323
  | Facebook | posts and video URLs: SDK (`sdk.js`), `FB.XFBML.parse`; video embed code: iframe | see [Facebook](#facebook) | `data-width`, `data-show-text`, `data-lazy`, `data-allowfullscreen`, `data-autoplay`, `data-show-captions`; iframe query (`show_text`, `width`, …); SDK locale | posts 750, videos none |
@@ -334,16 +338,16 @@ Script-based embeds try to render three times, waiting 15 s each time, 1 s and t
334
338
  | Apple Podcasts | iframe (`embed.podcasts.apple.com`), fixed height | `podcasts.apple.com/{country}/podcast/{slug}/id{id}`, an episode with `?i={id}` | `width`, `height` | 640 |
335
339
  | Tumblr | iframe (`embed.tumblr.com/embed/post/…`), height from the frame; `post.js` is not loaded | `www.tumblr.com/{blog}/{id}`, `{blog}.tumblr.com/post/{id}`, with or without the slug | none | 540 |
336
340
  | Kick | iframe (`player.kick.com/{channel}`) | `kick.com/{channel}` | `autoplay`, `muted`, `width`, `height` | none |
337
- | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/gifs/{id}`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/giphy.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
341
+ | Giphy | iframe (`giphy.com/embed/{id}`) | `giphy.com/gifs/{slug}-{id}`, `giphy.com/stickers/…`, `giphy.com/embed/{id}`, `media.giphy.com/media/{id}/{file}` (also after a `v1.…` segment), `i.giphy.com/{id}.gif` | `width` and `height`, or the responsive wrapper's ratio | none |
338
342
  | Truth Social | iframe (`truthsocial.com/@{user}/{id}/embed`), height from the frame; `embed.js` is not loaded | `truthsocial.com/@{user}/posts/{id}`, `truthsocial.com/@{user}/{id}` | `video`, set from the iframe's `truthsocial-video` class, not a prop | 600 |
339
343
  | Imgur | iframe (`imgur.com/{id}/embed?pub=true`), height from the frame; `embed.js` is not loaded | `imgur.com/{id}`, `imgur.com/a/{id}`, `imgur.com/gallery/{id}` and `…/gallery/{slug}-{id}`, `i.imgur.com/{id}.{ext}` | `data-context`, `data-analytics` | 540 |
340
344
  | Tenor | iframe (`tenor.com/embed/{id}`); `embed.js` is not loaded | `tenor.com/view/{slug}-gif-{id}`, with an optional locale (`tenor.com/en-GB/view/…`) | none; the ratio from `data-aspect-ratio`, or the iframe's `width` and `height` | none |
341
- | Streamable | iframe (`streamable.com/e/{id}`) | `streamable.com/{id}`, `streamable.com/e/{id}`, `streamable.com/o/{id}` | `loop`, `autoplay`, `nocontrols`, `hd`, `muted`; the ratio from the wrapper or the iframe | none |
345
+ | Streamable | iframe (`streamable.com/e/{id}`) | `streamable.com/{id}` (also with a trailing `/`), `streamable.com/e/{id}`, `streamable.com/o/{id}` | `loop`, `autoplay`, `nocontrols`, `hd`, `muted`; the ratio from the wrapper or the iframe | none |
342
346
  | Strava | iframe (`strava-embeds.com/{type}/{id}`), height from the frame; `embed.js` is not loaded | `www.strava.com/activities/{id}`, `www.strava.com/routes/{id}` | `data-style`, `data-full-width` (routes), `data-map-hash` | 554 (none for a full-width route) |
343
347
  | Flickr | iframe (`embedr.flickr.com/photos/{id}`), built on the client at the box's width; `client-code.js` is not loaded | `flickr.com/photos/{user}/{id}` (with or without `/in/…`), `…/photos/{user}/albums/{id}`, `flic.kr/p/{code}` | `data-header`, `data-footer`, `data-context`; the image's `width` and `height` | the image's width (none for a URL) |
344
348
  | Rumble | iframe (`rumble.com/embed/{id}/`) | `rumble.com/embed/{id}/` only: see [Rumble](#rumble) | `pub`, `width`, `height` | none |
345
349
 
346
- URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.`.
350
+ URLs must be absolute `http(s)` URLs. Hosts may have `www.`; YouTube also `m.`, Facebook also `m.` and `web.`.
347
351
 
348
352
  ### X
349
353
 
@@ -552,12 +556,12 @@ embed && <GenericIframeEmbed embed={embed} />;
552
556
 
553
557
  ## Without React
554
558
 
555
- `social-embeds/element` defines `<social-embed>`, a custom element for plain HTML, CMS templates, Vue, Svelte and Angular. It is one self-contained file with no React in it, about 25 KB gzipped.
559
+ `social-embeds/element` defines `<social-embed>`, a custom element for plain HTML, CMS templates, Vue, Svelte and Angular. It is one self-contained file with no React in it, about 26 KB gzipped.
556
560
 
557
561
  ```html
558
562
  <script
559
563
  type="module"
560
- src="https://cdn.jsdelivr.net/npm/social-embeds@0.6.0/dist/element.js"
564
+ src="https://cdn.jsdelivr.net/npm/social-embeds@0.8.0/dist/element.js"
561
565
  integrity="sha384-…"
562
566
  crossorigin="anonymous"
563
567
  ></script>
@@ -579,6 +583,7 @@ Embed code goes in a `<template>`, which keeps the platform's own `<script>` fro
579
583
 
580
584
  | Attribute / property | Meaning |
581
585
  | -------------------------- | ------------------------------------------------------------------------------- |
586
+ | `html` | Embed code. Usually set as a property (below). |
582
587
  | `url` | A post URL. |
583
588
  | `width` | A number means pixels; otherwise any CSS length. |
584
589
  | `max-width` / `maxWidth` | Pixels: `400` or `400px`. |
@@ -588,9 +593,9 @@ Embed code goes in a `<template>`, which keeps the platform's own `<script>` fro
588
593
 
589
594
  Each property reflects its attribute, so framework property bindings such as Angular's `[url]` work. `url` and the size properties take a string, and `null` removes the attribute; `eager` takes a boolean.
590
595
 
591
- The `html` property takes embed code from script. From a framework, pass embed code this way: a `<template>` the framework renders keeps its children in `childNodes`, not in `content`, where the element reads them. When several inputs are set, `html` wins over the `<template>`, and the `<template>` wins over `url`. Options come only from the embed code, as with `<SocialEmbed>`, and the element renders into the light DOM. The element has no `playerId`, so Dailymotion needs embed code that names a Player ID; a Dailymotion URL alone fires `error`.
596
+ The `html` property takes embed code from script. From a framework, pass embed code this way: a `<template>` the framework renders keeps its children in `childNodes`, not in `content`, where the element reads them. Before the tag is defined, React 19, Vue and Svelte write `html` as an attribute, and server HTML can carry it that way too; the element reads that attribute. When several inputs are set, the `html` property wins over the `html` attribute, which wins over the `<template>`, which wins over `url`. Options come only from the embed code, as with `<SocialEmbed>`, and the element renders into the light DOM. The element has no `playerId`, so Dailymotion needs embed code that names a Player ID; a Dailymotion URL alone fires `error`.
592
597
 
593
- Child elements other than `<template>` are the placeholder until the embed loads; without any, a neutral skeleton shows. They are read once, when the element first connects; children added later are not a placeholder. If the element connects while the document is still loading, it waits for `DOMContentLoaded` before reading its children.
598
+ The element's own children other than `<template>` are never rendered and never moved, so a framework that renders children into it keeps owning them. Copies of them, taken each time the embed starts, are the placeholder until it loads; without any, a neutral skeleton shows. The embed renders into a `<div slot="embed">` in the light DOM, which a shadow root holding only that slot shows; the `embed` slot name is the element's own. If other code removes that `<div>`, for example a framework setting a text child or a DOM morph, the embed starts again. If the element connects while the document is still loading, it waits for `DOMContentLoaded` before reading its children.
594
599
 
595
600
  It dispatches `load` (an `Event`) when the platform has rendered, and `error` (an `ErrorEvent`) when it cannot. `error.error` is an `Error` with the same message as React's `onError`. Neither event bubbles, both fire in a microtask, and only while the element is connected.
596
601
 
@@ -0,0 +1,7 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type AppleMusicEmbedProps = EmbedSource & FrameProps;
3
+ export type ApplePodcastsEmbedProps = EmbedSource & FrameProps;
4
+ /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
5
+ export declare function AppleMusicEmbed(props: AppleMusicEmbedProps): import("react").JSX.Element | null;
6
+ /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
7
+ export declare function ApplePodcastsEmbed(props: ApplePodcastsEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,39 @@
1
+ import { appleMusicPlan, applePodcastsPlan } from "../core/plans/apple.js";
2
+ import { applemusic } from "../parser/platforms/applemusic.js";
3
+ import { applepodcasts } from "../parser/platforms/applepodcasts.js";
4
+ import { useReportError } from "./hooks.js";
5
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
6
+ import { resolveEmbed } from "../core/resolve.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // src/components/apple-embed.tsx
9
+ /** A fixed height: the `height` prop, else the embed code's, else 175px for a song and 450px for the rest. */
10
+ function AppleMusicEmbed(props) {
11
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
12
+ const { embed, error } = resolveEmbed(url, given, applemusic);
13
+ const plan = embed ? appleMusicPlan(embed) : void 0;
14
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
15
+ if (plan?.kind !== "iframe") return null;
16
+ return /* @__PURE__ */ jsx(IframeEmbed, {
17
+ ...frame,
18
+ ...planProps(plan),
19
+ onError,
20
+ maxWidth: maxWidth ?? plan.maxWidth,
21
+ height: height ?? plan.height
22
+ });
23
+ }
24
+ /** A fixed height: the `height` prop, else the embed code's, else 160px for an episode and 450px for a show. */
25
+ function ApplePodcastsEmbed(props) {
26
+ const { url, embed: given, onError, height, maxWidth, ...frame } = props;
27
+ const { embed, error } = resolveEmbed(url, given, applepodcasts);
28
+ const plan = embed ? applePodcastsPlan(embed) : void 0;
29
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
30
+ if (plan?.kind !== "iframe") return null;
31
+ return /* @__PURE__ */ jsx(IframeEmbed, {
32
+ ...frame,
33
+ ...planProps(plan),
34
+ onError,
35
+ maxWidth: maxWidth ?? plan.maxWidth,
36
+ height: height ?? plan.height
37
+ });
38
+ }
39
+ export { AppleMusicEmbed, ApplePodcastsEmbed };
@@ -0,0 +1,10 @@
1
+ import { BlueskyOptions } from "../core/plans/bluesky.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type BlueskyEmbedProps = EmbedSource & Omit<SharedProps, keyof BlueskyOptions> & BlueskyOptions;
4
+ /**
5
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
6
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
7
+ * render: a handle URL needs a lookup, and `onError` says so.
8
+ */
9
+ export declare function BlueskyEmbed(props: BlueskyEmbedProps): import("react").JSX.Element | null;
10
+ export type { BlueskyOptions };
@@ -0,0 +1,27 @@
1
+ import { blueskyPlan } from "../core/plans/bluesky.js";
2
+ import { bluesky } from "../parser/platforms/bluesky.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, fallbackPlaceholder, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/bluesky-embed.tsx
8
+ /**
9
+ * At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
10
+ * create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
11
+ * render: a handle URL needs a lookup, and `onError` says so.
12
+ */
13
+ function BlueskyEmbed(props) {
14
+ const { url, embed: given, onError, maxWidth, colorMode, placeholder, ...shared } = props;
15
+ const { embed, error } = resolveEmbed(url, given, bluesky);
16
+ const plan = embed ? blueskyPlan(embed, { colorMode }) : void 0;
17
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
18
+ if (plan?.kind !== "iframe") return null;
19
+ return /* @__PURE__ */ jsx(IframeEmbed, {
20
+ ...shared,
21
+ ...planProps(plan),
22
+ onError,
23
+ maxWidth: maxWidth ?? plan.maxWidth,
24
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
25
+ });
26
+ }
27
+ export { BlueskyEmbed };
@@ -0,0 +1,9 @@
1
+ import { DailymotionOptions } from "../core/plans/dailymotion.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type DailymotionEmbedProps = EmbedSource & Omit<FrameProps, keyof DailymotionOptions> & DailymotionOptions;
4
+ /**
5
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
6
+ * prop, never another account's (docs/decisions.md D63).
7
+ */
8
+ export declare function DailymotionEmbed(props: DailymotionEmbedProps): import("react").JSX.Element | null;
9
+ export type { DailymotionOptions };
@@ -0,0 +1,30 @@
1
+ import { dailymotion } from "../parser/platforms/dailymotion.js";
2
+ import { dailymotionPlan } from "../core/plans/dailymotion.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/dailymotion-embed.tsx
8
+ /**
9
+ * Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
10
+ * prop, never another account's (docs/decisions.md D63).
11
+ */
12
+ function DailymotionEmbed(props) {
13
+ const { url, embed: given, onError, maxWidth, playerId, mute, startTime, loop, ...frame } = props;
14
+ const { embed, error } = resolveEmbed(url, given, dailymotion);
15
+ const plan = embed ? dailymotionPlan(embed, {
16
+ playerId,
17
+ mute,
18
+ startTime,
19
+ loop
20
+ }) : void 0;
21
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
22
+ if (plan?.kind !== "iframe") return null;
23
+ return /* @__PURE__ */ jsx(IframeEmbed, {
24
+ ...frame,
25
+ ...planProps(plan),
26
+ onError,
27
+ maxWidth: maxWidth ?? plan.maxWidth
28
+ });
29
+ }
30
+ export { DailymotionEmbed };
@@ -0,0 +1,6 @@
1
+ import { FacebookOptions } from "../core/plans/facebook.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ /** `height` and `maxHeight` apply only to a video that renders as an iframe. */
4
+ export type FacebookEmbedProps = EmbedSource & Omit<FrameProps, keyof FacebookOptions> & FacebookOptions;
5
+ export declare function FacebookEmbed(props: FacebookEmbedProps): import("react").JSX.Element | null;
6
+ export type { FacebookOptions };
@@ -0,0 +1,40 @@
1
+ import { facebookPlan } from "../core/plans/facebook.js";
2
+ import { facebook } from "../parser/platforms/facebook.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { ScriptEmbed } from "./script-embed.js";
6
+ import { resolveEmbed } from "../core/resolve.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // src/components/facebook-embed.tsx
9
+ function FacebookEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, locale, showText, allowfullscreen, autoplay, showCaptions, height, maxHeight, ...shared } = props;
11
+ const { embed, error } = resolveEmbed(url, given, facebook);
12
+ const plan = embed ? facebookPlan(embed, {
13
+ locale,
14
+ showText,
15
+ allowfullscreen,
16
+ autoplay,
17
+ showCaptions
18
+ }) : void 0;
19
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
20
+ if (plan?.kind === "iframe") return /* @__PURE__ */ jsx(IframeEmbed, {
21
+ ...shared,
22
+ ...planProps(plan),
23
+ onError,
24
+ maxWidth: maxWidth ?? plan.maxWidth,
25
+ height,
26
+ maxHeight
27
+ });
28
+ if (plan?.kind !== "script") return null;
29
+ return /* @__PURE__ */ jsx(ScriptEmbed, {
30
+ ...shared,
31
+ onError,
32
+ maxWidth: maxWidth ?? plan.maxWidth,
33
+ driver: plan.driver,
34
+ markup: plan.markup,
35
+ hasFallback: plan.hasFallback,
36
+ minHeight: plan.minHeight,
37
+ label: plan.label
38
+ }, plan.key);
39
+ }
40
+ export { FacebookEmbed };
@@ -0,0 +1,6 @@
1
+ import { FlickrOptions } from "../core/plans/flickr.js";
2
+ import { EmbedSource, FrameProps } from "./shared.js";
3
+ export type FlickrEmbedProps = EmbedSource & Omit<FrameProps, keyof FlickrOptions> & FlickrOptions;
4
+ /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
5
+ export declare function FlickrEmbed(props: FlickrEmbedProps): import("react").JSX.Element | null;
6
+ export type { FlickrOptions };
@@ -0,0 +1,27 @@
1
+ import { flickrPlan } from "../core/plans/flickr.js";
2
+ import { flickr } from "../parser/platforms/flickr.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, fallbackPlaceholder, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/flickr-embed.tsx
8
+ /** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
9
+ function FlickrEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, header, footer, context, placeholder, ...frame } = props;
11
+ const { embed, error } = resolveEmbed(url, given, flickr);
12
+ const plan = embed ? flickrPlan(embed, {
13
+ header,
14
+ footer,
15
+ context
16
+ }) : void 0;
17
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
18
+ if (plan?.kind !== "iframe") return null;
19
+ return /* @__PURE__ */ jsx(IframeEmbed, {
20
+ ...frame,
21
+ ...planProps(plan),
22
+ onError,
23
+ maxWidth: maxWidth ?? plan.maxWidth,
24
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
25
+ });
26
+ }
27
+ export { FlickrEmbed };
@@ -0,0 +1,11 @@
1
+ import { ParsedIframe } from "../parser/iframe.js";
2
+ import { FrameProps } from "./shared.js";
3
+ export type GenericIframeEmbedProps = ({
4
+ html: string;
5
+ embed?: never;
6
+ } | {
7
+ embed: ParsedIframe;
8
+ html?: never;
9
+ }) & FrameProps;
10
+ /** One iframe rebuilt from its checked attributes; nothing else in the code renders. */
11
+ export declare function GenericIframeEmbed(props: GenericIframeEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,26 @@
1
+ import { genericPlan } from "../core/plans/generic.js";
2
+ import { parseIframe } from "../parser/iframe.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { useMemo } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/generic-iframe-embed.tsx
8
+ /** One iframe rebuilt from its checked attributes; nothing else in the code renders. */
9
+ function GenericIframeEmbed(props) {
10
+ const { html, embed: given, onError, maxWidth, height, ...frame } = props;
11
+ const embed = useMemo(() => given ?? parseIframe(html), [given, html]);
12
+ const plan = embed ? genericPlan(embed) : {
13
+ kind: "error",
14
+ message: "social-embeds: not an iframe embed code"
15
+ };
16
+ useReportError(plan.kind === "error" ? plan.message : void 0, onError);
17
+ if (plan.kind !== "iframe") return null;
18
+ return /* @__PURE__ */ jsx(IframeEmbed, {
19
+ ...frame,
20
+ ...planProps(plan),
21
+ onError,
22
+ maxWidth: maxWidth ?? plan.maxWidth,
23
+ height: height ?? plan.height
24
+ });
25
+ }
26
+ export { GenericIframeEmbed };
@@ -0,0 +1,4 @@
1
+ import { EmbedSource, FrameProps } from "./shared.js";
2
+ export type GiphyEmbedProps = EmbedSource & FrameProps;
3
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
4
+ export declare function GiphyEmbed(props: GiphyEmbedProps): import("react").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ import { giphyPlan } from "../core/plans/giphy.js";
2
+ import { giphy } from "../parser/platforms/giphy.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/giphy-embed.tsx
8
+ /** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
9
+ function GiphyEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, ...frame } = props;
11
+ const { embed, error } = resolveEmbed(url, given, giphy);
12
+ const plan = embed ? giphyPlan(embed) : void 0;
13
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
+ if (plan?.kind !== "iframe") return null;
15
+ return /* @__PURE__ */ jsx(IframeEmbed, {
16
+ ...frame,
17
+ ...planProps(plan),
18
+ onError,
19
+ maxWidth: maxWidth ?? plan.maxWidth
20
+ });
21
+ }
22
+ export { GiphyEmbed };
@@ -0,0 +1,36 @@
1
+ import { ROOT_MARGIN } from "../core/timing.js";
2
+ import { useEffect, useRef, useState } from "react";
3
+ // src/components/hooks.ts
4
+ /** False on the server and in the first client render, so the markup matches on hydration. */
5
+ function useNearViewport(ref, lazy) {
6
+ const [near, setNear] = useState(false);
7
+ useEffect(() => {
8
+ const element = ref.current;
9
+ if (!lazy || !element || typeof IntersectionObserver === "undefined") {
10
+ setNear(true);
11
+ return;
12
+ }
13
+ const observer = new IntersectionObserver((entries) => {
14
+ if (entries.some((entry) => entry.isIntersecting)) {
15
+ setNear(true);
16
+ observer.disconnect();
17
+ }
18
+ }, { rootMargin: ROOT_MARGIN });
19
+ observer.observe(element);
20
+ return () => {
21
+ observer.disconnect();
22
+ };
23
+ }, [ref, lazy]);
24
+ return near;
25
+ }
26
+ /** Calls `onError` from an effect, once per distinct message. */
27
+ function useReportError(message, onError) {
28
+ const latest = useRef(onError);
29
+ useEffect(() => {
30
+ latest.current = onError;
31
+ });
32
+ useEffect(() => {
33
+ if (message !== void 0) latest.current?.(new Error(message));
34
+ }, [message]);
35
+ }
36
+ export { useNearViewport, useReportError };
@@ -0,0 +1,169 @@
1
+ import { FRAME_TIMEOUT_MS } from "../core/timing.js";
2
+ import { frameStyle, srcWithSize, watchWidth } from "../core/layout.js";
3
+ import { useNearViewport } from "./hooks.js";
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ // src/components/iframe-embed.tsx
7
+ /** The plan's fields as `IframeEmbed` props. */
8
+ function planProps(plan) {
9
+ const { kind, fallbackHtml, fallbackImage, ...props } = plan;
10
+ return props;
11
+ }
12
+ /** The plan's verified fallback content as the placeholder, if it has any. */
13
+ function fallbackPlaceholder(plan) {
14
+ const { fallbackHtml, fallbackImage } = plan;
15
+ if (fallbackHtml === void 0) return void 0;
16
+ return fallbackImage ? /* @__PURE__ */ jsx("div", {
17
+ style: { height: "100%" },
18
+ dangerouslySetInnerHTML: { __html: fallbackHtml }
19
+ }) : /* @__PURE__ */ jsx("blockquote", { dangerouslySetInnerHTML: { __html: fallbackHtml } });
20
+ }
21
+ const FILL = {
22
+ position: "absolute",
23
+ inset: 0
24
+ };
25
+ function IframeEmbed(props) {
26
+ return /* @__PURE__ */ jsx(Frame, { ...props }, props.src);
27
+ }
28
+ function Frame({ src, title, allow, allowFullscreen = true, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, borderRadius, sizeInSrc, width, maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
29
+ const frame = useRef(null);
30
+ const iframe = useRef(null);
31
+ const near = useNearViewport(frame, lazy);
32
+ const inView = useNearViewport(frame, !lazy);
33
+ const [loaded, setLoaded] = useState(false);
34
+ const [reportedHeight, setReportedHeight] = useState();
35
+ const [boxWidth, setBoxWidth] = useState();
36
+ const reported = useRef(false);
37
+ const callbacks = useRef({
38
+ onLoad,
39
+ onError
40
+ });
41
+ useEffect(() => {
42
+ callbacks.current = {
43
+ onLoad,
44
+ onError
45
+ };
46
+ });
47
+ const report = useCallback(() => {
48
+ setLoaded(true);
49
+ if (reported.current) return;
50
+ reported.current = true;
51
+ callbacks.current.onLoad?.();
52
+ }, []);
53
+ useEffect(() => {
54
+ if (!near || !messageHeight) return;
55
+ const { origin, read } = messageHeight;
56
+ const listen = (event) => {
57
+ if (event.origin !== origin) return;
58
+ if (!iframe.current || event.source !== iframe.current.contentWindow) return;
59
+ let value;
60
+ try {
61
+ value = read(event.data);
62
+ } catch {
63
+ return;
64
+ }
65
+ if (typeof value !== "number" || !(value > 0 && value <= 5e4)) return;
66
+ setReportedHeight(Math.ceil(value));
67
+ report();
68
+ };
69
+ window.addEventListener("message", listen);
70
+ return () => {
71
+ window.removeEventListener("message", listen);
72
+ };
73
+ }, [
74
+ near,
75
+ messageHeight,
76
+ report
77
+ ]);
78
+ useEffect(() => {
79
+ const element = frame.current;
80
+ if (!near || !sizeInSrc || !element) return;
81
+ return watchWidth(element, setBoxWidth);
82
+ }, [near, sizeInSrc]);
83
+ useEffect(() => {
84
+ if (!near || !inView) return;
85
+ const failure = messageHeight ? "did not report its height" : "did not load";
86
+ const timer = setTimeout(() => {
87
+ if (reported.current) return;
88
+ setLoaded(true);
89
+ callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} ${failure}`));
90
+ }, FRAME_TIMEOUT_MS);
91
+ return () => {
92
+ clearTimeout(timer);
93
+ };
94
+ }, [
95
+ near,
96
+ inView,
97
+ messageHeight,
98
+ title
99
+ ]);
100
+ const wrapper = {
101
+ ...frameStyle({
102
+ kind: "iframe",
103
+ src,
104
+ title,
105
+ allow,
106
+ ratio,
107
+ size,
108
+ messageHeight,
109
+ startHeight,
110
+ borderRadius
111
+ }, {
112
+ width,
113
+ maxWidth,
114
+ height,
115
+ maxHeight
116
+ }, reportedHeight),
117
+ ...style
118
+ };
119
+ const frameSrc = !sizeInSrc ? src : boxWidth === void 0 ? void 0 : srcWithSize({
120
+ src,
121
+ ratio,
122
+ size
123
+ }, boxWidth);
124
+ return /* @__PURE__ */ jsx("div", {
125
+ ...rest,
126
+ style: wrapper,
127
+ children: /* @__PURE__ */ jsxs("div", {
128
+ ref: frame,
129
+ style: FILL,
130
+ children: [near && frameSrc !== void 0 && /* @__PURE__ */ jsx("iframe", {
131
+ ref: iframe,
132
+ src: hostParam ? withHost(frameSrc, hostParam) : frameSrc,
133
+ title,
134
+ allow,
135
+ allowFullScreen: allowFullscreen,
136
+ referrerPolicy,
137
+ scrolling,
138
+ sandbox,
139
+ style: {
140
+ display: "block",
141
+ width: "100%",
142
+ height: "100%",
143
+ border: 0
144
+ },
145
+ onLoad: () => {
146
+ if (!messageHeight) report();
147
+ }
148
+ }, sizeInSrc ? frameSrc : void 0), !loaded && /* @__PURE__ */ jsx("div", {
149
+ style: FILL,
150
+ children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
151
+ })]
152
+ })
153
+ });
154
+ }
155
+ function withHost(src, name) {
156
+ return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
157
+ }
158
+ function Skeleton({ minHeight }) {
159
+ return /* @__PURE__ */ jsx("div", {
160
+ "aria-hidden": "true",
161
+ style: {
162
+ width: "100%",
163
+ height: "100%",
164
+ minHeight,
165
+ background: "rgba(128, 128, 128, 0.12)"
166
+ }
167
+ });
168
+ }
169
+ export { IframeEmbed, Skeleton, fallbackPlaceholder, planProps };
@@ -0,0 +1,6 @@
1
+ import { ImgurOptions } from "../core/plans/imgur.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type ImgurEmbedProps = EmbedSource & Omit<SharedProps, keyof ImgurOptions> & ImgurOptions;
4
+ /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
5
+ export declare function ImgurEmbed(props: ImgurEmbedProps): import("react").JSX.Element | null;
6
+ export type { ImgurOptions };
@@ -0,0 +1,23 @@
1
+ import { imgurPlan } from "../core/plans/imgur.js";
2
+ import { imgur } from "../parser/platforms/imgur.js";
3
+ import { useReportError } from "./hooks.js";
4
+ import { IframeEmbed, fallbackPlaceholder, planProps } from "./iframe-embed.js";
5
+ import { resolveEmbed } from "../core/resolve.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/imgur-embed.tsx
8
+ /** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
9
+ function ImgurEmbed(props) {
10
+ const { url, embed: given, onError, maxWidth, context, placeholder, ...shared } = props;
11
+ const { embed, error } = resolveEmbed(url, given, imgur);
12
+ const plan = embed ? imgurPlan(embed, { context }) : void 0;
13
+ useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
14
+ if (plan?.kind !== "iframe") return null;
15
+ return /* @__PURE__ */ jsx(IframeEmbed, {
16
+ ...shared,
17
+ ...planProps(plan),
18
+ onError,
19
+ maxWidth: maxWidth ?? plan.maxWidth,
20
+ placeholder: placeholder ?? fallbackPlaceholder(plan)
21
+ });
22
+ }
23
+ export { ImgurEmbed };
@@ -0,0 +1,5 @@
1
+ import { InstagramOptions } from "../core/plans/instagram.js";
2
+ import { EmbedSource, SharedProps } from "./shared.js";
3
+ export type InstagramEmbedProps = EmbedSource & Omit<SharedProps, keyof InstagramOptions> & InstagramOptions;
4
+ export declare function InstagramEmbed(props: InstagramEmbedProps): import("react").JSX.Element | null;
5
+ export type { InstagramOptions };