mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge 01809637cb
into 4a60fe3d22
This commit is contained in:
commit
85c081fa79
1 changed files with 55 additions and 0 deletions
|
@ -54,6 +54,11 @@ const RE_REDDIT =
|
||||||
const RE_REDDIT_EMBED =
|
const RE_REDDIT_EMBED =
|
||||||
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
||||||
|
|
||||||
|
const RE_TWITCH_CLIP =
|
||||||
|
/^https?:\/\/(www\.)?twitch\.tv\/[^/]+\/clip\/([a-zA-Z0-9_-]+)/i;
|
||||||
|
|
||||||
|
const RE_TWITCH_VIDEO = /^https?:\/\/(www\.)?twitch\.tv\/videos\/(\d+)/i;
|
||||||
|
|
||||||
const ALLOWED_DOMAINS = new Set([
|
const ALLOWED_DOMAINS = new Set([
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"youtu.be",
|
"youtu.be",
|
||||||
|
@ -69,6 +74,9 @@ const ALLOWED_DOMAINS = new Set([
|
||||||
"val.town",
|
"val.town",
|
||||||
"giphy.com",
|
"giphy.com",
|
||||||
"reddit.com",
|
"reddit.com",
|
||||||
|
"twitch.tv",
|
||||||
|
"clips.twitch.tv",
|
||||||
|
"player.twitch.tv",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ALLOW_SAME_ORIGIN = new Set([
|
const ALLOW_SAME_ORIGIN = new Set([
|
||||||
|
@ -82,6 +90,9 @@ const ALLOW_SAME_ORIGIN = new Set([
|
||||||
"*.simplepdf.eu",
|
"*.simplepdf.eu",
|
||||||
"stackblitz.com",
|
"stackblitz.com",
|
||||||
"reddit.com",
|
"reddit.com",
|
||||||
|
"twitch.tv",
|
||||||
|
"clips.twitch.tv",
|
||||||
|
"player.twitch.tv",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const createSrcDoc = (body: string) => {
|
export const createSrcDoc = (body: string) => {
|
||||||
|
@ -270,6 +281,50 @@ export const getEmbedLink = (
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parent = typeof window !== "undefined" ? window.location.hostname : "";
|
||||||
|
const twitchClip = link.match(RE_TWITCH_CLIP);
|
||||||
|
if (twitchClip?.[2]) {
|
||||||
|
link = `https://clips.twitch.tv/embed?clip=${twitchClip[2]}&parent=${parent}&autoplay=false`;
|
||||||
|
type = "video";
|
||||||
|
aspectRatio = { w: 560, h: 315 };
|
||||||
|
embeddedLinkCache.set(originalLink, {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const twitchVideo = link.match(RE_TWITCH_VIDEO);
|
||||||
|
if (twitchVideo?.[2]) {
|
||||||
|
const urlObj = new URL(link);
|
||||||
|
const tParam = urlObj.searchParams.get("t") || "";
|
||||||
|
link = `https://player.twitch.tv/?video=${
|
||||||
|
twitchVideo[2]
|
||||||
|
}&parent=${parent}&autoplay=false${tParam ? `&t=${tParam}` : ""}`;
|
||||||
|
|
||||||
|
type = "video";
|
||||||
|
aspectRatio = { w: 560, h: 315 };
|
||||||
|
embeddedLinkCache.set(originalLink, {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
embeddedLinkCache.set(link, {
|
embeddedLinkCache.set(link, {
|
||||||
link,
|
link,
|
||||||
intrinsicSize: aspectRatio,
|
intrinsicSize: aspectRatio,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue