social-embeds 0.8.1 → 0.9.1
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 +37 -1
- package/dist/components/iframe-embed.js +15 -31
- package/dist/components/platforms.d.ts +32 -0
- package/dist/components/platforms.js +384 -0
- package/dist/components/social-embed.d.ts +31 -4
- package/dist/components/social-embed.js +48 -211
- 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/index.d.ts +21 -20
- package/dist/index.js +3 -2
- package/dist/loader/platform-scripts.js +23 -22
- package/dist/parser/html.d.ts +14 -0
- package/dist/parser/html.js +6 -1
- package/dist/parser/lookup.js +11 -5
- package/dist/parser/match-url.js +6 -2
- package/dist/parser/parse-embed.js +12 -8
- package/dist/parser/platform.d.ts +32 -0
- 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/url.d.ts +6 -0
- package/dist/parser/verify.js +2 -46
- package/package.json +1 -1
|
@@ -6,10 +6,8 @@ const FACEBOOK_SDK_VERSION = "v26.0";
|
|
|
6
6
|
const LOCALE = /^[a-z]{2,3}_[A-Z]{2}$/;
|
|
7
7
|
/** Instagram and Threads share `instgrm.Embeds`; each registers its name when loaded. */
|
|
8
8
|
function embedSdkRegistered(name) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return embeds?.registeredEmbedSDKs?.[name] === true && typeof embeds.process === "function";
|
|
12
|
-
};
|
|
9
|
+
const embeds = globals().instgrm?.Embeds;
|
|
10
|
+
return embeds?.registeredEmbedSDKs?.[name] === true && typeof embeds.process === "function";
|
|
13
11
|
}
|
|
14
12
|
const x = {
|
|
15
13
|
key: "x",
|
|
@@ -33,27 +31,24 @@ function besideFacebookSdk() {
|
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
function skippedBesideFacebookSdk(name) {
|
|
36
|
-
const
|
|
37
|
-
return ()
|
|
38
|
-
const fb = globals().FB;
|
|
39
|
-
return !registered() && fb !== void 0 && !fb.__buffer;
|
|
40
|
-
};
|
|
34
|
+
const fb = globals().FB;
|
|
35
|
+
return !embedSdkRegistered(name) && fb !== void 0 && !fb.__buffer;
|
|
41
36
|
}
|
|
42
37
|
const instagram = {
|
|
43
38
|
key: "instagram",
|
|
44
39
|
url: "https://www.instagram.com/embed.js",
|
|
45
40
|
isOwn: (src) => /^https?:\/\/www\.instagram\.com\/embed\.js(?:[?#]|$)/.test(src),
|
|
46
|
-
isPresent: embedSdkRegistered("instagram"),
|
|
41
|
+
isPresent: () => embedSdkRegistered("instagram"),
|
|
47
42
|
prepare: besideFacebookSdk,
|
|
48
|
-
skipped: skippedBesideFacebookSdk("instagram")
|
|
43
|
+
skipped: () => skippedBesideFacebookSdk("instagram")
|
|
49
44
|
};
|
|
50
45
|
const threads = {
|
|
51
46
|
key: "threads",
|
|
52
47
|
url: "https://www.threads.com/embed.js",
|
|
53
48
|
isOwn: (src) => /^https?:\/\/www\.threads\.(?:com|net)\/embed\.js(?:[?#]|$)/.test(src),
|
|
54
|
-
isPresent: embedSdkRegistered("threads"),
|
|
49
|
+
isPresent: () => embedSdkRegistered("threads"),
|
|
55
50
|
prepare: besideFacebookSdk,
|
|
56
|
-
skipped: skippedBesideFacebookSdk("threads")
|
|
51
|
+
skipped: () => skippedBesideFacebookSdk("threads")
|
|
57
52
|
};
|
|
58
53
|
function facebook(locale) {
|
|
59
54
|
return {
|
|
@@ -77,13 +72,19 @@ const pinterest = {
|
|
|
77
72
|
isOwn: (src) => /^https?:\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js(?:[?#]|$)/.test(src),
|
|
78
73
|
isPresent: () => typeof globals().PinUtils?.build === "function"
|
|
79
74
|
};
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
function loadX() {
|
|
76
|
+
return loadScript(x);
|
|
77
|
+
}
|
|
78
|
+
function loadInstagram() {
|
|
79
|
+
return loadScript(instagram);
|
|
80
|
+
}
|
|
81
|
+
function loadThreads() {
|
|
82
|
+
return loadScript(threads);
|
|
83
|
+
}
|
|
84
|
+
function loadPinterest() {
|
|
85
|
+
return loadScript(pinterest);
|
|
86
|
+
}
|
|
87
|
+
function loadFacebook(locale) {
|
|
88
|
+
return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
|
|
88
89
|
}
|
|
89
|
-
export { FACEBOOK_SDK_VERSION,
|
|
90
|
+
export { FACEBOOK_SDK_VERSION, loadFacebook, loadInstagram, loadPinterest, loadThreads, loadX };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type HtmlElement = {
|
|
2
|
+
type: 'element';
|
|
3
|
+
tag: string;
|
|
4
|
+
attrs: ReadonlyMap<string, string>;
|
|
5
|
+
children: HtmlNode[];
|
|
6
|
+
};
|
|
7
|
+
export type HtmlText = {
|
|
8
|
+
type: 'text';
|
|
9
|
+
raw: string;
|
|
10
|
+
};
|
|
11
|
+
export type HtmlComment = {
|
|
12
|
+
type: 'comment';
|
|
13
|
+
};
|
|
14
|
+
export type HtmlNode = HtmlElement | HtmlText | HtmlComment;
|
package/dist/parser/html.js
CHANGED
|
@@ -169,4 +169,9 @@ function rebuild(nodes, whitelist) {
|
|
|
169
169
|
function escapeAttribute(value) {
|
|
170
170
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
/** True when `html` parses and rebuilds through the whitelist unchanged. */
|
|
173
|
+
function rebuildsAs(html, whitelist) {
|
|
174
|
+
const nodes = parseHtml(html);
|
|
175
|
+
return nodes !== null && rebuild(nodes, whitelist) === html;
|
|
176
|
+
}
|
|
177
|
+
export { decodeEntities, descendants, escapeAttribute, hasClass, parseHtml, rebuild, rebuildsAs };
|
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 };
|
package/dist/parser/match-url.js
CHANGED
|
@@ -3,9 +3,13 @@ import { parseUrl } from "./url.js";
|
|
|
3
3
|
// src/parser/match-url.ts
|
|
4
4
|
/** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
|
|
5
5
|
function matchUrl(url) {
|
|
6
|
+
return matchUrlWith(platforms, url);
|
|
7
|
+
}
|
|
8
|
+
/** `matchUrl` for these platforms only. */
|
|
9
|
+
function matchUrlWith(parsers, url) {
|
|
6
10
|
const parsed = parse(url);
|
|
7
11
|
if (!parsed) return null;
|
|
8
|
-
for (const platform of
|
|
12
|
+
for (const platform of parsers) {
|
|
9
13
|
const embed = platform.match(parsed);
|
|
10
14
|
if (embed) return embed;
|
|
11
15
|
}
|
|
@@ -19,4 +23,4 @@ function matchWith(parser, url) {
|
|
|
19
23
|
function parse(url) {
|
|
20
24
|
return typeof url === "string" ? parseUrl(url) : null;
|
|
21
25
|
}
|
|
22
|
-
export { matchUrl, matchWith };
|
|
26
|
+
export { matchUrl, matchUrlWith, matchWith };
|
|
@@ -7,20 +7,24 @@ import { platforms } from "./platforms/index.js";
|
|
|
7
7
|
* comments (docs/decisions.md D14).
|
|
8
8
|
*/
|
|
9
9
|
function parseEmbed(html) {
|
|
10
|
+
return parseEmbedWith(platforms, html);
|
|
11
|
+
}
|
|
12
|
+
/** `parseEmbed` for these platforms only. */
|
|
13
|
+
function parseEmbedWith(parsers, html) {
|
|
10
14
|
if (typeof html !== "string") return null;
|
|
11
15
|
const nodes = parseHtml(html);
|
|
12
|
-
return nodes ? parseNodes(nodes) : parseRepaired(html);
|
|
16
|
+
return nodes ? parseNodes(parsers, nodes) : parseRepaired(parsers, html);
|
|
13
17
|
}
|
|
14
|
-
function parseRepaired(html) {
|
|
15
|
-
for (const platform of
|
|
18
|
+
function parseRepaired(parsers, html) {
|
|
19
|
+
for (const platform of parsers) {
|
|
16
20
|
const repaired = platform.repair?.(html);
|
|
17
21
|
const nodes = repaired === void 0 || repaired === null ? null : parseHtml(repaired);
|
|
18
|
-
const embed = nodes && parseNodes(nodes);
|
|
22
|
+
const embed = nodes && parseNodes(parsers, nodes);
|
|
19
23
|
if (embed?.platform === platform.platform) return embed;
|
|
20
24
|
}
|
|
21
25
|
return null;
|
|
22
26
|
}
|
|
23
|
-
function parseNodes(nodes) {
|
|
27
|
+
function parseNodes(parsers, nodes) {
|
|
24
28
|
let root;
|
|
25
29
|
let extra;
|
|
26
30
|
const scripts = [];
|
|
@@ -42,13 +46,13 @@ function parseNodes(nodes) {
|
|
|
42
46
|
const [script] = scripts;
|
|
43
47
|
if (fbRoot || scripts.length !== 1 || !script) return null;
|
|
44
48
|
if (script.children.length !== 0) return null;
|
|
45
|
-
for (const platform of
|
|
49
|
+
for (const platform of parsers) {
|
|
46
50
|
const embed = platform.parseScript?.(script);
|
|
47
51
|
if (embed) return embed;
|
|
48
52
|
}
|
|
49
53
|
return null;
|
|
50
54
|
}
|
|
51
|
-
for (const platform of
|
|
55
|
+
for (const platform of parsers) {
|
|
52
56
|
const embed = platform.parse(root);
|
|
53
57
|
if (!embed) continue;
|
|
54
58
|
if (fbRoot && !platform.allowsFbRoot) return null;
|
|
@@ -66,4 +70,4 @@ function parseNodes(nodes) {
|
|
|
66
70
|
function isFbRoot(element) {
|
|
67
71
|
return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
|
|
68
72
|
}
|
|
69
|
-
export { parseEmbed };
|
|
73
|
+
export { parseEmbed, parseEmbedWith };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HtmlElement } from "./html.js";
|
|
2
|
+
import { ParsedEmbed, Platform } from "./types.js";
|
|
3
|
+
import { ParsedUrl } from "./url.js";
|
|
4
|
+
export type Options = ParsedEmbed['options'];
|
|
5
|
+
export type PlatformParser = {
|
|
6
|
+
platform: Platform;
|
|
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;
|
|
15
|
+
/** The embed element (blockquote, div or iframe) of the platform's own embed code. */
|
|
16
|
+
parse: (root: HtmlElement) => ParsedEmbed | null;
|
|
17
|
+
/** Embed code that is a single `<script>` tag, as Telegram's is. */
|
|
18
|
+
parseScript?: (script: HtmlElement) => ParsedEmbed | null;
|
|
19
|
+
/**
|
|
20
|
+
* For code the HTML parser rejects: the same code without the stray markup this platform's own
|
|
21
|
+
* tool writes, or `null`. The result must still parse as this platform's embed.
|
|
22
|
+
*/
|
|
23
|
+
repair?: (html: string) => string | null;
|
|
24
|
+
isOwnScript: (src: string) => boolean;
|
|
25
|
+
scriptOptions?: (src: string) => Options;
|
|
26
|
+
allowsFbRoot?: boolean;
|
|
27
|
+
/** A sibling element after the embed that is the platform's own markup, such as a credit; it is dropped. */
|
|
28
|
+
isOwnExtra?: (element: HtmlElement, embed: ParsedEmbed) => boolean;
|
|
29
|
+
match: (url: ParsedUrl) => ParsedEmbed | null;
|
|
30
|
+
/** True also for frames `parse` rejects, so generic iframe code never bypasses the platform's checks. */
|
|
31
|
+
ownsFrame?: (src: ParsedUrl) => boolean;
|
|
32
|
+
};
|
|
@@ -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);
|