social-embeds 0.2.1 → 0.4.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 +174 -44
- package/dist/{index-DCF8EEVz.d.ts → index-CSSlJIJU.d.ts} +1 -1
- package/dist/index.d.ts +105 -3
- package/dist/index.js +773 -255
- package/dist/{parser-BrlUKvvo.js → parser-D7a5KPhN.js} +739 -104
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,290 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as escapeAttribute, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { a as escapeAttribute, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-D7a5KPhN.js";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/hooks.ts
|
|
6
|
+
const ROOT_MARGIN = "200px 0px";
|
|
7
|
+
/** False on the server and in the first client render, so the markup matches on hydration. */
|
|
8
|
+
function useNearViewport(ref, lazy) {
|
|
9
|
+
const [near, setNear] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const element = ref.current;
|
|
12
|
+
if (!lazy || !element || typeof IntersectionObserver === "undefined") {
|
|
13
|
+
setNear(true);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const observer = new IntersectionObserver((entries) => {
|
|
17
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
18
|
+
setNear(true);
|
|
19
|
+
observer.disconnect();
|
|
20
|
+
}
|
|
21
|
+
}, { rootMargin: ROOT_MARGIN });
|
|
22
|
+
observer.observe(element);
|
|
23
|
+
return () => {
|
|
24
|
+
observer.disconnect();
|
|
25
|
+
};
|
|
26
|
+
}, [ref, lazy]);
|
|
27
|
+
return near;
|
|
28
|
+
}
|
|
29
|
+
/** Calls `onError` from an effect, once per distinct message. */
|
|
30
|
+
function useReportError(message, onError) {
|
|
31
|
+
const latest = useRef(onError);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
latest.current = onError;
|
|
34
|
+
});
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (message !== void 0) latest.current?.(new Error(message));
|
|
37
|
+
}, [message]);
|
|
38
|
+
}
|
|
39
|
+
// src/components/iframe-embed.tsx
|
|
40
|
+
const FILL = {
|
|
41
|
+
position: "absolute",
|
|
42
|
+
inset: 0
|
|
43
|
+
};
|
|
44
|
+
const HEIGHT_TIMEOUT_MS = 15e3;
|
|
45
|
+
const MAX_REPORTED_HEIGHT = 5e4;
|
|
46
|
+
function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, sandbox, ratio, size, messageHeight, startHeight, hostParam, width = "100%", maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, onError, style, ...rest }) {
|
|
47
|
+
const frame = useRef(null);
|
|
48
|
+
const iframe = useRef(null);
|
|
49
|
+
const near = useNearViewport(frame, lazy);
|
|
50
|
+
const [loaded, setLoaded] = useState(false);
|
|
51
|
+
const [reportedHeight, setReportedHeight] = useState();
|
|
52
|
+
const reported = useRef(false);
|
|
53
|
+
const callbacks = useRef({
|
|
54
|
+
onLoad,
|
|
55
|
+
onError
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
callbacks.current = {
|
|
59
|
+
onLoad,
|
|
60
|
+
onError
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const report = useCallback(() => {
|
|
64
|
+
setLoaded(true);
|
|
65
|
+
if (reported.current) return;
|
|
66
|
+
reported.current = true;
|
|
67
|
+
callbacks.current.onLoad?.();
|
|
68
|
+
}, []);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!near || !messageHeight) return;
|
|
71
|
+
const { origin, read } = messageHeight;
|
|
72
|
+
let heard = false;
|
|
73
|
+
const listen = (event) => {
|
|
74
|
+
if (event.origin !== origin) return;
|
|
75
|
+
if (!iframe.current || event.source !== iframe.current.contentWindow) return;
|
|
76
|
+
let value;
|
|
77
|
+
try {
|
|
78
|
+
value = read(event.data);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value !== "number" || !(value > 0 && value <= MAX_REPORTED_HEIGHT)) return;
|
|
83
|
+
heard = true;
|
|
84
|
+
setReportedHeight(Math.ceil(value));
|
|
85
|
+
report();
|
|
86
|
+
};
|
|
87
|
+
window.addEventListener("message", listen);
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
if (heard) return;
|
|
90
|
+
setLoaded(true);
|
|
91
|
+
callbacks.current.onError?.(/* @__PURE__ */ new Error(`social-embeds: ${title} did not report its height`));
|
|
92
|
+
}, HEIGHT_TIMEOUT_MS);
|
|
93
|
+
return () => {
|
|
94
|
+
window.removeEventListener("message", listen);
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
};
|
|
97
|
+
}, [
|
|
98
|
+
near,
|
|
99
|
+
messageHeight,
|
|
100
|
+
title,
|
|
101
|
+
report
|
|
102
|
+
]);
|
|
103
|
+
const aspectWidth = size?.width ?? ratio.width;
|
|
104
|
+
const aspectHeight = size?.height ?? ratio.height;
|
|
105
|
+
const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
|
|
106
|
+
const wrapper = {
|
|
107
|
+
position: "relative",
|
|
108
|
+
width,
|
|
109
|
+
maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
|
|
110
|
+
...messageHeight ? { height: reportedHeight ?? startHeight } : height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
|
|
111
|
+
height,
|
|
112
|
+
maxHeight
|
|
113
|
+
},
|
|
114
|
+
...style
|
|
115
|
+
};
|
|
116
|
+
return /* @__PURE__ */ jsx("div", {
|
|
117
|
+
...rest,
|
|
118
|
+
style: wrapper,
|
|
119
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
120
|
+
ref: frame,
|
|
121
|
+
style: FILL,
|
|
122
|
+
children: [near && /* @__PURE__ */ jsx("iframe", {
|
|
123
|
+
ref: iframe,
|
|
124
|
+
src: hostParam ? withHost(src, hostParam) : src,
|
|
125
|
+
title,
|
|
126
|
+
allow,
|
|
127
|
+
allowFullScreen: true,
|
|
128
|
+
referrerPolicy,
|
|
129
|
+
scrolling,
|
|
130
|
+
sandbox,
|
|
131
|
+
style: {
|
|
132
|
+
display: "block",
|
|
133
|
+
width: "100%",
|
|
134
|
+
height: "100%",
|
|
135
|
+
border: 0
|
|
136
|
+
},
|
|
137
|
+
onLoad: () => {
|
|
138
|
+
if (!messageHeight) report();
|
|
139
|
+
}
|
|
140
|
+
}), !loaded && /* @__PURE__ */ jsx("div", {
|
|
141
|
+
style: FILL,
|
|
142
|
+
children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
|
|
143
|
+
})]
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function withHost(src, name) {
|
|
148
|
+
return `${src}${src.includes("?") ? "&" : "?"}${encodeURIComponent(name)}=${encodeURIComponent(window.location.hostname)}`;
|
|
149
|
+
}
|
|
150
|
+
function Skeleton({ minHeight }) {
|
|
151
|
+
return /* @__PURE__ */ jsx("div", {
|
|
152
|
+
"aria-hidden": "true",
|
|
153
|
+
style: {
|
|
154
|
+
width: "100%",
|
|
155
|
+
height: "100%",
|
|
156
|
+
minHeight,
|
|
157
|
+
background: "rgba(128, 128, 128, 0.12)"
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// src/parser/verify.ts
|
|
162
|
+
const SHAPES = {
|
|
163
|
+
x: ["post sdk"],
|
|
164
|
+
instagram: ["post sdk"],
|
|
165
|
+
threads: ["post sdk"],
|
|
166
|
+
facebook: [
|
|
167
|
+
"post sdk",
|
|
168
|
+
"video sdk",
|
|
169
|
+
"video iframe"
|
|
170
|
+
],
|
|
171
|
+
tiktok: ["video iframe"],
|
|
172
|
+
youtube: ["video iframe"],
|
|
173
|
+
telegram: ["post iframe"],
|
|
174
|
+
snapchat: ["post iframe", "video iframe"],
|
|
175
|
+
linkedin: ["post iframe"],
|
|
176
|
+
reddit: ["post iframe"],
|
|
177
|
+
pinterest: ["post sdk"],
|
|
178
|
+
spotify: ["post iframe", "video iframe"],
|
|
179
|
+
vimeo: ["video iframe"],
|
|
180
|
+
twitch: ["video iframe"],
|
|
181
|
+
dailymotion: ["video iframe"]
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
|
|
185
|
+
* into the page: only what this parser itself produces passes (docs/decisions.md D35).
|
|
186
|
+
*/
|
|
187
|
+
function verifyEmbed(embed) {
|
|
188
|
+
const matched = matchUrl(embed.url);
|
|
189
|
+
if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
|
|
190
|
+
if (matched.url !== embed.url) return null;
|
|
191
|
+
if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
|
|
192
|
+
if (embed.fallbackHtml === void 0) return embed;
|
|
193
|
+
if (trustedFallback(embed, embed.fallbackHtml)) return embed;
|
|
194
|
+
const withoutFallback = { ...embed };
|
|
195
|
+
delete withoutFallback.fallbackHtml;
|
|
196
|
+
return withoutFallback;
|
|
197
|
+
}
|
|
198
|
+
function trustedFallback(embed, fallbackHtml) {
|
|
199
|
+
const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
|
|
200
|
+
const nodes = parseHtml(fallbackHtml);
|
|
201
|
+
if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
|
|
202
|
+
if (embed.platform !== "x") return true;
|
|
203
|
+
const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
|
|
204
|
+
return root?.type === "element" && x$1.parse(root)?.id === embed.id;
|
|
205
|
+
}
|
|
206
|
+
// src/components/shared.ts
|
|
207
|
+
const NAMES = {
|
|
208
|
+
x: "X",
|
|
209
|
+
instagram: "Instagram",
|
|
210
|
+
facebook: "Facebook",
|
|
211
|
+
threads: "Threads",
|
|
212
|
+
tiktok: "TikTok",
|
|
213
|
+
youtube: "YouTube",
|
|
214
|
+
telegram: "Telegram",
|
|
215
|
+
snapchat: "Snapchat",
|
|
216
|
+
linkedin: "LinkedIn",
|
|
217
|
+
reddit: "Reddit",
|
|
218
|
+
pinterest: "Pinterest",
|
|
219
|
+
spotify: "Spotify",
|
|
220
|
+
vimeo: "Vimeo",
|
|
221
|
+
twitch: "Twitch",
|
|
222
|
+
dailymotion: "Dailymotion"
|
|
223
|
+
};
|
|
224
|
+
function resolveEmbed(url, given, platform) {
|
|
225
|
+
const embed = given ?? (url === void 0 ? null : matchUrl(url));
|
|
226
|
+
if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
|
|
227
|
+
if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
|
|
228
|
+
const verified = verifyEmbed(embed);
|
|
229
|
+
if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
|
|
230
|
+
return { embed: verified };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Security: options are not verified (docs/decisions.md D68). Keys that choose the content
|
|
234
|
+
* come only from the verified url and id.
|
|
235
|
+
*/
|
|
236
|
+
function optionsWithout(options, reserved) {
|
|
237
|
+
return Object.entries(options).filter(([key]) => !reserved.includes(key));
|
|
238
|
+
}
|
|
239
|
+
/** Later entries replace earlier ones with the same name. */
|
|
240
|
+
function query(...sources) {
|
|
241
|
+
const params = /* @__PURE__ */ new Map();
|
|
242
|
+
for (const source of sources) for (const [key, value] of source ?? []) params.set(key, String(value));
|
|
243
|
+
const pairs = [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
244
|
+
return pairs.length > 0 ? `?${pairs.join("&")}` : "";
|
|
245
|
+
}
|
|
246
|
+
/** Player parameters take 0 and 1, so booleans become numbers. */
|
|
247
|
+
function playerParams(props, names) {
|
|
248
|
+
const params = [];
|
|
249
|
+
for (const [prop, name] of Object.entries(names)) {
|
|
250
|
+
const value = props[prop];
|
|
251
|
+
if (typeof value === "boolean") params.push([name, value ? 1 : 0]);
|
|
252
|
+
else if (typeof value === "string" || typeof value === "number") params.push([name, value]);
|
|
253
|
+
}
|
|
254
|
+
return params;
|
|
255
|
+
}
|
|
256
|
+
// src/components/dailymotion-embed.tsx
|
|
257
|
+
const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
|
|
258
|
+
const ALLOW$7 = "autoplay; fullscreen; picture-in-picture; web-share";
|
|
259
|
+
/**
|
|
260
|
+
* Dailymotion refuses embeds without a Player ID: one from the embed code or the `playerId`
|
|
261
|
+
* prop, never another account's (docs/decisions.md D63).
|
|
262
|
+
*/
|
|
263
|
+
function DailymotionEmbed(props) {
|
|
264
|
+
const { url, embed: given, onError, playerId, mute, startTime, loop, ...frame } = props;
|
|
265
|
+
const resolved = resolveEmbed(url, given, "dailymotion");
|
|
266
|
+
const { playerId: parsedPlayer, ...parsed } = resolved.embed?.options ?? {};
|
|
267
|
+
const player = playerId ?? parsedPlayer;
|
|
268
|
+
const error = resolved.error ?? (player === void 0 ? "social-embeds: a Dailymotion embed needs a Player ID: pass playerId to DailymotionEmbed" : typeof player !== "string" || !PLAYER_ID.test(player) ? `social-embeds: not a Dailymotion Player ID: ${String(player)}` : void 0);
|
|
269
|
+
useReportError(error, onError);
|
|
270
|
+
const { embed } = resolved;
|
|
271
|
+
if (!embed || error) return null;
|
|
272
|
+
const params = [];
|
|
273
|
+
if (mute !== void 0) params.push(["mute", String(mute)]);
|
|
274
|
+
if (startTime !== void 0) params.push(["startTime", startTime]);
|
|
275
|
+
if (loop !== void 0) params.push(["loop", String(loop)]);
|
|
276
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
277
|
+
...frame,
|
|
278
|
+
src: `https://geo.dailymotion.com/player/${String(player)}.html${query([["video", embed.id]], optionsWithout(parsed, ["video", "playlist"]), params)}`,
|
|
279
|
+
title: "Dailymotion video player",
|
|
280
|
+
allow: ALLOW$7,
|
|
281
|
+
ratio: {
|
|
282
|
+
width: 16,
|
|
283
|
+
height: 9
|
|
284
|
+
},
|
|
285
|
+
size: embed.size
|
|
286
|
+
});
|
|
287
|
+
}
|
|
5
288
|
// src/loader/load-script.ts
|
|
6
289
|
const ATTEMPTS$1 = 3;
|
|
7
290
|
const RETRY_DELAY_MS$1 = 1e3;
|
|
@@ -161,11 +444,18 @@ function facebook(locale) {
|
|
|
161
444
|
})
|
|
162
445
|
};
|
|
163
446
|
}
|
|
447
|
+
const pinterest = {
|
|
448
|
+
key: "pinterest",
|
|
449
|
+
url: "https://assets.pinterest.com/js/pinit_main.js",
|
|
450
|
+
isOwn: (src) => /^https?:\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js(?:[?#]|$)/.test(src),
|
|
451
|
+
isPresent: () => typeof globals$1().PinUtils?.build === "function"
|
|
452
|
+
};
|
|
164
453
|
function loadPlatformScript(platform, { locale = "en_US" } = {}) {
|
|
165
454
|
switch (platform) {
|
|
166
455
|
case "x": return loadScript(x);
|
|
167
456
|
case "instagram": return loadScript(instagram);
|
|
168
457
|
case "threads": return loadScript(threads);
|
|
458
|
+
case "pinterest": return loadScript(pinterest);
|
|
169
459
|
case "facebook": return LOCALE.test(locale) ? loadScript(facebook(locale)) : Promise.reject(/* @__PURE__ */ new Error(`social-embeds: invalid Facebook locale "${locale}"`));
|
|
170
460
|
}
|
|
171
461
|
}
|
|
@@ -199,258 +489,101 @@ function reveal(container, className) {
|
|
|
199
489
|
const blockquote = container.querySelector("blockquote");
|
|
200
490
|
if (blockquote && !blockquote.hasAttribute("class")) blockquote.classList.add(className);
|
|
201
491
|
}
|
|
202
|
-
function hasSizedIframe(container) {
|
|
203
|
-
return [...container.querySelectorAll("iframe")].some((iframe) => Number.parseFloat(iframe.style.height) > 0);
|
|
204
|
-
}
|
|
205
|
-
const xDriver = {
|
|
206
|
-
load: () => loadPlatformScript("x"),
|
|
207
|
-
render(container, done) {
|
|
208
|
-
const twttr = globals().twttr;
|
|
209
|
-
const onRendered = (event) => {
|
|
210
|
-
if (event.target instanceof Node && container.contains(event.target)) done();
|
|
211
|
-
};
|
|
212
|
-
twttr?.events?.bind?.("rendered", onRendered);
|
|
213
|
-
const stop = watch(container, hasSizedIframe, done);
|
|
214
|
-
reveal(container, "twitter-tweet");
|
|
215
|
-
twttr?.widgets?.load?.(container);
|
|
216
|
-
return () => {
|
|
217
|
-
twttr?.events?.unbind?.("rendered", onRendered);
|
|
218
|
-
stop();
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
/** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
|
|
223
|
-
function processEmbeds() {
|
|
224
|
-
const process = globals().instgrm?.Embeds?.process;
|
|
225
|
-
if (!process) throw new Error("social-embeds: instgrm.Embeds.process is missing");
|
|
226
|
-
process();
|
|
227
|
-
}
|
|
228
|
-
const instagramDriver = {
|
|
229
|
-
load: () => loadPlatformScript("instagram"),
|
|
230
|
-
render(container, done) {
|
|
231
|
-
const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
|
|
232
|
-
reveal(container, "instagram-media");
|
|
233
|
-
processEmbeds();
|
|
234
|
-
return stop;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
const threadsDriver = {
|
|
238
|
-
load: () => loadPlatformScript("threads"),
|
|
239
|
-
render(container, done) {
|
|
240
|
-
const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
|
|
241
|
-
reveal(container, "text-post-media");
|
|
242
|
-
processEmbeds();
|
|
243
|
-
return stop;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
const facebookDrivers = /* @__PURE__ */ new Map();
|
|
247
|
-
function facebookDriver(locale) {
|
|
248
|
-
let driver = facebookDrivers.get(locale);
|
|
249
|
-
if (!driver) {
|
|
250
|
-
driver = {
|
|
251
|
-
load: () => loadPlatformScript("facebook", { locale }),
|
|
252
|
-
render(container, done) {
|
|
253
|
-
const fb = globals().FB;
|
|
254
|
-
const parse = fb?.XFBML?.parse;
|
|
255
|
-
if (!fb || !parse) throw new Error("social-embeds: FB.XFBML.parse is missing");
|
|
256
|
-
const run = () => {
|
|
257
|
-
parse(container, done);
|
|
258
|
-
};
|
|
259
|
-
try {
|
|
260
|
-
run();
|
|
261
|
-
} catch (error) {
|
|
262
|
-
if (!(error instanceof Error) || !/init not called/.test(error.message)) throw error;
|
|
263
|
-
fb.init?.({
|
|
264
|
-
xfbml: false,
|
|
265
|
-
version: FACEBOOK_SDK_VERSION
|
|
266
|
-
});
|
|
267
|
-
run();
|
|
268
|
-
}
|
|
269
|
-
return () => {};
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
facebookDrivers.set(locale, driver);
|
|
273
|
-
}
|
|
274
|
-
return driver;
|
|
275
|
-
}
|
|
276
|
-
// src/components/hooks.ts
|
|
277
|
-
const ROOT_MARGIN = "200px 0px";
|
|
278
|
-
/** False on the server and in the first client render, so the markup matches on hydration. */
|
|
279
|
-
function useNearViewport(ref, lazy) {
|
|
280
|
-
const [near, setNear] = useState(false);
|
|
281
|
-
useEffect(() => {
|
|
282
|
-
const element = ref.current;
|
|
283
|
-
if (!lazy || !element || typeof IntersectionObserver === "undefined") {
|
|
284
|
-
setNear(true);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const observer = new IntersectionObserver((entries) => {
|
|
288
|
-
if (entries.some((entry) => entry.isIntersecting)) {
|
|
289
|
-
setNear(true);
|
|
290
|
-
observer.disconnect();
|
|
291
|
-
}
|
|
292
|
-
}, { rootMargin: ROOT_MARGIN });
|
|
293
|
-
observer.observe(element);
|
|
294
|
-
return () => {
|
|
295
|
-
observer.disconnect();
|
|
296
|
-
};
|
|
297
|
-
}, [ref, lazy]);
|
|
298
|
-
return near;
|
|
299
|
-
}
|
|
300
|
-
/** Calls `onError` from an effect, once per distinct message. */
|
|
301
|
-
function useReportError(message, onError) {
|
|
302
|
-
const latest = useRef(onError);
|
|
303
|
-
useEffect(() => {
|
|
304
|
-
latest.current = onError;
|
|
305
|
-
});
|
|
306
|
-
useEffect(() => {
|
|
307
|
-
if (message !== void 0) latest.current?.(new Error(message));
|
|
308
|
-
}, [message]);
|
|
309
|
-
}
|
|
310
|
-
// src/components/iframe-embed.tsx
|
|
311
|
-
const FILL = {
|
|
312
|
-
position: "absolute",
|
|
313
|
-
inset: 0
|
|
314
|
-
};
|
|
315
|
-
function IframeEmbed({ src, title, allow, referrerPolicy, scrolling, ratio, size, width = "100%", maxWidth, height, maxHeight, placeholder, lazy = true, onLoad, style, ...rest }) {
|
|
316
|
-
const frame = useRef(null);
|
|
317
|
-
const near = useNearViewport(frame, lazy);
|
|
318
|
-
const [loaded, setLoaded] = useState(false);
|
|
319
|
-
const reported = useRef(false);
|
|
320
|
-
const aspectWidth = size?.width ?? ratio.width;
|
|
321
|
-
const aspectHeight = size?.height ?? ratio.height;
|
|
322
|
-
const widest = maxHeight === void 0 || height !== void 0 ? void 0 : Math.floor(maxHeight * aspectWidth / aspectHeight);
|
|
323
|
-
const wrapper = {
|
|
324
|
-
position: "relative",
|
|
325
|
-
width,
|
|
326
|
-
maxWidth: widest === void 0 || maxWidth !== void 0 && maxWidth < widest ? maxWidth : widest,
|
|
327
|
-
...height === void 0 ? { aspectRatio: `${String(aspectWidth)} / ${String(aspectHeight)}` } : {
|
|
328
|
-
height,
|
|
329
|
-
maxHeight
|
|
330
|
-
},
|
|
331
|
-
...style
|
|
332
|
-
};
|
|
333
|
-
return /* @__PURE__ */ jsx("div", {
|
|
334
|
-
...rest,
|
|
335
|
-
style: wrapper,
|
|
336
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
337
|
-
ref: frame,
|
|
338
|
-
style: FILL,
|
|
339
|
-
children: [near && /* @__PURE__ */ jsx("iframe", {
|
|
340
|
-
src,
|
|
341
|
-
title,
|
|
342
|
-
allow,
|
|
343
|
-
allowFullScreen: true,
|
|
344
|
-
referrerPolicy,
|
|
345
|
-
scrolling,
|
|
346
|
-
style: {
|
|
347
|
-
display: "block",
|
|
348
|
-
width: "100%",
|
|
349
|
-
height: "100%",
|
|
350
|
-
border: 0
|
|
351
|
-
},
|
|
352
|
-
onLoad: () => {
|
|
353
|
-
setLoaded(true);
|
|
354
|
-
if (reported.current) return;
|
|
355
|
-
reported.current = true;
|
|
356
|
-
onLoad?.();
|
|
357
|
-
}
|
|
358
|
-
}), !loaded && /* @__PURE__ */ jsx("div", {
|
|
359
|
-
style: FILL,
|
|
360
|
-
children: placeholder ?? /* @__PURE__ */ jsx(Skeleton, {})
|
|
361
|
-
})]
|
|
362
|
-
})
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
function Skeleton({ minHeight }) {
|
|
366
|
-
return /* @__PURE__ */ jsx("div", {
|
|
367
|
-
"aria-hidden": "true",
|
|
368
|
-
style: {
|
|
369
|
-
width: "100%",
|
|
370
|
-
height: "100%",
|
|
371
|
-
minHeight,
|
|
372
|
-
background: "rgba(128, 128, 128, 0.12)"
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
// src/parser/verify.ts
|
|
377
|
-
const SHAPES = {
|
|
378
|
-
x: ["post sdk"],
|
|
379
|
-
instagram: ["post sdk"],
|
|
380
|
-
threads: ["post sdk"],
|
|
381
|
-
facebook: [
|
|
382
|
-
"post sdk",
|
|
383
|
-
"video sdk",
|
|
384
|
-
"video iframe"
|
|
385
|
-
],
|
|
386
|
-
tiktok: ["video iframe"],
|
|
387
|
-
youtube: ["video iframe"]
|
|
388
|
-
};
|
|
389
|
-
/**
|
|
390
|
-
* Security: the embed may be host-built, and its url, id and `fallbackHtml` are written
|
|
391
|
-
* into the page: only what this parser itself produces passes (docs/decisions.md D35).
|
|
392
|
-
*/
|
|
393
|
-
function verifyEmbed(embed) {
|
|
394
|
-
const matched = matchUrl(embed.url);
|
|
395
|
-
if (matched?.platform !== embed.platform || matched.id !== embed.id) return null;
|
|
396
|
-
if (!SHAPES[embed.platform].includes(`${embed.kind} ${embed.variant}`)) return null;
|
|
397
|
-
if (embed.fallbackHtml === void 0) return embed;
|
|
398
|
-
if (trustedFallback(embed, embed.fallbackHtml)) return embed;
|
|
399
|
-
const withoutFallback = { ...embed };
|
|
400
|
-
delete withoutFallback.fallbackHtml;
|
|
401
|
-
return withoutFallback;
|
|
402
|
-
}
|
|
403
|
-
function trustedFallback(embed, fallbackHtml) {
|
|
404
|
-
const whitelist = platforms.find((platform) => platform.platform === embed.platform)?.fallback;
|
|
405
|
-
const nodes = parseHtml(fallbackHtml);
|
|
406
|
-
if (!whitelist || !nodes || rebuild(nodes, whitelist) !== fallbackHtml) return false;
|
|
407
|
-
if (embed.platform !== "x") return true;
|
|
408
|
-
const [root] = parseHtml(`<blockquote class="twitter-tweet">${fallbackHtml}</blockquote>`) ?? [];
|
|
409
|
-
return root?.type === "element" && x$1.parse(root)?.id === embed.id;
|
|
410
|
-
}
|
|
411
|
-
// src/components/shared.ts
|
|
412
|
-
const NAMES = {
|
|
413
|
-
x: "X",
|
|
414
|
-
instagram: "Instagram",
|
|
415
|
-
facebook: "Facebook",
|
|
416
|
-
threads: "Threads",
|
|
417
|
-
tiktok: "TikTok",
|
|
418
|
-
youtube: "YouTube"
|
|
419
|
-
};
|
|
420
|
-
function resolveEmbed(url, given, platform) {
|
|
421
|
-
const embed = given ?? (url === void 0 ? null : matchUrl(url));
|
|
422
|
-
if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
|
|
423
|
-
if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
|
|
424
|
-
const verified = verifyEmbed(embed);
|
|
425
|
-
if (!verified) return { error: `social-embeds: the ${NAMES[platform]} embed's url and id do not match` };
|
|
426
|
-
return { embed: verified };
|
|
427
|
-
}
|
|
428
|
-
/** Later entries replace earlier ones with the same name. */
|
|
429
|
-
function query(...sources) {
|
|
430
|
-
const params = /* @__PURE__ */ new Map();
|
|
431
|
-
for (const source of sources) for (const [key, value] of source ?? []) params.set(key, String(value));
|
|
432
|
-
const pairs = [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
433
|
-
return pairs.length > 0 ? `?${pairs.join("&")}` : "";
|
|
492
|
+
function hasSizedIframe(container) {
|
|
493
|
+
return [...container.querySelectorAll("iframe")].some((iframe) => Number.parseFloat(iframe.style.height) > 0);
|
|
434
494
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
495
|
+
const xDriver = {
|
|
496
|
+
load: () => loadPlatformScript("x"),
|
|
497
|
+
render(container, done) {
|
|
498
|
+
const twttr = globals().twttr;
|
|
499
|
+
const onRendered = (event) => {
|
|
500
|
+
if (event.target instanceof Node && container.contains(event.target)) done();
|
|
501
|
+
};
|
|
502
|
+
twttr?.events?.bind?.("rendered", onRendered);
|
|
503
|
+
const stop = watch(container, hasSizedIframe, done);
|
|
504
|
+
reveal(container, "twitter-tweet");
|
|
505
|
+
twttr?.widgets?.load?.(container);
|
|
506
|
+
return () => {
|
|
507
|
+
twttr?.events?.unbind?.("rendered", onRendered);
|
|
508
|
+
stop();
|
|
509
|
+
};
|
|
442
510
|
}
|
|
443
|
-
|
|
511
|
+
};
|
|
512
|
+
/** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
|
|
513
|
+
function processEmbeds() {
|
|
514
|
+
const process = globals().instgrm?.Embeds?.process;
|
|
515
|
+
if (!process) throw new Error("social-embeds: instgrm.Embeds.process is missing");
|
|
516
|
+
process();
|
|
517
|
+
}
|
|
518
|
+
const instagramDriver = {
|
|
519
|
+
load: () => loadPlatformScript("instagram"),
|
|
520
|
+
render(container, done) {
|
|
521
|
+
const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
|
|
522
|
+
reveal(container, "instagram-media");
|
|
523
|
+
processEmbeds();
|
|
524
|
+
return stop;
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
const threadsDriver = {
|
|
528
|
+
load: () => loadPlatformScript("threads"),
|
|
529
|
+
render(container, done) {
|
|
530
|
+
const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
|
|
531
|
+
reveal(container, "text-post-media");
|
|
532
|
+
processEmbeds();
|
|
533
|
+
return stop;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
const facebookDrivers = /* @__PURE__ */ new Map();
|
|
537
|
+
function facebookDriver(locale) {
|
|
538
|
+
let driver = facebookDrivers.get(locale);
|
|
539
|
+
if (!driver) {
|
|
540
|
+
driver = {
|
|
541
|
+
load: () => loadPlatformScript("facebook", { locale }),
|
|
542
|
+
render(container, done) {
|
|
543
|
+
const fb = globals().FB;
|
|
544
|
+
const parse = fb?.XFBML?.parse;
|
|
545
|
+
if (!fb || !parse) throw new Error("social-embeds: FB.XFBML.parse is missing");
|
|
546
|
+
const run = () => {
|
|
547
|
+
parse(container, done);
|
|
548
|
+
};
|
|
549
|
+
try {
|
|
550
|
+
run();
|
|
551
|
+
} catch (error) {
|
|
552
|
+
if (!(error instanceof Error) || !/init not called/.test(error.message)) throw error;
|
|
553
|
+
fb.init?.({
|
|
554
|
+
xfbml: false,
|
|
555
|
+
version: FACEBOOK_SDK_VERSION
|
|
556
|
+
});
|
|
557
|
+
run();
|
|
558
|
+
}
|
|
559
|
+
return () => {};
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
facebookDrivers.set(locale, driver);
|
|
563
|
+
}
|
|
564
|
+
return driver;
|
|
444
565
|
}
|
|
566
|
+
const pinterestDriver = {
|
|
567
|
+
load: () => loadPlatformScript("pinterest"),
|
|
568
|
+
render(container, done) {
|
|
569
|
+
const build = globals().PinUtils?.build;
|
|
570
|
+
if (!build) throw new Error("social-embeds: PinUtils.build is missing");
|
|
571
|
+
const stop = watch(container, (element) => element.querySelector("span[data-pin-id]") !== null, done);
|
|
572
|
+
const link = container.querySelector("a");
|
|
573
|
+
if (link && !link.hasAttribute("data-pin-do")) link.setAttribute("data-pin-do", "embedPin");
|
|
574
|
+
build(container);
|
|
575
|
+
return stop;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
445
578
|
// src/components/facebook-video-iframe.tsx
|
|
446
|
-
const ALLOW$
|
|
579
|
+
const ALLOW$6 = "autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share";
|
|
447
580
|
function FacebookVideoIframe({ embed, ...frame }) {
|
|
448
581
|
const params = Object.entries(embed.options).filter(([key]) => key !== "href");
|
|
449
582
|
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
450
583
|
...frame,
|
|
451
584
|
src: `https://www.facebook.com/plugins/video.php${query([["href", embed.url]], params)}`,
|
|
452
585
|
title: "Facebook video player",
|
|
453
|
-
allow: ALLOW$
|
|
586
|
+
allow: ALLOW$6,
|
|
454
587
|
scrolling: "no",
|
|
455
588
|
ratio: {
|
|
456
589
|
width: 16,
|
|
@@ -578,7 +711,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
|
|
|
578
711
|
});
|
|
579
712
|
}
|
|
580
713
|
// src/components/facebook-embed.tsx
|
|
581
|
-
const ATTRIBUTES$
|
|
714
|
+
const ATTRIBUTES$2 = {
|
|
582
715
|
width: "data-width",
|
|
583
716
|
showText: "data-show-text",
|
|
584
717
|
lazy: "data-lazy",
|
|
@@ -595,7 +728,7 @@ const PLAYER_PARAMETERS = {
|
|
|
595
728
|
/** Embedded Posts: "Max. 750 pixel"; videos have no upper limit (docs/decisions.md D33). */
|
|
596
729
|
const POST_MAX_WIDTH = 750;
|
|
597
730
|
/** docs/decisions.md D34. */
|
|
598
|
-
const MIN_HEIGHT$
|
|
731
|
+
const MIN_HEIGHT$4 = {
|
|
599
732
|
post: 300,
|
|
600
733
|
video: 200
|
|
601
734
|
};
|
|
@@ -638,7 +771,7 @@ function FacebookEmbed(props) {
|
|
|
638
771
|
});
|
|
639
772
|
}
|
|
640
773
|
const sdkLocale = locale ?? (typeof options.locale === "string" ? options.locale : "en_US");
|
|
641
|
-
const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$
|
|
774
|
+
const markup = `<div class="${embed.kind === "video" ? "fb-video" : "fb-post"}" data-href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$2, options)}>${embed.fallbackHtml ?? ""}</div>`;
|
|
642
775
|
return /* @__PURE__ */ jsx(ScriptEmbed, {
|
|
643
776
|
maxWidth: embed.kind === "post" ? POST_MAX_WIDTH : void 0,
|
|
644
777
|
...shared,
|
|
@@ -646,13 +779,13 @@ function FacebookEmbed(props) {
|
|
|
646
779
|
driver: facebookDriver(sdkLocale),
|
|
647
780
|
markup,
|
|
648
781
|
hasFallback: hasFallback(embed.fallbackHtml),
|
|
649
|
-
minHeight: MIN_HEIGHT$
|
|
782
|
+
minHeight: MIN_HEIGHT$4[embed.kind],
|
|
650
783
|
label: "Facebook"
|
|
651
784
|
}, `${sdkLocale} ${markup}`);
|
|
652
785
|
}
|
|
653
786
|
// src/components/instagram-embed.tsx
|
|
654
787
|
/** A photo post without caption at 375px, the smallest measured (docs/decisions.md D34). */
|
|
655
|
-
const MIN_HEIGHT$
|
|
788
|
+
const MIN_HEIGHT$3 = 680;
|
|
656
789
|
const FLUID_WIDTH = "width:calc(100% - 2px)";
|
|
657
790
|
function InstagramEmbed(props) {
|
|
658
791
|
const { url, embed: given, onError, maxWidth = 540, captioned, ...shared } = props;
|
|
@@ -673,10 +806,244 @@ function InstagramEmbed(props) {
|
|
|
673
806
|
driver: instagramDriver,
|
|
674
807
|
markup,
|
|
675
808
|
hasFallback: hasFallback(embed.fallbackHtml),
|
|
676
|
-
minHeight: MIN_HEIGHT$
|
|
809
|
+
minHeight: MIN_HEIGHT$3,
|
|
677
810
|
label: "Instagram"
|
|
678
811
|
}, markup);
|
|
679
812
|
}
|
|
813
|
+
// src/components/linkedin-embed.tsx
|
|
814
|
+
const DEFAULT_HEIGHT = 670;
|
|
815
|
+
const DEFAULT_WIDTH = 504;
|
|
816
|
+
/** A fixed height: the `height` prop, else the embed code's, else 670px. */
|
|
817
|
+
function LinkedInEmbed(props) {
|
|
818
|
+
const { url, embed: given, onError, maxWidth, height, collapsed, ...frame } = props;
|
|
819
|
+
const { embed, error } = resolveEmbed(url, given, "linkedin");
|
|
820
|
+
useReportError(error, onError);
|
|
821
|
+
if (!embed) return null;
|
|
822
|
+
const params = new Map(Object.entries(embed.options));
|
|
823
|
+
if (collapsed === true) params.set("collapsed", 1);
|
|
824
|
+
if (collapsed === false) params.delete("collapsed");
|
|
825
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
826
|
+
...frame,
|
|
827
|
+
maxWidth: maxWidth ?? embed.size?.width ?? DEFAULT_WIDTH,
|
|
828
|
+
height: height ?? embed.size?.height ?? DEFAULT_HEIGHT,
|
|
829
|
+
src: `https://www.linkedin.com/embed/feed/update/${embed.id}${query(params)}`,
|
|
830
|
+
title: "LinkedIn post",
|
|
831
|
+
allow: "",
|
|
832
|
+
ratio: {
|
|
833
|
+
width: DEFAULT_WIDTH,
|
|
834
|
+
height: DEFAULT_HEIGHT
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
// src/components/pinterest-embed.tsx
|
|
839
|
+
const ATTRIBUTES$1 = {
|
|
840
|
+
width: "data-pin-width",
|
|
841
|
+
lang: "data-pin-lang",
|
|
842
|
+
terse: "data-pin-terse"
|
|
843
|
+
};
|
|
844
|
+
const PIN_WIDTHS = {
|
|
845
|
+
small: 236,
|
|
846
|
+
medium: 345,
|
|
847
|
+
large: 600
|
|
848
|
+
};
|
|
849
|
+
const DEFAULT_PIN_WIDTH = 236;
|
|
850
|
+
const MIN_HEIGHT$2 = 270;
|
|
851
|
+
function PinterestEmbed(props) {
|
|
852
|
+
const { url, embed: given, onError, maxWidth, pinWidth, ...shared } = props;
|
|
853
|
+
const { embed, error } = resolveEmbed(url, given, "pinterest");
|
|
854
|
+
useReportError(error, onError);
|
|
855
|
+
if (!embed) return null;
|
|
856
|
+
const options = withProps(embed.options, { width: pinWidth });
|
|
857
|
+
const pinWidthPx = PIN_WIDTHS[String(options.width)] ?? DEFAULT_PIN_WIDTH;
|
|
858
|
+
const markup = `<a href="${escapeAttribute(embed.url)}"${dataAttributes(ATTRIBUTES$1, options)}></a>`;
|
|
859
|
+
return /* @__PURE__ */ jsx(ScriptEmbed, {
|
|
860
|
+
...shared,
|
|
861
|
+
onError,
|
|
862
|
+
maxWidth: maxWidth ?? pinWidthPx,
|
|
863
|
+
driver: pinterestDriver,
|
|
864
|
+
markup,
|
|
865
|
+
hasFallback: false,
|
|
866
|
+
minHeight: MIN_HEIGHT$2,
|
|
867
|
+
label: "Pinterest"
|
|
868
|
+
}, markup);
|
|
869
|
+
}
|
|
870
|
+
// src/components/reddit-embed.tsx
|
|
871
|
+
const PARAMS$4 = {
|
|
872
|
+
theme: "theme",
|
|
873
|
+
showMedia: "showmedia",
|
|
874
|
+
showTitle: "showtitle",
|
|
875
|
+
showUsername: "showusername",
|
|
876
|
+
locale: "locale",
|
|
877
|
+
depth: "depth"
|
|
878
|
+
};
|
|
879
|
+
const SANDBOX = "allow-scripts allow-same-origin allow-popups";
|
|
880
|
+
const ALLOW$5 = "clipboard-read; clipboard-write";
|
|
881
|
+
const START_HEIGHT = 316;
|
|
882
|
+
/** docs/decisions.md D52. */
|
|
883
|
+
const REDDIT_HEIGHT = {
|
|
884
|
+
origin: "https://embed.reddit.com",
|
|
885
|
+
read(data) {
|
|
886
|
+
if (typeof data !== "string") return void 0;
|
|
887
|
+
const message = JSON.parse(data);
|
|
888
|
+
return message.type === "resize.embed" && typeof message.data === "number" ? message.data : void 0;
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
/** At most 640px wide by default, the width widgets.js gives the frame (docs/decisions.md D52). */
|
|
892
|
+
function RedditEmbed(props) {
|
|
893
|
+
const { url, embed: given, onError, maxWidth = 640, theme, showMedia, showTitle, showUsername, locale, depth, ...shared } = props;
|
|
894
|
+
const { embed, error } = resolveEmbed(url, given, "reddit");
|
|
895
|
+
useReportError(error, onError);
|
|
896
|
+
if (!embed) return null;
|
|
897
|
+
const fromProps = [];
|
|
898
|
+
const values = {
|
|
899
|
+
theme,
|
|
900
|
+
showMedia,
|
|
901
|
+
showTitle,
|
|
902
|
+
showUsername,
|
|
903
|
+
locale,
|
|
904
|
+
depth
|
|
905
|
+
};
|
|
906
|
+
for (const [prop, name] of Object.entries(PARAMS$4)) {
|
|
907
|
+
const value = values[prop];
|
|
908
|
+
if (value !== void 0) fromProps.push([name, value]);
|
|
909
|
+
}
|
|
910
|
+
const path = embed.url.slice(22);
|
|
911
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
912
|
+
...shared,
|
|
913
|
+
onError,
|
|
914
|
+
maxWidth,
|
|
915
|
+
src: `https://embed.reddit.com${path}${query([["embed", true]], Object.entries(embed.options), fromProps)}`,
|
|
916
|
+
title: "Reddit post",
|
|
917
|
+
allow: ALLOW$5,
|
|
918
|
+
sandbox: SANDBOX,
|
|
919
|
+
scrolling: "no",
|
|
920
|
+
ratio: {
|
|
921
|
+
width: 1,
|
|
922
|
+
height: 1
|
|
923
|
+
},
|
|
924
|
+
messageHeight: REDDIT_HEIGHT,
|
|
925
|
+
startHeight: embed.size?.height ?? START_HEIGHT
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
// src/components/snapchat-embed.tsx
|
|
929
|
+
const ALLOW$4 = "autoplay; camera; microphone; clipboard-write;";
|
|
930
|
+
/** At most 416px wide by default, the size of Snapchat's own embed code (docs/decisions.md D50). */
|
|
931
|
+
function SnapchatEmbed(props) {
|
|
932
|
+
const { url, embed: given, onError, maxWidth = 416, ...frame } = props;
|
|
933
|
+
const { embed, error } = resolveEmbed(url, given, "snapchat");
|
|
934
|
+
useReportError(error, onError);
|
|
935
|
+
if (!embed) return null;
|
|
936
|
+
const title = embed.options.title;
|
|
937
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
938
|
+
...frame,
|
|
939
|
+
maxWidth,
|
|
940
|
+
src: `${embed.url}/embed`,
|
|
941
|
+
title: typeof title === "string" && title !== "" ? title : "Snapchat",
|
|
942
|
+
allow: ALLOW$4,
|
|
943
|
+
scrolling: "no",
|
|
944
|
+
ratio: {
|
|
945
|
+
width: 416,
|
|
946
|
+
height: 692
|
|
947
|
+
},
|
|
948
|
+
size: embed.size
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
// src/components/spotify-embed.tsx
|
|
952
|
+
const ALLOW$3 = "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";
|
|
953
|
+
const COMPACT = /* @__PURE__ */ new Set(["track", "episode"]);
|
|
954
|
+
const COMPACT_HEIGHT = 152;
|
|
955
|
+
const FULL_HEIGHT = 352;
|
|
956
|
+
/**
|
|
957
|
+
* A fixed height: the `height` prop, else the embed code's, else 152px for a track or episode
|
|
958
|
+
* and 352px for the rest. A video show keeps its 16:9 aspect ratio instead.
|
|
959
|
+
*/
|
|
960
|
+
function SpotifyEmbed(props) {
|
|
961
|
+
const { url, embed: given, onError, height, theme, style, ...frame } = props;
|
|
962
|
+
const { embed, error } = resolveEmbed(url, given, "spotify");
|
|
963
|
+
useReportError(error, onError);
|
|
964
|
+
if (!embed) return null;
|
|
965
|
+
const type = new URL(embed.url).pathname.split("/")[1] ?? "";
|
|
966
|
+
const video = embed.kind === "video";
|
|
967
|
+
const params = query(Object.entries(embed.options), theme === void 0 ? void 0 : [["theme", theme]]);
|
|
968
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
969
|
+
...frame,
|
|
970
|
+
style: {
|
|
971
|
+
borderRadius: 12,
|
|
972
|
+
overflow: "hidden",
|
|
973
|
+
...style
|
|
974
|
+
},
|
|
975
|
+
height: video ? height : height ?? embed.size?.height ?? (COMPACT.has(type) ? COMPACT_HEIGHT : FULL_HEIGHT),
|
|
976
|
+
src: `https://open.spotify.com/embed/${type}/${embed.id}${video ? "/video" : ""}${params}`,
|
|
977
|
+
title: "Spotify Embed",
|
|
978
|
+
allow: ALLOW$3,
|
|
979
|
+
ratio: {
|
|
980
|
+
width: 16,
|
|
981
|
+
height: 9
|
|
982
|
+
},
|
|
983
|
+
size: video ? embed.size : void 0
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
// src/components/telegram-embed.tsx
|
|
987
|
+
const PARAMS$3 = [
|
|
988
|
+
["comment", "comment"],
|
|
989
|
+
["userpic", "userpic"],
|
|
990
|
+
["mode", "mode"],
|
|
991
|
+
["single", "single"],
|
|
992
|
+
["color", "color"],
|
|
993
|
+
["dark", "dark"],
|
|
994
|
+
["darkColor", "dark_color"]
|
|
995
|
+
];
|
|
996
|
+
function param(name, value) {
|
|
997
|
+
if (typeof value === "boolean") {
|
|
998
|
+
if (name === "userpic") return String(value);
|
|
999
|
+
if (name === "single") return value ? 1 : void 0;
|
|
1000
|
+
return value ? 1 : 0;
|
|
1001
|
+
}
|
|
1002
|
+
return typeof value === "string" || typeof value === "number" ? value : void 0;
|
|
1003
|
+
}
|
|
1004
|
+
/** docs/decisions.md D49. */
|
|
1005
|
+
const TELEGRAM_HEIGHT = {
|
|
1006
|
+
origin: "https://t.me",
|
|
1007
|
+
read(data) {
|
|
1008
|
+
if (typeof data !== "string") return void 0;
|
|
1009
|
+
const message = JSON.parse(data);
|
|
1010
|
+
return message.event === "resize" && typeof message.height === "number" ? message.height : void 0;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
/** At most 500px wide by default, the widest the post renders (docs/decisions.md D49). */
|
|
1014
|
+
function TelegramEmbed(props) {
|
|
1015
|
+
const { url, embed: given, onError, maxWidth = 500, userpic, color, dark, darkColor, ...shared } = props;
|
|
1016
|
+
const { embed, error } = resolveEmbed(url, given, "telegram");
|
|
1017
|
+
useReportError(error, onError);
|
|
1018
|
+
if (!embed) return null;
|
|
1019
|
+
const values = {
|
|
1020
|
+
...embed.options,
|
|
1021
|
+
...userpic === void 0 ? {} : { userpic },
|
|
1022
|
+
...color === void 0 ? {} : { color },
|
|
1023
|
+
...dark === void 0 ? {} : { dark },
|
|
1024
|
+
...darkColor === void 0 ? {} : { darkColor }
|
|
1025
|
+
};
|
|
1026
|
+
const params = [["embed", 1]];
|
|
1027
|
+
for (const [option, name] of PARAMS$3) {
|
|
1028
|
+
const value = param(name, values[option]);
|
|
1029
|
+
if (value !== void 0) params.push([name, value]);
|
|
1030
|
+
}
|
|
1031
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
1032
|
+
...shared,
|
|
1033
|
+
onError,
|
|
1034
|
+
maxWidth,
|
|
1035
|
+
src: `${embed.url}${query(params)}`,
|
|
1036
|
+
title: "Telegram post",
|
|
1037
|
+
allow: "",
|
|
1038
|
+
scrolling: "no",
|
|
1039
|
+
ratio: {
|
|
1040
|
+
width: 1,
|
|
1041
|
+
height: 1
|
|
1042
|
+
},
|
|
1043
|
+
messageHeight: TELEGRAM_HEIGHT,
|
|
1044
|
+
startHeight: 300
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
680
1047
|
// src/components/threads-embed.tsx
|
|
681
1048
|
/** A text-only post (docs/decisions.md D34). */
|
|
682
1049
|
const MIN_HEIGHT$1 = 240;
|
|
@@ -704,7 +1071,7 @@ function ThreadsEmbed(props) {
|
|
|
704
1071
|
}, markup);
|
|
705
1072
|
}
|
|
706
1073
|
// src/components/tiktok-embed.tsx
|
|
707
|
-
const PARAMS$
|
|
1074
|
+
const PARAMS$2 = {
|
|
708
1075
|
controls: "controls",
|
|
709
1076
|
progressBar: "progress_bar",
|
|
710
1077
|
playButton: "play_button",
|
|
@@ -720,7 +1087,7 @@ const PARAMS$1 = {
|
|
|
720
1087
|
closedCaption: "closed_caption",
|
|
721
1088
|
forceMuted: "force_muted"
|
|
722
1089
|
};
|
|
723
|
-
const ALLOW$
|
|
1090
|
+
const ALLOW$2 = "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share";
|
|
724
1091
|
/** At most 325px wide by default, the size of TikTok's own embed code (docs/decisions.md D40). */
|
|
725
1092
|
function TikTokEmbed(props) {
|
|
726
1093
|
const { url, embed: given, onError, maxWidth = 325, controls, progressBar, playButton, volumeControl, fullscreenButton, timestamp, loop, autoplay, musicInfo, description, rel, nativeContextMenu, closedCaption, forceMuted, ...frame } = props;
|
|
@@ -742,13 +1109,13 @@ function TikTokEmbed(props) {
|
|
|
742
1109
|
nativeContextMenu,
|
|
743
1110
|
closedCaption,
|
|
744
1111
|
forceMuted
|
|
745
|
-
}, PARAMS$
|
|
1112
|
+
}, PARAMS$2);
|
|
746
1113
|
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
747
1114
|
...frame,
|
|
748
1115
|
maxWidth,
|
|
749
1116
|
src: `https://www.tiktok.com/player/v1/${embed.id}${query(Object.entries(embed.options), params)}`,
|
|
750
1117
|
title: "TikTok video player",
|
|
751
|
-
allow: ALLOW$
|
|
1118
|
+
allow: ALLOW$2,
|
|
752
1119
|
ratio: {
|
|
753
1120
|
width: 9,
|
|
754
1121
|
height: 16
|
|
@@ -756,6 +1123,106 @@ function TikTokEmbed(props) {
|
|
|
756
1123
|
size: embed.size
|
|
757
1124
|
});
|
|
758
1125
|
}
|
|
1126
|
+
// src/components/twitch-embed.tsx
|
|
1127
|
+
const RESERVED = [
|
|
1128
|
+
"channel",
|
|
1129
|
+
"video",
|
|
1130
|
+
"collection",
|
|
1131
|
+
"clip",
|
|
1132
|
+
"parent"
|
|
1133
|
+
];
|
|
1134
|
+
/** The player and its content parameter for the embed's canonical URL (docs/decisions.md D64). */
|
|
1135
|
+
function player(url, id) {
|
|
1136
|
+
const { hostname, pathname } = new URL(url);
|
|
1137
|
+
if (hostname === "clips.twitch.tv") return ["https://clips.twitch.tv/embed", ["clip", id]];
|
|
1138
|
+
const section = pathname.split("/")[1];
|
|
1139
|
+
return ["https://player.twitch.tv/", section === "videos" ? ["video", `v${id}`] : section === "collections" ? ["collection", id] : ["channel", id]];
|
|
1140
|
+
}
|
|
1141
|
+
/** `parent` is the page's own host, added on the client (docs/decisions.md D62, D65). */
|
|
1142
|
+
function TwitchEmbed(props) {
|
|
1143
|
+
const { url, embed: given, onError, autoplay, muted, time, ...frame } = props;
|
|
1144
|
+
const { embed, error } = resolveEmbed(url, given, "twitch");
|
|
1145
|
+
useReportError(error, onError);
|
|
1146
|
+
if (!embed) return null;
|
|
1147
|
+
const params = [];
|
|
1148
|
+
if (autoplay !== void 0) params.push(["autoplay", String(autoplay)]);
|
|
1149
|
+
if (muted !== void 0) params.push(["muted", String(muted)]);
|
|
1150
|
+
if (time !== void 0) params.push(["time", time]);
|
|
1151
|
+
const [base, content] = player(embed.url, embed.id);
|
|
1152
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
1153
|
+
...frame,
|
|
1154
|
+
src: `${base}${query([content], optionsWithout(embed.options, RESERVED), params)}`,
|
|
1155
|
+
title: "Twitch player",
|
|
1156
|
+
allow: "",
|
|
1157
|
+
ratio: {
|
|
1158
|
+
width: 16,
|
|
1159
|
+
height: 9
|
|
1160
|
+
},
|
|
1161
|
+
size: embed.size,
|
|
1162
|
+
hostParam: "parent"
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
// src/components/vimeo-embed.tsx
|
|
1166
|
+
const PARAMS$1 = {
|
|
1167
|
+
autopause: "autopause",
|
|
1168
|
+
autoplay: "autoplay",
|
|
1169
|
+
background: "background",
|
|
1170
|
+
byline: "byline",
|
|
1171
|
+
color: "color",
|
|
1172
|
+
controls: "controls",
|
|
1173
|
+
dnt: "dnt",
|
|
1174
|
+
keyboard: "keyboard",
|
|
1175
|
+
loop: "loop",
|
|
1176
|
+
muted: "muted",
|
|
1177
|
+
pip: "pip",
|
|
1178
|
+
playsinline: "playsinline",
|
|
1179
|
+
portrait: "portrait",
|
|
1180
|
+
quality: "quality",
|
|
1181
|
+
speed: "speed",
|
|
1182
|
+
title: "title",
|
|
1183
|
+
transparent: "transparent"
|
|
1184
|
+
};
|
|
1185
|
+
const ALLOW$1 = "autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share";
|
|
1186
|
+
function VimeoEmbed(props) {
|
|
1187
|
+
const { url, embed: given, onError, autopause, autoplay, background, byline, color, controls, dnt, keyboard, loop, muted, pip, playsinline, portrait, quality, speed, title, transparent, t, ...frame } = props;
|
|
1188
|
+
const { embed, error } = resolveEmbed(url, given, "vimeo");
|
|
1189
|
+
useReportError(error, onError);
|
|
1190
|
+
if (!embed) return null;
|
|
1191
|
+
const { t: parsedStart, ...parsed } = embed.options;
|
|
1192
|
+
const hash = new URL(embed.url).pathname.split("/")[2];
|
|
1193
|
+
const params = playerParams({
|
|
1194
|
+
autopause,
|
|
1195
|
+
autoplay,
|
|
1196
|
+
background,
|
|
1197
|
+
byline,
|
|
1198
|
+
color,
|
|
1199
|
+
controls,
|
|
1200
|
+
dnt,
|
|
1201
|
+
keyboard,
|
|
1202
|
+
loop,
|
|
1203
|
+
muted,
|
|
1204
|
+
pip,
|
|
1205
|
+
playsinline,
|
|
1206
|
+
portrait,
|
|
1207
|
+
quality,
|
|
1208
|
+
speed,
|
|
1209
|
+
title,
|
|
1210
|
+
transparent
|
|
1211
|
+
}, PARAMS$1);
|
|
1212
|
+
const start = t ?? parsedStart;
|
|
1213
|
+
return /* @__PURE__ */ jsx(IframeEmbed, {
|
|
1214
|
+
...frame,
|
|
1215
|
+
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))}`}`,
|
|
1216
|
+
title: "Vimeo video player",
|
|
1217
|
+
allow: ALLOW$1,
|
|
1218
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
1219
|
+
ratio: {
|
|
1220
|
+
width: 16,
|
|
1221
|
+
height: 9
|
|
1222
|
+
},
|
|
1223
|
+
size: embed.size
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
759
1226
|
// src/components/x-embed.tsx
|
|
760
1227
|
const ATTRIBUTES = {
|
|
761
1228
|
theme: "data-theme",
|
|
@@ -908,6 +1375,57 @@ function SocialEmbed(props) {
|
|
|
908
1375
|
onError,
|
|
909
1376
|
embed
|
|
910
1377
|
});
|
|
1378
|
+
case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
|
|
1379
|
+
...shared,
|
|
1380
|
+
onError,
|
|
1381
|
+
embed
|
|
1382
|
+
});
|
|
1383
|
+
case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
|
|
1384
|
+
...shared,
|
|
1385
|
+
...frame,
|
|
1386
|
+
onError,
|
|
1387
|
+
embed
|
|
1388
|
+
});
|
|
1389
|
+
case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
|
|
1390
|
+
...shared,
|
|
1391
|
+
...frame,
|
|
1392
|
+
onError,
|
|
1393
|
+
embed
|
|
1394
|
+
});
|
|
1395
|
+
case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
|
|
1396
|
+
...shared,
|
|
1397
|
+
onError,
|
|
1398
|
+
embed
|
|
1399
|
+
});
|
|
1400
|
+
case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
|
|
1401
|
+
...shared,
|
|
1402
|
+
onError,
|
|
1403
|
+
embed
|
|
1404
|
+
});
|
|
1405
|
+
case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
|
|
1406
|
+
...shared,
|
|
1407
|
+
...frame,
|
|
1408
|
+
onError,
|
|
1409
|
+
embed
|
|
1410
|
+
});
|
|
1411
|
+
case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
|
|
1412
|
+
...shared,
|
|
1413
|
+
...frame,
|
|
1414
|
+
onError,
|
|
1415
|
+
embed
|
|
1416
|
+
});
|
|
1417
|
+
case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
|
|
1418
|
+
...shared,
|
|
1419
|
+
...frame,
|
|
1420
|
+
onError,
|
|
1421
|
+
embed
|
|
1422
|
+
});
|
|
1423
|
+
case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
|
|
1424
|
+
...shared,
|
|
1425
|
+
...frame,
|
|
1426
|
+
onError,
|
|
1427
|
+
embed
|
|
1428
|
+
});
|
|
911
1429
|
}
|
|
912
1430
|
}
|
|
913
|
-
export { FacebookEmbed, InstagramEmbed, SocialEmbed, ThreadsEmbed, TikTokEmbed, XEmbed, YouTubeEmbed };
|
|
1431
|
+
export { DailymotionEmbed, FacebookEmbed, InstagramEmbed, LinkedInEmbed, PinterestEmbed, RedditEmbed, SnapchatEmbed, SocialEmbed, SpotifyEmbed, TelegramEmbed, ThreadsEmbed, TikTokEmbed, TwitchEmbed, VimeoEmbed, XEmbed, YouTubeEmbed };
|