social-embeds 0.7.0 → 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 +14 -9
  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
@@ -0,0 +1,46 @@
1
+ import { query } from "../params.js";
2
+ // src/core/plans/reddit.ts
3
+ const PARAMS = {
4
+ theme: "theme",
5
+ showMedia: "showmedia",
6
+ showTitle: "showtitle",
7
+ showUsername: "showusername",
8
+ locale: "locale",
9
+ depth: "depth"
10
+ };
11
+ const SANDBOX = "allow-scripts allow-same-origin allow-popups";
12
+ const ALLOW = "clipboard-read; clipboard-write";
13
+ const START_HEIGHT = 316;
14
+ /** docs/decisions.md D52. */
15
+ const REDDIT_HEIGHT = {
16
+ origin: "https://embed.reddit.com",
17
+ read(data) {
18
+ if (typeof data !== "string") return void 0;
19
+ const message = JSON.parse(data);
20
+ return message.type === "resize.embed" && typeof message.data === "number" ? message.data : void 0;
21
+ }
22
+ };
23
+ /** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
24
+ function redditPlan(embed, options) {
25
+ const fromProps = [];
26
+ for (const [prop, name] of Object.entries(PARAMS)) {
27
+ const value = options[prop];
28
+ if (value !== void 0) fromProps.push([name, value]);
29
+ }
30
+ return {
31
+ kind: "iframe",
32
+ src: `https://embed.reddit.com${embed.url.slice(22)}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
33
+ title: "Reddit post",
34
+ allow: ALLOW,
35
+ sandbox: SANDBOX,
36
+ scrolling: "no",
37
+ ratio: {
38
+ width: 1,
39
+ height: 1
40
+ },
41
+ messageHeight: REDDIT_HEIGHT,
42
+ startHeight: embed.size?.height ?? START_HEIGHT,
43
+ maxWidth: 640
44
+ };
45
+ }
46
+ export { redditPlan };
@@ -0,0 +1,21 @@
1
+ import { optionsWithout, query } from "../params.js";
2
+ // src/core/plans/rumble.ts
3
+ /**
4
+ * Rumble documents no player parameters (docs/decisions.md D99), so there are no options.
5
+ * The embed code's `pub` is kept as given and never added.
6
+ */
7
+ function rumblePlan(embed) {
8
+ const pub = optionsWithout(embed.options, []).filter(([key]) => key === "pub");
9
+ return {
10
+ kind: "iframe",
11
+ src: `https://rumble.com/embed/${embed.id}/${query(pub)}`,
12
+ title: "Rumble video",
13
+ allow: "fullscreen",
14
+ ratio: {
15
+ width: 16,
16
+ height: 9
17
+ },
18
+ size: embed.size
19
+ };
20
+ }
21
+ export { rumblePlan };
@@ -0,0 +1,20 @@
1
+ // src/core/plans/snapchat.ts
2
+ const ALLOW = "autoplay; camera; microphone; clipboard-write;";
3
+ /** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
4
+ function snapchatPlan(embed) {
5
+ const title = embed.options.title;
6
+ return {
7
+ kind: "iframe",
8
+ src: `${embed.url}/embed`,
9
+ title: typeof title === "string" && title !== "" ? title : "Snapchat",
10
+ allow: ALLOW,
11
+ scrolling: "no",
12
+ ratio: {
13
+ width: 416,
14
+ height: 692
15
+ },
16
+ size: embed.size,
17
+ maxWidth: 416
18
+ };
19
+ }
20
+ export { snapchatPlan };
@@ -0,0 +1,14 @@
1
+ /** SoundCloud's player parameters, in camelCase. */
2
+ export type SoundCloudOptions = {
3
+ /** The large-artwork player; `false` for the classic one. */
4
+ visual?: boolean;
5
+ /** Accent colour, such as `'#ff5500'`. */
6
+ color?: string;
7
+ autoPlay?: boolean;
8
+ hideRelated?: boolean;
9
+ showComments?: boolean;
10
+ showUser?: boolean;
11
+ showReposts?: boolean;
12
+ showTeaser?: boolean;
13
+ showArtwork?: boolean;
14
+ };
@@ -0,0 +1,37 @@
1
+ import { optionsWithout, query } from "../params.js";
2
+ // src/core/plans/soundcloud.ts
3
+ const PARAMS = {
4
+ visual: "visual",
5
+ color: "color",
6
+ autoPlay: "auto_play",
7
+ hideRelated: "hide_related",
8
+ showComments: "show_comments",
9
+ showUser: "show_user",
10
+ showReposts: "show_reposts",
11
+ showTeaser: "show_teaser",
12
+ showArtwork: "show_artwork"
13
+ };
14
+ const ALLOW = "autoplay; encrypted-media";
15
+ const URL_HEIGHT = 400;
16
+ /** A fixed height: the embed code's, else 400px for the visual player. */
17
+ function soundcloudPlan(embed, options) {
18
+ const fromOptions = [];
19
+ for (const [option, name] of Object.entries(PARAMS)) {
20
+ const value = options[option];
21
+ if (value !== void 0) fromOptions.push([name, value]);
22
+ }
23
+ const fromUrl = embed.size === void 0;
24
+ return {
25
+ kind: "iframe",
26
+ src: `https://w.soundcloud.com/player/${query([["url", embed.url]], fromUrl ? [["visual", true]] : void 0, optionsWithout(embed.options, ["url", "secret_token"]), fromOptions)}`,
27
+ title: "SoundCloud player",
28
+ allow: ALLOW,
29
+ scrolling: "no",
30
+ ratio: {
31
+ width: 16,
32
+ height: 9
33
+ },
34
+ height: embed.size?.height ?? URL_HEIGHT
35
+ };
36
+ }
37
+ export { soundcloudPlan };
@@ -0,0 +1,4 @@
1
+ export type SpotifyOptions = {
2
+ /** `0` for the dark player. */
3
+ theme?: 0;
4
+ };
@@ -0,0 +1,29 @@
1
+ import { query } from "../params.js";
2
+ // src/core/plans/spotify.ts
3
+ const ALLOW = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
4
+ const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
5
+ const COMPACT_HEIGHT = 152;
6
+ const FULL_HEIGHT = 352;
7
+ /**
8
+ * A fixed height: the embed code's, else 152px for a track or episode and 352px for the rest.
9
+ * A video show keeps its 16:9 aspect ratio instead.
10
+ */
11
+ function spotifyPlan(embed, options) {
12
+ const type = new URL(embed.url).pathname.split("/")[1] ?? "";
13
+ const video = embed.kind === "video";
14
+ const params = query(Object.entries(embed.options), options.theme === void 0 ? void 0 : [["theme", options.theme]]);
15
+ return {
16
+ kind: "iframe",
17
+ src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
18
+ title: "Spotify Embed",
19
+ allow: ALLOW,
20
+ ratio: {
21
+ width: 16,
22
+ height: 9
23
+ },
24
+ size: video ? embed.size : void 0,
25
+ borderRadius: 12,
26
+ height: video ? void 0 : embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT)
27
+ };
28
+ }
29
+ export { spotifyPlan };
@@ -0,0 +1,8 @@
1
+ /** The display options of Strava's embed code (docs/decisions.md D97). */
2
+ export type StravaOptions = {
3
+ /** The embed's `data-style`. */
4
+ embedStyle?: 'standard' | 'minimal';
5
+ /** Routes only: the frame fills its container, with no maximum width. */
6
+ fullWidth?: boolean;
7
+ mapHash?: string;
8
+ };
@@ -0,0 +1,38 @@
1
+ // src/core/plans/strava.ts
2
+ const NS = "social-embeds";
3
+ /** The frame posts `[ns, 'BROADCAST_IFRAME_HEIGHT', height]` once, unasked (docs/decisions.md D97). */
4
+ const STRAVA_HEIGHT = {
5
+ origin: "https://strava-embeds.com",
6
+ read(data) {
7
+ if (!Array.isArray(data)) return void 0;
8
+ const [, type, height] = data;
9
+ return type === "BROADCAST_IFRAME_HEIGHT" && typeof height === "number" ? height : void 0;
10
+ }
11
+ };
12
+ function styleOf(value) {
13
+ return value === "minimal" ? "minimal" : "standard";
14
+ }
15
+ /** At most 554px wide by default, as `embed.js` makes the frame; a full-width route has no maximum (docs/decisions.md D97). */
16
+ function stravaPlan(embed, options) {
17
+ const route = embed.id.startsWith("route/");
18
+ const style = styleOf(options.embedStyle ?? embed.options.style);
19
+ const fullWidth = route && (options.fullWidth ?? embed.options.fullWidth === true);
20
+ const mapHash = options.mapHash ?? embed.options.mapHash;
21
+ const query = `?style=${style}${fullWidth ? "&fullWidth=true" : ""}`;
22
+ const fragment = `#ns=${NS}${typeof mapHash === "string" && mapHash !== "" ? `&mapHash=${encodeURIComponent(mapHash)}` : ""}`;
23
+ return {
24
+ kind: "iframe",
25
+ src: `https://strava-embeds.com/${embed.id}${query}${fragment}`,
26
+ title: route ? "Strava route" : "Strava activity",
27
+ allow: "",
28
+ scrolling: "no",
29
+ ratio: {
30
+ width: 1,
31
+ height: 1
32
+ },
33
+ messageHeight: STRAVA_HEIGHT,
34
+ startHeight: 650,
35
+ ...fullWidth ? {} : { maxWidth: 554 }
36
+ };
37
+ }
38
+ export { stravaPlan };
@@ -0,0 +1,8 @@
1
+ /** The player parameters of Streamable's help center (docs/decisions.md D96). */
2
+ export type StreamableOptions = {
3
+ autoplay?: boolean;
4
+ hd?: boolean;
5
+ loop?: boolean;
6
+ muted?: boolean;
7
+ nocontrols?: boolean;
8
+ };
@@ -0,0 +1,31 @@
1
+ import { playerParams, query } from "../params.js";
2
+ // src/core/plans/streamable.ts
3
+ const KEPT = /* @__PURE__ */ new Set([
4
+ "autoplay",
5
+ "hd",
6
+ "loop",
7
+ "muted",
8
+ "nocontrols"
9
+ ]);
10
+ const PARAMS = {
11
+ autoplay: "autoplay",
12
+ hd: "hd",
13
+ loop: "loop",
14
+ muted: "muted",
15
+ nocontrols: "nocontrols"
16
+ };
17
+ function streamablePlan(embed, options) {
18
+ const parsed = Object.entries(embed.options).filter(([key]) => KEPT.has(key));
19
+ return {
20
+ kind: "iframe",
21
+ src: `https://streamable.com/e/${embed.id}${query(parsed, playerParams(options, PARAMS))}`,
22
+ title: "Streamable video",
23
+ allow: "autoplay; fullscreen",
24
+ ratio: {
25
+ width: 16,
26
+ height: 9
27
+ },
28
+ size: embed.size
29
+ };
30
+ }
31
+ export { streamablePlan };
@@ -0,0 +1,10 @@
1
+ /** The options of Telegram's post widget configurator (core.telegram.org/widgets/post). */
2
+ export type TelegramOptions = {
3
+ /** Show the author's photo. */
4
+ userpic?: boolean;
5
+ /** Accent colour as hex, without `#`. */
6
+ color?: string;
7
+ dark?: boolean;
8
+ /** Accent colour in the dark theme, as hex without `#`. */
9
+ darkColor?: string;
10
+ };
@@ -0,0 +1,59 @@
1
+ import { query } from "../params.js";
2
+ // src/core/plans/telegram.ts
3
+ const PARAMS = [
4
+ ["comment", "comment"],
5
+ ["userpic", "userpic"],
6
+ ["mode", "mode"],
7
+ ["single", "single"],
8
+ ["color", "color"],
9
+ ["dark", "dark"],
10
+ ["darkColor", "dark_color"]
11
+ ];
12
+ function param(name, value) {
13
+ if (typeof value === "boolean") {
14
+ if (name === "userpic") return String(value);
15
+ if (name === "single") return value ? 1 : void 0;
16
+ return value ? 1 : 0;
17
+ }
18
+ return typeof value === "string" || typeof value === "number" ? value : void 0;
19
+ }
20
+ /** docs/decisions.md D49. */
21
+ const TELEGRAM_HEIGHT = {
22
+ origin: "https://t.me",
23
+ read(data) {
24
+ if (typeof data !== "string") return void 0;
25
+ const message = JSON.parse(data);
26
+ return message.event === "resize" && typeof message.height === "number" ? message.height : void 0;
27
+ }
28
+ };
29
+ /** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
30
+ function telegramPlan(embed, options) {
31
+ const { userpic, color, dark, darkColor } = options;
32
+ const values = {
33
+ ...embed.options,
34
+ ...userpic === void 0 ? {} : { userpic },
35
+ ...color === void 0 ? {} : { color },
36
+ ...dark === void 0 ? {} : { dark },
37
+ ...darkColor === void 0 ? {} : { darkColor }
38
+ };
39
+ const params = [["embed", 1]];
40
+ for (const [option, name] of PARAMS) {
41
+ const value = param(name, values[option]);
42
+ if (value !== void 0) params.push([name, value]);
43
+ }
44
+ return {
45
+ kind: "iframe",
46
+ src: `${embed.url}${query(params)}`,
47
+ title: "Telegram post",
48
+ allow: "",
49
+ scrolling: "no",
50
+ ratio: {
51
+ width: 1,
52
+ height: 1
53
+ },
54
+ messageHeight: TELEGRAM_HEIGHT,
55
+ startHeight: 300,
56
+ maxWidth: 500
57
+ };
58
+ }
59
+ export { telegramPlan };
@@ -0,0 +1,16 @@
1
+ // src/core/plans/tenor.ts
2
+ /** The embed code's aspect ratio; a URL carries no size and renders at 1.33:1, as `embed.js` does (docs/decisions.md D95). */
3
+ function tenorPlan(embed) {
4
+ return {
5
+ kind: "iframe",
6
+ src: `https://tenor.com/embed/${embed.id}`,
7
+ title: "Tenor GIF",
8
+ allow: "fullscreen",
9
+ ratio: {
10
+ width: 133,
11
+ height: 100
12
+ },
13
+ size: embed.size
14
+ };
15
+ }
16
+ export { tenorPlan };
@@ -0,0 +1,4 @@
1
+ export type ThreadsOptions = {
2
+ /** `data-theme`; embed.js also reads `dark` and `auto` (docs/decisions.md D32). */
3
+ theme?: 'light' | 'dark' | 'auto';
4
+ };
@@ -0,0 +1,25 @@
1
+ import { threadsDriver } from "../drivers.js";
2
+ import { attributes, hasFallback, withProps } from "../markup.js";
3
+ // src/core/plans/threads.ts
4
+ /** A text-only post (docs/decisions.md D34). */
5
+ const MIN_HEIGHT = 240;
6
+ function threadsPlan(embed, options) {
7
+ const merged = withProps(embed.options, { theme: options.theme });
8
+ const markup = `<blockquote${attributes({
9
+ "data-text-post-permalink": embed.url,
10
+ "data-text-post-version": merged.version ?? 0,
11
+ id: `ig-tp-${embed.id}`,
12
+ "data-theme": merged.theme
13
+ })}>${embed.fallbackHtml ?? ""}</blockquote>`;
14
+ return {
15
+ kind: "script",
16
+ key: markup,
17
+ markup,
18
+ driver: threadsDriver,
19
+ minHeight: MIN_HEIGHT,
20
+ label: "Threads",
21
+ hasFallback: hasFallback(embed.fallbackHtml),
22
+ maxWidth: 658
23
+ };
24
+ }
25
+ export { threadsPlan };
@@ -0,0 +1,17 @@
1
+ /** The Embed Player parameters TikTok documents (developers.tiktok.com/doc/embed-player). */
2
+ export type TikTokOptions = {
3
+ controls?: boolean;
4
+ progressBar?: boolean;
5
+ playButton?: boolean;
6
+ volumeControl?: boolean;
7
+ fullscreenButton?: boolean;
8
+ timestamp?: boolean;
9
+ loop?: boolean;
10
+ autoplay?: boolean;
11
+ musicInfo?: boolean;
12
+ description?: boolean;
13
+ rel?: boolean;
14
+ nativeContextMenu?: boolean;
15
+ closedCaption?: boolean;
16
+ forceMuted?: boolean;
17
+ };
@@ -0,0 +1,36 @@
1
+ import { playerParams, query } from "../params.js";
2
+ // src/core/plans/tiktok.ts
3
+ const PARAMS = {
4
+ controls: "controls",
5
+ progressBar: "progress_bar",
6
+ playButton: "play_button",
7
+ volumeControl: "volume_control",
8
+ fullscreenButton: "fullscreen_button",
9
+ timestamp: "timestamp",
10
+ loop: "loop",
11
+ autoplay: "autoplay",
12
+ musicInfo: "music_info",
13
+ description: "description",
14
+ rel: "rel",
15
+ nativeContextMenu: "native_context_menu",
16
+ closedCaption: "closed_caption",
17
+ forceMuted: "force_muted"
18
+ };
19
+ const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
20
+ /** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
21
+ function tiktokPlan(embed, options) {
22
+ const params = playerParams(options, PARAMS);
23
+ return {
24
+ kind: "iframe",
25
+ src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
26
+ title: "TikTok video player",
27
+ allow: ALLOW,
28
+ ratio: {
29
+ width: 9,
30
+ height: 16
31
+ },
32
+ size: embed.size,
33
+ maxWidth: 325
34
+ };
35
+ }
36
+ export { tiktokPlan };
@@ -0,0 +1,43 @@
1
+ // src/core/plans/truthsocial.ts
2
+ const VIDEO_EXTRA = 165;
3
+ function setHeight(data) {
4
+ const message = data;
5
+ return message?.type === "setHeight" && typeof message.height === "number" ? message.height : void 0;
6
+ }
7
+ /** The frame posts `{ type: 'setHeight', id, height }` without being asked (docs/decisions.md D93). */
8
+ const TRUTH_SOCIAL_HEIGHT = {
9
+ origin: "https://truthsocial.com",
10
+ read: setHeight
11
+ };
12
+ /** A video post reports its height before the video is sized (docs/decisions.md D100). */
13
+ const TRUTH_SOCIAL_VIDEO_HEIGHT = {
14
+ origin: "https://truthsocial.com",
15
+ read(data) {
16
+ const height = setHeight(data);
17
+ return height === void 0 || height <= 0 ? void 0 : height + VIDEO_EXTRA;
18
+ }
19
+ };
20
+ const CANONICAL = /^https:\/\/truthsocial\.com\/(@[^/]+)\/posts\/\d+$/;
21
+ /** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
22
+ function truthSocialPlan(embed) {
23
+ const user = CANONICAL.exec(embed.url)?.[1];
24
+ if (user === void 0) return {
25
+ kind: "error",
26
+ message: `social-embeds: not a Truth Social post URL: ${embed.url}`
27
+ };
28
+ return {
29
+ kind: "iframe",
30
+ src: `https://truthsocial.com/${user}/${embed.id}/embed`,
31
+ title: "Truth Social post",
32
+ allow: "",
33
+ scrolling: "no",
34
+ ratio: {
35
+ width: 1,
36
+ height: 1
37
+ },
38
+ messageHeight: embed.options.video === true ? TRUTH_SOCIAL_VIDEO_HEIGHT : TRUTH_SOCIAL_HEIGHT,
39
+ startHeight: 150,
40
+ maxWidth: embed.size?.width ?? 600
41
+ };
42
+ }
43
+ export { truthSocialPlan };
@@ -0,0 +1,29 @@
1
+ // src/core/plans/tumblr.ts
2
+ /** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
3
+ const TUMBLR_HEIGHT = {
4
+ origin: "https://embed.tumblr.com",
5
+ read(data) {
6
+ if (typeof data !== "string") return void 0;
7
+ const message = JSON.parse(data);
8
+ const [height] = Array.isArray(message.args) ? message.args : [];
9
+ return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
10
+ }
11
+ };
12
+ /** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
13
+ function tumblrPlan(embed) {
14
+ return {
15
+ kind: "iframe",
16
+ src: `https://embed.tumblr.com/embed/post/${embed.url.slice(23).split("/")[0] ?? ""}/${embed.id}/v2`,
17
+ title: "Tumblr post",
18
+ allow: "",
19
+ scrolling: "no",
20
+ ratio: {
21
+ width: 1,
22
+ height: 1
23
+ },
24
+ messageHeight: TUMBLR_HEIGHT,
25
+ startHeight: 400,
26
+ maxWidth: 540
27
+ };
28
+ }
29
+ export { tumblrPlan };
@@ -0,0 +1,7 @@
1
+ export type TwitchOptions = {
2
+ /** Twitch's default: `true` for channels and videos, `false` for clips. */
3
+ autoplay?: boolean;
4
+ muted?: boolean;
5
+ /** A video's start time, as `1h2m3s`. */
6
+ time?: string;
7
+ };
@@ -0,0 +1,38 @@
1
+ import { optionsWithout, query } from "../params.js";
2
+ // src/core/plans/twitch.ts
3
+ const RESERVED = [
4
+ "channel",
5
+ "video",
6
+ "collection",
7
+ "clip",
8
+ "parent"
9
+ ];
10
+ /** The player and its content parameter for the embed's canonical URL (docs/decisions.md D64). */
11
+ function player(url, id) {
12
+ const { hostname, pathname } = new URL(url);
13
+ if (hostname === "clips.twitch.tv") return ["https://clips.twitch.tv/embed", ["clip", id]];
14
+ const section = pathname.split("/")[1];
15
+ return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
16
+ }
17
+ /** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
18
+ function twitchPlan(embed, options) {
19
+ const { autoplay, muted, time } = options;
20
+ const params = [];
21
+ if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
22
+ if (muted !== void 0) params.push(["muted", String(muted)]);
23
+ if (time !== void 0) params.push(["time", time]);
24
+ const [base, content] = player(embed.url, embed.id);
25
+ return {
26
+ kind: "iframe",
27
+ src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
28
+ title: "Twitch player",
29
+ allow: "",
30
+ ratio: {
31
+ width: 16,
32
+ height: 9
33
+ },
34
+ size: embed.size,
35
+ hostParam: "parent"
36
+ };
37
+ }
38
+ export { twitchPlan };
@@ -0,0 +1,23 @@
1
+ /** The player parameters Vimeo documents (help.vimeo.com, "Using player parameters"). */
2
+ export type VimeoOptions = {
3
+ autopause?: boolean;
4
+ autoplay?: boolean;
5
+ background?: boolean;
6
+ byline?: boolean;
7
+ /** Hex colour without `#`. */
8
+ color?: string;
9
+ controls?: boolean;
10
+ dnt?: boolean;
11
+ keyboard?: boolean;
12
+ loop?: boolean;
13
+ muted?: boolean;
14
+ pip?: boolean;
15
+ playsinline?: boolean;
16
+ portrait?: boolean;
17
+ quality?: string;
18
+ speed?: boolean;
19
+ title?: boolean;
20
+ transparent?: boolean;
21
+ /** Start time: seconds, or `1m2s`. */
22
+ t?: number | string;
23
+ };
@@ -0,0 +1,42 @@
1
+ import { optionsWithout, playerParams, query } from "../params.js";
2
+ // src/core/plans/vimeo.ts
3
+ const PARAMS = {
4
+ autopause: "autopause",
5
+ autoplay: "autoplay",
6
+ background: "background",
7
+ byline: "byline",
8
+ color: "color",
9
+ controls: "controls",
10
+ dnt: "dnt",
11
+ keyboard: "keyboard",
12
+ loop: "loop",
13
+ muted: "muted",
14
+ pip: "pip",
15
+ playsinline: "playsinline",
16
+ portrait: "portrait",
17
+ quality: "quality",
18
+ speed: "speed",
19
+ title: "title",
20
+ transparent: "transparent"
21
+ };
22
+ const ALLOW = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
23
+ function vimeoPlan(embed, options) {
24
+ const { t, ...rest } = options;
25
+ const { t: parsedStart, ...parsed } = embed.options;
26
+ const hash = new URL(embed.url).pathname.split("/")[2];
27
+ const params = playerParams(rest, PARAMS);
28
+ const start = t ?? parsedStart;
29
+ return {
30
+ kind: "iframe",
31
+ 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))}`}`,
32
+ title: "Vimeo video player",
33
+ allow: ALLOW,
34
+ referrerPolicy: "strict-origin-when-cross-origin",
35
+ ratio: {
36
+ width: 16,
37
+ height: 9
38
+ },
39
+ size: embed.size
40
+ };
41
+ }
42
+ export { vimeoPlan };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `data-width` has no prop, because `width` is the wrapper's: the post fills the wrapper up
3
+ * to `maxWidth` (docs/decisions.md D33).
4
+ */
5
+ export type XOptions = {
6
+ theme?: 'light' | 'dark';
7
+ conversation?: 'none';
8
+ cards?: 'hidden';
9
+ align?: 'left' | 'center' | 'right';
10
+ lang?: string;
11
+ dnt?: boolean;
12
+ };