social-embeds 0.9.0 → 0.9.2
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 +7 -7
- package/dist/components/apple-embed.d.ts +2 -2
- package/dist/components/apple-embed.js +6 -28
- package/dist/components/bluesky-embed.d.ts +1 -1
- package/dist/components/bluesky-embed.js +5 -16
- package/dist/components/dailymotion-embed.d.ts +1 -1
- package/dist/components/dailymotion-embed.js +10 -20
- package/dist/components/facebook-embed.d.ts +1 -1
- package/dist/components/facebook-embed.js +13 -34
- package/dist/components/flickr-embed.d.ts +1 -1
- package/dist/components/flickr-embed.js +9 -20
- package/dist/components/giphy-embed.d.ts +1 -1
- package/dist/components/giphy-embed.js +4 -15
- package/dist/components/iframe-embed.js +30 -32
- package/dist/components/imgur-embed.d.ts +1 -1
- package/dist/components/imgur-embed.js +5 -16
- package/dist/components/instagram-embed.d.ts +1 -1
- package/dist/components/instagram-embed.js +5 -19
- package/dist/components/kick-embed.d.ts +1 -1
- package/dist/components/kick-embed.js +5 -18
- package/dist/components/linkedin-embed.d.ts +1 -1
- package/dist/components/linkedin-embed.js +5 -16
- package/dist/components/pinterest-embed.d.ts +1 -1
- package/dist/components/pinterest-embed.js +5 -19
- package/dist/components/reddit-embed.d.ts +1 -1
- package/dist/components/reddit-embed.js +12 -22
- package/dist/components/rumble-embed.d.ts +1 -1
- package/dist/components/rumble-embed.js +4 -15
- package/dist/components/script-embed.js +14 -1
- package/dist/components/snapchat-embed.d.ts +1 -1
- package/dist/components/snapchat-embed.js +4 -15
- package/dist/components/soundcloud-embed.d.ts +1 -1
- package/dist/components/soundcloud-embed.js +15 -26
- package/dist/components/spotify-embed.d.ts +1 -1
- package/dist/components/spotify-embed.js +5 -15
- package/dist/components/strava-embed.d.ts +1 -1
- package/dist/components/strava-embed.js +9 -19
- package/dist/components/streamable-embed.d.ts +1 -1
- package/dist/components/streamable-embed.js +11 -21
- package/dist/components/telegram-embed.d.ts +1 -1
- package/dist/components/telegram-embed.js +10 -20
- package/dist/components/tenor-embed.d.ts +1 -1
- package/dist/components/tenor-embed.js +4 -15
- package/dist/components/threads-embed.d.ts +1 -1
- package/dist/components/threads-embed.js +5 -19
- package/dist/components/tiktok-embed.d.ts +1 -1
- package/dist/components/tiktok-embed.js +20 -30
- package/dist/components/truthsocial-embed.d.ts +1 -1
- package/dist/components/truthsocial-embed.js +4 -15
- package/dist/components/tumblr-embed.d.ts +1 -1
- package/dist/components/tumblr-embed.js +4 -15
- package/dist/components/twitch-embed.d.ts +1 -1
- package/dist/components/twitch-embed.js +9 -19
- package/dist/components/use-plan.js +20 -0
- package/dist/components/vimeo-embed.d.ts +1 -1
- package/dist/components/vimeo-embed.js +24 -34
- package/dist/components/x-embed.d.ts +1 -1
- package/dist/components/x-embed.js +12 -26
- package/dist/components/youtube-embed.d.ts +1 -1
- package/dist/components/youtube-embed.js +27 -37
- package/dist/core/drivers.js +6 -6
- package/dist/core/layout.js +1 -45
- package/dist/core/message-height.js +24 -0
- package/dist/core/plans/bluesky.js +3 -1
- package/dist/core/plans/flickr.js +16 -6
- package/dist/core/plans/imgur.js +3 -1
- package/dist/core/plans/reddit.js +3 -1
- package/dist/core/plans/strava.js +3 -1
- package/dist/core/plans/telegram.js +3 -1
- package/dist/core/plans/truthsocial.js +5 -2
- package/dist/core/plans/tumblr.js +3 -1
- package/dist/core/plans/twitch.js +5 -2
- package/dist/core/resolve.js +15 -37
- package/dist/core/size-in-src.js +47 -0
- package/dist/element.js +1 -1
- package/dist/loader/platform-scripts.js +23 -22
- package/dist/parser/html.d.ts +1 -6
- package/dist/parser/html.js +6 -1
- package/dist/parser/lookup.js +11 -5
- package/dist/parser/platform.d.ts +9 -3
- package/dist/parser/platforms/applemusic.js +2 -0
- package/dist/parser/platforms/applepodcasts.js +2 -0
- package/dist/parser/platforms/bluesky.js +6 -2
- package/dist/parser/platforms/dailymotion.js +2 -0
- package/dist/parser/platforms/facebook.js +8 -2
- package/dist/parser/platforms/flickr.js +4 -2
- package/dist/parser/platforms/giphy.js +2 -0
- package/dist/parser/platforms/imgur.js +4 -2
- package/dist/parser/platforms/instagram.js +4 -2
- package/dist/parser/platforms/kick.js +2 -0
- package/dist/parser/platforms/linkedin.js +2 -0
- package/dist/parser/platforms/pinterest.js +2 -0
- package/dist/parser/platforms/reddit.js +2 -0
- package/dist/parser/platforms/rumble.js +4 -0
- package/dist/parser/platforms/snapchat.js +2 -0
- package/dist/parser/platforms/soundcloud.js +2 -0
- package/dist/parser/platforms/spotify.js +2 -0
- package/dist/parser/platforms/strava.js +2 -0
- package/dist/parser/platforms/streamable.js +2 -0
- package/dist/parser/platforms/telegram.js +2 -0
- package/dist/parser/platforms/tenor.js +4 -2
- package/dist/parser/platforms/threads.js +4 -2
- package/dist/parser/platforms/tiktok.js +2 -0
- package/dist/parser/platforms/truthsocial.js +2 -0
- package/dist/parser/platforms/tumblr.js +2 -0
- package/dist/parser/platforms/twitch.js +2 -0
- package/dist/parser/platforms/vimeo.js +2 -0
- package/dist/parser/platforms/x.js +8 -2
- package/dist/parser/platforms/youtube.js +2 -0
- package/dist/parser/verify.js +2 -46
- package/package.json +1 -1
package/dist/parser/lookup.js
CHANGED
|
@@ -12,9 +12,15 @@ const RUMBLE_PAGE = /^\/v[a-z0-9]{1,12}-[^/]{1,300}\.html$/;
|
|
|
12
12
|
function needsLookup(url) {
|
|
13
13
|
const parsed = typeof url === "string" ? parseUrl(url) : null;
|
|
14
14
|
if (!parsed) return null;
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
|
|
18
|
-
return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
|
|
15
|
+
if (rumbleNeedsLookup(parsed)) return "rumble";
|
|
16
|
+
return blueskyNeedsLookup(parsed) ? "bluesky" : null;
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
function rumbleNeedsLookup(url) {
|
|
19
|
+
return RUMBLE_HOSTS.has(url.host) && RUMBLE_PAGE.test(url.path);
|
|
20
|
+
}
|
|
21
|
+
function blueskyNeedsLookup(url) {
|
|
22
|
+
if (!BLUESKY_HOSTS.has(url.host)) return false;
|
|
23
|
+
const [, profile] = HANDLE_POST.exec(url.path) ?? [];
|
|
24
|
+
return profile !== void 0 && HANDLE.test(profile);
|
|
25
|
+
}
|
|
26
|
+
export { blueskyNeedsLookup, needsLookup, rumbleNeedsLookup };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { HtmlElement
|
|
1
|
+
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
|
export type PlatformParser = {
|
|
6
6
|
platform: Platform;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/** For messages: `YouTube`, `Apple Music`. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The `kind variant` pairs this platform's embeds may have, such as `post sdk`. */
|
|
10
|
+
shapes: readonly string[];
|
|
11
|
+
/** True when `fallbackHtml` is exactly what this parser writes for the embed (docs/decisions.md D35). */
|
|
12
|
+
trustsFallback?: (html: string, embed: ParsedEmbed) => boolean;
|
|
13
|
+
/** A post URL that only a network lookup could turn into an embed (docs/decisions.md D70). */
|
|
14
|
+
needsLookup?: (url: ParsedUrl) => boolean;
|
|
9
15
|
/** The embed element (blockquote, div or iframe) of the platform's own embed code. */
|
|
10
16
|
parse: (root: HtmlElement) => ParsedEmbed | null;
|
|
11
17
|
/** Embed code that is a single `<script>` tag, as Telegram's is. */
|
|
@@ -20,6 +20,8 @@ function appleContent(url, host) {
|
|
|
20
20
|
}
|
|
21
21
|
const applemusic = {
|
|
22
22
|
platform: "applemusic",
|
|
23
|
+
name: "Apple Music",
|
|
24
|
+
shapes: ["post iframe"],
|
|
23
25
|
parse(root) {
|
|
24
26
|
if (root.tag !== "iframe") return null;
|
|
25
27
|
const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), APPLE_MUSIC_FRAME_HOST);
|
|
@@ -20,6 +20,8 @@ function content(url, host) {
|
|
|
20
20
|
}
|
|
21
21
|
const applepodcasts = {
|
|
22
22
|
platform: "applepodcasts",
|
|
23
|
+
name: "Apple Podcasts",
|
|
24
|
+
shapes: ["post iframe"],
|
|
23
25
|
parse(root) {
|
|
24
26
|
if (root.tag !== "iframe") return null;
|
|
25
27
|
const found = content(parseUrl(root.attrs.get("src") ?? ""), APPLE_PODCASTS_FRAME_HOST);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { blueskyNeedsLookup } from "../lookup.js";
|
|
2
|
+
import { descendants, hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
3
|
import { parseUrl } from "../url.js";
|
|
3
4
|
// src/parser/platforms/bluesky.ts
|
|
4
5
|
const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
|
|
@@ -34,7 +35,10 @@ function fromUrl(url) {
|
|
|
34
35
|
}
|
|
35
36
|
const bluesky = {
|
|
36
37
|
platform: "bluesky",
|
|
37
|
-
|
|
38
|
+
name: "Bluesky",
|
|
39
|
+
shapes: ["post iframe"],
|
|
40
|
+
needsLookup: blueskyNeedsLookup,
|
|
41
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
38
42
|
parse(root) {
|
|
39
43
|
if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
|
|
40
44
|
const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { attributeOptions, sizeOf, withSize } from "../platform.js";
|
|
3
3
|
import { coerce, parseUrl, pixels } from "../url.js";
|
|
4
4
|
import { FACEBOOK_PLUGIN_HOSTS, facebookFrame } from "../frames.js";
|
|
@@ -119,7 +119,13 @@ function embed(found, kind, variant, options) {
|
|
|
119
119
|
}
|
|
120
120
|
const facebook = {
|
|
121
121
|
platform: "facebook",
|
|
122
|
-
|
|
122
|
+
name: "Facebook",
|
|
123
|
+
shapes: [
|
|
124
|
+
"post sdk",
|
|
125
|
+
"video sdk",
|
|
126
|
+
"video iframe"
|
|
127
|
+
],
|
|
128
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
123
129
|
parse(root) {
|
|
124
130
|
if (root.tag === "div") {
|
|
125
131
|
const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rebuild } from "../html.js";
|
|
1
|
+
import { rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { sizeOf, withSize } from "../platform.js";
|
|
3
3
|
import { parseUrl } from "../url.js";
|
|
4
4
|
// src/parser/platforms/flickr.ts
|
|
@@ -103,7 +103,9 @@ function onlyImage(root) {
|
|
|
103
103
|
}
|
|
104
104
|
const flickr = {
|
|
105
105
|
platform: "flickr",
|
|
106
|
-
|
|
106
|
+
name: "Flickr",
|
|
107
|
+
shapes: ["post iframe"],
|
|
108
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
107
109
|
parse(root) {
|
|
108
110
|
if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
|
|
109
111
|
const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
// src/parser/platforms/imgur.ts
|
|
3
3
|
const HOSTS = /* @__PURE__ */ new Set([
|
|
4
4
|
"imgur.com",
|
|
@@ -80,7 +80,9 @@ function falseOption(root, attribute) {
|
|
|
80
80
|
}
|
|
81
81
|
const imgur = {
|
|
82
82
|
platform: "imgur",
|
|
83
|
-
|
|
83
|
+
name: "Imgur",
|
|
84
|
+
shapes: ["post iframe"],
|
|
85
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
84
86
|
parse(root) {
|
|
85
87
|
if (root.tag !== "blockquote" || !hasClass(root, "imgur-embed-pub")) return null;
|
|
86
88
|
const id = root.attrs.get("data-id") ?? "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { descendants, hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { descendants, hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { coerce, parseUrl } from "../url.js";
|
|
3
3
|
// src/parser/platforms/instagram.ts
|
|
4
4
|
const HOSTS = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
|
|
@@ -31,7 +31,9 @@ function post(url) {
|
|
|
31
31
|
}
|
|
32
32
|
const instagram = {
|
|
33
33
|
platform: "instagram",
|
|
34
|
-
|
|
34
|
+
name: "Instagram",
|
|
35
|
+
shapes: ["post sdk"],
|
|
36
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
35
37
|
parse(root) {
|
|
36
38
|
if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
|
|
37
39
|
const permalink = root.attrs.get("data-instgrm-permalink");
|
|
@@ -21,6 +21,8 @@ function post(type, id, options = {}) {
|
|
|
21
21
|
const decodeColons = (path) => path.replace(/%3A/gi, ":");
|
|
22
22
|
const linkedin = {
|
|
23
23
|
platform: "linkedin",
|
|
24
|
+
name: "LinkedIn",
|
|
25
|
+
shapes: ["post iframe"],
|
|
24
26
|
parse(root) {
|
|
25
27
|
if (root.tag !== "iframe") return null;
|
|
26
28
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -47,6 +47,8 @@ function post(url) {
|
|
|
47
47
|
}
|
|
48
48
|
const reddit = {
|
|
49
49
|
platform: "reddit",
|
|
50
|
+
name: "Reddit",
|
|
51
|
+
shapes: ["post iframe"],
|
|
50
52
|
parse(root) {
|
|
51
53
|
if (root.tag !== "blockquote" || !(hasClass(root, "reddit-embed-bq") || hasClass(root, "reddit-card"))) return null;
|
|
52
54
|
const found = descendants(root.children).map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rumbleNeedsLookup } from "../lookup.js";
|
|
1
2
|
import { sizeOf, withSize } from "../platform.js";
|
|
2
3
|
import { coerce, parseUrl } from "../url.js";
|
|
3
4
|
import { rumbleFrame } from "../frames.js";
|
|
@@ -18,6 +19,9 @@ function idOf(url, hosts) {
|
|
|
18
19
|
}
|
|
19
20
|
const rumble = {
|
|
20
21
|
platform: "rumble",
|
|
22
|
+
name: "Rumble",
|
|
23
|
+
shapes: ["video iframe"],
|
|
24
|
+
needsLookup: rumbleNeedsLookup,
|
|
21
25
|
parse(root) {
|
|
22
26
|
if (root.tag !== "iframe") return null;
|
|
23
27
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
@@ -51,6 +51,8 @@ function content(url) {
|
|
|
51
51
|
}
|
|
52
52
|
const snapchat = {
|
|
53
53
|
platform: "snapchat",
|
|
54
|
+
name: "Snapchat",
|
|
55
|
+
shapes: ["post iframe", "video iframe"],
|
|
54
56
|
parse(root) {
|
|
55
57
|
if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
|
|
56
58
|
const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
|
|
@@ -24,6 +24,8 @@ function isType(value) {
|
|
|
24
24
|
}
|
|
25
25
|
const strava = {
|
|
26
26
|
platform: "strava",
|
|
27
|
+
name: "Strava",
|
|
28
|
+
shapes: ["post iframe"],
|
|
27
29
|
parse(root) {
|
|
28
30
|
if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
|
|
29
31
|
if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { sizeOf, withSize } from "../platform.js";
|
|
3
3
|
import { parseUrl } from "../url.js";
|
|
4
4
|
import { tenorFrame } from "../frames.js";
|
|
@@ -61,7 +61,9 @@ function fromIframe(root) {
|
|
|
61
61
|
}
|
|
62
62
|
const tenor = {
|
|
63
63
|
platform: "tenor",
|
|
64
|
-
|
|
64
|
+
name: "Tenor",
|
|
65
|
+
shapes: ["video iframe"],
|
|
66
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
65
67
|
parse(root) {
|
|
66
68
|
if (root.tag === "div") return fromDiv(root);
|
|
67
69
|
return root.tag === "iframe" ? fromIframe(root) : null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { hasClass, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { attributeOptions } from "../platform.js";
|
|
3
3
|
import { coerce, parseUrl } from "../url.js";
|
|
4
4
|
// src/parser/platforms/threads.ts
|
|
@@ -26,7 +26,9 @@ function post(url) {
|
|
|
26
26
|
}
|
|
27
27
|
const threads = {
|
|
28
28
|
platform: "threads",
|
|
29
|
-
|
|
29
|
+
name: "Threads",
|
|
30
|
+
shapes: ["post sdk"],
|
|
31
|
+
trustsFallback: (html) => rebuildsAs(html, FALLBACK),
|
|
30
32
|
parse(root) {
|
|
31
33
|
if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
|
|
32
34
|
const found = post(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
|
|
@@ -19,6 +19,8 @@ function video(id, user = "", options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
const tiktok = {
|
|
21
21
|
platform: "tiktok",
|
|
22
|
+
name: "TikTok",
|
|
23
|
+
shapes: ["video iframe"],
|
|
22
24
|
parse(root) {
|
|
23
25
|
if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
|
|
24
26
|
const cite = parseUrl(root.attrs.get("cite") ?? "");
|
|
@@ -43,6 +43,8 @@ function fromUrl(url) {
|
|
|
43
43
|
}
|
|
44
44
|
const tumblr = {
|
|
45
45
|
platform: "tumblr",
|
|
46
|
+
name: "Tumblr",
|
|
47
|
+
shapes: ["post iframe"],
|
|
46
48
|
parse(root) {
|
|
47
49
|
if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
|
|
48
50
|
const frame = parseUrl(root.attrs.get("data-href") ?? "");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { descendants, hasClass, rebuild } from "../html.js";
|
|
1
|
+
import { descendants, hasClass, parseHtml, rebuild, rebuildsAs } from "../html.js";
|
|
2
2
|
import { attributeOptions } from "../platform.js";
|
|
3
3
|
import { coerce, parseUrl } from "../url.js";
|
|
4
4
|
// src/parser/platforms/x.ts
|
|
@@ -40,9 +40,15 @@ function post(url, path = STATUS_PATH) {
|
|
|
40
40
|
variant: "sdk"
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
function fallbackNamesPost(html, id) {
|
|
44
|
+
const [root] = parseHtml(`<blockquote class="twitter-tweet">${html}</blockquote>`) ?? [];
|
|
45
|
+
return root?.type === "element" && x.parse(root)?.id === id;
|
|
46
|
+
}
|
|
43
47
|
const x = {
|
|
44
48
|
platform: "x",
|
|
45
|
-
|
|
49
|
+
name: "X",
|
|
50
|
+
shapes: ["post sdk"],
|
|
51
|
+
trustsFallback: (html, embed) => rebuildsAs(html, FALLBACK) && fallbackNamesPost(html, embed.id),
|
|
46
52
|
parse(root) {
|
|
47
53
|
if (root.tag !== "blockquote" || !(hasClass(root, "twitter-tweet") || hasClass(root, "twitter-video"))) return null;
|
|
48
54
|
const status = descendants(root.children).reverse().map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((found) => found !== null);
|
package/dist/parser/verify.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
import { parseHtml, rebuild } from "./html.js";
|
|
2
1
|
import { matchWith } from "./match-url.js";
|
|
3
2
|
// src/parser/verify.ts
|
|
4
|
-
const SHAPES = {
|
|
5
|
-
x: ["post sdk"],
|
|
6
|
-
instagram: ["post sdk"],
|
|
7
|
-
threads: ["post sdk"],
|
|
8
|
-
facebook: [
|
|
9
|
-
"post sdk",
|
|
10
|
-
"video sdk",
|
|
11
|
-
"video iframe"
|
|
12
|
-
],
|
|
13
|
-
tiktok: ["video iframe"],
|
|
14
|
-
youtube: ["video iframe"],
|
|
15
|
-
telegram: ["post iframe"],
|
|
16
|
-
snapchat: ["post iframe", "video iframe"],
|
|
17
|
-
linkedin: ["post iframe"],
|
|
18
|
-
reddit: ["post iframe"],
|
|
19
|
-
pinterest: ["post sdk"],
|
|
20
|
-
spotify: ["post iframe", "video iframe"],
|
|
21
|
-
vimeo: ["video iframe"],
|
|
22
|
-
twitch: ["video iframe"],
|
|
23
|
-
dailymotion: ["video iframe"],
|
|
24
|
-
bluesky: ["post iframe"],
|
|
25
|
-
soundcloud: ["post iframe"],
|
|
26
|
-
applemusic: ["post iframe"],
|
|
27
|
-
applepodcasts: ["post iframe"],
|
|
28
|
-
tumblr: ["post iframe"],
|
|
29
|
-
kick: ["video iframe"],
|
|
30
|
-
giphy: ["video iframe"],
|
|
31
|
-
truthsocial: ["post iframe"],
|
|
32
|
-
imgur: ["post iframe"],
|
|
33
|
-
tenor: ["video iframe"],
|
|
34
|
-
streamable: ["video iframe"],
|
|
35
|
-
strava: ["post iframe"],
|
|
36
|
-
flickr: ["post iframe"],
|
|
37
|
-
rumble: ["video iframe"]
|
|
38
|
-
};
|
|
39
3
|
/**
|
|
40
4
|
* `verifyEmbed` with only the embed's own parser, so a per-platform component does not
|
|
41
5
|
* bundle the other platforms' (docs/decisions.md D103).
|
|
@@ -45,19 +9,11 @@ function verifyWith(parser, embed) {
|
|
|
45
9
|
const matched = matchWith(parser, embed.url);
|
|
46
10
|
if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
|
|
47
11
|
if (matched.url !== embed.url) return null;
|
|
48
|
-
if (!
|
|
12
|
+
if (!parser.shapes.includes(`${embed.kind} ${embed.variant}`)) return null;
|
|
49
13
|
if (embed.fallbackHtml === void 0) return embed;
|
|
50
|
-
if (
|
|
14
|
+
if (parser.trustsFallback?.(embed.fallbackHtml, embed)) return embed;
|
|
51
15
|
const withoutFallback = { ...embed };
|
|
52
16
|
delete withoutFallback.fallbackHtml;
|
|
53
17
|
return withoutFallback;
|
|
54
18
|
}
|
|
55
|
-
function trustedFallback(parser, embed, fallbackHtml) {
|
|
56
|
-
const whitelist = parser.fallback;
|
|
57
|
-
const nodes = parseHtml(fallbackHtml);
|
|
58
|
-
if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
|
|
59
|
-
if (embed.platform !== "x") return true;
|
|
60
|
-
const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
|
|
61
|
-
return root?.type === "element" && parser.parse(root)?.id === embed.id;
|
|
62
|
-
}
|
|
63
19
|
export { verifyWith };
|