social-embeds 0.9.1 → 0.9.3

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 (121) hide show
  1. package/README.md +3 -3
  2. package/dist/components/apple-embed.d.ts +2 -2
  3. package/dist/components/apple-embed.js +8 -30
  4. package/dist/components/bluesky-embed.d.ts +1 -1
  5. package/dist/components/bluesky-embed.js +6 -17
  6. package/dist/components/dailymotion-embed.d.ts +1 -1
  7. package/dist/components/dailymotion-embed.js +11 -21
  8. package/dist/components/facebook-embed.d.ts +1 -1
  9. package/dist/components/facebook-embed.js +14 -35
  10. package/dist/components/flickr-embed.d.ts +1 -1
  11. package/dist/components/flickr-embed.js +10 -21
  12. package/dist/components/giphy-embed.d.ts +1 -1
  13. package/dist/components/giphy-embed.js +5 -16
  14. package/dist/components/iframe-embed.js +15 -1
  15. package/dist/components/imgur-embed.d.ts +1 -1
  16. package/dist/components/imgur-embed.js +6 -17
  17. package/dist/components/instagram-embed.d.ts +1 -1
  18. package/dist/components/instagram-embed.js +6 -20
  19. package/dist/components/kick-embed.d.ts +1 -1
  20. package/dist/components/kick-embed.js +6 -19
  21. package/dist/components/linkedin-embed.d.ts +1 -1
  22. package/dist/components/linkedin-embed.js +6 -17
  23. package/dist/components/pinterest-embed.d.ts +1 -1
  24. package/dist/components/pinterest-embed.js +6 -20
  25. package/dist/components/reddit-embed.d.ts +1 -1
  26. package/dist/components/reddit-embed.js +13 -23
  27. package/dist/components/rumble-embed.d.ts +1 -1
  28. package/dist/components/rumble-embed.js +5 -16
  29. package/dist/components/script-embed.js +14 -1
  30. package/dist/components/snapchat-embed.d.ts +1 -1
  31. package/dist/components/snapchat-embed.js +5 -16
  32. package/dist/components/soundcloud-embed.d.ts +1 -1
  33. package/dist/components/soundcloud-embed.js +16 -27
  34. package/dist/components/spotify-embed.d.ts +1 -1
  35. package/dist/components/spotify-embed.js +6 -16
  36. package/dist/components/strava-embed.d.ts +1 -1
  37. package/dist/components/strava-embed.js +10 -20
  38. package/dist/components/streamable-embed.d.ts +1 -1
  39. package/dist/components/streamable-embed.js +12 -22
  40. package/dist/components/telegram-embed.d.ts +1 -1
  41. package/dist/components/telegram-embed.js +11 -21
  42. package/dist/components/tenor-embed.d.ts +1 -1
  43. package/dist/components/tenor-embed.js +5 -16
  44. package/dist/components/threads-embed.d.ts +1 -1
  45. package/dist/components/threads-embed.js +6 -20
  46. package/dist/components/tiktok-embed.d.ts +1 -1
  47. package/dist/components/tiktok-embed.js +21 -31
  48. package/dist/components/truthsocial-embed.d.ts +1 -1
  49. package/dist/components/truthsocial-embed.js +5 -16
  50. package/dist/components/tumblr-embed.d.ts +1 -1
  51. package/dist/components/tumblr-embed.js +5 -16
  52. package/dist/components/twitch-embed.d.ts +1 -1
  53. package/dist/components/twitch-embed.js +10 -20
  54. package/dist/components/use-plan.js +20 -0
  55. package/dist/components/vimeo-embed.d.ts +1 -1
  56. package/dist/components/vimeo-embed.js +25 -35
  57. package/dist/components/x-embed.d.ts +1 -1
  58. package/dist/components/x-embed.js +13 -27
  59. package/dist/components/youtube-embed.d.ts +1 -1
  60. package/dist/components/youtube-embed.js +28 -38
  61. package/dist/element.js +1 -1
  62. package/dist/parser/matchers/applemusic.js +33 -0
  63. package/dist/parser/matchers/applepodcasts.js +32 -0
  64. package/dist/parser/matchers/bluesky.js +41 -0
  65. package/dist/parser/matchers/dailymotion.js +47 -0
  66. package/dist/parser/matchers/facebook.js +118 -0
  67. package/dist/parser/matchers/flickr.js +100 -0
  68. package/dist/parser/matchers/giphy.js +38 -0
  69. package/dist/parser/matchers/imgur.js +76 -0
  70. package/dist/parser/matchers/instagram.js +43 -0
  71. package/dist/parser/matchers/kick.js +48 -0
  72. package/dist/parser/matchers/linkedin.js +31 -0
  73. package/dist/parser/matchers/pinterest.js +32 -0
  74. package/dist/parser/matchers/reddit.js +43 -0
  75. package/dist/parser/matchers/rumble.js +32 -0
  76. package/dist/parser/matchers/snapchat.js +60 -0
  77. package/dist/parser/matchers/soundcloud.js +87 -0
  78. package/dist/parser/matchers/spotify.js +39 -0
  79. package/dist/parser/matchers/strava.js +31 -0
  80. package/dist/parser/matchers/streamable.js +59 -0
  81. package/dist/parser/matchers/telegram.js +34 -0
  82. package/dist/parser/matchers/tenor.js +34 -0
  83. package/dist/parser/matchers/threads.js +36 -0
  84. package/dist/parser/matchers/tiktok.js +25 -0
  85. package/dist/parser/matchers/truthsocial.js +34 -0
  86. package/dist/parser/matchers/tumblr.js +51 -0
  87. package/dist/parser/matchers/twitch.js +90 -0
  88. package/dist/parser/matchers/vimeo.js +71 -0
  89. package/dist/parser/matchers/x.js +50 -0
  90. package/dist/parser/matchers/youtube.js +123 -0
  91. package/dist/parser/platform.d.ts +10 -4
  92. package/dist/parser/platforms/applemusic.js +4 -30
  93. package/dist/parser/platforms/applepodcasts.js +4 -29
  94. package/dist/parser/platforms/bluesky.js +4 -38
  95. package/dist/parser/platforms/dailymotion.js +4 -44
  96. package/dist/parser/platforms/facebook.js +5 -115
  97. package/dist/parser/platforms/flickr.js +5 -98
  98. package/dist/parser/platforms/giphy.js +4 -35
  99. package/dist/parser/platforms/imgur.js +4 -73
  100. package/dist/parser/platforms/instagram.js +4 -40
  101. package/dist/parser/platforms/kick.js +4 -45
  102. package/dist/parser/platforms/linkedin.js +4 -28
  103. package/dist/parser/platforms/pinterest.js +4 -29
  104. package/dist/parser/platforms/reddit.js +3 -40
  105. package/dist/parser/platforms/rumble.js +3 -29
  106. package/dist/parser/platforms/snapchat.js +3 -57
  107. package/dist/parser/platforms/soundcloud.js +4 -84
  108. package/dist/parser/platforms/spotify.js +4 -36
  109. package/dist/parser/platforms/strava.js +3 -28
  110. package/dist/parser/platforms/streamable.js +3 -56
  111. package/dist/parser/platforms/telegram.js +3 -31
  112. package/dist/parser/platforms/tenor.js +5 -32
  113. package/dist/parser/platforms/threads.js +4 -33
  114. package/dist/parser/platforms/tiktok.js +4 -22
  115. package/dist/parser/platforms/truthsocial.js +3 -31
  116. package/dist/parser/platforms/tumblr.js +3 -48
  117. package/dist/parser/platforms/twitch.js +4 -87
  118. package/dist/parser/platforms/vimeo.js +4 -68
  119. package/dist/parser/platforms/x.js +6 -46
  120. package/dist/parser/platforms/youtube.js +5 -120
  121. package/package.json +1 -1
