social-embeds 0.7.1 → 0.8.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.
Files changed (176) hide show
  1. package/README.md +63 -51
  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 +38 -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 +108 -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 +125 -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 +59 -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.d.ts +1 -1
  124. package/dist/element.js +1 -1
  125. package/dist/index.d.ts +53 -344
  126. package/dist/index.js +30 -2575
  127. package/dist/loader/load-script.js +116 -0
  128. package/dist/loader/platform-scripts.js +89 -0
  129. package/dist/parser/frames.js +70 -0
  130. package/dist/parser/html.js +172 -0
  131. package/dist/parser/iframe.d.ts +24 -0
  132. package/dist/parser/iframe.js +151 -0
  133. package/dist/parser/lookup.js +20 -0
  134. package/dist/parser/match-url.d.ts +3 -0
  135. package/dist/parser/match-url.js +22 -0
  136. package/dist/parser/parse-embed.d.ts +7 -0
  137. package/dist/parser/parse-embed.js +69 -0
  138. package/dist/parser/platform.js +60 -0
  139. package/dist/parser/platforms/applemusic.js +45 -0
  140. package/dist/parser/platforms/applepodcasts.js +41 -0
  141. package/dist/parser/platforms/bluesky.js +64 -0
  142. package/dist/parser/platforms/dailymotion.js +57 -0
  143. package/dist/parser/platforms/facebook.js +181 -0
  144. package/dist/parser/platforms/flickr.js +134 -0
  145. package/dist/parser/platforms/giphy.js +68 -0
  146. package/dist/parser/platforms/imgur.js +107 -0
  147. package/dist/parser/platforms/index.js +62 -0
  148. package/dist/parser/platforms/instagram.js +59 -0
  149. package/dist/parser/platforms/kick.js +61 -0
  150. package/dist/parser/platforms/linkedin.js +42 -0
  151. package/dist/parser/platforms/pinterest.js +59 -0
  152. package/dist/parser/platforms/reddit.js +69 -0
  153. package/dist/parser/platforms/rumble.js +44 -0
  154. package/dist/parser/platforms/snapchat.js +87 -0
  155. package/dist/parser/platforms/soundcloud.js +128 -0
  156. package/dist/parser/platforms/spotify.js +51 -0
  157. package/dist/parser/platforms/strava.js +55 -0
  158. package/dist/parser/platforms/streamable.js +95 -0
  159. package/dist/parser/platforms/telegram.js +61 -0
  160. package/dist/parser/platforms/tenor.js +79 -0
  161. package/dist/parser/platforms/threads.js +51 -0
  162. package/dist/parser/platforms/tiktok.js +48 -0
  163. package/dist/parser/platforms/truthsocial.js +50 -0
  164. package/dist/parser/platforms/tumblr.js +72 -0
  165. package/dist/parser/platforms/twitch.js +128 -0
  166. package/dist/parser/platforms/vimeo.js +95 -0
  167. package/dist/parser/platforms/x.js +65 -0
  168. package/dist/parser/platforms/youtube.js +140 -0
  169. package/dist/parser/types.d.ts +14 -0
  170. package/dist/parser/url.js +41 -0
  171. package/dist/parser/verify.js +63 -0
  172. package/dist/parser.d.ts +4 -1
  173. package/dist/parser.js +4 -1
  174. package/package.json +1 -1
  175. package/dist/index-DrMHAkyG.d.ts +0 -46
  176. package/dist/parser-CovaPg5T.js +0 -2585
