mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge 3fdef201b0
into ab89d4c16f
This commit is contained in:
commit
94422f0d28
1 changed files with 7 additions and 6 deletions
|
@ -21,7 +21,7 @@ type IframeDataWithSandbox = MarkRequired<IframeData, "sandbox">;
|
||||||
const embeddedLinkCache = new Map<string, IframeDataWithSandbox>();
|
const embeddedLinkCache = new Map<string, IframeDataWithSandbox>();
|
||||||
|
|
||||||
const RE_YOUTUBE =
|
const RE_YOUTUBE =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(?:embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:.*?[&?](?:t=|start=)([a-zA-Z0-9_-]+))?.*$/;
|
||||||
|
|
||||||
const RE_VIMEO =
|
const RE_VIMEO =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
||||||
|
@ -106,22 +106,23 @@ export const getEmbedLink = (
|
||||||
let type: "video" | "generic" = "generic";
|
let type: "video" | "generic" = "generic";
|
||||||
let aspectRatio = { w: 560, h: 840 };
|
let aspectRatio = { w: 560, h: 840 };
|
||||||
const ytLink = link.match(RE_YOUTUBE);
|
const ytLink = link.match(RE_YOUTUBE);
|
||||||
if (ytLink?.[2]) {
|
const id = ytLink?.[1];
|
||||||
const time = ytLink[3] ? `&start=${ytLink[3]}` : ``;
|
if (id) {
|
||||||
|
const time = ytLink[2] ? `&start=${ytLink[2]}` : ``;
|
||||||
const isPortrait = link.includes("shorts");
|
const isPortrait = link.includes("shorts");
|
||||||
type = "video";
|
type = "video";
|
||||||
switch (ytLink[1]) {
|
switch (ytLink[1]) {
|
||||||
case "embed/":
|
case "embed/":
|
||||||
case "watch?v=":
|
case "watch?v=":
|
||||||
case "shorts/":
|
case "shorts/":
|
||||||
link = `https://www.youtube.com/embed/${ytLink[2]}?enablejsapi=1${time}`;
|
link = `https://www.youtube.com/embed/${id}?enablejsapi=1${time}`;
|
||||||
break;
|
break;
|
||||||
case "playlist?list=":
|
case "playlist?list=":
|
||||||
case "embed/videoseries?list=":
|
case "embed/videoseries?list=":
|
||||||
link = `https://www.youtube.com/embed/videoseries?list=${ytLink[2]}&enablejsapi=1${time}`;
|
link = `https://www.youtube.com/embed/videoseries?list=${id}&enablejsapi=1${time}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
link = `https://www.youtube.com/embed/${ytLink[2]}?enablejsapi=1${time}`;
|
link = `https://www.youtube.com/embed/${id}?enablejsapi=1${time}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aspectRatio = isPortrait ? { w: 315, h: 560 } : { w: 560, h: 315 };
|
aspectRatio = isPortrait ? { w: 315, h: 560 } : { w: 560, h: 315 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue