social-embeds 0.7.1 → 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 +13 -8
- 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,73 @@
|
|
|
1
|
+
// src/core/layout.ts
|
|
2
|
+
function aspectOf(plan) {
|
|
3
|
+
return {
|
|
4
|
+
width: plan.size?.width ?? plan.ratio.width,
|
|
5
|
+
height: plan.size?.height ?? plan.ratio.height
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/** The iframe wrapper's style, without the host's `style`. Numbers are pixels. */
|
|
9
|
+
function frameStyle(plan, layout, reportedHeight) {
|
|
10
|
+
const { width = "100%", maxHeight } = layout;
|
|
11
|
+
const height = layout.height ?? plan.height;
|
|
12
|
+
const maxWidth = layout.maxWidth ?? plan.maxWidth;
|
|
13
|
+
const { width: aspectWidth, height: aspectHeight } = aspectOf(plan);
|
|
14
|
+
const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
|
|
15
|
+
return {
|
|
16
|
+
position: "relative",
|
|
17
|
+
width,
|
|
18
|
+
maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
|
|
19
|
+
...plan.messageHeight ? { height: reportedHeight ?? plan.startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
|
|
20
|
+
height,
|
|
21
|
+
maxHeight
|
|
22
|
+
},
|
|
23
|
+
...plan.borderRadius === void 0 ? {} : {
|
|
24
|
+
borderRadius: plan.borderRadius,
|
|
25
|
+
overflow: "hidden"
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** `src` for a plan with `sizeInSrc`, in a box `width` pixels wide. */
|
|
30
|
+
function srcWithSize(plan, width) {
|
|
31
|
+
const aspect = aspectOf(plan);
|
|
32
|
+
const height = Math.round(width * aspect.height / aspect.width);
|
|
33
|
+
const query = plan.src.indexOf("?");
|
|
34
|
+
const path = query === -1 ? plan.src : plan.src.slice(0, query);
|
|
35
|
+
const rest = query === -1 ? "" : `&${plan.src.slice(query + 1)}`;
|
|
36
|
+
return `${path}?width=${String(width)}&height=${String(height)}${rest}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Calls `onWidth` with the element's rounded width once it has one, then with each new width
|
|
40
|
+
* that has held for WIDTH_SETTLE_MS, so a resize rebuilds the frame once.
|
|
41
|
+
*/
|
|
42
|
+
function watchWidth(element, onWidth) {
|
|
43
|
+
let last;
|
|
44
|
+
let timer;
|
|
45
|
+
const take = (width) => {
|
|
46
|
+
const rounded = Math.round(width);
|
|
47
|
+
if (rounded <= 0) return;
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
if (rounded === last) return;
|
|
50
|
+
if (last === void 0) {
|
|
51
|
+
last = rounded;
|
|
52
|
+
onWidth(rounded);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
timer = setTimeout(() => {
|
|
56
|
+
last = rounded;
|
|
57
|
+
onWidth(rounded);
|
|
58
|
+
}, 200);
|
|
59
|
+
};
|
|
60
|
+
if (typeof ResizeObserver === "undefined") {
|
|
61
|
+
take(element.getBoundingClientRect().width);
|
|
62
|
+
return () => {};
|
|
63
|
+
}
|
|
64
|
+
const observer = new ResizeObserver((entries) => {
|
|
65
|
+
for (const entry of entries) take(entry.contentRect.width);
|
|
66
|
+
});
|
|
67
|
+
observer.observe(element);
|
|
68
|
+
return () => {
|
|
69
|
+
observer.disconnect();
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export { frameStyle, srcWithSize, watchWidth };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { escapeAttribute } from "../parser/html.js";
|
|
2
|
+
// src/core/markup.ts
|
|
3
|
+
/** `true` becomes a valueless attribute. */
|
|
4
|
+
function attributes(entries) {
|
|
5
|
+
let html = "";
|
|
6
|
+
for (const [name, value] of Object.entries(entries)) {
|
|
7
|
+
if (value === void 0) continue;
|
|
8
|
+
html += value === true ? ` ${name}` : ` ${name}="${escapeAttribute(String(value))}"`;
|
|
9
|
+
}
|
|
10
|
+
return html;
|
|
11
|
+
}
|
|
12
|
+
/** Booleans are written as `"true"` and `"false"`, the way the platforms document them. */
|
|
13
|
+
function dataAttributes(names, options) {
|
|
14
|
+
const entries = {};
|
|
15
|
+
for (const [key, name] of Object.entries(names)) {
|
|
16
|
+
const value = options[key];
|
|
17
|
+
if (value !== void 0) entries[name] = String(value);
|
|
18
|
+
}
|
|
19
|
+
return attributes(entries);
|
|
20
|
+
}
|
|
21
|
+
/** Embed code options first; props the host passed replace them. */
|
|
22
|
+
function withProps(options, props) {
|
|
23
|
+
const merged = { ...options };
|
|
24
|
+
for (const [key, value] of Object.entries(props)) if (value !== void 0) merged[key] = value;
|
|
25
|
+
return merged;
|
|
26
|
+
}
|
|
27
|
+
function hasFallback(fallbackHtml) {
|
|
28
|
+
return fallbackHtml !== void 0 && fallbackHtml.trim() !== "";
|
|
29
|
+
}
|
|
30
|
+
export { attributes, dataAttributes, escapeAttribute, hasFallback, withProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/core/params.ts
|
|
2
|
+
/**
|
|
3
|
+
* Security: options are not verified (docs/decisions.md D68). Keys that choose the content
|
|
4
|
+
* come only from the verified url and id.
|
|
5
|
+
*/
|
|
6
|
+
function optionsWithout(options, reserved) {
|
|
7
|
+
return Object.entries(options).filter(([key]) => !reserved.includes(key.toLowerCase()));
|
|
8
|
+
}
|
|
9
|
+
/** Later entries replace earlier ones with the same name. */
|
|
10
|
+
function query(...sources) {
|
|
11
|
+
const params = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const source of sources) for (const [key, value] of source ?? []) params.set(key, String(value));
|
|
13
|
+
const pairs = [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
14
|
+
return pairs.length > 0 ? `?${pairs.join("&")}` : "";
|
|
15
|
+
}
|
|
16
|
+
/** Player parameters take 0 and 1, so booleans become numbers. */
|
|
17
|
+
function playerParams(props, names) {
|
|
18
|
+
const params = [];
|
|
19
|
+
for (const [prop, name] of Object.entries(names)) {
|
|
20
|
+
const value = props[prop];
|
|
21
|
+
if (typeof value === "boolean") params.push([name, value ? 1 : 0]);
|
|
22
|
+
else if (typeof value === "string" || typeof value === "number") params.push([name, value]);
|
|
23
|
+
}
|
|
24
|
+
return params;
|
|
25
|
+
}
|
|
26
|
+
export { optionsWithout, playerParams, query };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/core/plans/apple.ts
|
|
2
|
+
const ALLOW = "autoplay *; encrypted-media *; fullscreen *; clipboard-write";
|
|
3
|
+
const SANDBOX = "allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation";
|
|
4
|
+
const SINGLE_HEIGHT = 175;
|
|
5
|
+
const EPISODE_HEIGHT = 160;
|
|
6
|
+
const FULL_HEIGHT = 450;
|
|
7
|
+
/** A fixed height: the embed code's, else 175px for a song and 450px for the rest. */
|
|
8
|
+
function appleMusicPlan(embed) {
|
|
9
|
+
const path = embed.url.slice(23);
|
|
10
|
+
const single = path.includes("/song/") || path.includes("?i=");
|
|
11
|
+
return {
|
|
12
|
+
kind: "iframe",
|
|
13
|
+
src: `https://embed.music.apple.com${path}`,
|
|
14
|
+
title: "Apple Music player",
|
|
15
|
+
allow: ALLOW,
|
|
16
|
+
sandbox: SANDBOX,
|
|
17
|
+
ratio: {
|
|
18
|
+
width: 16,
|
|
19
|
+
height: 9
|
|
20
|
+
},
|
|
21
|
+
height: embed.size?.height ?? (single ? SINGLE_HEIGHT : FULL_HEIGHT),
|
|
22
|
+
maxWidth: 660,
|
|
23
|
+
borderRadius: 10
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** A fixed height: the embed code's, else 160px for an episode and 450px for a show. */
|
|
27
|
+
function applePodcastsPlan(embed) {
|
|
28
|
+
const path = embed.url.slice(26);
|
|
29
|
+
return {
|
|
30
|
+
kind: "iframe",
|
|
31
|
+
src: `https://embed.podcasts.apple.com${path}`,
|
|
32
|
+
title: "Apple Podcasts player",
|
|
33
|
+
allow: ALLOW,
|
|
34
|
+
sandbox: SANDBOX,
|
|
35
|
+
ratio: {
|
|
36
|
+
width: 16,
|
|
37
|
+
height: 9
|
|
38
|
+
},
|
|
39
|
+
height: embed.size?.height ?? (path.includes("?i=") ? EPISODE_HEIGHT : FULL_HEIGHT),
|
|
40
|
+
maxWidth: 640,
|
|
41
|
+
borderRadius: 12
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export { appleMusicPlan, applePodcastsPlan };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { query } from "../params.js";
|
|
2
|
+
// src/core/plans/bluesky.ts
|
|
3
|
+
/** The frame posts `{ height }` once it has painted (docs/decisions.md D70). */
|
|
4
|
+
const BLUESKY_HEIGHT = {
|
|
5
|
+
origin: "https://embed.bsky.app",
|
|
6
|
+
read(data) {
|
|
7
|
+
const height = data?.height;
|
|
8
|
+
return typeof height === "number" ? height : void 0;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* At most 600px wide by default, Bluesky's oEmbed width. Renders the frame `embed.js` would
|
|
13
|
+
* create, without the script (docs/decisions.md D77). Only embed code and URLs with a DID
|
|
14
|
+
* render: a handle URL needs a lookup, and `onError` says so.
|
|
15
|
+
*/
|
|
16
|
+
function blueskyPlan(embed, options) {
|
|
17
|
+
const mode = options.colorMode ?? embed.options.colorMode;
|
|
18
|
+
return {
|
|
19
|
+
kind: "iframe",
|
|
20
|
+
src: `https://embed.bsky.app/embed/${embed.id}${query(typeof mode === "string" ? [["colorMode", mode]] : void 0)}`,
|
|
21
|
+
title: "Bluesky post",
|
|
22
|
+
allow: "",
|
|
23
|
+
scrolling: "no",
|
|
24
|
+
ratio: {
|
|
25
|
+
width: 1,
|
|
26
|
+
height: 1
|
|
27
|
+
},
|
|
28
|
+
messageHeight: BLUESKY_HEIGHT,
|
|
29
|
+
startHeight: 300,
|
|
30
|
+
maxWidth: 600,
|
|
31
|
+
fallbackHtml: embed.fallbackHtml
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { blueskyPlan };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { optionsWithout, query } from "../params.js";
|
|
2
|
+
// src/core/plans/dailymotion.ts
|
|
3
|
+
const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
|
|
4
|
+
const ALLOW = "autoplay; fullscreen; picture-in-picture; web-share";
|
|
5
|
+
/**
|
|
6
|
+
* Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
|
|
7
|
+
* option, never another account's (docs/decisions.md D63).
|
|
8
|
+
*/
|
|
9
|
+
function dailymotionPlan(embed, options) {
|
|
10
|
+
const { playerId, mute, startTime, loop } = options;
|
|
11
|
+
const { playerId: parsedPlayer, ...parsed } = embed.options;
|
|
12
|
+
const player = playerId ?? parsedPlayer;
|
|
13
|
+
if (player === void 0) return {
|
|
14
|
+
kind: "error",
|
|
15
|
+
message: "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed"
|
|
16
|
+
};
|
|
17
|
+
if (typeof player !== "string" || !PLAYER_ID.test(player)) return {
|
|
18
|
+
kind: "error",
|
|
19
|
+
message: `social-embeds: not a Dailymotion Player ID: ${String(player)}`
|
|
20
|
+
};
|
|
21
|
+
const params = [];
|
|
22
|
+
if (mute !== void 0) params.push(["mute", String(mute)]);
|
|
23
|
+
if (startTime !== void 0) params.push(["startTime", startTime]);
|
|
24
|
+
if (loop !== void 0) params.push(["loop", String(loop)]);
|
|
25
|
+
return {
|
|
26
|
+
kind: "iframe",
|
|
27
|
+
src: `https://geo.dailymotion.com/player/${player}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
|
|
28
|
+
title: "Dailymotion video player",
|
|
29
|
+
allow: ALLOW,
|
|
30
|
+
ratio: {
|
|
31
|
+
width: 16,
|
|
32
|
+
height: 9
|
|
33
|
+
},
|
|
34
|
+
size: embed.size
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { dailymotionPlan };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `data-width` and `data-lazy` have no props, because `width` and `lazy` are the wrapper's
|
|
3
|
+
* (docs/decisions.md D33).
|
|
4
|
+
*/
|
|
5
|
+
export type FacebookOptions = {
|
|
6
|
+
/** SDK locale, such as `bg_BG`. One SDK serves the page: the first locale wins. */
|
|
7
|
+
locale?: string;
|
|
8
|
+
showText?: boolean;
|
|
9
|
+
/** Video only. */
|
|
10
|
+
allowfullscreen?: boolean;
|
|
11
|
+
/** Video only. */
|
|
12
|
+
autoplay?: boolean;
|
|
13
|
+
/** Video only. */
|
|
14
|
+
showCaptions?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { escapeAttribute } from "../../parser/html.js";
|
|
2
|
+
import { facebookDriver } from "../drivers.js";
|
|
3
|
+
import { dataAttributes, hasFallback, withProps } from "../markup.js";
|
|
4
|
+
import { query } from "../params.js";
|
|
5
|
+
// src/core/plans/facebook.ts
|
|
6
|
+
const ATTRIBUTES = {
|
|
7
|
+
width: "data-width",
|
|
8
|
+
showText: "data-show-text",
|
|
9
|
+
lazy: "data-lazy",
|
|
10
|
+
allowfullscreen: "data-allowfullscreen",
|
|
11
|
+
autoplay: "data-autoplay",
|
|
12
|
+
showCaptions: "data-show-captions"
|
|
13
|
+
};
|
|
14
|
+
const PLAYER_PARAMETERS = {
|
|
15
|
+
showText: "show_text",
|
|
16
|
+
allowfullscreen: "allowfullscreen",
|
|
17
|
+
autoplay: "autoplay",
|
|
18
|
+
showCaptions: "show_captions"
|
|
19
|
+
};
|
|
20
|
+
/** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
|
|
21
|
+
const POST_MAX_WIDTH = 750;
|
|
22
|
+
/** docs/decisions.md D34. */
|
|
23
|
+
const MIN_HEIGHT = {
|
|
24
|
+
post: 300,
|
|
25
|
+
video: 200
|
|
26
|
+
};
|
|
27
|
+
const ALLOW = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
|
|
28
|
+
/** Its content fills the iframe at any width, whatever `width` says (docs/decisions.md D29). */
|
|
29
|
+
function facebookVideoPlan(embed) {
|
|
30
|
+
const params = Object.entries(embed.options).filter(([key]) => key !== "href");
|
|
31
|
+
return {
|
|
32
|
+
kind: "iframe",
|
|
33
|
+
src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
|
|
34
|
+
title: "Facebook video player",
|
|
35
|
+
allow: ALLOW,
|
|
36
|
+
scrolling: "no",
|
|
37
|
+
ratio: {
|
|
38
|
+
width: 16,
|
|
39
|
+
height: 9
|
|
40
|
+
},
|
|
41
|
+
size: embed.size
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function facebookPlan(embed, options) {
|
|
45
|
+
if (embed.variant === "iframe") return facebookVideoPlan(embed);
|
|
46
|
+
const merged = withProps(embed.options, {
|
|
47
|
+
showText: options.showText,
|
|
48
|
+
allowfullscreen: options.allowfullscreen,
|
|
49
|
+
autoplay: options.autoplay,
|
|
50
|
+
showCaptions: options.showCaptions
|
|
51
|
+
});
|
|
52
|
+
const { size } = embed;
|
|
53
|
+
if (embed.kind === "video" && merged.showText === false && size?.width !== void 0 && size.height !== void 0) {
|
|
54
|
+
const parameters = {};
|
|
55
|
+
for (const [option, name] of Object.entries(PLAYER_PARAMETERS)) {
|
|
56
|
+
const value = merged[option];
|
|
57
|
+
if (value !== void 0) parameters[name] = value;
|
|
58
|
+
}
|
|
59
|
+
parameters.width = size.width;
|
|
60
|
+
parameters.height = size.height;
|
|
61
|
+
return facebookVideoPlan({
|
|
62
|
+
...embed,
|
|
63
|
+
options: parameters
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const sdkLocale = options.locale ?? (typeof merged.locale === "string" ? merged.locale : "en_US");
|
|
67
|
+
const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES, merged)}>${embed.fallbackHtml ?? ""}</div>`;
|
|
68
|
+
return {
|
|
69
|
+
kind: "script",
|
|
70
|
+
key: `${sdkLocale} ${markup}`,
|
|
71
|
+
markup,
|
|
72
|
+
driver: facebookDriver(sdkLocale),
|
|
73
|
+
minHeight: MIN_HEIGHT[embed.kind],
|
|
74
|
+
label: "Facebook",
|
|
75
|
+
hasFallback: hasFallback(embed.fallbackHtml),
|
|
76
|
+
maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export { facebookPlan, facebookVideoPlan };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/core/plans/flickr.ts
|
|
2
|
+
const OPTIONS = [
|
|
3
|
+
"header",
|
|
4
|
+
"footer",
|
|
5
|
+
"context"
|
|
6
|
+
];
|
|
7
|
+
const ALBUM = /\/albums\/\d+$/;
|
|
8
|
+
const IMAGE_STYLE = "display:block;width:100%;height:100%;object-fit:cover";
|
|
9
|
+
/** Embed code keeps its image's ratio and is at most as wide as the image; a URL renders at 4:3 (docs/decisions.md D98). */
|
|
10
|
+
function flickrPlan(embed, options) {
|
|
11
|
+
const album = ALBUM.test(embed.url);
|
|
12
|
+
const kept = OPTIONS.filter((name) => options[name] ?? embed.options[name] === true);
|
|
13
|
+
const { width, height } = embed.size ?? {};
|
|
14
|
+
const size = width !== void 0 && height !== void 0 ? {
|
|
15
|
+
width,
|
|
16
|
+
height
|
|
17
|
+
} : void 0;
|
|
18
|
+
return {
|
|
19
|
+
kind: "iframe",
|
|
20
|
+
src: `https://embedr.flickr.com/${album ? "photosets" : "photos"}/${embed.id}${kept.length > 0 ? `?${kept.map((name) => `${name}=true`).join("&")}` : ""}`,
|
|
21
|
+
title: album ? "Flickr album" : "Flickr photo",
|
|
22
|
+
allow: "",
|
|
23
|
+
scrolling: "no",
|
|
24
|
+
ratio: {
|
|
25
|
+
width: 4,
|
|
26
|
+
height: 3
|
|
27
|
+
},
|
|
28
|
+
...size ? {
|
|
29
|
+
size,
|
|
30
|
+
maxWidth: size.width
|
|
31
|
+
} : {},
|
|
32
|
+
sizeInSrc: true,
|
|
33
|
+
...embed.fallbackHtml === void 0 ? {} : { fallbackHtml: embed.fallbackHtml.replace(/<img(?=[\s>])/g, `<img style="${IMAGE_STYLE}"`) },
|
|
34
|
+
fallbackImage: true
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { flickrPlan };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { checkIframe } from "../../parser/iframe.js";
|
|
2
|
+
// src/core/plans/generic.ts
|
|
3
|
+
const DEFAULT_RATIO = {
|
|
4
|
+
width: 16,
|
|
5
|
+
height: 9
|
|
6
|
+
};
|
|
7
|
+
/** Re-checks the embed, so a host-built value renders only what `parseIframe` would keep. */
|
|
8
|
+
function genericPlan(embed) {
|
|
9
|
+
const checked = checkIframe(embed);
|
|
10
|
+
if (!checked) return {
|
|
11
|
+
kind: "error",
|
|
12
|
+
message: "social-embeds: not a generic iframe embed"
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
kind: "iframe",
|
|
16
|
+
src: checked.src,
|
|
17
|
+
title: checked.title ?? "Embedded content",
|
|
18
|
+
allow: checked.allow,
|
|
19
|
+
allowFullscreen: checked.allowFullscreen,
|
|
20
|
+
...checked.referrerPolicy ? { referrerPolicy: checked.referrerPolicy } : {},
|
|
21
|
+
...checked.sandbox === void 0 ? {} : { sandbox: checked.sandbox },
|
|
22
|
+
...checked.scrolling ? { scrolling: checked.scrolling } : {},
|
|
23
|
+
...layout(checked)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function layout({ size, ratio }) {
|
|
27
|
+
const { width, height } = size;
|
|
28
|
+
if (width !== void 0 && height !== void 0) return {
|
|
29
|
+
ratio: {
|
|
30
|
+
width,
|
|
31
|
+
height
|
|
32
|
+
},
|
|
33
|
+
maxWidth: width
|
|
34
|
+
};
|
|
35
|
+
if (height !== void 0) return {
|
|
36
|
+
ratio: DEFAULT_RATIO,
|
|
37
|
+
height
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
ratio: ratio ?? DEFAULT_RATIO,
|
|
41
|
+
...width === void 0 ? {} : { maxWidth: width }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export { genericPlan };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/core/plans/giphy.ts
|
|
2
|
+
/** The embed code's aspect ratio; a URL carries no size and renders square (docs/decisions.md D76). */
|
|
3
|
+
function giphyPlan(embed) {
|
|
4
|
+
return {
|
|
5
|
+
kind: "iframe",
|
|
6
|
+
src: `https://giphy.com/embed/${embed.id}`,
|
|
7
|
+
title: "Giphy GIF",
|
|
8
|
+
allow: "fullscreen",
|
|
9
|
+
ratio: {
|
|
10
|
+
width: 1,
|
|
11
|
+
height: 1
|
|
12
|
+
},
|
|
13
|
+
size: embed.size
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { giphyPlan };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/core/plans/imgur.ts
|
|
2
|
+
/** The frame posts one JSON string at `load`, unasked (docs/decisions.md D94). */
|
|
3
|
+
const IMGUR_HEIGHT = {
|
|
4
|
+
origin: "https://imgur.com",
|
|
5
|
+
read(data) {
|
|
6
|
+
if (typeof data !== "string") return void 0;
|
|
7
|
+
const message = JSON.parse(data);
|
|
8
|
+
return message.message === "resize_imgur" && typeof message.height === "number" ? message.height : void 0;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/** At most 540px wide by default, the widest `embed.js` makes the frame (docs/decisions.md D94). */
|
|
12
|
+
function imgurPlan(embed, options) {
|
|
13
|
+
const params = [
|
|
14
|
+
"pub=true",
|
|
15
|
+
...options.context ?? embed.options.context !== false ? [] : ["context=false"],
|
|
16
|
+
...embed.options.analytics === false ? ["analytics=false"] : []
|
|
17
|
+
];
|
|
18
|
+
return {
|
|
19
|
+
kind: "iframe",
|
|
20
|
+
src: `https://imgur.com/${embed.id}/embed?${params.join("&")}`,
|
|
21
|
+
title: "Imgur post",
|
|
22
|
+
allow: "",
|
|
23
|
+
scrolling: "no",
|
|
24
|
+
ratio: {
|
|
25
|
+
width: 1,
|
|
26
|
+
height: 1
|
|
27
|
+
},
|
|
28
|
+
messageHeight: IMGUR_HEIGHT,
|
|
29
|
+
startHeight: 500,
|
|
30
|
+
maxWidth: 540,
|
|
31
|
+
fallbackHtml: embed.fallbackHtml
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { imgurPlan };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { instagramDriver } from "../drivers.js";
|
|
2
|
+
import { attributes, hasFallback, withProps } from "../markup.js";
|
|
3
|
+
// src/core/plans/instagram.ts
|
|
4
|
+
/** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
|
|
5
|
+
const MIN_HEIGHT = 680;
|
|
6
|
+
const FLUID_WIDTH = "width:calc(100% - 2px)";
|
|
7
|
+
function instagramPlan(embed, options) {
|
|
8
|
+
const merged = withProps(embed.options, { captioned: options.captioned });
|
|
9
|
+
const markup = `<blockquote${attributes({
|
|
10
|
+
"data-instgrm-permalink": embed.url,
|
|
11
|
+
"data-instgrm-version": merged.version,
|
|
12
|
+
"data-instgrm-captioned": merged.captioned === true ? true : void 0,
|
|
13
|
+
style: FLUID_WIDTH
|
|
14
|
+
})}>${embed.fallbackHtml ?? ""}</blockquote>`;
|
|
15
|
+
return {
|
|
16
|
+
kind: "script",
|
|
17
|
+
key: markup,
|
|
18
|
+
markup,
|
|
19
|
+
driver: instagramDriver,
|
|
20
|
+
minHeight: MIN_HEIGHT,
|
|
21
|
+
label: "Instagram",
|
|
22
|
+
hasFallback: hasFallback(embed.fallbackHtml),
|
|
23
|
+
maxWidth: 540
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { instagramPlan };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { query } from "../params.js";
|
|
2
|
+
// src/core/plans/kick.ts
|
|
3
|
+
const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
|
|
4
|
+
/** A live channel at 16:9. */
|
|
5
|
+
function kickPlan(embed, options) {
|
|
6
|
+
const fromOptions = [];
|
|
7
|
+
if (options.autoplay !== void 0) fromOptions.push(["autoplay", options.autoplay]);
|
|
8
|
+
if (options.muted !== void 0) fromOptions.push(["muted", options.muted]);
|
|
9
|
+
return {
|
|
10
|
+
kind: "iframe",
|
|
11
|
+
src: `https://player.kick.com/${embed.id}${query(Object.entries(embed.options).filter(([key]) => KEPT.has(key)), fromOptions)}`,
|
|
12
|
+
title: "Kick player",
|
|
13
|
+
allow: "autoplay; fullscreen",
|
|
14
|
+
scrolling: "no",
|
|
15
|
+
ratio: {
|
|
16
|
+
width: 16,
|
|
17
|
+
height: 9
|
|
18
|
+
},
|
|
19
|
+
size: embed.size
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { kickPlan };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { query } from "../params.js";
|
|
2
|
+
// src/core/plans/linkedin.ts
|
|
3
|
+
const DEFAULT_HEIGHT = 670;
|
|
4
|
+
const DEFAULT_WIDTH = 504;
|
|
5
|
+
/** A fixed height: the embed code's, else 670px. */
|
|
6
|
+
function linkedinPlan(embed, options) {
|
|
7
|
+
const params = new Map(Object.entries(embed.options));
|
|
8
|
+
if (options.collapsed === true) params.set("collapsed", 1);
|
|
9
|
+
if (options.collapsed === false) params.delete("collapsed");
|
|
10
|
+
return {
|
|
11
|
+
kind: "iframe",
|
|
12
|
+
src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
|
|
13
|
+
title: "LinkedIn post",
|
|
14
|
+
allow: "",
|
|
15
|
+
ratio: {
|
|
16
|
+
width: DEFAULT_WIDTH,
|
|
17
|
+
height: DEFAULT_HEIGHT
|
|
18
|
+
},
|
|
19
|
+
height: embed.size?.height ?? DEFAULT_HEIGHT,
|
|
20
|
+
maxWidth: embed.size?.width ?? DEFAULT_WIDTH
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { linkedinPlan };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { escapeAttribute } from "../../parser/html.js";
|
|
2
|
+
import { pinterestDriver } from "../drivers.js";
|
|
3
|
+
import { dataAttributes, withProps } from "../markup.js";
|
|
4
|
+
// src/core/plans/pinterest.ts
|
|
5
|
+
const ATTRIBUTES = {
|
|
6
|
+
width: "data-pin-width",
|
|
7
|
+
lang: "data-pin-lang",
|
|
8
|
+
terse: "data-pin-terse"
|
|
9
|
+
};
|
|
10
|
+
const PIN_WIDTHS = {
|
|
11
|
+
small: 236,
|
|
12
|
+
medium: 345,
|
|
13
|
+
large: 600
|
|
14
|
+
};
|
|
15
|
+
const DEFAULT_PIN_WIDTH = 236;
|
|
16
|
+
const MIN_HEIGHT = 270;
|
|
17
|
+
function pinterestPlan(embed, options) {
|
|
18
|
+
const merged = withProps(embed.options, { width: options.pinWidth });
|
|
19
|
+
const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES, merged)}></a>`;
|
|
20
|
+
return {
|
|
21
|
+
kind: "script",
|
|
22
|
+
key: markup,
|
|
23
|
+
markup,
|
|
24
|
+
driver: pinterestDriver,
|
|
25
|
+
minHeight: MIN_HEIGHT,
|
|
26
|
+
label: "Pinterest",
|
|
27
|
+
hasFallback: false,
|
|
28
|
+
maxWidth: PIN_WIDTHS[String(merged.width)] ?? DEFAULT_PIN_WIDTH
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { pinterestPlan };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The `data-embed-*` options of Reddit's embed code that hosts set most. */
|
|
2
|
+
export type RedditOptions = {
|
|
3
|
+
theme?: 'light' | 'dark';
|
|
4
|
+
showMedia?: boolean;
|
|
5
|
+
showTitle?: boolean;
|
|
6
|
+
showUsername?: boolean;
|
|
7
|
+
/** Language of the post, which Reddit machine-translates (docs/decisions.md D52). */
|
|
8
|
+
locale?: string;
|
|
9
|
+
/** Replies shown under an embedded comment. */
|
|
10
|
+
depth?: number;
|
|
11
|
+
};
|