@@ -0,0 +1,87 @@
1
+ import { soundcloudFrame } from "../frames.js";
2
+ // src/parser/matchers/soundcloud.ts
3
+ const PAGE_HOSTS = /* @__PURE__ */ new Set([
4
+ "soundcloud.com",
5
+ "www.soundcloud.com",
6
+ "m.soundcloud.com"
7
+ ]);
8
+ const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
9
+ const NAME = "[a-z0-9_-]{1,64}";
10
+ const SECRET = "s-[A-Za-z0-9]{1,32}";
11
+ const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
12
+ const NOT_USERS = /* @__PURE__ */ new Set([
13
+ "discover",
14
+ "search",
15
+ "stream",
16
+ "feed",
17
+ "you",
18
+ "upload",
19
+ "charts",
20
+ "pages",
21
+ "settings",
22
+ "messages",
23
+ "notifications",
24
+ "people",
25
+ "stations",
26
+ "library",
27
+ "terms-of-use",
28
+ "signin"
29
+ ]);
30
+ const NOT_SOUNDS = /* @__PURE__ */ new Set([
31
+ "likes",
32
+ "tracks",
33
+ "sets",
34
+ "albums",
35
+ "reposts",
36
+ "popular-tracks",
37
+ "followers",
38
+ "following",
39
+ "comments",
40
+ "spotlight",
41
+ "toptracks"
42
+ ]);
43
+ const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
44
+ function sound(url, id) {
45
+ return {
46
+ platform: "soundcloud",
47
+ kind: "post",
48
+ url,
49
+ id,
50
+ variant: "iframe"
51
+ };
52
+ }
53
+ function fromApi(url) {
54
+ if (url?.host !== "api.soundcloud.com") return null;
55
+ const [, type, id] = API_PATH.exec(url.path) ?? [];
56
+ if (type === void 0 || id === void 0) return null;
57
+ const token = url.query.get("secret_token");
58
+ if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
59
+ const secret = token === void 0 ? "" : `?secret_token=${token}`;
60
+ return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
61
+ }
62
+ function fromPage(url) {
63
+ if (!PAGE_HOSTS.has(url.host)) return null;
64
+ const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
65
+ if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
66
+ if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
67
+ const path = [
68
+ user,
69
+ second,
70
+ secret
71
+ ].filter(Boolean).join("/");
72
+ return sound(`https://soundcloud.com/${path}`, path);
73
+ }
74
+ const soundcloudMatcher = {
75
+ platform: "soundcloud",
76
+ name: "SoundCloud",
77
+ shapes: ["post iframe"],
78
+ match(url) {
79
+ const found = fromApi(url) ?? fromPage(url);
80
+ return found && {
81
+ ...found,
82
+ options: {}
83
+ };
84
+ },
85
+ ownsFrame: soundcloudFrame
86
+ };
87
+ export { PAGE_HOSTS, SECRET_TOKEN, fromApi, sound, soundcloudMatcher };
@@ -0,0 +1,39 @@
1
+ import { coerce } from "../url.js";
2
+ import { spotifyFrame } from "../frames.js";
3
+ // src/parser/matchers/spotify.ts
4
+ 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)?/?$`);
5
+ const DROPPED = /* @__PURE__ */ new Set(["utm_source", "si"]);
6
+ function content(url) {
7
+ if (url?.host !== "open.spotify.com") return null;
8
+ const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
9
+ if (type === void 0 || id === void 0) return null;
10
+ return {
11
+ platform: "spotify",
12
+ kind: video ? "video" : "post",
13
+ url: `https://open.spotify.com/${type}/${id}`,
14
+ id,
15
+ variant: "iframe",
16
+ query: url.query
17
+ };
18
+ }
19
+ function options(query) {
20
+ return Object.fromEntries([...query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
21
+ }
22
+ const spotifyMatcher = {
23
+ platform: "spotify",
24
+ name: "Spotify",
25
+ shapes: ["post iframe", "video iframe"],
26
+ match(url) {
27
+ const found = content(url);
28
+ return found && {
29
+ platform: found.platform,
30
+ kind: "post",
31
+ url: found.url,
32
+ id: found.id,
33
+ variant: found.variant,
34
+ options: {}
35
+ };
36
+ },
37
+ ownsFrame: spotifyFrame
38
+ };
39
+ export { content, options, spotifyMatcher };
@@ -0,0 +1,31 @@
1
+ // src/parser/matchers/strava.ts
2
+ const HOSTS = /* @__PURE__ */ new Set(["strava.com", "www.strava.com"]);
3
+ const PAGE_PATH = /^\/(activities|routes)\/(\d{1,20})\/?$/;
4
+ const PAGES = {
5
+ activity: "activities",
6
+ route: "routes"
7
+ };
8
+ function item(type, number) {
9
+ return {
10
+ platform: "strava",
11
+ kind: "post",
12
+ url: `https://www.strava.com/${PAGES[type]}/${number}`,
13
+ id: `${type}/${number}`,
14
+ variant: "iframe"
15
+ };
16
+ }
17
+ const stravaMatcher = {
18
+ platform: "strava",
19
+ name: "Strava",
20
+ shapes: ["post iframe"],
21
+ match(url) {
22
+ if (!HOSTS.has(url.host)) return null;
23
+ const [, page, number] = PAGE_PATH.exec(url.path) ?? [];
24
+ if (page === void 0 || number === void 0) return null;
25
+ return {
26
+ ...item(page === "routes" ? "route" : "activity", number),
27
+ options: {}
28
+ };
29
+ }
30
+ };
31
+ export { item, stravaMatcher };
@@ -0,0 +1,59 @@
1
+ import { streamableFrame } from "../frames.js";
2
+ // src/parser/matchers/streamable.ts
3
+ const ID = "([a-z0-9]{4,8})";
4
+ const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
5
+ const PLAYER_PATH = new RegExp(`^/[eo]/${ID}$`);
6
+ const PAGE_PATH = new RegExp(`^/${ID}/?$`);
7
+ const NOT_VIDEOS = /* @__PURE__ */ new Set([
8
+ "about",
9
+ "login",
10
+ "signup",
11
+ "terms",
12
+ "privacy",
13
+ "pricing",
14
+ "upload",
15
+ "help",
16
+ "apps",
17
+ "blog",
18
+ "jobs",
19
+ "press",
20
+ "tools",
21
+ "embed",
22
+ "plans",
23
+ "contact",
24
+ "support",
25
+ "videos",
26
+ "account",
27
+ "profile"
28
+ ]);
29
+ function video(id) {
30
+ return {
31
+ platform: "streamable",
32
+ kind: "video",
33
+ url: `https://streamable.com/${id}`,
34
+ id,
35
+ variant: "iframe"
36
+ };
37
+ }
38
+ function validId(id) {
39
+ return id !== void 0 && !NOT_VIDEOS.has(id);
40
+ }
41
+ function idOf(url) {
42
+ if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
43
+ const id = (PLAYER_PATH.exec(url.path) ?? PAGE_PATH.exec(url.path))?.[1];
44
+ return validId(id) ? id : void 0;
45
+ }
46
+ const streamableMatcher = {
47
+ platform: "streamable",
48
+ name: "Streamable",
49
+ shapes: ["video iframe"],
50
+ match(url) {
51
+ const id = idOf(url);
52
+ return id === void 0 ? null : {
53
+ ...video(id),
54
+ options: {}
55
+ };
56
+ },
57
+ ownsFrame: streamableFrame
58
+ };
59
+ export { PLAYER_PATH, streamableMatcher, validId, video };
@@ -0,0 +1,34 @@
1
+ // src/parser/matchers/telegram.ts
2
+ const HOSTS = /* @__PURE__ */ new Set([
3
+ "t.me",
4
+ "telegram.me",
5
+ "www.telegram.me"
6
+ ]);
7
+ const CHANNEL = "[A-Za-z][A-Za-z0-9_]{2,31}";
8
+ const POST_PATH = new RegExp(`^/(?:s/)?(${CHANNEL})/(\\d{1,10})/?$`);
9
+ function post(channel, id, options) {
10
+ return {
11
+ platform: "telegram",
12
+ kind: "post",
13
+ url: `https://t.me/${channel}/${id}`,
14
+ id: `${channel}/${id}`,
15
+ variant: "iframe",
16
+ options
17
+ };
18
+ }
19
+ const telegramMatcher = {
20
+ platform: "telegram",
21
+ name: "Telegram",
22
+ shapes: ["post iframe"],
23
+ match(url) {
24
+ if (!HOSTS.has(url.host)) return null;
25
+ const [, channel, id] = POST_PATH.exec(url.path) ?? [];
26
+ if (channel === void 0 || id === void 0) return null;
27
+ const options = {};
28
+ if (url.query.has("single")) options.single = true;
29
+ const comment = url.query.get("comment");
30
+ if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
31
+ return post(channel, id, options);
32
+ }
33
+ };
34
+ export { CHANNEL, post, telegramMatcher };
@@ -0,0 +1,34 @@
1
+ import { rebuildsAs } from "../html.js";
2
+ import { tenorFrame } from "../frames.js";
3
+ // src/parser/matchers/tenor.ts
4
+ const HOSTS = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
5
+ const ID = "(\\d{1,20})";
6
+ const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID}/?$`);
7
+ const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]]]);
8
+ function gif(id) {
9
+ return {
10
+ platform: "tenor",
11
+ kind: "video",
12
+ url: `https://tenor.com/view/${id}`,
13
+ id,
14
+ variant: "iframe"
15
+ };
16
+ }
17
+ function idOf(url) {
18
+ return url && HOSTS.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
19
+ }
20
+ const tenorMatcher = {
21
+ platform: "tenor",
22
+ name: "Tenor",
23
+ shapes: ["video iframe"],
24
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
25
+ match(url) {
26
+ const id = idOf(url);
27
+ return id === void 0 ? null : {
28
+ ...gif(id),
29
+ options: {}
30
+ };
31
+ },
32
+ ownsFrame: tenorFrame
33
+ };
34
+ export { FALLBACK, ID, gif, tenorMatcher };
@@ -0,0 +1,36 @@
1
+ import { rebuildsAs } from "../html.js";
2
+ // src/parser/matchers/threads.ts
3
+ const HOSTS = /* @__PURE__ */ new Set([
4
+ "threads.com",
5
+ "www.threads.com",
6
+ "threads.net",
7
+ "www.threads.net"
8
+ ]);
9
+ const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
10
+ const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
11
+ function post(url) {
12
+ if (!url || !HOSTS.has(url.host)) return null;
13
+ const [, code] = POST_PATH.exec(url.path) ?? [];
14
+ if (code === void 0) return null;
15
+ return {
16
+ platform: "threads",
17
+ kind: "post",
18
+ url: `https://www.threads.com/t/${code}`,
19
+ id: code,
20
+ variant: "sdk"
21
+ };
22
+ }
23
+ const threadsMatcher = {
24
+ platform: "threads",
25
+ name: "Threads",
26
+ shapes: ["post sdk"],
27
+ trustsFallback: (html) => rebuildsAs(html, FALLBACK),
28
+ match(url) {
29
+ const found = post(url);
30
+ return found && {
31
+ ...found,
32
+ options: {}
33
+ };
34
+ }
35
+ };
36
+ export { FALLBACK, post, threadsMatcher };
@@ -0,0 +1,25 @@
1
+ import { TIKTOK_HOSTS, tiktokFrame } from "../frames.js";
2
+ // src/parser/matchers/tiktok.ts
3
+ const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
4
+ function video(id, user = "", options = {}) {
5
+ return {
6
+ platform: "tiktok",
7
+ kind: "video",
8
+ url: `https://www.tiktok.com/@${user}/video/${id}`,
9
+ id,
10
+ variant: "iframe",
11
+ options
12
+ };
13
+ }
14
+ const tiktokMatcher = {
15
+ platform: "tiktok",
16
+ name: "TikTok",
17
+ shapes: ["video iframe"],
18
+ match(url) {
19
+ if (!TIKTOK_HOSTS.has(url.host)) return null;
20
+ const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
21
+ return user === void 0 || id === void 0 ? null : video(id, user);
22
+ },
23
+ ownsFrame: tiktokFrame
24
+ };
25
+ export { VIDEO_PATH, tiktokMatcher, video };
@@ -0,0 +1,34 @@
1
+ import { truthsocialFrame } from "../frames.js";
2
+ // src/parser/matchers/truthsocial.ts
3
+ const HOSTS = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
4
+ const USER = "(@[A-Za-z0-9_.-]{1,64})";
5
+ const ID = "(\\d{1,25})";
6
+ const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
7
+ function post(user, id) {
8
+ return {
9
+ platform: "truthsocial",
10
+ kind: "post",
11
+ url: `https://truthsocial.com/${user}/posts/${id}`,
12
+ id,
13
+ variant: "iframe"
14
+ };
15
+ }
16
+ function fromUrl(url) {
17
+ if (!url || !HOSTS.has(url.host)) return null;
18
+ const [, user, id] = POST_PATH.exec(url.path) ?? [];
19
+ return user === void 0 || id === void 0 ? null : post(user, id);
20
+ }
21
+ const truthsocialMatcher = {
22
+ platform: "truthsocial",
23
+ name: "Truth Social",
24
+ shapes: ["post iframe"],
25
+ match(url) {
26
+ const found = fromUrl(url);
27
+ return found && {
28
+ ...found,
29
+ options: {}
30
+ };
31
+ },
32
+ ownsFrame: truthsocialFrame
33
+ };
34
+ export { ID, USER, post, truthsocialMatcher };
@@ -0,0 +1,51 @@
1
+ // src/parser/matchers/tumblr.ts
2
+ const BLOG = "([a-z0-9-]{1,32})";
3
+ const POST = "(\\d{1,20})";
4
+ const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
5
+ const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
6
+ const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
7
+ const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
8
+ const NOT_BLOGS = /* @__PURE__ */ new Set([
9
+ "dashboard",
10
+ "explore",
11
+ "tagged",
12
+ "search",
13
+ "settings",
14
+ "blog",
15
+ "www",
16
+ "assets",
17
+ "embed",
18
+ "api",
19
+ "help"
20
+ ]);
21
+ function fromUrl(url) {
22
+ if (!url) return null;
23
+ let blog;
24
+ let id;
25
+ if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
26
+ else {
27
+ [, blog] = BLOG_HOST.exec(url.host) ?? [];
28
+ [, id] = BLOG_PATH.exec(url.path) ?? [];
29
+ }
30
+ if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
31
+ return {
32
+ platform: "tumblr",
33
+ kind: "post",
34
+ url: `https://www.tumblr.com/${blog}/${id}`,
35
+ id,
36
+ variant: "iframe"
37
+ };
38
+ }
39
+ const tumblrMatcher = {
40
+ platform: "tumblr",
41
+ name: "Tumblr",
42
+ shapes: ["post iframe"],
43
+ match(url) {
44
+ const found = fromUrl(url);
45
+ return found && {
46
+ ...found,
47
+ options: {}
48
+ };
49
+ }
50
+ };
51
+ export { BLOG, POST, fromUrl, tumblrMatcher };
@@ -0,0 +1,90 @@
1
+ import { twitchFrame } from "../frames.js";
2
+ // src/parser/matchers/twitch.ts
3
+ const HOSTS = /* @__PURE__ */ new Set([
4
+ "twitch.tv",
5
+ "www.twitch.tv",
6
+ "m.twitch.tv"
7
+ ]);
8
+ const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
9
+ const VIDEO = /^v?(\d{1,12})$/;
10
+ const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
11
+ const CLIP = /^[A-Za-z0-9_-]{6,100}$/;
12
+ const TIME = /^(?:\d+h)?(?:\d+m)?(?:\d+s)?$/;
13
+ const RESERVED = /* @__PURE__ */ new Set([
14
+ "directory",
15
+ "videos",
16
+ "collections",
17
+ "settings",
18
+ "subscriptions",
19
+ "inventory",
20
+ "wallet",
21
+ "drops",
22
+ "search",
23
+ "downloads",
24
+ "jobs",
25
+ "turbo",
26
+ "p",
27
+ "login",
28
+ "signup"
29
+ ]);
30
+ function target(path, id) {
31
+ return {
32
+ platform: "twitch",
33
+ kind: "video",
34
+ url: path,
35
+ id,
36
+ variant: "iframe"
37
+ };
38
+ }
39
+ const channel = (name) => target(`https://www.twitch.tv/${name.toLowerCase()}`, name.toLowerCase());
40
+ const vod = (id) => target(`https://www.twitch.tv/videos/${id}`, id);
41
+ const collection = (id) => target(`https://www.twitch.tv/collections/${id}`, id);
42
+ const clip = (slug) => target(`https://clips.twitch.tv/${slug}`, slug);
43
+ function fromPage(url) {
44
+ if (url.host === "clips.twitch.tv") {
45
+ const slug = url.path.replace(/^\/|\/$/g, "");
46
+ return CLIP.test(slug) ? {
47
+ found: clip(slug),
48
+ options: {}
49
+ } : null;
50
+ }
51
+ if (!HOSTS.has(url.host)) return null;
52
+ const parts = url.path.replace(/^\/|\/$/g, "").split("/");
53
+ const [first = "", second, third] = parts;
54
+ if (parts.length === 2 && first === "videos") {
55
+ const [, id] = VIDEO.exec(second ?? "") ?? [];
56
+ if (id === void 0) return null;
57
+ const time = url.query.get("t");
58
+ return {
59
+ found: vod(id),
60
+ options: time !== void 0 && TIME.test(time) && time ? { time } : {}
61
+ };
62
+ }
63
+ if (parts.length === 2 && first === "collections") return COLLECTION.test(second ?? "") ? {
64
+ found: collection(second ?? ""),
65
+ options: {}
66
+ } : null;
67
+ if (parts.length === 3 && second === "clip") return CHANNEL.test(first) && CLIP.test(third ?? "") ? {
68
+ found: clip(third ?? ""),
69
+ options: {}
70
+ } : null;
71
+ if (parts.length === 1 && CHANNEL.test(first) && !RESERVED.has(first.toLowerCase())) return {
72
+ found: channel(first),
73
+ options: {}
74
+ };
75
+ return null;
76
+ }
77
+ const twitchMatcher = {
78
+ platform: "twitch",
79
+ name: "Twitch",
80
+ shapes: ["video iframe"],
81
+ match(url) {
82
+ const page = fromPage(url);
83
+ return page && {
84
+ ...page.found,
85
+ options: page.options
86
+ };
87
+ },
88
+ ownsFrame: twitchFrame
89
+ };
90
+ export { CHANNEL, CLIP, COLLECTION, VIDEO, channel, clip, collection, twitchMatcher, vod };
@@ -0,0 +1,71 @@
1
+ import { coerce } from "../url.js";
2
+ import { vimeoFrame } from "../frames.js";
3
+ // src/parser/matchers/vimeo.ts
4
+ const HOSTS = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
5
+ const VIDEO = "(\\d{1,12})";
6
+ const HASH = "([0-9a-f]{6,20})";
7
+ const PAGE_PATHS = [
8
+ new RegExp(`^/${VIDEO}(?:/${HASH})?/?$`),
9
+ new RegExp(`^/channels/[A-Za-z0-9_-]{1,64}/${VIDEO}/?$`),
10
+ new RegExp(`^/groups/[A-Za-z0-9_-]{1,64}/videos/${VIDEO}/?$`),
11
+ new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
12
+ ];
13
+ const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
14
+ const DROPPED = /* @__PURE__ */ new Set([
15
+ "h",
16
+ "app_id",
17
+ "player_id"
18
+ ]);
19
+ const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
20
+ function video(id, hash) {
21
+ return {
22
+ platform: "vimeo",
23
+ kind: "video",
24
+ url: `https://vimeo.com/${id}${hash ? `/${hash}` : ""}`,
25
+ id,
26
+ variant: "iframe"
27
+ };
28
+ }
29
+ function start(url) {
30
+ const [, time] = START.exec(url.fragment ?? "") ?? [];
31
+ return time ? { t: time } : {};
32
+ }
33
+ function fromPage(url) {
34
+ if (!url || !HOSTS.has(url.host)) return null;
35
+ for (const path of PAGE_PATHS) {
36
+ const [, id, hash] = path.exec(url.path) ?? [];
37
+ if (id !== void 0) return video(id, hash);
38
+ }
39
+ return null;
40
+ }
41
+ function fromPlayer(url) {
42
+ if (url?.host !== "player.vimeo.com") return null;
43
+ const [, id] = PLAYER_PATH.exec(url.path) ?? [];
44
+ if (id === void 0) return null;
45
+ const hash = url.query.get("h");
46
+ if (hash !== void 0 && !new RegExp(`^${HASH}$`).test(hash)) return null;
47
+ const options = Object.fromEntries([...url.query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
48
+ return {
49
+ ...video(id, hash),
50
+ options: {
51
+ ...options,
52
+ ...start(url)
53
+ }
54
+ };
55
+ }
56
+ const vimeoMatcher = {
57
+ platform: "vimeo",
58
+ name: "Vimeo",
59
+ shapes: ["video iframe"],
60
+ match(url) {
61
+ const player = fromPlayer(url);
62
+ if (player) return player;
63
+ const page = fromPage(url);
64
+ return page && {
65
+ ...page,
66
+ options: start(url)
67
+ };
68
+ },
69
+ ownsFrame: vimeoFrame
70
+ };
71
+ export { HOSTS, fromPage, fromPlayer, vimeoMatcher };
@@ -0,0 +1,50 @@
1
+ import { descendants, parseHtml, rebuildsAs } from "../html.js";
2
+ import { parseUrl } from "../url.js";
3
+ // src/parser/matchers/x.ts
4
+ const HOSTS = /* @__PURE__ */ new Set([
5
+ "x.com",
6
+ "www.x.com",
7
+ "mobile.x.com",
8
+ "twitter.com",
9
+ "www.twitter.com",
10
+ "mobile.twitter.com"
11
+ ]);
12
+ const STATUS_PATH = /^\/([A-Za-z0-9_]{1,15})\/status\/(\d{1,20})\/?$/;
13
+ const LINK_PATH = /^\/(?:([A-Za-z0-9_]{1,15})|i\/web)\/status\/(\d{1,20})(?:\/(?:photo|video)\/[1-4])?\/?$/;
14
+ const FALLBACK = /* @__PURE__ */ new Map([
15
+ ["p", ["lang", "dir"]],
16
+ ["a", ["href"]],
17
+ ["br", []]
18
+ ]);
19
+ function post(url, path = STATUS_PATH) {
20
+ if (!url || !HOSTS.has(url.host)) return null;
21
+ const [, user = "i", id] = path.exec(url.path) ?? [];
22
+ if (id === void 0) return null;
23
+ return {
24
+ platform: "x",
25
+ kind: "post",
26
+ url: `https://x.com/${user}/status/${id}`,
27
+ id,
28
+ variant: "sdk"
29
+ };
30
+ }
31
+ function lastStatus(nodes) {
32
+ return descendants(nodes).reverse().map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((found) => found !== null) ?? null;
33
+ }
34
+ function fallbackNamesPost(html, id) {
35
+ return lastStatus(parseHtml(html) ?? [])?.id === id;
36
+ }
37
+ const xMatcher = {
38
+ platform: "x",
39
+ name: "X",
40
+ shapes: ["post sdk"],
41
+ trustsFallback: (html, embed) => rebuildsAs(html, FALLBACK) && fallbackNamesPost(html, embed.id),
42
+ match(url) {
43
+ const status = post(url, LINK_PATH);
44
+ return status && {
45
+ ...status,
46
+ options: {}
47
+ };
48
+ }
49
+ };
50
+ export { FALLBACK, lastStatus, xMatcher };