social-embeds 0.9.2 → 0.9.4
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 +1 -1
- package/dist/components/apple-embed.js +4 -4
- package/dist/components/bluesky-embed.js +2 -2
- package/dist/components/dailymotion-embed.js +2 -2
- package/dist/components/facebook-embed.js +2 -2
- package/dist/components/flickr-embed.js +2 -2
- package/dist/components/giphy-embed.js +2 -2
- package/dist/components/imgur-embed.js +2 -2
- package/dist/components/instagram-embed.js +2 -2
- package/dist/components/kick-embed.js +2 -2
- package/dist/components/linkedin-embed.js +2 -2
- package/dist/components/pinterest-embed.js +2 -2
- package/dist/components/reddit-embed.js +2 -2
- package/dist/components/rumble-embed.js +2 -2
- package/dist/components/snapchat-embed.js +2 -2
- package/dist/components/soundcloud-embed.js +2 -2
- package/dist/components/spotify-embed.js +2 -2
- package/dist/components/strava-embed.js +2 -2
- package/dist/components/streamable-embed.js +2 -2
- package/dist/components/telegram-embed.js +2 -2
- package/dist/components/tenor-embed.js +2 -2
- package/dist/components/threads-embed.js +2 -2
- package/dist/components/tiktok-embed.js +2 -2
- package/dist/components/truthsocial-embed.js +2 -2
- package/dist/components/tumblr-embed.js +2 -2
- package/dist/components/twitch-embed.js +2 -2
- package/dist/components/vimeo-embed.js +2 -2
- package/dist/components/x-embed.js +2 -2
- package/dist/components/youtube-embed.js +2 -2
- package/dist/element.js +1 -1
- package/dist/parser/iframe.js +2 -2
- 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 +13 -5
- package/dist/parser/platform.js +11 -1
- package/dist/parser/platforms/applemusic.js +6 -33
- package/dist/parser/platforms/applepodcasts.js +6 -32
- package/dist/parser/platforms/bluesky.js +7 -41
- package/dist/parser/platforms/dailymotion.js +6 -47
- package/dist/parser/platforms/facebook.js +7 -118
- package/dist/parser/platforms/flickr.js +7 -101
- package/dist/parser/platforms/giphy.js +6 -38
- package/dist/parser/platforms/imgur.js +7 -76
- package/dist/parser/platforms/instagram.js +6 -42
- package/dist/parser/platforms/kick.js +6 -48
- package/dist/parser/platforms/linkedin.js +7 -32
- package/dist/parser/platforms/pinterest.js +6 -32
- package/dist/parser/platforms/reddit.js +6 -44
- package/dist/parser/platforms/rumble.js +5 -32
- package/dist/parser/platforms/snapchat.js +5 -60
- package/dist/parser/platforms/soundcloud.js +6 -87
- package/dist/parser/platforms/spotify.js +6 -39
- package/dist/parser/platforms/strava.js +5 -30
- package/dist/parser/platforms/streamable.js +5 -59
- package/dist/parser/platforms/telegram.js +6 -35
- package/dist/parser/platforms/tenor.js +8 -36
- package/dist/parser/platforms/threads.js +6 -36
- package/dist/parser/platforms/tiktok.js +6 -25
- package/dist/parser/platforms/truthsocial.js +6 -35
- package/dist/parser/platforms/tumblr.js +7 -52
- package/dist/parser/platforms/twitch.js +6 -90
- package/dist/parser/platforms/vimeo.js +6 -71
- package/dist/parser/platforms/x.js +8 -49
- package/dist/parser/platforms/youtube.js +6 -122
- package/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { underPath } from "../platform.js";
|
|
2
|
+
import { YOUTUBE_HOSTS, YOUTUBE_NOCOOKIE_HOSTS, youtubeFrame } from "../frames.js";
|
|
3
|
+
// src/parser/matchers/youtube.ts
|
|
4
|
+
const BASE = "https://www.youtube.com";
|
|
5
|
+
const VIDEO_ID = /^(?!videoseries|live_stream)[A-Za-z0-9_-]{11}$/;
|
|
6
|
+
const EMBED_PATH = /^\/embed\/(?:(videoseries|live_stream)|([A-Za-z0-9_-]{11}))\/?$/;
|
|
7
|
+
const URL_PATHS = /^\/(shorts|live)\/((?!videoseries|live_stream)[A-Za-z0-9_-]{11})\/?$/;
|
|
8
|
+
const SHORT_LINK_PATH = /^\/([A-Za-z0-9_-]{11})\/?$/;
|
|
9
|
+
const PLAYLIST_ID = /^[A-Za-z0-9_-]{10,64}$/;
|
|
10
|
+
const CHANNEL_ID = /^UC[A-Za-z0-9_-]{22}$/;
|
|
11
|
+
const CHANNEL_LIVE_PATH = /^\/channel\/(UC[A-Za-z0-9_-]{22})\/live\/?$/;
|
|
12
|
+
const DURATION = /^(?:(\d{1,5})h)?(?:(\d{1,6})m)?(?:(\d{1,7})s?)?$/;
|
|
13
|
+
const FRAGMENT_START = /^t=(.+)$/;
|
|
14
|
+
/** `90`, `90s`, `1m30s`, `1h2m3s` → seconds. */
|
|
15
|
+
function seconds(value) {
|
|
16
|
+
if (value === void 0 || value === "") return void 0;
|
|
17
|
+
const match = DURATION.exec(value);
|
|
18
|
+
if (!match) return void 0;
|
|
19
|
+
const [, hours = "0", minutes = "0", secs = "0"] = match;
|
|
20
|
+
return Number(hours) * 3600 + Number(minutes) * 60 + Number(secs);
|
|
21
|
+
}
|
|
22
|
+
/** `start` wins over `t`; `t` is converted, because the embed player only reads `start`. */
|
|
23
|
+
function startOf(query) {
|
|
24
|
+
return seconds(query.get("start")) ?? seconds(query.get("t"));
|
|
25
|
+
}
|
|
26
|
+
function found(id, url) {
|
|
27
|
+
return {
|
|
28
|
+
platform: "youtube",
|
|
29
|
+
kind: "video",
|
|
30
|
+
url,
|
|
31
|
+
id,
|
|
32
|
+
variant: "iframe"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function video(id, shorts = false) {
|
|
36
|
+
return found(id, shorts ? `${BASE}/shorts/${id}` : `${BASE}/watch?v=${id}`);
|
|
37
|
+
}
|
|
38
|
+
function playlist(id) {
|
|
39
|
+
return id !== void 0 && PLAYLIST_ID.test(id) ? found(id, `${BASE}/playlist?list=${id}`) : null;
|
|
40
|
+
}
|
|
41
|
+
function live(id) {
|
|
42
|
+
return id !== void 0 && CHANNEL_ID.test(id) ? found(id, `${BASE}/channel/${id}/live`) : null;
|
|
43
|
+
}
|
|
44
|
+
/** `key` is the query parameter that names the content, for a playlist or a channel's stream. */
|
|
45
|
+
function fromEmbed(url) {
|
|
46
|
+
const [, series, id] = EMBED_PATH.exec(url.path) ?? [];
|
|
47
|
+
if (id !== void 0) return { found: video(id) };
|
|
48
|
+
if (series === "videoseries") {
|
|
49
|
+
const list = playlist(url.query.get("list"));
|
|
50
|
+
return list && {
|
|
51
|
+
found: list,
|
|
52
|
+
key: "list"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (series === "live_stream") {
|
|
56
|
+
const stream = live(url.query.get("channel"));
|
|
57
|
+
return stream && {
|
|
58
|
+
found: stream,
|
|
59
|
+
key: "channel"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function urlOptions(url, nocookie) {
|
|
65
|
+
const start = startOf(url.query) ?? seconds(FRAGMENT_START.exec(url.fragment ?? "")?.[1]);
|
|
66
|
+
return {
|
|
67
|
+
...start === void 0 ? {} : { start },
|
|
68
|
+
...nocookie ? { nocookie: true } : {}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const youtubeMatcher = {
|
|
72
|
+
platform: "youtube",
|
|
73
|
+
name: "YouTube",
|
|
74
|
+
shapes: ["video iframe"],
|
|
75
|
+
match(url) {
|
|
76
|
+
if (url.host === "youtu.be") {
|
|
77
|
+
const [, id] = SHORT_LINK_PATH.exec(url.path) ?? [];
|
|
78
|
+
return id === void 0 ? null : {
|
|
79
|
+
...video(id),
|
|
80
|
+
options: urlOptions(url, false)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const nocookie = YOUTUBE_NOCOOKIE_HOSTS.has(url.host);
|
|
84
|
+
if (!nocookie && !YOUTUBE_HOSTS.has(url.host)) return null;
|
|
85
|
+
const options = urlOptions(url, nocookie);
|
|
86
|
+
if (underPath(url.path, "/embed")) {
|
|
87
|
+
const player = fromEmbed(url);
|
|
88
|
+
return player && {
|
|
89
|
+
...player.found,
|
|
90
|
+
options
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (nocookie) return null;
|
|
94
|
+
if (/^\/watch\/?$/.test(url.path)) {
|
|
95
|
+
const id = url.query.get("v");
|
|
96
|
+
return id !== void 0 && VIDEO_ID.test(id) ? {
|
|
97
|
+
...video(id),
|
|
98
|
+
options
|
|
99
|
+
} : null;
|
|
100
|
+
}
|
|
101
|
+
if (/^\/playlist\/?$/.test(url.path)) {
|
|
102
|
+
const list = playlist(url.query.get("list"));
|
|
103
|
+
return list && {
|
|
104
|
+
...list,
|
|
105
|
+
options
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const [, channel] = CHANNEL_LIVE_PATH.exec(url.path) ?? [];
|
|
109
|
+
const stream = live(channel);
|
|
110
|
+
if (stream) return {
|
|
111
|
+
...stream,
|
|
112
|
+
options
|
|
113
|
+
};
|
|
114
|
+
const [, kind, id] = URL_PATHS.exec(url.path) ?? [];
|
|
115
|
+
if (kind === void 0 || id === void 0) return null;
|
|
116
|
+
return {
|
|
117
|
+
...video(id, kind === "shorts"),
|
|
118
|
+
options
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
ownsFrame: youtubeFrame
|
|
122
|
+
};
|
|
123
|
+
export { fromEmbed, startOf, youtubeMatcher };
|
|
@@ -2,7 +2,11 @@ import { HtmlElement } from "./html.js";
|
|
|
2
2
|
import { ParsedEmbed, Platform } from "./types.js";
|
|
3
3
|
import { ParsedUrl } from "./url.js";
|
|
4
4
|
export type Options = ParsedEmbed['options'];
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The URL half of a platform: what a component needs to match a URL and verify an embed, without
|
|
7
|
+
* the embed-code parsing that only `parseEmbed` uses (docs/decisions.md D117).
|
|
8
|
+
*/
|
|
9
|
+
export type PlatformMatcher = {
|
|
6
10
|
platform: Platform;
|
|
7
11
|
/** For messages: `YouTube`, `Apple Music`. */
|
|
8
12
|
name: string;
|
|
@@ -12,6 +16,12 @@ export type PlatformParser = {
|
|
|
12
16
|
trustsFallback?: (html: string, embed: ParsedEmbed) => boolean;
|
|
13
17
|
/** A post URL that only a network lookup could turn into an embed (docs/decisions.md D70). */
|
|
14
18
|
needsLookup?: (url: ParsedUrl) => boolean;
|
|
19
|
+
match: (url: ParsedUrl) => ParsedEmbed | null;
|
|
20
|
+
/** True also for frames `parse` rejects, so generic iframe code never bypasses the platform's checks. */
|
|
21
|
+
ownsFrame?: (src: ParsedUrl) => boolean;
|
|
22
|
+
};
|
|
23
|
+
/** A parser's embed-code half: what it adds to its `PlatformMatcher`. */
|
|
24
|
+
export type EmbedCode = {
|
|
15
25
|
/** The embed element (blockquote, div or iframe) of the platform's own embed code. */
|
|
16
26
|
parse: (root: HtmlElement) => ParsedEmbed | null;
|
|
17
27
|
/** Embed code that is a single `<script>` tag, as Telegram's is. */
|
|
@@ -26,7 +36,5 @@ export type PlatformParser = {
|
|
|
26
36
|
allowsFbRoot?: boolean;
|
|
27
37
|
/** A sibling element after the embed that is the platform's own markup, such as a credit; it is dropped. */
|
|
28
38
|
isOwnExtra?: (element: HtmlElement, embed: ParsedEmbed) => boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ownsFrame?: (src: ParsedUrl) => boolean;
|
|
32
|
-
};
|
|
39
|
+
};
|
|
40
|
+
export type PlatformParser = PlatformMatcher & EmbedCode;
|
package/dist/parser/platform.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { pixels } from "./url.js";
|
|
2
2
|
// src/parser/platform.ts
|
|
3
|
+
/**
|
|
4
|
+
* Call it as `/* @__PURE__ *\/ parserOf(…)`. A minifier keeps an unused object literal that
|
|
5
|
+
* spreads another object, and with it every parser a scope-hoisted bundle holds (docs/decisions.md D118).
|
|
6
|
+
*/
|
|
7
|
+
function parserOf(matcher, code) {
|
|
8
|
+
return {
|
|
9
|
+
...matcher,
|
|
10
|
+
...code
|
|
11
|
+
};
|
|
12
|
+
}
|
|
3
13
|
/** `/embed` holds `/embed` and `/embed/…`, never `/embedded`. */
|
|
4
14
|
function underPath(path, folder) {
|
|
5
15
|
return path === folder || path.startsWith(`${folder}/`);
|
|
@@ -57,4 +67,4 @@ function unwrapRatio(root, pattern) {
|
|
|
57
67
|
function gcd(a, b) {
|
|
58
68
|
return b === 0 ? a : gcd(b, a % b);
|
|
59
69
|
}
|
|
60
|
-
export { attributeOptions, sizeOf, underPath, unwrapRatio, withSize };
|
|
70
|
+
export { attributeOptions, parserOf, sizeOf, underPath, unwrapRatio, withSize };
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import { sizeOf, withSize } from "../platform.js";
|
|
1
|
+
import { parserOf, sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { parseUrl } from "../url.js";
|
|
3
|
-
import { APPLE_MUSIC_FRAME_HOST
|
|
3
|
+
import { APPLE_MUSIC_FRAME_HOST } from "../frames.js";
|
|
4
|
+
import { appleContent, applemusicMatcher } from "../matchers/applemusic.js";
|
|
4
5
|
// src/parser/platforms/applemusic.ts
|
|
5
|
-
const
|
|
6
|
-
const SONG = /^\d{1,15}$/;
|
|
7
|
-
function appleContent(url, host) {
|
|
8
|
-
if (url?.host !== host) return null;
|
|
9
|
-
const [, country, type, id] = PATH.exec(url.path) ?? [];
|
|
10
|
-
if (country === void 0 || type === void 0 || id === void 0) return null;
|
|
11
|
-
if (type === "playlist" ? !id.startsWith("pl.") : !SONG.test(id)) return null;
|
|
12
|
-
const song = type === "album" ? url.query.get("i") : void 0;
|
|
13
|
-
if (song !== void 0 && !SONG.test(song)) return null;
|
|
14
|
-
return {
|
|
15
|
-
kind: "post",
|
|
16
|
-
url: `https://music.apple.com/${country}/${type}/${id}${song ? `?i=${song}` : ""}`,
|
|
17
|
-
id: song ?? id,
|
|
18
|
-
variant: "iframe"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const applemusic = {
|
|
22
|
-
platform: "applemusic",
|
|
23
|
-
name: "Apple Music",
|
|
24
|
-
shapes: ["post iframe"],
|
|
6
|
+
const applemusic = /* @__PURE__ */ parserOf(applemusicMatcher, {
|
|
25
7
|
parse(root) {
|
|
26
8
|
if (root.tag !== "iframe") return null;
|
|
27
9
|
const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), APPLE_MUSIC_FRAME_HOST);
|
|
@@ -33,15 +15,6 @@ const applemusic = {
|
|
|
33
15
|
options: {}
|
|
34
16
|
}, height === void 0 ? void 0 : { height });
|
|
35
17
|
},
|
|
36
|
-
isOwnScript: () => false
|
|
37
|
-
|
|
38
|
-
const found = appleContent(url, "music.apple.com");
|
|
39
|
-
return found && {
|
|
40
|
-
platform: "applemusic",
|
|
41
|
-
...found,
|
|
42
|
-
options: {}
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
ownsFrame: appleMusicFrame
|
|
46
|
-
};
|
|
18
|
+
isOwnScript: () => false
|
|
19
|
+
});
|
|
47
20
|
export { applemusic };
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import { sizeOf, withSize } from "../platform.js";
|
|
1
|
+
import { parserOf, sizeOf, withSize } from "../platform.js";
|
|
2
2
|
import { parseUrl } from "../url.js";
|
|
3
|
-
import { APPLE_PODCASTS_FRAME_HOST
|
|
3
|
+
import { APPLE_PODCASTS_FRAME_HOST } from "../frames.js";
|
|
4
|
+
import { applepodcastsMatcher, content } from "../matchers/applepodcasts.js";
|
|
4
5
|
// src/parser/platforms/applepodcasts.ts
|
|
5
|
-
const
|
|
6
|
-
const EPISODE = /^\d{1,15}$/;
|
|
7
|
-
function content(url, host) {
|
|
8
|
-
if (url?.host !== host) return null;
|
|
9
|
-
const [, country, show] = PATH.exec(url.path) ?? [];
|
|
10
|
-
if (country === void 0 || show === void 0) return null;
|
|
11
|
-
const episode = url.query.get("i");
|
|
12
|
-
if (episode !== void 0 && !EPISODE.test(episode)) return null;
|
|
13
|
-
return {
|
|
14
|
-
platform: "applepodcasts",
|
|
15
|
-
kind: "post",
|
|
16
|
-
url: `https://podcasts.apple.com/${country}/podcast/id${show}${episode ? `?i=${episode}` : ""}`,
|
|
17
|
-
id: episode ?? show,
|
|
18
|
-
variant: "iframe"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const applepodcasts = {
|
|
22
|
-
platform: "applepodcasts",
|
|
23
|
-
name: "Apple Podcasts",
|
|
24
|
-
shapes: ["post iframe"],
|
|
6
|
+
const applepodcasts = /* @__PURE__ */ parserOf(applepodcastsMatcher, {
|
|
25
7
|
parse(root) {
|
|
26
8
|
if (root.tag !== "iframe") return null;
|
|
27
9
|
const found = content(parseUrl(root.attrs.get("src") ?? ""), APPLE_PODCASTS_FRAME_HOST);
|
|
@@ -30,14 +12,6 @@ const applepodcasts = {
|
|
|
30
12
|
options: {}
|
|
31
13
|
}, sizeOf(root));
|
|
32
14
|
},
|
|
33
|
-
isOwnScript: () => false
|
|
34
|
-
|
|
35
|
-
const found = content(url, "podcasts.apple.com");
|
|
36
|
-
return found && {
|
|
37
|
-
...found,
|
|
38
|
-
options: {}
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
ownsFrame: applePodcastsFrame
|
|
42
|
-
};
|
|
15
|
+
isOwnScript: () => false
|
|
16
|
+
});
|
|
43
17
|
export { applepodcasts };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { descendants, hasClass, rebuild
|
|
1
|
+
import { parserOf } from "../platform.js";
|
|
2
|
+
import { descendants, hasClass, rebuild } from "../html.js";
|
|
3
3
|
import { parseUrl } from "../url.js";
|
|
4
|
+
import { DID, FALLBACK, RKEY, blueskyMatcher, fromUrl, post } from "../matchers/bluesky.js";
|
|
4
5
|
// src/parser/platforms/bluesky.ts
|
|
5
|
-
const
|
|
6
|
-
const RKEY = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9._~:-]{1,512})";
|
|
7
|
-
const HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
|
|
8
|
-
const POST_PATH = new RegExp(`^/profile/${DID}/post/${RKEY}/?$`);
|
|
9
|
-
const AT_URI = new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
|
|
6
|
+
const AT_URI = /* @__PURE__ */ new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
|
|
10
7
|
const CID = /^[a-z2-7]{20,100}$/;
|
|
11
8
|
const COLOR_MODES = /* @__PURE__ */ new Set([
|
|
12
9
|
"light",
|
|
@@ -14,31 +11,7 @@ const COLOR_MODES = /* @__PURE__ */ new Set([
|
|
|
14
11
|
"system"
|
|
15
12
|
]);
|
|
16
13
|
const SCRIPT = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
|
|
17
|
-
const
|
|
18
|
-
["p", ["lang"]],
|
|
19
|
-
["a", ["href"]],
|
|
20
|
-
["br", []]
|
|
21
|
-
]);
|
|
22
|
-
function post(did, rkey) {
|
|
23
|
-
return {
|
|
24
|
-
platform: "bluesky",
|
|
25
|
-
kind: "post",
|
|
26
|
-
url: `https://bsky.app/profile/${did}/post/${rkey}`,
|
|
27
|
-
id: `${did}/app.bsky.feed.post/${rkey}`,
|
|
28
|
-
variant: "iframe"
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function fromUrl(url) {
|
|
32
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
33
|
-
const [, did, rkey] = POST_PATH.exec(url.path) ?? [];
|
|
34
|
-
return did === void 0 || rkey === void 0 ? null : post(did, rkey);
|
|
35
|
-
}
|
|
36
|
-
const bluesky = {
|
|
37
|
-
platform: "bluesky",
|
|
38
|
-
name: "Bluesky",
|
|
39
|
-
shapes: ["post iframe"],
|
|
40
|
-
needsLookup: blueskyNeedsLookup,
|
|
41
|
-
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
14
|
+
const bluesky = /* @__PURE__ */ parserOf(blueskyMatcher, {
|
|
42
15
|
parse(root) {
|
|
43
16
|
if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
|
|
44
17
|
const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
|
|
@@ -56,13 +29,6 @@ const bluesky = {
|
|
|
56
29
|
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
57
30
|
};
|
|
58
31
|
},
|
|
59
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
60
|
-
|
|
61
|
-
const found = fromUrl(url);
|
|
62
|
-
return found && {
|
|
63
|
-
...found,
|
|
64
|
-
options: {}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
32
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
33
|
+
});
|
|
68
34
|
export { bluesky };
|
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
import { sizeOf, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { parserOf, sizeOf, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
import { dailymotionMatcher, fromPage, fromPlayer } from "../matchers/dailymotion.js";
|
|
4
4
|
// src/parser/platforms/dailymotion.ts
|
|
5
|
-
const VIDEO_ID = /^x[a-z0-9]{4,12}$/;
|
|
6
|
-
const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
|
|
7
5
|
const WRAPPER = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
platform: "dailymotion",
|
|
11
|
-
kind: "video",
|
|
12
|
-
url: `https://www.dailymotion.com/video/${id}`,
|
|
13
|
-
id,
|
|
14
|
-
variant: "iframe",
|
|
15
|
-
options
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
|
|
19
|
-
function fromPlayer(url) {
|
|
20
|
-
if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
|
|
21
|
-
const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
|
|
22
|
-
if (!match) return null;
|
|
23
|
-
const [, playerId] = match;
|
|
24
|
-
const id = url.query.get("video") ?? "";
|
|
25
|
-
if (!VIDEO_ID.test(id)) return null;
|
|
26
|
-
if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
|
|
27
|
-
const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
|
|
28
|
-
if (playerId !== void 0) options.playerId = playerId;
|
|
29
|
-
return video(id, options);
|
|
30
|
-
}
|
|
31
|
-
function fromPage(url) {
|
|
32
|
-
if (url.host === "dai.ly") {
|
|
33
|
-
const id = url.path.replace(/^\/|\/$/g, "");
|
|
34
|
-
return VIDEO_ID.test(id) ? video(id, {}) : null;
|
|
35
|
-
}
|
|
36
|
-
if (!DAILYMOTION_HOSTS.has(url.host)) return null;
|
|
37
|
-
const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
|
|
38
|
-
return id !== void 0 && VIDEO_ID.test(id) ? video(id, {}) : null;
|
|
39
|
-
}
|
|
40
|
-
const dailymotion = {
|
|
41
|
-
platform: "dailymotion",
|
|
42
|
-
name: "Dailymotion",
|
|
43
|
-
shapes: ["video iframe"],
|
|
6
|
+
const dailymotion = /* @__PURE__ */ parserOf(dailymotionMatcher, {
|
|
44
7
|
parse(root) {
|
|
45
8
|
const wrapped = unwrapRatio(root, WRAPPER);
|
|
46
9
|
const iframe = wrapped?.iframe ?? root;
|
|
@@ -50,10 +13,6 @@ const dailymotion = {
|
|
|
50
13
|
const embed = fromPlayer(src) ?? fromPage(src);
|
|
51
14
|
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
52
15
|
},
|
|
53
|
-
isOwnScript: () => false
|
|
54
|
-
|
|
55
|
-
return fromPlayer(url) ?? fromPage(url);
|
|
56
|
-
},
|
|
57
|
-
ownsFrame: dailymotionFrame
|
|
58
|
-
};
|
|
16
|
+
isOwnScript: () => false
|
|
17
|
+
});
|
|
59
18
|
export { dailymotion };
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import { hasClass, rebuild
|
|
2
|
-
import { attributeOptions, sizeOf, withSize } from "../platform.js";
|
|
1
|
+
import { hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { attributeOptions, parserOf, sizeOf, withSize } from "../platform.js";
|
|
3
3
|
import { coerce, parseUrl, pixels } from "../url.js";
|
|
4
|
-
import { FACEBOOK_PLUGIN_HOSTS
|
|
4
|
+
import { FACEBOOK_PLUGIN_HOSTS } from "../frames.js";
|
|
5
|
+
import { FALLBACK, embed, facebookMatcher, target } from "../matchers/facebook.js";
|
|
5
6
|
// src/parser/platforms/facebook.ts
|
|
6
|
-
const HOSTS = /* @__PURE__ */ new Set([
|
|
7
|
-
"facebook.com",
|
|
8
|
-
"www.facebook.com",
|
|
9
|
-
"web.facebook.com",
|
|
10
|
-
"m.facebook.com"
|
|
11
|
-
]);
|
|
12
|
-
const BASE = "https://www.facebook.com";
|
|
13
|
-
const NAME = "[A-Za-z0-9.\\-]{1,80}";
|
|
14
|
-
const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
|
|
15
|
-
const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
16
|
-
const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.\\-]{1,80})/(\\d{1,25})/?$`);
|
|
17
|
-
const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
18
|
-
const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
|
|
19
|
-
const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
|
|
20
|
-
const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
21
|
-
"/photo.php",
|
|
22
|
-
"/photo/",
|
|
23
|
-
"/photo"
|
|
24
|
-
]);
|
|
25
|
-
const STORY_ID = new RegExp(`^${POST_ID}$`);
|
|
26
|
-
const NUMERIC_ID = /^\d{1,25}$/;
|
|
27
7
|
const SCRIPT = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
|
|
28
8
|
const OPTION_ATTRIBUTES = [
|
|
29
9
|
["data-width", "width"],
|
|
@@ -39,93 +19,7 @@ const VIDEO_SDK_PARAMETERS = [
|
|
|
39
19
|
["autoplay", "autoplay"],
|
|
40
20
|
["show_captions", "showCaptions"]
|
|
41
21
|
];
|
|
42
|
-
const
|
|
43
|
-
name: "class",
|
|
44
|
-
value: /^fb-xfbml-parse-ignore$/
|
|
45
|
-
};
|
|
46
|
-
const FALLBACK = /* @__PURE__ */ new Map([
|
|
47
|
-
["div", [PARSE_IGNORE]],
|
|
48
|
-
["blockquote", ["cite", PARSE_IGNORE]],
|
|
49
|
-
["a", ["href"]],
|
|
50
|
-
["p", []]
|
|
51
|
-
]);
|
|
52
|
-
function target(url) {
|
|
53
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
54
|
-
const { path, query } = url;
|
|
55
|
-
const [, name, postId] = POSTS_PATH.exec(path) ?? [];
|
|
56
|
-
if (name !== void 0 && postId !== void 0) return {
|
|
57
|
-
kind: "post",
|
|
58
|
-
id: postId,
|
|
59
|
-
url: `${BASE}/${name}/posts/${postId}`
|
|
60
|
-
};
|
|
61
|
-
if (STORY_PATHS.has(path)) {
|
|
62
|
-
const storyId = query.get("story_fbid");
|
|
63
|
-
if (storyId === void 0 || !STORY_ID.test(storyId)) return null;
|
|
64
|
-
const owner = query.get("id");
|
|
65
|
-
const ownerQuery = owner !== void 0 && NUMERIC_ID.test(owner) ? `&id=${owner}` : "";
|
|
66
|
-
return {
|
|
67
|
-
kind: "post",
|
|
68
|
-
id: storyId,
|
|
69
|
-
url: `${BASE}${path}?story_fbid=${storyId}${ownerQuery}`
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (PHOTO_PATHS.has(path)) {
|
|
73
|
-
const fbid = query.get("fbid");
|
|
74
|
-
if (fbid === void 0 || !NUMERIC_ID.test(fbid)) return null;
|
|
75
|
-
return {
|
|
76
|
-
kind: "post",
|
|
77
|
-
id: fbid,
|
|
78
|
-
url: `${BASE}${path}?fbid=${fbid}`
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const [, owner, album, photoId] = PHOTOS_PATH.exec(path) ?? [];
|
|
82
|
-
if (owner !== void 0 && album !== void 0 && photoId !== void 0) return {
|
|
83
|
-
kind: "post",
|
|
84
|
-
id: photoId,
|
|
85
|
-
url: `${BASE}/${owner}/photos/${album}/${photoId}/`
|
|
86
|
-
};
|
|
87
|
-
const [, page, videoId] = VIDEOS_PATH.exec(path) ?? [];
|
|
88
|
-
if (page !== void 0 && videoId !== void 0) return {
|
|
89
|
-
kind: "video",
|
|
90
|
-
id: videoId,
|
|
91
|
-
url: `${BASE}/${page}/videos/${videoId}/`
|
|
92
|
-
};
|
|
93
|
-
if (path === "/watch" || path === "/watch/" || path === "/video.php") {
|
|
94
|
-
const v = query.get("v");
|
|
95
|
-
if (v === void 0 || !NUMERIC_ID.test(v)) return null;
|
|
96
|
-
return {
|
|
97
|
-
kind: "video",
|
|
98
|
-
id: v,
|
|
99
|
-
url: `${BASE}${path === "/video.php" ? path : "/watch/"}?v=${v}`
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const [, reelId] = REEL_PATH.exec(path) ?? [];
|
|
103
|
-
if (reelId !== void 0) return {
|
|
104
|
-
kind: "video",
|
|
105
|
-
id: reelId,
|
|
106
|
-
url: `${BASE}/reel/${reelId}`
|
|
107
|
-
};
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
function embed(found, kind, variant, options) {
|
|
111
|
-
return {
|
|
112
|
-
platform: "facebook",
|
|
113
|
-
kind,
|
|
114
|
-
url: found.url,
|
|
115
|
-
id: found.id,
|
|
116
|
-
variant,
|
|
117
|
-
options
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
const facebook = {
|
|
121
|
-
platform: "facebook",
|
|
122
|
-
name: "Facebook",
|
|
123
|
-
shapes: [
|
|
124
|
-
"post sdk",
|
|
125
|
-
"video sdk",
|
|
126
|
-
"video iframe"
|
|
127
|
-
],
|
|
128
|
-
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
22
|
+
const facebook = /* @__PURE__ */ parserOf(facebookMatcher, {
|
|
129
23
|
parse(root) {
|
|
130
24
|
if (root.tag === "div") {
|
|
131
25
|
const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
|
|
@@ -177,11 +71,6 @@ const facebook = {
|
|
|
177
71
|
const [, locale] = SCRIPT.exec(src) ?? [];
|
|
178
72
|
return locale === void 0 ? {} : { locale };
|
|
179
73
|
},
|
|
180
|
-
allowsFbRoot: true
|
|
181
|
-
|
|
182
|
-
const found = target(url);
|
|
183
|
-
return found && embed(found, found.kind, "sdk", {});
|
|
184
|
-
},
|
|
185
|
-
ownsFrame: facebookFrame
|
|
186
|
-
};
|
|
74
|
+
allowsFbRoot: true
|
|
75
|
+
});
|
|
187
76
|
export { facebook };
|
|
@@ -1,97 +1,14 @@
|
|
|
1
|
-
import { rebuild
|
|
2
|
-
import { sizeOf, withSize } from "../platform.js";
|
|
1
|
+
import { rebuild } from "../html.js";
|
|
2
|
+
import { parserOf, sizeOf, withSize } from "../platform.js";
|
|
3
3
|
import { parseUrl } from "../url.js";
|
|
4
|
+
import { FALLBACK, IMAGE_SRC, flickrMatcher, fromLongUrl } from "../matchers/flickr.js";
|
|
4
5
|
// src/parser/platforms/flickr.ts
|
|
5
|
-
const HOSTS = /* @__PURE__ */ new Set(["flickr.com", "www.flickr.com"]);
|
|
6
|
-
const USER = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9@_.-]{1,64})";
|
|
7
|
-
const ID = "(\\d{1,20})";
|
|
8
|
-
const PHOTO_PATH = new RegExp(`^/photos/${USER}/${ID}(?:/in/[A-Za-z0-9_@./-]{1,200})?/?$`);
|
|
9
|
-
const ALBUM_PATH = new RegExp(`^/photos/${USER}/(?:albums|sets)/${ID}/?$`);
|
|
10
|
-
const SHORT_PATH = /^\/p\/([1-9a-km-zA-HJ-NP-Z]{1,12})$/;
|
|
11
6
|
const SCRIPT = /^(?:https?:)?\/\/embedr\.flickr\.com\/assets\/client-code\.js$/;
|
|
12
|
-
const ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
13
7
|
const OPTIONS = [
|
|
14
8
|
"header",
|
|
15
9
|
"footer",
|
|
16
10
|
"context"
|
|
17
11
|
];
|
|
18
|
-
const IMAGE_SRC = /^https:\/\/(?:live|farm\d{1,3})\.staticflickr\.com\//;
|
|
19
|
-
const FALLBACK = /* @__PURE__ */ new Map([["a", [{
|
|
20
|
-
name: "href",
|
|
21
|
-
value: /^https:\/\/(?:www\.)?flickr\.com\//
|
|
22
|
-
}]], ["img", [
|
|
23
|
-
{
|
|
24
|
-
name: "src",
|
|
25
|
-
value: IMAGE_SRC
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: "width",
|
|
29
|
-
value: /^\d{1,6}$/
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "height",
|
|
33
|
-
value: /^\d{1,6}$/
|
|
34
|
-
},
|
|
35
|
-
"alt"
|
|
36
|
-
]]]);
|
|
37
|
-
/** 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. */
|
|
38
|
-
function decodeFlickrCode(code) {
|
|
39
|
-
if (code === "") return null;
|
|
40
|
-
let id = 0n;
|
|
41
|
-
for (const character of code) {
|
|
42
|
-
const digit = ALPHABET.indexOf(character);
|
|
43
|
-
if (digit === -1) return null;
|
|
44
|
-
id = id * 58n + BigInt(digit);
|
|
45
|
-
}
|
|
46
|
-
return id.toString();
|
|
47
|
-
}
|
|
48
|
-
function encodeFlickrCode(id) {
|
|
49
|
-
let rest = BigInt(id);
|
|
50
|
-
let code = "";
|
|
51
|
-
while (rest > 0n) {
|
|
52
|
-
code = ALPHABET.charAt(Number(rest % 58n)) + code;
|
|
53
|
-
rest /= 58n;
|
|
54
|
-
}
|
|
55
|
-
return code;
|
|
56
|
-
}
|
|
57
|
-
function photo(user, id) {
|
|
58
|
-
return {
|
|
59
|
-
platform: "flickr",
|
|
60
|
-
kind: "post",
|
|
61
|
-
url: `https://www.flickr.com/photos/${user}/${id}/`,
|
|
62
|
-
id,
|
|
63
|
-
variant: "iframe"
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function album(user, id) {
|
|
67
|
-
return {
|
|
68
|
-
platform: "flickr",
|
|
69
|
-
kind: "post",
|
|
70
|
-
url: `https://www.flickr.com/photos/${user}/albums/${id}`,
|
|
71
|
-
id,
|
|
72
|
-
variant: "iframe"
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function fromLongUrl(url) {
|
|
76
|
-
if (!url || !HOSTS.has(url.host)) return null;
|
|
77
|
-
const [, albumUser, albumId] = ALBUM_PATH.exec(url.path) ?? [];
|
|
78
|
-
if (albumUser !== void 0 && albumId !== void 0) return album(albumUser, albumId);
|
|
79
|
-
const [, user, id] = PHOTO_PATH.exec(url.path) ?? [];
|
|
80
|
-
return user === void 0 || id === void 0 ? null : photo(user, id);
|
|
81
|
-
}
|
|
82
|
-
function fromShortUrl(url) {
|
|
83
|
-
if (url.host !== "flic.kr") return null;
|
|
84
|
-
const [, code] = SHORT_PATH.exec(url.path) ?? [];
|
|
85
|
-
const id = code === void 0 ? null : decodeFlickrCode(code);
|
|
86
|
-
if (code === void 0 || id === null || encodeFlickrCode(id) !== code) return null;
|
|
87
|
-
return {
|
|
88
|
-
platform: "flickr",
|
|
89
|
-
kind: "post",
|
|
90
|
-
url: `https://flic.kr/p/${code}`,
|
|
91
|
-
id,
|
|
92
|
-
variant: "iframe"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
12
|
function onlyImage(root) {
|
|
96
13
|
let image = null;
|
|
97
14
|
for (const child of root.children) {
|
|
@@ -101,11 +18,7 @@ function onlyImage(root) {
|
|
|
101
18
|
}
|
|
102
19
|
return image;
|
|
103
20
|
}
|
|
104
|
-
const flickr = {
|
|
105
|
-
platform: "flickr",
|
|
106
|
-
name: "Flickr",
|
|
107
|
-
shapes: ["post iframe"],
|
|
108
|
-
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
21
|
+
const flickr = /* @__PURE__ */ parserOf(flickrMatcher, {
|
|
109
22
|
parse(root) {
|
|
110
23
|
if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
|
|
111
24
|
const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
|
|
@@ -124,13 +37,6 @@ const flickr = {
|
|
|
124
37
|
fallbackHtml: rebuild([linked], FALLBACK)
|
|
125
38
|
}, size?.width !== void 0 && size.height !== void 0 ? size : void 0);
|
|
126
39
|
},
|
|
127
|
-
isOwnScript: (src) => SCRIPT.test(src)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return found && {
|
|
131
|
-
...found,
|
|
132
|
-
options: {}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
export { decodeFlickrCode, flickr };
|
|
40
|
+
isOwnScript: (src) => SCRIPT.test(src)
|
|
41
|
+
});
|
|
42
|
+
export { flickr };
|