social-embeds 0.8.0 → 0.9.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 +91 -48
- package/dist/components/hooks.js +3 -1
- package/dist/components/platforms.d.ts +32 -0
- package/dist/components/platforms.js +384 -0
- package/dist/components/script-embed.js +8 -7
- package/dist/components/social-embed.d.ts +31 -4
- package/dist/components/social-embed.js +48 -211
- package/dist/core/drivers.js +8 -1
- package/dist/core/plans/youtube.js +15 -3
- package/dist/element.d.ts +1 -1
- package/dist/element.js +1 -1
- package/dist/index.d.ts +21 -20
- package/dist/index.js +3 -2
- package/dist/loader/load-script.js +2 -0
- package/dist/parser/frames.js +70 -0
- package/dist/parser/html.d.ts +19 -0
- package/dist/parser/iframe.js +2 -2
- package/dist/parser/match-url.js +6 -2
- package/dist/parser/parse-embed.js +14 -10
- package/dist/parser/platform.d.ts +26 -0
- package/dist/parser/platforms/applemusic.js +3 -3
- package/dist/parser/platforms/applepodcasts.js +3 -3
- package/dist/parser/platforms/dailymotion.js +6 -8
- package/dist/parser/platforms/facebook.js +5 -9
- package/dist/parser/platforms/giphy.js +6 -6
- package/dist/parser/platforms/kick.js +4 -4
- package/dist/parser/platforms/linkedin.js +4 -4
- package/dist/parser/platforms/pinterest.js +3 -3
- package/dist/parser/platforms/reddit.js +3 -2
- package/dist/parser/platforms/rumble.js +3 -2
- package/dist/parser/platforms/soundcloud.js +3 -3
- package/dist/parser/platforms/spotify.js +4 -4
- package/dist/parser/platforms/streamable.js +3 -2
- package/dist/parser/platforms/tenor.js +3 -2
- package/dist/parser/platforms/tiktok.js +6 -6
- package/dist/parser/platforms/truthsocial.js +2 -1
- package/dist/parser/platforms/tumblr.js +4 -2
- package/dist/parser/platforms/twitch.js +6 -7
- package/dist/parser/platforms/vimeo.js +31 -12
- package/dist/parser/platforms/x.js +1 -1
- package/dist/parser/platforms/youtube.js +73 -23
- package/dist/parser/url.d.ts +6 -0
- package/dist/parser/url.js +1 -1
- package/package.json +1 -1
|
@@ -1,221 +1,58 @@
|
|
|
1
|
-
import { matchUrl } from "../parser/match-url.js";
|
|
2
|
-
import { parseEmbed } from "../parser/parse-embed.js";
|
|
3
|
-
import { parseIframe } from "../parser/iframe.js";
|
|
4
1
|
import { sourceError } from "../core/resolve.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { DailymotionEmbed } from "./dailymotion-embed.js";
|
|
8
|
-
import { FacebookEmbed } from "./facebook-embed.js";
|
|
9
|
-
import { FlickrEmbed } from "./flickr-embed.js";
|
|
10
|
-
import { GenericIframeEmbed } from "./generic-iframe-embed.js";
|
|
11
|
-
import { GiphyEmbed } from "./giphy-embed.js";
|
|
2
|
+
import { matchUrlWith } from "../parser/match-url.js";
|
|
3
|
+
import { parseEmbedWith } from "../parser/parse-embed.js";
|
|
12
4
|
import { useReportError } from "./hooks.js";
|
|
13
|
-
import {
|
|
14
|
-
import { InstagramEmbed } from "./instagram-embed.js";
|
|
15
|
-
import { KickEmbed } from "./kick-embed.js";
|
|
16
|
-
import { LinkedInEmbed } from "./linkedin-embed.js";
|
|
17
|
-
import { PinterestEmbed } from "./pinterest-embed.js";
|
|
18
|
-
import { RedditEmbed } from "./reddit-embed.js";
|
|
19
|
-
import { SnapchatEmbed } from "./snapchat-embed.js";
|
|
20
|
-
import { SoundCloudEmbed } from "./soundcloud-embed.js";
|
|
21
|
-
import { SpotifyEmbed } from "./spotify-embed.js";
|
|
22
|
-
import { StravaEmbed } from "./strava-embed.js";
|
|
23
|
-
import { StreamableEmbed } from "./streamable-embed.js";
|
|
24
|
-
import { RumbleEmbed } from "./rumble-embed.js";
|
|
25
|
-
import { TenorEmbed } from "./tenor-embed.js";
|
|
26
|
-
import { TelegramEmbed } from "./telegram-embed.js";
|
|
27
|
-
import { ThreadsEmbed } from "./threads-embed.js";
|
|
28
|
-
import { TikTokEmbed } from "./tiktok-embed.js";
|
|
29
|
-
import { TruthSocialEmbed } from "./truthsocial-embed.js";
|
|
30
|
-
import { TumblrEmbed } from "./tumblr-embed.js";
|
|
31
|
-
import { TwitchEmbed } from "./twitch-embed.js";
|
|
32
|
-
import { VimeoEmbed } from "./vimeo-embed.js";
|
|
33
|
-
import { XEmbed } from "./x-embed.js";
|
|
34
|
-
import { YouTubeEmbed } from "./youtube-embed.js";
|
|
5
|
+
import { EVERY_PLATFORM } from "./platforms.js";
|
|
35
6
|
import { useMemo } from "react";
|
|
36
|
-
import { jsx } from "react/jsx-runtime";
|
|
37
7
|
// src/components/social-embed.tsx
|
|
38
|
-
|
|
39
|
-
|
|
8
|
+
function tableOf(list) {
|
|
9
|
+
const named = list.flatMap((entry) => entry.kind === "platform" ? [entry] : []);
|
|
10
|
+
return {
|
|
11
|
+
parsers: named.map((entry) => entry.parser),
|
|
12
|
+
renders: new Map(named.map((entry) => [entry.parser.platform, entry.render])),
|
|
13
|
+
iframe: list.find((entry) => entry.kind === "iframe")
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function useSocialEmbed(props, table) {
|
|
40
17
|
const { html, url, fallback, height, maxHeight, onError, ...shared } = props;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
const route = {
|
|
19
|
+
shared,
|
|
20
|
+
frame: {
|
|
21
|
+
height,
|
|
22
|
+
maxHeight
|
|
23
|
+
},
|
|
24
|
+
onError
|
|
44
25
|
};
|
|
45
|
-
const embed = useMemo(() => html !== void 0 ?
|
|
46
|
-
|
|
26
|
+
const embed = useMemo(() => html !== void 0 ? parseEmbedWith(table.parsers, html) : matchUrlWith(table.parsers, url), [
|
|
27
|
+
html,
|
|
28
|
+
url,
|
|
29
|
+
table
|
|
30
|
+
]);
|
|
31
|
+
const iframe = useMemo(() => embed === null && html !== void 0 ? table.iframe?.parse(html) ?? null : null, [
|
|
32
|
+
embed,
|
|
33
|
+
html,
|
|
34
|
+
table
|
|
35
|
+
]);
|
|
47
36
|
useReportError(embed === null && iframe === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
|
|
48
|
-
if (iframe) return
|
|
49
|
-
...shared,
|
|
50
|
-
...frame,
|
|
51
|
-
onError,
|
|
52
|
-
embed: iframe
|
|
53
|
-
});
|
|
37
|
+
if (iframe && table.iframe) return table.iframe.render(iframe, route);
|
|
54
38
|
if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
case "threads": return /* @__PURE__ */ jsx(ThreadsEmbed, {
|
|
67
|
-
...shared,
|
|
68
|
-
onError,
|
|
69
|
-
embed
|
|
70
|
-
});
|
|
71
|
-
case "facebook": return /* @__PURE__ */ jsx(FacebookEmbed, {
|
|
72
|
-
...shared,
|
|
73
|
-
...frame,
|
|
74
|
-
onError,
|
|
75
|
-
embed
|
|
76
|
-
});
|
|
77
|
-
case "tiktok": return /* @__PURE__ */ jsx(TikTokEmbed, {
|
|
78
|
-
...shared,
|
|
79
|
-
...frame,
|
|
80
|
-
onError,
|
|
81
|
-
embed
|
|
82
|
-
});
|
|
83
|
-
case "youtube": return /* @__PURE__ */ jsx(YouTubeEmbed, {
|
|
84
|
-
...shared,
|
|
85
|
-
...frame,
|
|
86
|
-
onError,
|
|
87
|
-
embed
|
|
88
|
-
});
|
|
89
|
-
case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
|
|
90
|
-
...shared,
|
|
91
|
-
onError,
|
|
92
|
-
embed
|
|
93
|
-
});
|
|
94
|
-
case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
|
|
95
|
-
...shared,
|
|
96
|
-
...frame,
|
|
97
|
-
onError,
|
|
98
|
-
embed
|
|
99
|
-
});
|
|
100
|
-
case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
|
|
101
|
-
...shared,
|
|
102
|
-
...frame,
|
|
103
|
-
onError,
|
|
104
|
-
embed
|
|
105
|
-
});
|
|
106
|
-
case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
|
|
107
|
-
...shared,
|
|
108
|
-
onError,
|
|
109
|
-
embed
|
|
110
|
-
});
|
|
111
|
-
case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
|
|
112
|
-
...shared,
|
|
113
|
-
onError,
|
|
114
|
-
embed
|
|
115
|
-
});
|
|
116
|
-
case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
|
|
117
|
-
...shared,
|
|
118
|
-
...frame,
|
|
119
|
-
onError,
|
|
120
|
-
embed
|
|
121
|
-
});
|
|
122
|
-
case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
|
|
123
|
-
...shared,
|
|
124
|
-
...frame,
|
|
125
|
-
onError,
|
|
126
|
-
embed
|
|
127
|
-
});
|
|
128
|
-
case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
|
|
129
|
-
...shared,
|
|
130
|
-
...frame,
|
|
131
|
-
onError,
|
|
132
|
-
embed
|
|
133
|
-
});
|
|
134
|
-
case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
|
|
135
|
-
...shared,
|
|
136
|
-
...frame,
|
|
137
|
-
onError,
|
|
138
|
-
embed
|
|
139
|
-
});
|
|
140
|
-
case "bluesky": return /* @__PURE__ */ jsx(BlueskyEmbed, {
|
|
141
|
-
...shared,
|
|
142
|
-
onError,
|
|
143
|
-
embed
|
|
144
|
-
});
|
|
145
|
-
case "soundcloud": return /* @__PURE__ */ jsx(SoundCloudEmbed, {
|
|
146
|
-
...shared,
|
|
147
|
-
...frame,
|
|
148
|
-
onError,
|
|
149
|
-
embed
|
|
150
|
-
});
|
|
151
|
-
case "applemusic": return /* @__PURE__ */ jsx(AppleMusicEmbed, {
|
|
152
|
-
...shared,
|
|
153
|
-
...frame,
|
|
154
|
-
onError,
|
|
155
|
-
embed
|
|
156
|
-
});
|
|
157
|
-
case "applepodcasts": return /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
|
|
158
|
-
...shared,
|
|
159
|
-
...frame,
|
|
160
|
-
onError,
|
|
161
|
-
embed
|
|
162
|
-
});
|
|
163
|
-
case "tumblr": return /* @__PURE__ */ jsx(TumblrEmbed, {
|
|
164
|
-
...shared,
|
|
165
|
-
onError,
|
|
166
|
-
embed
|
|
167
|
-
});
|
|
168
|
-
case "kick": return /* @__PURE__ */ jsx(KickEmbed, {
|
|
169
|
-
...shared,
|
|
170
|
-
...frame,
|
|
171
|
-
onError,
|
|
172
|
-
embed
|
|
173
|
-
});
|
|
174
|
-
case "giphy": return /* @__PURE__ */ jsx(GiphyEmbed, {
|
|
175
|
-
...shared,
|
|
176
|
-
...frame,
|
|
177
|
-
onError,
|
|
178
|
-
embed
|
|
179
|
-
});
|
|
180
|
-
case "tenor": return /* @__PURE__ */ jsx(TenorEmbed, {
|
|
181
|
-
...shared,
|
|
182
|
-
...frame,
|
|
183
|
-
onError,
|
|
184
|
-
embed
|
|
185
|
-
});
|
|
186
|
-
case "streamable": return /* @__PURE__ */ jsx(StreamableEmbed, {
|
|
187
|
-
...shared,
|
|
188
|
-
...frame,
|
|
189
|
-
onError,
|
|
190
|
-
embed
|
|
191
|
-
});
|
|
192
|
-
case "rumble": return /* @__PURE__ */ jsx(RumbleEmbed, {
|
|
193
|
-
...shared,
|
|
194
|
-
...frame,
|
|
195
|
-
onError,
|
|
196
|
-
embed
|
|
197
|
-
});
|
|
198
|
-
case "truthsocial": return /* @__PURE__ */ jsx(TruthSocialEmbed, {
|
|
199
|
-
...shared,
|
|
200
|
-
onError,
|
|
201
|
-
embed
|
|
202
|
-
});
|
|
203
|
-
case "imgur": return /* @__PURE__ */ jsx(ImgurEmbed, {
|
|
204
|
-
...shared,
|
|
205
|
-
onError,
|
|
206
|
-
embed
|
|
207
|
-
});
|
|
208
|
-
case "strava": return /* @__PURE__ */ jsx(StravaEmbed, {
|
|
209
|
-
...shared,
|
|
210
|
-
onError,
|
|
211
|
-
embed
|
|
212
|
-
});
|
|
213
|
-
case "flickr": return /* @__PURE__ */ jsx(FlickrEmbed, {
|
|
214
|
-
...shared,
|
|
215
|
-
...frame,
|
|
216
|
-
onError,
|
|
217
|
-
embed
|
|
218
|
-
});
|
|
39
|
+
return table.renders.get(embed.platform)?.(embed, route) ?? null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A `<SocialEmbed>` that recognises only the listed platforms, so a bundler leaves the others
|
|
43
|
+
* out. Call it in a client module: `createSocialEmbed([youtube, x, genericIframe])`.
|
|
44
|
+
*/
|
|
45
|
+
function createSocialEmbed(list) {
|
|
46
|
+
const table = tableOf(list);
|
|
47
|
+
function SocialEmbed(props) {
|
|
48
|
+
return useSocialEmbed(props, table);
|
|
219
49
|
}
|
|
50
|
+
return SocialEmbed;
|
|
51
|
+
}
|
|
52
|
+
let every;
|
|
53
|
+
/** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
|
|
54
|
+
function SocialEmbed(props) {
|
|
55
|
+
every ??= tableOf(EVERY_PLATFORM);
|
|
56
|
+
return useSocialEmbed(props, every);
|
|
220
57
|
}
|
|
221
|
-
export { SocialEmbed };
|
|
58
|
+
export { SocialEmbed, createSocialEmbed };
|
package/dist/core/drivers.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FACEBOOK_SDK_VERSION, loadPlatformScript } from "../loader/platform-scripts.js";
|
|
2
2
|
// src/core/drivers.ts
|
|
3
3
|
const globals = () => window;
|
|
4
|
+
/** Thrown by `render` when another attempt cannot succeed. */
|
|
5
|
+
var FinalError = class extends Error {};
|
|
4
6
|
function watch(container, rendered, done) {
|
|
5
7
|
if (rendered(container)) {
|
|
6
8
|
done();
|
|
@@ -49,6 +51,9 @@ const xDriver = {
|
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
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
|
+
}
|
|
52
57
|
/** Instagram and Threads share `instgrm.Embeds.process()`, which renders both. */
|
|
53
58
|
function processEmbeds() {
|
|
54
59
|
const process = globals().instgrm?.Embeds?.process;
|
|
@@ -58,6 +63,7 @@ function processEmbeds() {
|
|
|
58
63
|
const instagramDriver = {
|
|
59
64
|
load: () => loadPlatformScript("instagram"),
|
|
60
65
|
render(container, done) {
|
|
66
|
+
inDocument(container, "Instagram");
|
|
61
67
|
const stop = watch(container, (element) => element.querySelector("iframe.instagram-media-rendered") !== null, done);
|
|
62
68
|
reveal(container, "instagram-media");
|
|
63
69
|
processEmbeds();
|
|
@@ -67,6 +73,7 @@ const instagramDriver = {
|
|
|
67
73
|
const threadsDriver = {
|
|
68
74
|
load: () => loadPlatformScript("threads"),
|
|
69
75
|
render(container, done) {
|
|
76
|
+
inDocument(container, "Threads");
|
|
70
77
|
const stop = watch(container, (element) => element.querySelector("iframe") !== null && element.querySelector("blockquote") === null, done);
|
|
71
78
|
reveal(container, "text-post-media");
|
|
72
79
|
processEmbeds();
|
|
@@ -115,4 +122,4 @@ const pinterestDriver = {
|
|
|
115
122
|
return stop;
|
|
116
123
|
}
|
|
117
124
|
};
|
|
118
|
-
export { facebookDriver, instagramDriver, pinterestDriver, threadsDriver, xDriver };
|
|
125
|
+
export { FinalError, facebookDriver, instagramDriver, pinterestDriver, threadsDriver, xDriver };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { playerParams, query } from "../params.js";
|
|
1
|
+
import { optionsWithout, playerParams, query } from "../params.js";
|
|
2
2
|
// src/core/plans/youtube.ts
|
|
3
3
|
const PARAMS = {
|
|
4
4
|
autoplay: "autoplay",
|
|
@@ -23,14 +23,26 @@ const PARAMS = {
|
|
|
23
23
|
widgetReferrer: "widget_referrer"
|
|
24
24
|
};
|
|
25
25
|
const ALLOW = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
|
|
26
|
+
function player(embed) {
|
|
27
|
+
if (embed.url.startsWith("https://www.youtube.com/playlist?")) return {
|
|
28
|
+
path: "videoseries",
|
|
29
|
+
key: "list"
|
|
30
|
+
};
|
|
31
|
+
if (embed.url.startsWith("https://www.youtube.com/channel/")) return {
|
|
32
|
+
path: "live_stream",
|
|
33
|
+
key: "channel"
|
|
34
|
+
};
|
|
35
|
+
return { path: embed.id };
|
|
36
|
+
}
|
|
26
37
|
function youtubePlan(embed, options) {
|
|
27
38
|
const { nocookie, ...rest } = options;
|
|
28
39
|
const { nocookie: parsedNocookie, ...parsed } = embed.options;
|
|
29
40
|
const host = nocookie ?? parsedNocookie === true ? "https://www.youtube-nocookie.com" : "https://www.youtube.com";
|
|
30
|
-
const
|
|
41
|
+
const { path, key } = player(embed);
|
|
42
|
+
const params = playerParams(rest, PARAMS).filter(([name]) => name !== key);
|
|
31
43
|
return {
|
|
32
44
|
kind: "iframe",
|
|
33
|
-
src: `${host}/embed/${
|
|
45
|
+
src: `${host}/embed/${path}${query(key === void 0 ? void 0 : [[key, embed.id]], optionsWithout(parsed, key === void 0 ? [] : [key]), params)}`,
|
|
34
46
|
title: "YouTube video player",
|
|
35
47
|
allow: ALLOW,
|
|
36
48
|
referrerPolicy: "strict-origin-when-cross-origin",
|
package/dist/element.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class SocialEmbedElement extends Base {
|
|
|
19
19
|
get maxHeight(): string | null;
|
|
20
20
|
set maxHeight(value: string | null);
|
|
21
21
|
get eager(): boolean;
|
|
22
|
-
set eager(value: boolean | null | undefined);
|
|
22
|
+
set eager(value: boolean | string | null | undefined);
|
|
23
23
|
connectedCallback(): void;
|
|
24
24
|
disconnectedCallback(): void;
|
|
25
25
|
attributeChangedCallback(): void;
|