@@ -0,0 +1,128 @@
1
+ import { sizeOf, withSize } from "../platform.js";
2
+ import { coerce, parseUrl } from "../url.js";
3
+ import { soundcloudFrame } from "../frames.js";
4
+ // src/parser/platforms/soundcloud.ts
5
+ const PAGE_HOSTS = /* @__PURE__ */ new Set([
6
+ "soundcloud.com",
7
+ "www.soundcloud.com",
8
+ "m.soundcloud.com"
9
+ ]);
10
+ const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
11
+ const NAME = "[a-z0-9_-]{1,64}";
12
+ const SECRET = "s-[A-Za-z0-9]{1,32}";
13
+ const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
14
+ const NOT_USERS = /* @__PURE__ */ new Set([
15
+ "discover",
16
+ "search",
17
+ "stream",
18
+ "feed",
19
+ "you",
20
+ "upload",
21
+ "charts",
22
+ "pages",
23
+ "settings",
24
+ "messages",
25
+ "notifications",
26
+ "people",
27
+ "stations",
28
+ "library",
29
+ "terms-of-use",
30
+ "signin"
31
+ ]);
32
+ const NOT_SOUNDS = /* @__PURE__ */ new Set([
33
+ "likes",
34
+ "tracks",
35
+ "sets",
36
+ "albums",
37
+ "reposts",
38
+ "popular-tracks",
39
+ "followers",
40
+ "following",
41
+ "comments",
42
+ "spotlight",
43
+ "toptracks"
44
+ ]);
45
+ const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
46
+ function sound(url, id) {
47
+ return {
48
+ platform: "soundcloud",
49
+ kind: "post",
50
+ url,
51
+ id,
52
+ variant: "iframe"
53
+ };
54
+ }
55
+ function fromApi(url) {
56
+ if (url?.host !== "api.soundcloud.com") return null;
57
+ const [, type, id] = API_PATH.exec(url.path) ?? [];
58
+ if (type === void 0 || id === void 0) return null;
59
+ const token = url.query.get("secret_token");
60
+ if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
61
+ const secret = token === void 0 ? "" : `?secret_token=${token}`;
62
+ return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
63
+ }
64
+ function fromPage(url) {
65
+ if (!PAGE_HOSTS.has(url.host)) return null;
66
+ const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
67
+ if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
68
+ if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
69
+ const path = [
70
+ user,
71
+ second,
72
+ secret
73
+ ].filter(Boolean).join("/");
74
+ return sound(`https://soundcloud.com/${path}`, path);
75
+ }
76
+ const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
77
+ "href",
78
+ "title",
79
+ "target",
80
+ "style"
81
+ ]);
82
+ function isCreditLink(node) {
83
+ if (node?.type !== "element" || node.tag !== "a") return false;
84
+ if ([...node.attrs.keys()].some((name) => !LINK_ATTRIBUTES.has(name))) return false;
85
+ const [text, ...rest] = node.children;
86
+ return rest.length === 0 && text?.type === "text" && PAGE_HOSTS.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
87
+ }
88
+ /** Share code's credit: a styled `div` with the artist link, ` · `, and the sound link. */
89
+ function isCredit(element) {
90
+ if (element.tag !== "div" || element.attrs.size !== 1 || !element.attrs.has("style")) return false;
91
+ const [artist, separator, sound, ...rest] = element.children;
92
+ return rest.length === 0 && isCreditLink(artist) && separator?.type === "text" && /^\s*·\s*$/.test(separator.raw) && isCreditLink(sound);
93
+ }
94
+ const soundcloud = {
95
+ platform: "soundcloud",
96
+ parse(root) {
97
+ if (root.tag !== "iframe") return null;
98
+ const src = parseUrl(root.attrs.get("src") ?? "");
99
+ if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
100
+ let found = fromApi(parseUrl(src.query.get("url") ?? ""));
101
+ if (!found) return null;
102
+ const outer = src.query.get("secret_token");
103
+ if (outer !== void 0) {
104
+ if (!SECRET_TOKEN.test(outer)) return null;
105
+ if (!found.url.includes("?")) found = {
106
+ ...found,
107
+ url: `${found.url}?secret_token=${outer}`
108
+ };
109
+ }
110
+ const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
111
+ const { height } = sizeOf(root) ?? {};
112
+ return withSize({
113
+ ...found,
114
+ options
115
+ }, height === void 0 ? void 0 : { height });
116
+ },
117
+ isOwnScript: () => false,
118
+ isOwnExtra: isCredit,
119
+ match(url) {
120
+ const found = fromApi(url) ?? fromPage(url);
121
+ return found && {
122
+ ...found,
123
+ options: {}
124
+ };
125
+ },
126
+ ownsFrame: soundcloudFrame
127
+ };
128
+ export { soundcloud };
@@ -0,0 +1,51 @@
1
+ import { sizeOf, withSize } from "../platform.js";
2
+ import { coerce, parseUrl } from "../url.js";
3
+ import { spotifyFrame } from "../frames.js";
4
+ // src/parser/platforms/spotify.ts
5
+ const CONTENT_PATH = new RegExp(`^(?:/intl-[a-z]{2}(?:-[A-Za-z]{2})?)?(?:/embed)?/(track|album|playlist|artist|episode|show|audiobook|chapter)/([A-Za-z0-9]{22})(/video)?/?$`);
6
+ const DROPPED = /* @__PURE__ */ new Set(["utm_source", "si"]);
7
+ function content(url) {
8
+ if (url?.host !== "open.spotify.com") return null;
9
+ const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
10
+ if (type === void 0 || id === void 0) return null;
11
+ return {
12
+ platform: "spotify",
13
+ kind: video ? "video" : "post",
14
+ url: `https://open.spotify.com/${type}/${id}`,
15
+ id,
16
+ variant: "iframe",
17
+ query: url.query
18
+ };
19
+ }
20
+ function options(query) {
21
+ return Object.fromEntries([...query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
22
+ }
23
+ const spotify = {
24
+ platform: "spotify",
25
+ parse(root) {
26
+ if (root.tag !== "iframe") return null;
27
+ const src = parseUrl(root.attrs.get("src") ?? "");
28
+ if (!src?.path.startsWith("/embed/")) return null;
29
+ const found = content(src);
30
+ if (!found) return null;
31
+ const { query, ...embed } = found;
32
+ return withSize({
33
+ ...embed,
34
+ options: options(query)
35
+ }, sizeOf(root));
36
+ },
37
+ isOwnScript: () => false,
38
+ match(url) {
39
+ const found = content(url);
40
+ return found && {
41
+ platform: found.platform,
42
+ kind: "post",
43
+ url: found.url,
44
+ id: found.id,
45
+ variant: found.variant,
46
+ options: {}
47
+ };
48
+ },
49
+ ownsFrame: spotifyFrame
50
+ };
51
+ export { spotify };
@@ -0,0 +1,55 @@
1
+ import { hasClass } from "../html.js";
2
+ // src/parser/platforms/strava.ts
3
+ const HOSTS = /* @__PURE__ */ new Set(["strava.com", "www.strava.com"]);
4
+ const NUMBER = /^\d{1,20}$/;
5
+ const PAGE_PATH = /^\/(activities|routes)\/(\d{1,20})\/?$/;
6
+ const SCRIPT = /^(?:https?:)?\/\/strava-embeds\.com\/embed\.js$/;
7
+ const STYLES = /* @__PURE__ */ new Set(["standard", "minimal"]);
8
+ const MAP_HASH = /^[A-Za-z0-9_-]{1,100}$/;
9
+ const PAGES = {
10
+ activity: "activities",
11
+ route: "routes"
12
+ };
13
+ function item(type, number) {
14
+ return {
15
+ platform: "strava",
16
+ kind: "post",
17
+ url: `https://www.strava.com/${PAGES[type]}/${number}`,
18
+ id: `${type}/${number}`,
19
+ variant: "iframe"
20
+ };
21
+ }
22
+ function isType(value) {
23
+ return value === "activity" || value === "route";
24
+ }
25
+ const strava = {
26
+ platform: "strava",
27
+ parse(root) {
28
+ if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
29
+ if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
30
+ const type = root.attrs.get("data-embed-type");
31
+ const number = root.attrs.get("data-embed-id") ?? "";
32
+ if (!isType(type) || !NUMBER.test(number)) return null;
33
+ const options = {};
34
+ const style = root.attrs.get("data-style");
35
+ if (style !== void 0 && STYLES.has(style)) options.style = style;
36
+ if (type === "route" && root.attrs.get("data-full-width") === "true") options.fullWidth = true;
37
+ const mapHash = root.attrs.get("data-map-hash");
38
+ if (mapHash !== void 0 && MAP_HASH.test(mapHash)) options.mapHash = mapHash;
39
+ return {
40
+ ...item(type, number),
41
+ options
42
+ };
43
+ },
44
+ isOwnScript: (src) => SCRIPT.test(src),
45
+ match(url) {
46
+ if (!HOSTS.has(url.host)) return null;
47
+ const [, page, number] = PAGE_PATH.exec(url.path) ?? [];
48
+ if (page === void 0 || number === void 0) return null;
49
+ return {
50
+ ...item(page === "routes" ? "route" : "activity", number),
51
+ options: {}
52
+ };
53
+ }
54
+ };
55
+ export { strava };
@@ -0,0 +1,95 @@
1
+ import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
+ import { coerce, parseUrl } from "../url.js";
3
+ import { streamableFrame } from "../frames.js";
4
+ // src/parser/platforms/streamable.ts
5
+ const ID = "([a-z0-9]{4,8})";
6
+ const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
7
+ const PLAYER_PATH = new RegExp(`^/[eo]/${ID}$`);
8
+ const PAGE_PATH = new RegExp(`^/${ID}/?$`);
9
+ const NOT_VIDEOS = /* @__PURE__ */ new Set([
10
+ "about",
11
+ "login",
12
+ "signup",
13
+ "terms",
14
+ "privacy",
15
+ "pricing",
16
+ "upload",
17
+ "help",
18
+ "apps",
19
+ "blog",
20
+ "jobs",
21
+ "press",
22
+ "tools",
23
+ "embed",
24
+ "plans",
25
+ "contact",
26
+ "support",
27
+ "videos",
28
+ "account",
29
+ "profile"
30
+ ]);
31
+ const WRAPPER = /^width:\s*100%;\s*height:\s*0(?:px)?;\s*position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;?$/;
32
+ const KEPT = /* @__PURE__ */ new Set([
33
+ "loop",
34
+ "autoplay",
35
+ "nocontrols",
36
+ "hd",
37
+ "muted"
38
+ ]);
39
+ const STRAY_END = /<\/div\s*>$/i;
40
+ function video(id) {
41
+ return {
42
+ platform: "streamable",
43
+ kind: "video",
44
+ url: `https://streamable.com/${id}`,
45
+ id,
46
+ variant: "iframe"
47
+ };
48
+ }
49
+ function validId(id) {
50
+ return id !== void 0 && !NOT_VIDEOS.has(id);
51
+ }
52
+ function fromIframe(iframe) {
53
+ if (iframe.tag !== "iframe") return null;
54
+ const src = parseUrl(iframe.attrs.get("src") ?? "");
55
+ if (!src || src.host !== "streamable.com") return null;
56
+ const [, id] = PLAYER_PATH.exec(src.path) ?? [];
57
+ if (!validId(id)) return null;
58
+ const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
59
+ return {
60
+ ...video(id),
61
+ options
62
+ };
63
+ }
64
+ function idOf(url) {
65
+ if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
66
+ const id = (PLAYER_PATH.exec(url.path) ?? PAGE_PATH.exec(url.path))?.[1];
67
+ return validId(id) ? id : void 0;
68
+ }
69
+ const streamable = {
70
+ platform: "streamable",
71
+ parse(root) {
72
+ const wrapped = unwrapRatio(root, WRAPPER);
73
+ const iframe = wrapped?.iframe ?? root;
74
+ const found = fromIframe(iframe);
75
+ if (!found) return null;
76
+ return withSize(found, wrapped?.size ?? sizeOf(iframe));
77
+ },
78
+ isOwnScript: () => false,
79
+ repair(html) {
80
+ const code = html.trimEnd();
81
+ const end = STRAY_END.exec(code);
82
+ if (!end) return null;
83
+ const trimmed = code.slice(0, end.index).trimEnd();
84
+ return /^\s*<iframe[\s>]/i.test(trimmed) ? trimmed : null;
85
+ },
86
+ match(url) {
87
+ const id = idOf(url);
88
+ return id === void 0 ? null : {
89
+ ...video(id),
90
+ options: {}
91
+ };
92
+ },
93
+ ownsFrame: streamableFrame
94
+ };
95
+ export { streamable };
@@ -0,0 +1,61 @@
1
+ import { attributeOptions } from "../platform.js";
2
+ import { coerce } from "../url.js";
3
+ // src/parser/platforms/telegram.ts
4
+ const HOSTS = /* @__PURE__ */ new Set([
5
+ "t.me",
6
+ "telegram.me",
7
+ "www.telegram.me"
8
+ ]);
9
+ const CHANNEL = "[A-Za-z][A-Za-z0-9_]{2,31}";
10
+ const POST = new RegExp(`^(${CHANNEL})/(\\d{1,10})$`);
11
+ const POST_PATH = new RegExp(`^/(?:s/)?(${CHANNEL})/(\\d{1,10})/?$`);
12
+ const SCRIPT = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
13
+ const OTHER_WIDGETS = [
14
+ "data-telegram-login",
15
+ "data-telegram-discussion",
16
+ "data-telegram-share-url"
17
+ ];
18
+ const OPTION_ATTRIBUTES = [
19
+ ["data-width", "width"],
20
+ ["data-comment", "comment"],
21
+ ["data-userpic", "userpic"],
22
+ ["data-mode", "mode"],
23
+ ["data-color", "color"],
24
+ ["data-dark", "dark"],
25
+ ["data-dark-color", "darkColor"]
26
+ ];
27
+ function post(channel, id, options) {
28
+ return {
29
+ platform: "telegram",
30
+ kind: "post",
31
+ url: `https://t.me/${channel}/${id}`,
32
+ id: `${channel}/${id}`,
33
+ variant: "iframe",
34
+ options
35
+ };
36
+ }
37
+ const telegram = {
38
+ platform: "telegram",
39
+ parse: () => null,
40
+ parseScript(script) {
41
+ if (!SCRIPT.test(script.attrs.get("src") ?? "")) return null;
42
+ if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
43
+ const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
44
+ if (channel === void 0 || id === void 0) return null;
45
+ const options = attributeOptions(script, OPTION_ATTRIBUTES, coerce);
46
+ if (script.attrs.has("data-single")) options.single = true;
47
+ return post(channel, id, options);
48
+ },
49
+ isOwnScript: (src) => SCRIPT.test(src),
50
+ match(url) {
51
+ if (!HOSTS.has(url.host)) return null;
52
+ const [, channel, id] = POST_PATH.exec(url.path) ?? [];
53
+ if (channel === void 0 || id === void 0) return null;
54
+ const options = {};
55
+ if (url.query.has("single")) options.single = true;
56
+ const comment = url.query.get("comment");
57
+ if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
58
+ return post(channel, id, options);
59
+ }
60
+ };
61
+ export { telegram };
@@ -0,0 +1,79 @@
1
+ import { hasClass, rebuild } from "../html.js";
2
+ import { sizeOf, withSize } from "../platform.js";
3
+ import { parseUrl } from "../url.js";
4
+ import { tenorFrame } from "../frames.js";
5
+ // src/parser/platforms/tenor.ts
6
+ const HOSTS = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
7
+ const ID = "(\\d{1,20})";
8
+ const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID}/?$`);
9
+ const FRAME_PATH = new RegExp(`^/embed/${ID}$`);
10
+ const SCRIPT = /^(?:https?:)?\/\/tenor\.com\/embed\.js$/;
11
+ const RATIO = /^\d{1,3}(?:\.\d{1,20})?$/;
12
+ const DEFAULT_RATIO = 1.33;
13
+ const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]]]);
14
+ function gif(id) {
15
+ return {
16
+ platform: "tenor",
17
+ kind: "video",
18
+ url: `https://tenor.com/view/${id}`,
19
+ id,
20
+ variant: "iframe"
21
+ };
22
+ }
23
+ function idOf(url) {
24
+ return url && HOSTS.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
25
+ }
26
+ /** To four decimals, from 1:100 to 100:1. */
27
+ function ratioSize(ratio) {
28
+ const width = Math.round(ratio * 1e4);
29
+ if (!(width >= 100 && width <= 1e6)) return void 0;
30
+ const divisor = gcd(width, 1e4);
31
+ return {
32
+ width: width / divisor,
33
+ height: 1e4 / divisor
34
+ };
35
+ }
36
+ function gcd(a, b) {
37
+ return b === 0 ? a : gcd(b, a % b);
38
+ }
39
+ function fromDiv(root) {
40
+ if (!hasClass(root, "tenor-gif-embed")) return null;
41
+ const id = root.attrs.get("data-postid") ?? "";
42
+ if (!new RegExp(`^${ID}$`).test(id)) return null;
43
+ const given = root.attrs.get("data-aspect-ratio");
44
+ if (given !== void 0 && !RATIO.test(given)) return null;
45
+ const size = ratioSize(given === void 0 ? DEFAULT_RATIO : Number(given));
46
+ if (!size) return null;
47
+ return withSize({
48
+ ...gif(id),
49
+ options: {},
50
+ fallbackHtml: rebuild(root.children, FALLBACK)
51
+ }, size);
52
+ }
53
+ function fromIframe(root) {
54
+ const src = parseUrl(root.attrs.get("src") ?? "");
55
+ if (!src || src.host !== "tenor.com") return null;
56
+ const [, id] = FRAME_PATH.exec(src.path) ?? [];
57
+ return id === void 0 ? null : withSize({
58
+ ...gif(id),
59
+ options: {}
60
+ }, sizeOf(root));
61
+ }
62
+ const tenor = {
63
+ platform: "tenor",
64
+ fallback: FALLBACK,
65
+ parse(root) {
66
+ if (root.tag === "div") return fromDiv(root);
67
+ return root.tag === "iframe" ? fromIframe(root) : null;
68
+ },
69
+ isOwnScript: (src) => SCRIPT.test(src),
70
+ match(url) {
71
+ const id = idOf(url);
72
+ return id === void 0 ? null : {
73
+ ...gif(id),
74
+ options: {}
75
+ };
76
+ },
77
+ ownsFrame: tenorFrame
78
+ };
79
+ export { tenor };
@@ -0,0 +1,51 @@
1
+ import { hasClass, rebuild } from "../html.js";
2
+ import { attributeOptions } from "../platform.js";
3
+ import { coerce, parseUrl } from "../url.js";
4
+ // src/parser/platforms/threads.ts
5
+ const HOSTS = /* @__PURE__ */ new Set([
6
+ "threads.com",
7
+ "www.threads.com",
8
+ "threads.net",
9
+ "www.threads.net"
10
+ ]);
11
+ const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
12
+ const SCRIPT = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
13
+ const OPTION_ATTRIBUTES = [["data-theme", "theme"], ["data-text-post-version", "version"]];
14
+ const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
15
+ function post(url) {
16
+ if (!url || !HOSTS.has(url.host)) return null;
17
+ const [, code] = POST_PATH.exec(url.path) ?? [];
18
+ if (code === void 0) return null;
19
+ return {
20
+ platform: "threads",
21
+ kind: "post",
22
+ url: `https://www.threads.com/t/${code}`,
23
+ id: code,
24
+ variant: "sdk"
25
+ };
26
+ }
27
+ const threads = {
28
+ platform: "threads",
29
+ fallback: FALLBACK,
30
+ parse(root) {
31
+ if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
32
+ const found = post(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
33
+ if (!found) return null;
34
+ const elementId = root.attrs.get("id");
35
+ if (elementId !== void 0 && elementId !== `ig-tp-${found.id}`) return null;
36
+ return {
37
+ ...found,
38
+ options: attributeOptions(root, OPTION_ATTRIBUTES, coerce),
39
+ fallbackHtml: rebuild(root.children, FALLBACK)
40
+ };
41
+ },
42
+ isOwnScript: (src) => SCRIPT.test(src),
43
+ match(url) {
44
+ const found = post(url);
45
+ return found && {
46
+ ...found,
47
+ options: {}
48
+ };
49
+ }
50
+ };
51
+ export { threads };
@@ -0,0 +1,48 @@
1
+ import { hasClass } from "../html.js";
2
+ import { sizeOf, withSize } from "../platform.js";
3
+ import { coerce, parseUrl } from "../url.js";
4
+ import { TIKTOK_HOSTS, tiktokFrame } from "../frames.js";
5
+ // src/parser/platforms/tiktok.ts
6
+ const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
7
+ const PLAYER_PATH = /^\/player\/v1\/(\d{1,25})\/?$/;
8
+ const VIDEO_ID = /^\d{1,25}$/;
9
+ const SCRIPT = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
10
+ function video(id, user = "", options = {}) {
11
+ return {
12
+ platform: "tiktok",
13
+ kind: "video",
14
+ url: `https://www.tiktok.com/@${user}/video/${id}`,
15
+ id,
16
+ variant: "iframe",
17
+ options
18
+ };
19
+ }
20
+ const tiktok = {
21
+ platform: "tiktok",
22
+ parse(root) {
23
+ if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
24
+ const cite = parseUrl(root.attrs.get("cite") ?? "");
25
+ const [, user, citeId] = cite && TIKTOK_HOSTS.has(cite.host) ? VIDEO_PATH.exec(cite.path) ?? [] : [];
26
+ const dataId = root.attrs.get("data-video-id");
27
+ if (dataId !== void 0 && !VIDEO_ID.test(dataId)) return null;
28
+ if (dataId !== void 0 && citeId !== void 0 && dataId !== citeId) return null;
29
+ const id = dataId ?? citeId;
30
+ return id === void 0 ? null : video(id, user);
31
+ }
32
+ if (root.tag !== "iframe") return null;
33
+ const src = parseUrl(root.attrs.get("src") ?? "");
34
+ if (!src || !TIKTOK_HOSTS.has(src.host)) return null;
35
+ const [, id] = PLAYER_PATH.exec(src.path) ?? [];
36
+ if (id === void 0) return null;
37
+ const options = Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]));
38
+ return withSize(video(id, "", options), sizeOf(root));
39
+ },
40
+ isOwnScript: (src) => SCRIPT.test(src),
41
+ match(url) {
42
+ if (!TIKTOK_HOSTS.has(url.host)) return null;
43
+ const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
44
+ return user === void 0 || id === void 0 ? null : video(id, user);
45
+ },
46
+ ownsFrame: tiktokFrame
47
+ };
48
+ export { tiktok };
@@ -0,0 +1,50 @@
1
+ import { hasClass } from "../html.js";
2
+ import { sizeOf, withSize } from "../platform.js";
3
+ import { parseUrl } from "../url.js";
4
+ import { truthsocialFrame } from "../frames.js";
5
+ // src/parser/platforms/truthsocial.ts
6
+ const HOSTS = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
7
+ const USER = "(@[A-Za-z0-9_.-]{1,64})";
8
+ const ID = "(\\d{1,25})";
9
+ const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
10
+ const FRAME_PATH = new RegExp(`^/${USER}/${ID}/embed$`);
11
+ const SCRIPT = /^(?:https?:)?\/\/truthsocial\.com\/embed\.js$/;
12
+ function post(user, id) {
13
+ return {
14
+ platform: "truthsocial",
15
+ kind: "post",
16
+ url: `https://truthsocial.com/${user}/posts/${id}`,
17
+ id,
18
+ variant: "iframe"
19
+ };
20
+ }
21
+ function fromUrl(url) {
22
+ if (!url || !HOSTS.has(url.host)) return null;
23
+ const [, user, id] = POST_PATH.exec(url.path) ?? [];
24
+ return user === void 0 || id === void 0 ? null : post(user, id);
25
+ }
26
+ const truthsocial = {
27
+ platform: "truthsocial",
28
+ parse(root) {
29
+ if (root.tag !== "iframe") return null;
30
+ const src = parseUrl(root.attrs.get("src") ?? "");
31
+ if (!src || src.host !== "truthsocial.com") return null;
32
+ const [, user, id] = FRAME_PATH.exec(src.path) ?? [];
33
+ if (user === void 0 || id === void 0) return null;
34
+ const options = hasClass(root, "truthsocial-video") ? { video: true } : {};
35
+ return withSize({
36
+ ...post(user, id),
37
+ options
38
+ }, sizeOf(root));
39
+ },
40
+ isOwnScript: (src) => SCRIPT.test(src),
41
+ match(url) {
42
+ const found = fromUrl(url);
43
+ return found && {
44
+ ...found,
45
+ options: {}
46
+ };
47
+ },
48
+ ownsFrame: truthsocialFrame
49
+ };
50
+ export { truthsocial };