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,60 @@
|
|
|
1
|
+
import { pixels } from "./url.js";
|
|
2
|
+
// src/parser/platform.ts
|
|
3
|
+
/** `/embed` holds `/embed` and `/embed/…`, never `/embedded`. */
|
|
4
|
+
function underPath(path, folder) {
|
|
5
|
+
return path === folder || path.startsWith(`${folder}/`);
|
|
6
|
+
}
|
|
7
|
+
/** The first attribute present for a key wins. */
|
|
8
|
+
function attributeOptions(element, mapping, coerceValue) {
|
|
9
|
+
const options = {};
|
|
10
|
+
for (const [attribute, key] of mapping) {
|
|
11
|
+
const value = element.attrs.get(attribute);
|
|
12
|
+
if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
|
|
13
|
+
}
|
|
14
|
+
return options;
|
|
15
|
+
}
|
|
16
|
+
function sizeOf(element) {
|
|
17
|
+
const width = pixels(element.attrs.get("width"));
|
|
18
|
+
const height = pixels(element.attrs.get("height"));
|
|
19
|
+
if (width === void 0 && height === void 0) return void 0;
|
|
20
|
+
return {
|
|
21
|
+
...width === void 0 ? {} : { width },
|
|
22
|
+
...height === void 0 ? {} : { height }
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Adds `size` only when known, so results stay free of `undefined` properties. */
|
|
26
|
+
function withSize(embed, size) {
|
|
27
|
+
return size ? {
|
|
28
|
+
...embed,
|
|
29
|
+
size
|
|
30
|
+
} : embed;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A platform's own responsive wrapper: a `div` whose only attribute is a `style` that `pattern`
|
|
34
|
+
* matches, around one iframe. The padding percentage it captures is the video's ratio.
|
|
35
|
+
*/
|
|
36
|
+
function unwrapRatio(root, pattern) {
|
|
37
|
+
if (root.tag !== "div" || root.attrs.size !== 1) return null;
|
|
38
|
+
const [, percent] = pattern.exec(root.attrs.get("style") ?? "") ?? [];
|
|
39
|
+
if (percent === void 0) return null;
|
|
40
|
+
let iframe;
|
|
41
|
+
for (const child of root.children) {
|
|
42
|
+
if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
|
|
43
|
+
if (child.type !== "element" || child.tag !== "iframe" || iframe) return null;
|
|
44
|
+
iframe = child;
|
|
45
|
+
}
|
|
46
|
+
const height = Math.round(Number(percent) * 100);
|
|
47
|
+
if (!iframe || !(height > 0 && height <= 1e5)) return null;
|
|
48
|
+
const divisor = gcd(1e4, height);
|
|
49
|
+
return {
|
|
50
|
+
iframe,
|
|
51
|
+
size: {
|
|
52
|
+
width: 1e4 / divisor,
|
|
53
|
+
height: height / divisor
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function gcd(a, b) {
|
|
58
|
+
return b === 0 ? a : gcd(b, a % b);
|
|
59
|
+
}
|
|
60
|
+
export { attributeOptions, sizeOf, underPath, unwrapRatio, withSize };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { sizeOf, withSize } from "../platform.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/applemusic.ts
|
|
4
|
+
const PATH = /^\/([a-z]{2})\/(album|song|playlist)\/(?:[^/]{1,200}\/)?(\d{1,15}|pl\.[A-Za-z0-9-]{1,64})\/?$/;
|
|
5
|
+
const SONG = /^\d{1,15}$/;
|
|
6
|
+
const FRAME_HOST = "embed.music.apple.com";
|
|
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
|
+
parse(root) {
|
|
24
|
+
if (root.tag !== "iframe") return null;
|
|
25
|
+
const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST);
|
|
26
|
+
if (!found) return null;
|
|
27
|
+
const { height } = sizeOf(root) ?? {};
|
|
28
|
+
return withSize({
|
|
29
|
+
platform: "applemusic",
|
|
30
|
+
...found,
|
|
31
|
+
options: {}
|
|
32
|
+
}, height === void 0 ? void 0 : { height });
|
|
33
|
+
},
|
|
34
|
+
isOwnScript: () => false,
|
|
35
|
+
match(url) {
|
|
36
|
+
const found = appleContent(url, "music.apple.com");
|
|
37
|
+
return found && {
|
|
38
|
+
platform: "applemusic",
|
|
39
|
+
...found,
|
|
40
|
+
options: {}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
ownsFrame: (src) => src.host === FRAME_HOST
|
|
44
|
+
};
|
|
45
|
+
export { applemusic };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { sizeOf, withSize } from "../platform.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/applepodcasts.ts
|
|
4
|
+
const PATH = /^\/([a-z]{2})\/podcast\/(?:[^/]{1,200}\/)?(?:id)?(\d{1,15})\/?$/;
|
|
5
|
+
const EPISODE = /^\d{1,15}$/;
|
|
6
|
+
const FRAME_HOST = "embed.podcasts.apple.com";
|
|
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
|
+
parse(root) {
|
|
24
|
+
if (root.tag !== "iframe") return null;
|
|
25
|
+
const found = content(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST);
|
|
26
|
+
return found && withSize({
|
|
27
|
+
...found,
|
|
28
|
+
options: {}
|
|
29
|
+
}, sizeOf(root));
|
|
30
|
+
},
|
|
31
|
+
isOwnScript: () => false,
|
|
32
|
+
match(url) {
|
|
33
|
+
const found = content(url, "podcasts.apple.com");
|
|
34
|
+
return found && {
|
|
35
|
+
...found,
|
|
36
|
+
options: {}
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
ownsFrame: (src) => src.host === FRAME_HOST
|
|
40
|
+
};
|
|
41
|
+
export { applepodcasts };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { descendants, hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/bluesky.ts
|
|
4
|
+
const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
|
|
5
|
+
const RKEY = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9._~:-]{1,512})";
|
|
6
|
+
const HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
|
|
7
|
+
const POST_PATH = new RegExp(`^/profile/${DID}/post/${RKEY}/?$`);
|
|
8
|
+
const AT_URI = new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
|
|
9
|
+
const CID = /^[a-z2-7]{20,100}$/;
|
|
10
|
+
const COLOR_MODES = /* @__PURE__ */ new Set([
|
|
11
|
+
"light",
|
|
12
|
+
"dark",
|
|
13
|
+
"system"
|
|
14
|
+
]);
|
|
15
|
+
const SCRIPT = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
|
|
16
|
+
const FALLBACK = /* @__PURE__ */ new Map([
|
|
17
|
+
["p", ["lang"]],
|
|
18
|
+
["a", ["href"]],
|
|
19
|
+
["br", []]
|
|
20
|
+
]);
|
|
21
|
+
function post(did, rkey) {
|
|
22
|
+
return {
|
|
23
|
+
platform: "bluesky",
|
|
24
|
+
kind: "post",
|
|
25
|
+
url: `https://bsky.app/profile/${did}/post/${rkey}`,
|
|
26
|
+
id: `${did}/app.bsky.feed.post/${rkey}`,
|
|
27
|
+
variant: "iframe"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function fromUrl(url) {
|
|
31
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
32
|
+
const [, did, rkey] = POST_PATH.exec(url.path) ?? [];
|
|
33
|
+
return did === void 0 || rkey === void 0 ? null : post(did, rkey);
|
|
34
|
+
}
|
|
35
|
+
const bluesky = {
|
|
36
|
+
platform: "bluesky",
|
|
37
|
+
fallback: FALLBACK,
|
|
38
|
+
parse(root) {
|
|
39
|
+
if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
|
|
40
|
+
const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
|
|
41
|
+
if (did === void 0 || rkey === void 0) return null;
|
|
42
|
+
const found = post(did, rkey);
|
|
43
|
+
if (descendants(root.children).reverse().map((element) => element.tag === "a" ? fromUrl(parseUrl(element.attrs.get("href") ?? "")) : null).find((linked) => linked !== null)?.id !== found.id) return null;
|
|
44
|
+
const options = {};
|
|
45
|
+
const cid = root.attrs.get("data-bluesky-cid");
|
|
46
|
+
if (cid !== void 0 && CID.test(cid)) options.cid = cid;
|
|
47
|
+
const colorMode = root.attrs.get("data-bluesky-embed-color-mode");
|
|
48
|
+
if (colorMode !== void 0 && COLOR_MODES.has(colorMode)) options.colorMode = colorMode;
|
|
49
|
+
return {
|
|
50
|
+
...found,
|
|
51
|
+
options,
|
|
52
|
+
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
56
|
+
match(url) {
|
|
57
|
+
const found = fromUrl(url);
|
|
58
|
+
return found && {
|
|
59
|
+
...found,
|
|
60
|
+
options: {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export { bluesky };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
+
import { coerce, parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/dailymotion.ts
|
|
4
|
+
const VIDEO_ID = /^x[a-z0-9]{4,12}$/;
|
|
5
|
+
const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
|
|
6
|
+
const WRAPPER = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
|
|
7
|
+
const HOSTS = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
|
|
8
|
+
const PLAYER_HOST = "geo.dailymotion.com";
|
|
9
|
+
const SHORT_HOST = "dai.ly";
|
|
10
|
+
function video(id, options) {
|
|
11
|
+
return {
|
|
12
|
+
platform: "dailymotion",
|
|
13
|
+
kind: "video",
|
|
14
|
+
url: `https://www.dailymotion.com/video/${id}`,
|
|
15
|
+
id,
|
|
16
|
+
variant: "iframe",
|
|
17
|
+
options
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
|
|
21
|
+
function fromPlayer(url) {
|
|
22
|
+
if (url.host !== PLAYER_HOST || url.query.has("playlist")) return null;
|
|
23
|
+
const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
|
|
24
|
+
if (!match) return null;
|
|
25
|
+
const [, playerId] = match;
|
|
26
|
+
const id = url.query.get("video") ?? "";
|
|
27
|
+
if (!VIDEO_ID.test(id)) return null;
|
|
28
|
+
if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
|
|
29
|
+
const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
|
|
30
|
+
if (playerId !== void 0) options.playerId = playerId;
|
|
31
|
+
return video(id, options);
|
|
32
|
+
}
|
|
33
|
+
function fromPage(url) {
|
|
34
|
+
if (url.host === SHORT_HOST) {
|
|
35
|
+
const id = url.path.replace(/^\/|\/$/g, "");
|
|
36
|
+
return VIDEO_ID.test(id) ? video(id, {}) : null;
|
|
37
|
+
}
|
|
38
|
+
if (!HOSTS.has(url.host)) return null;
|
|
39
|
+
const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
|
|
40
|
+
return id !== void 0 && VIDEO_ID.test(id) ? video(id, {}) : null;
|
|
41
|
+
}
|
|
42
|
+
const dailymotion = {
|
|
43
|
+
platform: "dailymotion",
|
|
44
|
+
parse(root) {
|
|
45
|
+
const wrapped = unwrapRatio(root, WRAPPER);
|
|
46
|
+
const iframe = wrapped?.iframe ?? root;
|
|
47
|
+
if (iframe.tag !== "iframe") return null;
|
|
48
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
49
|
+
if (!src) return null;
|
|
50
|
+
const embed = fromPlayer(src) ?? fromPage(src);
|
|
51
|
+
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
52
|
+
},
|
|
53
|
+
isOwnScript: () => false,
|
|
54
|
+
match(url) {
|
|
55
|
+
return fromPlayer(url) ?? fromPage(url);
|
|
56
|
+
},
|
|
57
|
+
ownsFrame: (src) => src.host === PLAYER_HOST || src.host === SHORT_HOST || HOSTS.has(src.host) && (underPath(src.path, "/embed") || underPath(src.path, "/video"))
|
|
58
|
+
};
|
|
59
|
+
export { dailymotion };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { hasClass, rebuild } from "../html.js";
|
|
2
|
+
import { attributeOptions, sizeOf, underPath, withSize } from "../platform.js";
|
|
3
|
+
import { coerce, parseUrl, pixels } from "../url.js";
|
|
4
|
+
// src/parser/platforms/facebook.ts
|
|
5
|
+
const HOSTS = /* @__PURE__ */ new Set([
|
|
6
|
+
"facebook.com",
|
|
7
|
+
"www.facebook.com",
|
|
8
|
+
"web.facebook.com",
|
|
9
|
+
"m.facebook.com"
|
|
10
|
+
]);
|
|
11
|
+
const PLUGIN_HOSTS = /* @__PURE__ */ new Set([
|
|
12
|
+
"facebook.com",
|
|
13
|
+
"www.facebook.com",
|
|
14
|
+
"web.facebook.com"
|
|
15
|
+
]);
|
|
16
|
+
const BASE = "https://www.facebook.com";
|
|
17
|
+
const NAME = "[A-Za-z0-9.\\-]{1,80}";
|
|
18
|
+
const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
|
|
19
|
+
const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
20
|
+
const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
|
|
21
|
+
const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
22
|
+
const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
|
|
23
|
+
const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
|
|
24
|
+
const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
25
|
+
"/photo.php",
|
|
26
|
+
"/photo/",
|
|
27
|
+
"/photo"
|
|
28
|
+
]);
|
|
29
|
+
const STORY_ID = new RegExp(`^${POST_ID}$`);
|
|
30
|
+
const NUMERIC_ID = /^\d{1,25}$/;
|
|
31
|
+
const SCRIPT = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
|
|
32
|
+
const OPTION_ATTRIBUTES = [
|
|
33
|
+
["data-width", "width"],
|
|
34
|
+
["data-show-text", "showText"],
|
|
35
|
+
["data-lazy", "lazy"],
|
|
36
|
+
["data-allowfullscreen", "allowfullscreen"],
|
|
37
|
+
["data-autoplay", "autoplay"],
|
|
38
|
+
["data-show-captions", "showCaptions"]
|
|
39
|
+
];
|
|
40
|
+
const VIDEO_SDK_PARAMETERS = [
|
|
41
|
+
["show_text", "showText"],
|
|
42
|
+
["allowfullscreen", "allowfullscreen"],
|
|
43
|
+
["autoplay", "autoplay"],
|
|
44
|
+
["show_captions", "showCaptions"]
|
|
45
|
+
];
|
|
46
|
+
const PARSE_IGNORE = {
|
|
47
|
+
name: "class",
|
|
48
|
+
value: /^fb-xfbml-parse-ignore$/
|
|
49
|
+
};
|
|
50
|
+
const FALLBACK = /* @__PURE__ */ new Map([
|
|
51
|
+
["div", [PARSE_IGNORE]],
|
|
52
|
+
["blockquote", ["cite", PARSE_IGNORE]],
|
|
53
|
+
["a", ["href"]],
|
|
54
|
+
["p", []]
|
|
55
|
+
]);
|
|
56
|
+
function target(url) {
|
|
57
|
+
if (!url || !HOSTS.has(url.host)) return null;
|
|
58
|
+
const { path, query } = url;
|
|
59
|
+
const [, name, postId] = POSTS_PATH.exec(path) ?? [];
|
|
60
|
+
if (name !== void 0 && postId !== void 0) return {
|
|
61
|
+
kind: "post",
|
|
62
|
+
id: postId,
|
|
63
|
+
url: `${BASE}/${name}/posts/${postId}`
|
|
64
|
+
};
|
|
65
|
+
if (STORY_PATHS.has(path)) {
|
|
66
|
+
const storyId = query.get("story_fbid");
|
|
67
|
+
if (storyId === void 0 || !STORY_ID.test(storyId)) return null;
|
|
68
|
+
const owner = query.get("id");
|
|
69
|
+
const ownerQuery = owner !== void 0 && NUMERIC_ID.test(owner) ? `&id=${owner}` : "";
|
|
70
|
+
return {
|
|
71
|
+
kind: "post",
|
|
72
|
+
id: storyId,
|
|
73
|
+
url: `${BASE}${path}?story_fbid=${storyId}${ownerQuery}`
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (PHOTO_PATHS.has(path)) {
|
|
77
|
+
const fbid = query.get("fbid");
|
|
78
|
+
if (fbid === void 0 || !NUMERIC_ID.test(fbid)) return null;
|
|
79
|
+
return {
|
|
80
|
+
kind: "post",
|
|
81
|
+
id: fbid,
|
|
82
|
+
url: `${BASE}${path}?fbid=${fbid}`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const [, owner, album, photoId] = PHOTOS_PATH.exec(path) ?? [];
|
|
86
|
+
if (owner !== void 0 && album !== void 0 && photoId !== void 0) return {
|
|
87
|
+
kind: "post",
|
|
88
|
+
id: photoId,
|
|
89
|
+
url: `${BASE}/${owner}/photos/${album}/${photoId}/`
|
|
90
|
+
};
|
|
91
|
+
const [, page, videoId] = VIDEOS_PATH.exec(path) ?? [];
|
|
92
|
+
if (page !== void 0 && videoId !== void 0) return {
|
|
93
|
+
kind: "video",
|
|
94
|
+
id: videoId,
|
|
95
|
+
url: `${BASE}/${page}/videos/${videoId}/`
|
|
96
|
+
};
|
|
97
|
+
if (path === "/watch" || path === "/watch/" || path === "/video.php") {
|
|
98
|
+
const v = query.get("v");
|
|
99
|
+
if (v === void 0 || !NUMERIC_ID.test(v)) return null;
|
|
100
|
+
return {
|
|
101
|
+
kind: "video",
|
|
102
|
+
id: v,
|
|
103
|
+
url: `${BASE}${path === "/video.php" ? path : "/watch/"}?v=${v}`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const [, reelId] = REEL_PATH.exec(path) ?? [];
|
|
107
|
+
if (reelId !== void 0) return {
|
|
108
|
+
kind: "video",
|
|
109
|
+
id: reelId,
|
|
110
|
+
url: `${BASE}/reel/${reelId}`
|
|
111
|
+
};
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
function embed(found, kind, variant, options) {
|
|
115
|
+
return {
|
|
116
|
+
platform: "facebook",
|
|
117
|
+
kind,
|
|
118
|
+
url: found.url,
|
|
119
|
+
id: found.id,
|
|
120
|
+
variant,
|
|
121
|
+
options
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const facebook = {
|
|
125
|
+
platform: "facebook",
|
|
126
|
+
fallback: FALLBACK,
|
|
127
|
+
parse(root) {
|
|
128
|
+
if (root.tag === "div") {
|
|
129
|
+
const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
|
|
130
|
+
const found = target(parseUrl(root.attrs.get("data-href") ?? ""));
|
|
131
|
+
if (!kind || !found) return null;
|
|
132
|
+
return {
|
|
133
|
+
...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES, coerce)),
|
|
134
|
+
fallbackHtml: rebuild(root.children, FALLBACK)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (root.tag !== "iframe") return null;
|
|
138
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
139
|
+
if (!src || !PLUGIN_HOSTS.has(src.host)) return null;
|
|
140
|
+
const found = target(parseUrl(src.query.get("href") ?? ""));
|
|
141
|
+
if (!found) return null;
|
|
142
|
+
if (src.path === "/plugins/post.php") {
|
|
143
|
+
const options = {};
|
|
144
|
+
const showText = src.query.get("show_text");
|
|
145
|
+
const width = src.query.get("width");
|
|
146
|
+
if (showText !== void 0) options.showText = coerce(showText);
|
|
147
|
+
if (width !== void 0) options.width = coerce(width);
|
|
148
|
+
return embed(found, "post", "sdk", options);
|
|
149
|
+
}
|
|
150
|
+
if (src.path === "/plugins/video.php") {
|
|
151
|
+
const showText = coerce(src.query.get("show_text") ?? "");
|
|
152
|
+
if (showText === true || showText === 1) {
|
|
153
|
+
const options = {};
|
|
154
|
+
for (const [parameter, key] of VIDEO_SDK_PARAMETERS) {
|
|
155
|
+
const value = src.query.get(parameter);
|
|
156
|
+
if (value !== void 0) options[key] = coerce(value);
|
|
157
|
+
}
|
|
158
|
+
const width = pixels(src.query.get("width"));
|
|
159
|
+
const height = pixels(src.query.get("height"));
|
|
160
|
+
return withSize(embed(found, "video", "sdk", {
|
|
161
|
+
...options,
|
|
162
|
+
showText: true
|
|
163
|
+
}), width === void 0 || height === void 0 ? void 0 : {
|
|
164
|
+
width,
|
|
165
|
+
height
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const options = Object.fromEntries([...src.query].filter(([key]) => key !== "href").map(([key, value]) => [key, coerce(value)]));
|
|
169
|
+
return withSize(embed(found, "video", "iframe", options), sizeOf(root));
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
},
|
|
173
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
174
|
+
scriptOptions(src) {
|
|
175
|
+
const [, locale] = SCRIPT.exec(src) ?? [];
|
|
176
|
+
return locale === void 0 ? {} : { locale };
|
|
177
|
+
},
|
|
178
|
+
allowsFbRoot: true,
|
|
179
|
+
match(url) {
|
|
180
|
+
const found = target(url);
|
|
181
|
+
return found && embed(found, found.kind, "sdk", {});
|
|
182
|
+
},
|
|
183
|
+
ownsFrame: (src) => PLUGIN_HOSTS.has(src.host) && underPath(src.path, "/plugins")
|
|
184
|
+
};
|
|
185
|
+
export { facebook };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { rebuild } from "../html.js";
|
|
2
|
+
import { sizeOf, withSize } from "../platform.js";
|
|
3
|
+
import { parseUrl } from "../url.js";
|
|
4
|
+
// 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
|
+
const SCRIPT = /^(?:https?:)?\/\/embedr\.flickr\.com\/assets\/client-code\.js$/;
|
|
12
|
+
const ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
13
|
+
const OPTIONS = [
|
|
14
|
+
"header",
|
|
15
|
+
"footer",
|
|
16
|
+
"context"
|
|
17
|
+
];
|
|
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
|
+
function onlyImage(root) {
|
|
96
|
+
let image = null;
|
|
97
|
+
for (const child of root.children) {
|
|
98
|
+
if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
|
|
99
|
+
if (child.type !== "element" || child.tag !== "img" || image) return null;
|
|
100
|
+
image = child;
|
|
101
|
+
}
|
|
102
|
+
return image;
|
|
103
|
+
}
|
|
104
|
+
const flickr = {
|
|
105
|
+
platform: "flickr",
|
|
106
|
+
fallback: FALLBACK,
|
|
107
|
+
parse(root) {
|
|
108
|
+
if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
|
|
109
|
+
const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
|
|
110
|
+
const image = onlyImage(root);
|
|
111
|
+
if (!found || !image) return null;
|
|
112
|
+
const options = {};
|
|
113
|
+
for (const name of OPTIONS) if (root.attrs.get(`data-${name}`) === "true") options[name] = true;
|
|
114
|
+
const size = sizeOf(image);
|
|
115
|
+
const linked = IMAGE_SRC.test(image.attrs.get("src") ?? "") ? root : {
|
|
116
|
+
...root,
|
|
117
|
+
children: []
|
|
118
|
+
};
|
|
119
|
+
return withSize({
|
|
120
|
+
...found,
|
|
121
|
+
options,
|
|
122
|
+
fallbackHtml: rebuild([linked], FALLBACK)
|
|
123
|
+
}, size?.width !== void 0 && size.height !== void 0 ? size : void 0);
|
|
124
|
+
},
|
|
125
|
+
isOwnScript: (src) => SCRIPT.test(src),
|
|
126
|
+
match(url) {
|
|
127
|
+
const found = fromLongUrl(url) ?? fromShortUrl(url);
|
|
128
|
+
return found && {
|
|
129
|
+
...found,
|
|
130
|
+
options: {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
export { decodeFlickrCode, flickr };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { sizeOf, underPath, unwrapRatio, withSize } from "../platform.js";
|
|
2
|
+
import { parseUrl } from "../url.js";
|
|
3
|
+
// src/parser/platforms/giphy.ts
|
|
4
|
+
const ID = "([A-Za-z0-9]{6,40})";
|
|
5
|
+
const PAGE_HOSTS = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
|
|
6
|
+
const PAGE_PATH = new RegExp(`^/(?:gifs|stickers)/(?:[A-Za-z0-9-]{0,200}-)?${ID}/?$`);
|
|
7
|
+
const EMBED_PATH = new RegExp(`^/embed/${ID}/?$`);
|
|
8
|
+
const MEDIA_HOST = /^(?:media\d?|i)\.giphy\.com$/;
|
|
9
|
+
const FILE_TYPE = "\\.(?:gif|webp|mp4)";
|
|
10
|
+
const MEDIA_PATH = new RegExp(`^/media/(?:v1\\.[A-Za-z0-9_-]{1,500}/)?${ID}/[A-Za-z0-9_-]{1,40}${FILE_TYPE}$`);
|
|
11
|
+
const SHORT_MEDIA_PATH = new RegExp(`^/${ID}${FILE_TYPE}$`);
|
|
12
|
+
const WRAPPER = /^width:\s*100%;\s*height:\s*0;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*position:\s*relative;?$/;
|
|
13
|
+
function gif(id) {
|
|
14
|
+
return {
|
|
15
|
+
platform: "giphy",
|
|
16
|
+
kind: "video",
|
|
17
|
+
url: `https://giphy.com/gifs/${id}`,
|
|
18
|
+
id,
|
|
19
|
+
variant: "iframe"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function idOf(url) {
|
|
23
|
+
if (!url) return void 0;
|
|
24
|
+
if (PAGE_HOSTS.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH.exec(url.path))?.[1];
|
|
25
|
+
if (!MEDIA_HOST.test(url.host)) return void 0;
|
|
26
|
+
return (MEDIA_PATH.exec(url.path) ?? (url.host === "i.giphy.com" ? SHORT_MEDIA_PATH.exec(url.path) : null))?.[1];
|
|
27
|
+
}
|
|
28
|
+
function fromIframe(iframe) {
|
|
29
|
+
if (iframe.tag !== "iframe") return null;
|
|
30
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
31
|
+
if (!src || !PAGE_HOSTS.has(src.host)) return null;
|
|
32
|
+
const [, id] = EMBED_PATH.exec(src.path) ?? [];
|
|
33
|
+
return id === void 0 ? null : gif(id);
|
|
34
|
+
}
|
|
35
|
+
function isCredit(element, embed) {
|
|
36
|
+
if (element.tag !== "p" || element.attrs.size !== 0) return false;
|
|
37
|
+
const [link, ...rest] = element.children;
|
|
38
|
+
if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return false;
|
|
39
|
+
if (link.attrs.size !== 1) return false;
|
|
40
|
+
const href = parseUrl(link.attrs.get("href") ?? "");
|
|
41
|
+
if (!href || !PAGE_HOSTS.has(href.host) || PAGE_PATH.exec(href.path)?.[1] !== embed.id) return false;
|
|
42
|
+
const [text, ...more] = link.children;
|
|
43
|
+
return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
|
|
44
|
+
}
|
|
45
|
+
const giphy = {
|
|
46
|
+
platform: "giphy",
|
|
47
|
+
parse(root) {
|
|
48
|
+
const wrapped = unwrapRatio(root, WRAPPER);
|
|
49
|
+
const iframe = wrapped?.iframe ?? root;
|
|
50
|
+
const found = fromIframe(iframe);
|
|
51
|
+
if (!found) return null;
|
|
52
|
+
return withSize({
|
|
53
|
+
...found,
|
|
54
|
+
options: {}
|
|
55
|
+
}, wrapped?.size ?? sizeOf(iframe));
|
|
56
|
+
},
|
|
57
|
+
isOwnScript: () => false,
|
|
58
|
+
isOwnExtra: isCredit,
|
|
59
|
+
match(url) {
|
|
60
|
+
const id = idOf(url);
|
|
61
|
+
return id === void 0 ? null : {
|
|
62
|
+
...gif(id),
|
|
63
|
+
options: {}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
ownsFrame: (src) => PAGE_HOSTS.has(src.host) && underPath(src.path, "/embed")
|
|
67
|
+
};
|
|
68
|
+
export { giphy };
|