social-embeds 0.7.1 → 0.8.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 +63 -51
- 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 +38 -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 +108 -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 +125 -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 +59 -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.d.ts +1 -1
- 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 +116 -0
- package/dist/loader/platform-scripts.js +89 -0
- package/dist/parser/frames.js +70 -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 +57 -0
- package/dist/parser/platforms/facebook.js +181 -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 +69 -0
- package/dist/parser/platforms/rumble.js +44 -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 +95 -0
- package/dist/parser/platforms/telegram.js +61 -0
- package/dist/parser/platforms/tenor.js +79 -0
- package/dist/parser/platforms/threads.js +51 -0
- package/dist/parser/platforms/tiktok.js +48 -0
- package/dist/parser/platforms/truthsocial.js +50 -0
- package/dist/parser/platforms/tumblr.js +72 -0
- package/dist/parser/platforms/twitch.js +128 -0
- package/dist/parser/platforms/vimeo.js +95 -0
- package/dist/parser/platforms/x.js +65 -0
- package/dist/parser/platforms/youtube.js +140 -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,43 @@
|
|
|
1
|
+
// src/core/plans/truthsocial.ts
|
|
2
|
+
const VIDEO_EXTRA = 165;
|
|
3
|
+
function setHeight(data) {
|
|
4
|
+
const message = data;
|
|
5
|
+
return message?.type === "setHeight" && typeof message.height === "number" ? message.height : void 0;
|
|
6
|
+
}
|
|
7
|
+
/** The frame posts `{ type: 'setHeight', id, height }` without being asked (docs/decisions.md D93). */
|
|
8
|
+
const TRUTH_SOCIAL_HEIGHT = {
|
|
9
|
+
origin: "https://truthsocial.com",
|
|
10
|
+
read: setHeight
|
|
11
|
+
};
|
|
12
|
+
/** A video post reports its height before the video is sized (docs/decisions.md D100). */
|
|
13
|
+
const TRUTH_SOCIAL_VIDEO_HEIGHT = {
|
|
14
|
+
origin: "https://truthsocial.com",
|
|
15
|
+
read(data) {
|
|
16
|
+
const height = setHeight(data);
|
|
17
|
+
return height === void 0 || height <= 0 ? void 0 : height + VIDEO_EXTRA;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const CANONICAL = /^https:\/\/truthsocial\.com\/(@[^/]+)\/posts\/\d+$/;
|
|
21
|
+
/** At most 600px wide by default, the width of Truth Social's embed code (docs/decisions.md D93). */
|
|
22
|
+
function truthSocialPlan(embed) {
|
|
23
|
+
const user = CANONICAL.exec(embed.url)?.[1];
|
|
24
|
+
if (user === void 0) return {
|
|
25
|
+
kind: "error",
|
|
26
|
+
message: `social-embeds: not a Truth Social post URL: ${embed.url}`
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
kind: "iframe",
|
|
30
|
+
src: `https://truthsocial.com/${user}/${embed.id}/embed`,
|
|
31
|
+
title: "Truth Social post",
|
|
32
|
+
allow: "",
|
|
33
|
+
scrolling: "no",
|
|
34
|
+
ratio: {
|
|
35
|
+
width: 1,
|
|
36
|
+
height: 1
|
|
37
|
+
},
|
|
38
|
+
messageHeight: embed.options.video === true ? TRUTH_SOCIAL_VIDEO_HEIGHT : TRUTH_SOCIAL_HEIGHT,
|
|
39
|
+
startHeight: 150,
|
|
40
|
+
maxWidth: embed.size?.width ?? 600
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export { truthSocialPlan };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/core/plans/tumblr.ts
|
|
2
|
+
/** The frame posts a JSON string once it has painted (docs/decisions.md D74). */
|
|
3
|
+
const TUMBLR_HEIGHT = {
|
|
4
|
+
origin: "https://embed.tumblr.com",
|
|
5
|
+
read(data) {
|
|
6
|
+
if (typeof data !== "string") return void 0;
|
|
7
|
+
const message = JSON.parse(data);
|
|
8
|
+
const [height] = Array.isArray(message.args) ? message.args : [];
|
|
9
|
+
return message.method === "tumblr-post:sizeChange" && typeof height === "number" ? height : void 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/** At most 540px wide by default, Tumblr's oEmbed width. Renders the frame `post.js` would create (docs/decisions.md D77). */
|
|
13
|
+
function tumblrPlan(embed) {
|
|
14
|
+
return {
|
|
15
|
+
kind: "iframe",
|
|
16
|
+
src: `https://embed.tumblr.com/embed/post/${embed.url.slice(23).split("/")[0] ?? ""}/${embed.id}/v2`,
|
|
17
|
+
title: "Tumblr post",
|
|
18
|
+
allow: "",
|
|
19
|
+
scrolling: "no",
|
|
20
|
+
ratio: {
|
|
21
|
+
width: 1,
|
|
22
|
+
height: 1
|
|
23
|
+
},
|
|
24
|
+
messageHeight: TUMBLR_HEIGHT,
|
|
25
|
+
startHeight: 400,
|
|
26
|
+
maxWidth: 540
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export { tumblrPlan };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { optionsWithout, query } from "../params.js";
|
|
2
|
+
// src/core/plans/twitch.ts
|
|
3
|
+
const RESERVED = [
|
|
4
|
+
"channel",
|
|
5
|
+
"video",
|
|
6
|
+
"collection",
|
|
7
|
+
"clip",
|
|
8
|
+
"parent"
|
|
9
|
+
];
|
|
10
|
+
/** The player and its content parameter for the embed's canonical URL (docs/decisions.md D64). */
|
|
11
|
+
function player(url, id) {
|
|
12
|
+
const { hostname, pathname } = new URL(url);
|
|
13
|
+
if (hostname === "clips.twitch.tv") return ["https://clips.twitch.tv/embed", ["clip", id]];
|
|
14
|
+
const section = pathname.split("/")[1];
|
|
15
|
+
return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
|
|
16
|
+
}
|
|
17
|
+
/** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
|
|
18
|
+
function twitchPlan(embed, options) {
|
|
19
|
+
const { autoplay, muted, time } = options;
|
|
20
|
+
const params = [];
|
|
21
|
+
if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
|
|
22
|
+
if (muted !== void 0) params.push(["muted", String(muted)]);
|
|
23
|
+
if (time !== void 0) params.push(["time", time]);
|
|
24
|
+
const [base, content] = player(embed.url, embed.id);
|
|
25
|
+
return {
|
|
26
|
+
kind: "iframe",
|
|
27
|
+
src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
|
|
28
|
+
title: "Twitch player",
|
|
29
|
+
allow: "",
|
|
30
|
+
ratio: {
|
|
31
|
+
width: 16,
|
|
32
|
+
height: 9
|
|
33
|
+
},
|
|
34
|
+
size: embed.size,
|
|
35
|
+
hostParam: "parent"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { twitchPlan };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The player parameters Vimeo documents (help.vimeo.com, "Using player parameters"). */
|
|
2
|
+
export type VimeoOptions = {
|
|
3
|
+
autopause?: boolean;
|
|
4
|
+
autoplay?: boolean;
|
|
5
|
+
background?: boolean;
|
|
6
|
+
byline?: boolean;
|
|
7
|
+
/** Hex colour without `#`. */
|
|
8
|
+
color?: string;
|
|
9
|
+
controls?: boolean;
|
|
10
|
+
dnt?: boolean;
|
|
11
|
+
keyboard?: boolean;
|
|
12
|
+
loop?: boolean;
|
|
13
|
+
muted?: boolean;
|
|
14
|
+
pip?: boolean;
|
|
15
|
+
playsinline?: boolean;
|
|
16
|
+
portrait?: boolean;
|
|
17
|
+
quality?: string;
|
|
18
|
+
speed?: boolean;
|
|
19
|
+
title?: boolean;
|
|
20
|
+
transparent?: boolean;
|
|
21
|
+
/** Start time: seconds, or `1m2s`. */
|
|
22
|
+
t?: number | string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { optionsWithout, playerParams, query } from "../params.js";
|
|
2
|
+
// src/core/plans/vimeo.ts
|
|
3
|
+
const PARAMS = {
|
|
4
|
+
autopause: "autopause",
|
|
5
|
+
autoplay: "autoplay",
|
|
6
|
+
background: "background",
|
|
7
|
+
byline: "byline",
|
|
8
|
+
color: "color",
|
|
9
|
+
controls: "controls",
|
|
10
|
+
dnt: "dnt",
|
|
11
|
+
keyboard: "keyboard",
|
|
12
|
+
loop: "loop",
|
|
13
|
+
muted: "muted",
|
|
14
|
+
pip: "pip",
|
|
15
|
+
playsinline: "playsinline",
|
|
16
|
+
portrait: "portrait",
|
|
17
|
+
quality: "quality",
|
|
18
|
+
speed: "speed",
|
|
19
|
+
title: "title",
|
|
20
|
+
transparent: "transparent"
|
|
21
|
+
};
|
|
22
|
+
const ALLOW = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
|
|
23
|
+
function vimeoPlan(embed, options) {
|
|
24
|
+
const { t, ...rest } = options;
|
|
25
|
+
const { t: parsedStart, ...parsed } = embed.options;
|
|
26
|
+
const hash = new URL(embed.url).pathname.split("/")[2];
|
|
27
|
+
const params = playerParams(rest, PARAMS);
|
|
28
|
+
const start = t ?? parsedStart;
|
|
29
|
+
return {
|
|
30
|
+
kind: "iframe",
|
|
31
|
+
src: `https://player.vimeo.com/video/${embed.id}${query(hash ? [["h", hash]] : void 0, optionsWithout(parsed, ["h"]), params)}${start === void 0 ? "" : `#t=${encodeURIComponent(String(start))}`}`,
|
|
32
|
+
title: "Vimeo video player",
|
|
33
|
+
allow: ALLOW,
|
|
34
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
35
|
+
ratio: {
|
|
36
|
+
width: 16,
|
|
37
|
+
height: 9
|
|
38
|
+
},
|
|
39
|
+
size: embed.size
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { vimeoPlan };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `data-width` has no prop, because `width` is the wrapper's: the post fills the wrapper up
|
|
3
|
+
* to `maxWidth` (docs/decisions.md D33).
|
|
4
|
+
*/
|
|
5
|
+
export type XOptions = {
|
|
6
|
+
theme?: 'light' | 'dark';
|
|
7
|
+
conversation?: 'none';
|
|
8
|
+
cards?: 'hidden';
|
|
9
|
+
align?: 'left' | 'center' | 'right';
|
|
10
|
+
lang?: string;
|
|
11
|
+
dnt?: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { escapeAttribute } from "../../parser/html.js";
|
|
2
|
+
import { xDriver } from "../drivers.js";
|
|
3
|
+
import { dataAttributes, hasFallback, withProps } from "../markup.js";
|
|
4
|
+
// src/core/plans/x.ts
|
|
5
|
+
const ATTRIBUTES = {
|
|
6
|
+
theme: "data-theme",
|
|
7
|
+
conversation: "data-conversation",
|
|
8
|
+
cards: "data-cards",
|
|
9
|
+
align: "data-align",
|
|
10
|
+
lang: "data-lang",
|
|
11
|
+
dnt: "data-dnt",
|
|
12
|
+
width: "data-width"
|
|
13
|
+
};
|
|
14
|
+
/** A plain text post, the smallest X renders (docs/decisions.md D34). */
|
|
15
|
+
const MIN_HEIGHT = 250;
|
|
16
|
+
function xPlan(embed, options) {
|
|
17
|
+
const merged = withProps(embed.options, { ...options });
|
|
18
|
+
const content = embed.fallbackHtml ?? `<a href="${escapeAttribute(embed.url)}"></a>`;
|
|
19
|
+
const markup = `<blockquote${dataAttributes(ATTRIBUTES, merged)}>${content}</blockquote>`;
|
|
20
|
+
return {
|
|
21
|
+
kind: "script",
|
|
22
|
+
key: markup,
|
|
23
|
+
markup,
|
|
24
|
+
driver: xDriver,
|
|
25
|
+
minHeight: MIN_HEIGHT,
|
|
26
|
+
label: "X",
|
|
27
|
+
hasFallback: hasFallback(embed.fallbackHtml),
|
|
28
|
+
maxWidth: 550
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { xPlan };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The player parameters YouTube documents (developers.google.com/youtube/player_parameters). */
|
|
2
|
+
export type YouTubeOptions = {
|
|
3
|
+
autoplay?: boolean;
|
|
4
|
+
ccLangPref?: string;
|
|
5
|
+
ccLoadPolicy?: boolean;
|
|
6
|
+
color?: 'red' | 'white';
|
|
7
|
+
controls?: boolean;
|
|
8
|
+
disablekb?: boolean;
|
|
9
|
+
enablejsapi?: boolean;
|
|
10
|
+
end?: number;
|
|
11
|
+
fs?: boolean;
|
|
12
|
+
hl?: string;
|
|
13
|
+
ivLoadPolicy?: 1 | 3;
|
|
14
|
+
list?: string;
|
|
15
|
+
listType?: 'playlist' | 'user_uploads';
|
|
16
|
+
loop?: boolean;
|
|
17
|
+
origin?: string;
|
|
18
|
+
playlist?: string;
|
|
19
|
+
playsinline?: boolean;
|
|
20
|
+
rel?: boolean;
|
|
21
|
+
start?: number;
|
|
22
|
+
widgetReferrer?: string;
|
|
23
|
+
/** Privacy-enhanced mode: play from youtube-nocookie.com. */
|
|
24
|
+
nocookie?: boolean;
|
|
25
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { optionsWithout, playerParams, query } from "../params.js";
|
|
2
|
+
// src/core/plans/youtube.ts
|
|
3
|
+
const PARAMS = {
|
|
4
|
+
autoplay: "autoplay",
|
|
5
|
+
ccLangPref: "cc_lang_pref",
|
|
6
|
+
ccLoadPolicy: "cc_load_policy",
|
|
7
|
+
color: "color",
|
|
8
|
+
controls: "controls",
|
|
9
|
+
disablekb: "disablekb",
|
|
10
|
+
enablejsapi: "enablejsapi",
|
|
11
|
+
end: "end",
|
|
12
|
+
fs: "fs",
|
|
13
|
+
hl: "hl",
|
|
14
|
+
ivLoadPolicy: "iv_load_policy",
|
|
15
|
+
list: "list",
|
|
16
|
+
listType: "listType",
|
|
17
|
+
loop: "loop",
|
|
18
|
+
origin: "origin",
|
|
19
|
+
playlist: "playlist",
|
|
20
|
+
playsinline: "playsinline",
|
|
21
|
+
rel: "rel",
|
|
22
|
+
start: "start",
|
|
23
|
+
widgetReferrer: "widget_referrer"
|
|
24
|
+
};
|
|
25
|
+
const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
|
|
26
|
+
function player(embed) {
|
|
27
|
+
if (embed.url.startsWith("https://www.youtube.com/playlist?")) return {
|
|
28
|
+
path: "videoseries",
|
|
29
|
+
key: "list"
|
|
30
|
+
};
|
|
31
|
+
if (embed.url.startsWith("https://www.youtube.com/channel/")) return {
|
|
32
|
+
path: "live_stream",
|
|
33
|
+
key: "channel"
|
|
34
|
+
};
|
|
35
|
+
return { path: embed.id };
|
|
36
|
+
}
|
|
37
|
+
function youtubePlan(embed, options) {
|
|
38
|
+
const { nocookie, ...rest } = options;
|
|
39
|
+
const { nocookie: parsedNocookie, ...parsed } = embed.options;
|
|
40
|
+
const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
|
|
41
|
+
const { path, key } = player(embed);
|
|
42
|
+
const params = playerParams(rest, PARAMS).filter(([name]) => name !== key);
|
|
43
|
+
return {
|
|
44
|
+
kind: "iframe",
|
|
45
|
+
src: `${host}/embed/${path}${query(key === void 0 ? void 0 : [[key, embed.id]], optionsWithout(parsed, key === void 0 ? [] : [key]), params)}`,
|
|
46
|
+
title: "YouTube video player",
|
|
47
|
+
allow: ALLOW,
|
|
48
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
49
|
+
ratio: embed.url.includes("/shorts/") ? {
|
|
50
|
+
width: 9,
|
|
51
|
+
height: 16
|
|
52
|
+
} : {
|
|
53
|
+
width: 16,
|
|
54
|
+
height: 9
|
|
55
|
+
},
|
|
56
|
+
size: embed.size
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export { youtubePlan };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/core/post-link.ts
|
|
2
|
+
const URL_ATTRIBUTES = [
|
|
3
|
+
"href",
|
|
4
|
+
"data-href",
|
|
5
|
+
"data-instgrm-permalink",
|
|
6
|
+
"data-text-post-permalink"
|
|
7
|
+
];
|
|
8
|
+
/** Read it before the platform script runs, which replaces the markup. */
|
|
9
|
+
function postUrl(container) {
|
|
10
|
+
const element = container.querySelector(URL_ATTRIBUTES.map((name) => `[${name}]`).join());
|
|
11
|
+
for (const name of URL_ATTRIBUTES) {
|
|
12
|
+
const value = element?.getAttribute(name);
|
|
13
|
+
if (value) return value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function postLinkText(label) {
|
|
17
|
+
return `View this post on ${label}`;
|
|
18
|
+
}
|
|
19
|
+
export { postLinkText, postUrl };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { needsLookup } from "../parser/lookup.js";
|
|
2
|
+
import { matchWith } from "../parser/match-url.js";
|
|
3
|
+
import { verifyWith } from "../parser/verify.js";
|
|
4
|
+
// src/core/resolve.ts
|
|
5
|
+
const NAMES = {
|
|
6
|
+
x: "X",
|
|
7
|
+
instagram: "Instagram",
|
|
8
|
+
facebook: "Facebook",
|
|
9
|
+
threads: "Threads",
|
|
10
|
+
tiktok: "TikTok",
|
|
11
|
+
youtube: "YouTube",
|
|
12
|
+
telegram: "Telegram",
|
|
13
|
+
snapchat: "Snapchat",
|
|
14
|
+
linkedin: "LinkedIn",
|
|
15
|
+
reddit: "Reddit",
|
|
16
|
+
pinterest: "Pinterest",
|
|
17
|
+
spotify: "Spotify",
|
|
18
|
+
vimeo: "Vimeo",
|
|
19
|
+
twitch: "Twitch",
|
|
20
|
+
dailymotion: "Dailymotion",
|
|
21
|
+
bluesky: "Bluesky",
|
|
22
|
+
soundcloud: "SoundCloud",
|
|
23
|
+
applemusic: "Apple Music",
|
|
24
|
+
applepodcasts: "Apple Podcasts",
|
|
25
|
+
tumblr: "Tumblr",
|
|
26
|
+
kick: "Kick",
|
|
27
|
+
giphy: "Giphy",
|
|
28
|
+
truthsocial: "Truth Social",
|
|
29
|
+
imgur: "Imgur",
|
|
30
|
+
tenor: "Tenor",
|
|
31
|
+
streamable: "Streamable",
|
|
32
|
+
strava: "Strava",
|
|
33
|
+
flickr: "Flickr",
|
|
34
|
+
rumble: "Rumble"
|
|
35
|
+
};
|
|
36
|
+
/** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
|
|
37
|
+
function lookupMessage(platform) {
|
|
38
|
+
return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
|
|
39
|
+
}
|
|
40
|
+
/** Takes the platform's own parser, so a per-platform component bundles no other (docs/decisions.md D103). */
|
|
41
|
+
function resolveEmbed(url, given, parser) {
|
|
42
|
+
const { platform } = parser;
|
|
43
|
+
const embed = given ?? (url === void 0 ? null : matchWith(parser, url));
|
|
44
|
+
if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
|
|
45
|
+
if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
|
|
46
|
+
if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
|
|
47
|
+
const verified = verifyWith(parser, embed);
|
|
48
|
+
if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
|
|
49
|
+
return { embed: verified };
|
|
50
|
+
}
|
|
51
|
+
/** The message `<SocialEmbed>` reports when its input matches no platform. */
|
|
52
|
+
function sourceError(source) {
|
|
53
|
+
if ("html" in source) return "social-embeds: unrecognised embed code";
|
|
54
|
+
const lookup = needsLookup(source.url);
|
|
55
|
+
return lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${source.url}`;
|
|
56
|
+
}
|
|
57
|
+
export { NAMES, lookupMessage, resolveEmbed, sourceError };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// src/core/timing.ts
|
|
2
|
+
const ROOT_MARGIN = "200px 0px";
|
|
3
|
+
const FRAME_TIMEOUT_MS = 15e3;
|
|
4
|
+
const MAX_REPORTED_HEIGHT = 5e4;
|
|
5
|
+
const RENDER_TIMEOUT_MS = 15e3;
|
|
6
|
+
const RETRY_DELAY_MS = 1e3;
|
|
7
|
+
export { FRAME_TIMEOUT_MS, MAX_REPORTED_HEIGHT, RENDER_TIMEOUT_MS, RETRY_DELAY_MS, ROOT_MARGIN };
|
package/dist/element.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class SocialEmbedElement extends Base {
|
|
|
19
19
|
get maxHeight(): string | null;
|
|
20
20
|
set maxHeight(value: string | null);
|
|
21
21
|
get eager(): boolean;
|
|
22
|
-
set eager(value: boolean | null | undefined);
|
|
22
|
+
set eager(value: boolean | string | null | undefined);
|
|
23
23
|
connectedCallback(): void;
|
|
24
24
|
disconnectedCallback(): void;
|
|
25
25
|
attributeChangedCallback(): void;
|