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.
- package/README.md +3 -3
- package/dist/components/apple-embed.d.ts +2 -2
- package/dist/components/apple-embed.js +8 -30
- package/dist/components/bluesky-embed.d.ts +1 -1
- package/dist/components/bluesky-embed.js +6 -17
- package/dist/components/dailymotion-embed.d.ts +1 -1
- package/dist/components/dailymotion-embed.js +11 -21
- package/dist/components/facebook-embed.d.ts +1 -1
- package/dist/components/facebook-embed.js +14 -35
- package/dist/components/flickr-embed.d.ts +1 -1
- package/dist/components/flickr-embed.js +10 -21
- package/dist/components/giphy-embed.d.ts +1 -1
- package/dist/components/giphy-embed.js +5 -16
- package/dist/components/iframe-embed.js +15 -1
- package/dist/components/imgur-embed.d.ts +1 -1
- package/dist/components/imgur-embed.js +6 -17
- package/dist/components/instagram-embed.d.ts +1 -1
- package/dist/components/instagram-embed.js +6 -20
- package/dist/components/kick-embed.d.ts +1 -1
- package/dist/components/kick-embed.js +6 -19
- package/dist/components/linkedin-embed.d.ts +1 -1
- package/dist/components/linkedin-embed.js +6 -17
- package/dist/components/pinterest-embed.d.ts +1 -1
- package/dist/components/pinterest-embed.js +6 -20
- package/dist/components/reddit-embed.d.ts +1 -1
- package/dist/components/reddit-embed.js +13 -23
- package/dist/components/rumble-embed.d.ts +1 -1
- package/dist/components/rumble-embed.js +5 -16
- package/dist/components/script-embed.js +14 -1
- package/dist/components/snapchat-embed.d.ts +1 -1
- package/dist/components/snapchat-embed.js +5 -16
- package/dist/components/soundcloud-embed.d.ts +1 -1
- package/dist/components/soundcloud-embed.js +16 -27
- package/dist/components/spotify-embed.d.ts +1 -1
- package/dist/components/spotify-embed.js +6 -16
- package/dist/components/strava-embed.d.ts +1 -1
- package/dist/components/strava-embed.js +10 -20
- package/dist/components/streamable-embed.d.ts +1 -1
- package/dist/components/streamable-embed.js +12 -22
- package/dist/components/telegram-embed.d.ts +1 -1
- package/dist/components/telegram-embed.js +11 -21
- package/dist/components/tenor-embed.d.ts +1 -1
- package/dist/components/tenor-embed.js +5 -16
- package/dist/components/threads-embed.d.ts +1 -1
- package/dist/components/threads-embed.js +6 -20
- package/dist/components/tiktok-embed.d.ts +1 -1
- package/dist/components/tiktok-embed.js +21 -31
- package/dist/components/truthsocial-embed.d.ts +1 -1
- package/dist/components/truthsocial-embed.js +5 -16
- package/dist/components/tumblr-embed.d.ts +1 -1
- package/dist/components/tumblr-embed.js +5 -16
- package/dist/components/twitch-embed.d.ts +1 -1
- package/dist/components/twitch-embed.js +10 -20
- package/dist/components/use-plan.js +20 -0
- package/dist/components/vimeo-embed.d.ts +1 -1
- package/dist/components/vimeo-embed.js +25 -35
- package/dist/components/x-embed.d.ts +1 -1
- package/dist/components/x-embed.js +13 -27
- package/dist/components/youtube-embed.d.ts +1 -1
- package/dist/components/youtube-embed.js +28 -38
- package/dist/element.js +1 -1
- package/dist/parser/matchers/applemusic.js +33 -0
- package/dist/parser/matchers/applepodcasts.js +32 -0
- package/dist/parser/matchers/bluesky.js +41 -0
- package/dist/parser/matchers/dailymotion.js +47 -0
- package/dist/parser/matchers/facebook.js +118 -0
- package/dist/parser/matchers/flickr.js +100 -0
- package/dist/parser/matchers/giphy.js +38 -0
- package/dist/parser/matchers/imgur.js +76 -0
- package/dist/parser/matchers/instagram.js +43 -0
- package/dist/parser/matchers/kick.js +48 -0
- package/dist/parser/matchers/linkedin.js +31 -0
- package/dist/parser/matchers/pinterest.js +32 -0
- package/dist/parser/matchers/reddit.js +43 -0
- package/dist/parser/matchers/rumble.js +32 -0
- package/dist/parser/matchers/snapchat.js +60 -0
- package/dist/parser/matchers/soundcloud.js +87 -0
- package/dist/parser/matchers/spotify.js +39 -0
- package/dist/parser/matchers/strava.js +31 -0
- package/dist/parser/matchers/streamable.js +59 -0
- package/dist/parser/matchers/telegram.js +34 -0
- package/dist/parser/matchers/tenor.js +34 -0
- package/dist/parser/matchers/threads.js +36 -0
- package/dist/parser/matchers/tiktok.js +25 -0
- package/dist/parser/matchers/truthsocial.js +34 -0
- package/dist/parser/matchers/tumblr.js +51 -0
- package/dist/parser/matchers/twitch.js +90 -0
- package/dist/parser/matchers/vimeo.js +71 -0
- package/dist/parser/matchers/x.js +50 -0
- package/dist/parser/matchers/youtube.js +123 -0
- package/dist/parser/platform.d.ts +10 -4
- package/dist/parser/platforms/applemusic.js +4 -30
- package/dist/parser/platforms/applepodcasts.js +4 -29
- package/dist/parser/platforms/bluesky.js +4 -38
- package/dist/parser/platforms/dailymotion.js +4 -44
- package/dist/parser/platforms/facebook.js +5 -115
- package/dist/parser/platforms/flickr.js +5 -98
- package/dist/parser/platforms/giphy.js +4 -35
- package/dist/parser/platforms/imgur.js +4 -73
- package/dist/parser/platforms/instagram.js +4 -40
- package/dist/parser/platforms/kick.js +4 -45
- package/dist/parser/platforms/linkedin.js +4 -28
- package/dist/parser/platforms/pinterest.js +4 -29
- package/dist/parser/platforms/reddit.js +3 -40
- package/dist/parser/platforms/rumble.js +3 -29
- package/dist/parser/platforms/snapchat.js +3 -57
- package/dist/parser/platforms/soundcloud.js +4 -84
- package/dist/parser/platforms/spotify.js +4 -36
- package/dist/parser/platforms/strava.js +3 -28
- package/dist/parser/platforms/streamable.js +3 -56
- package/dist/parser/platforms/telegram.js +3 -31
- package/dist/parser/platforms/tenor.js +5 -32
- package/dist/parser/platforms/threads.js +4 -33
- package/dist/parser/platforms/tiktok.js +4 -22
- package/dist/parser/platforms/truthsocial.js +3 -31
- package/dist/parser/platforms/tumblr.js +3 -48
- package/dist/parser/platforms/twitch.js +4 -87
- package/dist/parser/platforms/vimeo.js +4 -68
- package/dist/parser/platforms/x.js +6 -46
- package/dist/parser/platforms/youtube.js +5 -120
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { rebuildsAs } from "../html.js";
|
|
2
|
+
import { facebookFrame } from "../frames.js";
|
|
3
|
+
// src/parser/matchers/facebook.ts
|
|
4
|
+
const HOSTS = /* @__PURE__ */ new Set([
|
|
5
|
+
"facebook.com",
|
|
6
|
+
"www.facebook.com",
|
|
7
|
+
"web.facebook.com",
|
|
8
|
+
"m.facebook.com"
|
|
9
|
+
]);
|
|
10
|
+
const BASE = "https://www.facebook.com";
|
|
11
|
+
const NAME = "[A-Za-z0-9.\\-]{1,80}";
|
|
12
|
+
const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
|
|
13
|
+
const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
14
|
+
const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.\\-]{1,80})/(\\d{1,25})/?$`);
|
|
15
|
+
const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
16
|
+
const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
|
|
17
|
+
const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
|
|
18
|
+
const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
19
|
+
"/photo.php",
|
|
20
|
+
"/photo/",
|
|
21
|
+
"/photo"
|
|
22
|
+
]);
|
|
23
|
+
const STORY_ID = new RegExp(`^${POST_ID}$`);
|
|
24
|
+
const NUMERIC_ID = /^\d{1,25}$/;
|
|
25
|
+
const PARSE_IGNORE = {
|
|
26
|
+
name: "class",
|
|
27
|
+
value: /^fb-xfbml-parse-ignore$/
|
|
28
|
+
};
|
|
29
|
+
const FALLBACK = /* @__PURE__ */ new Map([
|
|
30
|
+
["div", [PARSE_IGNORE]],
|
|
31
|
+
["blockquote", ["cite", PARSE_IGNORE]],
|
|
32
|
+
["a", ["href"]],
|
|
33
|
+
["p", []]
|
|
34
|
+
]);
|
|
35
|
+
function target(url) {
|
|
36
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
37
|
+
const { path, query } = url;
|
|
38
|
+
const [, name, postId] = POSTS_PATH.exec(path) ?? [];
|
|
39
|
+
if (name !== void 0 && postId !== void 0) return {
|
|
40
|
+
kind: "post",
|
|
41
|
+
id: postId,
|
|
42
|
+
url: `${BASE}/${name}/posts/${postId}`
|
|
43
|
+
};
|
|
44
|
+
if (STORY_PATHS.has(path)) {
|
|
45
|
+
const storyId = query.get("story_fbid");
|
|
46
|
+
if (storyId === void 0 || !STORY_ID.test(storyId)) return null;
|
|
47
|
+
const owner = query.get("id");
|
|
48
|
+
const ownerQuery = owner !== void 0 && NUMERIC_ID.test(owner) ? `&id=${owner}` : "";
|
|
49
|
+
return {
|
|
50
|
+
kind: "post",
|
|
51
|
+
id: storyId,
|
|
52
|
+
url: `${BASE}${path}?story_fbid=${storyId}${ownerQuery}`
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (PHOTO_PATHS.has(path)) {
|
|
56
|
+
const fbid = query.get("fbid");
|
|
57
|
+
if (fbid === void 0 || !NUMERIC_ID.test(fbid)) return null;
|
|
58
|
+
return {
|
|
59
|
+
kind: "post",
|
|
60
|
+
id: fbid,
|
|
61
|
+
url: `${BASE}${path}?fbid=${fbid}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const [, owner, album, photoId] = PHOTOS_PATH.exec(path) ?? [];
|
|
65
|
+
if (owner !== void 0 && album !== void 0 && photoId !== void 0) return {
|
|
66
|
+
kind: "post",
|
|
67
|
+
id: photoId,
|
|
68
|
+
url: `${BASE}/${owner}/photos/${album}/${photoId}/`
|
|
69
|
+
};
|
|
70
|
+
const [, page, videoId] = VIDEOS_PATH.exec(path) ?? [];
|
|
71
|
+
if (page !== void 0 && videoId !== void 0) return {
|
|
72
|
+
kind: "video",
|
|
73
|
+
id: videoId,
|
|
74
|
+
url: `${BASE}/${page}/videos/${videoId}/`
|
|
75
|
+
};
|
|
76
|
+
if (path === "/watch" || path === "/watch/" || path === "/video.php") {
|
|
77
|
+
const v = query.get("v");
|
|
78
|
+
if (v === void 0 || !NUMERIC_ID.test(v)) return null;
|
|
79
|
+
return {
|
|
80
|
+
kind: "video",
|
|
81
|
+
id: v,
|
|
82
|
+
url: `${BASE}${path === "/video.php" ? path : "/watch/"}?v=${v}`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const [, reelId] = REEL_PATH.exec(path) ?? [];
|
|
86
|
+
if (reelId !== void 0) return {
|
|
87
|
+
kind: "video",
|
|
88
|
+
id: reelId,
|
|
89
|
+
url: `${BASE}/reel/${reelId}`
|
|
90
|
+
};
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function embed(found, kind, variant, options) {
|
|
94
|
+
return {
|
|
95
|
+
platform: "facebook",
|
|
96
|
+
kind,
|
|
97
|
+
url: found.url,
|
|
98
|
+
id: found.id,
|
|
99
|
+
variant,
|
|
100
|
+
options
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const facebookMatcher = {
|
|
104
|
+
platform: "facebook",
|
|
105
|
+
name: "Facebook",
|
|
106
|
+
shapes: [
|
|
107
|
+
"post sdk",
|
|
108
|
+
"video sdk",
|
|
109
|
+
"video iframe"
|
|
110
|
+
],
|
|
111
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
112
|
+
match(url) {
|
|
113
|
+
const found = target(url);
|
|
114
|
+
return found && embed(found, found.kind, "sdk", {});
|
|
115
|
+
},
|
|
116
|
+
ownsFrame: facebookFrame
|
|
117
|
+
};
|
|
118
|
+
export { FALLBACK, embed, facebookMatcher, target };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { rebuildsAs } from "../html.js";
|
|
2
|
+
// src/parser/matchers/flickr.ts
|
|
3
|
+
const HOSTS = /* @__PURE__ */ new Set(["flickr.com", "www.flickr.com"]);
|
|
4
|
+
const USER = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9@_.-]{1,64})";
|
|
5
|
+
const ID = "(\\d{1,20})";
|
|
6
|
+
const PHOTO_PATH = new RegExp(`^/photos/${USER}/${ID}(?:/in/[A-Za-z0-9_@./-]{1,200})?/?$`);
|
|
7
|
+
const ALBUM_PATH = new RegExp(`^/photos/${USER}/(?:albums|sets)/${ID}/?$`);
|
|
8
|
+
const SHORT_PATH = /^\/p\/([1-9a-km-zA-HJ-NP-Z]{1,12})$/;
|
|
9
|
+
const ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
10
|
+
const IMAGE_SRC = /^https:\/\/(?:live|farm\d{1,3})\.staticflickr\.com\//;
|
|
11
|
+
const FALLBACK = /* @__PURE__ */ new Map([["a", [{
|
|
12
|
+
name: "href",
|
|
13
|
+
value: /^https:\/\/(?:www\.)?flickr\.com\//
|
|
14
|
+
}]], ["img", [
|
|
15
|
+
{
|
|
16
|
+
name: "src",
|
|
17
|
+
value: IMAGE_SRC
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "width",
|
|
21
|
+
value: /^\d{1,6}$/
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "height",
|
|
25
|
+
value: /^\d{1,6}$/
|
|
26
|
+
},
|
|
27
|
+
"alt"
|
|
28
|
+
]]]);
|
|
29
|
+
/** The photo id of a `flic.kr/p/{code}` code, or `null` for an empty code or a character outside Flickr's base-58 alphabet. */
|
|
30
|
+
function decodeFlickrCode(code) {
|
|
31
|
+
if (code === "") return null;
|
|
32
|
+
let id = 0n;
|
|
33
|
+
for (const character of code) {
|
|
34
|
+
const digit = ALPHABET.indexOf(character);
|
|
35
|
+
if (digit === -1) return null;
|
|
36
|
+
id = id * 58n + BigInt(digit);
|
|
37
|
+
}
|
|
38
|
+
return id.toString();
|
|
39
|
+
}
|
|
40
|
+
function encodeFlickrCode(id) {
|
|
41
|
+
let rest = BigInt(id);
|
|
42
|
+
let code = "";
|
|
43
|
+
while (rest > 0n) {
|
|
44
|
+
code = ALPHABET.charAt(Number(rest % 58n)) + code;
|
|
45
|
+
rest /= 58n;
|
|
46
|
+
}
|
|
47
|
+
return code;
|
|
48
|
+
}
|
|
49
|
+
function photo(user, id) {
|
|
50
|
+
return {
|
|
51
|
+
platform: "flickr",
|
|
52
|
+
kind: "post",
|
|
53
|
+
url: `https://www.flickr.com/photos/${user}/${id}/`,
|
|
54
|
+
id,
|
|
55
|
+
variant: "iframe"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function album(user, id) {
|
|
59
|
+
return {
|
|
60
|
+
platform: "flickr",
|
|
61
|
+
kind: "post",
|
|
62
|
+
url: `https://www.flickr.com/photos/${user}/albums/${id}`,
|
|
63
|
+
id,
|
|
64
|
+
variant: "iframe"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function fromLongUrl(url) {
|
|
68
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
69
|
+
const [, albumUser, albumId] = ALBUM_PATH.exec(url.path) ?? [];
|
|
70
|
+
if (albumUser !== void 0 && albumId !== void 0) return album(albumUser, albumId);
|
|
71
|
+
const [, user, id] = PHOTO_PATH.exec(url.path) ?? [];
|
|
72
|
+
return user === void 0 || id === void 0 ? null : photo(user, id);
|
|
73
|
+
}
|
|
74
|
+
function fromShortUrl(url) {
|
|
75
|
+
if (url.host !== "flic.kr") return null;
|
|
76
|
+
const [, code] = SHORT_PATH.exec(url.path) ?? [];
|
|
77
|
+
const id = code === void 0 ? null : decodeFlickrCode(code);
|
|
78
|
+
if (code === void 0 || id === null || encodeFlickrCode(id) !== code) return null;
|
|
79
|
+
return {
|
|
80
|
+
platform: "flickr",
|
|
81
|
+
kind: "post",
|
|
82
|
+
url: `https://flic.kr/p/${code}`,
|
|
83
|
+
id,
|
|
84
|
+
variant: "iframe"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const flickrMatcher = {
|
|
88
|
+
platform: "flickr",
|
|
89
|
+
name: "Flickr",
|
|
90
|
+
shapes: ["post iframe"],
|
|
91
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
92
|
+
match(url) {
|
|
93
|
+
const found = fromLongUrl(url) ?? fromShortUrl(url);
|
|
94
|
+
return found && {
|
|
95
|
+
...found,
|
|
96
|
+
options: {}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export { FALLBACK, IMAGE_SRC, decodeFlickrCode, flickrMatcher, fromLongUrl };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { GIPHY_PAGE_HOSTS, giphyFrame } from "../frames.js";
|
|
2
|
+
// src/parser/matchers/giphy.ts
|
|
3
|
+
const ID = "([A-Za-z0-9]{6,40})";
|
|
4
|
+
const PAGE_PATH = new RegExp(`^/(?:gifs|stickers)/(?:[A-Za-z0-9-]{0,200}-)?${ID}/?$`);
|
|
5
|
+
const EMBED_PATH = new RegExp(`^/embed/${ID}/?$`);
|
|
6
|
+
const MEDIA_HOST = /^(?:media\d?|i)\.giphy\.com$/;
|
|
7
|
+
const FILE_TYPE = "\\.(?:gif|webp|mp4)";
|
|
8
|
+
const MEDIA_PATH = new RegExp(`^/media/(?:v1\\.[A-Za-z0-9_-]{1,500}/)?${ID}/[A-Za-z0-9_-]{1,40}${FILE_TYPE}$`);
|
|
9
|
+
const SHORT_MEDIA_PATH = new RegExp(`^/${ID}${FILE_TYPE}$`);
|
|
10
|
+
function gif(id) {
|
|
11
|
+
return {
|
|
12
|
+
platform: "giphy",
|
|
13
|
+
kind: "video",
|
|
14
|
+
url: `https://giphy.com/gifs/${id}`,
|
|
15
|
+
id,
|
|
16
|
+
variant: "iframe"
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function idOf(url) {
|
|
20
|
+
if (!url) return void 0;
|
|
21
|
+
if (GIPHY_PAGE_HOSTS.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH.exec(url.path))?.[1];
|
|
22
|
+
if (!MEDIA_HOST.test(url.host)) return void 0;
|
|
23
|
+
return (MEDIA_PATH.exec(url.path) ?? (url.host === "i.giphy.com" ? SHORT_MEDIA_PATH.exec(url.path) : null))?.[1];
|
|
24
|
+
}
|
|
25
|
+
const giphyMatcher = {
|
|
26
|
+
platform: "giphy",
|
|
27
|
+
name: "Giphy",
|
|
28
|
+
shapes: ["video iframe"],
|
|
29
|
+
match(url) {
|
|
30
|
+
const id = idOf(url);
|
|
31
|
+
return id === void 0 ? null : {
|
|
32
|
+
...gif(id),
|
|
33
|
+
options: {}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
ownsFrame: giphyFrame
|
|
37
|
+
};
|
|
38
|
+
export { EMBED_PATH, PAGE_PATH, gif, giphyMatcher };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { rebuildsAs } from "../html.js";
|
|
2
|
+
// src/parser/matchers/imgur.ts
|
|
3
|
+
const HOSTS = /* @__PURE__ */ new Set([
|
|
4
|
+
"imgur.com",
|
|
5
|
+
"www.imgur.com",
|
|
6
|
+
"m.imgur.com"
|
|
7
|
+
]);
|
|
8
|
+
const HASH = "([A-Za-z0-9]{5,7})";
|
|
9
|
+
const ALBUM_PATH = new RegExp(`^/a/${HASH}/?$`);
|
|
10
|
+
const GALLERY_PATH = new RegExp(`^/gallery/(?:[A-Za-z0-9-]{1,200}-)?${HASH}/?$`);
|
|
11
|
+
const IMAGE_PATH = new RegExp(`^/${HASH}/?$`);
|
|
12
|
+
const FILE_PATH = new RegExp(`^/${HASH}\\.(?:jpe?g|png|gif|gifv|mp4|webp)$`);
|
|
13
|
+
const NOT_IMAGES = /* @__PURE__ */ new Set([
|
|
14
|
+
"about",
|
|
15
|
+
"apps",
|
|
16
|
+
"blog",
|
|
17
|
+
"help",
|
|
18
|
+
"jobs",
|
|
19
|
+
"login",
|
|
20
|
+
"press",
|
|
21
|
+
"privacy",
|
|
22
|
+
"random",
|
|
23
|
+
"search",
|
|
24
|
+
"signin",
|
|
25
|
+
"signup",
|
|
26
|
+
"terms",
|
|
27
|
+
"tools",
|
|
28
|
+
"upload",
|
|
29
|
+
"account",
|
|
30
|
+
"contact",
|
|
31
|
+
"emerald",
|
|
32
|
+
"explore",
|
|
33
|
+
"gallery",
|
|
34
|
+
"hot",
|
|
35
|
+
"new",
|
|
36
|
+
"rules",
|
|
37
|
+
"user"
|
|
38
|
+
]);
|
|
39
|
+
const FALLBACK = /* @__PURE__ */ new Map([["a", [{
|
|
40
|
+
name: "href",
|
|
41
|
+
value: /^https:\/\/(?:www\.)?imgur\.com\//
|
|
42
|
+
}]]]);
|
|
43
|
+
function post(id) {
|
|
44
|
+
return {
|
|
45
|
+
platform: "imgur",
|
|
46
|
+
kind: "post",
|
|
47
|
+
url: `https://imgur.com/${id}`,
|
|
48
|
+
id,
|
|
49
|
+
variant: "iframe"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function image(hash) {
|
|
53
|
+
return hash === void 0 || NOT_IMAGES.has(hash.toLowerCase()) ? void 0 : hash;
|
|
54
|
+
}
|
|
55
|
+
function idOf(url) {
|
|
56
|
+
if (!url) return void 0;
|
|
57
|
+
if (url.host === "i.imgur.com") return image(FILE_PATH.exec(url.path)?.[1]);
|
|
58
|
+
if (!HOSTS.has(url.host)) return void 0;
|
|
59
|
+
const album = (ALBUM_PATH.exec(url.path) ?? GALLERY_PATH.exec(url.path))?.[1];
|
|
60
|
+
if (album !== void 0) return `a/${album}`;
|
|
61
|
+
return image(IMAGE_PATH.exec(url.path)?.[1]);
|
|
62
|
+
}
|
|
63
|
+
const imgurMatcher = {
|
|
64
|
+
platform: "imgur",
|
|
65
|
+
name: "Imgur",
|
|
66
|
+
shapes: ["post iframe"],
|
|
67
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
68
|
+
match(url) {
|
|
69
|
+
const id = idOf(url);
|
|
70
|
+
return id === void 0 ? null : {
|
|
71
|
+
...post(id),
|
|
72
|
+
options: {}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
export { FALLBACK, HASH, image, imgurMatcher, post };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { rebuildsAs } from "../html.js";
|
|
2
|
+
// src/parser/matchers/instagram.ts
|
|
3
|
+
const HOSTS = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
|
|
4
|
+
const POST_PATH = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
5
|
+
const TYPES = /* @__PURE__ */ new Set([
|
|
6
|
+
"p",
|
|
7
|
+
"reel",
|
|
8
|
+
"reels",
|
|
9
|
+
"tv"
|
|
10
|
+
]);
|
|
11
|
+
const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
|
|
12
|
+
const FALLBACK = /* @__PURE__ */ new Map([
|
|
13
|
+
["div", []],
|
|
14
|
+
["a", ["href"]],
|
|
15
|
+
["p", []]
|
|
16
|
+
]);
|
|
17
|
+
function post(url) {
|
|
18
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
19
|
+
const [, user, type, code] = POST_PATH.exec(url.path) ?? [];
|
|
20
|
+
if (type === void 0 || code === void 0) return null;
|
|
21
|
+
if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
|
|
22
|
+
return {
|
|
23
|
+
platform: "instagram",
|
|
24
|
+
kind: "post",
|
|
25
|
+
url: `https://www.instagram.com/${type === "reels" ? "reel" : type}/${code}/`,
|
|
26
|
+
id: code,
|
|
27
|
+
variant: "sdk"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const instagramMatcher = {
|
|
31
|
+
platform: "instagram",
|
|
32
|
+
name: "Instagram",
|
|
33
|
+
shapes: ["post sdk"],
|
|
34
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
35
|
+
match(url) {
|
|
36
|
+
const found = post(url);
|
|
37
|
+
return found && {
|
|
38
|
+
...found,
|
|
39
|
+
options: {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export { FALLBACK, instagramMatcher, post };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KICK_PLAYER_HOSTS, kickFrame } from "../frames.js";
|
|
2
|
+
// src/parser/matchers/kick.ts
|
|
3
|
+
const PAGE_HOSTS = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
|
|
4
|
+
const CHANNEL = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
|
|
5
|
+
const NOT_CHANNELS = /* @__PURE__ */ new Set([
|
|
6
|
+
"browse",
|
|
7
|
+
"categories",
|
|
8
|
+
"category",
|
|
9
|
+
"clips",
|
|
10
|
+
"video",
|
|
11
|
+
"videos",
|
|
12
|
+
"following",
|
|
13
|
+
"search",
|
|
14
|
+
"settings",
|
|
15
|
+
"dashboard",
|
|
16
|
+
"subscriptions",
|
|
17
|
+
"privacy-policy",
|
|
18
|
+
"terms-of-service",
|
|
19
|
+
"community-guidelines",
|
|
20
|
+
"help"
|
|
21
|
+
]);
|
|
22
|
+
function channel(url, hosts) {
|
|
23
|
+
if (!url || !hosts.has(url.host)) return null;
|
|
24
|
+
const [, name] = CHANNEL.exec(url.path) ?? [];
|
|
25
|
+
if (name === void 0 || NOT_CHANNELS.has(name.toLowerCase())) return null;
|
|
26
|
+
const id = name.toLowerCase();
|
|
27
|
+
return {
|
|
28
|
+
platform: "kick",
|
|
29
|
+
kind: "video",
|
|
30
|
+
url: `https://kick.com/${id}`,
|
|
31
|
+
id,
|
|
32
|
+
variant: "iframe"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const kickMatcher = {
|
|
36
|
+
platform: "kick",
|
|
37
|
+
name: "Kick",
|
|
38
|
+
shapes: ["video iframe"],
|
|
39
|
+
match(url) {
|
|
40
|
+
const found = channel(url, PAGE_HOSTS) ?? channel(url, KICK_PLAYER_HOSTS);
|
|
41
|
+
return found && {
|
|
42
|
+
...found,
|
|
43
|
+
options: {}
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
ownsFrame: kickFrame
|
|
47
|
+
};
|
|
48
|
+
export { channel, kickMatcher };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { linkedinFrame } from "../frames.js";
|
|
2
|
+
// src/parser/matchers/linkedin.ts
|
|
3
|
+
const HOST = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
|
|
4
|
+
const URN = "(activity|share|ugcPost):(\\d{19})";
|
|
5
|
+
const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
|
|
6
|
+
const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
|
|
7
|
+
function post(type, id, options = {}) {
|
|
8
|
+
const urn = `urn:li:${type}:${id}`;
|
|
9
|
+
return {
|
|
10
|
+
platform: "linkedin",
|
|
11
|
+
kind: "post",
|
|
12
|
+
url: `https://www.linkedin.com/feed/update/${urn}/`,
|
|
13
|
+
id: urn,
|
|
14
|
+
variant: "iframe",
|
|
15
|
+
options
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const decodeColons = (path) => path.replace(/%3A/gi, ":");
|
|
19
|
+
const linkedinMatcher = {
|
|
20
|
+
platform: "linkedin",
|
|
21
|
+
name: "LinkedIn",
|
|
22
|
+
shapes: ["post iframe"],
|
|
23
|
+
match(url) {
|
|
24
|
+
if (!HOST.test(url.host)) return null;
|
|
25
|
+
const path = decodeColons(url.path);
|
|
26
|
+
const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
|
|
27
|
+
return type === void 0 || id === void 0 ? null : post(type, id);
|
|
28
|
+
},
|
|
29
|
+
ownsFrame: linkedinFrame
|
|
30
|
+
};
|
|
31
|
+
export { URN, linkedinMatcher, post };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { pinterestFrame } from "../frames.js";
|
|
2
|
+
// src/parser/matchers/pinterest.ts
|
|
3
|
+
const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
|
|
4
|
+
const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
|
|
5
|
+
function pin(id) {
|
|
6
|
+
return {
|
|
7
|
+
platform: "pinterest",
|
|
8
|
+
kind: "post",
|
|
9
|
+
url: `https://www.pinterest.com/pin/${id}/`,
|
|
10
|
+
id,
|
|
11
|
+
variant: "sdk"
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function pinOf(url) {
|
|
15
|
+
if (!url || !HOST.test(url.host)) return null;
|
|
16
|
+
const [, id] = PIN_PATH.exec(url.path) ?? [];
|
|
17
|
+
return id === void 0 ? null : pin(id);
|
|
18
|
+
}
|
|
19
|
+
const pinterestMatcher = {
|
|
20
|
+
platform: "pinterest",
|
|
21
|
+
name: "Pinterest",
|
|
22
|
+
shapes: ["post sdk"],
|
|
23
|
+
match(url) {
|
|
24
|
+
const found = pinOf(url);
|
|
25
|
+
return found && {
|
|
26
|
+
...found,
|
|
27
|
+
options: {}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
ownsFrame: pinterestFrame
|
|
31
|
+
};
|
|
32
|
+
export { pin, pinOf, pinterestMatcher };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/parser/matchers/reddit.ts
|
|
2
|
+
const HOSTS = /* @__PURE__ */ new Set([
|
|
3
|
+
"reddit.com",
|
|
4
|
+
"www.reddit.com",
|
|
5
|
+
"old.reddit.com",
|
|
6
|
+
"new.reddit.com"
|
|
7
|
+
]);
|
|
8
|
+
const POST_PATH = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
|
|
9
|
+
function post(url) {
|
|
10
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
11
|
+
const [, sub, postId, slug, commentId] = POST_PATH.exec(url.path) ?? [];
|
|
12
|
+
if (sub === void 0 || postId === void 0) return null;
|
|
13
|
+
const base = {
|
|
14
|
+
platform: "reddit",
|
|
15
|
+
kind: "post",
|
|
16
|
+
variant: "iframe"
|
|
17
|
+
};
|
|
18
|
+
const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
|
|
19
|
+
if (commentId === void 0) return {
|
|
20
|
+
...base,
|
|
21
|
+
url: postUrl,
|
|
22
|
+
id: postId
|
|
23
|
+
};
|
|
24
|
+
if (slug === void 0) return null;
|
|
25
|
+
return {
|
|
26
|
+
...base,
|
|
27
|
+
url: `${postUrl}comment/${commentId}/`,
|
|
28
|
+
id: commentId
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const redditMatcher = {
|
|
32
|
+
platform: "reddit",
|
|
33
|
+
name: "Reddit",
|
|
34
|
+
shapes: ["post iframe"],
|
|
35
|
+
match(url) {
|
|
36
|
+
const found = post(url);
|
|
37
|
+
return found && {
|
|
38
|
+
...found,
|
|
39
|
+
options: {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export { post, redditMatcher };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rumbleNeedsLookup } from "../lookup.js";
|
|
2
|
+
import { rumbleFrame } from "../frames.js";
|
|
3
|
+
// src/parser/matchers/rumble.ts
|
|
4
|
+
const PATH = /^\/embed\/(v[a-z0-9]{1,12})\/?$/;
|
|
5
|
+
const HOSTS = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
|
|
6
|
+
function video(id) {
|
|
7
|
+
return {
|
|
8
|
+
platform: "rumble",
|
|
9
|
+
kind: "video",
|
|
10
|
+
url: `https://rumble.com/embed/${id}/`,
|
|
11
|
+
id,
|
|
12
|
+
variant: "iframe"
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function idOf(url, hosts) {
|
|
16
|
+
return url && hosts.has(url.host) ? PATH.exec(url.path)?.[1] : void 0;
|
|
17
|
+
}
|
|
18
|
+
const rumbleMatcher = {
|
|
19
|
+
platform: "rumble",
|
|
20
|
+
name: "Rumble",
|
|
21
|
+
shapes: ["video iframe"],
|
|
22
|
+
needsLookup: rumbleNeedsLookup,
|
|
23
|
+
match(url) {
|
|
24
|
+
const id = idOf(url, HOSTS);
|
|
25
|
+
return id === void 0 ? null : {
|
|
26
|
+
...video(id),
|
|
27
|
+
options: {}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
ownsFrame: rumbleFrame
|
|
31
|
+
};
|
|
32
|
+
export { idOf, rumbleMatcher, video };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/parser/matchers/snapchat.ts
|
|
2
|
+
const HOSTS = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
|
|
3
|
+
const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
|
|
4
|
+
const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
|
|
5
|
+
const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
|
|
6
|
+
const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
|
|
7
|
+
const HIGHLIGHT = new RegExp(`^/@${USER}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
|
|
8
|
+
function content(url) {
|
|
9
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
10
|
+
const path = url.path.replace(/\/$/, "");
|
|
11
|
+
const base = {
|
|
12
|
+
platform: "snapchat",
|
|
13
|
+
variant: "iframe"
|
|
14
|
+
};
|
|
15
|
+
const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
|
|
16
|
+
if (spotlightId !== void 0) {
|
|
17
|
+
const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
|
|
18
|
+
return {
|
|
19
|
+
...base,
|
|
20
|
+
kind: "video",
|
|
21
|
+
url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
|
|
22
|
+
id: spotlightId
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const [, user] = PROFILE.exec(path) ?? [];
|
|
26
|
+
if (user !== void 0) return {
|
|
27
|
+
...base,
|
|
28
|
+
kind: "post",
|
|
29
|
+
url: `https://www.snapchat.com/@${user}`,
|
|
30
|
+
id: user
|
|
31
|
+
};
|
|
32
|
+
const [, lens] = LENS.exec(path) ?? [];
|
|
33
|
+
if (lens !== void 0) return {
|
|
34
|
+
...base,
|
|
35
|
+
kind: "post",
|
|
36
|
+
url: `https://www.snapchat.com/lens/${lens}`,
|
|
37
|
+
id: lens
|
|
38
|
+
};
|
|
39
|
+
const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
|
|
40
|
+
if (owner !== void 0 && highlight !== void 0) return {
|
|
41
|
+
...base,
|
|
42
|
+
kind: "post",
|
|
43
|
+
url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
|
|
44
|
+
id: highlight
|
|
45
|
+
};
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const snapchatMatcher = {
|
|
49
|
+
platform: "snapchat",
|
|
50
|
+
name: "Snapchat",
|
|
51
|
+
shapes: ["post iframe", "video iframe"],
|
|
52
|
+
match(url) {
|
|
53
|
+
const found = content(url);
|
|
54
|
+
return found && {
|
|
55
|
+
...found,
|
|
56
|
+
options: {}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export { content, snapchatMatcher };
|