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.
- package/README.md +14 -9
- package/dist/components/apple-embed.d.ts +7 -0
- package/dist/components/apple-embed.js +39 -0
- package/dist/components/bluesky-embed.d.ts +10 -0
- package/dist/components/bluesky-embed.js +27 -0
- package/dist/components/dailymotion-embed.d.ts +9 -0
- package/dist/components/dailymotion-embed.js +30 -0
- package/dist/components/facebook-embed.d.ts +6 -0
- package/dist/components/facebook-embed.js +40 -0
- package/dist/components/flickr-embed.d.ts +6 -0
- package/dist/components/flickr-embed.js +27 -0
- package/dist/components/generic-iframe-embed.d.ts +11 -0
- package/dist/components/generic-iframe-embed.js +26 -0
- package/dist/components/giphy-embed.d.ts +4 -0
- package/dist/components/giphy-embed.js +22 -0
- package/dist/components/hooks.js +36 -0
- package/dist/components/iframe-embed.js +169 -0
- package/dist/components/imgur-embed.d.ts +6 -0
- package/dist/components/imgur-embed.js +23 -0
- package/dist/components/instagram-embed.d.ts +5 -0
- package/dist/components/instagram-embed.js +25 -0
- package/dist/components/kick-embed.d.ts +6 -0
- package/dist/components/kick-embed.js +25 -0
- package/dist/components/linkedin-embed.d.ts +6 -0
- package/dist/components/linkedin-embed.js +23 -0
- package/dist/components/pinterest-embed.d.ts +5 -0
- package/dist/components/pinterest-embed.js +25 -0
- package/dist/components/reddit-embed.d.ts +6 -0
- package/dist/components/reddit-embed.js +29 -0
- package/dist/components/rumble-embed.d.ts +4 -0
- package/dist/components/rumble-embed.js +22 -0
- package/dist/components/script-embed.js +107 -0
- package/dist/components/shared.d.ts +29 -0
- package/dist/components/snapchat-embed.d.ts +4 -0
- package/dist/components/snapchat-embed.js +22 -0
- package/dist/components/social-embed.d.ts +60 -0
- package/dist/components/social-embed.js +221 -0
- package/dist/components/soundcloud-embed.d.ts +6 -0
- package/dist/components/soundcloud-embed.js +33 -0
- package/dist/components/spotify-embed.d.ts +9 -0
- package/dist/components/spotify-embed.js +25 -0
- package/dist/components/strava-embed.d.ts +6 -0
- package/dist/components/strava-embed.js +26 -0
- package/dist/components/streamable-embed.d.ts +6 -0
- package/dist/components/streamable-embed.js +28 -0
- package/dist/components/telegram-embed.d.ts +6 -0
- package/dist/components/telegram-embed.js +27 -0
- package/dist/components/tenor-embed.d.ts +4 -0
- package/dist/components/tenor-embed.js +22 -0
- package/dist/components/threads-embed.d.ts +5 -0
- package/dist/components/threads-embed.js +25 -0
- package/dist/components/tiktok-embed.d.ts +6 -0
- package/dist/components/tiktok-embed.js +37 -0
- package/dist/components/truthsocial-embed.d.ts +4 -0
- package/dist/components/truthsocial-embed.js +22 -0
- package/dist/components/tumblr-embed.d.ts +4 -0
- package/dist/components/tumblr-embed.js +22 -0
- package/dist/components/twitch-embed.d.ts +6 -0
- package/dist/components/twitch-embed.js +26 -0
- package/dist/components/vimeo-embed.d.ts +5 -0
- package/dist/components/vimeo-embed.js +40 -0
- package/dist/components/x-embed.d.ts +5 -0
- package/dist/components/x-embed.js +32 -0
- package/dist/components/youtube-embed.d.ts +5 -0
- package/dist/components/youtube-embed.js +43 -0
- package/dist/core/drivers.js +118 -0
- package/dist/core/layout.js +73 -0
- package/dist/core/markup.js +30 -0
- package/dist/core/params.js +26 -0
- package/dist/core/plans/apple.js +44 -0
- package/dist/core/plans/bluesky.d.ts +3 -0
- package/dist/core/plans/bluesky.js +34 -0
- package/dist/core/plans/dailymotion.d.ts +8 -0
- package/dist/core/plans/dailymotion.js +37 -0
- package/dist/core/plans/facebook.d.ts +15 -0
- package/dist/core/plans/facebook.js +79 -0
- package/dist/core/plans/flickr.d.ts +7 -0
- package/dist/core/plans/flickr.js +37 -0
- package/dist/core/plans/generic.js +44 -0
- package/dist/core/plans/giphy.js +16 -0
- package/dist/core/plans/imgur.d.ts +4 -0
- package/dist/core/plans/imgur.js +34 -0
- package/dist/core/plans/instagram.d.ts +4 -0
- package/dist/core/plans/instagram.js +26 -0
- package/dist/core/plans/kick.d.ts +5 -0
- package/dist/core/plans/kick.js +22 -0
- package/dist/core/plans/linkedin.d.ts +4 -0
- package/dist/core/plans/linkedin.js +23 -0
- package/dist/core/plans/pinterest.d.ts +4 -0
- package/dist/core/plans/pinterest.js +31 -0
- package/dist/core/plans/reddit.d.ts +11 -0
- package/dist/core/plans/reddit.js +46 -0
- package/dist/core/plans/rumble.js +21 -0
- package/dist/core/plans/snapchat.js +20 -0
- package/dist/core/plans/soundcloud.d.ts +14 -0
- package/dist/core/plans/soundcloud.js +37 -0
- package/dist/core/plans/spotify.d.ts +4 -0
- package/dist/core/plans/spotify.js +29 -0
- package/dist/core/plans/strava.d.ts +8 -0
- package/dist/core/plans/strava.js +38 -0
- package/dist/core/plans/streamable.d.ts +8 -0
- package/dist/core/plans/streamable.js +31 -0
- package/dist/core/plans/telegram.d.ts +10 -0
- package/dist/core/plans/telegram.js +59 -0
- package/dist/core/plans/tenor.js +16 -0
- package/dist/core/plans/threads.d.ts +4 -0
- package/dist/core/plans/threads.js +25 -0
- package/dist/core/plans/tiktok.d.ts +17 -0
- package/dist/core/plans/tiktok.js +36 -0
- package/dist/core/plans/truthsocial.js +43 -0
- package/dist/core/plans/tumblr.js +29 -0
- package/dist/core/plans/twitch.d.ts +7 -0
- package/dist/core/plans/twitch.js +38 -0
- package/dist/core/plans/vimeo.d.ts +23 -0
- package/dist/core/plans/vimeo.js +42 -0
- package/dist/core/plans/x.d.ts +12 -0
- package/dist/core/plans/x.js +31 -0
- package/dist/core/plans/youtube.d.ts +25 -0
- package/dist/core/plans/youtube.js +47 -0
- package/dist/core/post-link.js +19 -0
- package/dist/core/resolve.js +57 -0
- package/dist/core/timing.js +7 -0
- package/dist/element.js +1 -1
- package/dist/index.d.ts +53 -344
- package/dist/index.js +30 -2575
- package/dist/loader/load-script.js +114 -0
- package/dist/loader/platform-scripts.js +89 -0
- package/dist/parser/html.js +172 -0
- package/dist/parser/iframe.d.ts +24 -0
- package/dist/parser/iframe.js +151 -0
- package/dist/parser/lookup.js +20 -0
- package/dist/parser/match-url.d.ts +3 -0
- package/dist/parser/match-url.js +22 -0
- package/dist/parser/parse-embed.d.ts +7 -0
- package/dist/parser/parse-embed.js +69 -0
- package/dist/parser/platform.js +60 -0
- package/dist/parser/platforms/applemusic.js +45 -0
- package/dist/parser/platforms/applepodcasts.js +41 -0
- package/dist/parser/platforms/bluesky.js +64 -0
- package/dist/parser/platforms/dailymotion.js +59 -0
- package/dist/parser/platforms/facebook.js +185 -0
- package/dist/parser/platforms/flickr.js +134 -0
- package/dist/parser/platforms/giphy.js +68 -0
- package/dist/parser/platforms/imgur.js +107 -0
- package/dist/parser/platforms/index.js +62 -0
- package/dist/parser/platforms/instagram.js +59 -0
- package/dist/parser/platforms/kick.js +61 -0
- package/dist/parser/platforms/linkedin.js +42 -0
- package/dist/parser/platforms/pinterest.js +59 -0
- package/dist/parser/platforms/reddit.js +68 -0
- package/dist/parser/platforms/rumble.js +43 -0
- package/dist/parser/platforms/snapchat.js +87 -0
- package/dist/parser/platforms/soundcloud.js +128 -0
- package/dist/parser/platforms/spotify.js +51 -0
- package/dist/parser/platforms/strava.js +55 -0
- package/dist/parser/platforms/streamable.js +94 -0
- package/dist/parser/platforms/telegram.js +61 -0
- package/dist/parser/platforms/tenor.js +78 -0
- package/dist/parser/platforms/threads.js +51 -0
- package/dist/parser/platforms/tiktok.js +48 -0
- package/dist/parser/platforms/truthsocial.js +49 -0
- package/dist/parser/platforms/tumblr.js +70 -0
- package/dist/parser/platforms/twitch.js +129 -0
- package/dist/parser/platforms/vimeo.js +76 -0
- package/dist/parser/platforms/x.js +65 -0
- package/dist/parser/platforms/youtube.js +90 -0
- package/dist/parser/types.d.ts +14 -0
- package/dist/parser/url.js +41 -0
- package/dist/parser/verify.js +63 -0
- package/dist/parser.d.ts +4 -1
- package/dist/parser.js +4 -1
- package/package.json +1 -1
- package/dist/index-DrMHAkyG.d.ts +0 -46
- 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
|
+
// src/parser/platforms/soundcloud.ts
|
|
4
|
+
const PAGE_HOSTS = /* @__PURE__ */ new Set([
|
|
5
|
+
"soundcloud.com",
|
|
6
|
+
"www.soundcloud.com",
|
|
7
|
+
"m.soundcloud.com"
|
|
8
|
+
]);
|
|
9
|
+
const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
|
|
10
|
+
const NAME = "[a-z0-9_-]{1,64}";
|
|
11
|
+
const SECRET = "s-[A-Za-z0-9]{1,32}";
|
|
12
|
+
const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
|
|
13
|
+
const NOT_USERS = /* @__PURE__ */ new Set([
|
|
14
|
+
"discover",
|
|
15
|
+
"search",
|
|
16
|
+
"stream",
|
|
17
|
+
"feed",
|
|
18
|
+
"you",
|
|
19
|
+
"upload",
|
|
20
|
+
"charts",
|
|
21
|
+
"pages",
|
|
22
|
+
"settings",
|
|
23
|
+
"messages",
|
|
24
|
+
"notifications",
|
|
25
|
+
"people",
|
|
26
|
+
"stations",
|
|
27
|
+
"library",
|
|
28
|
+
"terms-of-use",
|
|
29
|
+
"signin"
|
|
30
|
+
]);
|
|
31
|
+
const NOT_SOUNDS = /* @__PURE__ */ new Set([
|
|
32
|
+
"likes",
|
|
33
|
+
"tracks",
|
|
34
|
+
"sets",
|
|
35
|
+
"albums",
|
|
36
|
+
"reposts",
|
|
37
|
+
"popular-tracks",
|
|
38
|
+
"followers",
|
|
39
|
+
"following",
|
|
40
|
+
"comments",
|
|
41
|
+
"spotlight",
|
|
42
|
+
"toptracks"
|
|
43
|
+
]);
|
|
44
|
+
const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
|
|
45
|
+
const WIDGET_HOST = "w.soundcloud.com";
|
|
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 !== WIDGET_HOST || !/^\/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: (src) => src.host === WIDGET_HOST
|
|
127
|
+
};
|
|
128
|
+
export { soundcloud };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sizeOf, underPath, withSize } from "../platform.js";
|
|
2
|
+
import { coerce, parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/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
|
+
const HOST = "open.spotify.com";
|
|
7
|
+
function content(url) {
|
|
8
|
+
if (url?.host !== HOST) 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: (src) => src.host === HOST && underPath(src.path, "/embed")
|
|
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,94 @@
|
|
|
1
|
+
import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
+
import { coerce, parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/streamable.ts
|
|
4
|
+
const ID = "([a-z0-9]{4,8})";
|
|
5
|
+
const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
|
|
6
|
+
const PLAYER_PATH = new RegExp(`^/[eo]/${ID}$`);
|
|
7
|
+
const PAGE_PATH = new RegExp(`^/${ID}/?$`);
|
|
8
|
+
const NOT_VIDEOS = /* @__PURE__ */ new Set([
|
|
9
|
+
"about",
|
|
10
|
+
"login",
|
|
11
|
+
"signup",
|
|
12
|
+
"terms",
|
|
13
|
+
"privacy",
|
|
14
|
+
"pricing",
|
|
15
|
+
"upload",
|
|
16
|
+
"help",
|
|
17
|
+
"apps",
|
|
18
|
+
"blog",
|
|
19
|
+
"jobs",
|
|
20
|
+
"press",
|
|
21
|
+
"tools",
|
|
22
|
+
"embed",
|
|
23
|
+
"plans",
|
|
24
|
+
"contact",
|
|
25
|
+
"support",
|
|
26
|
+
"videos",
|
|
27
|
+
"account",
|
|
28
|
+
"profile"
|
|
29
|
+
]);
|
|
30
|
+
const WRAPPER = /^width:\s*100%;\s*height:\s*0(?:px)?;\s*position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;?$/;
|
|
31
|
+
const KEPT = /* @__PURE__ */ new Set([
|
|
32
|
+
"loop",
|
|
33
|
+
"autoplay",
|
|
34
|
+
"nocontrols",
|
|
35
|
+
"hd",
|
|
36
|
+
"muted"
|
|
37
|
+
]);
|
|
38
|
+
const STRAY_END = /<\/div\s*>$/i;
|
|
39
|
+
function video(id) {
|
|
40
|
+
return {
|
|
41
|
+
platform: "streamable",
|
|
42
|
+
kind: "video",
|
|
43
|
+
url: `https://streamable.com/${id}`,
|
|
44
|
+
id,
|
|
45
|
+
variant: "iframe"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function validId(id) {
|
|
49
|
+
return id !== void 0 && !NOT_VIDEOS.has(id);
|
|
50
|
+
}
|
|
51
|
+
function fromIframe(iframe) {
|
|
52
|
+
if (iframe.tag !== "iframe") return null;
|
|
53
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
54
|
+
if (!src || src.host !== "streamable.com") return null;
|
|
55
|
+
const [, id] = PLAYER_PATH.exec(src.path) ?? [];
|
|
56
|
+
if (!validId(id)) return null;
|
|
57
|
+
const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
|
|
58
|
+
return {
|
|
59
|
+
...video(id),
|
|
60
|
+
options
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function idOf(url) {
|
|
64
|
+
if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
|
|
65
|
+
const id = (PLAYER_PATH.exec(url.path) ?? PAGE_PATH.exec(url.path))?.[1];
|
|
66
|
+
return validId(id) ? id : void 0;
|
|
67
|
+
}
|
|
68
|
+
const streamable = {
|
|
69
|
+
platform: "streamable",
|
|
70
|
+
parse(root) {
|
|
71
|
+
const wrapped = unwrapRatio(root, WRAPPER);
|
|
72
|
+
const iframe = wrapped?.iframe ?? root;
|
|
73
|
+
const found = fromIframe(iframe);
|
|
74
|
+
if (!found) return null;
|
|
75
|
+
return withSize(found, wrapped?.size ?? sizeOf(iframe));
|
|
76
|
+
},
|
|
77
|
+
isOwnScript: () => false,
|
|
78
|
+
repair(html) {
|
|
79
|
+
const code = html.trimEnd();
|
|
80
|
+
const end = STRAY_END.exec(code);
|
|
81
|
+
if (!end) return null;
|
|
82
|
+
const trimmed = code.slice(0, end.index).trimEnd();
|
|
83
|
+
return /^\s*<iframe[\s>]/i.test(trimmed) ? trimmed : null;
|
|
84
|
+
},
|
|
85
|
+
match(url) {
|
|
86
|
+
const id = idOf(url);
|
|
87
|
+
return id === void 0 ? null : {
|
|
88
|
+
...video(id),
|
|
89
|
+
options: {}
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
ownsFrame: (src) => src.host === "streamable.com" && (underPath(src.path, "/e") || underPath(src.path, "/o"))
|
|
93
|
+
};
|
|
94
|
+
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,78 @@
|
|
|
1
|
+
import { hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { sizeOf, underPath, withSize } from "../platform.js";
|
|
3
|
+
import { parseUrl } from "../url.js";
|
|
4
|
+
// src/parser/platforms/tenor.ts
|
|
5
|
+
const HOSTS = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
|
|
6
|
+
const ID = "(\\d{1,20})";
|
|
7
|
+
const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID}/?$`);
|
|
8
|
+
const FRAME_PATH = new RegExp(`^/embed/${ID}$`);
|
|
9
|
+
const SCRIPT = /^(?:https?:)?\/\/tenor\.com\/embed\.js$/;
|
|
10
|
+
const RATIO = /^\d{1,3}(?:\.\d{1,20})?$/;
|
|
11
|
+
const DEFAULT_RATIO = 1.33;
|
|
12
|
+
const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]]]);
|
|
13
|
+
function gif(id) {
|
|
14
|
+
return {
|
|
15
|
+
platform: "tenor",
|
|
16
|
+
kind: "video",
|
|
17
|
+
url: `https://tenor.com/view/${id}`,
|
|
18
|
+
id,
|
|
19
|
+
variant: "iframe"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function idOf(url) {
|
|
23
|
+
return url && HOSTS.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
|
|
24
|
+
}
|
|
25
|
+
/** To four decimals, from 1:100 to 100:1. */
|
|
26
|
+
function ratioSize(ratio) {
|
|
27
|
+
const width = Math.round(ratio * 1e4);
|
|
28
|
+
if (!(width >= 100 && width <= 1e6)) return void 0;
|
|
29
|
+
const divisor = gcd(width, 1e4);
|
|
30
|
+
return {
|
|
31
|
+
width: width / divisor,
|
|
32
|
+
height: 1e4 / divisor
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function gcd(a, b) {
|
|
36
|
+
return b === 0 ? a : gcd(b, a % b);
|
|
37
|
+
}
|
|
38
|
+
function fromDiv(root) {
|
|
39
|
+
if (!hasClass(root, "tenor-gif-embed")) return null;
|
|
40
|
+
const id = root.attrs.get("data-postid") ?? "";
|
|
41
|
+
if (!new RegExp(`^${ID}$`).test(id)) return null;
|
|
42
|
+
const given = root.attrs.get("data-aspect-ratio");
|
|
43
|
+
if (given !== void 0 && !RATIO.test(given)) return null;
|
|
44
|
+
const size = ratioSize(given === void 0 ? DEFAULT_RATIO : Number(given));
|
|
45
|
+
if (!size) return null;
|
|
46
|
+
return withSize({
|
|
47
|
+
...gif(id),
|
|
48
|
+
options: {},
|
|
49
|
+
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
50
|
+
}, size);
|
|
51
|
+
}
|
|
52
|
+
function fromIframe(root) {
|
|
53
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
54
|
+
if (!src || src.host !== "tenor.com") return null;
|
|
55
|
+
const [, id] = FRAME_PATH.exec(src.path) ?? [];
|
|
56
|
+
return id === void 0 ? null : withSize({
|
|
57
|
+
...gif(id),
|
|
58
|
+
options: {}
|
|
59
|
+
}, sizeOf(root));
|
|
60
|
+
}
|
|
61
|
+
const tenor = {
|
|
62
|
+
platform: "tenor",
|
|
63
|
+
fallback: FALLBACK,
|
|
64
|
+
parse(root) {
|
|
65
|
+
if (root.tag === "div") return fromDiv(root);
|
|
66
|
+
return root.tag === "iframe" ? fromIframe(root) : null;
|
|
67
|
+
},
|
|
68
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
69
|
+
match(url) {
|
|
70
|
+
const id = idOf(url);
|
|
71
|
+
return id === void 0 ? null : {
|
|
72
|
+
...gif(id),
|
|
73
|
+
options: {}
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
ownsFrame: (src) => src.host === "tenor.com" && underPath(src.path, "/embed")
|
|
77
|
+
};
|
|
78
|
+
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, underPath, withSize } from "../platform.js";
|
|
3
|
+
import { coerce, parseUrl } from "../url.js";
|
|
4
|
+
// src/parser/platforms/tiktok.ts
|
|
5
|
+
const HOSTS = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
|
|
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 && 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 || !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 (!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: (src) => HOSTS.has(src.host) && underPath(src.path, "/player")
|
|
47
|
+
};
|
|
48
|
+
export { tiktok };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { hasClass } from "../html.js";
|
|
2
|
+
import { sizeOf, withSize } from "../platform.js";
|
|
3
|
+
import { parseUrl } from "../url.js";
|
|
4
|
+
// src/parser/platforms/truthsocial.ts
|
|
5
|
+
const HOSTS = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
|
|
6
|
+
const USER = "(@[A-Za-z0-9_.-]{1,64})";
|
|
7
|
+
const ID = "(\\d{1,25})";
|
|
8
|
+
const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
|
|
9
|
+
const FRAME_PATH = new RegExp(`^/${USER}/${ID}/embed$`);
|
|
10
|
+
const SCRIPT = /^(?:https?:)?\/\/truthsocial\.com\/embed\.js$/;
|
|
11
|
+
function post(user, id) {
|
|
12
|
+
return {
|
|
13
|
+
platform: "truthsocial",
|
|
14
|
+
kind: "post",
|
|
15
|
+
url: `https://truthsocial.com/${user}/posts/${id}`,
|
|
16
|
+
id,
|
|
17
|
+
variant: "iframe"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function fromUrl(url) {
|
|
21
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
22
|
+
const [, user, id] = POST_PATH.exec(url.path) ?? [];
|
|
23
|
+
return user === void 0 || id === void 0 ? null : post(user, id);
|
|
24
|
+
}
|
|
25
|
+
const truthsocial = {
|
|
26
|
+
platform: "truthsocial",
|
|
27
|
+
parse(root) {
|
|
28
|
+
if (root.tag !== "iframe") return null;
|
|
29
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
30
|
+
if (!src || src.host !== "truthsocial.com") return null;
|
|
31
|
+
const [, user, id] = FRAME_PATH.exec(src.path) ?? [];
|
|
32
|
+
if (user === void 0 || id === void 0) return null;
|
|
33
|
+
const options = hasClass(root, "truthsocial-video") ? { video: true } : {};
|
|
34
|
+
return withSize({
|
|
35
|
+
...post(user, id),
|
|
36
|
+
options
|
|
37
|
+
}, sizeOf(root));
|
|
38
|
+
},
|
|
39
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
40
|
+
match(url) {
|
|
41
|
+
const found = fromUrl(url);
|
|
42
|
+
return found && {
|
|
43
|
+
...found,
|
|
44
|
+
options: {}
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
ownsFrame: (src) => src.host === "truthsocial.com" && src.path.startsWith("/@")
|
|
48
|
+
};
|
|
49
|
+
export { truthsocial };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { hasClass } from "../html.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/tumblr.ts
|
|
4
|
+
const BLOG = "([a-z0-9-]{1,32})";
|
|
5
|
+
const POST = "(\\d{1,20})";
|
|
6
|
+
const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
|
|
7
|
+
const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
|
|
8
|
+
const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
|
|
9
|
+
const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
|
|
10
|
+
const FRAME_PATH = new RegExp(`^/embed/post/(?:t:[A-Za-z0-9_-]{1,64}|${BLOG})/${POST}/v2$`);
|
|
11
|
+
const NOT_BLOGS = /* @__PURE__ */ new Set([
|
|
12
|
+
"dashboard",
|
|
13
|
+
"explore",
|
|
14
|
+
"tagged",
|
|
15
|
+
"search",
|
|
16
|
+
"settings",
|
|
17
|
+
"blog",
|
|
18
|
+
"www",
|
|
19
|
+
"assets",
|
|
20
|
+
"embed",
|
|
21
|
+
"api",
|
|
22
|
+
"help"
|
|
23
|
+
]);
|
|
24
|
+
const SCRIPT = /^(?:https?:)?\/\/assets\.tumblr\.com\/post\.js(?:\?[^#]*)?$/;
|
|
25
|
+
function fromUrl(url) {
|
|
26
|
+
if (!url) return null;
|
|
27
|
+
let blog;
|
|
28
|
+
let id;
|
|
29
|
+
if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
|
|
30
|
+
else {
|
|
31
|
+
[, blog] = BLOG_HOST.exec(url.host) ?? [];
|
|
32
|
+
[, id] = BLOG_PATH.exec(url.path) ?? [];
|
|
33
|
+
}
|
|
34
|
+
if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
|
|
35
|
+
return {
|
|
36
|
+
platform: "tumblr",
|
|
37
|
+
kind: "post",
|
|
38
|
+
url: `https://www.tumblr.com/${blog}/${id}`,
|
|
39
|
+
id,
|
|
40
|
+
variant: "iframe"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const tumblr = {
|
|
44
|
+
platform: "tumblr",
|
|
45
|
+
parse(root) {
|
|
46
|
+
if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
|
|
47
|
+
const frame = parseUrl(root.attrs.get("data-href") ?? "");
|
|
48
|
+
if (frame?.host !== "embed.tumblr.com") return null;
|
|
49
|
+
const [, frameBlog, framePost] = FRAME_PATH.exec(frame.path) ?? [];
|
|
50
|
+
if (framePost === void 0) return null;
|
|
51
|
+
const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
|
|
52
|
+
if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
|
|
53
|
+
const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
|
|
54
|
+
if (found?.id !== framePost) return null;
|
|
55
|
+
if (frameBlog !== void 0 && found.url !== `https://www.tumblr.com/${frameBlog}/${framePost}`) return null;
|
|
56
|
+
return {
|
|
57
|
+
...found,
|
|
58
|
+
options: {}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
62
|
+
match(url) {
|
|
63
|
+
const found = fromUrl(url);
|
|
64
|
+
return found && {
|
|
65
|
+
...found,
|
|
66
|
+
options: {}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
export { tumblr };
|