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,5 @@
|
|
|
1
|
+
import { XOptions } from "../core/plans/x.js";
|
|
2
|
+
import { EmbedSource, SharedProps } from "./shared.js";
|
|
3
|
+
export type XEmbedProps = EmbedSource & Omit<SharedProps, keyof XOptions> & XOptions;
|
|
4
|
+
export declare function XEmbed(props: XEmbedProps): import("react").JSX.Element | null;
|
|
5
|
+
export type { XOptions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { xPlan } from "../core/plans/x.js";
|
|
2
|
+
import { x } from "../parser/platforms/x.js";
|
|
3
|
+
import { useReportError } from "./hooks.js";
|
|
4
|
+
import { ScriptEmbed } from "./script-embed.js";
|
|
5
|
+
import { resolveEmbed } from "../core/resolve.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/x-embed.tsx
|
|
8
|
+
function XEmbed(props) {
|
|
9
|
+
const { url, embed: given, onError, maxWidth, theme, conversation, cards, align, lang, dnt, ...shared } = props;
|
|
10
|
+
const { embed, error } = resolveEmbed(url, given, x);
|
|
11
|
+
const plan = embed ? xPlan(embed, {
|
|
12
|
+
theme,
|
|
13
|
+
conversation,
|
|
14
|
+
cards,
|
|
15
|
+
align,
|
|
16
|
+
lang,
|
|
17
|
+
dnt
|
|
18
|
+
}) : void 0;
|
|
19
|
+
useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
|
|
20
|
+
if (plan?.kind !== "script") return null;
|
|
21
|
+
return /* @__PURE__ */ jsx(ScriptEmbed, {
|
|
22
|
+
...shared,
|
|
23
|
+
onError,
|
|
24
|
+
maxWidth: maxWidth ?? plan.maxWidth,
|
|
25
|
+
driver: plan.driver,
|
|
26
|
+
markup: plan.markup,
|
|
27
|
+
hasFallback: plan.hasFallback,
|
|
28
|
+
minHeight: plan.minHeight,
|
|
29
|
+
label: plan.label
|
|
30
|
+
}, plan.key);
|
|
31
|
+
}
|
|
32
|
+
export { XEmbed };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { YouTubeOptions } from "../core/plans/youtube.js";
|
|
2
|
+
import { EmbedSource, FrameProps } from "./shared.js";
|
|
3
|
+
export type YouTubeEmbedProps = EmbedSource & Omit<FrameProps, keyof YouTubeOptions> & YouTubeOptions;
|
|
4
|
+
export declare function YouTubeEmbed(props: YouTubeEmbedProps): import("react").JSX.Element | null;
|
|
5
|
+
export type { YouTubeOptions };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { youtubePlan } from "../core/plans/youtube.js";
|
|
2
|
+
import { youtube } from "../parser/platforms/youtube.js";
|
|
3
|
+
import { useReportError } from "./hooks.js";
|
|
4
|
+
import { IframeEmbed, planProps } from "./iframe-embed.js";
|
|
5
|
+
import { resolveEmbed } from "../core/resolve.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/youtube-embed.tsx
|
|
8
|
+
function YouTubeEmbed(props) {
|
|
9
|
+
const { url, embed: given, onError, maxWidth, autoplay, ccLangPref, ccLoadPolicy, color, controls, disablekb, enablejsapi, end, fs, hl, ivLoadPolicy, list, listType, loop, origin, playlist, playsinline, rel, start, widgetReferrer, nocookie, ...frame } = props;
|
|
10
|
+
const { embed, error } = resolveEmbed(url, given, youtube);
|
|
11
|
+
const plan = embed ? youtubePlan(embed, {
|
|
12
|
+
autoplay,
|
|
13
|
+
ccLangPref,
|
|
14
|
+
ccLoadPolicy,
|
|
15
|
+
color,
|
|
16
|
+
controls,
|
|
17
|
+
disablekb,
|
|
18
|
+
enablejsapi,
|
|
19
|
+
end,
|
|
20
|
+
fs,
|
|
21
|
+
hl,
|
|
22
|
+
ivLoadPolicy,
|
|
23
|
+
list,
|
|
24
|
+
listType,
|
|
25
|
+
loop,
|
|
26
|
+
origin,
|
|
27
|
+
playlist,
|
|
28
|
+
playsinline,
|
|
29
|
+
rel,
|
|
30
|
+
start,
|
|
31
|
+
widgetReferrer,
|
|
32
|
+
nocookie
|
|
33
|
+
}) : void 0;
|
|
34
|
+
useReportError(error ?? (plan?.kind === "error" ? plan.message : void 0), onError);
|
|
35
|
+
if (plan?.kind !== "iframe") return null;
|
|
36
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
37
|
+
...frame,
|
|
38
|
+
...planProps(plan),
|
|
39
|
+
onError,
|
|
40
|
+
maxWidth: maxWidth ?? plan.maxWidth
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export { YouTubeEmbed };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { FACEBOOK_SDK_VERSION, loadPlatformScript } from "../loader/platform-scripts.js";
|
|
2
|
+
// src/core/drivers.ts
|
|
3
|
+
const globals = () => window;
|
|
4
|
+
/** Thrown by `render` when another attempt cannot succeed. */
|
|
5
|
+
var FinalError = class extends Error {};
|
|
6
|
+
function watch(container, rendered, done) {
|
|
7
|
+
if (rendered(container)) {
|
|
8
|
+
done();
|
|
9
|
+
return () => {};
|
|
10
|
+
}
|
|
11
|
+
const observer = new MutationObserver(() => {
|
|
12
|
+
if (!rendered(container)) return;
|
|
13
|
+
observer.disconnect();
|
|
14
|
+
done();
|
|
15
|
+
});
|
|
16
|
+
observer.observe(container, {
|
|
17
|
+
subtree: true,
|
|
18
|
+
childList: true,
|
|
19
|
+
attributes: true,
|
|
20
|
+
attributeFilter: [
|
|
21
|
+
"class",
|
|
22
|
+
"style",
|
|
23
|
+
"height"
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function reveal(container, className) {
|
|
31
|
+
const blockquote = container.querySelector("blockquote");
|
|
32
|
+
if (blockquote && !blockquote.hasAttribute("class")) blockquote.classList.add(className);
|
|
33
|
+
}
|
|
34
|
+
function hasSizedIframe(container) {
|
|
35
|
+
return [...container.querySelectorAll("iframe")].some((iframe) => Number.parseFloat(iframe.style.height) > 0);
|
|
36
|
+
}
|
|
37
|
+
const xDriver = {
|
|
38
|
+
load: () => loadPlatformScript("x"),
|
|
39
|
+
render(container, done) {
|
|
40
|
+
const twttr = globals().twttr;
|
|
41
|
+
const onRendered = (event) => {
|
|
42
|
+
if (event.target instanceof Node && container.contains(event.target)) done();
|
|
43
|
+
};
|
|
44
|
+
twttr?.events?.bind?.("rendered", onRendered);
|
|
45
|
+
const stop = watch(container, hasSizedIframe, done);
|
|
46
|
+
reveal(container, "twitter-tweet");
|
|
47
|
+
twttr?.widgets?.load?.(container);
|
|
48
|
+
return () => {
|
|
49
|
+
twttr?.events?.unbind?.("rendered", onRendered);
|
|
50
|
+
stop();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function inDocument(container, label) {
|
|
55
|
+
if (container.getRootNode() !== document) throw new FinalError(`social-embeds: the ${label} embed cannot render inside a shadow root`);
|
|
56
|
+
}
|
|
57
|
+
/** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
|
|
58
|
+
function processEmbeds() {
|
|
59
|
+
const process = globals().instgrm?.Embeds?.process;
|
|
60
|
+
if (!process) throw new Error("social-embeds: instgrm.Embeds.process is missing");
|
|
61
|
+
process();
|
|
62
|
+
}
|
|
63
|
+
const instagramDriver = {
|
|
64
|
+
load: () => loadPlatformScript("instagram"),
|
|
65
|
+
render(container, done) {
|
|
66
|
+
inDocument(container, "Instagram");
|
|
67
|
+
const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
|
|
68
|
+
reveal(container, "instagram-media");
|
|
69
|
+
processEmbeds();
|
|
70
|
+
return stop;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const threadsDriver = {
|
|
74
|
+
load: () => loadPlatformScript("threads"),
|
|
75
|
+
render(container, done) {
|
|
76
|
+
inDocument(container, "Threads");
|
|
77
|
+
const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
|
|
78
|
+
reveal(container, "text-post-media");
|
|
79
|
+
processEmbeds();
|
|
80
|
+
return stop;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const facebookDrivers = /* @__PURE__ */ new Map();
|
|
84
|
+
function facebookDriver(locale) {
|
|
85
|
+
let driver = facebookDrivers.get(locale);
|
|
86
|
+
if (!driver) {
|
|
87
|
+
driver = {
|
|
88
|
+
load: () => loadPlatformScript("facebook", { locale }),
|
|
89
|
+
render(container, done) {
|
|
90
|
+
const fb = globals().FB;
|
|
91
|
+
const parse = fb?.XFBML?.parse;
|
|
92
|
+
if (!fb || !parse) throw new Error("social-embeds: FB.XFBML.parse is missing");
|
|
93
|
+
const run = () => {
|
|
94
|
+
parse(container, done);
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
run();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!(error instanceof Error) || !/init not called/.test(error.message)) throw error;
|
|
100
|
+
fb.init?.({
|
|
101
|
+
xfbml: false,
|
|
102
|
+
version: FACEBOOK_SDK_VERSION
|
|
103
|
+
});
|
|
104
|
+
run();
|
|
105
|
+
}
|
|
106
|
+
return () => {};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
facebookDrivers.set(locale, driver);
|
|
110
|
+
}
|
|
111
|
+
return driver;
|
|
112
|
+
}
|
|
113
|
+
const pinterestDriver = {
|
|
114
|
+
load: () => loadPlatformScript("pinterest"),
|
|
115
|
+
render(container, done) {
|
|
116
|
+
const build = globals().PinUtils?.build;
|
|
117
|
+
if (!build) throw new Error("social-embeds: PinUtils.build is missing");
|
|
118
|
+
const stop = watch(container, (element) => element.querySelector("span[data-pin-id]") !== null, done);
|
|
119
|
+
const link = container.querySelector("a");
|
|
120
|
+
if (link && !link.hasAttribute("data-pin-do")) link.setAttribute("data-pin-do", "embedPin");
|
|
121
|
+
build(container);
|
|
122
|
+
return stop;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export { FinalError, facebookDriver, instagramDriver, pinterestDriver, threadsDriver, xDriver };
|
|
@@ -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 };
|